Source-Changes-HG archive

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

[src/trunk]: src Operation sysvbfs_remove() destructs inodes attached to acti...



details:   https://anonhg.NetBSD.org/src/rev/61704afa6677
branches:  trunk
changeset: 325851:61704afa6677
user:      hannken <hannken%NetBSD.org@localhost>
date:      Thu Jan 09 13:23:57 2014 +0000

description:
Operation sysvbfs_remove() destructs inodes attached to active vnodes.
Defer the destruction to sysvbfs_reclaim().

Disable test t_renamerace:sysvbfs_renamerace as it will exhaust the
inode table (sysvbfs has space for 8 inodes only).

Ok: Izumi Tsutsui <tsutsui%netbsd.org@localhost>

diffstat:

 sys/fs/sysvbfs/bfs.c           |  40 ++++++++++++++++++++++++++++++----------
 sys/fs/sysvbfs/bfs.h           |   5 +++--
 sys/fs/sysvbfs/sysvbfs_vnops.c |  11 ++++++++---
 tests/fs/vfs/t_renamerace.c    |   8 +++++++-
 4 files changed, 48 insertions(+), 16 deletions(-)

diffs (183 lines):

diff -r 462ba4b741cf -r 61704afa6677 sys/fs/sysvbfs/bfs.c
--- a/sys/fs/sysvbfs/bfs.c      Thu Jan 09 12:51:27 2014 +0000
+++ b/sys/fs/sysvbfs/bfs.c      Thu Jan 09 13:23:57 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bfs.c,v 1.16 2012/06/11 21:11:40 agc Exp $     */
+/*     $NetBSD: bfs.c,v 1.17 2014/01/09 13:23:57 hannken Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: bfs.c,v 1.16 2012/06/11 21:11:40 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bfs.c,v 1.17 2014/01/09 13:23:57 hannken Exp $");
 #define        BFS_DEBUG
 
 #include <sys/param.h>
@@ -290,7 +290,7 @@
                        return ENOENT;
                }
                attr = inode->attr;     /* copy old attribute */
-               bfs_file_delete(bfs, name);
+               bfs_file_delete(bfs, name, false);
                if ((err = bfs_file_create(bfs, name, buf, bufsz, &attr)) != 0)
                        return err;
        } else {
@@ -308,7 +308,7 @@
 }
 
 int
-bfs_file_delete(struct bfs *bfs, const char *fname)
+bfs_file_delete(struct bfs *bfs, const char *fname, bool keep_inode)
 {
        struct bfs_inode *inode;
        struct bfs_dirent *dirent;
@@ -316,16 +316,18 @@
        if (!bfs_dirent_lookup_by_name(bfs, fname, &dirent))
                return ENOENT;
 
-       if (!bfs_inode_lookup(bfs, dirent->inode, &inode))
+       if (!keep_inode && !bfs_inode_lookup(bfs, dirent->inode, &inode))
                return ENOENT;
 
        memset(dirent, 0, sizeof *dirent);
-       memset(inode, 0, sizeof *inode);
-       bfs->n_inode--;
        bfs->n_dirent--;
+       bfs_writeback_dirent(bfs, dirent, false);
 
-       bfs_writeback_dirent(bfs, dirent, false);
-       bfs_writeback_inode(bfs, inode);
+       if (!keep_inode) {
+               memset(inode, 0, sizeof *inode);
+               bfs->n_inode--;
+               bfs_writeback_inode(bfs, inode);
+       }
        DPRINTF(bfs->debug, "%s: \"%s\" deleted.\n", __func__, fname);
 
        return 0;
@@ -342,7 +344,7 @@
                goto out;
        }
 
-       bfs_file_delete(bfs, to_name);
+       bfs_file_delete(bfs, to_name, false);
        strncpy(dirent->name, to_name, BFS_FILENAME_MAXLEN);
        bfs_writeback_dirent(bfs, dirent, false);
 
@@ -563,6 +565,24 @@
        return true;
 }
 
+int
+bfs_inode_delete(struct bfs *bfs, ino_t ino)
+{
+       struct bfs_inode *inode;
+
+       if (!bfs_inode_lookup(bfs, ino, &inode))
+               return ENOENT;
+
+       memset(inode, 0, sizeof *inode);
+       bfs->n_inode--;
+
+       bfs_writeback_inode(bfs, inode);
+       DPRINTF(bfs->debug, "%s: %lld deleted.\n", __func__, (long long)ino);
+
+       return 0;
+}
+
+
 size_t
 bfs_file_size(const struct bfs_inode *inode)
 {
diff -r 462ba4b741cf -r 61704afa6677 sys/fs/sysvbfs/bfs.h
--- a/sys/fs/sysvbfs/bfs.h      Thu Jan 09 12:51:27 2014 +0000
+++ b/sys/fs/sysvbfs/bfs.h      Thu Jan 09 13:23:57 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bfs.h,v 1.7 2012/05/08 14:28:55 tsutsui Exp $  */
+/*     $NetBSD: bfs.h,v 1.8 2014/01/09 13:23:57 hannken Exp $  */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -150,7 +150,7 @@
 int bfs_file_write(struct bfs *, const char *, void *, size_t);
 int bfs_file_create(struct bfs *, const char *, void *,  size_t,
     const struct bfs_fileattr *);
-int bfs_file_delete(struct bfs *, const char *);
+int bfs_file_delete(struct bfs *, const char *, bool);
 int bfs_file_rename(struct bfs *, const char *, const char *);
 bool bfs_file_lookup(const struct bfs *, const char *, int *, int *,
     size_t *);
@@ -162,6 +162,7 @@
 int sysvbfs_bfs_init(struct bfs **, struct vnode *);
 void sysvbfs_bfs_fini(struct bfs *);
 bool bfs_inode_lookup(const struct bfs *, ino_t, struct bfs_inode **);
+int bfs_inode_delete(struct bfs *, ino_t);
 bool bfs_dirent_lookup_by_name(const struct bfs *, const char *,
     struct bfs_dirent **);
 bool bfs_dirent_lookup_by_inode(const struct bfs *, int,
diff -r 462ba4b741cf -r 61704afa6677 sys/fs/sysvbfs/sysvbfs_vnops.c
--- a/sys/fs/sysvbfs/sysvbfs_vnops.c    Thu Jan 09 12:51:27 2014 +0000
+++ b/sys/fs/sysvbfs/sysvbfs_vnops.c    Thu Jan 09 13:23:57 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysvbfs_vnops.c,v 1.49 2013/12/24 09:56:18 hannken Exp $       */
+/*     $NetBSD: sysvbfs_vnops.c,v 1.50 2014/01/09 13:23:57 hannken Exp $       */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.49 2013/12/24 09:56:18 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.50 2014/01/09 13:23:57 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -523,7 +523,7 @@
        if (vp->v_type == VDIR)
                return EPERM;
 
-       if ((err = bfs_file_delete(bfs, ap->a_cnp->cn_nameptr)) != 0)
+       if ((err = bfs_file_delete(bfs, ap->a_cnp->cn_nameptr, true)) != 0)
                DPRINTF("%s: bfs_file_delete failed.\n", __func__);
 
        VN_KNOTE(ap->a_vp, NOTE_DELETE);
@@ -694,8 +694,13 @@
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
        struct sysvbfs_node *bnode = vp->v_data;
+       struct bfs *bfs = bnode->bmp->bfs;
 
        DPRINTF("%s:\n", __func__);
+       if (bnode->removed) {
+               if (bfs_inode_delete(bfs, bnode->inode->number) != 0)
+                       DPRINTF("%s: delete inode failed\n", __func__);
+       }
        mutex_enter(&mntvnode_lock);
        LIST_REMOVE(bnode, link);
        mutex_exit(&mntvnode_lock);
diff -r 462ba4b741cf -r 61704afa6677 tests/fs/vfs/t_renamerace.c
--- a/tests/fs/vfs/t_renamerace.c       Thu Jan 09 12:51:27 2014 +0000
+++ b/tests/fs/vfs/t_renamerace.c       Thu Jan 09 13:23:57 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_renamerace.c,v 1.29 2013/07/10 18:55:00 reinoud Exp $        */
+/*     $NetBSD: t_renamerace.c,v 1.30 2014/01/09 13:23:57 hannken Exp $        */
 
 /*
  * Modified for rump and atf from a program supplied
@@ -93,6 +93,12 @@
        pthread_t pt1[NWRK], pt2[NWRK];
        int i;
 
+       /*
+        * Sysvbfs supports only 8 inodes so this test would exhaust
+        * the inode table and creating files would fail with ENOSPC.
+        */
+       if (FSTYPE_SYSVBFS(tc))
+               atf_tc_skip("filesystem has not enough inodes");
        if (FSTYPE_RUMPFS(tc))
                atf_tc_skip("rename not supported by file system");
 



Home | Main Index | Thread Index | Old Index