Skip to content

Commit 7f954a6

Browse files
author
Al Viro
committed
simplify the callers of mnt_unhold_writers()
The logics in cleanup on failure in mount_setattr_prepare() is simplified by having the mnt_hold_writers() failure followed by advancing m to the next node in the tree before leaving the loop. And since all calls are preceded by the same check that flag has been set and the function is inlined, let's just shift the check into it. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent d7b7253 commit 7f954a6

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

fs/namespace.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,14 @@ static inline int mnt_hold_writers(struct mount *mnt)
714714
* Stop preventing write access to @mnt allowing callers to gain write access
715715
* to @mnt again.
716716
*
717-
* This function can only be called after a successful call to
718-
* mnt_hold_writers().
717+
* This function can only be called after a call to mnt_hold_writers().
719718
*
720719
* Context: This function expects lock_mount_hash() to be held.
721720
*/
722721
static inline void mnt_unhold_writers(struct mount *mnt)
723722
{
723+
if (!(mnt->mnt_flags & MNT_WRITE_HOLD))
724+
return;
724725
/*
725726
* MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers
726727
* that become unheld will see MNT_READONLY.
@@ -4768,34 +4769,20 @@ static int mount_setattr_prepare(struct mount_kattr *kattr, struct mount *mnt)
47684769

47694770
if (!mnt_allow_writers(kattr, m)) {
47704771
err = mnt_hold_writers(m);
4771-
if (err)
4772+
if (err) {
4773+
m = next_mnt(m, mnt);
47724774
break;
4775+
}
47734776
}
47744777

47754778
if (!(kattr->kflags & MOUNT_KATTR_RECURSE))
47764779
return 0;
47774780
}
47784781

47794782
if (err) {
4780-
struct mount *p;
4781-
4782-
/*
4783-
* If we had to call mnt_hold_writers() MNT_WRITE_HOLD will
4784-
* be set in @mnt_flags. The loop unsets MNT_WRITE_HOLD for all
4785-
* mounts and needs to take care to include the first mount.
4786-
*/
4787-
for (p = mnt; p; p = next_mnt(p, mnt)) {
4788-
/* If we had to hold writers unblock them. */
4789-
if (p->mnt.mnt_flags & MNT_WRITE_HOLD)
4790-
mnt_unhold_writers(p);
4791-
4792-
/*
4793-
* We're done once the first mount we changed got
4794-
* MNT_WRITE_HOLD unset.
4795-
*/
4796-
if (p == m)
4797-
break;
4798-
}
4783+
/* undo all mnt_hold_writers() we'd done */
4784+
for (struct mount *p = mnt; p != m; p = next_mnt(p, mnt))
4785+
mnt_unhold_writers(p);
47994786
}
48004787
return err;
48014788
}
@@ -4826,8 +4813,7 @@ static void mount_setattr_commit(struct mount_kattr *kattr, struct mount *mnt)
48264813
WRITE_ONCE(m->mnt.mnt_flags, flags);
48274814

48284815
/* If we had to hold writers unblock them. */
4829-
if (m->mnt.mnt_flags & MNT_WRITE_HOLD)
4830-
mnt_unhold_writers(m);
4816+
mnt_unhold_writers(m);
48314817

48324818
if (kattr->propagation)
48334819
change_mnt_propagation(m, kattr->propagation);

0 commit comments

Comments
 (0)