Add a flag "ConfigOnly" to make sure that some non-daemon-functions
should be called only at CONFIG state(RHBZ796520).
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
generator/generator_actions.ml | 44 ++++++++++++++++++++--------------------
generator/generator_c.ml | 8 ++++++-
generator/generator_checks.ml | 1 +
generator/generator_types.ml | 2 +
4 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index d9bd356..53a9607 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -112,7 +112,7 @@ You probably don't want to call this function.")]
*)
let non_daemon_functions = test_functions @ [
- ("launch", (RErr, [], []), -1, [FishAlias "run"; Progress],
+ ("launch", (RErr, [], []), -1, [FishAlias "run"; Progress;
ConfigOnly],
[],
"launch the qemu subprocess",
"\
@@ -122,7 +122,7 @@ using L<qemu(1)>.
You should call this after configuring the handle
(eg. adding drives) but before performing any actions.");
- ("wait_ready", (RErr, [], []), -1, [NotInFish; DeprecatedBy
"launch"],
+ ("wait_ready", (RErr, [], []), -1, [NotInFish; DeprecatedBy
"launch"; ConfigOnly],
[],
"wait until the qemu subprocess launches (no op)",
"\
@@ -143,7 +143,7 @@ versions of the API.");
"\
This kills the qemu subprocess. You should never need to call this.");
- ("add_drive", (RErr, [String "filename"], []), -1, [],
+ ("add_drive", (RErr, [String "filename"], []), -1, [ConfigOnly],
[],
"add an image to examine or modify",
"\
@@ -158,7 +158,7 @@ this security hole. Therefore you should think about replacing
calls to this function with calls to C<guestfs_add_drive_opts>,
and specifying the format.");
- ("add_cdrom", (RErr, [String "filename"], []), -1, [DeprecatedBy
"add_drive_opts"],
+ ("add_cdrom", (RErr, [String "filename"], []), -1, [DeprecatedBy
"add_drive_opts"; ConfigOnly],
[],
"add a CD-ROM disk image to examine",
"\
@@ -185,7 +185,7 @@ should probably use C<guestfs_add_drive_ro> instead.
=back");
- ("add_drive_ro", (RErr, [String "filename"], []), -1, [FishAlias
"add-ro"],
+ ("add_drive_ro", (RErr, [String "filename"], []), -1, [FishAlias
"add-ro"; ConfigOnly],
[],
"add a drive in snapshot mode (read-only)",
"\
@@ -194,7 +194,7 @@ with the optional parameter C<GUESTFS_ADD_DRIVE_OPTS_READONLY>
set to 1,
so the disk is added read-only, with the format being detected
automatically.");
- ("config", (RErr, [String "qemuparam"; OptString
"qemuvalue"], []), -1, [],
+ ("config", (RErr, [String "qemuparam"; OptString
"qemuvalue"], []), -1, [ConfigOnly],
[],
"add qemu parameters",
"\
@@ -207,7 +207,7 @@ The first character of C<param> string must be a C<->
(dash).
C<value> can be NULL.");
- ("set_qemu", (RErr, [OptString "qemu"], []), -1, [FishAlias
"qemu"],
+ ("set_qemu", (RErr, [OptString "qemu"], []), -1, [FishAlias
"qemu"; ConfigOnly],
[],
"set the qemu binary",
"\
@@ -239,7 +239,7 @@ Return the current qemu binary.
This is always non-NULL. If it wasn't set already, then this will
return the default qemu binary name.");
- ("set_path", (RErr, [OptString "searchpath"], []), -1, [FishAlias
"path"],
+ ("set_path", (RErr, [OptString "searchpath"], []), -1, [FishAlias
"path"; ConfigOnly],
[],
"set the search path",
"\
@@ -260,7 +260,7 @@ Return the current search path.
This is always non-NULL. If it wasn't set already, then this will
return the default path.");
- ("set_append", (RErr, [OptString "append"], []), -1, [FishAlias
"append"],
+ ("set_append", (RErr, [OptString "append"], []), -1, [FishAlias
"append"; ConfigOnly],
[],
"add options to kernel command line",
"\
@@ -286,7 +286,7 @@ guest kernel command line.
If C<NULL> then no options are added.");
- ("set_autosync", (RErr, [Bool "autosync"], []), -1, [FishAlias
"autosync"],
+ ("set_autosync", (RErr, [Bool "autosync"], []), -1, [FishAlias
"autosync"; ConfigOnly],
[],
"set autosync mode",
"\
@@ -373,7 +373,7 @@ only useful for printing debug and internal error messages.
For more information on states, see L<guestfs(3)>.");
- ("set_memsize", (RErr, [Int "memsize"], []), -1, [FishAlias
"memsize"],
+ ("set_memsize", (RErr, [Int "memsize"], []), -1, [FishAlias
"memsize"; ConfigOnly],
[InitNone, Always, TestOutputInt (
[["set_memsize"; "500"];
["get_memsize"]], 500)],
@@ -451,7 +451,7 @@ features from later versions into earlier versions,
making this an unreliable way to test for features.
Use C<guestfs_available> instead.");
- ("set_selinux", (RErr, [Bool "selinux"], []), -1, [FishAlias
"selinux"],
+ ("set_selinux", (RErr, [Bool "selinux"], []), -1, [FishAlias
"selinux"; ConfigOnly],
[InitNone, Always, TestOutputTrue (
[["set_selinux"; "true"];
["get_selinux"]])],
@@ -502,7 +502,7 @@ C<guestfs_set_event_callback>).");
"\
Return the command trace flag.");
- ("set_direct", (RErr, [Bool "direct"], []), -1, [FishAlias
"direct"],
+ ("set_direct", (RErr, [Bool "direct"], []), -1, [FishAlias
"direct"; ConfigOnly],
[InitNone, Always, TestOutputFalse (
[["set_direct"; "false"];
["get_direct"]])],
@@ -527,7 +527,7 @@ The default is disabled.");
"\
Return the direct appliance mode flag.");
- ("set_recovery_proc", (RErr, [Bool "recoveryproc"], []), -1,
[FishAlias "recovery-proc"],
+ ("set_recovery_proc", (RErr, [Bool "recoveryproc"], []), -1,
[FishAlias "recovery-proc"; ConfigOnly],
[InitNone, Always, TestOutputTrue (
[["set_recovery_proc"; "true"];
["get_recovery_proc"]])],
@@ -553,14 +553,14 @@ qemu, which is not very helpful.");
"\
Return the recovery process enabled flag.");
- ("add_drive_with_if", (RErr, [String "filename"; String
"iface"], []), -1, [DeprecatedBy "add_drive_opts"],
+ ("add_drive_with_if", (RErr, [String "filename"; String
"iface"], []), -1, [DeprecatedBy "add_drive_opts"; ConfigOnly],
[],
"add a drive specifying the QEMU block emulation to use",
"\
This is the same as C<guestfs_add_drive> but it allows you
to specify the QEMU interface emulation to use at run time.");
- ("add_drive_ro_with_if", (RErr, [String "filename"; String
"iface"], []), -1, [DeprecatedBy "add_drive_opts"],
+ ("add_drive_ro_with_if", (RErr, [String "filename"; String
"iface"], []), -1, [DeprecatedBy "add_drive_opts"; ConfigOnly],
[],
"add a drive read-only specifying the QEMU block emulation to use",
"\
@@ -968,7 +968,7 @@ for a filesystem to be shared between operating systems.
Please read L<guestfs(3)/INSPECTION> for more details.
See also C<guestfs_inspect_get_mountpoints>.");
- ("set_network", (RErr, [Bool "network"], []), -1, [FishAlias
"network"],
+ ("set_network", (RErr, [Bool "network"], []), -1, [FishAlias
"network"; ConfigOnly],
[],
"set enable network flag",
"\
@@ -1020,7 +1020,7 @@ be mountable but require special options. Filesystems may
not all belong to a single logical operating system
(use C<guestfs_inspect_os> to look for OSes).");
- ("add_drive_opts", (RErr, [String "filename"], [OBool
"readonly"; OString "format"; OString "iface"; OString
"name"]), -1, [FishAlias "add"],
+ ("add_drive_opts", (RErr, [String "filename"], [OBool
"readonly"; OString "format"; OString "iface"; OString
"name"]), -1, [FishAlias "add"; ConfigOnly],
[],
"add an image to examine or modify",
"\
@@ -1110,7 +1110,7 @@ not part of the formal API and can be removed or changed at any
time.");
This returns the internal list of drives. 'debug' commands are
not part of the formal API and can be removed or changed at any time.");
- ("add_domain", (RInt "nrdisks", [String "dom"], [OString
"libvirturi"; OBool "readonly"; OString "iface"; OBool
"live"; OBool "allowuuid"; OString "readonlydisk"]), -1,
[FishAlias "domain"],
+ ("add_domain", (RInt "nrdisks", [String "dom"], [OString
"libvirturi"; OBool "readonly"; OString "iface"; OBool
"live"; OBool "allowuuid"; OString "readonlydisk"]), -1,
[FishAlias "domain"; ConfigOnly],
[],
"add the disk(s) from a named libvirt domain",
"\
@@ -1450,7 +1450,7 @@ part of a set.
Please read L<guestfs(3)/INSPECTION> for more details.");
- ("set_attach_method", (RErr, [String "attachmethod"], []), -1,
[FishAlias "attach-method"],
+ ("set_attach_method", (RErr, [String "attachmethod"], []), -1,
[FishAlias "attach-method"; ConfigOnly],
[],
"set the attach method",
"\
@@ -1618,7 +1618,7 @@ advice before using trademarks in applications.
=back");
- ("set_pgroup", (RErr, [Bool "pgroup"], []), -1, [FishAlias
"pgroup"],
+ ("set_pgroup", (RErr, [Bool "pgroup"], []), -1, [FishAlias
"pgroup"; ConfigOnly],
[],
"set process group flag",
"\
@@ -1637,7 +1637,7 @@ C<^C> to kill the subprocess.");
"\
This returns the process group flag.");
- ("set_smp", (RErr, [Int "smp"], []), -1, [FishAlias
"smp"],
+ ("set_smp", (RErr, [Int "smp"], []), -1, [FishAlias
"smp"; ConfigOnly],
[],
"set number of virtual CPUs in appliance",
"\
diff --git a/generator/generator_c.ml b/generator/generator_c.ml
index 7b73197..a312a43 100644
--- a/generator/generator_c.ml
+++ b/generator/generator_c.ml
@@ -1012,7 +1012,7 @@ trace_send_line (guestfs_h *g)
(* For non-daemon functions, generate a wrapper around each function. *)
List.iter (
- fun (shortname, (ret, _, optargs as style), _, _, _, _, _) ->
+ fun (shortname, (ret, _, optargs as style), _, flags, _, _, _) ->
if optargs = [] then
generate_prototype ~extern:false ~semicolon:false ~newline:true
~handle:"g" ~prefix:"guestfs_"
@@ -1046,6 +1046,12 @@ trace_send_line (guestfs_h *g)
pr " struct guestfs_%s_list *r;\n" typ
);
pr "\n";
+ if List.mem ConfigOnly flags then (
+ pr " if (g->state != CONFIG) {\n";
+ pr " error (g, \"This ConfigOnly function can only be called at
config state.\");\n";
+ pr " return -1;\n";
+ pr " }\n";
+ );
enter_event shortname;
check_null_strings shortname style;
reject_unknown_optargs shortname style;
diff --git a/generator/generator_checks.ml b/generator/generator_checks.ml
index 464b9cd..df038d0 100644
--- a/generator/generator_checks.ml
+++ b/generator/generator_checks.ml
@@ -189,6 +189,7 @@ let () =
| FishOutput _
| NotInFish
| NotInDocs
+ | ConfigOnly
| Progress -> ()
| FishAlias n ->
if contains_uppercase n then
diff --git a/generator/generator_types.ml b/generator/generator_types.ml
index dffe7c5..7555970 100644
--- a/generator/generator_types.ml
+++ b/generator/generator_types.ml
@@ -228,6 +228,8 @@ type flags =
This flag is currently only used by the GObject
bindings. *)
| Cancellable (* The user can cancel this long-running function *)
+ | ConfigOnly (* The non-daemon-function which only used at CONFIG
+ state. *)
and fish_output_t =
| FishOutputOctal (* for int return, print in octal *)
--
1.7.9