X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Ftaper-mem-port-source.c;h=d201e45a03757b1a3b16c7b15acd020822fe9819;hb=2627875b7d18858bc1f9f7652811e4d8c15a23eb;hp=0540845bb03275f594a7e31c661ff5d33383144a;hpb=fb2bd066c2f8b34addafe48d62550e3033a59431;p=debian%2Famanda diff --git a/server-src/taper-mem-port-source.c b/server-src/taper-mem-port-source.c index 0540845..d201e45 100644 --- a/server-src/taper-mem-port-source.c +++ b/server-src/taper-mem-port-source.c @@ -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 @@ -21,8 +21,6 @@ #include "taper-mem-port-source.h" -#include "physmem.h" - struct _TaperMemPortSourcePrivate { /* Actual size of this buffer is given by max_part_size in TaperSource. */ char * retry_buffer; @@ -112,33 +110,36 @@ static int taper_mem_port_source_predict_parts(TaperSource * pself) { } /* Allocate buffer space, if it hasn't been done yet. */ -static void setup_retry_buffer(TaperMemPortSource * self) { +static gboolean +setup_retry_buffer(TaperMemPortSource * self) { + TaperSource *pself = TAPER_SOURCE(self); guint64 alloc_size; - guint64 max_usage; if (selfp->retry_buffer != NULL) - return; + return TRUE; - alloc_size = TAPER_SOURCE(self)->max_part_size; + alloc_size = pself->max_part_size; if (alloc_size > SIZE_MAX) { g_fprintf(stderr, "Fallback split size of %lld is greater that system maximum of %lld.\n", (long long)alloc_size, (long long)SIZE_MAX); alloc_size = SIZE_MAX; } - max_usage = physmem_available() * .95; - if (alloc_size > max_usage) { - g_fprintf(stderr, "Fallback split size of %lld is greater than 95%% of available memory (%lld bytes).\n", (long long)alloc_size, (long long)max_usage); - alloc_size = max_usage; - } - if (alloc_size < DISK_BLOCK_BYTES * 10) { g_fprintf(stderr, "Fallback split size of %ju is smaller than 10 blocks (%u bytes).\n", (uintmax_t)alloc_size, DISK_BLOCK_BYTES * 10); alloc_size = DISK_BLOCK_BYTES * 10; } - TAPER_SOURCE(self)->max_part_size = alloc_size; + pself->max_part_size = alloc_size; selfp->retry_buffer = malloc(alloc_size); + + if (selfp->retry_buffer == NULL) { + pself->errmsg = g_strdup_printf(_("Can't allocate %ju bytes of memory for split buffer"), + (uintmax_t)pself->max_part_size); + return FALSE; + } + + return TRUE; } static ssize_t @@ -165,7 +166,8 @@ taper_mem_port_source_read (TaperSource * pself, void * buf, size_t count) { } else { int read_result; if (selfp->retry_buffer == NULL) { - setup_retry_buffer(self); + if (!setup_retry_buffer(self)) + return -1; } count = MIN(count, pself->max_part_size - selfp->buffer_len);