]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: add spinlock_t wrapper
authorDave Chinner <dchinner@redhat.com>
Wed, 29 Sep 2021 20:48:29 +0000 (16:48 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Wed, 29 Sep 2021 20:48:29 +0000 (16:48 -0400)
These provide the kernel spinlock_t interface, but are *not*
spinlocks. Spinlocks cannot be used by general purpose userspace
processes due to the fact they cannot control task preemption and
scheduling reliability. Hence these are implemented as a
pthread_mutex_t, similar to the way the kernel RT build implements
spinlock_t as a kernel mutex.

Because the current libxfs spinlock "implementation" just makes
spinlocks go away, we have to also add initialisation to spinlocks
that libxfs uses that are missing from the userspace implementation.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
[chandan.babu@oracle.com: Initialize inode log item spin lock]
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
[sandeen: fix minor whitespace]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/Makefile
include/libxfs.h
include/spinlock.h [new file with mode: 0644]
include/xfs_inode.h
include/xfs_mount.h
include/xfs_trans.h
libxfs/init.c
libxfs/libxfs_priv.h
libxfs/logitem.c
libxfs/rdwr.c

index 632b819fcded9104f12de8ef2ee642427dd8427c..f7c40a5ce1a1c245cb42fb3fc5e436d6699ac35d 100644 (file)
@@ -16,6 +16,7 @@ LIBHFILES = libxfs.h \
        kmem.h \
        list.h \
        parent.h \
+       spinlock.h \
        xfs_inode.h \
        xfs_log_recover.h \
        xfs_metadump.h \
index bc07655e64f1e1767981f5274d46b44f7b503238..a494a1d4b0026a33d544b05cc3e1fabdc1a6ce07 100644 (file)
@@ -18,6 +18,7 @@
 #include "kmem.h"
 #include "libfrog/radix-tree.h"
 #include "atomic.h"
+#include "spinlock.h"
 
 #include "xfs_types.h"
 #include "xfs_fs.h"
diff --git a/include/spinlock.h b/include/spinlock.h
new file mode 100644 (file)
index 0000000..8297372
--- /dev/null
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019-20 RedHat, Inc.
+ * All Rights Reserved.
+ */
+#ifndef __LIBXFS_SPINLOCK_H__
+#define __LIBXFS_SPINLOCK_H__
+
+/*
+ * This implements kernel compatible spinlock exclusion semantics. These,
+ * however, are not spinlocks, as spinlocks cannot be reliably implemented in
+ * userspace without using realtime scheduling task contexts. Hence this
+ * interface is implemented with pthread mutexes and so can block, but this is
+ * no different to the kernel RT build which replaces spinlocks with mutexes.
+ * Hence we know it works.
+ */
+
+typedef pthread_mutex_t        spinlock_t;
+
+#define spin_lock_init(l)      pthread_mutex_init(l, NULL)
+#define spin_lock(l)           pthread_mutex_lock(l)
+#define spin_trylock(l)                (pthread_mutex_trylock(l) != EBUSY)
+#define spin_unlock(l)         pthread_mutex_unlock(l)
+
+#endif /* __LIBXFS_SPINLOCK_H__ */
index 0551fe457d0ca0258a2f073bf4ea63d77fcf8aac..08a62d833372bfaebad3afe7c0999ac30335dcd5 100644 (file)
@@ -43,6 +43,7 @@ struct inode {
        struct timespec64       i_atime;
        struct timespec64       i_mtime;
        struct timespec64       i_ctime;
+       spinlock_t              i_lock;
 };
 
 static inline uint32_t i_uid_read(struct inode *inode)
index 12019c4b4dbd7e618d8a25455bf79457d5d8fc4c..2f32088025752cdceca092d08a80b36312e4e567 100644 (file)
@@ -22,6 +22,7 @@ typedef struct xfs_mount {
 #define m_icount       m_sb.sb_icount
 #define m_ifree                m_sb.sb_ifree
 #define m_fdblocks     m_sb.sb_fdblocks
+       spinlock_t              m_sb_lock;
 
        /*
         * Bitsets of per-fs metadata that have been checked and/or are sick.
@@ -32,6 +33,7 @@ typedef struct xfs_mount {
 
        char                    *m_fsname;      /* filesystem name */
        int                     m_bsize;        /* fs logical block size */
+       spinlock_t              m_agirotor_lock;
        xfs_agnumber_t          m_agfrotor;     /* last ag where space found */
        xfs_agnumber_t          m_agirotor;     /* last ag dir inode alloced */
        xfs_agnumber_t          m_maxagi;       /* highest inode alloc group */
index ad76ecfddebc9e6e11eea4506a33764e5f158742..2c55bb8573699b0091aa4ecb8fa03582bb34e7c9 100644 (file)
@@ -35,6 +35,7 @@ struct xfs_inode_log_item {
        unsigned int            ili_last_fields;        /* fields when flushed*/
        unsigned int            ili_fields;             /* fields to be logged */
        unsigned int            ili_fsync_fields;       /* ignored by userspace */
+       spinlock_t              ili_lock;
 };
 
 typedef struct xfs_buf_log_item {
index b06faf8acddeee4398a2296ae73cf83a55e48ff3..2c54546bcdda132429586362d2103ce4e7aeb061 100644 (file)
@@ -743,7 +743,9 @@ libxfs_mount(
        mp->m_flags = (LIBXFS_MOUNT_32BITINODES|LIBXFS_MOUNT_32BITINOOPT);
        mp->m_sb = *sb;
        INIT_RADIX_TREE(&mp->m_perag_tree, GFP_KERNEL);
-       sbp = &(mp->m_sb);
+       sbp = &mp->m_sb;
+       spin_lock_init(&mp->m_sb_lock);
+       spin_lock_init(&mp->m_agirotor_lock);
 
        xfs_sb_mount_common(mp, sb);
 
index db90e173f36e8740ebadb5004acde8215427d3d5..e1e90268c0b7616da1d8606a01c2e561f6d4f570 100644 (file)
@@ -48,6 +48,7 @@
 #include "kmem.h"
 #include "libfrog/radix-tree.h"
 #include "atomic.h"
+#include "spinlock.h"
 
 #include "xfs_types.h"
 #include "xfs_arch.h"
@@ -205,9 +206,6 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 #endif
 
 /* miscellaneous kernel routines not in user space */
-#define spin_lock_init(a)      ((void) 0)
-#define spin_lock(a)           ((void) 0)
-#define spin_unlock(a)         ((void) 0)
 #define likely(x)              (x)
 #define unlikely(x)            (x)
 
index 4d4e8080dffc8ce3915ca7d9a2398dc3d0dcdc9b..b073cdb493e608b55012e96858f0feadf7bafc5d 100644 (file)
@@ -144,6 +144,8 @@ xfs_inode_item_init(
                ip->i_ino, iip);
 #endif
 
-       xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE);
+       spin_lock_init(&iip->ili_lock);
+
+        xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE);
        iip->ili_inode = ip;
 }
index 713ef9afc8c61df90f936659fdf716462304cfe2..a5fd0596687e3b0a167c82840d874047f4bb2ad7 100644 (file)
@@ -1070,6 +1070,8 @@ libxfs_iget(
        VFS_I(ip)->i_count = 1;
        ip->i_ino = ino;
        ip->i_mount = mp;
+       spin_lock_init(&VFS_I(ip)->i_lock);
+
        error = xfs_imap(mp, tp, ip->i_ino, &ip->i_imap, 0);
        if (error)
                goto out_destroy;