Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp820103ybv; Fri, 7 Feb 2020 09:05:54 -0800 (PST) X-Google-Smtp-Source: APXvYqx84C9SiAfJ23gpwvpSdOhaSdWHvnkk1nxuaw3CvpJm+xdMQLwnkBETryBRfktvw2KDpaTf X-Received: by 2002:aca:44c1:: with SMTP id r184mr2594422oia.151.1581095154645; Fri, 07 Feb 2020 09:05:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581095154; cv=none; d=google.com; s=arc-20160816; b=vrlGEvHAqEME9LXYBsyJ3EI56rk7SZrsubX/fuTRSIr2d3I8JCkS18FRdmM5g/LGNJ XJ+dSDjNcJqvbe1aToLS7j/Z9XTLcxrn2rSV6rFpgEFPxCDZEjQ995RWpa1WFY89olyH uuCWE2UA/XjrTcaik+qpwXybc//zbTYcip/oYjRyGNu/Xwq8aiKGKqNIseaHbbVvxqE8 ISKM36DJbZf6sZtzf0iTey56e+xCuxHQod7MtXUzqOSg9LQW466VDVOds5kPnJkHAZqX AN9iVMG5mLcdhN6ELjw7T2OqdyruYPJ9EEv1nocGHYirsRWkY2pMYG25fJ0dLeAv/fyM OkKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nWxzKKhIpJ8XRJ4A5uzXcFbmg5f79s9X0x115kTIiWg=; b=UurolPZ0okHSe09PiNKT2l4STDQZtE55lJb9fgsX5QuffFn3Mj7ENK7AhaNi67Z4uX E+XZPi+qVto/j5pP5MoqWI3N6zAz0Rh5dway40ukung5hxMXsYl+v4FdTEZ6Brz2lUeV cbQIWBFxx+YC99mmEJ8vdYpIQkUj8Q8yJDTOtbAaHAK8YBZImEBvq1AfytfhUbwOSuvs WuT/POZorEpy9Vn9NIdTZc9tenD+iyLaYiJ0tlSoruUjj7gheIXnGknFoE6oes/b53OJ IfNFGKPev2ElxmYUOK9LPu+xzuNoZlFxBJEH1NDEsL6hqdUxP1HaOH6m9C32wrSFSQsP u7yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ERZFqZOr; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12si4024350oim.195.2020.02.07.09.05.42; Fri, 07 Feb 2020 09:05:54 -0800 (PST) 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=@kernel.org header.s=default header.b=ERZFqZOr; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727484AbgBGREb (ORCPT + 99 others); Fri, 7 Feb 2020 12:04:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:52972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726874AbgBGREa (ORCPT ); Fri, 7 Feb 2020 12:04:30 -0500 Received: from tleilax.poochiereds.net (68-20-15-154.lightspeed.rlghnc.sbcglobal.net [68.20.15.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7686521927; Fri, 7 Feb 2020 17:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581095069; bh=VLYiA3MH1A/lCTCPikOl983ZPXm4JWB1EKa7ZQ4K++8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ERZFqZOrJflJqfyYP391wT2lv0fv2F4QUwkCsVMrX5qea1T1V7FamJVwD0ODIsgXA r2JSwJytx+fq+jNyqL80QEXSzVFMkmNlH+Zl6XX9ypiXggZJ3Ssc7ZSZZPoJ4aG1bE foMynkqnumgWXTyPgV5j1Ax8pzyBfF20MNUziduw= From: Jeff Layton To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, andres@anarazel.de, willy@infradead.org, dhowells@redhat.com, hch@infradead.org, jack@suse.cz, akpm@linux-foundation.org Subject: [PATCH v3 3/3] vfs: add a new ioctl for fetching the superblock's errseq_t Date: Fri, 7 Feb 2020 12:04:23 -0500 Message-Id: <20200207170423.377931-4-jlayton@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200207170423.377931-1-jlayton@kernel.org> References: <20200207170423.377931-1-jlayton@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeff Layton Some time ago, the PostgreSQL developers mentioned that they'd like a way to tell whether there have been any writeback errors on a given filesystem without having to forcibly sync out all buffered writes. Now that we have a per-sb errseq_t that tracks whether any inode on the filesystem might have failed writeback, we can present that to userland applications via a new interface. Add a new generic fs ioctl for that purpose. This just reports the current state of the errseq_t counter with the SEEN bit masked off. Cc: Andres Freund Signed-off-by: Jeff Layton --- fs/ioctl.c | 4 ++++ include/linux/errseq.h | 1 + include/uapi/linux/fs.h | 1 + lib/errseq.c | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 7c9a5df5a597..41e991cec4c3 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -705,6 +705,10 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd, case FS_IOC_FIEMAP: return ioctl_fiemap(filp, argp); + case FS_IOC_GETFSERR: + return put_user(errseq_scrape(&inode->i_sb->s_wb_err), + (unsigned int __user *)argp); + case FIGETBSZ: /* anon_bdev filesystems may not have a block size */ if (!inode->i_sb->s_blocksize) diff --git a/include/linux/errseq.h b/include/linux/errseq.h index fc2777770768..de165623fa86 100644 --- a/include/linux/errseq.h +++ b/include/linux/errseq.h @@ -9,6 +9,7 @@ typedef u32 errseq_t; errseq_t errseq_set(errseq_t *eseq, int err); errseq_t errseq_sample(errseq_t *eseq); +errseq_t errseq_scrape(errseq_t *eseq); int errseq_check(errseq_t *eseq, errseq_t since); int errseq_check_and_advance(errseq_t *eseq, errseq_t *since); #endif diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 379a612f8f1d..c39b37fba7f9 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -214,6 +214,7 @@ struct fsxattr { #define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr) #define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX]) #define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX]) +#define FS_IOC_GETFSERR _IOR('e', 1, unsigned int) /* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) diff --git a/lib/errseq.c b/lib/errseq.c index 81f9e33aa7e7..8ded0920eed3 100644 --- a/lib/errseq.c +++ b/lib/errseq.c @@ -108,7 +108,7 @@ errseq_t errseq_set(errseq_t *eseq, int err) EXPORT_SYMBOL(errseq_set); /** - * errseq_sample() - Grab current errseq_t value. + * errseq_sample() - Grab current errseq_t value (or 0 if it hasn't been seen) * @eseq: Pointer to errseq_t to be sampled. * * This function allows callers to initialise their errseq_t variable. @@ -117,7 +117,7 @@ EXPORT_SYMBOL(errseq_set); * see it the next time it checks for an error. * * Context: Any context. - * Return: The current errseq value. + * Return: The current errseq value or 0 if it wasn't previously seen */ errseq_t errseq_sample(errseq_t *eseq) { @@ -130,6 +130,35 @@ errseq_t errseq_sample(errseq_t *eseq) } EXPORT_SYMBOL(errseq_sample); +/** + * errseq_scrape() - Grab current errseq_t value + * @eseq: Pointer to errseq_t to be sampled. + * + * This function allows callers to scrape the current value of an errseq_t. + * Unlike errseq_sample, this will always return the current value with + * the SEEN flag unset, even when the value has not yet been seen. + * + * Context: Any context. + * Return: The current errseq value with ERRSEQ_SEEN masked off + */ +errseq_t errseq_scrape(errseq_t *eseq) +{ + errseq_t old = READ_ONCE(*eseq); + + /* + * For the common case of no errors ever having been set, we can skip + * marking the SEEN bit. Once an error has been set, the value will + * never go back to zero. + */ + if (old != 0) { + errseq_t new = old | ERRSEQ_SEEN; + if (old != new) + cmpxchg(eseq, old, new); + } + return old & ~ERRSEQ_SEEN; +} +EXPORT_SYMBOL(errseq_scrape); + /** * errseq_check() - Has an error occurred since a particular sample point? * @eseq: Pointer to errseq_t value to be checked. -- 2.24.1