From nobody@FreeBSD.org  Wed Apr 16 21:35:08 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 9609C1065671
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Apr 2008 21:35:08 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 43D0D8FC20
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Apr 2008 21:35:08 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m3GLYu0I052843
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Apr 2008 21:34:56 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m3GLYuAO052842;
	Wed, 16 Apr 2008 21:34:56 GMT
	(envelope-from nobody)
Message-Id: <200804162134.m3GLYuAO052842@www.freebsd.org>
Date: Wed, 16 Apr 2008 21:34:56 GMT
From: Leon Kos <leon.kos@lecad.fs.uni-lj.si>
To: freebsd-gnats-submit@FreeBSD.org
Subject: mountd fails on nmount()  after UFS snapshot creation with mount
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         122833
>Category:       kern
>Synopsis:       [snapshots] [patch] mountd fails on nmount() after UFS snapshot creation with mount
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    rodrigc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 16 21:40:00 UTC 2008
>Closed-Date:    Fri Jun 27 00:25:03 UTC 2008
>Last-Modified:  Fri Jun 27 00:25:03 UTC 2008
>Originator:     Leon Kos
>Release:        RELENG_7
>Organization:
University of Ljubljana
>Environment:
FreeBSD cad.lecad.uni-lj.si 7.0-STABLE FreeBSD 7.0-STABLE #22: Wed Apr 16 10:41:55 CEST 2008     leon@cad.lecad.uni-lj.si:/usr/obj/usr/src/sys/CAD  i386

>Description:
After creating snapshot on filesystem mountd is unable to export under that tree.

Debugging /usr/src/usr.sbin/mountd/mountd.c shows that that it fails on
nmount() when clearing exports list and also when creating it. 

dmesg -a shows

Apr 16 18:37:06 cad mountd[1207]: can't delete exports for /usr: Cross-device link 
Apr 16 18:37:06 cad mountd[1207]: can't export /usr/tmp 
Apr 16 18:37:06 cad mountd[1207]: bad exports list line /usr /usr/tmp -network 192.168 -mask 255.255.0.0
Apr 16 18:49:52 cad mountd[1938]: can't delete exports for /usr: Cross-device link 

Even tried mountd.c from trunk with no improvements.

When googling for "UFS snapshot weirdness" some users suggested that this
is ipv6 issue. but from my experience it is not so.

>How-To-Repeat:
root@cad:~# showmount -e
Exports list on localhost:
/usr/tmp                           192.168.0.0 
/usr                               192.168.0.0 
/home/xlsvaje                      192.168.5.0 
/home                              192.168.5.0 
/tftpboot                          192.168.0.0 
root@cad:~# snapshot make /usr:daily
root@cad:~# showmount -e
Exports list on localhost:
/home/xlsvaje                      192.168.5.0 
/home                              192.168.5.0 
/tftpboot                          192.168.0.0 

>Fix:
Use command like:
root@cad:~# mksnap_ffs /usr /usr/.snap/daily.0

Do not use:
root@cad:~# mount -u -o snapshot   /usr/.snap/daily.0 /usr
or 
root@cad:~#snapshot make /usr:daily


When mountd fails to export only reboot helps.
Restarting mountd does not help. 
Removing created snapshot does not help.

Attached patch is only the fix for freebsd-snapshot utility and not the solution.

Beware there could also be dangling /usr/sbin/snapshot 

Patch attached with submission follows:

--- /usr/local/sbin/snapshot.orig       2008-04-16 19:42:15.000000000 +0200
+++ /usr/local/sbin/snapshot    2008-04-16 19:50:54.000000000 +0200
@@ -335,7 +335,7 @@
             done
 
             #   create new snapshot
-            system mount -u -o snapshot $fs_dir/.snap/$fs_tag.$fs_gen $fs_dir
+            system mksnap_ffs $fs_dir $fs_dir/.snap/$fs_tag.$fs_gen
         fi
     fi


>Release-Note:
>Audit-Trail:

From: Leon Kos <leon.kos@lecad.fs.uni-lj.si>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: kern/122833: mountd fails on nmount()  after UFS snapshot creation
 with mount
Date: Thu, 17 Apr 2008 08:58:53 +0200 (CEST)

 To prove that this is not worksforme kind of bug, I've installed vanilla
 FreeBSD 7.0 from distribution CD. Created /etc/exports with single line
 /usr -network 127.0
 After command "mount -u -o snapshot /usr/.snap/daily.0 /usr"
 I'am getting  messages of Cross-device link and bad exports line.
 
 Forgot to mention before, but this does not happen on 6.3-STABLE. I've been 
 running NFS for years and snapshoting daily without a problem on 6_RELENG
 
 

From: Leon Kos <leon.kos@lecad.fs.uni-lj.si>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: kern/122833: mountd fails on nmount()  after UFS snapshot creation
 with mount
Date: Thu, 17 Apr 2008 13:14:09 +0200 (CEST)

 This seems to be duplicate of the 
 http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/118360
 
 although this PR describes the same problem better.
 

From: =?iso-8859-1?q?Ga=EBl_Roualland?= <gael.roualland@dial.oleane.com>
To: bug-followup@freebsd.org, leon.kos@lecad.fs.uni-lj.si
Cc:  
Subject: Re: kern/122833: [snapshots] [patch] mountd fails on nmount() after UFS snapshot creation with mount
Date: Sun, 11 May 2008 13:14:27 +0200

 Same problem here.
 
 After looking a bit in mount and mksnap_ffs, this seems due to a 
 difference in the way the snapshot is created : mount calls nmount(2), 
 while mksnap_ffs only calls mount(2). There might also be differences 
 in the options passed to the syscalls, that needs investigating.
 
 Note that mount sends a HUP signal to mountd after each successful mount 
 (including snapshots), while mksnap_ffs does not, however manually 
 restarting mountd after a mksnap_ffs does not exhibit the bug.
 
 

From: Jaakko Heinonen <jh@saunalahti.fi>
To: =?utf-8?B?R2HDq2w=?= Roualland <gael.roualland@dial.oleane.com>
Cc: bug-followup@FreeBSD.org, leon.kos@lecad.fs.uni-lj.si,
	rodrigc@FreeBSD.org, Yar Tikhiy <yar@comp.chem.msu.su>
Subject: Re: kern/122833: [snapshots] [patch] mountd fails on nmount()
	after UFS snapshot creation with mount
Date: Mon, 12 May 2008 13:37:00 +0300

 Hi,
 
 On 2008-05-11, Gaël Roualland wrote:
 >  After looking a bit in mount and mksnap_ffs, this seems due to a 
 >  difference in the way the snapshot is created : mount calls nmount(2), 
 >  while mksnap_ffs only calls mount(2).
 
 This bug occurs because when doing a snapshot with nmount(2) call (with
 "snapshot" option) the "snapshot" option string persists for the mount
 point even after the nmount call. Later nmount(2) calls made by
 mountd(8) fail because the ffs code tries to create a snapshot due to
 "snapshot" option string presence.
 
 You can work around the problem without reboot by removing the option
 string with
 
 	mount -o nosnapshot <mountpoint>
 
 The bug could be worked around in mountd code but IMO a proper fix is
 needed in kernel nmount code.
 
 There are also other ways to reproduce the bug:
 
 # mount -o snapshot /.snap/foo /
 # mount -u -o atime /
 mount: /dev/ad2s1a : Cross-device link
 # mount -o nosnapshot /
 # mount -u -o atime /
 #
 
 -- 
 Jaakko

From: Jaakko Heinonen <jh@saunalahti.fi>
To: bug-followup@FreeBSD.org
Cc: =?utf-8?B?R2HDq2w=?= Roualland <gael.roualland@dial.oleane.com>,
	leon.kos@lecad.fs.uni-lj.si, rodrigc@FreeBSD.org,
	Yar Tikhiy <yar@comp.chem.msu.su>
Subject: Re: kern/122833: [snapshots] [patch] mountd fails on nmount()
	after UFS snapshot creation with mount
Date: Wed, 14 May 2008 11:18:52 +0300

 Hi,
 
 On 2008-05-12, Jaakko Heinonen wrote:
 > The bug could be worked around in mountd code but IMO a proper fix is
 > needed in kernel nmount code.
 
 Following change is a possible quick fix for the bug:
 
 Index: ffs_vfsops.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/ufs/ffs/ffs_vfsops.c,v
 retrieving revision 1.336
 diff -p -u -r1.336 ffs_vfsops.c
 --- ffs_vfsops.c	24 Feb 2008 16:38:58 -0000	1.336
 +++ ffs_vfsops.c	13 May 2008 17:08:20 -0000
 @@ -183,9 +183,6 @@ ffs_mount(struct mount *mp, struct threa
  	if (vfs_getopt(mp->mnt_optnew, "noclusterw", NULL, NULL) == 0)
  		mntorflags |= MNT_NOCLUSTERW;
  
 -	if (vfs_getopt(mp->mnt_optnew, "snapshot", NULL, NULL) == 0)
 -		mntorflags |= MNT_SNAPSHOT;
 -
  	MNT_ILOCK(mp);
  	mp->mnt_flag = (mp->mnt_flag | mntorflags) & ~mntandnotflags;
  	MNT_IUNLOCK(mp);
 
 However nmount(2) still has a fundamental problem with non-persistent
 string mount options.
 
 -- 
 Jaakko

From: Craig Rodrigues <rodrigc@crodrigues.org>
To: Jaakko Heinonen <jh@saunalahti.fi>
Cc: bug-followup@FreeBSD.org,
	Ga??l Roualland <gael.roualland@dial.oleane.com>,
	leon.kos@lecad.fs.uni-lj.si, rodrigc@FreeBSD.org,
	Yar Tikhiy <yar@comp.chem.msu.su>
Subject: Re: kern/122833: [snapshots] [patch] mountd fails on nmount() after UFS snapshot creation with mount
Date: Wed, 14 May 2008 18:56:40 +0000

 On Wed, May 14, 2008 at 11:18:52AM +0300, Jaakko Heinonen wrote:
 > Following change is a possible quick fix for the bug:
 > 
 > Index: ffs_vfsops.c
 > ===================================================================
 > RCS file: /home/ncvs/src/sys/ufs/ffs/ffs_vfsops.c,v
 > retrieving revision 1.336
 > diff -p -u -r1.336 ffs_vfsops.c
 > --- ffs_vfsops.c	24 Feb 2008 16:38:58 -0000	1.336
 > +++ ffs_vfsops.c	13 May 2008 17:08:20 -0000
 > @@ -183,9 +183,6 @@ ffs_mount(struct mount *mp, struct threa
 >  	if (vfs_getopt(mp->mnt_optnew, "noclusterw", NULL, NULL) == 0)
 >  		mntorflags |= MNT_NOCLUSTERW;
 >  
 > -	if (vfs_getopt(mp->mnt_optnew, "snapshot", NULL, NULL) == 0)
 > -		mntorflags |= MNT_SNAPSHOT;
 > -
 >  	MNT_ILOCK(mp);
 >  	mp->mnt_flag = (mp->mnt_flag | mntorflags) & ~mntandnotflags;
 >  	MNT_IUNLOCK(mp);
 
 
 That fix is wrong.  The better fix would be to come up
 with a function that traverses a vfs_optlist and deletes a string
 option from the list.  Something like:
 
 int vfs_delopt(struct vfsoptlist *optlist, const char *optname);
 
 Then the above code would change to:
 	if (vfs_getopt(mp->mnt_optnew, "snapshot", NULL, NULL) == 0) {
 		mntorflags |= MNT_SNAPSHOT;
 		vfs_delopt(mp->optnew, "snapshot");
 	}
 
 -- 
 Craig Rodrigues
 rodrigc@crodrigues.org

From: Craig Rodrigues <rodrigc@crodrigues.org>
To: Jaakko Heinonen <jh@saunalahti.fi>
Cc: bug-followup@FreeBSD.org,
	Ga??l Roualland <gael.roualland@dial.oleane.com>,
	leon.kos@lecad.fs.uni-lj.si, rodrigc@FreeBSD.org,
	Yar Tikhiy <yar@comp.chem.msu.su>
Subject: Re: kern/122833: [snapshots] [patch] mountd fails on nmount() after UFS snapshot creation with mount
Date: Wed, 14 May 2008 21:01:44 +0000

 On Wed, May 14, 2008 at 06:56:40PM +0000, Craig Rodrigues wrote:
 > That fix is wrong.  The better fix would be to come up
 > with a function that traverses a vfs_optlist and deletes a string
 > option from the list.  Something like:
 
 Actually we have such a function.  We need to do to the "snapshot" option
 what we do to the "export" option in sys/kern/vfs_export.c.
 
 
 Index: ffs_vfsops.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/ufs/ffs/ffs_vfsops.c,v
 retrieving revision 1.340
 diff -u -r1.340 ffs_vfsops.c
 --- ffs_vfsops.c	26 Mar 2008 20:48:07 -0000	1.340
 +++ ffs_vfsops.c	14 May 2008 21:00:23 -0000
 @@ -183,8 +183,15 @@
  	if (vfs_getopt(mp->mnt_optnew, "noclusterw", NULL, NULL) == 0)
  		mntorflags |= MNT_NOCLUSTERW;
  
 -	if (vfs_getopt(mp->mnt_optnew, "snapshot", NULL, NULL) == 0)
 +	if (vfs_getopt(mp->mnt_optnew, "snapshot", NULL, NULL) == 0) {
  		mntorflags |= MNT_SNAPSHOT;
 +		/*
 +		 * Once we have set the MNT_SNAPSHOT flag, do not
 +		 * persist "snapshot" in the options list.
 +		 */
 +		vfs_deleteopt(mp->mnt_optnew, "snapshot");
 +		vfs_deleteopt(mp->mnt_opt, "snapshot");
 +	}
  
  	MNT_ILOCK(mp);
  	mp->mnt_flag = (mp->mnt_flag | mntorflags) & ~mntandnotflags;
 
 
 -- 
 Craig Rodrigues
 rodrigc@crodrigues.org

From: "Yar Tikhiy" <yar@comp.chem.msu.su>
To: "Craig Rodrigues" <rodrigc@crodrigues.org>
Cc: "Jaakko Heinonen" <jh@saunalahti.fi>, bug-followup@freebsd.org, 
	"Ga??l Roualland" <gael.roualland@dial.oleane.com>, 
	leon.kos@lecad.fs.uni-lj.si, rodrigc@freebsd.org
Subject: Re: kern/122833: [snapshots] [patch] mountd fails on nmount() after UFS snapshot creation with mount
Date: Thu, 15 May 2008 08:42:35 +0400

 On Thu, May 15, 2008 at 1:01 AM, Craig Rodrigues <rodrigc@crodrigues.org> wrote:
 > On Wed, May 14, 2008 at 06:56:40PM +0000, Craig Rodrigues wrote:
 >> That fix is wrong.  The better fix would be to come up
 >> with a function that traverses a vfs_optlist and deletes a string
 >> option from the list.  Something like:
 >
 > Actually we have such a function.  We need to do to the "snapshot" option
 > what we do to the "export" option in sys/kern/vfs_export.c.
 
 And "update" is also on the waiting list for such handling.
 
 -- 
 Yar

From: Jaakko Heinonen <jh@saunalahti.fi>
To: Craig Rodrigues <rodrigc@crodrigues.org>
Cc: bug-followup@FreeBSD.org,
	Ga??l Roualland <gael.roualland@dial.oleane.com>,
	leon.kos@lecad.fs.uni-lj.si, rodrigc@FreeBSD.org,
	Yar Tikhiy <yar@comp.chem.msu.su>
Subject: Re: kern/122833: [snapshots] [patch] mountd fails on nmount()
	after UFS snapshot creation with mount
Date: Thu, 15 May 2008 13:35:39 +0300

 Thank you for your quick response.
 
 On 2008-05-14, Craig Rodrigues wrote:
 > On Wed, May 14, 2008 at 06:56:40PM +0000, Craig Rodrigues wrote:
 > > That fix is wrong.  The better fix would be to come up
 
 Yes, I probably should have stated more clearly that it was a quick
 hack.
 
 > Actually we have such a function.  We need to do to the "snapshot" option
 > what we do to the "export" option in sys/kern/vfs_export.c.
 
 > --- ffs_vfsops.c        26 Mar 2008 20:48:07 -0000      1.340
 > +++ ffs_vfsops.c        14 May 2008 21:00:23 -0000
 
 There is also code in vfs_mount.c that sets the MNT_SNAPSHOT flag:
 (in vfs_donmount())
 		else if (strcmp(opt->name, "snapshot") == 0)
 			fsflags |= MNT_SNAPSHOT;
 
 I wonder if we should add the option removal code also there or remove
 the "snapshot" handling completely from vfs_donmount(). For me it seems
 confusing that MNT_SNAPSHOT is first set in vfs_donmount() and then
 again in file system specific code but the snapshot option string is
 removed only in file system specific code.
 
 Thanks.
 -- 
 Jaakko

From: Craig Rodrigues <rodrigc@crodrigues.org>
To: Jaakko Heinonen <jh@saunalahti.fi>
Cc: bug-followup@FreeBSD.org,
	Ga??l Roualland <gael.roualland@dial.oleane.com>,
	leon.kos@lecad.fs.uni-lj.si, rodrigc@FreeBSD.org,
	Yar Tikhiy <yar@comp.chem.msu.su>
Subject: Re: kern/122833: [snapshots] [patch] mountd fails on nmount() after UFS snapshot creation with mount
Date: Thu, 15 May 2008 17:22:13 +0000

 On Thu, May 15, 2008 at 01:35:39PM +0300, Jaakko Heinonen wrote:
 > I wonder if we should add the option removal code also there or remove
 > the "snapshot" handling completely from vfs_donmount(). For me it seems
 
 We should remove the MNT_SNAPSHOT handling code from vfs_donmount(),
 because it only makes sense in UFS.
 
 -- 
 Craig Rodrigues
 rodrigc@crodrigues.org
Responsible-Changed-From-To: freebsd-bugs->rodrigc 
Responsible-Changed-By: rodrigc 
Responsible-Changed-When: Sat May 24 00:19:55 UTC 2008 
Responsible-Changed-Why:  
Taking it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=122833 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/122833: commit references a PR
Date: Sat, 24 May 2008 00:41:41 +0000 (UTC)

 rodrigc     2008-05-24 00:41:32 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/ufs/ffs          ffs_vfsops.c 
   Log:
   After converting the "snapshot" mount option to the MNT_SNAPSHOT flag,
   delete "snapshot" from the persistent mount options list.
   This should fix problems with doing a mount -o snapshot of a file system, followed by
   an NFS export of the same file system.
   
   PR:             122833
   Reported by:    Leon Kos <leon.kos lecad fs uni-lj si>,
                   Jaakko Heinonen <jh saunalahti fi>
   MFC after:      1 month
   
   Revision  Changes    Path
   1.342     +8 -1      src/sys/ufs/ffs/ffs_vfsops.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: gavin 
State-Changed-When: Wed Jun 11 12:57:16 UTC 2008 
State-Changed-Why:  
Fixed in HEAD, awaiting MFC 

http://www.freebsd.org/cgi/query-pr.cgi?pr=122833 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/122833: commit references a PR
Date: Thu, 26 Jun 2008 22:59:49 +0000 (UTC)

 rodrigc     2008-06-26 22:58:20 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sys/kern             vfs_mount.c 
     sys/ufs/ffs          ffs_vfsops.c 
   Log:
   SVN rev 180040 on 2008-06-26 22:58:20Z by rodrigc
   
   ffs_vfsops.c:
    MFC 179269-179270
    - delete "snapshot" from options list after we convert mount option to MNT_SNAPSHOT flag
    - do not perform string to flag conversions for mount option which are converted
      further up in vfs_donmount() in vfs_mount.c
   
   vfs_mount.c:
    MFC 179268
    - Do not convert the "snapshot" string to the MNT_SNAPSHOT flag here, since
      we do it further down in ffs_vfsops.c
   
   PR:             122833
   
   Revision   Changes    Path
   1.265.2.5  +0 -2      src/sys/kern/vfs_mount.c
   1.329.2.4  +8 -22     src/sys/ufs/ffs/ffs_vfsops.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: rodrigc 
State-Changed-When: Fri Jun 27 00:24:28 UTC 2008 
State-Changed-Why:  
Committed to HEAD and RELENG_7. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=122833 
>Unformatted:
