Commit 323726b7 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Pavel Emelyanov

make resolve_source() more friendly to FSTYPE__AUTO mounts

resolve_source() insists on kdev_major() == 0, and this makes sense.
However, at least FSTYPE__AUTO can try to use mi->source as a block
device and pray it will work.

[ Also bout this change from Oleg:

Let me send another (last) functional change before the promised
cleanups we discussed.

To remind, without this patch I still can't dump/restore /home and
/boot on my testing machine. --enable-fs xfs "works" in a sense that
"dump" succeeds. But "restore" fails.

However. Lets forget this for the moment. To me resolve_source() looks
just wrong. Sure, I agree, it is not safe to blindly use mi->source if
kdev_major() != 0. But this means that we should not have dumped this
mountpoint, simply because we can't restore it.

Yes, currently this works because fstypes[] contains only the diskless
filesystems, but still.

So this probably needs more cleanups too, and this patch doesn't make
this logic look better.

To me, we should do something like

	static char *resolve_source(struct mount_info *mi)
	{
		if (kdev_major(mi->s_dev) == 0)
			/*
			 * Anonymous block device. Kernel creates them for
			 * diskless mounts.
			 */
			return mi->source;

		if (mi->fstype->code != FSTYPE__AUTO) {
			pr_err("OOPS! something is wrong!!!\n");
			return NULL;
		}

		// OK, this is FSTYPE__AUTO, it should "just work"
		// by definition. Or the user should blame himself.

		struct stat st;

		if (stat(mi->source, &st) || !S_ISBLK(st.st_mode) ||
		    major(st.st_rdev) != kdev_major(mi->s_dev) ||
		    minor(st.st_rdev) != kdev_minor(mi->s_dev))
			pr_warn("Hmm, can't verify blkdev. Lets see if mount will work...\n");

		return mi->source;
	}

But this patch only does a minimal change to make FSTYPE__AUTO work
with blkdev.

]
Signed-off-by: 's avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 2085e078
...@@ -1639,6 +1639,15 @@ static char *resolve_source(struct mount_info *mi) ...@@ -1639,6 +1639,15 @@ static char *resolve_source(struct mount_info *mi)
*/ */
return mi->source; return mi->source;
if (mi->fstype->code == FSTYPE__AUTO) {
struct stat st;
if (!stat(mi->source, &st) && S_ISBLK(st.st_mode) &&
major(st.st_rdev) == kdev_major(mi->s_dev) &&
minor(st.st_rdev) == kdev_minor(mi->s_dev))
return mi->source;
}
pr_err("No device for %s mount\n", mi->mountpoint); pr_err("No device for %s mount\n", mi->mountpoint);
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment