From patchwork Tue Nov 16 22:07:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 12623247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB19BC433F5 for ; Tue, 16 Nov 2021 22:09:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D615611AF for ; Tue, 16 Nov 2021 22:09:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4D615611AF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B6CD66B0074; Tue, 16 Nov 2021 17:08:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B1D2A6B007D; Tue, 16 Nov 2021 17:08:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E44F6B007E; Tue, 16 Nov 2021 17:08:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 908BE6B0074 for ; Tue, 16 Nov 2021 17:08:12 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 57A787DCB9 for ; Tue, 16 Nov 2021 22:08:02 +0000 (UTC) X-FDA: 78816182004.18.47990D3 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf28.hostedemail.com (Postfix) with ESMTP id 0B02790000BB for ; Tue, 16 Nov 2021 22:08:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id C13F31F44E90 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637100481; bh=RqMGCc5ANCSX0caOVBCRAi6TG1XH+XSLk0z0lhMYJzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NUVK4h1yNWQ0bn9YXDH/oEj5dL4elNgiiSlB2/K/kwrOHSYZxauHQraYqz7InaTc/ /Nt0LnDve1uXRj0FGia2Cn9vpqLT8Kppb1WmDpDkm5tJyC79oOH1/xf4aE7PrbIC94 vSOrs9bqCmqvOwsyzoHinyeAlZwVsoENV9dPeVml+ezo13EpB4iawt5yW3aZ7rGH2n uUysPPJR0TSorf20lAOJ1/2VJy2NQSJkDE+g1o0N7MLN63O/zk8HBnzhAC0CH+Sy91 FgmJVO1AYgmOb7SN3VxRrSfkQwjwtAa1lXwqgDAWPJZL7cRU9rkJoy6B026LRmGgD3 P84ytBAo763BA== From: Gabriel Krisman Bertazi To: hughd@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, jack@suse.com, amir73il@gmail.com, repnop@google.com, khazhy@google.com, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH 2/2] shmem: Trigger FS_ERROR notification when file system is full Date: Tue, 16 Nov 2021 17:07:42 -0500 Message-Id: <20211116220742.584975-3-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116220742.584975-1-krisman@collabora.com> References: <20211116220742.584975-1-krisman@collabora.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0B02790000BB X-Stat-Signature: jtb8c5keptqnuk1p6t57zj3ksdgi8n1z Authentication-Results: imf28.hostedemail.com; dkim=fail ("headers rsa verify failed") header.d=collabora.com header.s=mail header.b=NUVK4h1y; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf28.hostedemail.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com X-HE-Tag: 1637100481-34431 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Notify a monitoring application through the new FS_ERROR fsnotify event that the file system is full, allowing a sysadmin or recovery application to start recovery procedures. Signed-off-by: Gabriel Krisman Bertazi --- mm/shmem.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 1cdd0253cb7a..525af77d35f3 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -39,6 +39,7 @@ #include #include #include +#include static struct vfsmount *shm_mnt; @@ -1823,6 +1824,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, int error; int once = 0; int alloced = 0; + bool max_blocks_reached = false; if (index > (MAX_LFS_FILESIZE >> PAGE_SHIFT)) return -EFBIG; @@ -1908,9 +1910,11 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, error = PTR_ERR(page); page = NULL; - if (error == -EPERM) + if (error == -ENOSPC) + max_blocks_reached = true; + else if (error == -EPERM) error = -ENOSPC; - else if (error != -ENOSPC) + else goto unlock; /* * Try to reclaim some space by splitting a huge page @@ -2024,11 +2028,16 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, unlock_page(page); put_page(page); } - if (error == -ENOSPC && !once++) { - spin_lock_irq(&info->lock); - shmem_recalc_inode(inode); - spin_unlock_irq(&info->lock); - goto repeat; + if (error == -ENOSPC) { + if (!once++) { + spin_lock_irq(&info->lock); + shmem_recalc_inode(inode); + spin_unlock_irq(&info->lock); + goto repeat; + } + + if (max_blocks_reached) + fsnotify_sb_error(inode->i_sb, inode, ENOSPC); } if (error == -EEXIST) goto repeat; @@ -2701,6 +2710,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT; /* Try to avoid a swapstorm if len is impossible to satisfy */ if (sbinfo->max_blocks && end - start > sbinfo->max_blocks) { + fsnotify_sb_error(inode->i_sb, inode, ENOSPC); error = -ENOSPC; goto out; }