예제 #1
0
func Format(driver Driver, volumeUUID, fs string) error {
	log.WithFields(logrus.Fields{
		LOG_FIELD_REASON: LOG_REASON_PREPARE,
		LOG_FIELD_EVENT:  LOG_EVENT_FORMAT,
		LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
		LOG_FIELD_VOLUME: volumeUUID,
	}).Debug()
	dev, err := driver.GetVolumeDevice(volumeUUID)
	if err != nil {
		return err
	}
	if fs != "ext4" {
		return fmt.Errorf("unsupported filesystem ", fs)
	}
	if _, err := util.Execute("mkfs", []string{"-t", fs, dev}); err != nil {
		return err
	}
	log.WithFields(logrus.Fields{
		LOG_FIELD_REASON: LOG_REASON_COMPLETE,
		LOG_FIELD_EVENT:  LOG_EVENT_FORMAT,
		LOG_FIELD_OBJECT: LOG_OBJECT_VOLUME,
		LOG_FIELD_VOLUME: volumeUUID,
	}).Debug()
	return nil
}
예제 #2
0
func Mount(driver Driver, volumeUUID, mountPoint, fs, option string, needFormat bool, newNS string) error {
	dev, err := driver.GetVolumeDevice(volumeUUID)
	if err != nil {
		return err
	}
	if fs != "ext4" {
		return fmt.Errorf("unsupported filesystem ", fs)
	}
	if needFormat {
		if err := Format(driver, volumeUUID, fs); err != nil {
			return err
		}
	}
	if newNS == "" {
		newNS = "/proc/1/ns/mnt"
	}
	cmdline := []string{newNS, "-m", "-t", fs}
	if option != "" {
		cmdline = append(cmdline, option)
	}
	cmdline = append(cmdline, dev, mountPoint)
	log.WithFields(logrus.Fields{
		LOG_FIELD_REASON:     LOG_REASON_START,
		LOG_FIELD_EVENT:      LOG_EVENT_MOUNT,
		LOG_FIELD_VOLUME:     volumeUUID,
		LOG_FIELD_MOUNTPOINT: mountPoint,
		LOG_FIELD_OPTION:     cmdline,
	}).Debug()
	_, err = util.Execute(RANCHER_MOUNT_BINARY, cmdline)
	if err != nil {
		log.Error("Failed mount, ", err)
		return err
	}
	return nil
}
예제 #3
0
func (d *Driver) CompareSnapshot(id, compareID, volumeID string) (*metadata.Mappings, error) {
	includeSame := false
	if compareID == "" || compareID == id {
		compareID = id
		includeSame = true
	}
	snap1, _, err := d.getSnapshotAndVolume(id, volumeID)
	if err != nil {
		return nil, err
	}
	snap2, _, err := d.getSnapshotAndVolume(compareID, volumeID)
	if err != nil {
		return nil, err
	}

	dev := d.MetadataDevice
	out, err := util.Execute(THIN_PROVISION_TOOLS_BINARY, []string{"thin_delta",
		"--snap1", strconv.Itoa(snap1.DevID),
		"--snap2", strconv.Itoa(snap2.DevID),
		dev})
	if err != nil {
		return nil, err
	}
	mapping, err := metadata.DeviceMapperThinDeltaParser([]byte(out), d.ThinpoolBlockSize*SECTOR_SIZE, includeSame)
	if err != nil {
		return nil, err
	}
	return mapping, err
}
예제 #4
0
func (v *VfsObjectStoreDriver) Download(src, dst string) error {
	_, err := util.Execute("cp", []string{v.updatePath(src), dst})
	if err != nil {
		return err
	}
	return nil
}
예제 #5
0
func (v *VfsObjectStoreDriver) Upload(src, dst string) error {
	tmpDst := dst + ".tmp"
	if v.FileExists(tmpDst) {
		v.Remove(tmpDst)
	}
	if err := v.preparePath(dst); err != nil {
		return err
	}
	_, err := util.Execute("cp", []string{src, v.updatePath(tmpDst)})
	if err != nil {
		return err
	}
	_, err = util.Execute("mv", []string{v.updatePath(tmpDst), v.updatePath(dst)})
	if err != nil {
		return err
	}
	return nil
}
예제 #6
0
func (v *VfsObjectStoreDriver) List(path string) ([]string, error) {
	out, err := util.Execute("ls", []string{"-1", v.updatePath(path)})
	if err != nil {
		return nil, err
	}
	var result []string
	if len(out) == 0 {
		return result, nil
	}
	result = strings.Split(strings.TrimSpace(string(out)), "\n")
	return result, nil
}
예제 #7
0
func Unmount(driver Driver, mountPoint, newNS string) error {
	if newNS == "" {
		newNS = "/proc/1/ns/mnt"
	}
	cmdline := []string{newNS, "-u", mountPoint}
	log.WithFields(logrus.Fields{
		LOG_FIELD_REASON:     LOG_REASON_START,
		LOG_FIELD_EVENT:      LOG_EVENT_UMOUNT,
		LOG_FIELD_MOUNTPOINT: mountPoint,
		LOG_FIELD_OPTION:     cmdline,
	}).Debug()
	_, err := util.Execute(RANCHER_MOUNT_BINARY, cmdline)
	if err != nil {
		log.Error("Failed umount, ", err)
		return err
	}
	return nil
}