Example #1
0
func (r rbdUtil) GetLockOwner(image RbdImage, pool CephPool) (RbdOwner, error) {
	var owner RbdOwner

	// step: construct the command
	output, err := utils.Execute(defaultTimeout, "rbd", "-p", pool.Name, "lock", "list", image.Name)
	if err != nil {
		return owner, fmt.Errorf("%s, output: %s", err, output)
	}

	// step: parse the output
	reader := bufio.NewReader(strings.NewReader(string(output)))
	for {
		line, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		if matched := lockRegex.Match([]byte(line)); matched {
			matches := lockRegex.FindAllStringSubmatch(line, -1)
			owner.ClientID = matches[0][1]
			owner.LockID = matches[0][2]
			owner.Address = matches[0][3]
			owner.Session = matches[0][4]
		}
	}

	return owner, nil
}
Example #2
0
// Get a list of the pool
func (r rbdUtil) GetPools() ([]CephPool, error) {
	// step: get the pool output
	result, err := utils.Execute(defaultTimeout, "ceph", "osd", "lspools", "-f", "json")
	if err != nil {
		return nil, err
	}

	// step: parse the json output
	var pools []CephPool
	err = json.NewDecoder(strings.NewReader(string(result))).Decode(&pools)
	if err != nil {
		return nil, err
	}
	return pools, nil
}
Example #3
0
func (r rbdUtil) GetImages(pool CephPool) ([]RbdImage, error) {
	// step: get the pool output
	result, err := utils.Execute(defaultTimeout, "rbd", "-p", pool.Name, "ls", "-l", "--format", "json")
	if err != nil {
		return nil, err
	}

	// step: parse the json output
	var images []RbdImage
	err = json.NewDecoder(strings.NewReader(string(result))).Decode(&images)
	if err != nil {
		return nil, err
	}
	return images, nil
}
Example #4
0
// UnlockImage ... removes a rbd lock from the image
//	image:	the details of the image (name/pool) etc that you wish to remove the lock
func (r rbdUtil) UnlockImage(image RbdImage, cephPool CephPool) error {
	var name = image.Name
	var pool = cephPool.Name

	glog.Infof("Removing the lock on image: %s/%s", pool, name)
	// step: we get the owner of the image
	owner, err := r.GetLockOwner(image, cephPool)
	if err != nil {
		glog.V(4).Infof("Failed to get the lock owner of image: %s/%s, error: %s", pool, name, err)
		return err
	}

	// step: construct the command
	output, err := utils.Execute(defaultTimeout, "rbd", "-p", pool, "lock", "remove", name, owner.LockID, owner.ClientID)
	if err != nil {
		return fmt.Errorf("%s, output: %s", err, output)
	}

	return nil
}