[libvirt] 答复: [PATCH] libvirt: lxc: Add Get/Set vcpus for lxc
On 2014/8/22 17:50, Li Yang wrote: 1.Add function to get vcpu count for lxc(vcpucount) 2.Add function to set vcpu count for lxc(setvcpus) Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- src/lxc/lxc_driver.c | 159 ++ 1 files changed, 159 insertions(+), 0 deletions(-) Does def-vcpus affect anything? No matter how much vcpus I set in xml , it seems that the vcpu count in container is equal to the host pcpu count. Thanks for your respond. Yes, the vcpus in xml doesn't affect container internal vcpu count, I wrote these functions because I saw `virsh setmem/setmaxmem` has already been working on domain's xml although it doesn't affect container internal memory information. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] libvirt: lxc: Add Get/Set vcpus for lxc
1.Add function to get vcpu count for lxc(vcpucount) 2.Add function to set vcpu count for lxc(setvcpus) Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- src/lxc/lxc_driver.c | 159 ++ 1 files changed, 159 insertions(+), 0 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4741632..4df0738 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5617,6 +5617,162 @@ lxcDomainGetMetadata(virDomainPtr dom, return ret; } +static int +lxcDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, +unsigned int flags) +{ +virLXCDriverPtr driver = dom-conn-privateData; +virDomainObjPtr vm = NULL; +virDomainDefPtr persistentDef; +int ret = -1; +bool maximum; +unsigned int maxvcpus = 0; +virLXCDriverConfigPtr cfg = NULL; +virCapsPtr caps = NULL; + +virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG | + VIR_DOMAIN_VCPU_MAXIMUM | + VIR_DOMAIN_VCPU_GUEST, -1); + +if (!nvcpus || (unsigned short) nvcpus != nvcpus) { +virReportError(VIR_ERR_INVALID_ARG, + _(argument out of range: %d), nvcpus); +return -1; +} + +if (!(vm = lxcDomObjFromDomain(dom))) +goto cleanup; + +cfg = virLXCDriverGetConfig(driver); + +if (virDomainSetVcpusFlagsEnsureACL(dom-conn, vm-def, flags) 0) +goto cleanup; + +if (!(caps = virLXCDriverGetCapabilities(driver, false))) +goto cleanup; + +maximum = (flags VIR_DOMAIN_VCPU_MAXIMUM) != 0; +flags = ~VIR_DOMAIN_VCPU_MAXIMUM; + +if (virDomainLiveConfigHelperMethod(caps, driver-xmlopt, vm, flags, +persistentDef) 0) +goto cleanup; + +/* MAXIMUM cannot be mixed with LIVE. */ +if (maximum (flags VIR_DOMAIN_AFFECT_LIVE)) { +virReportError(VIR_ERR_INVALID_ARG, %s, + _(cannot adjust maximum on running domain)); +goto cleanup; +} + +if (flags VIR_DOMAIN_AFFECT_LIVE) +maxvcpus = vm-def-maxvcpus; +if (flags VIR_DOMAIN_AFFECT_CONFIG) { +if (!maxvcpus || maxvcpus persistentDef-maxvcpus) +maxvcpus = persistentDef-maxvcpus; +} +if (!maximum nvcpus maxvcpus) { +virReportError(VIR_ERR_INVALID_ARG, + _(requested vcpus is greater than max allowable + vcpus for the domain: %d %d), + nvcpus, maxvcpus); +goto cleanup; +} + +if (flags VIR_DOMAIN_VCPU_GUEST) { +virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, + _(changing of vCPU count isn't supported + via guest agent)); +goto cleanup; +} else { +if (flags VIR_DOMAIN_AFFECT_LIVE) { +virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, + _(Cannot hotplug vCPUS for LXC hypervisor)); +goto cleanup; +} + +if (flags VIR_DOMAIN_AFFECT_CONFIG) { +if (maximum) { +persistentDef-maxvcpus = nvcpus; +if (nvcpus persistentDef-vcpus) +persistentDef-vcpus = nvcpus; +} else { +persistentDef-vcpus = nvcpus; +} + +if (virDomainSaveConfig(cfg-configDir, persistentDef) 0) +goto cleanup; +} +} + +ret = 0; + + cleanup: +if (vm) +virObjectUnlock(vm); +virObjectUnref(caps); +virObjectUnref(cfg); +return ret; +} + + +static int +lxcDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) +{ +return lxcDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_AFFECT_LIVE); +} + + +static int +lxcDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags) +{ +virLXCDriverPtr driver = dom-conn-privateData; +virDomainObjPtr vm; +virDomainDefPtr def; +int ret = -1; +virCapsPtr caps = NULL; + +virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG | + VIR_DOMAIN_VCPU_MAXIMUM | + VIR_DOMAIN_VCPU_GUEST, -1); + +if (!(vm = lxcDomObjFromDomain(dom))) +return -1; + +if (virDomainGetVcpusFlagsEnsureACL(dom-conn, vm-def, flags) 0) +goto cleanup; + +if (!(caps = virLXCDriverGetCapabilities(driver, false))) +goto cleanup; + +if (virDomainLiveConfigHelperMethod(caps, driver-xmlopt, +vm, flags, def) 0) +goto cleanup; + +if (flags VIR_DOMAIN_AFFECT_LIVE) +def = vm-def; + +if (flags VIR_DOMAIN_VCPU_GUEST) { +virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, + _(vCPU count cannot be provided by the guest agent + for LXC hypervisor)); +goto cleanup; +} else { +if (flags VIR_DOMAIN_VCPU_MAXIMUM
[libvirt] [PATCH] virsh: man: Add LXC format info for domxml-from/to-native
Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh.pod |6 -- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index 9efb920..015f119 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1128,14 +1128,16 @@ in order to get or set the guest time. Convert the file Iconfig in the native guest configuration format named by Iformat to a domain XML format. For QEMU/KVM hypervisor, the Iformat argument must be Bqemu-argv. For Xen hypervisor, the -Iformat argument may be Bxen-xm or Bxen-sxpr. +Iformat argument may be Bxen-xm or Bxen-sxpr. For LXC hypervisor, +the Iformat argument must be Blxc-tools. =item Bdomxml-to-native Iformat Ixml Convert the file Ixml in domain XML format to the native guest configuration format named by Iformat. For QEMU/KVM hypervisor, the Iformat argument must be Bqemu-argv. For Xen hypervisor, the -Iformat argument may be Bxen-xm or Bxen-sxpr. +Iformat argument may be Bxen-xm or Bxen-sxpr. For LXC hypervisor, +the Iformat argument must be Blxc-tools. =item Bdump Idomain Icorefilepath [I--bypass-cache] { [I--live] | [I--crash] | [I--reset] } [I--verbose] [I--memory-only] -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virsh: Fix help info for freepages
Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh-host.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ae14311..ad821b3 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -263,10 +263,10 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) */ static const vshCmdInfo info_freepages[] = { {.name = help, - .data = N_(NUMA free memory) + .data = N_(NUMA free pages) }, {.name = desc, - .data = N_(display available free memory for the NUMA cell.) + .data = N_(display available free pages for the NUMA cell.) }, {.name = NULL} }; -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] man: virsh: Add 'vcpu_period' and 'vcpu_quota' support info for LXC
Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh.pod |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index f07deec..a2d89b2 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1570,7 +1570,7 @@ Idomain Allows you to show (and set) the domain scheduler parameters. The parameters available for each hypervisor are: -LXC (posix scheduler) : cpu_shares +LXC (posix scheduler) : cpu_shares, vcpu_period, vcpu_quota QEMU/KVM (posix scheduler): cpu_shares, vcpu_period, vcpu_quota, emulator_period, emulator_quota -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] libvirt: Fix 'quest' typo in comment
Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- src/libvirt.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 79bcdf1..143d319 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -2950,7 +2950,7 @@ virDomainSaveImageDefineXML(virConnectPtr conn, const char *file, * a crashed state after the dump completes. If @flags includes * VIR_DUMP_LIVE, then make the core dump while continuing to allow * the guest to run; otherwise, the guest is suspended during the dump. - * VIR_DUMP_RESET flag forces reset of the quest after dump. + * VIR_DUMP_RESET flag forces reset of the guest after dump. * The above three flags are mutually exclusive. * * Additionally, if @flags includes VIR_DUMP_BYPASS_CACHE, then libvirt @@ -3042,7 +3042,7 @@ virDomainCoreDump(virDomainPtr domain, const char *to, unsigned int flags) * a crashed state after the dump completes. If @flags includes * VIR_DUMP_LIVE, then make the core dump while continuing to allow * the guest to run; otherwise, the guest is suspended during the dump. - * VIR_DUMP_RESET flag forces reset of the quest after dump. + * VIR_DUMP_RESET flag forces reset of the guest after dump. * The above three flags are mutually exclusive. * * Additionally, if @flags includes VIR_DUMP_BYPASS_CACHE, then libvirt -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virsh: Return false if only '--wipe-storage' is assigned when undefine a domain
For now, if only '--wipe-storage' is assigned, user can undefine a domain normally. But actually '--wipe-storage' doesn't work, this may confuse user. And since '--wipe-storage' wipes data on the removed volumes, if no removed volume storage assigned, we'd better raise an error message. Before: $ virsh undefine virt-tests-vm1 --wipe-storage Domain virt-tests-vm1 has been undefined After: $ virsh undefine virt-tests-vm1 --wipe-storage error: '--wipe-storage' needs storage volume deletion: '--stroage string' or '--remove-all-storage' is necessary. Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh-domain.c |8 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3a7c260..25236a0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2982,6 +2982,14 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) ignore_value(vshCommandOptString(cmd, storage, vol_string)); +if (!(vol_string || remove_all_storage) wipe_storage) { +vshError(ctl, + _('--wipe-storage' needs storage volume deletion: + '--stroage string' or '--remove-all-storage' + is necessary.)); +return false; +} + if (managed_save) { flags |= VIR_DOMAIN_UNDEFINE_MANAGED_SAVE; managed_save_safe = true; -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 1/2] virsh: Replace list element to defined variable
Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh-secret.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 47974fe..e996c72 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -558,7 +558,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) const char *usageStr = virSecretUsageTypeTypeToString(usageType); char uuid[VIR_UUID_STRING_BUFLEN]; -if (virSecretGetUUIDString(list-secrets[i], uuid) 0) { +if (virSecretGetUUIDString(sec, uuid) 0) { vshError(ctl, %s, _(Failed to get uuid of secret)); goto cleanup; } -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/2] datatypes: Fix comment of secret uuid
Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- src/datatypes.h |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/datatypes.h b/src/datatypes.h index 9621c55..3bc2420 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -469,7 +469,7 @@ struct _virNodeDevice { struct _virSecret { virObject object; virConnectPtr conn; /* pointer back to the connection */ -unsigned char uuid[VIR_UUID_BUFLEN]; /* the domain unique identifier */ +unsigned char uuid[VIR_UUID_BUFLEN]; /* the secret unique identifier */ int usageType; /* the type of usage */ char *usageID; /* the usage's unique identifier */ }; -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virsh: Move 'cpu-baseline' to host command group
As manual said, 'cpu-baseline' isn't specific to a domain, it should not belong to domain command group, and it's used for host usually, so move it to host command group. Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh-domain.c | 115 - tools/virsh-host.c | 116 ++ 2 files changed, 116 insertions(+), 115 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 73414f8..16a8854 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6223,115 +6223,6 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) return ret; } -/* - * cpu-baseline command - */ -static const vshCmdInfo info_cpu_baseline[] = { -{.name = help, - .data = N_(compute baseline CPU) -}, -{.name = desc, - .data = N_(Compute baseline CPU for a set of given CPUs.) -}, -{.name = NULL} -}; - -static const vshCmdOptDef opts_cpu_baseline[] = { -{.name = file, - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_(file containing XML CPU descriptions) -}, -{.name = features, - .type = VSH_OT_BOOL, - .help = N_(Show features that are part of the CPU model type) -}, -{.name = NULL} -}; - -static bool -cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) -{ -const char *from = NULL; -bool ret = false; -char *buffer; -char *result = NULL; -char **list = NULL; -unsigned int flags = 0; -int count = 0; - -xmlDocPtr xml = NULL; -xmlNodePtr *node_list = NULL; -xmlXPathContextPtr ctxt = NULL; -virBuffer buf = VIR_BUFFER_INITIALIZER; -size_t i; - -if (vshCommandOptBool(cmd, features)) -flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; - -if (vshCommandOptStringReq(ctl, cmd, file, from) 0) -return false; - -if (virFileReadAll(from, VSH_MAX_XML_FILE, buffer) 0) -return false; - -/* add a separate container around the xml */ -virBufferStrcat(buf, container, buffer, /container, NULL); -if (virBufferError(buf)) -goto no_memory; - -VIR_FREE(buffer); -buffer = virBufferContentAndReset(buf); - - -if (!(xml = virXMLParseStringCtxt(buffer, from, ctxt))) -goto cleanup; - -if ((count = virXPathNodeSet(//cpu[not(ancestor::cpus)], - ctxt, node_list)) == -1) -goto cleanup; - -if (count == 0) { -vshError(ctl, _(No host CPU specified in '%s'), from); -goto cleanup; -} - -list = vshCalloc(ctl, count, sizeof(const char *)); - -for (i = 0; i count; i++) { -if (!(list[i] = virXMLNodeToString(xml, node_list[i]))) { -vshSaveLibvirtError(); -goto cleanup; -} -} - -result = virConnectBaselineCPU(ctl-conn, - (const char **)list, count, flags); - -if (result) { -vshPrint(ctl, %s, result); -ret = true; -} - - cleanup: -xmlXPathFreeContext(ctxt); -xmlFreeDoc(xml); -VIR_FREE(result); -if (list != NULL count 0) { -for (i = 0; i count; i++) -VIR_FREE(list[i]); -} -VIR_FREE(list); -VIR_FREE(buffer); -VIR_FREE(node_list); - -return ret; - - no_memory: -vshError(ctl, %s, _(Out of memory)); -ret = false; -goto cleanup; -} /* * cpu-stats command @@ -11472,12 +11363,6 @@ const vshCmdDef domManagementCmds[] = { .flags = 0 }, #endif -{.name = cpu-baseline, - .handler = cmdCPUBaseline, - .opts = opts_cpu_baseline, - .info = info_cpu_baseline, - .flags = 0 -}, {.name = cpu-compare, .handler = cmdCPUCompare, .opts = opts_cpu_compare, diff --git a/tools/virsh-host.c b/tools/virsh-host.c index cac6086..8273654 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -38,6 +38,7 @@ #include virxml.h #include virtypedparam.h #include virstring.h +#include virfile.h /* * capabilities command @@ -939,6 +940,115 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) goto cleanup; } +/* + * cpu-baseline command + */ +static const vshCmdInfo info_cpu_baseline[] = { +{.name = help, + .data = N_(compute baseline CPU) +}, +{.name = desc, + .data = N_(Compute baseline CPU for a set of given CPUs.) +}, +{.name = NULL} +}; + +static const vshCmdOptDef opts_cpu_baseline[] = { +{.name = file, + .type = VSH_OT_DATA, + .flags = VSH_OFLAG_REQ, + .help = N_(file containing XML CPU descriptions) +}, +{.name = features, + .type = VSH_OT_BOOL, + .help = N_(Show features that are part of the CPU model type) +}, +{.name = NULL} +}; + +static bool +cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) +{ +const char *from = NULL; +bool ret = false; +char *buffer; +char *result = NULL; +char **list = NULL; +unsigned int flags = 0; +int count = 0; + +xmlDocPtr
[libvirt] [PATCH v2] virsh: Separate 'create'/'modify' message for secret-define
The current message of secret-define always be: Secret 09a9736f-eedb-449c-9983-80d0ab67393f created even you just modify the secret, perhaps this may puzzle uses. Now this patch make the modify action output message like this: Secret f2d1bafc-ac58-4a47-93e4-47723686fef5 modified Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh-secret.c | 18 +- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 10d5db3..47974fe 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -96,6 +96,8 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) char *buffer; virSecretPtr res; char uuid[VIR_UUID_STRING_BUFLEN]; +virSecretDefPtr new_attrs; +virSecretPtr new_res; bool ret = false; if (vshCommandOptStringReq(ctl, cmd, file, from) 0) @@ -104,6 +106,14 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, buffer) 0) return false; +if (!(new_attrs = virSecretDefParseString(buffer))) { +VIR_FREE(buffer); +return false; +} + +new_res = virSecretLookupByUUID(ctl-conn, new_attrs-uuid); +new_attrs = NULL; + if (!(res = virSecretDefineXML(ctl-conn, buffer, 0))) { vshError(ctl, _(Failed to set attributes from %s), from); goto cleanup; @@ -114,13 +124,19 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) goto cleanup; } -vshPrint(ctl, _(Secret %s created\n), uuid); +if (new_res == NULL) +vshPrint(ctl, _(Secret %s created\n), uuid); +else +vshPrint(ctl, _(Secret %s modified\n), uuid); ret = true; cleanup: VIR_FREE(buffer); +virSecretDefFree(new_attrs); if (res) virSecretFree(res); +if (new_res) +virSecretFree(new_res); return ret; } -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] virsh: Make secret's usage can be modified if the usage isn't used
Ping! When a secret's usage is specified, for example: secret ephemeral='no' private='no' uuid540c56d1-f4b3-5031-b76d-33e99e9b5c64/uuid usage type='volume' volume/tmp/test/volume /usage /secret If another volume '/tmp/test1' isn't used, the current secret's usage can bo modified to '/tmp/test1'. If '/tmp/test1' has been used for another secret, error message will be outputed. Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- src/secret/secret_driver.c | 18 +++--- 1 files changed, 11 insertions(+), 7 deletions(-) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] virsh: Separate 'create'/'modify' message for secret-define
On Fri, Apr 18, 2014 at 12:20:26 +0200, Martin Kletzander wrote: On Fri, Apr 18, 2014 at 04:27:10AM -0400, Li Yang wrote: The current message of secret-define always be: Secret 09a9736f-eedb-449c-9983-80d0ab67393f created even you just modify the secret, perhaps this may puzzle uses. Now this patch make the modify action output message like this: Secret f2d1bafc-ac58-4a47-93e4-47723686fef5 modified Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh-secret.c | 16 +++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 10d5db3..d1cbe04 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -39,6 +39,7 @@ #include virutil.h #include virxml.h #include conf/secret_conf.h +#include viruuid.h static virSecretPtr vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name) @@ -96,6 +97,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) char *buffer; virSecretPtr res; char uuid[VIR_UUID_STRING_BUFLEN]; +virSecretDefPtr new_attrs; bool ret = false; if (vshCommandOptStringReq(ctl, cmd, file, from) 0) @@ -104,6 +106,12 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, buffer) 0) return false; +new_attrs = virSecretDefParseString(buffer); +if (new_attrs == NULL){ +VIR_FREE(buffer); +return false; +} + if (!(res = virSecretDefineXML(ctl-conn, buffer, 0))) { vshError(ctl, _(Failed to set attributes from %s), from); goto cleanup; @@ -114,10 +122,16 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) goto cleanup; } -vshPrint(ctl, _(Secret %s created\n), uuid); +char uuidstr[VIR_UUID_STRING_BUFLEN]; +virUUIDFormat(new_attrs-uuid, uuidstr); +if (memcmp(uuid, uuidstr, VIR_UUID_BUFLEN) == 0) +vshPrint(ctl, _(Secret %s modified\n), uuid); +else +vshPrint(ctl, _(Secret %s created\n), uuid); ret = true; You'll still print 'modified' if the new created secret has an uuid in the file already, plus it does more parsing, etc. Wouldn't it be easier to just do s/created/defined/ ? Also you compare just the first VIR_UUID_BUFLEN characters in UUID string. I agree with Martin. Jirka Oh, yes, you are right, I didn't notice that. I will try another way to cover this situation. If I cannot find an easy way to solve this problem, I think we'd better leave it at that, Modify created to defined seems not enough useful for uses... After all, secret-undefine command's output is Secret *** deleted, it's correspond to secret-define command's output Secret *** created. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virsh: Separate 'create'/'modify' message for secret-define
The current message of secret-define always be: Secret 09a9736f-eedb-449c-9983-80d0ab67393f created even you just modify the secret, perhaps this may puzzle uses. Now this patch make the modify action output message like this: Secret f2d1bafc-ac58-4a47-93e4-47723686fef5 modified Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh-secret.c | 16 +++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 10d5db3..d1cbe04 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -39,6 +39,7 @@ #include virutil.h #include virxml.h #include conf/secret_conf.h +#include viruuid.h static virSecretPtr vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name) @@ -96,6 +97,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) char *buffer; virSecretPtr res; char uuid[VIR_UUID_STRING_BUFLEN]; +virSecretDefPtr new_attrs; bool ret = false; if (vshCommandOptStringReq(ctl, cmd, file, from) 0) @@ -104,6 +106,12 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, buffer) 0) return false; +new_attrs = virSecretDefParseString(buffer); +if (new_attrs == NULL){ +VIR_FREE(buffer); +return false; +} + if (!(res = virSecretDefineXML(ctl-conn, buffer, 0))) { vshError(ctl, _(Failed to set attributes from %s), from); goto cleanup; @@ -114,10 +122,16 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) goto cleanup; } -vshPrint(ctl, _(Secret %s created\n), uuid); +char uuidstr[VIR_UUID_STRING_BUFLEN]; +virUUIDFormat(new_attrs-uuid, uuidstr); +if (memcmp(uuid, uuidstr, VIR_UUID_BUFLEN) == 0) +vshPrint(ctl, _(Secret %s modified\n), uuid); +else +vshPrint(ctl, _(Secret %s created\n), uuid); ret = true; cleanup: +VIR_FREE(new_attrs); VIR_FREE(buffer); if (res) virSecretFree(res); -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Modify help information of virsh list command
Use 'virsh list domain --title' option can get domain's title, not description, the original help information 'show short domain description' will confuse users, so modify it to 'show domain title' Signed-off-by: Li Yang liyang.f...@cn.fujitsu.com --- tools/virsh-domain-monitor.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index de4afbb..5d19388 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1753,7 +1753,7 @@ static const vshCmdOptDef opts_list[] = { }, {.name = title, .type = VSH_OT_BOOL, - .help = N_(show short domain description) + .help = N_(show domain title) }, {.name = NULL} }; -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list