unionfs: rework locking scheme to only lock a single vnode
Instead of locking both the lower and upper vnodes, which is both complex and deadlock-prone, only lock the upper vnode, or the lower vnode if no upper vnode is present. In most cases this is all that is needed; for the cases in which both vnodes do need to be locked, this change also employs deadlock- avoiding techniques such as LK_NOWAIT and vn_lock_pair(). There are still some corner cases in which the current implementation ends up taking multiple vnode locks across different filesystems without taking special steps to avoid deadlock; those cases have been noted in the comments. Differential Revision: https://reviews.freebsd.org/D45398 Reviewed by: olce Tested by: pho
This commit is contained in:
parent
6ac0f711ad
commit
eb60ff1ee1
4 changed files with 985 additions and 752 deletions
|
|
@ -97,15 +97,17 @@ struct unionfs_node {
|
|||
|
||||
char *un_path; /* path */
|
||||
int un_pathlen; /* strlen of path */
|
||||
int un_flag; /* unionfs node flag */
|
||||
};
|
||||
|
||||
/*
|
||||
* unionfs node flags
|
||||
* It needs the vnode with exclusive lock, when changing the un_flag variable.
|
||||
*/
|
||||
#define UNIONFS_OPENEXTL 0x01 /* openextattr (lower) */
|
||||
#define UNIONFS_OPENEXTU 0x02 /* openextattr (upper) */
|
||||
/*
|
||||
* unionfs node flags
|
||||
* Changing these flags requires the vnode to be locked exclusive.
|
||||
*/
|
||||
#define UNIONFS_OPENEXTL 0x01 /* openextattr (lower) */
|
||||
#define UNIONFS_OPENEXTU 0x02 /* openextattr (upper) */
|
||||
#define UNIONFS_COPY_IN_PROGRESS 0x04 /* copy/dir shadow in progres */
|
||||
#define UNIONFS_LOOKUP_IN_PROGRESS 0x08
|
||||
unsigned int un_flag; /* unionfs node flag */
|
||||
};
|
||||
|
||||
extern struct vop_vector unionfs_vnodeops;
|
||||
|
||||
|
|
@ -136,29 +138,25 @@ void unionfs_get_node_status(struct unionfs_node *, struct thread *,
|
|||
void unionfs_tryrem_node_status(struct unionfs_node *,
|
||||
struct unionfs_node_status *);
|
||||
int unionfs_check_rmdir(struct vnode *, struct ucred *, struct thread *td);
|
||||
int unionfs_copyfile(struct unionfs_node *, int, struct ucred *,
|
||||
int unionfs_copyfile(struct vnode *, int, struct ucred *,
|
||||
struct thread *);
|
||||
void unionfs_create_uppervattr_core(struct unionfs_mount *, struct vattr *,
|
||||
struct vattr *, struct thread *);
|
||||
int unionfs_create_uppervattr(struct unionfs_mount *, struct vnode *,
|
||||
struct vattr *, struct ucred *, struct thread *);
|
||||
int unionfs_mkshadowdir(struct unionfs_mount *, struct vnode *,
|
||||
struct unionfs_node *, struct componentname *, struct thread *);
|
||||
int unionfs_mkshadowdir(struct vnode *, struct vnode *,
|
||||
struct componentname *, struct thread *);
|
||||
int unionfs_mkwhiteout(struct vnode *, struct vnode *,
|
||||
struct componentname *, struct thread *, char *, int);
|
||||
int unionfs_relookup(struct vnode *, struct vnode **,
|
||||
struct componentname *, struct componentname *, struct thread *,
|
||||
char *, int, u_long);
|
||||
int unionfs_relookup_for_create(struct vnode *, struct componentname *,
|
||||
struct thread *);
|
||||
int unionfs_relookup_for_delete(struct vnode *, struct componentname *,
|
||||
struct thread *);
|
||||
int unionfs_relookup_for_rename(struct vnode *, struct componentname *,
|
||||
struct thread *);
|
||||
void unionfs_forward_vop_start_pair(struct vnode *, int *,
|
||||
struct vnode *, int *);
|
||||
bool unionfs_forward_vop_finish_pair(struct vnode *, struct vnode *, int,
|
||||
struct vnode *, struct vnode *, int);
|
||||
int unionfs_set_in_progress_flag(struct vnode *, unsigned int);
|
||||
void unionfs_clear_in_progress_flag(struct vnode *, unsigned int);
|
||||
|
||||
static inline void
|
||||
unionfs_forward_vop_start(struct vnode *basevp, int *lkflags)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -327,18 +327,15 @@ unionfs_domount(struct mount *mp)
|
|||
* unionfs_lock()) and the mountpoint's busy count. Without this,
|
||||
* unmount will lock the covered vnode lock (directly through the
|
||||
* covered vnode) and wait for the busy count to drain, while a
|
||||
* concurrent lookup will increment the busy count and then lock
|
||||
* concurrent lookup will increment the busy count and then may lock
|
||||
* the covered vnode lock (indirectly through unionfs_lock()).
|
||||
*
|
||||
* Note that we can't yet use this facility for the 'below' case
|
||||
* in which the upper vnode is the covered vnode, because that would
|
||||
* introduce a different LOR in which the cross-mount lookup would
|
||||
* effectively hold the upper vnode lock before acquiring the lower
|
||||
* vnode lock, while an unrelated lock operation would still acquire
|
||||
* the lower vnode lock before the upper vnode lock, which is the
|
||||
* order unionfs currently requires.
|
||||
* Note that this is only needed for the 'below' case in which the
|
||||
* upper vnode is also the covered vnode, because unionfs_lock()
|
||||
* only locks the upper vnode as long as both lower and upper vnodes
|
||||
* are present (which they will always be for the unionfs mount root).
|
||||
*/
|
||||
if (!below) {
|
||||
if (below) {
|
||||
vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY | LK_CANRECURSE);
|
||||
mp->mnt_vnodecovered->v_vflag |= VV_CROSSLOCK;
|
||||
VOP_UNLOCK(mp->mnt_vnodecovered);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue