ext4: xattr-in-inode support
Subsystems (4)
PATCH 1/32 ext4: xattr-in-inode support
From: Andreas Dilger <[email protected]>
Large xattr support is implemented for EXT4_FEATURE_INCOMPAT_EA_INODE.
If the size of an xattr value is larger than will fit in a single external block, then the xattr value will be saved into the body of an external xattr inode.
The also helps support a larger number of xattr, since only the headers will be stored in the in-inode space or the single external block.
The inode is referenced from the xattr header via "e_value_inum", which was formerly "e_value_block", but that field was never used. The e_value_size still contains the xattr size so that listing xattrs does not need to look up the inode if the data is not accessed.
struct ext4_xattr_entry {
__u8 e_name_len; /* length of name */
__u8 e_name_index; /* attribute name index */
__le16 e_value_offs; /* offset in disk block of value */
__le32 e_value_inum; /* inode in which value is stored */
__le32 e_value_size; /* size of attribute value */
__le32 e_hash; /* hash value of name and value */
char e_name[0]; /* attribute name */};
The xattr inode is marked with the EXT4_EA_INODE_FL flag and also holds a back-reference to the owning inode in its i_mtime field, allowing the ext4/e2fsck to verify the correct inode is accessed.
Lustre-Jira: https://jira.hpdd.intel.com/browse/LU-80
Lustre-bugzilla: https://bugzilla.lustre.org/show_bug.cgi?id=4424
--- fs/ext4/ext4.h | 12 ++ fs/ext4/ialloc.c | 1 - fs/ext4/inline.c | 2 +- fs/ext4/inode.c | 49 ++++- fs/ext4/xattr.c | 565 ++++++++++++++++++++++++++++++++++++++++++++++++++----- fs/ext4/xattr.h | 33 +++- 6 files changed, 606 insertions(+), 56 deletions(-)
fs/ext4/ext4.h +12 -0
@@ -1797,6 +1797,7 @@ EXT4_FEATURE_INCOMPAT_FUNCS(encrypt, ENCRYPT)EXT4_FEATURE_INCOMPAT_EXTENTS | \EXT4_FEATURE_INCOMPAT_64BIT | \EXT4_FEATURE_INCOMPAT_FLEX_BG | \ +EXT4_FEATURE_INCOMPAT_EA_INODE | \EXT4_FEATURE_INCOMPAT_MMP | \EXT4_FEATURE_INCOMPAT_INLINE_DATA | \ EXT4_FEATURE_INCOMPAT_ENCRYPT | \
@@ -2219,6 +2220,12 @@ struct mmpd_data {*/ #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL +/* +* Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb +* This limit is arbitrary, but is reasonable for the xattr API. +*/ +#define EXT4_XATTR_MAX_LARGE_EA_SIZE (1024 * 1024) +/* * Function prototypes */
@@ -2231,6 +2238,10 @@ struct mmpd_data {# define ATTRIB_NORET __attribute__((noreturn))# define NORET_AND noreturn, +struct ext4_xattr_ino_array { +unsigned int xia_count;/* # of used item in the array */ +unsigned int xia_inodes[0 ]; +};/* bitmap.c */ extern unsigned int ext4_count_free (char *bitmap,unsigned numchars); void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
@@ -2478,6 +2489,7 @@ extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);extern void ext4_set_inode_flags (struct inode *);extern int ext4_alloc_da_blocks (struct inode *inode);extern void ext4_set_aops (struct inode *inode); +extern int ext4_meta_trans_blocks (struct inode *,int nrblocks,int chunk);extern int ext4_writepage_trans_blocks (struct inode *);extern int ext4_chunk_trans_blocks (struct inode *,int nrblocks); extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
fs/ext4/ialloc.c +0 -1
@@ -294,7 +294,6 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)* as writing the quota to disk may need the lock as well. */ dquot_initialize (inode); -ext4_xattr_delete_inode (handle, inode);dquot_free_inode (inode);dquot_drop (inode);
fs/ext4/inline.c +1 -1
@@ -61,7 +61,7 @@ static int get_max_inline_xattr_value_size(struct inode *inode,/* Compute min_offs. */ for (; !IS_LAST_ENTRY (entry); entry =EXT4_XATTR_NEXT (entry)) { -if (!entry->e_value_block && entry->e_value_size) { +if (!entry->e_value_inum && entry->e_value_size) {size_t offs =le16_to_cpu (entry->e_value_offs);if (offs < min_offs) min_offs = offs;
fs/ext4/inode.c +40 -9
96 lines not on this page · raw message
fs/ext4/xattr.c +523 -42
794 lines not on this page · raw message
fs/ext4/xattr.h +30 -3
@@ -44,7 +44,7 @@ struct ext4_xattr_entry {__u8 e_name_len;/* length of name */ __u8 e_name_index;/* attribute name index */ __le16 e_value_offs;/* offset in disk block of value */ -__le32 e_value_block;/* disk block attribute is stored on (n/i) */ +__le32 e_value_inum;/* inode in which the value is stored */ __le32 e_value_size;/* size of attribute value */ __le32 e_hash;/* hash value of name and value */ char e_name[0 ];/* attribute name */
@@ -69,6 +69,26 @@ struct ext4_xattr_entry { EXT4_I(inode)->i_extra_isize))#define IFIRST (hdr) ((struct ext4_xattr_entry *)((hdr)+1)) +/* +* Link EA inode back to parent one using i_mtime field. +* Extra integer type conversion added to ignore higher +* bits in i_mtime.tv_sec which might be set by ext4_get() +*/ +#define EXT4_XATTR_INODE_SET_PARENT (inode, inum) \ +do { \ + (inode)->i_mtime.tv_sec = inum; \ +} while(0) + +#define EXT4_XATTR_INODE_GET_PARENT (inode) \ +((__u32)(inode)->i_mtime.tv_sec) + +/* +* The minimum size of EA value when you start storing it in an external inode +* size of block - size of header - size of 1 entry - 4 null bytes +*/ +#define EXT4_XATTR_MIN_LARGE_EA_SIZE (b) \ + ((b) - EXT4_XATTR_LEN(3) - sizeof(struct ext4_xattr_header) - 4) +#define BHDR (bh) ((struct ext4_xattr_header *)((bh)->b_data))#define ENTRY (ptr) ((struct ext4_xattr_entry *)(ptr))#define BFIRST (bh) ENTRY(BHDR(bh)+1)
@@ -77,10 +97,11 @@ struct ext4_xattr_entry {#define EXT4_ZERO_XATTR_VALUE ((void *)-1)struct ext4_xattr_info { -int name_index;const char *name;const void *value;size_t value_len; +int name_index; +int in_inode; };struct ext4_xattr_search {
@@ -140,7 +161,13 @@ extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t);extern int ext4_xattr_set (struct inode *,int ,const char *,const void *,size_t ,int );extern int ext4_xattr_set_handle (handle_t *,struct inode *,int ,const char *,const void *,size_t ,int ); -extern void ext4_xattr_delete_inode (handle_t *,struct inode *); +extern struct inode *ext4_xattr_inode_iget (struct inode *parent,unsigned long ea_ino, +int *err); +extern int ext4_xattr_inode_unlink (struct inode *inode,unsigned long ea_ino); +extern int ext4_xattr_delete_inode (handle_t *handle,struct inode *inode, +struct ext4_xattr_ino_array **array); +extern void ext4_xattr_inode_array_free (struct inode *inode, +struct ext4_xattr_ino_array *array);extern int ext4_expand_extra_isize_ea (struct inode *inode,int new_extra_isize,struct ext4_inode *raw_inode,handle_t *handle);
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 2/32 ext4: fix lockdep warning about recursive inode locking
Setting a large xattr value may require writing the attribute contents to an external inode. In this case we may need to lock the xattr inode along with the parent inode. This doesn't pose a deadlock risk because xattr inodes are not directly visible to the user and their access is restricted.
Assign a lockdep subclass to xattr inode's lock.
============================================
WARNING: possible recursive locking detected
4.12.0-rc1+ #740 Not tainted
--------------------------------------------
python/1822 is trying to acquire lock:
(&sb->s_type->i_mutex_key#15){+.+...}, at: [<ffffffff804912ca>] ext4_xattr_set_entry+0x65a/0x7b0
but task is already holding lock:
(&sb->s_type->i_mutex_key#15){+.+...}, at: [<ffffffff803d6687>] vfs_setxattr+0x57/0xb0
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
---- lock(&sb->s_type->i_mutex_key#15);
lock(&sb->s_type->i_mutex_key#15);
*** DEADLOCK ***
May be due to missing lock nesting notation
4 locks held by python/1822:
#0: (sb_writers#10){.+.+.+}, at: [<ffffffff803d0eef>] mnt_want_write+0x1f/0x50
#1: (&sb->s_type->i_mutex_key#15){+.+...}, at: [<ffffffff803d6687>] vfs_setxattr+0x57/0xb0
#2: (jbd2_handle){.+.+..}, at: [<ffffffff80493f40>] start_this_handle+0xf0/0x420
#3: (&ei->xattr_sem){++++..}, at: [<ffffffff804920ba>] ext4_xattr_set_handle+0x9a/0x4f0stack backtrace: CPU: 0 PID: 1822 Comm: python Not tainted 4.12.0-rc1+ #740 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Call Trace: dump_stack+0x67/0x9e __lock_acquire+0x5f3/0x1750 lock_acquire+0xb5/0x1d0 down_write+0x2c/0x60 ext4_xattr_set_entry+0x65a/0x7b0 ext4_xattr_block_set+0x1b2/0x9b0 ext4_xattr_set_handle+0x322/0x4f0 ext4_xattr_set+0x144/0x1a0 ext4_xattr_user_set+0x34/0x40 __vfs_setxattr+0x66/0x80 __vfs_setxattr_noperm+0x69/0x1c0 vfs_setxattr+0xa2/0xb0 setxattr+0x12e/0x150 path_setxattr+0x87/0xb0 SyS_setxattr+0xf/0x20 entry_SYSCALL_64_fastpath+0x18/0xad
--- fs/ext4/inode.c | 2 ++ fs/ext4/xattr.c | 8 ++++++++ fs/ext4/xattr.h | 6 ++++++ 3 files changed, 16 insertions(+)
fs/ext4/inode.c +2 -0
@@ -4877,6 +4877,8 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) }brelse (iloc.bh);ext4_set_inode_flags (inode); +if (ei->i_flags &EXT4_EA_INODE_FL ) +ext4_xattr_inode_set_class (inode);unlock_new_inode (inode);return inode;
fs/ext4/xattr.c +8 -0
@@ -107,6 +107,13 @@ const struct xattr_handler *ext4_xattr_handlers[] = {#define EXT4_GET_MB_CACHE (inode) (((struct ext4_sb_info *) \ inode->i_sb->s_fs_info)->s_mb_cache) +#ifdef CONFIG_LOCKDEP +void ext4_xattr_inode_set_class (struct inode *ea_inode) +{ +lockdep_set_subclass (&ea_inode->i_rwsem,1 ); +} +#endif +static __le32 ext4_xattr_block_csum (struct inode *inode,sector_t block_nr,struct ext4_xattr_header *hdr)
@@ -830,6 +837,7 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle, ea_inode->i_op = &ext4_file_inode_operations; ea_inode->i_fop = &ext4_file_operations;ext4_set_aops (ea_inode); +ext4_xattr_inode_set_class (ea_inode); ea_inode->i_generation = inode->i_generation;EXT4_I (ea_inode)->i_flags |=EXT4_EA_INODE_FL ;
fs/ext4/xattr.h +6 -0
@@ -196,3 +196,9 @@ static inline int ext4_init_security(handle_t *handle, struct inode *inode, return 0; }#endif + +#ifdef CONFIG_LOCKDEP +extern void ext4_xattr_inode_set_class (struct inode *ea_inode); +#else +static inline void ext4_xattr_inode_set_class (struct inode *ea_inode) { } +#endif
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 3/32 ext4: lock inode before calling ext4_orphan_add()
In reply to Tahsin Erdoganext4_orphan_add() requires caller to be holding the inode lock. Add missing lock statements.
WARNING: CPU: 3 PID: 1806 at fs/ext4/namei.c:2731 ext4_orphan_add+0x4e/0x240 CPU: 3 PID: 1806 Comm: python Not tainted 4.12.0-rc1+ #746 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 task: ffff880135d466c0 task.stack: ffffc900014b0000 RIP: 0010:ext4_orphan_add+0x4e/0x240 RSP: 0018:ffffc900014b3d50 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff8801348fe1f0 RCX: ffffc900014b3c64 RDX: 0000000000000000 RSI: ffff8801348fe1f0 RDI: ffff8801348fe1f0 RBP: ffffc900014b3da0 R08: 0000000000000000 R09: ffffffff80e82025 R10: 0000000000004692 R11: 000000000000468d R12: ffff880137598000 R13: ffff880137217000 R14: ffff880134ac58d0 R15: 0000000000000000 FS: 00007fc50f09e740(0000) GS:ffff88013fd80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000008bc2e0 CR3: 00000001375ac000 CR4: 00000000000006e0 Call Trace: ext4_xattr_inode_orphan_add.constprop.19+0x9d/0xf0 ext4_xattr_delete_inode+0x1c4/0x2f0 ext4_evict_inode+0x15a/0x7f0 evict+0xc0/0x1a0 iput+0x16a/0x270 do_unlinkat+0x172/0x290 SyS_unlink+0x11/0x20 entry_SYSCALL_64_fastpath+0x18/0xad
--- fs/ext4/xattr.c | 2 ++ 1 file changed, 2 insertions(+)
fs/ext4/xattr.c +2 -0
@@ -1963,7 +1963,9 @@ ext4_xattr_inode_orphan_add(handle_t *handle, struct inode *inode, lea_ino_array->xia_inodes[idx], &error);if (error)continue ; +inode_lock (ea_inode);ext4_orphan_add (handle, ea_inode); +inode_unlock (ea_inode);/* the inode's i_count will be released by caller */ }
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 4/32 ext4: do not set posix acls on xattr inodes
In reply to Tahsin ErdoganWe don't need acls on xattr inodes because they are not directly accessible from user mode.
Besides lockdep complains about recursive locking of xattr_sem as seen below.
=============================================
[ INFO: possible recursive locking detected ]
4.11.0-rc8+ #402 Not tainted
---------------------------------------------
python/1894 is trying to acquire lock:
(&ei->xattr_sem){++++..}, at: [<ffffffff804878a6>] ext4_xattr_get+0x66/0x270
but task is already holding lock:
(&ei->xattr_sem){++++..}, at: [<ffffffff80489500>] ext4_xattr_set_handle+0xa0/0x5d0
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock(&ei->xattr_sem);
lock(&ei->xattr_sem);*** DEADLOCK ***
May be due to missing lock nesting notation
3 locks held by python/1894:
#0: (sb_writers#10){.+.+.+}, at: [<ffffffff803d829f>] mnt_want_write+0x1f/0x50
#1: (&sb->s_type->i_mutex_key#15){+.+...}, at: [<ffffffff803dda27>] vfs_setxattr+0x57/0xb0
#2: (&ei->xattr_sem){++++..}, at: [<ffffffff80489500>] ext4_xattr_set_handle+0xa0/0x5d0stack backtrace: CPU: 0 PID: 1894 Comm: python Not tainted 4.11.0-rc8+ #402 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Call Trace: dump_stack+0x67/0x99 __lock_acquire+0x5f3/0x1830 lock_acquire+0xb5/0x1d0 down_read+0x2f/0x60 ext4_xattr_get+0x66/0x270 ext4_get_acl+0x43/0x1e0 get_acl+0x72/0xf0 posix_acl_create+0x5e/0x170 ext4_init_acl+0x21/0xc0 __ext4_new_inode+0xffd/0x16b0 ext4_xattr_set_entry+0x5ea/0xb70 ext4_xattr_block_set+0x1b5/0x970 ext4_xattr_set_handle+0x351/0x5d0 ext4_xattr_set+0x124/0x180 ext4_xattr_user_set+0x34/0x40 __vfs_setxattr+0x66/0x80 __vfs_setxattr_noperm+0x69/0x1c0 vfs_setxattr+0xa2/0xb0 setxattr+0x129/0x160 path_setxattr+0x87/0xb0 SyS_setxattr+0xf/0x20 entry_SYSCALL_64_fastpath+0x18/0xad
--- fs/ext4/ext4.h | 11 ++++++----- fs/ext4/ialloc.c | 14 +++++++++----- fs/ext4/migrate.c | 2 +- fs/ext4/xattr.c | 3 ++- 4 files changed, 18 insertions(+), 12 deletions(-)
fs/ext4/ext4.h +6 -5
@@ -2400,16 +2400,17 @@ extern int ext4fs_dirhash(const char *name, int len, struct/* ialloc.c */ extern struct inode *__ext4_new_inode (handle_t *,struct inode *,umode_t ,const struct qstr *qstr,__u32 goal, -uid_t *owner,int handle_type, -unsigned int line_no,int nblocks); +uid_t *owner,__u32 i_flags, +int handle_type,unsigned int line_no, +int nblocks); -#define ext4_new_inode (handle, dir, mode, qstr, goal, owner) \ +#define ext4_new_inode (handle, dir, mode, qstr, goal, owner, i_flags) \ __ext4_new_inode((handle), (dir), (mode), (qstr), (goal), (owner), \ - 0, 0, 0) + i_flags, 0, 0, 0)#define ext4_new_inode_start_handle (dir, mode, qstr, goal, owner, \ type, nblocks) \ __ext4_new_inode(NULL, (dir), (mode), (qstr), (goal), (owner), \ - (type), __LINE__, (nblocks)) + 0, (type), __LINE__, (nblocks))extern void ext4_free_inode (handle_t *,struct inode *);
fs/ext4/ialloc.c +9 -5
@@ -742,8 +742,9 @@ static int recently_deleted(struct super_block *sb, ext4_group_t group, int ino)*/ struct inode *__ext4_new_inode (handle_t *handle,struct inode *dir,umode_t mode,const struct qstr *qstr, -__u32 goal,uid_t *owner,int handle_type, -unsigned int line_no,int nblocks) +__u32 goal,uid_t *owner,__u32 i_flags, +int handle_type,unsigned int line_no, +int nblocks) {struct super_block *sb;struct buffer_head *inode_bitmap_bh =NULL ;
@@ -1052,6 +1053,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,/* Don't inherit extent flag from directory, amongst others. */ ei->i_flags =ext4_mask_flags (mode,EXT4_I (dir)->i_flags &EXT4_FL_INHERITED ); + ei->i_flags |= i_flags; ei->i_file_acl =0 ; ei->i_dtime =0 ; ei->i_block_group = group;
@@ -1108,9 +1110,11 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir, goto fail_free_drop; } - err =ext4_init_acl (handle, inode, dir); -if (err) - goto fail_free_drop; +if (!(ei->i_flags &EXT4_EA_INODE_FL )) { + err =ext4_init_acl (handle, inode, dir); +if (err) + goto fail_free_drop; + } err =ext4_init_security (handle, inode, dir, qstr);if (err)
fs/ext4/migrate.c +1 -1
@@ -475,7 +475,7 @@ int ext4_ext_migrate(struct inode *inode) owner[0 ] =i_uid_read (inode); owner[1 ] =i_gid_read (inode); tmp_inode =ext4_new_inode (handle,d_inode (inode->i_sb->s_root), -S_IFREG ,NULL , goal, owner); +S_IFREG ,NULL , goal, owner,0 );if (IS_ERR (tmp_inode)) { retval =PTR_ERR (tmp_inode);ext4_journal_stop (handle);
fs/ext4/xattr.c +2 -1
@@ -832,7 +832,8 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle,* in the same group, or nearby one. */ ea_inode =ext4_new_inode (handle, inode->i_sb->s_root->d_inode, -S_IFREG |0600 ,NULL , inode->i_ino +1 ,NULL ); +S_IFREG |0600 ,NULL , inode->i_ino +1 ,NULL , +EXT4_EA_INODE_FL );if (!IS_ERR (ea_inode)) { ea_inode->i_op = &ext4_file_inode_operations; ea_inode->i_fop = &ext4_file_operations;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 5/32 ext4: attach jinode after creation of xattr inode
In reply to Tahsin ErdoganIn data=ordered mode jinode needs to be attached to the xattr inode when writing data to it. Attachment normally occurs during file open for regular files. Since we are not using file interface to write to the xattr inode, the jinode attach needs to be done manually.
Otherwise the following crash occurs in data=ordered mode.
BUG: unable to handle kernel NULL pointer dereference at (null) IP: jbd2_journal_file_inode+0x37/0x110 PGD 13b3c0067 P4D 13b3c0067 PUD 137660067 PMD 0 Oops: 0000 [#1] SMP CPU: 3 PID: 1877 Comm: python Not tainted 4.12.0-rc1+ #749 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 task: ffff88010e368980 task.stack: ffffc90000374000 RIP: 0010:jbd2_journal_file_inode+0x37/0x110 RSP: 0018:ffffc90000377980 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff880123b06230 RCX: 0000000000280000 RDX: 0000000000000006 RSI: 0000000000000000 RDI: ffff88012c8585d0 RBP: ffffc900003779b0 R08: 0000000000000202 R09: 0000000000000001 R10: 0000000000000000 R11: 0000000000000400 R12: ffff8801111f81c0 R13: ffff88013b2b6800 R14: ffffc90000377ab0 R15: 0000000000000001 FS: 00007f0c99b77740(0000) GS:ffff88013fd80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000000136d91000 CR4: 00000000000006e0 Call Trace: jbd2_journal_inode_add_write+0xe/0x10 ext4_map_blocks+0x59e/0x620 ext4_xattr_set_entry+0x501/0x7d0 ext4_xattr_block_set+0x1b2/0x9b0 ext4_xattr_set_handle+0x322/0x4f0 ext4_xattr_set+0x144/0x1a0 ext4_xattr_user_set+0x34/0x40 __vfs_setxattr+0x66/0x80 __vfs_setxattr_noperm+0x69/0x1c0 vfs_setxattr+0xa2/0xb0 setxattr+0x12e/0x150 path_setxattr+0x87/0xb0 SyS_setxattr+0xf/0x20 entry_SYSCALL_64_fastpath+0x18/0xad
--- fs/ext4/xattr.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/ext4/xattr.c +6 -0
@@ -826,6 +826,7 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle, struct inode *inode) {struct inode *ea_inode =NULL ; +int err;/* * Let the next inode be the goal, so we try and allocate the EA inode
@@ -848,6 +849,11 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle,*/ EXT4_XATTR_INODE_SET_PARENT (ea_inode, inode->i_ino);unlock_new_inode (ea_inode); + err =ext4_inode_attach_jinode (ea_inode); +if (err) { +iput (ea_inode); +return ERR_PTR (err); + } }return ea_inode;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 6/32 ext4: ea_inode owner should be the same as the inode owner
In reply to Tahsin ErdoganQuota charging is based on the ownership of the inode. Currently, the xattr inode owner is set to the caller which may be different from the parent inode owner. This is inconsistent with how quota is charged for xattr block and regular data block writes.
--- fs/ext4/xattr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/xattr.c +2 -1
@@ -826,6 +826,7 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle, struct inode *inode) {struct inode *ea_inode =NULL ; +uid_t owner[2 ] = {i_uid_read (inode),i_gid_read (inode) };int err;/*
@@ -833,7 +834,7 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle,* in the same group, or nearby one. */ ea_inode =ext4_new_inode (handle, inode->i_sb->s_root->d_inode, -S_IFREG |0600 ,NULL , inode->i_ino +1 ,NULL , +S_IFREG |0600 ,NULL , inode->i_ino +1 , owner,EXT4_EA_INODE_FL );if (!IS_ERR (ea_inode)) { ea_inode->i_op = &ext4_file_inode_operations;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 11/32 ext4: clean up ext4_xattr_inode_get()
In reply to Tahsin ErdoganThe input and output values of *size parameter are equal on successful return from ext4_xattr_inode_get(). On error return, the callers ignore the output value so there is no need to update it.
Also check for NULL return from ext4_bread(). If the actual xattr inode size happens to be smaller than the expected size, ext4_bread() may return NULL which would indicate data corruption.
--- fs/ext4/xattr.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-)
fs/ext4/xattr.c +13 -22
@@ -278,37 +278,28 @@ ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,/* * Read the EA value from an inode. */ -static int -ext4_xattr_inode_read (struct inode *ea_inode,void *buf,size_t *size) +static int ext4_xattr_inode_read (struct inode *ea_inode,void *buf,size_t size) {unsigned long block =0 ;struct buffer_head *bh =NULL ; -int blocksize; -size_t csize, ret_size =0 ; - -if (*size ==0 ) -return 0 ; +int blocksize = ea_inode->i_sb->s_blocksize; +size_t csize, copied =0 ; - blocksize = ea_inode->i_sb->s_blocksize; - -while (ret_size < *size) { - csize = (*size - ret_size) > blocksize ? blocksize : - *size - ret_size; +while (copied < size) { + csize = (size - copied) > blocksize ? blocksize : size - copied; bh =ext4_bread (NULL , ea_inode, block,0 ); -if (IS_ERR (bh)) { - *size = ret_size; +if (IS_ERR (bh))return PTR_ERR (bh); - } +if (!bh) +return -EFSCORRUPTED ; +memcpy (buf, bh->b_data, csize);brelse (bh); buf += csize; block +=1 ; - ret_size += csize; + copied += csize; } - - *size = ret_size; -return 0 ; }
@@ -360,7 +351,7 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,*/ static int ext4_xattr_inode_get (struct inode *inode,unsigned long ea_ino,void *buffer, -size_t *size) +size_t size) {struct inode *ea_inode;int ret;
@@ -417,7 +408,7 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,if (entry->e_value_inum) { error =ext4_xattr_inode_get (inode,le32_to_cpu (entry->e_value_inum), - buffer, &size); + buffer, size);if (error) goto cleanup; }else {
@@ -467,7 +458,7 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,if (entry->e_value_inum) { error =ext4_xattr_inode_get (inode,le32_to_cpu (entry->e_value_inum), - buffer, &size); + buffer, size);if (error) goto cleanup; }else {
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 13/32 ext4: ext4_xattr_value_same() should return false for external data
In reply to Tahsin Erdoganext4_xattr_value_same() is used as a quick optimization in case the new xattr value is identical to the previous value. When xattr value is stored in a xattr inode the check becomes expensive so it is better to just assume that they are not equal.
--- fs/ext4/xattr.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext4/xattr.c +3 -0
@@ -1428,6 +1428,9 @@ static int ext4_xattr_value_same(struct ext4_xattr_search *s, {void *value; +/* When e_value_inum is set the value is stored externally. */ +if (s->here->e_value_inum) +return 0 ;if (le32_to_cpu (s->here->e_value_size) != i->value_len)return 0 ; value = ((void *)s->base) +le16_to_cpu (s->here->e_value_offs);
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 14/32 ext4: fix ext4_xattr_make_inode_space() value size calculation
In reply to Tahsin Erdoganext4_xattr_make_inode_space() is interested in calculating the inline space used in an inode. When a xattr entry refers to an external inode the value size indicates the external inode size, not the value size in the inline area. Change the function to take this into account.
--- fs/ext4/xattr.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
fs/ext4/xattr.c +8 -5
@@ -1747,9 +1747,10 @@ static int ext4_xattr_make_inode_space(handle_t *handle, struct inode *inode, last =IFIRST (header);/* Find the entry best suited to be pushed into EA block */ for (; !IS_LAST_ENTRY (last); last =EXT4_XATTR_NEXT (last)) { - total_size = -EXT4_XATTR_SIZE (le32_to_cpu (last->e_value_size)) + -EXT4_XATTR_LEN (last->e_name_len); + total_size =EXT4_XATTR_LEN (last->e_name_len); +if (!last->e_value_inum) + total_size +=EXT4_XATTR_SIZE ( +le32_to_cpu (last->e_value_size));if (total_size <= bfree && total_size < min_total_size) {if (total_size + ifree < isize_diff) {
@@ -1768,8 +1769,10 @@ static int ext4_xattr_make_inode_space(handle_t *handle, struct inode *inode, } entry_size =EXT4_XATTR_LEN (entry->e_name_len); - total_size = entry_size + -EXT4_XATTR_SIZE (le32_to_cpu (entry->e_value_size)); + total_size = entry_size; +if (!entry->e_value_inum) + total_size +=EXT4_XATTR_SIZE ( +le32_to_cpu (entry->e_value_size)); error =ext4_xattr_move_to_block (handle, inode, raw_inode, entry);if (error)
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 17/32 ext4: fix credits calculation for xattr inode
In reply to Tahsin ErdoganWhen there is no space for a value in xattr block, it may be stored in an xattr inode even if the value length is less than EXT4_XATTR_MIN_LARGE_EA_SIZE(). So the current assumption in credits calculation is wrong.
--- fs/ext4/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/xattr.c +1 -2
@@ -1590,8 +1590,7 @@ ext4_xattr_set(struct inode *inode, int name_index, const char *name,if (error)return error; -if ((value_len >=EXT4_XATTR_MIN_LARGE_EA_SIZE (sb->s_blocksize)) && -ext4_has_feature_ea_inode (sb)) { +if (ext4_has_feature_ea_inode (sb)) {int nrblocks = (value_len + sb->s_blocksize -1 ) >> sb->s_blocksize_bits;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 18/32 ext4: retry storing value in external inode with xattr block too
In reply to Tahsin ErdoganWhen value size is <= EXT4_XATTR_MIN_LARGE_EA_SIZE(), and it doesn't fit in either inline or xattr block, a second try is made to store it in an external inode while storing the entry itself in inline area. There should also be an attempt to store the entry in xattr block.
This patch adds a retry loop to do that. It also makes the caller the sole decider on whether to store a value in an external inode.
---
v2: fix checkpatch.pl warning about indented retry_inode: label
fs/ext4/xattr.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
fs/ext4/xattr.c +18 -17
@@ -911,11 +911,6 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,int in_inode = i->in_inode;int rc; -if (ext4_has_feature_ea_inode (inode->i_sb) && - (EXT4_XATTR_SIZE (i->value_len) > -EXT4_XATTR_MIN_LARGE_EA_SIZE (inode->i_sb->s_blocksize))) - in_inode =1 ; -/* Compute min_offs and last. */ last = s->first;for (; !IS_LAST_ENTRY (last); last =EXT4_XATTR_NEXT (last)) {
@@ -1097,7 +1092,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, {struct super_block *sb = inode->i_sb;struct buffer_head *new_bh =NULL ; -struct ext4_xattr_search *s = &bs->s; +struct ext4_xattr_search s_copy = bs->s; +struct ext4_xattr_search *s = &s_copy;struct mb_cache_entry *ce =NULL ;int error =0 ;struct mb_cache *ext4_mb_cache =EXT4_GET_MB_CACHE (inode);
@@ -1519,6 +1515,11 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,if (!bs.s.not_found &&ext4_xattr_value_same (&bs.s, &i)) goto cleanup; +if (ext4_has_feature_ea_inode (inode->i_sb) && + (EXT4_XATTR_SIZE (i.value_len) > +EXT4_XATTR_MIN_LARGE_EA_SIZE (inode->i_sb->s_blocksize))) + i.in_inode =1 ; +retry_inode: error =ext4_xattr_ibody_set (handle, inode, &i, &is);if (!error && !bs.s.not_found) { i.value =NULL ;
@@ -1530,20 +1531,20 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, goto cleanup; } error =ext4_xattr_block_set (handle, inode, &i, &bs); -if (ext4_has_feature_ea_inode (inode->i_sb) && - error == -ENOSPC ) { -/* xattr not fit to block, store at external -* inode */ - i.in_inode =1 ; - error =ext4_xattr_ibody_set (handle, inode, - &i, &is); - } -if (error) - goto cleanup; -if (!is.s.not_found) { +if (!error && !is.s.not_found) { i.value =NULL ; error =ext4_xattr_ibody_set (handle, inode, &i, &is); + }else if (error == -ENOSPC ) { +/* +* Xattr does not fit in the block, store at +* external inode if possible. +*/ +if (ext4_has_feature_ea_inode (inode->i_sb) && + !i.in_inode) { + i.in_inode =1 ; + goto retry_inode; + } } } }
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 19/32 ext4: ext4_xattr_delete_inode() should return accurate errors
In reply to Tahsin ErdoganIn a few places the function returns without trying to pass the actual error code to the caller. Fix those.
--- fs/ext4/xattr.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fs/ext4/xattr.c +10 -6
@@ -2026,7 +2026,8 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,if (!entry->e_value_inum)continue ; ea_ino =le32_to_cpu (entry->e_value_inum); -if (ext4_expand_ino_array (lea_ino_array, ea_ino) !=0 ) { + error =ext4_expand_ino_array (lea_ino_array, ea_ino); +if (error) {brelse (iloc.bh); goto cleanup; }
@@ -2037,20 +2038,22 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode, delete_external_ea:if (!EXT4_I (inode)->i_file_acl) {/* add xattr inode to orphan list */ -ext4_xattr_inode_orphan_add (handle, inode, credits, - *lea_ino_array); + error =ext4_xattr_inode_orphan_add (handle, inode, credits, + *lea_ino_array); goto cleanup; } bh =sb_bread (inode->i_sb,EXT4_I (inode)->i_file_acl);if (!bh) {EXT4_ERROR_INODE (inode,"block %llu read error" ,EXT4_I (inode)->i_file_acl); + error = -EIO ; goto cleanup; }if (BHDR (bh)->h_magic !=cpu_to_le32 (EXT4_XATTR_MAGIC ) ||BHDR (bh)->h_blocks !=cpu_to_le32 (1 )) {EXT4_ERROR_INODE (inode,"bad block %llu" ,EXT4_I (inode)->i_file_acl); + error = -EFSCORRUPTED ; goto cleanup; }
@@ -2059,7 +2062,8 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,if (!entry->e_value_inum)continue ; ea_ino =le32_to_cpu (entry->e_value_inum); -if (ext4_expand_ino_array (lea_ino_array, ea_ino) !=0 ) + error =ext4_expand_ino_array (lea_ino_array, ea_ino); +if (error) goto cleanup; entry->e_value_inum =0 ; }
@@ -2067,7 +2071,7 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,/* add xattr inode to orphan list */ error =ext4_xattr_inode_orphan_add (handle, inode, credits, *lea_ino_array); -if (error !=0 ) +if (error) goto cleanup;if (!IS_NOQUOTA (inode))
@@ -2077,7 +2081,7 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode, error =ext4_journal_extend (handle, credits);if (error >0 ) error =ext4_journal_restart (handle, credits); -if (error !=0 ) { +if (error) {ext4_warning (inode->i_sb,"couldn't extend journal (err %d)" , error); goto cleanup;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 21/32 ext4: modify ext4_xattr_ino_array to hold struct inode *
In reply to Tahsin ErdoganTracking struct inode * rather than the inode number eliminates the repeated ext4_xattr_inode_iget() call later. The second call cannot fail in practice but still requires explanation when it wants to ignore the return value. Avoid the trouble and make things simple.
--- fs/ext4/ext4.h | 6 ++-- fs/ext4/inode.c | 8 ++--- fs/ext4/xattr.c | 93 ++++++++++++++++++++++++++++----------------------------- fs/ext4/xattr.h | 5 ++-- 4 files changed, 53 insertions(+), 59 deletions(-)
fs/ext4/ext4.h +3 -3
@@ -2232,9 +2232,9 @@ struct mmpd_data {# define ATTRIB_NORET __attribute__((noreturn))# define NORET_AND noreturn, -struct ext4_xattr_ino_array { -unsigned int xia_count;/* # of used item in the array */ -unsigned int xia_inodes[0 ]; +struct ext4_xattr_inode_array { +unsigned int count;/* # of used items in the array */ +struct inode *inodes[0 ]; };/* bitmap.c */ extern unsigned int ext4_count_free (char *bitmap,unsigned numchars);
fs/ext4/inode.c +3 -5
@@ -188,7 +188,7 @@ void ext4_evict_inode(struct inode *inode)handle_t *handle;int err;int extra_credits =3 ; -struct ext4_xattr_ino_array *lea_ino_array =NULL ; +struct ext4_xattr_inode_array *ea_inode_array =NULL ;trace_ext4_evict_inode (inode);
@@ -257,7 +257,7 @@ void ext4_evict_inode(struct inode *inode)/* * Delete xattr inode before deleting the main inode. */ - err =ext4_xattr_delete_inode (handle, inode, &lea_ino_array); + err =ext4_xattr_delete_inode (handle, inode, &ea_inode_array);if (err) {ext4_warning (inode->i_sb,"couldn't delete inode's xattr (err %d)" , err);
@@ -345,9 +345,7 @@ void ext4_evict_inode(struct inode *inode)ext4_journal_stop (handle);sb_end_intwrite (inode->i_sb); - -if (lea_ino_array !=NULL ) -ext4_xattr_inode_array_free (inode, lea_ino_array); +ext4_xattr_inode_array_free (ea_inode_array);return ; no_delete:ext4_clear_inode (inode);/* We must guarantee clearing of inode... */
fs/ext4/xattr.c +45 -48
185 lines not on this page · raw message
fs/ext4/xattr.h +2 -3
@@ -164,9 +164,8 @@ extern int ext4_xattr_set_credits(struct inode *inode, size_t value_len);extern int ext4_xattr_inode_unlink (struct inode *inode,unsigned long ea_ino);extern int ext4_xattr_delete_inode (handle_t *handle,struct inode *inode, -struct ext4_xattr_ino_array **array); -extern void ext4_xattr_inode_array_free (struct inode *inode, -struct ext4_xattr_ino_array *array); +struct ext4_xattr_inode_array **array); +extern void ext4_xattr_inode_array_free (struct ext4_xattr_inode_array *array);extern int ext4_expand_extra_isize_ea (struct inode *inode,int new_extra_isize,struct ext4_inode *raw_inode,handle_t *handle);
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 22/32 ext4: move struct ext4_xattr_inode_array to xattr.h
In reply to Tahsin ErdoganSince this is a xattr specific data structure it is cleaner to keep it in xattr header file.
--- fs/ext4/ext4.h | 4 ---- fs/ext4/xattr.h | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-)
fs/ext4/ext4.h +0 -4
@@ -2232,10 +2232,6 @@ struct mmpd_data {# define ATTRIB_NORET __attribute__((noreturn))# define NORET_AND noreturn, -struct ext4_xattr_inode_array { -unsigned int count;/* # of used items in the array */ -struct inode *inodes[0 ]; -};/* bitmap.c */ extern unsigned int ext4_count_free (char *bitmap,unsigned numchars); void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
fs/ext4/xattr.h +5 -0
@@ -117,6 +117,11 @@ struct ext4_xattr_ibody_find {struct ext4_iloc iloc; }; +struct ext4_xattr_inode_array { +unsigned int count;/* # of used items in the array */ +struct inode *inodes[0 ]; +}; +extern const struct xattr_handler ext4_xattr_user_handler;extern const struct xattr_handler ext4_xattr_trusted_handler;extern const struct xattr_handler ext4_xattr_security_handler;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 23/32 mbcache: make mbcache naming more generic
In reply to Tahsin ErdoganMake names more generic so that mbcache usage is not limited to block sharing. In a subsequent patch in the series
("ext4: xattr inode deduplication"), we start using the mbcache code for sharing xattr inodes. With that patch, old mb_cache_entry.e_block field could be holding either a block number or an inode number.
---
v3: removed space after typecast
v2: updated commit title and description
fs/ext2/xattr.c | 18 +++++++++--------- fs/ext4/xattr.c | 10 +++++----- fs/mbcache.c | 43 +++++++++++++++++++++---------------------- include/linux/mbcache.h | 11 +++++------ 4 files changed, 40 insertions(+), 42 deletions(-)
fs/ext2/xattr.c +9 -9
@@ -493,8 +493,8 @@ bad_block: ext2_error(sb, "ext2_xattr_set",* This must happen under buffer lock for * ext2_xattr_set2() to reliably detect modified block */ -mb_cache_entry_delete_block (EXT2_SB (sb)->s_mb_cache, - hash, bh->b_blocknr); +mb_cache_entry_delete (EXT2_SB (sb)->s_mb_cache, hash, + bh->b_blocknr);/* keep the buffer locked while modifying it. */ }else {
@@ -721,8 +721,8 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,* This must happen under buffer lock for * ext2_xattr_set2() to reliably detect freed block */ -mb_cache_entry_delete_block (ext2_mb_cache, - hash, old_bh->b_blocknr); +mb_cache_entry_delete (ext2_mb_cache, hash, + old_bh->b_blocknr);/* Free the old block. */ ea_bdebug (old_bh,"freeing" );ext2_free_blocks (inode, old_bh->b_blocknr,1 );
@@ -795,8 +795,8 @@ ext2_xattr_delete_inode(struct inode *inode)* This must happen under buffer lock for ext2_xattr_set2() to * reliably detect freed block */ -mb_cache_entry_delete_block (EXT2_SB (inode->i_sb)->s_mb_cache, - hash, bh->b_blocknr); +mb_cache_entry_delete (EXT2_SB (inode->i_sb)->s_mb_cache, hash, + bh->b_blocknr);ext2_free_blocks (inode,EXT2_I (inode)->i_file_acl,1 );get_bh (bh);bforget (bh);
@@ -907,11 +907,11 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)while (ce) {struct buffer_head *bh; - bh =sb_bread (inode->i_sb, ce->e_block); + bh =sb_bread (inode->i_sb, ce->e_value);if (!bh) {ext2_error (inode->i_sb,"ext2_xattr_cache_find" ,"inode %ld: block %ld read error" , - inode->i_ino, (unsigned long ) ce->e_block); + inode->i_ino, (unsigned long ) ce->e_value); }else {lock_buffer (bh);/*
@@ -931,7 +931,7 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header) }else if (le32_to_cpu (HDR (bh)->h_refcount) >EXT2_XATTR_REFCOUNT_MAX ) {ea_idebug (inode,"block %ld refcount %d>%d" , - (unsigned long ) ce->e_block, + (unsigned long ) ce->e_value,le32_to_cpu (HDR (bh)->h_refcount),EXT2_XATTR_REFCOUNT_MAX ); }else if (!ext2_xattr_cmp (header,HDR (bh))) {
fs/ext4/xattr.c +5 -5
@@ -678,7 +678,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,* This must happen under buffer lock for * ext4_xattr_block_set() to reliably detect freed block */ -mb_cache_entry_delete_block (ext4_mb_cache, hash, bh->b_blocknr); +mb_cache_entry_delete (ext4_mb_cache, hash, bh->b_blocknr);get_bh (bh);unlock_buffer (bh); ext4_free_blocks(handle, inode, bh, 0, 1,
@@ -1115,8 +1115,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,* ext4_xattr_block_set() to reliably detect modified * block */ -mb_cache_entry_delete_block (ext4_mb_cache, hash, - bs->bh->b_blocknr); +mb_cache_entry_delete (ext4_mb_cache, hash, + bs->bh->b_blocknr);ea_bdebug (bs->bh,"modifying in-place" ); error =ext4_xattr_set_entry (i, s, handle, inode);if (!error) {
@@ -2238,10 +2238,10 @@ ext4_xattr_cache_find(struct inode *inode, struct ext4_xattr_header *header,while (ce) {struct buffer_head *bh; - bh =sb_bread (inode->i_sb, ce->e_block); + bh =sb_bread (inode->i_sb, ce->e_value);if (!bh) {EXT4_ERROR_INODE (inode,"block %lu read error" , - (unsigned long ) ce->e_block); + (unsigned long )ce->e_value); }else if (ext4_xattr_cmp (header,BHDR (bh)) ==0 ) { *pce = ce;return bh;
fs/mbcache.c +21 -22
104 lines not on this page · raw message
include/linux/mbcache.h +5 -6
@@ -19,15 +19,15 @@ struct mb_cache_entry {u32 e_key; u32 e_referenced:1; u32 e_reusable:1; -/* Block number of hashed block - stable during lifetime of the entry */ -sector_t e_block; +/* User provided value - stable during lifetime of the entry */ +u64 e_value; };struct mb_cache *mb_cache_create (int bucket_bits);void mb_cache_destroy (struct mb_cache *cache);int mb_cache_entry_create (struct mb_cache *cache,gfp_t mask,u32 key, -sector_t block,bool reusable); +u64 value,bool reusable);void __mb_cache_entry_free (struct mb_cache_entry *entry);static inline int mb_cache_entry_put (struct mb_cache *cache,struct mb_cache_entry *entry)
@@ -38,10 +38,9 @@ static inline int mb_cache_entry_put(struct mb_cache *cache,return 1 ; } -void mb_cache_entry_delete_block (struct mb_cache *cache,u32 key, -sector_t block); +void mb_cache_entry_delete (struct mb_cache *cache,u32 key,u64 value);struct mb_cache_entry *mb_cache_entry_get (struct mb_cache *cache,u32 key, -sector_t block); +u64 value);struct mb_cache_entry *mb_cache_entry_find_first (struct mb_cache *cache,u32 key); struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache,
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 24/32 ext2, ext4: make mb block cache names more explicit
In reply to Tahsin ErdoganThere will be a second mb_cache instance that tracks ea_inodes. Make existing names more explicit so that it is clear that they refer to xattr block cache.
---
v2:
- renamed s_mb_cache to s_mb_block_cache in both ext2 and ext4
- renamed local variables named ext[24]_mb_cache to mb_block_cache
- renamed macro EXT4_GET_MB_CACHE() to MB_BLOCK_CACHE()
- added MB_BLOCK_CACHE() to ext2 for consistency with ext4
fs/ext2/ext2.h | 2 +- fs/ext2/super.c | 14 ++++++------ fs/ext2/xattr.c | 36 +++++++++++++++-------------- fs/ext4/ext4.h | 2 +- fs/ext4/super.c | 16 ++++++------- fs/ext4/xattr.c | 71 ++++++++++++++++++++++++++++++--------------------------- 6 files changed, 73 insertions(+), 68 deletions(-)
fs/ext2/ext2.h +1 -1
@@ -113,7 +113,7 @@ struct ext2_sb_info {* of the mount options. */ spinlock_t s_lock; -struct mb_cache *s_mb_cache; +struct mb_cache *s_mb_block_cache; }; static inline spinlock_t *
fs/ext2/super.c +7 -7
@@ -147,9 +147,9 @@ static void ext2_put_super (struct super_block * sb)ext2_quota_off_umount (sb); -if (sbi->s_mb_cache) { -ext2_xattr_destroy_cache (sbi->s_mb_cache); - sbi->s_mb_cache =NULL ; +if (sbi->s_mb_block_cache) { +ext2_xattr_destroy_cache (sbi->s_mb_block_cache); + sbi->s_mb_block_cache =NULL ; }if (!(sb->s_flags &MS_RDONLY )) {struct ext2_super_block *es = sbi->s_es;
@@ -1131,8 +1131,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) }#ifdef CONFIG_EXT2_FS_XATTR - sbi->s_mb_cache =ext2_xattr_create_cache (); -if (!sbi->s_mb_cache) { + sbi->s_mb_block_cache =ext2_xattr_create_cache (); +if (!sbi->s_mb_block_cache) {ext2_msg (sb,KERN_ERR ,"Failed to create an mb_cache" ); goto failed_mount3; }
@@ -1182,8 +1182,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) sb->s_id); goto failed_mount; failed_mount3: -if (sbi->s_mb_cache) -ext2_xattr_destroy_cache (sbi->s_mb_cache); +if (sbi->s_mb_block_cache) +ext2_xattr_destroy_cache (sbi->s_mb_block_cache);percpu_counter_destroy (&sbi->s_freeblocks_counter);percpu_counter_destroy (&sbi->s_freeinodes_counter);percpu_counter_destroy (&sbi->s_dirs_counter);
fs/ext2/xattr.c +19 -17
@@ -121,6 +121,8 @@ const struct xattr_handler *ext2_xattr_handlers[] = { NULL }; +#define MB_BLOCK_CACHE (inode) (EXT2_SB(inode->i_sb)->s_mb_block_cache) +static inline const struct xattr_handler *ext2_xattr_handler (int name_index) {
@@ -150,7 +152,7 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,size_t name_len, size;char *end;int error; -struct mb_cache *ext2_mb_cache =EXT2_SB (inode->i_sb)->s_mb_cache; +struct mb_cache *mb_block_cache =MB_BLOCK_CACHE (inode);ea_idebug (inode,"name=%d.%s, buffer=%p, buffer_size=%ld" , name_index, name, buffer, (long )buffer_size);
@@ -195,7 +197,7 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_get", goto found; entry = next; } -if (ext2_xattr_cache_insert (ext2_mb_cache, bh)) +if (ext2_xattr_cache_insert (mb_block_cache, bh))ea_idebug (inode,"cache insert failed" ); error = -ENODATA ; goto cleanup;
@@ -208,7 +210,7 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_get", le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize) goto bad_block; -if (ext2_xattr_cache_insert (ext2_mb_cache, bh)) +if (ext2_xattr_cache_insert (mb_block_cache, bh))ea_idebug (inode,"cache insert failed" );if (buffer) { error = -ERANGE ;
@@ -246,7 +248,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)char *end;size_t rest = buffer_size;int error; -struct mb_cache *ext2_mb_cache =EXT2_SB (inode->i_sb)->s_mb_cache; +struct mb_cache *mb_block_cache =MB_BLOCK_CACHE (inode);ea_idebug (inode,"buffer=%p, buffer_size=%ld" , buffer, (long )buffer_size);
@@ -281,7 +283,7 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list", goto bad_block; entry = next; } -if (ext2_xattr_cache_insert (ext2_mb_cache, bh)) +if (ext2_xattr_cache_insert (mb_block_cache, bh))ea_idebug (inode,"cache insert failed" );/* list the attribute names */
@@ -493,7 +495,7 @@ bad_block: ext2_error(sb, "ext2_xattr_set",* This must happen under buffer lock for * ext2_xattr_set2() to reliably detect modified block */ -mb_cache_entry_delete (EXT2_SB (sb)->s_mb_cache, hash, +mb_cache_entry_delete (MB_BLOCK_CACHE (inode), hash, bh->b_blocknr);/* keep the buffer locked while modifying it. */
@@ -627,7 +629,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,struct super_block *sb = inode->i_sb;struct buffer_head *new_bh =NULL ;int error; -struct mb_cache *ext2_mb_cache =EXT2_SB (sb)->s_mb_cache; +struct mb_cache *mb_block_cache =MB_BLOCK_CACHE (inode);if (header) { new_bh =ext2_xattr_cache_find (inode, header);
@@ -655,7 +657,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,don't need to change the reference count. */ new_bh = old_bh;get_bh (new_bh); -ext2_xattr_cache_insert (ext2_mb_cache, new_bh); +ext2_xattr_cache_insert (mb_block_cache, new_bh); }else {/* We need to allocate a new block */ ext2_fsblk_t goal = ext2_group_first_block_no(sb,
@@ -676,7 +678,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,memcpy (new_bh->b_data, header, new_bh->b_size);set_buffer_uptodate (new_bh);unlock_buffer (new_bh); -ext2_xattr_cache_insert (ext2_mb_cache, new_bh); +ext2_xattr_cache_insert (mb_block_cache, new_bh);ext2_xattr_update_super_block (sb); }
@@ -721,7 +723,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,* This must happen under buffer lock for * ext2_xattr_set2() to reliably detect freed block */ -mb_cache_entry_delete (ext2_mb_cache, hash, +mb_cache_entry_delete (mb_block_cache, hash, old_bh->b_blocknr);/* Free the old block. */ ea_bdebug (old_bh,"freeing" );
@@ -795,7 +797,7 @@ ext2_xattr_delete_inode(struct inode *inode)* This must happen under buffer lock for ext2_xattr_set2() to * reliably detect freed block */ -mb_cache_entry_delete (EXT2_SB (inode->i_sb)->s_mb_cache, hash, +mb_cache_entry_delete (MB_BLOCK_CACHE (inode), hash, bh->b_blocknr);ext2_free_blocks (inode,EXT2_I (inode)->i_file_acl,1 );get_bh (bh);
@@ -897,13 +899,13 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header) {__u32 hash =le32_to_cpu (header->h_hash);struct mb_cache_entry *ce; -struct mb_cache *ext2_mb_cache =EXT2_SB (inode->i_sb)->s_mb_cache; +struct mb_cache *mb_block_cache =MB_BLOCK_CACHE (inode);if (!header->h_hash)return NULL ;/* never share */ ea_idebug (inode,"looking for cached blocks [%x]" , (int )hash); again: - ce =mb_cache_entry_find_first (ext2_mb_cache, hash); + ce =mb_cache_entry_find_first (mb_block_cache, hash);while (ce) {struct buffer_head *bh;
@@ -924,7 +926,7 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)* entry is still hashed is reliable. */ if (hlist_bl_unhashed (&ce->e_hash_list)) { -mb_cache_entry_put (ext2_mb_cache, ce); +mb_cache_entry_put (mb_block_cache, ce);unlock_buffer (bh);brelse (bh); goto again;
@@ -937,14 +939,14 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header) }else if (!ext2_xattr_cmp (header,HDR (bh))) {ea_bdebug (bh,"b_count=%d" ,atomic_read (&(bh->b_count))); -mb_cache_entry_touch (ext2_mb_cache, ce); -mb_cache_entry_put (ext2_mb_cache, ce); +mb_cache_entry_touch (mb_block_cache, ce); +mb_cache_entry_put (mb_block_cache, ce);return bh; }unlock_buffer (bh);brelse (bh); } - ce =mb_cache_entry_find_next (ext2_mb_cache, ce); + ce =mb_cache_entry_find_next (mb_block_cache, ce); }return NULL ; }
fs/ext4/ext4.h +1 -1
@@ -1516,7 +1516,7 @@ struct ext4_sb_info {struct list_head s_es_list;/* List of inodes with reclaimable extents */ long s_es_nr_inode;struct ext4_es_stats s_es_stats; -struct mb_cache *s_mb_cache; +struct mb_cache *s_mb_block_cache;spinlock_t s_es_lock____cacheline_aligned_in_smp ;/* Ratelimit ext4 messages. */
fs/ext4/super.c +8 -8
@@ -927,9 +927,9 @@ static void ext4_put_super(struct super_block *sb)invalidate_bdev (sbi->journal_bdev);ext4_blkdev_remove (sbi); } -if (sbi->s_mb_cache) { -ext4_xattr_destroy_cache (sbi->s_mb_cache); - sbi->s_mb_cache =NULL ; +if (sbi->s_mb_block_cache) { +ext4_xattr_destroy_cache (sbi->s_mb_block_cache); + sbi->s_mb_block_cache =NULL ; }if (sbi->s_mmp_tsk)kthread_stop (sbi->s_mmp_tsk);
@@ -4061,8 +4061,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_journal->j_commit_callback = ext4_journal_commit_callback; no_journal: - sbi->s_mb_cache =ext4_xattr_create_cache (); -if (!sbi->s_mb_cache) { + sbi->s_mb_block_cache =ext4_xattr_create_cache (); +if (!sbi->s_mb_block_cache) {ext4_msg (sb,KERN_ERR ,"Failed to create an mb_cache" ); goto failed_mount_wq; }
@@ -4296,9 +4296,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)if (EXT4_SB (sb)->rsv_conversion_wq)destroy_workqueue (EXT4_SB (sb)->rsv_conversion_wq); failed_mount_wq: -if (sbi->s_mb_cache) { -ext4_xattr_destroy_cache (sbi->s_mb_cache); - sbi->s_mb_cache =NULL ; +if (sbi->s_mb_block_cache) { +ext4_xattr_destroy_cache (sbi->s_mb_block_cache); + sbi->s_mb_block_cache =NULL ; }if (sbi->s_journal) {jbd2_journal_destroy (sbi->s_journal);
fs/ext4/xattr.c +37 -34
219 lines not on this page · raw message
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 25/32 ext4: add ext4_is_quota_file()
In reply to Tahsin ErdoganIS_NOQUOTA() indicates whether quota is disabled for an inode. Ext4 also uses it to check whether an inode is for a quota file. The distinction currently doesn't matter because quota is disabled only for the quota files. When we start disabling quota for other inodes in the future, we will want to make the distinction clear.
Replace IS_NOQUOTA() call with ext4_is_quota_file() at places where we are checking for quota files.
--- fs/ext4/ext4.h | 2 ++ fs/ext4/inode.c | 2 +- fs/ext4/ioctl.c | 4 ++-- fs/ext4/mballoc.c | 2 +- fs/ext4/move_extent.c | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-)
fs/ext4/ext4.h +2 -0
@@ -2099,6 +2099,8 @@ static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc)return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset); } +#define ext4_is_quota_file (inode) IS_NOQUOTA(inode) +/* * This structure is stuffed into the struct file's private_data field * for directories. It is where we put information so that we can do
fs/ext4/inode.c +1 -1
@@ -739,7 +739,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,if (map->m_flags &EXT4_MAP_NEW && !(map->m_flags &EXT4_MAP_UNWRITTEN ) && !(flags &EXT4_GET_BLOCKS_ZERO ) && - !IS_NOQUOTA (inode) && + !ext4_is_quota_file (inode) &&ext4_should_order_data (inode)) {if (flags &EXT4_GET_BLOCKS_IO_SUBMIT ) ret =ext4_jbd2_inode_add_wait (handle, inode);
fs/ext4/ioctl.c +2 -2
@@ -218,7 +218,7 @@ static int ext4_ioctl_setflags(struct inode *inode,unsigned int jflag;/* Is it quota file? Do not allow user to mess with it */ -if (IS_NOQUOTA (inode)) +if (ext4_is_quota_file (inode)) goto flags_out; oldflags = ei->i_flags;
@@ -342,7 +342,7 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid) err = -EPERM ;inode_lock (inode);/* Is it quota file? Do not allow user to mess with it */ -if (IS_NOQUOTA (inode)) +if (ext4_is_quota_file (inode)) goto out_unlock; err =ext4_get_inode_loc (inode, &iloc);
fs/ext4/mballoc.c +1 -1
@@ -4464,7 +4464,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,trace_ext4_request_blocks (ar);/* Allow to use superuser reservation for quota file */ -if (IS_NOQUOTA (ar->inode)) +if (ext4_is_quota_file (ar->inode)) ar->flags |=EXT4_MB_USE_ROOT_BLOCKS ;if ((ar->flags &EXT4_MB_DELALLOC_RESERVED ) ==0 ) {
fs/ext4/move_extent.c +1 -1
@@ -484,7 +484,7 @@ mext_check_arguments(struct inode *orig_inode,return -EBUSY ; } -if (IS_NOQUOTA (orig_inode) ||IS_NOQUOTA (donor_inode)) { +if (ext4_is_quota_file (orig_inode) &&ext4_is_quota_file (donor_inode)) {ext4_debug ("ext4 move extent: The argument files should " "not be quota files [ino:orig %lu, donor %lu]\n" , orig_inode->i_ino, donor_inode->i_ino);
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 26/32 ext4: cleanup transaction restarts during inode deletion
In reply to Tahsin ErdoganDuring inode deletion, journal credits that will be needed are hard to determine, that is why we have journal extend/restart calls in several places. Whenever a transaction is restarted, filesystem must be in a consistent state because there is no atomicity guarantee beyond a restart call.
Add ext4_xattr_ensure_credits() helper function which takes care of journal extend/restart logic. It also handles getting jbd2 write access and dirty metadata calls. This function is called at every iteration of handling an ea_inode reference.
---
v3: fixed checkpatch.pl warnings about long lines and indented label
v2: made ext4_xattr_ensure_credits() static
fs/ext4/inode.c | 66 ++++----------- fs/ext4/xattr.c | 258 ++++++++++++++++++++++++++++++++++++-------------------- fs/ext4/xattr.h | 3 +- 3 files changed, 184 insertions(+), 143 deletions(-)
fs/ext4/inode.c +17 -49
@@ -239,7 +239,11 @@ void ext4_evict_inode(struct inode *inode)*/ sb_start_intwrite (inode->i_sb); - handle =ext4_journal_start (inode,EXT4_HT_TRUNCATE , extra_credits); +if (!IS_NOQUOTA (inode)) + extra_credits +=EXT4_MAXQUOTAS_DEL_BLOCKS (inode->i_sb); + + handle =ext4_journal_start (inode,EXT4_HT_TRUNCATE , +ext4_blocks_for_truncate (inode)+extra_credits);if (IS_ERR (handle)) {ext4_std_error (inode->i_sb,PTR_ERR (handle));/*
@@ -251,36 +255,9 @@ void ext4_evict_inode(struct inode *inode)sb_end_intwrite (inode->i_sb); goto no_delete; } +if (IS_SYNC (inode))ext4_handle_sync (handle); - -/* -* Delete xattr inode before deleting the main inode. -*/ - err =ext4_xattr_delete_inode (handle, inode, &ea_inode_array); -if (err) { -ext4_warning (inode->i_sb, -"couldn't delete inode's xattr (err %d)" , err); - goto stop_handle; - } - -if (!IS_NOQUOTA (inode)) - extra_credits +=2 *EXT4_QUOTA_DEL_BLOCKS (inode->i_sb); - -if (!ext4_handle_has_enough_credits (handle, -ext4_blocks_for_truncate (inode) + extra_credits)) { - err =ext4_journal_extend (handle, -ext4_blocks_for_truncate (inode) + extra_credits); -if (err >0 ) - err =ext4_journal_restart (handle, -ext4_blocks_for_truncate (inode) + extra_credits); -if (err !=0 ) { -ext4_warning (inode->i_sb, -"couldn't extend journal (err %d)" , err); - goto stop_handle; - } - } - inode->i_size =0 ; err =ext4_mark_inode_dirty (handle, inode);if (err) {
@@ -298,25 +275,17 @@ void ext4_evict_inode(struct inode *inode) } } -/* -* ext4_ext_truncate() doesn't reserve any slop when it -* restarts journal transactions; therefore there may not be -* enough credits left in the handle to remove the inode from -* the orphan list and set the dtime field. -*/ -if (!ext4_handle_has_enough_credits (handle, extra_credits)) { - err =ext4_journal_extend (handle, extra_credits); -if (err >0 ) - err =ext4_journal_restart (handle, extra_credits); -if (err !=0 ) { -ext4_warning (inode->i_sb, -"couldn't extend journal (err %d)" , err); - stop_handle: -ext4_journal_stop (handle); -ext4_orphan_del (NULL , inode); -sb_end_intwrite (inode->i_sb); - goto no_delete; - } +/* Remove xattr references. */ + err =ext4_xattr_delete_inode (handle, inode, &ea_inode_array, + extra_credits); +if (err) { +ext4_warning (inode->i_sb,"xattr delete (err %d)" , err); +stop_handle: +ext4_journal_stop (handle); +ext4_orphan_del (NULL , inode); +sb_end_intwrite (inode->i_sb); +ext4_xattr_inode_array_free (ea_inode_array); + goto no_delete; }/*
@@ -342,7 +311,6 @@ void ext4_evict_inode(struct inode *inode)ext4_clear_inode (inode); elseext4_free_inode (handle ,inode ); -ext4_journal_stop (handle);sb_end_intwrite (inode->i_sb);ext4_xattr_inode_array_free (ea_inode_array);
fs/ext4/xattr.c +165 -93
312 lines not on this page · raw message
fs/ext4/xattr.h +2 -1
@@ -169,7 +169,8 @@ extern int ext4_xattr_set_credits(struct inode *inode, size_t value_len);extern int ext4_xattr_inode_unlink (struct inode *inode,unsigned long ea_ino);extern int ext4_xattr_delete_inode (handle_t *handle,struct inode *inode, -struct ext4_xattr_inode_array **array); +struct ext4_xattr_inode_array **array, +int extra_credits);extern void ext4_xattr_inode_array_free (struct ext4_xattr_inode_array *array); extern int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 27/32 ext4: xattr inode deduplication
In reply to Tahsin ErdoganExt4 now supports xattr values that are up to 64k in size (vfs limit). Large xattr values are stored in external inodes each one holding a single value. Once written the data blocks of these inodes are immutable.
The real world use cases are expected to have a lot of value duplication such as inherited acls etc. To reduce data duplication on disk, this patch implements a deduplicator that allows sharing of xattr inodes.
The deduplication is based on an in-memory hash lookup that is a best effort sharing scheme. When a xattr inode is read from disk (i.e. getxattr() call), its crc32c hash is added to a hash table. Before creating a new xattr inode for a value being set, the hash table is checked to see if an existing inode holds an identical value. If such an inode is found, the ref count on that inode is incremented. On value removal the ref count is decremented and if it reaches zero the inode is deleted.
The quota charging for such inodes is manually managed. Every reference holder is charged the full size as if there was no sharing happening. This is consistent with how xattr blocks are also charged.
---
v5:
- made ext4_meta_trans_blocks() static again since there are no remaining users outside of inode.c
- initialize sbi->s_csum_seed when ea_inode feature is enabled
- use l_i_version to hold lower 32 bits of the xattr ref count. This avoids clashes with old implementations which use i_mtime. Since l_i_version is not available in HURD_COMPAT mode, fail mount request when both ea_inode feature and HURD_COMPAT are set.
- when hash validation fails, fall back to old implementation which has a backref to parent.
- fixed checkpatch.pl warning about using unsigned alone
v4:
- eliminated xattr entry in the xattr inode to avoid complexity and recursion in xattr update path. Now the ref count and hash are stored in i_[c/m/a]time.tv_sec fields.
- some clean up in ext4_xattr_set_entry() to reduce code duplication and complexity
v3:
- use s_csum_seed for hash calculations when available
- return error on stored vs calculated hash mismatch
v2:
- make dependency on crc32c dynamic
- update ext4_has_metadata_csum() and ext4_has_group_desc_csum() so that they do not misinterpret existence of EXT4_SB(sb)->s_chksum_driver
fs/ext4/acl.c | 5 +- fs/ext4/ext4.h | 23 +- fs/ext4/inode.c | 13 +- fs/ext4/super.c | 37 +- fs/ext4/xattr.c | 1038 +++++++++++++++++++++++++++++++++++++++++-------------- fs/ext4/xattr.h | 17 +- fs/mbcache.c | 9 +- 7 files changed, 848 insertions(+), 294 deletions(-)
fs/ext4/acl.c +4 -1
@@ -238,7 +238,10 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)if (error)return error; retry: - credits =ext4_xattr_set_credits (inode, acl_size); + error =ext4_xattr_set_credits (inode, acl_size, &credits); +if (error) +return error; + handle =ext4_journal_start (inode,EXT4_HT_XATTR , credits);if (IS_ERR (handle))return PTR_ERR (handle);
fs/ext4/ext4.h +14 -9
@@ -1517,6 +1517,7 @@ struct ext4_sb_info {long s_es_nr_inode;struct ext4_es_stats s_es_stats;struct mb_cache *s_mb_block_cache; +struct mb_cache *s_ea_inode_cache;spinlock_t s_es_lock____cacheline_aligned_in_smp ;/* Ratelimit ext4 messages. */
@@ -2099,7 +2100,11 @@ static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc)return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset); } -#define ext4_is_quota_file (inode) IS_NOQUOTA(inode) +static inline bool ext4_is_quota_file (struct inode *inode) +{ +return IS_NOQUOTA (inode) && + !(EXT4_I (inode)->i_flags &EXT4_EA_INODE_FL ); +}/* * This structure is stuffed into the struct file's private_data field
@@ -2482,7 +2487,6 @@ extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);extern void ext4_set_inode_flags (struct inode *);extern int ext4_alloc_da_blocks (struct inode *inode);extern void ext4_set_aops (struct inode *inode); -extern int ext4_meta_trans_blocks (struct inode *,int nrblocks,int chunk);extern int ext4_writepage_trans_blocks (struct inode *);extern int ext4_chunk_trans_blocks (struct inode *,int nrblocks); extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
@@ -2709,19 +2713,20 @@ extern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group,extern int ext4_register_li_request (struct super_block *sb,ext4_group_t first_not_zeroed); -static inline int ext4_has_group_desc_csum (struct super_block *sb) -{ -return ext4_has_feature_gdt_csum (sb) || -EXT4_SB (sb)->s_chksum_driver !=NULL ; -} -static inline int ext4_has_metadata_csum (struct super_block *sb) {WARN_ON_ONCE (ext4_has_feature_metadata_csum (sb) && !EXT4_SB (sb)->s_chksum_driver); -return (EXT4_SB (sb)->s_chksum_driver !=NULL ); +return ext4_has_feature_metadata_csum (sb) && + (EXT4_SB (sb)->s_chksum_driver !=NULL ); } + +static inline int ext4_has_group_desc_csum (struct super_block *sb) +{ +return ext4_has_feature_gdt_csum (sb) ||ext4_has_metadata_csum (sb); +} +static inline ext4_fsblk_t ext4_blocks_count (struct ext4_super_block *es) { return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
fs/ext4/inode.c +11 -2
@@ -139,6 +139,8 @@ static void ext4_invalidatepage(struct page *page, unsigned int offset, unsigned int length);static int __ext4_journalled_writepage (struct page *page,unsigned int len);static int ext4_bh_delay_or_unwritten (handle_t *handle,struct buffer_head *bh); +static int ext4_meta_trans_blocks (struct inode *inode,int lblocks, +int pextents);/* * Test whether an inode is a fast symlink.
@@ -4843,8 +4845,15 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) }brelse (iloc.bh);ext4_set_inode_flags (inode); -if (ei->i_flags &EXT4_EA_INODE_FL ) + +if (ei->i_flags &EXT4_EA_INODE_FL ) {ext4_xattr_inode_set_class (inode); + +inode_lock (inode); + inode->i_flags |=S_NOQUOTA ; +inode_unlock (inode); + } +unlock_new_inode (inode);return inode;
@@ -5503,7 +5512,7 @@ static int ext4_index_trans_blocks(struct inode *inode, int lblocks,* * Also account for superblock, inode, quota and xattr blocks */ -int ext4_meta_trans_blocks (struct inode *inode,int lblocks, +static int ext4_meta_trans_blocks (struct inode *inode,int lblocks,int pextents) {ext4_group_t groups, ngroups =ext4_get_groups_count (inode->i_sb);
fs/ext4/super.c +34 -3
@@ -927,6 +927,10 @@ static void ext4_put_super(struct super_block *sb)invalidate_bdev (sbi->journal_bdev);ext4_blkdev_remove (sbi); } +if (sbi->s_ea_inode_cache) { +ext4_xattr_destroy_cache (sbi->s_ea_inode_cache); + sbi->s_ea_inode_cache =NULL ; + }if (sbi->s_mb_block_cache) {ext4_xattr_destroy_cache (sbi->s_mb_block_cache); sbi->s_mb_block_cache =NULL ;
@@ -1178,7 +1182,10 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,if (res)return res; retry: - credits =ext4_xattr_set_credits (inode, len); + res =ext4_xattr_set_credits (inode, len, &credits); +if (res) +return res; + handle =ext4_journal_start (inode,EXT4_HT_MISC , credits);if (IS_ERR (handle))return PTR_ERR (handle);
@@ -3445,7 +3452,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) }/* Load the checksum driver */ -if (ext4_has_feature_metadata_csum (sb)) { +if (ext4_has_feature_metadata_csum (sb) || +ext4_has_feature_ea_inode (sb)) { sbi->s_chksum_driver =crypto_alloc_shash ("crc32c" ,0 ,0 );if (IS_ERR (sbi->s_chksum_driver)) {ext4_msg (sb,KERN_ERR ,"Cannot load crc32c driver." );
@@ -3467,7 +3475,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)/* Precompute checksum seed for all metadata */ if (ext4_has_feature_csum_seed (sb)) sbi->s_csum_seed =le32_to_cpu (es->s_checksum_seed); -else if (ext4_has_metadata_csum (sb)) +else if (ext4_has_metadata_csum (sb) ||ext4_has_feature_ea_inode (sb)) sbi->s_csum_seed =ext4_chksum (sbi, ~0 , es->s_uuid,sizeof (es->s_uuid));
@@ -3597,6 +3605,16 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) "The Hurd can't support 64-bit file systems"); goto failed_mount; } + +/* +* ea_inode feature uses l_i_version field which is not +* available in HURD_COMPAT mode. +*/ +if (ext4_has_feature_ea_inode (sb)) { +ext4_msg (sb,KERN_ERR , +"ea_inode feature is not supported for Hurd" ); + goto failed_mount; + } }if (IS_EXT2_SB (sb)) {
@@ -4067,6 +4085,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount_wq; } +if (ext4_has_feature_ea_inode (sb)) { + sbi->s_ea_inode_cache =ext4_xattr_create_cache (); +if (!sbi->s_ea_inode_cache) { +ext4_msg (sb,KERN_ERR , +"Failed to create an s_ea_inode_cache" ); + goto failed_mount_wq; + } + } +if ((DUMMY_ENCRYPTION_ENABLED (sbi) ||ext4_has_feature_encrypt (sb)) && (blocksize !=PAGE_SIZE )) { ext4_msg(sb, KERN_ERR,
@@ -4296,6 +4323,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)if (EXT4_SB (sb)->rsv_conversion_wq)destroy_workqueue (EXT4_SB (sb)->rsv_conversion_wq); failed_mount_wq: +if (sbi->s_ea_inode_cache) { +ext4_xattr_destroy_cache (sbi->s_ea_inode_cache); + sbi->s_ea_inode_cache =NULL ; + }if (sbi->s_mb_block_cache) {ext4_xattr_destroy_cache (sbi->s_mb_block_cache); sbi->s_mb_block_cache =NULL ;
fs/ext4/xattr.c +778 -260
1,330 lines not on this page · raw message
fs/ext4/xattr.h +2 -15
@@ -69,19 +69,6 @@ struct ext4_xattr_entry { EXT4_I(inode)->i_extra_isize))#define IFIRST (hdr) ((struct ext4_xattr_entry *)((hdr)+1)) -/* -* Link EA inode back to parent one using i_mtime field. -* Extra integer type conversion added to ignore higher -* bits in i_mtime.tv_sec which might be set by ext4_get() -*/ -#define EXT4_XATTR_INODE_SET_PARENT (inode, inum) \ -do { \ - (inode)->i_mtime.tv_sec = inum; \ -} while(0) - -#define EXT4_XATTR_INODE_GET_PARENT (inode) \ -((__u32)(inode)->i_mtime.tv_sec) -/* * The minimum size of EA value when you start storing it in an external inode * size of block - size of header - size of 1 entry - 4 null bytes
@@ -165,9 +152,9 @@ extern ssize_t ext4_listxattr(struct dentry *, char *, size_t);extern int ext4_xattr_get (struct inode *,int ,const char *,void *,size_t );extern int ext4_xattr_set (struct inode *,int ,const char *,const void *,size_t ,int );extern int ext4_xattr_set_handle (handle_t *,struct inode *,int ,const char *,const void *,size_t ,int ); -extern int ext4_xattr_set_credits (struct inode *inode,size_t value_len); +extern int ext4_xattr_set_credits (struct inode *inode,size_t value_len, +int *credits); -extern int ext4_xattr_inode_unlink (struct inode *inode,unsigned long ea_ino);extern int ext4_xattr_delete_inode (handle_t *handle,struct inode *inode,struct ext4_xattr_inode_array **array,int extra_credits);
fs/mbcache.c +5 -4
@@ -13,10 +13,11 @@* mb_cache_entry_delete()). * * Ext2 and ext4 use this cache for deduplication of extended attribute blocks. -* They use hash of a block contents as a key and block number as a value. -* That's why keys need not be unique (different xattr blocks may end up having -* the same hash). However block number always uniquely identifies a cache -* entry. +* Ext4 also uses it for deduplication of xattr values stored in inodes. +* They use hash of data as a key and provide a value that may represent a +* block or inode number. That's why keys need not be unique (hash of different +* data may be the same). However user provided value always uniquely +* identifies a cache entry. * * We provide functions for creation and removal of entries, search by key, * and a special "delete entry with given key-value pair" operation. Fixed
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 28/32 quota: add get_inode_usage callback to transfer multi-inode charges
In reply to Tahsin ErdoganExt4 ea_inode feature allows storing xattr values in external inodes to be able to store values that are bigger than a block in size. Ext4 also has deduplication support for these type of inodes. With deduplication, the actual storage waste is eliminated but the users of such inodes are still charged full quota for the inodes as if there was no sharing happening in the background.
This design requires ext4 to manually charge the users because the inodes are shared.
An implication of this is that, if someone calls chown on a file that has such references we need to transfer the quota for the file and xattr inodes. Current dquot_transfer() function implicitly transfers one inode charge. With ea_inode feature, we would like to transfer multiple inode charges.
Add get_inode_usage callback which can interrogate the total number of inodes that were charged for a given inode.
---
v3: added Acked-by
v2:
- added get_inode_usage() callback to query total inodes charge to be transferred
fs/ext4/inode.c | 7 +++++++ fs/ext4/ioctl.c | 6 ++++++ fs/ext4/super.c | 21 ++++++++++---------- fs/ext4/xattr.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/xattr.h | 2 ++ fs/quota/dquot.c | 16 +++++++++++---- include/linux/quota.h | 2 ++ 7 files changed, 94 insertions(+), 14 deletions(-)
fs/ext4/inode.c +7 -0
@@ -5295,7 +5295,14 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) error =PTR_ERR (handle); goto err_out; } + +/* dquot_transfer() calls back ext4_get_inode_usage() which +* counts xattr inode references. +*/ +down_read (&EXT4_I (inode)->xattr_sem); error =dquot_transfer (inode, attr); +up_read (&EXT4_I (inode)->xattr_sem); +if (error) {ext4_journal_stop (handle);return error;
fs/ext4/ioctl.c +6 -0
@@ -373,7 +373,13 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid) transfer_to[PRJQUOTA ] =dqget (sb,make_kqid_projid (kprojid));if (!IS_ERR (transfer_to[PRJQUOTA ])) { + +/* __dquot_transfer() calls back ext4_get_inode_usage() which +* counts xattr inode references. +*/ +down_read (&EXT4_I (inode)->xattr_sem); err =__dquot_transfer (inode, transfer_to); +up_read (&EXT4_I (inode)->xattr_sem);dqput (transfer_to[PRJQUOTA ]);if (err) goto out_dirty;
fs/ext4/super.c +11 -10
@@ -1263,16 +1263,17 @@ static struct dquot **ext4_get_dquots(struct inode *inode) }static const struct dquot_operations ext4_quota_operations = { - .get_reserved_space = ext4_get_reserved_space, - .write_dquot = ext4_write_dquot, - .acquire_dquot = ext4_acquire_dquot, - .release_dquot = ext4_release_dquot, - .mark_dirty = ext4_mark_dquot_dirty, - .write_info = ext4_write_info, - .alloc_dquot = dquot_alloc, - .destroy_dquot = dquot_destroy, - .get_projid = ext4_get_projid, - .get_next_id = ext4_get_next_id, + .get_reserved_space = ext4_get_reserved_space, + .write_dquot = ext4_write_dquot, + .acquire_dquot = ext4_acquire_dquot, + .release_dquot = ext4_release_dquot, + .mark_dirty = ext4_mark_dquot_dirty, + .write_info = ext4_write_info, + .alloc_dquot = dquot_alloc, + .destroy_dquot = dquot_destroy, + .get_projid = ext4_get_projid, + .get_inode_usage = ext4_get_inode_usage, + .get_next_id = ext4_get_next_id, };static const struct quotactl_ops ext4_qctl_operations = {
fs/ext4/xattr.c +54 -0
60 lines not on this page · raw message
fs/ext4/xattr.h +2 -0
@@ -193,3 +193,5 @@ extern void ext4_xattr_inode_set_class(struct inode *ea_inode);#else static inline void ext4_xattr_inode_set_class (struct inode *ea_inode) { }#endif + +extern int ext4_get_inode_usage (struct inode *inode,qsize_t *usage);
fs/quota/dquot.c +12 -4
@@ -1910,6 +1910,7 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to) {qsize_t space, cur_space;qsize_t rsv_space =0 ; +qsize_t inode_usage =1 ;struct dquot *transfer_from[MAXQUOTAS ] = {};int cnt, ret =0 ;char is_valid[MAXQUOTAS ] = {};
@@ -1919,6 +1920,13 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)if (IS_NOQUOTA (inode))return 0 ; + +if (inode->i_sb->dq_op->get_inode_usage) { + ret = inode->i_sb->dq_op->get_inode_usage (inode, &inode_usage); +if (ret) +return ret; + } +/* Initialize the arrays */ for (cnt =0 ; cnt <MAXQUOTAS ; cnt++) { warn_to[cnt].w_type =QUOTA_NL_NOWARN ;
@@ -1946,7 +1954,7 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)continue ; is_valid[cnt] =1 ; transfer_from[cnt] =i_dquot (inode)[cnt]; - ret =check_idq (transfer_to[cnt],1 , &warn_to[cnt]); + ret =check_idq (transfer_to[cnt], inode_usage, &warn_to[cnt]);if (ret) goto over_quota; ret =check_bdq (transfer_to[cnt], space,0 , &warn_to[cnt]);
@@ -1963,7 +1971,7 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)/* Due to IO error we might not have transfer_from[] structure */ if (transfer_from[cnt]) {int wtype; - wtype =info_idq_free (transfer_from[cnt],1 ); + wtype =info_idq_free (transfer_from[cnt], inode_usage);if (wtype !=QUOTA_NL_NOWARN )prepare_warning (&warn_from_inodes[cnt], transfer_from[cnt], wtype);
@@ -1971,13 +1979,13 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)if (wtype !=QUOTA_NL_NOWARN )prepare_warning (&warn_from_space[cnt], transfer_from[cnt], wtype); -dquot_decr_inodes (transfer_from[cnt],1 ); +dquot_decr_inodes (transfer_from[cnt], inode_usage);dquot_decr_space (transfer_from[cnt], cur_space);dquot_free_reserved_space (transfer_from[cnt], rsv_space); } -dquot_incr_inodes (transfer_to[cnt],1 ); +dquot_incr_inodes (transfer_to[cnt], inode_usage);dquot_incr_space (transfer_to[cnt], cur_space);dquot_resv_space (transfer_to[cnt], rsv_space);
include/linux/quota.h +2 -0
@@ -332,6 +332,8 @@ struct dquot_operations {* quota code only */ qsize_t *(*get_reserved_space) (struct inode *);int (*get_projid) (struct inode *,kprojid_t *);/* Get project ID */ +/* Get number of inodes that were charged for a given inode */ +int (*get_inode_usage) (struct inode *,qsize_t *);/* Get next ID with active quota structure */ int (*get_next_id) (struct super_block *sb,struct kqid *qid); };
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 30/32 ext4: eliminate xattr entry e_hash recalculation for removes
In reply to Tahsin ErdoganWhen an extended attribute block is modified, ext4_xattr_hash_entry() recalculates e_hash for the entry that is pointed by s->here. This is unnecessary if the modification is to remove an entry.
Currently, if the removed entry is the last one and there are other entries remaining, hash calculation targets the just erased entry which has been filled with zeroes and effectively does nothing. If the removed entry is not the last one and there are more entries, this time it will recalculate hash on the next entry which is totally unnecessary.
Fix these by moving the decision on when to recalculate hash to ext4_xattr_set_entry().
--- fs/ext4/xattr.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-)
fs/ext4/xattr.c +26 -24
@@ -77,8 +77,9 @@ static void ext4_xattr_block_cache_insert(struct mb_cache *,static struct buffer_head *ext4_xattr_block_cache_find (struct inode *,struct ext4_xattr_header *,struct mb_cache_entry **); -static void ext4_xattr_rehash (struct ext4_xattr_header *, -struct ext4_xattr_entry *); +static void ext4_xattr_hash_entry (struct ext4_xattr_entry *entry, +void *value_base); +static void ext4_xattr_rehash (struct ext4_xattr_header *);static const struct xattr_handler *const ext4_xattr_handler_map[] = { [EXT4_XATTR_INDEX_USER ] = &ext4_xattr_user_handler,
@@ -1454,7 +1455,8 @@ static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode,static int ext4_xattr_set_entry (struct ext4_xattr_info *i,struct ext4_xattr_search *s, -handle_t *handle,struct inode *inode) +handle_t *handle,struct inode *inode, +bool is_block) {struct ext4_xattr_entry *last;struct ext4_xattr_entry *here = s->here;
@@ -1518,8 +1520,8 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,* attribute block so that a long value does not occupy the * whole space and prevent futher entries being added. */ -if (ext4_has_feature_ea_inode (inode->i_sb) && new_size && - (s->end - s->base) ==i_blocksize (inode) && +if (ext4_has_feature_ea_inode (inode->i_sb) && + new_size && is_block && (min_offs + old_size - new_size) <EXT4_XATTR_BLOCK_RESERVE (inode)) { ret = -ENOSPC ;
@@ -1649,6 +1651,13 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, } here->e_value_size =cpu_to_le32 (i->value_len); } + +if (is_block) { +if (i->value) +ext4_xattr_hash_entry (here, s->base); +ext4_xattr_rehash ((struct ext4_xattr_header *)s->base); + } + ret =0 ; out:iput (old_ea_inode);
@@ -1738,14 +1747,11 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,mb_cache_entry_delete (mb_block_cache, hash, bs->bh->b_blocknr);ea_bdebug (bs->bh,"modifying in-place" ); - error =ext4_xattr_set_entry (i, s, handle, inode); -if (!error) { -if (!IS_LAST_ENTRY (s->first)) -ext4_xattr_rehash (header (s->base), - s->here); + error =ext4_xattr_set_entry (i, s, handle, inode, + true/* is_block */ ); +if (!error)ext4_xattr_block_cache_insert (mb_block_cache, bs->bh); - }ext4_xattr_block_csum_set (inode, bs->bh);unlock_buffer (bs->bh);if (error == -EFSCORRUPTED )
@@ -1805,7 +1811,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, s->end = s->base + sb->s_blocksize; } - error =ext4_xattr_set_entry (i, s, handle, inode); + error =ext4_xattr_set_entry (i, s, handle, inode, true/* is_block */ );if (error == -EFSCORRUPTED ) goto bad_block;if (error)
@@ -1828,9 +1834,6 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, } } -if (!IS_LAST_ENTRY (s->first)) -ext4_xattr_rehash (header (s->base), s->here); - inserted:if (!IS_LAST_ENTRY (s->first)) { new_bh = ext4_xattr_block_cache_find(inode, header(s->base),
@@ -2063,7 +2066,7 @@ int ext4_xattr_ibody_inline_set(handle_t *handle, struct inode *inode,if (EXT4_I (inode)->i_extra_isize ==0 )return -ENOSPC ; - error =ext4_xattr_set_entry (i, s, handle, inode); + error =ext4_xattr_set_entry (i, s, handle, inode, false/* is_block */ );if (error) {if (error == -ENOSPC &&ext4_has_inline_data (inode)) {
@@ -2075,7 +2078,8 @@ int ext4_xattr_ibody_inline_set(handle_t *handle, struct inode *inode, error =ext4_xattr_ibody_find (inode, i, is);if (error)return error; - error =ext4_xattr_set_entry (i, s, handle, inode); + error =ext4_xattr_set_entry (i, s, handle, inode, + false/* is_block */ ); }if (error)return error;
@@ -2101,7 +2105,7 @@ static int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,if (EXT4_I (inode)->i_extra_isize ==0 )return -ENOSPC ; - error =ext4_xattr_set_entry (i, s, handle, inode); + error =ext4_xattr_set_entry (i, s, handle, inode, false/* is_block */ );if (error)return error; header =IHDR (inode,ext4_raw_inode (&is->iloc));
@@ -2927,8 +2931,8 @@ ext4_xattr_block_cache_find(struct inode *inode,* * Compute the hash of an extended attribute. */ -static inline void ext4_xattr_hash_entry (struct ext4_xattr_header *header, -struct ext4_xattr_entry *entry) +static void ext4_xattr_hash_entry (struct ext4_xattr_entry *entry, +void *value_base) {__u32 hash =0 ;char *name = entry->e_name;
@@ -2941,7 +2945,7 @@ static inline void ext4_xattr_hash_entry(struct ext4_xattr_header *header, }if (!entry->e_value_inum && entry->e_value_size) { -__le32 *value = (__le32 *)((char *)header + +__le32 *value = (__le32 *)((char *)value_base +le16_to_cpu (entry->e_value_offs));for (n = (le32_to_cpu (entry->e_value_size) +EXT4_XATTR_ROUND ) >>EXT4_XATTR_PAD_BITS ; n; n--) {
@@ -2963,13 +2967,11 @@ static inline void ext4_xattr_hash_entry(struct ext4_xattr_header *header,* * Re-compute the extended attribute hash value after an entry has changed. */ -static void ext4_xattr_rehash (struct ext4_xattr_header *header, -struct ext4_xattr_entry *entry) +static void ext4_xattr_rehash (struct ext4_xattr_header *header) {struct ext4_xattr_entry *here;__u32 hash =0 ; -ext4_xattr_hash_entry (header, entry); here =ENTRY (header+1 );while (!IS_LAST_ENTRY (here)) {if (!here->e_hash) {
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 32/32 ext4: add nombcache mount option
In reply to Tahsin ErdoganThe main purpose of mb cache is to achieve deduplication in extended attributes. In use cases where opportunity for deduplication is unlikely, it only adds overhead.
Add a mount option to explicitly turn off mb cache.
--- fs/ext4/ext4.h | 1 + fs/ext4/super.c | 34 +++++++++++++++++++++++----------- fs/ext4/xattr.c | 52 +++++++++++++++++++++++++++++++++++----------------- 3 files changed, 59 insertions(+), 28 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -1149,6 +1149,7 @@ struct ext4_inode_info {#define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000/* Enable support for dio read nolocking */ #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000/* Journal checksums */ #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000/* Journal Async Commit */ +#define EXT4_MOUNT_NO_MBCACHE 0x2000000/* No mbcache usage */ #define EXT4_MOUNT_DELALLOC 0x8000000/* Delalloc support */ #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000/* Abort on file data write */ #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000/* Block validity checking */
fs/ext4/super.c +23 -11
@@ -1336,7 +1336,7 @@ enum { Opt_inode_readahead_blks, Opt_journal_ioprio, Opt_dioread_nolock, Opt_dioread_lock, Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable, - Opt_max_dir_size_kb, Opt_nojournal_checksum, + Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache, }; static const match_table_t tokens = {
@@ -1419,6 +1419,8 @@ static const match_table_t tokens = { {Opt_noinit_itable, "noinit_itable"}, {Opt_max_dir_size_kb, "max_dir_size_kb=%u"}, {Opt_test_dummy_encryption, "test_dummy_encryption"}, + {Opt_nombcache, "nombcache"}, + {Opt_nombcache, "no_mbcache"}, /* for backward compatibility */ {Opt_removed, "check=none"}, /* mount option from ext2/3 */ {Opt_removed, "nocheck"}, /* mount option from ext2/3 */ {Opt_removed, "reservation"}, /* mount option from ext2/3 */
@@ -1626,6 +1628,7 @@ static const struct mount_opts { {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT}, {Opt_max_dir_size_kb, 0, MOPT_GTE0}, {Opt_test_dummy_encryption, 0, MOPT_GTE0}, + {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, {Opt_err, 0, 0} };
@@ -4080,19 +4083,22 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_journal->j_commit_callback = ext4_journal_commit_callback; no_journal: - sbi->s_mb_block_cache =ext4_xattr_create_cache (); -if (!sbi->s_mb_block_cache) { -ext4_msg (sb,KERN_ERR ,"Failed to create an mb_cache" ); - goto failed_mount_wq; - } - -if (ext4_has_feature_ea_inode (sb)) { - sbi->s_ea_inode_cache =ext4_xattr_create_cache (); -if (!sbi->s_ea_inode_cache) { +if (!test_opt (sb,NO_MBCACHE )) { + sbi->s_mb_block_cache =ext4_xattr_create_cache (); +if (!sbi->s_mb_block_cache) {ext4_msg (sb,KERN_ERR , -"Failed to create an s_ea_inode_cache" ); +"Failed to create xattr block mb_cache" ); goto failed_mount_wq; } + +if (ext4_has_feature_ea_inode (sb)) { + sbi->s_ea_inode_cache =ext4_xattr_create_cache (); +if (!sbi->s_ea_inode_cache) { +ext4_msg (sb,KERN_ERR , +"Failed to create ea_inode mb_cache" ); + goto failed_mount_wq; + } + } } if ((DUMMY_ENCRYPTION_ENABLED(sbi) || ext4_has_feature_encrypt(sb)) &&
@@ -4989,6 +4995,12 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) } } +if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) &EXT4_MOUNT_NO_MBCACHE ) { +ext4_msg (sb,KERN_ERR ,"can't enable nombcache during remount" ); + err = -EINVAL ; + goto restore_opts; + } +if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) &EXT4_MOUNT_DAX ) {ext4_msg (sb,KERN_WARNING ,"warning: refusing change of " "dax flag with busy inodes while remounting" );
fs/ext4/xattr.c +35 -17
106 lines not on this page · raw message
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 8/32 ext4: fix ref counting for ea_inode
In reply to Tahsin ErdoganThe ref count on ea_inode is incremented by ext4_xattr_inode_orphan_add() which is supposed to be decremented by ext4_xattr_inode_array_free(). The decrement is conditioned on whether the ea_inode is currently on the orphan list. However, the orphan list addition only happens when journaling is enabled. In non-journaled case,r we fail to release the ref count causing an error message like below.
"VFS: Busy inodes after unmount of sdb. Self-destruct in 5 seconds. Have a nice day..."
--- fs/ext4/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/xattr.c +1 -2
@@ -2098,8 +2098,7 @@ ext4_xattr_inode_array_free(struct inode *inode,if (err)continue ;/* for inode's i_count get from ext4_xattr_delete_inode */ -if (!list_empty (&EXT4_I (ea_inode)->i_orphan)) -iput (ea_inode); +iput (ea_inode);clear_nlink (ea_inode);iput (ea_inode); }
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 9/32 ext4: extended attribute value size limit is enforced by vfs
In reply to Tahsin ErdoganEXT4_XATTR_MAX_LARGE_EA_SIZE definition in ext4 is currently unused. Besides, vfs enforces its own 64k limit which makes the 1MB limit in ext4 redundant. Remove it.
--- fs/ext4/ext4.h | 6 ------ 1 file changed, 6 deletions(-)
fs/ext4/ext4.h +0 -5
@@ -2220,12 +2220,6 @@ struct mmpd_data {*/ #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL -/* -* Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb -* This limit is arbitrary, but is reasonable for the xattr API. -*/ -#define EXT4_XATTR_MAX_LARGE_EA_SIZE (1024 * 1024)
PATCH 7/32 ext4: call journal revoke when freeing ea_inode blocks
In reply to Tahsin Erdoganea_inode contents are treated as metadata, that's why it is journaled during initial writes. Failing to call revoke during freeing could cause user data to be overwritten with original ea_inode contents during journal replay.
--- fs/ext4/extents.c | 3 ++- fs/ext4/indirect.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
fs/ext4/extents.c +2 -1
@@ -2488,7 +2488,8 @@ int ext4_ext_index_trans_blocks(struct inode *inode, int extents)static inline int get_default_free_blocks_flags (struct inode *inode) { -if (S_ISDIR (inode->i_mode) ||S_ISLNK (inode->i_mode)) +if (S_ISDIR (inode->i_mode) ||S_ISLNK (inode->i_mode) || +ext4_test_inode_flag (inode,EXT4_INODE_EA_INODE ))return EXT4_FREE_BLOCKS_METADATA |EXT4_FREE_BLOCKS_FORGET ;else if (ext4_should_journal_data (inode))return EXT4_FREE_BLOCKS_FORGET ;
fs/ext4/indirect.c +2 -1
@@ -829,7 +829,8 @@ static int ext4_clear_blocks(handle_t *handle, struct inode *inode,int flags =EXT4_FREE_BLOCKS_VALIDATED ;int err; -if (S_ISDIR (inode->i_mode) ||S_ISLNK (inode->i_mode)) +if (S_ISDIR (inode->i_mode) ||S_ISLNK (inode->i_mode) || +ext4_test_inode_flag (inode,EXT4_INODE_EA_INODE )) flags |=EXT4_FREE_BLOCKS_FORGET |EXT4_FREE_BLOCKS_METADATA ;else if (ext4_should_journal_data (inode)) flags |=EXT4_FREE_BLOCKS_FORGET ;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 12/32 ext4: add missing le32_to_cpu(e_value_inum) conversions
In reply to Tahsin ErdoganTwo places in code missed converting xattr inode number using le32_to_cpu().
--- fs/ext4/xattr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/ext4/xattr.c +5 -4
@@ -1997,6 +1997,7 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,struct ext4_inode *raw_inode;struct ext4_iloc iloc;struct ext4_xattr_entry *entry; +unsigned int ea_ino;int credits =3 , error =0 ;if (!ext4_test_inode_state (inode,EXT4_STATE_XATTR ))
@@ -2011,8 +2012,8 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode, entry = EXT4_XATTR_NEXT(entry)) {if (!entry->e_value_inum)continue ; -if (ext4_expand_ino_array (lea_ino_array, - entry->e_value_inum) !=0 ) { + ea_ino =le32_to_cpu (entry->e_value_inum); +if (ext4_expand_ino_array (lea_ino_array, ea_ino) !=0 ) {brelse (iloc.bh); goto cleanup; }
@@ -2044,8 +2045,8 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode, entry = EXT4_XATTR_NEXT(entry)) {if (!entry->e_value_inum)continue ; -if (ext4_expand_ino_array (lea_ino_array, - entry->e_value_inum) !=0 ) + ea_ino =le32_to_cpu (entry->e_value_inum); +if (ext4_expand_ino_array (lea_ino_array, ea_ino) !=0 ) goto cleanup; entry->e_value_inum =0 ; }
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 15/32 ext4: fix ext4_xattr_move_to_block()
In reply to Tahsin ErdoganWhen moving xattr entries from inline area to a xattr block, entries that refer to external xattr inodes need special handling because value data is not available in the inline area but rather should be read from its external inode.
--- fs/ext4/xattr.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
fs/ext4/xattr.c +13 -6
@@ -1658,18 +1658,16 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,struct ext4_xattr_ibody_find *is =NULL ;struct ext4_xattr_block_find *bs =NULL ;char *buffer =NULL , *b_entry_name =NULL ; -size_t value_offs, value_size; +size_t value_size =le32_to_cpu (entry->e_value_size);struct ext4_xattr_info i = { .value =NULL , .value_len =0 , .name_index = entry->e_name_index, + .in_inode = !!entry->e_value_inum, };struct ext4_xattr_ibody_header *header =IHDR (inode, raw_inode);int error; - value_offs =le16_to_cpu (entry->e_value_offs); - value_size =le32_to_cpu (entry->e_value_size); - is =kzalloc (sizeof (struct ext4_xattr_ibody_find ),GFP_NOFS ); bs =kzalloc (sizeof (struct ext4_xattr_block_find ),GFP_NOFS ); buffer =kmalloc (value_size,GFP_NOFS );
@@ -1685,7 +1683,17 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode, bs->bh =NULL ;/* Save the entry name and the entry value */ -memcpy (buffer, (void *)IFIRST (header) + value_offs, value_size); +if (entry->e_value_inum) { + error =ext4_xattr_inode_get (inode, +le32_to_cpu (entry->e_value_inum), + buffer, value_size); +if (error) + goto out; + }else { +size_t value_offs =le16_to_cpu (entry->e_value_offs); +memcpy (buffer, (void *)IFIRST (header) + value_offs, value_size); + } +memcpy (b_entry_name, entry->e_name, entry->e_name_len); b_entry_name[entry->e_name_len] ='\0' ; i.name = b_entry_name;
@@ -1703,7 +1711,6 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,if (error) goto out; - i.name = b_entry_name; i.value = buffer; i.value_len = value_size; error =ext4_xattr_block_find (inode, &i, bs);
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 16/32 ext4: fix ext4_xattr_cmp()
In reply to Tahsin ErdoganWhen a xattr entry refers to an external inode, the value data is not available in the inline area so we should not attempt to read it using value offset.
--- fs/ext4/xattr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/xattr.c +2 -1
@@ -2169,7 +2169,8 @@ ext4_xattr_cmp(struct ext4_xattr_header *header1, entry1->e_value_inum != entry2->e_value_inum || memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))return 1 ; -if (memcmp ((char *)header1 +le16_to_cpu (entry1->e_value_offs), +if (!entry1->e_value_inum && +memcmp ((char *)header1 +le16_to_cpu (entry1->e_value_offs), (char *)header2 +le16_to_cpu (entry2->e_value_offs),le32_to_cpu (entry1->e_value_size)))return 1 ;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 20/32 ext4: improve journal credit handling in set xattr paths
In reply to Tahsin ErdoganBoth ext4_set_acl() and ext4_set_context() need to be made aware of ea_inode feature when it comes to credits calculation.
Also add a sufficient credits check in ext4_xattr_set_handle() right after xattr write lock is grabbed. Original credits calculation is done outside the lock so there is a possiblity that the initially calculated credits are not sufficient anymore.
---
v2: fixed checkpatch.pl warning about replacing spaces with tab
fs/ext4/acl.c | 7 ++++--- fs/ext4/ext4_jbd2.h | 14 -------------- fs/ext4/super.c | 6 +++--- fs/ext4/xattr.c | 55 +++++++++++++++++++++++++++++++++++++++++------------ fs/ext4/xattr.h | 1 + 5 files changed, 51 insertions(+), 32 deletions(-)
fs/ext4/acl.c +4 -3
@@ -231,14 +231,15 @@ int ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type) { handle_t *handle; -int error, retries =0 ; +int error, credits, retries =0 ; +size_t acl_size = acl ?ext4_acl_size (acl->a_count) :0 ; error =dquot_initialize (inode);if (error)return error; retry: - handle =ext4_journal_start (inode,EXT4_HT_XATTR , -ext4_jbd2_credits_xattr (inode)); + credits =ext4_xattr_set_credits (inode, acl_size); + handle =ext4_journal_start (inode,EXT4_HT_XATTR , credits);if (IS_ERR (handle))return PTR_ERR (handle);
fs/ext4/ext4_jbd2.h +0 -14
@@ -104,20 +104,6 @@#define EXT4_MAXQUOTAS_INIT_BLOCKS (sb) (EXT4_MAXQUOTAS*EXT4_QUOTA_INIT_BLOCKS(sb))#define EXT4_MAXQUOTAS_DEL_BLOCKS (sb) (EXT4_MAXQUOTAS*EXT4_QUOTA_DEL_BLOCKS(sb)) -static inline int ext4_jbd2_credits_xattr (struct inode *inode) -{ -int credits =EXT4_DATA_TRANS_BLOCKS (inode->i_sb); - -/* -* In case of inline data, we may push out the data to a block, -* so we need to reserve credits for this eventuality -*/ -if (ext4_has_inline_data (inode)) - credits +=ext4_writepage_trans_blocks (inode) +1 ; -return credits; -} - -/* * Ext4 handle operation types -- for logging purposes */
fs/ext4/super.c +3 -3
@@ -1143,7 +1143,7 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, void *fs_data) {handle_t *handle = fs_data; -int res, res2, retries =0 ; +int res, res2, credits, retries =0 ; res =ext4_convert_inline_data (inode);if (res)
@@ -1178,8 +1178,8 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,if (res)return res; retry: - handle =ext4_journal_start (inode,EXT4_HT_MISC , -ext4_jbd2_credits_xattr (inode)); + credits =ext4_xattr_set_credits (inode, len); + handle =ext4_journal_start (inode,EXT4_HT_MISC , credits);if (IS_ERR (handle))return PTR_ERR (handle);
fs/ext4/xattr.c +42 -11
73 lines not on this page · raw message
PATCH 10/32 ext4: change ext4_xattr_inode_iget() signature
In reply to Tahsin ErdoganIn general, kernel functions indicate success/failure through their return values. This function returns the status as an output parameter and reserves the return value for the inode. Make it follow the general convention.
--- fs/ext4/xattr.c | 73 +++++++++++++++++++++++++++++++-------------------------- fs/ext4/xattr.h | 2 -- 2 files changed, 40 insertions(+), 35 deletions(-)
fs/ext4/xattr.c +40 -33
@@ -312,40 +312,47 @@ ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t *size)return 0 ; } -struct inode *ext4_xattr_inode_iget (struct inode *parent,unsigned long ea_ino,int *err) +static int ext4_xattr_inode_iget (struct inode *parent,unsigned long ea_ino, +struct inode **ea_inode) { -struct inode *ea_inode =NULL ; +struct inode *inode; +int err; + + inode =ext4_iget (parent->i_sb, ea_ino); +if (IS_ERR (inode)) { + err =PTR_ERR (inode); +ext4_error (parent->i_sb,"error while reading EA inode %lu " +"err=%d" , ea_ino, err); +return err; + } - ea_inode =ext4_iget (parent->i_sb, ea_ino); -if (IS_ERR (ea_inode) ||is_bad_inode (ea_inode)) { -int rc =IS_ERR (ea_inode) ?PTR_ERR (ea_inode) :0 ; +if (is_bad_inode (inode)) {ext4_error (parent->i_sb,"error while reading EA inode %lu " -"/ %d %d" , ea_ino, rc,is_bad_inode (ea_inode)); - *err = rc !=0 ? rc : -EIO ; -return NULL ; +"is_bad_inode" , ea_ino); + err = -EIO ; + goto error; } -if (EXT4_XATTR_INODE_GET_PARENT (ea_inode) != parent->i_ino || - ea_inode->i_generation != parent->i_generation) { +if (EXT4_XATTR_INODE_GET_PARENT (inode) != parent->i_ino || + inode->i_generation != parent->i_generation) {ext4_error (parent->i_sb,"Backpointer from EA inode %lu " -"to parent invalid." , ea_ino); - *err = -EINVAL ; +"to parent is invalid." , ea_ino); + err = -EINVAL ; goto error; } -if (!(EXT4_I (ea_inode)->i_flags &EXT4_EA_INODE_FL )) { +if (!(EXT4_I (inode)->i_flags &EXT4_EA_INODE_FL )) {ext4_error (parent->i_sb,"EA inode %lu does not have " "EXT4_EA_INODE_FL flag set.\n" , ea_ino); - *err = -EINVAL ; + err = -EINVAL ; goto error; } - *err =0 ; -return ea_inode; - + *ea_inode = inode; +return 0 ; error: -iput (ea_inode); -return NULL ; +iput (inode); +return err; }/*
@@ -355,17 +362,17 @@ static int ext4_xattr_inode_get(struct inode *inode, unsigned long ea_ino, void *buffer, size_t *size) { - struct inode *ea_inode = NULL; -int err; + struct inode *ea_inode; +int ret; - ea_inode =ext4_xattr_inode_iget (inode, ea_ino, &err); -if (err) -return err; + ret =ext4_xattr_inode_iget (inode, ea_ino, &ea_inode); +if (ret) +return ret; - err =ext4_xattr_inode_read (ea_inode, buffer, size); + ret =ext4_xattr_inode_read (ea_inode, buffer, size);iput (ea_inode); -return err; +return ret; } static int
@@ -868,7 +875,7 @@ int ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino)struct inode *ea_inode =NULL ;int err; - ea_inode =ext4_xattr_inode_iget (inode, ea_ino, &err); + err =ext4_xattr_inode_iget (inode, ea_ino, &ea_inode);if (err)return err;
@@ -1948,7 +1955,7 @@ static int ext4_xattr_inode_orphan_add(handle_t *handle, struct inode *inode, int credits, struct ext4_xattr_ino_array *lea_ino_array) { -struct inode *ea_inode =NULL ; +struct inode *ea_inode;int idx =0 , error =0 ;if (lea_ino_array ==NULL )
@@ -1967,8 +1974,8 @@ ext4_xattr_inode_orphan_add(handle_t *handle, struct inode *inode,return error; } } - ea_inode =ext4_xattr_inode_iget (inode, - lea_ino_array->xia_inodes[idx], &error); + error =ext4_xattr_inode_iget (inode, + lea_ino_array->xia_inodes[idx], &ea_inode);if (error)continue ;inode_lock (ea_inode);
@@ -2085,7 +2092,7 @@ void ext4_xattr_inode_array_free(struct inode *inode, struct ext4_xattr_ino_array *lea_ino_array) { - struct inode *ea_inode = NULL; + struct inode *ea_inode;int idx =0 ;int err;
@@ -2093,8 +2100,8 @@ ext4_xattr_inode_array_free(struct inode *inode,return ;for (; idx < lea_ino_array->xia_count; ++idx) { - ea_inode =ext4_xattr_inode_iget (inode, - lea_ino_array->xia_inodes[idx], &err); + err =ext4_xattr_inode_iget (inode, + lea_ino_array->xia_inodes[idx], &ea_inode);if (err)continue ;/* for inode's i_count get from ext4_xattr_delete_inode */
fs/ext4/xattr.h +0 -2
@@ -161,8 +161,6 @@ extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t);extern int ext4_xattr_set (struct inode *,int ,const char *,const void *,size_t ,int );extern int ext4_xattr_set_handle (handle_t *,struct inode *,int ,const char *,const void *,size_t ,int ); -extern struct inode *ext4_xattr_inode_iget (struct inode *parent,unsigned long ea_ino, -int *err);extern int ext4_xattr_inode_unlink (struct inode *inode,unsigned long ea_ino);extern int ext4_xattr_delete_inode (handle_t *handle,struct inode *inode,struct ext4_xattr_ino_array **array);
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 29/32 ext4: reserve space for xattr entries/names
In reply to Tahsin ErdoganNew ea_inode feature allows putting large xattr values into external inodes. struct ext4_xattr_entry and the attribute name however have to remain in the inode extra space or external attribute block. Once that space is exhausted, no further entries can be added. Some of that space could also be used by values that fit in there at the time of addition.
So, a single xattr entry whose value barely fits in the external block could prevent further entries being added.
To mitigate the problem, this patch introduces a notion of reserve in the
external attribute block that cannot be used by value data. This reserve is enforced when ea_inode feature is enabled. The amount of reserve is arbitrarily chosen to be min(block_size/8, 1024). The table below shows how much space is reserved for each block size and the guaranteed mininum
number of entries that can be placed in the external attribute block.
block size reserved bytes entries (name length = 16) 1k 128 3 2k 256 7 4k 512 15 8k 1024 31 16k 1024 31 32k 1024 31 64k 1024 31
--- fs/ext4/xattr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
fs/ext4/xattr.c +20 -0
@@ -1446,6 +1446,12 @@ static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode,return 0 ; } +/* +* Reserve min(block_size/8, 1024) bytes for xattr entries/names if ea_inode +* feature is enabled. +*/ +#define EXT4_XATTR_BLOCK_RESERVE (inode) min(i_blocksize(inode)/8, 1024U) +static int ext4_xattr_set_entry (struct ext4_xattr_info *i,struct ext4_xattr_search *s,handle_t *handle,struct inode *inode)
@@ -1505,6 +1511,20 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, ret = -ENOSPC ; goto out; } + +/* +* If storing the value in an external inode is an option, +* reserve space for xattr entries/names in the external +* attribute block so that a long value does not occupy the +* whole space and prevent futher entries being added. +*/ +if (ext4_has_feature_ea_inode (inode->i_sb) && new_size && + (s->end - s->base) ==i_blocksize (inode) && + (min_offs + old_size - new_size) < +EXT4_XATTR_BLOCK_RESERVE (inode)) { + ret = -ENOSPC ; + goto out; + } }/*
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
PATCH 31/32 ext4: strong binding of xattr inode references
In reply to Tahsin ErdoganTo verify that a xattr entry is not pointing to the wrong xattr inode, we currently check that the target inode has EXT4_EA_INODE_FL flag set and also the entry size matches the target inode size.
For stronger validation, also incorporate crc32c hash of the value into the e_hash field. This is done regardless of whether the entry lives in the inode body or external attribute block.
---
v2: naming updates to adapt to other patch changes in the series
fs/ext4/xattr.c | 104 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 39 deletions(-)
fs/ext4/xattr.c +60 -28
@@ -77,8 +77,8 @@ static void ext4_xattr_block_cache_insert(struct mb_cache *,static struct buffer_head *ext4_xattr_block_cache_find (struct inode *,struct ext4_xattr_header *,struct mb_cache_entry **); -static void ext4_xattr_hash_entry (struct ext4_xattr_entry *entry, -void *value_base); +static __le32 ext4_xattr_hash_entry (char *name,size_t name_len,__le32 *value, +size_t value_count);static void ext4_xattr_rehash (struct ext4_xattr_header *);static const struct xattr_handler *const ext4_xattr_handler_map[] = {
@@ -380,7 +380,9 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino, }static int -ext4_xattr_inode_verify_hash (struct inode *ea_inode,void *buffer,size_t size) +ext4_xattr_inode_verify_hashes (struct inode *ea_inode, +struct ext4_xattr_entry *entry,void *buffer, +size_t size) {u32 hash;
@@ -388,23 +390,35 @@ ext4_xattr_inode_verify_hash(struct inode *ea_inode, void *buffer, size_t size) hash =ext4_xattr_inode_hash (EXT4_SB (ea_inode->i_sb), buffer, size);if (hash !=ext4_xattr_inode_get_hash (ea_inode))return -EFSCORRUPTED ; + +if (entry) { +__le32 e_hash, tmp_data; + +/* Verify entry hash. */ + tmp_data =cpu_to_le32 (hash); + e_hash =ext4_xattr_hash_entry (entry->e_name, entry->e_name_len, + &tmp_data,1 ); +if (e_hash != entry->e_hash) +return -EFSCORRUPTED ; + }return 0 ; }#define EXT4_XATTR_INODE_GET_PARENT (inode) ((__u32)(inode)->i_mtime.tv_sec)/* -* Read the value from the EA inode. +* Read xattr value from the EA inode. */ static int -ext4_xattr_inode_get (struct inode *inode,unsigned long ea_ino,void *buffer, -size_t size) +ext4_xattr_inode_get (struct inode *inode,struct ext4_xattr_entry *entry, +void *buffer,size_t size) {struct mb_cache *ea_inode_cache =EA_INODE_CACHE (inode);struct inode *ea_inode;int err; - err =ext4_xattr_inode_iget (inode, ea_ino, &ea_inode); + err =ext4_xattr_inode_iget (inode,le32_to_cpu (entry->e_value_inum), + &ea_inode);if (err) { ea_inode =NULL ; goto out;
@@ -422,7 +436,7 @@ ext4_xattr_inode_get(struct inode *inode, unsigned long ea_ino, void *buffer,if (err) goto out; - err =ext4_xattr_inode_verify_hash (ea_inode, buffer, size); + err =ext4_xattr_inode_verify_hashes (ea_inode, entry, buffer, size);/* * Compatibility check for old Lustre ea_inode implementation. Old * version does not have hash validation, but it has a backpointer
@@ -489,9 +503,8 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,if (size > buffer_size) goto cleanup;if (entry->e_value_inum) { - error =ext4_xattr_inode_get (inode, -le32_to_cpu (entry->e_value_inum), - buffer, size); + error =ext4_xattr_inode_get (inode, entry, buffer, + size);if (error) goto cleanup; }else {
@@ -539,9 +552,8 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,if (size > buffer_size) goto cleanup;if (entry->e_value_inum) { - error =ext4_xattr_inode_get (inode, -le32_to_cpu (entry->e_value_inum), - buffer, size); + error =ext4_xattr_inode_get (inode, entry, buffer, + size);if (error) goto cleanup; }else {
@@ -1387,8 +1399,8 @@ ext4_xattr_inode_cache_find(struct inode *inode, const void *value, (EXT4_I(ea_inode)->i_flags & EXT4_EA_INODE_FL) && i_size_read(ea_inode) == value_len && !ext4_xattr_inode_read(ea_inode, ea_data, value_len) && - !ext4_xattr_inode_verify_hash(ea_inode, ea_data, - value_len) && + !ext4_xattr_inode_verify_hashes(ea_inode, NULL, ea_data, + value_len) && !memcmp(value, ea_data, value_len)) {mb_cache_entry_touch (ea_inode_cache, ce);mb_cache_entry_put (ea_inode_cache, ce);
@@ -1652,12 +1664,36 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, here->e_value_size =cpu_to_le32 (i->value_len); } -if (is_block) { -if (i->value) -ext4_xattr_hash_entry (here, s->base); -ext4_xattr_rehash ((struct ext4_xattr_header *)s->base); +if (i->value) { +__le32 hash =0 ; + +/* Entry hash calculation. */ +if (in_inode) { +__le32 crc32c_hash; + +/* +* Feed crc32c hash instead of the raw value for entry +* hash calculation. This is to avoid walking +* potentially long value buffer again. +*/ + crc32c_hash =cpu_to_le32 ( +ext4_xattr_inode_get_hash (new_ea_inode)); + hash =ext4_xattr_hash_entry (here->e_name, + here->e_name_len, + &crc32c_hash,1 ); + }else if (is_block) { +__le32 *value = s->base + min_offs - new_size; + + hash =ext4_xattr_hash_entry (here->e_name, + here->e_name_len, value, + new_size >>2 ); + } + here->e_hash = hash; } +if (is_block) +ext4_xattr_rehash ((struct ext4_xattr_header *)s->base); + ret =0 ; out:iput (old_ea_inode);
@@ -2439,9 +2475,7 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,/* Save the entry name and the entry value */ if (entry->e_value_inum) { - error =ext4_xattr_inode_get (inode, -le32_to_cpu (entry->e_value_inum), - buffer, value_size); + error =ext4_xattr_inode_get (inode, entry, buffer, value_size);if (error) goto out; }else {
@@ -2931,30 +2965,22 @@ ext4_xattr_block_cache_find(struct inode *inode,* * Compute the hash of an extended attribute. */ -static void ext4_xattr_hash_entry (struct ext4_xattr_entry *entry, -void *value_base) +static __le32 ext4_xattr_hash_entry (char *name,size_t name_len,__le32 *value, +size_t value_count) {__u32 hash =0 ; -char *name = entry->e_name; -int n; -for (n =0 ; n < entry->e_name_len; n++) { +while (name_len--) { hash = (hash <<NAME_HASH_SHIFT ) ^ (hash >> (8 *sizeof (hash) -NAME_HASH_SHIFT )) ^ *name++; }
Quoted 30 lines · Tahsin Erdogan
From: Andreas Dilger <[email protected]>
Large xattr support is implemented for
EXT4_FEATURE_INCOMPAT_EA_INODE.If the size of an xattr value is larger than will fit in a single external block, then the xattr value will be saved into the body of an external xattr inode.
The also helps support a larger number of xattr, since only the headers will be stored in the in-inode space or the single external block.
The inode is referenced from the xattr header via "
e_value_inum", which was formerly "e_value_block", but that field was never used. Thee_value_sizestill contains the xattr size so that listing xattrs does not need to look up the inode if the data is not accessed.struct
ext4_xattr_entry{__u8 e_name_len; /* length of name */ __u8 e_name_index; /* attribute name index */ __le16 e_value_offs; /* offset in disk block of value */ __le32 e_value_inum; /* inode in which value is stored */ __le32 e_value_size; /* size of attribute value */ __le32 e_hash; /* hash value of name and value */ char e_name[0]; /* attribute name */};
The xattr inode is marked with the
EXT4_EA_INODE_FLflag and also holds a back-reference to the owning inode in itsi_mtimefield, allowing the ext4/e2fsck to verify the correct inode is accessed.
Quoted 6 lines
Lustre-Jira: https://jira.hpdd.intel.com/browse/LU-80
Lustre-bugzilla: https://bugzilla.lustre.org/show_bug.cgi?id=4424Signed-off-by Kalpak Shah <[email protected]>Signed-off-by James Simmons <[email protected]>Signed-off-by Andreas Dilger <[email protected]>Signed-off-by Tahsin Erdogan <[email protected]>
Applied, thanks.
- Ted
Re: [PATCH 02/32] ext4: fix lockdep warning about recursive inode locking
In reply to Tahsin ErdoganQuoted 57 lines · Tahsin Erdogan
Setting a large xattr value may require writing the attribute contents to an external inode. In this case we may need to lock the xattr inode along with the parent inode. This doesn't pose a deadlock risk because xattr inodes are not directly visible to the user and their access is restricted.
Assign a lockdep subclass to xattr inode's lock.
============================================
WARNING: possible recursive locking detected
4.12.0-rc1+ #740 Not tainted
--------------------------------------------
python/1822 is trying to acquire lock:
(&sb->s_type->i_mutex_key#15){+.+...}, at: [<ffffffff804912ca>]ext4_xattr_set_entry+0x65a/0x7b0but task is already holding lock:
(&sb->s_type->i_mutex_key#15){+.+...}, at: [<ffffffff803d6687>]vfs_setxattr+0x57/0xb0other info that might help us debug this:
Possible unsafe locking scenario:CPU0 ---- lock(&sb->s_type->i_mutex_key#15); lock(&sb->s_type->i_mutex_key#15);*** DEADLOCK ***
May be due to missing lock nesting notation
4 locks held by python/1822:
#0: (sb_writers#10){.+.+.+}, at: [<ffffffff803d0eef>] mnt_want_write+0x1f/0x50 #1: (&sb->s_type->i_mutex_key#15){+.+...}, at: [<ffffffff803d6687>] vfs_setxattr+0x57/0xb0 #2: (jbd2_handle){.+.+..}, at: [<ffffffff80493f40>] start_this_handle+0xf0/0x420 #3: (&ei->xattr_sem){++++..}, at: [<ffffffff804920ba>] ext4_xattr_set_handle+0x9a/0x4f0stack backtrace: CPU: 0 PID: 1822 Comm: python Not tainted 4.12.0-rc1+ #740 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Call Trace: dump_stack+0x67/0x9e __lock_acquire+0x5f3/0x1750 lock_acquire+0xb5/0x1d0 down_write+0x2c/0x60 ext4_xattr_set_entry+0x65a/0x7b0 ext4_xattr_block_set+0x1b2/0x9b0 ext4_xattr_set_handle+0x322/0x4f0 ext4_xattr_set+0x144/0x1a0 ext4_xattr_user_set+0x34/0x40 __vfs_setxattr+0x66/0x80 __vfs_setxattr_noperm+0x69/0x1c0 vfs_setxattr+0xa2/0xb0 setxattr+0x12e/0x150 path_setxattr+0x87/0xb0 SyS_setxattr+0xf/0x20 entry_SYSCALL_64_fastpath+0x18/0xad
Quoted 1 line
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applied.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 03/32] ext4: lock inode before calling ext4_orphan_add()
In reply to Tahsin ErdoganQuoted 27 lines · Tahsin Erdogan
ext4_orphan_add()requires caller to be holding the inode lock. Add missing lock statements.WARNING: CPU: 3 PID: 1806 at fs/ext4/namei.c:2731 ext4_orphan_add+0x4e/0x240 CPU: 3 PID: 1806 Comm: python Not tainted 4.12.0-rc1+ #746 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 task: ffff880135d466c0 task.stack: ffffc900014b0000 RIP: 0010:ext4_orphan_add+0x4e/0x240 RSP: 0018:ffffc900014b3d50 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff8801348fe1f0 RCX: ffffc900014b3c64 RDX: 0000000000000000 RSI: ffff8801348fe1f0 RDI: ffff8801348fe1f0 RBP: ffffc900014b3da0 R08: 0000000000000000 R09: ffffffff80e82025 R10: 0000000000004692 R11: 000000000000468d R12: ffff880137598000 R13: ffff880137217000 R14: ffff880134ac58d0 R15: 0000000000000000 FS: 00007fc50f09e740(0000) GS:ffff88013fd80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000008bc2e0 CR3: 00000001375ac000 CR4: 00000000000006e0 Call Trace: ext4_xattr_inode_orphan_add.constprop.19+0x9d/0xf0 ext4_xattr_delete_inode+0x1c4/0x2f0 ext4_evict_inode+0x15a/0x7f0 evict+0xc0/0x1a0 iput+0x16a/0x270 do_unlinkat+0x172/0x290 SyS_unlink+0x11/0x20 entry_SYSCALL_64_fastpath+0x18/0xad
Quoted 1 line
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 04/32] ext4: do not set posix acls on xattr inodes
In reply to Tahsin ErdoganQuoted 60 lines · Tahsin Erdogan
We don't need acls on xattr inodes because they are not directly accessible from user mode.
Besides lockdep complains about recursive locking of
xattr_semas seen below.=============================================
[ INFO: possible recursive locking detected ]
4.11.0-rc8+ #402 Not tainted
---------------------------------------------
python/1894 is trying to acquire lock:(&ei->xattr_sem){++++..}, at: [<ffffffff804878a6>] ext4_xattr_get+0x66/0x270but task is already holding lock:
(&ei->xattr_sem){++++..}, at: [<ffffffff80489500>] ext4_xattr_set_handle+0xa0/0x5d0other info that might help us debug this:
Possible unsafe locking scenario:CPU0 ---- lock(&ei->xattr_sem); lock(&ei->xattr_sem);*** DEADLOCK ***
May be due to missing lock nesting notation
3 locks held by python/1894:
#0: (sb_writers#10){.+.+.+}, at: [<ffffffff803d829f>] mnt_want_write+0x1f/0x50 #1: (&sb->s_type->i_mutex_key#15){+.+...}, at: [<ffffffff803dda27>] vfs_setxattr+0x57/0xb0 #2: (&ei->xattr_sem){++++..}, at: [<ffffffff80489500>] ext4_xattr_set_handle+0xa0/0x5d0stack backtrace: CPU: 0 PID: 1894 Comm: python Not tainted 4.11.0-rc8+ #402 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Call Trace: dump_stack+0x67/0x99 __lock_acquire+0x5f3/0x1830 lock_acquire+0xb5/0x1d0 down_read+0x2f/0x60 ext4_xattr_get+0x66/0x270 ext4_get_acl+0x43/0x1e0 get_acl+0x72/0xf0 posix_acl_create+0x5e/0x170 ext4_init_acl+0x21/0xc0 __ext4_new_inode+0xffd/0x16b0 ext4_xattr_set_entry+0x5ea/0xb70 ext4_xattr_block_set+0x1b5/0x970 ext4_xattr_set_handle+0x351/0x5d0 ext4_xattr_set+0x124/0x180 ext4_xattr_user_set+0x34/0x40 __vfs_setxattr+0x66/0x80 __vfs_setxattr_noperm+0x69/0x1c0 vfs_setxattr+0xa2/0xb0 setxattr+0x129/0x160 path_setxattr+0x87/0xb0 SyS_setxattr+0xf/0x20 entry_SYSCALL_64_fastpath+0x18/0xad
Quoted 1 line
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Re: [PATCH 05/32] ext4: attach jinode after creation of xattr inode
In reply to Tahsin ErdoganQuoted 44 lines · Tahsin Erdogan
In data=ordered mode jinode needs to be attached to the xattr inode when writing data to it. Attachment normally occurs during file open for regular files. Since we are not using file interface to write to the xattr inode, the jinode attach needs to be done manually.
Otherwise the following crash occurs in data=ordered mode.
BUG: unable to handle kernel NULL pointer dereference at (null) IP: jbd2_journal_file_inode+0x37/0x110 PGD 13b3c0067 P4D 13b3c0067 PUD 137660067 PMD 0 Oops: 0000 [#1] SMP CPU: 3 PID: 1877 Comm: python Not tainted 4.12.0-rc1+ #749 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 task: ffff88010e368980 task.stack: ffffc90000374000 RIP: 0010:jbd2_journal_file_inode+0x37/0x110 RSP: 0018:ffffc90000377980 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff880123b06230 RCX: 0000000000280000 RDX: 0000000000000006 RSI: 0000000000000000 RDI: ffff88012c8585d0 RBP: ffffc900003779b0 R08: 0000000000000202 R09: 0000000000000001 R10: 0000000000000000 R11: 0000000000000400 R12: ffff8801111f81c0 R13: ffff88013b2b6800 R14: ffffc90000377ab0 R15: 0000000000000001 FS: 00007f0c99b77740(0000) GS:ffff88013fd80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000000136d91000 CR4: 00000000000006e0 Call Trace: jbd2_journal_inode_add_write+0xe/0x10 ext4_map_blocks+0x59e/0x620 ext4_xattr_set_entry+0x501/0x7d0 ext4_xattr_block_set+0x1b2/0x9b0 ext4_xattr_set_handle+0x322/0x4f0 ext4_xattr_set+0x144/0x1a0 ext4_xattr_user_set+0x34/0x40 __vfs_setxattr+0x66/0x80 __vfs_setxattr_noperm+0x69/0x1c0 vfs_setxattr+0xa2/0xb0 setxattr+0x12e/0x150 path_setxattr+0x87/0xb0 SyS_setxattr+0xf/0x20 entry_SYSCALL_64_fastpath+0x18/0xad
Quoted 1 line
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applied.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 06/32] ext4: ea_inode owner should be the same as the inode owner
In reply to Tahsin ErdoganQuoted 6 lines · Tahsin Erdogan
Quota charging is based on the ownership of the inode. Currently, the xattr inode owner is set to the caller which may be different from the parent inode owner. This is inconsistent with how quota is charged for xattr block and regular data block writes.
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Re: [PATCH 07/32] ext4: call journal revoke when freeing ea_inode blocks
In reply to Tahsin ErdoganQuoted 6 lines · Tahsin Erdogan
ea_inodecontents are treated as metadata, that's why it is journaled during initial writes. Failing to call revoke during freeing could cause user data to be overwritten with originalea_inodecontents during journal replay.Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applied.
- Ted
Re: [PATCH 08/32] ext4: fix ref counting for ea_inode
In reply to Tahsin ErdoganQuoted 11 lines · Tahsin Erdogan
The ref count on
ea_inodeis incremented byext4_xattr_inode_orphan_add()which is supposed to be decremented byext4_xattr_inode_array_free(). The decrement is conditioned on whether theea_inodeis currently on the orphan list. However, the orphan list addition only happens when journaling is enabled. In non-journaled case,r we fail to release the ref count causing an error message like below."VFS: Busy inodes after unmount of sdb. Self-destruct in 5 seconds. Have a nice day..."
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applied.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 09/32] ext4: extended attribute value size limit is enforced by vfs
In reply to Tahsin ErdoganQuoted 5 lines · Tahsin Erdogan
EXT4_XATTR_MAX_LARGE_EA_SIZEdefinition in ext4 is currently unused. Besides, vfs enforces its own 64k limit which makes the 1MB limit in ext4 redundant. Remove it.Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 10/32] ext4: change ext4_xattr_inode_iget() signature
In reply to Tahsin ErdoganQuoted 5 lines · Tahsin Erdogan
In general, kernel functions indicate success/failure through their return values. This function returns the status as an output parameter and reserves the return value for the inode. Make it follow the general convention.
Signed-off-by Tahsin Erdogan <[email protected]>
The fact that we have several conventions for error passing, is due to the long history of the ext2/3/4 code base. In the long term, I'd actually like to see us gradually move everyhing to use the ERR_PTR convention. It's a bit more efficient for the common (no error) case, and it allows us to drop an extra parameter from the function signature.
Still, it's incrementally better this way, so thanks, added to the ext4 patch queue.
- Ted
Re: [PATCH 11/32] ext4: clean up ext4_xattr_inode_get()
In reply to Tahsin ErdoganQuoted 9 lines · Tahsin Erdogan
The input and output values of *size parameter are equal on successful return from
ext4_xattr_inode_get(). On error return, the callers ignore the output value so there is no need to update it.Also check for NULL return from
ext4_bread(). If the actual xattr inode size happens to be smaller than the expected size,ext4_bread()may return NULL which would indicate data corruption.Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applied.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 12/32] ext4: add missing le32_to_cpu(e_value_inum) conversions
In reply to Tahsin ErdoganQuoted 4 lines · Tahsin Erdogan
Two places in code missed converting xattr inode number using
le32_to_cpu().Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 13/32] ext4: ext4_xattr_value_same() should return false for external data
In reply to Tahsin ErdoganQuoted 6 lines · Tahsin Erdogan
ext4_xattr_value_same()is used as a quick optimization in case the new xattr value is identical to the previous value. When xattr value is stored in a xattr inode the check becomes expensive so it is better to just assume that they are not equal.Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 14/32] ext4: fix ext4_xattr_make_inode_space() value size calculation
In reply to Tahsin ErdoganQuoted 6 lines · Tahsin Erdogan
ext4_xattr_make_inode_space()is interested in calculating the inline space used in an inode. When a xattr entry refers to an external inode the value size indicates the external inode size, not the value size in the inline area. Change the function to take this into account.Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applued.
- Ted
Re: [PATCH 15/32] ext4: fix ext4_xattr_move_to_block()
In reply to Tahsin ErdoganQuoted 6 lines · Tahsin Erdogan
When moving xattr entries from inline area to a xattr block, entries that refer to external xattr inodes need special handling because value data is not available in the inline area but rather should be read from its external inode.
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applied.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 16/32] ext4: fix ext4_xattr_cmp()
In reply to Tahsin ErdoganQuoted 5 lines · Tahsin Erdogan
When a xattr entry refers to an external inode, the value data is not available in the inline area so we should not attempt to read it using value offset.
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Re: [PATCH 17/32] ext4: fix credits calculation for xattr inode
In reply to Tahsin ErdoganQuoted 6 lines · Tahsin Erdogan
When there is no space for a value in xattr block, it may be stored in an xattr inode even if the value length is less than
EXT4_XATTR_MIN_LARGE_EA_SIZE(). So the current assumption in credits calculation is wrong.Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applied.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 18/32] ext4: retry storing value in external inode with xattr block too
In reply to Tahsin ErdoganQuoted 9 lines · Tahsin Erdogan
When value size is <=
EXT4_XATTR_MIN_LARGE_EA_SIZE(), and it doesn't fit in either inline or xattr block, a second try is made to store it in an external inode while storing the entry itself in inline area. There should also be an attempt to store the entry in xattr block.This patch adds a retry loop to do that. It also makes the caller the sole decider on whether to store a value in an external inode.
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 19/32] ext4: ext4_xattr_delete_inode() should return accurate errors
In reply to Tahsin ErdoganQuoted 4 lines · Tahsin Erdogan
In a few places the function returns without trying to pass the actual error code to the caller. Fix those.
Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Re: [PATCH 20/32] ext4: improve journal credit handling in set xattr paths
In reply to Tahsin ErdoganQuoted 9 lines · Tahsin Erdogan
Both
ext4_set_acl()andext4_set_context()need to be made aware ofea_inodefeature when it comes to credits calculation.Also add a sufficient credits check in
ext4_xattr_set_handle()right after xattr write lock is grabbed. Original credits calculation is done outside the lock so there is a possiblity that the initially calculated credits are not sufficient anymore.Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, applied.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 21/32] ext4: modify ext4_xattr_ino_array to hold struct inode *
In reply to Tahsin ErdoganQuoted 6 lines · Tahsin Erdogan
Tracking struct inode * rather than the inode number eliminates the repeated
ext4_xattr_inode_iget()call later. The second call cannot fail in practice but still requires explanation when it wants to ignore the return value. Avoid the trouble and make things simple.Signed-off-by Tahsin Erdogan <[email protected]>
Added to the ext4 patch queue, thanks.
- Ted
Re: [PATCH 22/32] ext4: move struct ext4_xattr_inode_array to xattr.h
In reply to Tahsin ErdoganQuoted 4 lines · Tahsin Erdogan
Since this is a xattr specific data structure it is cleaner to keep it in xattr header file.
Signed-off-by Tahsin Erdogan <[email protected]>
Applied, thanks.
- Ted
Theodore Ts'o
maintainerRe: [PATCH 23/32] mbcache: make mbcache naming more generic
In reply to Tahsin ErdoganQuoted 7 lines · Tahsin Erdogan
Make names more generic so that mbcache usage is not limited to block sharing. In a subsequent patch in the series
("ext4: xattr inode deduplication"), we start using the mbcache code for sharing xattr inodes. With that patch, old mb_cache_entry.e_block field could be holding either a block number or an inode number.Signed-off-by Tahsin Erdogan <[email protected]>
Thanks, added to the ext4 patch queue.
- Ted
Re: [PATCH 09/32] ext4: extended attribute value size limit is enforced by vfs
In reply to Tahsin ErdoganQuoted 3 lines · Tahsin Erdogan
EXT4_XATTR_MAX_LARGE_EA_SIZEdefinition in ext4 is currently unused. Besides, vfs enforces its own 64k limit which makes the 1MB limit in ext4 redundant. Remove it.
Just FYI I believe the 64k VFS limit exists because XFS is the only fs to allow large xattr values, and its maximum is 64k (on-disk field size limitation).
I don't know if anyone actually wants larger values? Now could be a time to have such a conversation, if anyone is so interested.
--D
Quoted 26 lines
Signed-off-by Tahsin Erdogan <[email protected]>--- fs/ext4/ext4.h | 6 ------ 1 file changed, 6 deletions(-)fs/ext4/ext4.h +0
-6@@ -2220,12 +2220,6 @@ struct mmpd_data {*/ #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL -/* -* Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb -* This limit is arbitrary, but is reasonable for the xattr API. -*/ -#define EXT4_XATTR_MAX_LARGE_EA_SIZE (1024 * 1024) -/* * Function prototypes */ Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
Re: [PATCH 09/32] ext4: extended attribute value size limit is enforced by vfs
Quoted 6 lines · Darrick J. Wong
Quoted 3 lines · Tahsin Erdogan
EXT4_XATTR_MAX_LARGE_EA_SIZEdefinition in ext4 is currently unused. Besides, vfs enforces its own 64k limit which makes the 1MB limit in ext4 redundant. Remove it.
Quoted 6 lines
Just FYI I believe the 64k VFS limit exists because XFS is the only fs to allow large xattr values, and its maximum is 64k (on-disk field size limitation).
I don't know if anyone actually wants larger values? Now could be a time to have such a conversation, if anyone is so interested.
The EXT4_XATTR_MAX_LARGE_EA_SIZE limit of 1MB was also totally arbitrary, but a reasonable upper limit for the atomic get/set interface used by xattrs. The underlying disk format could actually store xattrs of any size.
I'd think if we want to get huge xattrs that they should be handled by having separate streams (e.g. open file descriptor, ioctl/syscall to select a different stream number on that file) so that the data doesn't have to be completely rewritten any time it is modified, but streams are frowned upon by many Linux developers for security reasons so will probably be a no-go.
Cheers, Andreas
Quoted 16 lines
--D
Quoted 14 lines
Signed-off-by Tahsin Erdogan <[email protected]>---
fs/ext4/ext4.h| 6 ------1 file changed, 6 deletions(-)fs/ext4/ext4.h +0
-0@@ -2220,12 +2220,6 @@ struct mmpd_data {*/ #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL
Quoted 12 lines
Quoted 10 lines
fs/ext4/ext4.h +0
-7-/* -* Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb -* This limit is arbitrary, but is reasonable for the xattr API. -*/ -#define EXT4_XATTR_MAX_LARGE_EA_SIZE (1024 * 1024) -/* * Function prototypes */ --Quoted 2 lines
2.13.1.611.g7e3b11ae1-goog
Cheers, Andreas
Theodore Ts'o
maintainerRe: [PATCH 09/32] ext4: extended attribute value size limit is enforced by vfs
Quoted 10 lines · Andreas Dilger
The
EXT4_XATTR_MAX_LARGE_EA_SIZElimit of 1MB was also totally arbitrary, but a reasonable upper limit for the atomic get/set interface used by xattrs. The underlying disk format could actually store xattrs of any size.I'd think if we want to get huge xattrs that they should be handled by having separate streams (e.g. open file descriptor, ioctl/syscall to select a different stream number on that file) so that the data doesn't have to be completely rewritten any time it is modified, but streams are frowned upon by many Linux developers for security reasons so will probably be a no-go.
This has been discussed before. Most of the arguments (both pro and con) can be found on this thread (2016):
https://www.spinics.net/lists/linux-nfs/msg57055.html
Jeremy Allison used to pester me for alternate data stream support many years ago, but he has since completely changed his opinion on the matter:
http://www.spinics.net/lists/linux-fsdevel/msg96083.html
So if jra@ doesn't add support for this interface to Samba, the thing I'd ask is who is actually going to used such an interface; because if there aren't any user space applications lining up to use it, it's probably not worth adding it until we can find a flagship user of the proposed new API.
There are plenty of other things we could add that Jeremy has asked for, that *would* improve Samba performance. (For example, adding a mount option which provides case-insensitive lookup; the one thing that makes this hard is that while Android doesn't seem to care about I18N --- they are currently using an ascii-only tolower() in their sdcardfs hack --- Samba/Windows does care about I18N done right, so we wouldn't have to get a Unicode case folding implementation into the kernel.) So I'd argue that those are probably more interesting projects than O_XATTR support.
- Ted
Re: [PATCH 09/32] ext4: extended attribute value size limit is enforced by vfs
Quoted 21 lines · Theodore Ts'o
Quoted 10 lines · Andreas Dilger
The
EXT4_XATTR_MAX_LARGE_EA_SIZElimit of 1MB was also totally arbitrary, but a reasonable upper limit for the atomic get/set interface used by xattrs. The underlying disk format could actually store xattrs of any size.I'd think if we want to get huge xattrs that they should be handled by having separate streams (e.g. open file descriptor, ioctl/syscall to select a different stream number on that file) so that the data doesn't have to be completely rewritten any time it is modified, but streams are frowned upon by many Linux developers for security reasons so will probably be a no-go.
This has been discussed before. Most of the arguments (both pro and con) can be found on this thread (2016):
https://www.spinics.net/lists/linux-nfs/msg57055.htmlJeremy Allison used to pester me for alternate data stream support many years ago, but he has since completely changed his opinion on the matter:
Quoted 7 lines
http://www.spinics.net/lists/linux-fsdevel/msg96083.htmlSo if jra@ doesn't add support for this interface to Samba, the thing I'd ask is who is actually going to used such an interface; because if there aren't any user space applications lining up to use it, it's probably not worth adding it until we can find a flagship user of the proposed new API.
Heh, ok, that's about what I expected to hear. :)
Quoted 9 lines
There are plenty of other things we could add that Jeremy has asked for, that *would* improve Samba performance. (For example, adding a mount option which provides case-insensitive lookup; the one thing that makes this hard is that while Android doesn't seem to care about I18N --- they are currently using an ascii-only
tolower()in their sdcardfs hack --- Samba/Windows does care about I18N done right, so we wouldn't have to get a Unicode case folding implementation into the kernel.) So I'd argue that those are probably more interesting projects thanO_XATTRsupport.
--D
Quoted 2 lines
- Ted