]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/xfs_inode_fork.c
xfs: fix transaction leak on remote attr set/remove failure
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_inode_fork.c
index 750d339e7f1ae318942e4c12e03c3e6cbb24a31b..3d64fd46fb87c646f60974aaf29c53c1dd284cd5 100644 (file)
@@ -1,19 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 #include "libxfs_priv.h"
 #include "xfs_fs.h"
@@ -192,8 +180,9 @@ xfs_iformat_local(
        "corrupt inode %Lu (bad size %d for local fork, size = %d).",
                        (unsigned long long) ip->i_ino, size,
                        XFS_DFORK_SIZE(dip, ip->i_mount, whichfork));
-               XFS_CORRUPTION_ERROR("xfs_iformat_local", XFS_ERRLEVEL_LOW,
-                                    ip->i_mount, dip);
+               xfs_inode_verifier_error(ip, -EFSCORRUPTED,
+                               "xfs_iformat_local", dip, sizeof(*dip),
+                               __this_address);
                return -EFSCORRUPTED;
        }
 
@@ -228,8 +217,9 @@ xfs_iformat_extents(
        if (unlikely(size < 0 || size > XFS_DFORK_SIZE(dip, mp, whichfork))) {
                xfs_warn(ip->i_mount, "corrupt inode %Lu ((a)extents = %d).",
                        (unsigned long long) ip->i_ino, nex);
-               XFS_CORRUPTION_ERROR("xfs_iformat_extents(1)", XFS_ERRLEVEL_LOW,
-                                    mp, dip);
+               xfs_inode_verifier_error(ip, -EFSCORRUPTED,
+                               "xfs_iformat_extents(1)", dip, sizeof(*dip),
+                               __this_address);
                return -EFSCORRUPTED;
        }
 
@@ -242,10 +232,14 @@ xfs_iformat_extents(
 
                xfs_iext_first(ifp, &icur);
                for (i = 0; i < nex; i++, dp++) {
+                       xfs_failaddr_t  fa;
+
                        xfs_bmbt_disk_get_all(dp, &new);
-                       if (!xfs_bmbt_validate_extent(mp, whichfork, &new)) {
-                               XFS_ERROR_REPORT("xfs_iformat_extents(2)",
-                                                XFS_ERRLEVEL_LOW, mp);
+                       fa = xfs_bmap_validate_extent(ip, whichfork, &new);
+                       if (fa) {
+                               xfs_inode_verifier_error(ip, -EFSCORRUPTED,
+                                               "xfs_iformat_extents(2)",
+                                               dp, sizeof(*dp), fa);
                                return -EFSCORRUPTED;
                        }
 
@@ -295,14 +289,16 @@ xfs_iformat_btree(
         */
        if (unlikely(XFS_IFORK_NEXTENTS(ip, whichfork) <=
                                        XFS_IFORK_MAXEXT(ip, whichfork) ||
+                    nrecs == 0 ||
                     XFS_BMDR_SPACE_CALC(nrecs) >
                                        XFS_DFORK_SIZE(dip, mp, whichfork) ||
                     XFS_IFORK_NEXTENTS(ip, whichfork) > ip->i_d.di_nblocks) ||
                     level == 0 || level > XFS_BTREE_MAXLEVELS) {
                xfs_warn(mp, "corrupt inode %Lu (btree).",
                                        (unsigned long long) ip->i_ino);
-               XFS_CORRUPTION_ERROR("xfs_iformat_btree", XFS_ERRLEVEL_LOW,
-                                        mp, dip);
+               xfs_inode_verifier_error(ip, -EFSCORRUPTED,
+                               "xfs_iformat_btree", dfp, size,
+                               __this_address);
                return -EFSCORRUPTED;
        }
 
@@ -591,7 +587,7 @@ xfs_iextents_copy(
        for_each_xfs_iext(ifp, &icur, &rec) {
                if (isnullstartblock(rec.br_startblock))
                        continue;
-               ASSERT(xfs_bmbt_validate_extent(ip->i_mount, whichfork, &rec));
+               ASSERT(xfs_bmap_validate_extent(ip, whichfork, &rec) == NULL);
                xfs_bmbt_disk_set_all(dp, &rec);
                trace_xfs_write_extent(ip, &icur, state, _RET_IP_);
                copied += sizeof(struct xfs_bmbt_rec);