public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: xfs@oss.sgi.com
Subject: [PATCH 25/30 V2] libxfs: fix root inode handling inconsistencies
Date: Thu, 31 Oct 2013 15:13:43 +1100	[thread overview]
Message-ID: <20131031041343.GK6188@dastard> (raw)
In-Reply-To: <20131030215940.GH6188@dastard>

From: Dave Chinner <dchinner@redhat.com>

When "mounting" a filesystem via libxfs_mount(), callers can tell
libxfs to read the root and realtime inodes into cache. However,
when unmounting the filesystem, libxfs_unmount() used to
unconditionally free root inodes if they were present.

This leads to interesting issues like in mkfs, when it handles
creation, reading and freeing of the root and rt inodes itself.
It, however, passes in the flag to tell libxfs_mount() to read the
root inode, and so when unmounting throws an error like:

cache_node_put: node put on refcount 0 (node=0x684610)

when a second libxfs_iput() call is made on the root inode.

As it turns out, nothing ever uses mp->m_rootip and so we don't need
to read it in or free it, or even have a pointer to it in the struct
xfs_mount, so kill the m_rootip and LIBXFS_MOUNT_ROOTINOS parameter
completely.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
V2: just kill m_rootino and LIBXFS_MOUNT_ROOTINOS altogether.

 copy/xfs_copy.c  |  2 +-
 db/init.c        | 13 +++++--------
 include/libxfs.h | 12 +++++-------
 libxfs/init.c    | 27 ++++-----------------------
 mkfs/proto.c     |  1 -
 mkfs/xfs_mkfs.c  |  4 ++--
 repair/phase6.c  |  2 --
 7 files changed, 17 insertions(+), 44 deletions(-)

diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index bb37279..9986fbf 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -684,7 +684,7 @@ main(int argc, char **argv)
 	sb = &mbuf.m_sb;
 	libxfs_sb_from_disk(sb, XFS_BUF_TO_SBP(sbp));
 
-	mp = libxfs_mount(&mbuf, sb, xargs.ddev, xargs.logdev, xargs.rtdev, 1);
+	mp = libxfs_mount(&mbuf, sb, xargs.ddev, xargs.logdev, xargs.rtdev, 0);
 	if (mp == NULL) {
 		do_log(_("%s: %s filesystem failed to initialize\n"
 			"%s: Aborting.\n"), progname, source_name, progname);
diff --git a/db/init.c b/db/init.c
index a9b357b..7dd31ca 100644
--- a/db/init.c
+++ b/db/init.c
@@ -144,15 +144,12 @@ init(
 	}
 
 	mp = libxfs_mount(&xmount, sbp, x.ddev, x.logdev, x.rtdev,
-				LIBXFS_MOUNT_ROOTINOS | LIBXFS_MOUNT_DEBUGGER);
+			  LIBXFS_MOUNT_DEBUGGER);
 	if (!mp) {
-		mp = libxfs_mount(&xmount, sbp, x.ddev, x.logdev, x.rtdev,
-				LIBXFS_MOUNT_DEBUGGER);
-		if (!mp) {
-			fprintf(stderr, _("%s: device %s unusable (not an XFS "
-				"filesystem?)\n"), progname, fsdevice);
-			exit(1);
-		}
+		fprintf(stderr,
+			_("%s: device %s unusable (not an XFS filesystem?)\n"),
+			progname, fsdevice);
+		exit(1);
 	}
 	blkbb = 1 << mp->m_blkbb_log;
 
diff --git a/include/libxfs.h b/include/libxfs.h
index d28ac48..169dfc5 100644
--- a/include/libxfs.h
+++ b/include/libxfs.h
@@ -167,7 +167,6 @@ typedef struct xfs_mount {
 	uint			m_rsumsize;	/* size of rt summary, bytes */
 	struct xfs_inode	*m_rbmip;	/* pointer to bitmap inode */
 	struct xfs_inode	*m_rsumip;	/* pointer to summary inode */
-	struct xfs_inode	*m_rootip;	/* pointer to root directory */
 	struct xfs_buftarg	*m_ddev_targp;
 	struct xfs_buftarg	*m_logdev_targp;
 	struct xfs_buftarg	*m_rtdev_targp;
@@ -259,12 +258,11 @@ typedef struct xfs_perag {
 	int		pagb_count;	/* pagb slots in use */
 } xfs_perag_t;
 
-#define LIBXFS_MOUNT_ROOTINOS		0x0001
-#define LIBXFS_MOUNT_DEBUGGER		0x0002
-#define LIBXFS_MOUNT_32BITINODES	0x0004
-#define LIBXFS_MOUNT_32BITINOOPT	0x0008
-#define LIBXFS_MOUNT_COMPAT_ATTR	0x0010
-#define LIBXFS_MOUNT_ATTR2		0x0020
+#define LIBXFS_MOUNT_DEBUGGER		0x0001
+#define LIBXFS_MOUNT_32BITINODES	0x0002
+#define LIBXFS_MOUNT_32BITINOOPT	0x0004
+#define LIBXFS_MOUNT_COMPAT_ATTR	0x0008
+#define LIBXFS_MOUNT_ATTR2		0x0010
 
 #define LIBXFS_IHASHSIZE(sbp)		(1<<10)
 #define LIBXFS_BHASHSIZE(sbp) 		(1<<10)
diff --git a/libxfs/init.c b/libxfs/init.c
index 229aa50..6be0ac4 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -688,8 +688,6 @@ libxfs_mount(
 	libxfs_buftarg_init(mp, dev, logdev, rtdev);
 
 	mp->m_flags = (LIBXFS_MOUNT_32BITINODES|LIBXFS_MOUNT_32BITINOOPT);
-	if (flags & LIBXFS_MOUNT_ROOTINOS)
-		mp->m_flags |= LIBXFS_MOUNT_ROOTINOS;
 
 	mp->m_sb = *sb;
 	INIT_RADIX_TREE(&mp->m_perag_tree, GFP_KERNEL);
@@ -813,30 +811,15 @@ libxfs_mount(
 		exit(1);
 	}
 
-	/*
-	 * mkfs calls mount before the root inode is allocated.
-	 */
-	if ((flags & LIBXFS_MOUNT_ROOTINOS) && sbp->sb_rootino != NULLFSINO) {
-		error = libxfs_iget(mp, NULL, sbp->sb_rootino, 0,
-				&mp->m_rootip, 0);
-		if (error) {
-			fprintf(stderr, _("%s: cannot read root inode (%d)\n"),
-				progname, error);
-			if (!(flags & LIBXFS_MOUNT_DEBUGGER))
-				return NULL;
-		}
-		ASSERT(mp->m_rootip != NULL);
-	}
-	if ((flags & LIBXFS_MOUNT_ROOTINOS) && rtmount_inodes(mp)) {
-		if (mp->m_rootip)
-			libxfs_iput(mp->m_rootip, 0);
+	/* set up the realtime inodes if they exist */
+	error = rtmount_inodes(mp);
+	if (error)
 		return NULL;
-	}
 
 	/*
 	 * mkfs calls mount before the AGF/AGI structures are written.
 	 */
-	if ((flags & LIBXFS_MOUNT_ROOTINOS) && sbp->sb_rootino != NULLFSINO &&
+	if (sbp->sb_rootino != NULLFSINO &&
 	    xfs_sb_version_haslazysbcount(&mp->m_sb)) {
 		error = xfs_initialize_perag_data(mp, sbp->sb_agcount);
 		if (error) {
@@ -869,8 +852,6 @@ libxfs_umount(xfs_mount_t *mp)
 	int			agno;
 
 	libxfs_rtmount_destroy(mp);
-	if ((mp->m_flags & LIBXFS_MOUNT_ROOTINOS) && mp->m_rootip)
-		libxfs_iput(mp->m_rootip, 0);
 	libxfs_icache_purge();
 	libxfs_bcache_purge();
 
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 0cdef41..4cc0df6 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -543,7 +543,6 @@ parseproto(
 			pip = ip;
 			mp->m_sb.sb_rootino = ip->i_ino;
 			libxfs_mod_sb(tp, XFS_SB_ROOTINO);
-			mp->m_rootip = ip;
 			isroot = 1;
 		} else {
 			libxfs_trans_ijoin(tp, pip, 0);
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 355708c..d37e948 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -2582,6 +2582,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 	memset(XFS_BUF_PTR(buf), 0, sectorsize);
 	libxfs_sb_to_disk((void *)XFS_BUF_PTR(buf), sbp, XFS_SB_ALL_BITS);
 	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+	libxfs_purgebuf(buf);
 
 	/*
 	 * If the data area is a file, then grow it out to its final size
@@ -2616,7 +2617,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 		(xfs_extlen_t)XFS_FSB_TO_BB(mp, logblocks),
 		&sbp->sb_uuid, logversion, lsunit, XLOG_FMT);
 
-	mp = libxfs_mount(mp, sbp, xi.ddev, xi.logdev, xi.rtdev, 1);
+	mp = libxfs_mount(mp, sbp, xi.ddev, xi.logdev, xi.rtdev, 0);
 	if (mp == NULL) {
 		fprintf(stderr, _("%s: filesystem failed to initialize\n"),
 			progname);
@@ -2887,7 +2888,6 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 	/*
 	 * Allocate the root inode and anything else in the proto file.
 	 */
-	mp->m_rootip = NULL;
 	parse_proto(mp, &fsx, &protostring);
 
 	/*
diff --git a/repair/phase6.c b/repair/phase6.c
index 2a37438..5307acf 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -856,8 +856,6 @@ mk_root_dir(xfs_mount_t *mp)
 	ip->i_df.if_bytes = ip->i_df.if_real_bytes = 0;
 	ip->i_df.if_u1.if_extents = NULL;
 
-	mp->m_rootip = ip;
-
 	/*
 	 * initialize the directory
 	 */

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2013-10-31  4:14 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30  4:30 [PATCH 00/30 V3] xfsprogs: CRC write support for xfs_db Dave Chinner
2013-10-30  4:30 ` [PATCH 01/30] xfsprogs: fix automatic dependency generation Dave Chinner
2013-10-31 14:44   ` Christoph Hellwig
2013-10-30  4:30 ` [PATCH 02/30] xfs: fix some minor sparse warnings Dave Chinner
2013-10-31 14:44   ` Christoph Hellwig
2013-10-30  4:30 ` [PATCH 03/30] xfs: create a shared header file for format-related information Dave Chinner
2013-10-31 14:45   ` Christoph Hellwig
2013-10-30  4:30 ` [PATCH 04/30] xfs: split dquot buffer operations out Dave Chinner
2013-10-31 14:45   ` Christoph Hellwig
2013-10-30  4:30 ` [PATCH 05/30] xfs: decouple inode and bmap btree header files Dave Chinner
2013-10-31 14:45   ` Christoph Hellwig
2013-10-30  4:30 ` [PATCH 06/30] libxfs: unify xfs_btree.c with kernel code Dave Chinner
2013-10-31 14:46   ` Christoph Hellwig
2013-10-30  4:30 ` [PATCH 07/30] libxfs: bmap btree owner swap support Dave Chinner
2013-10-31 14:47   ` Christoph Hellwig
2013-10-30  4:30 ` [PATCH 08/30] libxfs: xfs_rtalloc.c becomes xfs_rtbitmap.c Dave Chinner
2013-10-31 14:48   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 09/30] libxfs: bring across inode buffer readahead verifier changes Dave Chinner
2013-10-31 14:48   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 10/30] libxfs: Minor cleanup and bug fix sync Dave Chinner
2013-10-31 14:48   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 11/30] xfs: remove newlines from strings passed to __xfs_printk Dave Chinner
2013-10-31 14:49   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 12/30] xfs: fix the wrong new_size/rnew_size at xfs_iext_realloc_direct() Dave Chinner
2013-10-31 14:49   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 13/30] xfs: fix node forward in xfs_node_toosmall Dave Chinner
2013-10-31 14:49   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 14/30] xfs: don't emit corruption noise on fs probes Dave Chinner
2013-10-31 14:49   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 15/30] db: separate out straight buffer IO from map based IO Dave Chinner
2013-10-31 14:56   ` Christoph Hellwig
2013-10-31 21:50     ` Dave Chinner
2013-11-01 12:51       ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 16/30] db: rewrite bbmap to use xfs_buf_map Dave Chinner
2013-10-31 15:06   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 17/30] db: rewrite IO engine to use libxfs Dave Chinner
2013-10-31 15:10   ` Christoph Hellwig
2013-10-31 21:59     ` Dave Chinner
2013-10-30  4:31 ` [PATCH 18/30] db: introduce verifier support into set_cur Dave Chinner
2013-11-01 13:07   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 19/30] db: indicate if the CRC on a buffer is correct or not Dave Chinner
2013-11-01 13:09   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 20/30] db: verify and calculate inode CRCs Dave Chinner
2013-11-04  9:05   ` Christoph Hellwig
2013-11-05  0:18     ` Dave Chinner
2013-10-30  4:31 ` [PATCH 21/30] db: verify and calculate dquot CRCs Dave Chinner
2013-11-04  9:06   ` Christoph Hellwig
2013-11-05  0:25     ` Dave Chinner
2013-10-30  4:31 ` [PATCH 22/30] db: add a special directory buffer verifier Dave Chinner
2013-11-04  9:07   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 23/30] db: add a special attribute " Dave Chinner
2013-11-04  9:07   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 24/30] db: re-enable write support for v5 filesystems Dave Chinner
2013-11-04  9:07   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 25/30] libxfs: fix root inode handling inconsistencies Dave Chinner
2013-10-30 10:23   ` Christoph Hellwig
2013-10-30 21:59     ` Dave Chinner
2013-10-31  4:13       ` Dave Chinner [this message]
2013-10-31 15:00         ` [PATCH 25/30 V2] " Christoph Hellwig
2013-10-31 22:04           ` Dave Chinner
2013-11-01 13:03             ` Christoph Hellwig
2013-11-04 23:22               ` Dave Chinner
2013-11-05  9:05                 ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 26/30] xfs_db: avoid libxfs buffer lookup warnings Dave Chinner
2013-11-04  9:12   ` Christoph Hellwig
2013-11-05  0:52     ` Dave Chinner
2013-11-05  9:06       ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 27/30] libxfs: work around do_div() not handling 32 bit numerators Dave Chinner
2013-11-04  9:16   ` Christoph Hellwig
2013-11-05  1:55     ` Dave Chinner
2013-10-30  4:31 ` [PATCH 28/30] db: enable metadump on CRC filesystems Dave Chinner
2013-11-04  9:18   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 29/30] xfs: support larger inode clusters on v5 filesystems Dave Chinner
2013-11-04  9:18   ` Christoph Hellwig
2013-10-30  4:31 ` [PATCH 30/30] xfsprogs: kill experimental warnings for " Dave Chinner
2013-11-04  9:19   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131031041343.GK6188@dastard \
    --to=david@fromorbit.com \
    --cc=hch@infradead.org \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox