From fe0e096567ba148d5690316d2bad2226c0cf70bf Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 29 Aug 2019 01:46:24 -0600 Subject: [PATCH] LU-9897 utils: remove dependency on libblkid There was a weak dependency in llverdev on libblkid in order to find the size of the underlying block device. However, in the absence of libblkid there is fallback code that can find the block device size, so we don't really need libblkid at all. Similarly, llverdev had a weak dependency on libext2fs to check if the block device was currently in use, but all kernels since v2.6.34-rc4-22-g6b4517a7913a allow using open(O_EXCL) to ensure a block device is not mounted, so there is no need for llverdev to depend on libext2fs for this. Remove the conditional code depending on the external libraries from llverdev and the corresponding configuration checks, which were causing problems in various build environments. Test-Parameters: trivial testlist=conf-sanity Fixes: 6bc323747706 ("LU-9897 build: use pkgconf for detecting libblkid") Signed-off-by: Andreas Dilger Change-Id: I90d2f0c99115ce07168c185dec6628be813ebbe5 Reviewed-on: https://review.whamcloud.com/36010 Reviewed-by: Patrick Farrell Tested-by: jenkins Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Sebastien Buisson Reviewed-by: Oleg Drokin --- lustre/autoconf/lustre-core.m4 | 8 ------- lustre/utils/Makefile.am | 1 - lustre/utils/llverdev.c | 48 +++++++----------------------------------- 3 files changed, 8 insertions(+), 49 deletions(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 89e2141..68c61f3 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -3199,11 +3199,6 @@ LC_MDS_MAX_THREADS AC_CHECK_HEADERS([netdb.h endian.h]) AC_CHECK_FUNCS([gethostbyname]) -# lustre/utils/llverdev.c -AS_IF([test "x$enable_dist" = xno], [ - PKG_CHECK_MODULES(blkid, [blkid]) -]) - # lustre/utils/llverfs.c AC_CHECK_HEADERS([ext2fs/ext2fs.h]) @@ -3219,9 +3214,6 @@ AS_IF([test "$enable_dist" = "no"], [ ]) SELINUX="" -AS_IF([test "x$enable_dist" = xno], [ - PKG_CHECK_MODULES(blkid, [blkid]) -]) AC_CHECK_LIB([selinux], [is_selinux_enabled], [AC_CHECK_HEADERS([selinux/selinux.h], diff --git a/lustre/utils/Makefile.am b/lustre/utils/Makefile.am index 44ae523..11e2392 100644 --- a/lustre/utils/Makefile.am +++ b/lustre/utils/Makefile.am @@ -90,7 +90,6 @@ EXT2FSLIB = endif llverfs_LDADD := $(EXT2FSLIB) $(E2PLIB) -llverdev_LDADD := $(EXT2FSLIB) $(blkid_LIBS) liblustreapi_la_SOURCES = liblustreapi.c liblustreapi_hsm.c \ liblustreapi_nodemap.c lustreapi_internal.h \ diff --git a/lustre/utils/llverdev.c b/lustre/utils/llverdev.c index e05f41b..54e3499 100644 --- a/lustre/utils/llverdev.c +++ b/lustre/utils/llverdev.c @@ -84,10 +84,6 @@ #include #include -#ifdef HAVE_EXT2FS_EXT2FS_H -# include -#endif - #define ONE_MB (1024 * 1024) #define ONE_GB (1024 * 1024 * 1024) #define HALF_MB (ONE_MB / 2) @@ -157,23 +153,8 @@ void usage(int status) */ static int open_dev(const char *devname, int mode) { - int fd; -#ifdef HAVE_EXT2FS_EXT2FS_H - int mount_flags; - char mountpt[80] = ""; - - if (ext2fs_check_mount_point(devname, &mount_flags, mountpt, - sizeof(mountpt))) { - fprintf(stderr, "%s: ext2fs_check_mount_point failed:%s", - progname, strerror(errno)); - exit(1); - } - if (mount_flags & EXT2_MF_MOUNTED){ - fprintf(stderr, "%s: %s is already mounted\n", progname, - devname); - exit(1); - } -#endif + int fd; + fd = open(devname, mode | O_EXCL | O_LARGEFILE); if (fd < 0) { fprintf(stderr, "%s: Open failed: %s",progname,strerror(errno)); @@ -182,25 +163,13 @@ static int open_dev(const char *devname, int mode) return fd; } -#ifdef HAVE_BLKID_BLKID_H -#include -#endif /* * sizeof_dev: Returns size of device in bytes */ -static loff_t sizeof_dev(int fd) +static size_t sizeof_dev(int fd) { - loff_t numbytes; + size_t numbytes; -#ifdef HAVE_BLKID_BLKID_H - numbytes = blkid_get_dev_size(fd); - if (numbytes <= 0) { - fprintf(stderr, "%s: blkid_get_dev_size(%s) failed", - progname, devname); - return 1; - } - goto out; -#else # if defined BLKGETSIZE64 /* in sys/mount.h */ if (ioctl(fd, BLKGETSIZE64, &numbytes) >= 0) goto out; @@ -226,7 +195,6 @@ static loff_t sizeof_dev(int fd) fprintf(stderr, "%s: unable to determine size of %s\n", progname, devname); return 0; -#endif out: if (verbose) @@ -583,10 +551,10 @@ int main(int argc, char **argv) if (!force && writeoption) { printf("%s: permanently overwrite all data on %s (yes/no)? ", progname, devname); - if (scanf("%3s", yesno) == EOF && ferror(stdin)) { - perror("reading from stdin"); - return -1; - } + if (scanf("%3s", yesno) == EOF && ferror(stdin)) { + perror("reading from stdin"); + return -1; + } if (!(strcasecmp("yes", yesno) || strcasecmp("y", yesno))) { printf("Not continuing due to '%s' response", yesno); return 0; -- 1.8.3.1