mirror of
https://github.com/upa/mscp.git
synced 2026-02-04 11:34:44 +08:00
cleanup mscp_prepare-related code
This commit is contained in:
31
src/mscp.c
31
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;
|
||||
|
||||
21
src/path.c
21
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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user