Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp620651img; Fri, 22 Mar 2019 05:18:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyr3TXUntWNhmnOX1RxT3PW7bC5dFgZadp1yX/o5TkCXL1yBVASa+fuYN9ZGYUY9eBvpKvs X-Received: by 2002:a17:902:380c:: with SMTP id l12mr9284186plc.238.1553257126721; Fri, 22 Mar 2019 05:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257126; cv=none; d=google.com; s=arc-20160816; b=B5UFgrUlXx4jiShX4gJdvTQSuV/ZtcILSMC7UfW4z5YG18FBGvWULhelht77fAqW/y GZhmF8Pv76qxfiGqu4zW/gm3WqcuHP0n8jfWwx0wBFTdBt4XHYx9o1uoJdBWUqideeiJ Yxpz1bLqBs2o0W/gfmkhWpKSjf4sW8rrUdmDErZRKqBRheYoEYZ6NIWMXmpEIJkoQAb1 ERoK10Yyx1Ikt/JM3mnJSgZjlFUyoXHy9/CWmEcyLTidq+uwY2+bwSAPxWvJpODj3XVq sND8Ry8ZxehQ9WSdM0EnM2or4VsDhm5z5VUMpGGHMzqXxX6e40DRbmlzk+ATKxVzil67 qpnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tThFxq+SrlEYo3uried+SD9nGwBx0A2LgHzLFCq9H7M=; b=PDb+A7B+mGJTw19V5vv71oP2+nEi1E1t+e61Dr34mlNDLuMQu34pAqnr5k6I8Op3nL NJ61WbBP+vnlmZbg0AvA4n/DMrT7+Y5iJHVQgvCTL6U+0WhTQa7yrWCkNhgBktA/mZrT xUAgxhMobgrnOtEMRrdRSQgTxgUfWYnEJv6OGlCkylPvvVyei7jAQPpFn9Gj+l2sehGi VnYVPRFz4N2Tl4H16ZXpfVpiHViyH74/RXEPSdJGSOQDTjTaTTht4hJQlkBtAnzSRwiP EbArAFDtumHIqBYiTrXpSTv5dWgW1k8XP1OHTsEr3EmIly8+2cyR5LY8y7uFGmlXuwac H4pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qzY2KOsp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11si6482707pfc.39.2019.03.22.05.18.31; Fri, 22 Mar 2019 05:18:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qzY2KOsp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390426AbfCVMRw (ORCPT + 99 others); Fri, 22 Mar 2019 08:17:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:56752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389940AbfCVMRu (ORCPT ); Fri, 22 Mar 2019 08:17:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4693B2082C; Fri, 22 Mar 2019 12:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257069; bh=Hx0bkBdvuhlnnCiHmrgqAIyv2QbbSqanMWsD7GZ2mmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qzY2KOspswp81ZDev/gHofKBKm5VzS00NWnxfr8NkFcI2ocn+NbaCTaabUD1WqyHq 8JpPW4yrk1INW8IwWwCnFjNylWCL4KxhB/2kY/3+HIuZnsrhHojAxSIG0lCDzTHt+8 6+mz/fYZBNvTM71bgkDC8rGIgyfkh3ZJvNWU3yWw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, yangerkun , Theodore Tso , stable@kernel.org Subject: [PATCH 5.0 121/238] ext4: update quota information while swapping boot loader inode Date: Fri, 22 Mar 2019 12:15:40 +0100 Message-Id: <20190322111305.677644877@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: yangerkun commit aa507b5faf38784defe49f5e64605ac3c4425e26 upstream. While do swap between two inode, they swap i_data without update quota information. Also, swap_inode_boot_loader can do "revert" somtimes, so update the quota while all operations has been finished. Signed-off-by: yangerkun Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/ioctl.c | 56 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 13 deletions(-) --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -68,8 +68,6 @@ static void swap_inode_data(struct inode 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); @@ -115,6 +113,9 @@ static long swap_inode_boot_loader(struc int err; struct inode *inode_bl; struct ext4_inode_info *ei_bl; + qsize_t size, size_bl, diff; + blkcnt_t blocks; + unsigned short bytes; inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO, EXT4_IGET_SPECIAL); if (IS_ERR(inode_bl)) @@ -180,6 +181,13 @@ static long swap_inode_boot_loader(struc memset(ei_bl->i_data, 0, sizeof(ei_bl->i_data)); } + err = dquot_initialize(inode); + if (err) + goto err_out1; + + size = (qsize_t)(inode->i_blocks) * (1 << 9) + inode->i_bytes; + size_bl = (qsize_t)(inode_bl->i_blocks) * (1 << 9) + inode_bl->i_bytes; + diff = size - size_bl; swap_inode_data(inode, inode_bl); inode->i_ctime = inode_bl->i_ctime = current_time(inode); @@ -193,24 +201,46 @@ static long swap_inode_boot_loader(struc err = ext4_mark_inode_dirty(handle, inode); if (err < 0) { + /* No need to update quota information. */ ext4_warning(inode->i_sb, "couldn't mark inode #%lu dirty (err %d)", inode->i_ino, err); /* Revert all changes: */ swap_inode_data(inode, inode_bl); ext4_mark_inode_dirty(handle, inode); - } else { - err = ext4_mark_inode_dirty(handle, inode_bl); - if (err < 0) { - ext4_warning(inode_bl->i_sb, - "couldn't mark inode #%lu dirty (err %d)", - inode_bl->i_ino, err); - /* Revert all changes: */ - swap_inode_data(inode, inode_bl); - ext4_mark_inode_dirty(handle, inode); - ext4_mark_inode_dirty(handle, inode_bl); - } + goto err_out1; + } + + blocks = inode_bl->i_blocks; + bytes = inode_bl->i_bytes; + inode_bl->i_blocks = inode->i_blocks; + inode_bl->i_bytes = inode->i_bytes; + err = ext4_mark_inode_dirty(handle, inode_bl); + if (err < 0) { + /* No need to update quota information. */ + ext4_warning(inode_bl->i_sb, + "couldn't mark inode #%lu dirty (err %d)", + inode_bl->i_ino, err); + goto revert; + } + + /* Bootloader inode should not be counted into quota information. */ + if (diff > 0) + dquot_free_space(inode, diff); + else + err = dquot_alloc_space(inode, -1 * diff); + + if (err < 0) { +revert: + /* Revert all changes: */ + inode_bl->i_blocks = blocks; + inode_bl->i_bytes = bytes; + swap_inode_data(inode, inode_bl); + ext4_mark_inode_dirty(handle, inode); + ext4_mark_inode_dirty(handle, inode_bl); } + +err_out1: ext4_journal_stop(handle); ext4_double_up_write_data_sem(inode, inode_bl);