phyp: optimize use of sed

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'.
This commit is contained in:
Eric Blake 2010-06-24 16:25:56 -06:00
parent ebc46fea6f
commit 17dedf7cb5

View File

@ -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();