~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to fs/ubifs/recovery.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno
  • Date: 2011-06-07 12:14:05 UTC
  • mfrom: (43.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110607121405-i3h1rd7nrnd2b73h
Tags: 2.6.39-2
[ Ben Hutchings ]
* [x86] Enable BACKLIGHT_APPLE, replacing BACKLIGHT_MBP_NVIDIA
  (Closes: #627492)
* cgroups: Disable memory resource controller by default. Allow it
  to be enabled using kernel parameter 'cgroup_enable=memory'.
* rt2800usb: Enable support for more USB devices including
  Linksys WUSB600N (Closes: #596626) (this change was accidentally
  omitted from 2.6.39-1)
* [x86] Remove Celeron from list of processors supporting PAE. Most
  'Celeron M' models do not.
* Update debconf template translations:
  - Swedish (Martin Bagge) (Closes: #628932)
  - French (David Prévot) (Closes: #628191)
* aufs: Update for 2.6.39 (Closes: #627837)
* Add stable 2.6.39.1, including:
  - ext4: dont set PageUptodate in ext4_end_bio()
  - pata_cmd64x: fix boot crash on parisc (Closes: #622997, #622745)
  - ext3: Fix fs corruption when make_indexed_dir() fails
  - netfilter: nf_ct_sip: validate Content-Length in TCP SIP messages
  - sctp: fix race between sctp_bind_addr_free() and
    sctp_bind_addr_conflict()
  - sctp: fix memory leak of the ASCONF queue when free asoc
  - md/bitmap: fix saving of events_cleared and other state
  - cdc_acm: Fix oops when Droids MuIn LCD is connected
  - cx88: Fix conversion from BKL to fine-grained locks (Closes: #619827)
  - keys: Set cred->user_ns in key_replace_session_keyring (CVE-2011-2184)
  - tmpfs: fix race between truncate and writepage
  - nfs41: Correct offset for LAYOUTCOMMIT
  - xen/mmu: fix a race window causing leave_mm BUG()
  - ext4: fix possible use-after-free in ext4_remove_li_request()
  For the complete list of changes, see:
   http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.39.1
* Bump ABI to 2
* netfilter: Enable IP_SET, IP_SET_BITMAP_IP, IP_SET_BITMAP_IPMAC,
  IP_SET_BITMAP_PORT, IP_SET_HASH_IP, IP_SET_HASH_IPPORT,
  IP_SET_HASH_IPPORTIP, IP_SET_HASH_IPPORTNET, IP_SET_HASH_NET,
  IP_SET_HASH_NETPORT, IP_SET_LIST_SET, NETFILTER_XT_SET as modules
  (Closes: #629401)

[ Aurelien Jarno ]
* [mipsel/loongson-2f] Disable_SCSI_LPFC to workaround GCC ICE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 * UBIFS always cleans away all remnants of an unclean un-mount, so that
29
29
 * errors do not accumulate. However UBIFS defers recovery if it is mounted
30
30
 * read-only, and the flash is not modified in that case.
 
31
 *
 
32
 * The general UBIFS approach to the recovery is that it recovers from
 
33
 * corruptions which could be caused by power cuts, but it refuses to recover
 
34
 * from corruption caused by other reasons. And UBIFS tries to distinguish
 
35
 * between these 2 reasons of corruptions and silently recover in the former
 
36
 * case and loudly complain in the latter case.
 
37
 *
 
38
 * UBIFS writes only to erased LEBs, so it writes only to the flash space
 
39
 * containing only 0xFFs. UBIFS also always writes strictly from the beginning
 
40
 * of the LEB to the end. And UBIFS assumes that the underlying flash media
 
41
 * writes in @c->max_write_size bytes at a time.
 
42
 *
 
43
 * Hence, if UBIFS finds a corrupted node at offset X, it expects only the min.
 
44
 * I/O unit corresponding to offset X to contain corrupted data, all the
 
45
 * following min. I/O units have to contain empty space (all 0xFFs). If this is
 
46
 * not true, the corruption cannot be the result of a power cut, and UBIFS
 
47
 * refuses to mount.
31
48
 */
32
49
 
33
50
#include <linux/crc32.h>
300
317
                        goto out_free;
301
318
                }
302
319
                memcpy(c->rcvrd_mst_node, c->mst_node, UBIFS_MST_NODE_SZ);
 
320
 
 
321
                /*
 
322
                 * We had to recover the master node, which means there was an
 
323
                 * unclean reboot. However, it is possible that the master node
 
324
                 * is clean at this point, i.e., %UBIFS_MST_DIRTY is not set.
 
325
                 * E.g., consider the following chain of events:
 
326
                 *
 
327
                 * 1. UBIFS was cleanly unmounted, so the master node is clean
 
328
                 * 2. UBIFS is being mounted R/W and starts changing the master
 
329
                 *    node in the first (%UBIFS_MST_LNUM). A power cut happens,
 
330
                 *    so this LEB ends up with some amount of garbage at the
 
331
                 *    end.
 
332
                 * 3. UBIFS is being mounted R/O. We reach this place and
 
333
                 *    recover the master node from the second LEB
 
334
                 *    (%UBIFS_MST_LNUM + 1). But we cannot update the media
 
335
                 *    because we are being mounted R/O. We have to defer the
 
336
                 *    operation.
 
337
                 * 4. However, this master node (@c->mst_node) is marked as
 
338
                 *    clean (since the step 1). And if we just return, the
 
339
                 *    mount code will be confused and won't recover the master
 
340
                 *    node when it is re-mounter R/W later.
 
341
                 *
 
342
                 *    Thus, to force the recovery by marking the master node as
 
343
                 *    dirty.
 
344
                 */
 
345
                c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY);
303
346
        } else {
304
347
                /* Write the recovered master node */
305
348
                c->max_sqnum = le64_to_cpu(mst->ch.sqnum) - 1;
362
405
 * @offs: offset to check
363
406
 *
364
407
 * This function returns %1 if @offs was in the last write to the LEB whose data
365
 
 * is in @buf, otherwise %0 is returned.  The determination is made by checking
366
 
 * for subsequent empty space starting from the next @c->min_io_size boundary.
 
408
 * is in @buf, otherwise %0 is returned. The determination is made by checking
 
409
 * for subsequent empty space starting from the next @c->max_write_size
 
410
 * boundary.
367
411
 */
368
412
static int is_last_write(const struct ubifs_info *c, void *buf, int offs)
369
413
{
371
415
        uint8_t *p;
372
416
 
373
417
        /*
374
 
         * Round up to the next @c->min_io_size boundary i.e. @offs is in the
375
 
         * last wbuf written. After that should be empty space.
 
418
         * Round up to the next @c->max_write_size boundary i.e. @offs is in
 
419
         * the last wbuf written. After that should be empty space.
376
420
         */
377
 
        empty_offs = ALIGN(offs + 1, c->min_io_size);
 
421
        empty_offs = ALIGN(offs + 1, c->max_write_size);
378
422
        check_len = c->leb_size - empty_offs;
379
423
        p = buf + empty_offs - offs;
380
424
        return is_empty(p, check_len);
429
473
        int skip, dlen = le32_to_cpu(ch->len);
430
474
 
431
475
        /* Check for empty space after the corrupt node's common header */
432
 
        skip = ALIGN(offs + UBIFS_CH_SZ, c->min_io_size) - offs;
 
476
        skip = ALIGN(offs + UBIFS_CH_SZ, c->max_write_size) - offs;
433
477
        if (is_empty(buf + skip, len - skip))
434
478
                return 1;
435
479
        /*
441
485
                return 0;
442
486
        }
443
487
        /* Now we know the corrupt node's length we can skip over it */
444
 
        skip = ALIGN(offs + dlen, c->min_io_size) - offs;
 
488
        skip = ALIGN(offs + dlen, c->max_write_size) - offs;
445
489
        /* After which there should be empty space */
446
490
        if (is_empty(buf + skip, len - skip))
447
491
                return 1;
671
715
                } else {
672
716
                        int corruption = first_non_ff(buf, len);
673
717
 
 
718
                        /*
 
719
                         * See header comment for this file for more
 
720
                         * explanations about the reasons we have this check.
 
721
                         */
674
722
                        ubifs_err("corrupt empty space LEB %d:%d, corruption "
675
723
                                  "starts at %d", lnum, offs, corruption);
676
724
                        /* Make sure we dump interesting non-0xFF data */
677
 
                        offs = corruption;
 
725
                        offs += corruption;
678
726
                        buf += corruption;
679
727
                        goto corrupted;
680
728
                }
836
884
static int recover_head(const struct ubifs_info *c, int lnum, int offs,
837
885
                        void *sbuf)
838
886
{
839
 
        int len, err;
 
887
        int len = c->max_write_size, err;
840
888
 
841
 
        if (c->min_io_size > 1)
842
 
                len = c->min_io_size;
843
 
        else
844
 
                len = 512;
845
889
        if (offs + len > c->leb_size)
846
890
                len = c->leb_size - offs;
847
891