Browse Source

Further tweaks to config parsing and error reporting (#1559)

* Further tweaks to config parsing and error reporting

* Fix static builds
pull/1561/head
trapexit 6 days ago
committed by GitHub
parent
commit
2412ae7316
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      Makefile
  2. 2
      buildtools/build-release
  3. 10
      buildtools/containerfiles/static.amd64
  4. 10
      buildtools/containerfiles/static.arm64
  5. 10
      buildtools/containerfiles/static.armhf
  6. 10
      buildtools/containerfiles/static.i386
  7. 10
      buildtools/containerfiles/static.riscv64
  8. 11
      libfuse/Makefile
  9. 2
      libfuse/lib/fuse_lowlevel.cpp
  10. 16
      src/config.cpp
  11. 2
      src/mergerfs.cpp
  12. 28
      src/option_parser.cpp

4
Makefile

@ -12,6 +12,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
$(info mergerfs MAKEFLAGS: $(MAKEFLAGS))
ifeq ($(shell id -u),0)
FAKEROOT ?=
endif
@ -188,7 +190,7 @@ $(BUILDDIR)/tests: $(BUILDDIR)/mergerfs $(TESTS_OBJS)
.PHONY: libfuse
$(LIBFUSE):
libfuse:
$(MAKE) NDEBUG=$(NDEBUG) -C libfuse
$(MAKE) -C libfuse
tests: $(BUILDDIR)/tests

2
buildtools/build-release

@ -19,7 +19,7 @@ def build(git_repo,
if os.path.exists(git_repo):
git_repo = os.path.realpath(git_repo)
args += ['-v',f'{git_repo}:/tmp/mergerfs.git:ro']
args += ['--build-arg=GIT_REPO=/tmp/mergerfs.git']
args += ['--build-arg=GIT_REPO=file:///tmp/mergerfs.git']
else:
args += [f'--build-arg=GIT_REPO={git_repo}']
args += ['-o',pkgdirpath,

10
buildtools/containerfiles/static.amd64

@ -1,13 +1,15 @@
ARG BUILD_TIMESTAMP=0
FROM --platform=linux/amd64 alpine:latest as build
COPY install-build-pkgs /tmp/
RUN /tmp/install-build-pkgs
ARG BRANCH=master
RUN git clone --single-branch --depth=1 https://github.com/trapexit/mergerfs /tmp/mergerfs --branch="${BRANCH}"
ARG BUILD_TIMESTAMP=0
ARG GIT_REPO
ARG BRANCH
RUN git clone --single-branch --branch="${BRANCH}" ${GIT_REPO} /tmp/mergerfs
WORKDIR /tmp/mergerfs
RUN make NDEBUG=1 LTO=1 STATIC=1 DESTDIR=/tmp -j$(nproc) install
RUN mkdir /build
RUN tar cvfz /build/mergerfs-static-linux_amd64.tar.gz --directory=/tmp usr sbin
RUN /tmp/usr/local/bin/mergerfs --version | head -n1 | cut -c 11- | tee /tmp/version
RUN tar cvfz /build/mergerfs-$(cat /tmp/version)-static-linux_amd64.tar.gz --directory=/tmp usr sbin
FROM scratch
COPY --from=build /build/ /

10
buildtools/containerfiles/static.arm64

@ -1,13 +1,15 @@
ARG BUILD_TIMESTAMP=0
FROM --platform=linux/arm64 alpine:latest as build
COPY install-build-pkgs /tmp/
RUN /tmp/install-build-pkgs
ARG BRANCH=master
RUN git clone --single-branch --depth=1 https://github.com/trapexit/mergerfs /tmp/mergerfs --branch="${BRANCH}"
ARG BUILD_TIMESTAMP=0
ARG GIT_REPO
ARG BRANCH
RUN git clone --single-branch --branch="${BRANCH}" ${GIT_REPO} /tmp/mergerfs
WORKDIR /tmp/mergerfs
RUN make NDEBUG=1 LTO=1 STATIC=1 DESTDIR=/tmp -j$(nproc) install
RUN mkdir /build
RUN tar cvfz /build/mergerfs-static-linux_arm64.tar.gz --directory=/tmp usr sbin
RUN /tmp/usr/local/bin/mergerfs --version | head -n1 | cut -c 11- | tee /tmp/version
RUN tar cvfz /build/mergerfs-$(cat /tmp/version)-static-linux_arm64.tar.gz --directory=/tmp usr sbin
FROM scratch
COPY --from=build /build/ /

10
buildtools/containerfiles/static.armhf

@ -1,13 +1,15 @@
ARG BUILD_TIMESTAMP=0
FROM --platform=linux/armhf alpine:latest as build
COPY install-build-pkgs /tmp/
RUN /tmp/install-build-pkgs
ARG BRANCH=master
RUN git clone --single-branch --depth=1 https://github.com/trapexit/mergerfs /tmp/mergerfs --branch="${BRANCH}"
ARG BUILD_TIMESTAMP=0
ARG GIT_REPO
ARG BRANCH
RUN git clone --single-branch --branch="${BRANCH}" ${GIT_REPO} /tmp/mergerfs
WORKDIR /tmp/mergerfs
RUN make NDEBUG=1 LTO=1 STATIC=1 DESTDIR=/tmp -j$(nproc) install
RUN mkdir /build
RUN tar cvfz /build/mergerfs-static-linux_armhf.tar.gz --directory=/tmp usr sbin
RUN /tmp/usr/local/bin/mergerfs --version | head -n1 | cut -c 11- | tee /tmp/version
RUN tar cvfz /build/mergerfs-$(cat /tmp/version)-static-linux_armhf.tar.gz --directory=/tmp usr sbin
FROM scratch
COPY --from=build /build/ /

10
buildtools/containerfiles/static.i386

@ -1,13 +1,15 @@
ARG BUILD_TIMESTAMP=0
FROM --platform=linux/i386 alpine:latest as build
COPY install-build-pkgs /tmp/
RUN /tmp/install-build-pkgs
ARG BRANCH=master
RUN git clone --single-branch --depth=1 https://github.com/trapexit/mergerfs /tmp/mergerfs --branch="${BRANCH}"
ARG BUILD_TIMESTAMP=0
ARG GIT_REPO
ARG BRANCH
RUN git clone --single-branch --branch="${BRANCH}" ${GIT_REPO} /tmp/mergerfs
WORKDIR /tmp/mergerfs
RUN make NDEBUG=1 LTO=1 STATIC=1 DESTDIR=/tmp -j$(nproc) install
RUN mkdir /build
RUN tar cvfz /build/mergerfs-static-linux_i386.tar.gz --directory=/tmp usr sbin
RUN /tmp/usr/local/bin/mergerfs --version | head -n1 | cut -c 11- | tee /tmp/version
RUN tar cvfz /build/mergerfs-$(cat /tmp/version)-static-linux_i386.tar.gz --directory=/tmp usr sbin
FROM scratch
COPY --from=build /build/ /

10
buildtools/containerfiles/static.riscv64

@ -1,13 +1,15 @@
ARG BUILD_TIMESTAMP=0
FROM --platform=linux/riscv64 alpine:latest as build
COPY install-build-pkgs /tmp/
RUN /tmp/install-build-pkgs
ARG BRANCH=master
RUN git clone --single-branch --depth=1 https://github.com/trapexit/mergerfs /tmp/mergerfs --branch="${BRANCH}"
ARG BUILD_TIMESTAMP=0
ARG GIT_REPO
ARG BRANCH
RUN git clone --single-branch --branch="${BRANCH}" ${GIT_REPO} /tmp/mergerfs
WORKDIR /tmp/mergerfs
RUN make NDEBUG=1 LTO=1 STATIC=1 DESTDIR=/tmp -j$(nproc) install
RUN mkdir /build
RUN tar cvfz /build/mergerfs-static-linux_riscv64.tar.gz --directory=/tmp usr sbin
RUN /tmp/usr/local/bin/mergerfs --version | head -n1 | cut -c 11- | tee /tmp/version
RUN tar cvfz /build/mergerfs-$(cat /tmp/version)-static-linux_riscv64.tar.gz --directory=/tmp usr sbin
FROM scratch
COPY --from=build /build/ /

11
libfuse/Makefile

@ -12,6 +12,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
$(info libfuse MAKEFLAGS: $(MAKEFLAGS))
AR ?= ar
CHMOD ?= chmod
CHOWN ?= chown
@ -88,10 +90,17 @@ OBJS += $(SRC_CXX:lib/%.cpp=$(BUILDDIR)/.objs/%.cpp.o)
DEPS := $(SRC_C:lib/%.c=$(BUILDDIR)/.objs/%.c.d)
DEPS += $(SRC_CXX:lib/%.cpp=$(BUILDDIR)/.objs/%.cpp.d)
ifdef STATIC
STATIC_FLAGS := -static
else
STATIC_FLAGS :=
endif
CPPFLAGS ?=
CFLAGS ?= \
$(OPT_FLAGS) \
$(LTO_FLAGS) \
$(STATIC_FLAGS) \
-Wall \
-pipe
override CFLAGS += \
@ -101,6 +110,7 @@ override CFLAGS += \
CXXFLAGS ?= \
$(OPT_FLAGS) \
$(LTO_FLAGS) \
$(STATIC_FLAGS) \
-Wall \
-pipe
override CXXFLAGS += \
@ -138,6 +148,7 @@ $(BUILDDIR)/mergerfs-fusermount: util/fusermount.c lib/mount_util.c
mergerfs-fusermount: $(BUILDDIR)/mergerfs-fusermount
$(BUILDDIR)/mount.mergerfs: $(BUILDDIR)/libfuse.a util/mount.mergerfs.c
echo STATIC=$(STATIC) $(STATIC_FLAGS)
$(CC) $(CFLAGS) $(FUSE_FLAGS) -o $(BUILDDIR)/mount.mergerfs util/mount.mergerfs.c $(BUILDDIR)/libfuse.a $(LDFLAGS)
mount.mergerfs: $(BUILDDIR)/mount.mergerfs

2
libfuse/lib/fuse_lowlevel.cpp

@ -1863,7 +1863,7 @@ fuse_ll_opt_proc(void *data_,
int key_,
struct fuse_args *outargs_)
{
fmt::print(stderr, "* ERROR: unknown option '{}'\n", arg_);
fmt::print(stderr, "fuse: ERROR - unknown option - '{}'\n", arg_);
return -1;
}

16
src/config.cpp

@ -173,6 +173,7 @@ Config::Config()
nullrw.ro =
pid.ro =
pin_threads.ro =
posix_acl.ro =
process_thread_count.ro =
process_thread_queue_depth.ro =
read_thread_count.ro =
@ -180,9 +181,9 @@ Config::Config()
srcmounts.ro =
version.ro =
true;
congestion_threshold.ro =
congestion_threshold.display =
gid.display =
max_background.ro =
max_background.display =
threads.display =
_mount.display =
uid.display =
@ -389,6 +390,7 @@ Config::get(const std::string &key_,
key = str::replace(key_,'_','-');
i = _map.find(key);
if(i == _map.end())
return -ENOATTR;
@ -434,8 +436,6 @@ Config::from_stream(std::istream &istrm_)
{
int rv;
std::string line;
std::string key;
std::string val;
Config::ErrVec new_errs;
while(std::getline(istrm_,line,'\n'))
@ -444,13 +444,9 @@ Config::from_stream(std::istream &istrm_)
if(line.empty() || (line[0] == '#'))
continue;
str::splitkv(line,'=',&key,&val);
key = str::trim(key);
val = str::trim(val);
rv = set(key,val);
rv = set(line);
if(rv < 0)
new_errs.push_back({-rv,key+'='+val});
new_errs.push_back({-rv,line});
}
rv = (new_errs.empty() ? 0 : -EINVAL);

2
src/mergerfs.cpp

@ -324,7 +324,7 @@ _main(int argc_,
std::string s = err.to_string();
SysLog::error("error: {}",s);
fmt::println(stderr,"* ERROR: {}",s);
fmt::println(stderr,"mergerfs: ERROR - {}",s);
}
return 1;

28
src/option_parser.cpp

@ -121,37 +121,19 @@ _set_default_options(fuse_args *args_)
static
int
_parse_and_process_kv_arg(const std::string &key_,
const std::string &val_)
_process_opt(const std::string &arg_)
{
int rv;
std::string key(key_);
std::string val(val_);
if(cfg.has_key(key) == false)
return 1;
rv = cfg.set(key,val);
rv = cfg.set(arg_);
if(rv == -ENOATTR)
return OPT_KEEP;
if(rv < 0)
cfg.errs.push_back({-rv,key+'='+val});
cfg.errs.push_back({-rv,arg_});
return OPT_DISCARD;
}
static
int
_process_opt(const std::string &arg_)
{
std::string key;
std::string val;
str::splitkv(arg_,'=',&key,&val);
key = str::trim(key);
val = str::trim(val);
return ::_parse_and_process_kv_arg(key,val);
}
static
void
_usage(void)

Loading…
Cancel
Save