dlm: introduce dlmpfs
Subsystems (2)
Alexander Aring
maintainerRFC 1/1 dlm: introduce dlmpfs
DLMPFS is a new filesystem to offer distributed locking API (in this case DLM) over the already known and easy portable file locking API.
Why?
Because there are user outside that just use a distributed filesystem for locking. They don't have a use case to actually using a distributed filesystem to store data. Offering a DLM distributed API over a filesystem makes it easy for users to such switch to it as thats their only need as flock()/fcntl() is already being used in their application.
How to use, 2 node cluster:
1. node1:
$ mount -t dlmpfs -o clname=$CLUSTERNAME none /mnt $ touch /mnt/lock $ flock /mnt/lock -c "echo 'acquired'; sleep 20; echo 'released'"
2. node2:
$ mount -t dlmpfs -o clname=$CLUSTERNAME none /mnt $ touch /mnt/lock $ flock /mnt/lock -c "echo 'acquired'; sleep 20; echo 'released'"
do 2. at the 20 seconds range and you will victim the locking.
Limitations:
One limitation is that the filepath need to be known before as DLM cannot discover locks, but this is DLM nature as the resource name need to be based on a rule that every node has the same locking context for a specific resource. Usually this can be just hardcoded in an implementation.
Future work:
1. POSIX distributed locking specification:
The file locking API isn't made for distributed locking and has its problems because every distributed filesystem does their own stuff to somehow "map" distributed locking to the flock()/fcntl() behaviour. The goal is to use this filesystem to also allow "experiments" to introduce in a community effort new file locking callbacks/systemcalls that are more distributed locking friendly.
2. Support different lock manager backends
This filesystem is for DLM only, but I can also think of to support nfs "lockd" lock manager to it. Then this filesystem should be named more as "lockfs".
DLM stuff:
dlmpfs vs dlmfs:
There is a dlmfs already in the kernel but this offers ocfs2 DLM specific API to the user as user space interface. dlmpfs is offering file locking API to the user that uses DLM as backend.
Distributed inode problem (very DLM specific):
We need to use the same inode on all nodes that belongs to the same "context". We do that over the LVB area and using e.g. the filepath as identifier to request/allocate a clutser wide inode number.
E.g. if "/lock" regular file is created a lock request is being done with the filepath as resource name. This resource name will be asked if its already exists as this information is part of the LVB area. If such filepath/resource does not exists this node will write LVB data and allocate a unused inode number, also done over LVB and resource name. If the filepath/resource would exists then the node will held the lock only to keep this information alive. The LVB area will only be written by the first node trying creating the first file, this should make it safe that the LVB area keeps alive due recovery.
Other stuff:
This filesystem is based on ramfs, many thanks to provide such a filesystem and I was able to simple change it for my needs.
And yes, you cannot write/read any data, this filesystem is only for creating files/dirs and call flock()/fcntl() locking api on it.
--- fs/dlm/Kconfig | 10 + fs/dlm/Makefile | 2 +- fs/dlm/dlmpfs/Makefile | 8 + fs/dlm/dlmpfs/file.c | 134 +++++++++++ fs/dlm/dlmpfs/inode.c | 476 +++++++++++++++++++++++++++++++++++++ fs/dlm/dlmpfs/internal.h | 65 +++++ fs/dlm/dlmpfs/newdlm.c | 258 ++++++++++++++++++++ include/uapi/linux/magic.h | 1 + 8 files changed, 953 insertions(+), 1 deletion(-) create mode 100644 fs/dlm/dlmpfs/Makefile create mode 100644 fs/dlm/dlmpfs/file.c create mode 100644 fs/dlm/dlmpfs/inode.c create mode 100644 fs/dlm/dlmpfs/internal.h create mode 100644 fs/dlm/dlmpfs/newdlm.c
fs/dlm/Kconfig +10 -0
@@ -14,3 +14,13 @@ config DLM_DEBUG Under the debugfs mount point, the name of each lockspace will appear as a file in the "dlm" directory. The output is the list of resource and locks the local node knows about. + +config DLM_DLMPFS + tristate "DLM locking filesystem" + depends on DLM + help + Offers DLM locking API over filesystem operations locking callbacks + each node needs to create the same named file under this filesystem + and do locking API as flock or fcntl on it. It can be used if + using an applications that already use file locking for distributed + locking operations.
fs/dlm/Makefile +1 -1
@@ -18,4 +18,4 @@ dlm-y := ast.o \ user.o \ util.o dlm-$(CONFIG_DLM_DEBUG) += debug_fs.o - +obj-$(CONFIG_DLM_DLMPFS) += dlmpfs/
fs/dlm/dlmpfs/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the linux dlmpfs routines. +# + +obj-y += dlmpfs.o + +dlmpfs-objs += inode.o newdlm.o file.o
fs/dlm/dlmpfs/file.c new file +134 -0
134 lines not on this page · raw message
fs/dlm/dlmpfs/inode.c new file +476 -0
476 lines not on this page · raw message
fs/dlm/dlmpfs/internal.h new file +65 -0
65 lines not on this page · raw message
fs/dlm/dlmpfs/newdlm.c new file +258 -0
258 lines not on this page · raw message
include/uapi/linux/magic.h +1 -0
@@ -38,6 +38,7 @@#define OVERLAYFS_SUPER_MAGIC 0x794c7630#define FUSE_SUPER_MAGIC 0x65735546#define BCACHEFS_SUPER_MAGIC 0xca451a4e +#define DLMPFS_MAGIC 0x858458f7/* some random number */ #define MINIX_SUPER_MAGIC 0x137F/* minix v1 fs, 14 char names */ #define MINIX_SUPER_MAGIC2 0x138F/* minix v1 fs, 30 char names */
Signature · 1 line
2.43.0
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Alexander,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on v6.19]
url: https://github.com/intel-lab-lkp/linux/commits/Alexander-Aring/dlm-introduce-dlmpfs/20260214-020248 base: v6.19 patch link: https://lore.kernel.org/r/20260213180014.614646-1-aahringo%40redhat.com patch subject: [RFC v6.19] dlm: introduce dlmpfs config: xtensa-allyesconfig (https://download.01.org/0day-ci/archive/20260215/[email protected]/config) compiler: xtensa-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260215/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
fs/dlm/dlmpfs/inode.c: In function 'dlmpfs_alloc_inode':
>> fs/dlm/dlmpfs/inode.c:47:14: error: implicit declaration of function 'kzalloc_obj'; did you mean 'kzalloc_node'? [-Wimplicit-function-declaration]
47 | di = kzalloc_obj(*di, GFP_NOFS);
| ^~~~~~~~~~~
| kzalloc_node
>> fs/dlm/dlmpfs/inode.c:47:12: error: assignment to 'struct dlmpfs_inode *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
47 | di = kzalloc_obj(*di, GFP_NOFS);
| ^
fs/dlm/dlmpfs/inode.c: In function 'dlmpfs_init_fs_context':
>> fs/dlm/dlmpfs/inode.c:441:13: error: assignment to 'struct dlmpfs_fs_info *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
441 | fsi = kzalloc_obj(*fsi, GFP_KERNEL);
| ^
--
fs/dlm/dlmpfs/newdlm.c: In function 'dlmlk_alloc':
>> fs/dlm/dlmpfs/newdlm.c:137:14: error: implicit declaration of function 'kzalloc_obj'; did you mean 'kzalloc_node'? [-Wimplicit-function-declaration]
137 | lk = kzalloc_obj(*lk, GFP_NOFS);
| ^~~~~~~~~~~
| kzalloc_node
>> fs/dlm/dlmpfs/newdlm.c:137:12: error: assignment to 'struct dlmlk *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
137 | lk = kzalloc_obj(*lk, GFP_NOFS);
| ^
fs/dlm/dlmpfs/newdlm.c: In function 'dlmls_new':
>> fs/dlm/dlmpfs/newdlm.c:216:12: error: assignment to 'struct dlmls *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
216 | ls = kzalloc_obj(*ls, GFP_NOFS);
| ^
--
fs/dlm/dlmpfs/file.c: In function 'dlmpfs_open':
>> fs/dlm/dlmpfs/file.c:23:14: error: implicit declaration of function 'kzalloc_obj'; did you mean 'kzalloc_node'? [-Wimplicit-function-declaration]
23 | fp = kzalloc_obj(*fp, GFP_NOFS);
| ^~~~~~~~~~~
| kzalloc_node
>> fs/dlm/dlmpfs/file.c:23:12: error: assignment to 'struct dlmpfs_file *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
23 | fp = kzalloc_obj(*fp, GFP_NOFS);
| ^vim +47 fs/dlm/dlmpfs/inode.c
42
43 static struct inode *dlmpfs_alloc_inode(struct super_block *sb)
44 {
45 struct dlmpfs_inode *di;
46
> 47 di = kzalloc_obj(*di, GFP_NOFS);
48 if (!di)
49 return NULL;
50
51 inode_init_once(&di->inode);
52 return &di->inode;
53 }
54 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Alexander,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on v6.19]
url: https://github.com/intel-lab-lkp/linux/commits/Alexander-Aring/dlm-introduce-dlmpfs/20260214-020248 base: v6.19 patch link: https://lore.kernel.org/r/20260213180014.614646-1-aahringo%40redhat.com patch subject: [RFC v6.19] dlm: introduce dlmpfs config: riscv-allyesconfig (https://download.01.org/0day-ci/archive/20260216/[email protected]/config) compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260216/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> fs/dlm/dlmpfs/inode.c:47:7: error: call to undeclared function 'kzalloc_obj'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
di = kzalloc_obj(*di, GFP_NOFS);
^
>> fs/dlm/dlmpfs/inode.c:47:5: error: incompatible integer to pointer conversion assigning to 'struct dlmpfs_inode *' from 'int' [-Wint-conversion]
di = kzalloc_obj(*di, GFP_NOFS);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/dlm/dlmpfs/inode.c:441:8: error: call to undeclared function 'kzalloc_obj'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
fsi = kzalloc_obj(*fsi, GFP_KERNEL);
^
>> fs/dlm/dlmpfs/inode.c:441:6: error: incompatible integer to pointer conversion assigning to 'struct dlmpfs_fs_info *' from 'int' [-Wint-conversion]
fsi = kzalloc_obj(*fsi, GFP_KERNEL);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.
--
>> fs/dlm/dlmpfs/newdlm.c:137:7: error: call to undeclared function 'kzalloc_obj'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
lk = kzalloc_obj(*lk, GFP_NOFS);
^
>> fs/dlm/dlmpfs/newdlm.c:137:5: error: incompatible integer to pointer conversion assigning to 'struct dlmlk *' from 'int' [-Wint-conversion]
lk = kzalloc_obj(*lk, GFP_NOFS);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/dlm/dlmpfs/newdlm.c:216:7: error: call to undeclared function 'kzalloc_obj'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
ls = kzalloc_obj(*ls, GFP_NOFS);
^
>> fs/dlm/dlmpfs/newdlm.c:216:5: error: incompatible integer to pointer conversion assigning to 'struct dlmls *' from 'int' [-Wint-conversion]
ls = kzalloc_obj(*ls, GFP_NOFS);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.
--
>> fs/dlm/dlmpfs/file.c:23:7: error: call to undeclared function 'kzalloc_obj'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
fp = kzalloc_obj(*fp, GFP_NOFS);
^
>> fs/dlm/dlmpfs/file.c:23:5: error: incompatible integer to pointer conversion assigning to 'struct dlmpfs_file *' from 'int' [-Wint-conversion]
fp = kzalloc_obj(*fp, GFP_NOFS);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~2 errors generated.
vim +/kzalloc_obj +47 fs/dlm/dlmpfs/inode.c
42
43 static struct inode *dlmpfs_alloc_inode(struct super_block *sb)
44 {
45 struct dlmpfs_inode *di;
46
> 47 di = kzalloc_obj(*di, GFP_NOFS);
48 if (!di)
49 return NULL;
50
51 inode_init_once(&di->inode);
52 return &di->inode;
53 }
54 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki