RFC: direct MTD support for SquashFS
Subsystems (3)
Hi,
In embedded systems, SquashFS over MTD would be a considerable win, as that would permit configuring without CONFIG_BLOCK. Please find attached a naive patch against 2.6.33 for this. It does not handle bad MTD blocks, that could be handled by gluebi (once you're willing to take the UBI overhead), or by a custom solution later.
For now, 2.6.34 gained pluggable decompressors, so this patch does not apply anymore, though the main idea holds. My questions: is the community interested in integrating something like this, should this patch transformed into something acceptable, or am I a total lunatic? I don't know a thing about filesystem development, but willing to learn and refactor. Comments welcome.
Signature · 2 lines
Thanks, Feri.
Quoted 1 line
From
27c686fd47a7ed4edef1ecbe9bb26402774df4a6Mon Sep 17 00:00:00 2001
From: Ferenc Wagner <[email protected]>
Date: Tue, 16 Mar 2010 11:49:12 +0100
Subject: [PATCH] squashfs: add direct MTD support
--- fs/squashfs/Kconfig | 2 +- fs/squashfs/block.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++--- fs/squashfs/super.c | 51 ++++++++++++--- 3 files changed, 210 insertions(+), 21 deletions(-)
fs/squashfs/Kconfig +1 -1
@@ -1,6 +1,6 @@ config SQUASHFS tristate "SquashFS 4.0 - Squashed file system support" - depends on BLOCK + depends on MTD select ZLIB_INFLATE help Saying Y here includes support for SquashFS 4.0 (a Compressed
fs/squashfs/block.c +167 -11
203 lines not on this page · raw message
fs/squashfs/super.c +42 -9
103 lines not on this page · raw message
Signature · 1 line
1.5.6.5
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Ferenc" == Ferenc Wagner <[email protected]> writes:
Ferenc> Hi,
Ferenc> In embedded systems, SquashFS over MTD would be a considerable Ferenc> win, as that would permit configuring without CONFIG_BLOCK. Ferenc> Please find attached a naive patch against 2.6.33 for this. It Ferenc> does not handle bad MTD blocks, that could be handled by gluebi Ferenc> (once you're willing to take the UBI overhead), or by a custom Ferenc> solution later.
Ferenc> For now, 2.6.34 gained pluggable decompressors, so this patch Ferenc> does not apply anymore, though the main idea holds. My Ferenc> questions: is the community interested in integrating something Ferenc> like this, should this patch transformed into something Ferenc> acceptable, or am I a total lunatic? I don't know a thing Ferenc> about filesystem development, but willing to learn and Ferenc> refactor. Comments welcome.
Nice, I have been thinking about that as well. What kind of size savings are you getting with this?
CC'ing linux-embedded as this might be of interest there as well.
Signature · 5 lines
Bye, Peter Korsgaard ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 11 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Ferenc" == Ferenc Wagner <[email protected]> writes:
Ferenc> For now, 2.6.34 gained pluggable decompressors, so this patch Ferenc> does not apply anymore, though the main idea holds. My Ferenc> questions: is the community interested in integrating something Ferenc> like this, should this patch transformed into something Ferenc> acceptable, or am I a total lunatic? I don't know a thing Ferenc> about filesystem development, but willing to learn and Ferenc> refactor. Comments welcome.
Nice, I have been thinking about that as well. What kind of size savings are you getting with this?
Yeah, I'm interested in that as well.
~Vitaly
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 17 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Ferenc" == Ferenc Wagner <[email protected]> writes:
Ferenc> In embedded systems, SquashFS over MTD would be a considerable Ferenc> win, as that would permit configuring without
CONFIG_BLOCK. Ferenc> Please find attached a naive patch against 2.6.33 for this. It Ferenc> does not handle bad MTD blocks, that could be handled by gluebi Ferenc> (once you're willing to take the UBI overhead), or by a custom Ferenc> solution later.Ferenc> For now, 2.6.34 gained pluggable decompressors, so this patch Ferenc> does not apply anymore, though the main idea holds. My Ferenc> questions: is the community interested in integrating something Ferenc> like this, should this patch transformed into something Ferenc> acceptable, or am I a total lunatic? I don't know a thing Ferenc> about filesystem development, but willing to learn and Ferenc> refactor. Comments welcome.
Quoted 2 lines
Nice, I have been thinking about that as well. What kind of size savings are you getting with this?
I could only compare apples to oranges before porting the patch to the LZMA variant. So I refrain from that for a couple of days yet. But meanwhile I started adding a pluggable backend framework to SquashFS, and would much appreciate some comments about the applicability of this idea. The patch is (intended to be) a no-op, applies on top of current git (a3d3203e4bb40f253b1541e310dc0f9305be7c84).
Signature · 2 lines
Thanks, Feri.
From bbed39c4402d563598dc8034514fd66648f835f5 Mon Sep 17 00:00:00 2001
From: Ferenc Wagner <[email protected]>
Date: Thu, 18 Mar 2010 03:12:01 +0100
Subject: [PATCH] squashfs: add backend plugin framework
--- fs/squashfs/Kconfig | 2 +- fs/squashfs/Makefile | 4 +- fs/squashfs/backend.c | 27 ++++++++++ fs/squashfs/backend.h | 22 +++++++++ fs/squashfs/bdev.c | 108 ++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/mtd.c | 82 ++++++++++++++++++++++++++++++++ fs/squashfs/squashfs.h | 12 ++++- fs/squashfs/squashfs_fs_sb.h | 2 + 8 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 fs/squashfs/backend.c create mode 100644 fs/squashfs/backend.h create mode 100644 fs/squashfs/bdev.c create mode 100644 fs/squashfs/mtd.c
fs/squashfs/Kconfig +1 -1
@@ -1,6 +1,6 @@ config SQUASHFS tristate "SquashFS 4.0 - Squashed file system support" - depends on BLOCK + depends on BLOCK || MTD select ZLIB_INFLATE help Saying Y here includes support for SquashFS 4.0 (a Compressed
fs/squashfs/Makefile +3 -1
@@ -4,4 +4,6 @@ obj-$(CONFIG_SQUASHFS) += squashfs.o squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o -squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o +squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o backend.o +squashfs-$(CONFIG_BLOCK) += bdev.o +squashfs-$(CONFIG_MTD) += mtd.o
fs/squashfs/backend.c new file +27 -0
@@ -0,0 +1,27 @@ +#include <linux/fs.h> + +#include "squashfs_fs_i.h" +#include "squashfs.h" +#include "backend.h" + +const struct squashfs_backend *backends[] = { +#ifdef CONFIG_BLOCK + &squashfs_bdev_ops, +#endif +#ifdef CONFIG_MTD + &squashfs_mtd_ops, +#endif +NULL +}; + +const struct squashfs_backend * +squashfs_find_backend (struct file_system_type *fs_type,int flags, +const char *dev_name,void *data,struct vfsmount *mnt) +{ +const struct squashfs_backend **b; + +for (b = backends; *b; b++) +if (!(*b)->probe (fs_type, flags, dev_name, data, mnt)) +break ; +return *b; +}
fs/squashfs/backend.h new file +22 -0
@@ -0,0 +1,22 @@ +#include <linux/fs.h> +#include <linux/vfs.h> + +#include "squashfs_fs_sb.h" + +struct squashfs_backend { +void *(*init)(struct squashfs_sb_info *,u64 ,size_t ); +void (*free)(struct squashfs_sb_info *); +ssize_t (*read)(struct squashfs_sb_info *,void **,size_t ); +int (*probe)(struct file_system_type *,int ,const char *, +void *,struct vfsmount *); +void (*kill)(struct squashfs_sb_info *); +loff_t (*size)(const struct super_block *); +const char *(*devname)(const struct super_block *,char *); +}; + +/* Dummy, until the original is nuked */ +static inline int squashfs_fill_super2 (struct super_block *sb,void *data, +int silent,const struct squashfs_backend *ops) +{ +return -1 ; +}
fs/squashfs/bdev.c new file +108 -0
108 lines not on this page · raw message
fs/squashfs/mtd.c new file +82 -0
82 lines not on this page · raw message
fs/squashfs/squashfs.h +11 -1
@@ -73,8 +73,12 @@ extern struct inode *squashfs_iget(struct super_block *, long long, unsigned int);extern int squashfs_read_inode (struct inode *,long long ); +/* super.c +int squashfs_fill_super(struct super_block *, void *, int, +struct squashfs_backend *); +*/ /* -* Inodes, files and decompressor operations +* Inodes, files, backend and decompressor operations */ /* dir.c */
@@ -94,3 +98,9 @@ extern const struct address_space_operations squashfs_symlink_aops;/* zlib_wrapper.c */ extern const struct squashfs_decompressor squashfs_zlib_comp_ops; + +/* bdev.c */ +extern const struct squashfs_backend squashfs_bdev_ops; + +/* mtd.c */ +extern const struct squashfs_backend squashfs_mtd_ops;
fs/squashfs/squashfs_fs_sb.h +2 -0
@@ -53,6 +53,8 @@ struct squashfs_cache_entry {struct squashfs_sb_info {const struct squashfs_decompressor *decompressor; +const struct squashfs_backend *backend; +void *backend_data;int devblksize;int devblksize_log2;struct squashfs_cache *block_cache;
Signature · 1 line
1.5.6.5
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 7 lines · Ferenc Wagner
I could only compare apples to oranges before porting the patch to the LZMA variant. So I refrain from that for a couple of days yet. But meanwhile I started adding a pluggable backend framework to SquashFS, and would much appreciate some comments about the applicability of this idea. The patch is (intended to be) a no-op, applies on top of current git (
a3d3203e4bb40f253b1541e310dc0f9305be7c84).
This looks promising, making the backend pluggable (like the new compressor framework) is far better and cleaner than scattering the code full of #ifdef's. Far better than the previous patch :-)
A couple of specific comments...
+/* A backend is initialized for each SquashFS block read operation,
+ * making further sequential reads possible from the block.
+ */
+static void *bdev_init(struct squashfs_sb_info *msblk, u64 index, size_t length)
+{
+ struct squashfs_bdev *bdev = msblk->backend_data;
+ struct buffer_head *bh;
+
+ bh = kcalloc((msblk->block_size >> bdev->devblksize_log2) + 1,
+ sizeof(*bh), GFP_KERNEL);
You should alloc against the larger of msblk->block_size and METADATA_SIZE (8 Kbytes). Block_size could be 4 Kbytes only.
+static int fill_bdev_super(struct super_block *sb, void *data, int silent) +{
+ struct squashfs_sb_info *msblk;
+ struct squashfs_bdev *bdev;
+ int err = squashfs_fill_super2(sb, data, silent, &squashfs_bdev_ops);
+ if (err)
+ return err;
+
+ bdev = kzalloc(sizeof(*bdev), GFP_KERNEL);
+ if (!bdev)
+ return -ENOMEM;
+
+ bdev->devblksize = sb_min_blocksize(sb, BLOCK_SIZE);
+ bdev->devblksize_log2 = ffz(~bdev->devblksize);
+
+ msblk = sb->s_fs_info;
+ msblk->backend_data = bdev;
+ return 0;
+}
This function looks rather 'back-to-front' to me. I'm assuming that squashfs_fill_super2() will be the current fill superblock function? This function wants to read data off the filesystem through the backend, and yet the backend (bdev, mblk->backend_data) hasn't been initialised when it's called...
Phillip
Quoted 9 lines · Phillip Lougher
Quoted 6 lines · Ferenc Wagner
I could only compare apples to oranges before porting the patch to the LZMA variant. So I refrain from that for a couple of days yet. But meanwhile I started adding a pluggable backend framework to SquashFS, and would much appreciate some comments about the applicability of this idea. The patch is (intended to be) a no-op, applies on top of current git (
a3d3203e4bb40f253b1541e310dc0f9305be7c84).
Quoted 3 lines
This looks promising, making the backend pluggable (like the new compressor framework) is far better and cleaner than scattering the code full of #ifdef's. Far better than the previous patch :-)
Yeah, the previous patch was only a little bit more than a proof that I can make SquashFS work on an MTD device. The MTD access part is probably the only thing to criticize there: maybe it would be better done in blocks of some particular size, via a different interface.
Quoted 11 lines
+static void *bdev_init(struct
squashfs_sb_info*msblk, u64 index,size_tlength)fs/squashfs/bdev.c new file +6
-0+{ +struct squashfs_bdev *bdev = msblk->backend_data; +struct buffer_head *bh; + + bh =kcalloc ((msblk->block_size >> bdev->devblksize_log2) +1 , +sizeof (*bh),GFP_KERNEL );You should alloc against the larger of
msblk->block_sizeandMETADATA_SIZE(8 Kbytes).Block_sizecould be 4 Kbytes only.
Hmm, okay. Though this code is a verbatim copy of that in block.c.
Quoted 20 lines
fs/squashfs/bdev.c new file +19
-0+static int fill_bdev_super (struct super_block *sb,void *data,int silent) +{ +struct squashfs_sb_info *msblk; +struct squashfs_bdev *bdev; +int err =squashfs_fill_super2 (sb, data, silent, &squashfs_bdev_ops); +if (err) +return err; + + bdev =kzalloc (sizeof (*bdev),GFP_KERNEL ); +if (!bdev) +return -ENOMEM ; + + bdev->devblksize =sb_min_blocksize (sb,BLOCK_SIZE ); + bdev->devblksize_log2 =ffz (~bdev->devblksize); + + msblk = sb->s_fs_info; + msblk->backend_data = bdev; +return 0 ; +}
Quoted 2 lines
This function looks rather 'back-to-front' to me. I'm assuming that
squashfs_fill_super2()will be the current fill superblock function?
Yes, with the extra parameter added.
Quoted 3 lines
This function wants to read data off the filesystem through the backend, and yet the backend (bdev,
mblk->backend_data) hasn't been initialised when it's called...
It can't be, because msblk = sb->s_fs_info is allocated by squashfs_fill_super(). Now it will be passed the ops, so after allocating msblk it can also fill out the ops. After that it can read, and squashfs_read_data() will call the init, read and free operations of the backend. The backend itself has no persistent state between calls to squashfs_read_data(). Btw. struct super_block has fields named s_blocksize and s_blocksize_bits, aren't those the same as devblksize and devblksize_log in squashfs_sb_info? (They are being moved into backend_data by the above.) If yes, shouldn't they be used instead?
While we're at it: is it really worth submitting all the buffer heads at the beginning, instead of submitting them one at a time as needed by the decompression process and letting the IO scheduler do readahead and request coalescing as it sees fit? At the very least, that would require less memory, while possibly not hurting performance too much.
On the other hand, would it be possible to avoid the memory copy of uncompressed blocks by doing a straight (DMA) transfer from the device into the page cache?
LZMA support is not in mainline yet, but I saw that unlzma is done in a single step, which requires block-sized input and output buffers. Is there any particular reason it's done this way, not chunk-by-chunk as inflate? This easily costs hundreds of kilobytes of virtual memory, which isn't negligible on embedded systems.
Signature · 2 lines
Thanks for your comments, Feri.
Quoted 33 lines · Ferenc Wagner
Quoted 22 lines · Phillip Lougher
On Thu, Mar 18, 2010 at 4:38 PM, Ferenc Wagner <[email protected]> wrote:
fs/squashfs/bdev.c new file +19
-0+static int fill_bdev_super (struct super_block *sb,void *data,int silent) +{ +struct squashfs_sb_info *msblk; +struct squashfs_bdev *bdev; +int err =squashfs_fill_super2 (sb, data, silent, &squashfs_bdev_ops); +if (err) +return err; + + bdev =kzalloc (sizeof (*bdev),GFP_KERNEL ); +if (!bdev) +return -ENOMEM ; + + bdev->devblksize =sb_min_blocksize (sb,BLOCK_SIZE ); + bdev->devblksize_log2 =ffz (~bdev->devblksize); + + msblk = sb->s_fs_info; + msblk->backend_data = bdev; +return 0 ; +}Quoted 2 lines
This function looks rather 'back-to-front' to me. I'm assuming that
squashfs_fill_super2()will be the current fill superblock function?Yes, with the extra parameter added.
Quoted 3 lines
This function wants to read data off the filesystem through the backend, and yet the backend (bdev,
mblk->backend_data) hasn't been initialised when it's called...
Quoted 5 lines
It can't be, because msblk =
sb->s_fs_infois allocated bysquashfs_fill_super(). Now it will be passed the ops, so after allocating msblk it can also fill out the ops. After that it can read, andsquashfs_read_data()will call the init, read and free operations of the backend.
And here we indeed have a rather fundamental problem. This isn't specific to the discussed plugin system at all. Even in the current code, to set msblk->block_size squashfs_fill_super() calls squashfs_read_table() to read the superblock, which in turn calls squashfs_read_data(), which uses msblk->block_size to allocate enough buffer heads, but msblk->block_size just can't be set at this point. msblk->bytes_used is preset with a dummy value to make the read possible, but msblk->block_size is not. Fortunately, one buffer head is allocated each time nevertheless. I wonder what a correct solution would look lke..
Signature · 2 lines
Regards, Feri.
Quoted 41 lines · Ferenc Wagner
Quoted 33 lines · Ferenc Wagner
Quoted 22 lines · Phillip Lougher
On Thu, Mar 18, 2010 at 4:38 PM, Ferenc Wagner <[email protected]> wrote:
fs/squashfs/bdev.c new file +19
-0+static int fill_bdev_super (struct super_block *sb,void *data,int silent) +{ + struct squashfs_sb_info *msblk; + struct squashfs_bdev *bdev; + int err = squashfs_fill_super2(sb, data, silent, &squashfs_bdev_ops); + if (err) + return err; + + bdev = kzalloc(sizeof(*bdev), GFP_KERNEL); + if (!bdev) + return -ENOMEM; + + bdev->devblksize = sb_min_blocksize(sb, BLOCK_SIZE); + bdev->devblksize_log2 = ffz(~bdev->devblksize); + + msblk = sb->s_fs_info; + msblk->backend_data = bdev; + return 0; +}Quoted 2 lines
This function looks rather 'back-to-front' to me. I'm assuming that
squashfs_fill_super2()will be the current fill superblock function?Yes, with the extra parameter added.
Quoted 3 lines
This function wants to read data off the filesystem through the backend, and yet the backend (bdev,
mblk->backend_data) hasn't been initialised when it's called...Quoted 5 lines
It can't be, because msblk =
sb->s_fs_infois allocated bysquashfs_fill_super(). Now it will be passed the ops, so after allocating msblk it can also fill out the ops. After that it can read, andsquashfs_read_data()will call the init, read and free operations of the backend.
Quoted 10 lines
And here we indeed have a rather fundamental problem. This isn't specific to the discussed plugin system at all. Even in the current code, to set
msblk->block_sizesquashfs_fill_super()callssquashfs_read_table()to read the superblock, which in turn callssquashfs_read_data(), which usesmsblk->block_sizeto allocate enough buffer heads, butmsblk->block_sizejust can't be set at this point.msblk->bytes_usedis preset with a dummy value to make the read possible, butmsblk->block_sizeis not. Fortunately, one buffer head is allocated each time nevertheless. I wonder what a correct solution would look lke..
Block_size is known to be zero (the structure has been zeroed out at alloc), and so it is known that the one block alloced in this case will be correct.
Congratulations you've managed to really piss me off in your third or so email.
Cheers
Phillip
Quoted 4 lines
--
Regards,
Feri.
Quoted 54 lines · Phillip Lougher
Quoted 41 lines · Ferenc Wagner
Quoted 33 lines · Ferenc Wagner
Quoted 22 lines · Phillip Lougher
On Thu, Mar 18, 2010 at 4:38 PM, Ferenc Wagner <[email protected]> wrote:
fs/squashfs/bdev.c new file +19
-0+static int fill_bdev_super (struct super_block *sb,void *data,int silent) +{ + struct squashfs_sb_info *msblk; + struct squashfs_bdev *bdev; + int err = squashfs_fill_super2(sb, data, silent, &squashfs_bdev_ops); + if (err) + return err; + + bdev = kzalloc(sizeof(*bdev), GFP_KERNEL); + if (!bdev) + return -ENOMEM; + + bdev->devblksize = sb_min_blocksize(sb, BLOCK_SIZE); + bdev->devblksize_log2 = ffz(~bdev->devblksize); + + msblk = sb->s_fs_info; + msblk->backend_data = bdev; + return 0; +}Quoted 2 lines
This function looks rather 'back-to-front' to me. I'm assuming that
squashfs_fill_super2()will be the current fill superblock function?Yes, with the extra parameter added.
Quoted 3 lines
This function wants to read data off the filesystem through the backend, and yet the backend (bdev,
mblk->backend_data) hasn't been initialised when it's called...Quoted 5 lines
It can't be, because msblk =
sb->s_fs_infois allocated bysquashfs_fill_super(). Now it will be passed the ops, so after allocating msblk it can also fill out the ops. After that it can read, andsquashfs_read_data()will call the init, read and free operations of the backend.Quoted 10 lines
And here we indeed have a rather fundamental problem. This isn't specific to the discussed plugin system at all. Even in the current code, to set
msblk->block_sizesquashfs_fill_super()callssquashfs_read_table()to read the superblock, which in turn callssquashfs_read_data(), which usesmsblk->block_sizeto allocate enough buffer heads, butmsblk->block_sizejust can't be set at this point.msblk->bytes_usedis preset with a dummy value to make the read possible, butmsblk->block_sizeis not. Fortunately, one buffer head is allocated each time nevertheless. I wonder what a correct solution would look like..
Quoted 3 lines
Block_sizeis known to be zero (the structure has been zeroed out at alloc), and so it is known that the one block alloced in this case will be correct.
If block_size=0 is always a good dummy value for this single call, that's great. Fixing this in a general way in the backend framework might require allocating and partly initializing squashfs_sb_info in the backend specific fill_super() function, before calling squashfs_fill_super() for finalizing it. Even though it may be possible to work around this for the bdev or mtd backends, it probably isn't worth it.
Quoted 2 lines
Congratulations you've managed to really piss me off in your third or so email.
Sorry, I'm not sure I understand. If you mean that I made an ass of myself by my questions, that's OK, I'm certainly a newbie and I admittedly have no idea what I'm fiddling with. Please feel free to ignore stupid questions. On the other hand, if you mean that I hurt your feelings in any way, I'd like to apologize: it certainly wasn't my intention, but I might have chosen inappropriate terms. Sorry for that.
Signature · 2 lines
Cheers, Feri.
Quoted 14 lines · Phillip Lougher
A couple of specific comments...
(quoted diff) +4
-0+/* A backend is initialized for each SquashFS block read operation, + * making further sequential reads possible from the block. + */ +static void *bdev_init(struct squashfs_sb_info *msblk, u64 index,
size_tlength)(quoted diff) +6
-0+{ + struct squashfs_bdev *bdev = msblk->backend_data; + struct buffer_head *bh; + + bh = kcalloc((msblk->block_size >> bdev->devblksize_log2) + 1, + sizeof(*bh), GFP_KERNEL);
Quoted 2 lines
You should alloc against the larger of
msblk->block_sizeandMETADATA_SIZE(8 Kbytes).Block_sizecould be 4 Kbytes only.
I plugged in a max(). Couldn't that trailing +1 be converted into a +2 like this?
bh = kcalloc((max(msblk->block_size, METADATA_SIZE) + 2) >> bdev->devblksize_log2
Quoted 7 lines
+static int
fill_bdev_super(struct super_block *sb, void *data, int silent)This function looks rather 'back-to-front' to me. I'm assuming that
squashfs_fill_super2()will be the current fill superblock function? This function wants to read data off the filesystem through the backend, and yet the backend (bdev,mblk->backend_data) hasn't been initialised when it's called...
I solved it by introducing a callback function for adding the backend. That may be overkill, but it seems to give the most shared code.
The attached patch series survived some testing here. My only doubt:
the current backend interface necessitates a memory copy from the buffer heads. This is no problem for mtd and lzma which copy the data anyway, but makes this code less efficient in the bdev+zlib case.
I've got one more patch, which I forgot to export, to pull out the common logic from the backend init functions back into squashfs_read_data(). With the bdev backend, that entails reading the first block twice in a row most of the time. This again could be worked around by extending the backend interface, but I'm not sure if it's worth it.
How does this look like now?
Signature · 2 lines
Regards, Feri.
From 68f194727a9905e01d216918200671140ecbc04e Mon Sep 17 00:00:00 2001
From: Ferenc Wagner <[email protected]>
Date: Thu, 18 Mar 2010 03:12:01 +0100
Subject: [PATCH] squashfs: add backend plugin framework
--- fs/squashfs/Makefile | 3 +- fs/squashfs/backend.c | 24 +++++++++ fs/squashfs/backend.h | 22 ++++++++ fs/squashfs/bdev.c | 109 ++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/squashfs.h | 9 +++- fs/squashfs/squashfs_fs_sb.h | 2 + 6 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 fs/squashfs/backend.c create mode 100644 fs/squashfs/backend.h create mode 100644 fs/squashfs/bdev.c
fs/squashfs/Makefile +2 -1
@@ -4,5 +4,6 @@ obj-$(CONFIG_SQUASHFS) += squashfs.o squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o -squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o +squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o backend.o squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o +squashfs-$(CONFIG_BLOCK) += bdev.o
fs/squashfs/backend.c new file +24 -0
@@ -0,0 +1,24 @@ +#include <linux/fs.h> + +#include "squashfs_fs_i.h" +#include "squashfs.h" +#include "backend.h" + +const struct squashfs_backend *backends[] = { +#ifdef CONFIG_BLOCK + &squashfs_bdev_ops, +#endif +NULL +}; + +const struct squashfs_backend * +squashfs_find_backend (struct file_system_type *fs_type,int flags, +const char *dev_name,void *data,struct vfsmount *mnt) +{ +const struct squashfs_backend **b; + +for (b = backends; *b; b++) +if (!(*b)->probe (fs_type, flags, dev_name, data, mnt)) +break ; +return *b; +}
fs/squashfs/backend.h new file +22 -0
@@ -0,0 +1,22 @@ +#include <linux/fs.h> +#include <linux/vfs.h> + +#include "squashfs_fs_sb.h" + +struct squashfs_backend { +void *(*init)(struct squashfs_sb_info *,u64 ,size_t ); +void (*free)(struct squashfs_sb_info *); +ssize_t (*read)(struct squashfs_sb_info *,void **,size_t ); +int (*probe)(struct file_system_type *,int ,const char *, +void *,struct vfsmount *); +void (*kill)(struct squashfs_sb_info *); +loff_t (*size)(const struct super_block *); +const char *(*devname)(const struct super_block *,char *); +}; + +/* Dummy, until the original is nuked */ +static inline int squashfs_fill_super2 (struct super_block *sb,void *data, +int silent,int (*add_bend)(struct super_block *)) +{ +return -1 ; +}
fs/squashfs/bdev.c new file +109 -0
109 lines not on this page · raw message
fs/squashfs/squashfs.h +8 -1
@@ -73,8 +73,12 @@ extern struct inode *squashfs_iget(struct super_block *, long long, unsigned int);extern int squashfs_read_inode (struct inode *,long long ); +/* super.c +int squashfs_fill_super(struct super_block *, void *, int, +struct squashfs_backend *); +*/ /* -* Inodes, files and decompressor operations +* Inodes, files, backend and decompressor operations */ /* dir.c */
@@ -97,3 +101,6 @@ extern const struct squashfs_decompressor squashfs_zlib_comp_ops;/* lzma wrapper.c */ extern const struct squashfs_decompressor squashfs_lzma_comp_ops; + +/* bdev.c */ +extern const struct squashfs_backend squashfs_bdev_ops;
fs/squashfs/squashfs_fs_sb.h +2 -0
@@ -53,6 +53,8 @@ struct squashfs_cache_entry {struct squashfs_sb_info {const struct squashfs_decompressor *decompressor; +const struct squashfs_backend *backend; +void *backend_data;int devblksize;int devblksize_log2;struct squashfs_cache *block_cache;
Signature · 17 lines
1.5.6.5 From 7f3d85818017d128cc438fefdf300f770dd7869e Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Sat, 20 Mar 2010 15:58:21 +0100 Subject: [PATCH] squashfs: thread initialization through the backend framework This necessitated introducing the killsb callback. The read path is still untouched. --- fs/squashfs/backend.c | 22 +++++++++++++++----- fs/squashfs/backend.h | 11 ++++----- fs/squashfs/bdev.c | 3 +- fs/squashfs/squashfs.h | 6 ++-- fs/squashfs/super.c | 49 +++++++++++++++++++++-------------------------- 5 files changed, 48 insertions(+), 43 deletions(-)
fs/squashfs/backend.c +16 -6
@@ -11,14 +11,24 @@ const struct squashfs_backend *backends[] = { NULL }; -const struct squashfs_backend * -squashfs_find_backend (struct file_system_type *fs_type,int flags, +int squashfs_find_backend (struct file_system_type *fs_type,int flags,const char *dev_name,void *data,struct vfsmount *mnt) {const struct squashfs_backend **b; +int err; -for (b = backends; *b; b++) -if (!(*b)->probe (fs_type, flags, dev_name, data, mnt)) -break ; -return *b; +for (b = backends; *b; b++) { + err = (*b)->probe (fs_type, flags, dev_name, data, mnt); +if (!err) +return 0 ; + } +ERROR ("No suitable backend found\n" ); +return -ENODEV ; +} + +void squashfs_kill_super (struct super_block *sb) +{ +struct squashfs_sb_info *msblk = sb->s_fs_info; + + msblk->backend->killsb (sb); }
fs/squashfs/backend.h +5 -6
@@ -9,14 +9,13 @@ struct squashfs_backend {ssize_t (*read)(struct squashfs_sb_info *,void **,size_t );int (*probe)(struct file_system_type *,int ,const char *,void *,struct vfsmount *); +void (*killsb)(struct super_block *);void (*kill)(struct squashfs_sb_info *);loff_t (*size)(const struct super_block *);const char *(*devname)(const struct super_block *,char *); }; -/* Dummy, until the original is nuked */ -static inline int squashfs_fill_super2 (struct super_block *sb,void *data, -int silent,int (*add_bend)(struct super_block *)) -{ -return -1 ; -} +int squashfs_find_backend (struct file_system_type *,int , +const char *,void *,struct vfsmount *); + +void squashfs_kill_super (struct super_block *);
fs/squashfs/bdev.c +2 -1
@@ -68,7 +68,7 @@ static int add_bdev_backend(struct super_block *sb)static int fill_bdev_super (struct super_block *sb,void *data,int silent) { -return squashfs_fill_super2 (sb, data, silent, add_bdev_backend); +return squashfs_fill_super (sb, data, silent, add_bdev_backend); } static int bdev_probe(struct file_system_type *fs_type, int flags,
@@ -103,6 +103,7 @@ const struct squashfs_backend squashfs_bdev_ops = { .free = bdev_free, .read = bdev_read, .probe = bdev_probe, + .killsb = kill_block_super, .kill = bdev_kill, .size = bdev_size, .devname= bdev_devname
fs/squashfs/squashfs.h +3 -3
@@ -73,10 +73,10 @@ extern struct inode *squashfs_iget(struct super_block *, long long, unsigned int);extern int squashfs_read_inode (struct inode *,long long ); -/* super.c +/* super.c */ int squashfs_fill_super (struct super_block *,void *,int , -struct squashfs_backend *); -*/ +int (*)(struct super_block *)); +/* * Inodes, files, backend and decompressor operations */
fs/squashfs/super.c +22 -27
119 lines not on this page · raw message
Signature · 18 lines
1.5.6.5 From 4b150ae9d6c3ae77b139f75a1466aa10e1ef1b5a Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Sun, 21 Mar 2010 02:08:58 +0100 Subject: [PATCH] squashfs: read uncompressed blocks through the backend framework Avoid double free on the temporary decompression hack-path; this may leak buffer heads if decompression exits early. --- fs/squashfs/backend.h | 4 +- fs/squashfs/bdev.c | 191 ++++++++++++++++++++++++++++++++++++++---- fs/squashfs/block.c | 167 ++++++++----------------------------- fs/squashfs/lzma_wrapper.c | 2 + fs/squashfs/squashfs_fs_sb.h | 2 - fs/squashfs/super.c | 5 +- 6 files changed, 216 insertions(+), 155 deletions(-)
fs/squashfs/backend.h +2 -2
@@ -4,9 +4,9 @@#include "squashfs_fs_sb.h" struct squashfs_backend { -void *(*init)(struct squashfs_sb_info *,u64 ,size_t ); +int (*init)(struct super_block *,u64 ,int ,int ,u64 *,int *);void (*free)(struct squashfs_sb_info *); -ssize_t (*read)(struct squashfs_sb_info *,void **,size_t ); +int (*read)(struct super_block *,void *,int );int (*probe)(struct file_system_type *,int ,const char *,void *,struct vfsmount *);void (*killsb)(struct super_block *);
fs/squashfs/bdev.c +174 -17
242 lines not on this page · raw message
fs/squashfs/block.c +36 -131
197 lines not on this page · raw message
fs/squashfs/lzma_wrapper.c +2 -0
@@ -94,6 +94,8 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,void *buff = stream->input;int avail, i, bytes = length, res; +TRACE ("lzma_uncompress: bh=%p, b=%d, offset=%d, length=%d, srclength=%d," +" pages=%d\n" , bh, b, offset, length, srclength, pages);mutex_lock (&lzma_mutex);for (i =0 ; i < b; i++) {
fs/squashfs/squashfs_fs_sb.h +0 -2
@@ -55,8 +55,6 @@ struct squashfs_sb_info {const struct squashfs_decompressor *decompressor;const struct squashfs_backend *backend;void *backend_data; -int devblksize; -int devblksize_log2;struct squashfs_cache *block_cache;struct squashfs_cache *fragment_cache;struct squashfs_cache *read_page;
fs/squashfs/super.c +2 -3
@@ -87,7 +87,7 @@ int squashfs_fill_super(struct super_block *sb, void *data, int silent,u64 lookup_table_start;int err; -TRACE ("Entered squashfs_fill_superblock\n" ); +TRACE ("Entered squashfs_fill_superblock, silent=%d\n" , silent); sb->s_fs_info =kzalloc (sizeof (*msblk),GFP_KERNEL );if (sb->s_fs_info ==NULL ) {
@@ -103,8 +103,6 @@ int squashfs_fill_super(struct super_block *sb, void *data, int silent, goto free_msblk; } - msblk->devblksize =sb_min_blocksize (sb,BLOCK_SIZE ); - msblk->devblksize_log2 =ffz (~msblk->devblksize); err =add_backend (sb);if (err) goto free_sblk;
@@ -305,6 +303,7 @@ failed_mount:kfree (msblk->inode_lookup_table);/* FIXME: squashfs_put_super has meta_index instead */ kfree (msblk->fragment_index);kfree (msblk->id_table); +TRACE ("squasfs_fill_super: killing backend, err=%d\n" , err); msblk->backend->kill (msblk); free_sblk:kfree (sblk);
Signature · 14 lines
1.5.6.5 From a139798e093314d4fd6fe121a84ae6b30a33af43 Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Sun, 21 Mar 2010 22:38:00 +0100 Subject: [PATCH] squashfs: move the decompressors to the backend framework --- fs/squashfs/block.c | 17 +---------------- fs/squashfs/decompressor.h | 12 +++++------- fs/squashfs/lzma_wrapper.c | 27 +++++++++------------------ fs/squashfs/zlib_wrapper.c | 44 ++++++++++++++++++-------------------------- 4 files changed, 33 insertions(+), 67 deletions(-)
fs/squashfs/block.c +1 -16
@@ -39,18 +39,6 @@#include "decompressor.h" #include "backend.h" -/* FIXME: here for a temporary cheat only */ -struct squashfs_bdev { -int devblksize;/* FIXME: == s->s_blocksize(_bits)? */ -unsigned short devblksize_log2; -int length; -int bytes_read; -struct buffer_head **bh; -int bh_index;/* number of consumed buffer_heads */ -int offset;/* offset of next byte in buffer_head */ -int b;/* total number of buffer heads */ -}; -/* * Read and decompress a metadata block or datablock. Length is non-zero * if a datablock is being read (the size is stored elsewhere in the
@@ -71,10 +59,7 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,return length;if (compressed) { -struct squashfs_bdev *bdev = msblk->backend_data; - length =squashfs_decompress (msblk, buffer, bdev->bh, bdev->b, - bdev->offset, length, srclength, pages); - bdev->bh_index = bdev->b;/* temporary hack to avoid double free */ + length =squashfs_decompress (sb, buffer, length, pages);if (length <0 ) goto read_failure; }else {
fs/squashfs/decompressor.h +5 -7
@@ -26,8 +26,7 @@struct squashfs_decompressor {void *(*init)(struct squashfs_sb_info *);void (*free)(void *); -int (*decompress)(struct squashfs_sb_info *,void **, -struct buffer_head **,int ,int ,int ,int ,int ); +int (*decompress)(struct super_block *,void **,int ,int );int id;char *name;int supported;
@@ -45,11 +44,10 @@ static inline void squashfs_decompressor_free(struct squashfs_sb_info *msblk, msblk->decompressor->free(s); } -static inline int squashfs_decompress (struct squashfs_sb_info *msblk, -void **buffer,struct buffer_head **bh,int b,int offset,int length, -int srclength,int pages) +static inline int squashfs_decompress (struct super_block *sb, +void **buffer,int length,int pages) { -return msblk->decompressor->decompress (msblk, buffer, bh, b, offset, - length, srclength, pages); +struct squashfs_sb_info *msblk = sb->s_fs_info; +return msblk->decompressor->decompress (sb, buffer, length, pages); }#endif
fs/squashfs/lzma_wrapper.c +9 -18
@@ -32,6 +32,7 @@#include "squashfs_fs_i.h" #include "squashfs.h" #include "decompressor.h" +#include "backend.h" struct squashfs_lzma {void *input;
@@ -86,29 +87,23 @@ static void lzma_free(void *strm) } -static int lzma_uncompress (struct squashfs_sb_info *msblk,void **buffer, -struct buffer_head **bh,int b,int offset,int length,int srclength, -int pages) +static int lzma_uncompress (struct super_block *sb,void **buffer, +int length,int pages) { +struct squashfs_sb_info *msblk = sb->s_fs_info;struct squashfs_lzma *stream = msblk->stream;void *buff = stream->input;int avail, i, bytes = length, res; -TRACE ("lzma_uncompress: bh=%p, b=%d, offset=%d, length=%d, srclength=%d," -" pages=%d\n" , bh, b, offset, length, srclength, pages); +TRACE ("lzma_uncompress: length=%d, pages=%d\n" , length, pages);mutex_lock (&lzma_mutex); -for (i =0 ; i < b; i++) { -wait_on_buffer (bh[i]); -if (!buffer_uptodate (bh[i])) - goto block_release; - - avail =min (bytes, msblk->devblksize - offset); -memcpy (buff, bh[i]->b_data + offset, avail); +while ((avail = msblk->backend->read (sb, buff, length))) { +if (avail <0 ) + goto failed; +TRACE ("read %d bytes\n" , avail); buff += avail; bytes -= avail; - offset =0 ; -put_bh (bh[i]); } lzma_error =0 ;
@@ -131,10 +126,6 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,mutex_unlock (&lzma_mutex);return res; -block_release: -for (; i < b; i++) -put_bh (bh[i]); - failed:mutex_unlock (&lzma_mutex);
fs/squashfs/zlib_wrapper.c +18 -26
89 lines not on this page · raw message
Signature · 16 lines
1.5.6.5 From d04e9006614dceb61f26ed462d4e0682de0b31af Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Tue, 23 Mar 2010 02:21:27 +0100 Subject: [PATCH] squashfs: add mtd backend --- fs/squashfs/Kconfig | 2 +- fs/squashfs/Makefile | 1 + fs/squashfs/backend.c | 3 + fs/squashfs/mtd.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/squashfs.h | 3 + 5 files changed, 175 insertions(+), 1 deletions(-) create mode 100644 fs/squashfs/mtd.c
fs/squashfs/Kconfig +1 -1
@@ -1,6 +1,6 @@ config SQUASHFS tristate "SquashFS 4.0 - Squashed file system support" - depends on BLOCK + depends on BLOCK || MTD select ZLIB_INFLATE help Saying Y here includes support for SquashFS 4.0 (a Compressed
fs/squashfs/Makefile +1 -0
@@ -7,3 +7,4 @@ squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o backend.o squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o squashfs-$(CONFIG_BLOCK) += bdev.o +squashfs-$(CONFIG_MTD) += mtd.o
fs/squashfs/backend.c +3 -0
@@ -8,6 +8,9 @@ const struct squashfs_backend *backends[] = {#ifdef CONFIG_BLOCK &squashfs_bdev_ops,#endif +#ifdef CONFIG_MTD + &squashfs_mtd_ops, +#endifNULL };
fs/squashfs/mtd.c new file +167 -0
167 lines not on this page · raw message
fs/squashfs/squashfs.h +3 -0
@@ -104,3 +104,6 @@ extern const struct squashfs_decompressor squashfs_lzma_comp_ops;/* bdev.c */ extern const struct squashfs_backend squashfs_bdev_ops; + +/* mtd.c */ +extern const struct squashfs_backend squashfs_mtd_ops;
Signature · 1 line
1.5.6.5
Quoted 5 lines · Ferenc Wagner
I've got one more patch, which I forgot to export, to pull out the common logic from the backend init functions back into
squashfs_read_data(). With the bdev backend, that entails reading the first block twice in a row most of the time. This again could be worked around by extending the backend interface, but I'm not sure if it's worth it.
Here it is. I also corrected the name of SQUASHFS_METADATA_SIZE, so it may as well compile now.
Signature · 2 lines
Regards, Feri.
Now with the patch series, sorry.
Quoted 5 lines · Ferenc Wagner
I've got one more patch, which I forgot to export, to pull out the common logic from the backend init functions back into
squashfs_read_data(). With the bdev backend, that entails reading the first block twice in a row most of the time. This again could be worked around by extending the backend interface, but I'm not sure if it's worth it.
Here it is. I also corrected the name of SQUASHFS_METADATA_SIZE, so it may as well compile now.
Signature · 2 lines
Regards, Feri.
From 1318e378d15008c89971f4c300738bd46d0fd2ba Mon Sep 17 00:00:00 2001
From: Ferenc Wagner <[email protected]>
Date: Thu, 18 Mar 2010 03:12:01 +0100
Subject: [PATCH] squashfs: add backend plugin framework
--- fs/squashfs/Makefile | 3 +- fs/squashfs/backend.c | 24 +++++++++ fs/squashfs/backend.h | 22 ++++++++ fs/squashfs/bdev.c | 110 ++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/squashfs.h | 9 +++- fs/squashfs/squashfs_fs_sb.h | 2 + 6 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 fs/squashfs/backend.c create mode 100644 fs/squashfs/backend.h create mode 100644 fs/squashfs/bdev.c
fs/squashfs/Makefile +2 -1
@@ -4,5 +4,6 @@ obj-$(CONFIG_SQUASHFS) += squashfs.o squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o -squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o +squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o backend.o squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o +squashfs-$(CONFIG_BLOCK) += bdev.o
fs/squashfs/backend.c new file +24 -0
@@ -0,0 +1,24 @@ +#include <linux/fs.h> + +#include "squashfs_fs_i.h" +#include "squashfs.h" +#include "backend.h" + +const struct squashfs_backend *backends[] = { +#ifdef CONFIG_BLOCK + &squashfs_bdev_ops, +#endif +NULL +}; + +const struct squashfs_backend * +squashfs_find_backend (struct file_system_type *fs_type,int flags, +const char *dev_name,void *data,struct vfsmount *mnt) +{ +const struct squashfs_backend **b; + +for (b = backends; *b; b++) +if (!(*b)->probe (fs_type, flags, dev_name, data, mnt)) +break ; +return *b; +}
fs/squashfs/backend.h new file +22 -0
@@ -0,0 +1,22 @@ +#include <linux/fs.h> +#include <linux/vfs.h> + +#include "squashfs_fs_sb.h" + +struct squashfs_backend { +void *(*init)(struct squashfs_sb_info *,u64 ,size_t ); +void (*free)(struct squashfs_sb_info *); +ssize_t (*read)(struct squashfs_sb_info *,void **,size_t ); +int (*probe)(struct file_system_type *,int ,const char *, +void *,struct vfsmount *); +void (*kill)(struct squashfs_sb_info *); +loff_t (*size)(const struct super_block *); +const char *(*devname)(const struct super_block *,char *); +}; + +/* Dummy, until the original is nuked */ +static inline int squashfs_fill_super2 (struct super_block *sb,void *data, +int silent,int (*add_bend)(struct super_block *)) +{ +return -1 ; +}
fs/squashfs/bdev.c new file +110 -0
110 lines not on this page · raw message
fs/squashfs/squashfs.h +8 -1
@@ -73,8 +73,12 @@ extern struct inode *squashfs_iget(struct super_block *, long long, unsigned int);extern int squashfs_read_inode (struct inode *,long long ); +/* super.c +int squashfs_fill_super(struct super_block *, void *, int, +struct squashfs_backend *); +*/ /* -* Inodes, files and decompressor operations +* Inodes, files, backend and decompressor operations */ /* dir.c */
@@ -97,3 +101,6 @@ extern const struct squashfs_decompressor squashfs_zlib_comp_ops;/* lzma wrapper.c */ extern const struct squashfs_decompressor squashfs_lzma_comp_ops; + +/* bdev.c */ +extern const struct squashfs_backend squashfs_bdev_ops;
fs/squashfs/squashfs_fs_sb.h +2 -0
@@ -53,6 +53,8 @@ struct squashfs_cache_entry {struct squashfs_sb_info {const struct squashfs_decompressor *decompressor; +const struct squashfs_backend *backend; +void *backend_data;int devblksize;int devblksize_log2;struct squashfs_cache *block_cache;
Signature · 17 lines
1.5.6.5 From 3d469f3f3f2ecaacc8d99a142899216879099867 Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Sat, 20 Mar 2010 15:58:21 +0100 Subject: [PATCH] squashfs: thread initialization through the backend framework This necessitated introducing the killsb callback. The read path is still untouched. --- fs/squashfs/backend.c | 22 +++++++++++++++----- fs/squashfs/backend.h | 11 ++++----- fs/squashfs/bdev.c | 3 +- fs/squashfs/squashfs.h | 6 ++-- fs/squashfs/super.c | 49 +++++++++++++++++++++-------------------------- 5 files changed, 48 insertions(+), 43 deletions(-)
fs/squashfs/backend.c +16 -6
@@ -11,14 +11,24 @@ const struct squashfs_backend *backends[] = { NULL }; -const struct squashfs_backend * -squashfs_find_backend (struct file_system_type *fs_type,int flags, +int squashfs_find_backend (struct file_system_type *fs_type,int flags,const char *dev_name,void *data,struct vfsmount *mnt) {const struct squashfs_backend **b; +int err; -for (b = backends; *b; b++) -if (!(*b)->probe (fs_type, flags, dev_name, data, mnt)) -break ; -return *b; +for (b = backends; *b; b++) { + err = (*b)->probe (fs_type, flags, dev_name, data, mnt); +if (!err) +return 0 ; + } +ERROR ("No suitable backend found\n" ); +return -ENODEV ; +} + +void squashfs_kill_super (struct super_block *sb) +{ +struct squashfs_sb_info *msblk = sb->s_fs_info; + + msblk->backend->killsb (sb); }
fs/squashfs/backend.h +5 -6
@@ -9,14 +9,13 @@ struct squashfs_backend {ssize_t (*read)(struct squashfs_sb_info *,void **,size_t );int (*probe)(struct file_system_type *,int ,const char *,void *,struct vfsmount *); +void (*killsb)(struct super_block *);void (*kill)(struct squashfs_sb_info *);loff_t (*size)(const struct super_block *);const char *(*devname)(const struct super_block *,char *); }; -/* Dummy, until the original is nuked */ -static inline int squashfs_fill_super2 (struct super_block *sb,void *data, -int silent,int (*add_bend)(struct super_block *)) -{ -return -1 ; -} +int squashfs_find_backend (struct file_system_type *,int , +const char *,void *,struct vfsmount *); + +void squashfs_kill_super (struct super_block *);
fs/squashfs/bdev.c +2 -1
@@ -69,7 +69,7 @@ static int add_bdev_backend(struct super_block *sb)static int fill_bdev_super (struct super_block *sb,void *data,int silent) { -return squashfs_fill_super2 (sb, data, silent, add_bdev_backend); +return squashfs_fill_super (sb, data, silent, add_bdev_backend); } static int bdev_probe(struct file_system_type *fs_type, int flags,
@@ -104,6 +104,7 @@ const struct squashfs_backend squashfs_bdev_ops = { .free = bdev_free, .read = bdev_read, .probe = bdev_probe, + .killsb = kill_block_super, .kill = bdev_kill, .size = bdev_size, .devname= bdev_devname
fs/squashfs/squashfs.h +3 -3
@@ -73,10 +73,10 @@ extern struct inode *squashfs_iget(struct super_block *, long long, unsigned int);extern int squashfs_read_inode (struct inode *,long long ); -/* super.c +/* super.c */ int squashfs_fill_super (struct super_block *,void *,int , -struct squashfs_backend *); -*/ +int (*)(struct super_block *)); +/* * Inodes, files, backend and decompressor operations */
fs/squashfs/super.c +22 -27
119 lines not on this page · raw message
Signature · 18 lines
1.5.6.5 From 32d8c56b48b79a37a2b8204c1a14767287ea6044 Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Sun, 21 Mar 2010 02:08:58 +0100 Subject: [PATCH] squashfs: read uncompressed blocks through the backend framework Avoid double free on the temporary decompression hack-path; this may leak buffer heads if decompression exits early. --- fs/squashfs/backend.h | 4 +- fs/squashfs/bdev.c | 191 ++++++++++++++++++++++++++++++++++++++---- fs/squashfs/block.c | 167 ++++++++----------------------------- fs/squashfs/lzma_wrapper.c | 2 + fs/squashfs/squashfs_fs_sb.h | 2 - fs/squashfs/super.c | 5 +- 6 files changed, 216 insertions(+), 155 deletions(-)
fs/squashfs/backend.h +2 -2
@@ -4,9 +4,9 @@#include "squashfs_fs_sb.h" struct squashfs_backend { -void *(*init)(struct squashfs_sb_info *,u64 ,size_t ); +int (*init)(struct super_block *,u64 ,int ,int ,u64 *,int *);void (*free)(struct squashfs_sb_info *); -ssize_t (*read)(struct squashfs_sb_info *,void **,size_t ); +int (*read)(struct super_block *,void *,int );int (*probe)(struct file_system_type *,int ,const char *,void *,struct vfsmount *);void (*killsb)(struct super_block *);
fs/squashfs/bdev.c +174 -17
243 lines not on this page · raw message
fs/squashfs/block.c +36 -131
197 lines not on this page · raw message
fs/squashfs/lzma_wrapper.c +2 -0
@@ -94,6 +94,8 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,void *buff = stream->input;int avail, i, bytes = length, res; +TRACE ("lzma_uncompress: bh=%p, b=%d, offset=%d, length=%d, srclength=%d," +" pages=%d\n" , bh, b, offset, length, srclength, pages);mutex_lock (&lzma_mutex);for (i =0 ; i < b; i++) {
fs/squashfs/squashfs_fs_sb.h +0 -2
@@ -55,8 +55,6 @@ struct squashfs_sb_info {const struct squashfs_decompressor *decompressor;const struct squashfs_backend *backend;void *backend_data; -int devblksize; -int devblksize_log2;struct squashfs_cache *block_cache;struct squashfs_cache *fragment_cache;struct squashfs_cache *read_page;
fs/squashfs/super.c +2 -3
@@ -87,7 +87,7 @@ int squashfs_fill_super(struct super_block *sb, void *data, int silent,u64 lookup_table_start;int err; -TRACE ("Entered squashfs_fill_superblock\n" ); +TRACE ("Entered squashfs_fill_superblock, silent=%d\n" , silent); sb->s_fs_info =kzalloc (sizeof (*msblk),GFP_KERNEL );if (sb->s_fs_info ==NULL ) {
@@ -103,8 +103,6 @@ int squashfs_fill_super(struct super_block *sb, void *data, int silent, goto free_msblk; } - msblk->devblksize =sb_min_blocksize (sb,BLOCK_SIZE ); - msblk->devblksize_log2 =ffz (~msblk->devblksize); err =add_backend (sb);if (err) goto free_sblk;
@@ -305,6 +303,7 @@ failed_mount:kfree (msblk->inode_lookup_table);/* FIXME: squashfs_put_super has meta_index instead */ kfree (msblk->fragment_index);kfree (msblk->id_table); +TRACE ("squasfs_fill_super: killing backend, err=%d\n" , err); msblk->backend->kill (msblk); free_sblk:kfree (sblk);
Signature · 14 lines
1.5.6.5 From 7bad4e58afdc8c5e21dafcd538a1390e30176b0a Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Sun, 21 Mar 2010 22:38:00 +0100 Subject: [PATCH] squashfs: move the decompressors to the backend framework --- fs/squashfs/block.c | 17 +---------------- fs/squashfs/decompressor.h | 12 +++++------- fs/squashfs/lzma_wrapper.c | 27 +++++++++------------------ fs/squashfs/zlib_wrapper.c | 44 ++++++++++++++++++-------------------------- 4 files changed, 33 insertions(+), 67 deletions(-)
fs/squashfs/block.c +1 -16
@@ -39,18 +39,6 @@#include "decompressor.h" #include "backend.h" -/* FIXME: here for a temporary cheat only */ -struct squashfs_bdev { -int devblksize;/* FIXME: == s->s_blocksize(_bits)? */ -unsigned short devblksize_log2; -int length; -int bytes_read; -struct buffer_head **bh; -int bh_index;/* number of consumed buffer_heads */ -int offset;/* offset of next byte in buffer_head */ -int b;/* total number of buffer heads */ -}; -/* * Read and decompress a metadata block or datablock. Length is non-zero * if a datablock is being read (the size is stored elsewhere in the
@@ -71,10 +59,7 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,return length;if (compressed) { -struct squashfs_bdev *bdev = msblk->backend_data; - length =squashfs_decompress (msblk, buffer, bdev->bh, bdev->b, - bdev->offset, length, srclength, pages); - bdev->bh_index = bdev->b;/* temporary hack to avoid double free */ + length =squashfs_decompress (sb, buffer, length, pages);if (length <0 ) goto read_failure; }else {
fs/squashfs/decompressor.h +5 -7
@@ -26,8 +26,7 @@struct squashfs_decompressor {void *(*init)(struct squashfs_sb_info *);void (*free)(void *); -int (*decompress)(struct squashfs_sb_info *,void **, -struct buffer_head **,int ,int ,int ,int ,int ); +int (*decompress)(struct super_block *,void **,int ,int );int id;char *name;int supported;
@@ -45,11 +44,10 @@ static inline void squashfs_decompressor_free(struct squashfs_sb_info *msblk, msblk->decompressor->free(s); } -static inline int squashfs_decompress (struct squashfs_sb_info *msblk, -void **buffer,struct buffer_head **bh,int b,int offset,int length, -int srclength,int pages) +static inline int squashfs_decompress (struct super_block *sb, +void **buffer,int length,int pages) { -return msblk->decompressor->decompress (msblk, buffer, bh, b, offset, - length, srclength, pages); +struct squashfs_sb_info *msblk = sb->s_fs_info; +return msblk->decompressor->decompress (sb, buffer, length, pages); }#endif
fs/squashfs/lzma_wrapper.c +9 -18
@@ -32,6 +32,7 @@#include "squashfs_fs_i.h" #include "squashfs.h" #include "decompressor.h" +#include "backend.h" struct squashfs_lzma {void *input;
@@ -86,29 +87,23 @@ static void lzma_free(void *strm) } -static int lzma_uncompress (struct squashfs_sb_info *msblk,void **buffer, -struct buffer_head **bh,int b,int offset,int length,int srclength, -int pages) +static int lzma_uncompress (struct super_block *sb,void **buffer, +int length,int pages) { +struct squashfs_sb_info *msblk = sb->s_fs_info;struct squashfs_lzma *stream = msblk->stream;void *buff = stream->input;int avail, i, bytes = length, res; -TRACE ("lzma_uncompress: bh=%p, b=%d, offset=%d, length=%d, srclength=%d," -" pages=%d\n" , bh, b, offset, length, srclength, pages); +TRACE ("lzma_uncompress: length=%d, pages=%d\n" , length, pages);mutex_lock (&lzma_mutex); -for (i =0 ; i < b; i++) { -wait_on_buffer (bh[i]); -if (!buffer_uptodate (bh[i])) - goto block_release; - - avail =min (bytes, msblk->devblksize - offset); -memcpy (buff, bh[i]->b_data + offset, avail); +while ((avail = msblk->backend->read (sb, buff, length))) { +if (avail <0 ) + goto failed; +TRACE ("read %d bytes\n" , avail); buff += avail; bytes -= avail; - offset =0 ; -put_bh (bh[i]); } lzma_error =0 ;
@@ -131,10 +126,6 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,mutex_unlock (&lzma_mutex);return res; -block_release: -for (; i < b; i++) -put_bh (bh[i]); - failed:mutex_unlock (&lzma_mutex);
fs/squashfs/zlib_wrapper.c +18 -26
89 lines not on this page · raw message
Signature · 16 lines
1.5.6.5 From 9cb2a2373ab4b7a5519c5a2ef816894e28778196 Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Tue, 23 Mar 2010 02:21:27 +0100 Subject: [PATCH] squashfs: add mtd backend --- fs/squashfs/Kconfig | 2 +- fs/squashfs/Makefile | 1 + fs/squashfs/backend.c | 3 + fs/squashfs/mtd.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/squashfs.h | 3 + 5 files changed, 175 insertions(+), 1 deletions(-) create mode 100644 fs/squashfs/mtd.c
fs/squashfs/Kconfig +1 -1
@@ -1,6 +1,6 @@ config SQUASHFS tristate "SquashFS 4.0 - Squashed file system support" - depends on BLOCK + depends on BLOCK || MTD select ZLIB_INFLATE help Saying Y here includes support for SquashFS 4.0 (a Compressed
fs/squashfs/Makefile +1 -0
@@ -7,3 +7,4 @@ squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o backend.o squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o squashfs-$(CONFIG_BLOCK) += bdev.o +squashfs-$(CONFIG_MTD) += mtd.o
fs/squashfs/backend.c +3 -0
@@ -8,6 +8,9 @@ const struct squashfs_backend *backends[] = {#ifdef CONFIG_BLOCK &squashfs_bdev_ops,#endif +#ifdef CONFIG_MTD + &squashfs_mtd_ops, +#endifNULL };
fs/squashfs/mtd.c new file +167 -0
167 lines not on this page · raw message
fs/squashfs/squashfs.h +3 -0
@@ -104,3 +104,6 @@ extern const struct squashfs_decompressor squashfs_lzma_comp_ops;/* bdev.c */ extern const struct squashfs_backend squashfs_bdev_ops; + +/* mtd.c */ +extern const struct squashfs_backend squashfs_mtd_ops;
Signature · 14 lines
1.5.6.5 From 294602c4fed7319aeb5c44fff5bb8649f1f37b6e Mon Sep 17 00:00:00 2001 From: Ferenc Wagner <[email protected]> Date: Tue, 23 Mar 2010 10:21:40 +0100 Subject: [PATCH] squashfs: pull out common logic of backend init functions --- fs/squashfs/backend.h | 2 +- fs/squashfs/bdev.c | 155 +++++++++---------------------------------------- fs/squashfs/block.c | 33 ++++++++++- fs/squashfs/mtd.c | 38 +----------- 4 files changed, 62 insertions(+), 166 deletions(-)
fs/squashfs/backend.h +1 -1
@@ -4,7 +4,7 @@#include "squashfs_fs_sb.h" struct squashfs_backend { -int (*init)(struct super_block *,u64 ,int ,int ,u64 *,int *); +int (*init)(struct super_block *,u64 ,int );void (*free)(struct squashfs_sb_info *);int (*read)(struct super_block *,void *,int ); int (*probe)(struct file_system_type *, int, const char *,
fs/squashfs/bdev.c +27 -128
183 lines not on this page · raw message
fs/squashfs/block.c +31 -2
@@ -53,8 +53,37 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,int compressed;struct squashfs_sb_info *msblk = sb->s_fs_info; - length = msblk->backend->init (sb, index, length, srclength, - next_index, &compressed); +if (length) {/* Data block */ + compressed =SQUASHFS_COMPRESSED_BLOCK (length); + length =SQUASHFS_COMPRESSED_SIZE_BLOCK (length); +TRACE ("Block @ 0x%llx, %scompressed size %d, src size %d\n" , + index, compressed ?"" :"un" , length, srclength); + }else {/* Metadata block */ +int read; +u16 metalen; + + length = msblk->backend->init (sb, index,2 ); +if (length <0 ) +return length; + read = msblk->backend->read (sb, &metalen,2 ); +if (read !=2 ) + goto read_failure; + msblk->backend->free (msblk); + length =le16_to_cpu (metalen); + compressed =SQUASHFS_COMPRESSED (length); + length =SQUASHFS_COMPRESSED_SIZE (length); + index +=2 ; +TRACE ("Block @ 0x%llx, %scompressed size %d\n" , index, + compressed ?"" :"un" , length); + } +if (length <0 || length > srclength || + (index + length) > msblk->bytes_used) + goto read_failure; + +if (next_index) + *next_index = index + length; + + length = msblk->backend->init (sb, index, length);if (length <0 )return length;
fs/squashfs/mtd.c +3 -35
@@ -38,50 +38,18 @@ static int checked_mtd_read(struct super_block *sb, u64 index, int length,return 0 ; } -static int mtd_init (struct super_block *sb,u64 index,int length, -int srclength,u64 *next_index,int *compressed) +static int mtd_init (struct super_block *sb,u64 index,int length) {struct squashfs_sb_info *msblk = sb->s_fs_info;struct squashfs_mtd *mtd = msblk->backend_data; -TRACE ("Entering mtd_init: index=0x%llx, length=0x%x, srclength=%d\n" , - index, length, srclength); - -if (length) {/* datablock */ - *compressed =SQUASHFS_COMPRESSED_BLOCK (length); - length =SQUASHFS_COMPRESSED_SIZE_BLOCK (length); -if (next_index) - *next_index = index + length; -TRACE ("Block @ 0x%llx, %scompressed size %d, src size %d\n" , - index, *compressed ?"" :"un" , length, srclength); - }else {/* metadata block */ -u16 metalen; -if ((index +2 ) > msblk->bytes_used) - goto read_failure; -if (checked_mtd_read (sb, index,2 , &metalen)) - goto read_failure; - length =le16_to_cpu (metalen); - *compressed =SQUASHFS_COMPRESSED (length); - length =SQUASHFS_COMPRESSED_SIZE (length); -if (next_index) - *next_index = index + length +2 ; -TRACE ("Block @ 0x%llx, %scompressed size %d\n" , index, - *compressed ?"" :"un" , length); - index +=2 ; - } -if (length <0 || length > srclength || - (index + length) > msblk->bytes_used) - goto read_failure; +TRACE ("Entering mtd_init: index=0x%llx, length=0x%x\n" , + index, length); mtd->index = index; mtd->length = length; mtd->bytes_read =0 ;return length; - -read_failure: -ERROR ("mtd_init failed to read block 0x%llx\n" , - (unsigned long long ) index); -return -EIO ; }static void mtd_free (struct squashfs_sb_info *msblk)
Signature · 1 line
1.5.6.5
Quoted 4 lines · Ferenc Wagner
Now with the patch series, sorry.
Ferenc Wagner <[email protected]> writes:
Quoted 9 lines
Quoted 5 lines
I've got one more patch, which I forgot to export, to pull out the common logic from the backend init functions back into
squashfs_read_data(). With the bdev backend, that entails reading the first block twice in a row most of the time. This again could be worked around by extending the backend interface, but I'm not sure if it's worth it.Here it is. I also corrected the name of
SQUASHFS_METADATA_SIZE, so it may as well compile now.
Thanks for your patches.
First things first. Patch sending etiquette :-)
1. Please don't send separate git commits in one big email, it makes them hard to cross-reference (I lost count of the times I had to repeatedly scroll though the email to check an earlier commit).
2. Please don't send a patch series consisting of your development process. Reviewing takes effort, having reviewed one commit to find it reworked in a second commit, and then reworked again, as the code evolves from a -> b -> c-> d is irritating, it makes the final solution harder to evaluate (because you have to keep all the changes in your head), and wastes my time.
3. Incremental patches are valid if they break up a patch series into easily digestible changes which can be separately understood, but not if they're just reworking your code as development progresses...
OK, now for the specific comments.
Frameworks are supposed to make the code cleaner, more understandable, and generally better. Unfortunately, I see no evidence of that in your patch. Sorry to be blunt, but there it is.
The backend has seven functions!
+ void *(*init)(struct squashfs_sb_info *, u64, size_t);
+ void (*free)(struct squashfs_sb_info *);
+ ssize_t (*read)(struct squashfs_sb_info *, void **, size_t);
+ int (*probe)(struct file_system_type *, int, const char *,
+ void*, struct vfsmount *);
+ void (*kill)(struct squashfs_sb_info *);
+ loff_t (*size)(const struct super_block *);
+ const char *(*devname)(const struct super_block *, char *);
We move from a single read() function to requiring seven functions to do the same work, just to add mtd support...
Reading the superblock changes into a 6 function deep nightmare squashfs_find_backend -> probe -> get_sb_dev -> fill_bdev_super -> squashfs_fill_super -> add_backend
I find the current 3 function deep situation forced by VFS already a mess, squashfs_get_sb -> get_sb_bdev -> squashfs_fill_super
Reading a block now takes 3 function calls, init, read, and free. Plus in your last commit you make the huge mistake of preferring code elegance over performance, and resort to calling init, read, and free *twice*, the first just to read *two* bytes (yes, 2 bytes). Why do you think the code was coded that way in the first place? A fit of absent mindedness perhaps? No, for performance reasons.
Secondly you make the classic mistake of concentrating on what you want to do (add MTD), and not giving a damn about anything else. You've totally broken all the read optimisations in zlib decompression for block devices. Buffer_heads are deliberately passed directly to the zlib decompressor to allow it to optimise performance (pass the buffer_head directly to zlib etc.). Buffer_heads are exposed to the decompressors without crappy go-between wrappers deliberately.
Unfortunately there are lots of other instances where you've eliminated carefully optimised code.
That's another of my major issues, the patch seems hugely gratuitous, it touches a huge amount of files/code it shouldn't do, much of this slicing up optimisied heavily tested and fragile code into other files/functions hither and thither. Unfortunately much of this code took a long time to get right, and suffered numerous unanticipated edge conditions/fsfuzzer triggered bugs. I only touch this code with caution and nothing like to the extent you've subjected it to.
In short this doesn't pass my quality threshold or the make the minimum changes necessary threshold. I wouldn't consider asking Linus to merge this.
BTW as a comparison, I have added MTD support to Squashfs twice in the past, *with* bad block support. The latest has a diff patch of ~500 lines, with far less complexity and code changes necessary.
BTW2 as evidenced by your FIXME comments against my code in your patch, you really have to get over the notion that if you don't understand it, the code must be wrong.
Cheers
Phillip
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Phillip" == Phillip Lougher <[email protected]> writes:
Hi,
Phillip> BTW as a comparison, I have added MTD support to Squashfs Phillip> twice in the past, *with* bad block support. The latest has a Phillip> diff patch of ~500 lines, with far less complexity and code Phillip> changes necessary.
Could we merge that then please?
Again, what kind of size reduction can we expect from getting rid of the block layer?
Signature · 1 line
Bye, Peter Korsgaard
Quoted 9 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Phillip" == Phillip Lougher <[email protected]> writes:
Phillip> BTW as a comparison, I have added MTD support to Squashfs Phillip> twice in the past, *with* bad block support. The latest has a Phillip> diff patch of ~500 lines, with far less complexity and code Phillip> changes necessary.
Again, what kind of size reduction can we expect from getting rid of the block layer?
My size-optimized OpenWRT vmlinux shrank ~170 kB after disabling CONFIG_BLOCK. Similarly for the memory consumption.
Signature · 2 lines
Regards, Feri.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Ferenc" == Ferenc Wagner <[email protected]> writes:
Hi,
Quoted 2 lines
Quoted 2 lines
Again, what kind of size reduction can we expect from getting rid of the block layer?
Ferenc> My size-optimized OpenWRT vmlinux shrank ~170 kB after disabling Ferenc> CONFIG_BLOCK. Similarly for the memory consumption.
Neat, thanks - That sounds worthwhile.
Signature · 1 line
Bye, Peter Korsgaard
Quoted 12 lines · Phillip Lougher
Quoted 10 lines · Ferenc Wagner
Now with the patch series, sorry.
Quoted 5 lines · Ferenc Wagner
I've got one more patch, which I forgot to export, to pull out the common logic from the backend init functions back into
squashfs_read_data(). With the bdev backend, that entails reading the first block twice in a row most of the time. This again could be worked around by extending the backend interface, but I'm not sure if it's worth it.
Quoted 6 lines
Quoted 2 lines
Here it is. I also corrected the name of
SQUASHFS_METADATA_SIZE, so it may as well compile now.Thanks for your patches.
First things first. Patch sending etiquette :-) [...]
Points taken. About the splits, they were the result of quite some
rebasing: I tried to give each patch a unique focus, but apparently failed. Only the last one touches substantial changed code, for the explicitly stated reason: it hurts performance.
Quoted 2 lines
Frameworks are supposed to make the code cleaner, more understandable, and generally better.
This framework is about added flexibility. I agree it requires some added complexity, but I hope we can manage it.
Quoted 2 lines
Unfortunately, I see no evidence of that in your patch. Sorry to be blunt, but there it is.
No problem.
Quoted 11 lines
fs/squashfs/backend.h new file +8
-0+void *(*init)(struct squashfs_sb_info *,u64 ,size_t ); +void (*free)(struct squashfs_sb_info *); +ssize_t (*read)(struct squashfs_sb_info *,void **,size_t ); +int (*probe)(struct file_system_type *,int ,const char *, +void *,struct vfsmount *); +void (*kill)(struct squashfs_sb_info *); +loff_t (*size)(const struct super_block *); +const char *(*devname)(const struct super_block *,char *);We move from a single
read()function to requiring seven functions to do the same work, just to add mtd support...
Your single read() function also had separate init, read and free phases, with something generic in between. I can try to invert the structure, but see below.
Quoted 3 lines
Reading the superblock changes into a 6 function deep nightmare
squashfs_find_backend-> probe ->get_sb_dev->fill_bdev_super->squashfs_fill_super->add_backend
It's convoluted, but only moves original code around. If you prefer, I can simplify that by embedding squashfs_sb_info into backend-specific structures and allocating those separately. This would also get rid of some of the above 7 functions.
Quoted 1 line
Reading a block now takes 3 function calls, init, read, and free.
Actually, read must be called several times. Are you worried by the cost of the indirect function calls?
Quoted 5 lines
Plus in your last commit you make the huge mistake of preferring code elegance over performance, and resort to calling init, read, and free *twice*, the first just to read *two* bytes (yes, 2 bytes). Why do you think the code was coded that way in the first place? A fit of absent mindedness perhaps? No, for performance reasons.
I also pointed this out, and that's mosly why I created a separate last patch. I don't think it's optimal, but replicating the metadata length handling in the backends isn't either. There's RFC in the subject after all...
Quoted 5 lines
You've totally broken all the read optimisations in zlib decompression for block devices.
Buffer_headsare deliberately passed directly to the zlib decompressor to allow it to optimise performance (pass thebuffer_headdirectly to zlib etc.).Buffer_headsare exposed to the decompressors without crappy go-between wrappers deliberately.
At least this is something I noticed and expressed my concers about. You probably missed that due to the lots of scrolling required by my sub-par patch-posting technique. :)
Quoted 2 lines
Unfortunately there are lots of other instances where you've eliminated carefully optimised code.
Could you please provide some examples?
Quoted 3 lines
In short this doesn't pass my quality threshold or the make the minimum changes necessary threshold. I wouldn't consider asking Linus to merge this.
Please don't. It's a proof of concept, nothing more. Even a proof of a wrong concept.
Quoted 2 lines
BTW as a comparison, I have added MTD support to Squashfs twice in the past, *with* bad block support.
Unfortunately you aren't allowed to share those, if I read it right.
Quoted 2 lines
The latest has a diff patch of ~500 lines, with far less complexity and code changes necessary.
Sure, have a look at my very first patch: 3 files changed, 210 insertions, 21 deletions. And that didn't remove bdev support.
Quoted 3 lines
BTW2 as evidenced by your FIXME comments against my code in your patch, you really have to get over the notion that if you don't understand it, the code must be wrong.
Sometimes those are FIXMEs to make finding them easier, and are questions really. If you feel like answering them:
/* FIXME: == s->s_blocksize(_bits)? */
Why do you use devblksize and devblksize_log2 in squashfs_sb_info? Aren't they the same as sb->s_blocksize and sb->s_blocksize_bits, as their names suggest?
/* FIXME: squashfs_put_super has meta_index instead */
The failed_mount: part of squashfs_fill_super() is very similar to squashfs_put_super(), but frees meta_index instead of id_table. Why?
These are probably easy questions for people knowing the VFS layer well, but I am not one of those. They just triggered my built-in pattern matcher.
Signature · 2 lines
Regards, Feri.
cover RFC: direct MTD support for SquashFS
Hi,
Here is another, very different take on the subject. It isn't a real plugin system, but touches as little existing code as possible, and still quite easy to extend if needed. The MTD with LZMA case is somewhat challenged, as the current interface mismatch requires extra copying. It seems fairly easy to change the kernel decompressor interface to scatter/gather operation in the future, to do away with this.
This patch does not consider SQUASHFS_METADATA_SIZE during buffer_head allocation in block.c, on the principle of hands-off.
Extra question: does squashfs_put_super require BKL protection?
Comments welcome.
Regards,
Feri.
Ferenc Wagner (3):
squashfs: parametrize decompressors on buffer_head operations
squashfs: gather everything block device specific into block.c
squashfs: add MTD backend
fs/squashfs/Kconfig | 2 +- fs/squashfs/Makefile | 6 +- fs/squashfs/backend.c | 63 +++++++++++++++ fs/squashfs/backend.h | 12 +++ fs/squashfs/block.c | 42 +++++++--- fs/squashfs/decompressor.h | 8 +- fs/squashfs/lzma_wrapper.c | 11 ++- fs/squashfs/mtd.c | 179 ++++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/squashfs.h | 22 +++++- fs/squashfs/super.c | 45 +++--------- fs/squashfs/zlib_wrapper.c | 13 ++-- 11 files changed, 337 insertions(+), 66 deletions(-) create mode 100644 fs/squashfs/backend.c create mode 100644 fs/squashfs/backend.h create mode 100644 fs/squashfs/mtd.c
2010/3/30 Ferenc Wagner <[email protected]>:
Quoted 3 lines
Extra question: does
squashfs_put_superrequire BKL protection?
We should get rid off of BKL, so if you need a lock, you should use a local mutex.
Marco
cover RFC: direct MTD support for SquashFS
In reply to Ferenc WagnerHi,
Here is another, very different take on the subject. It isn't a real plugin system, but touches as little existing code as possible, and still quite easy to extend if needed. The MTD with LZMA case is somewhat challenged, as the current interface mismatch requires extra copying. It seems fairly easy to change the kernel decompressor interface to scatter/gather operation in the future, to do away with this.
This patch does not consider SQUASHFS_METADATA_SIZE during buffer_head allocation in block.c, on the principle of hands-off.
Extra question: does squashfs_put_super require BKL protection?
Comments welcome.
Regards,
Feri.
Ferenc Wagner (3):
squashfs: parametrize decompressors on buffer_head operations
squashfs: gather everything block device specific into block.c
squashfs: add MTD backend
fs/squashfs/Kconfig | 2 +- fs/squashfs/Makefile | 6 +- fs/squashfs/backend.c | 63 +++++++++++++++ fs/squashfs/backend.h | 12 +++ fs/squashfs/block.c | 42 +++++++--- fs/squashfs/decompressor.h | 8 +- fs/squashfs/lzma_wrapper.c | 11 ++- fs/squashfs/mtd.c | 179 ++++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/squashfs.h | 22 +++++- fs/squashfs/super.c | 45 +++--------- fs/squashfs/zlib_wrapper.c | 13 ++-- 11 files changed, 337 insertions(+), 66 deletions(-) create mode 100644 fs/squashfs/backend.c create mode 100644 fs/squashfs/backend.h create mode 100644 fs/squashfs/mtd.c
PATCH 1/3 squashfs: parametrize decompressors on buffer_head operations
In reply to Ferenc Wagner--- fs/squashfs/block.c | 9 ++++++++- fs/squashfs/decompressor.h | 8 +++++--- fs/squashfs/lzma_wrapper.c | 11 ++++++----- fs/squashfs/zlib_wrapper.c | 13 +++++++------ 4 files changed, 26 insertions(+), 15 deletions(-)
fs/squashfs/block.c +8 -1
@@ -37,6 +37,13 @@#include "squashfs_fs_i.h" #include "squashfs.h" #include "decompressor.h" + +static int update_buffer (struct buffer_head *bh) +{ +wait_on_buffer (bh); +return buffer_uptodate (bh); +} +/* * Read the metadata block length, this is stored in the first two * bytes of the metadata block.
@@ -152,7 +159,7 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,if (compressed) { length =squashfs_decompress (msblk, buffer, bh, b, offset, - length, srclength, pages); + length, srclength, pages, update_buffer, put_bh);if (length <0 ) goto read_failure; }else {
fs/squashfs/decompressor.h +5 -3
@@ -27,7 +27,8 @@ struct squashfs_decompressor {void *(*init)(struct squashfs_sb_info *);void (*free)(void *);int (*decompress)(struct squashfs_sb_info *,void **, -struct buffer_head **,int ,int ,int ,int ,int ); +struct buffer_head **,int ,int ,int ,int ,int , +int (*)(struct buffer_head *),void (*)(struct buffer_head *));int id;char *name;int supported;
@@ -47,9 +48,10 @@ static inline void squashfs_decompressor_free(struct squashfs_sb_info *msblk,static inline int squashfs_decompress (struct squashfs_sb_info *msblk,void **buffer,struct buffer_head **bh,int b,int offset,int length, -int srclength,int pages) +int srclength,int pages, +int (*update_buffer)(struct buffer_head *),void (*put_buffer)(struct buffer_head *)) {return msblk->decompressor->decompress (msblk, buffer, bh, b, offset, - length, srclength, pages); + length, srclength, pages, update_buffer, put_buffer); }#endif
fs/squashfs/lzma_wrapper.c +6 -5
@@ -88,7 +88,9 @@ static void lzma_free(void *strm)static int lzma_uncompress (struct squashfs_sb_info *msblk,void **buffer,struct buffer_head **bh,int b,int offset,int length,int srclength, -int pages) +int pages, +int (*update_buffer)(struct buffer_head *), +void (*put_buffer)(struct buffer_head *)) {struct squashfs_lzma *stream = msblk->stream;void *buff = stream->input;
@@ -97,8 +99,7 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,mutex_lock (&lzma_mutex);for (i =0 ; i < b; i++) { -wait_on_buffer (bh[i]); -if (!buffer_uptodate (bh[i])) +if (!update_buffer (bh[i])) goto block_release; avail =min (bytes, msblk->devblksize - offset);
@@ -106,7 +107,7 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer, buff += avail; bytes -= avail; offset =0 ; -put_bh (bh[i]); +put_buffer (bh[i]); } lzma_error =0 ;
@@ -131,7 +132,7 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer, block_release:for (; i < b; i++) -put_bh (bh[i]); +put_buffer (bh[i]); failed:mutex_unlock (&lzma_mutex);
fs/squashfs/zlib_wrapper.c +7 -6
@@ -63,7 +63,9 @@ static void zlib_free(void *strm)static int zlib_uncompress (struct squashfs_sb_info *msblk,void **buffer,struct buffer_head **bh,int b,int offset,int length,int srclength, -int pages) +int pages, +int (*update_buffer)(struct buffer_head *), +void (*put_buffer)(struct buffer_head *)) {int zlib_err =0 , zlib_init =0 ;int avail, bytes, k =0 , page =0 ;
@@ -79,13 +81,12 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,if (stream->avail_in ==0 && k < b) { avail =min (bytes, msblk->devblksize - offset); bytes -= avail; -wait_on_buffer (bh[k]); -if (!buffer_uptodate (bh[k])) +if (!update_buffer (bh[k])) goto release_mutex;if (avail ==0 ) { offset =0 ; -put_bh (bh[k++]); +put_buffer (bh[k++]);continue ; }
@@ -113,7 +114,7 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, zlib_err =zlib_inflate (stream,Z_SYNC_FLUSH );if (stream->avail_in ==0 && k < b) -put_bh (bh[k++]); +put_buffer (bh[k++]); }while (zlib_err ==Z_OK );if (zlib_err !=Z_STREAM_END ) {
@@ -134,7 +135,7 @@ release_mutex:mutex_unlock (&msblk->read_data_mutex);for (; k < b; k++) -put_bh (bh[k]); +put_buffer (bh[k]);return -EIO ; }
Signature · 1 line
1.6.5
PATCH 1/3 squashfs: parametrize decompressors on buffer_head operations
In reply to Ferenc Wagner--- fs/squashfs/block.c | 9 ++++++++- fs/squashfs/decompressor.h | 8 +++++--- fs/squashfs/lzma_wrapper.c | 11 ++++++----- fs/squashfs/zlib_wrapper.c | 13 +++++++------ 4 files changed, 26 insertions(+), 15 deletions(-)
fs/squashfs/block.c +8 -1
@@ -37,6 +37,13 @@#include "squashfs_fs_i.h" #include "squashfs.h" #include "decompressor.h" + +static int update_buffer (struct buffer_head *bh) +{ +wait_on_buffer (bh); +return buffer_uptodate (bh); +} +/* * Read the metadata block length, this is stored in the first two * bytes of the metadata block.
@@ -152,7 +159,7 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,if (compressed) { length =squashfs_decompress (msblk, buffer, bh, b, offset, - length, srclength, pages); + length, srclength, pages, update_buffer, put_bh);if (length <0 ) goto read_failure; }else {
fs/squashfs/decompressor.h +5 -3
@@ -27,7 +27,8 @@ struct squashfs_decompressor {void *(*init)(struct squashfs_sb_info *);void (*free)(void *);int (*decompress)(struct squashfs_sb_info *,void **, -struct buffer_head **,int ,int ,int ,int ,int ); +struct buffer_head **,int ,int ,int ,int ,int , +int (*)(struct buffer_head *),void (*)(struct buffer_head *));int id;char *name;int supported;
@@ -47,9 +48,10 @@ static inline void squashfs_decompressor_free(struct squashfs_sb_info *msblk,static inline int squashfs_decompress (struct squashfs_sb_info *msblk,void **buffer,struct buffer_head **bh,int b,int offset,int length, -int srclength,int pages) +int srclength,int pages, +int (*update_buffer)(struct buffer_head *),void (*put_buffer)(struct buffer_head *)) {return msblk->decompressor->decompress (msblk, buffer, bh, b, offset, - length, srclength, pages); + length, srclength, pages, update_buffer, put_buffer); }#endif
fs/squashfs/lzma_wrapper.c +6 -5
@@ -88,7 +88,9 @@ static void lzma_free(void *strm)static int lzma_uncompress (struct squashfs_sb_info *msblk,void **buffer,struct buffer_head **bh,int b,int offset,int length,int srclength, -int pages) +int pages, +int (*update_buffer)(struct buffer_head *), +void (*put_buffer)(struct buffer_head *)) {struct squashfs_lzma *stream = msblk->stream;void *buff = stream->input;
@@ -97,8 +99,7 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,mutex_lock (&lzma_mutex);for (i =0 ; i < b; i++) { -wait_on_buffer (bh[i]); -if (!buffer_uptodate (bh[i])) +if (!update_buffer (bh[i])) goto block_release; avail =min (bytes, msblk->devblksize - offset);
@@ -106,7 +107,7 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer, buff += avail; bytes -= avail; offset =0 ; -put_bh (bh[i]); +put_buffer (bh[i]); } lzma_error =0 ;
@@ -131,7 +132,7 @@ static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer, block_release:for (; i < b; i++) -put_bh (bh[i]); +put_buffer (bh[i]); failed:mutex_unlock (&lzma_mutex);
fs/squashfs/zlib_wrapper.c +7 -6
@@ -63,7 +63,9 @@ static void zlib_free(void *strm)static int zlib_uncompress (struct squashfs_sb_info *msblk,void **buffer,struct buffer_head **bh,int b,int offset,int length,int srclength, -int pages) +int pages, +int (*update_buffer)(struct buffer_head *), +void (*put_buffer)(struct buffer_head *)) {int zlib_err =0 , zlib_init =0 ;int avail, bytes, k =0 , page =0 ;
@@ -79,13 +81,12 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,if (stream->avail_in ==0 && k < b) { avail =min (bytes, msblk->devblksize - offset); bytes -= avail; -wait_on_buffer (bh[k]); -if (!buffer_uptodate (bh[k])) +if (!update_buffer (bh[k])) goto release_mutex;if (avail ==0 ) { offset =0 ; -put_bh (bh[k++]); +put_buffer (bh[k++]);continue ; }
@@ -113,7 +114,7 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, zlib_err =zlib_inflate (stream,Z_SYNC_FLUSH );if (stream->avail_in ==0 && k < b) -put_bh (bh[k++]); +put_buffer (bh[k++]); }while (zlib_err ==Z_OK );if (zlib_err !=Z_STREAM_END ) {
@@ -134,7 +135,7 @@ release_mutex:mutex_unlock (&msblk->read_data_mutex);for (; k < b; k++) -put_bh (bh[k]); +put_buffer (bh[k]);return -EIO ; }
Signature · 1 line
1.6.5
PATCH 2/3 squashfs: gather everything block device specific into block.c
In reply to Ferenc WagnerWe use buffer_head structures for communicating with the decompressors, so provide a basic definition even if CONFIG_BLOCK=n (which results in a backendless - ie. useless - squashfs right now).
--- fs/squashfs/Kconfig | 1 - fs/squashfs/Makefile | 5 +++-- fs/squashfs/backend.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/backend.h | 12 ++++++++++++ fs/squashfs/block.c | 33 +++++++++++++++++++++------------ fs/squashfs/squashfs.h | 18 +++++++++++++++++- fs/squashfs/super.c | 45 ++++++++++----------------------------------- 7 files changed, 111 insertions(+), 51 deletions(-) create mode 100644 fs/squashfs/backend.c create mode 100644 fs/squashfs/backend.h
fs/squashfs/Kconfig +0 -1
@@ -1,6 +1,5 @@ config SQUASHFS tristate "SquashFS 4.0 - Squashed file system support" - depends on BLOCK select ZLIB_INFLATE help Saying Y here includes support for SquashFS 4.0 (a Compressed
fs/squashfs/Makefile +3 -2
@@ -3,6 +3,7 @@ # obj-$(CONFIG_SQUASHFS) += squashfs.o -squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o -squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o +squashfs-y += cache.o dir.o export.o file.o fragment.o id.o inode.o +squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o backend.o squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o +squashfs-$(CONFIG_BLOCK) += block.o
fs/squashfs/backend.c new file +48 -0
48 lines not on this page · raw message
fs/squashfs/backend.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef BACKEND_H +#define BACKEND_H + +#include <linux/fs.h> +#include <linux/vfs.h> + +int squashfs_find_backend (struct file_system_type *,int ,const char *, +void *,struct vfsmount *); +void squashfs_kill_super (struct super_block *); +int squashfs_read_data (struct super_block *,void **,u64 ,int ,u64 *,int ,int ); + +#endif
fs/squashfs/block.c +21 -12
@@ -23,7 +23,7 @@/* * This file implements the low-level routines to read and decompress -* datablocks and metadata blocks. +* datablocks and metadata blocks from a block device. */ #include <linux/fs.h>
@@ -75,16 +75,7 @@ static struct buffer_head *get_block_length(struct super_block *sb,return bh; } - -/* -* Read and decompress a metadata block or datablock. Length is non-zero -* if a datablock is being read (the size is stored elsewhere in the -* filesystem), otherwise the length is obtained from the first two bytes of -* the metadata block. A bit in the length field indicates if the block -* is stored uncompressed in the filesystem (usually because compression -* generated a larger block - this does occasionally happen with zlib). -*/ -int squashfs_read_data (struct super_block *sb,void **buffer,u64 index, +int bdev_read_data (struct super_block *sb,void **buffer,u64 index,int length,u64 *next_index,int srclength,int pages) {struct squashfs_sb_info *msblk = sb->s_fs_info;
@@ -203,8 +194,26 @@ block_release:put_bh (bh[k]); read_failure: -ERROR ("squashfs_read_data failed to read block 0x%llx\n" , +ERROR ("bdev_read_data failed to read block 0x%llx\n" , (unsigned long long ) index);kfree (bh);return -EIO ; } + +int fill_bdev_super (struct super_block *sb,void *data,int silent) +{ +struct squashfs_sb_info *msblk; +char b[BDEVNAME_SIZE ]; + +TRACE ("Entering fill_bdev_super\n" ); + + msblk =kzalloc (sizeof (*msblk),GFP_KERNEL ); +if (!msblk) +return -ENOMEM ; + + sb->s_fs_info = msblk; + msblk->devblksize =sb_min_blocksize (sb,BLOCK_SIZE ); + msblk->devblksize_log2 =ffz (~msblk->devblksize); +return squashfs_fill_super (sb, data, silent,bdevname (sb->s_bdev, b), +i_size_read (sb->s_bdev->bd_inode)); +}
fs/squashfs/squashfs.h +17 -1
@@ -32,7 +32,7 @@ static inline struct squashfs_inode_info *squashfs_i(struct inode *inode) return list_entry(inode, struct squashfs_inode_info, vfs_inode); } -/* block.c */ +/* backend.c */ extern int squashfs_read_data (struct super_block *,void **,u64 ,int ,u64 *,int ,int );
@@ -73,6 +73,9 @@ extern struct inode *squashfs_iget(struct super_block *, long long, unsigned int);extern int squashfs_read_inode (struct inode *,long long ); +/* super.c */ +extern int squashfs_fill_super (struct super_block *,void *,int ,const char *,int ); +/* * Inodes, files and decompressor operations */
@@ -97,3 +100,16 @@ extern const struct squashfs_decompressor squashfs_zlib_comp_ops;/* lzma wrapper.c */ extern const struct squashfs_decompressor squashfs_lzma_comp_ops; + +/* block.c */ +extern int fill_bdev_super (struct super_block *,void *,int ); +extern int bdev_read_data (struct super_block *,void **,u64 ,int ,u64 *,int ,int ); + +#ifndef CONFIG_BLOCK +struct buffer_head { +sector_t b_blocknr; +size_t b_size; +char *b_data; +void *b_bdev; +}; +#endif
fs/squashfs/super.c +10 -35
106 lines not on this page · raw message
Signature · 1 line
1.6.5
Re: [PATCH 2/3] squashfs: gather everything block device specific into block.c
---
I lost this free somehow. Does squashfs_put_super() need protection from multiple invocation? If not, this kfree could be removed from there, and the condition from both places.
fs/squashfs/backend.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
fs/squashfs/backend.c +4 -0
@@ -24,6 +24,10 @@ int squashfs_find_backend(struct file_system_type *fs_type, int flags,void squashfs_kill_super (struct super_block *sb) { +if (sb->s_fs_info) { +kfree (sb->s_fs_info); + sb->s_fs_info =NULL ; + }#ifdef CONFIG_BLOCK if (sb->s_bdev) {kill_block_super (sb);
Signature · 1 line
1.6.5
PATCH 2/3 squashfs: gather everything block device specific into block.c
In reply to Ferenc WagnerWe use buffer_head structures for communicating with the decompressors, so provide a basic definition even if CONFIG_BLOCK=n (which results in a backendless - ie. useless - squashfs right now).
--- fs/squashfs/Kconfig | 1 - fs/squashfs/Makefile | 5 +++-- fs/squashfs/backend.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/backend.h | 12 ++++++++++++ fs/squashfs/block.c | 33 +++++++++++++++++++++------------ fs/squashfs/squashfs.h | 18 +++++++++++++++++- fs/squashfs/super.c | 45 ++++++++++----------------------------------- 7 files changed, 111 insertions(+), 51 deletions(-) create mode 100644 fs/squashfs/backend.c create mode 100644 fs/squashfs/backend.h
fs/squashfs/Kconfig +0 -1
@@ -1,6 +1,5 @@ config SQUASHFS tristate "SquashFS 4.0 - Squashed file system support" - depends on BLOCK select ZLIB_INFLATE help Saying Y here includes support for SquashFS 4.0 (a Compressed
fs/squashfs/Makefile +3 -2
@@ -3,6 +3,7 @@ # obj-$(CONFIG_SQUASHFS) += squashfs.o -squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o -squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o +squashfs-y += cache.o dir.o export.o file.o fragment.o id.o inode.o +squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o backend.o squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o +squashfs-$(CONFIG_BLOCK) += block.o
fs/squashfs/backend.c new file +48 -0
48 lines not on this page · raw message
fs/squashfs/backend.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef BACKEND_H +#define BACKEND_H + +#include <linux/fs.h> +#include <linux/vfs.h> + +int squashfs_find_backend (struct file_system_type *,int ,const char *, +void *,struct vfsmount *); +void squashfs_kill_super (struct super_block *); +int squashfs_read_data (struct super_block *,void **,u64 ,int ,u64 *,int ,int ); + +#endif
fs/squashfs/block.c +21 -12
@@ -23,7 +23,7 @@/* * This file implements the low-level routines to read and decompress -* datablocks and metadata blocks. +* datablocks and metadata blocks from a block device. */ #include <linux/fs.h>
@@ -75,16 +75,7 @@ static struct buffer_head *get_block_length(struct super_block *sb,return bh; } - -/* -* Read and decompress a metadata block or datablock. Length is non-zero -* if a datablock is being read (the size is stored elsewhere in the -* filesystem), otherwise the length is obtained from the first two bytes of -* the metadata block. A bit in the length field indicates if the block -* is stored uncompressed in the filesystem (usually because compression -* generated a larger block - this does occasionally happen with zlib). -*/ -int squashfs_read_data (struct super_block *sb,void **buffer,u64 index, +int bdev_read_data (struct super_block *sb,void **buffer,u64 index,int length,u64 *next_index,int srclength,int pages) {struct squashfs_sb_info *msblk = sb->s_fs_info;
@@ -203,8 +194,26 @@ block_release:put_bh (bh[k]); read_failure: -ERROR ("squashfs_read_data failed to read block 0x%llx\n" , +ERROR ("bdev_read_data failed to read block 0x%llx\n" , (unsigned long long ) index);kfree (bh);return -EIO ; } + +int fill_bdev_super (struct super_block *sb,void *data,int silent) +{ +struct squashfs_sb_info *msblk; +char b[BDEVNAME_SIZE ]; + +TRACE ("Entering fill_bdev_super\n" ); + + msblk =kzalloc (sizeof (*msblk),GFP_KERNEL ); +if (!msblk) +return -ENOMEM ; + + sb->s_fs_info = msblk; + msblk->devblksize =sb_min_blocksize (sb,BLOCK_SIZE ); + msblk->devblksize_log2 =ffz (~msblk->devblksize); +return squashfs_fill_super (sb, data, silent,bdevname (sb->s_bdev, b), +i_size_read (sb->s_bdev->bd_inode)); +}
fs/squashfs/squashfs.h +17 -1
@@ -32,7 +32,7 @@ static inline struct squashfs_inode_info *squashfs_i(struct inode *inode) return list_entry(inode, struct squashfs_inode_info, vfs_inode); } -/* block.c */ +/* backend.c */ extern int squashfs_read_data (struct super_block *,void **,u64 ,int ,u64 *,int ,int );
@@ -73,6 +73,9 @@ extern struct inode *squashfs_iget(struct super_block *, long long, unsigned int);extern int squashfs_read_inode (struct inode *,long long ); +/* super.c */ +extern int squashfs_fill_super (struct super_block *,void *,int ,const char *,int ); +/* * Inodes, files and decompressor operations */
@@ -97,3 +100,16 @@ extern const struct squashfs_decompressor squashfs_zlib_comp_ops;/* lzma wrapper.c */ extern const struct squashfs_decompressor squashfs_lzma_comp_ops; + +/* block.c */ +extern int fill_bdev_super (struct super_block *,void *,int ); +extern int bdev_read_data (struct super_block *,void **,u64 ,int ,u64 *,int ,int ); + +#ifndef CONFIG_BLOCK +struct buffer_head { +sector_t b_blocknr; +size_t b_size; +char *b_data; +void *b_bdev; +}; +#endif
fs/squashfs/super.c +10 -35
106 lines not on this page · raw message
Signature · 1 line
1.6.5
PATCH 3/3 squashfs: add MTD backend
In reply to Ferenc Wagner--- fs/squashfs/Kconfig | 1 + fs/squashfs/Makefile | 1 + fs/squashfs/backend.c | 15 ++++ fs/squashfs/mtd.c | 179 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/squashfs/squashfs.h | 4 + 5 files changed, 200 insertions(+), 0 deletions(-) create mode 100644 fs/squashfs/mtd.c
fs/squashfs/Kconfig +1 -0
@@ -1,5 +1,6 @@ config SQUASHFS tristate "SquashFS 4.0 - Squashed file system support" + depends on BLOCK || MTD select ZLIB_INFLATE help Saying Y here includes support for SquashFS 4.0 (a Compressed
fs/squashfs/Makefile +1 -0
@@ -7,3 +7,4 @@ squashfs-y += cache.o dir.o export.o file.o fragment.o id.o inode.o squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o backend.o squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o squashfs-$(CONFIG_BLOCK) += block.o +squashfs-$(CONFIG_MTD) += mtd.o
fs/squashfs/backend.c +15 -0
@@ -1,6 +1,7 @@#include <linux/fs.h> #include <linux/slab.h> #include <linux/buffer_head.h> +#include <linux/mtd/super.h> #include "squashfs_fs_i.h" #include "squashfs.h"
@@ -13,6 +14,10 @@ int squashfs_find_backend(struct file_system_type *fs_type, int flags,if (!get_sb_bdev (fs_type, flags, dev_name, data, fill_bdev_super, mnt))return 0 ;#endif +#ifdef CONFIG_MTD +if (!get_sb_mtd (fs_type, flags, dev_name, data, fill_mtd_super, mnt)) +return 0 ; +#endif WARNING ("no suitable backend found\n" );return -EINVAL ; }
@@ -25,6 +30,12 @@ void squashfs_kill_super(struct super_block *sb) return; }#endif +#ifdef CONFIG_MTD +if (sb->s_mtd) { +kill_mtd_super (sb); +return ; + } +#endif ERROR ("squashfs_kill_super: no device behind the super block\n" ); }
@@ -43,6 +54,10 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,if (sb->s_bdev)return bdev_read_data (sb, buffer, index, length, next_index, srclength, pages);#endif +#ifdef CONFIG_MTD +if (sb->s_mtd) +return mtd_read_data (sb, buffer, index, length, next_index, srclength, pages); +#endif ERROR ("squashfs_read_data: no device behind the super block\n" );return -EIO ; }
fs/squashfs/mtd.c new file +179 -0
179 lines not on this page · raw message
fs/squashfs/squashfs.h +4 -0
@@ -105,6 +105,10 @@ extern const struct squashfs_decompressor squashfs_lzma_comp_ops;extern int fill_bdev_super (struct super_block *,void *,int );extern int bdev_read_data (struct super_block *,void **,u64 ,int ,u64 *,int ,int ); +/* mtd.c */ +extern int fill_mtd_super (struct super_block *,void *,int ); +extern int mtd_read_data (struct super_block *,void **,u64 ,int ,u64 *,int ,int ); + #ifndef CONFIG_BLOCK struct buffer_head { sector_t b_blocknr;
Signature · 1 line
1.6.5