/* return the next shared peer mount of @p */ staticinlinestruct mount *next_peer(struct mount *p)
{ return list_entry(p->mnt_share.next, struct mount, mnt_share);
}
staticinlinestruct mount *first_slave(struct mount *p)
{ return hlist_entry(p->mnt_slave_list.first, struct mount, mnt_slave);
}
staticinlinestruct mount *next_slave(struct mount *p)
{ return hlist_entry(p->mnt_slave.next, struct mount, mnt_slave);
}
staticstruct mount *get_peer_under_root(struct mount *mnt, struct mnt_namespace *ns, conststruct path *root)
{ struct mount *m = mnt;
do { /* Check the namespace first for optimization */ if (m->mnt_ns == ns && is_path_reachable(m, m->mnt.mnt_root, root)) return m;
m = next_peer(m);
} while (m != mnt);
return NULL;
}
/* *GetIDofclosestdominatingpeergrouphavingarepresentative *underthegivenroot. * *Callermustholdnamespace_sem
*/ int get_dominating_id(struct mount *mnt, conststruct path *root)
{ struct mount *m;
for (m = mnt->mnt_master; m != NULL; m = m->mnt_master) { struct mount *d = get_peer_under_root(m, mnt->mnt_ns, root); if (d) return d->mnt_group_id;
}
return0;
}
staticinlinebool will_be_unmounted(struct mount *m)
{ return m->mnt.mnt_flags & MNT_UMOUNT;
}
staticstruct mount *propagation_source(struct mount *mnt)
{ do { struct mount *m; for (m = next_peer(mnt); m != mnt; m = next_peer(m)) { if (!will_be_unmounted(m)) return m;
}
mnt = mnt->mnt_master;
} while (mnt && will_be_unmounted(mnt)); return mnt;
}
staticvoid transfer_propagation(struct mount *mnt, struct mount *to)
{ struct hlist_node *p = NULL, *n; struct mount *m;
hlist_for_each_entry_safe(m, n, &mnt->mnt_slave_list, mnt_slave) {
m->mnt_master = to; if (!to)
hlist_del_init(&m->mnt_slave); else
p = &m->mnt_slave;
} if (p)
hlist_splice_init(&mnt->mnt_slave_list, p, &to->mnt_slave_list);
}
/* *EXCL[namespace_sem]
*/ void change_mnt_propagation(struct mount *mnt, int type)
{ struct mount *m = mnt->mnt_master;
if (type == MS_SHARED) {
set_mnt_shared(mnt); return;
} if (IS_MNT_SHARED(mnt)) { if (type == MS_SLAVE || !hlist_empty(&mnt->mnt_slave_list))
m = propagation_source(mnt); if (list_empty(&mnt->mnt_share)) {
mnt_release_group_id(mnt);
} else {
list_del_init(&mnt->mnt_share);
mnt->mnt_group_id = 0;
}
CLEAR_MNT_SHARED(mnt);
transfer_propagation(mnt, m);
}
hlist_del_init(&mnt->mnt_slave); if (type == MS_SLAVE) {
mnt->mnt_master = m; if (m)
hlist_add_head(&mnt->mnt_slave, &m->mnt_slave_list);
} else {
mnt->mnt_master = NULL; if (type == MS_UNBINDABLE)
mnt->mnt_t_flags |= T_UNBINDABLE; else
mnt->mnt_t_flags &= ~T_UNBINDABLE;
}
}
staticstruct mount *__propagation_next(struct mount *m, struct mount *origin)
{ while (1) { struct mount *master = m->mnt_master;
/* *getthenextmountinthepropagationtree. *@m:themountseenlast *@origin:theoriginalmountfromwherethetreewalkinitiated * *Notethatpeergroupsformcontiguoussegmentsofslavelists. *Werelyonthatinget_source()tobeabletofindoutif *vfsmountfoundwhileiteratingwithpropagation_next()is *apeerofonewe'dfoundearlier.
*/ staticstruct mount *propagation_next(struct mount *m, struct mount *origin)
{ /* are there any slaves of this mount? */ if (!IS_MNT_NEW(m) && !hlist_empty(&m->mnt_slave_list)) return first_slave(m);
return __propagation_next(m, origin);
}
staticstruct mount *skip_propagation_subtree(struct mount *m, struct mount *origin)
{ /* *Advancempasteverythingthatgetspropagationfromit.
*/ struct mount *p = __propagation_next(m, origin);
while (p && peers(m, p))
p = __propagation_next(p, origin);
return p;
}
staticstruct mount *next_group(struct mount *m, struct mount *origin)
{ while (1) { while (1) { struct mount *next; if (!IS_MNT_NEW(m) && !hlist_empty(&m->mnt_slave_list)) return first_slave(m);
next = next_peer(m); if (m->mnt_group_id == origin->mnt_group_id) { if (next == origin) return NULL;
} elseif (m->mnt_slave.next != &next->mnt_slave) break;
m = next;
} /* m is the last peer */ while (1) { struct mount *master = m->mnt_master; if (m->mnt_slave.next) return next_slave(m);
m = next_peer(master); if (master->mnt_group_id == origin->mnt_group_id) break; if (master->mnt_slave.next == &m->mnt_slave) break;
m = master;
} if (m == origin) return NULL;
}
}
staticbool need_secondary(struct mount *m, struct mountpoint *dest_mp)
{ /* skip ones added by this propagate_mnt() */ if (IS_MNT_NEW(m)) returnfalse; /* skip if mountpoint isn't visible in m */ if (!is_subdir(dest_mp->m_dentry, m->mnt.mnt_root)) returnfalse; /* skip if m is in the anon_ns */ if (is_anon_ns(m->mnt_ns)) returnfalse; returntrue;
}
staticstruct mount *find_master(struct mount *m, struct mount *last_copy, struct mount *original)
{ struct mount *p;
// ascend until there's a copy for something with the same master for (;;) {
p = m->mnt_master; if (!p || IS_MNT_MARKED(p)) break;
m = p;
} while (!peers(last_copy, original)) { struct mount *parent = last_copy->mnt_parent; if (parent->mnt_master == p) { if (!peers(parent, m))
last_copy = last_copy->mnt_master; break;
}
last_copy = last_copy->mnt_master;
} return last_copy;
}
/** *propagate_mnt()-createsecondarycopiesfortreeattachment *@dest_mnt:destinationmount. *@dest_mp:destinationmountpoint. *@source_mnt:sourcemount. *@tree_list:listofsecondariestobeattached. * *Createsecondarycopiesforattachingatreewithroot@source_mnt *atmount@dest_mntwithmountpoint@dest_mp.Linkallnewmounts *intoapropagationgraph.Setmountpointsforallsecondaries, *linktheirrootsinto@tree_listvia->mnt_hash.
*/ int propagate_mnt(struct mount *dest_mnt, struct mountpoint *dest_mp, struct mount *source_mnt, struct hlist_head *tree_list)
{ struct mount *m, *n, *copy, *this; int err = 0, type;
if (dest_mnt->mnt_master)
SET_MNT_MARK(dest_mnt->mnt_master);
/* iterate over peer groups, depth first */ for (m = dest_mnt; m && !err; m = next_group(m, dest_mnt)) { if (m == dest_mnt) { // have one for dest_mnt itself
copy = source_mnt;
type = CL_MAKE_SHARED;
n = next_peer(m); if (n == m) continue;
} else {
type = CL_SLAVE; /* beginning of peer group among the slaves? */ if (IS_MNT_SHARED(m))
type |= CL_MAKE_SHARED;
n = m;
} do { if (!need_secondary(n, dest_mp)) continue; if (type & CL_SLAVE) // first in this peer group
copy = find_master(n, copy, source_mnt); this = copy_tree(copy, copy->mnt.mnt_root, type); if (IS_ERR(this)) {
err = PTR_ERR(this); break;
}
read_seqlock_excl(&mount_lock);
mnt_set_mountpoint(n, dest_mp, this);
read_sequnlock_excl(&mount_lock); if (n->mnt_master)
SET_MNT_MARK(n->mnt_master);
copy = this;
hlist_add_head(&this->mnt_hash, tree_list);
err = count_mounts(n->mnt_ns, this); if (err) break;
type = CL_MAKE_SHARED;
} while ((n = next_peer(n)) != m);
}
hlist_for_each_entry(n, tree_list, mnt_hash) {
m = n->mnt_parent; if (m->mnt_master)
CLEAR_MNT_MARK(m->mnt_master);
} if (dest_mnt->mnt_master)
CLEAR_MNT_MARK(dest_mnt->mnt_master); return err;
}
/* *returntrueiftherefcountisgreaterthancount
*/ staticinlineint do_refcount_check(struct mount *mnt, int count)
{ return mnt_get_count(mnt) > count;
}
for (struct mount *m = propagation_next(parent, parent); m;
m = propagation_next(m, parent)) { struct list_head *head; struct mount *child = __lookup_mnt(&m->mnt, mnt->mnt_mountpoint);
if (!child) continue;
head = &child->mnt_mounts; if (!list_empty(head)) { /* *amountthatcoverschildcompletelywouldn'tprevent *itbeingpulledout;anyotherwould.
*/ if (!list_is_singular(head) || !child->overmount) continue;
} if (do_refcount_check(child, 1)) return1;
} return0;
}
/* *ClearMNT_LOCKEDwhenitcanbeshowntobesafe. * *mount_locklockmustbeheldforwrite
*/ void propagate_mount_unlock(struct mount *mnt)
{ struct mount *parent = mnt->mnt_parent; struct mount *m, *child;
BUG_ON(parent == mnt);
for (m = propagation_next(parent, parent); m;
m = propagation_next(m, parent)) {
child = __lookup_mnt(&m->mnt, mnt->mnt_mountpoint); if (child)
child->mnt.mnt_flags &= ~MNT_LOCKED;
}
}
staticinlinebool is_candidate(struct mount *m)
{ return m->mnt_t_flags & T_UMOUNT_CANDIDATE;
}
list_for_each_entry(m, set, mnt_list) { if (is_candidate(m)) continue;
m->mnt_t_flags |= T_UMOUNT_CANDIDATE;
p = m->mnt_parent;
q = propagation_next(p, p); while (q) { struct mount *child = __lookup_mnt(&q->mnt,
m->mnt_mountpoint); if (child) { /* *Wemight'vealreadyrunintothisone.That *must'vehappenedonearlieriterationofthe *outerloop;inthatcasewecanskipthose *parentsthatgetpropagationfromq-there *willbenothingnewonthoseaswell.
*/ if (is_candidate(child)) {
q = skip_propagation_subtree(q, p); continue;
}
child->mnt_t_flags |= T_UMOUNT_CANDIDATE; if (!will_be_unmounted(child))
list_add(&child->mnt_list, candidates);
}
q = propagation_next(q, p);
}
}
list_for_each_entry(m, set, mnt_list)
m->mnt_t_flags &= ~T_UMOUNT_CANDIDATE;
}
/* *Weknowthatsomechildof@mcan'tbeunmounted.Inallplaceswherethe *chainofdescentof@mhaschildnotovermountingtherootofparent, *theparentcan'tbeunmountedeither.
*/ staticvoid trim_ancestors(struct mount *m)
{ struct mount *p;
for (p = m->mnt_parent; is_candidate(p); m = p, p = p->mnt_parent) { if (IS_MNT_MARKED(m)) // all candidates beneath are overmounts return;
SET_MNT_MARK(m); if (m != p->overmount)
p->mnt_t_flags &= ~T_UMOUNT_CANDIDATE;
}
}
if (!is_candidate(m)) { // trim_ancestors() left it on list
remove_from_candidate_list(m); return;
}
list_for_each_entry(n, &m->mnt_mounts, mnt_child) { if (!is_candidate(n)) {
found = true; if (n != m->overmount) {
remove_this = true; break;
}
}
} if (found) {
trim_ancestors(m);
} elseif (!IS_MNT_LOCKED(m) && list_empty(&m->mnt_mounts)) {
remove_this = true;
umount_this = true;
} if (remove_this) {
remove_from_candidate_list(m); if (umount_this)
umount_one(m, to_umount);
}
}
staticvoid handle_locked(struct mount *m, struct list_head *to_umount)
{ struct mount *cutoff = m, *p;
if (!is_candidate(m)) { // trim_ancestors() left it on list
remove_from_candidate_list(m); return;
} for (p = m; is_candidate(p); p = p->mnt_parent) {
remove_from_candidate_list(p); if (!IS_MNT_LOCKED(p))
cutoff = p->mnt_parent;
} if (will_be_unmounted(p))
cutoff = p; while (m != cutoff) {
umount_one(m, to_umount);
m = m->mnt_parent;
}
}
/* *@misnottogoingaway,anditovermountsthetopofastackofmounts *thataregoingaway.Weknowthatallofthosearefullyovermounted *bytheoneabove(@mbeingthetopmostofthechain),so@mcanbeslid *inplacewherethebottomofthestackisattached. * *NOTE:herewetemporarilyviolateaconstraint-twomountsendupwith *thesameparentandmountpoint;thatwillberemediedassoonaswe *returnfrompropagate_umount()-itscaller(umount_tree())willdetach *thestackfromtheparentit(andnow@m)isattachedto.umount_tree() *mightchoosetokeepunmountedpiecesstucktoeachother,butitalways *detachesthemfromthemountsthatremaininthetree.
*/ staticvoid reparent(struct mount *m)
{ struct mount *p = m; struct mountpoint *mp;
do {
mp = p->mnt_mp;
p = p->mnt_parent;
} while (will_be_unmounted(p));
// collect all candidates
gather_candidates(set, &candidates);
// reduce the set until it's non-shifting
list_for_each_entry_safe(m, p, &candidates, mnt_list)
trim_one(m, &to_umount);
// ... and non-revealing while (!list_empty(&candidates)) {
m = list_first_entry(&candidates,struct mount, mnt_list);
handle_locked(m, &to_umount);
}
// now to_umount consists of all acceptable candidates // deal with reparenting of surviving overmounts on those
list_for_each_entry(m, &to_umount, mnt_list) { struct mount *over = m->overmount; if (over && !will_be_unmounted(over))
reparent(over);
}
// and fold them into the set
list_splice_tail_init(&to_umount, set);
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.72Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.