static gfarm_error_t create_hosthash_from_file(char *hostfile, int hashsize, struct gfarm_hash_table **hashp) { int error_line = -1, nhosts; gfarm_error_t e; char **hosts; if (hostfile == NULL) { *hashp = NULL; return (GFARM_ERR_NO_ERROR); } e = gfarm_hostlist_read(hostfile, &nhosts, &hosts, &error_line); if (e != GFARM_ERR_NO_ERROR) { if (error_line != -1) fprintf(stderr, "%s: line %d: %s\n", hostfile, error_line, gfarm_error_string(e)); else fprintf(stderr, "%s: %s\n", hostfile, gfarm_error_string(e)); exit(EXIT_FAILURE); } e = create_hash_table_from_string_list(nhosts, hosts, HOSTHASH_SIZE, hashp); gfarm_strings_free_deeply(nhosts, hosts); return (e); }
int gfsk_gfarm_init(uid_t uid) { gfarm_error_t e; e = gfarm_context_init(); if (e != GFARM_ERR_NO_ERROR) { gflog_error(GFARM_MSG_UNFIXED, "gfarm_context_init failed: %s", gfarm_error_string(e)); goto out; } e = gfarm_set_local_user_for_this_uid(uid); if (e != GFARM_ERR_NO_ERROR) { gflog_error(GFARM_MSG_UNFIXED, "gfarm_set_local_user_for_this_uid failed: %s", gfarm_error_string(e)); goto out; } gflog_initialize(); e = gfarm_config_read(); if (e != GFARM_ERR_NO_ERROR) { gflog_error(GFARM_MSG_UNFIXED, "gfarm_config_read() failed: %s", gfarm_error_string(e)); goto out; } out: return (-gfarm_error_to_errno(e)); }
/* * the following function is for client, * server/daemon process shouldn't call it. * Because this function may read incorrect setting from user specified * $USER or $HOME. */ gfarm_error_t gfarm_config_read(void) { gfarm_error_t e; char *home; FILE *config; int lineno, user_config_errno, rc_need_free;; static char gfarm_client_rc[] = GFARM_CLIENT_RC; char *rc; rc_need_free = 0; rc = getenv("GFARM_CONFIG_FILE"); if (rc == NULL) { /* * result of gfarm_get_local_homedir() should not be trusted. * (maybe forged) */ home = gfarm_get_local_homedir(); GFARM_MALLOC_ARRAY(rc, strlen(home) + 1 + sizeof(gfarm_client_rc)); if (rc == NULL) return (GFARM_ERR_NO_MEMORY); sprintf(rc, "%s/%s", home, gfarm_client_rc); rc_need_free = 1; } gfarm_init_user_map(); if ((config = fopen(rc, "r")) == NULL) { user_config_errno = errno; } else { user_config_errno = 0; e = gfarm_config_read_file(config, &lineno); if (e != GFARM_ERR_NO_ERROR) { gflog_error("%s: %d: %s", rc, lineno, gfarm_error_string(e)); if (rc_need_free) free(rc); return (e); } } if (rc_need_free) free(rc); if ((config = fopen(gfarm_config_file, "r")) == NULL) { if (user_config_errno != 0) return (GFARM_ERRMSG_CANNOT_OPEN_CONFIG); } else { e = gfarm_config_read_file(config, &lineno); if (e != GFARM_ERR_NO_ERROR) { gflog_error("%s: %d: %s", gfarm_config_file, lineno, gfarm_error_string(e)); return (e); } } gfarm_config_set_default_ports(); gfarm_config_set_default_misc(); return (GFARM_ERR_NO_ERROR); }
/* the following function is for server. */ gfarm_error_t gfarm_server_initialize(char *config_file, int *argcp, char ***argvp) { gfarm_error_t e; if ((e = gfarm_context_init()) != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_1003684, "gfarm_context_init failed: %s", gfarm_error_string(e)); return (e); } gflog_initialize(); if (argvp) gfarm_config_set_argv0(**argvp); if (config_file != NULL) gfarm_config_set_filename(config_file); e = gfarm_server_config_read(); if (e != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_1000977, "gfarm_server_config_read() failed: %s", gfarm_error_string(e)); return (e); } gfarm_setup_debug_command(); gfarm_config_set_default_spool_on_server(); return (GFARM_ERR_NO_ERROR); }
gfarm_error_t gfm_client_rpc_with_failover( gfarm_error_t (*rpc_op)(struct gfm_connection **, void *), gfarm_error_t (*post_failover_op)(struct gfm_connection *, void *), void (*exit_op)(struct gfm_connection *, gfarm_error_t, void *), int (*must_be_warned_op)(gfarm_error_t, void *), void *closure) { gfarm_error_t e; struct gfm_connection *gfm_server; int nretry = 1, post_nretry = 1; retry: gfm_server = NULL; e = rpc_op(&gfm_server, closure); if (nretry > 0 && gfm_client_connection_should_failover( gfm_server, e)) { if ((e = failover(gfm_server)) != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_1003865, "failover: %s", gfarm_error_string(e)); } else if (post_failover_op && (e = post_failover_op(gfm_server, closure)) != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_1003866, "post_failover_op: %s", gfarm_error_string(e)); if (gfm_client_is_connection_error(e) && post_nretry > 0) { /* * following cases: * - acquired conneciton in failover() is * created before failover(). * - connection error occurred after failover(). */ post_nretry--; goto retry; } } else { nretry--; goto retry; } } else if (e != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_1003867, "gfm_client_rpc_with_failover: rpc_op: %s", gfarm_error_string(e)); if (nretry == 0 && must_be_warned_op && must_be_warned_op(e, closure)) gflog_warning(GFARM_MSG_1003868, "error ocurred at retry for the operation after " "connection to metadb server was failed over, " "so the operation possibly succeeded in the server." " error='%s'", gfarm_error_string(e)); } if (exit_op) exit_op(gfm_server, e, closure); return (e); }
static gfarm_error_t gfs_pio_reopen(struct gfarm_filesystem *fs, GFS_File gf) { gfarm_error_t e; struct gfm_connection *gfm_server; int fd, type; gfarm_ino_t ino; char *real_url = NULL; /* avoid failover in gfm_open_fd_with_ino() */ gfarm_filesystem_set_failover_detected(fs, 0); /* increment ref count of gfm_server */ if ((e = gfm_open_fd_with_ino(gf->url, gf->open_flags & (~GFARM_FILE_TRUNC), &gfm_server, &fd, &type, &real_url, &ino)) != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_1003380, "reopen operation on file descriptor for URL (%s) " "failed: %s", gf->url, gfarm_error_string(e)); free(real_url); return (e); } else if (gfm_server != gf->gfm_server || type != GFS_DT_REG || ino != gf->ino) { e = GFARM_ERR_STALE_FILE_HANDLE; } else { gf->fd = fd; /* storage_context is null in scheduling */ if (get_storage_context(gf->view_context) != NULL) e = (*gf->ops->view_reopen)(gf); } if (e == GFARM_ERR_NO_ERROR) { if (real_url != NULL) { free(gf->url); gf->url = real_url; } } else { if (real_url != NULL) { free(real_url); } (void)gfm_close_fd(gfm_server, fd); /* ignore result */ gf->fd = GFARM_DESCRIPTOR_INVALID; gf->error = e; gflog_debug(GFARM_MSG_1003381, "reopen operation on pio for URL (%s) failed: %s", gf->url, gfarm_error_string(e)); } /* decrement ref count of gfm_server. then we'll use gf->gfm_server */ gfm_client_connection_free(gfm_server); return (e); }
/* assert(0); */ return; } #ifndef __KERNEL__ /* gfarm_sockaddr_to_name:: apl */ gfarm_error_t gfarm_sockaddr_to_name(struct sockaddr *addr, char **namep) { struct addrinfo hints, *res, *res0; struct sockaddr_in *sin1, *sin2; char *s, name[NI_MAXHOST]; if (gfarm_getnameinfo(addr, sizeof(*addr), name, sizeof(name), NULL, 0, NI_NAMEREQD) != 0) { gflog_debug(GFARM_MSG_1000863, "Cannot get name info from IP address: %s", gfarm_error_string( GFARM_ERR_CANNOT_RESOLVE_AN_IP_ADDRESS_INTO_A_HOSTNAME)); return (GFARM_ERR_CANNOT_RESOLVE_AN_IP_ADDRESS_INTO_A_HOSTNAME); } memset(&hints, 0, sizeof(hints)); hints.ai_family = addr->sa_family; if (gfarm_getaddrinfo(name, NULL, &hints, &res0) != 0) { gflog_debug(GFARM_MSG_1000864, "gfarm_getaddrinfo() failed: %s", gfarm_error_string( GFARM_ERRMSG_REVERSE_LOOKUP_NAME_IS_NOT_RESOLVABLE)); return (GFARM_ERRMSG_REVERSE_LOOKUP_NAME_IS_NOT_RESOLVABLE); } for (res = res0; res; res = res->ai_next) { if (res->ai_family != addr->sa_family) continue; switch (res->ai_family) { case AF_INET: sin1 = (struct sockaddr_in *)res->ai_addr; sin2 = (struct sockaddr_in *)addr; if (sin1->sin_addr.s_addr == sin2->sin_addr.s_addr) { s = strdup(name); gfarm_freeaddrinfo(res0); if (s == NULL) { gflog_debug(GFARM_MSG_1000865, "allocation of string failed:" " %s", gfarm_error_string( GFARM_ERR_NO_MEMORY)); return (GFARM_ERR_NO_MEMORY); } *namep = s; return (GFARM_ERR_NO_ERROR); /* success */ } break; } } gfarm_freeaddrinfo(res0); return (GFARM_ERRMSG_REVERSE_LOOKUP_NAME_DOES_NOT_MATCH); }
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 = ¶m->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, ¶m->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)); }
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); }
/* convert from uncached connection to cached */ static inline gfarm_error_t gfp_uncached_connection_into_cache(struct gfp_conn_cache *cache, struct gfp_cached_connection *connection, void (*func)(struct gfarm_lru_cache *, struct gfarm_lru_entry *)) { gfarm_error_t e; struct gfarm_hash_entry *entry; int created; static const char diag[] = "gfp_uncached_connection_enter_cache"; if (GFP_IS_CACHED_CONNECTION(connection)) { gflog_fatal(GFARM_MSG_1000057, "gfp_uncached_connection_enter_cache(%s): " "programming error", cache->type_name); } gfarm_mutex_lock(&cache->mutex, diag, diag_what); e = gfp_conn_hash_id_enter_noalloc(&cache->hashtab, cache->table_size, sizeof(connection), &connection->id, &entry, &created); if (e != GFARM_ERR_NO_ERROR) { gfarm_mutex_unlock(&cache->mutex, diag, diag_what); gflog_debug(GFARM_MSG_1001088, "insertion to connection hash (%s)(%d) failed: %s", gfp_cached_connection_hostname(connection), gfp_cached_connection_port(connection), gfarm_error_string(e)); return (e); } if (!created) { gfarm_mutex_unlock(&cache->mutex, diag, diag_what); gflog_debug(GFARM_MSG_1001089, "insertion to connection hash (%s)(%d) failed: %s", gfp_cached_connection_hostname(connection), gfp_cached_connection_port(connection), gfarm_error_string(GFARM_ERR_ALREADY_EXISTS)); return (GFARM_ERR_ALREADY_EXISTS); } func(&cache->lru_list, &connection->lru_entry); *(struct gfp_cached_connection **)gfarm_hash_entry_data(entry) = connection; connection->hash_entry = entry; gfarm_mutex_unlock(&cache->mutex, diag, diag_what); return (GFARM_ERR_NO_ERROR); }
int main(int argc, char **argv) { gfarm_error_t e; int i, c, status = 0; char *path = NULL; 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(1); } while ((c = getopt(argc, argv, "h?")) != -1) { switch (c) { case 'h': case '?': default: usage(); } } argc -= optind; argv += optind; if (argc <= 0) usage(); for (i = 0; i < argc; i++) { e = gfarm_realpath_by_gfarm2fs(argv[i], &path); if (e == GFARM_ERR_NO_ERROR) argv[i] = path; e = gfs_rmdir(argv[i]); if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "%s: %s: %s\n", program_name, argv[i], gfarm_error_string(e)); status = 1; } free(path); } e = gfarm_terminate(); if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "%s: %s\n", program_name, gfarm_error_string(e)); status = 1; } return (status); }
gfarm_error_t list_all(const char *architecture, const char *domainname, 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, nhosts; struct gfarm_host_info *hosts; if (architecture != NULL) e = gfm_client_host_info_get_by_architecture( gfarm_metadb_server, architecture, &nhosts, &hosts); else e = gfm_client_host_info_get_all( gfarm_metadb_server, &nhosts, &hosts); if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "%s: %s\n", program_name, gfarm_error_string(e)); return (e); } for (i = 0; i < nhosts; i++) { if (domainname == NULL || gfarm_host_is_in_domain(hosts[i].hostname, domainname)) { e = (*request_op)(&hosts[i], pa); if (e_save == GFARM_ERR_NO_ERROR) e_save = e; } } gfarm_host_info_free_all(nhosts, hosts); return (e_save); }
static gfarm_error_t usage_group_all() { struct gfarm_group_info *groups; gfarm_error_t e, e_save = GFARM_ERR_NO_ERROR; int ngroups, i, success = 0; e = gfm_client_group_info_get_all(gfm_server, &ngroups, &groups); if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "%s: gfm_client_group_info_get_all: %s\n", program_name, gfarm_error_string(e)); return (e); } print_header_group(); for (i = 0; i < ngroups; i++) { e = print_usage_group(groups[i].groupname); if (e == GFARM_ERR_NO_ERROR) success++; else { /* GFARM_ERR_NO_SUCH_OBJECT is preferred */ if (e == GFARM_ERR_NO_SUCH_OBJECT) e_save = e; if (e_save == GFARM_ERR_NO_ERROR) e_save = e; } gfarm_group_info_free(&groups[i]); } free(groups); if (success > 0) return (GFARM_ERR_NO_ERROR); else return (e_save); }
static gfarm_error_t print_usage_common(const char *name, int opt_group) { struct gfarm_quota_get_info qi; gfarm_error_t e; if (opt_group) e = gfm_client_quota_group_get(gfm_server, name, &qi); else e = gfm_client_quota_user_get(gfm_server, name, &qi); if (e == GFARM_ERR_OPERATION_NOT_PERMITTED) /* not report here */ return (e); else if (e == GFARM_ERR_NO_SUCH_OBJECT) { /* not enabled */ fprintf(stderr, "%s : quota is not enabled.\n", name); return (e); } else if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "%s: %s : %s\n", program_name, name, gfarm_error_string(e)); return (e); } else { printf("%12s :" " %15"GFARM_PRId64" %11"GFARM_PRId64 " %15"GFARM_PRId64" %11"GFARM_PRId64"\n" , name, qi.space, qi.num, qi.phy_space, qi.phy_num); gfarm_quota_get_info_free(&qi); return (GFARM_ERR_NO_ERROR); } }
gfarm_error_t request_nodename(struct gfarm_host_info *host_info, struct gfarm_paraccess *pa) { gfarm_error_t e; char *canonical_hostname; struct sockaddr addr; /* dup `host_info->hostname' -> `hostname' */ canonical_hostname = strdup(host_info->hostname); if (canonical_hostname == NULL) { e = GFARM_ERR_NO_MEMORY; fprintf(stderr, "%s: %s\n", program_name, gfarm_error_string(e)); return (e); } e = (*opt_resolv_addr)( canonical_hostname, host_info->port, host_info, &addr, NULL); if (e != GFARM_ERR_NO_ERROR) { output_process(NULL, canonical_hostname, NULL, NULL, NULL, e); return (e); } return (gfarm_paraccess_request(pa, NULL, canonical_hostname, host_info->port, &addr)); }
static gfarm_error_t display_group(int op, int n, char *names[], gfarm_error_t *errs, struct gfarm_group_info *groups) { gfarm_error_t e = GFARM_ERR_NO_ERROR; int i, j; for (i = 0; i < n; ++i) { if (errs != NULL && errs[i] != GFARM_ERR_NO_ERROR) { assert(names != NULL); fprintf(stderr, "%s: %s\n", names[i], gfarm_error_string(errs[i])); if (e == GFARM_ERR_NO_ERROR) e = errs[i]; continue; } printf("%s", groups[i].groupname); if (op == OP_LIST_LONG) { printf(":"); for (j = 0; j < groups[i].nusers; ++j) printf(" %s", groups[i].usernames[j]); } puts(""); gfarm_group_info_free(&groups[i]); } return (e); }
/* * Note that this may be called when opt_use_metadb == 0. * In that case, the host_info is faked, and all members in the info structure * except info->hostname are not valid. (see list_gfsd_info()) */ gfarm_error_t request_gfsd_info(struct gfarm_host_info *info, struct gfarm_paraccess *pa) { gfarm_error_t e; struct sockaddr addr; char *canonical_hostname, *if_hostname; canonical_hostname = strdup(info->hostname); if (canonical_hostname == NULL) { e = GFARM_ERR_NO_MEMORY; } else { e = (*opt_resolv_addr)( canonical_hostname, info->port, info, &addr, &if_hostname); } if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "%s: %s\n", info->hostname, gfarm_error_string(e)); if (canonical_hostname != NULL) free(canonical_hostname); return (e); } return (gfarm_paraccess_request(pa, if_hostname, canonical_hostname, info->port, &addr)); }
static gfarm_error_t gfs_pio_local_storage_fsync(GFS_File gf, int operation) { struct gfs_file_section_context *vc = gf->view_context; int rv; switch (operation) { case GFS_PROTO_FSYNC_WITHOUT_METADATA: #ifdef HAVE_FDATASYNC rv = fdatasync(vc->fd); break; #else /*FALLTHROUGH*/ #endif case GFS_PROTO_FSYNC_WITH_METADATA: rv = fsync(vc->fd); break; default: gflog_debug(GFARM_MSG_1001369, "Invalid operation (%d): %s", operation, gfarm_error_string(GFARM_ERR_INVALID_ARGUMENT)); return (GFARM_ERR_INVALID_ARGUMENT); } if (rv == -1) { int save_errno = errno; gflog_debug(GFARM_MSG_1001370, "fsync() or fdatasync() on view context " "file descriptor failed: %s", strerror(save_errno)); return (gfarm_errno_to_error(save_errno)); } return (GFARM_ERR_NO_ERROR); }
static gfarm_error_t acquire_valid_connection(struct gfm_connection *gfm_server, const char *host, int port, const char *user, struct gfarm_filesystem *fs) { gfarm_error_t e; int fc = gfarm_filesystem_failover_count(fs); int acquired = 0; while (fc > gfm_client_connection_failover_count(gfm_server)) { gfm_client_purge_from_cache(gfm_server); if (acquired) gfm_client_connection_free(gfm_server); if ((e = gfm_client_connection_and_process_acquire( host, port, user, &gfm_server)) != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_1003860, "gfm_client_connection_and_process_acquire: %s", gfarm_error_string(e)); return (e); } acquired = 1; } if (acquired) gfm_client_connection_free(gfm_server); gfarm_filesystem_set_failover_detected(fs, 0); return (GFARM_ERR_NO_ERROR); }
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); }
static gfarm_error_t get_inonum_result(struct gfm_connection *conn, struct gfp_xdr_context *ctx, struct file_info *f, int stat_or_open, int open_parent) { gfarm_error_t e; const char *errf; gfarm_ino_t ino; gfarm_mode_t mode; gfarm_uint64_t gen; struct gfs_stat st; if (stat_or_open) { if ((e = gfm_client_fstat_result(conn, ctx, &st)) != GFARM_ERR_NO_ERROR) errf = "gfm_client_fstat_result"; else f->ino = st.st_ino; } else if ((e = gfm_client_open_result( conn, ctx, &ino, &gen, &mode)) != GFARM_ERR_NO_ERROR) { errf = "gfm_client_open_result"; } else f->ino = ino; if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "get_inonum_result : %s : %s\n", errf, gfarm_error_string(e)); return (e); } return (e); }
static gfarm_error_t get_inonum_request(struct gfm_connection *conn, struct gfp_xdr_context *ctx, struct file_info *f, int stat_or_open, int open_parent) { gfarm_error_t e; const char *errf; const char *name; assert(strlen(f->name) > 0 || stat_or_open); name = open_parent ? "." : f->name; if (stat_or_open) { if ((e = gfm_client_fstat_request(conn, ctx)) != GFARM_ERR_NO_ERROR) errf = "gfm_client_fstat_request"; } else if ((e = gfm_client_open_request(conn, ctx, name, strlen(name), GFARM_FILE_RDONLY)) != GFARM_ERR_NO_ERROR) { errf = "gfm_client_open_request"; } if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "get_inonum_request : %s : %s\n", errf, gfarm_error_string(e)); return (e); } return (GFARM_ERR_NO_ERROR); }
/* the following function is for server. */ gfarm_error_t gfarm_server_config_read(void) { gfarm_error_t e; int lineno; FILE *config; char *config_file = gfarm_config_get_filename(); gfarm_init_config(); if ((config = fopen(config_file, "r")) == NULL) { gflog_debug(GFARM_MSG_1000976, "open operation on server config file (%s) failed", config_file); return (GFARM_ERRMSG_CANNOT_OPEN_CONFIG); } e = gfarm_config_read_file(config, &lineno); if (e != GFARM_ERR_NO_ERROR) { gflog_error(GFARM_MSG_1000014, "%s: line %d: %s", config_file, lineno, gfarm_error_string(e)); return (e); } gfarm_config_set_default_ports(); gfarm_config_set_default_misc(); return (GFARM_ERR_NO_ERROR); }
static int remove_replicas(struct file_info *fi, int ncopy, int nhost, char **host) { int i, j, k; gfarm_error_t e, e_save = GFARM_ERR_NO_ERROR; i = 0; /* XXX - linear search */ for (j = 0; j < fi->ncopy && i < ncopy; ++j) for (k = 0; k < nhost && i < ncopy; ++k) { if (strcmp(fi->copy[j], host[k]) == 0) { if (opt_verbose) { printf("remove %s on %s\n", fi->pathname, host[k]); fflush(stdout); } e = gfs_replica_remove_by_file( fi->pathname, host[k]); if (e == GFARM_ERR_NO_ERROR) ++i; else if (e == GFARM_ERR_INSUFFICIENT_NUMBER_OF_FILE_REPLICAS) { e_save = e; break; } else { /* error is always overwritten */ e_save = e; fprintf(stderr, "%s: %s\n", fi->pathname, gfarm_error_string(e)); } } } return (i >= ncopy ? GFARM_ERR_NO_ERROR : e_save); }
/* FIXME: should support return values other than gfarm_error_t too */ void gfm_async_server_reply_to_gfsd_schedule(struct host *host, struct peer *peer, gfp_xdr_xid_t xid, gfarm_error_t errcode, int flags, const char *diag) { gfarm_error_t e; struct gfm_async_server_reply_to_gfsd_entry *qe; GFARM_MALLOC(qe); if (qe == NULL) { gflog_error(GFARM_MSG_1004031, "%s: %s: no memory for queue entry", host_name(host), diag); } else { netsendq_entry_init(&qe->qentry, &gfm_async_server_reply_to_gfsd_queue); qe->qentry.abhost = host_to_abstract_host(host); qe->peer = peer; qe->xid = xid; qe->errcode = errcode; qe->diag = diag; e = netsendq_add_entry(host_sendq(host), &qe->qentry, flags); if (e != GFARM_ERR_NO_ERROR) { gflog_info(GFARM_MSG_1004032, "%s: %s queueing: %s", host_name(host), diag, gfarm_error_string(e)); if ((flags & NETSENDQ_ADD_FLAG_DETACH_ERROR_HANDLING) == 0) free(qe); } } }
static void * gfs_client_status_request(void *arg) { gfarm_error_t e; struct gfs_client_status_entry *qe = arg; struct host *host = abstract_host_to_host(qe->qentry.abhost); struct peer *peer = host_get_peer(host); /* increment refcount */ static const char diag[] = "GFS_PROTO_STATUS"; e = gfs_client_send_request(host, peer, diag, gfs_client_status_result, gfs_client_status_free, qe, GFS_PROTO_STATUS, ""); netsendq_entry_was_sent(abstract_host_get_sendq(qe->qentry.abhost), &qe->qentry); if (e != GFARM_ERR_NO_ERROR) { gflog_info(GFARM_MSG_1001986, "gfs_client_status_request: %s", gfarm_error_string(e)); /* accessing `qe' is only allowed if e != GFARM_ERR_NO_ERROR */ qe->qentry.result = e; gfs_client_status_free(peer, qe); } host_put_peer(host, peer); /* decrement refcount */ /* this return value won't be used, because this thread is detached */ return (NULL); }
static gfarm_int32_t gfs_client_status_result(void *p, void *arg, size_t size) { gfarm_error_t e; struct peer *peer = p; struct gfs_client_status_entry *qe = arg; struct host *host = abstract_host_to_host(qe->qentry.abhost); struct host_status st; static const char diag[] = "GFS_PROTO_STATUS"; e = gfs_client_recv_result(peer, host, size, diag, "fffll", &st.loadavg_1min, &st.loadavg_5min, &st.loadavg_15min, &st.disk_used, &st.disk_avail); netsendq_remove_entry(abstract_host_get_sendq(qe->qentry.abhost), &qe->qentry, e); if (e == GFARM_ERR_NO_ERROR) { host_status_update(host, &st); } else { /* this gfsd is not working correctly, thus, disconnect it */ gfs_client_status_disconnect_or_message(host, peer, diag, "result", gfarm_error_string(e)); } return (e); }
static int error_check(gfarm_error_t e) { if (e == GFARM_ERR_NO_ERROR) return (0); fprintf(stderr, "%s: %s\n", program_name, gfarm_error_string(e)); exit(EXIT_FAILURE); }
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); }
gfarm_error_t request_gfsd_cacheinfo(struct gfarm_host_info *host_info, struct gfarm_paraccess *pa) { gfarm_error_t e; char *canonical_hostname; char *str; struct sockaddr addr; struct gfs_connection *gfs_server; /* dup `host_info->hostname' -> `hostname' */ canonical_hostname = strdup(host_info->hostname); if (canonical_hostname == NULL) { e = GFARM_ERR_NO_MEMORY; fprintf(stderr, "%s: %s\n", program_name, gfarm_error_string(e)); return (e); } e = (*opt_resolv_addr)( canonical_hostname, host_info->port, host_info, &addr, NULL); if (e != GFARM_ERR_NO_ERROR) { output_process(NULL, canonical_hostname, NULL, NULL, NULL, e); return (e); } /* * Few additions by Kazushi */ e = gfs_client_connection_acquire_by_host(gfm_server, canonical_hostname, host_info->port, &gfs_server, "192.168.100.1"); if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "Could not establish to connect gfs client (%s)\n", canonical_hostname); return (e); } e = gfs_client_recv_hitrates(gfs_server, &str); if (e != GFARM_ERR_NO_ERROR) { fprintf(stderr, "Could not clear hitrate in (%s)\n", canonical_hostname); return (e); } fprintf(stdout, "<%s:%d> -- %s\n", canonical_hostname, host_info->port, str); free(str); gfs_client_connection_free(gfs_server); /* return (gfarm_paraccess_request(pa, */ /* if_hostname, canonical_hostname, info->port, &addr)); */ return GFARM_ERR_NO_ERROR; }