daemon: Split up very large daemon/stubs.c file.

This commit is contained in:
Richard W.M. Jones
2016-09-02 16:00:37 +01:00
parent a749b5d93a
commit 20f190617a
9 changed files with 154 additions and 52 deletions

5
.gitignore vendored
View File

@@ -133,6 +133,7 @@ Makefile.in
/customize/virt-customize
/customize/virt-customize.1
/daemon/actions.h
/daemon/dispatch.c
/daemon/errnostring.c
/daemon/errnostring-gperf.c
/daemon/errnostring-gperf.gperf
@@ -147,8 +148,10 @@ Makefile.in
/daemon/names.c
/daemon/optgroups.c
/daemon/optgroups.h
/daemon/lvm-tokenization.c
/daemon/stamp-guestfsd.pod
/daemon/stubs.c
/daemon/stubs-?.c
/daemon/stubs.h
/depcomp
/df/stamp-virt-df.pod
/df/virt-df

View File

@@ -19,8 +19,16 @@ include $(top_srcdir)/subdir-rules.mk
generator_built = \
actions.h \
stubs.c \
names.c
dispatch.c \
names.c \
lvm-tokenization.c \
stubs-0.c \
stubs-1.c \
stubs-2.c \
stubs-3.c \
stubs-4.c \
stubs-5.c \
stubs-6.c
shared_with_library = \
guestfs_protocol.c \
@@ -74,11 +82,7 @@ else
noinst_PROGRAMS = guestfsd
endif
# Compile the largest file (stubs.c) first. The other files are
# listed alphabetically. See also:
# https://rwmj.wordpress.com/2015/09/30/make-and-queuing-theory/#content
guestfsd_SOURCES = \
stubs.c \
9p.c \
acl.c \
actions.h \
@@ -107,6 +111,7 @@ guestfsd_SOURCES = \
devsparts.c \
df.c \
dir.c \
dispatch.c \
dmesg.c \
dropcaches.c \
du.c \
@@ -143,6 +148,7 @@ guestfsd_SOURCES = \
luks.c \
lvm.c \
lvm-filter.c \
lvm-tokenization.c \
md.c \
mkfs.c \
mknod.c \
@@ -172,6 +178,14 @@ guestfsd_SOURCES = \
stat.c \
statvfs.c \
strings.c \
stubs-0.c \
stubs-1.c \
stubs-2.c \
stubs-3.c \
stubs-4.c \
stubs-5.c \
stubs-6.c \
stubs.h \
swap.c \
sync.c \
syslinux.c \

View File

@@ -43,6 +43,14 @@ typedef struct {
char *volume;
} mountable_t;
extern void cleanup_free_mountable (mountable_t *mountable);
#ifdef HAVE_ATTRIBUTE_CLEANUP
#define CLEANUP_FREE_MOUNTABLE __attribute__((cleanup(cleanup_free_mountable)))
#else
#define CLEANUP_FREE_MOUNTABLE
#endif
/*-- in guestfsd.c --*/
extern int verbose;

View File

@@ -1249,3 +1249,12 @@ get_random_uuid (void)
return out;
}
void
cleanup_free_mountable (mountable_t *mountable)
{
if (mountable) {
free (mountable->device);
free (mountable->volume);
}
}

View File

@@ -37,6 +37,7 @@ daemon/debug.c
daemon/devsparts.c
daemon/df.c
daemon/dir.c
daemon/dispatch.c
daemon/dmesg.c
daemon/dropcaches.c
daemon/du.c
@@ -72,6 +73,7 @@ daemon/link.c
daemon/ls.c
daemon/luks.c
daemon/lvm-filter.c
daemon/lvm-tokenization.c
daemon/lvm.c
daemon/md.c
daemon/mkfs.c
@@ -101,7 +103,13 @@ daemon/sleuthkit.c
daemon/stat.c
daemon/statvfs.c
daemon/strings.c
daemon/stubs.c
daemon/stubs-0.c
daemon/stubs-1.c
daemon/stubs-2.c
daemon/stubs-3.c
daemon/stubs-4.c
daemon/stubs-5.c
daemon/stubs-6.c
daemon/swap.c
daemon/sync.c
daemon/syslinux.c

View File

@@ -72,26 +72,12 @@ let generate_daemon_actions_h () =
pr "\n";
pr "#endif /* GUESTFSD_ACTIONS_H */\n"
(* Generate the server-side stubs. *)
and generate_daemon_actions () =
let generate_daemon_stubs_h () =
generate_header CStyle GPLv2plus;
pr "\
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include \"daemon.h\"
#include \"c-ctype.h\"
#include \"guestfs_protocol.h\"
#include \"actions.h\"
#include \"optgroups.h\"
#ifndef GUESTFSD_STUBS_H
#define GUESTFSD_STUBS_H
/* Some macros to make resolving devices easier. These used to
* be available in daemon.h but now they are only used by stubs.
@@ -201,30 +187,44 @@ and generate_daemon_actions () =
} \\
} while (0) \\
/* Free the mountable.device & mountable.volume fields which are
* allocated by the above macros.
*/
#ifdef HAVE_ATTRIBUTE_CLEANUP
#define CLEANUP_FREE_MOUNTABLE __attribute__((cleanup(cleanup_free_mountable)))
#else
#define CLEANUP_FREE_MOUNTABLE
#endif
";
static void
cleanup_free_mountable (mountable_t *mountable)
{
if (mountable) {
free (mountable->device);
free (mountable->volume);
}
}
List.iter (
fun { name = name } ->
pr "extern void %s_stub (XDR *xdr_in);\n" name;
) (actions |> daemon_functions);
pr "\n";
pr "#endif /* GUESTFSD_STUBS_H */\n"
(* Generate the server-side stubs. *)
let generate_daemon_stubs actions () =
generate_header CStyle GPLv2plus;
pr "\
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include \"daemon.h\"
#include \"c-ctype.h\"
#include \"guestfs_protocol.h\"
#include \"actions.h\"
#include \"optgroups.h\"
#include \"stubs.h\"
";
List.iter (
fun { name = name; style = ret, args, optargs; optional = optional } ->
(* Generate server-side stubs. *)
pr "static void\n";
pr "void\n";
pr "%s_stub (XDR *xdr_in)\n" name;
pr "{\n";
(match ret with
@@ -508,10 +508,34 @@ cleanup_free_mountable (mountable_t *mountable)
pr "done_no_free:\n";
pr " return;\n";
pr "}\n\n";
) (actions |> daemon_functions);
) (actions |> daemon_functions)
let generate_daemon_dispatch () =
generate_header CStyle GPLv2plus;
pr "\
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include \"daemon.h\"
#include \"c-ctype.h\"
#include \"guestfs_protocol.h\"
#include \"actions.h\"
#include \"optgroups.h\"
#include \"stubs.h\"
";
(* Dispatch function. *)
pr "void dispatch_incoming_message (XDR *xdr_in)\n";
pr "void\n";
pr "dispatch_incoming_message (XDR *xdr_in)\n";
pr "{\n";
pr " switch (proc_nr) {\n";
@@ -526,7 +550,29 @@ cleanup_free_mountable (mountable_t *mountable)
pr " reply_with_error (\"dispatch_incoming_message: unknown procedure number %%d, set LIBGUESTFS_PATH to point to the matching libguestfs appliance directory\", proc_nr);\n";
pr " }\n";
pr "}\n";
pr "\n";
pr "\n"
let generate_daemon_lvm_tokenization () =
generate_header CStyle GPLv2plus;
pr "\
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include \"daemon.h\"
#include \"c-ctype.h\"
#include \"guestfs_protocol.h\"
#include \"actions.h\"
#include \"optgroups.h\"
";
(* LVM columns and tokenization functions. *)
(* XXX This generates crap code. We should rethink how we
@@ -697,7 +743,7 @@ cleanup_free_mountable (mountable_t *mountable)
) ["pv", lvm_pv_cols; "vg", lvm_vg_cols; "lv", lvm_lv_cols]
(* Generate a list of function names, for debugging in the daemon.. *)
and generate_daemon_names () =
let generate_daemon_names () =
generate_header CStyle GPLv2plus;
pr "#include <config.h>\n";
@@ -713,12 +759,12 @@ and generate_daemon_names () =
pr " [%d] = \"%s\",\n" proc_nr name
| { proc_nr = None } -> assert false
) (actions |> daemon_functions);
pr "};\n";
pr "};\n"
(* Generate the optional groups for the daemon to implement
* guestfs_available.
*)
and generate_daemon_optgroups_c () =
let generate_daemon_optgroups_c () =
generate_header CStyle GPLv2plus;
pr "#include <config.h>\n";
@@ -747,7 +793,7 @@ and generate_daemon_optgroups_c () =
pr " { NULL, NULL }\n";
pr "};\n"
and generate_daemon_optgroups_h () =
let generate_daemon_optgroups_h () =
generate_header CStyle GPLv2plus;
pr "#ifndef GUESTFSD_OPTGROUPS_H\n";

View File

@@ -16,8 +16,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)
val generate_daemon_actions : unit -> unit
val generate_daemon_actions_h : unit -> unit
val generate_daemon_stubs_h : unit -> unit
val generate_daemon_stubs : Types.action list -> unit -> unit
val generate_daemon_dispatch : unit -> unit
val generate_daemon_lvm_tokenization : unit -> unit
val generate_daemon_names : unit -> unit
val generate_daemon_optgroups_c : unit -> unit
val generate_daemon_optgroups_h : unit -> unit

View File

@@ -119,10 +119,13 @@ Run it from the top source directory using the command
output_to "src/actions-variants.c" generate_client_actions_variants;
output_to_subset "src/actions-%d.c" generate_client_actions;
output_to "daemon/actions.h" generate_daemon_actions_h;
output_to "daemon/stubs.c" generate_daemon_actions;
output_to "daemon/stubs.h" generate_daemon_stubs_h;
output_to_subset "daemon/stubs-%d.c" generate_daemon_stubs;
output_to "daemon/dispatch.c" generate_daemon_dispatch;
output_to "daemon/names.c" generate_daemon_names;
output_to "daemon/optgroups.c" generate_daemon_optgroups_c;
output_to "daemon/optgroups.h" generate_daemon_optgroups_h;
output_to "daemon/lvm-tokenization.c" generate_daemon_lvm_tokenization;
output_to "tests/c-api/tests.c" generate_c_api_tests;
output_to "fish/cmds-gperf.gperf" generate_fish_cmds_gperf;
output_to "fish/cmds.c" generate_fish_cmds;

View File

@@ -39,6 +39,7 @@ daemon/debug.c
daemon/devsparts.c
daemon/df.c
daemon/dir.c
daemon/dispatch.c
daemon/dmesg.c
daemon/dropcaches.c
daemon/du.c
@@ -76,6 +77,7 @@ daemon/link.c
daemon/ls.c
daemon/luks.c
daemon/lvm-filter.c
daemon/lvm-tokenization.c
daemon/lvm.c
daemon/md.c
daemon/mkfs.c
@@ -105,7 +107,13 @@ daemon/sleuthkit.c
daemon/stat.c
daemon/statvfs.c
daemon/strings.c
daemon/stubs.c
daemon/stubs-0.c
daemon/stubs-1.c
daemon/stubs-2.c
daemon/stubs-3.c
daemon/stubs-4.c
daemon/stubs-5.c
daemon/stubs-6.c
daemon/swap.c
daemon/sync.c
daemon/syslinux.c