X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=device-src%2Frait-device.c;h=3acf81f6f9e61190486ae42f419fdd815a9efd10;hb=HEAD;hp=e8e8f2e658e89b17cc93c3e0b130cfdce0b0289b;hpb=b116e9366c7b2ea2c2eb53b0a13df4090e176235;p=debian%2Famanda diff --git a/device-src/rait-device.c b/device-src/rait-device.c index e8e8f2e..3acf81f 100644 --- a/device-src/rait-device.c +++ b/device-src/rait-device.c @@ -1,9 +1,10 @@ /* - * 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 @@ -28,7 +29,7 @@ #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) @@ -115,7 +116,7 @@ typedef struct RaitDevicePrivate_s { /* value of this semaphore is the number of threaded operations * in progress */ - semaphore_t *threads_sem; + amsemaphore_t *threads_sem; #endif } RaitDevicePrivate; @@ -286,7 +287,7 @@ rait_device_finalize(GObject *obj_self) } if (PRIVATE(self)->threads_sem) - semaphore_free(PRIVATE(self)->threads_sem); + amsemaphore_free(PRIVATE(self)->threads_sem); #endif amfree(self->private); } @@ -426,7 +427,7 @@ static gpointer rait_thread_pool_func(gpointer data) { 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); @@ -437,7 +438,7 @@ static void do_thread_pool_op(RaitDevice *self, GFunc func, GPtrArray * ops) { 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, @@ -449,7 +450,7 @@ static void do_thread_pool_op(RaitDevice *self, GFunc func, GPtrArray * ops) { 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); @@ -469,7 +470,7 @@ static void do_thread_pool_op(RaitDevice *self, GFunc func, GPtrArray * ops) { } /* wait until semaphore hits zero */ - semaphore_wait_empty(PRIVATE(self)->threads_sem); + amsemaphore_wait_empty(PRIVATE(self)->threads_sem); } #else /* USE_INTERNAL_THREADPOOL */ @@ -1134,6 +1135,7 @@ static DeviceStatusFlags rait_device_read_label(Device * dself) { 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); @@ -1221,7 +1223,9 @@ rait_device_start (Device * dself, DeviceAccessMode mode, char * label, 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); @@ -1300,6 +1304,12 @@ rait_device_start (Device * dself, DeviceAccessMode mode, char * label, } } + 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); @@ -1309,7 +1319,6 @@ rait_device_start (Device * dself, DeviceAccessMode mode, char * label, device_set_error(dself, failure_errmsgs, total_status); return FALSE; } - amfree(failure_errmsgs); return TRUE; } @@ -1398,9 +1407,12 @@ rait_device_start_file (Device * dself, dumpfile_t * info) { 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; } @@ -1578,6 +1590,9 @@ rait_device_write_block (Device * dself, guint size, gpointer data) { return FALSE; } else { dself->block ++; + g_mutex_lock(dself->device_mutex); + dself->bytes_written += size; + g_mutex_unlock(dself->device_mutex); return TRUE; } @@ -1620,7 +1635,9 @@ rait_device_finish_file (Device * dself) { return FALSE; } + g_mutex_lock(dself->device_mutex); dself->in_file = FALSE; + g_mutex_unlock(dself->device_mutex); return TRUE; } @@ -1649,9 +1666,12 @@ rait_device_seek_file (Device * dself, guint file) { 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 ++) { @@ -1716,7 +1736,9 @@ rait_device_seek_file (Device * dself, guint file) { } /* 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; @@ -1984,7 +2006,9 @@ rait_device_read_block (Device * dself, gpointer buf, int * size) { 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")), @@ -2001,6 +2025,9 @@ rait_device_read_block (Device * dself, gpointer buf, int * size) { 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;