1 From: "Dan Langille" <dan@langille.org>
2 To: bacula-users@lists.sourceforge.net
3 Subject: [Bacula-users] FreeBSD - large backups to tape
4 Date: Mon, 20 Oct 2003 15:29:18 -0400
6 Kern and I have been working on a FreeBSD/Bacula problem.
7 He's asked me to post this to the list. The problem was within the
8 FreeBSD pthreads library. A solution has been found.
12 The FreeBSD pthreads library does not properly handle End Of Tape.
13 This problem will be fixed in FreeBSD 4.9. (note, the problem
14 was apparently not fixed in 4.9, and versions prior to 4.10-RELEASE
15 and 5.2.1-RELEASE need to be patched). The bug results in more
16 data being written to the tape than could be read. Any backup which
17 involved more than one tape would be incomplete.
21 To demonstrate the problem, tapetest.c can be obtained from
22 http://www.freebsd.org/cgi/query-pr.cgi?pr=56274
24 This tests without pthreads:
26 * If you build this program with:
28 * c++ -g -O2 -Wall -c tapetest.c
29 * c++ -g -O2 -Wall tapetest.o -o tapetest
31 * Procedure for testing tape
32 * ./tapetest /dev/your-tape-device
38 * The output will be something like:
42 * *Begin writing blocks of 64512 bytes.
43 * ++++++++++++++++++++ ...
44 * Write failed. Last block written=17294. stat=0 ERR=Unknown
47 * Wrote EOF to /dev/nsa0
49 * *Starting scan at file 0
50 * 17294 blocks of 64512 bytes in file 0
54 * Total files=1, blocks=17294, bytes = 1115670528
57 * which is correct. Notice that the return status is
58 * 0, while in the example below, which fails, the return
61 This tests with pthreads:
63 * If you build this program with:
65 * c++ -g -O2 -Wall -pthread -c tapetest.c
66 * c++ -g -O2 -Wall -pthread tapetest.o -o tapetest
67 * Note, we simply added -pthread compared to the
70 * Procedure for testing tape
71 * ./tapetest /dev/your-tape-device
77 * The output will be something like:
81 * *Begin writing blocks of 64512 bytes.
82 * +++++++++++++++++++++++++++++ ...
83 * Write failed. Last block written=17926. stat=-1 ERR=No space left on device
85 * Wrote EOF to /dev/nsa0
87 * *Starting scan at file 0
88 * 17913 blocks of 64512 bytes in file 0
92 * Total files=1, blocks=17913, bytes = 1155603456
95 * which is incorrect because it wrote 17,926 blocks but read
96 * back only 17,913 blocks AND the status on the last block
97 * written was -1 when it should have been 0.
99 If you get the same number of blocks written and read WHEN using
100 pthreads, and the test with pthreads enabled returns a stat=0
101 on the last write, and the scan operation returns no error
102 code, then you've been correctly patched.
106 For FreeBSD prior to and including 4.9, in other words, for
107 FreeBSD prior to 4.10-RELEASE and 5.2.1-RELEASE you have two
108 choices to ensure proper backups. These instructions assume you
109 are familiar with patching FreeBSD and already have the FreeBSD
110 source code installed on your machine.
114 Do one of the following:
116 - cvsup and build your system to FreeBSD 4.x-STABLE after the
117 date Mon Dec 29 15:18:01 2003 UTC
121 http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc_r/uthread/uthread_write.c.diff?r1=1.16.2.6&r2=1.16.2.8
123 To apply the patch, follow these instructions as root.
125 fetch -o pthread.diff 'http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc_r/uthread/uthread_write.c.diff?r1=1.16.2.6&r2=1.16.2.8'
127 cd /usr/src/lib/libc_r/uthread/
128 patch < /path/to/pthread.diff
134 Do one of the following:
136 - cvsup and build your >= 5.2 system to FreeBSD 5.x after the
137 date Wed Dec 17 16:44:03 2003 UTC
141 http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc_r/uthread/uthread_write.c.diff?r1=1.22&r2=1.23
143 Wed Dec 17 16:44:03 2003 UTC
145 To apply the patch, follow these instructions as root.
147 fetch -o pthread.diff 'http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc_r/uthread/uthread_write.c.diff?r1=1.22&r2=1.23'
149 cd /usr/src/lib/libc_r/uthread/
150 patch < /path/to/pthread.diff
154 After patching your system as shown above,
155 you should then recompile Bacula to get the new library
156 code included by doing:
166 I suggest running tapetest on your patched system and then
167 conducting a backup which spans two tapes. Restore the data
168 and compare to the original. If not identical, please let us know.
170 tapetest.c can also be found in the Bacula source distribution
171 in <bacula-source>/platforms/freebsd/tapetest.c