FIX for smbtar zero length files... (Cont :)

James Delahanty jimd at gie.com
Tue Jun 15 15:11:39 GMT 1999


(Erm, sorry about that...)

I was talking about errors of the type: Got 0 bytes.

The problem was sporatic, and seemed to be load/speed based.  That is,
the faster the Linux box, the more errors we had.

A look through clitar.c led me to a solution.  Currently, clitar.c is
written to pad a file with zeros if a file read error occurs.  This is
normal.  All of our errors were of the 0 byte length variety, which
allows us to retry the read.  In all the cases we've seen, this allows
us to read the file and save the real data to tape/disk (and not a
zero-filled file!)

The patch below will apply to both 2.0.3 and 2.0.4b, and gives you five
tries to read the file from the start, if you're having some sort of
sync/time problem with the read. (If you have an error in the middle of
reading the file, it won't help.  There's something else wrong,
probably.)  This fixes the zero-byte problem, and for the first time
we've had an error free backup of all our NT boxes!  BTW: We never have
seen the count go past 1 more try, but I let it try 5 times just to be
sure.

Thanks to the Samba team!

Patch is below:
----- CUT ----------
--- samba-2.0.3/source/client/clitar.c.orig     Sat Feb 27 16:08:59 1999

+++ samba-2.0.3/source/client/clitar.c          Tue Jun 15 08:35:40 1999

@@ -629,6 +629,9 @@
   char data[65520];
   int read_size = 65520;
   int datalen=0;
+  /* Zero Byte Error retry setup */
+  int zero_retry=0;
+  int max_zero_retry=5;

   struct timeval tp_start;
   GetTimeOfDay(&tp_start);
@@ -717,6 +720,8 @@
       /* write a tar header, don't bother with mode - just set to
100644 */
       writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644
\0", ftype);

+      zero_retry=0;
+
       while (nread < finfo.size && !close_done)        {

              DEBUG(3,("nread=%d\n",nread));
@@ -737,8 +742,15 @@

              nread += datalen;
              if (datalen == 0) {
-                     DEBUG(0,("Error reading file %s. Got 0 bytes\n",
rname));
-                     break;
+                     /* This *can* happen if the samba server is asking
for files
+                         faster than the NT/95 client can give it.
We'll try max_zero_retry times */
+                     if(zero_retry>=max_zero_retry) {
+                             DEBUG(0,("Zero Byte Error reading file %s.
Read FAILED.\n", rname));
+                             break;
+                     } else {
+                             zero_retry++;
+                             DEBUG(0,("Zero Byte Error reading file %s:
- Retrying %d of %d)\n", rname, zero_retr
y, max_zero_retry));
+                     };
              }

              datalen=0;

---- CUT ------

Jim Delahanty
Gulf Interstate Engineering



More information about the samba mailing list