]> git.sur5r.net Git - bacula/bacula/blob - bacula/platforms/freebsd/pthreads-fix.txt
Update doc
[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. (note, the problem
14 was apparently not fixed in 4.9, and version 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.
18
19 DEMONSTRATION:
20
21 To demonstrate the problem, tapetest.c can be obtained from 
22 http://www.freebsd.org/cgi/query-pr.cgi?pr=56274
23
24 This tests without pthreads:
25
26  *  If you build this program with:
27  *
28  *  c++ -g -O2 -Wall -c tapetest.c
29  *  c++ -g -O2 -Wall tapetest.o -o tapetest
30  *
31  *  Procedure for testing tape
32  *  ./tapetest /dev/your-tape-device
33  *  rewind
34  *  rawfill
35  *  rewind
36  *  scan
37  *
38  *  The output will be something like:
39  *
40  * ========
41  *  Rewound /dev/nsa0
42  *  *Begin writing blocks of 64512 bytes.
43  *  ++++++++++++++++++++ ...
44  *  Write failed.  Last block written=17294. stat=0 ERR=Unknown 
45 error: 0
46  *  weof_dev
47  *  Wrote EOF to /dev/nsa0
48  *  *Rewound /dev/nsa0
49  *  *Starting scan at file 0
50  *  17294 blocks of 64512 bytes in file 0
51  *  End of File mark.
52  *  End of File mark.
53  *  End of tape
54  *  Total files=1, blocks=17294, bytes = 1115670528
55  * ========
56  *
57  *  which is correct. Notice that the return status is
58  *  0, while in the example below, which fails, the return
59  *  status is -1.
60
61 This tests with pthreads:
62
63  *  If you build this program with:
64  *
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
68  *    previous example.
69  *
70  *  Procedure for testing tape
71  *  ./tapetest /dev/your-tape-device
72  *  rewind
73  *  rawfill
74  *  rewind
75  *  scan
76  *
77  *  The output will be something like:
78  *
79  * ========
80  *    Rewound /dev/nsa0
81  *    *Begin writing blocks of 64512 bytes.
82  *    +++++++++++++++++++++++++++++ ...
83  *    Write failed.  Last block written=17926. stat=-1 ERR=No space left on device
84  *    weof_dev
85  *    Wrote EOF to /dev/nsa0
86  *    *Rewound /dev/nsa0
87  *    *Starting scan at file 0
88  *    17913 blocks of 64512 bytes in file 0
89  *    End of File mark.
90  *    End of File mark.
91  *    End of tape
92  *    Total files=1, blocks=17913, bytes = 1155603456
93  * ========
94  *
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.
98
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.  
103
104 SOLUTION:
105
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.
111
112 Do one of the following:
113
114 - cvsup and build your system to FreeBSD 4.x-STABLE after the
115   date Mon Dec 29 15:18:01 2003 UTC
116
117 - Apply this patch.
118
119   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
120
121   To apply the patch, follow these instructions as root.  
122
123     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'
124
125     cd /usr/src/lib/libc_r/uthread/
126     patch < /path/to/pthread.diff
127     cd ..
128     make all install
129
130 You should then recompile Bacula to get the new library
131 code included by doing:
132
133   cd <bacula-source>
134   make clean
135   make 
136   ...
137
138
139 TESTING:
140
141 I suggest running tapetest on your patched system and then
142 conducting a backup which spans two tapes.  Restore the data
143 and compare to the original.  If not identical, please let us know.
144
145 tapetest.c can also be found in the Bacula source distribution
146 in <bacula-source>/platforms/freebsd/tapetest.c