linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: yangerkun <yangerkun@huawei.com>
To: <linux-ext4@vger.kernel.org>
Cc: <miaoxie@huawei.com>, <houtao1@huawei.com>, <yi.zhang@huawei.com>,
	<yangerkun@huawei.com>
Subject: [PATCH 3/4] ext4: update quota information while swapping boot loader inode
Date: Thu, 10 Jan 2019 11:36:49 +0800	[thread overview]
Message-ID: <20190110033650.108403-4-yangerkun@huawei.com> (raw)
In-Reply-To: <20190110033650.108403-1-yangerkun@huawei.com>

The quota information should also be update.

Signed-off-by: yangerkun <yangerkun@huawei.com>
---
 fs/ext4/ioctl.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index fdfada3..60d406f 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -63,13 +63,14 @@ static void swap_inode_data(struct inode *inode1, struct inode *inode2)
 	loff_t isize;
 	struct ext4_inode_info *ei1;
 	struct ext4_inode_info *ei2;
+	struct inode *big_inode;
+	struct inode *small_inode;
+	qsize_t size1, size2, diff;
 
 	ei1 = EXT4_I(inode1);
 	ei2 = EXT4_I(inode2);
 
 	swap(inode1->i_version, inode2->i_version);
-	swap(inode1->i_blocks, inode2->i_blocks);
-	swap(inode1->i_bytes, inode2->i_bytes);
 	swap(inode1->i_atime, inode2->i_atime);
 	swap(inode1->i_mtime, inode2->i_mtime);
 
@@ -79,6 +80,21 @@ static void swap_inode_data(struct inode *inode1, struct inode *inode2)
 	ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS);
 	ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS);
 
+	size1 = (qsize_t)(inode1->i_blocks) * (1 << 9) + inode1->i_bytes;
+	size2 = (qsize_t)(inode2->i_blocks) * (1 << 9) + inode2->i_bytes;
+	if (size1 > size2) {
+		big_inode = inode1;
+		small_inode = inode2;
+		diff = size1 - size2;
+	} else {
+		big_inode = inode2;
+		small_inode = inode1;
+		diff = size2 - size1;
+	}
+
+	dquot_alloc_space_nofail(small_inode, diff);
+	dquot_free_space(big_inode, diff);
+
 	isize = i_size_read(inode1);
 	i_size_write(inode1, i_size_read(inode2));
 	i_size_write(inode2, isize);
@@ -180,6 +196,14 @@ static long swap_inode_boot_loader(struct super_block *sb,
 			memset(ei_bl->i_data, 0, sizeof(ei_bl->i_data));
 	}
 
+	err = dquot_initialize(inode);
+	if (err)
+		goto err_out1;
+
+	err = dquot_initialize(inode_bl);
+	if (err)
+		goto err_out1;
+
 	swap_inode_data(inode, inode_bl);
 
 	inode->i_ctime = inode_bl->i_ctime = current_time(inode);
@@ -211,6 +235,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
 			ext4_mark_inode_dirty(handle, inode_bl);
 		}
 	}
+err_out1:
 	ext4_journal_stop(handle);
 	ext4_double_up_write_data_sem(inode, inode_bl);
 
-- 
2.9.5

  parent reply	other threads:[~2019-01-10  3:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-10  3:36 [PATCH 0/4] fix bugs for ioctl EXT4_IOC_SWAP_BOOT yangerkun
2019-01-10  3:36 ` [PATCH 1/4] ext4: fix check of inode in swap_inode_boot_loader yangerkun
2019-01-10  3:36 ` [PATCH 2/4] ext4: cleanup pagecache before swap i_data yangerkun
2019-01-10  3:36 ` yangerkun [this message]
2019-01-10  3:36 ` [PATCH 4/4] ext4: add mask of ext4 flags to swap yangerkun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190110033650.108403-4-yangerkun@huawei.com \
    --to=yangerkun@huawei.com \
    --cc=houtao1@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=miaoxie@huawei.com \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).