]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_{db,repair}: implement new attr hash value function
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:19 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:11 +0000 (17:01 -0700)
Port existing utilities to use libxfs_attr_hashname instead of calling
libxfs_da_hashname directly.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
db/hash.c
db/metadump.c
libxfs/libxfs_api_defs.h
repair/attr_repair.c

index 9b3fdea6c413643799423adab1531fd0ede32ca4..1500a6032fd75affd4263d289277aa7f51aceab8 100644 (file)
--- a/db/hash.c
+++ b/db/hash.c
@@ -73,7 +73,7 @@ hash_f(
                if (use_dir2_hash)
                        hashval = libxfs_dir2_hashname(mp, &xname);
                else
-                       hashval = libxfs_da_hashname(xname.name, xname.len);
+                       hashval = libxfs_attr_hashname(xname.name, xname.len);
                dbprintf("0x%x\n", hashval);
        }
 
@@ -306,7 +306,7 @@ collide_xattrs(
        unsigned long           i;
        int                     error = 0;
 
-       old_hash = libxfs_da_hashname((uint8_t *)name, namelen);
+       old_hash = libxfs_attr_hashname((uint8_t *)name, namelen);
 
        if (fd >= 0) {
                /*
@@ -331,8 +331,8 @@ collide_xattrs(
                snprintf(xattrname, MAXNAMELEN + 5, "user.%s", name);
                obfuscate_name(old_hash, namelen, (uint8_t *)xattrname + 5,
                                false);
-               ASSERT(old_hash == libxfs_da_hashname((uint8_t *)xattrname + 5,
-                               namelen));
+               ASSERT(old_hash == libxfs_attr_hashname(
+                                       (uint8_t *)xattrname + 5, namelen));
 
                if (fd >= 0) {
                        error = fsetxattr(fd, xattrname, "1", 1, 0);
index 9457e02e828865eaedeece7bcc9a2255c91fc094..c1bf5d00275148386b41128b76531670f4ec4d2b 100644 (file)
@@ -835,7 +835,7 @@ dirattr_hashname(
                return libxfs_dir2_hashname(mp, &xname);
        }
 
-       return libxfs_da_hashname(name, namelen);
+       return libxfs_attr_hashname(name, namelen);
 }
 
 static void
@@ -982,9 +982,9 @@ obfuscate_path_components(
                if (!slash) {
                        /* last (or single) component */
                        namelen = strnlen((char *)comp, len);
-                       hash = libxfs_da_hashname(comp, namelen);
+                       hash = dirattr_hashname(true, comp, namelen);
                        obfuscate_name(hash, namelen, comp, false);
-                       ASSERT(hash == libxfs_da_hashname(comp, namelen));
+                       ASSERT(hash == dirattr_hashname(true, comp, namelen));
                        break;
                }
                namelen = slash - (char *)comp;
@@ -994,9 +994,9 @@ obfuscate_path_components(
                        len--;
                        continue;
                }
-               hash = libxfs_da_hashname(comp, namelen);
+               hash = dirattr_hashname(true, comp, namelen);
                obfuscate_name(hash, namelen, comp, false);
-               ASSERT(hash == libxfs_da_hashname(comp, namelen));
+               ASSERT(hash == dirattr_hashname(true, comp, namelen));
                comp += namelen + 1;
                len -= namelen + 1;
        }
index 2d858580abfe29f4b8cba498ee03ef7959a388e4..c36a6ac81a7b0fa06b2f3623e8a009d66a99917b 100644 (file)
@@ -38,6 +38,8 @@
 
 #define xfs_attr_check_namespace       libxfs_attr_check_namespace
 #define xfs_attr_get                   libxfs_attr_get
+#define xfs_attr_hashname              libxfs_attr_hashname
+#define xfs_attr_hashval               libxfs_attr_hashval
 #define xfs_attr_leaf_newentsize       libxfs_attr_leaf_newentsize
 #define xfs_attr_namecheck             libxfs_attr_namecheck
 #define xfs_attr_set                   libxfs_attr_set
index 37b5852b885ebb3ff8a07d4768af579f731c1596..8321c9b679b2f81601af0024f41ad3b0413305ee 100644 (file)
@@ -485,6 +485,7 @@ process_leaf_attr_local(
        xfs_ino_t               ino)
 {
        xfs_attr_leaf_name_local_t *local;
+       xfs_dahash_t            computed;
 
        local = xfs_attr3_leaf_name_local(leaf, i);
        if (local->namelen == 0 ||
@@ -504,9 +505,12 @@ process_leaf_attr_local(
         * ordering anyway in case both the name value and the
         * hashvalue were wrong but matched. Unlikely, however.
         */
-       if (be32_to_cpu(entry->hashval) != libxfs_da_hashname(
-                               &local->nameval[0], local->namelen) ||
-                               be32_to_cpu(entry->hashval) < last_hashval) {
+       computed = libxfs_attr_hashval(mp, entry->flags, local->nameval,
+                                      local->namelen,
+                                      local->nameval + local->namelen,
+                                      be16_to_cpu(local->valuelen));
+       if (be32_to_cpu(entry->hashval) != computed ||
+           be32_to_cpu(entry->hashval) < last_hashval) {
                do_warn(
        _("bad hashvalue for attribute entry %d in attr block %u, inode %" PRIu64 "\n"),
                        i, da_bno, ino);
@@ -540,15 +544,17 @@ process_leaf_attr_remote(
 {
        xfs_attr_leaf_name_remote_t *remotep;
        char*                   value;
+       xfs_dahash_t            computed;
 
        remotep = xfs_attr3_leaf_name_remote(leaf, i);
 
+       computed = libxfs_attr_hashval(mp, entry->flags, remotep->name,
+                                      remotep->namelen, NULL,
+                                      be32_to_cpu(remotep->valuelen));
        if (remotep->namelen == 0 ||
            !libxfs_attr_namecheck(entry->flags, remotep->name,
                                   remotep->namelen) ||
-           be32_to_cpu(entry->hashval) !=
-                       libxfs_da_hashname((unsigned char *)&remotep->name[0],
-                                          remotep->namelen) ||
+           be32_to_cpu(entry->hashval) != computed ||
            be32_to_cpu(entry->hashval) < last_hashval ||
            be32_to_cpu(remotep->valueblk) == 0) {
                do_warn(