linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH for 4.15] libxfs: fix dev_t handling in inode forks
Date: Wed, 15 Nov 2017 17:15:05 -0800	[thread overview]
Message-ID: <20171116011505.GH5119@magnolia> (raw)

From: Darrick J. Wong <darrick.wong@oracle.com>

In commit 699f676961 ("xfs: remove if_rdev"), some ancient definitions
of MAJOR/MINOR/MKDEV were ported into libxfs.  However, platform_defs.h
already has IRIX_DEV_* macros which encode a (major, minor) tuple into a
(major:14, minor:18) u32 format.  libxfs writes these values to disk
without any further interpretation.

Existing libxfs clients pass these encoded device numbers into libxfs,
which means that we cannot suddenly start interpreting the bit fields
differently.  The ported MAJOR/MINOR does this (major:8, minor:8), with
the result that proto file specs for block/char devices write
bit-shifted garbage into i_rdev.

(Or at least it would write garbage if libxfs_ialloc hadn't also lost
the ability to set i_rdev in the same patch...)

Therefore, just keep using the "IRIX" device encoding macros in
platform_defs.h, and actually set i_rdev in libxfs_ialloc when someone
tries to create a device file.  This fixes a regression in xfs/019.

Cc: sandeen@sandeen.net
Fixes: 699f67696151d750a58c321b072360ccc694837b
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/libxfs_priv.h |   18 ++++--------------
 libxfs/util.c        |    1 +
 2 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index 8c3f3b7..4c083b9 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -87,23 +87,13 @@ extern char    *progname;
 #undef ASSERT
 #define ASSERT(ex) assert(ex)
 
-#define MAJOR(dev)      ((dev)>>8)
-#define MINOR(dev)      ((dev) & 0xff)
-#define MKDEV(ma,mi) ((ma)<<8 | (mi))
-
-static inline unsigned sysv_major(uint32_t dev)
-{
-        return (dev >> 18) & 0x3fff;
-}
-
-static inline unsigned sysv_minor(uint32_t dev)
-{
-        return dev & 0x3ffff;
-}
+#define MKDEV(major, minor)	IRIX_MKDEV(major, minor)
+#define sysv_major(dev)		IRIX_DEV_MAJOR(dev)
+#define sysv_minor(dev)		IRIX_DEV_MINOR(dev)
 
 static inline uint32_t sysv_encode_dev(dev_t dev)
 {
-        return MINOR(dev) | (MAJOR(dev) << 18);
+        return IRIX_DEV_MINOR(dev) | (IRIX_DEV_MAJOR(dev) << 18);
 }
 
 #ifndef EWRONGFS
diff --git a/libxfs/util.c b/libxfs/util.c
index 90f96f8..792a17f 100644
--- a/libxfs/util.c
+++ b/libxfs/util.c
@@ -336,6 +336,7 @@ libxfs_ialloc(
 	case S_IFBLK:
 		ip->i_d.di_format = XFS_DINODE_FMT_DEV;
 		flags |= XFS_ILOG_DEV;
+		VFS_I(ip)->i_rdev = rdev;
 		break;
 	case S_IFREG:
 	case S_IFDIR:

             reply	other threads:[~2017-11-16  1:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-16  1:15 Darrick J. Wong [this message]
2017-11-16 19:13 ` [PATCH for 4.15] libxfs: fix dev_t handling in inode forks Eric Sandeen
2017-11-17 16:57 ` Christoph Hellwig
2017-11-27 19:26   ` Eric Sandeen
2017-11-27 20:16     ` Eric Sandeen
2017-11-28 14:04       ` 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=20171116011505.GH5119@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.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;
as well as URLs for NNTP newsgroup(s).