Commit 1a9c643d authored by Rob Latham's avatar Rob Latham
Browse files

add a 'get file size' routine

parent f68420c0
......@@ -75,6 +75,10 @@ int bv_flush(bv_client_t client, const char *filename);
/* delete: remove the file */
int bv_delete(bv_client_t client, const char *filename);
/* getting file size: on parallel file system file size is expensive so make this a separate routine */
ssize_t bv_getsize(bv_client_t client, const char *filename);
#ifdef __cplusplus
}
#endif
......
......@@ -26,6 +26,7 @@ struct bv_client {
tl::remote_procedure delete_op;
tl::remote_procedure flush_op;
tl::remote_procedure statistics_op;
tl::remote_procedure size_op;
ssg_group_id_t gid; // attaches to this group; not a member
io_stats statistics;
......@@ -105,6 +106,7 @@ bv_client_t bv_init(MPI_Comm comm, const char * cfg_file)
client->delete_op = client->engine->define("delete");
client->flush_op = client->engine->define("flush");
client->statistics_op = client->engine->define("statistics");
client->size_op = client->engine->define("size");
/* used to think the server would know something about how it wanted to
......@@ -268,3 +270,11 @@ int bv_flush(bv_client_t client, const char *filename)
return ret;
}
ssize_t bv_getsize(bv_client_t client, const char *filename)
{
ssize_t size;
size = client->size_op.on(client->targets[0])(std::string(filename));
return size;
}
......@@ -293,6 +293,21 @@ struct bv_svc_provider : public tl::provider<bv_svc_provider>
return (fsync(fd));
}
ssize_t getsize(const std::string &file) {
off_t oldpos=-1, pos=-1;
int fd = getfd(file, O_RDONLY);
oldpos = lseek(fd, 0, SEEK_CUR);
if (oldpos == -1)
return -errno;
pos = lseek(fd, 0, SEEK_END);
if (pos == -1)
return -errno;
/* put things back the way we found them */
lseek(fd, oldpos, SEEK_SET);
return pos;
}
bv_svc_provider(tl::engine *e, abt_io_instance_id abtio,
ssg_group_id_t gid, uint16_t provider_id, tl::pool &pool)
: tl::provider<bv_svc_provider>(*e, provider_id), engine(e), gid(gid), pool(pool), abt_id(abtio) {
......@@ -303,6 +318,7 @@ struct bv_svc_provider : public tl::provider<bv_svc_provider>
define("delete", &bv_svc_provider::del);
define("flush", &bv_svc_provider::flush);
define("statistics", &bv_svc_provider::statistics);
define("size", &bv_svc_provider::getsize);
}
void dump_io_req(const std::string extra, tl::bulk &client_bulk, std::vector<off_t> &file_starts, std::vector<uint64_t> &file_sizes)
......
......@@ -19,6 +19,7 @@ int main(int argc, char **argv)
char cmp[128] = "";
int ret = 0;
char *filename;
ssize_t filesize;
#if 0
printf("delete:\n");
......@@ -83,6 +84,12 @@ int main(int argc, char **argv)
free(bigbuf);
free(cmpbuf);
filesize = bv_getsize(client, filename);
if (filesize != 15000+20) {
printf("Expected %d got %ld\n", 15000+20, filesize);
ret -= 1;
}
#if VERBOSE
bv_statistics(client, 1);
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment