289 lines
12 KiB
Diff
289 lines
12 KiB
Diff
From 7e145ef8bd7a45fef6ee4cf56d7fab9f21d23e72 Mon Sep 17 00:00:00 2001
|
|
From: Emil Velikov <emil.velikov@collabora.com>
|
|
Date: Mon, 6 Feb 2023 13:18:34 +0000
|
|
Subject: [PATCH 5/9] depmod: Introduce outdir option
|
|
|
|
This option is equivalent to basedir, with the small difference being
|
|
that's where the meta-data files are generated. In other words, this
|
|
allows us to have read-only input modules and modules.dep, while still
|
|
being able to generate the meta-data files.
|
|
|
|
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
|
|
[ Move files to a different dir so input files (produced by kernel build
|
|
system is separate from the files generated by depmod (output) ]
|
|
Signed-off-by: Lucas De Marchi <lucas.demarchi@gmail.com>
|
|
---
|
|
man/depmod.xml | 20 ++++++++++
|
|
.../modules-outdir/correct-modules.alias | 37 +++++++++++++++++++
|
|
.../modules-outdir/correct-modules.dep | 3 ++
|
|
.../lib/modules/4.4.4/modules.builtin | 0
|
|
.../lib/modules/4.4.4/modules.order | 7 ++++
|
|
testsuite/setup-rootfs.sh | 3 ++
|
|
testsuite/test-depmod.c | 36 ++++++++++++++++++
|
|
tools/depmod.c | 25 +++++++++++--
|
|
8 files changed, 128 insertions(+), 3 deletions(-)
|
|
create mode 100644 testsuite/rootfs-pristine/test-depmod/modules-outdir/correct-modules.alias
|
|
create mode 100644 testsuite/rootfs-pristine/test-depmod/modules-outdir/correct-modules.dep
|
|
create mode 100644 testsuite/rootfs-pristine/test-depmod/modules-outdir/lib/modules/4.4.4/modules.builtin
|
|
create mode 100644 testsuite/rootfs-pristine/test-depmod/modules-outdir/lib/modules/4.4.4/modules.order
|
|
|
|
diff --git a/man/depmod.xml b/man/depmod.xml
|
|
index ea0be27280b2..3b0097184fd7 100644
|
|
--- a/man/depmod.xml
|
|
+++ b/man/depmod.xml
|
|
@@ -45,6 +45,7 @@
|
|
<cmdsynopsis>
|
|
<command>depmod</command>
|
|
<arg><option>-b <replaceable>basedir</replaceable></option></arg>
|
|
+ <arg><option>-o <replaceable>outdir</replaceable></option></arg>
|
|
<arg><option>-e</option></arg>
|
|
<arg><option>-E <replaceable>Module.symvers</replaceable></option></arg>
|
|
<arg><option>-F <replaceable>System.map</replaceable></option></arg>
|
|
@@ -151,6 +152,25 @@
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
+ <varlistentry>
|
|
+ <term>
|
|
+ <option>-o <replaceable>outdir</replaceable></option>
|
|
+ </term>
|
|
+ <term>
|
|
+ <option>--outdir <replaceable>outdir</replaceable></option>
|
|
+ </term>
|
|
+ <listitem>
|
|
+ <para>
|
|
+ Set the output directory where depmod will store any generated file.
|
|
+ <replaceable>outdir</replaceable> serves as a root to that location,
|
|
+ similar to how <replaceable>basedir</replaceable> is used. Also this
|
|
+ setting takes precedence and if used together with
|
|
+ <replaceable>basedir</replaceable> it will result in the input being
|
|
+ that directory, but the output being the one set by
|
|
+ <replaceable>outdir</replaceable>.
|
|
+ </para>
|
|
+ </listitem>
|
|
+ </varlistentry>
|
|
<varlistentry>
|
|
<term>
|
|
<option>-C</option>
|
|
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-outdir/correct-modules.alias b/testsuite/rootfs-pristine/test-depmod/modules-outdir/correct-modules.alias
|
|
new file mode 100644
|
|
index 000000000000..56753291c47e
|
|
--- /dev/null
|
|
+++ b/testsuite/rootfs-pristine/test-depmod/modules-outdir/correct-modules.alias
|
|
@@ -0,0 +1,37 @@
|
|
+# Aliases extracted from modules themselves.
|
|
+alias pci:v0000103Cd00003230sv0000103Csd0000323Dbc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003230sv0000103Csd00003237bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003238sv0000103Csd00003215bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003238sv0000103Csd00003214bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003238sv0000103Csd00003213bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003238sv0000103Csd00003212bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003238sv0000103Csd00003211bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003230sv0000103Csd00003235bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003230sv0000103Csd00003234bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003230sv0000103Csd00003223bc*sc*i* cciss
|
|
+alias pci:v0000103Cd00003220sv0000103Csd00003225bc*sc*i* cciss
|
|
+alias pci:v00000E11d00000046sv00000E11sd0000409Dbc*sc*i* cciss
|
|
+alias pci:v00000E11d00000046sv00000E11sd0000409Cbc*sc*i* cciss
|
|
+alias pci:v00000E11d00000046sv00000E11sd0000409Bbc*sc*i* cciss
|
|
+alias pci:v00000E11d00000046sv00000E11sd0000409Abc*sc*i* cciss
|
|
+alias pci:v00000E11d00000046sv00000E11sd00004091bc*sc*i* cciss
|
|
+alias pci:v00000E11d0000B178sv00000E11sd00004083bc*sc*i* cciss
|
|
+alias pci:v00000E11d0000B178sv00000E11sd00004082bc*sc*i* cciss
|
|
+alias pci:v00000E11d0000B178sv00000E11sd00004080bc*sc*i* cciss
|
|
+alias pci:v00000E11d0000B060sv00000E11sd00004070bc*sc*i* cciss
|
|
+alias pci:v0000103Cd*sv*sd*bc01sc04i* hpsa
|
|
+alias pci:v0000103Cd0000323Bsv0000103Csd00003356bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Bsv0000103Csd00003355bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Bsv0000103Csd00003354bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Bsv0000103Csd00003353bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Bsv0000103Csd00003352bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Bsv0000103Csd00003351bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Bsv0000103Csd00003350bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Asv0000103Csd00003233bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Asv0000103Csd0000324Bbc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Asv0000103Csd0000324Abc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Asv0000103Csd00003249bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Asv0000103Csd00003247bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Asv0000103Csd00003245bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Asv0000103Csd00003243bc*sc*i* hpsa
|
|
+alias pci:v0000103Cd0000323Asv0000103Csd00003241bc*sc*i* hpsa
|
|
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-outdir/correct-modules.dep b/testsuite/rootfs-pristine/test-depmod/modules-outdir/correct-modules.dep
|
|
new file mode 100644
|
|
index 000000000000..ec50ac32426a
|
|
--- /dev/null
|
|
+++ b/testsuite/rootfs-pristine/test-depmod/modules-outdir/correct-modules.dep
|
|
@@ -0,0 +1,3 @@
|
|
+kernel/drivers/block/cciss.ko:
|
|
+kernel/drivers/scsi/scsi_mod.ko:
|
|
+kernel/drivers/scsi/hpsa.ko: kernel/drivers/scsi/scsi_mod.ko
|
|
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-outdir/lib/modules/4.4.4/modules.builtin b/testsuite/rootfs-pristine/test-depmod/modules-outdir/lib/modules/4.4.4/modules.builtin
|
|
new file mode 100644
|
|
index 000000000000..e69de29bb2d1
|
|
diff --git a/testsuite/rootfs-pristine/test-depmod/modules-outdir/lib/modules/4.4.4/modules.order b/testsuite/rootfs-pristine/test-depmod/modules-outdir/lib/modules/4.4.4/modules.order
|
|
new file mode 100644
|
|
index 000000000000..4b643099f661
|
|
--- /dev/null
|
|
+++ b/testsuite/rootfs-pristine/test-depmod/modules-outdir/lib/modules/4.4.4/modules.order
|
|
@@ -0,0 +1,7 @@
|
|
+#336
|
|
+kernel/drivers/block/cciss.ko
|
|
+#2094
|
|
+kernel/drivers/scsi/scsi_mod.ko
|
|
+#2137
|
|
+kernel/drivers/scsi/hpsa.ko
|
|
+
|
|
diff --git a/testsuite/setup-rootfs.sh b/testsuite/setup-rootfs.sh
|
|
index d9cc627f7224..3e814d22d813 100755
|
|
--- a/testsuite/setup-rootfs.sh
|
|
+++ b/testsuite/setup-rootfs.sh
|
|
@@ -70,6 +70,9 @@ map=(
|
|
["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/block/cciss.ko"]="mod-fake-cciss.ko"
|
|
["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko"]="mod-fake-hpsa.ko"
|
|
["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko"]="mod-fake-scsi-mod.ko"
|
|
+ ["test-depmod/modules-outdir/lib/modules/4.4.4/kernel/drivers/block/cciss.ko"]="mod-fake-cciss.ko"
|
|
+ ["test-depmod/modules-outdir/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko"]="mod-fake-hpsa.ko"
|
|
+ ["test-depmod/modules-outdir/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko"]="mod-fake-scsi-mod.ko"
|
|
["test-modinfo/mod-simple-i386.ko"]="mod-simple-i386.ko"
|
|
["test-modinfo/mod-simple-x86_64.ko"]="mod-simple-x86_64.ko"
|
|
["test-modinfo/mod-simple-sparc64.ko"]="mod-simple-sparc64.ko"
|
|
diff --git a/testsuite/test-depmod.c b/testsuite/test-depmod.c
|
|
index d7802d7b2e0b..6e3ae562d766 100644
|
|
--- a/testsuite/test-depmod.c
|
|
+++ b/testsuite/test-depmod.c
|
|
@@ -57,6 +57,42 @@ DEFINE_TEST(depmod_modules_order_for_compressed,
|
|
},
|
|
});
|
|
|
|
+#define MODULES_OUTDIR_UNAME "4.4.4"
|
|
+#define MODULES_OUTDIR_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-outdir"
|
|
+#define MODULES_OUTDIR_LIB_MODULES_OUTPUT MODULES_OUTDIR_ROOTFS "/outdir/lib/modules/" MODULES_OUTDIR_UNAME
|
|
+#define MODULES_OUTDIR_LIB_MODULES_INPUT MODULES_OUTDIR_ROOTFS "/lib/modules/" MODULES_OUTDIR_UNAME
|
|
+static noreturn int depmod_modules_outdir(const struct test *t)
|
|
+{
|
|
+ const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
|
|
+ const char *const args[] = {
|
|
+ progname,
|
|
+ "--outdir", MODULES_OUTDIR_ROOTFS "/outdir/",
|
|
+ NULL,
|
|
+ };
|
|
+
|
|
+ test_spawn_prog(progname, args);
|
|
+ exit(EXIT_FAILURE);
|
|
+}
|
|
+
|
|
+DEFINE_TEST(depmod_modules_outdir,
|
|
+#if defined(KMOD_SYSCONFDIR_NOT_ETC)
|
|
+ .skip = true,
|
|
+#endif
|
|
+ .description = "check if depmod honours the outdir option",
|
|
+ .config = {
|
|
+ [TC_UNAME_R] = MODULES_OUTDIR_UNAME,
|
|
+ [TC_ROOTFS] = MODULES_OUTDIR_ROOTFS,
|
|
+ },
|
|
+ .output = {
|
|
+ .files = (const struct keyval[]) {
|
|
+ { MODULES_OUTDIR_LIB_MODULES_OUTPUT "/modules.dep",
|
|
+ MODULES_OUTDIR_ROOTFS "/correct-modules.dep" },
|
|
+ { MODULES_OUTDIR_LIB_MODULES_OUTPUT "/modules.alias",
|
|
+ MODULES_OUTDIR_ROOTFS "/correct-modules.alias" },
|
|
+ { }
|
|
+ },
|
|
+ });
|
|
+
|
|
#define SEARCH_ORDER_SIMPLE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-simple"
|
|
static noreturn int depmod_search_order_simple(const struct test *t)
|
|
{
|
|
diff --git a/tools/depmod.c b/tools/depmod.c
|
|
index a9349b20ee9c..2d4cf75fdfee 100644
|
|
--- a/tools/depmod.c
|
|
+++ b/tools/depmod.c
|
|
@@ -59,11 +59,12 @@ static const char *default_cfg_paths[] = {
|
|
NULL
|
|
};
|
|
|
|
-static const char cmdopts_s[] = "aAb:C:E:F:euqrvnP:wmVh";
|
|
+static const char cmdopts_s[] = "aAb:o:C:E:F:euqrvnP:wmVh";
|
|
static const struct option cmdopts[] = {
|
|
{ "all", no_argument, 0, 'a' },
|
|
{ "quick", no_argument, 0, 'A' },
|
|
{ "basedir", required_argument, 0, 'b' },
|
|
+ { "outdir", required_argument, 0, 'o' },
|
|
{ "config", required_argument, 0, 'C' },
|
|
{ "symvers", required_argument, 0, 'E' },
|
|
{ "filesyms", required_argument, 0, 'F' },
|
|
@@ -105,6 +106,7 @@ static void help(void)
|
|
"\n"
|
|
"The following options are useful for people managing distributions:\n"
|
|
"\t-b, --basedir=DIR Use an image of a module tree.\n"
|
|
+ "\t-o, --outdir=DIR Output directory for generated files.\n"
|
|
"\t-F, --filesyms=FILE Use the file instead of the\n"
|
|
"\t current kernel symbols.\n"
|
|
"\t-E, --symvers=FILE Use Module.symvers file to check\n"
|
|
@@ -468,6 +470,8 @@ struct cfg {
|
|
const char *kversion;
|
|
char dirname[PATH_MAX];
|
|
size_t dirnamelen;
|
|
+ char outdirname[PATH_MAX];
|
|
+ size_t outdirnamelen;
|
|
char sym_prefix;
|
|
uint8_t check_symvers;
|
|
uint8_t print_unknown;
|
|
@@ -2577,7 +2581,7 @@ static int depmod_output(struct depmod *depmod, FILE *out)
|
|
{ "modules.devname", output_devname },
|
|
{ }
|
|
};
|
|
- const char *dname = depmod->cfg->dirname;
|
|
+ const char *dname = depmod->cfg->outdirname;
|
|
int dfd, err = 0;
|
|
struct timeval tv;
|
|
|
|
@@ -2586,6 +2590,11 @@ static int depmod_output(struct depmod *depmod, FILE *out)
|
|
if (out != NULL)
|
|
dfd = -1;
|
|
else {
|
|
+ err = mkdir_p(dname, strlen(dname), 0755);
|
|
+ if (err < 0) {
|
|
+ CRIT("could not create directory %s: %m\n", dname);
|
|
+ return err;
|
|
+ }
|
|
dfd = open(dname, O_RDONLY);
|
|
if (dfd < 0) {
|
|
err = -errno;
|
|
@@ -2899,6 +2908,7 @@ static int do_depmod(int argc, char *argv[])
|
|
FILE *out = NULL;
|
|
int err = 0, all = 0, maybe_all = 0, n_config_paths = 0;
|
|
_cleanup_free_ char *root = NULL;
|
|
+ _cleanup_free_ char *out_root = NULL;
|
|
_cleanup_free_ const char **config_paths = NULL;
|
|
const char *system_map = NULL;
|
|
const char *module_symvers = NULL;
|
|
@@ -2928,6 +2938,11 @@ static int do_depmod(int argc, char *argv[])
|
|
free(root);
|
|
root = path_make_absolute_cwd(optarg);
|
|
break;
|
|
+ case 'o':
|
|
+ if (out_root)
|
|
+ free(out_root);
|
|
+ out_root = path_make_absolute_cwd(optarg);
|
|
+ break;
|
|
case 'C': {
|
|
size_t bytes = sizeof(char *) * (n_config_paths + 2);
|
|
void *tmp = realloc(config_paths, bytes);
|
|
@@ -3010,7 +3025,11 @@ static int do_depmod(int argc, char *argv[])
|
|
|
|
cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX,
|
|
"%s/lib/modules/%s",
|
|
- root == NULL ? "" : root, cfg.kversion);
|
|
+ root ?: "", cfg.kversion);
|
|
+
|
|
+ cfg.outdirnamelen = snprintf(cfg.outdirname, PATH_MAX,
|
|
+ "%s/lib/modules/%s",
|
|
+ out_root ?: (root ?: ""), cfg.kversion);
|
|
|
|
if (optind == argc)
|
|
all = 1;
|
|
--
|
|
2.41.0
|
|
|