diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-20 12:19:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-20 12:19:03 -0400 |
commit | 396b122f6af3d329df3b4d688f6e66de3e2a399a (patch) | |
tree | 0b4185d529c1ba4c8eca1de23f14beecbe460323 /fs | |
parent | ed402af3c23a4804b3f8899263e8d0f97c62ab49 (diff) | |
parent | 54779aabb0183bbe049d2b52e96cd148366dfb0b (diff) |
Merge branch 'linux-next' of git://git.infradead.org/ubifs-2.6
* 'linux-next' of git://git.infradead.org/ubifs-2.6: (25 commits)
UBIFS: fix ubifs_compress commentary
UBIFS: amend printk
UBIFS: do not read unnecessary bytes when unpacking bits
UBIFS: check buffer length when scanning for LPT nodes
UBIFS: correct condition to eliminate unecessary assignment
UBIFS: add more debugging messages for LPT
UBIFS: fix bulk-read handling uptodate pages
UBIFS: improve garbage collection
UBIFS: allow for sync_fs when read-only
UBIFS: commit on sync_fs
UBIFS: correct comment for commit_on_unmount
UBIFS: update dbg_dump_inode
UBIFS: fix commentary
UBIFS: fix races in bit-fields
UBIFS: ensure data read beyond i_size is zeroed out correctly
UBIFS: correct key comparison
UBIFS: use bit-fields when possible
UBIFS: check data CRC when in error state
UBIFS: improve znode splitting rules
UBIFS: add no_chk_data_crc mount option
...
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ubifs/budget.c | 26 | ||||
-rw-r--r-- | fs/ubifs/compress.c | 2 | ||||
-rw-r--r-- | fs/ubifs/debug.c | 79 | ||||
-rw-r--r-- | fs/ubifs/debug.h | 6 | ||||
-rw-r--r-- | fs/ubifs/file.c | 260 | ||||
-rw-r--r-- | fs/ubifs/find.c | 4 | ||||
-rw-r--r-- | fs/ubifs/gc.c | 90 | ||||
-rw-r--r-- | fs/ubifs/io.c | 12 | ||||
-rw-r--r-- | fs/ubifs/key.h | 22 | ||||
-rw-r--r-- | fs/ubifs/lprops.c | 34 | ||||
-rw-r--r-- | fs/ubifs/lpt.c | 48 | ||||
-rw-r--r-- | fs/ubifs/lpt_commit.c | 187 | ||||
-rw-r--r-- | fs/ubifs/misc.h | 27 | ||||
-rw-r--r-- | fs/ubifs/scan.c | 2 | ||||
-rw-r--r-- | fs/ubifs/super.c | 109 | ||||
-rw-r--r-- | fs/ubifs/tnc.c | 345 | ||||
-rw-r--r-- | fs/ubifs/tnc_misc.c | 4 | ||||
-rw-r--r-- | fs/ubifs/ubifs-media.h | 1 | ||||
-rw-r--r-- | fs/ubifs/ubifs.h | 85 | ||||
-rw-r--r-- | fs/ubifs/xattr.c | 2 |
20 files changed, 1178 insertions, 167 deletions
diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c index 73db464cd08b..1a4973e10664 100644 --- a/fs/ubifs/budget.c +++ b/fs/ubifs/budget.c | |||
@@ -414,19 +414,21 @@ static int do_budget_space(struct ubifs_info *c) | |||
414 | * @c->lst.empty_lebs + @c->freeable_cnt + @c->idx_gc_cnt - | 414 | * @c->lst.empty_lebs + @c->freeable_cnt + @c->idx_gc_cnt - |
415 | * @c->lst.taken_empty_lebs | 415 | * @c->lst.taken_empty_lebs |
416 | * | 416 | * |
417 | * @empty_lebs are available because they are empty. @freeable_cnt are | 417 | * @c->lst.empty_lebs are available because they are empty. |
418 | * available because they contain only free and dirty space and the | 418 | * @c->freeable_cnt are available because they contain only free and |
419 | * index allocation always occurs after wbufs are synch'ed. | 419 | * dirty space, @c->idx_gc_cnt are available because they are index |
420 | * @idx_gc_cnt are available because they are index LEBs that have been | 420 | * LEBs that have been garbage collected and are awaiting the commit |
421 | * garbage collected (including trivial GC) and are awaiting the commit | 421 | * before they can be used. And the in-the-gaps method will grab these |
422 | * before they can be unmapped - note that the in-the-gaps method will | 422 | * if it needs them. @c->lst.taken_empty_lebs are empty LEBs that have |
423 | * grab these if it needs them. @taken_empty_lebs are empty_lebs that | 423 | * already been allocated for some purpose. |
424 | * have already been allocated for some purpose (also includes those | ||
425 | * LEBs on the @idx_gc list). | ||
426 | * | 424 | * |
427 | * Note, @taken_empty_lebs may temporarily be higher by one because of | 425 | * Note, @c->idx_gc_cnt is included to both @c->lst.empty_lebs (because |
428 | * the way we serialize LEB allocations and budgeting. See a comment in | 426 | * these LEBs are empty) and to @c->lst.taken_empty_lebs (because they |
429 | * 'ubifs_find_free_space()'. | 427 | * are taken until after the commit). |
428 | * | ||
429 | * Note, @c->lst.taken_empty_lebs may temporarily be higher by one | ||
430 | * because of the way we serialize LEB allocations and budgeting. See a | ||
431 | * comment in 'ubifs_find_free_space()'. | ||
430 | */ | 432 | */ |
431 | lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt - | 433 | lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt - |
432 | c->lst.taken_empty_lebs; | 434 | c->lst.taken_empty_lebs; |
diff --git a/fs/ubifs/compress.c b/fs/ubifs/compress.c index 5bb51dac3c16..a0ada596b17c 100644 --- a/fs/ubifs/compress.c +++ b/fs/ubifs/compress.c | |||
@@ -91,8 +91,6 @@ struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; | |||
91 | * | 91 | * |
92 | * Note, if the input buffer was not compressed, it is copied to the output | 92 | * Note, if the input buffer was not compressed, it is copied to the output |
93 | * buffer and %UBIFS_COMPR_NONE is returned in @compr_type. | 93 | * buffer and %UBIFS_COMPR_NONE is returned in @compr_type. |
94 | * | ||
95 | * This functions returns %0 on success or a negative error code on failure. | ||
96 | */ | 94 | */ |
97 | void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len, | 95 | void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len, |
98 | int *compr_type) | 96 | int *compr_type) |
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index d7f7645779f2..7186400750e7 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c | |||
@@ -222,30 +222,38 @@ void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode) | |||
222 | { | 222 | { |
223 | const struct ubifs_inode *ui = ubifs_inode(inode); | 223 | const struct ubifs_inode *ui = ubifs_inode(inode); |
224 | 224 | ||
225 | printk(KERN_DEBUG "inode %lu\n", inode->i_ino); | 225 | printk(KERN_DEBUG "Dump in-memory inode:"); |
226 | printk(KERN_DEBUG "size %llu\n", | 226 | printk(KERN_DEBUG "\tinode %lu\n", inode->i_ino); |
227 | printk(KERN_DEBUG "\tsize %llu\n", | ||
227 | (unsigned long long)i_size_read(inode)); | 228 | (unsigned long long)i_size_read(inode)); |
228 | printk(KERN_DEBUG "nlink %u\n", inode->i_nlink); | 229 | printk(KERN_DEBUG "\tnlink %u\n", inode->i_nlink); |
229 | printk(KERN_DEBUG "uid %u\n", (unsigned int)inode->i_uid); | 230 | printk(KERN_DEBUG "\tuid %u\n", (unsigned int)inode->i_uid); |
230 | printk(KERN_DEBUG "gid %u\n", (unsigned int)inode->i_gid); | 231 | printk(KERN_DEBUG "\tgid %u\n", (unsigned int)inode->i_gid); |
231 | printk(KERN_DEBUG "atime %u.%u\n", | 232 | printk(KERN_DEBUG "\tatime %u.%u\n", |
232 | (unsigned int)inode->i_atime.tv_sec, | 233 | (unsigned int)inode->i_atime.tv_sec, |
233 | (unsigned int)inode->i_atime.tv_nsec); | 234 | (unsigned int)inode->i_atime.tv_nsec); |
234 | printk(KERN_DEBUG "mtime %u.%u\n", | 235 | printk(KERN_DEBUG "\tmtime %u.%u\n", |
235 | (unsigned int)inode->i_mtime.tv_sec, | 236 | (unsigned int)inode->i_mtime.tv_sec, |
236 | (unsigned int)inode->i_mtime.tv_nsec); | 237 | (unsigned int)inode->i_mtime.tv_nsec); |
237 | printk(KERN_DEBUG "ctime %u.%u\n", | 238 | printk(KERN_DEBUG "\tctime %u.%u\n", |
238 | (unsigned int)inode->i_ctime.tv_sec, | 239 | (unsigned int)inode->i_ctime.tv_sec, |
239 | (unsigned int)inode->i_ctime.tv_nsec); | 240 | (unsigned int)inode->i_ctime.tv_nsec); |
240 | printk(KERN_DEBUG "creat_sqnum %llu\n", ui->creat_sqnum); | 241 | printk(KERN_DEBUG "\tcreat_sqnum %llu\n", ui->creat_sqnum); |
241 | printk(KERN_DEBUG "xattr_size %u\n", ui->xattr_size); | 242 | printk(KERN_DEBUG "\txattr_size %u\n", ui->xattr_size); |
242 | printk(KERN_DEBUG "xattr_cnt %u\n", ui->xattr_cnt); | 243 | printk(KERN_DEBUG "\txattr_cnt %u\n", ui->xattr_cnt); |
243 | printk(KERN_DEBUG "xattr_names %u\n", ui->xattr_names); | 244 | printk(KERN_DEBUG "\txattr_names %u\n", ui->xattr_names); |
244 | printk(KERN_DEBUG "dirty %u\n", ui->dirty); | 245 | printk(KERN_DEBUG "\tdirty %u\n", ui->dirty); |
245 | printk(KERN_DEBUG "xattr %u\n", ui->xattr); | 246 | printk(KERN_DEBUG "\txattr %u\n", ui->xattr); |
246 | printk(KERN_DEBUG "flags %d\n", ui->flags); | 247 | printk(KERN_DEBUG "\tbulk_read %u\n", ui->xattr); |
247 | printk(KERN_DEBUG "compr_type %d\n", ui->compr_type); | 248 | printk(KERN_DEBUG "\tsynced_i_size %llu\n", |
248 | printk(KERN_DEBUG "data_len %d\n", ui->data_len); | 249 | (unsigned long long)ui->synced_i_size); |
250 | printk(KERN_DEBUG "\tui_size %llu\n", | ||
251 | (unsigned long long)ui->ui_size); | ||
252 | printk(KERN_DEBUG "\tflags %d\n", ui->flags); | ||
253 | printk(KERN_DEBUG "\tcompr_type %d\n", ui->compr_type); | ||
254 | printk(KERN_DEBUG "\tlast_page_read %lu\n", ui->last_page_read); | ||
255 | printk(KERN_DEBUG "\tread_in_a_row %lu\n", ui->read_in_a_row); | ||
256 | printk(KERN_DEBUG "\tdata_len %d\n", ui->data_len); | ||
249 | } | 257 | } |
250 | 258 | ||
251 | void dbg_dump_node(const struct ubifs_info *c, const void *node) | 259 | void dbg_dump_node(const struct ubifs_info *c, const void *node) |
@@ -647,6 +655,43 @@ void dbg_dump_lprops(struct ubifs_info *c) | |||
647 | } | 655 | } |
648 | } | 656 | } |
649 | 657 | ||
658 | void dbg_dump_lpt_info(struct ubifs_info *c) | ||
659 | { | ||
660 | int i; | ||
661 | |||
662 | spin_lock(&dbg_lock); | ||
663 | printk(KERN_DEBUG "\tlpt_sz: %lld\n", c->lpt_sz); | ||
664 | printk(KERN_DEBUG "\tpnode_sz: %d\n", c->pnode_sz); | ||
665 | printk(KERN_DEBUG "\tnnode_sz: %d\n", c->nnode_sz); | ||
666 | printk(KERN_DEBUG "\tltab_sz: %d\n", c->ltab_sz); | ||
667 | printk(KERN_DEBUG "\tlsave_sz: %d\n", c->lsave_sz); | ||
668 | printk(KERN_DEBUG "\tbig_lpt: %d\n", c->big_lpt); | ||
669 | printk(KERN_DEBUG "\tlpt_hght: %d\n", c->lpt_hght); | ||
670 | printk(KERN_DEBUG "\tpnode_cnt: %d\n", c->pnode_cnt); | ||
671 | printk(KERN_DEBUG "\tnnode_cnt: %d\n", c->nnode_cnt); | ||
672 | printk(KERN_DEBUG "\tdirty_pn_cnt: %d\n", c->dirty_pn_cnt); | ||
673 | printk(KERN_DEBUG "\tdirty_nn_cnt: %d\n", c->dirty_nn_cnt); | ||
674 | printk(KERN_DEBUG "\tlsave_cnt: %d\n", c->lsave_cnt); | ||
675 | printk(KERN_DEBUG "\tspace_bits: %d\n", c->space_bits); | ||
676 | printk(KERN_DEBUG "\tlpt_lnum_bits: %d\n", c->lpt_lnum_bits); | ||
677 | printk(KERN_DEBUG "\tlpt_offs_bits: %d\n", c->lpt_offs_bits); | ||
678 | printk(KERN_DEBUG "\tlpt_spc_bits: %d\n", c->lpt_spc_bits); | ||
679 | printk(KERN_DEBUG "\tpcnt_bits: %d\n", c->pcnt_bits); | ||
680 | printk(KERN_DEBUG "\tlnum_bits: %d\n", c->lnum_bits); | ||
681 | printk(KERN_DEBUG "\tLPT root is at %d:%d\n", c->lpt_lnum, c->lpt_offs); | ||
682 | printk(KERN_DEBUG "\tLPT head is at %d:%d\n", | ||
683 | c->nhead_lnum, c->nhead_offs); | ||
684 | printk(KERN_DEBUG "\tLPT ltab is at %d:%d\n", c->ltab_lnum, c->ltab_offs); | ||
685 | if (c->big_lpt) | ||
686 | printk(KERN_DEBUG "\tLPT lsave is at %d:%d\n", | ||
687 | c->lsave_lnum, c->lsave_offs); | ||
688 | for (i = 0; i < c->lpt_lebs; i++) | ||
689 | printk(KERN_DEBUG "\tLPT LEB %d free %d dirty %d tgc %d " | ||
690 | "cmt %d\n", i + c->lpt_first, c->ltab[i].free, | ||
691 | c->ltab[i].dirty, c->ltab[i].tgc, c->ltab[i].cmt); | ||
692 | spin_unlock(&dbg_lock); | ||
693 | } | ||
694 | |||
650 | void dbg_dump_leb(const struct ubifs_info *c, int lnum) | 695 | void dbg_dump_leb(const struct ubifs_info *c, int lnum) |
651 | { | 696 | { |
652 | struct ubifs_scan_leb *sleb; | 697 | struct ubifs_scan_leb *sleb; |
diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h index 50315fc57185..33d6b95071e4 100644 --- a/fs/ubifs/debug.h +++ b/fs/ubifs/debug.h | |||
@@ -224,6 +224,7 @@ void dbg_dump_lstats(const struct ubifs_lp_stats *lst); | |||
224 | void dbg_dump_budg(struct ubifs_info *c); | 224 | void dbg_dump_budg(struct ubifs_info *c); |
225 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp); | 225 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp); |
226 | void dbg_dump_lprops(struct ubifs_info *c); | 226 | void dbg_dump_lprops(struct ubifs_info *c); |
227 | void dbg_dump_lpt_info(struct ubifs_info *c); | ||
227 | void dbg_dump_leb(const struct ubifs_info *c, int lnum); | 228 | void dbg_dump_leb(const struct ubifs_info *c, int lnum); |
228 | void dbg_dump_znode(const struct ubifs_info *c, | 229 | void dbg_dump_znode(const struct ubifs_info *c, |
229 | const struct ubifs_znode *znode); | 230 | const struct ubifs_znode *znode); |
@@ -249,6 +250,8 @@ int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot); | |||
249 | int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot); | 250 | int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot); |
250 | int dbg_check_cats(struct ubifs_info *c); | 251 | int dbg_check_cats(struct ubifs_info *c); |
251 | int dbg_check_ltab(struct ubifs_info *c); | 252 | int dbg_check_ltab(struct ubifs_info *c); |
253 | int dbg_chk_lpt_free_spc(struct ubifs_info *c); | ||
254 | int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len); | ||
252 | int dbg_check_synced_i_size(struct inode *inode); | 255 | int dbg_check_synced_i_size(struct inode *inode); |
253 | int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir); | 256 | int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir); |
254 | int dbg_check_tnc(struct ubifs_info *c, int extra); | 257 | int dbg_check_tnc(struct ubifs_info *c, int extra); |
@@ -367,6 +370,7 @@ static inline int dbg_change(struct ubi_volume_desc *desc, int lnum, | |||
367 | #define dbg_dump_budg(c) ({}) | 370 | #define dbg_dump_budg(c) ({}) |
368 | #define dbg_dump_lprop(c, lp) ({}) | 371 | #define dbg_dump_lprop(c, lp) ({}) |
369 | #define dbg_dump_lprops(c) ({}) | 372 | #define dbg_dump_lprops(c) ({}) |
373 | #define dbg_dump_lpt_info(c) ({}) | ||
370 | #define dbg_dump_leb(c, lnum) ({}) | 374 | #define dbg_dump_leb(c, lnum) ({}) |
371 | #define dbg_dump_znode(c, znode) ({}) | 375 | #define dbg_dump_znode(c, znode) ({}) |
372 | #define dbg_dump_heap(c, heap, cat) ({}) | 376 | #define dbg_dump_heap(c, heap, cat) ({}) |
@@ -379,6 +383,8 @@ static inline int dbg_change(struct ubi_volume_desc *desc, int lnum, | |||
379 | #define dbg_check_old_index(c, zroot) 0 | 383 | #define dbg_check_old_index(c, zroot) 0 |
380 | #define dbg_check_cats(c) 0 | 384 | #define dbg_check_cats(c) 0 |
381 | #define dbg_check_ltab(c) 0 | 385 | #define dbg_check_ltab(c) 0 |
386 | #define dbg_chk_lpt_free_spc(c) 0 | ||
387 | #define dbg_chk_lpt_sz(c, action, len) 0 | ||
382 | #define dbg_check_synced_i_size(inode) 0 | 388 | #define dbg_check_synced_i_size(inode) 0 |
383 | #define dbg_check_dir_size(c, dir) 0 | 389 | #define dbg_check_dir_size(c, dir) 0 |
384 | #define dbg_check_tnc(c, x) 0 | 390 | #define dbg_check_tnc(c, x) 0 |
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 3d698e2022b1..51cf511d44d9 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c | |||
@@ -147,6 +147,12 @@ static int do_readpage(struct page *page) | |||
147 | err = ret; | 147 | err = ret; |
148 | if (err != -ENOENT) | 148 | if (err != -ENOENT) |
149 | break; | 149 | break; |
150 | } else if (block + 1 == beyond) { | ||
151 | int dlen = le32_to_cpu(dn->size); | ||
152 | int ilen = i_size & (UBIFS_BLOCK_SIZE - 1); | ||
153 | |||
154 | if (ilen && ilen < dlen) | ||
155 | memset(addr + ilen, 0, dlen - ilen); | ||
150 | } | 156 | } |
151 | } | 157 | } |
152 | if (++i >= UBIFS_BLOCKS_PER_PAGE) | 158 | if (++i >= UBIFS_BLOCKS_PER_PAGE) |
@@ -577,8 +583,262 @@ out: | |||
577 | return copied; | 583 | return copied; |
578 | } | 584 | } |
579 | 585 | ||
586 | /** | ||
587 | * populate_page - copy data nodes into a page for bulk-read. | ||
588 | * @c: UBIFS file-system description object | ||
589 | * @page: page | ||
590 | * @bu: bulk-read information | ||
591 | * @n: next zbranch slot | ||
592 | * | ||
593 | * This function returns %0 on success and a negative error code on failure. | ||
594 | */ | ||
595 | static int populate_page(struct ubifs_info *c, struct page *page, | ||
596 | struct bu_info *bu, int *n) | ||
597 | { | ||
598 | int i = 0, nn = *n, offs = bu->zbranch[0].offs, hole = 0, read = 0; | ||
599 | struct inode *inode = page->mapping->host; | ||
600 | loff_t i_size = i_size_read(inode); | ||
601 | unsigned int page_block; | ||
602 | void *addr, *zaddr; | ||
603 | pgoff_t end_index; | ||
604 | |||
605 | dbg_gen("ino %lu, pg %lu, i_size %lld, flags %#lx", | ||
606 | inode->i_ino, page->index, i_size, page->flags); | ||
607 | |||
608 | addr = zaddr = kmap(page); | ||
609 | |||
610 | end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; | ||
611 | if (!i_size || page->index > end_index) { | ||
612 | hole = 1; | ||
613 | memset(addr, 0, PAGE_CACHE_SIZE); | ||
614 | goto out_hole; | ||
615 | } | ||
616 | |||
617 | page_block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT; | ||
618 | while (1) { | ||
619 | int err, len, out_len, dlen; | ||
620 | |||
621 | if (nn >= bu->cnt) { | ||
622 | hole = 1; | ||
623 | memset(addr, 0, UBIFS_BLOCK_SIZE); | ||
624 | } else if (key_block(c, &bu->zbranch[nn].key) == page_block) { | ||
625 | struct ubifs_data_node *dn; | ||
626 | |||
627 | dn = bu->buf + (bu->zbranch[nn].offs - offs); | ||
628 | |||
629 | ubifs_assert(dn->ch.sqnum > | ||
630 | ubifs_inode(inode)->creat_sqnum); | ||
631 | |||
632 | len = le32_to_cpu(dn->size); | ||
633 | if (len <= 0 || len > UBIFS_BLOCK_SIZE) | ||
634 | goto out_err; | ||
635 | |||
636 | dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; | ||
637 | out_len = UBIFS_BLOCK_SIZE; | ||
638 | err = ubifs_decompress(&dn->data, dlen, addr, &out_len, | ||
639 | le16_to_cpu(dn->compr_type)); | ||
640 | if (err || len != out_len) | ||
641 | goto out_err; | ||
642 | |||
643 | if (len < UBIFS_BLOCK_SIZE) | ||
644 | memset(addr + len, 0, UBIFS_BLOCK_SIZE - len); | ||
645 | |||
646 | nn += 1; | ||
647 | read = (i << UBIFS_BLOCK_SHIFT) + len; | ||
648 | } else if (key_block(c, &bu->zbranch[nn].key) < page_block) { | ||
649 | nn += 1; | ||
650 | continue; | ||
651 | } else { | ||
652 | hole = 1; | ||
653 | memset(addr, 0, UBIFS_BLOCK_SIZE); | ||
654 | } | ||
655 | if (++i >= UBIFS_BLOCKS_PER_PAGE) | ||
656 | break; | ||
657 | addr += UBIFS_BLOCK_SIZE; | ||
658 | page_block += 1; | ||
659 | } | ||
660 | |||
661 | if (end_index == page->index) { | ||
662 | int len = i_size & (PAGE_CACHE_SIZE - 1); | ||
663 | |||
664 | if (len && len < read) | ||
665 | memset(zaddr + len, 0, read - len); | ||
666 | } | ||
667 | |||
668 | out_hole: | ||
669 | if (hole) { | ||
670 | SetPageChecked(page); | ||
671 | dbg_gen("hole"); | ||
672 | } | ||
673 | |||
674 | SetPageUptodate(page); | ||
675 | ClearPageError(page); | ||
676 | flush_dcache_page(page); | ||
677 | kunmap(page); | ||
678 | *n = nn; | ||
679 | return 0; | ||
680 | |||
681 | out_err: | ||
682 | ClearPageUptodate(page); | ||
683 | SetPageError(page); | ||
684 | flush_dcache_page(page); | ||
685 | kunmap(page); | ||
686 | ubifs_err("bad data node (block %u, inode %lu)", | ||
687 | page_block, inode->i_ino); | ||
688 | return -EINVAL; | ||
689 | } | ||
690 | |||
691 | /** | ||
692 | * ubifs_do_bulk_read - do bulk-read. | ||
693 | * @c: UBIFS file-system description object | ||
694 | * @page1: first page | ||
695 | * | ||
696 | * This function returns %1 if the bulk-read is done, otherwise %0 is returned. | ||
697 | */ | ||
698 | static int ubifs_do_bulk_read(struct ubifs_info *c, struct page *page1) | ||
699 | { | ||
700 | pgoff_t offset = page1->index, end_index; | ||
701 | struct address_space *mapping = page1->mapping; | ||
702 | struct inode *inode = mapping->host; | ||
703 | struct ubifs_inode *ui = ubifs_inode(inode); | ||
704 | struct bu_info *bu; | ||
705 | int err, page_idx, page_cnt, ret = 0, n = 0; | ||
706 | loff_t isize; | ||
707 | |||
708 | bu = kmalloc(sizeof(struct bu_info), GFP_NOFS); | ||
709 | if (!bu) | ||
710 | return 0; | ||
711 | |||
712 | bu->buf_len = c->bulk_read_buf_size; | ||
713 | bu->buf = kmalloc(bu->buf_len, GFP_NOFS); | ||
714 | if (!bu->buf) | ||
715 | goto out_free; | ||
716 | |||
717 | data_key_init(c, &bu->key, inode->i_ino, | ||
718 | offset << UBIFS_BLOCKS_PER_PAGE_SHIFT); | ||
719 | |||
720 | err = ubifs_tnc_get_bu_keys(c, bu); | ||
721 | if (err) | ||
722 | goto out_warn; | ||
723 | |||
724 | if (bu->eof) { | ||
725 | /* Turn off bulk-read at the end of the file */ | ||
726 | ui->read_in_a_row = 1; | ||
727 | ui->bulk_read = 0; | ||
728 | } | ||
729 | |||
730 | page_cnt = bu->blk_cnt >> UBIFS_BLOCKS_PER_PAGE_SHIFT; | ||
731 | if (!page_cnt) { | ||
732 | /* | ||
733 | * This happens when there are multiple blocks per page and the | ||
734 | * blocks for the first page we are looking for, are not | ||
735 | * together. If all the pages were like this, bulk-read would | ||
736 | * reduce performance, so we turn it off for a while. | ||
737 | */ | ||
738 | ui->read_in_a_row = 0; | ||
739 | ui->bulk_read = 0; | ||
740 | goto out_free; | ||
741 | } | ||
742 | |||
743 | if (bu->cnt) { | ||
744 | err = ubifs_tnc_bulk_read(c, bu); | ||
745 | if (err) | ||
746 | goto out_warn; | ||
747 | } | ||
748 | |||
749 | err = populate_page(c, page1, bu, &n); | ||
750 | if (err) | ||
751 | goto out_warn; | ||
752 | |||
753 | unlock_page(page1); | ||
754 | ret = 1; | ||
755 | |||
756 | isize = i_size_read(inode); | ||
757 | if (isize == 0) | ||
758 | goto out_free; | ||
759 | end_index = ((isize - 1) >> PAGE_CACHE_SHIFT); | ||
760 | |||
761 | for (page_idx = 1; page_idx < page_cnt; page_idx++) { | ||
762 | pgoff_t page_offset = offset + page_idx; | ||
763 | struct page *page; | ||
764 | |||
765 | if (page_offset > end_index) | ||
766 | break; | ||
767 | page = find_or_create_page(mapping, page_offset, | ||
768 | GFP_NOFS | __GFP_COLD); | ||
769 | if (!page) | ||
770 | break; | ||
771 | if (!PageUptodate(page)) | ||
772 | err = populate_page(c, page, bu, &n); | ||
773 | unlock_page(page); | ||
774 | page_cache_release(page); | ||
775 | if (err) | ||
776 | break; | ||
777 | } | ||
778 | |||
779 | ui->last_page_read = offset + page_idx - 1; | ||
780 | |||
781 | out_free: | ||
782 | kfree(bu->buf); | ||
783 | kfree(bu); | ||
784 | return ret; | ||
785 | |||
786 | out_warn: | ||
787 | ubifs_warn("ignoring error %d and skipping bulk-read", err); | ||
788 | goto out_free; | ||
789 | } | ||
790 | |||
791 | /** | ||
792 | * ubifs_bulk_read - determine whether to bulk-read and, if so, do it. | ||
793 | * @page: page from which to start bulk-read. | ||
794 | * | ||
795 | * Some flash media are capable of reading sequentially at faster rates. UBIFS | ||
796 | * bulk-read facility is designed to take advantage of that, by reading in one | ||
797 | * go consecutive data nodes that are also located consecutively in the same | ||
798 | * LEB. This function returns %1 if a bulk-read is done and %0 otherwise. | ||
799 | */ | ||
800 | static int ubifs_bulk_read(struct page *page) | ||
801 | { | ||
802 | struct inode *inode = page->mapping->host; | ||
803 | struct ubifs_info *c = inode->i_sb->s_fs_info; | ||
804 | struct ubifs_inode *ui = ubifs_inode(inode); | ||
805 | pgoff_t index = page->index, last_page_read = ui->last_page_read; | ||
806 | int ret = 0; | ||
807 | |||
808 | ui->last_page_read = index; | ||
809 | |||
810 | if (!c->bulk_read) | ||
811 | return 0; | ||
812 | /* | ||
813 | * Bulk-read is protected by ui_mutex, but it is an optimization, so | ||
814 | * don't bother if we cannot lock the mutex. | ||
815 | */ | ||
816 | if (!mutex_trylock(&ui->ui_mutex)) | ||
817 | return 0; | ||
818 | if (index != last_page_read + 1) { | ||
819 | /* Turn off bulk-read if we stop reading sequentially */ | ||
820 | ui->read_in_a_row = 1; | ||
821 | if (ui->bulk_read) | ||
822 | ui->bulk_read = 0; | ||
823 | goto out_unlock; | ||
824 | } | ||
825 | if (!ui->bulk_read) { | ||
826 | ui->read_in_a_row += 1; | ||
827 | if (ui->read_in_a_row < 3) | ||
828 | goto out_unlock; | ||
829 | /* Three reads in a row, so switch on bulk-read */ | ||
830 | ui->bulk_read = 1; | ||
831 | } | ||
832 | ret = ubifs_do_bulk_read(c, page); | ||
833 | out_unlock: | ||
834 | mutex_unlock(&ui->ui_mutex); | ||
835 | return ret; | ||
836 | } | ||
837 | |||
580 | static int ubifs_readpage(struct file *file, struct page *page) | 838 | static int ubifs_readpage(struct file *file, struct page *page) |
581 | { | 839 | { |
840 | if (ubifs_bulk_read(page)) | ||
841 | return 0; | ||
582 | do_readpage(page); | 842 | do_readpage(page); |
583 | unlock_page(page); | 843 | unlock_page(page); |
584 | return 0; | 844 | return 0; |
diff --git a/fs/ubifs/find.c b/fs/ubifs/find.c index 47814cde2407..717d79c97c5e 100644 --- a/fs/ubifs/find.c +++ b/fs/ubifs/find.c | |||
@@ -901,11 +901,11 @@ static int get_idx_gc_leb(struct ubifs_info *c) | |||
901 | * it is needed now for this commit. | 901 | * it is needed now for this commit. |
902 | */ | 902 | */ |
903 | lp = ubifs_lpt_lookup_dirty(c, lnum); | 903 | lp = ubifs_lpt_lookup_dirty(c, lnum); |
904 | if (unlikely(IS_ERR(lp))) | 904 | if (IS_ERR(lp)) |
905 | return PTR_ERR(lp); | 905 | return PTR_ERR(lp); |
906 | lp = ubifs_change_lp(c, lp, LPROPS_NC, LPROPS_NC, | 906 | lp = ubifs_change_lp(c, lp, LPROPS_NC, LPROPS_NC, |
907 | lp->flags | LPROPS_INDEX, -1); | 907 | lp->flags | LPROPS_INDEX, -1); |
908 | if (unlikely(IS_ERR(lp))) | 908 | if (IS_ERR(lp)) |
909 | return PTR_ERR(lp); | 909 | return PTR_ERR(lp); |
910 | dbg_find("LEB %d, dirty %d and free %d flags %#x", | 910 | dbg_find("LEB %d, dirty %d and free %d flags %#x", |
911 | lp->lnum, lp->dirty, lp->free, lp->flags); | 911 | lp->lnum, lp->dirty, lp->free, lp->flags); |
diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c index 02aba36fe3d4..0bef6501d58a 100644 --- a/fs/ubifs/gc.c +++ b/fs/ubifs/gc.c | |||
@@ -96,6 +96,48 @@ static int switch_gc_head(struct ubifs_info *c) | |||
96 | } | 96 | } |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * joinup - bring data nodes for an inode together. | ||
100 | * @c: UBIFS file-system description object | ||
101 | * @sleb: describes scanned LEB | ||
102 | * @inum: inode number | ||
103 | * @blk: block number | ||
104 | * @data: list to which to add data nodes | ||
105 | * | ||
106 | * This function looks at the first few nodes in the scanned LEB @sleb and adds | ||
107 | * them to @data if they are data nodes from @inum and have a larger block | ||
108 | * number than @blk. This function returns %0 on success and a negative error | ||
109 | * code on failure. | ||
110 | */ | ||
111 | static int joinup(struct ubifs_info *c, struct ubifs_scan_leb *sleb, ino_t inum, | ||
112 | unsigned int blk, struct list_head *data) | ||
113 | { | ||
114 | int err, cnt = 6, lnum = sleb->lnum, offs; | ||
115 | struct ubifs_scan_node *snod, *tmp; | ||
116 | union ubifs_key *key; | ||
117 | |||
118 | list_for_each_entry_safe(snod, tmp, &sleb->nodes, list) { | ||
119 | key = &snod->key; | ||
120 | if (key_inum(c, key) == inum && | ||
121 | key_type(c, key) == UBIFS_DATA_KEY && | ||
122 | key_block(c, key) > blk) { | ||
123 | offs = snod->offs; | ||
124 | err = ubifs_tnc_has_node(c, key, 0, lnum, offs, 0); | ||
125 | if (err < 0) | ||
126 | return err; | ||
127 | list_del(&snod->list); | ||
128 | if (err) { | ||
129 | list_add_tail(&snod->list, data); | ||
130 | blk = key_block(c, key); | ||
131 | } else | ||
132 | kfree(snod); | ||
133 | cnt = 6; | ||
134 | } else if (--cnt == 0) | ||
135 | break; | ||
136 | } | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | /** | ||
99 | * move_nodes - move nodes. | 141 | * move_nodes - move nodes. |
100 | * @c: UBIFS file-system description object | 142 | * @c: UBIFS file-system description object |
101 | * @sleb: describes nodes to move | 143 | * @sleb: describes nodes to move |
@@ -116,16 +158,21 @@ static int switch_gc_head(struct ubifs_info *c) | |||
116 | static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb) | 158 | static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb) |
117 | { | 159 | { |
118 | struct ubifs_scan_node *snod, *tmp; | 160 | struct ubifs_scan_node *snod, *tmp; |
119 | struct list_head large, medium, small; | 161 | struct list_head data, large, medium, small; |
120 | struct ubifs_wbuf *wbuf = &c->jheads[GCHD].wbuf; | 162 | struct ubifs_wbuf *wbuf = &c->jheads[GCHD].wbuf; |
121 | int avail, err, min = INT_MAX; | 163 | int avail, err, min = INT_MAX; |
164 | unsigned int blk = 0; | ||
165 | ino_t inum = 0; | ||
122 | 166 | ||
167 | INIT_LIST_HEAD(&data); | ||
123 | INIT_LIST_HEAD(&large); | 168 | INIT_LIST_HEAD(&large); |
124 | INIT_LIST_HEAD(&medium); | 169 | INIT_LIST_HEAD(&medium); |
125 | INIT_LIST_HEAD(&small); | 170 | INIT_LIST_HEAD(&small); |
126 | 171 | ||
127 | list_for_each_entry_safe(snod, tmp, &sleb->nodes, list) { | 172 | while (!list_empty(&sleb->nodes)) { |
128 | struct list_head *lst; | 173 | struct list_head *lst = sleb->nodes.next; |
174 | |||
175 | snod = list_entry(lst, struct ubifs_scan_node, list); | ||
129 | 176 | ||
130 | ubifs_assert(snod->type != UBIFS_IDX_NODE); | 177 | ubifs_assert(snod->type != UBIFS_IDX_NODE); |
131 | ubifs_assert(snod->type != UBIFS_REF_NODE); | 178 | ubifs_assert(snod->type != UBIFS_REF_NODE); |
@@ -136,7 +183,6 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb) | |||
136 | if (err < 0) | 183 | if (err < 0) |
137 | goto out; | 184 | goto out; |
138 | 185 | ||
139 | lst = &snod->list; | ||
140 | list_del(lst); | 186 | list_del(lst); |
141 | if (!err) { | 187 | if (!err) { |
142 | /* The node is obsolete, remove it from the list */ | 188 | /* The node is obsolete, remove it from the list */ |
@@ -145,15 +191,30 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb) | |||
145 | } | 191 | } |
146 | 192 | ||
147 | /* | 193 | /* |
148 | * Sort the list of nodes so that large nodes go first, and | 194 | * Sort the list of nodes so that data nodes go first, large |
149 | * small nodes go last. | 195 | * nodes go second, and small nodes go last. |
150 | */ | 196 | */ |
151 | if (snod->len > MEDIUM_NODE_WM) | 197 | if (key_type(c, &snod->key) == UBIFS_DATA_KEY) { |
152 | list_add(lst, &large); | 198 | if (inum != key_inum(c, &snod->key)) { |
199 | if (inum) { | ||
200 | /* | ||
201 | * Try to move data nodes from the same | ||
202 | * inode together. | ||
203 | */ | ||
204 | err = joinup(c, sleb, inum, blk, &data); | ||
205 | if (err) | ||
206 | goto out; | ||
207 | } | ||
208 | inum = key_inum(c, &snod->key); | ||
209 | blk = key_block(c, &snod->key); | ||
210 | } | ||
211 | list_add_tail(lst, &data); | ||
212 | } else if (snod->len > MEDIUM_NODE_WM) | ||
213 | list_add_tail(lst, &large); | ||
153 | else if (snod->len > SMALL_NODE_WM) | 214 | else if (snod->len > SMALL_NODE_WM) |
154 | list_add(lst, &medium); | 215 | list_add_tail(lst, &medium); |
155 | else | 216 | else |
156 | list_add(lst, &small); | 217 | list_add_tail(lst, &small); |
157 | 218 | ||
158 | /* And find the smallest node */ | 219 | /* And find the smallest node */ |
159 | if (snod->len < min) | 220 | if (snod->len < min) |
@@ -164,6 +225,7 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb) | |||
164 | * Join the tree lists so that we'd have one roughly sorted list | 225 | * Join the tree lists so that we'd have one roughly sorted list |
165 | * ('large' will be the head of the joined list). | 226 | * ('large' will be the head of the joined list). |
166 | */ | 227 | */ |
228 | list_splice(&data, &large); | ||
167 | list_splice(&medium, large.prev); | 229 | list_splice(&medium, large.prev); |
168 | list_splice(&small, large.prev); | 230 | list_splice(&small, large.prev); |
169 | 231 | ||
@@ -653,7 +715,7 @@ int ubifs_gc_start_commit(struct ubifs_info *c) | |||
653 | */ | 715 | */ |
654 | while (1) { | 716 | while (1) { |
655 | lp = ubifs_fast_find_freeable(c); | 717 | lp = ubifs_fast_find_freeable(c); |
656 | if (unlikely(IS_ERR(lp))) { | 718 | if (IS_ERR(lp)) { |
657 | err = PTR_ERR(lp); | 719 | err = PTR_ERR(lp); |
658 | goto out; | 720 | goto out; |
659 | } | 721 | } |
@@ -665,7 +727,7 @@ int ubifs_gc_start_commit(struct ubifs_info *c) | |||
665 | if (err) | 727 | if (err) |
666 | goto out; | 728 | goto out; |
667 | lp = ubifs_change_lp(c, lp, c->leb_size, 0, lp->flags, 0); | 729 | lp = ubifs_change_lp(c, lp, c->leb_size, 0, lp->flags, 0); |
668 | if (unlikely(IS_ERR(lp))) { | 730 | if (IS_ERR(lp)) { |
669 | err = PTR_ERR(lp); | 731 | err = PTR_ERR(lp); |
670 | goto out; | 732 | goto out; |
671 | } | 733 | } |
@@ -680,7 +742,7 @@ int ubifs_gc_start_commit(struct ubifs_info *c) | |||
680 | /* Record index freeable LEBs for unmapping after commit */ | 742 | /* Record index freeable LEBs for unmapping after commit */ |
681 | while (1) { | 743 | while (1) { |
682 | lp = ubifs_fast_find_frdi_idx(c); | 744 | lp = ubifs_fast_find_frdi_idx(c); |
683 | if (unlikely(IS_ERR(lp))) { | 745 | if (IS_ERR(lp)) { |
684 | err = PTR_ERR(lp); | 746 | err = PTR_ERR(lp); |
685 | goto out; | 747 | goto out; |
686 | } | 748 | } |
@@ -696,7 +758,7 @@ int ubifs_gc_start_commit(struct ubifs_info *c) | |||
696 | /* Don't release the LEB until after the next commit */ | 758 | /* Don't release the LEB until after the next commit */ |
697 | flags = (lp->flags | LPROPS_TAKEN) ^ LPROPS_INDEX; | 759 | flags = (lp->flags | LPROPS_TAKEN) ^ LPROPS_INDEX; |
698 | lp = ubifs_change_lp(c, lp, c->leb_size, 0, flags, 1); | 760 | lp = ubifs_change_lp(c, lp, c->leb_size, 0, flags, 1); |
699 | if (unlikely(IS_ERR(lp))) { | 761 | if (IS_ERR(lp)) { |
700 | err = PTR_ERR(lp); | 762 | err = PTR_ERR(lp); |
701 | kfree(idx_gc); | 763 | kfree(idx_gc); |
702 | goto out; | 764 | goto out; |
diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index 054363f2b207..01682713af69 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c | |||
@@ -62,6 +62,7 @@ void ubifs_ro_mode(struct ubifs_info *c, int err) | |||
62 | { | 62 | { |
63 | if (!c->ro_media) { | 63 | if (!c->ro_media) { |
64 | c->ro_media = 1; | 64 | c->ro_media = 1; |
65 | c->no_chk_data_crc = 0; | ||
65 | ubifs_warn("switched to read-only mode, error %d", err); | 66 | ubifs_warn("switched to read-only mode, error %d", err); |
66 | dbg_dump_stack(); | 67 | dbg_dump_stack(); |
67 | } | 68 | } |
@@ -74,6 +75,7 @@ void ubifs_ro_mode(struct ubifs_info *c, int err) | |||
74 | * @lnum: logical eraseblock number | 75 | * @lnum: logical eraseblock number |
75 | * @offs: offset within the logical eraseblock | 76 | * @offs: offset within the logical eraseblock |
76 | * @quiet: print no messages | 77 | * @quiet: print no messages |
78 | * @chk_crc: indicates whether to always check the CRC | ||
77 | * | 79 | * |
78 | * This function checks node magic number and CRC checksum. This function also | 80 | * This function checks node magic number and CRC checksum. This function also |
79 | * validates node length to prevent UBIFS from becoming crazy when an attacker | 81 | * validates node length to prevent UBIFS from becoming crazy when an attacker |
@@ -85,7 +87,7 @@ void ubifs_ro_mode(struct ubifs_info *c, int err) | |||
85 | * or magic. | 87 | * or magic. |
86 | */ | 88 | */ |
87 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, | 89 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, |
88 | int offs, int quiet) | 90 | int offs, int quiet, int chk_crc) |
89 | { | 91 | { |
90 | int err = -EINVAL, type, node_len; | 92 | int err = -EINVAL, type, node_len; |
91 | uint32_t crc, node_crc, magic; | 93 | uint32_t crc, node_crc, magic; |
@@ -121,6 +123,10 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, | |||
121 | node_len > c->ranges[type].max_len) | 123 | node_len > c->ranges[type].max_len) |
122 | goto out_len; | 124 | goto out_len; |
123 | 125 | ||
126 | if (!chk_crc && type == UBIFS_DATA_NODE && !c->always_chk_crc) | ||
127 | if (c->no_chk_data_crc) | ||
128 | return 0; | ||
129 | |||
124 | crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); | 130 | crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); |
125 | node_crc = le32_to_cpu(ch->crc); | 131 | node_crc = le32_to_cpu(ch->crc); |
126 | if (crc != node_crc) { | 132 | if (crc != node_crc) { |
@@ -722,7 +728,7 @@ int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, | |||
722 | goto out; | 728 | goto out; |
723 | } | 729 | } |
724 | 730 | ||
725 | err = ubifs_check_node(c, buf, lnum, offs, 0); | 731 | err = ubifs_check_node(c, buf, lnum, offs, 0, 0); |
726 | if (err) { | 732 | if (err) { |
727 | ubifs_err("expected node type %d", type); | 733 | ubifs_err("expected node type %d", type); |
728 | return err; | 734 | return err; |
@@ -781,7 +787,7 @@ int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len, | |||
781 | goto out; | 787 | goto out; |
782 | } | 788 | } |
783 | 789 | ||
784 | err = ubifs_check_node(c, buf, lnum, offs, 0); | 790 | err = ubifs_check_node(c, buf, lnum, offs, 0, 0); |
785 | if (err) { | 791 | if (err) { |
786 | ubifs_err("expected node type %d", type); | 792 | ubifs_err("expected node type %d", type); |
787 | return err; | 793 | return err; |
diff --git a/fs/ubifs/key.h b/fs/ubifs/key.h index 8f7476007549..9ee65086f627 100644 --- a/fs/ubifs/key.h +++ b/fs/ubifs/key.h | |||
@@ -484,7 +484,7 @@ static inline void key_copy(const struct ubifs_info *c, | |||
484 | * @key2: the second key to compare | 484 | * @key2: the second key to compare |
485 | * | 485 | * |
486 | * This function compares 2 keys and returns %-1 if @key1 is less than | 486 | * This function compares 2 keys and returns %-1 if @key1 is less than |
487 | * @key2, 0 if the keys are equivalent and %1 if @key1 is greater than @key2. | 487 | * @key2, %0 if the keys are equivalent and %1 if @key1 is greater than @key2. |
488 | */ | 488 | */ |
489 | static inline int keys_cmp(const struct ubifs_info *c, | 489 | static inline int keys_cmp(const struct ubifs_info *c, |
490 | const union ubifs_key *key1, | 490 | const union ubifs_key *key1, |
@@ -503,6 +503,26 @@ static inline int keys_cmp(const struct ubifs_info *c, | |||
503 | } | 503 | } |
504 | 504 | ||
505 | /** | 505 | /** |
506 | * keys_eq - determine if keys are equivalent. | ||
507 | * @c: UBIFS file-system description object | ||
508 | * @key1: the first key to compare | ||
509 | * @key2: the second key to compare | ||
510 | * | ||
511 | * This function compares 2 keys and returns %1 if @key1 is equal to @key2 and | ||
512 | * %0 if not. | ||
513 | */ | ||
514 | static inline int keys_eq(const struct ubifs_info *c, | ||
515 | const union ubifs_key *key1, | ||
516 | const union ubifs_key *key2) | ||
517 | { | ||
518 | if (key1->u32[0] != key2->u32[0]) | ||
519 | return 0; | ||
520 | if (key1->u32[1] != key2->u32[1]) | ||
521 | return 0; | ||
522 | return 1; | ||
523 | } | ||
524 | |||
525 | /** | ||
506 | * is_hash_key - is a key vulnerable to hash collisions. | 526 | * is_hash_key - is a key vulnerable to hash collisions. |
507 | * @c: UBIFS file-system description object | 527 | * @c: UBIFS file-system description object |
508 | * @key: key | 528 | * @key: key |
diff --git a/fs/ubifs/lprops.c b/fs/ubifs/lprops.c index 2ba93da71b65..f27176e9b70d 100644 --- a/fs/ubifs/lprops.c +++ b/fs/ubifs/lprops.c | |||
@@ -125,6 +125,7 @@ static void adjust_lpt_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, | |||
125 | } | 125 | } |
126 | } | 126 | } |
127 | } | 127 | } |
128 | |||
128 | /* Not greater than parent, so compare to children */ | 129 | /* Not greater than parent, so compare to children */ |
129 | while (1) { | 130 | while (1) { |
130 | /* Compare to left child */ | 131 | /* Compare to left child */ |
@@ -460,18 +461,6 @@ static void change_category(struct ubifs_info *c, struct ubifs_lprops *lprops) | |||
460 | } | 461 | } |
461 | 462 | ||
462 | /** | 463 | /** |
463 | * ubifs_get_lprops - get reference to LEB properties. | ||
464 | * @c: the UBIFS file-system description object | ||
465 | * | ||
466 | * This function locks lprops. Lprops have to be unlocked by | ||
467 | * 'ubifs_release_lprops()'. | ||
468 | */ | ||
469 | void ubifs_get_lprops(struct ubifs_info *c) | ||
470 | { | ||
471 | mutex_lock(&c->lp_mutex); | ||
472 | } | ||
473 | |||
474 | /** | ||
475 | * calc_dark - calculate LEB dark space size. | 464 | * calc_dark - calculate LEB dark space size. |
476 | * @c: the UBIFS file-system description object | 465 | * @c: the UBIFS file-system description object |
477 | * @spc: amount of free and dirty space in the LEB | 466 | * @spc: amount of free and dirty space in the LEB |
@@ -576,7 +565,6 @@ const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, | |||
576 | ubifs_assert(!(lprops->free & 7) && !(lprops->dirty & 7)); | 565 | ubifs_assert(!(lprops->free & 7) && !(lprops->dirty & 7)); |
577 | 566 | ||
578 | spin_lock(&c->space_lock); | 567 | spin_lock(&c->space_lock); |
579 | |||
580 | if ((lprops->flags & LPROPS_TAKEN) && lprops->free == c->leb_size) | 568 | if ((lprops->flags & LPROPS_TAKEN) && lprops->free == c->leb_size) |
581 | c->lst.taken_empty_lebs -= 1; | 569 | c->lst.taken_empty_lebs -= 1; |
582 | 570 | ||
@@ -637,31 +625,12 @@ const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, | |||
637 | c->lst.taken_empty_lebs += 1; | 625 | c->lst.taken_empty_lebs += 1; |
638 | 626 | ||
639 | change_category(c, lprops); | 627 | change_category(c, lprops); |
640 | |||
641 | c->idx_gc_cnt += idx_gc_cnt; | 628 | c->idx_gc_cnt += idx_gc_cnt; |
642 | |||
643 | spin_unlock(&c->space_lock); | 629 | spin_unlock(&c->space_lock); |
644 | |||
645 | return lprops; | 630 | return lprops; |
646 | } | 631 | } |
647 | 632 | ||
648 | /** | 633 | /** |
649 | * ubifs_release_lprops - release lprops lock. | ||
650 | * @c: the UBIFS file-system description object | ||
651 | * | ||
652 | * This function has to be called after each 'ubifs_get_lprops()' call to | ||
653 | * unlock lprops. | ||
654 | */ | ||
655 | void ubifs_release_lprops(struct ubifs_info *c) | ||
656 | { | ||
657 | ubifs_assert(mutex_is_locked(&c->lp_mutex)); | ||
658 | ubifs_assert(c->lst.empty_lebs >= 0 && | ||
659 | c->lst.empty_lebs <= c->main_lebs); | ||
660 | |||
661 | mutex_unlock(&c->lp_mutex); | ||
662 | } | ||
663 | |||
664 | /** | ||
665 | * ubifs_get_lp_stats - get lprops statistics. | 634 | * ubifs_get_lp_stats - get lprops statistics. |
666 | * @c: UBIFS file-system description object | 635 | * @c: UBIFS file-system description object |
667 | * @st: return statistics | 636 | * @st: return statistics |
@@ -1262,7 +1231,6 @@ static int scan_check_cb(struct ubifs_info *c, | |||
1262 | } | 1231 | } |
1263 | 1232 | ||
1264 | ubifs_scan_destroy(sleb); | 1233 | ubifs_scan_destroy(sleb); |
1265 | |||
1266 | return LPT_SCAN_CONTINUE; | 1234 | return LPT_SCAN_CONTINUE; |
1267 | 1235 | ||
1268 | out_print: | 1236 | out_print: |
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c index 9ff2463177e5..db8bd0e518b2 100644 --- a/fs/ubifs/lpt.c +++ b/fs/ubifs/lpt.c | |||
@@ -109,7 +109,8 @@ static void do_calc_lpt_geom(struct ubifs_info *c) | |||
109 | c->lpt_sz = (long long)c->pnode_cnt * c->pnode_sz; | 109 | c->lpt_sz = (long long)c->pnode_cnt * c->pnode_sz; |
110 | c->lpt_sz += (long long)c->nnode_cnt * c->nnode_sz; | 110 | c->lpt_sz += (long long)c->nnode_cnt * c->nnode_sz; |
111 | c->lpt_sz += c->ltab_sz; | 111 | c->lpt_sz += c->ltab_sz; |
112 | c->lpt_sz += c->lsave_sz; | 112 | if (c->big_lpt) |
113 | c->lpt_sz += c->lsave_sz; | ||
113 | 114 | ||
114 | /* Add wastage */ | 115 | /* Add wastage */ |
115 | sz = c->lpt_sz; | 116 | sz = c->lpt_sz; |
@@ -287,25 +288,56 @@ uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits) | |||
287 | const int k = 32 - nrbits; | 288 | const int k = 32 - nrbits; |
288 | uint8_t *p = *addr; | 289 | uint8_t *p = *addr; |
289 | int b = *pos; | 290 | int b = *pos; |
290 | uint32_t val; | 291 | uint32_t uninitialized_var(val); |
292 | const int bytes = (nrbits + b + 7) >> 3; | ||
291 | 293 | ||
292 | ubifs_assert(nrbits > 0); | 294 | ubifs_assert(nrbits > 0); |
293 | ubifs_assert(nrbits <= 32); | 295 | ubifs_assert(nrbits <= 32); |
294 | ubifs_assert(*pos >= 0); | 296 | ubifs_assert(*pos >= 0); |
295 | ubifs_assert(*pos < 8); | 297 | ubifs_assert(*pos < 8); |
296 | if (b) { | 298 | if (b) { |
297 | val = p[1] | ((uint32_t)p[2] << 8) | ((uint32_t)p[3] << 16) | | 299 | switch (bytes) { |
298 | ((uint32_t)p[4] << 24); | 300 | case 2: |
301 | val = p[1]; | ||
302 | break; | ||
303 | case 3: | ||
304 | val = p[1] | ((uint32_t)p[2] << 8); | ||
305 | break; | ||
306 | case 4: | ||
307 | val = p[1] | ((uint32_t)p[2] << 8) | | ||
308 | ((uint32_t)p[3] << 16); | ||
309 | break; | ||
310 | case 5: | ||
311 | val = p[1] | ((uint32_t)p[2] << 8) | | ||
312 | ((uint32_t)p[3] << 16) | | ||
313 | ((uint32_t)p[4] << 24); | ||
314 | } | ||
299 | val <<= (8 - b); | 315 | val <<= (8 - b); |
300 | val |= *p >> b; | 316 | val |= *p >> b; |
301 | nrbits += b; | 317 | nrbits += b; |
302 | } else | 318 | } else { |
303 | val = p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | | 319 | switch (bytes) { |
304 | ((uint32_t)p[3] << 24); | 320 | case 1: |
321 | val = p[0]; | ||
322 | break; | ||
323 | case 2: | ||
324 | val = p[0] | ((uint32_t)p[1] << 8); | ||
325 | break; | ||
326 | case 3: | ||
327 | val = p[0] | ((uint32_t)p[1] << 8) | | ||
328 | ((uint32_t)p[2] << 16); | ||
329 | break; | ||
330 | case 4: | ||
331 | val = p[0] | ((uint32_t)p[1] << 8) | | ||
332 | ((uint32_t)p[2] << 16) | | ||
333 | ((uint32_t)p[3] << 24); | ||
334 | break; | ||
335 | } | ||
336 | } | ||
305 | val <<= k; | 337 | val <<= k; |
306 | val >>= k; | 338 | val >>= k; |
307 | b = nrbits & 7; | 339 | b = nrbits & 7; |
308 | p += nrbits / 8; | 340 | p += nrbits >> 3; |
309 | *addr = p; | 341 | *addr = p; |
310 | *pos = b; | 342 | *pos = b; |
311 | ubifs_assert((val >> nrbits) == 0 || nrbits - b == 32); | 343 | ubifs_assert((val >> nrbits) == 0 || nrbits - b == 32); |
diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c index 5f0b83e20af6..eed5a0025d63 100644 --- a/fs/ubifs/lpt_commit.c +++ b/fs/ubifs/lpt_commit.c | |||
@@ -177,8 +177,6 @@ static int alloc_lpt_leb(struct ubifs_info *c, int *lnum) | |||
177 | return 0; | 177 | return 0; |
178 | } | 178 | } |
179 | } | 179 | } |
180 | dbg_err("last LEB %d", *lnum); | ||
181 | dump_stack(); | ||
182 | return -ENOSPC; | 180 | return -ENOSPC; |
183 | } | 181 | } |
184 | 182 | ||
@@ -193,6 +191,9 @@ static int layout_cnodes(struct ubifs_info *c) | |||
193 | int lnum, offs, len, alen, done_lsave, done_ltab, err; | 191 | int lnum, offs, len, alen, done_lsave, done_ltab, err; |
194 | struct ubifs_cnode *cnode; | 192 | struct ubifs_cnode *cnode; |
195 | 193 | ||
194 | err = dbg_chk_lpt_sz(c, 0, 0); | ||
195 | if (err) | ||
196 | return err; | ||
196 | cnode = c->lpt_cnext; | 197 | cnode = c->lpt_cnext; |
197 | if (!cnode) | 198 | if (!cnode) |
198 | return 0; | 199 | return 0; |
@@ -206,6 +207,7 @@ static int layout_cnodes(struct ubifs_info *c) | |||
206 | c->lsave_lnum = lnum; | 207 | c->lsave_lnum = lnum; |
207 | c->lsave_offs = offs; | 208 | c->lsave_offs = offs; |
208 | offs += c->lsave_sz; | 209 | offs += c->lsave_sz; |
210 | dbg_chk_lpt_sz(c, 1, c->lsave_sz); | ||
209 | } | 211 | } |
210 | 212 | ||
211 | if (offs + c->ltab_sz <= c->leb_size) { | 213 | if (offs + c->ltab_sz <= c->leb_size) { |
@@ -213,6 +215,7 @@ static int layout_cnodes(struct ubifs_info *c) | |||
213 | c->ltab_lnum = lnum; | 215 | c->ltab_lnum = lnum; |
214 | c->ltab_offs = offs; | 216 | c->ltab_offs = offs; |
215 | offs += c->ltab_sz; | 217 | offs += c->ltab_sz; |
218 | dbg_chk_lpt_sz(c, 1, c->ltab_sz); | ||
216 | } | 219 | } |
217 | 220 | ||
218 | do { | 221 | do { |
@@ -226,9 +229,10 @@ static int layout_cnodes(struct ubifs_info *c) | |||
226 | while (offs + len > c->leb_size) { | 229 | while (offs + len > c->leb_size) { |
227 | alen = ALIGN(offs, c->min_io_size); | 230 | alen = ALIGN(offs, c->min_io_size); |
228 | upd_ltab(c, lnum, c->leb_size - alen, alen - offs); | 231 | upd_ltab(c, lnum, c->leb_size - alen, alen - offs); |
232 | dbg_chk_lpt_sz(c, 2, alen - offs); | ||
229 | err = alloc_lpt_leb(c, &lnum); | 233 | err = alloc_lpt_leb(c, &lnum); |
230 | if (err) | 234 | if (err) |
231 | return err; | 235 | goto no_space; |
232 | offs = 0; | 236 | offs = 0; |
233 | ubifs_assert(lnum >= c->lpt_first && | 237 | ubifs_assert(lnum >= c->lpt_first && |
234 | lnum <= c->lpt_last); | 238 | lnum <= c->lpt_last); |
@@ -238,6 +242,7 @@ static int layout_cnodes(struct ubifs_info *c) | |||
238 | c->lsave_lnum = lnum; | 242 | c->lsave_lnum = lnum; |
239 | c->lsave_offs = offs; | 243 | c->lsave_offs = offs; |
240 | offs += c->lsave_sz; | 244 | offs += c->lsave_sz; |
245 | dbg_chk_lpt_sz(c, 1, c->lsave_sz); | ||
241 | continue; | 246 | continue; |
242 | } | 247 | } |
243 | if (!done_ltab) { | 248 | if (!done_ltab) { |
@@ -245,6 +250,7 @@ static int layout_cnodes(struct ubifs_info *c) | |||
245 | c->ltab_lnum = lnum; | 250 | c->ltab_lnum = lnum; |
246 | c->ltab_offs = offs; | 251 | c->ltab_offs = offs; |
247 | offs += c->ltab_sz; | 252 | offs += c->ltab_sz; |
253 | dbg_chk_lpt_sz(c, 1, c->ltab_sz); | ||
248 | continue; | 254 | continue; |
249 | } | 255 | } |
250 | break; | 256 | break; |
@@ -257,6 +263,7 @@ static int layout_cnodes(struct ubifs_info *c) | |||
257 | c->lpt_offs = offs; | 263 | c->lpt_offs = offs; |
258 | } | 264 | } |
259 | offs += len; | 265 | offs += len; |
266 | dbg_chk_lpt_sz(c, 1, len); | ||
260 | cnode = cnode->cnext; | 267 | cnode = cnode->cnext; |
261 | } while (cnode && cnode != c->lpt_cnext); | 268 | } while (cnode && cnode != c->lpt_cnext); |
262 | 269 | ||
@@ -265,9 +272,10 @@ static int layout_cnodes(struct ubifs_info *c) | |||
265 | if (offs + c->lsave_sz > c->leb_size) { | 272 | if (offs + c->lsave_sz > c->leb_size) { |
266 | alen = ALIGN(offs, c->min_io_size); | 273 | alen = ALIGN(offs, c->min_io_size); |
267 | upd_ltab(c, lnum, c->leb_size - alen, alen - offs); | 274 | upd_ltab(c, lnum, c->leb_size - alen, alen - offs); |
275 | dbg_chk_lpt_sz(c, 2, alen - offs); | ||
268 | err = alloc_lpt_leb(c, &lnum); | 276 | err = alloc_lpt_leb(c, &lnum); |
269 | if (err) | 277 | if (err) |
270 | return err; | 278 | goto no_space; |
271 | offs = 0; | 279 | offs = 0; |
272 | ubifs_assert(lnum >= c->lpt_first && | 280 | ubifs_assert(lnum >= c->lpt_first && |
273 | lnum <= c->lpt_last); | 281 | lnum <= c->lpt_last); |
@@ -276,6 +284,7 @@ static int layout_cnodes(struct ubifs_info *c) | |||
276 | c->lsave_lnum = lnum; | 284 | c->lsave_lnum = lnum; |
277 | c->lsave_offs = offs; | 285 | c->lsave_offs = offs; |
278 | offs += c->lsave_sz; | 286 | offs += c->lsave_sz; |
287 | dbg_chk_lpt_sz(c, 1, c->lsave_sz); | ||
279 | } | 288 | } |
280 | 289 | ||
281 | /* Make sure to place LPT's own lprops table */ | 290 | /* Make sure to place LPT's own lprops table */ |
@@ -283,9 +292,10 @@ static int layout_cnodes(struct ubifs_info *c) | |||
283 | if (offs + c->ltab_sz > c->leb_size) { | 292 | if (offs + c->ltab_sz > c->leb_size) { |
284 | alen = ALIGN(offs, c->min_io_size); | 293 | alen = ALIGN(offs, c->min_io_size); |
285 | upd_ltab(c, lnum, c->leb_size - alen, alen - offs); | 294 | upd_ltab(c, lnum, c->leb_size - alen, alen - offs); |
295 | dbg_chk_lpt_sz(c, 2, alen - offs); | ||
286 | err = alloc_lpt_leb(c, &lnum); | 296 | err = alloc_lpt_leb(c, &lnum); |
287 | if (err) | 297 | if (err) |
288 | return err; | 298 | goto no_space; |
289 | offs = 0; | 299 | offs = 0; |
290 | ubifs_assert(lnum >= c->lpt_first && | 300 | ubifs_assert(lnum >= c->lpt_first && |
291 | lnum <= c->lpt_last); | 301 | lnum <= c->lpt_last); |
@@ -294,11 +304,23 @@ static int layout_cnodes(struct ubifs_info *c) | |||
294 | c->ltab_lnum = lnum; | 304 | c->ltab_lnum = lnum; |
295 | c->ltab_offs = offs; | 305 | c->ltab_offs = offs; |
296 | offs += c->ltab_sz; | 306 | offs += c->ltab_sz; |
307 | dbg_chk_lpt_sz(c, 1, c->ltab_sz); | ||
297 | } | 308 | } |
298 | 309 | ||
299 | alen = ALIGN(offs, c->min_io_size); | 310 | alen = ALIGN(offs, c->min_io_size); |
300 | upd_ltab(c, lnum, c->leb_size - alen, alen - offs); | 311 | upd_ltab(c, lnum, c->leb_size - alen, alen - offs); |
312 | dbg_chk_lpt_sz(c, 4, alen - offs); | ||
313 | err = dbg_chk_lpt_sz(c, 3, alen); | ||
314 | if (err) | ||
315 | return err; | ||
301 | return 0; | 316 | return 0; |
317 | |||
318 | no_space: | ||
319 | ubifs_err("LPT out of space"); | ||
320 | dbg_err("LPT out of space at LEB %d:%d needing %d, done_ltab %d, " | ||
321 | "done_lsave %d", lnum, offs, len, done_ltab, done_lsave); | ||
322 | dbg_dump_lpt_info(c); | ||
323 | return err; | ||
302 | } | 324 | } |
303 | 325 | ||
304 | /** | 326 | /** |
@@ -333,8 +355,6 @@ static int realloc_lpt_leb(struct ubifs_info *c, int *lnum) | |||
333 | *lnum = i + c->lpt_first; | 355 | *lnum = i + c->lpt_first; |
334 | return 0; | 356 | return 0; |
335 | } | 357 | } |
336 | dbg_err("last LEB %d", *lnum); | ||
337 | dump_stack(); | ||
338 | return -ENOSPC; | 358 | return -ENOSPC; |
339 | } | 359 | } |
340 | 360 | ||
@@ -369,12 +389,14 @@ static int write_cnodes(struct ubifs_info *c) | |||
369 | done_lsave = 1; | 389 | done_lsave = 1; |
370 | ubifs_pack_lsave(c, buf + offs, c->lsave); | 390 | ubifs_pack_lsave(c, buf + offs, c->lsave); |
371 | offs += c->lsave_sz; | 391 | offs += c->lsave_sz; |
392 | dbg_chk_lpt_sz(c, 1, c->lsave_sz); | ||
372 | } | 393 | } |
373 | 394 | ||
374 | if (offs + c->ltab_sz <= c->leb_size) { | 395 | if (offs + c->ltab_sz <= c->leb_size) { |
375 | done_ltab = 1; | 396 | done_ltab = 1; |
376 | ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); | 397 | ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); |
377 | offs += c->ltab_sz; | 398 | offs += c->ltab_sz; |
399 | dbg_chk_lpt_sz(c, 1, c->ltab_sz); | ||
378 | } | 400 | } |
379 | 401 | ||
380 | /* Loop for each cnode */ | 402 | /* Loop for each cnode */ |
@@ -392,10 +414,12 @@ static int write_cnodes(struct ubifs_info *c) | |||
392 | alen, UBI_SHORTTERM); | 414 | alen, UBI_SHORTTERM); |
393 | if (err) | 415 | if (err) |
394 | return err; | 416 | return err; |
417 | dbg_chk_lpt_sz(c, 4, alen - wlen); | ||
395 | } | 418 | } |
419 | dbg_chk_lpt_sz(c, 2, 0); | ||
396 | err = realloc_lpt_leb(c, &lnum); | 420 | err = realloc_lpt_leb(c, &lnum); |
397 | if (err) | 421 | if (err) |
398 | return err; | 422 | goto no_space; |
399 | offs = 0; | 423 | offs = 0; |
400 | from = 0; | 424 | from = 0; |
401 | ubifs_assert(lnum >= c->lpt_first && | 425 | ubifs_assert(lnum >= c->lpt_first && |
@@ -408,12 +432,14 @@ static int write_cnodes(struct ubifs_info *c) | |||
408 | done_lsave = 1; | 432 | done_lsave = 1; |
409 | ubifs_pack_lsave(c, buf + offs, c->lsave); | 433 | ubifs_pack_lsave(c, buf + offs, c->lsave); |
410 | offs += c->lsave_sz; | 434 | offs += c->lsave_sz; |
435 | dbg_chk_lpt_sz(c, 1, c->lsave_sz); | ||
411 | continue; | 436 | continue; |
412 | } | 437 | } |
413 | if (!done_ltab) { | 438 | if (!done_ltab) { |
414 | done_ltab = 1; | 439 | done_ltab = 1; |
415 | ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); | 440 | ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); |
416 | offs += c->ltab_sz; | 441 | offs += c->ltab_sz; |
442 | dbg_chk_lpt_sz(c, 1, c->ltab_sz); | ||
417 | continue; | 443 | continue; |
418 | } | 444 | } |
419 | break; | 445 | break; |
@@ -435,6 +461,7 @@ static int write_cnodes(struct ubifs_info *c) | |||
435 | clear_bit(COW_ZNODE, &cnode->flags); | 461 | clear_bit(COW_ZNODE, &cnode->flags); |
436 | smp_mb__after_clear_bit(); | 462 | smp_mb__after_clear_bit(); |
437 | offs += len; | 463 | offs += len; |
464 | dbg_chk_lpt_sz(c, 1, len); | ||
438 | cnode = cnode->cnext; | 465 | cnode = cnode->cnext; |
439 | } while (cnode && cnode != c->lpt_cnext); | 466 | } while (cnode && cnode != c->lpt_cnext); |
440 | 467 | ||
@@ -448,9 +475,10 @@ static int write_cnodes(struct ubifs_info *c) | |||
448 | UBI_SHORTTERM); | 475 | UBI_SHORTTERM); |
449 | if (err) | 476 | if (err) |
450 | return err; | 477 | return err; |
478 | dbg_chk_lpt_sz(c, 2, alen - wlen); | ||
451 | err = realloc_lpt_leb(c, &lnum); | 479 | err = realloc_lpt_leb(c, &lnum); |
452 | if (err) | 480 | if (err) |
453 | return err; | 481 | goto no_space; |
454 | offs = 0; | 482 | offs = 0; |
455 | ubifs_assert(lnum >= c->lpt_first && | 483 | ubifs_assert(lnum >= c->lpt_first && |
456 | lnum <= c->lpt_last); | 484 | lnum <= c->lpt_last); |
@@ -461,6 +489,7 @@ static int write_cnodes(struct ubifs_info *c) | |||
461 | done_lsave = 1; | 489 | done_lsave = 1; |
462 | ubifs_pack_lsave(c, buf + offs, c->lsave); | 490 | ubifs_pack_lsave(c, buf + offs, c->lsave); |
463 | offs += c->lsave_sz; | 491 | offs += c->lsave_sz; |
492 | dbg_chk_lpt_sz(c, 1, c->lsave_sz); | ||
464 | } | 493 | } |
465 | 494 | ||
466 | /* Make sure to place LPT's own lprops table */ | 495 | /* Make sure to place LPT's own lprops table */ |
@@ -473,9 +502,10 @@ static int write_cnodes(struct ubifs_info *c) | |||
473 | UBI_SHORTTERM); | 502 | UBI_SHORTTERM); |
474 | if (err) | 503 | if (err) |
475 | return err; | 504 | return err; |
505 | dbg_chk_lpt_sz(c, 2, alen - wlen); | ||
476 | err = realloc_lpt_leb(c, &lnum); | 506 | err = realloc_lpt_leb(c, &lnum); |
477 | if (err) | 507 | if (err) |
478 | return err; | 508 | goto no_space; |
479 | offs = 0; | 509 | offs = 0; |
480 | ubifs_assert(lnum >= c->lpt_first && | 510 | ubifs_assert(lnum >= c->lpt_first && |
481 | lnum <= c->lpt_last); | 511 | lnum <= c->lpt_last); |
@@ -486,6 +516,7 @@ static int write_cnodes(struct ubifs_info *c) | |||
486 | done_ltab = 1; | 516 | done_ltab = 1; |
487 | ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); | 517 | ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); |
488 | offs += c->ltab_sz; | 518 | offs += c->ltab_sz; |
519 | dbg_chk_lpt_sz(c, 1, c->ltab_sz); | ||
489 | } | 520 | } |
490 | 521 | ||
491 | /* Write remaining data in buffer */ | 522 | /* Write remaining data in buffer */ |
@@ -495,6 +526,12 @@ static int write_cnodes(struct ubifs_info *c) | |||
495 | err = ubifs_leb_write(c, lnum, buf + from, from, alen, UBI_SHORTTERM); | 526 | err = ubifs_leb_write(c, lnum, buf + from, from, alen, UBI_SHORTTERM); |
496 | if (err) | 527 | if (err) |
497 | return err; | 528 | return err; |
529 | |||
530 | dbg_chk_lpt_sz(c, 4, alen - wlen); | ||
531 | err = dbg_chk_lpt_sz(c, 3, ALIGN(offs, c->min_io_size)); | ||
532 | if (err) | ||
533 | return err; | ||
534 | |||
498 | c->nhead_lnum = lnum; | 535 | c->nhead_lnum = lnum; |
499 | c->nhead_offs = ALIGN(offs, c->min_io_size); | 536 | c->nhead_offs = ALIGN(offs, c->min_io_size); |
500 | 537 | ||
@@ -503,7 +540,15 @@ static int write_cnodes(struct ubifs_info *c) | |||
503 | dbg_lp("LPT ltab is at %d:%d", c->ltab_lnum, c->ltab_offs); | 540 | dbg_lp("LPT ltab is at %d:%d", c->ltab_lnum, c->ltab_offs); |
504 | if (c->big_lpt) | 541 | if (c->big_lpt) |
505 | dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs); | 542 | dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs); |
543 | |||
506 | return 0; | 544 | return 0; |
545 | |||
546 | no_space: | ||
547 | ubifs_err("LPT out of space mismatch"); | ||
548 | dbg_err("LPT out of space mismatch at LEB %d:%d needing %d, done_ltab " | ||
549 | "%d, done_lsave %d", lnum, offs, len, done_ltab, done_lsave); | ||
550 | dbg_dump_lpt_info(c); | ||
551 | return err; | ||
507 | } | 552 | } |
508 | 553 | ||
509 | /** | 554 | /** |
@@ -1044,6 +1089,8 @@ static int is_a_node(struct ubifs_info *c, uint8_t *buf, int len) | |||
1044 | int pos = 0, node_type, node_len; | 1089 | int pos = 0, node_type, node_len; |
1045 | uint16_t crc, calc_crc; | 1090 | uint16_t crc, calc_crc; |
1046 | 1091 | ||
1092 | if (len < UBIFS_LPT_CRC_BYTES + (UBIFS_LPT_TYPE_BITS + 7) / 8) | ||
1093 | return 0; | ||
1047 | node_type = ubifs_unpack_bits(&addr, &pos, UBIFS_LPT_TYPE_BITS); | 1094 | node_type = ubifs_unpack_bits(&addr, &pos, UBIFS_LPT_TYPE_BITS); |
1048 | if (node_type == UBIFS_LPT_NOT_A_NODE) | 1095 | if (node_type == UBIFS_LPT_NOT_A_NODE) |
1049 | return 0; | 1096 | return 0; |
@@ -1156,6 +1203,9 @@ int ubifs_lpt_start_commit(struct ubifs_info *c) | |||
1156 | dbg_lp(""); | 1203 | dbg_lp(""); |
1157 | 1204 | ||
1158 | mutex_lock(&c->lp_mutex); | 1205 | mutex_lock(&c->lp_mutex); |
1206 | err = dbg_chk_lpt_free_spc(c); | ||
1207 | if (err) | ||
1208 | goto out; | ||
1159 | err = dbg_check_ltab(c); | 1209 | err = dbg_check_ltab(c); |
1160 | if (err) | 1210 | if (err) |
1161 | goto out; | 1211 | goto out; |
@@ -1645,4 +1695,121 @@ int dbg_check_ltab(struct ubifs_info *c) | |||
1645 | return 0; | 1695 | return 0; |
1646 | } | 1696 | } |
1647 | 1697 | ||
1698 | /** | ||
1699 | * dbg_chk_lpt_free_spc - check LPT free space is enough to write entire LPT. | ||
1700 | * @c: the UBIFS file-system description object | ||
1701 | * | ||
1702 | * This function returns %0 on success and a negative error code on failure. | ||
1703 | */ | ||
1704 | int dbg_chk_lpt_free_spc(struct ubifs_info *c) | ||
1705 | { | ||
1706 | long long free = 0; | ||
1707 | int i; | ||
1708 | |||
1709 | for (i = 0; i < c->lpt_lebs; i++) { | ||
1710 | if (c->ltab[i].tgc || c->ltab[i].cmt) | ||
1711 | continue; | ||
1712 | if (i + c->lpt_first == c->nhead_lnum) | ||
1713 | free += c->leb_size - c->nhead_offs; | ||
1714 | else if (c->ltab[i].free == c->leb_size) | ||
1715 | free += c->leb_size; | ||
1716 | } | ||
1717 | if (free < c->lpt_sz) { | ||
1718 | dbg_err("LPT space error: free %lld lpt_sz %lld", | ||
1719 | free, c->lpt_sz); | ||
1720 | dbg_dump_lpt_info(c); | ||
1721 | return -EINVAL; | ||
1722 | } | ||
1723 | return 0; | ||
1724 | } | ||
1725 | |||
1726 | /** | ||
1727 | * dbg_chk_lpt_sz - check LPT does not write more than LPT size. | ||
1728 | * @c: the UBIFS file-system description object | ||
1729 | * @action: action | ||
1730 | * @len: length written | ||
1731 | * | ||
1732 | * This function returns %0 on success and a negative error code on failure. | ||
1733 | */ | ||
1734 | int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) | ||
1735 | { | ||
1736 | long long chk_lpt_sz, lpt_sz; | ||
1737 | int err = 0; | ||
1738 | |||
1739 | switch (action) { | ||
1740 | case 0: | ||
1741 | c->chk_lpt_sz = 0; | ||
1742 | c->chk_lpt_sz2 = 0; | ||
1743 | c->chk_lpt_lebs = 0; | ||
1744 | c->chk_lpt_wastage = 0; | ||
1745 | if (c->dirty_pn_cnt > c->pnode_cnt) { | ||
1746 | dbg_err("dirty pnodes %d exceed max %d", | ||
1747 | c->dirty_pn_cnt, c->pnode_cnt); | ||
1748 | err = -EINVAL; | ||
1749 | } | ||
1750 | if (c->dirty_nn_cnt > c->nnode_cnt) { | ||
1751 | dbg_err("dirty nnodes %d exceed max %d", | ||
1752 | c->dirty_nn_cnt, c->nnode_cnt); | ||
1753 | err = -EINVAL; | ||
1754 | } | ||
1755 | return err; | ||
1756 | case 1: | ||
1757 | c->chk_lpt_sz += len; | ||
1758 | return 0; | ||
1759 | case 2: | ||
1760 | c->chk_lpt_sz += len; | ||
1761 | c->chk_lpt_wastage += len; | ||
1762 | c->chk_lpt_lebs += 1; | ||
1763 | return 0; | ||
1764 | case 3: | ||
1765 | chk_lpt_sz = c->leb_size; | ||
1766 | chk_lpt_sz *= c->chk_lpt_lebs; | ||
1767 | chk_lpt_sz += len - c->nhead_offs; | ||
1768 | if (c->chk_lpt_sz != chk_lpt_sz) { | ||
1769 | dbg_err("LPT wrote %lld but space used was %lld", | ||
1770 | c->chk_lpt_sz, chk_lpt_sz); | ||
1771 | err = -EINVAL; | ||
1772 | } | ||
1773 | if (c->chk_lpt_sz > c->lpt_sz) { | ||
1774 | dbg_err("LPT wrote %lld but lpt_sz is %lld", | ||
1775 | c->chk_lpt_sz, c->lpt_sz); | ||
1776 | err = -EINVAL; | ||
1777 | } | ||
1778 | if (c->chk_lpt_sz2 && c->chk_lpt_sz != c->chk_lpt_sz2) { | ||
1779 | dbg_err("LPT layout size %lld but wrote %lld", | ||
1780 | c->chk_lpt_sz, c->chk_lpt_sz2); | ||
1781 | err = -EINVAL; | ||
1782 | } | ||
1783 | if (c->chk_lpt_sz2 && c->new_nhead_offs != len) { | ||
1784 | dbg_err("LPT new nhead offs: expected %d was %d", | ||
1785 | c->new_nhead_offs, len); | ||
1786 | err = -EINVAL; | ||
1787 | } | ||
1788 | lpt_sz = (long long)c->pnode_cnt * c->pnode_sz; | ||
1789 | lpt_sz += (long long)c->nnode_cnt * c->nnode_sz; | ||
1790 | lpt_sz += c->ltab_sz; | ||
1791 | if (c->big_lpt) | ||
1792 | lpt_sz += c->lsave_sz; | ||
1793 | if (c->chk_lpt_sz - c->chk_lpt_wastage > lpt_sz) { | ||
1794 | dbg_err("LPT chk_lpt_sz %lld + waste %lld exceeds %lld", | ||
1795 | c->chk_lpt_sz, c->chk_lpt_wastage, lpt_sz); | ||
1796 | err = -EINVAL; | ||
1797 | } | ||
1798 | if (err) | ||
1799 | dbg_dump_lpt_info(c); | ||
1800 | c->chk_lpt_sz2 = c->chk_lpt_sz; | ||
1801 | c->chk_lpt_sz = 0; | ||
1802 | c->chk_lpt_wastage = 0; | ||
1803 | c->chk_lpt_lebs = 0; | ||
1804 | c->new_nhead_offs = len; | ||
1805 | return err; | ||
1806 | case 4: | ||
1807 | c->chk_lpt_sz += len; | ||
1808 | c->chk_lpt_wastage += len; | ||
1809 | return 0; | ||
1810 | default: | ||
1811 | return -EINVAL; | ||
1812 | } | ||
1813 | } | ||
1814 | |||
1648 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | 1815 | #endif /* CONFIG_UBIFS_FS_DEBUG */ |
diff --git a/fs/ubifs/misc.h b/fs/ubifs/misc.h index 4c12a9215d7f..4fa81d867e41 100644 --- a/fs/ubifs/misc.h +++ b/fs/ubifs/misc.h | |||
@@ -310,4 +310,31 @@ static inline int ubifs_tnc_lookup(struct ubifs_info *c, | |||
310 | return ubifs_tnc_locate(c, key, node, NULL, NULL); | 310 | return ubifs_tnc_locate(c, key, node, NULL, NULL); |
311 | } | 311 | } |
312 | 312 | ||
313 | /** | ||
314 | * ubifs_get_lprops - get reference to LEB properties. | ||
315 | * @c: the UBIFS file-system description object | ||
316 | * | ||
317 | * This function locks lprops. Lprops have to be unlocked by | ||
318 | * 'ubifs_release_lprops()'. | ||
319 | */ | ||
320 | static inline void ubifs_get_lprops(struct ubifs_info *c) | ||
321 | { | ||
322 | mutex_lock(&c->lp_mutex); | ||
323 | } | ||
324 | |||
325 | /** | ||
326 | * ubifs_release_lprops - release lprops lock. | ||
327 | * @c: the UBIFS file-system description object | ||
328 | * | ||
329 | * This function has to be called after each 'ubifs_get_lprops()' call to | ||
330 | * unlock lprops. | ||
331 | */ | ||
332 | static inline void ubifs_release_lprops(struct ubifs_info *c) | ||
333 | { | ||
334 | ubifs_assert(mutex_is_locked(&c->lp_mutex)); | ||
335 | ubifs_assert(c->lst.empty_lebs >= 0 && | ||
336 | c->lst.empty_lebs <= c->main_lebs); | ||
337 | mutex_unlock(&c->lp_mutex); | ||
338 | } | ||
339 | |||
313 | #endif /* __UBIFS_MISC_H__ */ | 340 | #endif /* __UBIFS_MISC_H__ */ |
diff --git a/fs/ubifs/scan.c b/fs/ubifs/scan.c index acf5c5fffc60..0ed82479b44b 100644 --- a/fs/ubifs/scan.c +++ b/fs/ubifs/scan.c | |||
@@ -87,7 +87,7 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum, | |||
87 | 87 | ||
88 | dbg_scan("scanning %s", dbg_ntype(ch->node_type)); | 88 | dbg_scan("scanning %s", dbg_ntype(ch->node_type)); |
89 | 89 | ||
90 | if (ubifs_check_node(c, buf, lnum, offs, quiet)) | 90 | if (ubifs_check_node(c, buf, lnum, offs, quiet, 1)) |
91 | return SCANNED_A_CORRUPT_NODE; | 91 | return SCANNED_A_CORRUPT_NODE; |
92 | 92 | ||
93 | if (ch->node_type == UBIFS_PAD_NODE) { | 93 | if (ch->node_type == UBIFS_PAD_NODE) { |
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 9a9220333b3b..8780efbf40ac 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c | |||
@@ -401,6 +401,16 @@ static int ubifs_show_options(struct seq_file *s, struct vfsmount *mnt) | |||
401 | else if (c->mount_opts.unmount_mode == 1) | 401 | else if (c->mount_opts.unmount_mode == 1) |
402 | seq_printf(s, ",norm_unmount"); | 402 | seq_printf(s, ",norm_unmount"); |
403 | 403 | ||
404 | if (c->mount_opts.bulk_read == 2) | ||
405 | seq_printf(s, ",bulk_read"); | ||
406 | else if (c->mount_opts.bulk_read == 1) | ||
407 | seq_printf(s, ",no_bulk_read"); | ||
408 | |||
409 | if (c->mount_opts.chk_data_crc == 2) | ||
410 | seq_printf(s, ",chk_data_crc"); | ||
411 | else if (c->mount_opts.chk_data_crc == 1) | ||
412 | seq_printf(s, ",no_chk_data_crc"); | ||
413 | |||
404 | return 0; | 414 | return 0; |
405 | } | 415 | } |
406 | 416 | ||
@@ -408,13 +418,26 @@ static int ubifs_sync_fs(struct super_block *sb, int wait) | |||
408 | { | 418 | { |
409 | struct ubifs_info *c = sb->s_fs_info; | 419 | struct ubifs_info *c = sb->s_fs_info; |
410 | int i, ret = 0, err; | 420 | int i, ret = 0, err; |
421 | long long bud_bytes; | ||
411 | 422 | ||
412 | if (c->jheads) | 423 | if (c->jheads) { |
413 | for (i = 0; i < c->jhead_cnt; i++) { | 424 | for (i = 0; i < c->jhead_cnt; i++) { |
414 | err = ubifs_wbuf_sync(&c->jheads[i].wbuf); | 425 | err = ubifs_wbuf_sync(&c->jheads[i].wbuf); |
415 | if (err && !ret) | 426 | if (err && !ret) |
416 | ret = err; | 427 | ret = err; |
417 | } | 428 | } |
429 | |||
430 | /* Commit the journal unless it has too little data */ | ||
431 | spin_lock(&c->buds_lock); | ||
432 | bud_bytes = c->bud_bytes; | ||
433 | spin_unlock(&c->buds_lock); | ||
434 | if (bud_bytes > c->leb_size) { | ||
435 | err = ubifs_run_commit(c); | ||
436 | if (err) | ||
437 | return err; | ||
438 | } | ||
439 | } | ||
440 | |||
418 | /* | 441 | /* |
419 | * We ought to call sync for c->ubi but it does not have one. If it had | 442 | * We ought to call sync for c->ubi but it does not have one. If it had |
420 | * it would in turn call mtd->sync, however mtd operations are | 443 | * it would in turn call mtd->sync, however mtd operations are |
@@ -538,6 +561,18 @@ static int init_constants_early(struct ubifs_info *c) | |||
538 | * calculations when reporting free space. | 561 | * calculations when reporting free space. |
539 | */ | 562 | */ |
540 | c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ; | 563 | c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ; |
564 | /* Buffer size for bulk-reads */ | ||
565 | c->bulk_read_buf_size = UBIFS_MAX_BULK_READ * UBIFS_MAX_DATA_NODE_SZ; | ||
566 | if (c->bulk_read_buf_size > c->leb_size) | ||
567 | c->bulk_read_buf_size = c->leb_size; | ||
568 | if (c->bulk_read_buf_size > 128 * 1024) { | ||
569 | /* Check if we can kmalloc more than 128KiB */ | ||
570 | void *try = kmalloc(c->bulk_read_buf_size, GFP_KERNEL); | ||
571 | |||
572 | kfree(try); | ||
573 | if (!try) | ||
574 | c->bulk_read_buf_size = 128 * 1024; | ||
575 | } | ||
541 | return 0; | 576 | return 0; |
542 | } | 577 | } |
543 | 578 | ||
@@ -840,17 +875,29 @@ static int check_volume_empty(struct ubifs_info *c) | |||
840 | * | 875 | * |
841 | * Opt_fast_unmount: do not run a journal commit before un-mounting | 876 | * Opt_fast_unmount: do not run a journal commit before un-mounting |
842 | * Opt_norm_unmount: run a journal commit before un-mounting | 877 | * Opt_norm_unmount: run a journal commit before un-mounting |
878 | * Opt_bulk_read: enable bulk-reads | ||
879 | * Opt_no_bulk_read: disable bulk-reads | ||
880 | * Opt_chk_data_crc: check CRCs when reading data nodes | ||
881 | * Opt_no_chk_data_crc: do not check CRCs when reading data nodes | ||
843 | * Opt_err: just end of array marker | 882 | * Opt_err: just end of array marker |
844 | */ | 883 | */ |
845 | enum { | 884 | enum { |
846 | Opt_fast_unmount, | 885 | Opt_fast_unmount, |
847 | Opt_norm_unmount, | 886 | Opt_norm_unmount, |
887 | Opt_bulk_read, | ||
888 | Opt_no_bulk_read, | ||
889 | Opt_chk_data_crc, | ||
890 | Opt_no_chk_data_crc, | ||
848 | Opt_err, | 891 | Opt_err, |
849 | }; | 892 | }; |
850 | 893 | ||
851 | static const match_table_t tokens = { | 894 | static const match_table_t tokens = { |
852 | {Opt_fast_unmount, "fast_unmount"}, | 895 | {Opt_fast_unmount, "fast_unmount"}, |
853 | {Opt_norm_unmount, "norm_unmount"}, | 896 | {Opt_norm_unmount, "norm_unmount"}, |
897 | {Opt_bulk_read, "bulk_read"}, | ||
898 | {Opt_no_bulk_read, "no_bulk_read"}, | ||
899 | {Opt_chk_data_crc, "chk_data_crc"}, | ||
900 | {Opt_no_chk_data_crc, "no_chk_data_crc"}, | ||
854 | {Opt_err, NULL}, | 901 | {Opt_err, NULL}, |
855 | }; | 902 | }; |
856 | 903 | ||
@@ -888,6 +935,22 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options, | |||
888 | c->mount_opts.unmount_mode = 1; | 935 | c->mount_opts.unmount_mode = 1; |
889 | c->fast_unmount = 0; | 936 | c->fast_unmount = 0; |
890 | break; | 937 | break; |
938 | case Opt_bulk_read: | ||
939 | c->mount_opts.bulk_read = 2; | ||
940 | c->bulk_read = 1; | ||
941 | break; | ||
942 | case Opt_no_bulk_read: | ||
943 | c->mount_opts.bulk_read = 1; | ||
944 | c->bulk_read = 0; | ||
945 | break; | ||
946 | case Opt_chk_data_crc: | ||
947 | c->mount_opts.chk_data_crc = 2; | ||
948 | c->no_chk_data_crc = 0; | ||
949 | break; | ||
950 | case Opt_no_chk_data_crc: | ||
951 | c->mount_opts.chk_data_crc = 1; | ||
952 | c->no_chk_data_crc = 1; | ||
953 | break; | ||
891 | default: | 954 | default: |
892 | ubifs_err("unrecognized mount option \"%s\" " | 955 | ubifs_err("unrecognized mount option \"%s\" " |
893 | "or missing value", p); | 956 | "or missing value", p); |
@@ -996,6 +1059,8 @@ static int mount_ubifs(struct ubifs_info *c) | |||
996 | goto out_free; | 1059 | goto out_free; |
997 | } | 1060 | } |
998 | 1061 | ||
1062 | c->always_chk_crc = 1; | ||
1063 | |||
999 | err = ubifs_read_superblock(c); | 1064 | err = ubifs_read_superblock(c); |
1000 | if (err) | 1065 | if (err) |
1001 | goto out_free; | 1066 | goto out_free; |
@@ -1032,8 +1097,6 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1032 | 1097 | ||
1033 | /* Create background thread */ | 1098 | /* Create background thread */ |
1034 | c->bgt = kthread_create(ubifs_bg_thread, c, c->bgt_name); | 1099 | c->bgt = kthread_create(ubifs_bg_thread, c, c->bgt_name); |
1035 | if (!c->bgt) | ||
1036 | c->bgt = ERR_PTR(-EINVAL); | ||
1037 | if (IS_ERR(c->bgt)) { | 1100 | if (IS_ERR(c->bgt)) { |
1038 | err = PTR_ERR(c->bgt); | 1101 | err = PTR_ERR(c->bgt); |
1039 | c->bgt = NULL; | 1102 | c->bgt = NULL; |
@@ -1139,24 +1202,28 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1139 | if (err) | 1202 | if (err) |
1140 | goto out_infos; | 1203 | goto out_infos; |
1141 | 1204 | ||
1205 | c->always_chk_crc = 0; | ||
1206 | |||
1142 | ubifs_msg("mounted UBI device %d, volume %d, name \"%s\"", | 1207 | ubifs_msg("mounted UBI device %d, volume %d, name \"%s\"", |
1143 | c->vi.ubi_num, c->vi.vol_id, c->vi.name); | 1208 | c->vi.ubi_num, c->vi.vol_id, c->vi.name); |
1144 | if (mounted_read_only) | 1209 | if (mounted_read_only) |
1145 | ubifs_msg("mounted read-only"); | 1210 | ubifs_msg("mounted read-only"); |
1146 | x = (long long)c->main_lebs * c->leb_size; | 1211 | x = (long long)c->main_lebs * c->leb_size; |
1147 | ubifs_msg("file system size: %lld bytes (%lld KiB, %lld MiB, %d LEBs)", | 1212 | ubifs_msg("file system size: %lld bytes (%lld KiB, %lld MiB, %d " |
1148 | x, x >> 10, x >> 20, c->main_lebs); | 1213 | "LEBs)", x, x >> 10, x >> 20, c->main_lebs); |
1149 | x = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes; | 1214 | x = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes; |
1150 | ubifs_msg("journal size: %lld bytes (%lld KiB, %lld MiB, %d LEBs)", | 1215 | ubifs_msg("journal size: %lld bytes (%lld KiB, %lld MiB, %d " |
1151 | x, x >> 10, x >> 20, c->log_lebs + c->max_bud_cnt); | 1216 | "LEBs)", x, x >> 10, x >> 20, c->log_lebs + c->max_bud_cnt); |
1152 | ubifs_msg("default compressor: %s", ubifs_compr_name(c->default_compr)); | 1217 | ubifs_msg("media format: %d (latest is %d)", |
1153 | ubifs_msg("media format %d, latest format %d", | ||
1154 | c->fmt_version, UBIFS_FORMAT_VERSION); | 1218 | c->fmt_version, UBIFS_FORMAT_VERSION); |
1219 | ubifs_msg("default compressor: %s", ubifs_compr_name(c->default_compr)); | ||
1220 | ubifs_msg("reserved for root: %llu bytes (%llu KiB)", | ||
1221 | c->report_rp_size, c->report_rp_size >> 10); | ||
1155 | 1222 | ||
1156 | dbg_msg("compiled on: " __DATE__ " at " __TIME__); | 1223 | dbg_msg("compiled on: " __DATE__ " at " __TIME__); |
1157 | dbg_msg("min. I/O unit size: %d bytes", c->min_io_size); | 1224 | dbg_msg("min. I/O unit size: %d bytes", c->min_io_size); |
1158 | dbg_msg("LEB size: %d bytes (%d KiB)", | 1225 | dbg_msg("LEB size: %d bytes (%d KiB)", |
1159 | c->leb_size, c->leb_size / 1024); | 1226 | c->leb_size, c->leb_size >> 10); |
1160 | dbg_msg("data journal heads: %d", | 1227 | dbg_msg("data journal heads: %d", |
1161 | c->jhead_cnt - NONDATA_JHEADS_CNT); | 1228 | c->jhead_cnt - NONDATA_JHEADS_CNT); |
1162 | dbg_msg("UUID: %02X%02X%02X%02X-%02X%02X" | 1229 | dbg_msg("UUID: %02X%02X%02X%02X-%02X%02X" |
@@ -1282,6 +1349,7 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1282 | 1349 | ||
1283 | mutex_lock(&c->umount_mutex); | 1350 | mutex_lock(&c->umount_mutex); |
1284 | c->remounting_rw = 1; | 1351 | c->remounting_rw = 1; |
1352 | c->always_chk_crc = 1; | ||
1285 | 1353 | ||
1286 | /* Check for enough free space */ | 1354 | /* Check for enough free space */ |
1287 | if (ubifs_calc_available(c, c->min_idx_lebs) <= 0) { | 1355 | if (ubifs_calc_available(c, c->min_idx_lebs) <= 0) { |
@@ -1345,20 +1413,20 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1345 | 1413 | ||
1346 | /* Create background thread */ | 1414 | /* Create background thread */ |
1347 | c->bgt = kthread_create(ubifs_bg_thread, c, c->bgt_name); | 1415 | c->bgt = kthread_create(ubifs_bg_thread, c, c->bgt_name); |
1348 | if (!c->bgt) | ||
1349 | c->bgt = ERR_PTR(-EINVAL); | ||
1350 | if (IS_ERR(c->bgt)) { | 1416 | if (IS_ERR(c->bgt)) { |
1351 | err = PTR_ERR(c->bgt); | 1417 | err = PTR_ERR(c->bgt); |
1352 | c->bgt = NULL; | 1418 | c->bgt = NULL; |
1353 | ubifs_err("cannot spawn \"%s\", error %d", | 1419 | ubifs_err("cannot spawn \"%s\", error %d", |
1354 | c->bgt_name, err); | 1420 | c->bgt_name, err); |
1355 | return err; | 1421 | goto out; |
1356 | } | 1422 | } |
1357 | wake_up_process(c->bgt); | 1423 | wake_up_process(c->bgt); |
1358 | 1424 | ||
1359 | c->orph_buf = vmalloc(c->leb_size); | 1425 | c->orph_buf = vmalloc(c->leb_size); |
1360 | if (!c->orph_buf) | 1426 | if (!c->orph_buf) { |
1361 | return -ENOMEM; | 1427 | err = -ENOMEM; |
1428 | goto out; | ||
1429 | } | ||
1362 | 1430 | ||
1363 | /* Check for enough log space */ | 1431 | /* Check for enough log space */ |
1364 | lnum = c->lhead_lnum + 1; | 1432 | lnum = c->lhead_lnum + 1; |
@@ -1385,6 +1453,7 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1385 | dbg_gen("re-mounted read-write"); | 1453 | dbg_gen("re-mounted read-write"); |
1386 | c->vfs_sb->s_flags &= ~MS_RDONLY; | 1454 | c->vfs_sb->s_flags &= ~MS_RDONLY; |
1387 | c->remounting_rw = 0; | 1455 | c->remounting_rw = 0; |
1456 | c->always_chk_crc = 0; | ||
1388 | mutex_unlock(&c->umount_mutex); | 1457 | mutex_unlock(&c->umount_mutex); |
1389 | return 0; | 1458 | return 0; |
1390 | 1459 | ||
@@ -1400,6 +1469,7 @@ out: | |||
1400 | c->ileb_buf = NULL; | 1469 | c->ileb_buf = NULL; |
1401 | ubifs_lpt_free(c, 1); | 1470 | ubifs_lpt_free(c, 1); |
1402 | c->remounting_rw = 0; | 1471 | c->remounting_rw = 0; |
1472 | c->always_chk_crc = 0; | ||
1403 | mutex_unlock(&c->umount_mutex); | 1473 | mutex_unlock(&c->umount_mutex); |
1404 | return err; | 1474 | return err; |
1405 | } | 1475 | } |
@@ -1408,12 +1478,9 @@ out: | |||
1408 | * commit_on_unmount - commit the journal when un-mounting. | 1478 | * commit_on_unmount - commit the journal when un-mounting. |
1409 | * @c: UBIFS file-system description object | 1479 | * @c: UBIFS file-system description object |
1410 | * | 1480 | * |
1411 | * This function is called during un-mounting and it commits the journal unless | 1481 | * This function is called during un-mounting and re-mounting, and it commits |
1412 | * the "fast unmount" mode is enabled. It also avoids committing the journal if | 1482 | * the journal unless the "fast unmount" mode is enabled. It also avoids |
1413 | * it contains too few data. | 1483 | * committing the journal if it contains too few data. |
1414 | * | ||
1415 | * Sometimes recovery requires the journal to be committed at least once, and | ||
1416 | * this function takes care about this. | ||
1417 | */ | 1484 | */ |
1418 | static void commit_on_unmount(struct ubifs_info *c) | 1485 | static void commit_on_unmount(struct ubifs_info *c) |
1419 | { | 1486 | { |
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index 7634c5970887..d27fd918b9c9 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c | |||
@@ -284,7 +284,7 @@ static struct ubifs_znode *dirty_cow_znode(struct ubifs_info *c, | |||
284 | } | 284 | } |
285 | 285 | ||
286 | zn = copy_znode(c, znode); | 286 | zn = copy_znode(c, znode); |
287 | if (unlikely(IS_ERR(zn))) | 287 | if (IS_ERR(zn)) |
288 | return zn; | 288 | return zn; |
289 | 289 | ||
290 | if (zbr->len) { | 290 | if (zbr->len) { |
@@ -470,6 +470,10 @@ static int try_read_node(const struct ubifs_info *c, void *buf, int type, | |||
470 | if (node_len != len) | 470 | if (node_len != len) |
471 | return 0; | 471 | return 0; |
472 | 472 | ||
473 | if (type == UBIFS_DATA_NODE && !c->always_chk_crc) | ||
474 | if (c->no_chk_data_crc) | ||
475 | return 0; | ||
476 | |||
473 | crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); | 477 | crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); |
474 | node_crc = le32_to_cpu(ch->crc); | 478 | node_crc = le32_to_cpu(ch->crc); |
475 | if (crc != node_crc) | 479 | if (crc != node_crc) |
@@ -1128,7 +1132,7 @@ static struct ubifs_znode *dirty_cow_bottom_up(struct ubifs_info *c, | |||
1128 | ubifs_assert(znode == c->zroot.znode); | 1132 | ubifs_assert(znode == c->zroot.znode); |
1129 | znode = dirty_cow_znode(c, &c->zroot); | 1133 | znode = dirty_cow_znode(c, &c->zroot); |
1130 | } | 1134 | } |
1131 | if (unlikely(IS_ERR(znode)) || !p) | 1135 | if (IS_ERR(znode) || !p) |
1132 | break; | 1136 | break; |
1133 | ubifs_assert(path[p - 1] >= 0); | 1137 | ubifs_assert(path[p - 1] >= 0); |
1134 | ubifs_assert(path[p - 1] < znode->child_cnt); | 1138 | ubifs_assert(path[p - 1] < znode->child_cnt); |
@@ -1492,6 +1496,289 @@ out: | |||
1492 | } | 1496 | } |
1493 | 1497 | ||
1494 | /** | 1498 | /** |
1499 | * ubifs_tnc_get_bu_keys - lookup keys for bulk-read. | ||
1500 | * @c: UBIFS file-system description object | ||
1501 | * @bu: bulk-read parameters and results | ||
1502 | * | ||
1503 | * Lookup consecutive data node keys for the same inode that reside | ||
1504 | * consecutively in the same LEB. | ||
1505 | */ | ||
1506 | int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu) | ||
1507 | { | ||
1508 | int n, err = 0, lnum = -1, uninitialized_var(offs); | ||
1509 | int uninitialized_var(len); | ||
1510 | unsigned int block = key_block(c, &bu->key); | ||
1511 | struct ubifs_znode *znode; | ||
1512 | |||
1513 | bu->cnt = 0; | ||
1514 | bu->blk_cnt = 0; | ||
1515 | bu->eof = 0; | ||
1516 | |||
1517 | mutex_lock(&c->tnc_mutex); | ||
1518 | /* Find first key */ | ||
1519 | err = ubifs_lookup_level0(c, &bu->key, &znode, &n); | ||
1520 | if (err < 0) | ||
1521 | goto out; | ||
1522 | if (err) { | ||
1523 | /* Key found */ | ||
1524 | len = znode->zbranch[n].len; | ||
1525 | /* The buffer must be big enough for at least 1 node */ | ||
1526 | if (len > bu->buf_len) { | ||
1527 | err = -EINVAL; | ||
1528 | goto out; | ||
1529 | } | ||
1530 | /* Add this key */ | ||
1531 | bu->zbranch[bu->cnt++] = znode->zbranch[n]; | ||
1532 | bu->blk_cnt += 1; | ||
1533 | lnum = znode->zbranch[n].lnum; | ||
1534 | offs = ALIGN(znode->zbranch[n].offs + len, 8); | ||
1535 | } | ||
1536 | while (1) { | ||
1537 | struct ubifs_zbranch *zbr; | ||
1538 | union ubifs_key *key; | ||
1539 | unsigned int next_block; | ||
1540 | |||
1541 | /* Find next key */ | ||
1542 | err = tnc_next(c, &znode, &n); | ||
1543 | if (err) | ||
1544 | goto out; | ||
1545 | zbr = &znode->zbranch[n]; | ||
1546 | key = &zbr->key; | ||
1547 | /* See if there is another data key for this file */ | ||
1548 | if (key_inum(c, key) != key_inum(c, &bu->key) || | ||
1549 | key_type(c, key) != UBIFS_DATA_KEY) { | ||
1550 | err = -ENOENT; | ||
1551 | goto out; | ||
1552 | } | ||
1553 | if (lnum < 0) { | ||
1554 | /* First key found */ | ||
1555 | lnum = zbr->lnum; | ||
1556 | offs = ALIGN(zbr->offs + zbr->len, 8); | ||
1557 | len = zbr->len; | ||
1558 | if (len > bu->buf_len) { | ||
1559 | err = -EINVAL; | ||
1560 | goto out; | ||
1561 | } | ||
1562 | } else { | ||
1563 | /* | ||
1564 | * The data nodes must be in consecutive positions in | ||
1565 | * the same LEB. | ||
1566 | */ | ||
1567 | if (zbr->lnum != lnum || zbr->offs != offs) | ||
1568 | goto out; | ||
1569 | offs += ALIGN(zbr->len, 8); | ||
1570 | len = ALIGN(len, 8) + zbr->len; | ||
1571 | /* Must not exceed buffer length */ | ||
1572 | if (len > bu->buf_len) | ||
1573 | goto out; | ||
1574 | } | ||
1575 | /* Allow for holes */ | ||
1576 | next_block = key_block(c, key); | ||
1577 | bu->blk_cnt += (next_block - block - 1); | ||
1578 | if (bu->blk_cnt >= UBIFS_MAX_BULK_READ) | ||
1579 | goto out; | ||
1580 | block = next_block; | ||
1581 | /* Add this key */ | ||
1582 | bu->zbranch[bu->cnt++] = *zbr; | ||
1583 | bu->blk_cnt += 1; | ||
1584 | /* See if we have room for more */ | ||
1585 | if (bu->cnt >= UBIFS_MAX_BULK_READ) | ||
1586 | goto out; | ||
1587 | if (bu->blk_cnt >= UBIFS_MAX_BULK_READ) | ||
1588 | goto out; | ||
1589 | } | ||
1590 | out: | ||
1591 | if (err == -ENOENT) { | ||
1592 | bu->eof = 1; | ||
1593 | err = 0; | ||
1594 | } | ||
1595 | bu->gc_seq = c->gc_seq; | ||
1596 | mutex_unlock(&c->tnc_mutex); | ||
1597 | if (err) | ||
1598 | return err; | ||
1599 | /* | ||
1600 | * An enormous hole could cause bulk-read to encompass too many | ||
1601 | * page cache pages, so limit the number here. | ||
1602 | */ | ||
1603 | if (bu->blk_cnt > UBIFS_MAX_BULK_READ) | ||
1604 | bu->blk_cnt = UBIFS_MAX_BULK_READ; | ||
1605 | /* | ||
1606 | * Ensure that bulk-read covers a whole number of page cache | ||
1607 | * pages. | ||
1608 | */ | ||
1609 | if (UBIFS_BLOCKS_PER_PAGE == 1 || | ||
1610 | !(bu->blk_cnt & (UBIFS_BLOCKS_PER_PAGE - 1))) | ||
1611 | return 0; | ||
1612 | if (bu->eof) { | ||
1613 | /* At the end of file we can round up */ | ||
1614 | bu->blk_cnt += UBIFS_BLOCKS_PER_PAGE - 1; | ||
1615 | return 0; | ||
1616 | } | ||
1617 | /* Exclude data nodes that do not make up a whole page cache page */ | ||
1618 | block = key_block(c, &bu->key) + bu->blk_cnt; | ||
1619 | block &= ~(UBIFS_BLOCKS_PER_PAGE - 1); | ||
1620 | while (bu->cnt) { | ||
1621 | if (key_block(c, &bu->zbranch[bu->cnt - 1].key) < block) | ||
1622 | break; | ||
1623 | bu->cnt -= 1; | ||
1624 | } | ||
1625 | return 0; | ||
1626 | } | ||
1627 | |||
1628 | /** | ||
1629 | * read_wbuf - bulk-read from a LEB with a wbuf. | ||
1630 | * @wbuf: wbuf that may overlap the read | ||
1631 | * @buf: buffer into which to read | ||
1632 | * @len: read length | ||
1633 | * @lnum: LEB number from which to read | ||
1634 | * @offs: offset from which to read | ||
1635 | * | ||
1636 | * This functions returns %0 on success or a negative error code on failure. | ||
1637 | */ | ||
1638 | static int read_wbuf(struct ubifs_wbuf *wbuf, void *buf, int len, int lnum, | ||
1639 | int offs) | ||
1640 | { | ||
1641 | const struct ubifs_info *c = wbuf->c; | ||
1642 | int rlen, overlap; | ||
1643 | |||
1644 | dbg_io("LEB %d:%d, length %d", lnum, offs, len); | ||
1645 | ubifs_assert(wbuf && lnum >= 0 && lnum < c->leb_cnt && offs >= 0); | ||
1646 | ubifs_assert(!(offs & 7) && offs < c->leb_size); | ||
1647 | ubifs_assert(offs + len <= c->leb_size); | ||
1648 | |||
1649 | spin_lock(&wbuf->lock); | ||
1650 | overlap = (lnum == wbuf->lnum && offs + len > wbuf->offs); | ||
1651 | if (!overlap) { | ||
1652 | /* We may safely unlock the write-buffer and read the data */ | ||
1653 | spin_unlock(&wbuf->lock); | ||
1654 | return ubi_read(c->ubi, lnum, buf, offs, len); | ||
1655 | } | ||
1656 | |||
1657 | /* Don't read under wbuf */ | ||
1658 | rlen = wbuf->offs - offs; | ||
1659 | if (rlen < 0) | ||
1660 | rlen = 0; | ||
1661 | |||
1662 | /* Copy the rest from the write-buffer */ | ||
1663 | memcpy(buf + rlen, wbuf->buf + offs + rlen - wbuf->offs, len - rlen); | ||
1664 | spin_unlock(&wbuf->lock); | ||
1665 | |||
1666 | if (rlen > 0) | ||
1667 | /* Read everything that goes before write-buffer */ | ||
1668 | return ubi_read(c->ubi, lnum, buf, offs, rlen); | ||
1669 | |||
1670 | return 0; | ||
1671 | } | ||
1672 | |||
1673 | /** | ||
1674 | * validate_data_node - validate data nodes for bulk-read. | ||
1675 | * @c: UBIFS file-system description object | ||
1676 | * @buf: buffer containing data node to validate | ||
1677 | * @zbr: zbranch of data node to validate | ||
1678 | * | ||
1679 | * This functions returns %0 on success or a negative error code on failure. | ||
1680 | */ | ||
1681 | static int validate_data_node(struct ubifs_info *c, void *buf, | ||
1682 | struct ubifs_zbranch *zbr) | ||
1683 | { | ||
1684 | union ubifs_key key1; | ||
1685 | struct ubifs_ch *ch = buf; | ||
1686 | int err, len; | ||
1687 | |||
1688 | if (ch->node_type != UBIFS_DATA_NODE) { | ||
1689 | ubifs_err("bad node type (%d but expected %d)", | ||
1690 | ch->node_type, UBIFS_DATA_NODE); | ||
1691 | goto out_err; | ||
1692 | } | ||
1693 | |||
1694 | err = ubifs_check_node(c, buf, zbr->lnum, zbr->offs, 0, 0); | ||
1695 | if (err) { | ||
1696 | ubifs_err("expected node type %d", UBIFS_DATA_NODE); | ||
1697 | goto out; | ||
1698 | } | ||
1699 | |||
1700 | len = le32_to_cpu(ch->len); | ||
1701 | if (len != zbr->len) { | ||
1702 | ubifs_err("bad node length %d, expected %d", len, zbr->len); | ||
1703 | goto out_err; | ||
1704 | } | ||
1705 | |||
1706 | /* Make sure the key of the read node is correct */ | ||
1707 | key_read(c, buf + UBIFS_KEY_OFFSET, &key1); | ||
1708 | if (!keys_eq(c, &zbr->key, &key1)) { | ||
1709 | ubifs_err("bad key in node at LEB %d:%d", | ||
1710 | zbr->lnum, zbr->offs); | ||
1711 | dbg_tnc("looked for key %s found node's key %s", | ||
1712 | DBGKEY(&zbr->key), DBGKEY1(&key1)); | ||
1713 | goto out_err; | ||
1714 | } | ||
1715 | |||
1716 | return 0; | ||
1717 | |||
1718 | out_err: | ||
1719 | err = -EINVAL; | ||
1720 | out: | ||
1721 | ubifs_err("bad node at LEB %d:%d", zbr->lnum, zbr->offs); | ||
1722 | dbg_dump_node(c, buf); | ||
1723 | dbg_dump_stack(); | ||
1724 | return err; | ||
1725 | } | ||
1726 | |||
1727 | /** | ||
1728 | * ubifs_tnc_bulk_read - read a number of data nodes in one go. | ||
1729 | * @c: UBIFS file-system description object | ||
1730 | * @bu: bulk-read parameters and results | ||
1731 | * | ||
1732 | * This functions reads and validates the data nodes that were identified by the | ||
1733 | * 'ubifs_tnc_get_bu_keys()' function. This functions returns %0 on success, | ||
1734 | * -EAGAIN to indicate a race with GC, or another negative error code on | ||
1735 | * failure. | ||
1736 | */ | ||
1737 | int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu) | ||
1738 | { | ||
1739 | int lnum = bu->zbranch[0].lnum, offs = bu->zbranch[0].offs, len, err, i; | ||
1740 | struct ubifs_wbuf *wbuf; | ||
1741 | void *buf; | ||
1742 | |||
1743 | len = bu->zbranch[bu->cnt - 1].offs; | ||
1744 | len += bu->zbranch[bu->cnt - 1].len - offs; | ||
1745 | if (len > bu->buf_len) { | ||
1746 | ubifs_err("buffer too small %d vs %d", bu->buf_len, len); | ||
1747 | return -EINVAL; | ||
1748 | } | ||
1749 | |||
1750 | /* Do the read */ | ||
1751 | wbuf = ubifs_get_wbuf(c, lnum); | ||
1752 | if (wbuf) | ||
1753 | err = read_wbuf(wbuf, bu->buf, len, lnum, offs); | ||
1754 | else | ||
1755 | err = ubi_read(c->ubi, lnum, bu->buf, offs, len); | ||
1756 | |||
1757 | /* Check for a race with GC */ | ||
1758 | if (maybe_leb_gced(c, lnum, bu->gc_seq)) | ||
1759 | return -EAGAIN; | ||
1760 | |||
1761 | if (err && err != -EBADMSG) { | ||
1762 | ubifs_err("failed to read from LEB %d:%d, error %d", | ||
1763 | lnum, offs, err); | ||
1764 | dbg_dump_stack(); | ||
1765 | dbg_tnc("key %s", DBGKEY(&bu->key)); | ||
1766 | return err; | ||
1767 | } | ||
1768 | |||
1769 | /* Validate the nodes read */ | ||
1770 | buf = bu->buf; | ||
1771 | for (i = 0; i < bu->cnt; i++) { | ||
1772 | err = validate_data_node(c, buf, &bu->zbranch[i]); | ||
1773 | if (err) | ||
1774 | return err; | ||
1775 | buf = buf + ALIGN(bu->zbranch[i].len, 8); | ||
1776 | } | ||
1777 | |||
1778 | return 0; | ||
1779 | } | ||
1780 | |||
1781 | /** | ||
1495 | * do_lookup_nm- look up a "hashed" node. | 1782 | * do_lookup_nm- look up a "hashed" node. |
1496 | * @c: UBIFS file-system description object | 1783 | * @c: UBIFS file-system description object |
1497 | * @key: node key to lookup | 1784 | * @key: node key to lookup |
@@ -1675,7 +1962,7 @@ static int tnc_insert(struct ubifs_info *c, struct ubifs_znode *znode, | |||
1675 | { | 1962 | { |
1676 | struct ubifs_znode *zn, *zi, *zp; | 1963 | struct ubifs_znode *zn, *zi, *zp; |
1677 | int i, keep, move, appending = 0; | 1964 | int i, keep, move, appending = 0; |
1678 | union ubifs_key *key = &zbr->key; | 1965 | union ubifs_key *key = &zbr->key, *key1; |
1679 | 1966 | ||
1680 | ubifs_assert(n >= 0 && n <= c->fanout); | 1967 | ubifs_assert(n >= 0 && n <= c->fanout); |
1681 | 1968 | ||
@@ -1716,20 +2003,33 @@ again: | |||
1716 | zn->level = znode->level; | 2003 | zn->level = znode->level; |
1717 | 2004 | ||
1718 | /* Decide where to split */ | 2005 | /* Decide where to split */ |
1719 | if (znode->level == 0 && n == c->fanout && | 2006 | if (znode->level == 0 && key_type(c, key) == UBIFS_DATA_KEY) { |
1720 | key_type(c, key) == UBIFS_DATA_KEY) { | 2007 | /* Try not to split consecutive data keys */ |
1721 | union ubifs_key *key1; | 2008 | if (n == c->fanout) { |
1722 | 2009 | key1 = &znode->zbranch[n - 1].key; | |
1723 | /* | 2010 | if (key_inum(c, key1) == key_inum(c, key) && |
1724 | * If this is an inode which is being appended - do not split | 2011 | key_type(c, key1) == UBIFS_DATA_KEY) |
1725 | * it because no other zbranches can be inserted between | 2012 | appending = 1; |
1726 | * zbranches of consecutive data nodes anyway. | 2013 | } else |
1727 | */ | 2014 | goto check_split; |
1728 | key1 = &znode->zbranch[n - 1].key; | 2015 | } else if (appending && n != c->fanout) { |
1729 | if (key_inum(c, key1) == key_inum(c, key) && | 2016 | /* Try not to split consecutive data keys */ |
1730 | key_type(c, key1) == UBIFS_DATA_KEY && | 2017 | appending = 0; |
1731 | key_block(c, key1) == key_block(c, key) - 1) | 2018 | check_split: |
1732 | appending = 1; | 2019 | if (n >= (c->fanout + 1) / 2) { |
2020 | key1 = &znode->zbranch[0].key; | ||
2021 | if (key_inum(c, key1) == key_inum(c, key) && | ||
2022 | key_type(c, key1) == UBIFS_DATA_KEY) { | ||
2023 | key1 = &znode->zbranch[n].key; | ||
2024 | if (key_inum(c, key1) != key_inum(c, key) || | ||
2025 | key_type(c, key1) != UBIFS_DATA_KEY) { | ||
2026 | keep = n; | ||
2027 | move = c->fanout - keep; | ||
2028 | zi = znode; | ||
2029 | goto do_split; | ||
2030 | } | ||
2031 | } | ||
2032 | } | ||
1733 | } | 2033 | } |
1734 | 2034 | ||
1735 | if (appending) { | 2035 | if (appending) { |
@@ -1759,6 +2059,8 @@ again: | |||
1759 | zbr->znode->parent = zn; | 2059 | zbr->znode->parent = zn; |
1760 | } | 2060 | } |
1761 | 2061 | ||
2062 | do_split: | ||
2063 | |||
1762 | __set_bit(DIRTY_ZNODE, &zn->flags); | 2064 | __set_bit(DIRTY_ZNODE, &zn->flags); |
1763 | atomic_long_inc(&c->dirty_zn_cnt); | 2065 | atomic_long_inc(&c->dirty_zn_cnt); |
1764 | 2066 | ||
@@ -1785,14 +2087,11 @@ again: | |||
1785 | 2087 | ||
1786 | /* Insert new znode (produced by spitting) into the parent */ | 2088 | /* Insert new znode (produced by spitting) into the parent */ |
1787 | if (zp) { | 2089 | if (zp) { |
1788 | i = n; | 2090 | if (n == 0 && zi == znode && znode->iip == 0) |
2091 | correct_parent_keys(c, znode); | ||
2092 | |||
1789 | /* Locate insertion point */ | 2093 | /* Locate insertion point */ |
1790 | n = znode->iip + 1; | 2094 | n = znode->iip + 1; |
1791 | if (appending && n != c->fanout) | ||
1792 | appending = 0; | ||
1793 | |||
1794 | if (i == 0 && zi == znode && znode->iip == 0) | ||
1795 | correct_parent_keys(c, znode); | ||
1796 | 2095 | ||
1797 | /* Tail recursion */ | 2096 | /* Tail recursion */ |
1798 | zbr->key = zn->zbranch[0].key; | 2097 | zbr->key = zn->zbranch[0].key; |
diff --git a/fs/ubifs/tnc_misc.c b/fs/ubifs/tnc_misc.c index a25c1cc1f8d9..b48db999903e 100644 --- a/fs/ubifs/tnc_misc.c +++ b/fs/ubifs/tnc_misc.c | |||
@@ -480,8 +480,8 @@ int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr, | |||
480 | } | 480 | } |
481 | 481 | ||
482 | /* Make sure the key of the read node is correct */ | 482 | /* Make sure the key of the read node is correct */ |
483 | key_read(c, key, &key1); | 483 | key_read(c, node + UBIFS_KEY_OFFSET, &key1); |
484 | if (memcmp(node + UBIFS_KEY_OFFSET, &key1, c->key_len)) { | 484 | if (!keys_eq(c, key, &key1)) { |
485 | ubifs_err("bad key in node at LEB %d:%d", | 485 | ubifs_err("bad key in node at LEB %d:%d", |
486 | zbr->lnum, zbr->offs); | 486 | zbr->lnum, zbr->offs); |
487 | dbg_tnc("looked for key %s found node's key %s", | 487 | dbg_tnc("looked for key %s found node's key %s", |
diff --git a/fs/ubifs/ubifs-media.h b/fs/ubifs/ubifs-media.h index a9ecbd9af20d..0b378042a3a2 100644 --- a/fs/ubifs/ubifs-media.h +++ b/fs/ubifs/ubifs-media.h | |||
@@ -75,7 +75,6 @@ | |||
75 | */ | 75 | */ |
76 | #define UBIFS_BLOCK_SIZE 4096 | 76 | #define UBIFS_BLOCK_SIZE 4096 |
77 | #define UBIFS_BLOCK_SHIFT 12 | 77 | #define UBIFS_BLOCK_SHIFT 12 |
78 | #define UBIFS_BLOCK_MASK 0x00000FFF | ||
79 | 78 | ||
80 | /* UBIFS padding byte pattern (must not be first or last byte of node magic) */ | 79 | /* UBIFS padding byte pattern (must not be first or last byte of node magic) */ |
81 | #define UBIFS_PADDING_BYTE 0xCE | 80 | #define UBIFS_PADDING_BYTE 0xCE |
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 17c620b93eec..a7bd32fa15b9 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h | |||
@@ -142,6 +142,9 @@ | |||
142 | /* Maximum expected tree height for use by bottom_up_buf */ | 142 | /* Maximum expected tree height for use by bottom_up_buf */ |
143 | #define BOTTOM_UP_HEIGHT 64 | 143 | #define BOTTOM_UP_HEIGHT 64 |
144 | 144 | ||
145 | /* Maximum number of data nodes to bulk-read */ | ||
146 | #define UBIFS_MAX_BULK_READ 32 | ||
147 | |||
145 | /* | 148 | /* |
146 | * Lockdep classes for UBIFS inode @ui_mutex. | 149 | * Lockdep classes for UBIFS inode @ui_mutex. |
147 | */ | 150 | */ |
@@ -328,9 +331,10 @@ struct ubifs_gced_idx_leb { | |||
328 | * this inode | 331 | * this inode |
329 | * @dirty: non-zero if the inode is dirty | 332 | * @dirty: non-zero if the inode is dirty |
330 | * @xattr: non-zero if this is an extended attribute inode | 333 | * @xattr: non-zero if this is an extended attribute inode |
334 | * @bulk_read: non-zero if bulk-read should be used | ||
331 | * @ui_mutex: serializes inode write-back with the rest of VFS operations, | 335 | * @ui_mutex: serializes inode write-back with the rest of VFS operations, |
332 | * serializes "clean <-> dirty" state changes, protects @dirty, | 336 | * serializes "clean <-> dirty" state changes, serializes bulk-read, |
333 | * @ui_size, and @xattr_size | 337 | * protects @dirty, @bulk_read, @ui_size, and @xattr_size |
334 | * @ui_lock: protects @synced_i_size | 338 | * @ui_lock: protects @synced_i_size |
335 | * @synced_i_size: synchronized size of inode, i.e. the value of inode size | 339 | * @synced_i_size: synchronized size of inode, i.e. the value of inode size |
336 | * currently stored on the flash; used only for regular file | 340 | * currently stored on the flash; used only for regular file |
@@ -338,6 +342,8 @@ struct ubifs_gced_idx_leb { | |||
338 | * @ui_size: inode size used by UBIFS when writing to flash | 342 | * @ui_size: inode size used by UBIFS when writing to flash |
339 | * @flags: inode flags (@UBIFS_COMPR_FL, etc) | 343 | * @flags: inode flags (@UBIFS_COMPR_FL, etc) |
340 | * @compr_type: default compression type used for this inode | 344 | * @compr_type: default compression type used for this inode |
345 | * @last_page_read: page number of last page read (for bulk read) | ||
346 | * @read_in_a_row: number of consecutive pages read in a row (for bulk read) | ||
341 | * @data_len: length of the data attached to the inode | 347 | * @data_len: length of the data attached to the inode |
342 | * @data: inode's data | 348 | * @data: inode's data |
343 | * | 349 | * |
@@ -379,12 +385,15 @@ struct ubifs_inode { | |||
379 | unsigned int xattr_names; | 385 | unsigned int xattr_names; |
380 | unsigned int dirty:1; | 386 | unsigned int dirty:1; |
381 | unsigned int xattr:1; | 387 | unsigned int xattr:1; |
388 | unsigned int bulk_read:1; | ||
382 | struct mutex ui_mutex; | 389 | struct mutex ui_mutex; |
383 | spinlock_t ui_lock; | 390 | spinlock_t ui_lock; |
384 | loff_t synced_i_size; | 391 | loff_t synced_i_size; |
385 | loff_t ui_size; | 392 | loff_t ui_size; |
386 | int flags; | 393 | int flags; |
387 | int compr_type; | 394 | int compr_type; |
395 | pgoff_t last_page_read; | ||
396 | pgoff_t read_in_a_row; | ||
388 | int data_len; | 397 | int data_len; |
389 | void *data; | 398 | void *data; |
390 | }; | 399 | }; |
@@ -698,8 +707,8 @@ struct ubifs_jhead { | |||
698 | * struct ubifs_zbranch - key/coordinate/length branch stored in znodes. | 707 | * struct ubifs_zbranch - key/coordinate/length branch stored in znodes. |
699 | * @key: key | 708 | * @key: key |
700 | * @znode: znode address in memory | 709 | * @znode: znode address in memory |
701 | * @lnum: LEB number of the indexing node | 710 | * @lnum: LEB number of the target node (indexing node or data node) |
702 | * @offs: offset of the indexing node within @lnum | 711 | * @offs: target node offset within @lnum |
703 | * @len: target node length | 712 | * @len: target node length |
704 | */ | 713 | */ |
705 | struct ubifs_zbranch { | 714 | struct ubifs_zbranch { |
@@ -744,6 +753,28 @@ struct ubifs_znode { | |||
744 | }; | 753 | }; |
745 | 754 | ||
746 | /** | 755 | /** |
756 | * struct bu_info - bulk-read information | ||
757 | * @key: first data node key | ||
758 | * @zbranch: zbranches of data nodes to bulk read | ||
759 | * @buf: buffer to read into | ||
760 | * @buf_len: buffer length | ||
761 | * @gc_seq: GC sequence number to detect races with GC | ||
762 | * @cnt: number of data nodes for bulk read | ||
763 | * @blk_cnt: number of data blocks including holes | ||
764 | * @oef: end of file reached | ||
765 | */ | ||
766 | struct bu_info { | ||
767 | union ubifs_key key; | ||
768 | struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ]; | ||
769 | void *buf; | ||
770 | int buf_len; | ||
771 | int gc_seq; | ||
772 | int cnt; | ||
773 | int blk_cnt; | ||
774 | int eof; | ||
775 | }; | ||
776 | |||
777 | /** | ||
747 | * struct ubifs_node_range - node length range description data structure. | 778 | * struct ubifs_node_range - node length range description data structure. |
748 | * @len: fixed node length | 779 | * @len: fixed node length |
749 | * @min_len: minimum possible node length | 780 | * @min_len: minimum possible node length |
@@ -862,9 +893,13 @@ struct ubifs_orphan { | |||
862 | /** | 893 | /** |
863 | * struct ubifs_mount_opts - UBIFS-specific mount options information. | 894 | * struct ubifs_mount_opts - UBIFS-specific mount options information. |
864 | * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast) | 895 | * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast) |
896 | * @bulk_read: enable bulk-reads | ||
897 | * @chk_data_crc: check CRCs when reading data nodes | ||
865 | */ | 898 | */ |
866 | struct ubifs_mount_opts { | 899 | struct ubifs_mount_opts { |
867 | unsigned int unmount_mode:2; | 900 | unsigned int unmount_mode:2; |
901 | unsigned int bulk_read:2; | ||
902 | unsigned int chk_data_crc:2; | ||
868 | }; | 903 | }; |
869 | 904 | ||
870 | /** | 905 | /** |
@@ -905,13 +940,12 @@ struct ubifs_mount_opts { | |||
905 | * @cmt_state: commit state | 940 | * @cmt_state: commit state |
906 | * @cs_lock: commit state lock | 941 | * @cs_lock: commit state lock |
907 | * @cmt_wq: wait queue to sleep on if the log is full and a commit is running | 942 | * @cmt_wq: wait queue to sleep on if the log is full and a commit is running |
943 | * | ||
908 | * @fast_unmount: do not run journal commit before un-mounting | 944 | * @fast_unmount: do not run journal commit before un-mounting |
909 | * @big_lpt: flag that LPT is too big to write whole during commit | 945 | * @big_lpt: flag that LPT is too big to write whole during commit |
910 | * @check_lpt_free: flag that indicates LPT GC may be needed | 946 | * @no_chk_data_crc: do not check CRCs when reading data nodes (except during |
911 | * @nospace: non-zero if the file-system does not have flash space (used as | 947 | * recovery) |
912 | * optimization) | 948 | * @bulk_read: enable bulk-reads |
913 | * @nospace_rp: the same as @nospace, but additionally means that even reserved | ||
914 | * pool is full | ||
915 | * | 949 | * |
916 | * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and | 950 | * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and |
917 | * @calc_idx_sz | 951 | * @calc_idx_sz |
@@ -935,6 +969,7 @@ struct ubifs_mount_opts { | |||
935 | * @mst_node: master node | 969 | * @mst_node: master node |
936 | * @mst_offs: offset of valid master node | 970 | * @mst_offs: offset of valid master node |
937 | * @mst_mutex: protects the master node area, @mst_node, and @mst_offs | 971 | * @mst_mutex: protects the master node area, @mst_node, and @mst_offs |
972 | * @bulk_read_buf_size: buffer size for bulk-reads | ||
938 | * | 973 | * |
939 | * @log_lebs: number of logical eraseblocks in the log | 974 | * @log_lebs: number of logical eraseblocks in the log |
940 | * @log_bytes: log size in bytes | 975 | * @log_bytes: log size in bytes |
@@ -977,12 +1012,17 @@ struct ubifs_mount_opts { | |||
977 | * but which still have to be taken into account because | 1012 | * but which still have to be taken into account because |
978 | * the index has not been committed so far | 1013 | * the index has not been committed so far |
979 | * @space_lock: protects @budg_idx_growth, @budg_data_growth, @budg_dd_growth, | 1014 | * @space_lock: protects @budg_idx_growth, @budg_data_growth, @budg_dd_growth, |
980 | * @budg_uncommited_idx, @min_idx_lebs, @old_idx_sz, and @lst; | 1015 | * @budg_uncommited_idx, @min_idx_lebs, @old_idx_sz, @lst, |
1016 | * @nospace, and @nospace_rp; | ||
981 | * @min_idx_lebs: minimum number of LEBs required for the index | 1017 | * @min_idx_lebs: minimum number of LEBs required for the index |
982 | * @old_idx_sz: size of index on flash | 1018 | * @old_idx_sz: size of index on flash |
983 | * @calc_idx_sz: temporary variable which is used to calculate new index size | 1019 | * @calc_idx_sz: temporary variable which is used to calculate new index size |
984 | * (contains accurate new index size at end of TNC commit start) | 1020 | * (contains accurate new index size at end of TNC commit start) |
985 | * @lst: lprops statistics | 1021 | * @lst: lprops statistics |
1022 | * @nospace: non-zero if the file-system does not have flash space (used as | ||
1023 | * optimization) | ||
1024 | * @nospace_rp: the same as @nospace, but additionally means that even reserved | ||
1025 | * pool is full | ||
986 | * | 1026 | * |
987 | * @page_budget: budget for a page | 1027 | * @page_budget: budget for a page |
988 | * @inode_budget: budget for an inode | 1028 | * @inode_budget: budget for an inode |
@@ -1061,6 +1101,7 @@ struct ubifs_mount_opts { | |||
1061 | * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab | 1101 | * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab |
1062 | * @dirty_nn_cnt: number of dirty nnodes | 1102 | * @dirty_nn_cnt: number of dirty nnodes |
1063 | * @dirty_pn_cnt: number of dirty pnodes | 1103 | * @dirty_pn_cnt: number of dirty pnodes |
1104 | * @check_lpt_free: flag that indicates LPT GC may be needed | ||
1064 | * @lpt_sz: LPT size | 1105 | * @lpt_sz: LPT size |
1065 | * @lpt_nod_buf: buffer for an on-flash nnode or pnode | 1106 | * @lpt_nod_buf: buffer for an on-flash nnode or pnode |
1066 | * @lpt_buf: buffer of LEB size used by LPT | 1107 | * @lpt_buf: buffer of LEB size used by LPT |
@@ -1102,6 +1143,7 @@ struct ubifs_mount_opts { | |||
1102 | * @rcvrd_mst_node: recovered master node to write when mounting ro to rw | 1143 | * @rcvrd_mst_node: recovered master node to write when mounting ro to rw |
1103 | * @size_tree: inode size information for recovery | 1144 | * @size_tree: inode size information for recovery |
1104 | * @remounting_rw: set while remounting from ro to rw (sb flags have MS_RDONLY) | 1145 | * @remounting_rw: set while remounting from ro to rw (sb flags have MS_RDONLY) |
1146 | * @always_chk_crc: always check CRCs (while mounting and remounting rw) | ||
1105 | * @mount_opts: UBIFS-specific mount options | 1147 | * @mount_opts: UBIFS-specific mount options |
1106 | * | 1148 | * |
1107 | * @dbg_buf: a buffer of LEB size used for debugging purposes | 1149 | * @dbg_buf: a buffer of LEB size used for debugging purposes |
@@ -1146,11 +1188,11 @@ struct ubifs_info { | |||
1146 | int cmt_state; | 1188 | int cmt_state; |
1147 | spinlock_t cs_lock; | 1189 | spinlock_t cs_lock; |
1148 | wait_queue_head_t cmt_wq; | 1190 | wait_queue_head_t cmt_wq; |
1191 | |||
1149 | unsigned int fast_unmount:1; | 1192 | unsigned int fast_unmount:1; |
1150 | unsigned int big_lpt:1; | 1193 | unsigned int big_lpt:1; |
1151 | unsigned int check_lpt_free:1; | 1194 | unsigned int no_chk_data_crc:1; |
1152 | unsigned int nospace:1; | 1195 | unsigned int bulk_read:1; |
1153 | unsigned int nospace_rp:1; | ||
1154 | 1196 | ||
1155 | struct mutex tnc_mutex; | 1197 | struct mutex tnc_mutex; |
1156 | struct ubifs_zbranch zroot; | 1198 | struct ubifs_zbranch zroot; |
@@ -1175,6 +1217,7 @@ struct ubifs_info { | |||
1175 | struct ubifs_mst_node *mst_node; | 1217 | struct ubifs_mst_node *mst_node; |
1176 | int mst_offs; | 1218 | int mst_offs; |
1177 | struct mutex mst_mutex; | 1219 | struct mutex mst_mutex; |
1220 | int bulk_read_buf_size; | ||
1178 | 1221 | ||
1179 | int log_lebs; | 1222 | int log_lebs; |
1180 | long long log_bytes; | 1223 | long long log_bytes; |
@@ -1218,6 +1261,8 @@ struct ubifs_info { | |||
1218 | unsigned long long old_idx_sz; | 1261 | unsigned long long old_idx_sz; |
1219 | unsigned long long calc_idx_sz; | 1262 | unsigned long long calc_idx_sz; |
1220 | struct ubifs_lp_stats lst; | 1263 | struct ubifs_lp_stats lst; |
1264 | unsigned int nospace:1; | ||
1265 | unsigned int nospace_rp:1; | ||
1221 | 1266 | ||
1222 | int page_budget; | 1267 | int page_budget; |
1223 | int inode_budget; | 1268 | int inode_budget; |
@@ -1294,6 +1339,7 @@ struct ubifs_info { | |||
1294 | int lpt_drty_flgs; | 1339 | int lpt_drty_flgs; |
1295 | int dirty_nn_cnt; | 1340 | int dirty_nn_cnt; |
1296 | int dirty_pn_cnt; | 1341 | int dirty_pn_cnt; |
1342 | int check_lpt_free; | ||
1297 | long long lpt_sz; | 1343 | long long lpt_sz; |
1298 | void *lpt_nod_buf; | 1344 | void *lpt_nod_buf; |
1299 | void *lpt_buf; | 1345 | void *lpt_buf; |
@@ -1335,6 +1381,7 @@ struct ubifs_info { | |||
1335 | struct ubifs_mst_node *rcvrd_mst_node; | 1381 | struct ubifs_mst_node *rcvrd_mst_node; |
1336 | struct rb_root size_tree; | 1382 | struct rb_root size_tree; |
1337 | int remounting_rw; | 1383 | int remounting_rw; |
1384 | int always_chk_crc; | ||
1338 | struct ubifs_mount_opts mount_opts; | 1385 | struct ubifs_mount_opts mount_opts; |
1339 | 1386 | ||
1340 | #ifdef CONFIG_UBIFS_FS_DEBUG | 1387 | #ifdef CONFIG_UBIFS_FS_DEBUG |
@@ -1347,6 +1394,12 @@ struct ubifs_info { | |||
1347 | unsigned long fail_timeout; | 1394 | unsigned long fail_timeout; |
1348 | unsigned int fail_cnt; | 1395 | unsigned int fail_cnt; |
1349 | unsigned int fail_cnt_max; | 1396 | unsigned int fail_cnt_max; |
1397 | long long chk_lpt_sz; | ||
1398 | long long chk_lpt_sz2; | ||
1399 | long long chk_lpt_wastage; | ||
1400 | int chk_lpt_lebs; | ||
1401 | int new_nhead_lnum; | ||
1402 | int new_nhead_offs; | ||
1350 | #endif | 1403 | #endif |
1351 | }; | 1404 | }; |
1352 | 1405 | ||
@@ -1377,7 +1430,7 @@ int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, | |||
1377 | int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, | 1430 | int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, |
1378 | int offs, int dtype); | 1431 | int offs, int dtype); |
1379 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, | 1432 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, |
1380 | int offs, int quiet); | 1433 | int offs, int quiet, int chk_crc); |
1381 | void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); | 1434 | void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); |
1382 | void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); | 1435 | void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); |
1383 | int ubifs_io_init(struct ubifs_info *c); | 1436 | int ubifs_io_init(struct ubifs_info *c); |
@@ -1490,6 +1543,8 @@ void destroy_old_idx(struct ubifs_info *c); | |||
1490 | int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level, | 1543 | int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level, |
1491 | int lnum, int offs); | 1544 | int lnum, int offs); |
1492 | int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode); | 1545 | int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode); |
1546 | int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu); | ||
1547 | int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu); | ||
1493 | 1548 | ||
1494 | /* tnc_misc.c */ | 1549 | /* tnc_misc.c */ |
1495 | struct ubifs_znode *ubifs_tnc_levelorder_next(struct ubifs_znode *zr, | 1550 | struct ubifs_znode *ubifs_tnc_levelorder_next(struct ubifs_znode *zr, |
@@ -1586,12 +1641,10 @@ int ubifs_lpt_post_commit(struct ubifs_info *c); | |||
1586 | void ubifs_lpt_free(struct ubifs_info *c, int wr_only); | 1641 | void ubifs_lpt_free(struct ubifs_info *c, int wr_only); |
1587 | 1642 | ||
1588 | /* lprops.c */ | 1643 | /* lprops.c */ |
1589 | void ubifs_get_lprops(struct ubifs_info *c); | ||
1590 | const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, | 1644 | const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, |
1591 | const struct ubifs_lprops *lp, | 1645 | const struct ubifs_lprops *lp, |
1592 | int free, int dirty, int flags, | 1646 | int free, int dirty, int flags, |
1593 | int idx_gc_cnt); | 1647 | int idx_gc_cnt); |
1594 | void ubifs_release_lprops(struct ubifs_info *c); | ||
1595 | void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *stats); | 1648 | void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *stats); |
1596 | void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops, | 1649 | void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops, |
1597 | int cat); | 1650 | int cat); |
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c index 649bec78b645..cfd31e229c89 100644 --- a/fs/ubifs/xattr.c +++ b/fs/ubifs/xattr.c | |||
@@ -446,7 +446,7 @@ ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size) | |||
446 | int type; | 446 | int type; |
447 | 447 | ||
448 | xent = ubifs_tnc_next_ent(c, &key, &nm); | 448 | xent = ubifs_tnc_next_ent(c, &key, &nm); |
449 | if (unlikely(IS_ERR(xent))) { | 449 | if (IS_ERR(xent)) { |
450 | err = PTR_ERR(xent); | 450 | err = PTR_ERR(xent); |
451 | break; | 451 | break; |
452 | } | 452 | } |