Exemplo n.º 1
0
// Release a shared or exclusive lock on an object.
func (ioctx *IOContext) Unlock(oid, name, cookie string) (int, error) {
	c_oid := C.CString(oid)
	c_name := C.CString(name)
	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_cookie))

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

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

	switch ret {
	case 0:
		return int(ret), nil
	case -2: // -ENOENT
		return int(ret), nil
	default:
		return int(ret), RadosError(int(ret))
	}
}
Exemplo n.º 2
0
// Unlock unlocks a locked object. This returns an error if the lock is not owned by the current client.
func (o *Object) Unlock(name, cookie string) error {
	oid := C.CString(o.name)
	defer freeString(oid)

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

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

	ret := C.rados_unlock(o.ioContext, oid, n, c)
	if int(ret) == -int(syscall.ENOENT) {
		err := toRadosError(ret)
		err.Message = fmt.Sprintf("%s does not own the lock.", o.name)
		return err
	}
	return nil
}