Skip to content

Commit

Permalink
cf-serverd now stats file every read on network transmission
Browse files Browse the repository at this point in the history
Previously the file was `stat`'ed every N read to detect file changes
during transmission. The reason for limiting the calls to stat is
probably to make the code more efficient. However, there are reasons to
believe that the bug experienced in ENT-12033 is attributed to
filechanges during transmission. Hence, I'm changing the code to do this
for every read, as it better to be safe and happy rather than fast but
sorry.

Yes, `stat()` is a system call. However, it has pretty good cashing
mechanisms on modern systems. So it should not be too expensive.

Ticket: None
Changelog: None
Signed-off-by: Lars Erik Wik <[email protected]>
  • Loading branch information
larsewi committed Oct 28, 2024
1 parent 1d85047 commit 9fb6026
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions cf-serverd/server_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ static void FailedTransfer(ConnectionInfo *connection)
void CfGetFile(ServerFileGetState *args)
{
int fd;
off_t n_read, total = 0, sendlen = 0, count = 0;
off_t n_read, total = 0, sendlen = 0;
char sendbuffer[CF_BUFSIZE + 256], filename[CF_BUFSIZE - 128];
struct stat sb;
int blocksize = 2048;
Expand Down Expand Up @@ -459,13 +459,6 @@ void CfGetFile(ServerFileGetState *args)
}
else
{
int div = 3;

if (sb.st_size > 10485760L) /* File larger than 10 MB, checks every 64kB */
{
div = 32;
}

while (true)
{
memset(sendbuffer, 0, CF_BUFSIZE);
Expand All @@ -488,14 +481,11 @@ void CfGetFile(ServerFileGetState *args)

/* check the file is not changing at source */

if (count++ % div == 0) /* Don't do this too often */
if (stat(filename, &sb) == -1)
{
if (stat(filename, &sb))
{
Log(LOG_LEVEL_ERR, "Cannot stat file '%s'. (stat: %s)",
filename, GetErrorStr());
break;
}
Log(LOG_LEVEL_ERR, "Cannot stat file '%s'. (stat: %s)",
filename, GetErrorStr());
break;
}

if (sb.st_size != savedlen)
Expand Down

0 comments on commit 9fb6026

Please sign in to comment.