From 20f190617aafcddd08f99c0abec4fef90426ec9e Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 2 Sep 2016 16:00:37 +0100 Subject: [PATCH] daemon: Split up very large daemon/stubs.c file. --- .gitignore | 5 +- daemon/Makefile.am | 26 +++++++-- daemon/daemon.h | 8 +++ daemon/guestfsd.c | 9 +++ docs/C_SOURCE_FILES | 10 +++- generator/daemon.ml | 128 +++++++++++++++++++++++++++++-------------- generator/daemon.mli | 5 +- generator/main.ml | 5 +- po/POTFILES | 10 +++- 9 files changed, 154 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 8312d9969..8ec5319ad 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/daemon/Makefile.am b/daemon/Makefile.am index df93d7eaf..23f60eb6f 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -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 \ diff --git a/daemon/daemon.h b/daemon/daemon.h index 9fb047239..79a5288f6 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -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; diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index b343d7e4d..b129ad045 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -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); + } +} diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES index a94b009f6..fde4ad650 100644 --- a/docs/C_SOURCE_FILES +++ b/docs/C_SOURCE_FILES @@ -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 diff --git a/generator/daemon.ml b/generator/daemon.ml index e24ae15ee..ce5dada59 100644 --- a/generator/daemon.ml +++ b/generator/daemon.ml @@ -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 - -#include -#include -#include -#include -#include -#include -#include - -#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 + +#include +#include +#include +#include +#include +#include +#include + +#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 + +#include +#include +#include +#include +#include +#include +#include + +#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 + +#include +#include +#include +#include +#include +#include +#include + +#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 \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 \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"; diff --git a/generator/daemon.mli b/generator/daemon.mli index 21788aa6f..d60d0e6b2 100644 --- a/generator/daemon.mli +++ b/generator/daemon.mli @@ -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 diff --git a/generator/main.ml b/generator/main.ml index 52b77b4aa..50e402f4b 100644 --- a/generator/main.ml +++ b/generator/main.ml @@ -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; diff --git a/po/POTFILES b/po/POTFILES index 70213eb7a..53d4bdd50 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -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