xfs: xfs_trans_alloc_empty
authorChristoph Hellwig <hch@lst.de>
Sat, 3 Jun 2017 13:18:31 +0000 (15:18 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Jun 2017 10:07:52 +0000 (12:07 +0200)
This is a partial cherry-pick of commit e89c041338
("xfs: implement the GETFSMAP ioctl"), which also adds this helper, and
a great example of why feature patches should be properly split into
their parts.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
[hch: split from the larger patch for -stable]
Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_trans.c
fs/xfs/xfs_trans.h

index 70f42ea86dfbd4a7de39d0709ee4a90e59f0a758..a280e126491fd631584630991805ad9f9ba50e49 100644 (file)
@@ -262,6 +262,28 @@ xfs_trans_alloc(
        return 0;
 }
 
+/*
+ * Create an empty transaction with no reservation.  This is a defensive
+ * mechanism for routines that query metadata without actually modifying
+ * them -- if the metadata being queried is somehow cross-linked (think a
+ * btree block pointer that points higher in the tree), we risk deadlock.
+ * However, blocks grabbed as part of a transaction can be re-grabbed.
+ * The verifiers will notice the corrupt block and the operation will fail
+ * back to userspace without deadlocking.
+ *
+ * Note the zero-length reservation; this transaction MUST be cancelled
+ * without any dirty data.
+ */
+int
+xfs_trans_alloc_empty(
+       struct xfs_mount                *mp,
+       struct xfs_trans                **tpp)
+{
+       struct xfs_trans_res            resv = {0};
+
+       return xfs_trans_alloc(mp, &resv, 0, 0, XFS_TRANS_NO_WRITECOUNT, tpp);
+}
+
 /*
  * Record the indicated change to the given field for application
  * to the file system's superblock when the transaction commits.
index 61b7fbdd3ebddfd1ebd20641753a87d292521508..98024cb933efae8ceeb9e7768519aa4fad5205fe 100644 (file)
@@ -159,6 +159,8 @@ typedef struct xfs_trans {
 int            xfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp,
                        uint blocks, uint rtextents, uint flags,
                        struct xfs_trans **tpp);
+int            xfs_trans_alloc_empty(struct xfs_mount *mp,
+                       struct xfs_trans **tpp);
 void           xfs_trans_mod_sb(xfs_trans_t *, uint, int64_t);
 
 struct xfs_buf *xfs_trans_get_buf_map(struct xfs_trans *tp,