Esempio n. 1
0
static
gfarm_error_t
do_replica()
{
	gfarm_error_t e;
	struct gfm_connection *sv;
	struct gfarm_host_info from, to;
	const char *path = GFARM_PATH_ROOT;

	e = gfarm_url_parse_metadb(&path, &sv);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "metadb %s: %s\n", testdir_filename,
			gfarm_error_string(e));
		return (e);
	}

	e = gfm_host_info_get_by_name_alias(sv, from_gfsd_name, &from);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "host_info %s: %s\n", from_gfsd_name,
			gfarm_error_string(e));
		return (e);
	}

	e = gfm_host_info_get_by_name_alias(sv, to_gfsd_name, &to);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "host_info %s: %s\n", to_gfsd_name,
			gfarm_error_string(e));
		gfarm_host_info_free(&from);
		return (e);
	}

	e = gfs_replicate_from_to(testdir_filename,
				  from.hostname, from.port,
				  to.hostname, to.port);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "replicate %s: %s\n", testdir_filename,
			gfarm_error_string(e));
		if (e == GFARM_ERR_ALREADY_EXISTS)
			fprintf(stderr,
				"may be enabled auto replication "
				"in %s or the parent directory.\n",
				testdir);
		gfarm_host_info_free(&from);
		gfarm_host_info_free(&to);
		return (e);
	}

	gfarm_host_info_free(&from);
	gfarm_host_info_free(&to);
	return (GFARM_ERR_NO_ERROR);
}
Esempio n. 2
0
gfarm_error_t
list(int nhosts, char **hosts,
	gfarm_error_t (*request_op)(struct gfarm_host_info *,
	    struct gfarm_paraccess *),
	struct gfarm_paraccess *pa)
{
	gfarm_error_t e, e_save = GFARM_ERR_NO_ERROR;
	int i;
	struct gfarm_host_info hi;

	for (i = 0; i < nhosts; i++) {
		e = gfarm_host_info_get_by_if_hostname(hosts[i], &hi);
		if (e != GFARM_ERR_NO_ERROR) {
			fprintf(stderr, "%s: %s\n", hosts[i],
		    	    gfarm_error_string(e));
			if (e_save == GFARM_ERR_NO_ERROR)
				e_save = e;
		} else {
			e = (*request_op)(&hi, pa);
			if (e_save == GFARM_ERR_NO_ERROR)
				e_save = e;
			gfarm_host_info_free(&hi);
		}
	}
	return (e_save);
}
Esempio n. 3
0
void
gfarm_internal_host_info_free(struct gfarm_internal_host_info *i_info)
{
	struct gfarm_host_info *info = &i_info->hi;

	if (i_info->fsngroupname != NULL)
		free(i_info->fsngroupname);
	gfarm_host_info_free(info);
}
Esempio n. 4
0
gfarm_error_t
request_long_format(struct gfarm_host_info *host_info,
	struct gfarm_paraccess *pa)
{
	gfarm_error_t e;
	struct sockaddr addr;
	struct long_format_parameter *param;
	struct gfarm_host_info *info;

	GFARM_MALLOC(param);
	if (param == NULL) {
		e = GFARM_ERR_NO_MEMORY;
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		return (e);
	}
	info = &param->info;

	/* dup `*host_info' -> `*info' */
	info->hostname = strdup(host_info->hostname);
	info->port = host_info->port;
	info->nhostaliases = host_info->nhostaliases;
	if (host_info->nhostaliases == 0) {
		info->hostaliases = NULL;
	} else {
		info->hostaliases = gfarm_strarray_dup(host_info->hostaliases);
		if (info->hostaliases == NULL)
			info->nhostaliases = 0;
	}
	info->architecture = strdup(host_info->architecture);
	info->ncpu = host_info->ncpu;
	info->flags = host_info->flags;
	if (info->hostname == NULL || info->architecture == NULL) {
		gfarm_host_info_free(info);
		free(param);
		e = GFARM_ERR_NO_MEMORY;
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		return (e);
	}

	param->if_hostname = NULL;
	e = (*opt_resolv_addr)(info->hostname, info->port, info,
	    &addr, &param->if_hostname);
	if (e != GFARM_ERR_NO_ERROR) {
		output_process(param, info->hostname, NULL, NULL, NULL, e);
		return (e);
	}

	return (gfarm_paraccess_request(pa, param, info->hostname, info->port,
	    &addr));
}
Esempio n. 5
0
void
callback_long_format(struct output *o)
{
	struct long_format_parameter *param = o->closure;
	char *if_hostname = param->if_hostname;
	struct gfarm_host_info *info = &param->info;
	/* sizeof(struct sockaddr_in) == sizeof(struct sockaddr) */
	struct sockaddr_in *addr_in = (struct sockaddr_in *)&o->peer_addr;
	int i, print_ifaddr = if_hostname != NULL;

	print_loadavg_authinfo(o);
	printf("%s %d %s %d %d",
	    info->architecture, info->ncpu,
	    o->canonical_hostname, info->port, info->flags);
	if (print_ifaddr &&
	    strcasecmp(o->canonical_hostname, if_hostname) == 0) {
		print_ifaddr = 0;
		printf("(%s)", inet_ntoa(addr_in->sin_addr));
	}
	for (i = 0; i < info->nhostaliases; i++) {
		printf(" %s", info->hostaliases[i]);
		if (print_ifaddr &&
		    strcasecmp(info->hostaliases[i], if_hostname) == 0) {
			print_ifaddr = 0;
			printf("(%s)", inet_ntoa(addr_in->sin_addr));
		}
	}
	if (print_ifaddr) {
		printf(" [%s(%s)]", if_hostname, inet_ntoa(addr_in->sin_addr));
	}
	putchar('\n');
	if (opt_verbose && o->error != GFARM_ERR_NO_ERROR)
		fprintf(stderr, "%s: %s\n", o->canonical_hostname,
		    gfarm_error_string(o->error));
	gfarm_host_info_free(info);
	if (if_hostname != NULL)
		free(if_hostname);
	free(param);
}
Esempio n. 6
0
int
main(int argc, char *argv[])
{
	char *src = NULL, *dst = NULL, *f, c;
	struct gfarm_host_info sinfo, dinfo;
	gfarm_error_t e;

	if (argc > 0)
		program_name = basename(argv[0]);

	e = gfarm_initialize(&argc, &argv);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n",
		    program_name, gfarm_error_string(e));
		exit(EXIT_FAILURE);
	}
	while ((c = getopt(argc, argv, "d:s:h?")) != -1) {
		switch (c) {
		case 'd':
			dst = optarg;
			break;
		case 's':
			src = optarg;
			break;
		case 'h':
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (dst == NULL)
		usage();

	if (src != NULL) {
		e = gfarm_host_info_get_by_name_alias(src, &sinfo);
		if (e != GFARM_ERR_NO_ERROR) {
			fprintf(stderr, "%s: %s\n", src,
				gfarm_error_string(e));
			exit(EXIT_FAILURE);
		}
	}
	e = gfarm_host_info_get_by_name_alias(dst, &dinfo);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n", dst, gfarm_error_string(e));
		exit(EXIT_FAILURE);
	}

	f = *argv;
	e = gfs_replicate_from_to(f, src, sinfo.port, dst, dinfo.port);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n", f, gfarm_error_string(e));
		exit(EXIT_FAILURE);
	}
	if (src != NULL)
		gfarm_host_info_free(&sinfo);
	gfarm_host_info_free(&dinfo);

	e = gfarm_terminate();
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n",
		    program_name, gfarm_error_string(e));
		exit(EXIT_FAILURE);
	}
	return (0);
}
Esempio n. 7
0
gfarm_error_t
gfarm_modify_host(const char *hostname, int port,
	char **hostaliases, char *architecture,
	int ncpu, int flags, int add_aliases)
{
	gfarm_error_t e, e2;
	struct gfarm_host_info hi;
	int host_info_needs_free = 0;
	gfarm_stringlist aliases;

	if (port == 0 || *hostaliases == NULL || architecture == NULL ||
	    ncpu < 1 || flags == -1 || add_aliases) {
		e = gfm_client_host_info_get_by_names(gfarm_metadb_server,
		    1, &hostname, &e2, &hi);
		if (e != GFARM_ERR_NO_ERROR)
			return (e);
		if (e2 != GFARM_ERR_NO_ERROR)
			return (e2);
		host_info_needs_free = 1;
		if (!add_aliases) {
			/* XXX - do check_hostaliases() here, too. */
			hostaliases = hostaliases;
		} else {
			e = check_hostaliases(
			    gfarm_strarray_length(hostaliases), hostaliases);
			if (e != GFARM_ERR_NO_ERROR)
				goto free_host_info;

			e = gfarm_stringlist_init(&aliases);
			if (e != GFARM_ERR_NO_ERROR)
				goto free_host_info;
			if (hi.hostaliases != NULL) {
				e = gfarm_stringlist_cat(&aliases,
				    hi.hostaliases);
				if (e != GFARM_ERR_NO_ERROR)
					goto free_aliases;
			}
			if (hostaliases != NULL) {
				e = gfarm_stringlist_cat(&aliases,
				    hostaliases);
				if (e != GFARM_ERR_NO_ERROR)
					goto free_aliases;
			}
			e = gfarm_stringlist_add(&aliases, NULL);
			if (e != GFARM_ERR_NO_ERROR)
				goto free_aliases;
			hostaliases = GFARM_STRINGLIST_STRARRAY(aliases);
		}
		if (port == 0)
			port = hi.port;
		if (architecture == NULL)
			architecture = hi.architecture;
		if (ncpu < 1)
			ncpu = hi.ncpu;
		if (flags == -1)
			flags = hi.flags;
	}
	e = update_host(hostname, port,
	    gfarm_strarray_length(hostaliases), hostaliases,
	    architecture, ncpu, flags,
	    gfm_client_host_info_modify);
#if 0 /* XXX FIXME not yet in v2 */
	if (e == GFARM_ERR_NO_ERROR && !add_aliases && *hostaliases == NULL)
		e = gfarm_host_info_remove_hostaliases(hostname);
#endif
 free_aliases:
	if (add_aliases)
		gfarm_stringlist_free(&aliases);
 free_host_info:
	if (host_info_needs_free)
		gfarm_host_info_free(&hi);
	return (e);
}