From 089c3a75fde95ff643f2e0b40a4e14da0debd05a Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Fri, 1 Sep 2023 16:28:15 +0000 Subject: [PATCH] LU-17079 utils: improve mkfs.lustre error messages, do cleanup Several error message have been changed to output the real error. This should make it much easier to debug certain types of issues. Many conditional compilation macros have been cleaned up. Since this utilies have loadable plugings, we can't know at compile time which backend storage types are going to be supported. Plus, these macros add complexity to the code. Test-Parameters: trivial Test-Parameters: trivial fstype=zfs Signed-off-by: Timothy Day Change-Id: Ifcd20cc9fa389a6440b453f6236c41b3a80d92d3 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52223 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/utils/libmount_utils_zfs.c | 4 +- lustre/utils/mkfs_lustre.c | 83 +++++++++++++++------------------------ lustre/utils/mount_utils.c | 43 ++++++++++++-------- lustre/utils/mount_utils.h | 9 +++++ 4 files changed, 69 insertions(+), 70 deletions(-) diff --git a/lustre/utils/libmount_utils_zfs.c b/lustre/utils/libmount_utils_zfs.c index 4852b1c..e9383cb 100644 --- a/lustre/utils/libmount_utils_zfs.c +++ b/lustre/utils/libmount_utils_zfs.c @@ -985,7 +985,9 @@ int zfs_init(void) if (ret == 0) osd_zfs_setup = 1; else - fprintf(stderr, "Failed to initialize ZFS library: %d\n", ret); + fprintf(stderr, + "Failed to initialize ZFS library. Are the ZFS packages and modules correctly installed? (%d)\n", + ret); return ret; } diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index db5be76..51d09cc 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -72,58 +72,39 @@ int verbose = 1; int version; static int print_only; -#ifdef HAVE_LDISKFS_OSD -#define FSLIST_LDISKFS "ldiskfs" -#define HAVE_FSLIST -#else - #define FSLIST_LDISKFS "" -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - #ifdef HAVE_FSLIST - #define FSLIST_ZFS "|zfs" - #else - #define FSLIST_ZFS "zfs" - #define HAVE_FSLIST - #endif -#else - #define FSLIST_ZFS "" -#endif /* HAVE_ZFS_OSD */ - -#ifndef HAVE_FSLIST - #error "no backing OSD types (ldiskfs or ZFS) are configured" -#endif - -#define FSLIST FSLIST_LDISKFS FSLIST_ZFS - static void usage(FILE *out) { - fprintf(out, "usage: %s [--backfstype="FSLIST"] " - "--fsname=\n" - "\t--index= [options] \n", progname); -#ifdef HAVE_ZFS_OSD - fprintf(out, "usage: %s --backfstype=zfs " - "--fsname= [options]\n" - "\t/\n" - "\t[[] [ ...] [vdev type>] ...]\n", - progname); -#endif + if (backfs_mount_type_loaded(LDD_MT_LDISKFS)) { + fprintf(out, "usage: %s --backfstype=ldiskfs " + "--fsname=\n" + "\t--index= [options] \n\n", + progname); + } + + if (backfs_mount_type_loaded(LDD_MT_ZFS)) { + fprintf(out, "usage: %s --backfstype=zfs " + "--fsname= [options]\n" + "\t/\n" + "\t[[] [ ...] [vdev type>] ...]\n", + progname); + fprintf(out, + "\t:block device or file (e.g /dev/sda or /tmp/ost1)\n" + "\t: name of ZFS pool where target is created " + "(e.g. tank)\n" + "\t: name of new dataset, must be unique within " + "pool (e.g. ost1)\n" + "\t: type of vdev (mirror, raidz, raidz2, spare, " + "cache, log)\n"); + } + fprintf(out, - "\t:block device or file (e.g /dev/sda or /tmp/ost1)\n" -#ifdef HAVE_ZFS_OSD - "\t: name of ZFS pool where target is created " - "(e.g. tank)\n" - "\t: name of new dataset, must be unique within " - "pool (e.g. ost1)\n" - "\t: type of vdev (mirror, raidz, raidz2, spare, " - "cache, log)\n" -#endif "\n" "\ttarget types:\n" "\t\t--mgs: configuration management service\n" "\t\t--nomgs: turn off MGS service on this MDT\n" #ifndef TUNEFS "\t\t--mdt: metadata storage, mutually exclusive with ost\n" - "\t\t--ost: object storage, mutually exclusive with mdt, mgs\n" + "\t\t--ost: object storage, mutually exclusive with mdt, mgs\n\n" #endif "\toptions (in order of popularity):\n" "\t\t--index=#N: numerical target index (0..N)\n" @@ -171,8 +152,6 @@ static void usage(FILE *out) (int)sizeof(((struct lustre_disk_data *)0)->ldd_userdata)); } -/* ==================== Lustre config functions =============*/ - static void print_ldd(char *str, struct mkfs_opts *mop) { struct lustre_disk_data *ldd = &mop->mo_ldd; @@ -839,6 +818,13 @@ int main(int argc, char *const argv[]) else progname = argv[0]; + ret = osd_init(); + if (ret != 0) { + fprintf(stderr, "%s: no OSD plugins found: %d (%s)\n", + progname, ret, strerror(ret)); + return ret; + } + if (chk_args(argc, argv)) { usage(stderr); return EINVAL; @@ -850,13 +836,6 @@ int main(int argc, char *const argv[]) /* device is last arg */ strscpy(mop.mo_device, argv[argc - 1], sizeof(mop.mo_device)); - ret = osd_init(); - if (ret != 0) { - fprintf(stderr, "%s: osd_init() failed: %d (%s)\n", - progname, ret, strerror(ret)); - return ret; - } - #ifdef TUNEFS /* * For tunefs, we must read in the old values before parsing any diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index 99652b6..8d59e29 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -503,12 +503,14 @@ int loop_format(struct mkfs_opts *mop) #endif /* PLUGIN_DIR */ /** - * Load plugin for a given mount_type from ${pkglibdir}/mount_osd_FSTYPE.so and - * return struct of function pointers (will be freed in unloack_backfs_module). + * load_backfs_module() - Load plugin for a given mount_type + * @mount_type: mount type to load module for * - * \param[in] mount_type Mount type to load module for. - * \retval Value of backfs_ops struct - * \retval NULL if no module exists + * Load plugin from ${pkglibdir}/mount_osd_FSTYPE.so and + * return struct of function pointers (will be freed in + * unloack_backfs_module). + * + * Return: Value of backfs_ops struct, NULL if no module exists */ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type) { @@ -528,7 +530,6 @@ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type) fsname[sizeof("osd-") - 2] = '_'; snprintf(filename, sizeof(filename), PLUGIN_DIR"/mount_%s.so", fsname); - handle = dlopen(filename, RTLD_LAZY); /* @@ -543,6 +544,7 @@ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type) snprintf(filename, sizeof(filename), "%s/utils/mount_%s.so", dirname, fsname); + handle = dlopen(filename, RTLD_LAZY); } } @@ -620,21 +622,28 @@ static void unload_backfs_module(struct module_backfs_ops *ops) #endif } +bool backfs_mount_type_loaded(enum ldd_mount_type mt) +{ + if (mt >= LDD_MT_LAST || mt < 0) + return false; + + if (!backfs_ops[mt]) + return false; + + return true; +} + /* Return true if backfs_ops has operations for the given mount_type. */ -static int backfs_mount_type_okay(enum ldd_mount_type mount_type) +static bool backfs_mount_type_okay(enum ldd_mount_type mt) { - if (mount_type >= LDD_MT_LAST || mount_type < 0) { - fatal(); - fprintf(stderr, "fs type out of range %d\n", mount_type); - return 0; - } - if (!backfs_ops[mount_type]) { + if (!backfs_mount_type_loaded(mt)) { fatal(); - fprintf(stderr, "unhandled/unloaded fs type %d '%s'\n", - mount_type, mt_str(mount_type)); - return 0; + fprintf(stderr, "unhandled/unloaded OSD plugin %d '%s'\n", + mt, mt_str(mt) ? mt_str(mt) : "INVALID"); + return false; } - return 1; + + return true; } /* Write the server config files */ diff --git a/lustre/utils/mount_utils.h b/lustre/utils/mount_utils.h index 2661f18..2ebf615 100644 --- a/lustre/utils/mount_utils.h +++ b/lustre/utils/mount_utils.h @@ -129,6 +129,9 @@ int get_mountdata(char *, struct lustre_disk_data *); static inline const char *mt_str(enum ldd_mount_type mt) { + if (mt >= LDD_MT_LAST || mt < 0) + return NULL; + static const char * const mount_type_string[] = { "ext3", "ldiskfs", @@ -137,11 +140,15 @@ static inline const char *mt_str(enum ldd_mount_type mt) "ldiskfs2", "zfs", }; + return mount_type_string[mt]; } static inline const char *mt_type(enum ldd_mount_type mt) { + if (mt >= LDD_MT_LAST || mt < 0) + return NULL; + static const char * const mount_type_string[] = { "osd-ldiskfs", "osd-ldiskfs", @@ -150,6 +157,7 @@ static inline const char *mt_type(enum ldd_mount_type mt) "osd-ldiskfs", "osd-zfs", }; + return mount_type_string[mt]; } #endif /* HAVE_SERVER_SUPPORT */ @@ -236,6 +244,7 @@ extern struct module_backfs_ops ldiskfs_ops; struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type); void unload_backfs_ops(struct module_backfs_ops *ops); +bool backfs_mount_type_loaded(enum ldd_mount_type mt); #endif #ifdef HAVE_OPENSSL_SSK -- 1.8.3.1