summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2023-03-14 00:11:13 +0900
committerRyo Nakamura <upa@haeena.net>2023-03-14 00:11:13 +0900
commit9b0eb668f92c5d90447475df8845344d166fa36c (patch)
tree4224254eb1440c28474d9673630011a454dd809d /src
parent5f9f20f15006fab8065780eda52f32f14bb3935c (diff)
cleanup mscp_prepare-related code
Diffstat (limited to 'src')
-rw-r--r--src/mscp.c31
-rw-r--r--src/path.c21
-rw-r--r--src/path.h1
3 files changed, 25 insertions, 28 deletions
diff --git a/src/mscp.c b/src/mscp.c
index 9ffdc9e..94570c0 100644
--- a/src/mscp.c
+++ b/src/mscp.c
@@ -294,6 +294,20 @@ int mscp_set_dst_path(struct mscp *m, const char *dst_path)
return 0;
}
+static int get_page_mask(void)
+{
+ long page_sz = sysconf(_SC_PAGESIZE);
+ size_t page_mask = 0;
+ int n;
+
+ for (n = 0; page_sz > 0; page_sz >>= 1, n++) {
+ page_mask <<= 1;
+ page_mask |= 1;
+ }
+
+ return page_mask >> 1;
+}
+
static void mscp_stop_copy_thread(struct mscp *m)
{
int n;
@@ -341,10 +355,11 @@ void *mscp_prepare_thread(void *arg)
goto err_out;
}
+ /* initialize path_resolve_args */
memset(&a, 0, sizeof(a));
a.msg_fd = m->msg_fd;
a.total_bytes = &m->total_bytes;
- a.nr_conn = m->opts->nr_threads;
+
if (list_count(&m->src_list) > 1)
a.dst_path_should_dir = true;
@@ -354,6 +369,12 @@ void *mscp_prepare_thread(void *arg)
mscp_stat_free(ds);
}
+ a.cp = &m->cp;
+ a.nr_conn = m->opts->nr_threads;
+ a.min_chunk_sz = m->opts->min_chunk_sz;
+ a.max_chunk_sz = m->opts->max_chunk_sz;
+ a.chunk_align = get_page_mask();
+
mpr_info(m->msg_fd, "start to walk source path(s)\n");
/* walk a src_path recusively, and resolve path->dst_path for each src */
@@ -364,18 +385,12 @@ void *mscp_prepare_thread(void *arg)
goto err_out;
}
- /* fill path_resolve_args */
+ /* set path specific args */
a.src_path = s->path;
a.dst_path = m->dst_path;
a.src_path_is_dir = mstat_is_dir(ss);
-
- a.cp = &m->cp;
- a.min_chunk_sz = m->opts->min_chunk_sz;
- a.max_chunk_sz = m->opts->max_chunk_sz;
-
mscp_stat_free(ss);
-
INIT_LIST_HEAD(&tmp);
if (walk_src_path(src_sftp, s->path, &tmp, &a) < 0)
goto err_out;
diff --git a/src/path.c b/src/path.c
index dc88aa1..2feb52e 100644
--- a/src/path.c
+++ b/src/path.c
@@ -13,22 +13,6 @@
#include <message.h>
-/* util */
-static int get_page_mask(void)
-{
- long page_sz = sysconf(_SC_PAGESIZE);
- size_t page_mask = 0;
- int n;
-
- for (n = 0; page_sz > 0; page_sz >>= 1, n++) {
- page_mask <<= 1;
- page_mask |= 1;
- }
-
- return page_mask >> 1;
-}
-
-
/* chunk pool operations */
#define CHUNK_POOL_STATE_FILLING 0
#define CHUNK_POOL_STATE_FILLED 1
@@ -174,19 +158,16 @@ static struct chunk *alloc_chunk(struct path *p)
static int resolve_chunk(struct path *p, struct path_resolve_args *a)
{
struct chunk *c;
- size_t page_mask;
size_t chunk_sz;
size_t size;
- page_mask = get_page_mask();
-
if (p->size <= a->min_chunk_sz)
chunk_sz = p->size;
else if (a->max_chunk_sz)
chunk_sz = a->max_chunk_sz;
else {
chunk_sz = (p->size - (p->size % a->nr_conn)) / a->nr_conn;
- chunk_sz &= ~page_mask; /* align with page_sz */
+ chunk_sz &= ~a->chunk_align; /* align with page_sz */
if (chunk_sz <= a->min_chunk_sz)
chunk_sz = a->min_chunk_sz;
}
diff --git a/src/path.h b/src/path.h
index 41b22fa..c834969 100644
--- a/src/path.h
+++ b/src/path.h
@@ -83,6 +83,7 @@ struct path_resolve_args {
int nr_conn;
size_t min_chunk_sz;
size_t max_chunk_sz;
+ size_t chunk_align;
};
/* recursivly walk through src_path and fill path_list for each file */