Imported Upstream version 2.6.1p2
[debian/amanda] / server-src / taper-disk-port-source.c
index 58f13d324774a66dc29133df7801bbc00243f560..94a513abe21d80f72c7edb807dd7be59d8c805df 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
- * Copyright (c) 2006 Zmanda Inc.
+ * Copyright (c) 2005-2008 Zmanda Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -186,6 +186,7 @@ static gboolean open_buffer_file(TaperDiskPortSource * self) {
     int fd;
     char * filename;
     mode_t old_umask;
+    TaperSource * pself = (TaperSource *)self;
 
     g_return_val_if_fail(self != NULL, FALSE);
     g_return_val_if_fail(self->buffer_dir_name != NULL, FALSE);
@@ -197,7 +198,8 @@ static gboolean open_buffer_file(TaperDiskPortSource * self) {
     fd = g_mkstemp(filename);
     umask(old_umask);
     if (fd < 0) {
-        g_fprintf(stderr, "Couldn't open temporary file with template %s: %s\n",
+       pself->errmsg = newvstrallocf(pself->errmsg,
+               "Couldn't open temporary file with template %s: %s",
                 filename, strerror(errno));
         return FALSE;
     }
@@ -235,13 +237,11 @@ static void store_excess(TaperDiskPortSource * self, char * buf,
 /* Handle the output of the small amount of saved in-memory data. */
 static size_t handle_excess_buffer_read(TaperDiskPortSource * self,
                                         void * buf, size_t count) {
-    TaperSource * pself = (TaperSource*)self;
     guint64 offset;
 
     /* First, do we have anything left? */
     if (selfp->retry_data_written >=
         (selfp->disk_buffered_bytes + selfp->excess_buffer_size)) {
-        pself->end_of_part = TRUE;
         return 0;
     }
     
@@ -316,6 +316,8 @@ static ssize_t write_disk_buffer(TaperDiskPortSource * self, char * buf,
 static ssize_t 
 taper_disk_port_source_read (TaperSource * pself, void * buf, size_t count) {
     TaperDiskPortSource * self = (TaperDiskPortSource*)pself;
+    int read_result;
+    int result;
 
     g_return_val_if_fail (self != NULL, -1);
     g_return_val_if_fail (TAPER_IS_DISK_PORT_SOURCE (self), -1);
@@ -343,7 +345,6 @@ taper_disk_port_source_read (TaperSource * pself, void * buf, size_t count) {
 
         if (selfp->retry_data_written < selfp->disk_buffered_bytes) {
             /* Read from disk. */
-            int result;
             count = MIN(count, selfp->disk_buffered_bytes -
                                selfp->retry_data_written);
             result = read(selfp->buffer_fd, buf, count);
@@ -356,40 +357,42 @@ taper_disk_port_source_read (TaperSource * pself, void * buf, size_t count) {
             }
         } else if (selfp->excess_buffer != NULL) {
             /* We are writing out the last bit of buffer. Handle that. */
-            return handle_excess_buffer_read(self, buf, count);
-        } else {
-            /* No more data. */
-            pself->end_of_part = TRUE;
-            return 0;
+            result = handle_excess_buffer_read(self, buf, count);
+           if (result) {
+               return result;
+           }
         }
-        
-        g_assert_not_reached();
-    } else {
-        /* Read from port. */
-        int read_result;
-        count = MIN(count, pself->max_part_size - selfp->disk_buffered_bytes);
-        if (count == 0) /* It was nonzero before. */ {
-            pself->end_of_part = TRUE;
-            return 0;
-        }
-        
-        read_result = source_parent_class->read(pself, buf, count);
-        /* Parent handles EOF and other goodness. */
-        if (read_result <= 0) {
-            return read_result;
-        }
-        /* Now write to disk buffer. */
-        return write_disk_buffer(self, buf, read_result);
+
+       /* No more cached data -- start reading from the part again */
+       selfp->retry_mode = FALSE;
     }
+
+    /* Read from port. */
+    count = MIN(count, pself->max_part_size - selfp->disk_buffered_bytes);
+    if (count == 0) /* It was nonzero before. */ {
+       pself->end_of_part = TRUE;
+       return 0;
+    }
+
+    read_result = source_parent_class->read(pself, buf, count);
+    /* Parent handles EOF and other goodness. */
+    if (read_result <= 0) {
+       return read_result;
+    }
+
+    /* Now write to disk buffer. */
+    return write_disk_buffer(self, buf, read_result);
 }
 
 /* Try seeking back to byte 0. If that fails, then we mark ourselves
    as having a disk problem. Returns FALSE in that case. */
 static gboolean try_rewind(TaperDiskPortSource * self) {
     gint64 result;
+    TaperSource * pself = (TaperSource *)self;
     result = lseek(selfp->buffer_fd, 0, SEEK_SET);
     if (result != 0) {
-        g_fprintf(stderr, "Couldn't seek split buffer: %s\n", strerror(errno));
+       pself->errmsg = newvstrallocf(pself->errmsg,
+               "Couldn't seek split buffer: %s", strerror(errno));
         selfp->disk_problem = TRUE;
         return FALSE;
     } else {
@@ -399,12 +402,8 @@ static gboolean try_rewind(TaperDiskPortSource * self) {
 
 static gboolean 
 taper_disk_port_source_seek_to_part_start (TaperSource * pself) {
-    TaperDiskPortSource * self = (TaperDiskPortSource*)pself;
-    g_return_val_if_fail (self != NULL, FALSE);
-    g_return_val_if_fail (TAPER_IS_DISK_PORT_SOURCE (pself), FALSE);
-    g_return_val_if_fail (selfp->disk_buffered_bytes
-                          + selfp->excess_buffer_size > 0, FALSE);
-    
+    TaperDiskPortSource * self = TAPER_DISK_PORT_SOURCE(pself);
+
     if (self->_priv->fallback != NULL) {
         return taper_source_seek_to_part_start(selfp->fallback);
     }