[Libguestfs] [PATCH 1/2] actions: turn available & feature_available as non-daemon

Pino Toscano ptoscano at redhat.com
Thu Nov 5 15:56:42 UTC 2015


Rename the current available and feature_available into internal daemon
functions, and provide non-daemon functions wrapping them at library
side.  This will make it possible to e.g. add caching for them.

Should be only refactoring, no actual behaviour change.
---
 daemon/available.c   |   4 +-
 generator/actions.ml | 192 ++++++++++++++++++++++++++++-----------------------
 po/POTFILES          |   1 +
 src/MAX_PROC_NR      |   2 +-
 src/Makefile.am      |   1 +
 src/available.c      |  34 +++++++++
 6 files changed, 143 insertions(+), 91 deletions(-)
 create mode 100644 src/available.c

diff --git a/daemon/available.c b/daemon/available.c
index 54c6b9b..6409b90 100644
--- a/daemon/available.c
+++ b/daemon/available.c
@@ -67,13 +67,13 @@ available (char *const *groups, int error_on_unavailable)
 }
 
 int
-do_feature_available (char *const *groups)
+do_internal_feature_available (char *const *groups)
 {
   return available (groups, 0);
 }
 
 int
-do_available (char *const *groups)
+do_internal_available (char *const *groups)
 {
   if (available (groups, 1) == -1)
     return -1;
diff --git a/generator/actions.ml b/generator/actions.ml
index 7ecd384..6348c88 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -3412,6 +3412,92 @@ C<guestfs_get_identifier>." };
     longdesc = "\
 Get the handle identifier.  See C<guestfs_set_identifier>." };
 
+  { defaults with
+    name = "available"; added = (1, 0, 80);
+    style = RErr, [StringList "groups"], [];
+    tests = [
+      InitNone, Always, TestRun [["available"; ""]], []
+    ];
+    shortdesc = "test availability of some parts of the API";
+    longdesc = "\
+This command is used to check the availability of some
+groups of functionality in the appliance, which not all builds of
+the libguestfs appliance will be able to provide.
+
+The libguestfs groups, and the functions that those
+groups correspond to, are listed in L<guestfs(3)/AVAILABILITY>.
+You can also fetch this list at runtime by calling
+C<guestfs_available_all_groups>.
+
+The argument C<groups> is a list of group names, eg:
+C<[\"inotify\", \"augeas\"]> would check for the availability of
+the Linux inotify functions and Augeas (configuration file
+editing) functions.
+
+The command returns no error if I<all> requested groups are available.
+
+It fails with an error if one or more of the requested
+groups is unavailable in the appliance.
+
+If an unknown group name is included in the
+list of groups then an error is always returned.
+
+I<Notes:>
+
+=over 4
+
+=item *
+
+C<guestfs_feature_available> is the same as this call, but
+with a slightly simpler to use API: that call returns a boolean
+true/false instead of throwing an error.
+
+=item *
+
+You must call C<guestfs_launch> before calling this function.
+
+The reason is because we don't know what groups are
+supported by the appliance/daemon until it is running and can
+be queried.
+
+=item *
+
+If a group of functions is available, this does not necessarily
+mean that they will work.  You still have to check for errors
+when calling individual API functions even if they are
+available.
+
+=item *
+
+It is usually the job of distro packagers to build
+complete functionality into the libguestfs appliance.
+Upstream libguestfs, if built from source with all
+requirements satisfied, will support everything.
+
+=item *
+
+This call was added in version C<1.0.80>.  In previous
+versions of libguestfs all you could do would be to speculatively
+execute a command to find out if the daemon implemented it.
+See also C<guestfs_version>.
+
+=back
+
+See also C<guestfs_filesystem_available>." };
+
+  { defaults with
+    name = "feature_available"; added = (1, 21, 26);
+    style = RBool "isavailable", [StringList "groups"], [];
+    tests = [
+      InitNone, Always, TestResultTrue [["feature_available"; ""]], []
+    ];
+    shortdesc = "test availability of some parts of the API";
+    longdesc = "\
+This is the same as C<guestfs_available>, but unlike that
+call it returns a simple true/false boolean result, instead
+of throwing an exception if a feature is not found.  For
+other documentation see C<guestfs_available>." };
+
 ]
 
 (* daemon_functions are any functions which cause some action
@@ -8031,80 +8117,6 @@ To create a file with a pattern of repeating bytes
 use C<guestfs_fill_pattern>." };
 
   { defaults with
-    name = "available"; added = (1, 0, 80);
-    style = RErr, [StringList "groups"], [];
-    proc_nr = Some 216;
-    tests = [
-      InitNone, Always, TestRun [["available"; ""]], []
-    ];
-    shortdesc = "test availability of some parts of the API";
-    longdesc = "\
-This command is used to check the availability of some
-groups of functionality in the appliance, which not all builds of
-the libguestfs appliance will be able to provide.
-
-The libguestfs groups, and the functions that those
-groups correspond to, are listed in L<guestfs(3)/AVAILABILITY>.
-You can also fetch this list at runtime by calling
-C<guestfs_available_all_groups>.
-
-The argument C<groups> is a list of group names, eg:
-C<[\"inotify\", \"augeas\"]> would check for the availability of
-the Linux inotify functions and Augeas (configuration file
-editing) functions.
-
-The command returns no error if I<all> requested groups are available.
-
-It fails with an error if one or more of the requested
-groups is unavailable in the appliance.
-
-If an unknown group name is included in the
-list of groups then an error is always returned.
-
-I<Notes:>
-
-=over 4
-
-=item *
-
-C<guestfs_feature_available> is the same as this call, but
-with a slightly simpler to use API: that call returns a boolean
-true/false instead of throwing an error.
-
-=item *
-
-You must call C<guestfs_launch> before calling this function.
-
-The reason is because we don't know what groups are
-supported by the appliance/daemon until it is running and can
-be queried.
-
-=item *
-
-If a group of functions is available, this does not necessarily
-mean that they will work.  You still have to check for errors
-when calling individual API functions even if they are
-available.
-
-=item *
-
-It is usually the job of distro packagers to build
-complete functionality into the libguestfs appliance.
-Upstream libguestfs, if built from source with all
-requirements satisfied, will support everything.
-
-=item *
-
-This call was added in version C<1.0.80>.  In previous
-versions of libguestfs all you could do would be to speculatively
-execute a command to find out if the daemon implemented it.
-See also C<guestfs_version>.
-
-=back
-
-See also C<guestfs_filesystem_available>." };
-
-  { defaults with
     name = "dd"; added = (1, 0, 80);
     style = RErr, [Dev_or_Path "src"; Dev_or_Path "dest"], [];
     proc_nr = Some 217;
@@ -11763,20 +11775,6 @@ This is only used to debug RHBZ#914931.  Note that this
 deliberately crashes guestfsd." };
 
   { defaults with
-    name = "feature_available"; added = (1, 21, 26);
-    style = RBool "isavailable", [StringList "groups"], [];
-    proc_nr = Some 398;
-    tests = [
-      InitNone, Always, TestResultTrue [["feature_available"; ""]], []
-    ];
-    shortdesc = "test availability of some parts of the API";
-    longdesc = "\
-This is the same as C<guestfs_available>, but unlike that
-call it returns a simple true/false boolean result, instead
-of throwing an exception if a feature is not found.  For
-other documentation see C<guestfs_available>." };
-
-  { defaults with
     name = "syslinux"; added = (1, 21, 27);
     style = RErr, [Device "device"], [OString "directory"];
     proc_nr = Some 399;
@@ -12780,6 +12778,24 @@ this will fail and set errno as ENOTSUP.
 
 See also L<ntfsresize(8)>, L<resize2fs(8)>, L<btrfs(8)>, L<xfs_info(8)>." };
 
+  { defaults with
+    name = "internal_available"; added = (1, 31, 25);
+    style = RErr, [StringList "groups"], [];
+    proc_nr = Some 458;
+    visibility = VInternal;
+    shortdesc = "test availability of some parts of the API";
+    longdesc = "\
+This is the internal call which implements C<guestfs_available>." };
+
+  { defaults with
+    name = "internal_feature_available"; added = (1, 31, 25);
+    style = RBool "isavailable", [StringList "groups"], [];
+    proc_nr = Some 459;
+    visibility = VInternal;
+    shortdesc = "test availability of some parts of the API";
+    longdesc = "\
+This is the internal call which implements C<guestfs_feature_available>." };
+
 ]
 
 (* Non-API meta-commands available only in guestfish.
diff --git a/po/POTFILES b/po/POTFILES
index 32f88a1..d87d668 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -300,6 +300,7 @@ src/actions-support.c
 src/actions-variants.c
 src/alloc.c
 src/appliance.c
+src/available.c
 src/bindtests.c
 src/canonical-name.c
 src/cleanup.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index de2a00c..658bd78 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-457
+459
diff --git a/src/Makefile.am b/src/Makefile.am
index 4515c4d..25c6fa3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -83,6 +83,7 @@ libguestfs_la_SOURCES = \
 	actions-variants.c \
 	alloc.c \
 	appliance.c \
+	available.c \
 	bindtests.c \
 	canonical-name.c \
 	command.c \
diff --git a/src/available.c b/src/available.c
new file mode 100644
index 0000000..6738449
--- /dev/null
+++ b/src/available.c
@@ -0,0 +1,34 @@
+/* libguestfs
+ * Copyright (C) 2015 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <config.h>
+
+#include "guestfs.h"
+#include "guestfs-internal-actions.h"
+
+int
+guestfs_impl_available (guestfs_h *g, char *const *groups)
+{
+  return guestfs_internal_available (g, groups);
+}
+
+int
+guestfs_impl_feature_available (guestfs_h *g, char *const *groups)
+{
+  return guestfs_internal_feature_available (g, groups);
+}
-- 
2.1.0




More information about the Libguestfs mailing list