diff options
author | Lee Duncan <lduncan@suse.com> | 2022-09-21 09:33:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-21 09:33:56 -0700 |
commit | 531039d15c3fe34fcd373d0923e0c7a34786c58c (patch) | |
tree | 0948146a9f7ae95fbcf081550504a8d0d8aa55f5 /utils | |
parent | 7726ecc89015edb49057473a605c63ac9354f5cb (diff) | |
download | open-iscsi-531039d15c3fe34fcd373d0923e0c7a34786c58c.tar.gz |
Use meson as the main build system (#365)
* Build: Add an iscsiuio 'build_date.sh' script
This is currently unused, but will be used by meson to
build the "build_date.[ch]" files used by iscsiuio.
* Build: have git ignore file '.setup'
I commonly use this file for shell aliases/functions.
* Add framework to support building using meson.
This adds the ability to use meson/ninja to build open-iscsi
and iscsiuio, rather than the current system that uses 'autoconf'
for iscsiuio and uses 'make' for everything else.
The old make/autoconf system is left in place, for now, but
deprecated, including a warning about that when running 'make all'
or 'make user' from the top-level.
* utils/build: enhance iscsi-iname to generate prefix
Added new "-g/--generate-iname-prefix" argument to generate the
InitiatorName= prefix. Also, updated iscsi-iname to use getopts.
Also, use the new option from meson.
* git/meson: remove 'builddir' from ignored files
The build directory can be called anything.
Suggested by: Eli Schwartz
* iscsiuio build: fix new build_date.sh script
Fixed several issues:
- fix option handling for "-S"
- fix epoch date handling from env (noticed by Eli Schwartz)
- remove debug statements
* iscsiuio meson: warn when not creating a symlink for iscsiuio
* meson: install man pages more efficiently
We don't need to specify path or subdirectory
* iscsiuio meson: remove unused source date epoch option
This option was never used, since we pass this info
from the environment.
* meson: no need to set libdir: default is fine
* iscsiuio meson: no need to add c_args: already there
* Don't generate initiatorname when cross-building (#367)
Let it be generated by the iscsi-init service.
Signed-off-by: TIAN Yuanhao <tianyuanhao3@163.com>
* Set ISCSI_CONFIG_ROOT by meson
Signed-off-by: TIAN Yuanhao <tianyuanhao3@163.com>
* Set LOCK_DIR from home_dir to lock_dir
Signed-off-by: TIAN Yuanhao <tianyuanhao3@163.com>
* Install iface.example to db_root/ifaces
Signed-off-by: TIAN Yuanhao <tianyuanhao3@163.com>
Signed-off-by: TIAN Yuanhao <tianyuanhao3@163.com>
Co-authored-by: TIAN Yuanhao <78596099+tianyuanhao@users.noreply.github.com>
Co-authored-by: TIAN Yuanhao <tianyuanhao3@163.com>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/iscsi-iname.c | 60 | ||||
-rw-r--r-- | utils/meson.build | 32 |
2 files changed, 73 insertions, 19 deletions
diff --git a/utils/iscsi-iname.c b/utils/iscsi-iname.c index 834352e..c241aaf 100644 --- a/utils/iscsi-iname.c +++ b/utils/iscsi-iname.c @@ -31,18 +31,26 @@ #include <string.h> #include <sys/utsname.h> #include <sys/time.h> +#include <getopt.h> +#include <stdbool.h> #include "md5.h" #define RANDOM_NUM_GENERATOR "/dev/urandom" +#define DEFAULT_PREFIX "iqn.2016-04.com.open-iscsi" + /* iSCSI names have a maximum length of 223 characters, we reserve 13 to append * a seperator and 12 characters (6 random bytes in hex representation) */ #define PREFIX_MAX_LEN 210 static void usage(void) { - fprintf(stderr, "Usage: iscsi-iname [-h | --help | -p <prefix>]\n"); + fprintf(stderr, "Usage: iscsi-iname [OPTIONS]\n"); + fprintf(stderr, "Where OPTIONS are from:\n"); + fprintf(stderr, " -p/--prefix <prefix> -- set IQN prefix [%s]\n", + DEFAULT_PREFIX); + fprintf(stderr, " -g/--generate-iname-prefix -- generate the InitiatorName= prefix\n"); fprintf(stderr, "where <prefix> has max length of %d\n", PREFIX_MAX_LEN); } @@ -59,7 +67,16 @@ main(int argc, char *argv[]) unsigned char entropy[16]; int e; int fd; - char *prefix; + char *prefix = DEFAULT_PREFIX; + int c; + char *short_options = "p:gh"; + struct option const long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"prefix", required_argument, NULL, 'p'}, + {"generate-iname-prefix", no_argument, NULL, 'g'}, + {NULL, 0, NULL, 0} + }; + bool generate_iname_prefix = false; /* initialize */ memset(digest, 0, sizeof (digest)); @@ -67,29 +84,32 @@ main(int argc, char *argv[]) MD5Init(&context); /* take a prefix if given, otherwise use a default. */ - if (argc > 1 && argv[1]) { - prefix = argv[1]; - if (( strcmp(prefix, "-h") == 0 ) || - ( strcmp(prefix, "--help") == 0 )) { - printf("\nGenerates a unique iSCSI node name " - "on every invocation.\n"); - exit(0); - } else if ( strcmp(prefix, "-p") == 0 ) { - if (argc != 3) { - usage(); - exit(1); - } - prefix = argv[2]; + while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) >= 0) { + switch (c) { + case 'p': + prefix = optarg; if (strnlen(prefix, PREFIX_MAX_LEN + 1) > PREFIX_MAX_LEN) { + fprintf(stderr, "error: prefix too long\n"); usage(); exit(1); } - } else { + break; + case 'h': usage(); exit(0); + case 'g': + generate_iname_prefix = true; + break; + default: + case '?': + usage(); + exit(1); } - } else { - prefix = "iqn.2016-04.com.open-iscsi"; + } + if (optind < argc) { + fprintf(stderr, "unknown argument(s)\n"); + usage(); + exit(1); } /* try to feed some entropy from the pool to MD5 in order to get @@ -150,7 +170,9 @@ main(int argc, char *argv[]) } /* print the prefix followed by 6 bytes of the MD5 hash */ - printf("%s:%x%x%x%x%x%x\n", prefix, + printf("%s%s:%x%x%x%x%x%x\n", + generate_iname_prefix ? "InitiatorName=" : "", + prefix, bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]); return 0; } diff --git a/utils/meson.build b/utils/meson.build new file mode 100644 index 0000000..9e74cc0 --- /dev/null +++ b/utils/meson.build @@ -0,0 +1,32 @@ +# meson build file for utils + +# sources for iscsi_iname +iscsi_iname_src_files = [files( + 'iscsi-iname.c', + 'md5.c')] + +# templated shell scripts (NAME.sh.template -> NAME.sh -> NAME) +iscsi_util_sh_template_tgts = [ + 'iscsi_fw_login', + 'iscsi-gen-initiatorname'] +iscsi_util_sh_template_arr = {} +foreach t: iscsi_util_sh_template_tgts + iscsi_util_sh_template_arr += {t: files(t + '.sh.template')} +endforeach + +# regular shell scripts (NAME.sh -> NAME) +iscsi_util_sh_tgts = [ + 'iscsi_discovery', + 'iscsi_offload'] +iscsi_util_sh_arr = {} +foreach t: iscsi_util_sh_tgts + iscsi_util_sh_arr += {t: files(t + '.sh')} +endforeach + +# other templated files (NAME.template -> NAME) +iscsi_util_other_template_tgts = [ + '50-iscsi-firmware-login.rules'] +iscsi_util_other_template_arr = {} +foreach t: iscsi_util_other_template_tgts + iscsi_util_other_template_arr += {t: files(t + '.template')} +endforeach |