diff options
-rw-r--r-- | include/mscp.h | 24 | ||||
-rw-r--r-- | mscp/mscp.py | 14 | ||||
-rw-r--r-- | src/main.c | 6 | ||||
-rw-r--r-- | src/mscp.c | 42 | ||||
-rw-r--r-- | src/pymscp.c | 6 |
5 files changed, 46 insertions, 46 deletions
diff --git a/include/mscp.h b/include/mscp.h index aff28ce..3e8f80f 100644 --- a/include/mscp.h +++ b/include/mscp.h @@ -18,7 +18,7 @@ * 2. connect to remote host with mscp_connect() * 3. add path to source files with mscp_add_src_path() * 4. set path to destination with mscp_set_dst_path() - * 5. finish preparation with mscp_prepare() + * 5. start to scan source files with mscp_scan() * 6. start copy with mscp_start() * 7. wait for copy finished with mscp_join() * 8. cleanup mscp instance with mscp_cleanup() and mscp_free() @@ -110,7 +110,7 @@ struct mscp *mscp_init(const char *remote_host, int direction, /** * @brief Connect the first SSH connection. mscp_connect connects to * remote host and initialize a SFTP session over the - * connection. mscp_prepare() and mscp_start() require mscp_connect() + * connection. mscp_scan() and mscp_start() require mscp_connect() * beforehand. * * @param m mscp instance. @@ -150,31 +150,31 @@ int mscp_add_src_path(struct mscp *m, const char *src_path); */ int mscp_set_dst_path(struct mscp *m, const char *dst_path); -/* check source files, resolve destination file paths for all source - * files, and prepare chunks for all files. */ +/* scan source files, resolve destination file paths for all source + * files, and calculate chunks for all files. */ /** - * @brief Prepare for file transfer. This function checks all source - * files (recursively), resolve paths on the destination side, and - * calculate file chunks. This function is non-blocking. + * @brief Scan source paths and prepare. This function checks all + * source files (recursively), resolve paths on the destination side, + * and calculate file chunks. This function is non-blocking. * * @param m mscp instance. * * @return 0 on success, < 0 if an error occured. * mscp_get_error() can be used to retrieve error message. */ -int mscp_prepare(struct mscp *m); +int mscp_scan(struct mscp *m); /** - * @brief Join prepare thread invoked by mscp_prepare(). mscp_join() - * involves this, so that mscp_prepare_join() should be called when - * mscp_prepare() is called by mscp_start() is not. + * @brief Join scna thread invoked by mscp_scan(). mscp_join() + * involves this, so that mscp_scan_join() should be called when + * mscp_scan() is called by mscp_start() is not. * * @param m mscp instance. * @return 0 on success, < 0 if an error occured. * mscp_get_error() can be used to retrieve error message. */ -int mscp_prepare_join(struct mscp *m); +int mscp_scan_join(struct mscp *m); /** * @brief Start to copy files. mscp_start() returns immediately. You diff --git a/mscp/mscp.py b/mscp/mscp.py index 97f3cb1..30b2ce3 100644 --- a/mscp/mscp.py +++ b/mscp/mscp.py @@ -37,7 +37,7 @@ SEVERITY_DEBUG = pymscp.SEVERITY_DEBUG STATE_INIT = 0 STATE_CONNECTED = 1 -STATE_PREPARED = 2 +STATE_SCANNED = 2 STATE_RUNNING = 3 STATE_STOPPED = 4 STATE_JOINED = 5 @@ -47,7 +47,7 @@ STATE_RELEASED = 7 _state_str = { STATE_INIT: "init", STATE_CONNECTED: "connected", - STATE_PREPARED: "prepared", + STATE_SCANNED: "scanned", STATE_RUNNING: "running", STATE_STOPPED: "stopped", STATE_JOINED: "joined", @@ -114,7 +114,7 @@ class mscp: self.dst_path = dst_path pymscp.mscp_set_dst_path(m = self.m, dst_path = dst_path); - def prepare(self): + def scan(self): if self.state != STATE_CONNECTED: raise RuntimeError("invalid mscp state: {}".format(self.__state2str())) if not self.src_paths: @@ -122,11 +122,11 @@ class mscp: if self.dst_path == None: raise RuntimeError("dst path is not set") - pymscp.mscp_prepare(m = self.m) - self.state = STATE_PREPARED + pymscp.mscp_scan(m = self.m) + self.state = STATE_SCANNED def start(self): - if self.state != STATE_PREPARED: + if self.state != STATE_SCANNED: raise RuntimeError("invalid mscp state: {}".format(self.__state2str())) pymscp.mscp_start(m = self.m) @@ -174,7 +174,7 @@ class mscp: self.set_dst_path(dst) - self.prepare() + self.scan() self.start() if nonblock: return @@ -358,13 +358,13 @@ int main(int argc, char **argv) return -1; } - if (mscp_prepare(m) < 0) { - fprintf(stderr, "mscp_prepare: %s\n", mscp_get_error()); + if (mscp_scan(m) < 0) { + fprintf(stderr, "mscp_scan: %s\n", mscp_get_error()); return -1; } if (dryrun) { - ret = mscp_prepare_join(m); + ret = mscp_scan_join(m); goto out; } @@ -36,8 +36,8 @@ struct mscp { struct list_head path_list; struct chunk_pool cp; - pthread_t tid_prepare; /* tid for prepare thread */ - int ret_prepare; /* return code from prepare thread */ + pthread_t tid_scan; /* tid for scan thread */ + int ret_scan; /* return code from scan thread */ size_t total_bytes; /* total bytes to be transferred */ struct mscp_thread *threads; @@ -345,19 +345,19 @@ static void mscp_stop_copy_thread(struct mscp *m) } } -static void mscp_stop_prepare_thread(struct mscp *m) +static void mscp_stop_scan_thread(struct mscp *m) { - if (m->tid_prepare) - pthread_cancel(m->tid_prepare); + if (m->tid_scan) + pthread_cancel(m->tid_scan); } void mscp_stop(struct mscp *m) { - mscp_stop_prepare_thread(m); + mscp_stop_scan_thread(m); mscp_stop_copy_thread(m); } -void *mscp_prepare_thread(void *arg) +void *mscp_scan_thread(void *arg) { struct mscp *m = arg; sftp_session src_sftp = NULL, dst_sftp = NULL; @@ -367,7 +367,7 @@ void *mscp_prepare_thread(void *arg) struct src *s; mstat ss, ds; - m->ret_prepare = 0; + m->ret_scan = 0; switch (m->direction) { case MSCP_DIRECTION_L2R: @@ -430,21 +430,21 @@ void *mscp_prepare_thread(void *arg) mpr_info(m->msg_fp, "walk source path(s) done\n"); - m->ret_prepare = 0; + m->ret_scan = 0; return NULL; err_out: - m->ret_prepare = -1; + m->ret_scan = -1; mscp_stop_copy_thread(m); return NULL; } -int mscp_prepare(struct mscp *m) +int mscp_scan(struct mscp *m) { - int ret = pthread_create(&m->tid_prepare, NULL, mscp_prepare_thread, m); + int ret = pthread_create(&m->tid_scan, NULL, mscp_scan_thread, m); if (ret < 0) { mscp_set_error("pthread_create_error: %d", ret); - m->tid_prepare = 0; + m->tid_scan = 0; mscp_stop(m); return -1; } @@ -458,12 +458,12 @@ int mscp_prepare(struct mscp *m) return 0; } -int mscp_prepare_join(struct mscp *m) +int mscp_scan_join(struct mscp *m) { - if (m->tid_prepare) { - pthread_join(m->tid_prepare, NULL); - m->tid_prepare = 0; - return m->ret_prepare; + if (m->tid_scan) { + pthread_join(m->tid_scan, NULL); + m->tid_scan = 0; + return m->ret_scan; } return 0; } @@ -482,7 +482,7 @@ int mscp_start(struct mscp *m) m->opts->nr_threads = n; } - /* prepare thread instances */ + /* scan thread instances */ m->threads = calloc(m->opts->nr_threads, sizeof(struct mscp_thread)); memset(m->threads, 0, m->opts->nr_threads * sizeof(struct mscp_thread)); for (n = 0; n < m->opts->nr_threads; n++) { @@ -509,8 +509,8 @@ int mscp_join(struct mscp *m) { int n, ret = 0; - /* waiting for prepare thread joins... */ - ret = mscp_prepare_join(m); + /* waiting for scan thread joins... */ + ret = mscp_scan_join(m); /* waiting for copy threads join... */ for (n = 0; n < m->opts->nr_threads; n++) { diff --git a/src/pymscp.c b/src/pymscp.c index 0a0642e..1a55a3d 100644 --- a/src/pymscp.c +++ b/src/pymscp.c @@ -268,7 +268,7 @@ static PyObject *wrap_mscp_set_dst_path(PyObject *self, PyObject *args, PyObject return Py_BuildValue(""); } -static PyObject *wrap_mscp_prepare(PyObject *self, PyObject *args, PyObject *kw) +static PyObject *wrap_mscp_scan(PyObject *self, PyObject *args, PyObject *kw) { char *keywords[] = { "m", NULL }; unsigned long long addr; @@ -283,7 +283,7 @@ static PyObject *wrap_mscp_prepare(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (mscp_prepare(m) < 0) { + if (mscp_scan(m) < 0) { PyErr_Format(PyExc_RuntimeError, mscp_get_error()); return NULL; } @@ -437,7 +437,7 @@ static PyMethodDef pymscpMethods[] = { METH_VARARGS | METH_KEYWORDS, NULL }, { - "mscp_prepare", (PyCFunction)wrap_mscp_prepare, + "mscp_scan", (PyCFunction)wrap_mscp_scan, METH_VARARGS | METH_KEYWORDS, NULL }, { |