@@ -45,6 +45,14 @@ def __init__(self, machine):
4545 self .expected_release = None
4646 self .vmlinux = None
4747
48+ # Detect root disks if we're called from scripts/boot/qemu-xxx
49+ base = os .path .dirname (sys .argv [0 ])
50+ path = f'{ base } /../../root-disks'
51+ if os .path .isdir (path ):
52+ self .root_disk_path = path
53+ else :
54+ self .root_disk_path = None
55+
4856 def machine_is (self , needle ):
4957 return self .machine .startswith (needle )
5058
@@ -79,6 +87,7 @@ def configure_from_args(self, orig_args):
7987 parser .add_argument ('--modules-path' , type = str , help = 'Path to modules tarball' )
8088 parser .add_argument ('--cap' , dest = 'machine_caps' , type = str , default = [], action = 'append' , help = 'Machine caps' )
8189 parser .add_argument ('--qemu-path' , dest = 'qemu_path' , type = str , help = 'Path to qemu bin directory' )
90+ parser .add_argument ('--root-disk-path' , dest = 'root_disk_path' , type = str , help = 'Path to root disk directory' )
8291 args = parser .parse_args (orig_args )
8392
8493 if args .gdb :
@@ -130,6 +139,9 @@ def configure_from_args(self, orig_args):
130139 if args .qemu_path :
131140 self .qemu_path = args .qemu_path
132141
142+ if args .root_disk_path :
143+ self .root_disk_path = args .root_disk_path
144+
133145 self .compat_rootfs = args .compat_rootfs
134146 self .use_vof = args .use_vof
135147 self .quiet = args .quiet
@@ -145,7 +157,11 @@ def apply_defaults(self):
145157 if not self .vmlinux :
146158 logging .error ("Can't find kernel vmlinux" )
147159 return
148-
160+
161+ if not self .root_disk_path :
162+ logging .error ("Couldn't locate root disks" )
163+ return
164+
149165 if self .machine_is ('pseries' ):
150166 if self .accel == 'tcg' :
151167 self .machine_caps += ['cap-htm=off' ]
@@ -304,7 +320,7 @@ def prepare_cloud_image(self):
304320 if self .cloud_image is None :
305321 return
306322
307- rdpath = get_root_disk_path ()
323+ rdpath = self . root_disk_path
308324 img_path = f'{ rdpath } /{ self .cloud_image } '
309325
310326 if self .cloud_image .endswith ('.qcow2' ):
@@ -366,7 +382,7 @@ def cmd(self):
366382
367383 if self .initrd :
368384 l .append ('-initrd' )
369- l .append (get_root_disk ( self .initrd ))
385+ l .append (os . path . join ( self . root_disk_path , self .initrd ))
370386
371387 if len (self .drives ):
372388 l .extend (self .drives )
@@ -393,26 +409,6 @@ def qemu_monitor_shutdown(p):
393409 p .send ('quit' )
394410
395411
396- def get_root_disk_path ():
397- path = get_env_var ('ROOT_DISK_PATH' , None )
398- if path is not None :
399- return path
400-
401- base = os .path .dirname (sys .argv [0 ])
402- # Assumes we're called from scripts/boot/qemu-xxx
403- path = f'{ base } /../../root-disks'
404- if os .path .isdir (path ):
405- return path
406-
407- return ''
408-
409-
410- def get_root_disk (fname ):
411- val = os .path .join (get_root_disk_path (), fname )
412- logging .debug (f'Using rootfs { val } ' )
413- return val
414-
415-
416412def get_qemu_version (emulator ):
417413 p = PexpectHelper ()
418414 p .spawn ('%s --version' % emulator , quiet = True )
0 commit comments