static gfarm_error_t display_copy(char *path) { int n, i; char **hosts; gfarm_error_t e; e = gfs_replica_list_by_name(path, &n, &hosts); if (e == GFARM_ERR_NO_ERROR) { i = 0; if (i < n) printf("%s", hosts[i++]); for (; i < n; ++i) printf(" %s", hosts[i]); for (i = 0; i < n; ++i) free(hosts[i]); free(hosts); } printf("\n"); return (e); }
static gfarm_error_t create_filelist(char *file, struct gfs_stat *st, void *arg) { struct flist *a = arg; int i, j, ncopy, src_ncopy = 0, dst_ncopy = 0; char **copy; gfarm_error_t e; if (!GFARM_S_ISREG(st->st_mode)) { if (opt_verbose) printf("%s: not a regular file, skipped\n", file); return (GFARM_ERR_NO_ERROR); } e = gfs_replica_list_by_name(file, &ncopy, ©); if (e != GFARM_ERR_NO_ERROR) return (e); /* if there is no available file replica, display error message */ if (ncopy == 0 && st->st_size > 0) { fprintf(stderr, "%s: no available file repilca\n", file); e = GFARM_ERR_NO_ERROR; goto free_copy; } for (i = 0; i < ncopy; ++i) { if ((a->src_hosthash == NULL || gfarm_hash_lookup( a->src_hosthash, copy[i], strlen(copy[i]) + 1)) && gfarm_host_is_in_domain(copy[i], a->src_domain)) { ++src_ncopy; } if ((a->dst_hosthash == NULL || gfarm_hash_lookup( a->dst_hosthash, copy[i], strlen(copy[i]) + 1)) && gfarm_host_is_in_domain(copy[i], a->dst_domain)) { ++dst_ncopy; } } /* * if there is no replica in a set of source nodes or there * are already specified number of replicas in a set of * destination nodes, do not add. */ if (src_ncopy == 0 || dst_ncopy == opt_nrep) { e = GFARM_ERR_NO_ERROR; goto free_copy; } /* add source nodes to srchash to count the number of source nodes */ for (i = 0; i < ncopy; ++i) { char *s = copy[i]; if ((a->src_hosthash == NULL || gfarm_hash_lookup( a->src_hosthash, s, strlen(s) + 1)) && gfarm_host_is_in_domain(s, a->src_domain)) gfarm_hash_enter(a->srchash, s, strlen(s)+1, 0, NULL); } /* add a file info to slist */ for (j = 0; j < opt_nrep - dst_ncopy; ++j) { e = gfarm_list_add_file_info(file, st->st_size, ncopy, copy, 0, &a->slist); if (e != GFARM_ERR_NO_ERROR) goto free_copy; } /* add a file info to dlist if too many file replicas exist */ if (dst_ncopy > opt_nrep) { e = gfarm_list_add_file_info(file, st->st_size, ncopy, copy, dst_ncopy - opt_nrep, &a->dlist); } free_copy: gfarm_strings_free_deeply(ncopy, copy); return (e); }