linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@collabora.com>
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 <krisman@collabora.com>,
	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	[thread overview]
Message-ID: <20211116220742.584975-3-krisman@collabora.com> (raw)
In-Reply-To: <20211116220742.584975-1-krisman@collabora.com>

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 <krisman@collabora.com>
---
 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 <linux/frontswap.h>
 #include <linux/fs_parser.h>
 #include <linux/swapfile.h>
+#include <linux/fsnotify.h>
 
 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;
 	}
-- 
2.33.0



  parent reply	other threads:[~2021-11-16 22:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 22:07 [PATCH 0/2] shmem: Notify user space " Gabriel Krisman Bertazi
2021-11-16 22:07 ` [PATCH 1/2] shmem: Differentiate cause of blk account error due to lack of space Gabriel Krisman Bertazi
2021-11-16 22:07 ` Gabriel Krisman Bertazi [this message]
2021-11-17  9:00 ` [PATCH 0/2] shmem: Notify user space when file system is full Amir Goldstein
2022-01-11  1:57   ` Gabriel Krisman Bertazi
2022-01-11  7:50     ` Amir Goldstein
2022-01-12  3:19       ` Gabriel Krisman Bertazi
2022-01-12  5:59         ` Amir Goldstein
2022-01-14 20:17           ` Gabriel Krisman Bertazi
2022-01-14 22:16             ` Khazhy Kumykov
2022-01-15 11:30               ` Amir Goldstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211116220742.584975-3-krisman@collabora.com \
    --to=krisman@collabora.com \
    --cc=akpm@linux-foundation.org \
    --cc=amir73il@gmail.com \
    --cc=hughd@google.com \
    --cc=jack@suse.com \
    --cc=kernel@collabora.com \
    --cc=khazhy@google.com \
    --cc=linux-mm@kvack.org \
    --cc=repnop@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox