static int testStorageLookup(const void *args) { const struct testLookupData *data = args; int ret = 0; const char *actualResult; virStorageFileMetadataPtr actualMeta; const char *actualParent; /* This function is documented as giving results within chain, but * as the same string may be duplicated into more than one field, * we rely on STREQ rather than pointer equality. Test twice to * ensure optional parameters don't cause NULL deref. */ actualResult = virStorageFileChainLookup(data->chain, data->name, NULL, NULL); if (!data->expResult) { if (!virGetLastError()) { fprintf(stderr, "call should have failed\n"); ret = -1; } virResetLastError(); } else { if (virGetLastError()) { fprintf(stderr, "call should not have warned\n"); ret = -1; } } if (STRNEQ_NULLABLE(data->expResult, actualResult)) { fprintf(stderr, "result 1: expected %s, got %s\n", NULLSTR(data->expResult), NULLSTR(actualResult)); ret = -1; } actualResult = virStorageFileChainLookup(data->chain, data->name, &actualMeta, &actualParent); if (!data->expResult) virResetLastError(); if (STRNEQ_NULLABLE(data->expResult, actualResult)) { fprintf(stderr, "result 2: expected %s, got %s\n", NULLSTR(data->expResult), NULLSTR(actualResult)); ret = -1; } if (data->expMeta != actualMeta) { fprintf(stderr, "meta: expected %p, got %p\n", data->expMeta, actualMeta); ret = -1; } if (STRNEQ_NULLABLE(data->expParent, actualParent)) { fprintf(stderr, "parent: expected %s, got %s\n", NULLSTR(data->expParent), NULLSTR(actualParent)); ret = -1; } return ret; }
void qemuDomainReAttachHostdevDevices(struct qemud_driver *driver, const char *name, virDomainHostdevDefPtr *hostdevs, int nhostdevs) { pciDeviceList *pcidevs; int i; if (!(pcidevs = qemuGetActivePciHostDeviceList(driver, hostdevs, nhostdevs))) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to allocate pciDeviceList: %s"), err ? err->message : _("unknown error")); virResetError(err); return; } /* Again 3 loops; mark all devices as inactive before reset * them and reset all the devices before re-attach */ for (i = 0; i < pciDeviceListCount(pcidevs); i++) { pciDevice *dev = pciDeviceListGet(pcidevs, i); pciDevice *activeDev = NULL; /* Never delete the dev from list driver->activePciHostdevs * if it's used by other domain. */ activeDev = pciDeviceListFind(driver->activePciHostdevs, dev); if (activeDev && STRNEQ_NULLABLE(name, pciDeviceGetUsedBy(activeDev))) { pciDeviceListSteal(pcidevs, dev); continue; } /* pciDeviceListFree() will take care of freeing the dev. */ pciDeviceListSteal(driver->activePciHostdevs, dev); } for (i = 0; i < pciDeviceListCount(pcidevs); i++) { pciDevice *dev = pciDeviceListGet(pcidevs, i); if (pciResetDevice(dev, driver->activePciHostdevs, driver->inactivePciHostdevs) < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to reset PCI device: %s"), err ? err->message : _("unknown error")); virResetError(err); } } for (i = 0; i < pciDeviceListCount(pcidevs); i++) { pciDevice *dev = pciDeviceListGet(pcidevs, i); qemuReattachPciDevice(dev, driver); } pciDeviceListFree(pcidevs); }
static int testCompareFiles(const char *vmx, const char *xml) { int result = -1; char *vmxData = NULL; char *xmlData = NULL; char *formatted = NULL; virDomainDefPtr def = NULL; virErrorPtr err = NULL; if (virtTestLoadFile(vmx, &vmxData) < 0) { goto failure; } if (virtTestLoadFile(xml, &xmlData) < 0) { goto failure; } def = virVMXParseConfig(&ctx, xmlopt, vmxData); if (def == NULL) { err = virGetLastError(); fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>"); goto failure; } formatted = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE); if (formatted == NULL) { err = virGetLastError(); fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>"); goto failure; } if (STRNEQ(xmlData, formatted)) { virtTestDifference(stderr, xmlData, formatted); goto failure; } result = 0; failure: VIR_FREE(vmxData); VIR_FREE(xmlData); VIR_FREE(formatted); virDomainDefFree(def); return result; }
static int mymain(void) { int ret = 0; if (!(mgr = virSecurityManagerNew("selinux", "QEMU", false, true, false))) { virErrorPtr err = virGetLastError(); if (err->code == VIR_ERR_CONFIG_UNSUPPORTED) exit(EXIT_AM_SKIP); fprintf(stderr, "Unable to initialize security driver: %s\n", err->message); exit(EXIT_FAILURE); } if ((caps = testQemuCapsInit()) == NULL) exit(EXIT_FAILURE); #define DO_TEST_LABELING(name) \ if (virtTestRun("Labelling " # name, 1, testSELinuxLabeling, name) < 0) \ ret = -1; \ setcon((security_context_t)"system_r:system_u:libvirtd_t:s0:c0.c1023"); DO_TEST_LABELING("disks"); DO_TEST_LABELING("kernel"); DO_TEST_LABELING("chardev"); return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }
void qemuReattachPciDevice(pciDevice *dev, struct qemud_driver *driver) { int retries = 100; /* If the device is not managed and was attached to guest * successfully, it must have been inactive. */ if (!pciDeviceGetManaged(dev)) { if (pciDeviceListAdd(driver->inactivePciHostdevs, dev) < 0) pciFreeDevice(dev); return; } while (pciWaitForDeviceCleanup(dev, "kvm_assigned_device") && retries) { usleep(100*1000); retries--; } if (pciReAttachDevice(dev, driver->activePciHostdevs, driver->inactivePciHostdevs) < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to re-attach PCI device: %s"), err ? err->message : _("unknown error")); virResetError(err); } pciFreeDevice(dev); }
/* --------------- * Misc utils * --------------- */ int virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason) { virDomainInfo info; virshControlPtr priv = ctl->privData; if (reason) *reason = -1; if (!priv->useGetInfo) { int state; if (virDomainGetState(dom, &state, reason, 0) < 0) { virErrorPtr err = virGetLastError(); if (err && err->code == VIR_ERR_NO_SUPPORT) priv->useGetInfo = true; else return -1; } else { return state; } } /* fall back to virDomainGetInfo if virDomainGetState is not supported */ if (virDomainGetInfo(dom, &info) < 0) return -1; else return info.state; }
static void virConsoleShutdown(virConsolePtr con) { virErrorPtr err = virGetLastError(); if (con->error.code == VIR_ERR_OK && err) virCopyLastError(&con->error); if (con->st) { virStreamEventRemoveCallback(con->st); virStreamAbort(con->st); virStreamFree(con->st); con->st = NULL; } VIR_FREE(con->streamToTerminal.data); VIR_FREE(con->terminalToStream.data); if (con->stdinWatch != -1) virEventRemoveHandle(con->stdinWatch); if (con->stdoutWatch != -1) virEventRemoveHandle(con->stdoutWatch); con->stdinWatch = -1; con->stdoutWatch = -1; if (!con->quit) { con->quit = true; virCondSignal(&con->cond); } }
static int virLXCProcessAutostartDomain(virDomainObjPtr vm, void *opaque) { const struct virLXCProcessAutostartData *data = opaque; int ret = 0; virObjectLock(vm); if (vm->autostart && !virDomainObjIsActive(vm)) { ret = virLXCProcessStart(data->conn, data->driver, vm, 0, NULL, false, VIR_DOMAIN_RUNNING_BOOTED); virDomainAuditStart(vm, "booted", ret >= 0); if (ret < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to autostart VM '%s': %s"), vm->def->name, err ? err->message : ""); } else { virObjectEventPtr event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_BOOTED); if (event) virObjectEventStateQueue(data->driver->domainEventState, event); } } virObjectUnlock(vm); return ret; }
void virNetMessageSaveError(virNetMessageErrorPtr rerr) { /* This func may be called several times & the first * error is the one we want because we don't want * cleanup code overwriting the first one. */ if (rerr->code != VIR_ERR_OK) return; memset(rerr, 0, sizeof(*rerr)); virErrorPtr verr = virGetLastError(); if (verr) { rerr->code = verr->code; rerr->domain = verr->domain; if (verr->message && VIR_ALLOC(rerr->message) == 0) *rerr->message = strdup(verr->message); rerr->level = verr->level; if (verr->str1 && VIR_ALLOC(rerr->str1) == 0) *rerr->str1 = strdup(verr->str1); if (verr->str2 && VIR_ALLOC(rerr->str2) == 0) *rerr->str2 = strdup(verr->str2); if (verr->str3 && VIR_ALLOC(rerr->str3) == 0) *rerr->str3 = strdup(verr->str3); rerr->int1 = verr->int1; rerr->int2 = verr->int2; } else { rerr->code = VIR_ERR_INTERNAL_ERROR; rerr->domain = VIR_FROM_RPC; if (VIR_ALLOC(rerr->message) == 0) *rerr->message = strdup(_("Library function returned error but did not set virError")); rerr->level = VIR_ERR_ERROR; } }
static int testTypedParamsValidate(const void *opaque) { int rv; TypedParameterTest *test = (TypedParameterTest *)opaque; virErrorPtr errptr; rv = virTypedParamsValidate( test->params, test->nparams, "foobar", VIR_TYPED_PARAM_STRING | test->foobar_flags, "foo", VIR_TYPED_PARAM_INT, "bar", VIR_TYPED_PARAM_UINT, NULL); if (test->expected_errcode) { errptr = virGetLastError(); rv = (errptr == NULL) || ((rv < 0) && !(errptr->code == test->expected_errcode)); if (errptr && test->expected_errmessage) { rv = STRNEQ(test->expected_errmessage, errptr->message); if (rv) printf("%s\n", errptr->message); } } return rv; }
static xmlDocPtr get_domain_xml (guestfs_h *g, virDomainPtr dom) { virErrorPtr err; xmlDocPtr doc; CLEANUP_FREE char *xml = virDomainGetXMLDesc (dom, 0); if (!xml) { err = virGetLastError (); error (g, _("error reading libvirt XML information: %s"), err->message); return NULL; } debug (g, "original domain XML:\n%s", xml); /* Parse the domain XML into an XML document. */ doc = xmlReadMemory (xml, strlen (xml), NULL, NULL, XML_PARSE_NONET); if (doc == NULL) { error (g, _("unable to parse XML information returned by libvirt")); return NULL; } return doc; }
static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED, pid_t initpid, virDomainObjPtr vm) { virLXCDriverPtr driver = lxc_driver; virLXCDomainObjPrivatePtr priv; virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); ino_t inode; virObjectLock(vm); priv = vm->privateData; priv->initpid = initpid; if (virLXCProcessGetNsInode(initpid, "pid", &inode) < 0) { virErrorPtr err = virGetLastError(); VIR_WARN("Cannot obtain pid NS inode for %llu: %s", (unsigned long long)initpid, err && err->message ? err->message : "<unknown>"); virResetLastError(); inode = 0; } virDomainAuditInit(vm, initpid, inode); if (virDomainSaveStatus(lxc_driver->xmlopt, cfg->stateDir, vm) < 0) VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name); virObjectUnlock(vm); virObjectUnref(cfg); }
static void print_libvirt_error (void) { virError * verr = virGetLastError(); if ( verr!=NULL ) { fprintf (stderr, "libvirt error: %s (code=%d)\n", verr->message, verr->code); virResetLastError(); } }
void StoragePoolControlThread::sendGlobalErrors() { virtErrors = virGetLastError(); if ( virtErrors!=NULL && virtErrors->code>0 ) emit errorMsg( QString("VirtError(%1) : %2").arg(virtErrors->code) .arg(QString().fromUtf8(virtErrors->message)) ); virResetLastError(); }
void ruby_libvirt_raise_error_if(const int condition, VALUE error, const char *method, virConnectPtr conn) { VALUE ruby_errinfo; virErrorPtr err; char *msg; int rc; struct rb_exc_new2_arg arg; int exception = 0; if (!condition) { return; } if (conn == NULL) { err = virGetLastError(); } else { err = virConnGetLastError(conn); } if (err != NULL && err->message != NULL) { rc = asprintf(&msg, "Call to %s failed: %s", method, err->message); } else { rc = asprintf(&msg, "Call to %s failed", method); } if (rc < 0) { /* there's not a whole lot we can do here; try to raise an * out-of-memory message */ rb_memerror(); } arg.error = error; arg.msg = msg; ruby_errinfo = rb_protect(ruby_libvirt_exc_new2_wrap, (VALUE)&arg, &exception); free(msg); if (exception) { rb_jump_tag(exception); } rb_iv_set(ruby_errinfo, "@libvirt_function_name", rb_str_new2(method)); if (err != NULL) { rb_iv_set(ruby_errinfo, "@libvirt_code", INT2NUM(err->code)); rb_iv_set(ruby_errinfo, "@libvirt_component", INT2NUM(err->domain)); rb_iv_set(ruby_errinfo, "@libvirt_level", INT2NUM(err->level)); if (err->message != NULL) { rb_iv_set(ruby_errinfo, "@libvirt_message", rb_str_new2(err->message)); } } rb_exc_raise(ruby_errinfo); };
void VM_Viewer::sendGlobalErrors() { virtErrors = virGetLastError(); if ( virtErrors!=NULL && virtErrors->code>0 ) { QString msg = QString("VirtError(%1) : %2").arg(virtErrors->code) .arg(QString().fromUtf8(virtErrors->message)); emit errorMsg( msg ); }; virResetLastError(); }
static int testSELinuxGenLabel(const void *opaque) { const struct testSELinuxGenLabelData *data = opaque; int ret = -1; virDomainDefPtr def; context_t con = NULL; context_t imgcon = NULL; if (setcon_raw((security_context_t)data->pidcon) < 0) { perror("Cannot set process security context"); return -1; } if (!(def = testBuildDomainDef(data->dynamic, data->label, data->baselabel))) goto cleanup; if (virSecurityManagerGenLabel(data->mgr, def) < 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "Cannot generate label: %s\n", err->message); goto cleanup; } VIR_DEBUG("label=%s imagelabel=%s", def->seclabels[0]->label, def->seclabels[0]->imagelabel); if (!(con = context_new(def->seclabels[0]->label))) goto cleanup; if (!(imgcon = context_new(def->seclabels[0]->imagelabel))) goto cleanup; if (!testSELinuxCheckCon(con, data->user, data->role, data->type, data->sensMin, data->sensMax, data->catMin, data->catMax)) goto cleanup; if (!testSELinuxCheckCon(imgcon, data->user, data->imagerole, data->imagetype, data->sensMin, data->sensMax, data->catMin, data->catMax)) goto cleanup; ret = 0; cleanup: context_free(con); context_free(imgcon); virDomainDefFree(def); return ret; }
QString _VirtThread::sendGlobalErrors() { QString msg; virtErrors = virGetLastError(); if ( virtErrors!=nullptr && virtErrors->code>0 ) { msg = QString("VirtError(%1) : %2").arg(virtErrors->code) .arg(QString().fromUtf8(virtErrors->message)); emit errorMsg( msg, number ); }; virResetLastError(); return msg; }
/** * virErrorPreserveLast: * @saveerr: pointer to virErrorPtr for storing last error object * * Preserves the currently set last error (for the thread) into @saveerr so that * it can be restored via virErrorRestore(). @saveerr must be passed to * virErrorRestore() */ void virErrorPreserveLast(virErrorPtr *saveerr) { int saved_errno = errno; virErrorPtr lasterr = virGetLastError(); *saveerr = NULL; if (lasterr) *saveerr = virErrorCopyNew(lasterr); errno = saved_errno; }
static int virLXCDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data) { virLXCDomainObjPrivatePtr priv = data; unsigned long long thepid; if (virXPathULongLong("string(./init[1]/@pid)", ctxt, &thepid) < 0) { virErrorPtr err = virGetLastError(); VIR_WARN("Failed to load init pid from state %s", err ? err->message : "null"); priv->initpid = 0; } else { priv->initpid = thepid; } return 0; }
/* * This tests sanity checking of our own certificates * * This code is done when libvirtd starts up, or before * a libvirt client connects. The test is ensuring that * the creation of virNetTLSContextPtr fails if we * give bogus certs, or succeeds for good certs */ static int testTLSContextInit(const void *opaque) { struct testTLSContextData *data = (struct testTLSContextData *)opaque; virNetTLSContextPtr ctxt = NULL; int ret = -1; if (data->isServer) { ctxt = virNetTLSContextNewServer(data->cacrt, NULL, data->crt, KEYFILE, NULL, true, true); } else { ctxt = virNetTLSContextNewClient(data->cacrt, NULL, data->crt, KEYFILE, true, true); } if (ctxt) { if (data->expectFail) { VIR_WARN("Expected failure %s against %s", data->cacrt, data->crt); goto cleanup; } } else { virErrorPtr err = virGetLastError(); if (!data->expectFail) { VIR_WARN("Unexpected failure %s against %s", data->cacrt, data->crt); goto cleanup; } VIR_DEBUG("Got error %s", err ? err->message : "<unknown>"); } ret = 0; cleanup: virObjectUnref(ctxt); return ret; }
static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool expect_error) { char *inXmlData = NULL; char *outXmlData = NULL; char *actual = NULL; int ret = -1; virNWFilterDefPtr dev = NULL; if (virtTestLoadFile(inxml, &inXmlData) < 0) goto fail; if (virtTestLoadFile(outxml, &outXmlData) < 0) goto fail; virResetLastError(); if (!(dev = virNWFilterDefParseString(NULL, inXmlData))) goto fail; if (!!virGetLastError() != expect_error) goto fail; if (expect_error) { /* need to suppress the errors */ virResetLastError(); } if (!(actual = virNWFilterDefFormat(dev))) goto fail; if (STRNEQ(outXmlData, actual)) { virtTestDifference(stderr, outXmlData, actual); goto fail; } ret = 0; fail: VIR_FREE(inXmlData); VIR_FREE(outXmlData); VIR_FREE(actual); virNWFilterDefFree(dev); return ret; }
void VirshType::Connect() { priv_state priv = set_root_priv(); if ( m_libvirt_connection ) { virConnectClose( m_libvirt_connection ); } m_libvirt_connection = virConnectOpen( m_sessionID.c_str() ); set_priv(priv); if( m_libvirt_connection == NULL ) { virErrorPtr err = virGetLastError(); EXCEPT("Failed to create libvirt connection: %s", (err ? err->message : "No reason found")); } }
static void gvir_storage_pool_constructed(GObject *object) { GVirStoragePool *conn = GVIR_STORAGE_POOL(object); GVirStoragePoolPrivate *priv = conn->priv; G_OBJECT_CLASS(gvir_storage_pool_parent_class)->constructed(object); /* xxx we may want to turn this into an initable */ if (virStoragePoolGetUUIDString(priv->handle, priv->uuid) < 0) { virErrorPtr verr = virGetLastError(); if (verr) { g_warning("Failed to get storage pool UUID on %p: %s", priv->handle, verr->message); } else { g_warning("Failed to get storage pool UUID on %p", priv->handle); } } }
static int testSELinuxLabeling(const void *opaque) { const char *testname = opaque; int ret = -1; testSELinuxFile *files = NULL; size_t nfiles = 0; size_t i; virDomainDefPtr def = NULL; if (testSELinuxLoadFileList(testname, &files, &nfiles) < 0) goto cleanup; if (testSELinuxCreateDisks(files, nfiles) < 0) goto cleanup; if (!(def = testSELinuxLoadDef(testname))) goto cleanup; if (virSecurityManagerSetAllLabel(mgr, def, NULL) < 0) goto cleanup; if (testSELinuxCheckLabels(files, nfiles) < 0) goto cleanup; ret = 0; cleanup: if (testSELinuxDeleteDisks(files, nfiles) < 0) VIR_WARN("unable to fully clean up"); virDomainDefFree(def); for (i = 0; i < nfiles; i++) { VIR_FREE(files[i].file); VIR_FREE(files[i].context); } VIR_FREE(files); if (ret < 0) { virErrorPtr err = virGetLastError(); VIR_TEST_VERBOSE("%s\n", err ? err->message : "<unknown>"); } return ret; }
static void gvir_network_constructed(GObject *object) { GVirNetwork *net = GVIR_NETWORK(object); GVirNetworkPrivate *priv = net->priv; G_OBJECT_CLASS(gvir_network_parent_class)->constructed(object); /* xxx we may want to turn this into an initable */ if (virNetworkGetUUIDString(priv->handle, priv->uuid) < 0) { virErrorPtr verr = virGetLastError(); if (verr) { g_warning("Failed to get network UUID on %p: %s", priv->handle, verr->message); } else { g_warning("Failed to get network UUID on %p", priv->handle); } } }
static int bhyveAutostartDomain(virDomainObjPtr vm, void *opaque) { const struct bhyveAutostartData *data = opaque; int ret = 0; virObjectLock(vm); if (vm->autostart && !virDomainObjIsActive(vm)) { virResetLastError(); ret = virBhyveProcessStart(data->conn, data->driver, vm, VIR_DOMAIN_RUNNING_BOOTED, 0); if (ret < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to autostart VM '%s': %s"), vm->def->name, err ? err->message : _("unknown error")); } } virObjectUnlock(vm); return ret; }
static int mymain(void) { int ret = 0; char *filedata = NULL; char *filename = NULL; size_t i; size_t *params = NULL; if (virAsprintf(&filename, "%s/../daemon/libvirtd.conf", abs_srcdir) < 0) { perror("Format filename"); return EXIT_FAILURE; } if (virFileReadAll(filename, 1024*1024, &filedata) < 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "Cannot load %s for testing: %s", filename, err->message); ret = -1; goto cleanup; } if (uncomment_all_params(filedata, ¶ms) < 0) { perror("Find params"); ret = -1; goto cleanup; } VIR_DEBUG("Initial config [%s]", filedata); for (i = 0; params[i] != 0; i++) { const struct testCorruptData data = { params, filedata, filename, i }; /* Skip now ignored config param */ if (STRPREFIX(filedata + params[i], "log_buffer_size")) continue; if (virtTestRun("Test corruption", testCorrupt, &data) < 0) ret = -1; } cleanup: VIR_FREE(filename); VIR_FREE(filedata); VIR_FREE(params); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
static int mymain(void) { int ret = 0; int rc = testUserXattrEnabled(); if (rc < 0) return EXIT_FAILURE; if (!rc) return EXIT_AM_SKIP; if (!(mgr = virSecurityManagerNew("selinux", "QEMU", VIR_SECURITY_MANAGER_DEFAULT_CONFINED | VIR_SECURITY_MANAGER_PRIVILEGED))) { virErrorPtr err = virGetLastError(); VIR_TEST_VERBOSE("Unable to initialize security driver: %s\n", err->message); return EXIT_FAILURE; } if ((caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; #define DO_TEST_LABELING(name) \ if (virtTestRun("Labelling " # name, testSELinuxLabeling, name) < 0) \ ret = -1; setcon((security_context_t)"system_r:system_u:libvirtd_t:s0:c0.c1023"); DO_TEST_LABELING("disks"); DO_TEST_LABELING("kernel"); DO_TEST_LABELING("chardev"); DO_TEST_LABELING("nfs"); qemuTestDriverFree(&driver); return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }
static int virLockManagerLockDaemonSetupLockspace(const char *path) { virNetClientPtr client; virNetClientProgramPtr program = NULL; virLockSpaceProtocolCreateLockSpaceArgs args; int rv = -1; int counter = 0; memset(&args, 0, sizeof(args)); args.path = (char*)path; if (!(client = virLockManagerLockDaemonConnectionNew(getuid() == 0, &program))) return -1; if (virNetClientProgramCall(program, client, counter++, VIR_LOCK_SPACE_PROTOCOL_PROC_CREATE_LOCKSPACE, 0, NULL, NULL, NULL, (xdrproc_t)xdr_virLockSpaceProtocolCreateLockSpaceArgs, (char*)&args, (xdrproc_t)xdr_void, NULL) < 0) { virErrorPtr err = virGetLastError(); if (err && err->code == VIR_ERR_OPERATION_INVALID) { /* The lockspace already exists */ virResetLastError(); rv = 0; } else { goto cleanup; } } rv = 0; cleanup: virObjectUnref(program); virNetClientClose(client); virObjectUnref(client); return rv; }