From aae599ba27e581c6492f9bcbd7119a4a25ee1a03 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 21 May 2015 21:19:14 -0600 Subject: [PATCH] Add start of mount check For raw block devices, lets add some safety check that will check for destructive tests whether a device is mounted or not. Will plumb this in soon, and add an override option to continue regardless. Signed-off-by: Jens Axboe --- Makefile | 2 +- configure | 22 ++++++++++++++++++++++ lib/mountcheck.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 lib/mountcheck.c diff --git a/Makefile b/Makefile index d9aedf52..b3acbcfe 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ SOURCE := gettime.c ioengines.c init.c stat.c log.c time.c filesetup.c \ lib/lfsr.c gettime-thread.c helpers.c lib/flist_sort.c \ lib/hweight.c lib/getrusage.c idletime.c td_error.c \ profiles/tiobench.c profiles/act.c io_u_queue.c filelock.c \ - lib/tp.c lib/bloom.c lib/gauss.c workqueue.c + lib/tp.c lib/bloom.c lib/gauss.c lib/mountcheck.c workqueue.c ifdef CONFIG_LIBHDFS HDFSFLAGS= -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(FIO_LIBHDFS_INCLUDE) diff --git a/configure b/configure index 3b871efa..5c6129dc 100755 --- a/configure +++ b/configure @@ -1453,6 +1453,25 @@ fi echo "lex/yacc for arithmetic $arith" +########################################## +# Check whether we have setmntent/getmntent +getmntent="no" +cat > $TMPC << EOF +#include +#include +int main(int argc, char **argv) +{ + FILE *mtab = setmntent(NULL, "r"); + struct mntent *mnt = getmntent(mtab); + endmntent(mnt); + return 0; +} +EOF +if compile_prog "" "" "getmntent"; then + getmntent="yes" +fi +echo "getmntent $getmntent" + ############################################################################# if test "$wordsize" = "64" ; then @@ -1626,6 +1645,9 @@ if test "$arith" = "yes" ; then echo "YACC=$YACC" >> $config_host_mak fi fi +if test "$getmntent" = "yes" ; then + output_sym "CONFIG_GETMNTENT" +fi if test "$zlib" = "no" ; then echo "Consider installing zlib-dev (zlib-devel), some fio features depend on it." diff --git a/lib/mountcheck.c b/lib/mountcheck.c new file mode 100644 index 00000000..dea27462 --- /dev/null +++ b/lib/mountcheck.c @@ -0,0 +1,39 @@ +#include +#include +#include + +#ifdef CONFIG_GETMNTENT + +#define MTAB "/etc/mtab" + +int device_is_mounted(const char *dev) +{ + FILE *mtab; + struct mntent *mnt; + int ret = 0; + + mtab = setmntent(MTAB, "r"); + if (!mtab) + return 0; + + while ((mnt = getmntent(mtab)) != NULL) { + if (!mnt->mnt_fsname) + continue; + if (!strcmp(mnt->mnt_fsname, dev)) { + ret = 1; + break; + } + } + + endmntent(mtab); + return ret; +} + +#else + +int device_is_mounted(const char *dev) +{ + return 0; +} + +#endif -- 2.25.1