def unmount_host_device(device, cid): try: cpid = JBoxVol.get_pid(cid) cumount = create_container_mnt_command(cpid, "umount %s" % (device,)) crmdev = create_container_mnt_command(cpid, "rm %s" % (device,)) cumount() crmdev() return True except: JBoxVol.log_exception("Exception unmounting device %s from %s", device. cid) return False
def unmount_host_device(device, cid): try: cpid = JBoxVol.get_pid(cid) cumount = create_container_mnt_command(cpid, "umount %s" % (device, )) crmdev = create_container_mnt_command(cpid, "rm %s" % (device, )) cumount() crmdev() return True except: JBoxVol.log_exception("Exception unmounting device %s from %s", device.cid) return False
def mount_host_device(device, cid, container_path): try: cpid = JBoxVol.get_pid(cid) JBoxVol.duplicate_host_blockdevice(device, cpid) mount_cmd = "mount %s %s" % (device, container_path) cmount = create_container_mnt_command(cpid, mount_cmd) cmount() return True except: JBoxVol.log_exception("Exception mounting device %s at %s/%s", device. cid, container_path) return False
def duplicate_host_blockdevice(device, cpid): device_versions = JBoxVol.SH_DEVICE_VERSION(device) device_versions = [int(x, 16) for x in device_versions.split(',')] # mknod the same device in the container # can check existing device as: sh -c "[ -b /dev/loop1 ] || mknod --mode 0600 /dev/loop1 b 7 0 # but safer not to overwrite any existing device and throw error instead mknod_cmd = "mknod --mode 0600 %s b %d %d" % (device, device_versions[0], device_versions[1]) cmknod = create_container_mnt_command(cpid, mknod_cmd) cmknod() return True
def mount_host_device(device, cid, container_path): try: cpid = JBoxVol.get_pid(cid) JBoxVol.duplicate_host_blockdevice(device, cpid) mount_cmd = "mount %s %s" % (device, container_path) cmount = create_container_mnt_command(cpid, mount_cmd) cmount() return True except: JBoxVol.log_exception("Exception mounting device %s at %s/%s", device.cid, container_path) return False
def duplicate_host_blockdevice(device, cpid): device_versions = JBoxVol.SH_DEVICE_VERSION(device) device_versions = [int(x, 16) for x in device_versions.split(',')] # mknod the same device in the container # can check existing device as: sh -c "[ -b /dev/loop1 ] || mknod --mode 0600 /dev/loop1 b 7 0 # but safer not to overwrite any existing device and throw error instead mknod_cmd = "mknod --mode 0600 %s b %d %d" % ( device, device_versions[0], device_versions[1]) cmknod = create_container_mnt_command(cpid, mknod_cmd) cmknod() return True