dlm: net-namespace functionality
Subsystems (6)
Alexander Aring
maintainercover dlm: net-namespace functionality
Hi,
this patch-series is huge but brings a lot of basic "fun" net-namespace functionality to DLM. Currently you need a couple of Linux kernel instances running in e.g. Virtual Machines. With this patch-series I want to break out of this virtual machine world dealing with multiple kernels need to boot them all individually, etc. Now you can use DLM in only one Linux kernel instance and each "node" (previously represented by a virtual machine) is separate by a net-namespace. Why net-namespaces? It just fits to the DLM design for now, you need to have them anyway because the internal DLM socket handling on a per node basis. What we do additionally is to separate the DLM lockspaces (the lockspace that is being registered) by net-namespaces as this represents a "network entity" (node). There might be reasons to introduce a complete new kind of namespaces (locking namespace?) but I don't want to do this step now and as I said net-namespaces are required anyway for the DLM sockets.
You need some new user space tooling as a new netlink net-namespace aware UAPI is introduced (but can co-exist with configfs that operates on init_net only). See [0] for more steps, there is a copr repo for the new tooling and can be enabled by:
$ dnf copr enable aring/nldlm $ dnf install nldlm
or compile it yourself.
Then there is currently a very simple script [1] to show a 3 nodes cluster using gfs2 on a multiple loop block devices on a shared loop block device image (sounds weird but I do something like that). There are currently some user space synchronization issues that I solve by simple sleeps, but they are only user space problems.
To test it I recommend some virtual machine "but only one" and run the
[1] script. Afterwards you have in your executed net-namespace the 3 mountpoints /cluster/node1, /cluster/node2/ and /cluster/node3. Any vfs operations on those mountpoints acts as a per node entity operation.
We can use it for testing, development and also scale testing to have a large number of nodes joining a lockspace (which seems to be a problem right now). Instead of running 1000 vms, we can run 1000 net-namespaces in a more resource limited environment. For me it seems gfs2 can handle several mounts and still separate the resource according their global variables. Their data structures e.g. glock hash seems to have in their key a separation for that (fsid?). However this is still an experimental feature we might run into issues that requires more separation related to net-namespaces. However basic testing seems to run just fine.
Limitations
I disable any functionality for the DLM character device that allow plock handling or do DLM locking from user space. Just don't use any plock locking in gfs2 for now. But basic vfs operations should work. You can even sniff DLM traffic on the created "dlmsw" virtual bridge.
- Alex
[0] https://gitlab.com/netcoder/nldlm
[1] https://gitlab.com/netcoder/gfs2ns-examples/-/blob/main/three_nodes
Alexander Aring (12):
dlm: introduce dlm_find_lockspace_name()
dlm: disallow different configs nodeid storages
dlm: add struct net to dlm_new_lockspace()
dlm: handle port as __be16 network byte order
dlm: use dlm_config as only cluster configuration
dlm: dlm_config_info config fields to unsigned int
dlm: rename config to configfs
kobject: add kset_type_create_and_add() helper
kobject: export generic helper ops
dlm: separate dlm lockspaces per net-namespace
dlm: add nldlm net-namespace aware UAPI
gfs2: separate mount context by net-namespaces
drivers/md/md-cluster.c | 3 +- fs/dlm/Makefile | 2 + fs/dlm/config.c | 1291 +++++++++++++++---------------------- fs/dlm/config.h | 215 +++++-- fs/dlm/configfs.c | 882 ++++++++++++++++++++++++++ fs/dlm/configfs.h | 19 + fs/dlm/debug_fs.c | 24 +- fs/dlm/dir.c | 4 +- fs/dlm/dlm_internal.h | 24 +- fs/dlm/lock.c | 64 +- fs/dlm/lock.h | 3 +- fs/dlm/lockspace.c | 220 ++++--- fs/dlm/lockspace.h | 12 +- fs/dlm/lowcomms.c | 525 ++++++++-------- fs/dlm/lowcomms.h | 29 +- fs/dlm/main.c | 5 - fs/dlm/member.c | 36 +- fs/dlm/midcomms.c | 287 ++++----- fs/dlm/midcomms.h | 31 +- fs/dlm/nldlm.c | 1330 +++++++++++++++++++++++++++++++++++++++ fs/dlm/nldlm.h | 176 ++++++ fs/dlm/plock.c | 2 +- fs/dlm/rcom.c | 16 +- fs/dlm/rcom.h | 3 +- fs/dlm/recover.c | 17 +- fs/dlm/user.c | 63 +- fs/dlm/user.h | 2 +- fs/gfs2/glock.c | 8 + fs/gfs2/incore.h | 2 + fs/gfs2/lock_dlm.c | 6 +- fs/gfs2/ops_fstype.c | 5 + fs/gfs2/sys.c | 27 +- fs/ocfs2/stack_user.c | 2 +- include/linux/dlm.h | 9 +- include/linux/kobject.h | 10 +- lib/kobject.c | 55 +- 36 files changed, 3941 insertions(+), 1468 deletions(-) create mode 100644 fs/dlm/configfs.c create mode 100644 fs/dlm/configfs.h create mode 100644 fs/dlm/nldlm.c create mode 100644 fs/dlm/nldlm.h
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 1/12 dlm: introduce dlm_find_lockspace_name()
A DLM lockspace can be either identified by it's unique id or name. Later patches will introduce a new netlink api that is using a unique lockspace name to identify a lockspace in the lslist. This is mostly required for sysfs functionality that is currently solved by a per lockspace kobject allocation. The new netlink api cannot simple lookup the lockspace by a container_of() call to do whatever sysfs is providing so we introduce dlm_find_lockspace_name() to offer such functionality.
--- fs/dlm/lockspace.c | 18 ++++++++++++++++++ fs/dlm/lockspace.h | 1 + 2 files changed, 19 insertions(+)
fs/dlm/lockspace.c +18 -0
@@ -238,6 +238,24 @@ void dlm_lockspace_exit(void)kset_unregister (dlm_kset); } +struct dlm_ls *dlm_find_lockspace_name (const char *lsname) +{ +struct dlm_ls *ls; + +spin_lock_bh (&lslist_lock); + +list_for_each_entry (ls, &lslist, ls_list) { +if (!strncmp (ls->ls_name, lsname,DLM_LOCKSPACE_LEN )) { +atomic_inc (&ls->ls_count); + goto out; + } + } + ls =NULL ; + out: +spin_unlock_bh (&lslist_lock); +return ls; +} +struct dlm_ls *dlm_find_lockspace_global (uint32_t id) {struct dlm_ls *ls;
fs/dlm/lockspace.h +1 -0
@@ -22,6 +22,7 @@int dlm_lockspace_init (void );void dlm_lockspace_exit (void ); +struct dlm_ls *dlm_find_lockspace_name (const char *lsname);struct dlm_ls *dlm_find_lockspace_global (uint32_t id);struct dlm_ls *dlm_find_lockspace_local (void *id);struct dlm_ls *dlm_find_lockspace_device (int minor);
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 2/12 dlm: disallow different configs nodeid storages
In reply to Alexander AringThe DLM configfs path has usually a nodeid in it's directory path and again a file to store the nodeid again in a separate storage. It is forced that the user space will set both (the directory name and nodeid file) storage to the same value if it doesn't do that we run in some kind of broken state.
This patch will simply represent the file storage to it's upper directory nodeid name. It will force the user now to use a valid unsigned int as nodeid directory name and will ignore all nodeid writes in the nodeid file storage as this will now always represent the upper nodeid directory name.
--- fs/dlm/config.c | 53 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 18 deletions(-)
fs/dlm/config.c +35 -18
@@ -24,9 +24,9 @@#include "lowcomms.h" /* -* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid +* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid (refers to <node>) * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight -* /config/dlm/<cluster>/comms/<comm>/nodeid +* /config/dlm/<cluster>/comms/<comm>/nodeid (refers to <comm>) * /config/dlm/<cluster>/comms/<comm>/local * /config/dlm/<cluster>/comms/<comm>/addr (write only) * /config/dlm/<cluster>/comms/<comm>/addr_list (read only)
@@ -517,6 +517,12 @@ static void release_space(struct config_item *i)static struct config_item *make_comm (struct config_group *g,const char *name) {struct dlm_comm *cm; +unsigned int nodeid; +int rv; + + rv =kstrtouint (name,0 , &nodeid); +if (rv) +return ERR_PTR (rv); cm =kzalloc (sizeof (struct dlm_comm ),GFP_NOFS );if (!cm)
@@ -528,7 +534,7 @@ static struct config_item *make_comm(struct config_group *g, const char *name)if (!cm->seq) cm->seq = dlm_comm_count++; - cm->nodeid =-1 ; + cm->nodeid = nodeid; cm->local =0 ; cm->addr_count =0 ; cm->mark =0 ;
@@ -555,16 +561,25 @@ static void release_comm(struct config_item *i)static struct config_item *make_node (struct config_group *g,const char *name) {struct dlm_space *sp =config_item_to_space (g->cg_item.ci_parent); +unsigned int nodeid;struct dlm_node *nd; +uint32_t seq =0 ; +int rv; + + rv =kstrtouint (name,0 , &nodeid); +if (rv) +return ERR_PTR (rv); nd =kzalloc (sizeof (struct dlm_node ),GFP_NOFS );if (!nd)return ERR_PTR (-ENOMEM );config_item_init_type_name (&nd->item, name, &node_type); - nd->nodeid =-1 ; + nd->nodeid = nodeid; nd->weight =1 ;/* default weight of 1 if none is set */ nd->new =1 ;/* set to 0 once it's been read by dlm_nodeid_list() */ +dlm_comm_seq (nodeid, &seq); + nd->comm_seq = seq;mutex_lock (&sp->members_lock);list_add (&nd->list, &sp->members);
@@ -622,16 +637,19 @@ void dlm_config_exit(void)static ssize_t comm_nodeid_show (struct config_item *item,char *buf) { -return sprintf (buf,"%d\n" ,config_item_to_comm (item)->nodeid); +unsigned int nodeid; +int rv; + + rv =kstrtouint (config_item_name (item),0 , &nodeid); +if (WARN_ON (rv)) +return rv; + +return sprintf (buf,"%u\n" , nodeid); }static ssize_t comm_nodeid_store (struct config_item *item,const char *buf,size_t len) { -int rc =kstrtoint (buf,0 , &config_item_to_comm (item)->nodeid); - -if (rc) -return rc;return len; }
@@ -772,20 +790,19 @@ static struct configfs_attribute *comm_attrs[] = {static ssize_t node_nodeid_show (struct config_item *item,char *buf) { -return sprintf (buf,"%d\n" ,config_item_to_node (item)->nodeid); +unsigned int nodeid; +int rv; + + rv =kstrtouint (config_item_name (item),0 , &nodeid); +if (WARN_ON (rv)) +return rv; + +return sprintf (buf,"%u\n" , nodeid); }static ssize_t node_nodeid_store (struct config_item *item,const char *buf,size_t len) { -struct dlm_node *nd =config_item_to_node (item); -uint32_t seq =0 ; -int rc =kstrtoint (buf,0 , &nd->nodeid); - -if (rc) -return rc; -dlm_comm_seq (nd->nodeid, &seq); - nd->comm_seq = seq;return len; }
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 3/12 dlm: add struct net to dlm_new_lockspace()
In reply to Alexander AringTo prepare a namespace separation for each DLM lockspaces context we add a struct net parameter that the user tells us in which net-namespace the lockspace should be created. We are using net-namespace here because a DLM lockspaces context acts like a per cluster node separation and the created per node sockets need to be separated by their net-namespaces anyway. It just fits that the DLM lockspaces are also separated by a per "network entity".
This patch only prepares for such parameter for a functionality that does not exist yet. It does not have any effect. If there will be support for such handling the DLM user need to activate it anyway as the applied parameter for now is the "&init_net" instance that is the default namespace which we are currently using.
--- drivers/md/md-cluster.c | 3 ++- fs/dlm/lockspace.c | 5 +++-- fs/gfs2/lock_dlm.c | 6 +++--- fs/ocfs2/stack_user.c | 2 +- include/linux/dlm.h | 9 +++++++-- 5 files changed, 16 insertions(+), 9 deletions(-)
drivers/md/md-cluster.c +2 -1
@@ -896,7 +896,8 @@ static int join(struct mddev *mddev, int nodes)memset (str,0 ,64 );sprintf (str,"%pU" , mddev->uuid); - ret =dlm_new_lockspace (str, mddev->bitmap_info.cluster_name, + ret =dlm_new_lockspace (&init_net, str, + mddev->bitmap_info.cluster_name,DLM_LSFL_SOFTIRQ ,LVB_SIZE , &md_ls_ops, mddev, &ops_rv, &cinfo->lockspace);if (ret)
fs/dlm/lockspace.c +3 -2
@@ -663,8 +663,9 @@ static int __dlm_new_lockspace(const char *name, const char *cluster,return error; } -int dlm_new_lockspace (const char *name,const char *cluster,uint32_t flags, -int lvblen,const struct dlm_lockspace_ops *ops, +int dlm_new_lockspace (struct net *net,const char *name,const char *cluster, +uint32_t flags,int lvblen, +const struct dlm_lockspace_ops *ops,void *ops_arg,int *ops_result,dlm_lockspace_t **lockspace) {
fs/gfs2/lock_dlm.c +3 -3
@@ -1328,9 +1328,9 @@ static int gdlm_mount(struct gfs2_sbd *sdp, const char *table)* create/join lockspace */ - error =dlm_new_lockspace (fsname, cluster, flags,GDLM_LVB_SIZE , - &gdlm_lockspace_ops, sdp, &ops_result, - &ls->ls_dlm); + error =dlm_new_lockspace (&init_net, fsname, cluster, flags, +GDLM_LVB_SIZE , &gdlm_lockspace_ops, sdp, + &ops_result, &ls->ls_dlm);if (error) {fs_err (sdp,"dlm_new_lockspace error %d\n" , error); goto fail_free;
fs/ocfs2/stack_user.c +1 -1
@@ -984,7 +984,7 @@ static int user_cluster_connect(struct ocfs2_cluster_connection *conn) conn->cc_private = lc; lc->oc_type =NO_CONTROLD ; - rc =dlm_new_lockspace (conn->cc_name, conn->cc_cluster_name, + rc =dlm_new_lockspace (&init_net, conn->cc_name, conn->cc_cluster_name,DLM_LSFL_NEWEXCL ,DLM_LVB_LEN , &ocfs2_ls_ops, conn, &ops_rv, &fsdlm);if (rc) {
include/linux/dlm.h +7 -2
@@ -11,9 +11,9 @@ #ifndef __DLM_DOT_H__ #define __DLM_DOT_H__ +#include <net/net_namespace.h> #include <uapi/linux/dlm.h> - struct dlm_slot { int nodeid; /* 1 to MAX_INT */ int slot; /* 1 to MAX_INT */
@@ -43,6 +43,11 @@ struct dlm_lockspace_ops {* * Create/join a lockspace. * +* net: the net namespace context pointer where the lockspace belongs to. +* DLM lockspaces can be separated according to net namespaces. As DLM +* requires networking communication this net namespace can be used to +* have a own DLM lockspace on each network entity e.g. a DLM node. +* * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not * including terminating null). *
@@ -82,7 +87,7 @@ struct dlm_lockspace_ops {* lockspace: handle for dlm functions */ -int dlm_new_lockspace (const char *name,const char *cluster, +int dlm_new_lockspace (struct net *net,const char *name,const char *cluster,uint32_t flags,int lvblen,const struct dlm_lockspace_ops *ops,void *ops_arg,int *ops_result,dlm_lockspace_t **lockspace);
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 4/12 dlm: handle port as __be16 network byte order
In reply to Alexander AringThis patch handles the DLM listen port setting internally as byte order as it is a value that is used as network byte on the wire. The user space still sets this value as host byte order for configfs as we don't break UAPI here.
--- fs/dlm/config.c | 55 +++++++++++++++++++++++++++++++++++------------ fs/dlm/config.h | 2 +- fs/dlm/lowcomms.c | 8 +++---- 3 files changed, 46 insertions(+), 19 deletions(-)
fs/dlm/config.c +41 -14
@@ -73,7 +73,7 @@ const struct rhashtable_params dlm_rhash_rsb_params = {struct dlm_cluster {struct config_group group; -unsigned int cl_tcp_port; +__be16 cl_tcp_port;unsigned int cl_buffer_size;unsigned int cl_rsbtbl_size;unsigned int cl_recover_timer;
@@ -132,6 +132,45 @@ static ssize_t cluster_cluster_name_store(struct config_item *item,CONFIGFS_ATTR (cluster_, cluster_name); +static ssize_t cluster_tcp_port_show (struct config_item *item,char *buf) +{ +return sprintf (buf,"%u\n" ,be16_to_cpu (dlm_config.ci_tcp_port)); +} + +static int dlm_check_zero_and_dlm_running (unsigned int x) +{ +if (!x) +return -EINVAL ; + +if (dlm_lowcomms_is_running ()) +return -EBUSY ; + +return 0 ; +} + +static ssize_t cluster_tcp_port_store (struct config_item *item, +const char *buf,size_t len) +{ +int rc; +u16 x; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + + rc =kstrtou16 (buf,0 , &x); +if (rc) +return rc; + + rc =dlm_check_zero_and_dlm_running (x); +if (rc) +return rc; + + dlm_config.ci_tcp_port =cpu_to_be16 (x); +return len; +} + +CONFIGFS_ATTR (cluster_, tcp_port); +static ssize_t cluster_set (struct dlm_cluster *cl,unsigned int *cl_field,int *info_field,int (*check_cb)(unsigned int x),const char *buf,size_t len)
@@ -191,17 +230,6 @@ static int dlm_check_protocol_and_dlm_running(unsigned int x)return 0 ; } -static int dlm_check_zero_and_dlm_running (unsigned int x) -{ -if (!x) -return -EINVAL ; - -if (dlm_lowcomms_is_running ()) -return -EBUSY ; - -return 0 ; -} -static int dlm_check_zero (unsigned int x) {if (!x)
@@ -218,7 +246,6 @@ static int dlm_check_buffer_size(unsigned int x)return 0 ; } -CLUSTER_ATTR (tcp_port, dlm_check_zero_and_dlm_running);CLUSTER_ATTR (buffer_size, dlm_check_buffer_size);CLUSTER_ATTR (rsbtbl_size, dlm_check_zero);CLUSTER_ATTR (recover_timer, dlm_check_zero);
@@ -974,7 +1001,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int num)#define DEFAULT_CLUSTER_NAME ""struct dlm_config_info dlm_config = { - .ci_tcp_port =DEFAULT_TCP_PORT , + .ci_tcp_port =cpu_to_be16 (DEFAULT_TCP_PORT ), .ci_buffer_size =DLM_MAX_SOCKET_BUFSIZE , .ci_rsbtbl_size =DEFAULT_RSBTBL_SIZE , .ci_recover_timer =DEFAULT_RECOVER_TIMER ,
fs/dlm/config.h +1 -1
@@ -29,7 +29,7 @@ extern const struct rhashtable_params dlm_rhash_rsb_params;#define DLM_PROTO_SCTP 1struct dlm_config_info { -int ci_tcp_port; +__be16 ci_tcp_port;int ci_buffer_size;int ci_rsbtbl_size;int ci_recover_timer;
fs/dlm/lowcomms.c +4 -4
@@ -660,18 +660,18 @@ static void add_sock(struct socket *sock, struct connection *con)/* Add the port number to an IPv6 or 4 sockaddr and return the address length */ -static void make_sockaddr (struct sockaddr_storage *saddr,uint16_t port, +static void make_sockaddr (struct sockaddr_storage *saddr,__be16 port,int *addr_len) { saddr->ss_family = dlm_local_addr[0 ].ss_family;if (saddr->ss_family ==AF_INET ) {struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr; - in4_addr->sin_port =cpu_to_be16 (port); + in4_addr->sin_port = port; *addr_len =sizeof (struct sockaddr_in );memset (&in4_addr->sin_zero,0 ,sizeof (in4_addr->sin_zero)); }else {struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)saddr; - in6_addr->sin6_port =cpu_to_be16 (port); + in6_addr->sin6_port = port; *addr_len =sizeof (struct sockaddr_in6 ); }memset ((char *)saddr + *addr_len,0 ,sizeof (struct sockaddr_storage ) - *addr_len);
@@ -1121,7 +1121,7 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed)/* * sctp_bind_addrs - bind a SCTP socket to all our addresses */ -static int sctp_bind_addrs (struct socket *sock,uint16_t port) +static int sctp_bind_addrs (struct socket *sock,__be16 port) {struct sockaddr_storage localaddr;struct sockaddr *addr = (struct sockaddr *)&localaddr;
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 5/12 dlm: use dlm_config as only cluster configuration
In reply to Alexander AringThis patch removes the configfs storage fields from the dlm_cluster structure to store per cluster values. Those fields also exists for the dlm_config global variable and get stored in both when setting configfs values. To read values it will always be read out from the dlm_cluster configfs structure but this patch changes it to only use the global dlm_config variable. Storing them in two places makes no sense as both are able to be changed under certain conditions during DLM runtime.
--- fs/dlm/config.c | 47 +++++------------------------------------------ 1 file changed, 5 insertions(+), 42 deletions(-)
fs/dlm/config.c +5 -42
@@ -73,20 +73,6 @@ const struct rhashtable_params dlm_rhash_rsb_params = {struct dlm_cluster {struct config_group group; -__be16 cl_tcp_port; -unsigned int cl_buffer_size; -unsigned int cl_rsbtbl_size; -unsigned int cl_recover_timer; -unsigned int cl_toss_secs; -unsigned int cl_scan_secs; -unsigned int cl_log_debug; -unsigned int cl_log_info; -unsigned int cl_protocol; -unsigned int cl_mark; -unsigned int cl_new_rsb_count; -unsigned int cl_recover_callbacks; -char cl_cluster_name[DLM_LOCKSPACE_LEN ]; -struct dlm_spaces *sps;struct dlm_comms *cms; };
@@ -115,18 +101,14 @@ enum {static ssize_t cluster_cluster_name_show (struct config_item *item,char *buf) { -struct dlm_cluster *cl =config_item_to_cluster (item); -return sprintf (buf,"%s\n" , cl->cl_cluster_name); +return sprintf (buf,"%s\n" , dlm_config.ci_cluster_name); }static ssize_t cluster_cluster_name_store (struct config_item *item,const char *buf,size_t len) { -struct dlm_cluster *cl =config_item_to_cluster (item); -strscpy (dlm_config.ci_cluster_name, buf, -sizeof (dlm_config.ci_cluster_name)); -strscpy (cl->cl_cluster_name, buf,sizeof (cl->cl_cluster_name)); +sizeof (dlm_config.ci_cluster_name));return len; }
@@ -171,8 +153,7 @@ static ssize_t cluster_tcp_port_store(struct config_item *item,CONFIGFS_ATTR (cluster_, tcp_port); -static ssize_t cluster_set (struct dlm_cluster *cl,unsigned int *cl_field, -int *info_field,int (*check_cb)(unsigned int x), +static ssize_t cluster_set (int *info_field,int (*check_cb)(unsigned int x),const char *buf,size_t len) {unsigned int x;
@@ -190,7 +171,6 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,return rc; } - *cl_field = x; *info_field = x;return len;
@@ -200,14 +180,11 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, static ssize_t cluster_##name##_store(struct config_item *item, \ const char *buf, size_t len) \ { \ - struct dlm_cluster *cl = config_item_to_cluster(item); \ - return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \ - check_cb, buf, len); \ + return cluster_set(&dlm_config.ci_##name, check_cb, buf, len); \ } \ static ssize_t cluster_##name##_show(struct config_item *item, char *buf) \ { \ - struct dlm_cluster *cl = config_item_to_cluster(item); \ - return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \ + return snprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name); \ } \ CONFIGFS_ATTR(cluster_, name);
@@ -450,20 +427,6 @@ static struct config_group *make_cluster(struct config_group *g,configfs_add_default_group (&sps->ss_group, &cl->group);configfs_add_default_group (&cms->cs_group, &cl->group); - cl->cl_tcp_port = dlm_config.ci_tcp_port; - cl->cl_buffer_size = dlm_config.ci_buffer_size; - cl->cl_rsbtbl_size = dlm_config.ci_rsbtbl_size; - cl->cl_recover_timer = dlm_config.ci_recover_timer; - cl->cl_toss_secs = dlm_config.ci_toss_secs; - cl->cl_scan_secs = dlm_config.ci_scan_secs; - cl->cl_log_debug = dlm_config.ci_log_debug; - cl->cl_log_info = dlm_config.ci_log_info; - cl->cl_protocol = dlm_config.ci_protocol; - cl->cl_new_rsb_count = dlm_config.ci_new_rsb_count; - cl->cl_recover_callbacks = dlm_config.ci_recover_callbacks; -memcpy (cl->cl_cluster_name, dlm_config.ci_cluster_name, -DLM_LOCKSPACE_LEN ); - space_list = &sps->ss_group; comm_list = &cms->cs_group;return &cl->group;
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 6/12 dlm: dlm_config_info config fields to unsigned int
In reply to Alexander AringWe are using kstrtouint() to parse common integer fields. This patch will switch to use unsigned int instead of int as we are parsing unsigned integer values.
--- fs/dlm/config.c | 3 ++- fs/dlm/config.h | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-)
fs/dlm/config.c +2 -1
@@ -153,7 +153,8 @@ static ssize_t cluster_tcp_port_store(struct config_item *item,CONFIGFS_ATTR (cluster_, tcp_port); -static ssize_t cluster_set (int *info_field,int (*check_cb)(unsigned int x), +static ssize_t cluster_set (unsigned int *info_field, +int (*check_cb)(unsigned int x),const char *buf,size_t len) {unsigned int x;
fs/dlm/config.h +11 -11
@@ -30,17 +30,17 @@ extern const struct rhashtable_params dlm_rhash_rsb_params;struct dlm_config_info {__be16 ci_tcp_port; -int ci_buffer_size; -int ci_rsbtbl_size; -int ci_recover_timer; -int ci_toss_secs; -int ci_scan_secs; -int ci_log_debug; -int ci_log_info; -int ci_protocol; -int ci_mark; -int ci_new_rsb_count; -int ci_recover_callbacks; +unsigned int ci_buffer_size; +unsigned int ci_rsbtbl_size; +unsigned int ci_recover_timer; +unsigned int ci_toss_secs; +unsigned int ci_scan_secs; +unsigned int ci_log_debug; +unsigned int ci_log_info; +unsigned int ci_protocol; +unsigned int ci_mark; +unsigned int ci_new_rsb_count; +unsigned int ci_recover_callbacks;char ci_cluster_name[DLM_LOCKSPACE_LEN ]; };
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 7/12 dlm: rename config to configfs
In reply to Alexander AringThis patch will rename the config.c implementation file to configfs.c as in further patches we will introduce a configuration layer to allow different UAPI mechanism operate on current configfs configurations. We need a different UAPI mechanism as we want to separate our configuration on a per net-namespaces basis. The new file "configfs.c" only contains functionality to maintain configfs handling.
---
fs/dlm/Makefile | 2 +-
fs/dlm/{config.c => configfs.c} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename fs/dlm/{config.c => configfs.c} (100%)fs/dlm/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DLM) += dlm.o dlm-y := ast.o \ - config.o \ + configfs.o \ dir.o \ lock.o \ lockspace.o \
fs/dlm/configfs.c renamed from fs/dlm/config.c +0 -0
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 8/12 kobject: add kset_type_create_and_add() helper
In reply to Alexander AringCurrently there exists the kset_create_and_add() helper that does not allow to have a different ktype for the created kset kobject. To allow a different ktype this patch will introduce the function kset_type_create_and_add() that allows to set a different ktype instead of using the global default kset_ktype variable.
In my example I need to separate the created kobject inside the kset by net-namespaces. This patch allows me to do that by providing a user defined kobj_type structure that implements the necessary namespace functionality.
--- include/linux/kobject.h | 8 +++++-- lib/kobject.c | 49 +++++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 21 deletions(-)
include/linux/kobject.h +6 -2
@@ -175,8 +175,12 @@ struct kset {void kset_init (struct kset *kset);int __must_check kset_register (struct kset *kset);void kset_unregister (struct kset *kset); -struct kset *__must_check kset_create_and_add (const char *name,const struct kset_uevent_ops *u, -struct kobject *parent_kobj); +struct kset *__must_check +kset_type_create_and_add (const char *name,const struct kset_uevent_ops *u, +struct kobject *parent_kobj,const struct kobj_type *ktype); +struct kset *__must_check +kset_create_and_add (const char *name,const struct kset_uevent_ops *u, +struct kobject *parent_kobj);static inline struct kset *to_kset (struct kobject *kobj) {
lib/kobject.c +30 -19
72 lines not on this page · raw message
Signature · 1 line
2.43.0
kernel test robot
build botRe: [RFC dlm/next 08/12] kobject: add kset_type_create_and_add() helper
kernel test robot noticed the following build warnings:
Hi Alexander,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on teigland-dlm/next]
[also build test WARNING on driver-core/driver-core-testing driver-core/driver-core-next driver-core/driver-core-linus linus/master v6.11-rc3 next-20240815] [cannot apply to gfs2/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Alexander-Aring/dlm-introduce-dlm_find_lockspace_name/20240814-233736 base: https://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm.git next patch link: https://lore.kernel.org/r/20240814143414.1877505-9-aahringo%40redhat.com patch subject: [RFC dlm/next 08/12] kobject: add kset_type_create_and_add() helper config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20240815/[email protected]/config) compiler: or1k-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/[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 warnings (new ones prefixed by >>):
>> lib/kobject.c:962: warning: Function parameter or struct member 'ktype' not described in 'kset_create'
vim +962 lib/kobject.c
b727c702896f88 Greg Kroah-Hartman 2007-09-27 942
b727c702896f88 Greg Kroah-Hartman 2007-09-27 943 /**
ed856349dc0886 Tobin C. Harding 2019-05-02 944 * kset_create() - Create a struct kset dynamically.
b727c702896f88 Greg Kroah-Hartman 2007-09-27 945 *
b727c702896f88 Greg Kroah-Hartman 2007-09-27 946 * @name: the name for the kset
b727c702896f88 Greg Kroah-Hartman 2007-09-27 947 * @uevent_ops: a struct kset_uevent_ops for the kset
b727c702896f88 Greg Kroah-Hartman 2007-09-27 948 * @parent_kobj: the parent kobject of this kset, if any.
b727c702896f88 Greg Kroah-Hartman 2007-09-27 949 *
b727c702896f88 Greg Kroah-Hartman 2007-09-27 950 * This function creates a kset structure dynamically. This structure can
b727c702896f88 Greg Kroah-Hartman 2007-09-27 951 * then be registered with the system and show up in sysfs with a call to
b727c702896f88 Greg Kroah-Hartman 2007-09-27 952 * kset_register(). When you are finished with this structure, if
b727c702896f88 Greg Kroah-Hartman 2007-09-27 953 * kset_register() has been called, call kset_unregister() and the
b727c702896f88 Greg Kroah-Hartman 2007-09-27 954 * structure will be dynamically freed when it is no longer being used.
b727c702896f88 Greg Kroah-Hartman 2007-09-27 955 *
b727c702896f88 Greg Kroah-Hartman 2007-09-27 956 * If the kset was not able to be created, NULL will be returned.
b727c702896f88 Greg Kroah-Hartman 2007-09-27 957 */
b727c702896f88 Greg Kroah-Hartman 2007-09-27 958 static struct kset *kset_create(const char *name,
9cd43611ccfb46 Emese Revfy 2009-12-31 959 const struct kset_uevent_ops *uevent_ops,
9b20142ac9c1ca Alexander Aring 2024-08-14 960 struct kobject *parent_kobj,
9b20142ac9c1ca Alexander Aring 2024-08-14 961 const struct kobj_type *ktype)
b727c702896f88 Greg Kroah-Hartman 2007-09-27 @962 {
b727c702896f88 Greg Kroah-Hartman 2007-09-27 963 struct kset *kset;
d9cd8f37855b01 Dave Young 2009-05-11 964 int retval;
b727c702896f88 Greg Kroah-Hartman 2007-09-27 965
b727c702896f88 Greg Kroah-Hartman 2007-09-27 966 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
b727c702896f88 Greg Kroah-Hartman 2007-09-27 967 if (!kset)
b727c702896f88 Greg Kroah-Hartman 2007-09-27 968 return NULL;
b7165ebbf0898b Kees Cook 2013-06-06 969 retval = kobject_set_name(&kset->kobj, "%s", name);
d9cd8f37855b01 Dave Young 2009-05-11 970 if (retval) {
d9cd8f37855b01 Dave Young 2009-05-11 971 kfree(kset);
d9cd8f37855b01 Dave Young 2009-05-11 972 return NULL;
d9cd8f37855b01 Dave Young 2009-05-11 973 }
b727c702896f88 Greg Kroah-Hartman 2007-09-27 974 kset->uevent_ops = uevent_ops;
b727c702896f88 Greg Kroah-Hartman 2007-09-27 975 kset->kobj.parent = parent_kobj;
b727c702896f88 Greg Kroah-Hartman 2007-09-27 976
9b20142ac9c1ca Alexander Aring 2024-08-14 977 kset->kobj.ktype = ktype;
b727c702896f88 Greg Kroah-Hartman 2007-09-27 978 kset->kobj.kset = NULL;
b727c702896f88 Greg Kroah-Hartman 2007-09-27 979
b727c702896f88 Greg Kroah-Hartman 2007-09-27 980 return kset;
b727c702896f88 Greg Kroah-Hartman 2007-09-27 981 }
b727c702896f88 Greg Kroah-Hartman 2007-09-27 982 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [RFC dlm/next 08/12] kobject: add kset_type_create_and_add() helper
In reply to Alexander AringQuoted 6 lines · Alexander Aring
Currently there exists the
kset_create_and_add()helper that does not allow to have a different ktype for the created kset kobject. To allow a different ktype this patch will introduce the functionkset_type_create_and_add()that allows to set a different ktype instead of using the global defaultkset_ktypevariable.
Quoted 6 lines
In my example I need to separate the created kobject inside the kset by net-namespaces. This patch allows me to do that by providing a user defined
kobj_typestructure that implements the necessary namespace functionality.Signed-off-by Alexander Aring <[email protected]>
Alexander Aring
maintainerRe: [RFC dlm/next 08/12] kobject: add kset_type_create_and_add() helper
Hi,
Quoted 8 lines · Greg KH
Quoted 6 lines · Alexander Aring
Currently there exists the
kset_create_and_add()helper that does not allow to have a different ktype for the created kset kobject. To allow a different ktype this patch will introduce the functionkset_type_create_and_add()that allows to set a different ktype instead of using the global defaultkset_ktypevariable.
Quoted 9 lines
Quoted 6 lines
In my example I need to separate the created kobject inside the kset by net-namespaces. This patch allows me to do that by providing a user defined
kobj_typestructure that implements the necessary namespace functionality.Signed-off-by Alexander Aring <[email protected]>
note that I added the comments the kernel test robot pointed out. [0]
Thanks.
- Alex
Alexander Aring
maintainerRFC 9/12 kobject: export generic helper ops
In reply to Alexander AringThis patch exports generic helpers like kset_release() and kset_get_ownership() so users can use them in their own struct kobj_type implementation instead of implementing their own functions that do the same.
--- include/linux/kobject.h | 2 ++ lib/kobject.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/kobject.h +2 -0
@@ -181,6 +181,8 @@ kset_type_create_and_add(const char *name, const struct kset_uevent_ops *u,struct kset *__must_check kset_create_and_add (const char *name,const struct kset_uevent_ops *u,struct kobject *parent_kobj); +void kset_release (struct kobject *kobj); +void kset_get_ownership (const struct kobject *kobj,kuid_t *uid,kgid_t *gid);static inline struct kset *to_kset (struct kobject *kobj) {
lib/kobject.c +4 -2
@@ -920,19 +920,21 @@ struct kobject *kset_find_obj(struct kset *kset, const char *name) }EXPORT_SYMBOL_GPL (kset_find_obj); -static void kset_release (struct kobject *kobj) +void kset_release (struct kobject *kobj) { struct kset *kset = container_of(kobj, struct kset, kobj);pr_debug ("'%s' (%p): %s\n" ,kobject_name (kobj), kobj, __func__);kfree (kset); } +EXPORT_SYMBOL_GPL (kset_release); -static void kset_get_ownership (const struct kobject *kobj,kuid_t *uid,kgid_t *gid) +void kset_get_ownership (const struct kobject *kobj,kuid_t *uid,kgid_t *gid) {if (kobj->parent)kobject_get_ownership (kobj->parent, uid, gid); } +EXPORT_SYMBOL_GPL (kset_get_ownership);static const struct kobj_type kset_ktype = { .sysfs_ops = &kobj_sysfs_ops,
Signature · 1 line
2.43.0
Greg KH
maintainerRe: [RFC dlm/next 09/12] kobject: export generic helper ops
Quoted 4 lines · Alexander Aring
This patch exports generic helpers like
kset_release()andkset_get_ownership()so users can use them in their own structkobj_typeimplementation instead of implementing their own functions that do the same.
Why is anyone needing these? What raw kobjects require this type of stuff?
thanks,
greg k-h
Alexander Aring
maintainerRe: [RFC dlm/next 09/12] kobject: export generic helper ops
Hi,
Quoted 10 lines · Greg KH
Quoted 4 lines · Alexander Aring
This patch exports generic helpers like
kset_release()andkset_get_ownership()so users can use them in their own structkobj_typeimplementation instead of implementing their own functions that do the same.Why is anyone needing these? What raw kobjects require this type of stuff?
In this patch series I introduced kset_type_create_and_add() to have the possibility to do the exact same what kset_create_and_add() is doing, just setting a different "struct kobj_type", for the kset that is created internally by kset_create_and_add(). I can't use kset_create_and_add() as it always uses "kset_ktype", see [0].
I am doing that to have only a callback for ".child_ns_type" assigned as it returns the "&net_ns_type_operations;" structure to tell underneath everything is separated by net namespaces.
I don't want to change anything else so the "struct kobj_type" should look like what kset_create_and_add() is doing. Therefore I am creating the same structure as kset_create_and_add() is using, see [0]. The "kobj_sysfs_ops" structure seems to be already accessible from outside, just the two functions I am exporting in this patch are missing. Or I implement it in the same way in the dlm/gfs2 codebase (that is what nfs is currently doing, see [1]).
And then we are at the two users of those kobjects that are using those functions, it's DLM and GFS2 as they used kset_create_and_add() before and I just want to add the ".child_ns_type" callback. Other users could be nfs [1] (for the release, get_ownership - I have no idea).
thanks.
- Alex
[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/kobject.c?h=v6.11-rc3#n937
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/nfs/sysfs.c?h=v6.11-rc3#n23
Re: [RFC dlm/next 09/12] kobject: export generic helper ops
Quoted 31 lines · Alexander Aring
Hi,
Quoted 10 lines · Greg KH
Quoted 4 lines · Alexander Aring
This patch exports generic helpers like
kset_release()andkset_get_ownership()so users can use them in their own structkobj_typeimplementation instead of implementing their own functions that do the same.Why is anyone needing these? What raw kobjects require this type of stuff?
In this patch series I introduced
kset_type_create_and_add()to have the possibility to do the exact same whatkset_create_and_add()is doing, just setting a different "structkobj_type", for the kset that is created internally bykset_create_and_add(). I can't usekset_create_and_add()as it always uses "kset_ktype", see [0].I am doing that to have only a callback for ".child_ns_type" assigned as it returns the "
&net_ns_type_operations;" structure to tell underneath everything is separated by net namespaces.
I don't want to change anything else so the "structkobj_type" should look like whatkset_create_and_add()is doing. Therefore I am creating the same structure askset_create_and_add()is using, see [0]. The "kobj_sysfs_ops" structure seems to be already accessible from outside, just the two functions I am exporting in this patch are missing. Or I implement it in the same way in the dlm/gfs2 codebase (that is what nfs is currently doing, see [1]).
Quoted 5 lines
And then we are at the two users of those kobjects that are using those functions, it's DLM and GFS2 as they used
kset_create_and_add()before and I just want to add the ".child_ns_type" callback. Other users could be nfs [1] (for the release,get_ownership- I have no idea).
Ah, makes much more sense, thanks. And ick, network namespaces...
Anyway, feel free to take this through whatever tree the rest of the series needs to go through:
Alexander Aring
maintainerRFC 10/12 dlm: separate dlm lockspaces per net-namespace
In reply to Alexander AringThis patch separates the internal DLM lockspace handling on a per net-namespace basis. The current handling of DLM offers that all lockspaces are created on a local machine without separation and the machine is part of a cluster with several nodes as other machines. This patch allows us to create a cluster without running several machines on one Linux kernel. We do that by separating all current global variables on a per net-namespace basis, in this patch it is "struct dlm_net". This patch "simply" convert mostly all global variables on a per net-namespace basis and offer a new config layer to operate on this. The configfs UAPI mechanism is using this config layer, as configfs isn't net-namespace aware it only operates on "init_net" namespace. Further new UAPIs that are namespace aware can operate on the config layer on a net-namespace basis. The DLM config layer is implemented in "config.c" the current configfs UAPI mechanism to access the config layer is implemented in "configfs.c". The config layer uses a per net-namespace mutex lock to avoid mutual access of configuration variables as this layer can be accessed in future from multiple UAPI sources.
Character device access that is used for dlm locking calls from user space are only accessible from init_net namespace, any open() on those character devices will currently end in an -EOPNOTSUPP. To support such a functionality may a different mechanism will be introduced.
This patch will separate the DLM sysfs handling by net-namespace by using kset_type_create_and_add() and implementing the necessary callbacks to reference to the right "struct net" that is part of the per lockspace kobject.
Note as this patch series should have no effect as all users still apply &init_net to dlm_new_lockspace() except that users of the DLM character device don't open() those devices under &init_net will be rejected now.
--- fs/dlm/Makefile | 1 + fs/dlm/config.c | 699 ++++++++++++++++++++++++++++++++++++++++++ fs/dlm/config.h | 197 ++++++++++-- fs/dlm/configfs.c | 614 ++++++++++++++++--------------------- fs/dlm/configfs.h | 19 ++ fs/dlm/debug_fs.c | 24 +- fs/dlm/dir.c | 4 +- fs/dlm/dlm_internal.h | 20 +- fs/dlm/lock.c | 64 ++-- fs/dlm/lock.h | 3 +- fs/dlm/lockspace.c | 192 +++++++----- fs/dlm/lockspace.h | 13 +- fs/dlm/lowcomms.c | 521 ++++++++++++++++--------------- fs/dlm/lowcomms.h | 29 +- fs/dlm/main.c | 5 - fs/dlm/member.c | 36 +-- fs/dlm/midcomms.c | 287 ++++++++--------- fs/dlm/midcomms.h | 31 +- fs/dlm/plock.c | 2 +- fs/dlm/rcom.c | 16 +- fs/dlm/rcom.h | 3 +- fs/dlm/recover.c | 17 +- fs/dlm/user.c | 63 ++-- fs/dlm/user.h | 2 +- 24 files changed, 1855 insertions(+), 1007 deletions(-) create mode 100644 fs/dlm/config.c create mode 100644 fs/dlm/configfs.h
fs/dlm/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DLM) += dlm.o dlm-y := ast.o \ + config.o \ configfs.o \ dir.o \ lock.o \
fs/dlm/config.c new file +699 -0
699 lines not on this page · raw message
fs/dlm/config.h +171 -26
228 lines not on this page · raw message
fs/dlm/configfs.c +257 -357
868 lines not on this page · raw message
fs/dlm/configfs.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/****************************************************************************** +****************************************************************************** +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. +** +** +****************************************************************************** +******************************************************************************/ + +#ifndef __CONFIGFS_DOT_H__ +#define __CONFIGFS_DOT_H__ + +int dlm_configfs_init (void ); +void dlm_configfs_exit (void ); + +#endif /* __CONFIGFS_DOT_H__ */ +
fs/dlm/debug_fs.c +19 -5
@@ -331,9 +331,10 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)unlock_rsb (r); } -static void print_format4 (struct dlm_rsb *r,struct seq_file *s) +static void print_format4 (struct dlm_ls *ls,struct dlm_rsb *r, +struct seq_file *s) { -int our_nodeid =dlm_our_nodeid (); +int our_nodeid =dlm_our_nodeid (ls->ls_dn);int print_name =1 ;int i;
@@ -381,6 +382,7 @@ static const struct seq_operations format4_seq_ops;static int table_seq_show (struct seq_file *seq,void *iter_ptr) { struct dlm_rsb *rsb = list_entry(iter_ptr, struct dlm_rsb, res_slow_list); +struct dlm_ls *ls = seq->private;if (seq->op == &format1_seq_ops)print_format1 (rsb, seq);
@@ -389,7 +391,7 @@ static int table_seq_show(struct seq_file *seq, void *iter_ptr)else if (seq->op == &format3_seq_ops)print_format3 (rsb, seq);else if (seq->op == &format4_seq_ops) -print_format4 (rsb, seq); +print_format4 (ls, rsb, seq);return 0 ; }
@@ -736,11 +738,15 @@ static const struct file_operations dlm_rawmsg_fops = { .llseek = no_llseek, }; -void *dlm_create_debug_comms_file (int nodeid,void *data) +void *dlm_create_debug_comms_file (struct dlm_net *dn,int nodeid,void *data) {struct dentry *d_node;char name[256 ]; +/* debugfs only supported for init_net */ +if (!net_eq (read_pnet (&dn->net), &init_net)) +return NULL ; +memset (name,0 ,sizeof (name));snprintf (name,256 ,"%d" , nodeid);
@@ -755,8 +761,12 @@ void *dlm_create_debug_comms_file(int nodeid, void *data)return d_node; } -void dlm_delete_debug_comms_file (void *ctx) +void dlm_delete_debug_comms_file (struct dlm_net *dn,void *ctx) { +/* debugfs only supported for init_net */ +if (!net_eq (read_pnet (&dn->net), &init_net)) +return ; +debugfs_remove (ctx); }
@@ -765,6 +775,10 @@ void dlm_create_debug_file(struct dlm_ls *ls)/* Reserve enough space for the longest file name */ char name[DLM_LOCKSPACE_LEN +sizeof ("_queued_asts" )]; +/* debugfs only supported for init_net */ +if (!net_eq (read_pnet (&ls->ls_dn->net), &init_net)) +return ; +/* format 1 */ ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name,
fs/dlm/dir.c +2 -2
@@ -35,7 +35,7 @@ int dlm_hash2nodeid(struct dlm_ls *ls, uint32_t hash)uint32_t node;if (ls->ls_num_nodes ==1 ) -return dlm_our_nodeid (); +return dlm_our_nodeid (ls->ls_dn);else { node = (hash >>16 ) % ls->ls_total_weight;return ls->ls_node_array[node];
@@ -74,7 +74,7 @@ int dlm_recover_directory(struct dlm_ls *ls, uint64_t seq) goto out;list_for_each_entry (memb, &ls->ls_nodes, list) { -if (memb->nodeid ==dlm_our_nodeid ()) +if (memb->nodeid ==dlm_our_nodeid (ls->ls_dn))continue ;memset (last_name,0 ,DLM_RESNAME_MAXLEN );
fs/dlm/dlm_internal.h +12 -8
@@ -64,24 +64,24 @@ struct dlm_msg; #define log_rinfo(ls, fmt, args...) \ do { \ - if (dlm_config.ci_log_info) \ + if (ls->ls_dn->config.ci_log_info) \ printk(KERN_INFO "dlm: %s: " fmt "\n", \ (ls)->ls_name, ##args); \ - else if (dlm_config.ci_log_debug) \ + else if (ls->ls_dn->config.ci_log_debug) \ printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ (ls)->ls_name , ##args); \ } while (0) #define log_debug(ls, fmt, args...) \ do { \ - if (dlm_config.ci_log_debug) \ + if (ls->ls_dn->config.ci_log_debug) \ printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ (ls)->ls_name , ##args); \ } while (0) #define log_limit(ls, fmt, args...) \ do { \ - if (dlm_config.ci_log_debug) \ + if (ls->ls_dn->config.ci_log_debug) \ printk_ratelimited(KERN_DEBUG "dlm: %s: " fmt "\n", \ (ls)->ls_name , ##args); \ } while (0)
@@ -561,6 +561,8 @@ struct rcom_lock {struct dlm_ls {struct list_head ls_list;/* list of lockspaces */ +struct dlm_net *ls_dn; +netns_tracker ls_tracker;uint32_t ls_global_id;/* global unique lockspace ID */ uint32_t ls_generation;uint32_t ls_exflags;
@@ -816,15 +818,17 @@ void dlm_register_debugfs(void);void dlm_unregister_debugfs (void );void dlm_create_debug_file (struct dlm_ls *ls);void dlm_delete_debug_file (struct dlm_ls *ls); -void *dlm_create_debug_comms_file (int nodeid,void *data); -void dlm_delete_debug_comms_file (void *ctx); +void *dlm_create_debug_comms_file (struct dlm_net *dn,int nodeid,void *data); +void dlm_delete_debug_comms_file (struct dlm_net *dn,void *ctx);#else static inline void dlm_register_debugfs (void ) { }static inline void dlm_unregister_debugfs (void ) { }static inline void dlm_create_debug_file (struct dlm_ls *ls) { }static inline void dlm_delete_debug_file (struct dlm_ls *ls) { } -static inline void *dlm_create_debug_comms_file (int nodeid,void *data) {return NULL ; } -static inline void dlm_delete_debug_comms_file (void *ctx) { } +static inline void *dlm_create_debug_comms_file (struct dlm_net *dn,int nodeid, +void *data) {return NULL ; } +static inline void dlm_delete_debug_comms_file (struct dlm_net *dn, +void *ctx) { }#endif #endif /* __DLM_INTERNAL_DOT_H__ */
fs/dlm/lock.c +32 -32
202 lines not on this page · raw message
fs/dlm/lock.h +2 -1
@@ -16,7 +16,8 @@ void dlm_dump_rsb_name(struct dlm_ls *ls, const char *name, int len);void dlm_print_lkb (struct dlm_lkb *lkb);void dlm_receive_message_saved (struct dlm_ls *ls,const struct dlm_message *ms,uint32_t saved_seq); -void dlm_receive_buffer (const union dlm_packet *p,int nodeid); +void dlm_receive_buffer (struct dlm_net *dn,const union dlm_packet *p, +int nodeid);int dlm_modes_compat (int mode1,int mode2);void free_inactive_rsb (struct dlm_rsb *r);void dlm_put_rsb (struct dlm_rsb *r);
fs/dlm/lockspace.c +112 -80
461 lines not on this page · raw message
fs/dlm/lockspace.h +7 -6
@@ -22,14 +22,15 @@int dlm_lockspace_init (void );void dlm_lockspace_exit (void ); -struct dlm_ls *dlm_find_lockspace_name (const char *lsname); -struct dlm_ls *dlm_find_lockspace_global (uint32_t id); +void dlm_lockspace_net_init (struct dlm_net *dn); +struct dlm_ls *dlm_find_lockspace_name (struct dlm_net *dn,const char *lsname); +struct dlm_ls *dlm_find_lockspace_global (struct dlm_net *dn,uint32_t id);struct dlm_ls *dlm_find_lockspace_local (void *id); -struct dlm_ls *dlm_find_lockspace_device (int minor); +struct dlm_ls *dlm_find_lockspace_device (struct dlm_net *dn,int minor);void dlm_put_lockspace (struct dlm_ls *ls); -void dlm_stop_lockspaces (void ); -int dlm_new_user_lockspace (const char *name,const char *cluster, -uint32_t flags,int lvblen, +void dlm_stop_lockspaces (struct dlm_net *dn); +int dlm_new_user_lockspace (struct dlm_net *dn,const char *name, +const char *cluster,uint32_t flags,int lvblen,const struct dlm_lockspace_ops *ops,void *ops_arg,int *ops_result,dlm_lockspace_t **lockspace);
fs/dlm/lowcomms.c +259 -262
347 lines not on this page · raw message
fs/dlm/midcomms.c +146 -141
287 lines not on this page · raw message
fs/dlm/user.c +44 -19
63 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.43.0
Part of the diff is not shown here. View the raw message.
Alexander Aring
maintainerRFC 11/12 dlm: add nldlm net-namespace aware UAPI
In reply to Alexander AringRecent patches introduced support to separate DLM lockspaces on a per net-namespace basis. Currently the file based configfs mechanism is used to configure parts of DLM. Due the lack of namespace awareness (and it's probably complicated to add support for this) in configfs we introduce a socket based UAPI using "netlink". As the DLM subsystem offers now a config layer it can simultaneously being used with configfs, just that nldlm is net-namespace aware.
Most of the current configfs functionality that is necessary to configure DLM is being adapted for now. The nldlm netlink interface offers also a multicast group for lockspace events NLDLM_MCGRP_EVENT. This event group can be used as alternative to the already existing udev event behaviour just it only contains DLM related subsystem events.
Attributes e.g. nodeid, port, IP addresses are expected from the user space to fill those numbers as they appear on the wire. In case of DLM fields it is using little endian byte order.
The dumps are being designed to scale in future with high numbers of members in a lockspace. E.g. dump members require an unique lockspace identifier (currently only the name) and nldlm is using a netlink dump behaviour to be prepared if all entries may not fit into one netlink message.
--- fs/dlm/Makefile | 1 + fs/dlm/config.c | 20 +- fs/dlm/dlm_internal.h | 4 + fs/dlm/lockspace.c | 13 +- fs/dlm/nldlm.c | 1330 +++++++++++++++++++++++++++++++++++++++++ fs/dlm/nldlm.h | 176 ++++++ 6 files changed, 1538 insertions(+), 6 deletions(-) create mode 100644 fs/dlm/nldlm.c create mode 100644 fs/dlm/nldlm.h
fs/dlm/Makefile +1 -0
@@ -11,6 +11,7 @@ dlm-y := ast.o \ memory.o \ midcomms.o \ lowcomms.o \ + nldlm.o \ plock.o \ rcom.o \ recover.o \
fs/dlm/config.c +16 -4
@@ -91,11 +91,21 @@ int __init dlm_config_init(void)if (rv)return rv; + rv =dlm_nldlm_init (); +if (rv) + goto err; + rv =dlm_configfs_init (); -if (rv) { -unregister_pernet_subsys (&dlm_net_ops); - dlm_net_id =0 ; - } +if (rv) + goto err_nldlm; + +return rv; + +err_nldlm: +dlm_nldlm_exit (); +err: +unregister_pernet_subsys (&dlm_net_ops); + dlm_net_id =0 ;return rv; }
@@ -103,6 +113,8 @@ int __init dlm_config_init(void)void dlm_config_exit (void ) {dlm_configfs_exit (); +dlm_nldlm_exit (); +unregister_pernet_subsys (&dlm_net_ops); dlm_net_id =0 ; }
fs/dlm/dlm_internal.h +4 -0
@@ -813,6 +813,10 @@ extern struct workqueue_struct *dlm_wq;int dlm_plock_init (void );void dlm_plock_exit (void ); +int nldlm_ls_event (const struct dlm_ls *ls,uint32_t event); +int __init dlm_nldlm_init (void ); +void dlm_nldlm_exit (void ); +#ifdef CONFIG_DLM_DEBUG void dlm_register_debugfs (void );void dlm_unregister_debugfs (void );
fs/dlm/lockspace.c +11 -2
@@ -23,6 +23,7 @@#include "lock.h" #include "recover.h" #include "requestqueue.h" +#include "nldlm.h" #include "user.h" #include "ast.h"
@@ -205,10 +206,18 @@ static const struct kobj_type dlm_kset_ktype = {static int do_uevent (struct dlm_ls *ls,int in) { -if (in) +int rv; + +if (in) {kobject_uevent (&ls->ls_kobj,KOBJ_ONLINE ); -else + rv =nldlm_ls_event (ls,NLDLM_EVENT_LS_NEW ); + }else {kobject_uevent (&ls->ls_kobj,KOBJ_OFFLINE ); + rv =nldlm_ls_event (ls,NLDLM_EVENT_LS_RELEASE ); + } + +/* ignore if nldlm_ls_event() has no subscribes */ +WARN_ON (rv && rv != -ESRCH );log_rinfo (ls,"%s the lockspace group..." , in ?"joining" :"leaving" );
fs/dlm/nldlm.c new file +1330 -0
1,330 lines not on this page · raw message
fs/dlm/nldlm.h new file +176 -0
176 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Aring
maintainerRFC 12/12 gfs2: separate mount context by net-namespaces
In reply to Alexander AringThis patch changes gfs2 to be the first user of the recently introduced net-namespace feature of DLM. It uses the current net-namespace context of the get_tree() callback of "struct fs_context_operations" that is e.g. being called by syscalls of the coreutils mount process.
Debugfs is being disabled for non "init_net" net-namespaces as debugfs is not net-namespace aware. Otherwise we would see kernel log error messages about existing debugfs entries. There might be in future another ways to get similar information with an UAPI mechanism that is namespace aware.
With this patch you can setup a cluster in one machine without using multiple Linux kernel instances. The idea is to use this for developing/testing as a first use-case. Especially scale testing, a gfs2 file system with a lot of members can be setup without running a large set of virtual machines.
There is a small example script how it works:
https://gitlab.com/netcoder/gfs2ns-examples/-/blob/main/three_nodes
it uses multiple loop block devices references to the same file to provide a kind of shared block device (an alternative could be using dm linear mapping, but loop block device also works). After setting up multiple net-namespaces with a virtual bridge interface DLM can be configured by using nldlmd that is using the recently introduced net-namespace aware nldlm netlink API. Over a shell command like:
ip netns exec node1 sh -c "mount /dev/loop1 /cluster/node1" ip netns exec node2 sh -c "mount /dev/loop2 /cluster/node2"
...
every cluster "node" (hereby identifier with a "node#" string in the iproute2 namespace management mechanism) can mount the shared block device e.g. /dev/loop1, /dev/loop# that references to the same block image on a different file system. Note that the caller in the script will be unmount the file system if the last user left the namespace. I currently workaround this use case by mountbind each block device again in a kind of "default" namespace (usually it should be where "init_net" references to).
Then each mountpoint of "/cluster/node#" acts like being a cluster node access to the gfs2 file system with DLM locking enabled. This offers us new possibilities to write testcases as we operate on a single machine and can "easier" synchronize vfs syscalls in our testcase as no "remote machine" kind network communication is being involved.
The mount sysfs directory for gfs2 needs to be separated by net-namespace as our mount call is from namespace view separated and be treated as per "node" (machine) call. Otherwise we would run into conflicts on files/directories that already exists as the cluster wide unique identifiers are already being in use.
The gfs2 file system has some global variables and it seems it is not necessary to separate them by net-namespace as they store a unique per mount identifier. I didn't had problems yet and it seems it is currently okay to do that, otherwise there might be issues with "things" that are not net-namespace aware in gfs2 yet. However we only should find issues only when we using net-namespaces. If a user only uses "init_net" as this is the current default, there should not be any problems.
--- fs/gfs2/glock.c | 8 ++++++++ fs/gfs2/incore.h | 2 ++ fs/gfs2/lock_dlm.c | 2 +- fs/gfs2/ops_fstype.c | 5 +++++ fs/gfs2/sys.c | 27 ++++++++++++++++++++++++++- 5 files changed, 42 insertions(+), 2 deletions(-)
fs/gfs2/glock.c +8 -0
@@ -2898,6 +2898,10 @@ DEFINE_SEQ_ATTRIBUTE(gfs2_sbstats);void gfs2_create_debugfs_file (struct gfs2_sbd *sdp) { +/* debugfs is only available for init_net users */ +if (!net_eq (read_pnet (&sdp->net), &init_net)) +return ; + sdp->debugfs_dir =debugfs_create_dir (sdp->sd_table_name, gfs2_root); debugfs_create_file("glocks", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp,
@@ -2915,6 +2919,10 @@ void gfs2_create_debugfs_file(struct gfs2_sbd *sdp)void gfs2_delete_debugfs_file (struct gfs2_sbd *sdp) { +/* debugfs is only available for init_net users */ +if (!net_eq (read_pnet (&sdp->net), &init_net)) +return ; +debugfs_remove_recursive (sdp->debugfs_dir); sdp->debugfs_dir =NULL ; }
fs/gfs2/incore.h +2 -0
@@ -710,6 +710,8 @@ struct gfs2_sbd {/* Lock Stuff */ +possible_net_t net; +netns_tracker tracker;/* keep track of net references */ struct lm_lockstruct sd_lockstruct;struct gfs2_holder sd_live_gh;struct gfs2_glock *sd_rename_gl;
fs/gfs2/lock_dlm.c +1 -1
@@ -1328,7 +1328,7 @@ static int gdlm_mount(struct gfs2_sbd *sdp, const char *table)* create/join lockspace */ - error =dlm_new_lockspace (&init_net, fsname, cluster, flags, + error =dlm_new_lockspace (read_pnet (&sdp->net), fsname, cluster, flags,GDLM_LVB_SIZE , &gdlm_lockspace_ops, sdp, &ops_result, &ls->ls_dlm);if (error) {
fs/gfs2/ops_fstype.c +5 -0
@@ -64,6 +64,8 @@ static void gfs2_tune_init(struct gfs2_tune *gt)void free_sbd (struct gfs2_sbd *sdp) { +put_net_track (read_pnet (&sdp->net), &sdp->tracker); +if (sdp->sd_lkstats)free_percpu (sdp->sd_lkstats);kfree (sdp);
@@ -71,6 +73,7 @@ void free_sbd(struct gfs2_sbd *sdp)static struct gfs2_sbd *init_sbd (struct super_block *sb) { +struct net *net = current->nsproxy->net_ns;struct gfs2_sbd *sdp;struct address_space *mapping;
@@ -78,6 +81,8 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)if (!sdp)return NULL ; +/* store the net-namespace the sdp is created into */ +write_pnet (&sdp->net,get_net_track (net, &sdp->tracker,GFP_KERNEL )); sdp->sd_vfs = sb; sdp->sd_lkstats = alloc_percpu(struct gfs2_pcpu_lkstats);if (!sdp->sd_lkstats)
fs/gfs2/sys.c +26 -1
@@ -16,6 +16,7 @@#include <linux/uaccess.h> #include <linux/gfs2_ondisk.h> #include <linux/blkdev.h> +#include <linux/netdevice.h> #include "gfs2.h" #include "incore.h"
@@ -57,6 +58,20 @@ static const struct sysfs_ops gfs2_attr_ops = {static struct kset *gfs2_kset; +/* gfs2 sysfs is separated by net-namespaces */ +static const struct kobj_ns_type_operations * +gfs2_sysfs_object_child_ns_type (const struct kobject *kobj) +{ +return &net_ns_type_operations; +} + +static const struct kobj_type gfs2_kset_ktype = { + .sysfs_ops = &kobj_sysfs_ops, + .release = kset_release, + .get_ownership = kset_get_ownership, + .child_ns_type = gfs2_sysfs_object_child_ns_type, +}; +static ssize_t id_show (struct gfs2_sbd *sdp,char *buf) { return snprintf(buf, PAGE_SIZE, "%u:%u\n",
@@ -383,10 +398,19 @@ static void gfs2_sbd_release(struct kobject *kobj)complete (&sdp->sd_kobj_unregister); } +/* return the net-namespace the kobj belonging to */ +static const void *gfs2_kobj_namespace (const struct kobject *kobj) +{ + struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); + +return read_pnet (&sdp->net); +} +static struct kobj_type gfs2_ktype = { .release = gfs2_sbd_release, .default_groups = gfs2_groups, .sysfs_ops = &gfs2_attr_ops, + .namespace = gfs2_kobj_namespace, };
@@ -797,7 +821,8 @@ static const struct kset_uevent_ops gfs2_uevent_ops = {int gfs2_sys_init (void ) { - gfs2_kset =kset_create_and_add ("gfs2" , &gfs2_uevent_ops, fs_kobj); + gfs2_kset =kset_type_create_and_add ("gfs2" , &gfs2_uevent_ops, + fs_kobj, &gfs2_kset_ktype);if (!gfs2_kset)return -ENOMEM ;return 0 ;
Signature · 1 line
2.43.0