linux/fs/fs_struct.c
<<
>>
Prefs
   1#include <linux/export.h>
   2#include <linux/sched.h>
   3#include <linux/fs.h>
   4#include <linux/path.h>
   5#include <linux/slab.h>
   6#include <linux/fs_struct.h>
   7#include "internal.h"
   8
   9/*
  10 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
  11 * It can block.
  12 */
  13void set_fs_root(struct fs_struct *fs, struct path *path)
  14{
  15        struct path old_root;
  16
  17        path_get(path);
  18        spin_lock(&fs->lock);
  19        write_seqcount_begin(&fs->seq);
  20        old_root = fs->root;
  21        fs->root = *path;
  22        write_seqcount_end(&fs->seq);
  23        spin_unlock(&fs->lock);
  24        if (old_root.dentry)
  25                path_put(&old_root);
  26}
  27
  28/*
  29 * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
  30 * It can block.
  31 */
  32void set_fs_pwd(struct fs_struct *fs, struct path *path)
  33{
  34        struct path old_pwd;
  35
  36        path_get(path);
  37        spin_lock(&fs->lock);
  38        write_seqcount_begin(&fs->seq);
  39        old_pwd = fs->pwd;
  40        fs->pwd = *path;
  41        write_seqcount_end(&fs->seq);
  42        spin_unlock(&fs->lock);
  43
  44        if (old_pwd.dentry)
  45                path_put(&old_pwd);
  46}
  47
  48static inline int replace_path(struct path *p, const struct path *old, const struct path *new)
  49{
  50        if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
  51                return 0;
  52        *p = *new;
  53        return 1;
  54}
  55
  56void chroot_fs_refs(struct path *old_root, struct path *new_root)
  57{
  58        struct task_struct *g, *p;
  59        struct fs_struct *fs;
  60        int count = 0;
  61
  62        read_lock(&tasklist_lock);
  63        do_each_thread(g, p) {
  64                task_lock(p);
  65                fs = p->fs;
  66                if (fs) {
  67                        int hits = 0;
  68                        spin_lock(&fs->lock);
  69                        write_seqcount_begin(&fs->seq);
  70                        hits += replace_path(&fs->root, old_root, new_root);
  71                        hits += replace_path(&fs->pwd, old_root, new_root);
  72                        write_seqcount_end(&fs->seq);
  73                        while (hits--) {
  74                                count++;
  75                                path_get(new_root);
  76                        }
  77                        spin_unlock(&fs->lock);
  78                }
  79                task_unlock(p);
  80        } while_each_thread(g, p);
  81        read_unlock(&tasklist_lock);
  82        while (count--)
  83                path_put(old_root);
  84}
  85
  86void free_fs_struct(struct fs_struct *fs)
  87{
          +code=
  v2.6.16.2
  v2.6.16.54          +codlass="sref">fs->
  9ef">pfskmem_chil+co="+"+code=path_put" cla6.5chil+g" class="sref">6.5chil+gd(fs_struct *<5" cue="v2.6.16.54"
	  >
  9ef">pfs_structexiode=fs_struct" class="sref">fre  58        struct   84}
e_fs_struct(struct fs_struct *(& *= p->  85<9a>
fs)
  66                if (  87{
  67     kills="sref">fskill>   8<
  79                (& */*
                        spin_lock(&fs->(& *= p->p  67     kills="sref">fskill>spin_lock(&spin_lockuserf>                        spin_unlock(&fs->path)
  64                (& *  14{
  66fskill>ref="+code=path" class="sref0d_root;
  86void fs_struct *<5" cue="v2.6.16.54"
	  >
  106">  16
/*
e_fs_struct(struct   86void   86fs_struct" class="sref">free_fs_struct(struct mnt != e_fs_struct(struct fs_struct *fskmem_chil+calcod"+code=path_put" cla6.5chil+g" class="sref">6.5chil+gd(p *<5" cue="v2.6.16.54"
	  >
  1"> */
  12path)
  14{
  65                spin_lockuserf>  53     1ld_root;
  65                fsef=exed>h116">  16
          _ini  13void spin_unlock(&fs->path>);
void write_seqcount_end(&fs->lock>);
  65                (& *mnt != (& *href="+code=seq" class="sre1f">seq);
mnt != fs->  67     ="L21">  21        fs->mnt != fs->seq);
  83  +code=
  v2.6.16.2
  1">lock);
 ="L40">  40        fs->mnt != fs->  25  +codlass="sref">fs->
  1d_root);
                        mnt != fs->  16}
  27<1/a>
p->/*
  67     unshar="L86">  86void   86=spin"L13ref="+code=path" class="sref"> */
path)
e_fs_struct(struct fs_struct *        whileurre2 *= p->  33{
e_fs_struct(struct p *  86void   86fs_stfs_struct *<5" cue="v2.6.16.54"
	  >
  1old_pwd;
  67     kills="sref">fskill>  35<1/a>
path);
p *ref="+code=path" class="sref"7">  27<1>);
p/*);
pwd;
                        whileurre2 *<5" cue="v2.6.16.54"
	  >
  1f">path;
spin_lock(&fs->seq);
fskill>spin_lock(&spin_lockuserf>lock);
        whileurre2 *= p->p *path>)
                        spin_unlock(&fs->  64                        whileurre2 *<5" cue="v2.6.16.54"
	  >
  1f5">  35<1>);
  46}
  66fskill>ref="+code=path" class="sref47">  47<1/a>
  86void fs_struct *<5" cue="v2.6.16.54"
	  >
  1ef">new)
  49{
  51             1f">mnt))
p  86void   86=spi<5" cue="v2.6.16.54"
	  >
  1ef">new;
  54}
  35<1/a>
        whileurre2 *= p-> href="+code=old" clumask(& *href="+code=seq" class="sre1ew_root)
  47<1a>{
p(&
  1ef">new;
fs;
  12 =1 0;
e_fs_struct(struct fs_structefiode=>  61<1/a>
spin_lockuserf><<<<<<<<<<= 1,L14" class="line" name="L146f">new);
fs->fs-__SPIN_LOCK_UNLOCKED=task_unlock" class=efiode=sref">fs_structefiode=>code=old_pwd" cllass="sref">fs->fs->fsSEQCNT_ZEROt;  54);
(& *<<<<<<<<<<= 0022,L14" class="line" name="L146d_root>;
oldw_root =1 0;
  86void   86=spin"L13ref="+code=path" class="sref">lock);
seq);
e_fs_struct(struct fs_struct *        whileurre2 *= p->seq);
  67     kills="sref">fskill>  54                        whileurre2 *<5" cue="v2.6.16.54"
	  >
  1w_root);
  16
fs_structefiode=>code=old_pwd" cllass="sref">fs->
  1wts =1>);
fs_structefiode=>code=old_pwd" cluserf">spin_lockuserf>f="+code=count" class="sref">1         1  }
                        fs_structefiode=>code=old_pwd" cllass="sref">fs->
  1ref">p);
p);
spin_unlock(&fs->  67     curre2        whileurre2 *= p->fs_structefiode=>ef="+code=lock" class="sref1t">seq kills="sref">fskill>spin_lock(&spin_lockuserf>                        spin_unlock(&fs->  84}
  85<1/a>
  64                        whileurre2 *<5" cue="v2.6.16.54"
	  >
  1ref">fs)
  66fskill>ref="+code=path" class="sref7">  87{
  68 ame="L86">  86void fs_struct *<5" cue="v2.6.16.54"
	  >
  1v2.6.16.514pp
T;{pwriginal LXR software bygt;{p84" classhttp://sourceforge.net/projects/lxr">LXR lineufiohref=, this experie" nal verfion byg84" classmailto:lxr@llude.no>-&xr@llude.no>c
lts" clss="s
&xr.llude.no kindly hosted byg84" classhttp://www.redpill-llupro.no>-Redpill Llupro ASref=, provider of Lluuxhref=ulting and operanions services sinceL1995.
lts" clas/bodycls/html