Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Feb 2010 03:12:26 +0200
From:      Gleb Kurtsou <gleb.kurtsou@gmail.com>
To:        Pawel Jakub Dawidek <pjd@FreeBSD.org>
Cc:        freebsd-fs@freebsd.org, Jaakko Heinonen <jh@FreeBSD.org>
Subject:   Re: Unable to pwd in ZFS snapshot
Message-ID:  <20100205011226.GA2657@tops.skynet.lt>
In-Reply-To: <20100204205546.GA1733@garage.freebsd.pl>
References:  <4b473c1f1002032014y4da8c0f0xcb74c749332cced3@mail.gmail.com> <20100204205546.GA1733@garage.freebsd.pl>

next in thread | previous in thread | raw e-mail | index | archive | help

--4Ckj6UjgE2iN1+kY
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline

On (04/02/2010 21:55), Pawel Jakub Dawidek wrote:
> On Wed, Feb 03, 2010 at 11:14:37PM -0500, Randy Sofia wrote:
> > `pwd` returns "No such file or directory" when browsing snapshot files. This
> > was addressed in:
> > http://lists.freebsd.org/pipermail/freebsd-fs/2009-February/005675.html  but
> > remains the same as of 8.0-RELEASE.
> > 
> > I am wondering if this is the expected behavior or if this was left by the
> > wayside.
> > 
> > A work around is available as per the previous discussion:
> > zfs set snapdir=visible volume
> > 
> > Reproducible behavior:
> > CANAAN# zfs snapshot pithos/media@0_day_ago
> > CANAAN# cd /pithos/media/.zfs/snapshot/0_day_ago/
> > CANAAN# pwd
> > pwd: .: No such file or directory
> > CANAAN# uname -a
> > FreeBSD CANAAN 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Fri Dec 18 00:38:33 UTC
> > 2009     root@:/usr/obj/usr/src/sys/CANAAN  amd64
> 
> It was reported to me by Jaakko some time ago, that r197513 (committed
> by me) is responsible for this breakage. Unfortunately I had no time to
> fix it yet.
It looks like pwd gets puzzled by all inodes having the same inode
number under .zfs/snapshot. Besides we're trying to hide a fact that
each snapshot is actually a mount point.

Comments in zfs_ctldir.c explain the inode numbering scheme under .zfs
in detail, each snapshot node has to have unique inode number.  Correct
inode number is returned by READDIR call, but not by GETATTR for the
same vnode. This breaks our pwd (getcwd). The patch attached adds a hack
to VOP_GETATTR to return expected inode numbers.

Also, with r197513 reverted all inode numbers are still the same, but it
seems to work as expected.

Unfortunately I have no OpenSolaris installed to verify if inode numbers
are also the same there.

I think I should file a PR for the issue, so it doesn't get lost, what
do you think?

> -- 
> Pawel Jakub Dawidek                       http://www.wheel.pl
> pjd@FreeBSD.org                           http://www.FreeBSD.org
> FreeBSD committer                         Am I Evil? Yes, I Am!



--4Ckj6UjgE2iN1+kY
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="zfs-snapshot-pwd.patch.txt"

diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c
index 7820293..bb7e0ae 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c
@@ -1061,6 +1061,7 @@ zfsctl_snapshot_mknode(vnode_t *pvp, uint64_t objset)
 	VN_HOLD(vp);
 	zcp = vp->v_data;
 	zcp->zc_id = objset;
+	gfs_file_set_inode(vp, objset);
 	VFS_HOLD(vp->v_vfsp);
 	VOP_UNLOCK(vp, 0);
 
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
index 4f61f5f..19a3738 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
@@ -40,6 +40,7 @@
 #include <sys/uio.h>
 #include <sys/atomic.h>
 #include <sys/namei.h>
+#include <sys/gfs.h>
 #include <sys/mman.h>
 #include <sys/cmn_err.h>
 #include <sys/errno.h>
@@ -2371,6 +2372,15 @@ zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
 	zfs_fuid_map_ids(zp, cr, &vap->va_uid, &vap->va_gid);
 //	vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev;
 	vap->va_nodeid = zp->z_id;
+	/*
+	 * XXX Should root inode number for every mounted zfs
+	 * filesystem/snapshot be the same?
+	 * VROOT flag gets removed from the vp in zfsctl_snapdir_lookup
+	 */
+	if (zfsvfs->z_issnap && zp->z_id == zfsvfs->z_root) {
+		vnode_t *svp = zfsvfs->z_vfs->mnt_vnodecovered;
+		vap->va_nodeid = gfs_file_inode(svp);
+	}
 	if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp))
 		links = pzp->zp_links + 1;
 	else

--4Ckj6UjgE2iN1+kY--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100205011226.GA2657>