Skip to content
Snippets Groups Projects
Commit 6edfb24a authored by Avi Kivity's avatar Avi Kivity
Browse files

vfs: store directory entry pointer to vnode


In order to unmount, we need to drop all vnodes on a mount point, so we
need to find all directory entries pointing to them.

Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
parent dd882c51
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,7 @@ dentry_alloc(struct vnode *vp, const char *path) ...@@ -73,6 +73,7 @@ dentry_alloc(struct vnode *vp, const char *path)
dp->d_vnode = vp; dp->d_vnode = vp;
dp->d_mount = mp; dp->d_mount = mp;
dp->d_path = strdup(path); dp->d_path = strdup(path);
vn_add_name(vp, dp);
mutex_lock(&dentry_hash_lock); mutex_lock(&dentry_hash_lock);
LIST_INSERT_HEAD(&dentry_hash_table[dentry_hash(mp, path)], dp, d_link); LIST_INSERT_HEAD(&dentry_hash_table[dentry_hash(mp, path)], dp, d_link);
...@@ -121,6 +122,8 @@ drele(struct dentry *dp) ...@@ -121,6 +122,8 @@ drele(struct dentry *dp)
return; return;
} }
LIST_REMOVE(dp, d_link); LIST_REMOVE(dp, d_link);
vn_del_name(dp->d_vnode, dp);
mutex_unlock(&dentry_hash_lock); mutex_unlock(&dentry_hash_lock);
vrele(dp->d_vnode); vrele(dp->d_vnode);
...@@ -214,8 +217,8 @@ namei(char *path, struct dentry **dpp) ...@@ -214,8 +217,8 @@ namei(char *path, struct dentry **dpp)
return error; return error;
} }
dp = dentry_alloc(vp, node);
vn_unlock(dvp); vn_unlock(dvp);
dp = dentry_alloc(vp, node);
vput(vp); vput(vp);
if (!dp) { if (!dp) {
......
...@@ -174,6 +174,7 @@ vget(struct mount *mp, const char *path) ...@@ -174,6 +174,7 @@ vget(struct mount *mp, const char *path)
free(vp); free(vp);
return NULL; return NULL;
} }
LIST_INIT(&vp->v_names);
vp->v_mount = mp; vp->v_mount = mp;
vp->v_refcnt = 1; vp->v_refcnt = 1;
vp->v_op = mp->m_op->vfs_vnops; vp->v_op = mp->m_op->vfs_vnops;
...@@ -470,3 +471,18 @@ vnode_init(void) ...@@ -470,3 +471,18 @@ vnode_init(void)
for (i = 0; i < VNODE_BUCKETS; i++) for (i = 0; i < VNODE_BUCKETS; i++)
LIST_INIT(&vnode_table[i]); LIST_INIT(&vnode_table[i]);
} }
void vn_add_name(struct vnode *vp, struct dentry *dp)
{
vn_lock(vp);
LIST_INSERT_HEAD(&vp->v_names, dp, d_names_link);
vn_unlock(vp);
}
void vn_del_name(struct vnode *vp, struct dentry *dp)
{
vn_lock(vp);
LIST_REMOVE(dp, d_names_link);
vn_unlock(vp);
}
...@@ -19,6 +19,7 @@ struct dentry { ...@@ -19,6 +19,7 @@ struct dentry {
char *d_path; /* pointer to path in fs */ char *d_path; /* pointer to path in fs */
struct vnode *d_vnode; struct vnode *d_vnode;
struct mount *d_mount; struct mount *d_mount;
LIST_ENTRY(dentry) d_names_link; /* link fo vnode::d_names */
}; };
#endif /* _OSV_DENTRY_H */ #endif /* _OSV_DENTRY_H */
...@@ -74,6 +74,7 @@ struct vnode { ...@@ -74,6 +74,7 @@ struct vnode {
mode_t v_mode; /* file mode */ mode_t v_mode; /* file mode */
off_t v_size; /* file size */ off_t v_size; /* file size */
mutex_t v_lock; /* lock for this vnode */ mutex_t v_lock; /* lock for this vnode */
LIST_HEAD(, dentry) v_names; /* directory entries pointing at this */
int v_nrlocks; /* lock count (for debug) */ int v_nrlocks; /* lock count (for debug) */
char *v_path; /* pointer to path in fs */ char *v_path; /* pointer to path in fs */
void *v_data; /* private data for fs */ void *v_data; /* private data for fs */
...@@ -198,6 +199,8 @@ void vref(struct vnode *); ...@@ -198,6 +199,8 @@ void vref(struct vnode *);
void vrele(struct vnode *); void vrele(struct vnode *);
int vcount(struct vnode *); int vcount(struct vnode *);
void vflush(struct mount *); void vflush(struct mount *);
void vn_add_name(struct vnode *, struct dentry *);
void vn_del_name(struct vnode *, struct dentry *);
extern enum vtype iftovt_tab[]; extern enum vtype iftovt_tab[];
extern int vttoif_tab[]; extern int vttoif_tab[];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment