summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2024-02-17 13:25:07 +0900
committerRyo Nakamura <upa@haeena.net>2024-02-17 13:25:07 +0900
commit2f9c2c0f10f1cf81bb58b1603d089ac0209db8c4 (patch)
tree340f3c158dfb22162f06c182cf94be488a2a524b
parentf71c7a145a4c840baff1d34e9d2c3d9e2f26d74e (diff)
ready to implement the main-side
-rw-r--r--include/mscp.h28
-rw-r--r--src/checkpoint.c34
-rw-r--r--src/checkpoint.h12
-rw-r--r--src/mscp.c31
4 files changed, 58 insertions, 47 deletions
diff --git a/include/mscp.h b/include/mscp.h
index c6af3f8..9d83375 100644
--- a/include/mscp.h
+++ b/include/mscp.h
@@ -173,25 +173,39 @@ int mscp_scan(struct mscp *m);
int mscp_scan_join(struct mscp *m);
/**
- * @brief resume transfer from a checkpoint. mscp_load_checkpoint()
- * loads files and associated chunks from a checkpoint file pointed by
- * pathname. If you call mscp_load_checkpoint, do not call
- * mscp_scan().
+ * @brief get information about remote host and copy direction from a
+ * checkpoint file specified by *pathname. This functions returns
+ * remote host name to *renote, and the copy direction into *dir.
+ * Thus, you can call mscp_init with those values.
+ *
+ * @param pathname path to a checkpoint file.
+ * @param remote char buffer to which remote hostname is stored.
+ * @param len length of *remote.
+ * @param dir int to which the copy direction is stored.
+ */
+int mscp_checkpoint_get_remote(const char *pathname, char *remote, size_t len, int *dir);
+
+/**
+ * @brief load information about untransferred files and chunks at the
+ * last transfer . mscp_checkpoint_load() loads files and associated
+ * chunks from the checkpoint file pointed by pathname. If you call
+ * mscp_checkpoint_load(), do not call mscp_scan().
*
* @param m mscp instance.
* @param pathname path to a checkpoint file.
* @return 0 on success, < 0 if an error occured.
*/
-int mscp_load_checkpoint(struct mscp *m, const char *pathname);
+int mscp_checkpoint_load(struct mscp *m, const char *pathname);
/**
- * @brief save untransferred files and chunks to a checkpoint file.
+ * @brief save information about untransferred files and chunks to a
+ * checkpoint file.
*
* @param m mscp instance.
* @param pathname path to a checkpoint file.
* @return 0 on success, < 0 if an error occured.
*/
-int mscp_save_checkpoint(struct mscp *m, const char *pathname);
+int mscp_checkpoint_save(struct mscp *m, const char *pathname);
/**
* @brief Start to copy files. mscp_start() returns immediately. You
diff --git a/src/checkpoint.c b/src/checkpoint.c
index 8d3a5ee..457bb15 100644
--- a/src/checkpoint.c
+++ b/src/checkpoint.c
@@ -228,16 +228,13 @@ static int checkpoint_load_meta(struct checkpoint_obj_hdr *hdr, char *remote, si
}
pr_debug("checkpoint: version %u", meta->version);
- if (dir)
- *dir = meta->direction;
-
- if (remote) {
- if (len < ntohs(hdr->len) - sizeof(*meta)) {
- priv_set_errv("too short buffer");
- return -1;
- }
- snprintf(remote, len, "%s", meta->remote);
+ if (len < ntohs(hdr->len) - sizeof(*meta)) {
+ priv_set_errv("too short buffer");
+ return -1;
}
+ snprintf(remote, len, "%s", meta->remote);
+ *dir = meta->direction;
+
pr_info("checkpoint: remote=%s direction=%s", meta->remote,
meta->direction == MSCP_DIRECTION_L2R ? "local-to-remote" :
meta->direction == MSCP_DIRECTION_R2L ? "remote-to-local" :
@@ -305,8 +302,8 @@ static int checkpoint_load_chunk(struct checkpoint_obj_hdr *hdr, pool *path_pool
return 0;
}
-int checkpoint_load(const char *pathname, char *remote, size_t len, int *dir,
- pool *path_pool, pool *chunk_pool)
+static int checkpoint_load(const char *pathname, char *remote, size_t len, int *dir,
+ pool *path_pool, pool *chunk_pool)
{
char buf[CHECKPOINT_OBJ_MAXLEN];
struct checkpoint_obj_hdr *hdr;
@@ -323,10 +320,12 @@ int checkpoint_load(const char *pathname, char *remote, size_t len, int *dir,
while (checkpoint_read_obj(fd, buf, sizeof(buf)) == 0) {
switch (hdr->type) {
case OBJ_TYPE_META:
+ if (!remote || !dir)
+ break;
if (checkpoint_load_meta(hdr, remote, len, dir) < 0)
return -1;
if (!path_pool || !chunk_pool)
- break;
+ goto out;
break;
case OBJ_TYPE_PATH:
if (!path_pool)
@@ -346,7 +345,18 @@ int checkpoint_load(const char *pathname, char *remote, size_t len, int *dir,
}
}
+out:
close(fd);
return 0;
}
+
+int checkpoint_load_remote(const char *pathname, char *remote, size_t len, int *dir)
+{
+ return checkpoint_load(pathname, remote, len, dir, NULL, NULL);
+}
+
+int checkpoint_load_paths(const char *pathname, pool *path_pool, pool *chunk_pool)
+{
+ return checkpoint_load(pathname, NULL, 0, NULL, path_pool, chunk_pool);
+}
diff --git a/src/checkpoint.h b/src/checkpoint.h
index 8bbb738..d0d0948 100644
--- a/src/checkpoint.h
+++ b/src/checkpoint.h
@@ -7,10 +7,14 @@
int checkpoint_save(const char *pathname, int dir, char *remote_host, pool *path_pool,
pool *chunk_pool);
-/* checkpoint_load() reads a checkpoint file (pathname). If path_pool
- * and chunk_pool are NULL, This function fills only *remote and *dir.
+/* checkpoint_load_meta() reads a checkpoint file (pathname) and returns
+ * remote host string to *remote and transfer direction to *dir.
*/
-int checkpoint_load(const char *pathname, char *remote, size_t len, int *dir,
- pool *path_pool, pool *chunk_pool);
+int checkpoint_load_remote(const char *pathname, char *remote, size_t len, int *dir);
+
+/* checkpoint_load_paths() reads a checkpoint file (pathname) and
+ * fills path_pool and chunk_pool.
+ */
+int checkpoint_load_paths(const char *pathname, pool *path_pool, pool *chunk_pool);
#endif /* _CHECKPOINT_H_ */
diff --git a/src/mscp.c b/src/mscp.c
index 6b83d0d..ea697f2 100644
--- a/src/mscp.c
+++ b/src/mscp.c
@@ -492,34 +492,17 @@ int mscp_scan_join(struct mscp *m)
return 0;
}
-int mscp_load_checkpoint(struct mscp *m, const char *pathname)
+int mscp_checkpoint_get_remote(const char *pathname, char *remote, size_t len, int *dir)
{
- size_t total_bytes = 0;
- unsigned int idx;
- struct chunk *c;
- char remote[1024];
-
- if (checkpoint_load(pathname, remote, sizeof(remote), &m->direction, m->path_pool,
- m->chunk_pool) < 0)
- return -1;
-
- if (!(m->remote = strdup(remote))) {
- priv_set_errv("malloc: %s", strerrno());
- return -1;
- }
-
- pool_for_each(m->chunk_pool, c, idx) {
- total_bytes += c->len;
- }
- m->total_bytes = total_bytes;
-
- __sync_synchronize();
- chunk_pool_set_ready(m, true);
+ return checkpoint_load_remote(pathname, remote, len, dir);
+}
- return 0;
+int mscp_checkpoint_load(struct mscp *m, const char *pathname)
+{
+ return checkpoint_load_paths(pathname, m->path_pool, m->chunk_pool);
}
-int mscp_save_checkpoint(struct mscp *m, const char *pathname)
+int mscp_checkpoint_save(struct mscp *m, const char *pathname)
{
return checkpoint_save(pathname, m->direction, m->remote, m->path_pool,
m->chunk_pool);