bcachefs: qstr_eq()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 17 Dec 2023 02:16:34 +0000 (21:16 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Jan 2024 16:47:41 +0000 (11:47 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/dirent.c
fs/bcachefs/fsck.c
fs/bcachefs/util.h

index 580c1c95361e433684498f44759901b65cb51faf..78ce9634d05c127833cf2220e330c0c210e93305 100644 (file)
@@ -65,7 +65,7 @@ static bool dirent_cmp_key(struct bkey_s_c _l, const void *_r)
        const struct qstr l_name = bch2_dirent_get_name(l);
        const struct qstr *r_name = _r;
 
-       return l_name.len - r_name->len ?: memcmp(l_name.name, r_name->name, l_name.len);
+       return !qstr_eq(l_name, *r_name);
 }
 
 static bool dirent_cmp_bkey(struct bkey_s_c _l, struct bkey_s_c _r)
@@ -75,7 +75,7 @@ static bool dirent_cmp_bkey(struct bkey_s_c _l, struct bkey_s_c _r)
        const struct qstr l_name = bch2_dirent_get_name(l);
        const struct qstr r_name = bch2_dirent_get_name(r);
 
-       return l_name.len - r_name.len ?: memcmp(l_name.name, r_name.name, l_name.len);
+       return !qstr_eq(l_name, r_name);
 }
 
 static bool dirent_is_visible(subvol_inum inum, struct bkey_s_c k)
index 7023c2800d59d9f7159903535bbfb5a0e4c2e78a..43801e29bc5abe5c2c3ca5e92ae4a9d9f98153bd 100644 (file)
@@ -20,8 +20,6 @@
 #include <linux/bsearch.h>
 #include <linux/dcache.h> /* struct qstr */
 
-#define QSTR(n) { { { .len = strlen(n) } }, .name = n }
-
 /*
  * XXX: this is handling transaction restarts without returning
  * -BCH_ERR_transaction_restart_nested, this is not how we do things anymore:
index 7eb567ab4457928b5ede415e6470d04304273a4d..1ff063bb87416a83fd0823e62e044eabe7a6204f 100644 (file)
@@ -856,4 +856,11 @@ static inline int cmp_le32(__le32 l, __le32 r)
 
 #include <linux/uuid.h>
 
+#define QSTR(n) { { { .len = strlen(n) } }, .name = n }
+
+static inline bool qstr_eq(const struct qstr l, const struct qstr r)
+{
+       return l.len == r.len && !memcmp(l.name, r.name, l.len);
+}
+
 #endif /* _BCACHEFS_UTIL_H */