Skip to contentSkip to conversation

generating uevents by xfs

PATCH Krzysztof Błaszkowski 2 participants 3 messages Apr 28, 2009 – Apr 29, 2009

lore
Share & tools
lore
#0 lore raw

Hello,

once upon i was asked to think about such facility for notifying userspace when some mount point is nearly full at some level let's say e.g. 90% (threshold should be configurable).

here is a solution designed by me and i would like to see comments on this idea and solution.

i verified these patches with 2.6.27.19 (SuSE) but there are also patches for 2.6.28.4 and 2.6.29.2 but i haven't given a try to latest two kernels.

to use it one may need to pick right *-1- patch and the *-2 patch.

Krzysztof Blaszkowski

xfs/Makefile +2 -1
index c3dc491..b0a1330 100644
@@ -88,7 +88,8 @@ xfs-y				+= xfs_alloc.o \
 				   xfs_vnodeops.o \
 				   xfs_rw.o \
 				   xfs_dmops.o \
-				   xfs_qmops.o
+				   xfs_qmops.o \
+				   xfs_sysfs.o
 
 xfs-$(CONFIG_XFS_TRACE)		+= xfs_btree_trace.o \
 				   xfs_dir2_trace.o
xfs/linux-2.6/xfs_super.c +13 -0
index 32ae502..99ac6ed 100644
@@ -1082,6 +1082,9 @@ xfs_fs_put_super(
 	xfs_close_devices(mp);
 	xfs_qmops_put(mp);
 	xfs_dmops_put(mp);
+#ifdef CONFIG_SYSFS
+	xfs_event_release(mp);
+#endif
 	xfs_free_fsname(mp);
 	kfree(mp);
 }
@@ -1509,6 +1512,9 @@ xfs_fs_fill_super(
 
 	kfree(mtpt);
 
+#ifdef CONFIG_SYSFS
+	xfs_event_alloc(mp);
+#endif
 	xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
 	return 0;
 
@@ -1873,6 +1879,10 @@ init_xfs_fs(void)
 	error = register_filesystem(&xfs_fs_type);
 	if (error)
 		goto out_sysctl_unregister;
+
+#ifdef CONFIG_SYSFS
+	xfs_sysfs_init();
+#endif	
 	return 0;
 
  out_sysctl_unregister:
@@ -1906,6 +1916,9 @@ exit_xfs_fs(void)
 	xfs_free_trace_bufs();
 	xfs_destroy_zones();
 	ktrace_uninit();
+#ifdef CONFIG_SYSFS
+	xfs_sysfs_done();
+#endif	
 }
 
 module_init(init_xfs_fs);
xfs/xfs_mount.c +22 -0
index 3530025..c19fc17 100644
@@ -2413,3 +2413,25 @@ balance_counter:
 }
 
 #endif
+
+
+__uint64_t xfs_icsb_get_fdblocks_lazy(xfs_mount_t *mp)
+{
+        __uint64_t fdblocks = 0;
+#ifdef HAVE_PERCPU_SB
+        xfs_icsb_cnts_t *cntp;
+        int i;
+
+        for_each_online_cpu(i) {
+                cntp = (xfs_icsb_cnts_t *)per_cpu_ptr(mp->m_sb_cnts, i);
+                fdblocks += cntp->icsb_fdblocks;
+        }
+
+        if (xfs_icsb_counter_disabled(mp, XFS_SBS_FDBLOCKS))
+                fdblocks = mp->m_sb.sb_fdblocks;
+#else
+        fdblocks = mp->m_sb.sb_fdblocks;
+#endif
+        return fdblocks - XFS_ALLOC_SET_ASIDE(mp);
+}
+
xfs/xfs_mount.h +10 -0
index f5e9937..45ef4cb 100644
@@ -329,6 +329,9 @@ typedef struct xfs_mount {
 	wait_queue_head_t	m_wait_single_sync_task;
 	__int64_t		m_update_flags;	/* sb flags we need to update
 						   on the next remount,rw */
+#ifdef CONFIG_SYSFS
+	void *event_onlow;
+#endif
 } xfs_mount_t;
 
 /*
@@ -528,6 +531,13 @@ extern void	xfs_qmops_put(struct xfs_mount *);
 
 extern struct xfs_dmops xfs_dmcore_xfs;
 
+#ifdef CONFIG_SYSFS
+extern void xfs_sysfs_init(void);
+extern void xfs_sysfs_done(void);
+extern int xfs_event_alloc(struct xfs_mount *mnt);
+extern int xfs_event_release(struct xfs_mount *mnt);
+#endif
+
 #endif	/* __KERNEL__ */
 
 extern void	xfs_mod_sb(struct xfs_trans *, __int64_t);
xfs/Makefile +2 -1
index 737c9a4..1df5f4e 100644
@@ -89,7 +89,8 @@ xfs-y				+= xfs_alloc.o \
 				   xfs_vnodeops.o \
 				   xfs_rw.o \
 				   xfs_dmops.o \
-				   xfs_qmops.o
+				   xfs_qmops.o \
+				   xfs_sysfs.o
 
 xfs-$(CONFIG_XFS_TRACE)		+= xfs_dir2_trace.o
 
xfs/linux-2.6/xfs_super.c +13 -0
index 37ebe36..7cc0b6b 100644
@@ -1152,6 +1152,9 @@ xfs_fs_put_super(
 	xfs_close_devices(mp);
 	xfs_qmops_put(mp);
 	xfs_dmops_put(mp);
+#ifdef CONFIG_SYSFS
+	xfs_event_release(mp);
+#endif
 	xfs_free_fsname(mp);
 	kfree(mp);
 }
@@ -1783,6 +1786,9 @@ xfs_fs_fill_super(
 	xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
 
 	kfree(args);
+#ifdef CONFIG_SYSFS
+	xfs_event_alloc(mp);
+#endif
 	return 0;
 
  out_filestream_unmount:
@@ -2142,6 +2148,10 @@ init_xfs_fs(void)
 	error = register_filesystem(&xfs_fs_type);
 	if (error)
 		goto out_sysctl_unregister;
+
+#ifdef CONFIG_SYSFS
+	xfs_sysfs_init();
+#endif	
 	return 0;
 
  out_sysctl_unregister:
@@ -2175,6 +2185,9 @@ exit_xfs_fs(void)
 	xfs_free_trace_bufs();
 	xfs_destroy_zones();
 	ktrace_uninit();
+#ifdef CONFIG_SYSFS
+	xfs_sysfs_done();
+#endif	
 }
 
 module_init(init_xfs_fs);
xfs/xfs_mount.c +22 -0
index 15f5dd2..47e8202 100644
@@ -2442,3 +2442,25 @@ balance_counter:
 }
 
 #endif
+
+
+__uint64_t xfs_icsb_get_fdblocks_lazy(xfs_mount_t *mp)
+{
+        __uint64_t fdblocks = 0;
+#ifdef HAVE_PERCPU_SB
+        xfs_icsb_cnts_t *cntp;
+        int i;
+
+        for_each_online_cpu(i) {
+                cntp = (xfs_icsb_cnts_t *)per_cpu_ptr(mp->m_sb_cnts, i);
+                fdblocks += cntp->icsb_fdblocks;
+        }
+
+        if (xfs_icsb_counter_disabled(mp, XFS_SBS_FDBLOCKS))
+                fdblocks = mp->m_sb.sb_fdblocks;
+#else
+        fdblocks = mp->m_sb.sb_fdblocks;
+#endif
+        return fdblocks - XFS_ALLOC_SET_ASIDE(mp);
+}
+
xfs/xfs_mount.h +10 -0
index f3c1024..9a98c44 100644
@@ -341,6 +341,9 @@ typedef struct xfs_mount {
 	spinlock_t		m_sync_lock;	/* work item list lock */
 	int			m_sync_seq;	/* sync thread generation no. */
 	wait_queue_head_t	m_wait_single_sync_task;
+#ifdef CONFIG_SYSFS
+	void *event_onlow;
+#endif
 } xfs_mount_t;
 
 /*
@@ -539,6 +542,13 @@ extern void	xfs_qmops_put(struct xfs_mou
 
 extern struct xfs_dmops xfs_dmcore_xfs;
 
+#ifdef CONFIG_SYSFS
+extern void xfs_sysfs_init(void);
+extern void xfs_sysfs_done(void);
+extern int xfs_event_alloc(struct xfs_mount *mnt);
+extern int xfs_event_release(struct xfs_mount *mnt);
+#endif
+
 #endif	/* __KERNEL__ */
 
 #endif	/* __XFS_MOUNT_H__ */
xfs/Makefile +2 -1
index ba17121..904372b 100644
@@ -91,7 +91,8 @@ xfs-y				+= xfs_alloc.o \
 				   xfs_vnodeops.o \
 				   xfs_rw.o \
 				   xfs_dmops.o \
-				   xfs_qmops.o
+				   xfs_qmops.o \
+				   xfs_sysfs.o
 
 xfs-$(CONFIG_XFS_TRACE)		+= xfs_dir2_trace.o
 
xfs/linux-2.6/xfs_super.c +13 -0
index 9eaddb4..57f2558 100644
@@ -1152,6 +1152,9 @@ xfs_fs_put_super(
 	xfs_close_devices(mp);
 	xfs_qmops_put(mp);
 	xfs_dmops_put(mp);
+#ifdef CONFIG_SYSFS
+	xfs_event_release(mp);
+#endif
 	xfs_free_fsname(mp);
 	kfree(mp);
 }
@@ -1783,6 +1786,9 @@ xfs_fs_fill_super(
 	xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
 
 	kfree(args);
+#ifdef CONFIG_SYSFS
+	xfs_event_alloc(mp);
+#endif
 	return 0;
 
  out_filestream_unmount:
@@ -2151,6 +2157,10 @@ init_xfs_fs(void)
 	error = register_filesystem(&xfs_fs_type);
 	if (error)
 		goto out_sysctl_unregister;
+
+#ifdef CONFIG_SYSFS
+	xfs_sysfs_init();
+#endif	
 	return 0;
 
  out_sysctl_unregister:
@@ -2184,6 +2194,9 @@ exit_xfs_fs(void)
 	xfs_free_trace_bufs();
 	xfs_destroy_zones();
 	ktrace_uninit();
+#ifdef CONFIG_SYSFS
+	xfs_sysfs_done();
+#endif	
 }
 
 module_init(init_xfs_fs);
xfs/xfs_mount.c +22 -0
index a4503f5..2854b00 100644
@@ -2441,3 +2441,25 @@ balance_counter:
 }
 
 #endif
+
+
+__uint64_t xfs_icsb_get_fdblocks_lazy(xfs_mount_t *mp)
+{
+        __uint64_t fdblocks = 0;
+#ifdef HAVE_PERCPU_SB
+        xfs_icsb_cnts_t *cntp;
+        int i;
+
+        for_each_online_cpu(i) {
+                cntp = (xfs_icsb_cnts_t *)per_cpu_ptr(mp->m_sb_cnts, i);
+                fdblocks += cntp->icsb_fdblocks;
+        }
+
+        if (xfs_icsb_counter_disabled(mp, XFS_SBS_FDBLOCKS))
+                fdblocks = mp->m_sb.sb_fdblocks;
+#else
+        fdblocks = mp->m_sb.sb_fdblocks;
+#endif
+        return fdblocks - XFS_ALLOC_SET_ASIDE(mp);
+}
+
xfs/xfs_mount.h +10 -0
index b6b8be8..a7c17fe 100644
@@ -342,6 +342,9 @@ typedef struct xfs_mount {
 	int			m_sync_seq;	/* sync thread generation no. */
 	wait_queue_head_t	m_wait_single_sync_task;
 	struct vfsmount         *m_vfsmount;
+#ifdef CONFIG_SYSFS
+	void *event_onlow;
+#endif
 } xfs_mount_t;
 
 /*
@@ -540,6 +543,13 @@ extern void	xfs_qmops_put(struct xfs_mount *);
 
 extern struct xfs_dmops xfs_dmcore_xfs;
 
+#ifdef CONFIG_SYSFS
+extern void xfs_sysfs_init(void);
+extern void xfs_sysfs_done(void);
+extern int xfs_event_alloc(struct xfs_mount *mnt);
+extern int xfs_event_release(struct xfs_mount *mnt);
+#endif
+
 #endif	/* __KERNEL__ */
 
 #endif	/* __XFS_MOUNT_H__ */
xfs/xfs_sysfs.c new file +339 -0

339 lines not on this page · raw message

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw
Quoted 8 lines · Krzysztof Bâaszkowski

Hello,

once upon i was asked to think about such facility for notifying userspace when some mount point is nearly full at some level let's say e.g. 90% (threshold should be configurable).

here is a solution designed by me and i would like to see comments on this idea and solution.

It doesn't seem to be very useful to poll in kernel for this. When you're in kernel you could just hook into the respective functions that handle disk allocation directly. Polling can be as well done in user space only, so it doesn't make too much sense to put polling code into the kernel.

-Andi

Signature · 6 lines
[email protected] -- Speaking for myself only.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw
Quoted 7 lines · Andi Kleen
Quoted 6 lines · Krzysztof Bâaszkowski

Hello,

once upon i was asked to think about such facility for notifying userspace when some mount point is nearly full at some level let's say e.g. 90% (threshold should be configurable).

Quoted 6 lines
Quoted 2 lines

here is a solution designed by me and i would like to see comments on this idea and solution.

It doesn't seem to be very useful to poll in kernel for this. When you're in kernel you could just hook into the respective functions that handle disk allocation directly.

i reckon yes and no both. "no" because i wanted a solution which will have almost no impact on performance. if the speed wasn't an important concern then why would one take care about per cpu counters like fdblocks ?

Quoted 2 lines

Polling can be as well done in user space only,
so it doesn't make too much sense to put polling code into the kernel.

yes i think too, that's maybe a bit too huge thing looking at benefits it brings but consider bash instance consuming 1.5M (at least) and other things spawned periodically,
do they have more sense ? i don't think so and this is the solution which voids all hassle with userspace polling because it uses unified notification system and this can be good starting point for notification system for other purposes i haven't think of yet but maybe someone has a new idea regarding this.

are these reasons good to (complete and) merge this stuff ?

I found that the xfs-sysfs-2 requires small rework around event_alloc() and event_release() because of very rare (but possible) race with timer function which drops lock (i decided to drop lock because i think kobject_uevent may be synchronous in the case of deprecated /sbin/hotplug and i'm not sure also how long it takes for udevd)

i think that there is no point to update patch as long as we will not sort out if the whole idea is really worth to implement.

Thanks for reply.

Krzysztof Blaszkowski

Quoted 2 lines

-Andi

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs