Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 7f954a6f d7b7253a

+10 -24
+10 -24
fs/namespace.c
··· 714 714 * Stop preventing write access to @mnt allowing callers to gain write access 715 715 * to @mnt again. 716 716 * 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(). 719 718 * 720 719 * Context: This function expects lock_mount_hash() to be held. 721 720 */ 722 721 static inline void mnt_unhold_writers(struct mount *mnt) 723 722 { 723 + if (!(mnt->mnt_flags & MNT_WRITE_HOLD)) 724 + return; 724 725 /* 725 726 * MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers 726 727 * that become unheld will see MNT_READONLY. ··· 4769 4768 4770 4769 if (!mnt_allow_writers(kattr, m)) { 4771 4770 err = mnt_hold_writers(m); 4772 - if (err) 4771 + if (err) { 4772 + m = next_mnt(m, mnt); 4773 4773 break; 4774 + } 4774 4775 } 4775 4776 4776 4777 if (!(kattr->kflags & MOUNT_KATTR_RECURSE)) ··· 4780 4777 } 4781 4778 4782 4779 if (err) { 4783 - struct mount *p; 4784 - 4785 - /* 4786 - * If we had to call mnt_hold_writers() MNT_WRITE_HOLD will 4787 - * be set in @mnt_flags. The loop unsets MNT_WRITE_HOLD for all 4788 - * mounts and needs to take care to include the first mount. 4789 - */ 4790 - for (p = mnt; p; p = next_mnt(p, mnt)) { 4791 - /* If we had to hold writers unblock them. */ 4792 - if (p->mnt.mnt_flags & MNT_WRITE_HOLD) 4793 - mnt_unhold_writers(p); 4794 - 4795 - /* 4796 - * We're done once the first mount we changed got 4797 - * MNT_WRITE_HOLD unset. 4798 - */ 4799 - if (p == m) 4800 - break; 4801 - } 4780 + /* undo all mnt_hold_writers() we'd done */ 4781 + for (struct mount *p = mnt; p != m; p = next_mnt(p, mnt)) 4782 + mnt_unhold_writers(p); 4802 4783 } 4803 4784 return err; 4804 4785 } ··· 4813 4826 WRITE_ONCE(m->mnt.mnt_flags, flags); 4814 4827 4815 4828 /* If we had to hold writers unblock them. */ 4816 - if (m->mnt.mnt_flags & MNT_WRITE_HOLD) 4817 - mnt_unhold_writers(m); 4829 + mnt_unhold_writers(m); 4818 4830 4819 4831 if (kattr->propagation) 4820 4832 change_mnt_propagation(m, kattr->propagation);