From patchwork Mon Jul 17 12:50:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tahsin Erdogan X-Patchwork-Id: 789456 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 3xB3744F57z9s82 for ; Mon, 17 Jul 2017 22:50:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="rs3wkNkU"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751401AbdGQMuj (ORCPT ); Mon, 17 Jul 2017 08:50:39 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:33709 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751290AbdGQMuj (ORCPT ); Mon, 17 Jul 2017 08:50:39 -0400 Received: by mail-pf0-f175.google.com with SMTP id e26so8205513pfd.0 for ; Mon, 17 Jul 2017 05:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=gJbBYn60B8ly15IDnY4KiLPNzg1UhXrbEiYkljZr3LM=; b=rs3wkNkUFyHju6rIU6lqP5TAV0/iZI6iBc2Pxsi4NPFDZFPs+kq+iCMGI7pE5ULQjI E0kIAdPfh7Um+V9n1vJ05ebePzfyTcjQh0wZlTItTrQdbt4mohGm4EsH2aSX2NttgWn7 fUO63G9/XVmPm3mie7dzvo+7W91rpKpbSheO7LoQExm13KbrRxTHVhLD1PsHYXAR2URd 44bfHTVTwj3i6Jvw70sX2+nJZPZ7iG7W6ZVYB1T+hA5bojzjQrInWw6gnuKvUc9KFJw3 n8ujNreH4g4t+h6CxVMQAx41PHsoIQPF35SdpjFBTrDAbrRqcMCoIv1COY16kzubpyRB t8Ng== 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=gJbBYn60B8ly15IDnY4KiLPNzg1UhXrbEiYkljZr3LM=; b=mVH32d01b1yYcGl7ehGmBLe6ya4B6HpzHzZpR2uH/dQZGrGO/AjLwFpQlVAitAmEXn 01rsBmwn/0bc2EvQHK/Vn2hYwRWvId3NPVDTVi+hXFAd6cyozCT2s3zki+jq/mY6jFX7 7nKQz54dgCX9QHQRAizlhLNuUioAVoaBPrhbCy75L546NxrzUrpRHFTr8ouGp0AeTjTa p8F4LIAttTRAy0Z3GYnVCxHT2Il3CyrzW282w/6qylBLKHKyadClDYaBPsaKPfu3fOB8 WyKFoUNRHCUa0DmrF4AVVfKp827XqZLPamqmdBBPD+sCJqJh7Tnhb55Cx2TYvIpDxnl2 wyXA== X-Gm-Message-State: AIVw112EmTRZ0Puwbxwg55/DXyJXM6nbdBkV/R1X9T2ooy6NnwCGUnpk 5IUpBIT+tq0EB4yr X-Received: by 10.98.236.78 with SMTP id k75mr6025990pfh.215.1500295838329; Mon, 17 Jul 2017 05:50:38 -0700 (PDT) Received: from tahsin1.svl.corp.google.com ([100.123.230.167]) by smtp.gmail.com with ESMTPSA id h90sm43435915pfh.133.2017.07.17.05.50.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:50:37 -0700 (PDT) From: Tahsin Erdogan To: Theodore Ts'o , Andreas Dilger , linux-ext4@vger.kernel.org Cc: Tahsin Erdogan Subject: [PATCH] e2fsck: eliminate bad update link count attempt Date: Mon, 17 Jul 2017 05:50:35 -0700 Message-Id: <20170717125035.12852-1-tahsin@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Extended attribute inodes have a link count of 1 but they are not attached to any directories. When an xattr inode with zero ea references is found, the remedy is to reconnect it to lost+found dir. Since reconnect operation increments the link count, it would normally become 2 but to avoid that, check_ea_inode() sets the link count to zero in anticipation of reconnect operation. And it does it even when e2fsck is invoked with -n option which causes a fatal e2fsck failure as can be demonstrated with the following test script: mke2fs -b 4096 -I 256 -F -O extent,ea_inode /dev/sdb 1G mount /dev/sdb /mnt/sdb touch /mnt/sdb/x setfattr -n user.ie1 -v $(python -c "print 'v'*5000") /mnt/sdb/x umount /dev/sdb debugfs -w -R 'rm x' /dev/sdb e2fsck -f -n /dev/sdb In this case, e2fsck fails with the following error: e2fsck 1.43.5-WIP (17-Feb-2017) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts ext2fs_write_inode: Attempt to write to filesystem opened read-only while writing inode 13 in check_ea_inode e2fsck: aborted Setting link count to zero is not really required because e2fsck will detect the discrepancy in link count and offer to fix it. Signed-off-by: Tahsin Erdogan --- e2fsck/pass4.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/e2fsck/pass4.c b/e2fsck/pass4.c index 663f87ab59c0..b23347cdb6b0 100644 --- a/e2fsck/pass4.c +++ b/e2fsck/pass4.c @@ -122,17 +122,8 @@ static void check_ea_inode(e2fsck_t ctx, ext2_ino_t i, if (ctx->ea_inode_refs) ea_refcount_fetch(ctx->ea_inode_refs, i, &actual_refs); - if (!actual_refs) { - /* - * There are no attribute references to the ea_inode. - * Zero the link count so that when inode is linked to - * lost+found it has correct link count. - */ - inode->i_links_count = 0; - e2fsck_write_inode(ctx, i, EXT2_INODE(inode), "check_ea_inode"); - ext2fs_icount_store(ctx->inode_link_info, i, 0); + if (!actual_refs) return; - } /* * There are some attribute references, link_counted is now considered