[libvirt] [PATCHv3 4/4] phyp: optimize use of sed

Eduardo Otubo otubo at linux.vnet.ibm.com
Fri Jun 25 06:02:05 UTC 2010


On 06/24/2010 07:32 PM, Eric Blake wrote:
> Minor speedups by using the full power of sed.
>
> * src/phyp/phyp_driver.c (phypGetVIOSFreeSCSIAdapter)
> (phypDiskType, phypListDefinedDomains): Use fewer processes, by
> folding other work into sed.
> (phypGetVIOSPartitionID): Likewise.  Also avoid non-portable use
> of 'sed -s'.
> ---
>   src/phyp/phyp_driver.c |   12 ++++++------
>   1 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
> index df6d10c..3692f2c 100644
> --- a/src/phyp/phyp_driver.c
> +++ b/src/phyp/phyp_driver.c
> @@ -227,8 +227,8 @@ phypGetVIOSPartitionID(virConnectPtr conn)
>       virBufferAddLit(&buf, "lssyscfg");
>       if (system_type == HMC)
>           virBufferVSprintf(&buf, " -m %s", managed_system);
> -    virBufferAddLit(&buf, " -r lpar -F lpar_id,lpar_env|grep "
> -                    "vioserver|sed -s 's/,.*$//'");
> +    virBufferAddLit(&buf, " -r lpar -F lpar_id,lpar_env"
> +                    "|sed -n '/vioserver/ {\n s/,.*$//\n p\n}'");
>       if (virBufferError(&buf)) {
>           virBufferFreeAndReset(&buf);
>           virReportOOMError();
> @@ -1889,7 +1889,7 @@ phypGetVIOSFreeSCSIAdapter(virConnectPtr conn)
>       if (system_type == HMC)
>           virBufferAddChar(&buf, '\'');
>
> -    virBufferVSprintf(&buf, "|grep -v ',[^.*]'|head -n 1|sed -e 's/,//g'");
> +    virBufferVSprintf(&buf, "|sed '/,[^.*]/d; s/,//g; q'");
>
>       if (virBufferError(&buf)) {
>           virBufferFreeAndReset(&buf);
> @@ -3330,7 +3330,7 @@ phypDiskType(virConnectPtr conn, char *backing_device)
>       if (system_type == HMC)
>           virBufferVSprintf(&buf, " -m %s", managed_system);
>       virBufferVSprintf(&buf, " -p %d -c \"lssp -field name type "
> -                      "-fmt , -all|grep %s|sed -e 's/^.*,//'\"",
> +                      "-fmt , -all|sed -n '/%s/ {\n s/^.*,//\n p\n}'\"",
>                         vios_id, backing_device);
>       if (virBufferError(&buf)) {
>           virBufferFreeAndReset(&buf);
> @@ -3398,8 +3398,8 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames)
>       virBufferAddLit(&buf, "lssyscfg -r lpar");
>       if (system_type == HMC)
>           virBufferVSprintf(&buf, " -m %s", managed_system);
> -    virBufferVSprintf(&buf, " -F name,state | grep \"Not Activated\" | "
> -                      "sed -e 's/,.*$//'");
> +    virBufferVSprintf(&buf, " -F name,state"
> +                      "|sed -n '/Not Activated/ {\n s/,.*$//\n p\n}'");
>       if (virBufferError(&buf)) {
>           virBufferFreeAndReset(&buf);
>           virReportOOMError();

I tested each sed expression on HMC shell, all of them are working fine.

Eric, again, thank you very much for all the help to complete this
driver. It's been a great lesson to discuss all these patches. I Hope I
can improve the quality of them in the future.

-- 
Eduardo Otubo
Software Engineer
Linux Technology Center
IBM Systems & Technology Group
Mobile: +55 19 8135 0885
eotubo at linux.vnet.ibm.com




More information about the libvir-list mailing list