Skip to content

Commit

Permalink
xen: stop using loop device in run.py
Browse files Browse the repository at this point in the history
This patch eliminates use of losetup in run.py when running OSv
on Xen. Instead of creating a loop device pointing to qcow2 or
raw image, run.py adds an entry to the xl config file pointing
directly to the OSv disk image like so:

disk=['/home/wkozaczuk/projects/osv/build/last/usr.img,qcow2,hda,rw']

or:

disk=['/home/wkozaczuk/projects/osv/build/last/usr.raw,raw,hda,rw']

In addition, we also enhance run.py to support 2nd disk when running
OSv on Xen. Finally, when executing run.py with '--dry-run', one can
see content of the xl config file which can be useful for
troubleshouting or manually running OSv using the xl utility.

Examples to run OSv on Xen:

./scripts/run.py -p xen #uses default qcow2 image build/last/usr.img

./scripts/run.py -nv -c 1 -p xen --script vif-bridge -b virbr0

./scripts/run.py -p xen --second-disk-image ./disk.raw

Fixes cloudius-systems#285
Fixes cloudius-systems#344

Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
  • Loading branch information
wkozaczuk committed Aug 14, 2024
1 parent a9a1fd8 commit 3a79c31
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ def start_osv_xen(options):
print("Unrecognized memory size", file=sys.stderr)
return

disk_type = "qcow2" if options.image_file.endswith(".img") else "raw"
disk_value = "'%s,%s,hda,rw'" % (options.image_file, disk_type)

if cmdargs.second_disk_image:
second_disk_type = "qcow2" if options.second_disk_image.endswith(".img") else "raw"
disk_value = disk_value + ",'%s,%s,hda,rw'" % (options.second_disk_image, second_disk_type)

if not options.novnc:
vncoptions = re.match("^(?P<vncaddr>[^:]*):?(?P<vncdisplay>[0-9]*$)", options.vnc)

Expand All @@ -387,7 +394,7 @@ def start_osv_xen(options):
"vcpus=%s" % (options.vcpus),
"maxcpus=%s" % (options.vcpus),
"name='osv-%d'" % (os.getpid()),
"disk=['/dev/loop%s,raw,hda,rw']" % os.getpid(),
"disk=[%s]" % (disk_value),
"serial='pty'",
"paused=0",
"on_crash='preserve'"
Expand All @@ -411,23 +418,22 @@ def start_osv_xen(options):
# Save the current settings of the stty
stty_save()

#create a loop device backed by image file
subprocess.call(["losetup", "/dev/loop%s" % os.getpid(), options.image_file])
# Launch qemu
cmdline = ["xl", "create"]
if not options.detach:
cmdline += ["-c"]
cmdline += [xenfile.name]
if options.dry_run:
print(format_args(cmdline))
print("\nContent of %s\n---------------------------" % xenfile.name)
for item in args:
print("%s" % item)
else:
subprocess.call(cmdline)
except:
pass
finally:
xenfile.close()
#delete loop device
subprocess.call(["losetup", "-d", "/dev/loop%s" % os.getpid()])
cleanups()

def start_osv_vmware(options):
Expand Down

0 comments on commit 3a79c31

Please sign in to comment.