]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add API for iterating over all character devices
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 24 Jun 2010 14:06:43 +0000 (15:06 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 25 Jun 2010 13:39:45 +0000 (14:39 +0100)
The parallel, serial, console and channel devices are all just
character devices. A lot of code needs todo the same thing to
all these devices. This provides an convenient API for iterating
over all of them.

* src/conf/domain_conf.c, src/conf/domain_conf.c,
  src/libvirt_private.syms: Add virDomainChrDefForeach

src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms

index 182d8abec6231cc3ebd27b4b4a2999a956035653..378c06ef0a976b7a7a524de0eadbcc99b508bfdd 100644 (file)
@@ -7221,4 +7221,56 @@ int virDomainSnapshotHasChildren(virDomainSnapshotObjPtr snap,
 }
 
 
+int virDomainChrDefForeach(virDomainDefPtr def,
+                           bool abortOnError,
+                           virDomainChrDefIterator iter,
+                           void *opaque)
+{
+    int i;
+    int rc = 0;
+
+    for (i = 0 ; i < def->nserials ; i++) {
+        if ((iter)(def,
+                   def->serials[i],
+                   opaque) < 0)
+            rc = -1;
+
+        if (abortOnError && rc != 0)
+            goto done;
+    }
+
+    for (i = 0 ; i < def->nparallels ; i++) {
+        if ((iter)(def,
+                   def->parallels[i],
+                   opaque) < 0)
+            rc = -1;
+
+        if (abortOnError && rc != 0)
+            goto done;
+    }
+
+    for (i = 0 ; i < def->nchannels ; i++) {
+        if ((iter)(def,
+                   def->channels[i],
+                   opaque) < 0)
+            rc = -1;
+
+        if (abortOnError && rc != 0)
+            goto done;
+    }
+    if (def->console) {
+        if ((iter)(def,
+                   def->console,
+                   opaque) < 0)
+            rc = -1;
+
+        if (abortOnError && rc != 0)
+            goto done;
+    }
+
+done:
+    return rc;
+}
+
+
 #endif /* ! PROXY */
index 55893d6914daae4afa8dff15efbd6a1a8615bf88..01da17e5e2d049b5a1b112218f2b85b03e5310a3 100644 (file)
@@ -1069,6 +1069,15 @@ int virDomainObjListGetInactiveNames(virDomainObjListPtr doms,
                                      char **const names,
                                      int maxnames);
 
+typedef int (*virDomainChrDefIterator)(virDomainDefPtr def,
+                                       virDomainChrDefPtr dev,
+                                       void *opaque);
+
+int virDomainChrDefForeach(virDomainDefPtr def,
+                           bool abortOnError,
+                           virDomainChrDefIterator iter,
+                           void *opaque);
+
 
 VIR_ENUM_DECL(virDomainVirt)
 VIR_ENUM_DECL(virDomainBoot)
index 4e61e5567bdc489e3237d5862a1f8fff053fc012..778ceb1aa862cf0446d0bdcde7c75ecaf8ec811e 100644 (file)
@@ -224,6 +224,7 @@ virDomainSnapshotDefParseString;
 virDomainSnapshotDefFormat;
 virDomainSnapshotAssignDef;
 virDomainObjAssignDef;
+virDomainChrDefForeach;
 
 
 # domain_event.h