Re: [libvirt] [PATCH 01/12] Introduce new public API virNodeDeviceFindByWWN

2013-01-08 Thread Osier Yang

On 2013年01月08日 01:27, Daniel P. Berrange wrote:

On Tue, Jan 08, 2013 at 01:05:23AM +0800, Osier Yang wrote:

Since the name (like scsi_host10) is not stable for vHBA, (it can
be changed either after recreating or system rebooting), current
API virNodeDeviceFindByName is not nice to use for management app
in this case. (E.g. one wants to destroy the vHBA whose name has
been changed after system rebooting, he has to find out current
name first).

Later patches will support the persistent vHBA via storage pool,
with which one can identify the vHBA stably by the wwnn  wwpn
pair.

So this new API comes.
---
  include/libvirt/libvirt.h.in |5 
  src/driver.h |6 +
  src/libvirt.c|   45 ++
  src/libvirt_public.syms  |1 +
  4 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 09c89c5..b4e1ead 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3156,6 +3156,11 @@ int virConnectListAllNodeDevices 
(virConnectPtr conn,
  virNodeDevicePtrvirNodeDeviceLookupByName (virConnectPtr conn,
 const char *name);

+virNodeDevicePtrvirNodeDeviceLookupByWWN (virConnectPtr conn,
+  const char *wwnn,
+  const char *wwpn,
+  unsigned int flags);


Since this API doesn't work for all types of node dev, its name
should really reflect that. eg

   virNodeDeviceLookupSCSIHostByWWN()



Agreed, and v2 posted.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 01/12] Introduce new public API virNodeDeviceFindByWWN

2013-01-07 Thread Osier Yang
Since the name (like scsi_host10) is not stable for vHBA, (it can
be changed either after recreating or system rebooting), current
API virNodeDeviceFindByName is not nice to use for management app
in this case. (E.g. one wants to destroy the vHBA whose name has
been changed after system rebooting, he has to find out current
name first).

Later patches will support the persistent vHBA via storage pool,
with which one can identify the vHBA stably by the wwnn  wwpn
pair.

So this new API comes.
---
 include/libvirt/libvirt.h.in |5 
 src/driver.h |6 +
 src/libvirt.c|   45 ++
 src/libvirt_public.syms  |1 +
 4 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 09c89c5..b4e1ead 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3156,6 +3156,11 @@ int virConnectListAllNodeDevices 
(virConnectPtr conn,
 virNodeDevicePtrvirNodeDeviceLookupByName (virConnectPtr conn,
const char *name);
 
+virNodeDevicePtrvirNodeDeviceLookupByWWN (virConnectPtr conn,
+  const char *wwnn,
+  const char *wwpn,
+  unsigned int flags);
+
 const char *virNodeDeviceGetName (virNodeDevicePtr dev);
 
 const char *virNodeDeviceGetParent   (virNodeDevicePtr dev);
diff --git a/src/driver.h b/src/driver.h
index 01c95cf..a4a6573 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1547,6 +1547,11 @@ typedef int (*virDevMonListAllNodeDevices)(virConnectPtr 
conn,
 typedef virNodeDevicePtr (*virDevMonDeviceLookupByName)(virConnectPtr conn,
 const char *name);
 
+typedef virNodeDevicePtr (*virDevMonDeviceLookupByWWN)(virConnectPtr conn,
+   const char *wwnn,
+   const char *wwpn,
+   unsigned int flags);
+
 typedef char * (*virDevMonDeviceGetXMLDesc)(virNodeDevicePtr dev,
 unsigned int flags);
 
@@ -1578,6 +1583,7 @@ struct _virDeviceMonitor {
 virDevMonListDeviceslistDevices;
 virDevMonListAllNodeDevices listAllNodeDevices;
 virDevMonDeviceLookupByName deviceLookupByName;
+virDevMonDeviceLookupByWWN  deviceLookupByWWN;
 virDevMonDeviceGetXMLDesc   deviceGetXMLDesc;
 virDevMonDeviceGetParentdeviceGetParent;
 virDevMonDeviceNumOfCapsdeviceNumOfCaps;
diff --git a/src/libvirt.c b/src/libvirt.c
index 6d1da12..3ca7e9c 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -14303,6 +14303,51 @@ error:
 return NULL;
 }
 
+/**
+ * virNodeDeviceLookupByWWN:
+ * @conn: pointer to the hypervisor connection
+ * @wwnn: WWNN of the HBA.
+ * @wwpn: WWPN of the HBA.
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Lookup a node device (specially for HBA) by its WWNN and
+ * WWPN.
+ *
+ * Returns a virNodeDevicePtr if found, NULL otherwise.
+ */
+virNodeDevicePtr
+virNodeDeviceLookupByWWN(virConnectPtr conn,
+ const char *wwnn,
+ const char *wwpn,
+ unsigned int flags)
+{
+VIR_DEBUG(conn=%p, wwnn=%p, wwpn=%p, flags=%x, conn, wwnn, wwpn, flags);
+
+virResetLastError();
+
+if (!VIR_IS_CONNECT(conn)) {
+virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+virDispatchError(NULL);
+return NULL;
+}
+
+virCheckNonNullArgGoto(wwnn, error);
+virCheckNonNullArgGoto(wwpn, error);
+
+if (conn-deviceMonitor  conn-deviceMonitor-deviceLookupByWWN) {
+virNodeDevicePtr ret;
+ret = conn-deviceMonitor-deviceLookupByWWN(conn, wwnn, wwpn, flags);
+if (!ret)
+goto error;
+return ret;
+}
+
+virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+virDispatchError(conn);
+return NULL;
+}
 
 /**
  * virNodeDeviceGetXMLDesc:
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 2107519..13f67ca 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -583,6 +583,7 @@ LIBVIRT_1.0.1 {
 LIBVIRT_1.0.2 {
 global:
 virDomainOpenChannel;
+virNodeDeviceLookupByWWN;
 } LIBVIRT_1.0.1;
 
 #  define new API here using predicted next version number 
-- 
1.7.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 01/12] Introduce new public API virNodeDeviceFindByWWN

2013-01-07 Thread Daniel P. Berrange
On Tue, Jan 08, 2013 at 01:05:23AM +0800, Osier Yang wrote:
 Since the name (like scsi_host10) is not stable for vHBA, (it can
 be changed either after recreating or system rebooting), current
 API virNodeDeviceFindByName is not nice to use for management app
 in this case. (E.g. one wants to destroy the vHBA whose name has
 been changed after system rebooting, he has to find out current
 name first).
 
 Later patches will support the persistent vHBA via storage pool,
 with which one can identify the vHBA stably by the wwnn  wwpn
 pair.
 
 So this new API comes.
 ---
  include/libvirt/libvirt.h.in |5 
  src/driver.h |6 +
  src/libvirt.c|   45 
 ++
  src/libvirt_public.syms  |1 +
  4 files changed, 57 insertions(+), 0 deletions(-)
 
 diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
 index 09c89c5..b4e1ead 100644
 --- a/include/libvirt/libvirt.h.in
 +++ b/include/libvirt/libvirt.h.in
 @@ -3156,6 +3156,11 @@ int virConnectListAllNodeDevices 
 (virConnectPtr conn,
  virNodeDevicePtrvirNodeDeviceLookupByName (virConnectPtr conn,
 const char *name);
  
 +virNodeDevicePtrvirNodeDeviceLookupByWWN (virConnectPtr conn,
 +  const char *wwnn,
 +  const char *wwpn,
 +  unsigned int flags);

Since this API doesn't work for all types of node dev, its name
should really reflect that. eg

  virNodeDeviceLookupSCSIHostByWWN()


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list