From patchwork Fri Jun 30 03:51:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 782645 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wzMzf6b7Tz9sNV for ; Fri, 30 Jun 2017 13:52:14 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BEQ87bRK"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751776AbdF3DwN (ORCPT ); Thu, 29 Jun 2017 23:52:13 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34071 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751696AbdF3DwN (ORCPT ); Thu, 29 Jun 2017 23:52:13 -0400 Received: by mail-pf0-f194.google.com with SMTP id c24so856736pfe.1 for ; Thu, 29 Jun 2017 20:52:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=2sLBIB+LmmLwzlznGlaKx/X9vHl7rpQ7djlJUW+a3tU=; b=BEQ87bRK75Axn68SzcKZQnTYqwzGOzT/crNZUjGxhANfrOLvZCmbx98k4Xxn7T45ta SpA0v3MbpVMedMvzPrBPKV2vkoZyG8yysV4vyD5RzrVVZNEUA+guLdzfBuQj7/L7z8R/ igslIfpVgIE0yTiC6zoz8unZhZhkUiQ3h6cA2q9tYQ34deInTOMihHB6C04wHhHYgy00 l2SFYteGsMnnaqFwU6vd9PKSag4ySZJQ532HXzUWlMmS500+o2R+rARHUODhyN31+0ug icYZGyrz4RRaJ+68+1a2EJxkN2V18yzlDwnVGq7oIjBmFOaQSLma3eJhJrmzB4N5428v skGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2sLBIB+LmmLwzlznGlaKx/X9vHl7rpQ7djlJUW+a3tU=; b=T8/pWQl84ESpFKLiTOh1fYeEspJbJkVr6wmS7Gyg+L+x/ptrcj4qrDkNXfdI7rx5KU lOWQwiHOGcv1FfUdIG+HMqjo5iiLNB3zS1N2caEUmAogQG8wPAhXwoOObJQ+VAE4at1i J+F/68oZ/NbMqvfbedWH4hyub36l11F4LC2l5d/kW7mOiXNWTchsGhPGE9ZfGsBnqhJU HU8xWGenMQ3/6syzfPUCsY7JZVt6l7SXK+Fr/cIo+o/wo0CnjPRK5QPiMvF8xzjJHzqr LzvLdDd1Lg8hCmPwrxCMfdGDPHaP48IIvwFmsjLJnizOAYVkNGgKnxvyiG1tau/Y0Tl0 ciPA== X-Gm-Message-State: AKS2vOzzox9nw8tLNyzAWOCibbtmEXRm8lQU+PfS9RS/hpve7lUt9YF5 u82RR+H7+1oKNVWy X-Received: by 10.84.238.206 with SMTP id l14mr21670588pln.280.1498794732234; Thu, 29 Jun 2017 20:52:12 -0700 (PDT) Received: from localhost.localdomain ([45.76.153.63]) by smtp.gmail.com with ESMTPSA id g10sm9787167pgr.18.2017.06.29.20.52.07 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 29 Jun 2017 20:52:11 -0700 (PDT) From: Wang Shilong X-Google-Original-From: Wang Shilong To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, lixi@ddn.com, yi.zhang@huawei.com, miaoxie@huawei.com, adilger@dilger.ca, wshilong@ddn.com, sihara@ddn.com Subject: [PATCH 1/2] ext4, project: expand inode extra size if possible Date: Fri, 30 Jun 2017 11:51:48 +0800 Message-Id: <20170630035148.63305-1-wshilong@ddn.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org when upgrading from old format, try to set project id to old file first time, it will return EOVERFLOW, but if that file is dirtied(touch etc), changing project id will be allowed, this might be confusing for users, we could try to expand @i_extra_iszie here too. Reported-by: zhangyi(F) Signed-off-by: Wang Shilong --- fs/ext4/ext4.h | 3 +++ fs/ext4/inode.c | 7 +++---- fs/ext4/ioctl.c | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3219154..640f006 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2453,6 +2453,9 @@ int ext4_walk_page_buffers(handle_t *handle, int *partial, int (*fn)(handle_t *handle, struct buffer_head *bh)); +int ext4_expand_extra_isize(struct inode *inode, + unsigned int new_extra_isize, + struct ext4_iloc iloc, handle_t *handle); int do_journal_get_write_access(handle_t *handle, struct buffer_head *bh); #define FALL_BACK_TO_NONDELALLOC 1 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5cf82d0..d53fae6 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5632,10 +5632,9 @@ ext4_reserve_inode_write(handle_t *handle, struct inode *inode, * Expand an inode by new_extra_isize bytes. * Returns 0 on success or negative error number on failure. */ -static int ext4_expand_extra_isize(struct inode *inode, - unsigned int new_extra_isize, - struct ext4_iloc iloc, - handle_t *handle) +int ext4_expand_extra_isize(struct inode *inode, + unsigned int new_extra_isize, + struct ext4_iloc iloc, handle_t *handle) { struct ext4_inode *raw_inode; struct ext4_xattr_ibody_header *header; diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 0c21e22..819f59d 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -319,6 +319,7 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid) struct ext4_iloc iloc; struct ext4_inode *raw_inode; struct dquot *transfer_to[MAXQUOTAS] = { }; + bool need_expand = false; if (!ext4_has_feature_project(sb)) { if (projid != EXT4_DEF_PROJID) @@ -350,7 +351,10 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid) goto out_unlock; raw_inode = ext4_raw_inode(&iloc); - if (!EXT4_FITS_IN_INODE(raw_inode, ei, i_projid)) { + if (!EXT4_FITS_IN_INODE(raw_inode, ei, i_projid) && + !ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) { + need_expand = true; + } else if (!EXT4_FITS_IN_INODE(raw_inode, ei, i_projid)) { err = -EOVERFLOW; brelse(iloc.bh); goto out_unlock; @@ -361,12 +365,21 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid) handle = ext4_journal_start(inode, EXT4_HT_QUOTA, EXT4_QUOTA_INIT_BLOCKS(sb) + - EXT4_QUOTA_DEL_BLOCKS(sb) + 3); + EXT4_QUOTA_DEL_BLOCKS(sb) + 3 + + need_expand ? EXT4_DATA_TRANS_BLOCKS(sb) : 0); if (IS_ERR(handle)) { err = PTR_ERR(handle); goto out_unlock; } + if (need_expand) { + err = ext4_expand_extra_isize(inode, + EXT4_SB(sb)->s_want_extra_isize, + iloc, handle); + if (err) + goto out_stop; + } + err = ext4_reserve_inode_write(handle, inode, &iloc); if (err) goto out_stop;