Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afd4672d authored by Theodore Ts'o's avatar Theodore Ts'o
Browse files

ext4: Add auto_da_alloc mount option



Add a mount option which allows the user to disable automatic
allocation of blocks whose allocation by delayed allocation when the
file was originally truncated or when the file is renamed over an
existing file.  This feature is intended to save users from the
effects of naive application writers, but it reduces the effectiveness
of the delayed allocation code.  This mount option disables this
safety feature, which may be desirable for prodcutions systems where
the risk of unclean shutdowns or unexpected system crashes is low.

Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 7d39db14
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -549,7 +549,7 @@ do { \
#define EXT4_MOUNT_NO_UID32		0x02000  /* Disable 32-bit UIDs */
#define EXT4_MOUNT_NO_UID32		0x02000  /* Disable 32-bit UIDs */
#define EXT4_MOUNT_XATTR_USER		0x04000	/* Extended user attributes */
#define EXT4_MOUNT_XATTR_USER		0x04000	/* Extended user attributes */
#define EXT4_MOUNT_POSIX_ACL		0x08000	/* POSIX Access Control Lists */
#define EXT4_MOUNT_POSIX_ACL		0x08000	/* POSIX Access Control Lists */
#define EXT4_MOUNT_RESERVATION		0x10000	/* Preallocation */
#define EXT4_MOUNT_NO_AUTO_DA_ALLOC	0x10000	/* No auto delalloc mapping */
#define EXT4_MOUNT_BARRIER		0x20000 /* Use block barriers */
#define EXT4_MOUNT_BARRIER		0x20000 /* Use block barriers */
#define EXT4_MOUNT_NOBH			0x40000 /* No bufferheads */
#define EXT4_MOUNT_NOBH			0x40000 /* No bufferheads */
#define EXT4_MOUNT_QUOTA		0x80000 /* Some quota option set */
#define EXT4_MOUNT_QUOTA		0x80000 /* Some quota option set */
+1 −1
Original line number Original line Diff line number Diff line
@@ -3908,7 +3908,7 @@ void ext4_truncate(struct inode *inode)
	if (!ext4_can_truncate(inode))
	if (!ext4_can_truncate(inode))
		return;
		return;


	if (inode->i_size == 0)
	if (inode->i_size == 0 && !test_opt(inode->i_sb, NO_AUTO_DA_ALLOC))
		ei->i_state |= EXT4_STATE_DA_ALLOC_CLOSE;
		ei->i_state |= EXT4_STATE_DA_ALLOC_CLOSE;


	if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) {
	if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) {
+2 −1
Original line number Original line Diff line number Diff line
@@ -2497,6 +2497,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
		ext4_mark_inode_dirty(handle, new_inode);
		ext4_mark_inode_dirty(handle, new_inode);
		if (!new_inode->i_nlink)
		if (!new_inode->i_nlink)
			ext4_orphan_add(handle, new_inode);
			ext4_orphan_add(handle, new_inode);
		if (!test_opt(new_dir->i_sb, NO_AUTO_DA_ALLOC))
			force_da_alloc = 1;
			force_da_alloc = 1;
	}
	}
	retval = 0;
	retval = 0;
+13 −12
Original line number Original line Diff line number Diff line
@@ -816,8 +816,6 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
	if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL))
	if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL))
		seq_puts(seq, ",noacl");
		seq_puts(seq, ",noacl");
#endif
#endif
	if (!test_opt(sb, RESERVATION))
		seq_puts(seq, ",noreservation");
	if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
	if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
		seq_printf(seq, ",commit=%u",
		seq_printf(seq, ",commit=%u",
			   (unsigned) (sbi->s_commit_interval / HZ));
			   (unsigned) (sbi->s_commit_interval / HZ));
@@ -868,6 +866,9 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
	if (test_opt(sb, DATA_ERR_ABORT))
	if (test_opt(sb, DATA_ERR_ABORT))
		seq_puts(seq, ",data_err=abort");
		seq_puts(seq, ",data_err=abort");


	if (test_opt(sb, NO_AUTO_DA_ALLOC))
		seq_puts(seq, ",auto_da_alloc=0");

	ext4_show_quota_options(seq, sb);
	ext4_show_quota_options(seq, sb);
	return 0;
	return 0;
}
}
@@ -1017,7 +1018,7 @@ enum {
	Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
	Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
	Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov,
	Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov,
	Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
	Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
	Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh,
	Opt_auto_da_alloc, Opt_noload, Opt_nobh, Opt_bh,
	Opt_commit, Opt_min_batch_time, Opt_max_batch_time,
	Opt_commit, Opt_min_batch_time, Opt_max_batch_time,
	Opt_journal_update, Opt_journal_dev,
	Opt_journal_update, Opt_journal_dev,
	Opt_journal_checksum, Opt_journal_async_commit,
	Opt_journal_checksum, Opt_journal_async_commit,
@@ -1052,8 +1053,6 @@ static const match_table_t tokens = {
	{Opt_nouser_xattr, "nouser_xattr"},
	{Opt_nouser_xattr, "nouser_xattr"},
	{Opt_acl, "acl"},
	{Opt_acl, "acl"},
	{Opt_noacl, "noacl"},
	{Opt_noacl, "noacl"},
	{Opt_reservation, "reservation"},
	{Opt_noreservation, "noreservation"},
	{Opt_noload, "noload"},
	{Opt_noload, "noload"},
	{Opt_nobh, "nobh"},
	{Opt_nobh, "nobh"},
	{Opt_bh, "bh"},
	{Opt_bh, "bh"},
@@ -1088,6 +1087,7 @@ static const match_table_t tokens = {
	{Opt_nodelalloc, "nodelalloc"},
	{Opt_nodelalloc, "nodelalloc"},
	{Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
	{Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
	{Opt_journal_ioprio, "journal_ioprio=%u"},
	{Opt_journal_ioprio, "journal_ioprio=%u"},
	{Opt_auto_da_alloc, "auto_da_alloc=%u"},
	{Opt_err, NULL},
	{Opt_err, NULL},
};
};


@@ -1220,12 +1220,6 @@ static int parse_options(char *options, struct super_block *sb,
			       "not supported\n");
			       "not supported\n");
			break;
			break;
#endif
#endif
		case Opt_reservation:
			set_opt(sbi->s_mount_opt, RESERVATION);
			break;
		case Opt_noreservation:
			clear_opt(sbi->s_mount_opt, RESERVATION);
			break;
		case Opt_journal_update:
		case Opt_journal_update:
			/* @@@ FIXME */
			/* @@@ FIXME */
			/* Eventually we will want to be able to create
			/* Eventually we will want to be able to create
@@ -1491,6 +1485,14 @@ static int parse_options(char *options, struct super_block *sb,
			*journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE,
			*journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE,
							    option);
							    option);
			break;
			break;
		case Opt_auto_da_alloc:
			if (match_int(&args[0], &option))
				return 0;
			if (option)
				clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC);
			else
				set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC);
			break;
		default:
		default:
			printk(KERN_ERR
			printk(KERN_ERR
			       "EXT4-fs: Unrecognized mount option \"%s\" "
			       "EXT4-fs: Unrecognized mount option \"%s\" "
@@ -2306,7 +2308,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
	sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
	sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
	sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
	sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;


	set_opt(sbi->s_mount_opt, RESERVATION);
	set_opt(sbi->s_mount_opt, BARRIER);
	set_opt(sbi->s_mount_opt, BARRIER);


	/*
	/*