From 4dc7c37c789e5ecd568616ea4e51b85b06a598ae Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Tue, 27 Dec 2016 14:49:03 -0500 Subject: UPSTREAM: kernfs: add kernfs_ops->open/release() callbacks Add ->open/release() methods to kernfs_ops. ->open() is called when the file is opened and ->release() when the file is either released or severed. These callbacks can be used, for example, to manage persistent caching objects over multiple seq_file iterations. Signed-off-by: Tejun Heo Acked-by: Greg Kroah-Hartman Acked-by: Acked-by: Zefan Li (cherry picked from commit 0e67db2f9fe91937e798e3d7d22c50a8438187e1) Bug: 111308141 Test: modified lmkd to use PSI and tested using lmkd_unit_test Change-Id: Id06e9d5c6da1280bcdd4dc86309dcfaf52b8f9a4 Signed-off-by: Suren Baghdasaryan Signed-off-by: Chatur27 --- include/linux/kernfs.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/linux') diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 12b4d960c083..14d13da5234a 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -46,6 +46,7 @@ enum kernfs_node_flag { KERNFS_SUICIDAL = 0x0400, KERNFS_SUICIDED = 0x0800, KERNFS_EMPTY_DIR = 0x1000, + KERNFS_HAS_RELEASE = 0x2000, }; /* @flags for kernfs_create_root() */ @@ -175,6 +176,7 @@ struct kernfs_open_file { /* published fields */ struct kernfs_node *kn; struct file *file; + struct seq_file *seq_file; void *priv; /* private fields, do not use outside kernfs proper */ @@ -185,10 +187,18 @@ struct kernfs_open_file { size_t atomic_write_len; bool mmapped; + bool released:1; const struct vm_operations_struct *vm_ops; }; struct kernfs_ops { + /* + * Optional open/release methods. Both are called with + * @of->seq_file populated. + */ + int (*open)(struct kernfs_open_file *of); + void (*release)(struct kernfs_open_file *of); + /* * Read is handled by either seq_file or raw_read(). * -- cgit v1.2.3