mirror of
https://github.com/upa/mscp.git
synced 2026-03-13 11:47:32 +08:00
fix idx increment (typo) and async write improves copy speed!
This commit is contained in:
20
src/file.c
20
src/file.c
@@ -619,6 +619,9 @@ static sftp_file chunk_open_remote(const char *path, int flags, mode_t mode, siz
|
|||||||
return sf;
|
return sf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: handle case when read returns 0 (EOF).
|
||||||
|
*/
|
||||||
static int chunk_copy_internal_local_to_remote(struct chunk *c, int fd, sftp_file sf,
|
static int chunk_copy_internal_local_to_remote(struct chunk *c, int fd, sftp_file sf,
|
||||||
size_t sftp_buf_sz, size_t io_buf_sz,
|
size_t sftp_buf_sz, size_t io_buf_sz,
|
||||||
size_t *counter)
|
size_t *counter)
|
||||||
@@ -661,11 +664,11 @@ static int chunk_copy_internal_local_to_remote_async(struct chunk *c, int fd,
|
|||||||
size_t *counter)
|
size_t *counter)
|
||||||
{
|
{
|
||||||
size_t read_bytes, remaind, thrown;
|
size_t read_bytes, remaind, thrown;
|
||||||
|
char buf[XFER_BUF_SIZE];
|
||||||
int idx, ret;
|
int idx, ret;
|
||||||
struct {
|
struct {
|
||||||
int id;
|
int id;
|
||||||
size_t len;
|
size_t len;
|
||||||
char buf[XFER_BUF_SIZE];
|
|
||||||
} reqs[nr_ahead];
|
} reqs[nr_ahead];
|
||||||
|
|
||||||
if (c->len == 0)
|
if (c->len == 0)
|
||||||
@@ -673,14 +676,13 @@ static int chunk_copy_internal_local_to_remote_async(struct chunk *c, int fd,
|
|||||||
|
|
||||||
remaind = thrown = c->len;
|
remaind = thrown = c->len;
|
||||||
for (idx = 0; idx < nr_ahead && thrown > 0; idx++) {
|
for (idx = 0; idx < nr_ahead && thrown > 0; idx++) {
|
||||||
reqs[idx].len = min(thrown, XFER_BUF_SIZE);
|
reqs[idx].len = min(thrown, sizeof(buf));
|
||||||
/* TODO: should use iovec? */
|
read_bytes = read(fd, buf, reqs[idx].len);
|
||||||
read_bytes = read(fd, reqs[idx].buf, reqs[idx].len);
|
|
||||||
if (read_bytes < 0) {
|
if (read_bytes < 0) {
|
||||||
pr_err("read from %s failed: %s\n", c->f->src_path, strerrno());
|
pr_err("read from %s failed: %s\n", c->f->src_path, strerrno());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = sftp_async_write(sf, reqs[idx].buf, reqs[idx].len, &reqs[idx].id);
|
ret = sftp_async_write(sf, buf, reqs[idx].len, &reqs[idx].id);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
pr_err("sftp_async_write for %s failed: %d\n",
|
pr_err("sftp_async_write for %s failed: %d\n",
|
||||||
c->f->dst_path, sftp_get_error(sf->sftp));
|
c->f->dst_path, sftp_get_error(sf->sftp));
|
||||||
@@ -703,21 +705,21 @@ static int chunk_copy_internal_local_to_remote_async(struct chunk *c, int fd,
|
|||||||
if (remaind == 0)
|
if (remaind == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
reqs[idx].len = min(remaind, XFER_BUF_SIZE);
|
reqs[idx].len = min(remaind, sizeof(buf));
|
||||||
read_bytes = read(fd, reqs[idx].buf, reqs[idx].len);
|
read_bytes = read(fd, buf, reqs[idx].len);
|
||||||
if (read_bytes < 0) {
|
if (read_bytes < 0) {
|
||||||
pr_err("read from %s failed: %s\n", c->f->src_path, strerrno());
|
pr_err("read from %s failed: %s\n", c->f->src_path, strerrno());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sftp_async_write(sf, reqs[idx].buf, reqs[idx].len, &reqs[idx].id);
|
ret = sftp_async_write(sf, buf, reqs[idx].len, &reqs[idx].id);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
pr_err("sftp_async_write for %s failed: %d\n",
|
pr_err("sftp_async_write for %s failed: %d\n",
|
||||||
c->f->dst_path, sftp_get_error(sf->sftp));
|
c->f->dst_path, sftp_get_error(sf->sftp));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = (idx + 1) & nr_ahead;
|
idx = (idx + 1) % nr_ahead;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user