cmd/sharefs: move translate_pathname body to macro wrapper
All checks were successful
Test / Create distribution (push) Successful in 45s
Test / Sandbox (push) Successful in 2m26s
Test / Hakurei (push) Successful in 3m29s
Test / ShareFS (push) Successful in 3m26s
Test / Hpkg (push) Successful in 4m20s
Test / Sandbox (race detector) (push) Successful in 4m50s
Test / Hakurei (race detector) (push) Successful in 5m39s
Test / Flake checks (push) Successful in 1m45s
All checks were successful
Test / Create distribution (push) Successful in 45s
Test / Sandbox (push) Successful in 2m26s
Test / Hakurei (push) Successful in 3m29s
Test / ShareFS (push) Successful in 3m26s
Test / Hpkg (push) Successful in 4m20s
Test / Sandbox (race detector) (push) Successful in 4m50s
Test / Hakurei (race detector) (push) Successful in 5m39s
Test / Flake checks (push) Successful in 1m45s
This is never called directly anywhere and it is simple enough to be included in the macro. This avoids passing the pointer around and dereferencing errno location, resulting in over 5% increase in throughput on the clang build. No change in the gcc build though. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -10,31 +10,17 @@
|
|||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
|
||||||
#include "fuse-helper.h"
|
#include "fuse-helper.h"
|
||||||
#define SHAREFS_MEDIA_RW_ID (1 << 10) - 1 /* owning gid presented to userspace */
|
|
||||||
#define SHAREFS_PERM_DIR 0700 /* permission bits for directories presented to userspace */
|
|
||||||
#define SHAREFS_PERM_REG 0600 /* permission bits for regular files presented to userspace */
|
|
||||||
#define SHAREFS_FORBIDDEN_FLAGS O_DIRECT /* these open flags are cleared unconditionally */
|
|
||||||
|
|
||||||
/* translate_pathname translates a userspace pathname to a relative pathname;
|
|
||||||
* the returned address is a constant string or part of pathname, it is never heap allocated. */
|
|
||||||
static inline const char *translate_pathname(const char *pathname) {
|
|
||||||
if (pathname == NULL) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (*pathname == '/')
|
|
||||||
pathname++;
|
|
||||||
if (*pathname == '\0')
|
|
||||||
pathname = ".";
|
|
||||||
return pathname;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* MUST_TRANSLATE_PATHNAME translates a userspace pathname to a relative pathname;
|
||||||
|
* the resulting address points to a constant string or part of pathname, it is never heap allocated. */
|
||||||
#define MUST_TRANSLATE_PATHNAME(pathname) \
|
#define MUST_TRANSLATE_PATHNAME(pathname) \
|
||||||
do { \
|
do { \
|
||||||
pathname = translate_pathname(pathname); \
|
|
||||||
if (pathname == NULL) \
|
if (pathname == NULL) \
|
||||||
return -errno; \
|
return -EINVAL; \
|
||||||
|
while (*pathname == '/') \
|
||||||
|
pathname++; \
|
||||||
|
if (*pathname == '\0') \
|
||||||
|
pathname = "."; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* GET_CONTEXT_PRIV obtains fuse context and private data for the calling thread. */
|
/* GET_CONTEXT_PRIV obtains fuse context and private data for the calling thread. */
|
||||||
@@ -170,8 +156,6 @@ int sharefs_rmdir(const char *pathname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int sharefs_rename(const char *oldpath, const char *newpath, unsigned int flags) {
|
int sharefs_rename(const char *oldpath, const char *newpath, unsigned int flags) {
|
||||||
int res;
|
|
||||||
|
|
||||||
struct fuse_context *ctx;
|
struct fuse_context *ctx;
|
||||||
struct sharefs_private *priv;
|
struct sharefs_private *priv;
|
||||||
GET_CONTEXT_PRIV(ctx, priv);
|
GET_CONTEXT_PRIV(ctx, priv);
|
||||||
@@ -204,8 +188,6 @@ int sharefs_truncate(const char *pathname, off_t length, struct fuse_file_info *
|
|||||||
}
|
}
|
||||||
|
|
||||||
int sharefs_utimens(const char *pathname, const struct timespec times[2], struct fuse_file_info *fi) {
|
int sharefs_utimens(const char *pathname, const struct timespec times[2], struct fuse_file_info *fi) {
|
||||||
int res;
|
|
||||||
|
|
||||||
struct fuse_context *ctx;
|
struct fuse_context *ctx;
|
||||||
struct sharefs_private *priv;
|
struct sharefs_private *priv;
|
||||||
GET_CONTEXT_PRIV(ctx, priv);
|
GET_CONTEXT_PRIV(ctx, priv);
|
||||||
@@ -227,7 +209,6 @@ int sharefs_create(const char *pathname, mode_t mode, struct fuse_file_info *fi)
|
|||||||
MUST_TRANSLATE_PATHNAME(pathname);
|
MUST_TRANSLATE_PATHNAME(pathname);
|
||||||
|
|
||||||
(void)mode;
|
(void)mode;
|
||||||
(void)fi;
|
|
||||||
|
|
||||||
if ((fd = openat(priv->dirfd, pathname, fi->flags & ~SHAREFS_FORBIDDEN_FLAGS, SHAREFS_PERM_REG)) == -1)
|
if ((fd = openat(priv->dirfd, pathname, fi->flags & ~SHAREFS_FORBIDDEN_FLAGS, SHAREFS_PERM_REG)) == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
@@ -293,8 +274,6 @@ int sharefs_release(const char *pathname, struct fuse_file_info *fi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int sharefs_fsync(const char *pathname, int datasync, struct fuse_file_info *fi) {
|
int sharefs_fsync(const char *pathname, int datasync, struct fuse_file_info *fi) {
|
||||||
int res;
|
|
||||||
|
|
||||||
(void)pathname;
|
(void)pathname;
|
||||||
|
|
||||||
if (datasync ? fdatasync(fi->fh) : fsync(fi->fh) == -1)
|
if (datasync ? fdatasync(fi->fh) : fsync(fi->fh) == -1)
|
||||||
|
|||||||
@@ -6,6 +6,11 @@
|
|||||||
#error This package requires libfuse >= v3.4
|
#error This package requires libfuse >= v3.4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SHAREFS_MEDIA_RW_ID (1 << 10) - 1 /* owning gid presented to userspace */
|
||||||
|
#define SHAREFS_PERM_DIR 0700 /* permission bits for directories presented to userspace */
|
||||||
|
#define SHAREFS_PERM_REG 0600 /* permission bits for regular files presented to userspace */
|
||||||
|
#define SHAREFS_FORBIDDEN_FLAGS O_DIRECT /* these open flags are cleared unconditionally */
|
||||||
|
|
||||||
/* sharefs_private is populated by sharefs_init and contains process-wide context */
|
/* sharefs_private is populated by sharefs_init and contains process-wide context */
|
||||||
struct sharefs_private {
|
struct sharefs_private {
|
||||||
int dirfd; /* source dirfd opened during sharefs_init */
|
int dirfd; /* source dirfd opened during sharefs_init */
|
||||||
|
|||||||
Reference in New Issue
Block a user