added persistence option to HostWithPrivateDirs. also attached mount namespaces when mnexec -a is specified
This commit is contained in:
+3
-1
@@ -20,7 +20,9 @@ from functools import partial
|
|||||||
def testHostWithPrivateDirs():
|
def testHostWithPrivateDirs():
|
||||||
"Test bind mounts"
|
"Test bind mounts"
|
||||||
topo = SingleSwitchTopo( 10 )
|
topo = SingleSwitchTopo( 10 )
|
||||||
privateDirs = [ '/var/log', '/var/run' ]
|
privateDirs = [ ( '/var/log', '/onos/%(name)s/var/log' ),
|
||||||
|
( '/var/run', '/ovx/%(name)s/var/run' ),
|
||||||
|
'/mn' ]
|
||||||
host = partial( HostWithPrivateDirs,
|
host = partial( HostWithPrivateDirs,
|
||||||
privateDirs=privateDirs )
|
privateDirs=privateDirs )
|
||||||
net = Mininet( topo=topo, host=host )
|
net = Mininet( topo=topo, host=host )
|
||||||
|
|||||||
+17
-3
@@ -728,14 +728,28 @@ class CPULimitedHost( Host ):
|
|||||||
class HostWithPrivateDirs( Host ):
|
class HostWithPrivateDirs( Host ):
|
||||||
"Host with private directories"
|
"Host with private directories"
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs ):
|
def __init__(self, name, *args, **kwargs ):
|
||||||
"""privateDirs: list of private directories"""
|
"""privateDirs: list of private directories"""
|
||||||
|
self.name = name
|
||||||
self.privateDirs = kwargs.pop( 'privateDirs', [] )
|
self.privateDirs = kwargs.pop( 'privateDirs', [] )
|
||||||
Host.__init__( self, *args, **kwargs )
|
Host.__init__( self, name, *args, **kwargs )
|
||||||
self.mountPrivateDirs()
|
self.mountPrivateDirs()
|
||||||
|
|
||||||
def mountPrivateDirs( self ):
|
def mountPrivateDirs( self ):
|
||||||
|
"mount the directories that have specified mountpoints"
|
||||||
|
for directory in self.privateDirs:
|
||||||
|
if isinstance( directory, tuple ):
|
||||||
|
privateDir = directory[ 1 ] %self.__dict__
|
||||||
|
mountPoint = directory[ 0 ]
|
||||||
|
self.cmd( 'mkdir -p %s' %privateDir )
|
||||||
|
self.cmd( 'mkdir -p %s' %mountPoint )
|
||||||
|
self.cmd( 'mount --bind %s %s' %( privateDir, mountPoint ) )
|
||||||
|
else:
|
||||||
|
self.cmd( 'mkdir -p %s' %directory )
|
||||||
|
self.cmd( 'mount -n -t tmpfs tmpfs %s' %directory )
|
||||||
|
|
||||||
|
|
||||||
|
def mountTempDirs( self ):
|
||||||
"Mount tmpfs for each private directory"
|
"Mount tmpfs for each private directory"
|
||||||
for dir_ in self.privateDirs:
|
for dir_ in self.privateDirs:
|
||||||
self.cmd( 'mkdir -p ' + dir_ )
|
self.cmd( 'mkdir -p ' + dir_ )
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ int main(int argc, char *argv[])
|
|||||||
perror("mount");
|
perror("mount");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
/* print pid */
|
/* print pid */
|
||||||
@@ -140,7 +141,7 @@ int main(int argc, char *argv[])
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
/* Attach to pid's network namespace */
|
/* Attach to pid's network namespace and mount namespace*/
|
||||||
pid = atoi(optarg);
|
pid = atoi(optarg);
|
||||||
sprintf(path, "/proc/%d/ns/net", pid );
|
sprintf(path, "/proc/%d/ns/net", pid );
|
||||||
nsid = open(path, O_RDONLY);
|
nsid = open(path, O_RDONLY);
|
||||||
@@ -152,6 +153,18 @@ int main(int argc, char *argv[])
|
|||||||
perror("setns");
|
perror("setns");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
sprintf(path, "/proc/%d/ns/mnt", pid );
|
||||||
|
nsid = open(path, O_RDONLY);
|
||||||
|
if (nsid < 0) {
|
||||||
|
perror(path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (setns(nsid, 0) != 0) {
|
||||||
|
perror("setns");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
/* Attach to cgroup */
|
/* Attach to cgroup */
|
||||||
|
|||||||
Reference in New Issue
Block a user