From patchwork Wed May 16 17:54:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10404555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B323601F7 for ; Wed, 16 May 2018 17:54:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08DA5285B7 for ; Wed, 16 May 2018 17:54:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1684285F7; Wed, 16 May 2018 17:54:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 498CA285B7 for ; Wed, 16 May 2018 17:54:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751315AbeEPRyY (ORCPT ); Wed, 16 May 2018 13:54:24 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33788 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751062AbeEPRyV (ORCPT ); Wed, 16 May 2018 13:54:21 -0400 Received: by mail-pf0-f193.google.com with SMTP id a20-v6so739342pfo.0 for ; Wed, 16 May 2018 10:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=nRRe6DfUksszx4tmNUMTcoy0y7Q0OM9V+HZym8gFQSI=; b=spaXbhI09YUnQsBDSaubHuL/ctHLOkZhbmgChhDcntjqLPhgN8yXHWOuYjoF2IcoN3 5OmnCLweJ+y/0lLdUHnBhaU+AZS+1gVFQvOEG02U18g/fXtKwHbG3QULrBMEej6RroWo vNnFP56D/QnEGz8PanoLkvA9wYR9BDa4w2iG7f1nDHdqek3XCRL3ReGe7wqc+lRcSrbQ Jrm/U9EnNjJ2ocUhWs8AwzvW8GUft4vtbz2OzcMLYX3AgKSRZM6NlUVsmTr6U5EC1gWW PstNUEJkb5O8JKxHxA8KDt/Z/T+tfOMBjDOqo2FjtrgjG6I1OEOAqDs5bVol9KzvT2m6 cEHQ== 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:in-reply-to :references:in-reply-to:references; bh=nRRe6DfUksszx4tmNUMTcoy0y7Q0OM9V+HZym8gFQSI=; b=hp39DJ/aX7OVFv6/rGu8kvBSdRTcNcdi8UsR+UbiOCv/6244OXIplJtkJXzv0vtntw AcyheAcVTXW4K7gYf1bSx8VAx5PSmV8hE8iDVo7znvYDq4S1ohTYZ+4sYtRAGaG8XQOB zNQuYUUkB3gfEFDXFZw9uMlj95EHss2M1kPyeR7W1CKeka1UxLN1WtKmBlgjSvz6SUB8 86ICEPyaZRYUI7aHh91fHGjWT2Yf+Ejh9hKY9x3m2l/J1B9eijGT1R49KEYKiQb4kqJm 2CReRXslY9zeWbuqPrTdt2b0e7/HDoxaHwF/yytcpW+bGrG7wxw33EfGN6K6ZanMpj7u WxLQ== X-Gm-Message-State: ALKqPwdEI0EO7t/8GIOwdu9bkSJ/HtSy9IniINdf8cMb8qlFvjnqJ6JS HdEPBkOH3NXRU0sJdQamlRp/eQ== X-Google-Smtp-Source: AB8JxZrfyazCdnJsIZrIKxsTfU2tioECWXT1sEeRfjucXr8Fzy27C1gsV3kmLxNHA3k6N/rgEf4Dkg== X-Received: by 2002:a62:12d4:: with SMTP id 81-v6mr1922874pfs.243.1526493261153; Wed, 16 May 2018 10:54:21 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8800:a9a9:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id f13-v6sm4134213pgs.84.2018.05.16.10.54.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 May 2018 10:54:20 -0700 (PDT) From: Omar Sandoval To: "Darrick J . Wong" , linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Jan Kara , Christoph Hellwig , Aleksei Besogonov , kernel-team@fb.com Subject: [PATCH v3 1/2] iomap: provide more useful errors for invalid swap files Date: Wed, 16 May 2018 10:54:10 -0700 Message-Id: <5299c1f79f445e89b4b1c3c6c21da6b0b8510cfb.1526493125.git.osandov@fb.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Currently, for an invalid swap file, we print the same error message regardless of the reason. This isn't very useful for an admin, who will likely want to know why exactly they can't use their swap file. So, let's add specific error messages for each reason, and also move the bdev check after the flags checks, since the latter are more fundamental. Reviewed-by: Darrick J. Wong Signed-off-by: Omar Sandoval Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/iomap.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/fs/iomap.c b/fs/iomap.c index d193390a1c20..89517442e296 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1214,26 +1214,37 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, struct iomap_swapfile_info *isi = data; int error; + /* No inline data. */ + if (iomap->flags & IOMAP_F_DATA_INLINE) { + pr_err("swapon: file is inline\n"); + return -EINVAL; + } + /* Skip holes. */ if (iomap->type == IOMAP_HOLE) goto out; - /* Only one bdev per swap file. */ - if (iomap->bdev != isi->sis->bdev) - goto err; - /* Only real or unwritten extents. */ - if (iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN) - goto err; + if (iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN) { + pr_err("swapon: file has unallocated extents\n"); + return -EINVAL; + } - /* No uncommitted metadata or shared blocks or inline data. */ - if (iomap->flags & (IOMAP_F_DIRTY | IOMAP_F_SHARED | - IOMAP_F_DATA_INLINE)) - goto err; + /* No uncommitted metadata or shared blocks. */ + if (iomap->flags & IOMAP_F_DIRTY) { + pr_err("swapon: file is not committed\n"); + return -EINVAL; + } + if (iomap->flags & IOMAP_F_SHARED) { + pr_err("swapon: file has shared extents\n"); + return -EINVAL; + } - /* No null physical addresses. */ - if (iomap->addr == IOMAP_NULL_ADDR) - goto err; + /* Only one bdev per swap file. */ + if (iomap->bdev != isi->sis->bdev) { + pr_err("swapon: file is on multiple devices\n"); + return -EINVAL; + } if (isi->iomap.length == 0) { /* No accumulated extent, so just store it. */ @@ -1250,9 +1261,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, } out: return count; -err: - pr_err("swapon: file cannot be used for swap\n"); - return -EINVAL; } /*