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
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();
}
/*