Received: by 10.213.65.68 with SMTP id h4csp2117442imn; Sun, 8 Apr 2018 20:08:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Nz6btAL/9uAynfS32SCAOGe1EsNuF6VFxcGvVsFrytP1BNx68iy2P/MKWu6Htp1Snw//g X-Received: by 10.99.3.140 with SMTP id 134mr23169714pgd.92.1523243309603; Sun, 08 Apr 2018 20:08:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243309; cv=none; d=google.com; s=arc-20160816; b=mSup6BGf1lseIdN4/XAaU9zmQG7Oy7UYS6jOyS5sqrC1bw28QpM9GNH0Z57K/HkC5I yUZHIbBmLfL/V+rZB+82FnH+WfUQ/Mn9rkzgupIdq7lWer1qoTfQ5rbbiDLoYAvPHKPA gWXND1uTDdejuxELaRhKa2vALn57PcdOscC8JZReZiYgoRiecMXMaTRMvCCWb0qY4H0k L1BXYk83povEUdJKXYLlwSN1x3azkwaQtFX/aam5u2WB38VnUUqvyR743u4IBFUAa2i8 4iakqgETetc/SwHrvcTnZZEUCTc+Wcl4SEgi0p1UG1EHXq9KnCPi7qszeQbrNc2fES+f ZBiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=v6A1wYuPa1TKnzafA8nwlXm6Yg9rVq3ahLcYaIDTUSU=; b=NeDyqaBVZypJEyy8h2iz9LxYn/IwIK7m2PRk1GbGqaxLPeFLh7vsVLiTWx/TEb97xe PY1tcsnGoZ7YxEJPLMXq/pBf/jOP9D301KDl9N/2hVa4b3w5hgMTxG9kDqAhYYt7BRvI wgpT6YpyrCHsmbg/dV3WG6IaFeMCvRgnxILhHyT/Y/JGdqqGiqr44M5oqNhdeqAPqk7e g1DsdmWmXIKQyL5PUnIAQU46eQyRgK4KZMOE+paV16EO2LI9Ys9hHPLQnLk1yG49p56m 3K9eYCtj6pvi+vMJE4F/38Jc+gMfYTY+O9saswVsWfq95ZSd4lLsOTUcuBqE3AY1LzCp fG5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=bP+FnN7x; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z69si12022157pfl.209.2018.04.08.20.07.53; Sun, 08 Apr 2018 20:08:29 -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=@microsoft.com header.s=selector1 header.b=bP+FnN7x; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756506AbeDIAcT (ORCPT + 98 others); Sun, 8 Apr 2018 20:32:19 -0400 Received: from mail-sn1nam01on0103.outbound.protection.outlook.com ([104.47.32.103]:45281 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756440AbeDIAcM (ORCPT ); Sun, 8 Apr 2018 20:32:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=v6A1wYuPa1TKnzafA8nwlXm6Yg9rVq3ahLcYaIDTUSU=; b=bP+FnN7xrKIiij627MMbcQvr0rzQdoyDJuxr3r+UE5ZI0ai0DXNqoOg7dE95b+Ug2vPAn15K4tnJyzyX7aJm2blqU4Qjg/0H5srWv5OjOqdMiovktxP1NkWO1sgtfDS165UsJNkeObutyAp+IZLKvFsdpHM28LAWjQjzwl4Ns6Q= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0870.namprd21.prod.outlook.com (10.167.110.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:32:07 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:32:07 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Tahsin Erdogan , Theodore Ts'o , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 200/293] ext4: change fast symlink test to not rely on i_blocks Thread-Topic: [PATCH AUTOSEL for 4.9 200/293] ext4: change fast symlink test to not rely on i_blocks Thread-Index: AQHTz5lDMhH58tsi/kqrW2TA+mvsxg== Date: Mon, 9 Apr 2018 00:25:30 +0000 Message-ID: <20180409002239.163177-200-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0870;7:vgm77yOLA1NSSBDYS7/pdb23D3OxFzqUl+zS2xHxIX0Egy/MA69B+G7RClkr6VsBCuChkm/3g3Dlp+mArHFiMYQmsp9TEWIMl1VEkHOWTn7A5aI1KpET/CR43w/W1iol1hibDrXuxw0udHoGehf0hjRo28ge31dCxI8jsi+HOU8Mh+VhoMvsHY0sFeHNjuJm1AwX40uadM5im7wFP1A66YJh0VjJ1Qi0zlNJsbtZTobctUI/uyIkp/GPyHHYe620;20:JMCeYKWyNmu9laSShd27B/4anqNBwt7uzNgnxk/JdBD73xjavjFaYtBP+mkUkndvghXm+HOfEJVRkYhIdulYLmNt1HozNw5cOEyJ/lhYwcqkJ+XnYDqKlhodnkwnmKTHot/Mk9xcpXrB5KPL6C2vjtyq6p7r3PnfsHRU+sczbbM= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 1e360685-a4e2-46d7-06fa-08d59db15351 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0870; x-ms-traffictypediagnostic: DM5PR2101MB0870: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(211936372134217)(153496737603132)(240460790083961); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231221)(944501327)(52105095)(93006095)(93001095)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0870;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0870; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(366004)(396003)(39380400002)(376002)(199004)(189003)(53936002)(2906002)(6512007)(102836004)(2616005)(76176011)(14454004)(446003)(10090500001)(11346002)(476003)(486006)(107886003)(59450400001)(2900100001)(97736004)(66066001)(6506007)(6436002)(106356001)(99286004)(105586002)(3660700001)(6116002)(86612001)(3280700002)(6666003)(2501003)(10290500003)(26005)(8676002)(8936002)(478600001)(68736007)(5250100002)(5660300001)(316002)(4326008)(72206003)(186003)(110136005)(6486002)(7736002)(25786009)(3846002)(86362001)(36756003)(22452003)(81156014)(81166006)(575784001)(305945005)(54906003)(1076002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0870;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: nN3e8HWKDOEa5eGWV8fUfgdms8ywKIfy5N4QC/uAfxGGydqyS6EI8iqheE7fN5V5wPOOcM2DkpNeLecbMvvcUZdnaMdg5BU/lTs0RKIEvu1KqCEmWQnk0X+CglOckxwx7NhsnEdHcMVVSMHH/g5Q5ESAGglI2h00KE672K780CPICKtGxgN6gMo0/53QWrONNPSLa8+uod2lH5jUS2EPQLokZk36SuGgzyrSGQ6fapndyV1LnTBOQWoqSxphKp55mFic7Cnq7NOSDBgidNT5LnC4SemgokTkZvmY6As2apAdNYxT3OYZZznRN0iKHVec0aN4st7Vu/gWF3kFSo4buSKrl+41xHyZxheiV7zontmjQX9eQW2RBP2toSKnyOUswZiGaO92xMqw+sHYei302vSYL3Hc8ksM06R0OAbvG7Y= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e360685-a4e2-46d7-06fa-08d59db15351 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:25:30.3315 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0870 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tahsin Erdogan [ Upstream commit 407cd7fb83c0ebabb490190e673d8c71ee7df97e ] ext4_inode_info->i_data is the storage area for 4 types of data: a) Extents data b) Inline data c) Block map d) Fast symlink data (symlink length < 60) Extents data case is positively identified by EXT4_INODE_EXTENTS flag. Inline data case is also obvious because of EXT4_INODE_INLINE_DATA flag. Distinguishing c) and d) however requires additional logic. This currently relies on i_blocks count. After subtracting external xattr block from i_blocks, if it is greater than 0 then we know that some data blocks exist, so there must be a block map. This logic got broken after ea_inode feature was added. That feature charges the data blocks of external xattr inodes to the referencing inode and so adds them to the i_blocks. To fix this, we could subtract ea_inode blocks by iterating through all xattr entries and then check whether remaining i_blocks count is zero. Besides being complicated, this won't change the fact that the current way of distinguishing between c) and d) is fragile. The alternative solution is to test whether i_size is less than 60 to determine fast symlink case. ext4_symlink() uses the same test to decide whether to store the symlink in i_data. There is one caveat to address before this can work though. If an inode's i_nlink is zero during eviction, its i_size is set to zero and its data is truncated. If system crashes before inode is removed from the orphan list, next boot orphan cleanup may find the inode with zero i_size. So, a symlink that had its data stored in a block may now appear to be a fast symlink. The solution used in this patch is to treat i_size =3D 0 as a non-fast symlink case. A zero sized symlink is not legal so the only time this can happen is the mentioned scenario. This is also logically correct because a i_size =3D 0 symlink has no data stored in i_data. Suggested-by: Andreas Dilger Signed-off-by: Tahsin Erdogan Signed-off-by: Theodore Ts'o Reviewed-by: Andreas Dilger Signed-off-by: Sasha Levin --- fs/ext4/inode.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 58d57c56ec62..1c6c75ad1c60 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -143,16 +143,12 @@ static int ext4_meta_trans_blocks(struct inode *inode= , int lblocks, =20 /* * Test whether an inode is a fast symlink. + * A fast symlink has its symlink data stored in ext4_inode_info->i_data. */ int ext4_inode_is_fast_symlink(struct inode *inode) { - int ea_blocks =3D EXT4_I(inode)->i_file_acl ? - EXT4_CLUSTER_SIZE(inode->i_sb) >> 9 : 0; - - if (ext4_has_inline_data(inode)) - return 0; - - return (S_ISLNK(inode->i_mode) && inode->i_blocks - ea_blocks =3D=3D 0); + return S_ISLNK(inode->i_mode) && inode->i_size && + (inode->i_size < EXT4_N_BLOCKS * 4); } =20 /* @@ -253,6 +249,16 @@ void ext4_evict_inode(struct inode *inode) =20 if (IS_SYNC(inode)) ext4_handle_sync(handle); + + /* + * Set inode->i_size to 0 before calling ext4_truncate(). We need + * special handling of symlinks here because i_size is used to + * determine whether ext4_inode_info->i_data contains symlink data or + * block mappings. Setting i_size to 0 will remove its fast symlink + * status. Erase i_data so that it becomes a valid empty block map. + */ + if (ext4_inode_is_fast_symlink(inode)) + memset(EXT4_I(inode)->i_data, 0, sizeof(EXT4_I(inode)->i_data)); inode->i_size =3D 0; err =3D ext4_mark_inode_dirty(handle, inode); if (err) { --=20 2.15.1