Skip to content

Commit 8f627a8

Browse files
committed
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: clean-up commentaries UBIFS: save 128KiB or more RAM UBIFS: allocate orphans scan buffer on demand UBIFS: allocate lpt dump buffer on demand UBIFS: allocate ltab checking buffer on demand UBIFS: allocate scanning buffer on demand UBIFS: allocate dump buffer on demand UBIFS: do not check data crc by default UBIFS: simplify UBIFS Kconfig menu UBIFS: print max. index node size UBIFS: handle allocation failures in UBIFS write path UBIFS: use max_write_size during recovery UBIFS: use max_write_size for write-buffers UBIFS: introduce write-buffer size field UBI: incorporate LEB offset information UBIFS: incorporate maximum write size UBI: provide LEB offset information UBI: incorporate maximum write size UBIFS: fix LEB number in printk UBIFS: restrict world-writable debugfs files ...
2 parents fd57ed0 + 5d630e4 commit 8f627a8

19 files changed

Lines changed: 490 additions & 176 deletions

File tree

‎Documentation/filesystems/ubifs.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ Mount options
8282
bulk_read read more in one go to take advantage of flash
8383
media that read faster sequentially
8484
no_bulk_read (*) do not bulk-read
85-
no_chk_data_crc skip checking of CRCs on data nodes in order to
85+
no_chk_data_crc (*) skip checking of CRCs on data nodes in order to
8686
improve read performance. Use this option only
8787
if the flash media is highly reliable. The effect
8888
of this option is that corruption of the contents
8989
of a file can go unnoticed.
90-
chk_data_crc (*) do not skip checking CRCs on data nodes
90+
chk_data_crc do not skip checking CRCs on data nodes
9191
compr=none override default compressor and set it to "none"
9292
compr=lzo override default compressor and set it to "lzo"
9393
compr=zlib override default compressor and set it to "zlib"

‎drivers/mtd/ubi/build.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,25 @@ static int io_init(struct ubi_device *ubi)
690690
ubi_assert(ubi->hdrs_min_io_size <= ubi->min_io_size);
691691
ubi_assert(ubi->min_io_size % ubi->hdrs_min_io_size == 0);
692692

693+
ubi->max_write_size = ubi->mtd->writebufsize;
694+
/*
695+
* Maximum write size has to be greater or equivalent to min. I/O
696+
* size, and be multiple of min. I/O size.
697+
*/
698+
if (ubi->max_write_size < ubi->min_io_size ||
699+
ubi->max_write_size % ubi->min_io_size ||
700+
!is_power_of_2(ubi->max_write_size)) {
701+
ubi_err("bad write buffer size %d for %d min. I/O unit",
702+
ubi->max_write_size, ubi->min_io_size);
703+
return -EINVAL;
704+
}
705+
693706
/* Calculate default aligned sizes of EC and VID headers */
694707
ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size);
695708
ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size);
696709

697710
dbg_msg("min_io_size %d", ubi->min_io_size);
711+
dbg_msg("max_write_size %d", ubi->max_write_size);
698712
dbg_msg("hdrs_min_io_size %d", ubi->hdrs_min_io_size);
699713
dbg_msg("ec_hdr_alsize %d", ubi->ec_hdr_alsize);
700714
dbg_msg("vid_hdr_alsize %d", ubi->vid_hdr_alsize);

‎drivers/mtd/ubi/kapi.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di)
4040
{
4141
di->ubi_num = ubi->ubi_num;
4242
di->leb_size = ubi->leb_size;
43+
di->leb_start = ubi->leb_start;
4344
di->min_io_size = ubi->min_io_size;
45+
di->max_write_size = ubi->max_write_size;
4446
di->ro_mode = ubi->ro_mode;
4547
di->cdev = ubi->cdev.dev;
4648
}

‎drivers/mtd/ubi/ubi.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ struct ubi_wl_entry;
382382
* @bad_allowed: whether the MTD device admits of bad physical eraseblocks or
383383
* not
384384
* @nor_flash: non-zero if working on top of NOR flash
385+
* @max_write_size: maximum amount of bytes the underlying flash can write at a
386+
* time (MTD write buffer size)
385387
* @mtd: MTD device descriptor
386388
*
387389
* @peb_buf1: a buffer of PEB size used for different purposes
@@ -463,6 +465,7 @@ struct ubi_device {
463465
int vid_hdr_shift;
464466
unsigned int bad_allowed:1;
465467
unsigned int nor_flash:1;
468+
int max_write_size;
466469
struct mtd_info *mtd;
467470

468471
void *peb_buf1;

‎fs/ubifs/Kconfig‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,20 @@ config UBIFS_FS_ZLIB
4444

4545
# Debugging-related stuff
4646
config UBIFS_FS_DEBUG
47-
bool "Enable debugging"
47+
bool "Enable debugging support"
4848
depends on UBIFS_FS
4949
select DEBUG_FS
5050
select KALLSYMS_ALL
5151
help
52-
This option enables UBIFS debugging.
53-
54-
config UBIFS_FS_DEBUG_MSG_LVL
55-
int "Default message level (0 = no extra messages, 3 = lots)"
56-
depends on UBIFS_FS_DEBUG
57-
default "0"
58-
help
59-
This controls the amount of debugging messages produced by UBIFS.
60-
If reporting bugs, please try to have available a full dump of the
61-
messages at level 1 while the misbehaviour was occurring. Level 2
62-
may become necessary if level 1 messages were not enough to find the
63-
bug. Generally Level 3 should be avoided.
52+
This option enables UBIFS debugging support. It makes sure various
53+
assertions, self-checks, debugging messages and test modes are compiled
54+
in (this all is compiled out otherwise). Assertions are light-weight
55+
and this option also enables them. Self-checks, debugging messages and
56+
test modes are switched off by default. Thus, it is safe and actually
57+
recommended to have debugging support enabled, and it should not slow
58+
down UBIFS. You can then further enable / disable individual debugging
59+
features using UBIFS module parameters and the corresponding sysfs
60+
interfaces.
6461

6562
config UBIFS_FS_DEBUG_CHKS
6663
bool "Enable extra checks"

‎fs/ubifs/commit.c‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,56 @@
4848
#include <linux/slab.h>
4949
#include "ubifs.h"
5050

51+
/*
52+
* nothing_to_commit - check if there is nothing to commit.
53+
* @c: UBIFS file-system description object
54+
*
55+
* This is a helper function which checks if there is anything to commit. It is
56+
* used as an optimization to avoid starting the commit if it is not really
57+
* necessary. Indeed, the commit operation always assumes flash I/O (e.g.,
58+
* writing the commit start node to the log), and it is better to avoid doing
59+
* this unnecessarily. E.g., 'ubifs_sync_fs()' runs the commit, but if there is
60+
* nothing to commit, it is more optimal to avoid any flash I/O.
61+
*
62+
* This function has to be called with @c->commit_sem locked for writing -
63+
* this function does not take LPT/TNC locks because the @c->commit_sem
64+
* guarantees that we have exclusive access to the TNC and LPT data structures.
65+
*
66+
* This function returns %1 if there is nothing to commit and %0 otherwise.
67+
*/
68+
static int nothing_to_commit(struct ubifs_info *c)
69+
{
70+
/*
71+
* During mounting or remounting from R/O mode to R/W mode we may
72+
* commit for various recovery-related reasons.
73+
*/
74+
if (c->mounting || c->remounting_rw)
75+
return 0;
76+
77+
/*
78+
* If the root TNC node is dirty, we definitely have something to
79+
* commit.
80+
*/
81+
if (c->zroot.znode && test_bit(DIRTY_ZNODE, &c->zroot.znode->flags))
82+
return 0;
83+
84+
/*
85+
* Even though the TNC is clean, the LPT tree may have dirty nodes. For
86+
* example, this may happen if the budgeting subsystem invoked GC to
87+
* make some free space, and the GC found an LEB with only dirty and
88+
* free space. In this case GC would just change the lprops of this
89+
* LEB (by turning all space into free space) and unmap it.
90+
*/
91+
if (c->nroot && test_bit(DIRTY_CNODE, &c->nroot->flags))
92+
return 0;
93+
94+
ubifs_assert(atomic_long_read(&c->dirty_zn_cnt) == 0);
95+
ubifs_assert(c->dirty_pn_cnt == 0);
96+
ubifs_assert(c->dirty_nn_cnt == 0);
97+
98+
return 1;
99+
}
100+
51101
/**
52102
* do_commit - commit the journal.
53103
* @c: UBIFS file-system description object
@@ -70,6 +120,12 @@ static int do_commit(struct ubifs_info *c)
70120
goto out_up;
71121
}
72122

123+
if (nothing_to_commit(c)) {
124+
up_write(&c->commit_sem);
125+
err = 0;
126+
goto out_cancel;
127+
}
128+
73129
/* Sync all write buffers (necessary for recovery) */
74130
for (i = 0; i < c->jhead_cnt; i++) {
75131
err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
@@ -162,12 +218,12 @@ static int do_commit(struct ubifs_info *c)
162218
if (err)
163219
goto out;
164220

221+
out_cancel:
165222
spin_lock(&c->cs_lock);
166223
c->cmt_state = COMMIT_RESTING;
167224
wake_up(&c->cmt_wq);
168225
dbg_cmt("commit end");
169226
spin_unlock(&c->cs_lock);
170-
171227
return 0;
172228

173229
out_up:

‎fs/ubifs/debug.c‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ DEFINE_SPINLOCK(dbg_lock);
4343
static char dbg_key_buf0[128];
4444
static char dbg_key_buf1[128];
4545

46-
unsigned int ubifs_msg_flags = UBIFS_MSG_FLAGS_DEFAULT;
47-
unsigned int ubifs_chk_flags = UBIFS_CHK_FLAGS_DEFAULT;
46+
unsigned int ubifs_msg_flags;
47+
unsigned int ubifs_chk_flags;
4848
unsigned int ubifs_tst_flags;
4949

5050
module_param_named(debug_msgs, ubifs_msg_flags, uint, S_IRUGO | S_IWUSR);
@@ -810,16 +810,24 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
810810
{
811811
struct ubifs_scan_leb *sleb;
812812
struct ubifs_scan_node *snod;
813+
void *buf;
813814

814815
if (dbg_failure_mode)
815816
return;
816817

817818
printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n",
818819
current->pid, lnum);
819-
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf, 0);
820+
821+
buf = __vmalloc(c->leb_size, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
822+
if (!buf) {
823+
ubifs_err("cannot allocate memory for dumping LEB %d", lnum);
824+
return;
825+
}
826+
827+
sleb = ubifs_scan(c, lnum, 0, buf, 0);
820828
if (IS_ERR(sleb)) {
821829
ubifs_err("scan error %d", (int)PTR_ERR(sleb));
822-
return;
830+
goto out;
823831
}
824832

825833
printk(KERN_DEBUG "LEB %d has %d nodes ending at %d\n", lnum,
@@ -835,6 +843,9 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
835843
printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n",
836844
current->pid, lnum);
837845
ubifs_scan_destroy(sleb);
846+
847+
out:
848+
vfree(buf);
838849
return;
839850
}
840851

@@ -2690,16 +2701,8 @@ int ubifs_debugging_init(struct ubifs_info *c)
26902701
if (!c->dbg)
26912702
return -ENOMEM;
26922703

2693-
c->dbg->buf = vmalloc(c->leb_size);
2694-
if (!c->dbg->buf)
2695-
goto out;
2696-
26972704
failure_mode_init(c);
26982705
return 0;
2699-
2700-
out:
2701-
kfree(c->dbg);
2702-
return -ENOMEM;
27032706
}
27042707

27052708
/**
@@ -2709,7 +2712,6 @@ int ubifs_debugging_init(struct ubifs_info *c)
27092712
void ubifs_debugging_exit(struct ubifs_info *c)
27102713
{
27112714
failure_mode_exit(c);
2712-
vfree(c->dbg->buf);
27132715
kfree(c->dbg);
27142716
}
27152717

@@ -2813,19 +2815,19 @@ int dbg_debugfs_init_fs(struct ubifs_info *c)
28132815
}
28142816

28152817
fname = "dump_lprops";
2816-
dent = debugfs_create_file(fname, S_IWUGO, d->dfs_dir, c, &dfs_fops);
2818+
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops);
28172819
if (IS_ERR(dent))
28182820
goto out_remove;
28192821
d->dfs_dump_lprops = dent;
28202822

28212823
fname = "dump_budg";
2822-
dent = debugfs_create_file(fname, S_IWUGO, d->dfs_dir, c, &dfs_fops);
2824+
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops);
28232825
if (IS_ERR(dent))
28242826
goto out_remove;
28252827
d->dfs_dump_budg = dent;
28262828

28272829
fname = "dump_tnc";
2828-
dent = debugfs_create_file(fname, S_IWUGO, d->dfs_dir, c, &dfs_fops);
2830+
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops);
28292831
if (IS_ERR(dent))
28302832
goto out_remove;
28312833
d->dfs_dump_tnc = dent;

‎fs/ubifs/debug.h‎

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
/**
2929
* ubifs_debug_info - per-FS debugging information.
30-
* @buf: a buffer of LEB size, used for various purposes
3130
* @old_zroot: old index root - used by 'dbg_check_old_index()'
3231
* @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
3332
* @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
@@ -54,7 +53,6 @@
5453
* dfs_dump_tnc: "dump TNC" debugfs knob
5554
*/
5655
struct ubifs_debug_info {
57-
void *buf;
5856
struct ubifs_zbranch old_zroot;
5957
int old_zroot_level;
6058
unsigned long long old_zroot_sqnum;
@@ -173,7 +171,7 @@ const char *dbg_key_str1(const struct ubifs_info *c,
173171
#define dbg_rcvry(fmt, ...) dbg_do_msg(UBIFS_MSG_RCVRY, fmt, ##__VA_ARGS__)
174172

175173
/*
176-
* Debugging message type flags (must match msg_type_names in debug.c).
174+
* Debugging message type flags.
177175
*
178176
* UBIFS_MSG_GEN: general messages
179177
* UBIFS_MSG_JNL: journal messages
@@ -205,14 +203,8 @@ enum {
205203
UBIFS_MSG_RCVRY = 0x1000,
206204
};
207205

208-
/* Debugging message type flags for each default debug message level */
209-
#define UBIFS_MSG_LVL_0 0
210-
#define UBIFS_MSG_LVL_1 0x1
211-
#define UBIFS_MSG_LVL_2 0x7f
212-
#define UBIFS_MSG_LVL_3 0xffff
213-
214206
/*
215-
* Debugging check flags (must match chk_names in debug.c).
207+
* Debugging check flags.
216208
*
217209
* UBIFS_CHK_GEN: general checks
218210
* UBIFS_CHK_TNC: check TNC
@@ -233,7 +225,7 @@ enum {
233225
};
234226

235227
/*
236-
* Special testing flags (must match tst_names in debug.c).
228+
* Special testing flags.
237229
*
238230
* UBIFS_TST_FORCE_IN_THE_GAPS: force the use of in-the-gaps method
239231
* UBIFS_TST_RCVRY: failure mode for recovery testing
@@ -243,22 +235,6 @@ enum {
243235
UBIFS_TST_RCVRY = 0x4,
244236
};
245237

246-
#if CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 1
247-
#define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_1
248-
#elif CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 2
249-
#define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_2
250-
#elif CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 3
251-
#define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_3
252-
#else
253-
#define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_0
254-
#endif
255-
256-
#ifdef CONFIG_UBIFS_FS_DEBUG_CHKS
257-
#define UBIFS_CHK_FLAGS_DEFAULT 0xffffffff
258-
#else
259-
#define UBIFS_CHK_FLAGS_DEFAULT 0
260-
#endif
261-
262238
extern spinlock_t dbg_lock;
263239

264240
extern unsigned int ubifs_msg_flags;

0 commit comments

Comments
 (0)