gfarm_error_t gfs_closedirplus(GFS_DirPlus dir) { gfarm_error_t e = gfm_close_fd(dir->gfm_server, dir->fd); gfm_client_connection_free(dir->gfm_server); gfs_dirplus_clear(dir); free(dir); return (e); }
static gfarm_error_t gfs_closedir_internal(GFS_Dir super) { struct gfs_dir_internal *dir = (struct gfs_dir_internal *)super; gfarm_error_t e = gfm_close_fd(dir->gfm_server, dir->fd); gfm_client_connection_free(dir->gfm_server); free(dir); 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); }
gfarm_error_t gfs_opendirplus(const char *path, GFS_DirPlus *dirp) { gfarm_error_t e; struct gfm_connection *gfm_server; int fd, type; if ((e = gfm_open_fd(path, GFARM_FILE_RDONLY, &gfm_server, &fd, &type)) != GFARM_ERR_NO_ERROR) return (e); if (type != GFS_DT_DIR) e = GFARM_ERR_NOT_A_DIRECTORY; else if ((e = gfs_dirplus_alloc(gfm_server, fd, dirp)) == GFARM_ERR_NO_ERROR) return (GFARM_ERR_NO_ERROR); (void)gfm_close_fd(gfm_server, fd); /* ignore result */ gfm_client_connection_free(gfm_server); return (e); }
static int reset_and_reopen(GFS_File gf, void *closure) { gfarm_error_t e = GFARM_ERR_NO_ERROR; struct reset_and_reopen_info *ri = closure; struct gfm_connection *gfm_server = ri->gfm_server; struct gfm_connection *gfm_server1; struct gfs_connection *sc; struct gfarm_filesystem *fs = gfarm_filesystem_get_by_connection(gfm_server); int fc = gfarm_filesystem_failover_count(fs); if ((e = gfm_client_connection_acquire(gfm_client_hostname(gfm_server), gfm_client_port(gfm_server), gfm_client_username(gfm_server), &gfm_server1)) != GFARM_ERR_NO_ERROR) { gf->error = e; gflog_debug(GFARM_MSG_1003383, "gfm_client_connection_acquire: %s", gfarm_error_string(e)); return (1); } if (gfm_server != gfm_server1) { gfm_client_connection_free(gfm_server1); gflog_debug(GFARM_MSG_1003384, "reconnected to other gfmd or gfmd restarted"); ri->must_retry = 1; return (0); } /* if old gfm_connection is alive, fd must be closed */ (void)gfm_close_fd(gf->gfm_server, gf->fd); gf->fd = GFARM_DESCRIPTOR_INVALID; gfm_client_connection_free(gf->gfm_server); /* ref count of gfm_server is incremented above */ gf->gfm_server = gfm_server; if ((sc = get_storage_context(gf->view_context)) != NULL) { /* * pid will be 0 if gfarm_client_process_reset() resulted * in failure at reset_and_reopen() previously called with * the same gfs_connection. */ if (gfs_client_pid(sc) == 0) { gf->error = GFARM_ERR_CONNECTION_ABORTED; gflog_debug(GFARM_MSG_1003385, "%s", gfarm_error_string(gf->error)); return (1); } /* reset pid */ if (fc > gfs_client_connection_failover_count(sc)) { gfs_client_connection_set_failover_count(sc, fc); /* * gfs_file just in scheduling is not related to * gfs_server. * In that case, gfarm_client_process_reset() is * called in gfs_pio_open_section(). * * all fd will be closed in gfsd by * gfarm_client_process_reset(). */ e = gfarm_client_process_reset(sc, gfm_server); if (e != GFARM_ERR_NO_ERROR) { gf->error = e; gflog_debug(GFARM_MSG_1003386, "gfarm_client_process_reset: %s", gfarm_error_string(e)); return (1); } } } /* reopen file */ if (gfs_pio_error(gf) != GFARM_ERR_STALE_FILE_HANDLE && (e = gfs_pio_reopen(fs, gf)) != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_1003387, "gfs_pio_reopen: %s", gfarm_error_string(e)); } return (1); }