[Devel] [PATCH RHEL9 COMMIT] xfs: Notify userspace about events

Konstantin Khorenko khorenko at virtuozzo.com
Thu Jan 27 17:36:58 MSK 2022


The commit is pushed to "branch-rh9-5.14.0-4.vz9.12.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.12.2
------>
commit 78712ea1618669dfb7277d18fe6863699831b811
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Thu Jan 27 17:36:57 2022 +0300

    xfs: Notify userspace about events
    
    The same cases as for ext4 except xfs does not remount RO on error.
    
    Test:
        #Prepare:
        $truncate -s 512M xfs.img
        $mkfs.xfs /dev/loop0 xfs.img
        $mount /dev/loop0 /mnt
        $for i in `seq 1 10000`; do echo $i > /mnt/$i.txt; done
        $sync
        $echo 3 > /proc/sys/vm/drop_caches
    
        #Run udevadm in screen:
        $udevadm monitor -p
    
        #Generate REMOUNT and ERROR events:
        $mount -n -o remount,ro /mnt
        $dd if=/dev/urandom of=/dev/loop0 bs=1M oflag=direct
        $ls /mnt
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    ====================
    xfs: Add notification about fs events like for ext4
    
    This patchset generalizes ext4's related code and introduced the same
    uevent notifications for xfs.
    
    https://jira.sw.ru/browse/PSBM-135476
    Feature: fs: udev events support
---
 fs/xfs/xfs_error.c | 4 ++++
 fs/xfs/xfs_super.c | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c
index 25550c5bbb5b..6ef78dd3dd0e 100644
--- a/fs/xfs/xfs_error.c
+++ b/fs/xfs/xfs_error.c
@@ -353,6 +353,7 @@ xfs_corruption_error(
 		xfs_hex_dump(buf, bufsize);
 	xfs_error_report(tag, level, mp, filename, linenum, failaddr);
 	xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair");
+	xfs_send_uevent(mp->m_super, FS_UA_ERROR);
 }
 
 /*
@@ -377,6 +378,7 @@ xfs_buf_corruption_error(
 
 	if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
 		xfs_stack_trace();
+	xfs_send_uevent(mp->m_super, FS_UA_ERROR);
 }
 
 /*
@@ -415,6 +417,7 @@ xfs_buf_verifier_error(
 
 	if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
 		xfs_stack_trace();
+	xfs_send_uevent(mp->m_super, FS_UA_ERROR);
 }
 
 /*
@@ -465,6 +468,7 @@ xfs_inode_verifier_error(
 
 	if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
 		xfs_stack_trace();
+	xfs_send_uevent(mp->m_super, FS_UA_ERROR);
 }
 
 void xfs_send_uevent(struct super_block *sb, enum fs_event_type event)
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index bd28e2a0d496..7434f0e1a6eb 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -37,6 +37,7 @@
 #include "xfs_reflink.h"
 #include "xfs_pwork.h"
 #include "xfs_ag.h"
+#include "xfs_error.h"
 
 #include <linux/magic.h>
 #include <linux/fs_context.h>
@@ -943,6 +944,8 @@ xfs_fs_freeze(
 	xfs_save_resvblks(mp);
 	ret = xfs_log_quiesce(mp);
 	memalloc_nofs_restore(flags);
+	if (!ret)
+		xfs_send_uevent(sb, FS_UA_FREEZE);
 	return ret;
 }
 
@@ -955,6 +958,7 @@ xfs_fs_unfreeze(
 	xfs_restore_resvblks(mp);
 	xfs_log_work_queue(mp);
 	xfs_blockgc_start(mp);
+	xfs_send_uevent(sb, FS_UA_UNFREEZE);
 	return 0;
 }
 
@@ -1090,6 +1094,9 @@ xfs_fs_put_super(
 	if (!sb->s_fs_info)
 		return;
 
+	xfs_send_uevent(sb, FS_UA_UMOUNT);
+	flush_workqueue(fs_events_wq);
+
 	xfs_notice(mp, "Unmounting Filesystem");
 	xfs_filestream_unmount(mp);
 	xfs_unmountfs(mp);
@@ -1674,6 +1681,7 @@ xfs_fs_fill_super(
 		goto out_unmount;
 	}
 
+	xfs_send_uevent(sb, FS_UA_MOUNT);
 	return 0;
 
  out_filestream_unmount:
@@ -1888,6 +1896,7 @@ xfs_fs_reconfigure(
 		WRITE_ONCE(mp->m_balloon_ino, new_mp->m_balloon_ino);
 	}
 
+	xfs_send_uevent(mp->m_super, FS_UA_REMOUNT);
 	return 0;
 }
 


More information about the Devel mailing list