diff options
author | des <des@FreeBSD.org> | 2007-03-12 12:16:52 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2007-03-12 12:16:52 +0000 |
commit | 3d3e50beaf534ec30b151614f684eccd85ef5782 (patch) | |
tree | bf90ea580c06ca59d01616d80a1764d6c48580d1 /sys/fs | |
parent | a3cbd559395af5e36b0ce853ee5218ddc911ff25 (diff) | |
download | FreeBSD-src-3d3e50beaf534ec30b151614f684eccd85ef5782.zip FreeBSD-src-3d3e50beaf534ec30b151614f684eccd85ef5782.tar.gz |
Add a pn_destroy field to pfs_node. This field points to a destructor
function which is called from pfs_destroy() before the node is reclaimed.
Modify pfs_create_{dir,file,link}() to accept a pointer to a destructor
function in addition to the usual attr / fill / vis pointers.
This breaks both the programming and binary interfaces between pseudofs
and its consumers. It is believed that there are no pseudofs consumers
outside the source tree, so that the impact of this change is minimal.
Submitted by: Aniruddha Bohra <bohra@cs.rutgers.edu>
Diffstat (limited to 'sys/fs')
-rw-r--r-- | sys/fs/procfs/procfs.c | 30 | ||||
-rw-r--r-- | sys/fs/pseudofs/pseudofs.c | 17 | ||||
-rw-r--r-- | sys/fs/pseudofs/pseudofs.h | 19 |
3 files changed, 44 insertions, 22 deletions
diff --git a/sys/fs/procfs/procfs.c b/sys/fs/procfs/procfs.c index d311a98..56bc0cc 100644 --- a/sys/fs/procfs/procfs.c +++ b/sys/fs/procfs/procfs.c @@ -160,39 +160,39 @@ procfs_init(PFS_INIT_ARGS) root = pi->pi_root; pfs_create_link(root, "curproc", procfs_docurproc, - NULL, NULL, 0); + NULL, NULL, NULL, 0); dir = pfs_create_dir(root, "pid", - procfs_attr, NULL, PFS_PROCDEP); + procfs_attr, NULL, NULL, PFS_PROCDEP); pfs_create_file(dir, "cmdline", procfs_doproccmdline, - NULL, NULL, PFS_RD); + NULL, NULL, NULL, PFS_RD); pfs_create_file(dir, "ctl", procfs_doprocctl, - procfs_attr, NULL, PFS_WR); + procfs_attr, NULL, NULL, PFS_WR); pfs_create_file(dir, "dbregs", procfs_doprocdbregs, - procfs_attr, procfs_candebug, PFS_RDWR|PFS_RAW); + procfs_attr, procfs_candebug, NULL, PFS_RDWR|PFS_RAW); pfs_create_file(dir, "etype", procfs_doproctype, - NULL, NULL, PFS_RD); + NULL, NULL, NULL, PFS_RD); pfs_create_file(dir, "fpregs", procfs_doprocfpregs, - procfs_attr, procfs_candebug, PFS_RDWR|PFS_RAW); + procfs_attr, procfs_candebug, NULL, PFS_RDWR|PFS_RAW); pfs_create_file(dir, "map", procfs_doprocmap, - NULL, procfs_notsystem, PFS_RD); + NULL, procfs_notsystem, NULL, PFS_RD); node = pfs_create_file(dir, "mem", procfs_doprocmem, - procfs_attr, procfs_candebug, PFS_RDWR|PFS_RAW); + procfs_attr, procfs_candebug, NULL, PFS_RDWR|PFS_RAW); node->pn_ioctl = procfs_ioctl; node->pn_close = procfs_close; pfs_create_file(dir, "note", procfs_doprocnote, - procfs_attr, procfs_candebug, PFS_WR); + procfs_attr, procfs_candebug, NULL, PFS_WR); pfs_create_file(dir, "notepg", procfs_doprocnote, - procfs_attr, procfs_candebug, PFS_WR); + procfs_attr, procfs_candebug, NULL, PFS_WR); pfs_create_file(dir, "regs", procfs_doprocregs, - procfs_attr, procfs_candebug, PFS_RDWR|PFS_RAW); + procfs_attr, procfs_candebug, NULL, PFS_RDWR|PFS_RAW); pfs_create_file(dir, "rlimit", procfs_doprocrlimit, - NULL, NULL, PFS_RD); + NULL, NULL, NULL, PFS_RD); pfs_create_file(dir, "status", procfs_doprocstatus, - NULL, NULL, PFS_RD); + NULL, NULL, NULL, PFS_RD); pfs_create_link(dir, "file", procfs_doprocfile, - NULL, procfs_notsystem, 0); + NULL, procfs_notsystem, NULL, 0); return (0); } diff --git a/sys/fs/pseudofs/pseudofs.c b/sys/fs/pseudofs/pseudofs.c index da1758b..42c45bb 100644 --- a/sys/fs/pseudofs/pseudofs.c +++ b/sys/fs/pseudofs/pseudofs.c @@ -122,7 +122,8 @@ _pfs_fixup_dir(struct pfs_node *parent) */ struct pfs_node * pfs_create_dir(struct pfs_node *parent, const char *name, - pfs_attr_t attr, pfs_vis_t vis, int flags) + pfs_attr_t attr, pfs_vis_t vis, pfs_destroy_t destroy, + int flags) { struct pfs_node *dir; @@ -135,6 +136,7 @@ pfs_create_dir(struct pfs_node *parent, const char *name, dir->pn_type = (flags & PFS_PROCDEP) ? pfstype_procdir : pfstype_dir; dir->pn_attr = attr; dir->pn_vis = vis; + dir->pn_destroy = destroy; dir->pn_flags = flags; if (_pfs_add_node(parent, dir) != 0) { @@ -155,7 +157,8 @@ pfs_create_dir(struct pfs_node *parent, const char *name, */ struct pfs_node * pfs_create_file(struct pfs_node *parent, const char *name, pfs_fill_t fill, - pfs_attr_t attr, pfs_vis_t vis, int flags) + pfs_attr_t attr, pfs_vis_t vis, pfs_destroy_t destroy, + int flags) { struct pfs_node *node; @@ -169,6 +172,7 @@ pfs_create_file(struct pfs_node *parent, const char *name, pfs_fill_t fill, node->pn_func = fill; node->pn_attr = attr; node->pn_vis = vis; + node->pn_destroy = destroy; node->pn_flags = flags; if (_pfs_add_node(parent, node) != 0) { @@ -184,11 +188,12 @@ pfs_create_file(struct pfs_node *parent, const char *name, pfs_fill_t fill, */ struct pfs_node * pfs_create_link(struct pfs_node *parent, const char *name, pfs_fill_t fill, - pfs_attr_t attr, pfs_vis_t vis, int flags) + pfs_attr_t attr, pfs_vis_t vis, pfs_destroy_t destroy, + int flags) { struct pfs_node *node; - node = pfs_create_file(parent, name, fill, attr, vis, flags); + node = pfs_create_file(parent, name, fill, attr, vis, destroy, flags); if (node == NULL) return (NULL); node->pn_type = pfstype_symlink; @@ -249,6 +254,10 @@ pfs_destroy(struct pfs_node *node) mtx_unlock(&node->pn_info->pi_mutex); } + /* callback to free any private resources */ + if(node->pn_destroy != NULL) + (node->pn_destroy)(node); + /* revoke vnodes and release memory */ pfs_disable(node); FREE(node, M_PFSNODES); diff --git a/sys/fs/pseudofs/pseudofs.h b/sys/fs/pseudofs/pseudofs.h index b9701bc..58eba44 100644 --- a/sys/fs/pseudofs/pseudofs.h +++ b/sys/fs/pseudofs/pseudofs.h @@ -155,6 +155,15 @@ typedef int (*pfs_getextattr_t)(PFS_GETEXTATTR_ARGS); typedef int (*pfs_close_t)(PFS_CLOSE_ARGS); /* + * Destroy callback + */ +#define PFS_DESTROY_ARGS \ + struct pfs_node *pn +#define PFS_DESTROY_PROTO(name) \ + int name(PFS_DESTROY_ARGS); +typedef int (*pfs_destroy_t)(PFS_DESTROY_ARGS); + +/* * pfs_info: describes a pseudofs instance */ struct pfs_info { @@ -186,6 +195,7 @@ struct pfs_node { pfs_attr_t pn_attr; pfs_vis_t pn_vis; pfs_getextattr_t pn_getextattr; + pfs_destroy_t pn_destroy; void *pn_data; int pn_flags; @@ -215,13 +225,16 @@ int pfs_uninit (struct pfs_info *pi, struct vfsconf *vfc); * Directory structure construction and manipulation */ struct pfs_node *pfs_create_dir (struct pfs_node *parent, const char *name, - pfs_attr_t attr, pfs_vis_t vis, int flags); + pfs_attr_t attr, pfs_vis_t vis, + pfs_destroy_t destroy, int flags); struct pfs_node *pfs_create_file(struct pfs_node *parent, const char *name, pfs_fill_t fill, pfs_attr_t attr, - pfs_vis_t vis, int flags); + pfs_vis_t vis, pfs_destroy_t destroy, + int flags); struct pfs_node *pfs_create_link(struct pfs_node *parent, const char *name, pfs_fill_t fill, pfs_attr_t attr, - pfs_vis_t vis, int flags); + pfs_vis_t vis, pfs_destroy_t destroy, + int flags); struct pfs_node *pfs_find_node (struct pfs_node *parent, const char *name); int pfs_disable (struct pfs_node *pn); int pfs_enable (struct pfs_node *pn); |