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: 10404557 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 EBE5C601F7 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 DB194285B7 for ; Wed, 16 May 2018 17:54:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF9F2285F7; Wed, 16 May 2018 17:54:26 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 7E759285B7 for ; Wed, 16 May 2018 17:54:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751096AbeEPRyY (ORCPT ); Wed, 16 May 2018 13:54:24 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:44777 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751130AbeEPRyV (ORCPT ); Wed, 16 May 2018 13:54:21 -0400 Received: by mail-pf0-f195.google.com with SMTP id q22-v6so728203pff.11 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=I+mq5+PUDc0kfnocrrlFTB6iHMMdVaEtQc5a3NJlJMJzTZqjhnsxXq8T9gqb/aUywz IFnn4KBHw+lE/cSSwn8kv97IYhWgSDJEwo1EmJbRYk5IRVGx2pu+yCStCTUtQr4CQT1M eKhI/uDgTlyxN2pReCxp/LiC46VhqmucJrfphspl+alzy58Xq3ec+jYHuZ02J+4UMD2r HEPa6Zz+Ing1Afg27LT6spPHQj5/+yPW5Vrjv7lFaUH0ELhUotG3orpDTztCbEpWCWr0 /pbYGPfqCOeyXoH0ymSgMjNu8P4kzC0rGMcdKWWQGfkrZ2aTm6SvsGg7ak8w6jd1YuGb 6IKA== X-Gm-Message-State: ALKqPwf7kgc6uJxQ5YruCLyombaulc8Rc1i+6r0jCBgzYVspJCYsBeVm XG9liejMiG4SxtiWYXrnBJhLoQ== 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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; } /*