コード例 #1
0
ファイル: objects.go プロジェクト: objStorage/grados
// LockShared share locks an object. At the moment, lock duration cannot be specified so this locks the object
// indefinitely.
func (o *Object) LockShared(name, cookie, tag, description string, flags ...LibradosLock) error {
	oid := C.CString(o.name)
	defer freeString(oid)

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

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

	t := C.CString(tag)
	defer freeString(t)

	d := C.CString(description)
	defer freeString(d)

	f := 0
	for _, flag := range flags {
		f |= int(flag)
	}

	ret := C.rados_lock_shared(o.ioContext, oid, n, c, t, d, nil, C.uint8_t(f))
	switch int(ret) {
	case -int(syscall.EBUSY):
		err := toRadosError(ret)
		err.Message = fmt.Sprintf("%s is already locked by another client", o.name)
		return err
	case -int(syscall.EEXIST):
		err := toRadosError(ret)
		err.Message = fmt.Sprintf("%s is already locked by current client", o.name)
		return err
	}
	return nil
}
コード例 #2
0
ファイル: ioctx.go プロジェクト: kallax/go-ceph-1
// Take a shared lock on an object.
func (ioctx *IOContext) LockShared(oid, name, cookie, tag, desc string, duration time.Duration, flags *byte) (int, error) {
	c_oid := C.CString(oid)
	c_name := C.CString(name)
	c_cookie := C.CString(cookie)
	c_tag := C.CString(tag)
	c_desc := C.CString(desc)

	var c_duration C.struct_timeval
	if duration != 0 {
		tv := syscall.NsecToTimeval(time.Now().Add(duration).UnixNano())
		c_duration = C.struct_timeval{tv_sec: C.__time_t(tv.Sec), tv_usec: C.__suseconds_t(tv.Usec)}
	}

	var c_flags C.uint8_t
	if flags != nil {
		c_flags = C.uint8_t(*flags)
	}

	defer C.free(unsafe.Pointer(c_oid))
	defer C.free(unsafe.Pointer(c_name))
	defer C.free(unsafe.Pointer(c_cookie))
	defer C.free(unsafe.Pointer(c_tag))
	defer C.free(unsafe.Pointer(c_desc))

	ret := C.rados_lock_shared(
		ioctx.ioctx,
		c_oid,
		c_name,
		c_cookie,
		c_tag,
		c_desc,
		&c_duration,
		c_flags)

	// 0 on success, negative error code on failure
	// -EBUSY if the lock is already held by another (client, cookie) pair
	// -EEXIST if the lock is already held by the same (client, cookie) pair

	switch ret {
	case 0:
		return int(ret), nil
	case -16: // EBUSY
		return int(ret), nil
	case -17: // EEXIST
		return int(ret), nil
	default:
		return int(ret), RadosError(int(ret))
	}
}