Esempio n. 1
0
// Releases a shared or exclusive lock on an object, which was taken by the specified client.
func (ioctx *IOContext) BreakLock(oid, name, client, cookie string) (int, error) {
	c_oid := C.CString(oid)
	c_name := C.CString(name)
	c_client := C.CString(client)
	c_cookie := C.CString(cookie)

	defer C.free(unsafe.Pointer(c_oid))
	defer C.free(unsafe.Pointer(c_name))
	defer C.free(unsafe.Pointer(c_client))
	defer C.free(unsafe.Pointer(c_cookie))

	// 0 on success, negative error code on failure
	// -ENOENT if the lock is not held by the specified (client, cookie) pair
	// -EINVAL if the client cannot be parsed

	ret := C.rados_break_lock(
		ioctx.ioctx,
		c_oid,
		c_name,
		c_client,
		c_cookie)

	switch ret {
	case 0:
		return int(ret), nil
	case -2: // -ENOENT
		return int(ret), nil
	case -22: // -EINVAL
		return int(ret), nil
	default:
		return int(ret), RadosError(int(ret))
	}
}
Esempio n. 2
0
// BreakLock forcefully breaks the object lock. This fails if specified client does not hold the lock.
func (o *Object) BreakLock(name, client, cookie string) error {
	oid := C.CString(o.name)
	defer freeString(oid)

	n := C.CString(name)
	defer freeString(n)

	cl := C.CString(client)
	defer freeString(cl)

	c := C.CString(cookie)
	defer freeString(c)

	ret := C.rados_break_lock(o.ioContext, oid, n, cl, c)
	switch int(ret) {
	case -int(syscall.ENOENT):
		err := toRadosError(ret)
		err.Message = fmt.Sprintf("%s lock is not held by %s:%s", o.name, client, cookie)
		return err
	case -int(syscall.EINVAL):
		err := toRadosError(ret)
		err.Message = fmt.Sprintf("%s client cannot be parsed.", client)
		return err
	}
	return nil
}