Skip to content

Commit 92abc47

Browse files
dilingerdedekind
authored andcommitted
jffs2: implement mount option parsing and compression overriding
Currently jffs2 has compile-time constants (and .config options) controlling whether or not the various compression/decompression drivers are built in and enabled. This is fine for embedded systems, but it clashes with distribution kernels. Distro kernels tend to turn on everything; this causes OpenFirmware to fall over, as it understands ZLIB-compressed inodes. Booting a kernel that has LZO compression enabled, writing to the boot partition, and then rebooting causes OFW to fail to read the kernel from the filesystem. This is because LZO compression has priority when writing new data to jffs2, if LZO is enabled. This patch adds mount option parsing, and a single supported option ("compr=none"). This adds the flexibility of being able to specify which compressor overrides on a per-superblock basis. For now, we can simply disable compression; additional flexibility coming soon. v2: kill some printks, and implement show_options as suggested by Artem Bityutskiy. Signed-off-by: Andres Salomon <dilinger@queued.net> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
1 parent 23b1a99 commit 92abc47

5 files changed

Lines changed: 112 additions & 4 deletions

File tree

‎fs/jffs2/compr.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,18 @@ uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
7676
uint32_t *datalen, uint32_t *cdatalen)
7777
{
7878
int ret = JFFS2_COMPR_NONE;
79-
int compr_ret;
79+
int mode, compr_ret;
8080
struct jffs2_compressor *this, *best=NULL;
8181
unsigned char *output_buf = NULL, *tmp_buf;
8282
uint32_t orig_slen, orig_dlen;
8383
uint32_t best_slen=0, best_dlen=0;
8484

85-
switch (jffs2_compression_mode) {
85+
if (c->mount_opts.override_compr)
86+
mode = c->mount_opts.compr;
87+
else
88+
mode = jffs2_compression_mode;
89+
90+
switch (mode) {
8691
case JFFS2_COMPR_MODE_NONE:
8792
break;
8893
case JFFS2_COMPR_MODE_PRIORITY:

‎fs/jffs2/fs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void jffs2_dirty_inode(struct inode *inode, int flags)
379379
jffs2_do_setattr(inode, &iattr);
380380
}
381381

382-
int jffs2_remount_fs (struct super_block *sb, int *flags, char *data)
382+
int jffs2_do_remount_fs(struct super_block *sb, int *flags, char *data)
383383
{
384384
struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
385385

‎fs/jffs2/jffs2_fs_sb.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
struct jffs2_inodirty;
3131

32+
struct jffs2_mount_opts {
33+
bool override_compr;
34+
unsigned int compr;
35+
};
36+
3237
/* A struct for the overall file system control. Pointers to
3338
jffs2_sb_info structs are named `c' in the source code.
3439
Nee jffs_control
@@ -126,6 +131,7 @@ struct jffs2_sb_info {
126131
#endif
127132

128133
struct jffs2_summary *summary; /* Summary information */
134+
struct jffs2_mount_opts mount_opts;
129135

130136
#ifdef CONFIG_JFFS2_FS_XATTR
131137
#define XATTRINDEX_HASHSIZE (57)

‎fs/jffs2/os-linux.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void jffs2_dirty_inode(struct inode *inode, int flags);
176176
struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode,
177177
struct jffs2_raw_inode *ri);
178178
int jffs2_statfs (struct dentry *, struct kstatfs *);
179-
int jffs2_remount_fs (struct super_block *, int *, char *);
179+
int jffs2_do_remount_fs(struct super_block *, int *, char *);
180180
int jffs2_do_fill_super(struct super_block *sb, void *data, int silent);
181181
void jffs2_gc_release_inode(struct jffs2_sb_info *c,
182182
struct jffs2_inode_info *f);

‎fs/jffs2/super.c‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
#include <linux/fs.h>
1818
#include <linux/err.h>
1919
#include <linux/mount.h>
20+
#include <linux/parser.h>
2021
#include <linux/jffs2.h>
2122
#include <linux/pagemap.h>
2223
#include <linux/mtd/super.h>
2324
#include <linux/ctype.h>
2425
#include <linux/namei.h>
26+
#include <linux/seq_file.h>
2527
#include <linux/exportfs.h>
2628
#include "compr.h"
2729
#include "nodelist.h"
@@ -75,6 +77,29 @@ static void jffs2_write_super(struct super_block *sb)
7577
unlock_super(sb);
7678
}
7779

80+
static const char *jffs2_compr_name(unsigned int compr)
81+
{
82+
switch (compr) {
83+
case JFFS2_COMPR_MODE_NONE:
84+
return "none";
85+
default:
86+
/* should never happen; programmer error */
87+
WARN_ON(1);
88+
return "";
89+
}
90+
}
91+
92+
static int jffs2_show_options(struct seq_file *s, struct vfsmount *mnt)
93+
{
94+
struct jffs2_sb_info *c = JFFS2_SB_INFO(mnt->mnt_sb);
95+
struct jffs2_mount_opts *opts = &c->mount_opts;
96+
97+
if (opts->override_compr)
98+
seq_printf(s, ",compr=%s", jffs2_compr_name(opts->compr));
99+
100+
return 0;
101+
}
102+
78103
static int jffs2_sync_fs(struct super_block *sb, int wait)
79104
{
80105
struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
@@ -133,6 +158,71 @@ static const struct export_operations jffs2_export_ops = {
133158
.fh_to_parent = jffs2_fh_to_parent,
134159
};
135160

161+
/*
162+
* JFFS2 mount options.
163+
*
164+
* Opt_override_compr: override default compressor
165+
* Opt_err: just end of array marker
166+
*/
167+
enum {
168+
Opt_override_compr,
169+
Opt_err,
170+
};
171+
172+
static const match_table_t tokens = {
173+
{Opt_override_compr, "compr=%s"},
174+
{Opt_err, NULL},
175+
};
176+
177+
static int jffs2_parse_options(struct jffs2_sb_info *c, char *data)
178+
{
179+
substring_t args[MAX_OPT_ARGS];
180+
char *p, *name;
181+
182+
if (!data)
183+
return 0;
184+
185+
while ((p = strsep(&data, ","))) {
186+
int token;
187+
188+
if (!*p)
189+
continue;
190+
191+
token = match_token(p, tokens, args);
192+
switch (token) {
193+
case Opt_override_compr:
194+
name = match_strdup(&args[0]);
195+
196+
if (!name)
197+
return -ENOMEM;
198+
if (!strcmp(name, "none")) {
199+
c->mount_opts.compr = JFFS2_COMPR_MODE_NONE;
200+
c->mount_opts.override_compr = true;
201+
}
202+
kfree(name);
203+
break;
204+
default:
205+
printk(KERN_ERR "JFFS2 Error: unrecognized mount option '%s' or missing value\n",
206+
p);
207+
return -EINVAL;
208+
}
209+
}
210+
211+
return 0;
212+
}
213+
214+
static int jffs2_remount_fs(struct super_block *sb, int *flags, char *data)
215+
{
216+
struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
217+
int err;
218+
219+
err = jffs2_parse_options(c, data);
220+
if (err)
221+
return -EINVAL;
222+
223+
return jffs2_do_remount_fs(sb, flags, data);
224+
}
225+
136226
static const struct super_operations jffs2_super_operations =
137227
{
138228
.alloc_inode = jffs2_alloc_inode,
@@ -143,6 +233,7 @@ static const struct super_operations jffs2_super_operations =
143233
.remount_fs = jffs2_remount_fs,
144234
.evict_inode = jffs2_evict_inode,
145235
.dirty_inode = jffs2_dirty_inode,
236+
.show_options = jffs2_show_options,
146237
.sync_fs = jffs2_sync_fs,
147238
};
148239

@@ -166,6 +257,12 @@ static int jffs2_fill_super(struct super_block *sb, void *data, int silent)
166257
c->os_priv = sb;
167258
sb->s_fs_info = c;
168259

260+
ret = jffs2_parse_options(c, data);
261+
if (ret) {
262+
kfree(c);
263+
return -EINVAL;
264+
}
265+
169266
/* Initialize JFFS2 superblock locks, the further initialization will
170267
* be done later */
171268
mutex_init(&c->alloc_sem);

0 commit comments

Comments
 (0)