22
22
from devlib .exception import TargetStableError
23
23
from devlib .utils .misc import list_to_ranges , isiterable
24
24
from devlib .utils .types import boolean
25
+ import devlib .utils .asyn as asyn
25
26
26
27
27
28
class Controller (object ):
@@ -53,9 +54,10 @@ def __init__(self, kind, hid, clist):
53
54
self .mount_point = None
54
55
self ._cgroups = {}
55
56
56
- def mount (self , target , mount_root ):
57
+ @asyn .asyncf
58
+ async def mount (self , target , mount_root ):
57
59
58
- mounted = target .list_file_systems ()
60
+ mounted = await target .list_file_systems . asyn ()
59
61
if self .mount_name in [e .device for e in mounted ]:
60
62
# Identify mount point if controller is already in use
61
63
self .mount_point = [
@@ -66,16 +68,18 @@ def mount(self, target, mount_root):
66
68
else :
67
69
# Mount the controller if not already in use
68
70
self .mount_point = target .path .join (mount_root , self .mount_name )
69
- target .execute ('mkdir -p {} 2>/dev/null' \
70
- .format (self .mount_point ), as_root = True )
71
- target .execute ('mount -t cgroup -o {} {} {}' \
72
- .format (',' .join (self .clist ),
73
- self .mount_name ,
74
- self .mount_point ),
75
- as_root = True )
71
+ cmd = 'mkdir -p {mount_point} 2>/dev/null && mount -t cgroup -o {clist} {name} {mount_point}'
72
+ await target .execute .asyn (
73
+ cmd .format (
74
+ clist = ',' .join (self .clist ),
75
+ name = self .mount_name ,
76
+ mount_point = self .mount_point ,
77
+ ),
78
+ as_root = True ,
79
+ )
76
80
77
81
# Check if this controller uses "noprefix" option
78
- output = target .execute ('mount | grep "{} "' .format (self .mount_name ))
82
+ output = await target .execute . asyn ('mount | grep "{} "' .format (self .mount_name ))
79
83
if 'noprefix' in output :
80
84
self ._noprefix = True
81
85
# self.logger.debug('Controller %s using "noprefix" option',
@@ -386,19 +390,30 @@ def __init__(self, target):
386
390
self .logger .debug ('Available hierarchies: %s' , hierarchy )
387
391
388
392
# Initialize controllers
389
- self . logger . info ( 'Available controllers:' )
390
- self . controllers = {}
391
- for ss in subsys :
393
+
394
+ @ asyn . asyncf
395
+ async def init_controller ( ss ) :
392
396
hid = ss .hierarchy
393
397
controller = Controller (ss .name , hid , hierarchy [hid ])
394
398
try :
395
- controller .mount (self .target , self .cgroup_root )
399
+ await controller .mount . asyn (self .target , self .cgroup_root )
396
400
except TargetStableError :
397
401
message = 'Failed to mount "{}" controller'
398
402
raise TargetStableError (message .format (controller .kind ))
399
403
self .logger .info (' %-12s : %s' , controller .kind ,
400
404
controller .mount_point )
401
- self .controllers [ss .name ] = controller
405
+
406
+ return controller
407
+
408
+ self .logger .info ('Available controllers:' )
409
+ controllers = self .target .async_manager .map_concurrently (
410
+ init_controller ,
411
+ subsys ,
412
+ )
413
+ self .controllers = {
414
+ ss .name : controller
415
+ for ss , controller in controllers .items ()
416
+ }
402
417
403
418
def list_subsystems (self ):
404
419
subsystems = []
0 commit comments