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 <tj@kernel.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Acked-by: Zefan Li <lizefan@huawei.com>
This commit is contained in:
@@ -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 */
|
||||
@@ -186,10 +188,18 @@ struct kernfs_open_file {
|
||||
|
||||
size_t atomic_write_len;
|
||||
bool mmapped:1;
|
||||
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().
|
||||
*
|
||||
|
Reference in New Issue
Block a user