Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs Change ffs to use vcache_new:



details:   https://anonhg.NetBSD.org/src/rev/739c82759a31
branches:  trunk
changeset: 336756:739c82759a31
user:      hannken <hannken%NetBSD.org@localhost>
date:      Tue Mar 17 09:39:29 2015 +0000

description:
Change ffs to use vcache_new:
- Change ffs_valloc to return an inode number.
- Remove now obsolete UFS operations UFS_VALLOC and UFS_VFREE.
- Make ufs_makeinode private to ufs_vnops.c and pass vattr instead of mode.

diffstat:

 sys/ufs/ext2fs/ext2fs_vfsops.c |    5 +-
 sys/ufs/ffs/ffs_alloc.c        |   64 +----------
 sys/ufs/ffs/ffs_extern.h       |    4 +-
 sys/ufs/ffs/ffs_vfsops.c       |  230 ++++++++++++++++++++++++++++++++++------
 sys/ufs/ffs/ffs_wapbl.c        |   31 +++--
 sys/ufs/mfs/mfs_vfsops.c       |    5 +-
 sys/ufs/ufs/ufs_extern.h       |    4 +-
 sys/ufs/ufs/ufs_vfsops.c       |    6 +-
 sys/ufs/ufs/ufs_vnops.c        |  130 ++++++----------------
 sys/ufs/ufs/ufsmount.h         |    8 +-
 10 files changed, 266 insertions(+), 221 deletions(-)

diffs (truncated from 864 to 300 lines):

diff -r 1c2d5526e8a0 -r 739c82759a31 sys/ufs/ext2fs/ext2fs_vfsops.c
--- a/sys/ufs/ext2fs/ext2fs_vfsops.c    Tue Mar 17 09:38:21 2015 +0000
+++ b/sys/ufs/ext2fs/ext2fs_vfsops.c    Tue Mar 17 09:39:29 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs_vfsops.c,v 1.190 2015/02/23 17:05:58 maxv Exp $ */
+/*     $NetBSD: ext2fs_vfsops.c,v 1.191 2015/03/17 09:39:29 hannken Exp $      */
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.190 2015/02/23 17:05:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.191 2015/03/17 09:39:29 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -156,7 +156,6 @@
 static const struct ufs_ops ext2fs_ufsops = {
        .uo_itimes = ext2fs_itimes,
        .uo_update = ext2fs_update,
-       .uo_vfree = ext2fs_vfree,
 };
 
 /* Fill in the inode uid/gid from ext2 halves.  */
diff -r 1c2d5526e8a0 -r 739c82759a31 sys/ufs/ffs/ffs_alloc.c
--- a/sys/ufs/ffs/ffs_alloc.c   Tue Mar 17 09:38:21 2015 +0000
+++ b/sys/ufs/ffs/ffs_alloc.c   Tue Mar 17 09:39:29 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_alloc.c,v 1.147 2014/09/08 20:52:37 joerg Exp $    */
+/*     $NetBSD: ffs_alloc.c,v 1.148 2015/03/17 09:39:29 hannken Exp $  */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.147 2014/09/08 20:52:37 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.148 2015/03/17 09:39:29 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -555,20 +555,16 @@
  * => um_lock not held upon entry or return
  */
 int
-ffs_valloc(struct vnode *pvp, int mode, kauth_cred_t cred,
-    struct vnode **vpp)
+ffs_valloc(struct vnode *pvp, int mode, kauth_cred_t cred, ino_t *inop)
 {
        struct ufsmount *ump;
        struct inode *pip;
        struct fs *fs;
-       struct inode *ip;
-       struct timespec ts;
        ino_t ino, ipref;
        int cg, error;
 
        UFS_WAPBL_JUNLOCK_ASSERT(pvp->v_mount);
 
-       *vpp = NULL;
        pip = VTOI(pvp);
        fs = pip->i_fs;
        ump = pip->i_ump;
@@ -603,63 +599,15 @@
        if (ino == 0)
                goto noinodes;
        UFS_WAPBL_END(pvp->v_mount);
-       error = VFS_VGET(pvp->v_mount, ino, vpp);
-       if (error) {
-               int err;
-               err = UFS_WAPBL_BEGIN(pvp->v_mount);
-               if (err == 0)
-                       ffs_vfree(pvp, ino, mode);
-               if (err == 0)
-                       UFS_WAPBL_END(pvp->v_mount);
-               return (error);
-       }
-       KASSERT((*vpp)->v_type == VNON);
-       ip = VTOI(*vpp);
-       if (ip->i_mode) {
-#if 0
-               printf("mode = 0%o, inum = %d, fs = %s\n",
-                   ip->i_mode, ip->i_number, fs->fs_fsmnt);
-#else
-               printf("dmode %x mode %x dgen %x gen %x\n",
-                   DIP(ip, mode), ip->i_mode,
-                   DIP(ip, gen), ip->i_gen);
-               printf("size %llx blocks %llx\n",
-                   (long long)DIP(ip, size), (long long)DIP(ip, blocks));
-               printf("ino %llu ipref %llu\n", (unsigned long long)ino,
-                   (unsigned long long)ipref);
-#if 0
-               error = bread(ump->um_devvp, FFS_FSBTODB(fs, ino_to_fsba(fs, ino)),
-                   (int)fs->fs_bsize, NOCRED, 0, &bp);
-#endif
+       *inop = ino;
+       return 0;
 
-#endif
-               panic("ffs_valloc: dup alloc");
-       }
-       if (DIP(ip, blocks)) {                          /* XXX */
-               printf("free inode %llu on %s had %" PRId64 " blocks\n",
-                   (unsigned long long)ino, fs->fs_fsmnt, DIP(ip, blocks));
-               DIP_ASSIGN(ip, blocks, 0);
-       }
-       ip->i_flag &= ~IN_SPACECOUNTED;
-       ip->i_flags = 0;
-       DIP_ASSIGN(ip, flags, 0);
-       /*
-        * Set up a new generation number for this inode.
-        */
-       ip->i_gen++;
-       DIP_ASSIGN(ip, gen, ip->i_gen);
-       if (fs->fs_magic == FS_UFS2_MAGIC) {
-               vfs_timestamp(&ts);
-               ip->i_ffs2_birthtime = ts.tv_sec;
-               ip->i_ffs2_birthnsec = ts.tv_nsec;
-       }
-       return (0);
 noinodes:
        mutex_exit(&ump->um_lock);
        UFS_WAPBL_END(pvp->v_mount);
        ffs_fserr(fs, kauth_cred_geteuid(cred), "out of inodes");
        uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);
-       return (ENOSPC);
+       return ENOSPC;
 }
 
 /*
diff -r 1c2d5526e8a0 -r 739c82759a31 sys/ufs/ffs/ffs_extern.h
--- a/sys/ufs/ffs/ffs_extern.h  Tue Mar 17 09:38:21 2015 +0000
+++ b/sys/ufs/ffs/ffs_extern.h  Tue Mar 17 09:39:29 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_extern.h,v 1.80 2013/06/16 13:33:30 hannken Exp $  */
+/*     $NetBSD: ffs_extern.h,v 1.81 2015/03/17 09:39:29 hannken Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -92,7 +92,7 @@
                  daddr_t *);
 int    ffs_realloccg(struct inode *, daddr_t, daddr_t, int, int ,
                      kauth_cred_t, struct buf **, daddr_t *);
-int    ffs_valloc(struct vnode *, int, kauth_cred_t, struct vnode **);
+int    ffs_valloc(struct vnode *, int, kauth_cred_t, ino_t *);
 daddr_t        ffs_blkpref_ufs1(struct inode *, daddr_t, int, int, int32_t *);
 daddr_t        ffs_blkpref_ufs2(struct inode *, daddr_t, int, int, int64_t *);
 int    ffs_blkalloc(struct inode *, daddr_t, long);
diff -r 1c2d5526e8a0 -r 739c82759a31 sys/ufs/ffs/ffs_vfsops.c
--- a/sys/ufs/ffs/ffs_vfsops.c  Tue Mar 17 09:38:21 2015 +0000
+++ b/sys/ufs/ffs/ffs_vfsops.c  Tue Mar 17 09:39:29 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_vfsops.c,v 1.324 2015/03/15 09:21:01 maxv Exp $    */
+/*     $NetBSD: ffs_vfsops.c,v 1.325 2015/03/17 09:39:29 hannken Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.324 2015/03/15 09:21:01 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.325 2015/03/17 09:39:29 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -114,6 +114,9 @@
 static int ffs_vfs_fsync(vnode_t *, int);
 static int ffs_superblock_validate(struct fs *);
 
+static int ffs_init_vnode(struct ufsmount *, struct vnode *, ino_t);
+static void ffs_deinit_vnode(struct ufsmount *, struct vnode *);
+
 static struct sysctllog *ffs_sysctl_log;
 
 static kauth_listener_t ffs_snapshot_listener;
@@ -150,6 +153,7 @@
        .vfs_sync = ffs_sync,
        .vfs_vget = ufs_vget,
        .vfs_loadvnode = ffs_loadvnode,
+       .vfs_newvnode = ffs_newvnode,
        .vfs_fhtovp = ffs_fhtovp,
        .vfs_vptofh = ffs_vptofh,
        .vfs_init = ffs_init,
@@ -176,8 +180,6 @@
        .uo_itimes = ffs_itimes,
        .uo_update = ffs_update,
        .uo_truncate = ffs_truncate,
-       .uo_valloc = ffs_valloc,
-       .uo_vfree = ffs_vfree,
        .uo_balloc = ffs_balloc,
        .uo_snapgone = ffs_snapgone,
 };
@@ -1927,6 +1929,75 @@
 }
 
 /*
+ * Load inode from disk and initialize vnode.
+ */
+static int
+ffs_init_vnode(struct ufsmount *ump, struct vnode *vp, ino_t ino)
+{
+       struct fs *fs;
+       struct inode *ip;
+       struct buf *bp;
+       int error;
+
+       fs = ump->um_fs;
+
+       /* Read in the disk contents for the inode. */
+       error = bread(ump->um_devvp, FFS_FSBTODB(fs, ino_to_fsba(fs, ino)),
+                     (int)fs->fs_bsize, NOCRED, 0, &bp);
+       if (error)
+               return error;
+
+       /* Allocate and initialize inode. */
+       ip = pool_cache_get(ffs_inode_cache, PR_WAITOK);
+       memset(ip, 0, sizeof(struct inode));
+       ip->i_ump = ump;
+       ip->i_fs = fs;
+       ip->i_dev = ump->um_dev;
+       ip->i_number = ino;
+       if (ump->um_fstype == UFS1)
+               ip->i_din.ffs1_din = pool_cache_get(ffs_dinode1_cache,
+                   PR_WAITOK);
+       else
+               ip->i_din.ffs2_din = pool_cache_get(ffs_dinode2_cache,
+                   PR_WAITOK);
+       ffs_load_inode(bp, ip, fs, ino);
+       brelse(bp, 0);
+       ip->i_vnode = vp;
+#if defined(QUOTA) || defined(QUOTA2)
+       ufsquota_init(ip);
+#endif
+
+       /* Initialise vnode with this inode. */
+       vp->v_tag = VT_UFS;
+       vp->v_op = ffs_vnodeop_p;
+       vp->v_vflag |= VV_LOCKSWORK;
+       vp->v_data = ip;
+
+       /* Initialize genfs node. */
+       genfs_node_init(vp, &ffs_genfsops);
+
+       return 0;
+}
+
+/*
+ * Undo ffs_init_vnode().
+ */
+static void
+ffs_deinit_vnode(struct ufsmount *ump, struct vnode *vp)
+{
+       struct inode *ip = VTOI(vp);
+
+       if (ump->um_fstype == UFS1)
+               pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
+       else
+               pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
+       pool_cache_put(ffs_inode_cache, ip);
+
+       genfs_node_destroy(vp);
+       vp->v_data = NULL;
+}
+
+/*
  * Read an inode from disk and initialize this vnode / inode pair.
  * Caller assures no other thread will try to load this inode.
  */
@@ -1938,49 +2009,23 @@
        struct fs *fs;
        struct inode *ip;
        struct ufsmount *ump;
-       struct buf *bp;
-       dev_t dev;
        int error;
 
        KASSERT(key_len == sizeof(ino));
        memcpy(&ino, key, key_len);
        ump = VFSTOUFS(mp);
-       dev = ump->um_dev;
        fs = ump->um_fs;
 
-       /* Read in the disk contents for the inode. */
-       error = bread(ump->um_devvp, FFS_FSBTODB(fs, ino_to_fsba(fs, ino)),
-                     (int)fs->fs_bsize, NOCRED, 0, &bp);
+       error = ffs_init_vnode(ump, vp, ino);
        if (error)
                return error;
 
-       /* Allocate and initialize inode. */
-       ip = pool_cache_get(ffs_inode_cache, PR_WAITOK);
-       memset(ip, 0, sizeof(struct inode));
-       vp->v_tag = VT_UFS;
-       vp->v_op = ffs_vnodeop_p;
-       vp->v_vflag |= VV_LOCKSWORK;
-       vp->v_data = ip;



Home | Main Index | Thread Index | Old Index