From 8a831a9f229e9937f69438b24d24d98c3724324d Mon Sep 17 00:00:00 2001 From: rwatson Date: Sun, 10 Feb 2008 11:18:12 +0000 Subject: Since we're now actively maintaining the Coda module in the FreeBSD source tree, restyle everything but coda.h (which is more explicitly shared across systems) into a closer approximation to style(9). Remove a few more unused function prototypes. Add or clarify some comments. MFC after: 1 month --- sys/fs/coda/cnode.h | 163 +-- sys/fs/coda/coda_fbsd.c | 75 +- sys/fs/coda/coda_io.h | 46 +- sys/fs/coda/coda_kernel.h | 59 +- sys/fs/coda/coda_namecache.c | 812 ++++++------ sys/fs/coda/coda_namecache.h | 233 ++-- sys/fs/coda/coda_opstats.h | 117 +- sys/fs/coda/coda_pioctl.h | 51 +- sys/fs/coda/coda_psdev.c | 970 +++++++-------- sys/fs/coda/coda_psdev.h | 21 +- sys/fs/coda/coda_subr.c | 658 +++++----- sys/fs/coda/coda_subr.h | 44 +- sys/fs/coda/coda_venus.c | 985 +++++++-------- sys/fs/coda/coda_venus.h | 164 +-- sys/fs/coda/coda_vfsops.c | 632 +++++----- sys/fs/coda/coda_vfsops.h | 39 +- sys/fs/coda/coda_vnops.c | 2800 ++++++++++++++++++++++-------------------- sys/fs/coda/coda_vnops.h | 87 +- 18 files changed, 4002 insertions(+), 3954 deletions(-) (limited to 'sys/fs') diff --git a/sys/fs/coda/cnode.h b/sys/fs/coda/cnode.h index 6f040c0..c1c5441 100644 --- a/sys/fs/coda/cnode.h +++ b/sys/fs/coda/cnode.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,21 +14,21 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * - * @(#) src/sys/coda/cnode.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ + * + * @(#) src/sys/coda/cnode.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * + * */ /*- @@ -53,25 +53,25 @@ MALLOC_DECLARE(M_CODA); /* - * tmp below since we need struct queue + * tmp below since we need struct queue. */ #include /* * Cnode lookup stuff. + * * NOTE: CODA_CACHESIZE must be a power of 2 for cfshash to work! */ -#define CODA_CACHESIZE 512 - -#define CODA_ALLOC(ptr, cast, size) \ -do { \ - ptr = (cast)malloc((unsigned long) size, M_CODA, M_WAITOK); \ - if (ptr == 0) { \ - panic("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__); \ - } \ +#define CODA_CACHESIZE 512 + +#define CODA_ALLOC(ptr, cast, size) do { \ + ptr = (cast)malloc((unsigned long) size, M_CODA, M_WAITOK); \ + if (ptr == NULL) \ + panic("kernel malloc returns 0 at %s:%d\n", __FILE__, \ + __LINE__); \ } while (0) -#define CODA_FREE(ptr, size) free((ptr), M_CODA) +#define CODA_FREE(ptr, size) free((ptr), M_CODA) /* * Used to select debugging statements throughout the cfs code. @@ -82,41 +82,46 @@ extern int coda_vnop_print_entry; extern int coda_psdev_print_entry; extern int coda_vfsop_print_entry; -#define CODADBGMSK(N) (1 << N) -#define CODADEBUG(N, STMT) { if (codadebug & CODADBGMSK(N)) { STMT } } -#define myprintf(args) \ -do { \ - if (coda_printf_delay) \ - DELAY(coda_printf_delay);\ - printf args ; \ +#define CODADBGMSK(N) (1 << N) + +#define CODADEBUG(N, STMT) do { \ + if (codadebug & CODADBGMSK(N)) { \ + STMT \ + } \ +} while (0) + +#define myprintf(args) do { \ + if (coda_printf_delay) \ + DELAY(coda_printf_delay); \ + printf args ; \ } while (0) struct cnode { - struct vnode *c_vnode; - u_short c_flags; /* flags (see below) */ - CodaFid c_fid; /* file handle */ - struct vnode *c_ovp; /* open vnode pointer */ - u_short c_ocount; /* count of openers */ - u_short c_owrite; /* count of open for write */ - struct vattr c_vattr; /* attributes */ - char *c_symlink; /* pointer to symbolic link */ - u_short c_symlen; /* length of symbolic link */ - struct cnode *c_next; /* links if on FreeBSD machine */ + struct vnode *c_vnode; + u_short c_flags; /* flags (see below) */ + CodaFid c_fid; /* file handle */ + struct vnode *c_ovp; /* open vnode pointer */ + u_short c_ocount; /* count of openers */ + u_short c_owrite; /* count of open for write */ + struct vattr c_vattr; /* attributes */ + char *c_symlink; /* pointer to symbolic link */ + u_short c_symlen; /* length of symbolic link */ + struct cnode *c_next; /* links if on FreeBSD machine */ }; #define VTOC(vp) ((struct cnode *)(vp)->v_data) #define CTOV(cp) ((struct vnode *)((cp)->c_vnode)) /* flags */ -#define C_VATTR 0x01 /* Validity of vattr in the cnode */ -#define C_SYMLINK 0x02 /* Validity of symlink pointer in the Code */ -#define C_WANTED 0x08 /* Set if lock wanted */ -#define C_LOCKED 0x10 /* Set if lock held */ -#define C_UNMOUNTING 0X20 /* Set if unmounting */ -#define C_PURGING 0x40 /* Set if purging a fid */ +#define C_VATTR 0x01 /* Validity of vattr in the cnode */ +#define C_SYMLINK 0x02 /* Validity of symlink pointer in the Code */ +#define C_WANTED 0x08 /* Set if lock wanted */ +#define C_LOCKED 0x10 /* Set if lock held */ +#define C_UNMOUNTING 0X20 /* Set if unmounting */ +#define C_PURGING 0x40 /* Set if purging a fid */ -#define VALID_VATTR(cp) ((cp->c_flags) & C_VATTR) -#define VALID_SYMLINK(cp) ((cp->c_flags) & C_SYMLINK) -#define IS_UNMOUNTING(cp) ((cp)->c_flags & C_UNMOUNTING) +#define VALID_VATTR(cp) ((cp->c_flags) & C_VATTR) +#define VALID_SYMLINK(cp) ((cp->c_flags) & C_SYMLINK) +#define IS_UNMOUNTING(cp) ((cp)->c_flags & C_UNMOUNTING) struct vcomm { u_long vc_seq; @@ -125,9 +130,9 @@ struct vcomm { struct queue vc_replys; }; -#define VC_OPEN(vcp) ((vcp)->vc_requests.forw != NULL) -#define MARK_VC_CLOSED(vcp) (vcp)->vc_requests.forw = NULL; -#define MARK_VC_OPEN(vcp) /* MT */ +#define VC_OPEN(vcp) ((vcp)->vc_requests.forw != NULL) +#define MARK_VC_CLOSED(vcp) (vcp)->vc_requests.forw = NULL; +#define MARK_VC_OPEN(vcp) /* MT */ struct coda_clstat { int ncalls; /* client requests */ @@ -137,61 +142,63 @@ struct coda_clstat { extern struct coda_clstat coda_clstat; /* - * CODA structure to hold mount/filesystem information + * CODA structure to hold mount/filesystem information. */ struct coda_mntinfo { - struct vnode *mi_rootvp; - struct mount *mi_vfsp; - struct vcomm mi_vcomm; - struct cdev *dev; - int mi_started; - LIST_ENTRY(coda_mntinfo) mi_list; + struct vnode *mi_rootvp; + struct mount *mi_vfsp; + struct vcomm mi_vcomm; + struct cdev *dev; + int mi_started; + LIST_ENTRY(coda_mntinfo) mi_list; }; struct coda_mntinfo *dev2coda_mntinfo(struct cdev *dev); /* - * vfs pointer to mount info + * vfs pointer to mount info. */ -#define vftomi(vfsp) ((struct coda_mntinfo *)(vfsp->mnt_data)) -#define CODA_MOUNTED(vfsp) (vftomi((vfsp)) != (struct coda_mntinfo *)0) +#define vftomi(vfsp) ((struct coda_mntinfo *)(vfsp->mnt_data)) +#define CODA_MOUNTED(vfsp) (vftomi((vfsp)) != NULL) /* - * vnode pointer to mount info + * vnode pointer to mount info. */ -#define vtomi(vp) ((struct coda_mntinfo *)(vp->v_mount->mnt_data)) +#define vtomi(vp) ((struct coda_mntinfo *)(vp->v_mount->mnt_data)) /* - * Used for identifying usage of "Control" object + * Used for identifying usage of "Control" object. */ extern struct vnode *coda_ctlvp; -#define IS_CTL_VP(vp) ((vp) == coda_ctlvp) -#define IS_CTL_NAME(vp, name, l)((l == CODA_CONTROLLEN) \ - && ((vp) == vtomi((vp))->mi_rootvp) \ - && strncmp(name, CODA_CONTROL, l) == 0) - -/* - * An enum to tell us whether something that will remove a reference - * to a cnode was a downcall or not +#define IS_CTL_VP(vp) ((vp) == coda_ctlvp) +#define IS_CTL_NAME(vp, name, l) ((l == CODA_CONTROLLEN) \ + && ((vp) == vtomi((vp))->mi_rootvp) && \ + strncmp(name, CODA_CONTROL, l) == 0) + +/* + * An enum to tell us whether something that will remove a reference to a + * cnode was a downcall or not. */ enum dc_status { - IS_DOWNCALL = 6, - NOT_DOWNCALL = 7 + IS_DOWNCALL = 6, + NOT_DOWNCALL = 7 }; /* cfs_psdev.h */ -int coda_call(struct coda_mntinfo *mntinfo, int inSize, int *outSize, caddr_t buffer); +int coda_call(struct coda_mntinfo *mntinfo, int inSize, int *outSize, + caddr_t buffer); + extern int coda_kernel_version; /* cfs_subr.h */ -int handleDownCall(int opcode, union outputArgs *out); -void coda_unmounting(struct mount *whoIam); -int coda_vmflush(struct cnode *cp); +int handleDownCall(int opcode, union outputArgs *out); +void coda_unmounting(struct mount *whoIam); +int coda_vmflush(struct cnode *cp); /* cfs_vnodeops.h */ -struct cnode *make_coda_node(CodaFid *fid, struct mount *vfsp, short type); -int coda_vnodeopstats_init(void); +struct cnode *make_coda_node(CodaFid *fid, struct mount *vfsp, short type); +int coda_vnodeopstats_init(void); /* sigh */ -#define CODA_RDWR ((u_long) 31) +#define CODA_RDWR ((u_long) 31) -#endif /* _CNODE_H_ */ +#endif /* _CNODE_H_ */ diff --git a/sys/fs/coda/coda_fbsd.c b/sys/fs/coda/coda_fbsd.c index ab1e360..765c3fd 100644 --- a/sys/fs/coda/coda_fbsd.c +++ b/sys/fs/coda/coda_fbsd.c @@ -1,10 +1,10 @@ /*- * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -13,18 +13,18 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ */ @@ -66,17 +66,20 @@ static eventhandler_tag clonetag; static LIST_HEAD(, coda_mntinfo) coda_mnttbl; -int vcdebug = 1; -#define VCDEBUG if (vcdebug) printf - -/* for DEVFS, using bpf & tun drivers as examples*/ +/* + * For DEVFS, using bpf & tun drivers as examples. + * + * XXX: Why use a cloned interface, aren't we really just interested in + * having a single /dev/cfs0? It's not clear the coda module knows what to + * do with more than one. + */ static void coda_fbsd_clone(void *arg, struct ucred *cred, char *name, int namelen, struct cdev **dev); static int codadev_modevent(module_t mod, int type, void *data) { - struct coda_mntinfo *mnt; + struct coda_mntinfo *mnt; switch (type) { case MOD_LOAD: @@ -84,7 +87,14 @@ codadev_modevent(module_t mod, int type, void *data) clonetag = EVENTHANDLER_REGISTER(dev_clone, coda_fbsd_clone, 0, 1000); break; + case MOD_UNLOAD: + /* + * XXXRW: At the very least, a busy check should occur here + * to prevent untimely unload. Much more serious collection + * of allocated memory needs to take place; right now we leak + * like a sieve. + */ EVENTHANDLER_DEREGISTER(dev_clone, clonetag); while ((mnt = LIST_FIRST(&coda_mnttbl)) != NULL) { LIST_REMOVE(mnt, mi_list); @@ -96,8 +106,9 @@ codadev_modevent(module_t mod, int type, void *data) default: return (EOPNOTSUPP); } - return 0; + return (0); } + static moduledata_t codadev_mod = { "codadev", codadev_modevent, @@ -105,37 +116,33 @@ static moduledata_t codadev_mod = { }; DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); -static void coda_fbsd_clone(arg, cred, name, namelen, dev) - void *arg; - struct ucred *cred; - char *name; - int namelen; - struct cdev **dev; +static void +coda_fbsd_clone(void *arg, struct ucred *cred, char *name, int namelen, + struct cdev **dev) { - int u; - struct coda_mntinfo *mnt; - - if (*dev != NULL) - return; - if (dev_stdclone(name,NULL,"cfs",&u) != 1) - return; - - *dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u); - dev_ref(*dev); - mnt = malloc(sizeof(struct coda_mntinfo), M_CODA, M_WAITOK|M_ZERO); - LIST_INSERT_HEAD(&coda_mnttbl, mnt, mi_list); - mnt->dev = *dev; + struct coda_mntinfo *mnt; + int u; + + if (*dev != NULL) + return; + if (dev_stdclone(name, NULL, "cfs", &u) != 1) + return; + *dev = make_dev(&codadevsw, unit2minor(u), UID_ROOT, GID_WHEEL, 0600, + "cfs%d", u); + dev_ref(*dev); + mnt = malloc(sizeof(struct coda_mntinfo), M_CODA, M_WAITOK|M_ZERO); + LIST_INSERT_HEAD(&coda_mnttbl, mnt, mi_list); + mnt->dev = *dev; } struct coda_mntinfo * dev2coda_mntinfo(struct cdev *dev) { - struct coda_mntinfo *mnt; + struct coda_mntinfo *mnt; LIST_FOREACH(mnt, &coda_mnttbl, mi_list) { if (mnt->dev == dev) - return mnt; + return (mnt); } - - return NULL; + return (NULL); } diff --git a/sys/fs/coda/coda_io.h b/sys/fs/coda/coda_io.h index 1985b01..6058cf0 100644 --- a/sys/fs/coda/coda_io.h +++ b/sys/fs/coda/coda_io.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,21 +14,21 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * - * @(#) src/sys/coda/coda_io.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ + * + * @(#) src/sys/coda/coda_io.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * + * */ /*- @@ -45,15 +45,29 @@ */ #ifndef _CODAIO_H_ -#define _CODAIO_H_ +#define _CODAIO_H_ -/* Define ioctl commands for vcioctl, /dev/cfs */ +/* + * Define ioctl commands for vcioctl, /dev/cfs. + * + * Resize Coda namecache. + */ +#define CODARESIZE _IOW('c', 1, struct coda_resize) -#define CODARESIZE _IOW('c', 1, struct coda_resize ) /* Resize CODA NameCache */ -#define CODASTATS _IO('c', 2) /* Collect stats */ -#define CODAPRINT _IO('c', 3) /* Print Cache */ -#define CODATEST _IO('c', 4) /* Print Cache */ +/* + * Collect statistics. + */ +#define CODASTATS _IO('c', 2) + +/* + * Print cache. + */ +#define CODAPRINT _IO('c', 3) +#define CODATEST _IO('c', 4) -struct coda_resize { int hashsize, heapsize; }; +struct coda_resize { + int hashsize; + int heapsize; +}; -#endif +#endif /* !_CODAIO_H_ */ diff --git a/sys/fs/coda/coda_kernel.h b/sys/fs/coda/coda_kernel.h index fd365b8..a326063 100644 --- a/sys/fs/coda/coda_kernel.h +++ b/sys/fs/coda/coda_kernel.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,53 +14,54 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * - * @(#) src/sys/coda/coda_kernel.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ + * + * @(#) src/sys/coda/coda_kernel.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * + * */ -/* Macros to manipulate the queue */ +/* + * Macros to manipulate the queue. + * + * XXX: It would be good to replace this with use of queue(9) throughout the + * Coda kernel module. + */ #ifndef INIT_QUEUE + struct queue { - struct queue *forw, *back; + struct queue *forw, *back; }; -#define INIT_QUEUE(head) \ -do { \ - (head).forw = (struct queue *)&(head); \ - (head).back = (struct queue *)&(head); \ +#define INIT_QUEUE(head) do { \ + (head).forw = (struct queue *)&(head); \ + (head).back = (struct queue *)&(head); \ } while (0) -#define GETNEXT(head) (head).forw - -#define EMPTY(head) ((head).forw == &(head)) +#define GETNEXT(head) (head).forw +#define EMPTY(head) ((head).forw == &(head)) +#define EOQ(el, head) ((struct queue *)(el) == (struct queue *)&(head)) -#define EOQ(el, head) ((struct queue *)(el) == (struct queue *)&(head)) - -#define INSQUE(el, head) \ -do { \ - (el).forw = ((head).back)->forw; \ - (el).back = (head).back; \ - ((head).back)->forw = (struct queue *)&(el); \ - (head).back = (struct queue *)&(el); \ +#define INSQUE(el, head) do { \ + (el).forw = ((head).back)->forw; \ + (el).back = (head).back; \ + ((head).back)->forw = (struct queue *)&(el); \ + (head).back = (struct queue *)&(el); \ } while (0) -#define REMQUE(el) \ -do { \ - ((el).forw)->back = (el).back; \ - (el).back->forw = (el).forw; \ +#define REMQUE(el) do { \ + ((el).forw)->back = (el).back; \ + (el).back->forw = (el).forw; \ } while (0) #endif diff --git a/sys/fs/coda/coda_namecache.c b/sys/fs/coda/coda_namecache.c index 4fed042..617634f 100644 --- a/sys/fs/coda/coda_namecache.c +++ b/sys/fs/coda/coda_namecache.c @@ -1,10 +1,10 @@ /*- * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -13,18 +13,18 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/coda/coda_namecache.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ */ /*- @@ -41,33 +41,34 @@ */ /* - * This module contains the routines to implement the CODA name cache. The - * purpose of this cache is to reduce the cost of translating pathnames - * into Vice FIDs. Each entry in the cache contains the name of the file, - * the vnode (FID) of the parent directory, and the cred structure of the - * user accessing the file. + * This module contains the routines to implement the CODA name cache. The + * purpose of this cache is to reduce the cost of translating pathnames into + * Vice FIDs. Each entry in the cache contains the name of the file, the + * vnode (FID) of the parent directory, and the cred structure of the user + * accessing the file. * * The first time a file is accessed, it is looked up by the local Venus - * which first insures that the user has access to the file. In addition - * we are guaranteed that Venus will invalidate any name cache entries in - * case the user no longer should be able to access the file. For these - * reasons we do not need to keep access list information as well as a - * cred structure for each entry. + * which first ensures that the user has access to the file. In addition we + * are guaranteed that Venus will invalidate any name cache entries in case + * the user no longer should be able to access the file. For these reasons we + * do not need to keep access list information as well as a cred structure + * for each entry. * - * The table can be accessed through the routines cnc_init(), cnc_enter(), - * cnc_lookup(), cnc_rmfidcred(), cnc_rmfid(), cnc_rmcred(), and cnc_purge(). - * There are several other routines which aid in the implementation of the - * hash table. + * The table can be accessed through the routines coda_nc_init(), + * coda_nc_enter(), coda_nc_lookup(), coda_nc_rmfidcred(), coda_nc_rmfid(), + * coda_nc_rmcred(), and coda_nc_purge(). There are several other routines + * which aid in the implementation of the hash table. */ -/* +/*- * NOTES: rvb@cs - * 1. The name cache holds a reference to every vnode in it. Hence files can not be - * closed or made inactive until they are released. - * 2. coda_nc_name(cp) was added to get a name for a cnode pointer for debugging. - * 3. coda_nc_find() has debug code to detect when entries are stored with different - * credentials. We don't understand yet, if/how entries are NOT EQ but still - * EQUAL + * 1. The name cache holds a reference to every vnode in it. Hence files + * can not be closed or made inactive until they are released. + * 2. coda_nc_name(cp) was added to get a name for a cnode pointer for + * debugging. + * 3. coda_nc_find() has debug code to detect when entries are stored with + * different credentials. We don't understand yet, if/how entries are + * NOT EQ but still EQUAL. * 4. I wonder if this name cache could be replace by the vnode name cache. * The latter has no zapping functions, so probably not. */ @@ -90,290 +91,268 @@ __FBSDID("$FreeBSD$"); #include #include -#ifdef DEBUG +#ifdef DEBUG #include #endif -/* +/* * Declaration of the name cache data structure. */ +int coda_nc_use = 1; /* Indicate use of CODA Name Cache */ +int coda_nc_size = CODA_NC_CACHESIZE; /* size of the cache */ +int coda_nc_hashsize = CODA_NC_HASHSIZE; /* size of the primary hash */ -int coda_nc_use = 1; /* Indicate use of CODA Name Cache */ -int coda_nc_size = CODA_NC_CACHESIZE; /* size of the cache */ -int coda_nc_hashsize = CODA_NC_HASHSIZE; /* size of the primary hash */ - -struct coda_cache *coda_nc_heap; /* pointer to the cache entries */ -struct coda_hash *coda_nc_hash; /* hash table of coda_cache pointers */ -struct coda_lru coda_nc_lru; /* head of lru chain */ - +struct coda_cache *coda_nc_heap; /* pointer to the cache entries */ +struct coda_hash *coda_nc_hash; /* hash table of coda_cache pointers */ +struct coda_lru coda_nc_lru; /* head of lru chain */ struct coda_nc_statistics coda_nc_stat; /* Keep various stats */ -/* - * for testing purposes +/* + * For testing purposes. */ int coda_nc_debug = 0; /* - * Entry points for the CODA Name Cache + * Entry points for the CODA Name Cache. */ -static struct coda_cache *coda_nc_find(struct cnode *dcp, const char *name, int namelen, - struct ucred *cred, int hash); -static void coda_nc_remove(struct coda_cache *cncp, enum dc_status dcstat); +static struct coda_cache *coda_nc_find(struct cnode *dcp, + const char *name, int namelen, + struct ucred *cred, int hash); +static void coda_nc_remove(struct coda_cache *cncp, + enum dc_status dcstat); -/* - * Initialize the cache, the LRU structure and the Hash structure(s) +/* + * Initialize the cache, the LRU structure and the Hash structure(s). */ - -#define TOTAL_CACHE_SIZE (sizeof(struct coda_cache) * coda_nc_size) -#define TOTAL_HASH_SIZE (sizeof(struct coda_hash) * coda_nc_hashsize) +#define TOTAL_CACHE_SIZE (sizeof(struct coda_cache) * coda_nc_size) +#define TOTAL_HASH_SIZE (sizeof(struct coda_hash) * coda_nc_hashsize) int coda_nc_initialized = 0; /* Initially the cache has not been initialized */ void coda_nc_init(void) { - int i; + int i; - /* zero the statistics structure */ - - bzero(&coda_nc_stat, (sizeof(struct coda_nc_statistics))); + bzero(&coda_nc_stat, (sizeof(struct coda_nc_statistics))); -#ifdef CODA_VERBOSE - printf("CODA NAME CACHE: CACHE %d, HASH TBL %d\n", CODA_NC_CACHESIZE, CODA_NC_HASHSIZE); +#ifdef CODA_VERBOSE + printf("CODA NAME CACHE: CACHE %d, HASH TBL %d\n", CODA_NC_CACHESIZE, + CODA_NC_HASHSIZE); #endif - CODA_ALLOC(coda_nc_heap, struct coda_cache *, TOTAL_CACHE_SIZE); - CODA_ALLOC(coda_nc_hash, struct coda_hash *, TOTAL_HASH_SIZE); - - coda_nc_lru.lru_next = - coda_nc_lru.lru_prev = (struct coda_cache *)LRU_PART(&coda_nc_lru); - - - for (i=0; i < coda_nc_size; i++) { /* initialize the heap */ - CODA_NC_LRUINS(&coda_nc_heap[i], &coda_nc_lru); - CODA_NC_HSHNUL(&coda_nc_heap[i]); - coda_nc_heap[i].cp = coda_nc_heap[i].dcp = (struct cnode *)0; - } - - for (i=0; i < coda_nc_hashsize; i++) { /* initialize the hashtable */ - CODA_NC_HSHNUL((struct coda_cache *)&coda_nc_hash[i]); - } - - coda_nc_initialized++; + CODA_ALLOC(coda_nc_heap, struct coda_cache *, TOTAL_CACHE_SIZE); + CODA_ALLOC(coda_nc_hash, struct coda_hash *, TOTAL_HASH_SIZE); + coda_nc_lru.lru_next = coda_nc_lru.lru_prev = + (struct coda_cache *)LRU_PART(&coda_nc_lru); + + /* + * Initialize the heap. + */ + for (i=0; i < coda_nc_size; i++) { + CODA_NC_LRUINS(&coda_nc_heap[i], &coda_nc_lru); + CODA_NC_HSHNUL(&coda_nc_heap[i]); + coda_nc_heap[i].cp = coda_nc_heap[i].dcp = NULL; + } + + /* + * Initialize the hashtable. + */ + for (i=0; i < coda_nc_hashsize; i++) + CODA_NC_HSHNUL((struct coda_cache *)&coda_nc_hash[i]); + coda_nc_initialized++; } /* - * Auxillary routines -- shouldn't be entry points + * Auxillary routines -- shouldn't be entry points. */ - static struct coda_cache * -coda_nc_find(dcp, name, namelen, cred, hash) - struct cnode *dcp; - const char *name; - int namelen; - struct ucred *cred; - int hash; +coda_nc_find(struct cnode *dcp, const char *name, int namelen, + struct ucred *cred, int hash) { - /* - * hash to find the appropriate bucket, look through the chain - * for the right entry (especially right cred, unless cred == 0) - */ struct coda_cache *cncp; int count = 1; - CODA_NC_DEBUG(CODA_NC_FIND, - myprintf(("coda_nc_find(dcp %p, name %s, len %d, cred %p, hash %d\n", - dcp, name, namelen, cred, hash));) - - for (cncp = coda_nc_hash[hash].hash_next; - cncp != (struct coda_cache *)&coda_nc_hash[hash]; - cncp = cncp->hash_next, count++) - { - - if ((CODA_NAMEMATCH(cncp, name, namelen, dcp)) && - ((cred == 0) || (cncp->cred == cred))) - { - /* compare cr_uid instead */ - coda_nc_stat.Search_len += count; - return(cncp); - } -#ifdef DEBUG - else if (CODA_NAMEMATCH(cncp, name, namelen, dcp)) { - printf("coda_nc_find: name %s, new cred = %p, cred = %p\n", - name, cred, cncp->cred); - printf("nref %d, nuid %d, ngid %d // oref %d, ocred %d, ogid %d\n", - cred->cr_ref, cred->cr_uid, cred->cr_gid, - cncp->cred->cr_ref, cncp->cred->cr_uid, cncp->cred->cr_gid); - coda_print_cred(cred); - coda_print_cred(cncp->cred); - } + /* + * Hash to find the appropriate bucket, look through the chain for + * the right entry (especially right cred, unless cred == 0). + */ + CODA_NC_DEBUG(CODA_NC_FIND, myprintf(("coda_nc_find(dcp %p, name %s, " + "len %d, cred %p, hash %d\n", dcp, name, namelen, cred, hash));); + for (cncp = coda_nc_hash[hash].hash_next; + cncp != (struct coda_cache *)&coda_nc_hash[hash]; + cncp = cncp->hash_next, count++) { + if ((CODA_NAMEMATCH(cncp, name, namelen, dcp)) && + ((cred == 0) || (cncp->cred == cred))) { + /* Compare cr_uid instead. */ + coda_nc_stat.Search_len += count; + return (cncp); + } +#ifdef DEBUG + else if (CODA_NAMEMATCH(cncp, name, namelen, dcp)) { + printf("coda_nc_find: name %s, new cred = %p, " + "cred = %p\n", name, cred, cncp->cred); + printf("nref %d, nuid %d, ngid %d // oref %d, " + "ocred %d, ogid %d\n", cred->cr_ref, + cred->cr_uid, cred->cr_gid, cncp->cred->cr_ref, + cncp->cred->cr_uid, cncp->cred->cr_gid); + coda_print_cred(cred); + coda_print_cred(cncp->cred); + } #endif } - - return((struct coda_cache *)0); + return (NULL); } /* - * Enter a new (dir cnode, name) pair into the cache, updating the - * LRU and Hash as needed. + * Enter a new (dir cnode, name) pair into the cache, updating the LRU and + * Hash as needed. */ void -coda_nc_enter(dcp, name, namelen, cred, cp) - struct cnode *dcp; - const char *name; - int namelen; - struct ucred *cred; - struct cnode *cp; +coda_nc_enter(struct cnode *dcp, const char *name, int namelen, + struct ucred *cred, struct cnode *cp) { - struct coda_cache *cncp; - int hash; - - if (coda_nc_use == 0) /* Cache is off */ - return; - - CODA_NC_DEBUG(CODA_NC_ENTER, - myprintf(("Enter: dcp %p cp %p name %s cred %p \n", - dcp, cp, name, cred)); ) - - if (namelen > CODA_NC_NAMELEN) { - CODA_NC_DEBUG(CODA_NC_ENTER, - myprintf(("long name enter %s\n",name));) - coda_nc_stat.long_name_enters++; /* record stats */ - return; - } - - hash = CODA_NC_HASH(name, namelen, dcp); - cncp = coda_nc_find(dcp, name, namelen, cred, hash); - if (cncp != (struct coda_cache *) 0) { - coda_nc_stat.dbl_enters++; /* duplicate entry */ - return; - } - - coda_nc_stat.enters++; /* record the enters statistic */ - - /* Grab the next element in the lru chain */ - cncp = CODA_NC_LRUGET(coda_nc_lru); - - CODA_NC_LRUREM(cncp); /* remove it from the lists */ - - if (CODA_NC_VALID(cncp)) { - /* Seems really ugly, but we have to decrement the appropriate - hash bucket length here, so we have to find the hash bucket - */ - coda_nc_hash[CODA_NC_HASH(cncp->name, cncp->namelen, cncp->dcp)].length--; - - coda_nc_stat.lru_rm++; /* zapped a valid entry */ - CODA_NC_HSHREM(cncp); - vrele(CTOV(cncp->dcp)); - vrele(CTOV(cncp->cp)); - crfree(cncp->cred); - } - - /* - * Put a hold on the current vnodes and fill in the cache entry. - */ - vref(CTOV(cp)); - vref(CTOV(dcp)); - cncp->dcp = dcp; - cncp->cp = cp; - cncp->namelen = namelen; - cncp->cred = crhold(cred); - - bcopy(name, cncp->name, (unsigned)namelen); - - /* Insert into the lru and hash chains. */ - - CODA_NC_LRUINS(cncp, &coda_nc_lru); - CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]); - coda_nc_hash[hash].length++; /* Used for tuning */ - - CODA_NC_DEBUG(CODA_NC_PRINTCODA_NC, print_coda_nc(); ) + struct coda_cache *cncp; + int hash; + + if (coda_nc_use == 0) + return; + CODA_NC_DEBUG(CODA_NC_ENTER, myprintf(("Enter: dcp %p cp %p name %s " + "cred %p \n", dcp, cp, name, cred)); ); + if (namelen > CODA_NC_NAMELEN) { + CODA_NC_DEBUG(CODA_NC_ENTER, myprintf(("long name enter %s\n", + name));); + coda_nc_stat.long_name_enters++; + return; + } + hash = CODA_NC_HASH(name, namelen, dcp); + cncp = coda_nc_find(dcp, name, namelen, cred, hash); + if (cncp != NULL) { + /* + * Duplicate entry. + */ + coda_nc_stat.dbl_enters++; + return; + } + coda_nc_stat.enters++; + + /* + * Grab the next element in the LRU chain. + */ + cncp = CODA_NC_LRUGET(coda_nc_lru); + + /* + * Remove it from the lists. + */ + CODA_NC_LRUREM(cncp); + if (CODA_NC_VALID(cncp)) { + /* + * Seems really ugly, but we have to decrement the + * appropriate hash bucket length here, so we have to find + * the hash bucket. + */ + coda_nc_hash[CODA_NC_HASH(cncp->name, cncp->namelen, + cncp->dcp)].length--; + coda_nc_stat.lru_rm++; /* Zapped a valid entry. */ + CODA_NC_HSHREM(cncp); + vrele(CTOV(cncp->dcp)); + vrele(CTOV(cncp->cp)); + crfree(cncp->cred); + } + + /* + * Put a hold on the current vnodes and fill in the cache entry. + */ + vref(CTOV(cp)); + vref(CTOV(dcp)); + cncp->dcp = dcp; + cncp->cp = cp; + cncp->namelen = namelen; + cncp->cred = crhold(cred); + bcopy(name, cncp->name, (unsigned)namelen); + + /* + * Insert into the lru and hash chains. + */ + CODA_NC_LRUINS(cncp, &coda_nc_lru); + CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]); + coda_nc_hash[hash].length++; /* Used for tuning. */ + CODA_NC_DEBUG(CODA_NC_PRINTCODA_NC, print_coda_nc();); } /* - * Find the (dir cnode, name) pair in the cache, if it's cred - * matches the input, return it, otherwise return 0 + * Find the (dir cnode, name) pair in the cache, if its cred matches the + * input, return it, otherwise return NULL. */ struct cnode * -coda_nc_lookup(dcp, name, namelen, cred) - struct cnode *dcp; - const char *name; - int namelen; - struct ucred *cred; +coda_nc_lookup(struct cnode *dcp, const char *name, int namelen, + struct ucred *cred) { - int hash; struct coda_cache *cncp; + int hash; - if (coda_nc_use == 0) /* Cache is off */ - return((struct cnode *) 0); - + if (coda_nc_use == 0) + return (NULL); if (namelen > CODA_NC_NAMELEN) { - CODA_NC_DEBUG(CODA_NC_LOOKUP, - myprintf(("long name lookup %s\n",name));) - coda_nc_stat.long_name_lookups++; /* record stats */ - return((struct cnode *) 0); + CODA_NC_DEBUG(CODA_NC_LOOKUP, myprintf(("long name lookup " + "%s\n",name));); + coda_nc_stat.long_name_lookups++; + return (NULL); } - /* Use the hash function to locate the starting point, - then the search routine to go down the list looking for - the correct cred. + /* + * Use the hash function to locate the starting point, then the + * search routine to go down the list looking for the correct cred. */ - hash = CODA_NC_HASH(name, namelen, dcp); cncp = coda_nc_find(dcp, name, namelen, cred, hash); - if (cncp == (struct coda_cache *) 0) { - coda_nc_stat.misses++; /* record miss */ - return((struct cnode *) 0); + if (cncp == NULL) { + coda_nc_stat.misses++; + return (NULL); } - coda_nc_stat.hits++; - /* put this entry at the end of the LRU */ + /* + * Put this entry at the end of the LRU. + */ CODA_NC_LRUREM(cncp); CODA_NC_LRUINS(cncp, &coda_nc_lru); - /* move it to the front of the hash chain */ - /* don't need to change the hash bucket length */ + /* + * Move it to the front of the hash chain; don't need to change the + * hash bucket length. + */ CODA_NC_HSHREM(cncp); CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]); - - CODA_NC_DEBUG(CODA_NC_LOOKUP, - printf("lookup: dcp %p, name %s, cred %p = cp %p\n", - dcp, name, cred, cncp->cp); ) - - return(cncp->cp); + CODA_NC_DEBUG(CODA_NC_LOOKUP, printf("lookup: dcp %p, name %s, cred " + "%p = cp %p\n", dcp, name, cred, cncp->cp);); + return (cncp->cp); } static void -coda_nc_remove(cncp, dcstat) - struct coda_cache *cncp; - enum dc_status dcstat; +coda_nc_remove(struct coda_cache *cncp, enum dc_status dcstat) { - /* - * remove an entry -- vrele(cncp->dcp, cp), crfree(cred), - * remove it from it's hash chain, and - * place it at the head of the lru list. + + /* + * Remove an entry -- vrele(cncp->dcp, cp), crfree(cred), remove it + * from it's hash chain, and place it at the head of the lru list. */ - CODA_NC_DEBUG(CODA_NC_REMOVE, - myprintf(("coda_nc_remove %s from parent %s\n", - cncp->name, coda_f2s(&cncp->dcp->c_fid))); ) + CODA_NC_DEBUG(CODA_NC_REMOVE, myprintf(("coda_nc_remove %s from " + "parent %s\n", cncp->name, coda_f2s(&cncp->dcp->c_fid)));); CODA_NC_HSHREM(cncp); - - CODA_NC_HSHNUL(cncp); /* have it be a null chain */ - if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->dcp)) == 1)) { + CODA_NC_HSHNUL(cncp); /* Have it be a null chain. */ + if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->dcp)) == 1)) cncp->dcp->c_flags |= C_PURGING; - } - vrele(CTOV(cncp->dcp)); - - if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->cp)) == 1)) { + vrele(CTOV(cncp->dcp)); + if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->cp)) == 1)) cncp->cp->c_flags |= C_PURGING; - } - vrele(CTOV(cncp->cp)); - - crfree(cncp->cred); + vrele(CTOV(cncp->cp)); + crfree(cncp->cred); bzero(DATA_PART(cncp),DATA_SIZE); - /* Put the null entry just after the least-recently-used entry */ - /* LRU_TOP adjusts the pointer to point to the top of the structure. */ + /* + * Put the null entry just after the least-recently-used entry. + * LRU_TOP adjusts the pointer to point to the top of the structure. + */ CODA_NC_LRUREM(cncp); CODA_NC_LRUINS(cncp, LRU_TOP(coda_nc_lru.lru_prev)); } @@ -382,258 +361,222 @@ coda_nc_remove(cncp, dcstat) * Remove all entries with a parent which has the input fid. */ void -coda_nc_zapParentfid(fid, dcstat) - CodaFid *fid; - enum dc_status dcstat; +coda_nc_zapParentfid(CodaFid *fid, enum dc_status dcstat) { - /* To get to a specific fid, we might either have another hashing - function or do a sequential search through the cache for the - appropriate entries. The later may be acceptable since I don't - think callbacks or whatever Case 1 covers are frequent occurences. - */ struct coda_cache *cncp, *ncncp; int i; - if (coda_nc_use == 0) /* Cache is off */ - return; - - CODA_NC_DEBUG(CODA_NC_ZAPPFID, - myprintf(("ZapParent: fid %s\n", coda_f2s(fid))); ) - + /* + * To get to a specific fid, we might either have another hashing + * function or do a sequential search through the cache for the + * appropriate entries. The later may be acceptable since I don't + * think callbacks or whatever Case 1 covers are frequent occurences. + */ + if (coda_nc_use == 0) + return; + CODA_NC_DEBUG(CODA_NC_ZAPPFID, myprintf(("ZapParent: fid %s\n", + coda_f2s(fid)));); coda_nc_stat.zapPfids++; - for (i = 0; i < coda_nc_hashsize; i++) { - /* * Need to save the hash_next pointer in case we remove the * entry. remove causes hash_next to point to itself. */ - - for (cncp = coda_nc_hash[i].hash_next; + for (cncp = coda_nc_hash[i].hash_next; cncp != (struct coda_cache *)&coda_nc_hash[i]; cncp = ncncp) { ncncp = cncp->hash_next; if (coda_fid_eq(&(cncp->dcp->c_fid), fid)) { - coda_nc_hash[i].length--; /* Used for tuning */ - coda_nc_remove(cncp, dcstat); + /* Used for tuning. */ + coda_nc_hash[i].length--; + coda_nc_remove(cncp, dcstat); } } } } /* - * Remove all entries which have the same fid as the input + * Remove all entries which have the same fid as the input. */ void -coda_nc_zapfid(fid, dcstat) - CodaFid *fid; - enum dc_status dcstat; +coda_nc_zapfid(CodaFid *fid, enum dc_status dcstat) { - /* See comment for zapParentfid. This routine will be used - if attributes are being cached. - */ struct coda_cache *cncp, *ncncp; int i; - if (coda_nc_use == 0) /* Cache is off */ + /* + * See comment for zapParentfid. This routine will be used if + * attributes are being cached. + */ + if (coda_nc_use == 0) return; - - CODA_NC_DEBUG(CODA_NC_ZAPFID, - myprintf(("Zapfid: fid %s\n", coda_f2s(fid))); ) - + CODA_NC_DEBUG(CODA_NC_ZAPFID, myprintf(("Zapfid: fid %s\n", + coda_f2s(fid)));); coda_nc_stat.zapFids++; - for (i = 0; i < coda_nc_hashsize; i++) { - for (cncp = coda_nc_hash[i].hash_next; + for (cncp = coda_nc_hash[i].hash_next; cncp != (struct coda_cache *)&coda_nc_hash[i]; cncp = ncncp) { ncncp = cncp->hash_next; if (coda_fid_eq(&cncp->cp->c_fid, fid)) { - coda_nc_hash[i].length--; /* Used for tuning */ - coda_nc_remove(cncp, dcstat); + /* Used for tuning. */ + coda_nc_hash[i].length--; + coda_nc_remove(cncp, dcstat); } } } } -/* - * Remove all entries which match the fid and the cred +/* + * Remove all entries which match the fid and the cred. * * XXX: This is unused. */ void -coda_nc_zapvnode(fid, cred, dcstat) - CodaFid *fid; - struct ucred *cred; - enum dc_status dcstat; +coda_nc_zapvnode(CodaFid *fid, struct ucred *cred, enum dc_status dcsta) { - /* See comment for zapfid. I don't think that one would ever - want to zap a file with a specific cred from the kernel. - We'll leave this one unimplemented. - */ - if (coda_nc_use == 0) /* Cache is off */ + /* + * See comment for zapfid. I don't think that one would ever want to + * zap a file with a specific cred from the kernel. We'll leave this + * one unimplemented. + */ + if (coda_nc_use == 0) return; - - CODA_NC_DEBUG(CODA_NC_ZAPVNODE, - myprintf(("Zapvnode: fid %s cred %p\n", - coda_f2s(fid), cred)); ) + CODA_NC_DEBUG(CODA_NC_ZAPVNODE, myprintf(("Zapvnode: fid %s cred " + "%p\n", coda_f2s(fid), cred));); } /* - * Remove all entries which have the (dir vnode, name) pair + * Remove all entries which have the (dir vnode, name) pair. */ void -coda_nc_zapfile(dcp, name, namelen) - struct cnode *dcp; - const char *name; - int namelen; +coda_nc_zapfile(struct cnode *dcp, const char *name, int namelen) { - /* use the hash function to locate the file, then zap all - entries of it regardless of the cred. - */ struct coda_cache *cncp; int hash; - if (coda_nc_use == 0) /* Cache is off */ + /* + * use the hash function to locate the file, then zap all entries of + * it regardless of the cred. + */ + if (coda_nc_use == 0) return; - - CODA_NC_DEBUG(CODA_NC_ZAPFILE, - myprintf(("Zapfile: dcp %p name %s \n", - dcp, name)); ) - + CODA_NC_DEBUG(CODA_NC_ZAPFILE, myprintf(("Zapfile: dcp %p name %s\n", + dcp, name));); if (namelen > CODA_NC_NAMELEN) { - coda_nc_stat.long_remove++; /* record stats */ + coda_nc_stat.long_remove++; return; } - coda_nc_stat.zapFile++; - hash = CODA_NC_HASH(name, namelen, dcp); cncp = coda_nc_find(dcp, name, namelen, 0, hash); - while (cncp) { - coda_nc_hash[hash].length--; /* Used for tuning */ - - coda_nc_remove(cncp, NOT_DOWNCALL); - cncp = coda_nc_find(dcp, name, namelen, 0, hash); + /* Used for tuning. */ + coda_nc_hash[hash].length--; + coda_nc_remove(cncp, NOT_DOWNCALL); + cncp = coda_nc_find(dcp, name, namelen, 0, hash); } } -/* - * Remove all the entries for a particular user. Used when tokens expire. - * A user is determined by his/her effective user id (id_uid). +/* + * Remove all the entries for a particular user. Used when tokens expire. A + * user is determined by his/her effective user id (id_uid). */ void -coda_nc_purge_user(uid, dcstat) - uid_t uid; - enum dc_status dcstat; +coda_nc_purge_user(uid_t uid, enum dc_status dcstat) { - /* - * I think the best approach is to go through the entire cache - * via HASH or whatever and zap all entries which match the - * input cred. Or just flush the whole cache. It might be - * best to go through on basis of LRU since cache will almost - * always be full and LRU is more straightforward. - */ - struct coda_cache *cncp, *ncncp; int hash; - if (coda_nc_use == 0) /* Cache is off */ + /* + * I think the best approach is to go through the entire cache via + * HASH or whatever and zap all entries which match the input cred. + * Or just flush the whole cache. It might be best to go through on + * basis of LRU since cache will almost always be full and LRU is + * more straightforward. + */ + if (coda_nc_use == 0) return; - - CODA_NC_DEBUG(CODA_NC_PURGEUSER, - myprintf(("ZapDude: uid %x\n", uid)); ) + CODA_NC_DEBUG(CODA_NC_PURGEUSER, myprintf(("ZapDude: uid %x\n", + uid));); coda_nc_stat.zapUsers++; - for (cncp = CODA_NC_LRUGET(coda_nc_lru); cncp != (struct coda_cache *)(&coda_nc_lru); cncp = ncncp) { ncncp = CODA_NC_LRUGET(*cncp); - if ((CODA_NC_VALID(cncp)) && ((cncp->cred)->cr_uid == uid)) { - /* Seems really ugly, but we have to decrement the appropriate - hash bucket length here, so we have to find the hash bucket - */ - hash = CODA_NC_HASH(cncp->name, cncp->namelen, cncp->dcp); - coda_nc_hash[hash].length--; /* For performance tuning */ - - coda_nc_remove(cncp, dcstat); + /* + * Seems really ugly, but we have to decrement the + * appropriate hash bucket length here, so we have to + * find the hash bucket. + */ + hash = CODA_NC_HASH(cncp->name, cncp->namelen, + cncp->dcp); + /* For performance tuning. */ + coda_nc_hash[hash].length--; + coda_nc_remove(cncp, dcstat); } } } /* - * Flush the entire name cache. In response to a flush of the Venus cache. + * Flush the entire name cache. In response to a flush of the Venus cache. */ void -coda_nc_flush(dcstat) - enum dc_status dcstat; +coda_nc_flush(enum dc_status dcstat) { - /* One option is to deallocate the current name cache and - call init to start again. Or just deallocate, then rebuild. - Or again, we could just go through the array and zero the - appropriate fields. - */ - - /* - * Go through the whole lru chain and kill everything as we go. - * I don't use remove since that would rebuild the lru chain - * as it went and that seemed unneccesary. - */ struct coda_cache *cncp; int i; - if (coda_nc_use == 0) /* Cache is off */ - return; + /* + * One option is to deallocate the current name cache and call init + * to start again. Or just deallocate, then rebuild. Or again, we + * could just go through the array and zero the appropriate fields. + */ + /* + * Go through the whole lru chain and kill everything as we go. I + * don't use remove since that would rebuild the LRU chain as it went + * and that seemed unneccesary. + */ + if (coda_nc_use == 0) + return; coda_nc_stat.Flushes++; - for (cncp = CODA_NC_LRUGET(coda_nc_lru); cncp != (struct coda_cache *)&coda_nc_lru; cncp = CODA_NC_LRUGET(*cncp)) { if (CODA_NC_VALID(cncp)) { - - CODA_NC_HSHREM(cncp); /* only zero valid nodes */ + CODA_NC_HSHREM(cncp); /* Only zero valid nodes. */ CODA_NC_HSHNUL(cncp); - if ((dcstat == IS_DOWNCALL) - && (vrefcnt(CTOV(cncp->dcp)) == 1)) - { + if ((dcstat == IS_DOWNCALL) && + (vrefcnt(CTOV(cncp->dcp)) == 1)) cncp->dcp->c_flags |= C_PURGING; - } - vrele(CTOV(cncp->dcp)); - + vrele(CTOV(cncp->dcp)); ASSERT_VOP_LOCKED(CTOV(cncp->cp), "coda_nc_flush"); - if (CTOV(cncp->cp)->v_vflag & VV_TEXT) { - if (coda_vmflush(cncp->cp)) - CODADEBUG(CODA_FLUSH, - myprintf(("coda_nc_flush: %s busy\n", - coda_f2s(&cncp->cp->c_fid))); ) - } - - if ((dcstat == IS_DOWNCALL) - && (vrefcnt(CTOV(cncp->cp)) == 1)) - { + if (CTOV(cncp->cp)->v_vflag & VV_TEXT && + coda_vmflush(cncp->cp)) + CODADEBUG(CODA_FLUSH, myprintf(("coda_nc_" + "flush: %s busy\n", coda_f2s( + &cncp->cp->c_fid)));); + if ((dcstat == IS_DOWNCALL) && + (vrefcnt(CTOV(cncp->cp)) == 1)) cncp->cp->c_flags |= C_PURGING; - } - vrele(CTOV(cncp->cp)); - - crfree(cncp->cred); + vrele(CTOV(cncp->cp)); + crfree(cncp->cred); bzero(DATA_PART(cncp),DATA_SIZE); } } - for (i = 0; i < coda_nc_hashsize; i++) - coda_nc_hash[i].length = 0; + coda_nc_hash[i].length = 0; } /* - * Debugging routines + * Debugging routines. */ -/* +/* * This routine should print out all the hash chains to the console. */ void @@ -644,52 +587,46 @@ print_coda_nc(void) for (hash = 0; hash < coda_nc_hashsize; hash++) { myprintf(("\nhash %d\n",hash)); - - for (cncp = coda_nc_hash[hash].hash_next; + for (cncp = coda_nc_hash[hash].hash_next; cncp != (struct coda_cache *)&coda_nc_hash[hash]; cncp = cncp->hash_next) { myprintf(("cp %p dcp %p cred %p name %s\n", - cncp->cp, cncp->dcp, - cncp->cred, cncp->name)); - } + cncp->cp, cncp->dcp, cncp->cred, cncp->name)); + } } } void coda_nc_gather_stats(void) { - int i, max = 0, sum = 0, temp, zeros = 0, ave, n; + int i, max = 0, sum = 0, temp, zeros = 0, ave, n; for (i = 0; i < coda_nc_hashsize; i++) { - if (coda_nc_hash[i].length) { - sum += coda_nc_hash[i].length; - } else { - zeros++; - } - - if (coda_nc_hash[i].length > max) - max = coda_nc_hash[i].length; + if (coda_nc_hash[i].length) + sum += coda_nc_hash[i].length; + else + zeros++; + if (coda_nc_hash[i].length > max) + max = coda_nc_hash[i].length; } /* - * When computing the Arithmetic mean, only count slots which - * are not empty in the distribution. + * When computing the Arithmetic mean, only count slots which are not + * empty in the distribution. */ coda_nc_stat.Sum_bucket_len = sum; coda_nc_stat.Num_zero_len = zeros; coda_nc_stat.Max_bucket_len = max; - - if ((n = coda_nc_hashsize - zeros) > 0) - ave = sum / n; + if ((n = coda_nc_hashsize - zeros) > 0) + ave = sum / n; else - ave = 0; - + ave = 0; sum = 0; for (i = 0; i < coda_nc_hashsize; i++) { - if (coda_nc_hash[i].length) { - temp = coda_nc_hash[i].length - ave; - sum += temp * temp; - } + if (coda_nc_hash[i].length) { + temp = coda_nc_hash[i].length - ave; + sum += temp * temp; + } } coda_nc_stat.Sum2_bucket_len = sum; } @@ -701,33 +638,39 @@ coda_nc_gather_stats(void) * is in an improper state (except by turning the cache off). */ int -coda_nc_resize(hashsize, heapsize, dcstat) - int hashsize, heapsize; - enum dc_status dcstat; +coda_nc_resize(int hashsize, int heapsize, enum dc_status dcstat) { - if ((hashsize % 2) || (heapsize % 2)) { /* Illegal hash or cache sizes */ - return(EINVAL); - } - - coda_nc_use = 0; /* Turn the cache off */ - - coda_nc_flush(dcstat); /* free any cnodes in the cache */ - - /* WARNING: free must happen *before* size is reset */ - CODA_FREE(coda_nc_heap,TOTAL_CACHE_SIZE); - CODA_FREE(coda_nc_hash,TOTAL_HASH_SIZE); - - coda_nc_hashsize = hashsize; - coda_nc_size = heapsize; - - coda_nc_init(); /* Set up a cache with the new size */ - - coda_nc_use = 1; /* Turn the cache back on */ - return(0); + + /* + * Check for illegal hash or cache sizes. + */ + if ((hashsize % 2) || (heapsize % 2)) + return (EINVAL); + + /* + * Turn off the cache and free any cnodes in the cache. + */ + coda_nc_use = 0; + coda_nc_flush(dcstat); + + /* + * WARNING: free must happen *before* size is reset. + */ + CODA_FREE(coda_nc_heap,TOTAL_CACHE_SIZE); + CODA_FREE(coda_nc_hash,TOTAL_HASH_SIZE); + + /* + * Set up a cache with the new size and turn the cache back on. + */ + coda_nc_hashsize = hashsize; + coda_nc_size = heapsize; + coda_nc_init(); + coda_nc_use = 1; + return (0); } -#ifdef DEBUG -char coda_nc_name_buf[CODA_MAXNAMLEN+1]; +#ifdef DEBUG +static char coda_nc_name_buf[CODA_MAXNAMLEN+1]; void coda_nc_name(struct cnode *cp) @@ -735,19 +678,20 @@ coda_nc_name(struct cnode *cp) struct coda_cache *cncp, *ncncp; int i; - if (coda_nc_use == 0) /* Cache is off */ + if (coda_nc_use == 0) return; for (i = 0; i < coda_nc_hashsize; i++) { - for (cncp = coda_nc_hash[i].hash_next; + for (cncp = coda_nc_hash[i].hash_next; cncp != (struct coda_cache *)&coda_nc_hash[i]; cncp = ncncp) { ncncp = cncp->hash_next; if (cncp->cp == cp) { - bcopy(cncp->name, coda_nc_name_buf, cncp->namelen); + bcopy(cncp->name, coda_nc_name_buf, + cncp->namelen); coda_nc_name_buf[cncp->namelen] = 0; - printf(" is %s (%p,%p)@%p", - coda_nc_name_buf, cncp->cp, cncp->dcp, cncp); + printf(" is %s (%p,%p)@%p", coda_nc_name_buf, + cncp->cp, cncp->dcp, cncp); } } diff --git a/sys/fs/coda/coda_namecache.h b/sys/fs/coda/coda_namecache.h index 637a0d0..87b60d7 100644 --- a/sys/fs/coda/coda_namecache.h +++ b/sys/fs/coda/coda_namecache.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,21 +14,21 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * - * @(#) src/sys/coda/coda_namecache.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ + * + * @(#) src/sys/coda/coda_namecache.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * + * */ /*- @@ -45,107 +45,117 @@ */ #ifndef _CODA_NC_HEADER_ -#define _CODA_NC_HEADER_ +#define _CODA_NC_HEADER_ /* - * Coda constants + * Coda constants. */ -#define CODA_NC_NAMELEN 15 /* longest name stored in cache */ -#define CODA_NC_CACHESIZE 256 /* Default cache size */ -#define CODA_NC_HASHSIZE 64 /* Must be multiple of 2 */ +#define CODA_NC_NAMELEN 15 /* Longest name stored in cache */ +#define CODA_NC_CACHESIZE 256 /* Default cache size */ +#define CODA_NC_HASHSIZE 64 /* Must be multiple of 2 */ /* * Hash function for the primary hash. - */ - -/* + * * First try -- (first + last letters + length + (int)cp) mod size * 2nd try -- same, except dir fid.vnode instead of cp */ +#define CODA_NC_HASH(name, namelen, cp) \ + ((name[0] + (name[namelen-1]<<4) + namelen + \ + (((int)(intptr_t)cp)>>8)) & (coda_nc_hashsize-1)) -#define CODA_NC_HASH(name, namelen, cp) \ - ((name[0] + (name[namelen-1]<<4) + namelen + (((int)(intptr_t)cp)>>8)) & (coda_nc_hashsize-1)) - -#define CODA_NAMEMATCH(cp, name, namelen, dcp) \ - ((namelen == cp->namelen) && (dcp == cp->dcp) && \ - (bcmp(cp->name,name,namelen) == 0)) +#define CODA_NAMEMATCH(cp, name, namelen, dcp) \ + ((namelen == cp->namelen) && (dcp == cp->dcp) && \ + (bcmp(cp->name,name,namelen) == 0)) /* - * Functions to modify the hash and lru chains. - * insque and remque assume that the pointers are the first thing - * in the list node, thus the trickery for lru. + * Functions to modify the hash and LRU chains. insque and remque assume + * that the pointers are the first thing in the list node, thus the trickery + * for LRU. */ - -#define CODA_NC_HSHINS(elem, pred) insque(elem,pred) -#define CODA_NC_HSHREM(elem) remque(elem) -#define CODA_NC_HSHNUL(elem) (elem)->hash_next = \ +#define CODA_NC_HSHINS(elem, pred) insque(elem,pred) +#define CODA_NC_HSHREM(elem) remque(elem) +#define CODA_NC_HSHNUL(elem) (elem)->hash_next = \ (elem)->hash_prev = (elem) -#define CODA_NC_LRUINS(elem, pred) insque(LRU_PART(elem), LRU_PART(pred)) -#define CODA_NC_LRUREM(elem) remque(LRU_PART(elem)); -#define CODA_NC_LRUGET(lruhead) LRU_TOP((lruhead).lru_prev) +#define CODA_NC_LRUINS(elem, pred) insque(LRU_PART(elem), LRU_PART(pred)) +#define CODA_NC_LRUREM(elem) remque(LRU_PART(elem)); +#define CODA_NC_LRUGET(lruhead) LRU_TOP((lruhead).lru_prev) + +#define CODA_NC_VALID(cncp) (cncp->dcp != (struct cnode *)0) -#define CODA_NC_VALID(cncp) (cncp->dcp != (struct cnode *)0) - -#define LRU_PART(cncp) (struct coda_cache *) \ - ((char *)cncp + (2*sizeof(struct coda_cache *))) -#define LRU_TOP(cncp) (struct coda_cache *) \ - ((char *)cncp - (2*sizeof(struct coda_cache *))) -#define DATA_PART(cncp) (struct coda_cache *) \ - ((char *)cncp + (4*sizeof(struct coda_cache *))) -#define DATA_SIZE (sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *))) +#define LRU_PART(cncp) (struct coda_cache *) ((char *)cncp + \ + (2*sizeof(struct coda_cache *))) +#define LRU_TOP(cncp) (struct coda_cache *) ((char *)cncp - \ + (2*sizeof(struct coda_cache *))) +#define DATA_PART(cncp) (struct coda_cache *) ((char *)cncp + \ + (4*sizeof(struct coda_cache *))) +#define DATA_SIZE (sizeof(struct coda_cache) - \ + (4*sizeof(struct coda_cache *))) /* * Structure for an element in the CODA Name Cache. - * NOTE: I use the position of arguments and their size in the - * implementation of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and - * DATA_PART. + * + * NOTE: I use the position of arguments and their size in the implementation + * of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and DATA_PART. */ - -struct coda_cache { - struct coda_cache *hash_next,*hash_prev; /* Hash list */ +struct coda_cache { + struct coda_cache *hash_next, *hash_prev; /* Hash list */ struct coda_cache *lru_next, *lru_prev; /* LRU list */ struct cnode *cp; /* vnode of the file */ struct cnode *dcp; /* parent's cnode */ struct ucred *cred; /* user credentials */ - char name[CODA_NC_NAMELEN]; /* segment name */ - int namelen; /* length of name */ + char name[CODA_NC_NAMELEN]; /* segment name */ + int namelen; /* length of name */ }; -struct coda_lru { /* Start of LRU chain */ - char *dummy1, *dummy2; /* place holders */ - struct coda_cache *lru_next, *lru_prev; /* position of pointers is important */ +/* + * Start of an LRU chain -- notice position of pointers. + */ +struct coda_lru { + char *dummy1, *dummy2; + struct coda_cache *lru_next, *lru_prev; }; - -struct coda_hash { /* Start of Hash chain */ - struct coda_cache *hash_next, *hash_prev; /* NOTE: chain pointers must be first */ - int length; /* used for tuning purposes */ +/* + * Start of Hash chain -- notice position of pointers -- chain pointers must + * be first. + */ +struct coda_hash { + struct coda_cache *hash_next, *hash_prev; + int length; /* Used for tuning purposes. */ }; - -/* - * Symbols to aid in debugging the namecache code. Assumes the existence - * of the variable coda_nc_debug, which is defined in cfs_namecache.c +/* + * Symbols to aid in debugging the namecache code. Assumes the existence of + * the variable coda_nc_debug, which is defined in cfs_namecache.c */ -#define CODA_NC_DEBUG(N, STMT) { if (coda_nc_debug & (1 <= _VICEIOCTL(0) && \ + com <= _VICEIOCTL(255)) -#define _VALIDVICEIOCTL(com) (com >= _VICEIOCTL(0) && com <= _VICEIOCTL(255)) - -#endif +#endif /* !_SYS_PIOCTL_H_ */ diff --git a/sys/fs/coda/coda_psdev.c b/sys/fs/coda/coda_psdev.c index 3b474cf..0cf856a 100644 --- a/sys/fs/coda/coda_psdev.c +++ b/sys/fs/coda/coda_psdev.c @@ -1,10 +1,10 @@ /*- * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -13,18 +13,18 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/coda/coda_psdev.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ */ /*- @@ -39,14 +39,16 @@ * University. Contributers include David Steere, James Kistler, and * M. Satyanarayanan. */ -/* - * These routines define the psuedo device for communication between - * Coda's Venus and Minicache in Mach 2.6. They used to be in cfs_subr.c, - * but I moved them to make it easier to port the Minicache without - * porting coda. -- DCS 10/12/94 +/* + * These routines define the psuedo device for communication between Coda's + * Venus and Minicache in Mach 2.6. They used to be in cfs_subr.c, but I + * moved them to make it easier to port the Minicache without porting coda. + * -- DCS 10/12/94 */ -/* These routines are the device entry points for Venus. */ +/* + * These routines are the device entry points for Venus. + */ #include __FBSDID("$FreeBSD$"); @@ -71,489 +73,496 @@ __FBSDID("$FreeBSD$"); #include #include -#define CTL_C +/* + * Variables to determine how Coda sleeps and whether or not it is + * interruptible when it does sleep waiting for Venus. + */ +#define CTL_C #ifdef CTL_C #include #endif int coda_psdev_print_entry = 0; -static -int outstanding_upcalls = 0; +static int outstanding_upcalls = 0; int coda_call_sleep = PZERO - 1; -#ifdef CTL_C +#ifdef CTL_C int coda_pcatch = PCATCH; #else #endif -#define ENTRY if(coda_psdev_print_entry) myprintf(("Entered %s\n",__func__)) +#define ENTRY do { \ + if (coda_psdev_print_entry) \ + myprintf(("Entered %s\n", __func__)); \ +} while (0) struct vmsg { - struct queue vm_chain; - caddr_t vm_data; - u_short vm_flags; - u_short vm_inSize; /* Size is at most 5000 bytes */ - u_short vm_outSize; - u_short vm_opcode; /* copied from data to save ptr lookup */ - int vm_unique; - caddr_t vm_sleep; /* Not used by Mach. */ + struct queue vm_chain; + caddr_t vm_data; + u_short vm_flags; + u_short vm_inSize; /* Size is at most 5000 bytes */ + u_short vm_outSize; + u_short vm_opcode; /* Copied from data to save ptr deref */ + int vm_unique; + caddr_t vm_sleep; /* Not used by Mach. */ }; -#define VM_READ 1 -#define VM_WRITE 2 -#define VM_INTR 4 /* Unused. */ +#define VM_READ 1 +#define VM_WRITE 2 +#define VM_INTR 4 /* Unused. */ -int -vc_open(dev, flag, mode, td) - struct cdev *dev; - int flag; - int mode; - struct thread *td; +int +vc_open(struct cdev *dev, int flag, int mode, struct thread *td) { - struct vcomm *vcp; - struct coda_mntinfo *mnt; - - ENTRY; - - if (!coda_nc_initialized) - coda_nc_init(); - - mnt = dev2coda_mntinfo(dev); - KASSERT(mnt, ("Coda: tried to open uninitialized cfs device")); - - vcp = &mnt->mi_vcomm; - if (VC_OPEN(vcp)) - return(EBUSY); - - bzero(&(vcp->vc_selproc), sizeof (struct selinfo)); - INIT_QUEUE(vcp->vc_requests); - INIT_QUEUE(vcp->vc_replys); - MARK_VC_OPEN(vcp); - - mnt->mi_vfsp = NULL; - mnt->mi_rootvp = NULL; - - return(0); + struct vcomm *vcp; + struct coda_mntinfo *mnt; + + ENTRY; + if (!coda_nc_initialized) + coda_nc_init(); + mnt = dev2coda_mntinfo(dev); + KASSERT(mnt, ("Coda: tried to open uninitialized cfs device")); + vcp = &mnt->mi_vcomm; + if (VC_OPEN(vcp)) + return (EBUSY); + bzero(&(vcp->vc_selproc), sizeof (struct selinfo)); + INIT_QUEUE(vcp->vc_requests); + INIT_QUEUE(vcp->vc_replys); + MARK_VC_OPEN(vcp); + mnt->mi_vfsp = NULL; + mnt->mi_rootvp = NULL; + return (0); } -int -vc_close (dev, flag, mode, td) - struct cdev *dev; - int flag; - int mode; - struct thread *td; +int +vc_close(struct cdev *dev, int flag, int mode, struct thread *td) { - register struct vcomm *vcp; - register struct vmsg *vmp, *nvmp = NULL; - struct coda_mntinfo *mi; - int err; - - ENTRY; - - mi = dev2coda_mntinfo(dev); - KASSERT(mi, ("Coda: closing unknown cfs device")); - - vcp = &mi->mi_vcomm; - KASSERT(VC_OPEN(vcp), ("Coda: closing unopened cfs device")); - - /* prevent future operations on this vfs from succeeding by auto- - * unmounting any vfs mounted via this device. This frees user or - * sysadm from having to remember where all mount points are located. - * Put this before WAKEUPs to avoid queuing new messages between - * the WAKEUP and the unmount (which can happen if we're unlucky) - */ - if (!mi->mi_rootvp) { - /* just a simple open/close w no mount */ - MARK_VC_CLOSED(vcp); - return 0; - } - - /* Let unmount know this is for real */ - VTOC(mi->mi_rootvp)->c_flags |= C_UNMOUNTING; - coda_unmounting(mi->mi_vfsp); - - outstanding_upcalls = 0; - /* Wakeup clients so they can return. */ - for (vmp = (struct vmsg *)GETNEXT(vcp->vc_requests); - !EOQ(vmp, vcp->vc_requests); - vmp = nvmp) - { - nvmp = (struct vmsg *)GETNEXT(vmp->vm_chain); - /* Free signal request messages and don't wakeup cause - no one is waiting. */ - if (vmp->vm_opcode == CODA_SIGNAL) { - CODA_FREE((caddr_t)vmp->vm_data, (u_int)VC_IN_NO_DATA); - CODA_FREE((caddr_t)vmp, (u_int)sizeof(struct vmsg)); - continue; + struct vcomm *vcp; + struct vmsg *vmp, *nvmp = NULL; + struct coda_mntinfo *mi; + int err; + + ENTRY; + mi = dev2coda_mntinfo(dev); + KASSERT(mi, ("Coda: closing unknown cfs device")); + vcp = &mi->mi_vcomm; + KASSERT(VC_OPEN(vcp), ("Coda: closing unopened cfs device")); + + /* + * Prevent future operations on this vfs from succeeding by + * auto-unmounting any vfs mounted via this device. This frees user + * or sysadm from having to remember where all mount points are + * located. Put this before WAKEUPs to avoid queuing new messages + * between the WAKEUP and the unmount (which can happen if we're + * unlucky). + */ + if (mi->mi_rootvp == NULL) { + /* + * Just a simple open/close with no mount. + */ + MARK_VC_CLOSED(vcp); + return (0); } - outstanding_upcalls++; - wakeup(&vmp->vm_sleep); - } - - for (vmp = (struct vmsg *)GETNEXT(vcp->vc_replys); - !EOQ(vmp, vcp->vc_replys); - vmp = (struct vmsg *)GETNEXT(vmp->vm_chain)) - { - outstanding_upcalls++; - wakeup(&vmp->vm_sleep); - } - MARK_VC_CLOSED(vcp); + /* + * Let unmount know this is for real. + */ + VTOC(mi->mi_rootvp)->c_flags |= C_UNMOUNTING; + coda_unmounting(mi->mi_vfsp); - if (outstanding_upcalls) { -#ifdef CODA_VERBOSE - printf("presleep: outstanding_upcalls = %d\n", outstanding_upcalls); - (void) tsleep(&outstanding_upcalls, coda_call_sleep, "coda_umount", 0); - printf("postsleep: outstanding_upcalls = %d\n", outstanding_upcalls); -#else - (void) tsleep(&outstanding_upcalls, coda_call_sleep, "coda_umount", 0); + /* + * Wakeup clients so they can return. + */ + outstanding_upcalls = 0; + for (vmp = (struct vmsg *)GETNEXT(vcp->vc_requests); + !EOQ(vmp, vcp->vc_requests); vmp = nvmp) { + nvmp = (struct vmsg *)GETNEXT(vmp->vm_chain); + /* + * Free signal request messages and don't wakeup cause no one + * is waiting. + */ + if (vmp->vm_opcode == CODA_SIGNAL) { + CODA_FREE((caddr_t)vmp->vm_data, + (u_int)VC_IN_NO_DATA); + CODA_FREE((caddr_t)vmp, (u_int)sizeof(struct vmsg)); + continue; + } + outstanding_upcalls++; + wakeup(&vmp->vm_sleep); + } + for (vmp = (struct vmsg *)GETNEXT(vcp->vc_replys); + !EOQ(vmp, vcp->vc_replys); + vmp = (struct vmsg *)GETNEXT(vmp->vm_chain)) { + outstanding_upcalls++; + wakeup(&vmp->vm_sleep); + } + MARK_VC_CLOSED(vcp); + if (outstanding_upcalls) { +#ifdef CODA_VERBOSE + printf("presleep: outstanding_upcalls = %d\n", + outstanding_upcalls); #endif - } - - err = dounmount(mi->mi_vfsp, flag, td); - if (err) - myprintf(("Error %d unmounting vfs in vcclose(%s)\n", - err, devtoname(dev))); - return 0; + (void) tsleep(&outstanding_upcalls, coda_call_sleep, + "coda_umount", 0); +#ifdef CODA_VERBOSE + printf("postsleep: outstanding_upcalls = %d\n", + outstanding_upcalls); +#endif + } + err = dounmount(mi->mi_vfsp, flag, td); + if (err) + myprintf(("Error %d unmounting vfs in vcclose(%s)\n", err, + devtoname(dev))); + return (0); } -int -vc_read(dev, uiop, flag) - struct cdev *dev; - struct uio *uiop; - int flag; +int +vc_read(struct cdev *dev, struct uio *uiop, int flag) { - register struct vcomm * vcp; - register struct vmsg *vmp; - int error = 0; - - ENTRY; - - vcp = &dev2coda_mntinfo(dev)->mi_vcomm; - /* Get message at head of request queue. */ - if (EMPTY(vcp->vc_requests)) - return(0); /* Nothing to read */ - - vmp = (struct vmsg *)GETNEXT(vcp->vc_requests); - - /* Move the input args into userspace */ - uiop->uio_rw = UIO_READ; - error = uiomove(vmp->vm_data, vmp->vm_inSize, uiop); - if (error) { - myprintf(("vcread: error (%d) on uiomove\n", error)); - error = EINVAL; - } - -#ifdef OLD_DIAGNOSTIC - if (vmp->vm_chain.forw == 0 || vmp->vm_chain.back == 0) - panic("vc_read: bad chain"); + struct vcomm *vcp; + struct vmsg *vmp; + int error = 0; + + ENTRY; + vcp = &dev2coda_mntinfo(dev)->mi_vcomm; + + /* + * Get message at head of request queue. + */ + if (EMPTY(vcp->vc_requests)) + return (0); /* Nothing to read */ + vmp = (struct vmsg *)GETNEXT(vcp->vc_requests); + + /* + * Move the input args into userspace. + */ + uiop->uio_rw = UIO_READ; + error = uiomove(vmp->vm_data, vmp->vm_inSize, uiop); + if (error) { + myprintf(("vcread: error (%d) on uiomove\n", error)); + error = EINVAL; + } +#ifdef OLD_DIAGNOSTIC + if (vmp->vm_chain.forw == 0 || vmp->vm_chain.back == 0) + panic("vc_read: bad chain"); #endif + REMQUE(vmp->vm_chain); - REMQUE(vmp->vm_chain); - - /* If request was a signal, free up the message and don't - enqueue it in the reply queue. */ - if (vmp->vm_opcode == CODA_SIGNAL) { - if (codadebug) - myprintf(("vcread: signal msg (%d, %d)\n", - vmp->vm_opcode, vmp->vm_unique)); - CODA_FREE((caddr_t)vmp->vm_data, (u_int)VC_IN_NO_DATA); - CODA_FREE((caddr_t)vmp, (u_int)sizeof(struct vmsg)); - return(error); - } - - vmp->vm_flags |= VM_READ; - INSQUE(vmp->vm_chain, vcp->vc_replys); - - return(error); + /* + * If request was a signal, free up the message and don't enqueue it + * in the reply queue. + */ + if (vmp->vm_opcode == CODA_SIGNAL) { + if (codadebug) + myprintf(("vcread: signal msg (%d, %d)\n", + vmp->vm_opcode, vmp->vm_unique)); + CODA_FREE((caddr_t)vmp->vm_data, (u_int)VC_IN_NO_DATA); + CODA_FREE((caddr_t)vmp, (u_int)sizeof(struct vmsg)); + return (error); + } + vmp->vm_flags |= VM_READ; + INSQUE(vmp->vm_chain, vcp->vc_replys); + return (error); } int -vc_write(dev, uiop, flag) - struct cdev *dev; - struct uio *uiop; - int flag; +vc_write(struct cdev *dev, struct uio *uiop, int flag) { - register struct vcomm * vcp; - register struct vmsg *vmp; - struct coda_out_hdr *out; - u_long seq; - u_long opcode; - int buf[2]; - int error = 0; - - ENTRY; - - vcp = &dev2coda_mntinfo(dev)->mi_vcomm; - - /* Peek at the opcode, unique without transfering the data. */ - uiop->uio_rw = UIO_WRITE; - error = uiomove((caddr_t)buf, sizeof(int) * 2, uiop); - if (error) { - myprintf(("vcwrite: error (%d) on uiomove\n", error)); - return(EINVAL); - } - - opcode = buf[0]; - seq = buf[1]; - - if (codadebug) - myprintf(("vcwrite got a call for %ld.%ld\n", opcode, seq)); - - if (DOWNCALL(opcode)) { - union outputArgs pbuf; - - /* get the rest of the data. */ + struct vcomm *vcp; + struct vmsg *vmp; + struct coda_out_hdr *out; + u_long seq; + u_long opcode; + int buf[2]; + int error = 0; + + ENTRY; + vcp = &dev2coda_mntinfo(dev)->mi_vcomm; + + /* + * Peek at the opcode, unique without transfering the data. + */ uiop->uio_rw = UIO_WRITE; - error = uiomove((caddr_t)&pbuf.coda_purgeuser.oh.result, sizeof(pbuf) - (sizeof(int)*2), uiop); + error = uiomove((caddr_t)buf, sizeof(int) * 2, uiop); if (error) { - myprintf(("vcwrite: error (%d) on uiomove (Op %ld seq %ld)\n", - error, opcode, seq)); - return(EINVAL); - } - - return handleDownCall(opcode, &pbuf); - } - - /* Look for the message on the (waiting for) reply queue. */ - for (vmp = (struct vmsg *)GETNEXT(vcp->vc_replys); - !EOQ(vmp, vcp->vc_replys); - vmp = (struct vmsg *)GETNEXT(vmp->vm_chain)) - { - if (vmp->vm_unique == seq) break; - } - - if (EOQ(vmp, vcp->vc_replys)) { + myprintf(("vcwrite: error (%d) on uiomove\n", error)); + return (EINVAL); + } + opcode = buf[0]; + seq = buf[1]; if (codadebug) - myprintf(("vcwrite: msg (%ld, %ld) not found\n", opcode, seq)); - - return(ESRCH); + myprintf(("vcwrite got a call for %ld.%ld\n", opcode, seq)); + if (DOWNCALL(opcode)) { + union outputArgs pbuf; + + /* + * Get the rest of the data. + */ + uiop->uio_rw = UIO_WRITE; + error = uiomove((caddr_t)&pbuf.coda_purgeuser.oh.result, + sizeof(pbuf) - (sizeof(int)*2), uiop); + if (error) { + myprintf(("vcwrite: error (%d) on uiomove (Op %ld " + "seq %ld)\n", error, opcode, seq)); + return (EINVAL); + } + return (handleDownCall(opcode, &pbuf)); } - - /* Remove the message from the reply queue */ - REMQUE(vmp->vm_chain); - - /* move data into response buffer. */ - out = (struct coda_out_hdr *)vmp->vm_data; - /* Don't need to copy opcode and uniquifier. */ - - /* get the rest of the data. */ - if (vmp->vm_outSize < uiop->uio_resid) { - myprintf(("vcwrite: more data than asked for (%d < %d)\n", - vmp->vm_outSize, uiop->uio_resid)); - wakeup(&vmp->vm_sleep); /* Notify caller of the error. */ - return(EINVAL); - } - - buf[0] = uiop->uio_resid; /* Save this value. */ - uiop->uio_rw = UIO_WRITE; - error = uiomove((caddr_t) &out->result, vmp->vm_outSize - (sizeof(int) * 2), uiop); - if (error) { - myprintf(("vcwrite: error (%d) on uiomove (op %ld seq %ld)\n", - error, opcode, seq)); - return(EINVAL); - } - - /* I don't think these are used, but just in case. */ - /* XXX - aren't these two already correct? -bnoble */ - out->opcode = opcode; - out->unique = seq; - vmp->vm_outSize = buf[0]; /* Amount of data transferred? */ - vmp->vm_flags |= VM_WRITE; - - error = 0; - if (opcode == CODA_OPEN_BY_FD) { - struct coda_open_by_fd_out *tmp = (struct coda_open_by_fd_out *)out; - struct file *fp; - struct vnode *vp = NULL; - - if (tmp->oh.result == 0) { - error = getvnode(uiop->uio_td->td_proc->p_fd, tmp->fd, &fp); - if (!error) { - mtx_lock(&Giant); - vp = fp->f_vnode; - VREF(vp); - fdrop(fp, uiop->uio_td); - mtx_unlock(&Giant); - } + + /* + * Look for the message on the (waiting for) reply queue. + */ + for (vmp = (struct vmsg *)GETNEXT(vcp->vc_replys); + !EOQ(vmp, vcp->vc_replys); + vmp = (struct vmsg *)GETNEXT(vmp->vm_chain)) { + if (vmp->vm_unique == seq) + break; + } + if (EOQ(vmp, vcp->vc_replys)) { + if (codadebug) + myprintf(("vcwrite: msg (%ld, %ld) not found\n", + opcode, seq)); + return (ESRCH); + } + + /* + * Remove the message from the reply queue. + */ + REMQUE(vmp->vm_chain); + + /* + * Move data into response buffer. + */ + out = (struct coda_out_hdr *)vmp->vm_data; + + /* + * Don't need to copy opcode and uniquifier. + * + * Get the rest of the data. + */ + if (vmp->vm_outSize < uiop->uio_resid) { + myprintf(("vcwrite: more data than asked for (%d < %d)\n", + vmp->vm_outSize, uiop->uio_resid)); + + /* + * Notify caller of the error. + */ + wakeup(&vmp->vm_sleep); + return (EINVAL); + } + + /* + * Save the value. + */ + buf[0] = uiop->uio_resid; + uiop->uio_rw = UIO_WRITE; + error = uiomove((caddr_t) &out->result, vmp->vm_outSize - + (sizeof(int) * 2), uiop); + if (error) { + myprintf(("vcwrite: error (%d) on uiomove (op %ld seq %ld)\n", + error, opcode, seq)); + return (EINVAL); } - tmp->vp = vp; - } - wakeup(&vmp->vm_sleep); - - return(error); + /* + * I don't think these are used, but just in case. + * + * XXX - aren't these two already correct? -bnoble + */ + out->opcode = opcode; + out->unique = seq; + vmp->vm_outSize = buf[0]; /* Amount of data transferred? */ + vmp->vm_flags |= VM_WRITE; + error = 0; + if (opcode == CODA_OPEN_BY_FD) { + struct coda_open_by_fd_out *tmp = + (struct coda_open_by_fd_out *)out; + struct file *fp; + struct vnode *vp = NULL; + + if (tmp->oh.result == 0) { + error = getvnode(uiop->uio_td->td_proc->p_fd, + tmp->fd, &fp); + if (!error) { + /* + * XXX: Since the whole driver runs with + * Giant, don't actually need to acquire it + * explicitly here yet. + */ + mtx_lock(&Giant); + vp = fp->f_vnode; + VREF(vp); + fdrop(fp, uiop->uio_td); + mtx_unlock(&Giant); + } + } + tmp->vp = vp; + } + wakeup(&vmp->vm_sleep); + return (error); } int -vc_ioctl(dev, cmd, addr, flag, td) - struct cdev *dev; - u_long cmd; - caddr_t addr; - int flag; - struct thread *td; +vc_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, + struct thread *t) { - ENTRY; - - switch(cmd) { - case CODARESIZE: { - struct coda_resize *data = (struct coda_resize *)addr; - return(coda_nc_resize(data->hashsize, data->heapsize, IS_DOWNCALL)); - break; - } - case CODASTATS: - if (coda_nc_use) { - coda_nc_gather_stats(); - return(0); - } else { - return(ENODEV); - } - break; - case CODAPRINT: - if (coda_nc_use) { - print_coda_nc(); - return(0); - } else { - return(ENODEV); + + ENTRY; + switch(cmd) { + case CODARESIZE: { + struct coda_resize *data = (struct coda_resize *)addr; + + return (coda_nc_resize(data->hashsize, data->heapsize, + IS_DOWNCALL)); } - break; - case CIOC_KERNEL_VERSION: - switch (*(u_int *)addr) { - case 0: - *(u_int *)addr = coda_kernel_version; - return 0; - break; - case 1: - case 2: - if (coda_kernel_version != *(u_int *)addr) - return ENOENT; - else - return 0; + + case CODASTATS: + if (coda_nc_use) { + coda_nc_gather_stats(); + return (0); + } else + return (ENODEV); + + case CODAPRINT: + if (coda_nc_use) { + print_coda_nc(); + return (0); + } else + return (ENODEV); + + case CIOC_KERNEL_VERSION: + switch (*(u_int *)addr) { + case 0: + *(u_int *)addr = coda_kernel_version; + return (0); + + case 1: + case 2: + if (coda_kernel_version != *(u_int *)addr) + return (ENOENT); + else + return (0); + + default: + return (ENOENT); + } + default: - return ENOENT; + return (EINVAL); } - break; - default : - return(EINVAL); - break; - } } int -vc_poll(dev, events, td) - struct cdev *dev; - int events; - struct thread *td; +vc_poll(struct cdev *dev, int events, struct thread *td) { - register struct vcomm *vcp; - int event_msk = 0; - - ENTRY; - - vcp = &dev2coda_mntinfo(dev)->mi_vcomm; - - event_msk = events & (POLLIN|POLLRDNORM); - if (!event_msk) - return(0); - - if (!EMPTY(vcp->vc_requests)) - return(events & (POLLIN|POLLRDNORM)); - - selrecord(td, &(vcp->vc_selproc)); - - return(0); + struct vcomm *vcp; + int event_msk = 0; + + ENTRY; + vcp = &dev2coda_mntinfo(dev)->mi_vcomm; + event_msk = events & (POLLIN|POLLRDNORM); + if (!event_msk) + return (0); + if (!EMPTY(vcp->vc_requests)) + return (events & (POLLIN|POLLRDNORM)); + selrecord(td, &(vcp->vc_selproc)); + return (0); } /* - * Statistics + * Statistics. */ struct coda_clstat coda_clstat; -/* - * Key question: whether to sleep interuptably or uninteruptably when - * waiting for Venus. The former seems better (cause you can ^C a - * job), but then GNU-EMACS completion breaks. Use tsleep with no - * timeout, and no longjmp happens. But, when sleeping - * "uninterruptibly", we don't get told if it returns abnormally - * (e.g. kill -9). +/* + * Key question: whether to sleep interuptably or uninteruptably when waiting + * for Venus. The former seems better (cause you can ^C a job), but then + * GNU-EMACS completion breaks. Use tsleep with no timeout, and no longjmp + * happens. But, when sleeping "uninterruptibly", we don't get told if it + * returns abnormally (e.g. kill -9). */ - int -coda_call(mntinfo, inSize, outSize, buffer) - struct coda_mntinfo *mntinfo; int inSize; int *outSize; caddr_t buffer; +coda_call(struct coda_mntinfo *mntinfo, int inSize, int *outSize, + caddr_t buffer) { struct vcomm *vcp; struct vmsg *vmp; int error; -#ifdef CTL_C +#ifdef CTL_C struct thread *td = curthread; struct proc *p = td->td_proc; sigset_t psig_omask; sigset_t tempset; int i; #endif - if (mntinfo == NULL) { - /* Unlikely, but could be a race condition with a dying warden */ - return ENODEV; - } + /* + * Unlikely, but could be a race condition with a dying warden. + */ + if (mntinfo == NULL) + return ENODEV; vcp = &(mntinfo->mi_vcomm); - coda_clstat.ncalls++; coda_clstat.reqs[((struct coda_in_hdr *)buffer)->opcode]++; - if (!VC_OPEN(vcp)) - return(ENODEV); - + return (ENODEV); CODA_ALLOC(vmp,struct vmsg *,sizeof(struct vmsg)); - /* Format the request message. */ + + /* + * Format the request message. + */ vmp->vm_data = buffer; vmp->vm_flags = 0; vmp->vm_inSize = inSize; - vmp->vm_outSize + vmp->vm_outSize = *outSize ? *outSize : inSize; /* |buffer| >= inSize */ vmp->vm_opcode = ((struct coda_in_hdr *)buffer)->opcode; vmp->vm_unique = ++vcp->vc_seq; if (codadebug) - myprintf(("Doing a call for %d.%d\n", - vmp->vm_opcode, vmp->vm_unique)); - - /* Fill in the common input args. */ + myprintf(("Doing a call for %d.%d\n", vmp->vm_opcode, + vmp->vm_unique)); + + /* + * Fill in the common input args. + */ ((struct coda_in_hdr *)buffer)->unique = vmp->vm_unique; - /* Append msg to request queue and poke Venus. */ + /* + * Append msg to request queue and poke Venus. + */ INSQUE(vmp->vm_chain, vcp->vc_requests); selwakeuppri(&(vcp->vc_selproc), coda_call_sleep); - /* We can be interrupted while we wait for Venus to process - * our request. If the interrupt occurs before Venus has read - * the request, we dequeue and return. If it occurs after the - * read but before the reply, we dequeue, send a signal - * message, and return. If it occurs after the reply we ignore - * it. In no case do we want to restart the syscall. If it - * was interrupted by a venus shutdown (vcclose), return - * ENODEV. */ - - /* Ignore return, We have to check anyway */ -#ifdef CTL_C - /* This is work in progress. Setting coda_pcatch lets tsleep reawaken - on a ^c or ^z. The problem is that emacs sets certain interrupts - as SA_RESTART. This means that we should exit sleep handle the - "signal" and then go to sleep again. Mostly this is done by letting - the syscall complete and be restarted. We are not idempotent and - can not do this. A better solution is necessary. + /* + * We can be interrupted while we wait for Venus to process our + * request. If the interrupt occurs before Venus has read the + * request, we dequeue and return. If it occurs after the read but + * before the reply, we dequeue, send a signal message, and return. + * If it occurs after the reply we ignore it. In no case do we want + * to restart the syscall. If it was interrupted by a venus shutdown + * (vcclose), return ENODEV. + * + * Ignore return, we have to check anyway. + */ +#ifdef CTL_C + /* + * This is work in progress. Setting coda_pcatch lets tsleep + * reawaken on a ^c or ^z. The problem is that emacs sets certain + * interrupts as SA_RESTART. This means that we should exit sleep + * handle the "signal" and then go to sleep again. Mostly this is + * done by letting the syscall complete and be restarted. We are not + * idempotent and can not do this. A better solution is necessary. */ i = 0; PROC_LOCK(p); psig_omask = td->td_sigmask; do { error = msleep(&vmp->vm_sleep, &p->p_mtx, - (coda_call_sleep|coda_pcatch), "coda_call", - hz*2); + (coda_call_sleep|coda_pcatch), "coda_call", hz*2); if (error == 0) break; else if (error == EWOULDBLOCK) { -#ifdef CODA_VERBOSE +#ifdef CODA_VERBOSE printf("coda_call: tsleep TIMEOUT %d sec\n", 2+2*i); #endif } @@ -562,39 +571,40 @@ coda_call(mntinfo, inSize, outSize, buffer) SIGADDSET(tempset, SIGIO); if (SIGSETEQ(td->td_siglist, tempset)) { SIGADDSET(td->td_sigmask, SIGIO); -#ifdef CODA_VERBOSE - printf("coda_call: tsleep returns %d SIGIO, cnt %d\n", - error, i); +#ifdef CODA_VERBOSE + printf("coda_call: tsleep returns %d SIGIO, " + "cnt %d\n", error, i); #endif } else { SIGDELSET(tempset, SIGIO); SIGADDSET(tempset, SIGALRM); if (SIGSETEQ(td->td_siglist, tempset)) { SIGADDSET(td->td_sigmask, SIGALRM); -#ifdef CODA_VERBOSE - printf("coda_call: tsleep returns %d SIGALRM, cnt %d\n", - error, i); +#ifdef CODA_VERBOSE + printf("coda_call: tsleep returns " + "%d SIGALRM, cnt %d\n", error, i); #endif - } - else { -#ifdef CODA_VERBOSE - printf("coda_call: tsleep returns %d, cnt %d\n", - error, i); + } else { +#ifdef CODA_VERBOSE + printf("coda_call: tsleep returns " + "%d, cnt %d\n", error, i); #endif #ifdef notyet tempset = td->td_siglist; SIGSETNAND(tempset, td->td_sigmask); - printf("coda_call: siglist = %p, sigmask = %p, mask %p\n", - td->td_siglist, td->td_sigmask, - tempset); + printf("coda_call: siglist = %p, " + "sigmask = %p, mask %p\n", + td->td_siglist, td->td_sigmask, + tempset); break; SIGSETOR(td->td_sigmask, td->td_siglist); tempset = td->td_siglist; SIGSETNAND(tempset, td->td_sigmask); - printf("coda_call: new mask, siglist = %p, sigmask = %p, mask %p\n", - td->td_siglist, td->td_sigmask, - tempset); + printf("coda_call: new mask, " + "siglist = %p, sigmask = %p, " + "mask %p\n", td->td_siglist, + td->td_sigmask, tempset); #endif } } @@ -604,81 +614,81 @@ coda_call(mntinfo, inSize, outSize, buffer) signotify(td); PROC_UNLOCK(p); #else - (void) tsleep(&vmp->vm_sleep, coda_call_sleep, "coda_call", 0); + (void)tsleep(&vmp->vm_sleep, coda_call_sleep, "coda_call", 0); #endif - if (VC_OPEN(vcp)) { /* Venus is still alive */ - /* Op went through, interrupt or not... */ - if (vmp->vm_flags & VM_WRITE) { - error = 0; - *outSize = vmp->vm_outSize; - } - - else if (!(vmp->vm_flags & VM_READ)) { - /* Interrupted before venus read it. */ -#ifdef CODA_VERBOSE - if (1) + if (VC_OPEN(vcp)) { + /* + * Venus is still alive. + * + * Op went through, interrupt or not... + */ + if (vmp->vm_flags & VM_WRITE) { + error = 0; + *outSize = vmp->vm_outSize; + } else if (!(vmp->vm_flags & VM_READ)) { + /* Interrupted before venus read it. */ +#ifdef CODA_VERBOSE + if (1) #else - if (codadebug) + if (codadebug) #endif - myprintf(("interrupted before read: op = %d.%d, flags = %x\n", - vmp->vm_opcode, vmp->vm_unique, vmp->vm_flags)); - REMQUE(vmp->vm_chain); - error = EINTR; - } - - else { - /* (!(vmp->vm_flags & VM_WRITE)) means interrupted after - upcall started */ - /* Interrupted after start of upcall, send venus a signal */ - struct coda_in_hdr *dog; - struct vmsg *svmp; - -#ifdef CODA_VERBOSE - if (1) + myprintf(("interrupted before read: op = " + "%d.%d, flags = %x\n", vmp->vm_opcode, + vmp->vm_unique, vmp->vm_flags)); + REMQUE(vmp->vm_chain); + error = EINTR; + } else { + /* + * (!(vmp->vm_flags & VM_WRITE)) means interrupted + * after upcall started. + * + * Interrupted after start of upcall, send venus a + * signal. + */ + struct coda_in_hdr *dog; + struct vmsg *svmp; + +#ifdef CODA_VERBOSE + if (1) #else - if (codadebug) + if (codadebug) #endif - myprintf(("Sending Venus a signal: op = %d.%d, flags = %x\n", - vmp->vm_opcode, vmp->vm_unique, vmp->vm_flags)); - - REMQUE(vmp->vm_chain); - error = EINTR; - - CODA_ALLOC(svmp, struct vmsg *, sizeof (struct vmsg)); - - CODA_ALLOC((svmp->vm_data), char *, sizeof (struct coda_in_hdr)); - dog = (struct coda_in_hdr *)svmp->vm_data; - - svmp->vm_flags = 0; - dog->opcode = svmp->vm_opcode = CODA_SIGNAL; - dog->unique = svmp->vm_unique = vmp->vm_unique; - svmp->vm_inSize = sizeof (struct coda_in_hdr); -/*??? rvb */ svmp->vm_outSize = sizeof (struct coda_in_hdr); - + myprintf(("Sending Venus a signal: op = " + "%d.%d, flags = %x\n", vmp->vm_opcode, + vmp->vm_unique, vmp->vm_flags)); + REMQUE(vmp->vm_chain); + error = EINTR; + CODA_ALLOC(svmp, struct vmsg *, sizeof(struct vmsg)); + CODA_ALLOC((svmp->vm_data), char *, + sizeof(struct coda_in_hdr)); + dog = (struct coda_in_hdr *)svmp->vm_data; + svmp->vm_flags = 0; + dog->opcode = svmp->vm_opcode = CODA_SIGNAL; + dog->unique = svmp->vm_unique = vmp->vm_unique; + svmp->vm_inSize = sizeof (struct coda_in_hdr); +/*??? rvb */ svmp->vm_outSize = sizeof (struct coda_in_hdr); + if (codadebug) + myprintf(("coda_call: enqueing signal msg " + "(%d, %d)\n", svmp->vm_opcode, + svmp->vm_unique)); + + /* + * Insert at head of queue! + */ + INSQUE(svmp->vm_chain, vcp->vc_requests); + selwakeuppri(&(vcp->vc_selproc), coda_call_sleep); + } + } else { + /* If venus died (!VC_OPEN(vcp)) */ if (codadebug) - myprintf(("coda_call: enqueing signal msg (%d, %d)\n", - svmp->vm_opcode, svmp->vm_unique)); - - /* insert at head of queue! */ - INSQUE(svmp->vm_chain, vcp->vc_requests); - selwakeuppri(&(vcp->vc_selproc), coda_call_sleep); - } - } - - else { /* If venus died (!VC_OPEN(vcp)) */ - if (codadebug) - myprintf(("vcclose woke op %d.%d flags %d\n", - vmp->vm_opcode, vmp->vm_unique, vmp->vm_flags)); - + myprintf(("vcclose woke op %d.%d flags %d\n", + vmp->vm_opcode, vmp->vm_unique, vmp->vm_flags)); error = ENODEV; } - CODA_FREE(vmp, sizeof(struct vmsg)); - if (outstanding_upcalls > 0 && (--outstanding_upcalls == 0)) wakeup(&outstanding_upcalls); - if (!error) error = ((struct coda_out_hdr *)buffer)->result; - return(error); + return (error); } diff --git a/sys/fs/coda/coda_psdev.h b/sys/fs/coda/coda_psdev.h index a446e3d..021456b 100644 --- a/sys/fs/coda/coda_psdev.h +++ b/sys/fs/coda/coda_psdev.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,26 +14,33 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/coda/coda_psdev.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * */ +#ifndef _CODA_PSDEV_H_ +#define _CODA_PSDEV_H_ + +/* + * Prototypes for cfs device operations. + */ d_open_t vc_open; d_close_t vc_close; d_read_t vc_read; d_write_t vc_write; d_ioctl_t vc_ioctl; d_poll_t vc_poll; + +#endif /* !_CODA_PSDEV_H_ */ diff --git a/sys/fs/coda/coda_subr.c b/sys/fs/coda/coda_subr.c index c49309a..9183bf0a 100644 --- a/sys/fs/coda/coda_subr.c +++ b/sys/fs/coda/coda_subr.c @@ -1,10 +1,10 @@ /*- * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -13,20 +13,21 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/coda/coda_subr.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ */ + /*- * Mach Operating System * Copyright (c) 1989 Carnegie-Mellon University @@ -40,15 +41,16 @@ * M. Satyanarayanan. */ -/* NOTES: rvb - * 1. Added coda_unmounting to mark all cnodes as being UNMOUNTING. This has to - * be done before dounmount is called. Because some of the routines that - * dounmount calls before coda_unmounted might try to force flushes to venus. - * The vnode pager does this. +/*- + * NOTES: rvb + * 1. Added coda_unmounting to mark all cnodes as being UNMOUNTING. This + * has to be done before dounmount is called. Because some of the + * routines that dounmount calls before coda_unmounted might try to + * force flushes to venus. The vnode pager does this. * 2. coda_unmounting marks all cnodes scanning coda_cache. - * 3. cfs_checkunmounting (under DEBUG) checks all cnodes by chasing the vnodes - * under the /coda mount point. - * 4. coda_cacheprint (under DEBUG) prints names with vnode/cnode address + * 3. cfs_checkunmounting (under DEBUG) checks all cnodes by chasing the + * vnodes under the /coda mount point. + * 4. coda_cacheprint (under DEBUG) prints names with vnode/cnode address. */ #include @@ -66,22 +68,21 @@ __FBSDID("$FreeBSD$"); #include #include -int coda_active = 0; -int coda_reuse = 0; -int coda_new = 0; +static int coda_active = 0; +static int coda_reuse = 0; +static int coda_new = 0; -struct cnode *coda_freelist = NULL; -struct cnode *coda_cache[CODA_CACHESIZE]; +static struct cnode *coda_freelist = NULL; +static struct cnode *coda_cache[CODA_CACHESIZE]; #define CNODE_NEXT(cp) ((cp)->c_next) #ifdef CODA_COMPAT_5 -#define coda_hash(fid) \ - (((fid)->Volume + (fid)->Vnode) & (CODA_CACHESIZE-1)) -#define IS_DIR(cnode) (cnode.Vnode & 0x1) +#define coda_hash(fid) (((fid)->Volume + (fid)->Vnode) & (CODA_CACHESIZE-1)) +#define IS_DIR(cnode) (cnode.Vnode & 0x1) #else -#define coda_hash(fid) (coda_f2i(fid) & (CODA_CACHESIZE-1)) -#define IS_DIR(cnode) (cnode.opaque[2] & 0x1) +#define coda_hash(fid) (coda_f2i(fid) & (CODA_CACHESIZE-1)) +#define IS_DIR(cnode) (cnode.opaque[2] & 0x1) #endif /* @@ -90,210 +91,208 @@ struct cnode *coda_cache[CODA_CACHESIZE]; struct cnode * coda_alloc(void) { - struct cnode *cp; - - if (coda_freelist) { - cp = coda_freelist; - coda_freelist = CNODE_NEXT(cp); - coda_reuse++; - } - else { - CODA_ALLOC(cp, struct cnode *, sizeof(struct cnode)); - /* FreeBSD vnodes don't have any Pager info in them ('cause there are - no external pagers, duh!) */ -#define VNODE_VM_INFO_INIT(vp) /* MT */ - VNODE_VM_INFO_INIT(CTOV(cp)); - coda_new++; - } - bzero(cp, sizeof (struct cnode)); - - return(cp); + struct cnode *cp; + + if (coda_freelist != NULL) { + cp = coda_freelist; + coda_freelist = CNODE_NEXT(cp); + coda_reuse++; + } else { + CODA_ALLOC(cp, struct cnode *, sizeof(struct cnode)); + + /* + * FreeBSD vnodes don't have any Pager info in them ('cause + * there are no external pagers, duh!). + */ +#define VNODE_VM_INFO_INIT(vp) /* MT */ + VNODE_VM_INFO_INIT(CTOV(cp)); + coda_new++; + } + bzero(cp, sizeof (struct cnode)); + return (cp); } /* * Deallocate a cnode. */ void -coda_free(cp) - register struct cnode *cp; +coda_free(struct cnode *cp) { - CNODE_NEXT(cp) = coda_freelist; - coda_freelist = cp; + CNODE_NEXT(cp) = coda_freelist; + coda_freelist = cp; } /* - * Put a cnode in the hash table + * Put a cnode in the hash table. */ void -coda_save(cp) - struct cnode *cp; +coda_save(struct cnode *cp) { + CNODE_NEXT(cp) = coda_cache[coda_hash(&cp->c_fid)]; coda_cache[coda_hash(&cp->c_fid)] = cp; } /* - * Remove a cnode from the hash table + * Remove a cnode from the hash table. */ void -coda_unsave(cp) - struct cnode *cp; +coda_unsave(struct cnode *cp) { - struct cnode *ptr; - struct cnode *ptrprev = NULL; - - ptr = coda_cache[coda_hash(&cp->c_fid)]; - while (ptr != NULL) { - if (ptr == cp) { - if (ptrprev == NULL) { - coda_cache[coda_hash(&cp->c_fid)] - = CNODE_NEXT(ptr); - } else { - CNODE_NEXT(ptrprev) = CNODE_NEXT(ptr); - } - CNODE_NEXT(cp) = (struct cnode *)NULL; - - return; - } - ptrprev = ptr; - ptr = CNODE_NEXT(ptr); - } + struct cnode *ptr; + struct cnode *ptrprev = NULL; + + ptr = coda_cache[coda_hash(&cp->c_fid)]; + while (ptr != NULL) { + if (ptr == cp) { + if (ptrprev == NULL) + coda_cache[coda_hash(&cp->c_fid)] = + CNODE_NEXT(ptr); + else + CNODE_NEXT(ptrprev) = CNODE_NEXT(ptr); + CNODE_NEXT(cp) = (struct cnode *)NULL; + return; + } + ptrprev = ptr; + ptr = CNODE_NEXT(ptr); + } } /* * Lookup a cnode by fid. If the cnode is dying, it is bogus so skip it. + * * NOTE: this allows multiple cnodes with same fid -- dcs 1/25/95 */ struct cnode * -coda_find(fid) - CodaFid *fid; +coda_find(CodaFid *fid) { - struct cnode *cp; - - cp = coda_cache[coda_hash(fid)]; - while (cp) { - if (coda_fid_eq(&(cp->c_fid), fid) && - (!IS_UNMOUNTING(cp))) - { - coda_active++; - return(cp); - } - cp = CNODE_NEXT(cp); - } - return(NULL); + struct cnode *cp; + + cp = coda_cache[coda_hash(fid)]; + while (cp) { + if (coda_fid_eq(&(cp->c_fid), fid) && (!IS_UNMOUNTING(cp))) { + coda_active++; + return (cp); + } + cp = CNODE_NEXT(cp); + } + return (NULL); } /* - * coda_kill is called as a side effect to vcopen. To prevent any - * cnodes left around from an earlier run of a venus or warden from - * causing problems with the new instance, mark any outstanding cnodes - * as dying. Future operations on these cnodes should fail (excepting - * coda_inactive of course!). Since multiple venii/wardens can be - * running, only kill the cnodes for a particular entry in the - * coda_mnttbl. -- DCS 12/1/94 */ - + * coda_kill is called as a side effect to vcopen. To prevent any cnodes + * left around from an earlier run of a venus or warden from causing problems + * with the new instance, mark any outstanding cnodes as dying. Future + * operations on these cnodes should fail (excepting coda_inactive of + * course!). Since multiple venii/wardens can be running, only kill the + * cnodes for a particular entry in the coda_mnttbl. -- DCS 12/1/94 + */ int -coda_kill(whoIam, dcstat) - struct mount *whoIam; - enum dc_status dcstat; +coda_kill(struct mount *whoIam, enum dc_status dcstat) { int hash, count = 0; struct cnode *cp; - - /* - * Algorithm is as follows: + + /*- + * Algorithm is as follows: * Second, flush whatever vnodes we can from the name cache. - * + * * Finally, step through whatever is left and mark them dying. * This prevents any operation at all. + * + * This is slightly overkill, but should work. Eventually it'd be + * nice to only flush those entries from the namecache that reference + * a vnode in this vfs. */ - - /* This is slightly overkill, but should work. Eventually it'd be - * nice to only flush those entries from the namecache that - * reference a vnode in this vfs. */ coda_nc_flush(dcstat); - for (hash = 0; hash < CODA_CACHESIZE; hash++) { - for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) { + for (cp = coda_cache[hash];cp != NULL; + cp = CNODE_NEXT(cp)) { if (CTOV(cp)->v_mount == whoIam) { -#ifdef DEBUG - printf("coda_kill: vp %p, cp %p\n", CTOV(cp), cp); +#ifdef DEBUG + printf("coda_kill: vp %p, cp %p\n", CTOV(cp), + cp); #endif count++; - CODADEBUG(CODA_FLUSH, - myprintf(("Live cnode fid %s flags %d count %d\n", - coda_f2s(&cp->c_fid), - cp->c_flags, - vrefcnt(CTOV(cp)))); ); + CODADEBUG(CODA_FLUSH, myprintf(("Live cnode " + "fid %s flags %d count %d\n", + coda_f2s(&cp->c_fid), cp->c_flags, + vrefcnt(CTOV(cp))));); } } } - return count; + return (count); } /* - * There are two reasons why a cnode may be in use, it may be in the - * name cache or it may be executing. + * There are two reasons why a cnode may be in use, it may be in the name + * cache or it may be executing. */ void -coda_flush(dcstat) - enum dc_status dcstat; +coda_flush(enum dc_status dcstat) { - int hash; - struct cnode *cp; - - coda_clstat.ncalls++; - coda_clstat.reqs[CODA_FLUSH]++; - - coda_nc_flush(dcstat); /* flush files from the name cache */ - - for (hash = 0; hash < CODA_CACHESIZE; hash++) { - for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) { - if (!IS_DIR(cp->c_fid)) /* only files can be executed */ - coda_vmflush(cp); + int hash; + struct cnode *cp; + + coda_clstat.ncalls++; + coda_clstat.reqs[CODA_FLUSH]++; + + /* + * Flush files from the name cache. + */ + coda_nc_flush(dcstat); + for (hash = 0; hash < CODA_CACHESIZE; hash++) { + for (cp = coda_cache[hash]; cp != NULL; + cp = CNODE_NEXT(cp)) { + /* + * Only files that can be executed need to be flushed + * from the VM. + * + * NOTE: Currently this doesn't do anything, but + * perhaps it should? + */ + if (!IS_DIR(cp->c_fid)) + coda_vmflush(cp); + } } - } } /* - * As a debugging measure, print out any cnodes that lived through a - * name cache flush. + * As a debugging measure, print out any cnodes that lived through a name + * cache flush. */ void coda_testflush(void) { - int hash; - struct cnode *cp; - - for (hash = 0; hash < CODA_CACHESIZE; hash++) { - for (cp = coda_cache[hash]; - cp != NULL; - cp = CNODE_NEXT(cp)) { - myprintf(("Live cnode fid %s count %d\n", - coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount)); + int hash; + struct cnode *cp; + + for (hash = 0; hash < CODA_CACHESIZE; hash++) { + for (cp = coda_cache[hash]; cp != NULL; + cp = CNODE_NEXT(cp)) + myprintf(("Live cnode fid %s count %d\n", + coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount)); } - } } /* - * First, step through all cnodes and mark them unmounting. - * FreeBSD kernels may try to fsync them now that venus - * is dead, which would be a bad thing. - * + * First, step through all cnodes and mark them unmounting. FreeBSD kernels + * may try to fsync them now that venus is dead, which would be a bad thing. */ void -coda_unmounting(whoIam) - struct mount *whoIam; -{ +coda_unmounting(struct mount *whoIam) +{ int hash; struct cnode *cp; for (hash = 0; hash < CODA_CACHESIZE; hash++) { - for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) { + for (cp = coda_cache[hash]; cp != NULL; + cp = CNODE_NEXT(cp)) { if (CTOV(cp)->v_mount == whoIam) { if (cp->c_flags & (C_LOCKED|C_WANTED)) { - printf("coda_unmounting: Unlocking %p\n", cp); + printf("coda_unmounting: Unlocking " + "%p\n", cp); cp->c_flags &= ~(C_LOCKED|C_WANTED); wakeup((caddr_t) cp); } @@ -303,10 +302,9 @@ coda_unmounting(whoIam) } } -#ifdef DEBUG +#ifdef DEBUG void -coda_checkunmounting(mp) - struct mount *mp; +coda_checkunmounting(struct mount *mp) { struct vnode *vp, *nvp; struct cnode *cp; @@ -332,21 +330,22 @@ coda_checkunmounting(mp) } void -coda_cacheprint(whoIam) - struct mount *whoIam; -{ +coda_cacheprint(struct mount *whoIam) +{ int hash; struct cnode *cp; int count = 0; - printf("coda_cacheprint: coda_ctlvp %p, cp %p", coda_ctlvp, VTOC(coda_ctlvp)); + printf("coda_cacheprint: coda_ctlvp %p, cp %p", coda_ctlvp, + VTOC(coda_ctlvp)); coda_nc_name(VTOC(coda_ctlvp)); printf("\n"); - for (hash = 0; hash < CODA_CACHESIZE; hash++) { - for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) { + for (cp = coda_cache[hash]; cp != NULL; + cp = CNODE_NEXT(cp)) { if (CTOV(cp)->v_mount == whoIam) { - printf("coda_cacheprint: vp %p, cp %p", CTOV(cp), cp); + printf("coda_cacheprint: vp %p, cp %p", + CTOV(cp), cp); coda_nc_name(cp); printf("\n"); count++; @@ -357,202 +356,201 @@ coda_cacheprint(whoIam) } #endif -/* - * There are 6 cases where invalidations occur. The semantics of each - * is listed here. +/*- + * There are 6 cases where invalidations occur. The semantics of each is + * listed here: + * + * CODA_FLUSH -- Flush all entries from the name cache and the cnode + * cache. + * + * CODA_PURGEUSER -- Flush all entries from the name cache for a specific + * user. This call is a result of token expiration. * - * CODA_FLUSH -- flush all entries from the name cache and the cnode cache. - * CODA_PURGEUSER -- flush all entries from the name cache for a specific user - * This call is a result of token expiration. + * The next two are the result of callbacks on a file or directory: * - * The next two are the result of callbacks on a file or directory. - * CODA_ZAPDIR -- flush the attributes for the dir from its cnode. - * Zap all children of this directory from the namecache. - * CODA_ZAPFILE -- flush the attributes for a file. + * CODA_ZAPDIR -- Flush the attributes for the dir from its cnode. Zap + * all children of this directory from the namecache. * - * The fifth is a result of Venus detecting an inconsistent file. - * CODA_PURGEFID -- flush the attribute for the file - * If it is a dir (odd vnode), purge its - * children from the namecache - * remove the file from the namecache. + * CODA_ZAPFILE -- Flush the attributes for a file. * - * The sixth allows Venus to replace local fids with global ones - * during reintegration. + * The fifth is a result of Venus detecting an inconsistent file: * - * CODA_REPLACE -- replace one CodaFid with another throughout the name cache + * CODA_PURGEFID -- Flush the attribute for the file; if it is a dir (odd + * vnode), purge its children from the namecache; remove + * the file from the namecache. + * + * The sixth allows Venus to replace local fids with global ones during + * reintegration. + * + * CODA_REPLACE -- Replace one CodaFid with another throughout the name + * cache. */ - -int handleDownCall(opcode, out) - int opcode; union outputArgs *out; +int handleDownCall(int opcode, union outputArgs *out) { - int error; + int error; + + /* + * Handle invalidate requests. + */ + switch (opcode) { + case CODA_FLUSH: { + coda_flush(IS_DOWNCALL); - /* Handle invalidate requests. */ - switch (opcode) { - case CODA_FLUSH : { + /* Print any remaining cnodes. */ + CODADEBUG(CODA_FLUSH, coda_testflush();); + return (0); + } - coda_flush(IS_DOWNCALL); - - CODADEBUG(CODA_FLUSH,coda_testflush();) /* print remaining cnodes */ - return(0); - } - - case CODA_PURGEUSER : { - coda_clstat.ncalls++; - coda_clstat.reqs[CODA_PURGEUSER]++; - - /* XXX - need to prevent fsync's */ + case CODA_PURGEUSER: { + coda_clstat.ncalls++; + coda_clstat.reqs[CODA_PURGEUSER]++; + + /* XXX - need to prevent fsync's. */ #ifdef CODA_COMPAT_5 - coda_nc_purge_user(out->coda_purgeuser.cred.cr_uid, IS_DOWNCALL); + coda_nc_purge_user(out->coda_purgeuser.cred.cr_uid, + IS_DOWNCALL); #else - coda_nc_purge_user(out->coda_purgeuser.uid, IS_DOWNCALL); + coda_nc_purge_user(out->coda_purgeuser.uid, IS_DOWNCALL); #endif - return(0); - } - - case CODA_ZAPFILE : { - struct cnode *cp; - - error = 0; - coda_clstat.ncalls++; - coda_clstat.reqs[CODA_ZAPFILE]++; - - cp = coda_find(&out->coda_zapfile.Fid); - if (cp != NULL) { - vref(CTOV(cp)); - - cp->c_flags &= ~C_VATTR; - ASSERT_VOP_LOCKED(CTOV(cp), "coda HandleDownCall"); - if (CTOV(cp)->v_vflag & VV_TEXT) - error = coda_vmflush(cp); - CODADEBUG(CODA_ZAPFILE, - myprintf(("zapfile: fid = %s, refcnt = %d, error = %d\n", - coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1, error));); - if (vrefcnt(CTOV(cp)) == 1) { - cp->c_flags |= C_PURGING; - } - vrele(CTOV(cp)); - } - - return(error); - } - - case CODA_ZAPDIR : { - struct cnode *cp; - - coda_clstat.ncalls++; - coda_clstat.reqs[CODA_ZAPDIR]++; - - cp = coda_find(&out->coda_zapdir.Fid); - if (cp != NULL) { - vref(CTOV(cp)); - - cp->c_flags &= ~C_VATTR; - coda_nc_zapParentfid(&out->coda_zapdir.Fid, IS_DOWNCALL); - - CODADEBUG(CODA_ZAPDIR, myprintf(( - "zapdir: fid = %s, refcnt = %d\n", - coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1));); - if (vrefcnt(CTOV(cp)) == 1) { - cp->c_flags |= C_PURGING; - } - vrele(CTOV(cp)); - } - - return(0); - } - - case CODA_PURGEFID : { - struct cnode *cp; - - error = 0; - coda_clstat.ncalls++; - coda_clstat.reqs[CODA_PURGEFID]++; - - cp = coda_find(&out->coda_purgefid.Fid); - if (cp != NULL) { - vref(CTOV(cp)); - if (IS_DIR(out->coda_purgefid.Fid)) { /* Vnode is a directory */ - coda_nc_zapParentfid(&out->coda_purgefid.Fid,IS_DOWNCALL); - } - cp->c_flags &= ~C_VATTR; - coda_nc_zapfid(&out->coda_purgefid.Fid, IS_DOWNCALL); - ASSERT_VOP_LOCKED(CTOV(cp), "coda HandleDownCall"); - if (!(IS_DIR(out->coda_purgefid.Fid)) - && (CTOV(cp)->v_vflag & VV_TEXT)) { - - error = coda_vmflush(cp); - } - CODADEBUG(CODA_PURGEFID, myprintf(( - "purgefid: fid = %s, refcnt = %d, error = %d\n", - coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1, error));); - if (vrefcnt(CTOV(cp)) == 1) { - cp->c_flags |= C_PURGING; - } - vrele(CTOV(cp)); - } - return(error); + return (0); + } + + case CODA_ZAPFILE: { + struct cnode *cp; + + error = 0; + coda_clstat.ncalls++; + coda_clstat.reqs[CODA_ZAPFILE]++; + cp = coda_find(&out->coda_zapfile.Fid); + if (cp != NULL) { + vref(CTOV(cp)); + cp->c_flags &= ~C_VATTR; + ASSERT_VOP_LOCKED(CTOV(cp), "coda HandleDownCall"); + if (CTOV(cp)->v_vflag & VV_TEXT) + error = coda_vmflush(cp); + CODADEBUG(CODA_ZAPFILE, + myprintf(("zapfile: fid = %s, refcnt = %d, error = " + "%d\n", coda_f2s(&cp->c_fid), + CTOV(cp)->v_usecount - 1, error));); + if (vrefcnt(CTOV(cp)) == 1) + cp->c_flags |= C_PURGING; + vrele(CTOV(cp)); + } + return (error); } - case CODA_REPLACE : { - struct cnode *cp = NULL; - - coda_clstat.ncalls++; - coda_clstat.reqs[CODA_REPLACE]++; - - cp = coda_find(&out->coda_replace.OldFid); - if (cp != NULL) { - /* remove the cnode from the hash table, replace the fid, and reinsert */ - vref(CTOV(cp)); - coda_unsave(cp); - cp->c_fid = out->coda_replace.NewFid; - coda_save(cp); - - CODADEBUG(CODA_REPLACE, myprintf(( - "replace: oldfid = %s, newfid = %s, cp = %p\n", - coda_f2s(&out->coda_replace.OldFid), - coda_f2s(&cp->c_fid), cp));) vrele(CTOV(cp)); - } - return (0); + case CODA_ZAPDIR: { + struct cnode *cp; + + coda_clstat.ncalls++; + coda_clstat.reqs[CODA_ZAPDIR]++; + cp = coda_find(&out->coda_zapdir.Fid); + if (cp != NULL) { + vref(CTOV(cp)); + cp->c_flags &= ~C_VATTR; + coda_nc_zapParentfid(&out->coda_zapdir.Fid, + IS_DOWNCALL); + CODADEBUG(CODA_ZAPDIR, myprintf(("zapdir: fid = %s, " + "refcnt = %d\n", coda_f2s(&cp->c_fid), + CTOV(cp)->v_usecount - 1));); + if (vrefcnt(CTOV(cp)) == 1) + cp->c_flags |= C_PURGING; + vrele(CTOV(cp)); + } + return (0); } - default: - myprintf(("handleDownCall: unknown opcode %d\n", opcode)); - return (EINVAL); - } -} -/* coda_grab_vnode: lives in either cfs_mach.c or cfs_nbsd.c */ + case CODA_PURGEFID: { + struct cnode *cp; + + error = 0; + coda_clstat.ncalls++; + coda_clstat.reqs[CODA_PURGEFID]++; + cp = coda_find(&out->coda_purgefid.Fid); + if (cp != NULL) { + vref(CTOV(cp)); + if (IS_DIR(out->coda_purgefid.Fid)) + coda_nc_zapParentfid(&out->coda_purgefid.Fid, + IS_DOWNCALL); + cp->c_flags &= ~C_VATTR; + coda_nc_zapfid(&out->coda_purgefid.Fid, IS_DOWNCALL); + ASSERT_VOP_LOCKED(CTOV(cp), "coda HandleDownCall"); + if (!(IS_DIR(out->coda_purgefid.Fid)) + && (CTOV(cp)->v_vflag & VV_TEXT)) + error = coda_vmflush(cp); + CODADEBUG(CODA_PURGEFID, myprintf(("purgefid: fid " + "= %s, refcnt = %d, error = %d\n", + coda_f2s(&cp->c_fid), + CTOV(cp)->v_usecount - 1, error));); + if (vrefcnt(CTOV(cp)) == 1) + cp->c_flags |= C_PURGING; + vrele(CTOV(cp)); + } + return (error); + } + + case CODA_REPLACE: { + struct cnode *cp = NULL; + + coda_clstat.ncalls++; + coda_clstat.reqs[CODA_REPLACE]++; + cp = coda_find(&out->coda_replace.OldFid); + if (cp != NULL) { + /* + * Remove the cnode from the hash table, replace the + * fid, and reinsert. + */ + vref(CTOV(cp)); + coda_unsave(cp); + cp->c_fid = out->coda_replace.NewFid; + coda_save(cp); + CODADEBUG(CODA_REPLACE, myprintf(("replace: oldfid " + "= %s, newfid = %s, cp = %p\n", + coda_f2s(&out->coda_replace.OldFid), + coda_f2s(&cp->c_fid), cp));); + vrele(CTOV(cp)); + } + return (0); + } + default: + myprintf(("handleDownCall: unknown opcode %d\n", opcode)); + return (EINVAL); + } +} int -coda_vmflush(cp) - struct cnode *cp; +coda_vmflush(struct cnode *cp) { - return 0; -} + return (0); +} -/* - * kernel-internal debugging switches +/* + * Kernel-internal debugging switches. */ -void coda_debugon(void) +void +coda_debugon(void) { - codadebug = -1; - coda_nc_debug = -1; - coda_vnop_print_entry = 1; - coda_psdev_print_entry = 1; - coda_vfsop_print_entry = 1; + + codadebug = -1; + coda_nc_debug = -1; + coda_vnop_print_entry = 1; + coda_psdev_print_entry = 1; + coda_vfsop_print_entry = 1; } -void coda_debugoff(void) +void +coda_debugoff(void) { - codadebug = 0; - coda_nc_debug = 0; - coda_vnop_print_entry = 0; - coda_psdev_print_entry = 0; - coda_vfsop_print_entry = 0; + + codadebug = 0; + coda_nc_debug = 0; + coda_vnop_print_entry = 0; + coda_psdev_print_entry = 0; + coda_vfsop_print_entry = 0; } -/* +/*- * Utilities used by both client and server * Standard levels: * 0) no debugging diff --git a/sys/fs/coda/coda_subr.h b/sys/fs/coda/coda_subr.h index 91bf122..2b307cb 100644 --- a/sys/fs/coda/coda_subr.h +++ b/sys/fs/coda/coda_subr.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,32 +14,36 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * - * @(#) src/sys/coda/coda_subr.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ + * + * @(#) src/sys/coda/coda_subr.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * */ -struct cnode *coda_alloc(void); -void coda_free(struct cnode *cp); -struct cnode *coda_find(CodaFid *fid); -void coda_flush(enum dc_status dcstat); -void coda_testflush(void); -void coda_checkunmounting(struct mount *mp); -void coda_cacheprint(struct mount *whoIam); -void coda_debugon(void); -void coda_debugoff(void); -int coda_kill(struct mount *whoIam, enum dc_status dcstat); -void coda_save(struct cnode *cp); -void coda_unsave(struct cnode *cp); +#ifndef _CODA_SUBR_H_ +#define _CODA_SUBR_H_ + +struct cnode *coda_alloc(void); +void coda_free(struct cnode *cp); +struct cnode *coda_find(CodaFid *fid); +void coda_flush(enum dc_status dcstat); +void coda_testflush(void); +void coda_checkunmounting(struct mount *mp); +void coda_cacheprint(struct mount *whoIam); +void coda_debugon(void); +void coda_debugoff(void); +int coda_kill(struct mount *whoIam, enum dc_status dcstat); +void coda_save(struct cnode *cp); +void coda_unsave(struct cnode *cp); + +#endif /* !_CODA_SUBR_H_ */ diff --git a/sys/fs/coda/coda_venus.c b/sys/fs/coda/coda_venus.c index 03df54e..c69741b 100644 --- a/sys/fs/coda/coda_venus.c +++ b/sys/fs/coda/coda_venus.c @@ -1,10 +1,10 @@ /*- * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -13,18 +13,18 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/cfs/coda_venus.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ */ @@ -46,198 +46,195 @@ __FBSDID("$FreeBSD$"); #include #include -#define DECL_NO_IN(name) \ - struct coda_in_hdr *inp; \ - struct name ## _out *outp; \ - int name ## _size = sizeof (struct coda_in_hdr); \ - int Isize = sizeof (struct coda_in_hdr); \ - int Osize = sizeof (struct name ## _out); \ - int error - -#define DECL(name) \ - struct name ## _in *inp; \ - struct name ## _out *outp; \ - int name ## _size = sizeof (struct name ## _in); \ - int Isize = sizeof (struct name ## _in); \ - int Osize = sizeof (struct name ## _out); \ - int error - -#define DECL_NO_OUT(name) \ - struct name ## _in *inp; \ - struct coda_out_hdr *outp; \ - int name ## _size = sizeof (struct name ## _in); \ - int Isize = sizeof (struct name ## _in); \ - int Osize = sizeof (struct coda_out_hdr); \ - int error - -#define ALLOC_NO_IN(name) \ - if (Osize > name ## _size) \ - name ## _size = Osize; \ - CODA_ALLOC(inp, struct coda_in_hdr *, name ## _size);\ - outp = (struct name ## _out *) inp - -#define ALLOC(name) \ - if (Osize > name ## _size) \ - name ## _size = Osize; \ - CODA_ALLOC(inp, struct name ## _in *, name ## _size);\ - outp = (struct name ## _out *) inp - -#define ALLOC_NO_OUT(name) \ - if (Osize > name ## _size) \ - name ## _size = Osize; \ - CODA_ALLOC(inp, struct name ## _in *, name ## _size);\ - outp = (struct coda_out_hdr *) inp - -#define STRCPY(struc, name, len) \ - bcopy(name, (char *)inp + (int)inp->struc, len); \ - ((char*)inp + (int)inp->struc)[len++] = 0; \ - Isize += len +#define DECL_NO_IN(name) \ + struct coda_in_hdr *inp; \ + struct name ## _out *outp; \ + int name ## _size = sizeof (struct coda_in_hdr); \ + int Isize = sizeof (struct coda_in_hdr); \ + int Osize = sizeof (struct name ## _out); \ + int error + +#define DECL(name) \ + struct name ## _in *inp; \ + struct name ## _out *outp; \ + int name ## _size = sizeof (struct name ## _in); \ + int Isize = sizeof (struct name ## _in); \ + int Osize = sizeof (struct name ## _out); \ + int error + +#define DECL_NO_OUT(name) \ + struct name ## _in *inp; \ + struct coda_out_hdr *outp; \ + int name ## _size = sizeof (struct name ## _in); \ + int Isize = sizeof (struct name ## _in); \ + int Osize = sizeof (struct coda_out_hdr); \ + int error + +#define ALLOC_NO_IN(name) \ + if (Osize > name ## _size) \ + name ## _size = Osize; \ + CODA_ALLOC(inp, struct coda_in_hdr *, name ## _size); \ + outp = (struct name ## _out *) inp + +#define ALLOC(name) \ + if (Osize > name ## _size) \ + name ## _size = Osize; \ + CODA_ALLOC(inp, struct name ## _in *, name ## _size); \ + outp = (struct name ## _out *) inp + +#define ALLOC_NO_OUT(name) \ + if (Osize > name ## _size) \ + name ## _size = Osize; \ + CODA_ALLOC(inp, struct name ## _in *, name ## _size); \ + outp = (struct coda_out_hdr *) inp + +#define STRCPY(struc, name, len) \ + bcopy(name, (char *)inp + (int)inp->struc, len); \ + ((char*)inp + (int)inp->struc)[len++] = 0; \ + Isize += len #ifdef CODA_COMPAT_5 -#define INIT_IN(in, op, ident, p) \ - (in)->opcode = (op); \ - sx_slock(&proctree_lock); \ - (in)->pid = p ? p->p_pid : -1; \ - (in)->pgid = p ? p->p_pgid : -1; \ - (in)->sid = (p && p->p_session && p->p_session->s_leader) ? (p->p_session->s_leader->p_pid) : -1; \ - sx_sunlock(&proctree_lock); \ - if (ident != NOCRED) { \ - (in)->cred.cr_uid = ident->cr_uid; \ - (in)->cred.cr_groupid = ident->cr_gid; \ - } else { \ - bzero(&((in)->cred),sizeof(struct coda_cred)); \ - (in)->cred.cr_uid = -1; \ - (in)->cred.cr_groupid = -1; \ - } +#define INIT_IN(in, op, ident, p) do { \ + (in)->opcode = (op); \ + sx_slock(&proctree_lock); \ + (in)->pid = p ? p->p_pid : -1; \ + (in)->pgid = p ? p->p_pgid : -1; \ + (in)->sid = (p && p->p_session && p->p_session->s_leader) ? \ + (p->p_session->s_leader->p_pid) : -1; \ + sx_sunlock(&proctree_lock); \ + if (ident != NOCRED) { \ + (in)->cred.cr_uid = ident->cr_uid; \ + (in)->cred.cr_groupid = ident->cr_gid; \ + } else { \ + bzero(&((in)->cred),sizeof(struct coda_cred)); \ + (in)->cred.cr_uid = -1; \ + (in)->cred.cr_groupid = -1; \ + } \ +} while (0) #else -#define INIT_IN(in, op, ident, p) \ - (in)->opcode = (op); \ - (in)->pid = p ? p->p_pid : -1; \ - (in)->pgid = p ? p->p_pgid : -1; \ - if (ident != NOCRED) { \ - (in)->uid = ident->cr_uid; \ - } else { \ - (in)->uid = -1; \ - } +#define INIT_IN(in, op, ident, p) do { \ + (in)->opcode = (op); \ + (in)->pid = p ? p->p_pid : -1; \ + (in)->pgid = p ? p->p_pgid : -1; \ + if (ident != NOCRED) \ + (in)->uid = ident->cr_uid; \ + else \ + (in)->uid = -1; \ +} while (0) #endif -#define CNV_OFLAG(to, from) \ - do { \ - to = 0; \ - if (from & FREAD) to |= C_O_READ; \ - if (from & FWRITE) to |= C_O_WRITE; \ - if (from & O_TRUNC) to |= C_O_TRUNC; \ - if (from & O_EXCL) to |= C_O_EXCL; \ - if (from & O_CREAT) to |= C_O_CREAT; \ - } while (0) - -#define CNV_VV2V_ATTR(top, fromp) \ - do { \ - (top)->va_type = (fromp)->va_type; \ - (top)->va_mode = (fromp)->va_mode; \ - (top)->va_nlink = (fromp)->va_nlink; \ - (top)->va_uid = (fromp)->va_uid; \ - (top)->va_gid = (fromp)->va_gid; \ - (top)->va_fsid = VNOVAL; \ - (top)->va_fileid = (fromp)->va_fileid; \ - (top)->va_size = (fromp)->va_size; \ - (top)->va_blocksize = (fromp)->va_blocksize; \ - (top)->va_atime = (fromp)->va_atime; \ - (top)->va_mtime = (fromp)->va_mtime; \ - (top)->va_ctime = (fromp)->va_ctime; \ - (top)->va_gen = (fromp)->va_gen; \ - (top)->va_flags = (fromp)->va_flags; \ - (top)->va_rdev = (fromp)->va_rdev; \ - (top)->va_bytes = (fromp)->va_bytes; \ - (top)->va_filerev = (fromp)->va_filerev; \ - (top)->va_vaflags = VNOVAL; \ - (top)->va_spare = VNOVAL; \ - } while (0) - -#define CNV_V2VV_ATTR(top, fromp) \ - do { \ - (top)->va_type = (fromp)->va_type; \ - (top)->va_mode = (fromp)->va_mode; \ - (top)->va_nlink = (fromp)->va_nlink; \ - (top)->va_uid = (fromp)->va_uid; \ - (top)->va_gid = (fromp)->va_gid; \ - (top)->va_fileid = (fromp)->va_fileid; \ - (top)->va_size = (fromp)->va_size; \ - (top)->va_blocksize = (fromp)->va_blocksize; \ - (top)->va_atime = (fromp)->va_atime; \ - (top)->va_mtime = (fromp)->va_mtime; \ - (top)->va_ctime = (fromp)->va_ctime; \ - (top)->va_gen = (fromp)->va_gen; \ - (top)->va_flags = (fromp)->va_flags; \ - (top)->va_rdev = (fromp)->va_rdev; \ - (top)->va_bytes = (fromp)->va_bytes; \ - (top)->va_filerev = (fromp)->va_filerev; \ - } while (0) +#define CNV_OFLAG(to, from) do { \ + to = 0; \ + if (from & FREAD) to |= C_O_READ; \ + if (from & FWRITE) to |= C_O_WRITE; \ + if (from & O_TRUNC) to |= C_O_TRUNC; \ + if (from & O_EXCL) to |= C_O_EXCL; \ + if (from & O_CREAT) to |= C_O_CREAT; \ +} while (0) + +#define CNV_VV2V_ATTR(top, fromp) do { \ + (top)->va_type = (fromp)->va_type; \ + (top)->va_mode = (fromp)->va_mode; \ + (top)->va_nlink = (fromp)->va_nlink; \ + (top)->va_uid = (fromp)->va_uid; \ + (top)->va_gid = (fromp)->va_gid; \ + (top)->va_fsid = VNOVAL; \ + (top)->va_fileid = (fromp)->va_fileid; \ + (top)->va_size = (fromp)->va_size; \ + (top)->va_blocksize = (fromp)->va_blocksize; \ + (top)->va_atime = (fromp)->va_atime; \ + (top)->va_mtime = (fromp)->va_mtime; \ + (top)->va_ctime = (fromp)->va_ctime; \ + (top)->va_gen = (fromp)->va_gen; \ + (top)->va_flags = (fromp)->va_flags; \ + (top)->va_rdev = (fromp)->va_rdev; \ + (top)->va_bytes = (fromp)->va_bytes; \ + (top)->va_filerev = (fromp)->va_filerev; \ + (top)->va_vaflags = VNOVAL; \ + (top)->va_spare = VNOVAL; \ +} while (0) + +#define CNV_V2VV_ATTR(top, fromp) do { \ + (top)->va_type = (fromp)->va_type; \ + (top)->va_mode = (fromp)->va_mode; \ + (top)->va_nlink = (fromp)->va_nlink; \ + (top)->va_uid = (fromp)->va_uid; \ + (top)->va_gid = (fromp)->va_gid; \ + (top)->va_fileid = (fromp)->va_fileid; \ + (top)->va_size = (fromp)->va_size; \ + (top)->va_blocksize = (fromp)->va_blocksize; \ + (top)->va_atime = (fromp)->va_atime; \ + (top)->va_mtime = (fromp)->va_mtime; \ + (top)->va_ctime = (fromp)->va_ctime; \ + (top)->va_gen = (fromp)->va_gen; \ + (top)->va_flags = (fromp)->va_flags; \ + (top)->va_rdev = (fromp)->va_rdev; \ + (top)->va_bytes = (fromp)->va_bytes; \ + (top)->va_filerev = (fromp)->va_filerev; \ +} while (0) int coda_kernel_version = CODA_KERNEL_VERSION; int -venus_root(void *mdp, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid) +venus_root(void *mdp, struct ucred *cred, struct proc *p, + /*out*/ CodaFid *VFid) { - DECL_NO_IN(coda_root); /* sets Isize & Osize */ - ALLOC_NO_IN(coda_root); /* sets inp & outp */ + DECL_NO_IN(coda_root); /* sets Isize & Osize */ + ALLOC_NO_IN(coda_root); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(inp, CODA_ROOT, cred, p); + /* send the open to venus. */ + INIT_IN(inp, CODA_ROOT, cred, p); - error = coda_call(mdp, Isize, &Osize, (char *)inp); - if (!error) - *VFid = outp->Fid; + error = coda_call(mdp, Isize, &Osize, (char *)inp); + if (!error) + *VFid = outp->Fid; - CODA_FREE(inp, coda_root_size); - return error; + CODA_FREE(inp, coda_root_size); + return (error); } int -venus_open(void *mdp, CodaFid *fid, int flag, - struct ucred *cred, struct proc *p, -/*out*/ struct vnode **vp) +venus_open(void *mdp, CodaFid *fid, int flag, struct ucred *cred, + struct proc *p, /*out*/ struct vnode **vp) { - int cflag; - DECL(coda_open_by_fd); /* sets Isize & Osize */ - ALLOC(coda_open_by_fd); /* sets inp & outp */ + int cflag; + DECL(coda_open_by_fd); /* sets Isize & Osize */ + ALLOC(coda_open_by_fd); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_OPEN_BY_FD, cred, p); - inp->Fid = *fid; - CNV_OFLAG(cflag, flag); - inp->flags = cflag; + /* send the open to venus. */ + INIT_IN(&inp->ih, CODA_OPEN_BY_FD, cred, p); + inp->Fid = *fid; + CNV_OFLAG(cflag, flag); + inp->flags = cflag; - error = coda_call(mdp, Isize, &Osize, (char *)inp); - *vp = error ? NULL : outp->vp; + error = coda_call(mdp, Isize, &Osize, (char *)inp); + *vp = error ? NULL : outp->vp; - CODA_FREE(inp, coda_open_by_fd_size); - return error; + CODA_FREE(inp, coda_open_by_fd_size); + return (error); } int -venus_close(void *mdp, CodaFid *fid, int flag, - struct ucred *cred, struct proc *p) +venus_close(void *mdp, CodaFid *fid, int flag, struct ucred *cred, + struct proc *p) { - int cflag; - DECL_NO_OUT(coda_close); /* sets Isize & Osize */ - ALLOC_NO_OUT(coda_close); /* sets inp & outp */ + int cflag; + DECL_NO_OUT(coda_close); /* sets Isize & Osize */ + ALLOC_NO_OUT(coda_close); /* sets inp & outp */ - INIT_IN(&inp->ih, CODA_CLOSE, cred, p); - inp->Fid = *fid; - CNV_OFLAG(cflag, flag); - inp->flags = cflag; + INIT_IN(&inp->ih, CODA_CLOSE, cred, p); + inp->Fid = *fid; + CNV_OFLAG(cflag, flag); + inp->flags = cflag; - error = coda_call(mdp, Isize, &Osize, (char *)inp); + error = coda_call(mdp, Isize, &Osize, (char *)inp); - CODA_FREE(inp, coda_close_size); - return error; + CODA_FREE(inp, coda_close_size); + return (error); } /* - * these two calls will not exist!!! the container file is read/written + * These two calls will not exist!!! The container file is read/written * directly. */ void @@ -251,424 +248,444 @@ venus_write(void) } /* - * this is a bit sad too. the ioctl's are for the control file, not for + * This is a bit sad too. the ioctl's are for the control file, not for * normal files. */ int -venus_ioctl(void *mdp, CodaFid *fid, - int com, int flag, caddr_t data, - struct ucred *cred, struct proc *p) +venus_ioctl(void *mdp, CodaFid *fid, int com, int flag, caddr_t data, + struct ucred *cred, struct proc *p) { - DECL(coda_ioctl); /* sets Isize & Osize */ - struct PioctlData *iap = (struct PioctlData *)data; - int tmp; - - coda_ioctl_size = VC_MAXMSGSIZE; - ALLOC(coda_ioctl); /* sets inp & outp */ - - INIT_IN(&inp->ih, CODA_IOCTL, cred, p); - inp->Fid = *fid; - - /* command was mutated by increasing its size field to reflect the - * path and follow args. we need to subtract that out before sending - * the command to venus. - */ - inp->cmd = (com & ~(IOCPARM_MASK << 16)); - tmp = ((com >> 16) & IOCPARM_MASK) - sizeof (char *) - sizeof (int); - inp->cmd |= (tmp & IOCPARM_MASK) << 16; - - inp->rwflag = flag; - inp->len = iap->vi.in_size; - inp->data = (char *)(sizeof (struct coda_ioctl_in)); - - error = copyin(iap->vi.in, (char*)inp + (long)inp->data, - iap->vi.in_size); - if (error) { - CODA_FREE(inp, coda_ioctl_size); - return(error); - } - - Osize = VC_MAXMSGSIZE; - error = coda_call(mdp, Isize + iap->vi.in_size, &Osize, (char *)inp); - - /* copy out the out buffer. */ - if (!error) { - if (outp->len > iap->vi.out_size) { - error = EINVAL; - } else { - error = copyout((char *)outp + (long)outp->data, + DECL(coda_ioctl); /* sets Isize & Osize */ + struct PioctlData *iap = (struct PioctlData *)data; + int tmp; + + coda_ioctl_size = VC_MAXMSGSIZE; + ALLOC(coda_ioctl); /* sets inp & outp */ + + INIT_IN(&inp->ih, CODA_IOCTL, cred, p); + inp->Fid = *fid; + + /* + * Command was mutated by increasing its size field to reflect the + * path and follow args. we need to subtract that out before sending + * the command to venus. + */ + inp->cmd = (com & ~(IOCPARM_MASK << 16)); + tmp = ((com >> 16) & IOCPARM_MASK) - sizeof (char *) - sizeof (int); + inp->cmd |= (tmp & IOCPARM_MASK) << 16; + + inp->rwflag = flag; + inp->len = iap->vi.in_size; + inp->data = (char *)(sizeof (struct coda_ioctl_in)); + + error = copyin(iap->vi.in, (char*)inp + (long)inp->data, + iap->vi.in_size); + if (error) { + CODA_FREE(inp, coda_ioctl_size); + return (error); + } + + Osize = VC_MAXMSGSIZE; + error = coda_call(mdp, Isize + iap->vi.in_size, &Osize, (char *)inp); + + /* + * Copy out the out buffer. + */ + if (!error) { + if (outp->len > iap->vi.out_size) + error = EINVAL; + else + error = copyout((char *)outp + (long)outp->data, iap->vi.out, iap->vi.out_size); } - } - CODA_FREE(inp, coda_ioctl_size); - return error; + CODA_FREE(inp, coda_ioctl_size); + return (error); } int -venus_getattr(void *mdp, CodaFid *fid, - struct ucred *cred, struct proc *p, -/*out*/ struct vattr *vap) +venus_getattr(void *mdp, CodaFid *fid, struct ucred *cred, struct proc *p, + /*out*/ struct vattr *vap) { - DECL(coda_getattr); /* sets Isize & Osize */ - ALLOC(coda_getattr); /* sets inp & outp */ + DECL(coda_getattr); /* sets Isize & Osize */ + ALLOC(coda_getattr); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_GETATTR, cred, p); - inp->Fid = *fid; + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_GETATTR, cred, p); + inp->Fid = *fid; - error = coda_call(mdp, Isize, &Osize, (char *)inp); - if (!error) { - CNV_VV2V_ATTR(vap, &outp->attr); - } + error = coda_call(mdp, Isize, &Osize, (char *)inp); + if (!error) + CNV_VV2V_ATTR(vap, &outp->attr); - CODA_FREE(inp, coda_getattr_size); - return error; + CODA_FREE(inp, coda_getattr_size); + return (error); } int -venus_setattr(void *mdp, CodaFid *fid, struct vattr *vap, - struct ucred *cred, struct proc *p) +venus_setattr(void *mdp, CodaFid *fid, struct vattr *vap, struct ucred *cred, + struct proc *p) { - DECL_NO_OUT(coda_setattr); /* sets Isize & Osize */ - ALLOC_NO_OUT(coda_setattr); /* sets inp & outp */ + DECL_NO_OUT(coda_setattr); /* sets Isize & Osize */ + ALLOC_NO_OUT(coda_setattr); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_SETATTR, cred, p); - inp->Fid = *fid; - CNV_V2VV_ATTR(&inp->attr, vap); + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_SETATTR, cred, p); + inp->Fid = *fid; + CNV_V2VV_ATTR(&inp->attr, vap); - error = coda_call(mdp, Isize, &Osize, (char *)inp); + error = coda_call(mdp, Isize, &Osize, (char *)inp); - CODA_FREE(inp, coda_setattr_size); - return error; + CODA_FREE(inp, coda_setattr_size); + return (error); } int -venus_access(void *mdp, CodaFid *fid, int mode, - struct ucred *cred, struct proc *p) +venus_access(void *mdp, CodaFid *fid, int mode, struct ucred *cred, + struct proc *p) { - DECL_NO_OUT(coda_access); /* sets Isize & Osize */ - ALLOC_NO_OUT(coda_access); /* sets inp & outp */ - - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_ACCESS, cred, p); - inp->Fid = *fid; - /* NOTE: - * FreeBSD and Venus internals use the "data" in the low 3 bits. - * Hence, the conversion. - */ - inp->flags = mode>>6; - - error = coda_call(mdp, Isize, &Osize, (char *)inp); - - CODA_FREE(inp, coda_access_size); - return error; + DECL_NO_OUT(coda_access); /* sets Isize & Osize */ + ALLOC_NO_OUT(coda_access); /* sets inp & outp */ + + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_ACCESS, cred, p); + inp->Fid = *fid; + + /* + * NOTE: FreeBSD and Venus internals use the "data" in the low 3 + * bits. Hence, the conversion. + */ + inp->flags = mode>>6; + + error = coda_call(mdp, Isize, &Osize, (char *)inp); + + CODA_FREE(inp, coda_access_size); + return (error); } int -venus_readlink(void *mdp, CodaFid *fid, - struct ucred *cred, struct proc *p, -/*out*/ char **str, int *len) +venus_readlink(void *mdp, CodaFid *fid, struct ucred *cred, struct proc *p, + /*out*/ char **str, int *len) { - DECL(coda_readlink); /* sets Isize & Osize */ - coda_readlink_size += CODA_MAXPATHLEN; - ALLOC(coda_readlink); /* sets inp & outp */ - - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_READLINK, cred, p); - inp->Fid = *fid; - - Osize += CODA_MAXPATHLEN; - error = coda_call(mdp, Isize, &Osize, (char *)inp); - if (!error) { - CODA_ALLOC(*str, char *, outp->count); - *len = outp->count; - bcopy((char *)outp + (long)outp->data, *str, *len); - } - - CODA_FREE(inp, coda_readlink_size); - return error; + DECL(coda_readlink); /* sets Isize & Osize */ + coda_readlink_size += CODA_MAXPATHLEN; + ALLOC(coda_readlink); /* sets inp & outp */ + + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_READLINK, cred, p); + inp->Fid = *fid; + + Osize += CODA_MAXPATHLEN; + error = coda_call(mdp, Isize, &Osize, (char *)inp); + if (!error) { + CODA_ALLOC(*str, char *, outp->count); + *len = outp->count; + bcopy((char *)outp + (long)outp->data, *str, *len); + } + + CODA_FREE(inp, coda_readlink_size); + return (error); } int venus_fsync(void *mdp, CodaFid *fid, struct proc *p) { - DECL_NO_OUT(coda_fsync); /* sets Isize & Osize */ - ALLOC_NO_OUT(coda_fsync); /* sets inp & outp */ + DECL_NO_OUT(coda_fsync); /* sets Isize & Osize */ + ALLOC_NO_OUT(coda_fsync); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_FSYNC, NOCRED, p); /* XXX: should be cached mount cred */ - inp->Fid = *fid; + /* + * Send the open to venus. + * + * XXX: should be cached mount cred. + */ + INIT_IN(&inp->ih, CODA_FSYNC, NOCRED, p); + inp->Fid = *fid; - error = coda_call(mdp, Isize, &Osize, (char *)inp); + error = coda_call(mdp, Isize, &Osize, (char *)inp); - CODA_FREE(inp, coda_fsync_size); - return error; + CODA_FREE(inp, coda_fsync_size); + return (error); } int -venus_lookup(void *mdp, CodaFid *fid, - const char *nm, int len, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid, int *vtype) +venus_lookup(void *mdp, CodaFid *fid, const char *nm, int len, + struct ucred *cred, struct proc *p, /*out*/ CodaFid *VFid, int *vtype) { - DECL(coda_lookup); /* sets Isize & Osize */ - coda_lookup_size += len + 1; - ALLOC(coda_lookup); /* sets inp & outp */ - - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_LOOKUP, cred, p); - inp->Fid = *fid; - - /* NOTE: - * Between version 1 and version 2 we have added an extra flag field - * to this structure. But because the string was at the end and because - * of the wierd way we represent strings by having the slot point to - * where the string characters are in the "heap", we can just slip the - * flag parameter in after the string slot pointer and veni that don't - * know better won't see this new flag field ... - * Otherwise we'd need two different venus_lookup functions. - */ - inp->name = Isize; - inp->flags = CLU_CASE_SENSITIVE; /* doesn't really matter for BSD */ - STRCPY(name, nm, len); /* increments Isize */ - - error = coda_call(mdp, Isize, &Osize, (char *)inp); - if (!error) { - *VFid = outp->Fid; - *vtype = outp->vtype; - } - - CODA_FREE(inp, coda_lookup_size); - return error; + DECL(coda_lookup); /* sets Isize & Osize */ + coda_lookup_size += len + 1; + ALLOC(coda_lookup); /* sets inp & outp */ + + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_LOOKUP, cred, p); + inp->Fid = *fid; + + /* + * NOTE: Between version 1 and version 2 we have added an extra flag + * field to this structure. But because the string was at the end + * and because of the wierd way we represent strings by having the + * slot point to where the string characters are in the "heap", we + * can just slip the flag parameter in after the string slot pointer + * and veni that don't know better won't see this new flag field ... + * Otherwise we'd need two different venus_lookup functions. + */ + inp->name = Isize; + inp->flags = CLU_CASE_SENSITIVE; /* doesn't really matter for BSD */ + STRCPY(name, nm, len); /* increments Isize */ + + error = coda_call(mdp, Isize, &Osize, (char *)inp); + if (!error) { + *VFid = outp->Fid; + *vtype = outp->vtype; + } + + CODA_FREE(inp, coda_lookup_size); + return (error); } int -venus_create(void *mdp, CodaFid *fid, - const char *nm, int len, int exclusive, int mode, struct vattr *va, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid, struct vattr *attr) +venus_create(void *mdp, CodaFid *fid, const char *nm, int len, int exclusive, + int mode, struct vattr *va, struct ucred *cred, struct proc *p, + /*out*/ CodaFid *VFid, struct vattr *attr) { - DECL(coda_create); /* sets Isize & Osize */ - coda_create_size += len + 1; - ALLOC(coda_create); /* sets inp & outp */ - - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_CREATE, cred, p); - inp->Fid = *fid; - inp->excl = exclusive ? C_O_EXCL : 0; - inp->mode = mode; - CNV_V2VV_ATTR(&inp->attr, va); - - inp->name = Isize; - STRCPY(name, nm, len); /* increments Isize */ - - error = coda_call(mdp, Isize, &Osize, (char *)inp); - if (!error) { - *VFid = outp->Fid; - CNV_VV2V_ATTR(attr, &outp->attr); - } - - CODA_FREE(inp, coda_create_size); - return error; + DECL(coda_create); /* sets Isize & Osize */ + coda_create_size += len + 1; + ALLOC(coda_create); /* sets inp & outp */ + + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_CREATE, cred, p); + inp->Fid = *fid; + inp->excl = exclusive ? C_O_EXCL : 0; + inp->mode = mode; + CNV_V2VV_ATTR(&inp->attr, va); + + inp->name = Isize; + STRCPY(name, nm, len); /* increments Isize */ + + error = coda_call(mdp, Isize, &Osize, (char *)inp); + if (!error) { + *VFid = outp->Fid; + CNV_VV2V_ATTR(attr, &outp->attr); + } + + CODA_FREE(inp, coda_create_size); + return (error); } int -venus_remove(void *mdp, CodaFid *fid, - const char *nm, int len, - struct ucred *cred, struct proc *p) +venus_remove(void *mdp, CodaFid *fid, const char *nm, int len, + struct ucred *cred, struct proc *p) { - DECL_NO_OUT(coda_remove); /* sets Isize & Osize */ - coda_remove_size += len + 1; - ALLOC_NO_OUT(coda_remove); /* sets inp & outp */ + DECL_NO_OUT(coda_remove); /* sets Isize & Osize */ + coda_remove_size += len + 1; + ALLOC_NO_OUT(coda_remove); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_REMOVE, cred, p); - inp->Fid = *fid; + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_REMOVE, cred, p); + inp->Fid = *fid; - inp->name = Isize; - STRCPY(name, nm, len); /* increments Isize */ + inp->name = Isize; + STRCPY(name, nm, len); /* increments Isize */ - error = coda_call(mdp, Isize, &Osize, (char *)inp); + error = coda_call(mdp, Isize, &Osize, (char *)inp); - CODA_FREE(inp, coda_remove_size); - return error; + CODA_FREE(inp, coda_remove_size); + return (error); } int -venus_link(void *mdp, CodaFid *fid, CodaFid *tfid, - const char *nm, int len, - struct ucred *cred, struct proc *p) +venus_link(void *mdp, CodaFid *fid, CodaFid *tfid, const char *nm, int len, + struct ucred *cred, struct proc *p) { - DECL_NO_OUT(coda_link); /* sets Isize & Osize */ - coda_link_size += len + 1; - ALLOC_NO_OUT(coda_link); /* sets inp & outp */ + DECL_NO_OUT(coda_link); /* sets Isize & Osize */ + coda_link_size += len + 1; + ALLOC_NO_OUT(coda_link); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_LINK, cred, p); - inp->sourceFid = *fid; - inp->destFid = *tfid; + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_LINK, cred, p); + inp->sourceFid = *fid; + inp->destFid = *tfid; - inp->tname = Isize; - STRCPY(tname, nm, len); /* increments Isize */ + inp->tname = Isize; + STRCPY(tname, nm, len); /* increments Isize */ - error = coda_call(mdp, Isize, &Osize, (char *)inp); + error = coda_call(mdp, Isize, &Osize, (char *)inp); - CODA_FREE(inp, coda_link_size); - return error; + CODA_FREE(inp, coda_link_size); + return (error); } int -venus_rename(void *mdp, CodaFid *fid, CodaFid *tfid, - const char *nm, int len, const char *tnm, int tlen, - struct ucred *cred, struct proc *p) +venus_rename(void *mdp, CodaFid *fid, CodaFid *tfid, const char *nm, int len, + const char *tnm, int tlen, struct ucred *cred, struct proc *p) { - DECL_NO_OUT(coda_rename); /* sets Isize & Osize */ - coda_rename_size += len + 1 + tlen + 1; - ALLOC_NO_OUT(coda_rename); /* sets inp & outp */ + DECL_NO_OUT(coda_rename); /* sets Isize & Osize */ + coda_rename_size += len + 1 + tlen + 1; + ALLOC_NO_OUT(coda_rename); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_RENAME, cred, p); - inp->sourceFid = *fid; - inp->destFid = *tfid; + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_RENAME, cred, p); + inp->sourceFid = *fid; + inp->destFid = *tfid; - inp->srcname = Isize; - STRCPY(srcname, nm, len); /* increments Isize */ + inp->srcname = Isize; + STRCPY(srcname, nm, len); /* increments Isize */ - inp->destname = Isize; - STRCPY(destname, tnm, tlen); /* increments Isize */ + inp->destname = Isize; + STRCPY(destname, tnm, tlen); /* increments Isize */ - error = coda_call(mdp, Isize, &Osize, (char *)inp); + error = coda_call(mdp, Isize, &Osize, (char *)inp); - CODA_FREE(inp, coda_rename_size); - return error; + CODA_FREE(inp, coda_rename_size); + return (error); } int -venus_mkdir(void *mdp, CodaFid *fid, - const char *nm, int len, struct vattr *va, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid, struct vattr *ova) +venus_mkdir(void *mdp, CodaFid *fid, const char *nm, int len, + struct vattr *va, struct ucred *cred, struct proc *p, + /*out*/ CodaFid *VFid, struct vattr *ova) { - DECL(coda_mkdir); /* sets Isize & Osize */ - coda_mkdir_size += len + 1; - ALLOC(coda_mkdir); /* sets inp & outp */ - - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_MKDIR, cred, p); - inp->Fid = *fid; - CNV_V2VV_ATTR(&inp->attr, va); - - inp->name = Isize; - STRCPY(name, nm, len); /* increments Isize */ - - error = coda_call(mdp, Isize, &Osize, (char *)inp); - if (!error) { - *VFid = outp->Fid; - CNV_VV2V_ATTR(ova, &outp->attr); - } - - CODA_FREE(inp, coda_mkdir_size); - return error; + DECL(coda_mkdir); /* sets Isize & Osize */ + coda_mkdir_size += len + 1; + ALLOC(coda_mkdir); /* sets inp & outp */ + + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_MKDIR, cred, p); + inp->Fid = *fid; + CNV_V2VV_ATTR(&inp->attr, va); + + inp->name = Isize; + STRCPY(name, nm, len); /* increments Isize */ + + error = coda_call(mdp, Isize, &Osize, (char *)inp); + if (!error) { + *VFid = outp->Fid; + CNV_VV2V_ATTR(ova, &outp->attr); + } + + CODA_FREE(inp, coda_mkdir_size); + return (error); } int -venus_rmdir(void *mdp, CodaFid *fid, - const char *nm, int len, - struct ucred *cred, struct proc *p) +venus_rmdir(void *mdp, CodaFid *fid, const char *nm, int len, + struct ucred *cred, struct proc *p) { - DECL_NO_OUT(coda_rmdir); /* sets Isize & Osize */ - coda_rmdir_size += len + 1; - ALLOC_NO_OUT(coda_rmdir); /* sets inp & outp */ + DECL_NO_OUT(coda_rmdir); /* sets Isize & Osize */ + coda_rmdir_size += len + 1; + ALLOC_NO_OUT(coda_rmdir); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_RMDIR, cred, p); - inp->Fid = *fid; + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_RMDIR, cred, p); + inp->Fid = *fid; - inp->name = Isize; - STRCPY(name, nm, len); /* increments Isize */ + inp->name = Isize; + STRCPY(name, nm, len); /* increments Isize */ - error = coda_call(mdp, Isize, &Osize, (char *)inp); + error = coda_call(mdp, Isize, &Osize, (char *)inp); - CODA_FREE(inp, coda_rmdir_size); - return error; + CODA_FREE(inp, coda_rmdir_size); + return (error); } int -venus_symlink(void *mdp, CodaFid *fid, - const char *lnm, int llen, const char *nm, int len, struct vattr *va, - struct ucred *cred, struct proc *p) +venus_symlink(void *mdp, CodaFid *fid, const char *lnm, int llen, + const char *nm, int len, struct vattr *va, struct ucred *cred, + struct proc *p) { - DECL_NO_OUT(coda_symlink); /* sets Isize & Osize */ - coda_symlink_size += llen + 1 + len + 1; - ALLOC_NO_OUT(coda_symlink); /* sets inp & outp */ + DECL_NO_OUT(coda_symlink); /* sets Isize & Osize */ + coda_symlink_size += llen + 1 + len + 1; + ALLOC_NO_OUT(coda_symlink); /* sets inp & outp */ - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_SYMLINK, cred, p); - inp->Fid = *fid; - CNV_V2VV_ATTR(&inp->attr, va); + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_SYMLINK, cred, p); + inp->Fid = *fid; + CNV_V2VV_ATTR(&inp->attr, va); - inp->srcname = Isize; - STRCPY(srcname, lnm, llen); /* increments Isize */ + inp->srcname = Isize; + STRCPY(srcname, lnm, llen); /* increments Isize */ - inp->tname = Isize; - STRCPY(tname, nm, len); /* increments Isize */ + inp->tname = Isize; + STRCPY(tname, nm, len); /* increments Isize */ - error = coda_call(mdp, Isize, &Osize, (char *)inp); + error = coda_call(mdp, Isize, &Osize, (char *)inp); - CODA_FREE(inp, coda_symlink_size); - return error; + CODA_FREE(inp, coda_symlink_size); + return (error); } /* * XXX: Unused. */ int -venus_readdir(void *mdp, CodaFid *fid, - int count, int offset, - struct ucred *cred, struct proc *p, -/*out*/ char *buffer, int *len) +venus_readdir(void *mdp, CodaFid *fid, int count, int offset, + struct ucred *cred, struct proc *p, /*out*/ char *buffer, int *len) { - DECL(coda_readdir); /* sets Isize & Osize */ - coda_readdir_size = VC_MAXMSGSIZE; - ALLOC(coda_readdir); /* sets inp & outp */ - - /* send the open to venus. */ - INIT_IN(&inp->ih, CODA_READDIR, cred, p); - inp->Fid = *fid; - inp->count = count; - inp->offset = offset; - - Osize = VC_MAXMSGSIZE; - error = coda_call(mdp, Isize, &Osize, (char *)inp); - if (!error) { - bcopy((char *)outp + (long)outp->data, buffer, outp->size); - *len = outp->size; - } - - CODA_FREE(inp, coda_readdir_size); - return error; + DECL(coda_readdir); /* sets Isize & Osize */ + coda_readdir_size = VC_MAXMSGSIZE; + ALLOC(coda_readdir); /* sets inp & outp */ + + /* + * Send the open to venus. + */ + INIT_IN(&inp->ih, CODA_READDIR, cred, p); + inp->Fid = *fid; + inp->count = count; + inp->offset = offset; + + Osize = VC_MAXMSGSIZE; + error = coda_call(mdp, Isize, &Osize, (char *)inp); + if (!error) { + bcopy((char *)outp + (long)outp->data, buffer, outp->size); + *len = outp->size; + } + + CODA_FREE(inp, coda_readdir_size); + return (error); } int -venus_fhtovp(void *mdp, CodaFid *fid, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid, int *vtype) +venus_fhtovp(void *mdp, CodaFid *fid, struct ucred *cred, struct proc *p, + /*out*/ CodaFid *VFid, int *vtype) { - DECL(coda_vget); /* sets Isize & Osize */ - ALLOC(coda_vget); /* sets inp & outp */ - - /* Send the open to Venus. */ - INIT_IN(&inp->ih, CODA_VGET, cred, p); - inp->Fid = *fid; - - error = coda_call(mdp, Isize, &Osize, (char *)inp); - if (!error) { - *VFid = outp->Fid; - *vtype = outp->vtype; - } + DECL(coda_vget); /* sets Isize & Osize */ + ALLOC(coda_vget); /* sets inp & outp */ + + /* + * Send the open to Venus. + */ + INIT_IN(&inp->ih, CODA_VGET, cred, p); + inp->Fid = *fid; + + error = coda_call(mdp, Isize, &Osize, (char *)inp); + if (!error) { + *VFid = outp->Fid; + *vtype = outp->vtype; + } - CODA_FREE(inp, coda_vget_size); - return error; + CODA_FREE(inp, coda_vget_size); + return (error); } diff --git a/sys/fs/coda/coda_venus.h b/sys/fs/coda/coda_venus.h index d8f0198..97e7be3 100644 --- a/sys/fs/coda/coda_venus.h +++ b/sys/fs/coda/coda_venus.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,119 +14,69 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * - * @(#) src/sys/coda/coda_venus.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ + * + * @(#) src/sys/coda/coda_venus.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * */ -int -venus_root(void *mdp, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid); - -int -venus_open(void *mdp, CodaFid *fid, int flag, - struct ucred *cred, struct proc *p, -/*out*/ struct vnode **vp); - -int -venus_close(void *mdp, CodaFid *fid, int flag, - struct ucred *cred, struct proc *p); - -void -venus_read(void); - -void -venus_write(void); - -int -venus_ioctl(void *mdp, CodaFid *fid, - int com, int flag, caddr_t data, - struct ucred *cred, struct proc *p); - -int -venus_getattr(void *mdp, CodaFid *fid, - struct ucred *cred, struct proc *p, -/*out*/ struct vattr *vap); - -int -venus_setattr(void *mdp, CodaFid *fid, struct vattr *vap, - struct ucred *cred, struct proc *p); - -int -venus_access(void *mdp, CodaFid *fid, int mode, - struct ucred *cred, struct proc *p); - -int -venus_readlink(void *mdp, CodaFid *fid, - struct ucred *cred, struct proc *p, -/*out*/ char **str, int *len); - -int -venus_fsync(void *mdp, CodaFid *fid, struct proc *p); - -int -venus_lookup(void *mdp, CodaFid *fid, - const char *nm, int len, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid, int *vtype); - -int -venus_create(void *mdp, CodaFid *fid, - const char *nm, int len, int exclusive, int mode, struct vattr *va, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid, struct vattr *attr); - -int -venus_remove(void *mdp, CodaFid *fid, - const char *nm, int len, - struct ucred *cred, struct proc *p); - -int -venus_link(void *mdp, CodaFid *fid, CodaFid *tfid, - const char *nm, int len, - struct ucred *cred, struct proc *p); - -int -venus_rename(void *mdp, CodaFid *fid, CodaFid *tfid, - const char *nm, int len, const char *tnm, int tlen, - struct ucred *cred, struct proc *p); - -int -venus_mkdir(void *mdp, CodaFid *fid, - const char *nm, int len, struct vattr *va, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid, struct vattr *ova); - -int -venus_rmdir(void *mdp, CodaFid *fid, - const char *nm, int len, - struct ucred *cred, struct proc *p); - -int -venus_symlink(void *mdp, CodaFid *fid, - const char *lnm, int llen, const char *nm, int len, struct vattr *va, - struct ucred *cred, struct proc *p); - -int -venus_readdir(void *mdp, CodaFid *fid, - int count, int offset, - struct ucred *cred, struct proc *p, -/*out*/ char *buffer, int *len); - -int -venus_fhtovp(void *mdp, CodaFid *fid, - struct ucred *cred, struct proc *p, -/*out*/ CodaFid *VFid, int *vtype); +#ifndef _CODA_VENUS_H_ +#define _CODA_VENUS_H_ + +int venus_root(void *mdp, struct ucred *cred, struct proc *p, + /*out*/ CodaFid *VFid); +int venus_open(void *mdp, CodaFid *fid, int flag, struct ucred *cred, + struct proc *p, /*out*/ struct vnode **vp); +int venus_close(void *mdp, CodaFid *fid, int flag, struct ucred *cred, + struct proc *p); +void venus_read(void); +void venus_write(void); +int venus_ioctl(void *mdp, CodaFid *fid, int com, int flag, caddr_t data, + struct ucred *cred, struct proc *p); +int venus_getattr(void *mdp, CodaFid *fid, struct ucred *cred, + struct proc *p, /*out*/ struct vattr *vap); +int venus_setattr(void *mdp, CodaFid *fid, struct vattr *vap, + struct ucred *cred, struct proc *p); +int venus_access(void *mdp, CodaFid *fid, int mode, struct ucred *cred, + struct proc *p); +int venus_readlink(void *mdp, CodaFid *fid, struct ucred *cred, + struct proc *p, /*out*/ char **str, int *len); +int venus_fsync(void *mdp, CodaFid *fid, struct proc *p); +int venus_lookup(void *mdp, CodaFid *fid, const char *nm, int len, + struct ucred *cred, struct proc *p, /*out*/ CodaFid *VFid, + int *vtype); +int venus_create(void *mdp, CodaFid *fid, const char *nm, int len, + int exclusive, int mode, struct vattr *va, struct ucred *cred, + struct proc *p, /*out*/ CodaFid *VFid, struct vattr *attr); +int venus_remove(void *mdp, CodaFid *fid, const char *nm, int len, + struct ucred *cred, struct proc *p); +int venus_link(void *mdp, CodaFid *fid, CodaFid *tfid, const char *nm, + int len, struct ucred *cred, struct proc *p); +int venus_rename(void *mdp, CodaFid *fid, CodaFid *tfid, const char *nm, + int len, const char *tnm, int tlen, struct ucred *cred, + struct proc *p); +int venus_mkdir(void *mdp, CodaFid *fid, const char *nm, int len, + struct vattr *va, struct ucred *cred, struct proc *p, + /*out*/ CodaFid *VFid, struct vattr *ova); +int venus_rmdir(void *mdp, CodaFid *fid, const char *nm, int len, + struct ucred *cred, struct proc *p); +int venus_symlink(void *mdp, CodaFid *fid, const char *lnm, int llen, + const char *nm, int len, struct vattr *va, struct ucred *cred, + struct proc *p); +int venus_readdir(void *mdp, CodaFid *fid, int count, int offset, + struct ucred *cred, struct proc *p, /*out*/ char *buffer, + int *len); +int venus_fhtovp(void *mdp, CodaFid *fid, struct ucred *cred, + struct proc *p, /*out*/ CodaFid *VFid, int *vtype); + +#endif /* !_CODA_VENUS_H_ */ diff --git a/sys/fs/coda/coda_vfsops.c b/sys/fs/coda/coda_vfsops.c index e5c4b19..2f7b373 100644 --- a/sys/fs/coda/coda_vfsops.c +++ b/sys/fs/coda/coda_vfsops.c @@ -1,10 +1,10 @@ /*- * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -13,20 +13,21 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/cfs/coda_vfsops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ */ + /*- * Mach Operating System * Copyright (c) 1989 Carnegie-Mellon University @@ -37,7 +38,7 @@ /* * This code was written for the Coda filesystem at Carnegie Mellon * University. Contributers include David Steere, James Kistler, and - * M. Satyanarayanan. + * M. Satyanarayanan. */ #include @@ -64,337 +65,332 @@ MALLOC_DEFINE(M_CODA, "coda", "Various Coda Structures"); int codadebug = 0; int coda_vfsop_print_entry = 0; -#define ENTRY if(coda_vfsop_print_entry) myprintf(("Entered %s\n",__func__)) +#define ENTRY do { \ + if (coda_vfsop_print_entry) \ + myprintf(("Entered %s\n", __func__)); \ +} while (0) struct vnode *coda_ctlvp; -/* structure to keep statistics of internally generated/satisfied calls */ - -struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE]; +/* + * Structure to keep statistics of internally generated/satisfied calls. + */ +static struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE]; -#define MARK_ENTRY(op) (coda_vfsopstats[op].entries++) -#define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++) -#define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++) -#define MARK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++) +#define MARK_ENTRY(op) (coda_vfsopstats[op].entries++) +#define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++) +#define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++) +#define MARK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++) int coda_vfsopstats_init(void) { - register int i; - - for (i=0;imnt_optnew, coda_opts)) - return (EINVAL); - - from = vfs_getopts(vfsp->mnt_optnew, "from", &error); - if (error) - return (error); + struct vnode *dvp; + struct cnode *cp; + struct cdev *dev; + struct coda_mntinfo *mi; + struct vnode *rootvp; + CodaFid rootfid = INVAL_FID; + CodaFid ctlfid = CTL_FID; + int error; + struct nameidata ndp; + ENTRY; + char *from; + + if (vfs_filteropt(vfsp->mnt_optnew, coda_opts)) + return (EINVAL); + from = vfs_getopts(vfsp->mnt_optnew, "from", &error); + if (error) + return (error); + coda_vfsopstats_init(); + coda_vnodeopstats_init(); + MARK_ENTRY(CODA_MOUNT_STATS); + if (CODA_MOUNTED(vfsp)) { + MARK_INT_FAIL(CODA_MOUNT_STATS); + return (EBUSY); + } - coda_vfsopstats_init(); - coda_vnodeopstats_init(); - - MARK_ENTRY(CODA_MOUNT_STATS); - if (CODA_MOUNTED(vfsp)) { - MARK_INT_FAIL(CODA_MOUNT_STATS); - return(EBUSY); - } - - /* Validate mount device. Similar to getmdev(). */ - NDINIT(&ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, from, td); - error = namei(&ndp); - dvp = ndp.ni_vp; - - if (error) { - MARK_INT_FAIL(CODA_MOUNT_STATS); - return (error); - } - if (dvp->v_type != VCHR) { - MARK_INT_FAIL(CODA_MOUNT_STATS); + /* + * Validate mount device. Similar to getmdev(). + */ + NDINIT(&ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, from, td); + error = namei(&ndp); + dvp = ndp.ni_vp; + if (error) { + MARK_INT_FAIL(CODA_MOUNT_STATS); + return (error); + } + if (dvp->v_type != VCHR) { + MARK_INT_FAIL(CODA_MOUNT_STATS); + vrele(dvp); + NDFREE(&ndp, NDF_ONLY_PNBUF); + return (ENXIO); + } + dev = dvp->v_rdev; vrele(dvp); NDFREE(&ndp, NDF_ONLY_PNBUF); - return(ENXIO); - } - dev = dvp->v_rdev; - vrele(dvp); - NDFREE(&ndp, NDF_ONLY_PNBUF); - - /* - * Initialize the mount record and link it to the vfs struct - */ - mi = dev2coda_mntinfo(dev); - if (!mi) { - MARK_INT_FAIL(CODA_MOUNT_STATS); - printf("Coda mount: %s is not a cfs device\n", from); - return(ENXIO); - } - - if (!VC_OPEN(&mi->mi_vcomm)) { - MARK_INT_FAIL(CODA_MOUNT_STATS); - return(ENODEV); - } - - /* No initialization (here) of mi_vcomm! */ - vfsp->mnt_data = mi; - vfs_getnewfsid (vfsp); - - mi->mi_vfsp = vfsp; - mi->mi_started = 0; /* XXX See coda_root() */ - - /* - * Make a root vnode to placate the Vnode interface, but don't - * actually make the CODA_ROOT call to venus until the first call - * to coda_root in case a server is down while venus is starting. - */ - cp = make_coda_node(&rootfid, vfsp, VDIR); - rootvp = CTOV(cp); - rootvp->v_vflag |= VV_ROOT; - - cp = make_coda_node(&ctlfid, vfsp, VREG); - coda_ctlvp = CTOV(cp); - - /* Add vfs and rootvp to chain of vfs hanging off mntinfo */ - mi->mi_vfsp = vfsp; - mi->mi_rootvp = rootvp; - - vfs_mountedfrom(vfsp, from); - /* error is currently guaranteed to be zero, but in case some - code changes... */ - CODADEBUG(1, - myprintf(("coda_omount returned %d\n",error));); - if (error) - MARK_INT_FAIL(CODA_MOUNT_STATS); - else - MARK_INT_SAT(CODA_MOUNT_STATS); - - return(error); -} -int -coda_unmount(vfsp, mntflags, td) - struct mount *vfsp; - int mntflags; - struct thread *td; -{ - struct coda_mntinfo *mi = vftomi(vfsp); - int active, error = 0; - - ENTRY; - MARK_ENTRY(CODA_UMOUNT_STATS); - if (!CODA_MOUNTED(vfsp)) { - MARK_INT_FAIL(CODA_UMOUNT_STATS); - return(EINVAL); - } - - if (mi->mi_vfsp == vfsp) { /* We found the victim */ - if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp))) - return (EBUSY); /* Venus is still running */ - -#ifdef DEBUG - printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, VTOC(mi->mi_rootvp)); -#endif - vrele(mi->mi_rootvp); - mi->mi_rootvp = NULL; - vrele(coda_ctlvp); - coda_ctlvp = NULL; - active = coda_kill(vfsp, NOT_DOWNCALL); - error = vflush(mi->mi_vfsp, 0, FORCECLOSE, td); -#ifdef CODA_VERBOSE - printf("coda_unmount: active = %d, vflush active %d\n", active, error); -#endif - error = 0; - /* I'm going to take this out to allow lookups to go through. I'm - * not sure it's important anyway. -- DCS 2/2/94 + /* + * Initialize the mount record and link it to the vfs struct. */ - /* vfsp->VFS_DATA = NULL; */ + mi = dev2coda_mntinfo(dev); + if (!mi) { + MARK_INT_FAIL(CODA_MOUNT_STATS); + printf("Coda mount: %s is not a cfs device\n", from); + return (ENXIO); + } + if (!VC_OPEN(&mi->mi_vcomm)) { + MARK_INT_FAIL(CODA_MOUNT_STATS); + return (ENODEV); + } - /* No more vfsp's to hold onto */ - mi->mi_vfsp = NULL; + /* + * No initialization (here) of mi_vcomm! + */ + vfsp->mnt_data = mi; + vfs_getnewfsid (vfsp); + mi->mi_vfsp = vfsp; + mi->mi_started = 0; /* XXX See coda_root() */ + /* + * Make a root vnode to placate the Vnode interface, but don't + * actually make the CODA_ROOT call to venus until the first call to + * coda_root in case a server is down while venus is starting. + */ + cp = make_coda_node(&rootfid, vfsp, VDIR); + rootvp = CTOV(cp); + rootvp->v_vflag |= VV_ROOT; + cp = make_coda_node(&ctlfid, vfsp, VREG); + coda_ctlvp = CTOV(cp); + + /* + * Add vfs and rootvp to chain of vfs hanging off mntinfo. + */ + mi->mi_vfsp = vfsp; + mi->mi_rootvp = rootvp; + vfs_mountedfrom(vfsp, from); + + /* + * Error is currently guaranteed to be zero, but in case some code + * changes... + */ + CODADEBUG(1, myprintf(("coda_mount returned %d\n", error));); if (error) - MARK_INT_FAIL(CODA_UMOUNT_STATS); + MARK_INT_FAIL(CODA_MOUNT_STATS); else - MARK_INT_SAT(CODA_UMOUNT_STATS); + MARK_INT_SAT(CODA_MOUNT_STATS); + return (error); +} - return(error); - } - return (EINVAL); +int +coda_unmount(struct mount *vfsp, int mntflags, struct thread *td) +{ + struct coda_mntinfo *mi = vftomi(vfsp); + int active, error = 0; + + ENTRY; + MARK_ENTRY(CODA_UMOUNT_STATS); + if (!CODA_MOUNTED(vfsp)) { + MARK_INT_FAIL(CODA_UMOUNT_STATS); + return (EINVAL); + } + if (mi->mi_vfsp == vfsp) { + /* + * We found the victim. + */ + if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp))) + return (EBUSY); /* Venus is still running */ +#ifdef DEBUG + printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, + VTOC(mi->mi_rootvp)); +#endif + vrele(mi->mi_rootvp); + mi->mi_rootvp = NULL; + vrele(coda_ctlvp); + coda_ctlvp = NULL; + active = coda_kill(vfsp, NOT_DOWNCALL); + error = vflush(mi->mi_vfsp, 0, FORCECLOSE, td); +#ifdef CODA_VERBOSE + printf("coda_unmount: active = %d, vflush active %d\n", + active, error); +#endif + error = 0; + /* + * I'm going to take this out to allow lookups to go through. + * I'm not sure it's important anyway. -- DCS 2/2/94 + */ + /* vfsp->VFS_DATA = NULL; */ + + /* + * No more vfsp's to hold onto. + */ + mi->mi_vfsp = NULL; + + if (error) + MARK_INT_FAIL(CODA_UMOUNT_STATS); + else + MARK_INT_SAT(CODA_UMOUNT_STATS); + return (error); + } + return (EINVAL); } /* - * find root of cfs + * Find root of cfs. */ int -coda_root(vfsp, flags, vpp, td) - struct mount *vfsp; - int flags; - struct vnode **vpp; - struct thread *td; +coda_root(struct mount *vfsp, int flags, struct vnode **vpp, + struct thread *td) { - struct coda_mntinfo *mi = vftomi(vfsp); - struct vnode **result; - int error; - struct proc *p = td->td_proc; - CodaFid VFid; - static const CodaFid invalfid = INVAL_FID; - - ENTRY; - MARK_ENTRY(CODA_ROOT_STATS); - result = NULL; - - if (vfsp == mi->mi_vfsp) { - /* - * Cache the root across calls. We only need to pass the request - * on to Venus if the root vnode is the dummy we installed in - * coda_omount() with all c_fid members zeroed. - * - * XXX In addition, we assume that the first call to coda_root() - * is from vfs_omount() - * (before the call to checkdirs()) and return the dummy root - * node to avoid a deadlock. This bug is fixed in the Coda CVS - * repository but not in any released versions as of 6 Mar 2003. - */ - if (memcmp(&VTOC(mi->mi_rootvp)->c_fid, &invalfid, - sizeof(CodaFid)) != 0 || mi->mi_started == 0) - { /* Found valid root. */ - *vpp = mi->mi_rootvp; - mi->mi_started = 1; + struct coda_mntinfo *mi = vftomi(vfsp); + struct vnode **result; + int error; + struct proc *p = td->td_proc; + CodaFid VFid; + static const CodaFid invalfid = INVAL_FID; + + ENTRY; + MARK_ENTRY(CODA_ROOT_STATS); + result = NULL; + if (vfsp == mi->mi_vfsp) { + /* + * Cache the root across calls. We only need to pass the + * request on to Venus if the root vnode is the dummy we + * installed in coda_mount() with all c_fid members zeroed. + * + * XXX In addition, we assume that the first call to + * coda_root() is from vfs_mount() (before the call to + * checkdirs()) and return the dummy root node to avoid a + * deadlock. This bug is fixed in the Coda CVS repository + * but not in any released versions as of 6 Mar 2003. + */ + if (memcmp(&VTOC(mi->mi_rootvp)->c_fid, &invalfid, + sizeof(CodaFid)) != 0 || mi->mi_started == 0) { + /* + * Found valid root. + */ + *vpp = mi->mi_rootvp; + mi->mi_started = 1; + + /* + * On Mach, this is vref. On FreeBSD, vref + + * vn_lock. + */ + vref(*vpp); + vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY); + MARK_INT_SAT(CODA_ROOT_STATS); + return (0); + } + } - /* On Mach, this is vref. On FreeBSD, vref + vn_lock. */ + error = venus_root(vftomi(vfsp), td->td_ucred, p, &VFid); + if (!error) { + /* + * Save the new rootfid in the cnode, and rehash the cnode + * into the cnode hash with the new fid key. + */ + coda_unsave(VTOC(mi->mi_rootvp)); + VTOC(mi->mi_rootvp)->c_fid = VFid; + coda_save(VTOC(mi->mi_rootvp)); + *vpp = mi->mi_rootvp; vref(*vpp); vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY); MARK_INT_SAT(CODA_ROOT_STATS); - return(0); - } - } - - error = venus_root(vftomi(vfsp), td->td_ucred, p, &VFid); - - if (!error) { - /* - * Save the new rootfid in the cnode, and rehash the cnode into the - * cnode hash with the new fid key. - */ - coda_unsave(VTOC(mi->mi_rootvp)); - VTOC(mi->mi_rootvp)->c_fid = VFid; - coda_save(VTOC(mi->mi_rootvp)); - - *vpp = mi->mi_rootvp; - vref(*vpp); - vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY); - - MARK_INT_SAT(CODA_ROOT_STATS); - goto exit; - } else if (error == ENODEV || error == EINTR) { - /* Gross hack here! */ - /* - * If Venus fails to respond to the CODA_ROOT call, coda_call returns - * ENODEV. Return the uninitialized root vnode to allow vfs - * operations such as unmount to continue. Without this hack, - * there is no way to do an unmount if Venus dies before a - * successful CODA_ROOT call is done. All vnode operations - * will fail. - */ - *vpp = mi->mi_rootvp; - vref(*vpp); - vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY); - - MARK_INT_FAIL(CODA_ROOT_STATS); - error = 0; - goto exit; - } else { - CODADEBUG( CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", error)); ); - MARK_INT_FAIL(CODA_ROOT_STATS); - - goto exit; - } - - exit: - return(error); + } else if (error == ENODEV || error == EINTR) { + /* + * Gross hack here! + * + * If Venus fails to respond to the CODA_ROOT call, coda_call + * returns ENODEV. Return the uninitialized root vnode to + * allow vfs operations such as unmount to continue. Without + * this hack, there is no way to do an unmount if Venus dies + * before a successful CODA_ROOT call is done. All vnode + * operations will fail. + */ + *vpp = mi->mi_rootvp; + vref(*vpp); + vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY); + MARK_INT_FAIL(CODA_ROOT_STATS); + error = 0; + } else { + CODADEBUG(CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", + error));); + MARK_INT_FAIL(CODA_ROOT_STATS); + } + return (error); } /* * Get filesystem statistics. */ int -coda_statfs(vfsp, sbp, td) - register struct mount *vfsp; - struct statfs *sbp; - struct thread *td; +coda_statfs(struct mount *vfsp, struct statfs *sbp, struct thread *td) { - ENTRY; - MARK_ENTRY(CODA_STATFS_STATS); - if (!CODA_MOUNTED(vfsp)) { - MARK_INT_FAIL(CODA_STATFS_STATS); - return(EINVAL); - } - - /* XXX - what to do about f_flags, others? --bnoble */ - /* Below This is what AFS does - #define CODA_SFS_SIZ 0x895440 - */ - sbp->f_flags = 0; - sbp->f_bsize = 8192; /* XXX */ - sbp->f_iosize = 8192; /* XXX */ -#define CODA_SFS_SIZ 0x8AB75D - sbp->f_blocks = CODA_SFS_SIZ; - sbp->f_bfree = CODA_SFS_SIZ; - sbp->f_bavail = CODA_SFS_SIZ; - sbp->f_files = CODA_SFS_SIZ; - sbp->f_ffree = CODA_SFS_SIZ; - MARK_INT_SAT(CODA_STATFS_STATS); - return(0); + + ENTRY; + MARK_ENTRY(CODA_STATFS_STATS); + if (!CODA_MOUNTED(vfsp)) { + MARK_INT_FAIL(CODA_STATFS_STATS); + return (EINVAL); + } + + /* + * XXX - what to do about f_flags, others? --bnoble + * + * We just make up free space counts that are sufficiently large. + */ + sbp->f_flags = 0; + sbp->f_bsize = 8192; /* XXX */ + sbp->f_iosize = 8192; /* XXX */ +#define CODA_SFS_SIZ 0x8AB75D + sbp->f_blocks = CODA_SFS_SIZ; + sbp->f_bfree = CODA_SFS_SIZ; + sbp->f_bavail = CODA_SFS_SIZ; + sbp->f_files = CODA_SFS_SIZ; + sbp->f_ffree = CODA_SFS_SIZ; + MARK_INT_SAT(CODA_STATFS_STATS); + return (0); } /* * Flush any pending I/O. */ int -coda_sync(vfsp, waitfor, td) - struct mount *vfsp; - int waitfor; - struct thread *td; +coda_sync(struct mount *vfsp, int waitfor, struct thread *td) { - ENTRY; - MARK_ENTRY(CODA_SYNC_STATS); - MARK_INT_SAT(CODA_SYNC_STATS); - return(0); + + ENTRY; + MARK_ENTRY(CODA_SYNC_STATS); + MARK_INT_SAT(CODA_SYNC_STATS); + return (0); } -/* - * fhtovp is now what vget used to be in 4.3-derived systems. For - * some silly reason, vget is now keyed by a 32 bit ino_t, rather than - * a type-specific fid. +/* + * fhtovp is now what vget used to be in 4.3-derived systems. For some silly + * reason, vget is now keyed by a 32 bit ino_t, rather than a type-specific + * fid. * * XXX: coda_fhtovp is currently not hooked up, so no NFS export for Coda. * We leave it here in the hopes that someone will find it someday and hook @@ -402,54 +398,48 @@ coda_sync(vfsp, waitfor, td) * vfs_fhtovp_t prototype. */ int -coda_fhtovp(vfsp, fhp, nam, vpp, exflagsp, creadanonp) - register struct mount *vfsp; - struct fid *fhp; - struct mbuf *nam; - struct vnode **vpp; - int *exflagsp; - struct ucred **creadanonp; +coda_fhtovp(struct mount *vfsp, struct fid *fhp, struct mbuf *nam, + struct vnode **vpp, int *exflagsp, struct ucred **creadanonp) { - struct cfid *cfid = (struct cfid *)fhp; - struct cnode *cp = 0; - int error; - struct thread *td = curthread; /* XXX -mach */ - struct proc *p = td->td_proc; - CodaFid VFid; - int vtype; - - ENTRY; - - MARK_ENTRY(CODA_VGET_STATS); - /* Check for vget of control object. */ - if (IS_CTL_FID(&cfid->cfid_fid)) { - *vpp = coda_ctlvp; - vref(coda_ctlvp); - MARK_INT_SAT(CODA_VGET_STATS); - return(0); - } - - error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, td->td_ucred, p, &VFid, &vtype); - - if (error) { - CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));) - *vpp = (struct vnode *)0; - } else { - CODADEBUG(CODA_VGET, - myprintf(("vget: %s type %d result %d\n", - coda_f2s(&VFid), vtype, error)); ) - cp = make_coda_node(&VFid, vfsp, vtype); - *vpp = CTOV(cp); - } - return(error); + struct cfid *cfid = (struct cfid *)fhp; + struct cnode *cp = NULL; + int error; + struct thread *td = curthread; /* XXX -mach */ + struct proc *p = td->td_proc; + CodaFid VFid; + int vtype; + + ENTRY; + MARK_ENTRY(CODA_VGET_STATS); + + /* + * Check for vget of control object. + */ + if (IS_CTL_FID(&cfid->cfid_fid)) { + *vpp = coda_ctlvp; + vref(coda_ctlvp); + MARK_INT_SAT(CODA_VGET_STATS); + return (0); + } + error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, td->td_ucred, p, + &VFid, &vtype); + if (error) { + CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));); + *vpp = NULL; + } else { + CODADEBUG(CODA_VGET, myprintf(("vget: %s type %d result " + "%d\n", coda_f2s(&VFid), vtype, error));); + cp = make_coda_node(&VFid, vfsp, vtype); + *vpp = CTOV(cp); + } + return (error); } struct vfsops coda_vfsops = { - .vfs_mount = coda_mount, - .vfs_root = coda_root, - .vfs_statfs = coda_statfs, - .vfs_sync = coda_sync, - .vfs_unmount = coda_unmount, + .vfs_mount = coda_mount, + .vfs_root = coda_root, + .vfs_statfs = coda_statfs, + .vfs_sync = coda_sync, + .vfs_unmount = coda_unmount, }; - VFS_SET(coda_vfsops, coda, VFCF_NETWORK); diff --git a/sys/fs/coda/coda_vfsops.h b/sys/fs/coda/coda_vfsops.h index b661e0a..b51f4bc 100644 --- a/sys/fs/coda/coda_vfsops.h +++ b/sys/fs/coda/coda_vfsops.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,44 +14,47 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * - * @(#) src/sys/cfs/coda_vfsops.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ + * + * @(#) src/sys/cfs/coda_vfsops.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * */ +#ifndef _CODA_VFSOPS_H_ +#define _CODA_VFSOPS_H_ + /* * cfid structure: - * This overlays the fid structure (see vfs.h) - * Only used below and will probably go away. + * + * This overlays the fid structure (see vfs.h); only used below and will + * probably go away. */ - struct cfid { - u_short cfid_len; - u_short padding; - CodaFid cfid_fid; + u_short cfid_len; + u_short padding; + CodaFid cfid_fid; }; struct mbuf; struct mount; - -int coda_vfsopstats_init(void); -int coda_fhtovp(struct mount *, struct fid *, struct mbuf *, struct vnode **, - int *, struct ucred **); +int coda_vfsopstats_init(void); +int coda_fhtovp(struct mount *, struct fid *, struct mbuf *, + struct vnode **, int *, struct ucred **); vfs_mount_t coda_mount; vfs_unmount_t coda_unmount; vfs_root_t coda_root; vfs_statfs_t coda_statfs; vfs_sync_t coda_sync; + +#endif /* !_CODA_VFSOPS_H_ */ diff --git a/sys/fs/coda/coda_vnops.c b/sys/fs/coda/coda_vnops.c index 3206268..f55a808 100644 --- a/sys/fs/coda/coda_vnops.c +++ b/sys/fs/coda/coda_vnops.c @@ -1,10 +1,10 @@ /*- * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -13,21 +13,21 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ */ -/* +/* * Mach Operating System * Copyright (c) 1990 Carnegie-Mellon University * Copyright (c) 1989 Carnegie-Mellon University @@ -38,7 +38,7 @@ /* * This code was written for the Coda filesystem at Carnegie Mellon * University. Contributers include David Steere, James Kistler, and - * M. Satyanarayanan. + * M. Satyanarayanan. */ #include @@ -73,75 +73,80 @@ __FBSDID("$FreeBSD$"); #include #include -/* +/* * These flags select various performance enhancements. */ -int coda_attr_cache = 1; /* Set to cache attributes in the kernel */ -int coda_symlink_cache = 1; /* Set to cache symbolic link information */ -int coda_access_cache = 1; /* Set to handle some access checks directly */ - -/* structure to keep track of vfs calls */ +static int coda_attr_cache = 1; /* Set to cache attributes. */ +static int coda_symlink_cache = 1; /* Set to cache symbolic links. */ +static int coda_access_cache = 1; /* Set to cache some access checks. */ -struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE]; +/* + * Structure to keep track of vfs calls. + */ +static struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE]; -#define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++) -#define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++) -#define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++) -#define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++) +#define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++) +#define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++) +#define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++) +#define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++) -/* What we are delaying for in printf */ -int coda_printf_delay = 0; /* in microseconds */ +/* + * What we are delaying for in printf. + */ +int coda_printf_delay = 0; /* In microseconds */ int coda_vnop_print_entry = 0; static int coda_lockdebug = 0; /* * Some FreeBSD details: - * - * codadev_modevent is called at boot time or module load time. + * + * codadev_modevent is called at boot time or module load time. */ +#define ENTRY do { \ + if (coda_vnop_print_entry) \ + myprintf(("Entered %s\n", __func__)); \ +} while (0) -#define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__)) - -/* Definition of the vnode operation vector */ - +/* + * Definition of the vnode operation vector. + */ struct vop_vector coda_vnodeops = { - .vop_default = &default_vnodeops, - .vop_lookup = coda_lookup, /* lookup */ - .vop_create = coda_create, /* create */ - .vop_open = coda_open, /* open */ - .vop_close = coda_close, /* close */ - .vop_access = coda_access, /* access */ - .vop_getattr = coda_getattr, /* getattr */ - .vop_setattr = coda_setattr, /* setattr */ - .vop_read = coda_read, /* read */ - .vop_write = coda_write, /* write */ - .vop_ioctl = coda_ioctl, /* ioctl */ - .vop_fsync = coda_fsync, /* fsync */ - .vop_remove = coda_remove, /* remove */ - .vop_link = coda_link, /* link */ - .vop_rename = coda_rename, /* rename */ - .vop_mkdir = coda_mkdir, /* mkdir */ - .vop_rmdir = coda_rmdir, /* rmdir */ - .vop_symlink = coda_symlink, /* symlink */ - .vop_readdir = coda_readdir, /* readdir */ - .vop_readlink = coda_readlink, /* readlink */ - .vop_inactive = coda_inactive, /* inactive */ - .vop_reclaim = coda_reclaim, /* reclaim */ - .vop_lock1 = coda_lock, /* lock */ - .vop_unlock = coda_unlock, /* unlock */ - .vop_bmap = VOP_EOPNOTSUPP, /* bmap */ - .vop_print = VOP_NULL, /* print */ - .vop_islocked = coda_islocked, /* islocked */ - .vop_pathconf = coda_pathconf, /* pathconf */ - .vop_poll = vop_stdpoll, - .vop_getpages = vop_stdgetpages, /* pager intf.*/ - .vop_putpages = vop_stdputpages, /* pager intf.*/ - .vop_getwritemount = vop_stdgetwritemount, - + .vop_default = &default_vnodeops, + .vop_lookup = coda_lookup, /* lookup */ + .vop_create = coda_create, /* create */ + .vop_open = coda_open, /* open */ + .vop_close = coda_close, /* close */ + .vop_access = coda_access, /* access */ + .vop_getattr = coda_getattr, /* getattr */ + .vop_setattr = coda_setattr, /* setattr */ + .vop_read = coda_read, /* read */ + .vop_write = coda_write, /* write */ + .vop_ioctl = coda_ioctl, /* ioctl */ + .vop_fsync = coda_fsync, /* fsync */ + .vop_remove = coda_remove, /* remove */ + .vop_link = coda_link, /* link */ + .vop_rename = coda_rename, /* rename */ + .vop_mkdir = coda_mkdir, /* mkdir */ + .vop_rmdir = coda_rmdir, /* rmdir */ + .vop_symlink = coda_symlink, /* symlink */ + .vop_readdir = coda_readdir, /* readdir */ + .vop_readlink = coda_readlink, /* readlink */ + .vop_inactive = coda_inactive, /* inactive */ + .vop_reclaim = coda_reclaim, /* reclaim */ + .vop_lock1 = coda_lock, /* lock */ + .vop_unlock = coda_unlock, /* unlock */ + .vop_bmap = VOP_EOPNOTSUPP, /* bmap */ + .vop_print = VOP_NULL, /* print */ + .vop_islocked = coda_islocked, /* islocked */ + .vop_pathconf = coda_pathconf, /* pathconf */ + .vop_poll = vop_stdpoll, + .vop_getpages = vop_stdgetpages, /* pager intf.*/ + .vop_putpages = vop_stdputpages, /* pager intf.*/ + .vop_getwritemount = vop_stdgetwritemount, #if 0 - missing - .vop_cachedlookup = ufs_lookup, - .vop_whiteout = ufs_whiteout, + /* missing */ + .vop_cachedlookup = ufs_lookup, + .vop_whiteout = ufs_whiteout, #endif }; @@ -151,91 +156,97 @@ static void coda_print_vattr(struct vattr *attr); int coda_vnodeopstats_init(void) { - register int i; - - for(i=0;ia_vp); - struct cnode *cp = VTOC(*vpp); - int flag = ap->a_mode & (~O_EXCL); - struct ucred *cred = ap->a_cred; - struct thread *td = ap->a_td; -/* locals */ - int error; - struct vnode *vp; - - MARK_ENTRY(CODA_OPEN_STATS); - - /* Check for open of control file. */ - if (IS_CTL_VP(*vpp)) { - /* XXX */ - /* if (WRITEABLE(flag)) */ - if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) { - MARK_INT_FAIL(CODA_OPEN_STATS); - return(EACCES); + + /* + * FreeBSD can pass the O_EXCL flag in mode, even though the check + * has already happened. Venus defensively assumes that if open is + * passed the EXCL, it must be a bug. We strip the flag here. + */ + /* true args */ + struct vnode **vpp = &(ap->a_vp); + struct cnode *cp = VTOC(*vpp); + int flag = ap->a_mode & (~O_EXCL); + struct ucred *cred = ap->a_cred; + struct thread *td = ap->a_td; + /* locals */ + int error; + struct vnode *vp; + + MARK_ENTRY(CODA_OPEN_STATS); + + /* + * Check for open of control file. + */ + if (IS_CTL_VP(*vpp)) { + /* XXX */ + /* if (WRITEABLE(flag)) */ + if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) { + MARK_INT_FAIL(CODA_OPEN_STATS); + return (EACCES); + } + MARK_INT_SAT(CODA_OPEN_STATS); + return (0); } - MARK_INT_SAT(CODA_OPEN_STATS); - return(0); - } + error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, + td->td_proc, &vp); + if (error) + return (error); + CODADEBUG(CODA_OPEN, myprintf(("open: vp %p result %d\n", vp, + error));); - error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td->td_proc, &vp); - if (error) - return (error); + /* + * Save the vnode pointer for the cache file. + */ + if (cp->c_ovp == NULL) { + cp->c_ovp = vp; + } else { + if (cp->c_ovp != vp) + panic("coda_open: cp->c_ovp != ITOV(ip)"); + } + cp->c_ocount++; + + /* + * Flush the attribute cached if writing the file. + */ + if (flag & FWRITE) { + cp->c_owrite++; + cp->c_flags &= ~C_VATTR; + } - CODADEBUG( CODA_OPEN,myprintf(("open: vp %p result %d\n", vp, error));) - - /* Save the vnode pointer for the cache file. */ - if (cp->c_ovp == NULL) { - cp->c_ovp = vp; - } else { - if (cp->c_ovp != vp) - panic("coda_open: cp->c_ovp != ITOV(ip)"); - } - cp->c_ocount++; - - /* Flush the attribute cached if writing the file. */ - if (flag & FWRITE) { - cp->c_owrite++; - cp->c_flags &= ~C_VATTR; - } - - /* Open the cache file. */ - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - error = VOP_OPEN(vp, flag, cred, td, NULL); - if (error) { - VOP_UNLOCK(vp, 0); - printf("coda_open: VOP_OPEN on container failed %d\n", error); - return (error); - } else { + /* + * Open the cache file. + */ + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + error = VOP_OPEN(vp, flag, cred, td, NULL); + if (error) { + VOP_UNLOCK(vp, 0); + printf("coda_open: VOP_OPEN on container failed %d\n", error); + return (error); + } (*vpp)->v_object = vp->v_object; - } - VOP_UNLOCK(vp, 0); -/* grab (above) does this when it calls newvnode unless it's in the cache*/ - - return(error); + VOP_UNLOCK(vp, 0); + return (0); } /* @@ -244,1439 +255,1514 @@ coda_open(struct vop_open_args *ap) int coda_close(struct vop_close_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - int flag = ap->a_fflag; - struct ucred *cred = ap->a_cred; - struct thread *td = ap->a_td; -/* locals */ - int error; - - MARK_ENTRY(CODA_CLOSE_STATS); - - /* Check for close of control file. */ - if (IS_CTL_VP(vp)) { - MARK_INT_SAT(CODA_CLOSE_STATS); - return(0); - } - - if (cp->c_ovp) { - vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY); - VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */ - vput(cp->c_ovp); - } -#ifdef CODA_VERBOSE - else printf("coda_close: NO container vp %p/cp %p\n", vp, cp); -#endif - - if (--cp->c_ocount == 0) - cp->c_ovp = NULL; - - if (flag & FWRITE) /* file was opened for write */ - --cp->c_owrite; + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + int flag = ap->a_fflag; + struct ucred *cred = ap->a_cred; + struct thread *td = ap->a_td; + /* locals */ + int error; - if (!IS_UNMOUNTING(cp)) - error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, td->td_proc); - else error = ENODEV; + MARK_ENTRY(CODA_CLOSE_STATS); - CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); ) - return(error); + /* + * Check for close of control file. + */ + if (IS_CTL_VP(vp)) { + MARK_INT_SAT(CODA_CLOSE_STATS); + return (0); + } + if (cp->c_ovp) { + vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY); + /* Do errors matter here? */ + VOP_CLOSE(cp->c_ovp, flag, cred, td); + vput(cp->c_ovp); + } +#ifdef CODA_VERBOSE + else + printf("coda_close: NO container vp %p/cp %p\n", vp, cp); +#endif + if (--cp->c_ocount == 0) + cp->c_ovp = NULL; + + /* + * File was opened for write. + */ + if (flag & FWRITE) + --cp->c_owrite; + if (!IS_UNMOUNTING(cp)) + error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, + td->td_proc); + else + error = ENODEV; + CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error));); + return (error); } int coda_read(struct vop_read_args *ap) { - ENTRY; - return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ, - ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td)); + ENTRY; + return (coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ, ap->a_ioflag, + ap->a_cred, ap->a_uio->uio_td)); } int coda_write(struct vop_write_args *ap) { - ENTRY; - return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE, - ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td)); + ENTRY; + return (coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE, ap->a_ioflag, + ap->a_cred, ap->a_uio->uio_td)); } int coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag, struct ucred *cred, struct thread *td) -{ -/* upcall decl */ - /* NOTE: container file operation!!! */ -/* locals */ - struct cnode *cp = VTOC(vp); - struct vnode *cfvp = cp->c_ovp; - int opened_internally = 0; - int error = 0; - - MARK_ENTRY(CODA_RDWR_STATS); - - CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw, - (void *)uiop->uio_iov->iov_base, uiop->uio_resid, - (long long)uiop->uio_offset, uiop->uio_segflg)); ) - - /* Check for rdwr of control object. */ - if (IS_CTL_VP(vp)) { - MARK_INT_FAIL(CODA_RDWR_STATS); - return(EINVAL); - } - - /* - * If file is not already open this must be a page {read,write} request - * and we should open it internally. - */ - if (cfvp == NULL) { - opened_internally = 1; - MARK_INT_GEN(CODA_OPEN_STATS); - error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, td, NULL); +{ + /* upcall decl */ + /* NOTE: container file operation!!! */ + /* locals */ + struct cnode *cp = VTOC(vp); + struct vnode *cfvp = cp->c_ovp; + int opened_internally = 0; + int error = 0; + + MARK_ENTRY(CODA_RDWR_STATS); + CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", + rw, (void *)uiop->uio_iov->iov_base, uiop->uio_resid, + (long long)uiop->uio_offset, uiop->uio_segflg));); + + /* + * Check for rdwr of control object. + */ + if (IS_CTL_VP(vp)) { + MARK_INT_FAIL(CODA_RDWR_STATS); + return (EINVAL); + } + + /* + * If file is not already open this must be a page {read,write} + * request and we should open it internally. + */ + if (cfvp == NULL) { + opened_internally = 1; + MARK_INT_GEN(CODA_OPEN_STATS); + error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, + td, NULL); #ifdef CODA_VERBOSE - printf("coda_rdwr: Internally Opening %p\n", vp); + printf("coda_rdwr: Internally Opening %p\n", vp); #endif - if (error) { - printf("coda_rdwr: VOP_OPEN on container failed %d\n", error); - return (error); + if (error) { + printf("coda_rdwr: VOP_OPEN on container failed " + "%d\n", error); + return (error); + } + cfvp = cp->c_ovp; } - cfvp = cp->c_ovp; - } - - /* Have UFS handle the call. */ - CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = %s, refcnt = %d\n", - coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount)); ) - vn_lock(cfvp, LK_EXCLUSIVE | LK_RETRY); - if (rw == UIO_READ) { - error = VOP_READ(cfvp, uiop, ioflag, cred); - } else { - error = VOP_WRITE(cfvp, uiop, ioflag, cred); - /* ufs_write updates the vnode_pager_setsize for the vnode/object */ - - { struct vattr attr; - - if (VOP_GETATTR(cfvp, &attr, cred, td) == 0) { - vnode_pager_setsize(vp, attr.va_size); - } + + /* + * Have UFS handle the call. + */ + CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = %s, refcnt = " + "%d\n", coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount));); + vn_lock(cfvp, LK_EXCLUSIVE | LK_RETRY); + if (rw == UIO_READ) { + error = VOP_READ(cfvp, uiop, ioflag, cred); + } else { + error = VOP_WRITE(cfvp, uiop, ioflag, cred); + /* + * ufs_write updates the vnode_pager_setsize for the + * vnode/object. + * + * XXX: Since we now share vm objects between layers, this is + * probably unnecessary. + */ + { + struct vattr attr; + if (VOP_GETATTR(cfvp, &attr, cred, td) == 0) + vnode_pager_setsize(vp, attr.va_size); + } + } + VOP_UNLOCK(cfvp, 0); + if (error) + MARK_INT_FAIL(CODA_RDWR_STATS); + else + MARK_INT_SAT(CODA_RDWR_STATS); + + /* + * Do an internal close if necessary. + */ + if (opened_internally) { + MARK_INT_GEN(CODA_CLOSE_STATS); + (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, + td); } - } - VOP_UNLOCK(cfvp, 0); - - if (error) - MARK_INT_FAIL(CODA_RDWR_STATS); - else - MARK_INT_SAT(CODA_RDWR_STATS); - - /* Do an internal close if necessary. */ - if (opened_internally) { - MARK_INT_GEN(CODA_CLOSE_STATS); - (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, td); - } - - /* Invalidate cached attributes if writing. */ - if (rw == UIO_WRITE) - cp->c_flags &= ~C_VATTR; - return(error); + + /* + * Invalidate cached attributes if writing. + */ + if (rw == UIO_WRITE) + cp->c_flags &= ~C_VATTR; + return (error); } int coda_ioctl(struct vop_ioctl_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - int com = ap->a_command; - caddr_t data = ap->a_data; - int flag = ap->a_fflag; - struct ucred *cred = ap->a_cred; - struct thread *td = ap->a_td; -/* locals */ - int error; - struct vnode *tvp; - struct nameidata ndp; - struct PioctlData *iap = (struct PioctlData *)data; - - MARK_ENTRY(CODA_IOCTL_STATS); - - CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));) - - /* Don't check for operation on a dying object, for ctlvp it - shouldn't matter */ - - /* Must be control object to succeed. */ - if (!IS_CTL_VP(vp)) { - MARK_INT_FAIL(CODA_IOCTL_STATS); - CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));) - return (EOPNOTSUPP); - } - /* Look up the pathname. */ - - /* Should we use the name cache here? It would get it from - lookupname sooner or later anyway, right? */ - - NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, td); - error = namei(&ndp); - tvp = ndp.ni_vp; - - if (error) { - MARK_INT_FAIL(CODA_IOCTL_STATS); - CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n", - error));) - return(error); - } - - /* - * Make sure this is a coda style cnode, but it may be a - * different vfsp - */ - if (tvp->v_op != &coda_vnodeops) { + /* true args */ + struct vnode *vp = ap->a_vp; + int com = ap->a_command; + caddr_t data = ap->a_data; + int flag = ap->a_fflag; + struct ucred *cred = ap->a_cred; + struct thread *td = ap->a_td; + /* locals */ + int error; + struct vnode *tvp; + struct nameidata ndp; + struct PioctlData *iap = (struct PioctlData *)data; + + MARK_ENTRY(CODA_IOCTL_STATS); + CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));); + + /* + * Don't check for operation on a dying object, for ctlvp it + * shouldn't matter. + * + * Must be control object to succeed. + */ + if (!IS_CTL_VP(vp)) { + MARK_INT_FAIL(CODA_IOCTL_STATS); + CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != " + "ctlvp"));); + return (EOPNOTSUPP); + } + + /* + * Look up the pathname. + * + * Should we use the name cache here? It would get it from lookupname + * sooner or later anyway, right? + */ + NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), + UIO_USERSPACE, iap->path, td); + error = namei(&ndp); + tvp = ndp.ni_vp; + if (error) { + MARK_INT_FAIL(CODA_IOCTL_STATS); + CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup " + "returns %d\n", error));); + return (error); + } + + /* + * Make sure this is a coda style cnode, but it may be a different + * vfsp. + */ + if (tvp->v_op != &coda_vnodeops) { + vrele(tvp); + NDFREE(&ndp, NDF_ONLY_PNBUF); + MARK_INT_FAIL(CODA_IOCTL_STATS); + CODADEBUG(CODA_IOCTL, + myprintf(("coda_ioctl error: %s not a coda object\n", + iap->path));); + return (EINVAL); + } + if (iap->vi.in_size > VC_MAXDATASIZE) { + NDFREE(&ndp, 0); + return (EINVAL); + } + error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, + data, cred, td->td_proc); + if (error) + MARK_INT_FAIL(CODA_IOCTL_STATS); + else + CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", + error));); vrele(tvp); NDFREE(&ndp, NDF_ONLY_PNBUF); - MARK_INT_FAIL(CODA_IOCTL_STATS); - CODADEBUG(CODA_IOCTL, - myprintf(("coda_ioctl error: %s not a coda object\n", - iap->path));) - return(EINVAL); - } - - if (iap->vi.in_size > VC_MAXDATASIZE) { - NDFREE(&ndp, 0); - return(EINVAL); - } - error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td->td_proc); - - if (error) - MARK_INT_FAIL(CODA_IOCTL_STATS); - else - CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); ) - - vrele(tvp); - NDFREE(&ndp, NDF_ONLY_PNBUF); - return(error); + return (error); } /* - * To reduce the cost of a user-level venus;we cache attributes in - * the kernel. Each cnode has storage allocated for an attribute. If - * c_vattr is valid, return a reference to it. Otherwise, get the - * attributes from venus and store them in the cnode. There is some - * question if this method is a security leak. But I think that in - * order to make this call, the user must have done a lookup and - * opened the file, and therefore should already have access. + * To reduce the cost of a user-level venus;we cache attributes in the + * kernel. Each cnode has storage allocated for an attribute. If c_vattr is + * valid, return a reference to it. Otherwise, get the attributes from venus + * and store them in the cnode. There is some question if this method is a + * security leak. But I think that in order to make this call, the user must + * have done a lookup and opened the file, and therefore should already have + * access. */ int coda_getattr(struct vop_getattr_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - struct vattr *vap = ap->a_vap; - struct ucred *cred = ap->a_cred; - struct thread *td = ap->a_td; -/* locals */ - int error; - - MARK_ENTRY(CODA_GETATTR_STATS); - - if (IS_UNMOUNTING(cp)) - return ENODEV; - - /* Check for getattr of control object. */ - if (IS_CTL_VP(vp)) { - MARK_INT_FAIL(CODA_GETATTR_STATS); - return(ENOENT); - } - - /* Check to see if the attributes have already been cached */ - if (VALID_VATTR(cp)) { - CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: %s\n", - coda_f2s(&cp->c_fid)));}); - CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) - coda_print_vattr(&cp->c_vattr); ); - - *vap = cp->c_vattr; - MARK_INT_SAT(CODA_GETATTR_STATS); - return(0); - } - - error = venus_getattr(vtomi(vp), &cp->c_fid, cred, td->td_proc, vap); - - if (!error) { - CODADEBUG(CODA_GETATTR, myprintf(("getattr miss %s: result %d\n", - coda_f2s(&cp->c_fid), error)); ) - - CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) - coda_print_vattr(vap); ); - - { int size = vap->va_size; - struct vnode *convp = cp->c_ovp; - if (convp != (struct vnode *)0) { - vnode_pager_setsize(convp, size); + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + struct vattr *vap = ap->a_vap; + struct ucred *cred = ap->a_cred; + struct thread *td = ap->a_td; + /* locals */ + struct vnode *convp; + int error, size; + + MARK_ENTRY(CODA_GETATTR_STATS); + if (IS_UNMOUNTING(cp)) + return (ENODEV); + + /* + * Check for getattr of control object. + */ + if (IS_CTL_VP(vp)) { + MARK_INT_FAIL(CODA_GETATTR_STATS); + return (ENOENT); + } + + /* + * Check to see if the attributes have already been cached. + */ + if (VALID_VATTR(cp)) { + CODADEBUG(CODA_GETATTR, myprintf(("attr cache hit: %s\n", + coda_f2s(&cp->c_fid)));); + CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) + coda_print_vattr(&cp->c_vattr);); + *vap = cp->c_vattr; + MARK_INT_SAT(CODA_GETATTR_STATS); + return (0); } - } - /* If not open for write, store attributes in cnode */ - if ((cp->c_owrite == 0) && (coda_attr_cache)) { - cp->c_vattr = *vap; - cp->c_flags |= C_VATTR; + error = venus_getattr(vtomi(vp), &cp->c_fid, cred, td->td_proc, vap); + if (!error) { + CODADEBUG(CODA_GETATTR, myprintf(("getattr miss %s: result " + "%d\n", coda_f2s(&cp->c_fid), error));); + CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) + coda_print_vattr(vap);); + + /* + * XXX: Since we now share vm objects between layers, this is + * probably unnecessary. + */ + size = vap->va_size; + convp = cp->c_ovp; + if (convp != NULL) + vnode_pager_setsize(convp, size); + + /* + * If not open for write, store attributes in cnode. + */ + if ((cp->c_owrite == 0) && (coda_attr_cache)) { + cp->c_vattr = *vap; + cp->c_flags |= C_VATTR; + } } - - } - return(error); + return (error); } int coda_setattr(struct vop_setattr_args *ap) { -/* true args */ - register struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - register struct vattr *vap = ap->a_vap; - struct ucred *cred = ap->a_cred; - struct thread *td = ap->a_td; -/* locals */ - int error; - - MARK_ENTRY(CODA_SETATTR_STATS); - - /* Check for setattr of control object. */ - if (IS_CTL_VP(vp)) { - MARK_INT_FAIL(CODA_SETATTR_STATS); - return(ENOENT); - } - - if (codadebug & CODADBGMSK(CODA_SETATTR)) { - coda_print_vattr(vap); - } - error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td->td_proc); - - if (!error) - cp->c_flags &= ~C_VATTR; - - { int size = vap->va_size; - struct vnode *convp = cp->c_ovp; - if (size != VNOVAL && convp != (struct vnode *)0) { - vnode_pager_setsize(convp, size); + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + struct vattr *vap = ap->a_vap; + struct ucred *cred = ap->a_cred; + struct thread *td = ap->a_td; + /* locals */ + struct vnode *convp; + int error, size; + + MARK_ENTRY(CODA_SETATTR_STATS); + + /* + * Check for setattr of control object. + */ + if (IS_CTL_VP(vp)) { + MARK_INT_FAIL(CODA_SETATTR_STATS); + return (ENOENT); } - } - CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); ) - return(error); + if (codadebug & CODADBGMSK(CODA_SETATTR)) + coda_print_vattr(vap); + error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td->td_proc); + if (!error) + cp->c_flags &= ~C_VATTR; + + /* + * XXX: Since we now share vm objects between layers, this is + * probably unnecessary. + * + * XXX: Shouldn't we only be doing this "set" if C_VATTR remains + * valid after venus_setattr()? + */ + size = vap->va_size; + convp = cp->c_ovp; + if (size != VNOVAL && convp != NULL) + vnode_pager_setsize(convp, size); + CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error));); + return (error); } int coda_access(struct vop_access_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - int mode = ap->a_mode; - struct ucred *cred = ap->a_cred; - struct thread *td = ap->a_td; -/* locals */ - int error; - - MARK_ENTRY(CODA_ACCESS_STATS); - - /* Check for access of control object. Only read access is - allowed on it. */ - if (IS_CTL_VP(vp)) { - /* bogus hack - all will be marked as successes */ - MARK_INT_SAT(CODA_ACCESS_STATS); - return(((mode & VREAD) && !(mode & (VWRITE | VEXEC))) - ? 0 : EACCES); - } - - /* - * if the file is a directory, and we are checking exec (eg lookup) - * access, and the file is in the namecache, then the user must have - * lookup access to it. - */ - if (coda_access_cache) { - if ((vp->v_type == VDIR) && (mode & VEXEC)) { - if (coda_nc_lookup(cp, ".", 1, cred)) { + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + int mode = ap->a_mode; + struct ucred *cred = ap->a_cred; + struct thread *td = ap->a_td; + /* locals */ + int error; + + MARK_ENTRY(CODA_ACCESS_STATS); + + /* + * Check for access of control object. Only read access is allowed + * on it. + */ + if (IS_CTL_VP(vp)) { + /* + * Bogus hack - all will be marked as successes. + */ MARK_INT_SAT(CODA_ACCESS_STATS); - return(0); /* it was in the cache */ - } + return (((mode & VREAD) && !(mode & (VWRITE | VEXEC))) + ? 0 : EACCES); } - } - - error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td->td_proc); - return(error); + /* + * if the file is a directory, and we are checking exec (eg lookup) + * access, and the file is in the namecache, then the user must have + * lookup access to it. + */ + if (coda_access_cache) { + if ((vp->v_type == VDIR) && (mode & VEXEC)) { + if (coda_nc_lookup(cp, ".", 1, cred)) { + MARK_INT_SAT(CODA_ACCESS_STATS); + return (0); + } + } + } + error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td->td_proc); + return (error); } int coda_readlink(struct vop_readlink_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - struct uio *uiop = ap->a_uio; - struct ucred *cred = ap->a_cred; - struct thread *td = ap->a_uio->uio_td; -/* locals */ - int error; - char *str; - int len; - - MARK_ENTRY(CODA_READLINK_STATS); - - /* Check for readlink of control object. */ - if (IS_CTL_VP(vp)) { - MARK_INT_FAIL(CODA_READLINK_STATS); - return(ENOENT); - } - - if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */ - uiop->uio_rw = UIO_READ; - error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop); - if (error) - MARK_INT_FAIL(CODA_READLINK_STATS); - else - MARK_INT_SAT(CODA_READLINK_STATS); - return(error); - } - - error = venus_readlink(vtomi(vp), &cp->c_fid, cred, - td != NULL ? td->td_proc : NULL, &str, &len); - - if (!error) { - uiop->uio_rw = UIO_READ; - error = uiomove(str, len, uiop); + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + struct uio *uiop = ap->a_uio; + struct ucred *cred = ap->a_cred; + struct thread *td = ap->a_uio->uio_td; + /* locals */ + int error; + char *str; + int len; - if (coda_symlink_cache) { - cp->c_symlink = str; - cp->c_symlen = len; - cp->c_flags |= C_SYMLINK; - } else - CODA_FREE(str, len); - } + MARK_ENTRY(CODA_READLINK_STATS); - CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));) - return(error); + /* + * Check for readlink of control object. + */ + if (IS_CTL_VP(vp)) { + MARK_INT_FAIL(CODA_READLINK_STATS); + return (ENOENT); + } + if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { + /* + * Symlink was cached. + */ + uiop->uio_rw = UIO_READ; + error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop); + if (error) + MARK_INT_FAIL(CODA_READLINK_STATS); + else + MARK_INT_SAT(CODA_READLINK_STATS); + return (error); + } + error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td != NULL ? + td->td_proc : NULL, &str, &len); + if (!error) { + uiop->uio_rw = UIO_READ; + error = uiomove(str, len, uiop); + if (coda_symlink_cache) { + cp->c_symlink = str; + cp->c_symlen = len; + cp->c_flags |= C_SYMLINK; + } else + CODA_FREE(str, len); + } + CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n", + error));); + return (error); } int coda_fsync(struct vop_fsync_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - struct thread *td = ap->a_td; -/* locals */ - struct vnode *convp = cp->c_ovp; - int error; - - MARK_ENTRY(CODA_FSYNC_STATS); - - /* Check for fsync on an unmounting object */ - /* - * XXX: Is this comment true on FreeBSD? It seems likely, since - * unmounting is fairly non-atomic. - * - * The NetBSD kernel, in it's infinite wisdom, can try to fsync - * after an unmount has been initiated. This is a Bad Thing, - * which we have to avoid. Not a legitimate failure for stats. - */ - if (IS_UNMOUNTING(cp)) { - return(ENODEV); - } - - /* Check for fsync of control object. */ - if (IS_CTL_VP(vp)) { - MARK_INT_SAT(CODA_FSYNC_STATS); - return(0); - } - - if (convp) { - vn_lock(convp, LK_EXCLUSIVE | LK_RETRY); - VOP_FSYNC(convp, MNT_WAIT, td); - VOP_UNLOCK(convp, 0); - } - - /* - * We see fsyncs with usecount == 1 then usecount == 0. - * For now we ignore them. - */ - /* - VI_LOCK(vp); - if (!vp->v_usecount) { - printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n", - vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING); - } - VI_UNLOCK(vp); - */ - - /* - * We can expect fsync on any vnode at all if venus is purging it. - * Venus can't very well answer the fsync request, now can it? - * Hopefully, it won't have to, because hopefully, venus preserves - * the (possibly untrue) invariant that it never purges an open - * vnode. Hopefully. - */ - if (cp->c_flags & C_PURGING) { - return(0); - } - - /* needs research */ - return 0; - error = venus_fsync(vtomi(vp), &cp->c_fid, td->td_proc); - - CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); ); - return(error); + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + struct thread *td = ap->a_td; + /* locals */ + struct vnode *convp = cp->c_ovp; + int error; + + MARK_ENTRY(CODA_FSYNC_STATS); + + /* + * Check for fsync on an unmounting object. + * + * XXX: Is this comment true on FreeBSD? It seems likely, since + * unmounting is fairly non-atomic. + * + * The NetBSD kernel, in it's infinite wisdom, can try to fsync after + * an unmount has been initiated. This is a Bad Thing, which we have + * to avoid. Not a legitimate failure for stats. + */ + if (IS_UNMOUNTING(cp)) + return (ENODEV); + + /* + * Check for fsync of control object. + */ + if (IS_CTL_VP(vp)) { + MARK_INT_SAT(CODA_FSYNC_STATS); + return (0); + } + if (convp != NULL) { + vn_lock(convp, LK_EXCLUSIVE | LK_RETRY); + VOP_FSYNC(convp, MNT_WAIT, td); + VOP_UNLOCK(convp, 0); + } + + /* + * We see fsyncs with usecount == 1 then usecount == 0. For now we + * ignore them. + */ +#if 0 + VI_LOCK(vp); + if (!vp->v_usecount) { + printf("coda_fsync on vnode %p with %d usecount. " + "c_flags = %x (%x)\n", vp, vp->v_usecount, cp->c_flags, + cp->c_flags&C_PURGING); + } + VI_UNLOCK(vp); +#endif + + /* + * We can expect fsync on any vnode at all if venus is purging it. + * Venus can't very well answer the fsync request, now can it? + * Hopefully, it won't have to, because hopefully, venus preserves + * the (possibly untrue) invariant that it never purges an open + * vnode. Hopefully. + */ + if (cp->c_flags & C_PURGING) + return (0); + + /* XXX: needs research */ + return (0); + error = venus_fsync(vtomi(vp), &cp->c_fid, td->td_proc); + CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n", error));); + return (error); } int coda_inactive(struct vop_inactive_args *ap) { - /* XXX - at the moment, inactive doesn't look at cred, and doesn't - have a proc pointer. Oops. */ -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - struct ucred *cred __attribute__((unused)) = NULL; - struct thread *td __attribute__((unused)) = curthread; -/* upcall decl */ -/* locals */ - - /* We don't need to send inactive to venus - DCS */ - MARK_ENTRY(CODA_INACTIVE_STATS); - - CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %s, vfsp %p\n", - coda_f2s(&cp->c_fid), vp->v_mount));) - - vp->v_object = NULL; - - /* If an array has been allocated to hold the symlink, deallocate it */ - if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { - if (cp->c_symlink == NULL) - panic("coda_inactive: null symlink pointer in cnode"); - - CODA_FREE(cp->c_symlink, cp->c_symlen); - cp->c_flags &= ~C_SYMLINK; - cp->c_symlen = 0; - } - - /* Remove it from the table so it can't be found. */ - coda_unsave(cp); - if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) { - myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp)); - panic("badness in coda_inactive\n"); - } - - if (IS_UNMOUNTING(cp)) { + /* + * XXX - at the moment, inactive doesn't look at cred, and doesn't + * have a proc pointer. Oops. + */ + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + struct ucred *cred __attribute__((unused)) = NULL; + struct thread *td __attribute__((unused)) = curthread; + /* upcall decl */ + /* locals */ + + /* + * We don't need to send inactive to venus - DCS. + */ + MARK_ENTRY(CODA_INACTIVE_STATS); + CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %s, vfsp %p\n", + coda_f2s(&cp->c_fid), vp->v_mount));); + vp->v_object = NULL; + + /* + * If an array has been allocated to hold the symlink, deallocate it. + */ + if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { + if (cp->c_symlink == NULL) + panic("coda_inactive: null symlink pointer in cnode"); + CODA_FREE(cp->c_symlink, cp->c_symlen); + cp->c_flags &= ~C_SYMLINK; + cp->c_symlen = 0; + } + + /* + * Remove it from the table so it can't be found. + */ + coda_unsave(cp); + if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) { + myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p " + "wasn't dying\n", vp)); + panic("badness in coda_inactive\n"); + } + if (IS_UNMOUNTING(cp)) { #ifdef DEBUG - printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vrefcnt(vp), vp, cp); - if (cp->c_ovp != NULL) - printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n", - vrefcnt(vp), vp, cp); + printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", + vrefcnt(vp), vp, cp); + if (cp->c_ovp != NULL) + printf("coda_inactive: cp->ovp != NULL use %d: vp " + "%p, cp %p\n", vrefcnt(vp), vp, cp); #endif - } else { + } else { #ifdef OLD_DIAGNOSTIC - if (vrefcnt(CTOV(cp))) { - panic("coda_inactive: nonzero reference count"); - } - if (cp->c_ovp != NULL) { - panic("coda_inactive: cp->ovp != NULL"); - } + if (vrefcnt(CTOV(cp))) + panic("coda_inactive: nonzero reference count"); + if (cp->c_ovp != NULL) + panic("coda_inactive: cp->ovp != NULL"); #endif - vgone(vp); - } - - MARK_INT_SAT(CODA_INACTIVE_STATS); - return(0); + vgone(vp); + } + MARK_INT_SAT(CODA_INACTIVE_STATS); + return (0); } /* * Remote filesystem operations having to do with directory manipulation. */ -/* +/* * In FreeBSD, lookup returns the vnode locked. */ int coda_lookup(struct vop_lookup_args *ap) { -/* true args */ - struct vnode *dvp = ap->a_dvp; - struct cnode *dcp = VTOC(dvp); - struct vnode **vpp = ap->a_vpp; - /* - * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest - * of the string to xlate, and that we must try to get at least - * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I - * could be wrong. - */ - struct componentname *cnp = ap->a_cnp; - struct ucred *cred = cnp->cn_cred; - struct thread *td = cnp->cn_thread; -/* locals */ - struct cnode *cp; - const char *nm = cnp->cn_nameptr; - int len = cnp->cn_namelen; - CodaFid VFid; - int vtype; - int error = 0; - - MARK_ENTRY(CODA_LOOKUP_STATS); - - CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %s\n", - nm, coda_f2s(&dcp->c_fid)));); - - /* Check for lookup of control object. */ - if (IS_CTL_NAME(dvp, nm, len)) { - *vpp = coda_ctlvp; - vref(*vpp); - MARK_INT_SAT(CODA_LOOKUP_STATS); - goto exit; - } - - if (len+1 > CODA_MAXNAMLEN) { - MARK_INT_FAIL(CODA_LOOKUP_STATS); - - CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %s (%s)\n", - coda_f2s(&dcp->c_fid), nm));); - *vpp = (struct vnode *)0; - error = EINVAL; - goto exit; - } - /* First try to look the file up in the cfs name cache */ - /* lock the parent vnode? */ - cp = coda_nc_lookup(dcp, nm, len, cred); - if (cp) { - *vpp = CTOV(cp); - vref(*vpp); - CODADEBUG(CODA_LOOKUP, - myprintf(("lookup result %d vpp %p\n",error,*vpp));) - } else { - - /* The name wasn't cached, so we need to contact Venus */ - error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc, &VFid, &vtype); - - if (error) { - MARK_INT_FAIL(CODA_LOOKUP_STATS); + /* true args */ + struct vnode *dvp = ap->a_dvp; + struct cnode *dcp = VTOC(dvp); + struct vnode **vpp = ap->a_vpp; + /* + * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest of + * the string to xlate, and that we must try to get at least + * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I + * could be wrong. + */ + struct componentname *cnp = ap->a_cnp; + struct ucred *cred = cnp->cn_cred; + struct thread *td = cnp->cn_thread; + /* locals */ + struct cnode *cp; + const char *nm = cnp->cn_nameptr; + int len = cnp->cn_namelen; + CodaFid VFid; + int vtype; + int error = 0; + + MARK_ENTRY(CODA_LOOKUP_STATS); + CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %s\n", nm, + coda_f2s(&dcp->c_fid)));); + + /* + * Check for lookup of control object. + */ + if (IS_CTL_NAME(dvp, nm, len)) { + *vpp = coda_ctlvp; + vref(*vpp); + MARK_INT_SAT(CODA_LOOKUP_STATS); + goto exit; + } + if (len+1 > CODA_MAXNAMLEN) { + MARK_INT_FAIL(CODA_LOOKUP_STATS); + CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, " + "%s (%s)\n", coda_f2s(&dcp->c_fid), nm));); + *vpp = NULL; + error = EINVAL; + goto exit; + } - CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %s (%s)%d\n", - coda_f2s(&dcp->c_fid), nm, error));) - *vpp = (struct vnode *)0; + /* + * First try to look the file up in the cfs name cache. + * + * XXX: lock the parent vnode? + */ + cp = coda_nc_lookup(dcp, nm, len, cred); + if (cp) { + *vpp = CTOV(cp); + vref(*vpp); + CODADEBUG(CODA_LOOKUP, myprintf(("lookup result %d vpp %p\n", + error,*vpp));); } else { - MARK_INT_SAT(CODA_LOOKUP_STATS); - CODADEBUG(CODA_LOOKUP, - myprintf(("lookup: %s type %o result %d\n", - coda_f2s(&VFid), vtype, error)); ) - cp = make_coda_node(&VFid, dvp->v_mount, vtype); - *vpp = CTOV(cp); - - /* enter the new vnode in the Name Cache only if the top bit isn't set */ - /* And don't enter a new vnode for an invalid one! */ - if (!(vtype & CODA_NOCACHE)) - coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); + /* + * The name wasn't cached, so we need to contact Venus. + */ + error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, + td->td_proc, &VFid, &vtype); + if (error) { + MARK_INT_FAIL(CODA_LOOKUP_STATS); + CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on " + "%s (%s)%d\n", coda_f2s(&dcp->c_fid), nm, + error));); + *vpp = NULL; + } else { + MARK_INT_SAT(CODA_LOOKUP_STATS); + CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s type %o " + "result %d\n", coda_f2s(&VFid), vtype, error));); + cp = make_coda_node(&VFid, dvp->v_mount, vtype); + *vpp = CTOV(cp); + + /* + * Enter the new vnode in the Name Cache only if the + * top bit isn't set. + * + * And don't enter a new vnode for an invalid one! + */ + if (!(vtype & CODA_NOCACHE)) + coda_nc_enter(VTOC(dvp), nm, len, cred, + VTOC(*vpp)); + } } - } - - exit: - /* - * If we are creating, and this was the last name to be looked up, - * and the error was ENOENT, then there really shouldn't be an - * error and we can make the leaf NULL and return success. Since - * this is supposed to work under Mach as well as FreeBSD, we're - * leaving this fn wrapped. We also must tell lookup/namei that - * we need to save the last component of the name. (Create will - * have to free the name buffer later...lucky us...) - */ - if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME)) - && (cnp->cn_flags & ISLASTCN) - && (error == ENOENT)) - { - error = EJUSTRETURN; - cnp->cn_flags |= SAVENAME; - *ap->a_vpp = NULL; - } - - /* - * If we are removing, and we are at the last element, and we - * found it, then we need to keep the name around so that the - * removal will go ahead as planned. Unfortunately, this will - * probably also lock the to-be-removed vnode, which may or may - * not be a good idea. I'll have to look at the bits of - * coda_remove to make sure. We'll only save the name if we did in - * fact find the name, otherwise coda_remove won't have a chance - * to free the pathname. - */ - if ((cnp->cn_nameiop == DELETE) - && (cnp->cn_flags & ISLASTCN) - && !error) - { - cnp->cn_flags |= SAVENAME; - } - - /* - * If the lookup went well, we need to (potentially?) unlock the - * parent, and lock the child. We are only responsible for - * checking to see if the parent is supposed to be unlocked before - * we return. We must always lock the child (provided there is - * one, and (the parent isn't locked or it isn't the same as the - * parent.) Simple, huh? We can never leave the parent locked unless - * we are ISLASTCN - */ - if (!error || (error == EJUSTRETURN)) { - if (cnp->cn_flags & ISDOTDOT) { - if ((error = VOP_UNLOCK(dvp, 0))) { - return error; - } - /* - * The parent is unlocked. As long as there is a child, - * lock it without bothering to check anything else. - */ - if (*ap->a_vpp) { - vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY); - } - vn_lock(dvp, LK_RETRY|LK_EXCLUSIVE); +exit: + /* + * If we are creating, and this was the last name to be looked up, + * and the error was ENOENT, then there really shouldn't be an error + * and we can make the leaf NULL and return success. Since this is + * supposed to work under Mach as well as FreeBSD, we're leaving this + * fn wrapped. We also must tell lookup/namei that we need to save + * the last component of the name. (Create will have to free the + * name buffer later...lucky us...). + */ + if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME)) + && (cnp->cn_flags & ISLASTCN) && (error == ENOENT)) { + error = EJUSTRETURN; + cnp->cn_flags |= SAVENAME; + *ap->a_vpp = NULL; + } + + /* + * If we are removing, and we are at the last element, and we found + * it, then we need to keep the name around so that the removal will + * go ahead as planned. Unfortunately, this will probably also lock + * the to-be-removed vnode, which may or may not be a good idea. + * I'll have to look at the bits of coda_remove to make sure. We'll + * only save the name if we did in fact find the name, otherwise + * coda_remove won't have a chance to free the pathname. + */ + if ((cnp->cn_nameiop == DELETE) && (cnp->cn_flags & ISLASTCN) + && !error) + cnp->cn_flags |= SAVENAME; + + /* + * If the lookup went well, we need to (potentially?) unlock the + * parent, and lock the child. We are only responsible for checking + * to see if the parent is supposed to be unlocked before we return. + * We must always lock the child (provided there is one, and (the + * parent isn't locked or it isn't the same as the parent.) Simple, + * huh? We can never leave the parent locked unless we are ISLASTCN. + */ + if (!error || (error == EJUSTRETURN)) { + if (cnp->cn_flags & ISDOTDOT) { + VOP_UNLOCK(dvp, 0); + /* + * The parent is unlocked. As long as there is a + * child, lock it without bothering to check anything + * else. + */ + if (*ap->a_vpp) + vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY); + vn_lock(dvp, LK_RETRY|LK_EXCLUSIVE); + } else { + /* + * The parent is locked, and may be the same as the + * child. If different, go ahead and lock it. + */ + if (*ap->a_vpp && (*ap->a_vpp != dvp)) + vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY); + } } else { - /* The parent is locked, and may be the same as the child */ - if (*ap->a_vpp && (*ap->a_vpp != dvp)) { - /* Different, go ahead and lock it. */ - vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY); - } + /* + * If the lookup failed, we need to ensure that the leaf is + * NULL. + * + * Don't change any locking? + */ + *ap->a_vpp = NULL; } - } else { - /* If the lookup failed, we need to ensure that the leaf is NULL */ - /* Don't change any locking? */ - *ap->a_vpp = NULL; - } - return(error); + return (error); } /*ARGSUSED*/ int coda_create(struct vop_create_args *ap) { -/* true args */ - struct vnode *dvp = ap->a_dvp; - struct cnode *dcp = VTOC(dvp); - struct vattr *va = ap->a_vap; - int exclusive = 1; - int mode = ap->a_vap->va_mode; - struct vnode **vpp = ap->a_vpp; - struct componentname *cnp = ap->a_cnp; - struct ucred *cred = cnp->cn_cred; - struct thread *td = cnp->cn_thread; -/* locals */ - int error; - struct cnode *cp; - const char *nm = cnp->cn_nameptr; - int len = cnp->cn_namelen; - CodaFid VFid; - struct vattr attr; - - MARK_ENTRY(CODA_CREATE_STATS); - - /* All creates are exclusive XXX */ - /* I'm assuming the 'mode' argument is the file mode bits XXX */ - - /* Check for create of control object. */ - if (IS_CTL_NAME(dvp, nm, len)) { - *vpp = (struct vnode *)0; - MARK_INT_FAIL(CODA_CREATE_STATS); - return(EACCES); - } - - error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td->td_proc, &VFid, &attr); - - if (!error) { - - /* If this is an exclusive create, panic if the file already exists. */ - /* Venus should have detected the file and reported EEXIST. */ - - if ((exclusive == 1) && - (coda_find(&VFid) != NULL)) - panic("cnode existed for newly created file!"); - - cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type); - *vpp = CTOV(cp); - - /* Update va to reflect the new attributes. */ - (*va) = attr; - - /* Update the attribute cache and mark it as valid */ - if (coda_attr_cache) { - VTOC(*vpp)->c_vattr = attr; - VTOC(*vpp)->c_flags |= C_VATTR; + /* true args */ + struct vnode *dvp = ap->a_dvp; + struct cnode *dcp = VTOC(dvp); + struct vattr *va = ap->a_vap; + int exclusive = 1; + int mode = ap->a_vap->va_mode; + struct vnode **vpp = ap->a_vpp; + struct componentname *cnp = ap->a_cnp; + struct ucred *cred = cnp->cn_cred; + struct thread *td = cnp->cn_thread; + /* locals */ + int error; + struct cnode *cp; + const char *nm = cnp->cn_nameptr; + int len = cnp->cn_namelen; + CodaFid VFid; + struct vattr attr; + + MARK_ENTRY(CODA_CREATE_STATS); + + /* + * All creates are exclusive XXX. + * + * I'm assuming the 'mode' argument is the file mode bits XXX. + * + * Check for create of control object. + */ + if (IS_CTL_NAME(dvp, nm, len)) { + *vpp = (struct vnode *)0; + MARK_INT_FAIL(CODA_CREATE_STATS); + return (EACCES); } - - /* Invalidate the parent's attr cache, the modification time has changed */ - VTOC(dvp)->c_flags &= ~C_VATTR; - - /* enter the new vnode in the Name Cache */ - coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); - - CODADEBUG(CODA_CREATE, - myprintf(("create: %s, result %d\n", - coda_f2s(&VFid), error)); ) - } else { - *vpp = (struct vnode *)0; - CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));) - } - - if (!error) { - if (cnp->cn_flags & LOCKLEAF) { - vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY); + error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, + mode, va, cred, td->td_proc, &VFid, &attr); + if (!error) { + /* + * If this is an exclusive create, panic if the file already + * exists. + * + * Venus should have detected the file and reported EEXIST. + */ + if ((exclusive == 1) && (coda_find(&VFid) != NULL)) + panic("cnode existed for newly created file!"); + cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type); + *vpp = CTOV(cp); + + /* + * Update va to reflect the new attributes. + */ + (*va) = attr; + + /* + * Update the attribute cache and mark it as valid. + */ + if (coda_attr_cache) { + VTOC(*vpp)->c_vattr = attr; + VTOC(*vpp)->c_flags |= C_VATTR; + } + + /* + * Invalidate the parent's attr cache, the modification time + * has changed. + */ + VTOC(dvp)->c_flags &= ~C_VATTR; + + /* + * Enter the new vnode in the Name Cache. + */ + coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); + CODADEBUG(CODA_CREATE, myprintf(("create: %s, result %d\n", + coda_f2s(&VFid), error));); + } else { + *vpp = (struct vnode *)0; + CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", + error));); } + if (!error) { + if (cnp->cn_flags & LOCKLEAF) + vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY); #ifdef OLD_DIAGNOSTIC - else { - printf("coda_create: LOCKLEAF not set!\n"); - } + else + printf("coda_create: LOCKLEAF not set!\n"); #endif - } - return(error); + } + return (error); } int coda_remove(struct vop_remove_args *ap) { -/* true args */ - struct vnode *dvp = ap->a_dvp; - struct cnode *cp = VTOC(dvp); - struct componentname *cnp = ap->a_cnp; - struct ucred *cred = cnp->cn_cred; - struct thread *td = cnp->cn_thread; -/* locals */ - int error; - const char *nm = cnp->cn_nameptr; - int len = cnp->cn_namelen; - struct cnode *tp; - - MARK_ENTRY(CODA_REMOVE_STATS); - - CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %s\n", - nm, coda_f2s(&cp->c_fid)));); - /* Remove the file's entry from the CODA Name Cache */ - /* We're being conservative here, it might be that this person - * doesn't really have sufficient access to delete the file - * but we feel zapping the entry won't really hurt anyone -- dcs - */ - /* I'm gonna go out on a limb here. If a file and a hardlink to it - * exist, and one is removed, the link count on the other will be - * off by 1. We could either invalidate the attrs if cached, or - * fix them. I'll try to fix them. DCS 11/8/94 - */ - tp = coda_nc_lookup(VTOC(dvp), nm, len, cred); - if (tp) { - if (VALID_VATTR(tp)) { /* If attrs are cached */ - if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */ - tp->c_vattr.va_nlink--; - } + /* true args */ + struct vnode *dvp = ap->a_dvp; + struct cnode *cp = VTOC(dvp); + struct componentname *cnp = ap->a_cnp; + struct ucred *cred = cnp->cn_cred; + struct thread *td = cnp->cn_thread; + /* locals */ + int error; + const char *nm = cnp->cn_nameptr; + int len = cnp->cn_namelen; + struct cnode *tp; + + MARK_ENTRY(CODA_REMOVE_STATS); + CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %s\n", nm, + coda_f2s(&cp->c_fid)));); + + /* + * Remove the file's entry from the CODA Name Cache. + * + * We're being conservative here, it might be that this person + * doesn't really have sufficient access to delete the file but we + * feel zapping the entry won't really hurt anyone -- dcs. + * + * I'm gonna go out on a limb here. If a file and a hardlink to it + * exist, and one is removed, the link count on the other will be off + * by 1. We could either invalidate the attrs if cached, orfix them. + * I'll try to fix them. DCS 11/8/94 + */ + tp = coda_nc_lookup(VTOC(dvp), nm, len, cred); + if (tp!= NULL) { + if (VALID_VATTR(tp)) { + if (tp->c_vattr.va_nlink > 1) + tp->c_vattr.va_nlink--; + } + coda_nc_zapfile(VTOC(dvp), nm, len); } - - coda_nc_zapfile(VTOC(dvp), nm, len); - /* No need to flush it if it doesn't exist! */ - } - /* Invalidate the parent's attr cache, the modification time has changed */ - VTOC(dvp)->c_flags &= ~C_VATTR; - - /* Check for remove of control object. */ - if (IS_CTL_NAME(dvp, nm, len)) { - MARK_INT_FAIL(CODA_REMOVE_STATS); - return(ENOENT); - } - error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td->td_proc); - - CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); ) + /* + * Invalidate the parent's attr cache, the modification time has + * changed. + */ + VTOC(dvp)->c_flags &= ~C_VATTR; - return(error); + /* + * Check for remove of control object. + */ + if (IS_CTL_NAME(dvp, nm, len)) { + MARK_INT_FAIL(CODA_REMOVE_STATS); + return (ENOENT); + } + error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, + td->td_proc); + CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error));); + return (error); } int coda_link(struct vop_link_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - struct vnode *tdvp = ap->a_tdvp; - struct cnode *tdcp = VTOC(tdvp); - struct componentname *cnp = ap->a_cnp; - struct ucred *cred = cnp->cn_cred; - struct thread *td = cnp->cn_thread; -/* locals */ - int error; - const char *nm = cnp->cn_nameptr; - int len = cnp->cn_namelen; - - MARK_ENTRY(CODA_LINK_STATS); - - if (codadebug & CODADBGMSK(CODA_LINK)) { - myprintf(("nb_link: vp fid: %s\n", - coda_f2s(&cp->c_fid))); - myprintf(("nb_link: tdvp fid: %s)\n", - coda_f2s(&tdcp->c_fid))); - } - if (codadebug & CODADBGMSK(CODA_LINK)) { - myprintf(("link: vp fid: %s\n", - coda_f2s(&cp->c_fid))); - myprintf(("link: tdvp fid: %s\n", - coda_f2s(&tdcp->c_fid))); - } - - /* Check for link to/from control object. */ - if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) { - MARK_INT_FAIL(CODA_LINK_STATS); - return(EACCES); - } - - error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td->td_proc); - - /* Invalidate the parent's attr cache, the modification time has changed */ - VTOC(tdvp)->c_flags &= ~C_VATTR; - VTOC(vp)->c_flags &= ~C_VATTR; - - CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); ) - - return(error); + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + struct vnode *tdvp = ap->a_tdvp; + struct cnode *tdcp = VTOC(tdvp); + struct componentname *cnp = ap->a_cnp; + struct ucred *cred = cnp->cn_cred; + struct thread *td = cnp->cn_thread; + /* locals */ + int error; + const char *nm = cnp->cn_nameptr; + int len = cnp->cn_namelen; + + MARK_ENTRY(CODA_LINK_STATS); + + if (codadebug & CODADBGMSK(CODA_LINK)) { + myprintf(("nb_link: vp fid: %s\n", coda_f2s(&cp->c_fid))); + myprintf(("nb_link: tdvp fid: %s)\n", + coda_f2s(&tdcp->c_fid))); + } + if (codadebug & CODADBGMSK(CODA_LINK)) { + myprintf(("link: vp fid: %s\n", coda_f2s(&cp->c_fid))); + myprintf(("link: tdvp fid: %s\n", coda_f2s(&tdcp->c_fid))); + } + + /* + * Check for link to/from control object. + */ + if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) { + MARK_INT_FAIL(CODA_LINK_STATS); + return (EACCES); + } + error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, + cred, td->td_proc); + + /* + * Invalidate the parent's attr cache, the modification time has + * changed. + */ + VTOC(tdvp)->c_flags &= ~C_VATTR; + VTOC(vp)->c_flags &= ~C_VATTR; + CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error));); + return (error); } int coda_rename(struct vop_rename_args *ap) { -/* true args */ - struct vnode *odvp = ap->a_fdvp; - struct cnode *odcp = VTOC(odvp); - struct componentname *fcnp = ap->a_fcnp; - struct vnode *ndvp = ap->a_tdvp; - struct cnode *ndcp = VTOC(ndvp); - struct componentname *tcnp = ap->a_tcnp; - struct ucred *cred = fcnp->cn_cred; - struct thread *td = fcnp->cn_thread; -/* true args */ - int error; - const char *fnm = fcnp->cn_nameptr; - int flen = fcnp->cn_namelen; - const char *tnm = tcnp->cn_nameptr; - int tlen = tcnp->cn_namelen; - - MARK_ENTRY(CODA_RENAME_STATS); - - /* Hmmm. The vnodes are already looked up. Perhaps they are locked? - This could be Bad. XXX */ + /* true args */ + struct vnode *odvp = ap->a_fdvp; + struct cnode *odcp = VTOC(odvp); + struct componentname *fcnp = ap->a_fcnp; + struct vnode *ndvp = ap->a_tdvp; + struct cnode *ndcp = VTOC(ndvp); + struct componentname *tcnp = ap->a_tcnp; + struct ucred *cred = fcnp->cn_cred; + struct thread *td = fcnp->cn_thread; + /* true args */ + int error; + const char *fnm = fcnp->cn_nameptr; + int flen = fcnp->cn_namelen; + const char *tnm = tcnp->cn_nameptr; + int tlen = tcnp->cn_namelen; + + MARK_ENTRY(CODA_RENAME_STATS); + + /* + * Hmmm. The vnodes are already looked up. Perhaps they are locked? + * This could be Bad. XXX + */ #ifdef OLD_DIAGNOSTIC - if ((fcnp->cn_cred != tcnp->cn_cred) - || (fcnp->cn_thread != tcnp->cn_thread)) - { - panic("coda_rename: component names don't agree"); - } + if ((fcnp->cn_cred != tcnp->cn_cred) || + (fcnp->cn_thread != tcnp->cn_thread)) + panic("coda_rename: component names don't agree"); #endif - /* Check for rename involving control object. */ - if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) { - MARK_INT_FAIL(CODA_RENAME_STATS); - return(EACCES); - } - - /* Problem with moving directories -- need to flush entry for .. */ - if (odvp != ndvp) { - struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred); - if (ovcp) { - struct vnode *ovp = CTOV(ovcp); - if ((ovp) && - (ovp->v_type == VDIR)) /* If it's a directory */ - coda_nc_zapfile(VTOC(ovp),"..", 2); + /* + * Check for rename involving control object. + */ + if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) { + MARK_INT_FAIL(CODA_RENAME_STATS); + return (EACCES); } - } - - /* Remove the entries for both source and target files */ - coda_nc_zapfile(VTOC(odvp), fnm, flen); - coda_nc_zapfile(VTOC(ndvp), tnm, tlen); - - /* Invalidate the parent's attr cache, the modification time has changed */ - VTOC(odvp)->c_flags &= ~C_VATTR; - VTOC(ndvp)->c_flags &= ~C_VATTR; - - if (flen+1 > CODA_MAXNAMLEN) { - MARK_INT_FAIL(CODA_RENAME_STATS); - error = EINVAL; - goto exit; - } - - if (tlen+1 > CODA_MAXNAMLEN) { - MARK_INT_FAIL(CODA_RENAME_STATS); - error = EINVAL; - goto exit; - } - - error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td->td_proc); - - exit: - CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));) - /* XXX - do we need to call cache pureg on the moved vnode? */ - cache_purge(ap->a_fvp); - - /* Release parents first, then children. */ - vrele(odvp); - if (ap->a_tvp) { - if (ap->a_tvp == ndvp) - vrele(ndvp); - else - vput(ndvp); - vput(ap->a_tvp); - } else - vput(ndvp); - vrele(ap->a_fvp); - return(error); + /* + * Problem with moving directories -- need to flush entry for .. + */ + if (odvp != ndvp) { + struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, + cred); + + if (ovcp) { + struct vnode *ovp = CTOV(ovcp); + + if ((ovp) && (ovp->v_type == VDIR)) + coda_nc_zapfile(VTOC(ovp),"..", 2); + } + } + + /* + * Remove the entries for both source and target files. + */ + coda_nc_zapfile(VTOC(odvp), fnm, flen); + coda_nc_zapfile(VTOC(ndvp), tnm, tlen); + + /* + * Invalidate the parent's attr cache, the modification time has + * changed. + */ + VTOC(odvp)->c_flags &= ~C_VATTR; + VTOC(ndvp)->c_flags &= ~C_VATTR; + if (flen+1 > CODA_MAXNAMLEN) { + MARK_INT_FAIL(CODA_RENAME_STATS); + error = EINVAL; + goto exit; + } + if (tlen+1 > CODA_MAXNAMLEN) { + MARK_INT_FAIL(CODA_RENAME_STATS); + error = EINVAL; + goto exit; + } + error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, + flen, tnm, tlen, cred, td->td_proc); +exit: + CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));); + + /* + * XXX - do we need to call cache pureg on the moved vnode? + */ + cache_purge(ap->a_fvp); + + /* + * Release parents first, then children. + */ + vrele(odvp); + if (ap->a_tvp) { + if (ap->a_tvp == ndvp) + vrele(ndvp); + else + vput(ndvp); + vput(ap->a_tvp); + } else + vput(ndvp); + vrele(ap->a_fvp); + return (error); } int coda_mkdir(struct vop_mkdir_args *ap) { -/* true args */ - struct vnode *dvp = ap->a_dvp; - struct cnode *dcp = VTOC(dvp); - struct componentname *cnp = ap->a_cnp; - register struct vattr *va = ap->a_vap; - struct vnode **vpp = ap->a_vpp; - struct ucred *cred = cnp->cn_cred; - struct thread *td = cnp->cn_thread; -/* locals */ - int error; - const char *nm = cnp->cn_nameptr; - int len = cnp->cn_namelen; - struct cnode *cp; - CodaFid VFid; - struct vattr ova; - - MARK_ENTRY(CODA_MKDIR_STATS); - - /* Check for mkdir of target object. */ - if (IS_CTL_NAME(dvp, nm, len)) { - *vpp = (struct vnode *)0; - MARK_INT_FAIL(CODA_MKDIR_STATS); - return(EACCES); - } - - if (len+1 > CODA_MAXNAMLEN) { - *vpp = (struct vnode *)0; - MARK_INT_FAIL(CODA_MKDIR_STATS); - return(EACCES); - } - - error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td->td_proc, &VFid, &ova); - - if (!error) { - if (coda_find(&VFid) != NULL) - panic("cnode existed for newly created directory!"); - - - cp = make_coda_node(&VFid, dvp->v_mount, va->va_type); - *vpp = CTOV(cp); - - /* enter the new vnode in the Name Cache */ - coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); - - /* as a side effect, enter "." and ".." for the directory */ - coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp)); - coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp)); - - if (coda_attr_cache) { - VTOC(*vpp)->c_vattr = ova; /* update the attr cache */ - VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */ + /* true args */ + struct vnode *dvp = ap->a_dvp; + struct cnode *dcp = VTOC(dvp); + struct componentname *cnp = ap->a_cnp; + struct vattr *va = ap->a_vap; + struct vnode **vpp = ap->a_vpp; + struct ucred *cred = cnp->cn_cred; + struct thread *td = cnp->cn_thread; + /* locals */ + int error; + const char *nm = cnp->cn_nameptr; + int len = cnp->cn_namelen; + struct cnode *cp; + CodaFid VFid; + struct vattr ova; + + MARK_ENTRY(CODA_MKDIR_STATS); + + /* + * Check for mkdir of target object. + */ + if (IS_CTL_NAME(dvp, nm, len)) { + *vpp = (struct vnode *)0; + MARK_INT_FAIL(CODA_MKDIR_STATS); + return (EACCES); } + if (len+1 > CODA_MAXNAMLEN) { + *vpp = (struct vnode *)0; + MARK_INT_FAIL(CODA_MKDIR_STATS); + return (EACCES); + } + error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, + td->td_proc, &VFid, &ova); + if (!error) { + if (coda_find(&VFid) != NULL) + panic("cnode existed for newly created directory!"); + cp = make_coda_node(&VFid, dvp->v_mount, va->va_type); + *vpp = CTOV(cp); + + /* + * Enter the new vnode in the Name Cache. + */ + coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); - /* Invalidate the parent's attr cache, the modification time has changed */ - VTOC(dvp)->c_flags &= ~C_VATTR; - - vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY); - - CODADEBUG( CODA_MKDIR, myprintf(("mkdir: %s result %d\n", - coda_f2s(&VFid), error)); ) + /* + * As a side effect, enter "." and ".." for the directory. + */ + coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp)); + coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp)); + if (coda_attr_cache) { + /* + * Update the attr cache and mark as valid. + */ + VTOC(*vpp)->c_vattr = ova; + VTOC(*vpp)->c_flags |= C_VATTR; + } + + /* + * Invalidate the parent's attr cache, the modification time + * has changed. + */ + VTOC(dvp)->c_flags &= ~C_VATTR; + vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY); + CODADEBUG( CODA_MKDIR, myprintf(("mkdir: %s result %d\n", + coda_f2s(&VFid), error));); } else { - *vpp = (struct vnode *)0; - CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));) - } - - return(error); + *vpp = NULL; + CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));); + } + return (error); } int coda_rmdir(struct vop_rmdir_args *ap) { -/* true args */ - struct vnode *dvp = ap->a_dvp; - struct cnode *dcp = VTOC(dvp); - struct componentname *cnp = ap->a_cnp; - struct ucred *cred = cnp->cn_cred; - struct thread *td = cnp->cn_thread; -/* true args */ - int error; - const char *nm = cnp->cn_nameptr; - int len = cnp->cn_namelen; - struct cnode *cp; - - MARK_ENTRY(CODA_RMDIR_STATS); - - /* Check for rmdir of control object. */ - if (IS_CTL_NAME(dvp, nm, len)) { - MARK_INT_FAIL(CODA_RMDIR_STATS); - return(ENOENT); - } - - /* We're being conservative here, it might be that this person - * doesn't really have sufficient access to delete the file - * but we feel zapping the entry won't really hurt anyone -- dcs - */ - /* - * As a side effect of the rmdir, remove any entries for children of - * the directory, especially "." and "..". - */ - cp = coda_nc_lookup(dcp, nm, len, cred); - if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL); - - /* Remove the file's entry from the CODA Name Cache */ - coda_nc_zapfile(dcp, nm, len); - - /* Invalidate the parent's attr cache, the modification time has changed */ - dcp->c_flags &= ~C_VATTR; - - error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc); - - CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); ) - - return(error); + /* true args */ + struct vnode *dvp = ap->a_dvp; + struct cnode *dcp = VTOC(dvp); + struct componentname *cnp = ap->a_cnp; + struct ucred *cred = cnp->cn_cred; + struct thread *td = cnp->cn_thread; + /* true args */ + int error; + const char *nm = cnp->cn_nameptr; + int len = cnp->cn_namelen; + struct cnode *cp; + + MARK_ENTRY(CODA_RMDIR_STATS); + + /* + * Check for rmdir of control object. + */ + if (IS_CTL_NAME(dvp, nm, len)) { + MARK_INT_FAIL(CODA_RMDIR_STATS); + return (ENOENT); + } + + /* + * We're being conservative here, it might be that this person + * doesn't really have sufficient access to delete the file but we + * feel zapping the entry won't really hurt anyone -- dcs + * + * As a side effect of the rmdir, remove any entries for children of + * the directory, especially "." and "..". + */ + cp = coda_nc_lookup(dcp, nm, len, cred); + if (cp) + coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL); + + /* + * Remove the file's entry from the CODA Name Cache. + */ + coda_nc_zapfile(dcp, nm, len); + + /* + * Invalidate the parent's attr cache, the modification time has + * changed. + */ + dcp->c_flags &= ~C_VATTR; + error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, + td->td_proc); + CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error));); + return (error); } int coda_symlink(struct vop_symlink_args *ap) { -/* true args */ - struct vnode *tdvp = ap->a_dvp; - struct cnode *tdcp = VTOC(tdvp); - struct componentname *cnp = ap->a_cnp; - struct vattr *tva = ap->a_vap; - char *path = ap->a_target; - struct ucred *cred = cnp->cn_cred; - struct thread *td = cnp->cn_thread; - struct vnode **vpp = ap->a_vpp; -/* locals */ - int error; - /* - * XXX I'm assuming the following things about coda_symlink's - * arguments: - * t(foo) is the new name/parent/etc being created. - * lname is the contents of the new symlink. - */ - char *nm = cnp->cn_nameptr; - int len = cnp->cn_namelen; - int plen = strlen(path); - - /* - * Here's the strategy for the moment: perform the symlink, then - * do a lookup to grab the resulting vnode. I know this requires - * two communications with Venus for a new sybolic link, but - * that's the way the ball bounces. I don't yet want to change - * the way the Mach symlink works. When Mach support is - * deprecated, we should change symlink so that the common case - * returns the resultant vnode in a vpp argument. - */ - - MARK_ENTRY(CODA_SYMLINK_STATS); - - /* Check for symlink of control object. */ - if (IS_CTL_NAME(tdvp, nm, len)) { - MARK_INT_FAIL(CODA_SYMLINK_STATS); - return(EACCES); - } - - if (plen+1 > CODA_MAXPATHLEN) { - MARK_INT_FAIL(CODA_SYMLINK_STATS); - return(EINVAL); - } - - if (len+1 > CODA_MAXNAMLEN) { - MARK_INT_FAIL(CODA_SYMLINK_STATS); - error = EINVAL; - goto exit; - } - - error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td->td_proc); - - /* Invalidate the parent's attr cache, the modification time has changed */ - tdcp->c_flags &= ~C_VATTR; - - if (error == 0) - error = VOP_LOOKUP(tdvp, vpp, cnp); - - exit: - CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); ) - return(error); + /* true args */ + struct vnode *tdvp = ap->a_dvp; + struct cnode *tdcp = VTOC(tdvp); + struct componentname *cnp = ap->a_cnp; + struct vattr *tva = ap->a_vap; + char *path = ap->a_target; + struct ucred *cred = cnp->cn_cred; + struct thread *td = cnp->cn_thread; + struct vnode **vpp = ap->a_vpp; + /* locals */ + int error; + + /*- + * XXX I'm assuming the following things about coda_symlink's + * arguments: + * t(foo) is the new name/parent/etc being created. + * lname is the contents of the new symlink. + */ + char *nm = cnp->cn_nameptr; + int len = cnp->cn_namelen; + int plen = strlen(path); + + /* + * Here's the strategy for the moment: perform the symlink, then do a + * lookup to grab the resulting vnode. I know this requires two + * communications with Venus for a new sybolic link, but that's the + * way the ball bounces. I don't yet want to change the way the Mach + * symlink works. When Mach support is deprecated, we should change + * symlink so that the common case returns the resultant vnode in a + * vpp argument. + */ + MARK_ENTRY(CODA_SYMLINK_STATS); + + /* + * Check for symlink of control object. + */ + if (IS_CTL_NAME(tdvp, nm, len)) { + MARK_INT_FAIL(CODA_SYMLINK_STATS); + return (EACCES); + } + if (plen+1 > CODA_MAXPATHLEN) { + MARK_INT_FAIL(CODA_SYMLINK_STATS); + return (EINVAL); + } + if (len+1 > CODA_MAXNAMLEN) { + MARK_INT_FAIL(CODA_SYMLINK_STATS); + error = EINVAL; + goto exit; + } + error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, + tva, cred, td->td_proc); + + /* + * Invalidate the parent's attr cache, the modification time has + * changed. + */ + tdcp->c_flags &= ~C_VATTR; + if (error == 0) + error = VOP_LOOKUP(tdvp, vpp, cnp); +exit: + CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error));); + return (error); } /* * Read directory entries. * - * XXXRW: This forwards the operator straight to the cache vnode using + * XXX: This forwards the operator straight to the cache vnode using * VOP_READDIR(), rather than calling venus_readdir(). Why? */ int coda_readdir(struct vop_readdir_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); - register struct uio *uiop = ap->a_uio; - struct ucred *cred = ap->a_cred; - int *eofflag = ap->a_eofflag; - u_long **cookies = ap->a_cookies; - int *ncookies = ap->a_ncookies; - struct thread *td = ap->a_uio->uio_td; -/* upcall decl */ -/* locals */ - int error = 0; - - MARK_ENTRY(CODA_READDIR_STATS); - - CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n", - (void *)uiop->uio_iov->iov_base, - uiop->uio_resid, - (long long)uiop->uio_offset, - uiop->uio_segflg)); ) - - /* Check for readdir of control object. */ - if (IS_CTL_VP(vp)) { - MARK_INT_FAIL(CODA_READDIR_STATS); - return(ENOENT); - } - - { - /* If directory is not already open do an "internal open" on it. */ + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + struct uio *uiop = ap->a_uio; + struct ucred *cred = ap->a_cred; + int *eofflag = ap->a_eofflag; + u_long **cookies = ap->a_cookies; + int *ncookies = ap->a_ncookies; + struct thread *td = ap->a_uio->uio_td; + /* upcall decl */ + /* locals */ + int error = 0; int opened_internally = 0; + + MARK_ENTRY(CODA_READDIR_STATS); + CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n", + (void *)uiop->uio_iov->iov_base, uiop->uio_resid, + (long long)uiop->uio_offset, uiop->uio_segflg));); + + /* + * Check for readdir of control object. + */ + if (IS_CTL_VP(vp)) { + MARK_INT_FAIL(CODA_READDIR_STATS); + return (ENOENT); + } + + /* + * If directory is not already open do an "internal open" on it. + * + * XXX: Why would this happen? For files, there's memory mapping, + * execution, and other kernel access paths such as ktrace. For + * directories, it is less clear. + */ if (cp->c_ovp == NULL) { - opened_internally = 1; - MARK_INT_GEN(CODA_OPEN_STATS); - error = VOP_OPEN(vp, FREAD, cred, td, NULL); - printf("coda_readdir: Internally Opening %p\n", vp); - if (error) { - printf("coda_readdir: VOP_OPEN on container failed %d\n", error); - return (error); - } + opened_internally = 1; + MARK_INT_GEN(CODA_OPEN_STATS); + error = VOP_OPEN(vp, FREAD, cred, td, NULL); + printf("coda_readdir: Internally Opening %p\n", vp); + if (error) { + printf("coda_readdir: VOP_OPEN on container failed " + "%d\n", error); + return (error); + } } - - /* Have UFS handle the call. */ - CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = %s, refcnt = %d\n", coda_f2s(&cp->c_fid), vp->v_usecount)); ) + + /* + * Have UFS handle the call. + */ + CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = %s, " + "refcnt = %d\n", coda_f2s(&cp->c_fid), vp->v_usecount));); vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY); error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies, - cookies); + cookies); VOP_UNLOCK(cp->c_ovp, 0); - if (error) - MARK_INT_FAIL(CODA_READDIR_STATS); + MARK_INT_FAIL(CODA_READDIR_STATS); else - MARK_INT_SAT(CODA_READDIR_STATS); - - /* Do an "internal close" if necessary. */ + MARK_INT_SAT(CODA_READDIR_STATS); + + /* + * Do an "internal close" if necessary. + */ if (opened_internally) { - MARK_INT_GEN(CODA_CLOSE_STATS); - (void)VOP_CLOSE(vp, FREAD, cred, td); + MARK_INT_GEN(CODA_CLOSE_STATS); + (void)VOP_CLOSE(vp, FREAD, cred, td); } - } - - return(error); + return (error); } int coda_reclaim(struct vop_reclaim_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); -/* upcall decl */ -/* locals */ - -/* - * Forced unmount/flush will let vnodes with non zero use be destroyed! - */ - ENTRY; - - if (IS_UNMOUNTING(cp)) { + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + /* upcall decl */ + /* locals */ + + /* + * Forced unmount/flush will let vnodes with non-zero use be + * destroyed! + */ + ENTRY; + + if (IS_UNMOUNTING(cp)) { #ifdef DEBUG - if (VTOC(vp)->c_ovp) { - if (IS_UNMOUNTING(cp)) - printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp); - } + if (VTOC(vp)->c_ovp) { + if (IS_UNMOUNTING(cp)) + printf("coda_reclaim: c_ovp not void: vp " + "%p, cp %p\n", vp, cp); + } #endif - } else { + } else { #ifdef OLD_DIAGNOSTIC - if (vrefcnt(vp) != 0) - print("coda_reclaim: pushing active %p\n", vp); - if (VTOC(vp)->c_ovp) { - panic("coda_reclaim: c_ovp not void"); - } + if (vrefcnt(vp) != 0) + print("coda_reclaim: pushing active %p\n", vp); + if (VTOC(vp)->c_ovp) + panic("coda_reclaim: c_ovp not void"); #endif - } - cache_purge(vp); - coda_free(VTOC(vp)); - vp->v_data = NULL; - vp->v_object = NULL; - return (0); + } + cache_purge(vp); + coda_free(VTOC(vp)); + vp->v_data = NULL; + vp->v_object = NULL; + return (0); } int coda_lock(struct vop_lock1_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); -/* upcall decl */ -/* locals */ - - ENTRY; - - if ((ap->a_flags & LK_INTERLOCK) == 0) { - VI_LOCK(vp); - ap->a_flags |= LK_INTERLOCK; - } - - if (coda_lockdebug) { - myprintf(("Attempting lock on %s\n", - coda_f2s(&cp->c_fid))); - } - - return (vop_stdlock(ap)); + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + /* upcall decl */ + /* locals */ + + ENTRY; + if ((ap->a_flags & LK_INTERLOCK) == 0) { + VI_LOCK(vp); + ap->a_flags |= LK_INTERLOCK; + } + if (coda_lockdebug) + myprintf(("Attempting lock on %s\n", coda_f2s(&cp->c_fid))); + return (vop_stdlock(ap)); } int coda_unlock(struct vop_unlock_args *ap) { -/* true args */ - struct vnode *vp = ap->a_vp; - struct cnode *cp = VTOC(vp); -/* upcall decl */ -/* locals */ - - ENTRY; - if (coda_lockdebug) { - myprintf(("Attempting unlock on %s\n", - coda_f2s(&cp->c_fid))); - } - - return (vop_stdunlock(ap)); + /* true args */ + struct vnode *vp = ap->a_vp; + struct cnode *cp = VTOC(vp); + /* upcall decl */ + /* locals */ + + ENTRY; + if (coda_lockdebug) + myprintf(("Attempting unlock on %s\n", + coda_f2s(&cp->c_fid))); + return (vop_stdunlock(ap)); } int coda_islocked(struct vop_islocked_args *ap) { -/* true args */ - ENTRY; + /* true args */ - return (vop_stdislocked(ap)); + ENTRY; + return (vop_stdislocked(ap)); } static void coda_print_vattr(struct vattr *attr) { - char *typestr; - - switch (attr->va_type) { - case VNON: - typestr = "VNON"; - break; - case VREG: - typestr = "VREG"; - break; - case VDIR: - typestr = "VDIR"; - break; - case VBLK: - typestr = "VBLK"; - break; - case VCHR: - typestr = "VCHR"; - break; - case VLNK: - typestr = "VLNK"; - break; - case VSOCK: - typestr = "VSCK"; - break; - case VFIFO: - typestr = "VFFO"; - break; - case VBAD: - typestr = "VBAD"; - break; - default: - typestr = "????"; - break; - } - - - myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n", - typestr, (int)attr->va_mode, (int)attr->va_uid, - (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev)); - - myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n", - (int)attr->va_fileid, (int)attr->va_nlink, - (int)attr->va_size, - (int)attr->va_blocksize,(int)attr->va_bytes)); - myprintf((" gen %ld flags %ld vaflags %d\n", - attr->va_gen, attr->va_flags, attr->va_vaflags)); - myprintf((" atime sec %d nsec %d\n", - (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec)); - myprintf((" mtime sec %d nsec %d\n", - (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec)); - myprintf((" ctime sec %d nsec %d\n", - (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec)); + char *typestr; + + switch (attr->va_type) { + case VNON: + typestr = "VNON"; + break; + + case VREG: + typestr = "VREG"; + break; + + case VDIR: + typestr = "VDIR"; + break; + + case VBLK: + typestr = "VBLK"; + break; + + case VCHR: + typestr = "VCHR"; + break; + + case VLNK: + typestr = "VLNK"; + break; + + case VSOCK: + typestr = "VSCK"; + break; + + case VFIFO: + typestr = "VFFO"; + break; + + case VBAD: + typestr = "VBAD"; + break; + + default: + typestr = "????"; + break; + } + myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n", + typestr, (int)attr->va_mode, (int)attr->va_uid, + (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev)); + myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n", + (int)attr->va_fileid, (int)attr->va_nlink, (int)attr->va_size, + (int)attr->va_blocksize,(int)attr->va_bytes)); + myprintf((" gen %ld flags %ld vaflags %d\n", attr->va_gen, + attr->va_flags, attr->va_vaflags)); + myprintf((" atime sec %d nsec %d\n", (int)attr->va_atime.tv_sec, + (int)attr->va_atime.tv_nsec)); + myprintf((" mtime sec %d nsec %d\n", (int)attr->va_mtime.tv_sec, + (int)attr->va_mtime.tv_nsec)); + myprintf((" ctime sec %d nsec %d\n", (int)attr->va_ctime.tv_sec, + (int)attr->va_ctime.tv_nsec)); } -/* How to print a ucred */ +/* + * How to print a ucred. + */ void coda_print_cred(struct ucred *cred) { - int i; myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid)); - for (i=0; i < cred->cr_ngroups; i++) myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i])); myprintf(("\n")); - } /* - * Return a vnode for the given fid. - * If no cnode exists for this fid create one and put it - * in a table hashed by coda_f2i(). If the cnode for - * this fid is already in the table return it (ref count is - * incremented by coda_find. The cnode will be flushed from the - * table when coda_inactive calls coda_unsave. + * Return a vnode for the given fid. If no cnode exists for this fid create + * one and put it in a table hashed by coda_f2i(). If the cnode for this fid + * is already in the table return it (ref count is incremented by coda_find. + * The cnode will be flushed from the table when coda_inactive calls + * coda_unsave. */ struct cnode * make_coda_node(CodaFid *fid, struct mount *vfsp, short type) { - struct cnode *cp; - int err; - - if ((cp = coda_find(fid)) == NULL) { - struct vnode *vp; - - cp = coda_alloc(); - cp->c_fid = *fid; - - err = getnewvnode("coda", vfsp, &coda_vnodeops, &vp); - if (err) { - panic("coda: getnewvnode returned error %d\n", err); - } - err = insmntque1(vp, vfsp, NULL, NULL); /* XXX: Too early for mpsafe fs */ - if (err != 0) - panic("coda: insmntque failed: error %d", err); - vp->v_data = cp; - vp->v_type = type; - cp->c_vnode = vp; - coda_save(cp); - - } else { - vref(CTOV(cp)); - } - - return cp; + struct cnode *cp; + int err; + + if ((cp = coda_find(fid)) == NULL) { + struct vnode *vp; + + cp = coda_alloc(); + cp->c_fid = *fid; + err = getnewvnode("coda", vfsp, &coda_vnodeops, &vp); + if (err) + panic("coda: getnewvnode returned error %d\n", err); + + /* + * XXX: Too early for mpsafe fs. + */ + err = insmntque1(vp, vfsp, NULL, NULL); + if (err != 0) + panic("coda: insmntque failed: error %d", err); + vp->v_data = cp; + vp->v_type = type; + cp->c_vnode = vp; + coda_save(cp); + } else + vref(CTOV(cp)); + return (cp); } int @@ -1687,7 +1773,6 @@ coda_pathconf(struct vop_pathconf_args *ap) retval = ap->a_retval; error = 0; - switch (ap->a_name) { case _PC_NAME_MAX: *retval = CODA_MAXNAMLEN; @@ -1699,6 +1784,5 @@ coda_pathconf(struct vop_pathconf_args *ap) error = vop_stdpathconf(ap); break; } - return (error); } diff --git a/sys/fs/coda/coda_vnops.h b/sys/fs/coda/coda_vnops.h index 45d49ef..386dd07 100644 --- a/sys/fs/coda/coda_vnops.h +++ b/sys/fs/coda/coda_vnops.h @@ -1,11 +1,11 @@ /*- - * + * * Coda: an Experimental Distributed File System * Release 3.1 - * + * * Copyright (c) 1987-1998 Carnegie Mellon University * All Rights Reserved - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the @@ -14,24 +14,23 @@ * that credit is given to Carnegie Mellon University in all documents * and publicity pertaining to direct or indirect use of this code or its * derivatives. - * + * * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF * ANY DERIVATIVE WORK. - * + * * Carnegie Mellon encourages users of this software to return any * improvements or extensions that they make, and to grant Carnegie * Mellon the rights to redistribute these changes without encumbrance. - * + * * @(#) src/sys/coda/coda_vnops.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD$ - * */ -/* +/* * Mach Operating System * Copyright (c) 1990 Carnegie-Mellon University * Copyright (c) 1989 Carnegie-Mellon University @@ -42,42 +41,44 @@ /* * This code was written for the Coda filesystem at Carnegie Mellon * University. Contributers include David Steere, James Kistler, and - * M. Satyanarayanan. + * M. Satyanarayanan. */ +#ifndef _CODA_VNOPS_H_ +#define _CODA_VNOPS_H_ + +/* + * FreeBSD interfaces to the vnodeops. + */ +vop_open_t coda_open; +vop_close_t coda_close; +vop_read_t coda_read; +vop_write_t coda_write; +vop_ioctl_t coda_ioctl; +vop_getattr_t coda_getattr; +vop_setattr_t coda_setattr; +vop_access_t coda_access; +vop_readlink_t coda_readlink; +vop_fsync_t coda_fsync; +vop_inactive_t coda_inactive; +vop_lookup_t coda_lookup; +vop_create_t coda_create; +vop_remove_t coda_remove; +vop_link_t coda_link; +vop_rename_t coda_rename; +vop_mkdir_t coda_mkdir; +vop_rmdir_t coda_rmdir; +vop_symlink_t coda_symlink; +vop_readdir_t coda_readdir; +vop_strategy_t coda_strategy; +vop_reclaim_t coda_reclaim; +vop_lock1_t coda_lock; +vop_unlock_t coda_unlock; +vop_islocked_t coda_islocked; +vop_pathconf_t coda_pathconf; -/* FreeBSD interfaces to the vnodeops */ -vop_open_t coda_open; -vop_close_t coda_close; -vop_read_t coda_read; -vop_write_t coda_write; -vop_ioctl_t coda_ioctl; -/* 1.3 int cfs_select(void *);*/ -vop_getattr_t coda_getattr; -vop_setattr_t coda_setattr; -vop_access_t coda_access; -int coda_abortop(void *); -vop_readlink_t coda_readlink; -vop_fsync_t coda_fsync; -vop_inactive_t coda_inactive; -vop_lookup_t coda_lookup; -vop_create_t coda_create; -vop_remove_t coda_remove; -vop_link_t coda_link; -vop_rename_t coda_rename; -vop_mkdir_t coda_mkdir; -vop_rmdir_t coda_rmdir; -vop_symlink_t coda_symlink; -vop_readdir_t coda_readdir; -vop_strategy_t coda_strategy; -vop_reclaim_t coda_reclaim; -vop_lock1_t coda_lock; -vop_unlock_t coda_unlock; -vop_islocked_t coda_islocked; -int coda_vop_error(void *); -vop_pathconf_t coda_pathconf; +int coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, + int ioflag, struct ucred *cred, struct thread *td); +void coda_print_cred(struct ucred *cred); -int coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, - int ioflag, struct ucred *cred, struct thread *td); -int coda_grab_vnode(struct cdev *dev, ino_t ino, struct vnode **vpp); -void coda_print_cred(struct ucred *cred); +#endif /* !_CODA_VNOPS_H_ */ -- cgit v1.1