2011/6/6 Daniel P. Berrange <berrange@xxxxxxxxxx>: > On Sun, Jun 05, 2011 at 10:10:08AM +0200, Matthias Bolte wrote: >> Annotate the ESX device driver dummy. >> >> Refactor the udev and hal device driver strcuts to match the >> common annotation pattern. >> --- >> >> This is post-0.9.2. >> >> Âdocs/hvsupport.pl          Â|  22 +++++++++++++---- >> Âsrc/esx/esx_device_monitor.c     |  15 ++--------- >> Âsrc/node_device/node_device_driver.c |  45 +++++++++++++--------------------- >> Âsrc/node_device/node_device_driver.h |  14 +++++++++- >> Âsrc/node_device/node_device_hal.c  Â|  22 +++++++++++----- >> Âsrc/node_device/node_device_udev.c  |  22 +++++++++++----- >> Â6 files changed, 79 insertions(+), 61 deletions(-) >> >> diff --git a/docs/hvsupport.pl b/docs/hvsupport.pl >> index 8a0fa7a..b0d1f0f 100755 >> --- a/docs/hvsupport.pl >> +++ b/docs/hvsupport.pl >> @@ -27,7 +27,7 @@ my %groupheaders = ( >> Âmy @srcs; >> Âfind({ >>   Âwanted => sub { >> -   if (m!$srcdir/.*/\w+_(driver|tmpl)\.c$!) { >> +   if (m!$srcdir/.*/\w+_(driver|tmpl|monitor|hal|udev)\.c$!) { >>      push @srcs, $_ if $_ !~ /vbox_driver\.c/; >>    } >>   Â}, no_chdir => 1}, $srcdir); >> @@ -142,7 +142,7 @@ open FILE, "<$drivertable" >> Âmy %groups; >> Âmy $ingrp; >> Âwhile (defined($line = <FILE>)) { >> -  Âif ($line =~ /struct _(vir\w*Driver)/) { >> +  Âif ($line =~ /struct _(vir\w*(?:Driver|Monitor))/) { >>    my $grp = $1; >>    if ($grp ne "virStateDriver" && >>      $grp ne "virStreamDriver") { >> @@ -150,7 +150,7 @@ while (defined($line = <FILE>)) { >>      $groups{$ingrp} = { apis => {}, drivers => {} }; >>    } >>   Â} elsif ($ingrp) { >> -   if ($line =~ /^\s*virDrv(\w+)\s+(\w+);\s*$/) { >> +   if ($line =~ /^\s*vir(?:Drv|DevMon)(\w+)\s+(\w+);\s*$/) { >>      my $field = $2; >>      my $name = $1; >> >> @@ -159,6 +159,8 @@ while (defined($line = <FILE>)) { >>        $api = "vir$name"; >>      } elsif (exists $apis{"virConnect$name"}) { >>        $api = "virConnect$name"; >> +     } elsif (exists $apis{"virNode$name"}) { >> +       $api = "virNode$name"; >>      } else { >>        die "driver $name does not have a public API"; >>      } >> @@ -188,7 +190,17 @@ foreach my $src (@srcs) { >>          $line =~ /^\s*(?:static\s+)?$grp\s+NAME\(\w+\)\s*=\s*{/) { >>          $ingrp = $grp; >>          $impl = $src; >> -         $impl =~ s,.*/(\w+?)_((\w+)_)?(\w+)\.c,$1,; >> + >> +         if ($impl =~ m,.*/node_device_(\w+)\.c,) { >> +           $impl = $1; >> +         } else { >> +           $impl =~ s,.*/(\w+?)_((\w+)_)?(\w+)\.c,$1,; >> +         } >> + >> +         if ($groups{$ingrp}->{drivers}->{$impl}) { >> +           die "Group $ingrp already contains $impl"; >> +         } >> + >>          $groups{$ingrp}->{drivers}->{$impl} = {}; >>        } >>      } >> @@ -206,7 +218,7 @@ foreach my $src (@srcs) { >>        die "Driver method for $api is NULL in $src" if $meth eq "NULL"; >> >>        if (!exists($groups{$ingrp}->{apis}->{$api})) { >> -         die "Found unexpected driver $api in $ingrp\n"; >> +         die "Found unexpected method $api in $ingrp\n"; >>        } >> >>        $groups{$ingrp}->{drivers}->{$impl}->{$api} = $vers; >> diff --git a/src/esx/esx_device_monitor.c b/src/esx/esx_device_monitor.c >> index 3fa63d5..4bc8e7f 100644 >> --- a/src/esx/esx_device_monitor.c >> +++ b/src/esx/esx_device_monitor.c >> @@ -66,18 +66,9 @@ esxDeviceClose(virConnectPtr conn) >> >> >> Âstatic virDeviceMonitor esxDeviceMonitor = { >> -  Â"ESX",                 /* name */ >> -  ÂesxDeviceOpen,             /* open */ >> -  ÂesxDeviceClose,            Â/* close */ >> -  ÂNULL,                 Â/* numOfDevices */ >> -  ÂNULL,                 Â/* listDevices */ >> -  ÂNULL,                 Â/* deviceLookupByName */ >> -  ÂNULL,                 Â/* deviceGetXMLDesc */ >> -  ÂNULL,                 Â/* deviceGetParent */ >> -  ÂNULL,                 Â/* deviceNumOfCaps */ >> -  ÂNULL,                 Â/* deviceListCaps */ >> -  ÂNULL,                 Â/* deviceCreateXML */ >> -  ÂNULL,                 Â/* deviceDestroy */ >> +  Â.name = "ESX", >> +  Â.open = esxDeviceOpen, /* 0.7.6 */ >> +  Â.close = esxDeviceClose, /* 0.7.6 */ >> Â}; >> >> >> diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c >> index 8ec3e44..842f903 100644 >> --- a/src/node_device/node_device_driver.c >> +++ b/src/node_device/node_device_driver.c >> @@ -122,9 +122,10 @@ void nodeDeviceUnlock(virDeviceMonitorStatePtr driver) >>   ÂvirMutexUnlock(&driver->lock); >> Â} >> >> -static int nodeNumOfDevices(virConnectPtr conn, >> -              Âconst char *cap, >> -              Âunsigned int flags ATTRIBUTE_UNUSED) >> +int >> +nodeNumOfDevices(virConnectPtr conn, >> +         const char *cap, >> +         unsigned int flags ATTRIBUTE_UNUSED) >> Â{ >>   ÂvirDeviceMonitorStatePtr driver = conn->devMonPrivateData; >>   Âint ndevs = 0; >> @@ -143,7 +144,7 @@ static int nodeNumOfDevices(virConnectPtr conn, >>   Âreturn ndevs; >> Â} >> >> -static int >> +int >> ÂnodeListDevices(virConnectPtr conn, >>         Âconst char *cap, >>         Âchar **const names, int maxnames, >> @@ -179,8 +180,8 @@ nodeListDevices(virConnectPtr conn, >> Â} >> >> >> -static virNodeDevicePtr nodeDeviceLookupByName(virConnectPtr conn, >> -                        const char *name) >> +virNodeDevicePtr >> +nodeDeviceLookupByName(virConnectPtr conn, const char *name) >> Â{ >>   ÂvirDeviceMonitorStatePtr driver = conn->devMonPrivateData; >>   ÂvirNodeDeviceObjPtr obj; >> @@ -251,8 +252,9 @@ out: >> Â} >> >> >> -static char *nodeDeviceGetXMLDesc(virNodeDevicePtr dev, >> -                 Âunsigned int flags ATTRIBUTE_UNUSED) >> +char * >> +nodeDeviceGetXMLDesc(virNodeDevicePtr dev, >> +           unsigned int flags ATTRIBUTE_UNUSED) >> Â{ >>   ÂvirDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; >>   ÂvirNodeDeviceObjPtr obj; >> @@ -281,7 +283,8 @@ cleanup: >> Â} >> >> >> -static char *nodeDeviceGetParent(virNodeDevicePtr dev) >> +char * >> +nodeDeviceGetParent(virNodeDevicePtr dev) >> Â{ >>   ÂvirDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; >>   ÂvirNodeDeviceObjPtr obj; >> @@ -314,7 +317,8 @@ cleanup: >> Â} >> >> >> -static int nodeDeviceNumOfCaps(virNodeDevicePtr dev) >> +int >> +nodeDeviceNumOfCaps(virNodeDevicePtr dev) >> Â{ >>   ÂvirDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; >>   ÂvirNodeDeviceObjPtr obj; >> @@ -344,7 +348,7 @@ cleanup: >> Â} >> >> >> -static int >> +int >> ÂnodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) >> Â{ >>   ÂvirDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; >> @@ -538,7 +542,7 @@ find_new_device(virConnectPtr conn, const char *wwnn, const char *wwpn) >>   Âreturn dev; >> Â} >> >> -static virNodeDevicePtr >> +virNodeDevicePtr >> ÂnodeDeviceCreateXML(virConnectPtr conn, >>           Âconst char *xmlDesc, >>           Âunsigned int flags ATTRIBUTE_UNUSED) >> @@ -591,7 +595,7 @@ cleanup: >> Â} >> >> >> -static int >> +int >> ÂnodeDeviceDestroy(virNodeDevicePtr dev) >> Â{ >>   Âint ret = -1; >> @@ -651,21 +655,6 @@ out: >>   Âreturn ret; >> Â} >> >> - >> -void registerCommonNodeFuncs(virDeviceMonitorPtr driver) >> -{ >> -  Âdriver->numOfDevices = nodeNumOfDevices; >> -  Âdriver->listDevices = nodeListDevices; >> -  Âdriver->deviceLookupByName = nodeDeviceLookupByName; >> -  Âdriver->deviceGetXMLDesc = nodeDeviceGetXMLDesc; >> -  Âdriver->deviceGetParent = nodeDeviceGetParent; >> -  Âdriver->deviceNumOfCaps = nodeDeviceNumOfCaps; >> -  Âdriver->deviceListCaps = nodeDeviceListCaps; >> -  Âdriver->deviceCreateXML = nodeDeviceCreateXML; >> -  Âdriver->deviceDestroy = nodeDeviceDestroy; >> -} >> - >> - >> Âint nodedevRegister(void) { >> Â#if defined(HAVE_HAL) && defined(HAVE_UDEV) >>   Â/* Register only one of these two - they conflict */ >> diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h >> index e583c2b..08779b1 100644 >> --- a/src/node_device/node_device_driver.h >> +++ b/src/node_device/node_device_driver.h >> @@ -53,8 +53,6 @@ int udevNodeRegister(void); >> Âvoid nodeDeviceLock(virDeviceMonitorStatePtr driver); >> Âvoid nodeDeviceUnlock(virDeviceMonitorStatePtr driver); >> >> -void registerCommonNodeFuncs(virDeviceMonitorPtr mon); >> - >> Âint nodedevRegister(void); >> >> Â# ifdef __linux__ >> @@ -86,4 +84,16 @@ int read_wwn_linux(int host, const char *file, char **wwn); >> >> Â# endif /* __linux__ */ >> >> +int nodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags); >> +int nodeListDevices(virConnectPtr conn, const char *cap, char **const names, >> +          Âint maxnames, unsigned int flags); >> +virNodeDevicePtr nodeDeviceLookupByName(virConnectPtr conn, const char *name); >> +char *nodeDeviceGetXMLDesc(virNodeDevicePtr dev, unsigned int flags); >> +char *nodeDeviceGetParent(virNodeDevicePtr dev); >> +int nodeDeviceNumOfCaps(virNodeDevicePtr dev); >> +int nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames); >> +virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, >> +                   const char *xmlDesc, unsigned int flags); >> +int nodeDeviceDestroy(virNodeDevicePtr dev); >> + >> Â#endif /* __VIR_NODE_DEVICE_H__ */ >> diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c >> index 8df2875..a90e777 100644 >> --- a/src/node_device/node_device_hal.c >> +++ b/src/node_device/node_device_hal.c >> @@ -881,22 +881,30 @@ static int halNodeDrvClose(virConnectPtr conn ATTRIBUTE_UNUSED) >> >> Âstatic virDeviceMonitor halDeviceMonitor = { >>   Â.name = "halDeviceMonitor", >> -  Â.open = halNodeDrvOpen, >> -  Â.close = halNodeDrvClose, >> +  Â.open = halNodeDrvOpen, /* 0.5.0 */ >> +  Â.close = halNodeDrvClose, /* 0.5.0 */ >> +  Â.numOfDevices = nodeNumOfDevices, /* 0.5.0 */ >> +  Â.listDevices = nodeListDevices, /* 0.5.0 */ >> +  Â.deviceLookupByName = nodeDeviceLookupByName, /* 0.5.0 */ >> +  Â.deviceGetXMLDesc = nodeDeviceGetXMLDesc, /* 0.5.0 */ >> +  Â.deviceGetParent = nodeDeviceGetParent, /* 0.5.0 */ >> +  Â.deviceNumOfCaps = nodeDeviceNumOfCaps, /* 0.5.0 */ >> +  Â.deviceListCaps = nodeDeviceListCaps, /* 0.5.0 */ >> +  Â.deviceCreateXML = nodeDeviceCreateXML, /* 0.6.5 */ >> +  Â.deviceDestroy = nodeDeviceDestroy, /* 0.6.5 */ >> Â}; >> >> >> Âstatic virStateDriver halStateDriver = { >>   Â.name = "HAL", >> -  Â.initialize = halDeviceMonitorStartup, >> -  Â.cleanup = halDeviceMonitorShutdown, >> -  Â.reload = halDeviceMonitorReload, >> -  Â.active = halDeviceMonitorActive, >> +  Â.initialize = halDeviceMonitorStartup, /* 0.5.0 */ >> +  Â.cleanup = halDeviceMonitorShutdown, /* 0.5.0 */ >> +  Â.reload = halDeviceMonitorReload, /* 0.5.0 */ >> +  Â.active = halDeviceMonitorActive, /* 0.5.0 */ >> Â}; >> >> Âint halNodeRegister(void) >> Â{ >> -  ÂregisterCommonNodeFuncs(&halDeviceMonitor); >>   Âif (virRegisterDeviceMonitor(&halDeviceMonitor) < 0) >>     Âreturn -1; >>   Âreturn virRegisterStateDriver(&halStateDriver); >> diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c >> index 29e4bac..8b9694e 100644 >> --- a/src/node_device/node_device_udev.c >> +++ b/src/node_device/node_device_udev.c >> @@ -1741,23 +1741,31 @@ static int udevNodeDrvClose(virConnectPtr conn) >> >> Âstatic virDeviceMonitor udevDeviceMonitor = { >>   Â.name = "udevDeviceMonitor", >> -  Â.open = udevNodeDrvOpen, >> -  Â.close = udevNodeDrvClose, >> +  Â.open = udevNodeDrvOpen, /* 0.7.3 */ >> +  Â.close = udevNodeDrvClose, /* 0.7.3 */ >> +  Â.numOfDevices = nodeNumOfDevices, /* 0.7.3 */ >> +  Â.listDevices = nodeListDevices, /* 0.7.3 */ >> +  Â.deviceLookupByName = nodeDeviceLookupByName, /* 0.7.3 */ >> +  Â.deviceGetXMLDesc = nodeDeviceGetXMLDesc, /* 0.7.3 */ >> +  Â.deviceGetParent = nodeDeviceGetParent, /* 0.7.3 */ >> +  Â.deviceNumOfCaps = nodeDeviceNumOfCaps, /* 0.7.3 */ >> +  Â.deviceListCaps = nodeDeviceListCaps, /* 0.7.3 */ >> +  Â.deviceCreateXML = nodeDeviceCreateXML, /* 0.7.3 */ >> +  Â.deviceDestroy = nodeDeviceDestroy, /* 0.7.3 */ >> Â}; >> >> Âstatic virStateDriver udevStateDriver = { >>   Â.name = "udev", >> -  Â.initialize = udevDeviceMonitorStartup, >> -  Â.cleanup = udevDeviceMonitorShutdown, >> -  Â.reload = udevDeviceMonitorReload, >> -  Â.active = udevDeviceMonitorActive, >> +  Â.initialize = udevDeviceMonitorStartup, /* 0.7.3 */ >> +  Â.cleanup = udevDeviceMonitorShutdown, /* 0.7.3 */ >> +  Â.reload = udevDeviceMonitorReload, /* 0.7.3 */ >> +  Â.active = udevDeviceMonitorActive, /* 0.7.3 */ >> Â}; >> >> Âint udevNodeRegister(void) >> Â{ >>   ÂVIR_DEBUG("Registering udev node device backend"); >> >> -  ÂregisterCommonNodeFuncs(&udevDeviceMonitor); >>   Âif (virRegisterDeviceMonitor(&udevDeviceMonitor) < 0) { >>     Âreturn -1; >>   Â} > > ACK, I completely missed the node device APIs when doing the conversion > because of this wierd driver structure. > > Daniel Thanks, pushed. Matthias -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list