Bug 204705 - zfs receive mounts received dataset even if -u is given
Summary: zfs receive mounts received dataset even if -u is given
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.2-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Andriy Gapon
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-11-20 21:54 UTC by VK
Modified: 2016-04-19 12:21 UTC (History)
1 user (show)

See Also:


Attachments
proposed patch for testing (381 bytes, patch)
2015-11-20 22:58 UTC, Andriy Gapon
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description VK freebsd_triage 2015-11-20 21:54:13 UTC
It appears that `zfs send -R <root-dataset-snapshot> | zfs receive -Fdu <external-media-dataset>`   will mount the received dataset despite the -u flag. I discovered this sending the root partition having mountpoint=/ which broke devfs. Below is a session done in a clean new (KVM) VM install with two disks to replicate the issue:


root@freebsd:~ # zpool status

  pool: zroot
 state: ONLINE
  scan: none requested
config:

	NAME        STATE     READ WRITE CKSUM
	zroot       ONLINE       0     0     0
	  vtbd0p2   ONLINE       0     0     0

errors: No known data errors


root@freebsd:~ # zpool list

NAME    SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
zroot  3.97G   830M  3.16G         -    13%    20%  1.00x  ONLINE  -


root@freebsd:~ # zfs list

NAME    USED  AVAIL  REFER  MOUNTPOINT
zroot   830M  3.03G   829M  /


root@freebsd:~ # zpool list -t snapshot

NAME                  USED  AVAIL  REFER  MOUNTPOINT
zroot@test-snapshot   496K      -   829M  -


root@freebsd:~ # zpool create zbackup vtbd1


root@freebsd:~ # zfs create zbackup/backup


root@freebsd:~ # zfs list

NAME             USED  AVAIL  REFER  MOUNTPOINT
zbackup          250K  3.84G    19K  /zbackup
zbackup/backup    19K  3.84G    19K  /zbackup/backup
zroot            830M  3.03G   829M  /


root@freebsd:~ # zfs send -R zroot@test-snapshot | zfs receive -Fdu zbackup/backup

root@freebsd:~ # zfs list

internal error: failed to initialize ZFS library


root@freebsd:~ # mount

zroot on / (zfs, local, nfsv4acls)
devfs on /dev (devfs, local, multilabel)
zbackup on /zbackup (zfs, local, nfsv4acls)
zbackup/backup on / (zfs, local, nfsv4acls)


root@freebsd:~ # mount -t devfs devfs /dev


root@freebsd:~ # zfs list

NAME             USED  AVAIL  REFER  MOUNTPOINT
zbackup          829M  3.03G    19K  /zbackup
zbackup/backup   829M  3.03G   829M  /
zroot            830M  3.03G   829M  /


root@freebsd:~ # zfs mount

zroot                           /
zbackup                         /zbackup
zbackup/backup                  /


root@freebsd:~ # zpool export zbackup

cannot unmount '/': Device busy
Comment 1 Andriy Gapon freebsd_committer 2015-11-20 22:05:00 UTC
I think that the received filesystem got mounted because it was received as  zbackup/backup and zbackup/backup was mounted before. Still this is a bug, of course.  But you can try to repeat the procedure with zbackup/backup unmounted before doing send | receive.
Comment 2 VK freebsd_triage 2015-11-20 22:32:31 UTC
Yes, I just tried sending to imported but unmounted zbackup and indeed, it did not automount.
Comment 3 Andriy Gapon freebsd_committer 2015-11-20 22:54:23 UTC
okay, so this must be the same issue as https://www.illumos.org/issues/6412
Comment 4 VK freebsd_triage 2015-11-20 22:55:17 UTC
As suggested by Allan Jude on IRC, I tried sending to a nonexisting dataset and without the -d flag and it autocreated the receiving dataset but did not automount it.


root@freebsd:~ # zfs mount

zroot                           /
zbackup                         /zbackup
zbackup/backup                  /zbackup/backup


root@freebsd:~ # zfs send zroot@test-snapshot | zfs receive -Fu zbackup/backup/foo


root@freebsd:~ # zfs list

NAME                 USED  AVAIL  REFER  MOUNTPOINT
zbackup              829M  3.03G    19K  /zbackup
zbackup/backup       829M  3.03G    19K  /zbackup/backup
zbackup/backup/foo   829M  3.03G   829M  /
zroot                898M  2.97G   897M  /


root@freebsd:~ # zfs mount

zroot                           /
zbackup                         /zbackup
zbackup/backup                  /zbackup/backup
Comment 5 Andriy Gapon freebsd_committer 2015-11-20 22:58:00 UTC
Created attachment 163360 [details]
proposed patch for testing

Please test the attached patch using your original procedure.
Comment 6 VK freebsd_triage 2015-11-21 18:46:55 UTC
I tested it against r291085, the line numbers were different but I located the only place in the file where the code appears.

It looks like that fixed it. Tried the procedure again and the dataset is not remounted with -Fdu  onto existing dataset.
Comment 7 Andriy Gapon freebsd_committer 2015-11-21 20:32:09 UTC
Thank you!
Comment 8 commit-hook freebsd_committer 2016-04-03 07:41:23 UTC
A commit references this bug:

Author: avg
Date: Sun Apr  3 07:40:34 UTC 2016
New revision: 297520
URL: https://svnweb.freebsd.org/changeset/base/297520

Log:
  zfs receive: -u can be ignored sometimes

  When force-receiving a filesystem that was already mounted the re-created
  filesystem is mounted despite -u flag.

  Also see https://www.illumos.org/issues/6412.

  PR:		204705
  Tested by:	Vladimir Krstulja <vlad-fbsd@acheronmedia.com>
  MFC after:	2 weeks
  X-Needs-Upstreaming:	illumos

Changes:
  head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c
Comment 9 commit-hook freebsd_committer 2016-04-19 12:14:31 UTC
A commit references this bug:

Author: avg
Date: Tue Apr 19 12:14:15 UTC 2016
New revision: 298264
URL: https://svnweb.freebsd.org/changeset/base/298264

Log:
  MFC r297520: zfs receive: -u can be ignored sometimes

  PR:		204705

Changes:
_U  stable/10/
  stable/10/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c
Comment 10 commit-hook freebsd_committer 2016-04-19 12:15:33 UTC
A commit references this bug:

Author: avg
Date: Tue Apr 19 12:14:53 UTC 2016
New revision: 298265
URL: https://svnweb.freebsd.org/changeset/base/298265

Log:
  MFC r297520: zfs receive: -u can be ignored sometimes

  PR:		204705

Changes:
_U  stable/9/cddl/contrib/opensolaris/lib/libzfs/
  stable/9/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c