]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: move transaction code to trans.c
authorDave Chinner <dchinner@redhat.com>
Wed, 4 Sep 2013 22:05:30 +0000 (22:05 +0000)
committerRich Johnston <rjohnston@sgi.com>
Mon, 16 Sep 2013 20:14:43 +0000 (15:14 -0500)
There is very little code left in xfs_trans.c. So little it is not
worthtrying to share this file with kernel space any more. Move the
code to libxfs/trans.c, and remove libxfs/xfs_trans.c.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Review-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Rich Johnston <rjohnston@sgi.com>
libxfs/Makefile
libxfs/trans.c
libxfs/xfs.h
libxfs/xfs_trans.c [deleted file]

index b19ff6cc18e6e81b269a8ca9cefee5d1bbf715c0..64b5979bc1195c26a6cf692025b019ef16975a6f 100644 (file)
@@ -19,7 +19,6 @@ CFILES = cache.c init.c kmem.c logitem.c radix-tree.c rdwr.c trans.c util.c \
        xfs_mount.c xfs_rtalloc.c xfs_attr.c xfs_attr_remote.c \
        crc32.c \
        xfs_symlink.c \
-       xfs_trans.c \
        xfs_trans_resv.c
 
 CFILES += $(PKG_PLATFORM).c
index 645952cda4e28d008e1824a21314dc2234c4fe51..d0a91b18b9d1b174356ccf7631c90299794447b1 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2000-2001,2005-2006 Silicon Graphics, Inc.
+ * Copyright (C) 2010 Red Hat, Inc.
  * All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or
  * Simple transaction interface
  */
 
+kmem_zone_t    *xfs_log_item_desc_zone;
+
+/*
+ * Initialize the precomputed transaction reservation values
+ * in the mount structure.
+ */
+void
+libxfs_trans_init(
+       struct xfs_mount        *mp)
+{
+       xfs_trans_resv_calc(mp, &mp->m_reservations);
+}
+
+/*
+ * Add the given log item to the transaction's list of log items.
+ *
+ * The log item will now point to its new descriptor with its li_desc field.
+ */
+void
+libxfs_trans_add_item(
+       struct xfs_trans        *tp,
+       struct xfs_log_item     *lip)
+{
+       struct xfs_log_item_desc *lidp;
+
+       ASSERT(lip->li_mountp == tp->t_mountp);
+       ASSERT(lip->li_ailp == tp->t_mountp->m_ail);
+
+       lidp = calloc(sizeof(struct xfs_log_item_desc), 1);
+       if (!lidp) {
+               fprintf(stderr, _("%s: lidp calloc failed (%d bytes): %s\n"),
+                       progname, (int)sizeof(struct xfs_log_item_desc),
+                       strerror(errno));
+               exit(1);
+       }
+
+       lidp->lid_item = lip;
+       lidp->lid_flags = 0;
+       list_add_tail(&lidp->lid_trans, &tp->t_items);
+
+       lip->li_desc = lidp;
+}
+
+/*
+ * Unlink and free the given descriptor.
+ */
+void
+libxfs_trans_del_item(
+       struct xfs_log_item     *lip)
+{
+       list_del_init(&lip->li_desc->lid_trans);
+       free(lip->li_desc);
+       lip->li_desc = NULL;
+}
+
+/*
+ * Roll from one trans in the sequence of PERMANENT transactions to
+ * the next: permanent transactions are only flushed out when
+ * committed with XFS_TRANS_RELEASE_LOG_RES, but we still want as soon
+ * as possible to let chunks of it go to the log. So we commit the
+ * chunk we've been working on and get a new transaction to continue.
+ */
+int
+libxfs_trans_roll(
+       struct xfs_trans        **tpp,
+       struct xfs_inode        *dp)
+{
+       struct xfs_trans        *trans;
+       unsigned int            logres, count;
+       int                     error;
+
+       /*
+        * Ensure that the inode is always logged.
+        */
+       trans = *tpp;
+       xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
+
+       /*
+        * Copy the critical parameters from one trans to the next.
+        */
+       logres = trans->t_log_res;
+       count = trans->t_log_count;
+       *tpp = xfs_trans_dup(trans);
+
+       /*
+        * Commit the current transaction.
+        * If this commit failed, then it'd just unlock those items that
+        * are not marked ihold. That also means that a filesystem shutdown
+        * is in progress. The caller takes the responsibility to cancel
+        * the duplicate transaction that gets returned.
+        */
+       error = xfs_trans_commit(trans, 0);
+       if (error)
+               return (error);
+
+       trans = *tpp;
+
+       /*
+        * Reserve space in the log for th next transaction.
+        * This also pushes items in the "AIL", the list of logged items,
+        * out to disk if they are taking up space at the tail of the log
+        * that we want to use.  This requires that either nothing be locked
+        * across this call, or that anything that is locked be logged in
+        * the prior and the next transactions.
+        */
+       error = xfs_trans_reserve(trans, 0, logres, 0,
+                                 XFS_TRANS_PERM_LOG_RES, count);
+       /*
+        *  Ensure that the inode is in the new transaction and locked.
+        */
+       if (error)
+               return error;
+
+       xfs_trans_ijoin(trans, dp, 0);
+       return 0;
+}
+
 xfs_trans_t *
 libxfs_trans_alloc(
        xfs_mount_t     *mp,
index 66fca85fb49b343a9be4cdc8469dd7855caa540e..7149c0902dc1d56dc7e6294b65dd29d063658fe4 100644 (file)
@@ -235,12 +235,14 @@ roundup_pow_of_two(uint v)
 #define xfs_mod_incore_sb              libxfs_mod_incore_sb
 
 #define xfs_trans_alloc                        libxfs_trans_alloc
+#define xfs_trans_add_item             libxfs_trans_add_item
 #define xfs_trans_bhold                        libxfs_trans_bhold
 #define xfs_trans_binval               libxfs_trans_binval
 #define xfs_trans_bjoin                        libxfs_trans_bjoin
 #define xfs_trans_brelse               libxfs_trans_brelse
 #define xfs_trans_commit               libxfs_trans_commit
 #define xfs_trans_cancel               libxfs_trans_cancel
+#define xfs_trans_del_item             libxfs_trans_del_item
 #define xfs_trans_dup                  libxfs_trans_dup
 #define xfs_trans_get_buf              libxfs_trans_get_buf
 #define xfs_trans_getsb                        libxfs_trans_getsb
@@ -248,12 +250,14 @@ roundup_pow_of_two(uint v)
 #define xfs_trans_ihold                        libxfs_trans_ihold
 #define xfs_trans_ijoin                        libxfs_trans_ijoin
 #define xfs_trans_ijoin_ref            libxfs_trans_ijoin_ref
+#define xfs_trans_init                 libxfs_trans_init
 #define xfs_trans_inode_alloc_buf      libxfs_trans_inode_alloc_buf
 #define xfs_trans_log_buf              libxfs_trans_log_buf
 #define xfs_trans_log_inode            libxfs_trans_log_inode
 #define xfs_trans_mod_sb               libxfs_trans_mod_sb
 #define xfs_trans_read_buf             libxfs_trans_read_buf
 #define xfs_trans_read_buf_map         libxfs_trans_read_buf_map
+#define xfs_trans_roll                 libxfs_trans_roll
 #define xfs_trans_get_buf_map          libxfs_trans_get_buf_map
 #define xfs_trans_reserve              libxfs_trans_reserve
 
@@ -373,6 +377,8 @@ void xfs_mount_common(xfs_mount_t *, xfs_sb_t *);
 /*
  * logitem.c and trans.c prototypes
  */
+void xfs_trans_init(struct xfs_mount *);
+int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *);
 
 /* xfs_trans_item.c */
 void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
diff --git a/libxfs/xfs_trans.c b/libxfs/xfs_trans.c
deleted file mode 100644 (file)
index 2daf545..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
- * Copyright (C) 2010 Red Hat, 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 <xfs.h>
-
-kmem_zone_t    *xfs_trans_zone;
-kmem_zone_t    *xfs_log_item_desc_zone;
-
-/*
- * Initialize the precomputed transaction reservation values
- * in the mount structure.
- */
-void
-xfs_trans_init(
-       struct xfs_mount        *mp)
-{
-       xfs_trans_resv_calc(mp, &mp->m_reservations);
-}
-
-/*
- * Add the given log item to the transaction's list of log items.
- *
- * The log item will now point to its new descriptor with its li_desc field.
- */
-void
-xfs_trans_add_item(
-       struct xfs_trans        *tp,
-       struct xfs_log_item     *lip)
-{
-       struct xfs_log_item_desc *lidp;
-
-       ASSERT(lip->li_mountp == tp->t_mountp);
-       ASSERT(lip->li_ailp == tp->t_mountp->m_ail);
-
-       lidp = kmem_zone_zalloc(xfs_log_item_desc_zone, KM_SLEEP | KM_NOFS);
-
-       lidp->lid_item = lip;
-       lidp->lid_flags = 0;
-       list_add_tail(&lidp->lid_trans, &tp->t_items);
-
-       lip->li_desc = lidp;
-}
-
-STATIC void
-xfs_trans_free_item_desc(
-       struct xfs_log_item_desc *lidp)
-{
-       list_del_init(&lidp->lid_trans);
-       kmem_zone_free(xfs_log_item_desc_zone, lidp);
-}
-
-/*
- * Unlink and free the given descriptor.
- */
-void
-xfs_trans_del_item(
-       struct xfs_log_item     *lip)
-{
-       xfs_trans_free_item_desc(lip->li_desc);
-       lip->li_desc = NULL;
-}
-
-/*
- * Roll from one trans in the sequence of PERMANENT transactions to
- * the next: permanent transactions are only flushed out when
- * committed with XFS_TRANS_RELEASE_LOG_RES, but we still want as soon
- * as possible to let chunks of it go to the log. So we commit the
- * chunk we've been working on and get a new transaction to continue.
- */
-int
-xfs_trans_roll(
-       struct xfs_trans        **tpp,
-       struct xfs_inode        *dp)
-{
-       struct xfs_trans        *trans;
-       unsigned int            logres, count;
-       int                     error;
-
-       /*
-        * Ensure that the inode is always logged.
-        */
-       trans = *tpp;
-       xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
-
-       /*
-        * Copy the critical parameters from one trans to the next.
-        */
-       logres = trans->t_log_res;
-       count = trans->t_log_count;
-       *tpp = xfs_trans_dup(trans);
-
-       /*
-        * Commit the current transaction.
-        * If this commit failed, then it'd just unlock those items that
-        * are not marked ihold. That also means that a filesystem shutdown
-        * is in progress. The caller takes the responsibility to cancel
-        * the duplicate transaction that gets returned.
-        */
-       error = xfs_trans_commit(trans, 0);
-       if (error)
-               return (error);
-
-       trans = *tpp;
-
-       /*
-        * Reserve space in the log for th next transaction.
-        * This also pushes items in the "AIL", the list of logged items,
-        * out to disk if they are taking up space at the tail of the log
-        * that we want to use.  This requires that either nothing be locked
-        * across this call, or that anything that is locked be logged in
-        * the prior and the next transactions.
-        */
-       error = xfs_trans_reserve(trans, 0, logres, 0,
-                                 XFS_TRANS_PERM_LOG_RES, count);
-       /*
-        *  Ensure that the inode is in the new transaction and locked.
-        */
-       if (error)
-               return error;
-
-       xfs_trans_ijoin(trans, dp, 0);
-       return 0;
-}