From: <ta...@us...> - 2007-09-06 09:18:39
|
Revision: 3811 http://gfarm.svn.sourceforge.net/gfarm/?rev=3811&view=rev Author: tatebe Date: 2007-09-06 02:18:41 -0700 (Thu, 06 Sep 2007) Log Message: ----------- gfs_fstat() and gfs_pio_stat() Modified Paths: -------------- gfarm/branches/gfarm_v2/include/gfarm/gfs.h gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio.c gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio.h gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_local.c gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_remote.c gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_section.c gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_stat.c Modified: gfarm/branches/gfarm_v2/include/gfarm/gfs.h =================================================================== --- gfarm/branches/gfarm_v2/include/gfarm/gfs.h 2007-09-05 17:08:18 UTC (rev 3810) +++ gfarm/branches/gfarm_v2/include/gfarm/gfs.h 2007-09-06 09:18:41 UTC (rev 3811) @@ -166,6 +166,8 @@ gfarm_error_t gfs_pio_readdelim(GFS_File, char **, size_t *, size_t *, const char *, size_t); +gfarm_error_t gfs_pio_stat(GFS_File, struct gfs_stat *); + /* * Directory operations */ @@ -216,6 +218,7 @@ gfarm_error_t gfs_rename(const char *, const char *); gfarm_error_t gfs_stat(const char *, struct gfs_stat *); +gfarm_error_t gfs_fstat(GFS_File, struct gfs_stat *); #if 0 gfarm_error_t gfs_stat_section(const char *, const char *, struct gfs_stat *); gfarm_error_t gfs_stat_index(char *, int, struct gfs_stat *); Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio.c =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio.c 2007-09-05 17:08:18 UTC (rev 3810) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio.c 2007-09-06 09:18:41 UTC (rev 3811) @@ -75,7 +75,6 @@ return (e_save); } - static gfarm_error_t gfs_pio_check_view_default(GFS_File gf) { @@ -272,7 +271,7 @@ e_save = e; } - e = gfm_close_fd(gf->fd); + e = gfm_close_fd(gfs_pio_fileno(gf)); if (e_save == GFARM_ERR_NO_ERROR) e_save = e; gfs_file_free(gf); @@ -1083,6 +1082,30 @@ return (GFARM_ERR_NO_ERROR); } +/* + * fstat + */ + +gfarm_error_t +gfs_pio_stat(GFS_File gf, struct gfs_stat *st) +{ + gfarm_error_t e; + + e = gfs_pio_check_view_default(gf); + if (e != GFARM_ERR_NO_ERROR) + return (e); + + e = gfs_fstat(gf, st); + if (e != GFARM_ERR_NO_ERROR) + return (e); + + e = (*gf->ops->view_fstat)(gf, st); + if (e != GFARM_ERR_NO_ERROR) + gf->error = e; + + return (e); +} + void gfs_pio_display_timers(void) { Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio.h =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio.h 2007-09-05 17:08:18 UTC (rev 3810) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio.h 2007-09-06 09:18:41 UTC (rev 3811) @@ -22,6 +22,7 @@ const char *, size_t, gfarm_off_t, size_t *); gfarm_error_t (*view_ftruncate)(GFS_File, gfarm_off_t); gfarm_error_t (*view_fsync)(GFS_File, int); + gfarm_error_t (*view_fstat)(GFS_File, struct gfs_stat *); }; struct gfs_file { @@ -82,6 +83,7 @@ const char *, size_t, gfarm_off_t, size_t *); gfarm_error_t (*storage_ftruncate)(GFS_File, gfarm_off_t); gfarm_error_t (*storage_fsync)(GFS_File, int); + gfarm_error_t (*storage_fstat)(GFS_File, struct gfs_stat *); }; #define GFS_DEFAULT_DIGEST_NAME "md5" Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_local.c =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_local.c 2007-09-05 17:08:18 UTC (rev 3810) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_local.c 2007-09-06 09:18:41 UTC (rev 3811) @@ -195,6 +195,25 @@ return (GFARM_ERR_NO_ERROR); } +static gfarm_error_t +gfs_pio_local_storage_fstat(GFS_File gf, struct gfs_stat *st) +{ + struct gfs_file_section_context *vc = gf->view_context; + struct stat sb; + + if (fstat(vc->fd, &sb) == 0) { + st->st_size = sb.st_size; + st->st_atimespec.tv_sec = sb.st_atime; + st->st_atimespec.tv_nsec = 0; /* XXX */ + st->st_mtimespec.tv_sec = sb.st_mtime; + st->st_mtimespec.tv_nsec = 0; /* XXX */ + } + else + return (gfarm_errno_to_error(errno)); + + return (GFARM_ERR_NO_ERROR); +} + static int gfs_pio_local_storage_fd(GFS_File gf) { @@ -210,6 +229,7 @@ gfs_pio_local_storage_pwrite, gfs_pio_local_storage_ftruncate, gfs_pio_local_storage_fsync, + gfs_pio_local_storage_fstat, }; gfarm_error_t Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_remote.c =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_remote.c 2007-09-05 17:08:18 UTC (rev 3810) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_remote.c 2007-09-06 09:18:41 UTC (rev 3811) @@ -92,6 +92,17 @@ return (gfs_client_fsync(gfs_server, gf->fd, operation)); } +static gfarm_error_t +gfs_pio_remote_storage_fstat(GFS_File gf, struct gfs_stat *st) +{ + struct gfs_file_section_context *vc = gf->view_context; + struct gfs_connection *gfs_server = vc->storage_context; + + return (gfs_client_fstat(gfs_server, gf->fd, + &st->st_size, &st->st_atimespec.tv_sec, &st->st_atimespec.tv_nsec, + &st->st_mtimespec.tv_sec, &st->st_mtimespec.tv_nsec)); +} + static int gfs_pio_remote_storage_fd(GFS_File gf) { @@ -109,6 +120,7 @@ gfs_pio_remote_storage_pwrite, gfs_pio_remote_storage_ftruncate, gfs_pio_remote_storage_fsync, + gfs_pio_remote_storage_fstat, }; gfarm_error_t Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_section.c =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_section.c 2007-09-05 17:08:18 UTC (rev 3810) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_pio_section.c 2007-09-06 09:18:41 UTC (rev 3811) @@ -235,6 +235,14 @@ return ((*vc->ops->storage_fsync)(gf, operation)); } +static gfarm_error_t +gfs_pio_view_section_fstat(GFS_File gf, struct gfs_stat *st) +{ + struct gfs_file_section_context *vc = gf->view_context; + + return ((*vc->ops->storage_fstat)(gf, st)); +} + static int gfs_pio_view_section_fd(GFS_File gf) { @@ -250,6 +258,7 @@ gfs_pio_view_section_pwrite, gfs_pio_view_section_ftruncate, gfs_pio_view_section_fsync, + gfs_pio_view_section_fstat, }; Modified: gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_stat.c =================================================================== --- gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_stat.c 2007-09-05 17:08:18 UTC (rev 3810) +++ gfarm/branches/gfarm_v2/lib/libgfarm/gfarm/gfs_stat.c 2007-09-06 09:18:41 UTC (rev 3811) @@ -74,6 +74,49 @@ return (e); } +gfarm_error_t +gfs_fstat(GFS_File gf, struct gfs_stat *s) +{ + gfarm_error_t e; + + 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_client_put_fd_request( + gfarm_metadb_server, gfs_pio_fileno(gf))) + != GFARM_ERR_NO_ERROR) + gflog_warning("put_fd request: %s", + gfarm_error_string(e)); + else if ((e = gfm_client_fstat_request(gfarm_metadb_server)) + != GFARM_ERR_NO_ERROR) + gflog_warning("fstat 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_client_put_fd_result(gfarm_metadb_server)) + != GFARM_ERR_NO_ERROR) + gflog_warning("put_fd result: %s", + gfarm_error_string(e)); + else if ((e = gfm_client_fstat_result(gfarm_metadb_server, s)) + != GFARM_ERR_NO_ERROR) + gflog_warning("fstat 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)); + + return (e); +} + void gfs_stat_display_timers(void) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |