~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/ubifs/journal.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
         * LEB with some empty space.
142
142
         */
143
143
        lnum = ubifs_find_free_space(c, len, &offs, squeeze);
144
 
        if (lnum >= 0) {
145
 
                /* Found an LEB, add it to the journal head */
146
 
                err = ubifs_add_bud_to_log(c, jhead, lnum, offs);
147
 
                if (err)
148
 
                        goto out_return;
149
 
                /* A new bud was successfully allocated and added to the log */
 
144
        if (lnum >= 0)
150
145
                goto out;
151
 
        }
152
146
 
153
147
        err = lnum;
154
148
        if (err != -ENOSPC)
203
197
                return 0;
204
198
        }
205
199
 
206
 
        err = ubifs_add_bud_to_log(c, jhead, lnum, 0);
207
 
        if (err)
208
 
                goto out_return;
209
200
        offs = 0;
210
201
 
211
202
out:
 
203
        /*
 
204
         * Make sure we synchronize the write-buffer before we add the new bud
 
205
         * to the log. Otherwise we may have a power cut after the log
 
206
         * reference node for the last bud (@lnum) is written but before the
 
207
         * write-buffer data are written to the next-to-last bud
 
208
         * (@wbuf->lnum). And the effect would be that the recovery would see
 
209
         * that there is corruption in the next-to-last bud.
 
210
         */
 
211
        err = ubifs_wbuf_sync_nolock(wbuf);
 
212
        if (err)
 
213
                goto out_return;
 
214
        err = ubifs_add_bud_to_log(c, jhead, lnum, offs);
 
215
        if (err)
 
216
                goto out_return;
212
217
        err = ubifs_wbuf_seek_nolock(wbuf, lnum, offs, wbuf->dtype);
213
218
        if (err)
214
219
                goto out_unlock;
380
385
        if (err == -ENOSPC) {
381
386
                /* This are some budgeting problems, print useful information */
382
387
                down_write(&c->commit_sem);
383
 
                spin_lock(&c->space_lock);
384
388
                dbg_dump_stack();
385
 
                dbg_dump_budg(c);
386
 
                spin_unlock(&c->space_lock);
 
389
                dbg_dump_budg(c, &c->bi);
387
390
                dbg_dump_lprops(c);
388
391
                cmt_retries = dbg_check_lprops(c);
389
392
                up_write(&c->commit_sem);
666
669
 
667
670
out_release:
668
671
        release_head(c, BASEHD);
 
672
        kfree(dent);
669
673
out_ro:
670
674
        ubifs_ro_mode(c, err);
671
675
        if (last_reference)
690
694
{
691
695
        struct ubifs_data_node *data;
692
696
        int err, lnum, offs, compr_type, out_len;
693
 
        int dlen = UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR;
 
697
        int dlen = COMPRESSED_DATA_NODE_BUF_SZ, allocated = 1;
694
698
        struct ubifs_inode *ui = ubifs_inode(inode);
695
699
 
696
700
        dbg_jnl("ino %lu, blk %u, len %d, key %s",
698
702
                DBGKEY(key));
699
703
        ubifs_assert(len <= UBIFS_BLOCK_SIZE);
700
704
 
701
 
        data = kmalloc(dlen, GFP_NOFS);
702
 
        if (!data)
703
 
                return -ENOMEM;
 
705
        data = kmalloc(dlen, GFP_NOFS | __GFP_NOWARN);
 
706
        if (!data) {
 
707
                /*
 
708
                 * Fall-back to the write reserve buffer. Note, we might be
 
709
                 * currently on the memory reclaim path, when the kernel is
 
710
                 * trying to free some memory by writing out dirty pages. The
 
711
                 * write reserve buffer helps us to guarantee that we are
 
712
                 * always able to write the data.
 
713
                 */
 
714
                allocated = 0;
 
715
                mutex_lock(&c->write_reserve_mutex);
 
716
                data = c->write_reserve_buf;
 
717
        }
704
718
 
705
719
        data->ch.node_type = UBIFS_DATA_NODE;
706
720
        key_write(c, key, &data->key);
736
750
                goto out_ro;
737
751
 
738
752
        finish_reservation(c);
739
 
        kfree(data);
 
753
        if (!allocated)
 
754
                mutex_unlock(&c->write_reserve_mutex);
 
755
        else
 
756
                kfree(data);
740
757
        return 0;
741
758
 
742
759
out_release:
745
762
        ubifs_ro_mode(c, err);
746
763
        finish_reservation(c);
747
764
out_free:
748
 
        kfree(data);
 
765
        if (!allocated)
 
766
                mutex_unlock(&c->write_reserve_mutex);
 
767
        else
 
768
                kfree(data);
749
769
        return err;
750
770
}
751
771