Collect the pieces of lfs rename into lfs_rename.c, and sprinkle static.

This commit is contained in:
dholland 2013-07-20 19:59:31 +00:00
parent 40fd6d6fa3
commit 0e93cfc3cb
6 changed files with 789 additions and 757 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files.ufs,v 1.32 2013/06/08 22:07:24 dholland Exp $
# $NetBSD: files.ufs,v 1.33 2013/07/20 19:59:31 dholland Exp $
deffs FFS
deffs EXT2FS
@ -65,6 +65,7 @@ file ufs/lfs/lfs_cksum.c lfs
file ufs/lfs/lfs_debug.c lfs
file ufs/lfs/lfs_inode.c lfs
file ufs/lfs/lfs_itimes.c lfs
file ufs/lfs/lfs_rename.c lfs
file ufs/lfs/lfs_rfw.c lfs & lfs_kernel_rfw
file ufs/lfs/lfs_segment.c lfs
file ufs/lfs/lfs_subr.c lfs
@ -82,7 +83,6 @@ file ufs/lfs/ulfs_quota1.c lfs & lfs_quota
file ufs/lfs/ulfs_quota2.c lfs & lfs_quota2
file ufs/lfs/ulfs_quota1_subr.c lfs
file ufs/lfs/ulfs_quota2_subr.c lfs & lfs_quota2
file ufs/lfs/ulfs_rename.c lfs
file ufs/lfs/ulfs_snapshot.c lfs
file ufs/lfs/ulfs_vfsops.c lfs
file ufs/lfs/ulfs_vnops.c lfs

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_extern.h,v 1.99 2013/06/06 00:48:04 dholland Exp $ */
/* $NetBSD: lfs_extern.h,v 1.100 2013/07/20 19:59:31 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -167,6 +167,9 @@ struct ulfs1_dinode *lfs_ifind(struct lfs *, ino_t, struct buf *);
void lfs_finalize_ino_seguse(struct lfs *, struct inode *);
void lfs_finalize_fs_seguse(struct lfs *);
/* lfs_rename.c */
int lfs_rename(void *);
/* lfs_rfw.c */
int lfs_rf_valloc(struct lfs *, ino_t, int, struct lwp *, struct vnode **);
void lfs_roll_forward(struct lfs *, struct mount *, struct lwp *);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vnops.c,v 1.248 2013/06/18 18:18:58 christos Exp $ */
/* $NetBSD: lfs_vnops.c,v 1.249 2013/07/20 19:59:31 dholland Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.248 2013/06/18 18:18:58 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.249 2013/07/20 19:59:31 dholland Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -377,25 +377,7 @@ lfs_inactive(void *v)
return ulfs_inactive(v);
}
/*
* These macros are used to bracket ULFS directory ops, so that we can
* identify all the pages touched during directory ops which need to
* be ordered and flushed atomically, so that they may be recovered.
*
* Because we have to mark nodes VU_DIROP in order to prevent
* the cache from reclaiming them while a dirop is in progress, we must
* also manage the number of nodes so marked (otherwise we can run out).
* We do this by setting lfs_dirvcount to the number of marked vnodes; it
* is decremented during segment write, when VU_DIROP is taken off.
*/
#define MARK_VNODE(vp) lfs_mark_vnode(vp)
#define UNMARK_VNODE(vp) lfs_unmark_vnode(vp)
#define SET_DIROP_CREATE(dvp, vpp) lfs_set_dirop_create((dvp), (vpp))
#define SET_DIROP_REMOVE(dvp, vp) lfs_set_dirop((dvp), (vp))
static int lfs_set_dirop_create(struct vnode *, struct vnode **);
static int lfs_set_dirop(struct vnode *, struct vnode *);
static int
int
lfs_set_dirop(struct vnode *dvp, struct vnode *vp)
{
struct lfs *fs;
@ -474,7 +456,7 @@ lfs_set_dirop(struct vnode *dvp, struct vnode *vp)
* NB: this means we have to clear the new vnodes on error. Fortunately
* SET_ENDOP is there to do that for us.
*/
static int
int
lfs_set_dirop_create(struct vnode *dvp, struct vnode **vpp)
{
int error;
@ -501,49 +483,6 @@ lfs_set_dirop_create(struct vnode *dvp, struct vnode **vpp)
return 0;
}
#define SET_ENDOP_BASE(fs, dvp, str) \
do { \
mutex_enter(&lfs_lock); \
--(fs)->lfs_dirops; \
if (!(fs)->lfs_dirops) { \
if ((fs)->lfs_nadirop) { \
panic("SET_ENDOP: %s: no dirops but " \
" nadirop=%d", (str), \
(fs)->lfs_nadirop); \
} \
wakeup(&(fs)->lfs_writer); \
mutex_exit(&lfs_lock); \
lfs_check((dvp), LFS_UNUSED_LBN, 0); \
} else \
mutex_exit(&lfs_lock); \
} while(0)
#define SET_ENDOP_CREATE(fs, dvp, nvpp, str) \
do { \
UNMARK_VNODE(dvp); \
if (nvpp && *nvpp) \
UNMARK_VNODE(*nvpp); \
/* Check for error return to stem vnode leakage */ \
if (nvpp && *nvpp && !((*nvpp)->v_uflag & VU_DIROP)) \
ungetnewvnode(*(nvpp)); \
SET_ENDOP_BASE((fs), (dvp), (str)); \
lfs_reserve((fs), (dvp), NULL, -LFS_NRESERVE(fs)); \
vrele(dvp); \
} while(0)
#define SET_ENDOP_CREATE_AP(ap, str) \
SET_ENDOP_CREATE(VTOI((ap)->a_dvp)->i_lfs, (ap)->a_dvp, \
(ap)->a_vpp, (str))
#define SET_ENDOP_REMOVE(fs, dvp, ovp, str) \
do { \
UNMARK_VNODE(dvp); \
if (ovp) \
UNMARK_VNODE(ovp); \
SET_ENDOP_BASE((fs), (dvp), (str)); \
lfs_reserve((fs), (dvp), (ovp), -LFS_NRESERVE(fs)); \
vrele(dvp); \
if (ovp) \
vrele(ovp); \
} while(0)
void
lfs_mark_vnode(struct vnode *vp)
{
@ -809,131 +748,6 @@ lfs_link(void *v)
return (error);
}
static const struct genfs_rename_ops lfs_genfs_rename_ops;
/*
* lfs_sane_rename: The hairiest vop, with the saner API.
*
* Arguments:
*
* . fdvp (from directory vnode),
* . fcnp (from component name),
* . tdvp (to directory vnode),
* . tcnp (to component name),
* . cred (credentials structure), and
* . posixly_correct (flag for behaviour if target & source link same file).
*
* fdvp and tdvp may be the same, and must be referenced and unlocked.
*/
static int
lfs_sane_rename(
struct vnode *fdvp, struct componentname *fcnp,
struct vnode *tdvp, struct componentname *tcnp,
kauth_cred_t cred, bool posixly_correct)
{
struct ulfs_lookup_results fulr, tulr;
/*
* XXX Provisional kludge -- ulfs_lookup does not reject rename
* of . or .. (from or to), so we hack it here. This is not
* the right place: it should be caller's responsibility to
* reject this case.
*/
KASSERT(fcnp != NULL);
KASSERT(tcnp != NULL);
KASSERT(fcnp != tcnp);
KASSERT(fcnp->cn_nameptr != NULL);
KASSERT(tcnp->cn_nameptr != NULL);
if ((fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT)
return EINVAL; /* XXX EISDIR? */
if ((fcnp->cn_namelen == 1) && (fcnp->cn_nameptr[0] == '.'))
return EINVAL;
if ((tcnp->cn_namelen == 1) && (tcnp->cn_nameptr[0] == '.'))
return EINVAL;
return genfs_sane_rename(&lfs_genfs_rename_ops,
fdvp, fcnp, &fulr, tdvp, tcnp, &tulr,
cred, posixly_correct);
}
/*
* lfs_rename: The hairiest vop, with the insanest API. Defer to
* genfs_insane_rename immediately.
*/
int
lfs_rename(void *v)
{
return genfs_insane_rename(v, &lfs_sane_rename);
}
/*
* lfs_gro_rename: Actually perform the rename operation. Do a little
* LFS bookkeeping and then defer to ulfs_gro_rename.
*/
static int
lfs_gro_rename(struct mount *mp, kauth_cred_t cred,
struct vnode *fdvp, struct componentname *fcnp,
void *fde, struct vnode *fvp,
struct vnode *tdvp, struct componentname *tcnp,
void *tde, struct vnode *tvp)
{
int error;
KASSERT(mp != NULL);
KASSERT(fdvp != NULL);
KASSERT(fcnp != NULL);
KASSERT(fde != NULL);
KASSERT(fvp != NULL);
KASSERT(tdvp != NULL);
KASSERT(tcnp != NULL);
KASSERT(tde != NULL);
KASSERT(fdvp != fvp);
KASSERT(fdvp != tvp);
KASSERT(tdvp != fvp);
KASSERT(tdvp != tvp);
KASSERT(fvp != tvp);
KASSERT(fdvp->v_mount == mp);
KASSERT(fvp->v_mount == mp);
KASSERT(tdvp->v_mount == mp);
KASSERT((tvp == NULL) || (tvp->v_mount == mp));
KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
error = SET_DIROP_REMOVE(tdvp, tvp);
if (error != 0)
return error;
MARK_VNODE(fdvp);
MARK_VNODE(fvp);
error = ulfs_gro_rename(mp, cred,
fdvp, fcnp, fde, fvp,
tdvp, tcnp, tde, tvp);
UNMARK_VNODE(fdvp);
UNMARK_VNODE(fvp);
SET_ENDOP_REMOVE(VFSTOULFS(mp)->um_lfs, tdvp, tvp, "rename");
return error;
}
static const struct genfs_rename_ops lfs_genfs_rename_ops = {
.gro_directory_empty_p = ulfs_gro_directory_empty_p,
.gro_rename_check_possible = ulfs_gro_rename_check_possible,
.gro_rename_check_permitted = ulfs_gro_rename_check_permitted,
.gro_remove_check_possible = ulfs_gro_remove_check_possible,
.gro_remove_check_permitted = ulfs_gro_remove_check_permitted,
.gro_rename = lfs_gro_rename,
.gro_remove = ulfs_gro_remove,
.gro_lookup = ulfs_gro_lookup,
.gro_genealogy = ulfs_gro_genealogy,
.gro_lock_directory = ulfs_gro_lock_directory,
};
/* XXX hack to avoid calling ITIMES in getattr */
int
lfs_getattr(void *v)

View File

@ -1,4 +1,4 @@
/* $NetBSD: ulfs_extern.h,v 1.6 2013/06/08 02:12:56 dholland Exp $ */
/* $NetBSD: ulfs_extern.h,v 1.7 2013/07/20 19:59:31 dholland Exp $ */
/* from NetBSD: ufs_extern.h,v 1.72 2012/05/09 00:21:18 riastradh Exp */
/*-
@ -140,29 +140,6 @@ int ulfs_parentcheck(struct vnode *, struct vnode *, kauth_cred_t,
int *, struct vnode **);
int ulfs_blkatoff(struct vnode *, off_t, char **, struct buf **, bool);
/* ulfs_rename.c -- for lfs */
bool ulfs_gro_directory_empty_p(struct mount *, kauth_cred_t,
struct vnode *, struct vnode *);
int ulfs_gro_rename_check_possible(struct mount *,
struct vnode *, struct vnode *, struct vnode *, struct vnode *);
int ulfs_gro_rename_check_permitted(struct mount *, kauth_cred_t,
struct vnode *, struct vnode *, struct vnode *, struct vnode *);
int ulfs_gro_remove_check_possible(struct mount *,
struct vnode *, struct vnode *);
int ulfs_gro_remove_check_permitted(struct mount *, kauth_cred_t,
struct vnode *, struct vnode *);
int ulfs_gro_rename(struct mount *, kauth_cred_t,
struct vnode *, struct componentname *, void *, struct vnode *,
struct vnode *, struct componentname *, void *, struct vnode *);
int ulfs_gro_remove(struct mount *, kauth_cred_t,
struct vnode *, struct componentname *, void *, struct vnode *);
int ulfs_gro_lookup(struct mount *, struct vnode *,
struct componentname *, void *, struct vnode **);
int ulfs_gro_genealogy(struct mount *, kauth_cred_t,
struct vnode *, struct vnode *, struct vnode **);
int ulfs_gro_lock_directory(struct mount *, struct vnode *);
/* ulfs_quota.c */
/*
* Flags to lfs_chkdq() and lfs_chkiq()

View File

@ -1,4 +1,4 @@
/* $NetBSD: ulfs_inode.h,v 1.9 2013/06/18 18:18:58 christos Exp $ */
/* $NetBSD: ulfs_inode.h,v 1.10 2013/07/20 19:59:31 dholland Exp $ */
/* from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp */
/*
@ -45,6 +45,69 @@
#include <ufs/lfs/ulfs_dinode.h>
#include <ufs/lfs/ulfs_quotacommon.h>
/*
* These macros are used to bracket ULFS directory ops, so that we can
* identify all the pages touched during directory ops which need to
* be ordered and flushed atomically, so that they may be recovered.
*
* Because we have to mark nodes VU_DIROP in order to prevent
* the cache from reclaiming them while a dirop is in progress, we must
* also manage the number of nodes so marked (otherwise we can run out).
* We do this by setting lfs_dirvcount to the number of marked vnodes; it
* is decremented during segment write, when VU_DIROP is taken off.
*/
#define MARK_VNODE(vp) lfs_mark_vnode(vp)
#define UNMARK_VNODE(vp) lfs_unmark_vnode(vp)
#define SET_DIROP_CREATE(dvp, vpp) lfs_set_dirop_create((dvp), (vpp))
#define SET_DIROP_REMOVE(dvp, vp) lfs_set_dirop((dvp), (vp))
int lfs_set_dirop_create(struct vnode *, struct vnode **);
int lfs_set_dirop(struct vnode *, struct vnode *);
#define SET_ENDOP_BASE(fs, dvp, str) \
do { \
mutex_enter(&lfs_lock); \
--(fs)->lfs_dirops; \
if (!(fs)->lfs_dirops) { \
if ((fs)->lfs_nadirop) { \
panic("SET_ENDOP: %s: no dirops but " \
" nadirop=%d", (str), \
(fs)->lfs_nadirop); \
} \
wakeup(&(fs)->lfs_writer); \
mutex_exit(&lfs_lock); \
lfs_check((dvp), LFS_UNUSED_LBN, 0); \
} else \
mutex_exit(&lfs_lock); \
} while(0)
#define SET_ENDOP_CREATE(fs, dvp, nvpp, str) \
do { \
UNMARK_VNODE(dvp); \
if (nvpp && *nvpp) \
UNMARK_VNODE(*nvpp); \
/* Check for error return to stem vnode leakage */ \
if (nvpp && *nvpp && !((*nvpp)->v_uflag & VU_DIROP)) \
ungetnewvnode(*(nvpp)); \
SET_ENDOP_BASE((fs), (dvp), (str)); \
lfs_reserve((fs), (dvp), NULL, -LFS_NRESERVE(fs)); \
vrele(dvp); \
} while(0)
#define SET_ENDOP_CREATE_AP(ap, str) \
SET_ENDOP_CREATE(VTOI((ap)->a_dvp)->i_lfs, (ap)->a_dvp, \
(ap)->a_vpp, (str))
#define SET_ENDOP_REMOVE(fs, dvp, ovp, str) \
do { \
UNMARK_VNODE(dvp); \
if (ovp) \
UNMARK_VNODE(ovp); \
SET_ENDOP_BASE((fs), (dvp), (str)); \
lfs_reserve((fs), (dvp), (ovp), -LFS_NRESERVE(fs)); \
vrele(dvp); \
if (ovp) \
vrele(ovp); \
} while(0)
/* Misc. definitions */
#define BW_CLEAN 1 /* Flag for lfs_bwrite_ext() */
#define PG_DELWRI PG_PAGER1 /* Local def for delayed pageout */