]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_{db,repair}: implement new attr hash value function
authorDarrick J. Wong <djwong@kernel.org>
Tue, 26 Mar 2024 22:01:44 +0000 (15:01 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 10 Apr 2024 00:21:29 +0000 (17:21 -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>
db/hash.c
db/metadump.c
libxfs/libxfs_api_defs.h
repair/attr_repair.c

index 05a94f249c3d6417e8d59e0deaa2805eb6563c5b..5009533de951d1f61ef90ed8373aacf867e49d54 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;
 
-       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 a656ef574a7e44b29d54b1891e8bf972a4d44919..24a7d5ea0653f30110631afdc6629b208f4e67ac 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 70f234e20605e36393c14a1b99b5adb4164c0f72..71cd43d97672b682c9dad1a5014b4a4dababfcba 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 b2bac89bd44c606a2ae39af813525a43f080925b..a13df24526c08639be29a6eef1205ca42be53fc0 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(