Skip to contentSkip to conversation

erofs-utils: lib: introduce mutex & rwlock wrappers

PATCH New Gao Xiang 1 participant 2 messages Jun 18, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs-utils: lib: introduce mutex & rwlock wrappers

To avoid too many #ifdef EROFS_MT_ENABLEDs.

---
 include/erofs/lock.h | 44 +++++++++++++++++++++++++++++++++++++++++++
 lib/fragments.c      | 45 ++++++++++++++------------------------------
 2 files changed, 58 insertions(+), 31 deletions(-)
 create mode 100644 include/erofs/lock.h
include/erofs/lock.h new file +44 -0
new file mode 100644
index 0000000..f7a4b47
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
+#ifndef __EROFS_LOCK_H
+#define __EROFS_LOCK_H
+
+#include "defs.h"
+
+#if defined(HAVE_PTHREAD_H) && defined(EROFS_MT_ENABLED)
+#include <pthread.h>
+
+typedef pthread_mutex_t erofs_mutex_t;
+
+static inline void erofs_mutex_init(erofs_mutex_t *lock)
+{
+	pthread_mutex_init(lock, NULL);
+}
+#define erofs_mutex_lock	pthread_mutex_lock
+#define erofs_mutex_unlock	pthread_mutex_unlock
+
+typedef pthread_rwlock_t erofs_rwsem_t;
+
+static inline void erofs_init_rwsem(erofs_rwsem_t *lock)
+{
+	pthread_rwlock_init(lock, NULL);
+}
+#define erofs_down_read		pthread_rwlock_rdlock
+#define erofs_down_write	pthread_rwlock_wrlock
+#define erofs_up_read		pthread_rwlock_unlock
+#define erofs_up_write		pthread_rwlock_unlock
+#else
+typedef struct {} erofs_mutex_t;
+
+static inline void erofs_mutex_init(erofs_mutex_t *lock) {}
+static inline void erofs_mutex_lock(erofs_mutex_t *lock) {}
+static inline void erofs_mutex_unlock(erofs_mutex_t *lock) {}
+
+typedef struct {} erofs_rwsem_t;
+static inline void erofs_init_rwsem(erofs_rwsem_t *lock) {}
+static inline void erofs_down_read(erofs_rwsem_t *lock) {}
+static inline void erofs_down_write(erofs_rwsem_t *lock) {}
+static inline void erofs_up_read(erofs_rwsem_t *lock) {}
+static inline void erofs_up_write(erofs_rwsem_t *lock) {}
+
+#endif
+#endif
lib/fragments.c +14 -31

124 lines not on this page · raw message

Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/2 erofs-utils: lib: refine the inode hash table

- Increase the hash table entries to 65536;
- Protect the hash table with erofs_rwsem.

---
 include/erofs/inode.h |  2 +-
 lib/inode.c           | 65 +++++++++++++++++++++++--------------------
 lib/rebuild.c         |  2 +-
 3 files changed, 37 insertions(+), 32 deletions(-)
include/erofs/inode.h +1 -1
index eb8f45b..fe86101 100644
@@ -27,8 +27,8 @@ umode_t erofs_ftype_to_mode(unsigned int ftype, unsigned int perm);
 unsigned char erofs_ftype_to_dtype(unsigned int filetype);
 void erofs_inode_manager_init(void);
 void erofs_insert_ihash(struct erofs_inode *inode);
+void erofs_remove_ihash(struct erofs_inode *inode);
 struct erofs_inode *erofs_iget(dev_t dev, ino_t ino);
-struct erofs_inode *erofs_iget_by_nid(erofs_nid_t nid);
 unsigned int erofs_iput(struct erofs_inode *inode);
 erofs_nid_t erofs_lookupnid(struct erofs_inode *inode);
 int erofs_iflush(struct erofs_inode *inode);
lib/inode.c +35 -30

118 lines not on this page · raw message

lib/rebuild.c +1 -1
index 5787bb3..b61af15 100644
@@ -481,7 +481,7 @@ static int erofs_rebuild_basedir_dirent_iter(struct erofs_dir_context *ctx)
 		if (S_ISDIR(inode->i_mode) &&
 		    (ctx->de_ftype == EROFS_FT_DIR ||
 		     ctx->de_ftype == EROFS_FT_UNKNOWN)) {
-			list_del(&inode->i_hash);
+			erofs_remove_ihash(inode);
 			inode->dev = dir->sbi->dev;
 			inode->i_ino[1] = ctx->de_nid;
 			erofs_insert_ihash(inode);
Signature · 1 line
2.43.5