// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectRef
182575
func (c *Connect) Ref() error {
	var err C.virError
	ret := C.virConnectRefWrapper(c.ptr, &err)
	if ret == -1 {
		return makeError(&err)
	}
	return nil
}
1333035
func (c *Connect) NumOfDefinedDomains() (int, error) {
	var err C.virError
	result := int(C.virConnectNumOfDefinedDomainsWrapper(c.ptr, &err))
	if result == -1 {
		return 0, makeError(&err)
	}
	return result, nil
}
1275366
func connectAuthCallback(ccredlist C.virConnectCredentialPtr, ncred C.uint, callbackID C.int) C.int {
	cred := make([]*ConnectCredential, int(ncred))

	for i := 0; i < int(ncred); i++ {
		ccred := (C.virConnectCredentialPtr)(unsafe.Pointer((uintptr)(unsafe.Pointer(ccredlist)) + (unsafe.Sizeof(*ccredlist) * uintptr(i))))
		cred[i] = &ConnectCredential{
			Type:      ConnectCredentialType(ccred._type),
			Prompt:    C.GoString(ccred.prompt),
			Challenge: C.GoString(ccred.challenge),
			DefResult: C.GoString(ccred.defresult),
			ResultLen: -1,
		}
	}
	callbackEntry := getCallbackId(int(callbackID))
	callback, ok := callbackEntry.(ConnectAuthCallback)
	if !ok {
		panic("Unexpected callback type")
	}

	callback(cred)

	for i := 0; i < int(ncred); i++ {
		ccred := (C.virConnectCredentialPtr)(unsafe.Pointer((uintptr)(unsafe.Pointer(ccredlist)) + (unsafe.Sizeof(*ccredlist) * uintptr(i))))
		if cred[i].ResultLen >= 0 {
			ccred.result = C.CString(cred[i].Result)
			ccred.resultlen = C.uint(cred[i].ResultLen)
		}
	}

	return 0
}
1081237
func (_class VMGuestMetricsClass) GetCanUseHotplugVif(sessionID SessionRef, self VMGuestMetricsRef) (_retval TristateType, _err error) {
	_method := "VM_guest_metrics.get_can_use_hotplug_vif"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVMGuestMetricsRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertEnumTristateTypeToGo(_method + " -> ", _result.Value)
	return
}
102712
func (c *ChatRPC) ShouldRetryOnConnect(err error) bool {
	_, inputCanceled := err.(libkb.InputCanceledError)
	return !inputCanceled
}
833775
func (c *Connect) CompareHypervisorCPU(emulator string, arch string, machine string, virttype string, xmlDesc string, flags ConnectCompareCPUFlags) (CPUCompareResult, error) {
	if C.LIBVIR_VERSION_NUMBER < 4004000 {
		return CPU_COMPARE_ERROR, makeNotImplementedError("virConnectCompareHypervisorCPU")
	}

	var cemulator, carch, cmachine, cvirttype *C.char
	if emulator != "" {
		cemulator = C.CString(emulator)
		defer C.free(unsafe.Pointer(cemulator))
	}
	if arch != "" {
		carch = C.CString(arch)
		defer C.free(unsafe.Pointer(carch))
	}
	if machine != "" {
		cmachine = C.CString(machine)
		defer C.free(unsafe.Pointer(cmachine))
	}
	if virttype != "" {
		cvirttype = C.CString(virttype)
		defer C.free(unsafe.Pointer(cvirttype))
	}

	cxmlDesc := C.CString(xmlDesc)
	defer C.free(unsafe.Pointer(cxmlDesc))

	var err C.virError
	ret := C.virConnectCompareHypervisorCPUWrapper(c.ptr, cemulator, carch, cmachine, cvirttype, cxmlDesc, C.uint(flags), &err)
	if ret == C.VIR_CPU_COMPARE_ERROR {
		return CPU_COMPARE_ERROR, makeError(&err)
	}

	return CPUCompareResult(ret), nil
}
1026059
func (c *StoragePool) Ref() error {
	var err C.virError
	ret := C.virStoragePoolRefWrapper(c.ptr, &err)
	if ret == -1 {
		return makeError(&err)
	}
	return nil
}
77152
func (a *Adaptor) Reconnect() (err error) {
	if a.connected {
		a.Disconnect()
	}
	return a.Connect()
}
278113
func (c *NodeDevice) Ref() error {
	var err C.virError
	ret := C.virNodeDeviceRefWrapper(c.ptr, &err)
	if ret == -1 {
		return makeError(&err)
	}
	return nil
}
716172
func (b *BlockServerRemote) AddBlockReference(ctx context.Context, tlfID tlf.ID,
	id kbfsblock.ID, context kbfsblock.Context) (err error) {
	ctx = rpc.WithFireNow(ctx)
	b.log.LazyTrace(ctx, "BServer: AddRef %s", id)
	defer func() {
		b.log.LazyTrace(ctx, "BServer: AddRef %s done (err=%v)", id, err)
		if err != nil {
			b.deferLog.CWarningf(
				ctx, "AddBlockReference id=%s tlf=%s context=%s err=%v",
				id, tlfID, context, err)
		} else {
			b.deferLog.CDebugf(
				ctx, "AddBlockReference id=%s tlf=%s context=%s",
				id, tlfID, context)
		}
	}()

	arg := kbfsblock.MakeAddReferenceArg(tlfID, id, context)
	// Handle OverQuota errors at the caller
	return b.putConn.getClient().AddReference(ctx, arg)
}
332604
func (s *llStore) addRef() *llStore {
	s.m.Lock()
	s.refs += 1
	s.m.Unlock()

	return s
}
299568
func domainEventDeviceRemovedCallback(c C.virConnectPtr, d C.virDomainPtr,
	devAlias *C.char, opaque int) {

	domain := VirDomain{ptr: d}
	connection := VirConnection{ptr: c}

	eventDetails := DomainDeviceRemovedEvent{
		DevAlias: C.GoString(devAlias),
	}
	callDomainCallbackId(opaque, &connection, &domain, eventDetails)
}
983893
func (v *Stream) RecvHole(flags uint) (int64, error) {
	if C.LIBVIR_VERSION_NUMBER < 3004000 {
		return 0, makeNotImplementedError("virStreamSparseRecvHole")
	}

	var len C.longlong
	var err C.virError
	ret := C.virStreamRecvHoleWrapper(v.ptr, &len, C.uint(flags), &err)
	if ret < 0 {
		return 0, makeError(&err)
	}

	return int64(len), nil
}
265235
func AllowReconnection(v bool) Option {
	return func(c *client) Option {
		old := c.allowReconnect
		c.allowReconnect = v
		return AllowReconnection(old)
	}
}
1117917
func (d *DeleteEvent) GetRef() string {
	if d == nil || d.Ref == nil {
		return ""
	}
	return *d.Ref
}
39379
func (r *FileRef) DecRef() (err error) {
	if r == nil {
		return nil
	}

	r.m.Lock()

	r.refs--
	if r.refs <= 0 {
		for _, cb := range r.beforeCloseCallbacks {
			cb()
		}
		r.beforeCloseCallbacks = nil

		err = r.file.Close()

		for _, cb := range r.afterCloseCallbacks {
			cb()
		}
		r.afterCloseCallbacks = nil

		r.file = nil
	}

	r.m.Unlock()

	return err
}
1007628
func (c *Interface) Ref() error {
	var err C.virError
	ret := C.virInterfaceRefWrapper(c.ptr, &err)
	if ret == -1 {
		return makeError(&err)
	}
	return nil
}