mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-01-29 09:11:52 -05:00
Jason told me that's its very important for his site to log exactly
how many bytes were needed to be transferred for each file. I added %b and %c log format options to cover this. See the man page for details.
This commit is contained in:
8
io.c
8
io.c
@@ -100,7 +100,6 @@ static int read_timeout(int fd, char *buf, int len)
|
||||
n = read(fd, buf, len);
|
||||
|
||||
if (n > 0) {
|
||||
stats.total_read += n;
|
||||
buf += n;
|
||||
len -= n;
|
||||
ret += n;
|
||||
@@ -264,6 +263,8 @@ static void readfd(int fd,char *buffer,int N)
|
||||
ret = read_unbuffered(fd,buffer + total,N-total);
|
||||
total += ret;
|
||||
}
|
||||
|
||||
stats.total_read += total;
|
||||
}
|
||||
|
||||
|
||||
@@ -390,7 +391,6 @@ static void writefd_unbuffered(int fd,char *buf,int len)
|
||||
|
||||
blocked = 0;
|
||||
total += ret;
|
||||
stats.total_written += ret;
|
||||
|
||||
if (io_timeout)
|
||||
last_io = time(NULL);
|
||||
@@ -441,6 +441,8 @@ void io_end_buffering(int fd)
|
||||
|
||||
static void writefd(int fd,char *buf,int len)
|
||||
{
|
||||
stats.total_written += len;
|
||||
|
||||
if (!io_buffer) {
|
||||
writefd_unbuffered(fd, buf, len);
|
||||
return;
|
||||
@@ -577,6 +579,8 @@ int io_multiplex_write(int f, char *buf, int len)
|
||||
SIVAL(io_buffer-4, 0, ((MPLEX_BASE + f)<<24) + len);
|
||||
memcpy(io_buffer, buf, len);
|
||||
|
||||
stats.total_written += (len+4);
|
||||
|
||||
writefd_unbuffered(multiplex_out_fd, io_buffer-4, len+4);
|
||||
return 1;
|
||||
}
|
||||
|
||||
36
log.c
36
log.c
@@ -174,7 +174,8 @@ void rflush(int fd)
|
||||
|
||||
/* a generic logging routine for send/recv, with parameter
|
||||
substitiution */
|
||||
static void log_formatted(char *op, struct file_struct *file)
|
||||
static void log_formatted(char *op, struct file_struct *file,
|
||||
struct stats *initial_stats)
|
||||
{
|
||||
extern int module_id;
|
||||
extern char *auth_user;
|
||||
@@ -182,6 +183,9 @@ static void log_formatted(char *op, struct file_struct *file)
|
||||
char *p, *s, *n;
|
||||
char buf2[100];
|
||||
int l;
|
||||
extern struct stats stats;
|
||||
extern int am_sender;
|
||||
int64 b;
|
||||
|
||||
strlcpy(buf, lp_log_format(module_id), sizeof(buf)-1);
|
||||
|
||||
@@ -208,6 +212,28 @@ static void log_formatted(char *op, struct file_struct *file)
|
||||
case 'm': n = lp_name(module_id); break;
|
||||
case 'P': n = lp_path(module_id); break;
|
||||
case 'u': n = auth_user; break;
|
||||
case 'b':
|
||||
if (am_sender) {
|
||||
b = stats.total_written -
|
||||
initial_stats->total_written;
|
||||
} else {
|
||||
b = stats.total_read -
|
||||
initial_stats->total_read;
|
||||
}
|
||||
slprintf(buf2,sizeof(buf2)-1,"%.0f", (double)b);
|
||||
n = buf2;
|
||||
break;
|
||||
case 'c':
|
||||
if (!am_sender) {
|
||||
b = stats.total_written -
|
||||
initial_stats->total_written;
|
||||
} else {
|
||||
b = stats.total_read -
|
||||
initial_stats->total_read;
|
||||
}
|
||||
slprintf(buf2,sizeof(buf2)-1,"%.0f", (double)b);
|
||||
n = buf2;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!n) continue;
|
||||
@@ -232,20 +258,20 @@ static void log_formatted(char *op, struct file_struct *file)
|
||||
}
|
||||
|
||||
/* log the outgoing transfer of a file */
|
||||
void log_send(struct file_struct *file)
|
||||
void log_send(struct file_struct *file, struct stats *initial_stats)
|
||||
{
|
||||
extern int module_id;
|
||||
if (lp_transfer_logging(module_id)) {
|
||||
log_formatted("send", file);
|
||||
log_formatted("send", file, initial_stats);
|
||||
}
|
||||
}
|
||||
|
||||
/* log the incoming transfer of a file */
|
||||
void log_recv(struct file_struct *file)
|
||||
void log_recv(struct file_struct *file, struct stats *initial_stats)
|
||||
{
|
||||
extern int module_id;
|
||||
if (lp_transfer_logging(module_id)) {
|
||||
log_formatted("recv", file);
|
||||
log_formatted("recv", file, initial_stats);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -292,6 +292,8 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
|
||||
struct file_struct *file;
|
||||
int phase=0;
|
||||
int recv_ok;
|
||||
extern struct stats stats;
|
||||
struct stats initial_stats;
|
||||
|
||||
if (verbose > 2) {
|
||||
rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
|
||||
@@ -339,6 +341,8 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
|
||||
continue;
|
||||
}
|
||||
|
||||
initial_stats = stats;
|
||||
|
||||
if (verbose > 2)
|
||||
rprintf(FINFO,"recv_files(%s)\n",fname);
|
||||
|
||||
@@ -418,10 +422,10 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
|
||||
log_transfer(file, fname);
|
||||
}
|
||||
|
||||
log_recv(file);
|
||||
|
||||
/* recv file data */
|
||||
recv_ok = receive_data(f_in,buf,fd2,fname,file->length);
|
||||
|
||||
log_recv(file, &initial_stats);
|
||||
|
||||
if (buf) unmap_file(buf);
|
||||
if (fd1 != -1) {
|
||||
|
||||
@@ -129,6 +129,9 @@ itemize(
|
||||
it() %P for the module path
|
||||
it() %m for the module name
|
||||
it() %u for the authenticated username (or the null string)
|
||||
it() %b for the number of bytes actually transferred
|
||||
it() %c when sending files this gives the number of checksum bytes
|
||||
received for this file
|
||||
)
|
||||
|
||||
The default log format is "%o %h [%a] %m (%u) %f %l"
|
||||
|
||||
10
sender.c
10
sender.c
@@ -91,6 +91,8 @@ void send_files(struct file_list *flist,int f_out,int f_in)
|
||||
int i;
|
||||
struct file_struct *file;
|
||||
int phase = 0;
|
||||
extern struct stats stats;
|
||||
struct stats initial_stats;
|
||||
|
||||
if (verbose > 2)
|
||||
rprintf(FINFO,"send_files starting\n");
|
||||
@@ -149,6 +151,8 @@ void send_files(struct file_list *flist,int f_out,int f_in)
|
||||
continue;
|
||||
}
|
||||
|
||||
initial_stats = stats;
|
||||
|
||||
s = receive_sums(f_in);
|
||||
if (!s) {
|
||||
io_error = 1;
|
||||
@@ -184,8 +188,6 @@ void send_files(struct file_list *flist,int f_out,int f_in)
|
||||
rprintf(FINFO,"send_files mapped %s of size %d\n",
|
||||
fname,(int)st.st_size);
|
||||
|
||||
log_send(file);
|
||||
|
||||
write_int(f_out,i);
|
||||
|
||||
write_int(f_out,s->count);
|
||||
@@ -200,7 +202,9 @@ void send_files(struct file_list *flist,int f_out,int f_in)
|
||||
}
|
||||
|
||||
match_sums(f_out,s,buf,st.st_size);
|
||||
|
||||
|
||||
log_send(file, &initial_stats);
|
||||
|
||||
if (buf) unmap_file(buf);
|
||||
close(fd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user