>From 1250c1be64a3d5ae51315bec56914f41a59d2c8a Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Wed, 7 Apr 2010 21:04:01 +0100 Subject: [PATCH] Fix tar-in command hangs when running out of disk space (RHBZ#580246). This includes a regression test to ensure we've really fixed this. --- daemon/daemon.h | 2 +- daemon/proto.c | 4 ++- daemon/tar.c | 8 +++--- daemon/upload.c | 4 +- regressions/Makefile.am | 1 + regressions/rhbz580246.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 8 deletions(-) create mode 100755 regressions/rhbz580246.sh diff --git a/daemon/daemon.h b/daemon/daemon.h index 19dd69c..ebbeaa2 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -133,7 +133,7 @@ extern void reply_with_perror_errno (int err, const char *fs, ...) /* daemon functions that receive files (FileIn) should call * receive_file for each FileIn parameter. */ -typedef int (*receive_cb) (void *opaque, const void *buf, int len); +typedef int (*receive_cb) (void *opaque, const void *buf, size_t len); extern int receive_file (receive_cb cb, void *opaque); /* daemon functions that receive files (FileIn) can call this diff --git a/daemon/proto.c b/daemon/proto.c index 0002d80..507f324 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -380,8 +380,10 @@ receive_file (receive_cb cb, void *opaque) r = 0; xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk); - if (r == -1) /* write error */ + if (r == -1) { /* write error */ + fprintf (stderr, "receive_file: write error\n"); return -1; + } } } diff --git a/daemon/tar.c b/daemon/tar.c index ebcaded..2d44022 100644 --- a/daemon/tar.c +++ b/daemon/tar.c @@ -28,10 +28,10 @@ #include "actions.h" static int -fwrite_cb (void *fp_ptr, const void *buf, int len) +fwrite_cb (void *fp_ptr, const void *buf, size_t len) { FILE *fp = *(FILE **)fp_ptr; - return fwrite (buf, len, 1, fp) == 1 ? 0 : -1; + return fwrite (buf, 1, len, fp) < len ? 0 : -1; } /* Has one FileIn parameter. */ @@ -76,7 +76,7 @@ do_tar_in (const char *dir) err = errno; cancel_receive (); errno = err; - reply_with_perror ("write: %s", dir); + reply_with_error ("write error on directory: %s", dir); pclose (fp); return -1; } @@ -197,7 +197,7 @@ do_tgz_in (const char *dir) err = errno; cancel_receive (); errno = err; - reply_with_perror ("write: %s", dir); + reply_with_error ("write error on directory: %s", dir); pclose (fp); return -1; } diff --git a/daemon/upload.c b/daemon/upload.c index e15eade..2cc458b 100644 --- a/daemon/upload.c +++ b/daemon/upload.c @@ -28,7 +28,7 @@ #include "actions.h" static int -write_cb (void *fd_ptr, const void *buf, int len) +write_cb (void *fd_ptr, const void *buf, size_t len) { int fd = *(int *)fd_ptr; return xwrite (fd, buf, len); @@ -65,7 +65,7 @@ do_upload (const char *filename) err = errno; cancel_receive (); errno = err; - reply_with_perror ("write: %s", filename); + reply_with_error ("write error: %s", filename); close (fd); return -1; } diff --git a/regressions/Makefile.am b/regressions/Makefile.am index 2710e82..e8e43cf 100644 --- a/regressions/Makefile.am +++ b/regressions/Makefile.am @@ -27,6 +27,7 @@ TESTS = \ rhbz503169c10.sh \ rhbz503169c13.sh \ rhbz557655.sh \ + rhbz580246.sh \ test-cancellation-download-librarycancels.sh \ test-cancellation-upload-daemoncancels.sh \ test-find0.sh \ diff --git a/regressions/rhbz580246.sh b/regressions/rhbz580246.sh new file mode 100755 index 0000000..707231e --- /dev/null +++ b/regressions/rhbz580246.sh @@ -0,0 +1,47 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2010 Red Hat Inc. +# +# 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 or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# Test tar_in call when we upload something which is larger than +# available space. +# https://bugzilla.redhat.com/show_bug.cgi?id=580246 + +set -e +export LANG=C + +rm -f test.img test.tar + +dd if=/dev/zero of=test.img bs=1M count=2 +tar cf test.tar test.img + +output=$( +../fish/guestfish 2>&1 <<'EOF' +add test.img +run +mkfs ext2 /dev/sda +mount /dev/sda / +-tar-in test.tar / +EOF +) + +rm -f test.img test.tar + +# Check for error message in the output. +if [[ ! $output =~ libguestfs:.error:.tar_in ]]; then + echo "Missing error message from tar-in (expecting an error message)" + exit 1 +fi -- 1.6.6.1