@@ -14,3 +14,7 @@ ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o
ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o
ext4-$(CONFIG_EXT4_FS_ENCRYPTION) += crypto_policy.o crypto.o \
crypto_key.o crypto_fname.o
+
+ifdef CONFIG_FS_TRANSPARENT_COMPRESSION
+ccflags-y += -DFS_IMPL
+endif
@@ -32,6 +32,7 @@
#include <linux/ratelimit.h>
#include <crypto/hash.h>
#include <linux/falloc.h>
+#include <linux/fs-xcomp.h>
#ifdef __KERNEL__
#include <linux/compat.h>
#endif
@@ -957,6 +958,9 @@ struct ext4_inode_info {
/* Encryption params */
struct ext4_encryption_key i_encryption_key;
#endif
+#ifdef CONFIG_FS_TRANSPARENT_COMPRESSION
+ struct xcomp_inode_info i_xcomp_info;
+#endif
};
/*
@@ -46,6 +46,13 @@
#define MPAGE_DA_EXTENT_TAIL 0x01
+static int ext4_inode_is_compressed(struct inode *inode)
+{
+ if (!xcomp_enabled())
+ return 0;
+ return (EXT4_I(inode)->i_flags & EXT4_COMPR_FL);
+}
+
static __u32 ext4_inode_csum(struct inode *inode, struct ext4_inode *raw,
struct ext4_inode_info *ei)
{
@@ -250,6 +257,11 @@ void ext4_evict_inode(struct inode *inode)
if (IS_SYNC(inode))
ext4_handle_sync(handle);
+
+ if (ext4_inode_is_compressed(inode)) {
+ xcomp_inode_info_free(&EXT4_I(inode)->i_xcomp_info);
+ }
+
inode->i_size = 0;
err = ext4_mark_inode_dirty(handle, inode);
if (err) {
@@ -2912,7 +2924,7 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block)
return generic_block_bmap(mapping, block, ext4_get_block);
}
-static int ext4_readpage(struct file *file, struct page *page)
+static int __ext4_readpage(struct page *page)
{
int ret = -EAGAIN;
struct inode *inode = page->mapping->host;
@@ -2928,8 +2940,16 @@ static int ext4_readpage(struct file *file, struct page *page)
return ret;
}
+static int ext4_readpage(struct file *file, struct page *page)
+{
+ if (ext4_inode_is_compressed(page->mapping->host))
+ return xcomp_readpage(&EXT4_I(page->mapping->host)->i_xcomp_info, page);
+
+ return __ext4_readpage(page);
+}
+
static int
-ext4_readpages(struct file *file, struct address_space *mapping,
+__ext4_readpages(struct address_space *mapping,
struct list_head *pages, unsigned nr_pages)
{
struct inode *inode = mapping->host;
@@ -2941,6 +2961,16 @@ ext4_readpages(struct file *file, struct address_space *mapping,
return ext4_mpage_readpages(mapping, pages, NULL, nr_pages);
}
+static int
+ext4_readpages(struct file *file, struct address_space *mapping,
+ struct list_head *pages, unsigned nr_pages)
+{
+ if (ext4_inode_is_compressed(mapping->host))
+ return xcomp_readpages(&EXT4_I(mapping->host)->i_xcomp_info, mapping, pages, nr_pages);
+
+ return __ext4_readpages(mapping, pages, nr_pages);
+}
+
static void ext4_invalidatepage(struct page *page, unsigned int offset,
unsigned int length)
{
@@ -4117,6 +4147,9 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
ei->i_file_acl |=
((__u64)le16_to_cpu(raw_inode->i_file_acl_high)) << 32;
inode->i_size = ext4_isize(raw_inode);
+#ifdef CONFIG_FS_TRANSPARENT_COMPRESSION
+ inode->i_compressed_size = inode->i_size;
+#endif
ei->i_disksize = inode->i_size;
#ifdef CONFIG_QUOTA
ei->i_reserved_quota = 0;
@@ -4241,6 +4274,10 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
brelse(iloc.bh);
ext4_set_inode_flags(inode);
unlock_new_inode(inode);
+
+ if (S_ISREG(inode->i_mode) && ext4_inode_is_compressed(inode))
+ xcomp_inode_info_init(inode, &ei->i_xcomp_info, __ext4_readpage);
+
return inode;
bad_inode:
Signed-off-by: Tom Marshall <tdm@cyngn.com> --- fs/ext4/Makefile | 4 ++++ fs/ext4/ext4.h | 4 ++++ fs/ext4/inode.c | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-)