Skip to content

Commit

Permalink
Update open-vm-tools to build with either Fuse 3 or Fuse 2
Browse files Browse the repository at this point in the history
Vendors are requesting that open-vm-tools can be built with either
Fuse 2 or Fuse 3.  While both Fuse 2 and Fuse 3 runtime can be
installed on a Linux system, vendors would prefer to switch from
Fuse 2 to Fuse 3 at the same time for all products to be available
with the base OS.

Updating the configure.ac file to check for the presence of the Fuse 3
or Fuse 2 development packages in the build environment.  Providing
configure options to allow users to control the version of Fuse to be
used.
 --without-fuse       - vmblock-fuse and vmhgfs-fuse will be disabled.
 --with-fuse=fuse3|3  - use Fuse 3.x
 --with-fuse=fuse|2   - use Fuse 2.x
 --with-fuse=auto     - check for Fuse 3 or Fuse 2 availability; disable
                        vmblock-fuse and vmhgfs-fuse if unavailable.
 --with-fuse          - implicit "yes".
 --with-fuse=yes      - check for Fuse 3 or Fuse 2 availability; disable
                        vmblock-fuse and vmhgfs-fuse if unavailable.

Pull request: #544
Fixes issue:  #314

The vmblock-fuse code is also used by WorkStation.  Configure defines
are not available in internal builds.  Reworked preprocessor tests to
use FUSE_MAJOR_VERSION from the fuse headers to determine API to be
used during compilation.
  • Loading branch information
johnwvmw committed Dec 21, 2021
1 parent d0571b2 commit 97917fc
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 56 deletions.
3 changes: 3 additions & 0 deletions open-vm-tools/AUTHORS
Expand Up @@ -76,3 +76,6 @@ Vincent Milum Jr Adding FreeBSD on ARM64 support to open-vm-tools.

Miroslav Rezanina Fix issues using GCC 11 with gtk >= 3.20 and glib >=2.66.3
- https://github.com/vmware/open-vm-tools/pull/505

Marco Trevisan Update open-vm-tools to build with either Fuse 3 or Fuse 2
- https://github.com/vmware/open-vm-tools/pull/544
100 changes: 89 additions & 11 deletions open-vm-tools/configure.ac
Expand Up @@ -540,16 +540,93 @@ fi
#
# Check for fuse.
#
AC_VMW_CHECK_LIB([fuse],
[FUSE],
[fuse],
[],
[],
[fuse.h],
[fuse_main],
[have_fuse=yes],
[have_fuse=no;
AC_MSG_WARN([Fuse is missing, vmblock-fuse/vmhgfs-fuse will be disabled.])])

AC_ARG_WITH([fuse],
[AS_HELP_STRING([--without-fuse],
[compiles without FUSE support (disables vmblock-fuse/vmhgfs-fuse).])],
[with_fuse="$withval"],
[with_fuse=auto])

case "$with_fuse" in
fuse|2)
with_fuse="fuse"
;;
fuse3|3)
with_fuse="fuse3"
;;
auto)
;;
yes)
;;
no)
have_fuse3=no;
have_fuse=no;
;;
*)
AC_MSG_FAILURE([--with-fuse was given with an unsupported paramter $with_fuse])
;;
esac


if test "$with_fuse" = "auto" ||
test "$with_fuse" = "fuse3" ||
test "$with_fuse" = "yes"; then
#
# Check for fuse3.
#
# FUSE_USE_VERSION sets the version of the FUSE API that will be exported.
AC_VMW_CHECK_LIB([fuse3],
[FUSE3],
[fuse3],
[],
[3.10.0],
[fuse3/fuse.h],
[fuse_main],
[have_fuse3=yes;
AC_DEFINE([HAVE_FUSE3], 1, [Define to 1 if using FUSE3.])
AC_DEFINE([FUSE_USE_VERSION], 35, [FUSE API version to use.])],
[have_fuse3=no])

if test "$have_fuse3" = "no"; then
if test "$with_fuse" = "auto" || test "$with_fuse" = "yes"; then
AC_MSG_NOTICE([Fuse3 is missing, trying to use older Fuse library.])
else
AC_MSG_FAILURE([Fuse3 was requested but unavailable on the system.])
fi
fi
fi

if test "$with_fuse" = "fuse" ||
( ( test "$with_fuse" = "auto" || test "$with_fuse" = "yes" ) &&
test "$have_fuse3" = "no" ); then
#
# Check for fuse.
#
# FUSE_USE_VERSION sets the version of the FUSE API that will be exported.
AC_VMW_CHECK_LIB([fuse],
[FUSE],
[fuse],
[],
[],
[fuse.h],
[fuse_main],
[have_fuse=yes;
AC_DEFINE([HAVE_FUSE], 1, [Define to 1 if using FUSE.])
AC_DEFINE([FUSE_USE_VERSION], 29, [FUSE API version to use.])],
[have_fuse=no])

if test "$have_fuse" = "no"; then
if test "$with_fuse" = "auto" || test "$with_fuse" = "yes"; then
AC_MSG_NOTICE([Fuse is missing, vmblock-fuse/vmhgfs-fuse will be disabled.])
else
AC_MSG_FAILURE([Fuse2 was requested but unavailable on the system.])
fi
fi
fi

if test "$with_fuse" = "no"; then
AC_MSG_WARN([Fuse or Fuse3 is suppressed, vmblock-fuse/vmhgfs-fuse will be disabled.])
fi

#
# Check for PAM.
Expand Down Expand Up @@ -1607,7 +1684,8 @@ AM_CONDITIONAL(HAVE_XCOMPOSITE, test "$have_xcomposite" = "yes")
AM_CONDITIONAL(ENABLE_TESTS, test "$have_cunit" = "yes")
AM_CONDITIONAL(WITH_ROOT_PRIVILEGES, test "$with_root_privileges" = "yes")
AM_CONDITIONAL(HAVE_DOXYGEN, test "$have_doxygen" = "yes")
AM_CONDITIONAL(HAVE_FUSE, test "$have_fuse" = "yes")
AM_CONDITIONAL(HAVE_FUSE, test "$have_fuse" = "yes" || test "$have_fuse3" = "yes")
AM_CONDITIONAL(HAVE_FUSE3, test "$have_fuse3" = "yes")
AM_CONDITIONAL(HAVE_GNU_LD, test "$with_gnu_ld" = "yes")
AM_CONDITIONAL(HAVE_GTKMM, test "$have_x" = "yes" -a \( "$with_gtkmm" = "yes" -o "$with_gtkmm3" = "yes" \) )
AM_CONDITIONAL(HAVE_PAM, test "$with_pam" = "yes")
Expand Down
14 changes: 6 additions & 8 deletions open-vm-tools/tests/testVmblock/Makefile.am
Expand Up @@ -15,12 +15,14 @@
### Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
################################################################################

noinst_PROGRAMS =
if HAVE_FUSE
noinst_PROGRAMS = vmware-testvmblock-fuse
noinst_PROGRAMS += vmware-testvmblock-fuse
noinst_PROGRAMS += vmware-testvmblock-manual-fuse
endif
if HAVE_FUSE3
noinst_PROGRAMS += vmware-testvmblock-fuse
noinst_PROGRAMS += vmware-testvmblock-manual-fuse
else
noinst_PROGRAMS = vmware-testvmblock-legacy
noinst_PROGRAMS += vmware-testvmblock-manual-legacy
endif

AM_CFLAGS =
Expand All @@ -30,10 +32,6 @@ AM_CFLAGS += -DVMX86_DEBUG
AM_LDFLAGS =
AM_LDFLAGS += -lpthread

vmware_testvmblock_legacy_SOURCES = vmblocktest.c

vmware_testvmblock_manual_legacy_SOURCES = manual-blocker.c

vmware_testvmblock_fuse_CFLAGS = $(AM_CFLAGS) -Dvmblock_fuse
vmware_testvmblock_fuse_SOURCES = vmblocktest.c

Expand Down
4 changes: 3 additions & 1 deletion open-vm-tools/vmblock-fuse/Makefile.am
@@ -1,5 +1,5 @@
################################################################################
### Copyright (C) 2008-2016 VMware, Inc. All rights reserved.
### Copyright (c) 2008-2016,2021 VMware, Inc. All rights reserved.
###
### This program is free software; you can redistribute it and/or modify
### it under the terms of version 2 of the GNU General Public License as
Expand Down Expand Up @@ -29,12 +29,14 @@ AM_CFLAGS += -D_XOPEN_SOURCE=600
AM_CFLAGS += -DUSERLEVEL
AM_CFLAGS += -D_FILE_OFFSET_BITS=64
AM_CFLAGS += @FUSE_CPPFLAGS@
AM_CFLAGS += @FUSE3_CPPFLAGS@
AM_CFLAGS += @GLIB2_CPPFLAGS@
AM_CFLAGS += -I$(top_srcdir)/modules/shared/vmblock
AM_CFLAGS += -I$(srcdir)

vmware_vmblock_fuse_LDADD =
vmware_vmblock_fuse_LDADD += @FUSE_LIBS@
vmware_vmblock_fuse_LDADD += @FUSE3_LIBS@
vmware_vmblock_fuse_LDADD += @GLIB2_LIBS@

vmware_vmblock_fuse_SOURCES =
Expand Down
50 changes: 44 additions & 6 deletions open-vm-tools/vmblock-fuse/fsops.c
Expand Up @@ -65,6 +65,14 @@ static vmblockSpecialDirEntry symlinkDirEntry =
static vmblockSpecialDirEntry notifyDirEntry =
{ NOTIFY_DIR "/*", S_IFREG | 0444, 1, 0 };
#if FUSE_MAJOR_VERSION == 3
#define CALL_FUSE_FILLER(buf, name, stbuf, off, flags) \
filler(buf, name, stbuf, off, flags)
#else
#define CALL_FUSE_FILLER(buf, name, stbuf, off, flags) \
filler(buf, name, stbuf, off)
#endif
/*
*-----------------------------------------------------------------------------
*
Expand Down Expand Up @@ -248,9 +256,16 @@ SetTimesToNow(struct stat *statBuf) // OUT
*-----------------------------------------------------------------------------
*/

#if FUSE_MAJOR_VERSION == 3
int
VMBlockGetAttr(const char *path, // IN: File to get attributes of.
struct stat *statBuf, // OUT: Where to put the attributes.
struct fuse_file_info *fi) // IN: Ignored
#else
int
VMBlockGetAttr(const char *path, // IN: File to get attributes of.
struct stat *statBuf) // OUT: Where to put the attributes.
#endif
{
vmblockSpecialDirEntry *dirEntry;
ASSERT(path != NULL);
Expand Down Expand Up @@ -362,7 +377,7 @@ ExternalReadDir(const char *blockPath, // IN:
errno = 0;

while ((dentry = readdir(dir)) != NULL) {
status = filler(buf, dentry->d_name, &statBuf, 0);
status = CALL_FUSE_FILLER(buf, dentry->d_name, &statBuf, 0, 0);
if (status == 1) {
break;
}
Expand Down Expand Up @@ -408,6 +423,17 @@ ExternalReadDir(const char *blockPath, // IN:
*-----------------------------------------------------------------------------
*/

#if FUSE_MAJOR_VERSION == 3
int
VMBlockReadDir(const char *path, // IN: Directory to read.
void *buf, // OUT: Where to put directory
// listing.
fuse_fill_dir_t filler, // IN: Function to add an entry
// to buf.
off_t offset, // IN: Ignored.
struct fuse_file_info *fileInfo, // IN: Ignored.
enum fuse_readdir_flags flags) // IN: Ignored.
#else
int
VMBlockReadDir(const char *path, // IN: Directory to read.
void *buf, // OUT: Where to put directory
Expand All @@ -416,6 +442,7 @@ VMBlockReadDir(const char *path, // IN: Directory to read.
// to buf.
off_t offset, // IN: Ignored.
struct fuse_file_info *fileInfo) // IN: Ignored.
#endif
{
struct stat fileStat;
struct stat dirStat;
Expand All @@ -433,11 +460,11 @@ VMBlockReadDir(const char *path, // IN: Directory to read.
dirStat.st_mode = S_IFDIR;

if (strcmp(path, "/") == 0) {
(void)(filler(buf, ".", &dirStat, 0) ||
filler(buf, "..", &dirStat, 0) ||
filler(buf, VMBLOCK_DEVICE_NAME, &fileStat, 0) ||
filler(buf, REDIRECT_DIR_NAME, &dirStat, 0) ||
filler(buf, NOTIFY_DIR_NAME, &dirStat, 0));
(void)(CALL_FUSE_FILLER(buf, ".", &dirStat, 0, 0) ||
CALL_FUSE_FILLER(buf, "..", &dirStat, 0, 0) ||
CALL_FUSE_FILLER(buf, VMBLOCK_DEVICE_NAME, &fileStat, 0, 0) ||
CALL_FUSE_FILLER(buf, REDIRECT_DIR_NAME, &dirStat, 0, 0) ||
CALL_FUSE_FILLER(buf, NOTIFY_DIR_NAME, &dirStat, 0, 0));
return 0;
} else if ( (strcmp(path, REDIRECT_DIR) == 0)
|| (strcmp(path, NOTIFY_DIR) == 0)) {
Expand Down Expand Up @@ -764,8 +791,19 @@ VMBlockRelease(const char *path, // IN: Must be control file.
*-----------------------------------------------------------------------------
*/

#if FUSE_MAJOR_VERSION == 3
void *
VMBlockInit(struct fuse_conn_info *conn,
struct fuse_config *config)
#else
#if FUSE_USE_VERSION < 26
void *
VMBlockInit(void)
#else
void *
VMBlockInit(struct fuse_conn_info *conn)
#endif
#endif
{
BlockInit();
return NULL;
Expand Down
19 changes: 17 additions & 2 deletions open-vm-tools/vmblock-fuse/fsops.h
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 2008-2018 VMware, Inc. All rights reserved.
* Copyright (C) 2008-2018,2021 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
Expand Down Expand Up @@ -30,13 +30,19 @@
#ifndef _VMBLOCK_FUSE_H_
#define _VMBLOCK_FUSE_H_

/*
* FUSE_USE_VERSION must be set before the fuse or fuse3 headers are
* included. If undefined, fall back to previous default used.
*/
#ifndef FUSE_USE_VERSION
/*
* FUSE_USE_VERSION sets the version of the FUSE API that will be exported.
* Version 25 is the newest version supported by the libfuse in our toolchain
* as of 2008-07.
*/

#define FUSE_USE_VERSION 25
#endif

#include <fuse.h>

#include "vmblock.h"
Expand All @@ -55,9 +61,18 @@
*/

int VMBlockReadLink(const char *path, char *buf, size_t bufSize);

#if FUSE_MAJOR_VERSION == 3
int VMBlockGetAttr(const char *path, struct stat *statBuf,
struct fuse_file_info *fi);
int VMBlockReadDir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fileInfo,
enum fuse_readdir_flags);
#else
int VMBlockGetAttr(const char *path, struct stat *statBuf);
int VMBlockReadDir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fileInfo);
#endif
int VMBlockOpen(const char *path, struct fuse_file_info *fileInfo);
int VMBlockWrite(const char *path, const char *buf, size_t size, off_t offset,
struct fuse_file_info *fileInfo);
Expand Down
6 changes: 5 additions & 1 deletion open-vm-tools/vmblock-fuse/main.c
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 2008-2016 VMware, Inc. All rights reserved.
* Copyright (C) 2008-2016,2021 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
Expand Down Expand Up @@ -66,5 +66,9 @@ main(int argc, // IN
LOGLEVEL_THRESHOLD = 4;
}
}
#if FUSE_USE_VERSION < 26
return fuse_main(argc, argv, &vmblockOperations);
#else
return fuse_main(argc, argv, &vmblockOperations, NULL);
#endif
}
4 changes: 3 additions & 1 deletion open-vm-tools/vmhgfs-fuse/Makefile.am
@@ -1,5 +1,5 @@
################################################################################
### Copyright (C) 2015-2016 VMware, Inc. All rights reserved.
### Copyright (c) 2015-2016,2021 VMware, Inc. All rights reserved.
###
### This program is free software; you can redistribute it and/or modify
### it under the terms of version 2 of the GNU General Public License as
Expand All @@ -19,10 +19,12 @@ bin_PROGRAMS = vmhgfs-fuse

AM_CFLAGS =
AM_CFLAGS += @FUSE_CPPFLAGS@
AM_CFLAGS += @FUSE3_CPPFLAGS@
AM_CFLAGS += @GLIB2_CPPFLAGS@

vmhgfs_fuse_LDADD =
vmhgfs_fuse_LDADD += @FUSE_LIBS@
vmhgfs_fuse_LDADD += @FUSE3_LIBS@
vmhgfs_fuse_LDADD += @GLIB2_LIBS@
vmhgfs_fuse_LDADD += @VMTOOLS_LIBS@

Expand Down

0 comments on commit 97917fc

Please sign in to comment.