Skip to content

Commit fdd0a94

Browse files
committed
Merge tag 'ext4_for_linus-5.12-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 fixes from Ted Ts'o: "Fix some ext4 bugs and regressions relating to oneline resize and fast commits" * tag 'ext4_for_linus-5.12-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext4: fix off by one issue in alloc_flex_gd() ext4: mark fc as ineligible using an handle in ext4_xattr_set() ext4: use handle to mark fc as ineligible in __track_dentry_update()
2 parents 7c50f22 + 6121258 commit fdd0a94

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

fs/ext4/fast_commit.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
379379
*/
380380
static int ext4_fc_track_template(
381381
handle_t *handle, struct inode *inode,
382-
int (*__fc_track_fn)(struct inode *, void *, bool),
382+
int (*__fc_track_fn)(handle_t *handle, struct inode *, void *, bool),
383383
void *args, int enqueue)
384384
{
385385
bool update = false;
@@ -396,7 +396,7 @@ static int ext4_fc_track_template(
396396
ext4_fc_reset_inode(inode);
397397
ei->i_sync_tid = tid;
398398
}
399-
ret = __fc_track_fn(inode, args, update);
399+
ret = __fc_track_fn(handle, inode, args, update);
400400
mutex_unlock(&ei->i_fc_lock);
401401

402402
if (!enqueue)
@@ -420,7 +420,8 @@ struct __track_dentry_update_args {
420420
};
421421

422422
/* __track_fn for directory entry updates. Called with ei->i_fc_lock. */
423-
static int __track_dentry_update(struct inode *inode, void *arg, bool update)
423+
static int __track_dentry_update(handle_t *handle, struct inode *inode,
424+
void *arg, bool update)
424425
{
425426
struct ext4_fc_dentry_update *node;
426427
struct ext4_inode_info *ei = EXT4_I(inode);
@@ -435,14 +436,14 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
435436

436437
if (IS_ENCRYPTED(dir)) {
437438
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_ENCRYPTED_FILENAME,
438-
NULL);
439+
handle);
439440
mutex_lock(&ei->i_fc_lock);
440441
return -EOPNOTSUPP;
441442
}
442443

443444
node = kmem_cache_alloc(ext4_fc_dentry_cachep, GFP_NOFS);
444445
if (!node) {
445-
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL);
446+
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
446447
mutex_lock(&ei->i_fc_lock);
447448
return -ENOMEM;
448449
}
@@ -454,7 +455,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
454455
node->fcd_name.name = kmalloc(dentry->d_name.len, GFP_NOFS);
455456
if (!node->fcd_name.name) {
456457
kmem_cache_free(ext4_fc_dentry_cachep, node);
457-
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL);
458+
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
458459
mutex_lock(&ei->i_fc_lock);
459460
return -ENOMEM;
460461
}
@@ -576,7 +577,8 @@ void ext4_fc_track_create(handle_t *handle, struct dentry *dentry)
576577
}
577578

578579
/* __track_fn for inode tracking */
579-
static int __track_inode(struct inode *inode, void *arg, bool update)
580+
static int __track_inode(handle_t *handle, struct inode *inode, void *arg,
581+
bool update)
580582
{
581583
if (update)
582584
return -EEXIST;
@@ -614,7 +616,8 @@ struct __track_range_args {
614616
};
615617

616618
/* __track_fn for tracking data updates */
617-
static int __track_range(struct inode *inode, void *arg, bool update)
619+
static int __track_range(handle_t *handle, struct inode *inode, void *arg,
620+
bool update)
618621
{
619622
struct ext4_inode_info *ei = EXT4_I(inode);
620623
ext4_lblk_t oldstart;

fs/ext4/resize.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,34 +230,36 @@ struct ext4_new_flex_group_data {
230230
#define MAX_RESIZE_BG 16384
231231

232232
/*
233-
* alloc_flex_gd() allocates a ext4_new_flex_group_data with size of
234-
* @flexbg_size.
233+
* alloc_flex_gd() allocates an ext4_new_flex_group_data that satisfies the
234+
* resizing from @o_group to @n_group, its size is typically @flexbg_size.
235235
*
236236
* Returns NULL on failure otherwise address of the allocated structure.
237237
*/
238238
static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned int flexbg_size,
239239
ext4_group_t o_group, ext4_group_t n_group)
240240
{
241241
ext4_group_t last_group;
242+
unsigned int max_resize_bg;
242243
struct ext4_new_flex_group_data *flex_gd;
243244

244245
flex_gd = kmalloc(sizeof(*flex_gd), GFP_NOFS);
245246
if (flex_gd == NULL)
246247
goto out3;
247248

248-
if (unlikely(flexbg_size > MAX_RESIZE_BG))
249-
flex_gd->resize_bg = MAX_RESIZE_BG;
250-
else
251-
flex_gd->resize_bg = flexbg_size;
249+
max_resize_bg = umin(flexbg_size, MAX_RESIZE_BG);
250+
flex_gd->resize_bg = max_resize_bg;
252251

253252
/* Avoid allocating large 'groups' array if not needed */
254253
last_group = o_group | (flex_gd->resize_bg - 1);
255254
if (n_group <= last_group)
256-
flex_gd->resize_bg = 1 << fls(n_group - o_group + 1);
255+
flex_gd->resize_bg = 1 << fls(n_group - o_group);
257256
else if (n_group - last_group < flex_gd->resize_bg)
258-
flex_gd->resize_bg = 1 << max(fls(last_group - o_group + 1),
257+
flex_gd->resize_bg = 1 << max(fls(last_group - o_group),
259258
fls(n_group - last_group));
260259

260+
if (WARN_ON_ONCE(flex_gd->resize_bg > max_resize_bg))
261+
flex_gd->resize_bg = max_resize_bg;
262+
261263
flex_gd->groups = kmalloc_array(flex_gd->resize_bg,
262264
sizeof(struct ext4_new_group_data),
263265
GFP_NOFS);

fs/ext4/xattr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2559,14 +2559,15 @@ ext4_xattr_set(struct inode *inode, int name_index, const char *name,
25592559

25602560
error = ext4_xattr_set_handle(handle, inode, name_index, name,
25612561
value, value_len, flags);
2562+
ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_XATTR,
2563+
handle);
25622564
error2 = ext4_journal_stop(handle);
25632565
if (error == -ENOSPC &&
25642566
ext4_should_retry_alloc(sb, &retries))
25652567
goto retry;
25662568
if (error == 0)
25672569
error = error2;
25682570
}
2569-
ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_XATTR, NULL);
25702571

25712572
return error;
25722573
}

0 commit comments

Comments
 (0)