[Cocci] Having rules span multiple files

Luis R. Rodriguez mcgrof at kernel.org
Wed Nov 29 21:58:14 CET 2017


I've recently implemented support for a functionality which would allow us
to remove freezing calls on kthreads on filesystems *iff* the filesystem
implements support for filesystem freezing, this can be determined if
the filesystem implements the fs_freeze superblock callback. So the below
rule looks for the callback first, then looks to see if it has a kthread
implemented, and finally on the kthread fn, it removes any freeze calls.
This works quite nice on a filesystem where there is a match for all
the above in one file, for example fs/ext4/super.c, however it doesn't
work when say the fs_freeze is one file, and the kthread on another.

How could I get the rules to span multiple files?

@ has_freeze_fs @
identifier super_ops;
expression freeze_op;
@@

struct super_operations super_ops = {
	.freeze_fs = freeze_op,
};

@ has_kthread depends on has_freeze_fs @
identifier kthread_fn;
expression task;
@@

task = kthread_run(kthread_fn, ...);

@ remove_set_freezable depends on has_kthread @
identifier has_kthread.kthread_fn;
expression time;
@@

kthread_fn(...)
{
	<+...
(
-	set_freezable();
|
-	try_to_freeze();
|
-	freezable_schedule();
+	schedule();
|
-	freezable_schedule_timeout(time);
+	schedule_timeout(time);
)
	...+>
}


More information about the Cocci mailing list