~ubuntu-branches/ubuntu/edgy/xfsprogs/edgy

« back to all changes in this revision

Viewing changes to libxlog/xfs_log_recover.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2004-07-28 21:11:38 UTC
  • Revision ID: james.westby@ubuntu.com-20040728211138-0v4pdnunnp7na5lm
Tags: 2.6.20-1
* New upstream release.
* Fix xfs_io segfault on non-XFS files.  (closes: #260470)
* Fix packaging botch, deleted files included.  (closes: #260491)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3
 
 * 
 
2
 * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
 
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of version 2 of the GNU General Public License as
6
6
 * published by the Free Software Foundation.
7
 
 * 
 
7
 *
8
8
 * This program is distributed in the hope that it would be useful, but
9
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 
 * 
 
11
 *
12
12
 * Further, this software is distributed without any warranty that it is
13
13
 * free of the rightful claim of any third person regarding infringement
14
14
 * or the like.  Any license provided herein, whether implied or
15
15
 * otherwise, applies only to this software file.  Patent licenses, if
16
16
 * any, provided herein do not apply to combinations of this program with
17
17
 * other software, or any other product whatsoever.
18
 
 * 
 
18
 *
19
19
 * You should have received a copy of the GNU General Public License along
20
20
 * with this program; if not, write the Free Software Foundation, Inc., 59
21
21
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22
 
 * 
 
22
 *
23
23
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
24
 * Mountain View, CA  94043, or:
25
 
 * 
26
 
 * http://www.sgi.com 
27
 
 * 
28
 
 * For further information regarding this notice, see: 
29
 
 * 
 
25
 *
 
26
 * http://www.sgi.com
 
27
 *
 
28
 * For further information regarding this notice, see:
 
29
 *
30
30
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31
31
 */
32
32
 
33
 
#include <libxlog.h>
 
33
#include <xfs/libxlog.h>
 
34
 
 
35
#define xlog_unpack_data_checksum(rhead, dp, log)       ((void)0)
 
36
#define xlog_clear_stale_blocks(log, tail_lsn)          (0)
 
37
#define xfs_readonly_buftarg(buftarg)                   (0)
34
38
 
35
39
/*
36
40
 * This routine finds (to an approximation) the first block in the physical
39
43
 * necessarily be perfect.
40
44
 */
41
45
int
42
 
xlog_find_cycle_start(xlog_t    *log,
43
 
                      xfs_buf_t *bp,
44
 
                      xfs_daddr_t       first_blk,
45
 
                      xfs_daddr_t       *last_blk,
46
 
                      uint      cycle)
 
46
xlog_find_cycle_start(
 
47
        xlog_t          *log,
 
48
        xfs_buf_t       *bp,
 
49
        xfs_daddr_t     first_blk,
 
50
        xfs_daddr_t     *last_blk,
 
51
        uint            cycle)
47
52
{
48
 
        xfs_daddr_t mid_blk;
49
 
        uint    mid_cycle;
50
 
        int     error;
 
53
        xfs_caddr_t     offset;
 
54
        xfs_daddr_t     mid_blk;
 
55
        uint            mid_cycle;
 
56
        int             error;
51
57
 
52
58
        mid_blk = BLK_AVG(first_blk, *last_blk);
53
59
        while (mid_blk != first_blk && mid_blk != *last_blk) {
54
60
                if ((error = xlog_bread(log, mid_blk, 1, bp)))
55
61
                        return error;
56
 
                mid_cycle = GET_CYCLE(XFS_BUF_PTR(bp), ARCH_CONVERT);
 
62
                offset = xlog_align(log, mid_blk, 1, bp);
 
63
                mid_cycle = GET_CYCLE(offset, ARCH_CONVERT);
57
64
                if (mid_cycle == cycle) {
58
65
                        *last_blk = mid_blk;
59
66
                        /* last_half_cycle == mid_cycle */
67
74
               (mid_blk == *last_blk && mid_blk-1 == first_blk));
68
75
 
69
76
        return 0;
70
 
}       /* xlog_find_cycle_start */
71
 
 
 
77
}
72
78
 
73
79
/*
74
80
 * Check that the range of blocks does not contain the cycle number
77
83
 * test.  If the region is completely good, we end up returning the same
78
84
 * last block number.
79
85
 *
80
 
 * Return -1 if we encounter no errors.  This is an invalid block number
 
86
 * Set blkno to -1 if we encounter no errors.  This is an invalid block number
81
87
 * since we don't ever expect logs to get this large.
82
88
 */
83
 
 
84
 
STATIC xfs_daddr_t
85
 
xlog_find_verify_cycle( xlog_t          *log,
86
 
                        xfs_daddr_t     start_blk,
87
 
                        int             nbblks,
88
 
                        uint            stop_on_cycle_no)
 
89
STATIC int
 
90
xlog_find_verify_cycle(
 
91
        xlog_t          *log,
 
92
        xfs_daddr_t     start_blk,
 
93
        int             nbblks,
 
94
        uint            stop_on_cycle_no,
 
95
        xfs_daddr_t     *new_blk)
89
96
{
90
 
        int                     i, j;
91
 
        uint                    cycle;
92
 
        xfs_buf_t               *bp;
93
 
        char                    *buf        = NULL;
94
 
        int                     error       = 0;
95
 
        xfs_daddr_t             bufblks     = nbblks;
96
 
 
97
 
        while (!(bp = xlog_get_bp(bufblks, log->l_mp))) {
98
 
                /* can't get enough memory to do everything in one big buffer */
 
97
        xfs_daddr_t     i, j;
 
98
        uint            cycle;
 
99
        xfs_buf_t       *bp;
 
100
        xfs_daddr_t     bufblks;
 
101
        xfs_caddr_t     buf = NULL;
 
102
        int             error = 0;
 
103
 
 
104
        bufblks = 1 << ffs(nbblks);
 
105
 
 
106
        while (!(bp = xlog_get_bp(log, bufblks))) {
 
107
                /* can't get enough memory to do everything in one big buffer */
99
108
                bufblks >>= 1;
100
 
                if (!bufblks)
101
 
                        return -ENOMEM;
102
 
        }
103
 
        
104
 
 
105
 
        for (i = start_blk; i < start_blk + nbblks; i += bufblks)  {
106
 
                int bcount = min(bufblks, (start_blk + nbblks - i));
107
 
 
108
 
                if ((error = xlog_bread(log, i, bcount, bp)))
109
 
                        goto out;
110
 
 
111
 
                buf = XFS_BUF_PTR(bp);
 
109
                if (bufblks <= log->l_sectbb_log)
 
110
                        return ENOMEM;
 
111
        }
 
112
 
 
113
        for (i = start_blk; i < start_blk + nbblks; i += bufblks) {
 
114
                int     bcount;
 
115
 
 
116
                bcount = min(bufblks, (start_blk + nbblks - i));
 
117
 
 
118
                if ((error = xlog_bread(log, i, bcount, bp)))
 
119
                        goto out;
 
120
 
 
121
                buf = xlog_align(log, i, bcount, bp);
112
122
                for (j = 0; j < bcount; j++) {
113
123
                        cycle = GET_CYCLE(buf, ARCH_CONVERT);
114
124
                        if (cycle == stop_on_cycle_no) {
115
 
                                error = i;
 
125
                                *new_blk = i+j;
116
126
                                goto out;
117
127
                        }
118
 
                
119
 
                        buf += BBSIZE;
 
128
 
 
129
                        buf += BBSIZE;
120
130
                }
121
131
        }
122
132
 
123
 
        error = -1;
 
133
        *new_blk = -1;
124
134
 
125
135
out:
126
136
        xlog_put_bp(bp);
127
 
 
128
137
        return error;
129
 
}       /* xlog_find_verify_cycle */
130
 
 
 
138
}
131
139
 
132
140
/*
133
141
 * Potentially backup over partial log record write.
141
149
 * extra_bblks is the number of blocks potentially verified on a previous
142
150
 * call to this routine.
143
151
 */
144
 
 
145
152
STATIC int
146
 
xlog_find_verify_log_record(xlog_t      *log,
147
 
                            xfs_daddr_t start_blk,
148
 
                            xfs_daddr_t *last_blk,
149
 
                            int         extra_bblks)
 
153
xlog_find_verify_log_record(
 
154
        xlog_t                  *log,
 
155
        xfs_daddr_t             start_blk,
 
156
        xfs_daddr_t             *last_blk,
 
157
        int                     extra_bblks)
150
158
{
151
 
    xfs_daddr_t         i;
152
 
    xfs_buf_t           *bp;
153
 
    char                *buf        = NULL;
154
 
    xlog_rec_header_t   *head       = NULL;
155
 
    int                 error       = 0;
156
 
    int                 smallmem    = 0;
157
 
    int                 num_blks    = *last_blk - start_blk;
158
 
 
159
 
    ASSERT(start_blk != 0 || *last_blk != start_blk);
160
 
 
161
 
    if (!(bp = xlog_get_bp(num_blks, log->l_mp))) {
162
 
        if (!(bp = xlog_get_bp(1, log->l_mp))) 
163
 
            return -ENOMEM;
164
 
        smallmem = 1;
165
 
        buf = XFS_BUF_PTR(bp);
166
 
    } else {
167
 
        if ((error = xlog_bread(log, start_blk, num_blks, bp)))
168
 
            goto out;
169
 
        buf = XFS_BUF_PTR(bp) + (num_blks - 1) * BBSIZE;
170
 
    }
171
 
    
172
 
 
173
 
    for (i=(*last_blk)-1; i>=0; i--) {
174
 
        if (i < start_blk) {
175
 
            /* legal log record not found */
176
 
            xlog_warn("XFS: Log inconsistent (didn't find previous header)");
177
 
#ifdef __KERNEL__
178
 
            ASSERT(0);
179
 
#endif
180
 
            error = XFS_ERROR(EIO);
181
 
            goto out;
182
 
        }
183
 
 
184
 
        if (smallmem && (error = xlog_bread(log, i, 1, bp)))
185
 
            goto out;
186
 
        head = (xlog_rec_header_t*)buf;
187
 
        
188
 
        if (INT_GET(head->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM)
189
 
            break;
190
 
        
191
 
        if (!smallmem)
192
 
            buf -= BBSIZE;
193
 
    }
194
 
 
195
 
    /*
196
 
     * We hit the beginning of the physical log & still no header.  Return
197
 
     * to caller.  If caller can handle a return of -1, then this routine
198
 
     * will be called again for the end of the physical log.
199
 
     */
200
 
    if (i == -1) {
201
 
        error = -1;
202
 
        goto out;
203
 
    }
204
 
 
205
 
    /* we have the final block of the good log (the first block
206
 
     * of the log record _before_ the head. So we check the uuid.
207
 
     */
208
 
        
209
 
    if ((error = xlog_header_check_mount(log->l_mp, head)))
210
 
        goto out;
211
 
    
212
 
    /*
213
 
     * We may have found a log record header before we expected one.
214
 
     * last_blk will be the 1st block # with a given cycle #.  We may end
215
 
     * up reading an entire log record.  In this case, we don't want to
216
 
     * reset last_blk.  Only when last_blk points in the middle of a log
217
 
     * record do we update last_blk.
218
 
     */
219
 
    if (*last_blk - i + extra_bblks 
220
 
                != BTOBB(INT_GET(head->h_len, ARCH_CONVERT))+1)
221
 
            *last_blk = i;
 
159
        xfs_daddr_t             i;
 
160
        xfs_buf_t               *bp;
 
161
        xfs_caddr_t             offset = NULL;
 
162
        xlog_rec_header_t       *head = NULL;
 
163
        int                     error = 0;
 
164
        int                     smallmem = 0;
 
165
        int                     num_blks = *last_blk - start_blk;
 
166
        int                     xhdrs;
 
167
 
 
168
        ASSERT(start_blk != 0 || *last_blk != start_blk);
 
169
 
 
170
        if (!(bp = xlog_get_bp(log, num_blks))) {
 
171
                if (!(bp = xlog_get_bp(log, 1)))
 
172
                        return ENOMEM;
 
173
                smallmem = 1;
 
174
        } else {
 
175
                if ((error = xlog_bread(log, start_blk, num_blks, bp)))
 
176
                        goto out;
 
177
                offset = xlog_align(log, start_blk, num_blks, bp);
 
178
                offset += ((num_blks - 1) << BBSHIFT);
 
179
        }
 
180
 
 
181
        for (i = (*last_blk) - 1; i >= 0; i--) {
 
182
                if (i < start_blk) {
 
183
                        /* valid log record not found */
 
184
                        xlog_warn(
 
185
                "XFS: Log inconsistent (didn't find previous header)");
 
186
                        ASSERT(0);
 
187
                        error = XFS_ERROR(EIO);
 
188
                        goto out;
 
189
                }
 
190
 
 
191
                if (smallmem) {
 
192
                        if ((error = xlog_bread(log, i, 1, bp)))
 
193
                                goto out;
 
194
                        offset = xlog_align(log, i, 1, bp);
 
195
                }
 
196
 
 
197
                head = (xlog_rec_header_t *)offset;
 
198
 
 
199
                if (XLOG_HEADER_MAGIC_NUM ==
 
200
                    INT_GET(head->h_magicno, ARCH_CONVERT))
 
201
                        break;
 
202
 
 
203
                if (!smallmem)
 
204
                        offset -= BBSIZE;
 
205
        }
 
206
 
 
207
        /*
 
208
         * We hit the beginning of the physical log & still no header.  Return
 
209
         * to caller.  If caller can handle a return of -1, then this routine
 
210
         * will be called again for the end of the physical log.
 
211
         */
 
212
        if (i == -1) {
 
213
                error = -1;
 
214
                goto out;
 
215
        }
 
216
 
 
217
        /*
 
218
         * We have the final block of the good log (the first block
 
219
         * of the log record _before_ the head. So we check the uuid.
 
220
         */
 
221
        if ((error = xlog_header_check_mount(log->l_mp, head)))
 
222
                goto out;
 
223
 
 
224
        /*
 
225
         * We may have found a log record header before we expected one.
 
226
         * last_blk will be the 1st block # with a given cycle #.  We may end
 
227
         * up reading an entire log record.  In this case, we don't want to
 
228
         * reset last_blk.  Only when last_blk points in the middle of a log
 
229
         * record do we update last_blk.
 
230
         */
 
231
        if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
 
232
                uint    h_size = INT_GET(head->h_size, ARCH_CONVERT);
 
233
 
 
234
                xhdrs = h_size / XLOG_HEADER_CYCLE_SIZE;
 
235
                if (h_size % XLOG_HEADER_CYCLE_SIZE)
 
236
                        xhdrs++;
 
237
        } else {
 
238
                xhdrs = 1;
 
239
        }
 
240
 
 
241
        if (*last_blk - i + extra_bblks
 
242
                        != BTOBB(INT_GET(head->h_len, ARCH_CONVERT)) + xhdrs)
 
243
                *last_blk = i;
222
244
 
223
245
out:
224
 
    xlog_put_bp(bp);
225
 
 
226
 
    return error;
227
 
}       /* xlog_find_verify_log_record */
 
246
        xlog_put_bp(bp);
 
247
        return error;
 
248
}
228
249
 
229
250
/*
230
251
 * Head is defined to be the point of the log where the next log write
231
252
 * write could go.  This means that incomplete LR writes at the end are
232
253
 * eliminated when calculating the head.  We aren't guaranteed that previous
233
 
 * LR have complete transactions.  We only know that a cycle number of 
 
254
 * LR have complete transactions.  We only know that a cycle number of
234
255
 * current cycle number -1 won't be present in the log if we start writing
235
256
 * from our current block number.
236
257
 *
237
258
 * last_blk contains the block number of the first block with a given
238
259
 * cycle number.
239
260
 *
240
 
 * Also called from xfs_log_print.c
241
 
 *
242
261
 * Return: zero if normal, non-zero if error.
243
262
 */
244
263
int
245
 
xlog_find_head(xlog_t  *log,
246
 
               xfs_daddr_t *return_head_blk)
 
264
xlog_find_head(
 
265
        xlog_t          *log,
 
266
        xfs_daddr_t     *return_head_blk)
247
267
{
248
 
    xfs_buf_t   *bp;
249
 
    xfs_daddr_t new_blk, first_blk, start_blk, last_blk, head_blk;
250
 
    int     num_scan_bblks;
251
 
    uint    first_half_cycle, last_half_cycle;
252
 
    uint    stop_on_cycle;
253
 
    int     error, log_bbnum = log->l_logBBsize;
254
 
 
255
 
    /* Is the end of the log device zeroed? */
256
 
    if ((error = xlog_find_zeroed(log, &first_blk)) == -1) {
257
 
        *return_head_blk = first_blk;
258
 
        
259
 
        /* is the whole lot zeroed? */
260
 
        if (!first_blk) {
261
 
            /* Linux XFS shouldn't generate totally zeroed logs -
262
 
             * mkfs etc write a dummy unmount record to a fresh
263
 
             * log so we can store the uuid in there
264
 
             */
265
 
            xlog_warn("XFS: totally zeroed log\n");
266
 
        }
267
 
        
 
268
        xfs_buf_t       *bp;
 
269
        xfs_caddr_t     offset;
 
270
        xfs_daddr_t     new_blk, first_blk, start_blk, last_blk, head_blk;
 
271
        int             num_scan_bblks;
 
272
        uint            first_half_cycle, last_half_cycle;
 
273
        uint            stop_on_cycle;
 
274
        int             error, log_bbnum = log->l_logBBsize;
 
275
 
 
276
        /* Is the end of the log device zeroed? */
 
277
        if ((error = xlog_find_zeroed(log, &first_blk)) == -1) {
 
278
                *return_head_blk = first_blk;
 
279
 
 
280
                /* Is the whole lot zeroed? */
 
281
                if (!first_blk) {
 
282
                        /* Linux XFS shouldn't generate totally zeroed logs -
 
283
                         * mkfs etc write a dummy unmount record to a fresh
 
284
                         * log so we can store the uuid in there
 
285
                         */
 
286
                        xlog_warn("XFS: totally zeroed log");
 
287
                }
 
288
 
 
289
                return 0;
 
290
        } else if (error) {
 
291
                xlog_warn("XFS: empty log check failed");
 
292
                return error;
 
293
        }
 
294
 
 
295
        first_blk = 0;                  /* get cycle # of 1st block */
 
296
        bp = xlog_get_bp(log, 1);
 
297
        if (!bp)
 
298
                return ENOMEM;
 
299
        if ((error = xlog_bread(log, 0, 1, bp)))
 
300
                goto bp_err;
 
301
        offset = xlog_align(log, 0, 1, bp);
 
302
        first_half_cycle = GET_CYCLE(offset, ARCH_CONVERT);
 
303
 
 
304
        last_blk = head_blk = log_bbnum - 1;    /* get cycle # of last block */
 
305
        if ((error = xlog_bread(log, last_blk, 1, bp)))
 
306
                goto bp_err;
 
307
        offset = xlog_align(log, last_blk, 1, bp);
 
308
        last_half_cycle = GET_CYCLE(offset, ARCH_CONVERT);
 
309
        ASSERT(last_half_cycle != 0);
 
310
 
 
311
        /*
 
312
         * If the 1st half cycle number is equal to the last half cycle number,
 
313
         * then the entire log is stamped with the same cycle number.  In this
 
314
         * case, head_blk can't be set to zero (which makes sense).  The below
 
315
         * math doesn't work out properly with head_blk equal to zero.  Instead,
 
316
         * we set it to log_bbnum which is an invalid block number, but this
 
317
         * value makes the math correct.  If head_blk doesn't changed through
 
318
         * all the tests below, *head_blk is set to zero at the very end rather
 
319
         * than log_bbnum.  In a sense, log_bbnum and zero are the same block
 
320
         * in a circular file.
 
321
         */
 
322
        if (first_half_cycle == last_half_cycle) {
 
323
                /*
 
324
                 * In this case we believe that the entire log should have
 
325
                 * cycle number last_half_cycle.  We need to scan backwards
 
326
                 * from the end verifying that there are no holes still
 
327
                 * containing last_half_cycle - 1.  If we find such a hole,
 
328
                 * then the start of that hole will be the new head.  The
 
329
                 * simple case looks like
 
330
                 *        x | x ... | x - 1 | x
 
331
                 * Another case that fits this picture would be
 
332
                 *        x | x + 1 | x ... | x
 
333
                 * In this case the head really is somwhere at the end of the
 
334
                 * log, as one of the latest writes at the beginning was
 
335
                 * incomplete.
 
336
                 * One more case is
 
337
                 *        x | x + 1 | x ... | x - 1 | x
 
338
                 * This is really the combination of the above two cases, and
 
339
                 * the head has to end up at the start of the x-1 hole at the
 
340
                 * end of the log.
 
341
                 *
 
342
                 * In the 256k log case, we will read from the beginning to the
 
343
                 * end of the log and search for cycle numbers equal to x-1.
 
344
                 * We don't worry about the x+1 blocks that we encounter,
 
345
                 * because we know that they cannot be the head since the log
 
346
                 * started with x.
 
347
                 */
 
348
                head_blk = log_bbnum;
 
349
                stop_on_cycle = last_half_cycle - 1;
 
350
        } else {
 
351
                /*
 
352
                 * In this case we want to find the first block with cycle
 
353
                 * number matching last_half_cycle.  We expect the log to be
 
354
                 * some variation on
 
355
                 *        x + 1 ... | x ...
 
356
                 * The first block with cycle number x (last_half_cycle) will
 
357
                 * be where the new head belongs.  First we do a binary search
 
358
                 * for the first occurrence of last_half_cycle.  The binary
 
359
                 * search may not be totally accurate, so then we scan back
 
360
                 * from there looking for occurrences of last_half_cycle before
 
361
                 * us.  If that backwards scan wraps around the beginning of
 
362
                 * the log, then we look for occurrences of last_half_cycle - 1
 
363
                 * at the end of the log.  The cases we're looking for look
 
364
                 * like
 
365
                 *        x + 1 ... | x | x + 1 | x ...
 
366
                 *                               ^ binary search stopped here
 
367
                 * or
 
368
                 *        x + 1 ... | x ... | x - 1 | x
 
369
                 *        <---------> less than scan distance
 
370
                 */
 
371
                stop_on_cycle = last_half_cycle;
 
372
                if ((error = xlog_find_cycle_start(log, bp, first_blk,
 
373
                                                &head_blk, last_half_cycle)))
 
374
                        goto bp_err;
 
375
        }
 
376
 
 
377
        /*
 
378
         * Now validate the answer.  Scan back some number of maximum possible
 
379
         * blocks and make sure each one has the expected cycle number.  The
 
380
         * maximum is determined by the total possible amount of buffering
 
381
         * in the in-core log.  The following number can be made tighter if
 
382
         * we actually look at the block size of the filesystem.
 
383
         */
 
384
        num_scan_bblks = XLOG_TOTAL_REC_SHIFT(log);
 
385
        if (head_blk >= num_scan_bblks) {
 
386
                /*
 
387
                 * We are guaranteed that the entire check can be performed
 
388
                 * in one buffer.
 
389
                 */
 
390
                start_blk = head_blk - num_scan_bblks;
 
391
                if ((error = xlog_find_verify_cycle(log,
 
392
                                                start_blk, num_scan_bblks,
 
393
                                                stop_on_cycle, &new_blk)))
 
394
                        goto bp_err;
 
395
                if (new_blk != -1)
 
396
                        head_blk = new_blk;
 
397
        } else {                /* need to read 2 parts of log */
 
398
                /*
 
399
                 * We are going to scan backwards in the log in two parts.
 
400
                 * First we scan the physical end of the log.  In this part
 
401
                 * of the log, we are looking for blocks with cycle number
 
402
                 * last_half_cycle - 1.
 
403
                 * If we find one, then we know that the log starts there, as
 
404
                 * we've found a hole that didn't get written in going around
 
405
                 * the end of the physical log.  The simple case for this is
 
406
                 *        x + 1 ... | x ... | x - 1 | x
 
407
                 *        <---------> less than scan distance
 
408
                 * If all of the blocks at the end of the log have cycle number
 
409
                 * last_half_cycle, then we check the blocks at the start of
 
410
                 * the log looking for occurrences of last_half_cycle.  If we
 
411
                 * find one, then our current estimate for the location of the
 
412
                 * first occurrence of last_half_cycle is wrong and we move
 
413
                 * back to the hole we've found.  This case looks like
 
414
                 *        x + 1 ... | x | x + 1 | x ...
 
415
                 *                               ^ binary search stopped here
 
416
                 * Another case we need to handle that only occurs in 256k
 
417
                 * logs is
 
418
                 *        x + 1 ... | x ... | x+1 | x ...
 
419
                 *                   ^ binary search stops here
 
420
                 * In a 256k log, the scan at the end of the log will see the
 
421
                 * x + 1 blocks.  We need to skip past those since that is
 
422
                 * certainly not the head of the log.  By searching for
 
423
                 * last_half_cycle-1 we accomplish that.
 
424
                 */
 
425
                start_blk = log_bbnum - num_scan_bblks + head_blk;
 
426
                ASSERT(head_blk <= INT_MAX &&
 
427
                        (xfs_daddr_t) num_scan_bblks - head_blk >= 0);
 
428
                if ((error = xlog_find_verify_cycle(log, start_blk,
 
429
                                        num_scan_bblks - (int)head_blk,
 
430
                                        (stop_on_cycle - 1), &new_blk)))
 
431
                        goto bp_err;
 
432
                if (new_blk != -1) {
 
433
                        head_blk = new_blk;
 
434
                        goto bad_blk;
 
435
                }
 
436
 
 
437
                /*
 
438
                 * Scan beginning of log now.  The last part of the physical
 
439
                 * log is good.  This scan needs to verify that it doesn't find
 
440
                 * the last_half_cycle.
 
441
                 */
 
442
                start_blk = 0;
 
443
                ASSERT(head_blk <= INT_MAX);
 
444
                if ((error = xlog_find_verify_cycle(log,
 
445
                                        start_blk, (int)head_blk,
 
446
                                        stop_on_cycle, &new_blk)))
 
447
                        goto bp_err;
 
448
                if (new_blk != -1)
 
449
                        head_blk = new_blk;
 
450
        }
 
451
 
 
452
 bad_blk:
 
453
        /*
 
454
         * Now we need to make sure head_blk is not pointing to a block in
 
455
         * the middle of a log record.
 
456
         */
 
457
        num_scan_bblks = XLOG_REC_SHIFT(log);
 
458
        if (head_blk >= num_scan_bblks) {
 
459
                start_blk = head_blk - num_scan_bblks; /* don't read head_blk */
 
460
 
 
461
                /* start ptr at last block ptr before head_blk */
 
462
                if ((error = xlog_find_verify_log_record(log, start_blk,
 
463
                                                        &head_blk, 0)) == -1) {
 
464
                        error = XFS_ERROR(EIO);
 
465
                        goto bp_err;
 
466
                } else if (error)
 
467
                        goto bp_err;
 
468
        } else {
 
469
                start_blk = 0;
 
470
                ASSERT(head_blk <= INT_MAX);
 
471
                if ((error = xlog_find_verify_log_record(log, start_blk,
 
472
                                                        &head_blk, 0)) == -1) {
 
473
                        /* We hit the beginning of the log during our search */
 
474
                        start_blk = log_bbnum - num_scan_bblks + head_blk;
 
475
                        new_blk = log_bbnum;
 
476
                        ASSERT(start_blk <= INT_MAX &&
 
477
                                (xfs_daddr_t) log_bbnum-start_blk >= 0);
 
478
                        ASSERT(head_blk <= INT_MAX);
 
479
                        if ((error = xlog_find_verify_log_record(log,
 
480
                                                        start_blk, &new_blk,
 
481
                                                        (int)head_blk)) == -1) {
 
482
                                error = XFS_ERROR(EIO);
 
483
                                goto bp_err;
 
484
                        } else if (error)
 
485
                                goto bp_err;
 
486
                        if (new_blk != log_bbnum)
 
487
                                head_blk = new_blk;
 
488
                } else if (error)
 
489
                        goto bp_err;
 
490
        }
 
491
 
 
492
        xlog_put_bp(bp);
 
493
        if (head_blk == log_bbnum)
 
494
                *return_head_blk = 0;
 
495
        else
 
496
                *return_head_blk = head_blk;
 
497
        /*
 
498
         * When returning here, we have a good block number.  Bad block
 
499
         * means that during a previous crash, we didn't have a clean break
 
500
         * from cycle number N to cycle number N-1.  In this case, we need
 
501
         * to find the first block with cycle number N-1.
 
502
         */
268
503
        return 0;
269
 
    } else if (error) {
270
 
        xlog_warn("XFS: empty log check failed");
271
 
        return error;
272
 
    }
273
 
 
274
 
    first_blk = 0;                              /* get cycle # of 1st block */
275
 
    bp = xlog_get_bp(1,log->l_mp);
276
 
    if (!bp)
277
 
        return -ENOMEM;
278
 
    if ((error = xlog_bread(log, 0, 1, bp)))
279
 
        goto bp_err;
280
 
    first_half_cycle = GET_CYCLE(XFS_BUF_PTR(bp), ARCH_CONVERT);
281
 
 
282
 
    last_blk = head_blk = log_bbnum-1;          /* get cycle # of last block */
283
 
    if ((error = xlog_bread(log, last_blk, 1, bp)))
284
 
        goto bp_err;
285
 
    last_half_cycle = GET_CYCLE(XFS_BUF_PTR(bp), ARCH_CONVERT);
286
 
    ASSERT(last_half_cycle != 0);
287
 
 
288
 
    /*
289
 
     * If the 1st half cycle number is equal to the last half cycle number,
290
 
     * then the entire log is stamped with the same cycle number.  In this
291
 
     * case, head_blk can't be set to zero (which makes sense).  The below
292
 
     * math doesn't work out properly with head_blk equal to zero.  Instead,
293
 
     * we set it to log_bbnum which is an illegal block number, but this
294
 
     * value makes the math correct.  If head_blk doesn't changed through
295
 
     * all the tests below, *head_blk is set to zero at the very end rather
296
 
     * than log_bbnum.  In a sense, log_bbnum and zero are the same block
297
 
     * in a circular file.
298
 
     */
299
 
    if (first_half_cycle == last_half_cycle) {
300
 
        /*
301
 
         * In this case we believe that the entire log should have cycle
302
 
         * number last_half_cycle.  We need to scan backwards from the
303
 
         * end verifying that there are no holes still containing
304
 
         * last_half_cycle - 1.  If we find such a hole, then the start
305
 
         * of that hole will be the new head.  The simple case looks like
306
 
         *        x | x ... | x - 1 | x
307
 
         * Another case that fits this picture would be
308
 
         *        x | x + 1 | x ... | x
309
 
         * In this case the head really is somwhere at the end of the
310
 
         * log, as one of the latest writes at the beginning was incomplete.
311
 
         * One more case is
312
 
         *        x | x + 1 | x ... | x - 1 | x
313
 
         * This is really the combination of the above two cases, and the
314
 
         * head has to end up at the start of the x-1 hole at the end of
315
 
         * the log.
316
 
         * 
317
 
         * In the 256k log case, we will read from the beginning to the
318
 
         * end of the log and search for cycle numbers equal to x-1.  We
319
 
         * don't worry about the x+1 blocks that we encounter, because
320
 
         * we know that they cannot be the head since the log started with
321
 
         * x.
322
 
         */
323
 
        head_blk = log_bbnum;
324
 
        stop_on_cycle = last_half_cycle - 1;
325
 
    } else {
326
 
        /*
327
 
         * In this case we want to find the first block with cycle number
328
 
         * matching last_half_cycle.  We expect the log to be some
329
 
         * variation on
330
 
         *        x + 1 ... | x ...
331
 
         * The first block with cycle number x (last_half_cycle) will be
332
 
         * where the new head belongs.  First we do a binary search for
333
 
         * the first occurrence of last_half_cycle.  The binary search
334
 
         * may not be totally accurate, so then we scan back from there
335
 
         * looking for occurrences of last_half_cycle before us.  If
336
 
         * that backwards scan wraps around the beginning of the log,
337
 
         * then we look for occurrences of last_half_cycle - 1 at the
338
 
         * end of the log.  The cases we're looking for look like
339
 
         *        x + 1 ... | x | x + 1 | x ...
340
 
         *                               ^ binary search stopped here
341
 
         * or
342
 
         *        x + 1 ... | x ... | x - 1 | x
343
 
         *        <---------> less than scan distance
344
 
         */
345
 
        stop_on_cycle = last_half_cycle;
346
 
        if ((error = xlog_find_cycle_start(log, bp, first_blk,
347
 
                                          &head_blk, last_half_cycle)))
348
 
            goto bp_err;
349
 
    }
350
 
 
351
 
    /*
352
 
     * Now validate the answer.  Scan back some number of maximum possible
353
 
     * blocks and make sure each one has the expected cycle number.  The
354
 
     * maximum is determined by the total possible amount of buffering
355
 
     * in the in-core log.  The following number can be made tighter if
356
 
     * we actually look at the block size of the filesystem.
357
 
     */
358
 
    num_scan_bblks = BTOBB(XLOG_MAX_ICLOGS<<XLOG_MAX_RECORD_BSHIFT);
359
 
    if (head_blk >= num_scan_bblks) {
360
 
        /*
361
 
         * We are guaranteed that the entire check can be performed
362
 
         * in one buffer.
363
 
         */
364
 
        start_blk = head_blk - num_scan_bblks;
365
 
        new_blk = xlog_find_verify_cycle(log, start_blk, num_scan_bblks,
366
 
                                         stop_on_cycle);
367
 
        if (new_blk != -1)
368
 
            head_blk = new_blk;
369
 
    } else {                    /* need to read 2 parts of log */
370
 
        /*
371
 
         * We are going to scan backwards in the log in two parts.  First
372
 
         * we scan the physical end of the log.  In this part of the log,
373
 
         * we are looking for blocks with cycle number last_half_cycle - 1.
374
 
         * If we find one, then we know that the log starts there, as we've
375
 
         * found a hole that didn't get written in going around the end
376
 
         * of the physical log.  The simple case for this is
377
 
         *        x + 1 ... | x ... | x - 1 | x
378
 
         *        <---------> less than scan distance
379
 
         * If all of the blocks at the end of the log have cycle number
380
 
         * last_half_cycle, then we check the blocks at the start of the
381
 
         * log looking for occurrences of last_half_cycle.  If we find one,
382
 
         * then our current estimate for the location of the first
383
 
         * occurrence of last_half_cycle is wrong and we move back to the
384
 
         * hole we've found.  This case looks like
385
 
         *        x + 1 ... | x | x + 1 | x ...
386
 
         *                               ^ binary search stopped here    
387
 
         * Another case we need to handle that only occurs in 256k logs is
388
 
         *        x + 1 ... | x ... | x+1 | x ...
389
 
         *                   ^ binary search stops here
390
 
         * In a 256k log, the scan at the end of the log will see the x+1
391
 
         * blocks.  We need to skip past those since that is certainly not
392
 
         * the head of the log.  By searching for last_half_cycle-1 we
393
 
         * accomplish that.
394
 
         */
395
 
        start_blk = log_bbnum - num_scan_bblks + head_blk;
396
 
        ASSERT(head_blk <= INT_MAX && (xfs_daddr_t) num_scan_bblks-head_blk >= 0);
397
 
        new_blk= xlog_find_verify_cycle(log, start_blk,
398
 
                     num_scan_bblks-(int)head_blk, (stop_on_cycle - 1));
399
 
        if (new_blk != -1) {
400
 
            head_blk = new_blk;
401
 
            goto bad_blk;
402
 
        }
403
 
 
404
 
        /*
405
 
         * Scan beginning of log now.  The last part of the physical log
406
 
         * is good.  This scan needs to verify that it doesn't find the
407
 
         * last_half_cycle.
408
 
         */
409
 
        start_blk = 0;
410
 
        ASSERT(head_blk <= INT_MAX);
411
 
        new_blk = xlog_find_verify_cycle(log, start_blk, (int) head_blk,
412
 
                                         stop_on_cycle);
413
 
        if (new_blk != -1)
414
 
            head_blk = new_blk;
415
 
    }
416
 
 
417
 
bad_blk:
418
 
    /*
419
 
     * Now we need to make sure head_blk is not pointing to a block in
420
 
     * the middle of a log record.
421
 
     */
422
 
    num_scan_bblks = BTOBB(XLOG_MAX_RECORD_BSIZE);
423
 
    if (head_blk >= num_scan_bblks) {
424
 
        start_blk = head_blk - num_scan_bblks;  /* don't read head_blk */
425
 
 
426
 
        /* start ptr at last block ptr before head_blk */
427
 
        if ((error = xlog_find_verify_log_record(log,
428
 
                                                 start_blk,
429
 
                                                 &head_blk,
430
 
                                                 0)) == -1) {
431
 
            error = XFS_ERROR(EIO);
432
 
            goto bp_err;
433
 
        } else if (error)
434
 
            goto bp_err;
435
 
    } else {
436
 
        start_blk = 0;
437
 
        ASSERT(head_blk <= INT_MAX);
438
 
        if ((error = xlog_find_verify_log_record(log,
439
 
                                                 start_blk,
440
 
                                                 &head_blk,
441
 
                                                 0)) == -1) {
442
 
            /* We hit the beginning of the log during our search */
443
 
            start_blk = log_bbnum - num_scan_bblks + head_blk;
444
 
            new_blk = log_bbnum;
445
 
            ASSERT(start_blk <= INT_MAX && (xfs_daddr_t) log_bbnum-start_blk >= 0);
446
 
            ASSERT(head_blk <= INT_MAX);
447
 
            if ((error = xlog_find_verify_log_record(log,
448
 
                                                     start_blk,
449
 
                                                     &new_blk,
450
 
                                                     (int)head_blk)) == -1) {
451
 
                error = XFS_ERROR(EIO);
452
 
                goto bp_err;
453
 
            } else if (error)
454
 
                goto bp_err;
455
 
            if (new_blk != log_bbnum)
456
 
                head_blk = new_blk;
457
 
        } else if (error)
458
 
            goto bp_err;
459
 
    }
460
 
 
461
 
    xlog_put_bp(bp);
462
 
    if (head_blk == log_bbnum)
463
 
            *return_head_blk = 0;
464
 
    else
465
 
            *return_head_blk = head_blk;
466
 
    /*
467
 
     * When returning here, we have a good block number.  Bad block
468
 
     * means that during a previous crash, we didn't have a clean break
469
 
     * from cycle number N to cycle number N-1.  In this case, we need
470
 
     * to find the first block with cycle number N-1.
471
 
     */
472
 
    return 0;
473
 
 
474
 
bp_err:
 
504
 
 
505
 bp_err:
475
506
        xlog_put_bp(bp);
476
507
 
477
 
        if (error)
478
 
            xlog_warn("XFS: failed to find log head");
479
 
            
 
508
        if (error)
 
509
            xlog_warn("XFS: failed to find log head");
480
510
        return error;
481
 
}       /* xlog_find_head */
 
511
}
482
512
 
483
513
/*
484
514
 * Find the sync block number or the tail of the log.
497
527
 * available.
498
528
 */
499
529
int
500
 
xlog_find_tail(xlog_t  *log,
501
 
               xfs_daddr_t *head_blk,
502
 
               xfs_daddr_t *tail_blk,
503
 
               int readonly)
 
530
xlog_find_tail(
 
531
        xlog_t                  *log,
 
532
        xfs_daddr_t             *head_blk,
 
533
        xfs_daddr_t             *tail_blk,
 
534
        int                     readonly)
504
535
{
505
536
        xlog_rec_header_t       *rhead;
506
537
        xlog_op_header_t        *op_head;
 
538
        xfs_caddr_t             offset = NULL;
507
539
        xfs_buf_t               *bp;
508
540
        int                     error, i, found;
509
541
        xfs_daddr_t             umount_data_blk;
510
542
        xfs_daddr_t             after_umount_blk;
511
543
        xfs_lsn_t               tail_lsn;
512
 
        
513
 
        found = error = 0;
 
544
        int                     hblks;
 
545
 
 
546
        found = 0;
514
547
 
515
548
        /*
516
 
         * Find previous log record 
 
549
         * Find previous log record
517
550
         */
518
551
        if ((error = xlog_find_head(log, head_blk)))
519
552
                return error;
520
553
 
521
 
        bp = xlog_get_bp(1,log->l_mp);
 
554
        bp = xlog_get_bp(log, 1);
522
555
        if (!bp)
523
 
                return -ENOMEM;
 
556
                return ENOMEM;
524
557
        if (*head_blk == 0) {                           /* special case */
525
558
                if ((error = xlog_bread(log, 0, 1, bp)))
526
559
                        goto bread_err;
527
 
                if (GET_CYCLE(XFS_BUF_PTR(bp), ARCH_CONVERT) == 0) {
 
560
                offset = xlog_align(log, 0, 1, bp);
 
561
                if (GET_CYCLE(offset, ARCH_CONVERT) == 0) {
528
562
                        *tail_blk = 0;
529
563
                        /* leave all other log inited values alone */
530
564
                        goto exit;
535
569
         * Search backwards looking for log record header block
536
570
         */
537
571
        ASSERT(*head_blk < INT_MAX);
538
 
        for (i=(int)(*head_blk)-1; i>=0; i--) {
 
572
        for (i = (int)(*head_blk) - 1; i >= 0; i--) {
539
573
                if ((error = xlog_bread(log, i, 1, bp)))
540
574
                        goto bread_err;
541
 
                if (INT_GET(*(uint *)(XFS_BUF_PTR(bp)), ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM) {
 
575
                offset = xlog_align(log, i, 1, bp);
 
576
                if (XLOG_HEADER_MAGIC_NUM ==
 
577
                    INT_GET(*(uint *)offset, ARCH_CONVERT)) {
542
578
                        found = 1;
543
579
                        break;
544
580
                }
550
586
         * the previous code.
551
587
         */
552
588
        if (!found) {
553
 
                for (i=log->l_logBBsize-1; i>=(int)(*head_blk); i--) {
 
589
                for (i = log->l_logBBsize - 1; i >= (int)(*head_blk); i--) {
554
590
                        if ((error = xlog_bread(log, i, 1, bp)))
555
591
                                goto bread_err;
556
 
                        if (INT_GET(*(uint*)(XFS_BUF_PTR(bp)), ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM) {
 
592
                        offset = xlog_align(log, i, 1, bp);
 
593
                        if (XLOG_HEADER_MAGIC_NUM ==
 
594
                            INT_GET(*(uint*)offset, ARCH_CONVERT)) {
557
595
                                found = 2;
558
596
                                break;
559
597
                        }
566
604
        }
567
605
 
568
606
        /* find blk_no of tail of log */
569
 
        rhead = (xlog_rec_header_t *)XFS_BUF_PTR(bp);
 
607
        rhead = (xlog_rec_header_t *)offset;
570
608
        *tail_blk = BLOCK_LSN(rhead->h_tail_lsn, ARCH_CONVERT);
571
609
 
572
610
        /*
602
640
         * unmount record if there is one, so we pass the lsn of the
603
641
         * unmount record rather than the block after it.
604
642
         */
605
 
        after_umount_blk = (i + 2) % log->l_logBBsize;
 
643
        if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
 
644
                int     h_size = INT_GET(rhead->h_size, ARCH_CONVERT);
 
645
                int     h_version = INT_GET(rhead->h_version, ARCH_CONVERT);
 
646
 
 
647
                if ((h_version & XLOG_VERSION_2) &&
 
648
                    (h_size > XLOG_HEADER_CYCLE_SIZE)) {
 
649
                        hblks = h_size / XLOG_HEADER_CYCLE_SIZE;
 
650
                        if (h_size % XLOG_HEADER_CYCLE_SIZE)
 
651
                                hblks++;
 
652
                } else {
 
653
                        hblks = 1;
 
654
                }
 
655
        } else {
 
656
                hblks = 1;
 
657
        }
 
658
        after_umount_blk = (i + hblks + (int)
 
659
                BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT))) % log->l_logBBsize;
606
660
        tail_lsn = log->l_tail_lsn;
607
 
        if (*head_blk == after_umount_blk && INT_GET(rhead->h_num_logops, ARCH_CONVERT) == 1) {
608
 
                umount_data_blk = (i + 1) % log->l_logBBsize;
 
661
        if (*head_blk == after_umount_blk &&
 
662
            INT_GET(rhead->h_num_logops, ARCH_CONVERT) == 1) {
 
663
                umount_data_blk = (i + hblks) % log->l_logBBsize;
609
664
                if ((error = xlog_bread(log, umount_data_blk, 1, bp))) {
610
665
                        goto bread_err;
611
666
                }
612
 
                op_head = (xlog_op_header_t *)XFS_BUF_PTR(bp);
 
667
                offset = xlog_align(log, umount_data_blk, 1, bp);
 
668
                op_head = (xlog_op_header_t *)offset;
613
669
                if (op_head->oh_flags & XLOG_UNMOUNT_TRANS) {
614
670
                        /*
615
671
                         * Set tail and last sync so that newly written
624
680
                }
625
681
        }
626
682
 
627
 
#ifdef __KERNEL__
628
683
        /*
629
684
         * Make sure that there are no blocks in front of the head
630
685
         * with the same cycle number as the head.  This can happen
635
690
         * overwrite the unmount record after a clean unmount.
636
691
         *
637
692
         * Do this only if we are going to recover the filesystem
 
693
         *
 
694
         * NOTE: This used to say "if (!readonly)"
 
695
         * However on Linux, we can & do recover a read-only filesystem.
 
696
         * We only skip recovery if NORECOVERY is specified on mount,
 
697
         * in which case we would not be here.
 
698
         *
 
699
         * But... if the -device- itself is readonly, just skip this.
 
700
         * We can't recover this device anyway, so it won't matter.
638
701
         */
639
 
        if (!readonly)
 
702
        if (!xfs_readonly_buftarg(log->l_mp->m_logdev_targp)) {
640
703
                error = xlog_clear_stale_blocks(log, tail_lsn);
641
 
#endif
 
704
        }
642
705
 
643
706
bread_err:
644
707
exit:
645
708
        xlog_put_bp(bp);
646
709
 
647
 
        if (error) 
648
 
                xlog_warn("XFS: failed to locate log tail");
649
 
 
 
710
        if (error)
 
711
                xlog_warn("XFS: failed to locate log tail");
650
712
        return error;
651
 
}       /* xlog_find_tail */
652
 
 
 
713
}
653
714
 
654
715
/*
655
716
 * Is the log zeroed at all?
668
729
 *      >0 => error has occurred
669
730
 */
670
731
int
671
 
xlog_find_zeroed(struct log     *log,
672
 
                 xfs_daddr_t    *blk_no)
 
732
xlog_find_zeroed(
 
733
        xlog_t          *log,
 
734
        xfs_daddr_t     *blk_no)
673
735
{
674
736
        xfs_buf_t       *bp;
 
737
        xfs_caddr_t     offset;
675
738
        uint            first_cycle, last_cycle;
676
739
        xfs_daddr_t     new_blk, last_blk, start_blk;
677
740
        xfs_daddr_t     num_scan_bblks;
678
741
        int             error, log_bbnum = log->l_logBBsize;
679
742
 
680
 
        error = 0;
681
743
        /* check totally zeroed log */
682
 
        bp = xlog_get_bp(1,log->l_mp);
 
744
        bp = xlog_get_bp(log, 1);
683
745
        if (!bp)
684
 
                return -ENOMEM;
 
746
                return ENOMEM;
685
747
        if ((error = xlog_bread(log, 0, 1, bp)))
686
748
                goto bp_err;
687
 
        first_cycle = GET_CYCLE(XFS_BUF_PTR(bp), ARCH_CONVERT);
 
749
        offset = xlog_align(log, 0, 1, bp);
 
750
        first_cycle = GET_CYCLE(offset, ARCH_CONVERT);
688
751
        if (first_cycle == 0) {         /* completely zeroed log */
689
752
                *blk_no = 0;
690
753
                xlog_put_bp(bp);
694
757
        /* check partially zeroed log */
695
758
        if ((error = xlog_bread(log, log_bbnum-1, 1, bp)))
696
759
                goto bp_err;
697
 
        last_cycle = GET_CYCLE(XFS_BUF_PTR(bp), ARCH_CONVERT);
 
760
        offset = xlog_align(log, log_bbnum-1, 1, bp);
 
761
        last_cycle = GET_CYCLE(offset, ARCH_CONVERT);
698
762
        if (last_cycle != 0) {          /* log completely written to */
699
763
                xlog_put_bp(bp);
700
764
                return 0;
701
765
        } else if (first_cycle != 1) {
702
766
                /*
703
767
                 * If the cycle of the last block is zero, the cycle of
704
 
                 * the first block must be 1. If it's not, maybe we're
705
 
                 * not looking at a log... Bail out.
 
768
                 * the first block must be 1. If it's not, maybe we're
 
769
                 * not looking at a log... Bail out.
706
770
                 */
707
 
                xlog_warn("XFS: Log inconsistent or not a log (last==0, first!=1)");
 
771
                xlog_warn("XFS: Log inconsistent or not a log (last==0, first!=1)");
708
772
                return XFS_ERROR(EINVAL);
709
773
        }
710
 
        
 
774
 
711
775
        /* we have a partially zeroed log */
712
776
        last_blk = log_bbnum-1;
713
777
        if ((error = xlog_find_cycle_start(log, bp, 0, &last_blk, 0)))
719
783
         * we scan over the defined maximum blocks.  At this point, the maximum
720
784
         * is not chosen to mean anything special.   XXXmiken
721
785
         */
722
 
        num_scan_bblks = BTOBB(XLOG_MAX_ICLOGS<<XLOG_MAX_RECORD_BSHIFT);
 
786
        num_scan_bblks = XLOG_TOTAL_REC_SHIFT(log);
723
787
        ASSERT(num_scan_bblks <= INT_MAX);
724
 
        
 
788
 
725
789
        if (last_blk < num_scan_bblks)
726
790
                num_scan_bblks = last_blk;
727
791
        start_blk = last_blk - num_scan_bblks;
728
 
     
 
792
 
729
793
        /*
730
794
         * We search for any instances of cycle number 0 that occur before
731
795
         * our current estimate of the head.  What we're trying to detect is
732
796
         *        1 ... | 0 | 1 | 0...
733
797
         *                       ^ binary search ends here
734
798
         */
735
 
        new_blk = xlog_find_verify_cycle(log, start_blk,
736
 
                                         (int)num_scan_bblks, 0);
 
799
        if ((error = xlog_find_verify_cycle(log, start_blk,
 
800
                                         (int)num_scan_bblks, 0, &new_blk)))
 
801
                goto bp_err;
737
802
        if (new_blk != -1)
738
803
                last_blk = new_blk;
739
804
 
741
806
         * Potentially backup over partial log record write.  We don't need
742
807
         * to search the end of the log because we know it is zero.
743
808
         */
744
 
        if ((error = xlog_find_verify_log_record(log, start_blk, 
745
 
                                &last_blk, 0)))
 
809
        if ((error = xlog_find_verify_log_record(log, start_blk,
 
810
                                &last_blk, 0)) == -1) {
 
811
            error = XFS_ERROR(EIO);
 
812
            goto bp_err;
 
813
        } else if (error)
746
814
            goto bp_err;
747
815
 
748
816
        *blk_no = last_blk;
751
819
        if (error)
752
820
                return error;
753
821
        return -1;
754
 
}       /* xlog_find_zeroed */
 
822
}
755
823
 
756
 
/* stuff for transactional view */
757
824
STATIC void
758
 
xlog_unpack_data(xlog_rec_header_t *rhead,
759
 
                 xfs_caddr_t       dp,
760
 
                 xlog_t            *log)
 
825
xlog_unpack_data(
 
826
        xlog_rec_header_t       *rhead,
 
827
        xfs_caddr_t             dp,
 
828
        xlog_t                  *log)
761
829
{
762
 
        int i;
763
 
#if defined(DEBUG) && defined(XFS_LOUD_RECOVERY)
764
 
        uint *up = (uint *)dp;
765
 
        uint chksum = 0;
766
 
#endif
 
830
        int                     i, j, k;
 
831
        xlog_in_core_2_t        *xhdr;
767
832
 
768
 
        for (i=0; i<BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)); i++) {
769
 
                INT_SET(*(uint *)dp, ARCH_CONVERT, INT_GET(*(uint *)&rhead->h_cycle_data[i], ARCH_CONVERT));
 
833
        for (i = 0; i < BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)) &&
 
834
                  i < (XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++) {
 
835
                *(uint *)dp = *(uint *)&rhead->h_cycle_data[i];
770
836
                dp += BBSIZE;
771
837
        }
772
 
#if defined(DEBUG) && defined(XFS_LOUD_RECOVERY)
773
 
        /* divide length by 4 to get # words */
774
 
        for (i=0; i < INT_GET(rhead->h_len, ARCH_CONVERT) >> 2; i++) {
775
 
                chksum ^= INT_GET(*up, ARCH_CONVERT);
776
 
                up++;
 
838
 
 
839
        if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
 
840
                xhdr = (xlog_in_core_2_t *)rhead;
 
841
                for ( ; i < BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)); i++) {
 
842
                        j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
 
843
                        k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
 
844
                        *(uint *)dp = xhdr[j].hic_xheader.xh_cycle_data[k];
 
845
                        dp += BBSIZE;
 
846
                }
777
847
        }
778
 
        if (chksum != INT_GET(rhead->h_chksum, ARCH_CONVERT)) {
779
 
            if (!INT_ISZERO(rhead->h_chksum, ARCH_CONVERT) ||
780
 
                ((log->l_flags & XLOG_CHKSUM_MISMATCH) == 0)) {
781
 
                    cmn_err(CE_DEBUG,
782
 
                        "XFS: LogR chksum mismatch: was (0x%x) is (0x%x)",
783
 
                            INT_GET(rhead->h_chksum, ARCH_CONVERT), chksum);
784
 
                    cmn_err(CE_DEBUG,
785
 
"XFS: Disregard message if filesystem was created with non-DEBUG kernel");
786
 
                    log->l_flags |= XLOG_CHKSUM_MISMATCH;
787
 
            }
788
 
        }
789
 
#endif /* DEBUG && XFS_LOUD_RECOVERY */
790
 
}       /* xlog_unpack_data */
791
848
 
 
849
        xlog_unpack_data_checksum(rhead, dp, log);
 
850
}
792
851
 
793
852
STATIC xlog_recover_t *
794
 
xlog_recover_find_tid(xlog_recover_t *q,
795
 
                      xlog_tid_t     tid)
 
853
xlog_recover_find_tid(
 
854
        xlog_recover_t          *q,
 
855
        xlog_tid_t              tid)
796
856
{
797
 
        xlog_recover_t *p = q;
 
857
        xlog_recover_t          *p = q;
798
858
 
799
859
        while (p != NULL) {
800
860
                if (p->r_log_tid == tid)
802
862
                p = p->r_next;
803
863
        }
804
864
        return p;
805
 
}       /* xlog_recover_find_tid */
 
865
}
806
866
 
807
867
STATIC void
808
 
xlog_recover_put_hashq(xlog_recover_t **q,
809
 
                       xlog_recover_t *trans)
 
868
xlog_recover_put_hashq(
 
869
        xlog_recover_t  **q,
 
870
        xlog_recover_t  *trans)
810
871
{
811
872
        trans->r_next = *q;
812
873
        *q = trans;
813
 
}       /* xlog_recover_put_hashq */
 
874
}
814
875
 
815
876
STATIC void
816
 
xlog_recover_new_tid(xlog_recover_t     **q,
817
 
                     xlog_tid_t         tid,
818
 
                     xfs_lsn_t          lsn)
 
877
xlog_recover_new_tid(
 
878
        xlog_recover_t          **q,
 
879
        xlog_tid_t              tid,
 
880
        xfs_lsn_t               lsn)
819
881
{
820
 
        xlog_recover_t  *trans;
 
882
        xlog_recover_t          *trans;
821
883
 
822
 
        trans = kmem_zalloc(sizeof(xlog_recover_t), 0);
 
884
        trans = kmem_zalloc(sizeof(xlog_recover_t), KM_SLEEP);
823
885
        trans->r_log_tid   = tid;
824
886
        trans->r_lsn       = lsn;
825
887
        xlog_recover_put_hashq(q, trans);
826
 
}       /* xlog_recover_new_tid */
827
 
 
 
888
}
828
889
 
829
890
STATIC int
830
 
xlog_recover_unlink_tid(xlog_recover_t  **q,
831
 
                        xlog_recover_t  *trans)
 
891
xlog_recover_unlink_tid(
 
892
        xlog_recover_t          **q,
 
893
        xlog_recover_t          *trans)
832
894
{
833
 
        xlog_recover_t  *tp;
834
 
        int             found = 0;
 
895
        xlog_recover_t          *tp;
 
896
        int                     found = 0;
835
897
 
836
898
        ASSERT(trans != 0);
837
899
        if (trans == *q) {
854
916
                tp->r_next = tp->r_next->r_next;
855
917
        }
856
918
        return 0;
857
 
}       /* xlog_recover_unlink_tid */
 
919
}
858
920
 
859
921
/*
860
922
 * Free up any resources allocated by the transaction
862
924
 * Remember that EFIs, EFDs, and IUNLINKs are handled later.
863
925
 */
864
926
STATIC void
865
 
xlog_recover_free_trans(xlog_recover_t      *trans)
 
927
xlog_recover_free_trans(
 
928
        xlog_recover_t          *trans)
866
929
{
867
 
        xlog_recover_item_t *first_item, *item, *free_item;
868
 
        int i;
 
930
        xlog_recover_item_t     *first_item, *item, *free_item;
 
931
        int                     i;
869
932
 
870
933
        item = first_item = trans->r_itemq;
871
934
        do {
883
946
        } while (first_item != item);
884
947
        /* Free the transaction recover structure */
885
948
        kmem_free(trans, sizeof(xlog_recover_t));
886
 
}       /* xlog_recover_free_trans */
887
 
 
 
949
}
888
950
 
889
951
STATIC int
890
 
xlog_recover_commit_trans(xlog_t         *log,
891
 
                          xlog_recover_t **q,
892
 
                          xlog_recover_t *trans,
893
 
                          int            pass)
 
952
xlog_recover_commit_trans(
 
953
        xlog_t                  *log,
 
954
        xlog_recover_t          **q,
 
955
        xlog_recover_t          *trans,
 
956
        int                     pass)
894
957
{
895
 
        int error;
 
958
        int                     error;
896
959
 
897
960
        if ((error = xlog_recover_unlink_tid(q, trans)))
898
961
                return error;
900
963
                return error;
901
964
        xlog_recover_free_trans(trans);                 /* no error */
902
965
        return 0;
903
 
}       /* xlog_recover_commit_trans */
 
966
}
904
967
 
905
968
STATIC void
906
 
xlog_recover_insert_item_backq(xlog_recover_item_t **q,
907
 
                               xlog_recover_item_t *item)
 
969
xlog_recover_insert_item_backq(
 
970
        xlog_recover_item_t     **q,
 
971
        xlog_recover_item_t     *item)
908
972
{
909
973
        if (*q == 0) {
910
974
                item->ri_prev = item->ri_next = item;
915
979
                (*q)->ri_prev           = item;
916
980
                item->ri_prev->ri_next  = item;
917
981
        }
918
 
}       /* xlog_recover_insert_item_backq */
 
982
}
919
983
 
920
984
STATIC void
921
 
xlog_recover_add_item(xlog_recover_item_t **itemq)
 
985
xlog_recover_add_item(
 
986
        xlog_recover_item_t     **itemq)
922
987
{
923
 
        xlog_recover_item_t *item;
 
988
        xlog_recover_item_t     *item;
924
989
 
925
 
        item = kmem_zalloc(sizeof(xlog_recover_item_t), 0);
 
990
        item = kmem_zalloc(sizeof(xlog_recover_item_t), KM_SLEEP);
926
991
        xlog_recover_insert_item_backq(itemq, item);
927
 
}       /* xlog_recover_add_item */
928
 
 
929
 
/* The next region to add is the start of a new region.  It could be
 
992
}
 
993
 
 
994
STATIC int
 
995
xlog_recover_add_to_cont_trans(
 
996
        xlog_recover_t          *trans,
 
997
        xfs_caddr_t             dp,
 
998
        int                     len)
 
999
{
 
1000
        xlog_recover_item_t     *item;
 
1001
        xfs_caddr_t             ptr, old_ptr;
 
1002
        int                     old_len;
 
1003
 
 
1004
        item = trans->r_itemq;
 
1005
        if (item == 0) {
 
1006
                /* finish copying rest of trans header */
 
1007
                xlog_recover_add_item(&trans->r_itemq);
 
1008
                ptr = (xfs_caddr_t) &trans->r_theader +
 
1009
                                sizeof(xfs_trans_header_t) - len;
 
1010
                memcpy(ptr, dp, len); /* d, s, l */
 
1011
                return 0;
 
1012
        }
 
1013
        item = item->ri_prev;
 
1014
 
 
1015
        old_ptr = item->ri_buf[item->ri_cnt-1].i_addr;
 
1016
        old_len = item->ri_buf[item->ri_cnt-1].i_len;
 
1017
 
 
1018
        ptr = kmem_realloc(old_ptr, len+old_len, old_len, 0);
 
1019
        memcpy(&ptr[old_len], dp, len); /* d, s, l */
 
1020
        item->ri_buf[item->ri_cnt-1].i_len += len;
 
1021
        item->ri_buf[item->ri_cnt-1].i_addr = ptr;
 
1022
        return 0;
 
1023
}
 
1024
 
 
1025
/*
 
1026
 * The next region to add is the start of a new region.  It could be
930
1027
 * a whole region or it could be the first part of a new region.  Because
931
1028
 * of this, the assumption here is that the type and size fields of all
932
1029
 * format structures fit into the first 32 bits of the structure.
939
1036
 * will appear in the current log item.
940
1037
 */
941
1038
STATIC int
942
 
xlog_recover_add_to_trans(xlog_recover_t        *trans,
943
 
                          xfs_caddr_t           dp,
944
 
                          int                   len)
 
1039
xlog_recover_add_to_trans(
 
1040
        xlog_recover_t          *trans,
 
1041
        xfs_caddr_t             dp,
 
1042
        int                     len)
945
1043
{
946
 
        xfs_inode_log_format_t   *in_f;                 /* any will do */
947
 
        xlog_recover_item_t      *item;
948
 
        xfs_caddr_t              ptr;
 
1044
        xfs_inode_log_format_t  *in_f;                  /* any will do */
 
1045
        xlog_recover_item_t     *item;
 
1046
        xfs_caddr_t             ptr;
949
1047
 
950
1048
        if (!len)
951
1049
                return 0;
952
 
        ptr = kmem_zalloc(len, 0);
953
 
        bcopy(dp, ptr, len);
954
 
        
955
 
        in_f = (xfs_inode_log_format_t *)ptr;
956
1050
        item = trans->r_itemq;
957
1051
        if (item == 0) {
958
1052
                ASSERT(*(uint *)dp == XFS_TRANS_HEADER_MAGIC);
959
1053
                if (len == sizeof(xfs_trans_header_t))
960
1054
                        xlog_recover_add_item(&trans->r_itemq);
961
 
                bcopy(dp, &trans->r_theader, len); /* s, d, l */
 
1055
                memcpy(&trans->r_theader, dp, len); /* d, s, l */
962
1056
                return 0;
963
1057
        }
 
1058
 
 
1059
        ptr = kmem_alloc(len, KM_SLEEP);
 
1060
        memcpy(ptr, dp, len);
 
1061
        in_f = (xfs_inode_log_format_t *)ptr;
 
1062
 
964
1063
        if (item->ri_prev->ri_total != 0 &&
965
1064
             item->ri_prev->ri_total == item->ri_prev->ri_cnt) {
966
1065
                xlog_recover_add_item(&trans->r_itemq);
972
1071
                item->ri_total  = in_f->ilf_size;
973
1072
                ASSERT(item->ri_total <= XLOG_MAX_REGIONS_IN_ITEM);
974
1073
                item->ri_buf = kmem_zalloc((item->ri_total *
975
 
                                            sizeof(xfs_log_iovec_t)), 0);
 
1074
                                            sizeof(xfs_log_iovec_t)), KM_SLEEP);
976
1075
        }
977
1076
        ASSERT(item->ri_total > item->ri_cnt);
978
1077
        /* Description region is ri_buf[0] */
980
1079
        item->ri_buf[item->ri_cnt].i_len  = len;
981
1080
        item->ri_cnt++;
982
1081
        return 0;
983
 
}       /* xlog_recover_add_to_trans */
984
 
 
985
 
STATIC int
986
 
xlog_recover_add_to_cont_trans(xlog_recover_t   *trans,
987
 
                               xfs_caddr_t              dp,
988
 
                               int              len)
989
 
{
990
 
        xlog_recover_item_t     *item;
991
 
        xfs_caddr_t                     ptr, old_ptr;
992
 
        int                     old_len;
993
 
        
994
 
        item = trans->r_itemq;
995
 
        if (item == 0) {
996
 
                /* finish copying rest of trans header */
997
 
                xlog_recover_add_item(&trans->r_itemq);
998
 
                ptr = (xfs_caddr_t)&trans->r_theader+sizeof(xfs_trans_header_t)-len;
999
 
                bcopy(dp, ptr, len); /* s, d, l */
1000
 
                return 0;
1001
 
        }
1002
 
        item = item->ri_prev;
1003
 
 
1004
 
        old_ptr = item->ri_buf[item->ri_cnt-1].i_addr;
1005
 
        old_len = item->ri_buf[item->ri_cnt-1].i_len;
1006
 
 
1007
 
        ptr = kmem_realloc(old_ptr, len+old_len, old_len, 0); 
1008
 
        bcopy(dp , &ptr[old_len], len); /* s, d, l */
1009
 
        item->ri_buf[item->ri_cnt-1].i_len += len;
1010
 
        item->ri_buf[item->ri_cnt-1].i_addr = ptr;
1011
 
        return 0;
1012
 
}       /* xlog_recover_add_to_cont_trans */
1013
 
 
1014
 
STATIC int
1015
 
xlog_recover_unmount_trans(xlog_recover_t *trans)
 
1082
}
 
1083
 
 
1084
STATIC int
 
1085
xlog_recover_unmount_trans(
 
1086
        xlog_recover_t  *trans)
1016
1087
{
1017
1088
        /* Do nothing now */
1018
1089
        xlog_warn("XFS: xlog_recover_unmount_trans: Unmount LR");
1019
 
        return( 0 );
1020
 
}       /* xlog_recover_unmount_trans */
1021
 
 
1022
 
 
1023
 
STATIC int
1024
 
xlog_recover_process_data(xlog_t            *log,
1025
 
                          xlog_recover_t    *rhash[],
1026
 
                          xlog_rec_header_t *rhead,
1027
 
                          xfs_caddr_t       dp,
1028
 
                          int               pass)
1029
 
{
1030
 
    xfs_caddr_t         lp         = dp+INT_GET(rhead->h_len, ARCH_CONVERT);
1031
 
    int                 num_logops = INT_GET(rhead->h_num_logops, ARCH_CONVERT);
1032
 
    xlog_op_header_t    *ohead;
1033
 
    xlog_recover_t      *trans;
1034
 
    xlog_tid_t          tid;
1035
 
    int                 error;
1036
 
    unsigned long       hash;
1037
 
    uint                flags;
1038
 
    
1039
 
    /* check the log format matches our own - else we can't recover */
1040
 
    if (xlog_header_check_recover(log->l_mp, rhead))
1041
 
            return (XFS_ERROR(EIO));
1042
 
    
1043
 
    while (dp < lp) {
1044
 
        ASSERT(dp + sizeof(xlog_op_header_t) <= lp);
1045
 
        ohead = (xlog_op_header_t *)dp;
1046
 
        dp += sizeof(xlog_op_header_t);
1047
 
        if (ohead->oh_clientid != XFS_TRANSACTION &&
1048
 
            ohead->oh_clientid != XFS_LOG) {
1049
 
            xlog_warn("XFS: xlog_recover_process_data: bad clientid");
1050
 
            ASSERT(0);
1051
 
            return (XFS_ERROR(EIO));
1052
 
        }
1053
 
        tid = INT_GET(ohead->oh_tid, ARCH_CONVERT);
1054
 
        hash = XLOG_RHASH(tid);
1055
 
        trans = xlog_recover_find_tid(rhash[hash], tid);
1056
 
        if (trans == NULL) {                       /* not found; add new tid */
1057
 
            if (ohead->oh_flags & XLOG_START_TRANS)
1058
 
                xlog_recover_new_tid(&rhash[hash], tid, INT_GET(rhead->h_lsn, ARCH_CONVERT));
1059
 
        } else {
1060
 
            ASSERT(dp+INT_GET(ohead->oh_len, ARCH_CONVERT) <= lp);
1061
 
            flags = ohead->oh_flags & ~XLOG_END_TRANS;
1062
 
            if (flags & XLOG_WAS_CONT_TRANS)
1063
 
                flags &= ~XLOG_CONTINUE_TRANS;
1064
 
            switch (flags) {
1065
 
                case XLOG_COMMIT_TRANS: {
1066
 
                    error = xlog_recover_commit_trans(log, &rhash[hash],
1067
 
                                                      trans, pass);
1068
 
                    break;
1069
 
                }
1070
 
                case XLOG_UNMOUNT_TRANS: {
1071
 
                    error = xlog_recover_unmount_trans(trans);
1072
 
                    break;
1073
 
                }
1074
 
                case XLOG_WAS_CONT_TRANS: {
1075
 
                    error = xlog_recover_add_to_cont_trans(trans, dp,
1076
 
                                  INT_GET(ohead->oh_len, ARCH_CONVERT));
1077
 
                    break;
1078
 
                }
1079
 
                case XLOG_START_TRANS : {
1080
 
                    xlog_warn("XFS: xlog_recover_process_data: bad transaction");
1081
 
                    ASSERT(0);
1082
 
                    error = XFS_ERROR(EIO);
1083
 
                    break;
1084
 
                }
1085
 
                case 0:
1086
 
                case XLOG_CONTINUE_TRANS: {
1087
 
                    error = xlog_recover_add_to_trans(trans, dp,
1088
 
                                   INT_GET(ohead->oh_len, ARCH_CONVERT));
1089
 
                    break;
1090
 
                }
1091
 
                default: {
1092
 
                    xlog_warn("XFS: xlog_recover_process_data: bad flag");
1093
 
                    ASSERT(0);
1094
 
                    error = XFS_ERROR(EIO);
1095
 
                    break;
1096
 
                }
1097
 
            } /* switch */
1098
 
            if (error)
1099
 
                return error;
1100
 
        } /* if */
1101
 
        dp += INT_GET(ohead->oh_len, ARCH_CONVERT);
1102
 
        num_logops--;
1103
 
    }
1104
 
    return( 0 );
1105
 
}       /* xlog_recover_process_data */
 
1090
        return 0;
 
1091
}
 
1092
 
 
1093
/*
 
1094
 * There are two valid states of the r_state field.  0 indicates that the
 
1095
 * transaction structure is in a normal state.  We have either seen the
 
1096
 * start of the transaction or the last operation we added was not a partial
 
1097
 * operation.  If the last operation we added to the transaction was a
 
1098
 * partial operation, we need to mark r_state with XLOG_WAS_CONT_TRANS.
 
1099
 *
 
1100
 * NOTE: skip LRs with 0 data length.
 
1101
 */
 
1102
STATIC int
 
1103
xlog_recover_process_data(
 
1104
        xlog_t                  *log,
 
1105
        xlog_recover_t          *rhash[],
 
1106
        xlog_rec_header_t       *rhead,
 
1107
        xfs_caddr_t             dp,
 
1108
        int                     pass)
 
1109
{
 
1110
        xfs_caddr_t             lp;
 
1111
        int                     num_logops;
 
1112
        xlog_op_header_t        *ohead;
 
1113
        xlog_recover_t          *trans;
 
1114
        xlog_tid_t              tid;
 
1115
        int                     error;
 
1116
        unsigned long           hash;
 
1117
        uint                    flags;
 
1118
 
 
1119
        lp = dp + INT_GET(rhead->h_len, ARCH_CONVERT);
 
1120
        num_logops = INT_GET(rhead->h_num_logops, ARCH_CONVERT);
 
1121
 
 
1122
        /* check the log format matches our own - else we can't recover */
 
1123
        if (xlog_header_check_recover(log->l_mp, rhead))
 
1124
                return (XFS_ERROR(EIO));
 
1125
 
 
1126
        while ((dp < lp) && num_logops) {
 
1127
                ASSERT(dp + sizeof(xlog_op_header_t) <= lp);
 
1128
                ohead = (xlog_op_header_t *)dp;
 
1129
                dp += sizeof(xlog_op_header_t);
 
1130
                if (ohead->oh_clientid != XFS_TRANSACTION &&
 
1131
                    ohead->oh_clientid != XFS_LOG) {
 
1132
                        xlog_warn(
 
1133
                "XFS: xlog_recover_process_data: bad clientid");
 
1134
                        ASSERT(0);
 
1135
                        return (XFS_ERROR(EIO));
 
1136
                }
 
1137
                tid = INT_GET(ohead->oh_tid, ARCH_CONVERT);
 
1138
                hash = XLOG_RHASH(tid);
 
1139
                trans = xlog_recover_find_tid(rhash[hash], tid);
 
1140
                if (trans == NULL) {               /* not found; add new tid */
 
1141
                        if (ohead->oh_flags & XLOG_START_TRANS)
 
1142
                                xlog_recover_new_tid(&rhash[hash], tid,
 
1143
                                        INT_GET(rhead->h_lsn, ARCH_CONVERT));
 
1144
                } else {
 
1145
                        ASSERT(dp+INT_GET(ohead->oh_len, ARCH_CONVERT) <= lp);
 
1146
                        flags = ohead->oh_flags & ~XLOG_END_TRANS;
 
1147
                        if (flags & XLOG_WAS_CONT_TRANS)
 
1148
                                flags &= ~XLOG_CONTINUE_TRANS;
 
1149
                        switch (flags) {
 
1150
                        case XLOG_COMMIT_TRANS:
 
1151
                                error = xlog_recover_commit_trans(log,
 
1152
                                                &rhash[hash], trans, pass);
 
1153
                                break;
 
1154
                        case XLOG_UNMOUNT_TRANS:
 
1155
                                error = xlog_recover_unmount_trans(trans);
 
1156
                                break;
 
1157
                        case XLOG_WAS_CONT_TRANS:
 
1158
                                error = xlog_recover_add_to_cont_trans(trans,
 
1159
                                                dp, INT_GET(ohead->oh_len,
 
1160
                                                        ARCH_CONVERT));
 
1161
                                break;
 
1162
                        case XLOG_START_TRANS:
 
1163
                                xlog_warn(
 
1164
                        "XFS: xlog_recover_process_data: bad transaction");
 
1165
                                ASSERT(0);
 
1166
                                error = XFS_ERROR(EIO);
 
1167
                                break;
 
1168
                        case 0:
 
1169
                        case XLOG_CONTINUE_TRANS:
 
1170
                                error = xlog_recover_add_to_trans(trans,
 
1171
                                                dp, INT_GET(ohead->oh_len,
 
1172
                                                        ARCH_CONVERT));
 
1173
                                break;
 
1174
                        default:
 
1175
                                xlog_warn(
 
1176
                        "XFS: xlog_recover_process_data: bad flag");
 
1177
                                ASSERT(0);
 
1178
                                error = XFS_ERROR(EIO);
 
1179
                                break;
 
1180
                        }
 
1181
                        if (error)
 
1182
                                return error;
 
1183
                }
 
1184
                dp += INT_GET(ohead->oh_len, ARCH_CONVERT);
 
1185
                num_logops--;
 
1186
        }
 
1187
        return 0;
 
1188
}
 
1189
 
 
1190
STATIC int
 
1191
xlog_valid_rec_header(
 
1192
        xlog_t                  *log,
 
1193
        xlog_rec_header_t       *rhead,
 
1194
        xfs_daddr_t             blkno)
 
1195
{
 
1196
        int                     hlen;
 
1197
 
 
1198
        if (unlikely(
 
1199
            (INT_GET(rhead->h_magicno, ARCH_CONVERT) !=
 
1200
                        XLOG_HEADER_MAGIC_NUM))) {
 
1201
                XFS_ERROR_REPORT("xlog_valid_rec_header(1)",
 
1202
                                XFS_ERRLEVEL_LOW, log->l_mp);
 
1203
                return XFS_ERROR(EFSCORRUPTED);
 
1204
        }
 
1205
        if (unlikely(
 
1206
            (INT_ISZERO(rhead->h_version, ARCH_CONVERT) ||
 
1207
            (INT_GET(rhead->h_version, ARCH_CONVERT) &
 
1208
                        (~XLOG_VERSION_OKBITS)) != 0))) {
 
1209
                xlog_warn("XFS: %s: unrecognised log version (%d).",
 
1210
                        __FUNCTION__, INT_GET(rhead->h_version, ARCH_CONVERT));
 
1211
                return XFS_ERROR(EIO);
 
1212
        }
 
1213
 
 
1214
        /* LR body must have data or it wouldn't have been written */
 
1215
        hlen = INT_GET(rhead->h_len, ARCH_CONVERT);
 
1216
        if (unlikely( hlen <= 0 || hlen > INT_MAX )) {
 
1217
                XFS_ERROR_REPORT("xlog_valid_rec_header(2)",
 
1218
                                XFS_ERRLEVEL_LOW, log->l_mp);
 
1219
                return XFS_ERROR(EFSCORRUPTED);
 
1220
        }
 
1221
        if (unlikely( blkno > log->l_logBBsize || blkno > INT_MAX )) {
 
1222
                XFS_ERROR_REPORT("xlog_valid_rec_header(3)",
 
1223
                                XFS_ERRLEVEL_LOW, log->l_mp);
 
1224
                return XFS_ERROR(EFSCORRUPTED);
 
1225
        }
 
1226
        return 0;
 
1227
}
1106
1228
 
1107
1229
/*
1108
1230
 * Read the log from tail to head and process the log records found.
1113
1235
 * here.
1114
1236
 */
1115
1237
int
1116
 
xlog_do_recovery_pass(xlog_t    *log,
1117
 
                      xfs_daddr_t       head_blk,
1118
 
                      xfs_daddr_t       tail_blk,
1119
 
                      int       pass)
 
1238
xlog_do_recovery_pass(
 
1239
        xlog_t                  *log,
 
1240
        xfs_daddr_t             head_blk,
 
1241
        xfs_daddr_t             tail_blk,
 
1242
        int                     pass)
1120
1243
{
1121
 
    xlog_rec_header_t   *rhead;
1122
 
    xfs_daddr_t         blk_no;
1123
 
    xfs_caddr_t         bufaddr;
1124
 
    xfs_buf_t           *hbp, *dbp;
1125
 
    int                 error;
1126
 
    int                 bblks, split_bblks;
1127
 
    xlog_recover_t      *rhash[XLOG_RHASH_SIZE];
1128
 
 
1129
 
    error = 0;
1130
 
    hbp = xlog_get_bp(1,log->l_mp);
1131
 
    if (!hbp)
1132
 
        return -ENOMEM;
1133
 
    dbp = xlog_get_bp(BTOBB(XLOG_MAX_RECORD_BSIZE),log->l_mp);
1134
 
    if (!dbp) {
 
1244
        xlog_rec_header_t       *rhead;
 
1245
        xfs_daddr_t             blk_no;
 
1246
        xfs_caddr_t             bufaddr, offset;
 
1247
        xfs_buf_t               *hbp, *dbp;
 
1248
        int                     error = 0, h_size;
 
1249
        int                     bblks, split_bblks;
 
1250
        int                     hblks, split_hblks, wrapped_hblks;
 
1251
        xlog_recover_t          *rhash[XLOG_RHASH_SIZE];
 
1252
 
 
1253
        ASSERT(head_blk != tail_blk);
 
1254
 
 
1255
        /*
 
1256
         * Read the header of the tail block and get the iclog buffer size from
 
1257
         * h_size.  Use this to tell how many sectors make up the log header.
 
1258
         */
 
1259
        if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
 
1260
                /*
 
1261
                 * When using variable length iclogs, read first sector of
 
1262
                 * iclog header and extract the header size from it.  Get a
 
1263
                 * new hbp that is the correct size.
 
1264
                 */
 
1265
                hbp = xlog_get_bp(log, 1);
 
1266
                if (!hbp)
 
1267
                        return ENOMEM;
 
1268
                if ((error = xlog_bread(log, tail_blk, 1, hbp)))
 
1269
                        goto bread_err1;
 
1270
                offset = xlog_align(log, tail_blk, 1, hbp);
 
1271
                rhead = (xlog_rec_header_t *)offset;
 
1272
                error = xlog_valid_rec_header(log, rhead, tail_blk);
 
1273
                if (error)
 
1274
                        goto bread_err1;
 
1275
                h_size = INT_GET(rhead->h_size, ARCH_CONVERT);
 
1276
                if ((INT_GET(rhead->h_version, ARCH_CONVERT)
 
1277
                                & XLOG_VERSION_2) &&
 
1278
                    (h_size > XLOG_HEADER_CYCLE_SIZE)) {
 
1279
                        hblks = h_size / XLOG_HEADER_CYCLE_SIZE;
 
1280
                        if (h_size % XLOG_HEADER_CYCLE_SIZE)
 
1281
                                hblks++;
 
1282
                        xlog_put_bp(hbp);
 
1283
                        hbp = xlog_get_bp(log, hblks);
 
1284
                } else {
 
1285
                        hblks = 1;
 
1286
                }
 
1287
        } else {
 
1288
                ASSERT(log->l_sectbb_log == 0);
 
1289
                hblks = 1;
 
1290
                hbp = xlog_get_bp(log, 1);
 
1291
                h_size = XLOG_BIG_RECORD_BSIZE;
 
1292
        }
 
1293
 
 
1294
        if (!hbp)
 
1295
                return ENOMEM;
 
1296
        dbp = xlog_get_bp(log, BTOBB(h_size));
 
1297
        if (!dbp) {
 
1298
                xlog_put_bp(hbp);
 
1299
                return ENOMEM;
 
1300
        }
 
1301
 
 
1302
        memset(rhash, 0, sizeof(rhash));
 
1303
        if (tail_blk <= head_blk) {
 
1304
                for (blk_no = tail_blk; blk_no < head_blk; ) {
 
1305
                        if ((error = xlog_bread(log, blk_no, hblks, hbp)))
 
1306
                                goto bread_err2;
 
1307
                        offset = xlog_align(log, blk_no, hblks, hbp);
 
1308
                        rhead = (xlog_rec_header_t *)offset;
 
1309
                        error = xlog_valid_rec_header(log, rhead, blk_no);
 
1310
                        if (error)
 
1311
                                goto bread_err2;
 
1312
 
 
1313
                        /* blocks in data section */
 
1314
                        bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
 
1315
                        error = xlog_bread(log, blk_no + hblks, bblks, dbp);
 
1316
                        if (error)
 
1317
                                goto bread_err2;
 
1318
                        offset = xlog_align(log, blk_no + hblks, bblks, dbp);
 
1319
                        xlog_unpack_data(rhead, offset, log);
 
1320
                        if ((error = xlog_recover_process_data(log,
 
1321
                                                rhash, rhead, offset, pass)))
 
1322
                                goto bread_err2;
 
1323
                        blk_no += bblks + hblks;
 
1324
                }
 
1325
        } else {
 
1326
                /*
 
1327
                 * Perform recovery around the end of the physical log.
 
1328
                 * When the head is not on the same cycle number as the tail,
 
1329
                 * we can't do a sequential recovery as above.
 
1330
                 */
 
1331
                blk_no = tail_blk;
 
1332
                while (blk_no < log->l_logBBsize) {
 
1333
                        /*
 
1334
                         * Check for header wrapping around physical end-of-log
 
1335
                         */
 
1336
                        offset = NULL;
 
1337
                        split_hblks = 0;
 
1338
                        wrapped_hblks = 0;
 
1339
                        if (blk_no + hblks <= log->l_logBBsize) {
 
1340
                                /* Read header in one read */
 
1341
                                error = xlog_bread(log, blk_no, hblks, hbp);
 
1342
                                if (error)
 
1343
                                        goto bread_err2;
 
1344
                                offset = xlog_align(log, blk_no, hblks, hbp);
 
1345
                        } else {
 
1346
                                /* This LR is split across physical log end */
 
1347
                                if (blk_no != log->l_logBBsize) {
 
1348
                                        /* some data before physical log end */
 
1349
                                        ASSERT(blk_no <= INT_MAX);
 
1350
                                        split_hblks = log->l_logBBsize - (int)blk_no;
 
1351
                                        ASSERT(split_hblks > 0);
 
1352
                                        if ((error = xlog_bread(log, blk_no,
 
1353
                                                        split_hblks, hbp)))
 
1354
                                                goto bread_err2;
 
1355
                                        offset = xlog_align(log, blk_no,
 
1356
                                                        split_hblks, hbp);
 
1357
                                }
 
1358
                                /*
 
1359
                                 * Note: this black magic still works with
 
1360
                                 * large sector sizes (non-512) only because:
 
1361
                                 * - we increased the buffer size originally
 
1362
                                 *   by 1 sector giving us enough extra space
 
1363
                                 *   for the second read;
 
1364
                                 * - the log start is guaranteed to be sector
 
1365
                                 *   aligned;
 
1366
                                 * - we read the log end (LR header start)
 
1367
                                 *   _first_, then the log start (LR header end)
 
1368
                                 *   - order is important.
 
1369
                                 */
 
1370
                                bufaddr = XFS_BUF_PTR(hbp);
 
1371
                                XFS_BUF_SET_PTR(hbp,
 
1372
                                                bufaddr + BBTOB(split_hblks),
 
1373
                                                BBTOB(hblks - split_hblks));
 
1374
                                wrapped_hblks = hblks - split_hblks;
 
1375
                                error = xlog_bread(log, 0, wrapped_hblks, hbp);
 
1376
                                if (error)
 
1377
                                        goto bread_err2;
 
1378
                                XFS_BUF_SET_PTR(hbp, bufaddr, BBTOB(hblks));
 
1379
                                if (!offset)
 
1380
                                        offset = xlog_align(log, 0,
 
1381
                                                        wrapped_hblks, hbp);
 
1382
                        }
 
1383
                        rhead = (xlog_rec_header_t *)offset;
 
1384
                        error = xlog_valid_rec_header(log, rhead,
 
1385
                                                split_hblks ? blk_no : 0);
 
1386
                        if (error)
 
1387
                                goto bread_err2;
 
1388
 
 
1389
                        bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
 
1390
                        blk_no += hblks;
 
1391
 
 
1392
                        /* Read in data for log record */
 
1393
                        if (blk_no + bblks <= log->l_logBBsize) {
 
1394
                                error = xlog_bread(log, blk_no, bblks, dbp);
 
1395
                                if (error)
 
1396
                                        goto bread_err2;
 
1397
                                offset = xlog_align(log, blk_no, bblks, dbp);
 
1398
                        } else {
 
1399
                                /* This log record is split across the
 
1400
                                 * physical end of log */
 
1401
                                offset = NULL;
 
1402
                                split_bblks = 0;
 
1403
                                if (blk_no != log->l_logBBsize) {
 
1404
                                        /* some data is before the physical
 
1405
                                         * end of log */
 
1406
                                        ASSERT(!wrapped_hblks);
 
1407
                                        ASSERT(blk_no <= INT_MAX);
 
1408
                                        split_bblks =
 
1409
                                                log->l_logBBsize - (int)blk_no;
 
1410
                                        ASSERT(split_bblks > 0);
 
1411
                                        if ((error = xlog_bread(log, blk_no,
 
1412
                                                        split_bblks, dbp)))
 
1413
                                                goto bread_err2;
 
1414
                                        offset = xlog_align(log, blk_no,
 
1415
                                                        split_bblks, dbp);
 
1416
                                }
 
1417
                                /*
 
1418
                                 * Note: this black magic still works with
 
1419
                                 * large sector sizes (non-512) only because:
 
1420
                                 * - we increased the buffer size originally
 
1421
                                 *   by 1 sector giving us enough extra space
 
1422
                                 *   for the second read;
 
1423
                                 * - the log start is guaranteed to be sector
 
1424
                                 *   aligned;
 
1425
                                 * - we read the log end (LR header start)
 
1426
                                 *   _first_, then the log start (LR header end)
 
1427
                                 *   - order is important.
 
1428
                                 */
 
1429
                                bufaddr = XFS_BUF_PTR(dbp);
 
1430
                                XFS_BUF_SET_PTR(dbp,
 
1431
                                                bufaddr + BBTOB(split_bblks),
 
1432
                                                BBTOB(bblks - split_bblks));
 
1433
                                if ((error = xlog_bread(log, wrapped_hblks,
 
1434
                                                bblks - split_bblks, dbp)))
 
1435
                                        goto bread_err2;
 
1436
                                XFS_BUF_SET_PTR(dbp, bufaddr, h_size);
 
1437
                                if (!offset)
 
1438
                                        offset = xlog_align(log, wrapped_hblks,
 
1439
                                                bblks - split_bblks, dbp);
 
1440
                        }
 
1441
                        xlog_unpack_data(rhead, offset, log);
 
1442
                        if ((error = xlog_recover_process_data(log, rhash,
 
1443
                                                        rhead, offset, pass)))
 
1444
                                goto bread_err2;
 
1445
                        blk_no += bblks;
 
1446
                }
 
1447
 
 
1448
                ASSERT(blk_no >= log->l_logBBsize);
 
1449
                blk_no -= log->l_logBBsize;
 
1450
 
 
1451
                /* read first part of physical log */
 
1452
                while (blk_no < head_blk) {
 
1453
                        if ((error = xlog_bread(log, blk_no, hblks, hbp)))
 
1454
                                goto bread_err2;
 
1455
                        offset = xlog_align(log, blk_no, hblks, hbp);
 
1456
                        rhead = (xlog_rec_header_t *)offset;
 
1457
                        error = xlog_valid_rec_header(log, rhead, blk_no);
 
1458
                        if (error)
 
1459
                                goto bread_err2;
 
1460
                        bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
 
1461
                        if ((error = xlog_bread(log, blk_no+hblks, bblks, dbp)))
 
1462
                                goto bread_err2;
 
1463
                        offset = xlog_align(log, blk_no+hblks, bblks, dbp);
 
1464
                        xlog_unpack_data(rhead, offset, log);
 
1465
                        if ((error = xlog_recover_process_data(log, rhash,
 
1466
                                                        rhead, offset, pass)))
 
1467
                                goto bread_err2;
 
1468
                        blk_no += bblks + hblks;
 
1469
                }
 
1470
        }
 
1471
 
 
1472
 bread_err2:
 
1473
        xlog_put_bp(dbp);
 
1474
 bread_err1:
1135
1475
        xlog_put_bp(hbp);
1136
 
        return -ENOMEM;
1137
 
    }
1138
 
    bzero(rhash, sizeof(rhash));
1139
 
    if (tail_blk <= head_blk) {
1140
 
        for (blk_no = tail_blk; blk_no < head_blk; ) {
1141
 
            if ((error = xlog_bread(log, blk_no, 1, hbp)))
1142
 
                goto bread_err;
1143
 
            rhead = (xlog_rec_header_t *)XFS_BUF_PTR(hbp);
1144
 
            ASSERT(INT_GET(rhead->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM);
1145
 
            ASSERT(BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT) <= INT_MAX));
1146
 
            bblks = (int) BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));   /* blocks in data section */
1147
 
            if (bblks > 0) {
1148
 
                if ((error = xlog_bread(log, blk_no+1, bblks, dbp)))
1149
 
                    goto bread_err;
1150
 
                xlog_unpack_data(rhead, XFS_BUF_PTR(dbp), log);
1151
 
                if ((error = xlog_recover_process_data(log, rhash,
1152
 
                                                      rhead, XFS_BUF_PTR(dbp),
1153
 
                                                      pass)))
1154
 
                        goto bread_err;
1155
 
            }
1156
 
            blk_no += (bblks+1);
1157
 
        }
1158
 
    } else {
1159
 
        /*
1160
 
         * Perform recovery around the end of the physical log.  When the head
1161
 
         * is not on the same cycle number as the tail, we can't do a sequential
1162
 
         * recovery as above.
1163
 
         */
1164
 
        blk_no = tail_blk;
1165
 
        while (blk_no < log->l_logBBsize) {
1166
 
 
1167
 
            /* Read header of one block */
1168
 
            if ((error = xlog_bread(log, blk_no, 1, hbp)))
1169
 
                goto bread_err;
1170
 
            rhead = (xlog_rec_header_t *)XFS_BUF_PTR(hbp);
1171
 
            ASSERT(INT_GET(rhead->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM);
1172
 
            ASSERT(BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT) <= INT_MAX));            
1173
 
            bblks = (int) BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
1174
 
 
1175
 
            /* LR body must have data or it wouldn't have been written */
1176
 
            ASSERT(bblks > 0);
1177
 
            blk_no++;                   /* successfully read header */
1178
 
            ASSERT(blk_no <= log->l_logBBsize);
1179
 
 
1180
 
            if ((INT_GET(rhead->h_magicno, ARCH_CONVERT) != XLOG_HEADER_MAGIC_NUM) ||
1181
 
                (BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT) > INT_MAX)) ||
1182
 
                (bblks <= 0) ||
1183
 
                (blk_no > log->l_logBBsize)) {
1184
 
                    error = EFSCORRUPTED;
1185
 
                    goto bread_err;
1186
 
            }
1187
 
                    
1188
 
            /* Read in data for log record */
1189
 
            if (blk_no+bblks <= log->l_logBBsize) {
1190
 
                if ((error = xlog_bread(log, blk_no, bblks, dbp)))
1191
 
                    goto bread_err;
1192
 
            } else {
1193
 
                /* This log record is split across physical end of log */
1194
 
                split_bblks = 0;
1195
 
                if (blk_no != log->l_logBBsize) {
1196
 
 
1197
 
                    /* some data is before physical end of log */
1198
 
                    ASSERT(blk_no <= INT_MAX);
1199
 
                    split_bblks = log->l_logBBsize - (int)blk_no;
1200
 
                    ASSERT(split_bblks > 0);
1201
 
                    if ((error = xlog_bread(log, blk_no, split_bblks, dbp)))
1202
 
                        goto bread_err;
1203
 
                }
1204
 
                bufaddr = XFS_BUF_PTR(dbp);
1205
 
                XFS_BUF_SET_PTR(dbp, bufaddr + BBTOB(split_bblks),
1206
 
                        BBTOB(bblks - split_bblks));
1207
 
                if ((error = xlog_bread(log, 0, bblks - split_bblks, dbp)))
1208
 
                    goto bread_err;
1209
 
                XFS_BUF_SET_PTR(dbp, bufaddr, XLOG_MAX_RECORD_BSIZE);
1210
 
            }
1211
 
            xlog_unpack_data(rhead, XFS_BUF_PTR(dbp), log);
1212
 
            if ((error = xlog_recover_process_data(log, rhash,
1213
 
                                                  rhead, XFS_BUF_PTR(dbp),
1214
 
                                                  pass)))
1215
 
                goto bread_err;
1216
 
            blk_no += bblks;
1217
 
        }
1218
 
 
1219
 
        ASSERT(blk_no >= log->l_logBBsize);
1220
 
        blk_no -= log->l_logBBsize;
1221
 
 
1222
 
        /* read first part of physical log */
1223
 
        while (blk_no < head_blk) {
1224
 
            if ((error = xlog_bread(log, blk_no, 1, hbp)))
1225
 
                goto bread_err;
1226
 
            rhead = (xlog_rec_header_t *)XFS_BUF_PTR(hbp);
1227
 
            ASSERT(INT_GET(rhead->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM);
1228
 
            ASSERT(BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT) <= INT_MAX));
1229
 
            bblks = (int) BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
1230
 
            ASSERT(bblks > 0);
1231
 
            if ((error = xlog_bread(log, blk_no+1, bblks, dbp)))
1232
 
                goto bread_err;
1233
 
            xlog_unpack_data(rhead, XFS_BUF_PTR(dbp), log);
1234
 
            if ((error = xlog_recover_process_data(log, rhash,
1235
 
                                                  rhead, XFS_BUF_PTR(dbp),
1236
 
                                                  pass)))
1237
 
                goto bread_err;
1238
 
            blk_no += (bblks+1);
1239
 
        }
1240
 
    }
1241
 
 
1242
 
bread_err:
1243
 
    xlog_put_bp(dbp);
1244
 
    xlog_put_bp(hbp);
1245
 
 
1246
 
    return error;
 
1476
        return error;
1247
1477
}