]> sourceware.org Git - dm.git/commitdiff
Tidy the way we call init/exit functions.
authorAlasdair Kergon <agk@redhat.com>
Wed, 20 Mar 2002 23:45:47 +0000 (23:45 +0000)
committerAlasdair Kergon <agk@redhat.com>
Wed, 20 Mar 2002 23:45:47 +0000 (23:45 +0000)
kernel/Makefile.in
kernel/common/dm.c.in

index e2cd706002d3b9c13960c1381f3464c14319315d..174e4602b8bddd27665fa9a4b05219305c84be91 100644 (file)
@@ -31,7 +31,7 @@ LN_S = @LN_S@
 FS=dmfs-error.c dmfs-lv.c dmfs-root.c dmfs-status.c \
    dmfs-super.c dmfs-suspend.c dmfs-table.c dmfs.h
 
-COMMON=device-mapper.h dm-linear.c dm-stripe.c \
+COMMON=dm-linear.c dm-stripe.c \
        dm-mirror.c dm-origin.c dm-snapshot.c kcopyd.c \
        dm-table.c dm-target.c dm.c dm.h dm-snapshot.h \
        dm-exception-store.c
index 5b593123bb11aaa139ca25dd816cc14a2239b105..bf9537caff3bb4a7617308eb450e70bf02ebe230 100644 (file)
@@ -234,80 +234,59 @@ static void local_exit(void)
        DMINFO("%s cleaned up", _version);
 }
 
-static int __init dm_init(void)
-{
-       int r;
-
-       r = local_init();
-       if (r)
-               goto out;
-
-       r = dm_target_init();
-       if (r)
-               goto out_local;
-
-       r = dm_linear_init();
-       if (r)
-               goto out_target;
-
-       r = dm_stripe_init();
-       if (r)
-               goto out_linear;
-
-       r = kcopyd_init();
-       if (r)
-               goto out_stripe;
+/*
+ * We have a lot of init/exit functions, so it seems easier to
+ * store them in an array.  The disposable macro 'xx'
+ * expands a prefix into a pair of function names.
+ */
+#define xx(n) {n ## _init, n ## _exit}
+static struct {
+       int (*init)(void);
+       void (*exit)(void);
+
+} _inits[] = {
+       xx(local),
+       xx(dm_target),
+       xx(dm_linear),
+       xx(dm_stripe),
+       xx(kcopyd),
+       xx(dm_snapshot),
+       xx(dm_origin),
+       xx(dm_mirror),
+       xx(dm_interface),
+};
 
-       r = dm_snapshot_init();
-       if (r)
-               goto out_kcopyd;
+#undef xx
 
-       r = dm_origin_init();
-       if (r)
-               goto out_snapshot;
+static int __init dm_init(void)
+{
+       const int count = sizeof(_inits) / sizeof(*_inits);
 
-       r = dm_mirror_init();
-       if (r)
-               goto out_origin;
+       int r, i;
 
-       r = dm_interface_init();
-       if (r)
-               goto out_mirror;
+       for (i = 0; i < count; i++) {
+               r = _inits[i].init();
+               if (r)
+                       goto bad;
+       }
 
        return 0;
 
-      out_mirror:
-       dm_mirror_exit();
-      out_origin:
-       dm_origin_exit();
-      out_snapshot:
-       dm_snapshot_exit();
-      out_kcopyd:
-       kcopyd_exit();
-      out_stripe:
-       dm_stripe_exit();
-      out_linear:
-       dm_linear_exit();
-      out_target:
-       dm_target_exit();
-      out_local:
-       local_exit();
-      out:
+      bad:
+       while (i--)
+               _inits[i].exit();
+
        return r;
 }
 
 static void __exit dm_exit(void)
 {
+       int i = sizeof(_inits) / sizeof(*_inits);
+
        dm_destroy_all();
-       dm_interface_exit();
-       dm_stripe_exit();
-       dm_linear_exit();
-       dm_snapshot_exit();
-       dm_origin_exit();
-       dm_mirror_exit();
-       kcopyd_exit();
-       dm_target_exit();
-       local_exit();
+
+       while (i--)
+               _inits[i].exit();
 }
 
 /*
This page took 0.027948 seconds and 5 git commands to generate.