Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/modules/zfs Prepare the implementation of the ZFS contro...



details:   https://anonhg.NetBSD.org/src/rev/f54068c16455
branches:  trunk
changeset: 996608:f54068c16455
user:      hannken <hannken%NetBSD.org@localhost>
date:      Tue Feb 05 09:54:36 2019 +0000

description:
Prepare the implementation of the ZFS control directory ".zfs".

- Move the stub routines from zfs_stub.c to zfs_ctldir.c and
  remove now empty file zfs_stub.c

- Add stub routines for zfsctl_loadvnode() to initialize control
  nodes and zfsctl_snapshot() to retrieve ".zfs/snapshot".

- Add an initial vnode operations vector for control nodes.

- Implement lookup into ".zfs" and lookup ".." from ".zfs/snapshot/<snap>".

- Change nodeid of mounted snapshots to the snapshot object id.

- Respect "-u" flag to "zfs rename <snapshot> ...".

diffstat:

 external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ctldir.h |   6 +
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c     |  71 +++++++++++++
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c      |   2 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c     |  10 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c      |  44 ++++++-
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c      |   5 +-
 external/cddl/osnet/sys/kern/zfs_stub.c                     |  59 ----------
 sys/modules/zfs/Makefile.zfsmod                             |   6 +-
 8 files changed, 130 insertions(+), 73 deletions(-)

diffs (truncated from 337 to 300 lines):

diff -r 9fb5672b2fdb -r f54068c16455 external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ctldir.h
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ctldir.h       Tue Feb 05 09:50:18 2019 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ctldir.h       Tue Feb 05 09:54:36 2019 +0000
@@ -44,7 +44,13 @@
 
 void zfsctl_create(zfsvfs_t *);
 void zfsctl_destroy(zfsvfs_t *);
+#ifdef __NetBSD__
+int zfsctl_loadvnode(vfs_t *, vnode_t *, const void *, size_t, const void **);
+int zfsctl_root(zfsvfs_t *, vnode_t **);
+int zfsctl_snapshot(zfsvfs_t *, vnode_t **);
+#else
 int zfsctl_root(zfsvfs_t *, int, vnode_t **);
+#endif
 void zfsctl_init(void);
 void zfsctl_fini(void);
 boolean_t zfsctl_is_node(vnode_t *);
diff -r 9fb5672b2fdb -r f54068c16455 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c   Tue Feb 05 09:50:18 2019 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c   Tue Feb 05 09:54:36 2019 +0000
@@ -1261,9 +1261,80 @@
 
 #ifdef __NetBSD__
 
+#include <sys/pathname.h>
 #include <sys/zfs_context.h>
 #include <sys/zfs_ctldir.h>
 
+static int (**zfs_sfsop_p)(void *);
+
+static const struct vnodeopv_entry_desc zfs_sfsop_entries[] = {
+       { &vop_default_desc,            vn_default_error },
+       { NULL, NULL }
+};
+
+const struct vnodeopv_desc zfs_sfsop_opv_desc =
+       { &zfs_sfsop_p, zfs_sfsop_entries };
+
+void
+zfsctl_init(void)
+{
+}
+
+void
+zfsctl_fini(void)
+{
+}
+
+int
+zfsctl_loadvnode(vfs_t *vfsp, vnode_t *vp,
+    const void *key, size_t key_len, const void **new_key)
+{
+
+       return EINVAL;
+}
+
+int
+zfsctl_root(zfsvfs_t *zfsvfs, vnode_t **znode)
+{
+
+       return ENOENT;
+}
+
+int
+zfsctl_snapshot(zfsvfs_t *zfsvfs, vnode_t **znode)
+{
+
+       return ENOENT;
+}
+
+void
+zfsctl_create(zfsvfs_t *zfsvfs)
+{
+
+       ASSERT(zfsvfs->z_ctldir == NULL);
+}
+
+void
+zfsctl_destroy(zfsvfs_t *zfsvfs)
+{
+
+       ASSERT(zfsvfs->z_ctldir == NULL);
+}
+
+int
+zfsctl_lookup_objset(vfs_t *vfsp, uint64_t objsetid, zfsvfs_t **zfsvfsp)
+{
+
+       return EINVAL;
+}
+
+int
+zfsctl_umount_snapshots(vfs_t *vfsp, int fflags, cred_t *cr)
+{
+
+       return 0;
+}
+
 boolean_t
 zfsctl_is_node(vnode_t *vp)
 {
diff -r 9fb5672b2fdb -r f54068c16455 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c    Tue Feb 05 09:50:18 2019 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c    Tue Feb 05 09:54:36 2019 +0000
@@ -3881,7 +3881,7 @@
        char *at;
        boolean_t allow_mounted = B_TRUE;
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__NetBSD__)
        allow_mounted = (zc->zc_cookie & 2) != 0;
 #endif
 
diff -r 9fb5672b2fdb -r f54068c16455 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c   Tue Feb 05 09:50:18 2019 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c   Tue Feb 05 09:54:36 2019 +0000
@@ -146,9 +146,11 @@
 void zfs_fini(void);
 
 extern const struct vnodeopv_desc zfs_vnodeop_opv_desc;
+extern const struct vnodeopv_desc zfs_sfsop_opv_desc;
 
 static const struct vnodeopv_desc * const zfs_vnodeop_descs[] = {
        &zfs_vnodeop_opv_desc,
+       &zfs_sfsop_opv_desc,
        NULL,
 };
 
@@ -185,9 +187,11 @@
        znode_t *zp;
 
        /*
-        * Skip the vnode/inode if inaccessible, or if the
+        * Skip the vnode/inode if inaccessible, is control node or if the
         * atime is clean.
         */
+       if (zfsctl_is_node(vp))
+               return false;
        zp = VTOZ(vp);
        return zp != NULL && vp->v_type != VNON && zp->z_atime_dirty != 0
            && !zp->z_unlinked;
@@ -1302,7 +1306,11 @@
        zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
 }
 
+#ifdef __NetBSD__
+int
+#else
 static int
+#endif
 zfs_domount(vfs_t *vfsp, char *osname)
 {
        uint64_t recordsize, fsid_guid;
diff -r 9fb5672b2fdb -r f54068c16455 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c    Tue Feb 05 09:50:18 2019 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c    Tue Feb 05 09:54:36 2019 +0000
@@ -1929,9 +1929,8 @@
  */
 /* ARGSUSED */
 static int
-zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp,
-    int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
-    int *direntflags, pathname_t *realpnp)
+zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, int flags,
+    struct componentname *cnp, int nameiop, cred_t *cr)
 {
        znode_t *zdp = VTOZ(dvp);
        znode_t *zp;
@@ -2038,6 +2037,29 @@
                return (EILSEQ);
        }
 
+       /*
+        * First handle the special cases.
+        */
+       if ((cnp->cn_flags & ISDOTDOT) != 0) {
+               /*
+                * If we are a snapshot mounted under .zfs, return
+                * the vp for the snapshot directory.
+                */
+               if (zdp->z_id == zfsvfs->z_root && zfsvfs->z_parent != zfsvfs) {
+                       ZFS_EXIT(zfsvfs);
+                       error = zfsctl_snapshot(zfsvfs->z_parent, vpp);
+
+                       return (error);
+               }
+       }
+       if (zfs_has_ctldir(zdp) && strcmp(nm, ZFS_CTLDIR_NAME) == 0) {
+               ZFS_EXIT(zfsvfs);
+               if ((cnp->cn_flags & ISLASTCN) != 0 && nameiop != LOOKUP)
+                       return (SET_ERROR(ENOTSUP));
+               error = zfsctl_root(zfsvfs, vpp);
+               return (error);
+       }
+
        error = zfs_dirlook(zdp, nm, &zp);
        if (error == 0) {
                *vpp = ZTOV(zp);
@@ -3047,11 +3069,22 @@
 #endif
 #ifdef __FreeBSD__
        vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
+       vap->va_nodeid = zp->z_id;
 #endif
 #ifdef __NetBSD__
        vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
+       vap->va_nodeid = zp->z_id;
+       /*
+        * If we are a snapshot mounted under .zfs, return
+        * the object id of the snapshot to make getcwd happy.
+        */
+       if (zp->z_id == zfsvfs->z_root && zfsvfs->z_parent != zfsvfs) {
+               vnode_t *cvp = vp->v_mount->mnt_vnodecovered;
+
+               if (cvp && zfsctl_is_node(cvp))
+                       vap->va_nodeid = dmu_objset_id(zfsvfs->z_os);
+       }
 #endif
-       vap->va_nodeid = zp->z_id;
        if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp))
                links = zp->z_links + 1;
        else
@@ -5139,8 +5172,7 @@
                nm = short_nm;
        (void)strlcpy(nm, cnp->cn_nameptr, cnp->cn_namelen + 1);
 
-       error = zfs_lookup(dvp, nm, vpp, NULL, 0, NULL, cnp->cn_cred, NULL,
-           NULL, NULL);
+       error = zfs_lookup(dvp, nm, vpp, 0, cnp, cnp->cn_nameiop, cnp->cn_cred);
 
        if (nm != short_nm)
                PNBUF_PUT(nm);
diff -r 9fb5672b2fdb -r f54068c16455 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c    Tue Feb 05 09:50:18 2019 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c    Tue Feb 05 09:54:36 2019 +0000
@@ -54,6 +54,7 @@
 #include <sys/kidmap.h>
 
 #ifdef __NetBSD__
+#include <sys/zfs_ctldir.h>
 #include <miscfs/specfs/specdev.h>
 
 extern int (**zfs_vnodeop_p)(void *);
@@ -835,7 +836,9 @@
        sa_handle_t *hdl;
        znode_t *zp;
 
-       KASSERT(key_len == sizeof(obj_num));
+       if (key_len != sizeof(obj_num))
+               return zfsctl_loadvnode(mp, vp, key, key_len, new_key);
+
        memcpy(&obj_num, key, key_len);
 
        zfsvfs = mp->mnt_data;
diff -r 9fb5672b2fdb -r f54068c16455 external/cddl/osnet/sys/kern/zfs_stub.c
--- a/external/cddl/osnet/sys/kern/zfs_stub.c   Tue Feb 05 09:50:18 2019 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-#include <sys/pathname.h>
-#include <sys/zfs_context.h>
-#include <sys/zfs_ctldir.h>
-
-/* zfs_ctldir.c stub routtines */
-
-void
-zfsctl_init(void)
-{
-}
-
-void
-zfsctl_fini(void)
-{
-}
-
-int
-zfsctl_root(zfsvfs_t *zfsvfs, int flags, vnode_t **znode)
-{
-
-       return 0;
-}
-
-int
-zfsctl_root_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, pathname_t *pnp,
-    int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
-    int *direntflags, pathname_t *realpnp)
-{
-
-       return ENOENT;
-}
-
-void
-zfsctl_create(zfsvfs_t *zfsvfs)
-{
-       
-       return;
-}
-
-void
-zfsctl_destroy(zfsvfs_t *zfsvfs)
-{



Home | Main Index | Thread Index | Old Index