[libvirt] [PATCH 3/3] PHYP: create, destroy and other network functions

2010-11-19 Thread Eduardo Otubo
Adding networkCreateXML, networkDestroy, networkIsActive and 
networkLookupByName.

In the function phypCreateNetwork I just use the def-domain information to 
create
the new network interface because of the behaviour of the HMC and the 
hypervisor:

* HMC can't simply create a network interface without assigning it to a 
specific 
  LPAR.
* I also can't assign an IP addr or any other information from the HMC or 
VIOS
  side, but I can control in which vlan or vswitch it will be attached - but
  thought just in the simplest case scenarion now, I'll make some 
improvements
  in the future.

That's why I used a very simple XML for testing:

network
uuid3e3fce45-4f53-4fa7-bb32-11f34168b82b/uuid
domain name=LPAR01 /
namewhatever/name
bridge name=whatever /
/network

The only information I really need is the domain name which I'll assign the 
created 
network interface. Name, MAC Addr MUST be created automatically by the 
hypervisor, 
they're all unique. I had to put those two other tags name and bridge so 
the 
function virNetworkDefParseString can return successfully, otherwise it would 
say 
that the XML is malformed.

---
 src/phyp/phyp_driver.c |  400 +++-
 src/phyp/phyp_driver.h |2 +-
 2 files changed, 396 insertions(+), 6 deletions(-)

diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index c44fc69..244561e 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1,7 +1,7 @@
 
 /*
  * Copyright (C) 2010 Red Hat, Inc.
- * Copyright IBM Corp. 2009
+ * Copyright IBM Corp. 2010
  *
  * phyp_driver.c: ssh layer to access Power Hypervisors
  *
@@ -2829,6 +2829,396 @@ phypGetStoragePoolXMLDesc(virStoragePoolPtr pool, 
unsigned int flags)
 return NULL;
 }
 
+static int
+networkDestroy(virNetworkPtr net)
+{
+ConnectionData *connection_data = net-conn-networkPrivateData;
+phyp_driverPtr phyp_driver = net-conn-privateData;
+LIBSSH2_SESSION *session = connection_data-session;
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+uuid_nettablePtr uuid_nettable = phyp_driver-uuid_nettable;
+char *managed_system = phyp_driver-managed_system;
+int system_type = phyp_driver-system_type;
+int exit_status = 0;
+int slot_num = 0;
+char *char_ptr;
+char *cmd = NULL;
+char *ret = NULL;
+unsigned int i = 0;
+int lpar_id = 0;
+long long mac = 0;
+
+for (i = 0; i  uuid_nettable-nnets; i++) {
+if (STREQ(uuid_nettable-nets[i]-name, net-name)) {
+mac = uuid_nettable-nets[i]-mac;
+break;
+}
+}
+
+/* Getting the LPAR ID */
+
+virBufferAddLit(buf, lshwres );
+if (system_type == HMC)
+virBufferVSprintf(buf, -m %s , managed_system);
+
+virBufferVSprintf(buf,
+   -r virtualio --rsubtype slot --level slot 
+   -F drc_name,lpar_id|grep %s|
+   sed -e 's/^.*,//g', net-name);
+
+if (virBufferError(buf)) {
+virBufferFreeAndReset(buf);
+virReportOOMError();
+return -1;
+}
+cmd = virBufferContentAndReset(buf);
+
+ret = phypExec(session, cmd, exit_status, net-conn);
+
+if (exit_status  0 || ret == NULL)
+goto err;
+
+if (virStrToLong_i(ret, char_ptr, 10, lpar_id) == -1)
+goto err;
+
+/* Getting the remote slot number */
+
+virBufferAddLit(buf, lshwres );
+if (system_type == HMC)
+virBufferVSprintf(buf, -m %s , managed_system);
+
+virBufferVSprintf(buf,
+   -r virtualio --rsubtype eth --level lpar 
+   -F mac_addr,slot_num|grep %lld|
+   sed -e 's/^.*,//g', mac);
+
+if (virBufferError(buf)) {
+virBufferFreeAndReset(buf);
+virReportOOMError();
+return -1;
+}
+cmd = virBufferContentAndReset(buf);
+
+ret = phypExec(session, cmd, exit_status, net-conn);
+
+if (exit_status  0 || ret == NULL)
+goto err;
+
+if (virStrToLong_i(ret, char_ptr, 10, slot_num) == -1)
+goto err;
+
+/* excluding interface */
+
+virBufferAddLit(buf, chhwres );
+if (system_type == HMC)
+virBufferVSprintf(buf, -m %s , managed_system);
+
+virBufferVSprintf(buf,
+   -r virtualio --rsubtype eth
+   --id %d -o r -s %d, lpar_id, slot_num);
+
+if (virBufferError(buf)) {
+virBufferFreeAndReset(buf);
+virReportOOMError();
+return -1;
+}
+cmd = virBufferContentAndReset(buf);
+
+ret = phypExec(session, cmd, exit_status, net-conn);
+
+if (exit_status  0 || ret != NULL)
+goto err;
+
+if (phypUUIDTable_RemNetwork(net-conn, mac)  0)
+goto err;
+
+VIR_FREE(cmd);
+VIR_FREE(ret);
+return 0;
+
+  err:
+VIR_FREE(cmd);
+VIR_FREE(ret);
+return -1;
+}
+
+static virNetworkPtr
+phypCreateNetwork(virConnectPtr conn, const char *xml)

Re: [libvirt] [PATCH 3/3] PHYP: create, destroy and other network functions

2010-11-19 Thread Eric Blake
On 11/19/2010 07:55 AM, Eduardo Otubo wrote:
 Adding networkCreateXML, networkDestroy, networkIsActive and 
 networkLookupByName.
 
 In the function phypCreateNetwork I just use the def-domain information to 
 create
 the new network interface because of the behaviour of the HMC and the 
 hypervisor:
 
 * HMC can't simply create a network interface without assigning it to a 
 specific 
   LPAR.
 * I also can't assign an IP addr or any other information from the HMC or 
 VIOS
   side, but I can control in which vlan or vswitch it will be attached - 
 but
   thought just in the simplest case scenarion now, I'll make some 
 improvements

s/scenarion/scenario/

 +++ b/src/phyp/phyp_driver.c
 @@ -1,7 +1,7 @@
  
  /*
   * Copyright (C) 2010 Red Hat, Inc.
 - * Copyright IBM Corp. 2009
 + * Copyright IBM Corp. 2010

You should never remove copyright years; this would be okay as 2009-2010.

 +
 +virBufferAddLit(buf, lshwres );
 +if (system_type == HMC)
 +virBufferVSprintf(buf, -m %s , managed_system);
 +
 +virBufferVSprintf(buf,
 +   -r virtualio --rsubtype slot --level slot 
 +   -F drc_name,lpar_id|grep %s|
 +   sed -e 's/^.*,//g', net-name);

Another grep | sed you can simplify:

sed -n '/%s/ s/^.*,//p'

 +virBufferVSprintf(buf,
 +   -r virtualio --rsubtype eth --level lpar 
 +   -F mac_addr,slot_num|grep %lld|
 +   sed -e 's/^.*,//g', mac);

MACs are usually represented as hex, not decimal.  And if it really is
decimal, wouldn't you want unsigned?

Simplify:

sed -n '/%lld/ /^.*,//p'

 +
 +if (!def-domain) {
 +VIR_ERROR0(_(Domain can't be NULL, you must especify in which

s/especify/specify/

 +
 +ret = phypExec(session, cmd, exit_status, conn);
 +
 +if (exit_status  0 || ret != NULL)
 +goto err;
 +
 +/* Need to sleep a little while to wait for the HMC to
 + * complete the execution of the command.
 + * */
 +sleep(1);

This seems racy, and 1 second is a long pause.  Is there something more
reliable you can use to tell whether HMC is done?  Can you set up a
retry loop and sleep for shorter periods of time with retries until it
works to avoid a long pause?

 +
 +/* Getting the new interface name */
 +virBufferAddLit(buf, lshwres );
 +if (system_type == HMC)
 +virBufferVSprintf(buf, -m %s , managed_system);
 +
 +virBufferVSprintf(buf,
 +   -r virtualio --rsubtype slot --level slot
 +   |grep lpar_id=%d|grep slot_num=%d|
 +   sed -e 's/^.*drc_name=//g', lpar_id, slot);

sed '/lpar_id=%d/!d; /slot_num=%d/!d; s/^.*drc_name=//'

 +/* Getting the new interface mac addr */
 +virBufferAddLit(buf, lshwres );
 +if (system_type == HMC)
 +virBufferVSprintf(buf, -m %s , managed_system);
 +
 +virBufferVSprintf(buf,
 +  -r virtualio --rsubtype eth --level lpar 
 +  |grep lpar_id=%d|grep slot_num=%d|
 +   sed -e 's/^.*mac_addr=//g', lpar_id, slot);

Similar.

 +virBufferAddLit(buf, lshwres );
 +if (system_type == HMC)
 +virBufferVSprintf(buf, -m %s , managed_system);
 +
 +virBufferVSprintf(buf,
 +  -r virtualio --rsubtype eth --level lpar 
 +  -F mac_addr,state |grep %lld|
 +  sed -e 's/^.*,//g', mac);

Another instance where decimal MAC seems odd.

sed -n '/%lld/ s/^.*,//p'

 diff --git a/src/phyp/phyp_driver.h b/src/phyp/phyp_driver.h
 index 603d048..34ad84b 100644
 --- a/src/phyp/phyp_driver.h
 +++ b/src/phyp/phyp_driver.h
 @@ -1,6 +1,6 @@
  /*
   * Copyright (C) 2010 Red Hat, Inc.
 - * Copyright IBM Corp. 2009
 + * Copyright IBM Corp. 2010

This hunk seems completely random.  Should it be rebased into another
patch that actually touches phyp_driver.h?  And should it be 2009-2010?

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list