From aaa1a5bdf83e46334090056c58e48b74c444589b Mon Sep 17 00:00:00 2001 From: Niklas Hallqvist Date: Mon, 10 Nov 1997 23:57:07 +0000 Subject: Use vfs lite2 lockmanager. Add advisory locking. some KNF. some extra pathconf ops supported. --- sys/adosfs/adlookup.c | 14 +++--- sys/adosfs/adosfs.h | 8 ++-- sys/adosfs/adutil.c | 42 ++++++++++------- sys/adosfs/advfsops.c | 9 ++-- sys/adosfs/advnops.c | 122 +++++++++++++++++++++++++++++--------------------- 5 files changed, 116 insertions(+), 79 deletions(-) (limited to 'sys/adosfs') diff --git a/sys/adosfs/adlookup.c b/sys/adosfs/adlookup.c index 1e6760cdb90..ff5e551b83f 100644 --- a/sys/adosfs/adlookup.c +++ b/sys/adosfs/adlookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: adlookup.c,v 1.9 1997/11/06 17:23:08 csapuntz Exp $ */ +/* $OpenBSD: adlookup.c,v 1.10 1997/11/10 23:57:04 niklas Exp $ */ /* $NetBSD: adlookup.c,v 1.17 1996/10/25 23:13:58 cgd Exp $ */ /* @@ -123,7 +123,8 @@ adosfs_lookup(v) VOP_UNLOCK(vdp, 0, p); /* race */ error = vget(*vpp, LK_EXCLUSIVE, p); if (error == 0 && lockp && last) - error = vn_lock(vdp, LK_EXCLUSIVE | LK_RETRY, p); + error = + vn_lock(vdp, LK_EXCLUSIVE | LK_RETRY, p); } else { error = vget(*vpp, LK_EXCLUSIVE, p); /* if (lockp == 0 || error || last) */ @@ -230,7 +231,8 @@ adosfs_lookup(v) * not found */ if ((nameiop == CREATE || nameiop == RENAME) && last) { - if ((error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) != 0) { + if ((error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) != 0) + { #ifdef ADOSFS_DIAGNOSTIC printf("[VOP_ACCESS] %d)", error); #endif @@ -253,7 +255,8 @@ adosfs_lookup(v) found: if (nameiop == DELETE && last) { - if ((error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) != 0) { + if ((error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) != 0) + { if (vdp != *vpp) vput(*vpp); *vpp = NULL; @@ -264,7 +267,8 @@ found: if (nameiop == RENAME && wantp && last) { if (vdp == *vpp) return(EISDIR); - if ((error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) != 0) { + if ((error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) != 0) + { vput(*vpp); *vpp = NULL; return (error); diff --git a/sys/adosfs/adosfs.h b/sys/adosfs/adosfs.h index cfb7fd54607..b8017d38b16 100644 --- a/sys/adosfs/adosfs.h +++ b/sys/adosfs/adosfs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: adosfs.h,v 1.6 1997/01/20 15:49:52 niklas Exp $ */ +/* $OpenBSD: adosfs.h,v 1.7 1997/11/10 23:57:04 niklas Exp $ */ /* $NetBSD: adosfs.h,v 1.12 1996/10/08 22:18:02 thorpej Exp $ */ /* @@ -43,7 +43,6 @@ struct datestamp { }; enum anode_type { AROOT, ADIR, AFILE, ALDIR, ALFILE, ASLINK }; -enum anode_flags { AWANT = 0x1, ALOCKED = 0x2 }; /* * similar to inode's, we use to represent: @@ -60,6 +59,8 @@ struct anode { struct datestamp mtime; /* (r/d/f) last modified */ struct adosfsmount *amp; /* owner file system */ struct vnode *vp; /* owner vnode */ + struct lockf *a_lockf; /* byte level lock list */ + struct lock a_lock; /* anode lock */ u_int32_t fsize; /* (f) size of file in bytes */ daddr_t block; /* block num */ daddr_t pblock; /* (d/f/e) parent block */ @@ -76,7 +77,6 @@ struct anode { int adprot; /* (d/f) amigados protection bits */ uid_t uid; /* (d/f) uid of directory/file */ gid_t gid; /* (d/f) gid of directory/file */ - int flags; /* misc flags */ char *slinkto; /* name of file or dir */ }; #define VTOA(vp) ((struct anode *)(vp)->v_data) @@ -135,7 +135,7 @@ struct adosfsmount { /* * utility protos */ -#define adoswordn(bp,wn) ntohl(*((u_int32_t *)(bp)->b_data + (wn))) +#define adoswordn(bp,wn) betoh32(*((u_int32_t *)(bp)->b_data + (wn))) u_int32_t adoscksum __P((struct buf *, int)); int adoscaseequ __P((const char *, const char *, int, int)); diff --git a/sys/adosfs/adutil.c b/sys/adosfs/adutil.c index 01caadd3dd7..cec01c08d17 100644 --- a/sys/adosfs/adutil.c +++ b/sys/adosfs/adutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: adutil.c,v 1.9 1997/11/06 17:23:09 csapuntz Exp $ */ +/* $OpenBSD: adutil.c,v 1.10 1997/11/10 23:57:05 niklas Exp $ */ /* $NetBSD: adutil.c,v 1.15 1996/10/13 02:52:07 christos Exp $ */ /* @@ -37,9 +37,13 @@ #include #include #include +#include #include #include #include + +#include + #include /* @@ -56,24 +60,24 @@ adosfs_ahashget(mp, an) { struct anodechain *hp; struct anode *ap; - struct proc *p = curproc; + struct proc *p = curproc; /* XXX */ + struct vnode *vp; hp = &VFSTOADOSFS(mp)->anodetab[AHASH(an)]; -start_over: - for (ap = hp->lh_first; ap != NULL; ap = ap->link.le_next) { - if (ABLKTOINO(ap->block) != an) - continue; - if (ap->flags & ALOCKED) { - ap->flags |= AWANT; - tsleep(ap, PINOD, "ahashget", 0); - goto start_over; + for (;;) + for (ap = hp->lh_first; ; ap = ap->link.le_next) { + if (ap == NULL) + return (NULL); + if (ABLKTOINO(ap->block) == an) { + vp = ATOV(ap); + simple_lock(&vp->v_interlock); + if (!vget(vp, LK_EXCLUSIVE, p)) + return (vp); + break; + } } - if (vget(ATOV(ap), LK_EXCLUSIVE, p)) - goto start_over; - return (ATOV(ap)); - } - return (NULL); + /* NOTREACHED */ } /* @@ -84,9 +88,13 @@ adosfs_ainshash(amp, ap) struct adosfsmount *amp; struct anode *ap; { + struct proc *p = curproc; /* XXX */ + + /* lock the inode, then put it on the appropriate hash list */ + lockmgr(&ap->a_lock, LK_EXCLUSIVE, (struct simplelock *)0, p); + LIST_INSERT_HEAD(&->anodetab[AHASH(ABLKTOINO(ap->block))], ap, link); - ap->flags |= ALOCKED; } void @@ -175,7 +183,7 @@ adoscksum(bp, n) sum = 0; while (n--) - sum += ntohl(*lp++); + sum += betoh32(*lp++); return(sum); } diff --git a/sys/adosfs/advfsops.c b/sys/adosfs/advfsops.c index fd4c5141800..8f82094e993 100644 --- a/sys/adosfs/advfsops.c +++ b/sys/adosfs/advfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: advfsops.c,v 1.11 1997/11/06 17:23:09 csapuntz Exp $ */ +/* $OpenBSD: advfsops.c,v 1.12 1997/11/10 23:57:05 niklas Exp $ */ /* $NetBSD: advfsops.c,v 1.24 1996/12/22 10:10:12 cgd Exp $ */ /* @@ -45,6 +45,8 @@ #include #include +#include + #include /* XXX */ #include @@ -142,9 +144,9 @@ adosfs_mount(mp, path, data, ndp, p) amp->uid = args.uid; amp->gid = args.gid; amp->mask = args.mask; - (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); + (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); - (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, + (void)copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size); bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); return (0); @@ -376,6 +378,7 @@ adosfs_vget(mp, an, vpp) */ vp->v_data = ap = malloc(sizeof(struct anode), M_ANODE, M_WAITOK); bzero(ap, sizeof(struct anode)); + lockinit(&ap->a_lock, PINOD, "anode", 0, 0); ap->vp = vp; ap->amp = amp; ap->block = AINOTOBLK(an); diff --git a/sys/adosfs/advnops.c b/sys/adosfs/advnops.c index 006db0f076e..cd6e5c6c2d0 100644 --- a/sys/adosfs/advnops.c +++ b/sys/adosfs/advnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: advnops.c,v 1.10 1997/11/06 17:23:09 csapuntz Exp $ */ +/* $OpenBSD: advnops.c,v 1.11 1997/11/10 23:57:06 niklas Exp $ */ /* $NetBSD: advnops.c,v 1.32 1996/10/13 02:52:09 christos Exp $ */ /* @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -45,11 +46,14 @@ #include #include +#include + #include #include extern struct vnodeops adosfs_vnodeops; +int adosfs_advlock __P((void *)); int adosfs_open __P((void *)); int adosfs_getattr __P((void *)); int adosfs_read __P((void *)); @@ -85,7 +89,6 @@ int lease_check __P((void *)); #define adosfs_seek adnullop #define adosfs_vfree adnullop -#define adosfs_advlock adenotsup #define adosfs_blkatoff adenotsup #define adosfs_bwrite adenotsup #define adosfs_create adenotsup @@ -519,32 +522,23 @@ adosfs_lock(v) { struct vop_lock_args /* { struct vnode *a_vp; - } */ *sp = v; - struct vnode *vp; - struct anode *ap; + int a_flags; + struct proc *a_p; + } */ *ap = v; + struct vnode *vp = ap->a_vp; + int rv; #ifdef ADOSFS_DIAGNOSTIC - advopprint(sp); + advopprint(ap); #endif - vp = sp->a_vp; -start: - while (vp->v_flag & VXLOCK) { - vp->v_flag |= VXWANT; - tsleep(vp, PINOD, "adosfs_lock vp", 0); - } - if (vp->v_tag == VT_NON) - return (ENOENT); - ap = VTOA(vp); - if (ap->flags & ALOCKED) { - ap->flags |= AWANT; - tsleep(ap, PINOD, "adosfs_lock ap", 0); - goto start; - } - ap->flags |= ALOCKED; + + rv = lockmgr(&VTOA(vp)->a_lock, ap->a_flags, &vp->v_interlock, + ap->a_p); + #ifdef ADOSFS_DIAGNOSTIC - printf(" 0)"); + printf(" %d)", rv); #endif - return(0); + return (rv); } /* @@ -556,26 +550,23 @@ adosfs_unlock(v) { struct vop_unlock_args /* { struct vnode *a_vp; - } */ *sp = v; - struct anode *ap; + } */ *ap = v; + struct vnode *vp = ap->a_vp; + int rv; #ifdef ADOSFS_DIAGNOSTIC - advopprint(sp); + advopprint(ap); #endif - ap = VTOA(sp->a_vp); - ap->flags &= ~ALOCKED; - if (ap->flags & AWANT) { - ap->flags &= ~AWANT; - wakeup(ap); - } + + rv = lockmgr(&VTOA(vp)->a_lock, ap->a_flags | LK_RELEASE, + &vp->v_interlock, ap->a_p); #ifdef ADOSFS_DIAGNOSTIC - printf(" 0)"); + printf(" %d)", rv); #endif - return(0); + return (rv); } - /* * Wait until the vnode has finished changing state. */ @@ -709,14 +700,36 @@ int adosfs_print(v) void *v; { -#if 0 struct vop_print_args /* { struct vnode *a_vp; - } */ *sp = v; + } */ *ap = v; + struct anode *anp = VTOA(ap->a_vp); + + /* XXX Fill in more info here. */ + printf("tag VT_ADOSFS\n"); +#ifdef DIAGNOSTIC + lockmgr_printinfo(&anp->a_lock); #endif return(0); } +int +adosfs_advlock(v) + void *v; +{ + struct vop_advlock_args /* { + struct vnode *a_vp; + caddr_t a_id; + int a_op; + struct flock *a_fl; + int a_flags; + } */ *ap = v; + register struct anode *anp = VTOA(ap->a_vp); + + return (lf_advlock(&anp->a_lockf, anp->fsize, ap->a_id, ap->a_op, + ap->a_fl, ap->a_flags)); +} + /* This is laid out like a standard dirent, except that it is shorter. */ struct adirent { u_int32_t fileno; @@ -984,14 +997,14 @@ adosfs_islocked(v) { struct vop_islocked_args /* { struct vnode *a_vp; - } */ *sp = v; + } */ *ap = v; int locked; #ifdef ADOSFS_DIAGNOSTIC - advopprint(sp); + advopprint(ap); #endif - locked = (VTOA(sp->a_vp)->flags & ALOCKED) == ALOCKED; + locked = lockstatus(&VTOA(ap->a_vp)->a_lock); #ifdef ADOSFS_DIAGNOSTIC printf(" %d)", locked); @@ -1043,26 +1056,35 @@ adosfs_pathconf(v) struct vnode *a_vp; int a_name; register_t *a_retval; - } */ *sp = v; + } */ *ap = v; - switch (sp->a_name) { + switch (ap->a_name) { + case _PC_CHOWN_RESTRICTED: + *ap->a_retval = 1; + return (0); case _PC_LINK_MAX: - *sp->a_retval = LINK_MAX; + *ap->a_retval = LINK_MAX; return (0); case _PC_MAX_CANON: - *sp->a_retval = MAX_CANON; + *ap->a_retval = MAX_CANON; return (0); case _PC_MAX_INPUT: - *sp->a_retval = MAX_INPUT; + *ap->a_retval = MAX_INPUT; return (0); - case _PC_PIPE_BUF: - *sp->a_retval = PIPE_BUF; + case _PC_NAME_MAX: + *ap->a_retval = 30; return (0); - case _PC_CHOWN_RESTRICTED: - *sp->a_retval = 1; + case _PC_NO_TRUNC: + *ap->a_retval = 0; + return (0); + case _PC_PATH_MAX: + *ap->a_retval = PATH_MAX; + return (0); + case _PC_PIPE_BUF: + *ap->a_retval = PIPE_BUF; return (0); case _PC_VDISABLE: - *sp->a_retval = _POSIX_VDISABLE; + *ap->a_retval = _POSIX_VDISABLE; return (0); default: return (EINVAL); -- cgit v1.2.3