/*
- * Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved.
+ * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published
- * by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
#include "glib-util.h"
#include "device.h"
#include "fileheader.h"
-#include "semaphore.h"
+#include "amsemaphore.h"
/* Just a note about the failure mode of different operations:
- Recovers from a failure (enters degraded mode)
/* value of this semaphore is the number of threaded operations
* in progress */
- semaphore_t *threads_sem;
+ amsemaphore_t *threads_sem;
#endif
} RaitDevicePrivate;
}
if (PRIVATE(self)->threads_sem)
- semaphore_free(PRIVATE(self)->threads_sem);
+ amsemaphore_free(PRIVATE(self)->threads_sem);
#endif
amfree(self->private);
}
inf->data = NULL;
/* indicate that we're finished; will not block */
- semaphore_down(inf->private->threads_sem);
+ amsemaphore_down(inf->private->threads_sem);
}
}
g_mutex_unlock(inf->mutex);
guint i;
if (PRIVATE(self)->threads_sem == NULL)
- PRIVATE(self)->threads_sem = semaphore_new_with_value(0);
+ PRIVATE(self)->threads_sem = amsemaphore_new_with_value(0);
if (PRIVATE(self)->threads == NULL)
PRIVATE(self)->threads = g_array_sized_new(FALSE, TRUE,
g_array_set_size(PRIVATE(self)->threads, ops->len);
/* the semaphore will hit zero when each thread has decremented it */
- semaphore_force_set(PRIVATE(self)->threads_sem, ops->len);
+ amsemaphore_force_set(PRIVATE(self)->threads_sem, ops->len);
for (i = 0; i < ops->len; i++) {
ThreadInfo *inf = &g_array_index(PRIVATE(self)->threads, ThreadInfo, i);
}
/* wait until semaphore hits zero */
- semaphore_wait_empty(PRIVATE(self)->threads_sem);
+ amsemaphore_wait_empty(PRIVATE(self)->threads_sem);
}
#else /* USE_INTERNAL_THREADPOOL */
if (first_success->volume_header != NULL) {
dself->volume_header = dumpfile_copy(first_success->volume_header);
}
+ dself->header_block_size = first_success->header_block_size;
}
g_ptr_array_free_full(ops);
return FALSE;
dself->access_mode = mode;
+ g_mutex_lock(dself->device_mutex);
dself->in_file = FALSE;
+ g_mutex_unlock(dself->device_mutex);
amfree(dself->volume_label);
amfree(dself->volume_time);
dumpfile_free(dself->volume_header);
}
}
+ if (total_status == DEVICE_STATUS_SUCCESS) {
+ StartOp * op = g_ptr_array_index(ops, 0);
+ Device *child = op->base.child;
+ dself->header_block_size = child->header_block_size;
+ }
+
amfree(label_from_device);
g_ptr_array_free_full(ops);
device_set_error(dself, failure_errmsgs, total_status);
return FALSE;
}
-
amfree(failure_errmsgs);
return TRUE;
}
return FALSE;
}
- dself->in_file = TRUE;
g_assert(actual_file >= 1);
dself->file = actual_file;
+ g_mutex_lock(dself->device_mutex);
+ dself->in_file = TRUE;
+ dself->bytes_written = 0;
+ g_mutex_unlock(dself->device_mutex);
return TRUE;
}
return FALSE;
} else {
dself->block ++;
+ g_mutex_lock(dself->device_mutex);
+ dself->bytes_written += size;
+ g_mutex_unlock(dself->device_mutex);
return TRUE;
}
return FALSE;
}
+ g_mutex_lock(dself->device_mutex);
dself->in_file = FALSE;
+ g_mutex_unlock(dself->device_mutex);
return TRUE;
}
if (rait_device_in_error(self)) return NULL;
- dself->in_file = FALSE;
dself->is_eof = FALSE;
dself->block = 0;
+ g_mutex_lock(dself->device_mutex);
+ dself->in_file = FALSE;
+ dself->bytes_read = 0;
+ g_mutex_unlock(dself->device_mutex);
ops = g_ptr_array_sized_new(self->private->children->len);
for (i = 0; i < self->private->children->len; i ++) {
}
/* update our state */
+ g_mutex_lock(dself->device_mutex);
dself->in_file = in_file;
+ g_mutex_unlock(dself->device_mutex);
dself->file = actual_file;
return rval;
stralloc(_("EOF")),
DEVICE_STATUS_SUCCESS);
dself->is_eof = TRUE;
+ g_mutex_lock(dself->device_mutex);
dself->in_file = FALSE;
+ g_mutex_unlock(dself->device_mutex);
} else {
device_set_error(dself,
stralloc(_("All child devices failed to read, but not all are at eof")),
if (success) {
dself->block++;
*size = blocksize;
+ g_mutex_lock(dself->device_mutex);
+ dself->bytes_read += blocksize;
+ g_mutex_unlock(dself->device_mutex);
return blocksize;
} else {
return -1;