]> git.sur5r.net Git - bacula/bacula/blob - bacula/platforms/freebsd/pthreads-fix.txt
Apply win32 fixes + add tapetest.c
[bacula/bacula] / bacula / platforms / freebsd / pthreads-fix.txt
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
5
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.
9
10 PROBLEM DESCRIPTION:
11
12 The FreeBSD pthreads library does not properly handle End Of Tape.
13 This problem will be fixed in FreeBSD 4.9.  The bug results in more
14 data being written to the tape than could be read.  Any backup which
15 involved more than one tape would be incomplete.
16
17 DEMONSTRATION:
18
19 To demonstrate the problem, tapetest.c can be obtained from 
20 http://www.freebsd.org/cgi/query-pr.cgi?pr=56274
21
22 This tests without pthreads:
23
24  *  If you build this program with:
25  *
26  *  c++ -g -O2 -Wall -c tapetest.c
27  *  c++ -g -O2 -Wall tapetest.o -o tapetest
28  *
29  *  Procedure for testing tape
30  *  ./tapetest /dev/your-tape-device
31  *  rewind
32  *  rawfill
33  *  rewind
34  *  scan
35  *
36  *  The output will be something like:
37  *
38  * ========
39  *  Rewound /dev/nsa0
40  *  *Begin writing blocks of 64512 bytes.
41  *  ++++++++++++++++++++ ...
42  *  Write failed.  Last block written=17294. stat=0 ERR=Unknown 
43 error: 0
44  *  weof_dev
45  *  Wrote EOF to /dev/nsa0
46  *  *Rewound /dev/nsa0
47  *  *Starting scan at file 0
48  *  17294 blocks of 64512 bytes in file 0
49  *  End of File mark.
50  *  End of File mark.
51  *  End of tape
52  *  Total files=1, blocks=17294, bytes = 1115670528
53  * ========
54  *
55  *  which is correct. Notice that the return status is
56  *  0, while in the example below, which fails, the return
57  *  status is -1.
58
59 This tests with pthreads:
60
61  *  If you build this program with:
62  *
63  *  c++ -g -O2 -Wall -pthread -c tapetest.c
64  *  c++ -g -O2 -Wall -pthread tapetest.o -o tapetest
65  *    Note, we simply added -pthread compared to the
66  *    previous example.
67  *
68  *  Procedure for testing tape
69  *  ./tapetest /dev/your-tape-device
70  *  rewind
71  *  rawfill
72  *  rewind
73  *  scan
74  *
75  *  The output will be something like:
76  *
77  * ========
78  *    Rewound /dev/nsa0
79  *    *Begin writing blocks of 64512 bytes.
80  *    +++++++++++++++++++++++++++++ ...
81  *    Write failed.  Last block written=17926. stat=-1 ERR=No space left on device
82  *    weof_dev
83  *    Wrote EOF to /dev/nsa0
84  *    *Rewound /dev/nsa0
85  *    *Starting scan at file 0
86  *    17913 blocks of 64512 bytes in file 0
87  *    End of File mark.
88  *    End of File mark.
89  *    End of tape
90  *    Total files=1, blocks=17913, bytes = 1155603456
91  * ========
92  *
93  * which is incroorect because it wrote 17,926 blocks but read
94  * back only 17,913 blocks
95
96 If you get the same number of blocks written and read WHEN using 
97 pthreads, then you've been correctly patched.
98
99 SOLUTION:
100
101 For FreeBSD prior to 4.9, you have two choices to ensure proper
102 backups.  These instructions assume you are familiar with patching
103 FreeBSD and already have the FreeBSD source code installed on your
104 machine.  
105
106 1 - cvsup and build your system to FreeBSD 4.8-STABLE
107
108 2 - Apply this patch.
109
110 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
111
112 To apply the patch, follow these instructions as root.  
113
114 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
115
116 cd /usr/src/lib/libc_r/uthread/
117 patch < /path/to/pthread.diff
118 cd ..
119 make all install
120
121 I recommend restarting Bacula.
122
123
124 TESTING:
125
126 I suggest running tapetest on your patched system and then
127 conducting a backup which spans two tapes.  Restore the data
128 and compare to the original.  If not identical, please let us know.
129