Remove unused lock operation plumbing

This commit is contained in:
Antonio SJ Musumeci
2026-05-06 20:49:46 -04:00
committed by trapexit
parent cc780bc521
commit 8117998205
12 changed files with 8 additions and 458 deletions
-40
View File
@@ -1,40 +0,0 @@
/*
ISC License
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include "to_neg_errno.hpp"
#include <sys/file.h>
namespace fs
{
static
inline
int
flock(const int fd_,
const int operation_)
{
int rv;
rv = ::flock(fd_,operation_);
return ::to_neg_errno(rv);
}
}
-60
View File
@@ -1,60 +0,0 @@
/*
ISC License
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "fuse_flock.hpp"
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_flock.hpp"
#include "state.hpp"
#include "fuse.h"
static
int
_flock(const int fd_,
const int operation_)
{
int rv;
rv = fs::flock(fd_,operation_);
return rv;
}
// In cases where the node was opened but unlinked there will be no
// path and no guarentee of a `fh`. It could always do the lookup but
// why bother if the kernel has provided it to us? The reason the
// function doesn't need to run within the visit lambda is because
// since the request is outstanding the kernel won't be releasing the
// node and therefore the entry will be valid over the lifetime of
// this function.
int
FUSE::flock(const fuse_req_ctx_t *ctx_,
const fuse_file_info_t *ffi_,
int op_)
{
FileInfo *fi;
fi = state.get_fi(ctx_,ffi_->fh);
if(not fi)
return -EBADF;
return ::_flock(fi->fd,op_);
}
-30
View File
@@ -1,30 +0,0 @@
/*
ISC License
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include "fuse.h"
namespace FUSE
{
int
flock(const fuse_req_ctx_t *ctx,
const fuse_file_info_t *ffi,
int op);
}
-2
View File
@@ -209,8 +209,6 @@ FUSE::init(fuse_conn_info_t *conn_)
::_want_if_capable(conn_,FUSE_CAP_ALLOW_IDMAP,&cfg.allow_idmap);
// ::_want_if_capable(conn_,FUSE_CAP_READDIR_PLUS_AUTO);
::_want_if_capable_max_pages(conn_,cfg);
conn_->want &= ~FUSE_CAP_POSIX_LOCKS;
conn_->want &= ~FUSE_CAP_FLOCK_LOCKS;
::_spawn_thread_to_set_readahead();
-33
View File
@@ -1,33 +0,0 @@
/*
ISC License
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "fuse_lock.hpp"
#include "errno.hpp"
#include "fuse.h"
int
FUSE::lock(const fuse_req_ctx_t *ctx,
const fuse_file_info_t *ffi,
int cmd,
struct flock *flock)
{
return -ENOSYS;
}
-30
View File
@@ -1,30 +0,0 @@
/*
ISC License
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include "fuse.h"
namespace FUSE
{
int
lock(const fuse_req_ctx_t *ctx,
const fuse_file_info_t *ffi,
int cmd,
struct flock *flock);
}
-4
View File
@@ -46,7 +46,6 @@
#include "fuse_fchmod.hpp"
#include "fuse_fchown.hpp"
#include "fuse_fgetattr.hpp"
#include "fuse_flock.hpp"
#include "fuse_flush.hpp"
#include "fuse_fsync.hpp"
#include "fuse_fsyncdir.hpp"
@@ -58,7 +57,6 @@
#include "fuse_ioctl.hpp"
#include "fuse_link.hpp"
#include "fuse_listxattr.hpp"
#include "fuse_lock.hpp"
#include "fuse_mkdir.hpp"
#include "fuse_mknod.hpp"
#include "fuse_open.hpp"
@@ -111,7 +109,6 @@ _get_fuse_operations(struct fuse_operations &ops_,
ops_.fchmod = FUSE::fchmod;
ops_.fchown = FUSE::fchown;
ops_.fgetattr = FUSE::fgetattr;
ops_.flock = FUSE::flock;
ops_.flush = FUSE::flush;
ops_.fsync = FUSE::fsync;
ops_.fsyncdir = FUSE::fsyncdir;
@@ -123,7 +120,6 @@ _get_fuse_operations(struct fuse_operations &ops_,
ops_.ioctl = FUSE::ioctl;
ops_.link = FUSE::link;
ops_.listxattr = FUSE::listxattr;
ops_.lock = FUSE::lock;
ops_.mkdir = FUSE::mkdir;
ops_.mknod = FUSE::mknod;
ops_.open = FUSE::open;
-8
View File
@@ -14,7 +14,6 @@
#include "fuse_kernel.h"
#include "fuse_req_ctx.h"
#include <fcntl.h>
#include <time.h>
#include <utime.h>
#include <sys/types.h>
@@ -176,10 +175,6 @@ struct fuse_operations
const uint64_t,
struct stat *,
fuse_timeouts_t *);
int (*lock)(const fuse_req_ctx_t *,
const fuse_file_info_t *,
int cmd,
struct flock *);
int (*utimens)(const fuse_req_ctx_t *,
const char *,
const struct timespec tv[2]);
@@ -211,9 +206,6 @@ struct fuse_operations
char *buf,
size_t size,
off_t off);
int (*flock)(const fuse_req_ctx_t *,
const fuse_file_info_t *,
int op);
int (*fallocate)(const fuse_req_ctx_t *,
const uint64_t,
int,
+1 -17
View File
@@ -5,7 +5,6 @@
#include "fuse_kernel.h"
#include "fuse_req.hpp"
#include <fcntl.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
@@ -104,14 +103,12 @@ struct fuse_lowlevel_ops
void (*create)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*destroy)();
void (*fallocate)(fuse_req_t *req, const struct fuse_in_header *hdr);
void (*flock)(fuse_req_t *req, uint64_t ino, fuse_file_info_t *fi, int op);
void (*flush)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*forget)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*forget_multi)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*fsync)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*fsyncdir)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*getattr)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*getlk)(fuse_req_t *req, const struct fuse_in_header *hdr);
void (*getxattr)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*init)(fuse_conn_info_t *conn);
void (*ioctl)(fuse_req_t *req, const struct fuse_in_header *hdr);
@@ -137,7 +134,6 @@ struct fuse_lowlevel_ops
void (*retrieve_reply)(fuse_req_t *req, void *cookie, uint64_t ino, off_t offset);
void (*rmdir)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*setattr)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*setlk)(fuse_req_t *req, uint64_t ino, fuse_file_info_t *fi, struct flock *lock, int sleep);
void (*setupmapping)(fuse_req_t *req, const struct fuse_in_header *hdr);
void (*setxattr)(fuse_req_t *req, struct fuse_in_header *hdr);
void (*statfs)(fuse_req_t *req, struct fuse_in_header *hdr);
@@ -156,7 +152,7 @@ struct fuse_lowlevel_ops
* all except forget
*
* unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
* removexattr and setlk may send a zero code
* removexattr may send a zero code
*
* @param req request handle
* @param err the positive error value, or zero for success
@@ -329,18 +325,6 @@ int fuse_reply_statfs(fuse_req_t *req, const struct statvfs *stbuf);
*/
int fuse_reply_xattr(fuse_req_t *req, size_t count);
/**
* Reply with file lock information
*
* Possible requests:
* getlk
*
* @param req request handle
* @param lock the lock information
* @return zero for success, -errno for failure to send reply
*/
int fuse_reply_lock(fuse_req_t *req, const struct flock *lock);
/**
* Reply with block index
*
+3 -110
View File
@@ -2949,33 +2949,13 @@ fuse_lib_tmpfile(fuse_req_t *req_,
free_path(hdr_->nodeid,fusepath);
}
static
int
fuse_flush_common(fuse_req_t *req_,
fuse_file_info_t *ffi_)
{
struct flock lock;
int err;
int errlock;
memset(&lock,0,sizeof(lock));
lock.l_type = F_UNLCK;
lock.l_whence = SEEK_SET;
err = f.ops.flush(&req_->ctx,
ffi_);
errlock = f.ops.lock(&req_->ctx,
ffi_,
F_SETLK,
&lock);
if(errlock != -ENOSYS)
{
/* if op.lock() is defined FLUSH is needed regardless
of op.flush() */
if(err == -ENOSYS)
err = 0;
}
return err;
return f.ops.flush(&req_->ctx,
ffi_);
}
static
@@ -3036,83 +3016,6 @@ fuse_lib_flush(fuse_req_t *req_,
fuse_reply_err(req_,err);
}
static
void
convert_fuse_file_lock(const struct fuse_file_lock *fl,
struct flock *flock)
{
memset(flock, 0, sizeof(struct flock));
flock->l_type = fl->type;
flock->l_whence = SEEK_SET;
flock->l_start = fl->start;
if (fl->end == OFFSET_MAX)
flock->l_len = 0;
else
flock->l_len = fl->end - fl->start + 1;
flock->l_pid = fl->pid;
}
static
void
fuse_lib_getlk(fuse_req_t *req_,
const struct fuse_in_header *hdr_)
{
int err;
struct flock flk;
fuse_file_info_t ffi = {};
const struct fuse_lk_in *arg;
arg = (fuse_lk_in*)fuse_hdr_arg(hdr_);
ffi.fh = arg->fh;
ffi.lock_owner = arg->owner;
convert_fuse_file_lock(&arg->lk,&flk);
err = f.ops.lock(&req_->ctx,
&ffi,
F_GETLK,
&flk);
if(!err)
fuse_reply_lock(req_,&flk);
else
fuse_reply_err(req_,err);
}
static
void
fuse_lib_setlk(fuse_req_t *req_,
uint64_t ino,
fuse_file_info_t *fi,
struct flock *lock,
int sleep)
{
int err;
err = f.ops.lock(&req_->ctx,
fi,
sleep ? F_SETLKW : F_SETLK,
lock);
fuse_reply_err(req_,err);
}
static
void
fuse_lib_flock(fuse_req_t *req_,
uint64_t ino_,
fuse_file_info_t *ffi_,
int op_)
{
int err;
err = f.ops.flock(&req_->ctx,
ffi_,
op_);
fuse_reply_err(req_,err);
}
static
void
fuse_lib_bmap(fuse_req_t *req_,
@@ -3405,14 +3308,12 @@ static struct fuse_lowlevel_ops fuse_path_ops =
.create = fuse_lib_create,
.destroy = fuse_lib_destroy,
.fallocate = fuse_lib_fallocate,
.flock = fuse_lib_flock,
.flush = fuse_lib_flush,
.forget = fuse_lib_forget,
.forget_multi = fuse_lib_forget_multi,
.fsync = fuse_lib_fsync,
.fsyncdir = fuse_lib_fsyncdir,
.getattr = fuse_lib_getattr,
.getlk = fuse_lib_getlk,
.getxattr = fuse_lib_getxattr,
.init = fuse_lib_init,
.ioctl = fuse_lib_ioctl,
@@ -3438,7 +3339,6 @@ static struct fuse_lowlevel_ops fuse_path_ops =
.retrieve_reply = fuse_lib_retrieve_reply,
.rmdir = fuse_lib_rmdir,
.setattr = fuse_lib_setattr,
.setlk = fuse_lib_setlk,
.setupmapping = fuse_lib_setupmapping,
.setxattr = fuse_lib_setxattr,
.statfs = fuse_lib_statfs,
@@ -3662,13 +3562,6 @@ fuse_new(int fd_,
f.ops = *ops_;
/* Oh f**k,this is ugly! */
if(!f.ops.lock)
{
llop.getlk = NULL;
llop.setlk = NULL;
}
f.se = fuse_lowlevel_new_common(args,&llop,sizeof(llop));
if(f.se == NULL)
goto out_free_fs;
+3 -124
View File
@@ -476,29 +476,6 @@ fuse_reply_xattr(fuse_req_t *req,
return send_reply_ok(req, &arg, sizeof(arg));
}
int
fuse_reply_lock(fuse_req_t *req,
const struct flock *lock)
{
struct fuse_lk_out arg = {};
arg.lk.type = lock->l_type;
if(lock->l_type != F_UNLCK)
{
arg.lk.start = lock->l_start;
if(lock->l_len == 0)
arg.lk.end = OFFSET_MAX;
else
arg.lk.end = lock->l_start + lock->l_len - 1;
}
arg.lk.pid = lock->l_pid;
if(fuse_cfg.debug)
fuse_debug_lk_out(req->ctx.unique,&arg);
return send_reply_ok(req, &arg, sizeof(arg));
}
int
fuse_reply_bmap(fuse_req_t *req,
uint64_t idx)
@@ -913,91 +890,6 @@ do_removexattr(fuse_req_t *req,
f.op.removexattr(req,hdr_);
}
static
void
convert_fuse_file_lock(struct fuse_file_lock *fl,
struct flock *flock)
{
memset(flock, 0, sizeof(struct flock));
flock->l_type = fl->type;
flock->l_whence = SEEK_SET;
flock->l_start = fl->start;
if(fl->end == OFFSET_MAX)
flock->l_len = 0;
else
flock->l_len = fl->end - fl->start + 1;
flock->l_pid = fl->pid;
}
static
void
do_getlk(fuse_req_t *req,
struct fuse_in_header *hdr_)
{
f.op.getlk(req,hdr_);
}
static
void
do_setlk_common(fuse_req_t *req,
uint64_t nodeid,
const void *inarg,
int sleep)
{
struct flock flock;
fuse_file_info_t fi = {};
struct fuse_lk_in *arg = (struct fuse_lk_in*)inarg;
fi.fh = arg->fh;
fi.lock_owner = arg->owner;
if(arg->lk_flags & FUSE_LK_FLOCK)
{
int op = 0;
switch (arg->lk.type)
{
case F_RDLCK:
op = LOCK_SH;
break;
case F_WRLCK:
op = LOCK_EX;
break;
case F_UNLCK:
op = LOCK_UN;
break;
}
if(!sleep)
op |= LOCK_NB;
f.op.flock(req,nodeid,&fi,op);
}
else
{
convert_fuse_file_lock(&arg->lk, &flock);
f.op.setlk(req,nodeid,&fi,&flock,sleep);
}
}
static
void
do_setlk(fuse_req_t *req,
struct fuse_in_header *hdr_)
{
do_setlk_common(req, hdr_->nodeid, &hdr_[1], 0);
}
static
void
do_setlkw(fuse_req_t *req,
struct fuse_in_header *hdr_)
{
do_setlk_common(req, hdr_->nodeid, &hdr_[1], 1);
}
static
void
do_interrupt(fuse_req_t *req,
struct fuse_in_header *hdr_)
@@ -1100,8 +992,6 @@ do_init(fuse_req_t *req,
if(inargflags & FUSE_ASYNC_READ)
f.conn.capable |= FUSE_CAP_ASYNC_READ;
if(inargflags & FUSE_POSIX_LOCKS)
f.conn.capable |= FUSE_CAP_POSIX_LOCKS;
if(inargflags & FUSE_ATOMIC_O_TRUNC)
f.conn.capable |= FUSE_CAP_ATOMIC_O_TRUNC;
if(inargflags & FUSE_EXPORT_SUPPORT)
@@ -1110,8 +1000,6 @@ do_init(fuse_req_t *req,
f.conn.capable |= FUSE_CAP_BIG_WRITES;
if(inargflags & FUSE_DONT_MASK)
f.conn.capable |= FUSE_CAP_DONT_MASK;
if(inargflags & FUSE_FLOCK_LOCKS)
f.conn.capable |= FUSE_CAP_FLOCK_LOCKS;
if(inargflags & FUSE_POSIX_ACL)
f.conn.capable |= FUSE_CAP_POSIX_ACL;
if(inargflags & FUSE_CACHE_SYMLINKS)
@@ -1152,11 +1040,6 @@ do_init(fuse_req_t *req,
if(f.conn.proto_minor >= 18)
f.conn.capable |= FUSE_CAP_IOCTL_DIR;
if(f.op.getlk && f.op.setlk)
f.conn.want |= FUSE_CAP_POSIX_LOCKS;
if(f.op.flock)
f.conn.want |= FUSE_CAP_FLOCK_LOCKS;
if(bufsize < FUSE_MIN_READ_BUFFER)
{
fprintf(stderr, "fuse: warning: buffer size too small: %zu\n",
@@ -1183,8 +1066,6 @@ do_init(fuse_req_t *req,
if(f.conn.want & FUSE_CAP_ASYNC_READ)
outargflags |= FUSE_ASYNC_READ;
if(f.conn.want & FUSE_CAP_POSIX_LOCKS)
outargflags |= FUSE_POSIX_LOCKS;
if(f.conn.want & FUSE_CAP_ATOMIC_O_TRUNC)
outargflags |= FUSE_ATOMIC_O_TRUNC;
if(f.conn.want & FUSE_CAP_EXPORT_SUPPORT)
@@ -1193,8 +1074,6 @@ do_init(fuse_req_t *req,
outargflags |= FUSE_BIG_WRITES;
if(f.conn.want & FUSE_CAP_DONT_MASK)
outargflags |= FUSE_DONT_MASK;
if(f.conn.want & FUSE_CAP_FLOCK_LOCKS)
outargflags |= FUSE_FLOCK_LOCKS;
if(f.conn.want & FUSE_CAP_POSIX_ACL)
outargflags |= FUSE_POSIX_ACL;
if(f.conn.want & FUSE_CAP_CACHE_SYMLINKS)
@@ -1639,9 +1518,9 @@ fuse_ll_funcs[FUSE_OPCODE_LEN] =
do_readdir,
do_releasedir,
do_fsyncdir,
do_getlk,
do_setlk,
do_setlkw,
NULL,
NULL,
NULL,
do_access,
do_create,
do_interrupt,
+1
View File
@@ -11,6 +11,7 @@
#include "fuse_lowlevel.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>