From: <ta...@us...> - 2007-06-11 03:04:33
|
Revision: 3755 http://gfarm.svn.sourceforge.net/gfarm/?rev=3755&view=rev Author: tatebe Date: 2007-06-10 20:04:33 -0700 (Sun, 10 Jun 2007) Log Message: ----------- add gfs_repica_list_by_name() and gfwhere command Modified Paths: -------------- gfarm/branches/gfarm_v2/gftool/Makefile gfarm/branches/gfarm_v2/gftool/gfwhere/Makefile gfarm/branches/gfarm_v2/gftool/gfwhere/gfwhere.c gfarm/branches/gfarm_v2/include/gfarm/gfs.h gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/Makefile gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfm_client.c gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfm_client.h gfarm/branches/gfarm_v2/server/gfmd/fs.c gfarm/branches/gfarm_v2/server/gfmd/inode.c gfarm/branches/gfarm_v2/server/gfmd/inode.h Added Paths: ----------- gfarm/branches/gfarm_v2/gftool/gfwhere/gfarm_foreach.c gfarm/branches/gfarm_v2/gftool/gfwhere/gfarm_foreach.h gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_replica.c Modified: gfarm/branches/gfarm_v2/gftool/Makefile =================================================================== --- gfarm/branches/gfarm_v2/gftool/Makefile 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/gftool/Makefile 2007-06-11 03:04:33 UTC (rev 3755) @@ -19,6 +19,7 @@ gfrmdir \ gfstat \ gfuser \ + gfwhere \ config-gfarm # gfdf \ @@ -37,7 +38,6 @@ # gfstatus \ # gftest \ # gfusage \ -# gfwhere \ # gfwhoami \ # example \ Modified: gfarm/branches/gfarm_v2/gftool/gfwhere/Makefile =================================================================== --- gfarm/branches/gfarm_v2/gftool/gfwhere/Makefile 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/gftool/gfwhere/Makefile 2007-06-11 03:04:33 UTC (rev 3755) @@ -6,8 +6,8 @@ include $(top_srcdir)/makes/var.mk -SRCS = gfwhere.c -OBJS = gfwhere.o +SRCS = gfwhere.c gfarm_foreach.c +OBJS = gfwhere.o gfarm_foreach.o PROGRAM = gfwhere CFLAGS = $(COMMON_CFLAGS) -I$(GFARMLIB_SRCDIR) LDLIBS = $(COMMON_LDFLAGS) $(GFARMLIB) $(LIBS) @@ -19,4 +19,4 @@ ### -$(OBJS): $(DEPGFARMINC) $(GFARMLIB_SRCDIR)/gfarm_foreach.h +$(OBJS): $(DEPGFARMINC) gfarm_foreach.h Copied: gfarm/branches/gfarm_v2/gftool/gfwhere/gfarm_foreach.c (from rev 3754, gfarm/trunk/lib/libgfarm/gfarm/gfarm_foreach.c) =================================================================== --- gfarm/branches/gfarm_v2/gftool/gfwhere/gfarm_foreach.c (rev 0) +++ gfarm/branches/gfarm_v2/gftool/gfwhere/gfarm_foreach.c 2007-06-11 03:04:33 UTC (rev 3755) @@ -0,0 +1,79 @@ +/* + * $Id$ + */ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +#include <gfarm/gfarm.h> +#include "gfarm_foreach.h" + +gfarm_error_t +gfarm_foreach_directory_hierarchy( + gfarm_error_t (*op_file)(char *, struct gfs_stat *, void *), + gfarm_error_t (*op_dir1)(char *, struct gfs_stat *, void *), + gfarm_error_t (*op_dir2)(char *, struct gfs_stat *, void *), + char *file, void *arg) +{ + char *path, *slash; + gfarm_error_t e, e_save = GFARM_ERR_NO_ERROR; + int file_len; + struct gfs_stat st; + GFS_Dir dir; + struct gfs_dirent *dent; + + e = gfs_stat(file, &st); + if (e != GFARM_ERR_NO_ERROR) + return (e); + + /* add '/' if necessary */ + if (*gfarm_path_dir_skip(file)) + slash = "/"; + else + slash = ""; + file_len = strlen(file) + strlen(slash); + + if (GFARM_S_ISDIR(st.st_mode)) { + if (op_dir1 != NULL) { + e = op_dir1(file, &st, arg); + if (e != GFARM_ERR_NO_ERROR) + goto free_st; + } + e = gfs_opendir(file, &dir); + if (e != GFARM_ERR_NO_ERROR) + goto free_st; + + while ((e = gfs_readdir(dir, &dent)) == GFARM_ERR_NO_ERROR + && dent != NULL) { + char *d = dent->d_name; + + if (d[0] == '.' && (d[1] == '\0' || + (d[1] == '.' && d[2] == '\0'))) + continue; + + GFARM_MALLOC_ARRAY(path, file_len + strlen(d) + 1); + if (path == NULL) { + if (e_save == GFARM_ERR_NO_ERROR) + e_save = GFARM_ERR_NO_MEMORY; + continue; + } + sprintf(path, "%s%s%s", file, slash, d); + e = gfarm_foreach_directory_hierarchy( + op_file, op_dir1, op_dir2, path, arg); + free(path); + if (e_save == GFARM_ERR_NO_ERROR) + e_save = e; + } + e = gfs_closedir(dir); + if (e_save == GFARM_ERR_NO_ERROR) + e_save = e; + if (op_dir2 != NULL) + e = op_dir2(file, &st, arg); + } + else if (GFARM_S_ISREG(st.st_mode) && op_file != NULL) + e = op_file(file, &st, arg); +free_st: + gfs_stat_free(&st); + return (e_save == GFARM_ERR_NO_ERROR ? e : e_save); +} Copied: gfarm/branches/gfarm_v2/gftool/gfwhere/gfarm_foreach.h (from rev 3754, gfarm/trunk/lib/libgfarm/gfarm/gfarm_foreach.h) =================================================================== --- gfarm/branches/gfarm_v2/gftool/gfwhere/gfarm_foreach.h (rev 0) +++ gfarm/branches/gfarm_v2/gftool/gfwhere/gfarm_foreach.h 2007-06-11 03:04:33 UTC (rev 3755) @@ -0,0 +1,9 @@ +/* + * $Id$ + */ + +gfarm_error_t gfarm_foreach_directory_hierarchy( + gfarm_error_t (*)(char *, struct gfs_stat *, void *), + gfarm_error_t (*)(char *, struct gfs_stat *, void *), + gfarm_error_t (*)(char *, struct gfs_stat *, void *), + char *, void *); Modified: gfarm/branches/gfarm_v2/gftool/gfwhere/gfwhere.c =================================================================== --- gfarm/branches/gfarm_v2/gftool/gfwhere/gfwhere.c 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/gftool/gfwhere/gfwhere.c 2007-06-11 03:04:33 UTC (rev 3755) @@ -7,14 +7,11 @@ #include <fcntl.h> #include <libgen.h> #include <gfarm/gfarm.h> -#include "gfs_misc.h" #include "gfarm_foreach.h" char *program_name = "gfwhere"; -static int opt_size; - -static char * +static gfarm_error_t display_name(char *name, struct gfs_stat *st, void *arg) { static int print_ln; @@ -25,112 +22,58 @@ print_ln = 1; printf("%s:\n", name); - return (NULL); + return (GFARM_ERR_NO_ERROR); } -static char * -display_copy(struct gfarm_file_section_copy_info *info, void *arg) +static gfarm_error_t +display_copy(char *path) { - printf(" %s", info->hostname); - return (NULL); -} + int n, i; + char **hosts; + gfarm_error_t e; -static char * -display_section(char *gfarm_file, char *section) -{ - struct gfarm_file_section_info sinfo; - file_offset_t size; - char *e = NULL; - - e = gfarm_file_section_info_get(gfarm_file, section, &sinfo); - if (e != NULL) - return (e); - size = sinfo.filesize; - gfarm_file_section_info_free(&sinfo); - - printf("%s", section); - if (opt_size) - printf(" [%" PR_FILE_OFFSET " bytes]", size); - printf(":"); - - e = gfarm_foreach_copy(display_copy, gfarm_file, section, NULL, NULL); - + 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 char * -display_replica_catalog(char *gfarm_url, struct gfs_stat *st, void *arg) +static gfarm_error_t +display_replica_catalog(char *path, struct gfs_stat *st, void *arg) { - char *gfarm_file, *e = NULL, *e_save = NULL; - int i, nsections; - struct gfarm_file_section_info *sections; + gfarm_error_t e = GFARM_ERR_NO_ERROR; gfarm_mode_t mode; - char *section = arg; - display_name(gfarm_url, st, arg); + display_name(path, st, arg); mode = st->st_mode; if (GFARM_S_ISDIR(mode)) e = GFARM_ERR_IS_A_DIRECTORY; else if (!GFARM_S_ISREG(mode)) - e = "invalid file"; - if (e != NULL) { - fprintf(stderr, "%s\n", e); - return (e); - } + e = GFARM_ERR_FUNCTION_NOT_IMPLEMENTED; - e = gfarm_url_make_path(gfarm_url, &gfarm_file); - if (e != NULL) { - fprintf(stderr, "%s\n", e); - return (e); - } + if (e == GFARM_ERR_NO_ERROR) + e = display_copy(path); - /* display a speccified section */ - if (section != NULL) { - e = display_section(gfarm_file, section); - if (e != NULL) - fprintf(stderr, "%s: %s\n", section, e); - goto free_gfarm_file; - } - - /* display all sections */ - if ((mode & (S_IXUSR|S_IXGRP|S_IXOTH)) != 0) { /* program? */ - e = gfarm_file_section_info_get_all_by_file( - gfarm_file, &nsections, §ions); - } else { - e = gfarm_file_section_info_get_sorted_all_serial_by_file( - gfarm_file, &nsections, §ions); - } - if (e != NULL) { - fprintf(stderr, "%s\n", e); - goto free_gfarm_file; - } - for (i = 0; i < nsections; i++) { - e = display_section(gfarm_file, sections[i].section); - if (e != NULL) { - if (e_save == NULL) - e_save = e; - fprintf(stderr, "%s: %s\n", sections[i].section, e); - } - } - e = e_save; - gfarm_file_section_info_free_all(nsections, sections); -free_gfarm_file: - free(gfarm_file); - + if (e != GFARM_ERR_NO_ERROR) + fprintf(stderr, "%s\n", gfarm_error_string(e)); return (e); } void usage(void) { - fprintf(stderr, "Usage: %s [option] <gfarm_url>...\n", program_name); + fprintf(stderr, "Usage: %s [option] <path>...\n", program_name); fprintf(stderr, "option:\n"); - fprintf(stderr, "\t-I <fragment>\t" - "specify fragment index to be displayed\n"); - fprintf(stderr, "\t-s\t\t" - "display file size of each file fragment\n"); fprintf(stderr, "\t-r, -R\t\tdisplay subdirectories recursively\n"); exit(1); } @@ -140,7 +83,7 @@ { int argc_save = argc; char **argv_save = argv; - char *e, *section = NULL; + gfarm_error_t e, e_save = GFARM_ERR_NO_ERROR; int i, n, ch, opt_recursive = 0; gfarm_stringlist paths; gfs_glob_t types; @@ -148,18 +91,12 @@ if (argc >= 1) program_name = basename(argv[0]); - while ((ch = getopt(argc, argv, "srI:R?")) != -1) { + while ((ch = getopt(argc, argv, "rR?")) != -1) { switch (ch) { - case 's': - opt_size = 1; - break; case 'r': case 'R': opt_recursive = 1; break; - case 'I': - section = optarg; - break; case '?': default: usage(); @@ -169,8 +106,9 @@ argv += optind; e = gfarm_initialize(&argc_save, &argv_save); - if (e != NULL) { - fprintf(stderr, "%s: %s\n", program_name, e); + if (e != GFARM_ERR_NO_ERROR) { + fprintf(stderr, "%s: %s\n", program_name, + gfarm_error_string(e)); exit(1); } if (argc == 0) { @@ -178,13 +116,15 @@ } e = gfarm_stringlist_init(&paths); - if (e != NULL) { - fprintf(stderr, "%s: %s\n", program_name, e); + if (e != GFARM_ERR_NO_ERROR) { + fprintf(stderr, "%s: %s\n", program_name, + gfarm_error_string(e)); exit(EXIT_FAILURE); } e = gfs_glob_init(&types); - if (e != NULL) { - fprintf(stderr, "%s: %s\n", program_name, e); + if (e != GFARM_ERR_NO_ERROR) { + fprintf(stderr, "%s: %s\n", program_name, + gfarm_error_string(e)); exit(EXIT_FAILURE); } for (i = 0; i < argc; i++) @@ -196,26 +136,29 @@ char *p = gfarm_stringlist_elem(&paths, i); struct gfs_stat st; - if ((e = gfs_stat(p, &st)) != NULL) { - fprintf(stderr, "%s: %s\n", p, e); + if ((e = gfs_stat(p, &st)) != GFARM_ERR_NO_ERROR) { + fprintf(stderr, "%s: %s\n", p, gfarm_error_string(e)); } else { if (GFARM_S_ISREG(st.st_mode)) - display_replica_catalog(p, &st, section); + e = display_replica_catalog(p, &st, NULL); else if (opt_recursive) - (void)gfarm_foreach_directory_hierarchy( + e = gfarm_foreach_directory_hierarchy( display_replica_catalog, display_name, - NULL, p, section); + NULL, p, NULL); else fprintf(stderr, "%s: not a file\n", p); gfs_stat_free(&st); + if (e_save == GFARM_ERR_NO_ERROR) + e_save = e; } } gfarm_stringlist_free_deeply(&paths); e = gfarm_terminate(); - if (e != NULL) { - fprintf(stderr, "%s: %s\n", program_name, e); + if (e != GFARM_ERR_NO_ERROR) { + fprintf(stderr, "%s: %s\n", program_name, + gfarm_error_string(e)); exit(1); } - return (e == NULL ? 0 : 1); + return (e_save == GFARM_ERR_NO_ERROR ? 0 : 1); } Modified: gfarm/branches/gfarm_v2/include/gfarm/gfs.h =================================================================== --- gfarm/branches/gfarm_v2/include/gfarm/gfs.h 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/include/gfarm/gfs.h 2007-06-11 03:04:33 UTC (rev 3755) @@ -228,6 +228,7 @@ #define GFS_R_OK 4 gfarm_error_t gfs_replicate_from_to(char *, char *, int, char *, int); +gfarm_error_t gfs_replica_list_by_name(const char *, int *, char ***); gfarm_error_t gfs_execve(const char *, char *const *, char *const *); Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/Makefile =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/Makefile 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/Makefile 2007-06-11 03:04:33 UTC (rev 3755) @@ -50,6 +50,7 @@ gfs_rmdir.c \ gfs_remove.c \ gfs_rename.c \ + gfs_replica.c \ gfs_replicate.c \ gfs_unlink.c \ glob.c \ @@ -99,6 +100,7 @@ gfs_rmdir.lo \ gfs_remove.lo \ gfs_rename.lo \ + gfs_replica.lo \ gfs_replicate.lo \ gfs_unlink.lo \ glob.lo \ @@ -146,6 +148,7 @@ gfs_pio_remote.lo: host.h config.h gfs_proto.h gfs_client.h gfs_pio.h gfs_pio_section.lo: gfs_pio.h host.h config.h schedule.h gfs_client.h gfs_proto.h $(GFUTIL_SRCDIR)/timer.h gfs_proto.lo: gfs_proto.h +gfs_replica.lo: $(GFUTIL_SRCDIR)/gfutil.h gfm_client.h config.h lookup.h gfs_replicate.lo: $(GFUTIL_SRCDIR)/gfutil.h config.h gfs_client.h gfs_unlink.lo: config.h gfs_client.h gfs_pio.h gfs_misc.h $(GFUTIL_SRCDIR)/timer.h glob.lo: Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfm_client.c =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfm_client.c 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfm_client.c 2007-06-11 03:04:33 UTC (rev 3755) @@ -1363,40 +1363,36 @@ gfarm_error_t gfm_client_replica_list_by_name_result(struct gfm_connection *gfm_server, - gfarm_int32_t *n_replicasp, char ***replica_hosts, int **replica_ports) + gfarm_int32_t *n_replicasp, char ***replica_hosts) { gfarm_error_t e; int eof, i; gfarm_int32_t n; char **hosts; - int *ports; e = gfm_client_rpc_result(gfm_server, 0, "i", &n); if (e != GFARM_ERR_NO_ERROR) return (e); GFARM_MALLOC_ARRAY(hosts, n); - GFARM_MALLOC_ARRAY(ports, n); - if (hosts == NULL || ports == NULL) { - if (hosts != NULL) - free(hosts); - if (ports != NULL) - free(ports); + if (hosts == NULL) return (GFARM_ERR_NO_MEMORY); /* XXX not graceful */ - } + for (i = 0; i < n; i++) { - e = gfp_xdr_recv(gfm_server->conn, 0, &eof, "si", - &hosts[i], &ports[i]); + e = gfp_xdr_recv(gfm_server->conn, 0, &eof, "s", &hosts[i]); if (e != GFARM_ERR_NO_ERROR || eof) { if (e == GFARM_ERR_NO_ERROR) e = GFARM_ERR_PROTOCOL; - free(hosts); - free(ports); - return (e); + break; } } + if (i < n) { + for (; i >= 0; --i) + free(hosts[i]); + free(hosts); + return (e); + } *n_replicasp = n; *replica_hosts = hosts; - *replica_ports = ports; return (GFARM_ERR_NO_ERROR); } Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfm_client.h =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfm_client.h 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfm_client.h 2007-06-11 03:04:33 UTC (rev 3755) @@ -213,7 +213,7 @@ /* replica management from client */ gfarm_error_t gfm_client_replica_list_by_name_request(struct gfm_connection *); gfarm_error_t gfm_client_replica_list_by_name_result(struct gfm_connection *, - gfarm_int32_t *, char ***, int **); + gfarm_int32_t *, char ***); gfarm_error_t gfm_client_replica_list_by_host_request(struct gfm_connection *, const char *, gfarm_int32_t); gfarm_error_t gfm_client_replica_list_by_host_result(struct gfm_connection *, Added: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_replica.c =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_replica.c (rev 0) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_replica.c 2007-06-11 03:04:33 UTC (rev 3755) @@ -0,0 +1,70 @@ +/* + * $Id$ + */ + +#include <stdio.h> /* config.h needs FILE */ +#include <stdlib.h> + +#define GFARM_INTERNAL_USE +#include <gfarm/gfarm.h> + +#include "gfutil.h" + +#include "gfm_client.h" +#include "config.h" +#include "lookup.h" + +gfarm_error_t +gfs_replica_list_by_name(const char *path, int *np, char ***hostsp) +{ + gfarm_error_t e; + gfarm_int32_t n; + char **hosts; + + if ((e = gfm_client_compound_begin_request(gfarm_metadb_server)) + != GFARM_ERR_NO_ERROR) + gflog_warning("compound_begin request: %s", + gfarm_error_string(e)); + else if ((e = gfm_tmp_open_request(gfarm_metadb_server, path, + GFARM_FILE_LOOKUP)) != GFARM_ERR_NO_ERROR) + gflog_warning("tmp_open(%s) request: %s", path, + gfarm_error_string(e)); + else if ((e = gfm_client_replica_list_by_name_request( + gfarm_metadb_server)) + != GFARM_ERR_NO_ERROR) + gflog_warning("replica_list_by_name request: %s", + gfarm_error_string(e)); + else if ((e = gfm_client_compound_end_request(gfarm_metadb_server)) + != GFARM_ERR_NO_ERROR) + gflog_warning("compound_end request: %s", + gfarm_error_string(e)); + + else if ((e = gfm_client_compound_begin_result(gfarm_metadb_server)) + != GFARM_ERR_NO_ERROR) + gflog_warning("compound_begin result: %s", + gfarm_error_string(e)); + else if ((e = gfm_tmp_open_result(gfarm_metadb_server, path, NULL)) + != GFARM_ERR_NO_ERROR) + gflog_warning("tmp_open(%s) result: %s", path, + gfarm_error_string(e)); + else if ((e = gfm_client_replica_list_by_name_result( + gfarm_metadb_server, &n, &hosts)) + != GFARM_ERR_NO_ERROR) + gflog_warning("replica_list_by_name result: %s", + gfarm_error_string(e)); + else if ((e = gfm_client_compound_end_result(gfarm_metadb_server)) + != GFARM_ERR_NO_ERROR) { + gflog_warning("compound_end result: %s", + gfarm_error_string(e)); + while (--n >= 0) + free(hosts[n]); + free(hosts); + } + /* NOTE: the opened descriptor is automatically closed by gfmd */ + + if (e == GFARM_ERR_NO_ERROR) { + *np = n; + *hostsp = hosts; + } + return (e); +} Modified: gfarm/branches/gfarm_v2/server/gfmd/fs.c =================================================================== --- gfarm/branches/gfarm_v2/server/gfmd/fs.c 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/server/gfmd/fs.c 2007-06-11 03:04:33 UTC (rev 3755) @@ -1501,14 +1501,43 @@ gfm_server_replica_list_by_name(struct peer *peer, int from_client, int skip) { gfarm_error_t e; + struct host *spool_host; + struct process *process; + int fd, i; + gfarm_int32_t n; + struct inode *inode; + char **hosts; - /* XXX - NOT IMPLEMENTED */ - gflog_error("replica_list_by_name: not implemented"); + if (skip) + return (GFARM_ERR_NO_ERROR); + giant_lock(); - e = gfm_server_put_reply(peer, "replica_list_by_name", - GFARM_ERR_FUNCTION_NOT_IMPLEMENTED, ""); - return (e != GFARM_ERR_NO_ERROR ? e : - GFARM_ERR_FUNCTION_NOT_IMPLEMENTED); + if (!from_client && (spool_host = peer_get_host(peer)) == NULL) + e = GFARM_ERR_OPERATION_NOT_PERMITTED; + else if ((process = peer_get_process(peer)) == NULL) + e = GFARM_ERR_OPERATION_NOT_PERMITTED; + else if ((e = peer_fdpair_get_current(peer, &fd)) != + GFARM_ERR_NO_ERROR) + ; + else if ((e = process_get_file_inode(process, fd, &inode)) + != GFARM_ERR_NO_ERROR) + ; + else + e = inode_replica_list_by_name(inode, &n, &hosts); + + giant_unlock(); + e = gfm_server_put_reply(peer, "replica_list_by_name", e, "i", n); + if (e == GFARM_ERR_NO_ERROR) { + for (i = 0; i < n; ++i) { + e = gfp_xdr_send(peer_get_conn(peer), "s", hosts[i]); + if (e != GFARM_ERR_NO_ERROR) + break; + } + while (--i >= 0) + free(hosts[i]); + free(hosts); + } + return (e); } gfarm_error_t Modified: gfarm/branches/gfarm_v2/server/gfmd/inode.c =================================================================== --- gfarm/branches/gfarm_v2/server/gfmd/inode.c 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/server/gfmd/inode.c 2007-06-11 03:04:33 UTC (rev 3755) @@ -1597,7 +1597,47 @@ return (e_save); } +gfarm_error_t +inode_replica_list_by_name(struct inode *inode, + gfarm_int32_t *np, char ***hostsp) +{ + struct file_copy *copy; + gfarm_error_t e = GFARM_ERR_NO_ERROR; + int n, i; + char **hosts; + if (!inode_is_file(inode)) + gflog_fatal("inode_has_replica: not a file"); + + n = inode_get_ncopy(inode); + GFARM_MALLOC_ARRAY(hosts, n); + if (hosts == NULL) + return (GFARM_ERR_NO_MEMORY); + + i = 0; + for (copy = inode->u.c.s.f.copies; copy != NULL && i < n; + copy = copy->host_next) { + if (copy->valid) { + hosts[i] = strdup(host_name(copy->host)); + if (hosts[i] == NULL) { + e = GFARM_ERR_NO_MEMORY; + break; + } + ++i; + } + } + if (i < n) { + while (--i >= 0) + free(hosts[i]); + free(hosts); + } + else { + *np = n; + *hostsp = hosts; + } + return (e); +} + /* * loading metadata from persistent storage. */ Modified: gfarm/branches/gfarm_v2/server/gfmd/inode.h =================================================================== --- gfarm/branches/gfarm_v2/server/gfmd/inode.h 2007-06-09 14:47:20 UTC (rev 3754) +++ gfarm/branches/gfarm_v2/server/gfmd/inode.h 2007-06-11 03:04:33 UTC (rev 3755) @@ -80,6 +80,9 @@ gfarm_error_t inode_schedule_file_reply(struct inode *, struct peer *, int, int, const char *); +gfarm_error_t inode_replica_list_by_name(struct inode *, + gfarm_int32_t *, char ***); + /* debug */ void dir_dump(gfarm_ino_t); void rootdir_dump(void); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |