diff options
Diffstat (limited to 'fs/ubifs/super.c')
-rw-r--r-- | fs/ubifs/super.c | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 8780efbf40ac..d80b2aef42b6 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c | |||
@@ -36,6 +36,12 @@ | |||
36 | #include <linux/mount.h> | 36 | #include <linux/mount.h> |
37 | #include "ubifs.h" | 37 | #include "ubifs.h" |
38 | 38 | ||
39 | /* | ||
40 | * Maximum amount of memory we may 'kmalloc()' without worrying that we are | ||
41 | * allocating too much. | ||
42 | */ | ||
43 | #define UBIFS_KMALLOC_OK (128*1024) | ||
44 | |||
39 | /* Slab cache for UBIFS inodes */ | 45 | /* Slab cache for UBIFS inodes */ |
40 | struct kmem_cache *ubifs_inode_slab; | 46 | struct kmem_cache *ubifs_inode_slab; |
41 | 47 | ||
@@ -561,18 +567,11 @@ static int init_constants_early(struct ubifs_info *c) | |||
561 | * calculations when reporting free space. | 567 | * calculations when reporting free space. |
562 | */ | 568 | */ |
563 | c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ; | 569 | 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 | 570 | ||
572 | kfree(try); | 571 | /* Buffer size for bulk-reads */ |
573 | if (!try) | 572 | c->max_bu_buf_len = UBIFS_MAX_BULK_READ * UBIFS_MAX_DATA_NODE_SZ; |
574 | c->bulk_read_buf_size = 128 * 1024; | 573 | if (c->max_bu_buf_len > c->leb_size) |
575 | } | 574 | c->max_bu_buf_len = c->leb_size; |
576 | return 0; | 575 | return 0; |
577 | } | 576 | } |
578 | 577 | ||
@@ -992,6 +991,34 @@ static void destroy_journal(struct ubifs_info *c) | |||
992 | } | 991 | } |
993 | 992 | ||
994 | /** | 993 | /** |
994 | * bu_init - initialize bulk-read information. | ||
995 | * @c: UBIFS file-system description object | ||
996 | */ | ||
997 | static void bu_init(struct ubifs_info *c) | ||
998 | { | ||
999 | ubifs_assert(c->bulk_read == 1); | ||
1000 | |||
1001 | if (c->bu.buf) | ||
1002 | return; /* Already initialized */ | ||
1003 | |||
1004 | again: | ||
1005 | c->bu.buf = kmalloc(c->max_bu_buf_len, GFP_KERNEL | __GFP_NOWARN); | ||
1006 | if (!c->bu.buf) { | ||
1007 | if (c->max_bu_buf_len > UBIFS_KMALLOC_OK) { | ||
1008 | c->max_bu_buf_len = UBIFS_KMALLOC_OK; | ||
1009 | goto again; | ||
1010 | } | ||
1011 | |||
1012 | /* Just disable bulk-read */ | ||
1013 | ubifs_warn("Cannot allocate %d bytes of memory for bulk-read, " | ||
1014 | "disabling it", c->max_bu_buf_len); | ||
1015 | c->mount_opts.bulk_read = 1; | ||
1016 | c->bulk_read = 0; | ||
1017 | return; | ||
1018 | } | ||
1019 | } | ||
1020 | |||
1021 | /** | ||
995 | * mount_ubifs - mount UBIFS file-system. | 1022 | * mount_ubifs - mount UBIFS file-system. |
996 | * @c: UBIFS file-system description object | 1023 | * @c: UBIFS file-system description object |
997 | * | 1024 | * |
@@ -1059,6 +1086,13 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1059 | goto out_free; | 1086 | goto out_free; |
1060 | } | 1087 | } |
1061 | 1088 | ||
1089 | if (c->bulk_read == 1) | ||
1090 | bu_init(c); | ||
1091 | |||
1092 | /* | ||
1093 | * We have to check all CRCs, even for data nodes, when we mount the FS | ||
1094 | * (specifically, when we are replaying). | ||
1095 | */ | ||
1062 | c->always_chk_crc = 1; | 1096 | c->always_chk_crc = 1; |
1063 | 1097 | ||
1064 | err = ubifs_read_superblock(c); | 1098 | err = ubifs_read_superblock(c); |
@@ -1289,6 +1323,7 @@ out_cbuf: | |||
1289 | out_dereg: | 1323 | out_dereg: |
1290 | dbg_failure_mode_deregistration(c); | 1324 | dbg_failure_mode_deregistration(c); |
1291 | out_free: | 1325 | out_free: |
1326 | kfree(c->bu.buf); | ||
1292 | vfree(c->ileb_buf); | 1327 | vfree(c->ileb_buf); |
1293 | vfree(c->sbuf); | 1328 | vfree(c->sbuf); |
1294 | kfree(c->bottom_up_buf); | 1329 | kfree(c->bottom_up_buf); |
@@ -1325,10 +1360,11 @@ static void ubifs_umount(struct ubifs_info *c) | |||
1325 | kfree(c->cbuf); | 1360 | kfree(c->cbuf); |
1326 | kfree(c->rcvrd_mst_node); | 1361 | kfree(c->rcvrd_mst_node); |
1327 | kfree(c->mst_node); | 1362 | kfree(c->mst_node); |
1363 | kfree(c->bu.buf); | ||
1364 | vfree(c->ileb_buf); | ||
1328 | vfree(c->sbuf); | 1365 | vfree(c->sbuf); |
1329 | kfree(c->bottom_up_buf); | 1366 | kfree(c->bottom_up_buf); |
1330 | UBIFS_DBG(vfree(c->dbg_buf)); | 1367 | UBIFS_DBG(vfree(c->dbg_buf)); |
1331 | vfree(c->ileb_buf); | ||
1332 | dbg_failure_mode_deregistration(c); | 1368 | dbg_failure_mode_deregistration(c); |
1333 | } | 1369 | } |
1334 | 1370 | ||
@@ -1626,6 +1662,7 @@ static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data) | |||
1626 | ubifs_err("invalid or unknown remount parameter"); | 1662 | ubifs_err("invalid or unknown remount parameter"); |
1627 | return err; | 1663 | return err; |
1628 | } | 1664 | } |
1665 | |||
1629 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { | 1666 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { |
1630 | err = ubifs_remount_rw(c); | 1667 | err = ubifs_remount_rw(c); |
1631 | if (err) | 1668 | if (err) |
@@ -1633,6 +1670,14 @@ static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data) | |||
1633 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) | 1670 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) |
1634 | ubifs_remount_ro(c); | 1671 | ubifs_remount_ro(c); |
1635 | 1672 | ||
1673 | if (c->bulk_read == 1) | ||
1674 | bu_init(c); | ||
1675 | else { | ||
1676 | dbg_gen("disable bulk-read"); | ||
1677 | kfree(c->bu.buf); | ||
1678 | c->bu.buf = NULL; | ||
1679 | } | ||
1680 | |||
1636 | return 0; | 1681 | return 0; |
1637 | } | 1682 | } |
1638 | 1683 | ||
@@ -1723,6 +1768,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent) | |||
1723 | mutex_init(&c->log_mutex); | 1768 | mutex_init(&c->log_mutex); |
1724 | mutex_init(&c->mst_mutex); | 1769 | mutex_init(&c->mst_mutex); |
1725 | mutex_init(&c->umount_mutex); | 1770 | mutex_init(&c->umount_mutex); |
1771 | mutex_init(&c->bu_mutex); | ||
1726 | init_waitqueue_head(&c->cmt_wq); | 1772 | init_waitqueue_head(&c->cmt_wq); |
1727 | c->buds = RB_ROOT; | 1773 | c->buds = RB_ROOT; |
1728 | c->old_idx = RB_ROOT; | 1774 | c->old_idx = RB_ROOT; |