Example #1
0
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);
}
Example #2
0
static char *
gfs_pio_remote_storage_close(GFS_File gf)
{
	struct gfs_file_section_context *vc = gf->view_context;
	struct gfs_connection *gfs_server = vc->storage_context;

	return (gfs_client_close(gfs_server, vc->fd));
}
Example #3
0
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);
}
Example #4
0
static char *
gfs_pio_remote_storage_close(GFS_File gf)
{
	struct gfs_file_section_context *vc = gf->view_context;
	struct gfs_connection *gfs_server = vc->storage_context;

	/*
	 * Do not close remote file from a child process because its
	 * open file count is not incremented.
	 * XXX - This behavior is not the same as expected, but better
	 * than closing the remote file.
	 */
	if (vc->pid != getpid())
		return (NULL);
	return (gfs_client_close(gfs_server, vc->fd));
}
Example #5
0
static gfarm_error_t
gfs_pio_local_storage_close(GFS_File gf)
{
	gfarm_error_t e, e2;
	struct gfs_file_section_context *vc = gf->view_context;
	struct gfs_connection *gfs_server = vc->storage_context;

	if (close(vc->fd) == -1)
		e = gfarm_errno_to_error(errno);
	else
		e = GFARM_ERR_NO_ERROR;
#ifndef __KERNEL__
	/*
	 * Do not close remote file from a child process because its
	 * open file count is not incremented.
	 * XXX - This behavior is not the same as expected, but better
	 * than closing the remote file.
	 */
	if (vc->pid != getpid()) {
		if (e != GFARM_ERR_NO_ERROR) {
			gflog_debug(GFARM_MSG_1001362,
				"close operation on view context "
				"file descriptor failed: %s",
				gfarm_error_string(e));
		}
		return (e);
	}
#endif /* __KERNEL__ */
	e2 = gfs_client_close(gfs_server, gf->fd);
	gfarm_schedule_host_unused(
	    gfs_client_hostname(gfs_server),
	    gfs_client_port(gfs_server),
	    gfs_client_username(gfs_server),
	    gf->scheduled_age);

	gfs_client_connection_free(gfs_server);

	if (e != GFARM_ERR_NO_ERROR || e2 != GFARM_ERR_NO_ERROR) {
		gflog_debug(GFARM_MSG_1001363,
			"Close operation on local storage failed: %s",
			gfarm_error_string(
				e != GFARM_ERR_NO_ERROR ? e : e2));
	}

	return (e != GFARM_ERR_NO_ERROR ? e : e2);
}
Example #6
0
static gfarm_error_t
gfs_pio_remote_storage_close(GFS_File gf)
{
	gfarm_error_t e;
	struct gfs_file_section_context *vc = gf->view_context;
	struct gfs_connection *gfs_server = vc->storage_context;

	/*
	 * Do not close remote file from a child process because its
	 * open file count is not incremented.
	 * XXX - This behavior is not the same as expected, but better
	 * than closing the remote file.
	 */
	if (vc->pid != getpid())
		return (GFARM_ERR_NO_ERROR);
	e = gfs_client_close(gfs_server, gf->fd);
	gfs_client_connection_free(gfs_server);
	return (e);
}