Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/ufs/ext2fs Change ext2fs to use vcache_new like we did f...
details: https://anonhg.NetBSD.org/src/rev/1f4e83e63f17
branches: trunk
changeset: 353926:1f4e83e63f17
user: hannken <hannken%NetBSD.org@localhost>
date: Sun May 28 16:38:55 2017 +0000
description:
Change ext2fs to use vcache_new like we did for ffs:
- Change ext2fs_valloc to return an inode number.
- Make ext2fs_makeinode private to ext2fs_vnops.c and
pass vattr instead of mode.
diffstat:
sys/ufs/ext2fs/ext2fs_alloc.c | 37 +-------
sys/ufs/ext2fs/ext2fs_extern.h | 6 +-
sys/ufs/ext2fs/ext2fs_vfsops.c | 175 +++++++++++++++++++++++++++++++++++-----
sys/ufs/ext2fs/ext2fs_vnops.c | 97 ++++------------------
4 files changed, 179 insertions(+), 136 deletions(-)
diffs (truncated from 520 to 300 lines):
diff -r a8816612e4c8 -r 1f4e83e63f17 sys/ufs/ext2fs/ext2fs_alloc.c
--- a/sys/ufs/ext2fs/ext2fs_alloc.c Sun May 28 16:37:55 2017 +0000
+++ b/sys/ufs/ext2fs/ext2fs_alloc.c Sun May 28 16:38:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ext2fs_alloc.c,v 1.51 2016/08/20 19:53:43 jdolecek Exp $ */
+/* $NetBSD: ext2fs_alloc.c,v 1.52 2017/05/28 16:38:55 hannken Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_alloc.c,v 1.51 2016/08/20 19:53:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_alloc.c,v 1.52 2017/05/28 16:38:55 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -167,16 +167,13 @@
* available inode is located.
*/
int
-ext2fs_valloc(struct vnode *pvp, int mode, kauth_cred_t cred,
- struct vnode **vpp)
+ext2fs_valloc(struct vnode *pvp, int mode, kauth_cred_t cred, ino_t *inop)
{
struct inode *pip;
struct m_ext2fs *fs;
- struct inode *ip;
ino_t ino, ipref;
- int cg, error;
+ int cg;
- *vpp = NULL;
pip = VTOI(pvp);
fs = pip->i_e2fs;
if (fs->e2fs.e2fs_ficount == 0)
@@ -190,32 +187,10 @@
ino = (ino_t)ext2fs_hashalloc(pip, cg, (long)ipref, mode, ext2fs_nodealloccg);
if (ino == 0)
goto noinodes;
- error = VFS_VGET(pvp->v_mount, ino, vpp);
- if (error) {
- ext2fs_vfree(pvp, ino, mode);
- return error;
- }
- ip = VTOI(*vpp);
-
- KASSERT(!E2FS_HAS_GD_CSUM(fs) || (fs->e2fs_gd[ino_to_cg(fs, ino)].ext2bgd_flags & h2fs16(E2FS_BG_INODE_ZEROED)) != 0);
- /* check for already used inode; makes sense only for ZEROED itable */
- if (__predict_false(ip->i_e2fs_mode && ip->i_e2fs_nlink != 0)) {
- printf("mode = 0%o, nlinks %d, inum = %llu, fs = %s\n",
- ip->i_e2fs_mode, ip->i_e2fs_nlink,
- (unsigned long long)ip->i_number, fs->e2fs_fsmnt);
- panic("ext2fs_valloc: dup alloc");
- }
+ *inop = ino;
+ return 0;
- memset(ip->i_din.e2fs_din, 0, EXT2_DINODE_SIZE(fs));
-
- /*
- * Set up a new generation number for this inode.
- */
- if (++ext2gennumber < time_second)
- ext2gennumber = time_second;
- ip->i_e2fs_gen = ext2gennumber;
- return 0;
noinodes:
ext2fs_fserr(fs, kauth_cred_geteuid(cred), "out of inodes");
uprintf("\n%s: create/symlink failed, no inodes free\n", fs->e2fs_fsmnt);
diff -r a8816612e4c8 -r 1f4e83e63f17 sys/ufs/ext2fs/ext2fs_extern.h
--- a/sys/ufs/ext2fs/ext2fs_extern.h Sun May 28 16:37:55 2017 +0000
+++ b/sys/ufs/ext2fs/ext2fs_extern.h Sun May 28 16:38:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ext2fs_extern.h,v 1.55 2016/08/20 19:47:44 jdolecek Exp $ */
+/* $NetBSD: ext2fs_extern.h,v 1.56 2017/05/28 16:38:55 hannken Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -95,7 +95,7 @@
daddr_t *);
int ext2fs_realloccg(struct inode *, daddr_t, daddr_t, int, int ,
kauth_cred_t, struct buf **);
-int ext2fs_valloc(struct vnode *, int, kauth_cred_t, struct vnode **);
+int ext2fs_valloc(struct vnode *, int, kauth_cred_t, ino_t *);
/* XXX ondisk32 */
daddr_t ext2fs_blkpref(struct inode *, daddr_t, int, int32_t *);
void ext2fs_blkfree(struct inode *, daddr_t);
@@ -176,8 +176,6 @@
int ext2fs_fsync(void *);
int ext2fs_vinit(struct mount *, int (**specops)(void *),
int (**fifoops)(void *), struct vnode **);
-int ext2fs_makeinode(int, struct vnode *, struct vnode **,
- struct componentname *cnp, int);
int ext2fs_reclaim(void *);
/* ext2fs_hash.c */
diff -r a8816612e4c8 -r 1f4e83e63f17 sys/ufs/ext2fs/ext2fs_vfsops.c
--- a/sys/ufs/ext2fs/ext2fs_vfsops.c Sun May 28 16:37:55 2017 +0000
+++ b/sys/ufs/ext2fs/ext2fs_vfsops.c Sun May 28 16:38:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ext2fs_vfsops.c,v 1.208 2017/04/17 08:32:01 hannken Exp $ */
+/* $NetBSD: ext2fs_vfsops.c,v 1.209 2017/05/28 16:38:55 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.208 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.209 2017/05/28 16:38:55 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -131,6 +131,7 @@
.vfs_sync = ext2fs_sync,
.vfs_vget = ufs_vget,
.vfs_loadvnode = ext2fs_loadvnode,
+ .vfs_newvnode = ext2fs_newvnode,
.vfs_fhtovp = ext2fs_fhtovp,
.vfs_vptofh = ext2fs_vptofh,
.vfs_init = ext2fs_init,
@@ -966,25 +967,16 @@
}
/*
- * Read an inode from disk and initialize this vnode / inode pair.
- * Caller assures no other thread will try to load this inode.
+ * Load inode from disk and initialize vnode.
*/
-int
-ext2fs_loadvnode(struct mount *mp, struct vnode *vp,
- const void *key, size_t key_len, const void **new_key)
+static int
+ext2fs_init_vnode(struct ufsmount *ump, struct vnode *vp, ino_t ino)
{
- ino_t ino;
struct m_ext2fs *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_e2fs;
/* Read in the disk contents for the inode, copy into the inode. */
@@ -996,25 +988,20 @@
/* Allocate and initialize inode. */
ip = pool_get(&ext2fs_inode_pool, PR_WAITOK);
memset(ip, 0, sizeof(struct inode));
- vp->v_tag = VT_EXT2FS;
- vp->v_op = ext2fs_vnodeop_p;
- vp->v_vflag |= VV_LOCKSWORK;
- vp->v_data = ip;
ip->i_vnode = vp;
ip->i_ump = ump;
ip->i_e2fs = fs;
- ip->i_dev = dev;
+ ip->i_dev = ump->um_dev;
ip->i_number = ino;
ip->i_e2fs_last_lblk = 0;
ip->i_e2fs_last_blk = 0;
- /* Initialize genfs node. */
- genfs_node_init(vp, &ext2fs_genfsops);
-
error = ext2fs_loadvnode_content(fs, ino, bp, ip);
brelse(bp, 0);
- if (error)
+ if (error) {
+ pool_put(&ext2fs_inode_pool, ip);
return error;
+ }
/* If the inode was deleted, reset all fields */
if (ip->i_e2fs_dtime != 0) {
@@ -1024,6 +1011,41 @@
memset(ip->i_e2fs_blocks, 0, sizeof(ip->i_e2fs_blocks));
}
+ /* Initialise vnode with this inode. */
+ vp->v_tag = VT_EXT2FS;
+ vp->v_op = ext2fs_vnodeop_p;
+ vp->v_vflag |= VV_LOCKSWORK;
+ vp->v_data = ip;
+
+ /* Initialize genfs node. */
+ genfs_node_init(vp, &ext2fs_genfsops);
+
+ return 0;
+}
+
+/*
+ * Read an inode from disk and initialize this vnode / inode pair.
+ * Caller assures no other thread will try to load this inode.
+ */
+int
+ext2fs_loadvnode(struct mount *mp, struct vnode *vp,
+ const void *key, size_t key_len, const void **new_key)
+{
+ ino_t ino;
+ struct inode *ip;
+ struct ufsmount *ump;
+ int error;
+
+ KASSERT(key_len == sizeof(ino));
+ memcpy(&ino, key, key_len);
+ ump = VFSTOUFS(mp);
+
+ error = ext2fs_init_vnode(ump, vp, ino);
+ if (error)
+ return error;
+
+ ip = VTOI(vp);
+
/* Initialize the vnode from the inode. */
ext2fs_vinit(mp, ext2fs_specop_p, ext2fs_fifoop_p, &vp);
@@ -1049,6 +1071,113 @@
}
/*
+ * Create a new inode on disk and initialize this vnode / inode pair.
+ */
+int
+ext2fs_newvnode(struct mount *mp, struct vnode *dvp, struct vnode *vp,
+ struct vattr *vap, kauth_cred_t cred,
+ size_t *key_len, const void **new_key)
+{
+ ino_t ino;
+ struct inode *ip, *pdir;
+ struct m_ext2fs *fs;
+ struct ufsmount *ump;
+ int error, mode;
+
+ KASSERT(dvp->v_mount == mp);
+ KASSERT(vap->va_type != VNON);
+
+ *key_len = sizeof(ino);
+
+ pdir = VTOI(dvp);
+ fs = pdir->i_e2fs;
+ ump = VFSTOUFS(mp);
+ mode = MAKEIMODE(vap->va_type, vap->va_mode);
+
+ /* Allocate fresh inode. */
+ error = ext2fs_valloc(dvp, mode, cred, &ino);
+ if (error)
+ return error;
+
+ /* Attach inode to vnode. */
+ error = ext2fs_init_vnode(ump, vp, ino);
+ if (error) {
+ ext2fs_vfree(dvp, ino, mode);
+ return error;
+ }
+
+ ip = VTOI(vp);
+
+ KASSERT(!E2FS_HAS_GD_CSUM(fs) || (fs->e2fs_gd[ino_to_cg(fs, ino)].ext2bgd_flags & h2fs16(E2FS_BG_INODE_ZEROED)) != 0);
+
+ /* check for already used inode; makes sense only for ZEROED itable */
+ if (__predict_false(ip->i_e2fs_mode && ip->i_e2fs_nlink != 0)) {
+ printf("mode = 0%o, nlinks %d, inum = %llu, fs = %s\n",
+ ip->i_e2fs_mode, ip->i_e2fs_nlink,
+ (unsigned long long)ip->i_number, fs->e2fs_fsmnt);
+ panic("ext2fs_valloc: dup alloc");
+ }
+
+ memset(ip->i_din.e2fs_din, 0, EXT2_DINODE_SIZE(fs));
+
+ /*
+ * Set up a new generation number for this inode.
+ */
+ if (++ext2gennumber < time_second)
+ ext2gennumber = time_second;
+ ip->i_e2fs_gen = ext2gennumber;
+
+ ip->i_uid = kauth_cred_geteuid(cred);
+ ip->i_e2fs_uid = ip->i_uid & 0xffff;
+ ip->i_e2fs_gid = pdir->i_e2fs_gid;
+ if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0) {
+ ip->i_e2fs_uid_high = (ip->i_uid >> 16) & 0xffff;
+ ip->i_e2fs_gid_high = pdir->i_e2fs_gid_high;
+ } else {
+ ip->i_e2fs_uid_high = 0;
+ ip->i_e2fs_gid_high = 0;
+ }
+ ip->i_gid = ip->i_e2fs_gid | (ip->i_e2fs_gid_high << 16);
+ ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
+ ip->i_e2fs_mode = mode;
+ vp->v_type = IFTOVT(mode);
Home |
Main Index |
Thread Index |
Old Index