From: Sam Hartman Date: Mon, 17 May 2004 06:43:07 +0000 (+0000) Subject: In cases where conflicts exist between 1.3.64 and the Debian sources X-Git-Tag: debian/1.3.64-1~23 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=f82288ac9294f9f28e53cbbfb30aa29bb1090752;p=packages%2Fo%2Fopenafs.git In cases where conflicts exist between 1.3.64 and the Debian sources and where the conflict stems from old patches that have been applied upstream that make rcsids incompatible, use the upstream sources directly. --- diff --git a/src/afs/.cvsignore b/src/afs/.cvsignore index 61d3b800b..fb596ce66 100644 --- a/src/afs/.cvsignore +++ b/src/afs/.cvsignore @@ -3,3 +3,5 @@ Makefile afs_trace.h afs_trace.msf afszcm.cat +unified_afs.c +unified_afs.h diff --git a/src/afs/AIX/osi_config.c b/src/afs/AIX/osi_config.c index 6fa3d470c..93d015ab1 100644 --- a/src/afs/AIX/osi_config.c +++ b/src/afs/AIX/osi_config.c @@ -34,9 +34,10 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_config.c,v 1.1.1.4 2001/07/14 22:19:33 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_config.c,v 1.8 2003/07/15 23:14:16 shadow Exp $"); #include "sys/limits.h" #include "sys/types.h" @@ -50,14 +51,14 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_config.c,v 1.1.1.4 2001/07/ #include "sys/gfs.h" #include "sys/uio.h" #include "sys/pri.h" -#include "sys/priv.h" /* XXX */ +#include "sys/priv.h" /* XXX */ #include "sys/lockl.h" #include "sys/malloc.h" -#include /* to define the assert and ASSERT macros */ -#include /* For the timer related defines */ -#include /* for the serialization defines */ -#include /* for the parameters to xmalloc() */ -#include "afs/afs_osi.h" /* pick up osi_timeval_t for afs_stats.h */ +#include /* to define the assert and ASSERT macros */ +#include /* For the timer related defines */ +#include /* for the serialization defines */ +#include /* for the parameters to xmalloc() */ +#include "afs/afs_osi.h" /* pick up osi_timeval_t for afs_stats.h */ #include "afs/afs_stats.h" #include "export.h" @@ -66,15 +67,24 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_config.c,v 1.1.1.4 2001/07/ #else #define KOFF_PRESENT 0 #endif - + #if !KOFF_PRESENT -_db_trace() { ; } +_db_trace() +{; +} + long db_tflags = 0; #endif extern struct gfs afs_gfs; extern struct vnodeops locked_afs_gn_vnodeops; +#ifdef __64BIT__ +afs_uint64 get_toc(); +#else +afs_uint32 get_toc(); +#endif + #define AFS_CALLOUT_TBL_SIZE 256 #include @@ -88,69 +98,70 @@ extern Simple_lock afs_callout_lock; * uiop - uio vector describing any config params */ afs_config(cmd, uiop) -struct uio *uiop; { - int err; - extern struct vnodeops *afs_ops; - - AFS_STATCNT(afs_config); - - err = 0; - AFS_GLOCK(); - if (cmd == CFG_INIT) { /* add AFS gfs */ - /* - * init any vrmix mandated kluges - */ - if (err = kluge_init()) - goto out; - /* - * make sure that we pin everything - */ - if (err = pincode(afs_config)) - goto out; - err = gfsadd(AFS_MOUNT_AFS, &afs_gfs); - /* - * ok, if already installed - */ - if (err == EBUSY) - err = 0; - if (!err) { - pin(&afs_callout_lock, sizeof(afs_callout_lock)); - lock_alloc(&afs_callout_lock, LOCK_ALLOC_PIN, 0, 5); - simple_lock_init(&afs_callout_lock); - afs_ops = &locked_afs_gn_vnodeops; - timeoutcf(AFS_CALLOUT_TBL_SIZE); - } else { - unpincode(afs_config); - goto out; - } - if (KOFF_PRESENT) { - extern void *db_syms[]; - extern db_nsyms; - - koff_addsyms(db_syms, db_nsyms); - } - } else if (cmd == CFG_TERM) { /* delete AFS gfs */ - err = gfsdel(AFS_MOUNT_AFS); - /* - * ok, if already deleted - */ - if (err == ENOENT) - err = 0; - else if (!err) { - if (err = unpincode(afs_config)) - err = 0; - - timeoutcf(-AFS_CALLOUT_TBL_SIZE); - } - } else /* unknown command */ - err = EINVAL; - - out: - AFS_GUNLOCK(); - if ( !err && (cmd == CFG_INIT) ) - osi_Init(); - - return err; + struct uio *uiop; +{ + int err; + extern struct vnodeops *afs_ops; + + AFS_STATCNT(afs_config); + + err = 0; + AFS_GLOCK(); + if (cmd == CFG_INIT) { /* add AFS gfs */ + /* + * init any vrmix mandated kluges + */ + if (err = kluge_init()) + goto out; + /* + * make sure that we pin everything + */ + if (err = pincode(afs_config)) + goto out; + err = gfsadd(AFS_MOUNT_AFS, &afs_gfs); + /* + * ok, if already installed + */ + if (err == EBUSY) + err = 0; + if (!err) { + pin(&afs_callout_lock, sizeof(afs_callout_lock)); + lock_alloc(&afs_callout_lock, LOCK_ALLOC_PIN, 0, 5); + simple_lock_init(&afs_callout_lock); + afs_ops = &locked_afs_gn_vnodeops; + timeoutcf(AFS_CALLOUT_TBL_SIZE); + } else { + unpincode(afs_config); + goto out; + } + if (KOFF_PRESENT) { + extern void *db_syms[]; + extern db_nsyms; + + koff_addsyms(db_syms, db_nsyms); + } + } else if (cmd == CFG_TERM) { /* delete AFS gfs */ + err = gfsdel(AFS_MOUNT_AFS); + /* + * ok, if already deleted + */ + if (err == ENOENT) + err = 0; + else if (!err) { + if (err = unpincode(afs_config)) + err = 0; + + timeoutcf(-AFS_CALLOUT_TBL_SIZE); + } + } else /* unknown command */ + err = EINVAL; + + out: + AFS_GUNLOCK(); + if (!err && (cmd == CFG_INIT)) + osi_Init(); + + return err; } /* @@ -164,7 +175,8 @@ struct uio *uiop; { * Seems we can't make up our mind what to call these */ char * -mem_getbytes(size) { +mem_getbytes(size) +{ return malloc(size); } @@ -173,33 +185,38 @@ mem_getbytes(size) { * mem_freebytes - memory deallocator */ mem_freebytes(p, size) -char *p; { + char *p; +{ free(p); } char * -kmem_alloc(size) { +kmem_alloc(size) +{ - return malloc(size); + return malloc(size); } kmem_free(p, size) -char *p; { + char *p; +{ - free(p); + free(p); } VN_RELE(vp) -register struct vnode *vp; { + register struct vnode *vp; +{ - VNOP_RELE(vp); + VNOP_RELE(vp); } VN_HOLD(vp) -register struct vnode *vp; { + register struct vnode *vp; +{ - VNOP_HOLD(vp); + VNOP_HOLD(vp); } /* @@ -207,48 +224,48 @@ register struct vnode *vp; { * from the kernel isn't, so we must be devious. */ -int (*kluge_ufdalloc)(); -int (*kluge_fpalloc)(); -void *(*kluge_ufdfree)(); -void *(*kluge_ffree)(); -int (*kluge_iptovp)(); -int (*kluge_dev_ialloc)(); -int (*kluge_iget)(); -int (*kluge_iput)(); -int (*kluge_commit)(); -void *(*kluge_ksettimer)(); -void *(*kluge_fsSimpleLock)(); -void *(*kluge_fsSimpleUnlock)(); -void *(*kluge_fsReadLock)(); -void *(*kluge_fsWriteLock)(); -void *(*kluge_fsCxUnlock)(); +int (*kluge_ufdalloc) (); +int (*kluge_fpalloc) (); +void *(*kluge_ufdfree) (); +void *(*kluge_ffree) (); +int (*kluge_iptovp) (); +int (*kluge_dev_ialloc) (); +int (*kluge_iget) (); +int (*kluge_iput) (); +int (*kluge_commit) (); +void *(*kluge_ksettimer) (); +void *(*kluge_fsSimpleLock) (); +void *(*kluge_fsSimpleUnlock) (); +void *(*kluge_fsReadLock) (); +void *(*kluge_fsWriteLock) (); +void *(*kluge_fsCxUnlock) (); /* * kernel function import list */ struct k_func kfuncs[] = { - { (void *(**)()) &kluge_ufdalloc, ".ufdalloc" }, - { (void *(**)()) &kluge_fpalloc, ".fpalloc" }, - { &kluge_ufdfree, ".ufdfree" }, - { &kluge_ffree, ".ffree" }, - { (void *(**)()) &kluge_iptovp, ".iptovp" }, - { (void *(**)()) &kluge_dev_ialloc, ".dev_ialloc" }, - { (void *(**)()) &kluge_iget, ".iget" }, - { (void *(**)()) &kluge_iput, ".iput" }, - { (void *(**)()) &kluge_commit, ".commit" }, - { &kluge_ksettimer, ".ksettimer" }, + {(void *(**)())&kluge_ufdalloc, ".ufdalloc"}, + {(void *(**)())&kluge_fpalloc, ".fpalloc"}, + {&kluge_ufdfree, ".ufdfree"}, + {&kluge_ffree, ".ffree"}, + {(void *(**)())&kluge_iptovp, ".iptovp"}, + {(void *(**)())&kluge_dev_ialloc, ".dev_ialloc"}, + {(void *(**)())&kluge_iget, ".iget"}, + {(void *(**)())&kluge_iput, ".iput"}, + {(void *(**)())&kluge_commit, ".commit"}, + {&kluge_ksettimer, ".ksettimer"}, #ifdef _FSDEBUG - { &kluge_fsSimpleLock, ".fs_simple_lock" }, - { &kluge_fsSimpleUnlock, ".fs_simple_unlock" }, - { &kluge_fsReadLock, ".fs_read_lock" }, - { &kluge_fsWriteLock, ".fs_write_lock" }, - { &kluge_fsCxUnlock, ".fs_complex_unlock" }, + {&kluge_fsSimpleLock, ".fs_simple_lock"}, + {&kluge_fsSimpleUnlock, ".fs_simple_unlock"}, + {&kluge_fsReadLock, ".fs_read_lock"}, + {&kluge_fsWriteLock, ".fs_write_lock"}, + {&kluge_fsCxUnlock, ".fs_complex_unlock"}, #endif - { 0, 0 }, + {0, 0}, }; -void *vnodefops; /* dummy vnodeops */ +void *vnodefops; /* dummy vnodeops */ struct ifnet *ifnet; Simple_lock jfs_icache_lock; Simple_lock proc_tbl_lock; @@ -257,120 +274,148 @@ Simple_lock proc_tbl_lock; * kernel variable import list */ struct k_var kvars[] = { - { (void *) &vnodefops, "vnodefops" }, - { (void *) &ifnet, "ifnet" }, - { (void *) &jfs_icache_lock, "jfs_icache_lock" }, - { (void *) &proc_tbl_lock, "proc_tbl_lock" }, - { 0, 0 }, + {(void *)&vnodefops, "vnodefops"}, + {(void *)&ifnet, "ifnet"}, + {(void *)&jfs_icache_lock, "jfs_icache_lock"}, +#ifndef AFS_AIX51_ENV + {(void *)&proc_tbl_lock, "proc_tbl_lock"}, +#endif + {0, 0}, }; /* * kluge_init - initialise the kernel imports kluge */ -kluge_init() { - register struct k_func *kf; - register struct k_var *kv; - register afs_uint32 toc; - register err = 0; - - toc = get_toc(); - for (kf = kfuncs; !err && kf->name; ++kf) { - err = import_kfunc(kf); - } - for (kv = kvars; !err && kv->name; ++kv) { - err = import_kvar(kv, toc); - } +kluge_init() +{ + register struct k_func *kf; + register struct k_var *kv; +#ifdef __64BIT__ + register afs_uint64 toc; +#else + register afs_uint32 toc; +#endif + register err = 0; + + toc = get_toc(); + for (kf = kfuncs; !err && kf->name; ++kf) { + err = import_kfunc(kf); + } + for (kv = kvars; !err && kv->name; ++kv) { + err = import_kvar(kv, toc); + } - return err; + return err; } ufdalloc(i, fdp) -int *fdp; { + int *fdp; +{ - return (*kluge_ufdalloc)(i, fdp); + return (*kluge_ufdalloc) (i, fdp); } fpalloc(vp, flag, type, ops, fpp) -struct vnode *vp; -struct fileops *ops; -struct file **fpp; { + struct vnode *vp; + struct fileops *ops; + struct file **fpp; +{ - return (*kluge_fpalloc)(vp, flag, type, ops, fpp); + return (*kluge_fpalloc) (vp, flag, type, ops, fpp); } void -ufdfree(fd) { +ufdfree(fd) +{ - (void) (*kluge_ufdfree)(fd); + (void)(*kluge_ufdfree) (fd); } void ffree(fp) -struct file *fp; { + struct file *fp; +{ - (void) (*kluge_ffree)(fp); + (void)(*kluge_ffree) (fp); } iptovp(vfsp, ip, vpp) -struct vfs *vfsp; -struct inode *ip, **vpp; { + struct vfs *vfsp; + struct inode *ip, **vpp; +{ - return (*kluge_iptovp)(vfsp, ip, vpp); + return (*kluge_iptovp) (vfsp, ip, vpp); } dev_ialloc(pip, ino, mode, vfsp, ipp) -struct inode *pip; -ino_t ino; -mode_t mode; -struct vfs *vfsp; -struct inode **ipp; { + struct inode *pip; + ino_t ino; + mode_t mode; + struct vfs *vfsp; + struct inode **ipp; +{ - return (*kluge_dev_ialloc)(pip, ino, mode, vfsp, ipp); + return (*kluge_dev_ialloc) (pip, ino, mode, vfsp, ipp); } iget(dev, ino, ipp, doscan, vfsp) -dev_t dev; -ino_t ino; -struct vfs *vfsp; -struct inode **ipp; { - - return (*kluge_iget)(dev, ino, ipp, doscan, vfsp); + dev_t dev; + ino_t ino; +#ifdef __64BIT__ + afs_size_t doscan; +#endif + struct vfs *vfsp; + struct inode **ipp; +{ +#ifdef __64BIT__ + afs_int64 dummy[10]; + dummy[0] = doscan; + + return (*kluge_iget) (dev, ino, ipp, (afs_size_t) doscan, vfsp, &dummy); +#else + return (*kluge_iget) (dev, ino, ipp, doscan, vfsp); +#endif } iput(ip, vfsp) -struct vfs *vfsp; -struct inode *ip; { - return (*kluge_iput)(ip, vfsp); + struct vfs *vfsp; + struct inode *ip; +{ + return (*kluge_iput) (ip, vfsp); } commit(n, i0, i1, i2) -struct inode *i0, *i1, *i2; { + struct inode *i0, *i1, *i2; +{ - return (*kluge_commit)(n, i0, i1, i2); + return (*kluge_commit) (n, i0, i1, i2); } #ifdef _FSDEBUG -fs_simple_lock(void *lp, int type) { - return (*kluge_fsSimpleLock)(lp, type); +fs_simple_lock(void *lp, int type) +{ + return (*kluge_fsSimpleLock) (lp, type); } -fs_simple_unlock(void *lp, int type) { - return (*kluge_fsSimpleUnlock)(lp, type); +fs_simple_unlock(void *lp, int type) +{ + return (*kluge_fsSimpleUnlock) (lp, type); } -fs_read_lock(complex_lock_t lp, int type) { - return (*kluge_fsReadLock)(lp, type); +fs_read_lock(complex_lock_t lp, int type) +{ + return (*kluge_fsReadLock) (lp, type); } -fs_write_lock(complex_lock_t lp, int type) { - return (*kluge_fsWriteLock)(lp, type); +fs_write_lock(complex_lock_t lp, int type) +{ + return (*kluge_fsWriteLock) (lp, type); } -fs_complex_unlock(complex_lock_t lp, int type) { - return (*kluge_fsCxUnlock)(lp, type); +fs_complex_unlock(complex_lock_t lp, int type) +{ + return (*kluge_fsCxUnlock) (lp, type); } #endif - - diff --git a/src/afs/AIX/osi_file.c b/src/afs/AIX/osi_file.c index 4f64a92ee..2bea9a41e 100644 --- a/src/afs/AIX/osi_file.c +++ b/src/afs/AIX/osi_file.c @@ -8,34 +8,35 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_file.c,v 1.1.1.5 2001/09/11 14:24:51 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_file.c,v 1.9 2003/07/15 23:14:16 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ -int afs_osicred_initialized=0; -struct AFS_UCRED afs_osi_cred; +int afs_osicred_initialized = 0; +struct AFS_UCRED afs_osi_cred; afs_lock_t afs_xosi; /* lock is for tvattr */ extern struct osi_dev cacheDev; extern struct vfs *afs_cacheVfsp; -void *osi_UFSOpen(ainode) - afs_int32 ainode; +void * +osi_UFSOpen(afs_int32 ainode) { struct inode *ip; register struct osi_file *afile = NULL; extern struct vfs *rootvfs; - struct vnode *vp = (struct vnode *)0; + struct vnode *vp = NULL; extern int cacheDiskType; afs_int32 code = 0; int dummy; AFS_STATCNT(osi_UFSOpen); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) { + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) { osi_Panic("UFSOpen called for non-UFS cache\n"); } if (!afs_osicred_initialized) { @@ -44,30 +45,31 @@ void *osi_UFSOpen(ainode) crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */ afs_osicred_initialized = 1; } - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); setuerror(0); AFS_GUNLOCK(); - ip = (struct inode *) igetinode((dev_t) cacheDev.dev, rootvfs, (ino_t)ainode, &vp,&dummy); + ip = (struct inode *)igetinode((dev_t) cacheDev.dev, rootvfs, + (ino_t) ainode, &vp, &dummy); AFS_GLOCK(); if (getuerror()) { osi_FreeSmallSpace(afile); osi_Panic("UFSOpen: igetinode failed"); } - afile->vnode = vp; /* Save the vnode pointer for the inode ip; also ip is already prele'ed in igetinode */ + afile->vnode = vp; /* Save the vnode pointer for the inode ip; also ip is already prele'ed in igetinode */ afile->size = VTOI(afile->vnode)->i_size; afile->offset = 0; - afile->proc = (int (*)()) 0; - afile->inum = ainode; /* for hint validity checking */ + afile->proc = (int (*)())0; + afile->inum = ainode; /* for hint validity checking */ return (void *)afile; } -afs_osi_Stat(afile, astat) - register struct osi_file *afile; - register struct osi_stat *astat; { +int +afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) +{ register afs_int32 code; struct vattr tvattr; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi,320); + MObtainWriteLock(&afs_xosi, 320); AFS_GUNLOCK(); code = VNOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred); AFS_GLOCK(); @@ -81,11 +83,11 @@ afs_osi_Stat(afile, astat) return code; } -osi_UFSClose(afile) - register struct osi_file *afile; - { - AFS_STATCNT(osi_Close); - if(afile->vnode) { +int +osi_UFSClose(register struct osi_file *afile) +{ + AFS_STATCNT(osi_Close); + if (afile->vnode) { /* AIX writes entire data regions at a time when dumping core. We've * seen a 26M write go through the system. When this happens, we run * out of available pages. So, we'll flush the vnode's vm if we're short @@ -101,20 +103,20 @@ osi_UFSClose(afile) } } AFS_RELE(afile->vnode); - } - - osi_FreeSmallSpace(afile); - return 0; - } + } + + osi_FreeSmallSpace(afile); + return 0; +} -osi_UFSTruncate(afile, asize) - register struct osi_file *afile; - afs_int32 asize; { +int +osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) +{ struct AFS_UCRED *oldCred; struct vattr tvattr; register afs_int32 code; struct osi_stat tstat; - afs_int32 mode=FWRITE|FSYNC; + afs_int32 mode = FWRITE | FSYNC; AFS_STATCNT(osi_Truncate); /* This routine only shrinks files, and most systems @@ -122,69 +124,76 @@ osi_UFSTruncate(afile, asize) * small enough. Check now and save some time. */ code = afs_osi_Stat(afile, &tstat); - if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi,321); + if (code || tstat.size <= asize) + return code; + MObtainWriteLock(&afs_xosi, 321); /* * If we're truncating an unopened file to a non-zero length, * we need to bind it to a vm segment * Note that that the binding will actually happen inside * jfs by xix_ftrunc; setting mode to 0 will enable that. */ - if (asize && !VTOGP(afile->vnode)->gn_seg) + if (asize && !VTOGP(afile->vnode)->gn_seg) mode = 0; AFS_GUNLOCK(); - code = VNOP_FTRUNC(afile->vnode, mode, asize, (caddr_t)0, &afs_osi_cred); + code = VNOP_FTRUNC(afile->vnode, mode, asize, (caddr_t) 0, &afs_osi_cred); AFS_GLOCK(); MReleaseWriteLock(&afs_xosi); return code; } -void osi_DisableAtimes(avp) -struct vnode *avp; +void +osi_DisableAtimes(struct vnode *avp) { - struct inode *ip = VTOIP(avp); - ip->i_flag &= ~IACC; + struct inode *ip = VTOIP(avp); + ip->i_flag &= ~IACC; } /* Generic read interface */ -afs_osi_Read(afile, offset, aptr, asize) - register struct osi_file *afile; - int offset; - char *aptr; - afs_int32 asize; { +int +afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; unsigned int resid; register afs_int32 code; - register afs_int32 cnt1=0; + register afs_int32 cnt1 = 0; AFS_STATCNT(osi_Read); - + /** * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ - if ( !afile ) { - if ( !afs_shuttingdown ) + if (!afile) { + if (!afs_shuttingdown) osi_Panic("osi_Read called with null param"); else return EIO; } - if (offset != -1) afile->offset = offset; -retry_IO: + if (offset != -1) + afile->offset = offset; + retry_IO: /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */ AFS_GUNLOCK(); - code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, - (off_t)&afile->offset, AFS_UIOSYS, NULL, &resid); +#ifdef AFS_64BIT_KERNEL + code = + gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, + &afile->offset, AFS_UIOSYS, NULL, &resid); +#else + code = + gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, + (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid); +#endif AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; osi_DisableAtimes(afile->vnode); - } - else { + } else { afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, - ICL_TYPE_INT32, code); + ICL_TYPE_INT32, code); /* * To handle periodic low-level EFAULT failures that we've seen with the * Weitek chip; in all observed failed cases a second read succeeded. @@ -193,41 +202,54 @@ retry_IO: afs_stats_cmperf.osiread_efaults++; goto retry_IO; } - setuerror(code); + setuerror(code); code = -1; } return code; } /* Generic write interface */ -afs_osi_Write(afile, offset, aptr, asize) - register struct osi_file *afile; - char *aptr; - afs_int32 offset; - afs_int32 asize; { +int +afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; unsigned int resid; register afs_int32 code; AFS_STATCNT(osi_Write); - if ( !afile ) - osi_Panic("afs_osi_Write called with null param"); - if (offset != -1) afile->offset = offset; + if (!afile) + osi_Panic("afs_osi_Write called with null param"); + if (offset != -1) + afile->offset = offset; /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */ AFS_GUNLOCK(); - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, - (off_t)&afile->offset, AFS_UIOSYS, NULL, &resid); +#ifdef AFS_64BIT_KERNEL + code = + gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + &afile->offset, AFS_UIOSYS, NULL, &resid); +#else + code = + gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid); +#endif AFS_GLOCK(); if (code == 0) { + if (resid) + afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32, + asize, ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code); code = asize - resid; afile->offset += code; - } - else { - if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); + } else { + afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32, asize, + ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code); + if (code == ENOSPC) + afs_warnuser + ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); setuerror(code); code = -1; } if (afile->proc) { - (*afile->proc)(afile, code); + (*afile->proc) (afile, code); } return code; } @@ -236,9 +258,8 @@ afs_osi_Write(afile, offset, aptr, asize) /* This work should be handled by physstrat in ca/machdep.c. This routine written from the RT NFS port strategy routine. It has been generalized a bit, but should still be pretty clear. */ -int afs_osi_MapStrategy(aproc, bp) - int (*aproc)(); - register struct buf *bp; +int +afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp) { afs_int32 returnCode; @@ -251,13 +272,12 @@ int afs_osi_MapStrategy(aproc, bp) void -shutdown_osifile() +shutdown_osifile(void) { - extern int afs_cold_shutdown; + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osifile); - if (afs_cold_shutdown) { - afs_osicred_initialized = 0; - } + AFS_STATCNT(shutdown_osifile); + if (afs_cold_shutdown) { + afs_osicred_initialized = 0; + } } - diff --git a/src/afs/AIX/osi_groups.c b/src/afs/AIX/osi_groups.c index 9ac2b6f9e..e2d9a3db1 100644 --- a/src/afs/AIX/osi_groups.c +++ b/src/afs/AIX/osi_groups.c @@ -14,32 +14,28 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_groups.c,v 1.1.1.4 2001/07/14 22:19:32 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_groups.c,v 1.8 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset); + afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset); static int -afs_setgroups( - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent); + afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset, + int change_parent); +#ifndef AFS_AIX51_ENV int setgroups(ngroups, gidset) - int ngroups; - gid_t *gidset; + int ngroups; + gid_t *gidset; { int code = 0; struct vrequest treq; @@ -53,7 +49,8 @@ setgroups(ngroups, gidset) code = afs_InitReq(&treq, credp); AFS_GUNLOCK(); crfree(credp); - if (code) return code; + if (code) + return code; code = osetgroups(ngroups, gidset); @@ -77,45 +74,57 @@ setgroups(ngroups, gidset) } return code; } - +#endif int setpag(cred, pagvalue, newpag, change_parent) - struct ucred **cred; - afs_uint32 pagvalue; - afs_uint32 *newpag; - afs_uint32 change_parent; + struct ucred **cred; + afs_uint32 pagvalue; + afs_uint32 *newpag; + afs_uint32 change_parent; { gid_t gidset[NGROUPS]; int ngroups, code; int j; AFS_STATCNT(setpag); +#ifndef AFS_AIX51_ENV ngroups = afs_getgroups(*cred, NGROUPS, gidset); if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) { /* We will have to shift grouplist to make room for pag */ if (ngroups + 2 > NGROUPS) { return (setuerror(E2BIG), E2BIG); } - for (j = ngroups -1; j >= 0; j--) { - gidset[j+2] = gidset[j]; - } + for (j = ngroups - 1; j >= 0; j--) { + gidset[j + 2] = gidset[j]; + } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); +#endif + *newpag = (pagvalue == -1 ? genpag() : pagvalue); +#ifdef AFS_AIX51_ENV + if (change_parent) { + code = kcred_setpag(*cred, PAG_AFS, *newpag); + } else { + struct ucred *newcr = crdup(*cred); + + crset(newcr); + code = kcred_setpag(newcr, PAG_AFS, *newpag); + *cred = newcr; + } +#else afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]); if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) { return (setuerror(code), code); } +#endif return code; } +#ifndef AFS_AIX51_ENV static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset) +afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset) { int ngrps, savengrps; gid_t *gp; @@ -134,9 +143,9 @@ afs_getgroups( static void copy_to_cred(newcr, ngroups, gidset) - struct ucred *newcr; - int ngroups; - gid_t *gidset; + struct ucred *newcr; + int ngroups; + gid_t *gidset; { gid_t *gp; int newngroups; @@ -162,11 +171,8 @@ copy_to_cred(newcr, ngroups, gidset) */ static int -afs_setgroups( - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent) +afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset, + int change_parent) { AFS_STATCNT(afs_setgroups); @@ -198,3 +204,4 @@ afs_setgroups( } return 0; } +#endif diff --git a/src/afs/AIX/osi_inode.c b/src/afs/AIX/osi_inode.c index e1d89754a..cf5c75e6d 100644 --- a/src/afs/AIX/osi_inode.c +++ b/src/afs/AIX/osi_inode.c @@ -14,21 +14,22 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_inode.c,v 1.1.1.4 2001/07/14 22:19:33 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_inode.c,v 1.8 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/osi_inode.h" -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/osi_inode.h" +#include "afs/afs_stats.h" /* statistics stuff */ #include "sys/syspest.h" #if !defined(offsetof) -#include /* for definition of offsetof() */ +#include /* for definition of offsetof() */ #endif -extern Simple_lock jfs_icache_lock; +extern Simple_lock jfs_icache_lock; #define ICACHE_LOCK() simple_lock(&jfs_icache_lock) #define ICACHE_UNLOCK() simple_unlock(&jfs_icache_lock) @@ -57,11 +58,11 @@ extern Simple_lock jfs_icache_lock; * is at an expected offset. */ -#if IACTIVITY == 0x0020 /* in on AIX 4.2.0 */ +#if IACTIVITY == 0x0020 /* in on AIX 4.2.0 */ #define afs_inode_lock i_rdwrlock #endif -#if IACTIVITY == 0x0010 /* in on AIX 4.2.1 and later */ +#if IACTIVITY == 0x0010 /* in on AIX 4.2.1 and later */ #define afs_inode_lock i_nodelock #endif @@ -115,7 +116,8 @@ struct devtovfs_args { * (Returning nonzero causes vfs_search() to terminate the search.) */ -static int devtovfs_func(struct vfs *vfsp, struct devtovfs_args *rock) +static int +devtovfs_func(struct vfs *vfsp, struct devtovfs_args *rock) { if (vfsp->vfs_mntd != NULL && vfsp->vfs_type == MNT_JFS && (vfsp->vfs_flag & VFS_DEVMOUNT)) { @@ -141,7 +143,7 @@ devtovfs(dev_t dev) AFS_STATCNT(devtovfs); a.dev = dev; - a.ans = (struct vfs *)0; + a.ans = NULL; vfs_search(devtovfs_func, &a); return a.ans; } @@ -156,84 +158,93 @@ int IGI_mode; /* get an existing inode. Common code for iopen, iread/write, iinc/dec. */ /* Also used by rmt_remote to support passing of inode number from venus */ extern int iget(); +extern struct vnode *filevp; struct inode * -igetinode(dev, vfsp, inode, vpp,perror) - struct vfs *vfsp; - struct vnode **vpp; /* vnode associated with the inode */ - dev_t dev; - ino_t inode; - int *perror; +igetinode(dev, vfsp, inode, vpp, perror) + struct vfs *vfsp; + struct vnode **vpp; /* vnode associated with the inode */ + dev_t dev; + ino_t inode; + int *perror; { - struct inode *ip; - register was_locked; - struct vfs *nvfsp = NULL; - int code; - *perror = 0; - *vpp = NULL; - AFS_STATCNT(igetinode); - - /* - * Double check that the inode lock is at a known offset. - * - * If it isn't, then we need to reexamine our code to make - * sure that it is still okay. - */ - osi_Assert(offsetof(struct inode, afs_inode_lock) == 128); - - if (!vfsp && !(vfsp = devtovfs((dev_t)dev))) { - afs_warn("Dev=%d not mounted!!; quitting\n", dev); - setuerror(ENODEV); - ip = 0; - goto out; - } - if (vfsp->vfs_flag & VFS_DEVMOUNT) - nvfsp = vfsp; + struct inode *ip; + register was_locked; + struct vfs *nvfsp = NULL; + int code; + *perror = 0; + *vpp = NULL; + AFS_STATCNT(igetinode); + + /* + * Double check that the inode lock is at a known offset. + * + * If it isn't, then we need to reexamine our code to make + * sure that it is still okay. + */ +#ifdef __64BIT__ +/* osi_Assert(offsetof(struct inode, afs_inode_lock) == 208); */ +#else + osi_Assert(offsetof(struct inode, afs_inode_lock) == 128); +#endif - /* Check if inode 0. This is the mount inode for the device - * and will panic the aix system if removed: defect 11434. - * No file should ever point to this inode. - */ - if (inode == 0) { - afs_warn("Dev=%d zero inode.\n", dev); - setuerror(ENOENT); - ip = 0; - goto out; - } + if (!vfsp && !(vfsp = devtovfs((dev_t) dev))) { + afs_warn("Dev=%d not mounted!!; quitting\n", dev); + setuerror(ENODEV); + ip = 0; + goto out; + } + if (vfsp->vfs_flag & VFS_DEVMOUNT) + nvfsp = vfsp; + + /* Check if inode 0. This is the mount inode for the device + * and will panic the aix system if removed: defect 11434. + * No file should ever point to this inode. + */ + if (inode == 0) { + afs_warn("Dev=%d zero inode.\n", dev); + setuerror(ENOENT); + ip = 0; + goto out; + } - ICACHE_LOCK(); - if ((code = iget(dev, inode, &ip, 1, nvfsp))) { - IGI_error = code; - IGI_inode = inode; - *perror = BAD_IGET; - ICACHE_UNLOCK(); - setuerror(ENOENT); /* Well... */ - ip = 0; - goto out; - } + ICACHE_LOCK(); +#ifdef __64BIT__ + if ((code = iget(dev, inode, &ip, (afs_size_t) 1, nvfsp))) { +#else + if ((code = iget(dev, inode, &ip, 1, nvfsp))) { +#endif + IGI_error = code; + IGI_inode = inode; + *perror = BAD_IGET; ICACHE_UNLOCK(); - IREAD_LOCK(ip); - if (ip->i_nlink == 0 || (ip->i_mode&IFMT) != IFREG) { - IGI_error = 0; - IGI_inode = inode; - IGI_nlink = ip->i_nlink; - IGI_mode = ip->i_mode; - IREAD_UNLOCK(ip); - ICACHE_LOCK(); - iput(ip, NULL); - ICACHE_UNLOCK(); - setuerror(ENOENT); - ip = 0; - goto out; - } + setuerror(ENOENT); /* Well... */ + ip = 0; + goto out; + } + ICACHE_UNLOCK(); + IREAD_LOCK(ip); + if (ip->i_nlink == 0 || (ip->i_mode & IFMT) != IFREG) { + IGI_error = 0; + IGI_inode = inode; + IGI_nlink = ip->i_nlink; + IGI_mode = ip->i_mode; IREAD_UNLOCK(ip); - if (vpp) { - if (nvfsp) - *vpp = ip->i_gnode.gn_vnode; - else - setuerror(iptovp(vfsp, ip, vpp)); - } -out: - return ip; + ICACHE_LOCK(); + iput(ip, NULL); + ICACHE_UNLOCK(); + setuerror(ENOENT); + ip = 0; + goto out; + } + IREAD_UNLOCK(ip); + if (vpp) { + if (nvfsp) + *vpp = ip->i_gnode.gn_vnode; + else + setuerror(iptovp(vfsp, ip, vpp)); + } + out: + return ip; } @@ -243,113 +254,117 @@ out: * marked as journalled. We would also like to journal inodes corresponding * to directory information... */ -#define INODESPECIAL 0xffffffff /* ... from ../vol/viceonode.h */ +#define INODESPECIAL 0xffffffff /* ... from ../vol/viceonode.h */ #endif -SYSENT(icreate, (dev, near_inode, param1, param2, param3, param4), ) { - struct inode *ip, *newip, *pip; - register int err, rval1, rc=0; - struct vnode *vp = (struct vnode *)0; - extern struct vfs *rootvfs; - register struct vfs *vfsp; - struct vfs *nvfsp = NULL; - char error; - ino_t ino = near_inode; - - AFS_STATCNT(afs_syscall_icreate); - if (!suser(&error)) { - setuerror(error); - return -1; - } +SYSENT(icreate, (dev, near_inode, param1, param2, param3, param4),) +{ + struct inode *ip, *newip, *pip; + register int err, rval1, rc = 0; + struct vnode *vp = NULL; + extern struct vfs *rootvfs; + register struct vfs *vfsp; + struct vfs *nvfsp = NULL; + char error; + ino_t ino = near_inode; + + AFS_STATCNT(afs_syscall_icreate); + if (!suser(&error)) { + setuerror(error); + return -1; + } - if ((vfsp = devtovfs((dev_t)dev)) == 0) { - afs_warn("Dev=%d not mounted!!; quitting\n", dev); - setuerror(ENODEV); - return -1; - } - if (vfsp->vfs_flag & VFS_DEVMOUNT) - nvfsp = vfsp; - ICACHE_LOCK(); - rc = iget(dev, 0, &pip, 1, nvfsp); - if (!rc) { - /* - * this is the mount inode, and thus we should be - * safe putting it back. - */ - iput(pip, nvfsp); - } - ICACHE_UNLOCK(); + if ((vfsp = devtovfs((dev_t) dev)) == 0) { + afs_warn("Dev=%d not mounted!!; quitting\n", dev); + setuerror(ENODEV); + return -1; + } + if (vfsp->vfs_flag & VFS_DEVMOUNT) + nvfsp = vfsp; + ICACHE_LOCK(); + rc = iget(dev, 0, &pip, 1, nvfsp); + if (!rc) { + /* + * this is the mount inode, and thus we should be + * safe putting it back. + */ + iput(pip, nvfsp); + } + ICACHE_UNLOCK(); - if (rc) { - setuerror(EINVAL); - return -1; - } + if (rc) { + setuerror(EINVAL); + return -1; + } - if (setuerror(dev_ialloc(pip, ino, IFREG, nvfsp, &newip))) - return -1; - newip->i_flag |= IACC|IUPD|ICHG; - newip->i_gid = -2; /* Put special gid flag */ - newip->i_vicemagic = VICEMAGIC; - newip->i_vicep1 = param1; - newip->i_vicep2 = param2; - newip->i_vicep3 = param3; - newip->i_vicep4 = param4; - IWRITE_UNLOCK(newip); - if (nvfsp) { - vp = newip->i_gnode.gn_vnode; - } else { - rc = iptovp(vfsp, newip, &vp); - } - setuerror(rc); - - rval1 = newip->i_number; - if (vp) { - VNOP_RELE(vp); - } - return getuerror() ? -1 : rval1; + if (setuerror(dev_ialloc(pip, ino, IFREG, nvfsp, &newip))) + return -1; + newip->i_flag |= IACC | IUPD | ICHG; + newip->i_gid = -2; /* Put special gid flag */ + newip->i_vicemagic = VICEMAGIC; + newip->i_vicep1 = param1; + newip->i_vicep2 = param2; + newip->i_vicep3 = param3; + newip->i_vicep4 = param4; + IWRITE_UNLOCK(newip); + if (nvfsp) { + vp = newip->i_gnode.gn_vnode; + } else { + rc = iptovp(vfsp, newip, &vp); + } + setuerror(rc); + + rval1 = newip->i_number; + if (vp) { + VNOP_RELE(vp); + } + return getuerror()? -1 : rval1; } -SYSENT(iopen, (dev, inode, usrmod), ) { - struct file *fp; - register struct inode *ip; - struct vnode *vp = (struct vnode *)0; - extern struct fileops vnodefops; - register struct vfs *vfsp; - int fd; - char error; - struct ucred *credp; - int dummy; - - AFS_STATCNT(afs_syscall_iopen); - if (!suser(&error)) { - setuerror(error); - return -1; - } +SYSENT(iopen, (dev, inode, usrmod),) +{ + struct file *fp; + register struct inode *ip; + struct vnode *vp = NULL; + extern struct fileops vnodefops; + register struct vfs *vfsp; + int fd; + char error; + struct ucred *credp; + int dummy; + + AFS_STATCNT(afs_syscall_iopen); + if (!suser(&error)) { + setuerror(error); + return -1; + } - if ((vfsp = devtovfs((dev_t)dev)) == 0) { - afs_warn("Dev=%d not mounted!!; quitting\n", dev); - setuerror(ENODEV); - return -1; - } - ip = igetinode((dev_t)dev, vfsp, (ino_t)inode, &vp,&dummy); - if (getuerror()) - return -1; - - credp = crref(); - if (setuerror(ufdcreate((usrmod-FOPEN)&FMASK, &vnodefops, vp - , DTYPE_VNODE, &fd, credp))) { - crfree(credp); - VNOP_RELE(vp); - return -1; - } - - if (setuerror(VNOP_OPEN(vp, (usrmod-FOPEN)&FMASK, 0, 0, credp))) { - close(fd); - crfree(credp); - return -1; - } + if ((vfsp = devtovfs((dev_t) dev)) == 0) { + afs_warn("Dev=%d not mounted!!; quitting\n", dev); + setuerror(ENODEV); + return -1; + } + ip = igetinode((dev_t) dev, vfsp, (ino_t) inode, &vp, &dummy); + if (getuerror()) + return -1; + + credp = crref(); + if (setuerror + (ufdcreate + ((usrmod - FOPEN) & FMASK, &vnodefops, vp, DTYPE_VNODE, &fd, + credp))) { crfree(credp); - return fd; + VNOP_RELE(vp); + return -1; + } + + if (setuerror(VNOP_OPEN(vp, (usrmod - FOPEN) & FMASK, 0, 0, credp))) { + close(fd); + crfree(credp); + return -1; + } + crfree(credp); + return fd; } @@ -359,55 +374,58 @@ SYSENT(iopen, (dev, inode, usrmod), ) { * Restricted to super user. * Only VICEMAGIC type inodes. */ -iinc(dev, inode, inode_p1) { +iinc(dev, inode, inode_p1) +{ AFS_STATCNT(iinc); return iincdec(dev, inode, inode_p1, 1); } -idec(dev, inode, inode_p1) { +idec(dev, inode, inode_p1) +{ AFS_STATCNT(idec); return iincdec(dev, inode, inode_p1, -1); } -SYSENT(iincdec, (dev, inode, inode_p1, amount), ) { - register struct inode *ip; - char error; - struct vnode *vp = (struct vnode *)0; - int dummy; - - AFS_STATCNT(afs_syscall_iincdec); - if (!suser(&error)) { - setuerror(error); - return -1; - } +SYSENT(iincdec, (dev, inode, inode_p1, amount),) +{ + register struct inode *ip; + char error; + struct vnode *vp = NULL; + int dummy; + + AFS_STATCNT(afs_syscall_iincdec); + if (!suser(&error)) { + setuerror(error); + return -1; + } - ip = igetinode((dev_t)dev, 0, (ino_t)inode, &vp, &dummy); - if (getuerror()) { - return -1; - } - IWRITE_LOCK(ip); - if (ip->i_vicemagic != VICEMAGIC) - setuerror(EPERM); - else if (ip->i_vicep1 != inode_p1) - setuerror(ENXIO); - else { - ip->i_nlink += amount; - if (ip->i_nlink == 0) { - ip->i_vicemagic = 0; - ip->i_cflag &= ~CMNEW; - } - ip->i_flag |= ICHG; - commit(1, ip); /* always commit */ + ip = igetinode((dev_t) dev, 0, (ino_t) inode, &vp, &dummy); + if (getuerror()) { + return -1; + } + IWRITE_LOCK(ip); + if (ip->i_vicemagic != VICEMAGIC) + setuerror(EPERM); + else if (ip->i_vicep1 != inode_p1) + setuerror(ENXIO); + else { + ip->i_nlink += amount; + if (ip->i_nlink == 0) { + ip->i_vicemagic = 0; + ip->i_cflag &= ~CMNEW; } - IWRITE_UNLOCK(ip); - VNOP_RELE(vp); + ip->i_flag |= ICHG; + commit(1, ip); /* always commit */ + } + IWRITE_UNLOCK(ip); + VNOP_RELE(vp); /* ICACHE_LOCK(); iput(ip, 0); ICACHE_UNLOCK(); */ - return getuerror() ? -1 : 0; + return getuerror()? -1 : 0; } diff --git a/src/afs/AIX/osi_machdep.h b/src/afs/AIX/osi_machdep.h index 110ef7c4c..f52c4c11b 100644 --- a/src/afs/AIX/osi_machdep.h +++ b/src/afs/AIX/osi_machdep.h @@ -70,7 +70,7 @@ extern simple_lock_data afs_global_lock; } while(0) #define ISAFS_GLOCK() lock_mine((void *)&afs_global_lock) -#define AFS_RXGLOCK() +#define AFS_RXGLOCK() #define AFS_RXGUNLOCK() #define ISAFS_RXGLOCK() 1 #endif diff --git a/src/afs/AIX/osi_misc.c b/src/afs/AIX/osi_misc.c index 80ff5cc91..b89229c3e 100644 --- a/src/afs/AIX/osi_misc.c +++ b/src/afs/AIX/osi_misc.c @@ -17,47 +17,48 @@ */ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_misc.c,v 1.1.1.4 2001/07/14 22:19:33 hartmans Exp $"); - -#include "../h/systm.h" -#include "../h/types.h" -#include "../h/errno.h" -#include "../h/stat.h" -#include "../h/user.h" -#include "../h/uio.h" -#include "../h/vattr.h" -#include "../h/file.h" -#include "../h/vfs.h" -#include "../h/chownx.h" -#include "../h/systm.h" -#include "../h/access.h" -#include "../rpc/types.h" -#include "../afs/osi_vfs.h" -#include "../netinet/in.h" -#include "../h/mbuf.h" -#include "../rpc/types.h" -#include "../rpc/xdr.h" -#include "../h/vmuser.h" -#include "../h/syspest.h" - -#include "../afs/stds.h" -#include "../afs/afs_osi.h" +#include "afs/param.h" + +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_misc.c,v 1.7 2003/07/15 23:14:17 shadow Exp $"); + +#include "h/systm.h" +#include "h/types.h" +#include "h/errno.h" +#include "h/stat.h" +#include "h/user.h" +#include "h/uio.h" +#include "h/vattr.h" +#include "h/file.h" +#include "h/vfs.h" +#include "h/chownx.h" +#include "h/systm.h" +#include "h/access.h" +#include "rpc/types.h" +#include "osi_vfs.h" +#include "netinet/in.h" +#include "h/mbuf.h" +#include "rpc/types.h" +#include "rpc/xdr.h" +#include "h/vmuser.h" +#include "h/syspest.h" + +#include "afs/stds.h" +#include "afs/afs_osi.h" #define RFTP_INTERNALS 1 -#include "../afs/volerrors.h" -#include "../afsint/afsint.h" -#include "../afsint/vldbint.h" -#include "../afs/lock.h" -#include "../afs/exporter.h" -#include "../afs/afs.h" -#include "../afs/afs_stats.h" +#include "afs/volerrors.h" +#include "afsint.h" +#include "vldbint.h" +#include "afs/lock.h" +#include "afs/exporter.h" +#include "afs/afs.h" +#include "afs/afs_stats.h" /* In Aix one may specify an init routine routine which is called once during * initialization of all gfs; one day we might need to actual do somehing here. */ Afs_init(gfsp) -char *gfsp; /* this is really struct gfs *, but we do not use it */ + char *gfsp; /* this is really struct gfs *, but we do not use it */ { extern int afs_gn_strategy(); #define AFS_VM_BUFS 50 @@ -65,7 +66,7 @@ char *gfsp; /* this is really struct gfs *, but we do not use it */ /* For now nothing special is required during AFS initialization. */ AFS_STATCNT(afs_init); - (void) vm_mount(D_REMOTE, afs_gn_strategy, AFS_VM_BUFS); + (void)vm_mount(D_REMOTE, afs_gn_strategy, AFS_VM_BUFS); return 0; } @@ -82,15 +83,19 @@ char *gfsp; /* this is really struct gfs *, but we do not use it */ */ int gop_rdwr(rw, vp, base, len, offset, segflg, unit, aresid) -enum uio_rw rw; -struct vnode *vp; -caddr_t base; -off_t *offset; -int len, segflg; -int *aresid; -int unit; /* Ignored */ + enum uio_rw rw; + struct vnode *vp; + caddr_t base; +#ifdef AFS_64BIT_KERNEL + offset_t *offset; +#else + off_t *offset; +#endif + int len, segflg; + int *aresid; + int unit; /* Ignored */ { - struct uio uio_struct; + struct uio uio_struct; struct iovec uiovector; register int code; @@ -106,8 +111,16 @@ int unit; /* Ignored */ uio_struct.uio_resid = len; uio_struct.uio_fmode = (rw == UIO_READ ? FREAD : FWRITE); - code = VNOP_RDWR(vp, rw, (rw == UIO_READ ? FREAD : FWRITE), &uio_struct, - NULL, NULL, NULL, &afs_osi_cred); +#ifdef AFS_64BIT_KERNEL + code = + VNOP_RDWR(vp, rw, (int32long64_t) (rw == UIO_READ ? FREAD : FWRITE), + &uio_struct, (ext_t) 0, (caddr_t) 0, (struct vattr *)0, + &afs_osi_cred); +#else + code = + VNOP_RDWR(vp, rw, (rw == UIO_READ ? FREAD : FWRITE), &uio_struct, + NULL, NULL, NULL, &afs_osi_cred); +#endif *aresid = uio_struct.uio_resid; return code; } @@ -124,7 +137,7 @@ int unit; /* Ignored */ * no linked list of gnodes to remove this element from. */ aix_gnode_rele(vp) -struct vnode *vp; + struct vnode *vp; { register struct vnode *tvp; register struct vfs *vfsp = vp->v_vfsp; @@ -138,12 +151,12 @@ struct vnode *vp; if (vp->v_vfsprev != NULL) vp->v_vfsprev->v_vfsnext = vp->v_vfsnext; - endgnode: - /* Free the allocated gnode that was accompanying the vcache's vnode */ - if (vp->v_gnode) { - osi_FreeSmallSpace(vp->v_gnode); - vp->v_gnode = 0; - } + endgnode: + /* Free the allocated gnode that was accompanying the vcache's vnode */ + if (vp->v_gnode) { + osi_FreeSmallSpace(vp->v_gnode); + vp->v_gnode = 0; + } return 0; } @@ -154,11 +167,11 @@ struct vnode *vp; * Note that it must NOT set errno. */ -afs_suser() { +afs_suser() +{ register rc; char err; - + rc = suser(&err); return rc; } - diff --git a/src/afs/AIX/osi_prototypes.h b/src/afs/AIX/osi_prototypes.h index c869dc085..25f551258 100644 --- a/src/afs/AIX/osi_prototypes.h +++ b/src/afs/AIX/osi_prototypes.h @@ -10,6 +10,9 @@ #ifndef _OSI_PROTOTYPES_H_ #define _OSI_PROTOTYPES_H_ +/* osi_file.c */ +extern afs_rwlock_t afs_xosi; + /* osi_groups.c */ extern void afs_aix_SetupPagRefCount(void); diff --git a/src/afs/AIX/osi_sleep.c b/src/afs/AIX/osi_sleep.c index 06a058224..b5cd4dfde 100644 --- a/src/afs/AIX/osi_sleep.c +++ b/src/afs/AIX/osi_sleep.c @@ -8,44 +8,47 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_sleep.c,v 1.1.1.4 2001/07/14 22:19:33 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_sleep.c,v 1.10 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok); -void afs_osi_Wakeup(char *event); -void afs_osi_Sleep(char *event); static char waitV; -static void AfsWaitHack(struct trb *trb) +static void +AfsWaitHack(struct trb *trb) { AFS_STATCNT(WaitHack); e_clear_wait(trb->func_data, THREAD_TIMED_OUT); } -void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) +void +afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) { AFS_STATCNT(osi_InitWaitHandle); achandle->proc = (caddr_t) 0; } /* cancel osi_Wait */ -void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) { caddr_t proc; AFS_STATCNT(osi_CancelWait); proc = achandle->proc; - if (proc == 0) return; - achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ + if (proc == 0) + return; + achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ afs_osi_Wakeup(&waitV); } @@ -53,13 +56,14 @@ void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) * Waits for data on ahandle, or ams ms later. ahandle may be null. * Returns 0 if timeout and EINTR if signalled. */ -int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) +int +afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) { int code; afs_int32 endTime, tid; AFS_STATCNT(osi_Wait); - endTime = osi_Time() + (ams/1000); + endTime = osi_Time() + (ams / 1000); if (ahandle) ahandle->proc = (caddr_t) thread_self(); do { @@ -67,7 +71,8 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) code = 0; code = osi_TimedSleep(&waitV, ams, aintok); - if (code) break; /* if something happened, quit now */ + if (code) + break; /* if something happened, quit now */ /* if we we're cancelled, quit now */ if (ahandle && (ahandle->proc == (caddr_t) 0)) { /* we've been signalled */ @@ -85,19 +90,20 @@ typedef struct afs_event { char *event; /* lwp event: an address */ int refcount; /* Is it in use? */ int seq; /* Sequence number: this is incremented - by wakeup calls; wait will not return until - it changes */ - int cond; + * by wakeup calls; wait will not return until + * it changes */ + tid_t cond; } afs_event_t; #define HASHSIZE 128 -afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */ +afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */ #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1)); int afs_evhashcnt = 0; /* Get and initialize event structure corresponding to lwp event (i.e. address) * */ -static afs_event_t *afs_getevent(char *event) +static afs_event_t * +afs_getevent(char *event) { afs_event_t *evp, *newp = 0; int hashcode; @@ -115,7 +121,7 @@ static afs_event_t *afs_getevent(char *event) evp = evp->next; } if (!newp) { - newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t)); + newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t)); afs_evhashcnt++; newp->next = afs_evhasht[hashcode]; afs_evhasht[hashcode] = newp; @@ -131,7 +137,8 @@ static afs_event_t *afs_getevent(char *event) #define relevent(evp) ((evp)->refcount--) -void afs_osi_Sleep(char *event) +void +afs_osi_Sleep(void *event) { struct afs_event *evp; int seq; @@ -148,6 +155,13 @@ void afs_osi_Sleep(char *event) relevent(evp); } +int +afs_osi_SleepSig(void *event) +{ + afs_osi_Sleep(event); + return 0; +} + /* osi_TimedSleep * * Arguments: @@ -157,7 +171,8 @@ void afs_osi_Sleep(char *event) * * Returns 0 if timeout and EINTR if signalled. */ -static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) +static int +osi_TimedSleep(char *event, afs_int32 ams, int aintok) { int code = 0; struct afs_event *evp; @@ -166,7 +181,7 @@ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) int rc; ticks.tv_sec = ams / 1000; - ticks.tv_nsec = (ams - (ticks.tv_sec * 1000) ) * 1000000; + ticks.tv_nsec = (ams - (ticks.tv_sec * 1000)) * 1000000; evp = afs_getevent(event); @@ -175,7 +190,7 @@ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) if (trb == NULL) osi_Panic("talloc returned NULL"); trb->flags = 0; - trb->func = AfsWaitHack; + trb->func = AfsWaitHack; trb->eventlist = EVENT_NULL; trb->ipri = INTTIMER; trb->func_data = thread_self(); @@ -185,25 +200,29 @@ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) AFS_GUNLOCK(); tstart(trb); rc = e_block_thread(); - while(tstop(trb)); + while (tstop(trb)); if (rc == THREAD_INTERRUPTED) code = EINTR; tfree(trb); AFS_GLOCK(); - + relevent(evp); return code; } -void afs_osi_Wakeup(char *event) +int +afs_osi_Wakeup(void *event) { + int ret = 1; struct afs_event *evp; evp = afs_getevent(event); if (evp->refcount > 1) { - evp->seq++; + evp->seq++; e_wakeup(&evp->cond); + ret = 0; } relevent(evp); + return ret; } diff --git a/src/afs/AIX/osi_timeout.c b/src/afs/AIX/osi_timeout.c index cbdab5616..5f957ff0e 100644 --- a/src/afs/AIX/osi_timeout.c +++ b/src/afs/AIX/osi_timeout.c @@ -13,21 +13,22 @@ * Implements: */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_timeout.c,v 1.1.1.5 2001/09/11 14:24:52 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_timeout.c,v 1.7 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ #include "sys/limits.h" #include "sys/types.h" #include "sys/user.h" #include "sys/pri.h" -#include "sys/priv.h" /* XXX */ +#include "sys/priv.h" /* XXX */ #include "sys/lockl.h" #include "sys/malloc.h" -#include /* For the timer related defines */ -#include /* for the serialization defines */ +#include /* For the timer related defines */ +#include /* for the serialization defines */ /* NOTE: This lock makes the callout table MP-safe. timeout itself could * be subject to deadlocks if used for anything more complex than we are @@ -39,320 +40,306 @@ Simple_lock afs_callout_lock; #define AFS_UNLOCK_ENABLE(_pri, _lock) unlock_enable((_pri), (_lock)) -struct tos { - struct tos *toprev; /* previous tos in callout table*/ - struct tos *tonext; /* next tos in callout table */ - struct trb *trb; /* this timer request block */ - afs_int32 type; - long p1; +struct tos { + struct tos *toprev; /* previous tos in callout table */ + struct tos *tonext; /* next tos in callout table */ + struct trb *trb; /* this timer request block */ + afs_int32 type; + long p1; }; -struct callo { - int ncallo; /* number of callout table elements */ - struct tos *head; /* callout table head element */ +struct callo { + int ncallo; /* number of callout table elements */ + struct tos *head; /* callout table head element */ }; -struct callo afs_callo = {0, NULL};/* callout table anchor */ +struct callo afs_callo = { 0, NULL }; /* callout table anchor */ -static void timeout_end(struct trb *); /* timeout()'s timeout function */ -extern void tstart(struct trb *); -extern void i_enable(int); +static void timeout_end(struct trb *); /* timeout()'s timeout function */ +extern void tstart(struct trb *); +extern void i_enable(int); -void timeout( - register void (*func)(), /* function to call at timeout*/ - register caddr_t arg, /* It's argument. */ - register int ticks, /* when to set timeout for */ - register int type, - register char *p1) +void +timeout(register void (*func) (), /* function to call at timeout */ + register caddr_t arg, /* It's argument. */ + register int ticks, /* when to set timeout for */ + register int type, register char *p1) { - register int ipri; /* caller's interrupt priority */ - register struct tos *tos; /* tos to use for timeout */ - register struct trb *trb; /* trb in the tos being used */ - struct itimerstruc_t tv; /* timeout interval */ - - tv.it_value.tv_sec = ticks / HZ; - tv.it_value.tv_nsec = (ticks % HZ) * (NS_PER_SEC / HZ); - - osi_Assert(afs_callo.ncallo != 0); - -timeout_retry: - - ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); - /* - * Run the callout table chain to see if there is already a pending - * timeout for the specified function. If so, that timeout will - * be cancelled and the tos re-used. - */ - for(tos = afs_callo.head; tos != NULL; tos = tos->tonext) { - if((tos->trb->tof == func) && (tos->trb->func_data == (ulong) arg)) { - break; - } + register int ipri; /* caller's interrupt priority */ + register struct tos *tos; /* tos to use for timeout */ + register struct trb *trb; /* trb in the tos being used */ + struct itimerstruc_t tv; /* timeout interval */ + + tv.it_value.tv_sec = ticks / HZ; + tv.it_value.tv_nsec = (ticks % HZ) * (NS_PER_SEC / HZ); + + osi_Assert(afs_callo.ncallo != 0); + + timeout_retry: + + ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); + /* + * Run the callout table chain to see if there is already a pending + * timeout for the specified function. If so, that timeout will + * be cancelled and the tos re-used. + */ + for (tos = afs_callo.head; tos != NULL; tos = tos->tonext) { + if ((tos->trb->tof == func) && (tos->trb->func_data == (ulong) arg)) { + break; + } + } + + /* + * If a pending timeout for the specified function was NOT found, + * then the callout table chain will have to be run to find an + * unused tos. + */ + if (tos == NULL) { + for (tos = afs_callo.head; tos != NULL; tos = tos->tonext) { + if (tos->trb->tof == NULL) { + break; + } } /* - * If a pending timeout for the specified function was NOT found, - * then the callout table chain will have to be run to find an - * unused tos. + * If there isn't an available tos, then there is no error + * recovery. This means that either the caller has not + * correctly registered the number of callout table entries + * that would be needed or is incorrectly using the ones that + * were registered. Either way, panic is the only recourse. */ - if(tos == NULL) { - for(tos = afs_callo.head; tos != NULL; tos = tos->tonext) { - if(tos->trb->tof == NULL) { - break; - } - } - - /* - * If there isn't an available tos, then there is no error - * recovery. This means that either the caller has not - * correctly registered the number of callout table entries - * that would be needed or is incorrectly using the ones that - * were registered. Either way, panic is the only recourse. - */ - osi_Assert(tos != NULL); - } - /* - * A pending timeout for the specified function WAS found. - * If the request is still active, stop it. - */ - while (tstop(tos->trb)) { - AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); - goto timeout_retry; - } - - tos->type = type; /* Temp */ - tos->p1 = (long)p1; /* Temp */ - tos->trb->knext = NULL; - tos->trb->kprev = NULL; - tos->trb->flags = 0; - tos->trb->timeout = tv; - tos->trb->tof = func; - tos->trb->func = timeout_end; - tos->trb->func_data = (ulong) arg; - tos->trb->ipri = INTTIMER; - tos->trb->id = -1; - tstart(tos->trb); - + osi_Assert(tos != NULL); + } + /* + * A pending timeout for the specified function WAS found. + * If the request is still active, stop it. + */ + while (tstop(tos->trb)) { AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); + goto timeout_retry; + } + + tos->type = type; /* Temp */ + tos->p1 = (long)p1; /* Temp */ + tos->trb->knext = NULL; + tos->trb->kprev = NULL; + tos->trb->flags = 0; + tos->trb->timeout = tv; + tos->trb->tof = func; + tos->trb->func = timeout_end; + tos->trb->func_data = (ulong) arg; + tos->trb->ipri = INTTIMER; + tos->trb->id = -1; + tstart(tos->trb); + + AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); } -void untimeout( -register void (*func)(), -register ulong arg) +void +untimeout(register void (*func) (), register ulong arg) { - register int ipri; /* caller's interrupt priority */ - register struct tos *tos; /* tos to walk callout table */ - register struct trb *trb; /* trb for this tos */ + register int ipri; /* caller's interrupt priority */ + register struct tos *tos; /* tos to walk callout table */ + register struct trb *trb; /* trb for this tos */ - untimeout_retry: + untimeout_retry: - ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); - /* Run the callout table chain looking for the timeout. */ - for(tos = afs_callo.head; tos != NULL; tos = tos->tonext) { - if(tos->trb->tof == func && tos->trb->func_data == arg) { - break; - } + ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); + /* Run the callout table chain looking for the timeout. */ + for (tos = afs_callo.head; tos != NULL; tos = tos->tonext) { + if (tos->trb->tof == func && tos->trb->func_data == arg) { + break; } + } - if(tos) { - /* - * Found it on the timeout list - stop the pending timeout - * if it is active. - */ - while(tstop(tos->trb)) { - AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); - goto untimeout_retry; - } - - /* Mark this callout table entry as free. */ - tos->trb->knext = NULL; - tos->trb->kprev = NULL; - tos->trb->tof = NULL; + if (tos) { + /* + * Found it on the timeout list - stop the pending timeout + * if it is active. + */ + while (tstop(tos->trb)) { + AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); + goto untimeout_retry; } - AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); + + /* Mark this callout table entry as free. */ + tos->trb->knext = NULL; + tos->trb->kprev = NULL; + tos->trb->tof = NULL; + } + AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); } -static void timeout_end( -struct trb *trb) /* trb of the current timeout */ -{ - register void (*func)(); /* function to call at timeout */ - int ipri; - ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); +static void +timeout_end(struct trb *trb) +{ /* trb of the current timeout */ + register void (*func) (); /* function to call at timeout */ + int ipri; + ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); - func = trb->tof; - trb->func = NULL; - trb->tof = NULL; /* Zero out pointer to user function */ + func = trb->tof; + trb->func = NULL; + trb->tof = NULL; /* Zero out pointer to user function */ - AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); + AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); - (* func)(trb->func_data); - /* for compatibility with untimeout() */ + (*func) (trb->func_data); + /* for compatibility with untimeout() */ } -int timeoutcf( - register int cocnt) /* # entries to change callout table by */ -{ - register int ipri; /* caller's interrupt priority */ - register int rv; /* return value to the caller */ - register struct tos *tos; /* tos to add to/remove from table */ - register struct trb *trb; /* trb in the tos to be added/removed */ +int +timeoutcf(register int cocnt) +{ /* # entries to change callout table by */ + register int ipri; /* caller's interrupt priority */ + register int rv; /* return value to the caller */ + register struct tos *tos; /* tos to add to/remove from table */ + register struct trb *trb; /* trb in the tos to be added/removed */ - rv = 0; + rv = 0; - if(cocnt > 0) { - /* - * Callout table is being enlarged - keep working until the - * right number of elements have been added. - */ - while(cocnt > 0) { - /* Allocate a timer request block. */ - trb = (struct trb *) talloc(); - - /* - * If the low-level timer service could not provide - * a trb, the callout table can't be expanded any - * more so get out. - */ - if(trb == NULL) { - rv = -1; - break; - } - - /* Allocate memory for the callout table structure. */ - tos = (struct tos *) - xmalloc((uint)sizeof(struct tos), (uint)0, pinned_heap); - - /* - * If memory couldn't be allocated for the tos, the - * callout table can't be expanded any more so get out. - */ - if(tos == NULL) { - rv = -1; - break; - } - else { - memset(tos, 0, sizeof(struct tos)); - } - - /* The trb and the tos were both allocated. */ - tos->trb = trb; + if (cocnt > 0) { + /* + * Callout table is being enlarged - keep working until the + * right number of elements have been added. + */ + while (cocnt > 0) { + /* Allocate a timer request block. */ + trb = (struct trb *)talloc(); + + /* + * If the low-level timer service could not provide + * a trb, the callout table can't be expanded any + * more so get out. + */ + if (trb == NULL) { + rv = -1; + break; + } + + /* Allocate memory for the callout table structure. */ + tos = (struct tos *) + xmalloc((uint) sizeof(struct tos), (uint) 0, pinned_heap); + + /* + * If memory couldn't be allocated for the tos, the + * callout table can't be expanded any more so get out. + */ + if (tos == NULL) { + rv = -1; + break; + } else { + memset(tos, 0, sizeof(struct tos)); + } + + /* The trb and the tos were both allocated. */ + tos->trb = trb; #ifdef DEBUG - /* - * Debug code to ensure that the low-level timer - * service talloc() clears out the pointers. - */ - osi_Assert(trb->knext == NULL); - osi_Assert(trb->kprev == NULL); + /* + * Debug code to ensure that the low-level timer + * service talloc() clears out the pointers. + */ + osi_Assert(trb->knext == NULL); + osi_Assert(trb->kprev == NULL); #endif /* DEBUG */ - ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); - if(afs_callo.head == NULL) { - /* - * The callout table is currently empty. This - * is the easy case, just set the head of the - * callout chain to this tos. - */ - afs_callo.head = tos; - } - else { - /* - * The callout table is not empty. Chain this - * trb to the head of the callout chain. - */ - tos->tonext = afs_callo.head; - afs_callo.head->toprev = tos; - afs_callo.head = tos; - } - - /* Just finished adding a trb to the callout table. */ - afs_callo.ncallo++; - cocnt--; - AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); - } - } - else { + ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); + if (afs_callo.head == NULL) { /* - * Callout table is being shrunk - keep working until the - * right number of elements have been removed being careful - * only to remove elements which do not belong to timeout - * requests that are currently active. + * The callout table is currently empty. This + * is the easy case, just set the head of the + * callout chain to this tos. */ - if(cocnt < 0) { - - /* - * There had better be at least as many tos's in - * the callout table as the size by which the caller - * wants to decrease the size of the table. - */ - osi_Assert(afs_callo.ncallo >= -cocnt); - - while(cocnt < 0) { - - /* - * Start from the head of the callout chain, - * making sure that there is a tos at the - * head (i.e. that there is a callout chain). - */ - ipri = AFS_DISABLE_LOCK(INTMAX, - &afs_callout_lock); - tos = afs_callo.head; - osi_Assert(tos != NULL); - - /* - * Keep walking down the callout chain until - * a tos is found which is not currently - * active. - */ - while((tos != NULL) && - (tos->trb->tof != NULL)) { - tos = tos->tonext; - } - - /* - * If trb is not NULL, then there was not a - * callout table entry that wasn't set to - * timeout. Panic. - */ - osi_Assert(tos != NULL); - - /* - * Found a free callout table element, free - * it and remove it from the callout table. - */ - tfree(tos->trb); - if(afs_callo.head == tos) { - afs_callo.head = tos->tonext; - if(afs_callo.head != NULL) { - afs_callo.head->toprev = NULL; - } - } - else { - osi_Assert(tos->toprev != NULL); - tos->toprev->tonext = tos->tonext; - if(tos->tonext != NULL) { - tos->tonext->toprev = - tos->toprev; - } - } - /* - * Just finished removing a trb from the - * callout table. - */ - afs_callo.ncallo--; - cocnt++; - AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); - xmfree((void *)tos, pinned_heap); - - } - } + afs_callo.head = tos; + } else { + /* + * The callout table is not empty. Chain this + * trb to the head of the callout chain. + */ + tos->tonext = afs_callo.head; + afs_callo.head->toprev = tos; + afs_callo.head = tos; + } + + /* Just finished adding a trb to the callout table. */ + afs_callo.ncallo++; + cocnt--; + AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); } + } else { + /* + * Callout table is being shrunk - keep working until the + * right number of elements have been removed being careful + * only to remove elements which do not belong to timeout + * requests that are currently active. + */ + if (cocnt < 0) { - return(rv); -} + /* + * There had better be at least as many tos's in + * the callout table as the size by which the caller + * wants to decrease the size of the table. + */ + osi_Assert(afs_callo.ncallo >= -cocnt); + + while (cocnt < 0) { + + /* + * Start from the head of the callout chain, + * making sure that there is a tos at the + * head (i.e. that there is a callout chain). + */ + ipri = AFS_DISABLE_LOCK(INTMAX, &afs_callout_lock); + tos = afs_callo.head; + osi_Assert(tos != NULL); + /* + * Keep walking down the callout chain until + * a tos is found which is not currently + * active. + */ + while ((tos != NULL) && (tos->trb->tof != NULL)) { + tos = tos->tonext; + } + /* + * If trb is not NULL, then there was not a + * callout table entry that wasn't set to + * timeout. Panic. + */ + osi_Assert(tos != NULL); + /* + * Found a free callout table element, free + * it and remove it from the callout table. + */ + tfree(tos->trb); + if (afs_callo.head == tos) { + afs_callo.head = tos->tonext; + if (afs_callo.head != NULL) { + afs_callo.head->toprev = NULL; + } + } else { + osi_Assert(tos->toprev != NULL); + tos->toprev->tonext = tos->tonext; + if (tos->tonext != NULL) { + tos->tonext->toprev = tos->toprev; + } + } + /* + * Just finished removing a trb from the + * callout table. + */ + afs_callo.ncallo--; + cocnt++; + AFS_UNLOCK_ENABLE(ipri, &afs_callout_lock); + xmfree((void *)tos, pinned_heap); + } + } + } + return (rv); +} diff --git a/src/afs/AIX/osi_vfs.h b/src/afs/AIX/osi_vfs.h index 4b98e8b70..3e2842ccf 100644 --- a/src/afs/AIX/osi_vfs.h +++ b/src/afs/AIX/osi_vfs.h @@ -34,10 +34,9 @@ * if _SUN is defined, this is in vnode.h (at least today... who knows where * they will hide it tomorrow) */ -enum vcexcl {NONEXCL, EXCL}; /* (non)exclusive create */ +enum vcexcl { NONEXCL, EXCL }; /* (non)exclusive create */ #endif -struct buf *getblk(), *geteblk(), *breada(), *bread(); +struct buf *getblk(), *geteblk(), *breada(), *bread(); #define b_actf av_forw #define dbtob(db) ((unsigned)(db) << 9) /* (db * 512) */ - diff --git a/src/afs/AIX/osi_vfsops.c b/src/afs/AIX/osi_vfsops.c index 7fc5b38c7..6b051fced 100644 --- a/src/afs/AIX/osi_vfsops.c +++ b/src/afs/AIX/osi_vfsops.c @@ -11,19 +11,20 @@ * osi_vfsops.c for AIX */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_vfsops.c,v 1.1.1.5 2002/05/10 23:43:33 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_vfsops.c,v 1.11 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics stuff */ #ifdef AFS_AIX_IAUTH_ENV -#include "../afs/nfsclient.h" -#include "../afs/exporter.h" -extern struct afs_exporter *afs_nfsexporter; +#include "afs/nfsclient.h" +#include "afs/exporter.h" +extern struct afs_exporter *afs_nfsexporter; #endif #define AFS_VFSLOCK_DECL register int glockOwner = ISAFS_GLOCK() @@ -34,12 +35,13 @@ struct vfs *afs_globalVFS = 0; struct vcache *afs_globalVp = 0; -static int afs_root_nolock (struct vfs *afsp, struct vnode **avpp); +static int afs_root_nolock(struct vfs *afsp, struct vnode **avpp); -static int afs_mount(afsp, path, data) - char *path; - caddr_t data; - struct vfs *afsp; +static int +afs_mount(afsp, path, data) + char *path; + caddr_t data; + struct vfs *afsp; { struct vnode *afsrootvp = NULL; int error; @@ -52,38 +54,43 @@ static int afs_mount(afsp, path, data) * it well. */ AFS_VFSUNLOCK(); - return (setuerror(EBUSY)); + return (setuerror(EBUSY)); } afs_globalVFS = afsp; afsp->vfs_bsize = 8192; + afsp->vfs_count = 0; +#ifdef AFS_64BIT_CLIENT + afsp->vfs_flag |= VFS_DEVMOUNT; +#endif /* AFS_64BIT_CLIENT */ - afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ - afsp->vfs_fsid.val[1] = AFS_VFSFSID; + afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ + afsp->vfs_fsid.val[1] = AFS_VFSFSID; /* For AFS, we don't allow file over file mounts. */ - if (afsp->vfs_mntdover->v_type != VDIR) - return(ENOTDIR); - /* try to get the root vnode, but don't worry if you don't. The actual - * setting of the root vnode (vfs_mntd) is done in afs_root, so that it - * get re-eval'd at the right time if things aren't working when we - * first try the mount. - */ + if (afsp->vfs_mntdover->v_type != VDIR) + return (ENOTDIR); + /* try to get the root vnode, but don't worry if you don't. The actual + * setting of the root vnode (vfs_mntd) is done in afs_root, so that it + * get re-eval'd at the right time if things aren't working when we + * first try the mount. + */ afs_root_nolock(afsp, &afsrootvp); afsp->vfs_mntdover->v_mvfsp = afsp; afsp->vfs_mdata->vmt_flags |= MNT_REMOTE; #ifdef AFS_AIX_IAUTH_ENV - if (afs_iauth_register()<0) + if (afs_iauth_register() < 0) afs_warn("Can't register AFS iauth interface.\n"); #endif AFS_VFSUNLOCK(); return 0; } -static int afs_unmount (struct vfs *afsp, int flag) +static int +afs_unmount(struct vfs *afsp, int flag) { AFS_VFSLOCK_DECL; AFS_VFSLOCK(); @@ -96,22 +103,25 @@ static int afs_unmount (struct vfs *afsp, int flag) return 0; } -static int afs_root_nolock (struct vfs *afsp, struct vnode **avpp) +static int +afs_root_nolock(struct vfs *afsp, struct vnode **avpp) { register afs_int32 code = 0; struct vrequest treq; - register struct vcache *tvp=0; + register struct vcache *tvp = 0; AFS_STATCNT(afs_root); if (afs_globalVp && (afs_globalVp->states & CStatd)) { tvp = afs_globalVp; } else { struct ucred *credp; + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + afs_globalVp = NULL; + } credp = crref(); - if (!(code = afs_InitReq(&treq, credp)) && - !(code = afs_CheckInit())) { - tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) { + tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); /* we really want this to stay around */ if (tvp) { afs_globalVp = tvp; @@ -124,12 +134,12 @@ static int afs_root_nolock (struct vfs *afsp, struct vnode **avpp) VN_HOLD(AFSTOV(tvp)); VN_LOCK(AFSTOV(tvp)); - AFSTOV(tvp)->v_flag |= VROOT; /* No-op on Ultrix 2.2 */ + AFSTOV(tvp)->v_flag |= VROOT; /* No-op on Ultrix 2.2 */ VN_UNLOCK(AFSTOV(tvp)); afs_globalVFS = afsp; *avpp = AFSTOV(tvp); - afsp->vfs_mntd = *avpp; + afsp->vfs_mntd = *avpp; } afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp, @@ -138,7 +148,8 @@ static int afs_root_nolock (struct vfs *afsp, struct vnode **avpp) } -static int afs_root (struct vfs *afsp, struct vnode **avpp) +static int +afs_root(struct vfs *afsp, struct vnode **avpp) { int code; AFS_VFSLOCK_DECL; @@ -148,8 +159,8 @@ static int afs_root (struct vfs *afsp, struct vnode **avpp) return code; } -static int afs_statfs(struct vfs *afsp, struct statfs *abp, - struct ucred *credp) +static int +afs_statfs(struct vfs *afsp, struct statfs *abp, struct ucred *credp) { AFS_VFSLOCK_DECL; AFS_VFSLOCK(); @@ -163,17 +174,18 @@ static int afs_statfs(struct vfs *afsp, struct statfs *abp, abp->f_vfstype = AFS_VFSFSID; abp->f_vfsnumber = afsp->vfs_number; abp->f_vfsoff = abp->f_vfslen = abp->f_vfsvers = -1; - abp->f_fsize = 4096; /* fundamental filesystem block size */ + abp->f_fsize = 4096; /* fundamental filesystem block size */ abp->f_fsid = afsp->vfs_fsid; - (void) strcpy(abp->f_fname, "/afs"); - (void) strcpy(abp->f_fpack, "AFS"); + (void)strcpy(abp->f_fname, "/afs"); + (void)strcpy(abp->f_fpack, "AFS"); abp->f_name_max = 256; AFS_VFSUNLOCK(); return 0; } -static int afs_sync() +static int +afs_sync() { AFS_VFSLOCK_DECL; AFS_VFSLOCK(); @@ -185,7 +197,8 @@ static int afs_sync() /* Note that the cred is only for AIX 4.1.5+ and AIX 4.2+ */ -static int afs_vget(struct vfs *vfsp, struct vnode **avcp, struct fileid *fidp, +static int +afs_vget(struct vfs *vfsp, struct vnode **avcp, struct fileid *fidp, struct ucred *credp) { int code; @@ -203,8 +216,8 @@ static int afs_vget(struct vfs *vfsp, struct vnode **avcp, struct fileid *fidp, } #endif - if ((code = afs_InitReq(&treq, credp))==0) { - code = afs_osi_vget((struct vcache**)avcp, fidp, &treq); + if ((code = afs_InitReq(&treq, credp)) == 0) { + code = afs_osi_vget((struct vcache **)avcp, fidp, &treq); } afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp, @@ -214,22 +227,26 @@ static int afs_vget(struct vfs *vfsp, struct vnode **avcp, struct fileid *fidp, AFS_VFSUNLOCK(); return code; } - -static int afs_badop() + +static int +afs_badop() { return EOPNOTSUPP; } struct vfsops Afs_vfsops = { - afs_mount, - afs_unmount, - afs_root, - afs_statfs, - afs_sync, - afs_vget, - afs_badop, /* vfs_cntl */ - afs_badop /* vfs_quotactl */ + afs_mount, + afs_unmount, + afs_root, + afs_statfs, + afs_sync, + afs_vget, + afs_badop, /* vfs_cntl */ + afs_badop /* vfs_quotactl */ +#ifdef AFS_AIX51_ENV + , afs_badop /* vfs_syncvfs */ +#endif }; /* diff --git a/src/afs/AIX/osi_vm.c b/src/afs/AIX/osi_vm.c index 46682c0a9..0c44b3315 100644 --- a/src/afs/AIX/osi_vm.c +++ b/src/afs/AIX/osi_vm.c @@ -8,13 +8,14 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_vm.c,v 1.1.1.5 2002/05/10 23:43:33 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_vm.c,v 1.9 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ /* Try to discard pages, in order to recycle a vcache entry. * @@ -31,9 +32,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_vm.c,v 1.1.1.5 2002/05/10 2 * therefore obsolescent. */ int -osi_VM_FlushVCache(avc, slept) - struct vcache *avc; - int *slept; +osi_VM_FlushVCache(struct vcache *avc, int *slept) { if (avc->vrefCount != 0) return EBUSY; @@ -70,46 +69,45 @@ osi_VM_FlushVCache(avc, slept) * re-obtained. */ void -osi_VM_StoreAllSegments(avc) - struct vcache *avc; +osi_VM_StoreAllSegments(struct vcache *avc) { - if (avc->vmh) { + if (avc->segid) { /* * The execsOrWriters test is done so that we don't thrash on * the vm_writep call below. We only initiate a pageout of the * dirty vm pages on the last store... * this is strictly a pragmatic decision, and _does_ break the - * advertised AFS consistency semantics. Without this hack, - * AIX systems panic under heavy load. I consider the current - * behavior a bug introduced to hack around a worse bug. XXX + * advertised AFS consistency semantics. Without this hack, + * AIX systems panic under heavy load. I consider the current + * behavior a bug introduced to hack around a worse bug. XXX * * Removed do_writep governing sync'ing behavior. - */ - ReleaseWriteLock(&avc->lock); /* XXX */ + */ + ReleaseWriteLock(&avc->lock); /* XXX */ AFS_GUNLOCK(); - vm_writep(avc->vmh, 0, MAXFSIZE/PAGESIZE -1 ); - vms_iowait(avc->vmh); + vm_writep(avc->segid, 0, MAXFSIZE / PAGESIZE - 1); + vms_iowait(avc->segid); AFS_GLOCK(); - ObtainWriteLock(&avc->lock,93); /* XXX */ + ObtainWriteLock(&avc->lock, 93); /* XXX */ /* * The following is necessary because of the following * asynchronicity: We open a file, write to it and - * close the file + * close the file * if CCore flag is set, we clear it and do the extra - * decrement ourselves now. - * If we're called by the CCore clearer, the CCore flag - * will already be clear, so we don't have to worry about - * clearing it twice. + * decrement ourselves now. + * If we're called by the CCore clearer, the CCore flag + * will already be clear, so we don't have to worry about + * clearing it twice. * avc was "VN_HELD" and "crheld" when CCore was set in * afs_FakeClose - */ + */ if (avc->states & CCore) { avc->states &= ~CCore; avc->opens--; avc->execsOrWriters--; - AFS_RELE(AFSTOV(avc)); - crfree((struct ucred *)avc->linkData); - avc->linkData = (char *)0; + AFS_RELE(AFSTOV(avc)); + crfree((struct ucred *)avc->linkData); + avc->linkData = NULL; } } } @@ -124,18 +122,15 @@ osi_VM_StoreAllSegments(avc) * be some pages around when we return, newly created by concurrent activity. */ void -osi_VM_TryToSmush(avc, acred, sync) - struct vcache *avc; - struct AFS_UCRED *acred; - int sync; +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { if (avc->segid) { ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); - vm_flushp(avc->segid, 0, MAXFSIZE/PAGESIZE - 1); - vms_iowait(avc->vmh); /* XXX Wait?? XXX */ + vm_flushp(avc->segid, 0, MAXFSIZE / PAGESIZE - 1); + vms_iowait(avc->segid); /* XXX Wait?? XXX */ AFS_GLOCK(); - ObtainWriteLock(&avc->lock,60); + ObtainWriteLock(&avc->lock, 60); } } @@ -144,16 +139,14 @@ osi_VM_TryToSmush(avc, acred, sync) * Locking: No lock is held, not even the global lock. */ void -osi_VM_FlushPages(avc, credp) - struct vcache *avc; - struct AFS_UCRED *credp; +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { if (avc->segid) { - vm_flushp(avc->segid, 0, MAXFSIZE/PAGESIZE - 1); - /* - * XXX We probably don't need to wait but better be safe XXX - */ - vms_iowait(avc->vmh); + vm_flushp(avc->segid, 0, MAXFSIZE / PAGESIZE - 1); + /* + * XXX We probably don't need to wait but better be safe XXX + */ + vms_iowait(avc->segid); } } @@ -164,14 +157,11 @@ osi_VM_FlushPages(avc, credp) * it only works on Solaris. */ void -osi_VM_Truncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { if (avc->segid) { - int firstpage = (alen + PAGESIZE-1)/PAGESIZE; - vm_releasep(avc->segid, firstpage, MAXFSIZE/PAGESIZE - firstpage); - vms_iowait(avc->vmh); /* Do we need this? */ + int firstpage = (alen + PAGESIZE - 1) / PAGESIZE; + vm_releasep(avc->segid, firstpage, MAXFSIZE / PAGESIZE - firstpage); + vms_iowait(avc->segid); /* Do we need this? */ } } diff --git a/src/afs/AIX/osi_vnodeops.c b/src/afs/AIX/osi_vnodeops.c index 8ca0b0d4d..3c814d002 100644 --- a/src/afs/AIX/osi_vnodeops.c +++ b/src/afs/AIX/osi_vnodeops.c @@ -8,46 +8,51 @@ */ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/AIX/osi_vnodeops.c,v 1.1.1.6 2002/05/10 23:43:34 hartmans Exp $"); - -#include "../h/systm.h" -#include "../h/types.h" -#include "../h/errno.h" -#include "../h/stat.h" -#include "../h/user.h" -#include "../h/uio.h" -#include "../h/vattr.h" -#include "../h/file.h" -#include "../h/vfs.h" -#include "../h/chownx.h" -#include "../h/systm.h" -#include "../h/access.h" -#include "../rpc/types.h" -#include "../afs/osi_vfs.h" -#include "../netinet/in.h" -#include "../h/mbuf.h" -#include "../h/vmuser.h" -#include "../h/shm.h" -#include "../rpc/types.h" -#include "../rpc/xdr.h" - -#include "../afs/stds.h" -#include "../afs/afs_osi.h" +#include "afs/param.h" + +RCSID + ("$Header: /cvs/openafs/src/afs/AIX/osi_vnodeops.c,v 1.15 2004/03/17 02:29:39 shadow Exp $"); + +#include "h/systm.h" +#include "h/types.h" +#include "h/errno.h" +#include "h/stat.h" +#include "h/user.h" +#include "h/uio.h" +#include "h/vattr.h" +#include "h/file.h" +#include "h/vfs.h" +#include "h/chownx.h" +#include "h/systm.h" +#include "h/access.h" +#ifdef AFS_AIX51_ENV +#include "h/acl.h" +#endif +#include "rpc/types.h" +#include "osi_vfs.h" +#include "netinet/in.h" +#include "h/mbuf.h" +#include "h/vmuser.h" +#include "h/shm.h" +#include "rpc/types.h" +#include "rpc/xdr.h" + +#include "afs/stds.h" +#include "afs/afs_osi.h" #define RFTP_INTERNALS 1 -#include "../afs/volerrors.h" -#include "../afsint/afsint.h" -#include "../afsint/vldbint.h" -#include "../afs/lock.h" -#include "../afs/exporter.h" -#include "../afs/afs.h" -#include "../afs/afs_chunkops.h" -#include "../afs/afs_stats.h" -#include "../afs/nfsclient.h" -#include "../afs/icl.h" -#include "../afs/prs_fs.h" -#include "../h/flock.h" +#include "afs/volerrors.h" +#include "afsint.h" +#include "vldbint.h" +#include "afs/lock.h" +#include "afs/exporter.h" +#include "afs/afs.h" +#include "afs/afs_chunkops.h" +#include "afs/afs_stats.h" +#include "afs/nfsclient.h" +#include "afs/icl.h" +#include "afs/prs_fs.h" +#include "h/flock.h" +#include "afsincludes.h" /* @@ -102,122 +107,140 @@ int afs_gn_enosys(); * declare a struct vnodeops and initialize it with ptrs to all functions */ struct vnodeops afs_gn_vnodeops = { - /* creation/naming/deletion */ - afs_gn_link, - afs_gn_mkdir, - afs_gn_mknod, - afs_gn_remove, - afs_gn_rename, - afs_gn_rmdir, - /* lookup, file handle stuff */ - afs_gn_lookup, - afs_gn_fid, - /* access to files */ - afs_gn_open, - afs_gn_create, - afs_gn_hold, - afs_gn_rele, - afs_gn_close, - afs_gn_map, - afs_gn_unmap, - /* manipulate attributes of files */ - afs_gn_access, - afs_gn_getattr, - afs_gn_setattr, - /* data update operations */ - afs_gn_fclear, - afs_gn_fsync, - afs_gn_ftrunc, - afs_gn_rdwr, - afs_gn_lockctl, - /* extensions */ - afs_gn_ioctl, - afs_gn_readlink, - afs_gn_select, - afs_gn_symlink, - afs_gn_readdir, - /* buffer ops */ - afs_gn_strategy, - /* security things */ - afs_gn_revoke, - afs_gn_getacl, - afs_gn_setacl, - afs_gn_getpcl, - afs_gn_setpcl, - afs_gn_enosys, /* vn_seek */ - afs_gn_enosys, /* vn_spare0 */ - afs_gn_enosys, /* vn_spare1 */ - afs_gn_enosys, /* vn_spare2 */ - afs_gn_enosys, /* vn_spare3 */ - afs_gn_enosys, /* vn_spare4 */ - afs_gn_enosys, /* vn_spare5 */ - afs_gn_enosys, /* vn_spare6 */ - afs_gn_enosys, /* vn_spare7 */ - afs_gn_enosys, /* vn_spare8 */ - afs_gn_enosys, /* vn_spare9 */ - afs_gn_enosys, /* vn_spareA */ - afs_gn_enosys, /* vn_spareB */ - afs_gn_enosys, /* vn_spareC */ - afs_gn_enosys, /* vn_spareD */ - afs_gn_enosys, /* vn_spareE */ - afs_gn_enosys /* vn_spareF */ + /* creation/naming/deletion */ + afs_gn_link, + afs_gn_mkdir, + afs_gn_mknod, + afs_gn_remove, + afs_gn_rename, + afs_gn_rmdir, + /* lookup, file handle stuff */ + afs_gn_lookup, + afs_gn_fid, + /* access to files */ + afs_gn_open, + afs_gn_create, + afs_gn_hold, + afs_gn_rele, + afs_gn_close, + afs_gn_map, + afs_gn_unmap, + /* manipulate attributes of files */ + afs_gn_access, + afs_gn_getattr, + afs_gn_setattr, + /* data update operations */ + afs_gn_fclear, + afs_gn_fsync, + afs_gn_ftrunc, + afs_gn_rdwr, + afs_gn_lockctl, + /* extensions */ + afs_gn_ioctl, + afs_gn_readlink, + afs_gn_select, + afs_gn_symlink, + afs_gn_readdir, + /* buffer ops */ + afs_gn_strategy, + /* security things */ + afs_gn_revoke, + afs_gn_getacl, + afs_gn_setacl, + afs_gn_getpcl, + afs_gn_setpcl, + afs_gn_enosys, /* vn_seek */ + afs_gn_enosys, /* vn_fsync_range */ + afs_gn_enosys, /* vn_create_attr */ + afs_gn_enosys, /* vn_finfo */ + afs_gn_enosys, /* vn_map_lloff */ + afs_gn_enosys, /* vn_readdir_eofp */ + afs_gn_enosys, /* vn_rdwr_attr */ + afs_gn_enosys, /* vn_memcntl */ + afs_gn_enosys, /* vn_spare7 */ + afs_gn_enosys, /* vn_spare8 */ + afs_gn_enosys, /* vn_spare9 */ + afs_gn_enosys, /* vn_spareA */ + afs_gn_enosys, /* vn_spareB */ + afs_gn_enosys, /* vn_spareC */ + afs_gn_enosys, /* vn_spareD */ + afs_gn_enosys, /* vn_spareE */ + afs_gn_enosys /* vn_spareF */ +#ifdef AFS_AIX51_ENV + , afs_gn_enosys, /* pagerBackRange */ + afs_gn_enosys, /* pagerGetFileSize */ + afs_gn_enosys, /* pagerReadAhead */ + afs_gn_enosys, /* pagerWriteBehind */ + afs_gn_enosys /* pagerEndCopy */ +#endif }; struct vnodeops *afs_ops = &afs_gn_vnodeops; int afs_gn_link(vp, dp, name, cred) -struct vnode *vp; -struct vnode *dp; -char *name; -struct ucred *cred; + struct vnode *vp; + struct vnode *dp; + char *name; + struct ucred *cred; { - int error; + int error; AFS_STATCNT(afs_gn_link); error = afs_link(vp, dp, name, cred); - afs_Trace3(afs_iclSetp, CM_TRACE_GNLINK, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace3(afs_iclSetp, CM_TRACE_GNLINK, ICL_TYPE_POINTER, vp, ICL_TYPE_STRING, name, ICL_TYPE_LONG, error); - return(error); + return (error); } int -afs_gn_mkdir(dp, name, mode, cred) -struct vnode *dp; -char *name; -int mode; -struct ucred *cred; +afs_gn_mkdir(dp, name, Mode, cred) + struct vnode *dp; + char *name; +#ifdef AFS_AIX51_ENV + int32long64_t Mode; +#else + int Mode; +#endif + struct ucred *cred; { - struct vattr va; - struct vnode *vp; - int error; + struct vattr va; + struct vnode *vp; + int error; + int mode = Mode; AFS_STATCNT(afs_gn_mkdir); VATTR_NULL(&va); va.va_type = VDIR; va.va_mode = (mode & 07777) & ~get_umask(); error = afs_mkdir(dp, name, &va, &vp, cred); - if (! error) { + if (!error) { AFS_RELE(vp); } - afs_Trace4(afs_iclSetp, CM_TRACE_GMKDIR, ICL_TYPE_POINTER, (afs_int32)vp, - ICL_TYPE_STRING, name, ICL_TYPE_LONG, mode, ICL_TYPE_LONG, error); - return(error); + afs_Trace4(afs_iclSetp, CM_TRACE_GMKDIR, ICL_TYPE_POINTER, vp, + ICL_TYPE_STRING, name, ICL_TYPE_LONG, mode, ICL_TYPE_LONG, + error); + return (error); } int -afs_gn_mknod(dp, name, mode, dev, cred) -struct vnode *dp; -char *name; -int mode; -dev_t dev; -struct ucred *cred; +afs_gn_mknod(dp, name, Mode, dev, cred) + struct vnode *dp; + char *name; +#ifdef AFS_AIX51_ENV + int Mode; +#else + int Mode; +#endif + dev_t dev; + struct ucred *cred; { - struct vattr va; - struct vnode *vp; - int error; + struct vattr va; + struct vnode *vp; + int error; + int mode = Mode; AFS_STATCNT(afs_gn_mknod); VATTR_NULL(&va); @@ -226,155 +249,171 @@ struct ucred *cred; /**** I'm not sure if suser() should stay here since it makes no sense in AFS; however the documentation says that one "should be super-user unless making a FIFO file. Others systems such as SUN do this checking in the early stages of mknod (before the abstraction), so it's equivalently the same! *****/ if (va.va_type != VFIFO && !suser(&error)) - return(EPERM); + return (EPERM); switch (va.va_type) { - case VDIR: - error = afs_mkdir(dp, name, &va, &vp, cred); - break; - case VNON: - error = EINVAL; - break; - case VBAD: - case VCHR: - case VBLK: - va.va_rdev = dev; - default: - error = afs_create(dp, name, &va, NONEXCL, mode, &vp, cred); + case VDIR: + error = afs_mkdir(dp, name, &va, &vp, cred); + break; + case VNON: + error = EINVAL; + break; + case VBAD: + case VCHR: + case VBLK: + va.va_rdev = dev; + default: + error = afs_create(dp, name, &va, NONEXCL, mode, &vp, cred); } - if (! error) { + if (!error) { AFS_RELE(vp); } - afs_Trace4(afs_iclSetp, CM_TRACE_GMKNOD, ICL_TYPE_POINTER, (afs_int32)vp, - ICL_TYPE_STRING, name, ICL_TYPE_LONG, mode, ICL_TYPE_LONG, error); - return(error); + afs_Trace4(afs_iclSetp, CM_TRACE_GMKNOD, ICL_TYPE_POINTER, (afs_int32) vp, + ICL_TYPE_STRING, name, ICL_TYPE_LONG, mode, ICL_TYPE_LONG, + error); + return (error); } int afs_gn_remove(vp, dp, name, cred) -struct vnode *vp; /* Ignored in AFS */ -struct vnode *dp; -char *name; -struct ucred *cred; + struct vnode *vp; /* Ignored in AFS */ + struct vnode *dp; + char *name; + struct ucred *cred; { - int error; + int error; - AFS_STATCNT(afs_gn_remove); - error = afs_remove(dp, name, cred); - afs_Trace3(afs_iclSetp, CM_TRACE_GREMOVE, ICL_TYPE_POINTER, (afs_int32)dp, - ICL_TYPE_STRING, name, ICL_TYPE_LONG, error); - return(error); + AFS_STATCNT(afs_gn_remove); + error = afs_remove(dp, name, cred); + afs_Trace3(afs_iclSetp, CM_TRACE_GREMOVE, ICL_TYPE_POINTER, dp, + ICL_TYPE_STRING, name, ICL_TYPE_LONG, error); + return (error); } int afs_gn_rename(vp, dp, name, tp, tdp, tname, cred) -struct vnode *dp; -char *name; -struct vnode *vp; /* Ignored in AFS */ -struct vnode *tp; /* Ignored in AFS */ -struct vnode *tdp; -char *tname; -struct ucred *cred; + struct vnode *dp; + char *name; + struct vnode *vp; /* Ignored in AFS */ + struct vnode *tp; /* Ignored in AFS */ + struct vnode *tdp; + char *tname; + struct ucred *cred; { - int error; + int error; - AFS_STATCNT(afs_gn_rename); + AFS_STATCNT(afs_gn_rename); error = afs_rename(dp, name, tdp, tname, cred); - afs_Trace4(afs_iclSetp, CM_TRACE_GRENAME, ICL_TYPE_POINTER, (afs_int32)dp, - ICL_TYPE_STRING, name, ICL_TYPE_STRING, tname, ICL_TYPE_LONG, error); - return(error); + afs_Trace4(afs_iclSetp, CM_TRACE_GRENAME, ICL_TYPE_POINTER, dp, + ICL_TYPE_STRING, name, ICL_TYPE_STRING, tname, ICL_TYPE_LONG, + error); + return (error); } int afs_gn_rmdir(vp, dp, name, cred) -struct vnode *vp; /* Ignored in AFS */ -struct vnode *dp; -char *name; -struct ucred *cred; + struct vnode *vp; /* Ignored in AFS */ + struct vnode *dp; + char *name; + struct ucred *cred; { - int error; + int error; - AFS_STATCNT(afs_gn_rmdir); + AFS_STATCNT(afs_gn_rmdir); error = afs_rmdir(dp, name, cred); if (error) { - if (error == 66 /* 4.3's ENOTEMPTY */) - error = EEXIST; /* AIX returns EEXIST where 4.3 used ENOTEMPTY */ + if (error == 66 /* 4.3's ENOTEMPTY */ ) + error = EEXIST; /* AIX returns EEXIST where 4.3 used ENOTEMPTY */ } - afs_Trace3(afs_iclSetp, CM_TRACE_GRMDIR, ICL_TYPE_POINTER, (afs_int32)dp, + afs_Trace3(afs_iclSetp, CM_TRACE_GRMDIR, ICL_TYPE_POINTER, dp, ICL_TYPE_STRING, name, ICL_TYPE_LONG, error); - return(error); + return (error); } int -afs_gn_lookup(dp, vpp, name, flags, vattrp, cred) -struct vattr *vattrp; -struct vnode *dp; -struct vnode **vpp; -char *name; -afs_uint32 flags; /* includes FOLLOW... */ -struct ucred *cred; +afs_gn_lookup(dp, vpp, name, Flags, vattrp, cred) + struct vattr *vattrp; + struct vnode *dp; + struct vnode **vpp; + char *name; +#ifdef AFS_AIX51_ENV + int32long64_t Flags; /* includes FOLLOW... */ +#else + afs_uint32 Flags; /* includes FOLLOW... */ +#endif + struct ucred *cred; { - int error; + int error; + int flags = Flags; - AFS_STATCNT(afs_gn_lookup); + AFS_STATCNT(afs_gn_lookup); error = afs_lookup(dp, name, vpp, cred); - afs_Trace3(afs_iclSetp, CM_TRACE_GLOOKUP, ICL_TYPE_POINTER, (afs_int32)dp, + afs_Trace3(afs_iclSetp, CM_TRACE_GLOOKUP, ICL_TYPE_POINTER, dp, ICL_TYPE_STRING, name, ICL_TYPE_LONG, error); - if (vattrp != NULL && error == 0) - afs_gn_getattr(*vpp, vattrp, cred); - return(error); + if (vattrp != NULL && error == 0) + afs_gn_getattr(*vpp, vattrp, cred); + return (error); } int afs_gn_fid(vp, fidp, cred) -struct vnode *vp; -struct fid *fidp; -struct ucred *cred; + struct vnode *vp; + struct fid *fidp; + struct ucred *cred; { - int error; + int error; AFS_STATCNT(afs_gn_fid); - error = afs_fid(vp, fidp); - afs_Trace3(afs_iclSetp, CM_TRACE_GFID, ICL_TYPE_POINTER, (afs_int32)vp, - ICL_TYPE_LONG, (afs_int32)fidp, ICL_TYPE_LONG, error); - return(error); + error = afs_fid(vp, fidp); + afs_Trace3(afs_iclSetp, CM_TRACE_GFID, ICL_TYPE_POINTER, vp, + ICL_TYPE_LONG, (afs_int32) fidp, ICL_TYPE_LONG, error); + return (error); } int -afs_gn_open(vp, flags, ext, vinfop, cred) -struct vnode *vp; -int flags; -int ext; /* Ignored in AFS */ -struct ucred **vinfop; /* return ptr for fp->f_vinfo, used as fp->f_cred */ -struct ucred *cred; -{ - int error; - struct vattr va; +afs_gn_open(vp, Flags, ext, vinfop, cred) + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t Flags; + ext_t ext; /* Ignored in AFS */ +#else + int Flags; + int ext; /* Ignored in AFS */ +#endif + struct ucred **vinfop; /* return ptr for fp->f_vinfo, used as fp->f_cred */ + struct ucred *cred; +{ + int error; + struct vattr va; struct vcache *tvp = VTOAFS(vp); afs_int32 modes; + int flags = Flags; AFS_STATCNT(afs_gn_open); modes = 0; - if ((flags & FREAD)) modes |= R_ACC; - if ((flags & FEXEC)) modes |= X_ACC; - if ((flags & FWRITE) || (flags & FTRUNC)) modes |= W_ACC; + if ((flags & FREAD)) + modes |= R_ACC; + if ((flags & FEXEC)) + modes |= X_ACC; + if ((flags & FWRITE) || (flags & FTRUNC)) + modes |= W_ACC; while ((flags & FNSHARE) && tvp->opens) { if (!(flags & FDELAY)) { - error = ETXTBSY; - goto abort; + error = ETXTBSY; + goto abort; } afs_osi_Sleep(&tvp->opens); } error = afs_access(vp, modes, cred); if (error) { - goto abort; + goto abort; } error = afs_open(&vp, flags, cred); @@ -388,51 +427,60 @@ struct ucred *cred; if (flags & FNSHARE) tvp->states |= CNSHARE; - if (! error) { - *vinfop = cred; /* fp->f_vinfo is like fp->f_cred in suns */ - } - else { + if (!error) { + *vinfop = cred; /* fp->f_vinfo is like fp->f_cred in suns */ + } else { /* an error occurred; we've told CM that the file - * is open, so close it now so that open and - * writer counts are correct. Ignore error code, - * as it is likely to fail (the setattr just did). - */ + * is open, so close it now so that open and + * writer counts are correct. Ignore error code, + * as it is likely to fail (the setattr just did). + */ afs_close(vp, flags, cred); } } -abort: - afs_Trace3(afs_iclSetp, CM_TRACE_GOPEN, ICL_TYPE_POINTER, (afs_int32)vp, + abort: + afs_Trace3(afs_iclSetp, CM_TRACE_GOPEN, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, flags, ICL_TYPE_LONG, error); - return(error); + return (error); } int -afs_gn_create(dp, vpp, flags, name, mode, vinfop, cred) -struct vnode *dp; -struct vnode **vpp; -int flags; -char *name; -int mode; -struct ucred **vinfop; /* return ptr for fp->f_vinfo, used as fp->f_cred */ -struct ucred *cred; -{ - struct vattr va; - enum vcexcl exclusive; - int error, modes=0; +afs_gn_create(dp, vpp, Flags, name, Mode, vinfop, cred) + struct vnode *dp; + struct vnode **vpp; + char *name; +#ifdef AFS_AIX51_ENV + int32long64_t Flags; + int32long64_t Mode; +#else + int Flags; + int Mode; +#endif + struct ucred **vinfop; /* return ptr for fp->f_vinfo, used as fp->f_cred */ + struct ucred *cred; +{ + struct vattr va; + enum vcexcl exclusive; + int error, modes = 0; + int flags = Flags; + int mode = Mode; AFS_STATCNT(afs_gn_create); - if ((flags & (O_EXCL|O_CREAT)) == (O_EXCL|O_CREAT)) + if ((flags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) exclusive = EXCL; - else + else exclusive = NONEXCL; VATTR_NULL(&va); va.va_type = VREG; va.va_mode = (mode & 07777) & ~get_umask(); - if ((flags & FREAD)) modes |= R_ACC; - if ((flags & FEXEC)) modes |= X_ACC; - if ((flags & FWRITE) || (flags & FTRUNC)) modes |= W_ACC; + if ((flags & FREAD)) + modes |= R_ACC; + if ((flags & FEXEC)) + modes |= X_ACC; + if ((flags & FWRITE) || (flags & FTRUNC)) + modes |= W_ACC; error = afs_create(dp, name, &va, exclusive, modes, vpp, cred); if (error) { return error; @@ -453,56 +501,62 @@ struct ucred *cred; * are stuff in afs_open that we need. For example advance the * execsOrWriters flag (else we'll be treated as the sun's "core" * case). */ - *vinfop = cred; /* save user creds in fp->f_vinfo */ + *vinfop = cred; /* save user creds in fp->f_vinfo */ error = afs_open(vpp, flags, cred); } - afs_Trace4(afs_iclSetp, CM_TRACE_GCREATE, ICL_TYPE_POINTER, (afs_int32)dp, - ICL_TYPE_STRING, name, ICL_TYPE_LONG, mode, ICL_TYPE_LONG, error); + afs_Trace4(afs_iclSetp, CM_TRACE_GCREATE, ICL_TYPE_POINTER, dp, + ICL_TYPE_STRING, name, ICL_TYPE_LONG, mode, ICL_TYPE_LONG, + error); return error; } int afs_gn_hold(vp) -struct vnode *vp; + struct vnode *vp; { AFS_STATCNT(afs_gn_hold); ++(vp->v_count); - return(0); + return (0); } int vmPageHog = 0; int afs_gn_rele(vp) -struct vnode *vp; + struct vnode *vp; { - struct vcache *vcp = VTOAFS(vp); - int error = 0; + struct vcache *vcp = VTOAFS(vp); + int error = 0; AFS_STATCNT(afs_gn_rele); if (vp->v_count == 0) osi_Panic("afs_rele: zero v_count"); if (--(vp->v_count) == 0) { if (vcp->states & CPageHog) { - vmPageHog --; + vmPageHog--; vcp->states &= ~CPageHog; } error = afs_inactive(vp, 0); } - return(error); + return (error); } int -afs_gn_close(vp, flags, vinfo, cred) -struct vnode *vp; -int flags; -caddr_t vinfo; /* Ignored in AFS */ -struct ucred *cred; +afs_gn_close(vp, Flags, vinfo, cred) + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t Flags; +#else + int Flags; +#endif + caddr_t vinfo; /* Ignored in AFS */ + struct ucred *cred; { - int error; + int error; struct vcache *tvp = VTOAFS(vp); + int flags = Flags; AFS_STATCNT(afs_gn_close); @@ -512,48 +566,66 @@ struct ucred *cred; } error = afs_close(vp, flags, cred); - afs_Trace3(afs_iclSetp, CM_TRACE_GCLOSE, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace3(afs_iclSetp, CM_TRACE_GCLOSE, ICL_TYPE_POINTER, (afs_int32) vp, ICL_TYPE_LONG, flags, ICL_TYPE_LONG, error); - return(error); + return (error); } int -afs_gn_map(vp, addr, len, off, flag, cred) -struct vnode *vp; -caddr_t addr; -u_int len, off, flag; -struct ucred *cred; +afs_gn_map(vp, addr, Len, Off, Flag, cred) + struct vnode *vp; + caddr_t addr; +#ifdef AFS_AIX51_ENV + uint32long64_t Len, Off, Flag; +#else + u_int Len, Off, Flag; +#endif + struct ucred *cred; { struct vcache *vcp = VTOAFS(vp); struct vrequest treq; afs_int32 error; + afs_int32 len = Len; + afs_int32 off = Off; + afs_int32 flag = Flag; + AFS_STATCNT(afs_gn_map); #ifdef notdef - if (error = afs_InitReq(&treq, cred)) return error; + if (error = afs_InitReq(&treq, cred)) + return error; error = afs_VerifyVCache(vcp, &treq); if (error) return afs_CheckCode(error, &treq, 49); #endif - osi_FlushPages(vcp, cred); /* XXX ensure old pages are gone XXX */ + osi_FlushPages(vcp, cred); /* XXX ensure old pages are gone XXX */ ObtainWriteLock(&vcp->lock, 401); - vcp->states |= CMAPPED; /* flag cleared at afs_inactive */ + vcp->states |= CMAPPED; /* flag cleared at afs_inactive */ /* * We map the segment into our address space using the handle returned by vm_create. */ - if (!vcp->vmh) { + if (!vcp->segid) { + afs_uint32 tlen = vcp->m.Length; +#ifdef AFS_64BIT_CLIENT + if (vcp->m.Length > afs_vmMappingEnd) + tlen = afs_vmMappingEnd; +#endif /* Consider V_INTRSEG too for interrupts */ - if (error = vms_create(&vcp->segid, V_CLIENT, vcp->v.v_gnode, vcp->m.Length, 0, 0)) { + if (error = + vms_create(&vcp->segid, V_CLIENT, vcp->v.v_gnode, tlen, 0, 0)) { ReleaseWriteLock(&vcp->lock); - return(EOPNOTSUPP); + return (EOPNOTSUPP); } +#ifdef AFS_64BIT_KERNEL + vcp->vmh = vm_handle(vcp->segid, (int32long64_t) 0); +#else vcp->vmh = SRVAL(vcp->segid, 0, 0); +#endif } - vcp->v.v_gnode->gn_seg = vcp->segid; /* XXX Important XXX */ + vcp->v.v_gnode->gn_seg = vcp->segid; /* XXX Important XXX */ if (flag & SHM_RDONLY) { vp->v_gnode->gn_mrdcnt++; - } - else { + } else { vp->v_gnode->gn_mwrcnt++; } /* @@ -564,35 +636,40 @@ struct ucred *cred; crhold(cred); if (vcp->credp) { struct ucred *crp = vcp->credp; - vcp->credp = (struct ucred *)0; + vcp->credp = NULL; crfree(crp); } vcp->credp = cred; } ReleaseWriteLock(&vcp->lock); VN_HOLD(vp); - afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, addr, ICL_TYPE_LONG, len, ICL_TYPE_LONG, off); - return(0); + return (0); } int afs_gn_unmap(vp, flag, cred) -struct vnode *vp; -int flag; -struct ucred *cred; + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t flag; +#else + int flag; +#endif + struct ucred *cred; { struct vcache *vcp = VTOAFS(vp); AFS_STATCNT(afs_gn_unmap); ObtainWriteLock(&vcp->lock, 402); if (flag & SHM_RDONLY) { vp->v_gnode->gn_mrdcnt--; - if (vp->v_gnode->gn_mrdcnt <=0) vp->v_gnode->gn_mrdcnt = 0; - } - else { + if (vp->v_gnode->gn_mrdcnt <= 0) + vp->v_gnode->gn_mrdcnt = 0; + } else { vp->v_gnode->gn_mwrcnt--; - if (vp->v_gnode->gn_mwrcnt <=0) vp->v_gnode->gn_mwrcnt = 0; + if (vp->v_gnode->gn_mwrcnt <= 0) + vp->v_gnode->gn_mwrcnt = 0; } ReleaseWriteLock(&vcp->lock); @@ -602,18 +679,27 @@ struct ucred *cred; int -afs_gn_access(vp, mode, who, cred) -struct vnode *vp; -int mode; -int who; -struct ucred *cred; +afs_gn_access(vp, Mode, Who, cred) + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t Mode; + int32long64_t Who; +#else + int Mode; + int Who; +#endif + struct ucred *cred; { - int error; + int error; struct vattr vattr; + int mode = Mode; + int who = Who; AFS_STATCNT(afs_gn_access); - if (mode & ~0x7) - return(EINVAL); + if (mode & ~0x7) { + error = EINVAL; + goto out; + } error = afs_access(vp, mode, cred); if (!error) { @@ -623,117 +709,131 @@ struct ucred *cred; if (!error) { if (who == ACC_ANY) { if (((vattr.va_mode >> 6) & mode) == mode) { - error = 0; + error = 0; goto out; } } if (((vattr.va_mode >> 3) & mode) == mode) - error = 0; + error = 0; else error = EACCES; } } else if (who == ACC_ALL) { error = afs_getattr(vp, &vattr, cred); if (!error) { - if ((!((vattr.va_mode >> 6) & mode)) || (!((vattr.va_mode >> 3) & mode)) || - (!(vattr.va_mode & mode))) + if ((!((vattr.va_mode >> 6) & mode)) + || (!((vattr.va_mode >> 3) & mode)) + || (!(vattr.va_mode & mode))) error = EACCES; else error = 0; } } - + } -out: - afs_Trace3(afs_iclSetp, CM_TRACE_GACCESS, ICL_TYPE_POINTER, (afs_int32)vp, + out: + afs_Trace3(afs_iclSetp, CM_TRACE_GACCESS, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, mode, ICL_TYPE_LONG, error); - return(error); + return (error); } int afs_gn_getattr(vp, vattrp, cred) -struct vnode *vp; -struct vattr *vattrp; -struct ucred *cred; + struct vnode *vp; + struct vattr *vattrp; + struct ucred *cred; { - int error; + int error; - AFS_STATCNT(afs_gn_getattr); + AFS_STATCNT(afs_gn_getattr); error = afs_getattr(vp, vattrp, cred); - afs_Trace2(afs_iclSetp, CM_TRACE_GGETATTR, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace2(afs_iclSetp, CM_TRACE_GGETATTR, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, error); - return(error); + return (error); } int afs_gn_setattr(vp, op, arg1, arg2, arg3, cred) -struct vnode *vp; -int op; -int arg1; -int arg2; -int arg3; -struct ucred *cred; + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t op; + int32long64_t arg1; + int32long64_t arg2; + int32long64_t arg3; +#else + int op; + int arg1; + int arg2; + int arg3; +#endif + struct ucred *cred; { - struct vattr va; - int error = 0; + struct vattr va; + int error = 0; - AFS_STATCNT(afs_gn_setattr); + AFS_STATCNT(afs_gn_setattr); VATTR_NULL(&va); - switch(op) { + switch (op) { /* change mode */ - case V_MODE: - va.va_mode = arg1; - break; - case V_OWN: - if ((arg1 & T_OWNER_AS_IS) == 0) - va.va_uid = arg2; - if ((arg1 & T_GROUP_AS_IS) == 0) - va.va_gid = arg3; - break; - case V_UTIME: + case V_MODE: + va.va_mode = arg1; + break; + case V_OWN: + if ((arg1 & T_OWNER_AS_IS) == 0) + va.va_uid = arg2; + if ((arg1 & T_GROUP_AS_IS) == 0) + va.va_gid = arg3; + break; + case V_UTIME: #ifdef notdef - error = afs_access(vp, VWRITE, cred); - if (error) - return(error); + error = afs_access(vp, VWRITE, cred); + if (error) + goto out; #endif - if (arg1 & T_SETTIME) { - va.va_atime.tv_sec = time; - va.va_mtime.tv_sec = time; - } else { - va.va_atime = *(struct timestruc_t *) arg2; - va.va_mtime = *(struct timestruc_t *) arg3; - } - break; - default: - return(EINVAL); + if (arg1 & T_SETTIME) { + va.va_atime.tv_sec = time; + va.va_mtime.tv_sec = time; + } else { + va.va_atime = *(struct timestruc_t *)arg2; + va.va_mtime = *(struct timestruc_t *)arg3; + } + break; + default: + error = EINVAL; + goto out; } error = afs_setattr(vp, &va, cred); - afs_Trace2(afs_iclSetp, CM_TRACE_GSETATTR, ICL_TYPE_POINTER, (afs_int32)vp, + out: + afs_Trace2(afs_iclSetp, CM_TRACE_GSETATTR, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, error); - return(error); + return (error); } char zero_buffer[PAGESIZE]; int -afs_gn_fclear(vp, flags, offset, length, vinfo, cred) -struct vnode *vp; -int flags; -offset_t offset; -offset_t length; -caddr_t vinfo; -struct ucred *cred; +afs_gn_fclear(vp, flags, offset, length, vinfo, cred) + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t flags; +#else + int flags; +#endif + offset_t offset; + offset_t length; + caddr_t vinfo; + struct ucred *cred; { int i, len, error = 0; struct iovec iov; struct uio uio; - static int fclear_init =0; + static int fclear_init = 0; register struct vcache *avc = VTOAFS(vp); - AFS_STATCNT(afs_gn_fclear); + AFS_STATCNT(afs_gn_fclear); if (!fclear_init) { memset(zero_buffer, 0, PAGESIZE); fclear_init = 1; @@ -742,19 +842,19 @@ struct ucred *cred; * Don't clear past ulimit */ if (offset + length > get_ulimit()) - return(EFBIG); + return (EFBIG); /* Flush all pages first */ if (avc->segid) { AFS_GUNLOCK(); - vm_flushp(avc->segid, 0, MAXFSIZE/PAGESIZE - 1); - vms_iowait(avc->vmh); + vm_flushp(avc->segid, 0, MAXFSIZE / PAGESIZE - 1); + vms_iowait(avc->segid); AFS_GLOCK(); - } + } uio.afsio_offset = offset; for (i = offset; i < offset + length; i = uio.afsio_offset) { len = offset + length - i; - iov.iov_len = (len > PAGESIZE) ? PAGESIZE : len; + iov.iov_len = (len > PAGESIZE) ? PAGESIZE : len; iov.iov_base = zero_buffer; uio.afsio_iov = &iov; uio.afsio_iovcnt = 1; @@ -763,74 +863,94 @@ struct ucred *cred; if (error = afs_rdwr(vp, &uio, UIO_WRITE, 0, cred)) break; } - afs_Trace4(afs_iclSetp, CM_TRACE_GFCLEAR, ICL_TYPE_POINTER, (afs_int32)vp, - ICL_TYPE_LONG, offset, ICL_TYPE_LONG, length, ICL_TYPE_LONG, error); + afs_Trace4(afs_iclSetp, CM_TRACE_GFCLEAR, ICL_TYPE_POINTER, vp, + ICL_TYPE_LONG, offset, ICL_TYPE_LONG, length, ICL_TYPE_LONG, + error); return (error); } int afs_gn_fsync(vp, flags, vinfo, cred) -struct vnode *vp; -int flags; /* Not used by AFS */ -caddr_t vinfo; /* Not used by AFS */ -struct ucred *cred; + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t flags; /* Not used by AFS */ + int32long64_t vinfo; /* Not used by AFS */ +#else + int flags; /* Not used by AFS */ + caddr_t vinfo; /* Not used by AFS */ +#endif + struct ucred *cred; { - int error; + int error; - AFS_STATCNT(afs_gn_fsync); + AFS_STATCNT(afs_gn_fsync); error = afs_fsync(vp, cred); - afs_Trace3(afs_iclSetp, CM_TRACE_GFSYNC, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace3(afs_iclSetp, CM_TRACE_GFSYNC, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, flags, ICL_TYPE_LONG, error); - return(error); + return (error); } int afs_gn_ftrunc(vp, flags, length, vinfo, cred) -struct vnode *vp; -int flags; /* Ignored in AFS */ -offset_t length; -caddr_t vinfo; /* Ignored in AFS */ -struct ucred *cred; + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t flags; /* Ignored in AFS */ +#else + int flags; /* Ignored in AFS */ +#endif + offset_t length; + caddr_t vinfo; /* Ignored in AFS */ + struct ucred *cred; { - struct vattr va; - int error; + struct vattr va; + int error; AFS_STATCNT(afs_gn_ftrunc); VATTR_NULL(&va); va.va_size = length; error = afs_setattr(vp, &va, cred); - afs_Trace4(afs_iclSetp, CM_TRACE_GFTRUNC, ICL_TYPE_POINTER, (afs_int32)vp, - ICL_TYPE_LONG, flags, ICL_TYPE_LONG, length, ICL_TYPE_LONG, error); - return(error); + afs_Trace4(afs_iclSetp, CM_TRACE_GFTRUNC, ICL_TYPE_POINTER, vp, + ICL_TYPE_LONG, flags, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(length), ICL_TYPE_LONG, error); + return (error); } /* Min size of a file which is dumping core before we declare it a page hog. */ #define MIN_PAGE_HOG_SIZE 8388608 -int afs_gn_rdwr(vp, op, flags, ubuf, ext, vinfo, vattrp, cred) -struct vnode *vp; -enum uio_rw op; -int flags; -struct uio *ubuf; -int ext; /* Ignored in AFS */ -caddr_t vinfo; /* Ignored in AFS */ -struct vattr *vattrp; -struct ucred *cred; -{ - register struct vcache *vcp = VTOAFS(vp); +int +afs_gn_rdwr(vp, op, Flags, ubuf, ext, vinfo, vattrp, cred) + struct vnode *vp; + enum uio_rw op; +#ifdef AFS_AIX51_ENV + int32long64_t Flags; + ext_t ext; /* Ignored in AFS */ +#else + int Flags; + int ext; /* Ignored in AFS */ +#endif + struct uio *ubuf; + caddr_t vinfo; /* Ignored in AFS */ + struct vattr *vattrp; + struct ucred *cred; +{ + register struct vcache *vcp = VTOAFS(vp); struct vrequest treq; - int error=0; + int error = 0; int free_cred = 0; + int flags = Flags; AFS_STATCNT(afs_gn_rdwr); if (vcp->vc_error) { - if (op == UIO_WRITE) + if (op == UIO_WRITE) { + afs_Trace2(afs_iclSetp, CM_TRACE_GRDWR1, ICL_TYPE_POINTER, vp, + ICL_TYPE_LONG, vcp->vc_error); return vcp->vc_error; - else - return EIO; + } else + return EIO; } ObtainSharedLock(&vcp->lock, 507); @@ -850,37 +970,39 @@ struct ucred *cred; free_cred = 1; } #endif - crhold(cred); /* Bump refcount for reference in vcache */ + crhold(cred); /* Bump refcount for reference in vcache */ if (vcp->credp) { struct ucred *crp; UpgradeSToWLock(&vcp->lock, 508); crp = vcp->credp; - vcp->credp = (struct ucred *)0; + vcp->credp = NULL; ConvertWToSLock(&vcp->lock); crfree(crp); } - vcp->credp = cred; + vcp->credp = cred; } ReleaseSharedLock(&vcp->lock); /* * XXX Is the following really required?? XXX */ - if (error = afs_InitReq(&treq, cred)) return error; + if (error = afs_InitReq(&treq, cred)) + return error; if (error = afs_VerifyVCache(vcp, &treq)) return afs_CheckCode(error, &treq, 50); - osi_FlushPages(vcp, cred); /* Flush old pages */ + osi_FlushPages(vcp, cred); /* Flush old pages */ if (AFS_NFSXLATORREQ(cred)) { if (flags & FSYNC) flags &= ~FSYNC; if (op == UIO_READ) { - if (!afs_AccessOK(vcp, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) { - if (free_cred) - crfree(cred); - return EACCES; + if (!afs_AccessOK + (vcp, PRSFS_READ, &treq, + CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) { + if (free_cred) + crfree(cred); + return EACCES; } } } @@ -891,60 +1013,80 @@ struct ucred *cred; * We do a similar thing on the afs_read/write interface. */ if (op == UIO_WRITE) { - ObtainWriteLock(&vcp->lock,240); - vcp->states |= CDirty; /* Set the dirty bit */ - afs_FakeOpen(vcp); - ReleaseWriteLock(&vcp->lock); +#ifdef AFS_64BIT_CLIENT + if (ubuf->afsio_offset < afs_vmMappingEnd) { +#endif /* AFS_64BIT_ENV */ + ObtainWriteLock(&vcp->lock, 240); + vcp->states |= CDirty; /* Set the dirty bit */ + afs_FakeOpen(vcp); + ReleaseWriteLock(&vcp->lock); +#ifdef AFS_64BIT_CLIENT + } +#endif /* AFS_64BIT_ENV */ } error = afs_vm_rdwr(vp, ubuf, op, flags, cred); if (op == UIO_WRITE) { - ObtainWriteLock(&vcp->lock,241); - afs_FakeClose(vcp, cred); /* XXXX For nfs trans and cores XXXX */ - ReleaseWriteLock(&vcp->lock); +#ifdef AFS_64BIT_CLIENT + if (ubuf->afsio_offset < afs_vmMappingEnd) { +#endif /* AFS_64BIT_ENV */ + ObtainWriteLock(&vcp->lock, 241); + afs_FakeClose(vcp, cred); /* XXXX For nfs trans and cores XXXX */ + ReleaseWriteLock(&vcp->lock); +#ifdef AFS_64BIT_CLIENT + } +#endif /* AFS_64BIT_ENV */ } if (vattrp != NULL && error == 0) afs_gn_getattr(vp, vattrp, cred); - afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, flags, ICL_TYPE_LONG, op, ICL_TYPE_LONG, error); if (free_cred) - crfree(cred); - return(error); + crfree(cred); + return (error); } - #define AFS_MAX_VM_CHUNKS 10 afs_vm_rdwr(vp, uiop, rw, ioflag, credp) - register struct vnode *vp; - struct uio *uiop; - enum uio_rw rw; - int ioflag; - struct ucred *credp; + register struct vnode *vp; + struct uio *uiop; + enum uio_rw rw; + int ioflag; + struct ucred *credp; { register afs_int32 code = 0; register int i; - afs_int32 blockSize, fileSize; - afs_int32 xfrSize, xfrOffset; + afs_int32 blockSize; + afs_size_t fileSize, xfrOffset, offset, old_offset, xfrSize; + vmsize_t txfrSize; +#ifdef AFS_64BIT_CLIENT + afs_size_t finalOffset; + off_t toffset; + int mixed = 0; + afs_size_t add2resid = 0; +#endif /* AFS_64BIT_CLIENT */ register struct vcache *vcp = VTOAFS(vp); struct dcache *tdc; - register afs_int32 start_offset; - int save_resid = uiop->afsio_resid; - int old_offset, first_page; - int offset, count, len; + afs_size_t start_offset; + afs_int32 save_resid = uiop->afsio_resid; + int first_page, last_page, pages; + int count, len; int counter = 0; struct vrequest treq; - if (code = afs_InitReq(&treq, credp)) return code; + if (code = afs_InitReq(&treq, credp)) + return code; /* special case easy transfer; apparently a lot are done */ - if ((xfrSize=uiop->afsio_resid) == 0) return 0; + if ((xfrSize = uiop->afsio_resid) == 0) + return 0; ObtainReadLock(&vcp->lock); fileSize = vcp->m.Length; - if (rw == UIO_WRITE && (ioflag & IO_APPEND)) { /* handle IO_APPEND mode */ + if (rw == UIO_WRITE && (ioflag & IO_APPEND)) { /* handle IO_APPEND mode */ uiop->afsio_offset = fileSize; } /* compute xfrOffset now, and do some checks */ @@ -953,29 +1095,101 @@ afs_vm_rdwr(vp, uiop, rw, ioflag, credp) code = EINVAL; goto fail; } - +#ifndef AFS_64BIT_CLIENT /* check for "file too big" error, which should really be done above us */ if (rw == UIO_WRITE && xfrSize + fileSize > get_ulimit()) { code = EFBIG; goto fail; } +#endif /* AFS_64BIT_CLIENT */ + +#ifdef AFS_64BIT_CLIENT + if (xfrOffset + xfrSize > afs_vmMappingEnd) { + if (rw == UIO_READ) { + /* don't read past EOF */ + if (xfrSize+xfrOffset > fileSize) { + add2resid = xfrSize + xfrOffset - fileSize; + xfrSize = fileSize - xfrOffset; + if (xfrSize <= 0) goto fail; + txfrSize = xfrSize; + afsio_trim(uiop, txfrSize); + } + } + if (xfrOffset < afs_vmMappingEnd) { + /* special case of a buffer crossing the VM mapping line */ + struct uio tuio; + struct iovec tvec[16]; /* Should have access to #define */ + afs_int32 tsize; + + mixed = 1; + finalOffset = xfrOffset + xfrSize; + tsize = (afs_size_t) (xfrOffset + xfrSize - afs_vmMappingEnd); + txfrSize = xfrSize; + afsio_copy(uiop, &tuio, tvec); + afsio_skip(&tuio, txfrSize - tsize); + afsio_trim(&tuio, tsize); + tuio.afsio_offset = afs_vmMappingEnd; + ReleaseReadLock(&vcp->lock); + ObtainWriteLock(&vcp->lock, 243); + afs_FakeClose(vcp, credp); /* XXXX For nfs trans and cores XXXX */ + ReleaseWriteLock(&vcp->lock); + code = afs_direct_rdwr(vp, &tuio, rw, ioflag, credp); + ObtainWriteLock(&vcp->lock, 244); + afs_FakeOpen(vcp); /* XXXX For nfs trans and cores XXXX */ + ReleaseWriteLock(&vcp->lock); + ObtainReadLock(&vcp->lock); + if (code) + goto fail; + xfrSize = afs_vmMappingEnd - xfrOffset; + txfrSize = xfrSize; + afsio_trim(uiop, txfrSize); + } else { + ReleaseReadLock(&vcp->lock); + code = afs_direct_rdwr(vp, uiop, rw, ioflag, credp); + uiop->uio_resid += add2resid; + return code; + } + } +#endif /* AFS_64BIT_CLIENT */ - if (!vcp->vmh) { + if (!vcp->segid) { + afs_uint32 tlen = vcp->m.Length; +#ifdef AFS_64BIT_CLIENT + if (vcp->m.Length > afs_vmMappingEnd) + tlen = afs_vmMappingEnd; +#endif /* Consider V_INTRSEG too for interrupts */ - if (code = vms_create(&vcp->segid, V_CLIENT, vcp->v.v_gnode, - vcp->m.Length, 0, 0)) { + if (code = + vms_create(&vcp->segid, V_CLIENT, vcp->v.v_gnode, tlen, 0, 0)) { goto fail; } - vcp->vmh = SRVAL(vcp->segid, 0, 0); +#ifdef AFS_64BIT_KERNEL + vcp->vmh = vm_handle(vcp->segid, (int32long64_t) 0); +#else + vcp->vmh = SRVAL(vcp->segid, 0, 0); +#endif } + vcp->v.v_gnode->gn_seg = vcp->segid; if (rw == UIO_READ) { /* don't read past EOF */ - if (xfrSize+xfrOffset > fileSize) + if (xfrSize + xfrOffset > fileSize) xfrSize = fileSize - xfrOffset; - if (xfrSize <= 0) goto fail; + if (xfrSize <= 0) + goto fail; ReleaseReadLock(&vcp->lock); +#ifdef AFS_64BIT_CLIENT + toffset = xfrOffset; + uiop->afsio_offset = xfrOffset; + afs_Trace3(afs_iclSetp, CM_TRACE_VMWRITE, ICL_TYPE_POINTER, vcp, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(xfrOffset), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(xfrSize)); + AFS_GUNLOCK(); + txfrSize = xfrSize; + code = vm_move(vcp->segid, toffset, txfrSize, rw, uiop); +#else /* AFS_64BIT_CLIENT */ AFS_GUNLOCK(); code = vm_move(vcp->segid, xfrOffset, xfrSize, rw, uiop); +#endif /* AFS_64BIT_CLIENT */ AFS_GLOCK(); /* * If at a chunk boundary and staying within chunk, @@ -983,108 +1197,140 @@ afs_vm_rdwr(vp, uiop, rw, ioflag, credp) */ if (counter == 0 || AFS_CHUNKOFFSET(xfrOffset) == 0 && xfrSize <= AFS_CHUNKSIZE(xfrOffset)) { - ObtainWriteLock(&vcp->lock,407); + ObtainWriteLock(&vcp->lock, 407); tdc = afs_FindDCache(vcp, xfrOffset); - if (tdc) { - if (!(tdc->flags & DFNextStarted)) - afs_PrefetchChunk(vcp, tdc, credp, &treq); - afs_PutDCache(tdc); - } + if (tdc) { + if (!(tdc->mflags & DFNextStarted)) + afs_PrefetchChunk(vcp, tdc, credp, &treq); + afs_PutDCache(tdc); + } ReleaseWriteLock(&vcp->lock); } +#ifdef AFS_64BIT_CLIENT + if (mixed) { + uiop->afsio_offset = finalOffset; + } + uiop->uio_resid += add2resid; +#endif /* AFS_64BIT_CLIENT */ return code; } /* UIO_WRITE */ + start_offset = uiop->afsio_offset; + afs_Trace3(afs_iclSetp, CM_TRACE_VMWRITE, ICL_TYPE_POINTER, vcp, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(start_offset), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(xfrSize)); ReleaseReadLock(&vcp->lock); - ObtainWriteLock(&vcp->lock,400); + ObtainWriteLock(&vcp->lock, 400); vcp->m.Date = osi_Time(); /* Set file date (for ranlib) */ /* extend file */ /* un-protect last page. */ - vm_protectp(vcp->vmh, vcp->m.Length/PAGESIZE, 1, FILEKEY); + last_page = vcp->m.Length / PAGESIZE; +#ifdef AFS_64BIT_CLIENT + if (vcp->m.Length > afs_vmMappingEnd) + last_page = afs_vmMappingEnd / PAGESIZE; +#endif + vm_protectp(vcp->segid, last_page, 1, FILEKEY); if (xfrSize + xfrOffset > fileSize) { - vcp->m.Length = xfrSize+xfrOffset; - } + vcp->m.Length = xfrSize + xfrOffset; + } if ((!(vcp->states & CPageHog)) && (xfrSize >= MIN_PAGE_HOG_SIZE)) { - vmPageHog ++; + vmPageHog++; vcp->states |= CPageHog; } ReleaseWriteLock(&vcp->lock); - + /* If the write will fit into a single chunk we'll write all of it * at once. Otherwise, we'll write one chunk at a time, flushing * some of it to disk. */ - start_offset = uiop->afsio_offset; count = 0; /* Only create a page to avoid excess VM access if we're writing a * small file which is either new or completely overwrites the * existing file. */ - if ((xfrOffset == 0) && (xfrSize < PAGESIZE) && (xfrSize >= fileSize) && - (vcp->v.v_gnode->gn_mwrcnt == 0) && - (vcp->v.v_gnode->gn_mrdcnt == 0)) { - (void) vm_makep(vcp->segid, 0); + if ((xfrOffset == 0) && (xfrSize < PAGESIZE) && (xfrSize >= fileSize) + && (vcp->v.v_gnode->gn_mwrcnt == 0) + && (vcp->v.v_gnode->gn_mrdcnt == 0)) { + (void)vm_makep(vcp->segid, 0); } - + while (xfrSize > 0) { offset = AFS_CHUNKBASE(xfrOffset); len = xfrSize; - + if (AFS_CHUNKSIZE(xfrOffset) <= len) - len = AFS_CHUNKSIZE(xfrOffset) - (xfrOffset - offset); - + len = + (afs_size_t) AFS_CHUNKSIZE(xfrOffset) - (xfrOffset - offset); + if (len == xfrSize) { /* All data goes to this one chunk. */ AFS_GUNLOCK(); old_offset = uiop->afsio_offset; +#ifdef AFS_64BIT_CLIENT + uiop->afsio_offset = xfrOffset; + toffset = xfrOffset; + txfrSize = xfrSize; + code = vm_move(vcp->segid, toffset, txfrSize, rw, uiop); +#else /* AFS_64BIT_CLIENT */ code = vm_move(vcp->segid, xfrOffset, xfrSize, rw, uiop); +#endif /* AFS_64BIT_CLIENT */ AFS_GLOCK(); xfrOffset += len; xfrSize = 0; - } - else { + } else { /* Write just one chunk's worth of data. */ struct uio tuio; - struct iovec tvec[16]; /* Should have access to #define */ + struct iovec tvec[16]; /* Should have access to #define */ /* Purge dirty chunks of file if there are too many dirty chunks. * Inside the write loop, we only do this at a chunk boundary. * Clean up partial chunk if necessary at end of loop. */ if (counter > 0 && code == 0 && xfrOffset == offset) { - ObtainWriteLock(&vcp->lock,403); - code = afs_DoPartialWrite(vcp, &treq); + ObtainWriteLock(&vcp->lock, 403); + if (xfrOffset > vcp->m.Length) + vcp->m.Length = xfrOffset; + code = afs_DoPartialWrite(vcp, &treq); vcp->states |= CDirty; ReleaseWriteLock(&vcp->lock); } counter++; - + afsio_copy(uiop, &tuio, tvec); afsio_trim(&tuio, len); tuio.afsio_offset = xfrOffset; - + AFS_GUNLOCK(); old_offset = uiop->afsio_offset; +#ifdef AFS_64BIT_CLIENT + toffset = xfrOffset; + code = vm_move(vcp->segid, toffset, len, rw, &tuio); +#else /* AFS_64BIT_CLIENT */ code = vm_move(vcp->segid, xfrOffset, len, rw, &tuio); +#endif /* AFS_64BIT_CLIENT */ AFS_GLOCK(); len -= tuio.afsio_resid; afsio_skip(uiop, len); xfrSize -= len; xfrOffset += len; } - - first_page = old_offset >> PGSHIFT; + + first_page = (afs_size_t) old_offset >> PGSHIFT; + pages = + 1 + (((afs_size_t) old_offset + (len - 1)) >> PGSHIFT) - + first_page; + afs_Trace3(afs_iclSetp, CM_TRACE_VMWRITE2, ICL_TYPE_POINTER, vcp, + ICL_TYPE_INT32, first_page, ICL_TYPE_INT32, pages); AFS_GUNLOCK(); - code = vm_writep(vcp->segid, first_page, - 1 + ((old_offset + (len - 1)) >> PGSHIFT) - first_page); + code = vm_writep(vcp->segid, first_page, pages); if (++count > AFS_MAX_VM_CHUNKS) { count = 0; vms_iowait(vcp->segid); } AFS_GLOCK(); - + } if (count) { @@ -1093,17 +1339,17 @@ afs_vm_rdwr(vp, uiop, rw, ioflag, credp) AFS_GLOCK(); } - ObtainWriteLock(&vcp->lock,242); + ObtainWriteLock(&vcp->lock, 242); if (code == 0 && (vcp->states & CDirty)) { code = afs_DoPartialWrite(vcp, &treq); } - vm_protectp(vcp->vmh, vcp->m.Length/PAGESIZE, 1, RDONLY); + vm_protectp(vcp->segid, last_page, 1, RDONLY); ReleaseWriteLock(&vcp->lock); - + /* If requested, fsync the file after every write */ if (ioflag & FSYNC) afs_fsync(vp, credp); - + ObtainReadLock(&vcp->lock); if (vcp->vc_error) { /* Pretend we didn't write anything. We need to get the error back to @@ -1114,37 +1360,125 @@ afs_vm_rdwr(vp, uiop, rw, ioflag, credp) */ code = vcp->vc_error; if (code == EDQUOT || code == ENOSPC) - uiop->afsio_resid = save_resid; + uiop->afsio_resid = save_resid; + } +#ifdef AFS_64BIT_CLIENT + if (mixed) { + uiop->afsio_offset = finalOffset; } +#endif /* AFS_64BIT_CLIENT */ fail: ReleaseReadLock(&vcp->lock); + afs_Trace2(afs_iclSetp, CM_TRACE_VMWRITE3, ICL_TYPE_POINTER, vcp, + ICL_TYPE_INT32, code); return code; } +afs_direct_rdwr(vp, uiop, rw, ioflag, credp) + register struct vnode *vp; + struct uio *uiop; + enum uio_rw rw; + int ioflag; + struct ucred *credp; +{ + register afs_int32 code = 0; + afs_size_t fileSize, xfrOffset, offset, old_offset, xfrSize; + struct vcache *vcp = VTOAFS(vp); + afs_int32 save_resid = uiop->afsio_resid; + struct vrequest treq; -static int lock_normalize(vp, lckdat, offset, cred) - struct vnode *vp; - struct eflock *lckdat; - offset_t offset; - struct ucred *cred; + if (code = afs_InitReq(&treq, credp)) + return code; + + /* special case easy transfer; apparently a lot are done */ + if ((xfrSize = uiop->afsio_resid) == 0) + return 0; + + ObtainReadLock(&vcp->lock); + fileSize = vcp->m.Length; + if (rw == UIO_WRITE && (ioflag & IO_APPEND)) { /* handle IO_APPEND mode */ + uiop->afsio_offset = fileSize; + } + /* compute xfrOffset now, and do some checks */ + xfrOffset = uiop->afsio_offset; + if (xfrOffset < 0 || xfrOffset + xfrSize < 0) { + code = EINVAL; + ReleaseReadLock(&vcp->lock); + goto fail; + } + + /* check for "file too big" error, which should really be done above us */ +#ifdef notdef + if (rw == UIO_WRITE && xfrSize + fileSize > get_ulimit()) { + code = EFBIG; + ReleaseReadLock(&vcp->lock); + goto fail; + } +#endif + ReleaseReadLock(&vcp->lock); + if (rw == UIO_WRITE) { + ObtainWriteLock(&vcp->lock, 400); + vcp->m.Date = osi_Time(); /* Set file date (for ranlib) */ + /* extend file */ + if (xfrSize + xfrOffset > fileSize) + vcp->m.Length = xfrSize + xfrOffset; + ReleaseWriteLock(&vcp->lock); + } + afs_Trace3(afs_iclSetp, CM_TRACE_DIRECTRDWR, ICL_TYPE_POINTER, vp, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(uiop->afsio_offset), + ICL_TYPE_LONG, uiop->afsio_resid); + code = afs_rdwr(vp, uiop, rw, ioflag, credp); + if (code != 0) { + uiop->afsio_resid = save_resid; + } else { + uiop->afsio_offset = xfrOffset + xfrSize; + if (uiop->afsio_resid > 0) { + /* should zero here the remaining buffer */ + uiop->afsio_resid = 0; + } + /* Purge dirty chunks of file if there are too many dirty chunks. + * Inside the write loop, we only do this at a chunk boundary. + * Clean up partial chunk if necessary at end of loop. + */ + if (AFS_CHUNKBASE(uiop->afsio_offset) != AFS_CHUNKBASE(xfrOffset)) { + ObtainWriteLock(&vcp->lock, 402); + code = afs_DoPartialWrite(vcp, &treq); + vcp->states |= CDirty; + ReleaseWriteLock(&vcp->lock); + } + } + + fail: + return code; +} + + +static int +lock_normalize(vp, lckdat, offset, cred) + struct vnode *vp; + struct eflock *lckdat; + offset_t offset; + struct ucred *cred; { struct vattr vattr; int code; - switch(lckdat->l_whence) { - case 0: - return 0; - case 1: - lckdat->l_start += (off_t) offset; - break; - case 2: - code = afs_getattr(vp, &vattr, cred); - if (code != 0) return code; - lckdat->l_start += (off_t) vattr.va_size; - break; - default: return EINVAL; + switch (lckdat->l_whence) { + case 0: + return 0; + case 1: + lckdat->l_start += (off_t) offset; + break; + case 2: + code = afs_getattr(vp, &vattr, cred); + if (code != 0) + return code; + lckdat->l_start += (off_t) vattr.va_size; + break; + default: + return EINVAL; } lckdat->l_whence = 0; return 0; @@ -1153,131 +1487,144 @@ static int lock_normalize(vp, lckdat, offset, cred) afs_gn_lockctl(vp, offset, lckdat, cmd, ignored_fcn, ignored_id, cred) -void (*ignored_fcn)(); -void *ignored_id; -struct vnode *vp; -offset_t offset; -struct eflock *lckdat; -struct ucred *cred; -{ - int error, ncmd=0; - struct flock flkd; - struct vattr *attrs; - - AFS_STATCNT(afs_gn_lockctl); - /* Convert from AIX's cmd to standard lockctl lock types... */ - if (cmd == 0) - ncmd = F_GETLK; - else if (cmd & SETFLCK) { - ncmd = F_SETLK; - if (cmd & SLPFLCK) - ncmd = F_SETLKW; - } - flkd.l_type = lckdat->l_type; - flkd.l_whence = lckdat->l_whence; - flkd.l_start = lckdat->l_start; - flkd.l_len = lckdat->l_len; - flkd.l_pid = lckdat->l_pid; - flkd.l_sysid = lckdat->l_sysid; - - if (flkd.l_start != lckdat->l_start || flkd.l_len != lckdat->l_len) - return EINVAL; + void (*ignored_fcn) (); + void *ignored_id; + struct vnode *vp; + offset_t offset; + struct eflock *lckdat; + struct ucred *cred; +#ifdef AFS_AIX51_ENV + int32long64_t cmd; +#else + int cmd; +#endif +{ + int error, ncmd = 0; + struct flock flkd; + struct vattr *attrs; + + AFS_STATCNT(afs_gn_lockctl); + /* Convert from AIX's cmd to standard lockctl lock types... */ + if (cmd == 0) + ncmd = F_GETLK; + else if (cmd & SETFLCK) { + ncmd = F_SETLK; + if (cmd & SLPFLCK) + ncmd = F_SETLKW; + } + flkd.l_type = lckdat->l_type; + flkd.l_whence = lckdat->l_whence; + flkd.l_start = lckdat->l_start; + flkd.l_len = lckdat->l_len; + flkd.l_pid = lckdat->l_pid; + flkd.l_sysid = lckdat->l_sysid; + + if (flkd.l_start != lckdat->l_start || flkd.l_len != lckdat->l_len) + return EINVAL; if (error = lock_normalize(vp, &flkd, offset, cred)) - return(error); + return (error); error = afs_lockctl(vp, &flkd, ncmd, cred); - lckdat->l_type = flkd.l_type; - lckdat->l_whence = flkd.l_whence; - lckdat->l_start = flkd.l_start; - lckdat->l_len = flkd.l_len; - lckdat->l_pid = flkd.l_pid; - lckdat->l_sysid = flkd.l_sysid; - afs_Trace3(afs_iclSetp, CM_TRACE_GLOCKCTL, ICL_TYPE_POINTER, (afs_int32)vp, + lckdat->l_type = flkd.l_type; + lckdat->l_whence = flkd.l_whence; + lckdat->l_start = flkd.l_start; + lckdat->l_len = flkd.l_len; + lckdat->l_pid = flkd.l_pid; + lckdat->l_sysid = flkd.l_sysid; + afs_Trace3(afs_iclSetp, CM_TRACE_GLOCKCTL, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, ncmd, ICL_TYPE_LONG, error); - return(error); + return (error); } /* NOTE: In the nfs glue routine (nfs_gn2sun.c) the order was wrong (vp, flags, cmd, arg, ext); was that another typo? */ -int afs_gn_ioctl(vp, cmd, arg, flags, channel, ext) -struct vnode *vp; -int cmd; -int arg; -int flags; /* Ignored in AFS */ -int channel; /* Ignored in AFS */ -int ext; /* Ignored in AFS */ -{ - int error; +int +afs_gn_ioctl(vp, Cmd, arg, flags, channel, ext) + struct vnode *vp; +#ifdef AFS_AIX51_ENV + int32long64_t Cmd; +#else + int Cmd; +#endif + int arg; + int flags; /* Ignored in AFS */ + int channel; /* Ignored in AFS */ + int ext; /* Ignored in AFS */ +{ + int error; + int cmd = Cmd; + AFS_STATCNT(afs_gn_ioctl); - /* This seems to be a perfect fit for our ioctl redirection (afs_xioctl hack); thus the ioctl(2) entry in sysent.c is unaffected in the aix/afs port. */ + /* This seems to be a perfect fit for our ioctl redirection (afs_xioctl hack); thus the ioctl(2) entry in sysent.c is unaffected in the aix/afs port. */ error = afs_ioctl(vp, cmd, arg); - afs_Trace3(afs_iclSetp, CM_TRACE_GIOCTL, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace3(afs_iclSetp, CM_TRACE_GIOCTL, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, cmd, ICL_TYPE_LONG, error); - return(error); + return (error); } int -afs_gn_readlink(vp, uiop, cred) -struct vnode *vp; -struct uio *uiop; -struct ucred *cred; +afs_gn_readlink(vp, uiop, cred) + struct vnode *vp; + struct uio *uiop; + struct ucred *cred; { - int error; + int error; - AFS_STATCNT(afs_gn_readlink); + AFS_STATCNT(afs_gn_readlink); error = afs_readlink(vp, uiop, cred); - afs_Trace2(afs_iclSetp, CM_TRACE_GREADLINK, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace2(afs_iclSetp, CM_TRACE_GREADLINK, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, error); - return(error); + return (error); } int afs_gn_select(vp, which, vinfo, mpx) -struct vnode *vp; -int which; -caddr_t *vinfo; -caddr_t *mpx; + struct vnode *vp; + int which; + caddr_t *vinfo; + caddr_t *mpx; { - AFS_STATCNT(afs_gn_select); + AFS_STATCNT(afs_gn_select); /* NO SUPPORT for this in afs YET! */ - return(EOPNOTSUPP); + return (EOPNOTSUPP); } int afs_gn_symlink(vp, link, target, cred) -struct vnode *vp; -char *target; -char *link; -struct ucred *cred; + struct vnode *vp; + char *target; + char *link; + struct ucred *cred; { - struct vattr va; - int error; + struct vattr va; + int error; AFS_STATCNT(afs_gn_symlink); VATTR_NULL(&va); va.va_mode = 0777; error = afs_symlink(vp, link, &va, target, cred); - afs_Trace4(afs_iclSetp, CM_TRACE_GSYMLINK, ICL_TYPE_POINTER, (afs_int32)vp, - ICL_TYPE_STRING, link, ICL_TYPE_STRING, target, ICL_TYPE_LONG, error); - return(error); + afs_Trace4(afs_iclSetp, CM_TRACE_GSYMLINK, ICL_TYPE_POINTER, vp, + ICL_TYPE_STRING, link, ICL_TYPE_STRING, target, ICL_TYPE_LONG, + error); + return (error); } int afs_gn_readdir(vp, uiop, cred) -struct vnode *vp; -struct uio *uiop; -struct ucred *cred; + struct vnode *vp; + struct uio *uiop; + struct ucred *cred; { - int error; + int error; - AFS_STATCNT(afs_gn_readdir); + AFS_STATCNT(afs_gn_readdir); error = afs_readdir(vp, uiop, cred); - afs_Trace2(afs_iclSetp, CM_TRACE_GREADDIR, ICL_TYPE_POINTER, (afs_int32)vp, + afs_Trace2(afs_iclSetp, CM_TRACE_GREADDIR, ICL_TYPE_POINTER, vp, ICL_TYPE_LONG, error); - return(error); + return (error); } @@ -1301,11 +1648,15 @@ extern int afs_asyncbuf_cv; */ #define AIX_VM_BLKSIZE 8192 afs_gn_strategy(abp, cred) -struct ucred *cred; -register struct buf *abp; + struct ucred *cred; + register struct buf *abp; { register struct buf **lbp, *tbp; - int *lwbp; /* last guy in work chain */ +#ifdef AFS_64BIT_KERNEL + afs_int64 *lwbp; /* last quy in work chain */ +#else + int *lwbp; /* last guy in work chain */ +#endif struct buf *nbp, *qbp, *qnbp, *firstComparable; int doMerge; int oldPriority; @@ -1317,21 +1668,22 @@ register struct buf *abp; && !((y)->b_flags & B_PFPROT)) oldPriority = disable_lock(INTMAX, &afs_asyncbuf_lock); - for(tbp = abp; tbp; tbp=nbp) { + for (tbp = abp; tbp; tbp = nbp) { nbp = tbp->av_forw; /* remember for later */ tbp->b_work = 0; - tbp->av_back = (struct buf *) afs_biotime++; + tbp->av_back = (struct buf *)afs_biotime++; /* first insert the buffer into the afs_async queue. Insert buffer * sorted within its disk position within a set of comparable buffers. * Ensure that all comparable buffers are grouped contiguously. * Later on, we'll merge adjacent buffers into a single request. */ - firstComparable = (struct buf *) 0; + firstComparable = NULL; lbp = &afs_asyncbuf; - for(qbp = *lbp; qbp; lbp = &qbp->av_forw, qbp = *lbp) { + for (qbp = *lbp; qbp; lbp = &qbp->av_forw, qbp = *lbp) { if (EFS_COMPARABLE(tbp, qbp)) { - if (!firstComparable) firstComparable = qbp; + if (!firstComparable) + firstComparable = qbp; /* this buffer is comparable, so see if the next buffer * is farther in the file; if it is insert before next buffer. */ @@ -1350,7 +1702,7 @@ register struct buf *abp; /* do the insert before qbp now */ tbp->av_forw = *lbp; *lbp = tbp; - if (firstComparable == (struct buf *) 0) { + if (firstComparable == NULL) { /* next we're going to do all sorts of buffer merging tricks, but * here we know we're the only COMPARABLE block in the * afs_asyncbuf list, so we just skip that and continue with @@ -1383,31 +1735,34 @@ register struct buf *abp; * the file system block size, then we know that such blocks are also * on block boundaries. */ - - doMerge = 1; /* start the loop */ - while(doMerge) { /* loop until an iteration doesn't - * make any more changes */ + + doMerge = 1; /* start the loop */ + while (doMerge) { /* loop until an iteration doesn't + * make any more changes */ doMerge = 0; - for (qbp = firstComparable; ; qbp = qnbp) { + for (qbp = firstComparable;; qbp = qnbp) { qnbp = qbp->av_forw; - if (!qnbp) break; /* we're done */ - if (!EFS_COMPARABLE(qbp, qnbp)) break; + if (!qnbp) + break; /* we're done */ + if (!EFS_COMPARABLE(qbp, qnbp)) + break; /* try to merge qbp and qnbp */ /* first check if both not adjacent go on to next region */ - if ((dbtob(qbp->b_blkno) + qbp->b_bcount) != dbtob(qnbp->b_blkno)) + if ((dbtob(qbp->b_blkno) + qbp->b_bcount) != + dbtob(qnbp->b_blkno)) continue; /* note if both in the same block, the first byte of leftmost guy * and last byte of rightmost guy are in the same block. */ - if ((dbtob(qbp->b_blkno) & ~(AIX_VM_BLKSIZE-1)) == - ((dbtob(qnbp->b_blkno)+qnbp->b_bcount-1) & ~(AIX_VM_BLKSIZE-1))) { + if ((dbtob(qbp->b_blkno) & ~(AIX_VM_BLKSIZE - 1)) == + ((dbtob(qnbp->b_blkno) + qnbp->b_bcount - + 1) & ~(AIX_VM_BLKSIZE - 1))) { doMerge = 1; /* both in same block */ - } - else if ((qbp->b_bcount & (AIX_VM_BLKSIZE-1)) == 0 - && (qnbp->b_bcount & (AIX_VM_BLKSIZE-1)) == 0) { + } else if ((qbp->b_bcount & (AIX_VM_BLKSIZE - 1)) == 0 + && (qnbp->b_bcount & (AIX_VM_BLKSIZE - 1)) == 0) { doMerge = 1; /* both integral #s of blocks */ } if (doMerge) { @@ -1415,93 +1770,107 @@ register struct buf *abp; /* merge both of these blocks together */ /* first set age to the older of the two */ - if ((int) qnbp->av_back - (int) qbp->av_back < 0) +#ifdef AFS_64BIT_KERNEL + if ((afs_int64) qnbp->av_back - (afs_int64) qbp->av_back < + 0) +#else + if ((int)qnbp->av_back - (int)qbp->av_back < 0) +#endif qbp->av_back = qnbp->av_back; lwbp = &qbp->b_work; /* find end of qbp's work queue */ - for(xbp = (struct buf *)(*lwbp); xbp; - lwbp = &xbp->b_work, xbp = (struct buf *) (*lwbp)); + for (xbp = (struct buf *)(*lwbp); xbp; + lwbp = &xbp->b_work, xbp = (struct buf *)(*lwbp)); /* * now setting *lwbp will change the last ptr in the qbp's * work chain */ - qbp->av_forw = qnbp->av_forw; /* splice out qnbp */ - qbp->b_bcount += qnbp->b_bcount; /* fix count */ - *lwbp = (int) qnbp; /* append qnbp to end */ + qbp->av_forw = qnbp->av_forw; /* splice out qnbp */ + qbp->b_bcount += qnbp->b_bcount; /* fix count */ +#ifdef AFS_64BIT_KERNEL + *lwbp = (afs_int64) qnbp; /* append qnbp to end */ +#else + *lwbp = (int)qnbp; /* append qnbp to end */ +#endif /* * note that qnbp is bogus, but it doesn't matter because * we're going to restart the for loop now. */ - break; /* out of the for loop */ + break; /* out of the for loop */ } } } - } /* for loop for all interrupt data */ + } /* for loop for all interrupt data */ /* at this point, all I/O has been queued. Wakeup the daemon */ - e_wakeup_one((int*) &afs_asyncbuf_cv); + e_wakeup_one((int *)&afs_asyncbuf_cv); unlock_enable(oldPriority, &afs_asyncbuf_lock); return 0; } afs_inactive(avc, acred) - register struct vcache *avc; - struct AFS_UCRED *acred; + register struct vcache *avc; + struct AFS_UCRED *acred; { afs_InactiveVCache(avc, acred); } int afs_gn_revoke(vp) -struct vnode *vp; + struct vnode *vp; { AFS_STATCNT(afs_gn_revoke); /* NO SUPPORT for this in afs YET! */ - return(EOPNOTSUPP); + return (EOPNOTSUPP); } -int afs_gn_getacl(vp, uiop, cred) - struct vnode *vp; - struct uio *uiop; - struct ucred *cred; -{ +int +afs_gn_getacl(vp, uiop, cred) + struct vnode *vp; + struct uio *uiop; + struct ucred *cred; +{ return ENOSYS; }; -int afs_gn_setacl(vp, uiop, cred) - struct vnode *vp; - struct uio *uiop; - struct ucred *cred; -{ +int +afs_gn_setacl(vp, uiop, cred) + struct vnode *vp; + struct uio *uiop; + struct ucred *cred; +{ return ENOSYS; }; -int afs_gn_getpcl(vp, uiop, cred) - struct vnode *vp; - struct uio *uiop; - struct ucred *cred; -{ +int +afs_gn_getpcl(vp, uiop, cred) + struct vnode *vp; + struct uio *uiop; + struct ucred *cred; +{ return ENOSYS; }; -int afs_gn_setpcl(vp, uiop, cred) - struct vnode *vp; - struct uio *uiop; - struct ucred *cred; -{ +int +afs_gn_setpcl(vp, uiop, cred) + struct vnode *vp; + struct uio *uiop; + struct ucred *cred; +{ return ENOSYS; }; -int afs_gn_enosys() +int +afs_gn_enosys() { return ENOSYS; } - -extern struct vfsops Afs_vfsops; -extern struct vnodeops afs_gn_vnodeops; -extern int Afs_init(); + +extern struct vfsops Afs_vfsops; +extern struct vnodeops afs_gn_vnodeops; +extern int Afs_init(); #define AFS_CALLOUT_TBL_SIZE 256 @@ -1512,645 +1881,825 @@ extern int Afs_init(); */ static -vfs_mount(struct vfs *a, struct ucred *b) { - register glockOwner, ret; +vfs_mount(struct vfs *a, struct ucred *b) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*Afs_vfsops.vfs_mount)(a, b); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_mount) (a, b); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vfs_unmount(struct vfs *a, int b, struct ucred *c) { - register glockOwner, ret; +vfs_unmount(struct vfs *a, int b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*Afs_vfsops.vfs_unmount)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_unmount) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vfs_root(struct vfs *a, struct vnode **b, struct ucred *c) { - register glockOwner, ret; +vfs_root(struct vfs *a, struct vnode **b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*Afs_vfsops.vfs_root)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_root) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vfs_statfs(struct vfs *a, struct statfs *b, struct ucred *c) { - register glockOwner, ret; +vfs_statfs(struct vfs *a, struct statfs *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*Afs_vfsops.vfs_statfs)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_statfs) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vfs_sync(struct gfs *a) { - register glockOwner, ret; +vfs_sync(struct gfs *a) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*Afs_vfsops.vfs_sync)(a); - if (!glockOwner) - AFS_GUNLOCK(); - return ret; + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_sync) (a); + if (!glockOwner) + AFS_GUNLOCK(); + return ret; } static -vfs_vget(struct vfs *a, struct vnode **b, struct fileid *c - , struct ucred *d) { - register glockOwner, ret; +vfs_vget(struct vfs *a, struct vnode **b, struct fileid *c, struct ucred *d) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*Afs_vfsops.vfs_vget)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_vget) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vfs_cntl(struct vfs *a, int b, caddr_t c, size_t d, struct ucred *e) { - register glockOwner, ret; +vfs_cntl(struct vfs *a, int b, caddr_t c, size_t d, struct ucred *e) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*Afs_vfsops.vfs_cntl)(a, b, c, d, e); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_cntl) (a, b, c, d, e); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vfs_quotactl(struct vfs *a, int b, uid_t c, caddr_t d - , struct ucred *e) { - register glockOwner, ret; +vfs_quotactl(struct vfs *a, int b, uid_t c, caddr_t d, struct ucred *e) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*Afs_vfsops.vfs_quotactl)(a, b, c, d, e); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_quotactl) (a, b, c, d, e); + if (!glockOwner) + AFS_GUNLOCK(); + + return ret; +} + +#ifdef AFS_AIX51_ENV +static +vfs_syncvfs(struct gfs *a, struct vfs *b, int c, struct ucred *d) +{ + register glockOwner, ret; + + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*Afs_vfsops.vfs_syncvfs) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } +#endif struct vfsops locked_Afs_vfsops = { - vfs_mount, - vfs_unmount, - vfs_root, - vfs_statfs, - vfs_sync, - vfs_vget, - vfs_cntl, - vfs_quotactl, + vfs_mount, + vfs_unmount, + vfs_root, + vfs_statfs, + vfs_sync, + vfs_vget, + vfs_cntl, + vfs_quotactl, +#ifdef AFS_AIX51_ENV + vfs_syncvfs +#endif }; static -vn_link(struct vnode *a, struct vnode *b, char *c, struct ucred *d) { - register glockOwner, ret; +vn_link(struct vnode *a, struct vnode *b, char *c, struct ucred *d) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_link)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_link) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_mkdir(struct vnode *a, char *b, int c, struct ucred *d) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_mkdir(struct vnode *a, char *b, int32long64_t c, struct ucred *d) +{ +#else +vn_mkdir(struct vnode *a, char *b, int c, struct ucred *d) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_mkdir)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_mkdir) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_mknod(struct vnode *a, caddr_t b, int c, dev_t d, struct ucred *e) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_mknod(struct vnode *a, caddr_t b, int32long64_t c, dev_t d, + struct ucred *e) +{ +#else +vn_mknod(struct vnode *a, caddr_t b, int c, dev_t d, struct ucred *e) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_mknod)(a, b, c, d, e); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_mknod) (a, b, c, d, e); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_remove(struct vnode *a, struct vnode *b, char *c, struct ucred *d) { - register glockOwner, ret; +vn_remove(struct vnode *a, struct vnode *b, char *c, struct ucred *d) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_remove)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_remove) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_rename(struct vnode *a, struct vnode *b, caddr_t c - , struct vnode *d, struct vnode *e, caddr_t f, struct ucred *g) { - register glockOwner, ret; +vn_rename(struct vnode *a, struct vnode *b, caddr_t c, struct vnode *d, + struct vnode *e, caddr_t f, struct ucred *g) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_rename)(a, b, c, d, e, f, g); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_rename) (a, b, c, d, e, f, g); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_rmdir(struct vnode *a, struct vnode *b, char *c, struct ucred *d) { - register glockOwner, ret; +vn_rmdir(struct vnode *a, struct vnode *b, char *c, struct ucred *d) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_rmdir)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_rmdir) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static +#ifdef AFS_AIX51_ENV + vn_lookup(struct vnode *a, struct vnode **b, char *c, int32long64_t d, +#else vn_lookup(struct vnode *a, struct vnode **b, char *c, int d, - struct vattr *v, struct ucred *e) { - register glockOwner, ret; +#endif + struct vattr *v, struct ucred *e) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_lookup)(a, b, c, d, v, e); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_lookup) (a, b, c, d, v, e); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_fid(struct vnode *a, struct fileid *b, struct ucred *c) { - register glockOwner, ret; +vn_fid(struct vnode *a, struct fileid *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_fid)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_fid) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_open(struct vnode *a, int b, int c, caddr_t *d, struct ucred *e) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_open(struct vnode *a, int b, int c, caddr_t * d, struct ucred *e) +{ +#else +vn_open(struct vnode *a, int32long64_t b, ext_t c, caddr_t * d, + struct ucred *e) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_open)(a, b, c, d, e); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_open) (a, b, c, d, e); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_create(struct vnode *a, struct vnode **b, int c, caddr_t d - , int e, caddr_t *f, struct ucred *g) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_create(struct vnode *a, struct vnode **b, int32long64_t c, caddr_t d, + int32long64_t e, caddr_t * f, struct ucred *g) +{ +#else +vn_create(struct vnode *a, struct vnode **b, int c, caddr_t d, int e, + caddr_t * f, struct ucred *g) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_create)(a, b, c, d, e, f, g); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_create) (a, b, c, d, e, f, g); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_hold(struct vnode *a) { - register glockOwner, ret; +vn_hold(struct vnode *a) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_hold)(a); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_hold) (a); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_rele(struct vnode *a) { - register glockOwner, ret; +vn_rele(struct vnode *a) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_rele)(a); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_rele) (a); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_close(struct vnode *a, int b, caddr_t c, struct ucred *d) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_close(struct vnode *a, int32long64_t b, caddr_t c, struct ucred *d) +{ +#else +vn_close(struct vnode *a, int b, caddr_t c, struct ucred *d) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_close)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_close) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_map(struct vnode *a, caddr_t b, uint c, uint d, uint e, struct ucred *f) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_map(struct vnode *a, caddr_t b, uint32long64_t c, uint32long64_t d, + uint32long64_t e, struct ucred *f) +{ +#else +vn_map(struct vnode *a, caddr_t b, uint c, uint d, uint e, struct ucred *f) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_map)(a, b, c, d, e, f); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_map) (a, b, c, d, e, f); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_unmap(struct vnode *a, int b, struct ucred *c) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_unmap(struct vnode *a, int32long64_t b, struct ucred *c) +{ +#else +vn_unmap(struct vnode *a, int b, struct ucred *c) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_unmap)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_unmap) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_access(struct vnode *a, int b, int c, struct ucred *d) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_access(struct vnode *a, int32long64_t b, int32long64_t c, struct ucred *d) +{ +#else +vn_access(struct vnode *a, int b, int c, struct ucred *d) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_access)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_access) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_getattr(struct vnode *a, struct vattr *b, struct ucred *c) { - register glockOwner, ret; +vn_getattr(struct vnode *a, struct vattr *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_getattr)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_getattr) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_setattr(struct vnode *a, int b, int c, int d, int e, struct ucred *f) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_setattr(struct vnode *a, int32long64_t b, int32long64_t c, int32long64_t d, + int32long64_t e, struct ucred *f) +{ +#else +vn_setattr(struct vnode *a, int b, int c, int d, int e, struct ucred *f) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_setattr)(a, b, c, d, e, f); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_setattr) (a, b, c, d, e, f); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static +#ifdef AFS_AIX51_ENV + vn_fclear(struct vnode *a, int32long64_t b, offset_t c, offset_t d +#else vn_fclear(struct vnode *a, int b, offset_t c, offset_t d - , caddr_t e, struct ucred *f) { - register glockOwner, ret; +#endif + , caddr_t e, struct ucred *f) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_fclear)(a, b, c, d, e, f); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_fclear) (a, b, c, d, e, f); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_fsync(struct vnode *a, int b, int c, struct ucred *d) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_fsync(struct vnode *a, int32long64_t b, int32long64_t c, struct ucred *d) +{ +#else +vn_fsync(struct vnode *a, int b, int c, struct ucred *d) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_fsync)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_fsync) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_ftrunc(struct vnode *a, int b, offset_t c, caddr_t d, struct ucred *e) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_ftrunc(struct vnode *a, int32long64_t b, offset_t c, caddr_t d, + struct ucred *e) +{ +#else +vn_ftrunc(struct vnode *a, int b, offset_t c, caddr_t d, struct ucred *e) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_ftrunc)(a, b, c, d, e); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_ftrunc) (a, b, c, d, e); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_rdwr(struct vnode *a, enum uio_rw b, int c, struct uio *d - , int e, caddr_t f, struct vattr *v, struct ucred *g) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_rdwr(struct vnode *a, enum uio_rw b, int32long64_t c, struct uio *d, + ext_t e, caddr_t f, struct vattr *v, struct ucred *g) +{ +#else +vn_rdwr(struct vnode *a, enum uio_rw b, int c, struct uio *d, int e, + caddr_t f, struct vattr *v, struct ucred *g) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_rdwr)(a, b, c, d, e, f, v, g); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_rdwr) (a, b, c, d, e, f, v, g); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_lockctl(struct vnode *a, offset_t b, struct eflock *c, int d - , int (*e)(), ulong *f, struct ucred *g) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_lockctl(struct vnode *a, offset_t b, struct eflock *c, int32long64_t d, + int (*e) (), ulong32int64_t * f, struct ucred *g) +{ +#else +vn_lockctl(struct vnode *a, offset_t b, struct eflock *c, int d, int (*e) (), + ulong * f, struct ucred *g) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_lockctl)(a, b, c, d, e, f, g); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_lockctl) (a, b, c, d, e, f, g); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_ioctl(struct vnode *a, int b, caddr_t c, size_t d, int e, struct ucred *f) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_ioctl(struct vnode *a, int32long64_t b, caddr_t c, size_t d, ext_t e, + struct ucred *f) +{ +#else +vn_ioctl(struct vnode *a, int b, caddr_t c, size_t d, int e, struct ucred *f) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_ioctl)(a, b, c, d, e, f); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_ioctl) (a, b, c, d, e, f); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_readlink(struct vnode *a, struct uio *b, struct ucred *c) { - register glockOwner, ret; +vn_readlink(struct vnode *a, struct uio *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_readlink)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_readlink) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_select(struct vnode *a, int b, ushort c, ushort *d, void (*e)() - , caddr_t f, struct ucred *g) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV + vn_select(struct vnode *a, int32long64_t b, ushort c, ushort * d, + void (*e) () +#else +vn_select(struct vnode *a, int b, ushort c, ushort * d, void (*e) () +#endif + , caddr_t f, struct ucred *g) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_select)(a, b, c, d, e, f, g); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_select) (a, b, c, d, e, f, g); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_symlink(struct vnode *a, char *b, char *c, struct ucred *d) { - register glockOwner, ret; +vn_symlink(struct vnode *a, char *b, char *c, struct ucred *d) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_symlink)(a, b, c, d); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_symlink) (a, b, c, d); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_readdir(struct vnode *a, struct uio *b, struct ucred *c) { - register glockOwner, ret; +vn_readdir(struct vnode *a, struct uio *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_readdir)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_readdir) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_revoke(struct vnode *a, int b, int c, struct vattr *d, struct ucred *e) { - register glockOwner, ret; +#ifdef AFS_AIX51_ENV +vn_revoke(struct vnode *a, int32long64_t b, int32long64_t c, struct vattr *d, + struct ucred *e) +{ +#else +vn_revoke(struct vnode *a, int b, int c, struct vattr *d, struct ucred *e) +{ +#endif + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_revoke)(a, b, c, d, e); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_revoke) (a, b, c, d, e); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_getacl(struct vnode *a, struct uio *b, struct ucred *c) { - register glockOwner, ret; +vn_getacl(struct vnode *a, struct uio *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_getacl)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_getacl) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_setacl(struct vnode *a, struct uio *b, struct ucred *c) { - register glockOwner, ret; +vn_setacl(struct vnode *a, struct uio *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_setacl)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_setacl) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_getpcl(struct vnode *a, struct uio *b, struct ucred *c) { - register glockOwner, ret; +vn_getpcl(struct vnode *a, struct uio *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_getpcl)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_getpcl) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } static -vn_setpcl(struct vnode *a, struct uio *b, struct ucred *c) { - register glockOwner, ret; +vn_setpcl(struct vnode *a, struct uio *b, struct ucred *c) +{ + register glockOwner, ret; - glockOwner = ISAFS_GLOCK(); - if (!glockOwner) - AFS_GLOCK(); - ret = (*afs_gn_vnodeops.vn_setpcl)(a, b, c); - if (!glockOwner) - AFS_GUNLOCK(); + glockOwner = ISAFS_GLOCK(); + if (!glockOwner) + AFS_GLOCK(); + ret = (*afs_gn_vnodeops.vn_setpcl) (a, b, c); + if (!glockOwner) + AFS_GUNLOCK(); - return ret; + return ret; } extern int afs_gn_strategy(); struct vnodeops locked_afs_gn_vnodeops = { - vn_link, - vn_mkdir, - vn_mknod, - vn_remove, - vn_rename, - vn_rmdir, - vn_lookup, - vn_fid, - vn_open, - vn_create, - vn_hold, - vn_rele, - vn_close, - vn_map, - vn_unmap, - vn_access, - vn_getattr, - vn_setattr, - vn_fclear, - vn_fsync, - vn_ftrunc, - vn_rdwr, - vn_lockctl, - vn_ioctl, - vn_readlink, - vn_select, - vn_symlink, - vn_readdir, - afs_gn_strategy, /* no locking!!! (discovered the hard way) */ - vn_revoke, - vn_getacl, - vn_setacl, - vn_getpcl, - vn_setpcl, + vn_link, + vn_mkdir, + vn_mknod, + vn_remove, + vn_rename, + vn_rmdir, + vn_lookup, + vn_fid, + vn_open, + vn_create, + vn_hold, + vn_rele, + vn_close, + vn_map, + vn_unmap, + vn_access, + vn_getattr, + vn_setattr, + vn_fclear, + vn_fsync, + vn_ftrunc, + vn_rdwr, + vn_lockctl, + vn_ioctl, + vn_readlink, + vn_select, + vn_symlink, + vn_readdir, + afs_gn_strategy, /* no locking!!! (discovered the hard way) */ + vn_revoke, + vn_getacl, + vn_setacl, + vn_getpcl, + vn_setpcl, + afs_gn_enosys, /* vn_seek */ + afs_gn_enosys, /* vn_fsync_range */ + afs_gn_enosys, /* vn_create_attr */ + afs_gn_enosys, /* vn_finfo */ + afs_gn_enosys, /* vn_map_lloff */ + afs_gn_enosys, /* vn_readdir_eofp */ + afs_gn_enosys, /* vn_rdwr_attr */ + afs_gn_enosys, /* vn_memcntl */ + afs_gn_enosys, /* vn_spare7 */ + afs_gn_enosys, /* vn_spare8 */ + afs_gn_enosys, /* vn_spare9 */ + afs_gn_enosys, /* vn_spareA */ + afs_gn_enosys, /* vn_spareB */ + afs_gn_enosys, /* vn_spareC */ + afs_gn_enosys, /* vn_spareD */ + afs_gn_enosys, /* vn_spareE */ + afs_gn_enosys /* vn_spareF */ +#ifdef AFS_AIX51_ENV + , afs_gn_enosys, /* pagerBackRange */ + afs_gn_enosys, /* pagerGetFileSize */ + afs_gn_enosys, /* pagerReadAhead */ + afs_gn_enosys, /* pagerWriteBehind */ + afs_gn_enosys /* pagerEndCopy */ +#endif }; struct gfs afs_gfs = { - &locked_Afs_vfsops, - &locked_afs_gn_vnodeops, - AFS_MOUNT_AFS, - "afs", - Afs_init, - GFS_VERSION4 | GFS_REMOTE, - NULL + &locked_Afs_vfsops, + &locked_afs_gn_vnodeops, + AFS_MOUNT_AFS, + "afs", + Afs_init, + GFS_VERSION4 | GFS_REMOTE, + NULL }; - diff --git a/src/afs/DARWIN/osi_file.c b/src/afs/DARWIN/osi_file.c index 48dbea120..6bc21e3df 100644 --- a/src/afs/DARWIN/osi_file.c +++ b/src/afs/DARWIN/osi_file.c @@ -8,91 +8,93 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_file.c,v 1.1.1.4 2001/09/11 14:24:53 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_file.c,v 1.8 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ -#include "../afs/osi_inode.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#include "afs/osi_inode.h" -int afs_osicred_initialized=0; -struct AFS_UCRED afs_osi_cred; -afs_lock_t afs_xosi; /* lock is for tvattr */ +int afs_osicred_initialized = 0; +struct AFS_UCRED afs_osi_cred; +afs_lock_t afs_xosi; /* lock is for tvattr */ extern struct osi_dev cacheDev; extern struct mount *afs_cacheVfsp; int afs_CacheFSType = -1; /* Initialize the cache operations. Called while initializing cache files. */ -void afs_InitDualFSCacheOps(struct vnode *vp) +void +afs_InitDualFSCacheOps(struct vnode *vp) { int code; static int inited = 0; if (inited) - return; + return; inited = 1; if (vp == NULL) - return; + return; if (strncmp("hfs", vp->v_mount->mnt_vfc->vfc_name, 3) == 0) - afs_CacheFSType = AFS_APPL_HFS_CACHE; - else - if (strncmp("ufs", vp->v_mount->mnt_vfc->vfc_name, 3) == 0) - afs_CacheFSType = AFS_APPL_UFS_CACHE; + afs_CacheFSType = AFS_APPL_HFS_CACHE; + else if (strncmp("ufs", vp->v_mount->mnt_vfc->vfc_name, 3) == 0) + afs_CacheFSType = AFS_APPL_UFS_CACHE; else - osi_Panic("Unknown cache vnode type\n"); + osi_Panic("Unknown cache vnode type\n"); } -ino_t VnodeToIno(vnode_t *avp) +ino_t +VnodeToIno(vnode_t * avp) { - unsigned long ret; + unsigned long ret; - if (afs_CacheFSType == AFS_APPL_UFS_CACHE) { - struct inode *ip = VTOI(avp); - ret=ip->i_number; - } else if (afs_CacheFSType == AFS_APPL_HFS_CACHE) { + if (afs_CacheFSType == AFS_APPL_UFS_CACHE) { + struct inode *ip = VTOI(avp); + ret = ip->i_number; + } else if (afs_CacheFSType == AFS_APPL_HFS_CACHE) { #ifndef VTOH - struct vattr va; - if (VOP_GETATTR(avp, &va, &afs_osi_cred, current_proc())) - osi_Panic("VOP_GETATTR failed in VnodeToIno\n"); - ret=va.va_fileid; + struct vattr va; + if (VOP_GETATTR(avp, &va, &afs_osi_cred, current_proc())) + osi_Panic("VOP_GETATTR failed in VnodeToIno\n"); + ret = va.va_fileid; #else - struct hfsnode *hp = VTOH(avp); - ret=H_FILEID(hp); + struct hfsnode *hp = VTOH(avp); + ret = H_FILEID(hp); #endif - } else - osi_Panic("VnodeToIno called before cacheops initialized\n"); - return ret; + } else + osi_Panic("VnodeToIno called before cacheops initialized\n"); + return ret; } -dev_t VnodeToDev(vnode_t *avp) +dev_t +VnodeToDev(vnode_t * avp) { - - if (afs_CacheFSType == AFS_APPL_UFS_CACHE) { - struct inode *ip = VTOI(avp); - return ip->i_dev; - } else - if (afs_CacheFSType == AFS_APPL_HFS_CACHE) { -#ifndef VTOH /* slow, but works */ - struct vattr va; - if (VOP_GETATTR(avp, &va, &afs_osi_cred, current_proc())) - osi_Panic("VOP_GETATTR failed in VnodeToDev\n"); - return va.va_fsid; /* XXX they say it's the dev.... */ + + if (afs_CacheFSType == AFS_APPL_UFS_CACHE) { + struct inode *ip = VTOI(avp); + return ip->i_dev; + } else if (afs_CacheFSType == AFS_APPL_HFS_CACHE) { +#ifndef VTOH /* slow, but works */ + struct vattr va; + if (VOP_GETATTR(avp, &va, &afs_osi_cred, current_proc())) + osi_Panic("VOP_GETATTR failed in VnodeToDev\n"); + return va.va_fsid; /* XXX they say it's the dev.... */ #else - struct hfsnode *hp = VTOH(avp); - return H_DEV(hp); + struct hfsnode *hp = VTOH(avp); + return H_DEV(hp); #endif - } else - osi_Panic("VnodeToDev called before cacheops initialized\n"); + } else + osi_Panic("VnodeToDev called before cacheops initialized\n"); } -void *osi_UFSOpen(ainode) - afs_int32 ainode; +void * +osi_UFSOpen(afs_int32 ainode) { struct vnode *vp; struct vattr va; @@ -101,25 +103,26 @@ void *osi_UFSOpen(ainode) afs_int32 code = 0; int dummy; AFS_STATCNT(osi_UFSOpen); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) { + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) { osi_Panic("UFSOpen called for non-UFS cache\n"); } if (!afs_osicred_initialized) { /* valid for alpha_osf, SunOS, Ultrix */ memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED)); afs_osi_cred.cr_ref++; - afs_osi_cred.cr_ngroups=1; + afs_osi_cred.cr_ngroups = 1; afs_osicred_initialized = 1; } - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); AFS_GUNLOCK(); - if (afs_CacheFSType == AFS_APPL_HFS_CACHE) - code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, &ainode, &vp, &va, &dummy); /* XXX hfs is broken */ + if (afs_CacheFSType == AFS_APPL_HFS_CACHE) + code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, &ainode, &vp, &va, &dummy); /* XXX hfs is broken */ + else if (afs_CacheFSType == AFS_APPL_UFS_CACHE) + code = + igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, + &vp, &va, &dummy); else - if (afs_CacheFSType == AFS_APPL_UFS_CACHE) - code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode, &vp, &va, &dummy); - else - panic("osi_UFSOpen called before cacheops initialized\n"); + panic("osi_UFSOpen called before cacheops initialized\n"); AFS_GLOCK(); if (code) { osi_FreeSmallSpace(afile); @@ -128,20 +131,20 @@ void *osi_UFSOpen(ainode) afile->vnode = vp; afile->size = va.va_size; afile->offset = 0; - afile->proc = (int (*)()) 0; - afile->inum = ainode; /* for hint validity checking */ + afile->proc = (int (*)())0; + afile->inum = ainode; /* for hint validity checking */ return (void *)afile; } -afs_osi_Stat(afile, astat) - register struct osi_file *afile; - register struct osi_stat *astat; { +int +afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) +{ register afs_int32 code; struct vattr tvattr; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi,320); + MObtainWriteLock(&afs_xosi, 320); AFS_GUNLOCK(); - code=VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, current_proc()); + code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, current_proc()); AFS_GLOCK(); if (code == 0) { astat->size = tvattr.va_size; @@ -153,21 +156,21 @@ afs_osi_Stat(afile, astat) return code; } -osi_UFSClose(afile) - register struct osi_file *afile; - { - AFS_STATCNT(osi_Close); - if(afile->vnode) { +int +osi_UFSClose(register struct osi_file *afile) +{ + AFS_STATCNT(osi_Close); + if (afile->vnode) { AFS_RELE(afile->vnode); - } - - osi_FreeSmallSpace(afile); - return 0; - } - -osi_UFSTruncate(afile, asize) - register struct osi_file *afile; - afs_int32 asize; { + } + + osi_FreeSmallSpace(afile); + return 0; +} + +int +osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) +{ struct AFS_UCRED *oldCred; struct vattr tvattr; register afs_int32 code; @@ -179,41 +182,41 @@ osi_UFSTruncate(afile, asize) * small enough. Check now and save some time. */ code = afs_osi_Stat(afile, &tstat); - if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi,321); + if (code || tstat.size <= asize) + return code; + MObtainWriteLock(&afs_xosi, 321); VATTR_NULL(&tvattr); tvattr.va_size = asize; AFS_GUNLOCK(); - code=VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, current_proc()); + code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, current_proc()); AFS_GLOCK(); MReleaseWriteLock(&afs_xosi); return code; } -void osi_DisableAtimes(avp) -struct vnode *avp; +void +osi_DisableAtimes(struct vnode *avp) { - if (afs_CacheFSType == AFS_APPL_UFS_CACHE) { - struct inode *ip = VTOI(avp); - ip->i_flag &= ~IN_ACCESS; - } -#ifdef VTOH /* can't do this without internals */ - else if (afs_CacheFSType == AFS_APPL_HFS_CACHE) { - struct hfsnode *hp = VTOH(avp); - hp->h_nodeflags &= ~IN_ACCESS; - } + if (afs_CacheFSType == AFS_APPL_UFS_CACHE) { + struct inode *ip = VTOI(avp); + ip->i_flag &= ~IN_ACCESS; + } +#ifdef VTOH /* can't do this without internals */ + else if (afs_CacheFSType == AFS_APPL_HFS_CACHE) { + struct hfsnode *hp = VTOH(avp); + hp->h_nodeflags &= ~IN_ACCESS; + } #endif } /* Generic read interface */ -afs_osi_Read(afile, offset, aptr, asize) - register struct osi_file *afile; - int offset; - char *aptr; - afs_int32 asize; { +int +afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; unsigned int resid; register afs_int32 code; @@ -223,59 +226,61 @@ afs_osi_Read(afile, offset, aptr, asize) * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ - if ( !afile ) { - if ( !afs_shuttingdown ) + if (!afile) { + if (!afs_shuttingdown) osi_Panic("osi_Read called with null param"); else return EIO; } - if (offset != -1) afile->offset = offset; + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, + AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; osi_DisableAtimes(afile->vnode); - } - else { + } else { afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, - ICL_TYPE_INT32, code); + ICL_TYPE_INT32, code); code = -1; } return code; } /* Generic write interface */ -afs_osi_Write(afile, offset, aptr, asize) - register struct osi_file *afile; - char *aptr; - afs_int32 offset; - afs_int32 asize; { +int +afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; unsigned int resid; register afs_int32 code; AFS_STATCNT(osi_Write); - if ( !afile ) + if (!afile) osi_Panic("afs_osi_Write called with null param"); - if (offset != -1) afile->offset = offset; + if (offset != -1) + afile->offset = offset; { AFS_GUNLOCK(); - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + afile->offset, AFS_UIOSYS, IO_UNIT, &afs_osi_cred, + &resid); AFS_GLOCK(); } if (code == 0) { code = asize - resid; afile->offset += code; - } - else { + } else { code = -1; } if (afile->proc) { - (*afile->proc)(afile, code); + (*afile->proc) (afile, code); } return code; } @@ -285,13 +290,12 @@ afs_osi_Write(afile, offset, aptr, asize) void -shutdown_osifile() +shutdown_osifile(void) { - extern int afs_cold_shutdown; + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osifile); - if (afs_cold_shutdown) { - afs_osicred_initialized = 0; - } + AFS_STATCNT(shutdown_osifile); + if (afs_cold_shutdown) { + afs_osicred_initialized = 0; + } } - diff --git a/src/afs/DARWIN/osi_groups.c b/src/afs/DARWIN/osi_groups.c index a5a5d9eed..ded6bb485 100644 --- a/src/afs/DARWIN/osi_groups.c +++ b/src/afs/DARWIN/osi_groups.c @@ -15,63 +15,58 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_groups.c,v 1.1.1.3 2001/07/14 22:19:58 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_groups.c,v 1.5 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset); + afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset); static int -afs_setgroups( - struct proc *proc, - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent); + afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups, + gid_t * gidset, int change_parent); int Afs_xsetgroups(p, args, retval) - struct proc *p; - void *args; - int *retval; + struct proc *p; + void *args; + int *retval; { int code = 0; struct vrequest treq; struct ucred *cr; pcred_readlock(p); - cr=crdup(p->p_cred->pc_ucred); + cr = crdup(p->p_cred->pc_ucred); pcred_unlock(p); AFS_STATCNT(afs_xsetgroups); AFS_GLOCK(); - + code = afs_InitReq(&treq, cr); AFS_GUNLOCK(); crfree(cr); - if (code) return setgroups(p, args, retval); /* afs has shut down */ + if (code) + return setgroups(p, args, retval); /* afs has shut down */ code = setgroups(p, args, retval); /* Note that if there is a pag already in the new groups we don't * overwrite it with the old pag. */ pcred_readlock(p); - cr=crdup(p->p_cred->pc_ucred); + cr = crdup(p->p_cred->pc_ucred); pcred_unlock(p); if (PagInCred(cr) == NOPAG) { if (((treq.uid >> 24) & 0xff) == 'A') { AFS_GLOCK(); /* we've already done a setpag, so now we redo it */ - AddPag(p, treq.uid, &cr ); + AddPag(p, treq.uid, &cr); AFS_GUNLOCK(); } } @@ -82,11 +77,11 @@ Afs_xsetgroups(p, args, retval) int setpag(proc, cred, pagvalue, newpag, change_parent) - struct proc *proc; - struct ucred **cred; - afs_uint32 pagvalue; - afs_uint32 *newpag; - afs_uint32 change_parent; + struct proc *proc; + struct ucred **cred; + afs_uint32 pagvalue; + afs_uint32 *newpag; + afs_uint32 change_parent; { gid_t gidset[NGROUPS]; int ngroups, code; @@ -99,12 +94,12 @@ setpag(proc, cred, pagvalue, newpag, change_parent) if (ngroups + 2 > NGROUPS) { return (E2BIG); } - for (j = ngroups -1; j >= 1; j--) { - gidset[j+2] = gidset[j]; + for (j = ngroups - 1; j >= 1; j--) { + gidset[j + 2] = gidset[j]; } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); + *newpag = (pagvalue == -1 ? genpag() : pagvalue); afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]); code = afs_setgroups(proc, cred, ngroups, gidset, change_parent); return code; @@ -112,10 +107,7 @@ setpag(proc, cred, pagvalue, newpag, change_parent) static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset) +afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset) { int ngrps, savengrps; gid_t *gp; @@ -124,19 +116,15 @@ afs_getgroups( savengrps = ngrps = MIN(ngroups, cred->cr_ngroups); gp = cred->cr_groups; while (ngrps--) - *gidset++ = *gp++; + *gidset++ = *gp++; return savengrps; } static int -afs_setgroups( - struct proc *proc, - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent) +afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups, + gid_t * gidset, int change_parent) { int ngrps; int i; @@ -158,16 +146,16 @@ afs_setgroups( if (change_parent) { crhold(cr); pcred_writelock(proc->p_pptr); - oldcr=proc->p_pptr->p_cred->pc_ucred; - proc->p_pptr->p_cred->pc_ucred=cr; + oldcr = proc->p_pptr->p_cred->pc_ucred; + proc->p_pptr->p_cred->pc_ucred = cr; pcred_unlock(proc->p_pptr); crfree(oldcr); } crhold(cr); pcred_writelock(proc); - oldcr=proc->p_cred->pc_ucred; - proc->p_cred->pc_ucred=cr; + oldcr = proc->p_cred->pc_ucred; + proc->p_cred->pc_ucred = cr; pcred_unlock(proc); crfree(oldcr); - return(0); + return (0); } diff --git a/src/afs/DARWIN/osi_inode.c b/src/afs/DARWIN/osi_inode.c index adf5d93fd..a219f59d7 100644 --- a/src/afs/DARWIN/osi_inode.c +++ b/src/afs/DARWIN/osi_inode.c @@ -13,14 +13,15 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_inode.c,v 1.1.1.3 2001/07/14 22:20:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_inode.c,v 1.6 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/osi_inode.h" -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/osi_inode.h" +#include "afs/afs_stats.h" /* statistics stuff */ #include extern struct ucred afs_osi_cred; @@ -44,43 +45,44 @@ getinode(fs, dev, inode, vpp, perror) register struct vnode *vp; register struct mount *mp; extern struct mount *rootfs; - if (mp = rootfs) do { - /* - * XXX Also do the test for MFS - */ - if (!strcmp(mp->mnt_vfc->vfc_name, "ufs")) { - ump = VFSTOUFS(mp); - if (ump->um_fs == NULL) - break; - if (ump->um_dev == dev) { - fs = ump->um_mountp; - } - } + if (mp = rootfs) + do { + /* + * XXX Also do the test for MFS + */ + if (!strcmp(mp->mnt_vfc->vfc_name, "ufs")) { + ump = VFSTOUFS(mp); + if (ump->um_fs == NULL) + break; + if (ump->um_dev == dev) { + fs = ump->um_mountp; + } + } #ifdef VFSTOHFS - if (!strcmp(mp->mnt_vfc->vfc_name, "hfs")) { - hmp = VFSTOHFS(mp); + if (!strcmp(mp->mnt_vfc->vfc_name, "hfs")) { + hmp = VFSTOHFS(mp); #if 0 - if (hmp->hfs_mp == NULL) - break; + if (hmp->hfs_mp == NULL) + break; #endif - if (hmp->hfs_raw_dev == dev) { - fs = hmp->hfs_mp; - } - } + if (hmp->hfs_raw_dev == dev) { + fs = hmp->hfs_mp; + } + } #endif - mp = CIRCLEQ_NEXT(mp, mnt_list); - } while (mp != rootfs); + mp = CIRCLEQ_NEXT(mp, mnt_list); + } while (mp != rootfs); if (!fs) - return(ENXIO); + return (ENXIO); } - code=VFS_VGET(fs, (void *)inode, &vp); + code = VFS_VGET(fs, (void *)inode, &vp); if (code) { *perror = BAD_IGET; return code; - } else { + } else { *vpp = vp; - return(0); + return (0); } } extern int afs_CacheFSType; @@ -100,34 +102,34 @@ igetinode(vfsp, dev, inode, vpp, va, perror) AFS_STATCNT(igetinode); if ((code = getinode(vfsp, dev, inode, &vp, perror)) != 0) { - return(code); + return (code); } if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK) { - printf("igetinode: bad type %d\n", vp->v_type); - iforget(vp); - return(ENOENT); + printf("igetinode: bad type %d\n", vp->v_type); + iforget(vp); + return (ENOENT); } VOP_GETATTR(vp, va, &afs_osi_cred, current_proc()); if (va->va_mode == 0) { /* Not an allocated inode */ - iforget(vp); - return(ENOENT); + iforget(vp); + return (ENOENT); } if (vfsp && afs_CacheFSType == AFS_APPL_HFS_CACHE && va->va_nlink == 0) { - printf("igetinode: hfs nlink 0\n"); + printf("igetinode: hfs nlink 0\n"); } if (va->va_nlink == 0) { vput(vp); - return(ENOENT); + return (ENOENT); } VOP_UNLOCK(vp, 0, current_proc()); *vpp = vp; - return(0); + return (0); } iforget(vp) -struct vnode *vp; + struct vnode *vp; { AFS_STATCNT(iforget); @@ -135,8 +137,8 @@ struct vnode *vp; vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, current_proc()); /* this whole thing is too wierd. Why??? XXX */ if (vp->v_usecount == 1) { - vp->v_usecount=0; - VOP_UNLOCK(vp,0, current_proc()); + vp->v_usecount = 0; + VOP_UNLOCK(vp, 0, current_proc()); #if 0 simple_lock(&vnode_free_list_slock); TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist); @@ -158,72 +160,70 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval) long *retval; long dev, near_inode, param1, param2, param3, param4; { - int dummy, err=0; + int dummy, err = 0; struct inode *ip, *newip; register int code; struct vnode *vp; - + AFS_STATCNT(afs_syscall_icreate); - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = getinode(0, (dev_t)dev, 2, &ip, &dummy); + code = getinode(0, (dev_t) dev, 2, &ip, &dummy); if (code) { - return(ENOENT); + return (ENOENT); } - code = ialloc(ip, (ino_t)near_inode, 0, &newip); + code = ialloc(ip, (ino_t) near_inode, 0, &newip); iput(ip); if (code) { - return(code); + return (code); } IN_LOCK(newip); - newip->i_flag |= IACC|IUPD|ICHG; - + newip->i_flag |= IACC | IUPD | ICHG; + newip->i_nlink = 1; newip->i_mode = IFREG; - + IN_UNLOCK(newip); vp = ITOV(newip); VN_LOCK(vp); vp->v_type = VREG; VN_UNLOCK(vp); - - if ( !vp->v_object) - { - extern struct vfs_ubcops ufs_ubcops; - extern struct vm_ubc_object* ubc_object_allocate(); - struct vm_ubc_object* vop; - vop = ubc_object_allocate(&vp, &ufs_ubcops, - vp->v_mount->m_funnel); - VN_LOCK(vp); - vp->v_object = vop; - VN_UNLOCK(vp); - } - - + + if (!vp->v_object) { + extern struct vfs_ubcops ufs_ubcops; + extern struct vm_ubc_object *ubc_object_allocate(); + struct vm_ubc_object *vop; + vop = ubc_object_allocate(&vp, &ufs_ubcops, vp->v_mount->m_funnel); + VN_LOCK(vp); + vp->v_object = vop; + VN_UNLOCK(vp); + } + + IN_LOCK(newip); - newip->i_flags |= IC_XUID|IC_XGID; + newip->i_flags |= IC_XUID | IC_XGID; newip->i_flags &= ~IC_PROPLIST; newip->i_vicep1 = param1; - if (param2 == 0x1fffffff/*INODESPECIAL*/) { + if (param2 == 0x1fffffff /*INODESPECIAL*/) { newip->i_vicep2 = ((0x1fffffff << 3) + (param4 & 0x3)); - newip->i_vicep3a = (u_short)(param3 >> 16); - newip->i_vicep3b = (u_short)param3; + newip->i_vicep3a = (u_short) (param3 >> 16); + newip->i_vicep3b = (u_short) param3; } else { - newip->i_vicep2 = (((param2 >> 16) & 0x1f) << 27) + - (((param4 >> 16) & 0x1f) << 22) + - (param3 & 0x3fffff); - newip->i_vicep3a = (u_short)param4; - newip->i_vicep3b = (u_short)param2; + newip->i_vicep2 = + (((param2 >> 16) & 0x1f) << 27) + + (((param4 >> 16) & 0x1f) << 22) + (param3 & 0x3fffff); + newip->i_vicep3a = (u_short) param4; + newip->i_vicep3b = (u_short) param2; } newip->i_vicemagic = VICEMAGIC; - + *retval = newip->i_number; IN_UNLOCK(newip); iput(newip); - return(code); + return (code); } @@ -233,37 +233,37 @@ afs_syscall_iopen(dev, inode, usrmod, retval) { struct file *fp; struct inode *ip; - struct vnode *vp = (struct vnode *)0; + struct vnode *vp = NULL; int dummy; int fd; extern struct fileops vnops; register int code; - + AFS_STATCNT(afs_syscall_iopen); - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy); + code = igetinode(0, (dev_t) dev, (ino_t) inode, &ip, &dummy); if (code) { - return(code); + return (code); } if ((code = falloc(&fp, &fd)) != 0) { iput(ip); - return(code); + return (code); } IN_UNLOCK(ip); - + FP_LOCK(fp); - fp->f_flag = (usrmod-FOPEN) & FMASK; + fp->f_flag = (usrmod - FOPEN) & FMASK; fp->f_type = DTYPE_VNODE; fp->f_ops = &vnops; - fp->f_data = (caddr_t)ITOV(ip); - + fp->f_data = (caddr_t) ITOV(ip); + FP_UNLOCK(fp); U_FD_SET(fd, fp, &u.u_file_state); *retval = fd; - return(0); + return (0); } @@ -279,18 +279,18 @@ afs_syscall_iincdec(dev, inode, inode_p1, amount) int dummy; struct inode *ip; register int code; - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy); + code = igetinode(0, (dev_t) dev, (ino_t) inode, &ip, &dummy); if (code) { - return(code); + return (code); } if (!IS_VICEMAGIC(ip)) { - return(EPERM); + return (EPERM); } else if (ip->i_vicep1 != inode_p1) { - return(ENXIO); + return (ENXIO); } ip->i_nlink += amount; if (ip->i_nlink == 0) { @@ -298,24 +298,26 @@ afs_syscall_iincdec(dev, inode, inode_p1, amount) } ip->i_flag |= ICHG; iput(ip); - return(0); + return (0); } #else afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval) long *retval; long dev, near_inode, param1, param2, param3, param4; { - return EOPNOTSUPP; + return EOPNOTSUPP; } + afs_syscall_iopen(dev, inode, usrmod, retval) long *retval; int dev, inode, usrmod; { - return EOPNOTSUPP; + return EOPNOTSUPP; } + afs_syscall_iincdec(dev, inode, inode_p1, amount) int dev, inode, inode_p1, amount; { - return EOPNOTSUPP; + return EOPNOTSUPP; } #endif diff --git a/src/afs/DARWIN/osi_inode.h b/src/afs/DARWIN/osi_inode.h index f392a2666..c1b48fb84 100644 --- a/src/afs/DARWIN/osi_inode.h +++ b/src/afs/DARWIN/osi_inode.h @@ -25,13 +25,13 @@ #define i_vicep1 i_din.di_gen #define i_vicep2 i_din.di_uid #define i_vicep3 i_din.di_gid -#define i_vicep4 i_din.di_spare[0] /* not used */ +#define i_vicep4 i_din.di_spare[0] /* not used */ #define di_vicemagic di_flags #define di_vicep1 di_gen #define di_vicep2 di_uid #define di_vicep3 di_gid -#define di_vicep4 di_spare[0] /* not used */ +#define di_vicep4 di_spare[0] /* not used */ #define IS_VICEMAGIC(ip) ((ip)->i_vicemagic == VICEMAGIC) #define IS_DVICEMAGIC(dp) ((dp)->di_vicemagic == VICEMAGIC) diff --git a/src/afs/DARWIN/osi_machdep.h b/src/afs/DARWIN/osi_machdep.h index 9feda0345..c7eeaf652 100644 --- a/src/afs/DARWIN/osi_machdep.h +++ b/src/afs/DARWIN/osi_machdep.h @@ -21,7 +21,7 @@ #ifdef XAFS_DARWIN_ENV #ifndef _MACH_ETAP_H_ #define _MACH_ETAP_H_ -typedef unsigned short etap_event_t; +typedef unsigned short etap_event_t; #endif #endif @@ -37,7 +37,7 @@ typedef unsigned short etap_event_t; #define FTRUNC 0 /* vcexcl - used only by afs_create */ -enum vcexcl { EXCL, NONEXCL } ; +enum vcexcl { EXCL, NONEXCL }; /* * Time related macros @@ -103,8 +103,8 @@ extern struct lock__bsd__ afs_global_lock; #define AFS_APPL_UFS_CACHE 1 #define AFS_APPL_HFS_CACHE 2 -extern ino_t VnodeToIno(vnode_t *vp); -extern dev_t VnodeToDev(vnode_t *vp); +extern ino_t VnodeToIno(vnode_t * vp); +extern dev_t VnodeToDev(vnode_t * vp); #endif /* KERNEL */ diff --git a/src/afs/DARWIN/osi_misc.c b/src/afs/DARWIN/osi_misc.c index 4a23bbd6c..f5afaec76 100644 --- a/src/afs/DARWIN/osi_misc.c +++ b/src/afs/DARWIN/osi_misc.c @@ -8,37 +8,39 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_misc.c,v 1.1.1.3 2001/07/14 22:20:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_misc.c,v 1.5 2003/07/15 23:14:17 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" +#include "afs/sysincludes.h" +#include "afsincludes.h" #include -int osi_lookupname(char *aname, enum uio_seg seg, int followlink, - struct vnode **dirvpp, struct vnode **vpp) +int +osi_lookupname(char *aname, enum uio_seg seg, int followlink, + struct vnode **dirvpp, struct vnode **vpp) { - struct nameidata n; - int flags,error; - flags=0; - flags=LOCKLEAF; - if (followlink) - flags|=FOLLOW; - else - flags|=NOFOLLOW; -/* if (dirvpp) flags|=WANTPARENT;*/ /* XXX LOCKPARENT? */ - NDINIT(&n, LOOKUP, flags, seg, aname, current_proc()); - if (error=namei(&n)) - return error; - *vpp=n.ni_vp; + struct nameidata n; + int flags, error; + flags = 0; + flags = LOCKLEAF; + if (followlink) + flags |= FOLLOW; + else + flags |= NOFOLLOW; + /* if (dirvpp) flags|=WANTPARENT; *//* XXX LOCKPARENT? */ + NDINIT(&n, LOOKUP, flags, seg, aname, current_proc()); + if (error = namei(&n)) + return error; + *vpp = n.ni_vp; /* if (dirvpp) *dirvpp = n.ni_dvp; #/ /* should we do this? */ - VOP_UNLOCK(n.ni_vp, 0, current_proc()); - return 0; + VOP_UNLOCK(n.ni_vp, 0, current_proc()); + return 0; } /* @@ -47,12 +49,13 @@ int osi_lookupname(char *aname, enum uio_seg seg, int followlink, * Note that it must NOT set errno. */ -afs_suser() { +afs_suser() +{ int error; - struct proc *p=current_proc(); + struct proc *p = current_proc(); if ((error = suser(p->p_ucred, &p->p_acflag)) == 0) { - return(1); + return (1); } - return(0); + return (0); } diff --git a/src/afs/DARWIN/osi_module.c b/src/afs/DARWIN/osi_module.c index 5de3cf224..4a490e2b8 100644 --- a/src/afs/DARWIN/osi_module.c +++ b/src/afs/DARWIN/osi_module.c @@ -1,14 +1,15 @@ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_module.c,v 1.1.1.6 2002/09/26 18:58:04 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_module.c,v 1.10 2003/07/15 23:14:18 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#ifdef AFS_DARWIN60_ENV /* not in Kernel.framework anymore !?! */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#ifdef AFS_DARWIN60_ENV /* not in Kernel.framework anymore !?! */ #include #else -#include "../sys/syscall.h" +#include "sys/syscall.h" #endif #include @@ -22,44 +23,48 @@ extern int afs3_syscall(); extern int ioctl(); extern int setgroups(); extern int maxvfsconf; -kern_return_t afs_modload(struct kmod_info *ki, void *data) +kern_return_t +afs_modload(struct kmod_info *ki, void *data) { - if (sysent[AFS_SYSCALL].sy_call != nosys) { - printf("AFS_SYSCALL in use. aborting\n"); - return KERN_FAILURE; - } - memset(&afs_vfsconf, 0, sizeof(struct vfsconf)); - strcpy(afs_vfsconf.vfc_name, "afs"); - afs_vfsconf.vfc_vfsops=&afs_vfsops; - afs_vfsconf.vfc_typenum=maxvfsconf++;/* oddly not VT_AFS */ - afs_vfsconf.vfc_flags=MNT_NODEV; - if (vfsconf_add(&afs_vfsconf)) { - printf("AFS: vfsconf_add failed. aborting\n"); - return KERN_FAILURE; - } - sysent[SYS_setgroups].sy_call=Afs_xsetgroups; - sysent[SYS_ioctl].sy_call=afs_xioctl; - sysent[AFS_SYSCALL].sy_call=afs3_syscall; - sysent[AFS_SYSCALL].sy_narg = 5; - sysent[AFS_SYSCALL].sy_parallel = 0; + if (sysent[AFS_SYSCALL].sy_call != nosys) { + printf("AFS_SYSCALL in use. aborting\n"); + return KERN_FAILURE; + } + memset(&afs_vfsconf, 0, sizeof(struct vfsconf)); + strcpy(afs_vfsconf.vfc_name, "afs"); + afs_vfsconf.vfc_vfsops = &afs_vfsops; + afs_vfsconf.vfc_typenum = maxvfsconf++; /* oddly not VT_AFS */ + afs_vfsconf.vfc_flags = MNT_NODEV; + if (vfsconf_add(&afs_vfsconf)) { + printf("AFS: vfsconf_add failed. aborting\n"); + return KERN_FAILURE; + } + sysent[SYS_setgroups].sy_call = Afs_xsetgroups; + sysent[SYS_ioctl].sy_call = afs_xioctl; + sysent[AFS_SYSCALL].sy_call = afs3_syscall; + sysent[AFS_SYSCALL].sy_narg = 5; + sysent[AFS_SYSCALL].sy_parallel = 0; #ifdef KERNEL_FUNNEL - sysent[AFS_SYSCALL].sy_funnel=KERNEL_FUNNEL; + sysent[AFS_SYSCALL].sy_funnel = KERNEL_FUNNEL; #endif - return KERN_SUCCESS; + return KERN_SUCCESS; } -kern_return_t afs_modunload(struct kmod_info *ki, void *data) + +kern_return_t +afs_modunload(struct kmod_info * ki, void *data) { - if (afs_globalVFS) - return KERN_FAILURE; - if (vfsconf_del("afs")) - return KERN_FAILURE; - /* give up syscall entries for ioctl & setgroups, which we've stolen */ - sysent[SYS_ioctl].sy_call = ioctl; - sysent[SYS_setgroups].sy_call = setgroups; - /* give up the stolen syscall entry */ - sysent[AFS_SYSCALL].sy_narg = 0; - sysent[AFS_SYSCALL].sy_call = nosys; - return KERN_SUCCESS; - } + if (afs_globalVFS) + return KERN_FAILURE; + if (vfsconf_del("afs")) + return KERN_FAILURE; + /* give up syscall entries for ioctl & setgroups, which we've stolen */ + sysent[SYS_ioctl].sy_call = ioctl; + sysent[SYS_setgroups].sy_call = setgroups; + /* give up the stolen syscall entry */ + sysent[AFS_SYSCALL].sy_narg = 0; + sysent[AFS_SYSCALL].sy_call = nosys; + return KERN_SUCCESS; +} -KMOD_EXPLICIT_DECL(org.openafs.filesystems.afs, VERSION, afs_modload, afs_modunload) +KMOD_EXPLICIT_DECL(org.openafs.filesystems.afs, VERSION, afs_modload, + afs_modunload) diff --git a/src/afs/DARWIN/osi_prototypes.h b/src/afs/DARWIN/osi_prototypes.h index ed68243c1..012036e4d 100644 --- a/src/afs/DARWIN/osi_prototypes.h +++ b/src/afs/DARWIN/osi_prototypes.h @@ -14,9 +14,12 @@ #ifndef _OSI_PROTO_H_ #define _OSI_PROTO_H_ +/* osi_file.c */ +extern afs_rwlock_t afs_xosi; + /* osi_misc.c */ extern int osi_lookupname(char *aname, enum uio_seg seg, int followlink, - struct vnode **dirvpp, struct vnode **vpp); + struct vnode **dirvpp, struct vnode **vpp); /* osi_vm.c */ extern void osi_VM_NukePages(struct vnode *vp, off_t offset, off_t size); extern int osi_VM_Setup(struct vcache *avc, int force); diff --git a/src/afs/DARWIN/osi_sleep.c b/src/afs/DARWIN/osi_sleep.c index 5025b12f4..c9788a2f2 100644 --- a/src/afs/DARWIN/osi_sleep.c +++ b/src/afs/DARWIN/osi_sleep.c @@ -8,37 +8,39 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_sleep.c,v 1.1.1.4 2002/01/22 19:48:05 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_sleep.c,v 1.9 2003/07/15 23:14:18 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok); -void afs_osi_Wakeup(char *event); -void afs_osi_Sleep(char *event); static char waitV; -void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) +void +afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) { AFS_STATCNT(osi_InitWaitHandle); achandle->proc = (caddr_t) 0; } /* cancel osi_Wait */ -void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) { caddr_t proc; AFS_STATCNT(osi_CancelWait); proc = achandle->proc; - if (proc == 0) return; - achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ + if (proc == 0) + return; + achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ afs_osi_Wakeup(&waitV); } @@ -46,22 +48,24 @@ void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) * Waits for data on ahandle, or ams ms later. ahandle may be null. * Returns 0 if timeout and EINTR if signalled. */ -int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) +int +afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) { int code; afs_int32 endTime, tid; - struct proc *p=current_proc(); + struct proc *p = current_proc(); AFS_STATCNT(osi_Wait); - endTime = osi_Time() + (ams/1000); + endTime = osi_Time() + (ams / 1000); if (ahandle) - ahandle->proc = (caddr_t)p; + ahandle->proc = (caddr_t) p; do { AFS_ASSERT_GLOCK(); code = 0; code = osi_TimedSleep(&waitV, ams, aintok); - if (code) break; /* if something happened, quit now */ + if (code) + break; /* if something happened, quit now */ /* if we we're cancelled, quit now */ if (ahandle && (ahandle->proc == (caddr_t) 0)) { /* we've been signalled */ @@ -74,22 +78,23 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) typedef struct afs_event { - struct afs_event *next; /* next in hash chain */ - char *event; /* lwp event: an address */ - int refcount; /* Is it in use? */ - int seq; /* Sequence number: this is incremented - by wakeup calls; wait will not return until - it changes */ + struct afs_event *next; /* next in hash chain */ + char *event; /* lwp event: an address */ + int refcount; /* Is it in use? */ + int seq; /* Sequence number: this is incremented + * by wakeup calls; wait will not return until + * it changes */ } afs_event_t; #define HASHSIZE 128 -afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */ +afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */ #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1)); int afs_evhashcnt = 0; /* Get and initialize event structure corresponding to lwp event (i.e. address) * */ -static afs_event_t *afs_getevent(char *event) +static afs_event_t * +afs_getevent(char *event) { afs_event_t *evp, *newp = 0; int hashcode; @@ -107,7 +112,7 @@ static afs_event_t *afs_getevent(char *event) evp = evp->next; } if (!newp) { - newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t)); + newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t)); afs_evhashcnt++; newp->next = afs_evhasht[hashcode]; afs_evhasht[hashcode] = newp; @@ -122,7 +127,8 @@ static afs_event_t *afs_getevent(char *event) #define relevent(evp) ((evp)->refcount--) -void afs_osi_Sleep(char *event) +void +afs_osi_Sleep(void *event) { struct afs_event *evp; int seq; @@ -133,10 +139,10 @@ void afs_osi_Sleep(char *event) AFS_ASSERT_GLOCK(); AFS_GUNLOCK(); #ifdef AFS_DARWIN14_ENV - /* this is probably safe for all versions, but testing is hard */ - sleep(event, PVFS); + /* this is probably safe for all versions, but testing is hard */ + sleep(event, PVFS); #else - assert_wait((event_t)event, 0); + assert_wait((event_t) event, 0); thread_block(0); #endif AFS_GLOCK(); @@ -144,6 +150,13 @@ void afs_osi_Sleep(char *event) relevent(evp); } +int +afs_osi_SleepSig(void *event) +{ + afs_osi_Sleep(event); + return 0; +} + /* osi_TimedSleep * * Arguments: @@ -153,61 +166,66 @@ void afs_osi_Sleep(char *event) * * Returns 0 if timeout and EINTR if signalled. */ -static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) +static int +osi_TimedSleep(char *event, afs_int32 ams, int aintok) { int code = 0; struct afs_event *evp; - int ticks,seq; + int ticks, seq; int prio; - ticks = ( ams * afs_hz )/1000; + ticks = (ams * afs_hz) / 1000; evp = afs_getevent(event); - seq=evp->seq; + seq = evp->seq; AFS_GUNLOCK(); #ifdef AFS_DARWIN14_ENV /* this is probably safe for all versions, but testing is hard. */ /* using tsleep instead of assert_wait/thread_set_timer/thread_block - allows shutdown to work in 1.4 */ + * allows shutdown to work in 1.4 */ /* lack of PCATCH does *not* prevent signal delivery, neither does - a low priority. We would need to deal with ERESTART here if we - wanted to mess with p->p_sigmask, and messing with p_sigignore is - not the way to go.... (someone correct me if I'm wrong) - */ + * a low priority. We would need to deal with ERESTART here if we + * wanted to mess with p->p_sigmask, and messing with p_sigignore is + * not the way to go.... (someone correct me if I'm wrong) + */ if (aintok) - prio=PCATCH|PPAUSE; + prio = PCATCH | PPAUSE; else - prio=PVFS; - code=tsleep(event, prio, "afs_osi_TimedSleep", ticks); -#else - assert_wait((event_t)event, aintok ? THREAD_ABORTSAFE : THREAD_UNINT); + prio = PVFS; + code = tsleep(event, prio, "afs_osi_TimedSleep", ticks); +#else + assert_wait((event_t) event, aintok ? THREAD_ABORTSAFE : THREAD_UNINT); thread_set_timer(ticks, NSEC_PER_SEC / hz); thread_block(0); - code=0; + code = 0; #endif AFS_GLOCK(); if (seq == evp->seq) code = EINTR; - + relevent(evp); return code; } -void afs_osi_Wakeup(char *event) +int +afs_osi_Wakeup(void *event) { struct afs_event *evp; - + int ret = 1; + evp = afs_getevent(event); if (evp->refcount > 1) { - evp->seq++; + evp->seq++; #ifdef AFS_DARWIN14_ENV - /* this is probably safe for all versions, but testing is hard. */ - wakeup(event); + /* this is probably safe for all versions, but testing is hard. */ + wakeup(event); #else - thread_wakeup((event_t)event); + thread_wakeup((event_t) event); #endif + ret = 0; } relevent(evp); + return ret; } diff --git a/src/afs/DARWIN/osi_vfsops.c b/src/afs/DARWIN/osi_vfsops.c index f62d31f30..f5c15eb81 100644 --- a/src/afs/DARWIN/osi_vfsops.c +++ b/src/afs/DARWIN/osi_vfsops.c @@ -4,11 +4,12 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_vfsops.c,v 1.1.1.7 2004/01/10 20:52:50 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_vfsops.c,v 1.11 2003/10/24 06:26:01 shadow Exp $"); -#include /* Standard vendor system headers */ -#include /* Afs-based standard headers */ -#include /* statistics */ +#include /* Standard vendor system headers */ +#include /* Afs-based standard headers */ +#include /* statistics */ #include #include #include @@ -22,47 +23,47 @@ struct mount *afs_globalVFS = 0; int afs_quotactl() { - return EOPNOTSUPP; + return EOPNOTSUPP; } int afs_fhtovp(mp, fhp, vpp) -struct mount *mp; -struct fid *fhp; -struct vnode **vpp; + struct mount *mp; + struct fid *fhp; + struct vnode **vpp; { - return (EINVAL); + return (EINVAL); } int afs_vptofh(vp, fhp) -struct vnode *vp; -struct fid *fhp; + struct vnode *vp; + struct fid *fhp; { - return (EINVAL); + return (EINVAL); } int afs_start(mp, flags, p) -struct mount *mp; -int flags; -struct proc *p; + struct mount *mp; + int flags; + struct proc *p; { - return (0); /* nothing to do. ? */ + return (0); /* nothing to do. ? */ } int afs_mount(mp, path, data, ndp, p) -register struct mount *mp; -char *path; -caddr_t data; -struct nameidata *ndp; -struct proc *p; + register struct mount *mp; + char *path; + caddr_t data; + struct nameidata *ndp; + struct proc *p; { /* ndp contains the mounted-from device. Just ignore it. - we also don't care about our proc struct. */ + * we also don't care about our proc struct. */ size_t size; int error; @@ -72,7 +73,7 @@ struct proc *p; AFS_GLOCK(); AFS_STATCNT(afs_mount); - if (data == NULL && afs_globalVFS) { /* Don't allow remounts. */ + if (data == NULL && afs_globalVFS) { /* Don't allow remounts. */ AFS_GUNLOCK(); return (EBUSY); } @@ -80,27 +81,27 @@ struct proc *p; afs_globalVFS = mp; mp->vfs_bsize = 8192; vfs_getnewfsid(mp); - mp->mnt_stat.f_iosize=8192; - - (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size); + mp->mnt_stat.f_iosize = 8192; + + (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size); memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN); if (data == NULL) { strcpy(mp->mnt_stat.f_mntfromname, "AFS"); /* null terminated string "AFS" will fit, just leave it be. */ - mp->mnt_data = (qaddr_t)NULL; + mp->mnt_data = (qaddr_t) NULL; } else { struct VenusFid *rootFid = NULL; struct volume *tvp; char volName[MNAMELEN]; - (void) copyinstr((char *)data, volName, MNAMELEN-1, &size); + (void)copyinstr((char *)data, volName, MNAMELEN - 1, &size); memset(volName + size, 0, MNAMELEN - size); if (volName[0] == 0) { strcpy(mp->mnt_stat.f_mntfromname, "AFS"); - mp->mnt_data = (qaddr_t)&afs_rootFid; + mp->mnt_data = (qaddr_t) & afs_rootFid; } else { struct cell *localcell = afs_GetPrimaryCell(READ_LOCK); if (localcell == NULL) { @@ -109,15 +110,16 @@ struct proc *p; } /* Set the volume identifier to "AFS:volume.name" */ - snprintf(mp->mnt_stat.f_mntfromname, MNAMELEN-1, "AFS:%s", + snprintf(mp->mnt_stat.f_mntfromname, MNAMELEN - 1, "AFS:%s", volName); - tvp = afs_GetVolumeByName(volName, localcell->cellNum, 1, - (struct vrequest *)0, READ_LOCK); - + tvp = + afs_GetVolumeByName(volName, localcell->cellNum, 1, + (struct vrequest *)0, READ_LOCK); + if (tvp) { int volid = (tvp->roVol ? tvp->roVol : tvp->volume); - MALLOC(rootFid, struct VenusFid *, sizeof(*rootFid), - M_UFSMNT, M_WAITOK); + MALLOC(rootFid, struct VenusFid *, sizeof(*rootFid), M_UFSMNT, + M_WAITOK); rootFid->Cell = localcell->cellNum; rootFid->Fid.Volume = volid; rootFid->Fid.Vnode = 1; @@ -126,30 +128,30 @@ struct proc *p; AFS_GUNLOCK(); return ENODEV; } - - mp->mnt_data = (qaddr_t)rootFid; + + mp->mnt_data = (qaddr_t) rootFid; } } strcpy(mp->mnt_stat.f_fstypename, "afs"); AFS_GUNLOCK(); - (void) afs_statfs(mp, &mp->mnt_stat, p); + (void)afs_statfs(mp, &mp->mnt_stat, p); return 0; } int afs_unmount(mp, flags, p) -struct mount *mp; -int flags; -struct proc *p; + struct mount *mp; + int flags; + struct proc *p; { - + AFS_GLOCK(); AFS_STATCNT(afs_unmount); - if (mp->mnt_data != (qaddr_t)-1) { + if (mp->mnt_data != (qaddr_t) - 1) { if (mp->mnt_data != NULL) { FREE(mp->mnt_data, M_UFSMNT); - mp->mnt_data = (qaddr_t)-1; + mp->mnt_data = (qaddr_t) - 1; } else { if (flags & MNT_FORCE) { afs_globalVFS = 0; @@ -168,52 +170,54 @@ struct proc *p; } int -afs_root(struct mount *mp, - struct vnode **vpp) +afs_root(struct mount *mp, struct vnode **vpp) { int error; struct vrequest treq; - register struct vcache *tvp=0; - struct proc *p=current_proc(); + register struct vcache *tvp = 0; + struct proc *p = current_proc(); struct ucred cr; pcred_readlock(p); - cr=*p->p_cred->pc_ucred; + cr = *p->p_cred->pc_ucred; pcred_unlock(p); AFS_GLOCK(); AFS_STATCNT(afs_root); - if (mp->mnt_data == NULL - && afs_globalVp && (afs_globalVp->states & CStatd)) { + if (mp->mnt_data == NULL && afs_globalVp + && (afs_globalVp->states & CStatd)) { tvp = afs_globalVp; - error=0; - } else if (mp->mnt_data == (qaddr_t)-1) { + error = 0; + } else if (mp->mnt_data == (qaddr_t) - 1) { error = ENOENT; } else { struct VenusFid *rootFid = (mp->mnt_data == NULL) ? &afs_rootFid : (struct VenusFid *)mp->mnt_data; - - if (!(error = afs_InitReq(&treq, &cr)) && - !(error = afs_CheckInit())) { - tvp = afs_GetVCache(rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + afs_globalVp = NULL; + } + + if (!(error = afs_InitReq(&treq, &cr)) && !(error = afs_CheckInit())) { + tvp = afs_GetVCache(rootFid, &treq, NULL, NULL); /* we really want this to stay around */ if (tvp) { if (mp->mnt_data == NULL) afs_globalVp = tvp; } else - error = ENOENT; + error = ENOENT; } } if (tvp) { - osi_vnhold(tvp,0); - AFS_GUNLOCK(); - vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p); - AFS_GLOCK(); - if (mp->mnt_data == NULL) { + osi_vnhold(tvp, 0); + AFS_GUNLOCK(); + vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p); + AFS_GLOCK(); + if (mp->mnt_data == NULL) { afs_globalVFS = mp; - } + } *vpp = AFSTOV(tvp); - AFSTOV(tvp)->v_flag |= VROOT; + AFSTOV(tvp)->v_flag |= VROOT; AFSTOV(tvp)->v_vfsp = mp; } @@ -225,9 +229,9 @@ afs_root(struct mount *mp, int afs_vget(mp, lfl, vp) -struct mount *mp; -struct vnode *vp; -int lfl; + struct mount *mp; + struct vnode *vp; + int lfl; { int error; printf("vget called. help!\n"); @@ -237,11 +241,12 @@ int lfl; } error = vget(vp, lfl, current_proc()); if (!error) - insmntque(vp, mp); /* take off free list */ + insmntque(vp, mp); /* take off free list */ return error; } -int afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p) +int +afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p) { AFS_GLOCK(); AFS_STATCNT(afs_statfs); @@ -257,144 +262,141 @@ int afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p) * storing something there. */ abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = - abp->f_ffree = 2000000; + abp->f_ffree = 2000000; abp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0]; abp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1]; if (abp != &mp->mnt_stat) { abp->f_type = mp->mnt_vfc->vfc_typenum; - memcpy((caddr_t)&abp->f_mntonname[0], (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN); - memcpy((caddr_t)&abp->f_mntfromname[0], (caddr_t)mp->mnt_stat.f_mntfromname, MNAMELEN); + memcpy((caddr_t) & abp->f_mntonname[0], + (caddr_t) mp->mnt_stat.f_mntonname, MNAMELEN); + memcpy((caddr_t) & abp->f_mntfromname[0], + (caddr_t) mp->mnt_stat.f_mntfromname, MNAMELEN); } AFS_GUNLOCK(); return 0; } -int afs_sync(mp, waitfor, cred, p) -struct mount *mp; -int waitfor; -struct ucred *cred; -struct prioc *p; +int +afs_sync(mp, waitfor, cred, p) + struct mount *mp; + int waitfor; + struct ucred *cred; + struct prioc *p; { -return 0; + return 0; } u_int32_t afs_darwin_realmodes = 0; -int afs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) -int *name; -u_int namelen; -void *oldp; -size_t *oldlenp; -void *newp; -size_t newlen; -struct proc *p; +int afs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, + void *newp, size_t newlen, struct proc *p) { int error; switch (name[0]) { case AFS_SC_ALL: - /* nothing defined */ - break; + /* nothing defined */ + break; case AFS_SC_DARWIN: - if (namelen < 3) + if (namelen < 3) return ENOENT; switch (name[1]) { case AFS_SC_DARWIN_ALL: switch (name[2]) { case AFS_SC_DARWIN_ALL_REALMODES: - return sysctl_int(oldp, oldlenp, newp, newlen, - &afs_darwin_realmodes); + return sysctl_int(oldp, oldlenp, newp, newlen, + &afs_darwin_realmodes); } break; - /* darwin version specific sysctl's goes here */ + /* darwin version specific sysctl's goes here */ } break; } return EOPNOTSUPP; } - -typedef (*PFI)(); -extern int vfs_opv_numops; /* The total number of defined vnode operations */ +typedef (*PFI) (); +extern int vfs_opv_numops; /* The total number of defined vnode operations */ extern struct vnodeopv_desc afs_vnodeop_opv_desc; -int afs_init(struct vfsconf *vfc) { - int j; - int (**opv_desc_vector)(); - struct vnodeopv_entry_desc *opve_descp; - - - - MALLOC(afs_vnodeop_p, PFI *, vfs_opv_numops*sizeof(PFI), M_TEMP, M_WAITOK); - - memset(afs_vnodeop_p, 0, vfs_opv_numops*sizeof(PFI)); - - opv_desc_vector = afs_vnodeop_p; - for (j=0; afs_vnodeop_opv_desc.opv_desc_ops[j].opve_op; j++) { - opve_descp = &(afs_vnodeop_opv_desc.opv_desc_ops[j]); - - /* - * Sanity check: is this operation listed - * in the list of operations? We check this - * by seeing if its offest is zero. Since - * the default routine should always be listed - * first, it should be the only one with a zero - * offset. Any other operation with a zero - * offset is probably not listed in - * vfs_op_descs, and so is probably an error. - * - * A panic here means the layer programmer - * has committed the all-too common bug - * of adding a new operation to the layer's - * list of vnode operations but - * not adding the operation to the system-wide - * list of supported operations. - */ - if (opve_descp->opve_op->vdesc_offset == 0 && - opve_descp->opve_op->vdesc_offset != VOFFSET(vop_default)) { - printf("afs_init: operation %s not listed in %s.\n", - opve_descp->opve_op->vdesc_name, - "vfs_op_descs"); - panic ("load_afs: bad operation"); - } - /* - * Fill in this entry. - */ - opv_desc_vector[opve_descp->opve_op->vdesc_offset] = - opve_descp->opve_impl; - } - - /* - * Finally, go back and replace unfilled routines - * with their default. (Sigh, an O(n^3) algorithm. I - * could make it better, but that'd be work, and n is small.) - */ - - /* - * Force every operations vector to have a default routine. - */ - opv_desc_vector = afs_vnodeop_p; - if (opv_desc_vector[VOFFSET(vop_default)]==NULL) { - panic("afs_init: operation vector without default routine."); - } - for (j = 0;jopve_op->vdesc_offset == 0 + && opve_descp->opve_op->vdesc_offset != VOFFSET(vop_default)) { + printf("afs_init: operation %s not listed in %s.\n", + opve_descp->opve_op->vdesc_name, "vfs_op_descs"); + panic("load_afs: bad operation"); + } + /* + * Fill in this entry. + */ + opv_desc_vector[opve_descp->opve_op->vdesc_offset] = + opve_descp->opve_impl; + } + + /* + * Finally, go back and replace unfilled routines + * with their default. (Sigh, an O(n^3) algorithm. I + * could make it better, but that'd be work, and n is small.) + */ + + /* + * Force every operations vector to have a default routine. + */ + opv_desc_vector = afs_vnodeop_p; + if (opv_desc_vector[VOFFSET(vop_default)] == NULL) { + panic("afs_init: operation vector without default routine."); + } + for (j = 0; j < vfs_opv_numops; j++) + if (opv_desc_vector[j] == NULL) + opv_desc_vector[j] = opv_desc_vector[VOFFSET(vop_default)]; } struct vfsops afs_vfsops = { - afs_mount, - afs_start, - afs_unmount, - afs_root, - afs_quotactl, - afs_statfs, - afs_sync, - afs_vget, - afs_fhtovp, - afs_vptofh, - afs_init, - afs_sysctl + afs_mount, + afs_start, + afs_unmount, + afs_root, + afs_quotactl, + afs_statfs, + afs_sync, + afs_vget, + afs_fhtovp, + afs_vptofh, + afs_init, + afs_sysctl }; diff --git a/src/afs/DARWIN/osi_vm.c b/src/afs/DARWIN/osi_vm.c index f52b152e6..be31ed6a6 100644 --- a/src/afs/DARWIN/osi_vm.c +++ b/src/afs/DARWIN/osi_vm.c @@ -8,13 +8,14 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_vm.c,v 1.1.1.7 2002/09/26 18:58:05 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_vm.c,v 1.11 2003/07/15 23:14:18 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ #include /* Try to discard pages, in order to recycle a vcache entry. @@ -34,11 +35,9 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_vm.c,v 1.1.1.7 2002/09/2 * OSF/1 Locking: VN_LOCK has been called. */ int -osi_VM_FlushVCache(avc, slept) - struct vcache *avc; - int *slept; +osi_VM_FlushVCache(struct vcache *avc, int *slept) { - struct vnode *vp=AFSTOV(avc); + struct vnode *vp = AFSTOV(avc); #ifdef AFS_DARWIN14_ENV if (UBCINFOEXISTS(vp)) return EBUSY; @@ -56,13 +55,12 @@ osi_VM_FlushVCache(avc, slept) AFS_GUNLOCK(); cache_purge(vp); #ifndef AFS_DARWIN14_ENV - if (UBCINFOEXISTS(vp)) - { - ubc_clean(vp, 1); - ubc_uncache(vp); - ubc_release(vp); - ubc_info_free(vp); - } + if (UBCINFOEXISTS(vp)) { + ubc_clean(vp, 1); + ubc_uncache(vp); + ubc_release(vp); + ubc_info_free(vp); + } #endif AFS_GLOCK(); @@ -77,17 +75,16 @@ osi_VM_FlushVCache(avc, slept) * re-obtained. */ void -osi_VM_StoreAllSegments(avc) - struct vcache *avc; +osi_VM_StoreAllSegments(struct vcache *avc) { - struct vnode *vp=AFSTOV(avc); + struct vnode *vp = AFSTOV(avc); ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); if (UBCINFOEXISTS(vp)) { ubc_pushdirty(vp); } AFS_GLOCK(); - ObtainWriteLock(&avc->lock,94); + ObtainWriteLock(&avc->lock, 94); } /* Try to invalidate pages, for "fs flush" or "fs flushv"; or @@ -100,26 +97,23 @@ osi_VM_StoreAllSegments(avc) * be some pages around when we return, newly created by concurrent activity. */ void -osi_VM_TryToSmush(avc, acred, sync) - struct vcache *avc; - struct AFS_UCRED *acred; - int sync; +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { - struct vnode *vp=AFSTOV(avc); + struct vnode *vp = AFSTOV(avc); void *object; kern_return_t kret; off_t size, lastpg; - + ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); - if (UBCINFOEXISTS(vp)) { - size=ubc_getsize(vp); - kret=ubc_invalidate(vp,0,size); - if (kret != 1) /* should be KERN_SUCCESS */ - printf("TryToSmush: invalidate failed (error = %d)\n", kret); + if (UBCINFOEXISTS(vp)) { + size = ubc_getsize(vp); + kret = ubc_invalidate(vp, 0, size); + if (kret != 1) /* should be KERN_SUCCESS */ + printf("TryToSmush: invalidate failed (error = %d)\n", kret); } AFS_GLOCK(); - ObtainWriteLock(&avc->lock,59); + ObtainWriteLock(&avc->lock, 59); } /* Purge VM for a file when its callback is revoked. @@ -130,22 +124,20 @@ osi_VM_TryToSmush(avc, acred, sync) this, and also making sure that ubc's idea of the filesize is right more often */ void -osi_VM_FlushPages(avc, credp) - struct vcache *avc; - struct AFS_UCRED *credp; +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { - struct vnode *vp=AFSTOV(avc); + struct vnode *vp = AFSTOV(avc); void *object; kern_return_t kret; off_t size; - if (UBCINFOEXISTS(vp)) { - size=ubc_getsize(vp); - kret=ubc_invalidate(vp,0,size); - if (kret != 1) /* Should be KERN_SUCCESS */ - printf("VMFlushPages: invalidate failed (error = %d)\n", kret); - /* XXX what about when not CStatd */ - if (avc->states & CStatd && size != avc->m.Length) - ubc_setsize(vp, avc->m.Length); + if (UBCINFOEXISTS(vp)) { + size = ubc_getsize(vp); + kret = ubc_invalidate(vp, 0, size); + if (kret != 1) /* Should be KERN_SUCCESS */ + printf("VMFlushPages: invalidate failed (error = %d)\n", kret); + /* XXX what about when not CStatd */ + if (avc->states & CStatd && size != avc->m.Length) + ubc_setsize(vp, avc->m.Length); } } @@ -156,202 +148,199 @@ osi_VM_FlushPages(avc, credp) * it only works on Solaris. */ void -osi_VM_Truncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { - struct vnode *vp=AFSTOV(avc); - if (UBCINFOEXISTS(vp)) { + struct vnode *vp = AFSTOV(avc); + if (UBCINFOEXISTS(vp)) { ubc_setsize(vp, alen); } } -extern struct AFS_UCRED afs_osi_cred; -extern afs_rwlock_t afs_xvcache; /* vnreclaim and vinactive are probably not aggressive enough to keep enough afs vcaches free, so we try to do some of it ourselves */ /* XXX there's probably not nearly enough locking here */ -void osi_VM_TryReclaim(avc, slept) - struct vcache *avc; - int *slept; +void +osi_VM_TryReclaim(struct vcache *avc, int *slept) { - struct proc *p=current_proc(); - struct vnode *vp=AFSTOV(avc); + struct proc *p = current_proc(); + struct vnode *vp = AFSTOV(avc); void *obj; if (slept) - *slept=0; - VN_HOLD(vp); /* remove from inactive list */ + *slept = 0; + VN_HOLD(vp); /* remove from inactive list */ if (!simple_lock_try(&vp->v_interlock)) { - AFS_RELE(vp); - return; + AFS_RELE(vp); + return; } if (!UBCINFOEXISTS(vp) || vp->v_count != 2) { - simple_unlock(&vp->v_interlock); - AFS_RELE(vp); - return; + simple_unlock(&vp->v_interlock); + AFS_RELE(vp); + return; } #ifdef AFS_DARWIN14_ENV if (vp->v_ubcinfo->ui_refcount > 1 || vp->v_ubcinfo->ui_mapped) { - simple_unlock(&vp->v_interlock); - AFS_RELE(vp); - return; + simple_unlock(&vp->v_interlock); + AFS_RELE(vp); + return; } #else if (vp->v_ubcinfo->ui_holdcnt) { - simple_unlock(&vp->v_interlock); - AFS_RELE(vp); - return; + simple_unlock(&vp->v_interlock); + AFS_RELE(vp); + return; } #endif if (slept && ubc_issetflags(vp, UI_WASMAPPED)) { - /* We can't possibly release this in time for this NewVCache to get it */ - simple_unlock(&vp->v_interlock); - AFS_RELE(vp); - return; + /* We can't possibly release this in time for this NewVCache to get it */ + simple_unlock(&vp->v_interlock); + AFS_RELE(vp); + return; } - vp->v_usecount--; /* we want the usecount to be 1 */ + vp->v_usecount--; /* we want the usecount to be 1 */ if (slept) { - ReleaseWriteLock(&afs_xvcache); - *slept=1; + ReleaseWriteLock(&afs_xvcache); + *slept = 1; } else - ReleaseReadLock(&afs_xvcache); + ReleaseReadLock(&afs_xvcache); AFS_GUNLOCK(); - obj=0; + obj = 0; if (ubc_issetflags(vp, UI_WASMAPPED)) { - simple_unlock(&vp->v_interlock); + simple_unlock(&vp->v_interlock); #ifdef AFS_DARWIN14_ENV - ubc_release_named(vp); + ubc_release_named(vp); #else - ubc_release(vp); + ubc_release(vp); #endif - if (ubc_issetflags(vp, UI_HASOBJREF)) - printf("ubc_release didn't release the reference?!\n"); - } else if (!vn_lock(vp, LK_EXCLUSIVE|LK_INTERLOCK,current_proc())) { + if (ubc_issetflags(vp, UI_HASOBJREF)) + printf("ubc_release didn't release the reference?!\n"); + } else if (!vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK, current_proc())) { #ifdef AFS_DARWIN14_ENV - obj = ubc_getobject(vp,UBC_HOLDOBJECT); + obj = ubc_getobject(vp, UBC_HOLDOBJECT); #else #ifdef AFS_DARWIN13_ENV - obj = ubc_getobject(vp,(UBC_NOREACTIVATE|UBC_HOLDOBJECT)); + obj = ubc_getobject(vp, (UBC_NOREACTIVATE | UBC_HOLDOBJECT)); #else - obj = ubc_getobject(vp); + obj = ubc_getobject(vp); #endif #endif - (void)ubc_clean(vp, 1); - vinvalbuf(vp, V_SAVE, &afs_osi_cred, p, 0, 0); - if (vp->v_usecount == 1) - VOP_INACTIVE(vp, p); - else - VOP_UNLOCK(vp, 0, p); - if (obj) { - if (ISSET(vp->v_flag, VTERMINATE)) - panic("afs_vnreclaim: already teminating"); - SET(vp->v_flag, VTERMINATE); - memory_object_destroy(obj, 0); - while (ISSET(vp->v_flag, VTERMINATE)) { - SET(vp->v_flag, VTERMWANT); - tsleep((caddr_t)&vp->v_ubcinfo, PINOD, "afs_vnreclaim", 0); - } - } - } else { - if (simple_lock_try(&vp->v_interlock)) - panic("afs_vnreclaim: slept, but did no work :("); - if (UBCINFOEXISTS(vp) && vp->v_count == 1) { - vp->v_usecount++; - simple_unlock(&vp->v_interlock); - VN_RELE(vp); - } else - simple_unlock(&vp->v_interlock); - } - AFS_GLOCK(); - if (slept) - ObtainWriteLock(&afs_xvcache,175); - else - ObtainReadLock(&afs_xvcache); + (void)ubc_clean(vp, 1); + vinvalbuf(vp, V_SAVE, &afs_osi_cred, p, 0, 0); + if (vp->v_usecount == 1) + VOP_INACTIVE(vp, p); + else + VOP_UNLOCK(vp, 0, p); + if (obj) { + if (ISSET(vp->v_flag, VTERMINATE)) + panic("afs_vnreclaim: already teminating"); + SET(vp->v_flag, VTERMINATE); + memory_object_destroy(obj, 0); + while (ISSET(vp->v_flag, VTERMINATE)) { + SET(vp->v_flag, VTERMWANT); + tsleep((caddr_t) & vp->v_ubcinfo, PINOD, "afs_vnreclaim", 0); + } + } + } else { + if (simple_lock_try(&vp->v_interlock)) + panic("afs_vnreclaim: slept, but did no work :("); + if (UBCINFOEXISTS(vp) && vp->v_count == 1) { + vp->v_usecount++; + simple_unlock(&vp->v_interlock); + VN_RELE(vp); + } else + simple_unlock(&vp->v_interlock); + } + AFS_GLOCK(); + if (slept) + ObtainWriteLock(&afs_xvcache, 175); + else + ObtainReadLock(&afs_xvcache); } -void osi_VM_NukePages(struct vnode *vp, off_t offset, off_t size) { - +void +osi_VM_NukePages(struct vnode *vp, off_t offset, off_t size) +{ void *object; struct vcache *avc = VTOAFS(vp); #ifdef AFS_DARWIN14_ENV - offset=trunc_page(offset); - size=round_page(size+1); + offset = trunc_page(offset); + size = round_page(size + 1); while (size) { - ubc_page_op(vp, (vm_offset_t)offset, - UPL_POP_SET | UPL_POP_BUSY | UPL_POP_DUMP, - 0, 0); - size-=PAGE_SIZE; - offset+=PAGE_SIZE; + ubc_page_op(vp, (vm_offset_t) offset, + UPL_POP_SET | UPL_POP_BUSY | UPL_POP_DUMP, 0, 0); + size -= PAGE_SIZE; + offset += PAGE_SIZE; } #else - object=NULL; + object = NULL; #ifdef AFS_DARWIN13_ENV if (UBCINFOEXISTS(vp)) - object = ubc_getobject(vp, UBC_NOREACTIVATE); + object = ubc_getobject(vp, UBC_NOREACTIVATE); #else if (UBCINFOEXISTS(vp)) - object = ubc_getobject(vp); + object = ubc_getobject(vp); #endif if (!object) - return; + return; - offset=trunc_page(offset); - size=round_page(size+1); + offset = trunc_page(offset); + size = round_page(size + 1); #ifdef AFS_DARWIN13_ENV while (size) { - memory_object_page_op(object, (vm_offset_t)offset, - UPL_POP_SET | UPL_POP_BUSY | UPL_POP_DUMP, - 0, 0); - size-=PAGE_SIZE; - offset+=PAGE_SIZE; + memory_object_page_op(object, (vm_offset_t) offset, + UPL_POP_SET | UPL_POP_BUSY | UPL_POP_DUMP, 0, + 0); + size -= PAGE_SIZE; + offset += PAGE_SIZE; } -#else +#else /* This is all we can do, and it's not enough. sucks to be us */ ubc_setsize(vp, offset); - size=(offset + size > avc->m.Length) ? offset + size : avc->m.Length; + size = (offset + size > avc->m.Length) ? offset + size : avc->m.Length; ubc_setsize(vp, size); #endif #endif - } -int osi_VM_Setup(struct vcache *avc, int force) { - int error; - struct vnode *vp=AFSTOV(avc); - if (UBCISVALID(vp) && ((avc->states & CStatd) || force)) { - if (!UBCINFOEXISTS(vp) && !ISSET(vp->v_flag, VTERMINATE)) { - osi_vnhold(avc,0); - avc->states |= CUBCinit; - AFS_GUNLOCK(); - if ((error=ubc_info_init(&avc->v))) { - AFS_GLOCK(); - avc->states &= ~CUBCinit; - AFS_RELE(avc); - return error; - } +int +osi_VM_Setup(struct vcache *avc, int force) +{ + int error; + struct vnode *vp = AFSTOV(avc); + + if (UBCISVALID(vp) && ((avc->states & CStatd) || force)) { + if (!UBCINFOEXISTS(vp) && !ISSET(vp->v_flag, VTERMINATE)) { + osi_vnhold(avc, 0); + avc->states |= CUBCinit; + AFS_GUNLOCK(); + if ((error = ubc_info_init(&avc->v))) { + AFS_GLOCK(); + avc->states &= ~CUBCinit; + AFS_RELE(avc); + return error; + } #ifndef AFS_DARWIN14_ENV - simple_lock(&avc->v.v_interlock); - if (!ubc_issetflags(&avc->v, UI_HASOBJREF)) + simple_lock(&avc->v.v_interlock); + if (!ubc_issetflags(&avc->v, UI_HASOBJREF)) #ifdef AFS_DARWIN13_ENV - if (ubc_getobject(&avc->v, (UBC_NOREACTIVATE|UBC_HOLDOBJECT))) - panic("VM_Setup: null object"); + if (ubc_getobject + (&avc->v, (UBC_NOREACTIVATE | UBC_HOLDOBJECT))) + panic("VM_Setup: null object"); #else - (void)_ubc_getobject(&avc->v, 1); /* return value not used */ + (void)_ubc_getobject(&avc->v, 1); /* return value not used */ #endif - simple_unlock(&avc->v.v_interlock); + simple_unlock(&avc->v.v_interlock); #endif - AFS_GLOCK(); - avc->states &= ~CUBCinit; - AFS_RELE(avc); - } - if (UBCINFOEXISTS(&avc->v)) - ubc_setsize(&avc->v, avc->m.Length); - } - return 0; + AFS_GLOCK(); + avc->states &= ~CUBCinit; + AFS_RELE(avc); + } + if (UBCINFOEXISTS(&avc->v)) + ubc_setsize(&avc->v, avc->m.Length); + } + return 0; } diff --git a/src/afs/DARWIN/osi_vnodeops.c b/src/afs/DARWIN/osi_vnodeops.c index 18cca9b80..b914bbc5f 100644 --- a/src/afs/DARWIN/osi_vnodeops.c +++ b/src/afs/DARWIN/osi_vnodeops.c @@ -4,11 +4,12 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DARWIN/osi_vnodeops.c,v 1.1.1.10 2004/01/10 20:52:51 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DARWIN/osi_vnodeops.c,v 1.16 2004/04/05 06:21:33 shadow Exp $"); -#include /* Standard vendor system headers */ -#include /* Afs-based standard headers */ -#include /* statistics */ +#include /* Standard vendor system headers */ +#include /* Afs-based standard headers */ +#include /* statistics */ #include #include #include @@ -69,65 +70,65 @@ int afs_vop_cmap __P((struct vop_cmap_args *)); #define afs_vop_reallocblks afs_vop_opnotsupp /* Global vfs data structures for AFS. */ -int (**afs_vnodeop_p)(); +int (**afs_vnodeop_p) (); struct vnodeopv_entry_desc afs_vnodeop_entries[] = { - { &vop_default_desc, vn_default_error }, - { &vop_lookup_desc, afs_vop_lookup }, /* lookup */ - { &vop_create_desc, afs_vop_create }, /* create */ - { &vop_mknod_desc, afs_vop_mknod }, /* mknod */ - { &vop_open_desc, afs_vop_open }, /* open */ - { &vop_close_desc, afs_vop_close }, /* close */ - { &vop_access_desc, afs_vop_access }, /* access */ - { &vop_getattr_desc, afs_vop_getattr }, /* getattr */ - { &vop_setattr_desc, afs_vop_setattr }, /* setattr */ - { &vop_read_desc, afs_vop_read }, /* read */ - { &vop_write_desc, afs_vop_write }, /* write */ - { &vop_pagein_desc, afs_vop_pagein }, /* read */ - { &vop_pageout_desc, afs_vop_pageout }, /* write */ - { &vop_ioctl_desc, afs_vop_ioctl }, /* XXX ioctl */ - { &vop_select_desc, afs_vop_select }, /* select */ - { &vop_mmap_desc, afs_vop_mmap }, /* mmap */ - { &vop_fsync_desc, afs_vop_fsync }, /* fsync */ - { &vop_seek_desc, afs_vop_seek }, /* seek */ - { &vop_remove_desc, afs_vop_remove }, /* remove */ - { &vop_link_desc, afs_vop_link }, /* link */ - { &vop_rename_desc, afs_vop_rename }, /* rename */ - { &vop_mkdir_desc, afs_vop_mkdir }, /* mkdir */ - { &vop_rmdir_desc, afs_vop_rmdir }, /* rmdir */ - { &vop_symlink_desc, afs_vop_symlink }, /* symlink */ - { &vop_readdir_desc, afs_vop_readdir }, /* readdir */ - { &vop_readlink_desc, afs_vop_readlink }, /* readlink */ + {&vop_default_desc, vn_default_error}, + {&vop_lookup_desc, afs_vop_lookup}, /* lookup */ + {&vop_create_desc, afs_vop_create}, /* create */ + {&vop_mknod_desc, afs_vop_mknod}, /* mknod */ + {&vop_open_desc, afs_vop_open}, /* open */ + {&vop_close_desc, afs_vop_close}, /* close */ + {&vop_access_desc, afs_vop_access}, /* access */ + {&vop_getattr_desc, afs_vop_getattr}, /* getattr */ + {&vop_setattr_desc, afs_vop_setattr}, /* setattr */ + {&vop_read_desc, afs_vop_read}, /* read */ + {&vop_write_desc, afs_vop_write}, /* write */ + {&vop_pagein_desc, afs_vop_pagein}, /* read */ + {&vop_pageout_desc, afs_vop_pageout}, /* write */ + {&vop_ioctl_desc, afs_vop_ioctl}, /* XXX ioctl */ + {&vop_select_desc, afs_vop_select}, /* select */ + {&vop_mmap_desc, afs_vop_mmap}, /* mmap */ + {&vop_fsync_desc, afs_vop_fsync}, /* fsync */ + {&vop_seek_desc, afs_vop_seek}, /* seek */ + {&vop_remove_desc, afs_vop_remove}, /* remove */ + {&vop_link_desc, afs_vop_link}, /* link */ + {&vop_rename_desc, afs_vop_rename}, /* rename */ + {&vop_mkdir_desc, afs_vop_mkdir}, /* mkdir */ + {&vop_rmdir_desc, afs_vop_rmdir}, /* rmdir */ + {&vop_symlink_desc, afs_vop_symlink}, /* symlink */ + {&vop_readdir_desc, afs_vop_readdir}, /* readdir */ + {&vop_readlink_desc, afs_vop_readlink}, /* readlink */ #if defined(AFS_DARWIN70_ENV) - { &vop_abortop_desc, nop_abortop }, /* abortop */ + { &vop_abortop_desc, nop_abortop }, /* abortop */ #else /* ! defined(AFS_DARWIN70_ENV) */ - /* Yes, we use the ufs_abortop call. It just releases the namei - buffer stuff */ - { &vop_abortop_desc, ufs_abortop }, /* abortop */ + /* Yes, we use the ufs_abortop call. It just releases the namei + * buffer stuff */ + {&vop_abortop_desc, ufs_abortop}, /* abortop */ #endif /* defined(AFS_DARWIN70_ENV) */ - { &vop_inactive_desc, afs_vop_inactive }, /* inactive */ - { &vop_reclaim_desc, afs_vop_reclaim }, /* reclaim */ - { &vop_lock_desc, afs_vop_lock }, /* lock */ - { &vop_unlock_desc, afs_vop_unlock }, /* unlock */ - { &vop_bmap_desc, afs_vop_bmap }, /* bmap */ - { &vop_strategy_desc, afs_vop_strategy }, /* strategy */ - { &vop_print_desc, afs_vop_print }, /* print */ - { &vop_islocked_desc, afs_vop_islocked }, /* islocked */ - { &vop_pathconf_desc, afs_vop_pathconf }, /* pathconf */ - { &vop_advlock_desc, afs_vop_advlock }, /* advlock */ - { &vop_blkatoff_desc, afs_vop_blkatoff }, /* blkatoff */ - { &vop_valloc_desc, afs_vop_valloc }, /* valloc */ - { &vop_reallocblks_desc, afs_vop_reallocblks }, /* reallocblks */ - { &vop_vfree_desc, afs_vop_vfree }, /* vfree */ - { &vop_truncate_desc, afs_vop_truncate }, /* truncate */ - { &vop_update_desc, afs_vop_update }, /* update */ - { &vop_blktooff_desc, afs_vop_blktooff }, /* blktooff */ - { &vop_offtoblk_desc, afs_vop_offtoblk }, /* offtoblk */ - { &vop_cmap_desc, afs_vop_cmap }, /* cmap */ - { &vop_bwrite_desc, vn_bwrite }, - { (struct vnodeop_desc*)NULL, (int(*)())NULL } + {&vop_inactive_desc, afs_vop_inactive}, /* inactive */ + {&vop_reclaim_desc, afs_vop_reclaim}, /* reclaim */ + {&vop_lock_desc, afs_vop_lock}, /* lock */ + {&vop_unlock_desc, afs_vop_unlock}, /* unlock */ + {&vop_bmap_desc, afs_vop_bmap}, /* bmap */ + {&vop_strategy_desc, afs_vop_strategy}, /* strategy */ + {&vop_print_desc, afs_vop_print}, /* print */ + {&vop_islocked_desc, afs_vop_islocked}, /* islocked */ + {&vop_pathconf_desc, afs_vop_pathconf}, /* pathconf */ + {&vop_advlock_desc, afs_vop_advlock}, /* advlock */ + {&vop_blkatoff_desc, afs_vop_blkatoff}, /* blkatoff */ + {&vop_valloc_desc, afs_vop_valloc}, /* valloc */ + {&vop_reallocblks_desc, afs_vop_reallocblks}, /* reallocblks */ + {&vop_vfree_desc, afs_vop_vfree}, /* vfree */ + {&vop_truncate_desc, afs_vop_truncate}, /* truncate */ + {&vop_update_desc, afs_vop_update}, /* update */ + {&vop_blktooff_desc, afs_vop_blktooff}, /* blktooff */ + {&vop_offtoblk_desc, afs_vop_offtoblk}, /* offtoblk */ + {&vop_cmap_desc, afs_vop_cmap}, /* cmap */ + {&vop_bwrite_desc, vn_bwrite}, + {(struct vnodeop_desc *)NULL, (int (*)())NULL} }; struct vnodeopv_desc afs_vnodeop_opv_desc = - { &afs_vnodeop_p, afs_vnodeop_entries }; + { &afs_vnodeop_p, afs_vnodeop_entries }; #define GETNAME() \ struct componentname *cnp = ap->a_cnp; \ @@ -137,29 +138,29 @@ struct vnodeopv_desc afs_vnodeop_opv_desc = name[cnp->cn_namelen] = '\0' #define DROPNAME() FREE(name, M_TEMP) - + int afs_vop_lookup(ap) -struct vop_lookup_args /* { - struct vnodeop_desc * a_desc; - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - } */ *ap; + struct vop_lookup_args /* { + * struct vnodeop_desc * a_desc; + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * } */ *ap; { int error; struct vcache *vcp; struct vnode *vp, *dvp; register int flags = ap->a_cnp->cn_flags; - int lockparent; /* 1 => lockparent flag is set */ - int wantparent; /* 1 => wantparent or lockparent flag */ + int lockparent; /* 1 => lockparent flag is set */ + int wantparent; /* 1 => wantparent or lockparent flag */ struct proc *p; GETNAME(); - p=cnp->cn_proc; + p = cnp->cn_proc; lockparent = flags & LOCKPARENT; - wantparent = flags & (LOCKPARENT|WANTPARENT); + wantparent = flags & (LOCKPARENT | WANTPARENT); if (ap->a_dvp->v_type != VDIR) { *ap->a_vpp = 0; @@ -167,16 +168,16 @@ struct vop_lookup_args /* { return ENOTDIR; } dvp = ap->a_dvp; - if (flags & ISDOTDOT) - VOP_UNLOCK(dvp, 0, p); + if (flags & ISDOTDOT) + VOP_UNLOCK(dvp, 0, p); AFS_GLOCK(); error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred); AFS_GUNLOCK(); if (error) { - if (flags & ISDOTDOT) - VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p); - if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) && - (flags & ISLASTCN) && error == ENOENT) + if (flags & ISDOTDOT) + VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p); + if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) + && (flags & ISLASTCN) && error == ENOENT) error = EJUSTRETURN; if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)) cnp->cn_flags |= SAVENAME; @@ -184,35 +185,35 @@ struct vop_lookup_args /* { *ap->a_vpp = 0; return (error); } - vp = AFSTOV(vcp); /* always get a node if no error */ + vp = AFSTOV(vcp); /* always get a node if no error */ vp->v_vfsp = dvp->v_vfsp; /* The parent directory comes in locked. We unlock it on return - unless the caller wants it left locked. - we also always return the vnode locked. */ + * unless the caller wants it left locked. + * we also always return the vnode locked. */ if (flags & ISDOTDOT) { vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); - /* always return the child locked */ - if (lockparent && (flags & ISLASTCN) && - (error = vn_lock(dvp, LK_EXCLUSIVE, p))) { - vput(vp); - DROPNAME(); - return (error); - } + /* always return the child locked */ + if (lockparent && (flags & ISLASTCN) + && (error = vn_lock(dvp, LK_EXCLUSIVE, p))) { + vput(vp); + DROPNAME(); + return (error); + } } else if (vp == dvp) { /* they're the same; afs_lookup() already ref'ed the leaf. - It came in locked, so we don't need to ref OR lock it */ + * It came in locked, so we don't need to ref OR lock it */ } else { if (!lockparent || !(flags & ISLASTCN)) - VOP_UNLOCK(dvp, 0, p); /* done with parent. */ + VOP_UNLOCK(dvp, 0, p); /* done with parent. */ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); - /* always return the child locked */ + /* always return the child locked */ } *ap->a_vpp = vp; - if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN) || - (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))) + if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN) + || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))) cnp->cn_flags |= SAVENAME; DROPNAME(); @@ -221,42 +222,41 @@ struct vop_lookup_args /* { int afs_vop_create(ap) - struct vop_create_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - struct vattr *a_vap; - } */ *ap; + struct vop_create_args /* { + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * struct vattr *a_vap; + * } */ *ap; { int error = 0; struct vcache *vcp; register struct vnode *dvp = ap->a_dvp; struct proc *p; GETNAME(); - p=cnp->cn_proc; + p = cnp->cn_proc; /* vnode layer handles excl/nonexcl */ AFS_GLOCK(); - error = afs_create(VTOAFS(dvp), name, ap->a_vap, NONEXCL, - ap->a_vap->va_mode, &vcp, - cnp->cn_cred); + error = + afs_create(VTOAFS(dvp), name, ap->a_vap, NONEXCL, ap->a_vap->va_mode, + &vcp, cnp->cn_cred); AFS_GUNLOCK(); if (error) { VOP_ABORTOP(dvp, cnp); vput(dvp); DROPNAME(); - return(error); + return (error); } if (vcp) { *ap->a_vpp = AFSTOV(vcp); (*ap->a_vpp)->v_vfsp = dvp->v_vfsp; - vn_lock(*ap->a_vpp, LK_EXCLUSIVE| LK_RETRY, p); - if (UBCINFOMISSING(*ap->a_vpp) || - UBCINFORECLAIMED(*ap->a_vpp)) - ubc_info_init(*ap->a_vpp); - } - else *ap->a_vpp = 0; + vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY, p); + if (UBCINFOMISSING(*ap->a_vpp) || UBCINFORECLAIMED(*ap->a_vpp)) + ubc_info_init(*ap->a_vpp); + } else + *ap->a_vpp = 0; if ((cnp->cn_flags & SAVESTART) == 0) FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI); @@ -267,26 +267,26 @@ afs_vop_create(ap) int afs_vop_mknod(ap) - struct vop_mknod_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - struct vattr *a_vap; - } */ *ap; + struct vop_mknod_args /* { + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * struct vattr *a_vap; + * } */ *ap; { FREE_ZONE(ap->a_cnp->cn_pnbuf, ap->a_cnp->cn_pnlen, M_NAMEI); vput(ap->a_dvp); - return(ENODEV); + return (ENODEV); } int afs_vop_open(ap) - struct vop_open_args /* { - struct vnode *a_vp; - int a_mode; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_open_args /* { + * struct vnode *a_vp; + * int a_mode; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int error; struct vnode *vp = ap->a_vp; @@ -325,32 +325,32 @@ afs_vop_open(ap) int afs_vop_close(ap) - struct vop_close_args /* { - struct vnode *a_vp; - int a_fflag; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_close_args /* { + * struct vnode *a_vp; + * int a_fflag; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int code; - struct vcache *avc=ap->a_vp; + struct vcache *avc = ap->a_vp; AFS_GLOCK(); - if (ap->a_cred) - code=afs_close(avc, ap->a_fflag, ap->a_cred, ap->a_p); + if (ap->a_cred) + code = afs_close(avc, ap->a_fflag, ap->a_cred, ap->a_p); else - code=afs_close(avc, ap->a_fflag, &afs_osi_cred, ap->a_p); + code = afs_close(avc, ap->a_fflag, &afs_osi_cred, ap->a_p); afs_BozonLock(&avc->pvnLock, avc); - osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ + osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ afs_BozonUnlock(&avc->pvnLock, avc); AFS_GUNLOCK(); #ifdef AFS_DARWIN14_ENV if (UBCINFOEXISTS(ap->a_vp) && ap->a_vp->v_ubcinfo->ui_refcount < 2) { - ubc_hold(ap->a_vp); - if (ap->a_vp->v_ubcinfo->ui_refcount < 2) { - printf("afs: Imminent ui_refcount panic\n"); - } else { - printf("afs: WARNING: ui_refcount panic averted\n"); - } + ubc_hold(ap->a_vp); + if (ap->a_vp->v_ubcinfo->ui_refcount < 2) { + printf("afs: Imminent ui_refcount panic\n"); + } else { + printf("afs: WARNING: ui_refcount panic averted\n"); + } } #endif @@ -359,126 +359,130 @@ afs_vop_close(ap) int afs_vop_access(ap) - struct vop_access_args /* { - struct vnode *a_vp; - int a_mode; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_access_args /* { + * struct vnode *a_vp; + * int a_mode; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int code; AFS_GLOCK(); - code=afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred); + code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred); AFS_GUNLOCK(); return code; } + int afs_vop_getattr(ap) - struct vop_getattr_args /* { - struct vnode *a_vp; - struct vattr *a_vap; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_getattr_args /* { + * struct vnode *a_vp; + * struct vattr *a_vap; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int code; AFS_GLOCK(); - code=afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); + code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); AFS_GUNLOCK(); return code; } + int afs_vop_setattr(ap) - struct vop_setattr_args /* { - struct vnode *a_vp; - struct vattr *a_vap; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_setattr_args /* { + * struct vnode *a_vp; + * struct vattr *a_vap; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int code; AFS_GLOCK(); - code=afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); + code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); AFS_GUNLOCK(); return code; } + int afs_vop_read(ap) - struct vop_read_args /* { - struct vnode *a_vp; - struct uio *a_uio; - int a_ioflag; - struct ucred *a_cred; - } */ *ap; + struct vop_read_args /* { + * struct vnode *a_vp; + * struct uio *a_uio; + * int a_ioflag; + * struct ucred *a_cred; + * } */ *ap; { int code; - struct vcache *avc=VTOAFS(ap->a_vp); + struct vcache *avc = VTOAFS(ap->a_vp); AFS_GLOCK(); afs_BozonLock(&avc->pvnLock, avc); - osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ - code=afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0); + osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ + code = afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0); afs_BozonUnlock(&avc->pvnLock, avc); AFS_GUNLOCK(); return code; } + int afs_vop_pagein(ap) - struct vop_pagein_args /* { - struct vnode *a_vp; - upl_t a_pl; - vm_offset_t a_pl_offset; - off_t a_f_offset; - size_t a_size; - struct ucred *a_cred; - int a_flags; - } */ *ap; + struct vop_pagein_args /* { + * struct vnode *a_vp; + * upl_t a_pl; + * vm_offset_t a_pl_offset; + * off_t a_f_offset; + * size_t a_size; + * struct ucred *a_cred; + * int a_flags; + * } */ *ap; { register struct vnode *vp = ap->a_vp; upl_t pl = ap->a_pl; - size_t size= ap->a_size; + size_t size = ap->a_size; off_t f_offset = ap->a_f_offset; vm_offset_t pl_offset = ap->a_pl_offset; - int flags = ap->a_flags; + int flags = ap->a_flags; struct ucred *cred; vm_offset_t ioaddr; - struct uio auio; - struct iovec aiov; - struct uio * uio = &auio; + struct uio auio; + struct iovec aiov; + struct uio *uio = &auio; int nocommit = flags & UPL_NOCOMMIT; int code; - struct vcache *tvc=VTOAFS(vp); + struct vcache *tvc = VTOAFS(vp); if (UBCINVALID(vp)) { #if DIAGNOSTIC - panic("afs_vop_pagein: invalid vp"); + panic("afs_vop_pagein: invalid vp"); #endif /* DIAGNOSTIC */ - return (EPERM); + return (EPERM); } UBCINFOCHECK("afs_vop_pagein", vp); - if(pl == (upl_t)NULL) { - panic("afs_vop_pagein: no upl"); + if (pl == (upl_t) NULL) { + panic("afs_vop_pagein: no upl"); } cred = ubc_getcred(vp); if (cred == NOCRED) - cred = ap->a_cred; + cred = ap->a_cred; if (size == 0) { - if (!nocommit) - kernel_upl_abort_range(pl, pl_offset, size, - UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY); - return (0); + if (!nocommit) + kernel_upl_abort_range(pl, pl_offset, size, + UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY); + return (0); } if (f_offset < 0) { - if (!nocommit) - kernel_upl_abort_range(pl, pl_offset, size, - UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY); - return (EINVAL); + if (!nocommit) + kernel_upl_abort_range(pl, pl_offset, size, + UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY); + return (EINVAL); } if (f_offset & PAGE_MASK) - panic("afs_vop_pagein: offset not page aligned"); + panic("afs_vop_pagein: offset not page aligned"); auio.uio_iov = &aiov; auio.uio_iovcnt = 1; @@ -489,15 +493,15 @@ afs_vop_pagein(ap) kernel_upl_map(kernel_map, pl, &ioaddr); ioaddr += pl_offset; auio.uio_resid = aiov.iov_len = size; - aiov.iov_base = (caddr_t)ioaddr; + aiov.iov_base = (caddr_t) ioaddr; AFS_GLOCK(); afs_BozonLock(&tvc->pvnLock, tvc); - osi_FlushPages(tvc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ - code=afs_read(tvc, uio, cred, 0, 0, 0); + osi_FlushPages(tvc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ + code = afs_read(tvc, uio, cred, 0, 0, 0); if (code == 0) { - ObtainWriteLock(&tvc->lock, 2); - tvc->states |= CMAPPED; - ReleaseWriteLock(&tvc->lock); + ObtainWriteLock(&tvc->lock, 2); + tvc->states |= CMAPPED; + ReleaseWriteLock(&tvc->lock); } afs_BozonUnlock(&tvc->pvnLock, tvc); AFS_GUNLOCK(); @@ -508,37 +512,41 @@ afs_vop_pagein(ap) kernel_upl_unmap(kernel_map, pl); if (!nocommit) { - if (code) - kernel_upl_abort_range(pl, pl_offset, size, - UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY); - else - kernel_upl_commit_range(pl, pl_offset, size, - UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_FREE_ON_EMPTY, - UPL_GET_INTERNAL_PAGE_LIST(pl), MAX_UPL_TRANSFER); + if (code) + kernel_upl_abort_range(pl, pl_offset, size, + UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY); + else + kernel_upl_commit_range(pl, pl_offset, size, + UPL_COMMIT_CLEAR_DIRTY | + UPL_COMMIT_FREE_ON_EMPTY, + UPL_GET_INTERNAL_PAGE_LIST(pl), + MAX_UPL_TRANSFER); } return code; } int afs_vop_write(ap) - struct vop_write_args /* { - struct vnode *a_vp; - struct uio *a_uio; - int a_ioflag; - struct ucred *a_cred; - } */ *ap; + struct vop_write_args /* { + * struct vnode *a_vp; + * struct uio *a_uio; + * int a_ioflag; + * struct ucred *a_cred; + * } */ *ap; { int code; - struct vcache *avc=VTOAFS(ap->a_vp); + struct vcache *avc = VTOAFS(ap->a_vp); void *object; AFS_GLOCK(); afs_BozonLock(&avc->pvnLock, avc); - osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ + osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ if (UBCINFOEXISTS(ap->a_vp)) - ubc_clean(ap->a_vp, 1); + ubc_clean(ap->a_vp, 1); if (UBCINFOEXISTS(ap->a_vp)) - osi_VM_NukePages(ap->a_vp, ap->a_uio->uio_offset, ap->a_uio->uio_resid); - code=afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0); + osi_VM_NukePages(ap->a_vp, ap->a_uio->uio_offset, + ap->a_uio->uio_resid); + code = + afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0); afs_BozonUnlock(&avc->pvnLock, avc); AFS_GUNLOCK(); return code; @@ -546,94 +554,108 @@ afs_vop_write(ap) int afs_vop_pageout(ap) - struct vop_pageout_args /* { - struct vnode *a_vp; - upl_t a_pl, - vm_offset_t a_pl_offset, - off_t a_f_offset, - size_t a_size, - struct ucred *a_cred, - int a_flags - } */ *ap; + struct vop_pageout_args /* { + * struct vnode *a_vp; + * upl_t a_pl, + * vm_offset_t a_pl_offset, + * off_t a_f_offset, + * size_t a_size, + * struct ucred *a_cred, + * int a_flags + * } */ *ap; { register struct vnode *vp = ap->a_vp; upl_t pl = ap->a_pl; - size_t size= ap->a_size; + size_t size = ap->a_size; off_t f_offset = ap->a_f_offset; vm_offset_t pl_offset = ap->a_pl_offset; - int flags = ap->a_flags; + int flags = ap->a_flags; struct ucred *cred; vm_offset_t ioaddr; - struct uio auio; - struct iovec aiov; - struct uio * uio = &auio; + struct uio auio; + struct iovec aiov; + struct uio *uio = &auio; int nocommit = flags & UPL_NOCOMMIT; + int iosize; int code; - struct vcache *tvc=VTOAFS(vp); + struct vcache *tvc = VTOAFS(vp); if (UBCINVALID(vp)) { #if DIAGNOSTIC - panic("afs_vop_pageout: invalid vp"); + panic("afs_vop_pageout: invalid vp"); #endif /* DIAGNOSTIC */ - return (EPERM); + return (EPERM); } UBCINFOCHECK("afs_vop_pageout", vp); - if(pl == (upl_t)NULL) { - panic("afs_vop_pageout: no upl"); + if (pl == (upl_t) NULL) { + panic("afs_vop_pageout: no upl"); } #if 1 - { int lbn, iosize, s; - struct buf *bp; - int biosize = DEV_BSIZE; - - lbn = f_offset / DEV_BSIZE; - - for (iosize = size; iosize > 0; iosize -= biosize, lbn++) { - - s = splbio(); - if (bp = incore(vp, lbn)) { - if (ISSET(bp->b_flags, B_BUSY)) - panic("nfs_pageout: found BUSY buffer incore\n") -; - - bremfree(bp); - SET(bp->b_flags, (B_BUSY | B_INVAL)); - brelse(bp); - } - splx(s); - } + { + int lbn, s; + struct buf *bp; + int biosize = DEV_BSIZE; + + lbn = f_offset / DEV_BSIZE; + + for (iosize = size; iosize > 0; iosize -= biosize, lbn++) { + + s = splbio(); + if (bp = incore(vp, lbn)) { + if (ISSET(bp->b_flags, B_BUSY)) + panic("nfs_pageout: found BUSY buffer incore\n"); + + bremfree(bp); + SET(bp->b_flags, (B_BUSY | B_INVAL)); + brelse(bp); + } + splx(s); + } } #endif cred = ubc_getcred(vp); if (cred == NOCRED) - cred = ap->a_cred; + cred = ap->a_cred; if (size == 0) { - if (!nocommit) - kernel_upl_abort_range(pl, pl_offset, size, - UPL_ABORT_FREE_ON_EMPTY); - return (0); + if (!nocommit) + kernel_upl_abort_range(pl, pl_offset, size, + UPL_ABORT_FREE_ON_EMPTY); + return (0); } if (flags & (IO_APPEND | IO_SYNC)) - panic("nfs_pageout: (IO_APPEND | IO_SYNC)"); + panic("nfs_pageout: (IO_APPEND | IO_SYNC)"); if (f_offset < 0) { - if (!nocommit) - kernel_upl_abort_range(pl, pl_offset, size, - UPL_ABORT_FREE_ON_EMPTY); - return (EINVAL); + if (!nocommit) + kernel_upl_abort_range(pl, pl_offset, size, + UPL_ABORT_FREE_ON_EMPTY); + return (EINVAL); } if (f_offset >= tvc->m.Length) { - if (!nocommit) - kernel_upl_abort_range(pl, pl_offset, size, - UPL_ABORT_FREE_ON_EMPTY); - return (EINVAL); + if (!nocommit) + kernel_upl_abort_range(pl, pl_offset, size, + UPL_ABORT_FREE_ON_EMPTY); + return (EINVAL); } if (f_offset & PAGE_MASK) - panic("afs_vop_pageout: offset not page aligned"); + panic("afs_vop_pageout: offset not page aligned"); + + /* size will always be a multiple of PAGE_SIZE */ + /* pageout isn't supposed to extend files */ + if (f_offset + size > tvc->m.Length) + iosize = tvc->m.Length - f_offset; + else + iosize = size; + if (size > (iosize + (PAGE_SIZE - 1)) & ~PAGE_MASK && !nocommit) { + int iosize_rnd=(iosize + (PAGE_SIZE - 1)) & ~PAGE_MASK; + kernel_upl_abort_range(pl, pl_offset + iosize_rnd, + size - iosize_rnd, + UPL_ABORT_FREE_ON_EMPTY); + } auio.uio_iov = &aiov; auio.uio_iovcnt = 1; auio.uio_offset = f_offset; @@ -642,31 +664,31 @@ afs_vop_pageout(ap) auio.uio_procp = NULL; kernel_upl_map(kernel_map, pl, &ioaddr); ioaddr += pl_offset; - auio.uio_resid = aiov.iov_len = size; - aiov.iov_base = (caddr_t)ioaddr; -#if 1 /* USV [ */ - { - /* - * check for partial page and clear the - * contents past end of the file before - * releasing it in the VM page cache - */ - if ((f_offset < tvc->m.Length) && (f_offset + size) > tvc->m.Length) { - size_t io = tvc->m.Length - f_offset; - - memset((caddr_t)(ioaddr + pl_offset + io), 0, size - io); - } - } + auio.uio_resid = aiov.iov_len = iosize; + aiov.iov_base = (caddr_t) ioaddr; +#if 1 /* USV [ */ + { + /* + * check for partial page and clear the + * contents past end of the file before + * releasing it in the VM page cache + */ + if ((f_offset < tvc->m.Length) && (f_offset + size) > tvc->m.Length) { + size_t io = tvc->m.Length - f_offset; + + memset((caddr_t) (ioaddr + pl_offset + io), 0, size - io); + } + } #endif /* ] USV */ AFS_GLOCK(); afs_BozonLock(&tvc->pvnLock, tvc); - osi_FlushPages(tvc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ + osi_FlushPages(tvc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ ObtainWriteLock(&tvc->lock, 1); afs_FakeOpen(tvc); ReleaseWriteLock(&tvc->lock); - code=afs_write(tvc, uio, flags, cred, 0); + code = afs_write(tvc, uio, flags, cred, 0); ObtainWriteLock(&tvc->lock, 1); afs_FakeClose(tvc, cred); @@ -675,64 +697,68 @@ afs_vop_pageout(ap) AFS_GUNLOCK(); kernel_upl_unmap(kernel_map, pl); if (!nocommit) { - if(code) - kernel_upl_abort_range(pl, pl_offset, size, - UPL_ABORT_FREE_ON_EMPTY); - else - kernel_upl_commit_range(pl, pl_offset, size, - UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_FREE_ON_EMPTY, - UPL_GET_INTERNAL_PAGE_LIST(pl), MAX_UPL_TRANSFER); + if (code) + kernel_upl_abort_range(pl, pl_offset, size, + UPL_ABORT_FREE_ON_EMPTY); + else + kernel_upl_commit_range(pl, pl_offset, size, + UPL_COMMIT_CLEAR_DIRTY | + UPL_COMMIT_FREE_ON_EMPTY, + UPL_GET_INTERNAL_PAGE_LIST(pl), + MAX_UPL_TRANSFER); } return code; } + int afs_vop_ioctl(ap) - struct vop_ioctl_args /* { - struct vnode *a_vp; - int a_command; - caddr_t a_data; - int a_fflag; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_ioctl_args /* { + * struct vnode *a_vp; + * int a_command; + * caddr_t a_data; + * int a_fflag; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { struct vcache *tvc = VTOAFS(ap->a_vp); struct afs_ioctl data; int error = 0; - + /* in case we ever get in here... */ AFS_STATCNT(afs_ioctl); if (((ap->a_command >> 8) & 0xff) == 'V') { /* This is a VICEIOCTL call */ - AFS_GLOCK(); - error = HandleIoctl(tvc, (struct file *)0/*Not used*/, - ap->a_command, ap->a_data); - AFS_GUNLOCK(); - return(error); + AFS_GLOCK(); + error = HandleIoctl(tvc, (struct file *)0 /*Not used */ , + ap->a_command, ap->a_data); + AFS_GUNLOCK(); + return (error); } else { /* No-op call; just return. */ - return(ENOTTY); + return (ENOTTY); } } /* ARGSUSED */ int afs_vop_select(ap) - struct vop_select_args /* { - struct vnode *a_vp; - int a_which; - int a_fflags; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_select_args /* { + * struct vnode *a_vp; + * int a_which; + * int a_fflags; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { - /* - * We should really check to see if I/O is possible. - */ - return (1); + /* + * We should really check to see if I/O is possible. + */ + return (1); } + /* * Mmap a file * @@ -741,60 +767,60 @@ afs_vop_select(ap) /* ARGSUSED */ int afs_vop_mmap(ap) - struct vop_mmap_args /* { - struct vnode *a_vp; - int a_fflags; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_mmap_args /* { + * struct vnode *a_vp; + * int a_fflags; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { - return (EINVAL); + return (EINVAL); } int afs_vop_fsync(ap) - struct vop_fsync_args /* { - struct vnode *a_vp; - struct ucred *a_cred; - int a_waitfor; - struct proc *a_p; - } */ *ap; + struct vop_fsync_args /* { + * struct vnode *a_vp; + * struct ucred *a_cred; + * int a_waitfor; + * struct proc *a_p; + * } */ *ap; { int wait = ap->a_waitfor == MNT_WAIT; int error; register struct vnode *vp = ap->a_vp; AFS_GLOCK(); - /*vflushbuf(vp, wait);*/ + /*vflushbuf(vp, wait); */ if (ap->a_cred) - error=afs_fsync(VTOAFS(vp), ap->a_cred); + error = afs_fsync(VTOAFS(vp), ap->a_cred); else - error=afs_fsync(VTOAFS(vp), &afs_osi_cred); + error = afs_fsync(VTOAFS(vp), &afs_osi_cred); AFS_GUNLOCK(); return error; } int afs_vop_seek(ap) - struct vop_seek_args /* { - struct vnode *a_vp; - off_t a_oldoff; - off_t a_newoff; - struct ucred *a_cred; - } */ *ap; + struct vop_seek_args /* { + * struct vnode *a_vp; + * off_t a_oldoff; + * off_t a_newoff; + * struct ucred *a_cred; + * } */ *ap; { - if (ap->a_newoff > ULONG_MAX) /* AFS doesn't support 64-bit offsets */ + if (ap->a_newoff > ULONG_MAX) /* AFS doesn't support 64-bit offsets */ return EINVAL; return (0); } int afs_vop_remove(ap) - struct vop_remove_args /* { - struct vnode *a_dvp; - struct vnode *a_vp; - struct componentname *a_cnp; - } */ *ap; + struct vop_remove_args /* { + * struct vnode *a_dvp; + * struct vnode *a_vp; + * struct componentname *a_cnp; + * } */ *ap; { int error = 0; register struct vnode *vp = ap->a_vp; @@ -802,20 +828,20 @@ afs_vop_remove(ap) GETNAME(); AFS_GLOCK(); - error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred); + error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred); AFS_GUNLOCK(); cache_purge(vp); if (!error && UBCINFOEXISTS(vp)) { #ifdef AFS_DARWIN14_ENV - (void) ubc_uncache(vp); + (void)ubc_uncache(vp); #else - int wasmapped=ubc_issetflags(vp, UI_WASMAPPED); - int hasobjref=ubc_issetflags(vp, UI_HASOBJREF); - if (wasmapped) - (void) ubc_uncache(vp); - if (hasobjref) - ubc_release(vp); - /* WARNING vp may not be valid after this */ + int wasmapped = ubc_issetflags(vp, UI_WASMAPPED); + int hasobjref = ubc_issetflags(vp, UI_HASOBJREF); + if (wasmapped) + (void)ubc_uncache(vp); + if (hasobjref) + ubc_release(vp); + /* WARNING vp may not be valid after this */ #endif } if (dvp == vp) @@ -831,11 +857,11 @@ afs_vop_remove(ap) int afs_vop_link(ap) - struct vop_link_args /* { - struct vnode *a_vp; - struct vnode *a_tdvp; - struct componentname *a_cnp; - } */ *ap; + struct vop_link_args /* { + * struct vnode *a_vp; + * struct vnode *a_tdvp; + * struct componentname *a_cnp; + * } */ *ap; { int error = 0; register struct vnode *dvp = ap->a_tdvp; @@ -843,7 +869,7 @@ afs_vop_link(ap) struct proc *p; GETNAME(); - p=cnp->cn_proc; + p = cnp->cn_proc; if (vp->v_type == VDIR) { VOP_ABORTOP(vp, cnp); error = EISDIR; @@ -858,8 +884,8 @@ afs_vop_link(ap) AFS_GUNLOCK(); FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI); if (dvp != vp) - VOP_UNLOCK(vp,0, p); -out: + VOP_UNLOCK(vp, 0, p); + out: vput(dvp); DROPNAME(); return error; @@ -867,14 +893,14 @@ out: int afs_vop_rename(ap) - struct vop_rename_args /* { - struct vnode *a_fdvp; - struct vnode *a_fvp; - struct componentname *a_fcnp; - struct vnode *a_tdvp; - struct vnode *a_tvp; - struct componentname *a_tcnp; - } */ *ap; + struct vop_rename_args /* { + * struct vnode *a_fdvp; + * struct vnode *a_fvp; + * struct componentname *a_fcnp; + * struct vnode *a_tdvp; + * struct vnode *a_tvp; + * struct componentname *a_tcnp; + * } */ *ap; { int error = 0; struct componentname *fcnp = ap->a_fcnp; @@ -885,7 +911,16 @@ afs_vop_rename(ap) register struct vnode *tdvp = ap->a_tdvp; struct vnode *fvp = ap->a_fvp; register struct vnode *fdvp = ap->a_fdvp; - struct proc *p=fcnp->cn_proc; + struct proc *p = fcnp->cn_proc; + + /* Check for cross-device rename. + * For AFS, this means anything not in AFS-space + */ + if ((0 != strcmp(tdvp->v_mount->mnt_stat.f_fstypename, "afs")) || + (tvp && (0 != strcmp(tvp->v_mount->mnt_stat.f_fstypename, "afs")))) { + error = EXDEV; + goto abortit; + } /* * if fvp == tvp, we're just removing one name of a pair of @@ -895,15 +930,15 @@ afs_vop_rename(ap) if (fvp == tvp) { if (fvp->v_type == VDIR) { error = EINVAL; - abortit: - VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */ + abortit: + VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */ if (tdvp == tvp) vrele(tdvp); else vput(tdvp); if (tvp) vput(tvp); - VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */ + VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */ vrele(fdvp); vrele(fvp); return (error); @@ -922,30 +957,31 @@ afs_vop_rename(ap) if ((fcnp->cn_flags & SAVESTART) == 0) panic("afs_rename: lost from startdir"); fcnp->cn_nameiop = DELETE; - (void) relookup(fdvp, &fvp, fcnp); + (void)relookup(fdvp, &fvp, fcnp); return (VOP_REMOVE(fdvp, fvp, fcnp)); } if (error = vn_lock(fvp, LK_EXCLUSIVE, p)) goto abortit; - MALLOC(fname, char *, fcnp->cn_namelen+1, M_TEMP, M_WAITOK); + MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK); memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen); fname[fcnp->cn_namelen] = '\0'; - MALLOC(tname, char *, tcnp->cn_namelen+1, M_TEMP, M_WAITOK); + MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK); memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen); tname[tcnp->cn_namelen] = '\0'; AFS_GLOCK(); /* XXX use "from" or "to" creds? NFS uses "to" creds */ - error = afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred); + error = + afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred); AFS_GUNLOCK(); VOP_UNLOCK(fvp, 0, p); FREE(fname, M_TEMP); FREE(tname, M_TEMP); if (error) - goto abortit; /* XXX */ + goto abortit; /* XXX */ if (tdvp == tvp) vrele(tdvp); else @@ -959,12 +995,12 @@ afs_vop_rename(ap) int afs_vop_mkdir(ap) - struct vop_mkdir_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - struct vattr *a_vap; - } */ *ap; + struct vop_mkdir_args /* { + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * struct vattr *a_vap; + * } */ *ap; { register struct vnode *dvp = ap->a_dvp; register struct vattr *vap = ap->a_vap; @@ -973,7 +1009,7 @@ afs_vop_mkdir(ap) struct proc *p; GETNAME(); - p=cnp->cn_proc; + p = cnp->cn_proc; #ifdef DIAGNOSTIC if ((cnp->cn_flags & HASBUF) == 0) panic("afs_vop_mkdir: no name"); @@ -985,12 +1021,12 @@ afs_vop_mkdir(ap) VOP_ABORTOP(dvp, cnp); vput(dvp); DROPNAME(); - return(error); + return (error); } if (vcp) { *ap->a_vpp = AFSTOV(vcp); (*ap->a_vpp)->v_vfsp = dvp->v_vfsp; - vn_lock(*ap->a_vpp, LK_EXCLUSIVE|LK_RETRY, p); + vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY, p); } else *ap->a_vpp = 0; DROPNAME(); @@ -1001,11 +1037,11 @@ afs_vop_mkdir(ap) int afs_vop_rmdir(ap) - struct vop_rmdir_args /* { - struct vnode *a_dvp; - struct vnode *a_vp; - struct componentname *a_cnp; - } */ *ap; + struct vop_rmdir_args /* { + * struct vnode *a_dvp; + * struct vnode *a_vp; + * struct componentname *a_cnp; + * } */ *ap; { int error = 0; register struct vnode *vp = ap->a_vp; @@ -1031,13 +1067,13 @@ afs_vop_rmdir(ap) int afs_vop_symlink(ap) - struct vop_symlink_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - struct vattr *a_vap; - char *a_target; - } */ *ap; + struct vop_symlink_args /* { + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * struct vattr *a_vap; + * char *a_target; + * } */ *ap; { register struct vnode *dvp = ap->a_dvp; int error = 0; @@ -1045,8 +1081,8 @@ afs_vop_symlink(ap) GETNAME(); AFS_GLOCK(); - error = afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, - cnp->cn_cred); + error = + afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred); AFS_GUNLOCK(); DROPNAME(); FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI); @@ -1056,23 +1092,23 @@ afs_vop_symlink(ap) int afs_vop_readdir(ap) - struct vop_readdir_args /* { - struct vnode *a_vp; - struct uio *a_uio; - struct ucred *a_cred; - int *a_eofflag; - u_long *a_cookies; - int ncookies; - } */ *ap; + struct vop_readdir_args /* { + * struct vnode *a_vp; + * struct uio *a_uio; + * struct ucred *a_cred; + * int *a_eofflag; + * u_long *a_cookies; + * int ncookies; + * } */ *ap; { int error; off_t off; /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies, ap->a_ncookies); */ - off=ap->a_uio->uio_offset; + off = ap->a_uio->uio_offset; AFS_GLOCK(); - error= afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, - ap->a_eofflag); + error = + afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag); AFS_GUNLOCK(); if (!error && ap->a_ncookies != NULL) { struct uio *uio = ap->a_uio; @@ -1085,17 +1121,15 @@ afs_vop_readdir(ap) dp = (const struct dirent *) ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off)); - dp_end = (const struct dirent *) uio->uio_iov->iov_base; - for (dp_start = dp, ncookies = 0; - dp < dp_end; - dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) + dp_end = (const struct dirent *)uio->uio_iov->iov_base; + for (dp_start = dp, ncookies = 0; dp < dp_end; + dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) ncookies++; - MALLOC(cookies, u_long *, ncookies * sizeof(u_long), - M_TEMP, M_WAITOK); - for (dp = dp_start, cookiep = cookies; - dp < dp_end; - dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) { + MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP, + M_WAITOK); + for (dp = dp_start, cookiep = cookies; dp < dp_end; + dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) { off += dp->d_reclen; *cookiep++ = off; } @@ -1108,16 +1142,16 @@ afs_vop_readdir(ap) int afs_vop_readlink(ap) - struct vop_readlink_args /* { - struct vnode *a_vp; - struct uio *a_uio; - struct ucred *a_cred; - } */ *ap; + struct vop_readlink_args /* { + * struct vnode *a_vp; + * struct uio *a_uio; + * struct ucred *a_cred; + * } */ *ap; { int error; /* printf("readlink %x\n", ap->a_vp);*/ AFS_GLOCK(); - error= afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred); + error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred); AFS_GUNLOCK(); return error; } @@ -1126,10 +1160,10 @@ extern int prtactive; int afs_vop_inactive(ap) - struct vop_inactive_args /* { - struct vnode *a_vp; - struct proc *a_p; - } */ *ap; + struct vop_inactive_args /* { + * struct vnode *a_vp; + * struct proc *a_p; + * } */ *ap; { register struct vnode *vp = ap->a_vp; @@ -1137,7 +1171,7 @@ afs_vop_inactive(ap) vprint("afs_vop_inactive(): pushing active", vp); AFS_GLOCK(); - afs_InactiveVCache(VTOAFS(vp), 0); /* decrs ref counts */ + afs_InactiveVCache(VTOAFS(vp), 0); /* decrs ref counts */ AFS_GUNLOCK(); VOP_UNLOCK(vp, 0, ap->a_p); return 0; @@ -1145,74 +1179,74 @@ afs_vop_inactive(ap) int afs_vop_reclaim(ap) - struct vop_reclaim_args /* { - struct vnode *a_vp; - } */ *ap; + struct vop_reclaim_args /* { + * struct vnode *a_vp; + * } */ *ap; { int error; int sl; register struct vnode *vp = ap->a_vp; - cache_purge(vp); /* just in case... */ + cache_purge(vp); /* just in case... */ -#if 0 +#if 0 AFS_GLOCK(); - error = afs_FlushVCache(VTOAFS(vp), &sl); /* tosses our stuff from vnode */ + error = afs_FlushVCache(VTOAFS(vp), &sl); /* tosses our stuff from vnode */ AFS_GUNLOCK(); ubc_unlink(vp); if (!error && vp->v_data) panic("afs_reclaim: vnode not cleaned"); return error; #else - if (vp->v_usecount == 2) { - vprint("reclaim count==2", vp); - } else if (vp->v_usecount == 1) { - vprint("reclaim count==1", vp); - } else - vprint("reclaim bad count", vp); - - return 0; + if (vp->v_usecount == 2) { + vprint("reclaim count==2", vp); + } else if (vp->v_usecount == 1) { + vprint("reclaim count==1", vp); + } else + vprint("reclaim bad count", vp); + + return 0; #endif } int afs_vop_lock(ap) - struct vop_lock_args /* { - struct vnode *a_vp; - } */ *ap; + struct vop_lock_args /* { + * struct vnode *a_vp; + * } */ *ap; { - register struct vnode *vp = ap->a_vp; - register struct vcache *avc = VTOAFS(vp); + register struct vnode *vp = ap->a_vp; + register struct vcache *avc = VTOAFS(vp); - if (vp->v_tag == VT_NON) - return (ENOENT); - return (lockmgr(&avc->rwlock, ap->a_flags, &vp->v_interlock, - ap->a_p)); + if (vp->v_tag == VT_NON) + return (ENOENT); + return (lockmgr(&avc->rwlock, ap->a_flags, &vp->v_interlock, ap->a_p)); } int afs_vop_unlock(ap) - struct vop_unlock_args /* { - struct vnode *a_vp; - } */ *ap; + struct vop_unlock_args /* { + * struct vnode *a_vp; + * } */ *ap; { struct vnode *vp = ap->a_vp; struct vcache *avc = VTOAFS(vp); - return (lockmgr(&avc->rwlock, ap->a_flags | LK_RELEASE, - &vp->v_interlock, ap->a_p)); + return (lockmgr + (&avc->rwlock, ap->a_flags | LK_RELEASE, &vp->v_interlock, + ap->a_p)); } int afs_vop_bmap(ap) - struct vop_bmap_args /* { - struct vnode *a_vp; - daddr_t a_bn; - struct vnode **a_vpp; - daddr_t *a_bnp; - int *a_runp; - int *a_runb; - } */ *ap; + struct vop_bmap_args /* { + * struct vnode *a_vp; + * daddr_t a_bn; + * struct vnode **a_vpp; + * daddr_t *a_bnp; + * int *a_runp; + * int *a_runb; + * } */ *ap; { struct vcache *vcp; int error; @@ -1222,52 +1256,58 @@ afs_vop_bmap(ap) if (ap->a_vpp) { *ap->a_vpp = ap->a_vp; } - if (ap->a_runp != NULL) - *ap->a_runp = 0; + if (ap->a_runp != NULL) + *ap->a_runp = 0; #ifdef notyet - if (ap->a_runb != NULL) - *ap->a_runb = 0; + if (ap->a_runb != NULL) + *ap->a_runb = 0; #endif - + return 0; } + int afs_vop_strategy(ap) - struct vop_strategy_args /* { - struct buf *a_bp; - } */ *ap; + struct vop_strategy_args /* { + * struct buf *a_bp; + * } */ *ap; { int error; AFS_GLOCK(); - error= afs_ustrategy(ap->a_bp); + error = afs_ustrategy(ap->a_bp); AFS_GUNLOCK(); return error; } + int afs_vop_print(ap) - struct vop_print_args /* { - struct vnode *a_vp; - } */ *ap; + struct vop_print_args /* { + * struct vnode *a_vp; + * } */ *ap; { register struct vnode *vp = ap->a_vp; register struct vcache *vc = VTOAFS(ap->a_vp); int s = vc->states; - printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag, vc->fid.Cell, - vc->fid.Fid.Volume, vc->fid.Fid.Vnode, vc->fid.Fid.Unique, vc->opens, - vc->execsOrWriters); - printf("\n states%s%s%s%s%s", (s&CStatd) ? " statd" : "", (s&CRO) ? " readonly" : "",(s&CDirty) ? " dirty" : "",(s&CMAPPED) ? " mapped" : "", (s&CVFlushed) ? " flush in progress" : ""); + printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag, + vc->fid.Cell, vc->fid.Fid.Volume, vc->fid.Fid.Vnode, + vc->fid.Fid.Unique, vc->opens, vc->execsOrWriters); + printf("\n states%s%s%s%s%s", (s & CStatd) ? " statd" : "", + (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "", + (s & CMAPPED) ? " mapped" : "", + (s & CVFlushed) ? " flush in progress" : ""); if (UBCISVALID(vp)) { - printf("\n UBC: "); - if (UBCINFOEXISTS(vp)) { - printf("exists, ") ; + printf("\n UBC: "); + if (UBCINFOEXISTS(vp)) { + printf("exists, "); #ifdef AFS_DARWIN14_ENV - printf("refs %d%s%s", vp->v_ubcinfo->ui_refcount, - ubc_issetflags(vp, UI_HASOBJREF) ? " HASOBJREF" : "", - ubc_issetflags(vp, UI_WASMAPPED) ? " WASMAPPED" : ""); + printf("refs %d%s%s", vp->v_ubcinfo->ui_refcount, + ubc_issetflags(vp, UI_HASOBJREF) ? " HASOBJREF" : "", + ubc_issetflags(vp, UI_WASMAPPED) ? " WASMAPPED" : ""); #else - printf("holdcnt %d", vp->v_ubcinfo->ui_holdcnt); + printf("holdcnt %d", vp->v_ubcinfo->ui_holdcnt); #endif - } else printf("does not exist"); + } else + printf("does not exist"); } printf("\n"); return 0; @@ -1275,9 +1315,9 @@ afs_vop_print(ap) int afs_vop_islocked(ap) - struct vop_islocked_args /* { - struct vnode *a_vp; - } */ *ap; + struct vop_islocked_args /* { + * struct vnode *a_vp; + * } */ *ap; { struct vcache *vc = VTOAFS(ap->a_vp); return lockstatus(&vc->rwlock); @@ -1287,44 +1327,44 @@ afs_vop_islocked(ap) * Return POSIX pathconf information applicable to ufs filesystems. */ afs_vop_pathconf(ap) - struct vop_pathconf_args /* { - struct vnode *a_vp; - int a_name; - int *a_retval; - } */ *ap; + struct vop_pathconf_args /* { + * struct vnode *a_vp; + * int a_name; + * int *a_retval; + * } */ *ap; { AFS_STATCNT(afs_cntl); switch (ap->a_name) { - case _PC_LINK_MAX: + case _PC_LINK_MAX: *ap->a_retval = LINK_MAX; break; - case _PC_NAME_MAX: + case _PC_NAME_MAX: *ap->a_retval = NAME_MAX; break; - case _PC_PATH_MAX: + case _PC_PATH_MAX: *ap->a_retval = PATH_MAX; break; - case _PC_CHOWN_RESTRICTED: + case _PC_CHOWN_RESTRICTED: *ap->a_retval = 1; break; - case _PC_NO_TRUNC: + case _PC_NO_TRUNC: *ap->a_retval = 1; break; - case _PC_PIPE_BUF: + case _PC_PIPE_BUF: return EINVAL; break; #if defined(AFS_DARWIN70_ENV) - case _PC_NAME_CHARS_MAX: - *ap->a_retval = NAME_MAX; + case _PC_NAME_CHARS_MAX: + *ap->a_retval = NAME_MAX; break; - case _PC_CASE_SENSITIVE: - *ap->a_retval = 1; + case _PC_CASE_SENSITIVE: + *ap->a_retval = 1; break; - case _PC_CASE_PRESERVING: - *ap->a_retval = 1; + case _PC_CASE_PRESERVING: + *ap->a_retval = 1; break; #endif /* defined(AFS_DARWIN70_ENV) */ - default: + default: return EINVAL; } return 0; @@ -1335,36 +1375,36 @@ afs_vop_pathconf(ap) */ int afs_vop_advlock(ap) - struct vop_advlock_args /* { - struct vnode *a_vp; - caddr_t a_id; - int a_op; - struct flock *a_fl; - int a_flags; - } */ *ap; + struct vop_advlock_args /* { + * struct vnode *a_vp; + * caddr_t a_id; + * int a_op; + * struct flock *a_fl; + * int a_flags; + * } */ *ap; { int error; - struct proc *p=current_proc(); + struct proc *p = current_proc(); struct ucred cr; pcred_readlock(p); - cr=*p->p_cred->pc_ucred; + cr = *p->p_cred->pc_ucred; pcred_unlock(p); AFS_GLOCK(); - error= afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, - (int) ap->a_id); + error = + afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id); AFS_GUNLOCK(); return error; } int afs_vop_truncate(ap) - struct vop_truncate_args /* { - struct vnode *a_vp; - off_t a_length; - int a_flags; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_truncate_args /* { + * struct vnode *a_vp; + * off_t a_length; + * int a_flags; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { printf("stray afs_vop_truncate\n"); return EOPNOTSUPP; @@ -1372,52 +1412,54 @@ afs_vop_truncate(ap) int afs_vop_update(ap) - struct vop_update_args /* { - struct vnode *a_vp; - struct timeval *a_access; - struct timeval *a_modify; - int a_waitfor; - } */ *ap; + struct vop_update_args /* { + * struct vnode *a_vp; + * struct timeval *a_access; + * struct timeval *a_modify; + * int a_waitfor; + * } */ *ap; { printf("stray afs_vop_update\n"); return EOPNOTSUPP; } -int afs_vop_blktooff(ap) - struct vop_blktooff_args /* { - struct vnode *a_vp; - daddr_t a_lblkno; - off_t *a_offset; - } */ *ap; +int +afs_vop_blktooff(ap) + struct vop_blktooff_args /* { + * struct vnode *a_vp; + * daddr_t a_lblkno; + * off_t *a_offset; + * } */ *ap; { - *ap->a_offset = (off_t)(ap->a_lblkno * DEV_BSIZE); - return 0; + *ap->a_offset = (off_t) (ap->a_lblkno * DEV_BSIZE); + return 0; } -int afs_vop_offtoblk(ap) - struct vop_offtoblk_args /* { - struct vnode *a_vp; - off_t a_offset; - daddr_t *a_lblkno; - } */ *ap; +int +afs_vop_offtoblk(ap) + struct vop_offtoblk_args /* { + * struct vnode *a_vp; + * off_t a_offset; + * daddr_t *a_lblkno; + * } */ *ap; { - *ap->a_lblkno = (daddr_t)(ap->a_offset / DEV_BSIZE); + *ap->a_lblkno = (daddr_t) (ap->a_offset / DEV_BSIZE); - return (0); + return (0); } -int afs_vop_cmap(ap) - struct vop_cmap_args /* { - struct vnode *a_vp; - off_t a_foffset; - size_t a_size; - daddr_t *a_bpn; - size_t *a_run; - void *a_poff; - } */ *ap; +int +afs_vop_cmap(ap) + struct vop_cmap_args /* { + * struct vnode *a_vp; + * off_t a_foffset; + * size_t a_size; + * daddr_t *a_bpn; + * size_t *a_run; + * void *a_poff; + * } */ *ap; { - *ap->a_bpn = (daddr_t)(ap->a_foffset / DEV_BSIZE); - *ap->a_run= MAX(ap->a_size, AFS_CHUNKSIZE(ap->a_foffset)); - return 0; + *ap->a_bpn = (daddr_t) (ap->a_foffset / DEV_BSIZE); + *ap->a_run = MAX(ap->a_size, AFS_CHUNKSIZE(ap->a_foffset)); + return 0; } - diff --git a/src/afs/DOC/afs_rwlocks b/src/afs/DOC/afs_rwlocks index 865979402..b554d45ef 100644 --- a/src/afs/DOC/afs_rwlocks +++ b/src/afs/DOC/afs_rwlocks @@ -14,44 +14,65 @@ our own layer. they're locked in order of vnode within the same volume. afs_AccessOK is called before locking other entries. -3. afs_xvcache locked before afs_xdcache in afs_remove, afs_symlink, etc -in the file afs_vnodeops.c +3. VCache entry vlock (Solaris only). -4. afs_xvcache. Must be able to load new cache -entries while holding locks on others. Note this means you can't lock -a cache entry while holding either of this lock, unless, as in afs_create, -the cache entry is actually created while the afs_xvcache is held. +4. DCache entries. Tentatively, multiple ones can be locked now. +Locking order between dcache entries is in increasing offset order. +However, if it turns out we never need to lock multiple dcache's, +we should just say it's not allowed, and simplify things. -5. afs_xvcb. Volume callback lock. Locked before afs_xserver in afs_RemoveVCB. +5. afs_xdcache. Protects the dcache hash tables and afs_index* in +afs_dcache.c. As with afs_xvcache below, a newly created dcache +entries can be locked while holding afs_xdcache. -6. afs_xvolume -- allows low-level server etc stuff to happen while +Bugs: afs_xvcache locked before afs_xdcache in afs_remove, afs_symlink, +etc in the file afs_vnodeops.c + +6. afs_xvcache. Must be able to load new cache entries while holding +locks on others. Note this means you can't lock a cache entry while +holding either of this lock, unless, as in afs_create, the cache entry +is actually created while the afs_xvcache is held. + +7. afs_xvcb. Volume callback lock. Locked before afs_xserver in +afs_RemoveVCB. + +8. afs_xvolume -- allows low-level server etc stuff to happen while creating a volume? -7. afs_xuser -- afs_xuser locked before afs_xserver and afs_xconn in -PUnlog. +9. afs_xuser -- afs_xuser is locked before afs_xserver and afs_xconn +in PUnlog. -8. afs_xcell -- locked before server in afs_GetCell. +10. afs_xcell -- afs_xcell locked before afs_xserver in afs_GetCell. -9. afs_xserver -- afs_xserver locked before afs_xconn in -afs_ResetUserConns. +11. afs_xserver -- locked before afs_xconn in afs_ResetUserConns. -10. afs_xsrvAddr -- afs_xserver locked before afs_xsrvAddr in +12. afs_xsrvAddr -- afs_xserver locked before afs_xsrvAddr in afs_CheckServers. -11. afs_xconn -- see above +13. afs_xconn -- see above -12. Individual volume locks. Must be after afs_xvolume so we can +14. Individual volume locks. Must be after afs_xvolume so we can iterate over all volumes without others being inserted/deleted. Same hack doesn't work for cache entry locks since we need to be able to lock multiple cache entries (but not multiple volumes) simultaneously. -13. afs_xdnlc -- locked after afs_xvcache in afs_osidnlc.c. Shouldn't +15. afs_xdnlc -- locked after afs_xvcache in afs_osidnlc.c. Shouldn't interact with any of the other locks. -14. afs_xcbhash -- No code which holds xcbhash (all of it is in -afs_cbqueue.c) attempts to get any other locks, so it should always be -obtained last. It is locked in afs_DequeueCallbacks which is called from -afs_FlushVCache with afs_xvcache write-locked. +16. afs_xcbhash -- No code which holds xcbhash (all of it is in +afs_cbqueue.c) (note: this doesn't seem to be true -- it's used +elsewhere too) attempts to get any other locks, so it should always +be obtained last. It is locked in afs_DequeueCallbacks which is +called from afs_FlushVCache with afs_xvcache write-locked. + +17. afs_dynrootDirLock -- afs_GetDynroot returns the lock held, +afs_PutDynroot releases it. + +18. Dcache entry mflock -- used to atomize accesses and updates to +dcache mflags. + +19. DCache entry tlock -- used to make atomic reads or writes to +the dcache refcount. ***** RX_ENABLE_LOCKS diff --git a/src/afs/DUX/osi_file.c b/src/afs/DUX/osi_file.c index 842f5a220..edba62fd2 100644 --- a/src/afs/DUX/osi_file.c +++ b/src/afs/DUX/osi_file.c @@ -8,24 +8,25 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_file.c,v 1.1.1.6 2001/09/11 14:24:56 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DUX/osi_file.c,v 1.9 2003/07/15 23:14:18 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ -int afs_osicred_initialized=0; -struct AFS_UCRED afs_osi_cred; +int afs_osicred_initialized = 0; +struct AFS_UCRED afs_osi_cred; afs_lock_t afs_xosi; /* lock is for tvattr */ extern struct osi_dev cacheDev; extern struct mount *afs_cacheVfsp; -void *osi_UFSOpen(ainode) - afs_int32 ainode; +void * +osi_UFSOpen(afs_int32 ainode) { static struct vnode *tags_vnode = NULL; struct inode *ip; @@ -34,70 +35,72 @@ void *osi_UFSOpen(ainode) afs_int32 code = 0; int dummy; AFS_STATCNT(osi_UFSOpen); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) osi_Panic("UFSOpen called for non-UFS cache\n"); - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); AFS_GUNLOCK(); - switch(afs_cacheVfsp->m_stat.f_type) { + switch (afs_cacheVfsp->m_stat.f_type) { case MOUNT_UFS: - code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode, &ip, &dummy); - if (code) { - osi_FreeSmallSpace(afile); - osi_Panic("UFSOpen: igetinode failed"); - } - IN_UNLOCK(ip); - afile->vnode = ITOV(ip); - afile->size = VTOI(afile->vnode)->i_size; - afile->offset = 0; - afile->proc = NULL; - afile->inum = ainode; /* for hint validity checking */ - break; - case MOUNT_MSFS: { - char path[1024]; - struct nameidata nd, *ndp = &nd; - struct utask_nd utnd = { NULL, NULL }; - struct vattr attr; - - memset(&nd, 0, sizeof(nd)); - ndp->ni_utnd = &utnd; - ndp->ni_nameiop = LOOKUP; - ndp->ni_cred = &afs_osi_cred; - ndp->ni_segflg = UIO_SYSSPACE; - - /* get hold of a vnode for the .tags directory, so we can - lookup files relative to it */ - if(tags_vnode == NULL) { - ndp->ni_cdir = afs_cacheVfsp->m_vnodecovered; - strcpy(path, afs_cacheVfsp->m_stat.f_mntonname); - strcat(path, "/.tags"); - ndp->ni_dirp = path; - if((code = namei(ndp))) - osi_Panic("failed to lookup %s (%d)", path, code); - tags_vnode = ndp->ni_vp; - } - sprintf(path, "%d", ainode); - ndp->ni_dirp = path; - ndp->ni_cdir = tags_vnode; - if((code = namei(ndp))) - osi_Panic("failed to lookup %s (%d)", path, code); - - /* XXX this sucks, chances are we're going to do this again right - away, but apparently we can't just set the size to 0 */ - VOP_GETATTR(ndp->ni_vp, &attr, &afs_osi_cred, code); - if(code) - osi_Panic("failed to stat %s (%d)", path, code); - - afile->vnode = ndp->ni_vp; - afile->size = attr.va_size; - afile->offset = 0; - afile->proc = NULL; - afile->inum = ainode; /* for hint validity checking */ - break; - } + code = + igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, + &ip, &dummy); + if (code) { + osi_FreeSmallSpace(afile); + osi_Panic("UFSOpen: igetinode failed"); + } + IN_UNLOCK(ip); + afile->vnode = ITOV(ip); + afile->size = VTOI(afile->vnode)->i_size; + afile->offset = 0; + afile->proc = NULL; + afile->inum = ainode; /* for hint validity checking */ + break; + case MOUNT_MSFS:{ + char path[1024]; + struct nameidata nd, *ndp = &nd; + struct utask_nd utnd = { NULL, NULL }; + struct vattr attr; + + memset(&nd, 0, sizeof(nd)); + ndp->ni_utnd = &utnd; + ndp->ni_nameiop = LOOKUP; + ndp->ni_cred = &afs_osi_cred; + ndp->ni_segflg = UIO_SYSSPACE; + + /* get hold of a vnode for the .tags directory, so we can + * lookup files relative to it */ + if (tags_vnode == NULL) { + ndp->ni_cdir = afs_cacheVfsp->m_vnodecovered; + strcpy(path, afs_cacheVfsp->m_stat.f_mntonname); + strcat(path, "/.tags"); + ndp->ni_dirp = path; + if ((code = namei(ndp))) + osi_Panic("failed to lookup %s (%d)", path, code); + tags_vnode = ndp->ni_vp; + } + sprintf(path, "%d", ainode); + ndp->ni_dirp = path; + ndp->ni_cdir = tags_vnode; + if ((code = namei(ndp))) + osi_Panic("failed to lookup %s (%d)", path, code); + + /* XXX this sucks, chances are we're going to do this again right + * away, but apparently we can't just set the size to 0 */ + VOP_GETATTR(ndp->ni_vp, &attr, &afs_osi_cred, code); + if (code) + osi_Panic("failed to stat %s (%d)", path, code); + + afile->vnode = ndp->ni_vp; + afile->size = attr.va_size; + afile->offset = 0; + afile->proc = NULL; + afile->inum = ainode; /* for hint validity checking */ + break; + } default: - osi_Panic("UFSOpen called for unknown cache-type (%d)", + osi_Panic("UFSOpen called for unknown cache-type (%d)", afs_cacheVfsp->m_stat.f_type); } @@ -105,13 +108,13 @@ void *osi_UFSOpen(ainode) return afile; } -afs_osi_Stat(afile, astat) - register struct osi_file *afile; - register struct osi_stat *astat; { +int +afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) +{ register afs_int32 code; struct vattr tvattr; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi,320); + MObtainWriteLock(&afs_xosi, 320); AFS_GUNLOCK(); VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, code); AFS_GLOCK(); @@ -125,21 +128,21 @@ afs_osi_Stat(afile, astat) return code; } -osi_UFSClose(afile) - register struct osi_file *afile; - { - AFS_STATCNT(osi_Close); - if(afile->vnode) { +int +osi_UFSClose(register struct osi_file *afile) +{ + AFS_STATCNT(osi_Close); + if (afile->vnode) { AFS_RELE(afile->vnode); - } - - osi_FreeSmallSpace(afile); - return 0; - } - -osi_UFSTruncate(afile, asize) - register struct osi_file *afile; - afs_int32 asize; { + } + + osi_FreeSmallSpace(afile); + return 0; +} + +int +osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) +{ struct AFS_UCRED *oldCred; struct vattr tvattr; register afs_int32 code; @@ -151,105 +154,107 @@ osi_UFSTruncate(afile, asize) * small enough. Check now and save some time. */ code = afs_osi_Stat(afile, &tstat); - if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi,321); + if (code || tstat.size <= asize) + return code; + MObtainWriteLock(&afs_xosi, 321); VATTR_NULL(&tvattr); /* note that this credential swapping stuff is only necessary because - of ufs's references directly to u.u_cred instead of to - credentials parameter. Probably should fix ufs some day. */ - oldCred = u.u_cred; /* remember old credentials pointer */ - u.u_cred = &afs_osi_cred; /* temporarily use superuser credentials */ + * of ufs's references directly to u.u_cred instead of to + * credentials parameter. Probably should fix ufs some day. */ + oldCred = u.u_cred; /* remember old credentials pointer */ + u.u_cred = &afs_osi_cred; /* temporarily use superuser credentials */ tvattr.va_size = asize; AFS_GUNLOCK(); VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, code); AFS_GLOCK(); - u.u_cred = oldCred; /* restore */ + u.u_cred = oldCred; /* restore */ MReleaseWriteLock(&afs_xosi); return code; } -void osi_DisableAtimes(avp) -struct vnode *avp; +void +osi_DisableAtimes(struct vnode *avp) { - struct inode *ip; - assert(avp->v_tag == VT_UFS); - ip = VTOI(avp); - ip->i_flag &= ~IACC; + struct inode *ip; + assert(avp->v_tag == VT_UFS); + ip = VTOI(avp); + ip->i_flag &= ~IACC; } /* Generic read interface */ -afs_osi_Read(afile, offset, aptr, asize) - register struct osi_file *afile; - int offset; - char *aptr; - afs_int32 asize; { +int +afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; unsigned int resid; register afs_int32 code; - register afs_int32 cnt1=0; + register afs_int32 cnt1 = 0; AFS_STATCNT(osi_Read); /** * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ - if ( !afile ) { - if ( !afs_shuttingdown ) + if (!afile) { + if (!afs_shuttingdown) osi_Panic("osi_Read called with null param"); else return EIO; } - if (offset != -1) afile->offset = offset; + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, + AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; osi_DisableAtimes(afile->vnode); - } - else { + } else { afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, - ICL_TYPE_INT32, code); + ICL_TYPE_INT32, code); code = -1; } return code; } /* Generic write interface */ -afs_osi_Write(afile, offset, aptr, asize) - register struct osi_file *afile; - char *aptr; - afs_int32 offset; - afs_int32 asize; { +int +afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; unsigned int resid; register afs_int32 code; AFS_STATCNT(osi_Write); - if ( !afile ) - osi_Panic("afs_osi_Write called with null param"); - if (offset != -1) afile->offset = offset; + if (!afile) + osi_Panic("afs_osi_Write called with null param"); + if (offset != -1) + afile->offset = offset; { struct ucred *tmpcred = u.u_cred; u.u_cred = &afs_osi_cred; AFS_GUNLOCK(); - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + afile->offset, AFS_UIOSYS, IO_UNIT, &afs_osi_cred, + &resid); AFS_GLOCK(); u.u_cred = tmpcred; } if (code == 0) { code = asize - resid; afile->offset += code; - } - else { + } else { code = -1; } if (afile->proc) { - (*afile->proc)(afile, code); + (*afile->proc) (afile, code); } return code; } @@ -258,9 +263,8 @@ afs_osi_Write(afile, offset, aptr, asize) /* This work should be handled by physstrat in ca/machdep.c. This routine written from the RT NFS port strategy routine. It has been generalized a bit, but should still be pretty clear. */ -int afs_osi_MapStrategy(aproc, bp) - int (*aproc)(); - register struct buf *bp; +int +afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp) { afs_int32 returnCode; @@ -273,13 +277,12 @@ int afs_osi_MapStrategy(aproc, bp) void -shutdown_osifile() +shutdown_osifile(void) { - extern int afs_cold_shutdown; + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osifile); - if (afs_cold_shutdown) { - afs_osicred_initialized = 0; - } + AFS_STATCNT(shutdown_osifile); + if (afs_cold_shutdown) { + afs_osicred_initialized = 0; + } } - diff --git a/src/afs/DUX/osi_groups.c b/src/afs/DUX/osi_groups.c index cca17fbf1..f12553871 100644 --- a/src/afs/DUX/osi_groups.c +++ b/src/afs/DUX/osi_groups.c @@ -14,33 +14,27 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_groups.c,v 1.1.1.4 2001/07/14 22:19:36 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DUX/osi_groups.c,v 1.6 2003/07/15 23:14:18 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset); + afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset); static int -afs_setgroups( - struct proc *proc, - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent); + afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups, + gid_t * gidset, int change_parent); int Afs_xsetgroups(p, args, retval) - struct proc *p; - void *args; - int *retval; + struct proc *p; + void *args; + int *retval; { int code = 0; struct vrequest treq; @@ -50,7 +44,8 @@ Afs_xsetgroups(p, args, retval) code = afs_InitReq(&treq, u.u_cred); AFS_GUNLOCK(); - if (code) return code; + if (code) + return code; code = setgroups(p, args, retval); /* Note that if there is a pag already in the new groups we don't @@ -70,11 +65,11 @@ Afs_xsetgroups(p, args, retval) int setpag(proc, cred, pagvalue, newpag, change_parent) - struct proc *proc; - struct ucred **cred; - afs_uint32 pagvalue; - afs_uint32 *newpag; - afs_uint32 change_parent; + struct proc *proc; + struct ucred **cred; + afs_uint32 pagvalue; + afs_uint32 *newpag; + afs_uint32 change_parent; { gid_t gidset[NGROUPS]; int ngroups, code; @@ -87,12 +82,12 @@ setpag(proc, cred, pagvalue, newpag, change_parent) if (ngroups + 2 > NGROUPS) { return (E2BIG); } - for (j = ngroups -1; j >= 0; j--) { - gidset[j+2] = gidset[j]; - } + for (j = ngroups - 1; j >= 0; j--) { + gidset[j + 2] = gidset[j]; + } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); + *newpag = (pagvalue == -1 ? genpag() : pagvalue); afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]); code = afs_setgroups(proc, cred, ngroups, gidset, change_parent); return code; @@ -100,10 +95,7 @@ setpag(proc, cred, pagvalue, newpag, change_parent) static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset) +afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset) { int ngrps, savengrps; gid_t *gp; @@ -112,19 +104,15 @@ afs_getgroups( savengrps = ngrps = MIN(ngroups, cred->cr_ngroups); gp = cred->cr_groups; while (ngrps--) - *gidset++ = *gp++; + *gidset++ = *gp++; return savengrps; } static int -afs_setgroups( - struct proc *proc, - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent) +afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups, + gid_t * gidset, int change_parent) { int ngrps; int i; @@ -152,5 +140,5 @@ afs_setgroups( substitute_real_creds(proc, NOUID, NOUID, NOGID, NOGID, newcr); } *cred = newcr; - return(0); + return (0); } diff --git a/src/afs/DUX/osi_inode.c b/src/afs/DUX/osi_inode.c index 7ed70b301..128a962fd 100644 --- a/src/afs/DUX/osi_inode.c +++ b/src/afs/DUX/osi_inode.c @@ -14,14 +14,15 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_inode.c,v 1.1.1.6 2001/07/14 22:19:37 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DUX/osi_inode.c,v 1.12 2003/07/15 23:14:18 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/osi_inode.h" -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/osi_inode.h" +#include "afs/afs_stats.h" /* statistics stuff */ #include /* given a vnode, return the `inode number'; if it's a UFS vnode just @@ -34,28 +35,28 @@ osi_vnodeToInumber(struct vnode *vnode) struct vattr attr; /* use faster version with UFS */ - if(vnode->v_tag == VT_UFS) + if (vnode->v_tag == VT_UFS) return VTOI(vnode)->i_number; /* otherwise stat the file */ VOP_GETATTR(vnode, &attr, NULL, error); - if(error) + if (error) osi_Panic("VOP_GETATTR = %d", error); return attr.va_fileid; } /* return the id of the device containing the file */ afs_uint32 -osi_vnodeToDev(struct vnode *vnode) +osi_vnodeToDev(struct vnode * vnode) { int error; struct vattr attr; /* use faster version with UFS */ - if(vnode->v_tag == VT_UFS) + if (vnode->v_tag == VT_UFS) return VTOI(vnode)->i_dev; /* otherwise stat the file */ VOP_GETATTR(vnode, &attr, NULL, error); - if(error) + if (error) osi_Panic("VOP_GETATTR = %d", error); return attr.va_rdev; } @@ -78,43 +79,44 @@ getinode(fs, dev, inode, ipp, perror) register struct ufsmount *ump; register struct vnode *vp; register struct mount *mp; - + MOUNTLIST_LOCK(); - if (mp = rootfs) do { - /* - * XXX Also do the test for MFS - */ + if (mp = rootfs) + do { + /* + * XXX Also do the test for MFS + */ #undef m_data #undef m_next - if (mp->m_stat.f_type == MOUNT_UFS) { - MOUNTLIST_UNLOCK(); - ump = VFSTOUFS(mp); - if (ump->um_fs == NULL) - break; - if (ump->um_dev == dev) { - fs = ump->um_mountp; + if (mp->m_stat.f_type == MOUNT_UFS) { + MOUNTLIST_UNLOCK(); + ump = VFSTOUFS(mp); + if (ump->um_fs == NULL) + break; + if (ump->um_dev == dev) { + fs = ump->um_mountp; + } + MOUNTLIST_LOCK(); } - MOUNTLIST_LOCK(); - } #ifdef AFS_DUX50_ENV #define m_next m_nxt #endif - mp = mp->m_next; - } while (mp != rootfs); + mp = mp->m_next; + } while (mp != rootfs); MOUNTLIST_UNLOCK(); if (!fs) - return(ENXIO); + return (ENXIO); } - vp = (struct vnode *) fake_vnode; + vp = (struct vnode *)fake_vnode; fake_inode_init(vp, fs); assert(vp->v_tag == VT_UFS); code = iget(VTOI(vp), inode, &ip, 0); if (code != 0) { *perror = BAD_IGET; - return code; + return code; } else { *ipp = ip; - return(0); + return (0); } } @@ -134,26 +136,26 @@ igetinode(vfsp, dev, inode, ipp, perror) AFS_STATCNT(igetinode); if ((code = getinode(vfsp, dev, inode, &ip, perror)) != 0) { - return(code); + return (code); } if (ip->i_mode == 0) { /* Not an allocated inode */ - iforget(ip); - return(ENOENT); + iforget(ip); + return (ENOENT); } - if (ip->i_nlink == 0 || (ip->i_mode&IFMT) != IFREG) { + if (ip->i_nlink == 0 || (ip->i_mode & IFMT) != IFREG) { iput(ip); - return(ENOENT); + return (ENOENT); } *ipp = ip; - return(0); + return (0); } iforget(ip) -struct inode *ip; + struct inode *ip; { struct vnode *vp = ITOV(ip); @@ -176,72 +178,70 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval) long *retval; long dev, near_inode, param1, param2, param3, param4; { - int dummy, err=0; + int dummy, err = 0; struct inode *ip, *newip; register int code; struct vnode *vp; - + AFS_STATCNT(afs_syscall_icreate); - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = getinode(0, (dev_t)dev, 2, &ip, &dummy); + code = getinode(0, (dev_t) dev, 2, &ip, &dummy); if (code) { - return(ENOENT); + return (ENOENT); } - code = ialloc(ip, (ino_t)near_inode, 0, &newip); + code = ialloc(ip, (ino_t) near_inode, 0, &newip); iput(ip); if (code) { - return(code); + return (code); } IN_LOCK(newip); - newip->i_flag |= IACC|IUPD|ICHG; - + newip->i_flag |= IACC | IUPD | ICHG; + newip->i_nlink = 1; newip->i_mode = IFREG; - + IN_UNLOCK(newip); vp = ITOV(newip); VN_LOCK(vp); vp->v_type = VREG; VN_UNLOCK(vp); - - if ( !vp->v_object) - { - extern struct vfs_ubcops ufs_ubcops; - extern struct vm_ubc_object* ubc_object_allocate(); - struct vm_ubc_object* vop; - vop = ubc_object_allocate(&vp, &ufs_ubcops, - vp->v_mount->m_funnel); - VN_LOCK(vp); - vp->v_object = vop; - VN_UNLOCK(vp); - } - - + + if (!vp->v_object) { + extern struct vfs_ubcops ufs_ubcops; + extern struct vm_ubc_object *ubc_object_allocate(); + struct vm_ubc_object *vop; + vop = ubc_object_allocate(&vp, &ufs_ubcops, vp->v_mount->m_funnel); + VN_LOCK(vp); + vp->v_object = vop; + VN_UNLOCK(vp); + } + + IN_LOCK(newip); - newip->i_flags |= IC_XUID|IC_XGID; + newip->i_flags |= IC_XUID | IC_XGID; newip->i_flags &= ~IC_PROPLIST; newip->i_vicep1 = param1; - if (param2 == 0x1fffffff/*INODESPECIAL*/) { + if (param2 == 0x1fffffff /*INODESPECIAL*/) { newip->i_vicep2 = ((0x1fffffff << 3) + (param4 & 0x3)); - newip->i_vicep3a = (u_short)(param3 >> 16); - newip->i_vicep3b = (u_short)param3; + newip->i_vicep3a = (u_short) (param3 >> 16); + newip->i_vicep3b = (u_short) param3; } else { - newip->i_vicep2 = (((param2 >> 16) & 0x1f) << 27) + - (((param4 >> 16) & 0x1f) << 22) + - (param3 & 0x3fffff); - newip->i_vicep3a = (u_short)param4; - newip->i_vicep3b = (u_short)param2; + newip->i_vicep2 = + (((param2 >> 16) & 0x1f) << 27) + + (((param4 >> 16) & 0x1f) << 22) + (param3 & 0x3fffff); + newip->i_vicep3a = (u_short) param4; + newip->i_vicep3b = (u_short) param2; } newip->i_vicemagic = VICEMAGIC; - + *retval = newip->i_number; IN_UNLOCK(newip); iput(newip); - return(code); + return (code); } @@ -251,7 +251,7 @@ afs_syscall_iopen(dev, inode, usrmod, retval) { struct file *fp; struct inode *ip; - struct vnode *vp = (struct vnode *)0; + struct vnode *vp = NULL; int dummy; int fd; extern struct fileops vnops; @@ -259,35 +259,35 @@ afs_syscall_iopen(dev, inode, usrmod, retval) #ifdef AFS_DUX50_ENV struct ufile_entry *fe; #endif - + AFS_STATCNT(afs_syscall_iopen); - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy); + code = igetinode(0, (dev_t) dev, (ino_t) inode, &ip, &dummy); if (code) { - return(code); + return (code); } #ifdef AFS_DUX50_ENV if ((code = falloc(&fp, &fd, &fe)) != 0) { - iput(ip); - return(code); + iput(ip); + return (code); } #else if ((code = falloc(&fp, &fd)) != 0) { iput(ip); - return(code); + return (code); } #endif IN_UNLOCK(ip); - + FP_LOCK(fp); - fp->f_flag = (usrmod-FOPEN) & FMASK; + fp->f_flag = (usrmod - FOPEN) & FMASK; fp->f_type = DTYPE_VNODE; fp->f_ops = &vnops; - fp->f_data = (caddr_t)ITOV(ip); - + fp->f_data = (caddr_t) ITOV(ip); + FP_UNLOCK(fp); #ifdef AFS_DUX50_ENV u_set_fe(fd, fe, fp, &u.u_file_state); @@ -295,7 +295,7 @@ afs_syscall_iopen(dev, inode, usrmod, retval) U_FD_SET(fd, fp, &u.u_file_state); #endif *retval = fd; - return(0); + return (0); } @@ -311,18 +311,18 @@ afs_syscall_iincdec(dev, inode, inode_p1, amount) int dummy; struct inode *ip; register int code; - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy); + code = igetinode(0, (dev_t) dev, (ino_t) inode, &ip, &dummy); if (code) { - return(code); + return (code); } if (!IS_VICEMAGIC(ip)) { - return(EPERM); + return (EPERM); } else if (ip->i_vicep1 != inode_p1) { - return(ENXIO); + return (ENXIO); } ip->i_nlink += amount; if (ip->i_nlink == 0) { @@ -330,5 +330,5 @@ afs_syscall_iincdec(dev, inode, inode_p1, amount) } ip->i_flag |= ICHG; iput(ip); - return(0); + return (0); } diff --git a/src/afs/DUX/osi_inode.h b/src/afs/DUX/osi_inode.h index ea16d3350..505528292 100644 --- a/src/afs/DUX/osi_inode.h +++ b/src/afs/DUX/osi_inode.h @@ -34,7 +34,7 @@ #define di_vicep2 di_gid #define di_vicep3a di_bcuid #define di_vicep3b di_bcgid -#define di_vicep4 di_spare[0] /* not used */ +#define di_vicep4 di_spare[0] /* not used */ #define IS_VICEMAGIC(ip) ((ip)->i_vicemagic == VICEMAGIC) #define IS_DVICEMAGIC(dp) ((dp)->di_vicemagic == VICEMAGIC) diff --git a/src/afs/DUX/osi_misc.c b/src/afs/DUX/osi_misc.c index 774ceb31b..bd3208bd5 100644 --- a/src/afs/DUX/osi_misc.c +++ b/src/afs/DUX/osi_misc.c @@ -13,12 +13,13 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_misc.c,v 1.1.1.4 2001/07/14 22:19:37 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DUX/osi_misc.c,v 1.6 2003/07/15 23:14:19 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ /* * afs_suser() returns true if the caller is superuser, false otherwise. @@ -26,11 +27,12 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_misc.c,v 1.1.1.4 2001/07/14 * Note that it must NOT set errno. */ -afs_suser() { +afs_suser() +{ int error; if ((error = suser(u.u_cred, &u.u_acflag)) == 0) { - return(1); + return (1); } - return(0); + return (0); } diff --git a/src/afs/DUX/osi_sleep.c b/src/afs/DUX/osi_sleep.c index 158771bbc..a036738c7 100644 --- a/src/afs/DUX/osi_sleep.c +++ b/src/afs/DUX/osi_sleep.c @@ -8,38 +8,40 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_sleep.c,v 1.1.1.4 2001/07/14 22:19:36 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DUX/osi_sleep.c,v 1.9 2003/07/15 23:14:19 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok); -void afs_osi_Wakeup(char *event); -void afs_osi_Sleep(char *event); static char waitV; -void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) +void +afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) { AFS_STATCNT(osi_InitWaitHandle); achandle->proc = (caddr_t) 0; } /* cancel osi_Wait */ -void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) { caddr_t proc; AFS_STATCNT(osi_CancelWait); proc = achandle->proc; - if (proc == 0) return; - achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ + if (proc == 0) + return; + achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ afs_osi_Wakeup(&waitV); } @@ -47,13 +49,14 @@ void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) * Waits for data on ahandle, or ams ms later. ahandle may be null. * Returns 0 if timeout and EINTR if signalled. */ -int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) +int +afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) { int code; afs_int32 endTime, tid; AFS_STATCNT(osi_Wait); - endTime = osi_Time() + (ams/1000); + endTime = osi_Time() + (ams / 1000); if (ahandle) ahandle->proc = (caddr_t) u.u_procp; do { @@ -61,7 +64,8 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) code = 0; code = osi_TimedSleep(&waitV, ams, aintok); - if (code) break; /* if something happened, quit now */ + if (code) + break; /* if something happened, quit now */ /* if we we're cancelled, quit now */ if (ahandle && (ahandle->proc == (caddr_t) 0)) { /* we've been signalled */ @@ -79,19 +83,20 @@ typedef struct afs_event { char *event; /* lwp event: an address */ int refcount; /* Is it in use? */ int seq; /* Sequence number: this is incremented - by wakeup calls; wait will not return until - it changes */ + * by wakeup calls; wait will not return until + * it changes */ int cond; } afs_event_t; #define HASHSIZE 128 -afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */ +afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */ #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1)); int afs_evhashcnt = 0; /* Get and initialize event structure corresponding to lwp event (i.e. address) * */ -static afs_event_t *afs_getevent(char *event) +static afs_event_t * +afs_getevent(char *event) { afs_event_t *evp, *newp = 0; int hashcode; @@ -109,7 +114,7 @@ static afs_event_t *afs_getevent(char *event) evp = evp->next; } if (!newp) { - newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t)); + newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t)); afs_evhashcnt++; newp->next = afs_evhasht[hashcode]; afs_evhasht[hashcode] = newp; @@ -124,7 +129,8 @@ static afs_event_t *afs_getevent(char *event) #define relevent(evp) ((evp)->refcount--) -void afs_osi_Sleep(char *event) +void +afs_osi_Sleep(void *event) { struct afs_event *evp; int seq; @@ -133,7 +139,7 @@ void afs_osi_Sleep(char *event) seq = evp->seq; while (seq == evp->seq) { AFS_ASSERT_GLOCK(); - assert_wait((vm_offset_t)(&evp->cond), 0); + assert_wait((vm_offset_t) (&evp->cond), 0); AFS_GUNLOCK(); thread_block(); AFS_GLOCK(); @@ -141,6 +147,13 @@ void afs_osi_Sleep(char *event) relevent(evp); } +int +afs_osi_SleepSig(void *event) +{ + afs_osi_Sleep(event); + return 0; +} + /* osi_TimedSleep * * Arguments: @@ -150,38 +163,43 @@ void afs_osi_Sleep(char *event) * * Returns 0 if timeout and EINTR if signalled. */ -static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) +static int +osi_TimedSleep(char *event, afs_int32 ams, int aintok) { int code = 0; struct afs_event *evp; int ticks; - ticks = ( ams * afs_hz )/1000; + ticks = (ams * afs_hz) / 1000; evp = afs_getevent(event); - assert_wait((vm_offset_t)(&evp->cond), aintok); + assert_wait((vm_offset_t) (&evp->cond), aintok); AFS_GUNLOCK(); thread_set_timeout(ticks); thread_block(); AFS_GLOCK(); if (current_thread()->wait_result != THREAD_AWAKENED) code = EINTR; - + relevent(evp); return code; } -void afs_osi_Wakeup(char *event) +int +afs_osi_Wakeup(void *event) { + int ret = 1; struct afs_event *evp; evp = afs_getevent(event); if (evp->refcount > 1) { - evp->seq++; - thread_wakeup((vm_offset_t)(&evp->cond)); + evp->seq++; + thread_wakeup((vm_offset_t) (&evp->cond)); + ret = 0; } relevent(evp); + return ret; } diff --git a/src/afs/DUX/osi_vfsops.c b/src/afs/DUX/osi_vfsops.c index f66430cee..83e8eadac 100644 --- a/src/afs/DUX/osi_vfsops.c +++ b/src/afs/DUX/osi_vfsops.c @@ -11,13 +11,14 @@ * osi_vfsops.c for DUX */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_vfsops.c,v 1.1.1.8 2002/08/02 04:28:50 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DUX/osi_vfsops.c,v 1.15 2003/07/15 23:14:19 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics stuff */ #include #include #include @@ -37,10 +38,8 @@ udecl_simple_lock_data(, afsmntid_lock) #define AFSMNTID_LOCK() usimple_lock(&afsmntid_lock) #define AFSMNTID_UNLOCK() usimple_unlock(&afsmntid_lock) #define AFSMNTID_LOCK_INIT() usimple_lock_init(&afsmntid_lock) - - -int mp_afs_mount(struct mount *afsp,char * path, caddr_t data, - struct nameidata *ndp) + int mp_afs_mount(struct mount *afsp, char *path, caddr_t data, + struct nameidata *ndp) { u_int size; @@ -51,7 +50,7 @@ int mp_afs_mount(struct mount *afsp,char * path, caddr_t data, AFS_GLOCK(); AFS_STATCNT(afs_mount); - if (afs_globalVFS) { /* Don't allow remounts. */ + if (afs_globalVFS) { /* Don't allow remounts. */ AFS_GUNLOCK(); return (EBUSY); } @@ -65,7 +64,7 @@ int mp_afs_mount(struct mount *afsp,char * path, caddr_t data, afsp->m_stat.f_fsid.val[1] = MOUNT_AFS; AFSMNTID_LOCK(); if (++afs_mntid == 0) - ++afs_mntid; + ++afs_mntid; AFSMNTID_UNLOCK(); BM(AFSMNTID_LOCK()); tfsid.val[0] = makedev(130, afs_mntid); @@ -73,29 +72,30 @@ int mp_afs_mount(struct mount *afsp,char * path, caddr_t data, BM(AFSMNTID_UNLOCK()); while (xmp = getvfs(&tfsid)) { - UNMOUNT_READ_UNLOCK(xmp); - tfsid.val[0]++; - AFSMNTID_LOCK(); - afs_mntid++; - AFSMNTID_UNLOCK(); + UNMOUNT_READ_UNLOCK(xmp); + tfsid.val[0]++; + AFSMNTID_LOCK(); + afs_mntid++; + AFSMNTID_UNLOCK(); } if (major(tfsid.val[0]) != 130) { AFS_GUNLOCK(); - return (ENOENT); + return (ENOENT); } afsp->m_stat.f_fsid.val[0] = tfsid.val[0]; afsp->m_stat.f_mntonname = AFS_KALLOC(MNAMELEN); - afsp->m_stat.f_mntfromname = AFS_KALLOC(MNAMELEN); - if ( !afsp->m_stat.f_mntonname || !afsp->m_stat.f_mntfromname) + afsp->m_stat.f_mntfromname = AFS_KALLOC(MNAMELEN); + if (!afsp->m_stat.f_mntonname || !afsp->m_stat.f_mntfromname) panic("malloc failure in afs_mount\n"); memset(afsp->m_stat.f_mntonname, 0, MNAMELEN); memset(afsp->m_stat.f_mntfromname, 0, MNAMELEN); - AFS_COPYINSTR(path, (caddr_t)afsp->m_stat.f_mntonname, MNAMELEN, &size, code); + AFS_COPYINSTR(path, (caddr_t) afsp->m_stat.f_mntonname, MNAMELEN, &size, + code); memcpy(afsp->m_stat.f_mntfromname, "AFS", 4); AFS_GUNLOCK(); - (void) mp_afs_statfs(afsp); + (void)mp_afs_statfs(afsp); AFS_GLOCK(); afs_vfsdev = afsp->m_stat.f_fsid.val[0]; @@ -109,7 +109,8 @@ int mp_afs_mount(struct mount *afsp,char * path, caddr_t data, } -int mp_afs_unmount (struct mount *afsp, int flag) +int +mp_afs_unmount(struct mount *afsp, int flag) { AFS_GLOCK(); AFS_STATCNT(afs_unmount); @@ -120,26 +121,32 @@ int mp_afs_unmount (struct mount *afsp, int flag) } -int mp_afs_start(struct mount *mp, int flags) +int +mp_afs_start(struct mount *mp, int flags) { - return(0); + return (0); } -int mp_afs_root (struct mount *afsp, struct vnode **avpp) +int +mp_afs_root(struct mount *afsp, struct vnode **avpp) { register afs_int32 code = 0; struct vrequest treq; - register struct vcache *tvp=0; + register struct vcache *tvp = 0; AFS_GLOCK(); AFS_STATCNT(afs_root); if (afs_globalVp && (afs_globalVp->states & CStatd)) { tvp = afs_globalVp; } else { - if (!(code = afs_InitReq(&treq, u.u_cred)) && - !(code = afs_CheckInit())) { - tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + afs_globalVp = NULL; + } + + if (!(code = afs_InitReq(&treq, u.u_cred)) + && !(code = afs_CheckInit())) { + tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); /* we really want this to stay around */ if (tvp) { afs_globalVp = tvp; @@ -152,7 +159,7 @@ int mp_afs_root (struct mount *afsp, struct vnode **avpp) AFS_GUNLOCK(); VN_HOLD(vp); VN_LOCK(vp); - vp->v_flag |= VROOT; /* No-op on Ultrix 2.2 */ + vp->v_flag |= VROOT; /* No-op on Ultrix 2.2 */ VN_UNLOCK(vp); AFS_GLOCK(); @@ -167,12 +174,13 @@ int mp_afs_root (struct mount *afsp, struct vnode **avpp) } -mp_afs_quotactl(struct mount *mp, int cmd, uid_t uid, caddr_t arg) +mp_afs_quotactl(struct mount * mp, int cmd, uid_t uid, caddr_t arg) { return EOPNOTSUPP; } -int mp_afs_statfs(struct mount *afsp) +int +mp_afs_statfs(struct mount *afsp) { struct nstatfs *abp = &afsp->m_stat; @@ -187,7 +195,7 @@ int mp_afs_statfs(struct mount *afsp) * storing something there. */ abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = - abp->f_ffree = 2000000; + abp->f_ffree = 2000000; abp->f_fsize = 1024; abp->f_fsid.val[0] = afsp->m_stat.f_fsid.val[0]; @@ -198,7 +206,8 @@ int mp_afs_statfs(struct mount *afsp) } -int mp_afs_sync(struct mount *mp, int flags) +int +mp_afs_sync(struct mount *mp, int flags) { AFS_STATCNT(afs_sync); return 0; @@ -206,14 +215,16 @@ int mp_afs_sync(struct mount *mp, int flags) #ifdef AFS_DUX50_ENV -int mp_afs_smoothsync(struct mount *mp, u_int age, u_int smsync_flag) +int +mp_afs_smoothsync(struct mount *mp, u_int age, u_int smsync_flag) { AFS_STATCNT(afs_sync); return 0; } #endif -int mp_afs_fhtovp(struct mount *afsp, struct fid *fidp, struct vnode **avcp) +int +mp_afs_fhtovp(struct mount *afsp, struct fid *fidp, struct vnode **avcp) { struct vrequest treq; register code = 0; @@ -224,7 +235,7 @@ int mp_afs_fhtovp(struct mount *afsp, struct fid *fidp, struct vnode **avcp) *avcp = NULL; if ((code = afs_InitReq(&treq, u.u_cred)) == 0) { - code = afs_osi_vget((struct vcache**)avcp, fidp, &treq); + code = afs_osi_vget((struct vcache **)avcp, fidp, &treq); } afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp, @@ -264,11 +275,12 @@ int mp_afs_fhtovp(struct mount *afsp, struct fid *fidp, struct vnode **avcp) */ #define AFS_FIDDATASIZE 8 -#define AFS_SIZEOFSMALLFID 12 /* full size of fid, including len field */ -extern int afs_NFSRootOnly; /* 1 => only allow NFS mounts of /afs. */ -int afs_fid_vnodeoverflow=0, afs_fid_uniqueoverflow=0; +#define AFS_SIZEOFSMALLFID 12 /* full size of fid, including len field */ +extern int afs_NFSRootOnly; /* 1 => only allow NFS mounts of /afs. */ +int afs_fid_vnodeoverflow = 0, afs_fid_uniqueoverflow = 0; -int mp_afs_vptofh(struct vnode *avn, struct fid *fidp) +int +mp_afs_vptofh(struct vnode *avn, struct fid *fidp) { struct SmallFid Sfid; long addr[2]; @@ -284,13 +296,14 @@ int mp_afs_vptofh(struct vnode *avn, struct fid *fidp) return EIO; } - if (afs_NFSRootOnly && (avc == afs_globalVp)) rootvp = 1; + if (afs_NFSRootOnly && (avc == afs_globalVp)) + rootvp = 1; if (!afs_NFSRootOnly || rootvp) { tcell = afs_GetCell(avc->fid.Cell, READ_LOCK); Sfid.Volume = avc->fid.Fid.Volume; fidp->fid_reserved = avc->fid.Fid.Vnode; - Sfid.CellAndUnique = ((tcell->cellIndex << 24) + - (avc->fid.Fid.Unique & 0xffffff)); + Sfid.CellAndUnique = + ((tcell->cellIndex << 24) + (avc->fid.Fid.Unique & 0xffffff)); afs_PutCell(tcell, READ_LOCK); if (avc->fid.Fid.Vnode > 0xffff) afs_fid_vnodeoverflow++; @@ -308,26 +321,27 @@ int mp_afs_vptofh(struct vnode *avn, struct fid *fidp) fidp->fid_len = AFS_SIZEOFSMALLFID; if (afs_NFSRootOnly) { if (rootvp) { - memcpy(fidp->fid_data, (caddr_t)&Sfid, AFS_FIDDATASIZE); + memcpy(fidp->fid_data, (caddr_t) & Sfid, AFS_FIDDATASIZE); } else { - memcpy(fidp->fid_data, (caddr_t)addr, AFS_FIDDATASIZE); + memcpy(fidp->fid_data, (caddr_t) addr, AFS_FIDDATASIZE); } } else { - memcpy(fidp->fid_data, (caddr_t)&Sfid, AFS_FIDDATASIZE); + memcpy(fidp->fid_data, (caddr_t) & Sfid, AFS_FIDDATASIZE); } AFS_GUNLOCK(); return 0; } -int mp_Afs_init(void); /* vfs_init - defined below */ +int mp_Afs_init(void); /* vfs_init - defined below */ /* This is only called by vfs_mount when afs is going to be mounted as root. * Since we don't support diskless clients we shouldn't come here. */ -int afsmountroot=0; -int mp_afs_mountroot(struct mount *afsp, struct vnode **vp) +int afsmountroot = 0; +int +mp_afs_mountroot(struct mount *afsp, struct vnode **vp) { AFS_GLOCK(); AFS_STATCNT(afs_mountroot); @@ -340,8 +354,9 @@ int mp_afs_mountroot(struct mount *afsp, struct vnode **vp) /* It's called to setup swapping over the net for diskless clients; again * not for us. */ -int afsswapvp=0; -int mp_afs_swapvp(void) +int afsswapvp = 0; +int +mp_afs_swapvp(void) { AFS_GLOCK(); AFS_STATCNT(afs_swapvp); @@ -359,7 +374,7 @@ struct vfsops afs_vfsops = { mp_afs_quotactl, mp_afs_statfs, mp_afs_sync, - mp_afs_fhtovp, /* afs_vget */ + mp_afs_fhtovp, /* afs_vget */ mp_afs_vptofh, mp_Afs_init, mp_afs_mountroot, @@ -375,16 +390,16 @@ struct vfsops afs_vfsops = { */ #define NULL_FUNC (int (*)(int))0 -int (*afs_syscall_func)() = NULL_FUNC; -int (*afs_xsetgroups_func)() = NULL_FUNC; -int (*afs_xioctl_func)() = NULL_FUNC; +int (*afs_syscall_func) () = NULL_FUNC; +int (*afs_xsetgroups_func) () = NULL_FUNC; +int (*afs_xioctl_func) () = NULL_FUNC; afssyscall(p, args, retval) - struct proc *p; - void *args; - long *retval; + struct proc *p; + void *args; + long *retval; { - int (*func)(); + int (*func) (); int code; AFS_GLOCK(); @@ -392,18 +407,18 @@ afssyscall(p, args, retval) if (func == NULL_FUNC) { code = nosys(p, args, retval); } else { - code = (*func)(p, args, retval); + code = (*func) (p, args, retval); } AFS_GUNLOCK(); return code; } afsxsetgroups(p, args, retval) - struct proc *p; - void *args; - long *retval; + struct proc *p; + void *args; + long *retval; { - int (*func)(); + int (*func) (); int code; AFS_GLOCK(); @@ -411,18 +426,18 @@ afsxsetgroups(p, args, retval) if (func == NULL_FUNC) { code = nosys(p, args, retval); } else { - code = (*func)(p, args, retval); + code = (*func) (p, args, retval); } AFS_GUNLOCK(); return code; } afsxioctl(p, args, retval) - struct proc *p; - void *args; - long *retval; + struct proc *p; + void *args; + long *retval; { - int (*func)(); + int (*func) (); int code; AFS_GLOCK(); @@ -430,7 +445,7 @@ afsxioctl(p, args, retval) if (func == NULL_FUNC) { code = nosys(p, args, retval); } else { - code = (*func)(p, args, retval); + code = (*func) (p, args, retval); } AFS_GUNLOCK(); return code; @@ -447,15 +462,16 @@ afs_unconfig() } -cfg_subsys_attr_t afs_attributes[] = { +cfg_subsys_attr_t afs_attributes[] = { {"", 0, 0, 0, 0, 0, 0} /* must be the last element */ }; -afs_configure(cfg_op_t op, caddr_t indata, size_t indata_size, caddr_t outdata, size_t outdata_size) +afs_configure(cfg_op_t op, caddr_t indata, size_t indata_size, + caddr_t outdata, size_t outdata_size) { - cfg_attr_t *attributes; - int ret = ESUCCESS; - int i, j, size; + cfg_attr_t *attributes; + int ret = ESUCCESS; + int i, j, size; caddr_t p; switch (op) { @@ -465,11 +481,11 @@ afs_configure(cfg_op_t op, caddr_t indata, size_t indata_size, caddr_t outdata, * indata_size is the count of attributes. */ if ((ret = vfssw_add_fsname(MOUNT_AFS, &afs_vfsops, "afs")) != 0) - return(ret); + return (ret); break; case CFG_OP_UNCONFIGURE: if ((ret = afs_unconfig()) != 0) - return(ret); + return (ret); break; default: ret = EINVAL; @@ -479,22 +495,22 @@ afs_configure(cfg_op_t op, caddr_t indata, size_t indata_size, caddr_t outdata, } -int mp_Afs_init(void) +int +mp_Afs_init(void) { extern int Afs_xsetgroups(), afs_xioctl(), afs3_syscall(); - + AFS_GLOCK(); - ((struct sysent *) (&sysent[AFS_SYSCALL]))->sy_call = afs3_syscall; + ((struct sysent *)(&sysent[AFS_SYSCALL]))->sy_call = afs3_syscall; #ifdef SY_NARG - ((struct sysent *) (&sysent[AFS_SYSCALL]))->sy_info = 6; + ((struct sysent *)(&sysent[AFS_SYSCALL]))->sy_info = 6; #else - ((struct sysent *) (&sysent[AFS_SYSCALL]))->sy_parallel = 0; - ((struct sysent *) (&sysent[AFS_SYSCALL]))->sy_narg = 6; + ((struct sysent *)(&sysent[AFS_SYSCALL]))->sy_parallel = 0; + ((struct sysent *)(&sysent[AFS_SYSCALL]))->sy_narg = 6; #endif - ((struct sysent *) (&sysent[SYS_setgroups]))->sy_call = - Afs_xsetgroups; - afs_xioctl_func = afsxioctl; + ((struct sysent *)(&sysent[SYS_setgroups]))->sy_call = Afs_xsetgroups; + afs_xioctl_func = afsxioctl; afs_xsetgroups_func = afsxsetgroups; afs_syscall_func = afssyscall; AFS_GUNLOCK(); diff --git a/src/afs/DUX/osi_vm.c b/src/afs/DUX/osi_vm.c index 4a635cac6..d41afc844 100644 --- a/src/afs/DUX/osi_vm.c +++ b/src/afs/DUX/osi_vm.c @@ -8,13 +8,14 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_vm.c,v 1.1.1.5 2002/05/10 23:43:40 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DUX/osi_vm.c,v 1.8 2003/07/15 23:14:19 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ #include #include @@ -35,9 +36,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_vm.c,v 1.1.1.5 2002/05/10 2 * OSF/1 Locking: VN_LOCK has been called. */ int -osi_VM_FlushVCache(avc, slept) - struct vcache *avc; - int *slept; +osi_VM_FlushVCache(struct vcache *avc, int *slept) { if (avc->vrefCount > 1) return EBUSY; @@ -82,18 +81,17 @@ osi_VM_FlushVCache(avc, slept) * * Called with the global lock NOT held. */ -void -osi_ubc_flush_dirty_and_wait(vp, flags) -struct vnode *vp; -int flags; { +static void +osi_ubc_flush_dirty_and_wait(struct vnode *vp, int flags) +{ int retry; vm_page_t pp; int first; do { - struct vm_ubc_object* vop; - vop = (struct vm_ubc_object*)(vp->v_object); - ubc_flush_dirty(vop, flags); + struct vm_ubc_object *vop; + vop = (struct vm_ubc_object *)(vp->v_object); + ubc_flush_dirty(vop, flags); vm_object_lock(vop); if (vop->vu_dirtypl) @@ -108,14 +106,15 @@ int flags; { if (pp->pg_busy) { retry = 1; pp->pg_wait = 1; - assert_wait_mesg((vm_offset_t)pp, FALSE, "pg_wait"); + assert_wait_mesg((vm_offset_t) pp, FALSE, "pg_wait"); vm_object_unlock(vop); thread_block(); break; } } } - if (retry) continue; + if (retry) + continue; } vm_object_unlock(vop); } while (retry); @@ -127,14 +126,13 @@ int flags; { * re-obtained. */ void -osi_VM_StoreAllSegments(avc) - struct vcache *avc; +osi_VM_StoreAllSegments(struct vcache *avc) { ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); osi_ubc_flush_dirty_and_wait(AFSTOV(avc), 0); AFS_GLOCK(); - ObtainWriteLock(&avc->lock,94); + ObtainWriteLock(&avc->lock, 94); } /* Try to invalidate pages, for "fs flush" or "fs flushv"; or @@ -147,17 +145,14 @@ osi_VM_StoreAllSegments(avc) * be some pages around when we return, newly created by concurrent activity. */ void -osi_VM_TryToSmush(avc, acred, sync) - struct vcache *avc; - struct AFS_UCRED *acred; - int sync; +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); osi_ubc_flush_dirty_and_wait(AFSTOV(avc), 0); ubc_invalidate(AFSTOV(avc)->v_object, 0, 0, B_INVAL); AFS_GLOCK(); - ObtainWriteLock(&avc->lock,59); + ObtainWriteLock(&avc->lock, 59); } /* Purge VM for a file when its callback is revoked. @@ -165,9 +160,7 @@ osi_VM_TryToSmush(avc, acred, sync) * Locking: No lock is held, not even the global lock. */ void -osi_VM_FlushPages(avc, credp) - struct vcache *avc; - struct AFS_UCRED *credp; +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { ubc_flush_dirty(AFSTOV(avc)->v_object, 0); ubc_invalidate(AFSTOV(avc)->v_object, 0, 0, B_INVAL); @@ -180,11 +173,7 @@ osi_VM_FlushPages(avc, credp) * it only works on Solaris. */ void -osi_VM_Truncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { - ubc_invalidate(AFSTOV(avc)->v_object, alen, - MAXINT - alen, B_INVAL); + ubc_invalidate(AFSTOV(avc)->v_object, alen, MAXINT - alen, B_INVAL); } diff --git a/src/afs/DUX/osi_vnodeops.c b/src/afs/DUX/osi_vnodeops.c index c14e967a0..543a6453a 100644 --- a/src/afs/DUX/osi_vnodeops.c +++ b/src/afs/DUX/osi_vnodeops.c @@ -12,19 +12,20 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/DUX/osi_vnodeops.c,v 1.1.1.7 2002/09/26 18:58:07 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/DUX/osi_vnodeops.c,v 1.11 2003/07/15 23:14:19 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ #include #include -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern int afs_lookup(), afs_create(), afs_noop(), afs_open(), afs_close(); @@ -48,48 +49,48 @@ int mp_afs_ioctl(); /* AFS vnodeops */ struct vnodeops Afs_vnodeops = { - mp_afs_lookup, - mp_afs_create, - afs_noop, /* vn_mknod */ - mp_afs_open, - mp_afs_close, - mp_afs_access, - mp_afs_getattr, - mp_afs_setattr, - mp_afs_ubcrdwr, - mp_afs_ubcrdwr, - mp_afs_ioctl, /* vn_ioctl */ - seltrue, /* vn_select */ - mp_afs_mmap, - mp_afs_fsync, - mp_afs_seek, - mp_afs_remove, - mp_afs_link, - mp_afs_rename, - mp_afs_mkdir, - mp_afs_rmdir, - mp_afs_symlink, - mp_afs_readdir, - mp_afs_readlink, - mp_afs_abortop, - mp_afs_inactive, - mp_afs_reclaim, - mp_afs_bmap, - mp_afs_strategy, - mp_afs_print, - mp_afs_page_read, - mp_afs_page_write, - mp_afs_swap, - mp_afs_bread, - mp_afs_brelse, - mp_afs_lockctl, - mp_afs_syncdata, - afs_noop, /* Lock */ - afs_noop, /* unLock */ - afs_noop, /* get ext attrs */ - afs_noop, /* set ext attrs */ - afs_noop, /* del ext attrs */ - vn_pathconf_default, + mp_afs_lookup, + mp_afs_create, + afs_noop, /* vn_mknod */ + mp_afs_open, + mp_afs_close, + mp_afs_access, + mp_afs_getattr, + mp_afs_setattr, + mp_afs_ubcrdwr, + mp_afs_ubcrdwr, + mp_afs_ioctl, /* vn_ioctl */ + seltrue, /* vn_select */ + mp_afs_mmap, + mp_afs_fsync, + mp_afs_seek, + mp_afs_remove, + mp_afs_link, + mp_afs_rename, + mp_afs_mkdir, + mp_afs_rmdir, + mp_afs_symlink, + mp_afs_readdir, + mp_afs_readlink, + mp_afs_abortop, + mp_afs_inactive, + mp_afs_reclaim, + mp_afs_bmap, + mp_afs_strategy, + mp_afs_print, + mp_afs_page_read, + mp_afs_page_write, + mp_afs_swap, + mp_afs_bread, + mp_afs_brelse, + mp_afs_lockctl, + mp_afs_syncdata, + afs_noop, /* Lock */ + afs_noop, /* unLock */ + afs_noop, /* get ext attrs */ + afs_noop, /* set ext attrs */ + afs_noop, /* del ext attrs */ + vn_pathconf_default, }; struct vnodeops *afs_ops = &Afs_vnodeops; @@ -109,8 +110,8 @@ struct fileops afs_fileops = { }; mp_afs_lookup(adp, ndp) - struct vcache *adp; - struct nameidata *ndp; + struct vcache *adp; + struct nameidata *ndp; { int code; AFS_GLOCK(); @@ -120,8 +121,8 @@ mp_afs_lookup(adp, ndp) } mp_afs_create(ndp, attrs) - struct nameidata *ndp; - struct vattr *attrs; + struct nameidata *ndp; + struct vattr *attrs; { int code; AFS_GLOCK(); @@ -131,9 +132,9 @@ mp_afs_create(ndp, attrs) } mp_afs_open(avcp, aflags, acred) - struct vcache **avcp; - afs_int32 aflags; - struct AFS_UCRED *acred; + struct vcache **avcp; + afs_int32 aflags; + struct AFS_UCRED *acred; { int code; AFS_GLOCK(); @@ -143,9 +144,9 @@ mp_afs_open(avcp, aflags, acred) } mp_afs_access(avc, amode, acred) - struct vcache *avc; - afs_int32 amode; - struct AFS_UCRED *acred; + struct vcache *avc; + afs_int32 amode; + struct AFS_UCRED *acred; { int code; AFS_GLOCK(); @@ -155,9 +156,9 @@ mp_afs_access(avc, amode, acred) } mp_afs_close(avc, flags, cred) - struct vnode *avc; - int flags; - struct ucred *cred; + struct vnode *avc; + int flags; + struct ucred *cred; { int code; AFS_GLOCK(); @@ -167,9 +168,9 @@ mp_afs_close(avc, flags, cred) } mp_afs_getattr(avc, attrs, acred) - struct vcache *avc; - struct vattr *attrs; - struct AFS_UCRED *acred; + struct vcache *avc; + struct vattr *attrs; + struct AFS_UCRED *acred; { int code; AFS_GLOCK(); @@ -179,9 +180,9 @@ mp_afs_getattr(avc, attrs, acred) } mp_afs_setattr(avc, attrs, acred) - struct vcache *avc; - struct vattr *attrs; - struct AFS_UCRED *acred; + struct vcache *avc; + struct vattr *attrs; + struct AFS_UCRED *acred; { int code; AFS_GLOCK(); @@ -191,10 +192,10 @@ mp_afs_setattr(avc, attrs, acred) } mp_afs_fsync(avc, fflags, acred, waitfor) - struct vcache *avc; - int fflags; - struct AFS_UCRED *acred; - int waitfor; + struct vcache *avc; + int fflags; + struct AFS_UCRED *acred; + int waitfor; { int code; AFS_GLOCK(); @@ -204,7 +205,7 @@ mp_afs_fsync(avc, fflags, acred, waitfor) } mp_afs_remove(ndp) - struct nameidata *ndp; + struct nameidata *ndp; { int code; AFS_GLOCK(); @@ -214,8 +215,8 @@ mp_afs_remove(ndp) } mp_afs_link(avc, ndp) - struct vcache *avc; - struct nameidata *ndp; + struct vcache *avc; + struct nameidata *ndp; { int code; AFS_GLOCK(); @@ -225,7 +226,7 @@ mp_afs_link(avc, ndp) } mp_afs_rename(fndp, tndp) - struct nameidata *fndp, *tndp; + struct nameidata *fndp, *tndp; { int code; AFS_GLOCK(); @@ -235,8 +236,8 @@ mp_afs_rename(fndp, tndp) } mp_afs_mkdir(ndp, attrs) - struct nameidata *ndp; - struct vattr *attrs; + struct nameidata *ndp; + struct vattr *attrs; { int code; AFS_GLOCK(); @@ -246,7 +247,7 @@ mp_afs_mkdir(ndp, attrs) } mp_afs_rmdir(ndp) - struct nameidata *ndp; + struct nameidata *ndp; { int code; AFS_GLOCK(); @@ -256,9 +257,9 @@ mp_afs_rmdir(ndp) } mp_afs_symlink(ndp, attrs, atargetName) - struct nameidata *ndp; - struct vattr *attrs; - register char *atargetName; + struct nameidata *ndp; + struct vattr *attrs; + register char *atargetName; { int code; AFS_GLOCK(); @@ -268,10 +269,10 @@ mp_afs_symlink(ndp, attrs, atargetName) } mp_afs_readdir(avc, auio, acred, eofp) - struct vcache *avc; - struct uio *auio; - struct AFS_UCRED *acred; - int *eofp; + struct vcache *avc; + struct uio *auio; + struct AFS_UCRED *acred; + int *eofp; { int code; AFS_GLOCK(); @@ -281,9 +282,9 @@ mp_afs_readdir(avc, auio, acred, eofp) } mp_afs_readlink(avc, auio, acred) - struct vcache *avc; - struct uio *auio; - struct AFS_UCRED *acred; + struct vcache *avc; + struct uio *auio; + struct AFS_UCRED *acred; { int code; AFS_GLOCK(); @@ -293,12 +294,12 @@ mp_afs_readlink(avc, auio, acred) } mp_afs_lockctl(avc, af, flag, acred, clid, offset) - struct vcache *avc; - struct eflock *af; - struct AFS_UCRED *acred; - int flag; - pid_t clid; - off_t offset; + struct vcache *avc; + struct eflock *af; + struct AFS_UCRED *acred; + int flag; + pid_t clid; + off_t offset; { int code; AFS_GLOCK(); @@ -308,7 +309,7 @@ mp_afs_lockctl(avc, af, flag, acred, clid, offset) } mp_afs_closex(afd) - struct file *afd; + struct file *afd; { int code; AFS_GLOCK(); @@ -318,25 +319,25 @@ mp_afs_closex(afd) } mp_afs_seek(avc, oldoff, newoff, cred) - struct vcache *avc; - off_t oldoff, newoff; - struct ucred *cred; + struct vcache *avc; + off_t oldoff, newoff; + struct ucred *cred; { - if ((int) newoff < 0) - return(EINVAL); + if ((int)newoff < 0) + return (EINVAL); else - return(0); + return (0); } mp_afs_abortop(ndp) - struct nameidata *ndp; + struct nameidata *ndp; { - return(0); + return (0); } mp_afs_inactive(avc, acred) - register struct vcache *avc; - struct AFS_UCRED *acred; + register struct vcache *avc; + struct AFS_UCRED *acred; { AFS_GLOCK(); afs_InactiveVCache(avc, acred); @@ -345,21 +346,21 @@ mp_afs_inactive(avc, acred) mp_afs_reclaim(avc) - struct vcache *avc; + struct vcache *avc; { - return(0); + return (0); } mp_afs_print(avc) - struct vcache *avc; + struct vcache *avc; { - return(0); + return (0); } mp_afs_page_read(avc, uio, acred) - struct vcache *avc; - struct uio *uio; - struct ucred *acred; + struct vcache *avc; + struct uio *uio; + struct ucred *acred; { int error; struct vrequest treq; @@ -367,26 +368,26 @@ mp_afs_page_read(avc, uio, acred) AFS_GLOCK(); error = afs_rdwr(avc, uio, UIO_READ, 0, acred); afs_Trace3(afs_iclSetp, CM_TRACE_PAGE_READ, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, error, ICL_TYPE_INT32, avc->states); + ICL_TYPE_INT32, error, ICL_TYPE_INT32, avc->states); if (error) { error = EIO; } else if ((avc->states & CWired) == 0) { afs_InitReq(&treq, acred); - ObtainWriteLock(&avc->lock,161); + ObtainWriteLock(&avc->lock, 161); afs_Wire(avc, &treq); ReleaseWriteLock(&avc->lock); } AFS_GUNLOCK(); - return(error); + return (error); } mp_afs_page_write(avc, uio, acred, pager, offset) - struct vcache *avc; - struct uio *uio; - struct ucred *acred; - memory_object_t pager; - vm_offset_t offset; + struct vcache *avc; + struct uio *uio; + struct ucred *acred; + memory_object_t pager; + vm_offset_t offset; { int error; @@ -398,20 +399,20 @@ mp_afs_page_write(avc, uio, acred, pager, offset) error = EIO; } AFS_GUNLOCK(); - return(error); + return (error); } -int DO_FLUSH=1; +int DO_FLUSH = 1; mp_afs_ubcrdwr(avc, uio, ioflag, cred) - struct vcache *avc; - struct uio *uio; - int ioflag; - struct ucred *cred; + struct vcache *avc; + struct uio *uio; + int ioflag; + struct ucred *cred; { register afs_int32 code; register char *data; - afs_int32 fileBase, size, cnt=0; + afs_int32 fileBase, size, cnt = 0; afs_int32 pageBase; register afs_int32 tsize; register afs_int32 pageOffset; @@ -419,26 +420,26 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) struct vrequest treq; int rw = uio->uio_rw; int rv, flags; - int newpage=0; + int newpage = 0; vm_page_t page; afs_int32 save_resid; struct dcache *tdc; - int didFakeOpen=0; - int counter=0; + int didFakeOpen = 0; + int counter = 0; AFS_GLOCK(); afs_InitReq(&treq, cred); if (AFS_NFSXLATORREQ(cred) && rw == UIO_READ) { - if (!afs_AccessOK(avc, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) { + if (!afs_AccessOK + (avc, PRSFS_READ, &treq, + CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) { AFS_GUNLOCK(); return EACCES; } } afs_Trace4(afs_iclSetp, CM_TRACE_VMRW, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, (rw==UIO_WRITE? 1 : 0), - ICL_TYPE_LONG, uio->uio_offset, - ICL_TYPE_LONG, uio->uio_resid); + ICL_TYPE_INT32, (rw == UIO_WRITE ? 1 : 0), ICL_TYPE_LONG, + uio->uio_offset, ICL_TYPE_LONG, uio->uio_resid); code = afs_VerifyVCache(avc, &treq); if (code) { code = afs_CheckCode(code, &treq, 35); @@ -447,25 +448,26 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) } if (vType(avc) != VREG) { AFS_GUNLOCK(); - return EISDIR; /* can't read or write other things */ + return EISDIR; /* can't read or write other things */ } afs_BozonLock(&avc->pvnLock, avc); osi_FlushPages(avc, cred); /* hold bozon lock, but not basic vnode lock */ - ObtainWriteLock(&avc->lock,162); + ObtainWriteLock(&avc->lock, 162); /* adjust parameters when appending files */ if ((ioflag & IO_APPEND) && uio->uio_rw == UIO_WRITE) uio->uio_offset = avc->m.Length; /* write at EOF position */ if (uio->uio_rw == UIO_WRITE) { avc->states |= CDirty; afs_FakeOpen(avc); - didFakeOpen=1; + didFakeOpen = 1; /* * before starting any I/O, we must ensure that the file is big enough * to hold the results (since afs_putpage will be called to force * the I/O. */ size = uio->afsio_resid + uio->afsio_offset; /* new file size */ - if (size > avc->m.Length) avc->m.Length = size; /* file grew */ + if (size > avc->m.Length) + avc->m.Length = size; /* file grew */ avc->m.Date = osi_Time(); /* Set file date (for ranlib) */ if (uio->afsio_resid > PAGE_SIZE) cnt = uio->afsio_resid / PAGE_SIZE; @@ -477,26 +479,29 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) * compute the amount of data to move into this block, * based on uio->afsio_resid. */ - size = uio->afsio_resid; /* transfer size */ - fileBase = uio->afsio_offset; /* start file position */ - pageBase = fileBase & ~(PAGE_SIZE-1); /* file position of the page */ - pageOffset = fileBase & (PAGE_SIZE-1); /* start offset within page */ - tsize = PAGE_SIZE-pageOffset; /* amount left in this page */ + size = uio->afsio_resid; /* transfer size */ + fileBase = uio->afsio_offset; /* start file position */ + pageBase = fileBase & ~(PAGE_SIZE - 1); /* file position of the page */ + pageOffset = fileBase & (PAGE_SIZE - 1); /* start offset within page */ + tsize = PAGE_SIZE - pageOffset; /* amount left in this page */ /* * we'll read tsize bytes, * but first must make sure tsize isn't too big */ - if (tsize > size) tsize = size; /* don't read past end of request */ - eof = 0; /* flag telling us if we hit the EOF on the read */ + if (tsize > size) + tsize = size; /* don't read past end of request */ + eof = 0; /* flag telling us if we hit the EOF on the read */ if (uio->uio_rw == UIO_READ) { /* we're doing a read operation */ /* don't read past EOF */ if (tsize + fileBase > avc->m.Length) { tsize = avc->m.Length - fileBase; eof = 1; /* we did hit the EOF */ - if (tsize < 0) tsize = 0; /* better safe than sorry */ + if (tsize < 0) + tsize = 0; /* better safe than sorry */ } } - if (tsize <= 0) break; /* nothing to transfer, we're done */ + if (tsize <= 0) + break; /* nothing to transfer, we're done */ /* Purge dirty chunks of file if there are too many dirty chunks. * Inside the write loop, we only do this at a chunk boundary. @@ -516,28 +521,32 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); #ifdef AFS_DUX50_ENV - code = ubc_lookup(AFSTOV(avc)->v_object, pageBase, - PAGE_SIZE, PAGE_SIZE, &page, &flags, NULL); + code = + ubc_lookup(AFSTOV(avc)->v_object, pageBase, PAGE_SIZE, PAGE_SIZE, + &page, &flags, NULL); #else - code = ubc_lookup(AFSTOV(avc)->v_object, pageBase, - PAGE_SIZE, PAGE_SIZE, &page, &flags); + code = + ubc_lookup(AFSTOV(avc)->v_object, pageBase, PAGE_SIZE, PAGE_SIZE, + &page, &flags); #endif AFS_GLOCK(); - ObtainWriteLock(&avc->lock,163); + ObtainWriteLock(&avc->lock, 163); if (code) { break; } if (flags & B_NOCACHE) { /* - No page found. We should not read the page in if - 1. the write starts on a page edge (ie, pageoffset == 0) - and either - 1. we will fill the page (ie, size == PAGESIZE), or - 2. we are writing past eof + * No page found. We should not read the page in if + * 1. the write starts on a page edge (ie, pageoffset == 0) + * and either + * 1. we will fill the page (ie, size == PAGESIZE), or + * 2. we are writing past eof */ - if ((uio->uio_rw == UIO_WRITE) && - ((pageOffset == 0 && (size == PAGE_SIZE || fileBase >= avc->m.Length)))) { + if ((uio->uio_rw == UIO_WRITE) + && + ((pageOffset == 0 + && (size == PAGE_SIZE || fileBase >= avc->m.Length)))) { struct vnode *vp = AFSTOV(avc); /* we're doing a write operation past eof; no need to read it */ newpage = 1; @@ -557,13 +566,13 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) bp->b_blkno = btodb(pageBase); ReleaseWriteLock(&avc->lock); code = afs_ustrategy(bp, cred); /* do the I/O */ - ObtainWriteLock(&avc->lock,164); + ObtainWriteLock(&avc->lock, 164); AFS_GUNLOCK(); ubc_sync_iodone(bp); AFS_GLOCK(); if (code) { AFS_GUNLOCK(); - ubc_page_release(page, 0); + ubc_page_release(page, 0); AFS_GLOCK(); break; } @@ -571,53 +580,53 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) } AFS_GUNLOCK(); ubc_page_wait(page); - data = ubc_load(page, pageOffset, page_size); + data = ubc_load(page, pageOffset, page_size); AFS_GLOCK(); ReleaseWriteLock(&avc->lock); /* uiomove may page fault */ AFS_GUNLOCK(); - code = uiomove(data+pageOffset, tsize, uio); + code = uiomove(data + pageOffset, tsize, uio); ubc_unload(page, pageOffset, page_size); if (uio->uio_rw == UIO_WRITE) { - vm_offset_t toffset; - - /* Mark the page dirty and release it to avoid a deadlock - * in ubc_dirty_kluster when more than one process writes - * this page at the same time. */ - toffset = page->pg_offset; - flags |= B_DIRTY; - ubc_page_release(page, flags); - - if (cnt > 10) { - vm_page_t pl; - int kpcnt; - struct buf *bp; - - /* We released the page, so we can get a null page - * list if another thread calls the strategy routine. - */ - pl = ubc_dirty_kluster(AFSTOV(avc)->v_object, - NULL, toffset, 0, B_WANTED, FALSE, &kpcnt); - if (pl) { - bp = ubc_bufalloc(pl, 1, PAGE_SIZE, 1, B_WRITE); - bp->b_dev = 0; - bp->b_vp = AFSTOV(avc); - bp->b_blkno = btodb(pageBase); + vm_offset_t toffset; + + /* Mark the page dirty and release it to avoid a deadlock + * in ubc_dirty_kluster when more than one process writes + * this page at the same time. */ + toffset = page->pg_offset; + flags |= B_DIRTY; + ubc_page_release(page, flags); + + if (cnt > 10) { + vm_page_t pl; + int kpcnt; + struct buf *bp; + + /* We released the page, so we can get a null page + * list if another thread calls the strategy routine. + */ + pl = ubc_dirty_kluster(AFSTOV(avc)->v_object, NULL, toffset, + 0, B_WANTED, FALSE, &kpcnt); + if (pl) { + bp = ubc_bufalloc(pl, 1, PAGE_SIZE, 1, B_WRITE); + bp->b_dev = 0; + bp->b_vp = AFSTOV(avc); + bp->b_blkno = btodb(pageBase); + AFS_GLOCK(); + code = afs_ustrategy(bp, cred); /* do the I/O */ + AFS_GUNLOCK(); + ubc_sync_iodone(bp); + if (code) { AFS_GLOCK(); - code = afs_ustrategy(bp, cred); /* do the I/O */ - AFS_GUNLOCK(); - ubc_sync_iodone(bp); - if (code) { - AFS_GLOCK(); - ObtainWriteLock(&avc->lock,415); - break; - } + ObtainWriteLock(&avc->lock, 415); + break; } } + } } else { ubc_page_release(page, flags); } AFS_GLOCK(); - ObtainWriteLock(&avc->lock,165); + ObtainWriteLock(&avc->lock, 165); /* * If reading at a chunk boundary, start prefetch of next chunk. */ @@ -625,13 +634,14 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) && (counter == 0 || AFS_CHUNKOFFSET(fileBase) == 0)) { tdc = afs_FindDCache(avc, fileBase); if (tdc) { - if (!(tdc->flags & DFNextStarted)) + if (!(tdc->mflags & DFNextStarted)) afs_PrefetchChunk(avc, tdc, cred, &treq); afs_PutDCache(tdc); } } counter++; - if (code) break; + if (code) + break; } if (didFakeOpen) afs_FakeClose(avc, cred); @@ -642,7 +652,7 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) afs_BozonUnlock(&avc->pvnLock, avc); if (DO_FLUSH || (!newpage && (cnt < 10))) { AFS_GUNLOCK(); - ubc_flush_dirty(AFSTOV(avc)->v_object, flags); + ubc_flush_dirty(AFSTOV(avc)->v_object, flags); AFS_GLOCK(); } @@ -668,7 +678,7 @@ mp_afs_ubcrdwr(avc, uio, ioflag, cred) && !AFS_NFSXLATORREQ(cred)) { code = afs_fsync(avc, 0, cred, 0); } -out: + out: code = afs_CheckCode(code, &treq, 36); AFS_GUNLOCK(); return code; @@ -678,7 +688,7 @@ int mp_afs_ioctl(struct vnode *vp, int com, caddr_t data, int fflag, struct ucred *cred, int *retval) { - return ENOSYS; + return ENOSYS; } /* @@ -690,15 +700,15 @@ mp_afs_ioctl(struct vnode *vp, int com, caddr_t data, int fflag, */ mp_afs_mmap(avc, offset, map, addrp, len, prot, maxprot, flags, cred) - register struct vcache *avc; - vm_offset_t offset; - vm_map_t map; - vm_offset_t *addrp; - vm_size_t len; - vm_prot_t prot; - vm_prot_t maxprot; - int flags; - struct ucred *cred; + register struct vcache *avc; + vm_offset_t offset; + vm_map_t map; + vm_offset_t *addrp; + vm_size_t len; + vm_prot_t prot; + vm_prot_t maxprot; + int flags; + struct ucred *cred; { struct vp_mmap_args args; register struct vp_mmap_args *ap = &args; @@ -713,21 +723,20 @@ mp_afs_mmap(avc, offset, map, addrp, len, prot, maxprot, flags, cred) afs_InitReq(&treq, cred); code = afs_VerifyVCache(avc, &treq); if (code) { - code = afs_CheckCode(code, &treq, 37); - AFS_GUNLOCK(); - return code; + code = afs_CheckCode(code, &treq, 37); + AFS_GUNLOCK(); + return code; } afs_BozonLock(&avc->pvnLock, avc); osi_FlushPages(avc, cred); /* ensure old pages are gone */ afs_BozonUnlock(&avc->pvnLock, avc); - ObtainWriteLock(&avc->lock,166); + ObtainWriteLock(&avc->lock, 166); avc->states |= CMAPPED; ReleaseWriteLock(&avc->lock); ap->a_offset = offset; ap->a_vaddr = addrp; ap->a_size = len; - ap->a_prot = prot, - ap->a_maxprot = maxprot; + ap->a_prot = prot, ap->a_maxprot = maxprot; ap->a_flags = flags; AFS_GUNLOCK(); code = u_vp_create(map, vp->v_object, (vm_offset_t) ap); @@ -738,27 +747,28 @@ mp_afs_mmap(avc, offset, map, addrp, len, prot, maxprot, flags, cred) } -int mp_afs_getpage(vop, offset, len, protp, pl, plsz, +int +mp_afs_getpage(vop, offset, len, protp, pl, plsz, #ifdef AFS_DUX50_ENV - policy, + policy, #else - mape, addr, + mape, addr, #endif - rw, cred) - vm_ubc_object_t vop; - vm_offset_t offset; - vm_size_t len; - vm_prot_t *protp; - vm_page_t *pl; - int plsz; + rw, cred) + vm_ubc_object_t vop; + vm_offset_t offset; + vm_size_t len; + vm_prot_t *protp; + vm_page_t *pl; + int plsz; #ifdef AFS_DUX50_ENV - struct vm_policy *policy; + struct vm_policy *policy; #else - vm_map_entry_t mape; - vm_offset_t addr; + vm_map_entry_t mape; + vm_offset_t addr; #endif - int rw; - struct ucred *cred; + int rw; + struct ucred *cred; { register afs_int32 code; struct vrequest treq; @@ -767,7 +777,7 @@ int mp_afs_getpage(vop, offset, len, protp, pl, plsz, vm_page_t *pagep; vm_offset_t off; - struct vcache *avc = VTOAFS(vop->vu_vp); + struct vcache *avc = VTOAFS(vop->vu_vp); /* first, obtain the proper lock for the VM system */ @@ -776,42 +786,45 @@ int mp_afs_getpage(vop, offset, len, protp, pl, plsz, code = afs_VerifyVCache(avc, &treq); if (code) { *pl = VM_PAGE_NULL; - code = afs_CheckCode(code, &treq, 39); /* failed to get it */ + code = afs_CheckCode(code, &treq, 39); /* failed to get it */ AFS_GUNLOCK(); return code; } - + /* clean all dirty pages for this vnode */ AFS_GUNLOCK(); - ubc_flush_dirty(vop,0); + ubc_flush_dirty(vop, 0); AFS_GLOCK(); afs_BozonLock(&avc->pvnLock, avc); - ObtainWriteLock(&avc->lock,167); + ObtainWriteLock(&avc->lock, 167); afs_Trace4(afs_iclSetp, CM_TRACE_PAGEIN, ICL_TYPE_POINTER, avc, - ICL_TYPE_LONG, offset, ICL_TYPE_LONG, len, - ICL_TYPE_INT32, (int) rw); + ICL_TYPE_LONG, offset, ICL_TYPE_LONG, len, ICL_TYPE_INT32, + (int)rw); for (i = 0; i < pages; i++) { pagep = &pl[i]; off = offset + PAGE_SIZE * i; - if (protp) protp[i] = 0; + if (protp) + protp[i] = 0; flags = 0; ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); #ifdef AFS_DUX50_ENV - code = ubc_lookup(AFSTOV(avc)->v_object, off, - PAGE_SIZE, PAGE_SIZE, pagep, &flags, NULL); + code = + ubc_lookup(AFSTOV(avc)->v_object, off, PAGE_SIZE, PAGE_SIZE, + pagep, &flags, NULL); #else - code = ubc_lookup(AFSTOV(avc)->v_object, off, - PAGE_SIZE, PAGE_SIZE, pagep, &flags); + code = + ubc_lookup(AFSTOV(avc)->v_object, off, PAGE_SIZE, PAGE_SIZE, + pagep, &flags); #endif AFS_GLOCK(); - ObtainWriteLock(&avc->lock,168); + ObtainWriteLock(&avc->lock, 168); if (code) { goto out; } - if(flags & B_NOCACHE) { /* if (page) */ - if ((rw & B_WRITE) && (offset+len >= avc->m.Length)) { + if (flags & B_NOCACHE) { /* if (page) */ + if ((rw & B_WRITE) && (offset + len >= avc->m.Length)) { struct vnode *vp = AFSTOV(avc); /* we're doing a write operation past eof; no need to read it */ AFS_GUNLOCK(); @@ -830,7 +843,7 @@ int mp_afs_getpage(vop, offset, len, protp, pl, plsz, bp->b_blkno = btodb(off); ReleaseWriteLock(&avc->lock); code = afs_ustrategy(bp, cred); /* do the I/O */ - ObtainWriteLock(&avc->lock,169); + ObtainWriteLock(&avc->lock, 169); AFS_GUNLOCK(); ubc_sync_iodone(bp); AFS_GLOCK(); @@ -856,7 +869,7 @@ int mp_afs_getpage(vop, offset, len, protp, pl, plsz, } } } -out: + out: pl[i] = VM_PAGE_NULL; ReleaseWriteLock(&avc->lock); afs_BozonUnlock(&avc->pvnLock, avc); @@ -868,14 +881,15 @@ out: } -int mp_afs_putpage(vop, pl, pcnt, flags, cred) - vm_ubc_object_t vop; - vm_page_t *pl; - int pcnt; - int flags; - struct ucred *cred; +int +mp_afs_putpage(vop, pl, pcnt, flags, cred) + vm_ubc_object_t vop; + vm_page_t *pl; + int pcnt; + int flags; + struct ucred *cred; { - register afs_int32 code=0; + register afs_int32 code = 0; struct vnode *vp = vop->vu_vp; struct vcache *avc = VTOAFS(vp); int i; @@ -890,10 +904,10 @@ int mp_afs_putpage(vop, pl, pcnt, flags, cred) if (vp->v_flag & VXLOCK) { VN_UNLOCK(vp); for (i = 0; i < pcnt; i++) { - ubc_page_release(pl[i], B_DONE|B_DIRTY); + ubc_page_release(pl[i], B_DONE | B_DIRTY); pl[i] = VM_PAGE_NULL; } - return(0); + return (0); } else { VN_UNLOCK(vp); } @@ -902,7 +916,7 @@ int mp_afs_putpage(vop, pl, pcnt, flags, cred) /* first, obtain the proper lock for the VM system */ afs_BozonLock(&avc->pvnLock, avc); - ObtainWriteLock(&avc->lock,170); + ObtainWriteLock(&avc->lock, 170); for (i = 0; i < pcnt; i++) { vm_page_t page = pl[i]; struct buf *bp; @@ -916,7 +930,7 @@ int mp_afs_putpage(vop, pl, pcnt, flags, cred) bp->b_blkno = btodb(page->pg_offset); ReleaseWriteLock(&avc->lock); code = afs_ustrategy(bp, cred); /* do the I/O */ - ObtainWriteLock(&avc->lock,171); + ObtainWriteLock(&avc->lock, 171); AFS_GUNLOCK(); ubc_sync_iodone(bp); AFS_GLOCK(); @@ -926,7 +940,7 @@ int mp_afs_putpage(vop, pl, pcnt, flags, cred) pl[i] = VM_PAGE_NULL; } } -done: + done: ReleaseWriteLock(&avc->lock); afs_BozonUnlock(&avc->pvnLock, avc); afs_Trace2(afs_iclSetp, CM_TRACE_PAGEOUTDONE, ICL_TYPE_INT32, code, @@ -936,20 +950,22 @@ done: } -int mp_afs_swap(avc, swapop, argp) - struct vcache *avc; - vp_swap_op_t swapop; - vm_offset_t argp; +int +mp_afs_swap(avc, swapop, argp) + struct vcache *avc; + vp_swap_op_t swapop; + vm_offset_t argp; { return EIO; } -int mp_afs_syncdata(avc, flag, offset, length, cred) - struct vcache *avc; - int flag; - vm_offset_t offset; - vm_size_t length; - struct ucred *cred; +int +mp_afs_syncdata(avc, flag, offset, length, cred) + struct vcache *avc; + int flag; + vm_offset_t offset; + vm_size_t length; + struct ucred *cred; { /* NFS V3 makes this call, ignore it. We'll sync the data in afs_fsync. */ if (AFS_NFSXLATORREQ(cred)) @@ -966,90 +982,90 @@ struct buf *afs_bread_freebp = 0; * Thus we can use fake bufs (ie not from the real buffer pool). */ mp_afs_bread(vp, lbn, bpp, cred) - struct ucred *cred; - struct vnode *vp; - daddr_t lbn; - struct buf **bpp; + struct ucred *cred; + struct vnode *vp; + daddr_t lbn; + struct buf **bpp; { - int offset, fsbsize, error; - struct buf *bp; - struct iovec iov; - struct uio uio; + int offset, fsbsize, error; + struct buf *bp; + struct iovec iov; + struct uio uio; - AFS_GLOCK(); - AFS_STATCNT(afs_bread); - fsbsize = vp->v_vfsp->vfs_bsize; - offset = lbn * fsbsize; - if (afs_bread_freebp) { - bp = afs_bread_freebp; - afs_bread_freebp = 0; - } else { - bp = (struct buf *) AFS_KALLOC(sizeof(*bp)); - bp->b_un.b_addr = (caddr_t) AFS_KALLOC(fsbsize); - } + AFS_GLOCK(); + AFS_STATCNT(afs_bread); + fsbsize = vp->v_vfsp->vfs_bsize; + offset = lbn * fsbsize; + if (afs_bread_freebp) { + bp = afs_bread_freebp; + afs_bread_freebp = 0; + } else { + bp = (struct buf *)AFS_KALLOC(sizeof(*bp)); + bp->b_un.b_addr = (caddr_t) AFS_KALLOC(fsbsize); + } - iov.iov_base = bp->b_un.b_addr; - iov.iov_len = fsbsize; - uio.afsio_iov = &iov; - uio.afsio_iovcnt = 1; - uio.afsio_seg = AFS_UIOSYS; - uio.afsio_offset = offset; - uio.afsio_resid = fsbsize; - *bpp = 0; - error = afs_read(VTOAFS(vp), &uio, cred, lbn, bpp, 0); - if (error) { - afs_bread_freebp = bp; - AFS_GUNLOCK(); - return error; - } - if (*bpp) { - afs_bread_freebp = bp; - } else { - *(struct buf **)&bp->b_vp = bp; /* mark as fake */ - *bpp = bp; - } + iov.iov_base = bp->b_un.b_addr; + iov.iov_len = fsbsize; + uio.afsio_iov = &iov; + uio.afsio_iovcnt = 1; + uio.afsio_seg = AFS_UIOSYS; + uio.afsio_offset = offset; + uio.afsio_resid = fsbsize; + *bpp = 0; + error = afs_read(VTOAFS(vp), &uio, cred, lbn, bpp, 0); + if (error) { + afs_bread_freebp = bp; AFS_GUNLOCK(); - return 0; + return error; + } + if (*bpp) { + afs_bread_freebp = bp; + } else { + *(struct buf **)&bp->b_vp = bp; /* mark as fake */ + *bpp = bp; + } + AFS_GUNLOCK(); + return 0; } mp_afs_brelse(vp, bp) -struct vnode *vp; -struct buf *bp; + struct vnode *vp; + struct buf *bp; { AFS_GLOCK(); AFS_STATCNT(afs_brelse); - if ((struct buf *)bp->b_vp != bp) { /* not fake */ - brelse(bp); - } else if (afs_bread_freebp) { - AFS_KFREE(bp->b_un.b_addr, vp->v_vfsp->vfs_bsize); - AFS_KFREE(bp, sizeof(*bp)); - } else { - afs_bread_freebp = bp; - } + if ((struct buf *)bp->b_vp != bp) { /* not fake */ + brelse(bp); + } else if (afs_bread_freebp) { + AFS_KFREE(bp->b_un.b_addr, vp->v_vfsp->vfs_bsize); + AFS_KFREE(bp, sizeof(*bp)); + } else { + afs_bread_freebp = bp; + } AFS_GUNLOCK(); } mp_afs_bmap(avc, abn, anvp, anbn) - register struct vcache *avc; - afs_int32 abn, *anbn; - struct vcache **anvp; + register struct vcache *avc; + afs_int32 abn, *anbn; + struct vcache **anvp; { AFS_GLOCK(); AFS_STATCNT(afs_bmap); if (anvp) *anvp = avc; if (anbn) - *anbn = abn * (8192 / DEV_BSIZE); /* in 512 byte units */ + *anbn = abn * (8192 / DEV_BSIZE); /* in 512 byte units */ AFS_GUNLOCK(); return 0; } /* real strategy */ -mp_afs_strategy (abp) - register struct buf *abp; +mp_afs_strategy(abp) + register struct buf *abp; { register afs_int32 code; @@ -1063,47 +1079,47 @@ mp_afs_strategy (abp) mp_afs_refer(vm_ubc_object_t vop) { - VREF(vop->vu_vp); + VREF(vop->vu_vp); } mp_afs_release(vm_ubc_object_t vop) { - vrele(vop->vu_vp); + vrele(vop->vu_vp); } mp_afs_write_check(vm_ubc_object_t vop, vm_page_t pp) { - return TRUE; + return TRUE; } #ifdef AFS_DUX50_ENV int mp_afs_objtovp(vm_ubc_object_t vop, struct vnode **vp) { - *vp = vop->vu_vp; - return 0; + *vp = vop->vu_vp; + return 0; } int mp_afs_setpgstamp(vm_page_t pp, unsigned int tick) { - pp->pg_stamp = tick; - return 0; + pp->pg_stamp = tick; + return 0; } #endif struct vfs_ubcops afs_ubcops = { - mp_afs_refer, /* refer vnode */ - mp_afs_release, /* release vnode */ - mp_afs_getpage, /* get page */ - mp_afs_putpage, /* put page */ - mp_afs_write_check, /* check writablity */ + mp_afs_refer, /* refer vnode */ + mp_afs_release, /* release vnode */ + mp_afs_getpage, /* get page */ + mp_afs_putpage, /* put page */ + mp_afs_write_check, /* check writablity */ #ifdef AFS_DUX50_ENV - mp_afs_objtovp, /* get vnode pointer */ - mp_afs_setpgstamp /* set page stamp */ + mp_afs_objtovp, /* get vnode pointer */ + mp_afs_setpgstamp /* set page stamp */ #endif }; @@ -1115,24 +1131,23 @@ struct vfs_ubcops afs_ubcops = { * locked after return. */ lookupname(namep, seg, follow, dvpp, cvpp) - char *namep; /* path name */ - int seg; /* address space containing name */ - int follow; /* follow symbolic links */ - struct vnode **dvpp; /* result, containing parent vnode */ - struct vnode **cvpp; /* result, containing final component vnode */ + char *namep; /* path name */ + int seg; /* address space containing name */ + int follow; /* follow symbolic links */ + struct vnode **dvpp; /* result, containing parent vnode */ + struct vnode **cvpp; /* result, containing final component vnode */ { /* Should I use free-bee in u-area? */ struct nameidata *ndp = &u.u_nd; int error; - ndp->ni_nameiop = ((follow) ? (LOOKUP|FOLLOW) : (LOOKUP)); + ndp->ni_nameiop = ((follow) ? (LOOKUP | FOLLOW) : (LOOKUP)); ndp->ni_segflg = seg; ndp->ni_dirp = namep; error = namei(ndp); - if (dvpp != (struct vnode **)0) + if (dvpp != NULL) *dvpp = ndp->ni_dvp; - if (cvpp != (struct vnode **)0) + if (cvpp != NULL) *cvpp = ndp->ni_vp; - return(error); + return (error); } - diff --git a/src/afs/FBSD/osi_file.c b/src/afs/FBSD/osi_file.c index d8688f59c..7d80b62c5 100644 --- a/src/afs/FBSD/osi_file.c +++ b/src/afs/FBSD/osi_file.c @@ -8,66 +8,76 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_file.c,v 1.1.1.5 2002/09/26 18:58:08 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_file.c,v 1.13 2004/03/10 23:01:51 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ -int afs_osicred_initialized=0; -struct AFS_UCRED afs_osi_cred; +int afs_osicred_initialized = 0; +struct AFS_UCRED afs_osi_cred; afs_lock_t afs_xosi; /* lock is for tvattr */ extern struct osi_dev cacheDev; extern struct mount *afs_cacheVfsp; -void *osi_UFSOpen(ainode) - afs_int32 ainode; +void * +osi_UFSOpen(afs_int32 ainode) { - struct inode *ip; - register struct osi_file *afile = NULL; + struct osi_file *afile; + struct vnode *vp; extern int cacheDiskType; - afs_int32 code = 0; - int dummy; + afs_int32 code; + AFS_STATCNT(osi_UFSOpen); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) { + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) osi_Panic("UFSOpen called for non-UFS cache\n"); - } - if (!afs_osicred_initialized) { - /* valid for alpha_osf, SunOS, Ultrix */ - memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED)); - afs_osi_cred.cr_ref++; - afs_osicred_initialized = 1; - } - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); AFS_GUNLOCK(); - code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode, &ip, &dummy); +#if defined(AFS_FBSD50_ENV) + code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode, LK_EXCLUSIVE, &vp); +#else + code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode, &vp); +#endif AFS_GLOCK(); + if (code == 0 && vp->v_type == VNON) + code = ENOENT; if (code) { osi_FreeSmallSpace(afile); osi_Panic("UFSOpen: igetinode failed"); } - afile->vnode = ITOV(ip); - VOP_UNLOCK(afile->vnode, 0, curproc); - afile->size = VTOI(afile->vnode)->i_size; +#if defined(AFS_FBSD50_ENV) + VOP_UNLOCK(vp, 0, curthread); +#else + VOP_UNLOCK(vp, 0, curproc); +#endif + afile->vnode = vp; + afile->size = VTOI(vp)->i_size; afile->offset = 0; - afile->proc = (int (*)()) 0; - afile->inum = ainode; /* for hint validity checking */ + afile->proc = NULL; + afile->inum = ainode; /* for hint validity checking */ return (void *)afile; } -afs_osi_Stat(afile, astat) - register struct osi_file *afile; - register struct osi_stat *astat; { +int +afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) +{ register afs_int32 code; struct vattr tvattr; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi,320); + MObtainWriteLock(&afs_xosi, 320); AFS_GUNLOCK(); - code=VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc); +#if defined(AFS_FBSD50_ENV) + vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curthread); + code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread); + VOP_UNLOCK(afile->vnode, LK_EXCLUSIVE, curthread); +#else + code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc); +#endif AFS_GLOCK(); if (code == 0) { astat->size = tvattr.va_size; @@ -79,117 +89,138 @@ afs_osi_Stat(afile, astat) return code; } -osi_UFSClose(afile) - register struct osi_file *afile; - { - AFS_STATCNT(osi_Close); - if(afile->vnode) { +int +osi_UFSClose(register struct osi_file *afile) +{ + AFS_STATCNT(osi_Close); + if (afile->vnode) { AFS_RELE(afile->vnode); - } - - osi_FreeSmallSpace(afile); - return 0; - } - -osi_UFSTruncate(afile, asize) - register struct osi_file *afile; - afs_int32 asize; { + } + + osi_FreeSmallSpace(afile); + return 0; +} + +int +osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) +{ struct vattr tvattr; + struct vnode *vp; register afs_int32 code; - struct osi_stat tstat; AFS_STATCNT(osi_Truncate); - /* This routine only shrinks files, and most systems + MObtainWriteLock(&afs_xosi, 321); + vp = afile->vnode; + /* + * This routine only shrinks files, and most systems * have very slow truncates, even when the file is already * small enough. Check now and save some time. */ - code = afs_osi_Stat(afile, &tstat); - if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi,321); + AFS_GUNLOCK(); +#if defined(AFS_FBSD50_ENV) + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread); + code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread); +#else + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc); + code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc); +#endif + if (code != 0 || tvattr.va_size <= asize) + goto out; + VATTR_NULL(&tvattr); tvattr.va_size = asize; - AFS_GUNLOCK(); - code=VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc); +#if defined(AFS_FBSD50_ENV) + code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curthread); +#else + code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curproc); +#endif + +out: +#if defined(AFS_FBSD50_ENV) + VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread); +#else + VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc); +#endif AFS_GLOCK(); MReleaseWriteLock(&afs_xosi); return code; } -void osi_DisableAtimes(avp) -struct vnode *avp; +void +osi_DisableAtimes(struct vnode *avp) { - struct inode *ip = VTOI(avp); - ip->i_flag &= ~IN_ACCESS; + struct inode *ip = VTOI(avp); + ip->i_flag &= ~IN_ACCESS; } /* Generic read interface */ -afs_osi_Read(afile, offset, aptr, asize) - register struct osi_file *afile; - int offset; - char *aptr; - afs_int32 asize; { +int +afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, + afs_int32 asize) +{ unsigned int resid; register afs_int32 code; - register afs_int32 cnt1=0; AFS_STATCNT(osi_Read); /** * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ - if ( !afile ) { - if ( !afs_shuttingdown ) + if (!afile) { + if (!afs_shuttingdown) osi_Panic("osi_Read called with null param"); else return EIO; } - if (offset != -1) afile->offset = offset; + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, + AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; osi_DisableAtimes(afile->vnode); - } - else { + } else { afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, - ICL_TYPE_INT32, code); + ICL_TYPE_INT32, code); code = -1; } return code; } /* Generic write interface */ -afs_osi_Write(afile, offset, aptr, asize) - register struct osi_file *afile; - char *aptr; - afs_int32 offset; - afs_int32 asize; { +int +afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, + afs_int32 asize) +{ unsigned int resid; register afs_int32 code; AFS_STATCNT(osi_Write); - if ( !afile ) - osi_Panic("afs_osi_Write called with null param"); - if (offset != -1) afile->offset = offset; + if (!afile) + osi_Panic("afs_osi_Write called with null param"); + if (offset != -1) + afile->offset = offset; { AFS_GUNLOCK(); - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp, + &resid); AFS_GLOCK(); } if (code == 0) { code = asize - resid; afile->offset += code; - } - else { + } else { code = -1; } if (afile->proc) { - (*afile->proc)(afile, code); + (*afile->proc) (afile, code); } return code; } @@ -198,9 +229,8 @@ afs_osi_Write(afile, offset, aptr, asize) /* This work should be handled by physstrat in ca/machdep.c. This routine written from the RT NFS port strategy routine. It has been generalized a bit, but should still be pretty clear. */ -int afs_osi_MapStrategy(aproc, bp) - int (*aproc)(); - register struct buf *bp; +int +afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp) { afs_int32 returnCode; @@ -213,13 +243,12 @@ int afs_osi_MapStrategy(aproc, bp) void -shutdown_osifile() +shutdown_osifile(void) { - extern int afs_cold_shutdown; + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osifile); - if (afs_cold_shutdown) { - afs_osicred_initialized = 0; - } + AFS_STATCNT(shutdown_osifile); + if (afs_cold_shutdown) { + afs_osicred_initialized = 0; + } } - diff --git a/src/afs/FBSD/osi_groups.c b/src/afs/FBSD/osi_groups.c index f49c0d27b..13cac178b 100644 --- a/src/afs/FBSD/osi_groups.c +++ b/src/afs/FBSD/osi_groups.c @@ -15,74 +15,117 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" +#include +#ifdef AFS_FBSD50_ENV +#include +#endif -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_groups.c,v 1.1.1.4 2002/09/26 18:58:08 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_groups.c,v 1.8 2003/07/15 23:14:19 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset); + afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset); static int -afs_setgroups( - struct proc *proc, - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent); + afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups, + gid_t * gidset, int change_parent); + +#ifdef AFS_FBSD50_ENV +/* + * This does nothing useful yet. + * In 5.0, creds are associated not with a process, but with a thread. + * Probably the right thing to do is replace struct proc with struct thread + * everywhere, including setpag. + * That will be a tedious undertaking. + * For now, I'm just passing curproc to AddPag. + * This is probably wrong and I don't know what the consequences might be. + */ +int +Afs_xsetgroups(struct thread *td, struct setgroups_args *uap) +{ + int code = 0; + struct vrequest treq; + struct ucred *cr; + + cr = crdup(td->td_ucred); + + AFS_STATCNT(afs_xsetgroups); + AFS_GLOCK(); + + code = afs_InitReq(&treq, cr); + AFS_GUNLOCK(); + crfree(cr); + if (code) + return setgroups(td, uap); /* afs has shut down */ + + code = setgroups(td, uap); + /* Note that if there is a pag already in the new groups we don't + * overwrite it with the old pag. + */ + cr = crdup(td->td_ucred); + + if (PagInCred(cr) == NOPAG) { + if (((treq.uid >> 24) & 0xff) == 'A') { + AFS_GLOCK(); + /* we've already done a setpag, so now we redo it */ + AddPag(curproc, treq.uid, &cr); + AFS_GUNLOCK(); + } + } + crfree(cr); + return code; +} +#else /* FBSD50 */ int Afs_xsetgroups(p, args, retval) - struct proc *p; - void *args; - int *retval; + struct proc *p; + void *args; + int *retval; { int code = 0; struct vrequest treq; struct ucred *cr; - cr=crdup(p->p_cred->pc_ucred); + cr = crdup(p->p_cred->pc_ucred); AFS_STATCNT(afs_xsetgroups); AFS_GLOCK(); - + code = afs_InitReq(&treq, cr); AFS_GUNLOCK(); crfree(cr); - if (code) return setgroups(p, args, retval); /* afs has shut down */ + if (code) + return setgroups(p, args, retval); /* afs has shut down */ code = setgroups(p, args, retval); /* Note that if there is a pag already in the new groups we don't * overwrite it with the old pag. */ - cr=crdup(p->p_cred->pc_ucred); + cr = crdup(p->p_cred->pc_ucred); if (PagInCred(cr) == NOPAG) { if (((treq.uid >> 24) & 0xff) == 'A') { AFS_GLOCK(); /* we've already done a setpag, so now we redo it */ - AddPag(p, treq.uid, &cr ); + AddPag(p, treq.uid, &cr); AFS_GUNLOCK(); } } crfree(cr); return code; } +#endif int -setpag(proc, cred, pagvalue, newpag, change_parent) - struct proc *proc; - struct ucred **cred; - afs_uint32 pagvalue; - afs_uint32 *newpag; - afs_uint32 change_parent; +setpag(struct proc *proc, struct ucred **cred, afs_uint32 pagvalue, + afs_uint32 * newpag, int change_parent) { gid_t gidset[NGROUPS]; int ngroups, code; @@ -95,12 +138,12 @@ setpag(proc, cred, pagvalue, newpag, change_parent) if (ngroups + 2 > NGROUPS) { return (E2BIG); } - for (j = ngroups -1; j >= 1; j--) { - gidset[j+2] = gidset[j]; + for (j = ngroups - 1; j >= 1; j--) { + gidset[j + 2] = gidset[j]; } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); + *newpag = (pagvalue == -1 ? genpag() : pagvalue); afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]); code = afs_setgroups(proc, cred, ngroups, gidset, change_parent); return code; @@ -108,10 +151,7 @@ setpag(proc, cred, pagvalue, newpag, change_parent) static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset) +afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset) { int ngrps, savengrps; gid_t *gp; @@ -120,20 +160,16 @@ afs_getgroups( savengrps = ngrps = MIN(ngroups, cred->cr_ngroups); gp = cred->cr_groups; while (ngrps--) - *gidset++ = *gp++; + *gidset++ = *gp++; return savengrps; } - static int -afs_setgroups( - struct proc *proc, - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent) +afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups, + gid_t * gidset, int change_parent) { +#ifndef AFS_FBSD50_ENV int ngrps; int i; gid_t *gp; @@ -153,13 +189,14 @@ afs_setgroups( *gp++ = *gidset++; if (change_parent) { crhold(cr); - oldcr=proc->p_pptr->p_cred->pc_ucred; - proc->p_pptr->p_cred->pc_ucred=cr; + oldcr = proc->p_pptr->p_cred->pc_ucred; + proc->p_pptr->p_cred->pc_ucred = cr; crfree(oldcr); } crhold(cr); - oldcr=proc->p_cred->pc_ucred; - proc->p_cred->pc_ucred=cr; + oldcr = proc->p_cred->pc_ucred; + proc->p_cred->pc_ucred = cr; crfree(oldcr); - return(0); +#endif + return (0); } diff --git a/src/afs/FBSD/osi_inode.c b/src/afs/FBSD/osi_inode.c index ef70494f6..3179c32f7 100644 --- a/src/afs/FBSD/osi_inode.c +++ b/src/afs/FBSD/osi_inode.c @@ -14,19 +14,24 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_inode.c,v 1.1.1.4 2002/09/26 18:58:08 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_inode.c,v 1.9 2004/03/10 23:01:51 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/osi_inode.h" -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/osi_inode.h" +#include "afs/afs_stats.h" /* statistics stuff */ #include #include -#include #include +#if defined(AFS_FBSD50_ENV) +#include +#endif +#include +int getinode(fs, dev, inode, ipp, perror) struct mount *fs; struct inode **ipp; @@ -42,38 +47,52 @@ getinode(fs, dev, inode, ipp, perror) if (!fs) { register struct ufsmount *ump; register struct mount *mp; - - simple_lock(&mountlist_slock); - if (mp = TAILQ_FIRST(&mountlist)) do { - /* - * XXX Also do the test for MFS - */ + +#if defined(AFS_FBSD50_ENV) + mtx_lock(&mountlist_mtx); +#else + simple_lock(&mountlist_slock); +#endif + if ((mp = TAILQ_FIRST(&mountlist)) != NULL) + do { + /* + * XXX Also do the test for MFS + */ #undef m_data #undef m_next - if (mp->mnt_stat.f_type == MOUNT_UFS) { - ump = VFSTOUFS(mp); - if (ump->um_fs == NULL) - break; - if (ump->um_dev == dev) { - fs = ump->um_mountp; + if (!strcmp(mp->mnt_stat.f_fstypename, MOUNT_UFS)) { + ump = VFSTOUFS(mp); + if (ump->um_fs == NULL) + break; + if (ump->um_dev == dev) { + fs = ump->um_mountp; + } } - } - mp = TAILQ_NEXT(mp, mnt_list); - } while (mp != TAILQ_FIRST(&mountlist)); - simple_unlock(&mountlist_slock); + mp = TAILQ_NEXT(mp, mnt_list); + } while (mp != TAILQ_FIRST(&mountlist)); +#if defined(AFS_FBSD50_ENV) + mtx_unlock(&mountlist_mtx); +#else + simple_unlock(&mountlist_slock); +#endif if (!fs) - return(ENXIO); + return (ENXIO); } - code = VFS_VGET(fs,inode, &vp); +#if defined(AFS_FBSD50_ENV) + code = VFS_VGET(fs, inode, 0, &vp); +#else + code = VFS_VGET(fs, inode, &vp); +#endif if (code != 0) { *perror = BAD_IGET; - return code; + return code; } else { *ipp = VTOI(vp); - return(0); + return (0); } } +int igetinode(vfsp, dev, inode, ipp, perror) struct inode **ipp; struct mount *vfsp; @@ -81,8 +100,7 @@ igetinode(vfsp, dev, inode, ipp, perror) ino_t inode; int *perror; { - struct inode *pip, *ip; - extern struct osi_dev cacheDev; + struct inode *ip; register int code = 0; *perror = 0; @@ -90,22 +108,22 @@ igetinode(vfsp, dev, inode, ipp, perror) AFS_STATCNT(igetinode); if ((code = getinode(vfsp, dev, inode, &ip, perror)) != 0) { - return(code); + return (code); } if (ip->i_mode == 0) { /* Not an allocated inode */ - vput(ITOV(ip)); - return(ENOENT); + vput(ITOV(ip)); + return (ENOENT); } - if (ip->i_nlink == 0 || (ip->i_mode&IFMT) != IFREG) { - vput(ITOV(ip)); - return(ENOENT); + if (ip->i_nlink == 0 || (ip->i_mode & IFMT) != IFREG) { + vput(ITOV(ip)); + return (ENOENT); } *ipp = ip; - return(0); + return (0); } #if 0 @@ -116,112 +134,113 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval) long *retval; long dev, near_inode, param1, param2, param3, param4; { - int dummy, err=0; + int dummy, err = 0; struct inode *ip, *newip; register int code; struct vnode *vp; - + AFS_STATCNT(afs_syscall_icreate); - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = getinode(0, (dev_t)dev, 2, &ip, &dummy); + code = getinode(0, (dev_t) dev, 2, &ip, &dummy); if (code) { - return(ENOENT); + return (ENOENT); } - code = ialloc(ip, (ino_t)near_inode, 0, &newip); + code = ialloc(ip, (ino_t) near_inode, 0, &newip); iput(ip); if (code) { - return(code); + return (code); } IN_LOCK(newip); - newip->i_flag |= IACC|IUPD|ICHG; - + newip->i_flag |= IACC | IUPD | ICHG; + newip->i_nlink = 1; newip->i_mode = IFREG; - + IN_UNLOCK(newip); vp = ITOV(newip); VN_LOCK(vp); vp->v_type = VREG; VN_UNLOCK(vp); - + /* - if ( !vp->v_object) - { - extern struct vfs_ubcops ufs_ubcops; - extern struct vm_ubc_object* ubc_object_allocate(); - struct vm_ubc_object* vop; - vop = ubc_object_allocate(&vp, &ufs_ubcops, - vp->v_mount->m_funnel); - VN_LOCK(vp); - vp->v_object = vop; - VN_UNLOCK(vp); - } - */ - + * if ( !vp->v_object) + * { + * extern struct vfs_ubcops ufs_ubcops; + * extern struct vm_ubc_object* ubc_object_allocate(); + * struct vm_ubc_object* vop; + * vop = ubc_object_allocate(&vp, &ufs_ubcops, + * vp->v_mount->m_funnel); + * VN_LOCK(vp); + * vp->v_object = vop; + * VN_UNLOCK(vp); + * } + */ + IN_LOCK(newip); /* newip->i_flags |= IC_XUID|IC_XGID; */ /* newip->i_flags &= ~IC_PROPLIST; */ newip->i_vicep1 = param1; - if (param2 == 0x1fffffff/*INODESPECIAL*/) { + if (param2 == 0x1fffffff /*INODESPECIAL*/) { newip->i_vicep2 = ((0x1fffffff << 3) + (param4 & 0x3)); - newip->i_vicep3a = (u_short)(param3 >> 16); - newip->i_vicep3b = (u_short)param3; + newip->i_vicep3a = (u_short) (param3 >> 16); + newip->i_vicep3b = (u_short) param3; } else { - newip->i_vicep2 = (((param2 >> 16) & 0x1f) << 27) + - (((param4 >> 16) & 0x1f) << 22) + - (param3 & 0x3fffff); - newip->i_vicep3a = (u_short)param4; - newip->i_vicep3b = (u_short)param2; + newip->i_vicep2 = + (((param2 >> 16) & 0x1f) << 27) + + (((param4 >> 16) & 0x1f) << 22) + (param3 & 0x3fffff); + newip->i_vicep3a = (u_short) param4; + newip->i_vicep3b = (u_short) param2; } newip->i_vicemagic = VICEMAGIC; - + *retval = newip->i_number; IN_UNLOCK(newip); iput(newip); - return(code); + return (code); } +int afs_syscall_iopen(dev, inode, usrmod, retval) long *retval; int dev, inode, usrmod; { struct file *fp; struct inode *ip; - struct vnode *vp = (struct vnode *)0; + struct vnode *vp = NULL; int dummy; int fd; extern struct fileops vnops; register int code; - + AFS_STATCNT(afs_syscall_iopen); - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy); + code = igetinode(0, (dev_t) dev, (ino_t) inode, &ip, &dummy); if (code) { - return(code); + return (code); } if ((code = falloc(curproc, &fp, &fd)) != 0) { iput(ip); - return(code); + return (code); } IN_UNLOCK(ip); - + /* FreeBSD doesn't do much mp stuff yet :( */ /* FP_LOCK(fp); */ fp->f_flag = (usrmod) & FMASK; fp->f_type = DTYPE_VNODE; fp->f_ops = &vnops; - fp->f_data = (caddr_t)ITOV(ip); - + fp->f_data = (caddr_t) ITOV(ip); + /* FP_UNLOCK(fp); */ - return(0); + return (0); } @@ -231,24 +250,25 @@ afs_syscall_iopen(dev, inode, usrmod, retval) * Restricted to super user. * Only VICEMAGIC type inodes. */ +int afs_syscall_iincdec(dev, inode, inode_p1, amount) int dev, inode, inode_p1, amount; { int dummy; struct inode *ip; register int code; - + if (!afs_suser()) - return(EPERM); + return (EPERM); - code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy); + code = igetinode(0, (dev_t) dev, (ino_t) inode, &ip, &dummy); if (code) { - return(code); + return (code); } if (!IS_VICEMAGIC(ip)) { - return(EPERM); + return (EPERM); } else if (ip->i_vicep1 != inode_p1) { - return(ENXIO); + return (ENXIO); } ip->i_nlink += amount; if (ip->i_nlink == 0) { @@ -256,25 +276,29 @@ afs_syscall_iincdec(dev, inode, inode_p1, amount) } ip->i_flag |= ICHG; iput(ip); - return(0); + return (0); } #else +int afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval) long *retval; long dev, near_inode, param1, param2, param3, param4; { - return EOPNOTSUPP; + return EOPNOTSUPP; } + +int afs_syscall_iopen(dev, inode, usrmod, retval) long *retval; int dev, inode, usrmod; { - return EOPNOTSUPP; + return EOPNOTSUPP; } + +int afs_syscall_iincdec(dev, inode, inode_p1, amount) int dev, inode, inode_p1, amount; { - return EOPNOTSUPP; + return EOPNOTSUPP; } #endif - diff --git a/src/afs/FBSD/osi_inode.h b/src/afs/FBSD/osi_inode.h index 39c706fa1..d63526c95 100644 --- a/src/afs/FBSD/osi_inode.h +++ b/src/afs/FBSD/osi_inode.h @@ -46,7 +46,7 @@ #define di_vicep2 di_gid #define di_vicep3a di_u.oldids[0] #define di_vicep3b di_u.oldids[1] -#define di_vicep4 di_spare[1] /* not used */ +#define di_vicep4 di_spare[1] /* not used */ /* * Macros for handling inode numbers: diff --git a/src/afs/FBSD/osi_machdep.h b/src/afs/FBSD/osi_machdep.h index b134ad6d1..3e0cb3999 100644 --- a/src/afs/FBSD/osi_machdep.h +++ b/src/afs/FBSD/osi_machdep.h @@ -21,17 +21,17 @@ #include #include -/* #include */ -/* #include */ +#if defined(AFS_FBSD50_ENV) +#include +#endif -#define getpid() curproc extern struct simplelock afs_rxglobal_lock; /* * Time related macros */ -#define osi_Time() time_second -#define afs_hz hz +#define osi_Time() time_second +#define afs_hz hz #define PAGESIZE 8192 @@ -39,19 +39,57 @@ extern struct simplelock afs_rxglobal_lock; #define AFS_PROC struct proc #define afs_bufferpages bufpages +#ifndef iodone +#define iodone biodone +#endif -#define osi_vnhold(avc,r) do { VN_HOLD((struct vnode *)(avc)); } while (0) +#define osi_vnhold(avc,r) vref(AFSTOV(avc)) +#undef vSetVfsp +#define vSetVfsp(vc, vfsp) AFSTOV(vc)->v_mount = (vfsp) +#undef vSetType +#define vSetType(vc, type) AFSTOV(vc)->v_type = (type) +#undef vType +#define vType(vc) AFSTOV(vc)->v_type -#define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \ - vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc) #undef gop_lookupname #define gop_lookupname osi_lookupname #undef afs_suser +#define afs_strcat(s1, s2) strcat((s1), (s2)) + #ifdef KERNEL -extern struct proc * afs_global_owner; + +#undef afs_osi_Alloc_NoSleep +#define afs_osi_Alloc_NoSleep(size) osi_fbsd_alloc((size), 0) + +#define VN_RELE(vp) vrele(vp) +#define VN_HOLD(vp) VREF(vp) + +#if defined(AFS_FBSD50_ENV) +#define VT_AFS "afs" +#define VROOT VV_ROOT +#define v_flag v_vflag +#define osi_curcred() (curthread->td_ucred) +#define afs_suser() (!suser(curthread)) +#define simple_lock(x) mtx_lock(x) +#define simple_unlock(x) mtx_unlock(x) +#define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \ + vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread) +extern struct mtx afs_global_mtx; +#define AFS_GLOCK() mtx_lock(&afs_global_mtx) +#define AFS_GUNLOCK() mtx_unlock(&afs_global_mtx) +#define ISAFS_GLOCK() (mtx_owned(&afs_global_mtx)) + +#else /* FBSD50 */ extern struct lock afs_global_lock; + +#define osi_curcred() (curproc->p_cred->pc_ucred) +#define afs_suser() (!suser(curproc)) +#define getpid() curproc +#define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \ + vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc) +extern struct proc *afs_global_owner; #define AFS_GLOCK() \ do { \ osi_Assert(curproc); \ @@ -67,6 +105,8 @@ extern struct lock afs_global_lock; lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \ } while(0) #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc) +#endif /* FBSD50 */ + #define AFS_RXGLOCK() #define AFS_RXGUNLOCK() #define ISAFS_RXGLOCK() 1 diff --git a/src/afs/FBSD/osi_misc.c b/src/afs/FBSD/osi_misc.c index 1040984fe..943197573 100644 --- a/src/afs/FBSD/osi_misc.c +++ b/src/afs/FBSD/osi_misc.c @@ -15,50 +15,160 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_misc.c,v 1.1.1.4 2002/09/26 18:58:09 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_misc.c,v 1.9 2004/03/10 23:01:51 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ #include -/* - * afs_suser() returns true if the caller is superuser, false otherwise. - * - * Note that it must NOT set errno. - */ -afs_suser() { - int error; - - if (suser(curproc) == 0) { - return(1); - } - return(0); -} +#ifdef AFS_FBSD50_ENV +/* serious cheating */ +#undef curproc +#define curproc curthread +#endif -int osi_lookupname(char *aname, enum uio_seg seg, int followlink, - struct vnode **dirvpp, struct vnode **vpp) +int +osi_lookupname(char *aname, enum uio_seg seg, int followlink, + struct vnode **dirvpp, struct vnode **vpp) { - struct nameidata n; - int flags,error; - flags=0; - flags=LOCKLEAF; - if (followlink) - flags|=FOLLOW; - else - flags|=NOFOLLOW; -/* if (dirvpp) flags|=WANTPARENT;*/ /* XXX LOCKPARENT? */ - NDINIT(&n, LOOKUP, flags, seg, aname, curproc); - if (error=namei(&n)) - return error; - *vpp=n.ni_vp; + struct nameidata n; + int flags, error, wasowned; + +#ifdef AFS_FBSD50_ENV + wasowned = mtx_owned(&afs_global_mtx); + if (wasowned) + mtx_unlock(&afs_global_mtx); +#endif + + flags = 0; + flags = LOCKLEAF; + if (followlink) + flags |= FOLLOW; + else + flags |= NOFOLLOW; + /* if (dirvpp) flags|=WANTPARENT; *//* XXX LOCKPARENT? */ + NDINIT(&n, LOOKUP, flags, seg, aname, curproc); + if ((error = namei(&n)) != 0) { +#ifdef AFS_FBSD50_ENV + if (wasowned) + mtx_lock(&afs_global_mtx); +#endif + return error; + } + *vpp = n.ni_vp; /* if (dirvpp) *dirvpp = n.ni_dvp; */ - /* should we do this? */ - VOP_UNLOCK(n.ni_vp, 0, curproc); - NDFREE(&n, NDF_ONLY_PNBUF); - return 0; + /* should we do this? */ + VOP_UNLOCK(n.ni_vp, 0, curproc); + NDFREE(&n, NDF_ONLY_PNBUF); +#ifdef AFS_FBSD50_ENV + if (wasowned) + mtx_lock(&afs_global_mtx); +#endif + return 0; +} + +/* + * does not implement security features of kern_time.c:settime() + */ +void +afs_osi_SetTime(osi_timeval_t * atv) +{ +#ifdef AFS_FBSD50_ENV + printf("afs attempted to set clock; use \"afsd -nosettime\"\n"); +#else + struct timespec ts; + struct timeval tv, delta; + int s; + + AFS_GUNLOCK(); + s = splclock(); + microtime(&tv); + delta = *atv; + timevalsub(&delta, &tv); + ts.tv_sec = atv->tv_sec; + ts.tv_nsec = atv->tv_usec * 1000; + set_timecounter(&ts); + (void)splsoftclock(); + lease_updatetime(delta.tv_sec); + splx(s); + resettodr(); + AFS_GLOCK(); +#endif +} + +/* + * Replace all of the bogus special-purpose memory allocators... + */ +void * +osi_fbsd_alloc(size_t size, int dropglobal) +{ + void *rv; +#ifdef AFS_FBSD50_ENV + int wasowned; + + if (dropglobal) { + wasowned = mtx_owned(&afs_global_mtx); + if (wasowned) + mtx_unlock(&afs_global_mtx); + rv = malloc(size, M_AFS, M_WAITOK); + if (wasowned) + mtx_lock(&afs_global_mtx); + } else +#endif + rv = malloc(size, M_AFS, M_NOWAIT); + + return (rv); +} + +void +osi_fbsd_free(void *p) +{ + + free(p, M_AFS); +} + +void +osi_AllocMoreSSpace(afs_int32 preallocs) +{ + ; +} + +void +osi_FreeLargeSpace(void *p) +{ + osi_fbsd_free(p); +} + +void +osi_FreeSmallSpace(void *p) +{ + osi_fbsd_free(p); +} + +void * +osi_AllocLargeSpace(size_t size) +{ + AFS_ASSERT_GLOCK(); + AFS_STATCNT(osi_AllocLargeSpace); + return (osi_fbsd_alloc(size, 1)); +} + +void * +osi_AllocSmallSpace(size_t size) +{ + AFS_ASSERT_GLOCK(); + AFS_STATCNT(osi_AllocSmallSpace); + return (osi_fbsd_alloc(size, 1)); +} + +void +shutdown_osinet(void) +{ + ; } diff --git a/src/afs/FBSD/osi_module.c b/src/afs/FBSD/osi_module.c index 1b8fbd9da..a562ee251 100644 --- a/src/afs/FBSD/osi_module.c +++ b/src/afs/FBSD/osi_module.c @@ -1,8 +1,21 @@ +/* + * Copyright 2000, International Business Machines Corporation and others. + * All Rights Reserved. + * + * This software has been released under the terms of the IBM Public + * License. For details, see the LICENSE file in the top-level source + * directory or online at http://www.openafs.org/dl/license10.html + */ +#include #include + +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_module.c,v 1.5 2004/03/10 23:01:51 rees Exp $"); + #include -#include +#include #include #include #include @@ -19,73 +32,79 @@ extern int afs3_syscall(); extern int Afs_xsetgroups(); extern int afs_xioctl(); -int afs_module_handler(module_t mod, int what, void *arg) { - static sy_call_t *old_handler; - static int inited=0; - int error; - error=0; - switch (what) { - case MOD_LOAD: - if (inited) { - printf ("afs cannot be MOD_LOAD'd more than once\n"); - error=-1; - break; - } - if (sysent[AFS_SYSCALL].sy_call != nosys && - sysent[AFS_SYSCALL].sy_call != lkmnosys) { - printf("AFS_SYSCALL in use. aborting\n"); - error=-1; - break; - } - memset(&afs_vfsconf, 0, sizeof(struct vfsconf)); - strcpy(afs_vfsconf.vfc_name, "AFS"); - afs_vfsconf.vfc_vfsops=&afs_vfsops; - afs_vfsconf.vfc_typenum=-1; /* set by vfs_register */ - afs_vfsconf.vfc_flags=VFCF_NETWORK; - vfs_register(&afs_vfsconf); /* doesn't fail */ - vfs_add_vnodeops(&afs_vnodeop_opv_desc); - osi_Init(); - sysent[SYS_setgroups].sy_call=Afs_xsetgroups; - sysent[SYS_ioctl].sy_call=afs_xioctl; - old_handler=sysent[AFS_SYSCALL].sy_call; - sysent[AFS_SYSCALL].sy_call=afs3_syscall; - sysent[AFS_SYSCALL].sy_narg = 5; - inited=1; - break; - case MOD_UNLOAD: +int +afs_module_handler(module_t mod, int what, void *arg) +{ + static sy_call_t *old_handler; + static int inited = 0; + int error = 0; + + switch (what) { + case MOD_LOAD: + if (inited) { + printf("afs cannot be MOD_LOAD'd more than once\n"); + error = -1; + break; + } + if (sysent[AFS_SYSCALL].sy_call != nosys + && sysent[AFS_SYSCALL].sy_call != lkmnosys) { + printf("AFS_SYSCALL in use. aborting\n"); + error = -1; + break; + } + memset(&afs_vfsconf, 0, sizeof(struct vfsconf)); + strcpy(afs_vfsconf.vfc_name, "AFS"); + afs_vfsconf.vfc_vfsops = &afs_vfsops; + afs_vfsconf.vfc_typenum = -1; /* set by vfs_register */ + afs_vfsconf.vfc_flags = VFCF_NETWORK; + vfs_register(&afs_vfsconf); /* doesn't fail */ + vfs_add_vnodeops(&afs_vnodeop_opv_desc); + osi_Init(); +#if 0 + sysent[SYS_setgroups].sy_call = Afs_xsetgroups; + sysent[SYS_ioctl].sy_call = afs_xioctl; +#endif + old_handler = sysent[AFS_SYSCALL].sy_call; + sysent[AFS_SYSCALL].sy_call = afs3_syscall; + sysent[AFS_SYSCALL].sy_narg = 5; + inited = 1; + break; + case MOD_UNLOAD: #ifndef RXK_LISTENER_ENV - /* shutdown is incomplete unless RXK_LISTENER_ENV */ - printf("afs: I can't be unloaded yet\n"); - return -1; + /* shutdown is incomplete unless RXK_LISTENER_ENV */ + printf("afs: I can't be unloaded yet\n"); + return -1; #endif - if (! inited) { - error=0; - break; - } - if (afs_globalVFS) { - error=-1; - break; - } - if (vfs_unregister(&afs_vfsconf)) { - error=-1; - break; - } - vfs_rm_vnodeops(&afs_vnodeop_opv_desc); - sysent[SYS_ioctl].sy_call = ioctl; - sysent[SYS_setgroups].sy_call = setgroups; - sysent[AFS_SYSCALL].sy_narg = 0; - sysent[AFS_SYSCALL].sy_call = old_handler; - break; - } + if (!inited) { + error = 0; + break; + } + if (afs_globalVFS) { + error = -1; + break; + } + if (vfs_unregister(&afs_vfsconf)) { + error = -1; + break; + } + vfs_rm_vnodeops(&afs_vnodeop_opv_desc); +#if 0 + sysent[SYS_ioctl].sy_call = ioctl; + sysent[SYS_setgroups].sy_call = setgroups; +#endif + sysent[AFS_SYSCALL].sy_narg = 0; + sysent[AFS_SYSCALL].sy_call = old_handler; + break; + } - return (error); + return (error); } static moduledata_t afs_mod = { - "afs", - afs_module_handler, - &afs_mod + "afs", + afs_module_handler, + &afs_mod }; -DECLARE_MODULE(afs, afs_mod, SI_SUB_VFS, SI_ORDER_MIDDLE); +DECLARE_MODULE(afs, afs_mod, SI_SUB_VFS, SI_ORDER_MIDDLE); diff --git a/src/afs/FBSD/osi_prototypes.h b/src/afs/FBSD/osi_prototypes.h index b6bac7919..085eef7e3 100644 --- a/src/afs/FBSD/osi_prototypes.h +++ b/src/afs/FBSD/osi_prototypes.h @@ -9,12 +9,25 @@ /* * osi_prototypes.h * - * Exported macos support routines. + * Exported support routines. */ #ifndef _OSI_PROTO_H_ #define _OSI_PROTO_H_ +/* osi_file.c */ +extern afs_rwlock_t afs_xosi; + /* osi_misc.c */ extern int osi_lookupname(char *aname, enum uio_seg seg, int followlink, - struct vnode **dirvpp, struct vnode **vpp); + struct vnode **dirvpp, struct vnode **vpp); +extern void *osi_fbsd_alloc(size_t size, int dropglobal); +extern void osi_fbsd_free(void *p); + +/* osi_vfsops.c */ +#ifdef AFS_FBSD50_ENV +extern int afs_statfs(struct mount *mp, struct statfs *abp, struct thread *th); +#else +extern int afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p); +#endif + #endif /* _OSI_PROTO_H_ */ diff --git a/src/afs/FBSD/osi_sleep.c b/src/afs/FBSD/osi_sleep.c index 4728a201a..15786fbff 100644 --- a/src/afs/FBSD/osi_sleep.c +++ b/src/afs/FBSD/osi_sleep.c @@ -9,90 +9,140 @@ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_sleep.c,v 1.1.1.4 2002/09/26 18:58:09 hartmans Exp $"); - -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/param.h" +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_sleep.c,v 1.11 2004/03/10 23:01:51 rees Exp $"); +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#ifndef AFS_FBSD50_ENV static int osi_TimedSleep(char *event, afs_int32 ams, int aintok); -void afs_osi_Wakeup(char *event); -void afs_osi_Sleep(char *event); - static char waitV; +#endif -void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) +void +afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) { AFS_STATCNT(osi_InitWaitHandle); - achandle->proc = (caddr_t) 0; +#ifdef AFS_FBSD50_ENV + cv_init(&achandle->wh_condvar, "afscondvar"); + achandle->wh_inited = 1; +#else + achandle->proc = NULL; +#endif } /* cancel osi_Wait */ -void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) +/* XXX + * I can't tell -- is this supposed to be cv_signal() or cv_waitq_remove()? + * Or perhaps cv_broadcast()? + * Assuming cv_signal() is the desired meaning. -GAW + */ +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) { +#ifndef AFS_FBSD50_ENV caddr_t proc; +#endif AFS_STATCNT(osi_CancelWait); + +#ifdef AFS_FBSD50_ENV + /* XXX should not be necessary */ + if (!achandle->wh_inited) + return; + AFS_ASSERT_GLOCK(); + cv_signal(&achandle->wh_condvar); +#else proc = achandle->proc; - if (proc == 0) return; - achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ + if (proc == 0) + return; + achandle->proc = NULL; /* so dude can figure out he was signalled */ afs_osi_Wakeup(&waitV); +#endif } /* afs_osi_Wait * Waits for data on ahandle, or ams ms later. ahandle may be null. * Returns 0 if timeout and EINTR if signalled. */ -int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) +int +afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) { int code; - afs_int32 endTime, tid; +#ifdef AFS_FBSD50_ENV + struct timeval tv; + int ticks; +#else + afs_int32 endTime; +#endif AFS_STATCNT(osi_Wait); - endTime = osi_Time() + (ams/1000); +#ifdef AFS_FBSD50_ENV + tv.tv_sec = ams / 1000; + tv.tv_usec = (ams % 1000) * 1000; + ticks = tvtohz(&tv); + + AFS_ASSERT_GLOCK(); + if (ahandle == NULL) { + /* This is nasty and evil and rude. */ + code = msleep(&tv, &afs_global_mtx, (aintok ? PPAUSE|PCATCH : PVFS), + "afswait", ticks); + } else { + if (!ahandle->wh_inited) + afs_osi_InitWaitHandle(ahandle); /* XXX should not be needed */ + + if (aintok) + code = cv_timedwait_sig(&ahandle->wh_condvar, &afs_global_mtx, + ticks); + else + code = cv_timedwait(&ahandle->wh_condvar, &afs_global_mtx, ticks); + } +#else + endTime = osi_Time() + (ams / 1000); if (ahandle) - ahandle->proc = (caddr_t) curproc; + ahandle->proc = (caddr_t) curproc; do { AFS_ASSERT_GLOCK(); - code = 0; code = osi_TimedSleep(&waitV, ams, aintok); - - if (code) break; /* if something happened, quit now */ + if (code) + break; /* if something happened, quit now */ /* if we we're cancelled, quit now */ - if (ahandle && (ahandle->proc == (caddr_t) 0)) { + if (ahandle && (ahandle->proc == NULL)) { /* we've been signalled */ break; } } while (osi_Time() < endTime); +#endif return code; } - - - +/* + * All this gluck should probably also be replaced with CVs. + */ typedef struct afs_event { struct afs_event *next; /* next in hash chain */ char *event; /* lwp event: an address */ int refcount; /* Is it in use? */ int seq; /* Sequence number: this is incremented - by wakeup calls; wait will not return until - it changes */ + * by wakeup calls; wait will not return until + * it changes */ int cond; } afs_event_t; #define HASHSIZE 128 -afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */ +afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */ #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1)); int afs_evhashcnt = 0; /* Get and initialize event structure corresponding to lwp event (i.e. address) * */ -static afs_event_t *afs_getevent(char *event) +static afs_event_t * +afs_getevent(char *event) { afs_event_t *evp, *newp = 0; int hashcode; @@ -110,7 +160,7 @@ static afs_event_t *afs_getevent(char *event) evp = evp->next; } if (!newp) { - newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t)); + newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t)); afs_evhashcnt++; newp->next = afs_evhasht[hashcode]; afs_evhasht[hashcode] = newp; @@ -125,7 +175,8 @@ static afs_event_t *afs_getevent(char *event) #define relevent(evp) ((evp)->refcount--) -void afs_osi_Sleep(char *event) +void +afs_osi_Sleep(void *event) { struct afs_event *evp; int seq; @@ -134,19 +185,25 @@ void afs_osi_Sleep(char *event) seq = evp->seq; while (seq == evp->seq) { AFS_ASSERT_GLOCK(); +#ifdef AFS_FBSD50_ENV + msleep(event, &afs_global_mtx, PVFS, "afsslp", 0); +#else AFS_GUNLOCK(); - tsleep(event, PVFS, "afs_osi_Sleep", 0); + tsleep(event, PVFS, "afs_osi_Sleep", 0); AFS_GLOCK(); +#endif } relevent(evp); } -int afs_osi_SleepSig(char *event) +int +afs_osi_SleepSig(void *event) { afs_osi_Sleep(event); return 0; } +#ifndef AFS_FBSD50_ENV /* osi_TimedSleep * * Arguments: @@ -156,40 +213,45 @@ int afs_osi_SleepSig(char *event) * * Returns 0 if timeout and EINTR if signalled. */ -static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) +static int +osi_TimedSleep(char *event, afs_int32 ams, int aintok) { int code = 0; struct afs_event *evp; int ticks; - int seq,prio; - - ticks = ( ams * afs_hz )/1000; + int seq, prio; + + ticks = (ams * afs_hz) / 1000; evp = afs_getevent(event); - seq=evp->seq; + seq = evp->seq; AFS_GUNLOCK(); if (aintok) - prio=PCATCH|PPAUSE; + prio = PCATCH | PPAUSE; else - prio=PVFS; - code=tsleep(event, prio, "afs_osi_TimedSleep", ticks); + prio = PVFS; + code = tsleep(event, prio, "afs_osi_TimedSleep", ticks); AFS_GLOCK(); if (seq == evp->seq) - code=EINTR; + code = EINTR; relevent(evp); return code; } +#endif /* not AFS_FBSD50_ENV */ - -void afs_osi_Wakeup(char *event) +int +afs_osi_Wakeup(void *event) { + int ret = 1; struct afs_event *evp; evp = afs_getevent(event); if (evp->refcount > 1) { - evp->seq++; + evp->seq++; wakeup(event); + ret = 0; } relevent(evp); + return ret; } diff --git a/src/afs/FBSD/osi_vfsops.c b/src/afs/FBSD/osi_vfsops.c index 1617010fd..b66f76061 100644 --- a/src/afs/FBSD/osi_vfsops.c +++ b/src/afs/FBSD/osi_vfsops.c @@ -1,11 +1,12 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_vfsops.c,v 1.1.1.6 2002/09/26 18:58:09 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_vfsops.c,v 1.15 2004/03/10 23:01:51 rees Exp $"); -#include /* Standard vendor system headers */ -#include /* Afs-based standard headers */ -#include /* statistics */ +#include /* Standard vendor system headers */ +#include /* Afs-based standard headers */ +#include /* statistics */ #include #include #include @@ -13,54 +14,28 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_vfsops.c,v 1.1.1.6 2002/09 struct vcache *afs_globalVp = 0; struct mount *afs_globalVFS = 0; -int afs_pbuf_freecnt=-1; -int -afs_quotactl() -{ - return EOPNOTSUPP; -} - -int -afs_fhtovp(mp, fhp, vpp) -struct mount *mp; -struct fid *fhp; -struct vnode **vpp; -{ - - return (EINVAL); -} - -int -afs_vptofh(vp, fhp) -struct vnode *vp; -struct fid *fhp; -{ +int afs_pbuf_freecnt = -1; - return (EINVAL); -} +#ifdef AFS_FBSD50_ENV +#define THREAD_OR_PROC struct thread *p +#else +#define THREAD_OR_PROC struct proc *p +#endif int -afs_start(mp, flags, p) -struct mount *mp; -int flags; -struct proc *p; +afs_start(struct mount *mp, int flags, THREAD_OR_PROC) { afs_pbuf_freecnt = nswbuf / 2 + 1; - return (0); /* nothing to do. ? */ + return (0); /* nothing to do. ? */ } int -afs_mount(mp, path, data, ndp, p) -register struct mount *mp; -char *path; -caddr_t data; -struct nameidata *ndp; -struct proc *p; +afs_mount(struct mount *mp, char *path, caddr_t data, struct nameidata *ndp, + THREAD_OR_PROC) { /* ndp contains the mounted-from device. Just ignore it. - we also don't care about our proc struct. */ + * we also don't care about our proc struct. */ size_t size; - int error; if (mp->mnt_flag & MNT_UPDATE) return EINVAL; @@ -68,7 +43,7 @@ struct proc *p; AFS_GLOCK(); AFS_STATCNT(afs_mount); - if (afs_globalVFS) { /* Don't allow remounts. */ + if (afs_globalVFS) { /* Don't allow remounts. */ AFS_GUNLOCK(); return (EBUSY); } @@ -76,26 +51,30 @@ struct proc *p; afs_globalVFS = mp; mp->vfs_bsize = 8192; vfs_getnewfsid(mp); - mp->mnt_stat.f_iosize=8192; - - (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size); + mp->mnt_stat.f_iosize = 8192; + + (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size); memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN); strcpy(mp->mnt_stat.f_mntfromname, "AFS"); /* null terminated string "AFS" will fit, just leave it be. */ strcpy(mp->mnt_stat.f_fstypename, "afs"); AFS_GUNLOCK(); - (void) afs_statfs(mp, &mp->mnt_stat, p); + (void)afs_statfs(mp, &mp->mnt_stat, p); return 0; } int -afs_unmount(mp, flags, p) -struct mount *mp; -int flags; -struct proc *p; +afs_unmount(struct mount *mp, int flags, THREAD_OR_PROC) { - + + /* + * Release any remaining vnodes on this mount point. + * The `1' means that we hold one extra reference on + * the root vnode (this is just a guess right now). + * This has to be done outside the global lock. + */ + vflush(mp, 1, (flags & MNT_FORCE) ? FORCECLOSE : 0); AFS_GLOCK(); AFS_STATCNT(afs_unmount); afs_globalVFS = 0; @@ -106,76 +85,82 @@ struct proc *p; } int -afs_root(struct mount *mp, - struct vnode **vpp) +afs_root(struct mount *mp, struct vnode **vpp) { int error; struct vrequest treq; - register struct vcache *tvp=0; - struct proc *p=curproc; - struct ucred cr; + register struct vcache *tvp = 0; +#ifdef AFS_FBSD50_ENV + struct thread *td = curthread; + struct ucred *cr = td->td_ucred; +#else + struct proc *p = curproc; + struct ucred *cr = p->p_cred->pc_ucred; +#endif - cr=*p->p_cred->pc_ucred; AFS_GLOCK(); AFS_STATCNT(afs_root); + crhold(cr); if (afs_globalVp && (afs_globalVp->states & CStatd)) { tvp = afs_globalVp; - error=0; + error = 0; } else { - - if (!(error = afs_InitReq(&treq, &cr)) && - !(error = afs_CheckInit())) { - tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); +tryagain: + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + /* vrele() needed here or not? */ + afs_globalVp = NULL; + } + + if (!(error = afs_InitReq(&treq, cr)) && !(error = afs_CheckInit())) { + tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); /* we really want this to stay around */ - if (tvp) { - afs_globalVp = tvp; - } else - error = ENOENT; + if (tvp) + afs_globalVp = tvp; + else + error = ENOENT; } } if (tvp) { - osi_vnhold(tvp,0); - AFS_GUNLOCK(); - vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p); - AFS_GLOCK(); + struct vnode *vp = AFSTOV(tvp); + +#ifdef AFS_FBSD50_ENV + ASSERT_VI_UNLOCKED(vp, "afs_root"); +#endif + AFS_GUNLOCK(); + /* + * I'm uncomfortable about this. Shouldn't this happen at a + * higher level, and shouldn't we busy the top-level directory + * to prevent recycling? + */ +#ifdef AFS_FBSD50_ENV + error = vget(vp, LK_EXCLUSIVE | LK_RETRY, td); + vp->v_vflag |= VV_ROOT; +#else + error = vget(vp, LK_EXCLUSIVE | LK_RETRY, p); + vp->v_flag |= VROOT; +#endif + AFS_GLOCK(); + if (error != 0) + goto tryagain; + afs_globalVFS = mp; - *vpp = AFSTOV(tvp); - tvp->v.v_flag |= VROOT; + *vpp = vp; } afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *vpp, ICL_TYPE_INT32, error); AFS_GUNLOCK(); + crfree(cr); return error; } int -afs_vget(mp, lfl, vp) -struct mount *mp; -struct vnode *vp; -int lfl; -{ - int error; - printf("vget called. help!\n"); - if (vp->v_usecount < 0) { - vprint("bad usecount", vp); - panic("afs_vget"); - } - error = vget(vp, lfl, curproc); - if (!error) - insmntque(vp, afs_globalVFS); /* take off free list */ - return error; -} - -int afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p) +afs_statfs(struct mount *mp, struct statfs *abp, THREAD_OR_PROC) { AFS_GLOCK(); AFS_STATCNT(afs_statfs); -#if 0 - abp->f_type = MOUNT_AFS; -#endif abp->f_bsize = mp->vfs_bsize; abp->f_iosize = mp->vfs_bsize; @@ -184,49 +169,50 @@ int afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p) * storing something there. */ abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = - abp->f_ffree = 2000000; + abp->f_ffree = 2000000; abp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0]; abp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1]; if (abp != &mp->mnt_stat) { abp->f_type = mp->mnt_vfc->vfc_typenum; - memcpy((caddr_t)&abp->f_mntonname[0], (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN); - memcpy((caddr_t)&abp->f_mntfromname[0], (caddr_t)mp->mnt_stat.f_mntfromname, MNAMELEN); + memcpy((caddr_t) & abp->f_mntonname[0], + (caddr_t) mp->mnt_stat.f_mntonname, MNAMELEN); + memcpy((caddr_t) & abp->f_mntfromname[0], + (caddr_t) mp->mnt_stat.f_mntfromname, MNAMELEN); } AFS_GUNLOCK(); return 0; } -int afs_sync(mp, waitfor, cred, p) -struct mount *mp; -int waitfor; -struct ucred *cred; -struct prioc *p; +int +afs_sync(struct mount *mp, int waitfor, struct ucred *cred, THREAD_OR_PROC) { -return 0; -} - -int afs_sysctl() { - return EOPNOTSUPP; + return 0; } - -int afs_init(struct vfsconf *vfc) { - return 0; +int +afs_init(struct vfsconf *vfc) +{ + return 0; } struct vfsops afs_vfsops = { - afs_mount, - afs_start, - afs_unmount, - afs_root, - afs_quotactl, - afs_statfs, - afs_sync, - afs_vget, - afs_fhtovp, - afs_vptofh, - afs_init, - afs_sysctl + afs_mount, + afs_start, + afs_unmount, + afs_root, + vfs_stdquotactl, + afs_statfs, + afs_sync, + vfs_stdvget, + vfs_stdfhtovp, + vfs_stdcheckexp, + vfs_stdvptofh, + afs_init, + vfs_stduninit, + vfs_stdextattrctl, +#ifdef AFS_FBSD50_ENV + NULL, +#endif }; diff --git a/src/afs/FBSD/osi_vm.c b/src/afs/FBSD/osi_vm.c index 7dddab8ad..08db0570c 100644 --- a/src/afs/FBSD/osi_vm.c +++ b/src/afs/FBSD/osi_vm.c @@ -19,18 +19,46 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_vm.c,v 1.1.1.5 2002/09/26 18:58:09 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_vm.c,v 1.11 2004/03/10 23:01:51 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ #include #include #include #include +/* + * FreeBSD implementation notes: + * Most of these operations require us to frob vm_objects. Most + * functions require that the object be locked (with VM_OBJECT_LOCK) + * on entry and leave it locked on exit. In order to get the + * vm_object itself we call VOP_GETVOBJECT on the vnode; the + * locking protocol requires that we do so with the heavy vnode lock + * held and the vnode interlock unlocked, and it returns the same + * way. + * + * The locking protocol for vnodes is defined in + * kern/vnode_if.src and sys/vnode.h; the locking is still a work in + * progress, so some fields are (as of 5.1) still protected by Giant + * rather than an explicit lock. + */ + +#ifdef AFS_FBSD50_ENV +#define lock_vnode(v) vn_lock((v), LK_EXCLUSIVE | LK_RETRY, curthread) +#define unlock_vnode(v) VOP_UNLOCK((v), 0, curthread) +#else +#define lock_vnode(v) vn_lock((v), LK_EXCLUSIVE | LK_RETRY, curproc) +#define unlock_vnode(v) VOP_UNLOCK((v), 0, curproc) +/* need splvm() protection? */ +#define VM_OBJECT_LOCK(o) +#define VM_OBJECT_UNLOCK(o) +#endif + /* Try to discard pages, in order to recycle a vcache entry. * * We also make some sanity checks: ref count, open count, held locks. @@ -46,11 +74,11 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_vm.c,v 1.1.1.5 2002/09/26 * therefore obsolescent. * * OSF/1 Locking: VN_LOCK has been called. + * XXX - should FreeBSD have done this, too? Certainly looks like it. + * Maybe better to just call vnode_pager_setsize()? */ int -osi_VM_FlushVCache(avc, slept) - struct vcache *avc; - int *slept; +osi_VM_FlushVCache(struct vcache *avc, int *slept) { struct vm_object *obj; struct vnode *vp; @@ -65,20 +93,22 @@ osi_VM_FlushVCache(avc, slept) return EBUSY; AFS_GUNLOCK(); - vp=avc; - simple_lock(&vp->v_interlock); + vp = AFSTOV(avc); + lock_vnode(vp); if (VOP_GETVOBJECT(vp, &obj) == 0) { - vm_object_page_remove(obj, 0, 0, FALSE); + VM_OBJECT_LOCK(obj); + vm_object_page_remove(obj, 0, 0, FALSE); #if 0 - if (obj->ref_count == 0) { - vgonel(vp,curproc); - simple_lock(&vp->v_interlock); - vp->v_tag=VT_AFS; - SetAfsVnode(vp); - } + if (obj->ref_count == 0) { + vgonel(vp, curproc); + simple_lock(&vp->v_interlock); + vp->v_tag = VT_AFS; + SetAfsVnode(vp); + } #endif - } - simple_unlock(&vp->v_interlock); + VM_OBJECT_UNLOCK(obj); + } + unlock_vnode(vp); AFS_GLOCK(); return 0; @@ -90,35 +120,50 @@ osi_VM_FlushVCache(avc, slept) * re-obtained. */ void -osi_VM_StoreAllSegments(avc) - struct vcache *avc; +osi_VM_StoreAllSegments(struct vcache *avc) { struct vnode *vp; struct vm_object *obj; - int anyio,tries; + int anyio, tries; + ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); - tries=5; - vp=avc; + tries = 5; + vp = AFSTOV(avc); + + /* + * I don't understand this. Why not just call vm_object_page_clean() + * and be done with it? I particularly don't understand why we're calling + * vget() here. Is there some reason to believe that the vnode might + * be being recycled at this point? I don't think there's any need for + * this loop, either -- if we keep the vnode locked all the time, + * that and the object lock will prevent any new pages from appearing. + * The loop is what causes the race condition. -GAW + */ do { - anyio=0; - simple_lock(&vp->v_interlock); - if (VOP_GETVOBJECT(vp, &obj) == 0 && - (obj->flags & OBJ_MIGHTBEDIRTY)) { - if (!vget(vp, - LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) { - if (VOP_GETVOBJECT(vp, &obj) == 0) { - vm_object_page_clean(obj, 0, 0, OBJPC_SYNC); - anyio = 1; - } - vput(vp); - } - } else { - simple_unlock(&vp->v_interlock); - } + anyio = 0; + lock_vnode(vp); + if (VOP_GETVOBJECT(vp, &obj) == 0 && (obj->flags & OBJ_MIGHTBEDIRTY)) { + /* XXX - obj locking? */ + unlock_vnode(vp); +#ifdef AFS_FBSD50_ENV + if (!vget(vp, LK_EXCLUSIVE | LK_RETRY, curthread)) { +#else + if (!vget(vp, LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) { +#endif + if (VOP_GETVOBJECT(vp, &obj) == 0) { + VM_OBJECT_LOCK(obj); + vm_object_page_clean(obj, 0, 0, OBJPC_SYNC); + VM_OBJECT_UNLOCK(obj); + anyio = 1; + } + vput(vp); + } + } else + unlock_vnode(vp); } while (anyio && (--tries > 0)); AFS_GLOCK(); - ObtainWriteLock(&avc->lock,94); + ObtainWriteLock(&avc->lock, 94); } /* Try to invalidate pages, for "fs flush" or "fs flushv"; or @@ -131,43 +176,56 @@ osi_VM_StoreAllSegments(avc) * be some pages around when we return, newly created by concurrent activity. */ void -osi_VM_TryToSmush(avc, acred, sync) - struct vcache *avc; - struct AFS_UCRED *acred; - int sync; +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { struct vnode *vp; struct vm_object *obj; int anyio, tries; + ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); - tries=5; - vp=avc; + tries = 5; + vp = AFSTOV(avc); do { - anyio=0; - simple_lock(&vp->v_interlock); - if (VOP_GETVOBJECT(vp, &obj) == 0 && - (obj->flags & OBJ_MIGHTBEDIRTY)) { - if (!vget(vp, - LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) { - if (VOP_GETVOBJECT(vp, &obj) == 0) { - vm_object_page_clean(obj, 0, 0, OBJPC_SYNC); - anyio = 1; - } - vput(vp); - } - } else { - simple_unlock(&vp->v_interlock); - } + anyio = 0; + lock_vnode(vp); + /* See the comments above. */ + if (VOP_GETVOBJECT(vp, &obj) == 0 && (obj->flags & OBJ_MIGHTBEDIRTY)) { + /* XXX - obj locking */ + unlock_vnode(vp); +#ifdef AFS_FBSD50_ENV + if (!vget(vp, LK_EXCLUSIVE | LK_RETRY, curthread)) { +#else + if (!vget(vp, LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) { +#endif + if (VOP_GETVOBJECT(vp, &obj) == 0) { + VM_OBJECT_LOCK(obj); + /* + * Do we really want OBJPC_SYNC? OBJPC_INVAL would be + * faster, if invalidation is really what we are being + * asked to do. (It would make more sense, too, since + * otherwise this function is practically identical to + * osi_VM_StoreAllSegments().) -GAW + */ + vm_object_page_clean(obj, 0, 0, OBJPC_SYNC); + VM_OBJECT_UNLOCK(obj); + anyio = 1; + } + vput(vp); + } + } else + unlock_vnode(vp); } while (anyio && (--tries > 0)); - simple_lock(&vp->v_interlock); + lock_vnode(vp); if (VOP_GETVOBJECT(vp, &obj) == 0) { - vm_object_page_remove(obj, 0, 0, FALSE); + VM_OBJECT_LOCK(obj); + vm_object_page_remove(obj, 0, 0, FALSE); + VM_OBJECT_UNLOCK(obj); } - simple_unlock(&vp->v_interlock); - /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0);*/ + unlock_vnode(vp); + /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0); */ AFS_GLOCK(); - ObtainWriteLock(&avc->lock,59); + ObtainWriteLock(&avc->lock, 59); } /* Purge VM for a file when its callback is revoked. @@ -175,19 +233,19 @@ osi_VM_TryToSmush(avc, acred, sync) * Locking: No lock is held, not even the global lock. */ void -osi_VM_FlushPages(avc, credp) - struct vcache *avc; - struct AFS_UCRED *credp; +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { struct vnode *vp; struct vm_object *obj; - vp=avc; - simple_lock(&vp->v_interlock); + + vp = AFSTOV(avc); + ASSERT_VOP_LOCKED(vp, __func__); if (VOP_GETVOBJECT(vp, &obj) == 0) { - vm_object_page_remove(obj, 0, 0, FALSE); + VM_OBJECT_LOCK(obj); + vm_object_page_remove(obj, 0, 0, FALSE); + VM_OBJECT_UNLOCK(obj); } - simple_unlock(&vp->v_interlock); - /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0);*/ + /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0); */ } /* Purge pages beyond end-of-file, when truncating a file. @@ -197,10 +255,7 @@ osi_VM_FlushPages(avc, credp) * it only works on Solaris. */ void -osi_VM_Truncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { vnode_pager_setsize(AFSTOV(avc), alen); } diff --git a/src/afs/FBSD/osi_vnodeops.c b/src/afs/FBSD/osi_vnodeops.c index 574d0a493..be0030c32 100644 --- a/src/afs/FBSD/osi_vnodeops.c +++ b/src/afs/FBSD/osi_vnodeops.c @@ -1,14 +1,64 @@ +/* + * A large chunk of this file appears to be copied directly from + * sys/nfsclient/nfs_bio.c, which has the following license: + */ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)nfs_bio.c 8.9 (Berkeley) 3/30/95 + */ +/* + * Pursuant to a statement of U.C. Berkeley dated 1999-07-22, this license + * is amended to drop clause (3) above. + */ + #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/FBSD/osi_vnodeops.c,v 1.1.1.4 2002/09/26 18:58:10 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/FBSD/osi_vnodeops.c,v 1.18 2004/03/19 15:37:10 rees Exp $"); -#include /* Standard vendor system headers */ -#include /* Afs-based standard headers */ -#include /* statistics */ +#include /* Standard vendor system headers */ +#include /* Afs-based standard headers */ +#include /* statistics */ #include #include +#include +#ifndef AFS_FBSD50_ENV #include +#endif #include #include #include @@ -28,8 +78,11 @@ int afs_vop_write(struct vop_write_args *); int afs_vop_getpages(struct vop_getpages_args *); int afs_vop_putpages(struct vop_putpages_args *); int afs_vop_ioctl(struct vop_ioctl_args *); +static int afs_vop_pathconf(struct vop_pathconf_args *); int afs_vop_poll(struct vop_poll_args *); +#ifndef AFS_FBSD50_ENV int afs_vop_mmap(struct vop_mmap_args *); +#endif int afs_vop_fsync(struct vop_fsync_args *); int afs_vop_remove(struct vop_remove_args *); int afs_vop_link(struct vop_link_args *); @@ -54,50 +107,52 @@ int afs_vop_advlock(struct vop_advlock_args *); /* Global vfs data structures for AFS. */ vop_t **afs_vnodeop_p; struct vnodeopv_entry_desc afs_vnodeop_entries[] = { - { &vop_default_desc, (vop_t *) vop_eopnotsupp }, - { &vop_access_desc, (vop_t *) afs_vop_access }, /* access */ - { &vop_advlock_desc, (vop_t *) afs_vop_advlock }, /* advlock */ - { &vop_bmap_desc, (vop_t *) afs_vop_bmap }, /* bmap */ - { &vop_bwrite_desc, (vop_t *) vop_stdbwrite }, - { &vop_close_desc, (vop_t *) afs_vop_close }, /* close */ - { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject }, - { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject }, - { &vop_create_desc, (vop_t *) afs_vop_create }, /* create */ - { &vop_fsync_desc, (vop_t *) afs_vop_fsync }, /* fsync */ - { &vop_getattr_desc, (vop_t *) afs_vop_getattr }, /* getattr */ - { &vop_getpages_desc, (vop_t *) afs_vop_getpages }, /* read */ - { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject }, - { &vop_putpages_desc, (vop_t *) afs_vop_putpages }, /* write */ - { &vop_inactive_desc, (vop_t *) afs_vop_inactive }, /* inactive */ - { &vop_islocked_desc, (vop_t *) afs_vop_islocked }, /* islocked */ - { &vop_lease_desc, (vop_t *) vop_null }, - { &vop_link_desc, (vop_t *) afs_vop_link }, /* link */ - { &vop_lock_desc, (vop_t *) afs_vop_lock }, /* lock */ - { &vop_lookup_desc, (vop_t *) afs_vop_lookup }, /* lookup */ - { &vop_mkdir_desc, (vop_t *) afs_vop_mkdir }, /* mkdir */ - { &vop_mknod_desc, (vop_t *) afs_vop_mknod }, /* mknod */ - { &vop_mmap_desc, (vop_t *) afs_vop_mmap }, /* mmap */ - { &vop_open_desc, (vop_t *) afs_vop_open }, /* open */ - { &vop_poll_desc, (vop_t *) afs_vop_poll }, /* select */ - { &vop_print_desc, (vop_t *) afs_vop_print }, /* print */ - { &vop_read_desc, (vop_t *) afs_vop_read }, /* read */ - { &vop_readdir_desc, (vop_t *) afs_vop_readdir }, /* readdir */ - { &vop_readlink_desc, (vop_t *) afs_vop_readlink }, /* readlink */ - { &vop_reclaim_desc, (vop_t *) afs_vop_reclaim }, /* reclaim */ - { &vop_remove_desc, (vop_t *) afs_vop_remove }, /* remove */ - { &vop_rename_desc, (vop_t *) afs_vop_rename }, /* rename */ - { &vop_rmdir_desc, (vop_t *) afs_vop_rmdir }, /* rmdir */ - { &vop_setattr_desc, (vop_t *) afs_vop_setattr }, /* setattr */ - { &vop_strategy_desc, (vop_t *) afs_vop_strategy }, /* strategy */ - { &vop_symlink_desc, (vop_t *) afs_vop_symlink }, /* symlink */ - { &vop_unlock_desc, (vop_t *) afs_vop_unlock }, /* unlock */ - { &vop_write_desc, (vop_t *) afs_vop_write }, /* write */ - { &vop_ioctl_desc, (vop_t *) afs_vop_ioctl }, /* XXX ioctl */ - /*{ &vop_seek_desc, afs_vop_seek },*/ /* seek */ - { NULL, NULL } + {&vop_default_desc, (vop_t *) vop_defaultop}, + {&vop_access_desc, (vop_t *) afs_vop_access}, /* access */ + {&vop_advlock_desc, (vop_t *) afs_vop_advlock}, /* advlock */ + {&vop_bmap_desc, (vop_t *) afs_vop_bmap}, /* bmap */ +#ifndef AFS_FBSD50_ENV + {&vop_bwrite_desc, (vop_t *) vop_stdbwrite}, +#endif + {&vop_close_desc, (vop_t *) afs_vop_close}, /* close */ + {&vop_createvobject_desc, (vop_t *) vop_stdcreatevobject}, + {&vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject}, + {&vop_create_desc, (vop_t *) afs_vop_create}, /* create */ + {&vop_fsync_desc, (vop_t *) afs_vop_fsync}, /* fsync */ + {&vop_getattr_desc, (vop_t *) afs_vop_getattr}, /* getattr */ + {&vop_getpages_desc, (vop_t *) afs_vop_getpages}, /* read */ + {&vop_getvobject_desc, (vop_t *) vop_stdgetvobject}, + {&vop_putpages_desc, (vop_t *) afs_vop_putpages}, /* write */ + {&vop_inactive_desc, (vop_t *) afs_vop_inactive}, /* inactive */ + {&vop_lease_desc, (vop_t *) vop_null}, + {&vop_link_desc, (vop_t *) afs_vop_link}, /* link */ + {&vop_lookup_desc, (vop_t *) afs_vop_lookup}, /* lookup */ + {&vop_mkdir_desc, (vop_t *) afs_vop_mkdir}, /* mkdir */ + {&vop_mknod_desc, (vop_t *) afs_vop_mknod}, /* mknod */ +#ifndef AFS_FBSD50_ENV + {&vop_mmap_desc, (vop_t *) afs_vop_mmap}, /* mmap */ +#endif + {&vop_open_desc, (vop_t *) afs_vop_open}, /* open */ + {&vop_pathconf_desc, (vop_t *) afs_vop_pathconf}, /* pathconf */ + {&vop_poll_desc, (vop_t *) afs_vop_poll}, /* select */ + {&vop_print_desc, (vop_t *) afs_vop_print}, /* print */ + {&vop_read_desc, (vop_t *) afs_vop_read}, /* read */ + {&vop_readdir_desc, (vop_t *) afs_vop_readdir}, /* readdir */ + {&vop_readlink_desc, (vop_t *) afs_vop_readlink}, /* readlink */ + {&vop_reclaim_desc, (vop_t *) afs_vop_reclaim}, /* reclaim */ + {&vop_remove_desc, (vop_t *) afs_vop_remove}, /* remove */ + {&vop_rename_desc, (vop_t *) afs_vop_rename}, /* rename */ + {&vop_rmdir_desc, (vop_t *) afs_vop_rmdir}, /* rmdir */ + {&vop_setattr_desc, (vop_t *) afs_vop_setattr}, /* setattr */ + {&vop_strategy_desc, (vop_t *) afs_vop_strategy}, /* strategy */ + {&vop_symlink_desc, (vop_t *) afs_vop_symlink}, /* symlink */ + {&vop_write_desc, (vop_t *) afs_vop_write}, /* write */ + {&vop_ioctl_desc, (vop_t *) afs_vop_ioctl}, /* XXX ioctl */ + /*{ &vop_seek_desc, afs_vop_seek }, *//* seek */ + {NULL, NULL} }; struct vnodeopv_desc afs_vnodeop_opv_desc = - { &afs_vnodeop_p, afs_vnodeop_entries }; + { &afs_vnodeop_p, afs_vnodeop_entries }; #define GETNAME() \ struct componentname *cnp = ap->a_cnp; \ @@ -107,29 +162,129 @@ struct vnodeopv_desc afs_vnodeop_opv_desc = name[cnp->cn_namelen] = '\0' #define DROPNAME() FREE(name, M_TEMP) - +/* This is a bit of a cheat... */ +#ifdef AFS_FBSD50_ENV +#define a_p a_td +#endif + +/* + * Mosty copied from sys/ufs/ufs/ufs_vnops.c:ufs_pathconf(). + * We should know the correct answers to these questions with + * respect to the AFS protocol (which may differ from the UFS + * values) but for the moment this will do. + */ +static int +afs_vop_pathconf(struct vop_pathconf_args *ap) +{ + int error; + + error = 0; + switch (ap->a_name) { + case _PC_LINK_MAX: + *ap->a_retval = LINK_MAX; + break; + case _PC_NAME_MAX: + *ap->a_retval = NAME_MAX; + break; + case _PC_PATH_MAX: + *ap->a_retval = PATH_MAX; + break; + case _PC_PIPE_BUF: + *ap->a_retval = PIPE_BUF; + break; + case _PC_CHOWN_RESTRICTED: + *ap->a_retval = 1; + break; + case _PC_NO_TRUNC: + *ap->a_retval = 1; + break; +#ifdef _PC_ACL_EXTENDED + case _PC_ACL_EXTENDED: + *ap->a_retval = 0; + break; + case _PC_ACL_PATH_MAX: + *ap->a_retval = 3; + break; +#endif +#ifdef _PC_MAC_PRESENT + case _PC_MAC_PRESENT: + *ap->a_retval = 0; + break; +#endif +#ifdef _PC_ASYNC_IO + case _PC_ASYNC_IO: + /* _PC_ASYNC_IO should have been handled by upper layers. */ + KASSERT(0, ("_PC_ASYNC_IO should not get here")); + error = EINVAL; + break; + case _PC_PRIO_IO: + *ap->a_retval = 0; + break; + case _PC_SYNC_IO: + *ap->a_retval = 0; + break; +#endif +#ifdef _PC_ALLOC_SIZE_MIN + case _PC_ALLOC_SIZE_MIN: + *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize; + break; +#endif +#ifdef _PC_FILESIZEBITS + case _PC_FILESIZEBITS: + *ap->a_retval = 32; /* XXX */ + break; +#endif +#ifdef _PC_REC_INCR_XFER_SIZE + case _PC_REC_INCR_XFER_SIZE: + *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize; + break; + case _PC_REC_MAX_XFER_SIZE: + *ap->a_retval = -1; /* means ``unlimited'' */ + break; + case _PC_REC_MIN_XFER_SIZE: + *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize; + break; + case _PC_REC_XFER_ALIGN: + *ap->a_retval = PAGE_SIZE; + break; +#endif +#ifdef _PC_SYMLINK_MAX + case _PC_SYMLINK_MAX: + *ap->a_retval = MAXPATHLEN; + break; +#endif + default: + error = EINVAL; + break; + } + return (error); +} int afs_vop_lookup(ap) -struct vop_lookup_args /* { - struct vnodeop_desc * a_desc; - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - } */ *ap; + struct vop_lookup_args /* { + * struct vnodeop_desc * a_desc; + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * } */ *ap; { int error; struct vcache *vcp; struct vnode *vp, *dvp; register int flags = ap->a_cnp->cn_flags; - int lockparent; /* 1 => lockparent flag is set */ - int wantparent; /* 1 => wantparent or lockparent flag */ - struct proc *p; + int lockparent; /* 1 => lockparent flag is set */ + int wantparent; /* 1 => wantparent or lockparent flag */ +#ifdef AFS_FBSD50_ENV + struct thread *p = ap->a_cnp->cn_thread; +#else + struct proc *p = ap->a_cnp->cn_proc; +#endif GETNAME(); - p=cnp->cn_proc; + lockparent = flags & LOCKPARENT; - wantparent = flags & (LOCKPARENT|WANTPARENT); + wantparent = flags & (LOCKPARENT | WANTPARENT); if (ap->a_dvp->v_type != VDIR) { *ap->a_vpp = 0; @@ -137,16 +292,16 @@ struct vop_lookup_args /* { return ENOTDIR; } dvp = ap->a_dvp; - if (flags & ISDOTDOT) - VOP_UNLOCK(dvp, 0, p); + if (flags & ISDOTDOT) + VOP_UNLOCK(dvp, 0, p); AFS_GLOCK(); error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred); AFS_GUNLOCK(); if (error) { - if (flags & ISDOTDOT) - VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p); - if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) && - (flags & ISLASTCN) && error == ENOENT) + if (flags & ISDOTDOT) + VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p); + if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) + && (flags & ISLASTCN) && error == ENOENT) error = EJUSTRETURN; if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)) cnp->cn_flags |= SAVENAME; @@ -154,34 +309,34 @@ struct vop_lookup_args /* { *ap->a_vpp = 0; return (error); } - vp = AFSTOV(vcp); /* always get a node if no error */ + vp = AFSTOV(vcp); /* always get a node if no error */ /* The parent directory comes in locked. We unlock it on return - unless the caller wants it left locked. - we also always return the vnode locked. */ + * unless the caller wants it left locked. + * we also always return the vnode locked. */ if (flags & ISDOTDOT) { vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); - /* always return the child locked */ - if (lockparent && (flags & ISLASTCN) && - (error = vn_lock(dvp, LK_EXCLUSIVE, p))) { - vput(vp); - DROPNAME(); - return (error); - } + /* always return the child locked */ + if (lockparent && (flags & ISLASTCN) + && (error = vn_lock(dvp, LK_EXCLUSIVE, p))) { + vput(vp); + DROPNAME(); + return (error); + } } else if (vp == dvp) { /* they're the same; afs_lookup() already ref'ed the leaf. - It came in locked, so we don't need to ref OR lock it */ + * It came in locked, so we don't need to ref OR lock it */ } else { if (!lockparent || !(flags & ISLASTCN)) - VOP_UNLOCK(dvp, 0, p); /* done with parent. */ + VOP_UNLOCK(dvp, 0, p); /* done with parent. */ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); - /* always return the child locked */ + /* always return the child locked */ } *ap->a_vpp = vp; - if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN)) || - (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))) + if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN)) + || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))) cnp->cn_flags |= SAVENAME; DROPNAME(); @@ -190,35 +345,39 @@ struct vop_lookup_args /* { int afs_vop_create(ap) - struct vop_create_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - struct vattr *a_vap; - } */ *ap; + struct vop_create_args /* { + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * struct vattr *a_vap; + * } */ *ap; { int error = 0; struct vcache *vcp; register struct vnode *dvp = ap->a_dvp; - struct proc *p; +#ifdef AFS_FBSD50_ENV + struct thread *p = ap->a_cnp->cn_thread; +#else + struct proc *p = ap->a_cnp->cn_proc; +#endif GETNAME(); - p=cnp->cn_proc; AFS_GLOCK(); - error = afs_create(VTOAFS(dvp), name, ap->a_vap, ap->a_vap->va_vaflags & VA_EXCLUSIVE? EXCL : NONEXCL, - ap->a_vap->va_mode, &vcp, - cnp->cn_cred); + error = + afs_create(VTOAFS(dvp), name, ap->a_vap, + ap->a_vap->va_vaflags & VA_EXCLUSIVE ? EXCL : NONEXCL, + ap->a_vap->va_mode, &vcp, cnp->cn_cred); AFS_GUNLOCK(); if (error) { DROPNAME(); - return(error); + return (error); } if (vcp) { *ap->a_vpp = AFSTOV(vcp); - vn_lock(AFSTOV(vcp), LK_EXCLUSIVE| LK_RETRY, p); - } - else *ap->a_vpp = 0; + vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p); + } else + *ap->a_vpp = 0; DROPNAME(); return error; @@ -226,49 +385,50 @@ afs_vop_create(ap) int afs_vop_mknod(ap) - struct vop_mknod_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - struct vattr *a_vap; - } */ *ap; + struct vop_mknod_args /* { + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * struct vattr *a_vap; + * } */ *ap; { - return(ENODEV); + return (ENODEV); } #if 0 -static int validate_vops(struct vnode *vp, int after) +static int +validate_vops(struct vnode *vp, int after) { - int ret=0; - struct vnodeopv_entry_desc *this; - for (this=afs_vnodeop_entries; this->opve_op; this++) { + int ret = 0; + struct vnodeopv_entry_desc *this; + for (this = afs_vnodeop_entries; this->opve_op; this++) { if (vp->v_op[this->opve_op->vdesc_offset] != this->opve_impl) { - if (!ret) { - printf("v_op %d ", after); - vprint("check", vp); - } - ret=1; - printf("For oper %d (%s), func is %p, not %p", - this->opve_op->vdesc_offset, this->opve_op->vdesc_name, - vp->v_op[this->opve_op->vdesc_offset], this->opve_impl); - } - } - return ret; -} + if (!ret) { + printf("v_op %d ", after); + vprint("check", vp); + } + ret = 1; + printf("For oper %d (%s), func is %p, not %p", + this->opve_op->vdesc_offset, this->opve_op->vdesc_name, + vp->v_op[this->opve_op->vdesc_offset], this->opve_impl); + } + } + return ret; +} #endif int afs_vop_open(ap) - struct vop_open_args /* { - struct vnode *a_vp; - int a_mode; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_open_args /* { + * struct vnode *a_vp; + * int a_mode; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int error; int bad; struct vcache *vc = VTOAFS(ap->a_vp); - bad=0; + bad = 0; AFS_GLOCK(); error = afs_open(&vc, ap->a_mode, ap->a_cred); #ifdef DIAGNOSTIC @@ -276,7 +436,7 @@ afs_vop_open(ap) panic("AFS open changed vnode!"); #endif afs_BozonLock(&vc->pvnLock, vc); - osi_FlushPages(vc); + osi_FlushPages(vc, ap->a_cred); afs_BozonUnlock(&vc->pvnLock, vc); AFS_GUNLOCK(); return error; @@ -284,22 +444,22 @@ afs_vop_open(ap) int afs_vop_close(ap) - struct vop_close_args /* { - struct vnode *a_vp; - int a_fflag; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_close_args /* { + * struct vnode *a_vp; + * int a_fflag; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int code; - struct vcache *avc=ap->a_vp; + struct vcache *avc = VTOAFS(ap->a_vp); AFS_GLOCK(); - if (ap->a_cred) - code=afs_close(avc, ap->a_fflag, ap->a_cred, ap->a_p); + if (ap->a_cred) + code = afs_close(avc, ap->a_fflag, ap->a_cred); else - code=afs_close(avc, ap->a_fflag, &afs_osi_cred, ap->a_p); + code = afs_close(avc, ap->a_fflag, afs_osi_credp); afs_BozonLock(&avc->pvnLock, avc); - osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */ + osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ afs_BozonUnlock(&avc->pvnLock, avc); AFS_GUNLOCK(); return code; @@ -307,77 +467,83 @@ afs_vop_close(ap) int afs_vop_access(ap) - struct vop_access_args /* { - struct vnode *a_vp; - int a_mode; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_access_args /* { + * struct vnode *a_vp; + * int a_mode; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int code; AFS_GLOCK(); - code=afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred); + code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred); AFS_GUNLOCK(); return code; } + int afs_vop_getattr(ap) - struct vop_getattr_args /* { - struct vnode *a_vp; - struct vattr *a_vap; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_getattr_args /* { + * struct vnode *a_vp; + * struct vattr *a_vap; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int code; AFS_GLOCK(); - code=afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); + code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); AFS_GUNLOCK(); return code; } + int afs_vop_setattr(ap) - struct vop_setattr_args /* { - struct vnode *a_vp; - struct vattr *a_vap; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_setattr_args /* { + * struct vnode *a_vp; + * struct vattr *a_vap; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { int code; AFS_GLOCK(); - code=afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); + code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); AFS_GUNLOCK(); return code; -}int +} + +int afs_vop_read(ap) - struct vop_read_args /* { - struct vnode *a_vp; - struct uio *a_uio; - int a_ioflag; - struct ucred *a_cred; - -} */ *ap; + struct vop_read_args /* { + * struct vnode *a_vp; + * struct uio *a_uio; + * int a_ioflag; + * struct ucred *a_cred; + * + * } */ *ap; { int code; - struct vcache *avc=VTOAFS(ap->a_vp); + struct vcache *avc = VTOAFS(ap->a_vp); AFS_GLOCK(); afs_BozonLock(&avc->pvnLock, avc); - osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */ - code=afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0); + osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ + code = afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0); afs_BozonUnlock(&avc->pvnLock, avc); AFS_GUNLOCK(); return code; } + +/* struct vop_getpages_args { + * struct vnode *a_vp; + * vm_page_t *a_m; + * int a_count; + * int a_reqpage; + * vm_oofset_t a_offset; + * }; + */ int -afs_vop_getpages(ap) - struct vop_getpages_args /* { - struct vnode *a_vp; - vm_page_t *a_m; - int a_count; - int a_reqpage; - vm_oofset_t a_offset; - } */ *ap; +afs_vop_getpages(struct vop_getpages_args *ap) { int code; int i, nextoff, size, toff, npages; @@ -385,13 +551,20 @@ afs_vop_getpages(ap) struct iovec iov; struct buf *bp; vm_offset_t kva; - struct vcache *avc=VTOAFS(ap->a_vp); + vm_object_t object; + struct vnode *vp; + struct vcache *avc; - if (avc->v.v_object == NULL) { - printf("afs_getpages: called with non-merged cache vnode??\n"); - return VM_PAGER_ERROR; +#ifdef AFS_FBSD50_ENV + GIANT_REQUIRED; +#endif + vp = ap->a_vp; + avc = VTOAFS(vp); + if ((object = vp->v_object) == NULL) { + printf("afs_getpages: called with non-merged cache vnode??\n"); + return VM_PAGER_ERROR; } - npages=btoc(ap->a_count); + npages = btoc(ap->a_count); /* * If the requested page is partially valid, just return it and * allow the pager to zero-out the blanks. Partially valid pages @@ -399,127 +572,175 @@ afs_vop_getpages(ap) */ { - vm_page_t m = ap->a_m[ap->a_reqpage]; - - if (m->valid != 0) { - /* handled by vm_fault now */ - /* vm_page_zero_invalid(m, TRUE); */ - for (i = 0; i < npages; ++i) { - if (i != ap->a_reqpage) - vnode_pager_freepage(ap->a_m[i]); - } - return(0); - } + vm_page_t m = ap->a_m[ap->a_reqpage]; + +#ifdef AFS_FBSD50_ENV + VM_OBJECT_LOCK(object); + vm_page_lock_queues(); +#endif + if (m->valid != 0) { + /* handled by vm_fault now */ + /* vm_page_zero_invalid(m, TRUE); */ + for (i = 0; i < npages; ++i) { + if (i != ap->a_reqpage) + vm_page_free(ap->a_m[i]); + } +#ifdef AFS_FBSD50_ENV + vm_page_unlock_queues(); + VM_OBJECT_UNLOCK(object); +#endif + return (0); + } +#ifdef AFS_FBSD50_ENV + vm_page_unlock_queues(); + VM_OBJECT_UNLOCK(object); +#endif } bp = getpbuf(&afs_pbuf_freecnt); + kva = (vm_offset_t) bp->b_data; pmap_qenter(kva, ap->a_m, npages); - iov.iov_base=(caddr_t)kva; - iov.iov_len=ap->a_count; - uio.uio_iov=&iov; - uio.uio_iovcnt=1; - uio.uio_offset=IDX_TO_OFF(ap->a_m[0]->pindex); - uio.uio_resid=ap->a_count; - uio.uio_segflg=UIO_SYSSPACE; - uio.uio_rw=UIO_READ; - uio.uio_procp=curproc; +#ifdef AFS_FBSD50_ENV + cnt.v_vnodein++; + cnt.v_vnodepgsin += npages; +#endif + + iov.iov_base = (caddr_t) kva; + iov.iov_len = ap->a_count; + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex); + uio.uio_resid = ap->a_count; + uio.uio_segflg = UIO_SYSSPACE; + uio.uio_rw = UIO_READ; +#ifdef AFS_FBSD50_ENV + uio.uio_td = curthread; +#else + uio.uio_procp = curproc; +#endif + AFS_GLOCK(); afs_BozonLock(&avc->pvnLock, avc); - osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */ - code=afs_read(avc, &uio, curproc->p_cred->pc_ucred, 0, 0, 0); + osi_FlushPages(avc, osi_curcred()); /* hold bozon lock, but not basic vnode lock */ + code = afs_read(avc, &uio, osi_curcred(), 0, 0, 0); afs_BozonUnlock(&avc->pvnLock, avc); AFS_GUNLOCK(); pmap_qremove(kva, npages); relpbuf(bp, &afs_pbuf_freecnt); + if (code && (uio.uio_resid == ap->a_count)) { - for (i = 0; i < npages; ++i) { - if (i != ap->a_reqpage) - vnode_pager_freepage(ap->a_m[i]); - } - return VM_PAGER_ERROR; +#ifdef AFS_FBSD50_ENV + VM_OBJECT_LOCK(object); + vm_page_lock_queues(); +#endif + for (i = 0; i < npages; ++i) { + if (i != ap->a_reqpage) + vm_page_free(ap->a_m[i]); + } +#ifdef AFS_FBSD50_ENV + vm_page_unlock_queues(); + VM_OBJECT_UNLOCK(object); +#endif + return VM_PAGER_ERROR; } + size = ap->a_count - uio.uio_resid; +#ifdef AFS_FBSD50_ENV + VM_OBJECT_LOCK(object); + vm_page_lock_queues(); +#endif for (i = 0, toff = 0; i < npages; i++, toff = nextoff) { - vm_page_t m; - nextoff = toff + PAGE_SIZE; - m = ap->a_m[i]; - - m->flags &= ~PG_ZERO; - - if (nextoff <= size) { - /* - * Read operation filled an entire page - */ - m->valid = VM_PAGE_BITS_ALL; - vm_page_undirty(m); - } else if (size > toff) { - /* - * Read operation filled a partial page. - */ - m->valid = 0; - vm_page_set_validclean(m, 0, size - toff); - /* handled by vm_fault now */ - /* vm_page_zero_invalid(m, TRUE); */ - } - - if (i != ap->a_reqpage) { - /* - * Whether or not to leave the page activated is up in - * the air, but we should put the page on a page queue - * somewhere (it already is in the object). Result: - * It appears that emperical results show that - * deactivating pages is best. - */ - - /* - * Just in case someone was asking for this page we - * now tell them that it is ok to use. - */ - if (!code) { - if (m->flags & PG_WANTED) - vm_page_activate(m); - else - vm_page_deactivate(m); - vm_page_wakeup(m); - } else { - vnode_pager_freepage(m); - } - } + vm_page_t m; + nextoff = toff + PAGE_SIZE; + m = ap->a_m[i]; + + m->flags &= ~PG_ZERO; + + if (nextoff <= size) { + /* + * Read operation filled an entire page + */ + m->valid = VM_PAGE_BITS_ALL; + vm_page_undirty(m); + } else if (size > toff) { + /* + * Read operation filled a partial page. + */ + m->valid = 0; + vm_page_set_validclean(m, 0, size - toff); + /* handled by vm_fault now */ + /* vm_page_zero_invalid(m, TRUE); */ + } + + if (i != ap->a_reqpage) { + /* + * Whether or not to leave the page activated is up in + * the air, but we should put the page on a page queue + * somewhere (it already is in the object). Result: + * It appears that emperical results show that + * deactivating pages is best. + */ + + /* + * Just in case someone was asking for this page we + * now tell them that it is ok to use. + */ + if (!code) { + if (m->flags & PG_WANTED) + vm_page_activate(m); + else + vm_page_deactivate(m); + vm_page_wakeup(m); + } else { + vm_page_free(m); + } + } } +#ifdef AFS_FBSD50_ENV + vm_page_unlock_queues(); + VM_OBJECT_UNLOCK(object); +#endif return 0; } - + int afs_vop_write(ap) - struct vop_write_args /* { - struct vnode *a_vp; - struct uio *a_uio; - int a_ioflag; - struct ucred *a_cred; - } */ *ap; + struct vop_write_args /* { + * struct vnode *a_vp; + * struct uio *a_uio; + * int a_ioflag; + * struct ucred *a_cred; + * } */ *ap; { int code; - struct vcache *avc=VTOAFS(ap->a_vp); + struct vcache *avc = VTOAFS(ap->a_vp); AFS_GLOCK(); afs_BozonLock(&avc->pvnLock, avc); - osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */ - code=afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0); + osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */ + code = + afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0); afs_BozonUnlock(&avc->pvnLock, avc); AFS_GUNLOCK(); return code; } +/*- + * struct vop_putpages_args { + * struct vnode *a_vp; + * vm_page_t *a_m; + * int a_count; + * int a_sync; + * int *a_rtvals; + * vm_oofset_t a_offset; + * }; + */ +/* + * All of the pages passed to us in ap->a_m[] are already marked as busy, + * so there is no additional locking required to set their flags. -GAW + */ int -afs_vop_putpages(ap) - struct vop_putpages_args /* { - struct vnode *a_vp; - vm_page_t *a_m; - int a_count; - int a_sync; - int *a_rtvals; - vm_oofset_t a_offset; - } */ *ap; +afs_vop_putpages(struct vop_putpages_args *ap) { int code; int i, size, npages, sync; @@ -527,100 +748,120 @@ afs_vop_putpages(ap) struct iovec iov; struct buf *bp; vm_offset_t kva; - struct vcache *avc=VTOAFS(ap->a_vp); + struct vnode *vp; + struct vcache *avc; - if (avc->v.v_object == NULL) { - printf("afs_putpages: called with non-merged cache vnode??\n"); - return VM_PAGER_ERROR; +#ifdef AFS_FBSD50_ENV + GIANT_REQUIRED; +#endif + + vp = ap->a_vp; + avc = VTOAFS(vp); + /* Perhaps these two checks should just be KASSERTs instead... */ + if (vp->v_object == NULL) { + printf("afs_putpages: called with non-merged cache vnode??\n"); + return VM_PAGER_ERROR; /* XXX I think this is insufficient */ } if (vType(avc) != VREG) { - printf("afs_putpages: not VREG"); - return VM_PAGER_ERROR; + printf("afs_putpages: not VREG"); + return VM_PAGER_ERROR; /* XXX I think this is insufficient */ } - npages=btoc(ap->a_count); - for (i=0; i < npages; i++ ) ap->a_rtvals[i]=VM_PAGER_AGAIN; + npages = btoc(ap->a_count); + for (i = 0; i < npages; i++) + ap->a_rtvals[i] = VM_PAGER_AGAIN; bp = getpbuf(&afs_pbuf_freecnt); + kva = (vm_offset_t) bp->b_data; pmap_qenter(kva, ap->a_m, npages); - iov.iov_base=(caddr_t)kva; - iov.iov_len=ap->a_count; - uio.uio_iov=&iov; - uio.uio_iovcnt=1; - uio.uio_offset=IDX_TO_OFF(ap->a_m[0]->pindex); - uio.uio_resid=ap->a_count; - uio.uio_segflg=UIO_SYSSPACE; - uio.uio_rw=UIO_WRITE; - uio.uio_procp=curproc; - sync=IO_VMIO; +#ifdef AFS_FBSD50_ENV + cnt.v_vnodeout++; + cnt.v_vnodepgsout += ap->a_count; +#endif + + iov.iov_base = (caddr_t) kva; + iov.iov_len = ap->a_count; + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex); + uio.uio_resid = ap->a_count; + uio.uio_segflg = UIO_SYSSPACE; + uio.uio_rw = UIO_WRITE; +#ifdef AFS_FBSD50_ENV + uio.uio_td = curthread; +#else + uio.uio_procp = curproc; +#endif + sync = IO_VMIO; if (ap->a_sync & VM_PAGER_PUT_SYNC) - sync|=IO_SYNC; + sync |= IO_SYNC; /*if (ap->a_sync & VM_PAGER_PUT_INVAL) - sync|=IO_INVAL;*/ + * sync |= IO_INVAL; */ AFS_GLOCK(); afs_BozonLock(&avc->pvnLock, avc); - code=afs_write(avc, &uio, sync, curproc->p_cred->pc_ucred, 0); + code = afs_write(avc, &uio, sync, osi_curcred(), 0); afs_BozonUnlock(&avc->pvnLock, avc); AFS_GUNLOCK(); - pmap_qremove(kva, npages); + pmap_qremove(kva, npages); relpbuf(bp, &afs_pbuf_freecnt); + if (!code) { - size = ap->a_count - uio.uio_resid; - for (i = 0; i < round_page(size) / PAGE_SIZE; i++) { - ap->a_rtvals[i]=VM_PAGER_OK; - ap->a_m[i]->dirty=0; - } - return VM_PAGER_ERROR; + size = ap->a_count - uio.uio_resid; + for (i = 0; i < round_page(size) / PAGE_SIZE; i++) { + ap->a_rtvals[i] = VM_PAGER_OK; + vm_page_undirty(ap->a_m[i]); + } } return ap->a_rtvals[0]; } + int afs_vop_ioctl(ap) - struct vop_ioctl_args /* { - struct vnode *a_vp; - int a_command; - caddr_t a_data; - int a_fflag; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_ioctl_args /* { + * struct vnode *a_vp; + * int a_command; + * caddr_t a_data; + * int a_fflag; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { struct vcache *tvc = VTOAFS(ap->a_vp); - struct afs_ioctl data; int error = 0; - + /* in case we ever get in here... */ AFS_STATCNT(afs_ioctl); if (((ap->a_command >> 8) & 0xff) == 'V') { /* This is a VICEIOCTL call */ - AFS_GLOCK(); - error = HandleIoctl(tvc, (struct file *)0/*Not used*/, - ap->a_command, ap->a_data); - AFS_GUNLOCK(); - return(error); + AFS_GLOCK(); + error = HandleIoctl(tvc, NULL /*Not used */ , + ap->a_command, ap->a_data); + AFS_GUNLOCK(); + return (error); } else { /* No-op call; just return. */ - return(ENOTTY); + return (ENOTTY); } } /* ARGSUSED */ int afs_vop_poll(ap) - struct vop_poll_args /* { - struct vnode *a_vp; - int a_events; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_poll_args /* { + * struct vnode *a_vp; + * int a_events; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { - /* - * We should really check to see if I/O is possible. - */ - return (1); + /* + * We should really check to see if I/O is possible. + */ + return (1); } + /* * Mmap a file * @@ -629,46 +870,45 @@ afs_vop_poll(ap) /* ARGSUSED */ int afs_vop_mmap(ap) - struct vop_mmap_args /* { - struct vnode *a_vp; - int a_fflags; - struct ucred *a_cred; - struct proc *a_p; - } */ *ap; + struct vop_mmap_args /* { + * struct vnode *a_vp; + * int a_fflags; + * struct ucred *a_cred; + * struct proc *a_p; + * } */ *ap; { - return (EINVAL); + return (EINVAL); } int afs_vop_fsync(ap) - struct vop_fsync_args /* { - struct vnode *a_vp; - struct ucred *a_cred; - int a_waitfor; - struct proc *a_p; - } */ *ap; + struct vop_fsync_args /* { + * struct vnode *a_vp; + * struct ucred *a_cred; + * int a_waitfor; + * struct proc *a_p; + * } */ *ap; { - int wait = ap->a_waitfor == MNT_WAIT; int error; register struct vnode *vp = ap->a_vp; AFS_GLOCK(); - /*vflushbuf(vp, wait);*/ + /*vflushbuf(vp, wait); */ if (ap->a_cred) - error=afs_fsync(VTOAFS(vp), ap->a_cred); + error = afs_fsync(VTOAFS(vp), ap->a_cred); else - error=afs_fsync(VTOAFS(vp), &afs_osi_cred); + error = afs_fsync(VTOAFS(vp), afs_osi_credp); AFS_GUNLOCK(); return error; } int afs_vop_remove(ap) - struct vop_remove_args /* { - struct vnode *a_dvp; - struct vnode *a_vp; - struct componentname *a_cnp; - } */ *ap; + struct vop_remove_args /* { + * struct vnode *a_dvp; + * struct vnode *a_vp; + * struct componentname *a_cnp; + * } */ *ap; { int error = 0; register struct vnode *vp = ap->a_vp; @@ -676,7 +916,7 @@ afs_vop_remove(ap) GETNAME(); AFS_GLOCK(); - error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred); + error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred); AFS_GUNLOCK(); cache_purge(vp); DROPNAME(); @@ -685,19 +925,22 @@ afs_vop_remove(ap) int afs_vop_link(ap) - struct vop_link_args /* { - struct vnode *a_vp; - struct vnode *a_tdvp; - struct componentname *a_cnp; - } */ *ap; + struct vop_link_args /* { + * struct vnode *a_vp; + * struct vnode *a_tdvp; + * struct componentname *a_cnp; + * } */ *ap; { int error = 0; register struct vnode *dvp = ap->a_tdvp; register struct vnode *vp = ap->a_vp; - struct proc *p; +#ifdef AFS_FBSD50_ENV + struct thread *p = ap->a_cnp->cn_thread; +#else + struct proc *p = ap->a_cnp->cn_proc; +#endif GETNAME(); - p=cnp->cn_proc; if (dvp->v_mount != vp->v_mount) { error = EXDEV; goto out; @@ -706,29 +949,29 @@ afs_vop_link(ap) error = EISDIR; goto out; } - if (error = vn_lock(vp, LK_EXCLUSIVE, p)) { + if ((error = vn_lock(vp, LK_EXCLUSIVE, p)) != 0) { goto out; } AFS_GLOCK(); error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred); AFS_GUNLOCK(); if (dvp != vp) - VOP_UNLOCK(vp,0, p); -out: + VOP_UNLOCK(vp, 0, p); + out: DROPNAME(); return error; } int afs_vop_rename(ap) - struct vop_rename_args /* { - struct vnode *a_fdvp; - struct vnode *a_fvp; - struct componentname *a_fcnp; - struct vnode *a_tdvp; - struct vnode *a_tvp; - struct componentname *a_tcnp; - } */ *ap; + struct vop_rename_args /* { + * struct vnode *a_fdvp; + * struct vnode *a_fvp; + * struct componentname *a_fcnp; + * struct vnode *a_tdvp; + * struct vnode *a_tvp; + * struct componentname *a_tcnp; + * } */ *ap; { int error = 0; struct componentname *fcnp = ap->a_fcnp; @@ -739,15 +982,19 @@ afs_vop_rename(ap) register struct vnode *tdvp = ap->a_tdvp; struct vnode *fvp = ap->a_fvp; register struct vnode *fdvp = ap->a_fdvp; - struct proc *p=fcnp->cn_proc; +#ifdef AFS_FBSD50_ENV + struct thread *p = fcnp->cn_thread; +#else + struct proc *p = fcnp->cn_proc; +#endif /* * Check for cross-device rename. */ - if ((fvp->v_mount != tdvp->v_mount) || - (tvp && (fvp->v_mount != tvp->v_mount))) { + if ((fvp->v_mount != tdvp->v_mount) + || (tvp && (fvp->v_mount != tvp->v_mount))) { error = EXDEV; -abortit: + abortit: if (tdvp == tvp) vrele(tdvp); else @@ -762,7 +1009,7 @@ abortit: * if fvp == tvp, we're just removing one name of a pair of * directory entries for the same element. convert call into rename. ( (pinched from FreeBSD 4.4's ufs_rename()) - + */ if (fvp == tvp) { if (fvp->v_type == VDIR) { @@ -782,36 +1029,37 @@ abortit: if ((fcnp->cn_flags & SAVESTART) == 0) panic("afs_rename: lost from startdir"); fcnp->cn_nameiop = DELETE; - VREF(fdvp); - error=relookup(fdvp, &fvp, fcnp); - if (error == 0) - vrele(fdvp); - if (fvp == NULL) { - return (ENOENT); - } - - error=VOP_REMOVE(fdvp, fvp, fcnp); - if (fdvp == fvp) - vrele(fdvp); - else - vput(fdvp); - vput(fvp); - return (error); + VREF(fdvp); + error = relookup(fdvp, &fvp, fcnp); + if (error == 0) + vrele(fdvp); + if (fvp == NULL) { + return (ENOENT); + } + + error = VOP_REMOVE(fdvp, fvp, fcnp); + if (fdvp == fvp) + vrele(fdvp); + else + vput(fdvp); + vput(fvp); + return (error); } - if (error = vn_lock(fvp, LK_EXCLUSIVE, p)) + if ((error = vn_lock(fvp, LK_EXCLUSIVE, p)) != 0) goto abortit; - MALLOC(fname, char *, fcnp->cn_namelen+1, M_TEMP, M_WAITOK); + MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK); memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen); fname[fcnp->cn_namelen] = '\0'; - MALLOC(tname, char *, tcnp->cn_namelen+1, M_TEMP, M_WAITOK); + MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK); memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen); tname[tcnp->cn_namelen] = '\0'; AFS_GLOCK(); /* XXX use "from" or "to" creds? NFS uses "to" creds */ - error = afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred); + error = + afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred); AFS_GUNLOCK(); FREE(fname, M_TEMP); @@ -829,21 +1077,24 @@ abortit: int afs_vop_mkdir(ap) - struct vop_mkdir_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - struct vattr *a_vap; - } */ *ap; + struct vop_mkdir_args /* { + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * struct vattr *a_vap; + * } */ *ap; { register struct vnode *dvp = ap->a_dvp; register struct vattr *vap = ap->a_vap; int error = 0; struct vcache *vcp; - struct proc *p; +#ifdef AFS_FBSD50_ENV + struct thread *p = ap->a_cnp->cn_thread; +#else + struct proc *p = ap->a_cnp->cn_proc; +#endif GETNAME(); - p=cnp->cn_proc; #ifdef DIAGNOSTIC if ((cnp->cn_flags & HASBUF) == 0) panic("afs_vop_mkdir: no name"); @@ -852,13 +1103,12 @@ afs_vop_mkdir(ap) error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred); AFS_GUNLOCK(); if (error) { - vput(dvp); DROPNAME(); - return(error); + return (error); } if (vcp) { *ap->a_vpp = AFSTOV(vcp); - vn_lock(AFSTOV(vcp), LK_EXCLUSIVE|LK_RETRY, p); + vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p); } else *ap->a_vpp = 0; DROPNAME(); @@ -867,14 +1117,13 @@ afs_vop_mkdir(ap) int afs_vop_rmdir(ap) - struct vop_rmdir_args /* { - struct vnode *a_dvp; - struct vnode *a_vp; - struct componentname *a_cnp; - } */ *ap; + struct vop_rmdir_args /* { + * struct vnode *a_dvp; + * struct vnode *a_vp; + * struct componentname *a_cnp; + * } */ *ap; { int error = 0; - register struct vnode *vp = ap->a_vp; register struct vnode *dvp = ap->a_dvp; GETNAME(); @@ -885,48 +1134,66 @@ afs_vop_rmdir(ap) return error; } +/* struct vop_symlink_args { + * struct vnode *a_dvp; + * struct vnode **a_vpp; + * struct componentname *a_cnp; + * struct vattr *a_vap; + * char *a_target; + * }; + */ int -afs_vop_symlink(ap) - struct vop_symlink_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - struct vattr *a_vap; - char *a_target; - } */ *ap; +afs_vop_symlink(struct vop_symlink_args *ap) { - register struct vnode *dvp = ap->a_dvp; - int error = 0; - /* NFS ignores a_vpp; so do we. */ + struct vnode *dvp; + struct vnode *newvp; + struct vcache *vcp; + int error; GETNAME(); AFS_GLOCK(); - error = afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, - cnp->cn_cred); + + dvp = ap->a_dvp; + newvp = NULL; + + error = + afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred); + if (error == 0) { + error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred); + if (error == 0) { + newvp = AFSTOV(vcp); +#ifdef AFS_FBSD50_ENV + vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_thread); +#else + vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_proc); +#endif + } + } AFS_GUNLOCK(); DROPNAME(); + *(ap->a_vpp) = newvp; return error; } int afs_vop_readdir(ap) - struct vop_readdir_args /* { - struct vnode *a_vp; - struct uio *a_uio; - struct ucred *a_cred; - int *a_eofflag; - u_long *a_cookies; - int ncookies; - } */ *ap; + struct vop_readdir_args /* { + * struct vnode *a_vp; + * struct uio *a_uio; + * struct ucred *a_cred; + * int *a_eofflag; + * u_long *a_cookies; + * int ncookies; + * } */ *ap; { int error; off_t off; /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies, ap->a_ncookies); */ - off=ap->a_uio->uio_offset; + off = ap->a_uio->uio_offset; AFS_GLOCK(); - error= afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, - ap->a_eofflag); + error = + afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag); AFS_GUNLOCK(); if (!error && ap->a_ncookies != NULL) { struct uio *uio = ap->a_uio; @@ -939,17 +1206,15 @@ afs_vop_readdir(ap) dp = (const struct dirent *) ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off)); - dp_end = (const struct dirent *) uio->uio_iov->iov_base; - for (dp_start = dp, ncookies = 0; - dp < dp_end; - dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) + dp_end = (const struct dirent *)uio->uio_iov->iov_base; + for (dp_start = dp, ncookies = 0; dp < dp_end; + dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) ncookies++; - MALLOC(cookies, u_long *, ncookies * sizeof(u_long), - M_TEMP, M_WAITOK); - for (dp = dp_start, cookiep = cookies; - dp < dp_end; - dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) { + MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP, + M_WAITOK); + for (dp = dp_start, cookiep = cookies; dp < dp_end; + dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) { off += dp->d_reclen; *cookiep++ = off; } @@ -962,16 +1227,16 @@ afs_vop_readdir(ap) int afs_vop_readlink(ap) - struct vop_readlink_args /* { - struct vnode *a_vp; - struct uio *a_uio; - struct ucred *a_cred; - } */ *ap; + struct vop_readlink_args /* { + * struct vnode *a_vp; + * struct uio *a_uio; + * struct ucred *a_cred; + * } */ *ap; { int error; /* printf("readlink %x\n", ap->a_vp);*/ AFS_GLOCK(); - error= afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred); + error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred); AFS_GUNLOCK(); return error; } @@ -980,10 +1245,10 @@ extern int prtactive; int afs_vop_inactive(ap) - struct vop_inactive_args /* { - struct vnode *a_vp; - struct proc *a_p; - } */ *ap; + struct vop_inactive_args /* { + * struct vnode *a_vp; + * struct proc *a_p; + * } */ *ap; { register struct vnode *vp = ap->a_vp; @@ -991,158 +1256,137 @@ afs_vop_inactive(ap) vprint("afs_vop_inactive(): pushing active", vp); AFS_GLOCK(); - afs_InactiveVCache(VTOAFS(vp), 0); /* decrs ref counts */ + afs_InactiveVCache(VTOAFS(vp), 0); /* decrs ref counts */ AFS_GUNLOCK(); VOP_UNLOCK(vp, 0, ap->a_p); return 0; } +/* + * struct vop_reclaim_args { + * struct vnode *a_vp; + * }; + */ int -afs_vop_reclaim(ap) - struct vop_reclaim_args /* { - struct vnode *a_vp; - } */ *ap; -{ - int error; - int sl; - register struct vnode *vp = ap->a_vp; - - cache_purge(vp); /* just in case... */ - -#if 0 - AFS_GLOCK(); - error = afs_FlushVCache(VTOAFS(vp), &sl); /* tosses our stuff from vnode */ - AFS_GUNLOCK(); - ubc_unlink(vp); - if (!error && vp->v_data) - panic("afs_reclaim: vnode not cleaned"); - return error; -#else - if (vp->v_usecount == 2) { - vprint("reclaim count==2", vp); - } else if (vp->v_usecount == 1) { - vprint("reclaim count==1", vp); - } else - vprint("reclaim bad count", vp); - - return 0; -#endif -} - -int -afs_vop_lock(ap) - struct vop_lock_args /* { - struct vnode *a_vp; - } */ *ap; -{ - register struct vnode *vp = ap->a_vp; - register struct vcache *avc = VTOAFS(vp); - - if (vp->v_tag == VT_NON) - return (ENOENT); - return (lockmgr(&avc->rwlock, ap->a_flags, &vp->v_interlock, - ap->a_p)); -} - -int -afs_vop_unlock(ap) - struct vop_unlock_args /* { - struct vnode *a_vp; - } */ *ap; +afs_vop_reclaim(struct vop_reclaim_args *ap) { + /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */ + int code, slept; struct vnode *vp = ap->a_vp; struct vcache *avc = VTOAFS(vp); - return (lockmgr(&avc->rwlock, ap->a_flags | LK_RELEASE, - &vp->v_interlock, ap->a_p)); + int haveGlock = ISAFS_GLOCK(); + int haveVlock = CheckLock(&afs_xvcache); + + if (!haveGlock) + AFS_GLOCK(); + if (!haveVlock) + ObtainWriteLock(&afs_xvcache, 901); +#ifndef AFS_DISCON_ENV + code = afs_FlushVCache(avc, &slept); /* tosses our stuff from vnode */ +#else + /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */ + code = afs_FlushVS(avc); +#endif + if (!haveVlock) + ReleaseWriteLock(&afs_xvcache); + if (!haveGlock) + AFS_GUNLOCK(); + /* + * XXX Pretend it worked, to prevent panic on shutdown + * Garrett, please fix - Jim Rees + */ + if (code) + printf("afs_vop_reclaim: afs_FlushVCache failed code %d\n", code); + return 0; } int afs_vop_bmap(ap) - struct vop_bmap_args /* { - struct vnode *a_vp; - daddr_t a_bn; - struct vnode **a_vpp; - daddr_t *a_bnp; - int *a_runp; - int *a_runb; - } */ *ap; + struct vop_bmap_args /* { + * struct vnode *a_vp; + * daddr_t a_bn; + * struct vnode **a_vpp; + * daddr_t *a_bnp; + * int *a_runp; + * int *a_runb; + * } */ *ap; { - struct vcache *vcp; - int error; if (ap->a_bnp) { *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE); } if (ap->a_vpp) { *ap->a_vpp = ap->a_vp; } - if (ap->a_runp != NULL) - *ap->a_runp = 0; - if (ap->a_runb != NULL) - *ap->a_runb = 0; - + if (ap->a_runp != NULL) + *ap->a_runp = 0; + if (ap->a_runb != NULL) + *ap->a_runb = 0; + return 0; } + int afs_vop_strategy(ap) - struct vop_strategy_args /* { - struct buf *a_bp; - } */ *ap; + struct vop_strategy_args /* { + * struct buf *a_bp; + * } */ *ap; { int error; AFS_GLOCK(); - error= afs_ustrategy(ap->a_bp); + error = afs_ustrategy(ap->a_bp); AFS_GUNLOCK(); return error; } + int afs_vop_print(ap) - struct vop_print_args /* { - struct vnode *a_vp; - } */ *ap; + struct vop_print_args /* { + * struct vnode *a_vp; + * } */ *ap; { register struct vnode *vp = ap->a_vp; register struct vcache *vc = VTOAFS(ap->a_vp); int s = vc->states; - printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag, vc->fid.Cell, - vc->fid.Fid.Volume, vc->fid.Fid.Vnode, vc->fid.Fid.Unique, vc->opens, + +#ifdef AFS_FBSD50_ENV + printf("tag %s, fid: %d.%x.%x.%x, opens %d, writers %d", vp->v_tag, + (int)vc->fid.Cell, (u_int) vc->fid.Fid.Volume, + (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens, vc->execsOrWriters); - printf("\n states%s%s%s%s%s", (s&CStatd) ? " statd" : "", (s&CRO) ? " readonly" : "",(s&CDirty) ? " dirty" : "",(s&CMAPPED) ? " mapped" : "", (s&CVFlushed) ? " flush in progress" : ""); +#else + printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag, + vc->fid.Cell, (u_int) vc->fid.Fid.Volume, + (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens, + vc->execsOrWriters); +#endif + printf("\n states%s%s%s%s%s", (s & CStatd) ? " statd" : "", + (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "", + (s & CMAPPED) ? " mapped" : "", + (s & CVFlushed) ? " flush in progress" : ""); printf("\n"); return 0; } -int -afs_vop_islocked(ap) - struct vop_islocked_args /* { - struct vnode *a_vp; - } */ *ap; -{ - struct vcache *vc = VTOAFS(ap->a_vp); - return lockstatus(&vc->rwlock, ap->a_p); -} - /* * Advisory record locking support (fcntl() POSIX style) */ int afs_vop_advlock(ap) - struct vop_advlock_args /* { - struct vnode *a_vp; - caddr_t a_id; - int a_op; - struct flock *a_fl; - int a_flags; - } */ *ap; + struct vop_advlock_args /* { + * struct vnode *a_vp; + * caddr_t a_id; + * int a_op; + * struct flock *a_fl; + * int a_flags; + * } */ *ap; { int error; - struct proc *p=curproc; - struct ucred cr; - cr=*p->p_cred->pc_ucred; + struct ucred cr = *osi_curcred(); + AFS_GLOCK(); - error= afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, - (int) ap->a_id); + error = + afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id); AFS_GUNLOCK(); return error; } - diff --git a/src/afs/HPUX/osi_debug.c b/src/afs/HPUX/osi_debug.c index f339480e0..cb8e4facc 100644 --- a/src/afs/HPUX/osi_debug.c +++ b/src/afs/HPUX/osi_debug.c @@ -10,7 +10,8 @@ #include #include "param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_debug.c,v 1.1.1.4 2001/07/14 22:19:39 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_debug.c,v 1.5 2003/07/15 23:14:21 shadow Exp $"); #include "sysincludes.h" #include "afsincludes.h" diff --git a/src/afs/HPUX/osi_file.c b/src/afs/HPUX/osi_file.c index 81954b0b0..f88b5f6b0 100644 --- a/src/afs/HPUX/osi_file.c +++ b/src/afs/HPUX/osi_file.c @@ -8,25 +8,26 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_file.c,v 1.1.1.5 2001/09/11 14:24:59 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_file.c,v 1.8 2003/07/15 23:14:21 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ -#include "../afs/osi_inode.h" /* igetinode() */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#include "afs/osi_inode.h" /* igetinode() */ -int afs_osicred_initialized=0; -struct AFS_UCRED afs_osi_cred; +int afs_osicred_initialized = 0; +struct AFS_UCRED afs_osi_cred; afs_lock_t afs_xosi; /* lock is for tvattr */ extern struct osi_dev cacheDev; extern struct vfs *afs_cacheVfsp; -void *osi_UFSOpen(ainode) - afs_int32 ainode; +void * +osi_UFSOpen(afs_int32 ainode) { struct inode *ip; register struct osi_file *afile = NULL; @@ -34,7 +35,7 @@ void *osi_UFSOpen(ainode) afs_int32 code = 0; int dummy; AFS_STATCNT(osi_UFSOpen); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) { + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) { osi_Panic("UFSOpen called for non-UFS cache\n"); } if (!afs_osicred_initialized) { @@ -43,10 +44,11 @@ void *osi_UFSOpen(ainode) crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */ afs_osicred_initialized = 1; } - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); setuerror(0); AFS_GUNLOCK(); - ip = (struct inode *) igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode,&dummy); + ip = (struct inode *)igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, + (ino_t) ainode, &dummy); AFS_GLOCK(); if (getuerror()) { osi_FreeSmallSpace(afile); @@ -56,18 +58,18 @@ void *osi_UFSOpen(ainode) afile->vnode = ITOV(ip); afile->size = VTOI(afile->vnode)->i_size; afile->offset = 0; - afile->proc = (int (*)()) 0; - afile->inum = ainode; /* for hint validity checking */ + afile->proc = (int (*)())0; + afile->inum = ainode; /* for hint validity checking */ return (void *)afile; } -afs_osi_Stat(afile, astat) - register struct osi_file *afile; - register struct osi_stat *astat; { +int +afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) +{ register afs_int32 code; struct vattr tvattr; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi,320); + MObtainWriteLock(&afs_xosi, 320); AFS_GUNLOCK(); code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, VSYNC); AFS_GLOCK(); @@ -81,21 +83,21 @@ afs_osi_Stat(afile, astat) return code; } -osi_UFSClose(afile) - register struct osi_file *afile; - { - AFS_STATCNT(osi_Close); - if(afile->vnode) { +int +osi_UFSClose(register struct osi_file *afile) +{ + AFS_STATCNT(osi_Close); + if (afile->vnode) { AFS_RELE(afile->vnode); - } - - osi_FreeSmallSpace(afile); - return 0; - } - -osi_UFSTruncate(afile, asize) - register struct osi_file *afile; - afs_int32 asize; { + } + + osi_FreeSmallSpace(afile); + return 0; +} + +int +osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) +{ struct AFS_UCRED *oldCred; struct vattr tvattr; register afs_int32 code; @@ -107,68 +109,69 @@ osi_UFSTruncate(afile, asize) * small enough. Check now and save some time. */ code = afs_osi_Stat(afile, &tstat); - if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi,321); + if (code || tstat.size <= asize) + return code; + MObtainWriteLock(&afs_xosi, 321); VATTR_NULL(&tvattr); /* note that this credential swapping stuff is only necessary because - of ufs's references directly to u.u_cred instead of to - credentials parameter. Probably should fix ufs some day. */ + * of ufs's references directly to u.u_cred instead of to + * credentials parameter. Probably should fix ufs some day. */ oldCred = p_cred(u.u_procp); set_p_cred(u.u_procp, &afs_osi_cred); tvattr.va_size = asize; AFS_GUNLOCK(); code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, 0); AFS_GLOCK(); - set_p_cred(u.u_procp, oldCred); /* restore */ + set_p_cred(u.u_procp, oldCred); /* restore */ MReleaseWriteLock(&afs_xosi); return code; } -void osi_DisableAtimes(avp) -struct vnode *avp; +void +osi_DisableAtimes(struct vnode *avp) { - struct inode *ip = VTOI(avp); - ip->i_flag &= ~IACC; + struct inode *ip = VTOI(avp); + ip->i_flag &= ~IACC; } /* Generic read interface */ -afs_osi_Read(afile, offset, aptr, asize) - register struct osi_file *afile; - int offset; - char *aptr; - afs_int32 asize; { +int +afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; long resid; register afs_int32 code; - register afs_int32 cnt1=0; + register afs_int32 cnt1 = 0; AFS_STATCNT(osi_Read); /** * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ - if ( !afile ) { - if ( !afs_shuttingdown ) + if (!afile) { + if (!afs_shuttingdown) osi_Panic("osi_Read called with null param"); else return EIO; } - if (offset != -1) afile->offset = offset; -retry_IO: + if (offset != -1) + afile->offset = offset; + retry_IO: AFS_GUNLOCK(); - code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, IO_UNIT, &resid); + code = + gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, + AFS_UIOSYS, IO_UNIT, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; osi_DisableAtimes(afile->vnode); - } - else { - afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, (afs_int32) resid, - ICL_TYPE_INT32, code); + } else { + afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, + (afs_int32) resid, ICL_TYPE_INT32, code); /* * To handle periodic low-level EFAULT failures that we've seen with the * Weitek chip; in all observed failed cases a second read succeeded. @@ -177,53 +180,54 @@ retry_IO: afs_stats_cmperf.osiread_efaults++; goto retry_IO; } - setuerror(code); + setuerror(code); code = -1; } return code; } /* Generic write interface */ -afs_osi_Write(afile, offset, aptr, asize) - register struct osi_file *afile; - char *aptr; - afs_int32 offset; - afs_int32 asize; { +int +afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; long resid; register afs_int32 code; AFS_STATCNT(osi_Write); - if ( !afile ) - osi_Panic("afs_osi_Write called with null param"); - if (offset != -1) afile->offset = offset; + if (!afile) + osi_Panic("afs_osi_Write called with null param"); + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, IO_UNIT, &resid); + code = + gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + afile->offset, AFS_UIOSYS, IO_UNIT, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; - } - else { - if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); + } else { + if (code == ENOSPC) + afs_warnuser + ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); setuerror(code); code = -1; } if (afile->proc) { - (*afile->proc)(afile, code); + (*afile->proc) (afile, code); } return code; } void -shutdown_osifile() +shutdown_osifile(void) { - extern int afs_cold_shutdown; + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osifile); - if (afs_cold_shutdown) { - afs_osicred_initialized = 0; - } + AFS_STATCNT(shutdown_osifile); + if (afs_cold_shutdown) { + afs_osicred_initialized = 0; + } } - diff --git a/src/afs/HPUX/osi_groups.c b/src/afs/HPUX/osi_groups.c index 20d28d146..103adf1dc 100644 --- a/src/afs/HPUX/osi_groups.c +++ b/src/afs/HPUX/osi_groups.c @@ -14,29 +14,24 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_groups.c,v 1.1.1.5 2003/07/30 17:08:07 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_groups.c,v 1.8 2003/07/15 23:14:21 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset); + afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset); static int -afs_setgroups( - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent); + afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset, + int change_parent); int -Afs_xsetgroups() +Afs_xsetgroups() { int code = 0; struct vrequest treq; @@ -45,7 +40,8 @@ Afs_xsetgroups() AFS_GLOCK(); code = afs_InitReq(&treq, p_cred(u.u_procp)); AFS_GUNLOCK(); - if (code) return code; + if (code) + return code; setgroups(); /* Note that if there is a pag already in the new groups we don't @@ -66,10 +62,10 @@ Afs_xsetgroups() int setpag(cred, pagvalue, newpag, change_parent) - struct ucred **cred; - afs_uint32 pagvalue; - afs_uint32 *newpag; - afs_uint32 change_parent; + struct ucred **cred; + afs_uint32 pagvalue; + afs_uint32 *newpag; + afs_uint32 change_parent; { gid_t gidset[NGROUPS]; int ngroups, code; @@ -82,12 +78,12 @@ setpag(cred, pagvalue, newpag, change_parent) if (ngroups + 2 > NGROUPS) { return (setuerror(E2BIG), E2BIG); } - for (j = ngroups -1; j >= 0; j--) { - gidset[j+2] = gidset[j]; - } + for (j = ngroups - 1; j >= 0; j--) { + gidset[j + 2] = gidset[j]; + } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); + *newpag = (pagvalue == -1 ? genpag() : pagvalue); afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]); if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) { @@ -98,10 +94,7 @@ setpag(cred, pagvalue, newpag, change_parent) static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset) +afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset) { int ngrps, savengrps; int *gp; @@ -111,10 +104,10 @@ afs_getgroups( for (gp = &cred->cr_groups[NGROUPS]; gp > cred->cr_groups; gp--) { if (gp[-1] != NOGROUP) - break; + break; } savengrps = ngrps = MIN(ngroups, gp - cred->cr_groups); - for (gp = cred->cr_groups; ngrps--; ) + for (gp = cred->cr_groups; ngrps--;) *gidset++ = *gp++; return savengrps; } @@ -122,11 +115,8 @@ afs_getgroups( static int -afs_setgroups( - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent) +afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset, + int change_parent) { int ngrps; int i; @@ -138,51 +128,47 @@ afs_setgroups( #endif AFS_STATCNT(afs_setgroups); - - if (!change_parent) - { - newcr = (struct ucred *)crdup(*cred); - /* nobody else has the pointer to newcr because we - ** just allocated it, so no need for locking */ - } - else - { - /* somebody else might have a pointer to this structure. - ** make sure we do not have a race condition */ - newcr = *cred; + + if (!change_parent) { + newcr = (struct ucred *)crdup(*cred); + /* nobody else has the pointer to newcr because we + ** just allocated it, so no need for locking */ + } else { + /* somebody else might have a pointer to this structure. + ** make sure we do not have a race condition */ + newcr = *cred; #if defined(AFS_HPUX110_ENV) - /* all of the uniprocessor spinlocks are not defined. */ - /* I assume the UP and MP are now handled together */ - MP_SPINLOCK_USAV(cred_lock, context); + /* all of the uniprocessor spinlocks are not defined. */ + /* I assume the UP and MP are now handled together */ + MP_SPINLOCK_USAV(cred_lock, context); #else - s = UP_SPL6(); - SPINLOCK(cred_lock); + s = UP_SPL6(); + SPINLOCK(cred_lock); #endif - } - + } + + /* copy the group info */ gp = newcr->cr_groups; while (ngroups--) *gp++ = *gidset++; - for ( ; gp < &(newcr)->cr_groups[NGROUPS]; gp++) - *gp = ((gid_t) -1); - - if ( !change_parent) - { - /* replace the new cred structure in the proc area */ - struct ucred* tmp; - tmp = *cred; - set_p_cred(u.u_procp, newcr); - crfree(tmp); - } - else - { + for (; gp < &(newcr)->cr_groups[NGROUPS]; gp++) + *gp = ((gid_t) - 1); + + if (!change_parent) { + /* replace the new cred structure in the proc area */ + struct ucred *tmp; + tmp = *cred; + set_p_cred(u.u_procp, newcr); + crfree(tmp); + } else { #if defined(AFS_HPUX110_ENV) - MP_SPINUNLOCK_USAV(cred_lock, context); + MP_SPINUNLOCK_USAV(cred_lock, context); #else - (void) UP_SPLX(s); - SPINUNLOCK(cred_lock); + (void)UP_SPLX(s); + SPINUNLOCK(cred_lock); #endif - } + } + return (setuerror(0), 0); } diff --git a/src/afs/HPUX/osi_inode.c b/src/afs/HPUX/osi_inode.c index 5cb63d7bd..ea5fbf205 100644 --- a/src/afs/HPUX/osi_inode.c +++ b/src/afs/HPUX/osi_inode.c @@ -14,205 +14,206 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_inode.c,v 1.1.1.4 2001/07/14 22:19:40 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_inode.c,v 1.7 2003/07/15 23:14:21 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/osi_inode.h" -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/osi_inode.h" +#include "afs/afs_stats.h" /* statistics stuff */ #include static struct inode * getinode(struct vfs *vfsp, dev_t dev, ino_t inode, int *perror) { - struct mount *mp = (vfsp ? VFSTOM(vfsp) : 0); - struct inode *pip; - *perror = 0; - - if (!mp && !(mp = getmp(dev))) { - u.u_error = ENXIO; - return((struct inode *)0); - } - pip=iget(dev,mp,inode); - if(!pip) + struct mount *mp = (vfsp ? VFSTOM(vfsp) : 0); + struct inode *pip; + *perror = 0; + + if (!mp && !(mp = getmp(dev))) { + u.u_error = ENXIO; + return (NULL); + } + pip = iget(dev, mp, inode); + if (!pip) *perror = BAD_IGET; - return(pip); + return (pip); } struct inode * igetinode(struct vfs *vfsp, dev_t dev, ino_t inode, int *perror) { - struct inode *pip, *ip; - extern struct osi_dev cacheDev; - register int code = 0; - - *perror = 0; - AFS_STATCNT(igetinode); - ip = getinode(vfsp, dev, inode,perror); - if (ip == NULL) { - *perror = BAD_IGET; - u.u_error = ENOENT; /* Well... */ - return; - } - if (ip->i_mode == 0) { - /* Not an allocated inode */ - iforget(ip); - u.u_error = ENOENT; - return; - } - if (ip->i_nlink == 0 || (ip->i_mode&IFMT) != IFREG) { - iput(ip); - u.u_error = ENOENT; - return; - } - return ip; + struct inode *pip, *ip; + extern struct osi_dev cacheDev; + register int code = 0; + + *perror = 0; + AFS_STATCNT(igetinode); + ip = getinode(vfsp, dev, inode, perror); + if (ip == NULL) { + *perror = BAD_IGET; + u.u_error = ENOENT; /* Well... */ + return; + } + if (ip->i_mode == 0) { + /* Not an allocated inode */ + iforget(ip); + u.u_error = ENOENT; + return; + } + if (ip->i_nlink == 0 || (ip->i_mode & IFMT) != IFREG) { + iput(ip); + u.u_error = ENOENT; + return; + } + return ip; } iforget(ip) struct inode *ip; { - idrop(ip); + idrop(ip); } afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4) -long dev, near_inode, param1, param2, param3, param4; + long dev, near_inode, param1, param2, param3, param4; { - int dummy, err=0; - struct inode *ip, *newip; - - AFS_STATCNT(afs_syscall_icreate); - - if (!afs_suser()) { - u.u_error = EPERM; - goto out; - } - - ip = getinode(0, (dev_t)dev, 2,&dummy); - if (ip == NULL) { - u.u_error = ENOENT; /* Well... */ - goto out; - } - - newip = (struct inode *)ialloc(ip, near_inode, 0); - iput(ip); - if (newip == NULL) - goto out; - - newip->i_flag |= IACC|IUPD|ICHG; - newip->i_nlink = 1; - newip->i_mode = IFREG; - newip->i_vnode.v_type = VREG; - newip->i_vicemagic = VICEMAGIC; - newip->i_vicep1 = param1; - newip->i_vicep2 = param2; - I_VICE3(newip) = param3; - newip->i_vicep4 = param4; - u.u_r.r_val1 = newip->i_number; - - iput(newip); - -out: - return err; + int dummy, err = 0; + struct inode *ip, *newip; + + AFS_STATCNT(afs_syscall_icreate); + + if (!afs_suser()) { + u.u_error = EPERM; + goto out; + } + + ip = getinode(0, (dev_t) dev, 2, &dummy); + if (ip == NULL) { + u.u_error = ENOENT; /* Well... */ + goto out; + } + + newip = (struct inode *)ialloc(ip, near_inode, 0); + iput(ip); + if (newip == NULL) + goto out; + + newip->i_flag |= IACC | IUPD | ICHG; + newip->i_nlink = 1; + newip->i_mode = IFREG; + newip->i_vnode.v_type = VREG; + newip->i_vicemagic = VICEMAGIC; + newip->i_vicep1 = param1; + newip->i_vicep2 = param2; + I_VICE3(newip) = param3; + newip->i_vicep4 = param4; + u.u_r.r_val1 = newip->i_number; + + iput(newip); + + out: + return err; } afs_syscall_iopen(dev, inode, usrmod) -int dev, inode, usrmod; + int dev, inode, usrmod; { - struct file *fp; - struct inode *ip; - struct vnode *vp = (struct vnode *)0; - int dummy; - extern struct fileops vnodefops; - register int code; - - AFS_STATCNT(afs_syscall_iopen); - - if (!afs_suser()) { - u.u_error = EPERM; - goto out; - } - - ip = igetinode(0, (dev_t)dev, (ino_t)inode,&dummy); - if (u.u_error) - goto out; - fp = falloc(); - if (!fp) { - iput(ip); - goto out; - } - iunlock(ip); - - fp->f_ops = &vnodefops; - vp = ITOV(ip); - fp->f_data = (char *)vp; - fp->f_type = DTYPE_VNODE; - fp->f_flag = (usrmod+1) & (FMASK); - - /* Obtained from hp kernel sys/vfs_scalls.c: copen(). - * Otherwise we panic because the v_writecount - * goes less than 0 during close. - */ - if ((vp->v_type == VREG) && (fp->f_flag & FWRITE)) { - VN_INC_WRITECOUNT(vp); - } - - /* fp->f_count, f_msgcount are set by falloc */ - /* fp->f_offset zeroed by falloc */ - /* f_cred set by falloc */ - - /* - * Obtained from hp kernel sys/vfs_scalls.c: copen() does - * a PUTF() (defined earlier in the file) before returning, - * so we parrot what it does. If this is not done, then - * threaded processes will get EBADF errors when they try - * to use the resulting file descriptor (e.g. with lseek()). - * - * Note: u.u_r.r_val1 is set by ufalloc(), which is - * called by falloc(), which is called above. - */ - if (is_multithreaded(u.u_procp)) { - int fd = (int)u.u_r.r_val1; - putf(fd); - } - -out: - return; + struct file *fp; + struct inode *ip; + struct vnode *vp = NULL; + int dummy; + extern struct fileops vnodefops; + register int code; + + AFS_STATCNT(afs_syscall_iopen); + + if (!afs_suser()) { + u.u_error = EPERM; + goto out; + } + + ip = igetinode(0, (dev_t) dev, (ino_t) inode, &dummy); + if (u.u_error) + goto out; + fp = falloc(); + if (!fp) { + iput(ip); + goto out; + } + iunlock(ip); + + fp->f_ops = &vnodefops; + vp = ITOV(ip); + fp->f_data = (char *)vp; + fp->f_type = DTYPE_VNODE; + fp->f_flag = (usrmod + 1) & (FMASK); + + /* Obtained from hp kernel sys/vfs_scalls.c: copen(). + * Otherwise we panic because the v_writecount + * goes less than 0 during close. + */ + if ((vp->v_type == VREG) && (fp->f_flag & FWRITE)) { + VN_INC_WRITECOUNT(vp); + } + + /* fp->f_count, f_msgcount are set by falloc */ + /* fp->f_offset zeroed by falloc */ + /* f_cred set by falloc */ + + /* + * Obtained from hp kernel sys/vfs_scalls.c: copen() does + * a PUTF() (defined earlier in the file) before returning, + * so we parrot what it does. If this is not done, then + * threaded processes will get EBADF errors when they try + * to use the resulting file descriptor (e.g. with lseek()). + * + * Note: u.u_r.r_val1 is set by ufalloc(), which is + * called by falloc(), which is called above. + */ + if (is_multithreaded(u.u_procp)) { + int fd = (int)u.u_r.r_val1; + putf(fd); + } + + out: + return; } afs_syscall_iincdec(dev, inode, inode_p1, amount) -int dev, inode, inode_p1, amount; + int dev, inode, inode_p1, amount; { - int dummy; - struct inode *ip; - register afs_int32 code; - - if (!afs_suser()) { - u.u_error = EPERM; - goto out; - } - - ip = igetinode(0, (dev_t)dev, (ino_t)inode,&dummy); - if (u.u_error) { - goto out; + int dummy; + struct inode *ip; + register afs_int32 code; + + if (!afs_suser()) { + u.u_error = EPERM; + goto out; + } + + ip = igetinode(0, (dev_t) dev, (ino_t) inode, &dummy); + if (u.u_error) { + goto out; + } + + if (!IS_VICEMAGIC(ip)) + u.u_error = EPERM; + else if (ip->i_vicep1 != inode_p1) + u.u_error = ENXIO; + else { + ip->i_nlink += amount; + if (ip->i_nlink == 0) { + CLEAR_VICEMAGIC(ip); } + ip->i_flag |= ICHG; + } - if (!IS_VICEMAGIC(ip)) - u.u_error = EPERM; - else if (ip->i_vicep1 != inode_p1) - u.u_error = ENXIO; - else { - ip->i_nlink += amount; - if (ip->i_nlink == 0) { - CLEAR_VICEMAGIC(ip); - } - ip->i_flag |= ICHG; - } - - iput(ip); + iput(ip); -out: + out: return; } diff --git a/src/afs/HPUX/osi_inode.h b/src/afs/HPUX/osi_inode.h index d7f69a9d7..cdd3bac45 100644 --- a/src/afs/HPUX/osi_inode.h +++ b/src/afs/HPUX/osi_inode.h @@ -47,6 +47,7 @@ #define CLEAR_VICEMAGIC(ip) (ip)->i_vicemagic = 0 #define CLEAR_DVICEMAGIC(dp) (dp)->di_vicemagic = 0 -struct inode *igetinode(struct vfs *vfsp, dev_t dev, ino_t inode, int *perror); +struct inode *igetinode(struct vfs *vfsp, dev_t dev, ino_t inode, + int *perror); #endif /* _OSI_INODE_H_ */ diff --git a/src/afs/HPUX/osi_machdep.h b/src/afs/HPUX/osi_machdep.h index e7b8312f4..b13f6e461 100644 --- a/src/afs/HPUX/osi_machdep.h +++ b/src/afs/HPUX/osi_machdep.h @@ -18,7 +18,7 @@ #ifndef _OSI_MACHDEP_H_ #define _OSI_MACHDEP_H_ -#include "../h/kern_sem.h" +#include "h/kern_sem.h" #define afs_hz hz extern struct timeval time; @@ -38,6 +38,8 @@ extern struct timeval time; #undef afs_suser +#define osi_curcred() (p_cred(u.u_procp)) + #define getpid() (afs_uint32)p_pid(u.u_procp) #define getppid() (afs_uint32)p_ppid(u.u_procp) @@ -58,24 +60,27 @@ extern b_sema_t afs_global_sema; extern void osi_InitGlock(void); #if !defined(AFS_HPUX110_ENV) -extern void afsHash(int nbuckets); +extern void afsHash(int nbuckets); extern sv_sema_t *afsHashInsertFind(tid_t key); extern sv_sema_t *afsHashFind(tid_t key); -extern void afsHashRelease(tid_t key); +extern void afsHashRelease(tid_t key); #define AFS_GLOCK_PID kt_tid(u.u_kthreadp) #define AFS_SAVE_SEMA afsHashInsertFind(AFS_GLOCK_PID) #define AFS_FIND_SEMA afsHashFind(AFS_GLOCK_PID) + #define AFS_GLOCK() MP_PXSEMA(&afs_global_sema, AFS_SAVE_SEMA) #define AFS_GUNLOCK() (AFS_ASSERT_GLOCK(), MP_VXSEMA(&afs_global_sema,AFS_FIND_SEMA), (!uniprocessor ? (afsHashRelease(AFS_GLOCK_PID),0) : 0)) #define ISAFS_GLOCK() (!uniprocessor ? owns_sema(&afs_global_sema):1) + #else #define AFS_GLOCK() b_psema(&afs_global_sema) #define AFS_GUNLOCK() b_vsema(&afs_global_sema) #define ISAFS_GLOCK() b_owns_sema(&afs_global_sema) + #endif -#define AFS_RXGLOCK() +#define AFS_RXGLOCK() #define AFS_RXGUNLOCK() #define ISAFS_RXGLOCK() 1 @@ -92,11 +97,10 @@ extern void afsHashRelease(tid_t key); */ #define afs_osi_Sleep(x) sleep((caddr_t) x,PZERO-2) -#define afs_osi_Wakeup(x) wakeup((caddr_t) x) #else /* - * On 11.* global lock is a beta semaphore, hence we need to - * release and reacquire around sleep and wakeup. We also need to + * On 11.22 global lock is a beta semaphore, hence we need to + * release and reacquire around sllep and wakeup. We also need to * use the get_sleep_lock. * afs_osi_Sleep and afs_osi_Wakeup are defined */ @@ -104,13 +108,11 @@ void afs_osi_Sleep(void *event); int afs_osi_Wakeup(void *event); #endif - #define osi_NullHandle(x) ((x)->proc == (caddr_t) 0) #if !defined(AFS_HPUX110_ENV) extern caddr_t kmem_alloc(); #endif - #include /* for kt_cred() */ /* Expected to be available as a patch from HP */ diff --git a/src/afs/HPUX/osi_misc.c b/src/afs/HPUX/osi_misc.c index a0ee1e61c..ca1821a55 100644 --- a/src/afs/HPUX/osi_misc.c +++ b/src/afs/HPUX/osi_misc.c @@ -13,12 +13,13 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_misc.c,v 1.1.1.4 2001/07/14 22:19:40 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_misc.c,v 1.6 2003/07/15 23:14:21 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ /* * afs_suser() returns true if the caller is superuser, false otherwise. @@ -28,7 +29,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_misc.c,v 1.1.1.4 2001/07/1 * Here we have to save and restore errno since the HP-UX suser() sets errno. */ -afs_suser() { +afs_suser() +{ int save_errno; int code; diff --git a/src/afs/HPUX/osi_sleep.c b/src/afs/HPUX/osi_sleep.c index 1e123ad4d..bd6a1bb51 100644 --- a/src/afs/HPUX/osi_sleep.c +++ b/src/afs/HPUX/osi_sleep.c @@ -8,25 +8,25 @@ */ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_sleep.c,v 1.1.1.5 2003/07/30 17:08:07 hartmans Exp $"); - -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/param.h" +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_sleep.c,v 1.12 2003/07/15 23:14:21 shadow Exp $"); +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ #if !defined(AFS_HPUX110_ENV) static char waitV; #endif /* call procedure aproc with arock as an argument, in ams milliseconds */ -static int afs_osi_CallProc(aproc, arock, ams) - register void (*aproc)(); - register char *arock; - afs_int32 ams; +static int +afs_osi_CallProc(aproc, arock, ams) + register void (*aproc) (); + register char *arock; + afs_int32 ams; { int code; @@ -35,7 +35,7 @@ static int afs_osi_CallProc(aproc, arock, ams) AFS_GUNLOCK(); #endif /* hz is in cycles/second, and timeout's 3rd parm is in cycles */ - code = timeout(aproc, arock, (ams * afs_hz)/1000 + 1); + code = timeout(aproc, arock, (ams * afs_hz) / 1000 + 1); #if !defined(AFS_HPUX110_ENV) AFS_GLOCK(); #endif @@ -43,9 +43,10 @@ static int afs_osi_CallProc(aproc, arock, ams) } /* cancel a timeout, whether or not it has already occurred */ -static int afs_osi_CancelProc(aproc, arock) - register void (*aproc)(); - register char *arock; +static int +afs_osi_CancelProc(aproc, arock) + register void (*aproc) (); + register char *arock; { int code = 0; AFS_STATCNT(osi_CancelProc); @@ -61,9 +62,10 @@ static int afs_osi_CancelProc(aproc, arock) } #if defined(AFS_HPUX110_ENV) -static void AfsWaitHack(char * event) +static void +AfsWaitHack(char *event) { - lock_t * sleep_lock; + lock_t *sleep_lock; AFS_STATCNT(WaitHack); sleep_lock = get_sleep_lock(event); @@ -72,50 +74,56 @@ static void AfsWaitHack(char * event) } #else -static void AfsWaitHack() +static void +AfsWaitHack() { AFS_STATCNT(WaitHack); wakeup(&waitV); } #endif -void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) +void +afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) { AFS_STATCNT(osi_InitWaitHandle); achandle->proc = (caddr_t) 0; } /* cancel osi_Wait */ -void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) { caddr_t proc; AFS_STATCNT(osi_CancelWait); proc = achandle->proc; - if (proc == 0) return; - achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ + if (proc == 0) + return; + achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ #if defined(AFS_HPUX110_ENV) - afs_osi_Wakeup((char *)achandle); + afs_osi_Wakeup((char *)achandle); #else afs_osi_Wakeup(&waitV); #endif + } /* afs_osi_Wait * Waits for data on ahandle, or ams ms later. ahandle may be null. * Returns 0 if timeout and EINTR if signalled. */ -int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) +int +afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) { int code; afs_int32 endTime, tid; #if defined(AFS_HPUX110_ENV) - char localwait; - char * event; + char localwait; + char *event; #endif AFS_STATCNT(osi_Wait); - endTime = osi_Time() + (ams/1000); + endTime = osi_Time() + (ams / 1000); if (ahandle) ahandle->proc = (caddr_t) u.u_procp; do { @@ -123,22 +131,22 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) code = 0; /* do not do anything for solaris, digital, AIX, and SGI MP */ #if defined(AFS_HPUX110_ENV) - if (ahandle) { - event = (char *) ahandle; - } - else { - event = &localwait; - } - afs_osi_CallProc(AfsWaitHack, event, ams); - afs_osi_Sleep(event); - afs_osi_CancelProc(AfsWaitHack, event); + if (ahandle) { + event = (char *)ahandle; + } else { + event = &localwait; + } + afs_osi_CallProc(AfsWaitHack, event, ams); + afs_osi_Sleep(event); + afs_osi_CancelProc(AfsWaitHack, event); #else - afs_osi_CallProc(AfsWaitHack, (char *) u.u_procp, ams); - afs_osi_Sleep(&waitV); /* for HP 10.0 */ + afs_osi_CallProc(AfsWaitHack, (char *)u.u_procp, ams); + afs_osi_Sleep(&waitV); /* for HP 10.0 */ /* do not do anything for solaris, digital, and SGI MP */ - afs_osi_CancelProc(AfsWaitHack, (char *) u.u_procp); - if (code) break; /* if something happened, quit now */ + afs_osi_CancelProc(AfsWaitHack, (char *)u.u_procp); + if (code) + break; /* if something happened, quit now */ #endif /* if we we're cancelled, quit now */ if (ahandle && (ahandle->proc == (caddr_t) 0)) { @@ -149,26 +157,41 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) return code; } +int +afs_osi_SleepSig(void *event) +{ + afs_osi_Sleep(event); + return 0; +} + #if defined(AFS_HPUX110_ENV) -void afs_osi_Sleep(void *event) +void +afs_osi_Sleep(void *event) { - lock_t * sleep_lock; - - AFS_ASSERT_GLOCK(); - get_sleep_lock(event); - AFS_GUNLOCK(); - sleep((caddr_t) event, PZERO-2); - AFS_GLOCK(); + lock_t *sleep_lock; + + AFS_ASSERT_GLOCK(); + get_sleep_lock(event); + AFS_GUNLOCK(); + sleep((caddr_t) event, PZERO - 2); + AFS_GLOCK(); } -int afs_osi_Wakeup(void *event) +int +afs_osi_Wakeup(void *event) { - lock_t * sleep_lock; + lock_t *sleep_lock; - sleep_lock = get_sleep_lock(event); - wakeup((caddr_t) event); - spinunlock(sleep_lock); - return 0; + sleep_lock = get_sleep_lock(event); + wakeup((caddr_t) event); + spinunlock(sleep_lock); + return 0; +} +#else +int +afs_osi_Wakeup(void *event) +{ + wakeup((caddr_t) event); + return 0; } #endif - diff --git a/src/afs/HPUX/osi_vfs.h b/src/afs/HPUX/osi_vfs.h index 43b9f2519..bfcb3bd15 100644 --- a/src/afs/HPUX/osi_vfs.h +++ b/src/afs/HPUX/osi_vfs.h @@ -6,10 +6,10 @@ /* * Flock(3) call. (from sys/file.h) */ -#define LOCK_SH 1 /* shared lock */ -#define LOCK_EX 2 /* exclusive lock */ -#define LOCK_NB 4 /* don't block when locking */ -#define LOCK_UN 8 /* unlock */ +#define LOCK_SH 1 /* shared lock */ +#define LOCK_EX 2 /* exclusive lock */ +#define LOCK_NB 4 /* don't block when locking */ +#define LOCK_UN 8 /* unlock */ #define d_fileno d_ino diff --git a/src/afs/HPUX/osi_vfsops.c b/src/afs/HPUX/osi_vfsops.c index 15aca3888..bd4e47af1 100644 --- a/src/afs/HPUX/osi_vfsops.c +++ b/src/afs/HPUX/osi_vfsops.c @@ -11,34 +11,77 @@ * osi_vfsops.c for HPUX */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_vfsops.c,v 1.1.1.6 2003/07/30 17:08:07 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_vfsops.c,v 1.13 2003/11/27 01:17:39 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics stuff */ #include +#if defined(AFS_HPUX1123_ENV) +#include +#endif /* AFS_HPUX1123_ENV */ + +#if defined(AFS_HPUX1123_ENV) +/* defind DLKM tables so we can load dynamicly */ +/* we still need an afs_unload to unload */ +/* Note: There is to be a dependency on the + * the name of the struct _wrapper, and the + * name of the dynamicly loaded file + * We will define -DAFS_WRAPPER=_wrapper + * and -DAFS_CONF_DATA=_conf_data and pass into + * this routine + */ + +extern struct mod_operations mod_misc_ops; +extern struct mod_conf_data AFS_CONF_DATA; + +static int afs_load(void *arg); +/* static int afs_unload(void *arg); */ + +struct mod_type_data afs_mod_link = { + "AFS kernel module", + NULL +}; + +struct modlink afs_modlink[] = { + {&mod_misc_ops, &afs_mod_link}, + { NULL, NULL } +}; + +struct modwrapper AFS_WRAPPER = { + MODREV, + afs_load, + NULL, /* should be afs_unload if we had one */ + NULL, + &AFS_CONF_DATA, + afs_modlink +}; + +#endif /* AFS_HPUX1123_ENV */ static char afs_mountpath[512]; struct vfs *afs_globalVFS = 0; struct vcache *afs_globalVp = 0; -int afs_mount(struct vfs *afsp, char *path, smountargs_t *data) +int +afs_mount(struct vfs *afsp, char *path, smountargs_t * data) { AFS_GLOCK(); AFS_STATCNT(afs_mount); - if (afs_globalVFS) { /* Don't allow remounts. */ + if (afs_globalVFS) { /* Don't allow remounts. */ AFS_GUNLOCK(); - return (setuerror(EBUSY)); + return (setuerror(EBUSY)); } afs_globalVFS = afsp; afsp->vfs_bsize = 8192; - afsp->vfs_fsid[0] = AFS_VFSMAGIC; /* magic */ - afsp->vfs_fsid[1] = AFS_VFSFSID; + afsp->vfs_fsid[0] = AFS_VFSMAGIC; /* magic */ + afsp->vfs_fsid[1] = AFS_VFSFSID; strcpy(afsp->vfs_name, "AFS"); afsp->vfs_name[3] = '\0'; @@ -47,7 +90,7 @@ int afs_mount(struct vfs *afsp, char *path, smountargs_t *data) #ifndef AFS_NONFSTRANS /* Set up the xlator in case it wasn't done elsewhere */ - afs_xlatorinit_v2(); + afs_xlatorinit_v2(); #endif AFS_GUNLOCK(); @@ -55,7 +98,8 @@ int afs_mount(struct vfs *afsp, char *path, smountargs_t *data) } -int afs_unmount(struct vfs *afsp) +int +afs_unmount(struct vfs *afsp) { AFS_GLOCK(); AFS_STATCNT(afs_unmount); @@ -65,23 +109,28 @@ int afs_unmount(struct vfs *afsp) AFS_GUNLOCK(); return 0; -} +} -int afs_root (struct vfs *afsp, struct vnode **avpp, char *unused1) +int +afs_root(struct vfs *afsp, struct vnode **avpp, char *unused1) { int code = 0; struct vrequest treq; - register struct vcache *tvp=0; + register struct vcache *tvp = 0; AFS_GLOCK(); AFS_STATCNT(afs_root); if (afs_globalVp && (afs_globalVp->states & CStatd)) { tvp = afs_globalVp; } else { - if (!(code = afs_InitReq(&treq, p_cred(u.u_procp))) && - !(code = afs_CheckInit())) { - tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + afs_globalVp = NULL; + } + + if (!(code = afs_InitReq(&treq, p_cred(u.u_procp))) + && !(code = afs_CheckInit())) { + tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); /* we really want this to stay around */ if (tvp) { afs_globalVp = tvp; @@ -102,9 +151,10 @@ int afs_root (struct vfs *afsp, struct vnode **avpp, char *unused1) AFS_GUNLOCK(); return code; -} +} -int afs_statfs(register struct vfs *afsp, struct k_statvfs *abp) +int +afs_statfs(register struct vfs *afsp, struct k_statvfs *abp) { AFS_GLOCK(); AFS_STATCNT(afs_statfs); @@ -122,25 +172,27 @@ int afs_statfs(register struct vfs *afsp, struct k_statvfs *abp) AFS_GUNLOCK(); return 0; -} +} -int afs_sync(struct vfs *unused1, int unused2) +int +afs_sync(struct vfs *unused1, int unused2) { AFS_STATCNT(afs_sync); return 0; } -int afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp) +int +afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp) { int code; struct vrequest treq; AFS_GLOCK(); AFS_STATCNT(afs_vget); - * avcp = NULL; + *avcp = NULL; - if ((code = afs_InitReq(&treq, p_cred(u.u_procp)))==0) { - code = afs_osi_vget((struct vcache**)avcp, fidp, &treq); + if ((code = afs_InitReq(&treq, p_cred(u.u_procp))) == 0) { + code = afs_osi_vget((struct vcache **)avcp, fidp, &treq); } afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp, @@ -149,16 +201,19 @@ int afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp) AFS_GUNLOCK(); return code; -} +} -int afs_getmount(struct vfs *vfsp, char *fsmntdir, struct mount_data *mdp, char *unused1) +int +afs_getmount(struct vfs *vfsp, char *fsmntdir, struct mount_data *mdp, + char *unused1) { int l; mdp->md_msite = 0; mdp->md_dev = 0; mdp->md_rdev = 0; - return(copyoutstr(afs_mountpath, fsmntdir, strlen(afs_mountpath)+1, &l)); + return (copyoutstr + (afs_mountpath, fsmntdir, strlen(afs_mountpath) + 1, &l)); } @@ -170,29 +225,29 @@ struct vfsops Afs_vfsops = { afs_sync, afs_vget, afs_getmount, - (vfs_freeze_t *)0, /* vfs_freeze */ - (vfs_thaw_t *)0, /* vfs_thaw */ - (vfs_quota_t *)0, /* vfs_quota */ - (vfs_mountroot_t *)0, /* vfs_mountroot. Note: afs_mountroot_nullop in this - * position panicked HP 11.00+ - */ - (vfs_size_t *)0 /* vfs_size */ + (vfs_freeze_t *) 0, /* vfs_freeze */ + (vfs_thaw_t *) 0, /* vfs_thaw */ + (vfs_quota_t *) 0, /* vfs_quota */ + (vfs_mountroot_t *) 0, /* vfs_mountroot. Note: afs_mountroot_nullop in this + * position panicked HP 11.00+ + */ + (vfs_size_t *) 0 /* vfs_size */ }; static int afs_Starting = 0; #pragma align 64 -#if defined(AFS_HPUX110_ENV) -b_sema_t afs_global_sema = {0}; -#else +#if !defined(AFS_HPUX110_ENV) sema_t afs_global_sema = { - NULL, 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, /* sa_type */ - 0, 0, 0, 0, 0, 0, 0, NULL, /* sa_link */ - NULL, NULL + NULL, 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, /* sa_type */ + 0, 0, 0, 0, 0, 0, 0, NULL, /* sa_link */ + NULL, NULL #ifdef SEMA_COUNTING - , 0, 0, 0, NULL + , 0, 0, 0, NULL #endif - }; +}; +#else +b_sema_t afs_global_sema = { 0 }; #endif void @@ -201,14 +256,15 @@ osi_InitGlock() register ulong_t context; SPINLOCK_USAV(sched_lock, context); - if ( !afs_Starting ) { + if (!afs_Starting) { afs_Starting = 1; SPINUNLOCK_USAV(sched_lock, context); #if defined(AFS_HPUX110_ENV) - b_initsema(&afs_global_sema, 1, NFS_LOCK_ORDER2, "AFS GLOCK"); + b_initsema(&afs_global_sema, 1, NFS_LOCK_ORDER2, "AFS GLOCK"); + /* afsHash(64); *//* 64 buckets */ #else initsema(&afs_global_sema, 1, FILESYS_SEMA_PRI, FILESYS_SEMA_ORDER); - afsHash(64); /* 64 buckets */ + afsHash(64); /* 64 buckets */ #endif } else { SPINUNLOCK_USAV(sched_lock, context); @@ -218,10 +274,20 @@ osi_InitGlock() } } +#if defined(AFS_HPUX1123_ENV) +/* DLKM routine called when loaded */ +static int +afs_load(void *arg) +{ + afsc_link(); + return 0; +} +#endif /* AFS_HPUX1123_ENV */ + /* * afsc_link - Initialize VFS */ -int afs_vfs_slot=-1; +int afs_vfs_slot = -1; afsc_link() @@ -230,10 +296,11 @@ afsc_link() /* For now nothing special is required during AFS initialization. */ AFS_STATCNT(afsc_link); - osi_Init(); - if ( (afs_vfs_slot=add_vfs_type("afs", &Afs_vfsops)) < 0 ) + osi_Init(); + if ((afs_vfs_slot = add_vfs_type("afs", &Afs_vfsops)) < 0) return; - sysent_assign_function(AFS_SYSCALL, 7, (void (*)())Afs_syscall, "Afs_syscall"); + sysent_assign_function(AFS_SYSCALL, 7, (void (*)())Afs_syscall, + "Afs_syscall"); sysent_define_arg(AFS_SYSCALL, 0, longArg); sysent_define_arg(AFS_SYSCALL, 1, longArg); sysent_define_arg(AFS_SYSCALL, 2, longArg); @@ -250,4 +317,3 @@ afsc_link() sysent_returns_long(80); return 0; } - diff --git a/src/afs/HPUX/osi_vm.c b/src/afs/HPUX/osi_vm.c index 16d247c36..d3651fe79 100644 --- a/src/afs/HPUX/osi_vm.c +++ b/src/afs/HPUX/osi_vm.c @@ -8,13 +8,14 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_vm.c,v 1.1.1.5 2002/05/10 23:43:52 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_vm.c,v 1.8 2003/07/15 23:14:22 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ /* Try to discard pages, in order to recycle a vcache entry. * @@ -31,9 +32,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_vm.c,v 1.1.1.5 2002/05/10 * therefore obsolescent. */ int -osi_VM_FlushVCache(avc, slept) - struct vcache *avc; - int *slept; +osi_VM_FlushVCache(struct vcache *avc, int *slept) { if (avc->vrefCount > 1) return EBUSY; @@ -50,10 +49,9 @@ osi_VM_FlushVCache(avc, slept) * re-obtained. */ void -osi_VM_StoreAllSegments(avc) - struct vcache *avc; +osi_VM_StoreAllSegments(struct vcache *avc) { - ; /* Nothing here yet */ + ; /* Nothing here yet */ } /* Try to invalidate pages, for "fs flush" or "fs flushv"; or @@ -63,10 +61,7 @@ osi_VM_StoreAllSegments(avc) * re-obtained. */ void -osi_VM_TryToSmush(avc, acred, sync) - struct vcache *avc; - struct AFS_UCRED *acred; - int sync; +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { struct vnode *vp = AFSTOV(avc); @@ -74,7 +69,7 @@ osi_VM_TryToSmush(avc, acred, sync) * from the buffer cache */ if ((vp->v_flag & VTEXT) == 0) { - mpurge(vp); + mpurge(vp); } /* Mark the cached blocks on the free list as invalid; it invalidates blocks * associated with vp which are on the freelist. @@ -88,11 +83,9 @@ osi_VM_TryToSmush(avc, acred, sync) * Locking: No lock is held, not even the global lock. */ void -osi_VM_FlushPages(avc, credp) - struct vcache *avc; - struct AFS_UCRED *credp; +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { - ; /* Nothing here yet */ + ; /* Nothing here yet */ } /* Purge pages beyond end-of-file, when truncating a file. @@ -102,10 +95,7 @@ osi_VM_FlushPages(avc, credp) * it only works on Solaris. */ void -osi_VM_Truncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { - ; /* Nothing here yet */ + ; /* Nothing here yet */ } diff --git a/src/afs/HPUX/osi_vnodeops.c b/src/afs/HPUX/osi_vnodeops.c index b579afcbc..16dbf73dd 100644 --- a/src/afs/HPUX/osi_vnodeops.c +++ b/src/afs/HPUX/osi_vnodeops.c @@ -10,13 +10,14 @@ /* This is a placeholder for routines unique to the port of AFS to hp-ux*/ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/HPUX/osi_vnodeops.c,v 1.1.1.8 2003/07/30 17:08:08 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/HPUX/osi_vnodeops.c,v 1.13 2003/11/27 01:17:39 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics stuff */ #include #include @@ -61,7 +62,6 @@ extern int afs_close(); #define vmemp_unlockx() #endif - #if !defined(AFS_HPUX110_ENV) /* * Copy an mbuf to the contiguous area pointed to by cp. @@ -71,39 +71,39 @@ extern int afs_close(); */ int m_cpytoc(m, off, len, cp) - register struct mbuf *m; - register int off, len; - register caddr_t cp; + register struct mbuf *m; + register int off, len; + register caddr_t cp; { - register int ml; - - if (m == NULL || off < 0 || len < 0 || cp == NULL) - osi_Panic("m_cpytoc"); - while (off && m) - if (m->m_len <= off) { - off -= m->m_len; - m = m->m_next; - continue; - } else - break; - if (m == NULL) - return (len); - - ml = MIN(len, m->m_len - off); - memcpy(cp, mtod(m, caddr_t)+off, (u_int)ml); + register int ml; + + if (m == NULL || off < 0 || len < 0 || cp == NULL) + osi_Panic("m_cpytoc"); + while (off && m) + if (m->m_len <= off) { + off -= m->m_len; + m = m->m_next; + continue; + } else + break; + if (m == NULL) + return (len); + + ml = MIN(len, m->m_len - off); + memcpy(cp, mtod(m, caddr_t) + off, (u_int) ml); + cp += ml; + len -= ml; + m = m->m_next; + + while (len && m) { + ml = m->m_len; + memcpy(cp, mtod(m, caddr_t), (u_int) ml); cp += ml; len -= ml; m = m->m_next; + } - while (len && m) { - ml = m->m_len; - memcpy(cp, mtod(m, caddr_t), (u_int)ml); - cp += ml; - len -= ml; - m = m->m_next; - } - - return (len); + return (len); } #endif @@ -115,14 +115,14 @@ m_cpytoc(m, off, len, cp) * fcntl() looking request, and then translate the results back if necessary. * we call afs_lockctl() directly . */ -afs_lockf( vp, flag, len, cred, fp, LB, UB ) - struct vnode *vp; - int flag; - struct AFS_UCRED *cred; - struct file *fp; - k_off_t len, LB, UB; +afs_lockf(vp, flag, len, cred, fp, LB, UB) + struct vnode *vp; + int flag; + struct AFS_UCRED *cred; + struct file *fp; + k_off_t len, LB, UB; { - /*for now, just pretend it works*/ + /*for now, just pretend it works */ struct k_flock flock; int cmd, code; @@ -134,7 +134,7 @@ afs_lockf( vp, flag, len, cred, fp, LB, UB ) flock.l_len = len; flock.l_start = fp->f_offset; /* convert negative lengths to positive */ - if (flock.l_len < 0 ) { + if (flock.l_len < 0) { flock.l_start += flock.l_len; flock.l_len = -(flock.l_len); } @@ -147,19 +147,19 @@ afs_lockf( vp, flag, len, cred, fp, LB, UB ) flock.l_type = F_WRLCK; cmd = F_SETLK; switch (flag) { - case F_ULOCK: + case F_ULOCK: flock.l_type = F_UNLCK; break; - case F_LOCK: + case F_LOCK: cmd = F_SETLKW; break; - case F_TEST: + case F_TEST: cmd = F_GETLK; break; } - u.u_error = mp_afs_lockctl(vp, &flock, cmd, fp->f_cred); + u.u_error = mp_afs_lockctl(vp, &flock, cmd, fp->f_cred); if (u.u_error) { - return(u.u_error); /* some other error code */ + return (u.u_error); /* some other error code */ } /* * if request is F_TEST, and GETLK changed @@ -175,28 +175,37 @@ afs_lockf( vp, flag, len, cred, fp, LB, UB ) #if defined(AFS_HPUX1122_ENV) -#include "../machine/vm/vmparam.h" +#include "machine/vm/vmparam.h" #else -#include "../machine/vmparam.h" /* For KERNELSPACE */ +#include "../machine/vmparam.h" /* For KERNELSPACE */ +#endif +#include "h/debug.h" +#include "h/types.h" +#if !defined(AFS_HPUX1123_ENV) + /* 11.23 is using 64 bit in many cases */ +#define kern_daddr_t daddr_t #endif -#include "../h/debug.h" -#include "../h/types.h" -#include "../h/param.h" -#include "../h/vmmac.h" -#include "../h/time.h" -#include "../ufs/inode.h" -#include "../ufs/fs.h" -#include "../h/dbd.h" -#include "../h/vfd.h" -#include "../h/region.h" -#include "../h/pregion.h" -#include "../h/vmmeter.h" -#include "../h/user.h" -#include "../h/sysinfo.h" -#include "../h/pfdat.h" -#include "../h/tuneable.h" -#include "../h/buf.h" -#include "../netinet/in.h" +#include "h/param.h" +#include "h/vmmac.h" +#include "h/time.h" +#include "ufs/inode.h" +#include "ufs/fs.h" +#include "h/dbd.h" +#if defined(AFS_HPUX1123_ENV) +dbd_t *finddbd(); +#endif /* AFS_HPUX1123_ENV */ +#include "h/vfd.h" +#include "h/region.h" +#include "h/pregion.h" +#include "h/vmmeter.h" +#include "h/user.h" +#include "h/sysinfo.h" +#include "h/pfdat.h" +#if !defined(AFS_HPUX1123_ENV) +#include "h/tuneable.h" +#endif +#include "h/buf.h" +#include "netinet/in.h" /* a freelist of one */ struct buf *afs_bread_freebp = 0; @@ -206,58 +215,57 @@ struct buf *afs_bread_freebp = 0; * Thus we can use fake bufs (ie not from the real buffer pool). */ afs_bread(vp, lbn, bpp) - struct vnode *vp; - daddr_t lbn; - struct buf **bpp; + struct vnode *vp; + kern_daddr_t lbn; + struct buf **bpp; { - int offset, fsbsize, error; - struct buf *bp; - struct iovec iov; - struct uio uio; - - AFS_STATCNT(afs_bread); - fsbsize = vp->v_vfsp->vfs_bsize; - offset = lbn * fsbsize; - if (afs_bread_freebp) { - bp = afs_bread_freebp; - afs_bread_freebp = 0; - } else { - bp = (struct buf *) AFS_KALLOC(sizeof(*bp)); - bp->b_un.b_addr = (caddr_t) AFS_KALLOC(fsbsize); - } + int offset, fsbsize, error; + struct buf *bp; + struct iovec iov; + struct uio uio; + + AFS_STATCNT(afs_bread); + fsbsize = vp->v_vfsp->vfs_bsize; + offset = lbn * fsbsize; + if (afs_bread_freebp) { + bp = afs_bread_freebp; + afs_bread_freebp = 0; + } else { + bp = (struct buf *)AFS_KALLOC(sizeof(*bp)); + bp->b_un.b_addr = (caddr_t) AFS_KALLOC(fsbsize); + } - iov.iov_base = bp->b_un.b_addr; - iov.iov_len = fsbsize; - uio.afsio_iov = &iov; - uio.afsio_iovcnt = 1; - uio.afsio_seg = AFS_UIOSYS; - uio.afsio_offset = offset; - uio.afsio_resid = fsbsize; - uio.uio_fpflags = 0; - *bpp = 0; - - error = afs_read(VTOAFS(vp), &uio, p_cred(u.u_procp), - lbn, bpp, 0); - if (error) { - afs_bread_freebp = bp; - return error; - } - if (*bpp) { - afs_bread_freebp = bp; - } else { - *(struct buf **)&bp->b_vp = bp; /* mark as fake */ - *bpp = bp; - } - return 0; + iov.iov_base = bp->b_un.b_addr; + iov.iov_len = fsbsize; + uio.afsio_iov = &iov; + uio.afsio_iovcnt = 1; + uio.afsio_seg = AFS_UIOSYS; + uio.afsio_offset = offset; + uio.afsio_resid = fsbsize; + uio.uio_fpflags = 0; + *bpp = 0; + + error = afs_read(VTOAFS(vp), &uio, p_cred(u.u_procp), lbn, bpp, 0); + if (error) { + afs_bread_freebp = bp; + return error; + } + if (*bpp) { + afs_bread_freebp = bp; + } else { + *(struct buf **)&bp->b_vp = bp; /* mark as fake */ + *bpp = bp; + } + return 0; } afs_brelse(vp, bp) -struct vnode *vp; -struct buf *bp; + struct vnode *vp; + struct buf *bp; { AFS_STATCNT(afs_brelse); - if ((struct buf *)bp->b_vp != bp) { /* not fake */ + if ((struct buf *)bp->b_vp != bp) { /* not fake */ ufs_brelse(bp->b_vp, bp); } else if (afs_bread_freebp) { AFS_KFREE(bp->b_un.b_addr, vp->v_vfsp->vfs_bsize); @@ -269,42 +277,45 @@ struct buf *bp; afs_bmap(avc, abn, anvp, anbn) - register struct vcache *avc; - afs_int32 abn, *anbn; - struct vcache **anvp; { + register struct vcache *avc; + kern_daddr_t abn, *anbn; + struct vcache **anvp; +{ AFS_STATCNT(afs_bmap); if (anvp) *anvp = avc; if (anbn) - *anbn = abn * (8192 / DEV_BSIZE); /* in 512 byte units */ + *anbn = abn * (8192 / DEV_BSIZE); /* in 512 byte units */ return 0; } afs_inactive(avc, acred) - register struct vcache *avc; - struct AFS_UCRED *acred; + register struct vcache *avc; + struct AFS_UCRED *acred; { struct vnode *vp = AFSTOV(avc); ulong_t context; lock_t *sv_lock; - if (afs_shuttingdown) return ; + if (afs_shuttingdown) + return; /* * In Solaris and HPUX s800 and HP-UX10.0 they actually call us with * v_count 1 on last reference! */ - MP_H_SPINLOCK_USAV(vn_h_sl_pool,vp,&sv_lock,&context); - if (avc->vrefCount < 1) osi_Panic("afs_inactive : v_count < 1\n"); + MP_H_SPINLOCK_USAV(vn_h_sl_pool, vp, &sv_lock, &context); + if (avc->vrefCount < 1) + osi_Panic("afs_inactive : v_count < 1\n"); /* * If more than 1 don't unmap the vnode but do decrement the ref count */ vp->v_count--; if (vp->v_count > 0) { - MP_SPINUNLOCK_USAV(sv_lock,context); + MP_SPINUNLOCK_USAV(sv_lock, context); return 0; } - MP_SPINUNLOCK_USAV(sv_lock,context); + MP_SPINUNLOCK_USAV(sv_lock, context); afs_InactiveVCache(avc, acred); return 0; } @@ -333,7 +344,8 @@ mp_afs_close(register struct vnode *avcp, int aflags, struct AFS_UCRED *acred) } int -mp_afs_rdwr(register struct vnode *avcp, struct uio *uio, enum uio_rw arw, int aio, struct AFS_UCRED *acred) +mp_afs_rdwr(register struct vnode *avcp, struct uio *uio, enum uio_rw arw, + int aio, struct AFS_UCRED *acred) { register int code; long save_resid; @@ -350,7 +362,8 @@ mp_afs_rdwr(register struct vnode *avcp, struct uio *uio, enum uio_rw arw, int a } int -mp_afs_getattr(register struct vnode *avcp, struct vattr *attrs, struct AFS_UCRED *acred, enum vsync unused1) +mp_afs_getattr(register struct vnode *avcp, struct vattr *attrs, + struct AFS_UCRED *acred, enum vsync unused1) { register int code; @@ -361,7 +374,8 @@ mp_afs_getattr(register struct vnode *avcp, struct vattr *attrs, struct AFS_UCRE } int -mp_afs_setattr(register struct vnode *avcp, register struct vattr *attrs, struct AFS_UCRED *acred, int unused1) +mp_afs_setattr(register struct vnode *avcp, register struct vattr *attrs, + struct AFS_UCRED *acred, int unused1) { register int code; @@ -383,7 +397,9 @@ mp_afs_access(register struct vnode *avcp, int mode, struct AFS_UCRED *acred) } int -mp_afs_lookup(register struct vnode *adp, char *aname, register struct vnode **avcp, struct AFS_UCRED *acred, struct vnode *unused1) +mp_afs_lookup(register struct vnode *adp, char *aname, + register struct vnode **avcp, struct AFS_UCRED *acred, + struct vnode *unused1) { register int code; @@ -394,7 +410,9 @@ mp_afs_lookup(register struct vnode *adp, char *aname, register struct vnode **a } int -mp_afs_create(register struct vnode *adp, char *aname, struct vattr *attrs, enum vcexcl aexcl, int amode, struct vnode **avcp, struct AFS_UCRED *acred) +mp_afs_create(register struct vnode *adp, char *aname, struct vattr *attrs, + enum vcexcl aexcl, int amode, struct vnode **avcp, + struct AFS_UCRED *acred) { register int code; @@ -406,7 +424,8 @@ mp_afs_create(register struct vnode *adp, char *aname, struct vattr *attrs, enum int -mp_afs_remove(register struct vnode *adp, char *aname, struct AFS_UCRED *acred) +mp_afs_remove(register struct vnode *adp, char *aname, + struct AFS_UCRED *acred) { register int code; @@ -417,7 +436,8 @@ mp_afs_remove(register struct vnode *adp, char *aname, struct AFS_UCRED *acred) } int -mp_afs_link(register struct vnode *avc, register struct vnode *adp, char *aname, struct AFS_UCRED *acred) +mp_afs_link(register struct vnode *avc, register struct vnode *adp, + char *aname, struct AFS_UCRED *acred) { register int code; @@ -428,7 +448,9 @@ mp_afs_link(register struct vnode *avc, register struct vnode *adp, char *aname, } int -mp_afs_rename(register struct vnode *aodp, char *aname1, register struct vnode *andp, char *aname2, struct AFS_UCRED *acred) +mp_afs_rename(register struct vnode *aodp, char *aname1, + register struct vnode *andp, char *aname2, + struct AFS_UCRED *acred) { register int code; @@ -439,7 +461,8 @@ mp_afs_rename(register struct vnode *aodp, char *aname1, register struct vnode * } int -mp_afs_mkdir(register struct vnode *adp, char *aname, struct vattr *attrs, register struct vnode **avcp, struct AFS_UCRED *acred) +mp_afs_mkdir(register struct vnode *adp, char *aname, struct vattr *attrs, + register struct vnode **avcp, struct AFS_UCRED *acred) { register int code; @@ -463,18 +486,20 @@ mp_afs_rmdir(register struct vnode *adp, char *aname, struct AFS_UCRED *acred) int -mp_afs_readdir(register struct vnode *avc, struct uio *auio, struct AFS_UCRED *acred) +mp_afs_readdir(register struct vnode *avc, struct uio *auio, + struct AFS_UCRED *acred) { register int code; AFS_GLOCK(); code = afs_readdir(avc, auio, acred); AFS_GUNLOCK(); - return (code); + return (code); } int -mp_afs_symlink(register struct vnode *adp, char *aname, struct vattr *attrs, char *atargetName, struct AFS_UCRED *acred) +mp_afs_symlink(register struct vnode *adp, char *aname, struct vattr *attrs, + char *atargetName, struct AFS_UCRED *acred) { register int code; @@ -486,7 +511,8 @@ mp_afs_symlink(register struct vnode *adp, char *aname, struct vattr *attrs, cha int -mp_afs_readlink(register struct vnode *avc, struct uio *auio, struct AFS_UCRED *acred) +mp_afs_readlink(register struct vnode *avc, struct uio *auio, + struct AFS_UCRED *acred) { register int code; @@ -508,7 +534,8 @@ mp_afs_fsync(register struct vnode *avc, struct AFS_UCRED *acred, int unused1) } int -mp_afs_bread(register struct vnode *avc, daddr_t lbn, struct buf **bpp, struct vattr *unused1, struct ucred *unused2) +mp_afs_bread(register struct vnode *avc, kern_daddr_t lbn, struct buf **bpp, + struct vattr *unused1, struct ucred *unused2) { register int code; @@ -542,7 +569,9 @@ mp_afs_inactive(register struct vnode *avc, struct AFS_UCRED *acred) } int -mp_afs_lockctl(struct vnode *avc, struct flock *af, int cmd, struct AFS_UCRED *acred, struct file *unused1, off_t unused2, off_t unused3) +mp_afs_lockctl(struct vnode *avc, struct flock *af, int cmd, + struct AFS_UCRED *acred, struct file *unused1, off_t unused2, + off_t unused3) { register int code; @@ -562,8 +591,10 @@ mp_afs_fid(struct vnode *avc, struct fid **fidpp) AFS_GUNLOCK(); return (code); } + int -mp_afs_readdir2(register struct vnode *avc, struct uio *auio, struct AFS_UCRED *acred) +mp_afs_readdir2(register struct vnode *avc, struct uio *auio, + struct AFS_UCRED *acred) { register int code; @@ -575,66 +606,66 @@ mp_afs_readdir2(register struct vnode *avc, struct uio *auio, struct AFS_UCRED * struct vnodeops Afs_vnodeops = { - mp_afs_open, - mp_afs_close, - mp_afs_rdwr, - afs_ioctl, - afs_noop, - mp_afs_getattr, - mp_afs_setattr, - mp_afs_access, - mp_afs_lookup, - mp_afs_create, - mp_afs_remove, - mp_afs_link, - mp_afs_rename, - mp_afs_mkdir, - mp_afs_rmdir, - afs_readdir, - mp_afs_symlink, - mp_afs_readlink, - mp_afs_fsync, - mp_afs_inactive, - afs_bmap, - afs_hp_strategy, + mp_afs_open, + mp_afs_close, + mp_afs_rdwr, + afs_ioctl, + afs_noop, + mp_afs_getattr, + mp_afs_setattr, + mp_afs_access, + mp_afs_lookup, + mp_afs_create, + mp_afs_remove, + mp_afs_link, + mp_afs_rename, + mp_afs_mkdir, + mp_afs_rmdir, + afs_readdir, + mp_afs_symlink, + mp_afs_readlink, + mp_afs_fsync, + mp_afs_inactive, + afs_bmap, + afs_hp_strategy, #if !defined(AFS_NONFSTRANS) - /* on HPUX102 the nfs translator calls afs_bread but does - * not call afs_brelse. Hence we see a memory leak. If the - * VOP_BREAD() call fails, then nfs does VOP_RDWR() to get - * the same data : this is the path we follow now. */ - afs_noop, - afs_noop, + /* on HPUX102 the nfs translator calls afs_bread but does + * not call afs_brelse. Hence we see a memory leak. If the + * VOP_BREAD() call fails, then nfs does VOP_RDWR() to get + * the same data : this is the path we follow now. */ + afs_noop, + afs_noop, #else - mp_afs_bread, - mp_afs_brelse, + mp_afs_bread, + mp_afs_brelse, #endif - afs_badop, /* pathsend */ - afs_noop, /* setacl */ - afs_noop, /* getacl */ - afs_pathconf, - afs_pathconf, - mp_afs_lockctl, - afs_lockf, /* lockf */ - mp_afs_fid, - afs_noop, /*fsctl */ - afs_badop, - afs_pagein, - afs_pageout, - NULL, - NULL, - afs_prealloc, - afs_mapdbd, - afs_mmap, - afs_cachelimit, - afs_vm_checkpage, - afs_vm_fscontiguous, - afs_vm_stopio, - afs_read_ahead , - afs_release, - afs_unmap, - afs_swapfs_len, - mp_afs_readdir2, - afs_readdir3, + afs_badop, /* pathsend */ + afs_noop, /* setacl */ + afs_noop, /* getacl */ + afs_pathconf, + afs_pathconf, + mp_afs_lockctl, + afs_lockf, /* lockf */ + mp_afs_fid, + afs_noop, /*fsctl */ + afs_badop, + afs_pagein, + afs_pageout, + NULL, + NULL, + afs_prealloc, + afs_mapdbd, + afs_mmap, + afs_cachelimit, + afs_vm_checkpage, + afs_vm_fscontiguous, + afs_vm_stopio, + afs_read_ahead, + afs_release, + afs_unmap, + afs_swapfs_len, + mp_afs_readdir2, + afs_readdir3, }; struct vnodeops *afs_ops = &Afs_vnodeops; @@ -662,133 +693,130 @@ struct fileops afs_fileops = { ******************************************************************** */ pgcnt_t -afspgin_setup_io_ranges( - vfspage_t *vm_info, - pgcnt_t bpages, - k_off_t isize, - pgcnt_t startindex) +afspgin_setup_io_ranges(vfspage_t * vm_info, pgcnt_t bpages, k_off_t isize, + pgcnt_t startindex) { - pgcnt_t file_offset = VM_FILE_OFFSET(vm_info); - pgcnt_t minpage; /* first page to bring in */ - pgcnt_t maxpage; /* one past last page to bring in */ - pgcnt_t maxpagein; - pgcnt_t multio_maxpage; - daddr_t start_blk; - dbd_t *dbd; - expnd_flags_t up_reason, down_reason; - int count = 1; - int indx = 0; - int max_num_io; - int dbdtype; - preg_t *prp; - - VM_GET_IO_INFO(vm_info, maxpagein, max_num_io); - - /* - * We do not go past the end of the current pregion nor past the end - * of the current file. - */ - - maxpage = startindex + (bpages - (startindex+file_offset) % bpages); - maxpage = vm_reset_maxpage(vm_info, maxpage); - maxpage = MIN(maxpage, (pgcnt_t)btorp(isize) - file_offset); - maxpage = MIN(maxpage, startindex + maxpagein); - multio_maxpage = maxpage = vm_maxpage(vm_info, maxpage); - - if (!maxpage) - return (0); - - VASSERT(maxpage >= startindex); - - /* - * Expanding the fault will create calls to FINDENTRY() for new - * pages, which will obsolete "dbd", so copy what it points to - * and clear it to prevent using stale data. - */ - - prp = VM_PRP(vm_info); - dbdtype = DBD_TYPE(vm_info); - start_blk = DBD_DATA(vm_info); - vm_info->dbd = NULL; - vm_info->vfd = NULL; - VASSERT(dbdtype != DBD_NONE); - - if (max_num_io == 1) { - /* - * We need to set up one I/O: First we attempt to expand the - * I/O forward. Then we expand the I/O backwards. - */ - count = expand_faultin_up(vm_info, dbdtype, (int)bpages, - maxpage, count, startindex, - start_blk, &up_reason); - maxpage = startindex + count; - VASSERT(maxpage <= startindex + maxpagein); - minpage = startindex - (startindex+file_offset) % bpages; - minpage = MAX(minpage, maxpage - maxpagein); - VASSERT(startindex >= VM_BASE_OFFSET(vm_info)); - minpage = vm_minpage(vm_info, minpage); - VASSERT(minpage <= startindex); - count = expand_faultin_down(vm_info, dbdtype, (int)bpages, - minpage, count, &startindex, - &start_blk, &down_reason); - VM_SET_IO_STARTINDX(vm_info, 0, startindex); - VM_SET_IO_STARTBLK(vm_info, 0, start_blk); - VM_SET_IO_COUNT(vm_info, 0, count); - VM_SET_NUM_IO(vm_info, 1); - } - - if (max_num_io > 1) { - /* - * We need to set up multiple I/O information; beginning - * with the startindex, we will expand upwards. The expansion - * could stop for one of 2 reasons; we take the appropriate - * action in each of these cases: - * o VM reasons: abort setting up the multiple I/O - * information and return to our caller indicating - * that "retry" is required. - * o pagelimit: set up the next I/O info [we may have - * reached multio_maxpage at this point]. - * Note that expansion involves no more than a block at a time; - * hence it could never stop due to "discontiguous block" - * reason. - */ - startindex = minpage = vm_minpage(vm_info, 0); - for (indx = 0; - (indx < max_num_io) && (startindex < multio_maxpage); - indx++, startindex +=count) { - dbd = FINDDBD(prp->p_reg, startindex); - start_blk = dbd->dbd_data; - maxpage = startindex + - (bpages - (startindex+file_offset) % bpages); - maxpage = min(maxpage, multio_maxpage); - count = expand_faultin_up(vm_info, dbdtype, - bpages, maxpage, 1 /* count */, - startindex, start_blk, &up_reason); - VM_SET_IO_STARTINDX(vm_info, indx, startindex); - VM_SET_IO_STARTBLK(vm_info, indx, start_blk); - VM_SET_IO_COUNT(vm_info, indx, count); - if (up_reason & VM_REASONS) - break; - VASSERT(!(up_reason&NONCONTIGUOUS_BLOCK)); - VASSERT(up_reason & PAGELIMIT); - } - if (startindex < multio_maxpage) { - VM_MULT_IO_FAILURE(vm_info); - VM_REINIT_FAULT_DBDVFD(vm_info); - return (0); /* retry */ - } - count = maxpagein; - VM_SET_NUM_IO(vm_info, indx); - } - - /* - * Tell VM where the I/O intends to start. This may be different - * from the faulting point. - */ - - VM_SET_STARTINDX(vm_info, VM_GET_IO_STARTINDX(vm_info, 0)); - - return(count); + pgcnt_t file_offset = VM_FILE_OFFSET(vm_info); + pgcnt_t minpage; /* first page to bring in */ + pgcnt_t maxpage; /* one past last page to bring in */ + pgcnt_t maxpagein; + pgcnt_t multio_maxpage; + kern_daddr_t start_blk; + dbd_t *dbd; + expnd_flags_t up_reason, down_reason; + int count = 1; + int indx = 0; + int max_num_io; + int dbdtype; + preg_t *prp; + + VM_GET_IO_INFO(vm_info, maxpagein, max_num_io); + + /* + * We do not go past the end of the current pregion nor past the end + * of the current file. + */ + + maxpage = startindex + (bpages - (startindex + file_offset) % bpages); + maxpage = vm_reset_maxpage(vm_info, maxpage); + maxpage = MIN(maxpage, (pgcnt_t) btorp(isize) - file_offset); + maxpage = MIN(maxpage, startindex + maxpagein); + multio_maxpage = maxpage = vm_maxpage(vm_info, maxpage); + + if (!maxpage) + return (0); + + VASSERT(maxpage >= startindex); + + /* + * Expanding the fault will create calls to FINDENTRY() for new + * pages, which will obsolete "dbd", so copy what it points to + * and clear it to prevent using stale data. + */ + + prp = VM_PRP(vm_info); + dbdtype = DBD_TYPE(vm_info); + start_blk = DBD_DATA(vm_info); + vm_info->dbd = NULL; + vm_info->vfd = NULL; + VASSERT(dbdtype != DBD_NONE); + + if (max_num_io == 1) { + /* + * We need to set up one I/O: First we attempt to expand the + * I/O forward. Then we expand the I/O backwards. + */ + count = + expand_faultin_up(vm_info, dbdtype, (int)bpages, maxpage, count, + startindex, start_blk, &up_reason); + maxpage = startindex + count; + VASSERT(maxpage <= startindex + maxpagein); + minpage = startindex - (startindex + file_offset) % bpages; + minpage = MAX(minpage, maxpage - maxpagein); + VASSERT(startindex >= VM_BASE_OFFSET(vm_info)); + minpage = vm_minpage(vm_info, minpage); + VASSERT(minpage <= startindex); + count = + expand_faultin_down(vm_info, dbdtype, (int)bpages, minpage, count, + &startindex, &start_blk, &down_reason); + VM_SET_IO_STARTINDX(vm_info, 0, startindex); + VM_SET_IO_STARTBLK(vm_info, 0, start_blk); + VM_SET_IO_COUNT(vm_info, 0, count); + VM_SET_NUM_IO(vm_info, 1); + } + + if (max_num_io > 1) { + /* + * We need to set up multiple I/O information; beginning + * with the startindex, we will expand upwards. The expansion + * could stop for one of 2 reasons; we take the appropriate + * action in each of these cases: + * o VM reasons: abort setting up the multiple I/O + * information and return to our caller indicating + * that "retry" is required. + * o pagelimit: set up the next I/O info [we may have + * reached multio_maxpage at this point]. + * Note that expansion involves no more than a block at a time; + * hence it could never stop due to "discontiguous block" + * reason. + */ + startindex = minpage = vm_minpage(vm_info, 0); + for (indx = 0; (indx < max_num_io) && (startindex < multio_maxpage); + indx++, startindex += count) { + dbd = FINDDBD(prp->p_reg, startindex); + start_blk = dbd->dbd_data; + maxpage = + startindex + (bpages - (startindex + file_offset) % bpages); + maxpage = min(maxpage, multio_maxpage); + count = + expand_faultin_up(vm_info, dbdtype, bpages, maxpage, + 1 /* count */ , + startindex, start_blk, &up_reason); + VM_SET_IO_STARTINDX(vm_info, indx, startindex); + VM_SET_IO_STARTBLK(vm_info, indx, start_blk); + VM_SET_IO_COUNT(vm_info, indx, count); + if (up_reason & VM_REASONS) + break; + VASSERT(!(up_reason & NONCONTIGUOUS_BLOCK)); + VASSERT(up_reason & PAGELIMIT); + } + if (startindex < multio_maxpage) { + VM_MULT_IO_FAILURE(vm_info); + VM_REINIT_FAULT_DBDVFD(vm_info); + return (0); /* retry */ + } + count = maxpagein; + VM_SET_NUM_IO(vm_info, indx); + } + + /* + * Tell VM where the I/O intends to start. This may be different + * from the faulting point. + */ + + VM_SET_STARTINDX(vm_info, VM_GET_IO_STARTINDX(vm_info, 0)); + + return (count); } @@ -800,39 +828,36 @@ afspgin_setup_io_ranges( ******************************************************************** */ retval_t -afspgin_blkflsh ( - vfspage_t *vm_info, - struct vnode *devvp, - pgcnt_t *num_4k) +afspgin_blkflsh(vfspage_t * vm_info, struct vnode * devvp, pgcnt_t * num_4k) { - int flush_reslt = 0; - pgcnt_t count = *num_4k; - pgcnt_t page_count; - int indx = 0; - int num_io = VM_GET_NUM_IO(vm_info); - - /* - * On this blkflush() we don't want to purge the buffer cache and we do - * want to wait, so the flags are '0'. - */ - - for (indx = 0; indx < num_io; indx++) { - flush_reslt = blkflush(devvp, - (daddr_t)VM_GET_IO_STARTBLK(vm_info, indx), - ptob(VM_GET_IO_COUNT(vm_info, indx)), - 0, VM_REGION(vm_info)); - if (flush_reslt) { - vm_lock(vm_info); - if (vm_page_now_valid(vm_info, &page_count)) { - vm_release_memory(vm_info); - vm_release_structs(vm_info); - *num_4k = page_count; - return(VM_PAGE_PRESENT); - } - return (VM_RETRY); - } - } - return (VM_DONE); + int flush_reslt = 0; + pgcnt_t count = *num_4k; + pgcnt_t page_count; + int indx = 0; + int num_io = VM_GET_NUM_IO(vm_info); + + /* + * On this blkflush() we don't want to purge the buffer cache and we do + * want to wait, so the flags are '0'. + */ + + for (indx = 0; indx < num_io; indx++) { + flush_reslt = + blkflush(devvp, (kern_daddr_t) VM_GET_IO_STARTBLK(vm_info, indx), + ptob(VM_GET_IO_COUNT(vm_info, indx)), 0, + VM_REGION(vm_info)); + if (flush_reslt) { + vm_lock(vm_info); + if (vm_page_now_valid(vm_info, &page_count)) { + vm_release_memory(vm_info); + vm_release_structs(vm_info); + *num_4k = page_count; + return (VM_PAGE_PRESENT); + } + return (VM_RETRY); + } + } + return (VM_DONE); } /* @@ -843,104 +868,96 @@ afspgin_blkflsh ( ******************************************************************** */ int -afspgin_io( - vfspage_t *vm_info, - struct vnode *devvp, - pgcnt_t bpages, - pgcnt_t maxpagein, - pgcnt_t count) +afspgin_io(vfspage_t * vm_info, struct vnode *devvp, pgcnt_t bpages, + pgcnt_t maxpagein, pgcnt_t count) { - int i; - int error = 0; - caddr_t vaddr = VM_ADDR(vm_info); - caddr_t virt_addr = VM_MAPPED_ADDR(vm_info); - pagein_info_t *io = VM_PAGEIN_INFO(vm_info); - preg_t *prp = VM_PRP(vm_info); - int wrt = VM_WRT(vm_info); - space_t space = VM_SPACE(vm_info); - int num_io = VM_GET_NUM_IO(vm_info); - -#ifdef notdef /* Not used in AFS */ - /* - * With VM_READ_AHEAD_ALLOWED() macro, check if read-ahead should - * be used in this case. - * - * Unlike UFS, NFS does not start the faulting page I/O - * asynchronously. Why? Asynchronous requests are handled by the - * biod's. It doesn't make sense to queue up the faulting request - * behind other asynchrnous requests. This is not true for UFS - * where the asynchrnous request is immediately handled. - */ - - if ((VM_READ_AHEAD_ALLOWED(vm_info)) && - (nfs_read_ahead_on) && - (NFS_DO_READ_AHEAD) && - (should_do_read_ahead(prp, vaddr))) { - - pgcnt_t max_rhead_io; - caddr_t rhead_vaddr; - pgcnt_t total_rheads_allowed; - - /* - * Determine the maximum amount of read-ahead I/O. - */ - total_rheads_allowed = maxpagein - count ; - - /* - * If the count is less than a block, raise it to one. - */ - if (total_rheads_allowed < bpages) - total_rheads_allowed = bpages; - - max_rhead_io = total_rheads_allowed; - rhead_vaddr = VM_MAPPED_ADDR(vm_info) + (count*NBPG); - error = nfs_read_ahead(vm_info->vp, prp, wrt, space, - rhead_vaddr, &max_rhead_io); - - /* - * Set the next fault location. If read_ahead launches any - * I/O it will adjust it accordingly. - */ - vm_info->prp->p_nextfault = vm_info->startindex + count; - - /* - * Now perform the faulting I/O synchronously. - */ - vm_unlock(vm_info); - - error = syncpageio((swblk_t)VM_GET_IO_STARTBLK(vm_info, 0), - VM_MAPPED_SPACE(vm_info), - VM_MAPPED_ADDR(vm_info), - (int)ptob(count), B_READ, devvp, - B_vfs_pagein|B_pagebf, VM_REGION(vm_info)); - } else + int i; + int error = 0; + caddr_t vaddr = VM_ADDR(vm_info); + caddr_t virt_addr = VM_MAPPED_ADDR(vm_info); + pagein_info_t *io = VM_PAGEIN_INFO(vm_info); + preg_t *prp = VM_PRP(vm_info); + int wrt = VM_WRT(vm_info); + space_t space = VM_SPACE(vm_info); + int num_io = VM_GET_NUM_IO(vm_info); + +#ifdef notdef /* Not used in AFS */ + /* + * With VM_READ_AHEAD_ALLOWED() macro, check if read-ahead should + * be used in this case. + * + * Unlike UFS, NFS does not start the faulting page I/O + * asynchronously. Why? Asynchronous requests are handled by the + * biod's. It doesn't make sense to queue up the faulting request + * behind other asynchrnous requests. This is not true for UFS + * where the asynchrnous request is immediately handled. + */ + + if ((VM_READ_AHEAD_ALLOWED(vm_info)) && (nfs_read_ahead_on) + && (NFS_DO_READ_AHEAD) && (should_do_read_ahead(prp, vaddr))) { + + pgcnt_t max_rhead_io; + caddr_t rhead_vaddr; + pgcnt_t total_rheads_allowed; + + /* + * Determine the maximum amount of read-ahead I/O. + */ + total_rheads_allowed = maxpagein - count; + + /* + * If the count is less than a block, raise it to one. + */ + if (total_rheads_allowed < bpages) + total_rheads_allowed = bpages; + + max_rhead_io = total_rheads_allowed; + rhead_vaddr = VM_MAPPED_ADDR(vm_info) + (count * NBPG); + error = + nfs_read_ahead(vm_info->vp, prp, wrt, space, rhead_vaddr, + &max_rhead_io); + + /* + * Set the next fault location. If read_ahead launches any + * I/O it will adjust it accordingly. + */ + vm_info->prp->p_nextfault = vm_info->startindex + count; + + /* + * Now perform the faulting I/O synchronously. + */ + vm_unlock(vm_info); + + error = + syncpageio((swblk_t) VM_GET_IO_STARTBLK(vm_info, 0), + VM_MAPPED_SPACE(vm_info), VM_MAPPED_ADDR(vm_info), + (int)ptob(count), B_READ, devvp, + B_vfs_pagein | B_pagebf, VM_REGION(vm_info)); + } else #endif - { - virt_addr = VM_MAPPED_ADDR(vm_info); - vm_unlock(vm_info); - for (i = 0; i < num_io; i++) { - /* - * REVISIT -- investigate doing asyncpageio(). - */ - error |= (io[i].error = - syncpageio( - (swblk_t)VM_GET_IO_STARTBLK(vm_info, i), - VM_MAPPED_SPACE(vm_info), - virt_addr, - (int)ptob(VM_GET_IO_COUNT(vm_info, i)), - B_READ, devvp, - B_vfs_pagein|B_pagebf, - VM_REGION(vm_info))); - virt_addr += ptob(VM_GET_IO_COUNT(vm_info, i)); - } - /* - * Set the next fault location. If read_ahead launches any - * I/O it will adjust it accordingly. - */ - vm_info->prp->p_nextfault = vm_info->startindex + count; - } - - return (error); + { + virt_addr = VM_MAPPED_ADDR(vm_info); + vm_unlock(vm_info); + for (i = 0; i < num_io; i++) { + /* + * REVISIT -- investigate doing asyncpageio(). + */ + error |= (io[i].error = + syncpageio((swblk_t) VM_GET_IO_STARTBLK(vm_info, i), + VM_MAPPED_SPACE(vm_info), virt_addr, + (int)ptob(VM_GET_IO_COUNT(vm_info, i)), + B_READ, devvp, B_vfs_pagein | B_pagebf, + VM_REGION(vm_info))); + virt_addr += ptob(VM_GET_IO_COUNT(vm_info, i)); + } + /* + * Set the next fault location. If read_ahead launches any + * I/O it will adjust it accordingly. + */ + vm_info->prp->p_nextfault = vm_info->startindex + count; + } + + return (error); } /* @@ -951,91 +968,90 @@ afspgin_io( ******************************************************************** */ void -afspgin_update_dbd( - vfspage_t *vm_info, - int bsize) +afspgin_update_dbd(vfspage_t * vm_info, int bsize) { - k_off_t off; - pgcnt_t count = bsize / NBPG; - k_off_t rem; - pgcnt_t m; - pgcnt_t pgindx; - daddr_t blkno; - int num_io = VM_GET_NUM_IO(vm_info); - int i; - - for (i = 0; i < num_io; i++) { - - pgindx = VM_GET_IO_STARTINDX(vm_info, i); - off = vnodindx(VM_REGION(vm_info), pgindx); - rem = off % bsize; - blkno = VM_GET_IO_STARTBLK(vm_info, i); - - VASSERT(bsize % NBPG == 0); - VASSERT(rem % NBPG == 0); - - pgindx -= (pgcnt_t)btop(rem); - blkno -= (daddr_t)btodb(rem); - - /* - * This region could start in mid-block. If so, pgindx - * could be less than 0, so we adjust pgindx and blkno back - * up so that pgindx is 0. - */ - - if (pgindx < 0) { - pgcnt_t prem; - prem = 0 - pgindx; - pgindx = 0; - count -= prem; - blkno += btodb(ptob(prem)); - } - - for (m = 0; m < count && pgindx < VM_REGION_SIZE(vm_info); - m++, pgindx++, blkno += btodb(NBPG)) { - /* - * Note: since this only changes one block, it - * assumes only one block was faulted in. Currently - * this is always true for remote files, and we only - * get here for remote files, so everything is ok. - */ - vm_mark_dbd(vm_info, pgindx, blkno); - } - } + k_off_t off; + pgcnt_t count = bsize / NBPG; + k_off_t rem; + pgcnt_t m; + pgcnt_t pgindx; + kern_daddr_t blkno; + int num_io = VM_GET_NUM_IO(vm_info); + int i; + + for (i = 0; i < num_io; i++) { + + pgindx = VM_GET_IO_STARTINDX(vm_info, i); + off = vnodindx(VM_REGION(vm_info), pgindx); + rem = off % bsize; + blkno = VM_GET_IO_STARTBLK(vm_info, i); + + VASSERT(bsize % NBPG == 0); + VASSERT(rem % NBPG == 0); + + pgindx -= (pgcnt_t) btop(rem); + blkno -= (kern_daddr_t) btodb(rem); + + /* + * This region could start in mid-block. If so, pgindx + * could be less than 0, so we adjust pgindx and blkno back + * up so that pgindx is 0. + */ + + if (pgindx < 0) { + pgcnt_t prem; + prem = 0 - pgindx; + pgindx = 0; + count -= prem; + blkno += btodb(ptob(prem)); + } + + for (m = 0; m < count && pgindx < VM_REGION_SIZE(vm_info); + m++, pgindx++, blkno += btodb(NBPG)) { + /* + * Note: since this only changes one block, it + * assumes only one block was faulted in. Currently + * this is always true for remote files, and we only + * get here for remote files, so everything is ok. + */ + vm_mark_dbd(vm_info, pgindx, blkno); + } + } } -int afs_pagein(vp, prp, wrt, space, vaddr, ret_startindex) - struct vnode *vp; - preg_t *prp; - int wrt; - space_t space; - caddr_t vaddr; - pgcnt_t *ret_startindex; +int +afs_pagein(vp, prp, wrt, space, vaddr, ret_startindex) + struct vnode *vp; + preg_t *prp; + int wrt; + space_t space; + caddr_t vaddr; + pgcnt_t *ret_startindex; { - pgcnt_t startindex; - pgcnt_t pgindx = *ret_startindex; - pgcnt_t maxpagein; - struct vnode *devvp; - pgcnt_t count; - daddr_t start_blk=0; - int bsize; - int error; - k_off_t isize; - int shared; /* writable memory mapped file */ - retval_t retval = 0; - pgcnt_t ok_dbd_limit = 0; /* last dbd that we can trust */ - pgcnt_t bpages; /* number of pages per block */ - pgcnt_t page_count; - vfspage_t* vm_info=NULL; - int done; + pgcnt_t startindex; + pgcnt_t pgindx = *ret_startindex; + pgcnt_t maxpagein; + struct vnode *devvp; + pgcnt_t count; + kern_daddr_t start_blk = 0; + int bsize; + int error; + k_off_t isize; + int shared; /* writable memory mapped file */ + retval_t retval = 0; + pgcnt_t ok_dbd_limit = 0; /* last dbd that we can trust */ + pgcnt_t bpages; /* number of pages per block */ + pgcnt_t page_count; + vfspage_t *vm_info = NULL; + int done; struct vattr va; - caddr_t nvaddr; - space_t nspace; - int change_to_fstore = 0; /* need to change dbds to DBD_FSTORE */ - int flush_start_blk = 0; - int flush_end_blk = 0; + caddr_t nvaddr; + space_t nspace; + int change_to_fstore = 0; /* need to change dbds to DBD_FSTORE */ + int flush_start_blk = 0; + int flush_end_blk = 0; int i, j; @@ -1043,13 +1059,14 @@ int afs_pagein(vp, prp, wrt, space, vaddr, ret_startindex) vmemp_lockx(); /* lock down VM empire */ /* Initialize the VM info structure */ - done = vm_pagein_init(&vm_info, prp, pgindx, space, vaddr, wrt, 0, - LGPG_ENABLE); + done = + vm_pagein_init(&vm_info, prp, pgindx, space, vaddr, wrt, 0, + LGPG_ENABLE); /* Check to see if we slept and the page was falted in. */ if (done) { - vm_release_structs(vm_info); - vmemp_returnx(1); + vm_release_structs(vm_info); + vmemp_returnx(1); } vp = VM_GET_PAGEIN_VNODE(vm_info); @@ -1065,22 +1082,22 @@ int afs_pagein(vp, prp, wrt, space, vaddr, ret_startindex) if (bsize <= 0 || (bsize & (DEV_BSIZE - 1))) osi_Panic("afs_pagein: bsize is zero or not a multiple of DEV_BSIZE"); - bpages = (pgcnt_t)btop(bsize); + bpages = (pgcnt_t) btop(bsize); VASSERT(bpages > 0); VM_SET_FS_MAX_PAGES(vm_info, bpages); /* this trace cannot be here because the afs_global lock might not be - held at this point. We hold the vm global lock throughout - this procedure ( and not the AFS global lock ) - afs_Trace4(afs_iclSetp, CM_TRACE_HPPAGEIN, ICL_TYPE_POINTER, (afs_int32) vp, - ICL_TYPE_LONG, DBD_TYPE(vm_info), ICL_TYPE_LONG, bpages, - ICL_TYPE_LONG, shared); - */ + * held at this point. We hold the vm global lock throughout + * this procedure ( and not the AFS global lock ) + * afs_Trace4(afs_iclSetp, CM_TRACE_HPPAGEIN, ICL_TYPE_POINTER, (afs_int32) vp, + * ICL_TYPE_LONG, DBD_TYPE(vm_info), ICL_TYPE_LONG, bpages, + * ICL_TYPE_LONG, shared); + */ /* Come here if we have to release the region lock before * locking pages. This can happen in memreserve() and * blkflush(). */ -retry: + retry: /* * For remote files like ours, we want to check to see if the file has shrunk. * If so, we should invalidate any pages past the end. In the name @@ -1088,47 +1105,46 @@ retry: * past the end of the file. */ { - if (VOP_GETATTR(vp, &va, kt_cred(u.u_kthreadp), VIFSYNC) != 0) { - VM_ZOMBIE_OBJECT(vm_info); - vm_release_memory(vm_info); - vm_release_structs(vm_info); - vmemp_returnx(0); - } - isize = va.va_size; - if (vnodindx(VM_REGION(vm_info), pgindx) >= isize) { - /* - * The file has shrunk and someone is trying to access a - * page past the end of the object. Shrink the object back - * to its currrent size, send a SIGBUS to the faulting - * process and return. - * - * We must release the region lock before calling mtrunc(), - * since mtrunc() locks all the regions that are using this - * file. - */ - vm_release_memory(vm_info); - vm_truncate_region(vm_info, isize); - vm_release_structs(vm_info); - vmemp_returnx(-SIGBUS); - } + if (VOP_GETATTR(vp, &va, kt_cred(u.u_kthreadp), VIFSYNC) != 0) { + VM_ZOMBIE_OBJECT(vm_info); + vm_release_memory(vm_info); + vm_release_structs(vm_info); + vmemp_returnx(0); + } + isize = va.va_size; + if (vnodindx(VM_REGION(vm_info), pgindx) >= isize) { + /* + * The file has shrunk and someone is trying to access a + * page past the end of the object. Shrink the object back + * to its currrent size, send a SIGBUS to the faulting + * process and return. + * + * We must release the region lock before calling mtrunc(), + * since mtrunc() locks all the regions that are using this + * file. + */ + vm_release_memory(vm_info); + vm_truncate_region(vm_info, isize); + vm_release_structs(vm_info); + vmemp_returnx(-SIGBUS); + } } maxpagein = vm_pick_maxpagein(vm_info); if (vm_wait_for_memory(vm_info, maxpagein, 1)) { - /* Check to see if we should continue faulting. */ - if (vm_page_now_valid(vm_info, &page_count)) { - vm_release_memory(vm_info); - vm_release_structs(vm_info); - vmemp_returnx(page_count); - } + /* Check to see if we should continue faulting. */ + if (vm_page_now_valid(vm_info, &page_count)) { + vm_release_memory(vm_info); + vm_release_structs(vm_info); + vmemp_returnx(page_count); + } } if (count = vm_no_io_required(vm_info)) { - /* Release any excess memory. */ - vm_release_memory(vm_info); - vm_release_structs(vm_info); - vmemp_returnx(count); + /* Release any excess memory. */ + vm_release_memory(vm_info); + vm_release_structs(vm_info); + vmemp_returnx(count); } - #ifdef OSDEBUG /* * We should never have DBD_HOLE pages in a non-MMF region. @@ -1136,51 +1152,51 @@ retry: if (!shared) VASSERT(dbd->dbd_type != DBD_HOLE); #endif - VASSERT( DBD_TYPE(vm_info) != DBD_NONE); + VASSERT(DBD_TYPE(vm_info) != DBD_NONE); startindex = *ret_startindex; /* * If the page we want is in memory already, take it */ - if (VM_MEMORY_RESERVED(vm_info) < maxpagein) - { - /* pick up the rest of memory now. */ - if (vm_wait_for_memory(vm_info, maxpagein, 0)) { - if (vm_page_now_valid(vm_info, &page_count)) { - vm_release_memory(vm_info); - vm_release_structs(vm_info); - vmemp_returnx(page_count); - } - goto retry; - } + if (VM_MEMORY_RESERVED(vm_info) < maxpagein) { + /* pick up the rest of memory now. */ + if (vm_wait_for_memory(vm_info, maxpagein, 0)) { + if (vm_page_now_valid(vm_info, &page_count)) { + vm_release_memory(vm_info); + vm_release_structs(vm_info); + vmemp_returnx(page_count); + } + goto retry; + } } - if (!(count = afspgin_setup_io_ranges(vm_info, bpages, isize, - startindex))) { - goto retry; + if (! + (count = + afspgin_setup_io_ranges(vm_info, bpages, isize, startindex))) { + goto retry; } startindex = VM_GET_STARTINDX(vm_info); VASSERT(maxpagein >= count); - + /* * Release the memory we won't need. */ if (count < maxpagein) { - vm_release_excess_memory(vm_info, - (VM_MEMORY_RESERVED(vm_info) - count)); - } + vm_release_excess_memory(vm_info, + (VM_MEMORY_RESERVED(vm_info) - count)); + } retval = afspgin_blkflsh(vm_info, devvp, &count); - + if (retval == VM_RETRY) { - goto retry; + goto retry; } if (retval == VM_PAGE_PRESENT) - return (count); + return (count); #if 0 /* @@ -1192,9 +1208,9 @@ retry: /* It's a real fault, not a reclaim */ { - krusage_cntr_t *temp; - temp = kt_cntrp(u.u_kthreadp); - temp->krc_majflt++; + krusage_cntr_t *temp; + temp = kt_cntrp(u.u_kthreadp); + temp->krc_majflt++; } #endif @@ -1213,26 +1229,26 @@ retry: * Count may have been adjusted, check to make sure it's non-zero. */ if (count == 0) { - if (vm_retry(vm_info)) { - goto retry; - } - - /* - * Release resources and retry the fault. Release any excess - * memory. - */ - - vm_release_memory(vm_info); - vm_release_structs(vm_info); - vmemp_returnx(0); + if (vm_retry(vm_info)) { + goto retry; + } + + /* + * Release resources and retry the fault. Release any excess + * memory. + */ + + vm_release_memory(vm_info); + vm_release_structs(vm_info); + vmemp_returnx(0); } error = afspgin_io(vm_info, devvp, bpages, maxpagein, count); if ((VM_IS_ZOMBIE(vm_info)) || (error)) { - retval = -SIGBUS; - VM_ZOMBIE_OBJECT(vm_info); - goto backout; + retval = -SIGBUS; + VM_ZOMBIE_OBJECT(vm_info); + goto backout; } /* * For a writable memory mapped file that is remote we must @@ -1241,63 +1257,63 @@ retry: * no easy way to do this, so this gets a little ugly. */ if (shared && wrt) { - /* - * See if The user wants to write to this page. Write some - * minimal amount of data back to the remote file to - * force allocation of file space. We only need to - * write a small amount, since holes are always at - * least one filesystem block in size. - */ - error = vm_alloc_hole(vm_info); - - /* - * If some sort of I/O error occurred we generate a - * SIGBUS for the process that caused the write, - * undo our page locks, etc and return. - */ - if ((VM_IS_ZOMBIE(vm_info)) || (error)) { - VM_ZOMBIE_OBJECT(vm_info); - retval = -SIGBUS; - goto backout; - } - - /* - * Change these dbds to DBD_FSTORE. We cannot do it here, - * since the region must be locked, and it is not locked - * at the moment. We cannot lock the region yet, as we - * first have to release the page locks. - */ - change_to_fstore = 1; + /* + * See if The user wants to write to this page. Write some + * minimal amount of data back to the remote file to + * force allocation of file space. We only need to + * write a small amount, since holes are always at + * least one filesystem block in size. + */ + error = vm_alloc_hole(vm_info); + + /* + * If some sort of I/O error occurred we generate a + * SIGBUS for the process that caused the write, + * undo our page locks, etc and return. + */ + if ((VM_IS_ZOMBIE(vm_info)) || (error)) { + VM_ZOMBIE_OBJECT(vm_info); + retval = -SIGBUS; + goto backout; + } + + /* + * Change these dbds to DBD_FSTORE. We cannot do it here, + * since the region must be locked, and it is not locked + * at the moment. We cannot lock the region yet, as we + * first have to release the page locks. + */ + change_to_fstore = 1; } vm_finish_io(vm_info, count); - + /* * Acquire the lock before we play around with changing the vfd's. */ vm_lock(vm_info); if (change_to_fstore) - afspgin_update_dbd(vm_info, bsize); - + afspgin_update_dbd(vm_info, bsize); + #if defined(AFS_HPUX110_ENV) - getppdp()->cnt.v_exfod += count; + getppdp()->cnt.v_exfod += count; #else mpproc_info[getprocindex()].cnt.v_exfod += count; #endif - vmemp_unlockx(); /* free up VM empire */ + vmemp_unlockx(); /* free up VM empire */ *ret_startindex = startindex; - + /* * In case we have any excess memory... */ if (VM_MEMORY_RESERVED(vm_info)) - vm_release_memory(vm_info); + vm_release_memory(vm_info); vm_release_structs(vm_info); - + return count; -backout: + backout: vm_finish_io_failed(vm_info, count); @@ -1309,20 +1325,20 @@ backout: * In case we have any excess memory... */ if (VM_MEMORY_RESERVED(vm_info)) - vm_release_memory(vm_info); + vm_release_memory(vm_info); vm_release_structs(vm_info); - vmemp_unlockx(); /* free up VM empire */ + vmemp_unlockx(); /* free up VM empire */ return retval; } int -afs_pageout(vp,prp, start, end, flags) - struct vnode *vp; /* not used */ - preg_t *prp; - pgcnt_t start; - pgcnt_t end; - int flags; +afs_pageout(vp, prp, start, end, flags) + struct vnode *vp; /* not used */ + preg_t *prp; + pgcnt_t start; + pgcnt_t end; + int flags; { struct vnode *filevp; struct vnode *devvp; @@ -1330,7 +1346,7 @@ afs_pageout(vp,prp, start, end, flags) int steal; int vhand; int hard; - int *piocnt; /* wakeup counter used if PAGEOUT_WAIT */ + int *piocnt; /* wakeup counter used if PAGEOUT_WAIT */ struct ucred *old_cred; vfspage_t vm_info; fsdata_t args; @@ -1340,10 +1356,10 @@ afs_pageout(vp,prp, start, end, flags) struct inode *ip; AFS_STATCNT(afs_pageout); - + steal = (flags & PAGEOUT_FREE); vhand = (flags & PAGEOUT_VHAND); - hard = (flags & PAGEOUT_HARD); + hard = (flags & PAGEOUT_HARD); vmemp_lockx(); @@ -1357,7 +1373,7 @@ afs_pageout(vp,prp, start, end, flags) */ if (vm_no_pageout(&vm_info)) { vmemp_unlockx(); - return(0); + return (0); } /* @@ -1365,10 +1381,10 @@ afs_pageout(vp,prp, start, end, flags) */ vm_setup_wait_for_io(&vm_info); - filevp = VM_GET_PAGEOUT_VNODE(&vm_info); /* always page out to back store */ + filevp = VM_GET_PAGEOUT_VNODE(&vm_info); /* always page out to back store */ VASSERT(filevp != NULL); - memset((caddr_t)&args, 0, sizeof(fsdata_t)); + memset((caddr_t) & args, 0, sizeof(fsdata_t)); args.remote_down = 0; /* assume remote file servers are up */ args.remote = 1; /* we are remote */ args.bsize = 0; /* filled up later by afs_vm_checkpage() */ @@ -1377,8 +1393,7 @@ afs_pageout(vp,prp, start, end, flags) ip = VTOI(filevp); devvp = ip->i_devvp; file_is_remote = 0; - } - else { + } else { file_is_remote = 1; devvp = filevp; @@ -1389,8 +1404,8 @@ afs_pageout(vp,prp, start, end, flags) * of dirty NFS pages until a future time. */ #ifdef notdef - if (vhand && filevp->v_fstype == VNFS && - vtomi(filevp)->mi_down && vtomi(filevp)->mi_hard) { + if (vhand && filevp->v_fstype == VNFS && vtomi(filevp)->mi_down + && vtomi(filevp)->mi_hard) { extern afs_int32 vhand_nfs_retry; /* * If there is still time left on our timer, we will @@ -1407,14 +1422,14 @@ afs_pageout(vp,prp, start, end, flags) * it must get the file size and other attributes if it comes across * a dirty page. */ - vm_info.fs_data = (caddr_t)&args; + vm_info.fs_data = (caddr_t) & args; /* this trace cannot be here because the afs_global lock might not be - held at this point. We hold the vm global lock throughout - this procedure ( and not the AFS global lock ) - afs_Trace4(afs_iclSetp, CM_TRACE_HPPAGEOUT, ICL_TYPE_POINTER, (afs_int32) filevp, - ICL_TYPE_LONG, start, ICL_TYPE_LONG, end, ICL_TYPE_LONG, flags); - */ + * held at this point. We hold the vm global lock throughout + * this procedure ( and not the AFS global lock ) + * afs_Trace4(afs_iclSetp, CM_TRACE_HPPAGEOUT, ICL_TYPE_POINTER, (afs_int32) filevp, + * ICL_TYPE_LONG, start, ICL_TYPE_LONG, end, ICL_TYPE_LONG, flags); + */ i = start; @@ -1429,37 +1444,37 @@ afs_pageout(vp,prp, start, end, flags) space_t nspace; caddr_t nvaddr; - /* - * Ask the VM system to find the next run of pages. - */ - vm_find_next_range(&vm_info, i, end); - - /* - * It's possible that the remote file shrunk in size. Check the flags - * to see if the request was beyond the end of the file. If it was, - * truncate the region to the file size and continue. We could be on a - * run so after trunction continue, there may be some I/O to write - * out. - */ - if (VM_FS_FLAGS(&vm_info) & PAGEOUT_TRUNCATE) { - pgcnt_t pglen = (pgcnt_t)btorp(args.isize); - - /* - * This page is past the end of the file. Unlock this page - * (region_trunc will throw it away) and then call - * region_trunc() to invalidate all pages past the new end of - * the file. - */ - region_trunc(VM_REGION(&vm_info), pglen, pglen + 1); - - /* - * remove the truncation flag. - */ - VM_UNSETFS_FLAGS(&vm_info, PAGEOUT_TRUNCATE); - } - - if (VM_NO_PAGEOUT_RUN(&vm_info)) - break; + /* + * Ask the VM system to find the next run of pages. + */ + vm_find_next_range(&vm_info, i, end); + + /* + * It's possible that the remote file shrunk in size. Check the flags + * to see if the request was beyond the end of the file. If it was, + * truncate the region to the file size and continue. We could be on a + * run so after trunction continue, there may be some I/O to write + * out. + */ + if (VM_FS_FLAGS(&vm_info) & PAGEOUT_TRUNCATE) { + pgcnt_t pglen = (pgcnt_t) btorp(args.isize); + + /* + * This page is past the end of the file. Unlock this page + * (region_trunc will throw it away) and then call + * region_trunc() to invalidate all pages past the new end of + * the file. + */ + region_trunc(VM_REGION(&vm_info), pglen, pglen + 1); + + /* + * remove the truncation flag. + */ + VM_UNSETFS_FLAGS(&vm_info, PAGEOUT_TRUNCATE); + } + + if (VM_NO_PAGEOUT_RUN(&vm_info)) + break; /* * We have a run of dirty pages [args.start...args.end]. @@ -1468,31 +1483,32 @@ afs_pageout(vp,prp, start, end, flags) VASSERT((filevp->v_vfsp->vfs_flag & VFS_RDONLY) == 0); VASSERT(VM_GET_NUM_IO(&vm_info) == 1); - /* - * We will be doing an I/O on the region, let the VM system know. - */ - (void)vm_up_physio_count(&vm_info); + /* + * We will be doing an I/O on the region, let the VM system know. + */ + (void)vm_up_physio_count(&vm_info); /* * Okay, get set to perform the I/O. */ inode_changed = 1; - npages = (VM_END_PAGEOUT_INDX(&vm_info) + 1) - - VM_START_PAGEOUT_INDX(&vm_info); + npages = + (VM_END_PAGEOUT_INDX(&vm_info) + 1) - + VM_START_PAGEOUT_INDX(&vm_info); /* * Allocate and initialize an I/O buffer. */ bp = bswalloc(); - vm_init_bp(&vm_info, bp); /* Let the VM system initialize */ + vm_init_bp(&vm_info, bp); /* Let the VM system initialize */ - /* Identify this buffer for KI */ - bp->b_bptype = B_vfs_pageout|B_pagebf; + /* Identify this buffer for KI */ + bp->b_bptype = B_vfs_pageout | B_pagebf; if (steal) - bp->b_flags = B_CALL|B_BUSY|B_PAGEOUT; /* steal pages */ + bp->b_flags = B_CALL | B_BUSY | B_PAGEOUT; /* steal pages */ else - bp->b_flags = B_CALL|B_BUSY; /* keep pages */ + bp->b_flags = B_CALL | B_BUSY; /* keep pages */ /* * If we are vhand paging over NFS, we will wait for the I/O @@ -1535,32 +1551,31 @@ afs_pageout(vp,prp, start, end, flags) nbytes = roundup(args.isize - start, DEV_BSIZE); } - /* - * Now get ready to perform the I/O - */ - if (!vm_protect_pageout(&vm_info, npages)) - { - VASSERT(vhand); - vm_undo_invalidation(&vm_info, vm_info.start, vm_info.end); - vm_finish_io_failed(&vm_info, npages); - bswfree(bp); - break; - } - /* - * If this is an NFS write by vhand(), we will not be calling - * pageiodone(). asyncpageio() increments parolemem for us - * if bp->b_iodone is pageiodone, so we must do it manually - * if pageiodone() will not be called automatically. - */ - if (!(bp->b_flags & B_CALL) && steal) { - register ulong_t context; - - SPINLOCK_USAV(pfdat_lock, context); - parolemem += btorp(nbytes); - SPINUNLOCK_USAV(pfdat_lock, context); - } - blkflush(devvp, VM_START_PAGEOUT_BLK(&vm_info), (long)nbytes, - (BX_NOBUFWAIT|BX_PURGE), VM_REGION(&vm_info)); + /* + * Now get ready to perform the I/O + */ + if (!vm_protect_pageout(&vm_info, npages)) { + VASSERT(vhand); + vm_undo_invalidation(&vm_info, vm_info.start, vm_info.end); + vm_finish_io_failed(&vm_info, npages); + bswfree(bp); + break; + } + /* + * If this is an NFS write by vhand(), we will not be calling + * pageiodone(). asyncpageio() increments parolemem for us + * if bp->b_iodone is pageiodone, so we must do it manually + * if pageiodone() will not be called automatically. + */ + if (!(bp->b_flags & B_CALL) && steal) { + register ulong_t context; + + SPINLOCK_USAV(pfdat_lock, context); + parolemem += btorp(nbytes); + SPINUNLOCK_USAV(pfdat_lock, context); + } + blkflush(devvp, VM_START_PAGEOUT_BLK(&vm_info), (long)nbytes, + (BX_NOBUFWAIT | BX_PURGE), VM_REGION(&vm_info)); /* * If vhand is the one paging things out, and this is an NFS @@ -1573,64 +1588,76 @@ afs_pageout(vp,prp, start, end, flags) * value in the vas (this should be fixed in 10.0). */ old_cred = kt_cred(u.u_kthreadp); - if (vhand) { - set_kt_cred(u.u_kthreadp, filevp->v_vas->va_cred); - - /* - * If root was the one who opened the mmf for write, - * va_cred will be NULL. So reset kt_cred(u.u_kthreadp) to what it - * was. We will page out as root, but that is the - * correct thing to do in this case anyway. - */ - if (kt_cred(u.u_kthreadp) == NULL) - set_kt_cred(u.u_kthreadp, old_cred); - } + if (vhand) { +#if defined(AFS_HPUX1123_ENV) + /* + * DEE - 1123 does not have the vas.h, and it looks + * we should never be called with a NFS type file anyway. + * so where did this come from? Was it copied from NFS? + * I assume it was, so we will add an assert for now + * and see if the code runs at all. + */ + VASSERT(filevp->v_fstype != VNFS); +#else + set_kt_cred(u.u_kthreadp, filevp->v_vas->va_cred); + + /* + * If root was the one who opened the mmf for write, + * va_cred will be NULL. So reset kt_cred(u.u_kthreadp) to what it + * was. We will page out as root, but that is the + * correct thing to do in this case anyway. + */ + if (kt_cred(u.u_kthreadp) == NULL) + set_kt_cred(u.u_kthreadp, old_cred); +#endif + } /* * Really do the I/O. */ - error = asyncpageio(bp, VM_START_PAGEOUT_BLK(&vm_info), - VM_MAPPED_SPACE(&vm_info), VM_MAPPED_ADDR(&vm_info), + error = + asyncpageio(bp, VM_START_PAGEOUT_BLK(&vm_info), + VM_MAPPED_SPACE(&vm_info), VM_MAPPED_ADDR(&vm_info), (int)nbytes, B_WRITE, devvp); VASSERT(error == 0); #ifdef notdef - /* - * If we are vhand paging over NFS we want to wait for the - * I/O to complete and take the appropriate actions if an - * error is encountered. - */ - if (vhand) { - if (waitforpageio(bp) && nfs_mi_harddown(filevp)) { - /* - * The server is down, ignore this failure, and - * try again later. (rfscall() has set our retry - * timer). - */ - fsdata.remote_down = 1; - pageiocleanup(bp, 0); - - /* - * vm_vfdcheck() has cleared the valid bit on the - * vfds for these pages. We must go back and set the - * valid bit, as the pages are really not gone. - * - * NOTE: we can do this because we still hold (and have - * not released) the region lock. - */ - if (steal) - vm_undo_invalidation(&vm_info, vm_info.start, vm_info.end); - } - else { - /* - * The I/O succeeded, or we had an error that we do - * not want to defer until later. Call pageidone() - * to handle things. - */ - pageiodone(bp); - } - } + /* + * If we are vhand paging over NFS we want to wait for the + * I/O to complete and take the appropriate actions if an + * error is encountered. + */ + if (vhand) { + if (waitforpageio(bp) && nfs_mi_harddown(filevp)) { + /* + * The server is down, ignore this failure, and + * try again later. (rfscall() has set our retry + * timer). + */ + fsdata.remote_down = 1; + pageiocleanup(bp, 0); + + /* + * vm_vfdcheck() has cleared the valid bit on the + * vfds for these pages. We must go back and set the + * valid bit, as the pages are really not gone. + * + * NOTE: we can do this because we still hold (and have + * not released) the region lock. + */ + if (steal) + vm_undo_invalidation(&vm_info, vm_info.start, + vm_info.end); + } else { + /* + * The I/O succeeded, or we had an error that we do + * not want to defer until later. Call pageidone() + * to handle things. + */ + pageiodone(bp); + } + } #endif /* @@ -1658,8 +1685,7 @@ afs_pageout(vp,prp, start, end, flags) mpproc_info[getprocindex()].cnt.v_pswpout += npages; #endif /* sar_bswapout += ptod(npages);*/ - } - else if (vhand) { + } else if (vhand) { #if defined(AFS_HPUX110_ENV) getppdp()->cnt.v_pgout++; getppdp()->cnt.v_pgpgout += npages; @@ -1674,13 +1700,13 @@ afs_pageout(vp,prp, start, end, flags) * If time and patience have delivered enough * pages, then quit now while we are ahead. */ - if (VM_STOP_PAGING(&vm_info)) - break; + if (VM_STOP_PAGING(&vm_info)) + break; i = VM_END_PAGEOUT_INDX(&vm_info) - VM_BASE_OFFSET(&vm_info) + 1; } - vm_finish_pageout(&vm_info); /* update vhand's stealscan */ + vm_finish_pageout(&vm_info); /* update vhand's stealscan */ vmemp_unlockx(); @@ -1692,7 +1718,7 @@ afs_pageout(vp,prp, start, end, flags) vm_wait_for_io(&vm_info); if (inode_changed && !file_is_remote) { - imark(ip, IUPD|ICHG); + imark(ip, IUPD | ICHG); iupdat(ip, 0, 0); } return 0; @@ -1701,42 +1727,42 @@ afs_pageout(vp,prp, start, end, flags) int afs_mapdbd(filevp, offset, bn, flags, hole, startidx, endidx) struct vnode *filevp; - off_t offset; - daddr_t *bn; /* Block number. */ - int flags; /* B_READ or B_WRITE */ - int *hole; /* To be used for read-ahead. */ - pgcnt_t *startidx; /* To be used for read-ahead. */ - pgcnt_t *endidx; /* To be used for read-ahead. */ + off_t offset; + kern_daddr_t *bn; /* Block number. */ + int flags; /* B_READ or B_WRITE */ + int *hole; /* To be used for read-ahead. */ + pgcnt_t *startidx; /* To be used for read-ahead. */ + pgcnt_t *endidx; /* To be used for read-ahead. */ { - daddr_t lbn, local_bn; - int on; - int err; - long bsize = vtoblksz(filevp) & ~(DEV_BSIZE - 1); - - if (startidx) - *startidx = (pgcnt_t)(offset/NBPG); - if (endidx) - *endidx = (pgcnt_t)(offset/NBPG); - if (hole) - *hole = 0; /* Can't have holes. */ - if (bsize <= 0 ) - osi_Panic("afs_mapdbd: zero size"); - - lbn = (daddr_t)(offset / bsize); - on = offset % bsize; - - err = VOP_BMAP(filevp, lbn, NULL, &local_bn, flags); - VASSERT(err == 0); - - /* - * We can never get a bn less than zero on remote files. - */ - VASSERT(local_bn >= 0); - - local_bn = local_bn + btodb(on); - *bn = local_bn; - - return(0); + kern_daddr_t lbn, local_bn; + int on; + int err; + long bsize = vtoblksz(filevp) & ~(DEV_BSIZE - 1); + + if (startidx) + *startidx = (pgcnt_t) (offset / NBPG); + if (endidx) + *endidx = (pgcnt_t) (offset / NBPG); + if (hole) + *hole = 0; /* Can't have holes. */ + if (bsize <= 0) + osi_Panic("afs_mapdbd: zero size"); + + lbn = (kern_daddr_t) (offset / bsize); + on = offset % bsize; + + err = VOP_BMAP(filevp, lbn, NULL, &local_bn, flags); + VASSERT(err == 0); + + /* + * We can never get a bn less than zero on remote files. + */ + VASSERT(local_bn >= 0); + + local_bn = local_bn + btodb(on); + *bn = local_bn; + + return (0); } /* @@ -1747,14 +1773,14 @@ afs_mapdbd(filevp, offset, bn, flags, hole, startidx, endidx) int afs_vm_fscontiguous(vp, args, cur_data) struct vnode *vp; - vfspage_t *args; - u_int cur_data; + vfspage_t *args; + u_int cur_data; { - if (cur_data == (VM_END_PAGEOUT_BLK(args) + btodb(NBPG))) { - return(1); - } else { - return(0); - } + if (cur_data == (VM_END_PAGEOUT_BLK(args) + btodb(NBPG))) { + return (1); + } else { + return (0); + } } /* @@ -1765,15 +1791,23 @@ afs_vm_fscontiguous(vp, args, cur_data) */ afs_vm_stopio(vp, args) struct vnode *vp; - vfspage_t *args; + vfspage_t *args; { - fsdata_t *fsdata = (fsdata_t *)args->fs_data; + fsdata_t *fsdata = (fsdata_t *) args->fs_data; + +#if defined(AFS_HPUX1123_ENV) + uint64_t tmpdb; + tmpdb = VM_END_PAGEOUT_BLK(args); - if ((dbtob(VM_END_PAGEOUT_BLK(args)) + NBPG) % (fsdata->bsize) == 0) { - return(1); - } else { - return(0); - } + if ((dbtob(tmpdb) + NBPG) % (fsdata->bsize) == 0) +#else + if ((dbtob(VM_END_PAGEOUT_BLK(args)) + NBPG) % (fsdata->bsize) == 0) +#endif /* AFS_HPUX1123_ENV */ + { + return (1); + } else { + return (0); + } } /* @@ -1783,18 +1817,18 @@ afs_vm_stopio(vp, args) */ afs_vm_checkpage(vp, args, pgindx, cur_data) struct vnode *vp; - vfspage_t *args; - pgcnt_t pgindx; - int cur_data; + vfspage_t *args; + pgcnt_t pgindx; + int cur_data; { - fsdata_t *fsdata = (fsdata_t *)args->fs_data; - - if (fsdata->remote_down) { /* never happens for AFS */ - /* - * The remote system is down. - */ - VASSERT(args->run == 0); - return 1; + fsdata_t *fsdata = (fsdata_t *) args->fs_data; + + if (fsdata->remote_down) { /* never happens for AFS */ + /* + * The remote system is down. + */ + VASSERT(args->run == 0); + return 1; } /* * A dirty page. If we have not yet determined the file size and @@ -1803,137 +1837,136 @@ afs_vm_checkpage(vp, args, pgindx, cur_data) */ if (fsdata->bsize == 0) { k_off_t isize; - long bsize; - struct vattr va; - struct vnode *filevp; - /* - * Get the various attributes about the file. Store them - * in args for the next time around. - */ - filevp = args->vp; - - bsize = vtoblksz(filevp); - args->maxpgs = (pgcnt_t)btop(bsize); + long bsize; + struct vattr va; + struct vnode *filevp; + /* + * Get the various attributes about the file. Store them + * in args for the next time around. + */ + filevp = args->vp; + + bsize = vtoblksz(filevp); + args->maxpgs = (pgcnt_t) btop(bsize); if (VOP_GETATTR(filevp, &va, kt_cred(u.u_kthreadp), VIFSYNC) != 0) { - /* - * The VOP_GETATTR() failed. - * we are vhand, and this is a hard mount, we will - * skip dirty pages for a while and try again later. - */ - if (args->vm_flags & PAGEOUT_VHAND) - { - VASSERT(args->run == 0); - return 1; - } - /* - * This is a "soft" mount, or some other error was - * returned from the server. Mark this region - * as a zombie, and free this dirty page. - */ - VM_ZOMBIE_OBJECT(args); - - /* - * The caller will see r_zomb and remove the page - * appropriately. - */ - return(1); - } - isize = va.va_size; - fsdata->isize = isize; - fsdata->bsize = bsize; - fsdata->remote = 1; + /* + * The VOP_GETATTR() failed. + * we are vhand, and this is a hard mount, we will + * skip dirty pages for a while and try again later. + */ + if (args->vm_flags & PAGEOUT_VHAND) { + VASSERT(args->run == 0); + return 1; + } + /* + * This is a "soft" mount, or some other error was + * returned from the server. Mark this region + * as a zombie, and free this dirty page. + */ + VM_ZOMBIE_OBJECT(args); + + /* + * The caller will see r_zomb and remove the page + * appropriately. + */ + return (1); + } + isize = va.va_size; + fsdata->isize = isize; + fsdata->bsize = bsize; + fsdata->remote = 1; } /* - * See if the file has shrunk (this could have happened - * asynchronously because of NFS or DUX). If so, invalidate - * all of the pages past the end of the file. This is only - * needed for remote files, as local files are truncated - * synchronously. - */ + * See if the file has shrunk (this could have happened + * asynchronously because of NFS or DUX). If so, invalidate + * all of the pages past the end of the file. This is only + * needed for remote files, as local files are truncated + * synchronously. + */ if (vnodindx(VM_REGION(args), pgindx) > fsdata->isize) { - /* - * This page is past the end of the file. Unlock this page - * (region_trunc will throw it away) and then call region_trunc() - * to invalidate all pages past the new end of the file. - */ - VM_SETFS_FLAGS(args, PAGEOUT_TRUNCATE); - return(1); + /* + * This page is past the end of the file. Unlock this page + * (region_trunc will throw it away) and then call region_trunc() + * to invalidate all pages past the new end of the file. + */ + VM_SETFS_FLAGS(args, PAGEOUT_TRUNCATE); + return (1); } #ifdef notdef - if ((args->vm_flags & PAGEOUT_VHAND) && - (!(args->vm_flags & PAGEOUT_RESERVED)) && - (!(VM_IS_ZOMBIE(args)))) { - VASSERT(args->run == 0); - if (vm_reserve_malloc_memory(NFS_PAGEOUT_MEM)) { - /* - * Got enough memory to pageout. Mark the fact that we did - * a sysprocmemreserve(), so that we can sysprocmemunreserve() it - * later (in remote_pageout()). - */ - args->vm_flags |= PAGEOUT_RESERVED; - } else { - /* - * We do not have enough memory to do this pageout. By - * definition, we do not yet have a run, so we just unlock - * this page and tell foreach_valid() to continue scanning. - * If we come across another dirty page, we will try to - * reserve memory again. That is okay, in fact some memory - * may have freed up (as earlier pageouts complete under - * interrupt). - */ - return 1; - } + if ((args->vm_flags & PAGEOUT_VHAND) + && (!(args->vm_flags & PAGEOUT_RESERVED)) + && (!(VM_IS_ZOMBIE(args)))) { + VASSERT(args->run == 0); + if (vm_reserve_malloc_memory(NFS_PAGEOUT_MEM)) { + /* + * Got enough memory to pageout. Mark the fact that we did + * a sysprocmemreserve(), so that we can sysprocmemunreserve() it + * later (in remote_pageout()). + */ + args->vm_flags |= PAGEOUT_RESERVED; + } else { + /* + * We do not have enough memory to do this pageout. By + * definition, we do not yet have a run, so we just unlock + * this page and tell foreach_valid() to continue scanning. + * If we come across another dirty page, we will try to + * reserve memory again. That is okay, in fact some memory + * may have freed up (as earlier pageouts complete under + * interrupt). + */ + return 1; + } } #endif - return(0); + return (0); } afs_swapfs_len(bp) struct buf *bp; { - long fs_bsize; - long max_size; - long bnrem; - - fs_bsize = vtoblksz(bp->b_vp); - /* - * Check to see if we are starting mid block. If so, then - * we must return the remainder of the block or less depending - * on the length. - */ - bnrem = bp->b_offset % fs_bsize; - if (bnrem) { - max_size = fs_bsize - bnrem; - } else { - max_size = fs_bsize; - } - - if (bp->b_bcount > max_size) { - return(max_size); - } else { - return(bp->b_bcount); - } + long fs_bsize; + long max_size; + long bnrem; + + fs_bsize = vtoblksz(bp->b_vp); + /* + * Check to see if we are starting mid block. If so, then + * we must return the remainder of the block or less depending + * on the length. + */ + bnrem = bp->b_offset % fs_bsize; + if (bnrem) { + max_size = fs_bsize - bnrem; + } else { + max_size = fs_bsize; + } + + if (bp->b_bcount > max_size) { + return (max_size); + } else { + return (bp->b_bcount); + } } afs_mmap(vp, off, size_bytes, access) struct vnode *vp; u_int off; #if defined(AFS_HPUX1111_ENV) - u_long size_bytes; + u_long size_bytes; #else u_int size_bytes; #endif int access; { - long bsize = vtoblksz(vp); + long bsize = vtoblksz(vp); - if (bsize % NBPG != 0) { - return(EINVAL); - } + if (bsize % NBPG != 0) { + return (EINVAL); + } - return(0); + return (0); } afs_cachelimit(vp, len, location) @@ -1941,31 +1974,31 @@ afs_cachelimit(vp, len, location) k_off_t len; int *location; { - /* - * Disk addresses are logical, not physical, so fragments are - * transparent. - */ - *location = btorp(len) + 1; + /* + * Disk addresses are logical, not physical, so fragments are + * transparent. + */ + *location = btorp(len) + 1; } afs_release(vp) struct vnode *vp; { - return(0); + return (0); } int -afs_unmap(vp,off, size_bytes,access) +afs_unmap(vp, off, size_bytes, access) struct vnode *vp; u_int off; #if defined(AFS_HPUX1111_ENV) - u_long size_bytes; + u_long size_bytes; #else u_int size_bytes; #endif int access; { - return 0; + return 0; } int @@ -1977,51 +2010,52 @@ afs_read_ahead(vp, prp, wrt, space, vaddr, rhead_cnt) caddr_t vaddr; pgcnt_t *rhead_cnt; { - printf("afs_read_ahead returning 0 \n"); - return 0; + printf("afs_read_ahead returning 0 \n"); + return 0; } int afs_prealloc(vp, size, ignore_minfree, reserved) - struct vnode *vp; - /* DEE on 11.22 following is off_t */ - size_t size; - int ignore_minfree; - int reserved; + struct vnode *vp; + /* DEE on 11.22 following is off_t */ + size_t size; + int ignore_minfree; + int reserved; { - printf("afs_prealloc returning ENOSPC\n"); - return ENOSPC; + printf("afs_prealloc returning ENOSPC\n"); + return ENOSPC; } int afs_ioctl(vp, com, data, flag, cred) - struct vnode *vp; - int com; - caddr_t data; - int flag; - struct ucred *cred; + struct vnode *vp; + int com; + caddr_t data; + int flag; + struct ucred *cred; { - int error; - struct afs_ioctl afsioctl, *ai; + int error; + struct afs_ioctl afsioctl, *ai; - AFS_STATCNT(afs_ioctl); + AFS_STATCNT(afs_ioctl); - /* The call must be a VICEIOCTL call */ - if (((com >> 8) & 0xff) == 'V') { -#ifdef notdef - /* AFS_COPYIN returns error 14. Copy data in instead */ - AFS_COPYIN(data, (caddr_t) &afsioctl, sizeof(afsioctl), error); - if (error) return(error); + /* The call must be a VICEIOCTL call */ + if (((com >> 8) & 0xff) == 'V') { +#ifdef notdef + /* AFS_COPYIN returns error 14. Copy data in instead */ + AFS_COPYIN(data, (caddr_t) & afsioctl, sizeof(afsioctl), error); + if (error) + return (error); #endif - ai = (struct afs_ioctl *) data; - afsioctl.in = ai->in; - afsioctl.out = ai->out; - afsioctl.in_size = ai->in_size; - afsioctl.out_size = ai->out_size; - error = HandleIoctl(VTOAFS(vp), com, &afsioctl); - return(error); - } - return(ENOTTY); + ai = (struct afs_ioctl *)data; + afsioctl.in = ai->in; + afsioctl.out = ai->out; + afsioctl.in_size = ai->in_size; + afsioctl.out_size = ai->out_size; + error = HandleIoctl(VTOAFS(vp), com, &afsioctl); + return (error); + } + return (ENOTTY); } #if defined(AFS_HPUX1111_ENV) @@ -2044,60 +2078,60 @@ afs_readdir(vp, uiop, cred) struct uio *uiop; struct ucred *cred; { - struct uio auio; - struct iovec aiov; - caddr_t ibuf, obuf, ibufend, obufend; - struct __dirent32 *idp; - struct dirent *odp; - int count, outcount; - dir_off_t offset; - uint64_t tmp_offset; - - count = uiop->uio_resid; - /* Allocate temporary space for format conversion */ - ibuf = kmem_alloc(2*count); /* overkill - fix later */ - obuf = kmem_alloc(count + sizeof (struct dirent)); - aiov.iov_base = ibuf; - aiov.iov_len = count; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - offset = auio.uio_offset = uiop->uio_offset; - auio.uio_seg = UIOSEG_KERNEL; - auio.uio_resid = count; - auio.uio_fpflags = 0; - - u.u_error = mp_afs_readdir2(vp, &auio, cred); - if (u.u_error) - goto out; - - /* Convert entries from __dirent32 to dirent format */ - - for (idp = (struct __dirent32 *) ibuf, odp = (struct dirent *) obuf, - ibufend = ibuf + (count - auio.uio_resid), - obufend = obuf + count; - (caddr_t)idp < ibufend; - idp = (struct __dirent32 *) ((caddr_t) idp + idp->__d_reclen), - odp = (struct dirent *) ((caddr_t) odp + odp->d_reclen)) { - odp->d_ino = idp->__d_ino; - odp->d_namlen = idp->__d_namlen; - (void) strcpy(odp->d_name, idp->__d_name); - odp->d_reclen = reclen(odp); - if ((caddr_t) odp + odp->d_reclen > obufend) - break; - /* record offset *after* we're sure to use this entry */ - memcpy((char *)&tmp_offset, (char *)&idp->__d_off, sizeof tmp_offset); - offset = tmp_offset; - } - - outcount = (caddr_t) odp - obuf; - AFS_UIOMOVE(obuf, outcount, UIO_READ, uiop, u.u_error); - if (u.u_error) - goto out; - uiop->uio_offset = offset; -out: - kmem_free(ibuf, count); - kmem_free(obuf, count + sizeof (struct dirent)); - return u.u_error; + struct uio auio; + struct iovec aiov; + caddr_t ibuf, obuf, ibufend, obufend; + struct __dirent32 *idp; + struct dirent *odp; + int count, outcount; + dir_off_t offset; + uint64_t tmp_offset; + + count = uiop->uio_resid; + /* Allocate temporary space for format conversion */ + ibuf = kmem_alloc(2 * count); /* overkill - fix later */ + obuf = kmem_alloc(count + sizeof(struct dirent)); + aiov.iov_base = ibuf; + aiov.iov_len = count; + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + offset = auio.uio_offset = uiop->uio_offset; + auio.uio_seg = UIOSEG_KERNEL; + auio.uio_resid = count; + auio.uio_fpflags = 0; + + u.u_error = mp_afs_readdir2(vp, &auio, cred); + if (u.u_error) + goto out; + + /* Convert entries from __dirent32 to dirent format */ + + for (idp = (struct __dirent32 *)ibuf, odp = + (struct dirent *)obuf, ibufend = + ibuf + (count - auio.uio_resid), obufend = obuf + count; + (caddr_t) idp < ibufend; + idp = (struct __dirent32 *)((caddr_t) idp + idp->__d_reclen), odp = + (struct dirent *)((caddr_t) odp + odp->d_reclen)) { + odp->d_ino = idp->__d_ino; + odp->d_namlen = idp->__d_namlen; + (void)strcpy(odp->d_name, idp->__d_name); + odp->d_reclen = reclen(odp); + if ((caddr_t) odp + odp->d_reclen > obufend) + break; + /* record offset *after* we're sure to use this entry */ + memcpy((char *)&tmp_offset, (char *)&idp->__d_off, sizeof tmp_offset); + offset = tmp_offset; + } + + outcount = (caddr_t) odp - obuf; + AFS_UIOMOVE(obuf, outcount, UIO_READ, uiop, u.u_error); + if (u.u_error) + goto out; + uiop->uio_offset = offset; + out: + kmem_free(ibuf, count); + kmem_free(obuf, count + sizeof(struct dirent)); + return u.u_error; } @@ -2111,59 +2145,60 @@ afs_readdir3(vp, uiop, cred) struct uio *uiop; struct ucred *cred; { - struct uio auio; - struct iovec aiov; - caddr_t ibuf, obuf, ibufend, obufend; - struct __dirent32 *idp; - struct __dirent64 *odp; - int count, outcount; - dir_off_t offset; - - count = uiop->uio_resid; - /* Allocate temporary space for format conversion */ - ibuf = kmem_alloc(2*count); /* overkill - fix later */ - obuf = kmem_alloc(count + sizeof (struct __dirent64)); - aiov.iov_base = ibuf; - aiov.iov_len = count; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - offset = auio.uio_offset = uiop->uio_offset; - auio.uio_seg = UIOSEG_KERNEL; - auio.uio_resid = count; - auio.uio_fpflags = 0; - - u.u_error = mp_afs_readdir2(vp, &auio, cred); - if (u.u_error) - goto out; - - /* Convert entries from __dirent32 to __dirent64 format */ - - for (idp = (struct __dirent32 *) ibuf, odp = (struct __dirent64 *) obuf, - ibufend = ibuf + (count - auio.uio_resid), - obufend = obuf + count; - (caddr_t)idp < ibufend; - idp = (struct __dirent32 *) ((caddr_t) idp + idp->__d_reclen), - odp = (struct __dirent64 *) ((caddr_t) odp + odp->__d_reclen)) { - memcpy((char *)&odp->__d_off, (char *)&idp->__d_off, sizeof odp->__d_off); - odp->__d_ino = idp->__d_ino; - odp->__d_namlen = idp->__d_namlen; - (void) strcpy(odp->__d_name, idp->__d_name); - odp->__d_reclen = reclen_dirent64(odp); - if ((caddr_t) odp + odp->__d_reclen > obufend) - break; - /* record offset *after* we're sure to use this entry */ - offset = odp->__d_off; - } - - outcount = (caddr_t) odp - obuf; - AFS_UIOMOVE(obuf, outcount, UIO_READ, uiop, u.u_error); - if (u.u_error) - goto out; - uiop->uio_offset = offset; -out: - kmem_free(ibuf, count); - kmem_free(obuf, count + sizeof (struct __dirent64)); - return u.u_error; + struct uio auio; + struct iovec aiov; + caddr_t ibuf, obuf, ibufend, obufend; + struct __dirent32 *idp; + struct __dirent64 *odp; + int count, outcount; + dir_off_t offset; + + count = uiop->uio_resid; + /* Allocate temporary space for format conversion */ + ibuf = kmem_alloc(2 * count); /* overkill - fix later */ + obuf = kmem_alloc(count + sizeof(struct __dirent64)); + aiov.iov_base = ibuf; + aiov.iov_len = count; + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + offset = auio.uio_offset = uiop->uio_offset; + auio.uio_seg = UIOSEG_KERNEL; + auio.uio_resid = count; + auio.uio_fpflags = 0; + + u.u_error = mp_afs_readdir2(vp, &auio, cred); + if (u.u_error) + goto out; + + /* Convert entries from __dirent32 to __dirent64 format */ + + for (idp = (struct __dirent32 *)ibuf, odp = + (struct __dirent64 *)obuf, ibufend = + ibuf + (count - auio.uio_resid), obufend = obuf + count; + (caddr_t) idp < ibufend; + idp = (struct __dirent32 *)((caddr_t) idp + idp->__d_reclen), odp = + (struct __dirent64 *)((caddr_t) odp + odp->__d_reclen)) { + memcpy((char *)&odp->__d_off, (char *)&idp->__d_off, + sizeof odp->__d_off); + odp->__d_ino = idp->__d_ino; + odp->__d_namlen = idp->__d_namlen; + (void)strcpy(odp->__d_name, idp->__d_name); + odp->__d_reclen = reclen_dirent64(odp); + if ((caddr_t) odp + odp->__d_reclen > obufend) + break; + /* record offset *after* we're sure to use this entry */ + offset = odp->__d_off; + } + + outcount = (caddr_t) odp - obuf; + AFS_UIOMOVE(obuf, outcount, UIO_READ, uiop, u.u_error); + if (u.u_error) + goto out; + uiop->uio_offset = offset; + out: + kmem_free(ibuf, count); + kmem_free(obuf, count + sizeof(struct __dirent64)); + return u.u_error; } #define AFS_SV_SEMA_HASH 1 @@ -2215,28 +2250,26 @@ out: #define hashLock(xx) MP_PSEMA(&xx) #define hashUnlock(xx) MP_VSEMA(&xx) -typedef struct elem -{ - struct elem* next; - ELEMENT element; - KEY key; - int refCnt; +typedef struct elem { + struct elem *next; + ELEMENT element; + KEY key; + int refCnt; } Element; -typedef struct bucket -{ - sema_t lock; - Element* element; +typedef struct bucket { + sema_t lock; + Element *element; } Bucket; -static int sizeOfHashTable; -static Bucket* hashTable; +static int sizeOfHashTable; +static Bucket *hashTable; -static int currentSize=0; -static Element* freeList; /* free list */ +static int currentSize = 0; +static Element *freeList; /* free list */ #pragma align 64 -static sema_t afsHashLock = { 0 }; /* global lock for hash table */ +static sema_t afsHashLock = { 0 }; /* global lock for hash table */ static void afsHashGarbageCollect(); @@ -2250,232 +2283,231 @@ static void afsHashGarbageCollect(); void -afsHash(int nbuckets) /* allocate the hash table */ -{ - int i; +afsHash(int nbuckets) +{ /* allocate the hash table */ + int i; #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHash: enter\n"); + printf("afsHash: enter\n"); #endif - sizeOfHashTable = nbuckets; - currentSize = nbuckets * sizeof(Bucket); + sizeOfHashTable = nbuckets; + currentSize = nbuckets * sizeof(Bucket); - if ( hashTable ) - osi_Panic("afs: SEMA Hashtable already created\n"); + if (hashTable) + osi_Panic("afs: SEMA Hashtable already created\n"); - hashTable = (Bucket *)AFS_KALLOC(sizeOfHashTable * sizeof(Bucket)); - if ( ! hashTable ) - osi_Panic("afs: cannot create SEMA Hashtable\n"); + hashTable = (Bucket *) AFS_KALLOC(sizeOfHashTable * sizeof(Bucket)); + if (!hashTable) + osi_Panic("afs: cannot create SEMA Hashtable\n"); - /* initialize the hash table and associated locks */ - memset((char *)hashTable, 0, sizeOfHashTable * sizeof(Bucket )); - for ( i=0;i < sizeOfHashTable; i ++) - hashLockInit( hashTable[i].lock); - hashLockInit(afsHashLock); + /* initialize the hash table and associated locks */ + memset((char *)hashTable, 0, sizeOfHashTable * sizeof(Bucket)); + for (i = 0; i < sizeOfHashTable; i++) + hashLockInit(hashTable[i].lock); + hashLockInit(afsHashLock); #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHash: exit\n"); + printf("afsHash: exit\n"); #endif } -ELEMENT* +ELEMENT * afsHashInsertFind(KEY key) { - int index; - Element* ptr; + int index; + Element *ptr; #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHashInsertFind: %d\n", key); + printf("afsHashInsertFind: %d\n", key); #endif - if ( ! hashTable ) - osi_Panic("afs: afsHashInsertFind: no hashTable\n"); - - index = Hash(key); /* get bucket number */ - hashLock(hashTable[index].lock); /* lock this bucket */ - ptr = hashTable[index].element; - - /* if it is already there */ - while ( ptr ) { - if ( ptr->key == key ) { - ptr->refCnt++; /* hold it */ - hashUnlock(hashTable[index].lock); + if (!hashTable) + osi_Panic("afs: afsHashInsertFind: no hashTable\n"); + + index = Hash(key); /* get bucket number */ + hashLock(hashTable[index].lock); /* lock this bucket */ + ptr = hashTable[index].element; + + /* if it is already there */ + while (ptr) { + if (ptr->key == key) { + ptr->refCnt++; /* hold it */ + hashUnlock(hashTable[index].lock); #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHashInsertFind: %d FOUND\n", key); + printf("afsHashInsertFind: %d FOUND\n", key); #endif - return &(ptr->element); - } else { - ptr = ptr->next; - } + return &(ptr->element); + } else { + ptr = ptr->next; } + } - hashUnlock(hashTable[index].lock); + hashUnlock(hashTable[index].lock); - /* if something exists in the freeList, take it from there */ - ptr = NULL; - hashLock(afsHashLock); + /* if something exists in the freeList, take it from there */ + ptr = NULL; + hashLock(afsHashLock); - if ( freeList ) { - ptr = freeList; /* reuse entry */ - freeList = freeList->next; + if (freeList) { + ptr = freeList; /* reuse entry */ + freeList = freeList->next; + } else { + afsHashGarbageCollect(); /* afsHashLock locked */ + if (freeList) { + ptr = freeList; /* reuse entry */ + freeList = freeList->next; } else { - afsHashGarbageCollect(); /* afsHashLock locked */ - if ( freeList ) { - ptr = freeList; /* reuse entry */ - freeList = freeList->next; - } else { - ptr = (Element *)AFS_KALLOC(sizeof(Element)); - } + ptr = (Element *) AFS_KALLOC(sizeof(Element)); } + } - currentSize += sizeof(Element); /* update memory used */ - hashUnlock(afsHashLock); - - if ( ! ptr ) - osi_Panic("afs: SEMA Hashtable cannot create new entry\n"); - /* create new entry */ - ptr->key = key; - memset((char *)&ptr->element, 0, sizeof(ptr->element)); - ptr->refCnt = 1; /* this guy */ - - /* insert new entry in bucket */ - hashLock(hashTable[index].lock); /* lock this bucket */ - ptr->next = hashTable[index].element; - hashTable[index].element = ptr; - hashUnlock(hashTable[index].lock); + currentSize += sizeof(Element); /* update memory used */ + hashUnlock(afsHashLock); + + if (!ptr) + osi_Panic("afs: SEMA Hashtable cannot create new entry\n"); + /* create new entry */ + ptr->key = key; + memset((char *)&ptr->element, 0, sizeof(ptr->element)); + ptr->refCnt = 1; /* this guy */ + + /* insert new entry in bucket */ + hashLock(hashTable[index].lock); /* lock this bucket */ + ptr->next = hashTable[index].element; + hashTable[index].element = ptr; + hashUnlock(hashTable[index].lock); #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHashInsertFind: %d MADE\n", key); + printf("afsHashInsertFind: %d MADE\n", key); #endif - return &(ptr->element); + return &(ptr->element); } -ELEMENT* +ELEMENT * afsHashFind(KEY key) { - int index; - Element* ptr; + int index; + Element *ptr; #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHashFind: %d\n", key); + printf("afsHashFind: %d\n", key); #endif - if ( ! hashTable ) - osi_Panic("afs: afsHashFind: no hashTable\n"); - - index = Hash(key); /* get bucket number */ - hashLock(hashTable[index].lock); /* lock this bucket */ - ptr = hashTable[index].element; - - /* it should be in the hash table */ - while ( ptr ) { - if ( ptr->key == key ) - { - if(ptr->refCnt <= 0 ) - osi_Panic("afs: SEMA HashTable entry already released\n"); - hashUnlock(hashTable[index].lock); + if (!hashTable) + osi_Panic("afs: afsHashFind: no hashTable\n"); + + index = Hash(key); /* get bucket number */ + hashLock(hashTable[index].lock); /* lock this bucket */ + ptr = hashTable[index].element; + + /* it should be in the hash table */ + while (ptr) { + if (ptr->key == key) { + if (ptr->refCnt <= 0) + osi_Panic("afs: SEMA HashTable entry already released\n"); + hashUnlock(hashTable[index].lock); #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHashFind: %d FOUND\n", key); + printf("afsHashFind: %d FOUND\n", key); #endif - return &(ptr->element); - } else { - ptr = ptr->next; - } + return &(ptr->element); + } else { + ptr = ptr->next; } + } - hashUnlock(hashTable[index].lock); - /* it better be in the hash table */ - osi_Panic("afs: SEMA HashTable wants non-existent entry \n"); - return 0; + hashUnlock(hashTable[index].lock); + /* it better be in the hash table */ + osi_Panic("afs: SEMA HashTable wants non-existent entry \n"); + return 0; } void afsHashRelease(KEY key) { - int index; - Element* ptr; + int index; + Element *ptr; #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHashRelease: %d\n", key); + printf("afsHashRelease: %d\n", key); #endif - if ( ! hashTable ) - osi_Panic("afs: afsHashRelease: no hashTable\n"); - - index = Hash(key); /* get bucket number */ - hashLock(hashTable[index].lock); /* lock this bucket */ - ptr = hashTable[index].element; - - /* it should be in the hash table */ - while ( ptr ) { - if ( ptr->key == key ) { - if(ptr->refCnt <= 0 ) - osi_Panic("afs: SEMA HashTable entry already released\n"); - ptr->refCnt--; /* release this guy */ - hashUnlock(hashTable[index].lock); + if (!hashTable) + osi_Panic("afs: afsHashRelease: no hashTable\n"); + + index = Hash(key); /* get bucket number */ + hashLock(hashTable[index].lock); /* lock this bucket */ + ptr = hashTable[index].element; + + /* it should be in the hash table */ + while (ptr) { + if (ptr->key == key) { + if (ptr->refCnt <= 0) + osi_Panic("afs: SEMA HashTable entry already released\n"); + ptr->refCnt--; /* release this guy */ + hashUnlock(hashTable[index].lock); #if AFS_SV_SEMA_HASH_DEBUG -printf("afsHashRelease: %d FOUND\n", key); + printf("afsHashRelease: %d FOUND\n", key); #endif - return; - } else { - ptr = ptr->next; - } + return; + } else { + ptr = ptr->next; } + } - hashUnlock(hashTable[index].lock); - /* it better be in the hash table */ - osi_Panic("afs: SEMA HashTable deleting non-existent entry \n"); + hashUnlock(hashTable[index].lock); + /* it better be in the hash table */ + osi_Panic("afs: SEMA HashTable deleting non-existent entry \n"); } /* this should be called with afsHashLock WRITE locked */ static void afsHashGarbageCollect() { - int index; - Element* ptr; - int foundFlag=0; - - if ( ! hashTable ) - osi_Panic("afs: afsHashGarbageCollect: no hashTable\n"); - - for ( index = 0; index < sizeOfHashTable; index++) { - hashLock(hashTable[index].lock); - ptr = hashTable[index].element; /* pick up bucket */ - - while ( ptr && !ptr->refCnt ) { - /* insert this element into free list */ - Element* temp; - temp = ptr->next; - ptr->next = freeList; - freeList = ptr; - - foundFlag = 1; /* found at least one */ - currentSize -= sizeof(Element); - ptr = temp; + int index; + Element *ptr; + int foundFlag = 0; + + if (!hashTable) + osi_Panic("afs: afsHashGarbageCollect: no hashTable\n"); + + for (index = 0; index < sizeOfHashTable; index++) { + hashLock(hashTable[index].lock); + ptr = hashTable[index].element; /* pick up bucket */ + + while (ptr && !ptr->refCnt) { + /* insert this element into free list */ + Element *temp; + temp = ptr->next; + ptr->next = freeList; + freeList = ptr; + + foundFlag = 1; /* found at least one */ + currentSize -= sizeof(Element); + ptr = temp; + } + hashTable[index].element = ptr; + + /* scan thru the remaining list */ + if (ptr) { + while (ptr->next) { + if (ptr->next->refCnt == 0) { + /* collect this element */ + Element *temp; + temp = ptr->next; + ptr->next = ptr->next->next; + temp->next = freeList; + freeList = temp; + foundFlag = 1; + currentSize -= sizeof(Element); + } else { + ptr = ptr->next; } - hashTable[index].element = ptr; - - /* scan thru the remaining list */ - if ( ptr ) { - while ( ptr->next ) { - if ( ptr->next->refCnt == 0 ) { - /* collect this element */ - Element* temp; - temp = ptr->next; - ptr->next = ptr->next->next; - temp->next = freeList; - freeList = temp; - foundFlag = 1; - currentSize -= sizeof(Element); - } else { - ptr = ptr->next; - } - } - } - hashUnlock(hashTable[index].lock); + } } + hashUnlock(hashTable[index].lock); + } #if 0 - if(!foundFlag) - osi_Panic("afs: SEMA HashTable full\n"); + if (!foundFlag) + osi_Panic("afs: SEMA HashTable full\n"); #endif } @@ -2483,7 +2515,7 @@ afsHashGarbageCollect() afs_hp_strategy(bp) - register struct buf *bp; + register struct buf *bp; { register afs_int32 code; struct uio tuio; @@ -2502,40 +2534,37 @@ afs_hp_strategy(bp) hdl_kmap_bp(bp); AFS_GLOCK(); - afs_Trace4(afs_iclSetp, CM_TRACE_HPSTRAT, ICL_TYPE_POINTER, - bp->b_vp, ICL_TYPE_LONG, - (int)bp->b_blkno*DEV_BSIZE, ICL_TYPE_LONG, bp->b_bcount, - ICL_TYPE_LONG,0); - - /* Set up the uio structure */ - tuio.afsio_iov = tiovec; - tuio.afsio_iovcnt = 1; - tuio.afsio_offset = DEV_BSIZE * bp->b_blkno; - tuio.afsio_seg = AFS_UIOSYS; - tuio.afsio_resid = bp->b_bcount; - tuio.uio_fpflags = 0; - tiovec[0].iov_base = bp->b_un.b_addr; - tiovec[0].iov_len = bp->b_bcount; - - /* Do the I/O */ - if ((bp->b_flags & B_READ) == B_READ) - { - /* read b_bcount bytes into kernel address b_un.b_addr - starting at byte DEV_BSIZE * b_blkno. Bzero anything - we can't read, and finally call iodone(bp). File is - in bp->b_vp. Credentials are from u area?? - */ - code = afs_rdwr(VTOAFS(bp->b_vp),&tuio,UIO_READ,0,kt_cred(t)); - if (code == 0) - if (tuio.afsio_resid > 0) - { - privlbzero(bvtospace(bp, bp->b_un.b_addr), - bp->b_un.b_addr + bp->b_bcount - tuio.afsio_resid, - (size_t) tuio.afsio_resid); - - } - } else - code = afs_rdwr(VTOAFS(bp->b_vp),&tuio,UIO_WRITE,0,kt_cred(t)); + afs_Trace4(afs_iclSetp, CM_TRACE_HPSTRAT, ICL_TYPE_POINTER, bp->b_vp, + ICL_TYPE_LONG, (int)bp->b_blkno * DEV_BSIZE, ICL_TYPE_LONG, + bp->b_bcount, ICL_TYPE_LONG, 0); + + /* Set up the uio structure */ + tuio.afsio_iov = tiovec; + tuio.afsio_iovcnt = 1; + tuio.afsio_offset = DEV_BSIZE * bp->b_blkno; + tuio.afsio_seg = AFS_UIOSYS; + tuio.afsio_resid = bp->b_bcount; + tuio.uio_fpflags = 0; + tiovec[0].iov_base = bp->b_un.b_addr; + tiovec[0].iov_len = bp->b_bcount; + + /* Do the I/O */ + if ((bp->b_flags & B_READ) == B_READ) { + /* read b_bcount bytes into kernel address b_un.b_addr + * starting at byte DEV_BSIZE * b_blkno. Bzero anything + * we can't read, and finally call iodone(bp). File is + * in bp->b_vp. Credentials are from u area?? + */ + code = afs_rdwr(VTOAFS(bp->b_vp), &tuio, UIO_READ, 0, kt_cred(t)); + if (code == 0) + if (tuio.afsio_resid > 0) { + privlbzero(bvtospace(bp, bp->b_un.b_addr), + bp->b_un.b_addr + bp->b_bcount - tuio.afsio_resid, + (size_t) tuio.afsio_resid); + + } + } else + code = afs_rdwr(VTOAFS(bp->b_vp), &tuio, UIO_WRITE, 0, kt_cred(t)); /* Remap back to the user's space */ hdl_remap_bp(bp); @@ -2547,76 +2576,75 @@ afs_hp_strategy(bp) } afs_pathconf(vp, name, resultp, cred) -struct vnode *vp; -int name; -int *resultp; -struct ucred *cred; /* unused */ + struct vnode *vp; + int name; + int *resultp; + struct ucred *cred; /* unused */ { - switch(name) - { - case _PC_LINK_MAX: /* Maximum number of links to a file */ - *resultp = 255; /* an unsigned short on the fileserver*/ - break; /* a unsigned char in the client.... */ - - case _PC_NAME_MAX: /* Max length of file name */ - *resultp = 255; - break; + switch (name) { + case _PC_LINK_MAX: /* Maximum number of links to a file */ + *resultp = 255; /* an unsigned short on the fileserver */ + break; /* a unsigned char in the client.... */ - case _PC_PATH_MAX: /* Maximum length of Path Name */ - *resultp = 1024; - break; + case _PC_NAME_MAX: /* Max length of file name */ + *resultp = 255; + break; - case _PC_PIPE_BUF: /* Max atomic write to pipe. See fifo_vnops */ - case _PC_CHOWN_RESTRICTED: /* Anybody can chown? */ - case _PC_NO_TRUNC: /* No file name truncation on overflow? */ - u.u_error = EOPNOTSUPP; - return(EOPNOTSUPP); - break; + case _PC_PATH_MAX: /* Maximum length of Path Name */ + *resultp = 1024; + break; - case _PC_MAX_CANON: /* TTY buffer size for canonical input */ - /* need more work here for pty, ite buffer size, if differ */ - if (vp->v_type != VCHR) { - u.u_error = EINVAL; - return(EINVAL); - } - *resultp = CANBSIZ; /*for tty*/ - break; + case _PC_PIPE_BUF: /* Max atomic write to pipe. See fifo_vnops */ + case _PC_CHOWN_RESTRICTED: /* Anybody can chown? */ + case _PC_NO_TRUNC: /* No file name truncation on overflow? */ + u.u_error = EOPNOTSUPP; + return (EOPNOTSUPP); + break; - case _PC_MAX_INPUT: - /* need more work here for pty, ite buffer size, if differ */ - if (vp->v_type != VCHR) { /* TTY buffer size */ - u.u_error = EINVAL; - return(EINVAL); - } - *resultp = TTYHOG; /*for tty*/ - break; + case _PC_MAX_CANON: /* TTY buffer size for canonical input */ + /* need more work here for pty, ite buffer size, if differ */ + if (vp->v_type != VCHR) { + u.u_error = EINVAL; + return (EINVAL); + } + *resultp = CANBSIZ; /*for tty */ + break; - case _PC_VDISABLE: - /* Terminal special characters can be disabled? */ - if (vp->v_type != VCHR) { - u.u_error = EINVAL; - return(EINVAL); - } - *resultp = 1; - break; + case _PC_MAX_INPUT: + /* need more work here for pty, ite buffer size, if differ */ + if (vp->v_type != VCHR) { /* TTY buffer size */ + u.u_error = EINVAL; + return (EINVAL); + } + *resultp = TTYHOG; /*for tty */ + break; - case _PC_SYNC_IO: - if ((vp->v_type != VREG) && (vp->v_type != VBLK)) { - *resultp = -1; - return EINVAL; - } - *resultp = 1; /* Synchronized IO supported for this file */ - break; - - case _PC_FILESIZEBITS: - if (vp->v_type != VDIR) - return(EINVAL); - *resultp = MAX_SMALL_FILE_BITS; - break; + case _PC_VDISABLE: + /* Terminal special characters can be disabled? */ + if (vp->v_type != VCHR) { + u.u_error = EINVAL; + return (EINVAL); + } + *resultp = 1; + break; - default: - return(EINVAL); + case _PC_SYNC_IO: + if ((vp->v_type != VREG) && (vp->v_type != VBLK)) { + *resultp = -1; + return EINVAL; } + *resultp = 1; /* Synchronized IO supported for this file */ + break; - return(0); + case _PC_FILESIZEBITS: + if (vp->v_type != VDIR) + return (EINVAL); + *resultp = MAX_SMALL_FILE_BITS; + break; + + default: + return (EINVAL); + } + + return (0); } diff --git a/src/afs/IRIX/osi_file.c b/src/afs/IRIX/osi_file.c index 322af9a13..a71f1c555 100644 --- a/src/afs/IRIX/osi_file.c +++ b/src/afs/IRIX/osi_file.c @@ -8,16 +8,16 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_file.c,v 1.1.1.6 2001/09/11 14:25:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_file.c,v 1.10 2003/07/15 23:14:23 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ -int afs_osicred_initialized=0; -struct AFS_UCRED afs_osi_cred; +int afs_osicred_initialized = 0; afs_lock_t afs_xosi; /* lock is for tvattr */ extern struct osi_dev cacheDev; extern struct vfs *afs_cacheVfsp; @@ -28,32 +28,34 @@ extern struct vfs *afs_cacheVfsp; * added which accesses the inode, that will also need EFS/XFS variants. */ #ifdef AFS_SGI_EFS_IOPS_ENV -vnode_t *afs_EFSIGetVnode(ino_t ainode) +vnode_t * +afs_EFSIGetVnode(ino_t ainode) { struct inode *ip; int error; - if ((error = igetinode(afs_cacheVfsp, (dev_t)cacheDev.dev, ainode, &ip))) { + if ((error = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, ainode, &ip))) { osi_Panic("afs_EFSIGetVnode: igetinode failed, error=%d", error); } /* We don't care about atimes on the cache files, so disable them. I'm not * sure that this is the right place to do this: it should be *after* readi * and getattr and stuff. */ - ip->i_flags &= ~(ISYN|IACC); + ip->i_flags &= ~(ISYN | IACC); iunlock(ip); return (EFS_ITOV(ip)); -} +} #endif /* AFS_SGI_EFS_IOPS_ENV */ -vnode_t *afs_XFSIGetVnode(ino_t ainode) +vnode_t * +afs_XFSIGetVnode(ino_t ainode) { struct xfs_inode *ip; int error; vnode_t *vp; if ((error = - xfs_igetinode(afs_cacheVfsp, (dev_t)cacheDev.dev, ainode, &ip))) { + xfs_igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, ainode, &ip))) { osi_Panic("afs_XFSIGetVnode: xfs_igetinode failed, error=%d", error); } vp = XFS_ITOV(ip); @@ -61,7 +63,8 @@ vnode_t *afs_XFSIGetVnode(ino_t ainode) } /* Force to 64 bits, even for EFS filesystems. */ -void *osi_UFSOpen(ino_t ainode) +void * +osi_UFSOpen(ino_t ainode) { struct inode *ip; register struct osi_file *afile = NULL; @@ -69,7 +72,7 @@ void *osi_UFSOpen(ino_t ainode) afs_int32 code = 0; int dummy; AFS_STATCNT(osi_UFSOpen); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) { + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) { osi_Panic("UFSOpen called for non-UFS cache\n"); } if (!afs_osicred_initialized) { @@ -78,26 +81,26 @@ void *osi_UFSOpen(ino_t ainode) crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */ afs_osicred_initialized = 1; } - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); AFS_GUNLOCK(); afile->vnode = AFS_SGI_IGETVNODE(ainode); AFS_GLOCK(); afile->size = VnodeToSize(afile->vnode); afile->offset = 0; - afile->proc = (int (*)()) 0; - afile->inum = ainode; /* for hint validity checking */ + afile->proc = (int (*)())0; + afile->inum = ainode; /* for hint validity checking */ return (void *)afile; } -afs_osi_Stat(afile, astat) - register struct osi_file *afile; - register struct osi_stat *astat; { +int +afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) +{ register afs_int32 code; struct vattr tvattr; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi,320); + MObtainWriteLock(&afs_xosi, 320); AFS_GUNLOCK(); - tvattr.va_mask = AT_SIZE|AT_BLKSIZE|AT_MTIME|AT_ATIME; + tvattr.va_mask = AT_SIZE | AT_BLKSIZE | AT_MTIME | AT_ATIME; AFS_VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code); AFS_GLOCK(); if (code == 0) { @@ -110,21 +113,21 @@ afs_osi_Stat(afile, astat) return code; } -osi_UFSClose(afile) - register struct osi_file *afile; - { - AFS_STATCNT(osi_Close); - if(afile->vnode) { +int +osi_UFSClose(register struct osi_file *afile) +{ + AFS_STATCNT(osi_Close); + if (afile->vnode) { VN_RELE(afile->vnode); - } - - osi_FreeSmallSpace(afile); - return 0; - } + } -osi_UFSTruncate(afile, asize) - register struct osi_file *afile; - afs_int32 asize; { + osi_FreeSmallSpace(afile); + return 0; +} + +int +osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) +{ struct AFS_UCRED *oldCred; struct vattr tvattr; register afs_int32 code; @@ -137,8 +140,9 @@ osi_UFSTruncate(afile, asize) * small enough. Check now and save some time. */ code = afs_osi_Stat(afile, &tstat); - if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi,321); + if (code || tstat.size <= asize) + return code; + MObtainWriteLock(&afs_xosi, 321); AFS_GUNLOCK(); tvattr.va_mask = AT_SIZE; tvattr.va_size = asize; @@ -149,46 +153,46 @@ osi_UFSTruncate(afile, asize) } #ifdef AFS_SGI_EFS_IOPS_ENV -void osi_DisableAtimes(avp) -struct vnode *avp; +void +osi_DisableAtimes(struct vnode *avp) { - if (afs_CacheFSType == AFS_SGI_EFS_CACHE) - { - struct inode *ip = EFS_VTOI(avp); - ip->i_flags &= ~IACC; - } + if (afs_CacheFSType == AFS_SGI_EFS_CACHE) { + struct inode *ip = EFS_VTOI(avp); + ip->i_flags &= ~IACC; + } } #endif /* AFS_SGI_EFS_IOPS_ENV */ /* Generic read interface */ -afs_osi_Read(afile, offset, aptr, asize) - register struct osi_file *afile; - int offset; - char *aptr; - afs_int32 asize; { +int +afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; ssize_t resid; register afs_int32 code; - register afs_int32 cnt1=0; + register afs_int32 cnt1 = 0; AFS_STATCNT(osi_Read); - + /** * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ - if ( !afile ) { - if ( !afs_shuttingdown ) + if (!afile) { + if (!afs_shuttingdown) osi_Panic("osi_Read called with null param"); else - return EIO; + return EIO; } - - if (offset != -1) afile->offset = offset; + + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, + AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; @@ -196,42 +200,44 @@ afs_osi_Read(afile, offset, aptr, asize) #ifdef AFS_SGI_EFS_IOPS_ENV osi_DisableAtimes(afile->vnode); #endif /* AFS_SGI_EFS_IOPS_ENV */ - } - else { + } else { afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, - ICL_TYPE_INT32, code); + ICL_TYPE_INT32, code); code = -1; } return code; } /* Generic write interface */ -afs_osi_Write(afile, offset, aptr, asize) - register struct osi_file *afile; - char *aptr; - afs_int32 offset; - afs_int32 asize; { +int +afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; ssize_t resid; register afs_int32 code; AFS_STATCNT(osi_Write); - if ( !afile ) - osi_Panic("afs_osi_Write called with null param"); - if (offset != -1) afile->offset = offset; + if (!afile) + osi_Panic("afs_osi_Write called with null param"); + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + afile->offset, AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, + &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; - } - else { - if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); + } else { + if (code == ENOSPC) + afs_warnuser + ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); code = -1; } if (afile->proc) { - (*afile->proc)(afile, code); + (*afile->proc) (afile, code); } return code; } @@ -240,9 +246,8 @@ afs_osi_Write(afile, offset, aptr, asize) /* This work should be handled by physstrat in ca/machdep.c. This routine written from the RT NFS port strategy routine. It has been generalized a bit, but should still be pretty clear. */ -int afs_osi_MapStrategy(aproc, bp) - int (*aproc)(); - register struct buf *bp; +int +afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp) { afs_int32 returnCode; @@ -255,13 +260,12 @@ int afs_osi_MapStrategy(aproc, bp) void -shutdown_osifile() +shutdown_osifile(void) { - extern int afs_cold_shutdown; + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osifile); - if (afs_cold_shutdown) { - afs_osicred_initialized = 0; - } + AFS_STATCNT(shutdown_osifile); + if (afs_cold_shutdown) { + afs_osicred_initialized = 0; + } } - diff --git a/src/afs/IRIX/osi_groups.c b/src/afs/IRIX/osi_groups.c index 2a646345b..c77465f7b 100644 --- a/src/afs/IRIX/osi_groups.c +++ b/src/afs/IRIX/osi_groups.c @@ -16,27 +16,22 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_groups.c,v 1.1.1.5 2001/09/11 14:25:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_groups.c,v 1.9 2003/07/15 23:14:23 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset); + afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset); static int -afs_setgroups( - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent); + afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset, + int change_parent); /* This is common code between SGI's DFS and our AFS. Do *not* alter it's @@ -47,8 +42,9 @@ afs_setgroups( * Sets up the cred for the call to estgroups. This is pretty convoluted * in order to avoid including the private proc.h header file. */ -int fixup_pags(int **credpp, int ngroups, gid_t *gidset, int old_afs_pag, - int old_dfs_pag) +int +fixup_pags(int **credpp, int ngroups, gid_t * gidset, int old_afs_pag, + int old_dfs_pag) { int new_afs_pag = 0; int new_dfs_pag = 0; @@ -67,45 +63,46 @@ int fixup_pags(int **credpp, int ngroups, gid_t *gidset, int old_afs_pag, return EFAULT; } - if (ngroups >= 2) { /* possibly an AFS PAG */ - new_afs_pag = (afs_get_pag_from_groups(groups[0], groups[1]) != NOPAG); + if (ngroups >= 2) { /* possibly an AFS PAG */ + new_afs_pag = + (afs_get_pag_from_groups(groups[0], groups[1]) != NOPAG); } - if (ngroups >= 1) { /* possibly a DFS PAG */ - new_dfs_pag = (int) groups[ngroups-1]; + if (ngroups >= 1) { /* possibly a DFS PAG */ + new_dfs_pag = (int)groups[ngroups - 1]; if (((new_dfs_pag >> 24) & 0xff) == 'A') - new_dfs_pag = (int) groups[ngroups-1]; + new_dfs_pag = (int)groups[ngroups - 1]; else new_dfs_pag = 0; } /* Now compute the number of groups we will need. */ new = ngroups; - if (old_afs_pag && !new_afs_pag) /* prepend old AFS pag */ + if (old_afs_pag && !new_afs_pag) /* prepend old AFS pag */ new += 2; - if (old_dfs_pag && !new_dfs_pag) /* append old DFS pag */ - new ++; + if (old_dfs_pag && !new_dfs_pag) /* append old DFS pag */ + new++; if (new > ngroups_max) - return EINVAL; /* sorry */ + return EINVAL; /* sorry */ - cr = crdup(OSI_GET_CURRENT_CRED()); /* we will replace all the groups. */ - memset((char*)&cr->cr_groups, 0, ngroups_max * sizeof(gid_t)); + cr = crdup(OSI_GET_CURRENT_CRED()); /* we will replace all the groups. */ + memset((char *)&cr->cr_groups, 0, ngroups_max * sizeof(gid_t)); /* Now cobble the new groups list together. */ new = 0; old = 0; - if (old_afs_pag && !new_afs_pag) { /* prepend old AFS pag */ + if (old_afs_pag && !new_afs_pag) { /* prepend old AFS pag */ gid_t g0, g1; changed = 1; afs_get_groups_from_pag(old_afs_pag, &g0, &g1); cr->cr_groups[new++] = g0; cr->cr_groups[new++] = g1; } - + for (old = 0; old < ngroups; old++) cr->cr_groups[new++] = groups[old]; - if (old_dfs_pag && !new_dfs_pag) { /* append old DFS pag */ + if (old_dfs_pag && !new_dfs_pag) { /* append old DFS pag */ changed = 1; cr->cr_groups[new++] = old_dfs_pag; } @@ -114,8 +111,7 @@ int fixup_pags(int **credpp, int ngroups, gid_t *gidset, int old_afs_pag, if (changed) { cr->cr_ngroups = new; *credpp = cr; - } - else { + } else { crfree(cr); *credpp = NULL; } @@ -127,7 +123,8 @@ int fixup_pags(int **credpp, int ngroups, gid_t *gidset, int old_afs_pag, * If flag = 0 this is a DFS pag held in one group. * If flag = 1 this is a AFS pag held in two group entries */ -static int afsDFS_SetPagInCred(struct ucred *credp, int pag, int flag) +static int +afsDFS_SetPagInCred(struct ucred *credp, int pag, int flag) { int *gidset; int i, ngrps; @@ -138,31 +135,31 @@ static int afsDFS_SetPagInCred(struct ucred *credp, int pag, int flag) ngrps = credp->cr_ngroups + groups_taken; if (ngrps >= ngroups_max) - return E2BIG; + return E2BIG; + - if (flag) { - /* Break out the AFS pag into two groups */ - afs_get_groups_from_pag(pag, &g0, &g1); + /* Break out the AFS pag into two groups */ + afs_get_groups_from_pag(pag, &g0, &g1); } newcredp = crdup(credp); newcredp->cr_ngroups = ngrps; if (flag) { - /* AFS case */ - newcredp->cr_groups[0] = g0; - newcredp->cr_groups[1] = g1; + /* AFS case */ + newcredp->cr_groups[0] = g0; + newcredp->cr_groups[1] = g1; } else { - /* DFS case */ - if (PagInCred(newcredp) != NOPAG){ - /* found an AFS PAG is set in this cred */ - n = 2; - } - newcredp->cr_groups[n] = pag; + /* DFS case */ + if (PagInCred(newcredp) != NOPAG) { + /* found an AFS PAG is set in this cred */ + n = 2; + } + newcredp->cr_groups[n] = pag; } - for (i=n; icr_ngroups; i++) - newcredp->cr_groups[i+groups_taken] = credp->cr_groups[i]; + for (i = n; i < credp->cr_ngroups; i++) + newcredp->cr_groups[i + groups_taken] = credp->cr_groups[i]; /* estgroups sets current threads cred from newcredp and crfree's credp */ estgroups(credp, newcredp); @@ -172,11 +169,12 @@ static int afsDFS_SetPagInCred(struct ucred *credp, int pag, int flag) #endif /* AFS_SGI65_ENV */ /* SGI's osi_GetPagFromCred - They return a long. */ -int osi_DFSGetPagFromCred(struct ucred *credp) +int +osi_DFSGetPagFromCred(struct ucred *credp) { int pag; int ngroups; - + /* * For IRIX, the PAG is stored in the first entry * of the gruop list in the cred structure. gid_t's @@ -185,47 +183,47 @@ int osi_DFSGetPagFromCred(struct ucred *credp) */ ngroups = credp->cr_ngroups; if (ngroups < 1) - return NOPAG; + return NOPAG; /* * Keep in mind that we might be living with AFS here. * This means we don't really know if our DFS PAG is in * the first or third group entry. */ #ifdef AFS_SGI65_ENV - pag = credp->cr_groups[ngroups-1]; + pag = credp->cr_groups[ngroups - 1]; #else pag = credp->cr_groups[0]; - if (PagInCred(credp) != NOPAG ){ - /* AFS has a PAG value in the first two group entries */ - if (ngroups < 3) - return NOPAG; - pag = credp->cr_groups[2]; + if (PagInCred(credp) != NOPAG) { + /* AFS has a PAG value in the first two group entries */ + if (ngroups < 3) + return NOPAG; + pag = credp->cr_groups[2]; } #endif if (((pag >> 24) & 0xff) == 'A') - return pag; + return pag; else - return NOPAG; + return NOPAG; } - + int -Afs_xsetgroups(int ngroups, gid_t *gidset) +Afs_xsetgroups(int ngroups, gid_t * gidset) { int old_afs_pag = NOPAG; int old_dfs_pag = NOPAG; int code = 0; struct ucred *credp = OSI_GET_CURRENT_CRED(); struct ucred *modcredp; - + credp = OSI_GET_CURRENT_CRED(); /* First get any old PAG's */ old_afs_pag = PagInCred(credp); old_dfs_pag = osi_DFSGetPagFromCred(credp); - + /* Set the passed in group list. */ if (code = setgroups(ngroups, gidset)) - return code; + return code; #ifdef AFS_SGI65_ENV if (old_afs_pag == NOPAG && old_dfs_pag == NOPAG) @@ -236,42 +234,43 @@ Afs_xsetgroups(int ngroups, gid_t *gidset) * the uthread until we return to user space. So, we examine the passed * in groups in fixup_pags. */ - code = fixup_pags(&modcredp, ngroups, gidset, - (old_afs_pag == NOPAG) ? 0 : old_afs_pag, - (old_dfs_pag == NOPAG) ? 0 : old_dfs_pag); + code = + fixup_pags(&modcredp, ngroups, gidset, + (old_afs_pag == NOPAG) ? 0 : old_afs_pag, + (old_dfs_pag == NOPAG) ? 0 : old_dfs_pag); if (!code && modcredp) estgroups(OSI_GET_CURRENT_PROCP(), modcredp); #else - + /* * The setgroups gave our curent thread a new cred pointer * Get the value again */ credp = OSI_GET_CURRENT_CRED(); if ((PagInCred(credp) == NOPAG) && (old_afs_pag != NOPAG)) { - /* reset the AFS PAG */ - code = afsDFS_SetPagInCred(credp, old_afs_pag, 1); + /* reset the AFS PAG */ + code = afsDFS_SetPagInCred(credp, old_afs_pag, 1); } /* * Once again get the credp because the afsDFS_SetPagInCred might have * assigned a new one. */ credp = OSI_GET_CURRENT_CRED(); - if ((osi_DFSGetPagFromCred(credp)==NOPAG) + if ((osi_DFSGetPagFromCred(credp) == NOPAG) && (old_dfs_pag != NOPAG)) { - code = afsDFS_SetPagInCred(credp, old_dfs_pag, 0); + code = afsDFS_SetPagInCred(credp, old_dfs_pag, 0); } -#endif /* AFS_SGI65_ENV */ +#endif /* AFS_SGI65_ENV */ return code; } int setpag(cred, pagvalue, newpag, change_parent) - struct ucred **cred; - afs_uint32 pagvalue; - afs_uint32 *newpag; - afs_uint32 change_parent; + struct ucred **cred; + afs_uint32 pagvalue; + afs_uint32 *newpag; + afs_uint32 change_parent; { gid_t gidset[NGROUPS]; int ngroups, code; @@ -283,24 +282,24 @@ setpag(cred, pagvalue, newpag, change_parent) if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) { /* We will have to shift grouplist to make room for pag */ if (ngroups + 2 > NGROUPS) { -#ifdef AFS_SGI64_ENV - return (E2BIG); -#else +#if defined(KERNEL_HAVE_UERROR) return (setuerror(E2BIG), E2BIG); +#else + return (E2BIG); #endif } - for (j = ngroups -1; j >= 0; j--) { - gidset[j+2] = gidset[j]; - } + for (j = ngroups - 1; j >= 0; j--) { + gidset[j + 2] = gidset[j]; + } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); + *newpag = (pagvalue == -1 ? genpag() : pagvalue); afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]); if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) { -#ifdef AFS_SGI64_ENV - return code; -#else +#if defined(KERNEL_HAVE_UERROR) return (setuerror(code), code); +#else + return code; #endif } return code; @@ -308,10 +307,7 @@ setpag(cred, pagvalue, newpag, change_parent) static int -afs_getgroups( - struct ucred *cred, - int ngroups, - gid_t *gidset) +afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset) { int ngrps, savengrps; gid_t *gp; @@ -321,18 +317,15 @@ afs_getgroups( savengrps = ngrps = MIN(ngroups, cred->cr_ngroups); gp = cred->cr_groups; while (ngrps--) - *gidset++ = *gp++; + *gidset++ = *gp++; return savengrps; } static int -afs_setgroups( - struct ucred **cred, - int ngroups, - gid_t *gidset, - int change_parent) +afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset, + int change_parent) { gid_t *gp; cred_t *cr, *newcr; @@ -340,21 +333,21 @@ afs_setgroups( AFS_STATCNT(afs_setgroups); if (ngroups > ngroups_max) - return EINVAL; + return EINVAL; cr = *cred; if (!change_parent) - newcr = crdup(cr); + newcr = crdup(cr); else - newcr = cr; + newcr = cr; newcr->cr_ngroups = ngroups; gp = newcr->cr_groups; while (ngroups--) - *gp++ = *gidset++; + *gp++ = *gidset++; if (!change_parent) { #ifdef AFS_SGI65_ENV estgroups(OSI_GET_CURRENT_PROCP(), newcr); #else - estgroups(cr, newcr); + estgroups(cr, newcr); #endif } *cred = newcr; diff --git a/src/afs/IRIX/osi_idbg.c b/src/afs/IRIX/osi_idbg.c index 3ec909935..19ded0dd0 100644 --- a/src/afs/IRIX/osi_idbg.c +++ b/src/afs/IRIX/osi_idbg.c @@ -11,14 +11,15 @@ * Implementation of Irix IDBG facility for AFS. */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_idbg.c,v 1.1.1.4 2001/07/14 22:19:42 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_idbg.c,v 1.6 2003/07/15 23:14:23 shadow Exp $"); #ifdef AFS_SGI62_ENV -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ /* @@ -40,15 +41,15 @@ printflags(register unsigned int flags, register char **strings) } char *tab_vcache[] = { - "CStatd", /* 1 */ - "CBackup", /* 2 */ - "CRO", /* 4 */ - "CMValid", /* 8 */ - "CCore", /* 0x10 */ - "CDirty", /* 0x20 */ - "CSafeStore", /* 0x40 */ - "CMAPPED", /* 0x80 */ - "CNSHARE", /* 0x100 */ + "CStatd", /* 1 */ + "CBackup", /* 2 */ + "CRO", /* 4 */ + "CMValid", /* 8 */ + "CCore", /* 0x10 */ + "CDirty", /* 0x20 */ + "CSafeStore", /* 0x40 */ + "CMAPPED", /* 0x80 */ + "CNSHARE", /* 0x100 */ }; int @@ -56,119 +57,115 @@ idbg_prafsnode(OSI_VC_DECL(avc)) { OSI_VC_CONVERT(avc) - AFS_GLOCK(); + AFS_GLOCK(); qprintf(" Len %d DV %d Date %d Own %d Grp %d Mode 0%o Lnk %d\n", - avc->m.Length, avc->m.DataVersion, avc->m.Date, - avc->m.Owner, avc->m.Group, avc->m.Mode, avc->m.LinkCount); + avc->m.Length, avc->m.DataVersion, avc->m.Date, avc->m.Owner, + avc->m.Group, avc->m.Mode, avc->m.LinkCount); qprintf(" flushDV %d mapDV %d truncpos 0x%x cb 0x%x cbE 0x%x\n", - avc->flushDV, avc->mapDV, avc->truncPos, - avc->callback, avc->cbExpires); - qprintf(" opens %d ex/wr %d flckcnt %d state 0x%x ", - avc->opens, avc->execsOrWriters, avc->flockCount, - avc->states); + avc->flushDV, avc->mapDV, avc->truncPos, avc->callback, + avc->cbExpires); + qprintf(" opens %d ex/wr %d flckcnt %d state 0x%x ", avc->opens, + avc->execsOrWriters, avc->flockCount, avc->states); printflags(avc->states, tab_vcache); qprintf("\n"); #ifdef AFS_SGI64_ENV qprintf(" mapcnt %llu, mvstat %d anyAcc 0x%x Access 0x%x\n", avc->mapcnt, avc->mvstat, avc->anyAccess, avc->Access); - qprintf(" mvid 0x%x &lock 0x%x cred 0x%x\n", - avc->mvid, &avc->lock, avc->cred); - qprintf(" rwlock 0x%x (%d) id %llu trips %d\n", - &avc->vc_rwlock, valusema(&avc->vc_rwlock), avc->vc_rwlockid, - avc->vc_locktrips); + qprintf(" mvid 0x%x &lock 0x%x cred 0x%x\n", avc->mvid, &avc->lock, + avc->cred); + qprintf(" rwlock 0x%x (%d) id %llu trips %d\n", &avc->vc_rwlock, + valusema(&avc->vc_rwlock), avc->vc_rwlockid, avc->vc_locktrips); #else - qprintf(" mapcnt %d mvstat %d anyAcc 0x%x Access 0x%x\n", - avc->mapcnt, avc->mvstat, avc->anyAccess, avc->Access); - qprintf(" mvid 0x%x &lock 0x%x cred 0x%x\n", - avc->mvid, &avc->lock, avc->cred); - qprintf(" rwlock 0x%x (%d) id %d trips %d\n", - &avc->vc_rwlock, valusema(&avc->vc_rwlock), avc->vc_rwlockid, - avc->vc_locktrips); + qprintf(" mapcnt %d mvstat %d anyAcc 0x%x Access 0x%x\n", avc->mapcnt, + avc->mvstat, avc->anyAccess, avc->Access); + qprintf(" mvid 0x%x &lock 0x%x cred 0x%x\n", avc->mvid, &avc->lock, + avc->cred); + qprintf(" rwlock 0x%x (%d) id %d trips %d\n", &avc->vc_rwlock, + valusema(&avc->vc_rwlock), avc->vc_rwlockid, avc->vc_locktrips); #endif AFS_GUNLOCK(); return 0; } -extern struct afs_q VLRU; /*vcache LRU*/ +extern struct afs_q VLRU; /*vcache LRU */ static char *tab_vtypes[] = { - "VNON", - "VREG", - "VDIR", - "VBLK", - "VCHR", - "VLNK", - "VFIFO", - "VXNAM", - "VBAD", - "VSOCK", - 0 + "VNON", + "VREG", + "VDIR", + "VBLK", + "VCHR", + "VLNK", + "VFIFO", + "VXNAM", + "VBAD", + "VSOCK", + 0 }; int idbg_afsvfslist() { - struct vcache *tvc; - register struct afs_q *tq; - struct afs_q *uq; - afs_int32 nodeid; /* what ls prints as 'inode' */ + struct vcache *tvc; + register struct afs_q *tq; + struct afs_q *uq; + afs_int32 nodeid; /* what ls prints as 'inode' */ - AFS_GLOCK(); - for(tq = VLRU.prev; tq != &VLRU; tq = uq) { - tvc = QTOV(tq); - uq = QPrev(tq); - nodeid = tvc->fid.Fid.Vnode + (tvc->fid.Fid.Volume << 16); - nodeid &= 0x7fffffff; - qprintf("avp 0x%x type %s cnt %d pg %d map %d nodeid %d(0x%x)\n", - tvc, tab_vtypes[((vnode_t *)tvc)->v_type], - ((vnode_t *)tvc)->v_count, - (int) VN_GET_PGCNT((vnode_t *)tvc), - (int)tvc->mapcnt, nodeid, nodeid); - } - AFS_GUNLOCK(); - return 0; + AFS_GLOCK(); + for (tq = VLRU.prev; tq != &VLRU; tq = uq) { + tvc = QTOV(tq); + uq = QPrev(tq); + nodeid = tvc->fid.Fid.Vnode + (tvc->fid.Fid.Volume << 16); + nodeid &= 0x7fffffff; + qprintf("avp 0x%x type %s cnt %d pg %d map %d nodeid %d(0x%x)\n", tvc, + tab_vtypes[((vnode_t *) tvc)->v_type], + ((vnode_t *) tvc)->v_count, + (int)VN_GET_PGCNT((vnode_t *) tvc), (int)tvc->mapcnt, nodeid, + nodeid); + } + AFS_GUNLOCK(); + return 0; } static char *tab_userstates[] = { - "UHasTokens", - "UTokensBad", - "UPrimary", - "UNeedsReset", - "UPAGcounted", - "UNK", + "UHasTokens", + "UTokensBad", + "UPrimary", + "UNeedsReset", + "UPAGcounted", + "UNK", }; static void idbg_pruser(struct unixuser *tu) { - qprintf("@0x%x nxt 0x%x uid %d (0x%x) cell 0x%x vid 0x%x ref %d\n", - tu, tu->next, tu->uid, tu->uid, tu->cell, - tu->vid, tu->refCount); - qprintf("time %d stLen %d stp 0x%x exp 0x%x ", - tu->tokenTime, tu->stLen, tu->stp, tu->exporter); + qprintf("@0x%x nxt 0x%x uid %d (0x%x) cell 0x%x vid 0x%x ref %d\n", tu, + tu->next, tu->uid, tu->uid, tu->cell, tu->vid, tu->refCount); + qprintf("time %d stLen %d stp 0x%x exp 0x%x ", tu->tokenTime, tu->stLen, + tu->stp, tu->exporter); printflags(tu->states, tab_userstates); qprintf("\n"); qprintf("ClearToken: handle 0x%x ViceID 0x%x Btime %d Etime %d\n", - tu->ct.AuthHandle, tu->ct.ViceId, tu->ct.BeginTimestamp, - tu->ct.EndTimestamp); + tu->ct.AuthHandle, tu->ct.ViceId, tu->ct.BeginTimestamp, + tu->ct.EndTimestamp); } extern struct unixuser *afs_users[NUSERS]; int idbg_afsuser(void *x) { - struct unixuser *tu; - int i; - AFS_GLOCK(); + struct unixuser *tu; + int i; + AFS_GLOCK(); - if (x == (void *)-1L) { - for (i = 0; i < NUSERS; i++) - for (tu = afs_users[i]; tu; tu = tu->next) - idbg_pruser(tu); - } else - idbg_pruser((struct unixuser *)x); + if (x == (void *)-1L) { + for (i = 0; i < NUSERS; i++) + for (tu = afs_users[i]; tu; tu = tu->next) + idbg_pruser(tu); + } else + idbg_pruser((struct unixuser *)x); - AFS_GUNLOCK(); - return 0; + AFS_GUNLOCK(); + return 0; } #endif /* AFS_SGI62_ENV */ diff --git a/src/afs/IRIX/osi_inode.c b/src/afs/IRIX/osi_inode.c index 4a04d99f0..45741b2af 100644 --- a/src/afs/IRIX/osi_inode.c +++ b/src/afs/IRIX/osi_inode.c @@ -40,14 +40,15 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_inode.c,v 1.1.1.6 2001/09/11 14:25:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_inode.c,v 1.11 2003/07/15 23:14:23 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/osi_inode.h" -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/osi_inode.h" +#include "afs/afs_stats.h" /* statistics stuff */ #define BAD_IGET -1000 @@ -58,7 +59,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_inode.c,v 1.1.1.6 2001/09/ /* * `INODESPECIAL' type inodes are ones that describe volumes. */ -#define INODESPECIAL 0xffffffff /* ... from ../vol/viceinode.h */ +#define INODESPECIAL 0xffffffff /* ... from ../vol/viceinode.h */ #endif /* * copy disk inode to incore inode and vice-versa @@ -66,82 +67,84 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_inode.c,v 1.1.1.6 2001/09/ void afsdptoip(struct efs_dinode *dp, struct inode *ip) { - struct afsparms *ap; - - ip->i_afs = kmem_alloc(sizeof(struct afsparms), KM_SLEEP); - osi_Assert(ip->i_version == EFS_IVER_AFSSPEC - || ip->i_version == EFS_IVER_AFSINO); - ap = (struct afsparms *)ip->i_afs; - /* vicep1 is VOLid */ - ap->vicep1 = dmag(dp, 0) << 24 | dmag(dp, 1) << 16 | - dmag(dp, 2) << 8 | dmag(dp, 3) << 0; - - if (ip->i_version == EFS_IVER_AFSSPEC) { - ap->vicep3 = dmag(dp, 8); /* Type */ - ap->vicep4 = dmag(dp, 4) << 24 | dmag(dp, 5) << 16 | - dmag(dp, 6) << 8 | dmag(dp, 7) << 0; - - } else { - /* vnode number */ - ap->vicep2 = dmag(dp, 4) << 16 | - dmag(dp, 5) << 8 | dmag(dp, 6) << 0; - /* disk uniqifier */ - ap->vicep3 = dmag(dp, 7) << 16 | - dmag(dp, 8) << 8 | dmag(dp, 9) << 0; - /* data version */ - ap->vicep4 = dmag(dp, 10) << 16 | - dmag(dp, 11) << 8 | (dp)->di_spare; - } + struct afsparms *ap; + + ip->i_afs = kmem_alloc(sizeof(struct afsparms), KM_SLEEP); + osi_Assert(ip->i_version == EFS_IVER_AFSSPEC + || ip->i_version == EFS_IVER_AFSINO); + ap = (struct afsparms *)ip->i_afs; + /* vicep1 is VOLid */ + ap->vicep1 = + dmag(dp, 0) << 24 | dmag(dp, 1) << 16 | dmag(dp, 2) << 8 | dmag(dp, + 3) << + 0; + + if (ip->i_version == EFS_IVER_AFSSPEC) { + ap->vicep3 = dmag(dp, 8); /* Type */ + ap->vicep4 = + dmag(dp, 4) << 24 | dmag(dp, 5) << 16 | dmag(dp, + 6) << 8 | dmag(dp, + 7) << + 0; + + } else { + /* vnode number */ + ap->vicep2 = dmag(dp, 4) << 16 | dmag(dp, 5) << 8 | dmag(dp, 6) << 0; + /* disk uniqifier */ + ap->vicep3 = dmag(dp, 7) << 16 | dmag(dp, 8) << 8 | dmag(dp, 9) << 0; + /* data version */ + ap->vicep4 = dmag(dp, 10) << 16 | dmag(dp, 11) << 8 | (dp)->di_spare; + } } void afsiptodp(struct inode *ip, struct efs_dinode *dp) { - struct afsparms *ap; - - if (ip->i_afs == NULL) - return; - - osi_Assert(ip->i_version == EFS_IVER_AFSSPEC - || ip->i_version == EFS_IVER_AFSINO); - ap = (struct afsparms *)ip->i_afs; - /* vicep1 is VOLid */ - dmag(dp, 0) = ap->vicep1 >> 24; - dmag(dp, 1) = ap->vicep1 >> 16; - dmag(dp, 2) = ap->vicep1 >> 8; - dmag(dp, 3) = ap->vicep1 >> 0; - - if (ip->i_version == EFS_IVER_AFSSPEC) { - /* Type */ - dmag(dp, 8) = ap->vicep3; - /* ParentId */ - dmag(dp, 4) = ap->vicep4 >> 24; - dmag(dp, 5) = ap->vicep4 >> 16; - dmag(dp, 6) = ap->vicep4 >> 8; - dmag(dp, 7) = ap->vicep4 >> 0; - } else { - /* vnode number */ - dmag(dp, 4) = ap->vicep2 >> 16; - dmag(dp, 5) = ap->vicep2 >> 8; - dmag(dp, 6) = ap->vicep2 >> 0; - /* disk uniqifier */ - dmag(dp, 7) = ap->vicep3 >> 16; - dmag(dp, 8) = ap->vicep3 >> 8; - dmag(dp, 9) = ap->vicep3 >> 0; - /* data version */ - dmag(dp, 10) = ap->vicep4 >> 16; - dmag(dp, 11) = ap->vicep4 >> 8; - dp->di_spare = ap->vicep4 >> 0; - } + struct afsparms *ap; + + if (ip->i_afs == NULL) + return; + + osi_Assert(ip->i_version == EFS_IVER_AFSSPEC + || ip->i_version == EFS_IVER_AFSINO); + ap = (struct afsparms *)ip->i_afs; + /* vicep1 is VOLid */ + dmag(dp, 0) = ap->vicep1 >> 24; + dmag(dp, 1) = ap->vicep1 >> 16; + dmag(dp, 2) = ap->vicep1 >> 8; + dmag(dp, 3) = ap->vicep1 >> 0; + + if (ip->i_version == EFS_IVER_AFSSPEC) { + /* Type */ + dmag(dp, 8) = ap->vicep3; + /* ParentId */ + dmag(dp, 4) = ap->vicep4 >> 24; + dmag(dp, 5) = ap->vicep4 >> 16; + dmag(dp, 6) = ap->vicep4 >> 8; + dmag(dp, 7) = ap->vicep4 >> 0; + } else { + /* vnode number */ + dmag(dp, 4) = ap->vicep2 >> 16; + dmag(dp, 5) = ap->vicep2 >> 8; + dmag(dp, 6) = ap->vicep2 >> 0; + /* disk uniqifier */ + dmag(dp, 7) = ap->vicep3 >> 16; + dmag(dp, 8) = ap->vicep3 >> 8; + dmag(dp, 9) = ap->vicep3 >> 0; + /* data version */ + dmag(dp, 10) = ap->vicep4 >> 16; + dmag(dp, 11) = ap->vicep4 >> 8; + dp->di_spare = ap->vicep4 >> 0; + } } void afsidestroy(struct inode *ip) { - if (ip->i_afs) { - kmem_free(ip->i_afs, sizeof(struct afsparms)); - ip->i_afs = NULL; - } + if (ip->i_afs) { + kmem_free(ip->i_afs, sizeof(struct afsparms)); + ip->i_afs = NULL; + } } extern int efs_fstype; @@ -170,8 +173,9 @@ getinode(struct vfs *vfsp, dev_t dev, ino_t inode, struct inode **ipp) return ENOSYS; #endif - if (error = iget((((struct mount *)((vfsp)->vfs_bh.bh_first)->bd_pdata)), - (unsigned int)(inode&0xffffffff), &ip)) { + if (error = + iget((((struct mount *)((vfsp)->vfs_bh.bh_first)->bd_pdata)), + (unsigned int)(inode & 0xffffffff), &ip)) { return error; } *ipp = ip; @@ -197,8 +201,8 @@ dev_t XFS_IGET_DEV; #define SET_XFS_ERROR(POS, DEV, INO) \ XFS_IGET_EPOS = (POS), XFS_IGET_DEV = (DEV), XFS_IGET_INO = (INO) -int xfs_getinode(struct vfs *vfsp, dev_t dev, ino_t inode, - struct xfs_inode **ipp) +int +xfs_getinode(struct vfs *vfsp, dev_t dev, ino_t inode, struct xfs_inode **ipp) { struct xfs_inode *ip; int error; @@ -222,9 +226,9 @@ int xfs_getinode(struct vfs *vfsp, dev_t dev, ino_t inode, #endif if (error = xfs_iget((((struct mount *) - ((vfsp)->vfs_bh.bh_first)->bd_pdata)), - (void*)0, (xfs_ino_t)inode, - XFS_ILOCK_SHARED, &ip, (daddr_t)0)) { + ((vfsp)->vfs_bh.bh_first)->bd_pdata)), (void *)0, + (xfs_ino_t) inode, XFS_ILOCK_SHARED, &ip, + (daddr_t) 0)) { SET_XFS_ERROR(3, vfsp->vfs_dev, inode); return error; } @@ -236,8 +240,9 @@ int xfs_getinode(struct vfs *vfsp, dev_t dev, ino_t inode, /* xfs_igetinode now returns an unlocked inode. This is fine, since we * have a refcount on the holding vnode. */ -int xfs_igetinode(struct vfs *vfsp, dev_t dev, ino_t inode, - struct xfs_inode **ipp) +int +xfs_igetinode(struct vfs *vfsp, dev_t dev, ino_t inode, + struct xfs_inode **ipp) { struct xfs_inode *ip; vnode_t *vp; @@ -275,22 +280,23 @@ int xfs_igetinode(struct vfs *vfsp, dev_t dev, ino_t inode, * ***************************************************************************/ struct icreateargs { - sysarg_t dev; - sysarg_t near_inode; - sysarg_t param1; - sysarg_t param2; - sysarg_t param3; - sysarg_t param4; + sysarg_t dev; + sysarg_t near_inode; + sysarg_t param1; + sysarg_t param2; + sysarg_t param3; + sysarg_t param4; }; /* EFS only fs suite uses this entry point - icreate in afssyscalls.c. */ int -icreate(struct icreateargs *uap, rval_t *rvp) +icreate(struct icreateargs *uap, rval_t * rvp) { #ifdef AFS_SGI_EFS_IOPS_ENV AFS_STATCNT(icreate); - return(afs_syscall_icreate(uap->dev, uap->near_inode, uap->param1, - uap->param2, uap->param3, uap->param4, rvp)); + return (afs_syscall_icreate + (uap->dev, uap->near_inode, uap->param1, uap->param2, uap->param3, + uap->param4, rvp)); #else return ENOSYS; #endif @@ -299,51 +305,51 @@ icreate(struct icreateargs *uap, rval_t *rvp) #ifdef AFS_SGI_EFS_IOPS_ENV int afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp) -afs_uint32 dev, near_inode, param1, param2, param3, param4; -rval_t *rvp; + afs_uint32 dev, near_inode, param1, param2, param3, param4; + rval_t *rvp; { - struct inode *ip, *newip; - struct afsparms *ap; - struct cred cr; - int error; + struct inode *ip, *newip; + struct afsparms *ap; + struct cred cr; + int error; - AFS_STATCNT(afs_syscall_icreate); - if (!afs_suser()) - return EPERM; + AFS_STATCNT(afs_syscall_icreate); + if (!afs_suser()) + return EPERM; - if (error = getinode(0, (dev_t)dev, 2, &ip)) - return error; + if (error = getinode(0, (dev_t) dev, 2, &ip)) + return error; - cr.cr_uid = 0; - cr.cr_gid = -2; - if (error = efs_ialloc(ip, IFREG, 1, NODEV, &newip, &cr)) { - iput(ip); - return error; - } + cr.cr_uid = 0; + cr.cr_gid = -2; + if (error = efs_ialloc(ip, IFREG, 1, NODEV, &newip, &cr)) { iput(ip); - osi_Assert(newip); - newip->i_flags |= IACC|IUPD|ICHG; - - osi_Assert(newip->i_afs == NULL); - newip->i_afs = kmem_alloc(sizeof(struct afsparms), KM_SLEEP); - if (param2 == INODESPECIAL) - newip->i_version = EFS_IVER_AFSSPEC; - else - newip->i_version = EFS_IVER_AFSINO; - ap = (struct afsparms *)newip->i_afs; - ap->vicep1 = param1; /* VOLid */ - ap->vicep2 = param2; /* Vnode # */ - ap->vicep3 = param3; /* SPEC:type INO:vnode uniq */ - ap->vicep4 = param4; /* SPEC:parentId INO:data version */ - rvp->r_val1 = newip->i_number; - iput(newip); - return 0; + return error; + } + iput(ip); + osi_Assert(newip); + newip->i_flags |= IACC | IUPD | ICHG; + + osi_Assert(newip->i_afs == NULL); + newip->i_afs = kmem_alloc(sizeof(struct afsparms), KM_SLEEP); + if (param2 == INODESPECIAL) + newip->i_version = EFS_IVER_AFSSPEC; + else + newip->i_version = EFS_IVER_AFSINO; + ap = (struct afsparms *)newip->i_afs; + ap->vicep1 = param1; /* VOLid */ + ap->vicep2 = param2; /* Vnode # */ + ap->vicep3 = param3; /* SPEC:type INO:vnode uniq */ + ap->vicep4 = param4; /* SPEC:parentId INO:data version */ + rvp->r_val1 = newip->i_number; + iput(newip); + return 0; } #else /* !AFS_SGI_EFS_IOPS_ENV */ int afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp) -afs_uint32 dev, near_inode, param1, param2, param3, param4; -rval_t *rvp; + afs_uint32 dev, near_inode, param1, param2, param3, param4; + rval_t *rvp; { return ENOSYS; } @@ -388,7 +394,7 @@ int afs_vol_create_lock_inited = 0; */ int xfs_icreatename64(struct vfs *vfsp, int datap, int datalen, - afs_inode_params_t params, ino_t *inop) + afs_inode_params_t params, ino_t * inop) { #define AFS_PNAME_SIZE 16 char path[64]; @@ -400,7 +406,7 @@ xfs_icreatename64(struct vfs *vfsp, int datap, int datalen, int code = 0, unused; struct vnode *vp; struct vnode *dvp; - int rw_vno; /* volume ID of parent volume */ + int rw_vno; /* volume ID of parent volume */ int i; int createdDir = 0; size_t junk; @@ -411,7 +417,7 @@ xfs_icreatename64(struct vfs *vfsp, int datap, int datalen, if (datalen >= AFS_PNAME_SIZE) return E2BIG; - AFS_COPYINSTR((char*)datap, path, AFS_PNAME_SIZE-1, &junk, unused); + AFS_COPYINSTR((char *)datap, path, AFS_PNAME_SIZE - 1, &junk, unused); if (*path != '/') { return EINVAL; } @@ -426,14 +432,13 @@ xfs_icreatename64(struct vfs *vfsp, int datap, int datalen, if (params[1] == INODESPECIAL) AFS_LOCK_VOL_CREATE(); - code = gop_lookupname(path, AFS_UIOSYS, FOLLOW, (struct vnode **) 0, &dvp); + code = gop_lookupname(path, AFS_UIOSYS, FOLLOW, NULL, &dvp); if (code == ENOENT) { /* Maybe it's an old directory name format. */ - AFS_COPYINSTR((char*)datap, name, AFS_PNAME_SIZE-1, &junk, unused); + AFS_COPYINSTR((char *)datap, name, AFS_PNAME_SIZE - 1, &junk, unused); strcat(name, "/."); strcat(name, int_to_base64(stmp1, rw_vno)); - code = gop_lookupname(name, AFS_UIOSYS, FOLLOW, (struct vnode **) 0, - &dvp); + code = gop_lookupname(name, AFS_UIOSYS, FOLLOW, NULL, &dvp); if (!code) { /* Use old name format. */ strcpy(path, name); @@ -444,78 +449,78 @@ xfs_icreatename64(struct vfs *vfsp, int datap, int datalen, if (code == ENOENT) { afs_xfs_dattr_t dattr; /* make directory. */ - - code = AFS_VN_OPEN(path, UIO_SYSSPACE, FCREAT|FEXCL, 0700, &dvp, - CRMKDIR); + + code = + AFS_VN_OPEN(path, UIO_SYSSPACE, FCREAT | FEXCL, 0700, &dvp, + CRMKDIR); if (code) { if (code == EEXIST) { /* someone beat us to it? */ - code = gop_lookupname(path, AFS_UIOSYS, 0, (struct vnode **) 0, - &dvp); + code = gop_lookupname(path, AFS_UIOSYS, 0, NULL, &dvp); } if (code) { AFS_UNLOCK_VOL_CREATE(); return code; } - } - else + } else createdDir = 1; - memset((char*)&dattr, 0, sizeof(dattr)); + memset((char *)&dattr, 0, sizeof(dattr)); dattr.atd_version = AFS_XFS_ATD_VERS; dattr.atd_volume = rw_vno; - AFS_VOP_ATTR_SET(dvp, AFS_XFS_DATTR, (char*)&dattr, - SIZEOF_XFS_DATTR_T, - ATTR_ROOT|ATTR_CREATE, OSI_GET_CURRENT_CRED(), code); + AFS_VOP_ATTR_SET(dvp, AFS_XFS_DATTR, (char *)&dattr, + SIZEOF_XFS_DATTR_T, ATTR_ROOT | ATTR_CREATE, + OSI_GET_CURRENT_CRED(), code); if (code) { VN_RELE(dvp); if (createdDir) - (void) vn_remove(path, UIO_SYSSPACE, RMDIRECTORY); + (void)vn_remove(path, UIO_SYSSPACE, RMDIRECTORY); AFS_UNLOCK_VOL_CREATE(); return code; } } - vattr.va_mask = AT_FSID|AT_NODEID; /* gets a guick return using FSID*/ + vattr.va_mask = AT_FSID | AT_NODEID; /* gets a guick return using FSID */ AFS_VOP_GETATTR(dvp, &vattr, 0, OSI_GET_CURRENT_CRED(), code); if (code) { VN_RELE(dvp); return code; } - memset((char*)&attrs, 0, sizeof(attrs)); + memset((char *)&attrs, 0, sizeof(attrs)); attrs.at_pino = vattr.va_nodeid; VN_RELE(dvp); - + /* Create the desired file. Use up to ten tries to create a unique name. */ - (void) strcpy(name, path); - (void) strcat(name, "/."); - (void) strcat(name, int_to_base64(stmp2, params[2])); + (void)strcpy(name, path); + (void)strcat(name, "/."); + (void)strcat(name, int_to_base64(stmp2, params[2])); s = &name[strlen(name)]; - attrs.at_tag = 0; /* Initial guess at a unique tag. */ - for (i=0; i<10; i++) { - *s = '\0'; - strcat(s, "."); - strcat(s, int_to_base64(stmp1, attrs.at_tag)); - code = AFS_VN_OPEN(name, UIO_SYSSPACE, FCREAT|FEXCL, 0600, &vp, - CRCREAT); + attrs.at_tag = 0; /* Initial guess at a unique tag. */ + for (i = 0; i < 10; i++) { + *s = '\0'; + strcat(s, "."); + strcat(s, int_to_base64(stmp1, attrs.at_tag)); + code = + AFS_VN_OPEN(name, UIO_SYSSPACE, FCREAT | FEXCL, 0600, &vp, + CRCREAT); if (!code || code != EEXIST) break; - attrs.at_tag ++ ; + attrs.at_tag++; } - /* Unlock the creation process since the directory now has a file in it.*/ + /* Unlock the creation process since the directory now has a file in it. */ if (params[1] == INODESPECIAL) AFS_UNLOCK_VOL_CREATE(); - + if (!code) { /* Set attributes. */ - memcpy((char*)attrs.at_param, (char*)params, sizeof(afs_inode_params_t)); + memcpy((char *)attrs.at_param, (char *)params, + sizeof(afs_inode_params_t)); attrs.at_attr_version = AFS_XFS_ATTR_VERS; attrs.at_name_version = name_version; - AFS_VOP_ATTR_SET(vp, AFS_XFS_ATTR, (char*)&attrs, - SIZEOF_XFS_ATTR_T, - ATTR_ROOT|ATTR_CREATE, OSI_GET_CURRENT_CRED(), + AFS_VOP_ATTR_SET(vp, AFS_XFS_ATTR, (char *)&attrs, SIZEOF_XFS_ATTR_T, + ATTR_ROOT | ATTR_CREATE, OSI_GET_CURRENT_CRED(), code); if (!code) { vattr.va_mode = 1; @@ -535,12 +540,12 @@ xfs_icreatename64(struct vfs *vfsp, int datap, int datalen, if (code) { /* remove partially created file. */ - (void) vn_remove(name, UIO_SYSSPACE, RMFILE); - + (void)vn_remove(name, UIO_SYSSPACE, RMFILE); + /* and directory if volume special file. */ if (createdDir) { AFS_LOCK_VOL_CREATE(); - (void) vn_remove(path, UIO_SYSSPACE, RMDIRECTORY); + (void)vn_remove(path, UIO_SYSSPACE, RMDIRECTORY); AFS_UNLOCK_VOL_CREATE(); } } @@ -574,24 +579,25 @@ afs_syscall_icreatename64(int dev, int datap, int datalen, int paramp, return ENXIO; } - AFS_COPYIN((char*)paramp, (char*)param, sizeof(afs_inode_params_t), code); + AFS_COPYIN((char *)paramp, (char *)param, sizeof(afs_inode_params_t), + code); if (vfsp->vfs_fstype == xfs_fstype) { - code = xfs_icreatename64(vfsp, datap, datalen, param, &ino); + code = xfs_icreatename64(vfsp, datap, datalen, param, &ino); if (code) return code; else { - AFS_COPYOUT((char*)&ino, (char*)inop, sizeof(ino_t), code); + AFS_COPYOUT((char *)&ino, (char *)inop, sizeof(ino_t), code); return code; } - } - else if (vfsp->vfs_fstype == efs_fstype) { - code = afs_syscall_icreate(dev, 0, param[0], param[1], param[2], - param[3], &rval); + } else if (vfsp->vfs_fstype == efs_fstype) { + code = + afs_syscall_icreate(dev, 0, param[0], param[1], param[2], + param[3], &rval); if (code) return code; else { - ino = (ino_t)rval.r_val1; - AFS_COPYOUT((char*)&ino, (char*)inop, sizeof(ino_t), code); + ino = (ino_t) rval.r_val1; + AFS_COPYOUT((char *)&ino, (char *)inop, sizeof(ino_t), code); return code; } } @@ -608,69 +614,66 @@ afs_syscall_icreatename64(int dev, int datap, int datalen, int paramp, * still in use. */ struct iopenargs { - sysarg_t dev; - sysarg_t inode; - sysarg_t usrmod; + sysarg_t dev; + sysarg_t inode; + sysarg_t usrmod; }; #ifdef AFS_SGI_XFS_IOPS_ENV struct iopenargs64 { - sysarg_t dev; - sysarg_t inode_hi; - sysarg_t inode_lo; - sysarg_t usrmod; + sysarg_t dev; + sysarg_t inode_hi; + sysarg_t inode_lo; + sysarg_t usrmod; }; #ifdef AFS_SGI65_ENV int -afs_syscall_iopen(int dev, ino_t inode, int usrmod, rval_t *rvp) +afs_syscall_iopen(int dev, ino_t inode, int usrmod, rval_t * rvp) { - struct file *fp; - int fd; - int error; - struct vfs* vfsp; - struct vnode *vp; + struct file *fp; + int fd; + int error; + struct vfs *vfsp; + struct vnode *vp; - AFS_STATCNT(afs_syscall_iopen); - if (!afs_suser()) - return EPERM; - vfsp = vfs_devsearch(dev, xfs_fstype); - if (!vfsp) - vfsp = vfs_devsearch(dev, efs_fstype); - if (!vfsp) - return ENXIO; + AFS_STATCNT(afs_syscall_iopen); + if (!afs_suser()) + return EPERM; + vfsp = vfs_devsearch(dev, xfs_fstype); + if (!vfsp) + vfsp = vfs_devsearch(dev, efs_fstype); + if (!vfsp) + return ENXIO; #ifdef AFS_SGI_EFS_IOPS_ENV - if (vfsp->vfs_fstype == efs_fstype) { - struct inode *ip; - if (error = igetinode(vfsp, (dev_t)dev, inode, &ip)) - return error; - vp = EFS_ITOV(ip); - if (error = vfile_alloc((usrmod+1) & (FMASK), &fp, &fd)) { - iput(ip); - return error; - } - iunlock(ip); + if (vfsp->vfs_fstype == efs_fstype) { + struct inode *ip; + if (error = igetinode(vfsp, (dev_t) dev, inode, &ip)) + return error; + vp = EFS_ITOV(ip); + if (error = vfile_alloc((usrmod + 1) & (FMASK), &fp, &fd)) { + iput(ip); + return error; } - else + iunlock(ip); + } else #endif /* AFS_SGI_EFS_IOPS_ENV */ - if (vfsp->vfs_fstype == xfs_fstype) { - struct xfs_inode *xip; - if (error = xfs_igetinode(vfsp, (dev_t)dev, inode, &xip)) - return error; - vp = XFS_ITOV(xip); - if (error = vfile_alloc((usrmod+1) & (FMASK), &fp, &fd)) { - VN_RELE(vp); - return error; - } - } - else { - osi_Panic("afs_syscall_iopen: bad fstype = %d\n", - vfsp->vfs_fstype); - } - vfile_ready(fp, vp); - rvp->r_val1 = fd; - return 0; + if (vfsp->vfs_fstype == xfs_fstype) { + struct xfs_inode *xip; + if (error = xfs_igetinode(vfsp, (dev_t) dev, inode, &xip)) + return error; + vp = XFS_ITOV(xip); + if (error = vfile_alloc((usrmod + 1) & (FMASK), &fp, &fd)) { + VN_RELE(vp); + return error; + } + } else { + osi_Panic("afs_syscall_iopen: bad fstype = %d\n", vfsp->vfs_fstype); + } + vfile_ready(fp, vp); + rvp->r_val1 = fd; + return 0; } #else /* afs_syscall_iopen @@ -678,67 +681,64 @@ afs_syscall_iopen(int dev, ino_t inode, int usrmod, rval_t *rvp) * 64 bit inode number. */ int -afs_syscall_iopen(int dev, ino_t inode, int usrmod, rval_t *rvp) +afs_syscall_iopen(int dev, ino_t inode, int usrmod, rval_t * rvp) { - struct file *fp; - int fd; - int error; - struct vfs* vfsp; - - AFS_STATCNT(afs_syscall_iopen); - if (!afs_suser()) - return EPERM; - vfsp = vfs_devsearch(dev); - if (!vfsp) { - return ENXIO; - } + struct file *fp; + int fd; + int error; + struct vfs *vfsp; - if (vfsp->vfs_fstype == xfs_fstype) { - struct xfs_inode *xip; - struct vnode *vp; - if (error = xfs_igetinode(vfsp, (dev_t)dev, inode, &xip)) - return error; - vp = XFS_ITOV(xip); - if (error = falloc(vp, (usrmod+1) & (FMASK), &fp, &fd)) { - VN_RELE(vp); - return error; - } - } - else if (vfsp->vfs_fstype == efs_fstype) { - struct inode *ip; - if (error = igetinode(vfsp, (dev_t)dev, inode, &ip)) - return error; - if (error = falloc(EFS_ITOV(ip), (usrmod+1) & (FMASK), &fp, &fd)) { - iput(ip); - return error; - } - iunlock(ip); + AFS_STATCNT(afs_syscall_iopen); + if (!afs_suser()) + return EPERM; + vfsp = vfs_devsearch(dev); + if (!vfsp) { + return ENXIO; + } + + if (vfsp->vfs_fstype == xfs_fstype) { + struct xfs_inode *xip; + struct vnode *vp; + if (error = xfs_igetinode(vfsp, (dev_t) dev, inode, &xip)) + return error; + vp = XFS_ITOV(xip); + if (error = falloc(vp, (usrmod + 1) & (FMASK), &fp, &fd)) { + VN_RELE(vp); + return error; } - else { - osi_Panic("afs_syscall_iopen: bad fstype = %d\n", - vfsp->vfs_fstype); + } else if (vfsp->vfs_fstype == efs_fstype) { + struct inode *ip; + if (error = igetinode(vfsp, (dev_t) dev, inode, &ip)) + return error; + if (error = falloc(EFS_ITOV(ip), (usrmod + 1) & (FMASK), &fp, &fd)) { + iput(ip); + return error; } - fready(fp); - rvp->r_val1 = fd; - return 0; + iunlock(ip); + } else { + osi_Panic("afs_syscall_iopen: bad fstype = %d\n", vfsp->vfs_fstype); + } + fready(fp); + rvp->r_val1 = fd; + return 0; } #endif /* AFS_SGI65_ENV */ int -iopen(struct iopenargs *uap, rval_t *rvp) +iopen(struct iopenargs *uap, rval_t * rvp) { - AFS_STATCNT(iopen); - return (afs_syscall_iopen(uap->dev, (ino_t)uap->inode, uap->usrmod, - rvp)); + AFS_STATCNT(iopen); + return (afs_syscall_iopen + (uap->dev, (ino_t) uap->inode, uap->usrmod, rvp)); } int -iopen64(struct iopenargs64 *uap, rval_t *rvp) +iopen64(struct iopenargs64 *uap, rval_t * rvp) { - AFS_STATCNT(iopen); - return (afs_syscall_iopen(uap->dev, - (ino_t)((uap->inode_hi<<32) | uap->inode_lo), - uap->usrmod, rvp)); + AFS_STATCNT(iopen); + return (afs_syscall_iopen + (uap->dev, (ino_t) ((uap->inode_hi << 32) | uap->inode_lo), + uap->usrmod, rvp)); } #else /* AFS_SGI_XFS_IOPS_ENV */ @@ -747,37 +747,37 @@ iopen64(struct iopenargs64 *uap, rval_t *rvp) * Original EFS only 32 bit iopen call. */ int -iopen(struct iopenargs *uap, rval_t *rvp) +iopen(struct iopenargs *uap, rval_t * rvp) { - AFS_STATCNT(iopen); - return (afs_syscall_iopen(uap->dev, uap->inode, uap->usrmod, rvp)); + AFS_STATCNT(iopen); + return (afs_syscall_iopen(uap->dev, uap->inode, uap->usrmod, rvp)); } int afs_syscall_iopen(dev, inode, usrmod, rvp) -int dev, inode, usrmod; -rval_t *rvp; + int dev, inode, usrmod; + rval_t *rvp; { - struct file *fp; - struct inode *ip; - int fd; - int error; - - AFS_STATCNT(afs_syscall_iopen); - if (!afs_suser()) - return EPERM; - if (error = igetinode(0, (dev_t)dev, inode, &ip)) - return error; - if (error = falloc(EFS_ITOV(ip), (usrmod+1) & (FMASK), &fp, &fd)) { - iput(ip); - return error; - } - iunlock(ip); - rvp->r_val1 = fd; + struct file *fp; + struct inode *ip; + int fd; + int error; + + AFS_STATCNT(afs_syscall_iopen); + if (!afs_suser()) + return EPERM; + if (error = igetinode(0, (dev_t) dev, inode, &ip)) + return error; + if (error = falloc(EFS_ITOV(ip), (usrmod + 1) & (FMASK), &fp, &fd)) { + iput(ip); + return error; + } + iunlock(ip); + rvp->r_val1 = fd; #ifdef AFS_SGI53_ENV - fready(fp); + fready(fp); #endif - return 0; + return 0; } #endif /* AFS_SGI_XFS_IOPS_ENV */ @@ -793,16 +793,17 @@ rval_t *rvp; * * XFS/EFS iinc/idec code for EFS. Uses 32 bit inode numbers. */ -static int efs_iincdec(vfsp, inode, inode_p1, amount) -struct vfs *vfsp; -int inode, inode_p1, amount; +static int +efs_iincdec(vfsp, inode, inode_p1, amount) + struct vfs *vfsp; + int inode, inode_p1, amount; { struct inode *ip; int error; if (error = igetinode(vfsp, NULL, inode, &ip)) return error; - + if (!IS_VICEMAGIC(ip)) error = EPERM; else if (((struct afsparms *)ip->i_afs)->vicep1 != inode_p1) @@ -826,8 +827,8 @@ int inode, inode_p1, amount; * * XFS/EFS iinc/idec code for EFS. Uses 64 bit inode numbers. */ -static int xfs_iincdec64(struct vfs *vfsp, ino_t inode, int inode_p1, - int amount) +static int +xfs_iincdec64(struct vfs *vfsp, ino_t inode, int inode_p1, int amount) { vnode_t *vp; xfs_inode_t *ip; @@ -838,24 +839,25 @@ static int xfs_iincdec64(struct vfs *vfsp, ino_t inode, int inode_p1, struct vattr vattr; int nlink; int vol; - - code = xfs_iget((((struct mount *)((vfsp)->vfs_bh.bh_first)->bd_pdata)), - (void*)0, (xfs_ino_t)inode, XFS_ILOCK_SHARED, &ip, - (daddr_t)0); + + code = + xfs_iget((((struct mount *)((vfsp)->vfs_bh.bh_first)->bd_pdata)), + (void *)0, (xfs_ino_t) inode, XFS_ILOCK_SHARED, &ip, + (daddr_t) 0); if (code) return code; vp = XFS_ITOV(ip); xfs_iunlock(ip, XFS_ILOCK_SHARED); - + vattr.va_mask = AT_GID | AT_UID | AT_MODE; AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code); - if (code) + if (code) code = EPERM; if (!code && (vattr.va_gid != XFS_VICEMAGIC)) code = EPERM; - + if (!code && (AFS_XFS_VNO_CLIP(inode_p1) != vattr.va_uid)) code = ENXIO; @@ -876,16 +878,15 @@ static int xfs_iincdec64(struct vfs *vfsp, ino_t inode, int inode_p1, AFS_VOP_SETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code); VN_RELE(vp); return code; - } - else { + } else { char path[64]; b64_string_t stmp1, stmp2; vnode_t *dvp; xfs_inode_t *ip; - + length = SIZEOF_XFS_ATTR_T; - AFS_VOP_ATTR_GET(vp, AFS_XFS_ATTR, (char*)&attrs, &length, - ATTR_ROOT, OSI_GET_CURRENT_CRED(), code); + AFS_VOP_ATTR_GET(vp, AFS_XFS_ATTR, (char *)&attrs, &length, ATTR_ROOT, + OSI_GET_CURRENT_CRED(), code); VN_RELE(vp); if (!code) { if (length != SIZEOF_XFS_ATTR_T @@ -905,7 +906,7 @@ static int xfs_iincdec64(struct vfs *vfsp, ino_t inode, int inode_p1, /* Verify directory attributes. */ length = SIZEOF_XFS_DATTR_T; - AFS_VOP_ATTR_GET(dvp, AFS_XFS_DATTR , (char*)&dattr, &length, + AFS_VOP_ATTR_GET(dvp, AFS_XFS_DATTR, (char *)&dattr, &length, ATTR_ROOT, OSI_GET_CURRENT_CRED(), code); if (!code) { if (length != SIZEOF_XFS_DATTR_T @@ -921,35 +922,34 @@ static int xfs_iincdec64(struct vfs *vfsp, ino_t inode, int inode_p1, strcat(path, int_to_base64(stmp1, attrs.at_param[2])); strcat(path, "."); strcat(path, int_to_base64(stmp1, attrs.at_tag)); - + AFS_VOP_REMOVE(dvp, path, OSI_GET_CURRENT_CRED(), code); - + if (!code) { int code2; vattr.va_mask = AT_NLINK; - AFS_VOP_GETATTR(dvp, &vattr, 0, OSI_GET_CURRENT_CRED(), - code2); + AFS_VOP_GETATTR(dvp, &vattr, 0, OSI_GET_CURRENT_CRED(), code2); if (!code2) { if (vattr.va_nlink == 2) { - vnode_t *ddvp; /* parent of volume directory. */ + vnode_t *ddvp; /* parent of volume directory. */ /* Try to remove the directory if this is a volume * special file. It's ok to fail. */ - AFS_VOP_LOOKUP(dvp, "..", &ddvp, - (struct pathname *)NULL, + AFS_VOP_LOOKUP(dvp, "..", &ddvp, (struct pathname *)NULL, 0, OSI_GET_CURRENT_RDIR(), OSI_GET_CURRENT_CRED(), code2); if (!code2) { VN_RELE(dvp); - dvp = (vnode_t*)0; + dvp = (vnode_t *) 0; strcpy(path, "."); if (attrs.at_name_version == AFS_XFS_NAME_VERS2) strcpy(path, AFS_INODE_DIR_NAME); - else + else strcpy(path, "."); int_to_base64(stmp1, - (attrs.at_param[1] == INODESPECIAL) ? - attrs.at_param[3] : attrs.at_param[0]); + (attrs.at_param[1] == + INODESPECIAL) ? attrs. + at_param[3] : attrs.at_param[0]); strcat(path, stmp1); AFS_LOCK_VOL_CREATE(); AFS_VOP_RMDIR(ddvp, path, OSI_GET_CURRENT_CDIR(), @@ -1013,17 +1013,22 @@ afs_syscall_iinc64(int dev, int inode_hi, int inode_lo, int inode_p1) struct iincargs { - sysarg_t dev; - sysarg_t inode; - sysarg_t inode_p1; + sysarg_t dev; + sysarg_t inode; + sysarg_t inode_p1; }; #ifdef AFS_SGI65_ENV -int iinc(struct iincargs *uap, rval_t *rvp) { +int +iinc(struct iincargs *uap, rval_t * rvp) +{ AFS_STATCNT(iinc); return ENOTSUP; } -int idec(struct iincargs *uap, rval_t *rvp) { + +int +idec(struct iincargs *uap, rval_t * rvp) +{ AFS_STATCNT(idec); return ENOTSUP; } @@ -1035,10 +1040,10 @@ int idec(struct iincargs *uap, rval_t *rvp) { */ int iincdec(dev, inode, inode_p1, amount) -int dev, inode, inode_p1, amount; + int dev, inode, inode_p1, amount; { struct vfs *vfsp; - + if (!afs_suser()) return EPERM; vfsp = vfs_devsearch(dev); @@ -1050,14 +1055,17 @@ int dev, inode, inode_p1, amount; return efs_iincdec(vfsp, inode, inode_p1, amount); } + int -iinc(struct iincargs *uap, rval_t *rvp) { +iinc(struct iincargs *uap, rval_t * rvp) +{ AFS_STATCNT(iinc); return (iincdec(uap->dev, uap->inode, uap->inode_p1, 1)); } int -idec(struct iincargs *uap, rval_t *rvp) { +idec(struct iincargs *uap, rval_t * rvp) +{ AFS_STATCNT(idec); return (iincdec(uap->dev, uap->inode, uap->inode_p1, -1)); } @@ -1070,48 +1078,50 @@ idec(struct iincargs *uap, rval_t *rvp) { */ int afs_syscall_iincdec(dev, inode, inode_p1, amount) -int dev, inode, inode_p1, amount; + int dev, inode, inode_p1, amount; { - struct inode *ip; - int error = 0; + struct inode *ip; + int error = 0; - if (!afs_suser()) - return EPERM; - if (error = igetinode(0, (dev_t)dev, inode, &ip)) - return error; + if (!afs_suser()) + return EPERM; + if (error = igetinode(0, (dev_t) dev, inode, &ip)) + return error; - if (!IS_VICEMAGIC(ip)) - error = EPERM; - else if (((struct afsparms *)ip->i_afs)->vicep1 != inode_p1) - error = ENXIO; - else { - ip->i_nlink += amount; - osi_Assert(ip->i_nlink >= 0); - if (ip->i_nlink == 0) { - CLEAR_VICEMAGIC(ip); - afsidestroy(ip); - } - ip->i_flags |= ICHG; + if (!IS_VICEMAGIC(ip)) + error = EPERM; + else if (((struct afsparms *)ip->i_afs)->vicep1 != inode_p1) + error = ENXIO; + else { + ip->i_nlink += amount; + osi_Assert(ip->i_nlink >= 0); + if (ip->i_nlink == 0) { + CLEAR_VICEMAGIC(ip); + afsidestroy(ip); } - /* XXX sync write?? */ - iput(ip); - return error; + ip->i_flags |= ICHG; + } + /* XXX sync write?? */ + iput(ip); + return error; } struct iincargs { - sysarg_t dev; - sysarg_t inode; - sysarg_t inode_p1; + sysarg_t dev; + sysarg_t inode; + sysarg_t inode_p1; }; int -iinc(struct iincargs *uap, rval_t *rvp) { +iinc(struct iincargs *uap, rval_t * rvp) +{ AFS_STATCNT(iinc); return (afs_syscall_iincdec(uap->dev, uap->inode, uap->inode_p1, 1)); } int -idec(struct iincargs *uap, rval_t *rvp) { +idec(struct iincargs *uap, rval_t * rvp) +{ AFS_STATCNT(idec); return (afs_syscall_iincdec(uap->dev, uap->inode, uap->inode_p1, -1)); } @@ -1122,8 +1132,8 @@ idec(struct iincargs *uap, rval_t *rvp) { * Gathers up all required info for ListViceInodes in one system call. */ int -afs_syscall_ilistinode64(int dev, int inode_hi, int inode_lo, - int datap, int datalenp) +afs_syscall_ilistinode64(int dev, int inode_hi, int inode_lo, int datap, + int datalenp) { int code = 0; ino_t inode; @@ -1151,40 +1161,42 @@ afs_syscall_ilistinode64(int dev, int inode_hi, int inode_lo, return ENOSYS; #endif - AFS_COPYIN((char*)datalenp, &idatalen, sizeof(int), code); + AFS_COPYIN((char *)datalenp, &idatalen, sizeof(int), code); if (idatalen < sizeof(i_list_inode_t)) { idatalen = sizeof(i_list_inode_t); - AFS_COPYOUT((char*)datalenp, (char*)&idatalen, sizeof(int), code); + AFS_COPYOUT((char *)datalenp, (char *)&idatalen, sizeof(int), code); return E2BIG; } idatalen = sizeof(i_list_inode_t); - AFS_COPYOUT((char*)datalenp, (char*)&idatalen, sizeof(int), code); + AFS_COPYOUT((char *)datalenp, (char *)&idatalen, sizeof(int), code); - AFS_COPYIN((char*)datap, (char*)&data, sizeof(i_list_inode_t), code); + AFS_COPYIN((char *)datap, (char *)&data, sizeof(i_list_inode_t), code); if (data.ili_version != AFS_XFS_ILI_VERSION) { data.ili_version = AFS_XFS_ILI_VERSION; - AFS_COPYOUT((char*)&data, (char*)datap, sizeof(i_list_inode_t), code); + AFS_COPYOUT((char *)&data, (char *)datap, sizeof(i_list_inode_t), + code); return EINVAL; } - - + + inode = inode_hi; inode <<= 32; inode |= inode_lo; - code = xfs_iget((((struct mount *)((vfsp)->vfs_bh.bh_first)->bd_pdata)), - (void*)0, (xfs_ino_t)inode, - XFS_ILOCK_SHARED, &ip, (daddr_t)0); + code = + xfs_iget((((struct mount *)((vfsp)->vfs_bh.bh_first)->bd_pdata)), + (void *)0, (xfs_ino_t) inode, XFS_ILOCK_SHARED, &ip, + (daddr_t) 0); if (code) return code; - + vp = XFS_ITOV(ip); xfs_iunlock(ip, XFS_ILOCK_SHARED); - + length = SIZEOF_XFS_ATTR_T; - AFS_VOP_ATTR_GET(vp, AFS_XFS_ATTR, (char*)&attrs, &length, - ATTR_ROOT, OSI_GET_CURRENT_CRED(), code); - if (code) { + AFS_VOP_ATTR_GET(vp, AFS_XFS_ATTR, (char *)&attrs, &length, ATTR_ROOT, + OSI_GET_CURRENT_CRED(), code); + if (code) { code = EPERM; } @@ -1192,25 +1204,26 @@ afs_syscall_ilistinode64(int dev, int inode_hi, int inode_lo, if (attrs.at_attr_version != AFS_XFS_ATTR_VERS) code = EINVAL; } - + if (!code) { vattr.va_mask = AT_STAT; AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code); } - + if (!code) { - memset((char*)&data, 0, sizeof(data)); + memset((char *)&data, 0, sizeof(data)); data.ili_info.inodeNumber = inode; data.ili_info.byteCount = vattr.va_size; data.ili_info.linkCount = (vattr.va_mode & AFS_XFS_MODE_LINK_MASK); - memcpy((char*)data.ili_info.param, (char*)attrs.at_param, sizeof(data.ili_info.param)); + memcpy((char *)data.ili_info.param, (char *)attrs.at_param, + sizeof(data.ili_info.param)); data.ili_attr_version = attrs.at_attr_version; data.ili_name_version = attrs.at_name_version; data.ili_tag = attrs.at_tag; data.ili_pino = attrs.at_pino; data.ili_vno = vattr.va_uid; data.ili_magic = vattr.va_gid; - AFS_COPYOUT((char*)&data, (char*)datap, sizeof(data), code); + AFS_COPYOUT((char *)&data, (char *)datap, sizeof(data), code); } VN_RELE(vp); return code; diff --git a/src/afs/IRIX/osi_inode.h b/src/afs/IRIX/osi_inode.h index 56a533647..0340062f2 100644 --- a/src/afs/IRIX/osi_inode.h +++ b/src/afs/IRIX/osi_inode.h @@ -47,11 +47,11 @@ /* we hang this struct off of the incore inode */ struct afsparms { - afs_int32 vicep1; - afs_int32 vicep2; - afs_int32 vicep3; - afs_int32 vicep4; - }; + afs_int32 vicep1; + afs_int32 vicep2; + afs_int32 vicep3; + afs_int32 vicep4; +}; #define dmag(p,n) ((p)->di_u.di_extents[n].ex_magic) diff --git a/src/afs/IRIX/osi_machdep.h b/src/afs/IRIX/osi_machdep.h index 241f92515..fb6b59876 100644 --- a/src/afs/IRIX/osi_machdep.h +++ b/src/afs/IRIX/osi_machdep.h @@ -26,7 +26,8 @@ extern kmutex_t afs_global_lock; extern time_t time; #define osi_Time() (time) -#define AFS_UCRED ucred +/* This gets redefined from ucred to cred in osi_vfs.h, just do it right */ +#define AFS_UCRED cred #define osi_vnhold(avc, r) do { VN_HOLD(AFSTOV(avc)); } while(0) @@ -129,7 +130,7 @@ extern flid_t osi_flid; #if defined(KERNEL) #if defined(MP) -#define _MP_NETLOCKS /* to get sblock to work right */ +#define _MP_NETLOCKS /* to get sblock to work right */ /* On SGI mutex_owned doesn't work, so simulate this by remembering the owning * thread explicitly. This is only used for debugging so could be disabled for @@ -285,6 +286,8 @@ extern long afs_global_owner; #define OSI_GET_CURRENT_CRED() get_current_cred() #endif /* AFS_SGI64_ENV */ +#define osi_curcred() OSI_GET_CURRENT_CRED() + /* * OSI_SET_CURRENT_CRED */ diff --git a/src/afs/IRIX/osi_misc.c b/src/afs/IRIX/osi_misc.c index 3e5403bdb..fd7f3436a 100644 --- a/src/afs/IRIX/osi_misc.c +++ b/src/afs/IRIX/osi_misc.c @@ -11,14 +11,15 @@ * Implementation of miscellaneous Irix routines. */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_misc.c,v 1.1.1.5 2002/01/22 19:48:10 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_misc.c,v 1.7 2003/07/15 23:14:23 shadow Exp $"); #ifdef AFS_SGI62_ENV -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ @@ -26,7 +27,10 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_misc.c,v 1.1.1.5 2002/01/2 /* * various special purpose routines */ -void afs_mpservice(void *a) {} +void +afs_mpservice(void *a) +{ +} #ifdef AFS_SGI_VNODE_GLUE #include @@ -38,31 +42,32 @@ extern mutex_t afs_init_kern_lock; * Argument: flag * 0 = no numa, 1 = has numa, -1 = test for numa. */ -int afs_init_kernel_config(int flag) +int +afs_init_kernel_config(int flag) { static int afs_kern_inited = 0; int code = 0; - + mutex_enter(&afs_init_kern_lock); if (!afs_kern_inited) { afs_kern_inited = 1; - + if (flag == -1) { inventory_t *pinv; /* test for numa arch. */ /* Determine if thisis a NUMA platform. Currently, this is true * only if it's an IP27 or IP35. */ - pinv = find_inventory((inventory_t*)NULL, INV_PROCESSOR, - INV_CPUBOARD, -1, -1, -1); + pinv = + find_inventory((inventory_t *) NULL, INV_PROCESSOR, + INV_CPUBOARD, -1, -1, -1); if (!pinv) code = ENODEV; - else - afs_is_numa_arch = ((pinv->inv_state == INV_IP27BOARD) || - (pinv->inv_state == INV_IP35BOARD)) - ? 1 : 0; - } - else + else + afs_is_numa_arch = ((pinv->inv_state == INV_IP27BOARD) + || (pinv->inv_state == INV_IP35BOARD)) + ? 1 : 0; + } else afs_is_numa_arch = flag; } mutex_exit(&afs_init_kern_lock); diff --git a/src/afs/IRIX/osi_sleep.c b/src/afs/IRIX/osi_sleep.c index b43def99e..1e8f0a890 100644 --- a/src/afs/IRIX/osi_sleep.c +++ b/src/afs/IRIX/osi_sleep.c @@ -8,38 +8,40 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_sleep.c,v 1.1.1.4 2001/07/14 22:19:42 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_sleep.c,v 1.9 2003/07/15 23:14:23 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok); -void afs_osi_Wakeup(char *event); -void afs_osi_Sleep(char *event); static char waitV; -void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) +void +afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) { AFS_STATCNT(osi_InitWaitHandle); achandle->proc = (caddr_t) 0; } /* cancel osi_Wait */ -void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) { caddr_t proc; AFS_STATCNT(osi_CancelWait); proc = achandle->proc; - if (proc == 0) return; - achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ + if (proc == 0) + return; + achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ afs_osi_Wakeup(&waitV); } @@ -47,13 +49,14 @@ void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) * Waits for data on ahandle, or ams ms later. ahandle may be null. * Returns 0 if timeout and EINTR if signalled. */ -int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) +int +afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) { int code; afs_int32 endTime, tid; AFS_STATCNT(osi_Wait); - endTime = osi_Time() + (ams/1000); + endTime = osi_Time() + (ams / 1000); if (ahandle) ahandle->proc = (caddr_t) curthreadp; do { @@ -61,7 +64,8 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) code = 0; code = osi_TimedSleep(&waitV, ams, aintok); - if (code) break; /* if something happened, quit now */ + if (code) + break; /* if something happened, quit now */ /* if we we're cancelled, quit now */ if (ahandle && (ahandle->proc == (caddr_t) 0)) { /* we've been signalled */ @@ -79,13 +83,13 @@ typedef struct afs_event { char *event; /* lwp event: an address */ int refcount; /* Is it in use? */ int seq; /* Sequence number: this is incremented - by wakeup calls; wait will not return until - it changes */ + * by wakeup calls; wait will not return until + * it changes */ kcondvar_t cond; /* Currently associated condition variable */ } afs_event_t; #define HASHSIZE 128 -afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */ +afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */ #if (_MIPS_SZPTR == 64) #define afs_evhash(event) (afs_uint32) ((((long)event)>>3) & (HASHSIZE-1)); #else @@ -95,7 +99,8 @@ int afs_evhashcnt = 0; /* Get and initialize event structure corresponding to lwp event (i.e. address) * */ -static afs_event_t *afs_getevent(char *event) +static afs_event_t * +afs_getevent(char *event) { afs_event_t *evp, *newp = 0; int hashcode; @@ -113,7 +118,7 @@ static afs_event_t *afs_getevent(char *event) evp = evp->next; } if (!newp) { - newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t)); + newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t)); afs_evhashcnt++; newp->next = afs_evhasht[hashcode]; afs_evhasht[hashcode] = newp; @@ -129,7 +134,8 @@ static afs_event_t *afs_getevent(char *event) #define relevent(evp) ((evp)->refcount--) -void afs_osi_Sleep(char *event) +void +afs_osi_Sleep(void *event) { struct afs_event *evp; int seq; @@ -143,6 +149,13 @@ void afs_osi_Sleep(char *event) relevent(evp); } +int +afs_osi_SleepSig(void *event) +{ + afs_osi_Sleep(event); + return 0; +} + /* osi_TimedSleep * * Arguments: @@ -152,41 +165,47 @@ void afs_osi_Sleep(char *event) * * Returns 0 if timeout and EINTR if signalled. */ -static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) +static int +osi_TimedSleep(char *event, afs_int32 ams, int aintok) { int code = 0; struct afs_event *evp; struct timespec ticks; ticks.tv_sec = ams / 1000; - ticks.tv_nsec = (ams - (ticks.tv_sec * 1000) ) * 1000000; + ticks.tv_nsec = (ams - (ticks.tv_sec * 1000)) * 1000000; evp = afs_getevent(event); AFS_ASSERT_GLOCK(); if (aintok) { - if (sv_timedwait_sig(&evp->cond, AFSD_PRI(), &afs_global_lock, - 0, 0, &ticks, (struct timespec*)0)) + if (sv_timedwait_sig + (&evp->cond, AFSD_PRI(), &afs_global_lock, 0, 0, &ticks, + (struct timespec *)0)) code = EINTR; - AFS_MUTEX_ENTER(&afs_global_lock); + AFS_MUTEX_ENTER(&afs_global_lock); } else { cv_timedwait(&evp->cond, &afs_global_lock, ticks); } - + relevent(evp); return code; } -void afs_osi_Wakeup(char *event) +int +afs_osi_Wakeup(void *event) { + int ret = 1; struct afs_event *evp; evp = afs_getevent(event); if (evp->refcount > 1) { - evp->seq++; + evp->seq++; cv_broadcast(&evp->cond); + ret = 0; } relevent(evp); + return ret; } diff --git a/src/afs/IRIX/osi_vfs.h b/src/afs/IRIX/osi_vfs.h index d0225ed4e..1f2460a8b 100644 --- a/src/afs/IRIX/osi_vfs.h +++ b/src/afs/IRIX/osi_vfs.h @@ -47,8 +47,8 @@ typedef struct xfs_inode xfs_inode_t; #define XFS_ILOCK_SHARED 0x08 struct xfs_trans; struct xfs_mount; -extern int xfs_iget(struct mount *, struct xfs_trans *, xfs_ino_t, - uint, xfs_inode_t **, daddr_t); +extern int xfs_iget(struct mount *, struct xfs_trans *, xfs_ino_t, uint, + xfs_inode_t **, daddr_t); #ifdef AFS_SGI64_ENV #define XFS_ITOV(ip) BHV_TO_VNODE((struct bhv_desc *)(((char*)(ip)) + 6*sizeof(void*))) @@ -63,15 +63,15 @@ extern int xfs_iget(struct mount *, struct xfs_trans *, xfs_ino_t, #define AFS_SGI_EFS_CACHE 0 #define AFS_SGI_XFS_CACHE 1 extern int afs_CacheFSType; -extern vnode_t * (*afs_IGetVnode)(ino_t); +extern vnode_t *(*afs_IGetVnode) (ino_t); extern struct vnodeops *afs_efs_vnodeopsp; extern struct vnodeops *afs_xfs_vnodeopsp; #define AFS_SGI_IGETVNODE(INO) (*afs_IGetVnode)(INO) /* These need to be functions to wrap the vnode op calls. */ -extern ino_t VnodeToIno(vnode_t *vp); -extern dev_t VnodeToDev(vnode_t *vp); -extern off_t VnodeToSize(vnode_t *vp); +extern ino_t VnodeToIno(vnode_t * vp); +extern dev_t VnodeToDev(vnode_t * vp); +extern off_t VnodeToSize(vnode_t * vp); #else /* Just the EFS variants exist for now. */ #define VnodeToIno(vp) ((ino_t)(EFS_VTOI((vp))->i_number)) @@ -241,65 +241,65 @@ extern int afs_is_numa_arch; #ifdef AFS_SGI_VNODE_GLUE extern int afs_is_numa_arch; typedef struct bhv_head1 { - struct bhv_desc *bh_first; /* first behavior in chain */ + struct bhv_desc *bh_first; /* first behavior in chain */ #ifdef notdef - /* This is not present in the non NUMA machines. */ - mrlock_t bh_mrlock; /* lock for ops-in-progress synch. */ + /* This is not present in the non NUMA machines. */ + mrlock_t bh_mrlock; /* lock for ops-in-progress synch. */ #endif } bhv_head1_t; typedef struct vnode1 { - struct vnlist v_list; /* freelist linkage */ - uint v_flag; /* vnode flags (see below) */ - cnt_t v_count; /* reference count */ - u_short v_namecap; /* name cache capability */ - enum vtype v_type; /* vnode type */ - dev_t v_rdev; /* device (VCHR, VBLK) */ - struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */ - struct vfs *v_vfsp; /* ptr to containing VFS */ - struct stdata *v_stream; /* associated stream */ - struct filock *v_filocks; /* ptr to filock list */ - mutex_t *v_filocksem; /* ptr to mutex for list */ - vnumber_t v_number; /* in-core vnode number */ - short v_listid; /* free list id */ - cnt_t v_intpcount; /* interp. refcount for imon */ - bhv_head1_t v_bh; /* behavior head */ + struct vnlist v_list; /* freelist linkage */ + uint v_flag; /* vnode flags (see below) */ + cnt_t v_count; /* reference count */ + u_short v_namecap; /* name cache capability */ + enum vtype v_type; /* vnode type */ + dev_t v_rdev; /* device (VCHR, VBLK) */ + struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */ + struct vfs *v_vfsp; /* ptr to containing VFS */ + struct stdata *v_stream; /* associated stream */ + struct filock *v_filocks; /* ptr to filock list */ + mutex_t *v_filocksem; /* ptr to mutex for list */ + vnumber_t v_number; /* in-core vnode number */ + short v_listid; /* free list id */ + cnt_t v_intpcount; /* interp. refcount for imon */ + bhv_head1_t v_bh; /* behavior head */ - /* - * Used only by global cache. - */ - struct vnode *v_hashp; /* hash list for lookup */ - struct vnode *v_hashn; /* hash list for lookup */ + /* + * Used only by global cache. + */ + struct vnode *v_hashp; /* hash list for lookup */ + struct vnode *v_hashn; /* hash list for lookup */ - /* - * Values manipulated only by VM and - * the page/buffer caches. - */ - struct pregion *v_mreg; /* mapped file region pointer */ - int v_dbuf; /* delwri buffer count */ - pgno_t v_pgcnt; /* pages hashed to vnode */ - struct pfdat *v_dpages; /* delwri pages */ - struct buf *v_buf; /* vnode buffer tree head */ - unsigned int v_bufgen; /* buf list generation number */ - mutex_t v_buf_lock; /* mutex for buffer tree */ + /* + * Values manipulated only by VM and + * the page/buffer caches. + */ + struct pregion *v_mreg; /* mapped file region pointer */ + int v_dbuf; /* delwri buffer count */ + pgno_t v_pgcnt; /* pages hashed to vnode */ + struct pfdat *v_dpages; /* delwri pages */ + struct buf *v_buf; /* vnode buffer tree head */ + unsigned int v_bufgen; /* buf list generation number */ + mutex_t v_buf_lock; /* mutex for buffer tree */ - vnode_pcache_t v_pc; /* Page cache structure. - * per vnode. Refer to - * vnode_pcache.h - * for details. - */ + vnode_pcache_t v_pc; /* Page cache structure. + * per vnode. Refer to + * vnode_pcache.h + * for details. + */ #ifdef VNODE_TRACING - struct ktrace *v_trace; /* trace header structure */ + struct ktrace *v_trace; /* trace header structure */ #endif #ifdef CKPT - ckpt_handle_t v_ckpt; /* ckpt lookup info */ + ckpt_handle_t v_ckpt; /* ckpt lookup info */ #endif } vnode1_t; -extern struct pfdat *vnode_get_dpages(vnode_t*); -extern int vnode_get_dbuf(vnode_t*); -extern pgno_t vnode_get_pgcnt(vnode_t*); -extern struct pregion *vnode_get_mreg(vnode_t*); +extern struct pfdat *vnode_get_dpages(vnode_t *); +extern int vnode_get_dbuf(vnode_t *); +extern pgno_t vnode_get_pgcnt(vnode_t *); +extern struct pregion *vnode_get_mreg(vnode_t *); #define VN_GET_DPAGES(V) (afs_is_numa_arch ? \ ((V)->v_dpages) : \ (((vnode1_t*)(V))->v_dpages)) @@ -351,10 +351,10 @@ extern struct pregion *vnode_get_mreg(vnode_t*); /* * Flock(3) call. (from sys/file.h) */ -#define LOCK_SH 1 /* shared lock */ -#define LOCK_EX 2 /* exclusive lock */ -#define LOCK_NB 4 /* don't block when locking */ -#define LOCK_UN 8 /* unlock */ +#define LOCK_SH 1 /* shared lock */ +#define LOCK_EX 2 /* exclusive lock */ +#define LOCK_NB 4 /* don't block when locking */ +#define LOCK_UN 8 /* unlock */ #endif diff --git a/src/afs/IRIX/osi_vfsops.c b/src/afs/IRIX/osi_vfsops.c index 0b8b596d8..3164d7b92 100644 --- a/src/afs/IRIX/osi_vfsops.c +++ b/src/afs/IRIX/osi_vfsops.c @@ -11,13 +11,14 @@ * osi_vfsops.c for IRIX */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_vfsops.c,v 1.1.1.7 2003/04/13 19:02:45 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_vfsops.c,v 1.13 2003/07/15 23:14:23 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics stuff */ #include "sys/syssgi.h" @@ -33,7 +34,7 @@ mutex_t afs_init_kern_lock; #define SYS_setgroups SGI_SETGROUPS -int (*nfs_rfsdisptab_v2)() = NULL; +int (*nfs_rfsdisptab_v2) () = NULL; int afs_fstype; lock_t afs_rxlock; @@ -41,7 +42,7 @@ lock_t afs_rxlock; #include "sys/mload.h" char *Afs_mversion = M_VERSION; -extern int (*setgroupsp)(int, gid_t *); +extern int (*setgroupsp) (int, gid_t *); extern struct afs_lock afs_xvcache; extern int idbg_afsuser(); extern void afs_mpservice(void *); @@ -55,14 +56,14 @@ extern void afs_mpservice(void *); syscallsw[ABI_IRIX5].sc_sysent[(n)-1000].sy_flags = 0; extern struct vfsops Afs_vfsops, *afs_vfsopsp; extern struct vnodeops Afs_vnodeops, *afs_vnodeopsp; -extern void (*afsidestroyp)(struct inode *); -extern void (*afsdptoipp)(struct efs_dinode *, struct inode *); -extern void (*afsiptodpp)(struct inode *, struct efs_dinode *); +extern void (*afsidestroyp) (struct inode *); +extern void (*afsdptoipp) (struct efs_dinode *, struct inode *); +extern void (*afsiptodpp) (struct inode *, struct efs_dinode *); extern void afsidestroy(struct inode *); extern void afsdptoip(struct efs_dinode *, struct inode *); extern void afsiptodp(struct inode *, struct efs_dinode *); -extern int (*idbg_prafsnodep)(vnode_t *); -extern int (*idbg_afsvfslistp)(void); +extern int (*idbg_prafsnodep) (vnode_t *); +extern int (*idbg_afsvfslistp) (void); extern int idbg_prafsnode(vnode_t *); extern int idbg_afsvfslist(void); @@ -96,18 +97,18 @@ Afs_init(struct vfssw *vswp, int fstype) afsdptoipp = afsdptoip; idbg_prafsnodep = idbg_prafsnode; idbg_afsvfslistp = idbg_afsvfslist; - NewSystemCall (AFS_SYSCALL, Afs_syscall, 6); - NewSystemCall (AFS_PIOCTL, afs_pioctl, 4); - NewSystemCall (AFS_SETPAG, afs_setpag, 0); - NewSystemCall (AFS_IOPEN, iopen, 3); - NewSystemCall (AFS_ICREATE, icreate, 6); - NewSystemCall (AFS_IINC, iinc, 3); - NewSystemCall (AFS_IDEC, idec, 3); + NewSystemCall(AFS_SYSCALL, Afs_syscall, 6); + NewSystemCall(AFS_PIOCTL, afs_pioctl, 4); + NewSystemCall(AFS_SETPAG, afs_setpag, 0); + NewSystemCall(AFS_IOPEN, iopen, 3); + NewSystemCall(AFS_ICREATE, icreate, 6); + NewSystemCall(AFS_IINC, iinc, 3); + NewSystemCall(AFS_IDEC, idec, 3); #ifdef AFS_SGI_XFS_IOPS_ENV - NewSystemCall (AFS_IOPEN64, iopen64, 4); + NewSystemCall(AFS_IOPEN64, iopen64, 4); #else - NewSystemCall (AFS_IREAD, iread, 6); - NewSystemCall (AFS_IWRITE, iwrite, 6); + NewSystemCall(AFS_IREAD, iread, 6); + NewSystemCall(AFS_IWRITE, iwrite, 6); #endif /* last replace these */ @@ -124,7 +125,7 @@ extern int afs_sync(OSI_VFS_DECL(afsp), int flags, struct cred *cr); #else extern int afs_sync(OSI_VFS_DECL(afsp), short flags, struct cred *cr); #endif -extern int afs_vget(OSI_VFS_DECL(afsp), vnode_t **vpp, struct fid *afidp); +extern int afs_vget(OSI_VFS_DECL(afsp), vnode_t ** vpp, struct fid *afidp); #ifdef MP struct vfsops afs_lockedvfsops = #else @@ -140,8 +141,8 @@ struct vfsops Afs_vfsops = #endif afs_mount, #ifdef AFS_SGI64_ENV - fs_nosys, /* rootinit */ - fs_nosys, /* mntupdate */ + fs_nosys, /* rootinit */ + fs_nosys, /* mntupdate */ fs_dounmount, #endif afs_unmount, @@ -149,25 +150,25 @@ struct vfsops Afs_vfsops = afs_statfs, afs_sync, afs_vget, - fs_nosys, /* mountroot */ + fs_nosys, /* mountroot */ #ifdef AFS_SGI65_ENV - fs_nosys, /* realvfsops */ - fs_import, /* import */ - fs_nosys, /* quotactl */ + fs_nosys, /* realvfsops */ + fs_import, /* import */ + fs_nosys, /* quotactl */ #else - fs_nosys, /* swapvp */ + fs_nosys, /* swapvp */ #endif }; -extern struct afs_q VLRU; /*vcache LRU*/ +extern struct afs_q VLRU; /*vcache LRU */ #ifdef AFS_SGI64_ENV static bhv_desc_t afs_vfs_bhv; #endif -afs_mount(struct vfs *afsp, vnode_t *mvp, struct mounta *uap, +afs_mount(struct vfs *afsp, vnode_t * mvp, struct mounta *uap, #ifdef AFS_SGI65_ENV char *attrs, #endif - cred_t *cr) + cred_t * cr) { AFS_STATCNT(afs_mount); @@ -177,21 +178,21 @@ afs_mount(struct vfs *afsp, vnode_t *mvp, struct mounta *uap, if (mvp->v_type != VDIR) return ENOTDIR; - if (afs_globalVFS) { /* Don't allow remounts. */ + if (afs_globalVFS) { /* Don't allow remounts. */ return EBUSY; } afs_globalVFS = afsp; afsp->vfs_bsize = 8192; - afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ - afsp->vfs_fsid.val[1] = afs_fstype; + afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ + afsp->vfs_fsid.val[1] = afs_fstype; #ifdef AFS_SGI64_ENV vfs_insertbhv(afsp, &afs_vfs_bhv, &Afs_vfsops, &afs_vfs_bhv); #else afsp->vfs_data = NULL; #endif afsp->vfs_fstype = afs_fstype; - afsp->vfs_dev = 0xbabebabe; /* XXX this should be unique */ + afsp->vfs_dev = 0xbabebabe; /* XXX this should be unique */ #ifndef AFS_NONFSTRANS if (nfs_rfsdisptab_v2) @@ -202,9 +203,9 @@ afs_mount(struct vfs *afsp, vnode_t *mvp, struct mounta *uap, } afs_unmount(OSI_VFS_ARG(afsp), flags, cr) -OSI_VFS_DECL(afsp); -int flags; -cred_t *cr; + OSI_VFS_DECL(afsp); + int flags; + cred_t *cr; { extern int afs_afs_cold_shutdown; struct vcache *tvc; @@ -214,7 +215,7 @@ cred_t *cr; int error, fv_slept; OSI_VFS_CONVERT(afsp) - AFS_STATCNT(afs_unmount); + AFS_STATCNT(afs_unmount); if (!suser()) return EPERM; @@ -223,19 +224,19 @@ cred_t *cr; * flush all pages from inactive vnodes - return * EBUSY if any still in use */ - ObtainWriteLock(&afs_xvcache,172); + ObtainWriteLock(&afs_xvcache, 172); for (tq = VLRU.prev; tq != &VLRU; tq = uq) { tvc = QTOV(tq); uq = QPrev(tq); - vp = (vnode_t *)tvc; + vp = (vnode_t *) tvc; if (error = afs_FlushVCache(tvc, &fv_slept)) - if (vp->v_flag & VROOT) { - rootvp = vp; - continue; - } else { - ReleaseWriteLock(&afs_xvcache); - return error; - } + if (vp->v_flag & VROOT) { + rootvp = vp; + continue; + } else { + ReleaseWriteLock(&afs_xvcache); + return error; + } } /* @@ -243,14 +244,14 @@ cred_t *cr; */ if (rootvp) { tvc = VTOAFS(rootvp); - if (tvc->opens || CheckLock(&tvc->lock) || LockWaiters(&tvc->lock)) { + if (tvc->opens || CheckLock(&tvc->lock) || LockWaiters(&tvc->lock)) { ReleaseWriteLock(&afs_xvcache); return EBUSY; } - ReleaseWriteLock(&afs_xvcache); + ReleaseWriteLock(&afs_xvcache); rootvp->v_count = 1; AFS_RELE(rootvp); - ObtainWriteLock(&afs_xvcache,173); + ObtainWriteLock(&afs_xvcache, 173); afs_FlushVCache(tvc, &fv_slept); } ReleaseWriteLock(&afs_xvcache); @@ -264,23 +265,27 @@ cred_t *cr; -afs_root (OSI_VFS_ARG(afsp), avpp) +afs_root(OSI_VFS_ARG(afsp), avpp) OSI_VFS_DECL(afsp); - struct vnode **avpp; + struct vnode **avpp; { register afs_int32 code = 0; struct vrequest treq; - register struct vcache *tvp=0; + register struct vcache *tvp = 0; OSI_VFS_CONVERT(afsp) - AFS_STATCNT(afs_root); + AFS_STATCNT(afs_root); if (afs_globalVp && (afs_globalVp->states & CStatd)) { tvp = afs_globalVp; } else { - if (!(code = afs_InitReq(&treq, OSI_GET_CURRENT_CRED())) && - !(code = afs_CheckInit())) { - tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + afs_globalVp = NULL; + } + + if (!(code = afs_InitReq(&treq, OSI_GET_CURRENT_CRED())) + && !(code = afs_CheckInit())) { + tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); /* we really want this to stay around */ if (tvp) { afs_globalVp = tvp; @@ -292,7 +297,7 @@ afs_root (OSI_VFS_ARG(afsp), avpp) int s; VN_HOLD(AFSTOV(tvp)); s = VN_LOCK(AFSTOV(tvp)); - AFSTOV(tvp)->v_flag |= VROOT; + AFSTOV(tvp)->v_flag |= VROOT; VN_UNLOCK(AFSTOV(tvp), s); afs_globalVFS = afsp; @@ -305,27 +310,27 @@ afs_root (OSI_VFS_ARG(afsp), avpp) } afs_statfs(OSI_VFS_ARG(afsp), abp, avp) -OSI_VFS_DECL(afsp); -struct statvfs *abp; -struct vnode *avp; /* unused */ + OSI_VFS_DECL(afsp); + struct statvfs *abp; + struct vnode *avp; /* unused */ { OSI_VFS_CONVERT(afsp) AFS_STATCNT(afs_statfs); - abp->f_bsize = afsp->vfs_bsize; - abp->f_frsize = afsp->vfs_bsize; - /* Fake a high number below to satisfy programs that use the statfs - * call to make sure that there's enough space in the device partition - * before storing something there. - */ - abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = - abp->f_ffree = abp->f_favail = 900000; - - abp->f_fsid = AFS_VFSMAGIC; /* magic */ - strcpy(abp->f_basetype, AFS_MOUNT_AFS); - abp->f_flag = 0; - abp->f_namemax = 256; - return 0; + abp->f_bsize = afsp->vfs_bsize; + abp->f_frsize = afsp->vfs_bsize; + /* Fake a high number below to satisfy programs that use the statfs + * call to make sure that there's enough space in the device partition + * before storing something there. + */ + abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = + abp->f_ffree = abp->f_favail = 900000; + + abp->f_fsid = AFS_VFSMAGIC; /* magic */ + strcpy(abp->f_basetype, AFS_MOUNT_AFS); + abp->f_flag = 0; + abp->f_namemax = 256; + return 0; } @@ -367,154 +372,151 @@ afs_sync(OSI_VFS_DECL(afsp), struct cred *cr) { /* Why enable the vfs sync operation?? */ - int error, lasterr, preempt; - struct vcache *tvc; - struct vnode *vp; - afs_uint32 lvcachegen; - register struct afs_q *tq; - struct afs_q *uq; - int s; - OSI_VFS_CONVERT(afsp) + int error, lasterr, preempt; + struct vcache *tvc; + struct vnode *vp; + afs_uint32 lvcachegen; + register struct afs_q *tq; + struct afs_q *uq; + int s; + OSI_VFS_CONVERT(afsp) error = lasterr = 0; - /* - * if not interested in vnodes, skip all this - */ + /* + * if not interested in vnodes, skip all this + */ #ifdef AFS_SGI61_ENV - if ((flags & (SYNC_CLOSE|SYNC_DELWRI|SYNC_PDFLUSH)) == 0) - goto end; + if ((flags & (SYNC_CLOSE | SYNC_DELWRI | SYNC_PDFLUSH)) == 0) + goto end; #else /* AFS_SGI61_ENV */ - if ((flags & (SYNC_CLOSE|SYNC_DELWRI|SYNC_ATTR)) == 0) - goto end; + if ((flags & (SYNC_CLOSE | SYNC_DELWRI | SYNC_ATTR)) == 0) + goto end; #endif /* AFS_SGI61_ENV */ -loop: - ObtainReadLock(&afs_xvcache); - for (tq = VLRU.prev; tq != &VLRU; tq = uq) { - tvc = QTOV(tq); - uq = QPrev(tq); - vp = (vnode_t *)tvc; - /* - * Since we push all dirty pages on last close/VOP_INACTIVE - * we are only concerned with vnodes with - * active reference counts. - */ - s = VN_LOCK(vp); - if (vp->v_count == 0) { - VN_UNLOCK(vp, s); - continue; - } - if ((flags & SYNC_CLOSE) == 0 && !AFS_VN_DIRTY(vp)) { - VN_UNLOCK(vp, s); - continue; - } - - /* - * ignore vnodes which need no flushing - */ - if (flags & SYNC_DELWRI) { - if (!AFS_VN_DIRTY(vp)) { - VN_UNLOCK(vp, s); - continue; - } - } + loop: + ObtainReadLock(&afs_xvcache); + for (tq = VLRU.prev; tq != &VLRU; tq = uq) { + tvc = QTOV(tq); + uq = QPrev(tq); + vp = (vnode_t *) tvc; + /* + * Since we push all dirty pages on last close/VOP_INACTIVE + * we are only concerned with vnodes with + * active reference counts. + */ + s = VN_LOCK(vp); + if (vp->v_count == 0) { + VN_UNLOCK(vp, s); + continue; + } + if ((flags & SYNC_CLOSE) == 0 && !AFS_VN_DIRTY(vp)) { + VN_UNLOCK(vp, s); + continue; + } + + /* + * ignore vnodes which need no flushing + */ + if (flags & SYNC_DELWRI) { + if (!AFS_VN_DIRTY(vp)) { + VN_UNLOCK(vp, s); + continue; + } + } #ifdef AFS_SGI61_ENV - else if (flags & SYNC_PDFLUSH) { - if (!VN_GET_DPAGES(vp)) { - VN_UNLOCK(vp, s); - continue; - } - } + else if (flags & SYNC_PDFLUSH) { + if (!VN_GET_DPAGES(vp)) { + VN_UNLOCK(vp, s); + continue; + } + } #endif /* AFS_SGI61_ENV */ - vp->v_count++; - VN_UNLOCK(vp, s); - lvcachegen = vcachegen; - ReleaseReadLock(&afs_xvcache); - - /* - * Try to lock rwlock without sleeping. If we can't, we must - * sleep for rwlock. - */ - if (afs_rwlock_nowait(vp, 1) == 0) { + vp->v_count++; + VN_UNLOCK(vp, s); + lvcachegen = vcachegen; + ReleaseReadLock(&afs_xvcache); + + /* + * Try to lock rwlock without sleeping. If we can't, we must + * sleep for rwlock. + */ + if (afs_rwlock_nowait(vp, 1) == 0) { #ifdef AFS_SGI61_ENV - if (flags & (SYNC_BDFLUSH | SYNC_PDFLUSH)) + if (flags & (SYNC_BDFLUSH | SYNC_PDFLUSH)) #else /* AFS_SGI61_ENV */ - if (flags & SYNC_BDFLUSH) + if (flags & SYNC_BDFLUSH) #endif /* AFS_SGI61_ENV */ - { - AFS_RELE(vp); - ObtainReadLock(&afs_xvcache); - if (vcachegen != lvcachegen) { - ReleaseReadLock(&afs_xvcache); - goto loop; - } - continue; - } - AFS_RWLOCK(vp, VRWLOCK_WRITE); + { + AFS_RELE(vp); + ObtainReadLock(&afs_xvcache); + if (vcachegen != lvcachegen) { + ReleaseReadLock(&afs_xvcache); + goto loop; } + continue; + } + AFS_RWLOCK(vp, VRWLOCK_WRITE); + } - AFS_GUNLOCK(); - if (flags & SYNC_CLOSE) { - PFLUSHINVALVP(vp, (off_t)0, (off_t)tvc->m.Length); - } + AFS_GUNLOCK(); + if (flags & SYNC_CLOSE) { + PFLUSHINVALVP(vp, (off_t) 0, (off_t) tvc->m.Length); + } #ifdef AFS_SGI61_ENV - else if (flags & SYNC_PDFLUSH) { - if (VN_GET_DPAGES(vp)) { - pdflush(vp, B_ASYNC); - } - } + else if (flags & SYNC_PDFLUSH) { + if (VN_GET_DPAGES(vp)) { + pdflush(vp, B_ASYNC); + } + } #endif /* AFS_SGI61_ENV */ - if ((flags & SYNC_DELWRI) && AFS_VN_DIRTY(vp)) { + if ((flags & SYNC_DELWRI) && AFS_VN_DIRTY(vp)) { #ifdef AFS_SGI61_ENV - PFLUSHVP(vp, (off_t)tvc->m.Length, - (flags & SYNC_WAIT) ? 0 : B_ASYNC, error); + PFLUSHVP(vp, (off_t) tvc->m.Length, + (flags & SYNC_WAIT) ? 0 : B_ASYNC, error); #else /* AFS_SGI61_ENV */ - if (flags & SYNC_WAIT) - /* push all and wait */ - PFLUSHVP(vp, (off_t)tvc->m.Length, - (off_t)0, error); - else if (flags & SYNC_BDFLUSH) { - /* push oldest */ - error = pdflush(vp, B_ASYNC); - } - else { - /* push all but don't wait */ - PFLUSHVP(vp, (off_t)tvc->m.Length, - (off_t)B_ASYNC, error); - } + if (flags & SYNC_WAIT) + /* push all and wait */ + PFLUSHVP(vp, (off_t) tvc->m.Length, (off_t) 0, error); + else if (flags & SYNC_BDFLUSH) { + /* push oldest */ + error = pdflush(vp, B_ASYNC); + } else { + /* push all but don't wait */ + PFLUSHVP(vp, (off_t) tvc->m.Length, (off_t) B_ASYNC, error); + } #endif /* AFS_SGI61_ENV */ - } + } - /* - * Release vp, check error and whether to preempt, and if - * we let go of xvcache lock and someone has changed the - * VLRU, restart the loop - */ - AFS_GLOCK(); - AFS_RWUNLOCK(vp, VRWLOCK_WRITE); - AFS_RELE(vp); - if (error) - lasterr = error; - if ((++preempt & PREEMPT_MASK) == 0) { - AFS_GUNLOCK(); - PREEMPT(); - AFS_GLOCK(); - } - ObtainReadLock(&afs_xvcache); - if (vcachegen != lvcachegen) { - ReleaseReadLock(&afs_xvcache); - goto loop; - } + /* + * Release vp, check error and whether to preempt, and if + * we let go of xvcache lock and someone has changed the + * VLRU, restart the loop + */ + AFS_GLOCK(); + AFS_RWUNLOCK(vp, VRWLOCK_WRITE); + AFS_RELE(vp); + if (error) + lasterr = error; + if ((++preempt & PREEMPT_MASK) == 0) { + AFS_GUNLOCK(); + PREEMPT(); + AFS_GLOCK(); } - ReleaseReadLock(&afs_xvcache); -end: - return lasterr; + ObtainReadLock(&afs_xvcache); + if (vcachegen != lvcachegen) { + ReleaseReadLock(&afs_xvcache); + goto loop; + } + } + ReleaseReadLock(&afs_xvcache); + end: + return lasterr; } -afs_vget(OSI_VFS_DECL(afsp), vnode_t **avcp, struct fid *fidp) +afs_vget(OSI_VFS_DECL(afsp), vnode_t ** avcp, struct fid * fidp) { struct VenusFid vfid; struct vrequest treq; @@ -524,16 +526,16 @@ afs_vget(OSI_VFS_DECL(afsp), vnode_t **avcp, struct fid *fidp) #if defined(AFS_SGI64_ENV) && defined(CKPT) && !defined(_R5000_CVT_WAR) afs_fid2_t *afid2; -#endif +#endif OSI_VFS_CONVERT(afsp) - AFS_STATCNT(afs_vget); + AFS_STATCNT(afs_vget); *avcp = NULL; #if defined(AFS_SGI64_ENV) && defined(CKPT) && !defined(_R5000_CVT_WAR) - afid2 = (afs_fid2_t*)fidp; + afid2 = (afs_fid2_t *) fidp; if (afid2->af_len == sizeof(afs_fid2_t) - sizeof(afid2->af_len)) { /* It's a checkpoint restart fid. */ tcell = afs_GetCellByIndex(afid2->af_cell, READ_LOCK); @@ -549,19 +551,20 @@ afs_vget(OSI_VFS_DECL(afsp), vnode_t **avcp, struct fid *fidp) if (code = afs_InitReq(&treq, OSI_GET_CURRENT_CRED())) goto out; - *avcp = (vnode_t*) afs_GetVCache(&vfid, &treq, (afs_int32 *)0, - (struct vcache*)0, 0); - if (! *avcp) { + *avcp = + (vnode_t *) afs_GetVCache(&vfid, &treq, NULL, (struct vcache *)0); + if (!*avcp) { code = ENOENT; } goto out; } #endif - if (code = afs_InitReq(&treq, OSI_GET_CURRENT_CRED())) goto out; - code = afs_osi_vget((struct vcache**)avcp, fidp, &treq); + if (code = afs_InitReq(&treq, OSI_GET_CURRENT_CRED())) + goto out; + code = afs_osi_vget((struct vcache **)avcp, fidp, &treq); - out: + out: afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp, ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, &vfid); code = afs_CheckCode(code, &treq, 42); @@ -569,7 +572,7 @@ afs_vget(OSI_VFS_DECL(afsp), vnode_t **avcp, struct fid *fidp) } -#ifdef MP /* locked versions of vfs operations. */ +#ifdef MP /* locked versions of vfs operations. */ /* wrappers for vfs calls */ #ifdef AFS_SGI64_ENV @@ -578,70 +581,78 @@ afs_vget(OSI_VFS_DECL(afsp), vnode_t **avcp, struct fid *fidp) #define AFS_MP_VFS_ARG(A) struct vfs A #endif -int mp_afs_mount(struct vfs *a, struct vnode *b, struct mounta *c, +int +mp_afs_mount(struct vfs *a, struct vnode *b, struct mounta *c, #ifdef AFS_SGI65_ENV - char *d, + char *d, #endif - struct cred *e) + struct cred *e) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvfsops.vfs_mount(a, b, c, d + int rv; + AFS_GLOCK(); + rv = afs_lockedvfsops.vfs_mount(a, b, c, d #ifdef AFS_SGI65_ENV - , e + , e #endif - ); - AFS_GUNLOCK(); - return rv; + ); + AFS_GUNLOCK(); + return rv; } -int mp_afs_unmount(AFS_MP_VFS_ARG(*a), int b, struct cred *c) +int +mp_afs_unmount(AFS_MP_VFS_ARG(*a), int b, struct cred *c) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvfsops.vfs_unmount(a, b, c); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvfsops.vfs_unmount(a, b, c); + AFS_GUNLOCK(); + return rv; } -int mp_afs_root(AFS_MP_VFS_ARG(*a), struct vnode **b) +int +mp_afs_root(AFS_MP_VFS_ARG(*a), struct vnode **b) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvfsops.vfs_root(a, b); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvfsops.vfs_root(a, b); + AFS_GUNLOCK(); + return rv; } -int mp_afs_statvfs(AFS_MP_VFS_ARG(*a), struct statvfs *b, struct vnode *c) +int +mp_afs_statvfs(AFS_MP_VFS_ARG(*a), struct statvfs *b, struct vnode *c) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvfsops.vfs_statvfs(a, b, c); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvfsops.vfs_statvfs(a, b, c); + AFS_GUNLOCK(); + return rv; } -int mp_afs_sync(AFS_MP_VFS_ARG(*a), + +int +mp_afs_sync(AFS_MP_VFS_ARG(*a), #ifdef AFS_SGI65_ENV - int b, + int b, #else - short b, + short b, #endif - struct cred *c) + struct cred *c) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvfsops.vfs_sync(a, b, c); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvfsops.vfs_sync(a, b, c); + AFS_GUNLOCK(); + return rv; } -int mp_afs_vget(AFS_MP_VFS_ARG(*a), struct vnode **b, struct fid *c) + +int +mp_afs_vget(AFS_MP_VFS_ARG(*a), struct vnode **b, struct fid *c) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvfsops.vfs_vget(a, b, c); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvfsops.vfs_vget(a, b, c); + AFS_GUNLOCK(); + return rv; } struct vfsops Afs_vfsops = { @@ -654,8 +665,8 @@ struct vfsops Afs_vfsops = { #endif mp_afs_mount, #ifdef AFS_SGI64_ENV - fs_nosys, /* rootinit */ - fs_nosys, /* mntupdate */ + fs_nosys, /* rootinit */ + fs_nosys, /* mntupdate */ fs_dounmount, #endif mp_afs_unmount, @@ -663,13 +674,13 @@ struct vfsops Afs_vfsops = { mp_afs_statvfs, mp_afs_sync, mp_afs_vget, - fs_nosys, /* mountroot */ + fs_nosys, /* mountroot */ #ifdef AFS_SGI65_ENV - fs_nosys, /* realvfsops */ - fs_import, /* import */ - fs_nosys, /* quotactl */ + fs_nosys, /* realvfsops */ + fs_import, /* import */ + fs_nosys, /* quotactl */ #else - fs_nosys, /* swapvp */ + fs_nosys, /* swapvp */ #endif }; diff --git a/src/afs/IRIX/osi_vm.c b/src/afs/IRIX/osi_vm.c index cf447678c..2bfefaa5a 100644 --- a/src/afs/IRIX/osi_vm.c +++ b/src/afs/IRIX/osi_vm.c @@ -8,13 +8,14 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_vm.c,v 1.1.1.5 2002/05/10 23:44:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_vm.c,v 1.8 2003/07/15 23:14:23 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ #include "sys/flock.h" /* for IGN_PID */ extern struct vnodeops Afs_vnodeops; @@ -34,9 +35,7 @@ extern struct vnodeops Afs_vnodeops; * therefore obsolescent. */ int -osi_VM_FlushVCache(avc, slept) - struct vcache *avc; - int *slept; +osi_VM_FlushVCache(struct vcache *avc, int *slept) { int s, code; vnode_t *vp = &avc->v; @@ -63,7 +62,7 @@ osi_VM_FlushVCache(avc, slept) * Note that although we checked vcount above, we didn't have the lock */ if (vp->v_count > 0 || (vp->v_flag & VINACT)) { - VN_UNLOCK(vp, s); + VN_UNLOCK(vp, s); return EBUSY; } VN_UNLOCK(vp, s); @@ -74,7 +73,7 @@ osi_VM_FlushVCache(avc, slept) * Note that we hold the xvcache lock the entire time. */ AFS_GUNLOCK(); - PTOSSVP(vp, (off_t)0, (off_t)MAXLONG); + PTOSSVP(vp, (off_t) 0, (off_t) MAXLONG); AFS_GLOCK(); /* afs_chkpgoob will drop and re-acquire the global lock. */ @@ -91,9 +90,9 @@ osi_VM_FlushVCache(avc, slept) if (vp->v_filocksem) { if (vp->v_filocks) #ifdef AFS_SGI64_ENV - cleanlocks(vp, &curprocp->p_flid); + cleanlocks(vp, &curprocp->p_flid); #else - cleanlocks(vp, IGN_PID, 0); + cleanlocks(vp, IGN_PID, 0); #endif osi_Assert(vp->v_filocks == NULL); mutex_destroy(vp->v_filocksem); @@ -102,10 +101,11 @@ osi_VM_FlushVCache(avc, slept) } #endif /* AFS_SGI65_ENV */ - if (avc->vrefCount) osi_Panic("flushVcache: vm race"); + if (avc->vrefCount) + osi_Panic("flushVcache: vm race"); #ifdef AFS_SGI64_ENV AFS_GUNLOCK(); - vnode_pcache_reclaim(vp); /* this can sleep */ + vnode_pcache_reclaim(vp); /* this can sleep */ vnode_pcache_free(vp); if (vp->v_op != &Afs_vnodeops) { VOP_RECLAIM(vp, FSYNC_WAIT, code); @@ -123,7 +123,7 @@ osi_VM_FlushVCache(avc, slept) bhv_remove(VN_BHV_HEAD(vp), &(avc->vc_bhv_desc)); bhv_head_destroy(&(vp->v_bh)); #endif - vp->v_flag = 0; /* debug */ + vp->v_flag = 0; /* debug */ #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK) destroy_bitlock(&vp->v_flag); #endif @@ -145,20 +145,17 @@ osi_VM_FlushVCache(avc, slept) * be some pages around when we return, newly created by concurrent activity. */ void -osi_VM_TryToSmush(avc, acred, sync) - struct vcache *avc; - struct AFS_UCRED *acred; - int sync; +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); /* current remapf restriction - cannot have VOP_RWLOCK */ osi_Assert(OSI_GET_LOCKID() != avc->vc_rwlockid); - if (((vnode_t *)avc)->v_type == VREG && AFS_VN_MAPPED(((vnode_t *)avc))) - remapf(((vnode_t *)avc), 0, 0); - PTOSSVP(AFSTOV(avc), (off_t)0, (off_t)MAXLONG); + if (((vnode_t *) avc)->v_type == VREG && AFS_VN_MAPPED(((vnode_t *) avc))) + remapf(((vnode_t *) avc), 0, 0); + PTOSSVP(AFSTOV(avc), (off_t) 0, (off_t) MAXLONG); AFS_GLOCK(); - ObtainWriteLock(&avc->lock,62); + ObtainWriteLock(&avc->lock, 62); } /* Flush and invalidate pages, for fsync() with INVAL flag @@ -166,11 +163,10 @@ osi_VM_TryToSmush(avc, acred, sync) * Locking: only the global lock is held. */ void -osi_VM_FSyncInval(avc) - struct vcache *avc; +osi_VM_FSyncInval(struct vcache *avc) { AFS_GUNLOCK(); - PFLUSHINVALVP((vnode_t *)avc, (off_t)0, (off_t)avc->m.Length); + PFLUSHINVALVP((vnode_t *) avc, (off_t) 0, (off_t) avc->m.Length); AFS_GLOCK(); } @@ -180,8 +176,7 @@ osi_VM_FSyncInval(avc) * re-obtained. */ void -osi_VM_StoreAllSegments(avc) - struct vcache *avc; +osi_VM_StoreAllSegments(struct vcache *avc) { int error; osi_Assert(valusema(&avc->vc_rwlock) <= 0); @@ -194,11 +189,11 @@ osi_VM_StoreAllSegments(avc) AFS_GUNLOCK(); /* Write out dirty pages list to avoid B_DELWRI buffers. */ - while (VN_GET_DPAGES((vnode_t*)avc)) { + while (VN_GET_DPAGES((vnode_t *) avc)) { pdflush(AFSTOV(avc), 0); } - PFLUSHVP(AFSTOV(avc), (off_t)avc->m.Length, (off_t)0, error); + PFLUSHVP(AFSTOV(avc), (off_t) avc->m.Length, (off_t) 0, error); AFS_GLOCK(); if (error) { /* @@ -209,11 +204,12 @@ osi_VM_StoreAllSegments(avc) * does what we want (we don't use this normally since * it also unhashes pages ..) */ - PINVALFREE((vnode_t *)avc, avc->m.Length); + PINVALFREE((vnode_t *) avc, avc->m.Length); } - ObtainWriteLock(&avc->lock,121); + ObtainWriteLock(&avc->lock, 121); if (error && avc->m.LinkCount) - cmn_err(CE_WARN, "AFS:Failed to push back pages for vnode 0x%x error %d (from afs_StoreOnLastReference)", + cmn_err(CE_WARN, + "AFS:Failed to push back pages for vnode 0x%x error %d (from afs_StoreOnLastReference)", avc, error); } @@ -222,13 +218,11 @@ osi_VM_StoreAllSegments(avc) * Locking: No lock is held, not even the global lock. */ void -osi_VM_FlushPages(avc, credp) - struct vcache *avc; - struct AFS_UCRED *credp; +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { - vnode_t *vp = (vnode_t *)avc; + vnode_t *vp = (vnode_t *) avc; - remapf(vp, /*avc->m.Length*/ 0, 0); + remapf(vp, /*avc->m.Length */ 0, 0); /* Used to grab locks and recheck avc->m.DataVersion and * avc->execsOrWriters here, but we have to drop locks before calling @@ -239,7 +233,7 @@ osi_VM_FlushPages(avc, credp) * ptossvp tosses all pages associated with this vnode * All in-use pages are marked BAD */ - PTOSSVP(vp, (off_t)0, (off_t)MAXLONG); + PTOSSVP(vp, (off_t) 0, (off_t) MAXLONG); } /* Purge pages beyond end-of-file, when truncating a file. @@ -249,10 +243,7 @@ osi_VM_FlushPages(avc, credp) * it only works on Solaris. */ void -osi_VM_Truncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { - PTOSSVP(&avc->v, (off_t)alen, (off_t)MAXLONG); + PTOSSVP(&avc->v, (off_t) alen, (off_t) MAXLONG); } diff --git a/src/afs/IRIX/osi_vnodeops.c b/src/afs/IRIX/osi_vnodeops.c index cbbcdc407..796d34c78 100644 --- a/src/afs/IRIX/osi_vnodeops.c +++ b/src/afs/IRIX/osi_vnodeops.c @@ -11,16 +11,17 @@ * SGI specific vnodeops + other misc interface glue */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/IRIX/osi_vnodeops.c,v 1.1.1.9 2002/05/10 23:44:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/IRIX/osi_vnodeops.c,v 1.14 2003/07/15 23:14:23 shadow Exp $"); #ifdef AFS_SGI62_ENV -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../sys/flock.h" -#include "../afs/nfsclient.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "sys/flock.h" +#include "afs/nfsclient.h" /* AFSBSIZE must be at least the size of a page, else the client will hang. * For 64 bit platforms, the page size is more than 8K. @@ -33,14 +34,15 @@ static void afs_strategy(); static int afs_xread(), afs_xwrite(); static int afs_xbmap(), afs_map(), afs_reclaim(); #ifndef AFS_SGI65_ENV -static int afs_addmap(), afs_delmap(); +static int afs_addmap(), afs_delmap(); #endif extern int afs_open(), afs_close(), afs_ioctl(), afs_getattr(), afs_setattr(); extern int afs_access(), afs_lookup(); extern int afs_create(), afs_remove(), afs_link(), afs_rename(); extern int afs_mkdir(), afs_rmdir(), afs_readdir(); -extern int afs_symlink(), afs_readlink(), afs_fsync(), afs_fid(), afs_frlock(); -static int afs_seek(OSI_VC_DECL(a), off_t b, off_t *c); +extern int afs_symlink(), afs_readlink(), afs_fsync(), afs_fid(), +afs_frlock(); +static int afs_seek(OSI_VC_DECL(a), off_t b, off_t * c); #ifdef AFS_SGI64_ENV extern int afs_xinactive(); #else @@ -48,17 +50,14 @@ extern void afs_xinactive(); #endif extern void afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T b); -extern void afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T b); +extern void afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T b); extern int afs_fid2(); -static int afsrwvp(register struct vcache *avc, - register struct uio *uio, - enum uio_rw rw, - int ioflag, +static int afsrwvp(register struct vcache *avc, register struct uio *uio, + enum uio_rw rw, int ioflag, #ifdef AFS_SGI64_ENV - struct cred *cr, - struct flid *flp); + struct cred *cr, struct flid *flp); #else struct cred *cr); #endif @@ -72,89 +71,91 @@ struct vnodeops Afs_vnodeops = { #ifdef AFS_SGI64_ENV #ifdef AFS_SGI65_ENV - BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE), + BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE), #else - VNODE_POSITION_BASE, -#endif -#endif - afs_open, - afs_close, - afs_xread, - afs_xwrite, - afs_ioctl, - fs_setfl, - afs_getattr, - afs_setattr, - afs_access, - afs_lookup, - afs_create, - afs_remove, - afs_link, - afs_rename, - afs_mkdir, - afs_rmdir, - afs_readdir, - afs_symlink, - afs_readlink, - afs_fsync, - afs_xinactive, - afs_fid, - afs_fid2, - afs_rwlock, - afs_rwunlock, - afs_seek, - fs_cmp, - afs_frlock, - fs_nosys, /* realvp */ - afs_xbmap, - afs_strategy, - afs_map, + VNODE_POSITION_BASE, +#endif +#endif + afs_open, + afs_close, + afs_xread, + afs_xwrite, + afs_ioctl, + fs_setfl, + afs_getattr, + afs_setattr, + afs_access, + afs_lookup, + afs_create, + afs_remove, + afs_link, + afs_rename, + afs_mkdir, + afs_rmdir, + afs_readdir, + afs_symlink, + afs_readlink, + afs_fsync, + afs_xinactive, + afs_fid, + afs_fid2, + afs_rwlock, + afs_rwunlock, + afs_seek, + fs_cmp, + afs_frlock, + fs_nosys, /* realvp */ + afs_xbmap, + afs_strategy, + afs_map, #ifdef AFS_SGI65_ENV - fs_noerr, /* addmap - devices only */ - fs_noerr, /* delmap - devices only */ + fs_noerr, /* addmap - devices only */ + fs_noerr, /* delmap - devices only */ #else - afs_addmap, - afs_delmap, -#endif - fs_poll, /* poll */ - fs_nosys, /* dump */ - fs_pathconf, - fs_nosys, /* allocstore */ - fs_nosys, /* fcntl */ - afs_reclaim, /* reclaim */ - fs_nosys, /* attr_get */ - fs_nosys, /* attr_set */ - fs_nosys, /* attr_remove */ - fs_nosys, /* attr_list */ + afs_addmap, + afs_delmap, +#endif + fs_poll, /* poll */ + fs_nosys, /* dump */ + fs_pathconf, + fs_nosys, /* allocstore */ + fs_nosys, /* fcntl */ + afs_reclaim, /* reclaim */ + fs_nosys, /* attr_get */ + fs_nosys, /* attr_set */ + fs_nosys, /* attr_remove */ + fs_nosys, /* attr_list */ #ifdef AFS_SGI64_ENV #ifdef AFS_SGI65_ENV - fs_cover, - (vop_link_removed_t)fs_noval, - fs_vnode_change, - fs_tosspages, - fs_flushinval_pages, - fs_flush_pages, - fs_invalfree_pages, - fs_pages_sethole, - (vop_commit_t)fs_nosys, - (vop_readbuf_t)fs_nosys, - fs_strgetmsg, - fs_strputmsg, + fs_cover, + (vop_link_removed_t) fs_noval, + fs_vnode_change, + fs_tosspages, + fs_flushinval_pages, + fs_flush_pages, + fs_invalfree_pages, + fs_pages_sethole, + (vop_commit_t) fs_nosys, + (vop_readbuf_t) fs_nosys, + fs_strgetmsg, + fs_strputmsg, #else - fs_mount, + fs_mount, #endif #endif }; + #ifndef MP struct vnodeops *afs_ops = &Afs_vnodeops; #endif -int afs_frlock(OSI_VN_DECL(vp), int cmd, struct flock *lfp, int flag, - off_t offset, +int +afs_frlock(OSI_VN_DECL(vp), int cmd, struct flock *lfp, int flag, + off_t offset, #ifdef AFS_SGI65_ENV - vrwlock_t vrwlock, + vrwlock_t vrwlock, #endif - cred_t *cr) + cred_t * cr) { int error; OSI_VN_CONVERT(vp) @@ -177,13 +178,13 @@ int afs_frlock(OSI_VN_DECL(vp), int cmd, struct flock *lfp, int flag, * For GETLK we do a bit more - we first check any byte-wise * locks - if none then check for full AFS file locks */ - if (cmd == F_GETLK || lfp->l_whence != 0 || lfp->l_start != 0 || - (lfp->l_len != MAXEND && lfp->l_len != 0)) { + if (cmd == F_GETLK || lfp->l_whence != 0 || lfp->l_start != 0 + || (lfp->l_len != MAXEND && lfp->l_len != 0)) { AFS_RWLOCK(vp, VRWLOCK_WRITE); AFS_GUNLOCK(); #ifdef AFS_SGI65_ENV - error = fs_frlock(OSI_VN_ARG(vp), cmd, lfp, flag, offset, - vrwlock, cr); + error = + fs_frlock(OSI_VN_ARG(vp), cmd, lfp, flag, offset, vrwlock, cr); #else error = fs_frlock(vp, cmd, lfp, flag, offset, cr); #endif @@ -197,37 +198,36 @@ int afs_frlock(OSI_VN_DECL(vp), int cmd, struct flock *lfp, int flag, /* fall through to check for full AFS file locks */ } - /* map BSD style to plain - we don't call reclock() + /* map BSD style to plain - we don't call reclock() * and its only there that the difference is important */ switch (cmd) { - case F_GETLK: - case F_RGETLK: - break; - case F_SETLK: - case F_RSETLK: - break; - case F_SETBSDLK: - cmd = F_SETLK; - break; - case F_SETLKW: - case F_RSETLKW: - break; - case F_SETBSDLKW: - cmd = F_SETLKW; - break; - default: - return EINVAL; + case F_GETLK: + case F_RGETLK: + break; + case F_SETLK: + case F_RSETLK: + break; + case F_SETBSDLK: + cmd = F_SETLK; + break; + case F_SETLKW: + case F_RSETLKW: + break; + case F_SETBSDLKW: + cmd = F_SETLKW; + break; + default: + return EINVAL; } AFS_GUNLOCK(); - error = convoff(vp, lfp, 0, offset - , SEEKLIMIT + error = convoff(vp, lfp, 0, offset, SEEKLIMIT #ifdef AFS_SGI64_ENV , OSI_GET_CURRENT_CRED() #endif /* AFS_SGI64_ENV */ - ); + ); AFS_GLOCK(); if (!error) { @@ -263,32 +263,34 @@ int afs_frlock(OSI_VN_DECL(vp), int cmd, struct flock *lfp, int flag, */ /* ARGSUSED */ #ifdef AFS_SGI64_ENV -static int afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr, flp) -struct flid *flp; +static int +afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr, flp) + struct flid *flp; #else -static int afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr) +static int +afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr) #endif - OSI_VC_DECL(avc); - struct uio *uiop; - int ioflag; - struct cred *cr; +OSI_VC_DECL(avc); + struct uio *uiop; + int ioflag; + struct cred *cr; { int code; OSI_VC_CONVERT(avc) - osi_Assert(avc->v.v_count > 0); + osi_Assert(avc->v.v_count > 0); if (avc->v.v_type != VREG) return EISDIR; #ifdef AFS_SGI64_ENV #ifdef AFS_SGI65_ENV if (!(ioflag & IO_ISLOCKED)) - AFS_RWLOCK((vnode_t*)avc, VRWLOCK_READ); + AFS_RWLOCK((vnode_t *) avc, VRWLOCK_READ); #endif code = afsrwvp(avc, uiop, UIO_READ, ioflag, cr, flp); #ifdef AFS_SGI65_ENV if (!(ioflag & IO_ISLOCKED)) - AFS_RWUNLOCK((vnode_t*)avc, VRWLOCK_READ); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_READ); #endif #else code = afsrwvp(avc, uiop, UIO_READ, ioflag, cr); @@ -298,20 +300,22 @@ static int afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr) /* ARGSUSED */ #ifdef AFS_SGI64_ENV -static int afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr, flp) -struct flid *flp; +static int +afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr, flp) + struct flid *flp; #else -static int afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr) +static int +afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr) #endif - OSI_VC_DECL(avc); - struct uio *uiop; - int ioflag; - struct cred *cr; +OSI_VC_DECL(avc); + struct uio *uiop; + int ioflag; + struct cred *cr; { int code; OSI_VC_CONVERT(avc) - osi_Assert(avc->v.v_count > 0); + osi_Assert(avc->v.v_count > 0); if (avc->v.v_type != VREG) return EISDIR; @@ -320,12 +324,12 @@ static int afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr) #ifdef AFS_SGI64_ENV #ifdef AFS_SGI65_ENV if (!(ioflag & IO_ISLOCKED)) - AFS_RWLOCK(((vnode_t*)avc), VRWLOCK_WRITE); + AFS_RWLOCK(((vnode_t *) avc), VRWLOCK_WRITE); #endif code = afsrwvp(avc, uiop, UIO_WRITE, ioflag, cr, flp); #ifdef AFS_SGI65_ENV if (!(ioflag & IO_ISLOCKED)) - AFS_RWUNLOCK((vnode_t*)avc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE); #endif #else code = afsrwvp(avc, uiop, UIO_WRITE, ioflag, cr); @@ -338,15 +342,13 @@ static int prnra = 0; static int acchk = 0; static int acdrop = 0; -static int afsrwvp(register struct vcache *avc, - register struct uio *uio, - enum uio_rw rw, - int ioflag, +static int +afsrwvp(register struct vcache *avc, register struct uio *uio, enum uio_rw rw, + int ioflag, #ifdef AFS_SGI64_ENV - struct cred *cr, - struct flid *flp) + struct cred *cr, struct flid *flp) #else - struct cred *cr) + struct cred *cr) #endif { register struct vnode *vp = AFSTOV(avc); @@ -362,34 +364,32 @@ static int afsrwvp(register struct vcache *avc, struct dcache *tdc; int counter = 0; - osi_Assert((valusema(&avc->vc_rwlock) <= 0) && - (OSI_GET_LOCKID() == avc->vc_rwlockid)); + osi_Assert((valusema(&avc->vc_rwlock) <= 0) + && (OSI_GET_LOCKID() == avc->vc_rwlockid)); newoff = uio->uio_resid + uio->uio_offset; if (uio->uio_resid <= 0) { return (0); } - if (uio->uio_offset < 0 - || (signed long)newoff < 0) { + if (uio->uio_offset < 0 || (signed long)newoff < 0) { return (EINVAL); } if (ioflag & IO_DIRECT) return EINVAL; - if (rw == UIO_WRITE && vp->v_type == VREG - && newoff > uio->uio_limit) { + if (rw == UIO_WRITE && vp->v_type == VREG && newoff > uio->uio_limit) { return (EFBIG); } afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, ioflag, - ICL_TYPE_INT32, rw, ICL_TYPE_INT32, 0); + ICL_TYPE_INT32, ioflag, ICL_TYPE_INT32, rw, ICL_TYPE_INT32, 0); /* get a validated vcache entry */ afs_InitReq(&treq, cr); error = afs_VerifyVCache(avc, &treq); - if (error) return afs_CheckCode(error, &treq, 51); + if (error) + return afs_CheckCode(error, &treq, 51); /* * flush any stale pages - this will unmap @@ -398,8 +398,9 @@ static int afsrwvp(register struct vcache *avc, osi_FlushPages(avc, cr); if (cr && AFS_NFSXLATORREQ(cr) && rw == UIO_READ) { - if (!afs_AccessOK(avc, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) + if (!afs_AccessOK + (avc, PRSFS_READ, &treq, + CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) return EACCES; } /* @@ -408,7 +409,7 @@ static int afsrwvp(register struct vcache *avc, * the last writers credentials */ if (rw == UIO_WRITE || (rw == UIO_READ && avc->cred == NULL)) { - ObtainWriteLock(&avc->lock,92); + ObtainWriteLock(&avc->lock, 92); if (avc->cred) crfree(avc->cred); crhold(cr); @@ -422,7 +423,7 @@ static int afsrwvp(register struct vcache *avc, * because there're no open/close nfs rpc's to call our afs_open/close. */ if (root_exported && rw == UIO_WRITE) { - ObtainWriteLock(&avc->lock,234); + ObtainWriteLock(&avc->lock, 234); if (root_exported) { didFakeOpen = 1; afs_FakeOpen(avc); @@ -432,7 +433,7 @@ static int afsrwvp(register struct vcache *avc, error = 0; if (rw == UIO_WRITE) { - ObtainWriteLock(&avc->lock,330); + ObtainWriteLock(&avc->lock, 330); avc->states |= CDirty; ReleaseWriteLock(&avc->lock); } @@ -453,7 +454,7 @@ static int afsrwvp(register struct vcache *avc, error = avc->vc_error; break; } - bsize = AFSBSIZE; /* why not?? */ + bsize = AFSBSIZE; /* why not?? */ off = uio->uio_offset % bsize; bn = BTOBBT(uio->uio_offset - off); /* @@ -472,7 +473,7 @@ static int afsrwvp(register struct vcache *avc, /* * read/paging in a normal file */ - rem = avc->m.Length - (afs_int32)uio->uio_offset; + rem = avc->m.Length - (afs_int32) uio->uio_offset; if (rem <= 0) /* EOF */ break; @@ -503,8 +504,8 @@ static int afsrwvp(register struct vcache *avc, * do read-ahead on any file that has potentially * dirty mmap pages. */ - if ((avc->lastr + BTOBB(AFSBSIZE) == bn || - uio->uio_resid > AFSBSIZE) + if ((avc->lastr + BTOBB(AFSBSIZE) == bn + || uio->uio_resid > AFSBSIZE) #ifdef AFS_SGI61_ENV && (!AFS_VN_MAPPED(vp)) #else /* AFS_SGI61_ENV */ @@ -533,10 +534,10 @@ static int afsrwvp(register struct vcache *avc, } #ifdef DEBUG else if (prnra) - printf("NRA:vp 0x%x lastr %d bn %d len %d cnt %d bsize %d rem %d resid %d\n", - vp, avc->lastr, bn, - len, cnt, bsize, rem, - uio->uio_resid); + printf + ("NRA:vp 0x%x lastr %d bn %d len %d cnt %d bsize %d rem %d resid %d\n", + vp, avc->lastr, bn, len, cnt, bsize, rem, + uio->uio_resid); #endif avc->lastr = bn; @@ -546,13 +547,13 @@ static int afsrwvp(register struct vcache *avc, */ if (counter == 0 || AFS_CHUNKOFFSET(off) == 0) { AFS_GLOCK(); - ObtainWriteLock(&avc->lock,562); + ObtainWriteLock(&avc->lock, 562); tdc = afs_FindDCache(avc, off); - if (tdc) { - if (!(tdc->flags & DFNextStarted)) - afs_PrefetchChunk(avc, tdc, cr, &treq); + if (tdc) { + if (!(tdc->mflags & DFNextStarted)) + afs_PrefetchChunk(avc, tdc, cr, &treq); afs_PutDCache(tdc); - } + } ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); } @@ -568,13 +569,14 @@ static int afsrwvp(register struct vcache *avc, */ if (counter > 0 && AFS_CHUNKOFFSET(uio->uio_offset) == 0) { AFS_GLOCK(); - ObtainWriteLock(&avc->lock,90); + ObtainWriteLock(&avc->lock, 90); error = afs_DoPartialWrite(avc, &treq); if (error == 0) avc->states |= CDirty; ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); - if (error) break; + if (error) + break; } counter++; @@ -623,7 +625,7 @@ static int afsrwvp(register struct vcache *avc, osi_Assert(bp->b_error == 0); if (uio->uio_segflg != UIO_NOSPACE) - (void) bp_mapin(bp); + (void)bp_mapin(bp); AFS_UIOMOVE(bp->b_un.b_addr + bmv[0].pboff, cnt, rw, uio, error); if (rw == UIO_READ || error) { if (bp->b_flags & B_DELWRI) { @@ -635,12 +637,12 @@ static int afsrwvp(register struct vcache *avc, * m.Length is the maximum number of bytes known to be in the file. * Make sure it is at least as high as the last byte we just wrote * into the buffer. - */ - if (avc->m.Length < (afs_int32)uio->uio_offset) { + */ + if (avc->m.Length < (afs_int32) uio->uio_offset) { AFS_GLOCK(); - ObtainWriteLock(&avc->lock,235); + ObtainWriteLock(&avc->lock, 235); avc->m.Length = uio->uio_offset; - ReleaseWriteLock(&avc->lock); + ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); } if (uio->uio_fmode & FSYNC) { @@ -654,10 +656,11 @@ static int afsrwvp(register struct vcache *avc, /* * Since EIO on an unlinked file is non-intuitive - give some * explanation - */ + */ if (error) { if (avc->m.LinkCount == 0) - cmn_err(CE_WARN,"AFS: Process pid %d write error %d writing to unlinked file.", + cmn_err(CE_WARN, + "AFS: Process pid %d write error %d writing to unlinked file.", OSI_GET_CURRENT_PID(), error); } } @@ -674,8 +677,8 @@ static int afsrwvp(register struct vcache *avc, if (!error) { #ifdef AFS_SGI61_ENV - if (((ioflag & IO_SYNC) || (ioflag & IO_DSYNC)) && (rw == UIO_WRITE) && - !AFS_NFSXLATORREQ(cr)) { + if (((ioflag & IO_SYNC) || (ioflag & IO_DSYNC)) && (rw == UIO_WRITE) + && !AFS_NFSXLATORREQ(cr)) { error = afs_fsync(avc, 0, cr); } #else /* AFS_SGI61_ENV */ @@ -685,42 +688,43 @@ static int afsrwvp(register struct vcache *avc, #endif /* AFS_SGI61_ENV */ } if (didFakeOpen) { - ObtainWriteLock(&avc->lock,236); + ObtainWriteLock(&avc->lock, 236); afs_FakeClose(avc, cr); /* XXXX For nfs trans XXXX */ ReleaseWriteLock(&avc->lock); } afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, ioflag, - ICL_TYPE_INT32, rw, ICL_TYPE_INT32, error); + ICL_TYPE_INT32, ioflag, ICL_TYPE_INT32, rw, ICL_TYPE_INT32, + error); return (error); } -int afs_xbmap(OSI_VC_ARG(avc), offset, count, flag, cr, bmv, nbmv) - OSI_VC_DECL(avc); - off_t offset; - ssize_t count; - int flag; - struct cred *cr; - struct bmapval *bmv; - int *nbmv; +int +afs_xbmap(OSI_VC_ARG(avc), offset, count, flag, cr, bmv, nbmv) +OSI_VC_DECL(avc); + off_t offset; + ssize_t count; + int flag; + struct cred *cr; + struct bmapval *bmv; + int *nbmv; { - int bsize; /* server's block size in bytes */ + int bsize; /* server's block size in bytes */ off_t off; size_t rem, cnt; OSI_VC_CONVERT(avc) - bsize = AFSBSIZE; + bsize = AFSBSIZE; off = offset % bsize; /* offset into block */ bmv->bn = BTOBBT(offset - off); bmv->offset = bmv->bn; bmv->pboff = off; rem = avc->m.Length - offset; if (rem <= 0) - cnt = 0; /* EOF */ + cnt = 0; /* EOF */ else cnt = MIN(bsize - off, rem); - + /* * It is benign to ignore *nbmv > 1, since it is only for requesting * readahead. @@ -753,7 +757,7 @@ int afs_xbmap(OSI_VC_ARG(avc), offset, count, flag, cr, bmv, nbmv) */ static void afs_strategy(OSI_VC_ARG(avc), bp) - OSI_VC_DECL(avc); +OSI_VC_DECL(avc); struct buf *bp; { uio_t auio; @@ -762,31 +766,31 @@ afs_strategy(OSI_VC_ARG(avc), bp) int error; struct cred *cr; OSI_VC_CONVERT(avc) - vnode_t *vp = (vnode_t *)avc; + vnode_t *vp = (vnode_t *) avc; /* * We can't afford DELWRI buffers for 2 reasons: * 1) Since we can call underlying EFS, we can require a - * buffer to flush a buffer. This leads to 2 potential - * recursions/deadlocks - * a) if all buffers are DELWRI afs buffers, then - * ngeteblk -> bwrite -> afs_strategy -> afs_write -> - * UFS_Write -> efs_write -> ngeteblk .... could - * recurse a long ways! - * b) brelse -> chunkhold which can call dchunkpush - * will look for any DELWRI buffers and call strategy - * on them. This can then end up via UFS_Write - * recursing + * buffer to flush a buffer. This leads to 2 potential + * recursions/deadlocks + * a) if all buffers are DELWRI afs buffers, then + * ngeteblk -> bwrite -> afs_strategy -> afs_write -> + * UFS_Write -> efs_write -> ngeteblk .... could + * recurse a long ways! + * b) brelse -> chunkhold which can call dchunkpush + * will look for any DELWRI buffers and call strategy + * on them. This can then end up via UFS_Write + * recursing * Current hack: - * a) We never do bdwrite(s) on AFS buffers. - * b) We call pdflush with B_ASYNC - * c) in chunkhold where it can set a buffer DELWRI - * we immediatly do a clusterwrite for AFS vp's + * a) We never do bdwrite(s) on AFS buffers. + * b) We call pdflush with B_ASYNC + * c) in chunkhold where it can set a buffer DELWRI + * we immediatly do a clusterwrite for AFS vp's * XXX Alas, 'c' got dropped in 5.1 so its possible to get DELWRI - * buffers if someone has mmaped the file and dirtied it then - * reads/faults it again. - * Instead - wherever we call chunkread/getchunk we check for a - * returned bp with DELWRI set, and write it out immediately + * buffers if someone has mmaped the file and dirtied it then + * reads/faults it again. + * Instead - wherever we call chunkread/getchunk we check for a + * returned bp with DELWRI set, and write it out immediately */ if (CheckLock(&avc->lock) && VN_GET_DBUF(vp)) { printf("WARN: afs_strategy vp=%x, v_dbuf=%x bp=%x\n", vp, @@ -796,8 +800,9 @@ afs_strategy(OSI_VC_ARG(avc), bp) iodone(bp); return; } - if (bp->b_error != 0) - printf("WARNING: afs_strategy3 vp=%x, bp=%x, err=%x\n", vp, bp, bp->b_error); + if (bp->b_error != 0) + printf("WARNING: afs_strategy3 vp=%x, bp=%x, err=%x\n", vp, bp, + bp->b_error); /* * To get credentials somewhat correct (we may be called from bdflush/ @@ -815,7 +820,7 @@ afs_strategy(OSI_VC_ARG(avc), bp) ReleaseReadLock(&avc->lock); return; } - } else if ((avc->states & CWritingUFS) && (bp->b_flags & B_DELWRI)) { + } else if ((avc->states & CWritingUFS) && (bp->b_flags & B_DELWRI)) { bp->b_ref = 3; ReleaseReadLock(&avc->lock); iodone(bp); @@ -864,27 +869,28 @@ afs_strategy(OSI_VC_ARG(avc), bp) } /* ARGSUSED */ -static int afs_seek(OSI_VC_ARG(avc), ooff, noffp) - OSI_VC_DECL(avc); - off_t ooff; - off_t *noffp; +static int +afs_seek(OSI_VC_ARG(avc), ooff, noffp) +OSI_VC_DECL(avc); + off_t ooff; + off_t *noffp; { - return *noffp < 0 ? EINVAL : 0; + return *noffp < 0 ? EINVAL : 0; } #if !defined(AFS_SGI65_ENV) /* Irix 6.5 uses addmap/delmap only for devices. */ /* ARGSUSED */ -static int afs_addmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, - flags, cr) - off_t off; - OSI_VC_DECL(avc); - struct pregion *prp; - addr_t addr; - size_t len; - u_int prot, maxprot; - u_int flags; - struct cred *cr; +static int +afs_addmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, flags, cr) + off_t off; +OSI_VC_DECL(avc); + struct pregion *prp; + addr_t addr; + size_t len; + u_int prot, maxprot; + u_int flags; + struct cred *cr; { OSI_VC_CONVERT(avc) struct vnode *vp = AFSTOV(avc); @@ -896,7 +902,7 @@ static int afs_addmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, AFS_RWLOCK(vp, VRWLOCK_WRITE); if (avc->mapcnt == 0) { /* on first mapping add a open reference */ - ObtainWriteLock(&avc->lock,237); + ObtainWriteLock(&avc->lock, 237); avc->execsOrWriters++; avc->opens++; ReleaseWriteLock(&avc->lock); @@ -906,17 +912,16 @@ static int afs_addmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, return 0; } -/*ARGSUSED*/ -static int afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, - flags, acred) - off_t off; - OSI_VC_DECL(avc); - struct pregion *prp; - addr_t addr; - size_t len; - u_int prot, maxprot; - u_int flags; - struct cred *acred; + /*ARGSUSED*/ static int +afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, flags, acred) + off_t off; +OSI_VC_DECL(avc); + struct pregion *prp; + addr_t addr; + size_t len; + u_int prot, maxprot; + u_int flags; + struct cred *acred; { OSI_VC_CONVERT(avc) struct vnode *vp = AFSTOV(avc); @@ -937,9 +942,9 @@ static int afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, osi_Assert(avc->execsOrWriters > 0); osi_Assert(avc->opens > 0); if (avc->m.LinkCount == 0) { - ObtainWriteLock(&avc->lock,238); + ObtainWriteLock(&avc->lock, 238); AFS_GUNLOCK(); - PTOSSVP(vp, (off_t)0, (off_t)MAXLONG); + PTOSSVP(vp, (off_t) 0, (off_t) MAXLONG); AFS_GLOCK(); ReleaseWriteLock(&avc->lock); } @@ -949,17 +954,18 @@ static int afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, afs_InitReq(&treq, acred); if (afs_BBusy()) { /* do it yourself if daemons are all busy */ - ObtainWriteLock(&avc->lock,239); + ObtainWriteLock(&avc->lock, 239); code = afs_StoreOnLastReference(avc, &treq); ReleaseWriteLock(&avc->lock); /* BStore does CheckCode so we should also */ /* VNOVNODE is "acceptable" error code from close, since - may happen when deleting a file on another machine while - it is open here. */ + * may happen when deleting a file on another machine while + * it is open here. */ if (code == VNOVNODE) code = 0; if (code) { - afs_StoreWarn(code, avc->fid.Fid.Volume, /* /dev/console */ 1); + afs_StoreWarn(code, avc->fid.Fid.Volume, /* /dev/console */ + 1); } code = afs_CheckCode(code, &treq, 52); AFS_RWUNLOCK(vp, VRWLOCK_WRITE); @@ -967,8 +973,8 @@ static int afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, AFS_RWUNLOCK(vp, VRWLOCK_WRITE); /* at least one daemon is idle, so ask it to do the store. * Also, note that we don't lock it any more... */ - tb = afs_BQueue(BOP_STORE, avc, 0, 1, acred, (long)acred->cr_uid, - 0L, 0L, 0L); + tb = afs_BQueue(BOP_STORE, avc, 0, 1, acred, + (afs_size_t) acred->cr_uid, 0L, (void *)0); /* sleep waiting for the store to start, then retrieve error code */ while ((tb->flags & BUVALID) == 0) { tb->flags |= BUWAIT; @@ -991,25 +997,26 @@ static int afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, * ever having been 'opened' */ #ifdef AFS_SGI65_ENV -static int afs_map(OSI_VC_ARG(avc), off, len, prot, flags, cr, vpp) +static int +afs_map(OSI_VC_ARG(avc), off, len, prot, flags, cr, vpp) off_t off; - OSI_VC_DECL(avc); +OSI_VC_DECL(avc); size_t len; mprot_t prot; u_int flags; struct cred *cr; vnode_t **vpp; #else -static int afs_map(OSI_VC_ARG(avc), off, prp, addrp, len, prot, maxprot, - flags, cr) - off_t off; - OSI_VC_DECL(avc); - struct pregion *prp; - addr_t *addrp; - size_t len; - u_int prot, maxprot; - u_int flags; - struct cred *cr; +static int +afs_map(OSI_VC_ARG(avc), off, prp, addrp, len, prot, maxprot, flags, cr) + off_t off; +OSI_VC_DECL(avc); + struct pregion *prp; + addr_t *addrp; + size_t len; + u_int prot, maxprot; + u_int flags; + struct cred *cr; #endif { OSI_VC_CONVERT(avc) @@ -1020,7 +1027,8 @@ static int afs_map(OSI_VC_ARG(avc), off, prp, addrp, len, prot, maxprot, /* get a validated vcache entry */ afs_InitReq(&treq, cr); error = afs_VerifyVCache(avc, &treq); - if (error) return afs_CheckCode(error, &treq, 53); + if (error) + return afs_CheckCode(error, &treq, 53); osi_FlushPages(avc, cr); /* ensure old pages are gone */ #ifdef AFS_SGI65_ENV @@ -1031,17 +1039,18 @@ static int afs_map(OSI_VC_ARG(avc), off, prp, addrp, len, prot, maxprot, AFS_RWLOCK(vp, VRWLOCK_WRITE); ObtainWriteLock(&avc->lock, 501); if (avc->execsOrWriters > 0) { - avc->execsOrWriters ++; - avc->opens ++; - avc->mapcnt ++; /* count eow's due to mappings. */ + avc->execsOrWriters++; + avc->opens++; + avc->mapcnt++; /* count eow's due to mappings. */ } ReleaseWriteLock(&avc->lock); AFS_RWUNLOCK(vp, VRWLOCK_WRITE); #else AFS_RWLOCK(vp, VRWLOCK_WRITE); AFS_GUNLOCK(); - error = fs_map_subr(vp, (off_t) avc->m.Length, (u_int)avc->m.Mode, off, prp, - *addrp, len, prot, maxprot, flags, cr); + error = + fs_map_subr(vp, (off_t) avc->m.Length, (u_int) avc->m.Mode, off, prp, + *addrp, len, prot, maxprot, flags, cr); AFS_GLOCK(); AFS_RWUNLOCK(vp, VRWLOCK_WRITE); #endif /* AFS_SGI65_ENV */ @@ -1061,17 +1070,17 @@ extern afs_lock_t afs_xdcache; #ifdef AFS_SGI64_ENV int #else -void +void #endif afs_xinactive(OSI_VC_ARG(avc), acred) - OSI_VC_DECL(avc); - struct ucred *acred; +OSI_VC_DECL(avc); + struct ucred *acred; { int s; OSI_VC_CONVERT(avc) - vnode_t *vp = (vnode_t *)avc; - int mapcnt = avc->mapcnt; /* We just clear off this many. */ - + vnode_t *vp = (vnode_t *) avc; + int mapcnt = avc->mapcnt; /* We just clear off this many. */ + AFS_STATCNT(afs_inactive); s = VN_LOCK(vp); @@ -1096,7 +1105,7 @@ afs_xinactive(OSI_VC_ARG(avc), acred) /* In Irix 6.5, the last unmap of a dirty mmap'd file does not * get an explicit vnode op. Instead we only find out at VOP_INACTIVE. */ - if (!afs_rwlock_nowait((vnode_t*)avc, VRWLOCK_WRITE)) { + if (!afs_rwlock_nowait((vnode_t *) avc, VRWLOCK_WRITE)) { return VN_INACTIVE_CACHE; } if (NBObtainWriteLock(&avc->lock, 502)) { @@ -1104,7 +1113,7 @@ afs_xinactive(OSI_VC_ARG(avc), acred) return VN_INACTIVE_CACHE; } if (avc->states & CUnlinked) { - if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) { + if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) { avc->states |= CUnlinkedDel; ReleaseWriteLock(&avc->lock); AFS_RWUNLOCK(vp, VRWLOCK_WRITE); @@ -1136,16 +1145,16 @@ afs_xinactive(OSI_VC_ARG(avc), acred) code = 0; if (code) { if (mapcnt) { - cmn_err(CE_WARN, "AFS: Failed to store FID (%x:%lu.%lu.%lu) in VOP_INACTIVE, error = %d\n", + cmn_err(CE_WARN, + "AFS: Failed to store FID (%x:%lu.%lu.%lu) in VOP_INACTIVE, error = %d\n", (int)(avc->fid.Cell) & 0xffffffff, - avc->fid.Fid.Volume, - avc->fid.Fid.Vnode, avc->fid.Fid.Unique, - code); + avc->fid.Fid.Volume, avc->fid.Fid.Vnode, + avc->fid.Fid.Unique, code); } - afs_InvalidateAllSegments(avc, 1); + afs_InvalidateAllSegments(avc); } s = VN_LOCK(vp); - vp->v_count --; + vp->v_count--; code = (vp->v_count == 0); VN_UNLOCK(vp, s); /* If the vnode is now in use by someone else, return early. */ @@ -1158,7 +1167,7 @@ afs_xinactive(OSI_VC_ARG(avc), acred) } #endif - osi_Assert((avc->states & (CCore|CMAPPED)) == 0); + osi_Assert((avc->states & (CCore | CMAPPED)) == 0); if (avc->cred) { crfree(avc->cred); @@ -1173,17 +1182,16 @@ afs_xinactive(OSI_VC_ARG(avc), acred) */ if (avc->m.LinkCount == 0) { AFS_GUNLOCK(); - PTOSSVP(vp, (off_t)0, (off_t)MAXLONG); + PTOSSVP(vp, (off_t) 0, (off_t) MAXLONG); AFS_GLOCK(); } - #ifndef AFS_SGI65_ENV osi_Assert(avc->mapcnt == 0); afs_chkpgoob(&avc->v, btoc(avc->m.Length)); - avc->states &= ~CDirty; /* Give up on store-backs */ + avc->states &= ~CDirty; /* Give up on store-backs */ if (avc->states & CUnlinked) { - if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) { + if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) { avc->states |= CUnlinkedDel; } else { afs_remunlink(avc, 1); /* ignore any return code */ @@ -1199,14 +1207,15 @@ static int afs_reclaim(OSI_VC_DECL(avc), int flag) { #ifdef AFS_SGI64_ENV - /* Get's called via VOP_RELCAIM in afs_FlushVCache to clear repl_vnodeops*/ + /* Get's called via VOP_RELCAIM in afs_FlushVCache to clear repl_vnodeops */ return 0; #else panic("afs_reclaim"); #endif } -void afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag) +void +afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag) { OSI_VN_CONVERT(vp) struct vcache *avc = VTOAFS(vp); @@ -1221,7 +1230,8 @@ void afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag) avc->vc_rwlockid = OSI_GET_LOCKID(); } -void afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag) +void +afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag) { OSI_VN_CONVERT(vp) struct vcache *avc = VTOAFS(vp); @@ -1242,7 +1252,8 @@ void afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag) * does not match the corresponding lock flag. But they may start using this * flag for a real rw lock at some time. */ -int afs_rwlock_nowait(vnode_t *vp, AFS_RWLOCK_T flag) +int +afs_rwlock_nowait(vnode_t * vp, AFS_RWLOCK_T flag) { struct vcache *avc = VTOAFS(vp); @@ -1253,25 +1264,26 @@ int afs_rwlock_nowait(vnode_t *vp, AFS_RWLOCK_T flag) } if (cpsema(&avc->vc_rwlock)) { avc->vc_rwlockid = OSI_GET_LOCKID(); - return 1; + return 1; } return 0; } #if defined(AFS_SGI64_ENV) && defined(CKPT) && !defined(_R5000_CVT_WAR) -int afs_fid2(OSI_VC_DECL(avc), struct fid *fidp) +int +afs_fid2(OSI_VC_DECL(avc), struct fid *fidp) { struct cell *tcell; - afs_fid2_t *afid = (afs_fid2_t*)fidp; + afs_fid2_t *afid = (afs_fid2_t *) fidp; OSI_VC_CONVERT(avc) - osi_Assert(sizeof(fid_t) >= sizeof(afs_fid2_t)); + osi_Assert(sizeof(fid_t) >= sizeof(afs_fid2_t)); afid->af_len = sizeof(afs_fid2_t) - sizeof(afid->af_len); tcell = afs_GetCell(avc->fid.Cell, READ_LOCK); afid->af_cell = tcell->cellIndex & 0xffff; afs_PutCell(tcell, READ_LOCK); - + afid->af_volid = avc->fid.Fid.Volume; afid->af_vno = avc->fid.Fid.Vnode; afid->af_uniq = avc->fid.Fid.Unique; @@ -1286,7 +1298,8 @@ int afs_fid2(OSI_VC_DECL(avc), struct fid *fidp) * * afs_fid2 is used to support the R5000 workarounds (_R5000_CVT_WAR) */ -int afs_fid2(OSI_VC_DECL(avc), struct fid *fidp) +int +afs_fid2(OSI_VC_DECL(avc), struct fid *fidp) { #if defined(_R5000_CVT_WAR) extern int R5000_cvt_war; @@ -1308,7 +1321,7 @@ int afs_fid2(OSI_VC_DECL(avc), struct fid *fidp) * Drop the global lock here, since we may not actually do the call. */ void -afs_chkpgoob(vnode_t *vp, pgno_t pgno) +afs_chkpgoob(vnode_t * vp, pgno_t pgno) { #undef PGDEBUG #ifdef PGDEBUG @@ -1328,485 +1341,542 @@ afs_chkpgoob(vnode_t *vp, pgno_t pgno) #endif #ifdef AFS_SGI64_ENV -int mp_afs_open(bhv_desc_t *bhp, vnode_t **a, mode_t b, struct cred *c) +int +mp_afs_open(bhv_desc_t * bhp, vnode_t ** a, mode_t b, struct cred *c) #else -int mp_afs_open(vnode_t **a, mode_t b, struct cred *c) +int +mp_afs_open(vnode_t ** a, mode_t b, struct cred *c) #endif { - int rv; - AFS_GLOCK(); + int rv; + AFS_GLOCK(); #ifdef AFS_SGI64_ENV - rv = afs_lockedvnodeops.vop_open(bhp, a, b, c); + rv = afs_lockedvnodeops.vop_open(bhp, a, b, c); #else - rv = afs_lockedvnodeops.vop_open(a, b, c); + rv = afs_lockedvnodeops.vop_open(a, b, c); #endif - AFS_GUNLOCK(); - return rv; + AFS_GUNLOCK(); + return rv; } #if defined(AFS_SGI64_ENV) #if defined(AFS_SGI65_ENV) -int mp_afs_close(AFS_MP_VC_ARG (*a), int b, lastclose_t c, struct cred *d) +int +mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, struct cred *d) #else -int mp_afs_close(AFS_MP_VC_ARG (*a), int b, lastclose_t c, off_t d, - struct cred *e, struct flid *f) +int +mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, off_t d, struct cred *e, + struct flid *f) #endif #else -int mp_afs_close(AFS_MP_VC_ARG (*a), int b, lastclose_t c, off_t d, - struct cred *e) +int +mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, off_t d, struct cred *e) #endif { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_close(a, b, c, d + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_close(a, b, c, d #if !defined(AFS_SGI65_ENV) - , e + , e #if defined(AFS_SGI64_ENV) - , f + , f #endif #endif - ); - - AFS_GUNLOCK(); - return rv; + ); + + AFS_GUNLOCK(); + return rv; } #ifdef AFS_SGI64_ENV -int mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d, - struct flid *f) +int +mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d, + struct flid *f) #else -int mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d) +int +mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d) #endif { - int rv; - AFS_GLOCK(); + int rv; + AFS_GLOCK(); #ifdef AFS_SGI64_ENV - rv = afs_lockedvnodeops.vop_read(a, b, c, d, f); + rv = afs_lockedvnodeops.vop_read(a, b, c, d, f); #else - rv = afs_lockedvnodeops.vop_read(a, b, c, d); + rv = afs_lockedvnodeops.vop_read(a, b, c, d); #endif - AFS_GUNLOCK(); - return rv; + AFS_GUNLOCK(); + return rv; } #ifdef AFS_SGI64_ENV -int mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d, - struct flid *f) +int +mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d, + struct flid *f) #else -int mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d) +int +mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d) #endif { - int rv; - AFS_GLOCK(); + int rv; + AFS_GLOCK(); #ifdef AFS_SGI64_ENV - rv = afs_lockedvnodeops.vop_write(a, b, c, d, f); + rv = afs_lockedvnodeops.vop_write(a, b, c, d, f); #else - rv = afs_lockedvnodeops.vop_write(a, b, c, d); + rv = afs_lockedvnodeops.vop_write(a, b, c, d); #endif - AFS_GUNLOCK(); - return rv; + AFS_GUNLOCK(); + return rv; } -int mp_afs_ioctl(AFS_MP_VC_ARG(*a), int b, void *c, int d, struct cred *e, - int *f +int +mp_afs_ioctl(AFS_MP_VC_ARG(*a), int b, void *c, int d, struct cred *e, int *f #ifdef AFS_SGI65_ENV - , struct vopbd *vbds + , struct vopbd *vbds #endif - ) + ) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_ioctl(a, b, c, d, e, f + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_ioctl(a, b, c, d, e, f #ifdef AFS_SGI65_ENV - , vbds + , vbds #endif - ); - AFS_GUNLOCK(); - return rv; + ); + AFS_GUNLOCK(); + return rv; } -int mp_fs_setfl(AFS_MP_VC_ARG(*a), int b, int c, struct cred *d) +int +mp_fs_setfl(AFS_MP_VC_ARG(*a), int b, int c, struct cred *d) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_setfl(a, b, c, d); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_setfl(a, b, c, d); + AFS_GUNLOCK(); + return rv; } -int mp_afs_getattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d) + +int +mp_afs_getattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_getattr(a, b, c, d); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_getattr(a, b, c, d); + AFS_GUNLOCK(); + return rv; } -int mp_afs_setattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d) + +int +mp_afs_setattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_setattr(a, b, c, d); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_setattr(a, b, c, d); + AFS_GUNLOCK(); + return rv; } -int mp_afs_access(AFS_MP_VC_ARG(*a), int b, +int +mp_afs_access(AFS_MP_VC_ARG(*a), int b, #ifndef AFS_SGI65_ENV - int c, + int c, #endif - struct cred *d) + struct cred *d) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_access(a, b, + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_access(a, b, #ifndef AFS_SGI65_ENV - c, + c, #endif - d); - AFS_GUNLOCK(); - return rv; + d); + AFS_GUNLOCK(); + return rv; } -int mp_afs_lookup(AFS_MP_VC_ARG(*a), char *b, vnode_t **c, struct pathname *d, - int e, vnode_t *f, struct cred *g) +int +mp_afs_lookup(AFS_MP_VC_ARG(*a), char *b, vnode_t ** c, struct pathname *d, + int e, vnode_t * f, struct cred *g) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_lookup(a, b, c, d, e, f, g); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_lookup(a, b, c, d, e, f, g); + AFS_GUNLOCK(); + return rv; } + #ifdef AFS_SGI64_ENV -int mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, int d, int e, - vnode_t **f, struct cred *g) +int +mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, int d, int e, + vnode_t ** f, struct cred *g) #else -int mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, enum vcexcl d, - int e, vnode_t **f, struct cred *g) +int +mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, enum vcexcl d, + int e, vnode_t ** f, struct cred *g) #endif { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_create(a, b, c, d, e, f, g); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_create(a, b, c, d, e, f, g); + AFS_GUNLOCK(); + return rv; } -int mp_afs_remove(AFS_MP_VC_ARG(*a), char *b, struct cred *c) + +int +mp_afs_remove(AFS_MP_VC_ARG(*a), char *b, struct cred *c) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_remove(a, b, c); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_remove(a, b, c); + AFS_GUNLOCK(); + return rv; } -int mp_afs_link(AFS_MP_VC_ARG(*a), vnode_t *b, char *c, struct cred *d) + +int +mp_afs_link(AFS_MP_VC_ARG(*a), vnode_t * b, char *c, struct cred *d) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_link(a, b, c, d); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_link(a, b, c, d); + AFS_GUNLOCK(); + return rv; } -int mp_afs_rename(AFS_MP_VC_ARG(*a), char *b, vnode_t *c, char *d, - struct pathname *e, struct cred *f) + +int +mp_afs_rename(AFS_MP_VC_ARG(*a), char *b, vnode_t * c, char *d, + struct pathname *e, struct cred *f) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_rename(a, b, c, d, e, f); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_rename(a, b, c, d, e, f); + AFS_GUNLOCK(); + return rv; } -int mp_afs_mkdir(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, vnode_t **d, - struct cred *e) + +int +mp_afs_mkdir(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, vnode_t ** d, + struct cred *e) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_mkdir(a, b, c, d, e); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_mkdir(a, b, c, d, e); + AFS_GUNLOCK(); + return rv; } -int mp_afs_rmdir(AFS_MP_VC_ARG(*a), char *b, vnode_t *c, struct cred *d) + +int +mp_afs_rmdir(AFS_MP_VC_ARG(*a), char *b, vnode_t * c, struct cred *d) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_rmdir(a, b, c, d); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_rmdir(a, b, c, d); + AFS_GUNLOCK(); + return rv; } -int mp_afs_readdir(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c, int *d) + +int +mp_afs_readdir(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c, int *d) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_readdir(a, b, c, d); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_readdir(a, b, c, d); + AFS_GUNLOCK(); + return rv; } -int mp_afs_symlink(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, char *d, - struct cred *e) + +int +mp_afs_symlink(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, char *d, + struct cred *e) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_symlink(a, b, c, d, e); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_symlink(a, b, c, d, e); + AFS_GUNLOCK(); + return rv; } -int mp_afs_readlink(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c) + +int +mp_afs_readlink(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_readlink(a, b, c); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_readlink(a, b, c); + AFS_GUNLOCK(); + return rv; } -int mp_afs_fsync(AFS_MP_VC_ARG(*a), int b, struct cred *c +int +mp_afs_fsync(AFS_MP_VC_ARG(*a), int b, struct cred *c #ifdef AFS_SGI65_ENV - , off_t start, off_t stop + , off_t start, off_t stop #endif - ) + ) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_fsync(a, b, c + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_fsync(a, b, c #ifdef AFS_SGI65_ENV - , start, stop + , start, stop #endif - ); - AFS_GUNLOCK(); - return rv; + ); + AFS_GUNLOCK(); + return rv; } -void mp_afs_inactive(AFS_MP_VC_ARG(*a), struct cred *b) +void +mp_afs_inactive(AFS_MP_VC_ARG(*a), struct cred *b) { - AFS_GLOCK(); - afs_lockedvnodeops.vop_inactive(a, b); - AFS_GUNLOCK(); - return; + AFS_GLOCK(); + afs_lockedvnodeops.vop_inactive(a, b); + AFS_GUNLOCK(); + return; } -int mp_afs_fid(AFS_MP_VC_ARG(*a), struct fid **b) + +int +mp_afs_fid(AFS_MP_VC_ARG(*a), struct fid **b) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_fid(a, b); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_fid(a, b); + AFS_GUNLOCK(); + return rv; } -int mp_afs_fid2(AFS_MP_VC_ARG(*a), struct fid *b) + +int +mp_afs_fid2(AFS_MP_VC_ARG(*a), struct fid *b) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_fid2(a, b); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_fid2(a, b); + AFS_GUNLOCK(); + return rv; } -void mp_afs_rwlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b) + +void +mp_afs_rwlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b) { - AFS_GLOCK(); - afs_rwlock(a, VRWLOCK_WRITE); - AFS_GUNLOCK(); + AFS_GLOCK(); + afs_rwlock(a, VRWLOCK_WRITE); + AFS_GUNLOCK(); } -void mp_afs_rwunlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b) + +void +mp_afs_rwunlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b) { - AFS_GLOCK(); - afs_rwunlock(a, VRWLOCK_WRITE); - AFS_GUNLOCK(); + AFS_GLOCK(); + afs_rwunlock(a, VRWLOCK_WRITE); + AFS_GUNLOCK(); } -int mp_afs_seek(AFS_MP_VC_ARG(*a), off_t b, off_t*c) + +int +mp_afs_seek(AFS_MP_VC_ARG(*a), off_t b, off_t * c) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_seek(a, b, c); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_seek(a, b, c); + AFS_GUNLOCK(); + return rv; } -int mp_fs_cmp(AFS_MP_VC_ARG(*a), vnode_t *b) + +int +mp_fs_cmp(AFS_MP_VC_ARG(*a), vnode_t * b) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_cmp(a, b); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_cmp(a, b); + AFS_GUNLOCK(); + return rv; } -int mp_afs_frlock(AFS_MP_VC_ARG(*a), int b, struct flock *c, int d, off_t e, +int +mp_afs_frlock(AFS_MP_VC_ARG(*a), int b, struct flock *c, int d, off_t e, #ifdef AFS_SGI65_ENV - vrwlock_t vrwlock, + vrwlock_t vrwlock, #endif - struct cred *f) + struct cred *f) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_frlock(a, b, c, d, e, + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_frlock(a, b, c, d, e, #ifdef AFS_SGI65_ENV - vrwlock, + vrwlock, #endif - f); - AFS_GUNLOCK(); - return rv; + f); + AFS_GUNLOCK(); + return rv; } -int mp_afs_realvp(AFS_MP_VC_ARG(*a), vnode_t **b) +int +mp_afs_realvp(AFS_MP_VC_ARG(*a), vnode_t ** b) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_realvp(a, b); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_realvp(a, b); + AFS_GUNLOCK(); + return rv; } -int mp_afs_bmap(AFS_MP_VC_ARG(*a), off_t b, ssize_t c, int d, struct cred *e, - struct bmapval *f, int *g) + +int +mp_afs_bmap(AFS_MP_VC_ARG(*a), off_t b, ssize_t c, int d, struct cred *e, + struct bmapval *f, int *g) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_bmap(a, b, c, d, e, f, g); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_bmap(a, b, c, d, e, f, g); + AFS_GUNLOCK(); + return rv; } -void mp_afs_strategy(AFS_MP_VC_ARG(*a), struct buf *b) +void +mp_afs_strategy(AFS_MP_VC_ARG(*a), struct buf *b) { - int rv; - AFS_GLOCK(); - afs_lockedvnodeops.vop_strategy(a, b); - AFS_GUNLOCK(); - return; + int rv; + AFS_GLOCK(); + afs_lockedvnodeops.vop_strategy(a, b); + AFS_GUNLOCK(); + return; } #ifdef AFS_SGI65_ENV -int mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, size_t c, mprot_t d, - u_int e, struct cred *f, vnode_t **g) +int +mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, size_t c, mprot_t d, u_int e, + struct cred *f, vnode_t ** g) #else -int mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, char ** d, - size_t e, u_int f, u_int g, u_int h, struct cred *i) +int +mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, char **d, size_t e, + u_int f, u_int g, u_int h, struct cred *i) #endif { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_map(a, b, c, d, e, f, g + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_map(a, b, c, d, e, f, g #ifndef AFS_SGI65_ENV - , h, i + , h, i #endif - ); - AFS_GUNLOCK(); - return rv; + ); + AFS_GUNLOCK(); + return rv; } #ifndef AFS_SGI65_ENV /* As of Irix 6.5, addmap and delmap are only for devices */ -int mp_afs_addmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d, - size_t e, u_int f, u_int g, u_int h, struct cred *i) +int +mp_afs_addmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d, + size_t e, u_int f, u_int g, u_int h, struct cred *i) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_addmap(a, b, c, d, e, f, g, h, i); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_addmap(a, b, c, d, e, f, g, h, i); + AFS_GUNLOCK(); + return rv; } -int mp_afs_delmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d, - size_t e, u_int f, u_int g, u_int h, struct cred *i) +int +mp_afs_delmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d, + size_t e, u_int f, u_int g, u_int h, struct cred *i) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_delmap(a, b, c, d, e, f, g, h, i); - AFS_GUNLOCK(); - return rv; + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_delmap(a, b, c, d, e, f, g, h, i); + AFS_GUNLOCK(); + return rv; } #endif /* ! AFS_SGI65_ENV */ -int mp_fs_poll(AFS_MP_VC_ARG(*a), short b, int c, short *d, - struct pollhead **e +int +mp_fs_poll(AFS_MP_VC_ARG(*a), short b, int c, short *d, struct pollhead **e #ifdef AFS_SGI65_ENV - , unsigned int *f + , unsigned int *f #endif - ) + ) { - int rv; - AFS_GLOCK(); - rv = afs_lockedvnodeops.vop_poll(a, b, c, d, e + int rv; + AFS_GLOCK(); + rv = afs_lockedvnodeops.vop_poll(a, b, c, d, e #ifdef AFS_SGI65_ENV - , f + , f #endif - ); - AFS_GUNLOCK(); - return rv; + ); + AFS_GUNLOCK(); + return rv; } struct vnodeops Afs_vnodeops = { #ifdef AFS_SGI64_ENV #ifdef AFS_SGI65_ENV - BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE), + BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE), #else - VNODE_POSITION_BASE, -#endif -#endif - mp_afs_open, - mp_afs_close, - mp_afs_read, - mp_afs_write, - mp_afs_ioctl, - mp_fs_setfl, - mp_afs_getattr, - mp_afs_setattr, - mp_afs_access, - mp_afs_lookup, - mp_afs_create, - mp_afs_remove, - mp_afs_link, - mp_afs_rename, - mp_afs_mkdir, - mp_afs_rmdir, - mp_afs_readdir, - mp_afs_symlink, - mp_afs_readlink, - mp_afs_fsync, - mp_afs_inactive, - mp_afs_fid, - mp_afs_fid2, - mp_afs_rwlock, - mp_afs_rwunlock, - mp_afs_seek, - mp_fs_cmp, - mp_afs_frlock, - fs_nosys, /* realvp */ - mp_afs_bmap, - mp_afs_strategy, - mp_afs_map, + VNODE_POSITION_BASE, +#endif +#endif + mp_afs_open, + mp_afs_close, + mp_afs_read, + mp_afs_write, + mp_afs_ioctl, + mp_fs_setfl, + mp_afs_getattr, + mp_afs_setattr, + mp_afs_access, + mp_afs_lookup, + mp_afs_create, + mp_afs_remove, + mp_afs_link, + mp_afs_rename, + mp_afs_mkdir, + mp_afs_rmdir, + mp_afs_readdir, + mp_afs_symlink, + mp_afs_readlink, + mp_afs_fsync, + mp_afs_inactive, + mp_afs_fid, + mp_afs_fid2, + mp_afs_rwlock, + mp_afs_rwunlock, + mp_afs_seek, + mp_fs_cmp, + mp_afs_frlock, + fs_nosys, /* realvp */ + mp_afs_bmap, + mp_afs_strategy, + mp_afs_map, #ifdef AFS_SGI65_ENV - fs_noerr, /* addmap - devices only */ - fs_noerr, /* delmap - devices only */ + fs_noerr, /* addmap - devices only */ + fs_noerr, /* delmap - devices only */ #else - mp_afs_addmap, - mp_afs_delmap, -#endif - mp_fs_poll, /* poll */ - fs_nosys, /* dump */ - fs_pathconf, - fs_nosys, /* allocstore */ - fs_nosys, /* fcntl */ - afs_reclaim, /* reclaim */ - fs_nosys, /* attr_get */ - fs_nosys, /* attr_set */ - fs_nosys, /* attr_remove */ - fs_nosys, /* attr_list */ + mp_afs_addmap, + mp_afs_delmap, +#endif + mp_fs_poll, /* poll */ + fs_nosys, /* dump */ + fs_pathconf, + fs_nosys, /* allocstore */ + fs_nosys, /* fcntl */ + afs_reclaim, /* reclaim */ + fs_nosys, /* attr_get */ + fs_nosys, /* attr_set */ + fs_nosys, /* attr_remove */ + fs_nosys, /* attr_list */ #ifdef AFS_SGI64_ENV #ifdef AFS_SGI65_ENV - fs_cover, - (vop_link_removed_t)fs_noval, - fs_vnode_change, - fs_tosspages, - fs_flushinval_pages, - fs_flush_pages, - fs_invalfree_pages, - fs_pages_sethole, - (vop_commit_t)fs_nosys, - (vop_readbuf_t)fs_nosys, - fs_strgetmsg, - fs_strputmsg, + fs_cover, + (vop_link_removed_t) fs_noval, + fs_vnode_change, + fs_tosspages, + fs_flushinval_pages, + fs_flush_pages, + fs_invalfree_pages, + fs_pages_sethole, + (vop_commit_t) fs_nosys, + (vop_readbuf_t) fs_nosys, + fs_strgetmsg, + fs_strputmsg, #else - fs_mount, + fs_mount, #endif #endif }; @@ -1823,15 +1893,16 @@ struct vnodeops *afs_ops = &Afs_vnodeops; int afs_CacheFSType = -1; vnodeops_t *afs_efs_vnodeopsp; vnodeops_t *afs_xfs_vnodeopsp; -vnode_t * (*afs_IGetVnode)(ino_t); +vnode_t *(*afs_IGetVnode) (ino_t); -extern vnode_t *afs_EFSIGetVnode(ino_t); /* defined in osi_file.c */ -extern vnode_t *afs_XFSIGetVnode(ino_t); /* defined in osi_file.c */ +extern vnode_t *afs_EFSIGetVnode(ino_t); /* defined in osi_file.c */ +extern vnode_t *afs_XFSIGetVnode(ino_t); /* defined in osi_file.c */ -extern afs_lock_t afs_xosi; /* lock is for tvattr */ +extern afs_lock_t afs_xosi; /* lock is for tvattr */ /* Initialize the cache operations. Called while initializing cache files. */ -void afs_InitDualFSCacheOps(struct vnode *vp) +void +afs_InitDualFSCacheOps(struct vnode *vp) { static int inited = 0; struct vfssw *swp; @@ -1845,8 +1916,8 @@ void afs_InitDualFSCacheOps(struct vnode *vp) #ifdef AFS_SGI_EFS_IOPS_ENV swp = vfs_getvfssw("efs"); if (swp) { - afs_efs_vnodeopsp = swp->vsw_vnodeops; - if(vp && vp->v_op == afs_efs_vnodeopsp) { + afs_efs_vnodeopsp = swp->vsw_vnodeops; + if (vp && vp->v_op == afs_efs_vnodeopsp) { afs_CacheFSType = AFS_SGI_EFS_CACHE; afs_IGetVnode = afs_EFSIGetVnode; found = 1; @@ -1858,7 +1929,7 @@ void afs_InitDualFSCacheOps(struct vnode *vp) if (swp) { afs_xfs_vnodeopsp = swp->vsw_vnodeops; if (!found) { - if (vp &&vp->v_op == afs_xfs_vnodeopsp) { + if (vp && vp->v_op == afs_xfs_vnodeopsp) { afs_CacheFSType = AFS_SGI_XFS_CACHE; afs_IGetVnode = afs_XFSIGetVnode; found = 1; @@ -1866,18 +1937,19 @@ void afs_InitDualFSCacheOps(struct vnode *vp) } } - if (vp && !found) + if (vp && !found) osi_Panic("osi_InitCacheFSType: Can't find fstype for vnode 0x%llx\n", vp); } -ino_t VnodeToIno(vnode_t *vp) +ino_t +VnodeToIno(vnode_t * vp) { int code; struct vattr vattr; - MObtainWriteLock(&afs_xosi,579); - vattr.va_mask = AT_FSID|AT_NODEID; /* quick return using this mask. */ + MObtainWriteLock(&afs_xosi, 579); + vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */ AFS_GUNLOCK(); AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code); AFS_GLOCK(); @@ -1888,13 +1960,14 @@ ino_t VnodeToIno(vnode_t *vp) return vattr.va_nodeid; } -dev_t VnodeToDev(vnode_t *vp) +dev_t +VnodeToDev(vnode_t * vp) { int code; struct vattr vattr; - MObtainWriteLock(&afs_xosi,580); - vattr.va_mask = AT_FSID|AT_NODEID; /* quick return using this mask. */ + MObtainWriteLock(&afs_xosi, 580); + vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */ AFS_GUNLOCK(); AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code); AFS_GLOCK(); @@ -1902,15 +1975,16 @@ dev_t VnodeToDev(vnode_t *vp) osi_Panic("VnodeToDev"); } MReleaseWriteLock(&afs_xosi); - return (dev_t)vattr.va_fsid; + return (dev_t) vattr.va_fsid; } -off_t VnodeToSize(vnode_t *vp) +off_t +VnodeToSize(vnode_t * vp) { int code; struct vattr vattr; - MObtainWriteLock(&afs_xosi,581); + MObtainWriteLock(&afs_xosi, 581); vattr.va_mask = AT_SIZE; AFS_GUNLOCK(); AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code); diff --git a/src/afs/LINUX/osi_alloc.c b/src/afs/LINUX/osi_alloc.c index 37dd1acb2..2a6440713 100644 --- a/src/afs/LINUX/osi_alloc.c +++ b/src/afs/LINUX/osi_alloc.c @@ -12,25 +12,26 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_alloc.c,v 1.1.1.12 2003/07/30 17:08:09 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_alloc.c,v 1.21 2004/04/12 16:04:32 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../h/mm.h" -#include "../h/slab.h" +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "h/mm.h" +#include "h/slab.h" -#include "../afs/afs_atomlist.h" -#include "../afs/afs_lhash.h" +#include "afs_atomlist.h" +#include "afs_lhash.h" -#define MAX_KMALLOC_SIZE PAGE_SIZE /* Max we should alloc with kmalloc */ -#define MAX_BUCKET_LEN 30 /* max. no. of entries per buckets we expect to see */ -#define STAT_INTERVAL 8192 /* we collect stats once every STAT_INTERVAL allocs*/ +#define MAX_KMALLOC_SIZE PAGE_SIZE /* Max we should alloc with kmalloc */ +#define MAX_BUCKET_LEN 30 /* max. no. of entries per buckets we expect to see */ +#define STAT_INTERVAL 8192 /* we collect stats once every STAT_INTERVAL allocs */ /* types of alloc */ -#define KM_TYPE 1 /* kmalloc */ -#define VM_TYPE 2 /* vmalloc */ +#define KM_TYPE 1 /* kmalloc */ +#define VM_TYPE 2 /* vmalloc */ struct osi_linux_mem { void *chunk; @@ -41,30 +42,31 @@ struct osi_linux_mem { #define MEMADDR(A) (void *)((unsigned long)(A) & (~0x3)) /* globals */ -afs_atomlist *al_mem_pool; /* pool of osi_linux_mem structures */ -afs_lhash *lh_mem_htab; /* mem hash table */ -unsigned int allocator_init = 0; /* has the allocator been initialized? */ +afs_atomlist *al_mem_pool; /* pool of osi_linux_mem structures */ +afs_lhash *lh_mem_htab; /* mem hash table */ +unsigned int allocator_init = 0; /* has the allocator been initialized? */ unsigned int afs_linux_cur_allocs = 0; unsigned int afs_linux_total_allocs = 0; -unsigned int afs_linux_hash_verify_count = 0; /* used by hash_verify */ -struct afs_lhash_stat afs_linux_lsb; /* hash table statistics */ -unsigned int afs_linux_hash_bucket_dist[MAX_BUCKET_LEN]; /* bucket population distribution in our hash table */ +unsigned int afs_linux_hash_verify_count = 0; /* used by hash_verify */ +struct afs_lhash_stat afs_linux_lsb; /* hash table statistics */ +unsigned int afs_linux_hash_bucket_dist[MAX_BUCKET_LEN]; /* bucket population distribution in our hash table */ #if defined(AFS_LINUX24_ENV) -#include "../h/vmalloc.h" +#include "h/vmalloc.h" #else /* externs : can we do this in a better way. Including vmalloc.h causes other * problems.*/ -extern void vfree(void * addr); +extern void vfree(void *addr); extern void *vmalloc(unsigned long size); #endif /* Allocator support functions (static) */ -static int hash_equal(const void *a, const void *b) +static int +hash_equal(const void *a, const void *b) { - return ( MEMADDR(((struct osi_linux_mem *)a)->chunk) == - MEMADDR(((struct osi_linux_mem *)b)->chunk) ); + return (MEMADDR(((struct osi_linux_mem *)a)->chunk) == + MEMADDR(((struct osi_linux_mem *)b)->chunk)); } @@ -76,30 +78,30 @@ static int hash_equal(const void *a, const void *b) * returns NULL if we failed to allocate memory. * or pointer to memory if we succeeded. */ -static void *linux_alloc(unsigned int asize, int drop_glock) +static void * +linux_alloc(unsigned int asize, int drop_glock) { void *new = NULL; int max_retry = 10; int haveGlock = ISAFS_GLOCK(); /* if we can use kmalloc use it to allocate the required memory. */ - while(!new && max_retry) - { - if (asize <= MAX_KMALLOC_SIZE) { - new = (void *)(unsigned long)kmalloc(asize, + while (!new && max_retry) { + if (asize <= MAX_KMALLOC_SIZE) { + new = (void *)(unsigned long)kmalloc(asize, #ifdef GFP_NOFS - GFP_NOFS + GFP_NOFS #else - GFP_KERNEL + GFP_KERNEL #endif - ); - if (new) /* piggy back alloc type */ - (unsigned long)new |= KM_TYPE; - } else { - new = (void *)vmalloc(asize); - if (new) /* piggy back alloc type */ - (unsigned long)new |= VM_TYPE; - } + ); + if (new) /* piggy back alloc type */ + (unsigned long)new |= KM_TYPE; + } else { + new = (void *)vmalloc(asize); + if (new) /* piggy back alloc type */ + (unsigned long)new |= VM_TYPE; + } if (!new) { #ifdef set_current_state @@ -107,16 +109,18 @@ static void *linux_alloc(unsigned int asize, int drop_glock) #else current->state = TASK_INTERRUPTIBLE; #endif - if (drop_glock && haveGlock) AFS_GUNLOCK(); + if (drop_glock && haveGlock) + AFS_GUNLOCK(); schedule_timeout(HZ); - if (drop_glock && haveGlock) AFS_GLOCK(); + if (drop_glock && haveGlock) + AFS_GLOCK(); #ifdef set_current_state - set_current_state(TASK_RUNNING); + set_current_state(TASK_RUNNING); #else - current->state = TASK_RUNNING; + current->state = TASK_RUNNING; #endif - --max_retry; - } + --max_retry; + } } if (new) memset(MEMADDR(new), 0, asize); @@ -124,23 +128,24 @@ static void *linux_alloc(unsigned int asize, int drop_glock) return new; } -static void linux_free(void *p) +static void +linux_free(void *p) { - + /* mask out the type information from the pointer and - * use the appropriate free routine to free the chunk. + * use the appropriate free routine to free the chunk. */ - switch(MEMTYPE(p)) { - case KM_TYPE: - kfree(MEMADDR(p)); - break; - case VM_TYPE: - vfree(MEMADDR(p)); - break; - default: - printf("afs_osi_Free: Asked to free unknown type %d at 0x%x\n", - MEMTYPE(p), MEMADDR(p)); - break; + switch (MEMTYPE(p)) { + case KM_TYPE: + kfree(MEMADDR(p)); + break; + case VM_TYPE: + vfree(MEMADDR(p)); + break; + default: + printf("afs_osi_Free: Asked to free unknown type %d at 0x%x\n", + MEMTYPE(p), MEMADDR(p)); + break; } } @@ -152,12 +157,13 @@ static void linux_free(void *p) */ #define HASH_CONST 32786 #define HASH_PRIME 79367 -static unsigned hash_chunk(void *p) +static unsigned +hash_chunk(void *p) { unsigned int key; key = (unsigned int)(long)p >> 2; - key = (key * HASH_CONST)%HASH_PRIME; + key = (key * HASH_CONST) % HASH_PRIME; return key; } @@ -188,25 +194,18 @@ hash_verify(size_t index, unsigned key, void *data) int memtype; memtype = MEMTYPE(lmp->chunk); -#if defined(AFS_SPARC64_LINUX24_ENV) || defined(AFS_I386_UMLINUX20_ENV) - if ((memtype == KM_TYPE) && (!VALID_PAGE(virt_to_page(lmp->chunk)))) { - printf("osi_linux_verify_alloced_memory: address 0x%x outside range, index=%d, key=%d\n", lmp->chunk, index, key); - } -#else - if ((memtype == KM_TYPE) && (AFS_LINUX_MAP_NR(lmp->chunk) > max_mapnr)) { - printf("osi_linux_verify_alloced_memory: address 0x%x outside range, index=%d, key=%d\n", lmp->chunk, index, key); - } -#endif - if (memtype != KM_TYPE && memtype != VM_TYPE) { - printf("osi_linux_verify_alloced_memory: unknown type %d at 0x%x, index=%d\n", memtype, lmp->chunk, index); + printf + ("osi_linux_verify_alloced_memory: unknown type %d at 0x%x, index=%d\n", + memtype, lmp->chunk, index); } afs_linux_hash_verify_count++; } /* local_free() : wrapper for vfree(), to deal with incompatible protoypes */ -static void local_free(void *p, size_t n) +static void +local_free(void *p, size_t n) { vfree(p); } @@ -218,57 +217,62 @@ static void local_free(void *p, size_t n) * 0 - failure * 1 - success */ -static int linux_alloc_init() +static int +linux_alloc_init() { /* initiate our pool of osi_linux_mem structs */ - al_mem_pool = afs_atomlist_create(sizeof(struct osi_linux_mem), - sizeof(long)*1024, (void *)vmalloc, - local_free); + al_mem_pool = + afs_atomlist_create(sizeof(struct osi_linux_mem), sizeof(long) * 1024, + (void *)vmalloc, local_free); if (!al_mem_pool) { - printf("afs_osi_Alloc: Error in initialization(atomlist_create)\n"); - return 0; + printf("afs_osi_Alloc: Error in initialization(atomlist_create)\n"); + return 0; } /* initialize the hash table to hold references to alloc'ed chunks */ lh_mem_htab = afs_lhash_create(hash_equal, (void *)vmalloc, local_free); if (!lh_mem_htab) { - printf("afs_osi_Alloc: Error in initialization(lhash_create)\n"); - return 0; + printf("afs_osi_Alloc: Error in initialization(lhash_create)\n"); + return 0; } - + return 1; - + } /* hash_bucket_stat() : Counts the no. of elements in each bucket and * stores results in our bucket stats vector. */ static unsigned int cur_bucket, cur_bucket_len; -static void hash_bucket_stat(size_t index, unsigned key, void *data) +static void +hash_bucket_stat(size_t index, unsigned key, void *data) { - if (index == cur_bucket) { + if (index == cur_bucket) { /* while still on the same bucket, inc len & return */ cur_bucket_len++; return; - } - else { /* if we're on the next bucket, store the distribution */ + } else { /* if we're on the next bucket, store the distribution */ if (cur_bucket_len < MAX_BUCKET_LEN) afs_linux_hash_bucket_dist[cur_bucket_len]++; else - printf("afs_get_hash_stats: Warning! exceeded max bucket len %d\n", cur_bucket_len); + printf + ("afs_get_hash_stats: Warning! exceeded max bucket len %d\n", + cur_bucket_len); cur_bucket = index; cur_bucket_len = 1; } } + /* get_hash_stats() : get hash table statistics */ -static void get_hash_stats() +static void +get_hash_stats() { int i; afs_lhash_stat(lh_mem_htab, &afs_linux_lsb); /* clear out the bucket stat vector */ - for(i=0;ichunk); /* this contains the piggybacked type info*/ - afs_atomlist_put(al_mem_pool, lmp); /* return osi_linux_mem struct to pool*/ - afs_linux_cur_allocs--; - } - else { - printf("osi_linux_free: failed to remove chunk from hashtable\n"); + if ((lmp = + (struct osi_linux_mem *)afs_lhash_remove(lh_mem_htab, + hash_chunk(addr), &lmem))) { + linux_free(lmp->chunk); /* this contains the piggybacked type info */ + afs_atomlist_put(al_mem_pool, lmp); /* return osi_linux_mem struct to pool */ + afs_linux_cur_allocs--; + } else { + printf("osi_linux_free: failed to remove chunk from hashtable\n"); } up(&afs_linux_alloc_sem); @@ -364,7 +371,8 @@ void osi_linux_free(void *addr) /* osi_linux_free_afs_memory() - free all chunks of memory allocated. */ -void osi_linux_free_afs_memory(void) +void +osi_linux_free_afs_memory(void) { down(&afs_linux_alloc_sem); @@ -379,20 +387,21 @@ void osi_linux_free_afs_memory(void) /* free the hashlist. */ afs_lhash_destroy(lh_mem_htab); - + /* change the state so that the allocator is now uninitialized. */ allocator_init = 0; } - up(&afs_linux_alloc_sem); + up(&afs_linux_alloc_sem); } /* osi_linux_verify_alloced_memory(): verify all chunks of alloced memory in * our hash table. */ -void osi_linux_verify_alloced_memory() +void +osi_linux_verify_alloced_memory() { down(&afs_linux_alloc_sem); - + /* count of times hash_verify was called. reset it to 0 before iteration */ afs_linux_hash_verify_count = 0; @@ -401,10 +410,11 @@ void osi_linux_verify_alloced_memory() if (afs_linux_hash_verify_count != afs_linux_cur_allocs) { /* hmm, some pieces of memory are missing. */ - printf("osi_linux_verify_alloced_memory: %d chunks of memory are not accounted for during verify!\n", afs_linux_hash_verify_count - afs_linux_cur_allocs); + printf + ("osi_linux_verify_alloced_memory: %d chunks of memory are not accounted for during verify!\n", + afs_linux_hash_verify_count - afs_linux_cur_allocs); } up(&afs_linux_alloc_sem); return; } - diff --git a/src/afs/LINUX/osi_cred.c b/src/afs/LINUX/osi_cred.c index 5701b29e6..a4c499fc9 100644 --- a/src/afs/LINUX/osi_cred.c +++ b/src/afs/LINUX/osi_cred.c @@ -12,15 +12,16 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_cred.c,v 1.4 2001/07/15 07:22:26 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_cred.c,v 1.10 2004/04/21 02:20:23 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" +#include "afs/sysincludes.h" +#include "afsincludes.h" /* Setup a pool for creds. Allocate several at a time. */ -#define CRED_ALLOC_STEP 29 /* at 140 bytes/cred = 4060 bytes. */ +#define CRED_ALLOC_STEP 29 /* at 140 bytes/cred = 4060 bytes. */ static cred_t *cred_pool = NULL; @@ -39,7 +40,8 @@ static struct semaphore linux_cred_pool_lock = MUTEX; #define CRED_LOCK() down(&linux_cred_pool_lock) #define CRED_UNLOCK() up(&linux_cred_pool_lock) -cred_t *crget(void) +cred_t * +crget(void) { cred_t *tmp; int i; @@ -47,27 +49,34 @@ cred_t *crget(void) CRED_LOCK(); if (!cred_pool) { cred_allocs++; - cred_pool = (cred_t*)osi_Alloc(CRED_ALLOC_STEP * sizeof(cred_t)); + cred_pool = (cred_t *) osi_Alloc(CRED_ALLOC_STEP * sizeof(cred_t)); if (!cred_pool) osi_Panic("crget: No more memory for creds!\n"); - - for (i=0; i < CRED_ALLOC_STEP-1; i++) - cred_pool[i].cr_ref = (long)&cred_pool[i+1]; + + for (i = 0; i < CRED_ALLOC_STEP - 1; i++) + cred_pool[i].cr_ref = (long)&cred_pool[i + 1]; cred_pool[i].cr_ref = 0; } tmp = cred_pool; - cred_pool = (cred_t*)tmp->cr_ref; + cred_pool = (cred_t *) tmp->cr_ref; ncreds_inuse++; CRED_UNLOCK(); memset(tmp, 0, sizeof(cred_t)); +#if defined(AFS_LINUX26_ENV) + tmp->cr_group_info = groups_alloc(0); +#endif tmp->cr_ref = 1; return tmp; } -void crfree(cred_t *cr) +void +crfree(cred_t * cr) { if (cr->cr_ref > 1) { +#if defined(AFS_LINUX26_ENV) + put_group_info(cr->cr_group_info); +#endif cr->cr_ref--; return; } @@ -76,39 +85,83 @@ void crfree(cred_t *cr) cr->cr_ref = (long)cred_pool; cred_pool = cr; CRED_UNLOCK(); - ncreds_inuse --; + ncreds_inuse--; } /* Return a duplicate of the cred. */ -cred_t *crdup(cred_t *cr) +cred_t * +crdup(cred_t * cr) { cred_t *tmp = crget(); - *tmp = *cr; + + tmp->cr_uid = cr->cr_uid; + tmp->cr_ruid = cr->cr_ruid; + tmp->cr_gid = cr->cr_gid; +#if defined(AFS_LINUX26_ENV) +{ + struct group_info *old_info; + + old_info = tmp->cr_group_info; + get_group_info(cr->cr_group_info); + tmp->cr_group_info = cr->cr_group_info; + put_group_info(old_info); +} +#else + memcpy(tmp->cr_groups, cr->cr_groups, NGROUPS * sizeof(gid_t)); + tmp->cr_ngroups = cr->cr_ngroups; +#endif + tmp->cr_ref = 1; return tmp; } -cred_t *crref(void) +cred_t * +crref(void) { cred_t *cr = crget(); + cr->cr_uid = current->fsuid; cr->cr_ruid = current->uid; cr->cr_gid = current->fsgid; cr->cr_rgid = current->gid; +#if defined(AFS_LINUX26_ENV) +{ + struct group_info *old_info; + + old_info = cr->cr_group_info; + get_group_info(current->group_info); + cr->cr_group_info = current->group_info; + put_group_info(old_info); +} +#else memcpy(cr->cr_groups, current->groups, NGROUPS * sizeof(gid_t)); cr->cr_ngroups = current->ngroups; +#endif return cr; } /* Set the cred info into the current task */ -void crset(cred_t *cr) +void +crset(cred_t * cr) { current->fsuid = cr->cr_uid; current->uid = cr->cr_ruid; current->fsgid = cr->cr_gid; current->gid = cr->cr_rgid; +#if defined(AFS_LINUX26_ENV) +{ + struct group_info *old_info; + + /* using set_current_groups() will sort the groups */ + old_info = current->group_info; + get_group_info(cr->cr_group_info); + current->group_info = cr->cr_group_info; + put_group_info(old_info); +} +#else memcpy(current->groups, cr->cr_groups, NGROUPS * sizeof(gid_t)); current->ngroups = cr->cr_ngroups; +#endif } diff --git a/src/afs/LINUX/osi_file.c b/src/afs/LINUX/osi_file.c index 98456e438..0191e78a7 100644 --- a/src/afs/LINUX/osi_file.c +++ b/src/afs/LINUX/osi_file.c @@ -8,24 +8,26 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_file.c,v 1.8 2003/07/30 17:23:43 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_file.c,v 1.19 2004/04/12 16:04:32 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ -#include "../h/smp_lock.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#include "h/smp_lock.h" +#include "h/module.h" -int afs_osicred_initialized=0; -struct AFS_UCRED afs_osi_cred; +int afs_osicred_initialized = 0; +struct AFS_UCRED afs_osi_cred; afs_lock_t afs_xosi; /* lock is for tvattr */ extern struct osi_dev cacheDev; extern struct super_block *afs_cacheSBp; -void *osi_UFSOpen(ainode) - afs_int32 ainode; +void * +osi_UFSOpen(afs_int32 ainode) { struct inode *ip; register struct osi_file *afile = NULL; @@ -35,7 +37,7 @@ void *osi_UFSOpen(ainode) struct inode *tip = NULL; struct file *filp = NULL; AFS_STATCNT(osi_UFSOpen); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) { + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) { osi_Panic("UFSOpen called for non-UFS cache\n"); } if (!afs_osicred_initialized) { @@ -44,21 +46,24 @@ void *osi_UFSOpen(ainode) crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */ afs_osicred_initialized = 1; } - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocLargeSpace(sizeof(struct osi_file)); AFS_GUNLOCK(); if (!afile) { osi_Panic("osi_UFSOpen: Failed to allocate %d bytes for osi_file.\n", - sizeof(struct osi_file)); + sizeof(struct osi_file)); } memset(afile, 0, sizeof(struct osi_file)); filp = &afile->file; filp->f_dentry = &afile->dentry; - tip = iget(afs_cacheSBp, (u_long)ainode); + tip = iget(afs_cacheSBp, (u_long) ainode); if (!tip) osi_Panic("Can't get inode %d\n", ainode); FILE_INODE(filp) = tip; - tip->i_flags |= MS_NOATIME; /* Disable updating access times. */ + tip->i_flags |= MS_NOATIME; /* Disable updating access times. */ filp->f_flags = O_RDWR; +#if defined(AFS_LINUX26_ENV) + filp->f_mapping = tip->i_mapping; +#endif #if defined(AFS_LINUX24_ENV) filp->f_op = fops_get(tip->i_fop); #else @@ -71,46 +76,51 @@ void *osi_UFSOpen(ainode) afile->size = tip->i_size; AFS_GLOCK(); afile->offset = 0; - afile->proc = (int (*)()) 0; - afile->inum = ainode; /* for hint validity checking */ + afile->proc = (int (*)())0; + afile->inum = ainode; /* for hint validity checking */ return (void *)afile; } -afs_osi_Stat(afile, astat) - register struct osi_file *afile; - register struct osi_stat *astat; { +int +afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) +{ register afs_int32 code; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi,320); + MObtainWriteLock(&afs_xosi, 320); astat->size = FILE_INODE(&afile->file)->i_size; astat->blksize = FILE_INODE(&afile->file)->i_blksize; +#if defined(AFS_LINUX26_ENV) + astat->mtime = FILE_INODE(&afile->file)->i_mtime.tv_sec; + astat->atime = FILE_INODE(&afile->file)->i_atime.tv_sec; +#else astat->mtime = FILE_INODE(&afile->file)->i_mtime; astat->atime = FILE_INODE(&afile->file)->i_atime; +#endif code = 0; MReleaseWriteLock(&afs_xosi); return code; } -osi_UFSClose(afile) - register struct osi_file *afile; - { - AFS_STATCNT(osi_Close); - if (afile) { - if (FILE_INODE(&afile->file)) { - struct file *filp = &afile->file; - if (filp->f_op && filp->f_op->release) - filp->f_op->release(FILE_INODE(filp), filp); - iput(FILE_INODE(filp)); - } - } - - osi_FreeSmallSpace(afile); - return 0; - } +int +osi_UFSClose(register struct osi_file *afile) +{ + AFS_STATCNT(osi_Close); + if (afile) { + if (FILE_INODE(&afile->file)) { + struct file *filp = &afile->file; + if (filp->f_op && filp->f_op->release) + filp->f_op->release(FILE_INODE(filp), filp); + iput(FILE_INODE(filp)); + } + } + + osi_FreeLargeSpace(afile); + return 0; +} -osi_UFSTruncate(afile, asize) - register struct osi_file *afile; - afs_int32 asize; { +int +osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) +{ struct AFS_UCRED *oldCred; register afs_int32 code; struct osi_stat tstat; @@ -123,8 +133,9 @@ osi_UFSTruncate(afile, asize) * small enough. Check now and save some time. */ code = afs_osi_Stat(afile, &tstat); - if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi,321); + if (code || tstat.size <= asize) + return code; + MObtainWriteLock(&afs_xosi, 321); AFS_GUNLOCK(); #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM down_write(&inode->i_alloc_sem); @@ -169,74 +180,74 @@ osi_UFSTruncate(afile, asize) /* Generic read interface */ -afs_osi_Read(afile, offset, aptr, asize) - register struct osi_file *afile; - int offset; - char *aptr; - afs_int32 asize; { +int +afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; size_t resid; register afs_int32 code; - register afs_int32 cnt1=0; + register afs_int32 cnt1 = 0; AFS_STATCNT(osi_Read); /** * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ - if ( !afile ) { - if ( !afs_shuttingdown ) + if (!afile) { + if (!afs_shuttingdown) osi_Panic("osi_Read called with null param"); else return EIO; } - if (offset != -1) afile->offset = offset; + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); code = osi_rdwr(UIO_READ, afile, (caddr_t) aptr, asize, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; - } - else { + } else { afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, - ICL_TYPE_INT32, code); + ICL_TYPE_INT32, code); code = -1; } return code; } /* Generic write interface */ -afs_osi_Write(afile, offset, aptr, asize) - register struct osi_file *afile; - char *aptr; - afs_int32 offset; - afs_int32 asize; { +int +afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; size_t resid; register afs_int32 code; AFS_STATCNT(osi_Write); - if ( !afile ) { - if ( !afs_shuttingdown ) + if (!afile) { + if (!afs_shuttingdown) osi_Panic("afs_osi_Write called with null param"); else return EIO; - } - if (offset != -1) afile->offset = offset; + } + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = osi_rdwr(UIO_WRITE, afile, (caddr_t)aptr, asize, &resid); + code = osi_rdwr(UIO_WRITE, afile, (caddr_t) aptr, asize, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; - } - else { - if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); + } else { + if (code == ENOSPC) + afs_warnuser + ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); code = -1; } if (afile->proc) { - (*afile->proc)(afile, code); + (*afile->proc) (afile, code); } return code; } @@ -245,9 +256,8 @@ afs_osi_Write(afile, offset, aptr, asize) /* This work should be handled by physstrat in ca/machdep.c. This routine written from the RT NFS port strategy routine. It has been generalized a bit, but should still be pretty clear. */ -int afs_osi_MapStrategy(aproc, bp) - int (*aproc)(); - register struct buf *bp; +int +afs_osi_MapStrategy(int (*aproc) (struct buf * bp), register struct buf *bp) { afs_int32 returnCode; @@ -258,13 +268,12 @@ int afs_osi_MapStrategy(aproc, bp) } void -shutdown_osifile() +shutdown_osifile(void) { - extern int afs_cold_shutdown; + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osifile); - if (afs_cold_shutdown) { - afs_osicred_initialized = 0; - } + AFS_STATCNT(shutdown_osifile); + if (afs_cold_shutdown) { + afs_osicred_initialized = 0; + } } - diff --git a/src/afs/LINUX/osi_groups.c b/src/afs/LINUX/osi_groups.c index 3f2c11f38..52f1e6036 100644 --- a/src/afs/LINUX/osi_groups.c +++ b/src/afs/LINUX/osi_groups.c @@ -14,38 +14,111 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_groups.c,v 1.1.1.12 2003/07/30 17:08:10 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_groups.c,v 1.22 2004/04/21 02:20:23 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ #ifdef AFS_LINUX22_ENV -#include "../h/smp_lock.h" +#include "h/smp_lock.h" #endif -static int afs_getgroups(cred_t *cr, gid_t *groups); -static int afs_setgroups(cred_t **cr, int ngroups, gid_t *gidset, int change_parent); +#if defined(AFS_LINUX26_ENV) +static int +afs_setgroups(cred_t **cr, struct group_info *group_info, int change_parent) +{ + struct group_info *old_info; + + AFS_STATCNT(afs_setgroups); + + old_info = (*cr)->cr_group_info; + get_group_info(group_info); + (*cr)->cr_group_info = group_info; + put_group_info(old_info); + + crset(*cr); + + if (change_parent) { + old_info = current->parent->group_info; + get_group_info(group_info); + current->parent->group_info = group_info; + put_group_info(old_info); + } + + return (0); +} +#else +static int +afs_setgroups(cred_t **cr, int ngroups, gid_t * gidset, int change_parent) +{ + int ngrps; + int i; + gid_t *gp; + + AFS_STATCNT(afs_setgroups); + + if (ngroups > NGROUPS) + return EINVAL; + + gp = (*cr)->cr_groups; + if (ngroups < NGROUPS) + gp[ngroups] = (gid_t) NOGROUP; + + for (i = ngroups; i > 0; i--) { + *gp++ = *gidset++; + } + + (*cr)->cr_ngroups = ngroups; + crset(*cr); + return (0); +} +#endif + +#if defined(AFS_LINUX26_ENV) +static struct group_info * +afs_getgroups(cred_t * cr) +{ + AFS_STATCNT(afs_getgroups); + + get_group_info(cr->cr_group_info); + return cr->cr_group_info; +} +#else +/* Returns number of groups. And we trust groups to be large enough to + * hold all the groups. + */ +static int +afs_getgroups(cred_t *cr, gid_t *groups) +{ + int i; + AFS_STATCNT(afs_getgroups); + gid_t *gp = cr->cr_groups; + int n = cr->cr_ngroups; + + for (i = 0; (i < n) && (*gp != (gid_t) NOGROUP); i++) + *groups++ = *gp++; + return i; +} +#endif + +#if !defined(AFS_LINUX26_ENV) /* Only propogate the PAG to the parent process. Unix's propogate to * all processes sharing the cred. */ -int set_pag_in_parent(int pag, int g0, int g1) +int +set_pag_in_parent(int pag, int g0, int g1) { + int i; #ifdef STRUCT_TASK_STRUCT_HAS_PARENT gid_t *gp = current->parent->groups; + int ngroups = current->parent->ngroups; #else gid_t *gp = current->p_pptr->groups; -#endif - int ngroups; - int i; - - -#ifdef STRUCT_TASK_STRUCT_HAS_PARENT - ngroups = current->parent->ngroups; -#else - ngroups = current->p_pptr->ngroups; + int ngroups = current->p_pptr->ngroups; #endif if ((ngroups < 2) || (afs_get_pag_from_groups(gp[0], gp[1]) == NOPAG)) { @@ -53,9 +126,9 @@ int set_pag_in_parent(int pag, int g0, int g1) if (ngroups + 2 > NGROUPS) { return EINVAL; } - for (i = ngroups-1; i >= 0; i--) { - gp[i+2] = gp[i]; - } + for (i = ngroups - 1; i >= 0; i--) { + gp[i + 2] = gp[i]; + } ngroups += 2; } gp[0] = g0; @@ -70,30 +143,66 @@ int set_pag_in_parent(int pag, int g0, int g1) #endif return 0; } +#endif -int setpag(cred_t **cr, afs_uint32 pagvalue, afs_uint32 *newpag, int change_parent) +int +setpag(cred_t ** cr, afs_uint32 pagvalue, afs_uint32 * newpag, + int change_parent) { +#if defined(AFS_LINUX26_ENV) + struct group_info *group_info; + gid_t g0, g1; + + AFS_STATCNT(setpag); + + group_info = afs_getgroups(*cr); + g0 = GROUP_AT(group_info, 0); + g1 = GROUP_AT(group_info, 1); + + if (afs_get_pag_from_groups(g0, g1) == NOPAG) { + /* We will have to make sure group_info is big enough for pag */ + struct group_info *tmp; + int i; + + tmp = groups_alloc(group_info->ngroups + 2); + for (i = 0; i < group_info->ngroups; ++i) + GROUP_AT(tmp, i + 2) = GROUP_AT(group_info, i); + put_group_info(group_info); + group_info = tmp; + } + + *newpag = (pagvalue == -1 ? genpag() : pagvalue); + afs_get_groups_from_pag(*newpag, &g0, &g1); + GROUP_AT(group_info, 0) = g0; + GROUP_AT(group_info, 1) = g1; + + afs_setgroups(cr, group_info, change_parent); + + put_group_info(group_info); + + return 0; +#else gid_t *gidset; afs_int32 ngroups, code = 0; int j; AFS_STATCNT(setpag); - gidset = (gid_t *) osi_Alloc(NGROUPS*sizeof(gidset[0])); + gidset = (gid_t *) osi_Alloc(NGROUPS * sizeof(gidset[0])); ngroups = afs_getgroups(*cr, gidset); if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) { /* We will have to shift grouplist to make room for pag */ if (ngroups + 2 > NGROUPS) { - osi_Free((char *)gidset, NGROUPS*sizeof(int)); + osi_Free((char *)gidset, NGROUPS * sizeof(int)); return EINVAL; } for (j = ngroups - 1; j >= 0; j--) { - gidset[j+2] = gidset[j]; - } + gidset[j + 2] = gidset[j]; + } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); + *newpag = (pagvalue == -1 ? genpag() : pagvalue); afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]); code = afs_setgroups(cr, ngroups, gidset, change_parent); @@ -104,14 +213,16 @@ int setpag(cred_t **cr, afs_uint32 pagvalue, afs_uint32 *newpag, int change_pare code = set_pag_in_parent(*newpag, gidset[0], gidset[1]); } - osi_Free((char *)gidset, NGROUPS*sizeof(int)); + osi_Free((char *)gidset, NGROUPS * sizeof(int)); return code; +#endif } /* Intercept the standard system call. */ -extern long (*sys_setgroupsp)(int gidsetsize, gid_t *grouplist); -asmlinkage long afs_xsetgroups(int gidsetsize, gid_t *grouplist) +extern long (*sys_setgroupsp) (int gidsetsize, gid_t * grouplist); +asmlinkage long +afs_xsetgroups(int gidsetsize, gid_t * grouplist) { long code; cred_t *cr = crref(); @@ -123,7 +234,7 @@ asmlinkage long afs_xsetgroups(int gidsetsize, gid_t *grouplist) crfree(cr); unlock_kernel(); - code = (*sys_setgroupsp)(gidsetsize, grouplist); + code = (*sys_setgroupsp) (gidsetsize, grouplist); if (code) { return code; } @@ -138,25 +249,26 @@ asmlinkage long afs_xsetgroups(int gidsetsize, gid_t *grouplist) unlock_kernel(); /* Linux syscall ABI returns errno as negative */ - return (- code); + return (-code); } #if defined(AFS_LINUX24_ENV) /* Intercept the standard uid32 system call. */ -extern long (*sys_setgroups32p)(int gidsetsize, gid_t *grouplist); -asmlinkage long afs_xsetgroups32(int gidsetsize, gid_t *grouplist) +extern long (*sys_setgroups32p) (int gidsetsize, gid_t * grouplist); +asmlinkage long +afs_xsetgroups32(int gidsetsize, gid_t * grouplist) { long code; cred_t *cr = crref(); afs_uint32 junk; int old_pag; - + lock_kernel(); old_pag = PagInCred(cr); crfree(cr); unlock_kernel(); - code = (*sys_setgroups32p)(gidsetsize, grouplist); + code = (*sys_setgroups32p) (gidsetsize, grouplist); if (code) { return code; @@ -172,30 +284,30 @@ asmlinkage long afs_xsetgroups32(int gidsetsize, gid_t *grouplist) unlock_kernel(); /* Linux syscall ABI returns errno as negative */ - return (- code); + return (-code); } #endif -#if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_AMD64_LINUX20_ENV) +#if defined(AFS_PPC64_LINUX20_ENV) /* Intercept the uid16 system call as used by 32bit programs. */ -extern long (*sys32_setgroupsp)(int gidsetsize, old_gid_t *grouplist); -asmlinkage long afs32_xsetgroups(int gidsetsize, old_gid_t *grouplist) +extern long (*sys32_setgroupsp)(int gidsetsize, gid_t *grouplist); +asmlinkage long afs32_xsetgroups(int gidsetsize, gid_t *grouplist) { long code; cred_t *cr = crref(); afs_uint32 junk; int old_pag; - + lock_kernel(); old_pag = PagInCred(cr); crfree(cr); unlock_kernel(); - + code = (*sys32_setgroupsp)(gidsetsize, grouplist); if (code) { return code; } - + lock_kernel(); cr = crref(); if (old_pag != NOPAG && PagInCred(cr) == NOPAG) { @@ -204,14 +316,51 @@ asmlinkage long afs32_xsetgroups(int gidsetsize, old_gid_t *grouplist) } crfree(cr); unlock_kernel(); + + /* Linux syscall ABI returns errno as negative */ + return (-code); +} +#endif +#if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_AMD64_LINUX20_ENV) +/* Intercept the uid16 system call as used by 32bit programs. */ +extern long (*sys32_setgroupsp) (int gidsetsize, u16 * grouplist); +asmlinkage long +afs32_xsetgroups(int gidsetsize, u16 * grouplist) +{ + long code; + cred_t *cr = crref(); + afs_uint32 junk; + int old_pag; + + lock_kernel(); + old_pag = PagInCred(cr); + crfree(cr); + unlock_kernel(); + + code = (*sys32_setgroupsp) (gidsetsize, grouplist); + if (code) { + return code; + } + + lock_kernel(); + cr = crref(); + if (old_pag != NOPAG && PagInCred(cr) == NOPAG) { + /* re-install old pag if there's room. */ + code = setpag(&cr, old_pag, &junk, 0); + } + crfree(cr); + unlock_kernel(); + /* Linux syscall ABI returns errno as negative */ - return (- code); + return (-code); } + #ifdef AFS_LINUX24_ENV /* Intercept the uid32 system call as used by 32bit programs. */ -extern long (*sys32_setgroups32p)(int gidsetsize, gid_t *grouplist); -asmlinkage long afs32_xsetgroups32(int gidsetsize, gid_t *grouplist) +extern long (*sys32_setgroups32p) (int gidsetsize, gid_t * grouplist); +asmlinkage long +afs32_xsetgroups32(int gidsetsize, gid_t * grouplist) { long code; cred_t *cr = crref(); @@ -223,7 +372,7 @@ asmlinkage long afs32_xsetgroups32(int gidsetsize, gid_t *grouplist) crfree(cr); unlock_kernel(); - code = (*sys32_setgroups32p)(gidsetsize, grouplist); + code = (*sys32_setgroups32p) (gidsetsize, grouplist); if (code) { return code; } @@ -238,48 +387,8 @@ asmlinkage long afs32_xsetgroups32(int gidsetsize, gid_t *grouplist) unlock_kernel(); /* Linux syscall ABI returns errno as negative */ - return (- code); + return (-code); } #endif #endif -static int afs_setgroups(cred_t **cr, int ngroups, gid_t *gidset, int change_parent) -{ - int ngrps; - int i; - gid_t *gp; - - AFS_STATCNT(afs_setgroups); - - if (ngroups > NGROUPS) - return EINVAL; - - gp = (*cr)->cr_groups; - if (ngroups < NGROUPS) - gp[ngroups] = (gid_t)NOGROUP; - - for (i = ngroups; i > 0; i--) { - *gp++ = *gidset++; - } - - (*cr)->cr_ngroups = ngroups; - crset(*cr); - return (0); -} - -/* Returns number of groups. And we trust groups to be large enough to - * hold all the groups. - */ -static int afs_getgroups(cred_t *cr, gid_t *groups) -{ - int i; - gid_t *gp = cr->cr_groups; - int n = cr->cr_ngroups; - AFS_STATCNT(afs_getgroups); - - for (i = 0; (i < n) && (*gp != (gid_t)NOGROUP); i++) { - *groups++ = *gp++; - } - return i; -} - diff --git a/src/afs/LINUX/osi_inode.c b/src/afs/LINUX/osi_inode.c index f55d6551f..131ad1222 100644 --- a/src/afs/LINUX/osi_inode.c +++ b/src/afs/LINUX/osi_inode.c @@ -18,39 +18,30 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_inode.c,v 1.1.1.4 2001/07/14 22:19:46 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_inode.c,v 1.7 2004/04/05 22:39:53 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/osi_inode.h" -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/osi_inode.h" +#include "afs/afs_stats.h" /* statistics stuff */ -#define BAD_IGET -1000 - -/* - * SGI dependent system calls - */ -#ifndef INODESPECIAL -/* - * `INODESPECIAL' type inodes are ones that describe volumes. - */ -#define INODESPECIAL 0xffffffff /* ... from ../vol/viceinode.h */ -#endif - - -int afs_syscall_icreate(void) +int +afs_syscall_icreate(void) { return 0; } -int afs_syscall_iopen(void) +int +afs_syscall_iopen(void) { return 0; } -int afs_syscall_iincdec(void) +int +afs_syscall_iincdec(void) { return 0; } diff --git a/src/afs/LINUX/osi_machdep.h b/src/afs/LINUX/osi_machdep.h index c402a2388..038a19040 100644 --- a/src/afs/LINUX/osi_machdep.h +++ b/src/afs/LINUX/osi_machdep.h @@ -47,23 +47,33 @@ #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock) #endif + #define afs_hz HZ +#include "h/sched.h" #define osi_Time() (xtime.tv_sec) -#if (CPU == sparc64) -#define osi_GetTime(V) do { (*(V)).tv_sec = xtime.tv_sec; (*(V)).tv_usec = xtime.tv_usec; } while (0) -#else -#define osi_GetTime(V) (*(V)=xtime) -#endif +#define osi_GetTime(V) do_gettimeofday((V)) #undef gop_lookupname #define gop_lookupname osi_lookupname -#define osi_vnhold(v, n) VN_HOLD(v) +#define osi_vnhold(v, n) do { VN_HOLD(AFSTOV(v)); } while (0) + +#if defined(AFS_LINUX24_ENV) +#define VN_HOLD(V) atomic_inc(&((vnode_t *) V)->i_count) +#else +#define VN_HOLD(V) ((vnode_t *) V)->i_count++ +#endif + +#if defined(AFS_LINUX26_ENV) +#define VN_RELE(V) iput((struct inode *) V) +#else +#define VN_RELE(V) osi_iput((struct inode *) V) +#endif #define osi_AllocSmall afs_osi_Alloc #define osi_FreeSmall afs_osi_Free -#define afs_suser suser +#define afs_suser(x) capable(CAP_SYS_ADMIN) #define wakeup afs_osi_Wakeup #undef vType @@ -73,16 +83,12 @@ * Use the same type of test as other OS's for compatibility. */ #undef IsAfsVnode -extern struct vnodeops afs_dir_iops, afs_symlink_iops; -#define IsAfsVnode(vc) (((vc)->v_op == afs_ops) ? 1 : \ - ((vc)->v_op == &afs_dir_iops) ? 1 : \ - ((vc)->v_op == &afs_symlink_iops)) - -#if 0 -/* bcopy is in stds.h, just so fcrypt.c can pick it up. */ -#define bzero(D,C) memset((D), 0, (C)) -#define bcmp(A,B,C) memcmp((A), (B), (C)) -#endif +extern struct vnodeops afs_file_iops, afs_dir_iops, afs_symlink_iops; +#define IsAfsVnode(v) (((v)->v_op == &afs_file_iops) ? 1 : \ + ((v)->v_op == &afs_dir_iops) ? 1 : \ + ((v)->v_op == &afs_symlink_iops)) +#undef SetAfsVnode +#define SetAfsVnode(v) /* We often need to pretend we're in user space to get memory transfers * right for the kernel calls we use. @@ -111,6 +117,9 @@ extern struct vnodeops afs_dir_iops, afs_symlink_iops; #define PAGESIZE PAGE_SIZE +#ifndef NGROUPS +#define NGROUPS NGROUPS_SMALL +#endif /* cred struct */ typedef struct cred { /* maps to task field: */ @@ -119,12 +128,16 @@ typedef struct cred { /* maps to task field: */ #else int cr_ref; #endif - uid_t cr_uid; /* euid */ - uid_t cr_ruid; /* uid */ - gid_t cr_gid; /* egid */ - gid_t cr_rgid; /* gid */ + uid_t cr_uid; /* euid */ + uid_t cr_ruid; /* uid */ + gid_t cr_gid; /* egid */ + gid_t cr_rgid; /* gid */ +#if defined(AFS_LINUX26_ENV) + struct group_info *cr_group_info; +#else gid_t cr_groups[NGROUPS]; /* 32 groups - empty set to NOGROUP */ int cr_ngroups; +#endif } cred_t; #define AFS_UCRED cred #define AFS_PROC struct task_struct @@ -134,12 +147,12 @@ typedef struct cred { /* maps to task field: */ typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t; typedef enum { UIO_READ, UIO_WRITE } uio_flag_t; typedef struct uio { - struct iovec *uio_iov; - int uio_iovcnt; - int uio_offset; - uio_seg_t uio_seg; - int uio_resid; - uio_flag_t uio_flag; + struct iovec *uio_iov; + int uio_iovcnt; + afs_offs_t uio_offset; + uio_seg_t uio_seg; + int uio_resid; + uio_flag_t uio_flag; } uio_t; #define afsio_iov uio_iov #define afsio_iovcnt uio_iovcnt @@ -159,9 +172,7 @@ typedef struct uio { */ extern unsigned long afs_linux_page_offset; -/* some more functions to help with the page offset stuff */ -#define AFS_LINUX_MAP_NR(addr) ((((unsigned long)addr) - afs_linux_page_offset) >> PAGE_SHIFT) - +/* function to help with the page offset stuff */ #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map)) #if defined(__KERNEL__) && defined(CONFIG_SMP) @@ -185,7 +196,7 @@ do { \ #define AFS_GUNLOCK() \ do { \ if (!ISAFS_GLOCK()) \ - osi_Panic("afs global lock not held"); \ + osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \ afs_global_owner = 0; \ up(&afs_global_lock); \ } while (0) diff --git a/src/afs/LINUX/osi_misc.c b/src/afs/LINUX/osi_misc.c index f0dcfe437..9a6d1a2c5 100644 --- a/src/afs/LINUX/osi_misc.c +++ b/src/afs/LINUX/osi_misc.c @@ -12,35 +12,43 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_misc.c,v 1.14 2003/07/30 17:23:43 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_misc.c,v 1.33 2004/05/08 03:58:27 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" #if defined(AFS_LINUX24_ENV) -#include "../h/smp_lock.h" +#include "h/smp_lock.h" +#endif +#if defined(AFS_LINUX26_ENV) +#include "h/namei.h" #endif - -char *crash_addr = 0; /* Induce an oops by writing here. */ #if defined(AFS_LINUX24_ENV) /* Lookup name and return vnode for same. */ -int osi_lookupname_internal(char *aname, uio_seg_t seg, int followlink, - vnode_t **dirvpp, struct dentry **dpp, - struct nameidata *nd) +int +osi_lookupname(char *aname, uio_seg_t seg, int followlink, + vnode_t ** dirvpp, struct dentry **dpp) { int code; + extern struct nameidata afs_cacheNd; + struct nameidata *nd = &afs_cacheNd; code = ENOENT; if (seg == AFS_UIOUSER) { - code = followlink ? - user_path_walk(aname, nd) : user_path_walk_link(aname, nd); - } - else { + code = + followlink ? user_path_walk(aname, + nd) : user_path_walk_link(aname, nd); + } else { +#if defined(AFS_LINUX26_ENV) + code = path_lookup(aname, followlink ? LOOKUP_FOLLOW : 0, nd); +#else if (path_init(aname, followlink ? LOOKUP_FOLLOW : 0, nd)) code = path_walk(aname, nd); +#endif } if (!code) { @@ -54,28 +62,18 @@ int osi_lookupname_internal(char *aname, uio_seg_t seg, int followlink, } return code; } -#endif - -int osi_lookupname(char *aname, uio_seg_t seg, int followlink, - vnode_t **dirvpp, struct dentry **dpp) -{ -#if defined(AFS_LINUX24_ENV) - struct nameidata nd; - int code = osi_lookupname_internal(aname, seg, followlink, dirvpp, dpp, - &nd); - if (!code) - path_release(&nd); - - return (code); #else +int +osi_lookupname(char *aname, uio_seg_t seg, int followlink, vnode_t ** dirvpp, + struct dentry **dpp) +{ struct dentry *dp = NULL; int code; - + code = ENOENT; if (seg == AFS_UIOUSER) { dp = followlink ? namei(aname) : lnamei(aname); - } - else { + } else { dp = lookup_dentry(aname, NULL, followlink ? 1 : 0); } @@ -83,17 +81,17 @@ int osi_lookupname(char *aname, uio_seg_t seg, int followlink, if (dp->d_inode) { *dpp = dp; code = 0; - } - else + } else dput(dp); } - + return code; -#endif } +#endif /* Intialize cache device info and fragment size for disk cache partition. */ -int osi_InitCacheInfo(char *aname) +int +osi_InitCacheInfo(char *aname) { int code; struct dentry *dp; @@ -101,14 +99,12 @@ int osi_InitCacheInfo(char *aname) extern struct osi_dev cacheDev; extern afs_int32 afs_fsfragsize; extern struct super_block *afs_cacheSBp; - extern struct nameidata afs_cacheNd; - - code = osi_lookupname_internal(aname, AFS_UIOSYS, 1, NULL, &dp, - &afs_cacheNd); - if (code) return ENOENT; + code = osi_lookupname(aname, AFS_UIOSYS, 1, NULL, &dp); + if (code) + return ENOENT; cacheInode = dp->d_inode->i_ino; - cacheDev.dev = dp->d_inode->i_dev; + cacheDev.dev = dp->d_inode->i_sb->s_dev; afs_fsfragsize = dp->d_inode->i_sb->s_blocksize - 1; afs_cacheSBp = dp->d_inode->i_sb; @@ -125,8 +121,9 @@ int osi_InitCacheInfo(char *aname) * Seek, then read or write to an open inode. addrp points to data in * kernel space. */ -int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, - size_t *resid) +int +osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, + size_t * resid) { int code = 0; KERNEL_SPACE_DECL; @@ -136,10 +133,9 @@ int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, /* Seek to the desired position. Return -1 on error. */ if (filp->f_op->llseek) { - if (filp->f_op->llseek(filp, (loff_t)offset, 0) != offset) + if (filp->f_op->llseek(filp, (loff_t) offset, 0) != offset) return -1; - } - else + } else filp->f_pos = offset; savelim = current->rlim[RLIMIT_FSIZE].rlim_cur; @@ -151,24 +147,24 @@ int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, code = FOP_READ(filp, addrp, asize); else if (rw == UIO_WRITE) code = FOP_WRITE(filp, addrp, asize); - else /* all is well? */ + else /* all is well? */ code = asize; TO_KERNEL_SPACE(); current->rlim[RLIMIT_FSIZE].rlim_cur = savelim; - if (code >=0) { + if (code >= 0) { *resid = asize - code; return 0; - } - else + } else return -1; } /* This variant is called from AFS read/write routines and takes a uio * struct and, if successful, returns 0. */ -int osi_file_uio_rdwr(struct osi_file *osifile, uio_t *uiop, int rw) +int +osi_file_uio_rdwr(struct osi_file *osifile, uio_t * uiop, int rw) { struct file *filp = &osifile->file; struct inode *ip = FILE_INODE(&osifile->file); @@ -202,8 +198,16 @@ int osi_file_uio_rdwr(struct osi_file *osifile, uio_t *uiop, int rw) if (code < 0) { code = -code; break; + } else if (code == 0) { + /* + * This is bad -- we can't read any more data from the + * file, but we have no good way of signaling a partial + * read either. + */ + code = EIO; + break; } - + iov->iov_base += code; iov->iov_len -= code; uiop->uio_resid -= code; @@ -222,9 +226,9 @@ int osi_file_uio_rdwr(struct osi_file *osifile, uio_t *uiop, int rw) /* setup_uio * Setup a uio struct. */ -void setup_uio(uio_t *uiop, struct iovec *iovecp, char *buf, - int pos, int count, uio_flag_t flag, - uio_seg_t seg) +void +setup_uio(uio_t * uiop, struct iovec *iovecp, char *buf, afs_offs_t pos, + int count, uio_flag_t flag, uio_seg_t seg) { iovecp->iov_base = buf; iovecp->iov_len = count; @@ -241,7 +245,8 @@ void setup_uio(uio_t *uiop, struct iovec *iovecp, char *buf, * UIO_READ : dp -> uio * UIO_WRITE : uio -> dp */ -int uiomove(char *dp, int length, uio_flag_t rw, uio_t *uiop) +int +uiomove(char *dp, int length, uio_flag_t rw, uio_t * uiop) { int count, n; struct iovec *iov; @@ -259,25 +264,29 @@ int uiomove(char *dp, int length, uio_flag_t rw, uio_t *uiop) if (count > length) count = length; - - switch(uiop->uio_seg) { + + switch (uiop->uio_seg) { case AFS_UIOSYS: - switch(rw) { + switch (rw) { case UIO_READ: - memcpy(iov->iov_base, dp, count); break; + memcpy(iov->iov_base, dp, count); + break; case UIO_WRITE: - memcpy(dp, iov->iov_base, count); break; + memcpy(dp, iov->iov_base, count); + break; default: printf("uiomove: Bad rw = %d\n", rw); return -EINVAL; } break; case AFS_UIOUSER: - switch(rw) { + switch (rw) { case UIO_READ: - AFS_COPYOUT(dp, iov->iov_base, count, code); break; + AFS_COPYOUT(dp, iov->iov_base, count, code); + break; case UIO_WRITE: - AFS_COPYIN(iov->iov_base, dp, count, code); break; + AFS_COPYIN(iov->iov_base, dp, count, code); + break; default: printf("uiomove: Bad rw = %d\n", rw); return -EINVAL; @@ -298,22 +307,34 @@ int uiomove(char *dp, int length, uio_flag_t rw, uio_t *uiop) return 0; } -void afs_osi_SetTime(osi_timeval_t *tvp) +void +afs_osi_SetTime(osi_timeval_t * tvp) { - extern int (*sys_settimeofdayp)(struct timeval *tv, struct timezone *tz); -#ifdef AFS_LINUX_64BIT_KERNEL +#if defined(AFS_LINUX24_ENV) + +#if defined(AFS_LINUX26_ENV) + struct timespec tv; + tv.tv_sec = tvp->tv_sec; + tv.tv_nsec = tvp->tv_usec * NSEC_PER_USEC; +#else struct timeval tv; - AFS_STATCNT(osi_SetTime); tv.tv_sec = tvp->tv_sec; tv.tv_usec = tvp->tv_usec; - (void) (*sys_settimeofdayp)(&tv, NULL); +#endif + + AFS_STATCNT(osi_SetTime); + + do_settimeofday(&tv); #else + extern int (*sys_settimeofdayp) (struct timeval * tv, + struct timezone * tz); + KERNEL_SPACE_DECL; AFS_STATCNT(osi_SetTime); TO_USER_SPACE(); - (void) (*sys_settimeofdayp)(tvp, NULL); + (void)(*sys_settimeofdayp) (tvp, NULL); TO_KERNEL_SPACE(); #endif } @@ -321,15 +342,16 @@ void afs_osi_SetTime(osi_timeval_t *tvp) /* Free all the pages on any of the vnodes in the vlru. Must be done before * freeing all memory. */ -void osi_linux_free_inode_pages(void) +void +osi_linux_free_inode_pages(void) { int i; struct vcache *tvc; struct inode *ip; extern struct vcache *afs_vhashT[VCSIZE]; - for (i=0; ihnext) { + for (i = 0; i < VCSIZE; i++) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { ip = AFSTOI(tvc); #if defined(AFS_LINUX24_ENV) if (ip->i_data.nrpages) { @@ -337,9 +359,9 @@ void osi_linux_free_inode_pages(void) if (ip->i_nrpages) { #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) - truncate_inode_pages(&ip->i_data, 0); + truncate_inode_pages(&ip->i_data, 0); #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,15) - truncate_inode_pages(ip, 0); + truncate_inode_pages(ip, 0); #else invalidate_inode_pages(ip); #endif @@ -356,7 +378,8 @@ void osi_linux_free_inode_pages(void) } } -void osi_clear_inode(struct inode *ip) +void +osi_clear_inode(struct inode *ip) { cred_t *credp = crref(); struct vcache *vcp = ITOAFS(ip); @@ -366,55 +389,57 @@ void osi_clear_inode(struct inode *ip) #else if (ip->i_count > 1) #endif - printf("afs_put_inode: ino %d (0x%x) has count %d\n", ip->i_ino, ip); + printf("afs_put_inode: ino %d (0x%x) has count %d\n", ip->i_ino, ip, + ip->i_count); afs_InactiveVCache(vcp, credp); ObtainWriteLock(&vcp->lock, 504); -#if defined(AFS_LINUX24_ENV) - atomic_set(&ip->i_count, 0); -#else - ip->i_count = 0; -#endif - ip->i_nlink = 0; /* iput checks this after calling this routine. */ + ip->i_nlink = 0; /* iput checks this after calling this routine. */ + ip->i_state = I_CLEAR; ReleaseWriteLock(&vcp->lock); crfree(credp); } +#if !defined(AFS_LINUX26_ENV) /* iput an inode. Since we still have a separate inode pool, we don't want * to call iput on AFS inodes, since they would then end up on Linux's * inode_unsed list. */ -void osi_iput(struct inode *ip) +void +osi_iput(struct inode *ip) { extern struct vfs *afs_globalVFS; AFS_GLOCK(); + + if (afs_globalVFS && ip->i_sb != afs_globalVFS) + osi_Panic("IPUT Not an afs inode\n"); + #if defined(AFS_LINUX24_ENV) - if (atomic_read(&ip->i_count) == 0 || atomic_read(&ip->i_count) & 0xffff0000) { + if (atomic_read(&ip->i_count) == 0) #else - if (ip->i_count == 0 || ip->i_count & 0xffff0000) { + if (ip->i_count == 0) #endif osi_Panic("IPUT Bad refCount %d on inode 0x%x\n", #if defined(AFS_LINUX24_ENV) - atomic_read(&ip->i_count), ip); + atomic_read(&ip->i_count), #else - ip->i_count, ip); + ip->i_count, #endif - } - if (afs_globalVFS && afs_globalVFS == ip->i_sb ) { + ip); + #if defined(AFS_LINUX24_ENV) - atomic_dec(&ip->i_count); - if (!atomic_read(&ip->i_count)) + if (atomic_dec_and_test(&ip->i_count)) #else - ip->i_count --; - if (!ip->i_count) + if (!--ip->i_count) #endif - osi_clear_inode(ip); + { + osi_clear_inode(ip); + ip->i_state = 0; } - else - iput(ip); AFS_GUNLOCK(); } +#endif /* check_bad_parent() : Checks if this dentry's vcache is a root vcache * that has its mvid (parent dir's fid) pointer set to the wrong directory @@ -432,42 +457,46 @@ void osi_iput(struct inode *ip) * to the correct parent and mountpoint fids. */ -void check_bad_parent(struct dentry *dp) +void +check_bad_parent(struct dentry *dp) { - cred_t *credp; - struct vcache *vcp = ITOAFS(dp->d_inode), *avc = NULL; - struct vcache *pvc = ITOAFS(dp->d_parent->d_inode); - - if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */ - credp = crref(); - - - /* force a lookup, so vcp->mvid is fixed up */ - afs_lookup(pvc, dp->d_name.name, &avc, credp); - if (!avc || vcp != avc) { /* bad, very bad.. */ - afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING, - "afs_linux_revalidate : bad pointer returned from afs_lookup origvc newvc dentry", - ICL_TYPE_POINTER, vcp, - ICL_TYPE_POINTER, avc, - ICL_TYPE_POINTER, dp); + cred_t *credp; + struct vcache *vcp = ITOAFS(dp->d_inode), *avc = NULL; + struct vcache *pvc = ITOAFS(dp->d_parent->d_inode); + + if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */ + credp = crref(); + + + /* force a lookup, so vcp->mvid is fixed up */ + afs_lookup(pvc, dp->d_name.name, &avc, credp); + if (!avc || vcp != avc) { /* bad, very bad.. */ + afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING, + "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry", + ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc, + ICL_TYPE_POINTER, dp); + } + if (avc) + AFS_RELE(avc); + crfree(credp); } - if (avc) - AFS_RELE(avc); - crfree(credp); - } /* if bad parent */ - - return; + /* if bad parent */ + return; } struct task_struct *rxk_ListenerTask; -void osi_linux_mask() { +void +osi_linux_mask(void) +{ SIG_LOCK(current); sigfillset(¤t->blocked); RECALC_SIGPENDING(current); SIG_UNLOCK(current); } -void osi_linux_rxkreg() { +void +osi_linux_rxkreg(void) +{ rxk_ListenerTask = current; } diff --git a/src/afs/LINUX/osi_module.c b/src/afs/LINUX/osi_module.c index 38e5e344f..4eafd9d40 100644 --- a/src/afs/LINUX/osi_module.c +++ b/src/afs/LINUX/osi_module.c @@ -12,20 +12,22 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_module.c,v 1.12 2003/07/30 17:23:43 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_module.c,v 1.48 2004/05/11 20:36:13 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../h/unistd.h" /* For syscall numbers. */ -#include "../h/mm.h" +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "h/unistd.h" /* For syscall numbers. */ +#include "h/mm.h" #ifdef AFS_AMD64_LINUX20_ENV #include "../asm/ia32_unistd.h" #endif #include +#include #include #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) #include @@ -35,31 +37,37 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_module.c,v 1.12 2003/07/3 #include #endif +#if defined(AFS_LINUX26_ENV) +#include +#include + +MODULE_INFO(vermagic, VERMAGIC_STRING); -#ifdef AFS_SPARC64_LINUX24_ENV -#define __NR_setgroups32 82 /* This number is not exported for some bizarre reason. */ #endif -asmlinkage int (*sys_settimeofdayp)(struct timeval *tv, struct timezone *tz); -#if !defined(AFS_ALPHA_LINUX20_ENV) -asmlinkage int (*sys_socketcallp)(int call, long *args); -#endif /* no socketcall on alpha */ -asmlinkage long (*sys_setgroupsp)(int gidsetsize, gid_t *grouplist); +#ifdef AFS_SPARC64_LINUX24_ENV +#define __NR_setgroups32 82 /* This number is not exported for some bizarre reason. */ +#endif +#if !defined(AFS_LINUX24_ENV) +asmlinkage int (*sys_settimeofdayp) (struct timeval * tv, + struct timezone * tz); +#endif +asmlinkage long (*sys_setgroupsp) (int gidsetsize, gid_t * grouplist); #ifdef EXPORTED_SYS_CALL_TABLE #ifdef AFS_SPARC64_LINUX20_ENV -extern unsigned int sys_call_table[]; /* changed to uint because SPARC64 has syscaltable of 32bit items */ +extern unsigned int sys_call_table[]; /* changed to uint because SPARC64 has syscaltable of 32bit items */ #else -extern void * sys_call_table[]; /* safer for other linuces */ +extern void *sys_call_table[]; /* safer for other linuces */ #endif #else /* EXPORTED_SYS_CALL_TABLE */ #ifdef AFS_SPARC64_LINUX20_ENV -static unsigned int *sys_call_table; /* changed to uint because SPARC64 has syscaltable of 32bit items */ +static unsigned int *sys_call_table; /* changed to uint because SPARC64 has syscaltable of 32bit items */ #else -static void ** sys_call_table; /* safer for other linuces */ +static void **sys_call_table; /* safer for other linuces */ #endif #endif -extern struct file_system_type afs_file_system; +extern struct file_system_type afs_fs_type; static long get_page_offset(void); @@ -69,7 +77,9 @@ DECLARE_MUTEX(afs_global_lock); struct semaphore afs_global_lock = MUTEX; #endif int afs_global_owner = 0; -unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */ +#if !defined(AFS_LINUX24_ENV) +unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */ +#endif /* Since sys_ni_syscall is not exported, I need to cache it in order to restore * it. @@ -77,28 +87,34 @@ unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */ #ifdef AFS_SPARC64_LINUX20_ENV static unsigned int afs_ni_syscall = 0; #else -static void* afs_ni_syscall = 0; +static void *afs_ni_syscall = 0; #endif - + #ifdef AFS_AMD64_LINUX20_ENV #ifdef EXPORTED_IA32_SYS_CALL_TABLE -extern void * ia32_sys_call_table[]; +extern void *ia32_sys_call_table[]; #else static void **ia32_sys_call_table; #endif static void *ia32_ni_syscall = 0; -asmlinkage long (*sys32_setgroupsp)(int gidsetsize, old_gid_t *grouplist); +asmlinkage long (*sys32_setgroupsp) (int gidsetsize, u16 * grouplist); #if defined(__NR_ia32_setgroups32) -asmlinkage long (*sys32_setgroups32p)(int gidsetsize, gid_t *grouplist); +asmlinkage long (*sys32_setgroups32p) (int gidsetsize, gid_t * grouplist); #endif /* __NR_ia32_setgroups32 */ #endif /* AFS_AMD64_LINUX20_ENV */ +#ifdef AFS_PPC64_LINUX20_ENV +asmlinkage long (*sys32_setgroupsp)(int gidsetsize, gid_t *grouplist); +#endif /* AFS_AMD64_LINUX20_ENV */ + #ifdef AFS_SPARC64_LINUX20_ENV static unsigned int afs_ni_syscall32 = 0; -asmlinkage int (*sys32_setgroupsp)(int gidsetsize, __kernel_gid_t32 *grouplist); +asmlinkage int (*sys32_setgroupsp) (int gidsetsize, + __kernel_gid_t32 * grouplist); #if defined(__NR_setgroups32) -asmlinkage int (*sys32_setgroups32p)(int gidsetsize, __kernel_gid_t32 *grouplist); +asmlinkage int (*sys32_setgroups32p) (int gidsetsize, + __kernel_gid_t32 * grouplist); #endif /* __NR_setgroups32 */ #ifdef EXPORTED_SYS_CALL_TABLE extern unsigned int sys_call_table32[]; @@ -106,94 +122,95 @@ extern unsigned int sys_call_table32[]; static unsigned int *sys_call_table32; #endif /* EXPORTED_SYS_CALL_TABLE */ -asmlinkage int afs_syscall32(long syscall, long parm1, long parm2, long parm3, - long parm4, long parm5) +asmlinkage int +afs_syscall32(long syscall, long parm1, long parm2, long parm3, long parm4, + long parm5) { -__asm__ __volatile__ ("srl %o4, 0, %o4\n\t" - "mov %o7, %i7\n\t" - "call afs_syscall\n\t" - "srl %o5, 0, %o5\n\t" - "ret\n\t" - "nop"); + __asm__ __volatile__("srl %o4, 0, %o4\n\t" "mov %o7, %i7\n\t" + "call afs_syscall\n\t" "srl %o5, 0, %o5\n\t" + "ret\n\t" "nop"); } #endif /* AFS_SPARC64_LINUX20_ENV */ +static int afs_ioctl(struct inode *, struct file *, unsigned int, + unsigned long); + +static struct file_operations afs_syscall_fops = { + .ioctl = afs_ioctl, +}; + +static struct proc_dir_entry *openafs_procfs; + +static int +afsproc_init() +{ + struct proc_dir_entry *entry1; + + openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs); + entry1 = create_proc_entry(PROC_SYSCALL_NAME, 0, openafs_procfs); + + entry1->proc_fops = &afs_syscall_fops; + + entry1->owner = THIS_MODULE; + + return 0; +} + +static void +afsproc_exit() +{ + remove_proc_entry(PROC_SYSCALL_NAME, openafs_procfs); + remove_proc_entry(PROC_FSDIRNAME, proc_root_fs); +} + +static int +afs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, + unsigned long arg) +{ + + struct afsprocdata sysargs; + + if (cmd != VIOC_SYSCALL) return -EINVAL; + + if (copy_from_user(&sysargs, (void *)arg, sizeof(struct afsprocdata))) + return -EFAULT; + + return afs_syscall(sysargs.syscall, sysargs.param1, + sysargs.param2, sysargs.param3, sysargs.param4); +} + #ifdef AFS_IA64_LINUX20_ENV asmlinkage long afs_syscall_stub(int r0, int r1, long r2, long r3, long r4, long gp) { -__asm__ __volatile__ ("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" - "mov r41 = b0\n\t" /* save rp */ - "mov out0 = in0\n\t" - "mov out1 = in1\n\t" - "mov out2 = in2\n\t" - "mov out3 = in3\n\t" - "mov out4 = in4\n\t" - "mov out5 = gp\n\t" /* save gp */ - ";;\n" - ".L1: mov r3 = ip\n\t" - ";;\n\t" - "addl r15=.fptr_afs_syscall-.L1,r3\n\t" - ";;\n\t" - "ld8 r15=[r15]\n\t" - ";;\n\t" - "ld8 r16=[r15],8\n\t" - ";;\n\t" - "ld8 gp=[r15]\n\t" - "mov b6=r16\n\t" - "br.call.sptk.many b0 = b6\n\t" - ";;\n\t" - "mov ar.pfs = r42\n\t" - "mov b0 = r41\n\t" - "mov gp = r48\n\t" /* restore gp */ - "br.ret.sptk.many b0\n" - ".fptr_afs_syscall:\n\t" - "data8 @fptr(afs_syscall)"); + __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" "mov r41 = b0\n\t" /* save rp */ + "mov out0 = in0\n\t" "mov out1 = in1\n\t" "mov out2 = in2\n\t" "mov out3 = in3\n\t" "mov out4 = in4\n\t" "mov out5 = gp\n\t" /* save gp */ + ";;\n" ".L1: mov r3 = ip\n\t" ";;\n\t" "addl r15=.fptr_afs_syscall-.L1,r3\n\t" ";;\n\t" "ld8 r15=[r15]\n\t" ";;\n\t" "ld8 r16=[r15],8\n\t" ";;\n\t" "ld8 gp=[r15]\n\t" "mov b6=r16\n\t" "br.call.sptk.many b0 = b6\n\t" ";;\n\t" "mov ar.pfs = r42\n\t" "mov b0 = r41\n\t" "mov gp = r48\n\t" /* restore gp */ + "br.ret.sptk.many b0\n" ".fptr_afs_syscall:\n\t" + "data8 @fptr(afs_syscall)"); } asmlinkage long afs_xsetgroups_stub(int r0, int r1, long r2, long r3, long r4, long gp) { -__asm__ __volatile__ ("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" - "mov r41 = b0\n\t" /* save rp */ - "mov out0 = in0\n\t" - "mov out1 = in1\n\t" - "mov out2 = in2\n\t" - "mov out3 = in3\n\t" - "mov out4 = in4\n\t" - "mov out5 = gp\n\t" /* save gp */ - ";;\n" - ".L2: mov r3 = ip\n\t" - ";;\n\t" - "addl r15=.fptr_afs_xsetgroups - .L2,r3\n\t" - ";;\n\t" - "ld8 r15=[r15]\n\t" - ";;\n\t" - "ld8 r16=[r15],8\n\t" - ";;\n\t" - "ld8 gp=[r15]\n\t" - "mov b6=r16\n\t" - "br.call.sptk.many b0 = b6\n\t" - ";;\n\t" - "mov ar.pfs = r42\n\t" - "mov b0 = r41\n\t" - "mov gp = r48\n\t" /* restore gp */ - "br.ret.sptk.many b0\n" - ".fptr_afs_xsetgroups:\n\t" - "data8 @fptr(afs_xsetgroups)"); + __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" "mov r41 = b0\n\t" /* save rp */ + "mov out0 = in0\n\t" "mov out1 = in1\n\t" "mov out2 = in2\n\t" "mov out3 = in3\n\t" "mov out4 = in4\n\t" "mov out5 = gp\n\t" /* save gp */ + ";;\n" ".L2: mov r3 = ip\n\t" ";;\n\t" "addl r15=.fptr_afs_xsetgroups - .L2,r3\n\t" ";;\n\t" "ld8 r15=[r15]\n\t" ";;\n\t" "ld8 r16=[r15],8\n\t" ";;\n\t" "ld8 gp=[r15]\n\t" "mov b6=r16\n\t" "br.call.sptk.many b0 = b6\n\t" ";;\n\t" "mov ar.pfs = r42\n\t" "mov b0 = r41\n\t" "mov gp = r48\n\t" /* restore gp */ + "br.ret.sptk.many b0\n" ".fptr_afs_xsetgroups:\n\t" + "data8 @fptr(afs_xsetgroups)"); } -struct fptr -{ - void *ip; - unsigned long gp; +struct fptr { + void *ip; + unsigned long gp; }; #endif /* AFS_IA64_LINUX20_ENV */ #ifdef AFS_LINUX24_ENV -asmlinkage int (*sys_setgroups32p)(int gidsetsize, __kernel_gid32_t *grouplist); +asmlinkage int (*sys_setgroups32p) (int gidsetsize, + __kernel_gid32_t * grouplist); #endif /* AFS_LINUX24_ENV */ #ifdef AFS_SPARC64_LINUX20_ENV @@ -204,275 +221,277 @@ asmlinkage int (*sys_setgroups32p)(int gidsetsize, __kernel_gid32_t *grouplist); #define SYSCALL2POINTER (void *) #endif +#ifdef AFS_PPC64_LINUX20_ENV +extern void *set_afs_syscall(void*); +extern void *set_afs_xsetgroups_syscall(void*); +extern void *set_afs_xsetgroups_syscall32(void*); +#endif + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) -int __init afs_init(void) +int __init +afs_init(void) #else -int init_module(void) +int +init_module(void) #endif { #if defined(AFS_IA64_LINUX20_ENV) - unsigned long kernel_gp; - static struct fptr sys_settimeofday, sys_setgroups; -#endif + unsigned long kernel_gp = 0; + static struct fptr sys_setgroups; +#endif /* defined(AFS_IA64_LINUX20_ENV) */ extern int afs_syscall(); extern long afs_xsetgroups(); #if defined(__NR_setgroups32) extern int afs_xsetgroups32(); #endif /* __NR_setgroups32 */ -#if defined(AFS_SPARC64_LINUX20_ENV) || defined (AFS_AMD64_LINUX20_ENV) +#if defined(AFS_SPARC64_LINUX20_ENV) || defined (AFS_AMD64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV) extern int afs32_xsetgroups(); #if (defined(__NR_setgroups32) && defined(AFS_SPARC64_LINUX20_ENV)) extern int afs32_xsetgroups32(); -#endif +#endif /* defined(__NR_setgroups32) && defined(AFS_SPARC64_LINUX20_ENV) */ #if (defined(__NR_ia32_setgroups32) && defined(AFS_AMD64_LINUX20_ENV)) extern int afs32_xsetgroups32(); -#endif -#endif /* AFS_SPARC64_LINUX20_ENV || AFS_AMD64_LINUX20_ENV */ +#endif /* (defined(__NR_ia32_setgroups32) && defined(AFS_AMD64_LINUX20_ENV) */ +#endif /* AFS_SPARC64_LINUX20_ENV || AFS_AMD64_LINUX20_ENV || AFS_PPC64_LINUX20_ENV */ #if !defined(EXPORTED_SYS_CALL_TABLE) || (defined(AFS_AMD64_LINUX20_ENV) && !defined(EXPORTED_IA32_SYS_CALL_TABLE)) unsigned long *ptr; - unsigned long offset; - unsigned long datalen; + unsigned long offset=0; + unsigned long datalen=0; int ret; - unsigned long token; - char *mod_name; - unsigned long mod_start; - unsigned long mod_end; - char *sec_name; - unsigned long sec_start; - unsigned long sec_end; - char *sym_name; - unsigned long sym_start; - unsigned long sym_end; + unsigned long token=0; + char *mod_name; + unsigned long mod_start=0; + unsigned long mod_end=0; + char *sec_name; + unsigned long sec_start=0; + unsigned long sec_end=0; + char *sym_name; + unsigned long sym_start=0; + unsigned long sym_end=0; #endif /* EXPORTED_SYS_CALL_TABLE */ RWLOCK_INIT(&afs_xosi, "afs_xosi"); +#if !defined(AFS_LINUX24_ENV) /* obtain PAGE_OFFSET value */ afs_linux_page_offset = get_page_offset(); #ifndef AFS_S390_LINUX22_ENV if (afs_linux_page_offset == 0) { - /* couldn't obtain page offset so can't continue */ - printf("afs: Unable to obtain PAGE_OFFSET. Exiting.."); - return -EIO; + /* couldn't obtain page offset so can't continue */ + printf("afs: Unable to obtain PAGE_OFFSET. Exiting.."); + return -EIO; } #endif /* AFS_S390_LINUX22_ENV */ +#endif /* !defined(AFS_LINUX24_ENV) */ #ifndef EXPORTED_SYS_CALL_TABLE - sys_call_table=0; + sys_call_table = 0; + #ifdef EXPORTED_KALLSYMS_SYMBOL - ret=1; - token=0; + ret = 1; + token = 0; while (ret) { - sym_start=0; - ret=kallsyms_symbol_to_address("sys_call_table", &token, &mod_name, - &mod_start, &mod_end, &sec_name, &sec_start, &sec_end, - &sym_name, &sym_start, &sym_end); - if (ret && !strcmp(mod_name, "kernel")) - break; + sym_start = 0; + ret = + kallsyms_symbol_to_address("sys_call_table", &token, &mod_name, + &mod_start, &mod_end, &sec_name, + &sec_start, &sec_end, &sym_name, + &sym_start, &sym_end); + if (ret && !strcmp(mod_name, "kernel")) + break; } if (ret && sym_start) { - sys_call_table=sym_start; + sys_call_table = sym_start; } +#elif defined(EXPORTED_KALLSYMS_ADDRESS) + ret = + kallsyms_address_to_symbol((unsigned long)&init_mm, &mod_name, + &mod_start, &mod_end, &sec_name, + &sec_start, &sec_end, &sym_name, + &sym_start, &sym_end); + ptr = (unsigned long *)sec_start; + datalen = (sec_end - sec_start) / sizeof(unsigned long); +#elif defined(AFS_IA64_LINUX20_ENV) + ptr = (unsigned long *)(&sys_close - 0x180000); + datalen = 0x180000 / sizeof(ptr); +#elif defined(AFS_AMD64_LINUX20_ENV) + ptr = (unsigned long *)&init_mm; + datalen = 0x360000 / sizeof(ptr); #else -#ifdef EXPORTED_KALLSYMS_ADDRESS - ret=kallsyms_address_to_symbol((unsigned long)&init_mm, &mod_name, - &mod_start, &mod_end, &sec_name, &sec_start, &sec_end, - &sym_name, &sym_start, &sym_end); - ptr=(unsigned long *)sec_start; - datalen=(sec_end-sec_start)/sizeof(unsigned long); -#else -#if defined(AFS_IA64_LINUX20_ENV) - ptr = (unsigned long *) (&sys_close - 0x180000); - datalen=0x180000/sizeof(ptr); -#else -#if defined(AFS_AMD64_LINUX20_ENV) - ptr=(unsigned long *)&init_mm; - datalen=0x360000/sizeof(ptr); -#else - ptr=(unsigned long *)&init_mm; - datalen=16384; + ptr = (unsigned long *)&init_mm; + datalen = 16384; #endif -#endif -#endif - for (offset=0;offset ip; - unsigned long chdir_ip=(unsigned long) ((struct fptr *)&sys_chdir)->ip; - unsigned long write_ip=(unsigned long) ((struct fptr *)&sys_write)->ip; - if (ptr[0] == close_ip && - ptr[__NR_chdir - __NR_close] == chdir_ip && - ptr[__NR_write - __NR_close] == write_ip) { - sys_call_table=(void *) &(ptr[ -1 * (__NR_close-1024)]); + unsigned long close_ip = + (unsigned long)((struct fptr *)&sys_close)->ip; + unsigned long chdir_ip = + (unsigned long)((struct fptr *)&sys_chdir)->ip; + unsigned long write_ip = + (unsigned long)((struct fptr *)&sys_write)->ip; + if (ptr[0] == close_ip && ptr[__NR_chdir - __NR_close] == chdir_ip + && ptr[__NR_write - __NR_close] == write_ip) { + sys_call_table = (void *)&(ptr[-1 * (__NR_close - 1024)]); break; } -#else -#if defined(EXPORTED_SYS_WAIT4) && defined(EXPORTED_SYS_CLOSE) - if (ptr[0] == (unsigned long)&sys_close && - ptr[__NR_wait4 - __NR_close] == (unsigned long)&sys_wait4) { - sys_call_table=ptr - __NR_close; - break; - } -#else -#if defined(EXPORTED_SYS_CHDIR) && defined(EXPORTED_SYS_CLOSE) - if (ptr[0] == (unsigned long)&sys_close && - ptr[__NR_chdir - __NR_close] == (unsigned long)&sys_chdir) { - sys_call_table=ptr - __NR_close; +#elif defined(EXPORTED_SYS_WAIT4) && defined(EXPORTED_SYS_CLOSE) + if (ptr[0] == (unsigned long)&sys_close + && ptr[__NR_wait4 - __NR_close] == (unsigned long)&sys_wait4) { + sys_call_table = ptr - __NR_close; break; } -#else - if (ptr[0] == (unsigned long)&sys_exit && - ptr[__NR_open - __NR_exit] == (unsigned long)&sys_open) { - sys_call_table=ptr - __NR_exit; +#elif defined(EXPORTED_SYS_CHDIR) && defined(EXPORTED_SYS_CLOSE) + if (ptr[0] == (unsigned long)&sys_close + && ptr[__NR_chdir - __NR_close] == (unsigned long)&sys_chdir) { + sys_call_table = ptr - __NR_close; break; } -#endif -#endif -#endif +#elif defined(EXPORTED_SYS_OPEN) + if (ptr[0] == (unsigned long)&sys_exit + && ptr[__NR_open - __NR_exit] == (unsigned long)&sys_open) { + sys_call_table = ptr - __NR_exit; + break; + } +#else /* EXPORTED_SYS_OPEN */ + break; +#endif /* EXPORTED_KALLSYMS_ADDRESS */ } #ifdef EXPORTED_KALLSYMS_ADDRESS - ret=kallsyms_address_to_symbol((unsigned long)sys_call_table, &mod_name, - &mod_start, &mod_end, &sec_name, &sec_start, &sec_end, - &sym_name, &sym_start, &sym_end); + ret = + kallsyms_address_to_symbol((unsigned long)sys_call_table, &mod_name, + &mod_start, &mod_end, &sec_name, + &sec_start, &sec_end, &sym_name, + &sym_start, &sym_end); if (ret && strcmp(sym_name, "sys_call_table")) - sys_call_table=0; -#endif -#endif + sys_call_table = 0; +#endif /* EXPORTED_KALLSYMS_ADDRESS */ if (!sys_call_table) { - printf("Failed to find address of sys_call_table\n"); - return -EIO; - } - printf("Found sys_call_table at %x\n", sys_call_table); -# ifdef AFS_SPARC64_LINUX20_ENV -error cant support this yet. -#endif -#endif /* SYS_CALL_TABLE */ + printf("Failed to find address of sys_call_table\n"); + sys_settimeofdayp = 0; + } else { + printf("Found sys_call_table at %x\n", sys_call_table); +#ifdef AFS_SPARC64_LINUX20_ENV + error cant support this yet.; +#endif /* AFS_SPARC64_LINUX20_ENV */ +#endif /* EXPORTED_SYS_CALL_TABLE */ #ifdef AFS_AMD64_LINUX20_ENV #ifndef EXPORTED_IA32_SYS_CALL_TABLE - ia32_sys_call_table=0; + ia32_sys_call_table = 0; #ifdef EXPORTED_KALLSYMS_SYMBOL - ret=1; - token=0; - while (ret) { - sym_start=0; - ret=kallsyms_symbol_to_address("ia32_sys_call_table", &token, - &mod_name, &mod_start, &mod_end, - &sec_name, &sec_start, &sec_end, - &sym_name, &sym_start, &sym_end); - if (ret && !strcmp(mod_name, "kernel")) + ret = 1; + token = 0; + while (ret) { + sym_start = 0; + ret = kallsyms_symbol_to_address("ia32_sys_call_table", &token, + &mod_name, &mod_start, &mod_end, + &sec_name, &sec_start, &sec_end, + &sym_name, &sym_start, &sym_end); + if (ret && !strcmp(mod_name, "kernel")) break; - } - if (ret && sym_start) { - ia32_sys_call_table=sym_start; - } + } + if (ret && sym_start) { + ia32_sys_call_table = sym_start; + } #else /* EXPORTED_KALLSYMS_SYMBOL */ #ifdef EXPORTED_KALLSYMS_ADDRESS - ret=kallsyms_address_to_symbol((unsigned long)&sys_close, &mod_name, - &mod_start, &mod_end, &sec_name, &sec_start, &sec_end, - &sym_name, &sym_start, &sym_end); - ptr=(unsigned long *)sec_start; - datalen=(sec_end-sec_start)/sizeof(unsigned long); + ret = kallsyms_address_to_symbol((unsigned long) + &interruptible_sleep_on, + &mod_name, &mod_start, &mod_end, + &sec_name, &sec_start, &sec_end, + &sym_name, &sym_start, &sym_end); + ptr = (unsigned long *)sec_start; + datalen = (sec_end - sec_start) / sizeof(unsigned long); #else /* EXPORTED_KALLSYMS_ADDRESS */ -#if defined(AFS_IA64_LINUX20_ENV) - ptr = (unsigned long *) (&sys_close - 0x180000); - datalen=0x180000/sizeof(ptr); -#else /* AFS_IA64_LINUX20_ENV */ #if defined(AFS_AMD64_LINUX20_ENV) - ptr=(unsigned long *)&interruptible_sleep_on; - datalen=0x180000/sizeof(ptr); + ptr = (unsigned long *)&interruptible_sleep_on; + datalen = 0x180000 / sizeof(ptr); #else /* AFS_AMD64_LINUX20_ENV */ - ptr=(unsigned long *)&interruptible_sleep_on; - datalen=16384; + ptr = (unsigned long *)&interruptible_sleep_on; + datalen = 16384; #endif /* AFS_AMD64_LINUX20_ENV */ -#endif /* AFS_IA64_LINUX20_ENV */ #endif /* EXPORTED_KALLSYMS_ADDRESS */ - for (offset=0;offset gp; - - sys_settimeofdayp = (void *) &sys_settimeofday; - - ((struct fptr *)sys_settimeofdayp)->ip = - SYSCALL2POINTER sys_call_table[__NR_settimeofday - 1024]; - ((struct fptr *)sys_settimeofdayp)->gp = kernel_gp; - -#else /* !AFS_IA64_LINUX20_ENV */ - sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday]; -#ifdef __NR_socketcall - sys_socketcallp = SYSCALL2POINTER sys_call_table[__NR_socketcall]; -#endif /* no socketcall on alpha */ + /* Initialize pointers to kernel syscalls. */ +#if !defined(AFS_LINUX24_ENV) + sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday]; #endif /* AFS_IA64_LINUX20_ENV */ - /* setup AFS entry point. */ - if ( + /* setup AFS entry point. */ + if ( #if defined(AFS_IA64_LINUX20_ENV) - SYSCALL2POINTER sys_call_table[__NR_afs_syscall - 1024] + SYSCALL2POINTER sys_call_table[__NR_afs_syscall - 1024] #else - SYSCALL2POINTER sys_call_table[__NR_afs_syscall] + SYSCALL2POINTER sys_call_table[__NR_afs_syscall] #endif - == afs_syscall) { - printf("AFS syscall entry point already in use!\n"); - return -EBUSY; - } - + == afs_syscall) { + printf("AFS syscall entry point already in use!\n"); + return -EBUSY; + } #if defined(AFS_IA64_LINUX20_ENV) - afs_ni_syscall = sys_call_table[__NR_afs_syscall - 1024]; - sys_call_table[__NR_afs_syscall - 1024] = POINTER2SYSCALL ((struct fptr *)afs_syscall_stub)->ip; + afs_ni_syscall = sys_call_table[__NR_afs_syscall - 1024]; + sys_call_table[__NR_afs_syscall - 1024] = + POINTER2SYSCALL((struct fptr *)afs_syscall_stub)->ip; #else /* AFS_IA64_LINUX20_ENV */ - afs_ni_syscall = sys_call_table[__NR_afs_syscall]; - sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall; -# ifdef AFS_SPARC64_LINUX20_ENV - afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall]; - sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32; -# endif + afs_ni_syscall = sys_call_table[__NR_afs_syscall]; + sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall; +#ifdef AFS_SPARC64_LINUX20_ENV + afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall]; + sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32; +#endif #endif /* AFS_IA64_LINUX20_ENV */ #ifdef AFS_AMD64_LINUX20_ENV - if (ia32_sys_call_table) { - ia32_ni_syscall = ia32_sys_call_table[__NR_ia32_afs_syscall]; - ia32_sys_call_table[__NR_ia32_afs_syscall] = POINTER2SYSCALL afs_syscall; + if (ia32_sys_call_table) { + ia32_ni_syscall = ia32_sys_call_table[__NR_ia32_afs_syscall]; + ia32_sys_call_table[__NR_ia32_afs_syscall] = + POINTER2SYSCALL afs_syscall; + } +#endif /* AFS_S390_LINUX22_ENV */ +#ifndef EXPORTED_SYS_CALL_TABLE } -#endif - +#endif /* EXPORTED_SYS_CALL_TABLE */ osi_Init(); - register_filesystem(&afs_file_system); + register_filesystem(&afs_fs_type); /* Intercept setgroups calls */ + if (sys_call_table) { #if defined(AFS_IA64_LINUX20_ENV) - sys_setgroupsp = (void *) &sys_setgroups; + sys_setgroupsp = (void *)&sys_setgroups; ((struct fptr *)sys_setgroupsp)->ip = - SYSCALL2POINTER sys_call_table[__NR_setgroups - 1024]; + SYSCALL2POINTER sys_call_table[__NR_setgroups - 1024]; ((struct fptr *)sys_setgroupsp)->gp = kernel_gp; - sys_call_table[__NR_setgroups - 1024] = POINTER2SYSCALL ((struct fptr *)afs_xsetgroups_stub)->ip; + sys_call_table[__NR_setgroups - 1024] = + POINTER2SYSCALL((struct fptr *)afs_xsetgroups_stub)->ip; #else /* AFS_IA64_LINUX20_ENV */ sys_setgroupsp = SYSCALL2POINTER sys_call_table[__NR_setgroups]; sys_call_table[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups; @@ -484,43 +503,56 @@ error cant support this yet. sys_setgroups32p = SYSCALL2POINTER sys_call_table[__NR_setgroups32]; sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32; #ifdef AFS_SPARC64_LINUX20_ENV - sys32_setgroups32p = SYSCALL2POINTER sys_call_table32[__NR_setgroups32]; - sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL afs32_xsetgroups32; + sys32_setgroups32p = + SYSCALL2POINTER sys_call_table32[__NR_setgroups32]; + sys_call_table32[__NR_setgroups32] = + POINTER2SYSCALL afs32_xsetgroups32; #endif /* AFS_SPARC64_LINUX20_ENV */ #endif /* __NR_setgroups32 */ -#ifdef AFS_AMD64_LINUX20_ENV +#ifdef AFS_AMD64_LINUX20_ENV if (ia32_sys_call_table) { - sys32_setgroupsp = + sys32_setgroupsp = SYSCALL2POINTER ia32_sys_call_table[__NR_ia32_setgroups]; - ia32_sys_call_table[__NR_ia32_setgroups] = + ia32_sys_call_table[__NR_ia32_setgroups] = POINTER2SYSCALL afs32_xsetgroups; #if defined(__NR_ia32_setgroups32) - sys32_setgroups32p = + sys32_setgroups32p = SYSCALL2POINTER ia32_sys_call_table[__NR_ia32_setgroups32]; - ia32_sys_call_table[__NR_ia32_setgroups32] = + ia32_sys_call_table[__NR_ia32_setgroups32] = POINTER2SYSCALL afs32_xsetgroups32; #endif /* __NR_ia32_setgroups32 */ } #endif /* AFS_AMD64_LINUX20_ENV */ #endif /* AFS_IA64_LINUX20_ENV */ +#ifdef AFS_PPC64_LINUX20_ENV + afs_ni_syscall = set_afs_syscall(afs_syscall); + sys_setgroupsp = set_afs_xsetgroups_syscall(afs_xsetgroups); + sys32_setgroupsp = set_afs_xsetgroups_syscall32(afs32_xsetgroups); +#endif + } + osi_sysctl_init(); + afsproc_init(); return 0; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) -void __exit afs_cleanup(void) +void __exit +afs_cleanup(void) #else -void cleanup_module(void) +void +cleanup_module(void) #endif { struct task_struct *t; osi_sysctl_clean(); - + if (sys_call_table) { #if defined(AFS_IA64_LINUX20_ENV) - sys_call_table[__NR_setgroups - 1024] = POINTER2SYSCALL ((struct fptr *) sys_setgroupsp)->ip; + sys_call_table[__NR_setgroups - 1024] = + POINTER2SYSCALL((struct fptr *)sys_setgroupsp)->ip; sys_call_table[__NR_afs_syscall - 1024] = afs_ni_syscall; #else /* AFS_IA64_LINUX20_ENV */ sys_call_table[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp; @@ -532,27 +564,35 @@ void cleanup_module(void) # if defined(__NR_setgroups32) sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p; # ifdef AFS_SPARC64_LINUX20_ENV - sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL sys32_setgroups32p; + sys_call_table32[__NR_setgroups32] = + POINTER2SYSCALL sys32_setgroups32p; # endif # endif #endif /* AFS_IA64_LINUX20_ENV */ #ifdef AFS_AMD64_LINUX20_ENV if (ia32_sys_call_table) { - ia32_sys_call_table[__NR_ia32_setgroups] = + ia32_sys_call_table[__NR_ia32_setgroups] = POINTER2SYSCALL sys32_setgroupsp; - ia32_sys_call_table[__NR_ia32_afs_syscall] = + ia32_sys_call_table[__NR_ia32_afs_syscall] = POINTER2SYSCALL ia32_ni_syscall; # if defined(__NR_setgroups32) - ia32_sys_call_table[__NR_ia32_setgroups32] = + ia32_sys_call_table[__NR_ia32_setgroups32] = POINTER2SYSCALL sys32_setgroups32p; #endif } #endif - unregister_filesystem(&afs_file_system); + } +#ifdef AFS_PPC64_LINUX20_ENV + set_afs_syscall(afs_ni_syscall); + set_afs_xsetgroups_syscall(sys_setgroupsp); + set_afs_xsetgroups_syscall32(sys32_setgroupsp); +#endif + unregister_filesystem(&afs_fs_type); - osi_linux_free_inode_pages(); /* Invalidate all pages using AFS inodes. */ + osi_linux_free_inode_pages(); /* Invalidate all pages using AFS inodes. */ osi_linux_free_afs_memory(); + afsproc_exit(); return; } @@ -562,9 +602,11 @@ module_exit(afs_cleanup); #endif -static long get_page_offset(void) +#if !defined(AFS_LINUX24_ENV) +static long +get_page_offset(void) { -#if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV) || defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PARISC_LINUX24_ENV) || defined(AFS_AMD64_LINUX20_ENV) +#if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV) || defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PARISC_LINUX24_ENV) || defined(AFS_AMD64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV) return PAGE_OFFSET; #else struct task_struct *p, *q; @@ -575,21 +617,22 @@ static long get_page_offset(void) #endif /* search backward thru the circular list */ #ifdef DEFINED_PREV_TASK - for(q = current; p = q; q = prev_task(p)) { + for (q = current; p = q; q = prev_task(p)) { #else - for(p = current; p; p = p->prev_task) { + for (p = current; p; p = p->prev_task) { #endif - if (p->pid == 1) { + if (p->pid == 1) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) - read_unlock(&tasklist_lock); + read_unlock(&tasklist_lock); #endif - return p->addr_limit.seg; - } + return p->addr_limit.seg; + } } - + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) read_unlock(&tasklist_lock); #endif - return 0; + return 0; #endif } +#endif /* !AFS_LINUX24_ENV */ diff --git a/src/afs/LINUX/osi_prototypes.h b/src/afs/LINUX/osi_prototypes.h index 0d119216c..b39361a6d 100644 --- a/src/afs/LINUX/osi_prototypes.h +++ b/src/afs/LINUX/osi_prototypes.h @@ -22,25 +22,25 @@ extern void osi_linux_verify_alloced_memory(void); /* osi_cred.c */ extern cred_t *crget(void); -extern void crfree(cred_t *cr); -extern cred_t *crdup(cred_t *cr); +extern void crfree(cred_t * cr); +extern cred_t *crdup(cred_t * cr); extern cred_t *crref(void); -extern void crset(cred_t *cr); +extern void crset(cred_t * cr); /* osi_file.c */ extern afs_rwlock_t afs_xosi; /* osi_misc.c */ extern int osi_lookupname(char *aname, uio_seg_t seg, int followlink, - vnode_t **dirvpp, struct dentry **dpp); + vnode_t ** dirvpp, struct dentry **dpp); extern int osi_InitCacheInfo(char *aname); -extern int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, - size_t *resid); -extern void inline setup_uio(uio_t *uiop, struct iovec *iovecp, char *buf, - int pos, int count, uio_flag_t flag, +extern int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, + size_t asize, size_t * resid); +extern void inline setup_uio(uio_t * uiop, struct iovec *iovecp, char *buf, + afs_offs_t pos, int count, uio_flag_t flag, uio_seg_t seg); -extern int osi_file_uio_rdwr(struct osi_file *osifile, uio_t *uiop, int rw); -extern void afs_osi_SetTime(osi_timeval_t *tvp); +extern int osi_file_uio_rdwr(struct osi_file *osifile, uio_t * uiop, int rw); +extern void afs_osi_SetTime(osi_timeval_t * tvp); extern void osi_linux_free_inode_pages(void); extern void check_bad_parent(struct dentry *dp); diff --git a/src/afs/LINUX/osi_sleep.c b/src/afs/LINUX/osi_sleep.c index 91dde0e29..b559dd2c9 100644 --- a/src/afs/LINUX/osi_sleep.c +++ b/src/afs/LINUX/osi_sleep.c @@ -8,37 +8,37 @@ */ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_sleep.c,v 1.1.1.10 2003/04/13 19:02:46 hartmans Exp $"); - -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/param.h" +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_sleep.c,v 1.21 2003/07/15 23:14:24 shadow Exp $"); +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok); -void afs_osi_Wakeup(char *event); -void afs_osi_Sleep(char *event); static char waitV, dummyV; -void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) +void +afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) { AFS_STATCNT(osi_InitWaitHandle); achandle->proc = (caddr_t) 0; } /* cancel osi_Wait */ -void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) { caddr_t proc; AFS_STATCNT(osi_CancelWait); proc = achandle->proc; - if (proc == 0) return; - achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ + if (proc == 0) + return; + achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ afs_osi_Wakeup(&waitV); } @@ -46,23 +46,23 @@ void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) * Waits for data on ahandle, or ams ms later. ahandle may be null. * Returns 0 if timeout and EINTR if signalled. */ -int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) +int +afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) { - int code; - afs_int32 endTime, tid; + afs_int32 endTime; struct timer_list *timer = NULL; + int code; AFS_STATCNT(osi_Wait); - endTime = osi_Time() + (ams/1000); + endTime = osi_Time() + (ams / 1000); if (ahandle) ahandle->proc = (caddr_t) current; do { - AFS_ASSERT_GLOCK(); - code = 0; - code = osi_TimedSleep(&waitV, ams, aintok); - - if (code) break; + AFS_ASSERT_GLOCK(); + code = osi_TimedSleep(&waitV, ams, 1); + if (code) + break; if (ahandle && (ahandle->proc == (caddr_t) 0)) { /* we've been signalled */ break; @@ -79,8 +79,8 @@ typedef struct afs_event { char *event; /* lwp event: an address */ int refcount; /* Is it in use? */ int seq; /* Sequence number: this is incremented - by wakeup calls; wait will not return until - it changes */ + * by wakeup calls; wait will not return until + * it changes */ #if defined(AFS_LINUX24_ENV) wait_queue_head_t cond; #else @@ -89,13 +89,14 @@ typedef struct afs_event { } afs_event_t; #define HASHSIZE 128 -afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */ +afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */ #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1)); int afs_evhashcnt = 0; /* Get and initialize event structure corresponding to lwp event (i.e. address) * */ -static afs_event_t *afs_getevent(char *event) +static afs_event_t * +afs_getevent(char *event) { afs_event_t *evp, *newp = 0; int hashcode; @@ -132,11 +133,12 @@ static afs_event_t *afs_getevent(char *event) * a deadlock). */ -static void afs_addevent(char *event) +static void +afs_addevent(char *event) { int hashcode; afs_event_t *newp; - + AFS_ASSERT_GLOCK(); hashcode = afs_evhash(event); newp = osi_linux_alloc(sizeof(afs_event_t), 0); @@ -149,7 +151,7 @@ static void afs_addevent(char *event) init_waitqueue(&newp->cond); #endif newp->seq = 0; - newp->event = &dummyV; /* Dummy address for new events */ + newp->event = &dummyV; /* Dummy address for new events */ newp->refcount = 0; } @@ -160,17 +162,16 @@ static void afs_addevent(char *event) /* Release the specified event */ #define relevent(evp) ((evp)->refcount--) -/* afs_osi_Sleep -- waits for an event to be notified, ignoring signals. - * - NOTE: that on Linux, there are circumstances in which TASK_INTERRUPTIBLE - * can wake up, even if all signals are blocked - * - TODO: handle signals correctly by passing an indication back to the - * caller that the wait has been interrupted and the stack should be cleaned - * up preparatory to signal delivery +/* afs_osi_SleepSig + * + * Waits for an event to be notified, returning early if a signal + * is received. Returns EINTR if signaled, and 0 otherwise. */ -void afs_osi_Sleep(char *event) +int +afs_osi_SleepSig(void *event) { struct afs_event *evp; - int seq; + int seq, retval; #ifdef DECLARE_WAITQUEUE DECLARE_WAITQUEUE(wait, current); #else @@ -179,38 +180,56 @@ void afs_osi_Sleep(char *event) evp = afs_getevent(event); if (!evp) { - afs_addevent(event); + afs_addevent(event); evp = afs_getevent(event); } seq = evp->seq; + retval = 0; add_wait_queue(&evp->cond, &wait); while (seq == evp->seq) { - sigset_t saved_set; - set_current_state(TASK_INTERRUPTIBLE); AFS_ASSERT_GLOCK(); AFS_GUNLOCK(); - - SIG_LOCK(current); - saved_set = current->blocked; - sigfillset(¤t->blocked); - RECALC_SIGPENDING(current); - SIG_UNLOCK(current); - schedule(); - - SIG_LOCK(current); - current->blocked = saved_set; - RECALC_SIGPENDING(current); - SIG_UNLOCK(current); AFS_GLOCK(); + if (signal_pending(current)) { + retval = EINTR; + break; + } } remove_wait_queue(&evp->cond, &wait); set_current_state(TASK_RUNNING); relevent(evp); + return retval; +} + +/* afs_osi_Sleep -- waits for an event to be notified, ignoring signals. + * - NOTE: that on Linux, there are circumstances in which TASK_INTERRUPTIBLE + * can wake up, even if all signals are blocked + * - TODO: handle signals correctly by passing an indication back to the + * caller that the wait has been interrupted and the stack should be cleaned + * up preparatory to signal delivery + */ +void +afs_osi_Sleep(void *event) +{ + sigset_t saved_set; + + SIG_LOCK(current); + saved_set = current->blocked; + sigfillset(¤t->blocked); + RECALC_SIGPENDING(current); + SIG_UNLOCK(current); + + afs_osi_SleepSig(event); + + SIG_LOCK(current); + current->blocked = saved_set; + RECALC_SIGPENDING(current); + SIG_UNLOCK(current); } /* osi_TimedSleep @@ -223,7 +242,8 @@ void afs_osi_Sleep(char *event) * Returns 0 if timeout, EINTR if signalled, and EGAIN if it might * have raced. */ -static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) +static int +osi_TimedSleep(char *event, afs_int32 ams, int aintok) { int code = 0; long ticks = (ams * HZ / 1000) + 1; @@ -236,23 +256,23 @@ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) evp = afs_getevent(event); if (!evp) { - afs_addevent(event); + afs_addevent(event); evp = afs_getevent(event); } add_wait_queue(&evp->cond, &wait); set_current_state(TASK_INTERRUPTIBLE); /* always sleep TASK_INTERRUPTIBLE to keep load average - from artifically increasing. */ - + * from artifically increasing. */ AFS_GUNLOCK(); + if (aintok) { - if (schedule_timeout(ticks)) - code = EINTR; + if (schedule_timeout(ticks)) + code = EINTR; } else - schedule_timeout(ticks); - AFS_GLOCK(); + schedule_timeout(ticks); + AFS_GLOCK(); remove_wait_queue(&evp->cond, &wait); set_current_state(TASK_RUNNING); @@ -262,17 +282,21 @@ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) } -void afs_osi_Wakeup(char *event) +int +afs_osi_Wakeup(void *event) { + int ret = 2; struct afs_event *evp; evp = afs_getevent(event); - if (!evp) /* No sleepers */ - return; + if (!evp) /* No sleepers */ + return 1; if (evp->refcount > 1) { - evp->seq++; + evp->seq++; wake_up(&evp->cond); + ret = 0; } relevent(evp); + return ret; } diff --git a/src/afs/LINUX/osi_sysctl.c b/src/afs/LINUX/osi_sysctl.c index eabc30915..3b8e610f3 100644 --- a/src/afs/LINUX/osi_sysctl.c +++ b/src/afs/LINUX/osi_sysctl.c @@ -1,17 +1,17 @@ /* * osi_sysctl.c: Linux sysctl interface to OpenAFS * - * $Id: osi_sysctl.c,v 1.1.1.2 2002/08/02 04:28:56 hartmans Exp $ + * $Id: osi_sysctl.c,v 1.7 2003/08/08 19:55:05 shadow Exp $ * * Written Jan 30, 2002 by Kris Van Hees (Sine Nomine Associates) */ #include -#include "../afs/param.h" +#include "afs/param.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ #include #include @@ -25,41 +25,55 @@ extern afs_int32 hm_retry_int; static struct ctl_table_header *afs_sysctl = NULL; static ctl_table afs_sysctl_table[] = { - {1, "hm_retry_RO", - &hm_retry_RO, sizeof(afs_int32), 0644, NULL, - &proc_dointvec}, - {2, "hm_retry_RW", - &hm_retry_RW, sizeof(afs_int32), 0644, NULL, - &proc_dointvec}, - {3, "hm_retry_int", - &hm_retry_int, sizeof(afs_int32), 0644, NULL, - &proc_dointvec}, - {4, "GCPAGs", - &afs_gcpags, sizeof(afs_int32), 0644, NULL, - &proc_dointvec}, - {0} + {1, "hm_retry_RO", + &hm_retry_RO, sizeof(afs_int32), 0644, NULL, + &proc_dointvec} + , + {2, "hm_retry_RW", + &hm_retry_RW, sizeof(afs_int32), 0644, NULL, + &proc_dointvec} + , + {3, "hm_retry_int", + &hm_retry_int, sizeof(afs_int32), 0644, NULL, + &proc_dointvec} + , + {4, "GCPAGs", + &afs_gcpags, sizeof(afs_int32), 0644, NULL, + &proc_dointvec} + , + {5, "rx_deadtime", + &afs_rx_deadtime, sizeof(afs_int32), 0644, NULL, + &proc_dointvec} + , + {6, "bkVolPref", + &afs_bkvolpref, sizeof(afs_int32), 0644, NULL, + &proc_dointvec} + , + {0} }; static ctl_table fs_sysctl_table[] = { - {1, "afs", NULL, 0, 0555, afs_sysctl_table}, - {0} + {1, "afs", NULL, 0, 0555, afs_sysctl_table}, + {0} }; -int osi_sysctl_init() +int +osi_sysctl_init() { - afs_sysctl = register_sysctl_table(fs_sysctl_table, 0); - if (!afs_sysctl) - return -1; + afs_sysctl = register_sysctl_table(fs_sysctl_table, 0); + if (!afs_sysctl) + return -1; - return 0; + return 0; } -void osi_sysctl_clean() +void +osi_sysctl_clean() { - if (afs_sysctl) { - unregister_sysctl_table(afs_sysctl); - afs_sysctl = NULL; - } + if (afs_sysctl) { + unregister_sysctl_table(afs_sysctl); + afs_sysctl = NULL; + } } #endif /* CONFIG_SYSCTL */ diff --git a/src/afs/LINUX/osi_vfs.hin b/src/afs/LINUX/osi_vfs.hin index 90a572c17..87d58fe65 100644 --- a/src/afs/LINUX/osi_vfs.hin +++ b/src/afs/LINUX/osi_vfs.hin @@ -17,6 +17,7 @@ #ifndef OSI_VFS_H_ #define OSI_VFS_H_ +#if !defined(AFS_LINUX26_ENV) /* The vnode should match the current implementation of the fs independent * part of the Linux inode. */ @@ -24,6 +25,10 @@ /* LINUX VNODE INCLUDED BELOW -- DO NOT MODIFY */ typedef struct vnode vnode_t; +#else +typedef struct inode vnode_t; +#define vnode inode +#endif /* Map vnode fields to inode fields. */ #define i_number i_ino @@ -58,12 +63,6 @@ enum vcexcl { EXCL, NONEXCL } ; #define FSYNC O_SYNC #define VTOI(V) ((struct inode*)V) -#ifdef AFS_LINUX24_ENV -#define VN_HOLD(V) atomic_inc(&((vnode_t*)V)->i_count) -#else -#define VN_HOLD(V) ((vnode_t*)V)->i_count++; -#endif -#define VN_RELE(V) osi_iput((struct inode *)V); #define VFS_STATFS(V, S) ((V)->s_op->statfs)((V), (S), sizeof(*(S))) @@ -80,7 +79,7 @@ enum vcexcl { EXCL, NONEXCL } ; typedef struct vattr { int va_type; /* One of v_types above. */ - size_t va_size; + afs_size_t va_size; unsigned long va_blocks; unsigned long va_blocksize; int va_mask; /* AT_xxx operation to perform. */ @@ -105,7 +104,9 @@ typedef struct vattr { */ #define AT_SIZE ATTR_SIZE #define AT_MODE ATTR_MODE +#undef AT_UID #define AT_UID ATTR_UID +#undef AT_GID #define AT_GID ATTR_GID #define AT_MTIME ATTR_MTIME diff --git a/src/afs/LINUX/osi_vfsops.c b/src/afs/LINUX/osi_vfsops.c index 610daced5..5e9f30d8b 100644 --- a/src/afs/LINUX/osi_vfsops.c +++ b/src/afs/LINUX/osi_vfsops.c @@ -13,26 +13,31 @@ * super_block operations should return negated errno to Linux. */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_vfsops.c,v 1.1.1.14 2003/07/30 17:08:10 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_vfsops.c,v 1.27 2004/04/21 02:20:23 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" -#include "../h/locks.h" +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" +#if !defined(AFS_LINUX26_ENV) +#include "h/locks.h" +#endif #if defined(AFS_LINUX24_ENV) -#include "../h/smp_lock.h" +#include "h/smp_lock.h" #endif -#define __NO_VERSION__ /* don't define kernel_verion in module.h */ +#define __NO_VERSION__ /* don't define kernel_version in module.h */ #include struct vcache *afs_globalVp = 0; struct vfs *afs_globalVFS = 0; +#if defined(AFS_LINUX24_ENV) struct nameidata afs_cacheNd; -int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */ +#endif +int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */ extern struct super_operations afs_sops; extern afs_rwlock_t afs_xvcache; @@ -44,8 +49,9 @@ extern struct dentry_operations afs_dentry_operations; static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp); static void update_inode_cache(struct inode *ip, struct vattr *vp); static int afs_root(struct super_block *afsp); -struct super_block *afs_read_super(struct super_block *sb, void *data, - int silent); +struct super_block *afs_read_super(struct super_block *sb, void *data, int silent); +int afs_fill_super(struct super_block *sb, void *data, int silent); +static struct super_block *afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data); void put_inode_on_dummy_list(struct inode *ip); /* afs_file_system @@ -55,15 +61,28 @@ void put_inode_on_dummy_list(struct inode *ip); * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super. * We are expected to setup the super_block. See afs_read_super. */ -#if defined(AFS_LINUX24_ENV) -DECLARE_FSTYPE(afs_file_system, "afs", afs_read_super, 0); +#if defined(AFS_LINUX26_ENV) +struct backing_dev_info afs_backing_dev_info = { + .ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE, + .state = 0, +}; + +struct file_system_type afs_fs_type = { + .owner = THIS_MODULE, + .name = "afs", + .get_sb = afs_get_sb, + .kill_sb = kill_anon_super, + .fs_flags = FS_BINARY_MOUNTDATA, +}; +#elif defined(AFS_LINUX24_ENV) +DECLARE_FSTYPE(afs_fs_type, "afs", afs_read_super, 0); #else -struct file_system_type afs_file_system = { - "afs", /* name - used by mount operation. */ - 0, /* requires_dev - no for network filesystems. mount() will - * pass us an "unnamed" device. */ - afs_read_super, /* wrapper to afs_mount */ - NULL /* pointer to next file_system_type once registered. */ +struct file_system_type afs_fs_type = { + "afs", /* name - used by mount operation. */ + 0, /* requires_dev - no for network filesystems. mount() will + * pass us an "unnamed" device. */ + afs_read_super, /* wrapper to afs_mount */ + NULL /* pointer to next file_system_type once registered. */ }; #endif @@ -71,16 +90,32 @@ struct file_system_type afs_file_system = { * read the "super block" for AFS - roughly eguivalent to struct vfs. * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super. */ -struct super_block *afs_read_super(struct super_block *sb, void *data, - int silent) +#if defined(AFS_LINUX26_ENV) +static struct super_block * +afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) +{ + return get_sb_nodev(fs_type, flags, data, afs_fill_super); +} + +int +afs_fill_super(struct super_block *sb, void *data, int silent) +#else +struct super_block * +afs_read_super(struct super_block *sb, void *data, int silent) +#endif { int code = 0; AFS_GLOCK(); if (afs_was_mounted) { - printf("You must reload the AFS kernel extensions before remounting AFS.\n"); + printf + ("You must reload the AFS kernel extensions before remounting AFS.\n"); AFS_GUNLOCK(); +#if defined(AFS_LINUX26_ENV) + return -EINVAL; +#else return NULL; +#endif } afs_was_mounted = 1; @@ -88,7 +123,11 @@ struct super_block *afs_read_super(struct super_block *sb, void *data, #if !defined(AFS_LINUX24_ENV) lock_super(sb); #endif +#if defined(AFS_LINUX26_ENV) + __module_get(THIS_MODULE); +#else MOD_INC_USE_COUNT; +#endif afs_globalVFS = sb; sb->s_blocksize = 1024; @@ -100,40 +139,52 @@ struct super_block *afs_read_super(struct super_block *sb, void *data, #endif code = afs_root(sb); if (code) +#if defined(AFS_LINUX26_ENV) + module_put(THIS_MODULE); +#else MOD_DEC_USE_COUNT; +#endif #if !defined(AFS_LINUX24_ENV) unlock_super(sb); #endif AFS_GUNLOCK(); +#if defined(AFS_LINUX26_ENV) + return code ? -EINVAL : 0; +#else return code ? NULL : sb; +#endif } /* afs_root - stat the root of the file system. AFS global held on entry. */ -static int afs_root(struct super_block *afsp) +static int +afs_root(struct super_block *afsp) { register afs_int32 code = 0; struct vrequest treq; - register struct vcache *tvp=0; + register struct vcache *tvp = 0; AFS_STATCNT(afs_root); if (afs_globalVp && (afs_globalVp->states & CStatd)) { tvp = afs_globalVp; } else { cred_t *credp = crref(); - afs_globalVp = 0; - if (!(code = afs_InitReq(&treq, credp)) && - !(code = afs_CheckInit())) { - tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + afs_globalVp = NULL; + } + + if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) { + tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); if (tvp) { extern struct inode_operations afs_dir_iops; #if defined(AFS_LINUX24_ENV) extern struct file_operations afs_dir_fops; #endif - + /* "/afs" is a directory, reset inode ops accordingly. */ AFSTOV(tvp)->v_op = &afs_dir_iops; #if defined(AFS_LINUX24_ENV) @@ -161,24 +212,12 @@ static int afs_root(struct super_block *afsp) /* super_operations */ -/* afs_read_inode - * called via iget to read in the inode. The passed in inode has i_ino, i_dev - * and i_sb setup on input. Linux file systems use this to get super block - * inode information, so we don't really care what happens here. - * For Linux 2.2, we'll be called if we participate in the inode pool. - */ -void afs_read_inode(struct inode *ip) -{ - /* I don't think we ever get called with this. So print if we do. */ - printf("afs_read_inode: Called for inode %d\n", ip->i_ino); -} - - /* afs_notify_change * Linux version of setattr call. What to change is in the iattr struct. * We need to set bits in both the Linux inode as well as the vcache. */ -int afs_notify_change(struct dentry *dp, struct iattr* iattrp) +int +afs_notify_change(struct dentry *dp, struct iattr *iattrp) { struct vattr vattr; int code; @@ -186,8 +225,11 @@ int afs_notify_change(struct dentry *dp, struct iattr* iattrp) struct inode *ip = dp->d_inode; AFS_GLOCK(); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif VATTR_NULL(&vattr); - iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */ + iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */ update_inode_cache(ip, &vattr); code = afs_setattr(ITOAFS(ip), &vattr, credp); afs_CopyOutAttrs(ITOAFS(ip), &vattr); @@ -195,6 +237,9 @@ int afs_notify_change(struct dentry *dp, struct iattr* iattrp) * least we've got the newest version of what was supposed to be set. */ +#if defined(AFS_LINUX26_ENV) + unlock_kernel(); +#endif AFS_GUNLOCK(); crfree(credp); return -code; @@ -220,20 +265,29 @@ static LIST_HEAD(dummy_inode_list); * has synced some pages of a file to disk. */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) -void afs_write_inode(struct inode *ip, int unused) +static void +afs_write_inode(struct inode *ip, int unused) #else -void afs_write_inode(struct inode *ip) +static void +afs_write_inode(struct inode *ip) #endif { - /* and put it back on our dummy list. */ list_del(&ip->i_list); - list_add(&ip->i_list, &dummy_inode_list); + /* and put it back on our dummy list. */ + put_inode_on_dummy_list(ip); /* for now we don't actually update the metadata during msync. This * is just to keep linux happy. */ } +static void +afs_destroy_inode(struct inode *ip) +{ + ip->i_state = 0; +} + + /* afs_put_inode * called from iput when count goes to zero. Linux version of inactive. * For Linux 2.2, this funcionality has moved to the delete inode super op. @@ -241,9 +295,14 @@ void afs_write_inode(struct inode *ip) * That will trigger the call to delete routine. */ -void afs_delete_inode(struct inode *ip) +static void +afs_delete_inode(struct inode *ip) { - struct vcache *vc = ITOAFS(ip); + struct vcache *vp = ITOAFS(ip); + +#ifdef AFS_LINUX26_ENV + put_inode_on_dummy_list(ip); +#endif AFS_GLOCK(); osi_clear_inode(ip); @@ -253,7 +312,8 @@ void afs_delete_inode(struct inode *ip) /* afs_put_super * Called from unmount to release super_block. */ -void afs_put_super(struct super_block *sbp) +static void +afs_put_super(struct super_block *sbp) { extern int afs_afs_cold_shutdown; int code = 0; @@ -262,116 +322,104 @@ void afs_put_super(struct super_block *sbp) AFS_GLOCK(); AFS_STATCNT(afs_unmount); +#if !defined(AFS_LINUX26_ENV) if (!suser()) { AFS_GUNLOCK(); return; } +#endif afs_globalVFS = 0; afs_globalVp = 0; afs_shutdown(); +#if defined(AFS_LINUX24_ENV) path_release(&afs_cacheNd); +#endif osi_linux_verify_alloced_memory(); - done: + done: AFS_GUNLOCK(); if (!code) { sbp->s_dev = 0; +#if defined(AFS_LINUX26_ENV) + module_put(THIS_MODULE); +#else MOD_DEC_USE_COUNT; +#endif } } -#ifdef NOTUSED -/* afs_write_super - * Not required since we don't write out a super block. */ -void afs_write_super(struct super_block *sbp) -{ -} - -/* afs_remount_fs - * Used to remount filesystems with different flags. Not relevant for AFS. - */ -int afs_remount_fs(struct super_block *sbp, int *, char *) -{ - return -EINVAL; -} -#endif /* afs_statfs * statp is in user space, so we need to cobble together a statfs, then * copy it. */ -#if defined(AFS_LINUX24_ENV) -int afs_statfs(struct super_block *sbp, struct statfs *statp) +#if defined(AFS_LINUX26_ENV) +int +afs_statfs(struct super_block *sbp, struct kstatfs *statp) +#elif defined(AFS_LINUX24_ENV) +int +afs_statfs(struct super_block *sbp, struct statfs *statp) #else -int afs_statfs(struct super_block *sbp, struct statfs *statp, int size) +int +afs_statfs(struct super_block *sbp, struct statfs *__statp, int size) #endif { +#if !defined(AFS_LINUX24_ENV) struct statfs stat; - AFS_STATCNT(afs_statfs); - -#if !defined(AFS_LINUX24_ENV) if (size < sizeof(struct statfs)) return; - + memset(&stat, 0, size); + statp = &stat; #endif - stat.f_type = 0; /* Can we get a real type sometime? */ - stat.f_bsize = sbp->s_blocksize; - stat.f_blocks = stat.f_bfree = stat.f_bavail = stat.f_files = - stat.f_ffree = 9000000; - stat.f_fsid.val[0] = AFS_VFSMAGIC; - stat.f_fsid.val[1] = AFS_VFSFSID; - stat.f_namelen = 256; -#if defined(AFS_LINUX24_ENV) - *statp = stat; -#else - memcpy_tofs(statp, &stat, size); + AFS_STATCNT(afs_statfs); + + statp->f_type = 0; /* Can we get a real type sometime? */ + statp->f_bsize = sbp->s_blocksize; + statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files = + statp->f_ffree = 9000000; + statp->f_fsid.val[0] = AFS_VFSMAGIC; + statp->f_fsid.val[1] = AFS_VFSFSID; + statp->f_namelen = 256; + +#if !defined(AFS_LINUX24_ENV) + memcpy_tofs(__statp, &stat, size); #endif return 0; } - -void +void afs_umount_begin(struct super_block *sbp) { - afs_shuttingdown=1; + afs_shuttingdown = 1; } -#if defined(AFS_LINUX24_ENV) -struct super_operations afs_sops = { - read_inode: afs_read_inode, - write_inode: afs_write_inode, - delete_inode: afs_delete_inode, - put_super: afs_put_super, - statfs: afs_statfs, - umount_begin: afs_umount_begin -}; -#else struct super_operations afs_sops = { - afs_read_inode, - afs_write_inode, /* afs_write_inode - see doc above. */ - NULL, /* afs_put_inode */ - afs_delete_inode, - afs_notify_change, - afs_put_super, - NULL, /* afs_write_super - see doc above */ - afs_statfs, - NULL, /* afs_remount_fs - see doc above */ - NULL, /* afs_clear_inode */ - afs_umount_begin -}; +#if defined(AFS_LINUX26_ENV) + .drop_inode = generic_delete_inode, + .destroy_inode = afs_destroy_inode, #endif + .delete_inode = afs_delete_inode, + .write_inode = afs_write_inode, + .put_super = afs_put_super, + .statfs = afs_statfs, + .umount_begin = afs_umount_begin +#if !defined(AFS_LINUX24_ENV) + .notify_change = afs_notify_change, +#endif +}; /************** Support routines ************************/ /* vattr_setattr * Set iattr data into vattr. Assume vattr cleared before call. */ -static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp) +static void +iattr2vattr(struct vattr *vattrp, struct iattr *iattrp) { vattrp->va_mask = iattrp->ia_valid; if (iattrp->ia_valid & ATTR_MODE) @@ -383,15 +431,27 @@ static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp) if (iattrp->ia_valid & ATTR_SIZE) vattrp->va_size = iattrp->ia_size; if (iattrp->ia_valid & ATTR_ATIME) { +#if defined(AFS_LINUX26_ENV) + vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec; +#else vattrp->va_atime.tv_sec = iattrp->ia_atime; +#endif vattrp->va_atime.tv_usec = 0; } if (iattrp->ia_valid & ATTR_MTIME) { +#if defined(AFS_LINUX26_ENV) + vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec; +#else vattrp->va_mtime.tv_sec = iattrp->ia_mtime; +#endif vattrp->va_mtime.tv_usec = 0; } if (iattrp->ia_valid & ATTR_CTIME) { +#if defined(AFS_LINUX26_ENV) + vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec; +#else vattrp->va_ctime.tv_sec = iattrp->ia_ctime; +#endif vattrp->va_ctime.tv_usec = 0; } } @@ -400,7 +460,8 @@ static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp) * Update inode with info from vattr struct. Use va_mask to determine what * to update. */ -static void update_inode_cache(struct inode *ip, struct vattr *vp) +static void +update_inode_cache(struct inode *ip, struct vattr *vp) { if (vp->va_mask & ATTR_MODE) ip->i_mode = vp->va_mode; @@ -411,17 +472,30 @@ static void update_inode_cache(struct inode *ip, struct vattr *vp) if (vp->va_mask & ATTR_SIZE) ip->i_size = vp->va_size; if (vp->va_mask & ATTR_ATIME) +#if defined(AFS_LINUX26_ENV) + ip->i_atime.tv_sec = vp->va_atime.tv_sec; +#else ip->i_atime = vp->va_atime.tv_sec; +#endif if (vp->va_mask & ATTR_MTIME) +#if defined(AFS_LINUX26_ENV) + ip->i_mtime.tv_sec = vp->va_mtime.tv_sec; +#else ip->i_mtime = vp->va_mtime.tv_sec; +#endif if (vp->va_mask & ATTR_CTIME) +#if defined(AFS_LINUX26_ENV) + ip->i_ctime.tv_sec = vp->va_ctime.tv_sec; +#else ip->i_ctime = vp->va_ctime.tv_sec; +#endif } /* vattr2inode * Rewrite the inode cache from the attr. Assumes all vattr fields are valid. */ -void vattr2inode(struct inode *ip, struct vattr *vp) +void +vattr2inode(struct inode *ip, struct vattr *vp) { ip->i_ino = vp->va_nodeid; ip->i_nlink = vp->va_nlink; @@ -432,44 +506,45 @@ void vattr2inode(struct inode *ip, struct vattr *vp) ip->i_uid = vp->va_uid; ip->i_gid = vp->va_gid; ip->i_size = vp->va_size; +#if defined(AFS_LINUX26_ENV) + ip->i_atime.tv_sec = vp->va_atime.tv_sec; + ip->i_mtime.tv_sec = vp->va_mtime.tv_sec; + ip->i_ctime.tv_sec = vp->va_ctime.tv_sec; +#else ip->i_atime = vp->va_atime.tv_sec; ip->i_mtime = vp->va_mtime.tv_sec; ip->i_ctime = vp->va_ctime.tv_sec; - - /* we should put our inodes on a dummy inode list to keep linux happy.*/ - if (!ip->i_list.prev && !ip->i_list.next) { - /* this might be bad as we are reaching under the covers of the - * list structure but we want to avoid putting the inode - * on the list more than once. */ - put_inode_on_dummy_list(ip); - } +#endif } /* Put this afs inode on our own dummy list. Linux expects to see inodes * nicely strung up in lists. Linux inode syncing code chokes on our inodes if * they're not on any lists. */ -void put_inode_on_dummy_list(struct inode *ip) +void +put_inode_on_dummy_list(struct inode *ip) { /* Initialize list. See explanation above. */ list_add(&ip->i_list, &dummy_inode_list); } /* And yet another routine to update the inode cache - called from ProcessFS */ -void vcache2inode(struct vcache *avc) +void +vcache2inode(struct vcache *avc) { struct vattr vattr; VATTR_NULL(&vattr); - afs_CopyOutAttrs(avc, &vattr); /* calls vattr2inode */ + afs_CopyOutAttrs(avc, &vattr); /* calls vattr2inode */ } /* Yet another one for fakestat'ed mountpoints */ -void vcache2fakeinode(struct vcache *rootvp, struct vcache *mpvp) +void +vcache2fakeinode(struct vcache *rootvp, struct vcache *mpvp) { struct vattr vattr; VATTR_NULL(&vattr); afs_CopyOutAttrs(rootvp, &vattr); - vattr2inode(AFSTOV(mpvp), &vattr); + vattr2inode(AFSTOI(mpvp), &vattr); } diff --git a/src/afs/LINUX/osi_vm.c b/src/afs/LINUX/osi_vm.c index fb859018b..542a97963 100644 --- a/src/afs/LINUX/osi_vm.c +++ b/src/afs/LINUX/osi_vm.c @@ -8,13 +8,14 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_vm.c,v 1.1.1.9 2002/05/10 23:44:09 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_vm.c,v 1.16 2004/04/12 16:04:32 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ /* Linux VM operations * @@ -39,7 +40,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_vm.c,v 1.1.1.9 2002/05/10 * is not dropped and re-acquired for any platform. It may be that *slept is * therefore obsolescent. */ -int osi_VM_FlushVCache(struct vcache *avc, int *slept) +int +osi_VM_FlushVCache(struct vcache *avc, int *slept) { struct inode *ip = AFSTOI(avc); @@ -68,16 +70,24 @@ int osi_VM_FlushVCache(struct vcache *avc, int *slept) * Since we drop and re-obtain the lock, we can't guarantee that there won't * be some pages around when we return, newly created by concurrent activity. */ -void osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) +void +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { - invalidate_inode_pages(AFSTOI(avc)); + struct inode *ip = AFSTOI(avc); + +#if defined(AFS_LINUX26_ENV) + invalidate_inode_pages(ip->i_mapping); +#else + invalidate_inode_pages(ip); +#endif } /* Flush and invalidate pages, for fsync() with INVAL flag * * Locking: only the global lock is held. */ -void osi_VM_FSyncInval(struct vcache *avc) +void +osi_VM_FSyncInval(struct vcache *avc) { } @@ -87,7 +97,8 @@ void osi_VM_FSyncInval(struct vcache *avc) * Locking: the vcache entry's lock is held. It will usually be dropped and * re-obtained. */ -void osi_VM_StoreAllSegments(struct vcache *avc) +void +osi_VM_StoreAllSegments(struct vcache *avc) { struct inode *ip = AFSTOI(avc); @@ -95,7 +106,11 @@ void osi_VM_StoreAllSegments(struct vcache *avc) /* filemap_fdatasync() only exported in 2.4.5 and above */ ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); +#if defined(AFS_LINUX26_ENV) + filemap_fdatawrite(ip->i_mapping); +#else filemap_fdatasync(ip->i_mapping); +#endif filemap_fdatawait(ip->i_mapping); AFS_GLOCK(); ObtainWriteLock(&avc->lock, 121); @@ -106,7 +121,8 @@ void osi_VM_StoreAllSegments(struct vcache *avc) * * Locking: No lock is held, not even the global lock. */ -void osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) +void +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) struct inode *ip = AFSTOI(avc); @@ -127,7 +143,8 @@ void osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) * activeV is raised. This is supposed to block pageins, but at present * it only works on Solaris. */ -void osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) +void +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) struct inode *ip = AFSTOI(avc); diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c index aaf21c552..fad6b7687 100644 --- a/src/afs/LINUX/osi_vnodeops.c +++ b/src/afs/LINUX/osi_vnodeops.c @@ -9,9 +9,7 @@ /* * Linux specific vnodeops. Also includes the glue routines required to call - * AFS vnodeops. The "NOTUSED" #define is used to indicate routines and - * calling sequences present in an ops table that we don't actually use. - * They are present solely for documentation purposes. + * AFS vnodeops. * * So far the only truly scary part is that Linux relies on the inode cache * to be up to date. Don't you dare break a callback and expect an fstat @@ -21,18 +19,19 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_vnodeops.c,v 1.15 2003/04/13 19:32:22 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/LINUX/osi_vnodeops.c,v 1.74 2004/04/21 02:20:23 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" -#include "../afs/afs_osidnlc.h" -#include "../h/mm.h" -#include "../h/pagemap.h" +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" +#include "afs/afs_osidnlc.h" +#include "h/mm.h" +#include "h/pagemap.h" #if defined(AFS_LINUX24_ENV) -#include "../h/smp_lock.h" +#include "h/smp_lock.h" #endif #ifdef pgoff2loff @@ -41,10 +40,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/LINUX/osi_vnodeops.c,v 1.15 2003/04 #define pageoff(pp) pp->offset #endif +#if defined(AFS_LINUX26_ENV) +#define UnlockPage(pp) unlock_page(pp) +#endif + extern struct vcache *afs_globalVp; extern afs_rwlock_t afs_xvcache; -extern struct dentry_operations *afs_dops; #if defined(AFS_LINUX24_ENV) extern struct inode_operations afs_file_iops; extern struct address_space_operations afs_file_aops; @@ -54,12 +56,8 @@ extern struct inode_operations afs_dir_iops; extern struct inode_operations afs_symlink_iops; -#ifdef NOTUSED -static int afs_linux_lseek(struct inode *ip, struct file *fp, off_t, int) {} -#endif - -static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count, - loff_t *offp) +static ssize_t +afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp) { ssize_t code; struct vcache *vcp = ITOAFS(fp->f_dentry->d_inode); @@ -68,9 +66,8 @@ static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count, AFS_GLOCK(); afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp, - ICL_TYPE_INT32, (int)*offp, - ICL_TYPE_INT32, count, - ICL_TYPE_INT32, 99999); + ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32, + 99999); /* get a validated vcache entry */ code = afs_InitReq(&treq, credp); @@ -80,16 +77,56 @@ static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count, if (code) code = -code; else { - osi_FlushPages(vcp, credp); /* ensure stale pages are gone */ - AFS_GUNLOCK(); - code = generic_file_read(fp, buf, count, offp); - AFS_GLOCK(); +#ifdef AFS_64BIT_CLIENT + if (*offp + count > afs_vmMappingEnd) { + uio_t tuio; + struct iovec iov; + afs_size_t oldOffset = *offp; + afs_int32 xfered = 0; + + if (*offp < afs_vmMappingEnd) { + /* special case of a buffer crossing the VM mapping end */ + afs_int32 tcount = afs_vmMappingEnd - *offp; + count -= tcount; + osi_FlushPages(vcp, credp); /* ensure stale pages are gone */ + AFS_GUNLOCK(); + code = generic_file_read(fp, buf, tcount, offp); + AFS_GLOCK(); + if (code != tcount) { + goto done; + } + xfered = tcount; + } + setup_uio(&tuio, &iov, buf + xfered, (afs_offs_t) * offp, count, + UIO_READ, AFS_UIOSYS); + code = afs_read(vcp, &tuio, credp, 0, 0, 0); + xfered += count - tuio.uio_resid; + if (code != 0) { + afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, + vcp, ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, -1, + ICL_TYPE_INT32, code); + code = xfered; + *offp += count - tuio.uio_resid; + } else { + code = xfered; + *offp += count; + } + done: + ; + } else { +#endif /* AFS_64BIT_CLIENT */ + osi_FlushPages(vcp, credp); /* ensure stale pages are gone */ + AFS_GUNLOCK(); + code = generic_file_read(fp, buf, count, offp); + AFS_GLOCK(); +#ifdef AFS_64BIT_CLIENT + } +#endif /* AFS_64BIT_CLIENT */ } afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp, - ICL_TYPE_INT32, (int)*offp, - ICL_TYPE_INT32, count, - ICL_TYPE_INT32, code); + ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32, + code); AFS_GUNLOCK(); crfree(credp); @@ -101,50 +138,111 @@ static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count, * also takes care of re-positioning the pointer if file is open in append * mode. Call fake open/close to ensure we do writes of core dumps. */ -static ssize_t afs_linux_write(struct file *fp, const char *buf, size_t count, - loff_t *offp) +static ssize_t +afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp) { ssize_t code = 0; int code2; struct vcache *vcp = ITOAFS(fp->f_dentry->d_inode); struct vrequest treq; cred_t *credp = crref(); + afs_offs_t toffs; AFS_GLOCK(); afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp, - ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count, - ICL_TYPE_INT32, (fp->f_flags & O_APPEND) ? 99998 : 99999); + ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32, + (fp->f_flags & O_APPEND) ? 99998 : 99999); /* get a validated vcache entry */ - code = (ssize_t)afs_InitReq(&treq, credp); + code = (ssize_t) afs_InitReq(&treq, credp); if (!code) - code = (ssize_t)afs_VerifyVCache(vcp, &treq); + code = (ssize_t) afs_VerifyVCache(vcp, &treq); ObtainWriteLock(&vcp->lock, 529); afs_FakeOpen(vcp); ReleaseWriteLock(&vcp->lock); - AFS_GUNLOCK(); if (code) code = -code; else { - code = generic_file_write(fp, buf, count, offp); +#ifdef AFS_64BIT_CLIENT + toffs = *offp; + if (fp->f_flags & O_APPEND) + toffs += vcp->m.Length; + if (toffs + count > afs_vmMappingEnd) { + uio_t tuio; + struct iovec iov; + afs_size_t oldOffset = *offp; + afs_int32 xfered = 0; + + if (toffs < afs_vmMappingEnd) { + /* special case of a buffer crossing the VM mapping end */ + afs_int32 tcount = afs_vmMappingEnd - *offp; + count -= tcount; + AFS_GUNLOCK(); + code = generic_file_write(fp, buf, tcount, offp); + AFS_GLOCK(); + if (code != tcount) { + goto done; + } + xfered = tcount; + toffs += tcount; + } + setup_uio(&tuio, &iov, buf + xfered, (afs_offs_t) toffs, count, + UIO_WRITE, AFS_UIOSYS); + code = afs_write(vcp, &tuio, fp->f_flags, credp, 0); + xfered += count - tuio.uio_resid; + if (code != 0) { + code = xfered; + *offp += count - tuio.uio_resid; + } else { + /* Purge dirty chunks of file if there are too many dirty chunks. + * Inside the write loop, we only do this at a chunk boundary. + * Clean up partial chunk if necessary at end of loop. + */ + if (AFS_CHUNKBASE(tuio.afsio_offset) != + AFS_CHUNKBASE(oldOffset)) { + ObtainWriteLock(&vcp->lock, 402); + code = afs_DoPartialWrite(vcp, &treq); + vcp->states |= CDirty; + ReleaseWriteLock(&vcp->lock); + } + code = xfered; + *offp += count; + toffs += count; + ObtainWriteLock(&vcp->lock, 400); + vcp->m.Date = osi_Time(); /* Set file date (for ranlib) */ + /* extend file */ + if (!(fp->f_flags & O_APPEND) && toffs > vcp->m.Length) { + vcp->m.Length = toffs; + } + ReleaseWriteLock(&vcp->lock); + } + done: + ; + } else { +#endif /* AFS_64BIT_CLIENT */ + AFS_GUNLOCK(); + code = generic_file_write(fp, buf, count, offp); + AFS_GLOCK(); +#ifdef AFS_64BIT_CLIENT + } +#endif /* AFS_64BIT_CLIENT */ } - AFS_GLOCK(); ObtainWriteLock(&vcp->lock, 530); - vcp->m.Date = osi_Time(); /* set modification time */ + vcp->m.Date = osi_Time(); /* set modification time */ afs_FakeClose(vcp, credp); - if (code>=0) + if (code >= 0) code2 = afs_DoPartialWrite(vcp, &treq); - if (code2 && code >=0) - code = (ssize_t) -code2; + if (code2 && code >= 0) + code = (ssize_t) - code2; ReleaseWriteLock(&vcp->lock); - + afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp, - ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count, - ICL_TYPE_INT32, code); + ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32, + code); AFS_GUNLOCK(); crfree(credp); @@ -155,10 +253,10 @@ static ssize_t afs_linux_write(struct file *fp, const char *buf, size_t count, * filldir instead of afs_readdir_move. Note that changes to vcache/dcache * handling and use of bulkstats will need to be reflected here as well. */ -static int afs_linux_readdir(struct file *fp, - void *dirbuf, filldir_t filldir) +static int +afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir) { - extern struct DirEntry * afs_dir_GetBlob(); + extern struct DirEntry *afs_dir_GetBlob(); struct vcache *avc = ITOAFS(FILE_INODE(fp)); struct vrequest treq; register struct dcache *tdc; @@ -168,45 +266,41 @@ static int afs_linux_readdir(struct file *fp, struct DirEntry *de; ino_t ino; int len; - int origOffset; + afs_size_t origOffset, tlen; cred_t *credp = crref(); struct afs_fakestat_state fakestat; AFS_GLOCK(); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif AFS_STATCNT(afs_readdir); code = afs_InitReq(&treq, credp); crfree(credp); - if (code) { - AFS_GUNLOCK(); - return -code; - } + if (code) + goto out1; afs_InitFakeStat(&fakestat); code = afs_EvalFakeStat(&avc, &fakestat, &treq); - if (code) { - afs_PutFakeStat(&fakestat); - AFS_GUNLOCK(); - return -code; - } + if (code) + goto out; /* update the cache entry */ -tagain: + tagain: code = afs_VerifyVCache(avc, &treq); - if (code) { - afs_PutFakeStat(&fakestat); - AFS_GUNLOCK(); - return -code; - } + if (code) + goto out; /* get a reference to the entire directory */ - tdc = afs_GetDCache(avc, 0, &treq, &origOffset, &len, 1); + tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1); + len = tlen; if (!tdc) { - afs_PutFakeStat(&fakestat); - AFS_GUNLOCK(); - return -ENOENT; + code = -ENOENT; + goto out; } ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); /* * Make sure that the data in the cache is current. There are two * cases we need to worry about: @@ -214,15 +308,17 @@ tagain: * 2. The cache data is no longer valid */ while ((avc->states & CStatd) - && (tdc->flags & DFFetching) + && (tdc->dflags & DFFetching) && hsame(avc->m.DataVersion, tdc->f.versionNo)) { - tdc->flags |= DFWaiting; + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); afs_osi_Sleep(&tdc->validPos); ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); } if (!(avc->states & CStatd) || !hsame(avc->m.DataVersion, tdc->f.versionNo)) { + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); afs_PutDCache(tdc); goto tagain; @@ -232,82 +328,96 @@ tagain: * takes an offset in units of blobs, rather than bytes. */ code = 0; - offset = (int)fp->f_pos; - while(1) { + offset = (int) fp->f_pos; + while (1) { dirpos = BlobScan(&tdc->f.inode, offset); if (!dirpos) break; - de = (struct DirEntry*)afs_dir_GetBlob(&tdc->f.inode, dirpos); + de = afs_dir_GetBlob(&tdc->f.inode, dirpos); if (!de) break; ino = (avc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode); - ino &= 0x7fffffff; /* Assumes 32 bit ino_t ..... */ - len = strlen(de->name); + ino &= 0x7fffffff; /* Assumes 32 bit ino_t ..... */ + if (de->name) + len = strlen(de->name); + else { + printf("afs_linux_readdir: afs_dir_GetBlob failed, null name (inode %x, dirpos %d)\n", + &tdc->f.inode, dirpos); + DRelease((struct buffer *) de, 0); + afs_PutDCache(tdc); + ReleaseReadLock(&avc->lock); + code = -ENOENT; + goto out; + } /* filldir returns -EINVAL when the buffer is full. */ -#if (defined(AFS_LINUX24_ENV) || defined(pgoff2loff)) && defined(DECLARE_FSTYPE) - { - unsigned int type=DT_UNKNOWN; - struct VenusFid afid; - struct vcache *tvc; - int vtype; - afid.Cell=avc->fid.Cell; - afid.Fid.Volume=avc->fid.Fid.Volume; - afid.Fid.Vnode=ntohl(de->fid.vnode); - afid.Fid.Unique=ntohl(de->fid.vunique); - if ((avc->states & CForeign) == 0 && - (ntohl(de->fid.vnode) & 1)) { - type=DT_DIR; - } else if ((tvc=afs_FindVCache(&afid,0,0,0,0))) { - if (tvc->mvstat) { - type=DT_DIR; - } else if (((tvc->states) & (CStatd|CTruth))) { - /* CTruth will be set if the object has - *ever* been statd */ - vtype=vType(tvc); - if (vtype == VDIR) - type=DT_DIR; - else if (vtype == VREG) - type=DT_REG; - /* Don't do this until we're sure it can't be a mtpt */ - /* else if (vtype == VLNK) - type=DT_LNK; */ - /* what other types does AFS support? */ - } - /* clean up from afs_FindVCache */ - afs_PutVCache(tvc, WRITE_LOCK); - } - code = (*filldir)(dirbuf, de->name, len, offset, ino, type); - } +#if defined(AFS_LINUX26_ENV) || ((defined(AFS_LINUX24_ENV) || defined(pgoff2loff)) && defined(DECLARE_FSTYPE)) + { + unsigned int type = DT_UNKNOWN; + struct VenusFid afid; + struct vcache *tvc; + int vtype; + afid.Cell = avc->fid.Cell; + afid.Fid.Volume = avc->fid.Fid.Volume; + afid.Fid.Vnode = ntohl(de->fid.vnode); + afid.Fid.Unique = ntohl(de->fid.vunique); + if ((avc->states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) { + type = DT_DIR; + } else if ((tvc = afs_FindVCache(&afid, 0, 0))) { + if (tvc->mvstat) { + type = DT_DIR; + } else if (((tvc->states) & (CStatd | CTruth))) { + /* CTruth will be set if the object has + *ever* been statd */ + vtype = vType(tvc); + if (vtype == VDIR) + type = DT_DIR; + else if (vtype == VREG) + type = DT_REG; + /* Don't do this until we're sure it can't be a mtpt */ + /* else if (vtype == VLNK) + * type=DT_LNK; */ + /* what other types does AFS support? */ + } + /* clean up from afs_FindVCache */ + afs_PutVCache(tvc); + } + code = (*filldir) (dirbuf, de->name, len, offset, ino, type); + } #else - code = (*filldir)(dirbuf, de->name, len, offset, ino); + code = (*filldir) (dirbuf, de->name, len, offset, ino); #endif - DRelease(de, 0); + DRelease((struct buffer *)de, 0); if (code) break; - offset = dirpos + 1 + ((len+16)>>5); + offset = dirpos + 1 + ((len + 16) >> 5); } /* If filldir didn't fill in the last one this is still pointing to that * last attempt. */ - fp->f_pos = (loff_t)offset; + fp->f_pos = (loff_t) offset; + ReleaseReadLock(&tdc->lock); afs_PutDCache(tdc); ReleaseReadLock(&avc->lock); + code = 0; + +out: afs_PutFakeStat(&fakestat); +out1: +#if defined(AFS_LINUX26_ENV) + unlock_kernel(); +#endif AFS_GUNLOCK(); - return 0; + return code; } -#ifdef NOTUSED -int afs_linux_select(struct inode *ip, struct file *fp, int, select_table *); -#endif /* in afs_pioctl.c */ -extern int afs_xioctl(struct inode *ip, struct file *fp, - unsigned int com, unsigned long arg); +extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com, + unsigned long arg); /* We need to detect unmap's after close. To do that, we need our own @@ -320,10 +430,12 @@ static int afs_private_mmap_ops_inited = 0; static struct vm_operations_struct afs_shared_mmap_ops; static int afs_shared_mmap_ops_inited = 0; -void afs_linux_vma_close(struct vm_area_struct *vmap) +void +afs_linux_vma_close(struct vm_area_struct *vmap) { struct vcache *vcp; cred_t *credp; + int need_unlock = 0; if (!vmap->vm_file) return; @@ -333,36 +445,49 @@ void afs_linux_vma_close(struct vm_area_struct *vmap) return; AFS_GLOCK(); - afs_Trace4(afs_iclSetp, CM_TRACE_VM_CLOSE, - ICL_TYPE_POINTER, vcp, - ICL_TYPE_INT32, vcp->mapcnt, - ICL_TYPE_INT32, vcp->opens, + afs_Trace4(afs_iclSetp, CM_TRACE_VM_CLOSE, ICL_TYPE_POINTER, vcp, + ICL_TYPE_INT32, vcp->mapcnt, ICL_TYPE_INT32, vcp->opens, ICL_TYPE_INT32, vcp->execsOrWriters); - ObtainWriteLock(&vcp->lock, 532); + if ((&vcp->lock)->excl_locked == 0 || (&vcp->lock)->pid_writer == MyPidxx) { + ObtainWriteLock(&vcp->lock, 532); + need_unlock = 1; + } else + printk("AFS_VMA_CLOSE(%d): Skipping Already locked vcp=%p vmap=%p\n", + MyPidxx, &vcp, &vmap); if (vcp->mapcnt) { vcp->mapcnt--; - ReleaseWriteLock(&vcp->lock); + if (need_unlock) + ReleaseWriteLock(&vcp->lock); if (!vcp->mapcnt) { - credp = crref(); - (void) afs_close(vcp, vmap->vm_file->f_flags, credp); - /* only decrement the execsOrWriters flag if this is not a writable - * file. */ - if (! (vmap->vm_file->f_flags & (FWRITE | FTRUNC))) + if (need_unlock && vcp->execsOrWriters < 2) { + credp = crref(); + (void)afs_close(vcp, vmap->vm_file->f_flags, credp); + /* only decrement the execsOrWriters flag if this is not a + * writable file. */ + if (!(vmap->vm_file->f_flags & (FWRITE | FTRUNC))) + vcp->execsOrWriters--; + vcp->states &= ~CMAPPED; + crfree(credp); + } else if ((vmap->vm_file->f_flags & (FWRITE | FTRUNC))) vcp->execsOrWriters--; - - vcp->states &= ~CMAPPED; - crfree(credp); + /* If we did not have the lock */ + if (!need_unlock) { + vcp->mapcnt++; + if (!vcp->execsOrWriters) + vcp->execsOrWriters = 1; + } } - } - else { - ReleaseWriteLock(&vcp->lock); + } else { + if (need_unlock) + ReleaseWriteLock(&vcp->lock); } - unlock_exit: + unlock_exit: AFS_GUNLOCK(); } -static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap) +static int +afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap) { struct vcache *vcp = ITOAFS(FILE_INODE(fp)); cred_t *credp = crref(); @@ -372,13 +497,13 @@ static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap) AFS_GLOCK(); #if defined(AFS_LINUX24_ENV) afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp, - ICL_TYPE_POINTER, vmap->vm_start, - ICL_TYPE_INT32, vmap->vm_end - vmap->vm_start); + ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32, + vmap->vm_end - vmap->vm_start); #else afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp, - ICL_TYPE_POINTER, vmap->vm_start, - ICL_TYPE_INT32, vmap->vm_end - vmap->vm_start, - ICL_TYPE_INT32, vmap->vm_offset); + ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32, + vmap->vm_end - vmap->vm_start, ICL_TYPE_INT32, + vmap->vm_offset); #endif /* get a validated vcache entry */ @@ -398,7 +523,7 @@ static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap) } if (code == 0) { - ObtainWriteLock(&vcp->lock,531); + ObtainWriteLock(&vcp->lock, 531); /* Set out vma ops so we catch the close. The following test should be * the same as used in generic_file_mmap. */ @@ -409,8 +534,7 @@ static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap) afs_shared_mmap_ops.close = afs_linux_vma_close; } vmap->vm_ops = &afs_shared_mmap_ops; - } - else { + } else { if (!afs_private_mmap_ops_inited) { afs_private_mmap_ops_inited = 1; afs_private_mmap_ops = *vmap->vm_ops; @@ -418,8 +542,8 @@ static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap) } vmap->vm_ops = &afs_private_mmap_ops; } - - + + /* Add an open reference on the first mapping. */ if (vcp->mapcnt == 0) { vcp->execsOrWriters++; @@ -435,7 +559,8 @@ static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap) return code; } -int afs_linux_open(struct inode *ip, struct file *fp) +int +afs_linux_open(struct inode *ip, struct file *fp) { int code; cred_t *credp = crref(); @@ -444,7 +569,7 @@ int afs_linux_open(struct inode *ip, struct file *fp) #ifdef AFS_LINUX24_ENV lock_kernel(); #endif - code = afs_open((struct vcache**)&ip, fp->f_flags, credp); + code = afs_open((struct vcache **)&ip, fp->f_flags, credp); #ifdef AFS_LINUX24_ENV unlock_kernel(); #endif @@ -461,7 +586,8 @@ int afs_linux_open(struct inode *ip, struct file *fp) * fput. See afs_linux_flush for notes on interactions between release and * flush. */ -static int afs_linux_release(struct inode *ip, struct file *fp) +static int +afs_linux_release(struct inode *ip, struct file *fp) { int code = 0; cred_t *credp = crref(); @@ -472,9 +598,8 @@ static int afs_linux_release(struct inode *ip, struct file *fp) lock_kernel(); #endif if (vcp->flushcnt) { - vcp->flushcnt--; /* protected by AFS global lock. */ - } - else { + vcp->flushcnt--; /* protected by AFS global lock. */ + } else { code = afs_close(vcp, fp->f_flags, credp); } #ifdef AFS_LINUX24_ENV @@ -487,9 +612,11 @@ static int afs_linux_release(struct inode *ip, struct file *fp) } #if defined(AFS_LINUX24_ENV) -static int afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync) +static int +afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync) #else -static int afs_linux_fsync(struct file *fp, struct dentry *dp) +static int +afs_linux_fsync(struct file *fp, struct dentry *dp) #endif { int code; @@ -507,21 +634,12 @@ static int afs_linux_fsync(struct file *fp, struct dentry *dp) AFS_GUNLOCK(); crfree(credp); return -code; - -} -#ifdef NOTUSED -/* No support for async i/o */ -int afs_linux_fasync(struct inode *ip, struct file *fp, int); - -/* I don't think it will, at least not as can be detected here. */ -int afs_linux_check_media_change(kdev_t dev); +} -/* Revalidate media and file system. */ -int afs_linux_file_revalidate(kdev_t dev); -#endif /* NOTUSED */ -static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp) +static int +afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp) { int code = 0; struct vcache *vcp = ITOAFS(FILE_INODE(fp)); @@ -531,9 +649,9 @@ static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp) #else struct flock flock; #endif - + /* Convert to a lock format afs_lockctl understands. */ - memset((char*)&flock, 0, sizeof(flock)); + memset((char *)&flock, 0, sizeof(flock)); flock.l_type = flp->fl_type; flock.l_pid = flp->fl_pid; flock.l_whence = 0; @@ -562,7 +680,7 @@ static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp) crfree(credp); return -code; - + } /* afs_linux_flush @@ -577,7 +695,8 @@ static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp) * on the just flushed file is wasteful, since the background daemon will * execute the code that finally decides there is nothing to do. */ -int afs_linux_flush(struct file *fp) +int +afs_linux_flush(struct file *fp) { struct vcache *vcp = ITOAFS(FILE_INODE(fp)); int code = 0; @@ -595,81 +714,50 @@ int afs_linux_flush(struct file *fp) AFS_GLOCK(); code = afs_close(vcp, fp->f_flags, credp); - vcp->flushcnt++; /* protected by AFS global lock. */ + vcp->flushcnt++; /* protected by AFS global lock. */ AFS_GUNLOCK(); crfree(credp); return -code; } +#if !defined(AFS_LINUX24_ENV) /* Not allowed to directly read a directory. */ -ssize_t afs_linux_dir_read(struct file *fp, char *buf, size_t count, loff_t *ppos) +ssize_t +afs_linux_dir_read(struct file * fp, char *buf, size_t count, loff_t * ppos) { return -EISDIR; } +#endif -#if defined(AFS_LINUX24_ENV) struct file_operations afs_dir_fops = { - read: generic_read_dir, - readdir: afs_linux_readdir, - ioctl: afs_xioctl, - open: afs_linux_open, - release: afs_linux_release, -}; +#if !defined(AFS_LINUX24_ENV) + .read = afs_linux_dir_read, + .lock = afs_linux_lock, + .fsync = afs_linux_fsync, #else -struct file_operations afs_dir_fops = { - NULL, /* afs_linux_lseek */ - afs_linux_dir_read, - NULL, /* afs_linux_write */ - afs_linux_readdir, - NULL, /* afs_linux_select */ - afs_xioctl, /* close enough to use the ported AFS one */ - NULL, /* afs_linux_mmap */ - afs_linux_open, - NULL, /* afs_linux_flush */ - afs_linux_release, - afs_linux_fsync, - NULL, /* afs_linux_fasync */ - NULL, /* afs_linux_check_media_change */ - NULL, /* afs_linux_file_revalidate */ - afs_linux_lock, -}; + .read = generic_read_dir, #endif - -#if defined(AFS_LINUX24_ENV) -struct file_operations afs_file_fops = { - read: afs_linux_read, - write: afs_linux_write, - ioctl: afs_xioctl, - mmap: afs_linux_mmap, - open: afs_linux_open, - flush: afs_linux_flush, - release: afs_linux_release, - fsync: afs_linux_fsync, - lock: afs_linux_lock, + .readdir = afs_linux_readdir, + .ioctl = afs_xioctl, + .open = afs_linux_open, + .release = afs_linux_release, }; -#else + struct file_operations afs_file_fops = { - NULL, /* afs_linux_lseek */ - afs_linux_read, - afs_linux_write, - NULL, /* afs_linux_readdir */ - NULL, /* afs_linux_select */ - afs_xioctl, /* close enough to use the ported AFS one */ - afs_linux_mmap, - afs_linux_open, - afs_linux_flush, - afs_linux_release, - afs_linux_fsync, - NULL, /* afs_linux_fasync */ - NULL, /* afs_linux_check_media_change */ - NULL, /* afs_linux_file_revalidate */ - afs_linux_lock, + .read = afs_linux_read, + .write = afs_linux_write, + .ioctl = afs_xioctl, + .mmap = afs_linux_mmap, + .open = afs_linux_open, + .flush = afs_linux_flush, + .release = afs_linux_release, + .fsync = afs_linux_fsync, + .lock = afs_linux_lock, }; -#endif - + /********************************************************************** * AFS Linux dentry operations @@ -678,7 +766,8 @@ struct file_operations afs_file_fops = { /* afs_linux_revalidate * Ensure vcache is stat'd before use. Return 0 if entry is valid. */ -static int afs_linux_revalidate(struct dentry *dp) +static int +afs_linux_revalidate(struct dentry *dp) { int code; cred_t *credp; @@ -688,21 +777,20 @@ static int afs_linux_revalidate(struct dentry *dp) AFS_GLOCK(); - if (afs_fakestat_enable && vcp->mvstat == 1 && vcp->mvid && - (vcp->states & CMValid) && (vcp->states & CStatd)) { + if (afs_fakestat_enable && vcp->mvstat == 1 && vcp->mvid + && (vcp->states & CMValid) && (vcp->states & CStatd)) { ObtainSharedLock(&afs_xvcache, 680); - rootvp = afs_FindVCache(vcp->mvid, 0, 0, 0, 0); + rootvp = afs_FindVCache(vcp->mvid, 0, 0); ReleaseSharedLock(&afs_xvcache); } - #ifdef AFS_LINUX24_ENV lock_kernel(); #endif /* Make this a fast path (no crref), since it's called so often. */ if (vcp->states & CStatd) { - if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */ - check_bad_parent(dp); /* check and correct mvid */ + if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */ + check_bad_parent(dp); /* check and correct mvid */ if (rootvp) vcache2fakeinode(rootvp, vcp); else @@ -710,7 +798,8 @@ static int afs_linux_revalidate(struct dentry *dp) #ifdef AFS_LINUX24_ENV unlock_kernel(); #endif - if (rootvp) afs_PutVCache(rootvp); + if (rootvp) + afs_PutVCache(rootvp); AFS_GUNLOCK(); return 0; } @@ -726,9 +815,19 @@ static int afs_linux_revalidate(struct dentry *dp) AFS_GUNLOCK(); crfree(credp); - return -code ; + return -code; } +#if defined(AFS_LINUX26_ENV) +static int +afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) +{ + int err = afs_linux_revalidate(dentry); + if (!err) + generic_fillattr(dentry->d_inode, stat); + return err; +} +#endif /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate. * In kernels 2.2.10 and above, we are passed an additional flags var which @@ -738,9 +837,11 @@ static int afs_linux_revalidate(struct dentry *dp) * later on, we shouldn't have to do it until later. Perhaps in the future.. */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10) -static int afs_linux_dentry_revalidate(struct dentry *dp, int flags) +static int +afs_linux_dentry_revalidate(struct dentry *dp, int flags) #else -static int afs_linux_dentry_revalidate(struct dentry *dp) +static int +afs_linux_dentry_revalidate(struct dentry *dp) #endif { char *name; @@ -753,108 +854,79 @@ static int afs_linux_dentry_revalidate(struct dentry *dp) struct vcache *parentvcp = ITOAFS(dp->d_parent->d_inode); AFS_GLOCK(); + lock_kernel(); sysState.allocked = 0; /* If it's a negative dentry, then there's nothing to do. */ if (!vcp || !parentvcp) - goto done; + goto done; /* If it is the AFS root, then there's no chance it needs - revalidating */ + * revalidating */ if (vcp == afs_globalVp) { bad_dentry = 0; goto done; } - if (code = afs_InitReq(&treq, credp)) - goto done; + if ((code = afs_InitReq(&treq, credp))) + goto done; Check_AtSys(parentvcp, dp->d_name.name, &sysState, &treq); name = sysState.name; /* First try looking up the DNLC */ - if (lookupvcp = osi_dnlc_lookup(parentvcp, name, WRITE_LOCK)) { - /* Verify that the dentry does not point to an old inode */ - if (vcp != lookupvcp) - goto done; - /* Check and correct mvid */ - if (*name != '/' && vcp->mvstat == 2) - check_bad_parent(dp); + if ((lookupvcp = osi_dnlc_lookup(parentvcp, name, WRITE_LOCK))) { + /* Verify that the dentry does not point to an old inode */ + if (vcp != lookupvcp) + goto done; + /* Check and correct mvid */ + if (*name != '/' && vcp->mvstat == 2) + check_bad_parent(dp); vcache2inode(vcp); - bad_dentry = 0; - goto done; + bad_dentry = 0; + goto done; } - /* A DNLC lookup failure cannot be trusted. Try a real lookup */ - code = afs_lookup(parentvcp, name, &lookupvcp, credp); + /* A DNLC lookup failure cannot be trusted. Try a real lookup. + Make sure to try the real name and not the @sys expansion; + afs_lookup will expand @sys itself. */ + + code = afs_lookup(parentvcp, dp->d_name.name, &lookupvcp, credp); /* Verify that the dentry does not point to an old inode */ if (vcp != lookupvcp) - goto done; + goto done; bad_dentry = 0; -done: + done: /* Clean up */ if (lookupvcp) - afs_PutVCache(lookupvcp, WRITE_LOCK); + afs_PutVCache(lookupvcp); if (sysState.allocked) - osi_FreeLargeSpace(name); + osi_FreeLargeSpace(name); AFS_GUNLOCK(); crfree(credp); if (bad_dentry) { - shrink_dcache_parent(dp); - d_drop(dp); + shrink_dcache_parent(dp); + d_drop(dp); } + unlock_kernel(); return !bad_dentry; } -#ifdef notdef -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10) -static int afs_linux_dentry_revalidate(struct dentry *dp, int flags) -#else -static int afs_linux_dentry_revalidate(struct dentry *dp) -#endif -{ - int code; - cred_t *credp; - struct vrequest treq; - struct inode *ip = AFSTOI(dp->d_inode); - - unsigned long timeout = 3*HZ; /* 3 seconds */ - - if (!ip) - printk("negative dentry: %s\n", dp->d_name.name); - - if (!(flags & LOOKUP_CONTINUE)) { - long diff = CURRENT_TIME - dp->d_parent->d_inode->i_mtime; - - if (diff < 15*60) - timeout = 0; - } - - if (time_after(jiffies, dp->d_time + timeout)) - goto out_bad; - - out_valid: - return 1; - - out_bad: - return 0; -} -#endif - +#if !defined(AFS_LINUX26_ENV) /* afs_dentry_iput */ -static void afs_dentry_iput(struct dentry *dp, struct inode *ip) +static void +afs_dentry_iput(struct dentry *dp, struct inode *ip) { if (ICL_SETACTIVE(afs_iclSetp)) { AFS_GLOCK(); - afs_Trace3(afs_iclSetp, CM_TRACE_DENTRYIPUT, - ICL_TYPE_POINTER, ip, + afs_Trace3(afs_iclSetp, CM_TRACE_DENTRYIPUT, ICL_TYPE_POINTER, ip, ICL_TYPE_STRING, dp->d_parent->d_name.name, ICL_TYPE_STRING, dp->d_name.name); AFS_GUNLOCK(); @@ -862,41 +934,32 @@ static void afs_dentry_iput(struct dentry *dp, struct inode *ip) osi_iput(ip); } +#endif -static int afs_dentry_delete(struct dentry *dp) +static int +afs_dentry_delete(struct dentry *dp) { if (ICL_SETACTIVE(afs_iclSetp)) { AFS_GLOCK(); - afs_Trace3(afs_iclSetp, CM_TRACE_DENTRYDELETE, ICL_TYPE_POINTER, + afs_Trace3(afs_iclSetp, CM_TRACE_DENTRYDELETE, ICL_TYPE_POINTER, dp->d_inode, ICL_TYPE_STRING, dp->d_parent->d_name.name, ICL_TYPE_STRING, dp->d_name.name); AFS_GUNLOCK(); } if (dp->d_inode && (ITOAFS(dp->d_inode)->states & CUnlinked)) - return 1; /* bad inode? */ + return 1; /* bad inode? */ return 0; } -#if defined(AFS_LINUX24_ENV) -struct dentry_operations afs_dentry_operations = { - d_revalidate: afs_linux_dentry_revalidate, - d_iput: afs_dentry_iput, - d_delete: afs_dentry_delete, -}; -struct dentry_operations *afs_dops = &afs_dentry_operations; -#else struct dentry_operations afs_dentry_operations = { - afs_linux_dentry_revalidate, /* d_validate(struct dentry *) */ - NULL, /* d_hash */ - NULL, /* d_compare */ - afs_dentry_delete, /* d_delete(struct dentry *) */ - NULL, /* d_release(struct dentry *) */ - afs_dentry_iput /* d_iput(struct dentry *, struct inode *) */ -}; -struct dentry_operations *afs_dops = &afs_dentry_operations; + .d_revalidate = afs_linux_dentry_revalidate, + .d_delete = afs_dentry_delete, +#if !defined(AFS_LINUX26_ENV) + .d_iput = afs_dentry_iput, #endif +}; /********************************************************************** * AFS Linux inode operations @@ -910,7 +973,8 @@ struct dentry_operations *afs_dops = &afs_dentry_operations; * * name is in kernel space at this point. */ -int afs_linux_create(struct inode *dip, struct dentry *dp, int mode) +int +afs_linux_create(struct inode *dip, struct dentry *dp, int mode) { int code; cred_t *credp = crref(); @@ -923,26 +987,30 @@ int afs_linux_create(struct inode *dip, struct dentry *dp, int mode) vattr.va_mode = mode; AFS_GLOCK(); - code = afs_create(ITOAFS(dip), name, &vattr, NONEXCL, mode, - (struct vcache**)&ip, credp); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif + code = + afs_create(ITOAFS(dip), name, &vattr, NONEXCL, mode, + (struct vcache **)&ip, credp); if (!code) { vattr2inode(ip, &vattr); /* Reset ops if symlink or directory. */ #if defined(AFS_LINUX24_ENV) - if (S_ISREG(ip->i_mode)) { - ip->i_op = &afs_file_iops; - ip->i_fop = &afs_file_fops; - ip->i_data.a_ops = &afs_file_aops; - } else if (S_ISDIR(ip->i_mode)) { - ip->i_op = &afs_dir_iops; - ip->i_fop = &afs_dir_fops; - } else if (S_ISLNK(ip->i_mode)) { - ip->i_op = &afs_symlink_iops; - ip->i_data.a_ops = &afs_symlink_aops; - ip->i_mapping = &ip->i_data; - } else - printk("afs_linux_create: FIXME\n"); + if (S_ISREG(ip->i_mode)) { + ip->i_op = &afs_file_iops; + ip->i_fop = &afs_file_fops; + ip->i_data.a_ops = &afs_file_aops; + } else if (S_ISDIR(ip->i_mode)) { + ip->i_op = &afs_dir_iops; + ip->i_fop = &afs_dir_fops; + } else if (S_ISLNK(ip->i_mode)) { + ip->i_op = &afs_symlink_iops; + ip->i_data.a_ops = &afs_symlink_aops; + ip->i_mapping = &ip->i_data; + } else + printk("afs_linux_create: FIXME\n"); #else if (S_ISDIR(ip->i_mode)) ip->i_op = &afs_dir_iops; @@ -950,11 +1018,14 @@ int afs_linux_create(struct inode *dip, struct dentry *dp, int mode) ip->i_op = &afs_symlink_iops; #endif - dp->d_op = afs_dops; + dp->d_op = &afs_dentry_operations; dp->d_time = jiffies; d_instantiate(dp, ip); } +#if defined(AFS_LINUX26_ENV) + unlock_kernel(); +#endif AFS_GUNLOCK(); crfree(credp); return -code; @@ -962,46 +1033,57 @@ int afs_linux_create(struct inode *dip, struct dentry *dp, int mode) /* afs_linux_lookup */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10) -struct dentry *afs_linux_lookup(struct inode *dip, struct dentry *dp) +struct dentry * +afs_linux_lookup(struct inode *dip, struct dentry *dp) #else -int afs_linux_lookup(struct inode *dip, struct dentry *dp) +int +afs_linux_lookup(struct inode *dip, struct dentry *dp) #endif { int code = 0; cred_t *credp = crref(); - struct vcache *vcp=NULL; + struct vcache *vcp = NULL; const char *comp = dp->d_name.name; + AFS_GLOCK(); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif code = afs_lookup(ITOAFS(dip), comp, &vcp, credp); - + if (vcp) { struct inode *ip = AFSTOI(vcp); /* Reset ops if symlink or directory. */ #if defined(AFS_LINUX24_ENV) - if (S_ISREG(ip->i_mode)) { - ip->i_op = &afs_file_iops; - ip->i_fop = &afs_file_fops; - ip->i_data.a_ops = &afs_file_aops; - } else if (S_ISDIR(ip->i_mode)) { - ip->i_op = &afs_dir_iops; - ip->i_fop = &afs_dir_fops; - } else if (S_ISLNK(ip->i_mode)) { - ip->i_op = &afs_symlink_iops; - ip->i_data.a_ops = &afs_symlink_aops; - ip->i_mapping = &ip->i_data; + if (S_ISREG(ip->i_mode)) { + ip->i_op = &afs_file_iops; + ip->i_fop = &afs_file_fops; + ip->i_data.a_ops = &afs_file_aops; + } else if (S_ISDIR(ip->i_mode)) { + ip->i_op = &afs_dir_iops; + ip->i_fop = &afs_dir_fops; + } else if (S_ISLNK(ip->i_mode)) { + ip->i_op = &afs_symlink_iops; + ip->i_data.a_ops = &afs_symlink_aops; + ip->i_mapping = &ip->i_data; } else - printk("afs_linux_lookup: ip->i_mode 0x%x dp->d_name.name %s code %d\n", ip->i_mode, dp->d_name.name, code); + printk + ("afs_linux_lookup: ip->i_mode 0x%x dp->d_name.name %s code %d\n", + ip->i_mode, dp->d_name.name, code); #else if (S_ISDIR(ip->i_mode)) ip->i_op = &afs_dir_iops; else if (S_ISLNK(ip->i_mode)) ip->i_op = &afs_symlink_iops; #endif - } + } dp->d_time = jiffies; - dp->d_op = afs_dops; + dp->d_op = &afs_dentry_operations; d_add(dp, AFSTOI(vcp)); +#if defined(AFS_LINUX26_ENV) + unlock_kernel(); +#endif AFS_GUNLOCK(); crfree(credp); @@ -1020,8 +1102,8 @@ int afs_linux_lookup(struct inode *dip, struct dentry *dp) #endif } -int afs_linux_link(struct dentry *olddp, struct inode *dip, - struct dentry *newdp) +int +afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp) { int code; cred_t *credp = crref(); @@ -1041,24 +1123,31 @@ int afs_linux_link(struct dentry *olddp, struct inode *dip, return -code; } -int afs_linux_unlink(struct inode *dip, struct dentry *dp) +int +afs_linux_unlink(struct inode *dip, struct dentry *dp) { int code; cred_t *credp = crref(); const char *name = dp->d_name.name; AFS_GLOCK(); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif code = afs_remove(ITOAFS(dip), name, credp); - AFS_GUNLOCK(); if (!code) d_drop(dp); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif + AFS_GUNLOCK(); crfree(credp); return -code; } -int afs_linux_symlink(struct inode *dip, struct dentry *dp, - const char *target) +int +afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target) { int code; cred_t *credp = crref(); @@ -1078,7 +1167,8 @@ int afs_linux_symlink(struct inode *dip, struct dentry *dp, return -code; } -int afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode) +int +afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode) { int code; cred_t *credp = crref(); @@ -1087,6 +1177,9 @@ int afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode) const char *name = dp->d_name.name; AFS_GLOCK(); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif VATTR_NULL(&vattr); vattr.va_mask = ATTR_MODE; vattr.va_mode = mode; @@ -1097,23 +1190,30 @@ int afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode) #if defined(AFS_LINUX24_ENV) tvcp->v.v_fop = &afs_dir_fops; #endif - dp->d_op = afs_dops; + dp->d_op = &afs_dentry_operations; dp->d_time = jiffies; d_instantiate(dp, AFSTOI(tvcp)); } +#if defined(AFS_LINUX26_ENV) + unlock_kernel(); +#endif AFS_GUNLOCK(); crfree(credp); return -code; } -int afs_linux_rmdir(struct inode *dip, struct dentry *dp) +int +afs_linux_rmdir(struct inode *dip, struct dentry *dp) { int code; cred_t *credp = crref(); const char *name = dp->d_name.name; AFS_GLOCK(); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif code = afs_rmdir(ITOAFS(dip), name, credp); /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall @@ -1123,11 +1223,14 @@ int afs_linux_rmdir(struct inode *dip, struct dentry *dp) if (code == EEXIST) { code = ENOTEMPTY; } - + if (!code) { d_drop(dp); } +#if defined(AFS_LINUX26_ENV) + unlock_kernel(); +#endif AFS_GUNLOCK(); crfree(credp); return -code; @@ -1135,36 +1238,48 @@ int afs_linux_rmdir(struct inode *dip, struct dentry *dp) -int afs_linux_rename(struct inode *oldip, struct dentry *olddp, - struct inode *newip, struct dentry *newdp) +int +afs_linux_rename(struct inode *oldip, struct dentry *olddp, + struct inode *newip, struct dentry *newdp) { int code; cred_t *credp = crref(); const char *oldname = olddp->d_name.name; const char *newname = newdp->d_name.name; + AFS_GLOCK(); +#if defined(AFS_LINUX26_ENV) + lock_kernel(); +#endif /* Remove old and new entries from name hash. New one will change below. * While it's optimal to catch failures and re-insert newdp into hash, * it's also error prone and in that case we're already dealing with error * cases. Let another lookup put things right, if need be. */ - if (!list_empty(&olddp->d_hash)) { +#if defined(AFS_LINUX26_ENV) + if (!d_unhashed(olddp)) d_drop(olddp); - } - if (!list_empty(&newdp->d_hash)) { + if (!d_unhashed(newdp)) d_drop(newdp); - } - AFS_GLOCK(); - code = afs_rename(ITOAFS(oldip), oldname, ITOAFS(newip), - newname, credp); - AFS_GUNLOCK(); +#else + if (!list_empty(&olddp->d_hash)) + d_drop(olddp); + if (!list_empty(&newdp->d_hash)) + d_drop(newdp); +#endif + code = afs_rename(ITOAFS(oldip), oldname, ITOAFS(newip), newname, credp); if (!code) { - /* update time so it doesn't expire immediately */ + /* update time so it doesn't expire immediately */ newdp->d_time = jiffies; d_move(olddp, newdp); } +#if defined(AFS_LINUX26_ENV) + unlock_kernel(); +#endif + AFS_GUNLOCK(); + crfree(credp); return -code; } @@ -1174,15 +1289,15 @@ int afs_linux_rename(struct inode *oldip, struct dentry *olddp, * Internal readlink which can return link contents to user or kernel space. * Note that the buffer is NOT supposed to be null-terminated. */ -static int afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, - uio_seg_t seg) +static int +afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg) { int code; cred_t *credp = crref(); uio_t tuio; struct iovec iov; - setup_uio(&tuio, &iov, target, 0, maxlen, UIO_READ, seg); + setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg); code = afs_readlink(ITOAFS(ip), &tuio, credp); crfree(credp); @@ -1196,7 +1311,8 @@ static int afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, /* afs_linux_readlink * Fill target (which is in user space) with contents of symlink. */ -int afs_linux_readlink(struct dentry *dp, char *target, int maxlen) +int +afs_linux_readlink(struct dentry *dp, char *target, int maxlen) { int code; struct inode *ip = dp->d_inode; @@ -1211,16 +1327,17 @@ int afs_linux_readlink(struct dentry *dp, char *target, int maxlen) /* afs_linux_follow_link * a file system dependent link following routine. */ -struct dentry * afs_linux_follow_link(struct dentry *dp, - struct dentry *basep, - unsigned int follow) +struct dentry * +afs_linux_follow_link(struct dentry *dp, struct dentry *basep, + unsigned int follow) { int code = 0; char *name; struct dentry *res; + AFS_GLOCK(); - name = osi_Alloc(PATH_MAX+1); + name = osi_Alloc(PATH_MAX + 1); if (!name) { AFS_GUNLOCK(); dput(basep); @@ -1230,17 +1347,16 @@ struct dentry * afs_linux_follow_link(struct dentry *dp, code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS); AFS_GUNLOCK(); - if (code<0) { + if (code < 0) { dput(basep); res = ERR_PTR(code); - } - else { + } else { name[code] = '\0'; res = lookup_dentry(name, basep, follow); } AFS_GLOCK(); - osi_Free(name, PATH_MAX+1); + osi_Free(name, PATH_MAX + 1); AFS_GUNLOCK(); return res; } @@ -1249,29 +1365,26 @@ struct dentry * afs_linux_follow_link(struct dentry *dp, /* afs_linux_readpage * all reads come through here. A strategy-like read call. */ -int afs_linux_readpage(struct file *fp, struct page *pp) +int +afs_linux_readpage(struct file *fp, struct page *pp) { int code; cred_t *credp = crref(); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) char *address; - loff_t offset = pp->index << PAGE_CACHE_SHIFT; + afs_offs_t offset = pp->index << PAGE_CACHE_SHIFT; #else ulong address = afs_linux_page_address(pp); - loff_t offset = pageoff(pp); + afs_offs_t offset = pageoff(pp); #endif uio_t tuio; struct iovec iovec; struct inode *ip = FILE_INODE(fp); int cnt = atomic_read(&pp->count); + struct vcache *avc = ITOAFS(ip); AFS_GLOCK(); - afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, - ICL_TYPE_POINTER, ip, - ICL_TYPE_POINTER, pp, - ICL_TYPE_INT32, cnt, - ICL_TYPE_INT32, 99999); /* not a possible code value */ - + afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip, ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32, 99999); /* not a possible code value */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) address = kmap(pp); ClearPageError(pp); @@ -1279,20 +1392,20 @@ int afs_linux_readpage(struct file *fp, struct page *pp) lock_kernel(); #else atomic_add(1, &pp->count); - set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */ + set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */ clear_bit(PG_error, &pp->flags); #endif - setup_uio(&tuio, &iovec, (char*)address, offset, PAGESIZE, - UIO_READ, AFS_UIOSYS); - code = afs_rdwr(ITOAFS(ip), &tuio, UIO_READ, 0, credp); + setup_uio(&tuio, &iovec, (char *)address, offset, PAGESIZE, UIO_READ, + AFS_UIOSYS); + code = afs_rdwr(avc, &tuio, UIO_READ, 0, credp); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) unlock_kernel(); #endif if (!code) { - if (tuio.uio_resid) /* zero remainder of page */ - memset((void*)(address+(PAGESIZE-tuio.uio_resid)), 0, + if (tuio.uio_resid) /* zero remainder of page */ + memset((void *)(address + (PAGESIZE - tuio.uio_resid)), 0, tuio.uio_resid); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) flush_dcache_page(pp); @@ -1301,7 +1414,6 @@ int afs_linux_readpage(struct file *fp, struct page *pp) set_bit(PG_uptodate, &pp->flags); #endif } - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) kunmap(pp); UnlockPage(pp); @@ -1311,37 +1423,52 @@ int afs_linux_readpage(struct file *fp, struct page *pp) free_page(address); #endif + if (!code && AFS_CHUNKOFFSET(offset) == 0) { + struct dcache *tdc; + struct vrequest treq; + + code = afs_InitReq(&treq, credp); + if (!code && !NBObtainWriteLock(&avc->lock, 534)) { + tdc = afs_FindDCache(avc, offset); + if (tdc) { + if (!(tdc->mflags & DFNextStarted)) + afs_PrefetchChunk(avc, tdc, credp, &treq); + afs_PutDCache(tdc); + } + ReleaseWriteLock(&avc->lock); + } + } + crfree(credp); - afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, - ICL_TYPE_POINTER, ip, - ICL_TYPE_POINTER, pp, - ICL_TYPE_INT32, cnt, - ICL_TYPE_INT32, code); + afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip, + ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32, + code); AFS_GUNLOCK(); return -code; } #if defined(AFS_LINUX24_ENV) -int afs_linux_writepage(struct page *pp) +int +afs_linux_writepage(struct page *pp) { struct address_space *mapping = pp->mapping; struct inode *inode; unsigned long end_index; unsigned offset = PAGE_CACHE_SIZE; long status; - - inode = (struct inode *) mapping->host; + + inode = (struct inode *)mapping->host; end_index = inode->i_size >> PAGE_CACHE_SHIFT; /* easy case */ if (pp->index < end_index) goto do_it; /* things got complicated... */ - offset = inode->i_size & (PAGE_CACHE_SIZE-1); + offset = inode->i_size & (PAGE_CACHE_SIZE - 1); /* OK, are we completely out? */ - if (pp->index >= end_index+1 || !offset) + if (pp->index >= end_index + 1 || !offset) return -EIO; -do_it: + do_it: AFS_GLOCK(); status = afs_linux_writepage_sync(inode, pp, 0, offset); AFS_GUNLOCK(); @@ -1354,32 +1481,23 @@ do_it: } #endif -#ifdef NOTUSED -/* afs_linux_bmap - supports generic_readpage, but we roll our own. */ -int afs_linux_bmap(struct inode *ip, int) { return -EINVAL; } - -/* afs_linux_truncate - * Handles discarding disk blocks if this were a device. ext2 indicates we - * may need to zero partial last pages of memory mapped files. - */ -void afs_linux_truncate(struct inode *ip) -{ -} -#endif - /* afs_linux_permission * Check access rights - returns error if can't check or permission denied. */ -int afs_linux_permission(struct inode *ip, int mode) +int +afs_linux_permission(struct inode *ip, int mode) { int code; cred_t *credp = crref(); int tmp = 0; AFS_GLOCK(); - if (mode & MAY_EXEC) tmp |= VEXEC; - if (mode & MAY_READ) tmp |= VREAD; - if (mode & MAY_WRITE) tmp |= VWRITE; + if (mode & MAY_EXEC) + tmp |= VEXEC; + if (mode & MAY_READ) + tmp |= VREAD; + if (mode & MAY_WRITE) + tmp |= VWRITE; code = afs_access(ITOAFS(ip), tmp, credp); AFS_GUNLOCK(); @@ -1388,19 +1506,14 @@ int afs_linux_permission(struct inode *ip, int mode) } -#ifdef NOTUSED -/* msdos sector mapping hack for memory mapping. */ -int afs_linux_smap(struct inode *ip, int) { return -EINVAL; } -#endif - #if defined(AFS_LINUX24_ENV) -int afs_linux_writepage_sync(struct inode *ip, struct page *pp, - unsigned long offset, - unsigned int count) +int +afs_linux_writepage_sync(struct inode *ip, struct page *pp, + unsigned long offset, unsigned int count) { struct vcache *vcp = ITOAFS(ip); char *buffer; - loff_t base; + afs_offs_t base; int code = 0; cred_t *credp; uio_t tuio; @@ -1412,9 +1525,8 @@ int afs_linux_writepage_sync(struct inode *ip, struct page *pp, credp = crref(); afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp, - ICL_TYPE_POINTER, pp, - ICL_TYPE_INT32, atomic_read(&pp->count), - ICL_TYPE_INT32, 99999); + ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, atomic_read(&pp->count), + ICL_TYPE_INT32, 99999); setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS); @@ -1422,8 +1534,9 @@ int afs_linux_writepage_sync(struct inode *ip, struct page *pp, vcache2inode(vcp); - if (!code && afs_stats_cmperf.cacheCurrDirtyChunks > - afs_stats_cmperf.cacheMaxDirtyChunks) { + if (!code + && afs_stats_cmperf.cacheCurrDirtyChunks > + afs_stats_cmperf.cacheMaxDirtyChunks) { struct vrequest treq; ObtainWriteLock(&vcp->lock, 533); @@ -1434,9 +1547,8 @@ int afs_linux_writepage_sync(struct inode *ip, struct page *pp, code = code ? -code : count - tuio.uio_resid; afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp, - ICL_TYPE_POINTER, pp, - ICL_TYPE_INT32, atomic_read(&pp->count), - ICL_TYPE_INT32, code); + ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, atomic_read(&pp->count), + ICL_TYPE_INT32, code); crfree(credp); kunmap(pp); @@ -1445,7 +1557,7 @@ int afs_linux_writepage_sync(struct inode *ip, struct page *pp, } static int -afs_linux_updatepage(struct file *file, struct page *page, +afs_linux_updatepage(struct file *file, struct page *page, unsigned long offset, unsigned int count) { struct dentry *dentry = file->f_dentry; @@ -1458,27 +1570,27 @@ afs_linux_updatepage(struct file *file, struct page *page, * Called from generic_file_write. buffer is still in user space. pagep * has been filled in with old data if we're updating less than a page. */ -int afs_linux_updatepage(struct file *fp, struct page *pp, - unsigned long offset, - unsigned int count, int sync) +int +afs_linux_updatepage(struct file *fp, struct page *pp, unsigned long offset, + unsigned int count, int sync) { struct vcache *vcp = ITOAFS(FILE_INODE(fp)); - u8 *page_addr = (u8*) afs_linux_page_address(pp); + u8 *page_addr = (u8 *) afs_linux_page_address(pp); int code = 0; cred_t *credp; uio_t tuio; struct iovec iovec; - + set_bit(PG_locked, &pp->flags); credp = crref(); AFS_GLOCK(); afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp, - ICL_TYPE_POINTER, pp, - ICL_TYPE_INT32, atomic_read(&pp->count), + ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, atomic_read(&pp->count), ICL_TYPE_INT32, 99999); - setup_uio(&tuio, &iovec, page_addr + offset, pageoff(pp) + offset, count, - UIO_WRITE, AFS_UIOSYS); + setup_uio(&tuio, &iovec, page_addr + offset, + (afs_offs_t) (pageoff(pp) + offset), count, UIO_WRITE, + AFS_UIOSYS); code = afs_write(vcp, &tuio, fp->f_flags, credp, 0); @@ -1486,8 +1598,7 @@ int afs_linux_updatepage(struct file *fp, struct page *pp, code = code ? -code : count - tuio.uio_resid; afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp, - ICL_TYPE_POINTER, pp, - ICL_TYPE_INT32, atomic_read(&pp->count), + ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, atomic_read(&pp->count), ICL_TYPE_INT32, code); AFS_GUNLOCK(); @@ -1499,13 +1610,15 @@ int afs_linux_updatepage(struct file *fp, struct page *pp, #endif #if defined(AFS_LINUX24_ENV) -static int afs_linux_commit_write(struct file *file, struct page *page, unsigned offset, unsigned to) +static int +afs_linux_commit_write(struct file *file, struct page *page, unsigned offset, + unsigned to) { int code; AFS_GLOCK(); lock_kernel(); - code = afs_linux_updatepage(file, page, offset, to-offset); + code = afs_linux_updatepage(file, page, offset, to - offset); unlock_kernel(); AFS_GUNLOCK(); kunmap(page); @@ -1513,106 +1626,78 @@ static int afs_linux_commit_write(struct file *file, struct page *page, unsigned return code; } -static int afs_linux_prepare_write(struct file *file, struct page *page, - unsigned from, unsigned to) +static int +afs_linux_prepare_write(struct file *file, struct page *page, unsigned from, + unsigned to) { kmap(page); return 0; } -extern int afs_notify_change(struct dentry *dp, struct iattr* iattrp); +extern int afs_notify_change(struct dentry *dp, struct iattr *iattrp); #endif -#if defined(AFS_LINUX24_ENV) struct inode_operations afs_file_iops = { - revalidate: afs_linux_revalidate, - setattr: afs_notify_change, - permission: afs_linux_permission, -}; -struct address_space_operations afs_file_aops = { - readpage: afs_linux_readpage, - writepage: afs_linux_writepage, - commit_write: afs_linux_commit_write, - prepare_write: afs_linux_prepare_write, -}; - -struct inode_operations *afs_ops = &afs_file_iops; +#if defined(AFS_LINUX26_ENV) + .permission = afs_linux_permission, + .getattr = afs_linux_getattr, + .setattr = afs_notify_change, +#elif defined(AFS_LINUX24_ENV) + .permission = afs_linux_permission, + .revalidate = afs_linux_revalidate, + .setattr = afs_notify_change, #else -struct inode_operations afs_iops = { - &afs_file_fops, /* file operations */ - NULL, /* afs_linux_create */ - NULL, /* afs_linux_lookup */ - NULL, /* afs_linux_link */ - NULL, /* afs_linux_unlink */ - NULL, /* afs_linux_symlink */ - NULL, /* afs_linux_mkdir */ - NULL, /* afs_linux_rmdir */ - NULL, /* afs_linux_mknod */ - NULL, /* afs_linux_rename */ - NULL, /* afs_linux_readlink */ - NULL, /* afs_linux_follow_link */ - afs_linux_readpage, - NULL, /* afs_linux_writepage */ - NULL, /* afs_linux_bmap */ - NULL, /* afs_linux_truncate */ - afs_linux_permission, - NULL, /* afs_linux_smap */ - afs_linux_updatepage, - afs_linux_revalidate, + .default_file_ops = &afs_file_fops, + .readpage = afs_linux_readpage, + .revalidate = afs_linux_revalidate, + .updatepage = afs_linux_updatepage, +#endif }; -struct inode_operations *afs_ops = &afs_iops; +#if defined(AFS_LINUX24_ENV) +struct address_space_operations afs_file_aops = { + .readpage = afs_linux_readpage, + .writepage = afs_linux_writepage, + .commit_write = afs_linux_commit_write, + .prepare_write = afs_linux_prepare_write, +}; #endif + /* Separate ops vector for directories. Linux 2.2 tests type of inode * by what sort of operation is allowed..... */ -#if defined(AFS_LINUX24_ENV) + struct inode_operations afs_dir_iops = { - create: afs_linux_create, - lookup: afs_linux_lookup, - link: afs_linux_link, - unlink: afs_linux_unlink, - symlink: afs_linux_symlink, - mkdir: afs_linux_mkdir, - rmdir: afs_linux_rmdir, - rename: afs_linux_rename, - revalidate: afs_linux_revalidate, - setattr: afs_notify_change, - permission: afs_linux_permission, -}; +#if !defined(AFS_LINUX24_ENV) + .default_file_ops = &afs_dir_fops, #else -struct inode_operations afs_dir_iops = { - &afs_dir_fops, /* file operations for directories */ - afs_linux_create, - afs_linux_lookup, - afs_linux_link, - afs_linux_unlink, - afs_linux_symlink, - afs_linux_mkdir, - afs_linux_rmdir, - NULL, /* afs_linux_mknod */ - afs_linux_rename, - NULL, /* afs_linux_readlink */ - NULL, /* afs_linux_follow_link */ - NULL, /* afs_linux_readpage */ - NULL, /* afs_linux_writepage */ - NULL, /* afs_linux_bmap */ - NULL, /* afs_linux_truncate */ - afs_linux_permission, - NULL, /* afs_linux_smap */ - NULL, /* afs_linux_updatepage */ - afs_linux_revalidate, -}; + .setattr = afs_notify_change, #endif + .create = afs_linux_create, + .lookup = afs_linux_lookup, + .link = afs_linux_link, + .unlink = afs_linux_unlink, + .symlink = afs_linux_symlink, + .mkdir = afs_linux_mkdir, + .rmdir = afs_linux_rmdir, + .rename = afs_linux_rename, +#if defined(AFS_LINUX26_ENV) + .getattr = afs_linux_getattr, +#else + .revalidate = afs_linux_revalidate, +#endif + .permission = afs_linux_permission, +}; /* We really need a separate symlink set of ops, since do_follow_link() * determines if it _is_ a link by checking if the follow_link op is set. */ #if defined(AFS_LINUX24_ENV) -static int afs_symlink_filler(struct file *file, struct page *page) +static int +afs_symlink_filler(struct file *file, struct page *page) { - struct inode *ip = (struct inode *) page->mapping->host; + struct inode *ip = (struct inode *)page->mapping->host; char *p = (char *)kmap(page); int code; @@ -1620,9 +1705,9 @@ static int afs_symlink_filler(struct file *file, struct page *page) lock_kernel(); code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS); - if (code<0) - goto fail; - p[code] = '\0'; /* null terminate? */ + if (code < 0) + goto fail; + p[code] = '\0'; /* null terminate? */ unlock_kernel(); AFS_GUNLOCK(); @@ -1631,7 +1716,7 @@ static int afs_symlink_filler(struct file *file, struct page *page) UnlockPage(page); return 0; -fail: + fail: unlock_kernel(); AFS_GUNLOCK(); @@ -1642,35 +1727,19 @@ fail: } struct address_space_operations afs_symlink_aops = { - readpage: afs_symlink_filler + .readpage = afs_symlink_filler }; +#endif struct inode_operations afs_symlink_iops = { - readlink: page_readlink, - follow_link: page_follow_link, - setattr: afs_notify_change, -}; +#if defined(AFS_LINUX24_ENV) + .readlink = page_readlink, + .follow_link = page_follow_link, + .setattr = afs_notify_change, #else -struct inode_operations afs_symlink_iops = { - NULL, /* file operations */ - NULL, /* create */ - NULL, /* lookup */ - NULL, /* link */ - NULL, /* unlink */ - NULL, /* symlink */ - NULL, /* mkdir */ - NULL, /* rmdir */ - NULL, /* afs_linux_mknod */ - NULL, /* rename */ - afs_linux_readlink, - afs_linux_follow_link, - NULL, /* readpage */ - NULL, /* afs_linux_writepage */ - NULL, /* afs_linux_bmap */ - NULL, /* afs_linux_truncate */ - afs_linux_permission, /* tho the code appears to indicate not used? */ - NULL, /* afs_linux_smap */ - NULL, /* updatepage */ - afs_linux_revalidate, /* tho the code appears to indicate not used? */ -}; + .readlink = afs_linux_readlink, + .follow_link = afs_linux_follow_link, + .permission = afs_linux_permission, + .revalidate = afs_linux_revalidate, #endif +}; diff --git a/src/afs/Makefile.am b/src/afs/Makefile.am index 1ea96181f..58ac16009 100644 --- a/src/afs/Makefile.am +++ b/src/afs/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.1 2001/07/05 01:00:31 hartmans Exp $ +# $Id: Makefile.am,v 1.1 2001/06/05 20:17:49 shadow Exp $ include $(top_srcdir)/Makefile.am.common diff --git a/src/afs/Makefile.in b/src/afs/Makefile.in index e2d11baff..d31ce8dc5 100644 --- a/src/afs/Makefile.in +++ b/src/afs/Makefile.in @@ -7,48 +7,25 @@ # # Portions Copyright (c) 2003 Apple Computer, Inc. -DEST=@DEST@ -TOP_INCDIR=@TOP_INCDIR@ -TOP_LIBDIR=@TOP_LIBDIR@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ -libexecdir=@libexecdir@ -libdir=@libdir@ -includedir=@includedir@ -mandir=@mandir@ -afssrvbindir=@afssrvbindir@ -afssrvsbindir=@afssrvsbindir@ -afssrvlibexecdir=@afssrvlibexecdir@ -COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et -RXGEN=${TOP_SRCDIR}/rxgen/rxgen -TOP_SRCDIR=@TOP_SRCDIR@ -SYS_NAME=@AFS_SYSNAME@ - -SHELL=/bin/sh -KERNELDIR = ../libafs -UKERNELDIR = ../libuafs - -include ../config/Makefile.${SYS_NAME} - -all: kinstall ukinstall ${TOP_INCDIR}/afs/afs.h ${TOP_INCDIR}/afs/osi_inode.h ${TOP_INCDIR}/afs/afs_stats.h ${TOP_INCDIR}/afs/exporter.h ${TOP_INCDIR}/afs/nfsclient.h ${TOP_INCDIR}/afs/sysctl.h +srcdir=@srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config + +all: depinstall + +depinstall: ${TOP_INCDIR}/afs/afs.h ${TOP_INCDIR}/afs/osi_inode.h ${TOP_INCDIR}/afs/afs_stats.h \ + ${TOP_INCDIR}/afs/exporter.h ${TOP_INCDIR}/afs/nfsclient.h afszcm.cat AFS_component_version_number.c ${TOP_INCDIR}/afs/unified_afs.h ${TOP_INCDIR}/afs/sysctl.h case ${SYS_NAME} in \ pmax_ul43 | pmax_ul43a) \ ${INSTALL} longc_procs.h ${TOP_INCDIR}/afs ;; \ esac -kinstall: ${KERNELDIR}/afs AFS_component_version_number.c afs_trace.h afszcm.cat - -chmod 666 ${KERNELDIR}/afs/* - ${INSTALL} *.[csh] ${KERNELDIR}/afs - ${INSTALL} VNOPS/*.[csh] ${KERNELDIR}/afs - ${INSTALL} ${AFS_OSTYPE}/*.[csh] ${KERNELDIR}/afs +afs_trace.h afs_trace.msf: afs_trace.et + ${COMPILE_ET} -v 2 -p ${srcdir} afs_trace.et -afs_trace.h: afs_trace.et - ${COMPILE_ET} -v 2 afs_trace.et +unified_afs.c unified_afs.h: unified_afs.et + $(RM) -f unified_afs.c unified_afs.h + ${COMPILE_ET} -p ${srcdir} unified_afs -h unified_afs -# NOTE: linux case uses --new as well to work around bug in some versions of -# gencat. afszcm.cat: afs_trace.msf -$(RM) -f afszcm.cat case ${SYS_NAME} in \ @@ -64,26 +41,14 @@ afszcm.cat: afs_trace.msf gencat afszcm.cat afs_trace.msf ;; \ esac -${KERNELDIR}/afs: - mkdir -p $@ - -ukinstall: ${UKERNELDIR}/afs AFS_component_version_number.c afs_trace.h - -chmod 666 ${UKERNELDIR}/afs/* - ${INSTALL} *.[csh] ${UKERNELDIR}/afs - ${INSTALL} VNOPS/*.[csh] ${UKERNELDIR}/afs - ${INSTALL} UKERNEL/*.[csh] ${UKERNELDIR}/afs - -${UKERNELDIR}/afs: - mkdir -p $@ - -install: ${DESTDIR}${includedir}/afs/afs.h ${DESTDIR}${includedir}/afs/osi_inode.h ${DESTDIR}${includedir}/afs/afs_stats.h ${DESTDIR}${includedir}/afs/exporter.h ${DESTDIR}${includedir}/afs/nfsclient.h ${DESTDIR}${includedir}/afs/sysctl.h +install: ${DESTDIR}${includedir}/afs/afs.h ${DESTDIR}${includedir}/afs/osi_inode.h ${DESTDIR}${includedir}/afs/afs_stats.h ${DESTDIR}${includedir}/afs/exporter.h ${DESTDIR}${includedir}/afs/nfsclient.h ${DESTDIR}${includedir}/afs/unified_afs.h ${DESTDIR}${includedir}/afs/sysctl.h case ${SYS_NAME} in \ pmax_ul43 | pmax_ul43a) \ ${INSTALL} longc_procs.h ${DESTDIR}${includedir}/afs ;; \ esac case ${SYS_NAME} in \ *linux* ) \ - ${INSTALL} ${AFS_OSTYPE}/osi_vfs.h ${DESTDIR}${includedir}/afs || true ;;\ + ${INSTALL} ${MKAFS_OSTYPE}/osi_vfs.h ${DESTDIR}${includedir}/afs || true ;;\ * ) \ echo No vfs headers to install for ${SYS_NAME};; \ esac @@ -98,18 +63,27 @@ ${DEST}/include/afs/afs.h: afs.h ${DESTDIR}${includedir}/afs/afs.h: afs.h ${INSTALL} $? $@ - ${TOP_INCDIR}/afs/afs.h: afs.h ${INSTALL} $? $@ -${DEST}/include/afs/osi_inode.h: ${AFS_OSTYPE}/osi_inode.h +${DEST}/include/afs/unified_afs.h: unified_afs.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/unified_afs.h: unified_afs.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/unified_afs.h: unified_afs.h ${INSTALL} $? $@ -${DESTDIR}${includedir}/afs/osi_inode.h: ${AFS_OSTYPE}/osi_inode.h + +${DEST}/include/afs/osi_inode.h: ${MKAFS_OSTYPE}/osi_inode.h ${INSTALL} $? $@ -${TOP_INCDIR}/afs/osi_inode.h: ${AFS_OSTYPE}/osi_inode.h +${DESTDIR}${includedir}/afs/osi_inode.h: ${MKAFS_OSTYPE}/osi_inode.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/osi_inode.h: ${MKAFS_OSTYPE}/osi_inode.h ${INSTALL} $? $@ @@ -155,20 +129,20 @@ ${TOP_INCDIR}/afs/nfsclient.h: nfsclient.h ${INSTALL} $? $@ -dest: ${DEST}/include/afs/afs.h ${DEST}/include/afs/osi_inode.h ${DEST}/include/afs/afs_stats.h ${DEST}/include/afs/exporter.h ${DEST}/include/afs/nfsclient.h ${DEST}/include/afs/sysctl.h +dest: ${DEST}/include/afs/afs.h ${DEST}/include/afs/osi_inode.h ${DEST}/include/afs/afs_stats.h ${DEST}/include/afs/exporter.h ${DEST}/include/afs/nfsclient.h ${DEST}/include/afs/unified_afs.h ${DEST}/include/afs/sysctl.h case ${SYS_NAME} in \ pmax_ul43 | pmax_ul43a) \ ${INSTALL} longc_procs.h ${DEST}/include/afs ;; \ esac case ${SYS_NAME} in \ - next_mach30 | vax_ul43 | *_darwin_* | i386_fbsd* ) \ + next_mach30 | vax_ul43 | *_darwin* | i386_fbsd* ) \ echo skipping afszcm.cat install for ${SYS_NAME} ;; \ * ) \ ${INSTALL} afszcm.cat ${DEST}/root.client/usr/vice/etc/C ;; \ esac - -case ${SYS_NAME} in \ + case ${SYS_NAME} in \ *linux* ) \ - ${INSTALL} ${AFS_OSTYPE}/osi_vfs.h ${DEST}/include/afs || true ;;\ + ${INSTALL} ${MKAFS_OSTYPE}/osi_vfs.h ${DEST}/include/afs || true;;\ * ) \ echo No vfs headers to install for ${SYS_NAME};; \ esac diff --git a/src/afs/SOLARIS/osi_file.c b/src/afs/SOLARIS/osi_file.c index 13295789f..657e68f43 100644 --- a/src/afs/SOLARIS/osi_file.c +++ b/src/afs/SOLARIS/osi_file.c @@ -8,18 +8,19 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_file.c,v 1.1.1.9 2002/12/11 02:36:19 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/SOLARIS/osi_file.c,v 1.12 2003/07/15 23:14:26 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ -#include "../afs/osi_inode.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#include "afs/osi_inode.h" -int afs_osicred_initialized=0; -struct AFS_UCRED afs_osi_cred; +int afs_osicred_initialized = 0; +struct AFS_UCRED afs_osi_cred; afs_lock_t afs_xosi; /* lock is for tvattr */ extern struct osi_dev cacheDev; extern struct vfs *afs_cacheVfsp; @@ -35,17 +36,18 @@ extern struct vfs *afs_cacheVfsp; int afs_CacheFSType = -1; /* pointer to VXFS routine to access vnodes by inode number */ -int (*vxfs_vx_vp_byino)(); +int (*vxfs_vx_vp_byino) (); /* Initialize the cache operations. Called while initializing cache files. */ -void afs_InitDualFSCacheOps(struct vnode *vp) +void +afs_InitDualFSCacheOps(struct vnode *vp) { int code; static int inited = 0; struct vfs *vfsp; #ifdef AFS_SUN56_ENV struct statvfs64 vfst; -#else /* AFS_SUN56_ENV */ +#else /* AFS_SUN56_ENV */ struct statvfs vfst; #endif /* AFS_SUN56_ENV */ @@ -66,7 +68,8 @@ void afs_InitDualFSCacheOps(struct vnode *vp) if (strcmp(vfst.f_basetype, "vxfs") == 0) { vxfs_vx_vp_byino = (int (*)())modlookup("vxfs", "vx_vp_byino"); if (vxfs_vx_vp_byino == NULL) - osi_Panic("afs_InitDualFSCacheOps: modlookup(vx_vp_byino) failed"); + osi_Panic + ("afs_InitDualFSCacheOps: modlookup(vx_vp_byino) failed"); afs_CacheFSType = AFS_SUN_VXFS_CACHE; return; @@ -76,12 +79,13 @@ void afs_InitDualFSCacheOps(struct vnode *vp) return; } -ino_t VnodeToIno(vnode_t *vp) +ino_t +VnodeToIno(vnode_t * vp) { int code; struct vattr vattr; - vattr.va_mask = AT_FSID|AT_NODEID; /* quick return using this mask. */ + vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */ code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred); if (code) { osi_Panic("VnodeToIno"); @@ -89,22 +93,24 @@ ino_t VnodeToIno(vnode_t *vp) return vattr.va_nodeid; } -dev_t VnodeToDev(vnode_t *vp) +dev_t +VnodeToDev(vnode_t * vp) { int code; struct vattr vattr; - vattr.va_mask = AT_FSID|AT_NODEID; /* quick return using this mask. */ + vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */ AFS_GUNLOCK(); code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred); AFS_GLOCK(); if (code) { osi_Panic("VnodeToDev"); } - return (dev_t)vattr.va_fsid; + return (dev_t) vattr.va_fsid; } -afs_int32 VnodeToSize(vnode_t *vp) +afs_int32 +VnodeToSize(vnode_t * vp) { int code; struct vattr vattr; @@ -112,8 +118,8 @@ afs_int32 VnodeToSize(vnode_t *vp) /* * We lock xosi in osi_Stat, so we probably should * lock it here too - RWH. - */ - MObtainWriteLock(&afs_xosi,578); + */ + MObtainWriteLock(&afs_xosi, 578); vattr.va_mask = AT_SIZE; AFS_GUNLOCK(); code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred); @@ -122,19 +128,19 @@ afs_int32 VnodeToSize(vnode_t *vp) osi_Panic("VnodeToSize"); } MReleaseWriteLock(&afs_xosi); - return (afs_int32)(vattr.va_size); + return (afs_int32) (vattr.va_size); } -void *osi_VxfsOpen(ainode) - afs_int32 ainode; +void * +osi_VxfsOpen(afs_int32 ainode) { struct vnode *vp; register struct osi_file *afile = NULL; afs_int32 code = 0; int dummy; - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); AFS_GUNLOCK(); - code = (*vxfs_vx_vp_byino)(afs_cacheVfsp, &vp, (unsigned int)ainode); + code = (*vxfs_vx_vp_byino) (afs_cacheVfsp, &vp, (unsigned int)ainode); AFS_GLOCK(); if (code) { osi_FreeSmallSpace(afile); @@ -143,25 +149,29 @@ void *osi_VxfsOpen(ainode) afile->vnode = vp; afile->size = VnodeToSize(afile->vnode); afile->offset = 0; - afile->proc = (int (*)()) 0; - afile->inum = ainode; /* for hint validity checking */ + afile->proc = (int (*)())0; + afile->inum = ainode; /* for hint validity checking */ return (void *)afile; } #endif /* AFS_HAVE_VXFS */ #if defined(AFS_SUN57_64BIT_ENV) -void *osi_UfsOpen(ino_t ainode) +void * +osi_UfsOpen(ino_t ainode) #else -void *osi_UfsOpen(afs_int32 ainode) +void * +osi_UfsOpen(afs_int32 ainode) #endif { struct inode *ip; register struct osi_file *afile = NULL; afs_int32 code = 0; int dummy; - afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); + afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); AFS_GUNLOCK(); - code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode, &ip, CRED(),&dummy); + code = + igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, &ip, + CRED(), &dummy); AFS_GLOCK(); if (code) { osi_FreeSmallSpace(afile); @@ -170,8 +180,8 @@ void *osi_UfsOpen(afs_int32 ainode) afile->vnode = ITOV(ip); afile->size = VTOI(afile->vnode)->i_size; afile->offset = 0; - afile->proc = (int (*)()) 0; - afile->inum = ainode; /* for hint validity checking */ + afile->proc = (int (*)())0; + afile->inum = ainode; /* for hint validity checking */ return (void *)afile; } @@ -179,15 +189,16 @@ void *osi_UfsOpen(afs_int32 ainode) * In Solaris 7 we use 64 bit inode numbers */ #if defined(AFS_SUN57_64BIT_ENV) -void *osi_UFSOpen(ino_t ainode) +void * +osi_UFSOpen(ino_t ainode) #else -void *osi_UFSOpen(ainode) - afs_int32 ainode; +void * +osi_UFSOpen(afs_int32 ainode) #endif { extern int cacheDiskType; AFS_STATCNT(osi_UFSOpen); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) { + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) { osi_Panic("UFSOpen called for non-UFS cache\n"); } if (!afs_osicred_initialized) { @@ -203,13 +214,13 @@ void *osi_UFSOpen(ainode) return osi_UfsOpen(ainode); } -afs_osi_Stat(afile, astat) - register struct osi_file *afile; - register struct osi_stat *astat; { +int +afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) +{ register afs_int32 code; struct vattr tvattr; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi,320); + MObtainWriteLock(&afs_xosi, 320); /* Ufs doesn't seem to care about the flags so we pass 0 for now */ tvattr.va_mask = AT_ALL; AFS_GUNLOCK(); @@ -225,21 +236,21 @@ afs_osi_Stat(afile, astat) return code; } -osi_UFSClose(afile) - register struct osi_file *afile; - { - AFS_STATCNT(osi_Close); - if(afile->vnode) { +int +osi_UFSClose(register struct osi_file *afile) +{ + AFS_STATCNT(osi_Close); + if (afile->vnode) { AFS_RELE(afile->vnode); - } - - osi_FreeSmallSpace(afile); - return 0; - } - -osi_UFSTruncate(afile, asize) - register struct osi_file *afile; - afs_int32 asize; { + } + + osi_FreeSmallSpace(afile); + return 0; +} + +int +osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) +{ struct AFS_UCRED *oldCred; struct vattr tvattr; register afs_int32 code; @@ -251,8 +262,9 @@ osi_UFSTruncate(afile, asize) * small enough. Check now and save some time. */ code = afs_osi_Stat(afile, &tstat); - if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi,321); + if (code || tstat.size <= asize) + return code; + MObtainWriteLock(&afs_xosi, 321); tvattr.va_mask = AT_SIZE; tvattr.va_size = asize; /* @@ -265,26 +277,25 @@ osi_UFSTruncate(afile, asize) return code; } -void osi_DisableAtimes(avp) -struct vnode *avp; +void +osi_DisableAtimes(struct vnode *avp) { - if (afs_CacheFSType == AFS_SUN_UFS_CACHE) { - struct inode *ip = VTOI(avp); - rw_enter(&ip->i_contents, RW_READER); - mutex_enter(&ip->i_tlock); - ip->i_flag &= ~IACC; - mutex_exit(&ip->i_tlock); - rw_exit(&ip->i_contents); - } + if (afs_CacheFSType == AFS_SUN_UFS_CACHE) { + struct inode *ip = VTOI(avp); + rw_enter(&ip->i_contents, RW_READER); + mutex_enter(&ip->i_tlock); + ip->i_flag &= ~IACC; + mutex_exit(&ip->i_tlock); + rw_exit(&ip->i_contents); + } } /* Generic read interface */ -afs_osi_Read(afile, offset, aptr, asize) - register struct osi_file *afile; - int offset; - char *aptr; - afs_int32 asize; { +int +afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; #if defined(AFS_SUN57_ENV) ssize_t resid; @@ -292,69 +303,70 @@ afs_osi_Read(afile, offset, aptr, asize) int resid; #endif register afs_int32 code; - register afs_int32 cnt1=0; + register afs_int32 cnt1 = 0; AFS_STATCNT(osi_Read); /** * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ - if ( !afile ) { - if ( !afs_shuttingdown ) - osi_Panic("osi_Read called with null param"); + if (!afile) { + if (!afs_shuttingdown) + osi_Panic("osi_Read called with null param"); else return EIO; } - if (offset != -1) afile->offset = offset; + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, 0, 0, &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset, + AFS_UIOSYS, 0, 0, &afs_osi_cred, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; osi_DisableAtimes(afile->vnode); - } - else { + } else { afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, - ICL_TYPE_INT32, code); + ICL_TYPE_INT32, code); code = -1; } return code; } /* Generic write interface */ -afs_osi_Write(afile, offset, aptr, asize) - register struct osi_file *afile; - char *aptr; - afs_int32 offset; - afs_int32 asize; { +int +afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, + afs_int32 asize) +{ struct AFS_UCRED *oldCred; #if defined(AFS_SUN57_ENV) ssize_t resid; #else - int resid; + int resid; #endif register afs_int32 code; AFS_STATCNT(osi_Write); - if ( !afile ) - osi_Panic("afs_osi_Write called with null param"); - if (offset != -1) afile->offset = offset; + if (!afile) + osi_Panic("afs_osi_Write called with null param"); + if (offset != -1) + afile->offset = offset; AFS_GUNLOCK(); - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, - afile->offset, AFS_UIOSYS, 0, RLIM64_INFINITY, - &afs_osi_cred, &resid); + code = + gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + afile->offset, AFS_UIOSYS, 0, RLIM64_INFINITY, &afs_osi_cred, + &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; - } - else { + } else { code = -1; } if (afile->proc) { - (*afile->proc)(afile, code); + (*afile->proc) (afile, code); } return code; } @@ -363,9 +375,8 @@ afs_osi_Write(afile, offset, aptr, asize) /* This work should be handled by physstrat in ca/machdep.c. This routine written from the RT NFS port strategy routine. It has been generalized a bit, but should still be pretty clear. */ -int afs_osi_MapStrategy(aproc, bp) - int (*aproc)(); - register struct buf *bp; +int +afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp) { afs_int32 returnCode; @@ -378,13 +389,12 @@ int afs_osi_MapStrategy(aproc, bp) void -shutdown_osifile() +shutdown_osifile(void) { - extern int afs_cold_shutdown; + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osifile); - if (afs_cold_shutdown) { - afs_osicred_initialized = 0; - } + AFS_STATCNT(shutdown_osifile); + if (afs_cold_shutdown) { + afs_osicred_initialized = 0; + } } - diff --git a/src/afs/SOLARIS/osi_groups.c b/src/afs/SOLARIS/osi_groups.c index 0dff3c4e4..a85659832 100644 --- a/src/afs/SOLARIS/osi_groups.c +++ b/src/afs/SOLARIS/osi_groups.c @@ -14,42 +14,38 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_groups.c,v 1.1.1.5 2002/05/10 23:44:11 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/SOLARIS/osi_groups.c,v 1.7 2003/07/15 23:14:26 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ static int -afs_getgroups( - struct cred *cred, - gid_t *gidset); + afs_getgroups(struct cred *cred, gid_t * gidset); static int -afs_setgroups( - struct cred **cred, - int ngroups, - gid_t *gidset, - int change_parent); + afs_setgroups(struct cred **cred, int ngroups, gid_t * gidset, + int change_parent); #if defined(AFS_SUN55_ENV) int afs_xsetgroups(uap, rvp) -u_int uap; /* this is gidsetsize */ -gid_t *rvp; /* this is gidset */ -#else + u_int uap; /* this is gidsetsize */ + gid_t *rvp; /* this is gidset */ +#else struct setgroupsa { u_int gidsetsize; gid_t *gidset; }; -afs_xsetgroups(uap, rvp) - struct setgroupsa *uap; - rval_t *rvp; +afs_xsetgroups(uap, rvp) + struct setgroupsa *uap; + rval_t *rvp; #endif { int code = 0; @@ -60,7 +56,8 @@ afs_xsetgroups(uap, rvp) AFS_GLOCK(); code = afs_InitReq(&treq, proc->p_cred); AFS_GUNLOCK(); - if (code) return code; + if (code) + return code; code = setgroups(uap, rvp); /* Note that if there is a pag already in the new groups we don't @@ -79,10 +76,10 @@ afs_xsetgroups(uap, rvp) int setpag(cred, pagvalue, newpag, change_parent) - struct cred **cred; - afs_uint32 pagvalue; - afs_uint32 *newpag; - afs_uint32 change_parent; + struct cred **cred; + afs_uint32 pagvalue; + afs_uint32 *newpag; + afs_uint32 change_parent; { gid_t *gidset; int ngroups, code; @@ -97,16 +94,16 @@ setpag(cred, pagvalue, newpag, change_parent) if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) { /* We will have to shift grouplist to make room for pag */ - if ((sizeof gidset[0])*(ngroups + 2) > AFS_SMALLOCSIZ) { + if ((sizeof gidset[0]) * (ngroups + 2) > AFS_SMALLOCSIZ) { osi_FreeSmallSpace((char *)gidset); return (E2BIG); } - for (j = ngroups -1; j >= 0; j--) { - gidset[j+2] = gidset[j]; - } + for (j = ngroups - 1; j >= 0; j--) { + gidset[j + 2] = gidset[j]; + } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); + *newpag = (pagvalue == -1 ? genpag() : pagvalue); afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]); /* afs_setgroups will release curproc->p_crlock */ if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) { @@ -119,9 +116,7 @@ setpag(cred, pagvalue, newpag, change_parent) static int -afs_getgroups( - struct cred *cred, - gid_t *gidset) +afs_getgroups(struct cred *cred, gid_t * gidset) { int ngrps, savengrps; gid_t *gp; @@ -132,18 +127,15 @@ afs_getgroups( savengrps = ngrps = cred->cr_ngroups; gp = cred->cr_groups; while (ngrps--) - *gidset++ = *gp++; + *gidset++ = *gp++; return savengrps; } static int -afs_setgroups( - struct cred **cred, - int ngroups, - gid_t *gidset, - int change_parent) +afs_setgroups(struct cred **cred, int ngroups, gid_t * gidset, + int change_parent) { int ngrps; int i; @@ -163,6 +155,6 @@ afs_setgroups( *gp++ = *gidset++; mutex_exit(&curproc->p_crlock); if (!change_parent) - crset(curproc, *cred); /* broadcast to all threads */ + crset(curproc, *cred); /* broadcast to all threads */ return (0); } diff --git a/src/afs/SOLARIS/osi_inode.c b/src/afs/SOLARIS/osi_inode.c index 98fd765a3..a7b66bcf7 100644 --- a/src/afs/SOLARIS/osi_inode.c +++ b/src/afs/SOLARIS/osi_inode.c @@ -14,17 +14,18 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_inode.c,v 1.1.1.8 2002/05/10 23:44:12 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/SOLARIS/osi_inode.c,v 1.14 2003/07/15 23:14:26 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/osi_inode.h" -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/osi_inode.h" +#include "afs/afs_stats.h" /* statistics stuff */ -extern int (*ufs_iallocp)(), (*ufs_iupdatp)(), (*ufs_igetp)(), - (*ufs_itimes_nolockp)(); +extern int (*ufs_iallocp) (), (*ufs_iupdatp) (), (*ufs_igetp) (), + (*ufs_itimes_nolockp) (); #define AFS_ITIMES(ip) { \ mutex_enter(&(ip)->i_tlock); \ @@ -35,7 +36,7 @@ extern int (*ufs_iallocp)(), (*ufs_iupdatp)(), (*ufs_igetp)(), #define AFS_ITIMES_NOLOCK(ip) \ (*ufs_itimes_nolockp)(ip); -getinode(vfsp, dev, inode, ipp, credp,perror) +getinode(vfsp, dev, inode, ipp, credp, perror) struct vfs *vfsp; struct AFS_UCRED *credp; struct inode **ipp; @@ -49,16 +50,16 @@ getinode(vfsp, dev, inode, ipp, credp,perror) struct fs *fs; struct inode *pip; struct ufsvfs *ufsvfsp; - + AFS_STATCNT(getinode); - + *perror = 0; - - if (!vfsp + + if (!vfsp #if !defined(AFS_SUN58_ENV) && !(vfsp = vfs_devsearch(dev)) #else - && !(vfsp = vfs_dev2vfsp(dev)) + && !(vfsp = vfs_dev2vfsp(dev)) #endif ) { return (ENODEV); @@ -68,7 +69,7 @@ getinode(vfsp, dev, inode, ipp, credp,perror) #ifdef HAVE_VFS_DQRWLOCK rw_enter(&ufsvfsp->vfs_dqrwlock, RW_READER); #endif - code = (*ufs_igetp)(vfsp, inode, &ip, credp); + code = (*ufs_igetp) (vfsp, inode, &ip, credp); #ifdef HAVE_VFS_DQRWLOCK rw_exit(&ufsvfsp->vfs_dqrwlock); #endif @@ -82,7 +83,7 @@ getinode(vfsp, dev, inode, ipp, credp,perror) } /* get an existing inode. Common code for iopen, iread/write, iinc/dec. */ -igetinode(vfsp, dev, inode, ipp, credp,perror) +igetinode(vfsp, dev, inode, ipp, credp, perror) struct AFS_UCRED *credp; struct inode **ipp; struct vfs *vfsp; @@ -93,44 +94,44 @@ igetinode(vfsp, dev, inode, ipp, credp,perror) struct inode *pip, *ip; extern struct osi_dev cacheDev; register int code = 0; - + *perror = 0; - + AFS_STATCNT(igetinode); - - code = getinode(vfsp, dev, inode, &ip, credp,perror); - if (code) + + code = getinode(vfsp, dev, inode, &ip, credp, perror); + if (code) return code; - + rw_enter(&ip->i_contents, RW_READER); - + if (ip->i_mode == 0) { /* Not an allocated inode */ rw_exit(&ip->i_contents); VN_RELE(ITOV(ip)); return (ENOENT); } - - if (ip->i_nlink == 0 || (ip->i_mode&IFMT) != IFREG) { + + if (ip->i_nlink == 0 || (ip->i_mode & IFMT) != IFREG) { AFS_ITIMES(ip); rw_exit(&ip->i_contents); VN_RELE(ITOV(ip)); return (ENOENT); } - + /* On VFS40 systems, iput does major synchronous write action, but only - when the reference count on the vnode goes to 0. Normally, Sun users - don't notice this because the DNLC keep references for them, but we - notice 'cause we don't. So, we make a fake dnlc entry which gets - cleaned up by iget when it needs the space. */ + * when the reference count on the vnode goes to 0. Normally, Sun users + * don't notice this because the DNLC keep references for them, but we + * notice 'cause we don't. So, we make a fake dnlc entry which gets + * cleaned up by iget when it needs the space. */ if (dev != cacheDev.dev) { /* * Don't call dnlc for the cm inodes since it's a big performance * penalty there! */ - dnlc_enter(ITOV(ip), "a", ITOV(ip), (struct AFS_UCRED *) 0); + dnlc_enter(ITOV(ip), "a", ITOV(ip), (struct AFS_UCRED *)0); } - + *ipp = ip; rw_exit(&ip->i_contents); return (code); @@ -138,34 +139,35 @@ igetinode(vfsp, dev, inode, ipp, credp,perror) int CrSync = 1; -afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp, credp) +afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp, + credp) rval_t *rvp; struct AFS_UCRED *credp; long near_inode, param1, param2, param3, param4; dev_t dev; { - int dummy, err=0; + int dummy, err = 0; struct inode *ip, *newip; register int code; dev_t newdev; struct ufsvfs *ufsvfsp; AFS_STATCNT(afs_syscall_icreate); - + if (!afs_suser(credp)) return (EPERM); - + /** Code to convert a 32 bit dev_t into a 64 bit dev_t * This conversion is needed only for the 64 bit OS. */ - + #ifdef AFS_SUN57_64BIT_ENV - newdev = expldev( (dev32_t) dev); + newdev = expldev((dev32_t) dev); #else newdev = dev; #endif - code = getinode(0, (dev_t)newdev, 2, &ip, credp,&dummy); + code = getinode(0, (dev_t) newdev, 2, &ip, credp, &dummy); if (code) { return (code); } @@ -176,7 +178,7 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp, credp) rw_enter(&ufsvfsp->vfs_dqrwlock, RW_READER); #endif rw_enter(&ip->i_contents, RW_WRITER); - code = (*ufs_iallocp)(ip, near_inode, 0, &newip, credp); + code = (*ufs_iallocp) (ip, near_inode, 0, &newip, credp); AFS_ITIMES_NOLOCK(ip); rw_exit(&ip->i_contents); #ifdef HAVE_VFS_DQRWLOCK @@ -189,7 +191,7 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp, credp) return (code); } rw_enter(&newip->i_contents, RW_WRITER); - newip->i_flag |= IACC|IUPD|ICHG; + newip->i_flag |= IACC | IUPD | ICHG; #if defined(AFS_SUN56_ENV) newip->i_vicemagic = VICEMAGIC; @@ -200,15 +202,15 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp, credp) newip->i_nlink = 1; newip->i_mode = IFREG; newip->i_vnode.v_type = VREG; - + newip->i_vicep1 = param1; - if (param2 == 0x1fffffff/*INODESPECIAL*/) { + if (param2 == 0x1fffffff /*INODESPECIAL*/) { newip->i_vicep2 = ((0x1fffffff << 3) + (param4 & 0x3)); newip->i_vicep3 = param3; } else { - newip->i_vicep2 = (((param2 >> 16) & 0x1f) << 27) + - (((param4 >> 16) & 0x1f) << 22) + - (param3 & 0x3fffff); + newip->i_vicep2 = + (((param2 >> 16) & 0x1f) << 27) + + (((param4 >> 16) & 0x1f) << 22) + (param3 & 0x3fffff); newip->i_vicep3 = ((param4 << 16) + (param2 & 0xffff)); } #ifdef AFS_SUN57_64BIT_ENV @@ -216,12 +218,12 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp, credp) #else rvp->r_val1 = newip->i_number; #endif - + /* * We're being conservative and sync to the disk */ if (CrSync) - (*ufs_iupdatp)(newip, 1); + (*ufs_iupdatp) (newip, 1); AFS_ITIMES_NOLOCK(newip); rw_exit(&newip->i_contents); VN_RELE(ITOV(newip)); @@ -231,12 +233,12 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, rvp, credp) afs_syscall_iopen(dev, inode, usrmod, rvp, credp) rval_t *rvp; struct AFS_UCRED *credp; - int inode, usrmod; + int inode, usrmod; dev_t dev; { struct file *fp; struct inode *ip; - struct vnode *vp = (struct vnode *)0; + struct vnode *vp = NULL; int dummy; int fd; register int code; @@ -250,18 +252,18 @@ afs_syscall_iopen(dev, inode, usrmod, rvp, credp) /** Code to convert a 32 bit dev_t into a 64 bit dev_t * This conversion is needed only for the 64 bit OS. */ - + #ifdef AFS_SUN57_64BIT_ENV - newdev = expldev( (dev32_t) dev); + newdev = expldev((dev32_t) dev); #else newdev = dev; #endif - code = igetinode(0, (dev_t)newdev, (ino_t)inode, &ip, credp,&dummy); + code = igetinode(0, (dev_t) newdev, (ino_t) inode, &ip, credp, &dummy); if (code) { return (code); } - code = falloc((struct vnode *)NULL, FWRITE|FREAD, &fp, &fd); + code = falloc((struct vnode *)NULL, FWRITE | FREAD, &fp, &fd); if (code) { rw_enter(&ip->i_contents, RW_READER); AFS_ITIMES(ip); @@ -269,14 +271,14 @@ afs_syscall_iopen(dev, inode, usrmod, rvp, credp) VN_RELE(ITOV(ip)); return (code); } - + /* fp->f_count, f_audit_data are set by falloc */ fp->f_vnode = ITOV(ip); - - fp->f_flag = (usrmod+1) & (FMASK); - + + fp->f_flag = (usrmod + 1) & (FMASK); + /* fp->f_count, f_msgcount are set by falloc */ - + /* fp->f_offset zeroed by falloc */ /* f_cred set by falloc */ /* @@ -312,17 +314,17 @@ afs_syscall_iincdec(dev, inode, inode_p1, amount, rvp, credp) if (!afs_suser(credp)) return (EPERM); - /** Code to convert a 32 bit dev_t into a 64 bit dev_t + /** Code to convert a 32 bit dev_t into a 64 bit dev_t * This conversion is needed only for the 64 bit OS. */ - + #ifdef AFS_SUN57_64BIT_ENV - newdev = expldev( (dev32_t) dev); + newdev = expldev((dev32_t) dev); #else newdev = dev; #endif - code = igetinode(0, (dev_t)newdev, (ino_t)inode, &ip, credp,&dummy); + code = igetinode(0, (dev_t) newdev, (ino_t) inode, &ip, credp, &dummy); if (code) { return (code); } @@ -343,11 +345,10 @@ afs_syscall_iincdec(dev, inode, inode_p1, amount, rvp, credp) ip->i_flag |= ICHG; /* We may want to force the inode to the disk in case of crashes, other references, etc. */ if (IncSync) - (*ufs_iupdatp)(ip, 1); + (*ufs_iupdatp) (ip, 1); AFS_ITIMES_NOLOCK(ip); rw_exit(&ip->i_contents); VN_RELE(ITOV(ip)); } return (code); } - diff --git a/src/afs/SOLARIS/osi_inode.h b/src/afs/SOLARIS/osi_inode.h index 2a5cffac5..e131651d8 100644 --- a/src/afs/SOLARIS/osi_inode.h +++ b/src/afs/SOLARIS/osi_inode.h @@ -40,8 +40,8 @@ #endif #if defined(AFS_SUN56_ENV) -#define IS_VICEMAGIC(ip) ((ip)->i_vicemagic == VICEMAGIC) -#define IS_DVICEMAGIC(dp) ((dp)->di_vicemagic == VICEMAGIC) +#define IS_VICEMAGIC(ip) ((ip)->i_vicemagic == VICEMAGIC) +#define IS_DVICEMAGIC(dp) ((dp)->di_vicemagic == VICEMAGIC) #define CLEAR_VICEMAGIC(ip) (ip)->i_vicemagic = (ip)->i_vicep3 = 0 #define CLEAR_DVICEMAGIC(dp) (dp)->di_vicemagic = (dp)->di_vicep3 = 0 diff --git a/src/afs/SOLARIS/osi_machdep.h b/src/afs/SOLARIS/osi_machdep.h index 09403c6b8..a7d051b1a 100644 --- a/src/afs/SOLARIS/osi_machdep.h +++ b/src/afs/SOLARIS/osi_machdep.h @@ -19,7 +19,7 @@ #define _OSI_MACHDEP_H_ #ifdef AFS_SUN57_64BIT_ENV -#include /* for get_udatamodel() */ +#include /* for get_udatamodel() */ #endif #define getpid() curproc->p_pid @@ -45,9 +45,9 @@ extern void gethrestime(timespec_t *); static int local_osi_Time() { - timespec_t start; - gethrestime(&start); - return start.tv_sec; + timespec_t start; + gethrestime(&start); + return start.tv_sec; } #else #define osi_Time() (hrestime.tv_sec) @@ -71,7 +71,7 @@ extern void *afs_osi_Alloc_NoSleep(size_t size); extern kmutex_t afs_global_lock; extern kmutex_t afs_rxglobal_lock; -#define AFS_GLOCK() mutex_enter(&afs_global_lock); +#define AFS_GLOCK() mutex_enter(&afs_global_lock); #define AFS_GUNLOCK() mutex_exit(&afs_global_lock); #define ISAFS_GLOCK() mutex_owned(&afs_global_lock) @@ -82,10 +82,10 @@ extern kmutex_t afs_rxglobal_lock; /* Associate the Berkley signal equivalent lock types to System V's */ -#define LOCK_SH 1 /* F_RDLCK */ -#define LOCK_EX 2 /* F_WRLCK */ -#define LOCK_NB 4 /* XXX */ -#define LOCK_UN 8 /* F_UNLCK */ +#define LOCK_SH 1 /* F_RDLCK */ +#define LOCK_EX 2 /* F_WRLCK */ +#define LOCK_NB 4 /* XXX */ +#define LOCK_UN 8 /* F_UNLCK */ #ifndef IO_APPEND #define IO_APPEND FAPPEND @@ -106,4 +106,3 @@ extern kmutex_t afs_rxglobal_lock; #endif #endif /* _OSI_MACHDEP_H_ */ - diff --git a/src/afs/SOLARIS/osi_prototypes.h b/src/afs/SOLARIS/osi_prototypes.h index 6219269c0..a4e260958 100644 --- a/src/afs/SOLARIS/osi_prototypes.h +++ b/src/afs/SOLARIS/osi_prototypes.h @@ -10,19 +10,22 @@ #ifndef _OSI_PROTOTYPES_H_ #define _OSI_PROTOTYPES_H_ +/* osi_file.c */ +extern afs_rwlock_t afs_xosi; + /* osi_vnodeops.c */ int afs_putapage(struct vnode *vp, struct page *pages, #if defined(AFS_SUN56_ENV) - u_offset_t *offp, + u_offset_t * offp, #else - u_int *offp, + u_int * offp, #endif #if defined(AFS_SUN58_ENV) - size_t *lenp, + size_t * lenp, #else - u_int *lenp, + u_int * lenp, #endif - int flags, struct AFS_UCRED *credp); + int flags, struct AFS_UCRED *credp); diff --git a/src/afs/SOLARIS/osi_sleep.c b/src/afs/SOLARIS/osi_sleep.c index fd174b1fb..9836d3840 100644 --- a/src/afs/SOLARIS/osi_sleep.c +++ b/src/afs/SOLARIS/osi_sleep.c @@ -8,35 +8,37 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_sleep.c,v 1.1.1.4 2001/07/14 22:19:51 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/SOLARIS/osi_sleep.c,v 1.9 2003/07/15 23:14:26 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ static int osi_TimedSleep(char *event, afs_int32 ams, int aintok); -void afs_osi_Wakeup(char *event); -void afs_osi_Sleep(char *event); static char waitV; -void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) +void +afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle) { AFS_STATCNT(osi_InitWaitHandle); achandle->proc = (caddr_t) 0; } /* cancel osi_Wait */ -void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) { caddr_t proc; AFS_STATCNT(osi_CancelWait); proc = achandle->proc; - if (proc == 0) return; - achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ + if (proc == 0) + return; + achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */ afs_osi_Wakeup(&waitV); } @@ -44,13 +46,14 @@ void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle) * Waits for data on ahandle, or ams ms later. ahandle may be null. * Returns 0 if timeout and EINTR if signalled. */ -int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) +int +afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) { int code; afs_int32 endTime, tid; AFS_STATCNT(osi_Wait); - endTime = osi_Time() + (ams/1000); + endTime = osi_Time() + (ams / 1000); if (ahandle) ahandle->proc = (caddr_t) curthread; do { @@ -58,7 +61,8 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) code = 0; code = osi_TimedSleep(&waitV, ams, aintok); - if (code) break; /* if something happened, quit now */ + if (code) + break; /* if something happened, quit now */ /* if we we're cancelled, quit now */ if (ahandle && (ahandle->proc == (caddr_t) 0)) { /* we've been signalled */ @@ -76,19 +80,20 @@ typedef struct afs_event { char *event; /* lwp event: an address */ int refcount; /* Is it in use? */ int seq; /* Sequence number: this is incremented - by wakeup calls; wait will not return until - it changes */ + * by wakeup calls; wait will not return until + * it changes */ kcondvar_t cond; /* Currently associated condition variable */ } afs_event_t; #define HASHSIZE 128 -afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */ +afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */ #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1)); int afs_evhashcnt = 0; /* Get and initialize event structure corresponding to lwp event (i.e. address) * */ -static afs_event_t *afs_getevent(char *event) +static afs_event_t * +afs_getevent(char *event) { afs_event_t *evp, *newp = 0; int hashcode; @@ -106,7 +111,7 @@ static afs_event_t *afs_getevent(char *event) evp = evp->next; } if (!newp) { - newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t)); + newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t)); afs_evhashcnt++; newp->next = afs_evhasht[hashcode]; afs_evhasht[hashcode] = newp; @@ -122,7 +127,8 @@ static afs_event_t *afs_getevent(char *event) #define relevent(evp) ((evp)->refcount--) -void afs_osi_Sleep(char *event) +void +afs_osi_Sleep(void *event) { struct afs_event *evp; int seq; @@ -136,6 +142,25 @@ void afs_osi_Sleep(char *event) relevent(evp); } +int +afs_osi_SleepSig(void *event) +{ + struct afs_event *evp; + int seq, code = 0; + + evp = afs_getevent(event); + seq = evp->seq; + while (seq == evp->seq) { + AFS_ASSERT_GLOCK(); + if (cv_wait_sig(&evp->cond, &afs_global_lock) == 0) { + code = EINTR; + break; + } + } + relevent(evp); + return code; +} + /* osi_TimedSleep * * Arguments: @@ -145,38 +170,43 @@ void afs_osi_Sleep(char *event) * * Returns 0 if timeout and EINTR if signalled. */ -static int osi_TimedSleep(char *event, afs_int32 ams, int aintok) +static int +osi_TimedSleep(char *event, afs_int32 ams, int aintok) { int code = 0; struct afs_event *evp; clock_t ticks; - ticks = ( ams * afs_hz )/1000; - ticks = ticks + lbolt; + ticks = (ams * afs_hz) / 1000; + ticks = ticks + lbolt; evp = afs_getevent(event); AFS_ASSERT_GLOCK(); if (aintok) { - if (cv_timedwait_sig(&evp->cond, &afs_global_lock, ticks) == -1) + if (cv_timedwait_sig(&evp->cond, &afs_global_lock, ticks) == 0) code = EINTR; } else { cv_timedwait(&evp->cond, &afs_global_lock, ticks); } - + relevent(evp); return code; } -void afs_osi_Wakeup(char *event) +int +afs_osi_Wakeup(void *event) { + int ret = 1; struct afs_event *evp; evp = afs_getevent(event); if (evp->refcount > 1) { - evp->seq++; + evp->seq++; cv_broadcast(&evp->cond); + ret = 0; } relevent(evp); + return 0; } diff --git a/src/afs/SOLARIS/osi_vfsops.c b/src/afs/SOLARIS/osi_vfsops.c index 337eca28b..371241824 100644 --- a/src/afs/SOLARIS/osi_vfsops.c +++ b/src/afs/SOLARIS/osi_vfsops.c @@ -11,15 +11,16 @@ * osi_vfsops.c for SOLARIS */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_vfsops.c,v 1.1.1.11 2003/07/30 17:08:11 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/SOLARIS/osi_vfsops.c,v 1.17 2003/07/15 23:14:26 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics stuff */ -#include "../h/modctl.h" -#include "../h/syscall.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics stuff */ +#include "h/modctl.h" +#include "h/syscall.h" #include @@ -33,7 +34,8 @@ extern struct sysent sysent32[]; int afsfstype = 0; -int afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap, +int +afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap, struct AFS_UCRED *credp) { @@ -47,15 +49,15 @@ int afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap, } afsp->vfs_fstype = afsfstype; - if (afs_globalVFS) { /* Don't allow remounts. */ + if (afs_globalVFS) { /* Don't allow remounts. */ AFS_GUNLOCK(); return EBUSY; } afs_globalVFS = afsp; afsp->vfs_bsize = 8192; - afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ - afsp->vfs_fsid.val[1] = AFS_VFSFSID; + afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ + afsp->vfs_fsid.val[1] = AFS_VFSFSID; afsp->vfs_dev = AFS_VFSMAGIC; AFS_GUNLOCK(); @@ -63,9 +65,11 @@ int afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap, } #if defined(AFS_SUN58_ENV) -int afs_unmount (struct vfs *afsp, int flag, struct AFS_UCRED *credp) +int +afs_unmount(struct vfs *afsp, int flag, struct AFS_UCRED *credp) #else -int afs_unmount (struct vfs *afsp, struct AFS_UCRED *credp) +int +afs_unmount(struct vfs *afsp, struct AFS_UCRED *credp) #endif { AFS_GLOCK(); @@ -82,11 +86,12 @@ int afs_unmount (struct vfs *afsp, struct AFS_UCRED *credp) return 0; } -int afs_root (struct vfs *afsp, struct vnode **avpp) +int +afs_root(struct vfs *afsp, struct vnode **avpp) { register afs_int32 code = 0; struct vrequest treq; - register struct vcache *tvp=0; + register struct vcache *tvp = 0; struct proc *proc = ttoproc(curthread); struct vnode *vp = afsp->vfs_vnodecovered; int locked = 0; @@ -110,10 +115,15 @@ int afs_root (struct vfs *afsp, struct vnode **avpp) locked = 1; mutex_exit(&vp->v_lock); } - if (!(code = afs_InitReq(&treq, proc->p_cred)) && - !(code = afs_CheckInit())) { - tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + afs_globalVp = NULL; + } + + if (!(code = afs_InitReq(&treq, proc->p_cred)) + && !(code = afs_CheckInit())) { + tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); /* we really want this to stay around */ if (tvp) { afs_globalVp = tvp; @@ -148,9 +158,11 @@ int afs_root (struct vfs *afsp, struct vnode **avpp) } #ifdef AFS_SUN56_ENV -int afs_statvfs(struct vfs *afsp, struct statvfs64 *abp) +int +afs_statvfs(struct vfs *afsp, struct statvfs64 *abp) #else -int afs_statvfs(struct vfs *afsp, struct statvfs *abp) +int +afs_statvfs(struct vfs *afsp, struct statvfs *abp) #endif { AFS_GLOCK(); @@ -158,22 +170,24 @@ int afs_statvfs(struct vfs *afsp, struct statvfs *abp) AFS_STATCNT(afs_statfs); abp->f_frsize = 1024; - abp->f_favail = 9000000; + abp->f_favail = 9000000; abp->f_bsize = afsp->vfs_bsize; abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = - abp->f_ffree = 9000000; + abp->f_ffree = 9000000; abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID; AFS_GUNLOCK(); return 0; } -int afs_sync(struct vfs *afsp, short flags, struct AFS_UCRED *credp) +int +afs_sync(struct vfs *afsp, short flags, struct AFS_UCRED *credp) { return 0; } -int afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp) +int +afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp) { cred_t *credp = CRED(); struct vrequest treq; @@ -185,7 +199,7 @@ int afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp) *avcp = NULL; if (!(code = afs_InitReq(&treq, credp))) { - code = afs_osi_vget((struct vcache**)avcp, fidp, &treq); + code = afs_osi_vget((struct vcache **)avcp, fidp, &treq); } afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp, @@ -199,7 +213,7 @@ int afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp) /* This is only called by vfs_mount when afs is going to be mounted as root. * Since we don't support diskless clients we shouldn't come here. */ -int afsmountroot=0; +int afsmountroot = 0; afs_mountroot(struct vfs *afsp, whymountroot_t why) { AFS_GLOCK(); @@ -212,7 +226,7 @@ afs_mountroot(struct vfs *afsp, whymountroot_t why) /* afs_swapvp is called to setup swapping over the net for diskless clients. * Again not for us. */ -int afsswapvp=0; +int afsswapvp = 0; afs_swapvp(struct vfs *afsp, struct vnode **avpp, char *nm) { AFS_GLOCK(); @@ -241,13 +255,13 @@ struct vfsops Afs_vfsops = { /* * afsinit - intialize VFS */ -int (*ufs_iallocp)(); -void (*ufs_iupdatp)(); -int (*ufs_igetp)(); -void (*ufs_itimes_nolockp)(); +int (*ufs_iallocp) (); +void (*ufs_iupdatp) (); +int (*ufs_igetp) (); +void (*ufs_itimes_nolockp) (); -int (*afs_orig_ioctl)(), (*afs_orig_ioctl32)(); -int (*afs_orig_setgroups)(), (*afs_orig_setgroups32)(); +int (*afs_orig_ioctl) (), (*afs_orig_ioctl32) (); +int (*afs_orig_setgroups) (), (*afs_orig_setgroups32) (); struct streamtab *udp_infop = 0; struct ill_s *ill_g_headp = 0; @@ -255,12 +269,12 @@ struct ill_s *ill_g_headp = 0; int afs_sinited = 0; #if !defined(AFS_NONFSTRANS) -int (*nfs_rfsdisptab_v2)(); -int (*nfs_rfsdisptab_v3)(); -int (*nfs_acldisptab_v2)(); -int (*nfs_acldisptab_v3)(); +int (*nfs_rfsdisptab_v2) (); +int (*nfs_rfsdisptab_v3) (); +int (*nfs_acldisptab_v2) (); +int (*nfs_acldisptab_v3) (); -int (*nfs_checkauth)(); +int (*nfs_checkauth) (); #endif extern Afs_syscall(); @@ -289,45 +303,44 @@ afsinit(struct vfssw *vfsswp, int fstype) #if !defined(AFS_NONFSTRANS) - nfs_rfsdisptab_v2 = (int (*)()) modlookup("nfssrv", "rfsdisptab_v2"); - if ( !nfs_rfsdisptab_v2 ) { + nfs_rfsdisptab_v2 = (int (*)())modlookup("nfssrv", "rfsdisptab_v2"); + if (!nfs_rfsdisptab_v2) { afs_warn("warning : rfsdisptab_v2 NOT FOUND\n"); } if (nfs_rfsdisptab_v2) { - nfs_acldisptab_v2 = (int (*)()) modlookup("nfssrv", "acldisptab_v2"); - if ( !nfs_acldisptab_v2 ) { + nfs_acldisptab_v2 = (int (*)())modlookup("nfssrv", "acldisptab_v2"); + if (!nfs_acldisptab_v2) { afs_warn("warning : acldisptab_v2 NOT FOUND\n"); - } - else { + } else { afs_xlatorinit_v2(nfs_rfsdisptab_v2, nfs_acldisptab_v2); } } - nfs_rfsdisptab_v3 = (int (*)()) modlookup("nfssrv", "rfsdisptab_v3"); - if ( !nfs_rfsdisptab_v3 ) { + nfs_rfsdisptab_v3 = (int (*)())modlookup("nfssrv", "rfsdisptab_v3"); + if (!nfs_rfsdisptab_v3) { afs_warn("warning : rfsdisptab_v3 NOT FOUND\n"); } if (nfs_rfsdisptab_v3) { - nfs_acldisptab_v3 = (int (*)()) modlookup("nfssrv", "acldisptab_v3"); - if ( !nfs_acldisptab_v3 ) { + nfs_acldisptab_v3 = (int (*)())modlookup("nfssrv", "acldisptab_v3"); + if (!nfs_acldisptab_v3) { afs_warn("warning : acldisptab_v3 NOT FOUND\n"); - } - else { + } else { afs_xlatorinit_v3(nfs_rfsdisptab_v3, nfs_acldisptab_v3); } } - nfs_checkauth = (int (*)()) modlookup("nfssrv", "checkauth"); - if ( !nfs_checkauth ) afs_warn("nfs_checkauth not initialised"); + nfs_checkauth = (int (*)())modlookup("nfssrv", "checkauth"); + if (!nfs_checkauth) + afs_warn("nfs_checkauth not initialised"); #endif - ufs_iallocp = (int (*)()) modlookup("ufs", "ufs_ialloc"); - ufs_iupdatp = (void (*)()) modlookup("ufs", "ufs_iupdat"); - ufs_igetp = (int (*)()) modlookup("ufs", "ufs_iget"); - ufs_itimes_nolockp = (void (*)()) modlookup("ufs", "ufs_itimes_nolock"); - udp_infop = (struct streamtab *) modlookup("udp", "udpinfo"); - ill_g_headp = (struct ill_s *) modlookup("ip", "ill_g_head"); - - if ( !ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp || - !ufs_igetp || !udp_infop || !ill_g_headp ) + ufs_iallocp = (int (*)())modlookup("ufs", "ufs_ialloc"); + ufs_iupdatp = (void (*)())modlookup("ufs", "ufs_iupdat"); + ufs_igetp = (int (*)())modlookup("ufs", "ufs_iget"); + ufs_itimes_nolockp = (void (*)())modlookup("ufs", "ufs_itimes_nolock"); + udp_infop = (struct streamtab *)modlookup("udp", "udpinfo"); + ill_g_headp = (struct ill_s *)modlookup("ip", "ill_g_head"); + + if (!ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp || !ufs_igetp + || !udp_infop || !ill_g_headp) afs_warn("AFS to UFS mapping cannot be fully initialised\n"); afs_sinited = 1; @@ -340,13 +353,13 @@ static struct vfssw afs_vfw = { afsinit, &Afs_vfsops, 0 - }; +}; static struct sysent afssysent = { 6, 0, Afs_syscall - }; +}; /* inter-module dependencies */ char _depends_on[] = "drv/ip drv/udp strmod/rpcmod"; @@ -361,13 +374,13 @@ static struct modlfs afsmodlfs = { &mod_fsops, "afs filesystem", &afs_vfw - }; +}; static struct modlsys afsmodlsys = { &mod_syscallops, "afs syscall interface", &afssysent - }; +}; /** The two structures afssysent32 and afsmodlsys32 are being added * for supporting 32 bit syscalls. In Solaris 7 there are two system @@ -397,7 +410,7 @@ static struct modlinkage afs_modlinkage = { #endif (void *)&afsmodlfs, NULL - }; +}; /** This is the function that modload calls when loading the afs kernel * extensions. The solaris modload program searches for the _init @@ -415,29 +428,38 @@ _init() if (afs_sinited) return EBUSY; - if ((!(mp = mod_find_by_filename("fs", "ufs")) && - !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs")) && - !(mp = mod_find_by_filename(NULL, "sys/ufs"))) || - (mp && !mp->mod_installed)) { - printf("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n"); + if ((!(mp = mod_find_by_filename("fs", "ufs")) + && !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs")) + && !(mp = mod_find_by_filename(NULL, "sys/ufs"))) || (mp + && !mp-> + mod_installed)) + { + printf + ("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n"); return (ENOSYS); } #ifndef AFS_NONFSTRANS #if defined(AFS_SUN55_ENV) - if ((!(mp = mod_find_by_filename("misc", "nfssrv")) && - !(mp = mod_find_by_filename(NULL, NFSSRV)) && - !(mp = mod_find_by_filename(NULL, NFSSRV_V9))) || - (mp && !mp->mod_installed)) { - printf("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n"); - return (ENOSYS); + if ((!(mp = mod_find_by_filename("misc", "nfssrv")) + && !(mp = mod_find_by_filename(NULL, NFSSRV)) + && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))) || (mp + && !mp-> + mod_installed)) + { + printf + ("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n"); + return (ENOSYS); } #else /* !AFS_SUN55_ENV */ #if defined(AFS_SUN52_ENV) - if ((!(mp = mod_find_by_filename("fs", "nfs")) && - !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs")) && - !(mp = mod_find_by_filename(NULL, "sys/nfs"))) || - (mp && !mp->mod_installed)) { - printf("fs/nfs module must be loaded before loading afs with nfs-xlator\n"); + if ((!(mp = mod_find_by_filename("fs", "nfs")) + && !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs")) + && !(mp = mod_find_by_filename(NULL, "sys/nfs"))) || (mp + && !mp-> + mod_installed)) + { + printf + ("fs/nfs module must be loaded before loading afs with nfs-xlator\n"); return (ENOSYS); } #endif /* AFS_SUN52_ENV */ @@ -466,25 +488,25 @@ _init() if (sysent[AFS_SYSCALL].sy_call == nosys) { if ((sysn = mod_getsysname(AFS_SYSCALL)) != NULL) { sysent[AFS_SYSCALL].sy_lock = - (krwlock_t *) kobj_zalloc(sizeof (krwlock_t), KM_SLEEP); + (krwlock_t *) kobj_zalloc(sizeof(krwlock_t), KM_SLEEP); rw_init(sysent[AFS_SYSCALL].sy_lock, "afs_syscall", #ifdef AFS_SUN57_ENV RW_DEFAULT, NULL); #else /* !AFS_SUN57_ENV */ - RW_DEFAULT, DEFAULT_WT); + RW_DEFAULT, DEFAULT_WT); #endif /* AFS_SUN57_ENV */ } } #endif /* !AFS_SUN58_ENV */ - osi_Init(); /* initialize global lock, etc */ + osi_Init(); /* initialize global lock, etc */ code = mod_install(&afs_modlinkage); return code; } _info(modp) - struct modinfo *modp; + struct modinfo *modp; { int code; diff --git a/src/afs/SOLARIS/osi_vm.c b/src/afs/SOLARIS/osi_vm.c index 4817ab43f..691c8951a 100644 --- a/src/afs/SOLARIS/osi_vm.c +++ b/src/afs/SOLARIS/osi_vm.c @@ -8,14 +8,15 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_vm.c,v 1.1.1.5 2002/05/10 23:44:14 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/SOLARIS/osi_vm.c,v 1.8 2003/07/15 23:14:26 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/nfsclient.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/nfsclient.h" #if defined(AFS_SUN5_ENV) /* This file contains Solaris VM-related code for the cache manager. */ @@ -43,17 +44,14 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_vm.c,v 1.1.1.5 2002/05/ * Locking: only the global lock is held on entry. */ int -osi_VM_GetDownD(avc, adc) - struct vcache *avc; - struct dcache *adc; +osi_VM_GetDownD(struct vcache *avc, struct dcache *adc) { int code; AFS_GUNLOCK(); - code = afs_putpage(AFSTOV(avc), - (offset_t) AFS_CHUNKTOBASE(adc->f.chunk), - AFS_CHUNKTOSIZE(adc->f.chunk), - B_INVAL, CRED()); + code = + afs_putpage(AFSTOV(avc), (offset_t) AFS_CHUNKTOBASE(adc->f.chunk), + AFS_CHUNKTOSIZE(adc->f.chunk), B_INVAL, CRED()); AFS_GLOCK(); return code; @@ -74,9 +72,7 @@ osi_VM_GetDownD(avc, adc) * therefore obsolescent. */ int -osi_VM_FlushVCache(avc, slept) - struct vcache *avc; - int *slept; +osi_VM_FlushVCache(struct vcache *avc, int *slept) { if (avc->vrefCount != 0) return EBUSY; @@ -91,12 +87,12 @@ osi_VM_FlushVCache(avc, slept) return EBUSY; AFS_GUNLOCK(); - pvn_vplist_dirty(AFSTOV(avc), 0, NULL, B_TRUNC|B_INVAL, CRED()); + pvn_vplist_dirty(AFSTOV(avc), 0, NULL, B_TRUNC | B_INVAL, CRED()); AFS_GLOCK(); /* Might as well make the obvious check */ if (AFSTOV(avc)->v_pages) - return EBUSY; /* should be all gone still */ + return EBUSY; /* should be all gone still */ rw_destroy(&avc->rwlock); if (avc->credp) { @@ -114,15 +110,14 @@ osi_VM_FlushVCache(avc, slept) * re-obtained. */ void -osi_VM_StoreAllSegments(avc) - struct vcache *avc; +osi_VM_StoreAllSegments(struct vcache *avc) { AFS_GUNLOCK(); #if defined(AFS_SUN56_ENV) - (void) pvn_vplist_dirty(AFSTOV(avc), (u_offset_t)0, afs_putapage, - 0, CRED()); + (void)pvn_vplist_dirty(AFSTOV(avc), (u_offset_t) 0, afs_putapage, 0, + CRED()); #else - (void) pvn_vplist_dirty(AFSTOV(avc), 0, afs_putapage, 0, CRED()); + (void)pvn_vplist_dirty(AFSTOV(avc), 0, afs_putapage, 0, CRED()); #endif AFS_GLOCK(); } @@ -134,18 +129,15 @@ osi_VM_StoreAllSegments(avc) * re-obtained. */ void -osi_VM_TryToSmush(avc, acred, sync) - struct vcache *avc; - struct AFS_UCRED *acred; - int sync; +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { AFS_GUNLOCK(); #if defined(AFS_SUN56_ENV) - (void) pvn_vplist_dirty(AFSTOV(avc), (u_offset_t)0, afs_putapage, - (sync ? B_INVAL : B_FREE), acred); + (void)pvn_vplist_dirty(AFSTOV(avc), (u_offset_t) 0, afs_putapage, + (sync ? B_INVAL : B_FREE), acred); #else - (void) pvn_vplist_dirty(AFSTOV(avc), 0, afs_putapage, - (sync ? B_INVAL : B_FREE), acred); + (void)pvn_vplist_dirty(AFSTOV(avc), 0, afs_putapage, + (sync ? B_INVAL : B_FREE), acred); #endif AFS_GLOCK(); } @@ -155,15 +147,12 @@ osi_VM_TryToSmush(avc, acred, sync) * Locking: No lock is held, not even the global lock. */ void -osi_VM_FlushPages(avc, credp) - struct vcache *avc; - struct AFS_UCRED *credp; +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { extern int afs_pvn_vptrunc; afs_pvn_vptrunc++; - (void) afs_putpage(AFSTOV(avc), (offset_t)0, 0, - B_TRUNC|B_INVAL, credp); + (void)afs_putpage(AFSTOV(avc), (offset_t) 0, 0, B_TRUNC | B_INVAL, credp); } /* Zero no-longer-used part of last page, when truncating a file @@ -175,10 +164,7 @@ osi_VM_FlushPages(avc, credp) * be called first, since it causes a pagein. */ void -osi_VM_PreTruncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +osi_VM_PreTruncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { page_t *pp; int pageOffset = (alen & PAGEOFFSET); @@ -195,7 +181,7 @@ osi_VM_PreTruncate(avc, alen, acred) page_unlock(pp); } AFS_GLOCK(); - ObtainWriteLock(&avc->lock,563); + ObtainWriteLock(&avc->lock, 563); } /* Purge pages beyond end-of-file, when truncating a file. @@ -204,16 +190,13 @@ osi_VM_PreTruncate(avc, alen, acred) * Pageins are blocked (activeV is raised). */ void -osi_VM_Truncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { /* * It's OK to specify afs_putapage here, even though we aren't holding * the vcache entry lock, because it isn't going to get called. */ - pvn_vplist_dirty(AFSTOV(avc), alen, afs_putapage, B_TRUNC|B_INVAL, + pvn_vplist_dirty(AFSTOV(avc), alen, afs_putapage, B_TRUNC | B_INVAL, acred); } diff --git a/src/afs/SOLARIS/osi_vnodeops.c b/src/afs/SOLARIS/osi_vnodeops.c index d06ca8284..752e92b3f 100644 --- a/src/afs/SOLARIS/osi_vnodeops.c +++ b/src/afs/SOLARIS/osi_vnodeops.c @@ -8,9 +8,10 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_vnodeops.c,v 1.1.1.11 2002/12/11 02:36:21 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/SOLARIS/osi_vnodeops.c,v 1.19 2003/07/15 23:14:26 shadow Exp $"); #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV) /* @@ -32,10 +33,10 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_vnodeops.c,v 1.1.1.11 2 * Variables: Afs_vnodeops * */ -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/nfsclient.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/nfsclient.h" #include @@ -47,7 +48,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/SOLARIS/osi_vnodeops.c,v 1.1.1.11 2 #include #include #include -#if defined(AFS_SUN5_ENV) +#if defined(AFS_SUN5_ENV) #include #include #else @@ -100,9 +101,9 @@ afs_fc2errno(faultcode_t fc) } -extern struct as kas; /* kernel addr space */ -extern unsigned char *afs_indexFlags; -extern afs_lock_t afs_xdcache; +extern struct as kas; /* kernel addr space */ +extern unsigned char *afs_indexFlags; +extern afs_lock_t afs_xdcache; /* Additional vnodeops for SunOS 4.0.x */ int afs_nfsrdwr(), afs_getpage(), afs_putpage(), afs_map(); @@ -112,35 +113,38 @@ int afs_pvn_vptrunc; #ifdef AFS_SUN5_ENV -int afs_addmap(avp, offset, asp, addr, length, prot, maxprot, flags, credp) - register struct vnode *avp; - offset_t offset; - struct as *asp; - caddr_t addr; - int length, prot, maxprot, flags; - struct AFS_UCRED *credp; +int +afs_addmap(avp, offset, asp, addr, length, prot, maxprot, flags, credp) + register struct vnode *avp; + offset_t offset; + struct as *asp; + caddr_t addr; + int length, prot, maxprot, flags; + struct AFS_UCRED *credp; { /* XXX What should we do here?? XXX */ return (0); } -int afs_delmap(avp, offset, asp, addr, length, prot, maxprot, flags, credp) - register struct vnode *avp; - offset_t offset; - struct as *asp; - caddr_t addr; - int length, prot, maxprot, flags; - struct AFS_UCRED *credp; +int +afs_delmap(avp, offset, asp, addr, length, prot, maxprot, flags, credp) + register struct vnode *avp; + offset_t offset; + struct as *asp; + caddr_t addr; + int length, prot, maxprot, flags; + struct AFS_UCRED *credp; { /* XXX What should we do here?? XXX */ return (0); } -int afs_vmread(avp, auio, ioflag, acred) - register struct vnode *avp; - struct uio *auio; - int ioflag; - struct AFS_UCRED *acred; +int +afs_vmread(avp, auio, ioflag, acred) + register struct vnode *avp; + struct uio *auio; + int ioflag; + struct AFS_UCRED *acred; { register int code; @@ -153,11 +157,12 @@ int afs_vmread(avp, auio, ioflag, acred) } -int afs_vmwrite(avp, auio, ioflag, acred) - register struct vnode *avp; - struct uio *auio; - int ioflag; - struct AFS_UCRED *acred; +int +afs_vmwrite(avp, auio, ioflag, acred) + register struct vnode *avp; + struct uio *auio; + int ioflag; + struct AFS_UCRED *acred; { register int code; @@ -169,31 +174,29 @@ int afs_vmwrite(avp, auio, ioflag, acred) return code; } -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ -int afs_getpage(vp, off, len, protp, pl, plsz, seg, addr, rw, acred) -struct vnode *vp; -u_int len; -u_int *protp; -struct page *pl[]; -u_int plsz; -struct seg *seg; +int +afs_getpage(vp, off, len, protp, pl, plsz, seg, addr, rw, acred) + struct vnode *vp; + u_int len; + u_int *protp; + struct page *pl[]; + u_int plsz; + struct seg *seg; #ifdef AFS_SUN5_ENV -offset_t off; -caddr_t addr; + offset_t off; + caddr_t addr; #else -u_int off; -addr_t addr; + u_int off; + addr_t addr; #endif -enum seg_rw rw; -struct AFS_UCRED *acred; + enum seg_rw rw; + struct AFS_UCRED *acred; { register afs_int32 code = 0; -#if defined(AFS_SUN56_ENV) - u_offset_t toff = (u_offset_t)off; -#endif - AFS_STATCNT(afs_getpage); + #ifdef AFS_SUN5_ENV if (vp->v_flag & VNOMAP) /* File doesn't allow mapping */ return (ENOSYS); @@ -203,17 +206,18 @@ struct AFS_UCRED *acred; #if defined(AFS_SUN56_ENV) if (len <= PAGESIZE) - code = afs_GetOnePage(vp, toff, len, protp, pl, plsz, - seg, addr, rw, acred); + code = + afs_GetOnePage(vp, off, len, protp, pl, plsz, seg, addr, rw, + acred); #else #ifdef AFS_SUN5_ENV if (len <= PAGESIZE) - code = afs_GetOnePage(vp, (u_int)off, len, protp, pl, plsz, - seg, addr, rw, acred); + code = + afs_GetOnePage(vp, (u_int) off, len, protp, pl, plsz, seg, addr, + rw, acred); #else if (len == PAGESIZE) - code = afs_GetOnePage(vp, off, protp, pl, plsz, - seg, addr, rw, acred); + code = afs_GetOnePage(vp, off, protp, pl, plsz, seg, addr, rw, acred); #endif #endif else { @@ -225,11 +229,13 @@ struct AFS_UCRED *acred; #endif afs_BozonLock(&vcp->pvnLock, vcp); #if defined(AFS_SUN56_ENV) - code = pvn_getpages(afs_GetOnePage, vp, toff, - len, protp, pl, plsz, seg, addr, rw, acred); + code = + pvn_getpages(afs_GetOnePage, vp, off, len, protp, pl, plsz, seg, + addr, rw, acred); #else - code = pvn_getpages(afs_GetOnePage, vp, (u_int)off, - len, protp, pl, plsz, seg, addr, rw, acred); + code = + pvn_getpages(afs_GetOnePage, vp, (u_int) off, len, protp, pl, + plsz, seg, addr, rw, acred); #endif afs_BozonUnlock(&vcp->pvnLock, vcp); #ifdef AFS_SUN5_ENV @@ -244,28 +250,30 @@ struct AFS_UCRED *acred; /* Return all the pages from [off..off+len) in file */ #ifdef AFS_SUN5_ENV -int afs_GetOnePage(vp, off, alen, protp, pl, plsz, seg, addr, rw, acred) -u_int alen; +int +afs_GetOnePage(vp, off, alen, protp, pl, plsz, seg, addr, rw, acred) + u_int alen; #else -int afs_GetOnePage(vp, off, protp, pl, plsz, seg, addr, rw, acred) +int +afs_GetOnePage(vp, off, protp, pl, plsz, seg, addr, rw, acred) #endif -struct vnode *vp; + struct vnode *vp; #if defined(AFS_SUN56_ENV) -u_offset_t off; + u_offset_t off; #else -u_int off; + u_int off; #endif -u_int *protp; -struct page *pl[]; -u_int plsz; -struct seg *seg; + u_int *protp; + struct page *pl[]; + u_int plsz; + struct seg *seg; #ifdef AFS_SUN5_ENV -caddr_t addr; + caddr_t addr; #else -addr_t addr; + addr_t addr; #endif -enum seg_rw rw; -struct AFS_UCRED *acred; + enum seg_rw rw; + struct AFS_UCRED *acred; { register struct page *page; register afs_int32 code = 0; @@ -275,49 +283,93 @@ struct AFS_UCRED *acred; register struct vcache *avc; register struct dcache *tdc; int i, s, pexists; - int slot, offset, nlen; + int slot; + afs_size_t offset, nlen; struct vrequest treq; - afs_int32 mapForRead = 0, Code=0; + afs_int32 mapForRead = 0, Code = 0; #if defined(AFS_SUN56_ENV) - u_offset_t toffset; + u_offset_t toffset; #else - afs_int32 toffset; + afs_int32 toffset; #endif - if (!acred) + if (!acred) #ifdef AFS_SUN5_ENV osi_Panic("GetOnePage: !acred"); #else - acred = u.u_cred; /* better than nothing */ + acred = u.u_cred; /* better than nothing */ #endif - avc = VTOAFS(vp); /* cast to afs vnode */ + avc = VTOAFS(vp); /* cast to afs vnode */ #ifdef AFS_SUN5_ENV - if (avc->credp /*&& AFS_NFSXLATORREQ(acred)*/ && AFS_NFSXLATORREQ(avc->credp)) { + if (avc->credp /*&& AFS_NFSXLATORREQ(acred) */ + && AFS_NFSXLATORREQ(avc->credp)) { acred = avc->credp; } #endif - if (code = afs_InitReq(&treq, acred)) return code; + if (code = afs_InitReq(&treq, acred)) + return code; if (!pl) { - /* - * This is a read-ahead request, e.g. due to madvise. - */ - tdc = afs_GetDCache(avc, (afs_int32)off, &treq, &offset, &nlen, 1); - if (!tdc) return 0; + /* This is a read-ahead request, e.g. due to madvise. */ +#ifdef AFS_SUN5_ENV + int plen = alen; +#else + int plen = PAGESIZE; +#endif + ObtainReadLock(&avc->lock); - if (!(tdc->flags & DFNextStarted)) { - ObtainReadLock(&avc->lock); - afs_PrefetchChunk(avc, tdc, acred, &treq); - ReleaseReadLock(&avc->lock); + while (plen > 0 && !afs_BBusy()) { + /* Obtain a dcache entry at off. 2 means don't fetch data. */ + tdc = + afs_GetDCache(avc, (afs_offs_t) off, &treq, &offset, &nlen, + 2); + if (!tdc) + break; + + /* Write-lock the dcache entry, if we don't succeed, just go on */ + if (0 != NBObtainWriteLock(&tdc->lock, 642)) { + afs_PutDCache(tdc); + goto next_prefetch; + } + + /* If we aren't already fetching this dcache entry, queue it */ + if (!(tdc->mflags & DFFetchReq)) { + struct brequest *bp; + + tdc->mflags |= DFFetchReq; + bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred, + (afs_size_t) off, (afs_size_t) 1, tdc); + if (!bp) { + /* Unable to start background fetch; might as well stop */ + tdc->mflags &= ~DFFetchReq; + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); + break; + } + ReleaseWriteLock(&tdc->lock); + } else { + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); + } + + next_prefetch: + /* Adjust our offset and remaining length values */ + off += nlen; + plen -= nlen; + + /* If we aren't making progress for some reason, bail out */ + if (nlen <= 0) + break; } - afs_PutDCache(tdc); + + ReleaseReadLock(&avc->lock); return 0; } len = PAGESIZE; - pl[0] = NULL; /* Make sure it's empty */ + pl[0] = NULL; /* Make sure it's empty */ /* first, obtain the proper lock for the VM system */ @@ -328,42 +380,46 @@ struct AFS_UCRED *acred; * pages for the range covered by a chunk when we swap out the * chunk. */ - if (rw == S_READ || rw == S_EXEC) + if (rw == S_READ || rw == S_EXEC) mapForRead = 1; - if (protp) *protp = PROT_ALL; + if (protp) + *protp = PROT_ALL; #ifndef AFS_SUN5_ENV if (AFS_NFSXLATORREQ(acred)) { if (rw == S_READ) { - if (!afs_AccessOK(avc, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) { + if (!afs_AccessOK + (avc, PRSFS_READ, &treq, + CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) { return EACCES; } } } #endif -retry: + + retry: #ifdef AFS_SUN5_ENV if (rw == S_WRITE || rw == S_CREATE) - tdc = afs_GetDCache(avc, (afs_int32)off, &treq, &offset, &nlen, 5); + tdc = afs_GetDCache(avc, (afs_offs_t) off, &treq, &offset, &nlen, 5); else - tdc = afs_GetDCache(avc, (afs_int32)off, &treq, &offset, &nlen, 1); - if (!tdc) return EINVAL; + tdc = afs_GetDCache(avc, (afs_offs_t) off, &treq, &offset, &nlen, 1); + if (!tdc) + return EINVAL; #endif code = afs_VerifyVCache(avc, &treq); if (code) { #ifdef AFS_SUN5_ENV afs_PutDCache(tdc); -#endif - return afs_CheckCode(code, &treq, 44); /* failed to get it */ +#endif + return afs_CheckCode(code, &treq, 44); /* failed to get it */ } afs_BozonLock(&avc->pvnLock, avc); ObtainReadLock(&avc->lock); afs_Trace4(afs_iclSetp, CM_TRACE_PAGEIN, ICL_TYPE_POINTER, (afs_int32) vp, - ICL_TYPE_LONG, (afs_int32) off, ICL_TYPE_LONG, (afs_int32) len, - ICL_TYPE_LONG, (int) rw); + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(off), ICL_TYPE_LONG, len, + ICL_TYPE_LONG, (int)rw); tlen = len; slot = 0; @@ -373,10 +429,10 @@ retry: * the locks and try again when the VM purge is done. */ ObtainWriteLock(&avc->vlock, 550); if (avc->activeV) { - ReleaseReadLock(&avc->lock); - ReleaseWriteLock(&avc->vlock); + ReleaseReadLock(&avc->lock); + ReleaseWriteLock(&avc->vlock); afs_BozonUnlock(&avc->pvnLock, avc); - afs_PutDCache(tdc); + afs_PutDCache(tdc); /* Check activeV again, it may have been turned off * while we were waiting for a lock in afs_PutDCache */ ObtainWriteLock(&avc->vlock, 574); @@ -389,28 +445,33 @@ retry: } goto retry; } - ReleaseWriteLock(&avc->vlock); + ReleaseWriteLock(&avc->vlock); #endif + /* We're about to do stuff with our dcache entry.. Lock it. */ + ObtainReadLock(&tdc->lock); + /* Check to see whether the cache entry is still valid */ if (!(avc->states & CStatd) || !hsame(avc->m.DataVersion, tdc->f.versionNo)) { - ReleaseReadLock(&avc->lock); + ReleaseReadLock(&tdc->lock); + ReleaseReadLock(&avc->lock); afs_BozonUnlock(&avc->pvnLock, avc); afs_PutDCache(tdc); goto retry; } AFS_GUNLOCK(); - while (1) { /* loop over all pages */ + while (1) { /* loop over all pages */ /* now, try to find the page in memory (it may already be intransit or laying - around the free list */ - page = page_lookup( vp, toffset, (rw == S_CREATE ? SE_EXCL : SE_SHARED) ); - if (page) + * around the free list */ + page = + page_lookup(vp, toffset, (rw == S_CREATE ? SE_EXCL : SE_SHARED)); + if (page) goto nextpage; /* if we make it here, we can't find the page in memory. Do a real disk read - from the cache to get the data */ + * from the cache to get the data */ Code |= 0x200; /* XXX */ #ifdef AFS_SUN5_ENV #if defined(AFS_SUN54_ENV) @@ -420,9 +481,13 @@ retry: * in case someone tries to relax all the serialization of read and write * operations with harmless things like stat. */ #if defined(AFS_SUN58_ENV) - page = page_create_va(vp, toffset, PAGESIZE, PG_WAIT|PG_EXCL, seg, addr); + page = + page_create_va(vp, toffset, PAGESIZE, PG_WAIT | PG_EXCL, seg, + addr); #else - page = page_create_va(vp, toffset, PAGESIZE, PG_WAIT|PG_EXCL, seg->s_as, addr); + page = + page_create_va(vp, toffset, PAGESIZE, PG_WAIT | PG_EXCL, + seg->s_as, addr); #endif #else page = page_create(vp, toffset, PAGESIZE, PG_WAIT); @@ -431,37 +496,40 @@ retry: continue; } if (alen < PAGESIZE) - pagezero(page, alen, PAGESIZE-alen); + pagezero(page, alen, PAGESIZE - alen); #else page = rm_allocpage(seg, addr, PAGESIZE, 1); /* can't fail */ - if (!page) osi_Panic("afs_getpage alloc page"); + if (!page) + osi_Panic("afs_getpage alloc page"); /* we get a circularly-linked list of pages back, but we expect only - one, since that's what we asked for */ - if (page->p_next != page) osi_Panic("afs_getpage list"); + * one, since that's what we asked for */ + if (page->p_next != page) + osi_Panic("afs_getpage list"); /* page enter returns a locked page; we'll drop the lock as a side-effect - of the pvn_done done by afs_ustrategy. If we decide not to call - strategy, we must be sure to call pvn_fail, at least, to release the - page locks and otherwise reset the pages. The page, while locked, is - not held, for what it is worth */ + * of the pvn_done done by afs_ustrategy. If we decide not to call + * strategy, we must be sure to call pvn_fail, at least, to release the + * page locks and otherwise reset the pages. The page, while locked, is + * not held, for what it is worth */ page->p_intrans = 1; /* set appropriate flags */ page->p_pagein = 1; /* next call shouldn't fail, since we have pvnLock set */ - if (page_enter(page, vp, toffset)) osi_Panic("afs_getpage enter race"); -#endif /* AFS_SUN5_ENV */ + if (page_enter(page, vp, toffset)) + osi_Panic("afs_getpage enter race"); +#endif /* AFS_SUN5_ENV */ #ifdef AFS_SUN5_ENV - if (rw == S_CREATE) { + if (rw == S_CREATE) { /* XXX Don't read from AFS in write only cases XXX */ page_io_unlock(page); - } else + } else #else if (0) { /* XXX Don't read from AFS in write only cases XXX */ page->p_intrans = page->p_pagein = 0; page_unlock(page); /* XXX */ - } else + } else #endif - { + { #ifndef AFS_SUN5_ENV PAGE_HOLD(page); #endif @@ -472,20 +540,23 @@ retry: #endif buf->b_dev = 0; buf->b_blkno = btodb(toffset); - bp_mapin(buf); /* map it in to our address space */ -#ifndef AFS_SUN5_ENV - ReleaseReadLock(&avc->lock); -#endif + bp_mapin(buf); /* map it in to our address space */ + #if defined(AFS_SUN5_ENV) AFS_GLOCK(); + /* afs_ustrategy will want to lock the dcache entry */ + ReleaseReadLock(&tdc->lock); code = afs_ustrategy(buf, acred); /* do the I/O */ + ObtainReadLock(&tdc->lock); AFS_GUNLOCK(); #else + ReleaseReadLock(&tdc->lock); + ReleaseReadLock(&avc->lock); code = afs_ustrategy(buf); /* do the I/O */ -#endif -#ifndef AFS_SUN5_ENV ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); #endif + #ifdef AFS_SUN5_ENV /* Before freeing unmap the buffer */ bp_mapout(buf); @@ -508,9 +579,9 @@ retry: #ifdef AFS_SUN5_ENV /* The p_selock must be downgraded to a shared lock after the page is read */ #if defined(AFS_SUN56_ENV) - if ((rw != S_CREATE) && !(PAGE_SHARED(page))) + if ((rw != S_CREATE) && !(PAGE_SHARED(page))) #else - if ((rw != S_CREATE) && !(se_shared_assert(&page->p_selock))) + if ((rw != S_CREATE) && !(se_shared_assert(&page->p_selock))) #endif { page_downgrade(page); @@ -524,20 +595,23 @@ retry: toffset += PAGESIZE; addr += PAGESIZE; tlen -= PAGESIZE; - if (tlen <= 0) break; /* done all the pages */ - } /* while (1) ... */ + if (tlen <= 0) + break; /* done all the pages */ + } /* while (1) ... */ AFS_GLOCK(); - pl[slot] = (struct page *) 0; - /* - * XXX This seems kind-of wrong: we shouldn't be modifying - * avc->states while not holding the write lock (even - * though nothing really uses CHasPages..) - */ - avc->states |= CHasPages; + pl[slot] = NULL; + ReleaseReadLock(&tdc->lock); + + /* Prefetch next chunk if we're at a chunk boundary */ + if (AFS_CHUNKOFFSET(off) == 0) { + if (!(tdc->mflags & DFNextStarted)) + afs_PrefetchChunk(avc, tdc, acred, &treq); + } + ReleaseReadLock(&avc->lock); #ifdef AFS_SUN5_ENV - ObtainWriteLock(&afs_xdcache,246); + ObtainWriteLock(&afs_xdcache, 246); if (!mapForRead) { /* track that we have dirty (or dirty-able) pages for this chunk. */ afs_indexFlags[tdc->index] |= IFDirtyPages; @@ -549,37 +623,39 @@ retry: #ifdef AFS_SUN5_ENV afs_PutDCache(tdc); #endif - afs_Trace3(afs_iclSetp, CM_TRACE_PAGEINDONE, ICL_TYPE_LONG, code, ICL_TYPE_LONG, (int)page, - ICL_TYPE_LONG, Code); + afs_Trace3(afs_iclSetp, CM_TRACE_PAGEINDONE, ICL_TYPE_LONG, code, + ICL_TYPE_LONG, (int)page, ICL_TYPE_LONG, Code); return 0; bad: AFS_GLOCK(); - afs_Trace3(afs_iclSetp, CM_TRACE_PAGEINDONE, ICL_TYPE_LONG, code, ICL_TYPE_LONG, (int)page, - ICL_TYPE_LONG, Code); + afs_Trace3(afs_iclSetp, CM_TRACE_PAGEINDONE, ICL_TYPE_LONG, code, + ICL_TYPE_LONG, (int)page, ICL_TYPE_LONG, Code); /* release all pages, drop locks, return code */ #ifdef AFS_SUN5_ENV - if (page) + if (page) pvn_read_done(page, B_ERROR); #else - for(i=0; ilock); afs_BozonUnlock(&avc->pvnLock, avc); #ifdef AFS_SUN5_ENV + ReleaseReadLock(&tdc->lock); afs_PutDCache(tdc); #endif return code; } #ifdef AFS_SUN5_ENV -int afs_putpage(vp, off, len, flags, cred) - struct vnode *vp; - offset_t off; - u_int len; - int flags; - struct AFS_UCRED *cred; +int +afs_putpage(vp, off, len, flags, cred) + struct vnode *vp; + offset_t off; + u_int len; + int flags; + struct AFS_UCRED *cred; { struct vcache *avc; struct page *pages; @@ -589,43 +665,53 @@ int afs_putpage(vp, off, len, flags, cred) #else afs_int32 tlen; #endif - afs_int32 endPos, NPages=0; + afs_offs_t endPos; + afs_int32 NPages = 0; #if defined(AFS_SUN56_ENV) u_offset_t toff = off; #else int toff = (int)off; #endif + int didWriteLock; AFS_STATCNT(afs_putpage); - if (vp->v_flag & VNOMAP) /* file doesn't allow mapping */ + if (vp->v_flag & VNOMAP) /* file doesn't allow mapping */ return (ENOSYS); /* * Putpage (ASYNC) is called every sec to flush out dirty vm pages */ AFS_GLOCK(); - afs_Trace4(afs_iclSetp, CM_TRACE_PAGEOUT, ICL_TYPE_POINTER, (afs_int32) vp, - ICL_TYPE_LONG, (afs_int32) off, ICL_TYPE_LONG, (afs_int32) len, - ICL_TYPE_LONG, (int) flags); + afs_Trace4(afs_iclSetp, CM_TRACE_PAGEOUT, ICL_TYPE_POINTER, + (afs_int32) vp, ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(off), + ICL_TYPE_INT32, (afs_int32) len, ICL_TYPE_LONG, (int)flags); avc = VTOAFS(vp); afs_BozonLock(&avc->pvnLock, avc); - ObtainWriteLock(&avc->lock,247); + ObtainSharedLock(&avc->lock, 247); + didWriteLock = 0; /* Get a list of modified (or whatever) pages */ if (len) { - endPos = (int)off + len; /* position we're supposed to write up to */ - while ((afs_int32)toff < endPos && (afs_int32)toff < avc->m.Length) { + endPos = (afs_offs_t) off + len; /* position we're supposed to write up to */ + while ((afs_offs_t) toff < endPos + && (afs_offs_t) toff < avc->m.Length) { /* If not invalidating pages use page_lookup_nowait to avoid reclaiming * them from the free list */ AFS_GUNLOCK(); - if (flags & (B_FREE|B_INVAL)) + if (flags & (B_FREE | B_INVAL)) pages = page_lookup(vp, toff, SE_EXCL); else pages = page_lookup_nowait(vp, toff, SE_SHARED); - if (!pages || !pvn_getdirty(pages, flags)) + if (!pages || !pvn_getdirty(pages, flags)) tlen = PAGESIZE; else { + if (!didWriteLock) { + AFS_GLOCK(); + didWriteLock = 1; + UpgradeSToWLock(&avc->lock, 671); + AFS_GUNLOCK(); + } NPages++; code = afs_putapage(vp, pages, &toff, &tlen, flags, cred); if (code) { @@ -637,56 +723,70 @@ int afs_putpage(vp, off, len, flags, cred) AFS_GLOCK(); } } else { + if (!didWriteLock) { + UpgradeSToWLock(&avc->lock, 670); + didWriteLock = 1; + } + AFS_GUNLOCK(); -#if defined(AFS_SUN56_ENV) +#if defined(AFS_SUN56_ENV) code = pvn_vplist_dirty(vp, toff, afs_putapage, flags, cred); #else - code = pvn_vplist_dirty(vp, (u_int)off, afs_putapage, flags, cred); + code = pvn_vplist_dirty(vp, (u_int) off, afs_putapage, flags, cred); #endif AFS_GLOCK(); } - if (code && !avc->vc_error) + if (code && !avc->vc_error) { + if (!didWriteLock) { + UpgradeSToWLock(&avc->lock, 669); + didWriteLock = 1; + } avc->vc_error = code; + } - ReleaseWriteLock(&avc->lock); + if (didWriteLock) + ReleaseWriteLock(&avc->lock); + else + ReleaseSharedLock(&avc->lock); afs_BozonUnlock(&avc->pvnLock, avc); - afs_Trace2(afs_iclSetp, CM_TRACE_PAGEOUTDONE, ICL_TYPE_LONG, code, ICL_TYPE_LONG, NPages); + afs_Trace2(afs_iclSetp, CM_TRACE_PAGEOUTDONE, ICL_TYPE_LONG, code, + ICL_TYPE_LONG, NPages); AFS_GUNLOCK(); return (code); } -int afs_putapage(struct vnode *vp, struct page *pages, +int +afs_putapage(struct vnode *vp, struct page *pages, #if defined(AFS_SUN56_ENV) - u_offset_t *offp, + u_offset_t * offp, #else - u_int *offp, + u_int * offp, #endif #if defined(AFS_SUN58_ENV) - size_t *lenp, + size_t * lenp, #else - u_int *lenp, + u_int * lenp, #endif - int flags, struct AFS_UCRED *credp) + int flags, struct AFS_UCRED *credp) { struct buf *tbuf; struct vcache *avc = VTOAFS(vp); afs_int32 code = 0; - u_int toff, tlen = PAGESIZE, off = (pages->p_offset/PAGESIZE)*PAGESIZE; - u_int poff = pages->p_offset; + u_int tlen = PAGESIZE; + afs_offs_t off = (pages->p_offset / PAGESIZE) * PAGESIZE; /* * Now we've got the modified pages. All pages are locked and held * XXX Find a kluster that fits in one block (or page). We also * adjust the i/o if the file space is less than a while page. XXX */ - toff = off; - if (tlen+toff > avc->m.Length) { - tlen = avc->m.Length - toff; + if (off + tlen > avc->m.Length) { + tlen = avc->m.Length - off; } /* can't call mapout with 0 length buffers (rmfree panics) */ - if (((tlen>>24)&0xff) == 0xff) { + if (((tlen >> 24) & 0xff) == 0xff) { tlen = 0; } if ((int)tlen > 0) { @@ -694,36 +794,41 @@ int afs_putapage(struct vnode *vp, struct page *pages, * Can't call mapout with 0 length buffers since we'll get rmfree panics */ tbuf = pageio_setup(pages, tlen, vp, B_WRITE | flags); - if (!tbuf) return (ENOMEM); + if (!tbuf) + return (ENOMEM); tbuf->b_dev = 0; tbuf->b_blkno = btodb(pages->p_offset); bp_mapin(tbuf); AFS_GLOCK(); - afs_Trace4(afs_iclSetp, CM_TRACE_PAGEOUTONE, ICL_TYPE_LONG, avc, ICL_TYPE_LONG, pages, - ICL_TYPE_LONG, tlen, ICL_TYPE_LONG, toff); + afs_Trace4(afs_iclSetp, CM_TRACE_PAGEOUTONE, ICL_TYPE_LONG, avc, + ICL_TYPE_LONG, pages, ICL_TYPE_LONG, tlen, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(off)); code = afs_ustrategy(tbuf, credp); /* unlocks page */ AFS_GUNLOCK(); bp_mapout(tbuf); } - pvn_write_done(pages, ((code) ? B_ERROR:0) | B_WRITE | flags); + pvn_write_done(pages, ((code) ? B_ERROR : 0) | B_WRITE | flags); if ((int)tlen > 0) pageio_done(tbuf); - if (offp) *offp = toff; - if (lenp) *lenp = tlen; + if (offp) + *offp = off; + if (lenp) + *lenp = tlen; return code; } -#else AFS_SUN5_ENV +#else /* AFS_SUN5_ENV */ -int afs_putpage(vp, off, len, flags, cred) -struct vnode *vp; -u_int off; -u_int len; -int flags; -struct AFS_UCRED *cred; +int +afs_putpage(vp, off, len, flags, cred) + struct vnode *vp; + u_int off; + u_int len; + int flags; + struct AFS_UCRED *cred; { - int wholeEnchilada; /* true if we must get all of the pages */ + int wholeEnchilada; /* true if we must get all of the pages */ struct vcache *avc; struct page *pages; struct page *tpage; @@ -734,44 +839,49 @@ struct AFS_UCRED *cred; afs_int32 clusterStart, clusterEnd, endPos; /* In the wholeEnchilada case, we must ensure that we get all of the pages - from the system, since we're doing this to shutdown the use of a vnode */ + * from the system, since we're doing this to shutdown the use of a vnode */ AFS_STATCNT(afs_putpage); - wholeEnchilada = (off == 0 && len == 0 && (flags & (B_INVAL|B_ASYNC)) == B_INVAL); + wholeEnchilada = (off == 0 && len == 0 + && (flags & (B_INVAL | B_ASYNC)) == B_INVAL); avc = VTOAFS(vp); afs_BozonLock(&avc->pvnLock, avc); - ObtainWriteLock(&avc->lock,248); + ObtainWriteLock(&avc->lock, 248); while (1) { /* in whole enchilada case, loop until call to pvn_getdirty can't find - any more modified pages */ + * any more modified pages */ /* first we try to get a list of modified (or whatever) pages */ if (len == 0) { pages = pvn_vplist_dirty(vp, off, flags); - } - else { + } else { endPos = off + len; /* position we're supposed to write up to */ - if (endPos > avc->m.Length) endPos = avc->m.Length; /* bound by this */ - clusterStart = off & ~(PAGESIZE-1); /* round down to nearest page */ - clusterEnd = ((endPos-1) | (PAGESIZE-1))+1; /* round up to nearest page */ - pages = pvn_range_dirty(vp, off, endPos, clusterStart, clusterEnd, flags); + if (endPos > avc->m.Length) + endPos = avc->m.Length; /* bound by this */ + clusterStart = off & ~(PAGESIZE - 1); /* round down to nearest page */ + clusterEnd = ((endPos - 1) | (PAGESIZE - 1)) + 1; /* round up to nearest page */ + pages = + pvn_range_dirty(vp, off, endPos, clusterStart, clusterEnd, + flags); } - + /* Now we've got the modified pages. All pages are locked and held */ rcode = 0; /* return code */ - while(pages) { /* look over all pages in the returned set */ + while (pages) { /* look over all pages in the returned set */ tpage = pages; /* get first page in the list */ /* write out the page */ poffset = tpage->p_offset; /* where the page starts in the file */ /* tlen will represent the end of the range to write, for a while */ - tlen = PAGESIZE+poffset; /* basic place to end tpage write */ + tlen = PAGESIZE + poffset; /* basic place to end tpage write */ /* but we also don't want to write past end of off..off+len range */ - if (len != 0 && tlen > off+len) tlen = off+len; + if (len != 0 && tlen > off + len) + tlen = off + len; /* and we don't want to write past the end of the file */ - if (tlen > avc->m.Length) tlen = avc->m.Length; + if (tlen > avc->m.Length) + tlen = avc->m.Length; /* and we don't want to write at all if page starts after end */ if (poffset >= tlen) { pvn_fail(pages, B_WRITE | flags); @@ -782,28 +892,29 @@ struct AFS_UCRED *cred; page_sub(&pages, tpage); /* remove tpage from "pages" list */ tbuf = pageio_setup(tpage, tlen, vp, B_WRITE | flags); if (!tbuf) { - pvn_fail(tpage, B_WRITE|flags); - pvn_fail(pages, B_WRITE|flags); + pvn_fail(tpage, B_WRITE | flags); + pvn_fail(pages, B_WRITE | flags); goto done; } tbuf->b_dev = 0; tbuf->b_blkno = btodb(tpage->p_offset); bp_mapin(tbuf); ReleaseWriteLock(&avc->lock); /* can't hold during strategy call */ - code = afs_ustrategy(tbuf); /* unlocks page */ - ObtainWriteLock(&avc->lock,249); /* re-obtain */ + code = afs_ustrategy(tbuf); /* unlocks page */ + ObtainWriteLock(&avc->lock, 249); /* re-obtain */ if (code) { /* unlocking of tpage is done by afs_ustrategy */ rcode = code; if (pages) /* may have already removed last page */ - pvn_fail(pages, B_WRITE|flags); + pvn_fail(pages, B_WRITE | flags); goto done; } - } /* for (tpage=pages....) */ + } /* for (tpage=pages....) */ /* see if we've gotten all of the pages in the whole enchilada case */ - if (!wholeEnchilada || !vp->v_pages) break; - } /* while(1) obtaining all pages */ + if (!wholeEnchilada || !vp->v_pages) + break; + } /* while(1) obtaining all pages */ /* * If low on chunks, and if writing the last byte of a chunk, try to @@ -811,14 +922,15 @@ struct AFS_UCRED *cred; * calls afs_putpage, so this is recursion. It stops there because we * insist on len being non-zero. */ - if (afs_stats_cmperf.cacheCurrDirtyChunks > afs_stats_cmperf.cacheMaxDirtyChunks - && len != 0 && AFS_CHUNKOFFSET((off + len)) == 0) { + if (afs_stats_cmperf.cacheCurrDirtyChunks > + afs_stats_cmperf.cacheMaxDirtyChunks && len != 0 + && AFS_CHUNKOFFSET((off + len)) == 0) { struct vrequest treq; if (!afs_InitReq(&treq, cred ? cred : u.u_cred)) { rcode = afs_DoPartialWrite(avc, &treq); /* XXX */ } } - + done: if (rcode && !avc->vc_error) @@ -830,14 +942,15 @@ struct AFS_UCRED *cred; return rcode; } -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ -int afs_nfsrdwr(avc, auio, arw, ioflag, acred) -register struct vcache *avc; -struct uio *auio; -enum uio_rw arw; -int ioflag; -struct AFS_UCRED *acred; +int +afs_nfsrdwr(avc, auio, arw, ioflag, acred) + register struct vcache *avc; + struct uio *auio; + enum uio_rw arw; + int ioflag; + struct AFS_UCRED *acred; { register afs_int32 code; afs_int32 code2; @@ -845,13 +958,13 @@ struct AFS_UCRED *acred; afs_int32 mode, sflags; register char *data; struct dcache *dcp, *dcp_newpage; - afs_int32 fileBase, size; - afs_int32 pageBase; + afs_size_t fileBase, size; + afs_size_t pageBase; register afs_int32 tsize; - register afs_int32 pageOffset, extraResid=0; - register long origLength; /* length when reading/writing started */ - register long appendLength; /* length when this call will finish */ - int created; /* created pages instead of faulting them */ + register afs_int32 pageOffset, extraResid = 0; + register afs_size_t origLength; /* length when reading/writing started */ + register long appendLength; /* length when this call will finish */ + int created; /* created pages instead of faulting them */ int lockCode; int didFakeOpen, eof; struct vrequest treq; @@ -861,34 +974,40 @@ struct AFS_UCRED *acred; AFS_STATCNT(afs_nfsrdwr); /* can't read or write other things */ - if (vType(avc) != VREG) return EISDIR; + if (vType(avc) != VREG) + return EISDIR; if (auio->uio_resid == 0) return (0); - afs_Trace4(afs_iclSetp, CM_TRACE_VMRW, ICL_TYPE_POINTER, (afs_int32)avc, - ICL_TYPE_LONG, (arw==UIO_WRITE? 1 : 0), - ICL_TYPE_LONG, auio->uio_offset, - ICL_TYPE_LONG, auio->uio_resid); + afs_Trace4(afs_iclSetp, CM_TRACE_VMRW, ICL_TYPE_POINTER, (afs_int32) avc, + ICL_TYPE_LONG, (arw == UIO_WRITE ? 1 : 0), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(auio->uio_offset), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(auio->uio_resid)); - if ( AfsLargeFileUio(auio) ) /* file is larger than 2 GB */ +#ifndef AFS_64BIT_CLIENT + if (AfsLargeFileUio(auio)) /* file is larger than 2 GB */ return (EFBIG); - +#endif + #ifdef AFS_SUN5_ENV - if (!acred) osi_Panic("rdwr: !acred"); + if (!acred) + osi_Panic("rdwr: !acred"); #else - if (!acred) acred = u.u_cred; + if (!acred) + acred = u.u_cred; #endif - if (code = afs_InitReq(&treq, acred)) return code; + if (code = afs_InitReq(&treq, acred)) + return code; /* It's not really possible to know if a write cause a growth in the * cache size, we we wait for a cache drain for any write. */ afs_MaybeWakeupTruncateDaemon(); - while ((arw == UIO_WRITE) && - (afs_blocksUsed > (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100)) { + while ((arw == UIO_WRITE) + && (afs_blocksUsed > (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100)) { if (afs_blocksUsed - afs_blocksDiscarded > - (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100) { + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { afs_WaitForCacheDrain = 1; afs_osi_Sleep(&afs_WaitForCacheDrain); } @@ -896,58 +1015,59 @@ struct AFS_UCRED *acred; afs_MaybeWakeupTruncateDaemon(); } code = afs_VerifyVCache(avc, &treq); - if (code) return afs_CheckCode(code, &treq, 45); + if (code) + return afs_CheckCode(code, &treq, 45); afs_BozonLock(&avc->pvnLock, avc); osi_FlushPages(avc, acred); /* hold bozon lock, but not basic vnode lock */ - ObtainWriteLock(&avc->lock,250); + ObtainWriteLock(&avc->lock, 250); /* adjust parameters when appending files */ - if ((ioflag & IO_APPEND) && arw == UIO_WRITE) - { + if ((ioflag & IO_APPEND) && arw == UIO_WRITE) { #if defined(AFS_SUN56_ENV) auio->uio_loffset = 0; #endif auio->uio_offset = avc->m.Length; /* write at EOF position */ } if (auio->uio_offset < 0 || (auio->uio_offset + auio->uio_resid) < 0) { - ReleaseWriteLock(&avc->lock); + ReleaseWriteLock(&avc->lock); afs_BozonUnlock(&avc->pvnLock, avc); return EINVAL; } - - /* file is larger than 2GB */ - if ( AfsLargeFileSize(auio->uio_offset, auio->uio_resid) ) { - ReleaseWriteLock(&avc->lock); +#ifndef AFS_64BIT_CLIENT + /* file is larger than 2GB */ + if (AfsLargeFileSize(auio->uio_offset, auio->uio_resid)) { + ReleaseWriteLock(&avc->lock); afs_BozonUnlock(&avc->pvnLock, avc); return EFBIG; } +#endif - didFakeOpen=0; /* keep track of open so we can do close */ + didFakeOpen = 0; /* keep track of open so we can do close */ if (arw == UIO_WRITE) { /* do ulimit processing; shrink resid or fail */ #if defined(AFS_SUN56_ENV) if (auio->uio_loffset + auio->afsio_resid > auio->uio_llimit) { if (auio->uio_llimit >= auio->uio_llimit) { - ReleaseWriteLock(&avc->lock); - afs_BozonUnlock(&avc->pvnLock, avc); - return EFBIG; - } else { - /* track # of bytes we should write, but won't because of - * ulimit; we must add this into the final resid value - * so caller knows we punted some data. - */ - extraResid = auio->uio_resid; - auio->uio_resid = auio->uio_llimit - auio->uio_loffset; - extraResid -= auio->uio_resid; - } - } + ReleaseWriteLock(&avc->lock); + afs_BozonUnlock(&avc->pvnLock, avc); + return EFBIG; + } else { + /* track # of bytes we should write, but won't because of + * ulimit; we must add this into the final resid value + * so caller knows we punted some data. + */ + extraResid = auio->uio_resid; + auio->uio_resid = auio->uio_llimit - auio->uio_loffset; + extraResid -= auio->uio_resid; + } + } #else -#ifdef AFS_SUN52_ENV +#ifdef AFS_SUN52_ENV if (auio->afsio_offset + auio->afsio_resid > auio->uio_limit) { if (auio->afsio_offset >= auio->uio_limit) { - ReleaseWriteLock(&avc->lock); + ReleaseWriteLock(&avc->lock); afs_BozonUnlock(&avc->pvnLock, avc); return EFBIG; } else { @@ -964,27 +1084,33 @@ struct AFS_UCRED *acred; #endif /* SUN56 */ mode = S_WRITE; /* segment map-in mode */ afs_FakeOpen(avc); /* do this for writes, so data gets put back - when we want it to be put back */ + * when we want it to be put back */ didFakeOpen = 1; /* we'll be doing a fake open */ /* before starting any I/O, we must ensure that the file is big enough - to hold the results (since afs_putpage will be called to force the I/O */ + * to hold the results (since afs_putpage will be called to force the I/O */ size = auio->afsio_resid + auio->afsio_offset; /* new file size */ - appendLength = size; + appendLength = size; origLength = avc->m.Length; - if (size > avc->m.Length) + if (size > avc->m.Length) { + afs_Trace4(afs_iclSetp, CM_TRACE_SETLENGTH, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_LONG, __LINE__, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(size)); avc->m.Length = size; /* file grew */ - avc->states |= CDirty; /* Set the dirty bit */ + } + avc->states |= CDirty; /* Set the dirty bit */ avc->m.Date = osi_Time(); /* Set file date (for ranlib) */ } else { - mode = S_READ; /* map-in read-only */ + mode = S_READ; /* map-in read-only */ origLength = avc->m.Length; } if (acred && AFS_NFSXLATORREQ(acred)) { if (arw == UIO_READ) { - if (!afs_AccessOK(avc, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) { - ReleaseWriteLock(&avc->lock); + if (!afs_AccessOK + (avc, PRSFS_READ, &treq, + CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) { + ReleaseWriteLock(&avc->lock); afs_BozonUnlock(&avc->pvnLock, avc); return EACCES; } @@ -997,59 +1123,59 @@ struct AFS_UCRED *acred; avc->credp = acred; #endif } - counter = 0; /* don't call afs_DoPartialWrite first time through. */ + counter = 0; /* don't call afs_DoPartialWrite first time through. */ while (1) { /* compute the amount of data to move into this block, - based on auio->afsio_resid. Note that we copy data in units of - MAXBSIZE, not PAGESIZE. This is because segmap_getmap panics if you - call it with an offset based on blocks smaller than MAXBSIZE - (implying that it should be named BSIZE, since it is clearly both a - max and a min). */ - size = auio->afsio_resid; /* transfer size */ - fileBase = auio->afsio_offset; /* start file position for xfr */ - pageBase = fileBase & ~(MAXBSIZE-1); /* file position of the page */ - pageOffset = fileBase & (MAXBSIZE-1); /* xfr start's offset within page */ - tsize = MAXBSIZE-pageOffset; /* how much more fits in this page */ + * based on auio->afsio_resid. Note that we copy data in units of + * MAXBSIZE, not PAGESIZE. This is because segmap_getmap panics if you + * call it with an offset based on blocks smaller than MAXBSIZE + * (implying that it should be named BSIZE, since it is clearly both a + * max and a min). */ + size = auio->afsio_resid; /* transfer size */ + fileBase = auio->afsio_offset; /* start file position for xfr */ + pageBase = fileBase & ~(MAXBSIZE - 1); /* file position of the page */ + pageOffset = fileBase & (MAXBSIZE - 1); /* xfr start's offset within page */ + tsize = MAXBSIZE - pageOffset; /* how much more fits in this page */ /* we'll read tsize bytes, but first must make sure tsize isn't too big */ - if (tsize > size) tsize = size; /* don't read past end of request */ - eof = 0; /* flag telling us if we hit the EOF on the read */ - if (arw == UIO_READ) { /* we're doing a read operation */ + if (tsize > size) + tsize = size; /* don't read past end of request */ + eof = 0; /* flag telling us if we hit the EOF on the read */ + if (arw == UIO_READ) { /* we're doing a read operation */ /* don't read past EOF */ - if (tsize + fileBase > origLength) { + if (fileBase + tsize > origLength) { tsize = origLength - fileBase; - eof = 1; /* we did hit the EOF */ - if (tsize < 0) tsize = 0; /* better safe than sorry */ + eof = 1; /* we did hit the EOF */ + if (tsize < 0) + tsize = 0; /* better safe than sorry */ } sflags = 0; - } - else { + } else { #ifdef AFS_SUN5_ENV /* Purge dirty chunks of file if there are too many dirty * chunks. Inside the write loop, we only do this at a chunk * boundary. Clean up partial chunk if necessary at end of loop. */ - if (counter > 0 && code == 0 && AFS_CHUNKOFFSET(fileBase) == 0) - { - code = afs_DoPartialWrite(avc, &treq); - if (code) - break; - } -#endif /* AFS_SUN5_ENV */ + if (counter > 0 && code == 0 && AFS_CHUNKOFFSET(fileBase) == 0) { + code = afs_DoPartialWrite(avc, &treq); + if (code) + break; + } +#endif /* AFS_SUN5_ENV */ /* write case, we ask segmap_release to call putpage. Really, we - don't have to do this on every page mapin, but for now we're - lazy, and don't modify the rest of AFS to scan for modified - pages on a close or other "synchronize with file server" - operation. This makes things a little cleaner, but probably - hurts performance. */ + * don't have to do this on every page mapin, but for now we're + * lazy, and don't modify the rest of AFS to scan for modified + * pages on a close or other "synchronize with file server" + * operation. This makes things a little cleaner, but probably + * hurts performance. */ sflags = SM_WRITE; } if (tsize <= 0) { code = 0; - break; /* nothing to transfer, we're done */ + break; /* nothing to transfer, we're done */ } #ifdef AFS_SUN5_ENV if (arw == UIO_WRITE) - avc->states |= CDirty; /* may have been cleared by DoPartialWrite*/ + avc->states |= CDirty; /* may have been cleared by DoPartialWrite */ /* Before dropping lock, hold the chunk (create it if necessary). This * serves two purposes: (1) Ensure Cache Truncate Daemon doesn't try @@ -1073,10 +1199,10 @@ struct AFS_UCRED *acred; } ReleaseWriteLock(&avc->vlock); { - int toff, tlen; + afs_size_t toff, tlen; dcp = afs_GetDCache(avc, fileBase, &treq, &toff, &tlen, 2); if (!dcp) { - code = ENOENT; + code = ENOENT; break; } } @@ -1084,30 +1210,32 @@ struct AFS_UCRED *acred; ReleaseWriteLock(&avc->lock); /* uiomove may page fault */ AFS_GUNLOCK(); #if defined(AFS_SUN56_ENV) - data = segmap_getmap(segkmap,AFSTOV(avc),(u_offset_t)pageBase); + data = segmap_getmap(segkmap, AFSTOV(avc), (u_offset_t) pageBase); #else data = segmap_getmap(segkmap, AFSTOV(avc), pageBase); #endif #ifndef AFS_SUN5_ENV - code = afs_fc2errno(as_fault(&kas, data+pageOffset, tsize, - F_SOFTLOCK, mode)); + code = + afs_fc2errno(as_fault + (&kas, data + pageOffset, tsize, F_SOFTLOCK, mode)); if (code == 0) { - AFS_UIOMOVE(data+pageOffset, tsize, arw, auio, code); - as_fault(&kas, data+pageOffset, tsize, F_SOFTUNLOCK, mode); + AFS_UIOMOVE(data + pageOffset, tsize, arw, auio, code); + as_fault(&kas, data + pageOffset, tsize, F_SOFTUNLOCK, mode); code2 = segmap_release(segkmap, data, sflags); if (!code) code = code2; - } - else { - (void) segmap_release(segkmap, data, 0); + } else { + (void)segmap_release(segkmap, data, 0); } #else #if defined(AFS_SUN56_ENV) - raddr = (caddr_t) (((uintptr_t)data +pageOffset) & PAGEMASK); + raddr = (caddr_t) (((uintptr_t) data + pageOffset) & PAGEMASK); #else - raddr = (caddr_t) (((u_int)data +pageOffset) & PAGEMASK); + raddr = (caddr_t) (((u_int) data + pageOffset) & PAGEMASK); #endif - rsize = (((u_int)data+pageOffset+tsize+PAGEOFFSET) & PAGEMASK)-(u_int)raddr; + rsize = + (((u_int) data + pageOffset + tsize + PAGEOFFSET) & PAGEMASK) - + (u_int) raddr; if (code == 0) { /* if we're doing a write, and we're starting at the rounded * down page base, and we're writing enough data to cover all @@ -1115,9 +1243,8 @@ struct AFS_UCRED *acred; * in this MAXBSIZE window that we're creating. */ created = 0; - if (arw == UIO_WRITE - && ((long)raddr == (long)data+pageOffset) - && tsize >= rsize) { + if (arw == UIO_WRITE && ((long)raddr == (long)data + pageOffset) + && tsize >= rsize) { /* probably the dcache backing this guy is around, but if * not, we can't do this optimization, since we're creating * writable pages, which must be backed by a chunk. @@ -1126,71 +1253,67 @@ struct AFS_UCRED *acred; dcp_newpage = afs_FindDCache(avc, pageBase); if (dcp_newpage && hsame(avc->m.DataVersion, dcp_newpage->f.versionNo)) { - ObtainWriteLock(&avc->lock,251); - ObtainWriteLock(&avc->vlock,576); + ObtainWriteLock(&avc->lock, 251); + ObtainWriteLock(&avc->vlock, 576); + ObtainReadLock(&dcp_newpage->lock); if ((avc->activeV == 0) && hsame(avc->m.DataVersion, dcp_newpage->f.versionNo) - && !(dcp_newpage->flags & (DFFetching))) { + && !(dcp_newpage->dflags & (DFFetching))) { AFS_GUNLOCK(); segmap_pagecreate(segkmap, raddr, rsize, 1); AFS_GLOCK(); - ObtainWriteLock(&afs_xdcache,252); + ObtainWriteLock(&afs_xdcache, 252); /* Mark the pages as created and dirty */ afs_indexFlags[dcp_newpage->index] |= (IFAnyPages | IFDirtyPages); - ReleaseWriteLock(&afs_xdcache); - avc->states |= CHasPages; + ReleaseWriteLock(&afs_xdcache); created = 1; } + ReleaseReadLock(&dcp_newpage->lock); afs_PutDCache(dcp_newpage); ReleaseWriteLock(&avc->vlock); ReleaseWriteLock(&avc->lock); - } - else if ( dcp_newpage ) + } else if (dcp_newpage) afs_PutDCache(dcp_newpage); AFS_GUNLOCK(); } if (!created) - code = afs_fc2errno(segmap_fault(kas.a_hat, segkmap, raddr, - rsize, F_SOFTLOCK, mode)); + code = + afs_fc2errno(segmap_fault + (kas.a_hat, segkmap, raddr, rsize, + F_SOFTLOCK, mode)); } if (code == 0) { - AFS_UIOMOVE(data+pageOffset, tsize, arw, auio, code); - segmap_fault(kas.a_hat, segkmap, raddr, rsize, F_SOFTUNLOCK, mode); + AFS_UIOMOVE(data + pageOffset, tsize, arw, auio, code); + segmap_fault(kas.a_hat, segkmap, raddr, rsize, F_SOFTUNLOCK, + mode); } if (code == 0) { code = segmap_release(segkmap, data, sflags); } else { - (void) segmap_release(segkmap, data, 0); + (void)segmap_release(segkmap, data, 0); } -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ AFS_GLOCK(); - ObtainWriteLock(&avc->lock,253); + ObtainWriteLock(&avc->lock, 253); #ifdef AFS_SUN5_ENV - /* - * If at a chunk boundary, start prefetch of next chunk. - */ - if (counter == 0 || AFS_CHUNKOFFSET(fileBase) == 0) { - if (!(dcp->flags & DFNextStarted)) - afs_PrefetchChunk(avc, dcp, acred, &treq); - } counter++; - if (dcp) - afs_PutDCache(dcp); -#endif /* AFS_SUN5_ENV */ - if (code) break; + if (dcp) + afs_PutDCache(dcp); +#endif /* AFS_SUN5_ENV */ + if (code) + break; } if (didFakeOpen) { afs_FakeClose(avc, acred); } - #ifdef AFS_SUN5_ENV if (arw == UIO_WRITE && (avc->states & CDirty)) { code2 = afs_DoPartialWrite(avc, &treq); if (!code) code = code2; } -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ if (!code && avc->vc_error) { code = avc->vc_error; @@ -1199,7 +1322,8 @@ struct AFS_UCRED *acred; afs_BozonUnlock(&avc->pvnLock, avc); if (!code) { #ifdef AFS_SUN53_ENV - if ((ioflag & FSYNC) && (arw == UIO_WRITE) && !AFS_NFSXLATORREQ(acred)) + if ((ioflag & FSYNC) && (arw == UIO_WRITE) + && !AFS_NFSXLATORREQ(acred)) code = afs_fsync(avc, 0, acred); #else if ((ioflag & IO_SYNC) && (arw == UIO_WRITE) @@ -1207,7 +1331,7 @@ struct AFS_UCRED *acred; code = afs_fsync(avc, acred); #endif } -#ifdef AFS_SUN52_ENV +#ifdef AFS_SUN52_ENV /* * If things worked, add in as remaining in request any bytes * we didn't write due to file size ulimit. @@ -1219,112 +1343,114 @@ struct AFS_UCRED *acred; } afs_map(vp, off, as, addr, len, prot, maxprot, flags, cred) -struct vnode *vp; -struct as *as; + struct vnode *vp; + struct as *as; #ifdef AFS_SUN5_ENV -offset_t off; -caddr_t *addr; + offset_t off; + caddr_t *addr; #else -u_int off; -addr_t *addr; + u_int off; + addr_t *addr; #endif -u_int len; + u_int len; #ifdef AFS_SUN5_ENV -u_char prot, maxprot; + u_char prot, maxprot; #else -u_int prot, maxprot; + u_int prot, maxprot; #endif -u_int flags; -struct AFS_UCRED *cred; + u_int flags; + struct AFS_UCRED *cred; { - struct segvn_crargs crargs; - register afs_int32 code; - struct vrequest treq; - register struct vcache *avc = VTOAFS(vp); + struct segvn_crargs crargs; + register afs_int32 code; + struct vrequest treq; + register struct vcache *avc = VTOAFS(vp); - AFS_STATCNT(afs_map); + AFS_STATCNT(afs_map); - /* check for reasonableness on segment bounds; apparently len can be < 0 */ - if ((int)off < 0 || (int)(off + len) < 0) { - return (EINVAL); - } - if ( AfsLargeFileSize(off, len) ) /* file is larger than 2 GB */ - { - code = EFBIG; - goto out; - } + /* check for reasonableness on segment bounds; apparently len can be < 0 */ + if (off < 0 || off + len < 0) { + return (EINVAL); + } +#ifndef AFS_64BIT_CLIENT + if (AfsLargeFileSize(off, len)) { /* file is larger than 2 GB */ + code = EFBIG; + goto out; + } +#endif #if defined(AFS_SUN5_ENV) - if (vp->v_flag & VNOMAP) /* File isn't allowed to be mapped */ - return (ENOSYS); + if (vp->v_flag & VNOMAP) /* File isn't allowed to be mapped */ + return (ENOSYS); - if (vp->v_filocks) /* if locked, disallow mapping */ - return (EAGAIN); + if (vp->v_filocks) /* if locked, disallow mapping */ + return (EAGAIN); #endif - AFS_GLOCK(); - if (code = afs_InitReq(&treq, cred)) goto out; + AFS_GLOCK(); + if (code = afs_InitReq(&treq, cred)) + goto out; - if (vp->v_type != VREG) { - code = ENODEV; - goto out; - } + if (vp->v_type != VREG) { + code = ENODEV; + goto out; + } - code = afs_VerifyVCache(avc, &treq); - if (code) { - goto out; - } - afs_BozonLock(&avc->pvnLock, avc); - osi_FlushPages(avc, cred); /* ensure old pages are gone */ - avc->states |= CMAPPED; /* flag cleared at afs_inactive */ - afs_BozonUnlock(&avc->pvnLock, avc); + code = afs_VerifyVCache(avc, &treq); + if (code) { + goto out; + } + afs_BozonLock(&avc->pvnLock, avc); + osi_FlushPages(avc, cred); /* ensure old pages are gone */ + avc->states |= CMAPPED; /* flag cleared at afs_inactive */ + afs_BozonUnlock(&avc->pvnLock, avc); - AFS_GUNLOCK(); + AFS_GUNLOCK(); #ifdef AFS_SUN5_ENV - as_rangelock(as); + as_rangelock(as); #endif - if ((flags & MAP_FIXED) == 0) { + if ((flags & MAP_FIXED) == 0) { #if defined(AFS_SUN57_ENV) - map_addr(addr, len, off, 1, flags); + map_addr(addr, len, off, 1, flags); #elif defined(AFS_SUN56_ENV) - map_addr(addr, len, off, 1); + map_addr(addr, len, off, 1); #else - map_addr(addr, len, (off_t)off, 1); + map_addr(addr, len, (off_t) off, 1); #endif - if (*addr == NULL) { + if (*addr == NULL) { #ifdef AFS_SUN5_ENV - as_rangeunlock(as); + as_rangeunlock(as); #endif - code = ENOMEM; - goto out1; - } - } else - (void) as_unmap(as, *addr, len); /* unmap old address space use */ - /* setup the create parameter block for the call */ - crargs.vp = AFSTOV(avc); - crargs.offset = (u_int)off; - crargs.cred = cred; - crargs.type = flags&MAP_TYPE; - crargs.prot = prot; - crargs.maxprot = maxprot; - crargs.amp = (struct anon_map *) 0; + code = ENOMEM; + goto out1; + } + } else + (void)as_unmap(as, *addr, len); /* unmap old address space use */ + /* setup the create parameter block for the call */ + crargs.vp = AFSTOV(avc); + crargs.offset = (u_int) off; + crargs.cred = cred; + crargs.type = flags & MAP_TYPE; + crargs.prot = prot; + crargs.maxprot = maxprot; + crargs.amp = (struct anon_map *)0; #if defined(AFS_SUN5_ENV) - crargs.flags = flags & ~MAP_TYPE; + crargs.flags = flags & ~MAP_TYPE; #endif - code = as_map(as, *addr, len, segvn_create, (char *) &crargs); + code = as_map(as, *addr, len, segvn_create, (char *)&crargs); #ifdef AFS_SUN5_ENV - as_rangeunlock(as); + as_rangeunlock(as); #endif -out1: - AFS_GLOCK(); - code = afs_CheckCode(code, &treq, 47); - AFS_GUNLOCK(); - return code; -out: - code = afs_CheckCode(code, &treq, 48); - AFS_GUNLOCK(); - return code; + out1: + AFS_GLOCK(); + code = afs_CheckCode(code, &treq, 47); + AFS_GUNLOCK(); + return code; + out: + code = afs_CheckCode(code, &treq, 48); + AFS_GUNLOCK(); + return code; } /* Sun 4.0.X-specific code. It computes the number of bytes that need @@ -1333,16 +1459,19 @@ out: will be passed to pvn_vptrunc by the truncate code */ #ifndef AFS_SUN5_ENV /* Not good for Solaris */ afs_PageLeft(alen) -register afs_int32 alen; { + register afs_int32 alen; +{ register afs_int32 nbytes; AFS_STATCNT(afs_PageLeft); - nbytes = PAGESIZE - (alen & PAGEOFFSET); /* amount to zap in last page */ + nbytes = PAGESIZE - (alen & PAGEOFFSET); /* amount to zap in last page */ /* now check if we'd zero the entire last page. Don't need to do this - since pvn_vptrunc will handle this case properly (it will invalidate - this page) */ - if (nbytes == PAGESIZE) nbytes = 0; - if (nbytes < 0) nbytes = 0; /* just in case */ + * since pvn_vptrunc will handle this case properly (it will invalidate + * this page) */ + if (nbytes == PAGESIZE) + nbytes = 0; + if (nbytes < 0) + nbytes = 0; /* just in case */ return nbytes; } #endif @@ -1354,45 +1483,45 @@ register afs_int32 alen; { */ #if defined(AFS_SUN5_ENV) afs_pathconf(vp, cmd, outdatap, credp) - register struct AFS_UCRED *credp; + register struct AFS_UCRED *credp; #else afs_cntl(vp, cmd, indatap, outdatap, inflag, outflag) - int inflag, outflag; - char *indatap; + int inflag, outflag; + char *indatap; #endif - struct vnode *vp; - int cmd; - u_long *outdatap; + struct vnode *vp; + int cmd; + u_long *outdatap; { AFS_STATCNT(afs_cntl); switch (cmd) { - case _PC_LINK_MAX: + case _PC_LINK_MAX: *outdatap = MAXLINK; break; - case _PC_NAME_MAX: + case _PC_NAME_MAX: *outdatap = MAXNAMLEN; break; - case _PC_PATH_MAX: + case _PC_PATH_MAX: *outdatap = MAXPATHLEN; break; - case _PC_CHOWN_RESTRICTED: + case _PC_CHOWN_RESTRICTED: *outdatap = 1; break; - case _PC_NO_TRUNC: + case _PC_NO_TRUNC: *outdatap = 1; break; #if !defined(AFS_SUN5_ENV) - case _PC_MAX_CANON: + case _PC_MAX_CANON: *outdatap = CANBSIZ; break; - case _PC_VDISABLE: + case _PC_VDISABLE: *outdatap = VDISABLE; break; - case _PC_PIPE_BUF: + case _PC_PIPE_BUF: return EINVAL; break; #endif - default: + default: return EINVAL; } return 0; @@ -1403,25 +1532,27 @@ afs_cntl(vp, cmd, indatap, outdatap, inflag, outflag) #if defined(AFS_SUN5_ENV) afs_ioctl(vnp, com, arg, flag, credp, rvalp) - struct vnode *vnp; - int com, arg, flag; - cred_t *credp; - int *rvalp; + struct vnode *vnp; + int com, arg, flag; + cred_t *credp; + int *rvalp; { return (ENOTTY); } -void afs_rwlock(vnp, wlock) - struct vnode *vnp; - int wlock; +void +afs_rwlock(vnp, wlock) + struct vnode *vnp; + int wlock; { rw_enter(&(VTOAFS(vnp))->rwlock, (wlock ? RW_WRITER : RW_READER)); } -void afs_rwunlock(vnp, wlock) - struct vnode *vnp; - int wlock; +void +afs_rwunlock(vnp, wlock) + struct vnode *vnp; + int wlock; { rw_exit(&(VTOAFS(vnp))->rwlock); } @@ -1429,9 +1560,9 @@ void afs_rwunlock(vnp, wlock) /* NOT SUPPORTED */ afs_seek(vnp, ooff, noffp) - struct vnode *vnp; - offset_t ooff; - offset_t *noffp; + struct vnode *vnp; + offset_t ooff; + offset_t *noffp; { register int code = 0; @@ -1440,24 +1571,25 @@ afs_seek(vnp, ooff, noffp) return code; } -int afs_frlock(vnp, cmd, ap, flag, off, +int +afs_frlock(vnp, cmd, ap, flag, off, #ifdef AFS_SUN59_ENV - flkcb, + flkcb, #endif - credp) - struct vnode *vnp; - int cmd; + credp) + struct vnode *vnp; + int cmd; #if defined(AFS_SUN56_ENV) - struct flock64 *ap; + struct flock64 *ap; #else - struct flock *ap; + struct flock *ap; #endif - int flag; - offset_t off; + int flag; + offset_t off; #ifdef AFS_SUN59_ENV - struct flk_callback *flkcb; + struct flk_callback *flkcb; #endif - struct AFS_UCRED *credp; + struct AFS_UCRED *credp; { register afs_int32 code = 0; /* @@ -1468,7 +1600,8 @@ int afs_frlock(vnp, cmd, ap, flag, off, if (flkcb) afs_warn("Don't know how to deal with flk_callback's!\n"); #endif - if ((cmd == F_GETLK) || (cmd == F_O_GETLK) || (cmd == F_SETLK) || (cmd == F_SETLKW)) { + if ((cmd == F_GETLK) || (cmd == F_O_GETLK) || (cmd == F_SETLK) + || (cmd == F_SETLKW)) { #ifdef AFS_SUN53_ENV ap->l_pid = ttoproc(curthread)->p_pid; ap->l_sysid = 0; @@ -1481,9 +1614,10 @@ int afs_frlock(vnp, cmd, ap, flag, off, #ifdef AFS_SUN56_ENV code = convoff(vnp, ap, 0, off); #else - code = convoff(vnp, ap, 0, (off_t)off); + code = convoff(vnp, ap, 0, (off_t) off); #endif - if (code) return code; + if (code) + return code; AFS_GLOCK(); } @@ -1493,17 +1627,18 @@ int afs_frlock(vnp, cmd, ap, flag, off, } -int afs_space(vnp, cmd, ap, flag, off, credp) - struct vnode *vnp; - int cmd; +int +afs_space(vnp, cmd, ap, flag, off, credp) + struct vnode *vnp; + int cmd; #if defined(AFS_SUN56_ENV) - struct flock64 *ap; + struct flock64 *ap; #else - struct flock *ap; + struct flock *ap; #endif - int flag; - offset_t off; - struct AFS_UCRED *credp; + int flag; + offset_t off; + struct AFS_UCRED *credp; { register afs_int32 code = EINVAL; struct vattr vattr; @@ -1512,14 +1647,14 @@ int afs_space(vnp, cmd, ap, flag, off, credp) #ifdef AFS_SUN56_ENV && ((code = convoff(vnp, ap, 0, off)) == 0)) { #else - && ((code = convoff(vnp, ap, 0, (off_t)off)) == 0)) { + && ((code = convoff(vnp, ap, 0, (off_t) off)) == 0)) { #endif AFS_GLOCK(); if (!ap->l_len) { vattr.va_mask = AT_SIZE; vattr.va_size = ap->l_start; code = afs_setattr(VTOAFS(vnp), &vattr, 0, credp); - } + } AFS_GUNLOCK(); } return (code); @@ -1528,10 +1663,11 @@ int afs_space(vnp, cmd, ap, flag, off, credp) #endif -int afs_dump(vp, addr, i1, i2) -struct vnode *vp; -caddr_t addr; -int i1, i2; +int +afs_dump(vp, addr, i1, i2) + struct vnode *vp; + caddr_t addr; + int i1, i2; { AFS_STATCNT(afs_dump); afs_warn("AFS_DUMP. MUST IMPLEMENT THIS!!!\n"); @@ -1540,40 +1676,44 @@ int i1, i2; /* Nothing fancy here; just compare if vnodes are identical ones */ -afs_cmp(vp1, vp2) -struct vnode *vp1, *vp2; +afs_cmp(vp1, vp2) + struct vnode *vp1, *vp2; { AFS_STATCNT(afs_cmp); - return(vp1 == vp2); + return (vp1 == vp2); } -int afs_realvp(struct vnode *vp, struct vnode **vpp) { +int +afs_realvp(struct vnode *vp, struct vnode **vpp) +{ AFS_STATCNT(afs_realvp); return EINVAL; } -int afs_pageio(vp, pp, ui1, ui2, i1, credp) -struct vnode *vp; -struct page *pp; -u_int ui1, ui2; -int i1; -struct cred *credp; +int +afs_pageio(vp, pp, ui1, ui2, i1, credp) + struct vnode *vp; + struct page *pp; + u_int ui1, ui2; + int i1; + struct cred *credp; { afs_warn("afs_pageio: Not implemented\n"); return EINVAL; } -int afs_dumpctl(vp, i +int +afs_dumpctl(vp, i #ifdef AFS_SUN59_ENV - , blkp + , blkp #endif - ) -struct vnode *vp; -int i; + ) + struct vnode *vp; + int i; #ifdef AFS_SUN59_ENV -int *blkp; + int *blkp; #endif { afs_warn("afs_dumpctl: Not implemented\n"); @@ -1581,29 +1721,32 @@ int *blkp; } #ifdef AFS_SUN54_ENV -extern void afs_dispose(vp, p, fl, dn, cr) - struct vnode *vp; - struct page *p; - int fl, dn; - struct cred *cr; +extern void +afs_dispose(vp, p, fl, dn, cr) + struct vnode *vp; + struct page *p; + int fl, dn; + struct cred *cr; { fs_dispose(vp, p, fl, dn, cr); } -int afs_setsecattr(vp, vsecattr, flag, creds) -struct vnode *vp; -vsecattr_t *vsecattr; -int flag; -struct cred *creds; +int +afs_setsecattr(vp, vsecattr, flag, creds) + struct vnode *vp; + vsecattr_t *vsecattr; + int flag; + struct cred *creds; { return ENOSYS; } -int afs_getsecattr(vp, vsecattr, flag, creds) -struct vnode *vp; -vsecattr_t *vsecattr; -int flag; -struct cred *creds; +int +afs_getsecattr(vp, vsecattr, flag, creds) + struct vnode *vp; + vsecattr_t *vsecattr; + int flag; + struct cred *creds; { return fs_fab_acl(vp, vsecattr, flag, creds); } @@ -1619,52 +1762,52 @@ extern int afs_lockctl(); extern void gafs_inactive(); struct vnodeops Afs_vnodeops = { - gafs_open, - gafs_close, - afs_vmread, - afs_vmwrite, - afs_ioctl, - fs_setfl, - gafs_getattr, - gafs_setattr, - gafs_access, - gafs_lookup, - gafs_create, - gafs_remove, - gafs_link, - gafs_rename, - gafs_mkdir, - gafs_rmdir, - gafs_readdir, - gafs_symlink, - gafs_readlink, - gafs_fsync, - gafs_inactive, - gafs_fid, - afs_rwlock, - afs_rwunlock, - afs_seek, - afs_cmp, - afs_frlock, - afs_space, - afs_realvp, - afs_getpage, - afs_putpage, - afs_map, - afs_addmap, - afs_delmap, - fs_poll, - afs_dump, - afs_pathconf, - afs_pageio, - afs_dumpctl, + gafs_open, + gafs_close, + afs_vmread, + afs_vmwrite, + afs_ioctl, + fs_setfl, + gafs_getattr, + gafs_setattr, + gafs_access, + gafs_lookup, + gafs_create, + gafs_remove, + gafs_link, + gafs_rename, + gafs_mkdir, + gafs_rmdir, + gafs_readdir, + gafs_symlink, + gafs_readlink, + gafs_fsync, + gafs_inactive, + gafs_fid, + afs_rwlock, + afs_rwunlock, + afs_seek, + afs_cmp, + afs_frlock, + afs_space, + afs_realvp, + afs_getpage, + afs_putpage, + afs_map, + afs_addmap, + afs_delmap, + fs_poll, + afs_dump, + afs_pathconf, + afs_pageio, + afs_dumpctl, #ifdef AFS_SUN54_ENV - afs_dispose, - afs_setsecattr, - afs_getsecattr, + afs_dispose, + afs_setsecattr, + afs_getsecattr, #endif #if defined(AFS_SUN56_ENV) - fs_shrlock, + fs_shrlock, #endif }; struct vnodeops *afs_ops = &Afs_vnodeops; @@ -1672,9 +1815,9 @@ struct vnodeops *afs_ops = &Afs_vnodeops; gafs_open(avcp, aflags, acred) - register struct vcache **avcp; - afs_int32 aflags; - struct AFS_UCRED *acred; + register struct vcache **avcp; + afs_int32 aflags; + struct AFS_UCRED *acred; { register int code; @@ -1686,11 +1829,11 @@ gafs_open(avcp, aflags, acred) gafs_close(avc, aflags, count, offset, acred) - offset_t offset; - int count; - register struct vcache *avc; - afs_int32 aflags; - struct AFS_UCRED *acred; + offset_t offset; + int count; + register struct vcache *avc; + afs_int32 aflags; + struct AFS_UCRED *acred; { register int code; @@ -1702,10 +1845,10 @@ gafs_close(avc, aflags, count, offset, acred) gafs_getattr(avc, attrs, flags, acred) - int flags; - register struct vcache *avc; - register struct vattr *attrs; - struct AFS_UCRED *acred; + int flags; + register struct vcache *avc; + register struct vattr *attrs; + struct AFS_UCRED *acred; { register int code; @@ -1717,10 +1860,10 @@ gafs_getattr(avc, attrs, flags, acred) gafs_setattr(avc, attrs, flags, acred) - int flags; - register struct vcache *avc; - register struct vattr *attrs; - struct AFS_UCRED *acred; + int flags; + register struct vcache *avc; + register struct vattr *attrs; + struct AFS_UCRED *acred; { register int code; @@ -1732,10 +1875,10 @@ gafs_setattr(avc, attrs, flags, acred) gafs_access(avc, amode, flags, acred) - int flags; - register struct vcache *avc; - register afs_int32 amode; - struct AFS_UCRED *acred; + int flags; + register struct vcache *avc; + register afs_int32 amode; + struct AFS_UCRED *acred; { register int code; @@ -1747,12 +1890,12 @@ gafs_access(avc, amode, flags, acred) gafs_lookup(adp, aname, avcp, pnp, flags, rdir, acred) - struct pathname *pnp; - int flags; - struct vnode *rdir; - register struct vcache *adp, **avcp; - char *aname; - struct AFS_UCRED *acred; + struct pathname *pnp; + int flags; + struct vnode *rdir; + register struct vcache *adp, **avcp; + char *aname; + struct AFS_UCRED *acred; { register int code; @@ -1764,13 +1907,13 @@ gafs_lookup(adp, aname, avcp, pnp, flags, rdir, acred) gafs_create(adp, aname, attrs, aexcl, amode, avcp, acred) - register struct vcache *adp; - char *aname; - struct vattr *attrs; - enum vcexcl aexcl; - int amode; - struct vcache **avcp; - struct AFS_UCRED *acred; + register struct vcache *adp; + char *aname; + struct vattr *attrs; + enum vcexcl aexcl; + int amode; + struct vcache **avcp; + struct AFS_UCRED *acred; { register int code; @@ -1781,9 +1924,9 @@ gafs_create(adp, aname, attrs, aexcl, amode, avcp, acred) } gafs_remove(adp, aname, acred) - register struct vcache *adp; - char *aname; - struct AFS_UCRED *acred; + register struct vcache *adp; + char *aname; + struct AFS_UCRED *acred; { register int code; @@ -1794,10 +1937,10 @@ gafs_remove(adp, aname, acred) } gafs_link(adp, avc, aname, acred) - register struct vcache *avc; - register struct vcache *adp; - char *aname; - struct AFS_UCRED *acred; + register struct vcache *avc; + register struct vcache *adp; + char *aname; + struct AFS_UCRED *acred; { register int code; @@ -1808,9 +1951,9 @@ gafs_link(adp, avc, aname, acred) } gafs_rename(aodp, aname1, andp, aname2, acred) - register struct vcache *aodp, *andp; - char *aname1, *aname2; - struct AFS_UCRED *acred; + register struct vcache *aodp, *andp; + char *aname1, *aname2; + struct AFS_UCRED *acred; { register int code; @@ -1821,11 +1964,11 @@ gafs_rename(aodp, aname1, andp, aname2, acred) } gafs_mkdir(adp, aname, attrs, avcp, acred) - register struct vcache *adp; - register struct vcache **avcp; - char *aname; - struct vattr *attrs; - struct AFS_UCRED *acred; + register struct vcache *adp; + register struct vcache **avcp; + char *aname; + struct vattr *attrs; + struct AFS_UCRED *acred; { register int code; @@ -1837,10 +1980,10 @@ gafs_mkdir(adp, aname, attrs, avcp, acred) gafs_rmdir(adp, aname, cdirp, acred) - struct vnode *cdirp; - register struct vcache *adp; - char *aname; - struct AFS_UCRED *acred; + struct vnode *cdirp; + register struct vcache *adp; + char *aname; + struct AFS_UCRED *acred; { register int code; @@ -1852,25 +1995,25 @@ gafs_rmdir(adp, aname, cdirp, acred) gafs_readdir(avc, auio, acred, eofp) - int *eofp; - register struct vcache *avc; - struct uio *auio; - struct AFS_UCRED *acred; + int *eofp; + register struct vcache *avc; + struct uio *auio; + struct AFS_UCRED *acred; { register int code; AFS_GLOCK(); code = afs_readdir(avc, auio, acred, eofp); AFS_GUNLOCK(); - return (code); + return (code); } gafs_symlink(adp, aname, attrs, atargetName, acred) - register struct vcache *adp; - register char *atargetName; - char *aname; - struct vattr *attrs; - struct AFS_UCRED *acred; + register struct vcache *adp; + register char *atargetName; + char *aname; + struct vattr *attrs; + struct AFS_UCRED *acred; { register int code; @@ -1882,9 +2025,9 @@ gafs_symlink(adp, aname, attrs, atargetName, acred) gafs_readlink(avc, auio, acred) - register struct vcache *avc; - struct uio *auio; - struct AFS_UCRED *acred; + register struct vcache *avc; + struct uio *auio; + struct AFS_UCRED *acred; { register int code; @@ -1896,12 +2039,12 @@ gafs_readlink(avc, auio, acred) #ifdef AFS_SUN53_ENV gafs_fsync(avc, flag, acred) - int flag; + int flag; #else gafs_fsync(avc, acred) #endif - register struct vcache *avc; - struct AFS_UCRED *acred; + register struct vcache *avc; + struct AFS_UCRED *acred; { register int code; @@ -1915,26 +2058,29 @@ gafs_fsync(avc, acred) return (code); } -void afs_inactive(struct vcache *avc, struct AFS_UCRED *acred) +void +afs_inactive(struct vcache *avc, struct AFS_UCRED *acred) { struct vnode *vp = AFSTOV(avc); - if (afs_shuttingdown) return ; + if (afs_shuttingdown) + return; /* * In Solaris and HPUX s800 and HP-UX10.0 they actually call us with * v_count 1 on last reference! */ mutex_enter(&vp->v_lock); - if (avc->vrefCount <= 0) osi_Panic("afs_inactive : v_count <=0\n"); + if (avc->vrefCount <= 0) + osi_Panic("afs_inactive : v_count <=0\n"); /* * If more than 1 don't unmap the vnode but do decrement the ref count */ vp->v_count--; if (vp->v_count > 0) { - mutex_exit(&vp->v_lock); - return; - } + mutex_exit(&vp->v_lock); + return; + } mutex_exit(&vp->v_lock); /* @@ -1951,9 +2097,10 @@ void afs_inactive(struct vcache *avc, struct AFS_UCRED *acred) afs_InactiveVCache(avc, acred); } -void gafs_inactive(avc, acred) - register struct vcache *avc; - struct AFS_UCRED *acred; +void +gafs_inactive(avc, acred) + register struct vcache *avc; + struct AFS_UCRED *acred; { AFS_GLOCK(); afs_inactive(avc, acred); @@ -1962,8 +2109,8 @@ void gafs_inactive(avc, acred) gafs_fid(avc, fidpp) -struct vcache *avc; -struct fid **fidpp; + struct vcache *avc; + struct fid **fidpp; { register int code; @@ -1973,4 +2120,4 @@ struct fid **fidpp; return (code); } -#endif /* AFS_GLOBAL_SUNLOCK */ +#endif /* AFS_GLOBAL_SUNLOCK */ diff --git a/src/afs/SUNOS/osi_inode.h b/src/afs/SUNOS/osi_inode.h index a55f44dba..09b38b09a 100644 --- a/src/afs/SUNOS/osi_inode.h +++ b/src/afs/SUNOS/osi_inode.h @@ -1 +1 @@ -#error kernel code not supported on SunOS 4 +#error kernel code not supported on SunOS 4 diff --git a/src/afs/UKERNEL/afs_usrops.c b/src/afs/UKERNEL/afs_usrops.c index 966b52074..410713fa9 100644 --- a/src/afs/UKERNEL/afs_usrops.c +++ b/src/afs/UKERNEL/afs_usrops.c @@ -12,24 +12,25 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/UKERNEL/afs_usrops.c,v 1.1.1.10 2003/04/13 19:02:48 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/UKERNEL/afs_usrops.c,v 1.26 2004/05/10 13:51:16 shadow Exp $"); #ifdef UKERNEL -#include "../afs/sysincludes.h" /* Standard vendor system headers */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ #include -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_usrops.h" -#include "../afs/afs_stats.h" -#include "../afs/auth.h" -#include "../afs/cellconfig.h" -#include "../afs/vice.h" -#include "../afs/kautils.h" -#include "../afs/afsutil.h" -#include "../rx/rx_globals.h" +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs_usrops.h" +#include "afs/afs_stats.h" +#include "afs/auth.h" +#include "afs/cellconfig.h" +#include "afs/vice.h" +#include "afs/kautils.h" +#include "afs/afsutil.h" +#include "rx/rx_globals.h" #define VFS 1 #undef VIRTUE @@ -39,6 +40,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/UKERNEL/afs_usrops.c,v 1.1.1.10 200 #define AFSLOGFILE "AFSLog" #define DCACHEFILE "CacheItems" #define VOLINFOFILE "VolumeItems" +#define CELLINFOFILE "CellItems" #define MAXIPADDRS 64 #ifndef MIN @@ -62,40 +64,41 @@ struct usr_vfs afs_RootVfs; struct usr_vnode *afs_RootVnode = NULL; struct usr_vnode *afs_CurrentDir = NULL; -afs_int32 cacheBlocks; /* Num blocks in cache */ -afs_int32 cacheFiles = 1000; /* Num files in workstation cache */ -afs_int32 cacheStatEntries = 300; /* Num of stat cache entries */ -char cacheBaseDir[1024]; /* AFS cache directory */ -char confDir[1024]; /* AFS configuration directory */ -char afs_mountDir[1024]; /* AFS mount point */ -int afs_mountDirLen; /* strlen of AFS mount point */ -char fullpn_DCacheFile[1024]; /* Full pathname of DCACHEFILE */ -char fullpn_VolInfoFile[1024]; /* Full pathname of VOLINFOFILE */ -char fullpn_AFSLogFile[1024]; /* Full pathname of AFSLOGFILE */ -char fullpn_CacheInfo[1024]; /* Full pathname of CACHEINFO */ -char fullpn_VFile[1024]; /* Full pathname of data cache files */ -char *vFileNumber; /* Ptr to number in file pathname */ +afs_int32 cacheBlocks; /* Num blocks in cache */ +afs_int32 cacheFiles = 1000; /* Num files in workstation cache */ +afs_int32 cacheStatEntries = 300; /* Num of stat cache entries */ +char cacheBaseDir[1024]; /* AFS cache directory */ +char confDir[1024]; /* AFS configuration directory */ +char afs_mountDir[1024]; /* AFS mount point */ +int afs_mountDirLen; /* strlen of AFS mount point */ +char fullpn_DCacheFile[1024]; /* Full pathname of DCACHEFILE */ +char fullpn_VolInfoFile[1024]; /* Full pathname of VOLINFOFILE */ +char fullpn_CellInfoFile[1024]; /* Full pathname of CELLINFOFILE */ +char fullpn_AFSLogFile[1024]; /* Full pathname of AFSLOGFILE */ +char fullpn_CacheInfo[1024]; /* Full pathname of CACHEINFO */ +char fullpn_VFile[1024]; /* Full pathname of data cache files */ +char *vFileNumber; /* Ptr to number in file pathname */ char rootVolume[64] = "root.afs"; /* AFS root volume name */ -afs_int32 isHomeCell; /* Is current cell info for home cell */ -afs_int32 lookingForHomeCell; /* Are we still looking for home cell */ -int createAndTrunc = O_CREAT | O_TRUNC; /* Create & truncate on open */ -int ownerRWmode = 0600; /* Read/write OK by owner */ -static int nDaemons = 2; /* Number of background daemons */ -static int chunkSize = 0; /* 2^chunkSize bytes per chunk */ -static int dCacheSize = 300; /* # of dcache entries */ -static int vCacheSize = 50; /* # of volume cache entries */ -static int cacheFlags = 0; /* Flags to cache manager */ -static int preallocs = 400; /* Def # of allocated memory blocks */ -int afsd_verbose = 0; /* Are we being chatty? */ -int afsd_debug = 0; /* Are we printing debugging info? */ -int afsd_CloseSynch = 0; /* Are closes synchronous or not? */ +afs_int32 isHomeCell; /* Is current cell info for home cell */ +int createAndTrunc = O_CREAT | O_TRUNC; /* Create & truncate on open */ +int ownerRWmode = 0600; /* Read/write OK by owner */ +static int nDaemons = 2; /* Number of background daemons */ +static int chunkSize = 0; /* 2^chunkSize bytes per chunk */ +static int dCacheSize = 300; /* # of dcache entries */ +static int vCacheSize = 50; /* # of volume cache entries */ +static int cacheFlags = 0; /* Flags to cache manager */ +static int preallocs = 400; /* Def # of allocated memory blocks */ +int afsd_verbose = 0; /* Are we being chatty? */ +int afsd_debug = 0; /* Are we printing debugging info? */ +int afsd_CloseSynch = 0; /* Are closes synchronous or not? */ #define AFSD_INO_T afs_uint32 -char **pathname_for_V; /* Array of cache file pathnames */ -int missing_DCacheFile = 1; /* Is the DCACHEFILE missing? */ -int missing_VolInfoFile = 1; /* Is the VOLINFOFILE missing? */ -struct afs_cacheParams cparams; /* params passed to cache manager */ -struct afsconf_dir *afs_cdir; /* config dir */ +char **pathname_for_V; /* Array of cache file pathnames */ +int missing_DCacheFile = 1; /* Is the DCACHEFILE missing? */ +int missing_VolInfoFile = 1; /* Is the VOLINFOFILE missing? */ +int missing_CellInfoFile = 1; +struct afs_cacheParams cparams; /* params passed to cache manager */ +struct afsconf_dir *afs_cdir; /* config dir */ static int HandleMTab(); @@ -114,7 +117,7 @@ char V = 'V'; long V = 'V'; #endif /* AFS_USR_OSF_ENV */ -struct usr_ucred afs_osi_cred; +struct usr_ucred afs_osi_cred, *afs_osi_credp; usr_mutex_t afs_global_lock; usr_thread_t afs_global_owner; usr_mutex_t rx_global_lock; @@ -128,7 +131,7 @@ afs_lock_t osi_fsplock; void *vnodefops; #ifndef NETSCAPE_NSAPI - + /* * Mutex and condition variable used to implement sleep */ @@ -145,14 +148,14 @@ int call_syscall(long, long, long, long, long, long); * osi_Sleep/osi_Wakeup and osi_Wait/osi_Wakeup */ typedef struct osi_wait { - caddr_t addr; - usr_cond_t cond; - int flag; - struct osi_wait *next; - struct osi_wait *prev; - time_t expiration; - struct osi_wait *timedNext; - struct osi_wait *timedPrev; + caddr_t addr; + usr_cond_t cond; + int flag; + struct osi_wait *next; + struct osi_wait *prev; + time_t expiration; + struct osi_wait *timedNext; + struct osi_wait *timedPrev; } osi_wait_t; /* @@ -169,16 +172,15 @@ osi_wait_t *osi_timedwait_head; osi_wait_t *osi_timedwait_tail; struct { - osi_wait_t *head; - osi_wait_t *tail; + osi_wait_t *head; + osi_wait_t *tail; } osi_waithash_table[OSI_WAITHASH_SIZE]; /* * Never call afs_brelse */ -int ufs_brelse(vp, bp) -struct usr_vnode *vp; -struct usr_buf *bp; +int +ufs_brelse(struct usr_vnode *vp, struct usr_buf *bp) { usr_assert(0); } @@ -186,14 +188,14 @@ struct usr_buf *bp; /* * I am not sure what to do with these, they assert for now */ -int iodone(bp) -struct usr_buf *bp; +int +iodone(struct usr_buf *bp) { usr_assert(0); } -struct usr_file *getf(fd) -int fd; +struct usr_file * +getf(int fd) { usr_assert(0); } @@ -201,14 +203,14 @@ int fd; /* * Every user is a super user */ -int afs_osi_suser(credp) -struct usr_ucred *credp; +int +afs_osi_suser(void *credp) { return 1; } -int afs_suser(credp) -struct usr_ucred *credp; +int +afs_suser(void *credp) { return 1; } @@ -217,17 +219,18 @@ struct usr_ucred *credp; * These are no-ops in user space */ -int afs_osi_SetTime(atv) -osi_timeval_t *atv; +void +afs_osi_SetTime(osi_timeval_t * atv) { - return 0; + return; } /* * xflock should never fall through, the only files we know * about are AFS files */ -int usr_flock() +int +usr_flock(void) { usr_assert(0); } @@ -236,7 +239,8 @@ int usr_flock() * ioctl should never fall through, the only files we know * about are AFS files */ -int usr_ioctl() +int +usr_ioctl(void) { usr_assert(0); } @@ -244,22 +248,26 @@ int usr_ioctl() /* * We do not support the inode related system calls */ -int afs_syscall_icreate() +int +afs_syscall_icreate(void) { usr_assert(0); } -int afs_syscall_iincdec() +int +afs_syscall_iincdec(void) { usr_assert(0); } -int afs_syscall_iopen() +int +afs_syscall_iopen(void) { usr_assert(0); } -int afs_syscall_ireadwrite() +int +afs_syscall_ireadwrite(void) { usr_assert(0); } @@ -268,22 +276,26 @@ int afs_syscall_ireadwrite() * these routines are referenced in the vfsops structure, but * should never get called */ -int vno_close() +int +vno_close(void) { usr_assert(0); } -int vno_ioctl() +int +vno_ioctl(void) { usr_assert(0); } -int vno_rw() +int +vno_rw(void) { usr_assert(0); } -int vno_select() +int +vno_select(void) { usr_assert(0); } @@ -291,11 +303,8 @@ int vno_select() /* * uiomove copies data between kernel buffers and uio buffers */ -int usr_uiomove(kbuf, n, rw, uio) -char *kbuf; -int n; -int rw; -struct usr_uio *uio; +int +usr_uiomove(char *kbuf, int n, int rw, struct usr_uio *uio) { int nio; int len; @@ -312,7 +321,7 @@ struct usr_uio *uio; * copy the data */ ptr = kbuf; - while(nio > 0 && n > 0) { + while (nio > 0 && n > 0) { len = MIN(n, iovp->iov_len); if (rw == UIO_READ) { memcpy(iovp->iov_base, ptr, len); @@ -337,8 +346,8 @@ struct usr_uio *uio; /* * routines to manage user credentials */ -struct usr_ucred *usr_crcopy(credp) -struct usr_ucred *credp; +struct usr_ucred * +usr_crcopy(struct usr_ucred *credp) { struct usr_ucred *newcredp; @@ -348,7 +357,8 @@ struct usr_ucred *credp; return newcredp; } -struct usr_ucred *usr_crget() +struct usr_ucred * +usr_crget(void) { struct usr_ucred *newcredp; @@ -357,8 +367,8 @@ struct usr_ucred *usr_crget() return newcredp; } -int usr_crfree(credp) -struct usr_ucred *credp; +int +usr_crfree(struct usr_ucred *credp) { credp->cr_ref--; if (credp->cr_ref == 0) { @@ -366,18 +376,18 @@ struct usr_ucred *credp; } } -int usr_crhold(credp) -struct usr_ucred *credp; +int +usr_crhold(struct usr_ucred *credp) { credp->cr_ref++; } -void usr_vattr_null(vap) -struct usr_vattr *vap; +void +usr_vattr_null(struct usr_vattr *vap) { int n; char *cp; - + n = sizeof(struct usr_vattr); cp = (char *)vap; while (n--) { @@ -390,7 +400,8 @@ struct usr_vattr *vap; * kernel environment for each thread. The user structure * is stored in the thread specific data. */ -void uafs_InitThread() +void +uafs_InitThread(void) { int st; struct usr_user *uptr; @@ -400,13 +411,14 @@ void uafs_InitThread() * allocate the data block, so pthread_finish can free the buffer * when this thread terminates. */ - uptr = (struct usr_user *)malloc(sizeof(struct usr_user) + - sizeof(struct usr_ucred)); + uptr = + (struct usr_user *)malloc(sizeof(struct usr_user) + + sizeof(struct usr_ucred)); usr_assert(uptr != NULL); uptr->u_error = 0; uptr->u_prio = 0; uptr->u_procp = afs_global_procp; - uptr->u_cred = (struct usr_ucred *)(uptr+1); + uptr->u_cred = (struct usr_ucred *)(uptr + 1); *uptr->u_cred = *afs_global_ucredp; st = usr_setspecific(afs_global_u_key, (void *)uptr); usr_assert(st == 0); @@ -417,13 +429,14 @@ void uafs_InitThread() * this routine is used to implement the global 'u' structure. Initializes * the thread if needed. */ -struct usr_user *get_user_struct() +struct usr_user * +get_user_struct(void) { struct usr_user *uptr; int st; st = usr_getspecific(afs_global_u_key, (void **)&uptr); usr_assert(st == 0); - if(uptr == NULL) { + if (uptr == NULL) { uafs_InitThread(); st = usr_getspecific(afs_global_u_key, (void **)&uptr); usr_assert(st == 0); @@ -441,8 +454,8 @@ struct usr_user *get_user_struct() /* * Sleep on an event */ -int afs_osi_Sleep(x) -caddr_t x; +void +afs_osi_Sleep(void *x) { int index; osi_wait_t *waitp; @@ -458,7 +471,7 @@ caddr_t x; } index = WAITHASH(x); if (osi_waithash_avail == NULL) { - waitp = (osi_wait_t *)afs_osi_Alloc(sizeof(osi_wait_t)); + waitp = (osi_wait_t *) afs_osi_Alloc(sizeof(osi_wait_t)); usr_cond_init(&waitp->cond); } else { waitp = osi_waithash_avail; @@ -487,8 +500,15 @@ caddr_t x; } } -int afs_osi_Wakeup(x) -caddr_t x; +int +afs_osi_SleepSig(void *x) +{ + afs_osi_Sleep(x); + return 0; +} + +int +afs_osi_Wakeup(void *x) { int index; osi_wait_t *waitp; @@ -506,10 +526,8 @@ caddr_t x; usr_mutex_unlock(&osi_waitq_lock); } -int afs_osi_Wait(msec, handle, intok) -afs_int32 msec; -struct afs_osi_WaitHandle *handle; -int intok; +int +afs_osi_Wait(afs_int32 msec, struct afs_osi_WaitHandle *handle, int intok) { int index; osi_wait_t *waitp; @@ -531,7 +549,7 @@ int intok; ret = 0; if (glockOwner) { AFS_GLOCK(); - } + } if (rxGlockOwner) { AFS_RXGLOCK(); } @@ -543,22 +561,22 @@ int intok; if (rxGlockOwner) { AFS_RXGUNLOCK(); } - index = WAITHASH((caddr_t)handle); + index = WAITHASH((caddr_t) handle); if (osi_waithash_avail == NULL) { - waitp = (osi_wait_t *)afs_osi_Alloc(sizeof(osi_wait_t)); + waitp = (osi_wait_t *) afs_osi_Alloc(sizeof(osi_wait_t)); usr_cond_init(&waitp->cond); } else { waitp = osi_waithash_avail; osi_waithash_avail = osi_waithash_avail->next; } - waitp->addr = (caddr_t)handle; + waitp->addr = (caddr_t) handle; waitp->flag = 0; DLL_INSERT_TAIL(waitp, osi_waithash_table[index].head, osi_waithash_table[index].tail, next, prev); tv.tv_sec += time(NULL); - waitp->expiration = tv.tv_sec + ((tv.tv_nsec == 0)?0:1); + waitp->expiration = tv.tv_sec + ((tv.tv_nsec == 0) ? 0 : 1); DLL_INSERT_TAIL(waitp, osi_timedwait_head, osi_timedwait_tail, - timedNext, timedPrev); + timedNext, timedPrev); usr_cond_wait(&waitp->cond, &osi_waitq_lock); if (waitp->flag) { ret = 2; @@ -567,8 +585,8 @@ int intok; } DLL_DELETE(waitp, osi_waithash_table[index].head, osi_waithash_table[index].tail, next, prev); - DLL_DELETE(waitp, osi_timedwait_head, osi_timedwait_tail, - timedNext, timedPrev); + DLL_DELETE(waitp, osi_timedwait_head, osi_timedwait_tail, timedNext, + timedPrev); waitp->next = osi_waithash_avail; osi_waithash_avail = waitp; usr_mutex_unlock(&osi_waitq_lock); @@ -582,17 +600,18 @@ int intok; return ret; } -void afs_osi_CancelWait(handle) -struct afs_osi_WaitHandle *handle; +void +afs_osi_CancelWait(struct afs_osi_WaitHandle *handle) { - afs_osi_Wakeup((caddr_t)handle); + afs_osi_Wakeup(handle); } /* * Netscape NSAPI doesn't have a cond_timed_wait, so we need * to explicitly signal cond_timed_waits when their timers expire */ -int afs_osi_CheckTimedWaits() +int +afs_osi_CheckTimedWaits(void) { time_t curTime; osi_wait_t *waitp; @@ -629,19 +648,16 @@ int max_osi_files = 0; * Allocate a slot in the file table if there is not one there already, * copy in the file name and kludge up the vnode and inode structures */ -int lookupname(fnamep, segflg, followlink, dirvpp, compvpp) -char *fnamep; -int segflg; -int followlink; -struct usr_vnode **dirvpp; -struct usr_vnode **compvpp; +int +lookupname(char *fnamep, int segflg, int followlink, + struct usr_vnode **dirvpp, struct usr_vnode **compvpp) { int i; int code; struct usr_inode *ip; struct usr_vnode *vp; - /*usr_assert(followlink == 0);*/ + /*usr_assert(followlink == 0); */ usr_assert(dirvpp == NULL); /* @@ -656,7 +672,7 @@ struct usr_vnode **compvpp; usr_mutex_lock(&osi_inode_lock); - for (i = 0 ; i < n_osi_files ; i++) { + for (i = 0; i < n_osi_files; i++) { if (strcmp(fnamep, osi_file_table[i].name) == 0) { *compvpp = &osi_file_table[i].i_node.i_vnode; (*compvpp)->v_count++; @@ -670,12 +686,12 @@ struct usr_vnode **compvpp; return ENOSPC; } - osi_file_table[n_osi_files].name = afs_osi_Alloc(strlen(fnamep)+1); + osi_file_table[n_osi_files].name = afs_osi_Alloc(strlen(fnamep) + 1); usr_assert(osi_file_table[n_osi_files].name != NULL); strcpy(osi_file_table[n_osi_files].name, fnamep); ip = &osi_file_table[i].i_node; vp = &ip->i_vnode; - vp->v_data = (caddr_t)ip; + vp->v_data = (caddr_t) ip; ip->i_dev = -1; n_osi_files++; ip->i_number = n_osi_files; @@ -688,8 +704,8 @@ struct usr_vnode **compvpp; /* * open a file given its i-node number */ -void *osi_UFSOpen(ino) -int ino; +void * +osi_UFSOpen(afs_int32 ino) { int rc; struct osi_file *fp; @@ -705,7 +721,7 @@ int ino; AFS_GUNLOCK(); fp = (struct osi_file *)afs_osi_Alloc(sizeof(struct osi_file)); usr_assert(fp != NULL); - fp->fd = open(osi_file_table[ino-1].name, O_RDWR|O_CREAT, 0); + fp->fd = open(osi_file_table[ino - 1].name, O_RDWR | O_CREAT, 0); if (fp->fd < 0) { u.u_error = errno; afs_osi_Free((char *)fp, sizeof(struct osi_file)); @@ -728,8 +744,8 @@ int ino; return fp; } -int osi_UFSClose(fp) -struct osi_file *fp; +int +osi_UFSClose(struct osi_file *fp) { int rc; @@ -748,9 +764,8 @@ struct osi_file *fp; return 0; } -int osi_UFSTruncate(fp, len) -struct osi_file *fp; -int len; +int +osi_UFSTruncate(struct osi_file *fp, afs_int32 len) { int rc; @@ -768,11 +783,8 @@ int len; return 0; } -int afs_osi_Read(fp, offset, buf, len) -struct osi_file *fp; -int offset; -char *buf; -int len; +int +afs_osi_Read(struct osi_file *fp, int offset, void *buf, afs_int32 len) { int rc, ret; int code; @@ -810,11 +822,8 @@ int len; return ret; } -int afs_osi_Write(fp, offset, buf, len) -struct osi_file *fp; -int offset; -char *buf; -int len; +int +afs_osi_Write(struct osi_file *fp, afs_int32 offset, void *buf, afs_int32 len) { int rc, ret; int code; @@ -852,9 +861,8 @@ int len; return ret; } -int afs_osi_Stat(fp, stp) -struct osi_file *fp; -struct osi_stat *stp; +int +afs_osi_Stat(struct osi_file *fp, struct osi_stat *stp) { int rc; struct stat st; @@ -864,7 +872,7 @@ struct osi_stat *stp; if (rc < 0) { u.u_error = errno; AFS_GLOCK(); - return -1; + return -1; } stp->size = st.st_size; stp->blksize = st.st_blksize; @@ -877,12 +885,9 @@ struct osi_stat *stp; /* * VOP_RDWR routine */ -int afs_osi_VOP_RDWR( - struct usr_vnode *vnodeP, - struct usr_uio *uioP, - int rw, - int flags, - struct usr_ucred* credP) +int +afs_osi_VOP_RDWR(struct usr_vnode *vnodeP, struct usr_uio *uioP, int rw, + int flags, struct usr_ucred *credP) { int rc; struct osi_file *fp = (struct osi_file *)vnodeP; @@ -895,13 +900,11 @@ int afs_osi_VOP_RDWR( if (rw == UIO_WRITE) { usr_assert(uioP->uio_fmode == FWRITE); - rc = afs_osi_Write(fp, uioP->uio_offset, - uioP->uio_iov[0].iov_base, + rc = afs_osi_Write(fp, uioP->uio_offset, uioP->uio_iov[0].iov_base, uioP->uio_iov[0].iov_len); } else { usr_assert(uioP->uio_fmode == FREAD); - rc = afs_osi_Read(fp, uioP->uio_offset, - uioP->uio_iov[0].iov_base, + rc = afs_osi_Read(fp, uioP->uio_offset, uioP->uio_iov[0].iov_base, uioP->uio_iov[0].iov_len); } if (rc < 0) { @@ -922,126 +925,138 @@ int afs_osi_VOP_RDWR( static char *afs_check_string1 = "UAFS"; static char *afs_check_string2 = "AFS_OSI_"; -void *afs_osi_Alloc(size_t size) +void * +afs_osi_Alloc(size_t size) { return malloc(size); } -void afs_osi_Free(void *ptr, size_t size) +void +afs_osi_Free(void *ptr, size_t size) { free(ptr); } -void afs_osi_FreeStr(char *ptr) +void +afs_osi_FreeStr(char *ptr) { free(ptr); } -void *osi_AllocLargeSpace(size_t size) +void * +osi_AllocLargeSpace(size_t size) { AFS_STATCNT(osi_AllocLargeSpace); return afs_osi_Alloc(size); } -void osi_FreeLargeSpace(void *ptr) +void +osi_FreeLargeSpace(void *ptr) { AFS_STATCNT(osi_FreeLargeSpace); afs_osi_Free(ptr, 0); } -void *osi_AllocSmallSpace(size_t size) +void * +osi_AllocSmallSpace(size_t size) { AFS_STATCNT(osi_AllocSmallSpace); return afs_osi_Alloc(size); } -void osi_FreeSmallSpace(void *ptr) +void +osi_FreeSmallSpace(void *ptr) { AFS_STATCNT(osi_FreeSmallSpace); afs_osi_Free(ptr, 0); } -void shutdown_osi() +void +shutdown_osi(void) { AFS_STATCNT(shutdown_osi); return; } -void shutdown_osinet() +void +shutdown_osinet(void) { AFS_STATCNT(shutdown_osinet); return; } -void shutdown_osifile() +void +shutdown_osifile(void) { AFS_STATCNT(shutdown_osifile); return; } -int afs_nfsclient_init() +int +afs_nfsclient_init(void) { return 0; } -void shutdown_nfsclnt() +void +shutdown_nfsclnt(void) { return; } -int afs_osi_Invisible() +void +afs_osi_Invisible(void) { - return 0; + return; } -int osi_GetTime(tv) -struct timeval *tv; +int +osi_GetTime(struct timeval *tv) { gettimeofday(tv, NULL); return 0; } -int osi_SetTime(tv) -struct timeval *tv; +int +osi_SetTime(struct timeval *tv) { return 0; } -int osi_Active(avc) -struct vcache *avc; +int +osi_Active(struct vcache *avc) { AFS_STATCNT(osi_Active); - if (avc->opens > 0) return(1); + if (avc->opens > 0) + return (1); return 0; } -int afs_osi_MapStrategy(aproc, bp) -int (*aproc)(); -struct usr_buf *bp; +int +afs_osi_MapStrategy(int (*aproc) (), struct usr_buf *bp) { afs_int32 returnCode; - returnCode = (*aproc)(bp); + returnCode = (*aproc) (bp); return returnCode; } -osi_FlushPages(avc, credp) - register struct vcache *avc; - struct AFS_UCRED *credp; +void +osi_FlushPages(register struct vcache *avc, struct AFS_UCRED *credp) { - ObtainSharedLock(&avc->lock,555); - if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0) || - ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) { + ObtainSharedLock(&avc->lock, 555); + if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0) + || ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) { ReleaseSharedLock(&avc->lock); return; } - UpgradeSToWLock(&avc->lock,565); + UpgradeSToWLock(&avc->lock, 565); hset(avc->mapDV, avc->m.DataVersion); ReleaseWriteLock(&avc->lock); return; } -osi_FlushText_really(vp) - register struct vcache *vp; +void +osi_FlushText_really(register struct vcache *vp) { if (hcmp(vp->m.DataVersion, vp->flushDV) > 0) { hset(vp->flushDV, vp->m.DataVersion); @@ -1049,21 +1064,20 @@ osi_FlushText_really(vp) return; } -int osi_SyncVM(avc) -struct vcache *avc; +int +osi_SyncVM(struct vcache *avc) { return 0; } -void osi_ReleaseVM(avc, len, credp) -struct vcache *avc; -int len; -struct usr_ucred *credp; +void +osi_ReleaseVM(struct vcache *avc, int len, struct usr_ucred *credp) { return; } -void osi_Init() +void +osi_Init(void) { int i; int rc; @@ -1074,7 +1088,7 @@ void osi_Init() */ max_osi_files = cacheFiles + 100; osi_file_table = (osi_file_table_t *) - afs_osi_Alloc(max_osi_files * sizeof(osi_file_table_t)); + afs_osi_Alloc(max_osi_files * sizeof(osi_file_table_t)); usr_assert(osi_file_table != NULL); #ifndef NETSCAPE_NSAPI @@ -1089,7 +1103,7 @@ void osi_Init() /* * Initialize the hash table used for sleep/wakeup */ - for (i = 0 ; i < OSI_WAITHASH_SIZE ; i++) { + for (i = 0; i < OSI_WAITHASH_SIZE; i++) { DLL_INIT_LIST(osi_waithash_table[i].head, osi_waithash_table[i].tail); } DLL_INIT_LIST(osi_timedwait_head, osi_timedwait_tail); @@ -1098,7 +1112,7 @@ void osi_Init() /* * Initialize the AFS file table */ - for (i = 0 ; i < MAX_OSI_FILES ; i++) { + for (i = 0; i < MAX_OSI_FILES; i++) { afs_FileTable[i] = NULL; } @@ -1115,6 +1129,7 @@ void osi_Init() * Initialize the AFS OSI credentials */ afs_osi_cred = *afs_global_ucredp; + afs_osi_credp = &afs_osi_cred; } /* ParseArgs is now obsolete, being handled by cmd */ @@ -1142,12 +1157,12 @@ void osi_Init() * None. *------------------------------------------------------------------------*/ -int GetVFileNumber(fname) - char *fname; +int +GetVFileNumber(char *fname) { - int computedVNumber; /*The computed file number we return*/ - int filenameLen; /*Number of chars in filename*/ - int currDigit; /*Current digit being processed*/ + int computedVNumber; /*The computed file number we return */ + int filenameLen; /*Number of chars in filename */ + int currDigit; /*Current digit being processed */ /* * The filename must have at least two characters, the first of which must be a ``V'' @@ -1155,11 +1170,11 @@ int GetVFileNumber(fname) */ filenameLen = strlen(fname); if (filenameLen < 2) - return(-1); + return (-1); if (fname[0] != 'V') - return(-1); + return (-1); if ((filenameLen > 2) && (fname[1] == '0')) - return(-1); + return (-1); /* * Scan through the characters in the given filename, failing immediately if a non-digit @@ -1167,7 +1182,7 @@ int GetVFileNumber(fname) */ for (currDigit = 1; currDigit < filenameLen; currDigit++) if (isdigit(fname[currDigit]) == 0) - return(-1); + return (-1); /* * All relevant characters are digits. Pull out the decimal number they represent. @@ -1175,9 +1190,9 @@ int GetVFileNumber(fname) */ computedVNumber = atoi(++fname); if (computedVNumber < cacheFiles) - return(computedVNumber); + return (computedVNumber); else - return(-1); + return (-1); } /*--------------------------------------------------------------------- @@ -1201,30 +1216,30 @@ int GetVFileNumber(fname) * As described. *------------------------------------------------------------------------*/ -int CreateCacheFile(fname) - char *fname; +int +CreateCacheFile(char *fname) { - static char rn[] = "CreateCacheFile"; /*Routine name*/ - int cfd; /*File descriptor to AFS cache file*/ - int closeResult; /*Result of close()*/ + static char rn[] = "CreateCacheFile"; /*Routine name */ + int cfd; /*File descriptor to AFS cache file */ + int closeResult; /*Result of close() */ if (afsd_verbose) - printf("%s: Creating cache file '%s'\n", - rn, fname); + printf("%s: Creating cache file '%s'\n", rn, fname); cfd = open(fname, createAndTrunc, ownerRWmode); - if (cfd <= 0) { - printf("%s: Can't create '%s', error return is %d (%d)\n", - rn, fname, cfd, errno); - return(-1); + if (cfd <= 0) { + printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname, + cfd, errno); + return (-1); } closeResult = close(cfd); - if (closeResult) { - printf("%s: Can't close newly-created AFS cache file '%s' (code %d)\n", - rn, fname, errno); - return(-1); + if (closeResult) { + printf + ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n", + rn, fname, errno); + return (-1); } - return(0); + return (0); } /*--------------------------------------------------------------------- @@ -1255,38 +1270,37 @@ int CreateCacheFile(fname) * delete files as explained above. *------------------------------------------------------------------------*/ -int SweepAFSCache(vFilesFound) - int *vFilesFound; +int +SweepAFSCache(int *vFilesFound) { - static char rn[] = "SweepAFSCache"; /*Routine name*/ - char fullpn_FileToDelete[1024]; /*File to be deleted from cache*/ - char *fileToDelete; /*Ptr to last component of above*/ - DIR *cdirp; /*Ptr to cache directory structure*/ + static char rn[] = "SweepAFSCache"; /*Routine name */ + char fullpn_FileToDelete[1024]; /*File to be deleted from cache */ + char *fileToDelete; /*Ptr to last component of above */ + DIR *cdirp; /*Ptr to cache directory structure */ #undef dirent - struct dirent *currp; /*Current directory entry*/ - int vFileNum; /*Data cache file's associated number*/ + struct dirent *currp; /*Current directory entry */ + int vFileNum; /*Data cache file's associated number */ if (cacheFlags & AFSCALL_INIT_MEMCACHE) { if (afsd_debug) - printf("%s: Memory Cache, no cache sweep done\n"); + printf("%s: Memory Cache, no cache sweep done\n", rn); *vFilesFound = 0; return 0; } if (afsd_debug) - printf("%s: Opening cache directory '%s'\n", - rn, cacheBaseDir); + printf("%s: Opening cache directory '%s'\n", rn, cacheBaseDir); - if (chmod(cacheBaseDir, 0700)) { /* force it to be 700 */ - printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", - rn, cacheBaseDir); + if (chmod(cacheBaseDir, 0700)) { /* force it to be 700 */ + printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn, + cacheBaseDir); return (-1); } cdirp = opendir(cacheBaseDir); - if (cdirp == (DIR *)0) { - printf("%s: Can't open AFS cache directory, '%s'.\n", - rn, cacheBaseDir); - return(-1); + if (cdirp == (DIR *) 0) { + printf("%s: Can't open AFS cache directory, '%s'.\n", rn, + cacheBaseDir); + return (-1); } /* @@ -1297,13 +1311,11 @@ int SweepAFSCache(vFilesFound) sprintf(fullpn_FileToDelete, "%s/", cacheBaseDir); fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete); - for (currp = readdir(cdirp); currp; currp = readdir(cdirp)) - { + for (currp = readdir(cdirp); currp; currp = readdir(cdirp)) { if (afsd_debug) { - printf("%s: Current directory entry:\n", - rn); - printf("\tinode=%d, reclen=%d, name='%s'\n", - currp->d_ino, currp->d_reclen, currp->d_name); + printf("%s: Current directory entry:\n", rn); + printf("\tinode=%d, reclen=%d, name='%s'\n", currp->d_ino, + currp->d_reclen, currp->d_name); } /* @@ -1315,43 +1327,41 @@ int SweepAFSCache(vFilesFound) * Found a valid data cache filename. Remember this file's name * and bump the number of files found. */ - pathname_for_V[vFileNum] = afs_osi_Alloc(strlen(currp->d_name) + - strlen(cacheBaseDir) + 2); + pathname_for_V[vFileNum] = + afs_osi_Alloc(strlen(currp->d_name) + strlen(cacheBaseDir) + + 2); usr_assert(pathname_for_V[vFileNum] != NULL); - sprintf(pathname_for_V[vFileNum], "%s/%s", - cacheBaseDir, currp->d_name); + sprintf(pathname_for_V[vFileNum], "%s/%s", cacheBaseDir, + currp->d_name); (*vFilesFound)++; - } - else if (strcmp(currp->d_name, DCACHEFILE) == 0) { + } else if (strcmp(currp->d_name, DCACHEFILE) == 0) { /* * Found the file holding the dcache entries. */ missing_DCacheFile = 0; - } - else if (strcmp(currp->d_name, VOLINFOFILE) == 0) { + } else if (strcmp(currp->d_name, VOLINFOFILE) == 0) { /* * Found the file holding the volume info. */ missing_VolInfoFile = 0; - } - else if ((strcmp(currp->d_name, ".") == 0) || - (strcmp(currp->d_name, "..") == 0) || - (strcmp(currp->d_name, "lost+found") == 0)) { + } else if (strcmp(currp->d_name, CELLINFOFILE) == 0) { + missing_CellInfoFile = 0; + } else if ((strcmp(currp->d_name, ".") == 0) + || (strcmp(currp->d_name, "..") == 0) + || (strcmp(currp->d_name, "lost+found") == 0)) { /* * Don't do anything - this file is legit, and is to be left alone. */ - } - else { + } else { /* * This file doesn't belong in the cache. Nuke it. */ sprintf(fileToDelete, "%s", currp->d_name); if (afsd_verbose) - printf("%s: Deleting '%s'\n", - rn, fullpn_FileToDelete); + printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete); if (unlink(fullpn_FileToDelete)) { - printf("%s: Can't unlink '%s', errno is %d\n", - rn, fullpn_FileToDelete, errno); + printf("%s: Can't unlink '%s', errno is %d\n", rn, + fullpn_FileToDelete, errno); } } } @@ -1361,19 +1371,21 @@ int SweepAFSCache(vFilesFound) */ if (missing_DCacheFile) { if (afsd_verbose) - printf("%s: Creating '%s'\n", - rn, fullpn_DCacheFile); + printf("%s: Creating '%s'\n", rn, fullpn_DCacheFile); if (CreateCacheFile(fullpn_DCacheFile)) - printf("%s: Can't create '%s'\n", - rn, fullpn_DCacheFile); + printf("%s: Can't create '%s'\n", rn, fullpn_DCacheFile); } if (missing_VolInfoFile) { if (afsd_verbose) - printf("%s: Creating '%s'\n", - rn, fullpn_VolInfoFile); + printf("%s: Creating '%s'\n", rn, fullpn_VolInfoFile); if (CreateCacheFile(fullpn_VolInfoFile)) - printf("%s: Can't create '%s'\n", - rn, fullpn_VolInfoFile); + printf("%s: Can't create '%s'\n", rn, fullpn_VolInfoFile); + } + if (missing_CellInfoFile) { + if (afsd_verbose) + printf("%s: Creating '%s'\n", rn, fullpn_CellInfoFile); + if (CreateCacheFile(fullpn_CellInfoFile)) + printf("%s: Can't create '%s'\n", rn, fullpn_CellInfoFile); } if (*vFilesFound < cacheFiles) { @@ -1382,14 +1394,12 @@ int SweepAFSCache(vFilesFound) * list and create all missing files. */ for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++) - if (pathname_for_V[vFileNum] == (AFSD_INO_T)0) { + if (pathname_for_V[vFileNum] == (AFSD_INO_T) 0) { sprintf(vFileNumber, "%d", vFileNum); if (afsd_verbose) - printf("%s: Creating '%s'\n", - rn, fullpn_VFile); + printf("%s: Creating '%s'\n", rn, fullpn_VFile); if (CreateCacheFile(fullpn_VFile)) - printf("%s: Can't create '%s'\n", - rn, fullpn_VFile); + printf("%s: Can't create '%s'\n", rn, fullpn_VFile); } } @@ -1397,52 +1407,57 @@ int SweepAFSCache(vFilesFound) * Close the directory, return success. */ if (afsd_debug) - printf("%s: Closing cache directory.\n", - rn); + printf("%s: Closing cache directory.\n", rn); closedir(cdirp); - return(0); + return (0); } -static ConfigCell(aci, arock, adir) -register struct afsconf_cell *aci; -char *arock; -struct afsconf_dir *adir; { +static +ConfigCell(register struct afsconf_cell *aci, char *arock, + struct afsconf_dir *adir) +{ register int isHomeCell; register int i; - afs_int32 cellFlags; + afs_int32 cellFlags = 0; afs_int32 hosts[MAXHOSTSPERCELL]; /* figure out if this is the home cell */ isHomeCell = (strcmp(aci->name, afs_LclCellName) == 0); - if (isHomeCell) { - lookingForHomeCell = 0; - cellFlags = 1; /* home cell, suid is ok */ - } - else { - cellFlags = 2; /* not home, suid is forbidden */ - } + if (!isHomeCell) + cellFlags = 2; /* not home, suid is forbidden */ /* build address list */ - for(i=0;ihostAddr[i].sin_addr, sizeof(afs_int32)); - if (aci->linkedCell) cellFlags |= 4; /* Flag that linkedCell arg exists, - for upwards compatibility */ + if (aci->linkedCell) + cellFlags |= 4; /* Flag that linkedCell arg exists, + * for upwards compatibility */ /* configure one cell */ - call_syscall(AFSCALL_CALL, AFSOP_ADDCELL2, - (long)hosts, /* server addresses */ - (long)aci->name, /* cell name */ - (long)cellFlags, /* is this the home cell? */ - (long)aci->linkedCell); /* Linked cell, if any */ + call_syscall(AFSCALL_CALL, AFSOP_ADDCELL2, (long)hosts, /* server addresses */ + (long)aci->name, /* cell name */ + (long)cellFlags, /* is this the home cell? */ + (long)aci->linkedCell); /* Linked cell, if any */ return 0; } +static int +ConfigCellAlias(aca, arock, adir) + struct afsconf_cellalias *aca; + char *arock; + struct afsconf_dir *adir; +{ + call_syscall(AFSOP_ADDCELLALIAS, (long)aca->aliasName, + (long)aca->realName, 0, 0, 0); + return 0; +} + /* * Set the UDP port number RX uses for UDP datagrams */ -void uafs_SetRxPort( - int port) +void +uafs_SetRxPort(int port) { usr_assert(usr_rx_port == 0); usr_rx_port = port; @@ -1452,32 +1467,22 @@ void uafs_SetRxPort( /* * Initialize the user space client. */ -void uafs_Init( - char *rn, - char *mountDirParam, - char *confDirParam, - char *cacheBaseDirParam, - int cacheBlocksParam, - int cacheFilesParam, - int cacheStatEntriesParam, - int dCacheSizeParam, - int vCacheSizeParam, - int chunkSizeParam, - int closeSynchParam, - int debugParam, - int nDaemonsParam, - int cacheFlagsParam, - char *logFile) +void +uafs_Init(char *rn, char *mountDirParam, char *confDirParam, + char *cacheBaseDirParam, int cacheBlocksParam, int cacheFilesParam, + int cacheStatEntriesParam, int dCacheSizeParam, int vCacheSizeParam, + int chunkSizeParam, int closeSynchParam, int debugParam, + int nDaemonsParam, int cacheFlagsParam, char *logFile) { int st; struct usr_proc *procp; struct usr_ucred *ucredp; int i; int rc; - int currVFile; /* Current AFS cache file number */ - int lookupResult; /* Result of GetLocalCellName() */ - int cacheIteration; /* cache verification loop counter */ - int vFilesFound; /* Num data cache files found in sweep */ + int currVFile; /* Current AFS cache file number */ + int lookupResult; /* Result of GetLocalCellName() */ + int cacheIteration; /* cache verification loop counter */ + int vFilesFound; /* Num data cache files found in sweep */ FILE *logfd; afs_int32 vfs1_type = -1; struct afs_ioctl iob; @@ -1497,7 +1502,7 @@ void uafs_Init( * Initialize the global ucred structure */ afs_global_ucredp = (struct usr_ucred *) - afs_osi_Alloc(sizeof(struct usr_ucred)); + afs_osi_Alloc(sizeof(struct usr_ucred)); usr_assert(afs_global_ucredp != NULL); afs_global_ucredp->cr_ref = 1; afs_global_ucredp->cr_uid = geteuid(); @@ -1509,7 +1514,7 @@ void uafs_Init( st = getgroups(NGROUPS, &afs_global_ucredp->cr_groups[0]); usr_assert(st >= 0); afs_global_ucredp->cr_ngroups = (unsigned long)st; - for (i = st ; i < NGROUPS ; i++) { + for (i = st; i < NGROUPS; i++) { afs_global_ucredp->cr_groups[i] = NOGROUP; } @@ -1517,10 +1522,10 @@ void uafs_Init( * Initialize the global process structure */ afs_global_procp = (struct usr_proc *) - afs_osi_Alloc(sizeof(struct usr_proc)); + afs_osi_Alloc(sizeof(struct usr_proc)); usr_assert(afs_global_procp != NULL); afs_global_procp->p_pid = getpid(); - afs_global_procp->p_ppid = (pid_t)1; + afs_global_procp->p_ppid = (pid_t) 1; afs_global_procp->p_ucred = afs_global_ucredp; /* @@ -1535,7 +1540,7 @@ void uafs_Init( } afs_mountDir[0] = '/'; afs_mountDirLen = 1; - for (lastchar = '/', p = &tbuffer[0] ; *p != '\0' ; p++) { + for (lastchar = '/', p = &tbuffer[0]; *p != '\0'; p++) { if (lastchar != '/' || *p != '/') { afs_mountDir[afs_mountDirLen++] = lastchar = *p; } @@ -1553,7 +1558,7 @@ void uafs_Init( if (cacheFilesParam != 0) { cacheFiles = cacheFilesParam; } else { - cacheFiles = cacheBlocks/10; + cacheFiles = cacheBlocks / 10; } if (cacheStatEntriesParam != 0) { cacheStatEntries = cacheStatEntriesParam; @@ -1570,7 +1575,7 @@ void uafs_Init( if (dCacheSizeParam != 0) { dCacheSize = dCacheSizeParam; } else { - dCacheSize = cacheFiles/2; + dCacheSize = cacheFiles / 2; } if (vCacheSizeParam != 0) { vCacheSize = vCacheSizeParam; @@ -1581,12 +1586,12 @@ void uafs_Init( cacheFlags = cacheFlagsParam; } if (cacheFlags & AFSCALL_INIT_MEMCACHE) { - cacheFiles = dCacheSize; + cacheFiles = dCacheSize; } - sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE); + sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE); if (logFile == NULL) { - sprintf(fullpn_AFSLogFile, "%s/%s", confDir, AFSLOGFILE); + sprintf(fullpn_AFSLogFile, "%s/%s", confDir, AFSLOGFILE); } else { strcpy(fullpn_AFSLogFile, logFile); } @@ -1624,22 +1629,29 @@ void uafs_Init( exit(1); } - lookupResult = afsconf_GetLocalCell(afs_cdir, afs_LclCellName, - sizeof(afs_LclCellName)); + lookupResult = + afsconf_GetLocalCell(afs_cdir, afs_LclCellName, + sizeof(afs_LclCellName)); if (lookupResult) { - printf("%s: Can't get my home cell name! [Error is %d]\n", - rn, lookupResult); - } - else { + printf("%s: Can't get my home cell name! [Error is %d]\n", rn, + lookupResult); + } else { if (afsd_verbose) - printf("%s: My home cell is '%s'\n", - rn, afs_LclCellName); + printf("%s: My home cell is '%s'\n", rn, afs_LclCellName); } - if ((logfd = fopen(fullpn_AFSLogFile,"r+")) == 0) { - if (afsd_verbose) printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile); + /* + * Set the primary cell name. + */ + call_syscall(AFSOP_SET_THISCELL, (long)afs_LclCellName, 0, 0, 0, 0); + + if ((logfd = fopen(fullpn_AFSLogFile, "r+")) == 0) { + if (afsd_verbose) + printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile); if (CreateCacheFile(fullpn_AFSLogFile)) { - printf("%s: Can't create '%s' (You may want to use the -logfile option)\n", rn, fullpn_AFSLogFile); + printf + ("%s: Can't create '%s' (You may want to use the -logfile option)\n", + rn, fullpn_AFSLogFile); exit(1); } } else @@ -1656,29 +1668,30 @@ void uafs_Init( } memset(pathname_for_V, 0, (cacheFiles * sizeof(char *))); if (afsd_debug) - printf("%s: %d pathname_for_V entries at 0x%x, %d bytes\n", - rn, cacheFiles, (cacheFiles * sizeof(AFSD_INO_T))); + printf("%s: %d pathname_for_V entries at 0x%x, %d bytes\n", rn, + cacheFiles, pathname_for_V, (cacheFiles * sizeof(AFSD_INO_T))); /* * Set up all the pathnames we'll need for later. */ - sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE); + sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE); sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE); - sprintf(fullpn_VFile, "%s/V", cacheBaseDir); + sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE); + sprintf(fullpn_VFile, "%s/V", cacheBaseDir); vFileNumber = fullpn_VFile + strlen(fullpn_VFile); /* * Start the RX listener. */ if (afsd_debug) - printf("%s: Calling AFSOP_RXLISTENER_DAEMON\n", rn); - fork_syscall(AFSCALL_CALL, AFSOP_RXLISTENER_DAEMON, FALSE); + printf("%s: Calling AFSOP_RXLISTENER_DAEMON\n", rn); + fork_syscall(AFSCALL_CALL, AFSOP_RXLISTENER_DAEMON, FALSE, FALSE, FALSE); /* * Start the RX event handler. */ if (afsd_debug) - printf("%s: Calling AFSOP_RXEVENT_DAEMON\n", rn); + printf("%s: Calling AFSOP_RXEVENT_DAEMON\n", rn); fork_syscall(AFSCALL_CALL, AFSOP_RXEVENT_DAEMON, FALSE); /* @@ -1687,61 +1700,32 @@ void uafs_Init( /* initialize AFS callback interface */ { - /* parse multihomed address files */ - char reason[1024]; - st=parseNetFiles(buffer,maskbuffer,mtubuffer,MAXIPADDRS,reason, - AFSDIR_CLIENT_NETINFO_FILEPATH, - AFSDIR_CLIENT_NETRESTRICT_FILEPATH); - if(st>0) - call_syscall(AFSCALL_CALL, AFSOP_ADVISEADDR, st, (long) (&buffer[0]), - (long) (&maskbuffer[0]), (long) (&mtubuffer[0])); - else { - printf("ADVISEADDR: Error in specifying interface addresses:%s\n",reason); - exit(1); - } + /* parse multihomed address files */ + char reason[1024]; + st = parseNetFiles(buffer, maskbuffer, mtubuffer, MAXIPADDRS, reason, + AFSDIR_CLIENT_NETINFO_FILEPATH, + AFSDIR_CLIENT_NETRESTRICT_FILEPATH); + if (st > 0) + call_syscall(AFSCALL_CALL, AFSOP_ADVISEADDR, st, + (long)(&buffer[0]), (long)(&maskbuffer[0]), + (long)(&mtubuffer[0])); + else { + printf("ADVISEADDR: Error in specifying interface addresses:%s\n", + reason); + exit(1); + } } if (afsd_verbose) printf("%s: Forking rx callback listener.\n", rn); /* Child */ - if (preallocs < cacheStatEntries+50) - preallocs = cacheStatEntries+50; + if (preallocs < cacheStatEntries + 50) + preallocs = cacheStatEntries + 50; fork_syscall(AFSCALL_CALL, AFSOP_START_RXCALLBACK, preallocs); if (afsd_verbose) - printf("%s: Forking AFS daemon.\n", rn); - fork_syscall(AFSCALL_CALL, AFSOP_START_AFS); - - if (afsd_verbose) - printf("%s: Forking check server daemon.\n", rn); - fork_syscall(AFSCALL_CALL, AFSOP_START_CS); - - if (afsd_verbose) - printf("%s: Forking %d background daemons.\n", rn, nDaemons); - for (i=0;icr_suid = getuid(); crp->cr_groups[0] = getgid(); crp->cr_ngroups = 1; - for (i = 1 ; i < NGROUPS ; i++) { + for (i = 1; i < NGROUPS; i++) { crp->cr_groups[i] = NOGROUP; } - call_syscall(sysArgsP->syscall, sysArgsP->afscall, - sysArgsP->param1, sysArgsP->param2, - sysArgsP->param3, sysArgsP->param4); + call_syscall(sysArgsP->syscall, sysArgsP->afscall, sysArgsP->param1, + sysArgsP->param2, sysArgsP->param3, sysArgsP->param4); afs_osi_Free(argp, -1); } fork_syscall(syscall, afscall, param1, param2, param3, param4) -long syscall, afscall, param1, param2, param3, param4; + long syscall, afscall, param1, param2, param3, param4; { usr_thread_t tid; struct syscallThreadArgs *sysArgsP; sysArgsP = (struct syscallThreadArgs *) - afs_osi_Alloc(sizeof(struct syscallThreadArgs)); + afs_osi_Alloc(sizeof(struct syscallThreadArgs)); usr_assert(sysArgsP != NULL); sysArgsP->syscall = syscall; sysArgsP->afscall = afscall; @@ -2014,7 +2026,7 @@ long syscall, afscall, param1, param2, param3, param4; } call_syscall(syscall, afscall, param1, param2, param3, param4) -long syscall, afscall, param1, param2, param3, param4; + long syscall, afscall, param1, param2, param3, param4; { int code = 0; struct a { @@ -2040,7 +2052,8 @@ long syscall, afscall, param1, param2, param3, param4; return code; } -int uafs_SetTokens(char *tbuffer, int tlen) +int +uafs_SetTokens(char *tbuffer, int tlen) { int rc; struct afs_ioctl iob; @@ -2058,7 +2071,8 @@ int uafs_SetTokens(char *tbuffer, int tlen) return 0; } -int uafs_RPCStatsEnableProc() +int +uafs_RPCStatsEnableProc(void) { int rc; struct afs_ioctl iob; @@ -2077,7 +2091,8 @@ int uafs_RPCStatsEnableProc() return rc; } -int uafs_RPCStatsDisableProc() +int +uafs_RPCStatsDisableProc(void) { int rc; struct afs_ioctl iob; @@ -2096,7 +2111,8 @@ int uafs_RPCStatsDisableProc() return rc; } -int uafs_RPCStatsClearProc() +int +uafs_RPCStatsClearProc(void) { int rc; struct afs_ioctl iob; @@ -2115,7 +2131,8 @@ int uafs_RPCStatsClearProc() return rc; } -int uafs_RPCStatsEnablePeer() +int +uafs_RPCStatsEnablePeer(void) { int rc; struct afs_ioctl iob; @@ -2134,7 +2151,8 @@ int uafs_RPCStatsEnablePeer() return rc; } -int uafs_RPCStatsDisablePeer() +int +uafs_RPCStatsDisablePeer(void) { int rc; struct afs_ioctl iob; @@ -2153,7 +2171,8 @@ int uafs_RPCStatsDisablePeer() return rc; } -int uafs_RPCStatsClearPeer() +int +uafs_RPCStatsClearPeer(void) { int rc; struct afs_ioctl iob; @@ -2179,12 +2198,9 @@ int uafs_RPCStatsClearPeer() * * Note: Caller must hold the AFS global lock. */ -int uafs_LookupName( - char *path, - struct usr_vnode *parentVp, - struct usr_vnode **vpp, - int follow, - int no_eval_mtpt) +int +uafs_LookupName(char *path, struct usr_vnode *parentVp, + struct usr_vnode **vpp, int follow, int no_eval_mtpt) { int code; int linkCount; @@ -2213,7 +2229,7 @@ int uafs_LookupName( /* * Loop through the path looking for the new directory */ - tmpPath = afs_osi_Alloc(strlen(path)+1); + tmpPath = afs_osi_Alloc(strlen(path) + 1); usr_assert(tmpPath != NULL); strcpy(tmpPath, path); VN_HOLD(vp); @@ -2236,7 +2252,7 @@ int uafs_LookupName( */ if (vp->v_type != VDIR) { VN_RELE(vp); - afs_osi_Free(tmpPath, strlen(path)+1); + afs_osi_Free(tmpPath, strlen(path) + 1); return ENOTDIR; } @@ -2252,7 +2268,7 @@ int uafs_LookupName( code = afs_access(vp, VEXEC, u.u_cred); if (code != 0) { VN_RELE(vp); - afs_osi_Free(tmpPath, strlen(path)+1); + afs_osi_Free(tmpPath, strlen(path) + 1); return code; } @@ -2262,16 +2278,18 @@ int uafs_LookupName( */ nextVp = NULL; #ifdef AFS_WEB_ENHANCEMENTS - if ((nextPathP != NULL && *nextPathP != '\0') || !no_eval_mtpt) - code = afs_lookup(vp, pathP, &nextVp, u.u_cred, 0); - else - code = afs_lookup(vp, pathP, &nextVp, u.u_cred, AFS_LOOKUP_NOEVAL); + if ((nextPathP != NULL && *nextPathP != '\0') || !no_eval_mtpt) + code = afs_lookup(vp, pathP, &nextVp, u.u_cred, 0); + else + code = + afs_lookup(vp, pathP, &nextVp, u.u_cred, + AFS_LOOKUP_NOEVAL); #else - code = afs_lookup(vp, pathP, &nextVp, u.u_cred, 0); + code = afs_lookup(vp, pathP, &nextVp, u.u_cred, 0); #endif /* AFS_WEB_ENHANCEMENTS */ if (code != 0) { VN_RELE(vp); - afs_osi_Free(tmpPath, strlen(path)+1); + afs_osi_Free(tmpPath, strlen(path) + 1); return code; } } @@ -2282,18 +2300,18 @@ int uafs_LookupName( */ if ((nextPathP != NULL && *nextPathP != '\0') || follow) { linkCount = 0; - while(nextVp->v_type == VLNK) { + while (nextVp->v_type == VLNK) { if (++linkCount > MAX_OSI_LINKS) { VN_RELE(vp); VN_RELE(nextVp); - afs_osi_Free(tmpPath, strlen(path)+1); + afs_osi_Free(tmpPath, strlen(path) + 1); return code; } code = uafs_LookupLink(nextVp, vp, &linkVp); if (code) { VN_RELE(vp); VN_RELE(nextVp); - afs_osi_Free(tmpPath, strlen(path)+1); + afs_osi_Free(tmpPath, strlen(path) + 1); return code; } VN_RELE(nextVp); @@ -2311,11 +2329,11 @@ int uafs_LookupName( */ if (nextPathP != NULL && vp->v_type != VDIR) { VN_RELE(vp); - afs_osi_Free(tmpPath, strlen(path)+1); + afs_osi_Free(tmpPath, strlen(path) + 1); return ENOTDIR; } - afs_osi_Free(tmpPath, strlen(path)+1); + afs_osi_Free(tmpPath, strlen(path) + 1); *vpp = vp; return 0; } @@ -2327,10 +2345,9 @@ int uafs_LookupName( * * Note: Caller must hold the AFS global lock. */ -int uafs_LookupLink( - struct usr_vnode *vp, - struct usr_vnode *parentVp, - struct usr_vnode **vpp) +int +uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentVp, + struct usr_vnode **vpp) { int code; int len; @@ -2341,27 +2358,27 @@ int uafs_LookupLink( AFS_ASSERT_GLOCK(); - pathP = afs_osi_Alloc(MAX_OSI_PATH+1); + pathP = afs_osi_Alloc(MAX_OSI_PATH + 1); usr_assert(pathP != NULL); /* * set up the uio buffer */ iov[0].iov_base = pathP; - iov[0].iov_len = MAX_OSI_PATH+1; + iov[0].iov_len = MAX_OSI_PATH + 1; uio.uio_iov = &iov[0]; uio.uio_iovcnt = 1; uio.uio_offset = 0; uio.uio_segflg = 0; uio.uio_fmode = FREAD; - uio.uio_resid = MAX_OSI_PATH+1; + uio.uio_resid = MAX_OSI_PATH + 1; /* * Read the link data */ code = afs_readlink(vp, &uio, u.u_cred); if (code) { - afs_osi_Free(pathP, MAX_OSI_PATH+1); + afs_osi_Free(pathP, MAX_OSI_PATH + 1); return code; } len = MAX_OSI_PATH + 1 - uio.uio_resid; @@ -2372,11 +2389,11 @@ int uafs_LookupLink( */ code = uafs_LookupName(pathP, parentVp, &linkVp, 1, 0); if (code) { - afs_osi_Free(pathP, MAX_OSI_PATH+1); + afs_osi_Free(pathP, MAX_OSI_PATH + 1); return code; } - afs_osi_Free(pathP, MAX_OSI_PATH+1); + afs_osi_Free(pathP, MAX_OSI_PATH + 1); *vpp = linkVp; return 0; } @@ -2388,9 +2405,8 @@ int uafs_LookupLink( * * Note: Caller must hold the AFS global lock. */ -int uafs_LookupParent( - char *path, - struct usr_vnode **vpp) +int +uafs_LookupParent(char *path, struct usr_vnode **vpp) { int len; int code; @@ -2413,13 +2429,13 @@ int uafs_LookupParent( * Find the length of the parent path */ len = strlen(path); - while(len > 0 && path[len-1] == '/') { + while (len > 0 && path[len - 1] == '/') { len--; } if (len == 0) { return EINVAL; } - while(len > 0 && path[len-1] != '/') { + while (len > 0 && path[len - 1] != '/') { len--; } if (len == 0) { @@ -2428,8 +2444,8 @@ int uafs_LookupParent( pathP = afs_osi_Alloc(len); usr_assert(pathP != NULL); - memcpy(pathP, path, len-1); - pathP[len-1] = '\0'; + memcpy(pathP, path, len - 1); + pathP[len - 1] = '\0'; /* * look up the parent @@ -2452,15 +2468,16 @@ int uafs_LookupParent( * Return a pointer to the first character in the last component * of a pathname */ -char *uafs_LastPath(char *path) +char * +uafs_LastPath(char *path) { int len; len = strlen(path); - while (len > 0 && path[len-1] == '/') { + while (len > 0 && path[len - 1] == '/') { len--; } - while (len > 0 && path[len-1] != '/') { + while (len > 0 && path[len - 1] != '/') { len--; } if (len == 0) { @@ -2472,8 +2489,8 @@ char *uafs_LastPath(char *path) /* * Set the working directory. */ -int uafs_chdir( - char *path) +int +uafs_chdir(char *path) { int retval; AFS_GLOCK(); @@ -2482,8 +2499,8 @@ int uafs_chdir( return retval; } -int uafs_chdir_r( - char *path) +int +uafs_chdir_r(char *path) { int code; struct vnode *dirP; @@ -2506,9 +2523,8 @@ int uafs_chdir_r( /* * Create a directory. */ -int uafs_mkdir( - char *path, - int mode) +int +uafs_mkdir(char *path, int mode) { int retval; AFS_GLOCK(); @@ -2517,9 +2533,8 @@ int uafs_mkdir( return retval; } -int uafs_mkdir_r( - char *path, - int mode) +int +uafs_mkdir_r(char *path, int mode) { int code; char *nameP; @@ -2578,9 +2593,10 @@ int uafs_mkdir_r( /* * Return 1 if path is the AFS root, otherwise return 0 */ -int uafs_IsRoot(char *path) +int +uafs_IsRoot(char *path) { - while(*path == '/' && *(path+1) == '/') { + while (*path == '/' && *(path + 1) == '/') { path++; } if (strncmp(path, afs_mountDir, afs_mountDirLen) != 0) { @@ -2600,10 +2616,8 @@ int uafs_IsRoot(char *path) * Open a file * Note: file name may not end in a slash. */ -int uafs_open( - char *path, - int flags, - int mode) +int +uafs_open(char *path, int flags, int mode) { int retval; AFS_GLOCK(); @@ -2612,10 +2626,8 @@ int uafs_open( return retval; } -int uafs_open_r( - char *path, - int flags, - int mode) +int +uafs_open_r(char *path, int flags, int mode) { int fd; int code; @@ -2668,13 +2680,14 @@ int uafs_open_r( attrs.va_size = 0; } fileP = NULL; - code = afs_create(dirP, nameP, &attrs, - (flags & O_EXCL)?usr_EXCL:usr_NONEXCL, - mode, &fileP, u.u_cred); + code = + afs_create(dirP, nameP, &attrs, + (flags & O_EXCL) ? usr_EXCL : usr_NONEXCL, mode, + &fileP, u.u_cred); VN_RELE(dirP); if (code != 0) { - errno = code; - return -1; + errno = code; + return -1; } } else { fileP = NULL; @@ -2689,13 +2702,14 @@ int uafs_open_r( * Check whether we have access to this file */ fileMode = 0; - if (flags & (O_RDONLY|O_RDWR)) { + if (flags & (O_RDONLY | O_RDWR)) { fileMode |= VREAD; } - if (flags & (O_WRONLY|O_RDWR)) { + if (flags & (O_WRONLY | O_RDWR)) { fileMode |= VWRITE; } - if (!fileMode) fileMode = VREAD; /* since O_RDONLY is 0 */ + if (!fileMode) + fileMode = VREAD; /* since O_RDONLY is 0 */ code = afs_access(fileP, fileMode, u.u_cred); if (code != 0) { VN_RELE(fileP); @@ -2731,10 +2745,10 @@ int uafs_open_r( if (flags & O_SYNC) { openFlags |= FSYNC; } - if (flags & (O_RDONLY|O_RDWR)) { + if (flags & (O_RDONLY | O_RDWR)) { openFlags |= FREAD; } - if (flags & (O_WRONLY|O_RDWR)) { + if (flags & (O_WRONLY | O_RDWR)) { openFlags |= FWRITE; } @@ -2765,7 +2779,7 @@ int uafs_open_r( /* * Put the vnode pointer into the file table */ - for (fd = 0 ; fd < MAX_OSI_FILES ; fd++) { + for (fd = 0; fd < MAX_OSI_FILES; fd++) { if (afs_FileTable[fd] == NULL) { afs_FileTable[fd] = fileP; afs_FileFlags[fd] = openFlags; @@ -2789,31 +2803,27 @@ int uafs_open_r( /* * Create a file */ -int uafs_creat( - char *path, - int mode) +int +uafs_creat(char *path, int mode) { int rc; - rc = uafs_open(path, O_CREAT|O_WRONLY|O_TRUNC, mode); + rc = uafs_open(path, O_CREAT | O_WRONLY | O_TRUNC, mode); return rc; } -int uafs_creat_r( - char *path, - int mode) +int +uafs_creat_r(char *path, int mode) { int rc; - rc = uafs_open_r(path, O_CREAT|O_WRONLY|O_TRUNC, mode); + rc = uafs_open_r(path, O_CREAT | O_WRONLY | O_TRUNC, mode); return rc; } /* * Write to a file */ -int uafs_write( - int fd, - char *buf, - int len) +int +uafs_write(int fd, char *buf, int len) { int retval; AFS_GLOCK(); @@ -2822,10 +2832,8 @@ int uafs_write( return retval; } -int uafs_write_r( - int fd, - char *buf, - int len) +int +uafs_write_r(int fd, char *buf, int len) { int code; struct usr_uio uio; @@ -2864,16 +2872,14 @@ int uafs_write_r( } afs_FileOffsets[fd] = uio.uio_offset; - return(len - uio.uio_resid); + return (len - uio.uio_resid); } /* * Read from a file */ -int uafs_read( - int fd, - char *buf, - int len) +int +uafs_read(int fd, char *buf, int len) { int retval; AFS_GLOCK(); @@ -2882,10 +2888,8 @@ int uafs_read( return retval; } -int uafs_read_r( - int fd, - char *buf, - int len) +int +uafs_read_r(int fd, char *buf, int len) { int code; struct usr_uio uio; @@ -2924,7 +2928,7 @@ int uafs_read_r( } afs_FileOffsets[fd] = uio.uio_offset; - return(len - uio.uio_resid); + return (len - uio.uio_resid); } /* @@ -2932,9 +2936,8 @@ int uafs_read_r( * * NOTE: Caller must hold the global AFS lock. */ -int uafs_GetAttr( - struct usr_vnode *vp, - struct stat *stats) +int +uafs_GetAttr(struct usr_vnode *vp, struct stat *stats) { int code; struct usr_vattr attrs; @@ -2973,9 +2976,8 @@ int uafs_GetAttr( /* * Get the attributes of a file, do follow links */ -int uafs_stat( - char *path, - struct stat *buf) +int +uafs_stat(char *path, struct stat *buf) { int retval; AFS_GLOCK(); @@ -2984,9 +2986,8 @@ int uafs_stat( return retval; } -int uafs_stat_r( - char *path, - struct stat *buf) +int +uafs_stat_r(char *path, struct stat *buf) { int code; struct vnode *vp; @@ -3008,9 +3009,8 @@ int uafs_stat_r( /* * Get the attributes of a file, don't follow links */ -int uafs_lstat( - char *path, - struct stat *buf) +int +uafs_lstat(char *path, struct stat *buf) { int retval; AFS_GLOCK(); @@ -3019,9 +3019,8 @@ int uafs_lstat( return retval; } -int uafs_lstat_r( - char *path, - struct stat *buf) +int +uafs_lstat_r(char *path, struct stat *buf) { int code; struct vnode *vp; @@ -3043,9 +3042,8 @@ int uafs_lstat_r( /* * Get the attributes of an open file */ -int uafs_fstat( - int fd, - struct stat *buf) +int +uafs_fstat(int fd, struct stat *buf) { int retval; AFS_GLOCK(); @@ -3054,9 +3052,8 @@ int uafs_fstat( return retval; } -int uafs_fstat_r( - int fd, - struct stat *buf) +int +uafs_fstat_r(int fd, struct stat *buf) { int code; struct vnode *vp; @@ -3078,9 +3075,8 @@ int uafs_fstat_r( /* * change the permissions on a file */ -int uafs_chmod( - char *path, - int mode) +int +uafs_chmod(char *path, int mode) { int retval; AFS_GLOCK(); @@ -3089,9 +3085,8 @@ int uafs_chmod( return retval; } -int uafs_chmod_r( - char *path, - int mode) +int +uafs_chmod_r(char *path, int mode) { int code; struct vnode *vp; @@ -3116,9 +3111,8 @@ int uafs_chmod_r( /* * change the permissions on an open file */ -int uafs_fchmod( - int fd, - int mode) +int +uafs_fchmod(int fd, int mode) { int retval; AFS_GLOCK(); @@ -3127,9 +3121,8 @@ int uafs_fchmod( return retval; } -int uafs_fchmod_r( - int fd, - int mode) +int +uafs_fchmod_r(int fd, int mode) { int code; struct vnode *vp; @@ -3153,9 +3146,8 @@ int uafs_fchmod_r( /* * truncate a file */ -int uafs_truncate( - char *path, - int length) +int +uafs_truncate(char *path, int length) { int retval; AFS_GLOCK(); @@ -3164,9 +3156,8 @@ int uafs_truncate( return retval; } -int uafs_truncate_r( - char *path, - int length) +int +uafs_truncate_r(char *path, int length) { int code; struct vnode *vp; @@ -3191,9 +3182,8 @@ int uafs_truncate_r( /* * truncate an open file */ -int uafs_ftruncate( - int fd, - int length) +int +uafs_ftruncate(int fd, int length) { int retval; AFS_GLOCK(); @@ -3202,9 +3192,8 @@ int uafs_ftruncate( return retval; } -int uafs_ftruncate_r( - int fd, - int length) +int +uafs_ftruncate_r(int fd, int length) { int code; struct vnode *vp; @@ -3228,10 +3217,8 @@ int uafs_ftruncate_r( /* * set the read/write file pointer of an open file */ -int uafs_lseek( - int fd, - int offset, - int whence) +int +uafs_lseek(int fd, int offset, int whence) { int retval; AFS_GLOCK(); @@ -3240,10 +3227,8 @@ int uafs_lseek( return retval; } -int uafs_lseek_r( - int fd, - int offset, - int whence) +int +uafs_lseek_r(int fd, int offset, int whence) { int code; int newpos; @@ -3256,13 +3241,13 @@ int uafs_lseek_r( return -1; } switch (whence) { - case SEEK_CUR: + case SEEK_CUR: newpos = afs_FileOffsets[fd] + offset; break; - case SEEK_SET: + case SEEK_SET: newpos = offset; break; - case SEEK_END: + case SEEK_END: code = afs_getattr(vp, &attrs, u.u_cred); if (code != 0) { errno = code; @@ -3270,7 +3255,7 @@ int uafs_lseek_r( } newpos = attrs.va_size + offset; break; - default: + default: errno = EINVAL; return -1; } @@ -3285,8 +3270,8 @@ int uafs_lseek_r( /* * sync a file */ -int uafs_fsync( - int fd) +int +uafs_fsync(int fd) { int retval; AFS_GLOCK(); @@ -3295,8 +3280,8 @@ int uafs_fsync( return retval; } -int uafs_fsync_r( - int fd) +int +uafs_fsync_r(int fd) { int code; struct usr_vnode *fileP; @@ -3314,14 +3299,14 @@ int uafs_fsync_r( return -1; } - return 0; + return 0; } /* * Close a file */ -int uafs_close( - int fd) +int +uafs_close(int fd) { int retval; AFS_GLOCK(); @@ -3330,8 +3315,8 @@ int uafs_close( return retval; } -int uafs_close_r( - int fd) +int +uafs_close_r(int fd) { int code; struct usr_vnode *fileP; @@ -3350,16 +3335,15 @@ int uafs_close_r( return -1; } - return 0; + return 0; } /* * Create a hard link from the source to the target * Note: file names may not end in a slash. */ -int uafs_link( - char *existing, - char *new) +int +uafs_link(char *existing, char *new) { int retval; AFS_GLOCK(); @@ -3368,9 +3352,8 @@ int uafs_link( return retval; } -int uafs_link_r( - char *existing, - char *new) +int +uafs_link_r(char *existing, char *new) { int code; struct usr_vnode *existP; @@ -3434,9 +3417,8 @@ int uafs_link_r( * Create a symbolic link from the source to the target * Note: file names may not end in a slash. */ -int uafs_symlink( - char *target, - char *source) +int +uafs_symlink(char *target, char *source) { int retval; AFS_GLOCK(); @@ -3445,9 +3427,8 @@ int uafs_symlink( return retval; } -int uafs_symlink_r( - char *target, - char *source) +int +uafs_symlink_r(char *target, char *source) { int code; struct usr_vnode *dirP; @@ -3503,10 +3484,8 @@ int uafs_symlink_r( /* * Read a symbolic link into the buffer */ -int uafs_readlink( - char *path, - char *buf, - int len) +int +uafs_readlink(char *path, char *buf, int len) { int retval; AFS_GLOCK(); @@ -3515,10 +3494,8 @@ int uafs_readlink( return retval; } -int uafs_readlink_r( - char *path, - char *buf, - int len) +int +uafs_readlink_r(char *path, char *buf, int len) { int code; struct usr_vnode *vp; @@ -3555,7 +3532,7 @@ int uafs_readlink_r( code = afs_readlink(vp, &uio, u.u_cred); VN_RELE(vp); if (code) { - errno = code; + errno = code; return -1; } @@ -3569,8 +3546,8 @@ int uafs_readlink_r( * Remove a file (or directory) * Note: file name may not end in a slash. */ -int uafs_unlink( - char *path) +int +uafs_unlink(char *path) { int retval; AFS_GLOCK(); @@ -3579,8 +3556,8 @@ int uafs_unlink( return retval; } -int uafs_unlink_r( - char *path) +int +uafs_unlink_r(char *path) { int code; int openFlags; @@ -3633,9 +3610,8 @@ int uafs_unlink_r( /* * Rename a file (or directory) */ -int uafs_rename( - char *old, - char *new) +int +uafs_rename(char *old, char *new) { int retval; AFS_GLOCK(); @@ -3644,9 +3620,8 @@ int uafs_rename( return retval; } -int uafs_rename_r( - char *old, - char *new) +int +uafs_rename_r(char *old, char *new) { int code; char *onameP; @@ -3714,8 +3689,8 @@ int uafs_rename_r( * Remove a or directory * Note: file name may not end in a slash. */ -int uafs_rmdir( - char *path) +int +uafs_rmdir(char *path) { int retval; AFS_GLOCK(); @@ -3724,8 +3699,8 @@ int uafs_rmdir( return retval; } -int uafs_rmdir_r( - char *path) +int +uafs_rmdir_r(char *path) { int code; int openFlags; @@ -3778,8 +3753,8 @@ int uafs_rmdir_r( /* * Flush a file from the AFS cache */ -int uafs_FlushFile( - char *path) +int +uafs_FlushFile(char *path) { int code; struct afs_ioctl iob; @@ -3789,8 +3764,9 @@ int uafs_FlushFile( iob.out = NULL; iob.out_size = 0; - code = call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(6), - (long)&iob, 0, 0); + code = + call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(6), (long)&iob, 0, + 0); if (code != 0) { errno = code; return -1; @@ -3798,8 +3774,9 @@ int uafs_FlushFile( return 0; } -int uafs_FlushFile_r( - char *path) + +int +uafs_FlushFile_r(char *path) { int retval; AFS_GUNLOCK(); @@ -3811,8 +3788,8 @@ int uafs_FlushFile_r( /* * open a directory */ -usr_DIR *uafs_opendir( - char *path) +usr_DIR * +uafs_opendir(char *path) { usr_DIR *retval; AFS_GLOCK(); @@ -3821,8 +3798,8 @@ usr_DIR *uafs_opendir( return retval; } -usr_DIR *uafs_opendir_r( - char *path) +usr_DIR * +uafs_opendir_r(char *path) { usr_DIR *dirp; struct usr_vnode *fileP; @@ -3838,22 +3815,23 @@ usr_DIR *uafs_opendir_r( fileP = afs_FileTable[fd]; if (fileP == NULL) { - return NULL; + return NULL; } if (fileP->v_type != VDIR) { - uafs_close_r(fd); - errno = ENOTDIR; - return NULL; + uafs_close_r(fd); + errno = ENOTDIR; + return NULL; } /* * Set up the directory structures */ - dirp = (usr_DIR *)afs_osi_Alloc(sizeof(usr_DIR) + USR_DIRSIZE + - sizeof(struct usr_dirent)); + dirp = + (usr_DIR *) afs_osi_Alloc(sizeof(usr_DIR) + USR_DIRSIZE + + sizeof(struct usr_dirent)); usr_assert(dirp != NULL); - dirp->dd_buf = (char *)(dirp+1); + dirp->dd_buf = (char *)(dirp + 1); dirp->dd_fd = fd; dirp->dd_loc = 0; dirp->dd_size = 0; @@ -3867,10 +3845,8 @@ usr_DIR *uafs_opendir_r( * This routine was developed to support AFS cache consistency testing. * You should use uafs_readdir instead. */ -int uafs_getdents( - int fd, - struct min_direct *buf, - int len) +int +uafs_getdents(int fd, struct min_direct *buf, int len) { int retval; AFS_GLOCK(); @@ -3879,10 +3855,8 @@ int uafs_getdents( return retval; } -int uafs_getdents_r( - int fd, - struct min_direct *buf, - int len) +int +uafs_getdents_r(int fd, struct min_direct *buf, int len) { int code; struct usr_uio uio; @@ -3921,14 +3895,14 @@ int uafs_getdents_r( } afs_FileOffsets[fd] = uio.uio_offset; - return(len - uio.uio_resid); + return (len - uio.uio_resid); } /* * read from a directory (names only) */ -struct usr_dirent *uafs_readdir( - usr_DIR *dirp) +struct usr_dirent * +uafs_readdir(usr_DIR * dirp) { struct usr_dirent *retval; AFS_GLOCK(); @@ -3937,8 +3911,8 @@ struct usr_dirent *uafs_readdir( return retval; } -struct usr_dirent *uafs_readdir_r( - usr_DIR *dirp) +struct usr_dirent * +uafs_readdir_r(usr_DIR * dirp) { int rc; int code; @@ -3962,7 +3936,7 @@ struct usr_dirent *uafs_readdir_r( * If there are no entries in the stream buffer * then read another chunk */ - directP = (struct min_direct *)(dirp->dd_buf+dirp->dd_loc); + directP = (struct min_direct *)(dirp->dd_buf + dirp->dd_loc); if (dirp->dd_size == 0 || directP->d_fileno == 0) { /* * set up the uio buffer @@ -3988,7 +3962,7 @@ struct usr_dirent *uafs_readdir_r( dirp->dd_size = USR_DIRSIZE - iov[0].iov_len; dirp->dd_loc = 0; - directP = (struct min_direct *)(dirp->dd_buf+dirp->dd_loc); + directP = (struct min_direct *)(dirp->dd_buf + dirp->dd_loc); } /* @@ -3998,18 +3972,18 @@ struct usr_dirent *uafs_readdir_r( errno = 0; return NULL; } - len = ((sizeof(struct min_direct)+directP->d_namlen+4) & (~3)); + len = ((sizeof(struct min_direct) + directP->d_namlen + 4) & (~3)); usr_assert(len <= dirp->dd_size); /* * Copy the next entry into the usr_dirent structure and advance */ - direntP = (struct usr_dirent *)(dirp->dd_buf+USR_DIRSIZE); + direntP = (struct usr_dirent *)(dirp->dd_buf + USR_DIRSIZE); direntP->d_ino = directP->d_fileno; direntP->d_off = direntP->d_reclen; - direntP->d_reclen = sizeof(struct usr_dirent) - MAXNAMLEN + - directP->d_namlen + 1; - memcpy(&direntP->d_name[0], (void *)(directP+1), directP->d_namlen); + direntP->d_reclen = + sizeof(struct usr_dirent) - MAXNAMLEN + directP->d_namlen + 1; + memcpy(&direntP->d_name[0], (void *)(directP + 1), directP->d_namlen); direntP->d_name[directP->d_namlen] = '\0'; dirp->dd_loc += len; dirp->dd_size -= len; @@ -4020,8 +3994,8 @@ struct usr_dirent *uafs_readdir_r( /* * Close a directory */ -int uafs_closedir( - usr_DIR *dirp) +int +uafs_closedir(usr_DIR * dirp) { int retval; AFS_GLOCK(); @@ -4030,8 +4004,8 @@ int uafs_closedir( return retval; } -int uafs_closedir_r( - usr_DIR *dirp) +int +uafs_closedir_r(usr_DIR * dirp) { int fd; int rc; @@ -4046,29 +4020,23 @@ int uafs_closedir_r( /* * Do AFS authentication */ -int uafs_klog( - char *user, - char *cell, - char *passwd, - char **reason) +int +uafs_klog(char *user, char *cell, char *passwd, char **reason) { int code; afs_int32 password_expires = -1; usr_mutex_lock(&osi_authenticate_lock); - code = ka_UserAuthenticateGeneral( - KA_USERAUTH_VERSION+KA_USERAUTH_DOSETPAG2, user, - NULL, cell, passwd, 0, &password_expires, - 0, reason); + code = + ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION + + KA_USERAUTH_DOSETPAG2, user, NULL, cell, + passwd, 0, &password_expires, 0, reason); usr_mutex_unlock(&osi_authenticate_lock); return code; } -int uafs_klog_r( - char *user, - char *cell, - char *passwd, - char **reason) +int +uafs_klog_r(char *user, char *cell, char *passwd, char **reason) { int retval; AFS_GUNLOCK(); @@ -4080,7 +4048,8 @@ int uafs_klog_r( /* * Destroy AFS credentials from the kernel cache */ -int uafs_unlog() +int +uafs_unlog(void) { int code; @@ -4090,7 +4059,8 @@ int uafs_unlog() return code; } -int uafs_unlog_r() +int +uafs_unlog_r(void) { int retval; AFS_GUNLOCK(); @@ -4104,7 +4074,8 @@ int uafs_unlog_r() * NULL if the path is a relative pathname or if the path * doesn't start with the AFS mount point string. */ -char *uafs_afsPathName(char *path) +char * +uafs_afsPathName(char *path) { char *p; char lastchar; @@ -4113,7 +4084,7 @@ char *uafs_afsPathName(char *path) if (path[0] != '/') return NULL; lastchar = '/'; - for (i = 1, p = path+1; *p != '\0' ; p++) { + for (i = 1, p = path + 1; *p != '\0'; p++) { /* Ignore duplicate slashes */ if (*p == '/' && lastchar == '/') continue; @@ -4142,20 +4113,17 @@ char *uafs_afsPathName(char *path) * uafs_klog_nopag * klog but don't allocate a new pag */ -int uafs_klog_nopag( - char *user, - char *cell, - char *passwd, - char **reason) +int +uafs_klog_nopag(char *user, char *cell, char *passwd, char **reason) { int code; afs_int32 password_expires = -1; usr_mutex_lock(&osi_authenticate_lock); - code = ka_UserAuthenticateGeneral( - KA_USERAUTH_VERSION /*+KA_USERAUTH_DOSETPAG2*/, user, - NULL, cell, passwd, 0, &password_expires, - 0, reason); + code = ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION + /*+KA_USERAUTH_DOSETPAG2 */ , user, + NULL, cell, passwd, 0, + &password_expires, 0, reason); usr_mutex_unlock(&osi_authenticate_lock); return code; } @@ -4164,88 +4132,91 @@ int uafs_klog_nopag( * uafs_getcellstatus * get the cell status */ -int uafs_getcellstatus(char *cell, afs_int32 *status) +int +uafs_getcellstatus(char *cell, afs_int32 * status) { - int rc; - struct afs_ioctl iob; + int rc; + struct afs_ioctl iob; - iob.in = cell; - iob.in_size = strlen(cell)+1; - iob.out = 0; - iob.out_size = 0; + iob.in = cell; + iob.in_size = strlen(cell) + 1; + iob.out = 0; + iob.out_size = 0; - rc = call_syscall(AFSCALL_PIOCTL, /*path*/0, _VICEIOCTL(35), - (long)&iob, 0, 0); + rc = call_syscall(AFSCALL_PIOCTL, /*path */ 0, _VICEIOCTL(35), + (long)&iob, 0, 0); - if (rc < 0) { - errno = rc; - return -1; - } + if (rc < 0) { + errno = rc; + return -1; + } - *status = iob.out; - return 0; + *status = (afs_int32) iob.out; + return 0; } /* * uafs_getvolquota * Get quota of volume associated with path */ -int uafs_getvolquota(char *path, afs_int32 *BlocksInUse, afs_int32 *MaxQuota) +int +uafs_getvolquota(char *path, afs_int32 * BlocksInUse, afs_int32 * MaxQuota) { - int rc; - struct afs_ioctl iob; - VolumeStatus *status; - char buf[1024]; + int rc; + struct afs_ioctl iob; + VolumeStatus *status; + char buf[1024]; - iob.in = 0; - iob.in_size = 0; - iob.out = buf; - iob.out_size = 1024; + iob.in = 0; + iob.in_size = 0; + iob.out = buf; + iob.out_size = 1024; - rc = call_syscall(AFSCALL_PIOCTL, path, _VICEIOCTL(4), - (long)&iob, 0, 0); + rc = call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(4), (long)&iob, + 0, 0); - if (rc != 0) { - errno = rc; - return -1; - } + if (rc != 0) { + errno = rc; + return -1; + } - status = (VolumeStatus *) buf; - *BlocksInUse = status->BlocksInUse; - *MaxQuota = status->MaxQuota; - return 0; + status = (VolumeStatus *) buf; + *BlocksInUse = status->BlocksInUse; + *MaxQuota = status->MaxQuota; + return 0; } /* * uafs_setvolquota * Set quota of volume associated with path */ -int uafs_setvolquota(char *path, afs_int32 MaxQuota) +int +uafs_setvolquota(char *path, afs_int32 MaxQuota) { - int rc; - struct afs_ioctl iob; - VolumeStatus *status; - char buf[1024]; + int rc; + struct afs_ioctl iob; + VolumeStatus *status; + char buf[1024]; - iob.in = buf; - iob.in_size = 1024; - iob.out = 0; - iob.out_size = 0; + iob.in = buf; + iob.in_size = 1024; + iob.out = 0; + iob.out_size = 0; - memset(buf, 0, sizeof(VolumeStatus)); - status = (VolumeStatus *) buf; - status->MaxQuota = MaxQuota; - status->MinQuota = -1; + memset(buf, 0, sizeof(VolumeStatus)); + status = (VolumeStatus *) buf; + status->MaxQuota = MaxQuota; + status->MinQuota = -1; - rc = call_syscall(AFSCALL_PIOCTL, path, _VICEIOCTL(5), - (long)&iob, 0, 0); + rc = call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(5), (long)&iob, + 0, 0); - if (rc != 0) { - errno = rc; - return -1; - } + if (rc != 0) { + errno = rc; + return -1; + } - return 0; + return 0; } /* @@ -4253,7 +4224,8 @@ int uafs_setvolquota(char *path, afs_int32 MaxQuota) * Determine whether a dir. is a mount point or not * return 1 if mount point, 0 if not */ -int uafs_statmountpoint(char *path) +int +uafs_statmountpoint(char *path) { int retval; int code; @@ -4265,7 +4237,8 @@ int uafs_statmountpoint(char *path) return retval; } -int uafs_statmountpoint_r(char *path) +int +uafs_statmountpoint_r(char *path) { int code; struct vnode *vp; @@ -4275,8 +4248,8 @@ int uafs_statmountpoint_r(char *path) code = uafs_LookupName(path, afs_CurrentDir, &vp, 0, 1); if (code != 0) { - errno = code; - return -1; + errno = code; + return -1; } avc = VTOAFS(vp); @@ -4290,7 +4263,8 @@ int uafs_statmountpoint_r(char *path) * uafs_getRights * Get a list of rights for the current user on path. */ -int uafs_getRights(char *path) +int +uafs_getRights(char *path) { int code, rc; struct vnode *vp; @@ -4299,20 +4273,16 @@ int uafs_getRights(char *path) AFS_GLOCK(); code = uafs_LookupName(path, afs_CurrentDir, &vp, 1, 0); if (code != 0) { - errno = code; - AFS_GUNLOCK(); - return -1; + errno = code; + AFS_GUNLOCK(); + return -1; } - afs_rights = PRSFS_READ | - PRSFS_WRITE | - PRSFS_INSERT | - PRSFS_LOOKUP | - PRSFS_DELETE | - PRSFS_LOCK | - PRSFS_ADMINISTER; + afs_rights = + PRSFS_READ | PRSFS_WRITE | PRSFS_INSERT | PRSFS_LOOKUP | PRSFS_DELETE + | PRSFS_LOCK | PRSFS_ADMINISTER; - afs_rights = afs_getRights (vp, afs_rights, u.u_cred); + afs_rights = afs_getRights(vp, afs_rights, u.u_cred); AFS_GUNLOCK(); return afs_rights; diff --git a/src/afs/UKERNEL/afs_usrops.h b/src/afs/UKERNEL/afs_usrops.h index 0ef5fe6e4..a806e5a09 100644 --- a/src/afs/UKERNEL/afs_usrops.h +++ b/src/afs/UKERNEL/afs_usrops.h @@ -68,14 +68,14 @@ extern int afs_mountDirLen; extern void uafs_InitClient(void); extern void uafs_InitThread(void); -extern void uafs_Init(char *, char *, char *, char *, int, int, int, int, - int, int, int, int, int, int, char *); +extern void uafs_Init(char *, char *, char *, char *, int, int, int, int, int, + int, int, int, int, int, char *); extern void uafs_RxServerProc(void); extern int uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentP, struct usr_vnode **vpp); extern int uafs_LookupName(char *path, struct usr_vnode *parentP, struct usr_vnode **vpp, int follow, - int no_eval_mtpt); + int no_eval_mtpt); extern int uafs_LookupParent(char *path, struct usr_vnode **vpp); extern int uafs_GetAttr(struct usr_vnode *vp, struct stat *stats); @@ -107,6 +107,8 @@ extern int uafs_truncate(char *path, int len); extern int uafs_truncate_r(char *path, int len); extern int uafs_ftruncate(int fd, int len); extern int uafs_ftruncate_r(int fd, int len); +extern int uafs_lseek(int fd, int offset, int whence); +extern int uafs_lseek_r(int fd, int offset, int whence); extern int uafs_chmod(char *path, int mode); extern int uafs_chmod_r(char *path, int mode); extern int uafs_fchmod(int fd, int mode); @@ -127,16 +129,16 @@ extern int uafs_FlushFile(char *path); extern int uafs_FlushFile_r(char *path); extern usr_DIR *uafs_opendir(char *path); extern usr_DIR *uafs_opendir_r(char *path); -extern struct usr_dirent *uafs_readdir(usr_DIR *dirp); -extern struct usr_dirent *uafs_readdir_r(usr_DIR *dirp); +extern struct usr_dirent *uafs_readdir(usr_DIR * dirp); +extern struct usr_dirent *uafs_readdir_r(usr_DIR * dirp); extern int uafs_getdents(int fd, struct min_direct *buf, int len); extern int uafs_getdents_r(int fd, struct min_direct *buf, int len); -extern int uafs_closedir(usr_DIR *dirp); -extern int uafs_closedir_r(usr_DIR *dirp); +extern int uafs_closedir(usr_DIR * dirp); +extern int uafs_closedir_r(usr_DIR * dirp); extern void uafs_ThisCell(char *namep); extern void uafs_ThisCell_r(char *namep); -extern int uafs_klog(char *user,char *cell,char *passwd,char **reason); -extern int uafs_klog_r(char *user,char *cell,char *passwd,char **reason); +extern int uafs_klog(char *user, char *cell, char *passwd, char **reason); +extern int uafs_klog_r(char *user, char *cell, char *passwd, char **reason); extern int uafs_unlog(void); extern int uafs_unlog_r(void); extern void uafs_SetRxPort(int); diff --git a/src/afs/UKERNEL/afsincludes.h b/src/afs/UKERNEL/afsincludes.h index d14af1567..049475d21 100644 --- a/src/afs/UKERNEL/afsincludes.h +++ b/src/afs/UKERNEL/afsincludes.h @@ -8,20 +8,21 @@ */ /* AFS based headers */ -#include "../afs/stds.h" -#include "../afs/afs_osi.h" -#include "../rx/rx.h" -#include "../afs/lock.h" -#include "../afs/volerrors.h" -#include "../afs/voldefs.h" -#include "../afsint/afsint.h" -#include "../afs/exporter.h" -#include "../afsint/vldbint.h" -#include "../afs/afs.h" -#include "../afs/afs_chunkops.h" -#include "../afs/rxkad.h" -#include "../afs/prs_fs.h" -#include "../afs/dir.h" -#include "../afs/afs_axscache.h" -#include "../afs/icl.h" -#include "../afs/afs_prototypes.h" +#include "afs/stds.h" +#include "rx/rx.h" +#include "afs/afs_osi.h" +#include "afs/lock.h" +#include "afs/volerrors.h" +#include "afs/voldefs.h" +#include "afsint.h" +#include "afs/exporter.h" +#include "vldbint.h" +#include "afs/afs.h" +#include "afs/afs_chunkops.h" +#include "rx/rxkad.h" +#include "afs/prs_fs.h" +#include "afs/dir.h" +#include "afs/afs_axscache.h" +#include "afs/icl.h" +#include "afs/afs_stats.h" +#include "afs/afs_prototypes.h" diff --git a/src/afs/UKERNEL/osi_groups.c b/src/afs/UKERNEL/osi_groups.c index 8ea5a4c38..5a485920f 100644 --- a/src/afs/UKERNEL/osi_groups.c +++ b/src/afs/UKERNEL/osi_groups.c @@ -12,24 +12,24 @@ * setpag (aliased to use_setpag in sysincludes.h) */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/UKERNEL/osi_groups.c,v 1.1.1.4 2001/07/14 22:19:52 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/UKERNEL/osi_groups.c,v 1.7 2003/07/15 23:14:28 shadow Exp $"); -#include "../afs/sysincludes.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" +#include "afsincludes.h" +#include "afs/afs_stats.h" /* statistics */ -int afs_xsetgroups() +int +afs_xsetgroups() { usr_assert(0); } static int -afs_getgroups( - struct AFS_UCRED *cred, - gid_t *gidset) +afs_getgroups(struct AFS_UCRED *cred, gid_t * gidset) { int ngrps, savengrps; gid_t *gp; @@ -40,18 +40,15 @@ afs_getgroups( savengrps = ngrps = cred->cr_ngroups; gp = cred->cr_groups; while (ngrps--) - *gidset++ = *gp++; + *gidset++ = *gp++; return savengrps; } static int -afs_setgroups( - struct AFS_UCRED **cred, - int ngroups, - gid_t *gidset, - int change_parent) +afs_setgroups(struct AFS_UCRED **cred, int ngroups, gid_t * gidset, + int change_parent) { int ngrps; int i; @@ -70,11 +67,9 @@ afs_setgroups( return (0); } -int usr_setpag( - struct usr_ucred **cred, - afs_uint32 pagvalue, - afs_uint32 *newpag, - int change_parent) +int +usr_setpag(struct usr_ucred **cred, afs_uint32 pagvalue, afs_uint32 * newpag, + int change_parent) { gid_t *gidset; int ngroups, code; @@ -87,18 +82,18 @@ int usr_setpag( if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) { /* We will have to shift grouplist to make room for pag */ - if ((sizeof gidset[0])*(ngroups + 2) > AFS_SMALLOCSIZ) { + if ((sizeof gidset[0]) * (ngroups + 2) > AFS_SMALLOCSIZ) { osi_FreeSmallSpace((char *)gidset); return (E2BIG); } - for (j = ngroups -1; j >= 0; j--) { - gidset[j+2] = gidset[j]; - } + for (j = ngroups - 1; j >= 0; j--) { + gidset[j + 2] = gidset[j]; + } ngroups += 2; } - *newpag = (pagvalue == -1 ? genpag(): pagvalue); + *newpag = (pagvalue == -1 ? genpag() : pagvalue); afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]); - if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) { + if ((code = afs_setgroups(cred, ngroups, gidset, change_parent))) { osi_FreeSmallSpace((char *)gidset); return (code); } diff --git a/src/afs/UKERNEL/osi_machdep.h b/src/afs/UKERNEL/osi_machdep.h index e6d95950d..be85d6f61 100644 --- a/src/afs/UKERNEL/osi_machdep.h +++ b/src/afs/UKERNEL/osi_machdep.h @@ -18,12 +18,12 @@ #ifndef _OSI_MACHDEP_H_ #define _OSI_MACHDEP_H_ -#include "../afs/sysincludes.h" +#include "afs/sysincludes.h" #define MAX_OSI_PATH 1024 #define MAX_OSI_FILES 1024 #define MAX_OSI_LINKS 25 -#define OSI_WAITHASH_SIZE 128 /* must be power of two */ +#define OSI_WAITHASH_SIZE 128 /* must be power of two */ #define MAX_HOSTADDR 32 #define AFS_UCRED usr_ucred @@ -65,4 +65,3 @@ extern usr_mutex_t afs_global_lock; extern int afs_bufferpages; #endif /* _OSI_MACHDEP_H_ */ - diff --git a/src/afs/UKERNEL/osi_vfsops.c b/src/afs/UKERNEL/osi_vfsops.c index dcc39bd07..b0c26711b 100644 --- a/src/afs/UKERNEL/osi_vfsops.c +++ b/src/afs/UKERNEL/osi_vfsops.c @@ -8,13 +8,14 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/UKERNEL/osi_vfsops.c,v 1.1.1.6 2002/05/10 23:44:18 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/UKERNEL/osi_vfsops.c,v 1.10 2003/07/15 23:14:29 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics stuff */ int afs_mount(); @@ -36,52 +37,58 @@ struct vcache *afs_globalVp = 0; int afs_rootCellIndex = 0; #if !defined(AFS_USR_AIX_ENV) -#include "../sys/syscall.h" +#include "sys/syscall.h" #endif afs_mount(afsp, path, data) - char *path; - caddr_t data; - struct vfs *afsp; + char *path; + caddr_t data; + struct vfs *afsp; { AFS_STATCNT(afs_mount); if (afs_globalVFS) { /* Don't allow remounts since some system (like AIX) don't handle it well */ - return (setuerror(EBUSY)); + return (setuerror(EBUSY)); } afs_globalVFS = afsp; afsp->vfs_bsize = 8192; - afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ - afsp->vfs_fsid.val[1] = (afs_int32) AFS_VFSFSID; + afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ + afsp->vfs_fsid.val[1] = (afs_int32) AFS_VFSFSID; return 0; } -afs_unmount (afsp) - struct vfs *afsp; { +afs_unmount(afsp) + struct vfs *afsp; +{ AFS_STATCNT(afs_unmount); afs_globalVFS = 0; afs_shutdown(); return 0; } -afs_root (OSI_VFS_ARG(afsp), avpp) +afs_root(OSI_VFS_ARG(afsp), avpp) OSI_VFS_DECL(afsp); - struct vnode **avpp; { + struct vnode **avpp; +{ register afs_int32 code = 0; struct vrequest treq; - register struct vcache *tvp=0; + register struct vcache *tvp = 0; OSI_VFS_CONVERT(afsp) - AFS_STATCNT(afs_root); + AFS_STATCNT(afs_root); if (afs_globalVp && (afs_globalVp->states & CStatd)) { tvp = afs_globalVp; } else { - if (!(code = afs_InitReq(&treq, u.u_cred)) && - !(code = afs_CheckInit())) { - tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + if (afs_globalVp) { + afs_PutVCache(afs_globalVp); + afs_globalVp = NULL; + } + + if (!(code = afs_InitReq(&treq, u.u_cred)) + && !(code = afs_CheckInit())) { + tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); /* we really want this to stay around */ if (tvp) { afs_globalVp = tvp; @@ -92,7 +99,7 @@ afs_root (OSI_VFS_ARG(afsp), avpp) if (tvp) { VN_HOLD(AFSTOV(tvp)); - AFSTOV(tvp)->v_flag |= VROOT; /* No-op on Ultrix 2.2 */ + AFSTOV(tvp)->v_flag |= VROOT; /* No-op on Ultrix 2.2 */ afs_globalVFS = afsp; *avpp = AFSTOV(tvp); } @@ -103,32 +110,32 @@ afs_root (OSI_VFS_ARG(afsp), avpp) } afs_sync(afsp) - struct vfs *afsp; + struct vfs *afsp; { AFS_STATCNT(afs_sync); return 0; } afs_statfs(afsp, abp) - register struct vfs *afsp; - struct statfs *abp; - { - AFS_STATCNT(afs_statfs); - abp->f_type = 0; - abp->f_bsize = afsp->vfs_bsize; - abp->f_fsid.val[0] = AFS_VFSMAGIC; /* magic */ - abp->f_fsid.val[1] = (afs_int32) AFS_VFSFSID; - return 0; + register struct vfs *afsp; + struct statfs *abp; +{ + AFS_STATCNT(afs_statfs); + abp->f_type = 0; + abp->f_bsize = afsp->vfs_bsize; + abp->f_fsid.val[0] = AFS_VFSMAGIC; /* magic */ + abp->f_fsid.val[1] = (afs_int32) AFS_VFSFSID; + return 0; } afs_mountroot() { AFS_STATCNT(afs_mountroot); - return(EINVAL); + return (EINVAL); } -afs_swapvp() +afs_swapvp() { AFS_STATCNT(afs_swapvp); - return(EINVAL); + return (EINVAL); } diff --git a/src/afs/UKERNEL/osi_vm.c b/src/afs/UKERNEL/osi_vm.c index 13624bad8..df5eca986 100644 --- a/src/afs/UKERNEL/osi_vm.c +++ b/src/afs/UKERNEL/osi_vm.c @@ -8,46 +8,41 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/UKERNEL/osi_vm.c,v 1.1.1.4 2001/07/14 22:19:52 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/UKERNEL/osi_vm.c,v 1.7 2003/07/15 23:14:29 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ -void osi_VM_Truncate(avc, alen, acred) - struct vcache *avc; - int alen; - struct AFS_UCRED *acred; +void +osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred) { return; } -int osi_VM_FlushVCache(avc, slept) - struct vcache *avc; - int *slept; +int +osi_VM_FlushVCache(struct vcache *avc, int *slept) { return 0; } -void osi_VM_StoreAllSegments(avc) - struct vcache *avc; +void +osi_VM_StoreAllSegments(struct vcache *avc) { return; } -void osi_VM_TryToSmush(avc, acred, sync) - struct vcache *avc; - struct AFS_UCRED *acred; - int sync; +void +osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync) { return; } -void osi_VM_FlushPages(avc, credp) - struct vcache *avc; - struct AFS_UCRED *credp; +void +osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp) { return; } diff --git a/src/afs/UKERNEL/osi_vnodeops.c b/src/afs/UKERNEL/osi_vnodeops.c index fc0a1e537..875098a9f 100644 --- a/src/afs/UKERNEL/osi_vnodeops.c +++ b/src/afs/UKERNEL/osi_vnodeops.c @@ -8,13 +8,14 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/UKERNEL/osi_vnodeops.c,v 1.1.1.5 2002/05/10 23:44:19 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/UKERNEL/osi_vnodeops.c,v 1.7 2003/07/15 23:14:29 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ extern int afs_noop(); extern int afs_badop(); @@ -38,12 +39,9 @@ extern int afs_fsync(); extern int afs_lockctl(); extern int afs_fid(); -int afs_vrdwr( - struct usr_vnode *avc, - struct usr_uio *uio, - int rw, - int io, - struct usr_ucred* cred) +int +afs_vrdwr(struct usr_vnode *avc, struct usr_uio *uio, int rw, int io, + struct usr_ucred *cred) { int rc; @@ -56,42 +54,44 @@ int afs_vrdwr( return rc; } -int afs_inactive(struct vcache *avc, struct AFS_UCRED *acred) +int +afs_inactive(struct vcache *avc, struct AFS_UCRED *acred) { struct vnode *vp = AFSTOV(avc); - if (afs_shuttingdown) return ; + if (afs_shuttingdown) + return; usr_assert(avc->vrefCount == 0); afs_InactiveVCache(avc, acred); } struct usr_vnodeops Afs_vnodeops = { - afs_open, - afs_close, - afs_vrdwr, - afs_badop, /* ioctl */ - afs_noop, /* select */ - afs_getattr, - afs_setattr, - afs_access, - afs_lookup, - afs_create, - afs_remove, - afs_link, - afs_rename, - afs_mkdir, - afs_rmdir, - afs_readdir, - afs_symlink, - afs_readlink, - afs_fsync, - afs_inactive, - afs_badop, /* bmap */ - afs_badop, /* strategy */ - afs_badop, /* bread */ - afs_badop, /* brelse */ - afs_lockctl, - afs_fid + afs_open, + afs_close, + afs_vrdwr, + afs_badop, /* ioctl */ + afs_noop, /* select */ + afs_getattr, + afs_setattr, + afs_access, + afs_lookup, + afs_create, + afs_remove, + afs_link, + afs_rename, + afs_mkdir, + afs_rmdir, + afs_readdir, + afs_symlink, + afs_readlink, + afs_fsync, + afs_inactive, + afs_badop, /* bmap */ + afs_badop, /* strategy */ + afs_badop, /* bread */ + afs_badop, /* brelse */ + afs_lockctl, + afs_fid }; struct usr_vnodeops *afs_ops = &Afs_vnodeops; diff --git a/src/afs/UKERNEL/sysincludes.h b/src/afs/UKERNEL/sysincludes.h index 73db66ab7..54f078beb 100644 --- a/src/afs/UKERNEL/sysincludes.h +++ b/src/afs/UKERNEL/sysincludes.h @@ -11,7 +11,7 @@ #define __AFS_SYSINCLUDESH__ 1 #include -#if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) /* must be included after KERNEL undef'd */ +#if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) /* must be included after KERNEL undef'd */ #include #endif #include @@ -98,9 +98,9 @@ #endif /* AFS_USR_OSF_ENV */ #ifdef AFS_USR_LINUX22_ENV -#include /* _IOW() */ -#include /* struct iovec */ -#include /* struct timeval */ +#include /* _IOW() */ +#include /* struct iovec */ +#include /* struct timeval */ #include #include #include @@ -143,11 +143,11 @@ #endif /* AFS_AFSDB_ENV */ /* glibc 2.2 has pthread_attr_setstacksize */ -#if defined(AFS_LINUX22_ENV) || defined(AFS_USR_LINUX22_ENV) && (__GLIBC_MINOR__ < 2) +#if (defined(AFS_LINUX22_ENV) && !defined(AFS_USR_LINUX22_ENV)) || (defined(AFS_USR_LINUX22_ENV) && (__GLIBC_MINOR__ < 2)) #define pthread_attr_setstacksize(a,b) 0 #endif -#include /* afs_usrops.h uses struct stat in prototypes */ +#include /* afs_usrops.h uses struct stat in prototypes */ #ifdef NETSCAPE_NSAPI @@ -631,7 +631,7 @@ typedef int usr_vtype_t; #ifdef IO_SYNC #undef IO_SYNC #endif - + #define FAPPEND 0x0100 #define IO_APPEND FAPPEND #define FSYNC 0x0200 @@ -840,9 +840,9 @@ enum usr_uio_rw { USR_UIO_READ, USR_UIO_WRITE }; * waking when we do the signal. */ typedef struct { - int waiters; - CRITICAL lock; - CONDVAR cond; + int waiters; + CRITICAL lock; + CONDVAR cond; } usr_cond_t; #define usr_mutex_t CRITICAL @@ -973,6 +973,9 @@ extern pthread_cond_t usr_sleep_cond; #define uprintf printf #define usr_getpid() (int)(usr_thread_self()) +#ifdef ISAFS_GLOCK +#undef ISAFS_GLOCK +#endif #define ISAFS_GLOCK() (usr_thread_self() == afs_global_owner) #endif /* NETSCAPE_NSAPI */ @@ -988,7 +991,7 @@ extern pthread_cond_t usr_sleep_cond; { \ (vp)->v_count++; \ } - + #define VN_RELE(vp) \ do { \ AFS_ASSERT_GLOCK(); \ @@ -998,40 +1001,40 @@ do { \ } while(0) struct usr_statfs { - unsigned long f_type; - unsigned long f_bsize; - unsigned long f_frsize; - unsigned long f_ffree; - unsigned long f_favail; - struct { - unsigned long val[2]; - } f_fsid; - char f_basetype[FSTYPSZ]; - unsigned long f_flag; - unsigned long f_namemax; - unsigned long f_blocks; - unsigned long f_bfree; - unsigned long f_bavail; - unsigned long f_files; + unsigned long f_type; + unsigned long f_bsize; + unsigned long f_frsize; + unsigned long f_ffree; + unsigned long f_favail; + struct { + unsigned long val[2]; + } f_fsid; + char f_basetype[FSTYPSZ]; + unsigned long f_flag; + unsigned long f_namemax; + unsigned long f_blocks; + unsigned long f_bfree; + unsigned long f_bavail; + unsigned long f_files; }; struct usr_vattr { - long va_mask; - usr_vtype_t va_type; - unsigned short va_mode; - long va_uid; - long va_gid; - unsigned long va_fsid; - unsigned long va_nodeid; - unsigned long va_nlink; - unsigned long va_size; - struct timeval va_atime; - struct timeval va_mtime; - struct timeval va_ctime; - unsigned long va_rdev; - unsigned long va_blocksize; - unsigned long va_blocks; - unsigned long va_vcode; + long va_mask; + usr_vtype_t va_type; + unsigned short va_mode; + long va_uid; + long va_gid; + unsigned long va_fsid; + unsigned long va_nodeid; + unsigned long va_nlink; + unsigned long va_size; + struct timeval va_atime; + struct timeval va_mtime; + struct timeval va_ctime; + unsigned long va_rdev; + unsigned long va_blocksize; + unsigned long va_blocks; + unsigned long va_vcode; }; #ifdef VSUID @@ -1053,7 +1056,7 @@ struct usr_vattr { #undef VEXEC #endif -#define VSUID 04000 +#define VSUID 04000 #define VSGID 02000 #define VSVTX 01000 #define VREAD 00400 @@ -1062,99 +1065,99 @@ struct usr_vattr { struct usr_vnode { - unsigned short v_flag; - unsigned long v_count; - struct usr_vnodeops *v_op; - struct usr_vfs * v_vfsp; - long v_type; - unsigned long v_rdev; - char * v_data; + unsigned short v_flag; + unsigned long v_count; + struct usr_vnodeops *v_op; + struct usr_vfs *v_vfsp; + long v_type; + unsigned long v_rdev; + char *v_data; }; -struct usr_inode { - daddr_t i_db[NDADDR]; - struct usr_vnode *i_devvp; - unsigned long i_dev; - long i_flag; - struct usr_inode *i_freef; - struct usr_inode **i_freeb; - long i_gid; - daddr_t i_ib[NIADDR]; - unsigned short i_mode; - short i_nlink; - unsigned long i_number; - long i_size; - long i_uid; - struct usr_vnode i_vnode; - struct { - unsigned long ic_spare[4]; - } i_ic; +struct usr_inode { + daddr_t i_db[NDADDR]; + struct usr_vnode *i_devvp; + unsigned long i_dev; + long i_flag; + struct usr_inode *i_freef; + struct usr_inode **i_freeb; + long i_gid; + daddr_t i_ib[NIADDR]; + unsigned short i_mode; + short i_nlink; + unsigned long i_number; + long i_size; + long i_uid; + struct usr_vnode i_vnode; + struct { + unsigned long ic_spare[4]; + } i_ic; }; extern struct usr_inode *iget(); struct usr_fileops { - int (*vno_rw)(); - int (*vno_ioctl)(); - int (*vno_select)(); - int (*vno_closex)(); + int (*vno_rw) (void); + int (*vno_ioctl) (void); + int (*vno_select) (void); + int (*vno_closex) (void); }; struct usr_file { - unsigned short f_flag; - offset_t f_offset; - struct usr_ucred *f_cred; - struct usr_fileops *f_ops; - char * f_data; - long f_type; + unsigned short f_flag; + offset_t f_offset; + struct usr_ucred *f_cred; + struct usr_fileops *f_ops; + char *f_data; + long f_type; }; extern struct usr_file *falloc(); extern struct usr_file *getf(int); -#ifdef fid_len -#undef fid_len +#ifdef fid_len +#undef fid_len #endif #ifdef fid_data #undef fid_data #endif struct usr_fid { - unsigned short fid_len; - unsigned short fid_reserved; - char fid_data[MAXFIDSZ]; + unsigned short fid_len; + unsigned short fid_reserved; + char fid_data[MAXFIDSZ]; }; struct usr_flock { - short l_type; - short l_whence; - off_t l_start; - off_t l_len; - long l_sysid; - pid_t l_pid; + short l_type; + short l_whence; + off_t l_start; + off_t l_len; + long l_sysid; + pid_t l_pid; }; -extern struct usr_ucred *usr_crget(); +extern struct usr_ucred *usr_crget(void); extern struct usr_ucred *usr_crcopy(struct usr_ucred *); extern int usr_crhold(struct usr_ucred *); extern int usr_crfree(struct usr_ucred *); extern struct usr_ucred *afs_global_ucredp; -struct usr_proc { - unsigned long p_flag; - pid_t p_pid; - pid_t p_ppid; - struct usr_ucred *p_ucred; - char p_cursig; +struct usr_proc { + unsigned long p_flag; + pid_t p_pid; + pid_t p_ppid; + struct usr_ucred *p_ucred; + char p_cursig; }; -struct usr_a { - int fd; - int syscall; - int parm1; - int parm2; - int parm3; - int parm4; - int parm5; - int parm6; +struct usr_a { + int fd; + int syscall; + int parm1; + int parm2; + int parm3; + int parm4; + int parm5; + int parm6; }; #ifdef uio_offset @@ -1162,12 +1165,12 @@ struct usr_a { #endif struct usr_uio { - struct iovec *uio_iov; - int uio_iovcnt; - long uio_offset; - int uio_segflg; - short uio_fmode; - int uio_resid; + struct iovec *uio_iov; + int uio_iovcnt; + long uio_offset; + int uio_segflg; + short uio_fmode; + int uio_resid; }; #ifdef b_blkno @@ -1177,111 +1180,110 @@ struct usr_uio { #undef b_vp #endif -struct usr_buf { - int b_flags; - short b_dev; - unsigned b_bcount; - struct { - char * b_addr; - struct usr_fs *b_fs; - } b_un; - long b_blkno; - unsigned int b_resid; - struct usr_vnode *b_vp; +struct usr_buf { + int b_flags; + short b_dev; + unsigned b_bcount; + struct { + char *b_addr; + struct usr_fs *b_fs; + } b_un; + long b_blkno; + unsigned int b_resid; + struct usr_vnode *b_vp; }; struct usr_socket { - int sock; - short port; + int sock; + short port; }; #define NDIRSIZ_LEN(len) \ ((sizeof (struct usr_dirent)+4 - (MAXNAMLEN+1)) + (((len)+1 + 3) &~ 3)) struct usr_vnodeops { - int (*vn_open)(); - int (*vn_close)(); - int (*vn_rdwr)(); - int (*vn_ioctl)(); - int (*vn_select)(); - int (*vn_getattr)(); - int (*vn_setattr)(); - int (*vn_access)(); - int (*vn_lookup)(); - int (*vn_create)(); - int (*vn_remove)(); - int (*vn_link)(); - int (*vn_rename)(); - int (*vn_mkdir)(); - int (*vn_rmdir)(); - int (*vn_readdir)(); - int (*vn_symlink)(); - int (*vn_readlink)(); - int (*vn_fsync)(); - int (*vn_inactive)(); - int (*vn_bmap)(); - int (*vn_strategy)(); - int (*vn_bread)(); - int (*vn_brelse)(); - int (*vn_lockctl)(); - int (*vn_fid)(); + int (*vn_open) (char *path, int flags, int mode); + int (*vn_close) (int fd); + int (*vn_rdwr) (); + int (*vn_ioctl) (void); + int (*vn_select) (void); + int (*vn_getattr) (); + int (*vn_setattr) (); + int (*vn_access) (); + int (*vn_lookup) (); + int (*vn_create) (); + int (*vn_remove) (); + int (*vn_link) (); + int (*vn_rename) (); + int (*vn_mkdir) (); + int (*vn_rmdir) (); + int (*vn_readdir) (); + int (*vn_symlink) (); + int (*vn_readlink) (); + int (*vn_fsync) (); + int (*vn_inactive) (); + int (*vn_bmap) (); + int (*vn_strategy) (); + int (*vn_bread) (); + int (*vn_brelse) (); + int (*vn_lockctl) (); + int (*vn_fid) (); }; struct usr_fs { - int dummy; + int dummy; }; -struct usr_mount -{ - char m_flags; - unsigned long m_dev; - struct usr_inode *m_inodp; - struct usr_buf *m_bufp; - struct usr_vnode *m_mount; +struct usr_mount { + char m_flags; + unsigned long m_dev; + struct usr_inode *m_inodp; + struct usr_buf *m_bufp; + struct usr_vnode *m_mount; }; extern struct usr_mount *getmp(unsigned long); typedef long usr_whymountroot_t; struct usr_vfsops { - int (*vfs_mount)(); - int (*vfs_unmount)(); - int (*vfs_root)(); - int (*vfs_statfs)(); - int (*vfs_mountroot)(); - int (*vfs_swapvp)(); + int (*vfs_mount) (); + int (*vfs_unmount) (); + int (*vfs_root) (); + int (*vfs_statfs) (); + int (*vfs_mountroot) (); + int (*vfs_swapvp) (); }; struct usr_vfs { - struct usr_vnode *vfs_vnodecovered; - struct { - unsigned long val[2]; - } vfs_fsid; - char * vfs_data; - unsigned long vfs_bsize; - struct usr_mount *vfs_mount; - struct usr_vfsops *vfs_op; + struct usr_vnode *vfs_vnodecovered; + struct { + unsigned long val[2]; + } vfs_fsid; + char *vfs_data; + unsigned long vfs_bsize; + struct usr_mount *vfs_mount; + struct usr_vfsops *vfs_op; }; struct usr_sysent { - char sy_narg; - int (*sy_call)(); + char sy_narg; + int (*sy_call) (); }; extern struct usr_sysent usr_sysent[]; struct usr_ifnet { - struct usr_ifnet *if_next; - short if_flags; - u_int if_mtu; - u_int if_metric; - struct usr_ifaddr *if_addrlist; + struct usr_ifnet *if_next; + short if_flags; + u_int if_mtu; + u_int if_metric; + struct usr_ifaddr *if_addrlist; }; extern struct usr_ifnet *usr_ifnet; struct usr_ifaddr { - struct usr_ifaddr *ifa_next; - struct usr_ifnet *ifa_ifp; - struct sockaddr ifa_addr; + struct usr_ifaddr *ifa_next; + struct usr_ifnet *ifa_ifp; + struct sockaddr ifa_addr; }; #ifdef ia_ifp @@ -1292,14 +1294,14 @@ struct usr_ifaddr { #endif struct usr_in_ifaddr { - struct usr_in_ifaddr *ia_next; - struct usr_ifnet *ia_ifp; - struct sockaddr_in ia_addr; - unsigned long ia_net; - unsigned long ia_netmask; - unsigned long ia_subnet; - unsigned long ia_subnetmask; - struct in_addr ia_netbroadcast; + struct usr_in_ifaddr *ia_next; + struct usr_ifnet *ia_ifp; + struct sockaddr_in ia_addr; + unsigned long ia_net; + unsigned long ia_netmask; + unsigned long ia_subnet; + unsigned long ia_subnetmask; + struct in_addr ia_netbroadcast; }; extern struct usr_in_ifaddr *usr_in_ifaddr; @@ -1315,12 +1317,12 @@ extern long V; struct min_direct { #if defined(AFS_OFS_ENV) || defined(AFS_USR_OSF_ENV) - unsigned int d_fileno; -#else /* AFS_OFS_ENV || AFS_USR_OSF_ENV */ - unsigned long d_fileno; -#endif /* AFS_OFS_ENV || AFS_USR_OSF_ENV */ - unsigned short d_reclen; - unsigned short d_namlen; + unsigned int d_fileno; +#else /* AFS_OFS_ENV || AFS_USR_OSF_ENV */ + unsigned long d_fileno; +#endif /* AFS_OFS_ENV || AFS_USR_OSF_ENV */ + unsigned short d_reclen; + unsigned short d_namlen; }; #ifndef NGROUPS @@ -1329,58 +1331,59 @@ struct min_direct { #ifndef NOGROUP #define NOGROUP (-1) #endif +#ifdef cr_gid +#undef cr_gid +#endif struct usr_ucred { - unsigned long cr_ref; - long cr_uid; -#if !defined(AFS_USR_FBSD_ENV) - long cr_gid; -#endif - long cr_ruid; - long cr_rgid; - long cr_suid; - long cr_sgid; - long cr_ngroups; - gid_t cr_groups[NGROUPS]; + unsigned long cr_ref; + long cr_uid; + long cr_gid; + long cr_ruid; + long cr_rgid; + long cr_suid; + long cr_sgid; + long cr_ngroups; + gid_t cr_groups[NGROUPS]; }; #ifdef u_rval1 #undef u_rval1 #endif -struct usr_user { - int u_error; - int u_prio; - char * u_ap; - int u_rval1; - long u_viceid; - unsigned long u_expiration; - struct usr_proc *u_procp; - struct usr_ucred *u_cred; - struct { - int r_val1; - } u_r; +struct usr_user { + int u_error; + int u_prio; + char *u_ap; + int u_rval1; + long u_viceid; + unsigned long u_expiration; + struct usr_proc *u_procp; + struct usr_ucred *u_cred; + struct { + int r_val1; + } u_r; }; #define u_rval1 u_r.r_val1 #define u (*(get_user_struct())) -extern struct usr_user *get_user_struct(); +extern struct usr_user *get_user_struct(void); #define USR_DIRSIZE 2048 struct usr_dirent { - unsigned long d_ino; - unsigned long d_off; - unsigned short d_reclen; - char d_name[MAXNAMLEN+1]; + unsigned long d_ino; + unsigned long d_off; + unsigned short d_reclen; + char d_name[MAXNAMLEN + 1]; }; typedef struct { - int dd_fd; - int dd_loc; - int dd_size; - int dd_reserved; - char *dd_buf; + int dd_fd; + int dd_loc; + int dd_size; + int dd_reserved; + char *dd_buf; } usr_DIR; extern unsigned short usr_rx_port; diff --git a/src/afs/VNOPS/afs_vnop_access.c b/src/afs/VNOPS/afs_vnop_access.c index 5a19f3dcb..81a0d111b 100644 --- a/src/afs/VNOPS/afs_vnop_access.c +++ b/src/afs/VNOPS/afs_vnop_access.c @@ -20,19 +20,20 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_access.c,v 1.1.1.6 2002/08/02 04:29:00 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_access.c,v 1.10 2003/07/15 23:14:29 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" #ifndef ANONYMOUSID -#define ANONYMOUSID 32766 /* make sure this is same as in ptserver.h */ +#define ANONYMOUSID 32766 /* make sure this is same as in ptserver.h */ #endif @@ -51,10 +52,9 @@ static char fileModeMap[8] = { }; /* avc must be held. Returns bit map of mode bits. Ignores file mode bits */ -afs_int32 afs_GetAccessBits (avc, arights, areq) - register struct vcache *avc; - register afs_int32 arights; - register struct vrequest *areq; +afs_int32 +afs_GetAccessBits(register struct vcache *avc, register afs_int32 arights, + register struct vrequest *areq) { AFS_STATCNT(afs_GetAccessBits); /* see if anyuser has the required access bits */ @@ -63,41 +63,40 @@ afs_int32 afs_GetAccessBits (avc, arights, areq) } /* look in per-pag cache */ - if (avc->Access) { /* not beautiful, but Sun's cc will tolerate it */ - struct axscache *ac; + if (avc->Access) { /* not beautiful, but Sun's cc will tolerate it */ + struct axscache *ac; - ac = afs_FindAxs(avc->Access, areq->uid); - if (ac) { - return (arights & ac->axess); - } + ac = afs_FindAxs(avc->Access, areq->uid); + if (ac) { + return (arights & ac->axess); + } } - if (!(avc->states & CForeign)) { - /* If there aren't any bits cached for this user (but the vnode - * _is_ cached, obviously), make sure this user has valid tokens - * before bothering with the RPC. */ - struct unixuser *tu; - extern struct unixuser *afs_FindUser(); - tu = afs_FindUser( areq->uid, avc->fid.Cell, READ_LOCK ); - if (!tu) { - return (arights & avc->anyAccess); - } - if ((tu->vid == UNDEFVID) || !(tu->states & UHasTokens) || - (tu->states & UTokensBad)) { - afs_PutUser(tu, READ_LOCK); - return (arights & avc->anyAccess); - } - else { - afs_PutUser(tu, READ_LOCK); - } + if (!(avc->states & CForeign)) { + /* If there aren't any bits cached for this user (but the vnode + * _is_ cached, obviously), make sure this user has valid tokens + * before bothering with the RPC. */ + struct unixuser *tu; + extern struct unixuser *afs_FindUser(); + tu = afs_FindUser(areq->uid, avc->fid.Cell, READ_LOCK); + if (!tu) { + return (arights & avc->anyAccess); + } + if ((tu->vid == UNDEFVID) || !(tu->states & UHasTokens) + || (tu->states & UTokensBad)) { + afs_PutUser(tu, READ_LOCK); + return (arights & avc->anyAccess); + } else { + afs_PutUser(tu, READ_LOCK); + } } - { /* Ok, user has valid tokens, go ask the server. */ - struct AFSFetchStatus OutStatus; - afs_int32 code; - - code = afs_FetchStatus(avc, &avc->fid, areq, &OutStatus); - return (code ? 0 : OutStatus.CallerAccess & arights); + { /* Ok, user has valid tokens, go ask the server. */ + struct AFSFetchStatus OutStatus; + afs_int32 code; + + code = afs_FetchStatus(avc, &avc->fid, areq, &OutStatus); + return (code ? 0 : OutStatus.CallerAccess & arights); } } @@ -105,10 +104,10 @@ afs_int32 afs_GetAccessBits (avc, arights, areq) /* the new access ok function. AVC must be held but not locked. if avc is a * file, its parent need not be held, and should not be locked. */ -afs_AccessOK(avc, arights, areq, check_mode_bits) -struct vcache *avc; -afs_int32 arights, check_mode_bits; -struct vrequest *areq; { +int +afs_AccessOK(struct vcache *avc, afs_int32 arights, struct vrequest *areq, + afs_int32 check_mode_bits) +{ register struct vcache *tvc; struct VenusFid dirFid; register afs_int32 mask; @@ -118,10 +117,9 @@ struct vrequest *areq; { AFS_STATCNT(afs_AccessOK); if ((vType(avc) == VDIR) || (avc->states & CForeign)) { - /* rights are just those from acl */ - return (arights == afs_GetAccessBits(avc, arights, areq)); - } - else { + /* rights are just those from acl */ + return (arights == afs_GetAccessBits(avc, arights, areq)); + } else { /* some rights come from dir and some from file. Specifically, you * have "a" rights to a file if you are its owner, which comes * back as "a" rights to the file. You have other rights just @@ -136,14 +134,12 @@ struct vrequest *areq; { dirFid.Fid.Vnode = avc->parentVnode; dirFid.Fid.Unique = avc->parentUnique; /* Avoid this GetVCache call */ - tvc = afs_GetVCache(&dirFid, areq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + tvc = afs_GetVCache(&dirFid, areq, NULL, NULL); if (tvc) { dirBits = afs_GetAccessBits(tvc, arights, areq); - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); } - } - else + } else dirBits = 0xffffffff; /* assume OK; this is a race condition */ if (arights & PRSFS_ADMINISTER) fileBits = afs_GetAccessBits(avc, arights, areq); @@ -151,25 +147,28 @@ struct vrequest *areq; { fileBits = 0; /* don't make call if results don't matter */ /* compute basic rights in fileBits, taking A from file bits */ - fileBits = (fileBits & PRSFS_ADMINISTER) | (dirBits & ~PRSFS_ADMINISTER); + fileBits = + (fileBits & PRSFS_ADMINISTER) | (dirBits & ~PRSFS_ADMINISTER); /* for files, throw in R and W if have I and A (owner). This makes - insert-only dirs work properly */ - if (vType(avc) != VDIR && (fileBits & (PRSFS_ADMINISTER | PRSFS_INSERT)) == + * insert-only dirs work properly */ + if (vType(avc) != VDIR + && (fileBits & (PRSFS_ADMINISTER | PRSFS_INSERT)) == (PRSFS_ADMINISTER | PRSFS_INSERT)) fileBits |= (PRSFS_READ | PRSFS_WRITE); if (check_mode_bits & CHECK_MODE_BITS) { /* owner mode bits are further restrictions on the access mode - * The mode bits are mapped to protection bits through the - * fileModeMap. If CMB_ALLOW_EXEC_AS_READ is set, it's from the - * NFS translator and we don't know if it's a read or execute - * on the NFS client, but both need to read the data. - */ + * The mode bits are mapped to protection bits through the + * fileModeMap. If CMB_ALLOW_EXEC_AS_READ is set, it's from the + * NFS translator and we don't know if it's a read or execute + * on the NFS client, but both need to read the data. + */ mask = (avc->m.Mode & 0700) >> 6; /* file restrictions to use */ fileBits &= ~fileModeMap[mask]; if (check_mode_bits & CMB_ALLOW_EXEC_AS_READ) { - if (avc->m.Mode & 0100) fileBits |= PRSFS_READ; + if (avc->m.Mode & 0100) + fileBits |= PRSFS_READ; } } return ((fileBits & arights) == arights); /* true if all rights bits are on */ @@ -177,45 +176,48 @@ struct vrequest *areq; { } -#if defined(AFS_SUN5_ENV) || (defined(AFS_SGI_ENV) && !defined(AFS_SGI65_ENV)) -afs_access(OSI_VC_ARG(avc), amode, flags, acred) - int flags; +#if defined(AFS_SUN5_ENV) || (defined(AFS_SGI_ENV) && !defined(AFS_SGI65_ENV)) +int +afs_access(OSI_VC_DECL(avc), register afs_int32 amode, int flags, + struct AFS_UCRED *acred) #else -afs_access(OSI_VC_ARG(avc), amode, acred) +int +afs_access(OSI_VC_DECL(avc), register afs_int32 amode, + struct AFS_UCRED *acred) #endif - OSI_VC_DECL(avc); - register afs_int32 amode; - struct AFS_UCRED *acred; { +{ register afs_int32 code; struct vrequest treq; struct afs_fakestat_state fakestate; OSI_VC_CONVERT(avc) - AFS_STATCNT(afs_access); - afs_Trace3(afs_iclSetp, CM_TRACE_ACCESS, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, amode, ICL_TYPE_INT32, avc->m.Length); + AFS_STATCNT(afs_access); + afs_Trace3(afs_iclSetp, CM_TRACE_ACCESS, ICL_TYPE_POINTER, avc, + ICL_TYPE_INT32, amode, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length)); afs_InitFakeStat(&fakestate); - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; code = afs_EvalFakeStat(&avc, &fakestate, &treq); if (code) { - afs_PutFakeStat(&fakestate); - return code; + afs_PutFakeStat(&fakestate); + return code; } code = afs_VerifyVCache(avc, &treq); if (code) { - afs_PutFakeStat(&fakestate); - code = afs_CheckCode(code, &treq, 16); - return code; + afs_PutFakeStat(&fakestate); + code = afs_CheckCode(code, &treq, 16); + return code; } /* if we're looking for write access and we have a read-only file system, report it */ if ((amode & VWRITE) && (avc->states & CRO)) { - afs_PutFakeStat(&fakestate); + afs_PutFakeStat(&fakestate); return EROFS; } - code = 1; /* Default from here on in is access ok. */ + code = 1; /* Default from here on in is access ok. */ if (avc->states & CForeign) { /* In the dfs xlator the EXEC bit is mapped to LOOKUP */ if (amode & VEXEC) @@ -224,24 +226,33 @@ afs_access(OSI_VC_ARG(avc), amode, acred) code = afs_AccessOK(avc, PRSFS_WRITE, &treq, CHECK_MODE_BITS); if (code && (vType(avc) == VDIR)) { if (code) - code = afs_AccessOK(avc, PRSFS_INSERT, &treq, CHECK_MODE_BITS); - if (!code) - code = afs_AccessOK(avc, PRSFS_DELETE, &treq, CHECK_MODE_BITS); - } - } - if (code && (amode & VREAD)) + code = + afs_AccessOK(avc, PRSFS_INSERT, &treq, + CHECK_MODE_BITS); + if (!code) + code = + afs_AccessOK(avc, PRSFS_DELETE, &treq, + CHECK_MODE_BITS); + } + } + if (code && (amode & VREAD)) code = afs_AccessOK(avc, PRSFS_READ, &treq, CHECK_MODE_BITS); } else { if (vType(avc) == VDIR) { - if (amode & VEXEC) - code = afs_AccessOK(avc, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS); + if (amode & VEXEC) + code = + afs_AccessOK(avc, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS); if (code && (amode & VWRITE)) { - code = afs_AccessOK(avc, PRSFS_INSERT, &treq, CHECK_MODE_BITS); - if (!code) - code = afs_AccessOK(avc, PRSFS_DELETE, &treq, CHECK_MODE_BITS); + code = + afs_AccessOK(avc, PRSFS_INSERT, &treq, CHECK_MODE_BITS); + if (!code) + code = + afs_AccessOK(avc, PRSFS_DELETE, &treq, + CHECK_MODE_BITS); } if (code && (amode & VREAD)) - code = afs_AccessOK(avc, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS); + code = + afs_AccessOK(avc, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS); } else { if (amode & VEXEC) { code = afs_AccessOK(avc, PRSFS_READ, &treq, CHECK_MODE_BITS); @@ -258,32 +269,36 @@ afs_access(OSI_VC_ARG(avc), amode, acred) */ if (!((amode & VREAD) && AFS_NFSXLATORREQ(acred))) #endif - if ((avc->m.Mode & 0100) == 0) code = 0; - } else if (avc->m.Mode & 0100) code = 1; + if ((avc->m.Mode & 0100) == 0) + code = 0; + } else if (avc->m.Mode & 0100) + code = 1; } - if (code && (amode & VWRITE)) - { - code = afs_AccessOK(avc, PRSFS_WRITE, &treq, CHECK_MODE_BITS); - - /* The above call fails when the NFS translator tries to copy - ** a file with r--r--r-- permissions into a directory which - ** has system:anyuser acl. This is because the destination file - ** file is first created with r--r--r-- permissions through an - ** unauthenticated connectin. hence, the above afs_AccessOK - ** call returns failure. hence, we retry without any file - ** mode bit checking */ - if ( !code && AFS_NFSXLATORREQ(acred) && avc->m.Owner == ANONYMOUSID) - code=afs_AccessOK(avc,PRSFS_WRITE, &treq, DONT_CHECK_MODE_BITS); + if (code && (amode & VWRITE)) { + code = afs_AccessOK(avc, PRSFS_WRITE, &treq, CHECK_MODE_BITS); + + /* The above call fails when the NFS translator tries to copy + ** a file with r--r--r-- permissions into a directory which + ** has system:anyuser acl. This is because the destination file + ** file is first created with r--r--r-- permissions through an + ** unauthenticated connectin. hence, the above afs_AccessOK + ** call returns failure. hence, we retry without any file + ** mode bit checking */ + if (!code && AFS_NFSXLATORREQ(acred) + && avc->m.Owner == ANONYMOUSID) + code = + afs_AccessOK(avc, PRSFS_WRITE, &treq, + DONT_CHECK_MODE_BITS); } - if (code && (amode & VREAD)) - code = afs_AccessOK(avc, PRSFS_READ, &treq, CHECK_MODE_BITS); + if (code && (amode & VREAD)) + code = afs_AccessOK(avc, PRSFS_READ, &treq, CHECK_MODE_BITS); } } afs_PutFakeStat(&fakestate); if (code) { return 0; /* if access is ok */ } else { - code = afs_CheckCode(EACCES, &treq, 17); /* failure code */ + code = afs_CheckCode(EACCES, &treq, 17); /* failure code */ return code; } } @@ -293,21 +308,21 @@ afs_access(OSI_VC_ARG(avc), amode, acred) * afs_getRights * This function is just an interface to afs_GetAccessBits */ -int afs_getRights(OSI_VC_ARG(avc), arights, acred) - OSI_VC_DECL(avc); - register afs_int32 arights; - struct AFS_UCRED *acred; +int +afs_getRights(OSI_VC_DECL(avc), register afs_int32 arights, + struct AFS_UCRED *acred) { register afs_int32 code; struct vrequest treq; OSI_VC_CONVERT(avc) - if (code = afs_InitReq(&treq, acred)) return code; + if (code = afs_InitReq(&treq, acred)) + return code; code = afs_VerifyVCache(avc, &treq); if (code) { - code = afs_CheckCode(code, &treq, 16); - return code; + code = afs_CheckCode(code, &treq, 16); + return code; } return afs_GetAccessBits(avc, arights, &treq); diff --git a/src/afs/VNOPS/afs_vnop_attrs.c b/src/afs/VNOPS/afs_vnop_attrs.c index f6c00f2b1..682c1d565 100644 --- a/src/afs/VNOPS/afs_vnop_attrs.c +++ b/src/afs/VNOPS/afs_vnop_attrs.c @@ -21,16 +21,17 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_attrs.c,v 1.1.1.13 2004/01/10 20:52:57 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_attrs.c,v 1.27 2003/10/24 06:26:04 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern afs_rwlock_t afs_xcbhash; struct afs_exporter *afs_nfsexporter; @@ -40,38 +41,37 @@ extern struct vfs *afs_globalVFS; #endif /* copy out attributes from cache entry */ -afs_CopyOutAttrs(avc, attrs) - register struct vattr *attrs; - register struct vcache *avc; +int +afs_CopyOutAttrs(register struct vcache *avc, register struct vattr *attrs) { register struct volume *tvp; register struct cell *tcell; - register afs_int32 i; int fakedir = 0; AFS_STATCNT(afs_CopyOutAttrs); if (afs_fakestat_enable && avc->mvstat == 1) fakedir = 1; #if defined(AFS_MACH_ENV ) - attrs->va_mode = fakedir ? VDIR | 0755 : vType(avc) | (avc->m.Mode&~VFMT); + attrs->va_mode = + fakedir ? VDIR | 0755 : vType(avc) | (avc->m.Mode & ~VFMT); #else /* AFS_MACH_ENV */ attrs->va_type = fakedir ? VDIR : vType(avc); #if defined(AFS_SGI_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) - attrs->va_mode = fakedir ? 0755 : (mode_t)(avc->m.Mode & 0xffff); + attrs->va_mode = fakedir ? 0755 : (mode_t) (avc->m.Mode & 0xffff); #else attrs->va_mode = fakedir ? VDIR | 0755 : avc->m.Mode; #endif #endif /* AFS_MACH_ENV */ - if (avc->m.Mode & (VSUID|VSGID)) { + if (avc->m.Mode & (VSUID | VSGID)) { /* setuid or setgid, make sure we're allowed to run them from this cell */ tcell = afs_GetCell(avc->fid.Cell, 0); if (tcell && (tcell->states & CNoSUID)) - attrs->va_mode &= ~(VSUID|VSGID); + attrs->va_mode &= ~(VSUID | VSGID); } #if defined(AFS_DARWIN_ENV) { - extern u_int32_t afs_darwin_realmodes; + extern u_int32_t afs_darwin_realmodes; if (!afs_darwin_realmodes) { /* Mac OS X uses the mode bits to determine whether a file or * directory is accessible, and believes them, even though under @@ -80,20 +80,20 @@ afs_CopyOutAttrs(avc, attrs) * conservatively. */ if (S_ISDIR(attrs->va_mode)) { - /* all access bits need to be set for directories, since even - * a mode 0 directory can still be used normally. - */ - attrs->va_mode |= ACCESSPERMS; + /* all access bits need to be set for directories, since even + * a mode 0 directory can still be used normally. + */ + attrs->va_mode |= ACCESSPERMS; } else { - /* for other files, replicate the user bits to group and other */ - mode_t ubits = (attrs->va_mode & S_IRWXU) >> 6; - attrs->va_mode |= ubits | (ubits << 3); + /* for other files, replicate the user bits to group and other */ + mode_t ubits = (attrs->va_mode & S_IRWXU) >> 6; + attrs->va_mode |= ubits | (ubits << 3); } } } #endif /* AFS_DARWIN_ENV */ attrs->va_uid = fakedir ? 0 : avc->m.Owner; - attrs->va_gid = fakedir ? 0 : avc->m.Group; /* yeah! */ + attrs->va_gid = fakedir ? 0 : avc->m.Group; /* yeah! */ #if defined(AFS_SUN56_ENV) attrs->va_fsid = avc->v.v_vfsp->vfs_fsid.val[0]; #else @@ -102,7 +102,7 @@ afs_CopyOutAttrs(avc, attrs) attrs->va_fsid = 1; #else #ifdef AFS_OSF_ENV - attrs->va_fsid = avc->v.v_mount->m_stat.f_fsid.val[0]; + attrs->va_fsid = avc->v.v_mount->m_stat.f_fsid.val[0]; #else #ifdef AFS_DARWIN70_ENV attrs->va_fsid = avc->v.v_mount->mnt_stat.f_fsid.val[0]; @@ -115,16 +115,16 @@ afs_CopyOutAttrs(avc, attrs) if (avc->mvstat == 2) { tvp = afs_GetVolume(&avc->fid, 0, READ_LOCK); /* The mount point's vnode. */ - if (tvp) { + if (tvp) { attrs->va_nodeid = tvp->mtpoint.Fid.Vnode + (tvp->mtpoint.Fid.Volume << 16); if (FidCmp(&afs_rootFid, &avc->fid) && !attrs->va_nodeid) attrs->va_nodeid = 2; afs_PutVolume(tvp, READ_LOCK); - } - else attrs->va_nodeid = 2; - } - else attrs->va_nodeid = avc->fid.Fid.Vnode + (avc->fid.Fid.Volume << 16); + } else + attrs->va_nodeid = 2; + } else + attrs->va_nodeid = avc->fid.Fid.Vnode + (avc->fid.Fid.Volume << 16); attrs->va_nodeid &= 0x7fffffff; /* Saber C hates negative inode #s! */ attrs->va_nlink = fakedir ? 100 : avc->m.LinkCount; attrs->va_size = fakedir ? 4096 : avc->m.Length; @@ -139,29 +139,26 @@ afs_CopyOutAttrs(avc, attrs) */ #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) /* nfs on these systems puts an 0 in nsec and stores the nfs usec (aka - dataversion) in va_gen */ + * dataversion) in va_gen */ attrs->va_atime.tv_nsec = attrs->va_mtime.tv_nsec = - attrs->va_ctime.tv_nsec =0; - attrs->va_blocksize = PAGESIZE; /* XXX Was 8192 XXX */ + attrs->va_ctime.tv_nsec = 0; attrs->va_gen = hgetlo(avc->m.DataVersion); - attrs->va_flags = 0; -#else -#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) +#elif defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_OBSD_ENV) attrs->va_atime.tv_nsec = attrs->va_mtime.tv_nsec = attrs->va_ctime.tv_nsec = - (hgetlo(avc->m.DataVersion) & 0x7ffff) * 1000; -#if defined(AFS_AIX41_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - attrs->va_blocksize = PAGESIZE; /* XXX Was 8192 XXX */ -#else - attrs->va_blksize = PAGESIZE; /* XXX Was 8192 XXX */ -#endif + (hgetlo(avc->m.DataVersion) & 0x7ffff) * 1000; #else attrs->va_atime.tv_usec = attrs->va_mtime.tv_usec = - attrs->va_ctime.tv_usec = - (hgetlo(avc->m.DataVersion) & 0x7ffff); - attrs->va_blocksize = PAGESIZE; /* XXX Was 8192 XXX */ + attrs->va_ctime.tv_usec = (hgetlo(avc->m.DataVersion) & 0x7ffff); +#endif +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_OSF_ENV) + attrs->va_flags = 0; #endif +#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) + attrs->va_blksize = PAGESIZE; /* XXX Was 8192 XXX */ +#else + attrs->va_blocksize = PAGESIZE; /* XXX Was 8192 XXX */ #endif #ifdef AFS_DEC_ENV /* Have to use real device #s in Ultrix, since that's how FS type is @@ -172,51 +169,59 @@ afs_CopyOutAttrs(avc, attrs) attrs->va_rdev = ((struct mount *)(afs_globalVFS->vfs_data))->m_dev; else attrs->va_rdev = 1; /* better than nothing */ -#else +#else attrs->va_rdev = 1; #endif - #if defined(AFS_HPUX110_ENV) - if (afs_globalVFS) attrs->va_fstype = afs_globalVFS->vfs_mtype; + if (afs_globalVFS) + attrs->va_fstype = afs_globalVFS->vfs_mtype; #endif /* * Below return 0 (and not 1) blocks if the file is zero length. This conforms - * better with the other filesystems that do return 0. + * better with the other filesystems that do return 0. */ -#if defined(AFS_OSF_ENV) -#ifdef va_size_rsv - attrs->va_size_rsv = 0; -#endif -/* XXX do this */ -/* attrs->va_gen = avc->m.DataVersion;*/ - attrs->va_flags = 0; -#endif /* AFS_OSF_ENV */ - -#if !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) #if !defined(AFS_HPUX_ENV) #ifdef AFS_SUN5_ENV - attrs->va_nblocks = (attrs->va_size? ((attrs->va_size + 1023)>>10) << 1 : 0); -#else -#if defined(AFS_SGI_ENV) + attrs->va_nblocks = + (attrs->va_size ? ((attrs->va_size + 1023) >> 10) << 1 : 0); +#elif defined(AFS_SGI_ENV) attrs->va_blocks = BTOBB(attrs->va_size); #else - attrs->va_blocks = (attrs->va_size? ((attrs->va_size + 1023)>>10) << 1 : 0); -#endif + attrs->va_blocks = + (attrs->va_size ? ((attrs->va_size + 1023) >> 10) << 1 : 0); #endif #else /* !defined(AFS_HPUX_ENV) */ - attrs->va_blocks = (attrs->va_size? ((attrs->va_size + 1023)>>10) : 0); + attrs->va_blocks = (attrs->va_size ? ((attrs->va_size + 1023) >> 10) : 0); #endif /* !defined(AFS_HPUX_ENV) */ -#else /* ! AFS_OSF_ENV && !AFS_FBSD_ENV */ - attrs->va_bytes = (attrs->va_size? (attrs->va_size + 1023) : 1024); +#else /* ! AFS_OSF_ENV && !AFS_DARWIN_ENV && !AFS_XBSD_ENV */ + attrs->va_bytes = (attrs->va_size ? (attrs->va_size + 1023) : 1024); #ifdef va_bytes_rsv attrs->va_bytes_rsv = -1; #endif -#endif /* ! AFS_OSF_ENV */ +#endif /* ! AFS_OSF_ENV && !AFS_DARWIN_ENV && !AFS_XBSD_ENV */ #ifdef AFS_LINUX22_ENV - /* And linux has it's own stash as well. */ + /* And linux has its own stash as well. */ vattr2inode(AFSTOV(avc), attrs); +#endif +#ifdef notdef +#ifdef AFS_AIX51_ENV + afs_Trace2(afs_iclSetp, CM_TRACE_STATACLX, ICL_TYPE_POINTER, + attrs->va_acl, ICL_TYPE_INT32, attrs->va_aclsiz); + if (attrs->va_acl && attrs->va_aclsiz >= 12) { + struct acl *ap; + + ap = (struct acl *)attrs->va_acl; + ap->acl_len = 8; + ap->acl_mode = ACL_MODE; + ap->acl_rsvd = 0; + ap->u_access = 7; + } + /* temporary fix ? */ + attrs->va_aclsiz = 1; +#endif #endif return 0; } @@ -224,14 +229,13 @@ afs_CopyOutAttrs(avc, attrs) #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) -afs_getattr(OSI_VC_ARG(avc), attrs, flags, acred) - int flags; +int +afs_getattr(OSI_VC_DECL(avc), struct vattr *attrs, int flags, + struct AFS_UCRED *acred) #else -afs_getattr(OSI_VC_ARG(avc), attrs, acred) +int +afs_getattr(OSI_VC_DECL(avc), struct vattr *attrs, struct AFS_UCRED *acred) #endif - OSI_VC_DECL(avc); - struct vattr *attrs; - struct AFS_UCRED *acred; { afs_int32 code; struct vrequest treq; @@ -240,15 +244,16 @@ afs_getattr(OSI_VC_ARG(avc), attrs, acred) int inited = 0; OSI_VC_CONVERT(avc) - AFS_STATCNT(afs_getattr); - afs_Trace2(afs_iclSetp, CM_TRACE_GETATTR, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length); + AFS_STATCNT(afs_getattr); + afs_Trace2(afs_iclSetp, CM_TRACE_GETATTR, ICL_TYPE_POINTER, avc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length)); if (afs_fakestat_enable && avc->mvstat == 1) { struct afs_fakestat_state fakestat; code = afs_InitReq(&treq, acred); - if (code) return code; + if (code) + return code; afs_InitFakeStat(&fakestat); code = afs_TryEvalFakeStat(&avc, &fakestat, &treq); if (code) { @@ -260,17 +265,16 @@ afs_getattr(OSI_VC_ARG(avc), attrs, acred) afs_PutFakeStat(&fakestat); return code; } - #if defined(AFS_SUN5_ENV) if (flags & ATTR_HINT) { - code = afs_CopyOutAttrs(avc, attrs); - return code; + code = afs_CopyOutAttrs(avc, attrs); + return code; } #endif #if defined(AFS_DARWIN_ENV) if (avc->states & CUBCinit) { - code = afs_CopyOutAttrs(avc, attrs); - return code; + code = afs_CopyOutAttrs(avc, attrs); + return code; } #endif @@ -278,104 +282,107 @@ afs_getattr(OSI_VC_ARG(avc), attrs, acred) afs_BozonLock(&avc->pvnLock, avc); #endif - if (afs_shuttingdown) return EIO; + if (afs_shuttingdown) + return EIO; if (!(avc->states & CStatd)) { - if (!(code = afs_InitReq(&treq, acred))) { - code = afs_VerifyVCache2(avc, &treq); - inited = 1; - } - } - else code = 0; + if (!(code = afs_InitReq(&treq, acred))) { + code = afs_VerifyVCache2(avc, &treq); + inited = 1; + } + } else + code = 0; #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) - if (code == 0) osi_FlushPages(avc, acred); + if (code == 0) + osi_FlushPages(avc, acred); afs_BozonUnlock(&avc->pvnLock, avc); #endif if (code == 0) { - osi_FlushText(avc); /* only needed to flush text if text locked last time */ + osi_FlushText(avc); /* only needed to flush text if text locked last time */ code = afs_CopyOutAttrs(avc, attrs); if (afs_nfsexporter) { - if (!inited) { - if (code = afs_InitReq(&treq, acred)) - return code; - inited = 1; - } - if (AFS_NFSXLATORREQ(acred)) { - if ((vType(avc) != VDIR) && - !afs_AccessOK(avc, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) { - return EACCES; - } - if (avc->mvstat == 2) { -#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - attrs->va_mtime.tv_nsec += ((++avc->xlatordv) * 1000); + if (!inited) { + if ((code = afs_InitReq(&treq, acred))) + return code; + inited = 1; + } + if (AFS_NFSXLATORREQ(acred)) { + if ((vType(avc) != VDIR) + && !afs_AccessOK(avc, PRSFS_READ, &treq, + CHECK_MODE_BITS | + CMB_ALLOW_EXEC_AS_READ)) { + return EACCES; + } + if (avc->mvstat == 2) { +#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + attrs->va_mtime.tv_nsec += ((++avc->xlatordv) * 1000); #else - attrs->va_mtime.tv_usec += ++avc->xlatordv; -#endif - } - } - if (au = afs_FindUser(treq.uid, -1, READ_LOCK)) { - register struct afs_exporter *exporter = au->exporter; - - if (exporter && !(afs_nfsexporter->exp_states & EXP_UNIXMODE)) { - unsigned int ubits; - /* - * If the remote user wishes to enforce default Unix mode semantics, - * like in the nfs exporter case, we OR in the user bits - * into the group and other bits. We need to do this - * because there is no RFS_ACCESS call and thus nfs - * clients implement nfs_access by interpreting the - * mode bits in the traditional way, which of course - * loses with afs. - */ - ubits = (attrs->va_mode & 0700) >> 6; - attrs->va_mode = attrs->va_mode | ubits | (ubits << 3); - /* If it's the root of AFS, replace the inode number with the - * inode number of the mounted on directory; otherwise this - * confuses getwd()... */ -#ifdef AFS_LINUX22_ENV - if (avc == afs_globalVp) { - struct inode *ip = avc->v.i_sb->s_root->d_inode; - attrs->va_nodeid = ip->i_ino; + attrs->va_mtime.tv_usec += ++avc->xlatordv; +#endif } + } + if ((au = afs_FindUser(treq.uid, -1, READ_LOCK))) { + register struct afs_exporter *exporter = au->exporter; + + if (exporter && !(afs_nfsexporter->exp_states & EXP_UNIXMODE)) { + unsigned int ubits; + /* + * If the remote user wishes to enforce default Unix mode semantics, + * like in the nfs exporter case, we OR in the user bits + * into the group and other bits. We need to do this + * because there is no RFS_ACCESS call and thus nfs + * clients implement nfs_access by interpreting the + * mode bits in the traditional way, which of course + * loses with afs. + */ + ubits = (attrs->va_mode & 0700) >> 6; + attrs->va_mode = attrs->va_mode | ubits | (ubits << 3); + /* If it's the root of AFS, replace the inode number with the + * inode number of the mounted on directory; otherwise this + * confuses getwd()... */ +#ifdef AFS_LINUX22_ENV + if (avc == afs_globalVp) { + struct inode *ip = avc->v.i_sb->s_root->d_inode; + attrs->va_nodeid = ip->i_ino; + } #else - if (AFSTOV(avc)->v_flag & VROOT) { - struct vnode *vp = AFSTOV(avc); + if (AFSTOV(avc)->v_flag & VROOT) { + struct vnode *vp = AFSTOV(avc); - vp = vp->v_vfsp->vfs_vnodecovered; - if (vp) { /* Ignore weird failures */ + vp = vp->v_vfsp->vfs_vnodecovered; + if (vp) { /* Ignore weird failures */ #ifdef AFS_SGI62_ENV - attrs->va_nodeid = VnodeToIno(vp); + attrs->va_nodeid = VnodeToIno(vp); #else - struct inode *ip; - - ip = (struct inode *) VTOI(vp); - if (ip) /* Ignore weird failures */ - attrs->va_nodeid = ip->i_number; + struct inode *ip; + + ip = (struct inode *)VTOI(vp); + if (ip) /* Ignore weird failures */ + attrs->va_nodeid = ip->i_number; #endif + } } - } #endif /* AFS_LINUX22_ENV */ - } - afs_PutUser(au, READ_LOCK); - } + } + afs_PutUser(au, READ_LOCK); + } } } if (!code) - return 0; + return 0; code = afs_CheckCode(code, &treq, 14); return code; } /* convert a Unix request into a status store request */ -afs_VAttrToAS(avc, av, as) -register struct vcache *avc; -register struct vattr *av; -register struct AFSStoreStatus *as; { +int +afs_VAttrToAS(register struct vcache *avc, register struct vattr *av, + register struct AFSStoreStatus *as) +{ register int mask; mask = 0; AFS_STATCNT(afs_VAttrToAS); @@ -392,12 +399,11 @@ register struct AFSStoreStatus *as; { mask |= AFS_SETMODE; as->UnixModeBits = av->va_mode & 0xffff; if (avc->states & CForeign) { - ObtainWriteLock(&avc->lock,127); + ObtainWriteLock(&avc->lock, 127); afs_FreeAllAxs(&(avc->Access)); ReleaseWriteLock(&avc->lock); } } - #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX22_ENV) if (av->va_mask & AT_GID) { #else @@ -414,7 +420,6 @@ register struct AFSStoreStatus *as; { mask |= AFS_SETGROUP; as->Group = av->va_gid; } - #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX22_ENV) if (av->va_mask & AT_UID) { #else @@ -438,7 +443,7 @@ register struct AFSStoreStatus *as; { #endif mask |= AFS_SETMODTIME; #ifndef AFS_SGI_ENV -#if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) if (av->va_mtime.tv_nsec == -1) #else if (av->va_mtime.tv_usec == -1) @@ -455,33 +460,44 @@ register struct AFSStoreStatus *as; { /* We don't set CDirty bit in avc->states because setattr calls WriteVCache * synchronously, therefore, it's not needed. */ -#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) -afs_setattr(OSI_VC_ARG(avc), attrs, flags, acred) - int flags; +#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) +int +afs_setattr(OSI_VC_DECL(avc), register struct vattr *attrs, int flags, + struct AFS_UCRED *acred) #else -afs_setattr(avc, attrs, acred) +int +afs_setattr(OSI_VC_DECL(avc), register struct vattr *attrs, + struct AFS_UCRED *acred) #endif - OSI_VC_DECL(avc); - register struct vattr *attrs; - struct AFS_UCRED *acred; { +{ struct vrequest treq; struct AFSStoreStatus astat; register afs_int32 code; struct afs_fakestat_state fakestate; OSI_VC_CONVERT(avc) - AFS_STATCNT(afs_setattr); - afs_Trace2(afs_iclSetp, CM_TRACE_SETATTR, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length); - if (code = afs_InitReq(&treq, acred)) return code; + AFS_STATCNT(afs_setattr); +#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX22_ENV) + afs_Trace4(afs_iclSetp, CM_TRACE_SETATTR, ICL_TYPE_POINTER, avc, + ICL_TYPE_INT32, attrs->va_mask, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(attrs->va_size), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length)); +#else + afs_Trace4(afs_iclSetp, CM_TRACE_SETATTR, ICL_TYPE_POINTER, avc, + ICL_TYPE_INT32, attrs->va_mode, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(attrs->va_size), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length)); +#endif + if ((code = afs_InitReq(&treq, acred))) + return code; afs_InitFakeStat(&fakestate); code = afs_EvalFakeStat(&avc, &fakestate, &treq); if (code) - goto done; + goto done; if (avc->states & CRO) { - code=EROFS; + code = EROFS; goto done; } #if defined(AFS_SGI_ENV) @@ -533,20 +549,21 @@ afs_setattr(avc, attrs, acred) #endif #if defined(AFS_SGI_ENV) - AFS_RWLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWLOCK((vnode_t *) avc, VRWLOCK_WRITE); #endif #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX22_ENV) if (attrs->va_mask & AT_SIZE) { #else #if defined(AFS_OSF_ENV) if (attrs->va_size != VNOVAL) { -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ if (attrs->va_size != -1) { #endif #endif - ObtainWriteLock(&avc->lock,128); + afs_size_t tsize = attrs->va_size; + ObtainWriteLock(&avc->lock, 128); avc->states |= CDirty; - code = afs_TruncateAllSegments(avc, (afs_int32)attrs->va_size, &treq, acred); + code = afs_TruncateAllSegments(avc, tsize, &treq, acred); /* if date not explicitly set by this call, set it ourselves, since we * changed the data */ if (!(astat.Mask & AFS_SETMODTIME)) { @@ -554,14 +571,14 @@ afs_setattr(avc, attrs, acred) astat.ClientModTime = osi_Time(); } if (code == 0) { - if ( ( (avc->execsOrWriters <= 0 ) && (avc->states & CCreating) == 0) - || ( avc->execsOrWriters == 1 && AFS_NFSXLATORREQ(acred)) ) { - code = afs_StoreAllSegments(avc, &treq, AFS_ASYNC); - if (!code) - avc->states &= ~CDirty; - } + if (((avc->execsOrWriters <= 0) && (avc->states & CCreating) == 0) + || (avc->execsOrWriters == 1 && AFS_NFSXLATORREQ(acred))) { + code = afs_StoreAllSegments(avc, &treq, AFS_ASYNC); + if (!code) + avc->states &= ~CDirty; + } } else - avc->states &= ~CDirty; + avc->states &= ~CDirty; ReleaseWriteLock(&avc->lock); hzero(avc->flushDV); @@ -572,20 +589,19 @@ afs_setattr(avc, attrs, acred) #endif } if (code == 0) { - ObtainSharedLock(&avc->lock,16); /* lock entry */ - code = afs_WriteVCache(avc, &astat, &treq); /* send request */ + ObtainSharedLock(&avc->lock, 16); /* lock entry */ + code = afs_WriteVCache(avc, &astat, &treq); /* send request */ ReleaseSharedLock(&avc->lock); /* release lock */ } if (code) { - ObtainWriteLock(&afs_xcbhash, 487); - afs_DequeueCallback(avc); - avc->states &= ~CStatd; - ReleaseWriteLock(&afs_xcbhash); - if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR)) - osi_dnlc_purgedp(avc); - /* error? erase any changes we made to vcache entry */ - } - + ObtainWriteLock(&afs_xcbhash, 487); + afs_DequeueCallback(avc); + avc->states &= ~CStatd; + ReleaseWriteLock(&afs_xcbhash); + if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR)) + osi_dnlc_purgedp(avc); + /* error? erase any changes we made to vcache entry */ + } #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) if (AFS_NFSXLATORREQ(acred)) { avc->execsOrWriters--; @@ -595,9 +611,9 @@ afs_setattr(avc, attrs, acred) afs_BozonUnlock(&avc->pvnLock, avc); #endif #if defined(AFS_SGI_ENV) - AFS_RWUNLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE); #endif -done: + done: afs_PutFakeStat(&fakestate); code = afs_CheckCode(code, &treq, 15); return code; diff --git a/src/afs/VNOPS/afs_vnop_create.c b/src/afs/VNOPS/afs_vnop_create.c index 9bd9c7b5d..f3f0334c6 100644 --- a/src/afs/VNOPS/afs_vnop_create.c +++ b/src/afs/VNOPS/afs_vnop_create.c @@ -14,49 +14,47 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_create.c,v 1.1.1.9 2002/12/11 02:36:23 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_create.c,v 1.16 2003/07/15 23:14:30 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" - -extern afs_rwlock_t afs_xvcache; -extern afs_rwlock_t afs_xcbhash; +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" /* question: does afs_create need to set CDirty in the adp or the avc? * I think we can get away without it, but I'm not sure. Note that * afs_setattr is called in here for truncation. */ #ifdef AFS_OSF_ENV -afs_create(ndp, attrs) - struct nameidata *ndp; - struct vattr *attrs; { +int +afs_create(struct nameidata *ndp, struct vattr *attrs) +#else /* AFS_OSF_ENV */ +#ifdef AFS_SGI64_ENV +int +afs_create(OSI_VC_DECL(adp), char *aname, struct vattr *attrs, int flags, + int amode, struct vcache **avcp, struct AFS_UCRED *acred) +#else /* AFS_SGI64_ENV */ +int +afs_create(OSI_VC_DECL(adp), char *aname, struct vattr *attrs, + enum vcexcl aexcl, int amode, struct vcache **avcp, + struct AFS_UCRED *acred) +#endif /* AFS_SGI64_ENV */ +#endif /* AFS_OSF_ENV */ +{ +#ifdef AFS_OSF_ENV register struct vcache *adp = VTOAFS(ndp->ni_dvp); char *aname = ndp->ni_dent.d_name; - enum vcexcl aexcl = NONEXCL; /* XXX - create called properly */ - int amode = 0; /* XXX - checked in higher level */ + enum vcexcl aexcl = NONEXCL; /* XXX - create called properly */ + int amode = 0; /* XXX - checked in higher level */ struct vcache **avcp = (struct vcache **)&(ndp->ni_vp); struct ucred *acred = ndp->ni_cred; -#else /* AFS_OSF_ENV */ -#ifdef AFS_SGI64_ENV -afs_create(OSI_VC_ARG(adp), aname, attrs, flags, amode, avcp, acred) - int flags; -#else /* AFS_SGI64_ENV */ -afs_create(OSI_VC_ARG(adp), aname, attrs, aexcl, amode, avcp, acred) - enum vcexcl aexcl; -#endif /* AFS_SGI64_ENV */ - OSI_VC_DECL(adp); - char *aname; - struct vattr *attrs; - int amode; - struct vcache **avcp; - struct AFS_UCRED *acred; { -#endif /* AFS_OSF_ENV */ +#endif + afs_int32 origCBs, origZaps, finalZaps; struct vrequest treq; register afs_int32 code; @@ -68,17 +66,16 @@ afs_create(OSI_VC_ARG(adp), aname, attrs, aexcl, amode, avcp, acred) struct AFSCallBack CallBack; afs_int32 now; struct dcache *tdc; - afs_int32 offset, len; - struct server *hostp=0; + afs_size_t offset, len; + struct server *hostp = 0; struct vcache *tvc; - struct volume* volp = 0; + struct volume *volp = 0; struct afs_fakestat_state fakestate; - XSTATS_DECLS - OSI_VC_CONVERT(adp) + XSTATS_DECLS OSI_VC_CONVERT(adp) - AFS_STATCNT(afs_create); - if (code = afs_InitReq(&treq, acred)) + AFS_STATCNT(afs_create); + if ((code = afs_InitReq(&treq, acred))) goto done2; afs_Trace3(afs_iclSetp, CM_TRACE_CREATE, ICL_TYPE_POINTER, adp, @@ -114,27 +111,31 @@ afs_create(OSI_VC_ARG(adp), aname, attrs, aexcl, amode, avcp, acred) #endif case VFIFO: /* We don't support special devices or FIFOs */ - code = EINVAL; + code = EINVAL; goto done; default: ; } code = afs_EvalFakeStat(&adp, &fakestate, &treq); - if (code) goto done; -tagain: + if (code) + goto done; + tagain: code = afs_VerifyVCache(adp, &treq); - if (code) goto done; + if (code) + goto done; /** If the volume is read-only, return error without making an RPC to the * fileserver */ - if ( adp->states & CRO ) { - code = EROFS; + if (adp->states & CRO) { + code = EROFS; goto done; } - tdc = afs_GetDCache(adp, 0, &treq, &offset, &len, 1); - ObtainWriteLock(&adp->lock,135); + tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); + ObtainWriteLock(&adp->lock, 135); + if (tdc) + ObtainSharedLock(&tdc->lock, 630); /* * Make sure that the data in the cache is current. We may have @@ -143,15 +144,18 @@ tagain: if (!(adp->states & CStatd) || (tdc && !hsame(adp->m.DataVersion, tdc->f.versionNo))) { ReleaseWriteLock(&adp->lock); - if (tdc) + if (tdc) { + ReleaseSharedLock(&tdc->lock); afs_PutDCache(tdc); + } goto tagain; } if (tdc) { /* see if file already exists. If it does, we only set * the size attributes (to handle O_TRUNC) */ - code = afs_dir_Lookup(&tdc->f.inode, aname, &newFid.Fid); /* use dnlc first xxx */ + code = afs_dir_Lookup(&tdc->f.inode, aname, &newFid.Fid); /* use dnlc first xxx */ if (code == 0) { + ReleaseSharedLock(&tdc->lock); afs_PutDCache(tdc); ReleaseWriteLock(&adp->lock); #ifdef AFS_SGI64_ENV @@ -159,20 +163,18 @@ tagain: #else if (aexcl != NONEXCL) { #endif - code = EEXIST; /* file exists in excl mode open */ + code = EEXIST; /* file exists in excl mode open */ goto done; } /* found the file, so use it */ newFid.Cell = adp->fid.Cell; newFid.Fid.Volume = adp->fid.Fid.Volume; - tvc = (struct vcache *)0; + tvc = NULL; if (newFid.Fid.Unique == 0) { - tvc = afs_LookupVCache(&newFid, &treq, (afs_int32 *)0, - WRITE_LOCK, adp, aname); + tvc = afs_LookupVCache(&newFid, &treq, NULL, adp, aname); } - if (!tvc) /* lookup failed or wasn't called */ - tvc = afs_GetVCache(&newFid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + if (!tvc) /* lookup failed or wasn't called */ + tvc = afs_GetVCache(&newFid, &treq, NULL, NULL); if (tvc) { /* if the thing exists, we need the right access to open it. @@ -183,38 +185,38 @@ tagain: * We used to check always for READ access before; the * problem is that we will fail if the existing file * has mode -w-w-w, which is wrong. - */ - if ((amode & VREAD) && - !afs_AccessOK(tvc, PRSFS_READ, &treq, CHECK_MODE_BITS)) { - afs_PutVCache(tvc, READ_LOCK); - code = EACCES; - goto done; + */ + if ((amode & VREAD) + && !afs_AccessOK(tvc, PRSFS_READ, &treq, CHECK_MODE_BITS)) { + afs_PutVCache(tvc); + code = EACCES; + goto done; } - #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - if ((amode & VWRITE) || (attrs->va_mask & AT_SIZE)) + if ((amode & VWRITE) || (attrs->va_mask & AT_SIZE)) #else - if ((amode & VWRITE) || len != 0xffffffff) + if ((amode & VWRITE) || len != 0xffffffff) #endif - { + { /* needed for write access check */ tvc->parentVnode = adp->fid.Fid.Vnode; tvc->parentUnique = adp->fid.Fid.Unique; /* need write mode for these guys */ - if (!afs_AccessOK(tvc, PRSFS_WRITE, &treq, CHECK_MODE_BITS)) { - afs_PutVCache(tvc, READ_LOCK); + if (!afs_AccessOK + (tvc, PRSFS_WRITE, &treq, CHECK_MODE_BITS)) { + afs_PutVCache(tvc); code = EACCES; goto done; } } #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - if (attrs->va_mask & AT_SIZE) + if (attrs->va_mask & AT_SIZE) #else - if (len != 0xffffffff) + if (len != 0xffffffff) #endif - { + { if (vType(tvc) != VREG) { - afs_PutVCache(tvc, READ_LOCK); + afs_PutVCache(tvc); code = EISDIR; goto done; } @@ -225,30 +227,31 @@ tagain: VATTR_NULL(attrs); #endif attrs->va_size = len; - ObtainWriteLock(&tvc->lock,136); + ObtainWriteLock(&tvc->lock, 136); tvc->states |= CCreating; ReleaseWriteLock(&tvc->lock); #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) #if defined(AFS_SGI64_ENV) - code = afs_setattr(VNODE_TO_FIRST_BHV((vnode_t*)tvc), - attrs, 0, acred); + code = + afs_setattr(VNODE_TO_FIRST_BHV((vnode_t *) tvc), + attrs, 0, acred); #else code = afs_setattr(tvc, attrs, 0, acred); #endif /* AFS_SGI64_ENV */ #else /* SUN5 || SGI */ code = afs_setattr(tvc, attrs, acred); #endif /* SUN5 || SGI */ - ObtainWriteLock(&tvc->lock,137); + ObtainWriteLock(&tvc->lock, 137); tvc->states &= ~CCreating; ReleaseWriteLock(&tvc->lock); if (code) { - afs_PutVCache(tvc, 0); + afs_PutVCache(tvc); goto done; } } *avcp = tvc; - } - else code = ENOENT; /* shouldn't get here */ + } else + code = ENOENT; /* shouldn't get here */ /* make sure vrefCount bumped only if code == 0 */ goto done; } @@ -257,84 +260,86 @@ tagain: /* if we create the file, we don't do any access checks, since * that's how O_CREAT is supposed to work */ if (adp->states & CForeign) { - origCBs = afs_allCBs; - origZaps = afs_allZaps; + origCBs = afs_allCBs; + origZaps = afs_allZaps; } else { - origCBs = afs_evenCBs; /* if changes, we don't really have a callback */ - origZaps = afs_evenZaps; /* number of even numbered vnodes discarded */ + origCBs = afs_evenCBs; /* if changes, we don't really have a callback */ + origZaps = afs_evenZaps; /* number of even numbered vnodes discarded */ } InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP; InStatus.ClientModTime = osi_Time(); - InStatus.Group = (afs_int32)acred->cr_gid; + InStatus.Group = (afs_int32) acred->cr_gid; if (AFS_NFSXLATORREQ(acred)) { /* * XXX The following is mainly used to fix a bug in the HP-UX * nfs client where they create files with mode of 0 without * doing any setattr later on to fix it. * XXX - */ + */ #if defined(AFS_AIX_ENV) if (attrs->va_mode != -1) { #else #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - if (attrs->va_mask & AT_MODE) { + if (attrs->va_mask & AT_MODE) { #else if (attrs->va_mode != ((unsigned short)-1)) { #endif #endif if (!attrs->va_mode) - attrs->va_mode = 0x1b6; /* XXX default mode: rw-rw-rw XXX */ + attrs->va_mode = 0x1b6; /* XXX default mode: rw-rw-rw XXX */ } } - InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */ + InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */ do { tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK); if (tc) { - hostp = tc->srvr->server; /* remember for callback processing */ + hostp = tc->srvr->server; /* remember for callback processing */ now = osi_Time(); XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_CREATEFILE); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_CreateFile(tc->id, (struct AFSFid *) &adp->fid.Fid, - aname, &InStatus, (struct AFSFid *) - &newFid.Fid, &OutFidStatus, - &OutDirStatus, &CallBack, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + code = + RXAFS_CreateFile(tc->id, (struct AFSFid *)&adp->fid.Fid, + aname, &InStatus, (struct AFSFid *) + &newFid.Fid, &OutFidStatus, &OutDirStatus, + &CallBack, &tsync); + RX_AFS_GLOCK(); XSTATS_END_TIME; CallBack.ExpirationTime += now; - } - else code = -1; - } while - (afs_Analyze(tc, code, &adp->fid, &treq, - AFS_STATS_FS_RPCIDX_CREATEFILE, SHARED_LOCK, (struct cell *)0)); + } else + code = -1; + } while (afs_Analyze + (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_CREATEFILE, + SHARED_LOCK, NULL)); #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) if (code == EEXIST && aexcl == NONEXCL) { /* This lookup was handled in the common vn_open code in the - vnode layer */ - if (tdc) afs_PutDCache(tdc); + * vnode layer */ + if (tdc) { + ReleaseSharedLock(&tdc->lock); + afs_PutDCache(tdc); + } ReleaseWriteLock(&adp->lock); goto done; } -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #ifdef AFS_SGI64_ENV if (code == EEXIST && !(flags & VEXCL)) { #else /* AFS_SGI64_ENV */ if (code == EEXIST && aexcl == NONEXCL) { #endif /* AFS_SGI64_ENV */ /* if we get an EEXIST in nonexcl mode, just do a lookup */ - if (tdc) afs_PutDCache(tdc); + if (tdc) { + ReleaseSharedLock(&tdc->lock); + afs_PutDCache(tdc); + } ReleaseWriteLock(&adp->lock); #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) #if defined(AFS_SGI64_ENV) - code = afs_lookup(VNODE_TO_FIRST_BHV((vnode_t*)adp), aname, avcp, - (struct pathname *)0, 0, - (struct vnode *)0, acred); + code = + afs_lookup(VNODE_TO_FIRST_BHV((vnode_t *) adp), aname, avcp, NULL, + 0, NULL, acred); #else - code = afs_lookup(adp, aname, avcp, (struct pathname *)0, 0, - (struct vnode *)0, acred); + code = afs_lookup(adp, aname, avcp, NULL, 0, NULL, acred); #endif /* AFS_SGI64_ENV */ #else /* SUN5 || SGI */ code = afs_lookup(adp, aname, avcp, acred); @@ -344,26 +349,32 @@ tagain: #endif /* AFS_OSF_ENV */ if (code) { if (code < 0) { - ObtainWriteLock(&afs_xcbhash, 488); - afs_DequeueCallback(adp); - adp->states &= ~CStatd; - ReleaseWriteLock(&afs_xcbhash); - osi_dnlc_purgedp(adp); + ObtainWriteLock(&afs_xcbhash, 488); + afs_DequeueCallback(adp); + adp->states &= ~CStatd; + ReleaseWriteLock(&afs_xcbhash); + osi_dnlc_purgedp(adp); } ReleaseWriteLock(&adp->lock); - if (tdc) afs_PutDCache(tdc); + if (tdc) { + ReleaseSharedLock(&tdc->lock); + afs_PutDCache(tdc); + } goto done; } /* otherwise, we should see if we can make the change to the dir locally */ + if (tdc) + UpgradeSToWLock(&tdc->lock, 631); if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid); if (code) { - ZapDCE(tdc); - DZap(&tdc->f.inode); + ZapDCE(tdc); + DZap(&tdc->f.inode); } } if (tdc) { + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); } newFid.Cell = adp->fid.Cell; @@ -372,39 +383,38 @@ tagain: volp = afs_FindVolume(&newFid, READ_LOCK); /* New tricky optimistic callback handling algorithm for file creation works - as follows. We create the file essentially with no locks set at all. File - server may thus handle operations from others cache managers as well as from - this very own cache manager that reference the file in question before - we managed to create the cache entry. However, if anyone else changes - any of the status information for a file, we'll see afs_evenCBs increase - (files always have even fids). If someone on this workstation manages - to do something to the file, they'll end up having to create a cache - entry for the new file. Either we'll find it once we've got the afs_xvcache - lock set, or it was also *deleted* the vnode before we got there, in which case - we will find evenZaps has changed, too. Thus, we only assume we have the right - status information if no callbacks or vnode removals have occurred to even - numbered files from the time the call started until the time that we got the xvcache - lock set. Of course, this also assumes that any call that modifies a file first - gets a write lock on the file's vnode, but if that weren't true, the whole cache manager - would fail, since no call would be able to update the local vnode status after modifying - a file on a file server. */ - ObtainWriteLock(&afs_xvcache,138); - if (adp->states & CForeign) - finalZaps = afs_allZaps; /* do this before calling newvcache */ + * as follows. We create the file essentially with no locks set at all. File + * server may thus handle operations from others cache managers as well as from + * this very own cache manager that reference the file in question before + * we managed to create the cache entry. However, if anyone else changes + * any of the status information for a file, we'll see afs_evenCBs increase + * (files always have even fids). If someone on this workstation manages + * to do something to the file, they'll end up having to create a cache + * entry for the new file. Either we'll find it once we've got the afs_xvcache + * lock set, or it was also *deleted* the vnode before we got there, in which case + * we will find evenZaps has changed, too. Thus, we only assume we have the right + * status information if no callbacks or vnode removals have occurred to even + * numbered files from the time the call started until the time that we got the xvcache + * lock set. Of course, this also assumes that any call that modifies a file first + * gets a write lock on the file's vnode, but if that weren't true, the whole cache manager + * would fail, since no call would be able to update the local vnode status after modifying + * a file on a file server. */ + ObtainWriteLock(&afs_xvcache, 138); + if (adp->states & CForeign) + finalZaps = afs_allZaps; /* do this before calling newvcache */ else - finalZaps = afs_evenZaps; /* do this before calling newvcache */ + finalZaps = afs_evenZaps; /* do this before calling newvcache */ /* don't need to call RemoveVCB, since only path leaving a callback is the - one where we pass through afs_NewVCache. Can't have queued a VCB unless - we created and freed an entry between file creation time and here, and the - freeing of the vnode will change evenZaps. Don't need to update the VLRU - queue, since the find will only succeed in the event of a create race, and - then the vcache will be at the front of the VLRU queue anyway... */ - if (!(tvc = afs_FindVCache(&newFid, 0, WRITE_LOCK, - 0, DO_STATS))) { - tvc = afs_NewVCache(&newFid, hostp, 0, WRITE_LOCK); + * one where we pass through afs_NewVCache. Can't have queued a VCB unless + * we created and freed an entry between file creation time and here, and the + * freeing of the vnode will change evenZaps. Don't need to update the VLRU + * queue, since the find will only succeed in the event of a create race, and + * then the vcache will be at the front of the VLRU queue anyway... */ + if (!(tvc = afs_FindVCache(&newFid, 0, DO_STATS))) { + tvc = afs_NewVCache(&newFid, hostp); if (tvc) { int finalCBs; - ObtainWriteLock(&tvc->lock,139); + ObtainWriteLock(&tvc->lock, 139); ObtainWriteLock(&afs_xcbhash, 489); finalCBs = afs_evenCBs; @@ -414,42 +424,40 @@ tagain: finalCBs = afs_allCBs; } if (origCBs == finalCBs && origZaps == finalZaps) { - tvc->states |= CStatd; /* we've fake entire thing, so don't stat */ + tvc->states |= CStatd; /* we've fake entire thing, so don't stat */ tvc->states &= ~CBulkFetching; tvc->cbExpires = CallBack.ExpirationTime; afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), volp); - } - else { - afs_DequeueCallback(tvc); - tvc->states &= ~(CStatd | CUnique); - tvc->callback = 0; - if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)) - osi_dnlc_purgedp(tvc); + } else { + afs_DequeueCallback(tvc); + tvc->states &= ~(CStatd | CUnique); + tvc->callback = 0; + if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)) + osi_dnlc_purgedp(tvc); } ReleaseWriteLock(&afs_xcbhash); afs_ProcessFS(tvc, &OutFidStatus, &treq); ReleaseWriteLock(&tvc->lock); *avcp = tvc; code = 0; - } - else code = ENOENT; - } - else { - /* otherwise cache entry already exists, someone else must - * have created it. Comments used to say: "don't need write - * lock to *clear* these flags" but we should do it anyway. - * Code used to clear stat bit and callback, but I don't see - * the point -- we didn't have a create race, somebody else just - * snuck into NewVCache before we got here, probably a racing - * lookup. - */ + } else + code = ENOENT; + } else { + /* otherwise cache entry already exists, someone else must + * have created it. Comments used to say: "don't need write + * lock to *clear* these flags" but we should do it anyway. + * Code used to clear stat bit and callback, but I don't see + * the point -- we didn't have a create race, somebody else just + * snuck into NewVCache before we got here, probably a racing + * lookup. + */ *avcp = tvc; code = 0; } ReleaseWriteLock(&afs_xvcache); -done: - if ( volp ) + done: + if (volp) afs_PutVolume(volp, READ_LOCK); if (code == 0) { @@ -457,7 +465,6 @@ done: /* return the new status in vattr */ afs_CopyOutAttrs(*avcp, attrs); } - #ifdef AFS_OSF_ENV if (!code && !strcmp(aname, "core")) tvc->states |= CCore1; @@ -466,10 +473,10 @@ done: afs_PutFakeStat(&fakestate); code = afs_CheckCode(code, &treq, 20); -done2: + done2: #ifdef AFS_OSF_ENV - afs_PutVCache(adp, 0); -#endif /* AFS_OSF_ENV */ + afs_PutVCache(adp); +#endif /* AFS_OSF_ENV */ return code; } @@ -482,13 +489,13 @@ done2: * data and stat cache entries. This routine returns 1 if we should * do the operation locally, and 0 otherwise. * - * This routine must be called with the stat cache entry write-locked. + * This routine must be called with the stat cache entry write-locked, + * and dcache entry write-locked. */ -afs_LocalHero(avc, adc, astat, aincr) - register struct vcache *avc; - register AFSFetchStatus *astat; - register struct dcache *adc; - register int aincr; { +int +afs_LocalHero(register struct vcache *avc, register struct dcache *adc, + register AFSFetchStatus * astat, register int aincr) +{ register afs_int32 ok; afs_hyper_t avers; @@ -496,29 +503,31 @@ afs_LocalHero(avc, adc, astat, aincr) hset64(avers, astat->dataVersionHigh, astat->DataVersion); /* this *is* the version number, no matter what */ if (adc) { - ok = (hsame(avc->m.DataVersion, adc->f.versionNo) && avc->callback + ok = (hsame(avc->m.DataVersion, adc->f.versionNo) && avc->callback && (avc->states & CStatd) && avc->cbExpires >= osi_Time()); - } - else { + } else { ok = 0; } #if defined(AFS_SGI_ENV) - osi_Assert(avc->v.v_type == VDIR); + osi_Assert(avc->v.v_type == VDIR); #endif /* The bulk status code used the length as a sequence number. */ /* Don't update the vcache entry unless the stats are current. */ if (avc->states & CStatd) { hset(avc->m.DataVersion, avers); +#ifdef AFS_64BIT_CLIENT + FillInt64(avc->m.Length, astat->Length_hi, astat->Length); +#else /* AFS_64BIT_ENV */ avc->m.Length = astat->Length; +#endif /* AFS_64BIT_ENV */ avc->m.Date = astat->ClientModTime; } if (ok) { /* we've been tracking things correctly */ - adc->flags |= DFEntryMod; + adc->dflags |= DFEntryMod; adc->f.versionNo = avers; return 1; - } - else { + } else { if (adc) { ZapDCE(adc); DZap(&adc->f.inode); diff --git a/src/afs/VNOPS/afs_vnop_dirops.c b/src/afs/VNOPS/afs_vnop_dirops.c index cb473ff47..bae4c0113 100644 --- a/src/afs/VNOPS/afs_vnop_dirops.c +++ b/src/afs/VNOPS/afs_vnop_dirops.c @@ -18,44 +18,48 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_dirops.c,v 1.1.1.6 2002/08/02 04:29:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_dirops.c,v 1.14 2003/08/29 22:00:04 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern afs_rwlock_t afs_xvcache; extern afs_rwlock_t afs_xcbhash; /* don't set CDirty in here because RPC is called synchronously */ +int #ifdef AFS_OSF_ENV afs_mkdir(ndp, attrs) - struct nameidata *ndp; - struct vattr *attrs; { + struct nameidata *ndp; + struct vattr *attrs; +{ register struct vcache *adp = VTOAFS(ndp->ni_dvp); char *aname = ndp->ni_dent.d_name; register struct vcache **avcp = (struct vcache **)&(ndp->ni_vp); struct ucred *acred = ndp->ni_cred; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ afs_mkdir(OSI_VC_ARG(adp), aname, attrs, avcp, acred) OSI_VC_DECL(adp); - register struct vcache **avcp; - char *aname; - struct vattr *attrs; - struct AFS_UCRED *acred; { + register struct vcache **avcp; + char *aname; + struct vattr *attrs; + struct AFS_UCRED *acred; +{ #endif struct vrequest treq; register afs_int32 code; register struct conn *tc; struct VenusFid newFid; register struct dcache *tdc; - afs_int32 offset, len; + afs_size_t offset, len; register struct vcache *tvc; struct AFSStoreStatus InStatus; struct AFSFetchStatus OutFidStatus, OutDirStatus; @@ -63,14 +67,13 @@ afs_mkdir(OSI_VC_ARG(adp), aname, attrs, avcp, acred) struct AFSVolSync tsync; afs_int32 now; struct afs_fakestat_state fakestate; - XSTATS_DECLS - OSI_VC_CONVERT(adp) + XSTATS_DECLS OSI_VC_CONVERT(adp) - AFS_STATCNT(afs_mkdir); + AFS_STATCNT(afs_mkdir); afs_Trace2(afs_iclSetp, CM_TRACE_MKDIR, ICL_TYPE_POINTER, adp, ICL_TYPE_STRING, aname); - if (code = afs_InitReq(&treq, acred)) + if ((code = afs_InitReq(&treq, acred))) goto done2; afs_InitFakeStat(&fakestate); @@ -84,69 +87,73 @@ afs_mkdir(OSI_VC_ARG(adp), aname, attrs, avcp, acred) goto done; } code = afs_EvalFakeStat(&adp, &fakestate, &treq); - if (code) goto done; + if (code) + goto done; code = afs_VerifyVCache(adp, &treq); - if (code) goto done; + if (code) + goto done; /** If the volume is read-only, return error without making an RPC to the * fileserver */ - if ( adp->states & CRO ) { - code = EROFS; - goto done; + if (adp->states & CRO) { + code = EROFS; + goto done; } InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP; InStatus.ClientModTime = osi_Time(); - InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */ - InStatus.Group = (afs_int32)acred->cr_gid; - tdc = afs_GetDCache(adp, 0, &treq, &offset, &len, 1); - ObtainWriteLock(&adp->lock,153); + InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */ + InStatus.Group = (afs_int32) acred->cr_gid; + tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); + ObtainWriteLock(&adp->lock, 153); do { tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_MAKEDIR); - now = osi_Time(); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_MakeDir(tc->id, (struct AFSFid *) &adp->fid.Fid, aname, - &InStatus, (struct AFSFid *) &newFid.Fid, - &OutFidStatus, &OutDirStatus, &CallBack, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_MAKEDIR); + now = osi_Time(); + RX_AFS_GUNLOCK(); + code = + RXAFS_MakeDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname, + &InStatus, (struct AFSFid *)&newFid.Fid, + &OutFidStatus, &OutDirStatus, &CallBack, + &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; CallBack.ExpirationTime += now; /* DON'T forget to Set the callback value... */ - } - else code = -1; - } while - (afs_Analyze(tc, code, &adp->fid, &treq, - AFS_STATS_FS_RPCIDX_MAKEDIR, SHARED_LOCK, (struct cell *)0)); + } else + code = -1; + } while (afs_Analyze + (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_MAKEDIR, + SHARED_LOCK, NULL)); if (code) { if (code < 0) { - ObtainWriteLock(&afs_xcbhash, 490); - afs_DequeueCallback(adp); - adp->states &= ~CStatd; - ReleaseWriteLock(&afs_xcbhash); - osi_dnlc_purgedp(adp); + ObtainWriteLock(&afs_xcbhash, 490); + afs_DequeueCallback(adp); + adp->states &= ~CStatd; + ReleaseWriteLock(&afs_xcbhash); + osi_dnlc_purgedp(adp); } ReleaseWriteLock(&adp->lock); - if (tdc) afs_PutDCache(tdc); + if (tdc) + afs_PutDCache(tdc); goto done; } /* otherwise, we should see if we can make the change to the dir locally */ + if (tdc) + ObtainWriteLock(&tdc->lock, 632); if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { - /* we can do it locally */ - code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid); - if (code) { + /* we can do it locally */ + code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid); + if (code) { ZapDCE(tdc); /* surprise error -- use invalid value */ DZap(&tdc->f.inode); } } if (tdc) { + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); } adp->m.LinkCount = OutDirStatus.LinkCount; @@ -154,59 +161,61 @@ afs_mkdir(OSI_VC_ARG(adp), aname, attrs, avcp, acred) newFid.Fid.Volume = adp->fid.Fid.Volume; ReleaseWriteLock(&adp->lock); /* now we're done with parent dir, create the real dir's cache entry */ - tvc = afs_GetVCache(&newFid, &treq, (afs_int32 *)0, (struct vcache*)0, 0); + tvc = afs_GetVCache(&newFid, &treq, NULL, NULL); if (tvc) { code = 0; *avcp = tvc; - } - else code = ENOENT; -done: + } else + code = ENOENT; + done: afs_PutFakeStat(&fakestate); code = afs_CheckCode(code, &treq, 26); -done2: + done2: #ifdef AFS_OSF_ENV AFS_RELE(ndp->ni_dvp); -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ return code; } +int #ifdef AFS_OSF_ENV afs_rmdir(ndp) - struct nameidata *ndp; { + struct nameidata *ndp; +{ register struct vcache *adp = VTOAFS(ndp->ni_dvp); char *aname = ndp->ni_dent.d_name; struct ucred *acred = ndp->ni_cred; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ /* don't set CDirty in here because RPC is called synchronously */ #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) afs_rmdir(OSI_VC_ARG(adp), aname, cdirp, acred) - struct vnode *cdirp; + struct vnode *cdirp; #else afs_rmdir(adp, aname, acred) #endif OSI_VC_DECL(adp); - char *aname; - struct AFS_UCRED *acred; { + char *aname; + struct AFS_UCRED *acred; +{ #endif struct vrequest treq; register struct dcache *tdc; - register struct vcache *tvc = (struct vcache *)0; + register struct vcache *tvc = NULL; register afs_int32 code; register struct conn *tc; - afs_int32 offset, len; + afs_size_t offset, len; struct AFSFetchStatus OutDirStatus; struct AFSVolSync tsync; struct afs_fakestat_state fakestate; - XSTATS_DECLS - OSI_VC_CONVERT(adp) + XSTATS_DECLS OSI_VC_CONVERT(adp) - AFS_STATCNT(afs_rmdir); + AFS_STATCNT(afs_rmdir); - afs_Trace2(afs_iclSetp, CM_TRACE_RMDIR, ICL_TYPE_POINTER, adp, + afs_Trace2(afs_iclSetp, CM_TRACE_RMDIR, ICL_TYPE_POINTER, adp, ICL_TYPE_STRING, aname); - if (code = afs_InitReq(&treq, acred)) + if ((code = afs_InitReq(&treq, acred))) goto done2; afs_InitFakeStat(&fakestate); @@ -218,36 +227,39 @@ afs_rmdir(adp, aname, acred) code = afs_EvalFakeStat(&adp, &fakestate, &treq); if (code) goto done; + code = afs_VerifyVCache(adp, &treq); - if (code) goto done; + if (code) + goto done; /** If the volume is read-only, return error without making an RPC to the * fileserver */ - if ( adp->states & CRO ) { - code = EROFS; - goto done; + if (adp->states & CRO) { + code = EROFS; + goto done; } - tdc = afs_GetDCache(adp, 0, &treq, &offset, &len, 1); /* test for error below */ - ObtainWriteLock(&adp->lock,154); + tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */ + ObtainWriteLock(&adp->lock, 154); + if (tdc) + ObtainSharedLock(&tdc->lock, 633); if (tdc && (adp->states & CForeign)) { struct VenusFid unlinkFid; unlinkFid.Fid.Vnode = 0; code = afs_dir_Lookup(&tdc->f.inode, aname, &unlinkFid.Fid); - if (code == 0) { - afs_int32 cached=0; + if (code == 0) { + afs_int32 cached = 0; unlinkFid.Cell = adp->fid.Cell; unlinkFid.Fid.Volume = adp->fid.Fid.Volume; if (unlinkFid.Fid.Unique == 0) { - tvc = afs_LookupVCache(&unlinkFid, &treq, &cached, - WRITE_LOCK, adp, aname); + tvc = + afs_LookupVCache(&unlinkFid, &treq, &cached, adp, aname); } else { ObtainReadLock(&afs_xvcache); - tvc = afs_FindVCache(&unlinkFid, 1, WRITE_LOCK, - 0, 1/* do xstats */); + tvc = afs_FindVCache(&unlinkFid, 0, 1 /* do xstats */ ); ReleaseReadLock(&afs_xvcache); } } @@ -256,72 +268,75 @@ afs_rmdir(adp, aname, acred) do { tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEDIR); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_RemoveDir(tc->id, (struct AFSFid *) &adp->fid.Fid, - aname, &OutDirStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &adp->fid, &treq, - AFS_STATS_FS_RPCIDX_REMOVEDIR, SHARED_LOCK, (struct cell *)0)); + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEDIR); + RX_AFS_GUNLOCK(); + code = + RXAFS_RemoveDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname, + &OutDirStatus, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_REMOVEDIR, + SHARED_LOCK, NULL)); if (code) { - if (tdc) afs_PutDCache(tdc); + if (tdc) { + ReleaseSharedLock(&tdc->lock); + afs_PutDCache(tdc); + } if (code < 0) { - ObtainWriteLock(&afs_xcbhash, 491); - afs_DequeueCallback(adp); - adp->states &= ~CStatd; - ReleaseWriteLock(&afs_xcbhash); - osi_dnlc_purgedp(adp); + ObtainWriteLock(&afs_xcbhash, 491); + afs_DequeueCallback(adp); + adp->states &= ~CStatd; + ReleaseWriteLock(&afs_xcbhash); + osi_dnlc_purgedp(adp); } ReleaseWriteLock(&adp->lock); goto done; } /* here if rpc worked; update the in-core link count */ adp->m.LinkCount = OutDirStatus.LinkCount; + if (tdc) + UpgradeSToWLock(&tdc->lock, 634); if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ code = afs_dir_Delete(&tdc->f.inode, aname); - if (code) { + if (code) { ZapDCE(tdc); /* surprise error -- invalid value */ DZap(&tdc->f.inode); } } if (tdc) { + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); /* drop ref count */ } if (tvc) { - osi_dnlc_purgedp (tvc); /* get rid of any entries for this directory */ + osi_dnlc_purgedp(tvc); /* get rid of any entries for this directory */ afs_symhint_inval(tvc); } else - osi_dnlc_remove (adp, aname, 0); + osi_dnlc_remove(adp, aname, 0); if (tvc) { - ObtainWriteLock(&tvc->lock,155); - tvc->states &= ~CUnique; /* For the dfs xlator */ + ObtainWriteLock(&tvc->lock, 155); + tvc->states &= ~CUnique; /* For the dfs xlator */ ReleaseWriteLock(&tvc->lock); - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); } ReleaseWriteLock(&adp->lock); /* don't worry about link count since dirs can not be hardlinked */ code = 0; -done: + done: afs_PutFakeStat(&fakestate); - code = afs_CheckCode(code, &treq, 27); -done2: + code = afs_CheckCode(code, &treq, 27); + done2: #ifdef AFS_OSF_ENV - afs_PutVCache(adp, 0); - afs_PutVCache(ndp->ni_vp, 0); -#endif /* AFS_OSF_ENV */ + afs_PutVCache(adp); + afs_PutVCache(ndp->ni_vp); +#endif /* AFS_OSF_ENV */ return code; } diff --git a/src/afs/VNOPS/afs_vnop_fid.c b/src/afs/VNOPS/afs_vnop_fid.c index e35af21fa..67aa15f7e 100644 --- a/src/afs/VNOPS/afs_vnop_fid.c +++ b/src/afs/VNOPS/afs_vnop_fid.c @@ -15,21 +15,22 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_fid.c,v 1.1.1.7 2002/05/10 23:44:21 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_fid.c,v 1.11 2003/07/15 23:14:30 shadow Exp $"); -#if !defined(AFS_DUX40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#if !defined(AFS_DUX40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_OBSD_ENV) +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" -int afs_fid_vnodeoverflow=0, afs_fid_uniqueoverflow=0; +int afs_fid_vnodeoverflow = 0, afs_fid_uniqueoverflow = 0; /* * afs_fid @@ -64,19 +65,21 @@ int afs_iauth_initd = 0; #endif -extern int afs_NFSRootOnly; /* 1 => only allow NFS mounts of /afs. */ +extern int afs_NFSRootOnly; /* 1 => only allow NFS mounts of /afs. */ + +int #if !defined(AFS_DEC_ENV) && !defined(AFS_ATHENA_ENV) #ifdef AFS_AIX41_ENV afs_fid(OSI_VC_ARG(avc), fidpp, credp) - struct ucred *credp ; + struct ucred *credp; #else afs_fid(OSI_VC_ARG(avc), fidpp) -#endif /* AFS_AIX41_ENV */ +#endif /* AFS_AIX41_ENV */ OSI_VC_DECL(avc); #if defined(AFS_AIX_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN54_ENV) -struct fid *fidpp; + struct fid *fidpp; #else -struct fid **fidpp; + struct fid **fidpp; #endif { struct SmallFid Sfid; @@ -87,11 +90,13 @@ struct fid **fidpp; int rootvp = 0; OSI_VC_CONVERT(avc) - AFS_STATCNT(afs_fid); + AFS_STATCNT(afs_fid); - if (afs_shuttingdown) return EIO; + if (afs_shuttingdown) + return EIO; - if (afs_NFSRootOnly && (avc == afs_globalVp)) rootvp = 1; + if (afs_NFSRootOnly && (avc == afs_globalVp)) + rootvp = 1; if (!afs_NFSRootOnly || rootvp #ifdef AFS_AIX41_ENV || USE_SMALLFID(credp) @@ -99,9 +104,9 @@ struct fid **fidpp; ) { tcell = afs_GetCell(avc->fid.Cell, READ_LOCK); Sfid.Volume = avc->fid.Fid.Volume; - Sfid.Vnode = avc->fid.Fid.Vnode; - Sfid.CellAndUnique = ((tcell->cellIndex << 24) + - (avc->fid.Fid.Unique & 0xffffff)); + Sfid.Vnode = avc->fid.Fid.Vnode; + Sfid.CellAndUnique = + ((tcell->cellIndex << 24) + (avc->fid.Fid.Unique & 0xffffff)); afs_PutCell(tcell, READ_LOCK); if (avc->fid.Fid.Vnode > 0xffff) afs_fid_vnodeoverflow++; @@ -109,7 +114,7 @@ struct fid **fidpp; afs_fid_uniqueoverflow++; } else { #if defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZPTR == 64)) - addr[1] = (long)AFS_XLATOR_MAGIC << 48 ; + addr[1] = (long)AFS_XLATOR_MAGIC << 48; #else /* defined(AFS_SGI61_ENV) && (_MIPS_SZPTR == 64) */ addr[1] = AFS_XLATOR_MAGIC; SizeOfSmallFid = sizeof(addr); @@ -127,25 +132,25 @@ struct fid **fidpp; if (afs_NFSRootOnly) { if (rootvp #ifdef AFS_AIX41_ENV - || USE_SMALLFID(credp) + || USE_SMALLFID(credp) #endif ) { - memcpy(fidpp->fid_data, (caddr_t)&Sfid, SizeOfSmallFid); + memcpy(fidpp->fid_data, (caddr_t) & Sfid, SizeOfSmallFid); } else { - memcpy(fidpp->fid_data, (caddr_t)addr, SizeOfSmallFid); + memcpy(fidpp->fid_data, (caddr_t) addr, SizeOfSmallFid); } } else { - memcpy(fidpp->fid_data, (caddr_t)&Sfid, SizeOfSmallFid); + memcpy(fidpp->fid_data, (caddr_t) & Sfid, SizeOfSmallFid); } #else /* malloc a fid pointer ourselves. */ - *fidpp = (struct fid *) AFS_KALLOC(SizeOfSmallFid+2); + *fidpp = (struct fid *)AFS_KALLOC(SizeOfSmallFid + 2); (*fidpp)->fid_len = SizeOfSmallFid; if (afs_NFSRootOnly) { if (rootvp) { memcpy((*fidpp)->fid_data, (char *)&Sfid, SizeOfSmallFid); } else { - memcpy((*fidpp)->fid_data, (char *)addr, SizeOfSmallFid); + memcpy((*fidpp)->fid_data, (char *)addr, SizeOfSmallFid); } } else { memcpy((*fidpp)->fid_data, (char *)&Sfid, SizeOfSmallFid); diff --git a/src/afs/VNOPS/afs_vnop_flock.c b/src/afs/VNOPS/afs_vnop_flock.c index 23e8685c2..ea9e0572d 100644 --- a/src/afs/VNOPS/afs_vnop_flock.c +++ b/src/afs/VNOPS/afs_vnop_flock.c @@ -13,38 +13,36 @@ */ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_flock.c,v 1.1.1.11 2002/09/26 18:58:22 hartmans Exp $"); - -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" - -#if defined(AFS_HPUX102_ENV) -#define AFS_FLOCK k_flock -#else -#if defined(AFS_SUN56_ENV) || defined(AFS_LINUX24_ENV) -#define AFS_FLOCK flock64 -#else -#define AFS_FLOCK flock -#endif /* AFS_SUN65_ENV */ -#endif /* AFS_HPUX102_ENV */ - +#include "afs/param.h" + +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_flock.c,v 1.24 2003/07/15 23:14:30 shadow Exp $"); + +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" + +/* Static prototypes */ +static int HandleGetLock(register struct vcache *avc, + register struct AFS_FLOCK *af, + register struct vrequest *areq, int clid); static int GetFlockCount(struct vcache *avc, struct vrequest *areq); - -void lockIdSet(flock, slp, clid) - int clid; /* non-zero on SGI, OSF, SunOS, Darwin, xBSD *//* XXX ptr type */ - struct SimpleLocks *slp; - struct AFS_FLOCK *flock; +static int lockIdcmp2(struct AFS_FLOCK *flock1, struct vcache *vp, + register struct SimpleLocks *alp, int onlymine, + int clid); +static void DoLockWarning(void); + +/* int clid; * non-zero on SGI, OSF, SunOS, Darwin, xBSD ** XXX ptr type */ +void +lockIdSet(struct AFS_FLOCK *flock, struct SimpleLocks *slp, int clid) { #if defined(AFS_SUN5_ENV) - register proc_t *procp = ttoproc(curthread); + register proc_t *procp = ttoproc(curthread); #else -#if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) #ifdef AFS_SGI_ENV struct proc *procp = OSI_GET_CURRENT_PROCP(); #else @@ -80,17 +78,17 @@ void lockIdSet(flock, slp, clid) #ifdef AFS_SGI65_ENV slp->sysid = flid.fl_sysid; #else - slp->sysid = OSI_GET_CURRENT_SYSID(); + slp->sysid = OSI_GET_CURRENT_SYSID(); #endif - slp->pid = clid; + slp->pid = clid; #else -#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) slp->pid = clid; #else #if defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV) slp->pid = getpid(); #else - slp->pid = u.u_procp->p_pid; + slp->pid = u.u_procp->p_pid; #endif #endif #endif /* AFS_AIX_ENV */ @@ -119,11 +117,11 @@ void lockIdSet(flock, slp, clid) #ifdef AFS_SGI65_ENV flock->l_sysid = flid.fl_sysid; #else - flock->l_sysid = OSI_GET_CURRENT_SYSID(); + flock->l_sysid = OSI_GET_CURRENT_SYSID(); #endif - flock->l_pid = clid; + flock->l_pid = clid; #else -#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) flock->l_pid = clid; #else #if defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV) @@ -135,8 +133,8 @@ void lockIdSet(flock, slp, clid) #endif #endif /* AFS_AIX_ENV */ #endif /* AFS_AIX32_ENV */ - } -} + } +} /* return 1 (true) if specified flock does not match alp (if * specified), or any of the slp structs (if alp == 0) @@ -146,19 +144,18 @@ void lockIdSet(flock, slp, clid) * to p_ppid? Especially in the context of the lower loop, where * the repeated comparison doesn't make much sense... */ -static int lockIdcmp2(flock1, vp, alp, onlymine, clid) - struct AFS_FLOCK *flock1; - struct vcache *vp; - register struct SimpleLocks *alp; - int onlymine; /* don't match any locks which are held by my */ - /* parent */ - int clid; /* Only Irix 6.5 for now. */ +/* onlymine - don't match any locks which are held by my parent */ +/* clid - only irix 6.5 */ + +static int +lockIdcmp2(struct AFS_FLOCK *flock1, struct vcache *vp, + register struct SimpleLocks *alp, int onlymine, int clid) { register struct SimpleLocks *slp; #if defined(AFS_SUN5_ENV) - register proc_t *procp = ttoproc(curthread); + register proc_t *procp = ttoproc(curthread); #else -#if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) #ifdef AFS_SGI64_ENV struct proc *procp = curprocp; #else /* AFS_SGI64_ENV */ @@ -166,42 +163,41 @@ static int lockIdcmp2(flock1, vp, alp, onlymine, clid) #endif /* AFS_SGI64_ENV */ #endif #endif - int code = 0; if (alp) { #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - if (flock1->l_sysid != alp->sysid) { - return 1; - } + if (flock1->l_sysid != alp->sysid) { + return 1; + } #endif - if ((flock1->l_pid == alp->pid) || + if ((flock1->l_pid == alp->pid) || #if defined(AFS_AIX41_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV) - (!onlymine && (flock1->l_pid == getppid())) + (!onlymine && (flock1->l_pid == getppid())) #else -#if defined(AFS_SGI65_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - /* XXX check this. used to be *only* irix for some reason. */ - (!onlymine && (flock1->l_pid == clid)) +#if defined(AFS_SGI65_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + /* XXX check this. used to be *only* irix for some reason. */ + (!onlymine && (flock1->l_pid == clid)) #else - (!onlymine && (flock1->l_pid == procp->p_ppid)) + (!onlymine && (flock1->l_pid == procp->p_ppid)) #endif #endif - ) { - return 0; - } - return 1; + ) { + return 0; + } + return 1; } for (slp = vp->slocks; slp; slp = slp->next) { -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) +#if defined(AFS_HAVE_FLOCK_SYSID) if (flock1->l_sysid != slp->sysid) { - continue; + continue; } #endif if (flock1->l_pid == slp->pid) { return 0; - } + } } - return (1); /* failure */ + return (1); /* failure */ } @@ -219,115 +215,105 @@ static int lockIdcmp2(flock1, vp, alp, onlymine, clid) file, I guess we'll permit it. however, we don't want simple, innocent closes by children to unlock files in the parent process. */ -HandleFlock(avc, acom, areq, clid, onlymine) - pid_t clid; /* non-zero on SGI, SunOS, OSF1 only */ - register struct vcache *avc; - struct vrequest *areq; - int onlymine; - int acom; { +/* clid - nonzero on sgi sunos osf1 only */ +int +HandleFlock(register struct vcache *avc, int acom, struct vrequest *areq, + pid_t clid, int onlymine) +{ struct conn *tc; struct SimpleLocks *slp, *tlp, **slpp; afs_int32 code; struct AFSVolSync tsync; afs_int32 lockType; struct AFS_FLOCK flock; - XSTATS_DECLS - - AFS_STATCNT(HandleFlock); - code = 0; /* default when we don't make any network calls */ - lockIdSet(&flock, (struct SimpleLocks *)0, clid); + XSTATS_DECLS AFS_STATCNT(HandleFlock); + code = 0; /* default when we don't make any network calls */ + lockIdSet(&flock, NULL, clid); #if defined(AFS_SGI_ENV) osi_Assert(valusema(&avc->vc_rwlock) <= 0); osi_Assert(OSI_GET_LOCKID() == avc->vc_rwlockid); #endif - ObtainWriteLock(&avc->lock,118); + ObtainWriteLock(&avc->lock, 118); if (acom & LOCK_UN) { /* defect 3083 */ #ifdef AFS_AIX_ENV /* If the lock is held exclusive, then only the owning process - * or a child can unlock it. Use pid and ppid because they are - * unique identifiers. + * or a child can unlock it. Use pid and ppid because they are + * unique identifiers. */ if ((avc->flockCount < 0) && (getpid() != avc->ownslock)) { #ifdef AFS_AIX41_ENV - if (onlymine || (getppid() != avc->ownslock)) { + if (onlymine || (getppid() != avc->ownslock)) { #else - if (onlymine || (u.u_procp->p_ppid != avc->ownslock)) { + if (onlymine || (u.u_procp->p_ppid != avc->ownslock)) { +#endif + ReleaseWriteLock(&avc->lock); + return 0; + } + } #endif + if (lockIdcmp2(&flock, avc, NULL, onlymine, clid)) { ReleaseWriteLock(&avc->lock); return 0; - } } -#endif - if (lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, onlymine, clid)) { - ReleaseWriteLock(&avc->lock); - return 0; - } #ifdef AFS_AIX_ENV - avc->ownslock = 0; -#endif - if (avc->flockCount == 0) { - ReleaseWriteLock(&avc->lock); - return 0 /*ENOTTY*/; - /* no lock held */ - } - /* unlock the lock */ + avc->ownslock = 0; +#endif + if (avc->flockCount == 0) { + ReleaseWriteLock(&avc->lock); + return 0 /*ENOTTY*/; + /* no lock held */ + } + /* unlock the lock */ if (avc->flockCount > 0) { - slpp = &avc->slocks; - for (slp = *slpp; slp;) { - if (!lockIdcmp2(&flock, avc, slp, onlymine, clid)) { - avc->flockCount--; - tlp = *slpp = slp->next; - osi_FreeSmallSpace(slp); - slp = tlp; - } else { - slpp = &slp->next; - slp = *slpp; - } - } - } - else if (avc->flockCount == -1) { - afs_StoreAllSegments(avc, areq, AFS_ASYNC); /* fsync file early */ - avc->flockCount = 0; - /* And remove the (only) exclusive lock entry from the list... */ - osi_FreeSmallSpace(avc->slocks); - avc->slocks = 0; - } - if (avc->flockCount == 0) { - do { - tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); - if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_ReleaseLock(tc->id, (struct AFSFid *) - &avc->fid.Fid, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; + slpp = &avc->slocks; + for (slp = *slpp; slp;) { + if (!lockIdcmp2(&flock, avc, slp, onlymine, clid)) { + avc->flockCount--; + tlp = *slpp = slp->next; + osi_FreeSmallSpace(slp); + slp = tlp; + } else { + slpp = &slp->next; + slp = *slpp; } - else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_RELEASELOCK, - SHARED_LOCK, (struct cell *)0)); + } + } else if (avc->flockCount == -1) { + afs_StoreAllSegments(avc, areq, AFS_ASYNC); /* fsync file early */ + avc->flockCount = 0; + /* And remove the (only) exclusive lock entry from the list... */ + osi_FreeSmallSpace(avc->slocks); + avc->slocks = 0; } - } - else { - while (1) { /* set a new lock */ + if (avc->flockCount == 0) { + do { + tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); + if (tc) { + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK); + RX_AFS_GUNLOCK(); + code = RXAFS_ReleaseLock(tc->id, (struct AFSFid *) + &avc->fid.Fid, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, + AFS_STATS_FS_RPCIDX_RELEASELOCK, SHARED_LOCK, NULL)); + } + } else { + while (1) { /* set a new lock */ /* * Upgrading from shared locks to Exclusive and vice versa - * is a bit tricky and we don't really support it yet. But - * we try to support the common used one which is upgrade - * a shared lock to an exclusive for the same process... - */ - if ((avc->flockCount > 0 && (acom & LOCK_EX)) || - (avc->flockCount == -1 && (acom & LOCK_SH))) { + * is a bit tricky and we don't really support it yet. But + * we try to support the common used one which is upgrade + * a shared lock to an exclusive for the same process... + */ + if ((avc->flockCount > 0 && (acom & LOCK_EX)) + || (avc->flockCount == -1 && (acom & LOCK_SH))) { /* * Upgrading from shared locks to an exclusive one: * For now if all the shared locks belong to the @@ -340,7 +326,8 @@ HandleFlock(avc, acom, areq, clid, onlymine) */ slpp = &avc->slocks; for (slp = *slpp; slp;) { - if (!lockIdcmp2(&flock, avc, slp, 1/*!onlymine*/, clid)) { + if (!lockIdcmp2 + (&flock, avc, slp, 1 /*!onlymine */ , clid)) { if (acom & LOCK_EX) avc->flockCount--; else @@ -354,77 +341,73 @@ HandleFlock(avc, acom, areq, clid, onlymine) slp = *slpp; } } - if (!code && avc->flockCount == 0) { + if (!code && avc->flockCount == 0) { do { tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_ReleaseLock(tc->id, - (struct AFSFid *) &avc->fid.Fid, - &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_RELEASELOCK, - SHARED_LOCK, (struct cell *)0)); + XSTATS_START_TIME + (AFS_STATS_FS_RPCIDX_RELEASELOCK); + RX_AFS_GUNLOCK(); + code = + RXAFS_ReleaseLock(tc->id, + (struct AFSFid *)&avc->fid. + Fid, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, + AFS_STATS_FS_RPCIDX_RELEASELOCK, SHARED_LOCK, + NULL)); } } else if (avc->flockCount == -1 && (acom & LOCK_EX)) { - if (lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) { + if (lockIdcmp2(&flock, avc, NULL, 1, clid)) { code = EWOULDBLOCK; } else code = 0; } if (code == 0) { /* compatible here, decide if needs to go to file server. If - we've already got the file locked (and thus read-locked, since - we've already checked for compatibility), we shouldn't send - the call through to the server again */ + * we've already got the file locked (and thus read-locked, since + * we've already checked for compatibility), we shouldn't send + * the call through to the server again */ if (avc->flockCount == 0) { /* we're the first on our block, send the call through */ - lockType = ((acom & LOCK_EX)? LockWrite : LockRead); + lockType = ((acom & LOCK_EX) ? LockWrite : LockRead); do { tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETLOCK); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_SetLock(tc->id, (struct AFSFid *) - &avc->fid.Fid, lockType, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_SETLOCK, - SHARED_LOCK, (struct cell *)0)); - } - else code = 0; /* otherwise, pretend things worked */ + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETLOCK); + RX_AFS_GUNLOCK(); + code = RXAFS_SetLock(tc->id, (struct AFSFid *) + &avc->fid.Fid, lockType, + &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, + AFS_STATS_FS_RPCIDX_SETLOCK, SHARED_LOCK, + NULL)); + } else + code = 0; /* otherwise, pretend things worked */ } if (code == 0) { - slp = (struct SimpleLocks *) osi_AllocSmallSpace(sizeof(struct SimpleLocks)); + slp = (struct SimpleLocks *) + osi_AllocSmallSpace(sizeof(struct SimpleLocks)); if (acom & LOCK_EX) { /* defect 3083 */ #ifdef AFS_AIX_ENV - /* Record unique id of process owning exclusive lock. */ - avc->ownslock = getpid(); + /* Record unique id of process owning exclusive lock. */ + avc->ownslock = getpid(); #endif slp->type = LockWrite; - slp->next = (struct SimpleLocks *)0; + slp->next = NULL; avc->slocks = slp; avc->flockCount = -1; } else { @@ -438,66 +421,64 @@ HandleFlock(avc, acom, areq, clid, onlymine) break; } /* now, if we got EWOULDBLOCK, and we're supposed to wait, we do */ - if(((code == EWOULDBLOCK)||(code == EAGAIN)) && !(acom & LOCK_NB)) { + if (((code == EWOULDBLOCK) || (code == EAGAIN)) + && !(acom & LOCK_NB)) { /* sleep for a second, allowing interrupts */ ReleaseWriteLock(&avc->lock); #if defined(AFS_SGI_ENV) - AFS_RWUNLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE); #endif - code = afs_osi_Wait(1000, (struct afs_osi_WaitHandle *) 0, 1); + code = afs_osi_Wait(1000, NULL, 1); #if defined(AFS_SGI_ENV) - AFS_RWLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWLOCK((vnode_t *) avc, VRWLOCK_WRITE); #endif - ObtainWriteLock(&avc->lock,120); + ObtainWriteLock(&avc->lock, 120); if (code) { code = EINTR; /* return this if ^C typed */ break; } - } - else break; - } /* while loop */ + } else + break; + } /* while loop */ } ReleaseWriteLock(&avc->lock); - code = afs_CheckCode(code, areq, 1); /* defeat a buggy AIX optimization */ + code = afs_CheckCode(code, areq, 1); /* defeat a buggy AIX optimization */ return code; } /* warn a user that a lock has been ignored */ -afs_int32 lastWarnTime = 0; -static void DoLockWarning() { +afs_int32 lastWarnTime = 0; /* this is used elsewhere */ +static void +DoLockWarning(void) +{ register afs_int32 now; now = osi_Time(); AFS_STATCNT(DoLockWarning); /* check if we've already warned someone recently */ - if (now < lastWarnTime + 120) return; + if (now < lastWarnTime + 120) + return; /* otherwise, it is time to nag the user */ lastWarnTime = now; - afs_warn("afs: byte-range lock/unlock ignored; make sure no one else is running this program.\n"); + afs_warn + ("afs: byte-range lock/unlock ignored; make sure no one else is running this program.\n"); } #ifdef AFS_OSF_ENV -afs_lockctl(avc, af, flag, acred, clid, offset) -struct eflock *af; -int flag; -pid_t clid; -off_t offset; -#else -#if defined(AFS_SGI_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -afs_lockctl(avc, af, acmd, acred, clid) -pid_t clid; +afs_lockctl(struct vcache * avc, struct eflock * af, int flag, + struct AFS_UCRED * acred, pid_t clid, off_t offset) +#elif defined(AFS_SGI_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) +afs_lockctl(struct vcache * avc, struct AFS_FLOCK * af, int acmd, + struct AFS_UCRED * acred, pid_t clid) #else -u_int clid=0; -afs_lockctl(avc, af, acmd, acred) +u_int clid = 0; +afs_lockctl(struct vcache * avc, struct AFS_FLOCK * af, int acmd, + struct AFS_UCRED * acred) #endif -struct AFS_FLOCK *af; -int acmd; -#endif -struct vcache *avc; -struct AFS_UCRED *acred; { +{ struct vrequest treq; afs_int32 code; #ifdef AFS_OSF_ENV @@ -506,7 +487,8 @@ struct AFS_UCRED *acred; { struct afs_fakestat_state fakestate; AFS_STATCNT(afs_lockctl); - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; afs_InitFakeStat(&fakestate); code = afs_EvalFakeStat(&avc, &fakestate, &treq); if (code) { @@ -514,7 +496,7 @@ struct AFS_UCRED *acred; { return code; } #ifdef AFS_OSF_ENV - if (flag & VNOFLCK) { + if (flag & VNOFLCK) { afs_PutFakeStat(&fakestate); return 0; } @@ -535,69 +517,69 @@ struct AFS_UCRED *acred; { afs_PutFakeStat(&fakestate); return 0; } -#ifndef AFS_OSF_ENV /* getlock is a no-op for osf (for now) */ +#ifndef AFS_OSF_ENV /* getlock is a no-op for osf (for now) */ code = HandleGetLock(avc, af, &treq, clid); #endif - code = afs_CheckCode(code, &treq, 2); /* defeat buggy AIX optimz */ + code = afs_CheckCode(code, &treq, 2); /* defeat buggy AIX optimz */ afs_PutFakeStat(&fakestate); return code; - } - else if ((acmd == F_SETLK) || (acmd == F_SETLKW) + } else if ((acmd == F_SETLK) || (acmd == F_SETLKW) #if (defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)) && !defined(AFS_SUN58_ENV) - || (acmd == F_RSETLK)|| (acmd == F_RSETLKW)) { + || (acmd == F_RSETLK) || (acmd == F_RSETLKW)) { #else ) { #endif - /* this next check is safer when left out, but more applications work - with it in. However, they fail in race conditions. The question is - what to do for people who don't have source to their application; - this way at least, they can get work done */ + /* this next check is safer when left out, but more applications work + * with it in. However, they fail in race conditions. The question is + * what to do for people who don't have source to their application; + * this way at least, they can get work done */ #ifdef AFS_LINUX24_ENV - if (af->l_len == OFFSET_MAX) - af->l_len = 0; /* since some systems indicate it as EOF */ + if (af->l_len == OFFSET_MAX) + af->l_len = 0; /* since some systems indicate it as EOF */ #else - if (af->l_len == 0x7fffffff) - af->l_len = 0; /* since some systems indicate it as EOF */ + if (af->l_len == 0x7fffffff) + af->l_len = 0; /* since some systems indicate it as EOF */ #ifdef AFS_LINUX_64BIT_KERNEL - if (af->l_len == LONG_MAX) - af->l_len = 0; /* since some systems indicate it as EOF */ + if (af->l_len == LONG_MAX) + af->l_len = 0; /* since some systems indicate it as EOF */ #endif #endif - /* next line makes byte range locks always succeed, - even when they should block */ - if (af->l_whence != 0 || af->l_start != 0 || af->l_len != 0) { - DoLockWarning(); - afs_PutFakeStat(&fakestate); - return 0; - } - /* otherwise we can turn this into a whole-file flock */ - if (af->l_type == F_RDLCK) code = LOCK_SH; - else if (af->l_type == F_WRLCK) code = LOCK_EX; - else if (af->l_type == F_UNLCK) code = LOCK_UN; - else { - afs_PutFakeStat(&fakestate); - return EINVAL; /* unknown lock type */ - } - if (((acmd == F_SETLK) + /* next line makes byte range locks always succeed, + * even when they should block */ + if (af->l_whence != 0 || af->l_start != 0 || af->l_len != 0) { + DoLockWarning(); + afs_PutFakeStat(&fakestate); + return 0; + } + /* otherwise we can turn this into a whole-file flock */ + if (af->l_type == F_RDLCK) + code = LOCK_SH; + else if (af->l_type == F_WRLCK) + code = LOCK_EX; + else if (af->l_type == F_UNLCK) + code = LOCK_UN; + else { + afs_PutFakeStat(&fakestate); + return EINVAL; /* unknown lock type */ + } + if (((acmd == F_SETLK) #if (defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV)) && !defined(AFS_SUN58_ENV) - || (acmd == F_RSETLK) + || (acmd == F_RSETLK) #endif ) && code != LOCK_UN) - code |= LOCK_NB; /* non-blocking, s.v.p. */ -#if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) - code = HandleFlock(avc, code, &treq, clid, 0/*!onlymine*/); -#else -#if defined(AFS_SGI_ENV) - AFS_RWLOCK((vnode_t *)avc, VRWLOCK_WRITE); - code = HandleFlock(avc, code, &treq, clid, 0/*!onlymine*/); - AFS_RWUNLOCK((vnode_t *)avc, VRWLOCK_WRITE); + code |= LOCK_NB; /* non-blocking, s.v.p. */ +#if (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_OSF_ENV) + code = HandleFlock(avc, code, &treq, clid, 0 /*!onlymine */ ); +#elif defined(AFS_SGI_ENV) + AFS_RWLOCK((vnode_t *) avc, VRWLOCK_WRITE); + code = HandleFlock(avc, code, &treq, clid, 0 /*!onlymine */ ); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE); #else - code = HandleFlock(avc, code, &treq, 0, 0/*!onlymine*/); + code = HandleFlock(avc, code, &treq, 0, 0 /*!onlymine */ ); #endif -#endif - code = afs_CheckCode(code, &treq, 3); /* defeat AIX -O bug */ - afs_PutFakeStat(&fakestate); - return code; + code = afs_CheckCode(code, &treq, 3); /* defeat AIX -O bug */ + afs_PutFakeStat(&fakestate); + return code; } afs_PutFakeStat(&fakestate); return EINVAL; @@ -615,22 +597,22 @@ struct AFS_UCRED *acred; { * 2. Asking for write lock, and only the current * PID has the file read locked. */ -#ifndef AFS_OSF_ENV /* getlock is a no-op for osf (for now) */ -HandleGetLock(avc, af, areq, clid) - int clid; /* not used by some OSes */ - register struct vcache *avc; - register struct vrequest *areq; - register struct AFS_FLOCK *af; +#ifndef AFS_OSF_ENV /* getlock is a no-op for osf (for now) */ +static int +HandleGetLock(register struct vcache *avc, register struct AFS_FLOCK *af, + register struct vrequest *areq, int clid) { register afs_int32 code; struct AFS_FLOCK flock; - lockIdSet(&flock, (struct SimpleLocks *)0, clid); + lockIdSet(&flock, NULL, clid); - ObtainWriteLock(&avc->lock,122); + ObtainWriteLock(&avc->lock, 122); if (avc->flockCount == 0) { - /* We don't know ourselves, so ask the server. Unfortunately, we don't know the pid. - * Not even the server knows the pid. Besides, the process with the lock is on another machine + /* + * We don't know ourselves, so ask the server. Unfortunately, we + * don't know the pid. Not even the server knows the pid. Besides, + * the process with the lock is on another machine */ code = GetFlockCount(avc, areq); if (code == 0 || (af->l_type == F_RDLCK && code > 0)) { @@ -643,7 +625,7 @@ HandleGetLock(avc, af, areq, clid) af->l_type = F_WRLCK; af->l_pid = 0; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) +#if defined(AFS_HAVE_FLOCK_SYSID) af->l_sysid = 0; #endif goto done; @@ -655,22 +637,22 @@ HandleGetLock(avc, af, areq, clid) * read locks, or we are the one with the * write lock, say it is unlocked. */ - if (avc->flockCount > 0 || /* only read locks */ - !lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) { + if (avc->flockCount > 0 || /* only read locks */ + !lockIdcmp2(&flock, avc, NULL, 1, clid)) { af->l_type = F_UNLCK; goto unlck_leave; } /* one write lock, but who? */ - af->l_type = F_WRLCK; /* not us, so lock would block */ - if (avc->slocks) { /* we know who, so tell */ + af->l_type = F_WRLCK; /* not us, so lock would block */ + if (avc->slocks) { /* we know who, so tell */ af->l_pid = avc->slocks->pid; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) +#if defined(AFS_HAVE_FLOCK_SYSID) af->l_sysid = avc->slocks->sysid; #endif } else { - af->l_pid = 0; /* XXX can't happen?? */ -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) + af->l_pid = 0; /* XXX can't happen?? */ +#if defined(AFS_HAVE_FLOCK_SYSID) af->l_sysid = 0; #endif } @@ -682,22 +664,22 @@ HandleGetLock(avc, af, areq, clid) * already, and it is not this process, we fail. */ if (avc->flockCount < 0) { - if (lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) { + if (lockIdcmp2(&flock, avc, NULL, 1, clid)) { af->l_type = F_WRLCK; if (avc->slocks) { af->l_pid = avc->slocks->pid; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) +#if defined(AFS_HAVE_FLOCK_SYSID) af->l_sysid = avc->slocks->sysid; #endif } else { - af->l_pid = 0; /* XXX can't happen?? */ -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) + af->l_pid = 0; /* XXX can't happen?? */ +#if defined(AFS_HAVE_FLOCK_SYSID) af->l_sysid = 0; #endif } goto done; } - /* we are the one with the write lock */ + /* we are the one with the write lock */ af->l_type = F_UNLCK; goto unlck_leave; } @@ -707,104 +689,104 @@ HandleGetLock(avc, af, areq, clid) * If there is more than one, or it isn't us, we cannot lock. */ if ((avc->flockCount > 1) - || lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) { + || lockIdcmp2(&flock, avc, NULL, 1, clid)) { struct SimpleLocks *slp; - + af->l_type = F_RDLCK; af->l_pid = 0; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) +#if defined(AFS_HAVE_FLOCK_SYSID) af->l_sysid = 0; #endif /* find a pid that isn't our own */ for (slp = avc->slocks; slp; slp = slp->next) { - if (lockIdcmp2(&flock, (struct vcache *)0, slp, 1, clid)) { - af->l_pid = slp->pid; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - af->l_sysid = avc->slocks->sysid; + if (lockIdcmp2(&flock, NULL, slp, 1, clid)) { + af->l_pid = slp->pid; +#if defined(AFS_HAVE_FLOCK_SYSID) + af->l_sysid = avc->slocks->sysid; #endif break; - } - } + } + } goto done; } - /* - * Ok, we want a write lock. If there is a write lock - * already, and it is not this process, we fail. - */ - if (avc->flockCount < 0) { - if (lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) { - af->l_type = F_WRLCK; - if (avc->slocks) { - af->l_pid = avc->slocks->pid; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - af->l_sysid = avc->slocks->sysid; + /* + * Ok, we want a write lock. If there is a write lock + * already, and it is not this process, we fail. + */ + if (avc->flockCount < 0) { + if (lockIdcmp2(&flock, avc, NULL, 1, clid)) { + af->l_type = F_WRLCK; + if (avc->slocks) { + af->l_pid = avc->slocks->pid; +#if defined(AFS_HAVE_FLOCK_SYSID) + af->l_sysid = avc->slocks->sysid; #endif - } else { - af->l_pid = 0; /* XXX can't happen?? */ -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - af->l_sysid = 0; + } else { + af->l_pid = 0; /* XXX can't happen?? */ +#if defined(AFS_HAVE_FLOCK_SYSID) + af->l_sysid = 0; #endif - } - goto done; } - /* we are the one with the write lock */ - af->l_type = F_UNLCK; - goto unlck_leave; + goto done; } + /* we are the one with the write lock */ + af->l_type = F_UNLCK; + goto unlck_leave; + } - /* - * Want a write lock, and we know there are read locks. - * If there is more than one, or it isn't us, we cannot lock. - */ - if ((avc->flockCount > 1) - || lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) { - struct SimpleLocks *slp; - af->l_type = F_RDLCK; - af->l_pid = 0; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - af->l_sysid = 0; + /* + * Want a write lock, and we know there are read locks. + * If there is more than one, or it isn't us, we cannot lock. + */ + if ((avc->flockCount > 1) + || lockIdcmp2(&flock, avc, NULL, 1, clid)) { + struct SimpleLocks *slp; + af->l_type = F_RDLCK; + af->l_pid = 0; +#if defined(AFS_HAVE_FLOCK_SYSID) + af->l_sysid = 0; #endif - /* find a pid that isn't our own */ - for (slp = avc->slocks; slp; slp = slp->next) { - if (lockIdcmp2(&flock, (struct vcache *)0, slp, 1, clid)) { - af->l_pid = slp->pid; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - af->l_sysid = avc->slocks->sysid; + /* find a pid that isn't our own */ + for (slp = avc->slocks; slp; slp = slp->next) { + if (lockIdcmp2(&flock, NULL, slp, 1, clid)) { + af->l_pid = slp->pid; +#if defined(AFS_HAVE_FLOCK_SYSID) + af->l_sysid = avc->slocks->sysid; #endif - break; - } + break; } - goto done; - } - - /* - * Want a write lock, and there is just one read lock, and it - * is this process with a read lock. Ask the server if there - * are any more processes with the file locked. - */ - code = GetFlockCount(avc, areq); - if (code == 0 || code == 1) { - af->l_type = F_UNLCK; - goto unlck_leave; } - if (code > 0) - af->l_type = F_RDLCK; - else - af->l_type = F_WRLCK; - af->l_pid = 0; -#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) - af->l_sysid = 0; + goto done; + } + + /* + * Want a write lock, and there is just one read lock, and it + * is this process with a read lock. Ask the server if there + * are any more processes with the file locked. + */ + code = GetFlockCount(avc, areq); + if (code == 0 || code == 1) { + af->l_type = F_UNLCK; + goto unlck_leave; + } + if (code > 0) + af->l_type = F_RDLCK; + else + af->l_type = F_WRLCK; + af->l_pid = 0; +#if defined(AFS_HAVE_FLOCK_SYSID) + af->l_sysid = 0; #endif -done: - af->l_whence = 0; - af->l_start = 0; - af->l_len = 0; /* to end of file */ + done: + af->l_whence = 0; + af->l_start = 0; + af->l_len = 0; /* to end of file */ -unlck_leave: - ReleaseWriteLock(&avc->lock); - return 0; + unlck_leave: + ReleaseWriteLock(&avc->lock); + return 0; } /* Get the 'flock' count from the server. This comes back in a 'spare' @@ -813,7 +795,8 @@ unlck_leave: * the spare field will be a zero, saying the file is unlocked. This is * OK, as a further 'lock' request will do the right thing. */ -static int GetFlockCount(struct vcache *avc, struct vrequest *areq) +static int +GetFlockCount(struct vcache *avc, struct vrequest *areq) { register struct conn *tc; register afs_int32 code; @@ -821,54 +804,49 @@ static int GetFlockCount(struct vcache *avc, struct vrequest *areq) struct AFSCallBack CallBack; struct AFSVolSync tsync; int temp; - XSTATS_DECLS - - temp = areq->flags & O_NONBLOCK; + XSTATS_DECLS temp = areq->flags & O_NONBLOCK; areq->flags |= O_NONBLOCK; do { - tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); - if (tc){ - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_FetchStatus(tc->id, (struct AFSFid *) &avc->fid.Fid, - &OutStatus, &CallBack, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_FETCHSTATUS, - SHARED_LOCK, (struct cell *)0)); + tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); + if (tc) { + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS); + RX_AFS_GUNLOCK(); + code = + RXAFS_FetchStatus(tc->id, (struct AFSFid *)&avc->fid.Fid, + &OutStatus, &CallBack, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS, + SHARED_LOCK, NULL)); if (temp) areq->flags &= ~O_NONBLOCK; if (code) { - return(0); /* failed, say it is 'unlocked' */ + return (0); /* failed, say it is 'unlocked' */ } else { - return((int)OutStatus.lockCount); + return ((int)OutStatus.lockCount); } } #endif -#if !defined(AFS_AIX_ENV) && !defined(AFS_HPUX_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_SGI_ENV) && !defined(UKERNEL) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if !defined(AFS_AIX_ENV) && !defined(AFS_HPUX_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_SGI_ENV) && !defined(UKERNEL) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) /* Flock not support on System V systems */ #ifdef AFS_OSF_ENV extern struct fileops afs_fileops; -afs_xflock (p, args, retval) - struct proc *p; - void *args; - int *retval; -{ + +int +afs_xflock(struct proc *p, void *args, int *retval) #else /* AFS_OSF_ENV */ -afs_xflock () { +int +afs_xflock(void) #endif +{ int code = 0; struct a { int fd; @@ -909,7 +887,7 @@ afs_xflock () { /* find real vcache entry; shouldn't be null if gnode ref count * is greater than 0. */ - tvc = VTOAFS(afs_gntovn)(tvc); + tvc = VTOAFS(afs_gntovn) (tvc); if (!tvc) { u.u_error = ENOENT; afs_PutFakeStat(&fakestate); @@ -924,19 +902,21 @@ afs_xflock () { if ((fd->f_flag & (FEXLOCK | FSHLOCK)) && !(uap->com & LOCK_UN)) { /* First, if fd already has lock, release it for relock path */ #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) - HandleFlock(tvc, LOCK_UN, &treq, u.u_procp->p_pid, 0/*!onlymine*/); + HandleFlock(tvc, LOCK_UN, &treq, u.u_procp->p_pid, + 0 /*!onlymine */ ); #else - HandleFlock(tvc, LOCK_UN, &treq, 0, 0/*!onlymine*/); + HandleFlock(tvc, LOCK_UN, &treq, 0, 0 /*!onlymine */ ); #endif fd->f_flag &= ~(FEXLOCK | FSHLOCK); } /* now try the requested operation */ #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) - code = HandleFlock(tvc, uap->com, &treq, - u.u_procp->p_pid, 0/*!onlymine*/); + code = + HandleFlock(tvc, uap->com, &treq, u.u_procp->p_pid, + 0 /*!onlymine */ ); #else - code = HandleFlock(tvc, uap->com, &treq, 0, 0/*!onlymine*/); + code = HandleFlock(tvc, uap->com, &treq, 0, 0 /*!onlymine */ ); #endif #ifndef AFS_OSF_ENV u.u_error = code; @@ -945,15 +925,16 @@ afs_xflock () { if (uap->com & LOCK_UN) { /* gave up lock */ fd->f_flag &= ~(FEXLOCK | FSHLOCK); - } - else { + } else { #ifdef AFS_OSF_ENV if (!code) { #else /* AFS_OSF_ENV */ if (!u.u_error) { #endif - if (uap->com & LOCK_SH) fd->f_flag |= FSHLOCK; - else if (uap->com & LOCK_EX) fd->f_flag |= FEXLOCK; + if (uap->com & LOCK_SH) + fd->f_flag |= FSHLOCK; + else if (uap->com & LOCK_EX) + fd->f_flag |= FEXLOCK; } } flockDone = 1; @@ -970,16 +951,15 @@ afs_xflock () { #endif afs_PutFakeStat(&fakestate); return code; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ if (!flockDone) #ifdef DYNEL - (*afs_longcall_procs.LC_flock)(); + (*afs_longcall_procs.LC_flock) (); #else - flock(); + flock(); #endif afs_PutFakeStat(&fakestate); return; #endif } #endif /* !defined(AFS_AIX_ENV) && !defined(AFS_HPUX_ENV) && !defined(AFS_SUN5_ENV) && !defined(UKERNEL) && !defined(AFS_LINUX20_ENV) */ - diff --git a/src/afs/VNOPS/afs_vnop_link.c b/src/afs/VNOPS/afs_vnop_link.c index c6602dfbe..db500430b 100644 --- a/src/afs/VNOPS/afs_vnop_link.c +++ b/src/afs/VNOPS/afs_vnop_link.c @@ -14,67 +14,72 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_link.c,v 1.1.1.6 2002/08/02 04:29:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_link.c,v 1.15 2003/08/29 22:00:04 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern afs_rwlock_t afs_xcbhash; /* Note that we don't set CDirty here, this is OK because the link * RPC is called synchronously. */ +int #ifdef AFS_OSF_ENV afs_link(avc, ndp) - struct vcache *avc; - struct nameidata *ndp; { + struct vcache *avc; + struct nameidata *ndp; +{ struct vcache *adp = VTOAFS(ndp->ni_dvp); char *aname = ndp->ni_dent.d_name; struct ucred *acred = ndp->ni_cred; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) afs_link(OSI_VC_ARG(adp), avc, aname, acred) #else afs_link(avc, OSI_VC_ARG(adp), aname, acred) #endif OSI_VC_DECL(adp); - struct vcache *avc; - char *aname; - struct AFS_UCRED *acred; + struct vcache *avc; + char *aname; + struct AFS_UCRED *acred; { #endif struct vrequest treq; register struct dcache *tdc; register afs_int32 code; register struct conn *tc; - afs_int32 offset, len; + afs_size_t offset, len; struct AFSFetchStatus OutFidStatus, OutDirStatus; struct AFSVolSync tsync; struct afs_fakestat_state vfakestate, dfakestate; - XSTATS_DECLS - OSI_VC_CONVERT(adp) + XSTATS_DECLS OSI_VC_CONVERT(adp) - AFS_STATCNT(afs_link); + AFS_STATCNT(afs_link); afs_Trace3(afs_iclSetp, CM_TRACE_LINK, ICL_TYPE_POINTER, adp, ICL_TYPE_POINTER, avc, ICL_TYPE_STRING, aname); /* create a hard link; new entry is aname in dir adp */ - if (code = afs_InitReq(&treq, acred)) + if ((code = afs_InitReq(&treq, acred))) goto done2; afs_InitFakeStat(&vfakestate); afs_InitFakeStat(&dfakestate); code = afs_EvalFakeStat(&avc, &vfakestate, &treq); - if (code) goto done; + if (code) + goto done; code = afs_EvalFakeStat(&adp, &dfakestate, &treq); - if (code) goto done; + if (code) + goto done; - if (avc->fid.Cell != adp->fid.Cell || avc->fid.Fid.Volume != adp->fid.Fid.Volume) { + if (avc->fid.Cell != adp->fid.Cell + || avc->fid.Fid.Volume != adp->fid.Fid.Volume) { code = EXDEV; goto done; } @@ -83,51 +88,52 @@ afs_link(avc, OSI_VC_ARG(adp), aname, acred) goto done; } code = afs_VerifyVCache(adp, &treq); - if (code) goto done; + if (code) + goto done; /** If the volume is read-only, return error without making an RPC to the * fileserver */ - if ( adp->states & CRO ) { - code = EROFS; + if (adp->states & CRO) { + code = EROFS; goto done; } - tdc = afs_GetDCache(adp, 0, &treq, &offset, &len, 1); /* test for error below */ - ObtainWriteLock(&adp->lock,145); + tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */ + ObtainWriteLock(&adp->lock, 145); do { tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_LINK); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_Link(tc->id, (struct AFSFid *) &adp->fid.Fid, aname, - (struct AFSFid *) &avc->fid.Fid, &OutFidStatus, - &OutDirStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - - } - else code = -1; - } while - (afs_Analyze(tc, code, &adp->fid, &treq, - AFS_STATS_FS_RPCIDX_LINK, SHARED_LOCK, (struct cell *)0)); + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_LINK); + RX_AFS_GUNLOCK(); + code = + RXAFS_Link(tc->id, (struct AFSFid *)&adp->fid.Fid, aname, + (struct AFSFid *)&avc->fid.Fid, &OutFidStatus, + &OutDirStatus, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + + } else + code = -1; + } while (afs_Analyze + (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_LINK, + SHARED_LOCK, NULL)); if (code) { - if (tdc) afs_PutDCache(tdc); + if (tdc) + afs_PutDCache(tdc); if (code < 0) { - ObtainWriteLock(&afs_xcbhash, 492); - afs_DequeueCallback(adp); - adp->states &= ~CStatd; - ReleaseWriteLock(&afs_xcbhash); - osi_dnlc_purgedp(adp); + ObtainWriteLock(&afs_xcbhash, 492); + afs_DequeueCallback(adp); + adp->states &= ~CStatd; + ReleaseWriteLock(&afs_xcbhash); + osi_dnlc_purgedp(adp); } ReleaseWriteLock(&adp->lock); goto done; } + if (tdc) + ObtainWriteLock(&tdc->lock, 635); if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ code = afs_dir_Create(&tdc->f.inode, aname, &avc->fid.Fid); @@ -137,10 +143,11 @@ afs_link(avc, OSI_VC_ARG(adp), aname, acred) } } if (tdc) { + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); /* drop ref count */ } ReleaseWriteLock(&adp->lock); - ObtainWriteLock(&avc->lock,146); /* correct link count */ + ObtainWriteLock(&avc->lock, 146); /* correct link count */ /* we could lock both dir and file; since we get the new fid * status back, you'd think we could put it in the cache status @@ -151,20 +158,19 @@ afs_link(avc, OSI_VC_ARG(adp), aname, acred) ObtainWriteLock(&afs_xcbhash, 493); afs_DequeueCallback(avc); - avc->states &= ~CStatd; /* don't really know new link count */ + avc->states &= ~CStatd; /* don't really know new link count */ ReleaseWriteLock(&afs_xcbhash); if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR)) osi_dnlc_purgedp(avc); ReleaseWriteLock(&avc->lock); code = 0; -done: + done: code = afs_CheckCode(code, &treq, 24); afs_PutFakeStat(&vfakestate); afs_PutFakeStat(&dfakestate); -done2: + done2: #ifdef AFS_OSF_ENV - afs_PutVCache(adp, WRITE_LOCK); -#endif /* AFS_OSF_ENV */ + afs_PutVCache(adp); +#endif /* AFS_OSF_ENV */ return code; } - diff --git a/src/afs/VNOPS/afs_vnop_lookup.c b/src/afs/VNOPS/afs_vnop_lookup.c index 8f40009e6..8987c9820 100644 --- a/src/afs/VNOPS/afs_vnop_lookup.c +++ b/src/afs/VNOPS/afs_vnop_lookup.c @@ -12,46 +12,31 @@ * afs_lookup * EvalMountPoint * afs_DoBulkStat - * - * Locals: - * afs_strcat - * AFS_EQ_ATSYS (macro) - * afs_index */ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_lookup.c,v 1.14 2003/04/13 19:32:23 hartmans Exp $"); +#include "afs/param.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/exporter.h" -#include "../afs/afs_osidnlc.h" +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_lookup.c,v 1.50 2004/03/17 06:43:36 shadow Exp $"); +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/exporter.h" +#include "afs/afs_osidnlc.h" -/** - * A few definitions. This is until we have a proper header file - * which has prototypes for all functions - */ -extern struct DirEntry * afs_dir_GetBlob(); +extern struct DirEntry *afs_dir_GetBlob(); -extern afs_rwlock_t afs_xvcache; -extern afs_rwlock_t afs_xcbhash; -extern struct afs_exporter *afs_nfsexporter; -extern char *afs_sysname; -extern char *afs_sysnamelist[]; -extern int afs_sysnamecount; -extern struct afs_q VLRU; /*vcache LRU*/ #ifdef AFS_LINUX22_ENV extern struct inode_operations afs_symlink_iops, afs_dir_iops; #endif +afs_int32 afs_bkvolpref = 0; afs_int32 afs_bulkStatsDone; static int bulkStatCounter = 0; /* counter for bulk stat seq. numbers */ int afs_fakestat_enable = 0; /* 1: fakestat-all, 2: fakestat-crosscell */ @@ -62,34 +47,6 @@ int afs_fakestat_enable = 0; /* 1: fakestat-all, 2: fakestat-crosscell */ * what "@sys" is in binary... */ #define AFS_EQ_ATSYS(name) (((name)[0]=='@')&&((name)[1]=='s')&&((name)[2]=='y')&&((name)[3]=='s')&&(!(name)[4])) -char * -afs_strcat(s1, s2) - register char *s1, *s2; -{ - register char *os1; - - AFS_STATCNT(strcat); - os1 = s1; - while (*s1++) - ; - --s1; - while (*s1++ = *s2++) - ; - return (os1); -} - - -char *afs_index(a, c) - register char *a, c; { - register char tc; - AFS_STATCNT(afs_index); - while (tc = *a) { - if (tc == c) return a; - else a++; - } - return (char *) 0; -} - /* call under write lock, evaluate mvid field from a mt pt. * avc is the vnode of the mount point object; must be write-locked. * advc is the vnode of the containing directory (optional; if NULL and @@ -99,101 +56,115 @@ char *afs_index(a, c) * * NOTE: this function returns a held volume structure in *volpp if it returns 0! */ -EvalMountPoint(avc, advc, avolpp, areq) - register struct vcache *avc; - struct volume **avolpp; - struct vcache *advc; /* the containing dir */ - register struct vrequest *areq; +int +EvalMountPoint(register struct vcache *avc, struct vcache *advc, + struct volume **avolpp, register struct vrequest *areq) { - afs_int32 code; + afs_int32 code; struct volume *tvp = 0; struct VenusFid tfid; struct cell *tcell; - char *cpos, *volnamep; - char type, *buf; - afs_int32 prefetchRO; /* 1=>No 2=>Yes */ - afs_int32 mtptCell, assocCell, hac=0; - afs_int32 samecell, roname, len; + char *cpos, *volnamep; + char type, *buf; + afs_int32 prefetch; /* 1=>None 2=>RO 3=>BK */ + afs_int32 mtptCell, assocCell, hac = 0; + afs_int32 samecell, roname, len; AFS_STATCNT(EvalMountPoint); #ifdef notdef - if (avc->mvid && (avc->states & CMValid)) return 0; /* done while racing */ + if (avc->mvid && (avc->states & CMValid)) + return 0; /* done while racing */ #endif - *avolpp = (struct volume *)0; + *avolpp = NULL; code = afs_HandleLink(avc, areq); - if (code) return code; + if (code) + return code; /* Determine which cell and volume the mointpoint goes to */ - type = avc->linkData[0]; /* '#'=>Regular '%'=>RW */ - cpos = afs_index(&avc->linkData[1], ':'); /* if cell name present */ + type = avc->linkData[0]; /* '#'=>Regular '%'=>RW */ + cpos = afs_strchr(&avc->linkData[1], ':'); /* if cell name present */ if (cpos) { - volnamep = cpos+1; - *cpos = 0; - tcell = afs_GetCellByName(&avc->linkData[1], READ_LOCK); - *cpos = ':'; + volnamep = cpos + 1; + *cpos = 0; + tcell = afs_GetCellByName(&avc->linkData[1], READ_LOCK); + *cpos = ':'; } else { - volnamep = &avc->linkData[1]; - tcell = afs_GetCell(avc->fid.Cell, READ_LOCK); + volnamep = &avc->linkData[1]; + tcell = afs_GetCell(avc->fid.Cell, READ_LOCK); } - if (!tcell) return ENODEV; + if (!tcell) + return ENODEV; - mtptCell = tcell->cellNum; /* The cell for the mountpoint */ + mtptCell = tcell->cellNum; /* The cell for the mountpoint */ if (tcell->lcellp) { - hac = 1; /* has associated cell */ - assocCell = tcell->lcellp->cellNum; /* The associated cell */ + hac = 1; /* has associated cell */ + assocCell = tcell->lcellp->cellNum; /* The associated cell */ } - afs_PutCell(tcell, READ_LOCK); + afs_PutCell(tcell, READ_LOCK); /* Is volume name a ".backup" or ".readonly" name */ len = strlen(volnamep); - roname = ((len > 9) && (strcmp(&volnamep[len - 9],".readonly") == 0)) || - ((len > 7) && (strcmp(&volnamep[len - 7],".backup") == 0)); + roname = ((len > 9) && (strcmp(&volnamep[len - 9], ".readonly") == 0)) + || ((len > 7) && (strcmp(&volnamep[len - 7], ".backup") == 0)); /* When we cross mountpoint, do we stay in the same cell */ - samecell = (avc->fid.Cell == mtptCell) || (hac && (avc->fid.Cell == assocCell)); - - /* Decide whether to prefetch the RO. Also means we want the RO. - * If this is a regular mountpoint with a RW volume name and - * we cross a cell boundary -or- start from a RO volume, then we will - * want to prefetch the RO volume when we get the RW below. + samecell = (avc->fid.Cell == mtptCell) || (hac + && (avc->fid.Cell == + assocCell)); + + /* Decide whether to prefetch the BK, or RO. Also means we want the BK or + * RO. + * If this is a regular mountpoint with a RW volume name + * - If BK preference is enabled AND we remain within the same cell AND + * start from a BK volume, then we will want to prefetch the BK volume. + * - If we cross a cell boundary OR start from a RO volume, then we will + * want to prefetch the RO volume. */ - if ( (type == '#') && !roname && (!samecell || (avc->states & CRO)) ) { - prefetchRO = 2; /* Yes, prefetch the RO */ + if ((type == '#') && !roname) { + if (afs_bkvolpref && samecell && (avc->states & CBackup)) + prefetch = 3; /* Prefetch the BK */ + else if (!samecell || (avc->states & CRO)) + prefetch = 2; /* Prefetch the RO */ + else + prefetch = 1; /* Do not prefetch */ } else { - prefetchRO = 1; /* No prefetch of the RO */ + prefetch = 1; /* Do not prefetch */ } /* Get the volume struct. Unless this volume name has ".readonly" or * ".backup" in it, this will get the volume struct for the RW volume. * The RO volume will be prefetched if requested (but not returned). */ - tvp = afs_GetVolumeByName(volnamep, mtptCell, prefetchRO, areq, WRITE_LOCK); + tvp = afs_GetVolumeByName(volnamep, mtptCell, prefetch, areq, WRITE_LOCK); /* If no volume was found in this cell, try the associated linked cell */ if (!tvp && hac && areq->volumeError) { - tvp = afs_GetVolumeByName(volnamep, assocCell, prefetchRO, areq, WRITE_LOCK); + tvp = + afs_GetVolumeByName(volnamep, assocCell, prefetch, areq, + WRITE_LOCK); } /* Still not found. If we are looking for the RO, then perhaps the RW * doesn't exist? Try adding ".readonly" to volname and look for that. * Don't know why we do this. Would have still found it in above call - jpm. */ - if (!tvp && (prefetchRO == 2)) { - buf = (char *)osi_AllocSmallSpace(strlen(volnamep)+10); + if (!tvp && (prefetch == 2) && len < AFS_SMALLOCSIZ - 10) { + buf = (char *)osi_AllocSmallSpace(len + 10); strcpy(buf, volnamep); afs_strcat(buf, ".readonly"); tvp = afs_GetVolumeByName(buf, mtptCell, 1, areq, WRITE_LOCK); - + /* Try the associated linked cell if failed */ if (!tvp && hac && areq->volumeError) { tvp = afs_GetVolumeByName(buf, assocCell, 1, areq, WRITE_LOCK); } osi_FreeSmallSpace(buf); } - - if (!tvp) return ENODEV; /* Couldn't find the volume */ + + if (!tvp) + return ENODEV; /* Couldn't find the volume */ /* Don't cross mountpoint from a BK to a BK volume */ if ((avc->states & CBackup) && (tvp->states & VBackup)) { @@ -201,19 +172,31 @@ EvalMountPoint(avc, advc, avolpp, areq) return ENODEV; } - /* If we want (prefetched) the RO and it exists, then drop the - * RW volume and get the RO. Othewise, go with the RW. + /* If we want (prefetched) the BK and it exists, then drop the RW volume + * and get the BK. + * Otherwise, if we want (prefetched0 the RO and it exists, then drop the + * RW volume and get the RO. + * Otherwise, go with the RW. */ - if ((prefetchRO == 2) && tvp->roVol) { - tfid.Fid.Volume = tvp->roVol; /* remember RO volume */ - tfid.Cell = tvp->cell; - afs_PutVolume(tvp, WRITE_LOCK); /* release old volume */ - tvp = afs_GetVolume(&tfid, areq, WRITE_LOCK); /* get the new one */ - if (!tvp) return ENODEV; /* oops, can't do it */ + if ((prefetch == 3) && tvp->backVol) { + tfid.Fid.Volume = tvp->backVol; /* remember BK volume */ + tfid.Cell = tvp->cell; + afs_PutVolume(tvp, WRITE_LOCK); /* release old volume */ + tvp = afs_GetVolume(&tfid, areq, WRITE_LOCK); /* get the new one */ + if (!tvp) + return ENODEV; /* oops, can't do it */ + } else if ((prefetch >= 2) && tvp->roVol) { + tfid.Fid.Volume = tvp->roVol; /* remember RO volume */ + tfid.Cell = tvp->cell; + afs_PutVolume(tvp, WRITE_LOCK); /* release old volume */ + tvp = afs_GetVolume(&tfid, areq, WRITE_LOCK); /* get the new one */ + if (!tvp) + return ENODEV; /* oops, can't do it */ } if (avc->mvid == 0) - avc->mvid = (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid)); + avc->mvid = + (struct VenusFid *)osi_AllocSmallSpace(sizeof(struct VenusFid)); avc->mvid->Cell = tvp->cell; avc->mvid->Fid.Volume = tvp->volume; avc->mvid->Fid.Vnode = 1; @@ -236,7 +219,8 @@ EvalMountPoint(avc, advc, avolpp, areq) * to the new path. */ tvp->mtpoint = avc->fid; /* setup back pointer to mtpoint */ - if (advc) tvp->dotdot = advc->fid; + if (advc) + tvp->dotdot = advc->fid; *avolpp = tvp; return 0; @@ -250,10 +234,8 @@ EvalMountPoint(avc, advc, avolpp, areq) * without calling afs_EvalFakeStat is legal, as long as this * function is called. */ - void -afs_InitFakeStat(state) - struct afs_fakestat_state *state; +afs_InitFakeStat(struct afs_fakestat_state *state) { if (!afs_fakestat_enable) return; @@ -271,8 +253,9 @@ afs_InitFakeStat(state) * * Only issues RPCs if canblock is non-zero. */ -int afs_EvalFakeStat_int(struct vcache **avcp, struct afs_fakestat_state *state, - struct vrequest *areq, int canblock) +int +afs_EvalFakeStat_int(struct vcache **avcp, struct afs_fakestat_state *state, + struct vrequest *areq, int canblock) { struct vcache *tvc, *root_vp; struct volume *tvolp = NULL; @@ -312,15 +295,15 @@ int afs_EvalFakeStat_int(struct vcache **avcp, struct afs_fakestat_state *state, do { retry = 0; ObtainWriteLock(&afs_xvcache, 597); - root_vp = afs_FindVCache(tvc->mvid, 0, 0, &retry, 0); + root_vp = afs_FindVCache(tvc->mvid, &retry, 0); if (root_vp && retry) { ReleaseWriteLock(&afs_xvcache); - afs_PutVCache(root_vp, 0); + afs_PutVCache(root_vp); } } while (root_vp && retry); ReleaseWriteLock(&afs_xvcache); } else { - root_vp = afs_GetVCache(tvc->mvid, areq, NULL, NULL, WRITE_LOCK); + root_vp = afs_GetVCache(tvc->mvid, areq, NULL, NULL); } if (!root_vp) { code = canblock ? ENOENT : 0; @@ -344,7 +327,7 @@ int afs_EvalFakeStat_int(struct vcache **avcp, struct afs_fakestat_state *state, code = canblock ? ENOENT : 0; } -done: + done: if (tvolp) afs_PutVolume(tvolp, WRITE_LOCK); return code; @@ -364,10 +347,8 @@ done: * something goes wrong and the error code should be returned to the user. */ int -afs_EvalFakeStat(avcp, state, areq) - struct vcache **avcp; - struct afs_fakestat_state *state; - struct vrequest *areq; +afs_EvalFakeStat(struct vcache **avcp, struct afs_fakestat_state *state, + struct vrequest *areq) { return afs_EvalFakeStat_int(avcp, state, areq, 1); } @@ -383,10 +364,8 @@ afs_EvalFakeStat(avcp, state, areq) * vcache entry (possibly evaluated). */ int -afs_TryEvalFakeStat(avcp, state, areq) - struct vcache **avcp; - struct afs_fakestat_state *state; - struct vrequest *areq; +afs_TryEvalFakeStat(struct vcache **avcp, struct afs_fakestat_state *state, + struct vrequest *areq) { return afs_EvalFakeStat_int(avcp, state, areq, 0); } @@ -398,113 +377,145 @@ afs_TryEvalFakeStat(avcp, state, areq) * afs_InitFakeStat was previously called with this state. */ void -afs_PutFakeStat(state) - struct afs_fakestat_state *state; +afs_PutFakeStat(struct afs_fakestat_state *state) { if (!afs_fakestat_enable) return; osi_Assert(state->valid == 1); if (state->need_release) - afs_PutVCache(state->root_vp, 0); + afs_PutVCache(state->root_vp); state->valid = 0; } - -afs_ENameOK(aname) - register char *aname; { - register char tc; + +int +afs_ENameOK(register char *aname) +{ register int tlen; AFS_STATCNT(ENameOK); tlen = strlen(aname); - if (tlen >= 4 && strcmp(aname+tlen-4, "@sys") == 0) return 0; + if (tlen >= 4 && strcmp(aname + tlen - 4, "@sys") == 0) + return 0; return 1; } -afs_getsysname(areq, adp, bufp) - register struct vrequest *areq; - register struct vcache *adp; - register char *bufp; +static int +afs_getsysname(register struct vrequest *areq, register struct vcache *adp, + register char *bufp, int *num, char **sysnamelist[]) { - static char sysname[MAXSYSNAME]; register struct unixuser *au; register afs_int32 error; - if (!afs_nfsexporter) { - strcpy(bufp, afs_sysname); - return 0; - } AFS_STATCNT(getsysname); - au = afs_GetUser(areq->uid, adp->fid.Cell, 0); - afs_PutUser(au, 0); - if (au->exporter) { - error = EXP_SYSNAME(au->exporter, (char *)0, bufp); - if (error) - strcpy(bufp, "@sys"); - return -1; - } else { - strcpy(bufp, afs_sysname); - return 0; + + *sysnamelist = afs_sysnamelist; + + if (!afs_nfsexporter) + strcpy(bufp, (*sysnamelist)[0]); + else { + au = afs_GetUser(areq->uid, adp->fid.Cell, 0); + if (au->exporter) { + error = EXP_SYSNAME(au->exporter, (char *)0, sysnamelist, num); + if (error) { + strcpy(bufp, "@sys"); + afs_PutUser(au, 0); + return -1; + } else { + strcpy(bufp, (*sysnamelist)[0]); + } + } else + strcpy(bufp, afs_sysname); + afs_PutUser(au, 0); } + return 0; } -Check_AtSys(avc, aname, state, areq) - register struct vcache *avc; - char *aname; - struct sysname_info *state; - struct vrequest *areq; +void +Check_AtSys(register struct vcache *avc, char *aname, + struct sysname_info *state, struct vrequest *areq) { + int num = 0; + char **sysnamelist[MAXSYSNAME]; + if (AFS_EQ_ATSYS(aname)) { - state->offset = 0; - state->name = (char *) osi_AllocLargeSpace(AFS_SMALLOCSIZ); - state->allocked = 1; - state->index = afs_getsysname(areq, avc, state->name); + state->offset = 0; + state->name = (char *)osi_AllocLargeSpace(AFS_SMALLOCSIZ); + state->allocked = 1; + state->index = afs_getsysname(areq, avc, state->name, &num, sysnamelist); } else { - state->offset = -1; - state->allocked = 0; - state->index = 0; - state->name = aname; + state->offset = -1; + state->allocked = 0; + state->index = 0; + state->name = aname; } } -Next_AtSys(avc, areq, state) - register struct vcache *avc; - struct vrequest *areq; - struct sysname_info *state; +int +Next_AtSys(register struct vcache *avc, struct vrequest *areq, + struct sysname_info *state) { - if (state->index == -1) - return 0; /* No list */ - - /* Check for the initial state of aname != "@sys" in Check_AtSys*/ - if (state->offset == -1 && state->allocked == 0) { - register char *tname; - /* Check for .*@sys */ - for (tname=state->name; *tname; tname++) - /*Move to the end of the string*/; - if ((tname > state->name + 4) && (AFS_EQ_ATSYS(tname-4))) { - state->offset = (tname - 4) - state->name; - tname = (char *) osi_AllocLargeSpace(AFS_LRALLOCSIZ); - strncpy(tname, state->name, state->offset); - state->name = tname; - state->allocked = 1; - state->index = afs_getsysname(areq, avc, state->name+state->offset); - return 1; - } else - return 0; /* .*@sys doesn't match either */ - } else if (++(state->index) >= afs_sysnamecount - || !afs_sysnamelist[state->index]) - return 0; /* end of list */ - strcpy(state->name+state->offset, afs_sysnamelist[state->index]); - return 1; + int num = afs_sysnamecount; + char **sysnamelist[MAXSYSNAME]; + + if (state->index == -1) + return 0; /* No list */ + + /* Check for the initial state of aname != "@sys" in Check_AtSys*/ + if (state->offset == -1 && state->allocked == 0) { + register char *tname; + + /* Check for .*@sys */ + for (tname=state->name; *tname; tname++) + /*Move to the end of the string*/; + + if ((tname > state->name + 4) && (AFS_EQ_ATSYS(tname-4))) { + state->offset = (tname - 4) - state->name; + tname = (char *) osi_AllocLargeSpace(AFS_LRALLOCSIZ); + strncpy(tname, state->name, state->offset); + state->name = tname; + state->allocked = 1; + num = 0; + state->index = afs_getsysname(areq, avc, state->name+state->offset, + &num, sysnamelist); + return 1; + } else + return 0; /* .*@sys doesn't match either */ + } else { + register struct unixuser *au; + register afs_int32 error; + + *sysnamelist = afs_sysnamelist; + + if (afs_nfsexporter) { + au = afs_GetUser(areq->uid, avc->fid.Cell, 0); + if (au->exporter) { + error = EXP_SYSNAME(au->exporter, (char *)0, sysnamelist, num); + if (error) { + return 0; + } + } + afs_PutUser(au, 0); + } + if (++(state->index) >= num || !(*sysnamelist)[state->index]) + return 0; /* end of list */ + } + strcpy(state->name+state->offset, (*sysnamelist)[state->index]); + return 1; } #if (defined(AFS_SGI62_ENV) || defined(AFS_SUN57_64BIT_ENV)) -extern int BlobScan(ino64_t *afile, afs_int32 ablob); +extern int BlobScan(ino64_t * afile, afs_int32 ablob); +#else +#if defined(AFS_HPUX1123_ENV) +/* DEE should use the new afs_inode_t for all */ +extern int BlobScan(ino_t *afile, afs_int32 ablob); #else #if defined AFS_LINUX_64BIT_KERNEL extern int BlobScan(long *afile, afs_int32 ablob); #else -extern int BlobScan(afs_int32 *afile, afs_int32 ablob); +extern int BlobScan(afs_int32 * afile, afs_int32 ablob); +#endif #endif #endif @@ -525,11 +536,10 @@ extern int BlobScan(afs_int32 *afile, afs_int32 ablob); * ensure that vcaches created for failed RPC's to older servers have the * CForeign bit set. */ -struct vcache * BStvc = (struct vcache *) 0; -int afs_DoBulkStat(adp, dirCookie, areqp) - struct vcache *adp; - long dirCookie; - struct vrequest *areqp; +static struct vcache *BStvc = NULL; + +int +afs_DoBulkStat(struct vcache *adp, long dirCookie, struct vrequest *areqp) { int nentries; /* # of entries to prefetch */ int nskip; /* # of slots in the LRU queue to skip */ @@ -537,7 +547,7 @@ int afs_DoBulkStat(adp, dirCookie, areqp) struct dcache *dcp; /* chunk containing the dir block */ char *statMemp; /* status memory block */ char *cbfMemp; /* callback and fid memory block */ - long temp; /* temp for holding chunk length, &c. */ + afs_size_t temp; /* temp for holding chunk length, &c. */ struct AFSFid *fidsp; /* file IDs were collecting */ struct AFSCallBack *cbsp; /* call back pointers */ struct AFSCallBack *tcbp; /* temp callback ptr */ @@ -551,53 +561,51 @@ int afs_DoBulkStat(adp, dirCookie, areqp) struct conn *tcp; /* conn for call */ AFSCBs cbParm; /* callback parm for bulk stat */ struct server *hostp = 0; /* host we got callback from */ - long origEvenCBs; /* original # of callbacks for even-fid files */ - long origOddCBs; /* original # of callbacks for odd-fid files */ - long origEvenZaps; /* original # of recycles for even-fid files */ - long origOddZaps; /* original # of recycles for odd-fid files */ long startTime; /* time we started the call, * for callback expiration base */ - int statSeqNo; /* Valued of file size to detect races */ + afs_size_t statSeqNo; /* Valued of file size to detect races */ int code; /* error code */ long newIndex; /* new index in the dir */ struct DirEntry *dirEntryp; /* dir entry we are examining */ int i; struct VenusFid afid; /* file ID we are using now */ struct VenusFid tfid; /* another temp. file ID */ - afs_int32 retry; /* handle low-level SGI MP race conditions */ + afs_int32 retry; /* handle low-level SGI MP race conditions */ long volStates; /* flags from vol structure */ - struct volume *volp=0; /* volume ptr */ + struct volume *volp = 0; /* volume ptr */ struct VenusFid dotdot; - int flagIndex; /* First file with bulk fetch flag set */ - int inlinebulk=0; /* Did we use InlineBulk RPC or not? */ + int flagIndex; /* First file with bulk fetch flag set */ + int inlinebulk = 0; /* Did we use InlineBulk RPC or not? */ XSTATS_DECLS - - /* first compute some basic parameters. We dont want to prefetch more - * than a fraction of the cache in any given call, and we want to preserve - * a portion of the LRU queue in any event, so as to avoid thrashing - * the entire stat cache (we will at least leave some of it alone). - * presently dont stat more than 1/8 the cache in any one call. */ - nentries = afs_cacheStats / 8; + /* first compute some basic parameters. We dont want to prefetch more + * than a fraction of the cache in any given call, and we want to preserve + * a portion of the LRU queue in any event, so as to avoid thrashing + * the entire stat cache (we will at least leave some of it alone). + * presently dont stat more than 1/8 the cache in any one call. */ + nentries = afs_cacheStats / 8; /* dont bother prefetching more than one calls worth of info */ - if (nentries > AFSCBMAX) nentries = AFSCBMAX; + if (nentries > AFSCBMAX) + nentries = AFSCBMAX; /* heuristic to make sure that things fit in 4K. This means that * we shouldnt make it any bigger than 47 entries. I am typically * going to keep it a little lower, since we don't want to load * too much of the stat cache. */ - if (nentries > 30) nentries = 30; + if (nentries > 30) + nentries = 30; /* now, to reduce the stack size, well allocate two 4K blocks, * one for fids and callbacks, and one for stat info. Well set * up our pointers to the memory from there, too. */ statMemp = osi_AllocLargeSpace(nentries * sizeof(AFSFetchStatus)); - statsp = (struct AFSFetchStatus *) statMemp; - cbfMemp = osi_AllocLargeSpace(nentries * - (sizeof(AFSCallBack) + sizeof(AFSFid))); + statsp = (struct AFSFetchStatus *)statMemp; + cbfMemp = + osi_AllocLargeSpace(nentries * + (sizeof(AFSCallBack) + sizeof(AFSFid))); fidsp = (AFSFid *) cbfMemp; cbsp = (AFSCallBack *) (cbfMemp + nentries * sizeof(AFSFid)); @@ -606,11 +614,12 @@ int afs_DoBulkStat(adp, dirCookie, areqp) * We skip files that already have stat cache entries, since we * dont want to bulk stat files that are already in the cache. */ -tagain: + tagain: code = afs_VerifyVCache(adp, areqp); - if (code) goto done; + if (code) + goto done; - dcp = afs_GetDCache(adp, 0, areqp, &temp, &temp, 1); + dcp = afs_GetDCache(adp, (afs_size_t) 0, areqp, &temp, &temp, 1); if (!dcp) { code = ENOENT; goto done; @@ -618,6 +627,7 @@ tagain: /* lock the directory cache entry */ ObtainReadLock(&adp->lock); + ObtainReadLock(&dcp->lock); /* * Make sure that the data in the cache is current. There are two @@ -626,15 +636,20 @@ tagain: * 2. The cache data is no longer valid */ while ((adp->states & CStatd) - && (dcp->flags & DFFetching) + && (dcp->dflags & DFFetching) && hsame(adp->m.DataVersion, dcp->f.versionNo)) { - dcp->flags |= DFWaiting; + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, ICL_TYPE_POINTER, dcp, + ICL_TYPE_INT32, dcp->dflags); + ReleaseReadLock(&dcp->lock); ReleaseReadLock(&adp->lock); afs_osi_Sleep(&dcp->validPos); ObtainReadLock(&adp->lock); + ObtainReadLock(&dcp->lock); } if (!(adp->states & CStatd) || !hsame(adp->m.DataVersion, dcp->f.versionNo)) { + ReleaseReadLock(&dcp->lock); ReleaseReadLock(&adp->lock); afs_PutDCache(dcp); goto tagain; @@ -652,24 +667,27 @@ tagain: /* now we have dir data in the cache, so scan the dir page */ fidIndex = 0; flagIndex = 0; - while (1) { /* Should probably have some constant bound */ + while (1) { /* Should probably have some constant bound */ /* look for first safe entry to examine in the directory. BlobScan * looks for a the 1st allocated dir after the dirCookie slot. */ - newIndex = BlobScan(&dcp->f.inode, (dirCookie>>5)); - if (newIndex == 0) break; + newIndex = BlobScan(&dcp->f.inode, (dirCookie >> 5)); + if (newIndex == 0) + break; /* remember the updated directory cookie */ dirCookie = newIndex << 5; /* get a ptr to the dir entry */ - dirEntryp =(struct DirEntry *)afs_dir_GetBlob(&dcp->f.inode, newIndex); - if (!dirEntryp) break; + dirEntryp = + (struct DirEntry *)afs_dir_GetBlob(&dcp->f.inode, newIndex); + if (!dirEntryp) + break; /* dont copy more than we have room for */ if (fidIndex >= nentries) { - DRelease((char *) dirEntryp, 0); - break; + DRelease((struct buffer *)dirEntryp, 0); + break; } /* now, if the dir entry looks good, copy it out to our list. Vnode @@ -685,25 +703,25 @@ tagain: tfid.Fid.Vnode = ntohl(dirEntryp->fid.vnode); tfid.Fid.Unique = ntohl(dirEntryp->fid.vunique); do { - retry = 0; - ObtainWriteLock(&afs_xvcache, 130); - tvcp = afs_FindVCache(&tfid, 0, 0, &retry, 0 /* no stats | LRU */); - if (tvcp && retry) { - ReleaseWriteLock(&afs_xvcache); - afs_PutVCache(tvcp); - } + retry = 0; + ObtainWriteLock(&afs_xvcache, 130); + tvcp = afs_FindVCache(&tfid, &retry, 0 /* no stats | LRU */ ); + if (tvcp && retry) { + ReleaseWriteLock(&afs_xvcache); + afs_PutVCache(tvcp); + } } while (tvcp && retry); - if (!tvcp) { /* otherwise, create manually */ - tvcp = afs_NewVCache(&tfid, hostp, 0, 0); - ObtainWriteLock(&tvcp->lock, 505); - ReleaseWriteLock(&afs_xvcache); - afs_RemoveVCB(&tfid); - ReleaseWriteLock(&tvcp->lock); + if (!tvcp) { /* otherwise, create manually */ + tvcp = afs_NewVCache(&tfid, hostp); + ObtainWriteLock(&tvcp->lock, 505); + ReleaseWriteLock(&afs_xvcache); + afs_RemoveVCB(&tfid); + ReleaseWriteLock(&tvcp->lock); } else { - ReleaseWriteLock(&afs_xvcache); + ReleaseWriteLock(&afs_xvcache); } if (!tvcp) - goto done; /* can't happen at present, more's the pity */ + goto done; /* can't happen at present, more's the pity */ /* WARNING: afs_DoBulkStat uses the Length field to store a * sequence number for each bulk status request. Under no @@ -711,14 +729,14 @@ tagain: * if the new length will be ignored when afs_ProcessFS is * called with new stats. */ #ifdef AFS_SGI_ENV - if (!(tvcp->states & (CStatd|CBulkFetching)) - && (tvcp->execsOrWriters <= 0) - && !afs_DirtyPages(tvcp) - && !AFS_VN_MAPPED((vnode_t*)tvcp)) + if (!(tvcp->states & (CStatd | CBulkFetching)) + && (tvcp->execsOrWriters <= 0) + && !afs_DirtyPages(tvcp) + && !AFS_VN_MAPPED((vnode_t *) tvcp)) #else - if (!(tvcp->states & (CStatd|CBulkFetching)) - && (tvcp->execsOrWriters <= 0) - && !afs_DirtyPages(tvcp)) + if (!(tvcp->states & (CStatd | CBulkFetching)) + && (tvcp->execsOrWriters <= 0) + && !afs_DirtyPages(tvcp)) #endif { @@ -736,31 +754,36 @@ tagain: * preserve the value of the file size. We could * flush the pages, but it wouldn't be worthwhile. */ - memcpy((char *)(fidsp+fidIndex), (char *) &tfid.Fid, sizeof(*fidsp)); + memcpy((char *)(fidsp + fidIndex), (char *)&tfid.Fid, + sizeof(*fidsp)); tvcp->states |= CBulkFetching; tvcp->m.Length = statSeqNo; fidIndex++; } afs_PutVCache(tvcp); - } /* if dir vnode has non-zero entry */ + } + /* if dir vnode has non-zero entry */ /* move to the next dir entry by adding in the # of entries * used by this dir entry. */ temp = afs_dir_NameBlobs(dirEntryp->name) << 5; - DRelease((char *) dirEntryp, 0); - if (temp <= 0) break; + DRelease((struct buffer *)dirEntryp, 0); + if (temp <= 0) + break; dirCookie += temp; - } /* while loop over all dir entries */ + } /* while loop over all dir entries */ /* now release the dir lock and prepare to make the bulk RPC */ + ReleaseReadLock(&dcp->lock); ReleaseReadLock(&adp->lock); /* release the chunk */ afs_PutDCache(dcp); /* dont make a null call */ - if (fidIndex == 0) goto done; + if (fidIndex == 0) + goto done; do { /* setup the RPC parm structures */ @@ -778,34 +801,37 @@ tagain: if (tcp) { hostp = tcp->srvr->server; XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_BULKSTATUS); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ -#ifdef notdef - code = RXAFS_InlineBulkStatus(tcp->id, &fidParm, &statParm, - &cbParm, &volSync); - if (code == RXGEN_OPCODE) { -#endif - code = RXAFS_BulkStatus(tcp->id, &fidParm, &statParm, &cbParm, - &volSync); - inlinebulk=0; -#ifdef notdef + RX_AFS_GUNLOCK(); + + if (!(tcp->srvr->server->flags & SNO_INLINEBULK)) { + code = + RXAFS_InlineBulkStatus(tcp->id, &fidParm, &statParm, + &cbParm, &volSync); + if (code == RXGEN_OPCODE) { + tcp->srvr->server->flags |= SNO_INLINEBULK; + inlinebulk = 0; + code = + RXAFS_BulkStatus(tcp->id, &fidParm, &statParm, + &cbParm, &volSync); + } else + inlinebulk = 1; } else { - inlinebulk=1; + inlinebulk = 0; + code = + RXAFS_BulkStatus(tcp->id, &fidParm, &statParm, &cbParm, + &volSync); } -#endif - -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); XSTATS_END_TIME; - } - else code = -1; - } while (afs_Analyze(tcp, code, &adp->fid, areqp, - AFS_STATS_FS_RPCIDX_BULKSTATUS, SHARED_LOCK, (struct cell *)0)); + } else + code = -1; + } while (afs_Analyze + (tcp, code, &adp->fid, areqp, AFS_STATS_FS_RPCIDX_BULKSTATUS, + SHARED_LOCK, NULL)); /* now, if we didnt get the info, bail out. */ - if (code) goto done; + if (code) + goto done; /* we need vol flags to create the entries properly */ dotdot.Fid.Volume = 0; @@ -814,8 +840,8 @@ tagain: volStates = volp->states; if (volp->dotdot.Fid.Volume != 0) dotdot = volp->dotdot; - } - else volStates = 0; + } else + volStates = 0; /* find the place to merge the info into We do this by skipping * nskip entries in the LRU queue. The more we skip, the more @@ -823,27 +849,30 @@ tagain: * referenced file. */ reskip: - nskip = afs_cacheStats / 2; /* preserved fraction of the cache */ + nskip = afs_cacheStats / 2; /* preserved fraction of the cache */ ObtainReadLock(&afs_xvcache); if (QEmpty(&VLRU)) { - /* actually a serious error, probably should panic. Probably will - * panic soon, oh well. */ - ReleaseReadLock(&afs_xvcache); - afs_warnuser("afs_DoBulkStat: VLRU empty!"); - goto done; + /* actually a serious error, probably should panic. Probably will + * panic soon, oh well. */ + ReleaseReadLock(&afs_xvcache); + afs_warnuser("afs_DoBulkStat: VLRU empty!"); + goto done; } if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("Bulkstat VLRU inconsistent"); + refpanic("Bulkstat VLRU inconsistent"); } - for(tq = VLRU.next; tq != &VLRU; tq = QNext(tq)) { - if (--nskip <= 0) break; + for (tq = VLRU.next; tq != &VLRU; tq = QNext(tq)) { + if (--nskip <= 0) + break; else if (QNext(QPrev(tq)) != tq) { - BStvc = QTOV(tq); - refpanic ("BulkStat VLRU inconsistent"); + BStvc = QTOV(tq); + refpanic("BulkStat VLRU inconsistent"); } } - if (tq != &VLRU) lruvcp = QTOV(tq); - else lruvcp = QTOV(VLRU.next); + if (tq != &VLRU) + lruvcp = QTOV(tq); + else + lruvcp = QTOV(VLRU.next); /* now we have to hold this entry, so that it does not get moved * into the free list while we're running. It could still get @@ -852,9 +881,9 @@ tagain: */ retry = 0; osi_vnhold(lruvcp, &retry); - ReleaseReadLock(&afs_xvcache); /* could be read lock */ + ReleaseReadLock(&afs_xvcache); /* could be read lock */ if (retry) - goto reskip; + goto reskip; /* otherwise, merge in the info. We have to be quite careful here, * since we need to ensure that we don't merge old info over newer @@ -865,18 +894,18 @@ tagain: * * We also have to take into account racing token revocations. */ - for(i=0; ierrorCode) + for (i = 0; i < fidIndex; i++) { + if ((&statsp[i])->errorCode) continue; afid.Cell = adp->fid.Cell; afid.Fid.Volume = adp->fid.Fid.Volume; afid.Fid.Vnode = fidsp[i].Vnode; afid.Fid.Unique = fidsp[i].Unique; do { - retry = 0; - ObtainReadLock(&afs_xvcache); - tvcp = afs_FindVCache(&afid, 1, 0, &retry, 0/* !stats&!lru*/); - ReleaseReadLock(&afs_xvcache); + retry = 0; + ObtainReadLock(&afs_xvcache); + tvcp = afs_FindVCache(&afid, &retry, 0 /* !stats&!lru */ ); + ReleaseReadLock(&afs_xvcache); } while (tvcp && retry); /* The entry may no longer exist */ @@ -885,7 +914,7 @@ tagain: } /* now we have the entry held, but we need to fill it in */ - ObtainWriteLock(&tvcp->lock,131); + ObtainWriteLock(&tvcp->lock, 131); /* if CBulkFetching is not set, or if the file size no longer * matches the value we placed there when we set the CBulkFetching @@ -901,37 +930,42 @@ tagain: } /* now copy ".." entry back out of volume structure, if necessary */ - if (tvcp->mvstat == 2 && (dotdot.Fid.Volume != 0)) { + if (tvcp->mvstat == 2 && (dotdot.Fid.Volume != 0)) { if (!tvcp->mvid) - tvcp->mvid = (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid)); + tvcp->mvid = (struct VenusFid *) + osi_AllocSmallSpace(sizeof(struct VenusFid)); *tvcp->mvid = dotdot; } - ObtainWriteLock(&afs_xvcache,132); + ObtainWriteLock(&afs_xvcache, 132); if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("Bulkstat VLRU inconsistent2"); + refpanic("Bulkstat VLRU inconsistent2"); + } + if ((QNext(QPrev(&tvcp->vlruq)) != &tvcp->vlruq) + || (QPrev(QNext(&tvcp->vlruq)) != &tvcp->vlruq)) { + refpanic("Bulkstat VLRU inconsistent4"); + } + if ((QNext(QPrev(&lruvcp->vlruq)) != &lruvcp->vlruq) + || (QPrev(QNext(&lruvcp->vlruq)) != &lruvcp->vlruq)) { + refpanic("Bulkstat VLRU inconsistent5"); } - if ((QNext(QPrev(&tvcp->vlruq)) != &tvcp->vlruq) - || (QPrev(QNext(&tvcp->vlruq)) != &tvcp->vlruq)) - refpanic ("Bulkstat VLRU inconsistent4"); - if ((QNext(QPrev(&lruvcp->vlruq)) != &lruvcp->vlruq) - || (QPrev(QNext(&lruvcp->vlruq)) != &lruvcp->vlruq)) - refpanic ("Bulkstat VLRU inconsistent5"); - - if (tvcp != lruvcp) { /* if they are == don't move it, don't corrupt vlru */ - QRemove(&tvcp->vlruq); - QAdd(&lruvcp->vlruq, &tvcp->vlruq); + + if (tvcp != lruvcp) { /* if they are == don't move it, don't corrupt vlru */ + QRemove(&tvcp->vlruq); + QAdd(&lruvcp->vlruq, &tvcp->vlruq); } if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("Bulkstat VLRU inconsistent3"); + refpanic("Bulkstat VLRU inconsistent3"); + } + if ((QNext(QPrev(&tvcp->vlruq)) != &tvcp->vlruq) + || (QPrev(QNext(&tvcp->vlruq)) != &tvcp->vlruq)) { + refpanic("Bulkstat VLRU inconsistent5"); + } + if ((QNext(QPrev(&lruvcp->vlruq)) != &lruvcp->vlruq) + || (QPrev(QNext(&lruvcp->vlruq)) != &lruvcp->vlruq)) { + refpanic("Bulkstat VLRU inconsistent6"); } - if ((QNext(QPrev(&tvcp->vlruq)) != &tvcp->vlruq) - || (QPrev(QNext(&tvcp->vlruq)) != &tvcp->vlruq)) - refpanic ("Bulkstat VLRU inconsistent5"); - if ((QNext(QPrev(&lruvcp->vlruq)) != &lruvcp->vlruq) - || (QPrev(QNext(&lruvcp->vlruq)) != &lruvcp->vlruq)) - refpanic ("Bulkstat VLRU inconsistent6"); ReleaseWriteLock(&afs_xvcache); ObtainWriteLock(&afs_xcbhash, 494); @@ -969,9 +1003,12 @@ tagain: afs_bulkStatsDone++; /* merge in vol info */ - if (volStates & VRO) tvcp->states |= CRO; - if (volStates & VBackup) tvcp->states |= CBackup; - if (volStates & VForeign) tvcp->states |= CForeign; + if (volStates & VRO) + tvcp->states |= CRO; + if (volStates & VBackup) + tvcp->states |= CBackup; + if (volStates & VForeign) + tvcp->states |= CForeign; /* merge in the callback info */ tvcp->states |= CTruth; @@ -980,66 +1017,62 @@ tagain: tcbp = cbsp + i; if (tcbp->ExpirationTime != 0) { - tvcp->cbExpires = tcbp->ExpirationTime+startTime; + tvcp->cbExpires = tcbp->ExpirationTime + startTime; tvcp->callback = hostp; tvcp->states |= CStatd; afs_QueueCallback(tvcp, CBHash(tcbp->ExpirationTime), volp); - } - else if (tvcp->states & CRO) { + } else if (tvcp->states & CRO) { /* ordinary callback on a read-only volume -- AFS 3.2 style */ - tvcp->cbExpires = 3600+startTime; + tvcp->cbExpires = 3600 + startTime; tvcp->callback = hostp; tvcp->states |= CStatd; afs_QueueCallback(tvcp, CBHash(3600), volp); - } - else { + } else { tvcp->callback = 0; - tvcp->states &= ~(CStatd|CUnique); + tvcp->states &= ~(CStatd | CUnique); afs_DequeueCallback(tvcp); - if ((tvcp->states & CForeign) || (vType(tvcp) == VDIR)) - osi_dnlc_purgedp (tvcp); /* if it (could be) a directory */ + if ((tvcp->states & CForeign) || (vType(tvcp) == VDIR)) + osi_dnlc_purgedp(tvcp); /* if it (could be) a directory */ } ReleaseWriteLock(&afs_xcbhash); ReleaseWriteLock(&tvcp->lock); /* finally, we're done with the entry */ afs_PutVCache(tvcp); - } /* for all files we got back */ + } /* for all files we got back */ /* finally return the pointer into the LRU queue */ afs_PutVCache(lruvcp); done: /* Be sure to turn off the CBulkFetching flags */ - for(i=flagIndex; ifid.Cell; afid.Fid.Volume = adp->fid.Fid.Volume; afid.Fid.Vnode = fidsp[i].Vnode; afid.Fid.Unique = fidsp[i].Unique; do { - retry = 0; - ObtainReadLock(&afs_xvcache); - tvcp = afs_FindVCache(&afid, 1, 0, &retry, 0/* !stats&!lru*/); - ReleaseReadLock(&afs_xvcache); + retry = 0; + ObtainReadLock(&afs_xvcache); + tvcp = afs_FindVCache(&afid, &retry, 0 /* !stats&!lru */ ); + ReleaseReadLock(&afs_xvcache); } while (tvcp && retry); - if (tvcp != NULL - && (tvcp->states & CBulkFetching) + if (tvcp != NULL && (tvcp->states & CBulkFetching) && (tvcp->m.Length == statSeqNo)) { - tvcp->states &= ~CBulkFetching; + tvcp->states &= ~CBulkFetching; } if (tvcp != NULL) { - afs_PutVCache(tvcp); + afs_PutVCache(tvcp); } } - if ( volp ) + if (volp) afs_PutVolume(volp, READ_LOCK); - + /* If we did the InlineBulk RPC pull out the return code */ if (inlinebulk) { if ((&statsp[0])->errorCode) { - afs_Analyze(tcp, (&statsp[0])->errorCode, &adp->fid, areqp, - AFS_STATS_FS_RPCIDX_BULKSTATUS, SHARED_LOCK, - (struct cell *)0); + afs_Analyze(tcp, (&statsp[0])->errorCode, &adp->fid, areqp, + AFS_STATS_FS_RPCIDX_BULKSTATUS, SHARED_LOCK, NULL); code = (&statsp[0])->errorCode; } } else { @@ -1051,48 +1084,51 @@ tagain: } /* was: (AFS_DEC_ENV) || defined(AFS_OSF30_ENV) || defined(AFS_NCR_ENV) */ -int AFSDOBULK = 1; +static int AFSDOBULK = 1; +int #ifdef AFS_OSF_ENV afs_lookup(adp, ndp) - struct vcache *adp; - struct nameidata *ndp; { - char aname[MAXNAMLEN+1]; /* XXX */ + struct vcache *adp; + struct nameidata *ndp; +{ + char aname[MAXNAMLEN + 1]; /* XXX */ struct vcache **avcp = (struct vcache **)&(ndp->ni_vp); struct ucred *acred = ndp->ni_cred; int wantparent = ndp->ni_nameiop & WANTPARENT; int opflag = ndp->ni_nameiop & OPFLAG; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) afs_lookup(OSI_VC_ARG(adp), aname, avcp, pnp, flags, rdir, acred) - struct pathname *pnp; - int flags; - struct vnode *rdir; + struct pathname *pnp; + int flags; + struct vnode *rdir; #else #if defined(UKERNEL) afs_lookup(adp, aname, avcp, acred, flags) - int flags; -#else + int flags; +#else afs_lookup(adp, aname, avcp, acred) -#endif /* UKERNEL */ -#endif /* SUN5 || SGI */ - OSI_VC_DECL(adp); - struct vcache **avcp; - char *aname; - struct AFS_UCRED *acred; { +#endif /* UKERNEL */ +#endif /* SUN5 || SGI */ +OSI_VC_DECL(adp); + struct vcache **avcp; + char *aname; + struct AFS_UCRED *acred; +{ #endif struct vrequest treq; - char *tname = (char *)0; - register struct vcache *tvc=0; + char *tname = NULL; + register struct vcache *tvc = 0; register afs_int32 code; register afs_int32 bulkcode = 0; int pass = 0, hit = 0; long dirCookie; - extern afs_int32 afs_mariner; /*Writing activity to log?*/ + extern afs_int32 afs_mariner; /*Writing activity to log? */ OSI_VC_CONVERT(adp) afs_hyper_t versionNo; int no_read_access = 0; - struct sysname_info sysState; /* used only for @sys checking */ + struct sysname_info sysState; /* used only for @sys checking */ int dynrootRetry = 1; struct afs_fakestat_state fakestate; int tryEvalOnly = 0; @@ -1100,14 +1136,14 @@ afs_lookup(adp, aname, avcp, acred) AFS_STATCNT(afs_lookup); afs_InitFakeStat(&fakestate); - if (code = afs_InitReq(&treq, acred)) + if ((code = afs_InitReq(&treq, acred))) goto done; #ifdef AFS_OSF_ENV ndp->ni_dvp = AFSTOV(adp); memcpy(aname, ndp->ni_ptr, ndp->ni_namelen); aname[ndp->ni_namelen] = '\0'; -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ #if defined(AFS_DARWIN_ENV) /* Workaround for MacOSX Finder, which tries to look for @@ -1130,26 +1166,26 @@ afs_lookup(adp, aname, avcp, acred) if (code) goto done; - *avcp = (struct vcache *) 0; /* Since some callers don't initialize it */ + *avcp = NULL; /* Since some callers don't initialize it */ /* come back to here if we encounter a non-existent object in a read-only - volume's directory */ + * volume's directory */ redo: - *avcp = (struct vcache *) 0; /* Since some callers don't initialize it */ + *avcp = NULL; /* Since some callers don't initialize it */ bulkcode = 0; if (!(adp->states & CStatd)) { - if (code = afs_VerifyVCache2(adp, &treq)) { + if ((code = afs_VerifyVCache2(adp, &treq))) { goto done; } - } - else code = 0; + } else + code = 0; /* watch for ".." in a volume root */ if (adp->mvstat == 2 && aname[0] == '.' && aname[1] == '.' && !aname[2]) { /* looking up ".." in root via special hacks */ - if (adp->mvid == (struct VenusFid *) 0 || adp->mvid->Fid.Volume == 0) { + if (adp->mvid == (struct VenusFid *)0 || adp->mvid->Fid.Volume == 0) { #ifdef AFS_OSF_ENV extern struct vcache *afs_globalVp; if (adp == afs_globalVp) { @@ -1167,11 +1203,9 @@ afs_lookup(adp, aname, avcp, acred) goto done; } /* otherwise we have the fid here, so we use it */ - tvc = afs_GetVCache(adp->mvid, &treq, (afs_int32 *)0, - (struct vcache*)0, 0); - afs_Trace3(afs_iclSetp, CM_TRACE_GETVCDOTDOT, - ICL_TYPE_FID, adp->mvid, ICL_TYPE_POINTER, tvc, - ICL_TYPE_INT32, code); + tvc = afs_GetVCache(adp->mvid, &treq, NULL, NULL); + afs_Trace3(afs_iclSetp, CM_TRACE_GETVCDOTDOT, ICL_TYPE_FID, adp->mvid, + ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, code); *avcp = tvc; code = (tvc ? 0 : ENOENT); hit = 1; @@ -1179,23 +1213,23 @@ afs_lookup(adp, aname, avcp, acred) osi_Panic("TT1"); } if (code) { - /*printf("LOOKUP GETVCDOTDOT -> %d\n", code);*/ + /*printf("LOOKUP GETVCDOTDOT -> %d\n", code); */ } goto done; } /* now check the access */ - if (treq.uid != adp->last_looker) { - if (!afs_AccessOK(adp, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS)) { - *avcp = (struct vcache *)0; - code = EACCES; - goto done; - } - else adp->last_looker = treq.uid; - } + if (treq.uid != adp->last_looker) { + if (!afs_AccessOK(adp, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS)) { + *avcp = NULL; + code = EACCES; + goto done; + } else + adp->last_looker = treq.uid; + } /* Check for read access as well. We need read access in order to - stat files, but not to stat subdirectories. */ + * stat files, but not to stat subdirectories. */ if (!afs_AccessOK(adp, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS)) no_read_access = 1; @@ -1204,10 +1238,10 @@ afs_lookup(adp, aname, avcp, acred) * I'm not fiddling with the LRUQ here, either, perhaps I should, or else * invent a lightweight version of GetVCache. */ - if (aname[0] == '.' && !aname[1]) { /* special case */ - ObtainReadLock(&afs_xvcache); + if (aname[0] == '.' && !aname[1]) { /* special case */ + ObtainReadLock(&afs_xvcache); osi_vnhold(adp, 0); - ReleaseReadLock(&afs_xvcache); + ReleaseReadLock(&afs_xvcache); code = 0; *avcp = tvc = adp; hit = 1; @@ -1221,28 +1255,27 @@ afs_lookup(adp, aname, avcp, acred) tname = sysState.name; /* 1st Check_AtSys and lookup by tname is required here, for now, - because the dnlc is *not* told to remove entries for the parent - dir of file/dir op that afs_LocalHero likes, but dnlc is informed - if the cached entry for the parent dir is invalidated for a - non-local change. - Otherwise, we'd be able to do a dnlc lookup on an entry ending - w/@sys and know the dnlc was consistent with reality. */ - tvc = osi_dnlc_lookup (adp, tname, WRITE_LOCK); - *avcp = tvc; /* maybe wasn't initialized, but it is now */ + * because the dnlc is *not* told to remove entries for the parent + * dir of file/dir op that afs_LocalHero likes, but dnlc is informed + * if the cached entry for the parent dir is invalidated for a + * non-local change. + * Otherwise, we'd be able to do a dnlc lookup on an entry ending + * w/@sys and know the dnlc was consistent with reality. */ + tvc = osi_dnlc_lookup(adp, tname, WRITE_LOCK); + *avcp = tvc; /* maybe wasn't initialized, but it is now */ if (tvc) { if (no_read_access && vType(tvc) != VDIR && vType(tvc) != VLNK) { /* need read access on dir to stat non-directory / non-link */ - afs_PutVCache(tvc, WRITE_LOCK); - *avcp = (struct vcache *)0; + afs_PutVCache(tvc); + *avcp = NULL; code = EACCES; goto done; } #ifdef AFS_LINUX22_ENV - if (tvc->mvstat == 2) { /* we don't trust the dnlc for root vcaches */ + if (tvc->mvstat == 2) { /* we don't trust the dnlc for root vcaches */ AFS_RELE(tvc); *avcp = 0; - } - else { + } else { code = 0; hit = 1; goto done; @@ -1254,154 +1287,164 @@ afs_lookup(adp, aname, avcp, acred) #endif /* linux22 */ } - { - register struct dcache *tdc; - afs_int32 dirOffset, dirLen; - ino_t theDir; - struct VenusFid tfid; - - /* now we have to lookup the next fid */ - tdc = afs_GetDCache(adp, 0, &treq, &dirOffset, &dirLen, 1); - if (!tdc) { - *avcp = (struct vcache *)0; /* redundant, but harmless */ - code = EIO; - goto done; - } - - /* now we will just call dir package with appropriate inode. - Dirs are always fetched in their entirety for now */ - ObtainReadLock(&adp->lock); + { /* sub-block just to reduce stack usage */ + register struct dcache *tdc; + afs_size_t dirOffset, dirLen; + ino_t theDir; + struct VenusFid tfid; + + /* now we have to lookup the next fid */ + tdc = + afs_GetDCache(adp, (afs_size_t) 0, &treq, &dirOffset, &dirLen, 1); + if (!tdc) { + *avcp = NULL; /* redundant, but harmless */ + code = EIO; + goto done; + } - /* - * Make sure that the data in the cache is current. There are two - * cases we need to worry about: - * 1. The cache data is being fetched by another process. - * 2. The cache data is no longer valid - */ - while ((adp->states & CStatd) - && (tdc->flags & DFFetching) - && hsame(adp->m.DataVersion, tdc->f.versionNo)) { - tdc->flags |= DFWaiting; - ReleaseReadLock(&adp->lock); - afs_osi_Sleep(&tdc->validPos); + /* now we will just call dir package with appropriate inode. + * Dirs are always fetched in their entirety for now */ ObtainReadLock(&adp->lock); - } - if (!(adp->states & CStatd) - || !hsame(adp->m.DataVersion, tdc->f.versionNo)) { - ReleaseReadLock(&adp->lock); - afs_PutDCache(tdc); - goto redo; - } - - /* Save the version number for when we call osi_dnlc_enter */ - hset(versionNo, tdc->f.versionNo); - - /* - * check for, and handle "@sys" if it's there. We should be able - * to avoid the alloc and the strcpy with a little work, but it's - * not pressing. If there aren't any remote users (ie, via the - * NFS translator), we have a slightly easier job. - * the faster way to do this is to check for *aname == '@' and if - * it's there, check for @sys, otherwise, assume there's no @sys - * then, if the lookup fails, check for .*@sys... - */ - /* above now implemented by Check_AtSys and Next_AtSys */ + ObtainReadLock(&tdc->lock); - /* lookup the name in the appropriate dir, and return a cache entry - on the resulting fid */ - theDir = tdc->f.inode; - code = afs_dir_LookupOffset(&theDir, sysState.name, &tfid.Fid, &dirCookie); - - /* If the first lookup doesn't succeed, maybe it's got @sys in the name */ - while (code == ENOENT && Next_AtSys(adp, &treq, &sysState)) { - code = afs_dir_LookupOffset(&theDir, sysState.name, &tfid.Fid, &dirCookie); - } - tname = sysState.name; + /* + * Make sure that the data in the cache is current. There are two + * cases we need to worry about: + * 1. The cache data is being fetched by another process. + * 2. The cache data is no longer valid + */ + while ((adp->states & CStatd) + && (tdc->dflags & DFFetching) + && hsame(adp->m.DataVersion, tdc->f.versionNo)) { + ReleaseReadLock(&tdc->lock); + ReleaseReadLock(&adp->lock); + afs_osi_Sleep(&tdc->validPos); + ObtainReadLock(&adp->lock); + ObtainReadLock(&tdc->lock); + } + if (!(adp->states & CStatd) + || !hsame(adp->m.DataVersion, tdc->f.versionNo)) { + ReleaseReadLock(&tdc->lock); + ReleaseReadLock(&adp->lock); + afs_PutDCache(tdc); + if (tname && tname != aname) + osi_FreeLargeSpace(tname); + goto redo; + } - afs_PutDCache(tdc); + /* Save the version number for when we call osi_dnlc_enter */ + hset(versionNo, tdc->f.versionNo); + + /* + * check for, and handle "@sys" if it's there. We should be able + * to avoid the alloc and the strcpy with a little work, but it's + * not pressing. If there aren't any remote users (ie, via the + * NFS translator), we have a slightly easier job. + * the faster way to do this is to check for *aname == '@' and if + * it's there, check for @sys, otherwise, assume there's no @sys + * then, if the lookup fails, check for .*@sys... + */ + /* above now implemented by Check_AtSys and Next_AtSys */ + + /* lookup the name in the appropriate dir, and return a cache entry + * on the resulting fid */ + theDir = tdc->f.inode; + code = + afs_dir_LookupOffset(&theDir, sysState.name, &tfid.Fid, + &dirCookie); + + /* If the first lookup doesn't succeed, maybe it's got @sys in the name */ + while (code == ENOENT && Next_AtSys(adp, &treq, &sysState)) + code = + afs_dir_LookupOffset(&theDir, sysState.name, &tfid.Fid, + &dirCookie); + tname = sysState.name; + + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); - if (code == ENOENT && afs_IsDynroot(adp) && dynrootRetry) { - ReleaseReadLock(&adp->lock); - dynrootRetry = 0; - if (tname[0] == '.') - afs_LookupAFSDB(tname + 1); - else - afs_LookupAFSDB(tname); - if (tname && tname != aname) osi_FreeLargeSpace(tname); - goto redo; - } else { - ReleaseReadLock(&adp->lock); - } + if (code == ENOENT && afs_IsDynroot(adp) && dynrootRetry) { + ReleaseReadLock(&adp->lock); + dynrootRetry = 0; + if (tname[0] == '.') + afs_LookupAFSDB(tname + 1); + else + afs_LookupAFSDB(tname); + if (tname && tname != aname) + osi_FreeLargeSpace(tname); + goto redo; + } else { + ReleaseReadLock(&adp->lock); + } - /* new fid has same cell and volume */ - tfid.Cell = adp->fid.Cell; - tfid.Fid.Volume = adp->fid.Fid.Volume; - afs_Trace4(afs_iclSetp, CM_TRACE_LOOKUP, ICL_TYPE_POINTER, adp, - ICL_TYPE_STRING, tname, - ICL_TYPE_FID, &tfid, ICL_TYPE_INT32, code); + /* new fid has same cell and volume */ + tfid.Cell = adp->fid.Cell; + tfid.Fid.Volume = adp->fid.Fid.Volume; + afs_Trace4(afs_iclSetp, CM_TRACE_LOOKUP, ICL_TYPE_POINTER, adp, + ICL_TYPE_STRING, tname, ICL_TYPE_FID, &tfid, + ICL_TYPE_INT32, code); - if (code) { - if (code != ENOENT) { - printf("LOOKUP dirLookupOff -> %d\n", code); + if (code) { + if (code != ENOENT) { + printf("LOOKUP dirLookupOff -> %d\n", code); + } + goto done; } - goto done; - } - /* prefetch some entries, if the dir is currently open. The variable - * dirCookie tells us where to start prefetching from. - */ - if (AFSDOBULK && adp->opens > 0 && !(adp->states & CForeign) && !afs_IsDynroot(adp)) { - afs_int32 retry; - /* if the entry is not in the cache, or is in the cache, - * but hasn't been statd, then do a bulk stat operation. + /* prefetch some entries, if the dir is currently open. The variable + * dirCookie tells us where to start prefetching from. */ - do { - retry = 0; - ObtainReadLock(&afs_xvcache); - tvc = afs_FindVCache(&tfid, 1, 0, &retry, 0/* !stats,!lru */); - ReleaseReadLock(&afs_xvcache); - } while (tvc && retry); - - if (!tvc || !(tvc->states & CStatd)) - bulkcode = afs_DoBulkStat(adp, dirCookie, &treq); - else + if (AFSDOBULK && adp->opens > 0 && !(adp->states & CForeign) + && !afs_IsDynroot(adp)) { + afs_int32 retry; + /* if the entry is not in the cache, or is in the cache, + * but hasn't been statd, then do a bulk stat operation. + */ + do { + retry = 0; + ObtainReadLock(&afs_xvcache); + tvc = afs_FindVCache(&tfid, &retry, 0 /* !stats,!lru */ ); + ReleaseReadLock(&afs_xvcache); + } while (tvc && retry); + + if (!tvc || !(tvc->states & CStatd)) + bulkcode = afs_DoBulkStat(adp, dirCookie, &treq); + else + bulkcode = 0; + + /* if the vcache isn't usable, release it */ + if (tvc && !(tvc->states & CStatd)) { + afs_PutVCache(tvc); + tvc = NULL; + } + } else { + tvc = NULL; bulkcode = 0; - - /* if the vcache isn't usable, release it */ - if (tvc && !(tvc->states & CStatd)) { - afs_PutVCache(tvc); - tvc = (struct vcache *) 0; } - } else { - tvc = (struct vcache *) 0; - bulkcode = 0; - } - /* now get the status info, if we don't already have it */ - /* This is kind of weird, but we might wind up accidentally calling - * RXAFS_Lookup because we happened upon a file which legitimately - * has a 0 uniquifier. That is the result of allowing unique to wrap - * to 0. This was fixed in AFS 3.4. For CForeign, Unique == 0 means that - * the file has not yet been looked up. - */ - if (!tvc) { - afs_int32 cached = 0; - if (!tfid.Fid.Unique && (adp->states & CForeign)) { - tvc = afs_LookupVCache(&tfid, &treq, &cached, WRITE_LOCK, - adp, tname); - } - if (!tvc && !bulkcode) { /* lookup failed or wasn't called */ - tvc = afs_GetVCache(&tfid, &treq, &cached, (struct vcache*)0, - WRITE_LOCK); - } - } /* if !tvc */ - } /* sub-block just to reduce stack usage */ + /* now get the status info, if we don't already have it */ + /* This is kind of weird, but we might wind up accidentally calling + * RXAFS_Lookup because we happened upon a file which legitimately + * has a 0 uniquifier. That is the result of allowing unique to wrap + * to 0. This was fixed in AFS 3.4. For CForeign, Unique == 0 means that + * the file has not yet been looked up. + */ + if (!tvc) { + afs_int32 cached = 0; + if (!tfid.Fid.Unique && (adp->states & CForeign)) { + tvc = afs_LookupVCache(&tfid, &treq, &cached, adp, tname); + } + if (!tvc && !bulkcode) { /* lookup failed or wasn't called */ + tvc = afs_GetVCache(&tfid, &treq, &cached, NULL); + } + } /* if !tvc */ + } /* sub-block just to reduce stack usage */ if (tvc) { int force_eval = afs_fakestat_enable ? 0 : 1; if (adp->states & CForeign) - tvc->states |= CForeign; + tvc->states |= CForeign; tvc->parentVnode = adp->fid.Fid.Vnode; tvc->parentUnique = adp->fid.Fid.Unique; tvc->states &= ~CBulkStat; @@ -1420,88 +1463,89 @@ afs_lookup(adp, aname, avcp, acred) force_eval = 1; ReleaseReadLock(&tvc->lock); } - #if defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS) - if (!(flags & AFS_LOOKUP_NOEVAL)) - /* don't eval mount points */ + if (!(flags & AFS_LOOKUP_NOEVAL)) + /* don't eval mount points */ #endif /* UKERNEL && AFS_WEB_ENHANCEMENTS */ - if (tvc->mvstat == 1 && force_eval) { - /* a mt point, possibly unevaluated */ - struct volume *tvolp; + if (tvc->mvstat == 1 && force_eval) { + /* a mt point, possibly unevaluated */ + struct volume *tvolp; - ObtainWriteLock(&tvc->lock,133); - code = EvalMountPoint(tvc, adp, &tvolp, &treq); - ReleaseWriteLock(&tvc->lock); - - if (code) { - afs_PutVCache(tvc, WRITE_LOCK); - if (tvolp) afs_PutVolume(tvolp, WRITE_LOCK); - goto done; - } + ObtainWriteLock(&tvc->lock, 133); + code = EvalMountPoint(tvc, adp, &tvolp, &treq); + ReleaseWriteLock(&tvc->lock); - /* next, we want to continue using the target of the mt point */ - if (tvc->mvid && (tvc->states & CMValid)) { - struct vcache *uvc; - /* now lookup target, to set .. pointer */ - afs_Trace2(afs_iclSetp, CM_TRACE_LOOKUP1, - ICL_TYPE_POINTER, tvc, ICL_TYPE_FID, &tvc->fid); - uvc = tvc; /* remember for later */ - - if (tvolp && (tvolp->states & VForeign)) { - /* XXXX tvolp has ref cnt on but not locked! XXX */ - tvc = afs_GetRootVCache(tvc->mvid, &treq, (afs_int32 *)0, tvolp, WRITE_LOCK); - } else { - tvc = afs_GetVCache(tvc->mvid, &treq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + if (code) { + afs_PutVCache(tvc); + if (tvolp) + afs_PutVolume(tvolp, WRITE_LOCK); + goto done; } - afs_PutVCache(uvc, WRITE_LOCK); /* we're done with it */ - if (!tvc) { - code = ENOENT; + /* next, we want to continue using the target of the mt point */ + if (tvc->mvid && (tvc->states & CMValid)) { + struct vcache *uvc; + /* now lookup target, to set .. pointer */ + afs_Trace2(afs_iclSetp, CM_TRACE_LOOKUP1, + ICL_TYPE_POINTER, tvc, ICL_TYPE_FID, + &tvc->fid); + uvc = tvc; /* remember for later */ + + if (tvolp && (tvolp->states & VForeign)) { + /* XXXX tvolp has ref cnt on but not locked! XXX */ + tvc = + afs_GetRootVCache(tvc->mvid, &treq, NULL, tvolp); + } else { + tvc = afs_GetVCache(tvc->mvid, &treq, NULL, NULL); + } + afs_PutVCache(uvc); /* we're done with it */ + + if (!tvc) { + code = ENOENT; + if (tvolp) { + afs_PutVolume(tvolp, WRITE_LOCK); + } + goto done; + } + + /* now, if we came via a new mt pt (say because of a new + * release of a R/O volume), we must reevaluate the .. + * ptr to point back to the appropriate place */ if (tvolp) { + ObtainWriteLock(&tvc->lock, 134); + if (tvc->mvid == NULL) { + tvc->mvid = (struct VenusFid *) + osi_AllocSmallSpace(sizeof(struct VenusFid)); + } + /* setup backpointer */ + *tvc->mvid = tvolp->dotdot; + ReleaseWriteLock(&tvc->lock); afs_PutVolume(tvolp, WRITE_LOCK); } + } else { + afs_PutVCache(tvc); + code = ENOENT; + if (tvolp) + afs_PutVolume(tvolp, WRITE_LOCK); goto done; } - - /* now, if we came via a new mt pt (say because of a new - * release of a R/O volume), we must reevaluate the .. - * ptr to point back to the appropriate place */ - if (tvolp) { - ObtainWriteLock(&tvc->lock,134); - if (tvc->mvid == (struct VenusFid *) 0) { - tvc->mvid = (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid)); - } - /* setup backpointer */ - *tvc->mvid = tvolp->dotdot; - ReleaseWriteLock(&tvc->lock); - afs_PutVolume(tvolp, WRITE_LOCK); - } } - else { - afs_PutVCache(tvc, WRITE_LOCK); - code = ENOENT; - if (tvolp) afs_PutVolume(tvolp, WRITE_LOCK); - goto done; - } - } *avcp = tvc; if (tvc && !VREFCOUNT(tvc)) { osi_Panic("TT3"); } code = 0; - } - else { + } else { /* if we get here, we found something in a directory that couldn't - be located (a Multics "connection failure"). If the volume is - read-only, we try flushing this entry from the cache and trying - again. */ + * be located (a Multics "connection failure"). If the volume is + * read-only, we try flushing this entry from the cache and trying + * again. */ if (pass == 0) { struct volume *tv; tv = afs_GetVolume(&adp->fid, &treq, READ_LOCK); if (tv) { if (tv->states & VRO) { - pass = 1; /* try this *once* */ + pass = 1; /* try this *once* */ ObtainWriteLock(&afs_xcbhash, 495); afs_DequeueCallback(adp); /* re-stat to get later version */ @@ -1517,52 +1561,54 @@ afs_lookup(adp, aname, avcp, acred) code = ENOENT; } -done: + done: /* put the network buffer back, if need be */ - if (tname != aname && tname) osi_FreeLargeSpace(tname); + if (tname != aname && tname) + osi_FreeLargeSpace(tname); if (code == 0) { #ifdef AFS_OSF_ENV /* Handle RENAME; only need to check rename "." */ if (opflag == RENAME && wantparent && *ndp->ni_next == 0) { - if (!FidCmp(&(tvc->fid), &(adp->fid))) { - afs_PutVCache(*avcp, WRITE_LOCK); + if (!FidCmp(&(tvc->fid), &(adp->fid))) { + afs_PutVCache(*avcp); *avcp = NULL; afs_PutFakeStat(&fakestate); return afs_CheckCode(EISDIR, &treq, 18); } } -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ if (afs_mariner) - afs_AddMarinerName(aname, tvc); + afs_AddMarinerName(aname, tvc); #if defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS) - if (!(flags & AFS_LOOKUP_NOEVAL)) - /* Here we don't enter the name into the DNLC because we want the - evaluated mount dir to be there (the vcache for the mounted volume) - rather than the vc of the mount point itself. we can still find the - mount point's vc in the vcache by its fid. */ + if (!(flags & AFS_LOOKUP_NOEVAL)) + /* Here we don't enter the name into the DNLC because we want the + * evaluated mount dir to be there (the vcache for the mounted volume) + * rather than the vc of the mount point itself. we can still find the + * mount point's vc in the vcache by its fid. */ #endif /* UKERNEL && AFS_WEB_ENHANCEMENTS */ - if (!hit) { - osi_dnlc_enter (adp, aname, tvc, &versionNo); - } - else { + if (!hit) { + osi_dnlc_enter(adp, aname, tvc, &versionNo); + } else { #ifdef AFS_LINUX20_ENV - /* So Linux inode cache is up to date. */ - code = afs_VerifyVCache(tvc, &treq); + /* So Linux inode cache is up to date. */ + code = afs_VerifyVCache(tvc, &treq); #else - afs_PutFakeStat(&fakestate); - return 0; /* can't have been any errors if hit and !code */ + afs_PutFakeStat(&fakestate); + return 0; /* can't have been any errors if hit and !code */ #endif - } + } } - if (bulkcode) code = bulkcode; else - code = afs_CheckCode(code, &treq, 19); + if (bulkcode) + code = bulkcode; + else + code = afs_CheckCode(code, &treq, 19); if (code) { - /* If there is an error, make sure *avcp is null. - * Alphas panic otherwise - defect 10719. - */ - *avcp = (struct vcache *)0; + /* If there is an error, make sure *avcp is null. + * Alphas panic otherwise - defect 10719. + */ + *avcp = NULL; } afs_PutFakeStat(&fakestate); diff --git a/src/afs/VNOPS/afs_vnop_open.c b/src/afs/VNOPS/afs_vnop_open.c index 30b0de0eb..4e5f41f26 100644 --- a/src/afs/VNOPS/afs_vnop_open.c +++ b/src/afs/VNOPS/afs_vnop_open.c @@ -15,16 +15,17 @@ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_open.c,v 1.1.1.6 2002/08/02 04:29:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_open.c,v 1.10 2003/07/15 23:14:30 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" @@ -32,24 +33,23 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_open.c,v 1.1.1.6 200 * checks are done here, instead they're done by afs_create or afs_access, * both called by the vn_open call. */ +int #ifdef AFS_SGI64_ENV -afs_open(bhv, avcp, aflags, acred) - bhv_desc_t *bhv; +afs_open(bhv_desc_t * bhv, struct vcache **avcp, afs_int32 aflags, + struct AFS_UCRED *acred) #else -afs_open(avcp, aflags, acred) +afs_open(struct vcache **avcp, afs_int32 aflags, struct AFS_UCRED *acred) #endif - register struct vcache **avcp; - afs_int32 aflags; - struct AFS_UCRED *acred; { register afs_int32 code; struct vrequest treq; struct vcache *tvc; int writing; struct afs_fakestat_state fakestate; - + AFS_STATCNT(afs_open); - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; #ifdef AFS_SGI64_ENV /* avcpp can be, but is not necesarily, bhp's vnode. */ tvc = VTOAFS(BHV_TO_VNODE(bhv)); @@ -60,31 +60,34 @@ afs_open(avcp, aflags, acred) ICL_TYPE_INT32, aflags); afs_InitFakeStat(&fakestate); code = afs_EvalFakeStat(&tvc, &fakestate, &treq); - if (code) goto done; + if (code) + goto done; code = afs_VerifyVCache(tvc, &treq); - if (code) goto done; - if (aflags & (FWRITE | FTRUNC)) writing = 1; - else writing = 0; + if (code) + goto done; + if (aflags & (FWRITE | FTRUNC)) + writing = 1; + else + writing = 0; if (vType(tvc) == VDIR) { /* directory */ if (writing) { code = EISDIR; goto done; - } - else { - if (!afs_AccessOK(tvc, - ((tvc->states & CForeign) ? PRSFS_READ: PRSFS_LOOKUP), - &treq, CHECK_MODE_BITS)) { + } else { + if (!afs_AccessOK + (tvc, ((tvc->states & CForeign) ? PRSFS_READ : PRSFS_LOOKUP), + &treq, CHECK_MODE_BITS)) { code = EACCES; goto done; } } - } - else { + } else { #ifdef AFS_SUN5_ENV - if (AFS_NFSXLATORREQ(acred) && (aflags & FREAD)) { - if (!afs_AccessOK(tvc, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) { + if (AFS_NFSXLATORREQ(acred) && (aflags & FREAD)) { + if (!afs_AccessOK + (tvc, PRSFS_READ, &treq, + CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) { code = EACCES; goto done; } @@ -94,32 +97,32 @@ afs_open(avcp, aflags, acred) if (aflags & FRSHARE) { /* * Hack for AIX 4.1: - * Apparently it is possible for a file to get mapped without - * either VNOP_MAP or VNOP_RDWR being called, if (1) it is a - * sharable library, and (2) it has already been loaded. We must - * ensure that the credp is up to date. We detect the situation - * by checking for O_RSHARE at open time. + * Apparently it is possible for a file to get mapped without + * either VNOP_MAP or VNOP_RDWR being called, if (1) it is a + * sharable library, and (2) it has already been loaded. We must + * ensure that the credp is up to date. We detect the situation + * by checking for O_RSHARE at open time. */ /* * We keep the caller's credentials since an async daemon will * handle the request at some point. We assume that the same * credentials will be used. */ - ObtainWriteLock(&tvc->lock,140); + ObtainWriteLock(&tvc->lock, 140); if (!tvc->credp || (tvc->credp != acred)) { - crhold(acred); - if (tvc->credp) { - struct ucred *crp = tvc->credp; - tvc->credp = (struct ucred *)0; - crfree(crp); - } - tvc->credp = acred; + crhold(acred); + if (tvc->credp) { + struct ucred *crp = tvc->credp; + tvc->credp = NULL; + crfree(crp); + } + tvc->credp = acred; } ReleaseWriteLock(&tvc->lock); } #endif /* normal file or symlink */ - osi_FlushText(tvc); /* only needed to flush text if text locked last time */ + osi_FlushText(tvc); /* only needed to flush text if text locked last time */ #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonLock(&tvc->pvnLock, tvc); #endif @@ -131,13 +134,14 @@ afs_open(avcp, aflags, acred) /* set date on file if open in O_TRUNC mode */ if (aflags & FTRUNC) { /* this fixes touch */ - ObtainWriteLock(&tvc->lock,123); + ObtainWriteLock(&tvc->lock, 123); tvc->m.Date = osi_Time(); tvc->states |= CDirty; ReleaseWriteLock(&tvc->lock); } ObtainReadLock(&tvc->lock); - if (writing) tvc->execsOrWriters++; + if (writing) + tvc->execsOrWriters++; tvc->opens++; #if defined(AFS_SGI_ENV) if (writing && tvc->cred == NULL) { @@ -146,9 +150,9 @@ afs_open(avcp, aflags, acred) } #endif ReleaseReadLock(&tvc->lock); -done: + done: afs_PutFakeStat(&fakestate); - code = afs_CheckCode(code, &treq, 4); /* avoid AIX -O bug */ + code = afs_CheckCode(code, &treq, 4); /* avoid AIX -O bug */ afs_Trace2(afs_iclSetp, CM_TRACE_OPEN, ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, 999999); diff --git a/src/afs/VNOPS/afs_vnop_read.c b/src/afs/VNOPS/afs_vnop_read.c index 12e7f4260..960d2aadf 100644 --- a/src/afs/VNOPS/afs_vnop_read.c +++ b/src/afs/VNOPS/afs_vnop_read.c @@ -11,57 +11,56 @@ * Implements: * afs_MemRead * afs_PrefetchChunk - * afs_UFSReadFast * afs_UFSRead * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_read.c,v 1.1.1.7 2002/09/26 18:58:24 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_read.c,v 1.25 2003/08/27 21:43:19 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern char afs_zeros[AFS_ZEROS]; afs_int32 maxIHint; -afs_int32 nihints; /* # of above actually in-use */ +afs_int32 nihints; /* # of above actually in-use */ afs_int32 usedihint; /* Imported variables */ extern afs_rwlock_t afs_xdcache; extern unsigned char *afs_indexFlags; -extern afs_hyper_t *afs_indexTimes; /* Dcache entry Access times */ -extern afs_hyper_t afs_indexCounter; /* Fake time for marking index */ +extern afs_hyper_t *afs_indexTimes; /* Dcache entry Access times */ +extern afs_hyper_t afs_indexCounter; /* Fake time for marking index */ /* Forward declarations */ void afs_PrefetchChunk(struct vcache *avc, struct dcache *adc, - struct AFS_UCRED *acred, struct vrequest *areq); - -afs_MemRead(avc, auio, acred, albn, abpp, noLock) - register struct vcache *avc; - struct uio *auio; - struct AFS_UCRED *acred; - daddr_t albn; - int noLock; - struct buf **abpp; { - afs_int32 totalLength; - afs_int32 transferLength; - afs_int32 filePos; - struct dcache *tdc=0; - afs_int32 offset, len, error, trybusy=1; + struct AFS_UCRED *acred, struct vrequest *areq); + +int +afs_MemRead(register struct vcache *avc, struct uio *auio, + struct AFS_UCRED *acred, daddr_t albn, struct buf **abpp, + int noLock) +{ + afs_size_t totalLength; + afs_size_t transferLength; + afs_size_t filePos; + afs_size_t offset, len, tlen; + afs_int32 trimlen; + struct dcache *tdc = 0; + afs_int32 error, trybusy = 1; struct uio tuio; struct iovec *tvec; - char *tfile; afs_int32 code; struct vrequest treq; @@ -70,30 +69,32 @@ afs_MemRead(avc, auio, acred, albn, abpp, noLock) return EIO; /* check that we have the latest status info in the vnode cache */ - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; if (!noLock) { code = afs_VerifyVCache(avc, &treq); if (code) { - code = afs_CheckCode(code, &treq, 8); /* failed to get it */ - return code; + code = afs_CheckCode(code, &treq, 8); /* failed to get it */ + return code; } } - #ifndef AFS_VM_RDWR_ENV if (AFS_NFSXLATORREQ(acred)) { - if (!afs_AccessOK(avc, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) { + if (!afs_AccessOK + (avc, PRSFS_READ, &treq, + CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) { return afs_CheckCode(EACCES, &treq, 9); } } #endif - tvec = (struct iovec *) osi_AllocSmallSpace(sizeof(struct iovec)); + tvec = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec)); totalLength = auio->afsio_resid; filePos = auio->afsio_offset; - afs_Trace4(afs_iclSetp, CM_TRACE_READ, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, filePos, ICL_TYPE_INT32, totalLength, - ICL_TYPE_INT32, avc->m.Length); + afs_Trace4(afs_iclSetp, CM_TRACE_READ, ICL_TYPE_POINTER, avc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(filePos), ICL_TYPE_INT32, + totalLength, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length)); error = 0; transferLength = 0; if (!noLock) @@ -103,142 +104,217 @@ afs_MemRead(avc, auio, acred, albn, abpp, noLock) hset(avc->flushDV, avc->m.DataVersion); } #endif + + /* + * Locks held: + * avc->lock(R) + */ while (totalLength > 0) { /* read all of the cached info */ - if (filePos >= avc->m.Length) break; /* all done */ + if (filePos >= avc->m.Length) + break; /* all done */ if (noLock) { - if (tdc) afs_PutDCache(tdc); + if (tdc) { + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); + } tdc = afs_FindDCache(avc, filePos); if (tdc) { + ObtainReadLock(&tdc->lock); offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); len = tdc->f.chunkBytes - offset; } } else { /* a tricky question: does the presence of the DFFetching flag - mean that we're fetching the latest version of the file? No. - The server could update the file as soon as the fetch responsible - for the setting of the DFFetching flag completes. - - However, the presence of the DFFetching flag (visible under a - read lock since it is set and cleared only under a write lock) - means that we're fetching as good a version as was known to this - client at the time of the last call to afs_VerifyVCache, since - the latter updates the stat cache's m.DataVersion field under a - write lock, and from the time that the DFFetching flag goes on - (before the fetch starts), to the time it goes off (after the - fetch completes), afs_GetDCache keeps at least a read lock - (actually it keeps an S lock) on the cache entry. - - This means that if the DFFetching flag is set, we can use that - data for any reads that must come from the current version of - the file (current == m.DataVersion). - - Another way of looking at this same point is this: if we're - fetching some data and then try do an afs_VerifyVCache, the - VerifyVCache operation will not complete until after the - DFFetching flag is turned off and the dcache entry's f.versionNo - field is updated. - - Note, by the way, that if DFFetching is set, - m.DataVersion > f.versionNo (the latter is not updated until - after the fetch completes). + * mean that we're fetching the latest version of the file? No. + * The server could update the file as soon as the fetch responsible + * for the setting of the DFFetching flag completes. + * + * However, the presence of the DFFetching flag (visible under + * a dcache read lock since it is set and cleared only under a + * dcache write lock) means that we're fetching as good a version + * as was known to this client at the time of the last call to + * afs_VerifyVCache, since the latter updates the stat cache's + * m.DataVersion field under a vcache write lock, and from the + * time that the DFFetching flag goes on in afs_GetDCache (before + * the fetch starts), to the time it goes off (after the fetch + * completes), afs_GetDCache keeps at least a read lock on the + * vcache entry. + * + * This means that if the DFFetching flag is set, we can use that + * data for any reads that must come from the current version of + * the file (current == m.DataVersion). + * + * Another way of looking at this same point is this: if we're + * fetching some data and then try do an afs_VerifyVCache, the + * VerifyVCache operation will not complete until after the + * DFFetching flag is turned off and the dcache entry's f.versionNo + * field is updated. + * + * Note, by the way, that if DFFetching is set, + * m.DataVersion > f.versionNo (the latter is not updated until + * after the fetch completes). */ - if (tdc) afs_PutDCache(tdc); /* before reusing tdc */ + if (tdc) { + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); /* before reusing tdc */ + } tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 2); + ObtainReadLock(&tdc->lock); /* now, first try to start transfer, if we'll need the data. If * data already coming, we don't need to do this, obviously. Type * 2 requests never return a null dcache entry, btw. */ - if (!(tdc->flags & DFFetching) + if (!(tdc->dflags & DFFetching) && !hsame(avc->m.DataVersion, tdc->f.versionNo)) { /* have cache entry, it is not coming in now, * and we'll need new data */ -tagain: + tagain: if (trybusy && !afs_BBusy()) { struct brequest *bp; /* daemon is not busy */ - if (!(tdc->flags & DFFetchReq)) { + ObtainSharedLock(&tdc->mflock, 665); + if (!(tdc->mflags & DFFetchReq)) { /* start the daemon (may already be running, however) */ - tdc->flags |= DFFetchReq; + UpgradeSToWLock(&tdc->mflock, 666); + tdc->mflags |= DFFetchReq; bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred, - (long)filePos, (long) tdc, 0L, 0L); + (afs_size_t) filePos, (afs_size_t) 0, + tdc); if (!bp) { - tdc->flags &= ~DFFetchReq; + tdc->mflags &= ~DFFetchReq; trybusy = 0; /* Avoid bkg daemon since they're too busy */ + ReleaseWriteLock(&tdc->mflock); goto tagain; } + ConvertWToSLock(&tdc->mflock); /* don't use bp pointer! */ } - while (tdc->flags & DFFetchReq) { + code = 0; + ConvertSToRLock(&tdc->mflock); + while (!code && tdc->mflags & DFFetchReq) { + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, + ICL_TYPE_STRING, __FILE__, ICL_TYPE_INT32, + __LINE__, ICL_TYPE_POINTER, tdc, + ICL_TYPE_INT32, tdc->dflags); /* don't need waiting flag on this one */ + ReleaseReadLock(&tdc->mflock); + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); - afs_osi_Sleep(&tdc->validPos); + code = afs_osi_SleepSig(&tdc->validPos); ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); + ObtainReadLock(&tdc->mflock); + } + ReleaseReadLock(&tdc->mflock); + if (code) { + error = code; + break; } } } /* now data may have started flowing in (if DFFetching is on). If - * data is now streaming in, then wait for some interesting stuff. */ - while ((tdc->flags & DFFetching) && tdc->validPos <= filePos) { - /* too early: wait for DFFetching flag to vanish, or data to appear */ - tdc->flags |= DFWaiting; + * data is now streaming in, then wait for some interesting stuff. + */ + code = 0; + while (!code && (tdc->dflags & DFFetching) + && tdc->validPos <= filePos) { + /* too early: wait for DFFetching flag to vanish, + * or data to appear */ + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, + ICL_TYPE_POINTER, tdc, ICL_TYPE_INT32, + tdc->dflags); + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); - afs_osi_Sleep(&tdc->validPos); + code = afs_osi_SleepSig(&tdc->validPos); ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); } - /* fetching flag gone, data is here, or we never tried (BBusy for instance) */ - if (tdc->flags & DFFetching) { - /* still fetching, some new data is here: compute length and offset */ + if (code) { + error = code; + break; + } + /* fetching flag gone, data is here, or we never tried + * (BBusy for instance) */ + if (tdc->dflags & DFFetching) { + /* still fetching, some new data is here: + * compute length and offset */ offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); len = tdc->validPos - filePos; - } - else { - /* no longer fetching, verify data version (avoid new GetDCache call) */ - if (hsame(avc->m.DataVersion, tdc->f.versionNo)) { + } else { + /* no longer fetching, verify data version + * (avoid new GetDCache call) */ + if (hsame(avc->m.DataVersion, tdc->f.versionNo) + && ((len = tdc->validPos - filePos) > 0)) { offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); - len = tdc->f.chunkBytes - offset; - } - else { + } else { /* don't have current data, so get it below */ + afs_Trace3(afs_iclSetp, CM_TRACE_VERSIONNO, + ICL_TYPE_INT64, ICL_HANDLE_OFFSET(filePos), + ICL_TYPE_HYPER, &avc->m.DataVersion, + ICL_TYPE_HYPER, &tdc->f.versionNo); + ReleaseReadLock(&tdc->lock); afs_PutDCache(tdc); - tdc = (struct dcache *) 0; + tdc = NULL; } } if (!tdc) { + /* If we get, it was not possible to start the + * background daemon. With flag == 1 afs_GetDCache + * does the FetchData rpc synchronously. + */ ReleaseReadLock(&avc->lock); tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 1); ObtainReadLock(&avc->lock); + if (tdc) + ObtainReadLock(&tdc->lock); } } + afs_Trace3(afs_iclSetp, CM_TRACE_VNODEREAD, ICL_TYPE_POINTER, tdc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(offset), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(len)); if (!tdc) { error = EIO; break; } - if (len > totalLength) len = totalLength; /* will read len bytes */ - if (len <= 0) { /* shouldn't get here if DFFetching is on */ + + /* + * Locks held: + * avc->lock(R) + * tdc->lock(R) + */ + + if (len > totalLength) + len = totalLength; /* will read len bytes */ + if (len <= 0) { /* shouldn't get here if DFFetching is on */ /* read past the end of a chunk, may not be at next chunk yet, and yet - also not at eof, so may have to supply fake zeros */ - len = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset; /* bytes left in chunk addr space */ - if (len > totalLength) len = totalLength; /* and still within xfr request */ - code = avc->m.Length - offset; /* and still within file */ - if (len > code) len = code; - if (len > AFS_ZEROS) len = sizeof(afs_zeros); /* and in 0 buffer */ + * also not at eof, so may have to supply fake zeros */ + len = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset; /* bytes left in chunk addr space */ + if (len > totalLength) + len = totalLength; /* and still within xfr request */ + tlen = avc->m.Length - offset; /* and still within file */ + if (len > tlen) + len = tlen; + if (len > AFS_ZEROS) + len = sizeof(afs_zeros); /* and in 0 buffer */ afsio_copy(auio, &tuio, tvec); - afsio_trim(&tuio, len); - AFS_UIOMOVE(afs_zeros, len, UIO_READ, &tuio, code); + trimlen = len; + afsio_trim(&tuio, trimlen); + AFS_UIOMOVE(afs_zeros, trimlen, UIO_READ, &tuio, code); if (code) { error = code; break; } - } - else { + } else { /* get the data from the mem cache */ /* mung uio structure to be right for this transfer */ afsio_copy(auio, &tuio, tvec); - afsio_trim(&tuio, len); + trimlen = len; + afsio_trim(&tuio, trimlen); tuio.afsio_offset = offset; code = afs_MemReadUIO(tdc->f.inode, &tuio); @@ -249,23 +325,32 @@ tagain: } } /* otherwise we've read some, fixup length, etc and continue with next seg */ - len = len - tuio.afsio_resid; /* compute amount really transferred */ - afsio_skip(auio, len); /* update input uio structure */ + len = len - tuio.afsio_resid; /* compute amount really transferred */ + trimlen = len; + afsio_skip(auio, trimlen); /* update input uio structure */ totalLength -= len; transferLength += len; filePos += len; - if (len <= 0) break; /* surprise eof */ - } /* the whole while loop */ + if (len <= 0) + break; /* surprise eof */ + } /* the whole while loop */ + + /* + * Locks held: + * avc->lock(R) + * tdc->lock(R) if tdc + */ /* if we make it here with tdc non-zero, then it is the last chunk we * dealt with, and we have to release it when we're done. We hold on * to it in case we need to do a prefetch. */ if (tdc) { -#ifndef AFS_VM_RDWR_ENV + ReleaseReadLock(&tdc->lock); +#if !defined(AFS_VM_RDWR_ENV) /* try to queue prefetch, if needed */ - if (!(tdc->flags & DFNextStarted) && !noLock) { + if (!noLock) { afs_PrefetchChunk(avc, tdc, acred, &treq); } #endif @@ -284,217 +369,89 @@ tagain: * flag in the prefetched block, so that the next call to read knows to wait * for the daemon to start doing things. * - * This function must be called with the vnode at least read-locked - * because it plays around with dcache entries. + * This function must be called with the vnode at least read-locked, and + * no locks on the dcache, because it plays around with dcache entries. */ -void afs_PrefetchChunk(struct vcache *avc, struct dcache *adc, - struct AFS_UCRED *acred, struct vrequest *areq) +void +afs_PrefetchChunk(struct vcache *avc, struct dcache *adc, + struct AFS_UCRED *acred, struct vrequest *areq) { register struct dcache *tdc; - register afs_int32 offset; - afs_int32 j1, j2; /* junk vbls for GetDCache to trash */ - - offset = adc->f.chunk+1; /* next chunk we'll need */ - offset = AFS_CHUNKTOBASE(offset); /* base of next chunk */ - if (offset < avc->m.Length && !afs_BBusy()) { + afs_size_t offset; + afs_size_t j1, j2; /* junk vbls for GetDCache to trash */ + + offset = adc->f.chunk + 1; /* next chunk we'll need */ + offset = AFS_CHUNKTOBASE(offset); /* base of next chunk */ + ObtainReadLock(&adc->lock); + ObtainSharedLock(&adc->mflock, 662); + if (offset < avc->m.Length && !(adc->mflags & DFNextStarted) + && !afs_BBusy()) { struct brequest *bp; - adc->flags |= DFNextStarted; /* we've tried to prefetch for this guy */ + + UpgradeSToWLock(&adc->mflock, 663); + adc->mflags |= DFNextStarted; /* we've tried to prefetch for this guy */ + ReleaseWriteLock(&adc->mflock); + ReleaseReadLock(&adc->lock); + tdc = afs_GetDCache(avc, offset, areq, &j1, &j2, 2); /* type 2 never returns 0 */ - if (!(tdc->flags & DFFetchReq)) { + ObtainSharedLock(&tdc->mflock, 651); + if (!(tdc->mflags & DFFetchReq)) { /* ask the daemon to do the work */ - tdc->flags |= DFFetchReq; /* guaranteed to be cleared by BKG or GetDCache */ + UpgradeSToWLock(&tdc->mflock, 652); + tdc->mflags |= DFFetchReq; /* guaranteed to be cleared by BKG or GetDCache */ /* last parm (1) tells bkg daemon to do an afs_PutDCache when it is done, * since we don't want to wait for it to finish before doing so ourselves. */ -#ifdef AFS_SUN5_ENVX - mutex_exit(&tdc->lock); -#endif - bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred, (long)offset, - (long) tdc, 1L, 0L, 0L); + bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred, + (afs_size_t) offset, (afs_size_t) 1, tdc); if (!bp) { /* Bkg table full; just abort non-important prefetching to avoid deadlocks */ - tdc->flags &= ~(DFNextStarted | DFFetchReq); + tdc->mflags &= ~DFFetchReq; + ReleaseWriteLock(&tdc->mflock); afs_PutDCache(tdc); - return; - } - } - else - afs_PutDCache(tdc); - } -} - - -/* if the vcache is up-to-date, and the request fits entirely into the chunk - * that the hint here references, then we just use it quickly, otherwise we - * have to call the slow read. - * - * This could be generalized in several ways to take advantage of partial - * state even when all the chips don't fall the right way. For instance, - * if the hint is good and the first part of the read request can be - * satisfied from the chunk, then just do the read. After the read has - * completed, check to see if there's more. (Chances are there won't be.) - * If there is more, then just call afs_UFSReadSlow and let it do the rest. - * - * For the time being, I'm ignoring quick.f, but it should be used at - * some future date. - * do this in the future avc->quick.f = tfile; but I think it - * has to be done under a write lock, but don't want to wait on the - * write lock - */ - /* everywhere that a dcache can be freed (look for NULLIDX) - * probably does it under a write lock on xdcache. Need to invalidate - * stamp there, too. - * Also need to worry about DFFetching, and IFFree, I think. */ -static struct dcache *savedc = 0; - -afs_UFSReadFast(avc, auio, acred, albn, abpp, noLock) - register struct vcache *avc; - struct uio *auio; - struct AFS_UCRED *acred; - int noLock; - daddr_t albn; - struct buf **abpp; { - struct vrequest treq; - int offDiff; - struct dcache *tdc; - struct vnode *vp; - struct osi_file *tfile; - afs_int32 code = 0; - - if (!noLock) - ObtainReadLock(&avc->lock); - ObtainReadLock(&afs_xdcache); - - if ((avc->states & CStatd) /* up to date */ - && (tdc = avc->quick.dc) && (tdc->index != NULLIDX) - && !(afs_indexFlags[tdc->index] & IFFree)) { - - tdc->refCount++; - ReleaseReadLock(&afs_xdcache); - - if ((tdc->stamp == avc->quick.stamp) /* hint matches */ - && ((offDiff = (auio->afsio_offset - avc->quick.minLoc)) >= 0) - && (tdc->f.chunkBytes >= auio->afsio_resid + offDiff) - && !(tdc->flags & DFFetching)) { /* fits in chunk */ - auio->afsio_offset -= avc->quick.minLoc; - - tfile = (struct osi_file *)osi_UFSOpen(tdc->f.inode); - -#ifdef AFS_AIX_ENV -#ifdef AFS_AIX41_ENV - AFS_GUNLOCK(); - code = VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, auio, NULL, NULL, NULL, &afs_osi_cred); - AFS_GLOCK(); -#else -#ifdef AFS_AIX32_ENV - code = VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, auio, NULL, NULL); -#else - code = VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, (off_t)&auio->afsio_offset, auio, NULL, NULL, -1); -#endif -#endif -#else -#ifdef AFS_SUN5_ENV - AFS_GUNLOCK(); - VOP_RWLOCK(tfile->vnode, 0); - code = VOP_READ(tfile->vnode, auio, 0, &afs_osi_cred); - VOP_RWUNLOCK(tfile->vnode, 0); - AFS_GLOCK(); -#else -#if defined(AFS_SGI_ENV) - AFS_GUNLOCK(); - AFS_VOP_RWLOCK(tfile->vnode, VRWLOCK_READ); - AFS_VOP_READ(tfile->vnode, auio, IO_ISLOCKED, &afs_osi_cred, code); - AFS_VOP_RWUNLOCK(tfile->vnode, VRWLOCK_READ); - AFS_GLOCK(); -#else -#ifdef AFS_OSF_ENV - auio->uio_rw = UIO_READ; - AFS_GUNLOCK(); - VOP_READ(tfile->vnode, auio, 0, &afs_osi_cred, code); - AFS_GLOCK(); -#else /* AFS_OSF_ENV */ -#if defined(AFS_HPUX100_ENV) - AFS_GUNLOCK(); - code = VOP_RDWR(tfile->vnode, auio, UIO_READ, 0, &afs_osi_cred); - AFS_GLOCK(); -#else -#if defined(AFS_LINUX20_ENV) - AFS_GUNLOCK(); - code = osi_file_uio_rdwr(tfile, auio, UIO_READ); - AFS_GLOCK(); -#else -#if defined(AFS_DARWIN_ENV) - AFS_GUNLOCK(); - VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc()); - code = VOP_READ(tfile->vnode, auio, 0, &afs_osi_cred); - VOP_UNLOCK(tfile->vnode, 0, current_proc()); - AFS_GLOCK(); -#else -#if defined(AFS_FBSD_ENV) - AFS_GUNLOCK(); - VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc); - code = VOP_READ(tfile->vnode, auio, 0, &afs_osi_cred); - VOP_UNLOCK(tfile->vnode, 0, curproc); - AFS_GLOCK(); -#else - code = VOP_RDWR(tfile->vnode, auio, UIO_READ, 0, &afs_osi_cred); -#endif -#endif -#endif -#endif -#endif -#endif -#endif -#endif - auio->afsio_offset += avc->quick.minLoc; - osi_UFSClose(tfile); - /* Fix up LRU info */ - hset(afs_indexTimes[tdc->index], afs_indexCounter); - hadd32(afs_indexCounter, 1); - - if (!noLock) { -#ifndef AFS_VM_RDWR_ENV - if (!(code = afs_InitReq(&treq, acred))&& (!(tdc->flags & DFNextStarted))) - afs_PrefetchChunk(avc, tdc, acred, &treq); -#endif - ReleaseReadLock(&avc->lock); + /* + * DCLOCKXXX: This is a little sketchy, since someone else + * could have already started a prefetch.. In practice, + * this probably doesn't matter; at most it would cause an + * extra slot in the BKG table to be used up when someone + * prefetches this for the second time. + */ + ObtainReadLock(&adc->lock); + ObtainWriteLock(&adc->mflock, 664); + adc->mflags &= ~DFNextStarted; + ReleaseWriteLock(&adc->mflock); + ReleaseReadLock(&adc->lock); + } else { + ReleaseWriteLock(&tdc->mflock); } - tdc->refCount--; - return (code); - } - if (!tdc->f.chunkBytes) { /* debugging f.chunkBytes == 0 problem */ - savedc = tdc; + } else { + ReleaseSharedLock(&tdc->mflock); + afs_PutDCache(tdc); } - tdc->refCount--; } else { - ReleaseReadLock(&afs_xdcache); + ReleaseSharedLock(&adc->mflock); + ReleaseReadLock(&adc->lock); } - - /* come here if fast path doesn't work for some reason or other */ - if (!noLock) - ReleaseReadLock(&avc->lock); - return afs_UFSRead(avc, auio, acred, albn, abpp, noLock); } -afs_UFSRead(avc, auio, acred, albn, abpp, noLock) - struct vcache *avc; - struct uio *auio; - struct AFS_UCRED *acred; - daddr_t albn; - int noLock; - struct buf **abpp; { - afs_int32 totalLength; - afs_int32 transferLength; - afs_int32 filePos; - struct dcache *tdc=0; - afs_int32 offset, len, error; +int +afs_UFSRead(register struct vcache *avc, struct uio *auio, + struct AFS_UCRED *acred, daddr_t albn, struct buf **abpp, + int noLock) +{ + afs_size_t totalLength; + afs_size_t transferLength; + afs_size_t filePos; + afs_size_t offset, len, tlen; + afs_int32 trimlen; + struct dcache *tdc = 0; + afs_int32 error; struct uio tuio; struct iovec *tvec; struct osi_file *tfile; afs_int32 code; - int munlocked, trybusy=1; - struct vnode *vp; + int trybusy = 1; struct vrequest treq; AFS_STATCNT(afs_UFSRead); @@ -502,34 +459,36 @@ afs_UFSRead(avc, auio, acred, albn, abpp, noLock) return EIO; /* check that we have the latest status info in the vnode cache */ - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; if (!noLock) { - if (!avc) - osi_Panic ("null avc in afs_UFSRead"); - else { - code = afs_VerifyVCache(avc, &treq); - if (code) { - code = afs_CheckCode(code, &treq, 11); /* failed to get it */ - return code; + if (!avc) + osi_Panic("null avc in afs_UFSRead"); + else { + code = afs_VerifyVCache(avc, &treq); + if (code) { + code = afs_CheckCode(code, &treq, 11); /* failed to get it */ + return code; + } } - } } - #ifndef AFS_VM_RDWR_ENV if (AFS_NFSXLATORREQ(acred)) { - if (!afs_AccessOK(avc, PRSFS_READ, &treq, - CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) { + if (!afs_AccessOK + (avc, PRSFS_READ, &treq, + CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) { return afs_CheckCode(EACCES, &treq, 12); } } #endif - tvec = (struct iovec *) osi_AllocSmallSpace(sizeof(struct iovec)); + tvec = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec)); totalLength = auio->afsio_resid; filePos = auio->afsio_offset; - afs_Trace4(afs_iclSetp, CM_TRACE_READ, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, filePos, ICL_TYPE_INT32, totalLength, - ICL_TYPE_INT32, avc->m.Length); + afs_Trace4(afs_iclSetp, CM_TRACE_READ, ICL_TYPE_POINTER, avc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(filePos), ICL_TYPE_INT32, + totalLength, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length)); error = 0; transferLength = 0; if (!noLock) @@ -539,118 +498,165 @@ afs_UFSRead(avc, auio, acred, albn, abpp, noLock) hset(avc->flushDV, avc->m.DataVersion); } #endif - + while (totalLength > 0) { /* read all of the cached info */ - if (filePos >= avc->m.Length) break; /* all done */ + if (filePos >= avc->m.Length) + break; /* all done */ if (noLock) { - if (tdc) afs_PutDCache(tdc); + if (tdc) { + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); + } tdc = afs_FindDCache(avc, filePos); if (tdc) { + ObtainReadLock(&tdc->lock); offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); - len = tdc->f.chunkBytes - offset; + len = tdc->validPos - filePos; } } else { /* a tricky question: does the presence of the DFFetching flag - mean that we're fetching the latest version of the file? No. - The server could update the file as soon as the fetch responsible - for the setting of the DFFetching flag completes. - - However, the presence of the DFFetching flag (visible under a - read lock since it is set and cleared only under a write lock) - means that we're fetching as good a version as was known to this - client at the time of the last call to afs_VerifyVCache, since - the latter updates the stat cache's m.DataVersion field under a - write lock, and from the time that the DFFetching flag goes on - (before the fetch starts), to the time it goes off (after the - fetch completes), afs_GetDCache keeps at least a read lock - (actually it keeps an S lock) on the cache entry. - - This means that if the DFFetching flag is set, we can use that - data for any reads that must come from the current version of - the file (current == m.DataVersion). - - Another way of looking at this same point is this: if we're - fetching some data and then try do an afs_VerifyVCache, the - VerifyVCache operation will not complete until after the - DFFetching flag is turned off and the dcache entry's f.versionNo - field is updated. - - Note, by the way, that if DFFetching is set, - m.DataVersion > f.versionNo (the latter is not updated until - after the fetch completes). + * mean that we're fetching the latest version of the file? No. + * The server could update the file as soon as the fetch responsible + * for the setting of the DFFetching flag completes. + * + * However, the presence of the DFFetching flag (visible under + * a dcache read lock since it is set and cleared only under a + * dcache write lock) means that we're fetching as good a version + * as was known to this client at the time of the last call to + * afs_VerifyVCache, since the latter updates the stat cache's + * m.DataVersion field under a vcache write lock, and from the + * time that the DFFetching flag goes on in afs_GetDCache (before + * the fetch starts), to the time it goes off (after the fetch + * completes), afs_GetDCache keeps at least a read lock on the + * vcache entry. + * + * This means that if the DFFetching flag is set, we can use that + * data for any reads that must come from the current version of + * the file (current == m.DataVersion). + * + * Another way of looking at this same point is this: if we're + * fetching some data and then try do an afs_VerifyVCache, the + * VerifyVCache operation will not complete until after the + * DFFetching flag is turned off and the dcache entry's f.versionNo + * field is updated. + * + * Note, by the way, that if DFFetching is set, + * m.DataVersion > f.versionNo (the latter is not updated until + * after the fetch completes). */ - if (tdc) afs_PutDCache(tdc); /* before reusing tdc */ - munlocked = 0; - tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 2); - if (tdc == savedc) { - savedc = 0; + if (tdc) { + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); /* before reusing tdc */ } + tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 2); + ObtainReadLock(&tdc->lock); /* now, first try to start transfer, if we'll need the data. If * data already coming, we don't need to do this, obviously. Type * 2 requests never return a null dcache entry, btw. */ - if (!(tdc->flags & DFFetching) + if (!(tdc->dflags & DFFetching) && !hsame(avc->m.DataVersion, tdc->f.versionNo)) { /* have cache entry, it is not coming in now, and we'll need new data */ -tagain: + tagain: if (trybusy && !afs_BBusy()) { struct brequest *bp; /* daemon is not busy */ - if (!(tdc->flags & DFFetchReq)) { - tdc->flags |= DFFetchReq; -#ifdef AFS_SUN5_ENVX - mutex_exit(&tdc->lock); - munlocked = 1; -#endif + ObtainSharedLock(&tdc->mflock, 667); + if (!(tdc->mflags & DFFetchReq)) { + UpgradeSToWLock(&tdc->mflock, 668); + tdc->mflags |= DFFetchReq; bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred, - (long)filePos, (long) tdc, 0L, 0L); + (afs_size_t) filePos, (afs_size_t) 0, + tdc); if (!bp) { /* Bkg table full; retry deadlocks */ - tdc->flags &= ~DFFetchReq; + tdc->mflags &= ~DFFetchReq; trybusy = 0; /* Avoid bkg daemon since they're too busy */ + ReleaseWriteLock(&tdc->mflock); goto tagain; } + ConvertWToSLock(&tdc->mflock); } - while (tdc->flags & DFFetchReq) { + code = 0; + ConvertSToRLock(&tdc->mflock); + while (!code && tdc->mflags & DFFetchReq) { + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, + ICL_TYPE_STRING, __FILE__, ICL_TYPE_INT32, + __LINE__, ICL_TYPE_POINTER, tdc, + ICL_TYPE_INT32, tdc->dflags); /* don't need waiting flag on this one */ + ReleaseReadLock(&tdc->mflock); + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); - afs_osi_Sleep(&tdc->validPos); + code = afs_osi_SleepSig(&tdc->validPos); ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); + ObtainReadLock(&tdc->mflock); + } + ReleaseReadLock(&tdc->mflock); + if (code) { + error = code; + break; } } } /* now data may have started flowing in (if DFFetching is on). If - * data is now streaming in, then wait for some interesting stuff. */ - while ((tdc->flags & DFFetching) && tdc->validPos <= filePos) { - /* too early: wait for DFFetching flag to vanish, or data to appear */ - tdc->flags |= DFWaiting; + * data is now streaming in, then wait for some interesting stuff. + */ + code = 0; + while (!code && (tdc->dflags & DFFetching) + && tdc->validPos <= filePos) { + /* too early: wait for DFFetching flag to vanish, + * or data to appear */ + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, + ICL_TYPE_POINTER, tdc, ICL_TYPE_INT32, + tdc->dflags); + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); - afs_osi_Sleep(&tdc->validPos); + code = afs_osi_SleepSig(&tdc->validPos); ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); } - /* fetching flag gone, data is here, or we never tried (BBusy for instance) */ - if (tdc->flags & DFFetching) { - /* still fetching, some new data is here: compute length and offset */ + if (code) { + error = code; + break; + } + /* fetching flag gone, data is here, or we never tried + * (BBusy for instance) */ + if (tdc->dflags & DFFetching) { + /* still fetching, some new data is here: + * compute length and offset */ offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); len = tdc->validPos - filePos; - } - else { - /* no longer fetching, verify data version (avoid new GetDCache call) */ - if (hsame(avc->m.DataVersion, tdc->f.versionNo)) { + } else { + /* no longer fetching, verify data version (avoid new + * GetDCache call) */ + if (hsame(avc->m.DataVersion, tdc->f.versionNo) + && ((len = tdc->validPos - filePos) > 0)) { offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); - len = tdc->f.chunkBytes - offset; - } - else { + } else { /* don't have current data, so get it below */ + afs_Trace3(afs_iclSetp, CM_TRACE_VERSIONNO, + ICL_TYPE_INT64, ICL_HANDLE_OFFSET(filePos), + ICL_TYPE_HYPER, &avc->m.DataVersion, + ICL_TYPE_HYPER, &tdc->f.versionNo); + ReleaseReadLock(&tdc->lock); afs_PutDCache(tdc); - tdc = (struct dcache *) 0; + tdc = NULL; } } if (!tdc) { + /* If we get, it was not possible to start the + * background daemon. With flag == 1 afs_GetDCache + * does the FetchData rpc synchronously. + */ ReleaseReadLock(&avc->lock); tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 1); ObtainReadLock(&avc->lock); + if (tdc) + ObtainReadLock(&tdc->lock); } } @@ -658,59 +664,71 @@ tagain: error = EIO; break; } - if (len > totalLength) len = totalLength; /* will read len bytes */ - if (len <= 0) { /* shouldn't get here if DFFetching is on */ + len = tdc->validPos - filePos; + afs_Trace3(afs_iclSetp, CM_TRACE_VNODEREAD, ICL_TYPE_POINTER, tdc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(offset), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(len)); + if (len > totalLength) + len = totalLength; /* will read len bytes */ + if (len <= 0) { /* shouldn't get here if DFFetching is on */ + afs_Trace4(afs_iclSetp, CM_TRACE_VNODEREAD2, ICL_TYPE_POINTER, + tdc, ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(tdc->validPos), + ICL_TYPE_INT32, tdc->f.chunkBytes, ICL_TYPE_INT32, + tdc->dflags); /* read past the end of a chunk, may not be at next chunk yet, and yet - also not at eof, so may have to supply fake zeros */ - len = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset; /* bytes left in chunk addr space */ - if (len > totalLength) len = totalLength; /* and still within xfr request */ - code = avc->m.Length - offset; /* and still within file */ - if (len > code) len = code; - if (len > AFS_ZEROS) len = sizeof(afs_zeros); /* and in 0 buffer */ + * also not at eof, so may have to supply fake zeros */ + len = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset; /* bytes left in chunk addr space */ + if (len > totalLength) + len = totalLength; /* and still within xfr request */ + tlen = avc->m.Length - offset; /* and still within file */ + if (len > tlen) + len = tlen; + if (len > AFS_ZEROS) + len = sizeof(afs_zeros); /* and in 0 buffer */ afsio_copy(auio, &tuio, tvec); - afsio_trim(&tuio, len); - AFS_UIOMOVE(afs_zeros, len, UIO_READ, &tuio, code); + trimlen = len; + afsio_trim(&tuio, trimlen); + AFS_UIOMOVE(afs_zeros, trimlen, UIO_READ, &tuio, code); if (code) { error = code; break; } - } - else { + } else { /* get the data from the file */ #ifdef IHINT - if (tfile = tdc->ihint) { - if (tdc->f.inode != tfile->inum){ - afs_warn( "afs_UFSRead: %x hint mismatch tdc %d inum %d\n", - tdc, tdc->f.inode, tfile->inum ); - osi_UFSClose(tfile); + if (tfile = tdc->ihint) { + if (tdc->f.inode != tfile->inum) { + afs_warn("afs_UFSRead: %x hint mismatch tdc %d inum %d\n", + tdc, tdc->f.inode, tfile->inum); + osi_UFSClose(tfile); tdc->ihint = tfile = 0; nihints--; - } - } - if (tfile != 0) { - usedihint++; - } - else + } + } + if (tfile != 0) { + usedihint++; + } else #endif /* IHINT */ - tfile = (struct osi_file *)osi_UFSOpen(tdc->f.inode); + tfile = (struct osi_file *)osi_UFSOpen(tdc->f.inode); /* mung uio structure to be right for this transfer */ afsio_copy(auio, &tuio, tvec); - afsio_trim(&tuio, len); + trimlen = len; + afsio_trim(&tuio, trimlen); tuio.afsio_offset = offset; -#ifdef AFS_AIX_ENV -#ifdef AFS_AIX41_ENV - AFS_GUNLOCK(); - code = VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL, - NULL, &afs_osi_cred); - AFS_GLOCK(); -#else -#ifdef AFS_AIX32_ENV - code = VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL); - /* Flush all JFS pages now for big performance gain in big file cases - * If we do something like this, must check to be sure that AFS file - * isn't mmapped... see afs_gn_map() for why. - */ +#if defined(AFS_AIX41_ENV) + AFS_GUNLOCK(); + code = + VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL, + NULL, afs_osi_credp); + AFS_GLOCK(); +#elif defined(AFS_AIX32_ENV) + code = + VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL); + /* Flush all JFS pages now for big performance gain in big file cases + * If we do something like this, must check to be sure that AFS file + * isn't mmapped... see afs_gn_map() for why. + */ /* if (tfile->vnode->v_gnode && tfile->vnode->v_gnode->gn_seg) { many different ways to do similar things: @@ -731,78 +749,67 @@ tagain: (len + PAGESIZE-1)/PAGESIZE); } */ -#else - code = VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, (off_t)&offset, &tuio, NULL, NULL, -1); -#endif -#endif -#else -#ifdef AFS_SUN5_ENV - AFS_GUNLOCK(); +#elif defined(AFS_AIX_ENV) + code = + VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, (off_t) & offset, + &tuio, NULL, NULL, -1); +#elif defined(AFS_SUN5_ENV) + AFS_GUNLOCK(); VOP_RWLOCK(tfile->vnode, 0); - code = VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred); + code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp); VOP_RWUNLOCK(tfile->vnode, 0); - AFS_GLOCK(); -#else -#if defined(AFS_SGI_ENV) + AFS_GLOCK(); +#elif defined(AFS_SGI_ENV) AFS_GUNLOCK(); AFS_VOP_RWLOCK(tfile->vnode, VRWLOCK_READ); - AFS_VOP_READ(tfile->vnode, &tuio, IO_ISLOCKED, &afs_osi_cred, + AFS_VOP_READ(tfile->vnode, &tuio, IO_ISLOCKED, afs_osi_credp, code); AFS_VOP_RWUNLOCK(tfile->vnode, VRWLOCK_READ); AFS_GLOCK(); -#else -#ifdef AFS_OSF_ENV +#elif defined(AFS_OSF_ENV) tuio.uio_rw = UIO_READ; AFS_GUNLOCK(); - VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred, code); + VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp, code); AFS_GLOCK(); -#else /* AFS_OSF_ENV */ -#ifdef AFS_SUN_ENV - code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, &afs_osi_cred); -#else -#if defined(AFS_HPUX100_ENV) +#elif defined(AFS_SUN_ENV) + code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp); +#elif defined(AFS_HPUX100_ENV) AFS_GUNLOCK(); - code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, &afs_osi_cred); + code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp); AFS_GLOCK(); -#else -#if defined(AFS_LINUX20_ENV) +#elif defined(AFS_LINUX20_ENV) AFS_GUNLOCK(); code = osi_file_uio_rdwr(tfile, &tuio, UIO_READ); AFS_GLOCK(); +#elif defined(AFS_DARWIN_ENV) + AFS_GUNLOCK(); + VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc()); + code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp); + VOP_UNLOCK(tfile->vnode, 0, current_proc()); + AFS_GLOCK(); +#elif defined(AFS_FBSD50_ENV) + AFS_GUNLOCK(); + VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curthread); + code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp); + VOP_UNLOCK(tfile->vnode, 0, curthread); + AFS_GLOCK(); +#elif defined(AFS_XBSD_ENV) + AFS_GUNLOCK(); + VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc); + code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp); + VOP_UNLOCK(tfile->vnode, 0, curproc); + AFS_GLOCK(); #else -#if defined(AFS_DARWIN_ENV) - AFS_GUNLOCK(); - VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc()); - code = VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred); - VOP_UNLOCK(tfile->vnode, 0, current_proc()); - AFS_GLOCK(); -#else -#if defined(AFS_FBSD_ENV) - AFS_GUNLOCK(); - VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc); - code = VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred); - VOP_UNLOCK(tfile->vnode, 0, curproc); - AFS_GLOCK(); -#else - code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, &afs_osi_cred); -#endif -#endif -#endif -#endif -#endif -#endif -#endif -#endif + code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp); #endif #ifdef IHINT - if (!tdc->ihint && nihints < maxIHint) { - tdc->ihint = tfile; - nihints++; - } - else + if (!tdc->ihint && nihints < maxIHint) { + tdc->ihint = tfile; + nihints++; + } else #endif /* IHINT */ - osi_UFSClose(tfile); + osi_UFSClose(tfile); if (code) { error = code; @@ -810,12 +817,14 @@ tagain: } } /* otherwise we've read some, fixup length, etc and continue with next seg */ - len = len - tuio.afsio_resid; /* compute amount really transferred */ - afsio_skip(auio, len); /* update input uio structure */ + len = len - tuio.afsio_resid; /* compute amount really transferred */ + trimlen = len; + afsio_skip(auio, trimlen); /* update input uio structure */ totalLength -= len; transferLength += len; filePos += len; - if (len <= 0) break; /* surprise eof */ + if (len <= 0) + break; /* surprise eof */ } /* if we make it here with tdc non-zero, then it is the last chunk we @@ -823,10 +832,12 @@ tagain: * to it in case we need to do a prefetch, obviously. */ if (tdc) { -#ifndef AFS_VM_RDWR_ENV + ReleaseReadLock(&tdc->lock); +#if !defined(AFS_VM_RDWR_ENV) /* try to queue prefetch, if needed */ - if (!(tdc->flags & DFNextStarted) && !noLock) { - afs_PrefetchChunk(avc, tdc, acred, &treq); + if (!noLock) { + if (!(tdc->mflags & DFNextStarted)) + afs_PrefetchChunk(avc, tdc, acred, &treq); } #endif afs_PutDCache(tdc); diff --git a/src/afs/VNOPS/afs_vnop_readdir.c b/src/afs/VNOPS/afs_vnop_readdir.c index 669fa44fb..3320b0442 100644 --- a/src/afs/VNOPS/afs_vnop_readdir.c +++ b/src/afs/VNOPS/afs_vnop_readdir.c @@ -20,29 +20,30 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_readdir.c,v 1.11 2003/07/30 17:23:44 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_readdir.c,v 1.23 2003/11/27 01:17:40 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" -#if defined(AFS_HPUX1122_ENV) + +#if defined(AFS_HPUX1122_ENV) #define DIRPAD 7 #else #define DIRPAD 3 #endif - /** * A few definitions. This is until we have a proper header file * which ahs prototypes for all functions */ - -extern struct DirEntry * afs_dir_GetBlob(); + +extern struct DirEntry *afs_dir_GetBlob(); /* * AFS readdir vnodeop and bulk stat support. */ @@ -66,12 +67,21 @@ extern struct DirEntry * afs_dir_GetBlob(); become static. */ #if defined(AFS_SGI62_ENV) || defined(AFS_SUN57_64BIT_ENV) -int BlobScan(ino64_t *afile, afs_int32 ablob) +int +BlobScan(ino64_t * afile, afs_int32 ablob) +#else +#if defined(AFS_HPUX1123_ENV) +/*DEE should use afs_inode_t for all */ +int +BlobScan(ino_t *afile, afs_int32 ablob) #else #ifdef AFS_LINUX_64BIT_KERNEL -int BlobScan(long *afile, afs_int32 ablob) +int +BlobScan(long *afile, afs_int32 ablob) #else -int BlobScan(afs_int32 *afile, afs_int32 ablob) +int +BlobScan(afs_int32 * afile, afs_int32 ablob) +#endif #endif #endif { @@ -83,27 +93,31 @@ int BlobScan(afs_int32 *afile, afs_int32 ablob) AFS_STATCNT(BlobScan); /* advance ablob over free and header blobs */ while (1) { - pageBlob = ablob & ~(EPP-1); /* base blob in same page */ - tpe = (struct PageHeader *) afs_dir_GetBlob(afile, pageBlob); - if (!tpe) return 0; /* we've past the end */ - relativeBlob = ablob - pageBlob; /* relative to page's first blob */ + pageBlob = ablob & ~(EPP - 1); /* base blob in same page */ + tpe = (struct PageHeader *)afs_dir_GetBlob(afile, pageBlob); + if (!tpe) + return 0; /* we've past the end */ + relativeBlob = ablob - pageBlob; /* relative to page's first blob */ /* first watch for headers */ - if (pageBlob == 0) { /* first dir page has extra-big header */ + if (pageBlob == 0) { /* first dir page has extra-big header */ /* first page */ - if (relativeBlob < DHE+1) relativeBlob = DHE+1; - } - else { /* others have one header blob */ - if (relativeBlob == 0) relativeBlob = 1; + if (relativeBlob < DHE + 1) + relativeBlob = DHE + 1; + } else { /* others have one header blob */ + if (relativeBlob == 0) + relativeBlob = 1; } /* make sure blob is allocated */ - for(i = relativeBlob; i < EPP; i++) { - if (tpe->freebitmap[i>>3] & (1<<(i&7))) break; + for (i = relativeBlob; i < EPP; i++) { + if (tpe->freebitmap[i >> 3] & (1 << (i & 7))) + break; } /* now relativeBlob is the page-relative first allocated blob, - or EPP (if there are none in this page). */ - DRelease(tpe, 0); - if (i != EPP) return i+pageBlob; - ablob = pageBlob + EPP; /* go around again */ + * or EPP (if there are none in this page). */ + DRelease((struct buffer *)tpe, 0); + if (i != EPP) + return i + pageBlob; + ablob = pageBlob + EPP; /* go around again */ } /* never get here */ } @@ -122,18 +136,18 @@ int BlobScan(afs_int32 *afile, afs_int32 ablob) #if !defined(UKERNEL) #if defined(AFS_SGI_ENV) /* Long form for 64 bit apps and kernel requests. */ -struct min_dirent { /* miniature dirent structure */ - /* If struct dirent changes, this must too */ - ino_t d_fileno; /* This is 32 bits for 3.5, 64 for 6.2+ */ - off64_t d_off; - u_short d_reclen; +struct min_dirent { /* miniature dirent structure */ + /* If struct dirent changes, this must too */ + ino_t d_fileno; /* This is 32 bits for 3.5, 64 for 6.2+ */ + off64_t d_off; + u_short d_reclen; }; /* Short form for 32 bit apps. */ -struct irix5_min_dirent { /* miniature dirent structure */ - /* If struct dirent changes, this must too */ - afs_uint32 d_fileno; - afs_int32 d_off; - u_short d_reclen; +struct irix5_min_dirent { /* miniature dirent structure */ + /* If struct dirent changes, this must too */ + afs_uint32 d_fileno; + afs_int32 d_off; + u_short d_reclen; }; #ifdef AFS_SGI62_ENV #define AFS_DIRENT32BASESIZE IRIX5_DIRENTBASESIZE @@ -143,28 +157,29 @@ struct irix5_min_dirent { /* miniature dirent structure */ #define AFS_DIRENT64BASESIZE DIRENTBASESIZE #endif /* AFS_SGI62_ENV */ #else -struct min_direct { /* miniature direct structure */ - /* If struct direct changes, this must too */ -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - afs_uint32 d_fileno; - u_short d_reclen; - u_char d_type; - u_char d_namlen; -#else +struct min_direct { /* miniature direct structure */ + /* If struct direct changes, this must too */ +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + afs_uint32 d_fileno; + u_short d_reclen; + u_char d_type; + u_char d_namlen; +#else #ifdef AFS_SUN5_ENV - afs_uint32 d_fileno; - afs_int32 d_off; - u_short d_reclen; + afs_uint32 d_fileno; + afs_int32 d_off; + u_short d_reclen; #else #if defined(AFS_SUN_ENV) || defined(AFS_AIX32_ENV) - afs_int32 d_off; + afs_int32 d_off; + afs_uint32 d_fileno; #endif #if defined(AFS_HPUX100_ENV) unsigned long long d_off; + afs_uint32 d_fileno; #endif - afs_uint32 d_fileno; - u_short d_reclen; - u_short d_namlen; + u_short d_reclen; + u_short d_namlen; #endif #endif }; @@ -172,10 +187,10 @@ struct min_direct { /* miniature direct structure */ #if defined(AFS_HPUX_ENV) || defined(AFS_OSF_ENV) struct minnfs_direct { - afs_int32 d_off; /* XXX */ - afs_uint32 d_fileno; - u_short d_reclen; - u_short d_namlen; + afs_int32 d_off; /* XXX */ + afs_uint32 d_fileno; + u_short d_reclen; + u_short d_namlen; }; #define NDIRSIZ_LEN(len) ((sizeof (struct dirent)+4 - (MAXNAMLEN+1)) + (((len)+1 + DIRPAD) &~ DIRPAD)) #endif @@ -190,8 +205,8 @@ struct minnfs_direct { */ #define READDIR_STASH AFSCBMAX -struct AFSFid afs_readdir_stash[READDIR_STASH]; -int afs_rd_stash_i = 0; +struct AFSFid afs_readdir_stash[READDIR_STASH]; +int afs_rd_stash_i = 0; /* *------------------------------------------------------------------------------ @@ -203,6 +218,7 @@ int afs_rd_stash_i = 0; * * */ + #if defined(AFS_HPUX100_ENV) #define DIRSIZ_LEN(len) \ ((sizeof (struct __dirent) - (_MAXNAMLEN+1)) + (((len)+1 + DIRPAD) &~ DIRPAD)) @@ -229,42 +245,42 @@ int afs_rd_stash_i = 0; #endif /* AFS_DIRENT */ #endif /* AFS_SUN5_ENV */ #endif /* AFS_SUN56_ENV */ -#endif /* AFS_HPUX100_ENV */ +#endif /* AFS_HPUX100_ENV */ -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -int afs_readdir_type(avc, ade) -struct DirEntry * ade; -struct vcache * avc; +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) +int +afs_readdir_type(avc, ade) + struct DirEntry *ade; + struct vcache *avc; { - struct VenusFid tfid; - struct vcache *tvc; - int vtype; - tfid.Cell=avc->fid.Cell; - tfid.Fid.Volume=avc->fid.Fid.Volume; - tfid.Fid.Vnode=ntohl(ade->fid.vnode); - tfid.Fid.Unique=ntohl(ade->fid.vunique); - if ((avc->states & CForeign) == 0 && - (ntohl(ade->fid.vnode) & 1)) { - return DT_DIR; - } else if ((tvc=afs_FindVCache(&tfid,0,0,0,0))) { - if (tvc->mvstat) { - afs_PutVCache(tvc, WRITE_LOCK); - return DT_DIR; - } else if (((tvc->states) & (CStatd|CTruth))) { - /* CTruth will be set if the object has - *ever* been statd */ - vtype=vType(tvc); - afs_PutVCache(tvc, WRITE_LOCK); - if (vtype == VDIR) - return DT_DIR; - else if (vtype == VREG) - return DT_REG; - /* Don't do this until we're sure it can't be a mtpt */ - /* else if (vtype == VLNK) - type=DT_LNK; */ - /* what other types does AFS support? */ - } else - afs_PutVCache(tvc, WRITE_LOCK); + struct VenusFid tfid; + struct vcache *tvc; + int vtype; + tfid.Cell = avc->fid.Cell; + tfid.Fid.Volume = avc->fid.Fid.Volume; + tfid.Fid.Vnode = ntohl(ade->fid.vnode); + tfid.Fid.Unique = ntohl(ade->fid.vunique); + if ((avc->states & CForeign) == 0 && (ntohl(ade->fid.vnode) & 1)) { + return DT_DIR; + } else if ((tvc = afs_FindVCache(&tfid, 0, 0))) { + if (tvc->mvstat) { + afs_PutVCache(tvc); + return DT_DIR; + } else if (((tvc->states) & (CStatd | CTruth))) { + /* CTruth will be set if the object has + *ever* been statd */ + vtype = vType(tvc); + afs_PutVCache(tvc); + if (vtype == VDIR) + return DT_DIR; + else if (vtype == VREG) + return DT_REG; + /* Don't do this until we're sure it can't be a mtpt */ + /* else if (vtype == VLNK) + * type=DT_LNK; */ + /* what other types does AFS support? */ + } else + afs_PutVCache(tvc); } return DT_UNKNOWN; } @@ -277,24 +293,26 @@ struct vcache * avc; #define AFS_MOVE_LOCK() #define AFS_MOVE_UNLOCK() #endif -char bufofzeros[64]; /* gotta fill with something */ -afs_readdir_move (de, vc, auio, slen, rlen, off) -struct DirEntry * de; -struct vcache * vc; -struct uio * auio; -int slen; +char bufofzeros[64]; /* gotta fill with something */ + +int +afs_readdir_move(de, vc, auio, slen, rlen, off) + struct DirEntry *de; + struct vcache *vc; + struct uio *auio; + int slen; #ifdef AFS_SGI65_ENV -ssize_t rlen; + ssize_t rlen; #else -int rlen; + int rlen; #endif -int off; + afs_size_t off; { - int code = 0; + int code = 0; #if defined(AFS_SUN56_ENV) struct dirent64 *direntp; #else -#ifdef AFS_SUN5_ENV +#if defined(AFS_SUN5_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) struct dirent *direntp; #endif #endif /* AFS_SUN56_ENV */ @@ -304,85 +322,100 @@ int off; AFS_STATCNT(afs_readdir_move); #ifdef AFS_SGI53_ENV -{ - afs_int32 use64BitDirent; + { + afs_int32 use64BitDirent; #ifdef AFS_SGI61_ENV #ifdef AFS_SGI62_ENV - use64BitDirent = ABI_IS(ABI_IRIX5_64, - GETDENTS_ABI(OSI_GET_CURRENT_ABI(), auio)); + use64BitDirent = + ABI_IS(ABI_IRIX5_64, GETDENTS_ABI(OSI_GET_CURRENT_ABI(), auio)); #else - use64BitDirent = (auio->uio_segflg != UIO_USERSPACE) ? ABI_IRIX5_64 : - (ABI_IS(ABI_IRIX5_64 | ABI_IRIX5_N32, u.u_procp->p_abi)); + use64BitDirent = + (auio->uio_segflg != + UIO_USERSPACE) ? ABI_IRIX5_64 : (ABI_IS(ABI_IRIX5_64 | + ABI_IRIX5_N32, + u.u_procp->p_abi)); #endif #else /* AFS_SGI61_ENV */ - use64BitDirent = (auio->uio_segflg != UIO_USERSPACE) ? ABI_IRIX5_64 : - (ABI_IS(ABI_IRIX5_64, u.u_procp->p_abi)); + use64BitDirent = + (auio->uio_segflg != + UIO_USERSPACE) ? ABI_IRIX5_64 : (ABI_IS(ABI_IRIX5_64, + u.u_procp->p_abi)); #endif /* AFS_SGI61_ENV */ - if (use64BitDirent) { - struct min_dirent sdirEntry; - sdirEntry.d_fileno = (vc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode); - FIXUPSTUPIDINODE(sdirEntry.d_fileno); - sdirEntry.d_reclen = rlen; - sdirEntry.d_off = (off_t)off; - AFS_UIOMOVE(&sdirEntry, AFS_DIRENT64BASESIZE, UIO_READ, auio, code); - if (code == 0) - AFS_UIOMOVE(de->name, slen-1, UIO_READ, auio, code); - if (code == 0) - AFS_UIOMOVE(bufofzeros, - DIRENTSIZE(slen) - (AFS_DIRENT64BASESIZE + slen - 1), - UIO_READ, auio, code); - if (DIRENTSIZE(slen) < rlen) { - while(DIRENTSIZE(slen) < rlen) { - int minLen = rlen - DIRENTSIZE(slen); - if (minLen > sizeof(bufofzeros)) minLen = sizeof(bufofzeros); - AFS_UIOMOVE(bufofzeros, minLen, UIO_READ, auio, code); - rlen -= minLen; + if (use64BitDirent) { + struct min_dirent sdirEntry; + sdirEntry.d_fileno = + (vc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode); + FIXUPSTUPIDINODE(sdirEntry.d_fileno); + sdirEntry.d_reclen = rlen; + sdirEntry.d_off = (off_t) off; + AFS_UIOMOVE(&sdirEntry, AFS_DIRENT64BASESIZE, UIO_READ, auio, + code); + if (code == 0) + AFS_UIOMOVE(de->name, slen - 1, UIO_READ, auio, code); + if (code == 0) + AFS_UIOMOVE(bufofzeros, + DIRENTSIZE(slen) - (AFS_DIRENT64BASESIZE + slen - + 1), UIO_READ, auio, code); + if (DIRENTSIZE(slen) < rlen) { + while (DIRENTSIZE(slen) < rlen) { + int minLen = rlen - DIRENTSIZE(slen); + if (minLen > sizeof(bufofzeros)) + minLen = sizeof(bufofzeros); + AFS_UIOMOVE(bufofzeros, minLen, UIO_READ, auio, code); + rlen -= minLen; + } } - } - } else { - struct irix5_min_dirent sdirEntry; - sdirEntry.d_fileno = (vc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode); - FIXUPSTUPIDINODE(sdirEntry.d_fileno); - sdirEntry.d_reclen = rlen; - sdirEntry.d_off = (afs_int32)off; - AFS_UIOMOVE(&sdirEntry, AFS_DIRENT32BASESIZE, UIO_READ, auio, code); - if (code == 0) - AFS_UIOMOVE(de->name, slen-1, UIO_READ, auio, code); - if (code == 0) - AFS_UIOMOVE(bufofzeros, - IRIX5_DIRENTSIZE(slen) - - (AFS_DIRENT32BASESIZE + slen - 1), - UIO_READ, auio, code); - if (IRIX5_DIRENTSIZE(slen) < rlen) { - while(IRIX5_DIRENTSIZE(slen) < rlen) { - int minLen = rlen - IRIX5_DIRENTSIZE(slen); - if (minLen > sizeof(bufofzeros)) minLen = sizeof(bufofzeros); - AFS_UIOMOVE(bufofzeros, minLen, UIO_READ, auio, code); - rlen -= minLen; + } else { + struct irix5_min_dirent sdirEntry; + sdirEntry.d_fileno = + (vc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode); + FIXUPSTUPIDINODE(sdirEntry.d_fileno); + sdirEntry.d_reclen = rlen; + sdirEntry.d_off = (afs_int32) off; + AFS_UIOMOVE(&sdirEntry, AFS_DIRENT32BASESIZE, UIO_READ, auio, + code); + if (code == 0) + AFS_UIOMOVE(de->name, slen - 1, UIO_READ, auio, code); + if (code == 0) + AFS_UIOMOVE(bufofzeros, + IRIX5_DIRENTSIZE(slen) - (AFS_DIRENT32BASESIZE + + slen - 1), UIO_READ, + auio, code); + if (IRIX5_DIRENTSIZE(slen) < rlen) { + while (IRIX5_DIRENTSIZE(slen) < rlen) { + int minLen = rlen - IRIX5_DIRENTSIZE(slen); + if (minLen > sizeof(bufofzeros)) + minLen = sizeof(bufofzeros); + AFS_UIOMOVE(bufofzeros, minLen, UIO_READ, auio, code); + rlen -= minLen; + } } } } -} #else /* AFS_SGI53_ENV */ -#ifdef AFS_SUN5_ENV +#if defined(AFS_SUN5_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) #if defined(AFS_SUN56_ENV) - direntp = (struct dirent64 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ); + direntp = (struct dirent64 *)osi_AllocLargeSpace(AFS_LRALLOCSIZ); #else - direntp = (struct dirent *) osi_AllocLargeSpace(AFS_LRALLOCSIZ); + direntp = (struct dirent *)osi_AllocLargeSpace(AFS_LRALLOCSIZ); #endif - direntp->d_ino = (vc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode); + direntp->d_ino = (vc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode); FIXUPSTUPIDINODE(direntp->d_ino); +#if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) + direntp->d_offset = off; + direntp->d_namlen = slen; +#else direntp->d_off = off; +#endif direntp->d_reclen = rlen; strcpy(direntp->d_name, de->name); - AFS_UIOMOVE((caddr_t)direntp, rlen, UIO_READ, auio, code); + AFS_UIOMOVE((caddr_t) direntp, rlen, UIO_READ, auio, code); osi_FreeLargeSpace((char *)direntp); #else /* AFS_SUN5_ENV */ /* Note the odd mechanism for building the inode number */ - sdirEntry.d_fileno = (vc->fid.Fid.Volume << 16) + - ntohl(de->fid.vnode); + sdirEntry.d_fileno = (vc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode); FIXUPSTUPIDINODE(sdirEntry.d_fileno); sdirEntry.d_reclen = rlen; #if !defined(AFS_SGI_ENV) @@ -391,16 +424,18 @@ int off; #if defined(AFS_SUN_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_SGI_ENV) sdirEntry.d_off = off; #endif -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - sdirEntry.d_type=afs_readdir_type(vc, de); +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + sdirEntry.d_type = afs_readdir_type(vc, de); #endif #if defined(AFS_SGI_ENV) AFS_UIOMOVE(&sdirEntry, DIRENTBASESIZE, UIO_READ, auio, code); if (code == 0) - AFS_UIOMOVE(de->name, slen-1, UIO_READ, auio, code); + AFS_UIOMOVE(de->name, slen - 1, UIO_READ, auio, code); if (code == 0) - AFS_UIOMOVE(bufofzeros, DIRSIZ_LEN(slen) - (DIRENTBASESIZE + slen - 1), UIO_READ, auio, code); + AFS_UIOMOVE(bufofzeros, + DIRSIZ_LEN(slen) - (DIRENTBASESIZE + slen - 1), UIO_READ, + auio, code); #else /* AFS_SGI_ENV */ AFS_MOVE_UNLOCK(); AFS_UIOMOVE((char *)&sdirEntry, sizeof(sdirEntry), UIO_READ, auio, code); @@ -410,30 +445,28 @@ int off; } /* pad out the remaining characters with zeros */ - if (code == 0) { - AFS_UIOMOVE(bufofzeros, ((slen + 1 + DIRPAD) & ~DIRPAD) - slen, UIO_READ, - auio, code); + if (code == 0) { + AFS_UIOMOVE(bufofzeros, ((slen + 1 + DIRPAD) & ~DIRPAD) - slen, + UIO_READ, auio, code); } AFS_MOVE_LOCK(); #endif /* AFS_SGI_ENV */ /* pad out the difference between rlen and slen... */ - if (DIRSIZ_LEN(slen) < rlen) - { + if (DIRSIZ_LEN(slen) < rlen) { AFS_MOVE_UNLOCK(); - while(DIRSIZ_LEN(slen) < rlen) - { - int minLen = rlen - DIRSIZ_LEN(slen); - if (minLen > sizeof(bufofzeros)) - minLen = sizeof(bufofzeros); - AFS_UIOMOVE(bufofzeros, minLen, UIO_READ, auio, code); - rlen -= minLen; - } - AFS_MOVE_LOCK(); + while (DIRSIZ_LEN(slen) < rlen) { + int minLen = rlen - DIRSIZ_LEN(slen); + if (minLen > sizeof(bufofzeros)) + minLen = sizeof(bufofzeros); + AFS_UIOMOVE(bufofzeros, minLen, UIO_READ, auio, code); + rlen -= minLen; } -#endif /* AFS_SUN5_ENV */ -#endif /* AFS_SGI53_ENV */ - return(code); + AFS_MOVE_LOCK(); + } +#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SGI53_ENV */ + return (code); } @@ -453,11 +486,11 @@ int off; * This routine encodes knowledge of Vice dirs. */ -void afs_bulkstat_send( avc, req ) - struct vcache * avc; - struct vrequest * req; +void +afs_bulkstat_send(avc, req) + struct vcache *avc; + struct vrequest *req; { - XSTATS_DECLS afs_rd_stash_i = 0; } @@ -466,73 +499,82 @@ void afs_bulkstat_send( avc, req ) * It has to do with 'offset' (seek locations). */ -#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +int +#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) afs_readdir(OSI_VC_ARG(avc), auio, acred, eofp) - int *eofp; + int *eofp; #else -#if defined(AFS_HPUX100_ENV) +#if defined(AFS_HPUX100_ENV) afs_readdir2(OSI_VC_ARG(avc), auio, acred) #else afs_readdir(OSI_VC_ARG(avc), auio, acred) -#endif +#endif #endif OSI_VC_DECL(avc); - struct uio *auio; - struct AFS_UCRED *acred; { + struct uio *auio; + struct AFS_UCRED *acred; +{ struct vrequest treq; register struct dcache *tdc; - afs_int32 origOffset, len, dirsiz; + afs_size_t origOffset, tlen; + afs_int32 len; int code = 0; struct DirEntry *ode = 0, *nde = 0; int o_slen = 0, n_slen = 0; afs_uint32 us; struct afs_fakestat_state fakestate; #if defined(AFS_SGI53_ENV) - afs_int32 use64BitDirent; + afs_int32 use64BitDirent, dirsiz; #endif /* defined(AFS_SGI53_ENV) */ OSI_VC_CONVERT(avc) #ifdef AFS_HPUX_ENV - /* - * XXX All the hacks for alloced sdirEntry and inlining of afs_readdir_move instead of calling - * it is necessary for hpux due to stack problems that seem to occur when coming thru the nfs - * translator side XXX - */ - struct min_direct *sdirEntry = (struct min_direct *)osi_AllocSmallSpace(sizeof(struct min_direct)); + /* + * XXX All the hacks for alloced sdirEntry and inlining of afs_readdir_move instead of calling + * it is necessary for hpux due to stack problems that seem to occur when coming thru the nfs + * translator side XXX + */ + struct min_direct *sdirEntry = + (struct min_direct *)osi_AllocSmallSpace(sizeof(struct min_direct)); afs_int32 rlen; #endif /* opaque value is pointer into a vice dir; use bit map to decide - if the entries are in use. Always assumed to be valid. 0 is - special, means start of a new dir. Int32 inode, followed by - short reclen and short namelen. Namelen does not include - the null byte. Followed by null-terminated string. - */ + * if the entries are in use. Always assumed to be valid. 0 is + * special, means start of a new dir. Int32 inode, followed by + * short reclen and short namelen. Namelen does not include + * the null byte. Followed by null-terminated string. + */ AFS_STATCNT(afs_readdir); #if defined(AFS_SGI53_ENV) #ifdef AFS_SGI61_ENV #ifdef AFS_SGI62_ENV - use64BitDirent = ABI_IS(ABI_IRIX5_64, - GETDENTS_ABI(OSI_GET_CURRENT_ABI(), auio)); + use64BitDirent = + ABI_IS(ABI_IRIX5_64, GETDENTS_ABI(OSI_GET_CURRENT_ABI(), auio)); #else - use64BitDirent = (auio->uio_segflg != UIO_USERSPACE) ? ABI_IRIX5_64 : - (ABI_IS(ABI_IRIX5_64 | ABI_IRIX5_N32, u.u_procp->p_abi)); + use64BitDirent = + (auio->uio_segflg != + UIO_USERSPACE) ? ABI_IRIX5_64 : (ABI_IS(ABI_IRIX5_64 | ABI_IRIX5_N32, + u.u_procp->p_abi)); #endif /* AFS_SGI62_ENV */ #else /* AFS_SGI61_ENV */ - use64BitDirent = (auio->uio_segflg != UIO_USERSPACE) ? ABI_IRIX5_64 : - (ABI_IS(ABI_IRIX5_64, u.u_procp->p_abi)); + use64BitDirent = + (auio->uio_segflg != + UIO_USERSPACE) ? ABI_IRIX5_64 : (ABI_IS(ABI_IRIX5_64, + u.u_procp->p_abi)); #endif /* AFS_SGI61_ENV */ #endif /* defined(AFS_SGI53_ENV) */ -#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) /* Not really used by the callee so we ignore it for now */ - if (eofp) *eofp = 0; + if (eofp) + *eofp = 0; #endif - if ( AfsLargeFileUio(auio) /* file is large than 2 GB */ - || AfsLargeFileSize(auio->uio_offset, auio->uio_resid) ) + if (AfsLargeFileUio(auio) /* file is large than 2 GB */ + ||AfsLargeFileSize(auio->uio_offset, auio->uio_resid)) return EFBIG; - if (code = afs_InitReq(&treq, acred)) { + if ((code = afs_InitReq(&treq, acred))) { #ifdef AFS_HPUX_ENV osi_FreeSmallSpace((char *)sdirEntry); #endif @@ -541,17 +583,21 @@ afs_readdir(OSI_VC_ARG(avc), auio, acred) /* update the cache entry */ afs_InitFakeStat(&fakestate); code = afs_EvalFakeStat(&avc, &fakestate, &treq); - if (code) goto done; -tagain: + if (code) + goto done; + tagain: code = afs_VerifyVCache(avc, &treq); - if (code) goto done; + if (code) + goto done; /* get a reference to the entire directory */ - tdc = afs_GetDCache(avc, 0, &treq, &origOffset, &len, 1); + tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1); + len = tlen; if (!tdc) { code = ENOENT; goto done; } ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); /* * Make sure that the data in the cache is current. There are two @@ -560,76 +606,85 @@ tagain: * 2. The cache data is no longer valid */ while ((avc->states & CStatd) - && (tdc->flags & DFFetching) + && (tdc->dflags & DFFetching) && hsame(avc->m.DataVersion, tdc->f.versionNo)) { - tdc->flags |= DFWaiting; + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, ICL_TYPE_POINTER, tdc, + ICL_TYPE_INT32, tdc->dflags); + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); afs_osi_Sleep(&tdc->validPos); ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); } if (!(avc->states & CStatd) || !hsame(avc->m.DataVersion, tdc->f.versionNo)) { + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); afs_PutDCache(tdc); goto tagain; } /* - * iterator for the directory reads. Takes the AFS DirEntry - * structure and slams them into UFS direct structures. - * uses afs_readdir_move to get the struct to the user space. + * iterator for the directory reads. Takes the AFS DirEntry + * structure and slams them into UFS direct structures. + * uses afs_readdir_move to get the struct to the user space. * - * The routine works by looking ahead one AFS directory entry. - * That's because the AFS entry we are currenly working with - * may not fit into the buffer the user has provided. If it - * doesn't we have to change the size of the LAST AFS directory - * entry, so that it will FIT perfectly into the block the - * user has provided. - * - * The 'forward looking' of the code makes it a bit tough to read. - * Remember we need to get an entry, see if it it fits, then - * set it up as the LAST entry, and find the next one. + * The routine works by looking ahead one AFS directory entry. + * That's because the AFS entry we are currenly working with + * may not fit into the buffer the user has provided. If it + * doesn't we have to change the size of the LAST AFS directory + * entry, so that it will FIT perfectly into the block the + * user has provided. + * + * The 'forward looking' of the code makes it a bit tough to read. + * Remember we need to get an entry, see if it it fits, then + * set it up as the LAST entry, and find the next one. * - * Tough to take: We give out an EINVAL if we don't have enough - * space in the buffer, and at the same time, don't have an entry - * to put into the buffer. This CAN happen if the first AFS entry - * we get can't fit into the 512 character buffer provided. Seems - * it ought not happen... + * Tough to take: We give out an EINVAL if we don't have enough + * space in the buffer, and at the same time, don't have an entry + * to put into the buffer. This CAN happen if the first AFS entry + * we get can't fit into the 512 character buffer provided. Seems + * it ought not happen... * - * Assumption: don't need to use anything but one dc entry: - * this means the directory ought not be greater than 64k. + * Assumption: don't need to use anything but one dc entry: + * this means the directory ought not be greater than 64k. */ len = 0; #ifdef AFS_HPUX_ENV auio->uio_fpflags = 0; #endif - while (code==0) { + while (code == 0) { origOffset = auio->afsio_offset; /* scan for the next interesting entry scan for in-use blob otherwise up point at * this blob note that ode, if non-zero, also represents a held dir page */ - if (!(us = BlobScan(&tdc->f.inode, (origOffset >> 5)) ) - || !(nde = (struct DirEntry *) afs_dir_GetBlob(&tdc->f.inode, us) ) ) { + if (!(us = BlobScan(&tdc->f.inode, (origOffset >> 5))) + || !(nde = (struct DirEntry *)afs_dir_GetBlob(&tdc->f.inode, us))) { /* failed to setup nde, return what we've got, and release ode */ if (len) { /* something to hand over. */ #ifdef AFS_HPUX_ENV - sdirEntry->d_fileno = (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); + sdirEntry->d_fileno = + (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); FIXUPSTUPIDINODE(sdirEntry->d_fileno); sdirEntry->d_reclen = rlen = auio->afsio_resid; sdirEntry->d_namlen = o_slen; #if defined(AFS_SUN_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_HPUX100_ENV) sdirEntry->d_off = origOffset; #endif - AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, auio, code); + AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, + auio, code); if (code == 0) AFS_UIOMOVE(ode->name, o_slen, UIO_READ, auio, code); /* pad out the remaining characters with zeros */ if (code == 0) { - AFS_UIOMOVE(bufofzeros, ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, UIO_READ, auio, code); + AFS_UIOMOVE(bufofzeros, + ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, + UIO_READ, auio, code); } /* pad out the difference between rlen and slen... */ if (DIRSIZ_LEN(o_slen) < rlen) { - while(DIRSIZ_LEN(o_slen) < rlen) { + while (DIRSIZ_LEN(o_slen) < rlen) { int minLen = rlen - DIRSIZ_LEN(o_slen); if (minLen > sizeof(bufofzeros)) minLen = sizeof(bufofzeros); @@ -640,7 +695,7 @@ tagain: #else code = afs_readdir_move(ode, avc, auio, o_slen, #if defined(AFS_SUN5_ENV) - len, origOffset); + len, origOffset); #else auio->afsio_resid, origOffset); #endif @@ -651,10 +706,12 @@ tagain: } else { /* nothin to hand over */ } -#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - if (eofp) *eofp = 1; /* Set it properly */ +#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + if (eofp) + *eofp = 1; /* Set it properly */ #endif - if (ode) DRelease(ode, 0); + if (ode) + DRelease((struct buffer *)ode, 0); goto dirend; } /* by here nde is set */ @@ -666,33 +723,37 @@ tagain: n_slen = strlen(nde->name); #endif #ifdef AFS_SGI53_ENV - dirsiz = use64BitDirent ? DIRENTSIZE(n_slen) : - IRIX5_DIRENTSIZE(n_slen); - if (dirsiz >= (auio->afsio_resid-len)) { + dirsiz = + use64BitDirent ? DIRENTSIZE(n_slen) : IRIX5_DIRENTSIZE(n_slen); + if (dirsiz >= (auio->afsio_resid - len)) { #else - if (DIRSIZ_LEN(n_slen) >= (auio->afsio_resid-len)) { + if (DIRSIZ_LEN(n_slen) >= (auio->afsio_resid - len)) { #endif /* AFS_SGI53_ENV */ /* No can do no more now; ya know... at this time */ - DRelease (nde, 0); /* can't use this one. */ + DRelease((struct buffer *)nde, 0); /* can't use this one. */ if (len) { #ifdef AFS_HPUX_ENV - sdirEntry->d_fileno = (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); + sdirEntry->d_fileno = + (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); FIXUPSTUPIDINODE(sdirEntry->d_fileno); sdirEntry->d_reclen = rlen = auio->afsio_resid; sdirEntry->d_namlen = o_slen; #if defined(AFS_SUN_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_HPUX100_ENV) sdirEntry->d_off = origOffset; #endif - AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, auio, code); + AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, + auio, code); if (code == 0) AFS_UIOMOVE(ode->name, o_slen, UIO_READ, auio, code); /* pad out the remaining characters with zeros */ if (code == 0) { - AFS_UIOMOVE(bufofzeros, ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, UIO_READ, auio, code); + AFS_UIOMOVE(bufofzeros, + ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, + UIO_READ, auio, code); } /* pad out the difference between rlen and slen... */ if (DIRSIZ_LEN(o_slen) < rlen) { - while(DIRSIZ_LEN(o_slen) < rlen) { + while (DIRSIZ_LEN(o_slen) < rlen) { int minLen = rlen - DIRSIZ_LEN(o_slen); if (minLen > sizeof(bufofzeros)) minLen = sizeof(bufofzeros); @@ -701,21 +762,23 @@ tagain: } } #else /* AFS_HPUX_ENV */ - code = afs_readdir_move(ode, avc, auio, o_slen, - auio->afsio_resid, origOffset); + code = + afs_readdir_move(ode, avc, auio, o_slen, + auio->afsio_resid, origOffset); #endif /* AFS_HPUX_ENV */ /* this next line used to be AFSVFS40 or AIX 3.1, but is * really generic */ auio->afsio_offset = origOffset; - auio->afsio_resid = 0; - } else { /* trouble, can't give anything to the user! */ + auio->afsio_resid = 0; + } else { /* trouble, can't give anything to the user! */ /* even though he has given us a buffer, * even though we have something to give us, * Looks like we lost something somewhere. */ code = EINVAL; } - if (ode) DRelease(ode, 0); + if (ode) + DRelease((struct buffer *)ode, 0); goto dirend; } @@ -733,18 +796,19 @@ tagain: #if defined(AFS_SUN_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_HPUX100_ENV) sdirEntry->d_off = origOffset; #endif - AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, - auio, code); + AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, auio, + code); if (code == 0) AFS_UIOMOVE(ode->name, o_slen, UIO_READ, auio, code); /* pad out the remaining characters with zeros */ if (code == 0) { - AFS_UIOMOVE(bufofzeros, ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, + AFS_UIOMOVE(bufofzeros, + ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, UIO_READ, auio, code); } /* pad out the difference between rlen and slen... */ if (DIRSIZ_LEN(o_slen) < rlen) { - while(DIRSIZ_LEN(o_slen) < rlen) { + while (DIRSIZ_LEN(o_slen) < rlen) { int minLen = rlen - DIRSIZ_LEN(o_slen); if (minLen > sizeof(bufofzeros)) minLen = sizeof(bufofzeros); @@ -753,26 +817,31 @@ tagain: } } #else /* AFS_HPUX_ENV */ - code = afs_readdir_move (ode, avc, auio, o_slen, len, origOffset); + code = afs_readdir_move(ode, avc, auio, o_slen, len, origOffset); #endif /* AFS_HPUX_ENV */ } #ifdef AFS_SGI53_ENV - len = use64BitDirent ? DIRENTSIZE(o_slen = n_slen) : - IRIX5_DIRENTSIZE(o_slen = n_slen); + len = use64BitDirent ? DIRENTSIZE(o_slen = + n_slen) : IRIX5_DIRENTSIZE(o_slen = + n_slen); #else - len = DIRSIZ_LEN( o_slen = n_slen ); + len = DIRSIZ_LEN(o_slen = n_slen); #endif /* AFS_SGI53_ENV */ - if (ode) DRelease(ode, 0); + if (ode) + DRelease((struct buffer *)ode, 0); ode = nde; - auio->afsio_offset = (afs_int32)((us + afs_dir_NameBlobs(nde->name)) << 5); + auio->afsio_offset = + (afs_int32) ((us + afs_dir_NameBlobs(nde->name)) << 5); } - if (ode) DRelease(ode, 0); + if (ode) + DRelease((struct buffer *)ode, 0); -dirend: + dirend: + ReleaseReadLock(&tdc->lock); afs_PutDCache(tdc); ReleaseReadLock(&avc->lock); -done: + done: #ifdef AFS_HPUX_ENV osi_FreeSmallSpace((char *)sdirEntry); #endif @@ -784,16 +853,17 @@ done: #if defined(AFS_HPUX_ENV) || defined(AFS_OSF_ENV) #ifdef AFS_OSF_ENV afs1_readdir(avc, auio, acred, eofp) - int *eofp; + int *eofp; #else afs1_readdir(avc, auio, acred) #endif - struct vcache *avc; - struct uio *auio; - struct AFS_UCRED *acred; { + struct vcache *avc; + struct uio *auio; + struct AFS_UCRED *acred; +{ struct vrequest treq; register struct dcache *tdc; - afs_int32 origOffset, len; + afs_size_t origOffset, len; int code = 0; struct DirEntry *ode = 0, *nde = 0; int o_slen = 0, n_slen = 0; @@ -804,14 +874,16 @@ afs1_readdir(avc, auio, acred) * it is necessary for hpux due to stack problems that seem to occur when coming thru the nfs * translator side XXX */ - struct minnfs_direct *sdirEntry = (struct minnfs_direct *)osi_AllocSmallSpace(sizeof(struct min_direct)); + struct minnfs_direct *sdirEntry = (struct minnfs_direct *) + osi_AllocSmallSpace(sizeof(struct min_direct)); afs_int32 rlen; #endif struct afs_fakestat_state fakestate; AFS_STATCNT(afs_readdir); #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) - if (eofp) *eofp = 0; + if (eofp) + *eofp = 0; #endif if (code = afs_InitReq(&treq, acred)) { #ifdef AFS_HPUX_ENV @@ -829,16 +901,18 @@ afs1_readdir(avc, auio, acred) return code; } /* update the cache entry */ -tagain: + tagain: code = afs_VerifyVCache(avc, &treq); - if (code) goto done; + if (code) + goto done; /* get a reference to the entire directory */ - tdc = afs_GetDCache(avc, 0, &treq, &origOffset, &len, 1); + tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &len, 1); if (!tdc) { code = ENOENT; goto done; } ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); /* * Make sure that the data in the cache is current. There are two @@ -847,15 +921,20 @@ tagain: * 2. The cache data is no longer valid */ while ((avc->states & CStatd) - && (tdc->flags & DFFetching) + && (tdc->dflags & DFFetching) && hsame(avc->m.DataVersion, tdc->f.versionNo)) { - tdc->flags |= DFWaiting; + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, ICL_TYPE_POINTER, tdc, + ICL_TYPE_INT32, tdc->dflags); + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); afs_osi_Sleep(&tdc->validPos); ObtainReadLock(&avc->lock); + ObtainReadLock(&tdc->lock); } if (!(avc->states & CStatd) || !hsame(avc->m.DataVersion, tdc->f.versionNo)) { + ReleaseReadLock(&tdc->lock); ReleaseReadLock(&avc->lock); afs_PutDCache(tdc); goto tagain; @@ -865,34 +944,38 @@ tagain: #ifdef AFS_HPUX_ENV auio->uio_fpflags = 0; #endif - while (code==0) { + while (code == 0) { origOffset = auio->afsio_offset; /* scan for the next interesting entry scan for in-use blob otherwise up point at * this blob note that ode, if non-zero, also represents a held dir page */ - if (!(us = BlobScan(&tdc->f.inode, (origOffset >> 5)) ) - || !(nde = (struct DirEntry *) afs_dir_GetBlob(&tdc->f.inode, us) ) ) { + if (!(us = BlobScan(&tdc->f.inode, (origOffset >> 5))) + || !(nde = (struct DirEntry *)afs_dir_GetBlob(&tdc->f.inode, us))) { /* failed to setup nde, return what we've got, and release ode */ if (len) { /* something to hand over. */ #if defined(AFS_HPUX_ENV) || defined(AFS_OSF_ENV) - sdirEntry->d_fileno = (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); + sdirEntry->d_fileno = + (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); FIXUPSTUPIDINODE(sdirEntry->d_fileno); sdirEntry->d_reclen = rlen = auio->afsio_resid; sdirEntry->d_namlen = o_slen; sdirEntry->d_off = origOffset; - AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, auio, code); + AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, + auio, code); if (code == 0) { AFS_UIOMOVE(ode->name, o_slen, UIO_READ, auio, code); } /* pad out the remaining characters with zeros */ if (code == 0) { - AFS_UIOMOVE(bufofzeros, ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, UIO_READ, auio, code); + AFS_UIOMOVE(bufofzeros, + ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, + UIO_READ, auio, code); } /* pad out the difference between rlen and slen... */ if (NDIRSIZ_LEN(o_slen) < rlen) { - while(NDIRSIZ_LEN(o_slen) < rlen) { - int minLen = rlen - NDIRSIZ_LEN(o_slen); + while (NDIRSIZ_LEN(o_slen) < rlen) { + int minLen = rlen - NDIRSIZ_LEN(o_slen); if (minLen > sizeof(bufofzeros)) minLen = sizeof(bufofzeros); AFS_UIOMOVE(bufofzeros, minLen, UIO_READ, auio, code); @@ -900,17 +983,20 @@ tagain: } } #else - code = afs_readdir_move(ode, avc, auio, o_slen, - auio->afsio_resid, origOffset); + code = + afs_readdir_move(ode, avc, auio, o_slen, + auio->afsio_resid, origOffset); #endif /* AFS_HPUX_ENV */ - auio->afsio_resid = 0; + auio->afsio_resid = 0; } else { /* nothin to hand over */ } #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) - if (eofp) *eofp = 1; + if (eofp) + *eofp = 1; #endif - if (ode) DRelease(ode, 0); + if (ode) + DRelease(ode, 0); goto dirend; } /* by here nde is set */ @@ -921,26 +1007,30 @@ tagain: #else n_slen = strlen(nde->name); #endif - if (NDIRSIZ_LEN(n_slen) >= (auio->afsio_resid-len)) { + if (NDIRSIZ_LEN(n_slen) >= (auio->afsio_resid - len)) { /* No can do no more now; ya know... at this time */ - DRelease (nde, 0); /* can't use this one. */ + DRelease(nde, 0); /* can't use this one. */ if (len) { #if defined(AFS_HPUX_ENV) || defined(AFS_OSF_ENV) - sdirEntry->d_fileno = (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); + sdirEntry->d_fileno = + (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); FIXUPSTUPIDINODE(sdirEntry->d_fileno); sdirEntry->d_reclen = rlen = auio->afsio_resid; sdirEntry->d_namlen = o_slen; sdirEntry->d_off = origOffset; - AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, auio, code); + AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, + auio, code); if (code == 0) AFS_UIOMOVE(ode->name, o_slen, UIO_READ, auio, code); /* pad out the remaining characters with zeros */ if (code == 0) { - AFS_UIOMOVE(bufofzeros, ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, UIO_READ, auio, code); + AFS_UIOMOVE(bufofzeros, + ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, + UIO_READ, auio, code); } /* pad out the difference between rlen and slen... */ if (NDIRSIZ_LEN(o_slen) < rlen) { - while(NDIRSIZ_LEN(o_slen) < rlen) { + while (NDIRSIZ_LEN(o_slen) < rlen) { int minLen = rlen - NDIRSIZ_LEN(o_slen); if (minLen > sizeof(bufofzeros)) minLen = sizeof(bufofzeros); @@ -949,20 +1039,22 @@ tagain: } } #else - code = afs_readdir_move(ode, avc, auio, o_slen, - auio->afsio_resid, origOffset); + code = + afs_readdir_move(ode, avc, auio, o_slen, + auio->afsio_resid, origOffset); #endif /* AFS_HPUX_ENV */ /* this next line used to be AFSVFS40 or AIX 3.1, but is really generic */ auio->afsio_offset = origOffset; - auio->afsio_resid = 0; - } else { /* trouble, can't give anything to the user! */ + auio->afsio_resid = 0; + } else { /* trouble, can't give anything to the user! */ /* even though he has given us a buffer, * even though we have something to give us, * Looks like we lost something somewhere. */ code = EINVAL; } - if (ode) DRelease(ode, 0); + if (ode) + DRelease(ode, 0); goto dirend; } @@ -972,21 +1064,25 @@ tagain: */ if (len) { #if defined(AFS_HPUX_ENV) || defined(AFS_OSF_ENV) - sdirEntry->d_fileno = (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); + sdirEntry->d_fileno = + (avc->fid.Fid.Volume << 16) + ntohl(ode->fid.vnode); FIXUPSTUPIDINODE(sdirEntry->d_fileno); sdirEntry->d_reclen = rlen = len; sdirEntry->d_namlen = o_slen; sdirEntry->d_off = origOffset; - AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, auio, code); + AFS_UIOMOVE((char *)sdirEntry, sizeof(*sdirEntry), UIO_READ, auio, + code); if (code == 0) AFS_UIOMOVE(ode->name, o_slen, UIO_READ, auio, code); /* pad out the remaining characters with zeros */ if (code == 0) { - AFS_UIOMOVE(bufofzeros, ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, UIO_READ, auio, code); + AFS_UIOMOVE(bufofzeros, + ((o_slen + 1 + DIRPAD) & ~DIRPAD) - o_slen, + UIO_READ, auio, code); } /* pad out the difference between rlen and slen... */ if (NDIRSIZ_LEN(o_slen) < rlen) { - while(NDIRSIZ_LEN(o_slen) < rlen) { + while (NDIRSIZ_LEN(o_slen) < rlen) { int minLen = rlen - NDIRSIZ_LEN(o_slen); if (minLen > sizeof(bufofzeros)) minLen = sizeof(bufofzeros); @@ -995,21 +1091,24 @@ tagain: } } #else - code = afs_readdir_move (ode, avc, auio, o_slen, len, origOffset); + code = afs_readdir_move(ode, avc, auio, o_slen, len, origOffset); #endif /* AFS_HPUX_ENV */ } - len = NDIRSIZ_LEN( o_slen = n_slen ); - if (ode) DRelease(ode, 0); + len = NDIRSIZ_LEN(o_slen = n_slen); + if (ode) + DRelease(ode, 0); ode = nde; auio->afsio_offset = ((us + afs_dir_NameBlobs(nde->name)) << 5); } - if (ode) DRelease(ode, 0); + if (ode) + DRelease(ode, 0); -dirend: + dirend: + ReleaseReadLock(&tdc->lock); afs_PutDCache(tdc); ReleaseReadLock(&avc->lock); -done: + done: #if defined(AFS_HPUX_ENV) || defined(AFS_OSF_ENV) osi_FreeSmallSpace((char *)sdirEntry); #endif diff --git a/src/afs/VNOPS/afs_vnop_remove.c b/src/afs/VNOPS/afs_vnop_remove.c index 39e680eb3..55c060eaf 100644 --- a/src/afs/VNOPS/afs_vnop_remove.c +++ b/src/afs/VNOPS/afs_vnop_remove.c @@ -20,16 +20,17 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_remove.c,v 1.1.1.9 2002/08/02 04:29:03 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_remove.c,v 1.28 2004/04/05 06:26:17 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern afs_rwlock_t afs_xvcache; @@ -45,36 +46,41 @@ extern afs_rwlock_t afs_xcbhash; * afs_IsWired notices that the file is no longer Active. */ afs_Wire(avc, areq) -#else /* AFS_OSF_ENV */ -static void FetchWholeEnchilada(avc, areq) +#else /* AFS_OSF_ENV */ +static void +FetchWholeEnchilada(avc, areq) #endif -struct vrequest *areq; -register struct vcache *avc; { - register afs_int32 nextChunk, pos; + struct vrequest *areq; + register struct vcache *avc; +{ + register afs_int32 nextChunk; register struct dcache *tdc; - afs_int32 offset, len; + afs_size_t pos, offset, len; AFS_STATCNT(FetchWholeEnchilada); - if ((avc->states & CStatd) == 0) return; /* don't know size */ - for(nextChunk=0;nextChunk<1024;nextChunk++) { /* sanity check on N chunks */ + if ((avc->states & CStatd) == 0) + return; /* don't know size */ + for (nextChunk = 0; nextChunk < 1024; nextChunk++) { /* sanity check on N chunks */ pos = AFS_CHUNKTOBASE(nextChunk); #if defined(AFS_OSF_ENV) - if (pos >= avc->m.Length) break; /* all done */ -#else /* AFS_OSF_ENV */ - if (pos >= avc->m.Length) return; /* all done */ + if (pos >= avc->m.Length) + break; /* all done */ +#else /* AFS_OSF_ENV */ + if (pos >= avc->m.Length) + return; /* all done */ #endif tdc = afs_GetDCache(avc, pos, areq, &offset, &len, 0); - if (!tdc) + if (!tdc) #if defined(AFS_OSF_ENV) break; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ return; #endif afs_PutDCache(tdc); } #if defined(AFS_OSF_ENV) avc->states |= CWired; -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ } #if defined(AFS_OSF_ENV) @@ -83,7 +89,8 @@ register struct vcache *avc; { * is found to be inactive (ie not open and not being paged from). */ afs_IsWired(avc) - register struct vcache *avc; { + register struct vcache *avc; +{ if (avc->states & CWired) { if (osi_Active(avc)) { return 1; @@ -92,59 +99,59 @@ afs_IsWired(avc) } return 0; } -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ -afsremove(adp, tdc, tvc, aname, acred, treqp) - register struct vcache *adp; - register struct dcache *tdc; - register struct vcache *tvc; - char *aname; - struct vrequest *treqp; - struct AFS_UCRED *acred; { +int +afsremove(register struct vcache *adp, register struct dcache *tdc, + register struct vcache *tvc, char *aname, struct AFS_UCRED *acred, + struct vrequest *treqp) +{ register afs_int32 code; register struct conn *tc; - afs_int32 offset, len; struct AFSFetchStatus OutDirStatus; struct AFSVolSync tsync; XSTATS_DECLS - do { tc = afs_Conn(&adp->fid, treqp, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_RemoveFile(tc->id, (struct AFSFid *) &adp->fid.Fid, - aname, &OutDirStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &adp->fid, treqp, - AFS_STATS_FS_RPCIDX_REMOVEFILE, SHARED_LOCK, (struct cell *)0)); - - osi_dnlc_remove (adp, aname, tvc); - if (tvc) afs_symhint_inval(tvc); /* XXX: don't really need to be so extreme */ + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE); + RX_AFS_GUNLOCK(); + code = + RXAFS_RemoveFile(tc->id, (struct AFSFid *)&adp->fid.Fid, + aname, &OutDirStatus, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &adp->fid, treqp, AFS_STATS_FS_RPCIDX_REMOVEFILE, + SHARED_LOCK, NULL)); + + osi_dnlc_remove(adp, aname, tvc); + if (tvc) + afs_symhint_inval(tvc); /* XXX: don't really need to be so extreme */ if (code) { - if (tdc) afs_PutDCache(tdc); - if (tvc) afs_PutVCache(tvc, WRITE_LOCK); + if (tdc) { + ReleaseSharedLock(&tdc->lock); + afs_PutDCache(tdc); + } + if (tvc) + afs_PutVCache(tvc); if (code < 0) { - ObtainWriteLock(&afs_xcbhash, 497); - afs_DequeueCallback(adp); - adp->states &= ~CStatd; - ReleaseWriteLock(&afs_xcbhash); - osi_dnlc_purgedp(adp); + ObtainWriteLock(&afs_xcbhash, 497); + afs_DequeueCallback(adp); + adp->states &= ~CStatd; + ReleaseWriteLock(&afs_xcbhash); + osi_dnlc_purgedp(adp); } ReleaseWriteLock(&adp->lock); code = afs_CheckCode(code, treqp, 21); return code; } + if (tdc) + UpgradeSToWLock(&tdc->lock, 637); if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ code = afs_dir_Delete(&tdc->f.inode, aname); @@ -154,6 +161,7 @@ afsremove(adp, tdc, tvc, aname, acred, treqp) } } if (tdc) { + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); /* drop ref count */ } ReleaseWriteLock(&adp->lock); @@ -164,34 +172,38 @@ afsremove(adp, tdc, tvc, aname, acred, treqp) * gone, we won't be able to fetch the status info anyway. */ if (tvc) { #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) - afs_BozonLock(&tvc->pvnLock, tvc); + afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */ #endif - ObtainWriteLock(&tvc->lock,141); + ObtainWriteLock(&tvc->lock, 141); /* note that callback will be broken on the deleted file if there are * still >0 links left to it, so we'll get the stat right */ tvc->m.LinkCount--; - tvc->states &= ~CUnique; /* For the dfs xlator */ + tvc->states &= ~CUnique; /* For the dfs xlator */ if (tvc->m.LinkCount == 0 && !osi_Active(tvc)) { - if (!AFS_NFSXLATORREQ(acred)) afs_TryToSmush(tvc, acred, 0); - } + if (!AFS_NFSXLATORREQ(acred)) + afs_TryToSmush(tvc, acred, 0); + } ReleaseWriteLock(&tvc->lock); #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonUnlock(&tvc->pvnLock, tvc); #endif - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); } return (0); } -static char *newname() { +static char * +newname(void) +{ char *name, *sp, *p = ".__afs"; afs_int32 rd = afs_random() & 0xffff; sp = name = osi_AllocSmallSpace(AFS_SMALLOCSIZ); - while (*p != '\0') *sp++ = *p++; + while (*p != '\0') + *sp++ = *p++; while (rd) { - *sp++= "0123456789ABCDEF"[rd & 0x0f]; + *sp++ = "0123456789ABCDEF"[rd & 0x0f]; rd >>= 4; } *sp = '\0'; @@ -199,51 +211,51 @@ static char *newname() { } /* these variables appear to exist for debugging purposes */ -struct vcache * Tadp1, * Ttvc; +struct vcache *Tadp1, *Ttvc; int Tadpr, Ttvcr; char *Tnam; char *Tnam1; /* Note that we don't set CDirty here, this is OK because the unlink * RPC is called synchronously */ +int #ifdef AFS_OSF_ENV afs_remove(ndp) - struct nameidata *ndp; { + struct nameidata *ndp; +{ register struct vcache *adp = VTOAFS(ndp->ni_dvp); char *aname = ndp->ni_dent.d_name; struct ucred *acred = ndp->ni_cred; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ afs_remove(OSI_VC_ARG(adp), aname, acred) - OSI_VC_DECL(adp); - char *aname; - struct AFS_UCRED *acred; { +OSI_VC_DECL(adp); + char *aname; + struct AFS_UCRED *acred; +{ #endif struct vrequest treq; register struct dcache *tdc; struct VenusFid unlinkFid; register afs_int32 code; register struct vcache *tvc; - afs_int32 offset, len; - struct AFSFetchStatus OutDirStatus; - struct AFSVolSync tsync; + afs_size_t offset, len; struct afs_fakestat_state fakestate; - XSTATS_DECLS OSI_VC_CONVERT(adp) - AFS_STATCNT(afs_remove); + AFS_STATCNT(afs_remove); afs_Trace2(afs_iclSetp, CM_TRACE_REMOVE, ICL_TYPE_POINTER, adp, ICL_TYPE_STRING, aname); #ifdef AFS_OSF_ENV - tvc = (struct vcache *)ndp->ni_vp; /* should never be null */ + tvc = (struct vcache *)ndp->ni_vp; /* should never be null */ #endif - if (code = afs_InitReq(&treq, acred)) { + if ((code = afs_InitReq(&treq, acred))) { #ifdef AFS_OSF_ENV - afs_PutVCache(adp, 0); - afs_PutVCache(tvc, 0); + afs_PutVCache(adp); + afs_PutVCache(tvc); #endif - return code; + return code; } afs_InitFakeStat(&fakestate); @@ -251,8 +263,8 @@ afs_remove(OSI_VC_ARG(adp), aname, acred) if (code) { afs_PutFakeStat(&fakestate); #ifdef AFS_OSF_ENV - afs_PutVCache(adp, 0); - afs_PutVCache(tvc, 0); + afs_PutVCache(adp); + afs_PutVCache(tvc); #endif return code; } @@ -262,31 +274,43 @@ afs_remove(OSI_VC_ARG(adp), aname, acred) code = afs_DynrootVOPRemove(adp, acred, aname); afs_PutFakeStat(&fakestate); #ifdef AFS_OSF_ENV - afs_PutVCache(adp, 0); - afs_PutVCache(tvc, 0); + afs_PutVCache(adp); + afs_PutVCache(tvc); #endif return code; } + +#if 0 + if (adp->mvstat == 2) { + afs_PutFakeStat(&fakestate); +#ifdef AFS_OSF_ENV + afs_PutVCache(adp); + afs_PutVCache(tvc); +#endif + return EISDIR; + } +#endif + if (strlen(aname) > AFSNAMEMAX) { afs_PutFakeStat(&fakestate); #ifdef AFS_OSF_ENV - afs_PutVCache(adp, 0); - afs_PutVCache(tvc, 0); + afs_PutVCache(adp); + afs_PutVCache(tvc); #endif return ENAMETOOLONG; } -tagain: + tagain: code = afs_VerifyVCache(adp, &treq); #ifdef AFS_OSF_ENV - tvc = VTOAFS(ndp->ni_vp); /* should never be null */ + tvc = VTOAFS(ndp->ni_vp); /* should never be null */ if (code) { - afs_PutVCache(adp, 0); - afs_PutVCache(tvc, 0); + afs_PutVCache(adp); + afs_PutVCache(tvc); afs_PutFakeStat(&fakestate); return afs_CheckCode(code, &treq, 22); } -#else /* AFS_OSF_ENV */ - tvc = (struct vcache *) 0; +#else /* AFS_OSF_ENV */ + tvc = NULL; if (code) { code = afs_CheckCode(code, &treq, 23); afs_PutFakeStat(&fakestate); @@ -297,18 +321,20 @@ tagain: /** If the volume is read-only, return error without making an RPC to the * fileserver */ - if ( adp->states & CRO ) { + if (adp->states & CRO) { #ifdef AFS_OSF_ENV - afs_PutVCache(adp, 0); - afs_PutVCache(tvc, 0); + afs_PutVCache(adp); + afs_PutVCache(tvc); #endif - code = EROFS; + code = EROFS; afs_PutFakeStat(&fakestate); return code; } - tdc = afs_GetDCache(adp, 0, &treq, &offset, &len, 1); /* test for error below */ - ObtainWriteLock(&adp->lock,142); + tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */ + ObtainWriteLock(&adp->lock, 142); + if (tdc) + ObtainSharedLock(&tdc->lock, 638); /* * Make sure that the data in the cache is current. We may have @@ -317,63 +343,75 @@ tagain: if (!(adp->states & CStatd) || (tdc && !hsame(adp->m.DataVersion, tdc->f.versionNo))) { ReleaseWriteLock(&adp->lock); - if (tdc) + if (tdc) { + ReleaseSharedLock(&tdc->lock); afs_PutDCache(tdc); + } goto tagain; } unlinkFid.Fid.Vnode = 0; if (!tvc) { - tvc = osi_dnlc_lookup (adp, aname, WRITE_LOCK); + tvc = osi_dnlc_lookup(adp, aname, WRITE_LOCK); } /* This should not be necessary since afs_lookup() has already * done the work */ if (!tvc) - if (tdc) { - code = afs_dir_Lookup(&tdc->f.inode, aname, &unlinkFid.Fid); - if (code == 0) { - afs_int32 cached=0; - - unlinkFid.Cell = adp->fid.Cell; - unlinkFid.Fid.Volume = adp->fid.Fid.Volume; - if (unlinkFid.Fid.Unique == 0) { - tvc = afs_LookupVCache(&unlinkFid, &treq, &cached, - WRITE_LOCK, adp, aname); - } else { - ObtainReadLock(&afs_xvcache); - tvc = afs_FindVCache(&unlinkFid, 1, WRITE_LOCK, - 0 , DO_STATS ); - ReleaseReadLock(&afs_xvcache); + if (tdc) { + code = afs_dir_Lookup(&tdc->f.inode, aname, &unlinkFid.Fid); + if (code == 0) { + afs_int32 cached = 0; + + unlinkFid.Cell = adp->fid.Cell; + unlinkFid.Fid.Volume = adp->fid.Fid.Volume; + if (unlinkFid.Fid.Unique == 0) { + tvc = + afs_LookupVCache(&unlinkFid, &treq, &cached, adp, + aname); + } else { + ObtainReadLock(&afs_xvcache); + tvc = afs_FindVCache(&unlinkFid, 0, DO_STATS); + ReleaseReadLock(&afs_xvcache); + } } } - } if (tvc && osi_Active(tvc)) { /* about to delete whole file, prefetch it first */ ReleaseWriteLock(&adp->lock); - ObtainWriteLock(&tvc->lock,143); + ObtainWriteLock(&tvc->lock, 143); #if defined(AFS_OSF_ENV) afs_Wire(tvc, &treq); -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ FetchWholeEnchilada(tvc, &treq); #endif ReleaseWriteLock(&tvc->lock); - ObtainWriteLock(&adp->lock,144); + ObtainWriteLock(&adp->lock, 144); } - osi_dnlc_remove ( adp, aname, tvc); - if (tvc) afs_symhint_inval(tvc); - - Tadp1 = adp; Tadpr = VREFCOUNT(adp); Ttvc = tvc; Tnam = aname; Tnam1 = 0; - if (tvc) Ttvcr = VREFCOUNT(tvc); + osi_dnlc_remove(adp, aname, tvc); + if (tvc) + afs_symhint_inval(tvc); + + Tadp1 = adp; + Tadpr = VREFCOUNT(adp); + Ttvc = tvc; + Tnam = aname; + Tnam1 = 0; + if (tvc) + Ttvcr = VREFCOUNT(tvc); #ifdef AFS_AIX_ENV - if (tvc && (VREFCOUNT(tvc) > 2) && tvc->opens > 0 && !(tvc->states & CUnlinked)) { + if (tvc && (VREFCOUNT(tvc) > 2) && tvc->opens > 0 + && !(tvc->states & CUnlinked)) { #else - if (tvc && (VREFCOUNT(tvc) > 1) && tvc->opens > 0 && !(tvc->states & CUnlinked)) { + if (tvc && (VREFCOUNT(tvc) > 1) && tvc->opens > 0 + && !(tvc->states & CUnlinked)) { #endif char *unlname = newname(); ReleaseWriteLock(&adp->lock); + if (tdc) + ReleaseSharedLock(&tdc->lock); code = afsrename(adp, aname, adp, unlname, acred, &treq); Tnam1 = unlname; if (!code) { @@ -385,17 +423,17 @@ tagain: tvc->uncred = acred; tvc->states |= CUnlinked; } else { - osi_FreeSmallSpace(unlname); + osi_FreeSmallSpace(unlname); } - if ( tdc ) - afs_PutDCache(tdc); - afs_PutVCache(tvc, WRITE_LOCK); + if (tdc) + afs_PutDCache(tdc); + afs_PutVCache(tvc); } else { code = afsremove(adp, tdc, tvc, aname, acred, &treq); } #ifdef AFS_OSF_ENV - afs_PutVCache(adp, WRITE_LOCK); -#endif /* AFS_OSF_ENV */ + afs_PutVCache(adp); +#endif /* AFS_OSF_ENV */ afs_PutFakeStat(&fakestate); return code; } @@ -406,9 +444,8 @@ tagain: * * CAUTION -- may be called with avc unheld. */ -afs_remunlink(avc, doit) - register struct vcache *avc; - register int doit; +int +afs_remunlink(register struct vcache *avc, register int doit) { struct AFS_UCRED *cred; char *unlname; @@ -416,16 +453,15 @@ afs_remunlink(avc, doit) struct vrequest treq; struct VenusFid dirFid; register struct dcache *tdc; - afs_int32 offset, len, code=0; + afs_int32 code = 0; if (NBObtainWriteLock(&avc->lock, 423)) return 0; if (avc->mvid && (doit || (avc->states & CUnlinkedDel))) { - if (code = afs_InitReq(&treq, avc->uncred)) { + if ((code = afs_InitReq(&treq, avc->uncred))) { ReleaseWriteLock(&avc->lock); - } - else { + } else { /* Must bump the refCount because GetVCache may block. * Also clear mvid so no other thread comes here if we block. */ @@ -435,22 +471,22 @@ afs_remunlink(avc, doit) avc->uncred = NULL; #ifdef AFS_DARWIN_ENV - /* this is called by vrele (via VOP_INACTIVE) when the refcount - is 0. we can't just call VN_HOLD since vref will panic. - we can't just call osi_vnhold because a later AFS_RELE will call - vrele again, which will try to call VOP_INACTIVE again after - vn_locking the vnode. which would be fine except that our vrele - caller also locked the vnode... So instead, we just gimmick the - refcounts and hope nobody else can touch the file now */ + /* this is called by vrele (via VOP_INACTIVE) when the refcount + * is 0. we can't just call VN_HOLD since vref will panic. + * we can't just call osi_vnhold because a later AFS_RELE will call + * vrele again, which will try to call VOP_INACTIVE again after + * vn_locking the vnode. which would be fine except that our vrele + * caller also locked the vnode... So instead, we just gimmick the + * refcounts and hope nobody else can touch the file now */ osi_Assert(VREFCOUNT(avc) == 0); VREFCOUNT_SET(avc, 1); #endif - VN_HOLD(&avc->v); + VN_HOLD(AFSTOV(avc)); /* We'll only try this once. If it fails, just release the vnode. * Clear after doing hold so that NewVCache doesn't find us yet. */ - avc->states &= ~(CUnlinked | CUnlinkedDel); + avc->states &= ~(CUnlinked | CUnlinkedDel); ReleaseWriteLock(&avc->lock); @@ -458,19 +494,20 @@ afs_remunlink(avc, doit) dirFid.Fid.Volume = avc->fid.Fid.Volume; dirFid.Fid.Vnode = avc->parentVnode; dirFid.Fid.Unique = avc->parentUnique; - adp = afs_GetVCache(&dirFid, &treq, (afs_int32 *)0, - (struct vcache *)0, WRITE_LOCK); - + adp = afs_GetVCache(&dirFid, &treq, NULL, NULL); + if (adp) { - tdc = afs_FindDCache(adp, 0); + tdc = afs_FindDCache(adp, (afs_size_t) 0); ObtainWriteLock(&adp->lock, 159); + if (tdc) + ObtainSharedLock(&tdc->lock, 639); - /* afsremove releases the adp lock, and does vn_rele(avc) */ + /* afsremove releases the adp & tdc locks, and does vn_rele(avc) */ code = afsremove(adp, tdc, avc, unlname, cred, &treq); - afs_PutVCache(adp, WRITE_LOCK); + afs_PutVCache(adp); } else { /* we failed - and won't be back to try again. */ - afs_PutVCache(avc, WRITE_LOCK); + afs_PutVCache(avc); } osi_FreeSmallSpace(unlname); crfree(cred); @@ -478,9 +515,8 @@ afs_remunlink(avc, doit) osi_Assert(VREFCOUNT(avc) == 1); VREFCOUNT_SET(avc, 0); #endif - } - } - else { + } + } else { ReleaseWriteLock(&avc->lock); } diff --git a/src/afs/VNOPS/afs_vnop_rename.c b/src/afs/VNOPS/afs_vnop_rename.c index 90b5fd14e..419e68554 100644 --- a/src/afs/VNOPS/afs_vnop_rename.c +++ b/src/afs/VNOPS/afs_vnop_rename.c @@ -15,42 +15,39 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_rename.c,v 1.1.1.6 2002/08/02 04:29:03 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_rename.c,v 1.16 2003/08/29 22:00:04 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern afs_rwlock_t afs_xcbhash; /* Note that we don't set CDirty here, this is OK because the rename * RPC is called synchronously. */ -afsrename(aodp, aname1, andp, aname2, acred, areq) - struct vcache *aodp, *andp; - char *aname1, *aname2; - struct AFS_UCRED *acred; - struct vrequest *areq; +int +afsrename(struct vcache *aodp, char *aname1, struct vcache *andp, + char *aname2, struct AFS_UCRED *acred, struct vrequest *areq) { register struct conn *tc; register afs_int32 code; afs_int32 returnCode; int oneDir, doLocally; - afs_int32 offset, len; + afs_size_t offset, len; struct VenusFid unlinkFid, fileFid; struct vcache *tvc; struct dcache *tdc1, *tdc2; struct AFSFetchStatus OutOldDirStatus, OutNewDirStatus; struct AFSVolSync tsync; - XSTATS_DECLS - - AFS_STATCNT(afs_rename); - afs_Trace4(afs_iclSetp, CM_TRACE_RENAME, ICL_TYPE_POINTER, aodp, + XSTATS_DECLS AFS_STATCNT(afs_rename); + afs_Trace4(afs_iclSetp, CM_TRACE_RENAME, ICL_TYPE_POINTER, aodp, ICL_TYPE_STRING, aname1, ICL_TYPE_POINTER, andp, ICL_TYPE_STRING, aname2); @@ -60,18 +57,22 @@ afsrename(aodp, aname1, andp, aname2, acred, areq) } /* verify the latest versions of the stat cache entries */ -tagain: + tagain: code = afs_VerifyVCache(aodp, areq); - if (code) goto done; + if (code) + goto done; code = afs_VerifyVCache(andp, areq); - if (code) goto done; - + if (code) + goto done; + /* lock in appropriate order, after some checks */ - if (aodp->fid.Cell != andp->fid.Cell || aodp->fid.Fid.Volume != andp->fid.Fid.Volume) { + if (aodp->fid.Cell != andp->fid.Cell + || aodp->fid.Fid.Volume != andp->fid.Fid.Volume) { code = EXDEV; goto done; } oneDir = 0; + code = 0; if (andp->fid.Fid.Vnode == aodp->fid.Fid.Vnode) { if (!strcmp(aname1, aname2)) { /* Same directory and same name; this is a noop and just return success @@ -80,94 +81,113 @@ tagain: code = 0; goto done; } - ObtainWriteLock(&andp->lock,147); - oneDir = 1; /* only one dude locked */ - } - else if ((andp->states & CRO) || (aodp->states & CRO)) { - code = EROFS; - goto done; - } - else if (andp->fid.Fid.Vnode < aodp->fid.Fid.Vnode) { - ObtainWriteLock(&andp->lock,148); /* lock smaller one first */ - ObtainWriteLock(&aodp->lock,149); - } - else { - ObtainWriteLock(&aodp->lock,150); /* lock smaller one first */ - ObtainWriteLock(&andp->lock,557); + ObtainWriteLock(&andp->lock, 147); + tdc1 = afs_GetDCache(aodp, (afs_size_t) 0, areq, &offset, &len, 0); + if (!tdc1) { + code = ENOENT; + } else { + ObtainWriteLock(&tdc1->lock, 643); + } + tdc2 = tdc1; + oneDir = 1; /* only one dude locked */ + } else if ((andp->states & CRO) || (aodp->states & CRO)) { + code = EROFS; + goto done; + } else if (andp->fid.Fid.Vnode < aodp->fid.Fid.Vnode) { + ObtainWriteLock(&andp->lock, 148); /* lock smaller one first */ + ObtainWriteLock(&aodp->lock, 149); + tdc2 = afs_FindDCache(andp, (afs_size_t) 0); + if (tdc2) + ObtainWriteLock(&tdc2->lock, 644); + tdc1 = afs_GetDCache(aodp, (afs_size_t) 0, areq, &offset, &len, 0); + if (tdc1) + ObtainWriteLock(&tdc1->lock, 645); + else + code = ENOENT; + } else { + ObtainWriteLock(&aodp->lock, 150); /* lock smaller one first */ + ObtainWriteLock(&andp->lock, 557); + tdc1 = afs_GetDCache(aodp, (afs_size_t) 0, areq, &offset, &len, 0); + if (tdc1) + ObtainWriteLock(&tdc1->lock, 646); + else + code = ENOENT; + tdc2 = afs_FindDCache(andp, (afs_size_t) 0); + if (tdc2) + ObtainWriteLock(&tdc2->lock, 647); } - osi_dnlc_remove (aodp, aname1, 0); - osi_dnlc_remove (andp, aname2, 0); - afs_symhint_inval(aodp); + osi_dnlc_remove(aodp, aname1, 0); + osi_dnlc_remove(andp, aname2, 0); + afs_symhint_inval(aodp); afs_symhint_inval(andp); - /* before doing the rename, lookup the fileFid, just in case we - * don't make it down the path below that looks it up. We always need - * fileFid in order to handle ".." invalidation at the very end. - */ - code = 0; - tdc1 = afs_GetDCache(aodp, 0, areq, &offset, &len, 0); - if (!tdc1) { - code = ENOENT; - } /* * Make sure that the data in the cache is current. We may have * received a callback while we were waiting for the write lock. */ - else if (!(aodp->states & CStatd) - || !hsame(aodp->m.DataVersion, tdc1->f.versionNo)) { - ReleaseWriteLock(&aodp->lock); - if (!oneDir) ReleaseWriteLock(&andp->lock); - afs_PutDCache(tdc1); - goto tagain; + if (tdc1) { + if (!(aodp->states & CStatd) + || !hsame(aodp->m.DataVersion, tdc1->f.versionNo)) { + + ReleaseWriteLock(&aodp->lock); + if (!oneDir) { + if (tdc2) { + ReleaseWriteLock(&tdc2->lock); + afs_PutDCache(tdc2); + } + ReleaseWriteLock(&andp->lock); + } + ReleaseWriteLock(&tdc1->lock); + afs_PutDCache(tdc1); + goto tagain; + } } if (code == 0) code = afs_dir_Lookup(&tdc1->f.inode, aname1, &fileFid.Fid); if (code) { - if (tdc1) afs_PutDCache(tdc1); + if (tdc1) { + ReleaseWriteLock(&tdc1->lock); + afs_PutDCache(tdc1); + } ReleaseWriteLock(&aodp->lock); - if (!oneDir) ReleaseWriteLock(&andp->lock); + if (!oneDir) { + if (tdc2) { + ReleaseWriteLock(&tdc2->lock); + afs_PutDCache(tdc2); + } + ReleaseWriteLock(&andp->lock); + } goto done; } - afs_PutDCache(tdc1); /* locks are now set, proceed to do the real work */ do { tc = afs_Conn(&aodp->fid, areq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RENAME); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_Rename(tc->id, (struct AFSFid *) &aodp->fid.Fid, aname1, - (struct AFSFid *) &andp->fid.Fid, aname2, - &OutOldDirStatus, &OutNewDirStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } else code = -1; + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RENAME); + RX_AFS_GUNLOCK(); + code = + RXAFS_Rename(tc->id, (struct AFSFid *)&aodp->fid.Fid, aname1, + (struct AFSFid *)&andp->fid.Fid, aname2, + &OutOldDirStatus, &OutNewDirStatus, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; - } while - (afs_Analyze(tc, code, &andp->fid, areq, - AFS_STATS_FS_RPCIDX_RENAME, SHARED_LOCK, (struct cell *)0)); + } while (afs_Analyze + (tc, code, &andp->fid, areq, AFS_STATS_FS_RPCIDX_RENAME, + SHARED_LOCK, NULL)); + + returnCode = code; /* remember for later */ - returnCode = code; /* remember for later */ - /* Now we try to do things locally. This is really loathsome code. */ unlinkFid.Fid.Vnode = 0; if (code == 0) { - tdc1 = tdc2 = 0; - /* don't use GetDCache because we don't want to worry about what happens if - we have to stat the file (updating the stat block) before finishing - local hero stuff (which may put old (from rename) data version number - back in the cache entry). - In any event, we don't really care if the data is not - in the cache; if it isn't, we won't do the update locally. */ - tdc1 = afs_FindDCache(aodp, 0); - if (!oneDir) tdc2 = afs_FindDCache(andp, 0); - else tdc2 = tdc1; + /* In any event, we don't really care if the data (tdc2) is not + * in the cache; if it isn't, we won't do the update locally. */ /* see if version numbers increased properly */ doLocally = 1; if (oneDir) { @@ -175,8 +195,7 @@ tagain: if (!afs_LocalHero(aodp, tdc1, &OutOldDirStatus, 1)) { doLocally = 0; } - } - else { + } else { /* two separate dirs, each increasing by 1 */ if (!afs_LocalHero(aodp, tdc1, &OutOldDirStatus, 1)) doLocally = 0; @@ -202,8 +221,9 @@ tagain: code = afs_dir_Delete(&tdc1->f.inode, aname1); } /* first see if target is there */ - if (code == 0 && - afs_dir_Lookup(&tdc2->f.inode, aname2, &unlinkFid.Fid) == 0) { + if (code == 0 + && afs_dir_Lookup(&tdc2->f.inode, aname2, + &unlinkFid.Fid) == 0) { /* target already exists, and will be unlinked by server */ code = afs_dir_Delete(&tdc2->f.inode, aname2); } @@ -219,81 +239,88 @@ tagain: } } } - if (tdc1) afs_PutDCache(tdc1); - if ((!oneDir) && tdc2) afs_PutDCache(tdc2); /* update dir link counts */ aodp->m.LinkCount = OutOldDirStatus.LinkCount; if (!oneDir) andp->m.LinkCount = OutNewDirStatus.LinkCount; - } - else { /* operation failed (code != 0) */ - if (code < 0) { + } else { /* operation failed (code != 0) */ + if (code < 0) { /* if failed, server might have done something anyway, and * assume that we know about it */ - ObtainWriteLock(&afs_xcbhash, 498); - afs_DequeueCallback(aodp); - afs_DequeueCallback(andp); - andp->states &= ~CStatd; - aodp->states &= ~CStatd; - ReleaseWriteLock(&afs_xcbhash); - osi_dnlc_purgedp(andp); - osi_dnlc_purgedp(aodp); + ObtainWriteLock(&afs_xcbhash, 498); + afs_DequeueCallback(aodp); + afs_DequeueCallback(andp); + andp->states &= ~CStatd; + aodp->states &= ~CStatd; + ReleaseWriteLock(&afs_xcbhash); + osi_dnlc_purgedp(andp); + osi_dnlc_purgedp(aodp); } } /* release locks */ + if (tdc1) { + ReleaseWriteLock(&tdc1->lock); + afs_PutDCache(tdc1); + } + + if ((!oneDir) && tdc2) { + ReleaseWriteLock(&tdc2->lock); + afs_PutDCache(tdc2); + } + ReleaseWriteLock(&aodp->lock); - if (!oneDir) ReleaseWriteLock(&andp->lock); - + if (!oneDir) + ReleaseWriteLock(&andp->lock); + if (returnCode) { code = returnCode; goto done; } /* now, some more details. if unlinkFid.Fid.Vnode then we should decrement - the link count on this file. Note that if fileFid is a dir, then we don't - have to invalidate its ".." entry, since its DataVersion # should have - changed. However, interface is not good enough to tell us the - *file*'s new DataVersion, so we're stuck. Our hack: delete mark - the data as having an "unknown" version (effectively discarding the ".." - entry */ + * the link count on this file. Note that if fileFid is a dir, then we don't + * have to invalidate its ".." entry, since its DataVersion # should have + * changed. However, interface is not good enough to tell us the + * *file*'s new DataVersion, so we're stuck. Our hack: delete mark + * the data as having an "unknown" version (effectively discarding the ".." + * entry */ if (unlinkFid.Fid.Vnode) { unlinkFid.Fid.Volume = aodp->fid.Fid.Volume; unlinkFid.Cell = aodp->fid.Cell; - tvc = (struct vcache *)0; + tvc = NULL; if (!unlinkFid.Fid.Unique) { - tvc = afs_LookupVCache(&unlinkFid, areq, (afs_int32 *)0, WRITE_LOCK, - aodp, aname1); + tvc = afs_LookupVCache(&unlinkFid, areq, NULL, aodp, aname1); } - if (!tvc) /* lookup failed or wasn't called */ - tvc = afs_GetVCache(&unlinkFid, areq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + if (!tvc) /* lookup failed or wasn't called */ + tvc = afs_GetVCache(&unlinkFid, areq, NULL, NULL); if (tvc) { #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */ #endif - ObtainWriteLock(&tvc->lock,151); + ObtainWriteLock(&tvc->lock, 151); tvc->m.LinkCount--; - tvc->states &= ~CUnique; /* For the dfs xlator */ + tvc->states &= ~CUnique; /* For the dfs xlator */ if (tvc->m.LinkCount == 0 && !osi_Active(tvc)) { /* if this was last guy (probably) discard from cache. - * We have to be careful to not get rid of the stat - * information, since otherwise operations will start - * failing even if the file was still open (or - * otherwise active), and the server no longer has the - * info. If the file still has valid links, we'll get - * a break-callback msg from the server, so it doesn't - * matter that we don't discard the status info */ - if (!AFS_NFSXLATORREQ(acred)) afs_TryToSmush(tvc, acred, 0); + * We have to be careful to not get rid of the stat + * information, since otherwise operations will start + * failing even if the file was still open (or + * otherwise active), and the server no longer has the + * info. If the file still has valid links, we'll get + * a break-callback msg from the server, so it doesn't + * matter that we don't discard the status info */ + if (!AFS_NFSXLATORREQ(acred)) + afs_TryToSmush(tvc, acred, 0); } ReleaseWriteLock(&tvc->lock); #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonUnlock(&tvc->pvnLock, tvc); #endif - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); } } @@ -302,52 +329,56 @@ tagain: fileFid.Fid.Volume = aodp->fid.Fid.Volume; fileFid.Cell = aodp->fid.Cell; if (!fileFid.Fid.Unique) - tvc = afs_LookupVCache(&fileFid, areq, (afs_int32 *)0, WRITE_LOCK, andp, aname2); + tvc = afs_LookupVCache(&fileFid, areq, NULL, andp, aname2); else - tvc = afs_GetVCache(&fileFid, areq, (afs_int32 *)0, - (struct vcache*)0, WRITE_LOCK); + tvc = afs_GetVCache(&fileFid, areq, NULL, (struct vcache *)0); if (tvc && (vType(tvc) == VDIR)) { - ObtainWriteLock(&tvc->lock,152); - tdc1 = afs_FindDCache(tvc, 0); + ObtainWriteLock(&tvc->lock, 152); + tdc1 = afs_FindDCache(tvc, (afs_size_t) 0); if (tdc1) { + ObtainWriteLock(&tdc1->lock, 648); ZapDCE(tdc1); /* mark as unknown */ DZap(&tdc1->f.inode); + ReleaseWriteLock(&tdc1->lock); afs_PutDCache(tdc1); /* put it back */ } osi_dnlc_remove(tvc, "..", 0); ReleaseWriteLock(&tvc->lock); - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); } else if (tvc) { /* True we shouldn't come here since tvc SHOULD be a dir, but we * 'syntactically' need to unless we change the 'if' above... */ - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); } } code = returnCode; -done: + done: return code; } +int #ifdef AFS_OSF_ENV afs_rename(fndp, tndp) - struct nameidata *fndp, *tndp; { + struct nameidata *fndp, *tndp; +{ struct vcache *aodp = VTOAFS(fndp->ni_dvp); char *aname1 = fndp->ni_dent.d_name; struct vcache *andp = VTOAFS(tndp->ni_dvp); char *aname2 = tndp->ni_dent.d_name; struct ucred *acred = tndp->ni_cred; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #if defined(AFS_SGI_ENV) afs_rename(OSI_VC_ARG(aodp), aname1, andp, aname2, npnp, acred) - struct pathname *npnp; + struct pathname *npnp; #else afs_rename(OSI_VC_ARG(aodp), aname1, andp, aname2, acred) #endif OSI_VC_DECL(aodp); - struct vcache *andp; - char *aname1, *aname2; - struct AFS_UCRED *acred; { + struct vcache *andp; + char *aname1, *aname2; + struct AFS_UCRED *acred; +{ #endif register afs_int32 code; struct afs_fakestat_state ofakestate; @@ -355,16 +386,19 @@ afs_rename(OSI_VC_ARG(aodp), aname1, andp, aname2, acred) struct vrequest treq; OSI_VC_CONVERT(aodp) - code = afs_InitReq(&treq, acred); - if (code) return code; + code = afs_InitReq(&treq, acred); + if (code) + return code; afs_InitFakeStat(&ofakestate); afs_InitFakeStat(&nfakestate); code = afs_EvalFakeStat(&aodp, &ofakestate, &treq); - if (code) goto done; + if (code) + goto done; code = afs_EvalFakeStat(&andp, &nfakestate, &treq); - if (code) goto done; + if (code) + goto done; code = afsrename(aodp, aname1, andp, aname2, acred, &treq); -done: + done: afs_PutFakeStat(&ofakestate); afs_PutFakeStat(&nfakestate); #ifdef AFS_OSF_ENV @@ -374,7 +408,7 @@ done: } AFS_RELE(fndp->ni_dvp); AFS_RELE(fndp->ni_vp); -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ code = afs_CheckCode(code, &treq, 25); return code; } diff --git a/src/afs/VNOPS/afs_vnop_strategy.c b/src/afs/VNOPS/afs_vnop_strategy.c index 84765b8b3..4f32e17a8 100644 --- a/src/afs/VNOPS/afs_vnop_strategy.c +++ b/src/afs/VNOPS/afs_vnop_strategy.c @@ -13,42 +13,41 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_strategy.c,v 1.1.1.9 2002/09/26 18:58:25 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_strategy.c,v 1.18 2003/08/29 22:00:04 rees Exp $"); #if !defined(AFS_HPUX_ENV) && !defined(AFS_SGI_ENV) && !defined(AFS_LINUX20_ENV) -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" - -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +int +#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) afs_ustrategy(abp, credp) - struct AFS_UCRED *credp; + struct AFS_UCRED *credp; #else afs_ustrategy(abp) #endif - register struct buf *abp; { + register struct buf *abp; +{ register afs_int32 code; struct uio tuio; register struct vcache *tvc = VTOAFS(abp->b_vp); register afs_int32 len = abp->b_bcount; -#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) #ifdef AFS_AIX41_ENV struct ucred *credp; #else struct AFS_UCRED *credp = u.u_cred; #endif -#endif -#if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - int async = abp->b_flags & B_ASYNC; #endif struct iovec tiovec[1]; @@ -58,7 +57,7 @@ afs_ustrategy(abp) * So that it won't change while reading it */ ObtainReadLock(&tvc->lock); - if (tvc->credp) { + if (tvc->credp) { credp = tvc->credp; crhold(credp); } else { @@ -67,19 +66,27 @@ afs_ustrategy(abp) ReleaseReadLock(&tvc->lock); osi_Assert(credp); #endif +#ifdef AFS_FBSD50_ENV + if (abp->b_iocmd == BIO_READ) { +#else if ((abp->b_flags & B_READ) == B_READ) { +#endif /* read b_bcount bytes into kernel address b_un.b_addr starting - at byte DEV_BSIZE * b_blkno. Bzero anything we can't read, - and finally call iodone(abp). File is in abp->b_vp. Credentials - are from u area?? - */ + * at byte DEV_BSIZE * b_blkno. Bzero anything we can't read, + * and finally call iodone(abp). File is in abp->b_vp. Credentials + * are from u area?? + */ tuio.afsio_iov = tiovec; tuio.afsio_iovcnt = 1; -#if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_XBSD_ENV) +#ifdef AFS_64BIT_CLIENT + tuio.afsio_offset = (afs_offs_t) dbtob(abp->b_blkno); +#else /* AFS_64BIT_CLIENT */ tuio.afsio_offset = (u_int) dbtob(abp->b_blkno); #if defined(AFS_SUN5_ENV) tuio._uio_offset._p._u = 0; #endif +#endif /* AFS_64BIT_CLIENT */ #else tuio.afsio_offset = DEV_BSIZE * abp->b_blkno; #endif @@ -88,14 +95,14 @@ afs_ustrategy(abp) tuio.afsio_fmode = 0; #endif tuio.afsio_resid = abp->b_bcount; -#if defined(AFS_FBSD_ENV) +#if defined(AFS_XBSD_ENV) tiovec[0].iov_base = abp->b_saveaddr; #else tiovec[0].iov_base = abp->b_un.b_addr; -#endif /* AFS_FBSD_ENV */ +#endif /* AFS_XBSD_ENV */ tiovec[0].iov_len = abp->b_bcount; /* are user's credentials valid here? probably, but this - sure seems like the wrong things to do. */ + * sure seems like the wrong things to do. */ #if defined(AFS_SUN5_ENV) code = afs_nlrdwr(VTOAFS(abp->b_vp), &tuio, UIO_READ, 0, credp); #else @@ -103,11 +110,13 @@ afs_ustrategy(abp) #endif if (code == 0) { if (tuio.afsio_resid > 0) -#if defined(AFS_FBSD_ENV) - memset(abp->b_saveaddr + abp->b_bcount - tuio.afsio_resid, 0, tuio.afsio_resid); +#if defined(AFS_XBSD_ENV) + memset(abp->b_saveaddr + abp->b_bcount - tuio.afsio_resid, 0, + tuio.afsio_resid); #else - memset(abp->b_un.b_addr + abp->b_bcount - tuio.afsio_resid, 0, tuio.afsio_resid); -#endif /* AFS_FBSD_ENV */ + memset(abp->b_un.b_addr + abp->b_bcount - tuio.afsio_resid, 0, + tuio.afsio_resid); +#endif /* AFS_XBSD_ENV */ #ifdef AFS_AIX32_ENV /* * If we read a block that is past EOF and the user was not storing @@ -117,21 +126,26 @@ afs_ustrategy(abp) if (dbtob(abp->b_blkno) + abp->b_bcount > tvc->m.Length) { if ((abp->b_flags & B_PFSTORE) == 0) { AFS_GUNLOCK(); - vm_protectp(tvc->vmh, dbtob(abp->b_blkno)/PAGESIZE, - abp->b_bcount/PAGESIZE, RDONLY); + vm_protectp(tvc->segid, dbtob(abp->b_blkno) / PAGESIZE, + abp->b_bcount / PAGESIZE, RDONLY); AFS_GLOCK(); } } #endif } - } - else { + } else { tuio.afsio_iov = tiovec; tuio.afsio_iovcnt = 1; #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) +#ifdef AFS_64BIT_CLIENT + tuio.afsio_offset = (afs_offs_t) dbtob(abp->b_blkno); +#else /* AFS_64BIT_CLIENT */ tuio.afsio_offset = (u_int) dbtob(abp->b_blkno); #ifdef AFS_SUN5_ENV tuio._uio_offset._p._u = 0; +#endif +#endif /* AFS_64BIT_CLIENT */ +#ifdef AFS_SUN5_ENV #ifdef AFS_SUN59_ENV tuio.uio_limit = curproc->p_fsz_ctl.rlim_cur; #else @@ -145,25 +159,27 @@ afs_ustrategy(abp) #ifdef AFS_UIOFMODE tuio.afsio_fmode = 0; #endif -#ifdef AFS_AIX32_ENV +#ifdef AFS_AIX32_ENV /* * XXX It this really right? Ideally we should always write block size multiple * and not any arbitrary size, right? XXX */ len = MIN(len, tvc->m.Length - dbtob(abp->b_blkno)); #endif -#ifdef AFS_ALPHA_ENV - len = MIN(abp->b_bcount, (VTOAFS(abp->b_vp))->m.Length - dbtob(abp->b_blkno)); -#endif /* AFS_ALPHA_ENV */ +#ifdef AFS_ALPHA_ENV + len = + MIN(abp->b_bcount, + (VTOAFS(abp->b_vp))->m.Length - dbtob(abp->b_blkno)); +#endif /* AFS_ALPHA_ENV */ tuio.afsio_resid = len; -#if defined(AFS_FBSD_ENV) +#if defined(AFS_XBSD_ENV) tiovec[0].iov_base = abp->b_saveaddr; #else tiovec[0].iov_base = abp->b_un.b_addr; -#endif /* AFS_FBSD_ENV */ +#endif /* AFS_XBSD_ENV */ tiovec[0].iov_len = len; /* are user's credentials valid here? probably, but this - sure seems like the wrong things to do. */ + * sure seems like the wrong things to do. */ #if defined(AFS_SUN5_ENV) code = afs_nlrdwr(VTOAFS(abp->b_vp), &tuio, UIO_WRITE, 0, credp); #else @@ -171,7 +187,7 @@ afs_ustrategy(abp) #endif } #if !defined(AFS_AIX32_ENV) && !defined(AFS_SUN5_ENV) -#if defined(AFS_DUX40_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_DUX40_ENV) || (defined (AFS_XBSD_ENV) && !defined (AFS_FBSD50_ENV)) if (code) { abp->b_error = code; abp->b_flags |= B_ERROR; @@ -182,21 +198,21 @@ afs_ustrategy(abp) /* prevent ubc from retrying writes */ AFS_GUNLOCK(); ubc_invalidate(AFSTOV(tvc)->v_object, - (vm_offset_t)dbtob(abp->b_blkno), - PAGE_SIZE, B_INVAL); + (vm_offset_t) dbtob(abp->b_blkno), PAGE_SIZE, B_INVAL); AFS_GLOCK(); } #endif -#else /* AFS_DUX40_ENV || AFS_FBSD_ENV */ +#elif defined(AFS_FBSD50_ENV) + biodone(&abp->b_io); +#else /* AFS_DUX40_ENV */ iodone(abp); -#endif /* AFS_DUX40_ENV || AFS_FBSD_ENV */ +#endif /* AFS_DUX40_ENV */ #endif #ifdef AFS_AIX32_ENV crfree(credp); #endif afs_Trace3(afs_iclSetp, CM_TRACE_STRATEGYDONE, ICL_TYPE_POINTER, tvc, - ICL_TYPE_INT32, code, - ICL_TYPE_LONG, tuio.afsio_resid); + ICL_TYPE_INT32, code, ICL_TYPE_LONG, tuio.afsio_resid); return code; } diff --git a/src/afs/VNOPS/afs_vnop_symlink.c b/src/afs/VNOPS/afs_vnop_symlink.c index 1fd305117..4078925b5 100644 --- a/src/afs/VNOPS/afs_vnop_symlink.c +++ b/src/afs/VNOPS/afs_vnop_symlink.c @@ -19,16 +19,17 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_symlink.c,v 1.1.1.7 2002/08/02 04:29:04 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_symlink.c,v 1.19 2003/08/26 15:09:28 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern afs_rwlock_t afs_xvcache; extern afs_rwlock_t afs_xcbhash; @@ -40,46 +41,49 @@ extern afs_rwlock_t afs_xcbhash; /* don't set CDirty in here because RPC is called synchronously */ +int afs_symlink #ifdef AFS_OSF_ENV (ndp, attrs, atargetName) - struct nameidata *ndp; - struct vattr *attrs; - register char *atargetName; { + struct nameidata *ndp; + struct vattr *attrs; + register char *atargetName; +{ register struct vcache *adp = VTOAFS(ndp->ni_dvp); char *aname = ndp->ni_dent.d_name; struct ucred *acred = ndp->ni_cred; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ (OSI_VC_ARG(adp), aname, attrs, atargetName, acred) - OSI_VC_DECL(adp); - char *atargetName; - char *aname; - struct vattr *attrs; - struct AFS_UCRED *acred; { + OSI_VC_DECL(adp); + char *atargetName; + char *aname; + struct vattr *attrs; + struct AFS_UCRED *acred; +{ #endif - afs_uint32 now; + afs_uint32 now = 0; struct vrequest treq; afs_int32 code; struct conn *tc; struct VenusFid newFid; struct dcache *tdc; - afs_int32 offset, len, alen; - struct server *hostp=0; + afs_size_t offset, len; + afs_int32 alen; + struct server *hostp = 0; struct vcache *tvc; struct AFSStoreStatus InStatus; struct AFSFetchStatus OutFidStatus, OutDirStatus; struct AFSCallBack CallBack; struct AFSVolSync tsync; - struct volume* volp=0; + struct volume *volp = 0; struct afs_fakestat_state fakestate; - XSTATS_DECLS - OSI_VC_CONVERT(adp) - + XSTATS_DECLS OSI_VC_CONVERT(adp) + AFS_STATCNT(afs_symlink); afs_Trace2(afs_iclSetp, CM_TRACE_SYMLINK, ICL_TYPE_POINTER, adp, - ICL_TYPE_STRING, aname); + ICL_TYPE_STRING, aname); - if (code = afs_InitReq(&treq, acred)) + if ((code = afs_InitReq(&treq, acred))) goto done2; afs_InitFakeStat(&fakestate); @@ -89,42 +93,45 @@ afs_symlink if (strlen(aname) > AFSNAMEMAX || strlen(atargetName) > AFSPATHMAX) { code = ENAMETOOLONG; - goto done2; + goto done; } if (afs_IsDynroot(adp)) { code = afs_DynrootVOPSymlink(adp, acred, aname, atargetName); - goto done2; + goto done; } code = afs_VerifyVCache(adp, &treq); - if (code) { - code = afs_CheckCode(code, &treq, 30); - goto done2; + if (code) { + code = afs_CheckCode(code, &treq, 30); + goto done; } /** If the volume is read-only, return error without making an RPC to the * fileserver */ - if ( adp->states & CRO ) { - code = EROFS; - goto done2; + if (adp->states & CRO) { + code = EROFS; + goto done; } InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE; InStatus.ClientModTime = osi_Time(); - alen = strlen(atargetName); /* we want it to include the null */ + alen = strlen(atargetName); /* we want it to include the null */ if (*atargetName == '#' || *atargetName == '%') { InStatus.UnixModeBits = 0644; /* mt pt: null from "." at end */ - if (alen == 1) alen++; /* Empty string */ + if (alen == 1) + alen++; /* Empty string */ } else { InStatus.UnixModeBits = 0755; - alen++; /* add in the null */ + alen++; /* add in the null */ } - tdc = afs_GetDCache(adp, 0, &treq, &offset, &len, 1); - volp = afs_FindVolume(&adp->fid, READ_LOCK); /*parent is also in same vol*/ - ObtainWriteLock(&adp->lock,156); - ObtainSharedLock(&afs_xvcache,17); /* prevent others from creating this entry */ + tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); + volp = afs_FindVolume(&adp->fid, READ_LOCK); /*parent is also in same vol */ + ObtainWriteLock(&adp->lock, 156); + if (tdc) + ObtainWriteLock(&tdc->lock, 636); + ObtainSharedLock(&afs_xvcache, 17); /* prevent others from creating this entry */ /* XXX Pay attention to afs_xvcache around the whole thing!! XXX */ do { tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK); @@ -133,57 +140,58 @@ afs_symlink XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SYMLINK); if (adp->states & CForeign) { now = osi_Time(); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_DFSSymlink(tc->id, (struct AFSFid *) &adp->fid.Fid, aname, - atargetName, &InStatus, (struct AFSFid *) &newFid.Fid, - &OutFidStatus, &OutDirStatus, &CallBack, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + code = + RXAFS_DFSSymlink(tc->id, (struct AFSFid *)&adp->fid.Fid, + aname, atargetName, &InStatus, + (struct AFSFid *)&newFid.Fid, + &OutFidStatus, &OutDirStatus, &CallBack, + &tsync); + RX_AFS_GLOCK(); } else { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_Symlink(tc->id, (struct AFSFid *) &adp->fid.Fid, aname, - atargetName, &InStatus, (struct AFSFid *) &newFid.Fid, - &OutFidStatus, &OutDirStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + code = + RXAFS_Symlink(tc->id, (struct AFSFid *)&adp->fid.Fid, + aname, atargetName, &InStatus, + (struct AFSFid *)&newFid.Fid, &OutFidStatus, + &OutDirStatus, &tsync); + RX_AFS_GLOCK(); } - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &adp->fid, &treq, - AFS_STATS_FS_RPCIDX_SYMLINK, SHARED_LOCK, (struct cell *)0)); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_SYMLINK, + SHARED_LOCK, NULL)); - UpgradeSToWLock(&afs_xvcache,40); + UpgradeSToWLock(&afs_xvcache, 40); if (code) { if (code < 0) { - ObtainWriteLock(&afs_xcbhash, 499); - afs_DequeueCallback(adp); - adp->states &= ~CStatd; - ReleaseWriteLock(&afs_xcbhash); - osi_dnlc_purgedp(adp); + ObtainWriteLock(&afs_xcbhash, 499); + afs_DequeueCallback(adp); + adp->states &= ~CStatd; + ReleaseWriteLock(&afs_xcbhash); + osi_dnlc_purgedp(adp); } ReleaseWriteLock(&adp->lock); ReleaseWriteLock(&afs_xvcache); - if (tdc) afs_PutDCache(tdc); + if (tdc) { + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); + } goto done; } /* otherwise, we should see if we can make the change to the dir locally */ if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid); - if (code) { + if (code) { ZapDCE(tdc); /* surprise error -- use invalid value */ DZap(&tdc->f.inode); } } if (tdc) { + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); } newFid.Cell = adp->fid.Cell; @@ -193,10 +201,10 @@ afs_symlink /* now we're done with parent dir, create the link's entry. Note that * no one can get a pointer to the new cache entry until we release * the xvcache lock. */ - tvc = afs_NewVCache(&newFid, hostp, 1, WRITE_LOCK); - ObtainWriteLock(&tvc->lock,157); + tvc = afs_NewVCache(&newFid, hostp); + ObtainWriteLock(&tvc->lock, 157); ObtainWriteLock(&afs_xcbhash, 500); - tvc->states |= CStatd; /* have valid info */ + tvc->states |= CStatd; /* have valid info */ tvc->states &= ~CBulkFetching; if (adp->states & CForeign) { @@ -204,95 +212,105 @@ afs_symlink /* We don't have to worry about losing the callback since we're doing it * under the afs_xvcache lock actually, afs_NewVCache may drop the * afs_xvcache lock, if it calls afs_FlushVCache */ - tvc->cbExpires = CallBack.ExpirationTime + now; - afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), volp); + tvc->cbExpires = CallBack.ExpirationTime + now; + afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), volp); } else { tvc->cbExpires = 0x7fffffff; /* never expires, they can't change */ - /* since it never expires, we don't have to queue the callback */ + /* since it never expires, we don't have to queue the callback */ } ReleaseWriteLock(&afs_xcbhash); afs_ProcessFS(tvc, &OutFidStatus, &treq); if (!tvc->linkData) { - tvc->linkData = (char *) afs_osi_Alloc(alen); - strncpy(tvc->linkData, atargetName, alen-1); - tvc->linkData[alen-1] = 0; + tvc->linkData = (char *)afs_osi_Alloc(alen); + strncpy(tvc->linkData, atargetName, alen - 1); + tvc->linkData[alen - 1] = 0; } ReleaseWriteLock(&tvc->lock); ReleaseWriteLock(&afs_xvcache); - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); code = 0; -done: + done: afs_PutFakeStat(&fakestate); - if ( volp ) + if (volp) afs_PutVolume(volp, READ_LOCK); code = afs_CheckCode(code, &treq, 31); -done2: + done2: #ifdef AFS_OSF_ENV AFS_RELE(ndp->ni_dvp); -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ return code; } -afs_MemHandleLink(avc, areq) - register struct vcache *avc; - struct vrequest *areq; - { - register struct dcache *tdc; - register char *tp, *rbuf; - afs_int32 offset, len, alen; - register afs_int32 code; +int +afs_MemHandleLink(register struct vcache *avc, struct vrequest *areq) +{ + register struct dcache *tdc; + register char *tp, *rbuf; + afs_size_t offset, len; + afs_int32 tlen, alen; + register afs_int32 code; - AFS_STATCNT(afs_MemHandleLink); - /* two different formats, one for links protected 644, have a "." at - the end of the file name, which we turn into a null. Others, - protected 755, we add a null to the end of */ - if (!avc->linkData) { - void *addr; - tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 0); - if (!tdc) { - return EIO; - } - /* otherwise we have the data loaded, go for it */ - if (len > 1024) { - afs_PutDCache(tdc); - return EFAULT; - } - if (avc->m.Mode & 0111) alen = len+1; /* regular link */ - else alen = len; /* mt point */ - rbuf = (char *) osi_AllocLargeSpace(AFS_LRALLOCSIZ); - addr = afs_MemCacheOpen(tdc->f.inode); - code = afs_MemReadBlk(addr, 0, rbuf, len); - rbuf[alen-1] = '\0'; - alen = strlen(rbuf) + 1; - tp = afs_osi_Alloc(alen); /* make room for terminating null */ - memcpy(tp, rbuf, alen); - osi_FreeLargeSpace(rbuf); - afs_PutDCache(tdc); - if (code != len) { - afs_osi_Free(tp, alen); - return EIO; - } - avc->linkData = tp; - } - return 0; - } + AFS_STATCNT(afs_MemHandleLink); + /* two different formats, one for links protected 644, have a "." at + * the end of the file name, which we turn into a null. Others, + * protected 755, we add a null to the end of */ + if (!avc->linkData) { + void *addr; + tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 0); + if (!tdc) { + return EIO; + } + /* otherwise we have the data loaded, go for it */ + if (len > 1024) { + afs_PutDCache(tdc); + return EFAULT; + } + if (avc->m.Mode & 0111) + alen = len + 1; /* regular link */ + else + alen = len; /* mt point */ + rbuf = (char *)osi_AllocLargeSpace(AFS_LRALLOCSIZ); + ObtainReadLock(&tdc->lock); + addr = afs_MemCacheOpen(tdc->f.inode); + tlen = len; + code = afs_MemReadBlk(addr, 0, rbuf, tlen); + afs_MemCacheClose(addr); + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); + rbuf[alen - 1] = 0; + alen = strlen(rbuf) + 1; + tp = afs_osi_Alloc(alen); /* make room for terminating null */ + memcpy(tp, rbuf, alen); + osi_FreeLargeSpace(rbuf); + if (code != len) { + afs_osi_Free(tp, alen); + return EIO; + } + avc->linkData = tp; + } + return 0; +} -afs_UFSHandleLink(avc, areq) - register struct vcache *avc; - struct vrequest *areq; { +int +afs_UFSHandleLink(register struct vcache *avc, struct vrequest *areq) +{ register struct dcache *tdc; register char *tp, *rbuf; - char *tfile; - afs_int32 offset, len, alen; + void *tfile; + afs_size_t offset, len; + afs_int32 tlen, alen; register afs_int32 code; - /* two different formats, one for links protected 644, have a "." at the end - of the file name, which we turn into a null. Others, protected 755, - we add a null to the end of */ - AFS_STATCNT(afs_UFSHandleLink); + /* two different formats, one for links protected 644, have a "." at the + * end of the file name, which we turn into a null. Others, protected + * 755, we add a null to the end of */ + AFS_STATCNT(afs_UFSHandleLink); if (!avc->linkData) { - tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 0); + tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 0); + afs_Trace3(afs_iclSetp, CM_TRACE_UFSLINK, ICL_TYPE_POINTER, avc, + ICL_TYPE_POINTER, tdc, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length)); if (!tdc) { return EIO; } @@ -301,19 +319,24 @@ afs_UFSHandleLink(avc, areq) afs_PutDCache(tdc); return EFAULT; } - tfile = osi_UFSOpen (tdc->f.inode); - if (avc->m.Mode & 0111) alen = len+1; /* regular link */ - else alen = len; /* mt point */ - rbuf = (char *) osi_AllocLargeSpace(AFS_LRALLOCSIZ); - code = afs_osi_Read(tfile, -1, rbuf, len); - rbuf[alen-1] = '\0'; + if (avc->m.Mode & 0111) + alen = len + 1; /* regular link */ + else + alen = len; /* mt point */ + rbuf = (char *)osi_AllocLargeSpace(AFS_LRALLOCSIZ); + tlen = len; + ObtainReadLock(&tdc->lock); + tfile = osi_UFSOpen(tdc->f.inode); + code = afs_osi_Read(tfile, -1, rbuf, tlen); osi_UFSClose(tfile); + ReleaseReadLock(&tdc->lock); afs_PutDCache(tdc); + rbuf[alen - 1] = '\0'; alen = strlen(rbuf) + 1; tp = afs_osi_Alloc(alen); /* make room for terminating null */ memcpy(tp, rbuf, alen); osi_FreeLargeSpace(rbuf); - if (code != len) { + if (code != tlen) { afs_osi_Free(tp, alen); return EIO; } @@ -322,10 +345,12 @@ afs_UFSHandleLink(avc, areq) return 0; } +int afs_readlink(OSI_VC_ARG(avc), auio, acred) - OSI_VC_DECL(avc); - struct uio *auio; - struct AFS_UCRED *acred; { + OSI_VC_DECL(avc); + struct uio *auio; + struct AFS_UCRED *acred; +{ register afs_int32 code; struct vrequest treq; register char *tp; @@ -334,28 +359,32 @@ afs_readlink(OSI_VC_ARG(avc), auio, acred) AFS_STATCNT(afs_readlink); afs_Trace1(afs_iclSetp, CM_TRACE_READLINK, ICL_TYPE_POINTER, avc); - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; afs_InitFakeStat(&fakestat); code = afs_EvalFakeStat(&avc, &fakestat, &treq); - if (code) goto done; + if (code) + goto done; code = afs_VerifyVCache(avc, &treq); - if (code) goto done; + if (code) + goto done; if (vType(avc) != VLNK) { code = EINVAL; goto done; } - ObtainWriteLock(&avc->lock,158); + ObtainWriteLock(&avc->lock, 158); code = afs_HandleLink(avc, &treq); /* finally uiomove it to user-land */ if (code == 0) { tp = avc->linkData; - if (tp) AFS_UIOMOVE(tp, strlen(tp), UIO_READ, auio, code); + if (tp) + AFS_UIOMOVE(tp, strlen(tp), UIO_READ, auio, code); else { code = EIO; } } ReleaseWriteLock(&avc->lock); -done: + done: afs_PutFakeStat(&fakestat); code = afs_CheckCode(code, &treq, 32); return code; diff --git a/src/afs/VNOPS/afs_vnop_write.c b/src/afs/VNOPS/afs_vnop_write.c index 933cc4dcf..57b702f76 100644 --- a/src/afs/VNOPS/afs_vnop_write.c +++ b/src/afs/VNOPS/afs_vnop_write.c @@ -18,16 +18,17 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_write.c,v 1.1.1.12 2002/09/26 18:58:25 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/VNOPS/afs_vnop_write.c,v 1.35 2003/08/29 22:00:04 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" extern unsigned char *afs_indexFlags; @@ -37,12 +38,12 @@ extern unsigned char *afs_indexFlags; * afs_FlushActiveVCaches routine (when CCORE is on). * avc->lock must be write-locked. */ -afs_StoreOnLastReference(avc, treq) -register struct vcache *avc; -register struct vrequest *treq; +int +afs_StoreOnLastReference(register struct vcache *avc, + register struct vrequest *treq) { int code = 0; - + AFS_STATCNT(afs_StoreOnLastReference); /* if CCore flag is set, we clear it and do the extra decrement * ourselves now. If we're called by the CCore clearer, the CCore @@ -59,9 +60,9 @@ register struct vrequest *treq; * top level code. */ avc->opens--; avc->execsOrWriters--; - AFS_RELE(AFSTOV(avc)); /* VN_HOLD at set CCore(afs_FakeClose)*/ + AFS_RELE(AFSTOV(avc)); /* VN_HOLD at set CCore(afs_FakeClose) */ crfree((struct AFS_UCRED *)avc->linkData); /* "crheld" in afs_FakeClose */ - avc->linkData = (char *)0; + avc->linkData = NULL; } /* Now, send the file back. Used to require 0 writers left, but now do * it on every close for write, since two closes in a row are harmless @@ -70,7 +71,7 @@ register struct vrequest *treq; * inadvertently, since with old system, writes to the server would never * happen again. */ - code = afs_StoreAllSegments(avc, treq, AFS_LASTSTORE/*!sync-to-disk*/); + code = afs_StoreAllSegments(avc, treq, AFS_LASTSTORE /*!sync-to-disk */ ); /* * We have to do these after the above store in done: in some systems like * aix they'll need to flush all the vm dirty pages to the disk via the @@ -88,58 +89,60 @@ register struct vrequest *treq; -afs_MemWrite(avc, auio, aio, acred, noLock) - register struct vcache *avc; - struct uio *auio; - int aio, noLock; - struct AFS_UCRED *acred; { - afs_int32 totalLength; - afs_int32 transferLength; - afs_int32 filePos; +int +afs_MemWrite(register struct vcache *avc, struct uio *auio, int aio, + struct AFS_UCRED *acred, int noLock) +{ + afs_size_t totalLength; + afs_size_t transferLength; + afs_size_t filePos; + afs_size_t offset, len; + afs_int32 tlen, trimlen; afs_int32 startDate; afs_int32 max; register struct dcache *tdc; #ifdef _HIGHC_ volatile #endif - afs_int32 offset, len, error; + afs_int32 error; struct uio tuio; - struct iovec *tvec; /* again, should have define */ - char *tfile; + struct iovec *tvec; /* again, should have define */ register afs_int32 code; struct vrequest treq; AFS_STATCNT(afs_MemWrite); if (avc->vc_error) - return avc->vc_error; + return avc->vc_error; startDate = osi_Time(); - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; /* otherwise we read */ totalLength = auio->afsio_resid; filePos = auio->afsio_offset; error = 0; transferLength = 0; - afs_Trace4(afs_iclSetp, CM_TRACE_WRITE, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, filePos, ICL_TYPE_INT32, totalLength, - ICL_TYPE_INT32, avc->m.Length); + afs_Trace4(afs_iclSetp, CM_TRACE_WRITE, ICL_TYPE_POINTER, avc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(filePos), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(totalLength), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length)); if (!noLock) { afs_MaybeWakeupTruncateDaemon(); - ObtainWriteLock(&avc->lock,126); + ObtainWriteLock(&avc->lock, 126); } #if defined(AFS_SGI_ENV) { - off_t diff; - /* - * afs_xwrite handles setting m.Length - * and handles APPEND mode. - * Since we are called via strategy, we need to trim the write to - * the actual size of the file - */ - osi_Assert(filePos <= avc->m.Length); - diff = avc->m.Length - filePos; - auio->afsio_resid = MIN(totalLength, diff); - totalLength = auio->afsio_resid; + off_t diff; + /* + * afs_xwrite handles setting m.Length + * and handles APPEND mode. + * Since we are called via strategy, we need to trim the write to + * the actual size of the file + */ + osi_Assert(filePos <= avc->m.Length); + diff = avc->m.Length - filePos; + auio->afsio_resid = MIN(totalLength, diff); + totalLength = auio->afsio_resid; } #else if (aio & IO_APPEND) { @@ -154,11 +157,12 @@ afs_MemWrite(avc, auio, aio, acred, noLock) * Note that we use startDate rather than calling osi_Time() here. * This is to avoid counting lock-waiting time in file date (for ranlib). */ - avc->m.Date = startDate; + avc->m.Date = startDate; #if defined(AFS_HPUX_ENV) || defined(AFS_GFS_ENV) #if defined(AFS_HPUX101_ENV) - if ((totalLength + filePos) >> 9 > (p_rlimit(u.u_procp))[RLIMIT_FSIZE].rlim_cur) { + if ((totalLength + filePos) >> 9 > + (p_rlimit(u.u_procp))[RLIMIT_FSIZE].rlim_cur) { #else #ifdef AFS_HPUX_ENV if ((totalLength + filePos) >> 9 > u.u_rlimit[RLIMIT_FSIZE].rlim_cur) { @@ -177,13 +181,14 @@ afs_MemWrite(avc, auio, aio, acred, noLock) * high-level write op. */ if (avc->execsOrWriters <= 0) { - printf("WARNING: afs_ufswr vp=%x, exOrW=%d\n", avc, avc->execsOrWriters); + printf("WARNING: afs_ufswr vp=%x, exOrW=%d\n", avc, + avc->execsOrWriters); } #else afs_FakeOpen(avc); #endif avc->states |= CDirty; - tvec = (struct iovec *) osi_AllocSmallSpace(sizeof(struct iovec)); + tvec = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec)); while (totalLength > 0) { /* Read the cached info. If we call GetDCache while the cache * truncate daemon is running we risk overflowing the disk cache. @@ -193,96 +198,113 @@ afs_MemWrite(avc, auio, aio, acred, noLock) */ if (noLock) { tdc = afs_FindDCache(avc, filePos); - if (tdc) { - offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); - len = tdc->f.chunkBytes - offset; - } - } else if (afs_blocksUsed > (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100) { + if (tdc) + ObtainWriteLock(&tdc->lock, 653); + } else if (afs_blocksUsed > + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { tdc = afs_FindDCache(avc, filePos); if (tdc) { - if (!hsame(tdc->f.versionNo, avc->m.DataVersion) || - (tdc->flags & DFFetching)) { + ObtainWriteLock(&tdc->lock, 654); + if (!hsame(tdc->f.versionNo, avc->m.DataVersion) + || (tdc->dflags & DFFetching)) { + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); tdc = NULL; - } else { - offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); - len = tdc->f.chunkBytes - offset; } } if (!tdc) { afs_MaybeWakeupTruncateDaemon(); while (afs_blocksUsed > - (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100) { + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { ReleaseWriteLock(&avc->lock); if (afs_blocksUsed - afs_blocksDiscarded > - (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100) { + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { afs_WaitForCacheDrain = 1; afs_osi_Sleep(&afs_WaitForCacheDrain); } afs_MaybeFreeDiscardedDCache(); afs_MaybeWakeupTruncateDaemon(); - ObtainWriteLock(&avc->lock,506); + ObtainWriteLock(&avc->lock, 506); } avc->states |= CDirty; tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 4); + if (tdc) + ObtainWriteLock(&tdc->lock, 655); } } else { tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 4); + if (tdc) + ObtainWriteLock(&tdc->lock, 656); } if (!tdc) { error = EIO; break; } if (!(afs_indexFlags[tdc->index] & IFDataMod)) { - afs_stats_cmperf.cacheCurrDirtyChunks++; - afs_indexFlags[tdc->index] |= IFDataMod; /* so it doesn't disappear */ + afs_stats_cmperf.cacheCurrDirtyChunks++; + afs_indexFlags[tdc->index] |= IFDataMod; /* so it doesn't disappear */ } if (!(tdc->f.states & DWriting)) { /* don't mark entry as mod if we don't have to */ tdc->f.states |= DWriting; - tdc->flags |= DFEntryMod; + tdc->dflags |= DFEntryMod; } len = totalLength; /* write this amount by default */ + offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); max = AFS_CHUNKTOSIZE(tdc->f.chunk); /* max size of this chunk */ - if (max <= len + offset) { /*if we'd go past the end of this chunk */ + if (max <= len + offset) { /*if we'd go past the end of this chunk */ /* it won't all fit in this chunk, so write as much - as will fit */ + * as will fit */ len = max - offset; } /* mung uio structure to be right for this transfer */ afsio_copy(auio, &tuio, tvec); - afsio_trim(&tuio, len); + trimlen = len; + afsio_trim(&tuio, trimlen); tuio.afsio_offset = offset; code = afs_MemWriteUIO(tdc->f.inode, &tuio); if (code) { - void *mep; /* XXX in prototype world is struct memCacheEntry * */ + void *mep; /* XXX in prototype world is struct memCacheEntry * */ error = code; - ZapDCE(tdc); /* bad data */ + ZapDCE(tdc); /* bad data */ mep = afs_MemCacheOpen(tdc->f.inode); afs_MemCacheTruncate(mep, 0); afs_MemCacheClose(mep); afs_stats_cmperf.cacheCurrDirtyChunks--; - afs_indexFlags[tdc->index] &= ~IFDataMod; /* so it does disappear */ + afs_indexFlags[tdc->index] &= ~IFDataMod; /* so it does disappear */ + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); break; } /* otherwise we've written some, fixup length, etc and continue with next seg */ - len = len - tuio.afsio_resid; /* compute amount really transferred */ - afsio_skip(auio, len); /* advance auio over data written */ + len = len - tuio.afsio_resid; /* compute amount really transferred */ + tlen = len; + afsio_skip(auio, tlen); /* advance auio over data written */ /* compute new file size */ - if (offset + len > tdc->f.chunkBytes) - afs_AdjustSize(tdc, offset+len); + if (offset + len > tdc->f.chunkBytes) { + afs_int32 tlength = offset + len; + afs_AdjustSize(tdc, tlength); + if (tdc->validPos < filePos + len) + tdc->validPos = filePos + len; + } totalLength -= len; transferLength += len; filePos += len; #if defined(AFS_SGI_ENV) - /* afs_xwrite handles setting m.Length */ - osi_Assert(filePos <= avc->m.Length); + /* afs_xwrite handles setting m.Length */ + osi_Assert(filePos <= avc->m.Length); #else - if (filePos > avc->m.Length) + if (filePos > avc->m.Length) { + afs_Trace4(afs_iclSetp, CM_TRACE_SETLENGTH, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_LONG, __LINE__, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(filePos)); avc->m.Length = filePos; + } #endif + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); #if !defined(AFS_VM_RDWR_ENV) /* * If write is implemented via VM, afs_DoPartialWrite() is called from @@ -292,12 +314,10 @@ afs_MemWrite(avc, auio, aio, acred, noLock) code = afs_DoPartialWrite(avc, &treq); if (code) { error = code; - afs_PutDCache(tdc); break; } } #endif - afs_PutDCache(tdc); } #ifndef AFS_VM_RDWR_ENV afs_FakeClose(avc, acred); @@ -309,8 +329,8 @@ afs_MemWrite(avc, auio, aio, acred, noLock) osi_FreeSmallSpace(tvec); #ifdef AFS_DEC_ENV /* next, on GFS systems, we update g_size so that lseek's relative to EOF will - work. GFS is truly a poorly-designed interface! */ - afs_gfshack((struct gnode *) avc); + * work. GFS is truly a poorly-designed interface! */ + afs_gfshack((struct gnode *)avc); #endif error = afs_CheckCode(error, &treq, 6); return error; @@ -318,65 +338,68 @@ afs_MemWrite(avc, auio, aio, acred, noLock) /* called on writes */ -afs_UFSWrite(avc, auio, aio, acred, noLock) - register struct vcache *avc; - struct uio *auio; - int aio, noLock; - struct AFS_UCRED *acred; { - afs_int32 totalLength; - afs_int32 transferLength; - afs_int32 filePos; +int +afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio, + struct AFS_UCRED *acred, int noLock) +{ + afs_size_t totalLength; + afs_size_t transferLength; + afs_size_t filePos; + afs_size_t offset, len; + afs_int32 tlen; + afs_int32 trimlen; afs_int32 startDate; afs_int32 max; register struct dcache *tdc; #ifdef _HIGHC_ volatile #endif - afs_int32 offset, len, error; + afs_int32 error; struct uio tuio; - struct iovec *tvec; /* again, should have define */ + struct iovec *tvec; /* again, should have define */ struct osi_file *tfile; register afs_int32 code; - struct vnode *vp; struct vrequest treq; AFS_STATCNT(afs_UFSWrite); if (avc->vc_error) - return avc->vc_error; + return avc->vc_error; startDate = osi_Time(); - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; /* otherwise we read */ totalLength = auio->afsio_resid; filePos = auio->afsio_offset; error = 0; transferLength = 0; - afs_Trace4(afs_iclSetp, CM_TRACE_WRITE, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, filePos, ICL_TYPE_INT32, totalLength, - ICL_TYPE_INT32, avc->m.Length); + afs_Trace4(afs_iclSetp, CM_TRACE_WRITE, ICL_TYPE_POINTER, avc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(filePos), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(totalLength), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length)); if (!noLock) { afs_MaybeWakeupTruncateDaemon(); - ObtainWriteLock(&avc->lock,556); + ObtainWriteLock(&avc->lock, 556); } #if defined(AFS_SGI_ENV) { - off_t diff; - /* - * afs_xwrite handles setting m.Length - * and handles APPEND mode. - * Since we are called via strategy, we need to trim the write to - * the actual size of the file - */ - osi_Assert(filePos <= avc->m.Length); - diff = avc->m.Length - filePos; - auio->afsio_resid = MIN(totalLength, diff); - totalLength = auio->afsio_resid; + off_t diff; + /* + * afs_xwrite handles setting m.Length + * and handles APPEND mode. + * Since we are called via strategy, we need to trim the write to + * the actual size of the file + */ + osi_Assert(filePos <= avc->m.Length); + diff = avc->m.Length - filePos; + auio->afsio_resid = MIN(totalLength, diff); + totalLength = auio->afsio_resid; } #else if (aio & IO_APPEND) { /* append mode, start it at the right spot */ #if defined(AFS_SUN56_ENV) - auio->uio_loffset = 0; + auio->uio_loffset = 0; #endif filePos = auio->afsio_offset = avc->m.Length; } @@ -385,11 +408,12 @@ afs_UFSWrite(avc, auio, aio, acred, noLock) * Note that we use startDate rather than calling osi_Time() here. * This is to avoid counting lock-waiting time in file date (for ranlib). */ - avc->m.Date = startDate; + avc->m.Date = startDate; #if defined(AFS_HPUX_ENV) || defined(AFS_GFS_ENV) #if defined(AFS_HPUX101_ENV) - if ((totalLength + filePos) >> 9 > p_rlimit(u.u_procp)[RLIMIT_FSIZE].rlim_cur) { + if ((totalLength + filePos) >> 9 > + p_rlimit(u.u_procp)[RLIMIT_FSIZE].rlim_cur) { #else #ifdef AFS_HPUX_ENV if ((totalLength + filePos) >> 9 > u.u_rlimit[RLIMIT_FSIZE].rlim_cur) { @@ -408,186 +432,204 @@ afs_UFSWrite(avc, auio, aio, acred, noLock) * high-level write op. */ if (avc->execsOrWriters <= 0) { - printf("WARNING: afs_ufswr vp=%x, exOrW=%d\n", avc, avc->execsOrWriters); + printf("WARNING: afs_ufswr vcp=%x, exOrW=%d\n", avc, + avc->execsOrWriters); } #else afs_FakeOpen(avc); #endif avc->states |= CDirty; - tvec = (struct iovec *) osi_AllocSmallSpace(sizeof(struct iovec)); + tvec = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec)); while (totalLength > 0) { + /* + * The following line is necessary because afs_GetDCache with + * flag == 4 expects the length field to be filled. It decides + * from this whether it's necessary to fetch data into the chunk + * before writing or not (when the whole chunk is overwritten!). + */ + len = totalLength; /* write this amount by default */ /* read the cached info */ if (noLock) { tdc = afs_FindDCache(avc, filePos); - if (tdc) { - offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); - len = tdc->f.chunkBytes - offset; - } - } else if (afs_blocksUsed > (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100) { + if (tdc) + ObtainWriteLock(&tdc->lock, 657); + } else if (afs_blocksUsed > + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { tdc = afs_FindDCache(avc, filePos); if (tdc) { - if (!hsame(tdc->f.versionNo, avc->m.DataVersion) || - (tdc->flags & DFFetching)) { + ObtainWriteLock(&tdc->lock, 658); + if (!hsame(tdc->f.versionNo, avc->m.DataVersion) + || (tdc->dflags & DFFetching)) { + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); tdc = NULL; - } else { - offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); - len = tdc->f.chunkBytes - offset; } } if (!tdc) { afs_MaybeWakeupTruncateDaemon(); while (afs_blocksUsed > - (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100) { + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { ReleaseWriteLock(&avc->lock); if (afs_blocksUsed - afs_blocksDiscarded > - (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100) { + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { afs_WaitForCacheDrain = 1; afs_osi_Sleep(&afs_WaitForCacheDrain); } afs_MaybeFreeDiscardedDCache(); afs_MaybeWakeupTruncateDaemon(); - ObtainWriteLock(&avc->lock,509); + ObtainWriteLock(&avc->lock, 509); } avc->states |= CDirty; tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 4); + if (tdc) + ObtainWriteLock(&tdc->lock, 659); } } else { tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 4); + if (tdc) + ObtainWriteLock(&tdc->lock, 660); } if (!tdc) { error = EIO; break; } if (!(afs_indexFlags[tdc->index] & IFDataMod)) { - afs_stats_cmperf.cacheCurrDirtyChunks++; - afs_indexFlags[tdc->index] |= IFDataMod; /* so it doesn't disappear */ + afs_stats_cmperf.cacheCurrDirtyChunks++; + afs_indexFlags[tdc->index] |= IFDataMod; /* so it doesn't disappear */ } if (!(tdc->f.states & DWriting)) { /* don't mark entry as mod if we don't have to */ tdc->f.states |= DWriting; - tdc->flags |= DFEntryMod; + tdc->dflags |= DFEntryMod; } tfile = (struct osi_file *)osi_UFSOpen(tdc->f.inode); len = totalLength; /* write this amount by default */ + offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk); max = AFS_CHUNKTOSIZE(tdc->f.chunk); /* max size of this chunk */ - if (max <= len + offset) { /*if we'd go past the end of this chunk */ + if (max <= len + offset) { /*if we'd go past the end of this chunk */ /* it won't all fit in this chunk, so write as much - as will fit */ + * as will fit */ len = max - offset; } /* mung uio structure to be right for this transfer */ afsio_copy(auio, &tuio, tvec); - afsio_trim(&tuio, len); + trimlen = len; + afsio_trim(&tuio, trimlen); tuio.afsio_offset = offset; -#ifdef AFS_AIX_ENV -#ifdef AFS_AIX41_ENV +#if defined(AFS_AIX41_ENV) AFS_GUNLOCK(); - code = VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, &tuio, NULL, NULL, NULL, &afs_osi_cred); + code = + VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, &tuio, NULL, NULL, + NULL, afs_osi_credp); AFS_GLOCK(); -#else -#ifdef AFS_AIX32_ENV +#elif defined(AFS_AIX32_ENV) code = VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, &tuio, NULL, NULL); -#else - code = VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, (off_t)&offset, &tuio, NULL, NULL, -1); -#endif -#endif /* AFS_AIX41_ENV */ -#else /* AFS_AIX_ENV */ -#ifdef AFS_SUN5_ENV +#elif defined(AFS_AIX_ENV) + code = + VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, (off_t) & offset, + &tuio, NULL, NULL, -1); +#elif defined(AFS_SUN5_ENV) AFS_GUNLOCK(); VOP_RWLOCK(tfile->vnode, 1); - code = VOP_WRITE(tfile->vnode, &tuio, 0, &afs_osi_cred); + code = VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp); VOP_RWUNLOCK(tfile->vnode, 1); AFS_GLOCK(); - if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is full - decrease cachesize!!! ***\n\n\n"); -#else -#if defined(AFS_SGI_ENV) + if (code == ENOSPC) + afs_warnuser + ("\n\n\n*** Cache partition is full - decrease cachesize!!! ***\n\n\n"); +#elif defined(AFS_SGI_ENV) AFS_GUNLOCK(); - avc->states |= CWritingUFS; + avc->states |= CWritingUFS; AFS_VOP_RWLOCK(tfile->vnode, VRWLOCK_WRITE); - AFS_VOP_WRITE(tfile->vnode, &tuio, IO_ISLOCKED, &afs_osi_cred, code); + AFS_VOP_WRITE(tfile->vnode, &tuio, IO_ISLOCKED, afs_osi_credp, code); AFS_VOP_RWUNLOCK(tfile->vnode, VRWLOCK_WRITE); - avc->states &= ~CWritingUFS; + avc->states &= ~CWritingUFS; AFS_GLOCK(); -#else -#ifdef AFS_OSF_ENV - { - struct ucred *tmpcred = u.u_cred; - u.u_cred = &afs_osi_cred; - tuio.uio_rw = UIO_WRITE; +#elif defined(AFS_OSF_ENV) + { + struct ucred *tmpcred = u.u_cred; + u.u_cred = afs_osi_credp; + tuio.uio_rw = UIO_WRITE; + AFS_GUNLOCK(); + VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp, code); + AFS_GLOCK(); + u.u_cred = tmpcred; + } +#elif defined(AFS_HPUX100_ENV) + { + AFS_GUNLOCK(); + code = VOP_RDWR(tfile->vnode, &tuio, UIO_WRITE, 0, afs_osi_credp); + AFS_GLOCK(); + } +#elif defined(AFS_LINUX20_ENV) AFS_GUNLOCK(); - VOP_WRITE(tfile->vnode, &tuio, 0, &afs_osi_cred, code); + code = osi_file_uio_rdwr(tfile, &tuio, UIO_WRITE); AFS_GLOCK(); - u.u_cred = tmpcred; - } -#else /* AFS_OSF_ENV */ -#if defined(AFS_HPUX100_ENV) - { +#elif defined(AFS_DARWIN_ENV) AFS_GUNLOCK(); - code = VOP_RDWR(tfile->vnode, &tuio, UIO_WRITE, 0, &afs_osi_cred); + VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc()); + code = VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp); + VOP_UNLOCK(tfile->vnode, 0, current_proc()); + AFS_GLOCK(); +#elif defined(AFS_FBSD50_ENV) + AFS_GUNLOCK(); + VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curthread); + code = VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp); + VOP_UNLOCK(tfile->vnode, 0, curthread); + AFS_GLOCK(); +#elif defined(AFS_XBSD_ENV) + AFS_GUNLOCK(); + VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc); + code = VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp); + VOP_UNLOCK(tfile->vnode, 0, curproc); AFS_GLOCK(); - } #else #ifdef AFS_HPUX_ENV tuio.uio_fpflags &= ~FSYNCIO; /* don't do sync io */ #endif -#if defined(AFS_LINUX20_ENV) - AFS_GUNLOCK(); - code = osi_file_uio_rdwr(tfile, &tuio, UIO_WRITE); - AFS_GLOCK(); -#else -#if defined(AFS_DARWIN_ENV) - AFS_GUNLOCK(); - VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc()); - code = VOP_WRITE(tfile->vnode, &tuio, 0, &afs_osi_cred); - VOP_UNLOCK(tfile->vnode, 0, current_proc()); - AFS_GLOCK(); -#else -#if defined(AFS_FBSD_ENV) - AFS_GUNLOCK(); - VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc); - code = VOP_WRITE(tfile->vnode, &tuio, 0, &afs_osi_cred); - VOP_UNLOCK(tfile->vnode, 0, curproc); - AFS_GLOCK(); -#else - code = VOP_RDWR(tfile->vnode, &tuio, UIO_WRITE, 0, &afs_osi_cred); -#endif /* AFS_FBSD_ENV */ -#endif /* AFS_DARWIN_ENV */ -#endif /* AFS_LINUX20_ENV */ -#endif /* AFS_HPUX100_ENV */ -#endif /* AFS_OSF_ENV */ -#endif /* AFS_SGI_ENV */ -#endif /* AFS_SUN5_ENV */ -#endif /* AFS_AIX41_ENV */ + code = VOP_RDWR(tfile->vnode, &tuio, UIO_WRITE, 0, afs_osi_credp); +#endif if (code) { error = code; - ZapDCE(tdc); /* bad data */ - osi_UFSTruncate(tfile,0); /* fake truncate the segment */ - afs_AdjustSize(tdc, 0); /* sets f.chunkSize to 0 */ + ZapDCE(tdc); /* bad data */ + osi_UFSTruncate(tfile, 0); /* fake truncate the segment */ + afs_AdjustSize(tdc, 0); /* sets f.chunkSize to 0 */ afs_stats_cmperf.cacheCurrDirtyChunks--; - afs_indexFlags[tdc->index] &= ~IFDataMod; /* so it does disappear */ - afs_PutDCache(tdc); + afs_indexFlags[tdc->index] &= ~IFDataMod; /* so it does disappear */ afs_CFileClose(tfile); + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); break; } /* otherwise we've written some, fixup length, etc and continue with next seg */ - len = len - tuio.afsio_resid; /* compute amount really transferred */ - afsio_skip(auio, len); /* advance auio over data written */ + len = len - tuio.afsio_resid; /* compute amount really transferred */ + tlen = len; + afsio_skip(auio, tlen); /* advance auio over data written */ /* compute new file size */ - if (offset + len > tdc->f.chunkBytes) - afs_AdjustSize(tdc, offset+len); + if (offset + len > tdc->f.chunkBytes) { + afs_int32 tlength = offset + len; + afs_AdjustSize(tdc, tlength); + if (tdc->validPos < filePos + len) + tdc->validPos = filePos + len; + } totalLength -= len; transferLength += len; filePos += len; #if defined(AFS_SGI_ENV) - /* afs_xwrite handles setting m.Length */ - osi_Assert(filePos <= avc->m.Length); + /* afs_xwrite handles setting m.Length */ + osi_Assert(filePos <= avc->m.Length); #else if (filePos > avc->m.Length) { + afs_Trace4(afs_iclSetp, CM_TRACE_SETLENGTH, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_LONG, __LINE__, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(filePos)); avc->m.Length = filePos; } #endif osi_UFSClose(tfile); + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); #if !defined(AFS_VM_RDWR_ENV) /* * If write is implemented via VM, afs_DoPartialWrite() is called from @@ -597,12 +639,10 @@ afs_UFSWrite(avc, auio, aio, acred, noLock) code = afs_DoPartialWrite(avc, &treq); if (code) { error = code; - afs_PutDCache(tdc); break; } } #endif - afs_PutDCache(tdc); } #ifndef AFS_VM_RDWR_ENV afs_FakeClose(avc, acred); @@ -616,23 +656,23 @@ afs_UFSWrite(avc, auio, aio, acred, noLock) osi_FreeSmallSpace(tvec); #ifdef AFS_DEC_ENV /* next, on GFS systems, we update g_size so that lseek's relative to EOF will - work. GFS is truly a poorly-designed interface! */ - afs_gfshack((struct gnode *) avc); + * work. GFS is truly a poorly-designed interface! */ + afs_gfshack((struct gnode *)avc); #endif #ifndef AFS_VM_RDWR_ENV /* * If write is implemented via VM, afs_fsync() is called from the high-level * write op. */ -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - if (noLock && (aio & IO_SYNC)) { -#else +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + if (noLock && (aio & IO_SYNC)) { +#else #ifdef AFS_HPUX_ENV /* On hpux on synchronous writes syncio will be set to IO_SYNC. If * we're doing them because the file was opened with O_SYNCIO specified, * we have to look in the u area. No single mechanism here!! */ - if (noLock && ((aio & IO_SYNC) | (auio->uio_fpflags & FSYNCIO))) { + if (noLock && ((aio & IO_SYNC) | (auio->uio_fpflags & FSYNCIO))) { #else if (noLock && (aio & FSYNC)) { #endif @@ -645,16 +685,17 @@ afs_UFSWrite(avc, auio, aio, acred, noLock) } /* do partial write if we're low on unmodified chunks */ -afs_DoPartialWrite(avc, areq) -register struct vcache *avc; -struct vrequest *areq; { +int +afs_DoPartialWrite(register struct vcache *avc, struct vrequest *areq) +{ register afs_int32 code; - if (afs_stats_cmperf.cacheCurrDirtyChunks <= afs_stats_cmperf.cacheMaxDirtyChunks) - return 0; /* nothing to do */ + if (afs_stats_cmperf.cacheCurrDirtyChunks <= + afs_stats_cmperf.cacheMaxDirtyChunks) + return 0; /* nothing to do */ /* otherwise, call afs_StoreDCache (later try to do this async, if possible) */ afs_Trace2(afs_iclSetp, CM_TRACE_PARTIALWRITE, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length); + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length)); #if defined(AFS_SUN5_ENV) code = afs_StoreAllSegments(avc, areq, AFS_ASYNC | AFS_VMSYNC_INVAL); #else @@ -665,7 +706,7 @@ struct vrequest *areq; { -#if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV) && !defined (AFS_SUN5_ENV) && !defined(AFS_SGI_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV) && !defined (AFS_SUN5_ENV) && !defined(AFS_SGI_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) #ifdef AFS_DUX50_ENV #define vno_close(X) vn_close((X), 0, NOCRED) #elif defined(AFS_DUX40_ENV) @@ -686,8 +727,9 @@ struct vrequest *areq; { * N.B: Intercepting close syscall doesn't trap aborts or exit system * calls. */ -afs_closex(afd) - register struct file *afd; { +int +afs_closex(register struct file *afd) +{ struct vrequest treq; struct vcache *tvc; afs_int32 flags; @@ -697,7 +739,8 @@ afs_closex(afd) AFS_STATCNT(afs_closex); /* setup the credentials */ - if (code = afs_InitReq(&treq, u.u_cred)) return code; + if ((code = afs_InitReq(&treq, u.u_cred))) + return code; afs_InitFakeStat(&fakestat); closeDone = 0; @@ -709,22 +752,22 @@ afs_closex(afd) if (IsAfsVnode(AFSTOV(tvc))) { code = afs_EvalFakeStat(&tvc, &fakestat, &treq); if (code) { - afs_PutFakeStat(&fakestat); - return code; + afs_PutFakeStat(&fakestat); + return code; } VN_HOLD(AFSTOV(tvc)); flags = afd->f_flag & (FSHLOCK | FEXLOCK); afd->f_flag &= ~(FSHLOCK | FEXLOCK); code = vno_close(afd); - if (flags) + if (flags) #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV) - HandleFlock(tvc, LOCK_UN, &treq, - u.u_procp->p_pid, 1/*onlymine*/); + HandleFlock(tvc, LOCK_UN, &treq, u.u_procp->p_pid, + 1 /*onlymine */ ); #else - HandleFlock(tvc, LOCK_UN, &treq, 0, 1/*onlymine*/); + HandleFlock(tvc, LOCK_UN, &treq, 0, 1 /*onlymine */ ); #endif #ifdef AFS_DEC_ENV - grele((struct gnode *) tvc); + grele((struct gnode *)tvc); #else AFS_RELE(AFSTOV(tvc)); #endif @@ -736,12 +779,13 @@ afs_closex(afd) code = vno_close(afd); } afs_PutFakeStat(&fakestat); - return code; /* return code from vnode layer */ + return code; /* return code from vnode layer */ } #endif /* handle any closing cleanup stuff */ +int #ifdef AFS_SGI_ENV afs_close(OSI_VC_ARG(avc), aflags, lastclose, #if !defined(AFS_SGI65_ENV) @@ -751,30 +795,28 @@ afs_close(OSI_VC_ARG(avc), aflags, lastclose, #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV) , flp #endif - ) -lastclose_t lastclose; + ) + lastclose_t lastclose; #if !defined(AFS_SGI65_ENV) -off_t offset; + off_t offset; #if defined(AFS_SGI64_ENV) -struct flid *flp; + struct flid *flp; #endif #endif -#else /* SGI */ -#if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV) +#elif defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV) #ifdef AFS_SUN5_ENV afs_close(OSI_VC_ARG(avc), aflags, count, offset, acred) - offset_t offset; + offset_t offset; #else afs_close(OSI_VC_ARG(avc), aflags, count, acred) #endif -int count; + int count; #else afs_close(OSI_VC_ARG(avc), aflags, acred) #endif -#endif - OSI_VC_DECL(avc); - afs_int32 aflags; - struct AFS_UCRED *acred; +OSI_VC_DECL(avc); + afs_int32 aflags; + struct AFS_UCRED *acred; { register afs_int32 code; register struct brequest *tb; @@ -785,11 +827,12 @@ afs_close(OSI_VC_ARG(avc), aflags, acred) struct afs_fakestat_state fakestat; OSI_VC_CONVERT(avc) - AFS_STATCNT(afs_close); + AFS_STATCNT(afs_close); afs_Trace2(afs_iclSetp, CM_TRACE_CLOSE, ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, aflags); code = afs_InitReq(&treq, acred); - if (code) return code; + if (code) + return code; afs_InitFakeStat(&fakestat); code = afs_EvalFakeStat(&avc, &fakestat, &treq); if (code) { @@ -798,69 +841,67 @@ afs_close(OSI_VC_ARG(avc), aflags, acred) } #ifdef AFS_SUN5_ENV if (avc->flockCount) { - HandleFlock(avc, LOCK_UN, &treq, 0, 1/*onlymine*/); + HandleFlock(avc, LOCK_UN, &treq, 0, 1 /*onlymine */ ); } #endif #if defined(AFS_SGI_ENV) if (!lastclose) { afs_PutFakeStat(&fakestat); - return 0; + return 0; } -#else -#if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) +#elif defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) if (count > 1) { /* The vfs layer may call this repeatedly with higher "count"; only on the last close (i.e. count = 1) we should actually proceed with the close. */ afs_PutFakeStat(&fakestat); return 0; } #endif -#endif #ifndef AFS_SUN5_ENV #if defined(AFS_SGI_ENV) /* unlock any locks for pid - could be wrong for child .. */ - AFS_RWLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWLOCK((vnode_t *) avc, VRWLOCK_WRITE); #ifdef AFS_SGI65_ENV get_current_flid(&flid); - cleanlocks((vnode_t *)avc, flid.fl_pid, flid.fl_sysid); - HandleFlock(avc, LOCK_UN, &treq, flid.fl_pid, 1/*onlymine*/); + cleanlocks((vnode_t *) avc, flid.fl_pid, flid.fl_sysid); + HandleFlock(avc, LOCK_UN, &treq, flid.fl_pid, 1 /*onlymine */ ); #else #ifdef AFS_SGI64_ENV - cleanlocks((vnode_t *)avc, flp); + cleanlocks((vnode_t *) avc, flp); #else /* AFS_SGI64_ENV */ - cleanlocks((vnode_t *)avc, u.u_procp->p_epid, u.u_procp->p_sysid); + cleanlocks((vnode_t *) avc, u.u_procp->p_epid, u.u_procp->p_sysid); #endif /* AFS_SGI64_ENV */ - HandleFlock(avc, LOCK_UN, &treq, OSI_GET_CURRENT_PID(), 1/*onlymine*/); + HandleFlock(avc, LOCK_UN, &treq, OSI_GET_CURRENT_PID(), 1 /*onlymine */ ); #endif /* AFS_SGI65_ENV */ /* afs_chkpgoob will drop and re-acquire the global lock. */ afs_chkpgoob(&avc->v, btoc(avc->m.Length)); -#else - if (avc->flockCount) { /* Release Lock */ +#else /* AFS_SGI_ENV */ + if (avc->flockCount) { /* Release Lock */ #if defined(AFS_OSF_ENV) || defined(AFS_SUN_ENV) - HandleFlock(avc, LOCK_UN, &treq, u.u_procp->p_pid, 1/*onlymine*/); + HandleFlock(avc, LOCK_UN, &treq, u.u_procp->p_pid, 1 /*onlymine */ ); #else - HandleFlock(avc, LOCK_UN, &treq, 0, 1/*onlymine*/); + HandleFlock(avc, LOCK_UN, &treq, 0, 1 /*onlymine */ ); #endif } -#endif -#endif +#endif /* AFS_SGI_ENV */ +#endif /* AFS_SUN5_ENV */ if (aflags & (FWRITE | FTRUNC)) { if (afs_BBusy()) { /* do it yourself if daemons are all busy */ - ObtainWriteLock(&avc->lock,124); + ObtainWriteLock(&avc->lock, 124); code = afs_StoreOnLastReference(avc, &treq); ReleaseWriteLock(&avc->lock); #if defined(AFS_SGI_ENV) - AFS_RWUNLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE); #endif - } - else { + } else { #if defined(AFS_SGI_ENV) - AFS_RWUNLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE); #endif /* at least one daemon is idle, so ask it to do the store. - Also, note that we don't lock it any more... */ - tb = afs_BQueue(BOP_STORE, avc, 0, 1, acred, (long)acred->cr_uid, - 0L, 0L, 0L); + * Also, note that we don't lock it any more... */ + tb = afs_BQueue(BOP_STORE, avc, 0, 1, acred, + (afs_size_t) acred->cr_uid, (afs_size_t) 0, + (void *)0); /* sleep waiting for the store to start, then retrieve error code */ while ((tb->flags & BUVALID) == 0) { tb->flags |= BUWAIT; @@ -871,16 +912,16 @@ afs_close(OSI_VC_ARG(avc), aflags, acred) } /* VNOVNODE is "acceptable" error code from close, since - may happen when deleting a file on another machine while - it is open here. We do the same for ENOENT since in afs_CheckCode we map VNOVNODE -> ENOENT */ + * may happen when deleting a file on another machine while + * it is open here. We do the same for ENOENT since in afs_CheckCode we map VNOVNODE -> ENOENT */ if (code == VNOVNODE || code == ENOENT) code = 0; - + /* Ensure last closer gets the error. If another thread caused * DoPartialWrite and this thread does not actually store the data, * it may not see the quota error. */ - ObtainWriteLock(&avc->lock,406); + ObtainWriteLock(&avc->lock, 406); if (avc->vc_error) { #ifdef AFS_AIX32_ENV osi_ReleaseVM(avc, acred); @@ -896,13 +937,13 @@ afs_close(OSI_VC_ARG(avc), aflags, acred) } #ifdef AFS_SUN5_ENV else if (code == ENOSPC) { - afs_warnuser("afs: failed to store file (over quota or partition full)\n"); + afs_warnuser + ("afs: failed to store file (over quota or partition full)\n"); } #else else if (code == ENOSPC) { afs_warnuser("afs: failed to store file (partition full)\n"); - } - else if (code == EDQUOT) { + } else if (code == EDQUOT) { afs_warnuser("afs: failed to store file (over quota)\n"); } #endif @@ -912,10 +953,9 @@ afs_close(OSI_VC_ARG(avc), aflags, acred) /* finally, we flush any text pages lying around here */ hzero(avc->flushDV); osi_FlushText(avc); - } - else { + } else { #if defined(AFS_SGI_ENV) - AFS_RWUNLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE); osi_Assert(avc->opens > 0); #endif /* file open for read */ @@ -941,28 +981,28 @@ afs_close(OSI_VC_ARG(avc), aflags, acred) } - +int #ifdef AFS_OSF_ENV afs_fsync(avc, fflags, acred, waitfor) -int fflags; -int waitfor; -#else /* AFS_OSF_ENV */ + int fflags; + int waitfor; +#else /* AFS_OSF_ENV */ #if defined(AFS_SGI_ENV) || defined(AFS_SUN53_ENV) afs_fsync(OSI_VC_ARG(avc), flag, acred #ifdef AFS_SGI65_ENV - , start, stop + , start, stop #endif - ) + ) #else afs_fsync(avc, acred) #endif #endif - OSI_VC_DECL(avc); +OSI_VC_DECL(avc); struct AFS_UCRED *acred; #if defined(AFS_SGI_ENV) || defined(AFS_SUN53_ENV) -int flag; + int flag; #ifdef AFS_SGI65_ENV -off_t start, stop; + off_t start, stop; #endif #endif { @@ -970,41 +1010,41 @@ off_t start, stop; struct vrequest treq; OSI_VC_CONVERT(avc) - if (avc->vc_error) + if (avc->vc_error) return avc->vc_error; #if defined(AFS_SUN5_ENV) - /* back out if called from NFS server */ + /* back out if called from NFS server */ if (curthread->t_flag & T_DONTPEND) return 0; #endif AFS_STATCNT(afs_fsync); afs_Trace1(afs_iclSetp, CM_TRACE_FSYNC, ICL_TYPE_POINTER, avc); - if (code = afs_InitReq(&treq, acred)) return code; + if ((code = afs_InitReq(&treq, acred))) + return code; #if defined(AFS_SGI_ENV) - AFS_RWLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWLOCK((vnode_t *) avc, VRWLOCK_WRITE); if (flag & FSYNC_INVAL) osi_VM_FSyncInval(avc); #endif /* AFS_SGI_ENV */ - ObtainSharedLock(&avc->lock,18); + ObtainSharedLock(&avc->lock, 18); code = 0; if (avc->execsOrWriters > 0) { /* put the file back */ - UpgradeSToWLock(&avc->lock,41); + UpgradeSToWLock(&avc->lock, 41); code = afs_StoreAllSegments(avc, &treq, AFS_SYNC); ConvertWToSLock(&avc->lock); } - #if defined(AFS_SGI_ENV) - AFS_RWUNLOCK((vnode_t *)avc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE); if (code == VNOVNODE) { /* syncing an unlinked file! - non-informative to pass an errno * 102 (== VNOVNODE) to user */ - code = ENOENT; + code = ENOENT; } #endif diff --git a/src/afs/afs.h b/src/afs/afs.h index 8f93de5c4..355a29345 100644 --- a/src/afs/afs.h +++ b/src/afs/afs.h @@ -15,7 +15,7 @@ #ifdef KDUMP_KERNEL #include #else -#include "../afs/afs_args.h" +#include "afs/afs_args.h" #endif @@ -39,6 +39,17 @@ extern int afs_shuttingdown; #endif #endif +/* Moved from VNOPS/afs_vnop_flocks so can be used in prototypes */ +#if defined(AFS_HPUX102_ENV) +#define AFS_FLOCK k_flock +#else +#if defined(AFS_SUN56_ENV) || defined(AFS_LINUX24_ENV) +#define AFS_FLOCK flock64 +#else +#define AFS_FLOCK flock +#endif /* AFS_SUN65_ENV */ +#endif /* AFS_HPUX102_ENV */ + /* The following are various levels of afs debugging */ #define AFSDEB_GENERAL 1 /* Standard debugging */ #define AFSDEB_NETWORK 2 /* low level afs networking */ @@ -50,39 +61,43 @@ extern int afs_shuttingdown; /* The basic defines for the Andrew file system better keep things powers of two so "& (foo-1)" hack works for masking bits */ -#define MAXHOSTS 13 /* max hosts per single volume */ -#define OMAXHOSTS 8 /* backwards compatibility */ -#define MAXCELLHOSTS 8 /* max vldb servers per cell */ -#define NBRS 15 /* max number of queued daemon requests */ -#define NUSERS 16 /* hash table size for unixuser table */ -#define NSERVERS 16 /* hash table size for server table */ -#define NVOLS 64 /* hash table size for volume table */ -#define NFENTRIES 256 /* hash table size for disk volume table */ -#define VCSIZE 1024 /* stat cache hash table size */ -#define DCSIZE 512 /* disk cache hash table size */ -#define PIGGYSIZE 1350 /* max piggyback size */ -#define MAXVOLS 128 /* max vols we can store */ -#define MAXSYSNAME 128 /* max sysname (i.e. @sys) size */ -#define MAXNUMSYSNAMES 16 /* max that current constants allow */ -#define NOTOKTIMEOUT (2*3600) /* time after which to timeout conns sans tokens */ +#define MAXHOSTS 13 /* max hosts per single volume */ +#define OMAXHOSTS 8 /* backwards compatibility */ +#define MAXCELLHOSTS 8 /* max vldb servers per cell */ +#define NBRS 15 /* max number of queued daemon requests */ +#define NUSERS 16 /* hash table size for unixuser table */ +#define NSERVERS 16 /* hash table size for server table */ +#define NVOLS 64 /* hash table size for volume table */ +#define NFENTRIES 256 /* hash table size for disk volume table */ +#define VCSIZE 1024 /* stat cache hash table size */ +#define DCSIZE 512 /* disk cache hash table size */ +#define CBRSIZE 512 /* call back returns hash table size */ +#define PIGGYSIZE 1350 /* max piggyback size */ +#define MAXVOLS 128 /* max vols we can store */ +#define MAXSYSNAME 128 /* max sysname (i.e. @sys) size */ +#define MAXNUMSYSNAMES 16 /* max that current constants allow */ +#define NOTOKTIMEOUT (2*3600) /* time after which to timeout conns sans tokens */ #define NOPAG 0xffffffff -#define AFS_NCBRS 300 /* max # of call back return entries */ -#define AFS_MAXCBRSCALL 16 /* max to return in a given call */ -#define AFS_SALLOC_LOW_WATER 250 /* Min free blocks before allocating more */ -#define AFS_LRALLOCSIZ 4096 /* "Large" allocated size */ +#define AFS_NCBRS 300 /* max # of call back return entries */ +#define AFS_MAXCBRSCALL 16 /* max to return in a given call */ +#define AFS_SALLOC_LOW_WATER 250 /* Min free blocks before allocating more */ +#define AFS_LRALLOCSIZ 4096 /* "Large" allocated size */ #define VCACHE_FREE 5 #define AFS_NRXPACKETS 80 #define AFS_RXDEADTIME 50 -#define AFS_HARDDEADTIME 120 +#define AFS_HARDDEADTIME 120 + +extern afs_int32 afs_rx_deadtime; +extern afs_int32 afs_rx_harddead; struct sysname_info { - char *name; - short offset; - char index, allocked; + char *name; + short offset; + char index, allocked; }; /* flags to use with AFSOP_CACHEINIT */ -#define AFSCALL_INIT_MEMCACHE 0x1 /* use a memory-based cache */ +#define AFSCALL_INIT_MEMCACHE 0x1 /* use a memory-based cache */ /* below here used only for kernel procedures */ #ifdef KERNEL @@ -97,12 +112,12 @@ struct sysname_info { /* background request structure */ #define BPARMS 4 -#define BOP_NOOP 0 /* leave 0 unused */ -#define BOP_FETCH 1 /* parm1 is chunk to get */ -#define BOP_STORE 2 /* parm1 is chunk to store */ -#define BOP_PATH 3 /* parm1 is path, parm2 is chunk to fetch */ +#define BOP_NOOP 0 /* leave 0 unused */ +#define BOP_FETCH 1 /* parm1 is chunk to get */ +#define BOP_STORE 2 /* parm1 is chunk to store */ +#define BOP_PATH 3 /* parm1 is path, parm2 is chunk to fetch */ -#define B_DONTWAIT 1 /* On failure return; don't wait */ +#define B_DONTWAIT 1 /* On failure return; don't wait */ /* protocol is: refCount is incremented by user to take block out of free pool. Next, BSTARTED is set when daemon finds request. This prevents @@ -110,19 +125,19 @@ struct sysname_info { request is done, refCount is zeroed. BDONE and BWAIT are used by dudes waiting for operation to proceed to a certain point before returning. */ -#define BSTARTED 1 /* request picked up by a daemon */ -#define BUVALID 2 /* code is valid (store) */ -#define BUWAIT 4 /* someone is waiting for BUVALID */ +#define BSTARTED 1 /* request picked up by a daemon */ +#define BUVALID 2 /* code is valid (store) */ +#define BUWAIT 4 /* someone is waiting for BUVALID */ struct brequest { - struct vcache *vnode; /* vnode to use, with vrefcount bumped */ - struct AFS_UCRED *cred; /* credentials to use for operation */ - long parm[BPARMS]; /* random parameters - long's work for - * both 32 and 64 bit platforms. - */ - afs_int32 code; /* return code */ - short refCount; /* use counter for this structure */ - char opcode; /* what to do (store, fetch, etc) */ - char flags; /* free, etc */ + struct vcache *vc; /* vnode to use, with vrefcount bumped */ + struct AFS_UCRED *cred; /* credentials to use for operation */ + afs_size_t size_parm[BPARMS]; /* random parameters */ + void *ptr_parm[BPARMS]; /* pointer parameters */ + afs_int32 code; /* return code */ + short refCount; /* use counter for this structure */ + char opcode; /* what to do (store, fetch, etc) */ + char flags; /* free, etc */ + afs_int32 ts; /* counter "timestamp" */ }; struct SecretToken { @@ -130,15 +145,15 @@ struct SecretToken { }; struct ClearToken { - afs_int32 AuthHandle; - char HandShakeKey[8]; - afs_int32 ViceId; - afs_int32 BeginTimestamp; - afs_int32 EndTimestamp; + afs_int32 AuthHandle; + char HandShakeKey[8]; + afs_int32 ViceId; + afs_int32 BeginTimestamp; + afs_int32 EndTimestamp; }; struct VenusFid { - afs_int32 Cell; /* better sun packing if at end of structure */ + afs_int32 Cell; /* better sun packing if at end of structure */ struct AFSFid Fid; }; @@ -161,9 +176,9 @@ struct afs_q { }; struct vrequest { - afs_int32 uid; /* user id making the request */ - afs_int32 busyCount; /* how many busies we've seen so far */ - afs_int32 flags; /* things like O_SYNC, O_NONBLOCK go here */ + afs_int32 uid; /* user id making the request */ + afs_int32 busyCount; /* how many busies we've seen so far */ + afs_int32 flags; /* things like O_SYNC, O_NONBLOCK go here */ char initd; /* if non-zero, non-uid fields meaningful */ char accessError; /* flags for overriding error return code */ char volumeError; /* encountered a missing or busy volume */ @@ -177,7 +192,12 @@ struct vrequest { * callbacks. Sent asynchronously when we run a little low on free dudes. */ struct afs_cbr { + struct afs_cbr **pprev; struct afs_cbr *next; + + struct afs_cbr **hash_pprev; + struct afs_cbr *hash_next; + struct AFSFid fid; }; @@ -192,18 +212,18 @@ struct afs_cbr { #define CLinkedCell 0x20 /* has a linked cell in lcellp */ struct cell { - struct afs_q lruq; /* lru q next and prev */ - char *cellName; /* char string name of cell */ - afs_int32 cellIndex; /* sequence number */ - afs_int32 cellNum; /* semi-permanent cell number */ - struct server *cellHosts[MAXCELLHOSTS]; /* volume *location* hosts */ - struct cell *lcellp; /* Associated linked cell */ - u_short fsport; /* file server port */ - u_short vlport; /* volume server port */ - short states; /* state flags */ - time_t timeout; /* data expire time, if non-zero */ - struct cell_name *cnamep; /* pointer to our cell_name */ - afs_rwlock_t lock; /* protects cell data */ + struct afs_q lruq; /* lru q next and prev */ + char *cellName; /* char string name of cell */ + afs_int32 cellIndex; /* sequence number */ + afs_int32 cellNum; /* semi-permanent cell number */ + struct server *cellHosts[MAXCELLHOSTS]; /* volume *location* hosts */ + struct cell *lcellp; /* Associated linked cell */ + u_short fsport; /* file server port */ + u_short vlport; /* volume server port */ + short states; /* state flags */ + time_t timeout; /* data expire time, if non-zero */ + struct cell_name *cnamep; /* pointer to our cell_name */ + afs_rwlock_t lock; /* protects cell data */ }; struct cell_name { @@ -223,11 +243,11 @@ struct cell_alias { #define afs_PutCell(cellp, locktype) /* the unixuser flag bit definitions */ -#define UHasTokens 1 /* are the st and ct fields valid (ever set)? */ -#define UTokensBad 2 /* are tokens bad? */ -#define UPrimary 4 /* on iff primary identity */ -#define UNeedsReset 8 /* needs afs_ResetAccessCache call done */ -#define UPAGCounted 16 /* entry seen during PAG search (for stats) */ +#define UHasTokens 1 /* are the st and ct fields valid (ever set)? */ +#define UTokensBad 2 /* are tokens bad? */ +#define UPrimary 4 /* on iff primary identity */ +#define UNeedsReset 8 /* needs afs_ResetAccessCache call done */ +#define UPAGCounted 16 /* entry seen during PAG search (for stats) */ /* A flag used by afs_GCPAGs to keep track of * which entries in afs_users need to be deleted. * The lifetime of its presence in the table is the @@ -236,47 +256,40 @@ struct cell_alias { #define TMP_UPAGNotReferenced 128 /* values for afs_gcpags */ -enum -{ AFS_GCPAGS_NOTCOMPILED = 0 -, AFS_GCPAGS_OK = 1 -, AFS_GCPAGS_USERDISABLED -, AFS_GCPAGS_EPROC0 -, AFS_GCPAGS_EPROCN -, AFS_GCPAGS_EEQPID -, AFS_GCPAGS_EINEXACT -, AFS_GCPAGS_EPROCEND -, AFS_GCPAGS_EPROCWALK -, AFS_GCPAGS_ECREDWALK -, AFS_GCPAGS_EPIDCHECK -, AFS_GCPAGS_ENICECHECK +enum { AFS_GCPAGS_NOTCOMPILED = 0, AFS_GCPAGS_OK = + 1, AFS_GCPAGS_USERDISABLED, AFS_GCPAGS_EPROC0, AFS_GCPAGS_EPROCN, + AFS_GCPAGS_EEQPID, AFS_GCPAGS_EINEXACT, AFS_GCPAGS_EPROCEND, + AFS_GCPAGS_EPROCWALK, AFS_GCPAGS_ECREDWALK, AFS_GCPAGS_EPIDCHECK, + AFS_GCPAGS_ENICECHECK }; extern afs_int32 afs_gcpags; extern afs_int32 afs_gcpags_procsize; +extern afs_int32 afs_bkvolpref; struct unixuser { - struct unixuser *next; /* next hash pointer */ - afs_int32 uid; /* search based on uid and cell */ + struct unixuser *next; /* next hash pointer */ + afs_int32 uid; /* search based on uid and cell */ afs_int32 cell; - afs_int32 vid; /* corresponding vice id in specified cell */ - short refCount; /* reference count for allocation */ - char states; /* flag info */ - afs_int32 tokenTime; /* last time tokens were set, used for timing out conn data */ - afs_int32 stLen; /* ticket length (if kerberos, includes kvno at head) */ - char *stp; /* pointer to ticket itself */ + afs_int32 vid; /* corresponding vice id in specified cell */ + short refCount; /* reference count for allocation */ + char states; /* flag info */ + afs_int32 tokenTime; /* last time tokens were set, used for timing out conn data */ + afs_int32 stLen; /* ticket length (if kerberos, includes kvno at head) */ + char *stp; /* pointer to ticket itself */ struct ClearToken ct; - struct afs_exporter *exporter; /* more info about the exporter for the remote user */ + struct afs_exporter *exporter; /* more info about the exporter for the remote user */ }; struct conn { /* Per-connection block. */ - struct conn *next; /* Next dude same server. */ - struct unixuser *user; /* user validated with respect to. */ - struct rx_connection *id; /* RPC connid. */ - struct srvAddr *srvr; /* server associated with this conn */ - short refCount; /* reference count for allocation */ - unsigned short port; /* port associated with this connection */ - char forceConnectFS; /* Should we try again with these tokens? */ + struct conn *next; /* Next dude same server. */ + struct unixuser *user; /* user validated with respect to. */ + struct rx_connection *id; /* RPC connid. */ + struct srvAddr *srvr; /* server associated with this conn */ + short refCount; /* reference count for allocation */ + unsigned short port; /* port associated with this connection */ + char forceConnectFS; /* Should we try again with these tokens? */ }; @@ -319,13 +332,13 @@ struct conn { #define SRVADDR_MH 1 #define SRVADDR_ISDOWN 0x20 /* same as SRVR_ISDOWN */ -#define SRVADDR_NOUSE 0x40 /* Don't use this srvAddr */ +#define SRVADDR_NOUSE 0x40 /* Don't use this srvAddr */ struct srvAddr { - struct srvAddr *next_bkt; /* next item in hash bucket */ - struct srvAddr *next_sa; /* another interface on same host */ + struct srvAddr *next_bkt; /* next item in hash bucket */ + struct srvAddr *next_sa; /* another interface on same host */ struct server *server; /* back to parent */ - struct conn *conns; /* All user connections to this server */ - afs_int32 sa_ip; /* Host addr in network byte order */ + struct conn *conns; /* All user connections to this server */ + afs_int32 sa_ip; /* Host addr in network byte order */ u_short sa_iprank; /* indiv ip address priority */ u_short sa_portal; /* port addr in network byte order */ u_char sa_flags; @@ -344,6 +357,11 @@ struct srvAddr { #define SRVR_ISDOWN 0x20 #define SRVR_MULTIHOMED 0x40 #define SRVR_ISGONE 0x80 +#define SNO_INLINEBULK 0x100 +#define SNO_64BIT 0x200 + +#define afs_serverSetNo64Bit(s) ((s)->srvr->server->flags |= SNO_64BIT) +#define afs_serverHasNo64Bit(s) ((s)->srvr->server->flags & SNO_64BIT) struct server { union { @@ -352,9 +370,9 @@ struct server { afs_int32 addr_uniquifier; afs_int32 spares[2]; } _srvUuid; - struct { + struct { struct srvAddr haddr; - } _srvId; + } _srvId; } _suid; #define sr_uuid _suid._srvUuid.suuid #define sr_addr_uniquifier _suid._srvUuid.addr_uniquifier @@ -364,112 +382,109 @@ struct server { #define sr_flags _suid._srvId.haddr.flags #define sr_conns _suid._srvId.haddr.conns struct server *next; /* Ptr to next server in hash chain */ - struct cell *cell; /* Cell in which this host resides */ + struct cell *cell; /* Cell in which this host resides */ struct afs_cbr *cbrs; /* Return list of callbacks */ afs_int32 activationTime; /* Time when this record was first activated */ afs_int32 lastDowntimeStart; /* Time when last downtime incident began */ afs_int32 numDowntimeIncidents; /* # (completed) downtime incidents */ afs_int32 sumOfDowntimes; /* Total downtime experienced, in seconds */ struct srvAddr *addr; - char flags; /* Misc flags*/ + afs_uint32 flags; /* Misc flags */ }; -#define afs_PutServer(servp, locktype) +#define afs_PutServer(servp, locktype) /* structs for some pioctls - these are (or should be) * also in venus.h */ struct spref { - struct in_addr host; - unsigned short rank; + struct in_addr host; + unsigned short rank; }; struct sprefrequest_33 { - unsigned short offset; - unsigned short num_servers; + unsigned short offset; + unsigned short num_servers; }; -struct sprefrequest { /* new struct for 3.4 */ - unsigned short offset; - unsigned short num_servers; - unsigned short flags; +struct sprefrequest { /* new struct for 3.4 */ + unsigned short offset; + unsigned short num_servers; + unsigned short flags; }; #define DBservers 1 struct sprefinfo { - unsigned short next_offset; - unsigned short num_servers; - struct spref servers[1]; /* we overrun this array intentionally...*/ + unsigned short next_offset; + unsigned short num_servers; + struct spref servers[1]; /* we overrun this array intentionally... */ }; struct setspref { - unsigned short flags; - unsigned short num_servers; - struct spref servers[1]; /* we overrun this array intentionally...*/ + unsigned short flags; + unsigned short num_servers; + struct spref servers[1]; /* we overrun this array intentionally... */ }; /* struct for GAG pioctl */ struct gaginfo { - afs_uint32 showflags, logflags, logwritethruflag, spare[3]; - unsigned char spare2[128]; + afs_uint32 showflags, logflags, logwritethruflag, spare[3]; + unsigned char spare2[128]; }; #define GAGUSER 1 #define GAGCONSOLE 2 #define logwritethruON 1 struct rxparams { - afs_int32 rx_initReceiveWindow, rx_maxReceiveWindow, - rx_initSendWindow, rx_maxSendWindow, rxi_nSendFrags, - rxi_nRecvFrags, rxi_OrphanFragSize; - afs_int32 rx_maxReceiveSize, rx_MyMaxSendSize; - afs_uint32 spare[21]; - }; + afs_int32 rx_initReceiveWindow, rx_maxReceiveWindow, rx_initSendWindow, + rx_maxSendWindow, rxi_nSendFrags, rxi_nRecvFrags, rxi_OrphanFragSize; + afs_int32 rx_maxReceiveSize, rx_MyMaxSendSize; + afs_uint32 spare[21]; +}; /* struct for checkservers */ -struct chservinfo -{ - int magic; - char tbuffer[128]; - int tsize; - afs_int32 tinterval; - afs_int32 tflags; -} -; +struct chservinfo { + int magic; + char tbuffer[128]; + int tsize; + afs_int32 tinterval; + afs_int32 tflags; +}; /* state bits for volume */ -#define VRO 1 /* volume is readonly */ -#define VRecheck 2 /* recheck volume info with server */ -#define VBackup 4 /* is this a backup volume? */ -#define VForeign 8 /* this is a non-afs volume */ -#define VResort 16 /* server order was rearranged, sort when able */ -#define VMoreReps 32 /* This volume has more replicas than we are */ - /* keeping track of now -- check with VLDB */ +#define VRO 1 /* volume is readonly */ +#define VRecheck 2 /* recheck volume info with server */ +#define VBackup 4 /* is this a backup volume? */ +#define VForeign 8 /* this is a non-afs volume */ +#define VResort 16 /* server order was rearranged, sort when able */ +#define VMoreReps 32 /* This volume has more replicas than we are */ + /* keeping track of now -- check with VLDB */ - enum repstate { not_busy, end_not_busy = 6, rd_busy, rdwr_busy, offline }; +enum repstate { not_busy, end_not_busy = 6, rd_busy, rdwr_busy, offline }; struct volume { /* One structure per volume, describing where the volume is located - and where its mount points are. */ + * and where its mount points are. */ struct volume *next; /* Next volume in hash list. */ - afs_int32 cell; /* the cell in which the volume resides */ + afs_int32 cell; /* the cell in which the volume resides */ afs_rwlock_t lock; /* the lock for this structure */ afs_int32 volume; /* This volume's ID number. */ char *name; /* This volume's name, or 0 if unknown */ - struct server *serverHost[MAXHOSTS]; /* servers serving this volume */ - enum repstate status[MAXHOSTS]; /* busy, offline, etc */ + struct server *serverHost[MAXHOSTS]; /* servers serving this volume */ + enum repstate status[MAXHOSTS]; /* busy, offline, etc */ struct VenusFid dotdot; /* dir to access as .. */ struct VenusFid mtpoint; /* The mount point for this volume. */ afs_int32 rootVnode, rootUnique; /* Volume's root fid */ afs_int32 roVol; afs_int32 backVol; - afs_int32 rwVol; /* For r/o vols, original read/write volume. */ - afs_int32 accessTime; /* last time we used it */ - afs_int32 vtix; /* volume table index */ + afs_int32 rwVol; /* For r/o vols, original read/write volume. */ + afs_int32 accessTime; /* last time we used it */ + afs_int32 vtix; /* volume table index */ afs_int32 copyDate; /* copyDate field, for tracking vol releases */ - afs_int32 expireTime; /* for per-volume callbacks... */ + afs_int32 expireTime; /* for per-volume callbacks... */ short refCount; /* reference count for allocation */ char states; /* here for alignment reasons */ }; @@ -478,9 +493,9 @@ struct volume { /* format of an entry in volume info file */ struct fvolume { - afs_int32 cell; /* cell for this entry */ + afs_int32 cell; /* cell for this entry */ afs_int32 volume; /* volume */ - afs_int32 next; /* has index */ + afs_int32 next; /* has index */ struct VenusFid dotdot; /* .. value */ struct VenusFid mtpoint; /* mt point's fid */ afs_int32 rootVnode, rootUnique; /* Volume's root fid */ @@ -519,7 +534,6 @@ struct SimpleLocks { #endif #define CUnique 0x00001000 /* vc's uniquifier - latest unifiquier for fid */ #define CForeign 0x00002000 /* this is a non-afs vcache */ -#define CHasPages 0x00004000 #define CUnlinked 0x00010000 #define CBulkStat 0x00020000 /* loaded by a bulk stat, and not ref'd since */ #define CUnlinkedDel 0x00040000 @@ -537,13 +551,13 @@ struct SimpleLocks { #define VPageCleaning 0x2 /* Solaris - Cache Trunc Daemon sez keep out */ #define CPSIZE 2 -#if !defined(AFS_FBSD_ENV) -#define vrefCount v.v_count +#if defined(AFS_XBSD_ENV) +#define vrefCount v->v_usecount #else -#define vrefCount v.v_usecount -#endif /* AFS_FBSD_ENV */ +#define vrefCount v.v_count +#endif /* AFS_XBSD_ENV */ -#ifdef AFS_LINUX24_ENV +#if defined(AFS_LINUX24_ENV) #define VREFCOUNT(v) atomic_read(&((vnode_t *) v)->v_count) #define VREFCOUNT_SET(v, c) atomic_set(&((vnode_t *) v)->v_count, c) #define VREFCOUNT_DEC(v) atomic_dec(&((vnode_t *) v)->v_count) @@ -563,28 +577,37 @@ struct SimpleLocks { #define DCOUNT(d) ((d)->d_count) #endif -#define AFS_MAXDV 0x7fffffff /* largest dataversion number */ -#define AFS_NOTRUNC 0x7fffffff /* largest dataversion number */ +#define AFS_MAXDV 0x7fffffff /* largest dataversion number */ +#ifdef AFS_64BIT_CLIENT +#define AFS_NOTRUNC 0x7fffffffffffffffLL /* largest positive int64 number */ +#else /* AFS_64BIT_CLIENT */ +#define AFS_NOTRUNC 0x7fffffff /* largest dataversion number */ +#endif /* AFS_64BIT_CLIENT */ -extern afs_int32 vmPageHog; /* counter for # of vnodes which are page hogs. */ +extern afs_int32 vmPageHog; /* counter for # of vnodes which are page hogs. */ /* * Fast map from vcache to dcache */ -struct vtodc - { - struct dcache * dc; - afs_uint32 stamp; - struct osi_file * f; - afs_uint32 minLoc; /* smallest offset into dc. */ - afs_uint32 len; /* largest offset into dc. */ - }; - -extern afs_uint32 afs_stampValue; /* stamp for pair's usage */ +struct vtodc { + struct dcache *dc; + afs_uint32 stamp; + struct osi_file *f; + afs_offs_t minLoc; /* smallest offset into dc. */ + afs_offs_t len; /* largest offset into dc. */ +}; + +extern afs_uint32 afs_stampValue; /* stamp for pair's usage */ #define MakeStamp() (++afs_stampValue) -#define VTOAFS(V) ((struct vcache*)(V)) +#if defined(AFS_XBSD_ENV) +#define VTOAFS(v) ((struct vcache *)(v)->v_data) +#define AFSTOV(vc) ((vc)->v) +#else +#define VTOAFS(V) ((struct vcache *)(V)) #define AFSTOV(V) (&(V)->v) +#endif + #ifdef AFS_LINUX22_ENV #define ITOAFS(V) ((struct vcache*)(V)) #define AFSTOI(V) (struct inode *)(&(V)->v) @@ -595,27 +618,31 @@ extern afs_uint32 afs_stampValue; /* stamp for pair's usage */ * !(avc->nextfree) && !avc->vlruq.next => (FreeVCList == avc->nextfree) */ struct vcache { - struct vnode v; /* Has reference count in v.v_count */ - struct afs_q vlruq; /* lru q next and prev */ - struct vcache *nextfree; /* next on free list (if free) */ - struct vcache *hnext; /* Hash next */ +#if defined(AFS_XBSD_ENV) + struct vnode *v; +#else + struct vnode v; /* Has reference count in v.v_count */ +#endif + struct afs_q vlruq; /* lru q next and prev */ + struct vcache *nextfree; /* next on free list (if free) */ + struct vcache *hnext; /* Hash next */ struct VenusFid fid; struct mstat { - afs_uint32 Length; - afs_hyper_t DataVersion; - afs_uint32 Date; - afs_uint32 Owner; + afs_size_t Length; + afs_hyper_t DataVersion; + afs_uint32 Date; + afs_uint32 Owner; afs_uint32 Group; - ushort Mode; /* XXXX Should be afs_int32 XXXX */ - ushort LinkCount; + ushort Mode; /* XXXX Should be afs_int32 XXXX */ + ushort LinkCount; /* vnode type is in v.v_type */ } m; - afs_rwlock_t lock; /* The lock on the vcache contents. */ + afs_rwlock_t lock; /* The lock on the vcache contents. */ #if defined(AFS_SUN5_ENV) /* Lock used to protect the activeV, multipage, and vstates fields. * Do not try to get the vcache lock when the vlock is held */ afs_rwlock_t vlock; -#endif /* defined(AFS_SUN5_ENV) */ +#endif /* defined(AFS_SUN5_ENV) */ #if defined(AFS_SUN5_ENV) krwlock_t rwlock; struct cred *credp; @@ -626,73 +653,77 @@ struct vcache { #ifdef AFS_AIX32_ENV afs_lock_t pvmlock; vmhandle_t vmh; - int segid; +#if defined(AFS_AIX51_ENV) + vmid_t segid; +#else + int segid; +#endif struct ucred *credp; #endif #ifdef AFS_AIX_ENV - int ownslock; /* pid of owner of excl lock, else 0 - defect 3083 */ + int ownslock; /* pid of owner of excl lock, else 0 - defect 3083 */ #endif #ifdef AFS_DARWIN_ENV - struct lock__bsd__ rwlock; + struct lock__bsd__ rwlock; #endif -#ifdef AFS_FBSD_ENV - struct lock rwlock; +#ifdef AFS_XBSD_ENV + struct lock rwlock; #endif - afs_int32 parentVnode; /* Parent dir, if a file. */ + afs_int32 parentVnode; /* Parent dir, if a file. */ afs_int32 parentUnique; - struct VenusFid *mvid; /* Either parent dir (if root) or root (if mt pt) */ - char *linkData; /* Link data if a symlink. */ - afs_hyper_t flushDV; /* data version last flushed from text */ - afs_hyper_t mapDV; /* data version last flushed from map */ - afs_uint32 truncPos; /* truncate file to this position at next store */ - struct server *callback; /* The callback host, if any */ - afs_uint32 cbExpires; /* time the callback expires */ - struct afs_q callsort; /* queue in expiry order, sort of */ - struct axscache *Access; /* a list of cached access bits */ - afs_int32 anyAccess; /* System:AnyUser's access to this. */ - afs_int32 last_looker; /* pag/uid from last lookup here */ + struct VenusFid *mvid; /* Either parent dir (if root) or root (if mt pt) */ + char *linkData; /* Link data if a symlink. */ + afs_hyper_t flushDV; /* data version last flushed from text */ + afs_hyper_t mapDV; /* data version last flushed from map */ + afs_size_t truncPos; /* truncate file to this position at next store */ + struct server *callback; /* The callback host, if any */ + afs_uint32 cbExpires; /* time the callback expires */ + struct afs_q callsort; /* queue in expiry order, sort of */ + struct axscache *Access; /* a list of cached access bits */ + afs_int32 anyAccess; /* System:AnyUser's access to this. */ + afs_int32 last_looker; /* pag/uid from last lookup here */ #if defined(AFS_SUN5_ENV) afs_int32 activeV; -#endif /* defined(AFS_SUN5_ENV) */ +#endif /* defined(AFS_SUN5_ENV) */ struct SimpleLocks *slocks; - short opens; /* The numbers of opens, read or write, on this file. */ - short execsOrWriters; /* The number of execs (if < 0) or writers (if > 0) of - this file. */ - short flockCount; /* count of flock readers, or -1 if writer */ - char mvstat; /* 0->normal, 1->mt pt, 2->root. */ - afs_uint32 states; /* state bits */ + short opens; /* The numbers of opens, read or write, on this file. */ + short execsOrWriters; /* The number of execs (if < 0) or writers (if > 0) of + * this file. */ + short flockCount; /* count of flock readers, or -1 if writer */ + char mvstat; /* 0->normal, 1->mt pt, 2->root. */ + afs_uint32 states; /* state bits */ #if defined(AFS_SUN5_ENV) - afs_uint32 vstates; /* vstate bits */ -#endif /* defined(AFS_SUN5_ENV) */ + afs_uint32 vstates; /* vstate bits */ +#endif /* defined(AFS_SUN5_ENV) */ struct vtodc quick; afs_uint32 symhintstamp; union { - struct vcache *symhint; - struct dcache *dchint; + struct vcache *symhint; + struct dcache *dchint; } h1; #ifdef AFS_LINUX22_ENV - u_short flushcnt; /* Number of flushes which haven't released yet. */ - u_short mapcnt; /* Number of mappings of this file. */ + u_short flushcnt; /* Number of flushes which haven't released yet. */ + u_short mapcnt; /* Number of mappings of this file. */ #endif #if defined(AFS_SGI_ENV) - daddr_t lastr; /* for read-ahead */ + daddr_t lastr; /* for read-ahead */ #ifdef AFS_SGI64_ENV - uint64_t vc_rwlockid; /* kthread owning rwlock */ + uint64_t vc_rwlockid; /* kthread owning rwlock */ #else - short vc_rwlockid; /* pid of process owning rwlock */ + short vc_rwlockid; /* pid of process owning rwlock */ #endif - short vc_locktrips; /* # of rwlock reacquisitions */ - sema_t vc_rwlock; /* vop_rwlock for afs */ - pgno_t mapcnt; /* # of pages mapped */ - struct cred *cred; /* last writer's cred */ + short vc_locktrips; /* # of rwlock reacquisitions */ + sema_t vc_rwlock; /* vop_rwlock for afs */ + pgno_t mapcnt; /* # of pages mapped */ + struct cred *cred; /* last writer's cred */ #ifdef AFS_SGI64_ENV struct bhv_desc vc_bhv_desc; /* vnode's behavior data. */ #endif -#endif /* AFS_SGI_ENV */ - afs_int32 vc_error; /* stash write error for this vnode. */ - int xlatordv; /* Used by nfs xlator */ +#endif /* AFS_SGI_ENV */ + afs_int32 vc_error; /* stash write error for this vnode. */ + int xlatordv; /* Used by nfs xlator */ struct AFS_UCRED *uncred; - int asynchrony; /* num kbytes to store behind */ + int asynchrony; /* num kbytes to store behind */ #ifdef AFS_SUN5_ENV short multiPage; /* count of multi-page getpages in progress */ #endif @@ -703,7 +734,7 @@ struct vcache { #define DONT_CHECK_MODE_BITS 0 #define CHECK_MODE_BITS 1 -#define CMB_ALLOW_EXEC_AS_READ 2 /* For the NFS xlator */ +#define CMB_ALLOW_EXEC_AS_READ 2 /* For the NFS xlator */ #if defined(AFS_SGI_ENV) #define AVCRWLOCK(avc) (valusema(&(avc)->vc_rwlock) <= 0) @@ -719,7 +750,7 @@ struct vcache { #ifdef AFS_SGI53_ENV #ifdef AFS_SGI62_ENV #define AFS_RWLOCK_T vrwlock_t -#else +#else #define AFS_RWLOCK_T int #endif /* AFS_SGI62_ENV */ #ifdef AFS_SGI64_ENV @@ -743,7 +774,7 @@ struct vcxstat { struct VenusFid fid; afs_hyper_t DataVersion; afs_rwlock_t lock; - afs_int32 parentVnode; + afs_int32 parentVnode; afs_int32 parentUnique; afs_hyper_t flushDV; afs_hyper_t mapDV; @@ -761,14 +792,14 @@ struct vcxstat { }; struct sbstruct { - int sb_thisfile; - int sb_default; + int sb_thisfile; + int sb_default; }; /* CM inititialization parameters. What CM actually used after calculations * based on passed in arguments. */ -#define CMI_VERSION 1 /* increment when adding new fields. */ +#define CMI_VERSION 1 /* increment when adding new fields. */ struct cm_initparams { int cmi_version; int cmi_nChunkFiles; @@ -777,10 +808,10 @@ struct cm_initparams { int cmi_nVolumeCaches; int cmi_firstChunkSize; int cmi_otherChunkSize; - int cmi_cacheSize; /* The original cache size, in 1K blocks. */ + int cmi_cacheSize; /* The original cache size, in 1K blocks. */ unsigned cmi_setTime:1; unsigned cmi_memCache:1; - int spare[16-9]; /* size of struct is 16 * 4 = 64 bytes */ + int spare[16 - 9]; /* size of struct is 16 * 4 = 64 bytes */ }; @@ -806,28 +837,29 @@ struct cm_initparams { /* struct dcache states bits */ #define DWriting 8 /* file being written (used for cache validation) */ -/* dcache flags */ -#define DFNextStarted 1 /* next chunk has been prefetched already */ -#define DFEntryMod 2 /* has entry itself been modified? */ -#define DFFetching 4 /* file is currently being fetched */ -#define DFWaiting 8 /* someone waiting for file */ +/* dcache data flags */ +#define DFEntryMod 0x02 /* has entry itself been modified? */ +#define DFFetching 0x04 /* file is currently being fetched */ + +/* dcache meta flags */ +#define DFNextStarted 0x01 /* next chunk has been prefetched already */ #define DFFetchReq 0x10 /* someone is waiting for DFFetching to go on */ /* flags in afs_indexFlags array */ -#define IFEverUsed 1 /* index entry has >= 1 byte of data */ -#define IFFree 2 /* index entry in freeDCList */ -#define IFDataMod 4 /* file needs to be written out */ -#define IFFlag 8 /* utility flag */ +#define IFEverUsed 1 /* index entry has >= 1 byte of data */ +#define IFFree 2 /* index entry in freeDCList */ +#define IFDataMod 4 /* file needs to be written out */ +#define IFFlag 8 /* utility flag */ #define IFDirtyPages 16 #define IFAnyPages 32 -#define IFDiscarded 64 /* index entry in discardDCList */ +#define IFDiscarded 64 /* index entry in discardDCList */ struct afs_ioctl { - char *in; /* input buffer */ - char *out; /* output buffer */ - short in_size; /* Size of input buffer <= 2K */ - short out_size; /* Maximum size of output buffer, <= 2K */ + char *in; /* input buffer */ + char *out; /* output buffer */ + short in_size; /* Size of input buffer <= 2K */ + short out_size; /* Maximum size of output buffer, <= 2K */ }; /* @@ -850,7 +882,7 @@ struct afs_ioctl32 { * instead of using it. */ struct afs_fheader { -#define AFS_FHMAGIC 0x7635abaf /* uses version number */ +#define AFS_FHMAGIC 0x7635abaf /* uses version number */ afs_int32 magic; #if defined(AFS_SUN57_64BIT_ENV) #define AFS_CI_VERSION 3 @@ -862,25 +894,31 @@ struct afs_fheader { afs_int32 otherCSize; }; -/* kept on disk and in dcache entries */ -struct fcache { - struct VenusFid fid; /* Fid for this file */ - afs_int32 modTime; /* last time this entry was modified */ - afs_hyper_t versionNo; /* Associated data version number */ - afs_int32 chunk; /* Relative chunk number */ #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_64BIT_ENV) - /* Using ino64_t here so that user level debugging programs compile - * the size correctly. - */ - ino64_t inode; /* Unix inode for this chunk */ +/* Using ino64_t here so that user level debugging programs compile + * the size correctly. + */ +#define afs_inode_t ino64_t #else #if defined(AFS_LINUX_64BIT_KERNEL) - long inode; /* Unix inode for this chunk */ +#define afs_inode_t long #else - afs_int32 inode; /* Unix inode for this chunk */ +#if defined(AFS_AIX51_ENV) || defined(AFS_HPUX1123_ENV) +#define afs_inode_t ino_t +#else +#define afs_inode_t afs_int32 +#endif #endif #endif - afs_int32 chunkBytes; /* Num bytes in this chunk */ + +/* kept on disk and in dcache entries */ +struct fcache { + struct VenusFid fid; /* Fid for this file */ + afs_int32 modTime; /* last time this entry was modified */ + afs_hyper_t versionNo; /* Associated data version number */ + afs_int32 chunk; /* Relative chunk number */ + afs_inode_t inode; /* Unix inode for this chunk */ + afs_int32 chunkBytes; /* Num bytes in this chunk */ char states; /* Has this chunk been modified? */ }; @@ -894,31 +932,60 @@ struct fcache { /* kept in memory */ struct dcache { struct afs_q lruq; /* Free queue for in-memory images */ - afs_rwlock_t lock; /* XXX */ + struct afs_q dirty; /* Queue of dirty entries that need written */ + afs_rwlock_t lock; /* Protects validPos, some f */ + afs_rwlock_t tlock; /* Atomizes updates to refCount */ + afs_rwlock_t mflock; /* Atomizes accesses/updates to mflags */ + afs_size_t validPos; /* number of valid bytes during fetch */ + afs_int32 index; /* The index in the CacheInfo file */ short refCount; /* Associated reference count. */ - afs_int32 index; /* The index in the CacheInfo file*/ - short flags; /* more flags bits */ - afs_int32 validPos; /* number of valid bytes during fetch */ + char dflags; /* Data flags */ + char mflags; /* Meta flags */ struct fcache f; /* disk image */ - afs_int32 stamp; /* used with vtodc struct for hints */ + afs_int32 stamp; /* used with vtodc struct for hints */ + + /* + * Locking rules: + * + * dcache.lock protects the actual contents of the cache file (in + * f.inode), subfields of f except those noted below, dflags and + * validPos. + * + * dcache.tlock is used to make atomic updates to refCount. Zero + * refCount dcache entries are protected by afs_xdcache instead of + * tlock. + * + * dcache.mflock is used to access and update mflags. It cannot be + * held without holding the corresponding dcache.lock. Updating + * mflags requires holding dcache.lock(R) and dcache.mflock(W), and + * checking for mflags requires dcache.lock(R) and dcache.mflock(R). + * Note that dcache.lock(W) gives you the right to update mflags, + * as dcache.mflock(W) can only be held with dcache.lock(R). + * + * dcache.stamp is protected by the associated vcache lock, because + * it's only purpose is to establish correspondence between vcache + * and dcache entries. + * + * dcache.index, dcache.f.fid, dcache.f.chunk and dcache.f.inode are + * write-protected by afs_xdcache and read-protected by refCount. + * Once an entry is referenced, these values cannot change, and if + * it's on the free list (with refCount=0), it can be reused for a + * different file/chunk. These values can only be written while + * holding afs_xdcache(W) and allocating this dcache entry (thereby + * ensuring noone else has a refCount on it). + */ }; /* this is obsolete and should be removed */ -#define ihint stamp +#define ihint stamp /* macro to mark a dcache entry as bad */ #define ZapDCE(x) \ do { \ (x)->f.fid.Fid.Unique = 0; \ afs_indexUnique[(x)->index] = 0; \ - (x)->flags |= DFEntryMod; \ + (x)->dflags |= DFEntryMod; \ } while(0) -/* - * Convenient release macro for use when afs_PutDCache would cause - * deadlock on afs_xdcache lock - */ -#define lockedPutDCache(ad) ((ad)->refCount--) - /* FakeOpen and Fake Close used to be real subroutines. They're only used in * sun_subr and afs_vnodeops, and they're very frequently called, so I made * them into macros. They do: @@ -951,9 +1018,9 @@ struct dcache { avc->opens--; \ avc->execsOrWriters--; \ } \ -} +} -#define AFS_ZEROS 64 /* zero buffer */ +#define AFS_ZEROS 64 /* zero buffer */ /*#define afs_DirtyPages(avc) (((avc)->states & CDirty) || osi_VMDirty_p((avc)))*/ #define afs_DirtyPages(avc) ((avc)->states & CDirty) @@ -964,87 +1031,37 @@ struct dcache { */ /* extern int afs_dhashsize; */ #define DCHash(v, c) ((((v)->Fid.Vnode + (v)->Fid.Volume + (c))) & (afs_dhashsize-1)) - /*Vnode, Chunk -> Hash table index*/ + /*Vnode, Chunk -> Hash table index */ #define DVHash(v) ((((v)->Fid.Vnode + (v)->Fid.Volume )) & (afs_dhashsize-1)) - /*Vnode -> Other hash table index*/ + /*Vnode -> Other hash table index */ /* don't hash on the cell, our callback-breaking code sometimes fails to compute the cell correctly, and only scans one hash bucket */ #define VCHash(fid) (((fid)->Fid.Volume + (fid)->Fid.Vnode) & (VCSIZE-1)) -extern struct dcache **afs_indexTable; /*Pointers to in-memory dcache entries*/ -extern afs_int32 *afs_indexUnique; /*dcache entry Fid.Unique */ -extern afs_int32 *afs_dvnextTbl; /*Dcache hash table links */ -extern afs_int32 *afs_dcnextTbl; /*Dcache hash table links */ -extern afs_int32 afs_cacheFiles; /*Size of afs_indexTable*/ -extern afs_int32 afs_cacheBlocks; /*1K blocks in cache*/ -extern afs_int32 afs_cacheStats; /*Stat entries in cache*/ -extern struct vcache *afs_vhashT[VCSIZE]; /*Stat cache hash table*/ -extern afs_int32 afs_initState; /*Initialization state*/ -extern afs_int32 afs_termState; /* Termination state */ -extern struct VenusFid afs_rootFid; /*Root for whole file system*/ -extern afs_int32 afs_allCBs; /* Count of callbacks*/ -extern afs_int32 afs_oddCBs; /* Count of odd callbacks*/ -extern afs_int32 afs_evenCBs; /* Count of even callbacks*/ -extern afs_int32 afs_allZaps; /* Count of fid deletes */ -extern afs_int32 afs_oddZaps; /* Count of odd fid deletes */ -extern afs_int32 afs_evenZaps; /* Count of even fid deletes */ -extern struct brequest afs_brs[NBRS]; /* request structures */ +extern struct dcache **afs_indexTable; /*Pointers to in-memory dcache entries */ +extern afs_int32 *afs_indexUnique; /*dcache entry Fid.Unique */ +extern afs_int32 *afs_dvnextTbl; /*Dcache hash table links */ +extern afs_int32 *afs_dcnextTbl; /*Dcache hash table links */ +extern afs_int32 afs_cacheFiles; /*Size of afs_indexTable */ +extern afs_int32 afs_cacheBlocks; /*1K blocks in cache */ +extern afs_int32 afs_cacheStats; /*Stat entries in cache */ +extern struct vcache *afs_vhashT[VCSIZE]; /*Stat cache hash table */ +extern afs_int32 afs_initState; /*Initialization state */ +extern afs_int32 afs_termState; /* Termination state */ +extern struct VenusFid afs_rootFid; /*Root for whole file system */ +extern afs_int32 afs_allCBs; /* Count of callbacks */ +extern afs_int32 afs_oddCBs; /* Count of odd callbacks */ +extern afs_int32 afs_evenCBs; /* Count of even callbacks */ +extern afs_int32 afs_allZaps; /* Count of fid deletes */ +extern afs_int32 afs_oddZaps; /* Count of odd fid deletes */ +extern afs_int32 afs_evenZaps; /* Count of even fid deletes */ +extern struct brequest afs_brs[NBRS]; /* request structures */ #define UHash(auid) ((auid) & (NUSERS-1)) #define VHash(avol) ((avol)&(NVOLS-1)) #define SHash(aserv) ((ntohl(aserv)) & (NSERVERS-1)) #define FVHash(acell,avol) (((avol)+(acell)) & (NFENTRIES-1)) -extern struct cell *afs_GetCell(); -extern struct cell *afs_GetCellNoLock(); -extern struct cell *afs_GetCellByName(); -extern struct cell *afs_GetCellByName2(); -extern struct cell *afs_GetCellByIndex(); -extern struct unixuser *afs_GetUser(); -extern struct volume *afs_GetVolume(); -extern struct volume *afs_GetVolumeByName(); -extern struct conn *afs_Conn(); -extern struct conn *afs_ConnByHost(); -extern struct conn *afs_ConnByMHosts(); -extern struct dcache *afs_GetDCache(); -extern struct dcache *afs_FindDCache(); -extern struct dcache *afs_NewDCache(); -extern struct dcache *afs_GetDSlot(); -extern struct vcache *afs_GetVCache(); -extern struct brequest *afs_BQueue(); - -/* afs_cache.c */ -extern int afs_CacheInit(); -extern void afs_StoreWarn(); -extern void afs_AdjustSize(); -extern void afs_ComputeCacheParms(); -extern void afs_FlushDCache(); -extern void afs_FlushActiveVcaches(); -extern void afs_StuffVcache(); -extern void afs_PutVCache(); -extern void afs_TryToSmush(); -extern void afs_ProcessFS(); -extern void afs_WriteThroughDSlots(); -extern void shutdown_cache(); -/* afs_call.c */ -extern void afs_shutdown(); -/* afs_osifile.c */ -extern void shutdown_osifile(); - -/* afs_dynroot.c */ -extern int afs_IsDynrootFid(); -extern void afs_GetDynrootFid(); -extern int afs_IsDynroot(); -extern void afs_RefreshDynroot(); -extern void afs_GetDynroot(); -extern void afs_PutDynroot(); -extern int afs_DynrootNewVnode(); -extern int afs_SetDynrootEnable(); -extern int afs_GetDynrootEnable(); -extern int afs_DynrootVOPSymlink(); -extern int afs_DynrootVOPRemove(); - - /* Performance hack - we could replace VerifyVCache2 with the appropriate * GetVCache incantation, and could eliminate even this code from afs_UFSRead * by making intentionally invalidating quick.stamp in the various callbacks @@ -1064,7 +1081,7 @@ extern int afs_DynrootVOPRemove(); #endif #endif -#define DO_STATS 1 /* bits used by FindVCache */ +#define DO_STATS 1 /* bits used by FindVCache */ #define DO_VLRU 2 /* values for flag param of afs_CheckVolumeNames */ @@ -1088,11 +1105,6 @@ extern int afs_DynrootVOPRemove(); #define afs_nlrdwr(avc, uio, rw, io, cred) \ (((rw) == UIO_WRITE) ? afs_write(avc, uio, io, cred, 1) : afs_read(avc, uio, cred, 0, 0, 1)) -extern afs_int32 afs_blocksUsed, afs_blocksDiscarded; -extern afs_int32 afs_discardDCCount, afs_freeDCCount; -extern afs_int32 afs_bulkStatsDone, afs_bulkStatsLost; -extern int afs_TruncateDaemonRunning; -extern int afs_CacheTooFull; /* Cache size truncation uses the following low and high water marks: * If the cache is more than 95% full (CM_DCACHECOUNTFREEPCT), the cache * truncation daemon is awakened and will free up space until the cache is 85% @@ -1102,15 +1114,12 @@ extern int afs_CacheTooFull; * afs_GetDownD wakes those processes once the cache is 95% full * (CM_CACHESIZEDRAINEDPCT). */ -extern void afs_MaybeWakeupTruncateDaemon(); -extern void afs_CacheTruncateDaemon(); -extern int afs_WaitForCacheDrain; -#define CM_MAXDISCARDEDCHUNKS 16 /* # of chunks */ -#define CM_DCACHECOUNTFREEPCT 95 /* max pct of chunks in use */ -#define CM_DCACHESPACEFREEPCT 90 /* max pct of space in use */ -#define CM_DCACHEEXTRAPCT 5 /* extra to get when freeing */ -#define CM_CACHESIZEDRAINEDPCT 95 /* wakeup processes when down to here.*/ -#define CM_WAITFORDRAINPCT 98 /* sleep if cache is this full. */ +#define CM_MAXDISCARDEDCHUNKS 16 /* # of chunks */ +#define CM_DCACHECOUNTFREEPCT 95 /* max pct of chunks in use */ +#define CM_DCACHESPACEFREEPCT 90 /* max pct of space in use */ +#define CM_DCACHEEXTRAPCT 5 /* extra to get when freeing */ +#define CM_CACHESIZEDRAINEDPCT 95 /* wakeup processes when down to here. */ +#define CM_WAITFORDRAINPCT 98 /* sleep if cache is this full. */ #define afs_CacheIsTooFull() \ (afs_blocksUsed - afs_blocksDiscarded > \ @@ -1119,14 +1128,11 @@ extern int afs_WaitForCacheDrain; ((100-CM_DCACHECOUNTFREEPCT)*afs_cacheFiles)/100) /* Handy max length of a numeric string. */ -#define CVBS 12 /* max afs_int32 is 2^32 ~ 4*10^9, +1 for NULL, +luck */ +#define CVBS 12 /* max afs_int32 is 2^32 ~ 4*10^9, +1 for NULL, +luck */ -extern int afs_norefpanic; #define refpanic(foo) if (afs_norefpanic) \ { printf( foo ); afs_norefpanic++;} else osi_Panic( foo ) - - /* ** these are defined in the AIX source code sys/fs_locks.h but are not ** defined anywhere in the /usr/include directory @@ -1153,13 +1159,27 @@ extern int afs_norefpanic; #ifndef afs_vnodeToDev #if defined(AFS_SGI62_ENV) || defined(AFS_HAVE_VXFS) || defined(AFS_DARWIN_ENV) #define afs_vnodeToDev(V) VnodeToDev(V) -#else -#ifdef AFS_DECOSF_ENV +#elif defined(AFS_DECOSF_ENV) #define afs_vnodeToDev(V) osi_vnodeToDev(V) #else #define afs_vnodeToDev(V) (VTOI(V)->i_dev) -#endif /* AFS_DECOSF_ENV */ -#endif /* AFS_SGI62_ENV */ +#endif +#endif + + +/* Note: this should agree with the definition in kdump.c */ +#if defined(AFS_OSF_ENV) +#if !defined(UKERNEL) +#define AFS_USEBUFFERS 1 +#endif +#endif + +#if !defined(UKERNEL) && !defined(HAVE_STRUCT_BUF) +/* declare something so that prototypes don't flip out */ +/* appears struct buf stuff is only actually passed around as a pointer, + except with libuafs, in which case it is actually defined */ + +struct buf; #endif /* fakestat support: opaque storage for afs_EvalFakeStat to remember @@ -1174,5 +1194,32 @@ struct afs_fakestat_state { extern int afs_fakestat_enable; -#endif /* _AFS_H_ */ +struct buffer { + ino_t fid[1]; /* Unique cache key + i/o addressing */ + afs_int32 page; + afs_int32 accesstime; + struct buffer *hashNext; + char *data; + char lockers; + char dirty; + char hashIndex; +#if AFS_USEBUFFERS + struct buf *bufp; +#endif + afs_rwlock_t lock; /* the lock for this structure */ +}; + +/* afs_memcache.c */ +struct memCacheEntry { + int size; /* # of valid bytes in this entry */ + int dataSize; /* size of allocated data area */ + afs_lock_t afs_memLock; + char *data; /* bytes */ +}; + +/* First 32 bits of capabilities */ +#define CAPABILITY_ERRORTRANS (1<<0) + +#define CAPABILITY_BITS 1 +#endif /* _AFS_H_ */ diff --git a/src/afs/afs_analyze.c b/src/afs/afs_analyze.c index 106cdf964..1f0559004 100644 --- a/src/afs/afs_analyze.c +++ b/src/afs/afs_analyze.c @@ -11,12 +11,13 @@ * Implements: */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_analyze.c,v 1.1.1.11 2003/07/30 17:07:57 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_analyze.c,v 1.22 2003/08/27 21:43:16 rees Exp $"); -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ #ifndef UKERNEL #if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV) @@ -25,17 +26,17 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_analyze.c,v 1.1.1.11 2003/07/30 #endif #ifdef AFS_SGI62_ENV -#include "../h/hashing.h" +#include "h/hashing.h" #endif #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV) && !defined(AFS_DARWIN60_ENV) #include #endif #endif /* !UKERNEL */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ -#include "../afs/afs_util.h" -#include "../afs/afs_prototypes.h" +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#include "afs/afs_util.h" +#include "afs/unified_afs.h" #if defined(AFS_SUN56_ENV) #include @@ -52,6 +53,11 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_analyze.c,v 1.1.1.11 2003/07/30 #define ERROR_TABLE_BASE_U (5376L) #endif /* ubik error base define */ +/* shouldn't do it this way, but for now will do */ +#ifndef ERROR_TABLE_BASE_uae +#define ERROR_TABLE_BASE_uae (49733376L) +#endif /* unified afs error base define */ + /* same hack for vlserver error base as for ubik error base */ #ifndef ERROR_TABLE_BASE_VL #define ERROR_TABLE_BASE_VL (363520L) @@ -59,17 +65,155 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_analyze.c,v 1.1.1.11 2003/07/30 #endif /* vlserver error base define */ -int afs_BusyWaitPeriod = 15; /* poll every 15 seconds */ +int afs_BusyWaitPeriod = 15; /* poll every 15 seconds */ +afs_int32 hm_retry_RO = 0; /* don't wait */ +afs_int32 hm_retry_RW = 0; /* don't wait */ +afs_int32 hm_retry_int = 0; /* don't wait */ -afs_int32 hm_retry_RO=0; /* don't wait */ -afs_int32 hm_retry_RW=0; /* don't wait */ -afs_int32 hm_retry_int=0; /* don't wait */ - -void afs_CopyError(afrom, ato) - register struct vrequest *afrom; - register struct vrequest *ato; +static int et2sys[512]; +void +init_et_to_sys_error(void) +{ + memset(&et2sys, 0, sizeof(et2sys)); + et2sys[(UAEPERM - ERROR_TABLE_BASE_uae)] = EPERM; + et2sys[(UAENOENT - ERROR_TABLE_BASE_uae)] = ENOENT; + et2sys[(UAESRCH - ERROR_TABLE_BASE_uae)] = ESRCH; + et2sys[(UAEINTR - ERROR_TABLE_BASE_uae)] = EINTR; + et2sys[(UAEIO - ERROR_TABLE_BASE_uae)] = EIO; + et2sys[(UAENXIO - ERROR_TABLE_BASE_uae)] = ENXIO; + et2sys[(UAE2BIG - ERROR_TABLE_BASE_uae)] = E2BIG; + et2sys[(UAENOEXEC - ERROR_TABLE_BASE_uae)] = ENOEXEC; + et2sys[(UAEBADF - ERROR_TABLE_BASE_uae)] = EBADF; + et2sys[(UAECHILD - ERROR_TABLE_BASE_uae)] = ECHILD; + et2sys[(UAEAGAIN - ERROR_TABLE_BASE_uae)] = EAGAIN; + et2sys[(UAENOMEM - ERROR_TABLE_BASE_uae)] = ENOMEM; + et2sys[(UAEACCES - ERROR_TABLE_BASE_uae)] = EACCES; + et2sys[(UAEFAULT - ERROR_TABLE_BASE_uae)] = EFAULT; + et2sys[(UAENOTBLK - ERROR_TABLE_BASE_uae)] = ENOTBLK; + et2sys[(UAEBUSY - ERROR_TABLE_BASE_uae)] = EBUSY; + et2sys[(UAEEXIST - ERROR_TABLE_BASE_uae)] = EEXIST; + et2sys[(UAEXDEV - ERROR_TABLE_BASE_uae)] = EXDEV; + et2sys[(UAENODEV - ERROR_TABLE_BASE_uae)] = ENODEV; + et2sys[(UAENOTDIR - ERROR_TABLE_BASE_uae)] = ENOTDIR; + et2sys[(UAEISDIR - ERROR_TABLE_BASE_uae)] = EISDIR; + et2sys[(UAEINVAL - ERROR_TABLE_BASE_uae)] = EINVAL; + et2sys[(UAENFILE - ERROR_TABLE_BASE_uae)] = ENFILE; + et2sys[(UAEMFILE - ERROR_TABLE_BASE_uae)] = EMFILE; + et2sys[(UAENOTTY - ERROR_TABLE_BASE_uae)] = ENOTTY; + et2sys[(UAETXTBSY - ERROR_TABLE_BASE_uae)] = ETXTBSY; + et2sys[(UAEFBIG - ERROR_TABLE_BASE_uae)] = EFBIG; + et2sys[(UAENOSPC - ERROR_TABLE_BASE_uae)] = ENOSPC; + et2sys[(UAESPIPE - ERROR_TABLE_BASE_uae)] = ESPIPE; + et2sys[(UAEROFS - ERROR_TABLE_BASE_uae)] = EROFS; + et2sys[(UAEMLINK - ERROR_TABLE_BASE_uae)] = EMLINK; + et2sys[(UAEPIPE - ERROR_TABLE_BASE_uae)] = EPIPE; + et2sys[(UAEDOM - ERROR_TABLE_BASE_uae)] = EDOM; + et2sys[(UAERANGE - ERROR_TABLE_BASE_uae)] = ERANGE; + et2sys[(UAEDEADLK - ERROR_TABLE_BASE_uae)] = EDEADLK; + et2sys[(UAENAMETOOLONG - ERROR_TABLE_BASE_uae)] = ENAMETOOLONG; + et2sys[(UAENOLCK - ERROR_TABLE_BASE_uae)] = ENOLCK; + et2sys[(UAENOSYS - ERROR_TABLE_BASE_uae)] = ENOSYS; + et2sys[(UAENOTEMPTY - ERROR_TABLE_BASE_uae)] = ENOTEMPTY; + et2sys[(UAELOOP - ERROR_TABLE_BASE_uae)] = ELOOP; + et2sys[(UAEWOULDBLOCK - ERROR_TABLE_BASE_uae)] = EWOULDBLOCK; + et2sys[(UAENOMSG - ERROR_TABLE_BASE_uae)] = ENOMSG; + et2sys[(UAEIDRM - ERROR_TABLE_BASE_uae)] = EIDRM; + et2sys[(UAECHRNG - ERROR_TABLE_BASE_uae)] = ECHRNG; + et2sys[(UAEL2NSYNC - ERROR_TABLE_BASE_uae)] = EL2NSYNC; + et2sys[(UAEL3HLT - ERROR_TABLE_BASE_uae)] = EL3HLT; + et2sys[(UAEL3RST - ERROR_TABLE_BASE_uae)] = EL3RST; + et2sys[(UAELNRNG - ERROR_TABLE_BASE_uae)] = ELNRNG; + et2sys[(UAEUNATCH - ERROR_TABLE_BASE_uae)] = EUNATCH; + et2sys[(UAENOCSI - ERROR_TABLE_BASE_uae)] = ENOCSI; + et2sys[(UAEL2HLT - ERROR_TABLE_BASE_uae)] = EL2HLT; + et2sys[(UAEBADE - ERROR_TABLE_BASE_uae)] = EBADE; + et2sys[(UAEBADR - ERROR_TABLE_BASE_uae)] = EBADR; + et2sys[(UAEXFULL - ERROR_TABLE_BASE_uae)] = EXFULL; + et2sys[(UAENOANO - ERROR_TABLE_BASE_uae)] = ENOANO; + et2sys[(UAEBADRQC - ERROR_TABLE_BASE_uae)] = EBADRQC; + et2sys[(UAEBADSLT - ERROR_TABLE_BASE_uae)] = EBADSLT; + et2sys[(UAEBFONT - ERROR_TABLE_BASE_uae)] = EBFONT; + et2sys[(UAENOSTR - ERROR_TABLE_BASE_uae)] = ENOSTR; + et2sys[(UAENODATA - ERROR_TABLE_BASE_uae)] = ENODATA; + et2sys[(UAETIME - ERROR_TABLE_BASE_uae)] = ETIME; + et2sys[(UAENOSR - ERROR_TABLE_BASE_uae)] = ENOSR; + et2sys[(UAENONET - ERROR_TABLE_BASE_uae)] = ENONET; + et2sys[(UAENOPKG - ERROR_TABLE_BASE_uae)] = ENOPKG; + et2sys[(UAEREMOTE - ERROR_TABLE_BASE_uae)] = EREMOTE; + et2sys[(UAENOLINK - ERROR_TABLE_BASE_uae)] = ENOLINK; + et2sys[(UAEADV - ERROR_TABLE_BASE_uae)] = EADV; + et2sys[(UAESRMNT - ERROR_TABLE_BASE_uae)] = ESRMNT; + et2sys[(UAECOMM - ERROR_TABLE_BASE_uae)] = ECOMM; + et2sys[(UAEPROTO - ERROR_TABLE_BASE_uae)] = EPROTO; + et2sys[(UAEMULTIHOP - ERROR_TABLE_BASE_uae)] = EMULTIHOP; + et2sys[(UAEDOTDOT - ERROR_TABLE_BASE_uae)] = EDOTDOT; + et2sys[(UAEBADMSG - ERROR_TABLE_BASE_uae)] = EBADMSG; + et2sys[(UAEOVERFLOW - ERROR_TABLE_BASE_uae)] = EOVERFLOW; + et2sys[(UAENOTUNIQ - ERROR_TABLE_BASE_uae)] = ENOTUNIQ; + et2sys[(UAEBADFD - ERROR_TABLE_BASE_uae)] = EBADFD; + et2sys[(UAEREMCHG - ERROR_TABLE_BASE_uae)] = EREMCHG; + et2sys[(UAELIBACC - ERROR_TABLE_BASE_uae)] = ELIBACC; + et2sys[(UAELIBBAD - ERROR_TABLE_BASE_uae)] = ELIBBAD; + et2sys[(UAELIBSCN - ERROR_TABLE_BASE_uae)] = ELIBSCN; + et2sys[(UAELIBMAX - ERROR_TABLE_BASE_uae)] = ELIBMAX; + et2sys[(UAELIBEXEC - ERROR_TABLE_BASE_uae)] = ELIBEXEC; + et2sys[(UAEILSEQ - ERROR_TABLE_BASE_uae)] = EILSEQ; + et2sys[(UAERESTART - ERROR_TABLE_BASE_uae)] = ERESTART; + et2sys[(UAESTRPIPE - ERROR_TABLE_BASE_uae)] = ESTRPIPE; + et2sys[(UAEUSERS - ERROR_TABLE_BASE_uae)] = EUSERS; + et2sys[(UAENOTSOCK - ERROR_TABLE_BASE_uae)] = ENOTSOCK; + et2sys[(UAEDESTADDRREQ - ERROR_TABLE_BASE_uae)] = EDESTADDRREQ; + et2sys[(UAEMSGSIZE - ERROR_TABLE_BASE_uae)] = EMSGSIZE; + et2sys[(UAEPROTOTYPE - ERROR_TABLE_BASE_uae)] = EPROTOTYPE; + et2sys[(UAENOPROTOOPT - ERROR_TABLE_BASE_uae)] = ENOPROTOOPT; + et2sys[(UAEPROTONOSUPPORT - ERROR_TABLE_BASE_uae)] = EPROTONOSUPPORT; + et2sys[(UAESOCKTNOSUPPORT - ERROR_TABLE_BASE_uae)] = ESOCKTNOSUPPORT; + et2sys[(UAEOPNOTSUPP - ERROR_TABLE_BASE_uae)] = EOPNOTSUPP; + et2sys[(UAEPFNOSUPPORT - ERROR_TABLE_BASE_uae)] = EPFNOSUPPORT; + et2sys[(UAEAFNOSUPPORT - ERROR_TABLE_BASE_uae)] = EAFNOSUPPORT; + et2sys[(UAEADDRINUSE - ERROR_TABLE_BASE_uae)] = EADDRINUSE; + et2sys[(UAEADDRNOTAVAIL - ERROR_TABLE_BASE_uae)] = EADDRNOTAVAIL; + et2sys[(UAENETDOWN - ERROR_TABLE_BASE_uae)] = ENETDOWN; + et2sys[(UAENETUNREACH - ERROR_TABLE_BASE_uae)] = ENETUNREACH; + et2sys[(UAENETRESET - ERROR_TABLE_BASE_uae)] = ENETRESET; + et2sys[(UAECONNABORTED - ERROR_TABLE_BASE_uae)] = ECONNABORTED; + et2sys[(UAECONNRESET - ERROR_TABLE_BASE_uae)] = ECONNRESET; + et2sys[(UAENOBUFS - ERROR_TABLE_BASE_uae)] = ENOBUFS; + et2sys[(UAEISCONN - ERROR_TABLE_BASE_uae)] = EISCONN; + et2sys[(UAENOTCONN - ERROR_TABLE_BASE_uae)] = ENOTCONN; + et2sys[(UAESHUTDOWN - ERROR_TABLE_BASE_uae)] = ESHUTDOWN; + et2sys[(UAETOOMANYREFS - ERROR_TABLE_BASE_uae)] = ETOOMANYREFS; + et2sys[(UAETIMEDOUT - ERROR_TABLE_BASE_uae)] = ETIMEDOUT; + et2sys[(UAECONNREFUSED - ERROR_TABLE_BASE_uae)] = ECONNREFUSED; + et2sys[(UAEHOSTDOWN - ERROR_TABLE_BASE_uae)] = EHOSTDOWN; + et2sys[(UAEHOSTUNREACH - ERROR_TABLE_BASE_uae)] = EHOSTUNREACH; + et2sys[(UAEALREADY - ERROR_TABLE_BASE_uae)] = EALREADY; + et2sys[(UAEINPROGRESS - ERROR_TABLE_BASE_uae)] = EINPROGRESS; + et2sys[(UAESTALE - ERROR_TABLE_BASE_uae)] = ESTALE; + et2sys[(UAEUCLEAN - ERROR_TABLE_BASE_uae)] = EUCLEAN; + et2sys[(UAENOTNAM - ERROR_TABLE_BASE_uae)] = ENOTNAM; + et2sys[(UAENAVAIL - ERROR_TABLE_BASE_uae)] = ENAVAIL; + et2sys[(UAEISNAM - ERROR_TABLE_BASE_uae)] = EISNAM; + et2sys[(UAEREMOTEIO - ERROR_TABLE_BASE_uae)] = EREMOTEIO; + et2sys[(UAEDQUOT - ERROR_TABLE_BASE_uae)] = EDQUOT; + et2sys[(UAENOMEDIUM - ERROR_TABLE_BASE_uae)] = ENOMEDIUM; + et2sys[(UAEMEDIUMTYPE - ERROR_TABLE_BASE_uae)] = EMEDIUMTYPE; +} + +static afs_int32 +et_to_sys_error(afs_int32 in) +{ + if (in < ERROR_TABLE_BASE_uae || in >= ERROR_TABLE_BASE_uae + 512) + return in; + if (et2sys[in - ERROR_TABLE_BASE_uae] != 0) + return et2sys[in - ERROR_TABLE_BASE_uae]; + return in; +} + +void +afs_CopyError(register struct vrequest *afrom, register struct vrequest *ato) { AFS_STATCNT(afs_CopyError); if (!afrom->initd) @@ -84,12 +228,10 @@ void afs_CopyError(afrom, ato) if (afrom->permWriteError) ato->permWriteError = 1; -} /*afs_CopyError*/ - - -void afs_FinalizeReq(areq) - register struct vrequest *areq; +} +void +afs_FinalizeReq(register struct vrequest *areq) { AFS_STATCNT(afs_FinalizeReq); if (areq->initd) @@ -101,20 +243,18 @@ void afs_FinalizeReq(areq) areq->permWriteError = 0; areq->initd = 1; -} /*afs_FinalizeReq*/ - - -afs_CheckCode(acode, areq, where) - afs_int32 acode; - struct vrequest *areq; - int where; +} +int +afs_CheckCode(afs_int32 acode, struct vrequest *areq, int where) { AFS_STATCNT(afs_CheckCode); - if (acode) { - afs_Trace2(afs_iclSetp, CM_TRACE_CHECKCODE, - ICL_TYPE_INT32, acode, ICL_TYPE_INT32, where); + if (acode) { + afs_Trace2(afs_iclSetp, CM_TRACE_CHECKCODE, ICL_TYPE_INT32, acode, + ICL_TYPE_INT32, where); } + if ((acode & ~0xff) == ERROR_TABLE_BASE_uae) + acode = et_to_sys_error(acode); if (!areq || !areq->initd) return acode; if (areq->networkError) @@ -142,7 +282,7 @@ afs_CheckCode(acode, areq, where) return acode; -} /*afs_CheckCode*/ +} /*afs_CheckCode */ #define VSleep(at) afs_osi_Wait((at)*1000, 0, 0) @@ -163,93 +303,74 @@ int lastcode; #define DIFFERENT 0 #define SAME 1 #define DUNNO 2 -static int VLDB_Same (afid, areq) - struct VenusFid *afid; - struct vrequest *areq; +static int +VLDB_Same(struct VenusFid *afid, struct vrequest *areq) { struct vrequest treq; struct conn *tconn; - int i, type=0; - union { - struct vldbentry tve; - struct nvldbentry ntve; - struct uvldbentry utve; - } v; + int i, type = 0; + union { + struct vldbentry tve; + struct nvldbentry ntve; + struct uvldbentry utve; + } *v; struct volume *tvp; struct cell *tcell; - char *bp, tbuf[CVBS]; /* biggest volume id is 2^32, ~ 4*10^9 */ + char *bp, tbuf[CVBS]; /* biggest volume id is 2^32, ~ 4*10^9 */ unsigned int changed; struct server *(oldhosts[NMAXNSERVERS]); AFS_STATCNT(CheckVLDB); afs_FinalizeReq(areq); - if (i = afs_InitReq(&treq, &afs_osi_cred)) return DUNNO; + if ((i = afs_InitReq(&treq, afs_osi_credp))) + return DUNNO; + v = afs_osi_Alloc(sizeof(*v)); tcell = afs_GetCell(afid->Cell, READ_LOCK); bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume); do { - VSleep(2); /* Better safe than sorry. */ - tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, - tcell->cellNum, &treq, SHARED_LOCK); + VSleep(2); /* Better safe than sorry. */ + tconn = + afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum, + &treq, SHARED_LOCK); if (tconn) { if (tconn->srvr->server->flags & SNO_LHOSTS) { type = 0; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - i = VL_GetEntryByNameO(tconn->id, bp, &v.tve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + i = VL_GetEntryByNameO(tconn->id, bp, &v->tve); + RX_AFS_GLOCK(); } else if (tconn->srvr->server->flags & SYES_LHOSTS) { type = 1; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + i = VL_GetEntryByNameN(tconn->id, bp, &v->ntve); + RX_AFS_GLOCK(); } else { type = 2; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - i = VL_GetEntryByNameU(tconn->id, bp, &v.utve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + i = VL_GetEntryByNameU(tconn->id, bp, &v->utve); + RX_AFS_GLOCK(); if (!(tconn->srvr->server->flags & SVLSRV_UUID)) { if (i == RXGEN_OPCODE) { type = 1; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + i = VL_GetEntryByNameN(tconn->id, bp, &v->ntve); + RX_AFS_GLOCK(); if (i == RXGEN_OPCODE) { type = 0; tconn->srvr->server->flags |= SNO_LHOSTS; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - i = VL_GetEntryByNameO(tconn->id, bp, &v.tve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + i = VL_GetEntryByNameO(tconn->id, bp, &v->tve); + RX_AFS_GLOCK(); } else if (!i) tconn->srvr->server->flags |= SYES_LHOSTS; } else if (!i) - tconn->srvr->server->flags |= SVLSRV_UUID; + tconn->srvr->server->flags |= SVLSRV_UUID; } - lastcode = i; + lastcode = i; } } else i = -1; - } while (afs_Analyze(tconn, i, (struct VenusFid *) 0, &treq, - -1, /* no op code for this */ + } while (afs_Analyze(tconn, i, NULL, &treq, -1, /* no op code for this */ SHARED_LOCK, tcell)); afs_PutCell(tcell, READ_LOCK); @@ -257,50 +378,52 @@ static int VLDB_Same (afid, areq) ICL_TYPE_INT32, i); if (i) { + afs_osi_Free(v, sizeof(*v)); return DUNNO; } /* have info, copy into serverHost array */ changed = 0; tvp = afs_FindVolume(afid, WRITE_LOCK); if (tvp) { - ObtainWriteLock(&tvp->lock,107); - for (i=0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) { - oldhosts[i] = tvp->serverHost[i]; - } - - if (type == 2) { - InstallUVolumeEntry(tvp, &v.utve, afid->Cell, tcell, &treq); - } - else if (type == 1) { - InstallNVolumeEntry(tvp, &v.ntve, afid->Cell); - } - else { - InstallVolumeEntry(tvp, &v.tve, afid->Cell); - } - - if (i < NMAXNSERVERS && tvp->serverHost[i]) { + ObtainWriteLock(&tvp->lock, 107); + for (i = 0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) { + oldhosts[i] = tvp->serverHost[i]; + } + + if (type == 2) { + InstallUVolumeEntry(tvp, &v->utve, afid->Cell, tcell, &treq); + } else if (type == 1) { + InstallNVolumeEntry(tvp, &v->ntve, afid->Cell); + } else { + InstallVolumeEntry(tvp, &v->tve, afid->Cell); + } + + if (i < NMAXNSERVERS && tvp->serverHost[i]) { changed = 1; - } - for (--i;!changed && i >= 0; i--) { - if (tvp->serverHost[i] != oldhosts[i]) { - changed = 1; /* also happens if prefs change. big deal. */ - } - } - - ReleaseWriteLock(&tvp->lock); - afs_PutVolume(tvp, WRITE_LOCK); - } - else { /* can't find volume */ - tvp = afs_GetVolume(afid, &treq, WRITE_LOCK); - if (tvp) { + } + for (--i; !changed && i >= 0; i--) { + if (tvp->serverHost[i] != oldhosts[i]) { + changed = 1; /* also happens if prefs change. big deal. */ + } + } + + ReleaseWriteLock(&tvp->lock); afs_PutVolume(tvp, WRITE_LOCK); - return DIFFERENT; - } - else return DUNNO; + } else { /* can't find volume */ + tvp = afs_GetVolume(afid, &treq, WRITE_LOCK); + if (tvp) { + afs_PutVolume(tvp, WRITE_LOCK); + afs_osi_Free(v, sizeof(*v)); + return DIFFERENT; + } else { + afs_osi_Free(v, sizeof(*v)); + return DUNNO; + } } + afs_osi_Free(v, sizeof(*v)); return (changed ? DIFFERENT : SAME); -} /*VLDB_Same */ +} /*VLDB_Same */ /*------------------------------------------------------------------------ @@ -335,98 +458,95 @@ static int VLDB_Same (afid, areq) * The retry return value is used by afs_StoreAllSegments to determine * if this is a temporary or permanent error. *------------------------------------------------------------------------*/ -int afs_Analyze(aconn, acode, afid, areq, op, locktype, cellp) - register struct conn *aconn; - afs_int32 acode; - register struct vrequest *areq; - struct VenusFid *afid; - int op; - afs_int32 locktype; - struct cell *cellp; -{ /*afs_Analyze*/ - - afs_int32 i, code; - struct srvAddr *sa; - struct server *tsp; - struct volume *tvp; - afs_int32 shouldRetry = 0; - struct afs_stats_RPCErrors *aerrP; - XSTATS_DECLS; +int +afs_Analyze(register struct conn *aconn, afs_int32 acode, + struct VenusFid *afid, register struct vrequest *areq, int op, + afs_int32 locktype, struct cell *cellp) +{ + afs_int32 i; + struct srvAddr *sa; + struct server *tsp; + struct volume *tvp; + afs_int32 shouldRetry = 0; + struct afs_stats_RPCErrors *aerrP; AFS_STATCNT(afs_Analyze); afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op, - ICL_TYPE_POINTER, aconn, - ICL_TYPE_INT32, acode, ICL_TYPE_LONG, areq->uid); + ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG, + areq->uid); - aerrP = (struct afs_stats_RPCErrors *) 0; + aerrP = (struct afs_stats_RPCErrors *)0; if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS)) - aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]); + aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]); afs_FinalizeReq(areq); - if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */ - - tvp = afs_FindVolume(afid, READ_LOCK); - if (tvp) { - afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n", - (afid ? afid->Fid.Volume : 0), - (tvp->name ? tvp->name : ""), - ((tvp->serverHost[0] && tvp->serverHost[0]->cell) ? - tvp->serverHost[0]->cell->cellName : "")); - - for (i=0; i < MAXHOSTS; i++) { - if (tvp->status[i] != not_busy && tvp->status[i] != offline) { - tvp->status[i] = not_busy; + if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */ + + tvp = afs_FindVolume(afid, READ_LOCK); + if (tvp) { + afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n", + (afid ? afid->Fid.Volume : 0), + (tvp->name ? tvp->name : ""), + ((tvp->serverHost[0] + && tvp->serverHost[0]->cell) ? tvp->serverHost[0]-> + cell->cellName : "")); + + for (i = 0; i < MAXHOSTS; i++) { + if (tvp->status[i] != not_busy && tvp->status[i] != offline) { + tvp->status[i] = not_busy; + } + if (tvp->status[i] == not_busy) + shouldRetry = 1; } - if (tvp->status[i] == not_busy) - shouldRetry = 1; - } - afs_PutVolume(tvp, READ_LOCK); - } else { - afs_warnuser("afs: Waiting for busy volume %u\n", - (afid ? afid->Fid.Volume : 0)); - } - - if (areq->busyCount > 100) { - if (aerrP) - (aerrP->err_Volume)++; - areq->volumeError = VOLBUSY; - shouldRetry = 0; - } else { - VSleep(afs_BusyWaitPeriod); /* poll periodically */ - } - if (shouldRetry != 0) - areq->busyCount++; + afs_PutVolume(tvp, READ_LOCK); + } else { + afs_warnuser("afs: Waiting for busy volume %u\n", + (afid ? afid->Fid.Volume : 0)); + } + + if (areq->busyCount > 100) { + if (aerrP) + (aerrP->err_Volume)++; + areq->volumeError = VOLBUSY; + shouldRetry = 0; + } else { + VSleep(afs_BusyWaitPeriod); /* poll periodically */ + } + if (shouldRetry != 0) + areq->busyCount++; - return shouldRetry; /* should retry */ + return shouldRetry; /* should retry */ } - + if (!aconn) { if (!areq->volumeError) { if (aerrP) (aerrP->err_Network)++; - if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */ - ((afid && afs_IsPrimaryCellNum(afid->Cell)) || - (cellp && afs_IsPrimaryCell(cellp)))) { + if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */ + ((afid && afs_IsPrimaryCellNum(afid->Cell)) + || (cellp && afs_IsPrimaryCell(cellp)))) { if (!afid) { - afs_warnuser("afs: hard-mount waiting for a vlserver to return to service\n"); + afs_warnuser + ("afs: hard-mount waiting for a vlserver to return to service\n"); VSleep(hm_retry_int); - afs_CheckServers(1,cellp); - shouldRetry=1; + afs_CheckServers(1, cellp); + shouldRetry = 1; } else { tvp = afs_FindVolume(afid, READ_LOCK); if (!tvp || (tvp->states & VRO)) { - shouldRetry = hm_retry_RO; - } else { - shouldRetry = hm_retry_RW; + shouldRetry = hm_retry_RO; + } else { + shouldRetry = hm_retry_RW; } if (tvp) afs_PutVolume(tvp, READ_LOCK); if (shouldRetry) { - afs_warnuser("afs: hard-mount waiting for volume %u\n", - afid->Fid.Volume); - VSleep(hm_retry_int); - afs_CheckServers(1,cellp); + afs_warnuser + ("afs: hard-mount waiting for volume %u\n", + afid->Fid.Volume); + VSleep(hm_retry_int); + afs_CheckServers(1, cellp); } } } /* if (hm_retry_int ... */ @@ -441,61 +561,69 @@ int afs_Analyze(aconn, acode, afid, areq, op, locktype, cellp) sa = aconn->srvr; tsp = sa->server; + /* Before we do anything with acode, make sure we translate it back to + * a system error */ + if ((acode & ~0xff) == ERROR_TABLE_BASE_uae) + acode = et_to_sys_error(acode); + if (acode == 0) { - /* If we previously took an error, mark this volume not busy */ - if (areq->volumeError) { - tvp = afs_FindVolume(afid, READ_LOCK); - if (tvp) { - for (i=0; iserverHost[i] == tsp) { - tvp->status[i] = not_busy ; + /* If we previously took an error, mark this volume not busy */ + if (areq->volumeError) { + tvp = afs_FindVolume(afid, READ_LOCK); + if (tvp) { + for (i = 0; i < MAXHOSTS; i++) { + if (tvp->serverHost[i] == tsp) { + tvp->status[i] = not_busy; + } } - } - afs_PutVolume(tvp, READ_LOCK); - } - } + afs_PutVolume(tvp, READ_LOCK); + } + } - afs_PutConn(aconn, locktype); - return 0; + afs_PutConn(aconn, locktype); + return 0; } /* If network troubles, mark server as having bogued out again. */ /* VRESTARTING is < 0 because of backward compatibility issues * with 3.4 file servers and older cache managers */ - if ((acode < 0) && (acode != VRESTARTING)) { +#ifdef AFS_64BIT_CLIENT + if (acode == -455) + acode = 455; +#endif /* AFS_64BIT_CLIENT */ + if ((acode < 0) && (acode != VRESTARTING)) { afs_ServerDown(sa); - ForceNewConnections(sa); /*multi homed clients lock:afs_xsrvAddr?*/ + ForceNewConnections(sa); /*multi homed clients lock:afs_xsrvAddr? */ if (aerrP) (aerrP->err_Server)++; } if (acode == VBUSY || acode == VRESTARTING) { if (acode == VBUSY) { - areq->busyCount++; - if (aerrP) - (aerrP->err_VolumeBusies)++; - } - else areq->busyCount = 1; + areq->busyCount++; + if (aerrP) + (aerrP->err_VolumeBusies)++; + } else + areq->busyCount = 1; tvp = afs_FindVolume(afid, READ_LOCK); if (tvp) { - for (i=0; i < MAXHOSTS ; i++ ) { - if (tvp->serverHost[i] == tsp) { - tvp->status[i] = rdwr_busy ; /* can't tell which yet */ - /* to tell which, have to look at the op code. */ + for (i = 0; i < MAXHOSTS; i++) { + if (tvp->serverHost[i] == tsp) { + tvp->status[i] = rdwr_busy; /* can't tell which yet */ + /* to tell which, have to look at the op code. */ + } } - } - afs_PutVolume(tvp, READ_LOCK); - } - else { - afs_warnuser("afs: Waiting for busy volume %u in cell %s\n", - (afid? afid->Fid.Volume : 0), tsp->cell->cellName); - VSleep(afs_BusyWaitPeriod); /* poll periodically */ + afs_PutVolume(tvp, READ_LOCK); + } else { + afs_warnuser("afs: Waiting for busy volume %u in cell %s\n", + (afid ? afid->Fid.Volume : 0), tsp->cell->cellName); + VSleep(afs_BusyWaitPeriod); /* poll periodically */ } shouldRetry = 1; acode = 0; - } - else if (acode == VICETOKENDEAD || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) { + } else if (acode == VICETOKENDEAD + || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) { /* any rxkad error is treated as token expiration */ struct unixuser *tu; @@ -509,24 +637,28 @@ int afs_Analyze(aconn, acode, afid, areq, op, locktype, cellp) tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK); if (tu) { if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED)) - afs_warnuser("afs: Tokens for user of AFS id %d for cell %s have expired\n", - tu->vid, aconn->srvr->server->cell->cellName); + afs_warnuser + ("afs: Tokens for user of AFS id %d for cell %s have expired\n", + tu->vid, aconn->srvr->server->cell->cellName); else - afs_warnuser("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d)\n", - tu->vid, aconn->srvr->server->cell->cellName, acode); - afs_PutUser(tu, READ_LOCK); + afs_warnuser + ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d)\n", + tu->vid, aconn->srvr->server->cell->cellName, acode); + afs_PutUser(tu, READ_LOCK); } else { /* The else case shouldn't be possible and should probably be replaced by a panic? */ if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED)) - afs_warnuser("afs: Tokens for user %d for cell %s have expired\n", - areq->uid, aconn->srvr->server->cell->cellName); + afs_warnuser + ("afs: Tokens for user %d for cell %s have expired\n", + areq->uid, aconn->srvr->server->cell->cellName); else - afs_warnuser("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d)\n", - areq->uid, aconn->srvr->server->cell->cellName, acode); + afs_warnuser + ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d)\n", + areq->uid, aconn->srvr->server->cell->cellName, acode); } - aconn->forceConnectFS = 0; /* don't check until new tokens set */ + aconn->forceConnectFS = 0; /* don't check until new tokens set */ aconn->user->states |= UTokensBad; - shouldRetry = 1; /* Try again (as root). */ + shouldRetry = 1; /* Try again (as root). */ } /* Check for access violation. */ else if (acode == EACCES) { @@ -539,62 +671,58 @@ int afs_Analyze(aconn, acode, afid, areq, op, locktype, cellp) shouldRetry = 0; } /* check for ubik errors; treat them like crashed servers */ - else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U+255) { + else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) { afs_ServerDown(sa); if (aerrP) (aerrP->err_Server)++; - shouldRetry = 1; /* retryable (maybe one is working) */ - VSleep(1); /* just in case */ + shouldRetry = 1; /* retryable (maybe one is working) */ + VSleep(1); /* just in case */ } /* Check for bad volume data base / missing volume. */ - else if (acode == VSALVAGE || acode == VOFFLINE - || acode == VNOVOL || acode == VNOSERVICE || acode == VMOVED) { + else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL + || acode == VNOSERVICE || acode == VMOVED) { struct cell *tcell; - int same; + int same; shouldRetry = 1; areq->volumeError = VOLMISSING; if (aerrP) - (aerrP->err_Volume)++; + (aerrP->err_Volume)++; if (afid && (tcell = afs_GetCell(afid->Cell, 0))) { - same = VLDB_Same(afid, areq); - tvp = afs_FindVolume(afid, READ_LOCK); - if (tvp) { - for (i=0; i < MAXHOSTS && tvp->serverHost[i]; i++ ) { - if (tvp->serverHost[i] == tsp) { - if (tvp->status[i] == end_not_busy) - tvp->status[i] = offline ; - else - tvp->status[i]++; - } - else if (!same) { - tvp->status[i] = not_busy; /* reset the others */ - } - } - afs_PutVolume(tvp, READ_LOCK); - } + same = VLDB_Same(afid, areq); + tvp = afs_FindVolume(afid, READ_LOCK); + if (tvp) { + for (i = 0; i < MAXHOSTS && tvp->serverHost[i]; i++) { + if (tvp->serverHost[i] == tsp) { + if (tvp->status[i] == end_not_busy) + tvp->status[i] = offline; + else + tvp->status[i]++; + } else if (!same) { + tvp->status[i] = not_busy; /* reset the others */ + } + } + afs_PutVolume(tvp, READ_LOCK); + } } - } - else if (acode >= ERROR_TABLE_BASE_VL - && acode <= ERROR_TABLE_BASE_VL + 255) /* vlserver errors */ { - shouldRetry = 0; - areq->volumeError = VOLMISSING; - } - else if (acode >= 0) { + } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) { /* vlserver errors */ + shouldRetry = 0; + areq->volumeError = VOLMISSING; + } else if (acode >= 0) { if (aerrP) (aerrP->err_Other)++; if (op == AFS_STATS_FS_RPCIDX_STOREDATA) areq->permWriteError = 1; - shouldRetry = 0; /* Other random Vice error. */ - } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */ - VSleep(1); /* Just a hack for desperate times. */ + shouldRetry = 0; /* Other random Vice error. */ + } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */ + VSleep(1); /* Just a hack for desperate times. */ if (aerrP) (aerrP->err_Other)++; - shouldRetry = 1; /* packet was too big, please retry call */ - } + shouldRetry = 1; /* packet was too big, please retry call */ + } - if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) { - /* If we get here, code < 0 and we have network/Server troubles. + if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) { + /* If we get here, code < 0 and we have network/Server troubles. * areq->networkError is not set here, since we always * retry in case there is another server. However, if we find * no connection (aconn == 0) we set the networkError flag. @@ -605,9 +733,8 @@ int afs_Analyze(aconn, acode, afid, areq, op, locktype, cellp) VSleep(1); /* Just a hack for desperate times. */ shouldRetry = 1; } - + /* now unlock the connection and return */ afs_PutConn(aconn, locktype); return (shouldRetry); -} /*afs_Analyze*/ - +} /*afs_Analyze */ diff --git a/src/afs/afs_axscache.c b/src/afs/afs_axscache.c index 54354f2b9..f0f7131b0 100644 --- a/src/afs/afs_axscache.c +++ b/src/afs/afs_axscache.c @@ -8,70 +8,74 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_axscache.c,v 1.1.1.4 2001/07/14 22:19:17 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_axscache.c,v 1.7 2003/07/15 23:14:11 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ #include "afs/stds.h" static struct axscache *afs_axsfreelist = NULL; -static struct xfreelist { struct xfreelist *next; } *xfreemallocs = 0, *xsp = 0; -int afs_xaxscnt = 0; +static struct xfreelist { + struct xfreelist *next; +} *xfreemallocs = 0; +static int afs_xaxscnt = 0; afs_rwlock_t afs_xaxs; /* takes an address of an access cache & uid, returns ptr */ /* PRECONDITION: first field has been checked and doesn't match! * INVARIANT: isparent(i,j) ^ isparent(j,i) (ie, they switch around) */ -struct axscache *afs_SlowFindAxs(cachep,id) - struct axscache **cachep; - afs_int32 id; +struct axscache * +afs_SlowFindAxs(struct axscache **cachep, afs_int32 id) { - register struct axscache *i,*j; + register struct axscache *i, *j; - j=(*cachep); - i=j->next; + j = (*cachep); + i = j->next; while (i) { if (i->uid == id) { - axs_Front(cachep,j,i); /* maintain LRU queue */ - return(i); + axs_Front(cachep, j, i); /* maintain LRU queue */ + return (i); } - if (j=i->next) { /* ASSIGNMENT HERE! */ + if ((j = i->next)) { /* ASSIGNMENT HERE! */ if (j->uid == id) { - axs_Front(cachep,i,j); - return(j); + axs_Front(cachep, i, j); + return (j); } - } else - return ((struct axscache *) NULL); - i=j->next; + } else + return ((struct axscache *)NULL); + i = j->next; } - return ((struct axscache *) NULL); + return ((struct axscache *)NULL); } #define NAXSs (1000 / sizeof(struct axscache)) -struct axscache *axs_Alloc() +struct axscache * +axs_Alloc(void) { register struct axscache *i, *j, *xsp; struct axscache *h; int k; - ObtainWriteLock(&afs_xaxs,174); - if (h = afs_axsfreelist) { + ObtainWriteLock(&afs_xaxs, 174); + if ((h = afs_axsfreelist)) { afs_axsfreelist = h->next; } else { - h=i=j= (struct axscache *) afs_osi_Alloc(NAXSs * sizeof(struct axscache)); + h = i = j = + (struct axscache *)afs_osi_Alloc(NAXSs * sizeof(struct axscache)); afs_xaxscnt++; xsp = (struct axscache *)xfreemallocs; xfreemallocs = (struct xfreelist *)h; xfreemallocs->next = (struct xfreelist *)xsp; - for (k = 0; k < NAXSs-1; k++, i++) { + for (k = 0; k < NAXSs - 1; k++, i++) { i->uid = -2; i->axess = 0; - i->next = ++j; /* need j because order of evaluation not defined */ + i->next = ++j; /* need j because order of evaluation not defined */ } i->uid = -2; i->axess = 0; @@ -79,8 +83,8 @@ struct axscache *axs_Alloc() afs_axsfreelist = h->next; } ReleaseWriteLock(&afs_xaxs); - return(h); -} + return (h); +} #define axs_Free(axsp) { \ @@ -93,36 +97,36 @@ struct axscache *axs_Alloc() /* I optimize for speed on lookup, and don't give a RIP about delete. */ -void afs_RemoveAxs(headp, axsp) - struct axscache **headp, *axsp; +void +afs_RemoveAxs(struct axscache **headp, struct axscache *axsp) { struct axscache *i, *j; - if (*headp && axsp) { /* is bullet-proofing really neccessary? */ - if (*headp == axsp) { /* most common case, I think */ + if (*headp && axsp) { /* is bullet-proofing really neccessary? */ + if (*headp == axsp) { /* most common case, I think */ *headp = axsp->next; axs_Free(axsp); return; } - i= *headp; - j=i->next; - + i = *headp; + j = i->next; + while (j) { if (j == axsp) { i->next = j->next; axs_Free(axsp); return; } - if (i = j->next) { /* ASSIGNMENT HERE! */ + if ((i = j->next)) { /* ASSIGNMENT HERE! */ j->next = i->next; axs_Free(axsp); return; } } - } /* end of "if neither pointer is NULL" */ - - return; /* !#@ FAILED to find it! */ + } + /* end of "if neither pointer is NULL" */ + return; /* !#@ FAILED to find it! */ } @@ -130,44 +134,47 @@ void afs_RemoveAxs(headp, axsp) * Takes an entire list of access cache structs and prepends them, lock, stock, * and barrel, to the front of the freelist. */ -void afs_FreeAllAxs(headp) - struct axscache **headp; +void +afs_FreeAllAxs(struct axscache **headp) { - struct axscache *i,*j; + struct axscache *i, *j; - i= *headp; - j=NULL; + i = *headp; + j = NULL; - while (i) { /* chase down the list 'til we reach the end */ - j=i->next; + while (i) { /* chase down the list 'til we reach the end */ + j = i->next; if (!j) { - ObtainWriteLock (&afs_xaxs,176); - i->next = afs_axsfreelist; /* tack on the freelist to the end */ + ObtainWriteLock(&afs_xaxs, 176); + i->next = afs_axsfreelist; /* tack on the freelist to the end */ afs_axsfreelist = *headp; - ReleaseWriteLock (&afs_xaxs); + ReleaseWriteLock(&afs_xaxs); *headp = NULL; return; } - i=j->next; + i = j->next; } - if (j) { /* we ran off the end of the list... */ - ObtainWriteLock (&afs_xaxs,177); - j->next = afs_axsfreelist; /* tack on the freelist to the end */ + if (j) { /* we ran off the end of the list... */ + ObtainWriteLock(&afs_xaxs, 177); + j->next = afs_axsfreelist; /* tack on the freelist to the end */ afs_axsfreelist = *headp; - ReleaseWriteLock (&afs_xaxs); - } + ReleaseWriteLock(&afs_xaxs); + } *headp = NULL; return; } - -void shutdown_xscache() + +/* doesn't appear to be used at all */ +#if 0 +static void +shutdown_xscache(void) { struct xfreelist *xp, *nxp; RWLOCK_INIT(&afs_xaxs, "afs_xaxs"); - xp = xfreemallocs; + xp = xfreemallocs; while (xp) { nxp = xp->next; afs_osi_Free((char *)xp, NAXSs * sizeof(struct axscache)); @@ -176,3 +183,4 @@ void shutdown_xscache() afs_axsfreelist = NULL; xfreemallocs = NULL; } +#endif diff --git a/src/afs/afs_axscache.h b/src/afs/afs_axscache.h index cb271f5a6..370d3a993 100644 --- a/src/afs/afs_axscache.h +++ b/src/afs/afs_axscache.h @@ -26,29 +26,24 @@ */ struct axscache { - afs_int32 uid; /* most frequently used field, I think */ - afs_int32 axess; - struct axscache * next; + afs_int32 uid; /* most frequently used field, I think */ + afs_int32 axess; + struct axscache *next; }; -extern struct axscache *axs_Alloc(), *afs_SlowFindAxs(); -extern void afs_RemoveAxs(), afs_FreeAllAxs(); -extern afs_rwlock_t afs_xaxs; - /* DON'T use this with a NULL pointer! * the quick check should cover 99.9% of the cases */ -#define afs_FindAxs(cachep,id) (((cachep)->uid == id) ? cachep : afs_SlowFindAxs(&(cachep),id)) +#define afs_FindAxs(cachep,id) (((cachep)->uid == id) ? (cachep) : afs_SlowFindAxs(&(cachep),(id))) #define axs_Front(head,pp,p) {(pp)->next = (p)->next; (p)->next= *(head);*(head)=(p);} #define afs_AddAxs(cachep,id,bits) { \ struct axscache *ac; \ - if (ac = axs_Alloc()) { \ - ac->uid = id; \ - ac->axess = (afs_int32)bits; \ - ac->next = cachep; \ + if ((ac = axs_Alloc())) { \ + ac->uid = (id); \ + ac->axess = (afs_int32)(bits); \ + ac->next = (cachep); \ cachep = ac; }} #endif - diff --git a/src/afs/afs_buffer.c b/src/afs/afs_buffer.c index b950c3faf..5783f25bf 100644 --- a/src/afs/afs_buffer.c +++ b/src/afs/afs_buffer.c @@ -8,40 +8,43 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_buffer.c,v 1.1.1.7 2002/09/26 18:57:48 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_buffer.c,v 1.16 2004/01/23 16:53:35 rees Exp $"); -#include "../afs/sysincludes.h" +#include "afs/sysincludes.h" +#include "afsincludes.h" #if !defined(UKERNEL) -#include "../h/param.h" -#include "../h/types.h" -#include "../h/time.h" +#include "h/param.h" +#include "h/types.h" +#include "h/time.h" #if defined(AFS_AIX31_ENV) || defined(AFS_DEC_ENV) -#include "../h/limits.h" +#include "h/limits.h" #endif #if !defined(AFS_AIX_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_SGI_ENV) && !defined(AFS_LINUX20_ENV) -#include "../h/kernel.h" /* Doesn't needed, so it should go */ +#include "h/kernel.h" /* Doesn't needed, so it should go */ #endif #endif /* !defined(UKERNEL) */ -#include "../afs/afs_osi.h" -#include "../afsint/afsint.h" -#include "../afs/lock.h" +#include "afs/afs_osi.h" +#include "afsint.h" +#include "afs/lock.h" #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV) -#include "../h/buf.h" +#include "h/buf.h" #endif /* !defined(UKERNEL) */ -#include "../afs/stds.h" -#include "../afs/volerrors.h" -#include "../afs/exporter.h" -#include "../afs/prs_fs.h" -#include "../afs/afs_chunkops.h" -#include "../afs/dir.h" +#include "afs/stds.h" +#include "afs/volerrors.h" +#include "afs/exporter.h" +#include "afs/prs_fs.h" +#include "afs/afs_chunkops.h" +#include "afs/dir.h" -#include "../afs/afs_stats.h" -#include "../afs/longc_procs.h" +#include "afs/afs_stats.h" +#include "afs/longc_procs.h" +#include "afs/afs.h" #ifndef BUF_TIME_MAX #define BUF_TIME_MAX 0x7fffffff @@ -63,33 +66,12 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_buffer.c,v 1.1.1.7 2002/09/26 1 #define pHash(fid,page) ((((afs_int32)((fid)[0])) & PHFIDMASK) \ | (page & PHPAGEMASK)) -/* Note: this should agree with the definition in kdump.c */ -#if defined(AFS_OSF_ENV) -#if !defined(UKERNEL) -#define AFS_USEBUFFERS 1 -#endif -#endif - #ifdef dirty -#undef dirty /* XXX */ +#undef dirty /* XXX */ #endif -struct buffer { - ino_t fid[1]; /* Unique cache key + i/o addressing */ - afs_int32 page; - afs_int32 accesstime; - struct buffer *hashNext; - char *data; - char lockers; - char dirty; - char hashIndex; -#if AFS_USEBUFFERS - struct buf *bufp; -#endif - afs_rwlock_t lock; /* the lock for this structure */ -} *Buffers = 0; - -char *BufferData; +static struct buffer *Buffers = 0; +static char *BufferData; #ifdef AFS_AIX_ENV extern struct buf *geteblk(); @@ -102,77 +84,82 @@ extern struct buf *geteblk(); */ static afs_lock_t afs_bufferLock; static struct buffer *phTable[PHSIZE]; /* page hash table */ -int nbuffers; -afs_int32 timecounter; +static int nbuffers; +static afs_int32 timecounter; -static struct buffer *afs_newslot(); +/* Prototypes for static routines */ +static struct buffer *afs_newslot(afs_inode_t * afid, afs_int32 apage, + register struct buffer *lp); static int dinit_flag = 0; -void DInit (abuffers) - int abuffers; { +void +DInit(int abuffers) +{ /* Initialize the venus buffer system. */ register int i; register struct buffer *tb; #if AFS_USEBUFFERS - struct buf *tub; /* unix buffer for allocation */ + struct buf *tub; /* unix buffer for allocation */ #endif AFS_STATCNT(DInit); - if (dinit_flag) return; + if (dinit_flag) + return; dinit_flag = 1; #if AFS_USEBUFFERS /* round up to next multiple of NPB, since we allocate multiple pages per chunk */ - abuffers = ((abuffers-1) | (NPB-1)) + 1; + abuffers = ((abuffers - 1) | (NPB - 1)) + 1; #endif LOCK_INIT(&afs_bufferLock, "afs_bufferLock"); - Buffers = (struct buffer *) afs_osi_Alloc(abuffers * sizeof(struct buffer)); + Buffers = + (struct buffer *)afs_osi_Alloc(abuffers * sizeof(struct buffer)); #if !AFS_USEBUFFERS - BufferData = (char *) afs_osi_Alloc(abuffers * AFS_BUFFER_PAGESIZE); + BufferData = (char *)afs_osi_Alloc(abuffers * AFS_BUFFER_PAGESIZE); #endif timecounter = 1; afs_stats_cmperf.bufAlloced = nbuffers = abuffers; - for(i=0;ib_un.b_addr; + tub = geteblk(AFS_BUFFER_PAGESIZE * NPB); + BufferData = (char *)tub->b_un.b_addr; } #endif - /* Fill in each buffer with an empty indication. */ + /* Fill in each buffer with an empty indication. */ tb = &Buffers[i]; - dirp_Zap(tb->fid); - tb->accesstime = 0; + dirp_Zap(tb->fid); + tb->accesstime = 0; tb->lockers = 0; #if AFS_USEBUFFERS - if ((i & (NPB-1)) == 0) + if ((i & (NPB - 1)) == 0) tb->bufp = tub; else tb->bufp = 0; - tb->data = &BufferData[AFS_BUFFER_PAGESIZE * (i&(NPB-1))]; + tb->data = &BufferData[AFS_BUFFER_PAGESIZE * (i & (NPB - 1))]; #else - tb->data = &BufferData[AFS_BUFFER_PAGESIZE*i]; + tb->data = &BufferData[AFS_BUFFER_PAGESIZE * i]; #endif tb->hashIndex = 0; - tb->dirty = 0; + tb->dirty = 0; RWLOCK_INIT(&tb->lock, "buffer lock"); } return; } -char *DRead(fid,page) - register ino_t *fid; - register int page; { +void * +DRead(register afs_inode_t * fid, register int page) +{ /* Read a page from the disk. */ register struct buffer *tb, *tb2; - void *tfile; - register afs_int32 code, *sizep; + struct osi_file *tfile; + int code; AFS_STATCNT(DRead); - MObtainWriteLock(&afs_bufferLock,256); + MObtainWriteLock(&afs_bufferLock, 256); -/* some new code added 1/1/92 */ #define bufmatch(tb) (tb->page == page && dirp_Eq(tb->fid, fid)) #define buf_Front(head,parent,p) {(parent)->hashNext = (p)->hashNext; (p)->hashNext= *(head);*(head)=(p);} @@ -182,47 +169,46 @@ char *DRead(fid,page) * of larger code size. This could be simplified by better use of * macros. */ - if ( tb = phTable[pHash(fid,page)] ) { /* ASSMT HERE */ + if ((tb = phTable[pHash(fid, page)])) { if (bufmatch(tb)) { - MObtainWriteLock(&tb->lock,257); + MObtainWriteLock(&tb->lock, 257); ReleaseWriteLock(&afs_bufferLock); tb->lockers++; tb->accesstime = timecounter++; AFS_STATS(afs_stats_cmperf.bufHits++); MReleaseWriteLock(&tb->lock); return tb->data; - } - else { - register struct buffer **bufhead; - bufhead = &( phTable[pHash(fid,page)] ); - while (tb2 = tb->hashNext) { - if (bufmatch(tb2)) { - buf_Front(bufhead,tb,tb2); - MObtainWriteLock(&tb2->lock,258); - ReleaseWriteLock(&afs_bufferLock); - tb2->lockers++; - tb2->accesstime = timecounter++; - AFS_STATS(afs_stats_cmperf.bufHits++); - MReleaseWriteLock(&tb2->lock); - return tb2->data; - } - if (tb = tb2->hashNext) { /* ASSIGNMENT HERE! */ - if (bufmatch(tb)) { - buf_Front(bufhead,tb2,tb); - MObtainWriteLock(&tb->lock,259); - ReleaseWriteLock(&afs_bufferLock); - tb->lockers++; - tb->accesstime = timecounter++; - AFS_STATS(afs_stats_cmperf.bufHits++); - MReleaseWriteLock(&tb->lock); - return tb->data; - } + } else { + register struct buffer **bufhead; + bufhead = &(phTable[pHash(fid, page)]); + while ((tb2 = tb->hashNext)) { + if (bufmatch(tb2)) { + buf_Front(bufhead, tb, tb2); + MObtainWriteLock(&tb2->lock, 258); + ReleaseWriteLock(&afs_bufferLock); + tb2->lockers++; + tb2->accesstime = timecounter++; + AFS_STATS(afs_stats_cmperf.bufHits++); + MReleaseWriteLock(&tb2->lock); + return tb2->data; + } + if ((tb = tb2->hashNext)) { + if (bufmatch(tb)) { + buf_Front(bufhead, tb2, tb); + MObtainWriteLock(&tb->lock, 259); + ReleaseWriteLock(&afs_bufferLock); + tb->lockers++; + tb->accesstime = timecounter++; + AFS_STATS(afs_stats_cmperf.bufHits++); + MReleaseWriteLock(&tb->lock); + return tb->data; + } + } else + break; } - else break; - } } - } - else tb2 = NULL; + } else + tb2 = NULL; AFS_STATS(afs_stats_cmperf.bufMisses++); /* can't find it */ @@ -232,29 +218,29 @@ char *DRead(fid,page) */ tb = afs_newslot(fid, page, (tb ? tb : tb2)); if (!tb) { - MReleaseWriteLock(&afs_bufferLock); - return 0; + MReleaseWriteLock(&afs_bufferLock); + return NULL; } - MObtainWriteLock(&tb->lock,260); + MObtainWriteLock(&tb->lock, 260); MReleaseWriteLock(&afs_bufferLock); tb->lockers++; tfile = afs_CFileOpen(fid[0]); - sizep = (afs_int32 *)tfile; - if (page * AFS_BUFFER_PAGESIZE >= *sizep) { + if (page * AFS_BUFFER_PAGESIZE >= tfile->size) { dirp_Zap(tb->fid); tb->lockers--; MReleaseWriteLock(&tb->lock); afs_CFileClose(tfile); - return 0; + return NULL; } - code = afs_CFileRead(tfile, tb->page * AFS_BUFFER_PAGESIZE, - tb->data, AFS_BUFFER_PAGESIZE); + code = + afs_CFileRead(tfile, tb->page * AFS_BUFFER_PAGESIZE, tb->data, + AFS_BUFFER_PAGESIZE); afs_CFileClose(tfile); if (code < AFS_BUFFER_PAGESIZE) { dirp_Zap(tb->fid); tb->lockers--; MReleaseWriteLock(&tb->lock); - return 0; + return NULL; } /* Note that findslot sets the page field in the buffer equal to * what it is searching for. */ @@ -262,8 +248,9 @@ char *DRead(fid,page) return tb->data; } -static void FixupBucket(ap) - register struct buffer *ap; { +static void +FixupBucket(register struct buffer *ap) +{ register struct buffer **lp, *tp; register int i; /* first try to get it out of its current hash bucket, in which it @@ -271,7 +258,7 @@ static void FixupBucket(ap) AFS_STATCNT(FixupBucket); i = ap->hashIndex; lp = &phTable[i]; - for(tp = *lp; tp; tp=tp->hashNext) { + for (tp = *lp; tp; tp = tp->hashNext) { if (tp == ap) { *lp = tp->hashNext; break; @@ -279,22 +266,21 @@ static void FixupBucket(ap) lp = &tp->hashNext; } /* now figure the new hash bucket */ - i = pHash(ap->fid,ap->page); + i = pHash(ap->fid, ap->page); ap->hashIndex = i; /* remember where we are for deletion */ ap->hashNext = phTable[i]; /* add us to the list */ - phTable[i] = ap; /* at the front, since it's LRU */ + phTable[i] = ap; /* at the front, since it's LRU */ } -static struct buffer *afs_newslot (afid,apage,lp) - ino_t *afid; - afs_int32 apage; - register struct buffer *lp; /* pointer to a fairly-old buffer */ +/* lp is pointer to a fairly-old buffer */ +static struct buffer * +afs_newslot(afs_inode_t * afid, afs_int32 apage, register struct buffer *lp) { /* Find a usable buffer slot */ register afs_int32 i; afs_int32 lt; register struct buffer *tp; - void *tfile; + struct osi_file *tfile; AFS_STATCNT(afs_newslot); /* we take a pointer here to a buffer which was at the end of an @@ -304,11 +290,10 @@ static struct buffer *afs_newslot (afid,apage,lp) * case" for loop below. */ if (lp && (lp->lockers == 0)) { - lt = lp->accesstime; - } - else { - lp = 0; - lt = BUF_TIME_MAX; + lt = lp->accesstime; + } else { + lp = 0; + lt = BUF_TIME_MAX; } /* timecounter might have wrapped, if machine is very very busy @@ -326,44 +311,43 @@ static struct buffer *afs_newslot (afid,apage,lp) * themselves back out after just a few more DReads. */ if (timecounter < 0) { - timecounter = 1; - tp = Buffers; - for (i=0;iaccesstime = 0; - if (!lp && !tp->lockers) /* one is as good as the rest, I guess */ - lp = tp; - } - } - else { - /* this is the typical case */ - tp = Buffers; - for (i=0;ilockers == 0) { - if (tp->accesstime < lt) { - lp = tp; - lt = tp->accesstime; - } + timecounter = 1; + tp = Buffers; + for (i = 0; i < nbuffers; i++, tp++) { + tp->accesstime = 0; + if (!lp && !tp->lockers) /* one is as good as the rest, I guess */ + lp = tp; + } + } else { + /* this is the typical case */ + tp = Buffers; + for (i = 0; i < nbuffers; i++, tp++) { + if (tp->lockers == 0) { + if (tp->accesstime < lt) { + lp = tp; + lt = tp->accesstime; + } + } } - } } if (lp == 0) { - /* There are no unlocked buffers -- this used to panic, but that - * seems extreme. To the best of my knowledge, all the callers - * of DRead are prepared to handle a zero return. Some of them - * just panic directly, but not all of them. */ - afs_warn ("all buffers locked"); - return 0; + /* There are no unlocked buffers -- this used to panic, but that + * seems extreme. To the best of my knowledge, all the callers + * of DRead are prepared to handle a zero return. Some of them + * just panic directly, but not all of them. */ + afs_warn("all buffers locked"); + return 0; } if (lp->dirty) { tfile = afs_CFileOpen(lp->fid[0]); - afs_CFileWrite(tfile, lp->page * AFS_BUFFER_PAGESIZE, - lp->data, AFS_BUFFER_PAGESIZE); - lp->dirty = 0; + afs_CFileWrite(tfile, lp->page * AFS_BUFFER_PAGESIZE, lp->data, + AFS_BUFFER_PAGESIZE); + lp->dirty = 0; afs_CFileClose(tfile); AFS_STATS(afs_stats_cmperf.bufFlushDirty++); - } + } /* Now fill in the header. */ dirp_Cpy(lp->fid, afid); /* set this */ @@ -374,9 +358,9 @@ static struct buffer *afs_newslot (afid,apage,lp) return lp; } -void DRelease (bp,flag) - register struct buffer *bp; - int flag; { +void +DRelease(register struct buffer *bp, int flag) +{ /* Release a buffer, specifying whether or not the buffer has been * modified by the locker. */ register int index; @@ -385,30 +369,34 @@ void DRelease (bp,flag) #endif AFS_STATCNT(DRelease); - if (!bp) return; + if (!bp) + return; #if AFS_USEBUFFERS /* look for buffer by scanning Unix buffers for appropriate address */ tp = Buffers; - for(index = 0; index < nbuffers; index += NPB, tp += NPB) { - if ((afs_int32)bp >= (afs_int32)tp->data - && (afs_int32)bp < (afs_int32)tp->data + AFS_BUFFER_PAGESIZE*NPB) { + for (index = 0; index < nbuffers; index += NPB, tp += NPB) { + if ((afs_int32) bp >= (afs_int32) tp->data + && (afs_int32) bp < + (afs_int32) tp->data + AFS_BUFFER_PAGESIZE * NPB) { /* we found the right range */ - index += ((afs_int32)bp - (afs_int32)tp->data) >> LOGPS; + index += ((afs_int32) bp - (afs_int32) tp->data) >> LOGPS; break; } } #else - index = (((char *)bp)-((char *)BufferData))>>LOGPS; + index = (((char *)bp) - ((char *)BufferData)) >> LOGPS; #endif bp = &(Buffers[index]); - MObtainWriteLock(&bp->lock,261); + MObtainWriteLock(&bp->lock, 261); bp->lockers--; - if (flag) bp->dirty=1; + if (flag) + bp->dirty = 1; MReleaseWriteLock(&bp->lock); } -DVOffset (ap) - register void *ap; { +int +DVOffset(register void *ap) +{ /* Return the byte within a file represented by a buffer pointer. */ register struct buffer *bp; register int index; @@ -416,23 +404,26 @@ DVOffset (ap) register struct buffer *tp; #endif AFS_STATCNT(DVOffset); - bp=ap; + bp = ap; #if AFS_USEBUFFERS /* look for buffer by scanning Unix buffers for appropriate address */ tp = Buffers; - for(index = 0; index < nbuffers; index += NPB, tp += NPB) { - if ((afs_int32)bp >= (afs_int32)tp->data && (afs_int32)bp < (afs_int32)tp->data + AFS_BUFFER_PAGESIZE*NPB) { + for (index = 0; index < nbuffers; index += NPB, tp += NPB) { + if ((afs_int32) bp >= (afs_int32) tp->data + && (afs_int32) bp < + (afs_int32) tp->data + AFS_BUFFER_PAGESIZE * NPB) { /* we found the right range */ - index += ((afs_int32)bp - (afs_int32)tp->data) >> LOGPS; + index += ((afs_int32) bp - (afs_int32) tp->data) >> LOGPS; break; } } #else - index = (((char *)bp)-((char *)BufferData))>>LOGPS; + index = (((char *)bp) - ((char *)BufferData)) >> LOGPS; #endif - if (index<0 || index >= nbuffers) return -1; + if (index < 0 || index >= nbuffers) + return -1; bp = &(Buffers[index]); - return AFS_BUFFER_PAGESIZE*bp->page+(int)(((char *)ap)-bp->data); + return AFS_BUFFER_PAGESIZE * bp->page + (int)(((char *)ap) - bp->data); } /* 1/1/91 - I've modified the hash function to take the page as well @@ -441,39 +432,41 @@ DVOffset (ap) * of the hash function. Oh well. This should use the list traversal * method of DRead... */ -void DZap (fid) - ino_t *fid; +void +DZap(afs_inode_t * fid) { register int i; /* Destroy all buffers pertaining to a particular fid. */ register struct buffer *tb; - + AFS_STATCNT(DZap); MObtainReadLock(&afs_bufferLock); - for (i=0;i<=PHPAGEMASK;i++) - for(tb=phTable[pHash(fid,i)]; tb; tb=tb->hashNext) - if (dirp_Eq(tb->fid,fid)) { - MObtainWriteLock(&tb->lock,262); - dirp_Zap(tb->fid); - tb->dirty = 0; - MReleaseWriteLock(&tb->lock); - } + for (i = 0; i <= PHPAGEMASK; i++) + for (tb = phTable[pHash(fid, i)]; tb; tb = tb->hashNext) + if (dirp_Eq(tb->fid, fid)) { + MObtainWriteLock(&tb->lock, 262); + dirp_Zap(tb->fid); + tb->dirty = 0; + MReleaseWriteLock(&tb->lock); + } MReleaseReadLock(&afs_bufferLock); } -void DFlush () { +void +DFlush(void) +{ /* Flush all the modified buffers. */ - register int i, code; + register int i; register struct buffer *tb; - void *tfile; + struct osi_file *tfile; AFS_STATCNT(DFlush); tb = Buffers; MObtainReadLock(&afs_bufferLock); - for(i=0;idirty) { - MObtainWriteLock(&tb->lock,263); + for (i = 0; i < nbuffers; i++, tb++) { + if (tb->dirty) { + MObtainWriteLock(&tb->lock, 263); tb->lockers++; MReleaseReadLock(&afs_bufferLock); if (tb->dirty) { @@ -491,26 +484,27 @@ void DFlush () { MReleaseReadLock(&afs_bufferLock); } -char *DNew (fid,page) - register int page; - register ino_t *fid; +void * +DNew(register afs_inode_t * fid, register int page) { /* Same as read, only do *not* even try to read the page, since it probably doesn't exist. */ register struct buffer *tb; AFS_STATCNT(DNew); - MObtainWriteLock(&afs_bufferLock,264); - if ((tb = afs_newslot(fid,page,NULL)) == 0) { + MObtainWriteLock(&afs_bufferLock, 264); + if ((tb = afs_newslot(fid, page, NULL)) == 0) { MReleaseWriteLock(&afs_bufferLock); return 0; } - MObtainWriteLock(&tb->lock,265); + MObtainWriteLock(&tb->lock, 265); MReleaseWriteLock(&afs_bufferLock); tb->lockers++; MReleaseWriteLock(&tb->lock); return tb->data; } -void shutdown_bufferpackage() { +void +shutdown_bufferpackage(void) +{ #if AFS_USEBUFFERS register struct buffer *tp; #endif @@ -521,25 +515,27 @@ void shutdown_bufferpackage() { /* Free all allocated Buffers and associated buffer pages */ DFlush(); if (afs_cold_shutdown) { - dinit_flag = 0; + dinit_flag = 0; #if !AFS_USEBUFFERS - afs_osi_Free(BufferData, nbuffers * AFS_BUFFER_PAGESIZE); + afs_osi_Free(BufferData, nbuffers * AFS_BUFFER_PAGESIZE); #else - tp = Buffers; - for (i=0; i < nbuffers; i+= NPB, tp += NPB) { - /* The following check shouldn't be necessary and it will be removed soon */ - if (!tp->bufp) - afs_warn("shutdown_bufferpackage: bufp == 0!! Shouldn't happen\n"); - else { - brelse(tp->bufp); - tp->bufp = 0; + tp = Buffers; + for (i = 0; i < nbuffers; i += NPB, tp += NPB) { + /* The following check shouldn't be necessary and it will be removed soon */ + if (!tp->bufp) + afs_warn + ("shutdown_bufferpackage: bufp == 0!! Shouldn't happen\n"); + else { + brelse(tp->bufp); + tp->bufp = 0; + } } - } #endif - afs_osi_Free(Buffers, nbuffers * sizeof(struct buffer)); - nbuffers = 0; - timecounter = 1; - for(i=0;i -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_call.c,v 1.16 2003/07/30 17:23:42 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_call.c,v 1.66 2004/04/12 16:04:31 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" -#include "../rx/rx_globals.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" +#include "rx/rx_globals.h" #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV) #include "net/if.h" #ifdef AFS_SGI62_ENV -#include "../h/hashing.h" +#include "h/hashing.h" #endif #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV) #include "netinet/in_var.h" #endif #endif /* !defined(UKERNEL) */ #ifdef AFS_LINUX22_ENV -#include "../h/smp_lock.h" +#include "h/smp_lock.h" #endif @@ -42,28 +43,35 @@ struct afsop_cell { }; char afs_zeros[AFS_ZEROS]; -char afs_rootVolumeName[64]=""; -struct afs_icl_set *afs_iclSetp = (struct afs_icl_set*)0; -struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set*)0; - -#if defined(AFS_GLOBAL_SUNLOCK) && !defined(AFS_HPUX_ENV) && !defined(AFS_AIX41_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +char afs_rootVolumeName[64] = ""; +struct afs_icl_set *afs_iclSetp = (struct afs_icl_set *)0; +struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set *)0; +#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) kmutex_t afs_global_lock; kmutex_t afs_rxglobal_lock; +#endif #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) long afs_global_owner; #endif -#endif #if defined(AFS_OSF_ENV) simple_lock_data_t afs_global_lock; -#elif defined(AFS_DARWIN_ENV) +#endif + +#if defined(AFS_DARWIN_ENV) struct lock__bsd__ afs_global_lock; -#elif defined(AFS_FBSD_ENV) +#endif + +#if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD50_ENV) struct lock afs_global_lock; struct proc *afs_global_owner; #endif +#ifdef AFS_FBSD50_ENV +struct mtx afs_global_mtx; +#endif + #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) thread_t afs_global_owner; #endif /* AFS_OSF_ENV */ @@ -85,8 +93,11 @@ extern struct interfaceAddr afs_cb_interface; static int afs_RX_Running = 0; static int afs_InitSetup_done = 0; +afs_int32 afs_rx_deadtime = AFS_RXDEADTIME; +afs_int32 afs_rx_harddead = AFS_HARDDEADTIME; + static int -Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval); + Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval); #if defined(AFS_HPUX_ENV) extern int afs_vfs_mount(); @@ -95,13 +106,14 @@ extern int afs_vfs_mount(); /* This is code which needs to be called once when the first daemon enters * the client. A non-zero return means an error and AFS should not start. */ -static int afs_InitSetup(int preallocs) +static int +afs_InitSetup(int preallocs) { extern void afs_InitStats(); int code; if (afs_InitSetup_done) - return; + return EAGAIN; #ifndef AFS_NOSTATS /* @@ -111,7 +123,7 @@ static int afs_InitSetup(int preallocs) */ afs_InitStats(); #endif /* AFS_NOSTATS */ - + memset(afs_zeros, 0, AFS_ZEROS); /* start RX */ @@ -121,7 +133,7 @@ static int afs_InitSetup(int preallocs) printf("AFS: RX failed to initialize.\n"); return code; } - rx_SetRxDeadTime(AFS_RXDEADTIME); + rx_SetRxDeadTime(afs_rx_deadtime); /* resource init creates the services */ afs_ResourceInit(preallocs); @@ -130,239 +142,268 @@ static int afs_InitSetup(int preallocs) return code; } + #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS) struct afsd_thread_info { unsigned long parm; struct completion *complete; }; -static int afsd_thread(void *rock) { - struct afsd_thread_info *arg=rock; - unsigned long parm=arg->parm; +static int +afsd_thread(void *rock) +{ + struct afsd_thread_info *arg = rock; + unsigned long parm = arg->parm; #ifdef SYS_SETPRIORITY_EXPORTED - int (*sys_setpriority)(int,int,int) = sys_call_table[__NR_setpriority]; -#endif - daemonize(); /* doesn't do much, since we were forked from keventd, but - does call mm_release, which wakes up our parent (since it - used CLONE_VFORK) */ - reparent_to_init(); - afs_osi_MaskSignals(); - switch (parm) { - case AFSOP_START_RXCALLBACK: - sprintf(current->comm, "afs_cbstart"); - AFS_GLOCK(); - complete(arg->complete); - afs_CB_Running = 1; - while (afs_RX_Running != 2) - afs_osi_Sleep(&afs_RX_Running); - sprintf(current->comm, "afs_callback"); - afs_RXCallBackServer(); - AFS_GUNLOCK(); - complete_and_exit(0,0); - break; - case AFSOP_START_AFS: - sprintf(current->comm, "afs_afsstart"); - AFS_GLOCK(); - complete(arg->complete); - AFS_Running = 1; - while (afs_initState < AFSOP_START_AFS) - afs_osi_Sleep(&afs_initState); - DInit(AFS_MINBUFFERS); - afs_initState = AFSOP_START_BKG; - afs_osi_Wakeup(&afs_initState); - sprintf(current->comm, "afsd"); - afs_Daemon(); - AFS_GUNLOCK(); - complete_and_exit(0,0); - break; - case AFSOP_START_BKG: - sprintf(current->comm, "afs_bkgstart"); - AFS_GLOCK(); - complete(arg->complete); - while (afs_initState < AFSOP_START_BKG) - afs_osi_Sleep(&afs_initState); - if (afs_initState < AFSOP_GO) { - afs_initState = AFSOP_GO; - afs_osi_Wakeup(&afs_initState); - } - sprintf(current->comm, "afs_background"); - afs_BackgroundDaemon(); - AFS_GUNLOCK(); - complete_and_exit(0,0); - break; - case AFSOP_START_TRUNCDAEMON: - sprintf(current->comm, "afs_trimstart"); - AFS_GLOCK(); - complete(arg->complete); - while (afs_initState < AFSOP_GO) - afs_osi_Sleep(&afs_initState); - sprintf(current->comm, "afs_cachetrim"); - afs_CacheTruncateDaemon(); - AFS_GUNLOCK(); - complete_and_exit(0,0); - break; - case AFSOP_START_CS: - sprintf(current->comm, "afs_checkserver"); - AFS_GLOCK(); - complete(arg->complete); - afs_CheckServerDaemon(); - AFS_GUNLOCK(); - complete_and_exit(0,0); - break; - case AFSOP_RXEVENT_DAEMON: - sprintf(current->comm, "afs_evtstart"); + int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority]; +#endif +#if defined(AFS_LINUX26_ENV) + daemonize("afsd"); +#else + daemonize(); +#endif + /* doesn't do much, since we were forked from keventd, but + * does call mm_release, which wakes up our parent (since it + * used CLONE_VFORK) */ +#if !defined(AFS_LINUX26_ENV) + reparent_to_init(); +#endif + afs_osi_MaskSignals(); + switch (parm) { + case AFSOP_START_RXCALLBACK: + sprintf(current->comm, "afs_cbstart"); + AFS_GLOCK(); + complete(arg->complete); + afs_CB_Running = 1; + while (afs_RX_Running != 2) + afs_osi_Sleep(&afs_RX_Running); + sprintf(current->comm, "afs_callback"); + afs_RXCallBackServer(); + AFS_GUNLOCK(); + complete_and_exit(0, 0); + break; + case AFSOP_START_AFS: + sprintf(current->comm, "afs_afsstart"); + AFS_GLOCK(); + complete(arg->complete); + AFS_Running = 1; + while (afs_initState < AFSOP_START_AFS) + afs_osi_Sleep(&afs_initState); + afs_initState = AFSOP_START_BKG; + afs_osi_Wakeup(&afs_initState); + sprintf(current->comm, "afsd"); + afs_Daemon(); + AFS_GUNLOCK(); + complete_and_exit(0, 0); + break; + case AFSOP_START_BKG: + sprintf(current->comm, "afs_bkgstart"); + AFS_GLOCK(); + complete(arg->complete); + while (afs_initState < AFSOP_START_BKG) + afs_osi_Sleep(&afs_initState); + if (afs_initState < AFSOP_GO) { + afs_initState = AFSOP_GO; + afs_osi_Wakeup(&afs_initState); + } + sprintf(current->comm, "afs_background"); + afs_BackgroundDaemon(); + AFS_GUNLOCK(); + complete_and_exit(0, 0); + break; + case AFSOP_START_TRUNCDAEMON: + sprintf(current->comm, "afs_trimstart"); + AFS_GLOCK(); + complete(arg->complete); + while (afs_initState < AFSOP_GO) + afs_osi_Sleep(&afs_initState); + sprintf(current->comm, "afs_cachetrim"); + afs_CacheTruncateDaemon(); + AFS_GUNLOCK(); + complete_and_exit(0, 0); + break; + case AFSOP_START_CS: + sprintf(current->comm, "afs_checkserver"); + AFS_GLOCK(); + complete(arg->complete); + afs_CheckServerDaemon(); + AFS_GUNLOCK(); + complete_and_exit(0, 0); + break; + case AFSOP_RXEVENT_DAEMON: + sprintf(current->comm, "afs_evtstart"); #ifdef SYS_SETPRIORITY_EXPORTED - sys_setpriority(PRIO_PROCESS,0,-10); + sys_setpriority(PRIO_PROCESS, 0, -10); #else #ifdef CURRENT_INCLUDES_NICE - current->nice=-10; -#endif -#endif - AFS_GLOCK(); - complete(arg->complete); - while (afs_initState < AFSOP_START_BKG) - afs_osi_Sleep(&afs_initState); - sprintf(current->comm, "afs_rxevent"); - afs_rxevent_daemon(); - AFS_GUNLOCK(); - complete_and_exit(0,0); - break; - case AFSOP_RXLISTENER_DAEMON: - sprintf(current->comm, "afs_lsnstart"); + current->nice = -10; +#endif +#endif + AFS_GLOCK(); + complete(arg->complete); + while (afs_initState < AFSOP_START_BKG) + afs_osi_Sleep(&afs_initState); + sprintf(current->comm, "afs_rxevent"); + afs_rxevent_daemon(); + AFS_GUNLOCK(); + complete_and_exit(0, 0); + break; + case AFSOP_RXLISTENER_DAEMON: + sprintf(current->comm, "afs_lsnstart"); #ifdef SYS_SETPRIORITY_EXPORTED - sys_setpriority(PRIO_PROCESS,0,-10); + sys_setpriority(PRIO_PROCESS, 0, -10); #else #ifdef CURRENT_INCLUDES_NICE - current->nice=-10; -#endif -#endif - AFS_GLOCK(); - complete(arg->complete); - afs_initState = AFSOP_START_AFS; - afs_osi_Wakeup(&afs_initState); - afs_RX_Running = 2; - afs_osi_Wakeup(&afs_RX_Running); - afs_osi_RxkRegister(); - sprintf(current->comm, "afs_rxlistener"); - rxk_Listener(); - AFS_GUNLOCK(); - complete_and_exit(0,0); - break; - default: - printf("Unknown op %d in StartDaemon()\n"); - break; - } - return 0; + current->nice = -10; +#endif +#endif + AFS_GLOCK(); + complete(arg->complete); + afs_initState = AFSOP_START_AFS; + afs_osi_Wakeup(&afs_initState); + afs_RX_Running = 2; + afs_osi_Wakeup(&afs_RX_Running); + afs_osi_RxkRegister(); + sprintf(current->comm, "afs_rxlistener"); + rxk_Listener(); + AFS_GUNLOCK(); + complete_and_exit(0, 0); + break; + default: + printf("Unknown op %d in StartDaemon()\n"); + break; + } + return 0; } -void afsd_launcher(void *rock) { - if (!kernel_thread(afsd_thread,rock, CLONE_VFORK|SIGCHLD)) +void +afsd_launcher(void *rock) +{ + if (!kernel_thread(afsd_thread, rock, CLONE_VFORK | SIGCHLD)) printf("kernel_thread failed. afs startup will not complete\n"); } -void afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5, - long parm6) +void +afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5, + long parm6) { - int code; - DECLARE_COMPLETION(c); - struct tq_struct tq; - struct afsd_thread_info info; - if (parm == AFSOP_START_RXCALLBACK) { - if (afs_CB_Running) return; - } else if (parm == AFSOP_RXLISTENER_DAEMON) { - if (afs_RX_Running) return; - afs_RX_Running=1; - code = afs_InitSetup(parm2); - if (parm3) { - rx_enablePeerRPCStats(); - } - if (parm4) { - rx_enableProcessRPCStats(); - } - if (code) - return; - } else if (parm == AFSOP_START_AFS) { - if (AFS_Running) return; - } /* other functions don't need setup in the parent */ - info.complete=&c; - info.parm=parm; - tq.sync=0; - INIT_LIST_HEAD(&tq.list); - tq.routine=afsd_launcher; - tq.data=&info; - schedule_task(&tq); - AFS_GUNLOCK(); - /* we need to wait cause we passed stack pointers around.... */ - wait_for_completion(&c); - AFS_GLOCK(); + int code; + DECLARE_COMPLETION(c); +#if defined(AFS_LINUX26_ENV) + struct work_struct tq; +#else + struct tq_struct tq; +#endif + struct afsd_thread_info info; + if (parm == AFSOP_START_RXCALLBACK) { + if (afs_CB_Running) + return; + } else if (parm == AFSOP_RXLISTENER_DAEMON) { + if (afs_RX_Running) + return; + afs_RX_Running = 1; + code = afs_InitSetup(parm2); + if (parm3) { + rx_enablePeerRPCStats(); + } + if (parm4) { + rx_enableProcessRPCStats(); + } + if (code) + return; + } else if (parm == AFSOP_START_AFS) { + if (AFS_Running) + return; + } /* other functions don't need setup in the parent */ + info.complete = &c; + info.parm = parm; +#if defined(AFS_LINUX26_ENV) + INIT_WORK(&tq, afsd_launcher, &info); + schedule_work(&tq); +#else + tq.sync = 0; + INIT_LIST_HEAD(&tq.list); + tq.routine = afsd_launcher; + tq.data = &info; + schedule_task(&tq); +#endif + AFS_GUNLOCK(); + /* we need to wait cause we passed stack pointers around.... */ + wait_for_completion(&c); + AFS_GLOCK(); } #endif +/* leaving as is, probably will barf if we add prototypes here since it's likely being called +with partial list */ +int afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6) -long parm, parm2, parm3, parm4, parm5, parm6; + long parm, parm2, parm3, parm4, parm5, parm6; { afs_int32 code = 0; -#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - size_t bufferSize; +#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + size_t bufferSize; #else /* AFS_SGI61_ENV */ - u_int bufferSize; + u_int bufferSize; #endif /* AFS_SGI61_ENV */ AFS_STATCNT(afs_syscall_call); #ifdef AFS_SUN5_ENV - if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU) + if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) { - /* only root can run this code */ + /* only root can run this code */ return (EACCES); #else if (!afs_suser() && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) { - /* only root can run this code */ -#if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) + /* only root can run this code */ +#if defined(KERNEL_HAVE_UERROR) setuerror(EACCES); - return(EACCES); + return (EACCES); #else -#if defined(AFS_OSF_ENV) +#if defined(AFS_OSF_ENV) return EACCES; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ return EPERM; -#endif +#endif /* AFS_OSF_ENV */ #endif #endif } AFS_GLOCK(); #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS) && !defined(UKERNEL) if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON - || parm == AFSOP_RXLISTENER_DAEMON) { - afs_DaemonOp(parm,parm2,parm3,parm4,parm5,parm6); + || parm == AFSOP_RXLISTENER_DAEMON) { + afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6); } -#else +#else /* !(AFS_LINUX24_ENV && !UKERNEL) */ if (parm == AFSOP_START_RXCALLBACK) { - if (afs_CB_Running) goto out; + if (afs_CB_Running) + goto out; afs_CB_Running = 1; #ifndef RXK_LISTENER_ENV code = afs_InitSetup(parm2); - if (!code) -#endif /* RXK_LISTENER_ENV */ - { + if (!code) +#endif /* !RXK_LISTENER_ENV */ + { #ifdef RXK_LISTENER_ENV - while (afs_RX_Running != 2) - afs_osi_Sleep(&afs_RX_Running); -#else - afs_initState = AFSOP_START_AFS; - afs_osi_Wakeup(&afs_initState); + while (afs_RX_Running != 2) + afs_osi_Sleep(&afs_RX_Running); +#else /* !RXK_LISTENER_ENV */ + afs_initState = AFSOP_START_AFS; + afs_osi_Wakeup(&afs_initState); #endif /* RXK_LISTENER_ENV */ - afs_osi_Invisible(); - afs_RXCallBackServer(); - } -#ifdef AFS_SGI_ENV + afs_osi_Invisible(); + afs_RXCallBackServer(); + } +#ifdef AFS_SGI_ENV AFS_GUNLOCK(); exit(CLD_EXITED, code); -#endif +#endif /* AFS_SGI_ENV */ } #ifdef RXK_LISTENER_ENV else if (parm == AFSOP_RXLISTENER_DAEMON) { - if (afs_RX_Running) goto out; + if (afs_RX_Running) + goto out; afs_RX_Running = 1; code = afs_InitSetup(parm2); if (parm3) { @@ -379,20 +420,21 @@ long parm, parm2, parm3, parm4, parm5, parm6; afs_osi_Wakeup(&afs_RX_Running); #ifndef UKERNEL afs_osi_RxkRegister(); -#endif +#endif /* !UKERNEL */ rxk_Listener(); } #ifdef AFS_SGI_ENV AFS_GUNLOCK(); exit(CLD_EXITED, code); -#endif +#endif /* AFS_SGI_ENV */ } -#endif +#endif /* RXK_LISTENER_ENV */ else if (parm == AFSOP_START_AFS) { /* afs daemon */ - if (AFS_Running) goto out; + if (AFS_Running) + goto out; AFS_Running = 1; - while (afs_initState < AFSOP_START_AFS) + while (afs_initState < AFSOP_START_AFS) afs_osi_Sleep(&afs_initState); afs_initState = AFSOP_START_BKG; @@ -402,18 +444,16 @@ long parm, parm2, parm3, parm4, parm5, parm6; #ifdef AFS_SGI_ENV AFS_GUNLOCK(); exit(CLD_EXITED, 0); -#endif - } - else if (parm == AFSOP_START_CS) { +#endif /* AFS_SGI_ENV */ + } else if (parm == AFSOP_START_CS) { afs_osi_Invisible(); afs_CheckServerDaemon(); #ifdef AFS_SGI_ENV AFS_GUNLOCK(); exit(CLD_EXITED, 0); -#endif - } - else if (parm == AFSOP_START_BKG) { - while (afs_initState < AFSOP_START_BKG) +#endif /* AFS_SGI_ENV */ + } else if (parm == AFSOP_START_BKG) { + while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState); if (afs_initState < AFSOP_GO) { afs_initState = AFSOP_GO; @@ -421,19 +461,18 @@ long parm, parm2, parm3, parm4, parm5, parm6; } /* start the bkg daemon */ afs_osi_Invisible(); -#ifdef AFS_AIX32_ENV +#ifdef AFS_AIX32_ENV if (parm2) afs_BioDaemon(parm2); else -#endif +#endif /* AFS_AIX32_ENV */ afs_BackgroundDaemon(); #ifdef AFS_SGI_ENV AFS_GUNLOCK(); exit(CLD_EXITED, 0); -#endif - } - else if (parm == AFSOP_START_TRUNCDAEMON) { - while (afs_initState < AFSOP_GO) +#endif /* AFS_SGI_ENV */ + } else if (parm == AFSOP_START_TRUNCDAEMON) { + while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState); /* start the bkg daemon */ afs_osi_Invisible(); @@ -441,87 +480,94 @@ long parm, parm2, parm3, parm4, parm5, parm6; #ifdef AFS_SGI_ENV AFS_GUNLOCK(); exit(CLD_EXITED, 0); -#endif +#endif /* AFS_SGI_ENV */ } #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) else if (parm == AFSOP_RXEVENT_DAEMON) { - while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState); + while (afs_initState < AFSOP_START_BKG) + afs_osi_Sleep(&afs_initState); afs_osi_Invisible(); afs_rxevent_daemon(); #ifdef AFS_SGI_ENV AFS_GUNLOCK(); exit(CLD_EXITED, 0); -#endif +#endif /* AFS_SGI_ENV */ } -#endif -#endif +#endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */ +#endif /* AFS_LINUX24_ENV && !UKERNEL */ else if (parm == AFSOP_BASIC_INIT) { afs_int32 temp; while (!afs_InitSetup_done) afs_osi_Sleep(&afs_InitSetup_done); -#if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - temp = AFS_MINBUFFERS; /* Should fix this soon */ +#if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + temp = AFS_MINBUFFERS; /* Should fix this soon */ #else /* number of 2k buffers we could get from all of the buffer space */ - temp = ((afs_bufferpages * NBPG)>>11); - temp = temp>>2; /* don't take more than 25% (our magic parameter) */ + temp = ((afs_bufferpages * NBPG) >> 11); + temp = temp >> 2; /* don't take more than 25% (our magic parameter) */ if (temp < AFS_MINBUFFERS) - temp = AFS_MINBUFFERS; /* though we really should have this many */ + temp = AFS_MINBUFFERS; /* though we really should have this many */ #endif DInit(temp); afs_rootFid.Fid.Volume = 0; code = 0; - } - else if (parm == AFSOP_ADDCELL) { + } else if (parm == AFSOP_ADDCELL) { /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated - name. Parameter 4 is the length of the name, including the null. Parm 5 is the - home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */ - struct afsop_cell tcell; + * name. Parameter 4 is the length of the name, including the null. Parm 5 is the + * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */ + struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell)); - AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code); + AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts), + code); if (!code) { - if (parm4 > sizeof(tcell.cellName)) + if (parm4 > sizeof(tcell->cellName)) code = EFAULT; else { - AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code); - if (!code) - afs_NewCell(tcell.cellName, tcell.hosts, parm5, - NULL, 0, 0, 0); + AFS_COPYIN((char *)parm3, tcell->cellName, parm4, code); + if (!code) + afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0, + 0, 0); } } + afs_osi_Free(tcell, sizeof(struct afsop_cell)); } else if (parm == AFSOP_ADDCELL2) { - struct afsop_cell tcell; + struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell)); char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0; - char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *cnamep = 0; + char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ); int cflags = parm4; #if 0 /* wait for basic init - XXX can't find any reason we need this? */ - while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState); + while (afs_initState < AFSOP_START_BKG) + afs_osi_Sleep(&afs_initState); #endif - AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code); + AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts), + code); if (!code) { - AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code); + AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, + &bufferSize, code); if (!code) { if (parm4 & 4) { - AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code); + AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, + &bufferSize, code); if (!code) { lcnamep = tbuffer; cflags |= CLinkedCell; } } if (!code) - afs_NewCell(tbuffer1, tcell.hosts, cflags, - lcnamep, 0, 0, 0); + code = + afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep, + 0, 0, 0); } } + afs_osi_Free(tcell, sizeof(struct afsop_cell)); osi_FreeSmallSpace(tbuffer); osi_FreeSmallSpace(tbuffer1); - } - else if (parm == AFSOP_ADDCELLALIAS) { + } else if (parm == AFSOP_ADDCELLALIAS) { /* * Call arguments: * parm2 is the alias name @@ -530,103 +576,98 @@ long parm, parm2, parm3, parm4, parm5, parm6; char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ); char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ); - AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, code); - if (!code) AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, &bufferSize, code); - if (!code) afs_NewCellAlias(aliasName, cellName); - + AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, + code); + if (!code) + AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, + &bufferSize, code); + if (!code) + afs_NewCellAlias(aliasName, cellName); osi_FreeSmallSpace(aliasName); osi_FreeSmallSpace(cellName); - } - else if (parm == AFSOP_SET_THISCELL) { + } else if (parm == AFSOP_SET_THISCELL) { /* * Call arguments: * parm2 is the primary cell name */ char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ); - AFS_COPYINSTR((char *) parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code); + AFS_COPYINSTR((char *)parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code); if (!code) afs_SetPrimaryCell(cell); osi_FreeSmallSpace(cell); - } - else if (parm == AFSOP_CACHEINIT) { + } else if (parm == AFSOP_CACHEINIT) { struct afs_cacheParams cparms; - if (afs_CacheInit_Done) goto out; + if (afs_CacheInit_Done) + goto out; - AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code); + AFS_COPYIN((char *)parm2, (caddr_t) & cparms, sizeof(cparms), code); if (code) { -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined (AFS_SGI64_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - goto out; -#else +#if defined(KERNEL_HAVE_UERROR) setuerror(code); code = -1; - goto out; #endif + goto out; } afs_CacheInit_Done = 1; - { - struct afs_icl_log *logp; - /* initialize the ICL system */ - code = afs_icl_CreateLog("cmfx", 60*1024, &logp); - if (code == 0) - code = afs_icl_CreateSetWithFlags("cm", logp, - (struct icl_log *) 0, - ICL_CRSET_FLAG_DEFAULT_OFF, - &afs_iclSetp); - code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0, - &afs_iclLongTermSetp); - } + { + struct afs_icl_log *logp; + /* initialize the ICL system */ + code = afs_icl_CreateLog("cmfx", 60 * 1024, &logp); + if (code == 0) + code = + afs_icl_CreateSetWithFlags("cm", logp, NULL, + ICL_CRSET_FLAG_DEFAULT_OFF, + &afs_iclSetp); + code = + afs_icl_CreateSet("cmlongterm", logp, NULL, + &afs_iclLongTermSetp); + } afs_setTime = cparms.setTimeFlag; - code = afs_CacheInit(cparms.cacheScaches, - cparms.cacheFiles, - cparms.cacheBlocks, - cparms.cacheDcaches, - cparms.cacheVolumes, - cparms.chunkSize, - cparms.memCacheFlag, - cparms.inodes, - cparms.users); + code = + afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles, + cparms.cacheBlocks, cparms.cacheDcaches, + cparms.cacheVolumes, cparms.chunkSize, + cparms.memCacheFlag, cparms.inodes, cparms.users); - } - else if (parm == AFSOP_CACHEINODE) { + } else if (parm == AFSOP_CACHEINODE) { ino_t ainode = parm2; /* wait for basic init */ - while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState); + while (afs_initState < AFSOP_START_BKG) + afs_osi_Sleep(&afs_initState); /* do it by inode */ #ifdef AFS_SGI62_ENV ainode = (ainode << 32) | (parm3 & 0xffffffff); #endif - code = afs_InitCacheFile((char *) 0, ainode); - } - else if (parm == AFSOP_ROOTVOLUME) { + code = afs_InitCacheFile(NULL, ainode); + } else if (parm == AFSOP_ROOTVOLUME) { /* wait for basic init */ - while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState); + while (afs_initState < AFSOP_START_BKG) + afs_osi_Sleep(&afs_initState); if (parm2) { - AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code); - afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0; - } - else code = 0; - } - else if (parm == AFSOP_CACHEFILE || - parm == AFSOP_CACHEINFO || - parm == AFSOP_VOLUMEINFO || - parm == AFSOP_AFSLOG || - parm == AFSOP_CELLINFO) { + AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, + sizeof(afs_rootVolumeName), &bufferSize, code); + afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0; + } else + code = 0; + } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO + || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG + || parm == AFSOP_CELLINFO) { char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ); code = 0; - AFS_COPYINSTR((char *) parm2, tbuffer, AFS_SMALLOCSIZ, - &bufferSize, code); + AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize, + code); if (code) { osi_FreeSmallSpace(tbuffer); goto out; } if (!code) { - tbuffer[AFS_SMALLOCSIZ-1] = '\0'; /* null-terminate the name */ + tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */ /* We have the cache dir copied in. Call the cache init routine */ if (parm == AFSOP_CACHEFILE) code = afs_InitCacheFile(tbuffer, 0); @@ -638,85 +679,95 @@ long parm, parm2, parm3, parm4, parm5, parm6; code = afs_InitCellInfo(tbuffer); } osi_FreeSmallSpace(tbuffer); - } - else if (parm == AFSOP_GO) { + } else if (parm == AFSOP_GO) { /* the generic initialization calls come here. One parameter: should we do the - set-time operation on this workstation */ - if (afs_Go_Done) goto out; + * set-time operation on this workstation */ + if (afs_Go_Done) + goto out; afs_Go_Done = 1; - while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState); + while (afs_initState < AFSOP_GO) + afs_osi_Sleep(&afs_initState); afs_initState = 101; afs_setTime = parm2; afs_osi_Wakeup(&afs_initState); #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV) afs_nfsclient_init(); #endif - printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused, - (100*afs_stats_cmperf.cacheFilesReused) / - (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1)); - } - else if (parm == AFSOP_ADVISEADDR) { + printf("found %d non-empty cache files (%d%%).\n", + afs_stats_cmperf.cacheFilesReused, + (100 * afs_stats_cmperf.cacheFilesReused) / + (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf. + cacheNumEntries : 1)); + } else if (parm == AFSOP_ADVISEADDR) { /* pass in the host address to the rx package */ - afs_int32 count = parm2; - afs_int32 buffer[AFS_MAX_INTERFACE_ADDR]; - afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR]; - afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR]; - int i; - int code; - - if ( count > AFS_MAX_INTERFACE_ADDR ) { - code = ENOMEM; - count = AFS_MAX_INTERFACE_ADDR; + afs_int32 count = parm2; + afs_int32 *buffer = + afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); + afs_int32 *maskbuffer = + afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); + afs_int32 *mtubuffer = + afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); + int i; + int code; + + if (count > AFS_MAX_INTERFACE_ADDR) { + code = ENOMEM; + count = AFS_MAX_INTERFACE_ADDR; } - - AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code); + + AFS_COPYIN((char *)parm3, (char *)buffer, count * sizeof(afs_int32), + code); if (parm4) - AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code); + AFS_COPYIN((char *)parm4, (char *)maskbuffer, + count * sizeof(afs_int32), code); if (parm5) - AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code); + AFS_COPYIN((char *)parm5, (char *)mtubuffer, + count * sizeof(afs_int32), code); afs_cb_interface.numberOfInterfaces = count; - for (i=0; i < count ; i++) { - afs_cb_interface.addr_in[i] = buffer[i]; -#ifdef AFS_USERSPACE_IP_ADDR - /* AFS_USERSPACE_IP_ADDR means we have no way of finding the - * machines IP addresses when in the kernel (the in_ifaddr - * struct is not available), so we pass the info in at - * startup. We also pass in the subnetmask and mtu size. The - * subnetmask is used when setting the rank: - * afsi_SetServerIPRank(); and the mtu size is used when - * finding the best mtu size. rxi_FindIfnet() is replaced - * with rxi_Findcbi(). - */ - afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff); - afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500)); + for (i = 0; i < count; i++) { + afs_cb_interface.addr_in[i] = buffer[i]; +#ifdef AFS_USERSPACE_IP_ADDR + /* AFS_USERSPACE_IP_ADDR means we have no way of finding the + * machines IP addresses when in the kernel (the in_ifaddr + * struct is not available), so we pass the info in at + * startup. We also pass in the subnetmask and mtu size. The + * subnetmask is used when setting the rank: + * afsi_SetServerIPRank(); and the mtu size is used when + * finding the best mtu size. rxi_FindIfnet() is replaced + * with rxi_Findcbi(). + */ + afs_cb_interface.subnetmask[i] = + (parm4 ? maskbuffer[i] : 0xffffffff); + afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500)); #endif } afs_uuid_create(&afs_cb_interface.uuid); rxi_setaddr(buffer[0]); + afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); + afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); + afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR); } - #ifdef AFS_SGI53_ENV else if (parm == AFSOP_NFSSTATICADDR) { - extern int (*nfs_rfsdisptab_v2)(); + extern int (*nfs_rfsdisptab_v2) (); nfs_rfsdisptab_v2 = (int (*)())parm2; - } - else if (parm == AFSOP_NFSSTATICADDR2) { - extern int (*nfs_rfsdisptab_v2)(); + } else if (parm == AFSOP_NFSSTATICADDR2) { + extern int (*nfs_rfsdisptab_v2) (); #ifdef _K64U64 - nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff)); + nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff)); #else /* _K64U64 */ nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff); #endif /* _K64U64 */ } #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV) else if (parm == AFSOP_SBLOCKSTATICADDR2) { - extern int (*afs_sblockp)(); - extern void (*afs_sbunlockp)(); + extern int (*afs_sblockp) (); + extern void (*afs_sbunlockp) (); #ifdef _K64U64 - afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff)); - afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff)); -#else + afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff)); + afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff)); +#else afs_sblockp = (int (*)())(parm3 & 0xffffffff); afs_sbunlockp = (void (*)())(parm5 & 0xffffffff); #endif /* _K64U64 */ @@ -724,60 +775,45 @@ long parm, parm2, parm3, parm4, parm5, parm6; #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */ #endif /* AFS_SGI53_ENV */ else if (parm == AFSOP_SHUTDOWN) { -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - extern struct mount *afs_globalVFS; -#else /* AFS_OSF_ENV */ - extern struct vfs *afs_globalVFS; -#endif afs_cold_shutdown = 0; - if (parm == 1) afs_cold_shutdown = 1; + if (parm == 1) + afs_cold_shutdown = 1; #ifndef AFS_DARWIN_ENV - if (afs_globalVFS != 0) { + if (afs_globalVFS != 0) { afs_warn("AFS isn't unmounted yet! Call aborted\n"); - code = EACCES; - } else + code = EACCES; + } else #endif - afs_shutdown(); - } - -#if ! defined(AFS_HPUX90_ENV) || defined(AFS_HPUX100_ENV) - else if (parm == AFSOP_AFS_VFSMOUNT) { + afs_shutdown(); + } else if (parm == AFSOP_AFS_VFSMOUNT) { #ifdef AFS_HPUX_ENV -#if defined(AFS_HPUX100_ENV) vfsmount(parm2, parm3, parm4, parm5); -#else - afs_vfs_mount(parm2, parm3, parm4, parm5); -#endif /* AFS_HPUX100_ENV */ #else /* defined(AFS_HPUX_ENV) */ -#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - code = EINVAL; +#if defined(KERNEL_HAVE_UERROR) + setuerror(EINVAL); #else - setuerror(EINVAL); + code = EINVAL; #endif #endif /* defined(AFS_HPUX_ENV) */ - } -#endif - else if (parm == AFSOP_CLOSEWAIT) { + } else if (parm == AFSOP_CLOSEWAIT) { afs_SynchronousCloses = 'S'; - } - else if (parm == AFSOP_GETMTU) { - afs_uint32 mtu = 0; + } else if (parm == AFSOP_GETMTU) { + afs_uint32 mtu = 0; #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) #ifdef AFS_USERSPACE_IP_ADDR - afs_int32 i; - i = rxi_Findcbi(parm2); - mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]); + afs_int32 i; + i = rxi_Findcbi(parm2); + mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]); #else /* AFS_USERSPACE_IP_ADDR */ - struct ifnet *tifnp; - struct in_ifaddr *tifadp = (struct in_ifaddr *) 0; - extern struct ifnet *rxi_FindIfnet(); - - tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */ - mtu = (tifnp ? tifnp->if_mtu : htonl(1500)); + struct ifnet *tifnp; + + tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */ + mtu = (tifnp ? tifnp->if_mtu : htonl(1500)); #endif /* else AFS_USERSPACE_IP_ADDR */ #endif /* !AFS_SUN5_ENV */ - if (!code) - AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code); + if (!code) + AFS_COPYOUT((caddr_t) & mtu, (caddr_t) parm3, sizeof(afs_int32), + code); #ifdef AFS_AIX32_ENV /* this is disabled for now because I can't figure out how to get access * to these kernel variables. It's only for supporting user-mode rx @@ -794,40 +830,28 @@ long parm, parm2, parm3, parm4, parm5, parm6; } } */ #endif /* AFS_AIX32_ENV */ - } - else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */ - afs_uint32 mask = 0; + } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */ + afs_uint32 mask = 0; #if !defined(AFS_SUN5_ENV) #ifdef AFS_USERSPACE_IP_ADDR - afs_int32 i; - i = rxi_Findcbi(parm2); - if (i != -1) { - mask = afs_cb_interface.subnetmask[i]; - } else { - code = -1; - } + afs_int32 i; + i = rxi_Findcbi(parm2); + if (i != -1) { + mask = afs_cb_interface.subnetmask[i]; + } else { + code = -1; + } #else /* AFS_USERSPACE_IP_ADDR */ - struct ifnet *tifnp; -#ifdef AFS_DARWIN60_ENV - struct ifaddr *tifadp = (struct ifaddr *) 0; -#else - struct in_ifaddr *tifadp = (struct in_ifaddr *) 0; -#endif - extern struct ifnet *rxi_FindIfnet(); - tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */ - if (tifnp && tifadp) { -#ifdef AFS_DARWIN60_ENV - mask = ((struct sockaddr_in *)tifadp->ifa_netmask)->sin_addr.s_addr; -#else - mask = tifadp->ia_subnetmask; -#endif - } else { - code = -1; - } + struct ifnet *tifnp; + + tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */ + if (!tifnp) + code = -1; #endif /* else AFS_USERSPACE_IP_ADDR */ #endif /* !AFS_SUN5_ENV */ - if (!code) - AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code); + if (!code) + AFS_COPYOUT((caddr_t) & mask, (caddr_t) parm3, sizeof(afs_int32), + code); } #ifdef AFS_AFSDB_ENV else if (parm == AFSOP_AFSDB_HANDLER) { @@ -840,37 +864,39 @@ long parm, parm2, parm3, parm4, parm5, parm6; #ifndef UKERNEL afs_osi_MaskSignals(); #endif - AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code); - AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code); + AFS_COPYIN((afs_int32 *) parm2, cellname, cellLen, code); + AFS_COPYIN((afs_int32 *) parm3, kmsg, kmsgLen, code); if (!code) { code = afs_AFSDBHandler(cellname, cellLen, kmsg); - if (*cellname == 1) *cellname = 0; + if (*cellname == 1) + *cellname = 0; if (code == -2) { /* Shutting down? */ *cellname = 1; code = 0; } } - if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code); + if (!code) + AFS_COPYOUT(cellname, (char *)parm2, cellLen, code); afs_osi_Free(kmsg, kmsgLen); afs_osi_Free(cellname, cellLen); } #endif else if (parm == AFSOP_SET_DYNROOT) { code = afs_SetDynrootEnable(parm2); - } - else if (parm == AFSOP_SET_FAKESTAT) { - afs_fakestat_enable = parm2; - code = 0; - } - else - code = EINVAL; + } else if (parm == AFSOP_SET_FAKESTAT) { + afs_fakestat_enable = parm2; + code = 0; + } else if (parm == AFSOP_SET_BACKUPTREE) { + afs_bkvolpref = parm2; + } else + code = EINVAL; -out: - AFS_GUNLOCK(); + out: + AFS_GUNLOCK(); #ifdef AFS_LINUX20_ENV - return -code; + return -code; #else - return code; + return code; #endif } @@ -885,76 +911,80 @@ out: * THIS SHOULD BE CHANGED TO afs_syscall(), but requires * all the user-level calls to `syscall' to change. */ -syscall(syscall, p1, p2, p3, p4, p5, p6) { - register rval1=0, code; - register monster; - int retval=0; +syscall(syscall, p1, p2, p3, p4, p5, p6) +{ + register rval1 = 0, code; + register monster; + int retval = 0; #ifndef AFS_AIX41_ENV - extern lock_t kernel_lock; - monster = lockl(&kernel_lock, LOCK_SHORT); + extern lock_t kernel_lock; + monster = lockl(&kernel_lock, LOCK_SHORT); #endif /* !AFS_AIX41_ENV */ - AFS_STATCNT(syscall); - setuerror(0); - switch (syscall) { - case AFSCALL_CALL: - rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6); - break; + AFS_STATCNT(syscall); + setuerror(0); + switch (syscall) { + case AFSCALL_CALL: + rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6); + break; - case AFSCALL_SETPAG: - AFS_GLOCK(); - rval1 = afs_setpag(); - AFS_GUNLOCK(); - break; + case AFSCALL_SETPAG: + AFS_GLOCK(); + rval1 = afs_setpag(); + AFS_GUNLOCK(); + break; - case AFSCALL_PIOCTL: - AFS_GLOCK(); - rval1 = afs_syscall_pioctl(p1, p2, p3, p4); - AFS_GUNLOCK(); - break; + case AFSCALL_PIOCTL: + AFS_GLOCK(); + rval1 = afs_syscall_pioctl(p1, p2, p3, p4); + AFS_GUNLOCK(); + break; - case AFSCALL_ICREATE: - rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6); - break; + case AFSCALL_ICREATE: + rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6); + break; - case AFSCALL_IOPEN: - rval1 = afs_syscall_iopen(p1, p2, p3); - break; + case AFSCALL_IOPEN: + rval1 = afs_syscall_iopen(p1, p2, p3); + break; - case AFSCALL_IDEC: - rval1 = afs_syscall_iincdec(p1, p2, p3, -1); - break; + case AFSCALL_IDEC: + rval1 = afs_syscall_iincdec(p1, p2, p3, -1); + break; - case AFSCALL_IINC: - rval1 = afs_syscall_iincdec(p1, p2, p3, 1); - break; + case AFSCALL_IINC: + rval1 = afs_syscall_iincdec(p1, p2, p3, 1); + break; - case AFSCALL_ICL: - AFS_GLOCK(); - code = Afscall_icl(p1, p2, p3, p4, p5, &retval); - AFS_GUNLOCK(); - if (!code) rval1 = retval; - if (!rval1) rval1 = code; - break; + case AFSCALL_ICL: + AFS_GLOCK(); + code = Afscall_icl(p1, p2, p3, p4, p5, &retval); + AFS_GUNLOCK(); + if (!code) + rval1 = retval; + if (!rval1) + rval1 = code; + break; - default: - rval1 = EINVAL; - setuerror(EINVAL); - break; - } + default: + rval1 = EINVAL; + setuerror(EINVAL); + break; + } - out: + out: #ifndef AFS_AIX41_ENV - if (monster != LOCK_NEST) - unlockl(&kernel_lock); + if (monster != LOCK_NEST) + unlockl(&kernel_lock); #endif /* !AFS_AIX41_ENV */ - return getuerror() ? -1 : rval1; + return getuerror()? -1 : rval1; } /* * lsetpag - interface to afs_setpag(). */ -lsetpag() { +lsetpag() +{ AFS_STATCNT(lsetpag); return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0); @@ -964,57 +994,63 @@ lsetpag() { * lpioctl - interface to pioctl() */ lpioctl(path, cmd, cmarg, follow) -char *path, *cmarg; { + char *path, *cmarg; +{ AFS_STATCNT(lpioctl); return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow); } -#else /* !AFS_AIX32_ENV */ +#else /* !AFS_AIX32_ENV */ #if defined(AFS_SGI_ENV) -struct afsargs -{ - sysarg_t syscall; - sysarg_t parm1; - sysarg_t parm2; - sysarg_t parm3; - sysarg_t parm4; - sysarg_t parm5; +struct afsargs { + sysarg_t syscall; + sysarg_t parm1; + sysarg_t parm2; + sysarg_t parm3; + sysarg_t parm4; + sysarg_t parm5; }; int -Afs_syscall (struct afsargs *uap, rval_t *rvp) +Afs_syscall(struct afsargs *uap, rval_t * rvp) { int error; long retval; AFS_STATCNT(afs_syscall); - switch(uap->syscall) { + switch (uap->syscall) { case AFSCALL_ICL: retval = 0; AFS_GLOCK(); - error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval); + error = + Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + uap->parm5, &retval); AFS_GUNLOCK(); rvp->r_val1 = retval; break; #ifdef AFS_SGI_XFS_IOPS_ENV case AFSCALL_IDEC64: - error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3, - uap->parm4, uap->parm5); + error = + afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + uap->parm5); break; case AFSCALL_IINC64: - error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3, - uap->parm4, uap->parm5); + error = + afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + uap->parm5); break; case AFSCALL_ILISTINODE64: - error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3, - uap->parm4, uap->parm5); + error = + afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3, + uap->parm4, uap->parm5); break; case AFSCALL_ICREATENAME64: - error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3, - uap->parm4, uap->parm5); + error = + afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3, + uap->parm4, uap->parm5); break; #endif #ifdef AFS_SGI_VNODE_GLUE @@ -1023,8 +1059,9 @@ Afs_syscall (struct afsargs *uap, rval_t *rvp) break; #endif default: - error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2, - uap->parm3, uap->parm4, uap->parm5); + error = + afs_syscall_call(uap->syscall, uap->parm1, uap->parm2, uap->parm3, + uap->parm4, uap->parm5); } return error; } @@ -1049,10 +1086,10 @@ struct iparam32 { static void iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst) { - dst->param1 = src->param1; - dst->param2 = src->param2; - dst->param3 = src->param3; - dst->param4 = src->param4; + dst->param1 = src->param1; + dst->param2 = src->param2; + dst->param3 = src->param3; + dst->param4 = src->param4; } /* @@ -1063,53 +1100,54 @@ iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst) static int copyin_iparam(caddr_t cmarg, struct iparam *dst) { - int code; + int code; #if defined(AFS_HPUX_64BIT_ENV) - struct iparam32 dst32; + struct iparam32 dst32; - if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */ - { - AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code); - if (!code) - iparam32_to_iparam(&dst32, dst); - return code; - } + if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */ + AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code); + if (!code) + iparam32_to_iparam(&dst32, dst); + return code; + } #endif /* AFS_HPUX_64BIT_ENV */ #if defined(AFS_SUN57_64BIT_ENV) - struct iparam32 dst32; + struct iparam32 dst32; - if (get_udatamodel() == DATAMODEL_ILP32) { - AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code); - if (!code) - iparam32_to_iparam(&dst32, dst); - return code; - } + if (get_udatamodel() == DATAMODEL_ILP32) { + AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code); + if (!code) + iparam32_to_iparam(&dst32, dst); + return code; + } #endif /* AFS_SUN57_64BIT_ENV */ -#if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) - struct iparam32 dst32; +#if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV) + struct iparam32 dst32; #ifdef AFS_SPARC64_LINUX24_ENV - if (current->thread.flags & SPARC_FLAG_32BIT) + if (current->thread.flags & SPARC_FLAG_32BIT) #elif defined(AFS_SPARC64_LINUX20_ENV) - if (current->tss.flags & SPARC_FLAG_32BIT) + if (current->tss.flags & SPARC_FLAG_32BIT) #elif defined(AFS_AMD64_LINUX20_ENV) - if (current->thread.flags & THREAD_IA32) + if (current->thread.flags & THREAD_IA32) +#elif defined(AFS_PPC64_LINUX20_ENV) + if (current->thread.flags & PPC_FLAG_32BIT) #else #error Not done for this linux version -#endif - { - AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code); - if (!code) - iparam32_to_iparam(&dst32, dst); - return code; - } +#endif + { + AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code); + if (!code) + iparam32_to_iparam(&dst32, dst); + return code; + } #endif /* AFS_LINUX_64BIT_KERNEL */ - AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code); - return code; + AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code); + return code; } /* Main entry of all afs system calls */ @@ -1143,28 +1181,31 @@ struct afssysa { }; #endif -Afs_syscall (uap, rvp) - register struct afssysa *uap; - rval_t *rvp; +Afs_syscall(register struct afssysa *uap, rval_t * rvp) { int *retval = &rvp->r_val1; #else /* AFS_SUN5_ENV */ -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) +int afs3_syscall(p, args, retval) - struct proc *p; - void *args; - int *retval; +#ifdef AFS_FBSD50_ENV + struct thread *p; +#else + struct proc *p; +#endif + void *args; + int *retval; { register struct a { - long syscall; - long parm1; - long parm2; - long parm3; - long parm4; - long parm5; - long parm6; - } *uap = (struct a *)args; -#else /* AFS_OSF_ENV */ + long syscall; + long parm1; + long parm2; + long parm3; + long parm4; + long parm5; + long parm6; + } *uap = (struct a *)args; +#else /* AFS_OSF_ENV */ #ifdef AFS_LINUX20_ENV struct afssysargs { long syscall; @@ -1173,59 +1214,58 @@ struct afssysargs { long parm3; long parm4; long parm5; - long parm6; /* not actually used - should be removed */ + long parm6; /* not actually used - should be removed */ }; /* Linux system calls only set up for 5 arguments. */ -asmlinkage long afs_syscall(long syscall, long parm1, long parm2, long parm3, - long parm4) +asmlinkage long +afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4) { struct afssysargs args, *uap = &args; - long linux_ret=0; + long linux_ret = 0; long *retval = &linux_ret; - long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */ + long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */ #ifdef AFS_SPARC64_LINUX24_ENV afs_int32 eparm32[4]; #endif /* eparm is also used by AFSCALL_CALL in afsd.c */ #else #if defined(UKERNEL) -Afs_syscall () +Afs_syscall() { register struct a { - long syscall; - long parm1; - long parm2; - long parm3; - long parm4; - long parm5; - long parm6; - } *uap = (struct a *)u.u_ap; + long syscall; + long parm1; + long parm2; + long parm3; + long parm4; + long parm5; + long parm6; + } *uap = (struct a *)u.u_ap; #else /* UKERNEL */ +int #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV) -afs_syscall () +afs_syscall() #else -Afs_syscall () -#endif /* SUN && !SUN5 */ +Afs_syscall() +#endif /* SUN && !SUN5 */ { register struct a { - long syscall; - long parm1; - long parm2; - long parm3; - long parm4; - long parm5; - long parm6; - } *uap = (struct a *)u.u_ap; + long syscall; + long parm1; + long parm2; + long parm3; + long parm4; + long parm5; + long parm6; + } *uap = (struct a *)u.u_ap; #endif /* UKERNEL */ #if defined(AFS_DEC_ENV) int *retval = &u.u_r.r_val1; -#else -#if defined(AFS_HPUX_ENV) +#elif defined(AFS_HPUX_ENV) long *retval = &u.u_rval1; #else int *retval = &u.u_rval1; #endif -#endif #endif /* AFS_LINUX20_ENV */ #endif /* AFS_OSF_ENV */ #endif /* AFS_SUN5_ENV */ @@ -1260,19 +1300,18 @@ Afs_syscall () if (current->thread.flags & SPARC_FLAG_32BIT) { - AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code); - eparm[0]=AA(eparm32[0]); - eparm[1]=AA(eparm32[1]); - eparm[2]=AA(eparm32[2]); + AFS_COPYIN((char *)parm4, (char *)eparm32, sizeof(eparm32), code); + eparm[0] = AA(eparm32[0]); + eparm[1] = AA(eparm32[1]); + eparm[2] = AA(eparm32[2]); #undef AA -} else + } else #endif - AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code); + AFS_COPYIN((char *)parm4, (char *)eparm, sizeof(eparm), code); uap->parm4 = eparm[0]; uap->parm5 = eparm[1]; uap->parm6 = eparm[2]; - } - else { + } else { uap->parm4 = parm4; uap->parm5 = 0; uap->parm6 = 0; @@ -1290,10 +1329,13 @@ Afs_syscall () #endif if (uap->syscall == AFSCALL_CALL) { #ifdef AFS_SUN5_ENV - code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, - uap->parm4, uap->parm5, uap->parm6, rvp, CRED()); + code = + afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + uap->parm5, uap->parm6, rvp, CRED()); #else - code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6); + code = + afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + uap->parm5, uap->parm6); #endif } else if (uap->syscall == AFSCALL_SETPAG) { #ifdef AFS_SUN5_ENV @@ -1301,27 +1343,35 @@ Afs_syscall () procp = ttoproc(curthread); AFS_GLOCK(); - code = afs_setpag(&procp->p_cred); + code = afs_setpag(&procp->p_cred); AFS_GUNLOCK(); #else AFS_GLOCK(); -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) code = afs_setpag(p, args, retval); -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ code = afs_setpag(); #endif AFS_GUNLOCK(); #endif } else if (uap->syscall == AFSCALL_PIOCTL) { AFS_GLOCK(); -#ifdef AFS_SUN5_ENV - code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED()); -#else -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred); +#if defined(AFS_SUN5_ENV) + code = + afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + rvp, CRED()); +#elif defined(AFS_FBSD50_ENV) + code = + afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + p->td_ucred); +#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + code = + afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + p->p_cred->pc_ucred); #else - code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4); -#endif + code = + afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, + uap->parm4); #endif AFS_GUNLOCK(); } else if (uap->syscall == AFSCALL_ICREATE) { @@ -1329,67 +1379,79 @@ Afs_syscall () code = copyin_iparam((char *)uap->parm3, &iparams); if (code) { -#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if defined(KERNEL_HAVE_UERROR) setuerror(code); #endif } else #ifdef AFS_SUN5_ENV - code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2, - iparams.param3, iparams.param4, rvp, CRED()); + code = + afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, + iparams.param2, iparams.param3, + iparams.param4, rvp, CRED()); #else - code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2, -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - iparams.param3, iparams.param4, retval); + code = + afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, + iparams.param2, +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + iparams.param3, iparams.param4, retval); #else - iparams.param3, iparams.param4); + iparams.param3, iparams.param4); #endif -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ } else if (uap->syscall == AFSCALL_IOPEN) { #ifdef AFS_SUN5_ENV - code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED()); + code = + afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, + CRED()); #else -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval); #else code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3); #endif -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ } else if (uap->syscall == AFSCALL_IDEC) { #ifdef AFS_SUN5_ENV - code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED()); + code = + afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, + CRED()); #else code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1); -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ } else if (uap->syscall == AFSCALL_IINC) { #ifdef AFS_SUN5_ENV - code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED()); + code = + afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, + CRED()); #else code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1); -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ } else if (uap->syscall == AFSCALL_ICL) { AFS_GLOCK(); - code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval); + code = + Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, + uap->parm5, retval); AFS_GUNLOCK(); #ifdef AFS_LINUX20_ENV if (!code) { /* ICL commands can return values. */ - code = -linux_ret; /* Gets negated again at exit below */ + code = -linux_ret; /* Gets negated again at exit below */ } #else - if (code) { -#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) + if (code) { +#if defined(KERNEL_HAVE_UERROR) setuerror(code); #endif - } + } #endif /* !AFS_LINUX20_ENV */ } else { -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - code = EINVAL; +#if defined(KERNEL_HAVE_UERROR) + setuerror(EINVAL); #else - setuerror(EINVAL); -#endif /* AFS_SUN5_ENV */ + code = EINVAL; +#endif } -out: + #ifdef AFS_LINUX20_ENV code = -code; unlock_kernel(); @@ -1397,7 +1459,7 @@ out: return code; } #endif /* AFS_SGI_ENV */ -#endif /* !AFS_AIX32_ENV */ +#endif /* !AFS_AIX32_ENV */ /* * Initstate in the range 0 < x < 100 are early initialization states. @@ -1409,22 +1471,25 @@ out: * incorrectly. * Initstate of 300 means that the volume has been *successfully* looked up. */ -afs_CheckInit() { +int +afs_CheckInit(void) +{ register int code = 0; AFS_STATCNT(afs_CheckInit); if (afs_initState <= 100) - code = ENXIO; /* never finished init phase */ + code = ENXIO; /* never finished init phase */ else if (afs_initState == 101) { /* init done, wait for afs_daemon */ - while (afs_initState < 200) afs_osi_Sleep(&afs_initState); - } else if (afs_initState == 200) - code = ETIMEDOUT; /* didn't find root volume */ + while (afs_initState < 200) + afs_osi_Sleep(&afs_initState); + } else if (afs_initState == 200) + code = ETIMEDOUT; /* didn't find root volume */ return code; } -int afs_shuttingdown = 0; +int afs_shuttingdown = 0; void -afs_shutdown() +afs_shutdown(void) { extern short afs_brsDaemons; extern afs_int32 afs_CheckServerDaemonStarted; @@ -1432,11 +1497,14 @@ afs_shutdown() extern struct osi_file *afs_cacheInodep; AFS_STATCNT(afs_shutdown); - if (afs_shuttingdown) return; + if (afs_shuttingdown) + return; afs_shuttingdown = 1; - if (afs_cold_shutdown) afs_warn("COLD "); - else afs_warn("WARM "); - afs_warn("shutting down of: CB... "); + if (afs_cold_shutdown) + afs_warn("COLD "); + else + afs_warn("WARM "); + afs_warn("shutting down of: CB... "); afs_termState = AFSOP_STOP_RXCALLBACK; rx_WakeupServerProcs(); @@ -1464,7 +1532,7 @@ afs_shutdown() afs_warn("CTrunc... "); /* Cancel cache truncate daemon. */ while (afs_termState == AFSOP_STOP_TRUNCDAEMON) { - afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon); + afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon); afs_osi_Sleep(&afs_termState); } #ifdef AFS_AFSDB_ENV @@ -1475,38 +1543,40 @@ afs_shutdown() #endif #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) afs_warn("RxEvent... "); - /* cancel rx event deamon */ - while (afs_termState == AFSOP_STOP_RXEVENT) + /* cancel rx event daemon */ + while (afs_termState == AFSOP_STOP_RXEVENT) afs_osi_Sleep(&afs_termState); #if defined(RXK_LISTENER_ENV) - afs_warn("RxListener... "); #ifndef UKERNEL + afs_warn("UnmaskRxkSignals... "); afs_osi_UnmaskRxkSignals(); #endif /* cancel rx listener */ - osi_StopListener(); /* This closes rx_socket. */ - while (afs_termState == AFSOP_STOP_RXK_LISTENER) + afs_warn("RxListener... "); + osi_StopListener(); /* This closes rx_socket. */ + while (afs_termState == AFSOP_STOP_RXK_LISTENER) { + afs_warn("Sleep... "); afs_osi_Sleep(&afs_termState); + } #endif #else - afs_termState = AFSOP_STOP_COMPLETE; + afs_termState = AFSOP_STOP_COMPLETE; #endif afs_warn("\n"); /* Close file only after daemons which can write to it are stopped. */ - if (afs_cacheInodep) /* memcache won't set this */ - { - osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */ + if (afs_cacheInodep) { /* memcache won't set this */ + osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */ afs_cacheInodep = 0; } - return; /* Just kill daemons for now */ + return; /* Just kill daemons for now */ #ifdef notdef - shutdown_CB(); + shutdown_CB(); shutdown_AFS(); shutdown_rxkernel(); - shutdown_rxevent(); + shutdown_rxevent(); shutdown_rx(); - afs_shutdown_BKG(); + afs_shutdown_BKG(); shutdown_bufferpackage(); shutdown_daemons(); shutdown_cache(); @@ -1535,21 +1605,25 @@ afs_shutdown() #endif } -shutdown_afstest() +void +shutdown_afstest(void) { AFS_STATCNT(shutdown_afstest); afs_initState = afs_termState = afs_setTime = 0; AFS_Running = afs_CB_Running = 0; afs_CacheInit_Done = afs_Go_Done = 0; if (afs_cold_shutdown) { - *afs_rootVolumeName = 0; + *afs_rootVolumeName = 0; } } /* In case there is a bunch of dynamically build bkg daemons to free */ -afs_shutdown_BKG() -{ AFS_STATCNT(shutdown_BKG); } +void +afs_shutdown_BKG(void) +{ + AFS_STATCNT(shutdown_BKG); +} #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV) @@ -1560,13 +1634,18 @@ int afs_icl_sizeofLong = 1; int afs_icl_sizeofLong = 2; #endif /* SGI62 */ #else +#if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) +int afs_icl_sizeofLong = 2; +#else int afs_icl_sizeofLong = 1; #endif +#endif int afs_icl_inited = 0; /* init function, called once, under afs_icl_lock */ -afs_icl_Init() +int +afs_icl_Init(void) { afs_icl_inited = 1; return 0; @@ -1579,15 +1658,18 @@ extern struct afs_icl_set *afs_icl_FindSet(); static int Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval) { - register int i; afs_int32 *lp, elts, flags; register afs_int32 code; struct afs_icl_log *logp; struct afs_icl_set *setp; -#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) size_t temp; #else /* AFS_SGI61_ENV */ +#if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) + afs_uint64 temp; +#else afs_uint32 temp; +#endif #endif /* AFS_SGI61_ENV */ char tname[65]; afs_int32 startCookie; @@ -1599,8 +1681,8 @@ Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval) return (EACCES); } #else - if (!afs_suser()) { /* only root can run this code */ -#if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) + if (!afs_suser()) { /* only root can run this code */ +#if defined(KERNEL_HAVE_UERROR) setuerror(EACCES); return EACCES; #else @@ -1617,98 +1699,123 @@ Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval) * skip some records. */ AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code); - if (code) return code; + if (code) + return code; AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code); - if (code) return code; + if (code) + return code; logp = afs_icl_FindLog(tname); - if (!logp) return ENOENT; + if (!logp) + return ENOENT; #define BUFFERSIZE AFS_LRALLOCSIZ lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ); elts = BUFFERSIZE / sizeof(afs_int32); - if (p3 < elts) elts = p3; + if (p3 < elts) + elts = p3; flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD; - code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie, - &flags); + code = + afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) & startCookie, + &flags); if (code) { - osi_FreeLargeSpace((struct osi_buffer *) lp); + osi_FreeLargeSpace((struct osi_buffer *)lp); break; } AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code); - if (code) goto done; - AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code); - if (code) goto done; - *retval = (flags<<24) | (elts & 0xffffff); + if (code) + goto done; + AFS_COPYOUT((char *)&startCookie, (char *)p4, sizeof(afs_int32), + code); + if (code) + goto done; +#if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) + if (!(IS64U)) + *retval = ((long)((flags << 24) | (elts & 0xffffff))) << 32; + else +#endif + *retval = (flags << 24) | (elts & 0xffffff); done: afs_icl_LogRele(logp); - osi_FreeLargeSpace((struct osi_buffer *) lp); + osi_FreeLargeSpace((struct osi_buffer *)lp); break; case ICL_OP_ENUMLOGS: /* enumerate logs */ /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size. * return 0 for success, otherwise error. */ - for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) { - if (p1-- == 0) break; + for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) { + if (p1-- == 0) + break; } - if (!tlp) return ENOENT; /* past the end of file */ - temp = strlen(tlp->name)+1; - if (temp > p3) return EINVAL; - AFS_COPYOUT(tlp->name, (char *) p2, temp, code); - if (!code) /* copy out size of log */ - AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code); + if (!tlp) + return ENOENT; /* past the end of file */ + temp = strlen(tlp->name) + 1; + if (temp > p3) + return EINVAL; + AFS_COPYOUT(tlp->name, (char *)p2, temp, code); + if (!code) /* copy out size of log */ + AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof(afs_int32), + code); break; case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */ /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name). * return 0 for success, otherwise error. */ - AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code); - if (code) return code; + AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code); + if (code) + return code; setp = afs_icl_FindSet(tname); - if (!setp) return ENOENT; + if (!setp) + return ENOENT; if (p2 > ICL_LOGSPERSET) return EINVAL; if (!(tlp = setp->logs[p2])) return EBADF; - temp = strlen(tlp->name)+1; - if (temp > p4) return EINVAL; + temp = strlen(tlp->name) + 1; + if (temp > p4) + return EINVAL; AFS_COPYOUT(tlp->name, (char *)p3, temp, code); break; - case ICL_OP_CLRLOG: /* clear specified log */ + case ICL_OP_CLRLOG: /* clear specified log */ /* zero out the specified log: p1=logname */ - AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code); - if (code) return code; + AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code); + if (code) + return code; logp = afs_icl_FindLog(tname); - if (!logp) return ENOENT; + if (!logp) + return ENOENT; code = afs_icl_ZeroLog(logp); afs_icl_LogRele(logp); break; - case ICL_OP_CLRSET: /* clear specified set */ + case ICL_OP_CLRSET: /* clear specified set */ /* zero out the specified set: p1=setname */ - AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code); - if (code) return code; + AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code); + if (code) + return code; setp = afs_icl_FindSet(tname); - if (!setp) return ENOENT; + if (!setp) + return ENOENT; code = afs_icl_ZeroSet(setp); afs_icl_SetRele(setp); break; - case ICL_OP_CLRALL: /* clear all logs */ + case ICL_OP_CLRALL: /* clear all logs */ /* zero out all logs -- no args */ code = 0; - ObtainWriteLock(&afs_icl_lock,178); - for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) { + ObtainWriteLock(&afs_icl_lock, 178); + for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) { tlp->refCount++; /* hold this guy */ ReleaseWriteLock(&afs_icl_lock); /* don't clear persistent logs */ if ((tlp->states & ICL_LOGF_PERSISTENT) == 0) code = afs_icl_ZeroLog(tlp); - ObtainWriteLock(&afs_icl_lock,179); + ObtainWriteLock(&afs_icl_lock, 179); if (--tlp->refCount == 0) afs_icl_ZapLog(tlp); - if (code) break; + if (code) + break; } ReleaseWriteLock(&afs_icl_lock); break; @@ -1717,23 +1824,29 @@ Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval) /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states. * return 0 for success, otherwise error. */ - for(setp = afs_icl_allSets; setp; setp = setp->nextp) { - if (p1-- == 0) break; + for (setp = afs_icl_allSets; setp; setp = setp->nextp) { + if (p1-- == 0) + break; } - if (!setp) return ENOENT; /* past the end of file */ - temp = strlen(setp->name)+1; - if (temp > p3) return EINVAL; + if (!setp) + return ENOENT; /* past the end of file */ + temp = strlen(setp->name) + 1; + if (temp > p3) + return EINVAL; AFS_COPYOUT(setp->name, (char *)p2, temp, code); - if (!code) /* copy out size of log */ - AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code); + if (!code) /* copy out size of log */ + AFS_COPYOUT((char *)&setp->states, (char *)p4, sizeof(afs_int32), + code); break; case ICL_OP_SETSTAT: /* set status on a set */ /* activate the specified set: p1=setname, p2=op */ AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code); - if (code) return code; + if (code) + return code; setp = afs_icl_FindSet(tname); - if (!setp) return ENOENT; + if (!setp) + return ENOENT; code = afs_icl_SetSetStat(setp, p2); afs_icl_SetRele(setp); break; @@ -1741,51 +1854,61 @@ Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval) case ICL_OP_SETSTATALL: /* set status on all sets */ /* activate the specified set: p1=op */ code = 0; - ObtainWriteLock(&afs_icl_lock,180); - for(setp = afs_icl_allSets; setp; setp=setp->nextp) { + ObtainWriteLock(&afs_icl_lock, 180); + for (setp = afs_icl_allSets; setp; setp = setp->nextp) { setp->refCount++; /* hold this guy */ ReleaseWriteLock(&afs_icl_lock); /* don't set states on persistent sets */ if ((setp->states & ICL_SETF_PERSISTENT) == 0) code = afs_icl_SetSetStat(setp, p1); - ObtainWriteLock(&afs_icl_lock,181); + ObtainWriteLock(&afs_icl_lock, 181); if (--setp->refCount == 0) afs_icl_ZapSet(setp); - if (code) break; + if (code) + break; } ReleaseWriteLock(&afs_icl_lock); break; - case ICL_OP_SETLOGSIZE: /* set size of log */ + case ICL_OP_SETLOGSIZE: /* set size of log */ /* set the size of the specified log: p1=logname, p2=size (in words) */ AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code); - if (code) return code; + if (code) + return code; logp = afs_icl_FindLog(tname); - if (!logp) return ENOENT; + if (!logp) + return ENOENT; code = afs_icl_LogSetSize(logp, p2); afs_icl_LogRele(logp); break; - case ICL_OP_GETLOGINFO: /* get size of log */ + case ICL_OP_GETLOGINFO: /* get size of log */ /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */ AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code); - if (code) return code; + if (code) + return code; logp = afs_icl_FindLog(tname); - if (!logp) return ENOENT; + if (!logp) + return ENOENT; allocated = !!logp->datap; - AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code); + AFS_COPYOUT((char *)&logp->logSize, (char *)p2, sizeof(afs_int32), + code); if (!code) - AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code); + AFS_COPYOUT((char *)&allocated, (char *)p3, sizeof(afs_int32), + code); afs_icl_LogRele(logp); break; - case ICL_OP_GETSETINFO: /* get state of set */ + case ICL_OP_GETSETINFO: /* get state of set */ /* zero out the specified set: p1=setname, p2=&state */ AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code); - if (code) return code; + if (code) + return code; setp = afs_icl_FindSet(tname); - if (!setp) return ENOENT; - AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code); + if (!setp) + return ENOENT; + AFS_COPYOUT((char *)&setp->states, (char *)p2, sizeof(afs_int32), + code); afs_icl_SetRele(setp); break; @@ -1800,75 +1923,70 @@ Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval) afs_lock_t afs_icl_lock; /* exported routine: a 4 parameter event */ -afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, p4) - register struct afs_icl_set *setp; - afs_int32 eventID; - afs_int32 lAndT; - long p1, p2, p3, p4; +int +afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID, + afs_int32 lAndT, long p1, long p2, long p3, long p4) { - register struct afs_icl_log *logp; afs_int32 mask; register int i; register afs_int32 tmask; int ix; /* If things aren't init'ed yet (or the set is inactive), don't panic */ - if (!ICL_SETACTIVE(setp)) return; + if (!ICL_SETACTIVE(setp)) + return 0; AFS_ASSERT_GLOCK(); - mask = lAndT>>24 & 0xff; /* mask of which logs to log to */ + mask = lAndT >> 24 & 0xff; /* mask of which logs to log to */ ix = ICL_EVENTBYTE(eventID); ObtainReadLock(&setp->lock); if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) { - for(i=0, tmask = 1; ilogs[i], eventID, lAndT & 0xffffff, - p1, p2, p3, p4); + p1, p2, p3, p4); } mask &= ~tmask; - if (mask == 0) break; /* break early */ + if (mask == 0) + break; /* break early */ } } ReleaseReadLock(&setp->lock); + return 0; } /* Next 4 routines should be implemented via var-args or something. * Whole purpose is to avoid compiler warnings about parameter # mismatches. * Otherwise, could call afs_icl_Event4 directly. */ -afs_icl_Event3(setp, eventID, lAndT, p1, p2, p3) - register struct afs_icl_set *setp; - afs_int32 eventID; - afs_int32 lAndT; - long p1, p2, p3; +int +afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID, + afs_int32 lAndT, long p1, long p2, long p3) { return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0); } -afs_icl_Event2(setp, eventID, lAndT, p1, p2) - register struct afs_icl_set *setp; - afs_int32 eventID; - afs_int32 lAndT; - long p1, p2; +int +afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID, + afs_int32 lAndT, long p1, long p2) { return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0); } -afs_icl_Event1(setp, eventID, lAndT, p1) - register struct afs_icl_set *setp; - afs_int32 eventID; - afs_int32 lAndT; - long p1; +int +afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID, + afs_int32 lAndT, long p1) { - return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0); + return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, + (long)0); } -afs_icl_Event0(setp, eventID, lAndT) - register struct afs_icl_set *setp; - afs_int32 eventID; - afs_int32 lAndT; +int +afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID, + afs_int32 lAndT) { - return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0); + return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, + (long)0); } struct afs_icl_log *afs_icl_allLogs = 0; @@ -1879,9 +1997,8 @@ struct afs_icl_log *afs_icl_allLogs = 0; * * Log must be write-locked. */ -static afs_icl_GetLogSpace(logp, minSpace) - register struct afs_icl_log *logp; - afs_int32 minSpace; +static void +afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace) { register unsigned int tsize; @@ -1901,16 +2018,15 @@ static afs_icl_GetLogSpace(logp, minSpace) * log must be write-locked. */ #define ICL_CHARSPERLONG 4 -static afs_int32 afs_icl_AppendString(logp, astr) - struct afs_icl_log *logp; - char *astr; +static void +afs_icl_AppendString(struct afs_icl_log *logp, char *astr) { - char *op; /* ptr to char to write */ + char *op; /* ptr to char to write */ int tc; - register int bib; /* bytes in buffer */ + register int bib; /* bytes in buffer */ bib = 0; - op = (char *) &(logp->datap[logp->firstFree]); + op = (char *)&(logp->datap[logp->firstFree]); while (1) { tc = *astr++; *op++ = tc; @@ -1919,11 +2035,12 @@ static afs_int32 afs_icl_AppendString(logp, astr) bib = 0; if (++(logp->firstFree) >= logp->logSize) { logp->firstFree = 0; - op = (char *) &(logp->datap[0]); + op = (char *)&(logp->datap[0]); } logp->logElements++; } - if (tc == 0) break; + if (tc == 0) + break; } if (bib > 0) { /* if we've used this word at all, allocate it */ @@ -1935,7 +2052,6 @@ static afs_int32 afs_icl_AppendString(logp, astr) } /* add a long to the log, ignoring overflow (checked already) */ -#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) #define ICL_APPENDINT32(lp, x) \ MACRO_BEGIN \ (lp)->datap[(lp)->firstFree] = (x); \ @@ -1945,6 +2061,7 @@ static afs_int32 afs_icl_AppendString(logp, astr) (lp)->logElements++; \ MACRO_END +#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) #define ICL_APPENDLONG(lp, x) \ MACRO_BEGIN \ ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \ @@ -1952,25 +2069,17 @@ static afs_int32 afs_icl_AppendString(logp, astr) MACRO_END #else /* AFS_ALPHA_ENV */ -#define ICL_APPENDLONG(lp, x) \ - MACRO_BEGIN \ - (lp)->datap[(lp)->firstFree] = (x); \ - if (++((lp)->firstFree) >= (lp)->logSize) { \ - (lp)->firstFree = 0; \ - } \ - (lp)->logElements++; \ - MACRO_END -#define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x)) +#define ICL_APPENDLONG(lp, x) ICL_APPENDINT32((lp), (x)) #endif /* AFS_ALPHA_ENV */ /* routine to tell whether we're dealing with the address or the * object itself */ -afs_icl_UseAddr(type) - int type; +int +afs_icl_UseAddr(int type) { if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING - || type == ICL_TYPE_FID) + || type == ICL_TYPE_FID || type == ICL_TYPE_INT64) return 1; else return 0; @@ -1981,11 +2090,9 @@ afs_icl_UseAddr(type) * pretty soon, anyway. The log must be unlocked. */ -afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4) - register struct afs_icl_log *logp; - afs_int32 op; - afs_int32 types; - long p1, p2, p3, p4; +void +afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op, + afs_int32 types, long p1, long p2, long p3, long p4) { int rsize; /* record size in longs */ register int tsize; /* temp size */ @@ -2001,7 +2108,7 @@ afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4) t1 = types & 0x3f; osi_GetTime(&tv); /* It panics for solaris if inside */ - ObtainWriteLock(&logp->lock,182); + ObtainWriteLock(&logp->lock, 182); if (!logp->datap) { ReleaseWriteLock(&logp->lock); return; @@ -2011,23 +2118,24 @@ afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4) * change that often. This algorithm ticks over every 20 minutes * or so (1000 seconds). Write a timestamp record if it has. */ - if (tv.tv_sec - logp->lastTS > 1024) - { + if (tv.tv_sec - logp->lastTS > 1024) { /* the timer has wrapped -- write a timestamp record */ if (logp->logSize - logp->logElements <= 5) afs_icl_GetLogSpace(logp, 5); - ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18)); - ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP); - ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */ ICL_APPENDINT32(logp, - (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec); - ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec); + (afs_int32) (5 << 24) + (ICL_TYPE_UNIXDATE << 18)); + ICL_APPENDINT32(logp, (afs_int32) ICL_INFO_TIMESTAMP); + ICL_APPENDINT32(logp, (afs_int32) 0); /* use thread ID zero for clocks */ + ICL_APPENDINT32(logp, + (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 + + tv.tv_usec); + ICL_APPENDINT32(logp, (afs_int32) tv.tv_sec); logp->lastTS = tv.tv_sec; } - rsize = 4; /* base case */ + rsize = 4; /* base case */ if (t1) { /* compute size of parameter p1. Only tricky case is string. * In that case, we have to call strlen to get the string length. @@ -2060,95 +2168,179 @@ afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4) */ if (rsize > 255) { ReleaseWriteLock(&logp->lock); - return; /* log record too big to express */ + return; /* log record too big to express */ } if (logp->logSize - logp->logElements <= rsize) afs_icl_GetLogSpace(logp, rsize); ICL_APPENDINT32(logp, - (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4); - ICL_APPENDINT32(logp, (afs_int32)op); - ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique()); - ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec); + (afs_int32) (rsize << 24) + (t1 << 18) + (t2 << 12) + + (t3 << 6) + t4); + ICL_APPENDINT32(logp, (afs_int32) op); + ICL_APPENDINT32(logp, (afs_int32) osi_ThreadUnique()); + ICL_APPENDINT32(logp, + (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec); if (t1) { /* marshall parameter 1 now */ if (t1 == ICL_TYPE_STRING) { - afs_icl_AppendString(logp, (char *) p1); - } - else if (t1 == ICL_TYPE_HYPER) { - ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high); - ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low); - } - else if (t1 == ICL_TYPE_FID) { - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]); + afs_icl_AppendString(logp, (char *)p1); + } else if (t1 == ICL_TYPE_HYPER) { + ICL_APPENDINT32(logp, + (afs_int32) ((struct afs_hyper_t *)p1)->high); + ICL_APPENDINT32(logp, + (afs_int32) ((struct afs_hyper_t *)p1)->low); + } else if (t1 == ICL_TYPE_INT64) { +#ifdef AFSLITTLE_ENDIAN +#ifdef AFS_64BIT_CLIENT + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]); +#else /* AFS_64BIT_CLIENT */ + ICL_APPENDINT32(logp, (afs_int32) p1); + ICL_APPENDINT32(logp, (afs_int32) 0); +#endif /* AFS_64BIT_CLIENT */ +#else /* AFSLITTLE_ENDIAN */ +#ifdef AFS_64BIT_CLIENT + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]); +#else /* AFS_64BIT_CLIENT */ + ICL_APPENDINT32(logp, (afs_int32) 0); + ICL_APPENDINT32(logp, (afs_int32) p1); +#endif /* AFS_64BIT_CLIENT */ +#endif /* AFSLITTLE_ENDIAN */ + } else if (t1 == ICL_TYPE_FID) { + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[2]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[3]); } -#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) +#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) else if (t1 == ICL_TYPE_INT32) - ICL_APPENDINT32(logp, (afs_int32)p1); + ICL_APPENDINT32(logp, (afs_int32) p1); #endif /* AFS_ALPHA_ENV */ - else ICL_APPENDLONG(logp, p1); + else + ICL_APPENDLONG(logp, p1); } if (t2) { /* marshall parameter 2 now */ - if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2); + if (t2 == ICL_TYPE_STRING) + afs_icl_AppendString(logp, (char *)p2); else if (t2 == ICL_TYPE_HYPER) { - ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high); - ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low); - } - else if (t2 == ICL_TYPE_FID) { - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]); + ICL_APPENDINT32(logp, + (afs_int32) ((struct afs_hyper_t *)p2)->high); + ICL_APPENDINT32(logp, + (afs_int32) ((struct afs_hyper_t *)p2)->low); + } else if (t2 == ICL_TYPE_INT64) { +#ifdef AFSLITTLE_ENDIAN +#ifdef AFS_64BIT_CLIENT + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]); +#else /* AFS_64BIT_CLIENT */ + ICL_APPENDINT32(logp, (afs_int32) p2); + ICL_APPENDINT32(logp, (afs_int32) 0); +#endif /* AFS_64BIT_CLIENT */ +#else /* AFSLITTLE_ENDIAN */ +#ifdef AFS_64BIT_CLIENT + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]); +#else /* AFS_64BIT_CLIENT */ + ICL_APPENDINT32(logp, (afs_int32) 0); + ICL_APPENDINT32(logp, (afs_int32) p2); +#endif /* AFS_64BIT_CLIENT */ +#endif /* AFSLITTLE_ENDIAN */ + } else if (t2 == ICL_TYPE_FID) { + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[2]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[3]); } -#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) +#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) else if (t2 == ICL_TYPE_INT32) - ICL_APPENDINT32(logp, (afs_int32)p2); + ICL_APPENDINT32(logp, (afs_int32) p2); #endif /* AFS_ALPHA_ENV */ - else ICL_APPENDLONG(logp, p2); + else + ICL_APPENDLONG(logp, p2); } if (t3) { /* marshall parameter 3 now */ - if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3); + if (t3 == ICL_TYPE_STRING) + afs_icl_AppendString(logp, (char *)p3); else if (t3 == ICL_TYPE_HYPER) { - ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high); - ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low); + ICL_APPENDINT32(logp, + (afs_int32) ((struct afs_hyper_t *)p3)->high); + ICL_APPENDINT32(logp, + (afs_int32) ((struct afs_hyper_t *)p3)->low); + } else if (t3 == ICL_TYPE_INT64) { +#ifdef AFSLITTLE_ENDIAN +#ifdef AFS_64BIT_CLIENT + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]); +#else /* AFS_64BIT_CLIENT */ + ICL_APPENDINT32(logp, (afs_int32) p3); + ICL_APPENDINT32(logp, (afs_int32) 0); +#endif /* AFS_64BIT_CLIENT */ +#else /* AFSLITTLE_ENDIAN */ +#ifdef AFS_64BIT_CLIENT + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]); +#else /* AFS_64BIT_CLIENT */ + ICL_APPENDINT32(logp, (afs_int32) 0); + ICL_APPENDINT32(logp, (afs_int32) p3); +#endif /* AFS_64BIT_CLIENT */ +#endif /* AFSLITTLE_ENDIAN */ + } else if (t3 == ICL_TYPE_FID) { + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[2]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[3]); } - else if (t3 == ICL_TYPE_FID) { - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]); - } -#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) +#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) else if (t3 == ICL_TYPE_INT32) - ICL_APPENDINT32(logp, (afs_int32)p3); + ICL_APPENDINT32(logp, (afs_int32) p3); #endif /* AFS_ALPHA_ENV */ - else ICL_APPENDLONG(logp, p3); + else + ICL_APPENDLONG(logp, p3); } if (t4) { /* marshall parameter 4 now */ - if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4); + if (t4 == ICL_TYPE_STRING) + afs_icl_AppendString(logp, (char *)p4); else if (t4 == ICL_TYPE_HYPER) { - ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high); - ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low); - } - else if (t4 == ICL_TYPE_FID) { - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]); - ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]); + ICL_APPENDINT32(logp, + (afs_int32) ((struct afs_hyper_t *)p4)->high); + ICL_APPENDINT32(logp, + (afs_int32) ((struct afs_hyper_t *)p4)->low); + } else if (t4 == ICL_TYPE_INT64) { +#ifdef AFSLITTLE_ENDIAN +#ifdef AFS_64BIT_CLIENT + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]); +#else /* AFS_64BIT_CLIENT */ + ICL_APPENDINT32(logp, (afs_int32) p4); + ICL_APPENDINT32(logp, (afs_int32) 0); +#endif /* AFS_64BIT_CLIENT */ +#else /* AFSLITTLE_ENDIAN */ +#ifdef AFS_64BIT_CLIENT + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]); +#else /* AFS_64BIT_CLIENT */ + ICL_APPENDINT32(logp, (afs_int32) 0); + ICL_APPENDINT32(logp, (afs_int32) p4); +#endif /* AFS_64BIT_CLIENT */ +#endif /* AFSLITTLE_ENDIAN */ + } else if (t4 == ICL_TYPE_FID) { + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[2]); + ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[3]); } -#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) +#if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) else if (t4 == ICL_TYPE_INT32) - ICL_APPENDINT32(logp, (afs_int32)p4); + ICL_APPENDINT32(logp, (afs_int32) p4); #endif /* AFS_ALPHA_ENV */ - else ICL_APPENDLONG(logp, p4); + else + ICL_APPENDLONG(logp, p4); } ReleaseWriteLock(&logp->lock); } @@ -2156,37 +2348,34 @@ afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4) /* create a log with size logSize; return it in *outLogpp and tag * it with name "name." */ -afs_icl_CreateLog(name, logSize, outLogpp) - char *name; - afs_int32 logSize; - struct afs_icl_log **outLogpp; +int +afs_icl_CreateLog(char *name, afs_int32 logSize, + struct afs_icl_log **outLogpp) { - return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp); + return afs_icl_CreateLogWithFlags(name, logSize, /*flags */ 0, outLogpp); } /* create a log with size logSize; return it in *outLogpp and tag * it with name "name." 'flags' can be set to make the log unclearable. */ -afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp) - char *name; - afs_int32 logSize; - afs_uint32 flags; - struct afs_icl_log **outLogpp; +int +afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags, + struct afs_icl_log **outLogpp) { register struct afs_icl_log *logp; /* add into global list under lock */ - ObtainWriteLock(&afs_icl_lock,183); - if (!afs_icl_inited) afs_icl_Init(); + ObtainWriteLock(&afs_icl_lock, 183); + if (!afs_icl_inited) + afs_icl_Init(); - for (logp = afs_icl_allLogs; logp; logp=logp->nextp) { + for (logp = afs_icl_allLogs; logp; logp = logp->nextp) { if (strcmp(logp->name, name) == 0) { /* found it already created, just return it */ logp->refCount++; *outLogpp = logp; - if (flags & ICL_CRLOG_FLAG_PERSISTENT) - { - ObtainWriteLock(&logp->lock,184); + if (flags & ICL_CRLOG_FLAG_PERSISTENT) { + ObtainWriteLock(&logp->lock, 184); logp->states |= ICL_LOGF_PERSISTENT; ReleaseWriteLock(&logp->lock); } @@ -2194,17 +2383,17 @@ afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp) return 0; } } - + logp = (struct afs_icl_log *) osi_AllocSmallSpace(sizeof(struct afs_icl_log)); - memset((caddr_t)logp, 0, sizeof(*logp)); + memset((caddr_t) logp, 0, sizeof(*logp)); logp->refCount = 1; - logp->name = osi_AllocSmallSpace(strlen(name)+1); + logp->name = osi_AllocSmallSpace(strlen(name) + 1); strcpy(logp->name, name); LOCK_INIT(&logp->lock, "logp lock"); logp->logSize = logSize; - logp->datap = (afs_int32 *)0; /* don't allocate it until we need it */ + logp->datap = NULL; /* don't allocate it until we need it */ if (flags & ICL_CRLOG_FLAG_PERSISTENT) logp->states |= ICL_LOGF_PERSISTENT; @@ -2223,20 +2412,17 @@ afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp) * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't * find the record with cookie value cookie. */ -afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) - register struct afs_icl_log *logp; - afs_int32 *bufferp; - afs_int32 *bufSizep; - afs_uint32 *cookiep; - afs_int32 *flagsp; +int +afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 * bufferp, + afs_int32 * bufSizep, afs_uint32 * cookiep, + afs_int32 * flagsp) { afs_int32 nwords; /* number of words to copy out */ afs_uint32 startCookie; /* first cookie to use */ - register afs_int32 i; afs_int32 outWords; /* words we've copied out */ afs_int32 inWords; /* max words to copy out */ - afs_int32 code; /* return code */ - afs_int32 ix; /* index we're copying from */ + afs_int32 code; /* return code */ + afs_int32 ix; /* index we're copying from */ afs_int32 outFlags; /* return flags */ afs_int32 inFlags; /* flags passed in */ afs_int32 end; @@ -2248,7 +2434,7 @@ afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) inFlags = *flagsp; code = 0; - ObtainWriteLock(&logp->lock,185); + ObtainWriteLock(&logp->lock, 185); if (!logp->datap) { ReleaseWriteLock(&logp->lock); goto done; @@ -2258,7 +2444,7 @@ afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) while (1) { /* (re-)compute where we should start */ if (startCookie < logp->baseCookie) { - if (startCookie) /* missed some output */ + if (startCookie) /* missed some output */ outFlags |= ICL_COPYOUTF_MISSEDSOME; /* skip to the first available record */ startCookie = logp->baseCookie; @@ -2267,14 +2453,15 @@ afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) /* compute where we find the first element to copy out */ ix = logp->firstUsed + startCookie - logp->baseCookie; - if (ix >= logp->logSize) ix -= logp->logSize; + if (ix >= logp->logSize) + ix -= logp->logSize; /* if have some data now, break out and process it */ - if (startCookie - logp->baseCookie < logp->logElements) break; + if (startCookie - logp->baseCookie < logp->logElements) + break; /* At end of log, so clear it if we need to */ - if (inFlags & ICL_COPYOUTF_CLRAFTERREAD) - { + if (inFlags & ICL_COPYOUTF_CLRAFTERREAD) { logp->firstUsed = logp->firstFree = 0; logp->logElements = 0; } @@ -2287,7 +2474,7 @@ afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) logp->states |= ICL_LOGF_WAITING; ReleaseWriteLock(&logp->lock); afs_osi_Sleep(&logp->lock); - ObtainWriteLock(&logp->lock,186); + ObtainWriteLock(&logp->lock, 186); } /* copy out data from ix to logSize or firstFree, depending * upon whether firstUsed <= firstFree (no wrap) or otherwise. @@ -2303,7 +2490,8 @@ afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) if (end - ix < nwords) nwords = end - ix; if (nwords > 0) { - memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords); + memcpy((char *)bufferp, (char *)&logp->datap[ix], + sizeof(afs_int32) * nwords); outWords += nwords; inWords -= nwords; bufferp += nwords; @@ -2314,8 +2502,8 @@ afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) /* now, if active part of the log has wrapped, there's more stuff * starting at the head of the log. Copy out more from there. */ - if (logp->firstUsed > logp->firstFree - && ix < logp->firstFree && inWords > 0) { + if (logp->firstUsed > logp->firstFree && ix < logp->firstFree + && inWords > 0) { /* (more to) copy out from the wrapped section at the * start of the log. May get here even if didn't copy any * above, if the cookie points directly into the wrapped section. @@ -2323,7 +2511,8 @@ afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) nwords = inWords; if (logp->firstFree - ix < nwords) nwords = logp->firstFree - ix; - memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords); + memcpy((char *)bufferp, (char *)&logp->datap[ix], + sizeof(afs_int32) * nwords); outWords += nwords; inWords -= nwords; bufferp += nwords; @@ -2340,10 +2529,9 @@ afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp) } /* return basic parameter information about a log */ -afs_icl_GetLogParms(logp, maxSizep, curSizep) - struct afs_icl_log *logp; - afs_int32 *maxSizep; - afs_int32 *curSizep; +int +afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 * maxSizep, + afs_int32 * curSizep) { ObtainReadLock(&logp->lock); *maxSizep = logp->logSize; @@ -2354,36 +2542,37 @@ afs_icl_GetLogParms(logp, maxSizep, curSizep) /* hold and release logs */ -afs_icl_LogHold(logp) - register struct afs_icl_log *logp; +int +afs_icl_LogHold(register struct afs_icl_log *logp) { - ObtainWriteLock(&afs_icl_lock,187); + ObtainWriteLock(&afs_icl_lock, 187); logp->refCount++; ReleaseWriteLock(&afs_icl_lock); return 0; } /* hold and release logs, called with lock already held */ -afs_icl_LogHoldNL(logp) - register struct afs_icl_log *logp; +int +afs_icl_LogHoldNL(register struct afs_icl_log *logp) { logp->refCount++; return 0; } /* keep track of how many sets believe the log itself is allocated */ -afs_icl_LogUse(logp) - register struct afs_icl_log *logp; +int +afs_icl_LogUse(register struct afs_icl_log *logp) { - ObtainWriteLock(&logp->lock,188); + ObtainWriteLock(&logp->lock, 188); if (logp->setCount == 0) { /* this is the first set actually using the log -- allocate it */ - if (logp->logSize == 0) { + if (logp->logSize == 0) { /* we weren't passed in a hint and it wasn't set */ logp->logSize = ICL_DEFAULT_LOGSIZE; } - logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize); -#ifdef AFS_AIX32_ENV + logp->datap = + (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize); +#ifdef KERNEL_HAVE_PIN pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize); #endif } @@ -2393,46 +2582,45 @@ afs_icl_LogUse(logp) } /* decrement the number of real users of the log, free if possible */ -afs_icl_LogFreeUse(logp) - register struct afs_icl_log *logp; +int +afs_icl_LogFreeUse(register struct afs_icl_log *logp) { - ObtainWriteLock(&logp->lock,189); + ObtainWriteLock(&logp->lock, 189); if (--logp->setCount == 0) { - /* no more users -- free it (but keep log structure around)*/ + /* no more users -- free it (but keep log structure around) */ afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize); -#ifdef AFS_AIX32_ENV +#ifdef KERNEL_HAVE_PIN unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize); #endif logp->firstUsed = logp->firstFree = 0; logp->logElements = 0; - logp->datap = (afs_int32 *)0; + logp->datap = NULL; } ReleaseWriteLock(&logp->lock); return 0; } /* set the size of the log to 'logSize' */ -afs_icl_LogSetSize(logp, logSize) - register struct afs_icl_log *logp; - afs_int32 logSize; -{ - ObtainWriteLock(&logp->lock,190); +int +afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize) +{ + ObtainWriteLock(&logp->lock, 190); if (!logp->datap) { /* nothing to worry about since it's not allocated */ logp->logSize = logSize; - } - else { + } else { /* reset log */ logp->firstUsed = logp->firstFree = 0; logp->logElements = 0; /* free and allocate a new one */ afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize); -#ifdef AFS_AIX32_ENV +#ifdef KERNEL_HAVE_PIN unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize); #endif - logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize); -#ifdef AFS_AIX32_ENV + logp->datap = + (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize); +#ifdef KERNEL_HAVE_PIN pin((char *)logp->datap, sizeof(afs_int32) * logSize); #endif logp->logSize = logSize; @@ -2443,29 +2631,29 @@ afs_icl_LogSetSize(logp, logSize) } /* free a log. Called with afs_icl_lock locked. */ -afs_icl_ZapLog(logp) - register struct afs_icl_log *logp; +int +afs_icl_ZapLog(register struct afs_icl_log *logp) { register struct afs_icl_log **lpp, *tp; - for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) { + for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) { if (tp == logp) { /* found the dude we want to remove */ *lpp = logp->nextp; osi_FreeSmallSpace(logp->name); osi_FreeSmallSpace(logp->datap); osi_FreeSmallSpace(logp); - break; /* won't find it twice */ + break; /* won't find it twice */ } } return 0; } /* do the release, watching for deleted entries */ -afs_icl_LogRele(logp) - register struct afs_icl_log *logp; +int +afs_icl_LogRele(register struct afs_icl_log *logp) { - ObtainWriteLock(&afs_icl_lock,191); + ObtainWriteLock(&afs_icl_lock, 191); if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) { afs_icl_ZapLog(logp); /* destroys logp's lock! */ } @@ -2474,8 +2662,8 @@ afs_icl_LogRele(logp) } /* do the release, watching for deleted entries, log already held */ -afs_icl_LogReleNL(logp) - register struct afs_icl_log *logp; +int +afs_icl_LogReleNL(register struct afs_icl_log *logp) { if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) { afs_icl_ZapLog(logp); /* destroys logp's lock! */ @@ -2484,10 +2672,10 @@ afs_icl_LogReleNL(logp) } /* zero out the log */ -afs_icl_ZeroLog(logp) - register struct afs_icl_log *logp; +int +afs_icl_ZeroLog(register struct afs_icl_log *logp) { - ObtainWriteLock(&logp->lock,192); + ObtainWriteLock(&logp->lock, 192); logp->firstUsed = logp->firstFree = 0; logp->logElements = 0; logp->baseCookie = 0; @@ -2496,10 +2684,10 @@ afs_icl_ZeroLog(logp) } /* free a log entry, and drop its reference count */ -afs_icl_LogFree(logp) - register struct afs_icl_log *logp; +int +afs_icl_LogFree(register struct afs_icl_log *logp) { - ObtainWriteLock(&logp->lock,193); + ObtainWriteLock(&logp->lock, 193); logp->states |= ICL_LOGF_DELETED; ReleaseWriteLock(&logp->lock); afs_icl_LogRele(logp); @@ -2507,12 +2695,12 @@ afs_icl_LogFree(logp) } /* find a log by name, returning it held */ -struct afs_icl_log *afs_icl_FindLog(name) - char *name; +struct afs_icl_log * +afs_icl_FindLog(char *name) { register struct afs_icl_log *tp; - ObtainWriteLock(&afs_icl_lock,194); - for(tp = afs_icl_allLogs; tp; tp=tp->nextp) { + ObtainWriteLock(&afs_icl_lock, 194); + for (tp = afs_icl_allLogs; tp; tp = tp->nextp) { if (strcmp(tp->name, name) == 0) { /* this is the dude we want */ tp->refCount++; @@ -2523,25 +2711,27 @@ struct afs_icl_log *afs_icl_FindLog(name) return tp; } -afs_icl_EnumerateLogs(aproc, arock) - int (*aproc)(); - char *arock; +int +afs_icl_EnumerateLogs(int (*aproc) + (char *name, char *arock, struct afs_icl_log * tp), + char *arock) { register struct afs_icl_log *tp; register afs_int32 code; code = 0; - ObtainWriteLock(&afs_icl_lock,195); - for(tp = afs_icl_allLogs; tp; tp=tp->nextp) { - tp->refCount++; /* hold this guy */ + ObtainWriteLock(&afs_icl_lock, 195); + for (tp = afs_icl_allLogs; tp; tp = tp->nextp) { + tp->refCount++; /* hold this guy */ ReleaseWriteLock(&afs_icl_lock); ObtainReadLock(&tp->lock); - code = (*aproc)(tp->name, arock, tp); + code = (*aproc) (tp->name, arock, tp); ReleaseReadLock(&tp->lock); - ObtainWriteLock(&afs_icl_lock,196); + ObtainWriteLock(&afs_icl_lock, 196); if (--tp->refCount == 0) afs_icl_ZapLog(tp); - if (code) break; + if (code) + break; } ReleaseWriteLock(&afs_icl_lock); return code; @@ -2549,14 +2739,13 @@ afs_icl_EnumerateLogs(aproc, arock) struct afs_icl_set *afs_icl_allSets = 0; -afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp) - char *name; - struct afs_icl_log *baseLogp; - struct afs_icl_log *fatalLogp; - struct afs_icl_set **outSetpp; +int +afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp, + struct afs_icl_log *fatalLogp, + struct afs_icl_set **outSetpp) { return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, - /*flags*/0, outSetpp); + /*flags */ 0, outSetpp); } /* create a set, given pointers to base and fatal logs, if any. @@ -2565,27 +2754,25 @@ afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp) * addds references from the new afs_icl_set. When the set is destroyed, * those references will be released. */ -afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp) - char *name; - struct afs_icl_log *baseLogp; - struct afs_icl_log *fatalLogp; - afs_uint32 flags; - struct afs_icl_set **outSetpp; +int +afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp, + struct afs_icl_log *fatalLogp, afs_uint32 flags, + struct afs_icl_set **outSetpp) { register struct afs_icl_set *setp; register int i; afs_int32 states = ICL_DEFAULT_SET_STATES; - ObtainWriteLock(&afs_icl_lock,197); - if (!afs_icl_inited) afs_icl_Init(); + ObtainWriteLock(&afs_icl_lock, 197); + if (!afs_icl_inited) + afs_icl_Init(); for (setp = afs_icl_allSets; setp; setp = setp->nextp) { if (strcmp(setp->name, name) == 0) { setp->refCount++; *outSetpp = setp; - if (flags & ICL_CRSET_FLAG_PERSISTENT) - { - ObtainWriteLock(&setp->lock,198); + if (flags & ICL_CRSET_FLAG_PERSISTENT) { + ObtainWriteLock(&setp->lock, 198); setp->states |= ICL_SETF_PERSISTENT; ReleaseWriteLock(&setp->lock); } @@ -2593,7 +2780,7 @@ afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp) return 0; } } - + /* determine initial state */ if (flags & ICL_CRSET_FLAG_DEFAULT_ON) states = ICL_SETF_ACTIVE; @@ -2602,8 +2789,8 @@ afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp) if (flags & ICL_CRSET_FLAG_PERSISTENT) states |= ICL_SETF_PERSISTENT; - setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set)); - memset((caddr_t)setp, 0, sizeof(*setp)); + setp = (struct afs_icl_set *)afs_osi_Alloc(sizeof(struct afs_icl_set)); + memset((caddr_t) setp, 0, sizeof(*setp)); setp->refCount = 1; if (states & ICL_SETF_FREED) states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */ @@ -2614,15 +2801,15 @@ afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp) * it doesn't matter, since no one can find this lock yet, since * the afs_icl_lock is still held, and thus the obtain can't block. */ - ObtainWriteLock(&setp->lock,199); - setp->name = osi_AllocSmallSpace(strlen(name)+1); + ObtainWriteLock(&setp->lock, 199); + setp->name = osi_AllocSmallSpace(strlen(name) + 1); strcpy(setp->name, name); setp->nevents = ICL_DEFAULTEVENTS; setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS); -#ifdef AFS_AIX32_ENV +#ifdef KERNEL_HAVE_PIN pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS); #endif - for(i=0; ieventFlags[i] = 0xff; /* default to enabled */ /* update this global info under the afs_icl_lock */ @@ -2650,14 +2837,12 @@ afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp) } /* function to change event enabling information for a particular set */ -afs_icl_SetEnable(setp, eventID, setValue) - struct afs_icl_set *setp; - afs_int32 eventID; - int setValue; +int +afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue) { char *tp; - ObtainWriteLock(&setp->lock,200); + ObtainWriteLock(&setp->lock, 200); if (!ICL_EVENTOK(setp, eventID)) { ReleaseWriteLock(&setp->lock); return -1; @@ -2675,10 +2860,8 @@ afs_icl_SetEnable(setp, eventID, setValue) * for tracing. If *getValuep is set to 0, the event is disabled, * otherwise it is enabled. All events start out enabled by default. */ -afs_icl_GetEnable(setp, eventID, getValuep) - struct afs_icl_set *setp; - afs_int32 eventID; - int *getValuep; +int +afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, int *getValuep) { ObtainReadLock(&setp->lock); if (!ICL_EVENTOK(setp, eventID)) { @@ -2694,48 +2877,48 @@ afs_icl_GetEnable(setp, eventID, getValuep) } /* hold and release event sets */ -afs_icl_SetHold(setp) - register struct afs_icl_set *setp; +int +afs_icl_SetHold(register struct afs_icl_set *setp) { - ObtainWriteLock(&afs_icl_lock,201); + ObtainWriteLock(&afs_icl_lock, 201); setp->refCount++; ReleaseWriteLock(&afs_icl_lock); return 0; } /* free a set. Called with afs_icl_lock locked */ -afs_icl_ZapSet(setp) - register struct afs_icl_set *setp; +int +afs_icl_ZapSet(register struct afs_icl_set *setp) { register struct afs_icl_set **lpp, *tp; int i; register struct afs_icl_log *tlp; - for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) { + for (lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) { if (tp == setp) { /* found the dude we want to remove */ *lpp = setp->nextp; osi_FreeSmallSpace(setp->name); afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS); -#ifdef AFS_AIX32_ENV +#ifdef KERNEL_HAVE_PIN unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS); #endif - for(i=0; i < ICL_LOGSPERSET; i++) { - if (tlp = setp->logs[i]) + for (i = 0; i < ICL_LOGSPERSET; i++) { + if ((tlp = setp->logs[i])) afs_icl_LogReleNL(tlp); } osi_FreeSmallSpace(setp); - break; /* won't find it twice */ + break; /* won't find it twice */ } } return 0; } /* do the release, watching for deleted entries */ -afs_icl_SetRele(setp) - register struct afs_icl_set *setp; +int +afs_icl_SetRele(register struct afs_icl_set *setp) { - ObtainWriteLock(&afs_icl_lock,202); + ObtainWriteLock(&afs_icl_lock, 202); if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) { afs_icl_ZapSet(setp); /* destroys setp's lock! */ } @@ -2744,10 +2927,10 @@ afs_icl_SetRele(setp) } /* free a set entry, dropping its reference count */ -afs_icl_SetFree(setp) - register struct afs_icl_set *setp; +int +afs_icl_SetFree(register struct afs_icl_set *setp) { - ObtainWriteLock(&setp->lock,203); + ObtainWriteLock(&setp->lock, 203); setp->states |= ICL_SETF_DELETED; ReleaseWriteLock(&setp->lock); afs_icl_SetRele(setp); @@ -2755,12 +2938,12 @@ afs_icl_SetFree(setp) } /* find a set by name, returning it held */ -struct afs_icl_set *afs_icl_FindSet(name) - char *name; +struct afs_icl_set * +afs_icl_FindSet(char *name) { register struct afs_icl_set *tp; - ObtainWriteLock(&afs_icl_lock,204); - for(tp = afs_icl_allSets; tp; tp=tp->nextp) { + ObtainWriteLock(&afs_icl_lock, 204); + for (tp = afs_icl_allSets; tp; tp = tp->nextp) { if (strcmp(tp->name, name) == 0) { /* this is the dude we want */ tp->refCount++; @@ -2772,21 +2955,22 @@ struct afs_icl_set *afs_icl_FindSet(name) } /* zero out all the logs in the set */ -afs_icl_ZeroSet(setp) - struct afs_icl_set *setp; +int +afs_icl_ZeroSet(struct afs_icl_set *setp) { register int i; int code = 0; int tcode; struct afs_icl_log *logp; - + ObtainReadLock(&setp->lock); - for(i = 0; i < ICL_LOGSPERSET; i++) { + for (i = 0; i < ICL_LOGSPERSET; i++) { logp = setp->logs[i]; if (logp) { afs_icl_LogHold(logp); tcode = afs_icl_ZeroLog(logp); - if (tcode != 0) code = tcode; /* save the last bad one */ + if (tcode != 0) + code = tcode; /* save the last bad one */ afs_icl_LogRele(logp); } } @@ -2794,39 +2978,39 @@ afs_icl_ZeroSet(setp) return code; } -afs_icl_EnumerateSets(aproc, arock) - int (*aproc)(); - char *arock; +int +afs_icl_EnumerateSets(int (*aproc) + (char *name, char *arock, struct afs_icl_log * tp), + char *arock) { register struct afs_icl_set *tp, *np; register afs_int32 code; code = 0; - ObtainWriteLock(&afs_icl_lock,205); - for(tp = afs_icl_allSets; tp; tp=np) { - tp->refCount++; /* hold this guy */ + ObtainWriteLock(&afs_icl_lock, 205); + for (tp = afs_icl_allSets; tp; tp = np) { + tp->refCount++; /* hold this guy */ ReleaseWriteLock(&afs_icl_lock); - code = (*aproc)(tp->name, arock, tp); - ObtainWriteLock(&afs_icl_lock,206); - np = tp->nextp; /* tp may disappear next, but not np */ + code = (*aproc) (tp->name, arock, tp); + ObtainWriteLock(&afs_icl_lock, 206); + np = tp->nextp; /* tp may disappear next, but not np */ if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED)) afs_icl_ZapSet(tp); - if (code) break; + if (code) + break; } ReleaseWriteLock(&afs_icl_lock); return code; } -afs_icl_AddLogToSet(setp, newlogp) - struct afs_icl_set *setp; - struct afs_icl_log *newlogp; +int +afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp) { register int i; int code = -1; - struct afs_icl_log *logp; - - ObtainWriteLock(&setp->lock,207); - for(i = 0; i < ICL_LOGSPERSET; i++) { + + ObtainWriteLock(&setp->lock, 207); + for (i = 0; i < ICL_LOGSPERSET; i++) { if (!setp->logs[i]) { setp->logs[i] = newlogp; code = i; @@ -2842,16 +3026,15 @@ afs_icl_AddLogToSet(setp, newlogp) return code; } -afs_icl_SetSetStat(setp, op) - struct afs_icl_set *setp; - int op; +int +afs_icl_SetSetStat(struct afs_icl_set *setp, int op) { int i; afs_int32 code; struct afs_icl_log *logp; - ObtainWriteLock(&setp->lock,208); - switch(op) { + ObtainWriteLock(&setp->lock, 208); + switch (op) { case ICL_OP_SS_ACTIVATE: /* activate a log */ /* * If we are not already active, see if we have released @@ -2861,7 +3044,7 @@ afs_icl_SetSetStat(setp, op) if (!(setp->states & ICL_SETF_ACTIVE)) { if (setp->states & ICL_SETF_FREED) { /* have to reassert desire for logs */ - for(i = 0; i < ICL_LOGSPERSET; i++) { + for (i = 0; i < ICL_LOGSPERSET; i++) { logp = setp->logs[i]; if (logp) { afs_icl_LogHold(logp); @@ -2891,7 +3074,7 @@ afs_icl_SetSetStat(setp, op) code = EINVAL; else { if (!(setp->states & ICL_SETF_FREED)) { - for(i = 0; i < ICL_LOGSPERSET; i++) { + for (i = 0; i < ICL_LOGSPERSET; i++) { logp = setp->logs[i]; if (logp) { afs_icl_LogHold(logp); @@ -2911,4 +3094,3 @@ afs_icl_SetSetStat(setp, op) ReleaseWriteLock(&setp->lock); return code; } - diff --git a/src/afs/afs_callback.c b/src/afs/afs_callback.c index 9608523c6..dba98a250 100644 --- a/src/afs/afs_callback.c +++ b/src/afs/afs_callback.c @@ -14,36 +14,23 @@ */ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_callback.c,v 1.1.1.10 2003/04/13 19:02:34 hartmans Exp $"); - -#include "../afs/sysincludes.h" /*Standard vendor system headers*/ -#include "../afs/afsincludes.h" /*AFS-based standard headers*/ -#include "../afs/afs_stats.h" /*Cache Manager stats*/ -#include "../afs/afs_args.h" - -extern struct volume *afs_volumes[NVOLS]; /* volume hash table */ -extern void afs_DequeueCallback(); -extern void afs_ComputePAGStats(); -afs_int32 afs_allCBs = 0; /*Break callbacks on all objects */ -afs_int32 afs_oddCBs = 0; /*Break callbacks on dirs*/ -afs_int32 afs_evenCBs = 0; /*Break callbacks received on files*/ -afs_int32 afs_allZaps = 0; /*Objects entries deleted */ -afs_int32 afs_oddZaps = 0; /*Dir cache entries deleted*/ -afs_int32 afs_evenZaps = 0; /*File cache entries deleted*/ +#include "afs/param.h" + +RCSID + ("$Header: /cvs/openafs/src/afs/afs_callback.c,v 1.26 2004/04/16 04:57:01 kolya Exp $"); + +#include "afs/sysincludes.h" /*Standard vendor system headers */ +#include "afsincludes.h" /*AFS-based standard headers */ +#include "afs/afs_stats.h" /*Cache Manager stats */ +#include "afs/afs_args.h" + +afs_int32 afs_allCBs = 0; /*Break callbacks on all objects */ +afs_int32 afs_oddCBs = 0; /*Break callbacks on dirs */ +afs_int32 afs_evenCBs = 0; /*Break callbacks received on files */ +afs_int32 afs_allZaps = 0; /*Objects entries deleted */ +afs_int32 afs_oddZaps = 0; /*Dir cache entries deleted */ +afs_int32 afs_evenZaps = 0; /*File cache entries deleted */ afs_int32 afs_connectBacks = 0; -extern struct rx_service *afs_server; - -extern afs_lock_t afs_xvcb, afs_xbrs, afs_xdcache; -extern afs_rwlock_t afs_xvcache, afs_xserver, afs_xcell, afs_xuser; -extern afs_rwlock_t afs_xvolume, afs_puttofileLock, afs_ftf, afs_xinterface; -extern afs_rwlock_t afs_xconn; -extern struct afs_lock afs_xaxs; -extern afs_lock_t afs_xcbhash; -extern struct srvAddr *afs_srvAddrs[NSERVERS]; -extern struct afs_q CellLRU; -extern struct cm_initparams cm_initParams; /* * Some debugging aids. @@ -51,25 +38,32 @@ extern struct cm_initparams cm_initParams; static struct ltable { char *name; char *addr; -} ltable []= { - "afs_xvcache", (char *)&afs_xvcache, - "afs_xdcache", (char *)&afs_xdcache, - "afs_xserver", (char *)&afs_xserver, - "afs_xvcb", (char *)&afs_xvcb, - "afs_xbrs", (char *)&afs_xbrs, - "afs_xcell", (char *)&afs_xcell, - "afs_xconn", (char *)&afs_xconn, - "afs_xuser", (char *)&afs_xuser, - "afs_xvolume", (char *)&afs_xvolume, - "puttofile", (char *)&afs_puttofileLock, - "afs_ftf", (char *)&afs_ftf, - "afs_xcbhash", (char *)&afs_xcbhash, - "afs_xaxs", (char *)&afs_xaxs, - "afs_xinterface", (char *)&afs_xinterface, +} ltable[] = { + { + "afs_xvcache", (char *)&afs_xvcache}, { + "afs_xdcache", (char *)&afs_xdcache}, { + "afs_xserver", (char *)&afs_xserver}, { + "afs_xvcb", (char *)&afs_xvcb}, { + "afs_xbrs", (char *)&afs_xbrs}, { + "afs_xcell", (char *)&afs_xcell}, { + "afs_xconn", (char *)&afs_xconn}, { + "afs_xuser", (char *)&afs_xuser}, { + "afs_xvolume", (char *)&afs_xvolume}, { + "puttofile", (char *)&afs_puttofileLock}, { + "afs_ftf", (char *)&afs_ftf}, { + "afs_xcbhash", (char *)&afs_xcbhash}, { + "afs_xaxs", (char *)&afs_xaxs}, { + "afs_xinterface", (char *)&afs_xinterface}, +#ifndef UKERNEL + { + "afs_xosi", (char *)&afs_xosi}, +#endif + { + "afs_xsrvAddr", (char *)&afs_xsrvAddr} }; -unsigned long lastCallBack_vnode; -unsigned int lastCallBack_dv; -osi_timeval_t lastCallBack_time; +unsigned long lastCallBack_vnode; +unsigned int lastCallBack_dv; +osi_timeval_t lastCallBack_time; /* these are for storing alternate interface addresses */ struct interfaceAddr afs_cb_interface; @@ -97,21 +91,17 @@ struct interfaceAddr afs_cb_interface; * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_GetCE(a_call, a_index, a_result) - struct rx_call *a_call; - afs_int32 a_index; - struct AFSDBCacheEntry *a_result; - -{ /*SRXAFSCB_GetCE*/ +int +SRXAFSCB_GetCE(struct rx_call *a_call, afs_int32 a_index, + struct AFSDBCacheEntry *a_result) +{ - register int i; /*Loop variable*/ - register struct vcache *tvc; /*Ptr to current cache entry*/ - int code; /*Return code*/ + register int i; /*Loop variable */ + register struct vcache *tvc; /*Ptr to current cache entry */ + int code; /*Return code */ XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETCE); @@ -121,12 +111,12 @@ int SRXAFSCB_GetCE(a_call, a_index, a_result) if (a_index == 0) goto searchDone; a_index--; - } /*Zip through current hash chain*/ - } /*Zip through hash chains*/ + } /*Zip through current hash chain */ + } /*Zip through hash chains */ searchDone: - if (tvc == (struct vcache *) 0) { - /*Past EOF*/ + if (tvc == NULL) { + /*Past EOF */ code = 1; goto fcnDone; } @@ -153,9 +143,13 @@ int SRXAFSCB_GetCE(a_call, a_index, a_result) a_result->lock.pid_writer = 0; a_result->lock.src_indicator = 0; #endif /* AFS_OSF20_ENV */ +#ifdef AFS_64BIT_CLIENT + a_result->Length = (afs_int32) tvc->m.Length & 0xffffffff; +#else /* AFS_64BIT_CLIENT */ a_result->Length = tvc->m.Length; +#endif /* AFS_64BIT_CLIENT */ a_result->DataVersion = hgetlo(tvc->m.DataVersion); - a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */ + a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */ a_result->cbExpires = tvc->cbExpires; a_result->refCount = VREFCOUNT(tvc); a_result->opens = tvc->opens; @@ -167,16 +161,97 @@ int SRXAFSCB_GetCE(a_call, a_index, a_result) /* * Return our results. */ -fcnDone: + fcnDone: XSTATS_END_TIME; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); - return(code); + return (code); -} /*SRXAFSCB_GetCE*/ +} /*SRXAFSCB_GetCE */ + +int +SRXAFSCB_GetCE64(struct rx_call *a_call, afs_int32 a_index, + struct AFSDBCacheEntry64 *a_result) +{ + register int i; /*Loop variable */ + register struct vcache *tvc; /*Ptr to current cache entry */ + int code; /*Return code */ + XSTATS_DECLS; + + RX_AFS_GLOCK(); + + XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETCE); + + AFS_STATCNT(SRXAFSCB_GetCE64); + for (i = 0; i < VCSIZE; i++) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { + if (a_index == 0) + goto searchDone; + a_index--; + } /*Zip through current hash chain */ + } /*Zip through hash chains */ + + searchDone: + if (tvc == NULL) { + /*Past EOF */ + code = 1; + goto fcnDone; + } + + /* + * Copy out the located entry. + */ + a_result->addr = afs_data_pointer_to_int32(tvc); + a_result->cell = tvc->fid.Cell; + a_result->netFid.Volume = tvc->fid.Fid.Volume; + a_result->netFid.Vnode = tvc->fid.Fid.Vnode; + a_result->netFid.Unique = tvc->fid.Fid.Unique; + a_result->lock.waitStates = tvc->lock.wait_states; + a_result->lock.exclLocked = tvc->lock.excl_locked; + a_result->lock.readersReading = tvc->lock.readers_reading; + a_result->lock.numWaiting = tvc->lock.num_waiting; +#if defined(INSTRUMENT_LOCKS) + a_result->lock.pid_last_reader = tvc->lock.pid_last_reader; + a_result->lock.pid_writer = tvc->lock.pid_writer; + a_result->lock.src_indicator = tvc->lock.src_indicator; +#else + /* On osf20 , the vcache does not maintain these three fields */ + a_result->lock.pid_last_reader = 0; + a_result->lock.pid_writer = 0; + a_result->lock.src_indicator = 0; +#endif /* AFS_OSF20_ENV */ +#ifdef AFS_64BIT_ENV + a_result->Length = tvc->m.Length; +#else /* AFS_64BIT_ENV */ +#ifdef AFS_64BIT_CLIENT + a_result->Length = tvc->m.Length; +#else /* AFS_64BIT_CLIENT */ + a_result->Length.high = 0; + a_result->Length.low = tvc->m.Length; +#endif /* AFS_64BIT_CLIENT */ +#endif /* AFS_64BIT_ENV */ + a_result->DataVersion = hgetlo(tvc->m.DataVersion); + a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */ + a_result->cbExpires = tvc->cbExpires; + a_result->refCount = VREFCOUNT(tvc); + a_result->opens = tvc->opens; + a_result->writers = tvc->execsOrWriters; + a_result->mvstat = tvc->mvstat; + a_result->states = tvc->states; + code = 0; + + /* + * Return our results. + */ + fcnDone: + XSTATS_END_TIME; + + RX_AFS_GUNLOCK(); + + return (code); + +} /*SRXAFSCB_GetCE64 */ /*------------------------------------------------------------------------ @@ -203,46 +278,47 @@ fcnDone: * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_GetLock (a_call, a_index, a_result) - struct rx_call *a_call; - afs_int32 a_index; - struct AFSDBLock *a_result; - -{ /*SRXAFSCB_GetLock*/ - - struct ltable *tl; /*Ptr to lock table entry*/ - int nentries; /*Num entries in table*/ - int code; /*Return code*/ +int +SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index, + struct AFSDBLock *a_result) +{ + struct ltable *tl; /*Ptr to lock table entry */ + int nentries; /*Num entries in table */ + int code; /*Return code */ XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETLOCK); - + AFS_STATCNT(SRXAFSCB_GetLock); - nentries = sizeof(ltable)/sizeof(struct ltable); + nentries = sizeof(ltable) / sizeof(struct ltable); if (a_index < 0 || a_index >= nentries) { /* - * Past EOF - */ + * Past EOF + */ code = 1; - } - else { + } else { /* * Found it - copy out its contents. */ tl = <able[a_index]; strcpy(a_result->name, tl->name); - a_result->lock.waitStates = ((struct afs_lock *)(tl->addr))->wait_states; - a_result->lock.exclLocked = ((struct afs_lock *)(tl->addr))->excl_locked; - a_result->lock.readersReading = ((struct afs_lock *)(tl->addr))->readers_reading; - a_result->lock.numWaiting = ((struct afs_lock *)(tl->addr))->num_waiting; + a_result->lock.waitStates = + ((struct afs_lock *)(tl->addr))->wait_states; + a_result->lock.exclLocked = + ((struct afs_lock *)(tl->addr))->excl_locked; + a_result->lock.readersReading = + ((struct afs_lock *)(tl->addr))->readers_reading; + a_result->lock.numWaiting = + ((struct afs_lock *)(tl->addr))->num_waiting; #ifdef INSTRUMENT_LOCKS - a_result->lock.pid_last_reader = ((struct afs_lock *)(tl->addr))->pid_last_reader; - a_result->lock.pid_writer = ((struct afs_lock *)(tl->addr))->pid_writer; - a_result->lock.src_indicator = ((struct afs_lock *)(tl->addr))->src_indicator; + a_result->lock.pid_last_reader = + ((struct afs_lock *)(tl->addr))->pid_last_reader; + a_result->lock.pid_writer = + ((struct afs_lock *)(tl->addr))->pid_writer; + a_result->lock.src_indicator = + ((struct afs_lock *)(tl->addr))->src_indicator; #else a_result->lock.pid_last_reader = 0; a_result->lock.pid_writer = 0; @@ -253,13 +329,11 @@ int SRXAFSCB_GetLock (a_call, a_index, a_result) XSTATS_END_TIME; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); - return(code); + return (code); -} /*SRXAFSCB_GetLock*/ +} /*SRXAFSCB_GetLock */ /*------------------------------------------------------------------------ @@ -283,21 +357,24 @@ int SRXAFSCB_GetLock (a_call, a_index, a_result) * * Side Effects: * As advertised. - *------------------------------------------------------------------------*/ -static ClearCallBack(a_conn, a_fid) - register struct rx_connection *a_conn; - register struct AFSFid *a_fid; +Appears to need to be called with GLOCK held, as the icl_Event4 stuff asserts otherwise -{ /*ClearCallBack*/ + *------------------------------------------------------------------------*/ +static int +ClearCallBack(register struct rx_connection *a_conn, + register struct AFSFid *a_fid) +{ register struct vcache *tvc; register int i; struct VenusFid localFid; - struct volume * tv; + struct volume *tv; AFS_STATCNT(ClearCallBack); + AFS_ASSERT_GLOCK(); + /* * XXXX Don't hold any server locks here because of callback protocol XXX */ @@ -307,8 +384,8 @@ static ClearCallBack(a_conn, a_fid) localFid.Fid.Unique = a_fid->Unique; /* - * Volume ID of zero means don't do anything. - */ + * Volume ID of zero means don't do anything. + */ if (a_fid->Volume != 0) { if (a_fid->Vnode == 0) { /* @@ -318,27 +395,28 @@ static ClearCallBack(a_conn, a_fid) for (i = 0; i < VCSIZE; i++) for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { if (tvc->fid.Fid.Volume == a_fid->Volume) { - tvc->callback = (struct server *)0; - tvc->quick.stamp = 0; + tvc->callback = NULL; + tvc->quick.stamp = 0; if (!localFid.Cell) localFid.Cell = tvc->fid.Cell; - tvc->h1.dchint = NULL; /* invalidate hints */ + tvc->h1.dchint = NULL; /* invalidate hints */ ObtainWriteLock(&afs_xcbhash, 449); afs_DequeueCallback(tvc); tvc->states &= ~(CStatd | CUnique | CBulkFetching); afs_allCBs++; if (tvc->fid.Fid.Vnode & 1) - afs_oddCBs++; + afs_oddCBs++; else - afs_evenCBs++; + afs_evenCBs++; ReleaseWriteLock(&afs_xcbhash); if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)) osi_dnlc_purgedp(tvc); afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK, - ICL_TYPE_POINTER, tvc, - ICL_TYPE_INT32, tvc->states, - ICL_TYPE_INT32, a_fid->Volume); - } else if ((tvc->states & CMValid) && (tvc->mvid->Fid.Volume == a_fid->Volume)) { + ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, + tvc->states, ICL_TYPE_INT32, + a_fid->Volume); + } else if ((tvc->states & CMValid) + && (tvc->mvid->Fid.Volume == a_fid->Volume)) { tvc->states &= ~CMValid; if (!localFid.Cell) localFid.Cell = tvc->mvid->Cell; @@ -350,28 +428,28 @@ static ClearCallBack(a_conn, a_fid) */ tv = afs_FindVolume(&localFid, 0); if (tv) { - afs_ResetVolumeInfo(tv); - afs_PutVolume(tv, 0); - /* invalidate mtpoint? */ + afs_ResetVolumeInfo(tv); + afs_PutVolume(tv, 0); + /* invalidate mtpoint? */ } - } /*Clear callbacks for whole volume*/ + } /*Clear callbacks for whole volume */ else { /* * Clear callbacks just for the one file. */ afs_allCBs++; if (a_fid->Vnode & 1) - afs_oddCBs++; /*Could do this on volume basis, too*/ + afs_oddCBs++; /*Could do this on volume basis, too */ else - afs_evenCBs++; /*A particular fid was specified*/ + afs_evenCBs++; /*A particular fid was specified */ i = VCHash(&localFid); for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { if (tvc->fid.Fid.Vnode == a_fid->Vnode && tvc->fid.Fid.Volume == a_fid->Volume - && tvc->fid.Fid.Unique == a_fid->Unique ) { - tvc->callback = (struct server *)0; - tvc->quick.stamp = 0; - tvc->h1.dchint = NULL; /* invalidate hints */ + && tvc->fid.Fid.Unique == a_fid->Unique) { + tvc->callback = NULL; + tvc->quick.stamp = 0; + tvc->h1.dchint = NULL; /* invalidate hints */ ObtainWriteLock(&afs_xcbhash, 450); afs_DequeueCallback(tvc); tvc->states &= ~(CStatd | CUnique | CBulkFetching); @@ -379,24 +457,25 @@ static ClearCallBack(a_conn, a_fid) if (a_fid->Vnode & 1 || (vType(tvc) == VDIR)) osi_dnlc_purgedp(tvc); afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK, - ICL_TYPE_POINTER, tvc, - ICL_TYPE_INT32, tvc->states, ICL_TYPE_LONG, 0); + ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, + tvc->states, ICL_TYPE_LONG, 0); #ifdef CBDEBUG lastCallBack_vnode = afid->Vnode; lastCallBack_dv = tvc->mstat.DataVersion.low; osi_GetuTime(&lastCallBack_time); #endif /* CBDEBUG */ } - } /*Walk through hash table*/ - } /*Clear callbacks for one file*/ - } /*Fid has non-zero volume ID*/ + } /*Walk through hash table */ + } /*Clear callbacks for one file */ + } + /*Fid has non-zero volume ID */ /* * Always return a predictable value. */ - return(0); + return (0); -} /*ClearCallBack*/ +} /*ClearCallBack */ /*------------------------------------------------------------------------ @@ -422,45 +501,39 @@ static ClearCallBack(a_conn, a_fid) * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_CallBack(a_call, a_fids, a_callbacks) - struct rx_call *a_call; - register struct AFSCBFids *a_fids; - struct AFSCBs *a_callbacks; - -{ /*SRXAFSCB_CallBack*/ - - register int i; /*Loop variable*/ - struct AFSFid *tfid; /*Ptr to current fid*/ - register struct rx_connection *tconn; /*Call's connection*/ - int code=0; +int +SRXAFSCB_CallBack(struct rx_call *a_call, register struct AFSCBFids *a_fids, + struct AFSCBs *a_callbacks) +{ + register int i; /*Loop variable */ + struct AFSFid *tfid; /*Ptr to current fid */ + register struct rx_connection *tconn; /*Call's connection */ + int code = 0; XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_CALLBACK); AFS_STATCNT(SRXAFSCB_CallBack); - if (!(tconn = rx_ConnectionOf(a_call))) return; - tfid = (struct AFSFid *) a_fids->AFSCBFids_val; - + if (!(tconn = rx_ConnectionOf(a_call))) + return (0); + tfid = (struct AFSFid *)a_fids->AFSCBFids_val; + /* * For now, we ignore callbacks, since the File Server only *breaks* * callbacks at present. */ - for (i = 0; i < a_fids->AFSCBFids_len; i++) + for (i = 0; i < a_fids->AFSCBFids_len; i++) ClearCallBack(tconn, &tfid[i]); XSTATS_END_TIME; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - - return(0); + RX_AFS_GUNLOCK(); + + return (0); -} /*SRXAFSCB_CallBack*/ +} /*SRXAFSCB_CallBack */ /*------------------------------------------------------------------------ @@ -484,28 +557,23 @@ int SRXAFSCB_CallBack(a_call, a_fids, a_callbacks) * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_Probe(a_call) - struct rx_call *a_call; - -{ /*SRXAFSCB_Probe*/ +int +SRXAFSCB_Probe(struct rx_call *a_call) +{ int code = 0; XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); AFS_STATCNT(SRXAFSCB_Probe); XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE); XSTATS_END_TIME; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); - return(0); + return (0); -} /*SRXAFSCB_Probe*/ +} /*SRXAFSCB_Probe */ /*------------------------------------------------------------------------ @@ -528,23 +596,18 @@ int SRXAFSCB_Probe(a_call) * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_InitCallBackState(a_call) - struct rx_call *a_call; - -{ /*SRXAFSCB_InitCallBackState*/ - +int +SRXAFSCB_InitCallBackState(struct rx_call *a_call) +{ register int i; register struct vcache *tvc; register struct rx_connection *tconn; register struct rx_peer *peer; struct server *ts; int code = 0; - extern int osi_dnlc_purge(); XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_INITCALLBACKSTATE); AFS_STATCNT(SRXAFSCB_InitCallBackState); @@ -555,49 +618,48 @@ int SRXAFSCB_InitCallBackState(a_call) if ((tconn = rx_ConnectionOf(a_call)) && (peer = rx_PeerOf(tconn))) { afs_allCBs++; - afs_oddCBs++; /*Including any missed via create race*/ - afs_evenCBs++; /*Including any missed via create race*/ + afs_oddCBs++; /*Including any missed via create race */ + afs_evenCBs++; /*Including any missed via create race */ - ts = afs_FindServer(rx_HostOf(peer), rx_PortOf(peer), (afsUUID *)0, 0); + ts = afs_FindServer(rx_HostOf(peer), rx_PortOf(peer), (afsUUID *) 0, + 0); if (ts) { for (i = 0; i < VCSIZE; i++) for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { if (tvc->callback == ts) { ObtainWriteLock(&afs_xcbhash, 451); afs_DequeueCallback(tvc); - tvc->callback = (struct server *)0; + tvc->callback = NULL; tvc->states &= ~(CStatd | CUnique | CBulkFetching); ReleaseWriteLock(&afs_xcbhash); } } } - - + + /* find any volumes residing on this server and flush their state */ { register struct volume *tv; register int j; - - for (i=0;inext) { - for (j=0; jnext) { + for (j = 0; j < MAXHOSTS; j++) if (tv->serverHost[j] == ts) afs_ResetVolumeInfo(tv); } } - osi_dnlc_purge(); /* may be a little bit extreme */ + osi_dnlc_purge(); /* may be a little bit extreme */ } XSTATS_END_TIME; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); - return(0); + return (0); -} /*SRXAFSCB_InitCallBackState*/ +} /*SRXAFSCB_InitCallBackState */ /*------------------------------------------------------------------------ @@ -621,30 +683,24 @@ int SRXAFSCB_InitCallBackState(a_call) * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_XStatsVersion(a_call, a_versionP) - struct rx_call *a_call; - afs_int32 *a_versionP; - -{ /*SRXAFSCB_XStatsVersion*/ - int code=0; +int +SRXAFSCB_XStatsVersion(struct rx_call *a_call, afs_int32 * a_versionP) +{ + int code = 0; XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_XSTATSVERSION); *a_versionP = AFSCB_XSTAT_VERSION; XSTATS_END_TIME; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); - return(0); -} /*SRXAFSCB_XStatsVersion*/ + return (0); +} /*SRXAFSCB_XStatsVersion */ /*------------------------------------------------------------------------ @@ -674,24 +730,17 @@ int SRXAFSCB_XStatsVersion(a_call, a_versionP) * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVersionNumP, a_timeP, a_dataP) - struct rx_call *a_call; - afs_int32 a_clientVersionNum; - afs_int32 a_collectionNumber; - afs_int32 *a_srvVersionNumP; - afs_int32 *a_timeP; - AFSCB_CollData *a_dataP; - -{ /*SRXAFSCB_GetXStats*/ - - register int code; /*Return value*/ - afs_int32 *dataBuffP; /*Ptr to data to be returned*/ - afs_int32 dataBytes; /*Bytes in data buffer*/ +int +SRXAFSCB_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum, + afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP, + afs_int32 * a_timeP, AFSCB_CollData * a_dataP) +{ + register int code; /*Return value */ + afs_int32 *dataBuffP; /*Ptr to data to be returned */ + afs_int32 dataBytes; /*Bytes in data buffer */ XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETXSTATS); @@ -712,10 +761,10 @@ int SRXAFSCB_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVers * no data. */ a_dataP->AFSCB_CollData_len = 0; - a_dataP->AFSCB_CollData_val = (afs_int32 *)0; + a_dataP->AFSCB_CollData_val = NULL; #else - switch(a_collectionNumber) { - case AFSCB_XSTATSCOLL_CALL_INFO: + switch (a_collectionNumber) { + case AFSCB_XSTATSCOLL_CALL_INFO: /* * Pass back all the call-count-related data. * @@ -724,13 +773,13 @@ int SRXAFSCB_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVers * >>> will be freed at the tail end of the server stub code. */ dataBytes = sizeof(struct afs_CMStats); - dataBuffP = (afs_int32 *)afs_osi_Alloc(dataBytes); + dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes); memcpy((char *)dataBuffP, (char *)&afs_cmstats, dataBytes); - a_dataP->AFSCB_CollData_len = dataBytes>>2; + a_dataP->AFSCB_CollData_len = dataBytes >> 2; a_dataP->AFSCB_CollData_val = dataBuffP; break; - case AFSCB_XSTATSCOLL_PERF_INFO: + case AFSCB_XSTATSCOLL_PERF_INFO: /* * Update and then pass back all the performance-related data. * Note: the only performance fields that need to be computed @@ -744,13 +793,13 @@ int SRXAFSCB_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVers afs_stats_cmperf.numPerfCalls++; afs_CountServers(); dataBytes = sizeof(afs_stats_cmperf); - dataBuffP = (afs_int32 *)afs_osi_Alloc(dataBytes); + dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes); memcpy((char *)dataBuffP, (char *)&afs_stats_cmperf, dataBytes); - a_dataP->AFSCB_CollData_len = dataBytes>>2; + a_dataP->AFSCB_CollData_len = dataBytes >> 2; a_dataP->AFSCB_CollData_val = dataBuffP; break; - case AFSCB_XSTATSCOLL_FULL_PERF_INFO: + case AFSCB_XSTATSCOLL_FULL_PERF_INFO: /* * Pass back the full range of performance and statistical * data available. We have to bring the normal performance @@ -763,35 +812,34 @@ int SRXAFSCB_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVers */ afs_stats_cmperf.numPerfCalls++; afs_CountServers(); - memcpy((char *)(&(afs_stats_cmfullperf.perf)), (char *)(&afs_stats_cmperf), sizeof(struct afs_stats_CMPerf)); + memcpy((char *)(&(afs_stats_cmfullperf.perf)), + (char *)(&afs_stats_cmperf), sizeof(struct afs_stats_CMPerf)); afs_stats_cmfullperf.numFullPerfCalls++; dataBytes = sizeof(afs_stats_cmfullperf); - dataBuffP = (afs_int32 *)afs_osi_Alloc(dataBytes); + dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes); memcpy((char *)dataBuffP, (char *)(&afs_stats_cmfullperf), dataBytes); - a_dataP->AFSCB_CollData_len = dataBytes>>2; + a_dataP->AFSCB_CollData_len = dataBytes >> 2; a_dataP->AFSCB_CollData_val = dataBuffP; break; - default: + default: /* * Illegal collection number. */ a_dataP->AFSCB_CollData_len = 0; - a_dataP->AFSCB_CollData_val = (afs_int32 *)0; + a_dataP->AFSCB_CollData_val = NULL; code = 1; - } /*Switch on collection number*/ + } /*Switch on collection number */ #endif /* AFS_NOSTATS */ XSTATS_END_TIME; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); - return(code); + return (code); -} /*SRXAFSCB_GetXStats*/ +} /*SRXAFSCB_GetXStats */ /*------------------------------------------------------------------------ @@ -813,9 +861,9 @@ int SRXAFSCB_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVers * As advertised. *------------------------------------------------------------------------*/ -int afs_RXCallBackServer() - -{ /*afs_RXCallBackServer*/ +int +afs_RXCallBackServer(void) +{ AFS_STATCNT(afs_RXCallBackServer); while (1) { @@ -828,9 +876,9 @@ int afs_RXCallBackServer() * Donate this process to Rx. */ rx_ServerProc(); - return(0); + return (0); -} /*afs_RXCallBackServer*/ +} /*afs_RXCallBackServer */ /*------------------------------------------------------------------------ @@ -852,22 +900,19 @@ int afs_RXCallBackServer() * As advertised. *------------------------------------------------------------------------*/ -int shutdown_CB() - -{ /*shutdown_CB*/ - - extern int afs_cold_shutdown; - - AFS_STATCNT(shutdown_CB); +int +shutdown_CB(void) +{ + AFS_STATCNT(shutdown_CB); - if (afs_cold_shutdown) { - afs_oddCBs = afs_evenCBs = afs_allCBs = afs_allZaps = afs_oddZaps = afs_evenZaps = - afs_connectBacks = 0; - } + if (afs_cold_shutdown) { + afs_oddCBs = afs_evenCBs = afs_allCBs = afs_allZaps = afs_oddZaps = + afs_evenZaps = afs_connectBacks = 0; + } - return(0); + return (0); -} /*shutdown_CB*/ +} /*shutdown_CB */ /*------------------------------------------------------------------------ * EXPORTED SRXAFSCB_InitCallBackState2 @@ -889,11 +934,11 @@ int shutdown_CB() * None *------------------------------------------------------------------------*/ -int SRXAFSCB_InitCallBackState2(a_call, addr) -struct rx_call *a_call; -struct interfaceAddr * addr; +int +SRXAFSCB_InitCallBackState2(struct rx_call *a_call, + struct interfaceAddr *addr) { - return RXGEN_OPCODE; + return RXGEN_OPCODE; } /*------------------------------------------------------------------------ @@ -920,26 +965,24 @@ struct interfaceAddr * addr; * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_WhoAreYou(a_call, addr) -struct rx_call *a_call; -struct interfaceAddr *addr; +int +SRXAFSCB_WhoAreYou(struct rx_call *a_call, struct interfaceAddr *addr) { int i; int code = 0; - XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); AFS_STATCNT(SRXAFSCB_WhoAreYou); + memset(addr, 0, sizeof(*addr)); + ObtainReadLock(&afs_xinterface); /* return all network interface addresses */ addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces; addr->uuid = afs_cb_interface.uuid; - for ( i=0; i < afs_cb_interface.numberOfInterfaces; i++) { + for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) { addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]); addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]); addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]); @@ -947,9 +990,7 @@ struct interfaceAddr *addr; ReleaseReadLock(&afs_xinterface); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); return code; } @@ -975,9 +1016,8 @@ struct interfaceAddr *addr; * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_InitCallBackState3(a_call, a_uuid) -struct rx_call *a_call; -afsUUID *a_uuid; +int +SRXAFSCB_InitCallBackState3(struct rx_call *a_call, afsUUID * a_uuid) { int code; @@ -988,7 +1028,7 @@ afsUUID *a_uuid; return code; } - + /*------------------------------------------------------------------------ * EXPORTED SRXAFSCB_ProbeUuid @@ -1013,30 +1053,25 @@ afsUUID *a_uuid; * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_ProbeUuid(a_call, a_uuid) -struct rx_call *a_call; -afsUUID *a_uuid; +int +SRXAFSCB_ProbeUuid(struct rx_call *a_call, afsUUID * a_uuid) { int code = 0; XSTATS_DECLS; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); AFS_STATCNT(SRXAFSCB_Probe); XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE); if (!afs_uuid_equal(a_uuid, &afs_cb_interface.uuid)) - code = 1; /* failure */ + code = 1; /* failure */ XSTATS_END_TIME; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); return code; } - + /*------------------------------------------------------------------------ * EXPORTED SRXAFSCB_GetServerPrefs @@ -1061,18 +1096,14 @@ afsUUID *a_uuid; * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_GetServerPrefs( - struct rx_call *a_call, - afs_int32 a_index, - afs_int32 *a_srvr_addr, - afs_int32 *a_srvr_rank) +int +SRXAFSCB_GetServerPrefs(struct rx_call *a_call, afs_int32 a_index, + afs_int32 * a_srvr_addr, afs_int32 * a_srvr_rank) { int i, j; struct srvAddr *sa; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); AFS_STATCNT(SRXAFSCB_GetServerPrefs); ObtainReadLock(&afs_xserver); @@ -1080,7 +1111,7 @@ int SRXAFSCB_GetServerPrefs( /* Search the hash table for the server with this index */ *a_srvr_addr = 0xffffffff; *a_srvr_rank = 0xffffffff; - for (i=0, j=0; j < NSERVERS && i <= a_index; j++) { + for (i = 0, j = 0; j < NSERVERS && i <= a_index; j++) { for (sa = afs_srvAddrs[j]; sa && i <= a_index; sa = sa->next_bkt, i++) { if (i == a_index) { *a_srvr_addr = ntohl(sa->sa_ip); @@ -1091,13 +1122,11 @@ int SRXAFSCB_GetServerPrefs( ReleaseReadLock(&afs_xserver); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); return 0; } - + /*------------------------------------------------------------------------ * EXPORTED SRXAFSCB_GetCellServDB @@ -1121,46 +1150,40 @@ int SRXAFSCB_GetServerPrefs( * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_GetCellServDB( - struct rx_call *a_call, - afs_int32 a_index, - char **a_name, - serverList *a_hosts) +int +SRXAFSCB_GetCellServDB(struct rx_call *a_call, afs_int32 a_index, + char **a_name, serverList * a_hosts) { - afs_int32 i, j; + afs_int32 i, j = 0; struct cell *tcell; - struct afs_q *cq, *tq; char *t_name, *p_name = NULL; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); AFS_STATCNT(SRXAFSCB_GetCellServDB); tcell = afs_GetCellByIndex(a_index, READ_LOCK); if (!tcell) { - i = 0; - a_hosts->serverList_val = 0; - a_hosts->serverList_len = 0; + i = 0; + a_hosts->serverList_val = 0; + a_hosts->serverList_len = 0; } else { - p_name = tcell->cellName; - for (j = 0 ; j < AFSMAXCELLHOSTS && tcell->cellHosts[j] ; j++) - ; - i = strlen(p_name); - a_hosts->serverList_val = (afs_int32 *)afs_osi_Alloc(j*sizeof(afs_int32)); - a_hosts->serverList_len = j; - for (j = 0 ; j < AFSMAXCELLHOSTS && tcell->cellHosts[j] ; j++) - a_hosts->serverList_val[j] = ntohl(tcell->cellHosts[j]->addr->sa_ip); - afs_PutCell(tcell, READ_LOCK); + p_name = tcell->cellName; + for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++); + i = strlen(p_name); + a_hosts->serverList_val = + (afs_int32 *) afs_osi_Alloc(j * sizeof(afs_int32)); + a_hosts->serverList_len = j; + for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++) + a_hosts->serverList_val[j] = + ntohl(tcell->cellHosts[j]->addr->sa_ip); + afs_PutCell(tcell, READ_LOCK); } - t_name = (char *)afs_osi_Alloc(i+1); + t_name = (char *)afs_osi_Alloc(i + 1); if (t_name == NULL) { - afs_osi_Free(a_hosts->serverList_val, (j*sizeof(afs_int32))); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + afs_osi_Free(a_hosts->serverList_val, (j * sizeof(afs_int32))); + RX_AFS_GUNLOCK(); return ENOMEM; } @@ -1168,14 +1191,12 @@ int SRXAFSCB_GetCellServDB( if (p_name) memcpy(t_name, p_name, i); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); *a_name = t_name; return 0; } - + /*------------------------------------------------------------------------ * EXPORTED SRXAFSCB_GetLocalCell @@ -1197,17 +1218,14 @@ int SRXAFSCB_GetCellServDB( * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_GetLocalCell( - struct rx_call *a_call, - char **a_name) +int +SRXAFSCB_GetLocalCell(struct rx_call *a_call, char **a_name) { int plen; struct cell *tcell; char *t_name, *p_name = NULL; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); AFS_STATCNT(SRXAFSCB_GetLocalCell); /* Search the list for the primary cell. Cell number 1 is only @@ -1220,12 +1238,11 @@ int SRXAFSCB_GetLocalCell( plen = strlen(p_name); else plen = 0; - t_name = (char *)afs_osi_Alloc(plen+1); + t_name = (char *)afs_osi_Alloc(plen + 1); if (t_name == NULL) { - if (tcell) afs_PutCell(tcell, READ_LOCK); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + if (tcell) + afs_PutCell(tcell, READ_LOCK); + RX_AFS_GUNLOCK(); return ENOMEM; } @@ -1233,12 +1250,11 @@ int SRXAFSCB_GetLocalCell( if (p_name) memcpy(t_name, p_name, plen); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); *a_name = t_name; - if (tcell) afs_PutCell(tcell, READ_LOCK); + if (tcell) + afs_PutCell(tcell, READ_LOCK); return 0; } @@ -1258,10 +1274,9 @@ int SRXAFSCB_GetLocalCell( * * Returns void. */ -static void afs_MarshallCacheConfig( - afs_uint32 callerVersion, - cm_initparams_v1 *config, - afs_uint32 *ptr) +static void +afs_MarshallCacheConfig(afs_uint32 callerVersion, cm_initparams_v1 * config, + afs_uint32 * ptr) { AFS_STATCNT(afs_MarshallCacheConfig); /* @@ -1276,9 +1291,8 @@ static void afs_MarshallCacheConfig( *(ptr++) = config->cacheSize; *(ptr++) = config->setTime; *(ptr++) = config->memCache; - } - + /*------------------------------------------------------------------------ * EXPORTED SRXAFSCB_GetCacheConfig @@ -1305,31 +1319,25 @@ static void afs_MarshallCacheConfig( * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_GetCacheConfig( - struct rx_call *a_call, - afs_uint32 callerVersion, - afs_uint32 *serverVersion, - afs_uint32 *configCount, - cacheConfig *config) +int +SRXAFSCB_GetCacheConfig(struct rx_call *a_call, afs_uint32 callerVersion, + afs_uint32 * serverVersion, afs_uint32 * configCount, + cacheConfig * config) { afs_uint32 *t_config; size_t allocsize; cm_initparams_v1 cm_config; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); AFS_STATCNT(SRXAFSCB_GetCacheConfig); /* * Currently only support version 1 */ allocsize = sizeof(cm_initparams_v1); - t_config = (afs_uint32 *)afs_osi_Alloc(allocsize); + t_config = (afs_uint32 *) afs_osi_Alloc(allocsize); if (t_config == NULL) { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); return ENOMEM; } @@ -1348,15 +1356,78 @@ int SRXAFSCB_GetCacheConfig( *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION; *configCount = allocsize; config->cacheConfig_val = t_config; - config->cacheConfig_len = allocsize/sizeof(afs_uint32); + config->cacheConfig_len = allocsize / sizeof(afs_uint32); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); return 0; } +/*------------------------------------------------------------------------ + * EXPORTED SRXAFSCB_FetchData + * + * Description: + * Routine to do third party move from a remioserver to the original + * issuer of an ArchiveData request. Presently supported only by the + * "fs" command, not by the AFS client. + * + * Arguments: + * rxcall: Ptr to Rx call on which this request came in. + * Fid: pointer to AFSFid structure. + * Fd: File descriptor inside fs command. + * Position: Offset in the file. + * Length: Data length to transfer. + * TotalLength: Pointer to total file length field + * + * Returns: + * 0 on success + * + * Environment: + * Nothing interesting. + * + * Side Effects: + *------------------------------------------------------------------------*/ +int +SRXAFSCB_FetchData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd, + afs_int64 Position, afs_int64 Length, + afs_int64 * TotalLength) +{ + return ENOSYS; +} + +/*------------------------------------------------------------------------ + * EXPORTED SRXAFSCB_StoreData + * + * Description: + * Routine to do third party move from a remioserver to the original + * issuer of a RetrieveData request. Presently supported only by the + * "fs" command, not by the AFS client. + * + * Arguments: + * rxcall: Ptr to Rx call on which this request came in. + * Fid: pointer to AFSFid structure. + * Fd: File descriptor inside fs command. + * Position: Offset in the file. + * Length: Data length to transfer. + * TotalLength: Pointer to total file length field + * + * Returns: + * 0 on success + * + * Environment: + * Nothing interesting. + * + * Side Effects: + * As advertised. + *------------------------------------------------------------------------*/ +int +SRXAFSCB_StoreData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd, + afs_int64 Position, afs_int64 Length, + afs_int64 * TotalLength) +{ + return ENOSYS; +} + /*------------------------------------------------------------------------ * EXPORTED SRXAFSCB_GetCellByNum * @@ -1380,15 +1451,14 @@ int SRXAFSCB_GetCacheConfig( * As advertised. *------------------------------------------------------------------------*/ -int SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum, - char **a_name, serverList *a_hosts) +int +SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum, + char **a_name, serverList * a_hosts) { afs_int32 i, sn; struct cell *tcell; -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); AFS_STATCNT(SRXAFSCB_GetCellByNum); a_hosts->serverList_val = 0; @@ -1397,28 +1467,61 @@ int SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum, tcell = afs_GetCellStale(a_cellnum, READ_LOCK); if (!tcell) { *a_name = afs_strdup(""); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); return 0; } ObtainReadLock(&tcell->lock); *a_name = afs_strdup(tcell->cellName); - for (sn = 0; sn < AFSMAXCELLHOSTS && tcell->cellHosts[sn]; sn++) - ; + for (sn = 0; sn < AFSMAXCELLHOSTS && tcell->cellHosts[sn]; sn++); a_hosts->serverList_len = sn; - a_hosts->serverList_val = (afs_int32 *) afs_osi_Alloc(sn*sizeof(afs_int32)); + a_hosts->serverList_val = + (afs_int32 *) afs_osi_Alloc(sn * sizeof(afs_int32)); for (i = 0; i < sn; i++) a_hosts->serverList_val[i] = ntohl(tcell->cellHosts[i]->addr->sa_ip); ReleaseReadLock(&tcell->lock); afs_PutCell(tcell, READ_LOCK); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); return 0; } - + +int +SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call, + struct interfaceAddr *addr, + Capabilities * capabilities) +{ + int i; + int code = 0; + afs_int32 *dataBuffP; + afs_int32 dataBytes; + + RX_AFS_GLOCK(); + + AFS_STATCNT(SRXAFSCB_WhoAreYou); + + ObtainReadLock(&afs_xinterface); + + /* return all network interface addresses */ + addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces; + addr->uuid = afs_cb_interface.uuid; + for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) { + addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]); + addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]); + addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]); + } + + ReleaseReadLock(&afs_xinterface); + + RX_AFS_GUNLOCK(); + + dataBytes = 1 * sizeof(afs_int32); + dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes); + dataBuffP[0] = CAPABILITY_ERRORTRANS; + capabilities->Capabilities_len = dataBytes / sizeof(afs_int32); + capabilities->Capabilities_val = dataBuffP; + + return code; +} diff --git a/src/afs/afs_cbqueue.c b/src/afs/afs_cbqueue.c index e4b3ac654..44c52f1b7 100644 --- a/src/afs/afs_cbqueue.c +++ b/src/afs/afs_cbqueue.c @@ -72,30 +72,27 @@ * granted with a shorter expiration time. */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_cbqueue.c,v 1.1.1.5 2001/09/11 14:24:37 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_cbqueue.c,v 1.9 2003/07/15 23:14:11 shadow Exp $"); -#include "../afs/sysincludes.h" /*Standard vendor system headers*/ -#include "../afs/afsincludes.h" /*AFS-based standard headers*/ -#include "../afs/afs_cbqueue.h" +#include "afs/sysincludes.h" /*Standard vendor system headers */ +#include "afsincludes.h" /*AFS-based standard headers */ +#include "afs/afs_cbqueue.h" #include "afs/afs.h" -#include "../afs/lock.h" -#include "../afs/afs_stats.h" +#include "afs/lock.h" +#include "afs/afs_stats.h" static unsigned int base = 0; static unsigned int basetime = 0; -static struct vcache *debugvc; /* used only for post-mortem debugging */ +static struct vcache *debugvc; /* used only for post-mortem debugging */ struct bucket { - struct afs_q head; - /* struct afs_lock lock; only if you want lots of locks... */ + struct afs_q head; + /* struct afs_lock lock; only if you want lots of locks... */ }; -struct bucket cbHashT[CBHTSIZE]; +static struct bucket cbHashT[CBHTSIZE]; struct afs_lock afs_xcbhash; -extern afs_int32 afs_cacheStats; -extern struct volume * afs_FindVolume(); -extern unsigned int afs_paniconwarn; -void afs_FlushCBs(); /* afs_QueueCallback * Takes a write-locked vcache pointer and a callback expiration time @@ -112,22 +109,18 @@ void afs_FlushCBs(); * NOTE: The caller must hold a write lock on afs_xcbhash */ -void afs_QueueCallback(avc, atime, avp) -struct vcache *avc; -unsigned int atime; -struct volume *avp; +void +afs_QueueCallback(struct vcache *avc, unsigned int atime, struct volume *avp) { -struct vcache *list; - -if (avp && (avp->expireTime < avc->cbExpires)) - avp->expireTime = avc->cbExpires; -if (!(avc->callsort.next)) { - atime = (atime + base) % CBHTSIZE; - QAdd(&(cbHashT[atime].head), &(avc->callsort)); -} + if (avp && (avp->expireTime < avc->cbExpires)) + avp->expireTime = avc->cbExpires; + if (!(avc->callsort.next)) { + atime = (atime + base) % CBHTSIZE; + QAdd(&(cbHashT[atime].head), &(avc->callsort)); + } -return ; -} /* afs_QueueCallback */ + return; +} /* afs_QueueCallback */ /* afs_DequeueCallback * Takes a write-locked vcache pointer and removes it from the callback @@ -141,20 +134,19 @@ return ; * * NOTE: The caller must hold a write lock on afs_xcbhash */ -void afs_DequeueCallback(avc) -struct vcache *avc; +void +afs_DequeueCallback(struct vcache *avc) { - debugvc=avc; - if (avc->callsort.prev) { - QRemove(&(avc->callsort)); - avc->callsort.prev = avc->callsort.next = NULL; - } - else ; /* must have got dequeued in a race */ - afs_symhint_inval(avc); + debugvc = avc; + if (avc->callsort.prev) { + QRemove(&(avc->callsort)); + avc->callsort.prev = avc->callsort.next = NULL; + } else; /* must have got dequeued in a race */ + afs_symhint_inval(avc); - return; -} /* afs_DequeueCallback */ + return; +} /* afs_DequeueCallback */ /* afs_CheckCallbacks * called periodically to determine which callbacks are likely to @@ -191,97 +183,97 @@ struct vcache *avc; /* Sanity check on the callback queue. Allow for slop in the computation. */ #ifdef AFS_OSF_ENV -extern afs_int32 afs_maxvcount; #define CBQ_LIMIT (afs_maxvcount + 10) #else #define CBQ_LIMIT (afs_cacheStats + afs_stats_cmperf.vcacheXAllocs + 10) #endif -void afs_CheckCallbacks(secs) -unsigned int secs; +void +afs_CheckCallbacks(unsigned int secs) { - struct vcache *tvc; - register struct afs_q *tq; - struct afs_q *uq; - afs_uint32 now; - struct volume *tvp; - register int safety; - - ObtainWriteLock(&afs_xcbhash,85); /* pretty likely I'm going to remove something */ - now=osi_Time(); - for(safety = 0, tq = cbHashT[base].head.prev; - (safety <= CBQ_LIMIT) && (tq != &(cbHashT[base].head)); - tq = uq, safety++) { - - uq = QPrev(tq); - tvc = CBQTOV(tq); - if (tvc->cbExpires < now + secs) { /* race #1 here */ - /* Get the volume, and if its callback expiration time is more than secs - * seconds into the future, update this vcache entry and requeue it below - */ - if ((tvc->states & CRO) && (tvp=afs_FindVolume(&(tvc->fid), READ_LOCK))) { - if (tvp->expireTime > now + secs) { - tvc->cbExpires = tvp->expireTime; /* XXX race here */ - } - else { - int i; - for (i=0; i < MAXHOSTS && tvp->serverHost[i]; i++) { - if (!(tvp->serverHost[i]->flags & SRVR_ISDOWN)) { - /* What about locking xvcache or vrefcount++ or - * write locking tvc? */ - QRemove(tq); - tq->prev = tq->next = NULL; - tvc->states &= ~(CStatd | CMValid | CUnique); - if ((tvc->fid.Fid.Vnode & 1) || (vType(tvc) == VDIR)) - osi_dnlc_purgedp(tvc); - tvc->quick.stamp = 0; - tvc->h1.dchint = NULL;/*invalidate em */ - afs_ResetVolumeInfo(tvp); - break; + struct vcache *tvc; + register struct afs_q *tq; + struct afs_q *uq; + afs_uint32 now; + struct volume *tvp; + register int safety; + + ObtainWriteLock(&afs_xcbhash, 85); /* pretty likely I'm going to remove something */ + now = osi_Time(); + for (safety = 0, tq = cbHashT[base].head.prev; + (safety <= CBQ_LIMIT) && (tq != &(cbHashT[base].head)); + tq = uq, safety++) { + + uq = QPrev(tq); + tvc = CBQTOV(tq); + if (tvc->cbExpires < now + secs) { /* race #1 here */ + /* Get the volume, and if its callback expiration time is more than secs + * seconds into the future, update this vcache entry and requeue it below + */ + if ((tvc->states & CRO) + && (tvp = afs_FindVolume(&(tvc->fid), READ_LOCK))) { + if (tvp->expireTime > now + secs) { + tvc->cbExpires = tvp->expireTime; /* XXX race here */ + } else { + int i; + for (i = 0; i < MAXHOSTS && tvp->serverHost[i]; i++) { + if (!(tvp->serverHost[i]->flags & SRVR_ISDOWN)) { + /* What about locking xvcache or vrefcount++ or + * write locking tvc? */ + QRemove(tq); + tq->prev = tq->next = NULL; + tvc->states &= ~(CStatd | CMValid | CUnique); + if ((tvc->fid.Fid.Vnode & 1) + || (vType(tvc) == VDIR)) + osi_dnlc_purgedp(tvc); + tvc->quick.stamp = 0; + tvc->h1.dchint = NULL; /*invalidate em */ + afs_ResetVolumeInfo(tvp); + break; + } + } } - } - } - afs_PutVolume(tvp, READ_LOCK); - } - else { - /* Do I need to worry about things like execsorwriters? - * What about locking xvcache or vrefcount++ or write locking tvc? - */ - QRemove(tq); - tq->prev = tq->next = NULL; - tvc->states &= ~(CStatd | CMValid | CUnique); - if ((tvc->fid.Fid.Vnode & 1) || (vType(tvc) == VDIR)) - osi_dnlc_purgedp(tvc); - } - } - - if ((tvc->cbExpires > basetime) && CBHash(tvc->cbExpires - basetime)) { - /* it's been renewed on us. Have to be careful not to put it back - * into this slot, or we may never get out of here. - */ - int slot; - slot = (CBHash(tvc->cbExpires - basetime)+base)%CBHTSIZE ; - if (slot != base) { - if (QPrev(tq)) - QRemove(&(tvc->callsort)); - QAdd( &(cbHashT[slot].head), &(tvc->callsort) ); - /* XXX remember to update volume expiration time */ - /* -- not needed for correctness, though */ - } + afs_PutVolume(tvp, READ_LOCK); + } else { + /* Do I need to worry about things like execsorwriters? + * What about locking xvcache or vrefcount++ or write locking tvc? + */ + QRemove(tq); + tq->prev = tq->next = NULL; + tvc->states &= ~(CStatd | CMValid | CUnique); + if ((tvc->fid.Fid.Vnode & 1) || (vType(tvc) == VDIR)) + osi_dnlc_purgedp(tvc); + } + } + + if ((tvc->cbExpires > basetime) && CBHash(tvc->cbExpires - basetime)) { + /* it's been renewed on us. Have to be careful not to put it back + * into this slot, or we may never get out of here. + */ + int slot; + slot = (CBHash(tvc->cbExpires - basetime) + base) % CBHTSIZE; + if (slot != base) { + if (QPrev(tq)) + QRemove(&(tvc->callsort)); + QAdd(&(cbHashT[slot].head), &(tvc->callsort)); + /* XXX remember to update volume expiration time */ + /* -- not needed for correctness, though */ + } + } } - } - if (safety > CBQ_LIMIT) { - afs_stats_cmperf.cbloops++; - if (afs_paniconwarn) - osi_Panic ("CheckCallbacks"); + if (safety > CBQ_LIMIT) { + afs_stats_cmperf.cbloops++; + if (afs_paniconwarn) + osi_Panic("CheckCallbacks"); - afs_warn("AFS Internal Error (minor): please contact AFS Product Support.\n"); - ReleaseWriteLock(&afs_xcbhash); - afs_FlushCBs(); - return; - } - else ReleaseWriteLock(&afs_xcbhash); + afs_warn + ("AFS Internal Error (minor): please contact AFS Product Support.\n"); + ReleaseWriteLock(&afs_xcbhash); + afs_FlushCBs(); + return; + } else + ReleaseWriteLock(&afs_xcbhash); /* XXX future optimization: @@ -289,39 +281,42 @@ unsigned int secs; { struct dcache * adc; + ObtainReadLock(&afs_xdcache); if ((adc = tvc->quick.dc) && (adc->stamp == tvc->quick.stamp) && (afs_indexTimes[adc->index] > afs_indexCounter - 20)) { queue up the stat request } + ReleaseReadLock(&afs_xdcache); } */ -return; -} /* afs_CheckCallback */ + return; +} /* afs_CheckCallback */ /* afs_FlushCBs * to be used only in dire circumstances, this drops all callbacks on * the floor, without giving them back to the server. It's ok, the server can * deal with it, but it is a little bit rude. */ -void afs_FlushCBs() +void +afs_FlushCBs(void) { - register int i; - register struct vcache *tvc; - - ObtainWriteLock(&afs_xcbhash,86); /* pretty likely I'm going to remove something */ - - for (i = 0; i < VCSIZE; i++) /* reset all the vnodes */ - for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { - tvc->callback = 0; - tvc->quick.stamp = 0; - tvc->h1.dchint = NULL; /* invalidate hints */ - tvc->states &= ~(CStatd); - if ((tvc->fid.Fid.Vnode & 1) || (vType(tvc) == VDIR)) - osi_dnlc_purgedp(tvc); - tvc->callsort.prev = tvc->callsort.next = NULL; - } - + register int i; + register struct vcache *tvc; + + ObtainWriteLock(&afs_xcbhash, 86); /* pretty likely I'm going to remove something */ + + for (i = 0; i < VCSIZE; i++) /* reset all the vnodes */ + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { + tvc->callback = 0; + tvc->quick.stamp = 0; + tvc->h1.dchint = NULL; /* invalidate hints */ + tvc->states &= ~(CStatd); + if ((tvc->fid.Fid.Vnode & 1) || (vType(tvc) == VDIR)) + osi_dnlc_purgedp(tvc); + tvc->callsort.prev = tvc->callsort.next = NULL; + } + afs_InitCBQueue(0); ReleaseWriteLock(&afs_xcbhash); @@ -332,51 +327,51 @@ void afs_FlushCBs() * the floor for a specific server, without giving them back to the server. * It's ok, the server can deal with it, but it is a little bit rude. */ -void afs_FlushServerCBs(srvp) -struct server *srvp; +void +afs_FlushServerCBs(struct server *srvp) { - register int i; - register struct vcache *tvc; - - ObtainWriteLock(&afs_xcbhash,86); /* pretty likely I'm going to remove something */ - - for (i=0; ihnext) { - if (tvc->callback == srvp) { - tvc->callback = 0; - tvc->quick.stamp = 0; - tvc->h1.dchint = NULL; /* invalidate hints */ - tvc->states &= ~(CStatd); - if ((tvc->fid.Fid.Vnode & 1) || (vType(tvc) == VDIR)) { - osi_dnlc_purgedp(tvc); - } - afs_DequeueCallback(tvc); - } - } - } - - ReleaseWriteLock(&afs_xcbhash); + register int i; + register struct vcache *tvc; + + ObtainWriteLock(&afs_xcbhash, 86); /* pretty likely I'm going to remove something */ + + for (i = 0; i < VCSIZE; i++) { /* reset all the vnodes */ + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { + if (tvc->callback == srvp) { + tvc->callback = 0; + tvc->quick.stamp = 0; + tvc->h1.dchint = NULL; /* invalidate hints */ + tvc->states &= ~(CStatd); + if ((tvc->fid.Fid.Vnode & 1) || (vType(tvc) == VDIR)) { + osi_dnlc_purgedp(tvc); + } + afs_DequeueCallback(tvc); + } + } + } + + ReleaseWriteLock(&afs_xcbhash); } /* afs_InitCBQueue * called to initialize static and global variables associated with * the Callback expiration management mechanism. */ -void afs_InitCBQueue(doLockInit) -int doLockInit; +void +afs_InitCBQueue(int doLockInit) { -register int i; - -memset((char *)cbHashT, 0, CBHTSIZE*sizeof(struct bucket)); -for (i=0;i>7) - -extern int afs_BumpBase(); -extern void afs_InitCBQueue(); -extern void afs_CheckCallbacks(); -extern void afs_DequeueCallback(); -extern void afs_QueueCallback(); +#define CBHash(t) ((t)>>7) #define CBQTOV(e) ((struct vcache *)(((char *) (e)) - (((char *)(&(((struct vcache *)(e))->callsort))) - ((char *)(e))))) - - - - - - - - - - - - - - - diff --git a/src/afs/afs_cell.c b/src/afs/afs_cell.c index 159281b8e..3a783bfeb 100644 --- a/src/afs/afs_cell.c +++ b/src/afs/afs_cell.c @@ -13,12 +13,13 @@ #include #include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_cell.c,v 1.1.1.13 2003/07/30 17:07:58 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_cell.c,v 1.30 2004/05/08 04:22:19 shadow Exp $"); #include "afs/stds.h" #include "afs/sysincludes.h" /* Standard vendor system headers */ #include "afsincludes.h" /* Afs-based standard headers */ -#include "afs/afs_stats.h" /* afs statistics */ +#include "afs/afs_stats.h" /* afs statistics */ #include "afs/afs_osi.h" /* Local variables. */ @@ -48,7 +49,8 @@ static struct { char **realname; } afsdb_req; -void afs_StopAFSDB() +void +afs_StopAFSDB() { if (afsdb_handler_running) { afs_osi_Wakeup(&afsdb_req); @@ -58,9 +60,11 @@ void afs_StopAFSDB() } } -int afs_AFSDBHandler(char *acellName, int acellNameLen, afs_int32 *kernelMsg) +int +afs_AFSDBHandler(char *acellName, int acellNameLen, afs_int32 * kernelMsg) { - if (afsdb_handler_shutdown) return -2; + if (afsdb_handler_shutdown) + return -2; afsdb_handler_running = 1; ObtainSharedLock(&afsdb_req.lock, 683); @@ -70,14 +74,15 @@ int afs_AFSDBHandler(char *acellName, int acellNameLen, afs_int32 *kernelMsg) UpgradeSToWLock(&afsdb_req.lock, 684); hostCount = kernelMsg[0]; *afsdb_req.timeout = kernelMsg[1]; - if (*afsdb_req.timeout) *afsdb_req.timeout += osi_Time(); + if (*afsdb_req.timeout) + *afsdb_req.timeout += osi_Time(); *afsdb_req.realname = afs_strdup(acellName); - for (i=0; i= hostCount) afsdb_req.cellhosts[i] = 0; else - afsdb_req.cellhosts[i] = kernelMsg[2+i]; + afsdb_req.cellhosts[i] = kernelMsg[2 + i]; } /* Request completed, wake up the relevant thread */ @@ -109,17 +114,19 @@ int afs_AFSDBHandler(char *acellName, int acellNameLen, afs_int32 *kernelMsg) return -2; } - /* Return the lookup request to userspace */ + /* Return the lookup request to userspace */ strncpy(acellName, afsdb_req.cellname, acellNameLen); ReleaseReadLock(&afsdb_req.lock); return 0; } -static int afs_GetCellHostsAFSDB(char *acellName, afs_int32 *acellHosts, - int *timeout, char **realName) +static int +afs_GetCellHostsAFSDB(char *acellName, afs_int32 * acellHosts, int *timeout, + char **realName) { AFS_ASSERT_GLOCK(); - if (!afsdb_handler_running) return ENOENT; + if (!afsdb_handler_running) + return ENOENT; ObtainWriteLock(&afsdb_client_lock, 685); ObtainWriteLock(&afsdb_req.lock, 686); @@ -150,23 +157,26 @@ static int afs_GetCellHostsAFSDB(char *acellName, afs_int32 *acellHosts, } #endif -void afs_LookupAFSDB(char *acellName) +void +afs_LookupAFSDB(char *acellName) { #ifdef AFS_AFSDB_ENV afs_int32 cellHosts[MAXCELLHOSTS]; char *realName = NULL; int code, timeout; - + code = afs_GetCellHostsAFSDB(acellName, cellHosts, &timeout, &realName); - if (code) goto done; + if (code) + goto done; code = afs_NewCell(realName, cellHosts, CNoSUID, NULL, 0, 0, timeout); - if (code && code != EEXIST) goto done; + if (code && code != EEXIST) + goto done; /* If we found an alias, create it */ if (afs_strcasecmp(acellName, realName)) afs_NewCellAlias(acellName, realName); -done: + done: if (realName) afs_osi_FreeStr(realName); #endif @@ -189,14 +199,15 @@ static int afs_cellname_inode_set; static int afs_cellname_dirty; static afs_int32 afs_cellnum_next; -static struct cell_name *afs_cellname_new(char *name, afs_int32 cellnum) +static struct cell_name * +afs_cellname_new(char *name, afs_int32 cellnum) { struct cell_name *cn; if (cellnum == 0) cellnum = afs_cellnum_next; - cn = (struct cell_name *) afs_osi_Alloc(sizeof(*cn)); + cn = (struct cell_name *)afs_osi_Alloc(sizeof(*cn)); cn->next = afs_cellname_head; cn->cellnum = cellnum; cn->cellname = afs_strdup(name); @@ -209,7 +220,8 @@ static struct cell_name *afs_cellname_new(char *name, afs_int32 cellnum) return cn; } -static struct cell_name *afs_cellname_lookup_id(afs_int32 cellnum) +static struct cell_name * +afs_cellname_lookup_id(afs_int32 cellnum) { struct cell_name *cn; @@ -220,7 +232,8 @@ static struct cell_name *afs_cellname_lookup_id(afs_int32 cellnum) return NULL; } -static struct cell_name *afs_cellname_lookup_name(char *name) +static struct cell_name * +afs_cellname_lookup_name(char *name) { struct cell_name *cn; @@ -231,7 +244,8 @@ static struct cell_name *afs_cellname_lookup_name(char *name) return NULL; } -static void afs_cellname_ref(struct cell_name *cn) +static void +afs_cellname_ref(struct cell_name *cn) { if (!cn->used) { cn->used = 1; @@ -239,7 +253,8 @@ static void afs_cellname_ref(struct cell_name *cn) } } -int afs_cellname_init(ino_t inode, int lookupcode) +int +afs_cellname_init(ino_t inode, int lookupcode) { struct osi_file *tfile; int cc, off = 0; @@ -301,8 +316,8 @@ int afs_cellname_init(ino_t inode, int lookupcode) off += cc; cellname[clen] = '\0'; - if (afs_cellname_lookup_name(cellname) || - afs_cellname_lookup_id(cellnum)) { + if (afs_cellname_lookup_name(cellname) + || afs_cellname_lookup_id(cellnum)) { afs_osi_Free(cellname, clen + 1); break; } @@ -316,7 +331,8 @@ int afs_cellname_init(ino_t inode, int lookupcode) return 0; } -int afs_cellname_write() +int +afs_cellname_write(void) { struct osi_file *tfile; struct cell_name *cn; @@ -383,9 +399,10 @@ int afs_cellname_write() struct cell_alias *afs_cellalias_head; /* Export for kdump */ static afs_int32 afs_cellalias_index; -static int afs_CellOrAliasExists_nl(char *aname); /* Forward declaration */ +static int afs_CellOrAliasExists_nl(char *aname); /* Forward declaration */ -static struct cell_alias *afs_FindCellAlias(char *alias) +static struct cell_alias * +afs_FindCellAlias(char *alias) { struct cell_alias *tc; @@ -395,7 +412,8 @@ static struct cell_alias *afs_FindCellAlias(char *alias) return tc; } -struct cell_alias *afs_GetCellAlias(int index) +struct cell_alias * +afs_GetCellAlias(int index) { struct cell_alias *tc; @@ -408,12 +426,14 @@ struct cell_alias *afs_GetCellAlias(int index) return tc; } -void afs_PutCellAlias(struct cell_alias *a) +void +afs_PutCellAlias(struct cell_alias *a) { return; } -afs_int32 afs_NewCellAlias(char *alias, char *cell) +afs_int32 +afs_NewCellAlias(char *alias, char *cell) { struct cell_alias *tc; @@ -424,7 +444,7 @@ afs_int32 afs_NewCellAlias(char *alias, char *cell) } UpgradeSToWLock(&afs_xcell, 682); - tc = (struct cell_alias *) afs_osi_Alloc(sizeof(struct cell_alias)); + tc = (struct cell_alias *)afs_osi_Alloc(sizeof(struct cell_alias)); tc->alias = afs_strdup(alias); tc->cell = afs_strdup(cell); tc->next = afs_cellalias_head; @@ -463,9 +483,10 @@ afs_int32 afs_NewCellAlias(char *alias, char *cell) struct afs_q CellLRU; /* Export for kdump */ static char *afs_thiscell; -static afs_int32 afs_cellindex; +afs_int32 afs_cellindex; /* Export for kdump */ -static void afs_UpdateCellLRU(struct cell *c) +static void +afs_UpdateCellLRU(struct cell *c) { ObtainWriteLock(&afs_xcell, 100); QRemove(&c->lruq); @@ -473,7 +494,8 @@ static void afs_UpdateCellLRU(struct cell *c) ReleaseWriteLock(&afs_xcell); } -static void afs_RefreshCell(struct cell *ac) +static void +afs_RefreshCell(struct cell *ac) { if (ac->states & CNoAFSDB) return; @@ -481,22 +503,33 @@ static void afs_RefreshCell(struct cell *ac) afs_LookupAFSDB(ac->cellName); } -static void *afs_TraverseCells_nl(void *(*cb)(struct cell *, void *), void *arg) +static void * +afs_TraverseCells_nl(void *(*cb) (struct cell *, void *), void *arg) { struct afs_q *cq, *tq; struct cell *tc; void *ret = NULL; for (cq = CellLRU.next; cq != &CellLRU; cq = tq) { - tc = QTOC(cq); tq = QNext(cq); + tc = QTOC(cq); + + /* This is assuming that a NULL return is acceptable. */ + if (cq) { + tq = QNext(cq); + } else { + return NULL; + } + ret = cb(tc, arg); - if (ret) break; + if (ret) + break; } return ret; } -void *afs_TraverseCells(void *(*cb)(struct cell *, void *), void *arg) +void * +afs_TraverseCells(void *(*cb) (struct cell *, void *), void *arg) { void *ret; @@ -507,32 +540,43 @@ void *afs_TraverseCells(void *(*cb)(struct cell *, void *), void *arg) return ret; } -static void *afs_choose_cell_by_name(struct cell *cell, void *arg) +static void * +afs_choose_cell_by_name(struct cell *cell, void *arg) { - return strcmp(cell->cellName, (char *) arg) ? NULL : cell; + if (!arg) { + /* Safety net */ + return cell; + } else { + return strcmp(cell->cellName, (char *)arg) ? NULL : cell; + } } -static void *afs_choose_cell_by_num(struct cell *cell, void *arg) +static void * +afs_choose_cell_by_num(struct cell *cell, void *arg) { return (cell->cellNum == *((afs_int32 *) arg)) ? cell : NULL; } -static void *afs_choose_cell_by_index(struct cell *cell, void *arg) +static void * +afs_choose_cell_by_index(struct cell *cell, void *arg) { return (cell->cellIndex == *((afs_int32 *) arg)) ? cell : NULL; } -static struct cell *afs_FindCellByName_nl(char *acellName, afs_int32 locktype) +static struct cell * +afs_FindCellByName_nl(char *acellName, afs_int32 locktype) { return afs_TraverseCells_nl(&afs_choose_cell_by_name, acellName); } -static struct cell *afs_FindCellByName(char *acellName, afs_int32 locktype) +static struct cell * +afs_FindCellByName(char *acellName, afs_int32 locktype) { return afs_TraverseCells(&afs_choose_cell_by_name, acellName); } -struct cell *afs_GetCellByName(char *acellName, afs_int32 locktype) +struct cell * +afs_GetCellByName(char *acellName, afs_int32 locktype) { struct cell *tc; @@ -550,7 +594,8 @@ struct cell *afs_GetCellByName(char *acellName, afs_int32 locktype) return tc; } -struct cell *afs_GetCell(afs_int32 cellnum, afs_int32 locktype) +struct cell * +afs_GetCell(afs_int32 cellnum, afs_int32 locktype) { struct cell *tc; struct cell_name *cn; @@ -568,7 +613,8 @@ struct cell *afs_GetCell(afs_int32 cellnum, afs_int32 locktype) return tc; } -struct cell *afs_GetCellStale(afs_int32 cellnum, afs_int32 locktype) +struct cell * +afs_GetCellStale(afs_int32 cellnum, afs_int32 locktype) { struct cell *tc; @@ -580,7 +626,8 @@ struct cell *afs_GetCellStale(afs_int32 cellnum, afs_int32 locktype) return tc; } -struct cell *afs_GetCellByIndex(afs_int32 index, afs_int32 locktype) +struct cell * +afs_GetCellByIndex(afs_int32 index, afs_int32 locktype) { struct cell *tc; @@ -590,17 +637,31 @@ struct cell *afs_GetCellByIndex(afs_int32 index, afs_int32 locktype) return tc; } -struct cell *afs_GetPrimaryCell(afs_int32 locktype) +struct cell * +afs_GetPrimaryCell(afs_int32 locktype) { return afs_GetCellByName(afs_thiscell, locktype); } -int afs_IsPrimaryCell(struct cell *cell) +int +afs_IsPrimaryCell(struct cell *cell) { - return strcmp(cell->cellName, afs_thiscell) ? 0 : 1; + /* Simple safe checking */ + if (!cell) { + return 0; + } else if (!afs_thiscell) { + /* This is simply a safety net to avoid seg faults especially when + * using a user-space library. afs_SetPrimaryCell() should be set + * prior to this call. */ + afs_SetPrimaryCell(cell->cellName); + return 1; + } else { + return strcmp(cell->cellName, afs_thiscell) ? 0 : 1; + } } -int afs_IsPrimaryCellNum(afs_int32 cellnum) +int +afs_IsPrimaryCellNum(afs_int32 cellnum) { struct cell *tc; int primary = 0; @@ -614,7 +675,8 @@ int afs_IsPrimaryCellNum(afs_int32 cellnum) return primary; } -afs_int32 afs_SetPrimaryCell(char *acellName) +afs_int32 +afs_SetPrimaryCell(char *acellName) { ObtainWriteLock(&afs_xcell, 691); if (afs_thiscell) @@ -624,11 +686,12 @@ afs_int32 afs_SetPrimaryCell(char *acellName) return 0; } -afs_int32 afs_NewCell(char *acellName, afs_int32 *acellHosts, int aflags, - char *linkedcname, u_short fsport, u_short vlport, int timeout) +afs_int32 +afs_NewCell(char *acellName, afs_int32 * acellHosts, int aflags, + char *linkedcname, u_short fsport, u_short vlport, int timeout) { - struct cell *tc, *tcl=0; - afs_int32 i, newc=0, code=0; + struct cell *tc, *tcl = 0; + afs_int32 i, newc = 0, code = 0; AFS_STATCNT(afs_NewCell); @@ -638,8 +701,8 @@ afs_int32 afs_NewCell(char *acellName, afs_int32 *acellHosts, int aflags, if (tc) { aflags &= ~CNoSUID; } else { - tc = (struct cell *) afs_osi_Alloc(sizeof(struct cell)); - memset((char *) tc, 0, sizeof(*tc)); + tc = (struct cell *)afs_osi_Alloc(sizeof(struct cell)); + memset((char *)tc, 0, sizeof(*tc)); tc->cellName = afs_strdup(acellName); tc->fsport = AFS_FSPORT; tc->vlport = AFS_VLPORT; @@ -657,21 +720,24 @@ afs_int32 afs_NewCell(char *acellName, afs_int32 *acellHosts, int aflags, * it must get servers from AFSDB. */ if (timeout && !tc->timeout && tc->cellHosts[0]) { - code = EEXIST; /* This code is checked for in afs_LookupAFSDB */ + code = EEXIST; /* This code is checked for in afs_LookupAFSDB */ goto bad; } /* we don't want to keep pinging old vlservers which were down, * since they don't matter any more. It's easier to do this than * to remove the server from its various hash tables. */ - for (i=0; icellHosts[i]) break; + for (i = 0; i < MAXCELLHOSTS; i++) { + if (!tc->cellHosts[i]) + break; tc->cellHosts[i]->flags &= ~SRVR_ISDOWN; tc->cellHosts[i]->flags |= SRVR_ISGONE; } - if (fsport) tc->fsport = fsport; - if (vlport) tc->vlport = vlport; + if (fsport) + tc->fsport = fsport; + if (vlport) + tc->vlport = vlport; if (aflags & CLinkedCell) { if (!linkedcname) { @@ -694,10 +760,11 @@ afs_int32 afs_NewCell(char *acellName, afs_int32 *acellHosts, int aflags, tc->timeout = timeout; memset((char *)tc->cellHosts, 0, sizeof(tc->cellHosts)); - for (i=0; ivlport, WRITE_LOCK, NULL, 0); ts->cell = tc; ts->flags &= ~SRVR_ISGONE; @@ -726,7 +793,7 @@ afs_int32 afs_NewCell(char *acellName, afs_int32 *acellHosts, int aflags, afs_DynrootInvalidate(); return 0; -bad: + bad: if (newc) { afs_osi_FreeStr(tc->cellName); afs_osi_Free(tc, sizeof(struct cell)); @@ -747,7 +814,8 @@ bad: * afs_CellNumValid: check if a cell number is valid (also set the used flag) */ -void afs_CellInit() +void +afs_CellInit() { RWLOCK_INIT(&afs_xcell, "afs_xcell"); #ifdef AFS_AFSDB_ENV @@ -759,7 +827,8 @@ void afs_CellInit() afs_cellalias_index = 0; } -void shutdown_cell() +void +shutdown_cell() { struct afs_q *cq, *tq; struct cell *tc; @@ -767,25 +836,42 @@ void shutdown_cell() RWLOCK_INIT(&afs_xcell, "afs_xcell"); for (cq = CellLRU.next; cq != &CellLRU; cq = tq) { - tc = QTOC(cq); tq = QNext(cq); - if (tc->cellName) afs_osi_FreeStr(tc->cellName); + tc = QTOC(cq); + tq = QNext(cq); + if (tc->cellName) + afs_osi_FreeStr(tc->cellName); afs_osi_Free(tc, sizeof(struct cell)); } QInit(&CellLRU); + +{ + struct cell_name *cn = afs_cellname_head; + + while (cn) { + struct cell_name *next = cn->next; + + afs_osi_FreeStr(cn->cellname); + afs_osi_Free(cn, sizeof(struct cell_name)); + cn = next; + } +} } -void afs_RemoveCellEntry(struct server *srvp) +void +afs_RemoveCellEntry(struct server *srvp) { struct cell *tc; afs_int32 j, k; tc = srvp->cell; - if (!tc) return; + if (!tc) + return; /* Remove the server structure from the cell list - if there */ ObtainWriteLock(&tc->lock, 200); - for (j=k=0; jcellHosts[j]) break; + for (j = k = 0; j < MAXCELLHOSTS; j++) { + if (!tc->cellHosts[j]) + break; if (tc->cellHosts[j] != srvp) { tc->cellHosts[k++] = tc->cellHosts[j]; } @@ -793,13 +879,14 @@ void afs_RemoveCellEntry(struct server *srvp) if (k == 0) { /* What do we do if we remove the last one? */ } - for (; kcellHosts[k] = 0; } ReleaseWriteLock(&tc->lock); } -static int afs_CellOrAliasExists_nl(char *aname) +static int +afs_CellOrAliasExists_nl(char *aname) { struct cell *c; struct cell_alias *ca; @@ -819,7 +906,8 @@ static int afs_CellOrAliasExists_nl(char *aname) return 0; } -int afs_CellOrAliasExists(char *aname) +int +afs_CellOrAliasExists(char *aname) { int ret; @@ -830,7 +918,8 @@ int afs_CellOrAliasExists(char *aname) return ret; } -int afs_CellNumValid(afs_int32 cellnum) +int +afs_CellNumValid(afs_int32 cellnum) { struct cell_name *cn; diff --git a/src/afs/afs_chunk.c b/src/afs/afs_chunk.c index 749045afb..8d8e3131e 100644 --- a/src/afs/afs_chunk.c +++ b/src/afs/afs_chunk.c @@ -8,14 +8,15 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_chunk.c,v 1.1.1.4 2001/07/14 22:19:18 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_chunk.c,v 1.6 2003/07/15 23:14:11 shadow Exp $"); -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* * Chunk module. @@ -26,20 +27,22 @@ afs_int32 afs_OtherCSize = AFS_DEFAULTCSIZE; afs_int32 afs_LogChunk = AFS_DEFAULTLSIZE; #ifdef notdef -int afs_ChunkOffset(offset) - afs_int32 offset; +int +afs_ChunkOffset(offset) + afs_int32 offset; { AFS_STATCNT(afs_ChunkOffset); - if (offset < afs_FirstCSize) + if (offset < afs_FirstCSize) return offset; else return ((offset - afs_FirstCSize) & (afs_OtherCSize - 1)); } -int afs_Chunk(offset) - afs_int32 offset; +int +afs_Chunk(offset) + afs_int32 offset; { AFS_STATCNT(afs_Chunk); if (offset < afs_FirstCSize) @@ -49,19 +52,22 @@ int afs_Chunk(offset) } -int afs_ChunkBase(offset) - int offset; +int +afs_ChunkBase(offset) + int offset; { AFS_STATCNT(afs_ChunkBase); if (offset < afs_FirstCSize) return 0; else - return (((offset - afs_FirstCSize) & ~(afs_OtherCSize - 1)) + afs_FirstCSize); + return (((offset - afs_FirstCSize) & ~(afs_OtherCSize - 1)) + + afs_FirstCSize); } -int afs_ChunkSize(offset) - afs_int32 offset; +int +afs_ChunkSize(offset) + afs_int32 offset; { AFS_STATCNT(afs_ChunkSize); if (offset < afs_FirstCSize) @@ -71,19 +77,21 @@ int afs_ChunkSize(offset) } -int afs_ChunkToBase(chunk) - afs_int32 chunk; +int +afs_ChunkToBase(chunk) + afs_int32 chunk; { AFS_STATCNT(afs_ChunkToBase); if (chunk == 0) return 0; - else + else return (afs_FirstCSize + ((chunk - 1) << afs_LogChunk)); } -int afs_ChunkToSize(chunk) - afs_int32 chunk; +int +afs_ChunkToSize(chunk) + afs_int32 chunk; { AFS_STATCNT(afs_ChunkToSize); if (chunk == 0) @@ -93,12 +101,13 @@ int afs_ChunkToSize(chunk) } /* sizes are a power of two */ -int afs_SetChunkSize(chunk) +int +afs_SetChunkSize(chunk) afs_int32 chunk; - { - AFS_STATCNT(afs_SetChunkSize); - afs_LogChunk = chunk; - afs_FirstCSize = afs_OtherCSize = (1 << chunk); - } +{ + AFS_STATCNT(afs_SetChunkSize); + afs_LogChunk = chunk; + afs_FirstCSize = afs_OtherCSize = (1 << chunk); +} #endif /* notdef */ diff --git a/src/afs/afs_chunkops.h b/src/afs/afs_chunkops.h index caff5665a..9a482dc3f 100644 --- a/src/afs/afs_chunkops.h +++ b/src/afs/afs_chunkops.h @@ -26,8 +26,6 @@ #else /* AFS_NOCHUNKING */ -extern afs_int32 afs_OtherCSize, afs_LogChunk, afs_FirstCSize; - #define AFS_OTHERCSIZE (afs_OtherCSize) #define AFS_LOGCHUNK (afs_LogChunk) #define AFS_FIRSTCSIZE (afs_FirstCSize) @@ -37,21 +35,8 @@ extern afs_int32 afs_OtherCSize, afs_LogChunk, afs_FirstCSize; #endif /* AFS_NOCHUNKING */ -#define AFS_MINCHUNK 13 /* 8k is minimum */ -#define AFS_MAXCHUNK 18 /* 256K is maximum */ - -#ifdef notdef -extern int afs_ChunkOffset(), afs_Chunk(), afs_ChunkBase(), afs_ChunkSize(), - afs_ChunkToBase(), afs_ChunkToSize(); - -/* macros */ -#define AFS_CHUNKOFFSET(x) afs_ChunkOffset(x) -#define AFS_CHUNK(x) afs_Chunk(x) -#define AFS_CHUNKBASE(x) afs_ChunkBase(x) -#define AFS_CHUNKSIZE(x) afs_ChunkSize(x) -#define AFS_CHUNKTOBASE(x) afs_ChunkToBase(x) -#define AFS_CHUNKTOSIZE(x) afs_ChunkToSize(x) -#endif +#define AFS_MINCHUNK 13 /* 8k is minimum */ +#define AFS_MAXCHUNK 18 /* 256K is maximum */ #define AFS_CHUNKOFFSET(offset) ((offset < afs_FirstCSize) ? offset : \ ((offset - afs_FirstCSize) & (afs_OtherCSize - 1))) @@ -66,7 +51,7 @@ extern int afs_ChunkOffset(), afs_Chunk(), afs_ChunkBase(), afs_ChunkSize(), afs_OtherCSize) #define AFS_CHUNKTOBASE(chunk) ((chunk == 0) ? 0 : \ - (afs_FirstCSize + ((chunk - 1) << afs_LogChunk))) + ((afs_size_t) afs_FirstCSize + ((afs_size_t) (chunk - 1) << afs_LogChunk))) #define AFS_CHUNKTOSIZE(chunk) ((chunk == 0) ? afs_FirstCSize : afs_OtherCSize) @@ -74,28 +59,40 @@ extern int afs_ChunkOffset(), afs_Chunk(), afs_ChunkBase(), afs_ChunkSize(), #define AFS_SETCHUNKSIZE(chunk) { afs_LogChunk = chunk; \ afs_FirstCSize = afs_OtherCSize = (1 << chunk); } - -extern void afs_CacheTruncateDaemon(); - /* * Functions exported by a cache type */ -extern struct afs_cacheOps *afs_cacheType; - struct afs_cacheOps { - void *(*open)(); - int (*truncate)(); - int (*fread)(); - int (*fwrite)(); - int (*close)(); - int (*vread)(); - int (*vwrite)(); - int (*FetchProc)(); - int (*StoreProc)(); - struct dcache *(*GetDSlot)(); - struct volume *(*GetVolSlot)(); - int (*HandleLink)(); +#if defined(AFS_SUN57_64BIT_ENV) || defined(AFS_SGI62_ENV) + void *(*open) (ino_t ainode); +#else + void *(*open) (afs_int32 ainode); +#endif + int (*truncate) (struct osi_file * fp, afs_int32 len); + int (*fread) (struct osi_file * fp, int offset, void *buf, afs_int32 len); + int (*fwrite) (struct osi_file * fp, afs_int32 offset, void *buf, + afs_int32 len); + int (*close) (struct osi_file * fp); + int (*vread) (register struct vcache * avc, struct uio * auio, + struct AFS_UCRED * acred, daddr_t albn, struct buf ** abpp, + int noLock); + int (*vwrite) (register struct vcache * avc, struct uio * auio, int aio, + struct AFS_UCRED * acred, int noLock); + int (*FetchProc) (register struct rx_call * acall, + struct osi_file * afile, afs_size_t abase, + struct dcache * adc, struct vcache * avc, + afs_size_t * abytesToXferP, afs_size_t * abytesXferredP, + afs_int32 lengthFound); + int (*StoreProc) (register struct rx_call * acall, + struct osi_file * afile, register afs_int32 alen, + struct vcache * avc, int *shouldWake, + afs_size_t * abytesToXferP, + afs_size_t * abytesXferredP); + struct dcache *(*GetDSlot) (register afs_int32 aslot, + register struct dcache * tmpdc); + struct volume *(*GetVolSlot) (void); + int (*HandleLink) (register struct vcache * avc, struct vrequest * areq); }; /* Ideally we should have used consistent naming - like COP_OPEN, COP_TRUNCATE, etc. */ @@ -108,12 +105,9 @@ struct afs_cacheOps { #define afs_GetVolSlot() (*(afs_cacheType->GetVolSlot))() #define afs_HandleLink(avc, areq) (*(afs_cacheType->HandleLink))(avc, areq) -#define afs_CacheFetchProc(call, file, base, adc, avc, toxfer, xfered) \ - (*(afs_cacheType->FetchProc))(call, file, base, adc, avc, toxfer, xfered) +#define afs_CacheFetchProc(call, file, base, adc, avc, toxfer, xfered, length) \ + (*(afs_cacheType->FetchProc))(call, file, (afs_size_t)base, adc, avc, (afs_size_t *)toxfer, (afs_size_t *)xfered, length) #define afs_CacheStoreProc(call, file, bytes, avc, wake, toxfer, xfered) \ (*(afs_cacheType->StoreProc))(call, file, bytes, avc, wake, toxfer, xfered) #endif /* AFS_CHUNKOPS */ - - - diff --git a/src/afs/afs_conn.c b/src/afs/afs_conn.c index d8aeb9a04..404dda10a 100644 --- a/src/afs/afs_conn.c +++ b/src/afs/afs_conn.c @@ -11,12 +11,13 @@ * Implements: */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_conn.c,v 1.1.1.9 2003/07/30 17:07:59 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_conn.c,v 1.13 2003/07/15 23:14:11 shadow Exp $"); -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ #if !defined(UKERNEL) #if !defined(AFS_LINUX20_ENV) @@ -25,15 +26,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_conn.c,v 1.1.1.9 2003/07/30 17: #include #ifdef AFS_SGI62_ENV -#include "../h/hashing.h" +#include "h/hashing.h" #endif #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV) #include #endif /* ! AFS_HPUX110_ENV */ #endif /* !defined(UKERNEL) */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ #if defined(AFS_SUN56_ENV) #include @@ -44,147 +45,135 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_conn.c,v 1.1.1.9 2003/07/30 17: #include #endif -/* Imported variables */ -/* these are for storing alternate interface addresses - from afs_callback.c */ -extern struct interfaceAddr afs_cb_interface; - - -/* Imported functions. */ -struct rx_securityClass *rxnull_NewClientSecurityObject(); -struct rx_securityClass *rxkad_NewClientSecurityObject(); - /* Exported variables */ -afs_rwlock_t afs_xconn; /* allocation lock for new things */ -afs_rwlock_t afs_xinterface; /* for multiple client address */ - -/* Local variables */ -afs_int32 cryptall = 0; +afs_rwlock_t afs_xconn; /* allocation lock for new things */ +afs_rwlock_t afs_xinterface; /* for multiple client address */ +afs_int32 cryptall = 0; /* encrypt all communications */ unsigned int VNOSERVERS = 0; -struct conn *afs_Conn(afid, areq, locktype) - register struct VenusFid *afid; - register struct vrequest *areq; - afs_int32 locktype; +struct conn * +afs_Conn(register struct VenusFid *afid, register struct vrequest *areq, + afs_int32 locktype) { - u_short fsport=AFS_FSPORT; - struct volume *tv; - struct conn *tconn = (struct conn *)0; - struct srvAddr *lowp= (struct srvAddr *)0; - struct unixuser *tu; - int notbusy; - int i; - struct srvAddr *sa1p; - - AFS_STATCNT(afs_Conn); - tv = afs_GetVolume(afid, areq, READ_LOCK); - if (!tv) { - if (areq) { - afs_FinalizeReq(areq); - areq->volumeError = 1; - } - return (struct conn *) 0; - } - - if (tv->serverHost[0] && tv->serverHost[0]->cell) { - fsport = tv->serverHost[0]->cell->fsport; - } - else { - VNOSERVERS++; - } - - /* First is always lowest rank, if it's up */ - if ((tv->status[0] == not_busy) && tv->serverHost[0] && - !(tv->serverHost[0]->addr->sa_flags & SRVR_ISDOWN)) - lowp = tv->serverHost[0]->addr; - - /* Otherwise we look at all of them. There are seven levels of - * not_busy. This means we will check a volume seven times before it - * is marked offline. Ideally, we only need two levels, but this - * serves a second purpose of waiting some number of seconds before - * the client decides the volume is offline (ie: a clone could finish - * in this time). - */ - for (notbusy = not_busy; (!lowp && (notbusy <= end_not_busy)); notbusy++) { - for (i=0 ;iserverHost[i];i++) { - if (tv->status[i] != notbusy) { - if (tv->status[i] == rd_busy || tv->status[i] == rdwr_busy) { - if (!areq->busyCount) - areq->busyCount++; - } else if (tv->status[i] == offline) { - if (!areq->volumeError) - areq->volumeError = VOLMISSING; + u_short fsport = AFS_FSPORT; + struct volume *tv; + struct conn *tconn = NULL; + struct srvAddr *lowp = NULL; + struct unixuser *tu; + int notbusy; + int i; + struct srvAddr *sa1p; + + AFS_STATCNT(afs_Conn); + tv = afs_GetVolume(afid, areq, READ_LOCK); + if (!tv) { + if (areq) { + afs_FinalizeReq(areq); + areq->volumeError = 1; + } + return NULL; + } + + if (tv->serverHost[0] && tv->serverHost[0]->cell) { + fsport = tv->serverHost[0]->cell->fsport; + } else { + VNOSERVERS++; + } + + /* First is always lowest rank, if it's up */ + if ((tv->status[0] == not_busy) && tv->serverHost[0] + && !(tv->serverHost[0]->addr->sa_flags & SRVR_ISDOWN)) + lowp = tv->serverHost[0]->addr; + + /* Otherwise we look at all of them. There are seven levels of + * not_busy. This means we will check a volume seven times before it + * is marked offline. Ideally, we only need two levels, but this + * serves a second purpose of waiting some number of seconds before + * the client decides the volume is offline (ie: a clone could finish + * in this time). + */ + for (notbusy = not_busy; (!lowp && (notbusy <= end_not_busy)); notbusy++) { + for (i = 0; i < MAXHOSTS && tv->serverHost[i]; i++) { + if (tv->status[i] != notbusy) { + if (tv->status[i] == rd_busy || tv->status[i] == rdwr_busy) { + if (!areq->busyCount) + areq->busyCount++; + } else if (tv->status[i] == offline) { + if (!areq->volumeError) + areq->volumeError = VOLMISSING; + } + continue; } - continue; - } - for (sa1p = tv->serverHost[i]->addr; sa1p; sa1p = sa1p->next_sa) { - if (sa1p->sa_flags & SRVR_ISDOWN) - continue; - if (!lowp || (lowp->sa_iprank > sa1p->sa_iprank)) - lowp = sa1p; - } - } - } - afs_PutVolume(tv, READ_LOCK); - - if (lowp) { - tu = afs_GetUser(areq->uid, afid->Cell, SHARED_LOCK); - tconn = afs_ConnBySA(lowp, fsport, afid->Cell, tu, - 0/*!force*/, 1/*create*/, locktype); - - afs_PutUser(tu, SHARED_LOCK); - } - - return tconn; -} /*afs_Conn*/ - - -struct conn *afs_ConnBySA(struct srvAddr *sap, unsigned short aport, - afs_int32 acell, struct unixuser *tu, - int force_if_down, afs_int32 create, afs_int32 locktype) + for (sa1p = tv->serverHost[i]->addr; sa1p; sa1p = sa1p->next_sa) { + if (sa1p->sa_flags & SRVR_ISDOWN) + continue; + if (!lowp || (lowp->sa_iprank > sa1p->sa_iprank)) + lowp = sa1p; + } + } + } + afs_PutVolume(tv, READ_LOCK); + + if (lowp) { + tu = afs_GetUser(areq->uid, afid->Cell, SHARED_LOCK); + tconn = afs_ConnBySA(lowp, fsport, afid->Cell, tu, 0 /*!force */ , + 1 /*create */ , locktype); + + afs_PutUser(tu, SHARED_LOCK); + } + + return tconn; +} /*afs_Conn */ + + +struct conn * +afs_ConnBySA(struct srvAddr *sap, unsigned short aport, afs_int32 acell, + struct unixuser *tu, int force_if_down, afs_int32 create, + afs_int32 locktype) { - struct conn *tc=0; - struct rx_securityClass *csec; /*Security class object*/ - int isec; /*Security index*/ + struct conn *tc = 0; + struct rx_securityClass *csec; /*Security class object */ + int isec; /*Security index */ int service; if (!sap || ((sap->sa_flags & SRVR_ISDOWN) && !force_if_down)) { /* sa is known down, and we don't want to force it. */ - return (struct conn *)0; + return NULL; } - ObtainSharedLock(&afs_xconn,15); - for (tc = sap->conns; tc; tc=tc->next) { - if (tc->user == tu && tc->port == aport) { - break; - } - } + ObtainSharedLock(&afs_xconn, 15); + for (tc = sap->conns; tc; tc = tc->next) { + if (tc->user == tu && tc->port == aport) { + break; + } + } if (!tc && !create) { - ReleaseSharedLock(&afs_xconn); - return (struct conn *)0; + ReleaseSharedLock(&afs_xconn); + return NULL; } if (!tc) { - /* No such connection structure exists. Create one and splice it in. - * Make sure the server record has been marked as used (for the purposes - * of calculating up & down times, it's now considered to be an - * ``active'' server). Also make sure the server's lastUpdateEvalTime - * gets set, marking the time of its ``birth''. - */ - UpgradeSToWLock(&afs_xconn,37); - tc = (struct conn *) afs_osi_Alloc(sizeof(struct conn)); + /* No such connection structure exists. Create one and splice it in. + * Make sure the server record has been marked as used (for the purposes + * of calculating up & down times, it's now considered to be an + * ``active'' server). Also make sure the server's lastUpdateEvalTime + * gets set, marking the time of its ``birth''. + */ + UpgradeSToWLock(&afs_xconn, 37); + tc = (struct conn *)afs_osi_Alloc(sizeof(struct conn)); memset((char *)tc, 0, sizeof(struct conn)); tc->user = tu; tc->port = aport; tc->srvr = sap; - tc->refCount = 0; /* bumped below */ + tc->refCount = 0; /* bumped below */ tc->forceConnectFS = 1; - tc->id = (struct rx_connection *) 0; + tc->id = (struct rx_connection *)0; tc->next = sap->conns; sap->conns = tc; - afs_ActivateServer(sap); + afs_ActivateServer(sap); ConvertWToSLock(&afs_xconn); } @@ -192,21 +181,21 @@ struct conn *afs_ConnBySA(struct srvAddr *sap, unsigned short aport, if (tu->states & UTokensBad) { /* we may still have an authenticated RPC connection here, - * we'll have to create a new, unauthenticated, connection. - * Perhaps a better way to do this would be to set - * conn->forceConnectFS on all conns when the token first goes - * bad, but that's somewhat trickier, due to locking - * constraints (though not impossible). - */ + * we'll have to create a new, unauthenticated, connection. + * Perhaps a better way to do this would be to set + * conn->forceConnectFS on all conns when the token first goes + * bad, but that's somewhat trickier, due to locking + * constraints (though not impossible). + */ if (tc->id && (rx_SecurityClassOf(tc->id) != 0)) { - tc->forceConnectFS = 1; /* force recreation of connection */ + tc->forceConnectFS = 1; /* force recreation of connection */ } tu->vid = UNDEFVID; /* forcibly disconnect the authentication info */ } - if (tc->forceConnectFS) { - UpgradeSToWLock(&afs_xconn,38); - csec = (struct rx_securityClass *) 0; + if (tc->forceConnectFS) { + UpgradeSToWLock(&afs_xconn, 38); + csec = (struct rx_securityClass *)0; if (tc->id) { AFS_GUNLOCK(); rx_DestroyConnection(tc->id); @@ -222,29 +211,28 @@ struct conn *afs_ConnBySA(struct srvAddr *sap, unsigned short aport, service = 1; isec = 0; if (tu->vid != UNDEFVID) { - int level; - - if (cryptall) { - level=rxkad_crypt; - } else { - level=rxkad_clear; - } - isec=2; - /* kerberos tickets on channel 2 */ - csec = rxkad_NewClientSecurityObject(level, tu->ct.HandShakeKey, - /* kvno */ - tu->ct.AuthHandle, - tu->stLen, tu->stp); + int level; + + if (cryptall) { + level = rxkad_crypt; + } else { + level = rxkad_clear; + } + isec = 2; + /* kerberos tickets on channel 2 */ + csec = rxkad_NewClientSecurityObject(level, tu->ct.HandShakeKey, + /* kvno */ + tu->ct.AuthHandle, tu->stLen, + tu->stp); } if (isec == 0) csec = rxnull_NewClientSecurityObject(); AFS_GUNLOCK(); tc->id = rx_NewConnection(sap->sa_ip, aport, service, csec, isec); AFS_GLOCK(); - if (service == 52) { - rx_SetConnHardDeadTime(tc->id, AFS_HARDDEADTIME); - } - + if (service == 52) { + rx_SetConnHardDeadTime(tc->id, afs_rx_harddead); + } tc->forceConnectFS = 0; /* apparently we're appropriately connected now */ if (csec) @@ -255,6 +243,7 @@ struct conn *afs_ConnBySA(struct srvAddr *sap, unsigned short aport, ReleaseSharedLock(&afs_xconn); return tc; } + /* * afs_ConnByHost * @@ -264,18 +253,13 @@ struct conn *afs_ConnBySA(struct srvAddr *sap, unsigned short aport, * Having force... true and UTokensBad true simultaneously means that the tokens * went bad and we're supposed to create a new, unauthenticated, connection. */ -struct conn *afs_ConnByHost(aserver, aport, acell, areq, aforce, locktype) - struct server *aserver; - afs_int32 acell; - unsigned short aport; - struct vrequest *areq; - int aforce; - afs_int32 locktype; -{ /*afs_ConnByHost*/ - +struct conn * +afs_ConnByHost(struct server *aserver, unsigned short aport, afs_int32 acell, + struct vrequest *areq, int aforce, afs_int32 locktype) +{ struct unixuser *tu; - struct conn *tc=0; - struct srvAddr *sa=0; + struct conn *tc = 0; + struct srvAddr *sa = 0; AFS_STATCNT(afs_ConnByHost); /* @@ -286,36 +270,34 @@ struct conn *afs_ConnByHost(aserver, aport, acell, areq, aforce, locktype) tu = afs_GetUser(areq->uid, acell, SHARED_LOCK); - for (sa = aserver->addr; sa; sa = sa->next_sa) { - tc = afs_ConnBySA(sa, aport, acell, tu, aforce, - 0/*don't create one*/, - locktype); - if (tc) + for (sa = aserver->addr; sa; sa = sa->next_sa) { + tc = afs_ConnBySA(sa, aport, acell, tu, aforce, + 0 /*don't create one */ , + locktype); + if (tc) break; } if (!tc) { - for (sa = aserver->addr; sa; sa = sa->next_sa) { - tc = afs_ConnBySA(sa, aport, acell, tu, aforce, - 1/*create one*/, - locktype); - if (tc) - break; - } + for (sa = aserver->addr; sa; sa = sa->next_sa) { + tc = afs_ConnBySA(sa, aport, acell, tu, aforce, + 1 /*create one */ , + locktype); + if (tc) + break; + } } afs_PutUser(tu, SHARED_LOCK); return tc; -} /*afs_ConnByHost*/ +} /*afs_ConnByHost */ -struct conn *afs_ConnByMHosts(ahosts, aport, acell, areq, locktype) - struct server *ahosts[]; - afs_int32 acell; - unsigned short aport; - register struct vrequest *areq; - afs_int32 locktype; +struct conn * +afs_ConnByMHosts(struct server *ahosts[], unsigned short aport, + afs_int32 acell, register struct vrequest *areq, + afs_int32 locktype) { register afs_int32 i; register struct conn *tconn; @@ -323,50 +305,49 @@ struct conn *afs_ConnByMHosts(ahosts, aport, acell, areq, locktype) /* try to find any connection from the set */ AFS_STATCNT(afs_ConnByMHosts); - for (i=0;irefCount--; -} /*afs_PutConn*/ +} /*afs_PutConn */ /* for multi homed clients, an RPC may timeout because of a client network interface going down. We need to reopen new connections in this case */ -ForceNewConnections(sap) -struct srvAddr *sap; +void +ForceNewConnections(struct srvAddr *sap) { - struct conn *tc=0; + struct conn *tc = 0; - if ( !sap) return; /* defensive check */ + if (!sap) + return; /* defensive check */ - /* if client is not multihomed, do nothing */ - ObtainReadLock(&afs_xinterface); - if ( afs_cb_interface.numberOfInterfaces <= 1 ) - { - ReleaseReadLock(&afs_xinterface); - return; - } + /* if client is not multihomed, do nothing */ + ObtainReadLock(&afs_xinterface); + if (afs_cb_interface.numberOfInterfaces <= 1) { ReleaseReadLock(&afs_xinterface); - - ObtainWriteLock(&afs_xconn,413); - for (tc = sap->conns; tc; tc=tc->next) - tc->forceConnectFS=1; - ReleaseWriteLock(&afs_xconn); + return; + } + ReleaseReadLock(&afs_xinterface); + + ObtainWriteLock(&afs_xconn, 413); + for (tc = sap->conns; tc; tc = tc->next) + tc->forceConnectFS = 1; + ReleaseWriteLock(&afs_xconn); } diff --git a/src/afs/afs_daemons.c b/src/afs/afs_daemons.c index fad44353f..87848b035 100644 --- a/src/afs/afs_daemons.c +++ b/src/afs/afs_daemons.c @@ -8,14 +8,20 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_daemons.c,v 1.8 2003/04/13 19:32:22 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_daemons.c,v 1.28 2004/03/11 19:14:46 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics gathering code */ -#include "../afs/afs_cbqueue.h" +#ifdef AFS_AIX51_ENV +#define __FULL_PROTO +#include +#endif + +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics gathering code */ +#include "afs/afs_cbqueue.h" #ifdef AFS_AIX_ENV #include /* for vm_att(), vm_det() */ #endif @@ -26,46 +32,42 @@ afs_lock_t afs_xbrs; /* lock for brs */ static int brsInit = 0; short afs_brsWaiters = 0; /* number of users waiting for brs buffers */ short afs_brsDaemons = 0; /* number of daemons waiting for brs requests */ -struct brequest afs_brs[NBRS]; /* request structures */ +struct brequest afs_brs[NBRS]; /* request structures */ struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler; +static int afs_brs_count = 0; /* request counter, to service reqs in order */ -static int rxepoch_checked=0; +static int rxepoch_checked = 0; #define afs_CheckRXEpoch() {if (rxepoch_checked == 0 && rxkad_EpochWasSet) { \ rxepoch_checked = 1; afs_GCUserData(/* force flag */ 1); } } -extern char afs_rootVolumeName[]; -extern struct vcache *afs_globalVp; -extern struct VenusFid afs_rootFid; -extern struct osi_dev cacheDev; -extern char *afs_indexFlags; -extern afs_rwlock_t afs_xvcache; -extern struct afs_exporter *afs_nfsexporter; -extern int cacheDiskType; -extern int afs_BumpBase(); -extern void afs_CheckCallbacks(); - /* PAG garbage collection */ /* We induce a compile error if param.h does not define AFS_GCPAGS */ -afs_int32 afs_gcpags=AFS_GCPAGS; -afs_int32 afs_gcpags_procsize; +afs_int32 afs_gcpags = AFS_GCPAGS; +afs_int32 afs_gcpags_procsize = 0; afs_int32 afs_CheckServerDaemonStarted = 0; -afs_int32 PROBE_INTERVAL=180; /* default to 3 min */ +#ifdef DEFAULT_PROBE_INTERVAL +afs_int32 PROBE_INTERVAL = DEFAULT_PROBE_INTERVAL; /* overridding during compile */ +#else +afs_int32 PROBE_INTERVAL = 180; /* default to 3 min */ +#endif #define PROBE_WAIT() (1000 * (PROBE_INTERVAL - ((afs_random() & 0x7fffffff) \ % (PROBE_INTERVAL/2)))) -afs_CheckServerDaemon() +void +afs_CheckServerDaemon(void) { afs_int32 now, delay, lastCheck, last10MinCheck; afs_CheckServerDaemonStarted = 1; - while (afs_initState < 101) afs_osi_Sleep(&afs_initState); - afs_osi_Wait(PROBE_WAIT(), &AFS_CSWaitHandler, 0); - + while (afs_initState < 101) + afs_osi_Sleep(&afs_initState); + afs_osi_Wait(PROBE_WAIT(), &AFS_CSWaitHandler, 0); + last10MinCheck = lastCheck = osi_Time(); - while ( 1 ) { + while (1) { if (afs_termState == AFSOP_STOP_CS) { afs_termState = AFSOP_STOP_BKG; afs_osi_Wakeup(&afs_termState); @@ -74,13 +76,13 @@ afs_CheckServerDaemon() now = osi_Time(); if (PROBE_INTERVAL + lastCheck <= now) { - afs_CheckServers(1, (struct cell *) 0); /* check down servers */ + afs_CheckServers(1, NULL); /* check down servers */ lastCheck = now = osi_Time(); } if (600 + last10MinCheck <= now) { afs_Trace1(afs_iclSetp, CM_TRACE_PROBEUP, ICL_TYPE_INT32, 600); - afs_CheckServers(0, (struct cell *) 0); + afs_CheckServers(0, NULL); last10MinCheck = now = osi_Time(); } /* shutdown check. */ @@ -97,14 +99,15 @@ afs_CheckServerDaemon() delay -= now; if (delay < 1) delay = 1; - afs_osi_Wait(delay * 1000, &AFS_CSWaitHandler, 0); + afs_osi_Wait(delay * 1000, &AFS_CSWaitHandler, 0); } afs_CheckServerDaemonStarted = 0; } -void afs_Daemon() { +void +afs_Daemon(void) +{ afs_int32 code; - extern struct afs_exporter *root_exported; struct afs_exporter *exporter; afs_int32 now; afs_int32 last3MinCheck, last10MinCheck, last60MinCheck, lastNMinCheck; @@ -113,10 +116,12 @@ void afs_Daemon() { char cs_warned = 0; AFS_STATCNT(afs_Daemon); - last1MinCheck = last3MinCheck = last60MinCheck = last10MinCheck = lastNMinCheck = 0; + last1MinCheck = last3MinCheck = last60MinCheck = last10MinCheck = + lastNMinCheck = 0; afs_rootFid.Fid.Volume = 0; - while (afs_initState < 101) afs_osi_Sleep(&afs_initState); + while (afs_initState < 101) + afs_osi_Sleep(&afs_initState); now = osi_Time(); lastCBSlotBump = now; @@ -124,22 +129,22 @@ void afs_Daemon() { /* when a lot of clients are booted simultaneously, they develop * annoying synchronous VL server bashing behaviors. So we stagger them. */ - last1MinCheck = now + ((afs_random() & 0x7fffffff) % 60); /* an extra 30 */ + last1MinCheck = now + ((afs_random() & 0x7fffffff) % 60); /* an extra 30 */ last3MinCheck = now - 90 + ((afs_random() & 0x7fffffff) % 180); last60MinCheck = now - 1800 + ((afs_random() & 0x7fffffff) % 3600); last10MinCheck = now - 300 + ((afs_random() & 0x7fffffff) % 600); lastNMinCheck = now - 90 + ((afs_random() & 0x7fffffff) % 180); /* start off with afs_initState >= 101 (basic init done) */ - while(1) { - afs_CheckCallbacks(20); /* unstat anything which will expire soon */ - + while (1) { + afs_CheckCallbacks(20); /* unstat anything which will expire soon */ + /* things to do every 20 seconds or less - required by protocol spec */ - if (afs_nfsexporter) + if (afs_nfsexporter) afs_FlushActiveVcaches(0); /* flush NFS writes */ - afs_FlushVCBs(1); /* flush queued callbacks */ + afs_FlushVCBs(1); /* flush queued callbacks */ afs_MaybeWakeupTruncateDaemon(); /* free cache space if have too */ - rx_CheckPackets(); /* Does RX need more packets? */ + rx_CheckPackets(); /* Does RX need more packets? */ #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) /* * Hack: We always want to make sure there are plenty free @@ -147,34 +152,39 @@ void afs_Daemon() { * worry about rx (with disabled interrupts) to have to call * malloc). So we do the dummy call below... */ - if (((afs_stats_cmperf.SmallBlocksAlloced - afs_stats_cmperf.SmallBlocksActive) + if (((afs_stats_cmperf.SmallBlocksAlloced - + afs_stats_cmperf.SmallBlocksActive) <= AFS_SALLOC_LOW_WATER)) osi_FreeSmallSpace(osi_AllocSmallSpace(AFS_SMALLOCSIZ)); - if (((afs_stats_cmperf.MediumBlocksAlloced - afs_stats_cmperf.MediumBlocksActive) - <= AFS_MALLOC_LOW_WATER+50)) - osi_AllocMoreMSpace(AFS_MALLOC_LOW_WATER * 2); + if (((afs_stats_cmperf.MediumBlocksAlloced - + afs_stats_cmperf.MediumBlocksActive) + <= AFS_MALLOC_LOW_WATER + 50)) + osi_AllocMoreMSpace(AFS_MALLOC_LOW_WATER * 2); #endif - + now = osi_Time(); - if (lastCBSlotBump + CBHTSLOTLEN < now) { /* pretty time-dependant */ + if (lastCBSlotBump + CBHTSLOTLEN < now) { /* pretty time-dependant */ lastCBSlotBump = now; if (afs_BumpBase()) { - afs_CheckCallbacks(20); /* unstat anything which will expire soon */ + afs_CheckCallbacks(20); /* unstat anything which will expire soon */ } } - + if (last1MinCheck + 60 < now) { /* things to do every minute */ - DFlush(); /* write out dir buffers */ + DFlush(); /* write out dir buffers */ afs_WriteThroughDSlots(); /* write through cacheinfo entries */ - afs_FlushActiveVcaches(1);/* keep flocks held & flush nfs writes */ + afs_FlushActiveVcaches(1); /* keep flocks held & flush nfs writes */ +#ifdef AFS_DISCON_ENV + afs_StoreDirtyVcaches(); +#endif afs_CheckRXEpoch(); last1MinCheck = now; } - + if (last3MinCheck + 180 < now) { afs_CheckTokenCache(); /* check for access cache resets due to expired - tickets */ + * tickets */ last3MinCheck = now; } if (!afs_CheckServerDaemonStarted) { @@ -185,34 +195,34 @@ void afs_Daemon() { } if (lastNMinCheck + PROBE_INTERVAL < now) { /* only check down servers */ - afs_CheckServers(1, (struct cell *) 0); + afs_CheckServers(1, NULL); lastNMinCheck = now; } } if (last10MinCheck + 600 < now) { -#ifdef AFS_USERSPACE_IP_ADDR +#ifdef AFS_USERSPACE_IP_ADDR extern int rxi_GetcbiInfo(void); #endif - afs_Trace1(afs_iclSetp, CM_TRACE_PROBEUP, - ICL_TYPE_INT32, 600); -#ifdef AFS_USERSPACE_IP_ADDR - if (rxi_GetcbiInfo()) { /* addresses changed from last time */ + afs_Trace1(afs_iclSetp, CM_TRACE_PROBEUP, ICL_TYPE_INT32, 600); +#ifdef AFS_USERSPACE_IP_ADDR + if (rxi_GetcbiInfo()) { /* addresses changed from last time */ afs_FlushCBs(); } -#else /* AFS_USERSPACE_IP_ADDR */ - if (rxi_GetIFInfo()) { /* addresses changed from last time */ +#else /* AFS_USERSPACE_IP_ADDR */ + if (rxi_GetIFInfo()) { /* addresses changed from last time */ afs_FlushCBs(); } #endif /* else AFS_USERSPACE_IP_ADDR */ if (!afs_CheckServerDaemonStarted) - afs_CheckServers(0, (struct cell *) 0); - afs_GCUserData(0); /* gc old conns */ + afs_CheckServers(0, NULL); + afs_GCUserData(0); /* gc old conns */ /* This is probably the wrong way of doing GC for the various exporters but it will suffice for a while */ - for (exporter = root_exported; exporter; exporter = exporter->exp_next) { - (void) EXP_GC(exporter, 0); /* Generalize params */ + for (exporter = root_exported; exporter; + exporter = exporter->exp_next) { + (void)EXP_GC(exporter, 0); /* Generalize params */ } { - static int cnt=0; + static int cnt = 0; if (++cnt < 12) { afs_CheckVolumeNames(AFS_VOLCHECK_EXPIRED | AFS_VOLCHECK_BUSY); @@ -226,12 +236,12 @@ void afs_Daemon() { last10MinCheck = now; } if (last60MinCheck + 3600 < now) { - afs_Trace1(afs_iclSetp, CM_TRACE_PROBEVOLUME, - ICL_TYPE_INT32, 3600); + afs_Trace1(afs_iclSetp, CM_TRACE_PROBEVOLUME, ICL_TYPE_INT32, + 3600); afs_CheckRootVolume(); #if AFS_GCPAGS if (afs_gcpags == AFS_GCPAGS_OK) { - afs_int32 didany; + afs_int32 didany; afs_GCPAGs(&didany); } #endif @@ -239,11 +249,13 @@ void afs_Daemon() { } if (afs_initState < 300) { /* while things ain't rosy */ code = afs_CheckRootVolume(); - if (code == 0) afs_initState = 300; /* succeeded */ - if (afs_initState < 200) afs_initState = 200; /* tried once */ + if (code == 0) + afs_initState = 300; /* succeeded */ + if (afs_initState < 200) + afs_initState = 200; /* tried once */ afs_osi_Wakeup(&afs_initState); } - + /* 18285 is because we're trying to divide evenly into 128, that is, * CBSlotLen, while staying just under 20 seconds. If CBSlotLen * changes, should probably change this interval, too. @@ -251,9 +263,9 @@ void afs_Daemon() { * might not want to wait the entire interval */ now = 18285 - (osi_Time() - now); if (now > 0) { - afs_osi_Wait(now, &AFS_WaitHandler, 0); + afs_osi_Wait(now, &AFS_WaitHandler, 0); } - + if (afs_termState == AFSOP_STOP_AFS) { if (afs_CheckServerDaemonStarted) afs_termState = AFSOP_STOP_CS; @@ -265,9 +277,11 @@ void afs_Daemon() { } } -int afs_CheckRootVolume (void) { +int +afs_CheckRootVolume(void) +{ char rootVolName[32]; - struct volume *tvp; + struct volume *tvp = NULL; int usingDynroot = afs_GetDynrootEnable(); int localcell; @@ -279,111 +293,114 @@ int afs_CheckRootVolume (void) { } if (!usingDynroot) { - struct cell *lc = afs_GetPrimaryCell(READ_LOCK); + struct cell *lc = afs_GetPrimaryCell(READ_LOCK); - if (!lc) - return ENOENT; - localcell = lc->cellNum; - afs_PutCell(lc, READ_LOCK); + if (!lc) + return ENOENT; + localcell = lc->cellNum; + afs_PutCell(lc, READ_LOCK); } if (usingDynroot) { - afs_GetDynrootFid(&afs_rootFid); - tvp = afs_GetVolume(&afs_rootFid, NULL, READ_LOCK); + afs_GetDynrootFid(&afs_rootFid); + tvp = afs_GetVolume(&afs_rootFid, NULL, READ_LOCK); } else { - tvp = afs_GetVolumeByName(rootVolName, localcell, 1, NULL, READ_LOCK); + tvp = afs_GetVolumeByName(rootVolName, localcell, 1, NULL, READ_LOCK); } if (!tvp && !usingDynroot) { - char buf[128]; - int len = strlen(rootVolName); - - if ((len < 9) || strcmp(&rootVolName[len - 9], ".readonly")) { - strcpy(buf, rootVolName); - afs_strcat(buf, ".readonly"); - tvp = afs_GetVolumeByName(buf, localcell, 1, NULL, READ_LOCK); - } + char buf[128]; + int len = strlen(rootVolName); + + if ((len < 9) || strcmp(&rootVolName[len - 9], ".readonly")) { + strcpy(buf, rootVolName); + afs_strcat(buf, ".readonly"); + tvp = afs_GetVolumeByName(buf, localcell, 1, NULL, READ_LOCK); + } } if (tvp) { - if (!usingDynroot) { - int volid = (tvp->roVol? tvp->roVol : tvp->volume); - afs_rootFid.Cell = localcell; - if (afs_rootFid.Fid.Volume && afs_rootFid.Fid.Volume != volid - && afs_globalVp) { - /* If we had a root fid before and it changed location we reset - * the afs_globalVp so that it will be reevaluated. - * Just decrement the reference count. This only occurs during - * initial cell setup and can panic the machine if we set the - * count to zero and fs checkv is executed when the current - * directory is /afs. - */ - AFS_FAST_RELE(afs_globalVp); - afs_globalVp = 0; - } - afs_rootFid.Fid.Volume = volid; - afs_rootFid.Fid.Vnode = 1; - afs_rootFid.Fid.Unique = 1; - } - afs_initState = 300; /* won */ - afs_osi_Wakeup(&afs_initState); - afs_PutVolume(tvp, READ_LOCK); + if (!usingDynroot) { + int volid = (tvp->roVol ? tvp->roVol : tvp->volume); + afs_rootFid.Cell = localcell; + if (afs_rootFid.Fid.Volume && afs_rootFid.Fid.Volume != volid + && afs_globalVp) { + /* If we had a root fid before and it changed location we reset + * the afs_globalVp so that it will be reevaluated. + * Just decrement the reference count. This only occurs during + * initial cell setup and can panic the machine if we set the + * count to zero and fs checkv is executed when the current + * directory is /afs. + */ + AFS_FAST_RELE(afs_globalVp); + afs_globalVp = 0; + } + afs_rootFid.Fid.Volume = volid; + afs_rootFid.Fid.Vnode = 1; + afs_rootFid.Fid.Unique = 1; + } + afs_initState = 300; /* won */ + afs_osi_Wakeup(&afs_initState); + afs_PutVolume(tvp, READ_LOCK); } #ifdef AFS_DEC_ENV /* This is to make sure that we update the root gnode */ /* every time root volume gets released */ { - extern struct vfs *afs_globalVFS; - extern int afs_root(); struct gnode *rootgp; struct mount *mp; int code; /* Only do this if afs_globalVFS is properly set due to race conditions - this routine could be called before the gfs_mount is performed! - Furthermore, afs_root (called below) *waits* until - initState >= 200, so we don't try this until we've gotten - at least that far */ + * this routine could be called before the gfs_mount is performed! + * Furthermore, afs_root (called below) *waits* until + * initState >= 200, so we don't try this until we've gotten + * at least that far */ if (afs_globalVFS && afs_initState >= 200) { if (code = afs_root(afs_globalVFS, &rootgp)) return code; - mp = (struct mount *) afs_globalVFS->vfs_data ; + mp = (struct mount *)afs_globalVFS->vfs_data; mp->m_rootgp = gget(mp, 0, 0, (char *)rootgp); afs_unlock(mp->m_rootgp); /* unlock basic gnode */ - afs_vrele(VTOAFS(rootgp)); /* zap afs_root's vnode hold */ + afs_vrele(VTOAFS(rootgp)); /* zap afs_root's vnode hold */ } } #endif - if (afs_rootFid.Fid.Volume) return 0; - else return ENOENT; + if (afs_rootFid.Fid.Volume) + return 0; + else + return ENOENT; } -/* parm 0 is the pathname, parm 1 to the fetch is the chunk number */ -void BPath(ab) - register struct brequest *ab; { - register struct dcache *tdc; - struct vcache *tvc; - struct vnode *tvn; +/* ptr_parm 0 is the pathname, size_parm 0 to the fetch is the chunk number */ +static void +BPath(register struct brequest *ab) +{ + register struct dcache *tdc = NULL; + struct vcache *tvc = NULL; + struct vnode *tvn = NULL; #ifdef AFS_LINUX22_ENV struct dentry *dp = NULL; #endif - afs_int32 offset, len; + afs_size_t offset, len; struct vrequest treq; afs_int32 code; AFS_STATCNT(BPath); - if (code = afs_InitReq(&treq, ab->cred)) return; + if ((code = afs_InitReq(&treq, ab->cred))) + return; AFS_GUNLOCK(); #ifdef AFS_LINUX22_ENV - code = gop_lookupname((char *)ab->parm[0], AFS_UIOSYS, 1, (struct vnode **) 0, &dp); + code = gop_lookupname((char *)ab->ptr_parm[0], AFS_UIOSYS, 1, NULL, &dp); if (dp) - tvn = (struct vnode*)dp->d_inode; + tvn = (struct vnode *)dp->d_inode; #else - code = gop_lookupname((char *)ab->parm[0], AFS_UIOSYS, 1, (struct vnode **) 0, (struct vnode **)&tvn); + code = gop_lookupname((char *)ab->ptr_parm[0], AFS_UIOSYS, 1, NULL, &tvn); #endif AFS_GLOCK(); - osi_FreeLargeSpace((char *)ab->parm[0]); /* free path name buffer here */ - if (code) return; + osi_FreeLargeSpace((char *)ab->ptr_parm[0]); /* free path name buffer here */ + if (code) + return; /* now path may not have been in afs, so check that before calling our cache manager */ - if (!tvn || !IsAfsVnode((struct vnode *) tvn)) { + if (!tvn || !IsAfsVnode(tvn)) { /* release it and give up */ if (tvn) { #ifdef AFS_DEC_ENV @@ -392,7 +409,7 @@ void BPath(ab) #ifdef AFS_LINUX22_ENV dput(dp); #else - AFS_RELE((struct vnode *) tvn); + AFS_RELE(tvn); #endif #endif } @@ -404,7 +421,7 @@ void BPath(ab) tvc = VTOAFS(tvn); #endif /* here we know its an afs vnode, so we can get the data for the chunk */ - tdc = afs_GetDCache(tvc, ab->parm[1], &treq, &offset, &len, 1); + tdc = afs_GetDCache(tvc, ab->size_parm[0], &treq, &offset, &len, 1); if (tdc) { afs_PutDCache(tdc); } @@ -414,25 +431,28 @@ void BPath(ab) #ifdef AFS_LINUX22_ENV dput(dp); #else - AFS_RELE((struct vnode *) tvn); + AFS_RELE(tvn); #endif #endif } -/* parm 0 to the fetch is the chunk number; parm 1 is the dcache entry to wakeup, - * parm 2 is true iff we should release the dcache entry here. +/* size_parm 0 to the fetch is the chunk number, + * ptr_parm 0 is the dcache entry to wakeup, + * size_parm 1 is true iff we should release the dcache entry here. */ -void BPrefetch(ab) - register struct brequest *ab; { +static void +BPrefetch(register struct brequest *ab) +{ register struct dcache *tdc; register struct vcache *tvc; - afs_int32 offset, len; + afs_size_t offset, len; struct vrequest treq; AFS_STATCNT(BPrefetch); - if (len = afs_InitReq(&treq, ab->cred)) return; - tvc = ab->vnode; - tdc = afs_GetDCache(tvc, (afs_int32)ab->parm[0], &treq, &offset, &len, 1); + if ((len = afs_InitReq(&treq, ab->cred))) + return; + tvc = ab->vc; + tdc = afs_GetDCache(tvc, ab->size_parm[0], &treq, &offset, &len, 1); if (tdc) { afs_PutDCache(tdc); } @@ -440,23 +460,25 @@ void BPrefetch(ab) * use tdc from GetDCache since afs_GetDCache may fail, but someone may * be waiting for our wakeup anyway. */ - tdc = (struct dcache *) (ab->parm[1]); - tdc->flags &= ~DFFetchReq; + tdc = (struct dcache *)(ab->ptr_parm[0]); + ObtainSharedLock(&tdc->lock, 640); + if (tdc->mflags & DFFetchReq) { + UpgradeSToWLock(&tdc->lock, 641); + tdc->mflags &= ~DFFetchReq; + ReleaseWriteLock(&tdc->lock); + } else { + ReleaseSharedLock(&tdc->lock); + } afs_osi_Wakeup(&tdc->validPos); - if (ab->parm[2]) { -#ifdef AFS_SUN5_ENVX - mutex_enter(&tdc->lock); - tdc->refCount--; - mutex_exit(&tdc->lock); -#else + if (ab->size_parm[1]) { afs_PutDCache(tdc); /* put this one back, too */ -#endif } } -void BStore(ab) - register struct brequest *ab; { +static void +BStore(register struct brequest *ab) +{ register struct vcache *tvc; register afs_int32 code; struct vrequest treq; @@ -465,9 +487,10 @@ void BStore(ab) #endif AFS_STATCNT(BStore); - if (code = afs_InitReq(&treq, ab->cred)) return; + if ((code = afs_InitReq(&treq, ab->cred))) + return; code = 0; - tvc = ab->vnode; + tvc = ab->vc; #if defined(AFS_SGI_ENV) /* * Since StoreOnLastReference can end up calling osi_SyncVM which @@ -482,18 +505,18 @@ void BStore(ab) * operations, we hold the VOP_RWLOCK across this transaction as * do the other callers of StoreOnLastReference */ - AFS_RWLOCK((vnode_t *)tvc, 1); + AFS_RWLOCK((vnode_t *) tvc, 1); #endif - ObtainWriteLock(&tvc->lock,209); + ObtainWriteLock(&tvc->lock, 209); code = afs_StoreOnLastReference(tvc, &treq); ReleaseWriteLock(&tvc->lock); #if defined(AFS_SGI_ENV) OSI_SET_CURRENT_CRED(tmpcred); - AFS_RWUNLOCK((vnode_t *)tvc, 1); + AFS_RWUNLOCK((vnode_t *) tvc, 1); #endif /* now set final return code, and wakeup anyone waiting */ if ((ab->flags & BUVALID) == 0) { - ab->code = afs_CheckCode(code, &treq, 43); /* set final code, since treq doesn't go across processes */ + ab->code = afs_CheckCode(code, &treq, 43); /* set final code, since treq doesn't go across processes */ ab->flags |= BUVALID; if (ab->flags & BUWAIT) { ab->flags &= ~BUWAIT; @@ -503,47 +526,50 @@ void BStore(ab) } /* release a held request buffer */ -void afs_BRelease(ab) - register struct brequest *ab; { +void +afs_BRelease(register struct brequest *ab) +{ AFS_STATCNT(afs_BRelease); - MObtainWriteLock(&afs_xbrs,294); + MObtainWriteLock(&afs_xbrs, 294); if (--ab->refCount <= 0) { ab->flags = 0; } - if (afs_brsWaiters) afs_osi_Wakeup(&afs_brsWaiters); + if (afs_brsWaiters) + afs_osi_Wakeup(&afs_brsWaiters); MReleaseWriteLock(&afs_xbrs); } /* return true if bkg fetch daemons are all busy */ -int afs_BBusy() { +int +afs_BBusy(void) +{ AFS_STATCNT(afs_BBusy); - if (afs_brsDaemons > 0) return 0; + if (afs_brsDaemons > 0) + return 0; return 1; } -struct brequest *afs_BQueue(aopcode, avc, dontwait, ause, acred, aparm0, aparm1, aparm2, aparm3) - register short aopcode; - afs_int32 ause, dontwait; - register struct vcache *avc; - struct AFS_UCRED *acred; - /* On 64 bit platforms, "long" does the right thing. */ - long aparm0, aparm1, aparm2, aparm3; +struct brequest * +afs_BQueue(register short aopcode, register struct vcache *avc, + afs_int32 dontwait, afs_int32 ause, struct AFS_UCRED *acred, + afs_size_t asparm0, afs_size_t asparm1, void *apparm0) { register int i; register struct brequest *tb; AFS_STATCNT(afs_BQueue); - MObtainWriteLock(&afs_xbrs,296); + MObtainWriteLock(&afs_xbrs, 296); while (1) { tb = afs_brs; - for(i=0;irefCount == 0) break; + for (i = 0; i < NBRS; i++, tb++) { + if (tb->refCount == 0) + break; } if (i < NBRS) { /* found a buffer */ tb->opcode = aopcode; - tb->vnode = avc; + tb->vc = avc; tb->cred = acred; crhold(tb->cred); if (avc) { @@ -553,13 +579,13 @@ struct brequest *afs_BQueue(aopcode, avc, dontwait, ause, acred, aparm0, aparm1, VN_HOLD(AFSTOV(avc)); #endif } - tb->refCount = ause+1; - tb->parm[0] = aparm0; - tb->parm[1] = aparm1; - tb->parm[2] = aparm2; - tb->parm[3] = aparm3; + tb->refCount = ause + 1; + tb->size_parm[0] = asparm0; + tb->size_parm[1] = asparm1; + tb->ptr_parm[0] = apparm0; tb->flags = 0; tb->code = 0; + tb->ts = afs_brs_count++; /* if daemons are waiting for work, wake them up */ if (afs_brsDaemons > 0) { afs_osi_Wakeup(&afs_brsDaemons); @@ -567,15 +593,15 @@ struct brequest *afs_BQueue(aopcode, avc, dontwait, ause, acred, aparm0, aparm1, MReleaseWriteLock(&afs_xbrs); return tb; } - if (dontwait) { + if (dontwait) { MReleaseWriteLock(&afs_xbrs); - return (struct brequest *)0; + return NULL; } /* no free buffers, sleep a while */ afs_brsWaiters++; MReleaseWriteLock(&afs_xbrs); afs_osi_Sleep(&afs_brsWaiters); - MObtainWriteLock(&afs_xbrs,301); + MObtainWriteLock(&afs_xbrs, 301); afs_brsWaiters--; } } @@ -585,8 +611,8 @@ struct brequest *afs_BQueue(aopcode, avc, dontwait, ause, acred, aparm0, aparm1, /* AIX 4.1 has a much different sleep/wakeup mechanism available for use. * The modifications here will work for either a UP or MP machine. */ -struct buf *afs_asyncbuf = (struct buf*)0; -afs_int32 afs_asyncbuf_cv = EVENT_NULL; +struct buf *afs_asyncbuf = (struct buf *)0; +tid_t afs_asyncbuf_cv = EVENT_NULL; afs_int32 afs_biodcnt = 0; /* in implementing this, I assumed that all external linked lists were @@ -616,47 +642,48 @@ afs_int32 afs_biodcnt = 0; * process and interrupts. */ Simple_lock afs_asyncbuf_lock; -/*static*/ struct buf *afs_get_bioreq() +/*static*/ struct buf * +afs_get_bioreq() { - struct buf *bp = (struct buf *) 0; + struct buf *bp = NULL; struct buf *bestbp; struct buf **bestlbpP, **lbpP; - int bestage, stop; - struct buf *t1P, *t2P; /* temp pointers for list manipulation */ + long bestage, stop; + struct buf *t1P, *t2P; /* temp pointers for list manipulation */ int oldPriority; afs_uint32 wait_ret; struct afs_bioqueue *s; /* ??? Does the forward pointer of the returned buffer need to be NULL? - */ - + */ + /* Disable interrupts from the strategy function, and save the * prior priority level and lock access to the afs_asyncbuf. */ AFS_GUNLOCK(); - oldPriority = disable_lock(INTMAX, &afs_asyncbuf_lock) ; + oldPriority = disable_lock(INTMAX, &afs_asyncbuf_lock); - while(1) { + while (1) { if (afs_asyncbuf) { /* look for oldest buffer */ bp = bestbp = afs_asyncbuf; - bestage = (int) bestbp->av_back; + bestage = (long)bestbp->av_back; bestlbpP = &afs_asyncbuf; while (1) { lbpP = &bp->av_forw; bp = *lbpP; - if (!bp) break; - if ((int) bp->av_back - bestage < 0) { + if (!bp) + break; + if ((long)bp->av_back - bestage < 0) { bestbp = bp; bestlbpP = lbpP; - bestage = (int) bp->av_back; + bestage = (long)bp->av_back; } } bp = bestbp; *bestlbpP = bp->av_forw; break; - } - else { + } else { /* If afs_asyncbuf is null, it is necessary to go to sleep. * e_wakeup_one() ensures that only one thread wakes. */ @@ -664,20 +691,20 @@ Simple_lock afs_asyncbuf_lock; /* The LOCK_HANDLER indicates to e_sleep_thread to only drop the * lock on an MP machine. */ - interrupted = e_sleep_thread(&afs_asyncbuf_cv, - &afs_asyncbuf_lock, - LOCK_HANDLER|INTERRUPTIBLE); - if (interrupted==THREAD_INTERRUPTED) { + interrupted = + e_sleep_thread(&afs_asyncbuf_cv, &afs_asyncbuf_lock, + LOCK_HANDLER | INTERRUPTIBLE); + if (interrupted == THREAD_INTERRUPTED) { /* re-enable interrupts from strategy */ unlock_enable(oldPriority, &afs_asyncbuf_lock); AFS_GLOCK(); - return(NULL); + return (NULL); } - } /* end of "else asyncbuf is empty" */ - } /* end of "inner loop" */ - - /*assert (bp);*/ - + } /* end of "else asyncbuf is empty" */ + } /* end of "inner loop" */ + + /*assert (bp); */ + unlock_enable(oldPriority, &afs_asyncbuf_lock); AFS_GLOCK(); @@ -688,14 +715,14 @@ Simple_lock afs_asyncbuf_lock; * ??? what happens to the gnodes? They're not just cut loose, * are they? */ - for(t1P=bp;;) { - t2P = (struct buf *) t1P->b_work; - t1P->b_vp = ((struct gnode *) t1P->b_vp)->gn_vnode; - if (!t2P) + for (t1P = bp;;) { + t2P = (struct buf *)t1P->b_work; + t1P->b_vp = ((struct gnode *)t1P->b_vp)->gn_vnode; + if (!t2P) break; - t1P = (struct buf *) t2P->b_work; - t2P->b_vp = ((struct gnode *) t2P->b_vp)->gn_vnode; + t1P = (struct buf *)t2P->b_work; + t2P->b_vp = ((struct gnode *)t2P->b_vp)->gn_vnode; if (!t1P) break; } @@ -707,12 +734,12 @@ Simple_lock afs_asyncbuf_lock; * violation, rather than a request for I/O. The remainder * of the outer loop handles the case where the B_PFPROT bit is clear. */ - if (bp->b_flags & B_PFPROT) { + if (bp->b_flags & B_PFPROT) { return (bp); } return (bp); -} /* end of function get_bioreq() */ +} /* end of function get_bioreq() */ /* afs_BioDaemon @@ -724,14 +751,14 @@ Simple_lock afs_asyncbuf_lock; * each making the appropriate syscall, which will cause this * function to be invoked. */ -static int afs_initbiod = 0; /* this is self-initializing code */ +static int afs_initbiod = 0; /* this is self-initializing code */ int DOvmlock = 0; -afs_BioDaemon (nbiods) - afs_int32 nbiods; +int +afs_BioDaemon(afs_int32 nbiods) { afs_int32 code, s, pflg = 0; label_t jmpbuf; - struct buf *bp, *bp1, *tbp1, *tbp2; /* temp pointers only */ + struct buf *bp, *bp1, *tbp1, *tbp2; /* temp pointers only */ caddr_t tmpaddr; struct vnode *vp; struct vcache *vcp; @@ -742,26 +769,20 @@ afs_BioDaemon (nbiods) /* pin lock, since we'll be using it in an interrupt. */ lock_alloc(&afs_asyncbuf_lock, LOCK_ALLOC_PIN, 2, 1); simple_lock_init(&afs_asyncbuf_lock); - pin (&afs_asyncbuf, sizeof(struct buf*)); - pin (&afs_asyncbuf_cv, sizeof(afs_int32)); + pin(&afs_asyncbuf, sizeof(struct buf *)); + pin(&afs_asyncbuf_cv, sizeof(afs_int32)); } /* Ignore HUP signals... */ -#ifdef AFS_AIX41_ENV { - sigset_t sigbits, osigbits; - /* - * add SIGHUP to the set of already masked signals - */ - SIGFILLSET(sigbits); /* allow all signals */ - SIGDELSET(sigbits, SIGHUP); /* except SIGHUP */ - limit_sigs(&sigbits, &osigbits); /* and already masked */ + sigset_t sigbits, osigbits; + /* + * add SIGHUP to the set of already masked signals + */ + SIGFILLSET(sigbits); /* allow all signals */ + SIGDELSET(sigbits, SIGHUP); /* except SIGHUP */ + limit_sigs(&sigbits, &osigbits); /* and already masked */ } -#else - SIGDELSET(u.u_procp->p_sig, SIGHUP); - SIGADDSET(u.u_procp->p_sigignore, SIGHUP); - SIGDELSET(u.u_procp->p_sigcatch, SIGHUP); -#endif /* Main body starts here -- this is an intentional infinite loop, and * should NEVER exit * @@ -771,14 +792,14 @@ afs_BioDaemon (nbiods) while (1) { bp = afs_get_bioreq(); if (!bp) - break; /* we were interrupted */ + break; /* we were interrupted */ if (code = setjmpx(&jmpbuf)) { /* This should not have happend, maybe a lack of resources */ AFS_GUNLOCK(); s = disable_lock(INTMAX, &afs_asyncbuf_lock); - for (bp1 = bp; bp ; bp = bp1) { + for (bp1 = bp; bp; bp = bp1) { if (bp1) - bp1 = (struct buf *) bp1->b_work; + bp1 = (struct buf *)bp1->b_work; bp->b_actf = 0; bp->b_error = code; bp->b_flags |= B_ERROR; @@ -790,23 +811,31 @@ afs_BioDaemon (nbiods) } vcp = VTOAFS(bp->b_vp); if (bp->b_flags & B_PFSTORE) { /* XXXX */ - ObtainWriteLock(&vcp->lock,404); + ObtainWriteLock(&vcp->lock, 404); if (vcp->v.v_gnode->gn_mwrcnt) { - if (vcp->m.Length < bp->b_bcount + (u_int)dbtob(bp->b_blkno)) - vcp->m.Length = bp->b_bcount + (u_int)dbtob(bp->b_blkno); + afs_offs_t newlength = + (afs_offs_t) dbtob(bp->b_blkno) + bp->b_bcount; + if (vcp->m.Length < newlength) { + afs_Trace4(afs_iclSetp, CM_TRACE_SETLENGTH, + ICL_TYPE_STRING, __FILE__, ICL_TYPE_LONG, + __LINE__, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(vcp->m.Length), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(newlength)); + vcp->m.Length = newlength; + } } ReleaseWriteLock(&vcp->lock); } /* If the buffer represents a protection violation, rather than * an actual request for I/O, no special action need be taken. */ - if ( bp->b_flags & B_PFPROT ) { - iodone (bp); /* Notify all users of the buffer that we're done */ + if (bp->b_flags & B_PFPROT) { + iodone(bp); /* Notify all users of the buffer that we're done */ clrjmpx(&jmpbuf); continue; - } -if (DOvmlock) - ObtainWriteLock(&vcp->pvmlock,211); + } + if (DOvmlock) + ObtainWriteLock(&vcp->pvmlock, 211); /* * First map its data area to a region in the current address space * by calling vm_att with the subspace identifier, and a pointer to @@ -814,17 +843,17 @@ if (DOvmlock) * also want to hang onto the old one. */ tmpaddr = bp->b_baddr; - bp->b_baddr = vm_att (bp->b_xmemd.subspace_id, tmpaddr); + bp->b_baddr = (caddr_t) vm_att(bp->b_xmemd.subspace_id, tmpaddr); tmperr = afs_ustrategy(bp); /* temp variable saves offset calculation */ - if (tmperr) { /* in non-error case */ - bp->b_flags |= B_ERROR; /* should other flags remain set ??? */ + if (tmperr) { /* in non-error case */ + bp->b_flags |= B_ERROR; /* should other flags remain set ??? */ bp->b_error = tmperr; } /* Unmap the buffer's data area by calling vm_det. Reset data area * to the value that we saved above. */ - vm_det(bp->b_un.b_addr); + vm_det(bp->b_baddr); bp->b_baddr = tmpaddr; /* @@ -834,22 +863,22 @@ if (DOvmlock) * using it by calling iodone. * assumes iodone can modify the b_work field. */ - for(tbp1=bp;;) { - tbp2 = (struct buf *) tbp1->b_work; + for (tbp1 = bp;;) { + tbp2 = (struct buf *)tbp1->b_work; iodone(tbp1); - if (!tbp2) + if (!tbp2) break; - tbp1 = (struct buf *) tbp2->b_work; + tbp1 = (struct buf *)tbp2->b_work; iodone(tbp2); if (!tbp1) break; } -if (DOvmlock) - ReleaseWriteLock(&vcp->pvmlock); /* Unlock the vnode. */ + if (DOvmlock) + ReleaseWriteLock(&vcp->pvmlock); /* Unlock the vnode. */ clrjmpx(&jmpbuf); - } /* infinite loop (unless we're interrupted) */ -} /* end of afs_BioDaemon() */ + } /* infinite loop (unless we're interrupted) */ +} /* end of afs_BioDaemon() */ #else /* AFS_AIX41_ENV */ @@ -899,167 +928,165 @@ afs_int32 afs_biodcnt = 0; * The list of sleepers is variable afs_bioqueue. The unique address * on which to sleep is passed to get_bioreq as its parameter. */ -/*static*/ struct buf *afs_get_bioreq(self) - struct afs_bioqueue *self; /* address on which to sleep */ +/*static*/ struct buf * +afs_get_bioreq(self) + struct afs_bioqueue *self; /* address on which to sleep */ { - struct buf *bp = (struct buf *) 0; + struct buf *bp = NULL; struct buf *bestbp; struct buf **bestlbpP, **lbpP; int bestage, stop; - struct buf *t1P, *t2P; /* temp pointers for list manipulation */ + struct buf *t1P, *t2P; /* temp pointers for list manipulation */ int oldPriority; afs_uint32 wait_ret; -struct afs_bioqueue *s; + struct afs_bioqueue *s; /* ??? Does the forward pointer of the returned buffer need to be NULL? - */ - - /* Disable interrupts from the strategy function, and save the - * prior priority level - */ - oldPriority = i_disable ( INTMAX ) ; + */ - /* Each iteration of following loop either pulls - * a buffer off afs_asyncbuf, or sleeps. - */ - while (1) { /* inner loop */ - if (afs_asyncbuf) { - /* look for oldest buffer */ - bp = bestbp = afs_asyncbuf; - bestage = (int) bestbp->av_back; - bestlbpP = &afs_asyncbuf; - while (1) { - lbpP = &bp->av_forw; - bp = *lbpP; - if (!bp) break; - if ((int) bp->av_back - bestage < 0) { - bestbp = bp; - bestlbpP = lbpP; - bestage = (int) bp->av_back; - } - } - bp = bestbp; - *bestlbpP = bp->av_forw; - break; - } - else { - int interrupted; - - /* If afs_asyncbuf is null, it is necessary to go to sleep. - * There are two possibilities: either there is already a - * daemon that is sleeping on the address of afs_asyncbuf, - * or there isn't. - */ - if (afs_bioqueue.sleeper) { - /* enqueue */ - QAdd (&(afs_bioqueue.lruq), &(self->lruq)); - interrupted = sleep ((caddr_t) self, PCATCH|(PZERO + 1)); - if (self->lruq.next != &self->lruq) { /* XXX ##3 XXX */ - QRemove (&(self->lruq)); /* dequeue */ - } -self->cnt++; - afs_bioqueue.sleeper = FALSE; - if (interrupted) { - /* re-enable interrupts from strategy */ - i_enable (oldPriority); - return(NULL); - } - continue; - } else { - afs_bioqueue.sleeper = TRUE; - interrupted = sleep ((caddr_t) &afs_asyncbuf, PCATCH|(PZERO + 1)); - afs_bioqueue.sleeper = FALSE; - if (interrupted) - { - /* - * We need to wakeup another daemon if present - * since we were waiting on afs_asyncbuf. - */ -#ifdef notdef /* The following doesn't work as advertised */ - if (afs_bioqueue.lruq.next != &afs_bioqueue.lruq) - { - struct squeue *bq = afs_bioqueue.lruq.next; - QRemove (bq); - wakeup (bq); - } -#endif - /* re-enable interrupts from strategy */ - i_enable (oldPriority); - return(NULL); - } - continue; - } - - } /* end of "else asyncbuf is empty" */ - } /* end of "inner loop" */ - - /*assert (bp);*/ - - i_enable (oldPriority); /* re-enable interrupts from strategy */ - - /* For the convenience of other code, replace the gnodes in - * the b_vp field of bp and the other buffers on the b_work - * chain with the corresponding vnodes. - * - * ??? what happens to the gnodes? They're not just cut loose, - * are they? - */ - for(t1P=bp;;) { - t2P = (struct buf *) t1P->b_work; - t1P->b_vp = ((struct gnode *) t1P->b_vp)->gn_vnode; - if (!t2P) - break; - - t1P = (struct buf *) t2P->b_work; - t2P->b_vp = ((struct gnode *) t2P->b_vp)->gn_vnode; - if (!t1P) - break; - } + /* Disable interrupts from the strategy function, and save the + * prior priority level + */ + oldPriority = i_disable(INTMAX); - /* If the buffer does not specify I/O, it may immediately - * be returned to the caller. This condition is detected - * by examining the buffer's flags (the b_flags field). If - * the B_PFPROT bit is set, the buffer represents a protection - * violation, rather than a request for I/O. The remainder - * of the outer loop handles the case where the B_PFPROT bit is clear. - */ - if (bp->b_flags & B_PFPROT) { - return (bp); + /* Each iteration of following loop either pulls + * a buffer off afs_asyncbuf, or sleeps. + */ + while (1) { /* inner loop */ + if (afs_asyncbuf) { + /* look for oldest buffer */ + bp = bestbp = afs_asyncbuf; + bestage = (int)bestbp->av_back; + bestlbpP = &afs_asyncbuf; + while (1) { + lbpP = &bp->av_forw; + bp = *lbpP; + if (!bp) + break; + if ((int)bp->av_back - bestage < 0) { + bestbp = bp; + bestlbpP = lbpP; + bestage = (int)bp->av_back; + } } + bp = bestbp; + *bestlbpP = bp->av_forw; + break; + } else { + int interrupted; - /* wake up another process to handle the next buffer, and return - * bp to the caller. - */ - oldPriority = i_disable ( INTMAX ) ; - - /* determine where to find the sleeping process. - * There are two cases: either it is sleeping on - * afs_asyncbuf, or it is sleeping on its own unique - * address. These cases are distinguished by examining - * the sleeper field of afs_bioqueue. - */ - if (afs_bioqueue.sleeper) { - wakeup (&afs_asyncbuf); + /* If afs_asyncbuf is null, it is necessary to go to sleep. + * There are two possibilities: either there is already a + * daemon that is sleeping on the address of afs_asyncbuf, + * or there isn't. + */ + if (afs_bioqueue.sleeper) { + /* enqueue */ + QAdd(&(afs_bioqueue.lruq), &(self->lruq)); + interrupted = sleep((caddr_t) self, PCATCH | (PZERO + 1)); + if (self->lruq.next != &self->lruq) { /* XXX ##3 XXX */ + QRemove(&(self->lruq)); /* dequeue */ + } + self->cnt++; + afs_bioqueue.sleeper = FALSE; + if (interrupted) { + /* re-enable interrupts from strategy */ + i_enable(oldPriority); + return (NULL); } - else { - if (afs_bioqueue.lruq.next == &afs_bioqueue.lruq) { - /* queue is empty, what now? ???*/ - /* Should this be impossible, or does */ - /* it just mean that nobody is sleeping? */; - } - else { + continue; + } else { + afs_bioqueue.sleeper = TRUE; + interrupted = + sleep((caddr_t) & afs_asyncbuf, PCATCH | (PZERO + 1)); + afs_bioqueue.sleeper = FALSE; + if (interrupted) { + /* + * We need to wakeup another daemon if present + * since we were waiting on afs_asyncbuf. + */ +#ifdef notdef /* The following doesn't work as advertised */ + if (afs_bioqueue.lruq.next != &afs_bioqueue.lruq) { struct squeue *bq = afs_bioqueue.lruq.next; - QRemove (bq); - QInit (bq); - wakeup (bq); - afs_bioqueue.sleeper = TRUE; - } + QRemove(bq); + wakeup(bq); + } +#endif + /* re-enable interrupts from strategy */ + i_enable(oldPriority); + return (NULL); } - i_enable (oldPriority); /* re-enable interrupts from strategy */ + continue; + } + + } /* end of "else asyncbuf is empty" */ + } /* end of "inner loop" */ + + /*assert (bp); */ + + i_enable(oldPriority); /* re-enable interrupts from strategy */ + + /* For the convenience of other code, replace the gnodes in + * the b_vp field of bp and the other buffers on the b_work + * chain with the corresponding vnodes. + * + * ??? what happens to the gnodes? They're not just cut loose, + * are they? + */ + for (t1P = bp;;) { + t2P = (struct buf *)t1P->b_work; + t1P->b_vp = ((struct gnode *)t1P->b_vp)->gn_vnode; + if (!t2P) + break; + + t1P = (struct buf *)t2P->b_work; + t2P->b_vp = ((struct gnode *)t2P->b_vp)->gn_vnode; + if (!t1P) + break; + } + + /* If the buffer does not specify I/O, it may immediately + * be returned to the caller. This condition is detected + * by examining the buffer's flags (the b_flags field). If + * the B_PFPROT bit is set, the buffer represents a protection + * violation, rather than a request for I/O. The remainder + * of the outer loop handles the case where the B_PFPROT bit is clear. + */ + if (bp->b_flags & B_PFPROT) { return (bp); + } -} /* end of function get_bioreq() */ + /* wake up another process to handle the next buffer, and return + * bp to the caller. + */ + oldPriority = i_disable(INTMAX); + + /* determine where to find the sleeping process. + * There are two cases: either it is sleeping on + * afs_asyncbuf, or it is sleeping on its own unique + * address. These cases are distinguished by examining + * the sleeper field of afs_bioqueue. + */ + if (afs_bioqueue.sleeper) { + wakeup(&afs_asyncbuf); + } else { + if (afs_bioqueue.lruq.next == &afs_bioqueue.lruq) { + /* queue is empty, what now? ??? */ + /* Should this be impossible, or does */ + /* it just mean that nobody is sleeping? */ ; + } else { + struct squeue *bq = afs_bioqueue.lruq.next; + QRemove(bq); + QInit(bq); + wakeup(bq); + afs_bioqueue.sleeper = TRUE; + } + } + i_enable(oldPriority); /* re-enable interrupts from strategy */ + return (bp); + +} /* end of function get_bioreq() */ /* afs_BioDaemon @@ -1071,15 +1098,15 @@ self->cnt++; * each making the appropriate syscall, which will cause this * function to be invoked. */ -static int afs_initbiod = 0; /* this is self-initializing code */ +static int afs_initbiod = 0; /* this is self-initializing code */ int DOvmlock = 0; -afs_BioDaemon (nbiods) - afs_int32 nbiods; +afs_BioDaemon(nbiods) + afs_int32 nbiods; { struct afs_bioqueue *self; afs_int32 code, s, pflg = 0; label_t jmpbuf; - struct buf *bp, *bp1, *tbp1, *tbp2; /* temp pointers only */ + struct buf *bp, *bp1, *tbp1, *tbp2; /* temp pointers only */ caddr_t tmpaddr; struct vnode *vp; struct vcache *vcp; @@ -1088,35 +1115,23 @@ afs_BioDaemon (nbiods) /* XXX ###1 XXX */ afs_initbiod = 1; /* Initialize the queue of waiting processes, afs_bioqueue. */ - QInit (&(afs_bioqueue.lruq)); + QInit(&(afs_bioqueue.lruq)); } /* establish ourself as a kernel process so shutdown won't kill us */ /* u.u_procp->p_flag |= SKPROC;*/ /* Initialize a token (self) to use in the queue of sleeping processes. */ - self = (struct afs_bioqueue *) afs_osi_Alloc (sizeof (struct afs_bioqueue)); - pin (self, sizeof (struct afs_bioqueue)); /* fix in memory */ + self = (struct afs_bioqueue *)afs_osi_Alloc(sizeof(struct afs_bioqueue)); + pin(self, sizeof(struct afs_bioqueue)); /* fix in memory */ memset(self, 0, sizeof(*self)); - QInit (&(self->lruq)); /* initialize queue entry pointers */ + QInit(&(self->lruq)); /* initialize queue entry pointers */ /* Ignore HUP signals... */ -#ifdef AFS_AIX41_ENV - { - sigset_t sigbits, osigbits; - /* - * add SIGHUP to the set of already masked signals - */ - SIGFILLSET(sigbits); /* allow all signals */ - SIGDELSET(sigbits, SIGHUP); /* except SIGHUP */ - limit_sigs(&sigbits, &osigbits); /* and already masked */ - } -#else SIGDELSET(u.u_procp->p_sig, SIGHUP); SIGADDSET(u.u_procp->p_sigignore, SIGHUP); SIGDELSET(u.u_procp->p_sigcatch, SIGHUP); -#endif /* Main body starts here -- this is an intentional infinite loop, and * should NEVER exit * @@ -1126,11 +1141,11 @@ afs_BioDaemon (nbiods) while (1) { bp = afs_get_bioreq(self); if (!bp) - break; /* we were interrupted */ + break; /* we were interrupted */ if (code = setjmpx(&jmpbuf)) { /* This should not have happend, maybe a lack of resources */ s = splimp(); - for (bp1 = bp; bp ; bp = bp1) { + for (bp1 = bp; bp; bp = bp1) { if (bp1) bp1 = bp1->b_work; bp->b_actf = 0; @@ -1143,22 +1158,30 @@ afs_BioDaemon (nbiods) } vcp = VTOAFS(bp->b_vp); if (bp->b_flags & B_PFSTORE) { - ObtainWriteLock(&vcp->lock,210); + ObtainWriteLock(&vcp->lock, 210); if (vcp->v.v_gnode->gn_mwrcnt) { - if (vcp->m.Length < bp->b_bcount + (u_int)dbtob(bp->b_blkno)) - vcp->m.Length = bp->b_bcount + (u_int)dbtob(bp->b_blkno); + afs_offs_t newlength = + (afs_offs_t) dbtob(bp->b_blkno) + bp->b_bcount; + if (vcp->m.Length < newlength) { + afs_Trace4(afs_iclSetp, CM_TRACE_SETLENGTH, + ICL_TYPE_STRING, __FILE__, ICL_TYPE_LONG, + __LINE__, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(vcp->m.Length), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(newlength)); + vcp->m.Length = newlength; + } } ReleaseWriteLock(&vcp->lock); } /* If the buffer represents a protection violation, rather than * an actual request for I/O, no special action need be taken. */ - if ( bp->b_flags & B_PFPROT ) { - iodone (bp); /* Notify all users of the buffer that we're done */ + if (bp->b_flags & B_PFPROT) { + iodone(bp); /* Notify all users of the buffer that we're done */ continue; - } -if (DOvmlock) - ObtainWriteLock(&vcp->pvmlock,558); + } + if (DOvmlock) + ObtainWriteLock(&vcp->pvmlock, 558); /* * First map its data area to a region in the current address space * by calling vm_att with the subspace identifier, and a pointer to @@ -1166,10 +1189,10 @@ if (DOvmlock) * also want to hang onto the old one. */ tmpaddr = bp->b_baddr; - bp->b_baddr = vm_att (bp->b_xmemd.subspace_id, tmpaddr); + bp->b_baddr = vm_att(bp->b_xmemd.subspace_id, tmpaddr); tmperr = afs_ustrategy(bp); /* temp variable saves offset calculation */ - if (tmperr) { /* in non-error case */ - bp->b_flags |= B_ERROR; /* should other flags remain set ??? */ + if (tmperr) { /* in non-error case */ + bp->b_flags |= B_ERROR; /* should other flags remain set ??? */ bp->b_error = tmperr; } @@ -1186,33 +1209,34 @@ if (DOvmlock) * using it by calling iodone. * assumes iodone can modify the b_work field. */ - for(tbp1=bp;;) { - tbp2 = (struct buf *) tbp1->b_work; + for (tbp1 = bp;;) { + tbp2 = (struct buf *)tbp1->b_work; iodone(tbp1); - if (!tbp2) + if (!tbp2) break; - tbp1 = (struct buf *) tbp2->b_work; + tbp1 = (struct buf *)tbp2->b_work; iodone(tbp2); if (!tbp1) break; } -if (DOvmlock) - ReleaseWriteLock(&vcp->pvmlock); /* Unlock the vnode. */ + if (DOvmlock) + ReleaseWriteLock(&vcp->pvmlock); /* Unlock the vnode. */ clrjmpx(&jmpbuf); - } /* infinite loop (unless we're interrupted) */ - unpin (self, sizeof (struct afs_bioqueue)); - afs_osi_Free (self, sizeof (struct afs_bioqueue)); -} /* end of afs_BioDaemon() */ -#endif /* AFS_AIX41_ENV */ + } /* infinite loop (unless we're interrupted) */ + unpin(self, sizeof(struct afs_bioqueue)); + afs_osi_Free(self, sizeof(struct afs_bioqueue)); +} /* end of afs_BioDaemon() */ +#endif /* AFS_AIX41_ENV */ #endif /* AFS_AIX32_ENV */ int afs_nbrs = 0; -void afs_BackgroundDaemon() { +void +afs_BackgroundDaemon(void) +{ struct brequest *tb; int i, foundAny; - afs_int32 pid; AFS_STATCNT(afs_BackgroundDaemon); /* initialize subsystem */ @@ -1221,19 +1245,22 @@ void afs_BackgroundDaemon() { memset((char *)afs_brs, 0, sizeof(afs_brs)); brsInit = 1; #if defined (AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK) - /* - * steal the first daemon for doing delayed DSlot flushing - * (see afs_GetDownDSlot) - */ + /* + * steal the first daemon for doing delayed DSlot flushing + * (see afs_GetDownDSlot) + */ AFS_GUNLOCK(); - afs_sgidaemon(); - return; + afs_sgidaemon(); + return; #endif } afs_nbrs++; - MObtainWriteLock(&afs_xbrs,302); + MObtainWriteLock(&afs_xbrs, 302); while (1) { + int min_ts = 0; + struct brequest *min_tb = NULL; + if (afs_termState == AFSOP_STOP_BKG) { if (--afs_nbrs <= 0) afs_termState = AFSOP_STOP_TRUNCDAEMON; @@ -1241,80 +1268,85 @@ void afs_BackgroundDaemon() { afs_osi_Wakeup(&afs_termState); return; } - + /* find a request */ tb = afs_brs; foundAny = 0; - for(i=0;irefCount > 0) && !(tb->flags & BSTARTED)) { /* new request, not yet picked up */ - tb->flags |= BSTARTED; - MReleaseWriteLock(&afs_xbrs); - foundAny = 1; - afs_Trace1(afs_iclSetp, CM_TRACE_BKG1, - ICL_TYPE_INT32, tb->opcode); - if (tb->opcode == BOP_FETCH) - BPrefetch(tb); - else if (tb->opcode == BOP_STORE) - BStore(tb); - else if (tb->opcode == BOP_PATH) - BPath(tb); - else panic("background bop"); - if (tb->vnode) { + if ((min_tb && (min_ts - tb->ts > 0)) || !min_tb) { + min_tb = tb; + min_ts = tb->ts; + } + } + } + if ((tb = min_tb)) { + /* claim and process this request */ + tb->flags |= BSTARTED; + MReleaseWriteLock(&afs_xbrs); + foundAny = 1; + afs_Trace1(afs_iclSetp, CM_TRACE_BKG1, ICL_TYPE_INT32, + tb->opcode); + if (tb->opcode == BOP_FETCH) + BPrefetch(tb); + else if (tb->opcode == BOP_STORE) + BStore(tb); + else if (tb->opcode == BOP_PATH) + BPath(tb); + else + panic("background bop"); + if (tb->vc) { #ifdef AFS_DEC_ENV - tb->vnode->vrefCount--; /* fix up reference count */ + tb->vc->vrefCount--; /* fix up reference count */ #else - AFS_RELE((struct vnode *)(tb->vnode)); /* MUST call vnode layer or could lose vnodes */ + AFS_RELE(AFSTOV(tb->vc)); /* MUST call vnode layer or could lose vnodes */ #endif - tb->vnode = (struct vcache *) 0; - } - if (tb->cred) { - crfree(tb->cred); - tb->cred = (struct AFS_UCRED *) 0; - } - afs_BRelease(tb); /* this grabs and releases afs_xbrs lock */ - MObtainWriteLock(&afs_xbrs,305); + tb->vc = NULL; + } + if (tb->cred) { + crfree(tb->cred); + tb->cred = (struct AFS_UCRED *)0; } + afs_BRelease(tb); /* this grabs and releases afs_xbrs lock */ + MObtainWriteLock(&afs_xbrs, 305); } if (!foundAny) { /* wait for new request */ afs_brsDaemons++; MReleaseWriteLock(&afs_xbrs); afs_osi_Sleep(&afs_brsDaemons); - MObtainWriteLock(&afs_xbrs,307); + MObtainWriteLock(&afs_xbrs, 307); afs_brsDaemons--; } } } -void shutdown_daemons() +void +shutdown_daemons(void) { - extern int afs_cold_shutdown; - register int i; - register struct brequest *tb; - - AFS_STATCNT(shutdown_daemons); - if (afs_cold_shutdown) { - afs_brsDaemons = brsInit = 0; - rxepoch_checked = afs_nbrs = 0; - memset((char *)afs_brs, 0, sizeof(afs_brs)); - memset((char *)&afs_xbrs, 0, sizeof(afs_lock_t)); - afs_brsWaiters = 0; + AFS_STATCNT(shutdown_daemons); + if (afs_cold_shutdown) { + afs_brsDaemons = brsInit = 0; + rxepoch_checked = afs_nbrs = 0; + memset((char *)afs_brs, 0, sizeof(afs_brs)); + memset((char *)&afs_xbrs, 0, sizeof(afs_lock_t)); + afs_brsWaiters = 0; #ifdef AFS_AIX32_ENV #ifdef AFS_AIX41_ENV - lock_free(&afs_asyncbuf_lock); - unpin(&afs_asyncbuf, sizeof(struct buf*)); - pin (&afs_asyncbuf_cv, sizeof(afs_int32)); + lock_free(&afs_asyncbuf_lock); + unpin(&afs_asyncbuf, sizeof(struct buf *)); + pin(&afs_asyncbuf_cv, sizeof(afs_int32)); #else /* AFS_AIX41_ENV */ - afs_busyq = NULL; - afs_biodcnt = 0; - memset((char *)&afs_bioqueue, 0, sizeof(struct afs_bioqueue)); + afs_busyq = NULL; + afs_biodcnt = 0; + memset((char *)&afs_bioqueue, 0, sizeof(struct afs_bioqueue)); #endif - afs_initbiod = 0; + afs_initbiod = 0; #endif - } + } } #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK) @@ -1334,36 +1366,35 @@ struct dcache *afs_sgibklist; int afs_sgidaemon(void) { - int s; - struct dcache *tdc; + int s; + struct dcache *tdc; - if (afs_sgibklock == NULL) { - SV_INIT(&afs_sgibksync, "bksync", 0, 0); - SV_INIT(&afs_sgibkwait, "bkwait", 0, 0); - SPINLOCK_INIT(&afs_sgibklock, "bklock"); - } - s = SPLOCK(afs_sgibklock); - for (;;) { - /* wait for something to do */ - SP_WAIT(afs_sgibklock, s, &afs_sgibksync, PINOD); - osi_Assert(afs_sgibklist); - - /* XX will probably need to generalize to real list someday */ - s = SPLOCK(afs_sgibklock); - while (afs_sgibklist) { - tdc = afs_sgibklist; - afs_sgibklist = NULL; - SPUNLOCK(afs_sgibklock, s); - AFS_GLOCK(); - tdc->flags &= ~DFEntryMod; - afs_WriteDCache(tdc, 1); - AFS_GUNLOCK(); - s = SPLOCK(afs_sgibklock); - } + if (afs_sgibklock == NULL) { + SV_INIT(&afs_sgibksync, "bksync", 0, 0); + SV_INIT(&afs_sgibkwait, "bkwait", 0, 0); + SPINLOCK_INIT(&afs_sgibklock, "bklock"); + } + s = SPLOCK(afs_sgibklock); + for (;;) { + /* wait for something to do */ + SP_WAIT(afs_sgibklock, s, &afs_sgibksync, PINOD); + osi_Assert(afs_sgibklist); - /* done all the work - wake everyone up */ - while (SV_SIGNAL(&afs_sgibkwait)) - ; + /* XX will probably need to generalize to real list someday */ + s = SPLOCK(afs_sgibklock); + while (afs_sgibklist) { + tdc = afs_sgibklist; + afs_sgibklist = NULL; + SPUNLOCK(afs_sgibklock, s); + AFS_GLOCK(); + tdc->dflags &= ~DFEntryMod; + afs_WriteDCache(tdc, 1); + AFS_GUNLOCK(); + s = SPLOCK(afs_sgibklock); } + + /* done all the work - wake everyone up */ + while (SV_SIGNAL(&afs_sgibkwait)); + } } #endif diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index 4e72d16bf..0a4743e0a 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -1,6 +1,6 @@ /* * Copyright 2000, International Business Machines Corporation and others. - * All Rights Reserved. + *$All Rights Reserved. * * This software has been released under the terms of the IBM Public * License. For details, see the LICENSE file in the top-level source @@ -11,61 +11,67 @@ * Implements: */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_dcache.c,v 1.1.1.10 2003/07/30 17:07:59 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_dcache.c,v 1.42 2004/05/08 04:33:07 shadow Exp $"); -#include "../afs/sysincludes.h" /*Standard vendor system headers*/ -#include "../afs/afsincludes.h" /*AFS-based standard headers*/ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /*Standard vendor system headers */ +#include "afsincludes.h" /*AFS-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/afs_osidnlc.h" /* Forward declarations. */ static void afs_GetDownD(int anumber, int *aneedSpace); static void afs_FreeDiscardedDCache(void); static void afs_DiscardDCache(struct dcache *); - -/* Imported variables */ -extern afs_rwlock_t afs_xvcache; -extern afs_rwlock_t afs_xcbhash; -extern afs_int32 afs_mariner; -extern afs_int32 cacheInfoModTime; /*Last time cache info modified*/ - +static void afs_FreeDCache(struct dcache *); /* * --------------------- Exported definitions --------------------- */ -afs_lock_t afs_xdcache; /*Lock: alloc new disk cache entries*/ -afs_int32 afs_freeDCList; /*Free list for disk cache entries*/ -afs_int32 afs_freeDCCount; /*Count of elts in freeDCList*/ -afs_int32 afs_discardDCList; /*Discarded disk cache entries*/ -afs_int32 afs_discardDCCount; /*Count of elts in discardDCList*/ -struct dcache *afs_freeDSList; /*Free list for disk slots */ -struct dcache *afs_Initial_freeDSList; /*Initial list for above*/ -ino_t cacheInode; /*Inode for CacheItems file*/ +afs_lock_t afs_xdcache; /*Lock: alloc new disk cache entries */ +afs_int32 afs_freeDCList; /*Free list for disk cache entries */ +afs_int32 afs_freeDCCount; /*Count of elts in freeDCList */ +afs_int32 afs_discardDCList; /*Discarded disk cache entries */ +afs_int32 afs_discardDCCount; /*Count of elts in discardDCList */ +struct dcache *afs_freeDSList; /*Free list for disk slots */ +struct dcache *afs_Initial_freeDSList; /*Initial list for above */ +ino_t cacheInode; /*Inode for CacheItems file */ struct osi_file *afs_cacheInodep = 0; /* file for CacheItems inode */ -struct afs_q afs_DLRU; /*dcache LRU*/ +struct afs_q afs_DLRU; /*dcache LRU */ afs_int32 afs_dhashsize = 1024; -afs_int32 *afs_dvhashTbl; /*Data cache hash table*/ -afs_int32 *afs_dchashTbl; /*Data cache hash table*/ -afs_int32 *afs_dvnextTbl; /*Dcache hash table links */ -afs_int32 *afs_dcnextTbl; /*Dcache hash table links */ -struct dcache **afs_indexTable; /*Pointers to dcache entries*/ -afs_hyper_t *afs_indexTimes; /*Dcache entry Access times*/ -afs_int32 *afs_indexUnique; /*dcache entry Fid.Unique */ -unsigned char *afs_indexFlags; /*(only one) Is there data there?*/ -afs_hyper_t afs_indexCounter; /*Fake time for marking index - entries*/ -afs_int32 afs_cacheFiles =0; /*Size of afs_indexTable*/ -afs_int32 afs_cacheBlocks; /*1K blocks in cache*/ -afs_int32 afs_cacheStats; /*Stat entries in cache*/ -afs_int32 afs_blocksUsed; /*Number of blocks in use*/ -afs_int32 afs_blocksDiscarded; /*Blocks freed but not truncated */ -afs_int32 afs_fsfragsize = 1023; /*Underlying Filesystem minimum unit +afs_int32 *afs_dvhashTbl; /*Data cache hash table */ +afs_int32 *afs_dchashTbl; /*Data cache hash table */ +afs_int32 *afs_dvnextTbl; /*Dcache hash table links */ +afs_int32 *afs_dcnextTbl; /*Dcache hash table links */ +struct dcache **afs_indexTable; /*Pointers to dcache entries */ +afs_hyper_t *afs_indexTimes; /*Dcache entry Access times */ +afs_int32 *afs_indexUnique; /*dcache entry Fid.Unique */ +unsigned char *afs_indexFlags; /*(only one) Is there data there? */ +afs_hyper_t afs_indexCounter; /*Fake time for marking index + * entries */ +afs_int32 afs_cacheFiles = 0; /*Size of afs_indexTable */ +afs_int32 afs_cacheBlocks; /*1K blocks in cache */ +afs_int32 afs_cacheStats; /*Stat entries in cache */ +afs_int32 afs_blocksUsed; /*Number of blocks in use */ +afs_int32 afs_blocksDiscarded; /*Blocks freed but not truncated */ +afs_int32 afs_fsfragsize = 1023; /*Underlying Filesystem minimum unit *of disk allocation usually 1K *this value is (truefrag -1 ) to *save a bunch of subtracts... */ +#ifdef AFS_64BIT_CLIENT +#ifdef AFS_VM_RDWR_ENV +afs_size_t afs_vmMappingEnd; /* for large files (>= 2GB) the VM + * mapping an 32bit addressing machines + * can only be used below the 2 GB + * line. From this point upwards we + * must do direct I/O into the cache + * files. The value should be on a + * chunk boundary. */ +#endif /* AFS_VM_RDWR_ENV */ +#endif /* AFS_64BIT_CLIENT */ /* The following is used to ensure that new dcache's aren't obtained when * the cache is nearly full. @@ -74,17 +80,12 @@ int afs_WaitForCacheDrain = 0; int afs_TruncateDaemonRunning = 0; int afs_CacheTooFull = 0; -afs_int32 afs_dcentries; /* In-memory dcache entries */ +afs_int32 afs_dcentries; /* In-memory dcache entries */ int dcacheDisabled = 0; -extern struct dcache *afs_UFSGetDSlot(); -extern struct volume *afs_UFSGetVolSlot(); -extern int osi_UFSTruncate(), afs_osi_Read(), afs_osi_Write(), osi_UFSClose(); -extern int afs_UFSRead(), afs_UFSWrite(); static int afs_UFSCacheFetchProc(), afs_UFSCacheStoreProc(); -extern int afs_UFSHandleLink(); struct afs_cacheOps afs_UfsCacheOps = { osi_UFSOpen, osi_UFSTruncate, @@ -100,12 +101,6 @@ struct afs_cacheOps afs_UfsCacheOps = { afs_UFSHandleLink, }; -extern void *afs_MemCacheOpen(); -extern struct dcache *afs_MemGetDSlot(); -extern struct volume *afs_MemGetVolSlot(); -extern int afs_MemCacheTruncate(), afs_MemReadBlk(), afs_MemWriteBlk(), afs_MemCacheClose(); -extern int afs_MemRead(), afs_MemWrite(), afs_MemCacheFetchProc(), afs_MemCacheStoreProc(); -extern int afs_MemHandleLink(); struct afs_cacheOps afs_MemCacheOps = { afs_MemCacheOpen, afs_MemCacheTruncate, @@ -121,7 +116,7 @@ struct afs_cacheOps afs_MemCacheOps = { afs_MemHandleLink, }; -int cacheDiskType; /*Type of backing disk for cache*/ +int cacheDiskType; /*Type of backing disk for cache */ struct afs_cacheOps *afs_cacheType; @@ -145,72 +140,77 @@ struct afs_cacheOps *afs_cacheType; */ void -afs_StoreWarn(acode, avolume, aflags) - register afs_int32 acode; - afs_int32 avolume; - register afs_int32 aflags; - -{ /*afs_StoreWarn*/ - +afs_StoreWarn(register afs_int32 acode, afs_int32 avolume, + register afs_int32 aflags) +{ static char problem_fmt[] = "afs: failed to store file in volume %d (%s)\n"; static char problem_fmt_w_error[] = "afs: failed to store file in volume %d (error %d)\n"; static char netproblems[] = "network problems"; - static char partfull[] = "partition full"; - static char overquota[] = "over quota"; - static char unknownerr[] = "unknown error"; + static char partfull[] = "partition full"; + static char overquota[] = "over quota"; AFS_STATCNT(afs_StoreWarn); if (acode < 0) { - /* + /* * Network problems */ - if (aflags & 1) + if (aflags & 1) afs_warn(problem_fmt, avolume, netproblems); - if (aflags & 2) + if (aflags & 2) afs_warnuser(problem_fmt, avolume, netproblems); - } - else - if (acode == ENOSPC) { - /* - * Partition full - */ - if (aflags & 1) - afs_warn(problem_fmt, avolume, partfull); - if (aflags & 2) - afs_warnuser(problem_fmt, avolume, partfull); - } - else + } else if (acode == ENOSPC) { + /* + * Partition full + */ + if (aflags & 1) + afs_warn(problem_fmt, avolume, partfull); + if (aflags & 2) + afs_warnuser(problem_fmt, avolume, partfull); + } else #ifdef EDQUOT - /* EDQUOT doesn't exist on solaris and won't be sent by the server. - * Instead ENOSPC will be sent... - */ - if (acode == EDQUOT) { - /* - * Quota exceeded - */ - if (aflags & 1) - afs_warn(problem_fmt, avolume, overquota); - if (aflags & 2) - afs_warnuser(problem_fmt, avolume, overquota); - } else + /* EDQUOT doesn't exist on solaris and won't be sent by the server. + * Instead ENOSPC will be sent... + */ + if (acode == EDQUOT) { + /* + * Quota exceeded + */ + if (aflags & 1) + afs_warn(problem_fmt, avolume, overquota); + if (aflags & 2) + afs_warnuser(problem_fmt, avolume, overquota); + } else #endif - { - /* - * Unknown error - */ - if (aflags & 1) - afs_warn(problem_fmt_w_error, avolume, acode); - if (aflags & 2) - afs_warnuser(problem_fmt_w_error, avolume, acode); - } -} /*afs_StoreWarn*/ + { + /* + * Unknown error + */ + if (aflags & 1) + afs_warn(problem_fmt_w_error, avolume, acode); + if (aflags & 2) + afs_warnuser(problem_fmt_w_error, avolume, acode); + } +} /*afs_StoreWarn */ + +void +afs_MaybeWakeupTruncateDaemon(void) +{ + if (!afs_CacheTooFull && afs_CacheIsTooFull()) { + afs_CacheTooFull = 1; + if (!afs_TruncateDaemonRunning) + afs_osi_Wakeup((int *)afs_CacheTruncateDaemon); + } else if (!afs_TruncateDaemonRunning + && afs_blocksDiscarded > CM_MAXDISCARDEDCHUNKS) { + afs_osi_Wakeup((int *)afs_CacheTruncateDaemon); + } +} /* Keep statistics on run time for afs_CacheTruncateDaemon. This is a * struct so we need only export one symbol for AIX. */ -struct CTD_stats { +static struct CTD_stats { osi_timeval_t CTD_beforeSleep; osi_timeval_t CTD_afterSleep; osi_timeval_t CTD_sleepTime; @@ -218,38 +218,34 @@ struct CTD_stats { int CTD_nSleeps; } CTD_stats; -void afs_MaybeWakeupTruncateDaemon() { - if (!afs_CacheTooFull && afs_CacheIsTooFull()) { - afs_CacheTooFull = 1; - if (!afs_TruncateDaemonRunning) - afs_osi_Wakeup((char *)afs_CacheTruncateDaemon); - } else if (!afs_TruncateDaemonRunning && - afs_blocksDiscarded > CM_MAXDISCARDEDCHUNKS) { - afs_osi_Wakeup((char *)afs_CacheTruncateDaemon); - } -} - u_int afs_min_cache = 0; -void afs_CacheTruncateDaemon() { +void +afs_CacheTruncateDaemon(void) +{ osi_timeval_t CTD_tmpTime; u_int counter; u_int cb_lowat; - u_int dc_hiwat = (100-CM_DCACHECOUNTFREEPCT+CM_DCACHEEXTRAPCT)*afs_cacheFiles/100; - afs_min_cache = (((10 * AFS_CHUNKSIZE(0)) + afs_fsfragsize) & ~afs_fsfragsize)>>10; + u_int dc_hiwat = + (100 - CM_DCACHECOUNTFREEPCT + + CM_DCACHEEXTRAPCT) * afs_cacheFiles / 100; + afs_min_cache = + (((10 * AFS_CHUNKSIZE(0)) + afs_fsfragsize) & ~afs_fsfragsize) >> 10; osi_GetuTime(&CTD_stats.CTD_afterSleep); afs_TruncateDaemonRunning = 1; while (1) { - cb_lowat = ((CM_DCACHESPACEFREEPCT-CM_DCACHEEXTRAPCT) - * afs_cacheBlocks) / 100; - MObtainWriteLock(&afs_xdcache,266); + cb_lowat = ((CM_DCACHESPACEFREEPCT - CM_DCACHEEXTRAPCT) + * afs_cacheBlocks) / 100; + MObtainWriteLock(&afs_xdcache, 266); if (afs_CacheTooFull) { - int space_needed, slots_needed; + int space_needed, slots_needed; /* if we get woken up, we should try to clean something out */ for (counter = 0; counter < 10; counter++) { - space_needed = afs_blocksUsed - afs_blocksDiscarded - cb_lowat; - slots_needed = dc_hiwat - afs_freeDCCount - afs_discardDCCount; - afs_GetDownD(slots_needed, &space_needed); + space_needed = + afs_blocksUsed - afs_blocksDiscarded - cb_lowat; + slots_needed = + dc_hiwat - afs_freeDCCount - afs_discardDCCount; + afs_GetDownD(slots_needed, &space_needed); if ((space_needed <= 0) && (slots_needed <= 0)) { break; } @@ -268,26 +264,24 @@ void afs_CacheTruncateDaemon() { * any cache files then give up the global lock so other * threads get a chance to run. */ - if ((afs_termState!=AFSOP_STOP_TRUNCDAEMON) && afs_CacheTooFull && - (!afs_blocksDiscarded || afs_WaitForCacheDrain)) { - afs_osi_Wait(100, 0, 0); /* 100 milliseconds */ + if ((afs_termState != AFSOP_STOP_TRUNCDAEMON) && afs_CacheTooFull + && (!afs_blocksDiscarded || afs_WaitForCacheDrain)) { + afs_osi_Wait(100, 0, 0); /* 100 milliseconds */ } /* * This is where we free the discarded cache elements. */ - while(afs_blocksDiscarded && !afs_WaitForCacheDrain && - (afs_termState!=AFSOP_STOP_TRUNCDAEMON)) - { + while (afs_blocksDiscarded && !afs_WaitForCacheDrain + && (afs_termState != AFSOP_STOP_TRUNCDAEMON)) { afs_FreeDiscardedDCache(); } /* See if we need to continue to run. Someone may have * signalled us while we were executing. */ - if (!afs_WaitForCacheDrain && !afs_CacheTooFull && - (afs_termState!=AFSOP_STOP_TRUNCDAEMON)) - { + if (!afs_WaitForCacheDrain && !afs_CacheTooFull + && (afs_termState != AFSOP_STOP_TRUNCDAEMON)) { /* Collect statistics on truncate daemon. */ CTD_stats.CTD_nSleeps++; osi_GetuTime(&CTD_stats.CTD_beforeSleep); @@ -296,7 +290,7 @@ void afs_CacheTruncateDaemon() { afs_stats_AddTo(CTD_stats.CTD_runTime, CTD_tmpTime); afs_TruncateDaemonRunning = 0; - afs_osi_Sleep((char *)afs_CacheTruncateDaemon); + afs_osi_Sleep((int *)afs_CacheTruncateDaemon); afs_TruncateDaemonRunning = 1; osi_GetuTime(&CTD_stats.CTD_afterSleep); @@ -334,30 +328,25 @@ void afs_CacheTruncateDaemon() { */ void -afs_AdjustSize(adc, anewSize) - register struct dcache *adc; - register afs_int32 anewSize; - -{ /*afs_AdjustSize*/ - +afs_AdjustSize(register struct dcache *adc, register afs_int32 newSize) +{ register afs_int32 oldSize; AFS_STATCNT(afs_AdjustSize); - adc->flags |= DFEntryMod; - oldSize = ((adc->f.chunkBytes + afs_fsfragsize)^afs_fsfragsize)>>10;/* round up */ - adc->f.chunkBytes = anewSize; - anewSize = ((anewSize + afs_fsfragsize)^afs_fsfragsize)>>10;/* round up */ - if (anewSize > oldSize) { + + adc->dflags |= DFEntryMod; + oldSize = ((adc->f.chunkBytes + afs_fsfragsize) ^ afs_fsfragsize) >> 10; /* round up */ + adc->f.chunkBytes = newSize; + if (!newSize) + adc->validPos = 0; + newSize = ((newSize + afs_fsfragsize) ^ afs_fsfragsize) >> 10; /* round up */ + if (newSize > oldSize) { /* We're growing the file, wakeup the daemon */ afs_MaybeWakeupTruncateDaemon(); } - afs_blocksUsed += (anewSize - oldSize); + afs_blocksUsed += (newSize - oldSize); afs_stats_cmperf.cacheBlocksInUse = afs_blocksUsed; /* XXX */ - -} /*afs_AdjustSize*/ - - - +} /* @@ -373,7 +362,7 @@ afs_AdjustSize(adc, anewSize) * * Environment: * The anumber parameter is just a hint; at least one entry MUST be - * moved, of we'll panic. We must be called with afs_xdcache + * moved, or we'll panic. We must be called with afs_xdcache * write-locked. We should try to satisfy both anumber and aneedspace, * whichever is more demanding - need to do several things: * 1. only grab up to anumber victims if aneedSpace <= 0, not @@ -386,21 +375,22 @@ afs_AdjustSize(adc, anewSize) */ #define MAXATONCE 16 /* max we can obtain at once */ -static void afs_GetDownD(int anumber, int *aneedSpace) +static void +afs_GetDownD(int anumber, int *aneedSpace) { struct dcache *tdc; struct VenusFid *afid; - afs_int32 i, j, k; + afs_int32 i, j; afs_hyper_t vtime; int skip, phase; register struct vcache *tvc; afs_uint32 victims[MAXATONCE]; struct dcache *victimDCs[MAXATONCE]; - afs_hyper_t victimTimes[MAXATONCE];/* youngest (largest LRU time) first */ - afs_uint32 victimPtr; /* next free item in victim arrays */ - afs_hyper_t maxVictimTime; /* youngest (largest LRU time) victim */ - afs_uint32 maxVictimPtr; /* where it is */ + afs_hyper_t victimTimes[MAXATONCE]; /* youngest (largest LRU time) first */ + afs_uint32 victimPtr; /* next free item in victim arrays */ + afs_hyper_t maxVictimTime; /* youngest (largest LRU time) victim */ + afs_uint32 maxVictimPtr; /* where it is */ int discard; AFS_STATCNT(afs_GetDownD); @@ -411,11 +401,12 @@ static void afs_GetDownD(int anumber, int *aneedSpace) * because we should try to free space even if anumber <=0 */ if (!aneedSpace || *aneedSpace <= 0) { anumber -= afs_freeDCCount; - if (anumber <= 0) return; /* enough already free */ + if (anumber <= 0) + return; /* enough already free */ } /* bounds check parameter */ - if (anumber > MAXATONCE) - anumber = MAXATONCE; /* all we can do */ + if (anumber > MAXATONCE) + anumber = MAXATONCE; /* all we can do */ /* * The phase variable manages reclaims. Set to 0, the first pass, @@ -427,25 +418,26 @@ static void afs_GetDownD(int anumber, int *aneedSpace) /* turn off all flags */ afs_indexFlags[i] &= ~IFFlag; - while (anumber > 0 || (aneedSpace && *aneedSpace >0)) { + while (anumber > 0 || (aneedSpace && *aneedSpace > 0)) { /* find oldest entries for reclamation */ maxVictimPtr = victimPtr = 0; hzero(maxVictimTime); /* select victims from access time array */ for (i = 0; i < afs_cacheFiles; i++) { if (afs_indexFlags[i] & (IFDataMod | IFFree | IFDiscarded)) { - /* skip if dirty or already free */ - continue; + /* skip if dirty or already free */ + continue; } tdc = afs_indexTable[i]; if (tdc && (tdc->refCount != 0)) { - /* Referenced; can't use it! */ - continue; + /* Referenced; can't use it! */ + continue; } hset(vtime, afs_indexTimes[i]); /* if we've already looked at this one, skip it */ - if (afs_indexFlags[i] & IFFlag) continue; + if (afs_indexFlags[i] & IFFlag) + continue; if (victimPtr < MAXATONCE) { /* if there's at least one free victim slot left */ @@ -456,35 +448,44 @@ static void afs_GetDownD(int anumber, int *aneedSpace) maxVictimPtr = victimPtr; } victimPtr++; - } - else if (hcmp(vtime, maxVictimTime) < 0) { + } else if (hcmp(vtime, maxVictimTime) < 0) { /* * We're older than youngest victim, so we replace at * least one victim */ /* find youngest (largest LRU) victim */ - j = maxVictimPtr; - if (j == victimPtr) osi_Panic("getdownd local"); + j = maxVictimPtr; + if (j == victimPtr) + osi_Panic("getdownd local"); victims[j] = i; hset(victimTimes[j], vtime); /* recompute maxVictimTime */ hset(maxVictimTime, vtime); - for(j = 0; j < victimPtr; j++) + for (j = 0; j < victimPtr; j++) if (hcmp(maxVictimTime, victimTimes[j]) < 0) { hset(maxVictimTime, victimTimes[j]); maxVictimPtr = j; } } - } /* big for loop */ + } /* big for loop */ /* now really reclaim the victims */ - j = 0; /* flag to track if we actually got any of the victims */ + j = 0; /* flag to track if we actually got any of the victims */ /* first, hold all the victims, since we're going to release the lock * during the truncate operation. */ - for(i=0; i < victimPtr; i++) - victimDCs[i] = afs_GetDSlot(victims[i], 0); - for(i = 0; i < victimPtr; i++) { + for (i = 0; i < victimPtr; i++) { + tdc = afs_GetDSlot(victims[i], 0); + /* We got tdc->tlock(R) here */ + if (tdc->refCount == 1) + victimDCs[i] = tdc; + else + victimDCs[i] = 0; + ReleaseReadLock(&tdc->tlock); + if (!victimDCs[i]) + afs_PutDCache(tdc); + } + for (i = 0; i < victimPtr; i++) { /* q is first elt in dcache entry */ tdc = victimDCs[i]; /* now, since we're dropping the afs_xdcache lock below, we @@ -493,28 +494,34 @@ static void afs_GetDownD(int anumber, int *aneedSpace) * compare with 1, since we bumped it above when we called * afs_GetDSlot to preserve the entry's identity. */ - if (tdc->refCount == 1) { + if (tdc && tdc->refCount == 1) { unsigned char chunkFlags; - afid = &tdc->f.fid; + afs_size_t tchunkoffset = 0; + afid = &tdc->f.fid; /* xdcache is lower than the xvcache lock */ MReleaseWriteLock(&afs_xdcache); MObtainReadLock(&afs_xvcache); - tvc = afs_FindVCache(afid, 0,0, 0, 0 /* no stats, no vlru */ ); + tvc = afs_FindVCache(afid, 0, 0 /* no stats, no vlru */ ); MReleaseReadLock(&afs_xvcache); MObtainWriteLock(&afs_xdcache, 527); skip = 0; - if (tdc->refCount > 1) skip = 1; + if (tdc->refCount > 1) + skip = 1; if (tvc) { + tchunkoffset = AFS_CHUNKTOBASE(tdc->f.chunk); chunkFlags = afs_indexFlags[tdc->index]; - if (phase == 0 && osi_Active(tvc)) skip = 1; - if (phase > 0 && osi_Active(tvc) && (tvc->states & CDCLock) - && (chunkFlags & IFAnyPages)) skip = 1; - if (chunkFlags & IFDataMod) skip = 1; + if (phase == 0 && osi_Active(tvc)) + skip = 1; + if (phase > 0 && osi_Active(tvc) + && (tvc->states & CDCLock) + && (chunkFlags & IFAnyPages)) + skip = 1; + if (chunkFlags & IFDataMod) + skip = 1; afs_Trace4(afs_iclSetp, CM_TRACE_GETDOWND, ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, skip, - ICL_TYPE_INT32, - (afs_int32)(chunkFlags & IFDirtyPages), - ICL_TYPE_INT32, AFS_CHUNKTOBASE(tdc->f.chunk)); + ICL_TYPE_INT32, tdc->index, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(tchunkoffset)); #if defined(AFS_SUN5_ENV) /* @@ -540,10 +547,9 @@ static void afs_GetDownD(int anumber, int *aneedSpace) /* One last recheck */ MObtainWriteLock(&afs_xdcache, 333); chunkFlags = afs_indexFlags[tdc->index]; - if (tdc->refCount > 1 - || (chunkFlags & IFDataMod) + if (tdc->refCount > 1 || (chunkFlags & IFDataMod) || (osi_Active(tvc) && (tvc->states & CDCLock) - && (chunkFlags & IFAnyPages))) { + && (chunkFlags & IFAnyPages))) { skip = 1; MReleaseWriteLock(&afs_xdcache); goto endputpage; @@ -552,16 +558,18 @@ static void afs_GetDownD(int anumber, int *aneedSpace) code = osi_VM_GetDownD(tvc, tdc); - MObtainWriteLock(&afs_xdcache,269); + MObtainWriteLock(&afs_xdcache, 269); /* we actually removed all pages, clean and dirty */ if (code == 0) { - afs_indexFlags[tdc->index] &= ~(IFDirtyPages| IFAnyPages); + afs_indexFlags[tdc->index] &= + ~(IFDirtyPages | IFAnyPages); } else skip = 1; MReleaseWriteLock(&afs_xdcache); -endputpage: + endputpage: MObtainWriteLock(&tvc->vlock, 544); - if (--tvc->activeV == 0 && (tvc->vstates & VRevokeWait)) { + if (--tvc->activeV == 0 + && (tvc->vstates & VRevokeWait)) { tvc->vstates &= ~VRevokeWait; afs_osi_Wakeup((char *)&tvc->vstates); @@ -570,10 +578,10 @@ endputpage: tvc->vstates &= ~VPageCleaning; afs_osi_Wakeup((char *)&tvc->vstates); } -endmultipage: + endmultipage: MReleaseWriteLock(&tvc->vlock); } else -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ { MReleaseWriteLock(&afs_xdcache); } @@ -581,8 +589,10 @@ endmultipage: AFS_FAST_RELE(tvc); MObtainWriteLock(&afs_xdcache, 528); if (afs_indexFlags[tdc->index] & - (IFDataMod | IFDirtyPages | IFAnyPages)) skip = 1; - if (tdc->refCount > 1) skip = 1; + (IFDataMod | IFDirtyPages | IFAnyPages)) + skip = 1; + if (tdc->refCount > 1) + skip = 1; } #if defined(AFS_SUN5_ENV) else { @@ -593,20 +603,28 @@ endmultipage: * Hold vcache lock to prevent vnode from being * created while we're clearing IFDirtyPages. */ - afs_indexFlags[tdc->index] &= ~(IFDirtyPages | IFAnyPages); + afs_indexFlags[tdc->index] &= + ~(IFDirtyPages | IFAnyPages); } #endif if (skip) { /* skip this guy and mark him as recently used */ afs_indexFlags[tdc->index] |= IFFlag; - } - else { + afs_Trace4(afs_iclSetp, CM_TRACE_GETDOWND, + ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, 2, + ICL_TYPE_INT32, tdc->index, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(tchunkoffset)); + } else { /* flush this dude from the data cache and reclaim; - * first, make sure no one will care that we damage - * it, by removing it from all hash tables. Then, - * melt it down for parts. Note that any concurrent - * (new possibility!) calls to GetDownD won't touch - * this guy because his reference count is > 0. */ + * first, make sure no one will care that we damage + * it, by removing it from all hash tables. Then, + * melt it down for parts. Note that any concurrent + * (new possibility!) calls to GetDownD won't touch + * this guy because his reference count is > 0. */ + afs_Trace4(afs_iclSetp, CM_TRACE_GETDOWND, + ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, 3, + ICL_TYPE_INT32, tdc->index, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(tchunkoffset)); #ifndef AFS_DEC_ENV AFS_STATCNT(afs_gget); #endif @@ -614,7 +632,8 @@ endmultipage: if (tdc->f.chunkBytes != 0) { discard = 1; if (aneedSpace) - *aneedSpace -= (tdc->f.chunkBytes + afs_fsfragsize) >> 10; + *aneedSpace -= + (tdc->f.chunkBytes + afs_fsfragsize) >> 10; } else { discard = 0; } @@ -627,13 +646,9 @@ endmultipage: j = 1; /* we reclaimed at least one victim */ } } -#ifdef AFS_SUN5_ENVX afs_PutDCache(tdc); -#else - tdc->refCount--; /* put it back */ -#endif } - + if (phase == 0) { /* Phase is 0 and no one was found, so try phase 1 (ignore * osi_Active flag) */ @@ -643,15 +658,15 @@ endmultipage: /* turn off all flags */ afs_indexFlags[i] &= ~IFFlag; } - } - else { + } else { /* found no one in phase 1, we're hosed */ - if (victimPtr == 0) break; + if (victimPtr == 0) + break; } - } /* big while loop */ + } /* big while loop */ return; -} /*afs_GetDownD*/ +} /*afs_GetDownD */ /* @@ -662,11 +677,9 @@ endmultipage: * * Locks: Must have the afs_xdcache lock write-locked to call this function. */ -afs_HashOutDCache(adc) - struct dcache *adc; - -{ /*afs_HashOutDCache*/ - +int +afs_HashOutDCache(struct dcache *adc) +{ int i, us; #ifndef AFS_DEC_ENV @@ -682,8 +695,7 @@ afs_HashOutDCache(adc) if (us == adc->index) { /* first dude in the list */ afs_dchashTbl[i] = afs_dcnextTbl[adc->index]; - } - else { + } else { /* somewhere on the chain */ while (us != NULLIDX) { if (afs_dcnextTbl[us] == adc->index) { @@ -693,7 +705,8 @@ afs_HashOutDCache(adc) } us = afs_dcnextTbl[us]; } - if (us == NULLIDX) osi_Panic("dcache hc"); + if (us == NULLIDX) + osi_Panic("dcache hc"); } /* remove entry from *other* hash chain */ i = DVHash(&adc->f.fid); @@ -701,8 +714,7 @@ afs_HashOutDCache(adc) if (us == adc->index) { /* first dude in the list */ afs_dvhashTbl[i] = afs_dvnextTbl[adc->index]; - } - else { + } else { /* somewhere on the chain */ while (us != NULLIDX) { if (afs_dvnextTbl[us] == adc->index) { @@ -712,7 +724,8 @@ afs_HashOutDCache(adc) } us = afs_dvnextTbl[us]; } - if (us == NULLIDX) osi_Panic("dcache hv"); + if (us == NULLIDX) + osi_Panic("dcache hv"); } } @@ -723,11 +736,11 @@ afs_HashOutDCache(adc) adc->f.fid.Fid.Volume = 0; /* invalid */ /* mark entry as modified */ - adc->flags |= DFEntryMod; + adc->dflags |= DFEntryMod; /* all done */ return 0; -} /*afs_HashOutDCache */ +} /*afs_HashOutDCache */ /* @@ -746,10 +759,8 @@ afs_HashOutDCache(adc) */ void -afs_FlushDCache(adc) -register struct dcache *adc; -{ /*afs_FlushDCache*/ - +afs_FlushDCache(register struct dcache *adc) +{ AFS_STATCNT(afs_FlushDCache); /* * Bump the number of cache files flushed. @@ -773,12 +784,12 @@ register struct dcache *adc; if (afs_WaitForCacheDrain) { if (afs_blocksUsed <= - (CM_CACHESIZEDRAINEDPCT*afs_cacheBlocks)/100) { + (CM_CACHESIZEDRAINEDPCT * afs_cacheBlocks) / 100) { afs_WaitForCacheDrain = 0; afs_osi_Wakeup(&afs_WaitForCacheDrain); } } -} /*afs_FlushDCache*/ +} /*afs_FlushDCache */ /* @@ -790,8 +801,9 @@ register struct dcache *adc; * * Environment: called with afs_xdcache lock write-locked. */ -afs_FreeDCache(adc) -register struct dcache *adc; { +static void +afs_FreeDCache(register struct dcache *adc) +{ /* Thread on free list, update free list count and mark entry as * freed in its indexFlags element. Also, ensure DCache entry gets * written out (set DFEntryMod). @@ -801,16 +813,15 @@ register struct dcache *adc; { afs_freeDCList = adc->index; afs_freeDCCount++; afs_indexFlags[adc->index] |= IFFree; - adc->flags |= DFEntryMod; + adc->dflags |= DFEntryMod; if (afs_WaitForCacheDrain) { if ((afs_blocksUsed - afs_blocksDiscarded) <= - (CM_CACHESIZEDRAINEDPCT*afs_cacheBlocks)/100) { + (CM_CACHESIZEDRAINEDPCT * afs_cacheBlocks) / 100) { afs_WaitForCacheDrain = 0; afs_osi_Wakeup(&afs_WaitForCacheDrain); } } - return 0; } /* @@ -828,18 +839,21 @@ register struct dcache *adc; { * * Parameters: * adc : Ptr to dcache entry. + * + * Environment: + * Must be called with afs_xdcache write-locked. */ static void -afs_DiscardDCache(adc) - register struct dcache *adc; - -{ /*afs_DiscardDCache*/ - +afs_DiscardDCache(register struct dcache *adc) +{ register afs_int32 size; AFS_STATCNT(afs_DiscardDCache); - size = ((adc->f.chunkBytes + afs_fsfragsize)^afs_fsfragsize)>>10;/* round up */ + + osi_Assert(adc->refCount == 1); + + size = ((adc->f.chunkBytes + afs_fsfragsize) ^ afs_fsfragsize) >> 10; /* round up */ afs_blocksDiscarded += size; afs_stats_cmperf.cacheBlocksDiscarded = afs_blocksDiscarded; @@ -848,18 +862,18 @@ afs_DiscardDCache(adc) afs_discardDCCount++; adc->f.fid.Fid.Volume = 0; - adc->flags |= DFEntryMod; + adc->dflags |= DFEntryMod; afs_indexFlags[adc->index] |= IFDiscarded; if (afs_WaitForCacheDrain) { if ((afs_blocksUsed - afs_blocksDiscarded) <= - (CM_CACHESIZEDRAINEDPCT*afs_cacheBlocks)/100) { + (CM_CACHESIZEDRAINEDPCT * afs_cacheBlocks) / 100) { afs_WaitForCacheDrain = 0; afs_osi_Wakeup(&afs_WaitForCacheDrain); } } -} /*afs_DiscardDCache*/ +} /*afs_DiscardDCache */ /* * afs_FreeDiscardedDCache @@ -868,15 +882,15 @@ afs_DiscardDCache(adc) * Free the next element on the list of discarded cache elements. */ static void -afs_FreeDiscardedDCache() +afs_FreeDiscardedDCache(void) { register struct dcache *tdc; - register struct osi_file *tfile; + register struct osi_file *tfile; register afs_int32 size; AFS_STATCNT(afs_FreeDiscardedDCache); - MObtainWriteLock(&afs_xdcache,510); + MObtainWriteLock(&afs_xdcache, 510); if (!afs_blocksDiscarded) { MReleaseWriteLock(&afs_xdcache); return; @@ -886,12 +900,17 @@ afs_FreeDiscardedDCache() * Get an entry from the list of discarded cache elements */ tdc = afs_GetDSlot(afs_discardDCList, 0); + osi_Assert(tdc->refCount == 1); + ReleaseReadLock(&tdc->tlock); + afs_discardDCList = afs_dvnextTbl[tdc->index]; afs_dvnextTbl[tdc->index] = NULLIDX; afs_discardDCCount--; - size = ((tdc->f.chunkBytes + afs_fsfragsize)^afs_fsfragsize)>>10;/* round up */ + size = ((tdc->f.chunkBytes + afs_fsfragsize) ^ afs_fsfragsize) >> 10; /* round up */ afs_blocksDiscarded -= size; afs_stats_cmperf.cacheBlocksDiscarded = afs_blocksDiscarded; + /* We can lock because we just took it off the free list */ + ObtainWriteLock(&tdc->lock, 626); MReleaseWriteLock(&afs_xdcache); /* @@ -905,10 +924,11 @@ afs_FreeDiscardedDCache() /* * Free the element we just truncated */ - MObtainWriteLock(&afs_xdcache,511); + MObtainWriteLock(&afs_xdcache, 511); afs_indexFlags[tdc->index] &= ~IFDiscarded; afs_FreeDCache(tdc); - tdc->refCount--; + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); MReleaseWriteLock(&afs_xdcache); } @@ -922,13 +942,15 @@ afs_FreeDiscardedDCache() * Parameters: * None */ -afs_MaybeFreeDiscardedDCache() +int +afs_MaybeFreeDiscardedDCache(void) { AFS_STATCNT(afs_MaybeFreeDiscardedDCache); - while (afs_blocksDiscarded && - (afs_blocksUsed > (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100)) { + while (afs_blocksDiscarded + && (afs_blocksUsed > + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100)) { afs_FreeDiscardedDCache(); } return 0; @@ -942,24 +964,16 @@ afs_MaybeFreeDiscardedDCache() * * Parameters: * anumber : Targeted number of disk slots to free up. + * + * Environment: + * Must be called with afs_xdcache write-locked. */ -#if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK) -extern SV_TYPE afs_sgibksync; -extern SV_TYPE afs_sgibkwait; -extern lock_t afs_sgibklock; -extern struct dcache *afs_sgibklist; -#endif - static void -afs_GetDownDSlot(anumber) - int anumber; - -{ /*afs_GetDownDSlot*/ - +afs_GetDownDSlot(int anumber) +{ struct afs_q *tq, *nq; struct dcache *tdc; int ix; - unsigned int i=0; unsigned int cnt; AFS_STATCNT(afs_GetDownDSlot); @@ -970,27 +984,28 @@ afs_GetDownDSlot(anumber) osi_Panic("getdowndslot nolock"); /* decrement anumber first for all dudes in free list */ - for(tdc = afs_freeDSList; tdc; tdc = (struct dcache *)tdc->lruq.next) + for (tdc = afs_freeDSList; tdc; tdc = (struct dcache *)tdc->lruq.next) anumber--; - if (anumber <= 0) - return; /* enough already free */ + if (anumber <= 0) + return; /* enough already free */ - for(cnt=0, tq = afs_DLRU.prev; tq != &afs_DLRU && anumber > 0; - tq = nq, cnt++) { - tdc = (struct dcache *) tq; /* q is first elt in dcache entry */ - nq = QPrev(tq); /* in case we remove it */ + for (cnt = 0, tq = afs_DLRU.prev; tq != &afs_DLRU && anumber > 0; + tq = nq, cnt++) { + tdc = (struct dcache *)tq; /* q is first elt in dcache entry */ + nq = QPrev(tq); /* in case we remove it */ if (tdc->refCount == 0) { - if ((ix=tdc->index) == NULLIDX) osi_Panic("getdowndslot"); + if ((ix = tdc->index) == NULLIDX) + osi_Panic("getdowndslot"); /* pull the entry out of the lruq and put it on the free list */ QRemove(&tdc->lruq); /* write-through if modified */ - if (tdc->flags & DFEntryMod) { + if (tdc->dflags & DFEntryMod) { #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK) /* * ask proxy to do this for us - we don't have the stack space */ - while (tdc->flags & DFEntryMod) { + while (tdc->dflags & DFEntryMod) { int s; AFS_GUNLOCK(); s = SPLOCK(afs_sgibklock); @@ -1004,34 +1019,60 @@ afs_GetDownDSlot(anumber) AFS_GLOCK(); } #else - tdc->flags &= ~DFEntryMod; + tdc->dflags &= ~DFEntryMod; afs_WriteDCache(tdc, 1); #endif } tdc->stamp = 0; #ifdef IHINT - if (tdc->ihint) { - struct osi_file * f = (struct osi_file *)tdc->ihint; - tdc->ihint = 0; - afs_UFSClose(f); - nihints--; - } + if (tdc->ihint) { + struct osi_file *f = (struct osi_file *)tdc->ihint; + tdc->ihint = 0; + afs_UFSClose(f); + nihints--; + } #endif /* IHINT */ /* finally put the entry in the free list */ - afs_indexTable[ix] = (struct dcache *) 0; + afs_indexTable[ix] = NULL; afs_indexFlags[ix] &= ~IFEverUsed; tdc->index = NULLIDX; - tdc->lruq.next = (struct afs_q *) afs_freeDSList; + tdc->lruq.next = (struct afs_q *)afs_freeDSList; afs_freeDSList = tdc; anumber--; } } -} /*afs_GetDownDSlot*/ +} /*afs_GetDownDSlot */ +/* + * afs_RefDCache + * + * Description: + * Increment the reference count on a disk cache entry, + * which already has a non-zero refcount. In order to + * increment the refcount of a zero-reference entry, you + * have to hold afs_xdcache. + * + * Parameters: + * adc : Pointer to the dcache entry to increment. + * + * Environment: + * Nothing interesting. + */ +int +afs_RefDCache(struct dcache *adc) +{ + ObtainWriteLock(&adc->tlock, 627); + if (adc->refCount < 0) + osi_Panic("RefDCache: negative refcount"); + adc->refCount++; + ReleaseWriteLock(&adc->tlock); + return 0; +} + /* * afs_PutDCache @@ -1045,25 +1086,17 @@ afs_GetDownDSlot(anumber) * Environment: * Nothing interesting. */ -afs_PutDCache(ad) - register struct dcache *ad; - -{ /*afs_PutDCache*/ +int +afs_PutDCache(register struct dcache *adc) +{ AFS_STATCNT(afs_PutDCache); -#ifndef AFS_SUN5_ENVX - MObtainWriteLock(&afs_xdcache,276); -#endif - if (ad->refCount <= 0) + ObtainWriteLock(&adc->tlock, 276); + if (adc->refCount <= 0) osi_Panic("putdcache"); - --ad->refCount; -#ifdef AFS_SUN5_ENVX - MReleaseWriteLock(&ad->lock); -#else - MReleaseWriteLock(&afs_xdcache); -#endif + --adc->refCount; + ReleaseWriteLock(&adc->tlock); return 0; - -} /*afs_PutDCache*/ +} /* @@ -1080,23 +1113,19 @@ afs_PutDCache(ad) * Both pvnLock and lock are write held. */ void -afs_TryToSmush(avc, acred, sync) - register struct vcache *avc; - struct AFS_UCRED *acred; - int sync; -{ /*afs_TryToSmush*/ - +afs_TryToSmush(register struct vcache *avc, struct AFS_UCRED *acred, int sync) +{ register struct dcache *tdc; register int index; register int i; AFS_STATCNT(afs_TryToSmush); afs_Trace2(afs_iclSetp, CM_TRACE_TRYTOSMUSH, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length); - sync = 1; /* XX Temp testing XX*/ + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length)); + sync = 1; /* XX Temp testing XX */ #if defined(AFS_SUN5_ENV) ObtainWriteLock(&avc->vlock, 573); - avc->activeV++; /* block new getpages */ + avc->activeV++; /* block new getpages */ ReleaseWriteLock(&avc->vlock); #endif @@ -1106,23 +1135,28 @@ afs_TryToSmush(avc, acred, sync) /* * Get the hash chain containing all dce's for this fid */ - i = DVHash(&avc->fid); - MObtainWriteLock(&afs_xdcache,277); - for(index = afs_dvhashTbl[i]; index != NULLIDX; index=i) { - i = afs_dvnextTbl[index]; /* next pointer this hash table */ - if (afs_indexUnique[index] == avc->fid.Fid.Unique) { - tdc = afs_GetDSlot(index, (struct dcache *)0); - if (!FidCmp(&tdc->f.fid, &avc->fid)) { - if (sync) { - if ((afs_indexFlags[index] & IFDataMod) == 0 && - tdc->refCount == 1) { - afs_FlushDCache(tdc); - } - } else - afs_indexTable[index] = 0; + i = DVHash(&avc->fid); + MObtainWriteLock(&afs_xdcache, 277); + for (index = afs_dvhashTbl[i]; index != NULLIDX; index = i) { + i = afs_dvnextTbl[index]; /* next pointer this hash table */ + if (afs_indexUnique[index] == avc->fid.Fid.Unique) { + int releaseTlock = 1; + tdc = afs_GetDSlot(index, NULL); + if (!FidCmp(&tdc->f.fid, &avc->fid)) { + if (sync) { + if ((afs_indexFlags[index] & IFDataMod) == 0 + && tdc->refCount == 1) { + ReleaseReadLock(&tdc->tlock); + releaseTlock = 0; + afs_FlushDCache(tdc); + } + } else + afs_indexTable[index] = 0; + } + if (releaseTlock) + ReleaseReadLock(&tdc->tlock); + afs_PutDCache(tdc); } - lockedPutDCache(tdc); - } } #if defined(AFS_SUN5_ENV) ObtainWriteLock(&avc->vlock, 545); @@ -1138,7 +1172,7 @@ afs_TryToSmush(avc, acred, sync) * trytoSmush occured during the lookup call */ afs_allCBs++; -} /*afs_TryToSmush*/ +} /* * afs_FindDCache @@ -1160,12 +1194,9 @@ afs_TryToSmush(avc, acred, sync) * The vcache entry is held upon entry. */ -struct dcache *afs_FindDCache(avc, abyte) - register struct vcache *avc; - afs_int32 abyte; - -{ /*afs_FindDCache*/ - +struct dcache * +afs_FindDCache(register struct vcache *avc, afs_size_t abyte) +{ afs_int32 chunk; register afs_int32 i, index; register struct dcache *tdc; @@ -1178,27 +1209,27 @@ struct dcache *afs_FindDCache(avc, abyte) * after write-locking the dcache. */ i = DCHash(&avc->fid, chunk); - MObtainWriteLock(&afs_xdcache,278); - for(index = afs_dchashTbl[i]; index != NULLIDX;) { - if (afs_indexUnique[index] == avc->fid.Fid.Unique) { - tdc = afs_GetDSlot(index, (struct dcache *)0); - if (!FidCmp(&tdc->f.fid, &avc->fid) && chunk == tdc->f.chunk) { - break; /* leaving refCount high for caller */ + MObtainWriteLock(&afs_xdcache, 278); + for (index = afs_dchashTbl[i]; index != NULLIDX;) { + if (afs_indexUnique[index] == avc->fid.Fid.Unique) { + tdc = afs_GetDSlot(index, NULL); + ReleaseReadLock(&tdc->tlock); + if (!FidCmp(&tdc->f.fid, &avc->fid) && chunk == tdc->f.chunk) { + break; /* leaving refCount high for caller */ + } + afs_PutDCache(tdc); } - lockedPutDCache(tdc); - } - index = afs_dcnextTbl[index]; + index = afs_dcnextTbl[index]; } MReleaseWriteLock(&afs_xdcache); if (index != NULLIDX) { hset(afs_indexTimes[tdc->index], afs_indexCounter); hadd32(afs_indexCounter, 1); return tdc; - } - else - return(struct dcache *) 0; + } else + return NULL; -} /*afs_FindDCache*/ +} /*afs_FindDCache */ /* @@ -1223,17 +1254,12 @@ struct dcache *afs_FindDCache(avc, abyte) * Environment: * Nothing interesting. */ -static int afs_UFSCacheStoreProc(acall, afile, alen, avc, shouldWake, - abytesToXferP, abytesXferredP) - register struct rx_call *acall; - struct osi_file *afile; - register afs_int32 alen; - struct vcache *avc; - int *shouldWake; - afs_int32 *abytesToXferP; - afs_int32 *abytesXferredP; -{ /* afs_UFSCacheStoreProc*/ - +static int +afs_UFSCacheStoreProc(register struct rx_call *acall, struct osi_file *afile, + register afs_int32 alen, struct vcache *avc, + int *shouldWake, afs_size_t * abytesToXferP, + afs_size_t * abytesXferredP) +{ afs_int32 code, got; register char *tbuffer; register int tlen; @@ -1245,33 +1271,32 @@ static int afs_UFSCacheStoreProc(acall, afile, alen, avc, shouldWake, * In this case, alen is *always* the amount of data we'll be trying * to ship here. */ - (*abytesToXferP) = alen; + (*abytesToXferP) = alen; (*abytesXferredP) = 0; #endif /* AFS_NOSTATS */ - afs_Trace3(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length, ICL_TYPE_INT32, alen); + afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc, + ICL_TYPE_FID, &(avc->fid), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length), ICL_TYPE_INT32, alen); tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ); while (alen > 0) { tlen = (alen > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : alen); got = afs_osi_Read(afile, -1, tbuffer, tlen); - if ((got < 0) -#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_SGI64_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) + if ((got < 0) +#if defined(KERNEL_HAVE_UERROR) || (got != tlen && getuerror()) #endif ) { osi_FreeLargeSpace(tbuffer); return EIO; } -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = rx_Write(acall, tbuffer, got); /* writing 0 bytes will - * push a short packet. Is that really what we want, just because the - * data didn't come back from the disk yet? Let's try it and see. */ -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + afs_Trace2(afs_iclSetp, CM_TRACE_STOREPROC2, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(*tbuffer), ICL_TYPE_INT32, got); + RX_AFS_GUNLOCK(); + code = rx_Write(acall, tbuffer, got); /* writing 0 bytes will + * push a short packet. Is that really what we want, just because the + * data didn't come back from the disk yet? Let's try it and see. */ + RX_AFS_GLOCK(); #ifndef AFS_NOSTATS (*abytesXferredP) += code; #endif /* AFS_NOSTATS */ @@ -1285,14 +1310,17 @@ static int afs_UFSCacheStoreProc(acall, afile, alen, avc, shouldWake, * to continue. */ if (shouldWake && *shouldWake && (rx_GetRemoteStatus(acall) & 1)) { - *shouldWake = 0; /* only do this once */ + *shouldWake = 0; /* only do this once */ afs_wakeup(avc); } } + afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc, + ICL_TYPE_FID, &(avc->fid), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length), ICL_TYPE_INT32, alen); osi_FreeLargeSpace(tbuffer); return 0; -} /* afs_UFSCacheStoreProc*/ +} /* afs_UFSCacheStoreProc */ /* @@ -1306,7 +1334,7 @@ static int afs_UFSCacheStoreProc(acall, afile, alen, avc, shouldWake, * acall : Ptr to the Rx call structure. * afile : File descriptor for the cache file. * abase : Base offset to fetch. - * adc : Ptr to the dcache entry for the file. + * adc : Ptr to the dcache entry for the file, write-locked. * avc : Ptr to the vcache entry for the file. * abytesToXferP : Set to the number of bytes to xfer. * NOTE: This parameter is only used if AFS_NOSTATS @@ -1319,45 +1347,40 @@ static int afs_UFSCacheStoreProc(acall, afile, alen, avc, shouldWake, * Nothing interesting. */ -static int afs_UFSCacheFetchProc(acall, afile, abase, adc, avc, - abytesToXferP, abytesXferredP) - register struct rx_call *acall; - afs_int32 abase; - struct dcache *adc; - struct vcache *avc; - struct osi_file *afile; - afs_int32 *abytesToXferP; - afs_int32 *abytesXferredP; - -{ /*UFS_CacheFetchProc*/ - +static int +afs_UFSCacheFetchProc(register struct rx_call *acall, struct osi_file *afile, + afs_size_t abase, struct dcache *adc, + struct vcache *avc, afs_size_t * abytesToXferP, + afs_size_t * abytesXferredP, afs_int32 lengthFound) +{ afs_int32 length; register afs_int32 code; register char *tbuffer; register int tlen; - int moredata; + int moredata = 0; AFS_STATCNT(UFS_CacheFetchProc); - afile->offset = 0; /* Each time start from the beginning */ + osi_Assert(WriteLocked(&adc->lock)); + afile->offset = 0; /* Each time start from the beginning */ + length = lengthFound; #ifndef AFS_NOSTATS - (*abytesToXferP) = 0; + (*abytesToXferP) = 0; (*abytesXferredP) = 0; #endif /* AFS_NOSTATS */ tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ); + adc->validPos = abase; do { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = rx_Read(acall, (char *)&length, sizeof(afs_int32)); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - if (code != sizeof(afs_int32)) { - osi_FreeLargeSpace(tbuffer); - code = rx_Error(acall); - return (code?code:-1); /* try to return code, not -1 */ + if (moredata) { + RX_AFS_GUNLOCK(); + code = rx_Read(acall, (char *)&length, sizeof(afs_int32)); + RX_AFS_GLOCK(); + length = ntohl(length); + if (code != sizeof(afs_int32)) { + osi_FreeLargeSpace(tbuffer); + code = rx_Error(acall); + return (code ? code : -1); /* try to return code, not -1 */ + } } - length = ntohl(length); /* * The fetch protocol is extended for the AFS/DFS translator * to allow multiple blocks of data, each with its own length, @@ -1375,21 +1398,28 @@ static int afs_UFSCacheFetchProc(acall, afile, abase, adc, avc, } #ifndef AFS_NOSTATS (*abytesToXferP) += length; -#endif /* AFS_NOSTATS */ +#endif /* AFS_NOSTATS */ while (length > 0) { tlen = (length > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : length); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ +#ifdef RX_KERNEL_TRACE + afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING, + "before rx_Read"); +#endif + RX_AFS_GUNLOCK(); code = rx_Read(acall, tbuffer, tlen); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); +#ifdef RX_KERNEL_TRACE + afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING, + "after rx_Read"); +#endif #ifndef AFS_NOSTATS (*abytesXferredP) += code; -#endif /* AFS_NOSTATS */ +#endif /* AFS_NOSTATS */ if (code != tlen) { osi_FreeLargeSpace(tbuffer); + afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ, + ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code, + ICL_TYPE_INT32, length); return -34; } code = afs_osi_Write(afile, -1, tbuffer, tlen); @@ -1400,16 +1430,17 @@ static int afs_UFSCacheFetchProc(acall, afile, abase, adc, avc, abase += tlen; length -= tlen; adc->validPos = abase; - if (adc->flags & DFWaiting) { - adc->flags &= ~DFWaiting; - afs_osi_Wakeup(&adc->validPos); - } + if (afs_osi_Wakeup(&adc->validPos) == 0) + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, + ICL_TYPE_POINTER, adc, ICL_TYPE_INT32, + adc->dflags); } } while (moredata); osi_FreeLargeSpace(tbuffer); return 0; -} /* afs_UFSCacheFetchProc*/ +} /* afs_UFSCacheFetchProc */ /* * afs_GetDCache @@ -1428,6 +1459,8 @@ static int afs_UFSCacheFetchProc(acall, afile, abase, adc, avc, * aflags : Settings as follows: * 1 : Set locks * 2 : Return after creating entry. + * 4 : called from afs_vnop_write.c + * *alen contains length of data to be written. * OUT: * aoffset : Set to the offset within the chunk where the resident * byte is located. @@ -1445,10 +1478,14 @@ struct tlocal1 { struct AFSCallBack CallBack; }; -/* these fields are protected by the lock on the vcache and luck - * on the dcache */ -void updateV2DC(int l, struct vcache *v, struct dcache *d, int src) { - if (!l || 0 == NBObtainWriteLock(&(v->lock),src)) { +/* + * Update the vnode-to-dcache hint if we can get the vnode lock + * right away. Assumes dcache entry is at least read-locked. + */ +void +updateV2DC(int lockVc, struct vcache *v, struct dcache *d, int src) +{ + if (!lockVc || 0 == NBObtainWriteLock(&v->lock, src)) { if (hsame(v->m.DataVersion, d->f.versionNo) && v->callback) { v->quick.dc = d; v->quick.stamp = d->stamp = MakeStamp(); @@ -1457,43 +1494,57 @@ void updateV2DC(int l, struct vcache *v, struct dcache *d, int src) { v->quick.len = d->f.chunkBytes; v->h1.dchint = d; } - if(l) ReleaseWriteLock(&((v)->lock)); + if (lockVc) + ReleaseWriteLock(&v->lock); } } -struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) - register struct vcache *avc; /*Held*/ - afs_int32 abyte; - int aflags; - afs_int32 *aoffset, *alen; - register struct vrequest *areq; - -{ /*afs_GetDCache*/ - - register afs_int32 i, code, code1, shortcut , adjustsize=0; +/* avc - Write-locked unless aflags & 1 */ +struct dcache * +afs_GetDCache(register struct vcache *avc, afs_size_t abyte, + register struct vrequest *areq, afs_size_t * aoffset, + afs_size_t * alen, int aflags) +{ + register afs_int32 i, code, code1 = 0, shortcut; +#if defined(AFS_AIX32_ENV) || defined(AFS_SGI_ENV) + register afs_int32 adjustsize = 0; +#endif int setLocks; afs_int32 index; afs_int32 us; afs_int32 chunk; - afs_int32 maxGoodLength; /* amount of good data at server */ + afs_size_t maxGoodLength; /* amount of good data at server */ struct rx_call *tcall; - afs_int32 Position = 0; - afs_int32 size; /* size of segment to transfer */ - struct tlocal1 *tsmall; + afs_size_t Position = 0; +#ifdef AFS_64BIT_CLIENT + afs_size_t tsize; + afs_size_t lengthFound; /* as returned from server */ +#endif /* AFS_64BIT_CLIENT */ + afs_int32 size, tlen; /* size of segment to transfer */ + struct tlocal1 *tsmall = 0; register struct dcache *tdc; register struct osi_file *file; register struct conn *tc; int downDCount = 0; + struct server *newCallback; + char setNewCallback; + char setVcacheStatus; + char doVcacheUpdate; + char slowPass = 0; + int doAdjustSize = 0; + int doReallyAdjustSize = 0; + int overWriteWholeChunk = 0; + XSTATS_DECLS #ifndef AFS_NOSTATS struct afs_stats_xferData *xferP; /* Ptr to this op's xfer struct */ - osi_timeval_t xferStartTime, /*FS xfer start time*/ - xferStopTime; /*FS xfer stop time*/ - afs_int32 bytesToXfer; /* # bytes to xfer*/ - afs_int32 bytesXferred; /* # bytes actually xferred*/ - struct afs_stats_AccessInfo *accP; /*Ptr to access record in stats*/ - int fromReplica; /*Are we reading from a replica?*/ - int numFetchLoops; /*# times around the fetch/analyze loop*/ + osi_timeval_t xferStartTime, /*FS xfer start time */ + xferStopTime; /*FS xfer stop time */ + afs_size_t bytesToXfer; /* # bytes to xfer */ + afs_size_t bytesXferred; /* # bytes actually xferred */ + struct afs_stats_AccessInfo *accP; /*Ptr to access record in stats */ + int fromReplica; /*Are we reading from a replica? */ + int numFetchLoops; /*# times around the fetch/analyze loop */ #endif /* AFS_NOSTATS */ AFS_STATCNT(afs_GetDCache); @@ -1501,177 +1552,272 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) if (dcacheDisabled) return NULL; + setLocks = aflags & 1; + /* * Determine the chunk number and offset within the chunk corresponding * to the desired byte. */ - if (vType(avc) == VDIR) { + if (avc->fid.Fid.Vnode & 1) { /* if (vType(avc) == VDIR) */ chunk = 0; - } - else { + } else { chunk = AFS_CHUNK(abyte); } - setLocks = aflags & 1; - /* come back to here if we waited for the cache to drain. */ - RetryGetDCache: + RetryGetDCache: + + setNewCallback = setVcacheStatus = 0; + + if (setLocks) { + if (slowPass) + ObtainWriteLock(&avc->lock, 616); + else + ObtainReadLock(&avc->lock); + } + + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + */ + shortcut = 0; /* check hints first! (might could use bcmp or some such...) */ + if ((tdc = avc->h1.dchint)) { + int dcLocked; - if (tdc = avc->h1.dchint) { + /* + * The locking order between afs_xdcache and dcache lock matters. + * The hint dcache entry could be anywhere, even on the free list. + * Locking afs_xdcache ensures that noone is trying to pull dcache + * entries from the free list, and thereby assuming them to be not + * referenced and not locked. + */ MObtainReadLock(&afs_xdcache); - if ( (tdc->index != NULLIDX) && !FidCmp(&tdc->f.fid, &avc->fid) && - chunk == tdc->f.chunk && - !(afs_indexFlags[tdc->index] & (IFFree|IFDiscarded))) { + dcLocked = (0 == NBObtainSharedLock(&tdc->lock, 601)); + + if (dcLocked && (tdc->index != NULLIDX) + && !FidCmp(&tdc->f.fid, &avc->fid) && chunk == tdc->f.chunk + && !(afs_indexFlags[tdc->index] & (IFFree | IFDiscarded))) { /* got the right one. It might not be the right version, and it * might be fetching, but it's the right dcache entry. */ /* All this code should be integrated better with what follows: * I can save a good bit more time under a write lock if I do.. */ - /* does avc need to be locked? */ - /* Note that the race labeled LOCKXXX is inconsequential: the xdcache - * lock protects both the dcache slots AND the DLRU list. While - * the slots and hash table and DLRU list all may change in the race, - * THIS particular dcache structure cannot be recycled and its LRU - * pointers must still be valid once we get the lock again. Still - * we should either create another lock or invent a new method of - * managing dcache structs -- CLOCK or something. */ - shortcut = 1; -#ifdef AFS_SUN5_ENVX - MObtainWriteLock(&tdc->lock,279); -#endif + ObtainWriteLock(&tdc->tlock, 603); tdc->refCount++; - if (hsame(tdc->f.versionNo, avc->m.DataVersion) - && !(tdc->flags & DFFetching)) { - afs_stats_cmperf.dcacheHits++; - MReleaseReadLock(&afs_xdcache); + ReleaseWriteLock(&tdc->tlock); + + MReleaseReadLock(&afs_xdcache); + shortcut = 1; + + if (hsame(tdc->f.versionNo, avc->m.DataVersion) + && !(tdc->dflags & DFFetching)) { - MObtainWriteLock(&afs_xdcache, 559); /* LOCKXXX */ + afs_stats_cmperf.dcacheHits++; + MObtainWriteLock(&afs_xdcache, 559); QRemove(&tdc->lruq); QAdd(&afs_DLRU, &tdc->lruq); MReleaseWriteLock(&afs_xdcache); + + /* Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(S) + */ goto done; } -#ifdef AFS_SUN5_ENVX - MReleaseWriteLock(&tdc->lock); -#endif + } else { + if (dcLocked) + ReleaseSharedLock(&tdc->lock); + MReleaseReadLock(&afs_xdcache); } - MReleaseReadLock(&afs_xdcache); - } - if (!shortcut) - { - /* - * Hash on the [fid, chunk] and get the corresponding dcache index - * after write-locking the dcache. - */ - RetryLookup: - i = DCHash(&avc->fid, chunk); - afs_MaybeWakeupTruncateDaemon(); /* check to make sure our space is fine */ - MObtainWriteLock(&afs_xdcache,280); - us = NULLIDX; - for(index = afs_dchashTbl[i]; index != NULLIDX;) { - if (afs_indexUnique[index] == avc->fid.Fid.Unique) { - tdc = afs_GetDSlot(index, (struct dcache *)0); - if (!FidCmp(&tdc->f.fid, &avc->fid) && chunk == tdc->f.chunk) { - /* Move it up in the beginning of the list */ - if (afs_dchashTbl[i] != index) { - afs_dcnextTbl[us] = afs_dcnextTbl[index]; - afs_dcnextTbl[index] = afs_dchashTbl[i]; - afs_dchashTbl[i] = index; - } - MReleaseWriteLock(&afs_xdcache); - break; /* leaving refCount high for caller */ - } - lockedPutDCache(tdc); - } - us = index; - index = afs_dcnextTbl[index]; + if (!shortcut) + tdc = 0; } - /* - * If we didn't find the entry, we'll create one. + + /* Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(S) if tdc */ - if (index == NULLIDX) { - afs_Trace2(afs_iclSetp, CM_TRACE_GETDCACHE1, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, chunk); - - if (afs_discardDCList == NULLIDX && afs_freeDCList == NULLIDX) { - while (1) { - if (!setLocks) avc->states |= CDCLock; - afs_GetDownD(5, (int*)0); /* just need slots */ - if (!setLocks) avc->states &= (~CDCLock); - if (afs_discardDCList != NULLIDX || afs_freeDCList != NULLIDX) - break; - /* If we can't get space for 5 mins we give up and panic */ - if (++downDCount > 300) - osi_Panic("getdcache"); - MReleaseWriteLock(&afs_xdcache); - afs_osi_Wait(1000, 0, 0); - goto RetryLookup; - } - } - if (afs_discardDCList == NULLIDX || - ((aflags & 2) && afs_freeDCList != NULLIDX)) { - afs_indexFlags[afs_freeDCList] &= ~IFFree; - tdc = afs_GetDSlot(afs_freeDCList, 0); - afs_freeDCList = afs_dvnextTbl[tdc->index]; - afs_freeDCCount--; - } else { - afs_indexFlags[afs_discardDCList] &= ~IFDiscarded; - tdc = afs_GetDSlot(afs_discardDCList, 0); - afs_discardDCList = afs_dvnextTbl[tdc->index]; - afs_discardDCCount--; - size = ((tdc->f.chunkBytes + afs_fsfragsize)^afs_fsfragsize)>>10; - afs_blocksDiscarded -= size; - afs_stats_cmperf.cacheBlocksDiscarded = afs_blocksDiscarded; - if (aflags & 2) { - /* Truncate the chunk so zeroes get filled properly */ - file = afs_CFileOpen(tdc->f.inode); - afs_CFileTruncate(file, 0); - afs_CFileClose(file); - afs_AdjustSize(tdc, 0); - } - } + if (!tdc) { /* If the hint wasn't the right dcache entry */ /* - * Fill in the newly-allocated dcache record. + * Hash on the [fid, chunk] and get the corresponding dcache index + * after write-locking the dcache. */ - afs_indexFlags[tdc->index] &= ~(IFDirtyPages | IFAnyPages); - tdc->f.fid = avc->fid; - afs_indexUnique[tdc->index] = tdc->f.fid.Fid.Unique; - hones(tdc->f.versionNo); /* invalid value */ - tdc->f.chunk = chunk; - /* XXX */ - if (tdc->lruq.prev == &tdc->lruq) osi_Panic("lruq 1"); - /* - * Now add to the two hash chains - note that i is still set - * from the above DCHash call. + RetryLookup: + + /* Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass */ - afs_dcnextTbl[tdc->index] = afs_dchashTbl[i]; - afs_dchashTbl[i] = tdc->index; - i = DVHash(&avc->fid); - afs_dvnextTbl[tdc->index] = afs_dvhashTbl[i]; - afs_dvhashTbl[i] = tdc->index; - tdc->flags = DFEntryMod; - tdc->f.states = 0; + + i = DCHash(&avc->fid, chunk); + /* check to make sure our space is fine */ afs_MaybeWakeupTruncateDaemon(); - MReleaseWriteLock(&afs_xdcache); + + MObtainWriteLock(&afs_xdcache, 280); + us = NULLIDX; + for (index = afs_dchashTbl[i]; index != NULLIDX;) { + if (afs_indexUnique[index] == avc->fid.Fid.Unique) { + tdc = afs_GetDSlot(index, NULL); + ReleaseReadLock(&tdc->tlock); + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * afs_xdcache(W) + */ + if (!FidCmp(&tdc->f.fid, &avc->fid) && chunk == tdc->f.chunk) { + /* Move it up in the beginning of the list */ + if (afs_dchashTbl[i] != index) { + afs_dcnextTbl[us] = afs_dcnextTbl[index]; + afs_dcnextTbl[index] = afs_dchashTbl[i]; + afs_dchashTbl[i] = index; + } + MReleaseWriteLock(&afs_xdcache); + ObtainSharedLock(&tdc->lock, 606); + break; /* leaving refCount high for caller */ + } + afs_PutDCache(tdc); + tdc = 0; + } + us = index; + index = afs_dcnextTbl[index]; + } + + /* + * If we didn't find the entry, we'll create one. + */ + if (index == NULLIDX) { + /* + * Locks held: + * avc->lock(R) if setLocks + * avc->lock(W) if !setLocks + * afs_xdcache(W) + */ + afs_Trace2(afs_iclSetp, CM_TRACE_GETDCACHE1, ICL_TYPE_POINTER, + avc, ICL_TYPE_INT32, chunk); + + /* Make sure there is a free dcache entry for us to use */ + if (afs_discardDCList == NULLIDX && afs_freeDCList == NULLIDX) { + while (1) { + if (!setLocks) + avc->states |= CDCLock; + afs_GetDownD(5, (int *)0); /* just need slots */ + if (!setLocks) + avc->states &= ~CDCLock; + if (afs_discardDCList != NULLIDX + || afs_freeDCList != NULLIDX) + break; + /* If we can't get space for 5 mins we give up and panic */ + if (++downDCount > 300) + osi_Panic("getdcache"); + MReleaseWriteLock(&afs_xdcache); + /* + * Locks held: + * avc->lock(R) if setLocks + * avc->lock(W) if !setLocks + */ + afs_osi_Wait(1000, 0, 0); + goto RetryLookup; + } + } + + if (afs_discardDCList == NULLIDX + || ((aflags & 2) && afs_freeDCList != NULLIDX)) { + + afs_indexFlags[afs_freeDCList] &= ~IFFree; + tdc = afs_GetDSlot(afs_freeDCList, 0); + osi_Assert(tdc->refCount == 1); + ReleaseReadLock(&tdc->tlock); + ObtainWriteLock(&tdc->lock, 604); + afs_freeDCList = afs_dvnextTbl[tdc->index]; + afs_freeDCCount--; + } else { + afs_indexFlags[afs_discardDCList] &= ~IFDiscarded; + tdc = afs_GetDSlot(afs_discardDCList, 0); + osi_Assert(tdc->refCount == 1); + ReleaseReadLock(&tdc->tlock); + ObtainWriteLock(&tdc->lock, 605); + afs_discardDCList = afs_dvnextTbl[tdc->index]; + afs_discardDCCount--; + size = + ((tdc->f.chunkBytes + + afs_fsfragsize) ^ afs_fsfragsize) >> 10; + afs_blocksDiscarded -= size; + afs_stats_cmperf.cacheBlocksDiscarded = afs_blocksDiscarded; + if (aflags & 2) { + /* Truncate the chunk so zeroes get filled properly */ + file = afs_CFileOpen(tdc->f.inode); + afs_CFileTruncate(file, 0); + afs_CFileClose(file); + afs_AdjustSize(tdc, 0); + } + } + + /* + * Locks held: + * avc->lock(R) if setLocks + * avc->lock(W) if !setLocks + * tdc->lock(W) + * afs_xdcache(W) + */ + + /* + * Fill in the newly-allocated dcache record. + */ + afs_indexFlags[tdc->index] &= ~(IFDirtyPages | IFAnyPages); + tdc->f.fid = avc->fid; + afs_indexUnique[tdc->index] = tdc->f.fid.Fid.Unique; + hones(tdc->f.versionNo); /* invalid value */ + tdc->f.chunk = chunk; + tdc->validPos = AFS_CHUNKTOBASE(chunk); + /* XXX */ + if (tdc->lruq.prev == &tdc->lruq) + osi_Panic("lruq 1"); + + /* + * Now add to the two hash chains - note that i is still set + * from the above DCHash call. + */ + afs_dcnextTbl[tdc->index] = afs_dchashTbl[i]; + afs_dchashTbl[i] = tdc->index; + i = DVHash(&avc->fid); + afs_dvnextTbl[tdc->index] = afs_dvhashTbl[i]; + afs_dvhashTbl[i] = tdc->index; + tdc->dflags = DFEntryMod; + tdc->mflags = 0; + tdc->f.states = 0; + afs_MaybeWakeupTruncateDaemon(); + MReleaseWriteLock(&afs_xdcache); + ConvertWToSLock(&tdc->lock); + } } - } /* else hint failed... */ + + /* vcache->dcache hint failed */ + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(S) + */ afs_Trace4(afs_iclSetp, CM_TRACE_GETDCACHE2, ICL_TYPE_POINTER, avc, - ICL_TYPE_POINTER, tdc, - ICL_TYPE_INT32, hgetlo(tdc->f.versionNo), - ICL_TYPE_INT32, hgetlo(avc->m.DataVersion)); + ICL_TYPE_POINTER, tdc, ICL_TYPE_INT32, + hgetlo(tdc->f.versionNo), ICL_TYPE_INT32, + hgetlo(avc->m.DataVersion)); /* - * Here we have the unlocked entry in tdc, with its refCount - * incremented. Note: we don't use the S-lock; it costs concurrency - * when storing a file back to the server. + * Here we have the entry in tdc, with its refCount incremented. + * Note: we don't use the S-lock on avc; it costs concurrency when + * storing a file back to the server. */ - if (setLocks) ObtainReadLock(&avc->lock); /* * Not a newly created file so we need to check the file's length and @@ -1680,79 +1826,111 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) * read rpcs on newly created files (dv of 0) since only then we guarantee * that this chunk's data hasn't been filled by another client. */ - if (!hiszero(avc->m.DataVersion)) - aflags &= ~4; + size = AFS_CHUNKSIZE(abyte); + if (aflags & 4) /* called from write */ + tlen = *alen; + else /* called from read */ + tlen = tdc->validPos - abyte; + Position = AFS_CHUNKTOBASE(chunk); + afs_Trace4(afs_iclSetp, CM_TRACE_GETDCACHE3, ICL_TYPE_INT32, tlen, + ICL_TYPE_INT32, aflags, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(abyte), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(Position)); + if ((aflags & 4) && (hiszero(avc->m.DataVersion))) + doAdjustSize = 1; + if ((aflags & 4) && (abyte == Position) && (tlen >= size)) + overWriteWholeChunk = 1; + if (doAdjustSize || overWriteWholeChunk) { #if defined(AFS_AIX32_ENV) || defined(AFS_SGI_ENV) #ifdef AFS_SGI_ENV #ifdef AFS_SGI64_ENV - if (aflags & 4) adjustsize = NBPP; -#else - if (aflags & 4) adjustsize = 8192; -#endif -#else - if (aflags & 4) adjustsize = 4096; -#endif - if (AFS_CHUNKTOBASE(chunk)+adjustsize >= avc->m.Length && -#else -#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) - if (((aflags & 4) || (AFS_CHUNKTOBASE(chunk) >= avc->m.Length)) && -#else - if (AFS_CHUNKTOBASE(chunk) >= avc->m.Length && -#endif -#endif - !hsame(avc->m.DataVersion, tdc->f.versionNo)) { - /* no data in file to read at this position */ - if (setLocks) { - ReleaseReadLock(&avc->lock); - ObtainWriteLock(&avc->lock,64); - } - /* check again, now that we have a write lock */ -#if defined(AFS_AIX32_ENV) || defined(AFS_SGI_ENV) - if (AFS_CHUNKTOBASE(chunk)+adjustsize >= avc->m.Length && -#else + if (doAdjustSize) + adjustsize = NBPP; +#else /* AFS_SGI64_ENV */ + if (doAdjustSize) + adjustsize = 8192; +#endif /* AFS_SGI64_ENV */ +#else /* AFS_SGI_ENV */ + if (doAdjustSize) + adjustsize = 4096; +#endif /* AFS_SGI_ENV */ + if (AFS_CHUNKTOBASE(chunk) + adjustsize >= avc->m.Length && +#else /* defined(AFS_AIX32_ENV) || defined(AFS_SGI_ENV) */ #if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) - if (((aflags & 4) || (AFS_CHUNKTOBASE(chunk) >= avc->m.Length)) && + if ((doAdjustSize || (AFS_CHUNKTOBASE(chunk) >= avc->m.Length)) && #else if (AFS_CHUNKTOBASE(chunk) >= avc->m.Length && #endif -#endif - !hsame(avc->m.DataVersion, tdc->f.versionNo)) { +#endif /* defined(AFS_AIX32_ENV) || defined(AFS_SGI_ENV) */ + !hsame(avc->m.DataVersion, tdc->f.versionNo)) + doReallyAdjustSize = 1; + + if (doReallyAdjustSize || overWriteWholeChunk) { + /* no data in file to read at this position */ + UpgradeSToWLock(&tdc->lock, 607); + file = afs_CFileOpen(tdc->f.inode); afs_CFileTruncate(file, 0); afs_CFileClose(file); afs_AdjustSize(tdc, 0); hset(tdc->f.versionNo, avc->m.DataVersion); - tdc->flags |= DFEntryMod; - } - if (setLocks) { - ReleaseWriteLock(&avc->lock); - ObtainReadLock(&avc->lock); + tdc->dflags |= DFEntryMod; + + ConvertWToSLock(&tdc->lock); } } - if (setLocks) ReleaseReadLock(&avc->lock); /* - * We must read in the whole chunk iff the version number doesn't + * We must read in the whole chunk if the version number doesn't * match. */ if (aflags & 2) { /* don't need data, just a unique dcache entry */ + ObtainWriteLock(&afs_xdcache, 608); hset(afs_indexTimes[tdc->index], afs_indexCounter); hadd32(afs_indexCounter, 1); - updateV2DC(setLocks,avc,tdc,567); - return tdc; /* check if we're done */ + ReleaseWriteLock(&afs_xdcache); + + updateV2DC(setLocks, avc, tdc, 553); + if (vType(avc) == VDIR) + *aoffset = abyte; + else + *aoffset = AFS_CHUNKOFFSET(abyte); + if (tdc->validPos < abyte) + *alen = (afs_size_t) 0; + else + *alen = tdc->validPos - abyte; + ReleaseSharedLock(&tdc->lock); + if (setLocks) { + if (slowPass) + ReleaseWriteLock(&avc->lock); + else + ReleaseReadLock(&avc->lock); + } + return tdc; /* check if we're done */ } - osi_Assert(setLocks || WriteLocked(&avc->lock)); - if (setLocks) ObtainReadLock(&avc->lock); - if (!hsame(avc->m.DataVersion, tdc->f.versionNo)) { + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(S) + */ + osi_Assert((setLocks && !slowPass) || WriteLocked(&avc->lock)); + + setNewCallback = setVcacheStatus = 0; + + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(S) + */ + if (!hsame(avc->m.DataVersion, tdc->f.versionNo) && !overWriteWholeChunk) { /* * Version number mismatch. */ - if (setLocks) { - ReleaseReadLock(&avc->lock); - ObtainWriteLock(&avc->lock,65); - } + UpgradeSToWLock(&tdc->lock, 609); /* * If data ever existed for this vnode, and this is a text object, @@ -1772,45 +1950,67 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) /* * By here, the cache entry is always write-locked. We can * deadlock if we call osi_Flush with the cache entry locked... + * Unlock the dcache too. */ - ReleaseWriteLock(&avc->lock); + ReleaseWriteLock(&tdc->lock); + if (setLocks && !slowPass) + ReleaseReadLock(&avc->lock); + else + ReleaseWriteLock(&avc->lock); + osi_FlushText(avc); /* * Call osi_FlushPages in open, read/write, and map, since it * is too hard here to figure out if we should lock the * pvnLock. */ - ObtainWriteLock(&avc->lock,66); + if (setLocks && !slowPass) + ObtainReadLock(&avc->lock); + else + ObtainWriteLock(&avc->lock, 66); + ObtainWriteLock(&tdc->lock, 610); } - /* Watch for standard race condition */ + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(W) + */ + + /* Watch for standard race condition around osi_FlushText */ if (hsame(avc->m.DataVersion, tdc->f.versionNo)) { - updateV2DC(0,avc,tdc,569); /* set hint */ - if (setLocks) ReleaseWriteLock(&avc->lock); + updateV2DC(setLocks, avc, tdc, 569); /* set hint */ afs_stats_cmperf.dcacheHits++; + ConvertWToSLock(&tdc->lock); goto done; } /* Sleep here when cache needs to be drained. */ - if (setLocks && - (afs_blocksUsed > (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100)) { + if (setLocks && !slowPass + && (afs_blocksUsed > + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100)) { /* Make sure truncate daemon is running */ afs_MaybeWakeupTruncateDaemon(); - tdc->refCount--; /* we'll re-obtain the dcache when we re-try. */ - ReleaseWriteLock(&avc->lock); - while ((afs_blocksUsed-afs_blocksDiscarded) > - (CM_WAITFORDRAINPCT*afs_cacheBlocks)/100) { + ObtainWriteLock(&tdc->tlock, 614); + tdc->refCount--; /* we'll re-obtain the dcache when we re-try. */ + ReleaseWriteLock(&tdc->tlock); + ReleaseWriteLock(&tdc->lock); + ReleaseReadLock(&avc->lock); + while ((afs_blocksUsed - afs_blocksDiscarded) > + (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { afs_WaitForCacheDrain = 1; afs_osi_Sleep(&afs_WaitForCacheDrain); } afs_MaybeFreeDiscardedDCache(); /* need to check if someone else got the chunk first. */ goto RetryGetDCache; - } + } /* Do not fetch data beyond truncPos. */ maxGoodLength = avc->m.Length; - if (avc->truncPos < maxGoodLength) maxGoodLength = avc->truncPos; + if (avc->truncPos < maxGoodLength) + maxGoodLength = avc->truncPos; Position = AFS_CHUNKBASE(abyte); if (vType(avc) == VDIR) { size = avc->m.Length; @@ -1818,51 +2018,56 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) /* pre-reserve space for file */ afs_AdjustSize(tdc, size); } - size = 999999999; /* max size for transfer */ - } - else { + size = 999999999; /* max size for transfer */ + } else { size = AFS_CHUNKSIZE(abyte); /* expected max size */ /* don't read past end of good data on server */ if (Position + size > maxGoodLength) size = maxGoodLength - Position; - if (size < 0) size = 0; /* Handle random races */ + if (size < 0) + size = 0; /* Handle random races */ if (size > tdc->f.chunkBytes) { /* pre-reserve space for file */ afs_AdjustSize(tdc, size); /* changes chunkBytes */ /* max size for transfer still in size */ } } - if (afs_mariner && !tdc->f.chunk) - afs_MarinerLog("fetch$Fetching", avc); /* , Position, size, afs_indexCounter );*/ + if (afs_mariner && !tdc->f.chunk) + afs_MarinerLog("fetch$Fetching", avc); /* , Position, size, afs_indexCounter ); */ /* * Right now, we only have one tool, and it's a hammer. So, we * fetch the whole file. */ DZap(&tdc->f.inode); /* pages in cache may be old */ #ifdef IHINT - if (file = tdc->ihint) { - if (tdc->f.inode == file->inum ) - usedihint++; - else { - tdc->ihint = 0; - afs_UFSClose(file); - file = 0; - nihints--; - file = osi_UFSOpen(tdc->f.inode); - } - } - else + if (file = tdc->ihint) { + if (tdc->f.inode == file->inum) + usedihint++; + else { + tdc->ihint = 0; + afs_UFSClose(file); + file = 0; + nihints--; + file = osi_UFSOpen(tdc->f.inode); + } + } else #endif /* IHINT */ - file = afs_CFileOpen(tdc->f.inode); + file = afs_CFileOpen(tdc->f.inode); afs_RemoveVCB(&avc->fid); tdc->f.states |= DWriting; - tdc->flags |= DFFetching; - tdc->validPos = Position; /*Last valid position in this chunk*/ - if (tdc->flags & DFFetchReq) { - tdc->flags &= ~DFFetchReq; - afs_osi_Wakeup(&tdc->validPos); + tdc->dflags |= DFFetching; + tdc->validPos = Position; /* which is AFS_CHUNKBASE(abyte) */ + if (tdc->mflags & DFFetchReq) { + tdc->mflags &= ~DFFetchReq; + if (afs_osi_Wakeup(&tdc->validPos) == 0) + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, + ICL_TYPE_POINTER, tdc, ICL_TYPE_INT32, + tdc->dflags); } - tsmall = (struct tlocal1 *) osi_AllocLargeSpace(sizeof(struct tlocal1)); + tsmall = + (struct tlocal1 *)osi_AllocLargeSpace(sizeof(struct tlocal1)); + setVcacheStatus = 0; #ifndef AFS_NOSTATS /* * Remember if we are doing the reading from a replicated volume, @@ -1877,10 +2082,13 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) (accP->unreplicatedRefs)++; #endif /* AFS_NOSTATS */ /* this is a cache miss */ - afs_stats_cmperf.dcacheMisses++; - afs_Trace3(afs_iclSetp, CM_TRACE_FETCHPROC, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, Position, ICL_TYPE_INT32, size); + afs_Trace4(afs_iclSetp, CM_TRACE_FETCHPROC, ICL_TYPE_POINTER, avc, + ICL_TYPE_FID, &(avc->fid), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(Position), ICL_TYPE_INT32, size); + if (size) + afs_stats_cmperf.dcacheMisses++; + code = 0; /* * Dynamic root support: fetch data from local memory. */ @@ -1894,7 +2102,8 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) dynrootLen -= Position; if (size > dynrootLen) size = dynrootLen; - if (size < 0) size = 0; + if (size < 0) + size = 0; code = afs_CFileWrite(file, 0, dynrootDir, size); afs_PutDynroot(); @@ -1904,155 +2113,276 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) code = -1; tdc->validPos = Position + size; - afs_CFileTruncate(file, size); /* prune it */ + afs_CFileTruncate(file, size); /* prune it */ } else - /* - * Not a dynamic vnode: do the real fetch. - */ - do { - tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); - if (tc) { + /* + * Not a dynamic vnode: do the real fetch. + */ + do { + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(W) + */ + + tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); + if (tc) { + afs_int32 length_hi, length, bytes; #ifndef AFS_NOSTATS - numFetchLoops++; - if (fromReplica) - (accP->numReplicasAccessed)++; - + numFetchLoops++; + if (fromReplica) + (accP->numReplicasAccessed)++; + #endif /* AFS_NOSTATS */ - avc->callback = tc->srvr->server; - ConvertWToSLock(&avc->lock); - i = osi_Time(); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - tcall = rx_NewCall(tc->id); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - - - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = StartRXAFS_FetchData(tcall, - (struct AFSFid *) &avc->fid.Fid, - Position, size); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - if (code == 0) { + if (!setLocks || slowPass) { + avc->callback = tc->srvr->server; + } else { + newCallback = tc->srvr->server; + setNewCallback = 1; + } + i = osi_Time(); + RX_AFS_GUNLOCK(); + tcall = rx_NewCall(tc->id); + RX_AFS_GLOCK(); + + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA); +#ifdef AFS_64BIT_CLIENT + length_hi = code = 0; + if (!afs_serverHasNo64Bit(tc)) { + tsize = size; + RX_AFS_GUNLOCK(); + code = + StartRXAFS_FetchData64(tcall, + (struct AFSFid *)&avc->fid. + Fid, Position, tsize); + if (code != 0) { + RX_AFS_GLOCK(); + afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE, + ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, + code); + } else { + bytes = + rx_Read(tcall, (char *)&length_hi, + sizeof(afs_int32)); + RX_AFS_GLOCK(); + if (bytes == sizeof(afs_int32)) { + length_hi = ntohl(length_hi); + } else { + length_hi = 0; + code = rx_Error(tcall); + RX_AFS_GUNLOCK(); + code1 = rx_EndCall(tcall, code); + RX_AFS_GLOCK(); + tcall = (struct rx_call *)0; + } + } + } + if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) { + if (Position > 0x7FFFFFFF) { + code = EFBIG; + } else { + afs_int32 pos; + pos = Position; + RX_AFS_GUNLOCK(); + if (!tcall) + tcall = rx_NewCall(tc->id); + code = + StartRXAFS_FetchData(tcall, (struct AFSFid *) + &avc->fid.Fid, pos, + size); + RX_AFS_GLOCK(); + } + afs_serverSetNo64Bit(tc); + } + if (code == 0) { + RX_AFS_GUNLOCK(); + bytes = + rx_Read(tcall, (char *)&length, + sizeof(afs_int32)); + RX_AFS_GLOCK(); + if (bytes == sizeof(afs_int32)) { + length = ntohl(length); + } else { + code = rx_Error(tcall); + } + } + FillInt64(lengthFound, length_hi, length); + afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG, + ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code, + ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(lengthFound)); +#else /* AFS_64BIT_CLIENT */ + RX_AFS_GUNLOCK(); + code = + StartRXAFS_FetchData(tcall, + (struct AFSFid *)&avc->fid.Fid, + Position, size); + RX_AFS_GLOCK(); + if (code == 0) { + RX_AFS_GUNLOCK(); + bytes = + rx_Read(tcall, (char *)&length, + sizeof(afs_int32)); + RX_AFS_GLOCK(); + if (bytes == sizeof(afs_int32)) { + length = ntohl(length); + } else { + code = rx_Error(tcall); + } + } +#endif /* AFS_64BIT_CLIENT */ + if (code == 0) { #ifndef AFS_NOSTATS - xferP = &(afs_stats_cmfullperf.rpc.fsXferTimes[AFS_STATS_FS_XFERIDX_FETCHDATA]); - osi_GetuTime(&xferStartTime); - - code = afs_CacheFetchProc(tcall, file, Position, tdc, avc, - &bytesToXfer, &bytesXferred); - - osi_GetuTime(&xferStopTime); - (xferP->numXfers)++; - if (!code) { - (xferP->numSuccesses)++; - afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] += bytesXferred; - (xferP->sumBytes) += (afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] >> 10); - afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] &= 0x3FF; - if (bytesXferred < xferP->minBytes) - xferP->minBytes = bytesXferred; - if (bytesXferred > xferP->maxBytes) - xferP->maxBytes = bytesXferred; - - /* - * Tally the size of the object. Note: we tally the actual size, - * NOT the number of bytes that made it out over the wire. - */ - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) - (xferP->count[0])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1) - (xferP->count[1])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2) - (xferP->count[2])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3) - (xferP->count[3])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4) - (xferP->count[4])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5) - (xferP->count[5])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6) - (xferP->count[6])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7) - (xferP->count[7])++; - else - (xferP->count[8])++; - - afs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime); - afs_stats_AddTo((xferP->sumTime), elapsedTime); - afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime); - if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) { - afs_stats_TimeAssign((xferP->minTime), elapsedTime); - } - if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) { - afs_stats_TimeAssign((xferP->maxTime), elapsedTime); - } - } + xferP = + &(afs_stats_cmfullperf.rpc. + fsXferTimes[AFS_STATS_FS_XFERIDX_FETCHDATA]); + osi_GetuTime(&xferStartTime); + + code = + afs_CacheFetchProc(tcall, file, + (afs_size_t) Position, tdc, + avc, &bytesToXfer, + &bytesXferred, length); + + osi_GetuTime(&xferStopTime); + (xferP->numXfers)++; + if (!code) { + (xferP->numSuccesses)++; + afs_stats_XferSumBytes + [AFS_STATS_FS_XFERIDX_FETCHDATA] += + bytesXferred; + (xferP->sumBytes) += + (afs_stats_XferSumBytes + [AFS_STATS_FS_XFERIDX_FETCHDATA] >> 10); + afs_stats_XferSumBytes + [AFS_STATS_FS_XFERIDX_FETCHDATA] &= 0x3FF; + if (bytesXferred < xferP->minBytes) + xferP->minBytes = bytesXferred; + if (bytesXferred > xferP->maxBytes) + xferP->maxBytes = bytesXferred; + + /* + * Tally the size of the object. Note: we tally the actual size, + * NOT the number of bytes that made it out over the wire. + */ + if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) + (xferP->count[0])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET1) + (xferP->count[1])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET2) + (xferP->count[2])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET3) + (xferP->count[3])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET4) + (xferP->count[4])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET5) + (xferP->count[5])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET6) + (xferP->count[6])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET7) + (xferP->count[7])++; + else + (xferP->count[8])++; + + afs_stats_GetDiff(elapsedTime, xferStartTime, + xferStopTime); + afs_stats_AddTo((xferP->sumTime), elapsedTime); + afs_stats_SquareAddTo((xferP->sqrTime), + elapsedTime); + if (afs_stats_TimeLessThan + (elapsedTime, (xferP->minTime))) { + afs_stats_TimeAssign((xferP->minTime), + elapsedTime); + } + if (afs_stats_TimeGreaterThan + (elapsedTime, (xferP->maxTime))) { + afs_stats_TimeAssign((xferP->maxTime), + elapsedTime); + } + } #else - code = afs_CacheFetchProc(tcall, file, Position, tdc, avc, 0, 0); + code = + afs_CacheFetchProc(tcall, file, Position, tdc, + avc, 0, 0, length); #endif /* AFS_NOSTATS */ + } + if (code == 0) { + RX_AFS_GUNLOCK(); + code = + EndRXAFS_FetchData(tcall, &tsmall->OutStatus, + &tsmall->CallBack, + &tsmall->tsync); + RX_AFS_GLOCK(); + } + XSTATS_END_TIME; + RX_AFS_GUNLOCK(); + if (tcall) + code1 = rx_EndCall(tcall, code); + RX_AFS_GLOCK(); + } else { + code = -1; } + if (!code && code1) + code = code1; + if (code == 0) { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = EndRXAFS_FetchData(tcall, - &tsmall->OutStatus, - &tsmall->CallBack, - &tsmall->tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + /* callback could have been broken (or expired) in a race here, + * but we return the data anyway. It's as good as we knew about + * when we started. */ + /* + * validPos is updated by CacheFetchProc, and can only be + * modifed under a dcache write lock, which we've blocked out + */ + size = tdc->validPos - Position; /* actual segment size */ + if (size < 0) + size = 0; + afs_CFileTruncate(file, size); /* prune it */ + } else { + if (!setLocks || slowPass) { + ObtainWriteLock(&afs_xcbhash, 453); + afs_DequeueCallback(avc); + avc->states &= ~(CStatd | CUnique); + avc->callback = NULL; + ReleaseWriteLock(&afs_xcbhash); + if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR)) + osi_dnlc_purgedp(avc); + } else { + /* Something lost. Forget about performance, and go + * back with a vcache write lock. + */ + afs_CFileTruncate(file, 0); + afs_AdjustSize(tdc, 0); + afs_CFileClose(file); + osi_FreeLargeSpace(tsmall); + tsmall = 0; + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); + tdc = 0; + ReleaseReadLock(&avc->lock); + slowPass = 1; + goto RetryGetDCache; + } } - XSTATS_END_TIME; - code1 = rx_EndCall(tcall, code); - UpgradeSToWLock(&avc->lock,27); - } - else { - code = -1; - } - if ( !code && code1 ) - code = code1; - - if (code == 0) { - /* callback could have been broken (or expired) in a race here, - * but we return the data anyway. It's as good as we knew about - * when we started. */ - /* - * validPos is updated by CacheFetchProc, and can only be - * modifed under an S or W lock, which we've blocked out - */ - size = tdc->validPos - Position; /* actual segment size */ - if (size < 0) size = 0; - afs_CFileTruncate(file, size); /* prune it */ - } - else { - ObtainWriteLock(&afs_xcbhash, 453); - afs_DequeueCallback(avc); - avc->states &= ~(CStatd | CUnique); - avc->callback = (struct server *)0; - ReleaseWriteLock(&afs_xcbhash); - if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR)) - osi_dnlc_purgedp(avc); - } - - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_FETCHDATA, - SHARED_LOCK, (struct cell *)0)); + + } while (afs_Analyze + (tc, code, &avc->fid, areq, + AFS_STATS_FS_RPCIDX_FETCHDATA, SHARED_LOCK, NULL)); + + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(W) + */ #ifndef AFS_NOSTATS /* @@ -2067,14 +2397,18 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) } #endif /* AFS_NOSTATS */ - tdc->flags &= ~DFFetching; - if (tdc->flags & DFWaiting) { - tdc->flags &= ~DFWaiting; - afs_osi_Wakeup(&tdc->validPos); - } - if (avc->execsOrWriters == 0) tdc->f.states &= ~DWriting; - - /* now, if code != 0, we have an error and should punt */ + tdc->dflags &= ~DFFetching; + if (afs_osi_Wakeup(&tdc->validPos) == 0) + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, ICL_TYPE_POINTER, + tdc, ICL_TYPE_INT32, tdc->dflags); + if (avc->execsOrWriters == 0) + tdc->f.states &= ~DWriting; + + /* now, if code != 0, we have an error and should punt. + * note that we have the vcache write lock, either because + * !setLocks or slowPass. + */ if (code) { afs_CFileTruncate(file, 0); afs_AdjustSize(tdc, 0); @@ -2083,48 +2417,57 @@ struct dcache *afs_GetDCache(avc, abyte, areq, aoffset, alen, aflags) if (vType(avc) == VDIR) { DZap(&tdc->f.inode); } -#ifdef AFS_SUN5_ENVX + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); -#else - tdc->refCount--; -#endif ObtainWriteLock(&afs_xcbhash, 454); afs_DequeueCallback(avc); - avc->states &= ~( CStatd | CUnique ); + avc->states &= ~(CStatd | CUnique); ReleaseWriteLock(&afs_xcbhash); if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR)) osi_dnlc_purgedp(avc); - if (setLocks) ReleaseWriteLock(&avc->lock); - osi_FreeLargeSpace(tsmall); - tdc = (struct dcache *) 0; - goto done; + /* + * Locks held: + * avc->lock(W); assert(!setLocks || slowPass) + */ + osi_Assert(!setLocks || slowPass); + tdc = NULL; + goto done; } /* otherwise we copy in the just-fetched info */ afs_CFileClose(file); - afs_AdjustSize(tdc, size); /* new size */ + afs_AdjustSize(tdc, size); /* new size */ /* - * Copy appropriate fields into vcache + * Copy appropriate fields into vcache. Status is + * copied later where we selectively acquire the + * vcache write lock. */ - afs_ProcessFS(avc, &tsmall->OutStatus, areq); - hset64(tdc->f.versionNo, tsmall->OutStatus.dataVersionHigh, tsmall->OutStatus.DataVersion); - tdc->flags |= DFEntryMod; + if (slowPass) + afs_ProcessFS(avc, &tsmall->OutStatus, areq); + else + setVcacheStatus = 1; + hset64(tdc->f.versionNo, tsmall->OutStatus.dataVersionHigh, + tsmall->OutStatus.DataVersion); + tdc->dflags |= DFEntryMod; afs_indexFlags[tdc->index] |= IFEverUsed; - if (setLocks) ReleaseWriteLock(&avc->lock); - osi_FreeLargeSpace(tsmall); - } /*Data version numbers don't match*/ + ConvertWToSLock(&tdc->lock); + } /*Data version numbers don't match */ else { /* - * Data version numbers match. Release locks if we locked - * them, and remember we've had a cache hit. + * Data version numbers match. */ - if (setLocks) - ReleaseReadLock(&avc->lock); afs_stats_cmperf.dcacheHits++; - } /*Data version numbers match*/ + } /*Data version numbers match */ + + updateV2DC(setLocks, avc, tdc, 335); /* set hint */ + done: + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + * tdc->lock(S) if tdc + */ - updateV2DC(setLocks,avc,tdc,332); /* set hint */ -done: /* * See if this was a reference to a file in the local cell. */ @@ -2136,20 +2479,89 @@ done: /* Fix up LRU info */ if (tdc) { - hset(afs_indexTimes[tdc->index], afs_indexCounter); - hadd32(afs_indexCounter, 1); + MObtainWriteLock(&afs_xdcache, 602); + hset(afs_indexTimes[tdc->index], afs_indexCounter); + hadd32(afs_indexCounter, 1); + MReleaseWriteLock(&afs_xdcache); - /* return the data */ - if (vType(avc) == VDIR) + /* return the data */ + if (vType(avc) == VDIR) *aoffset = abyte; - else + else *aoffset = AFS_CHUNKOFFSET(abyte); - *alen = (tdc->f.chunkBytes - *aoffset); + *alen = (tdc->f.chunkBytes - *aoffset); + ReleaseSharedLock(&tdc->lock); } - return tdc; + /* + * Locks held: + * avc->lock(R) if setLocks && !slowPass + * avc->lock(W) if !setLocks || slowPass + */ -} /*afs_GetDCache*/ + /* Fix up the callback and status values in the vcache */ + doVcacheUpdate = 0; + if (setLocks && !slowPass) { + /* DCLOCKXXX + * + * This is our dirty little secret to parallel fetches. + * We don't write-lock the vcache while doing the fetch, + * but potentially we'll need to update the vcache after + * the fetch is done. + * + * Drop the read lock and try to re-obtain the write + * lock. If the vcache still has the same DV, it's + * ok to go ahead and install the new data. + */ + afs_hyper_t currentDV, statusDV; + + hset(currentDV, avc->m.DataVersion); + + if (setNewCallback && avc->callback != newCallback) + doVcacheUpdate = 1; + + if (tsmall) { + hset64(statusDV, tsmall->OutStatus.dataVersionHigh, + tsmall->OutStatus.DataVersion); + + if (setVcacheStatus && avc->m.Length != tsmall->OutStatus.Length) + doVcacheUpdate = 1; + if (setVcacheStatus && !hsame(currentDV, statusDV)) + doVcacheUpdate = 1; + } + + ReleaseReadLock(&avc->lock); + + if (doVcacheUpdate) { + ObtainWriteLock(&avc->lock, 615); + if (!hsame(avc->m.DataVersion, currentDV)) { + /* We lose. Someone will beat us to it. */ + doVcacheUpdate = 0; + ReleaseWriteLock(&avc->lock); + } + } + } + + /* With slow pass, we've already done all the updates */ + if (slowPass) { + ReleaseWriteLock(&avc->lock); + } + + /* Check if we need to perform any last-minute fixes with a write-lock */ + if (!setLocks || doVcacheUpdate) { + if (setNewCallback) + avc->callback = newCallback; + if (tsmall && setVcacheStatus) + afs_ProcessFS(avc, &tsmall->OutStatus, areq); + if (setLocks) + ReleaseWriteLock(&avc->lock); + } + + if (tsmall) + osi_FreeLargeSpace(tsmall); + + return tdc; +} /*afs_GetDCache */ /* @@ -2166,26 +2578,72 @@ done: * The afs_xdcache is write-locked through this whole affair. */ void -afs_WriteThroughDSlots() - -{ /*afs_WriteThroughDSlots*/ - +afs_WriteThroughDSlots(void) +{ register struct dcache *tdc; - register afs_int32 i, touchedit=0; + register afs_int32 i, touchedit = 0; + + struct afs_q DirtyQ, *tq; AFS_STATCNT(afs_WriteThroughDSlots); - MObtainWriteLock(&afs_xdcache,283); - for(i = 0; i < afs_cacheFiles; i++) { + + /* + * Because of lock ordering, we can't grab dcache locks while + * holding afs_xdcache. So we enter xdcache, get a reference + * for every dcache entry, and exit xdcache. + */ + MObtainWriteLock(&afs_xdcache, 283); + QInit(&DirtyQ); + for (i = 0; i < afs_cacheFiles; i++) { tdc = afs_indexTable[i]; - if (tdc && (tdc->flags & DFEntryMod)) { - tdc->flags &= ~DFEntryMod; - afs_WriteDCache(tdc, 1); - touchedit = 1; + + /* Grab tlock in case the existing refcount isn't zero */ + if (tdc && !(afs_indexFlags[i] & (IFFree | IFDiscarded))) { + ObtainWriteLock(&tdc->tlock, 623); + tdc->refCount++; + ReleaseWriteLock(&tdc->tlock); + + QAdd(&DirtyQ, &tdc->dirty); } } + MReleaseWriteLock(&afs_xdcache); + + /* + * Now, for each dcache entry we found, check if it's dirty. + * If so, get write-lock, get afs_xdcache, which protects + * afs_cacheInodep, and flush it. Don't forget to put back + * the refcounts. + */ + +#define DQTODC(q) ((struct dcache *)(((char *) (q)) - sizeof(struct afs_q))) + + for (tq = DirtyQ.prev; tq != &DirtyQ; tq = QPrev(tq)) { + tdc = DQTODC(tq); + if (tdc->dflags & DFEntryMod) { + int wrLock; + + wrLock = (0 == NBObtainWriteLock(&tdc->lock, 619)); + + /* Now that we have the write lock, double-check */ + if (wrLock && (tdc->dflags & DFEntryMod)) { + tdc->dflags &= ~DFEntryMod; + MObtainWriteLock(&afs_xdcache, 620); + afs_WriteDCache(tdc, 1); + MReleaseWriteLock(&afs_xdcache); + touchedit = 1; + } + if (wrLock) + ReleaseWriteLock(&tdc->lock); + } + + afs_PutDCache(tdc); + } + + MObtainWriteLock(&afs_xdcache, 617); if (!touchedit && (cacheDiskType != AFS_FCACHE_TYPE_MEM)) { - /* Touch the file to make sure that the mtime on the file is kept up-to-date - * to avoid losing cached files on cold starts because their mtime seems old... + /* Touch the file to make sure that the mtime on the file is kept + * up-to-date to avoid losing cached files on cold starts because + * their mtime seems old... */ struct afs_fheader theader; @@ -2196,82 +2654,96 @@ afs_WriteThroughDSlots() afs_osi_Write(afs_cacheInodep, 0, &theader, sizeof(theader)); } MReleaseWriteLock(&afs_xdcache); - -} /*afs_WriteThroughDSlots*/ +} /* * afs_MemGetDSlot * * Description: * Return a pointer to an freshly initialized dcache entry using - * a memory-based cache. + * a memory-based cache. The tlock will be read-locked. * * Parameters: * aslot : Dcache slot to look at. * tmpdc : Ptr to dcache entry. * * Environment: - * Nothing interesting. + * Must be called with afs_xdcache write-locked. */ -struct dcache *afs_MemGetDSlot(aslot, tmpdc) - register afs_int32 aslot; - register struct dcache *tmpdc; - -{ /*afs_MemGetDSlot*/ - - register afs_int32 code; +struct dcache * +afs_MemGetDSlot(register afs_int32 aslot, register struct dcache *tmpdc) +{ register struct dcache *tdc; - register char *tfile; + int existing = 0; AFS_STATCNT(afs_MemGetDSlot); - if (CheckLock(&afs_xdcache) != -1) osi_Panic("getdslot nolock"); - if (aslot < 0 || aslot >= afs_cacheFiles) osi_Panic("getdslot slot"); + if (CheckLock(&afs_xdcache) != -1) + osi_Panic("getdslot nolock"); + if (aslot < 0 || aslot >= afs_cacheFiles) + osi_Panic("getdslot slot"); tdc = afs_indexTable[aslot]; if (tdc) { - QRemove(&tdc->lruq); /* move to queue head */ + QRemove(&tdc->lruq); /* move to queue head */ QAdd(&afs_DLRU, &tdc->lruq); + /* We're holding afs_xdcache, but get tlock in case refCount != 0 */ + ObtainWriteLock(&tdc->tlock, 624); tdc->refCount++; + ConvertWToRLock(&tdc->tlock); return tdc; } - if (tmpdc == (struct dcache *)0) { - if (!afs_freeDSList) afs_GetDownDSlot(4); + if (tmpdc == NULL) { + if (!afs_freeDSList) + afs_GetDownDSlot(4); if (!afs_freeDSList) { /* none free, making one is better than a panic */ afs_stats_cmperf.dcacheXAllocs++; /* count in case we have a leak */ - tdc = (struct dcache *) afs_osi_Alloc(sizeof (struct dcache)); -#ifdef AFS_AIX32_ENV + tdc = (struct dcache *)afs_osi_Alloc(sizeof(struct dcache)); +#ifdef KERNEL_HAVE_PIN pin((char *)tdc, sizeof(struct dcache)); /* XXX */ #endif } else { tdc = afs_freeDSList; - afs_freeDSList = (struct dcache *) tdc->lruq.next; + afs_freeDSList = (struct dcache *)tdc->lruq.next; + existing = 1; } - tdc->flags = 0; /* up-to-date, not in free q */ + tdc->dflags = 0; /* up-to-date, not in free q */ + tdc->mflags = 0; QAdd(&afs_DLRU, &tdc->lruq); - if (tdc->lruq.prev == &tdc->lruq) osi_Panic("lruq 3"); - } - else { + if (tdc->lruq.prev == &tdc->lruq) + osi_Panic("lruq 3"); + } else { tdc = tmpdc; tdc->f.states = 0; } - + /* initialize entry */ tdc->f.fid.Cell = 0; tdc->f.fid.Fid.Volume = 0; tdc->f.chunk = -1; hones(tdc->f.versionNo); tdc->f.inode = aslot; - tdc->flags |= DFEntryMod; + tdc->dflags |= DFEntryMod; tdc->refCount = 1; tdc->index = aslot; afs_indexUnique[aslot] = tdc->f.fid.Fid.Unique; - - if (tmpdc == (struct dcache *)0) + + if (existing) { + osi_Assert(0 == NBObtainWriteLock(&tdc->lock, 674)); + osi_Assert(0 == NBObtainWriteLock(&tdc->mflock, 675)); + osi_Assert(0 == NBObtainWriteLock(&tdc->tlock, 676)); + } + + RWLOCK_INIT(&tdc->lock, "dcache lock"); + RWLOCK_INIT(&tdc->tlock, "dcache tlock"); + RWLOCK_INIT(&tdc->mflock, "dcache flock"); + ObtainReadLock(&tdc->tlock); + + if (tmpdc == NULL) afs_indexTable[aslot] = tdc; return tdc; -} /*afs_MemGetDSlot*/ +} /*afs_MemGetDSlot */ unsigned int last_error = 0, lasterrtime = 0; @@ -2280,7 +2752,7 @@ unsigned int last_error = 0, lasterrtime = 0; * * Description: * Return a pointer to an freshly initialized dcache entry using - * a UFS-based disk cache. + * a UFS-based disk cache. The dcache tlock will be read-locked. * * Parameters: * aslot : Dcache slot to look at. @@ -2289,27 +2761,27 @@ unsigned int last_error = 0, lasterrtime = 0; * Environment: * afs_xdcache lock write-locked. */ -struct dcache *afs_UFSGetDSlot(aslot, tmpdc) - register afs_int32 aslot; - register struct dcache *tmpdc; - -{ /*afs_UFSGetDSlot*/ - +struct dcache * +afs_UFSGetDSlot(register afs_int32 aslot, register struct dcache *tmpdc) +{ register afs_int32 code; register struct dcache *tdc; + int existing = 0; int entryok; AFS_STATCNT(afs_UFSGetDSlot); - if (CheckLock(&afs_xdcache) != -1) osi_Panic("getdslot nolock"); - if (aslot < 0 || aslot >= afs_cacheFiles) osi_Panic("getdslot slot"); + if (CheckLock(&afs_xdcache) != -1) + osi_Panic("getdslot nolock"); + if (aslot < 0 || aslot >= afs_cacheFiles) + osi_Panic("getdslot slot"); tdc = afs_indexTable[aslot]; if (tdc) { -#ifdef AFS_SUN5_ENVX - mutex_enter(&tdc->lock); -#endif - QRemove(&tdc->lruq); /* move to queue head */ + QRemove(&tdc->lruq); /* move to queue head */ QAdd(&afs_DLRU, &tdc->lruq); + /* Grab tlock in case refCount != 0 */ + ObtainWriteLock(&tdc->tlock, 625); tdc->refCount++; + ConvertWToRLock(&tdc->tlock); return tdc; } /* otherwise we should read it in from the cache file */ @@ -2317,38 +2789,40 @@ struct dcache *afs_UFSGetDSlot(aslot, tmpdc) * If we weren't passed an in-memory region to place the file info, * we have to allocate one. */ - if (tmpdc == (struct dcache *)0) { - if (!afs_freeDSList) afs_GetDownDSlot(4); + if (tmpdc == NULL) { + if (!afs_freeDSList) + afs_GetDownDSlot(4); if (!afs_freeDSList) { /* none free, making one is better than a panic */ afs_stats_cmperf.dcacheXAllocs++; /* count in case we have a leak */ - tdc = (struct dcache *) afs_osi_Alloc(sizeof (struct dcache)); -#ifdef AFS_AIX32_ENV + tdc = (struct dcache *)afs_osi_Alloc(sizeof(struct dcache)); +#ifdef KERNEL_HAVE_PIN pin((char *)tdc, sizeof(struct dcache)); /* XXX */ #endif } else { tdc = afs_freeDSList; - afs_freeDSList = (struct dcache *) tdc->lruq.next; + afs_freeDSList = (struct dcache *)tdc->lruq.next; + existing = 1; } - tdc->flags = 0; /* up-to-date, not in free q */ + tdc->dflags = 0; /* up-to-date, not in free q */ + tdc->mflags = 0; QAdd(&afs_DLRU, &tdc->lruq); - if (tdc->lruq.prev == &tdc->lruq) osi_Panic("lruq 3"); - } - else { + if (tdc->lruq.prev == &tdc->lruq) + osi_Panic("lruq 3"); + } else { tdc = tmpdc; tdc->f.states = 0; tdc->ihint = 0; } -#ifdef AFS_SUN5_ENVX - mutex_enter(&tdc->lock); -#endif /* - * Seek to the aslot'th entry and read it in. - */ - code = afs_osi_Read(afs_cacheInodep, sizeof(struct fcache) * aslot + - sizeof(struct afs_fheader), - (char *)(&tdc->f), sizeof(struct fcache)); + * Seek to the aslot'th entry and read it in. + */ + code = + afs_osi_Read(afs_cacheInodep, + sizeof(struct fcache) * aslot + + sizeof(struct afs_fheader), (char *)(&tdc->f), + sizeof(struct fcache)); entryok = 1; if (code != sizeof(struct fcache)) entryok = 0; @@ -2360,8 +2834,8 @@ struct dcache *afs_UFSGetDSlot(aslot, tmpdc) tdc->f.fid.Fid.Volume = 0; tdc->f.chunk = -1; hones(tdc->f.versionNo); - tdc->flags |= DFEntryMod; -#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_SGI64_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) + tdc->dflags |= DFEntryMod; +#if defined(KERNEL_HAVE_UERROR) last_error = getuerror(); #endif lasterrtime = osi_Time(); @@ -2369,16 +2843,31 @@ struct dcache *afs_UFSGetDSlot(aslot, tmpdc) } tdc->refCount = 1; tdc->index = aslot; + if (tdc->f.chunk >= 0) + tdc->validPos = AFS_CHUNKTOBASE(tdc->f.chunk) + tdc->f.chunkBytes; + else + tdc->validPos = 0; + + if (existing) { + osi_Assert(0 == NBObtainWriteLock(&tdc->lock, 674)); + osi_Assert(0 == NBObtainWriteLock(&tdc->mflock, 675)); + osi_Assert(0 == NBObtainWriteLock(&tdc->tlock, 676)); + } + + RWLOCK_INIT(&tdc->lock, "dcache lock"); + RWLOCK_INIT(&tdc->tlock, "dcache tlock"); + RWLOCK_INIT(&tdc->mflock, "dcache flock"); + ObtainReadLock(&tdc->tlock); /* * If we didn't read into a temporary dcache region, update the * slot pointer table. */ - if (tmpdc == (struct dcache *)0) + if (tmpdc == NULL) afs_indexTable[aslot] = tdc; return tdc; -} /*afs_UFSGetDSlot*/ +} /*afs_UFSGetDSlot */ @@ -2394,20 +2883,18 @@ struct dcache *afs_UFSGetDSlot(aslot, tmpdc) * atime : If true, set the modtime on the file to the current time. * * Environment: - * Must be called with the afs_xdcache lock at least read-locked. + * Must be called with the afs_xdcache lock at least read-locked, + * and dcache entry at least read-locked. * The reference count is not changed. */ -afs_WriteDCache(adc, atime) - int atime; - register struct dcache *adc; - -{ /*afs_WriteDCache*/ - - register struct osi_file *tfile; +int +afs_WriteDCache(register struct dcache *adc, int atime) +{ register afs_int32 code; - if (cacheDiskType == AFS_FCACHE_TYPE_MEM) return 0; + if (cacheDiskType == AFS_FCACHE_TYPE_MEM) + return 0; AFS_STATCNT(afs_WriteDCache); if (atime) adc->f.modTime = osi_Time(); @@ -2415,13 +2902,15 @@ afs_WriteDCache(adc, atime) * Seek to the right dcache slot and write the in-memory image out to disk. */ afs_cellname_write(); - code = afs_osi_Write(afs_cacheInodep, sizeof(struct fcache) * adc->index + - sizeof(struct afs_fheader), - (char *)(&adc->f), sizeof(struct fcache)); - if (code != sizeof(struct fcache)) return EIO; + code = + afs_osi_Write(afs_cacheInodep, + sizeof(struct fcache) * adc->index + + sizeof(struct afs_fheader), (char *)(&adc->f), + sizeof(struct fcache)); + if (code != sizeof(struct fcache)) + return EIO; return 0; - -} /*afs_WriteDCache*/ +} @@ -2439,18 +2928,16 @@ afs_WriteDCache(adc, atime) * Nothing interesting. */ -afs_wakeup(avc) - register struct vcache *avc; - -{ /*afs_wakeup*/ - +int +afs_wakeup(register struct vcache *avc) +{ register int i; register struct brequest *tb; tb = afs_brs; AFS_STATCNT(afs_wakeup); for (i = 0; i < NBRS; i++, tb++) { /* if request is valid and for this file, we've found it */ - if (tb->refCount > 0 && avc == tb->vnode) { + if (tb->refCount > 0 && avc == tb->vc) { /* * If CSafeStore is on, then we don't awaken the guy @@ -2473,8 +2960,7 @@ afs_wakeup(avc) } } return 0; - -} /*afs_wakeup*/ +} /* @@ -2493,14 +2979,11 @@ afs_wakeup(avc) * This function is called only during initialization. */ -int afs_InitCacheFile(afile, ainode) - ino_t ainode; - char *afile; - -{ /*afs_InitCacheFile*/ - +int +afs_InitCacheFile(char *afile, ino_t ainode) +{ register afs_int32 code; -#ifdef AFS_LINUX22_ENV +#if defined(AFS_LINUX22_ENV) struct dentry *filevp; #else struct vnode *filevp; @@ -2513,18 +2996,21 @@ int afs_InitCacheFile(afile, ainode) AFS_STATCNT(afs_InitCacheFile); index = afs_stats_cmperf.cacheNumEntries; - if (index >= afs_cacheFiles) return EINVAL; + if (index >= afs_cacheFiles) + return EINVAL; - MObtainWriteLock(&afs_xdcache,282); - tdc = afs_GetDSlot(index, (struct dcache *)0); + MObtainWriteLock(&afs_xdcache, 282); + tdc = afs_GetDSlot(index, NULL); + ReleaseReadLock(&tdc->tlock); MReleaseWriteLock(&afs_xdcache); + + ObtainWriteLock(&tdc->lock, 621); + MObtainWriteLock(&afs_xdcache, 622); if (afile) { - code = gop_lookupname(afile, - AFS_UIOSYS, - 0, - (struct vnode **) 0, - &filevp); + code = gop_lookupname(afile, AFS_UIOSYS, 0, NULL, &filevp); if (code) { + ReleaseWriteLock(&afs_xdcache); + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); return code; } @@ -2541,24 +3027,25 @@ int afs_InitCacheFile(afile, ainode) #ifdef AFS_DEC_ENV grele(filevp); #else - AFS_RELE((struct vnode *)filevp); + AFS_RELE(filevp); #endif #endif /* AFS_LINUX22_ENV */ - } - else { + } else { tdc->f.inode = ainode; } fileIsBad = 0; - if ((tdc->f.states & DWriting) || - tdc->f.fid.Fid.Volume == 0) fileIsBad = 1; + if ((tdc->f.states & DWriting) || tdc->f.fid.Fid.Volume == 0) + fileIsBad = 1; tfile = osi_UFSOpen(tdc->f.inode); code = afs_osi_Stat(tfile, &tstat); - if (code) osi_Panic("initcachefile stat"); + if (code) + osi_Panic("initcachefile stat"); /* * If file size doesn't match the cache info file, it's probably bad. */ - if (tdc->f.chunkBytes != tstat.size) fileIsBad = 1; + if (tdc->f.chunkBytes != tstat.size) + fileIsBad = 1; tdc->f.chunkBytes = 0; /* @@ -2567,14 +3054,17 @@ int afs_InitCacheFile(afile, ainode) * the cache info file may be incorrectly identified, and so slot * may be bad. */ - if (cacheInfoModTime < tstat.mtime + 120) fileIsBad = 1; - if (cacheInfoModTime < tdc->f.modTime + 120) fileIsBad = 1; + if (cacheInfoModTime < tstat.mtime + 120) + fileIsBad = 1; + if (cacheInfoModTime < tdc->f.modTime + 120) + fileIsBad = 1; /* In case write through is behind, make sure cache items entry is * at least as new as the chunk. */ - if (tdc->f.modTime < tstat.mtime) fileIsBad = 1; + if (tdc->f.modTime < tstat.mtime) + fileIsBad = 1; if (fileIsBad) { - tdc->f.fid.Fid.Volume = 0; /* not in the hash table */ + tdc->f.fid.Fid.Volume = 0; /* not in the hash table */ if (tstat.size != 0) osi_UFSTruncate(tfile, 0); /* put entry in free cache slot list */ @@ -2583,19 +3073,18 @@ int afs_InitCacheFile(afile, ainode) afs_freeDCCount++; afs_indexFlags[index] |= IFFree; afs_indexUnique[index] = 0; - } - else { + } else { /* * We must put this entry in the appropriate hash tables. * Note that i is still set from the above DCHash call */ code = DCHash(&tdc->f.fid, tdc->f.chunk); - afs_dcnextTbl[tdc->index] = afs_dchashTbl[code]; + afs_dcnextTbl[tdc->index] = afs_dchashTbl[code]; afs_dchashTbl[code] = tdc->index; code = DVHash(&tdc->f.fid); afs_dvnextTbl[tdc->index] = afs_dvhashTbl[code]; afs_dvhashTbl[code] = tdc->index; - afs_AdjustSize(tdc, tstat.size); /* adjust to new size */ + afs_AdjustSize(tdc, tstat.size); /* adjust to new size */ if (tstat.size > 0) /* has nontrivial amt of data */ afs_indexFlags[index] |= IFEverUsed; @@ -2609,18 +3098,19 @@ int afs_InitCacheFile(afile, ainode) hset32(afs_indexCounter, tstat.atime); } afs_indexUnique[index] = tdc->f.fid.Fid.Unique; - } /*File is not bad*/ + } /*File is not bad */ osi_UFSClose(tfile); tdc->f.states &= ~DWriting; - tdc->flags &= ~DFEntryMod; + tdc->dflags &= ~DFEntryMod; /* don't set f.modTime; we're just cleaning up */ afs_WriteDCache(tdc, 0); + ReleaseWriteLock(&afs_xdcache); + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); afs_stats_cmperf.cacheNumEntries++; return 0; - -} /*afs_InitCacheFile*/ +} /*Max # of struct dcache's resident at any time*/ @@ -2636,8 +3126,8 @@ int afs_InitCacheFile(afile, ainode) * Description: * Initialize dcache related variables. */ -void afs_dcacheInit(int afiles, int ablocks, int aDentries, int achunk, - int aflags) +void +afs_dcacheInit(int afiles, int ablocks, int aDentries, int achunk, int aflags) { register struct dcache *tdp; int i; @@ -2646,110 +3136,114 @@ void afs_dcacheInit(int afiles, int ablocks, int aDentries, int achunk, afs_freeDCList = NULLIDX; afs_discardDCList = NULLIDX; afs_freeDCCount = 0; - afs_freeDSList = (struct dcache *)0; + afs_freeDSList = NULL; hzero(afs_indexCounter); LOCK_INIT(&afs_xdcache, "afs_xdcache"); - + /* * Set chunk size */ if (achunk) { if (achunk < 0 || achunk > 30) - achunk = 13; /* Use default */ + achunk = 13; /* Use default */ AFS_SETCHUNKSIZE(achunk); } - - if(!aDentries) + + if (!aDentries) aDentries = DDSIZE; - - if(aflags & AFSCALL_INIT_MEMCACHE) { + + if (aflags & AFSCALL_INIT_MEMCACHE) { /* * Use a memory cache instead of a disk cache */ cacheDiskType = AFS_FCACHE_TYPE_MEM; afs_cacheType = &afs_MemCacheOps; - afiles = (afiles < aDentries) ? afiles : aDentries; /* min */ - ablocks = afiles * (AFS_FIRSTCSIZE/1024); + afiles = (afiles < aDentries) ? afiles : aDentries; /* min */ + ablocks = afiles * (AFS_FIRSTCSIZE / 1024); /* ablocks is reported in 1K blocks */ - code = afs_InitMemCache(afiles * AFS_FIRSTCSIZE, AFS_FIRSTCSIZE, aflags); + code = afs_InitMemCache(afiles, AFS_FIRSTCSIZE, aflags); if (code != 0) { printf("afsd: memory cache too large for available memory.\n"); printf("afsd: AFS files cannot be accessed.\n\n"); dcacheDisabled = 1; afiles = ablocks = 0; - } - else - printf("Memory cache: Allocating %d dcache entries...", aDentries); + } else + printf("Memory cache: Allocating %d dcache entries...", + aDentries); } else { cacheDiskType = AFS_FCACHE_TYPE_UFS; afs_cacheType = &afs_UfsCacheOps; } - if (aDentries > 512) + if (aDentries > 512) afs_dhashsize = 2048; /* initialize hash tables */ - afs_dvhashTbl = (afs_int32 *) afs_osi_Alloc(afs_dhashsize * sizeof(afs_int32)); - afs_dchashTbl = (afs_int32 *) afs_osi_Alloc(afs_dhashsize * sizeof(afs_int32)); - for(i=0;i< afs_dhashsize;i++) { + afs_dvhashTbl = + (afs_int32 *) afs_osi_Alloc(afs_dhashsize * sizeof(afs_int32)); + afs_dchashTbl = + (afs_int32 *) afs_osi_Alloc(afs_dhashsize * sizeof(afs_int32)); + for (i = 0; i < afs_dhashsize; i++) { afs_dvhashTbl[i] = NULLIDX; afs_dchashTbl[i] = NULLIDX; } afs_dvnextTbl = (afs_int32 *) afs_osi_Alloc(afiles * sizeof(afs_int32)); afs_dcnextTbl = (afs_int32 *) afs_osi_Alloc(afiles * sizeof(afs_int32)); - for(i=0;i< afiles;i++) { + for (i = 0; i < afiles; i++) { afs_dvnextTbl[i] = NULLIDX; afs_dcnextTbl[i] = NULLIDX; } - + /* Allocate and zero the pointer array to the dcache entries */ afs_indexTable = (struct dcache **) afs_osi_Alloc(sizeof(struct dcache *) * afiles); memset((char *)afs_indexTable, 0, sizeof(struct dcache *) * afiles); - afs_indexTimes = (afs_hyper_t *) afs_osi_Alloc(afiles * sizeof(afs_hyper_t)); + afs_indexTimes = + (afs_hyper_t *) afs_osi_Alloc(afiles * sizeof(afs_hyper_t)); memset((char *)afs_indexTimes, 0, afiles * sizeof(afs_hyper_t)); - afs_indexUnique = (afs_int32 *) afs_osi_Alloc(afiles * sizeof(afs_uint32)); + afs_indexUnique = + (afs_int32 *) afs_osi_Alloc(afiles * sizeof(afs_uint32)); memset((char *)afs_indexUnique, 0, afiles * sizeof(afs_uint32)); afs_indexFlags = (u_char *) afs_osi_Alloc(afiles * sizeof(u_char)); memset((char *)afs_indexFlags, 0, afiles * sizeof(char)); - + /* Allocate and thread the struct dcache entries themselves */ tdp = afs_Initial_freeDSList = - (struct dcache *) afs_osi_Alloc(aDentries * sizeof(struct dcache)); + (struct dcache *)afs_osi_Alloc(aDentries * sizeof(struct dcache)); memset((char *)tdp, 0, aDentries * sizeof(struct dcache)); -#ifdef AFS_AIX32_ENV - pin((char *)afs_indexTable, sizeof(struct dcache *) * afiles);/* XXX */ - pin((char *)afs_indexTimes, sizeof(afs_hyper_t) * afiles); /* XXX */ - pin((char *)afs_indexFlags, sizeof(char) * afiles); /* XXX */ - pin((char *)afs_indexUnique, sizeof(afs_int32) * afiles); /* XXX */ - pin((char *)tdp, aDentries * sizeof(struct dcache)); /* XXX */ - pin((char *)afs_dvhashTbl, sizeof(afs_int32) * afs_dhashsize); /* XXX */ - pin((char *)afs_dchashTbl, sizeof(afs_int32) * afs_dhashsize); /* XXX */ - pin((char *)afs_dcnextTbl, sizeof(afs_int32) * afiles); /* XXX */ - pin((char *)afs_dvnextTbl, sizeof(afs_int32) * afiles); /* XXX */ +#ifdef KERNEL_HAVE_PIN + pin((char *)afs_indexTable, sizeof(struct dcache *) * afiles); /* XXX */ + pin((char *)afs_indexTimes, sizeof(afs_hyper_t) * afiles); /* XXX */ + pin((char *)afs_indexFlags, sizeof(char) * afiles); /* XXX */ + pin((char *)afs_indexUnique, sizeof(afs_int32) * afiles); /* XXX */ + pin((char *)tdp, aDentries * sizeof(struct dcache)); /* XXX */ + pin((char *)afs_dvhashTbl, sizeof(afs_int32) * afs_dhashsize); /* XXX */ + pin((char *)afs_dchashTbl, sizeof(afs_int32) * afs_dhashsize); /* XXX */ + pin((char *)afs_dcnextTbl, sizeof(afs_int32) * afiles); /* XXX */ + pin((char *)afs_dvnextTbl, sizeof(afs_int32) * afiles); /* XXX */ #endif afs_freeDSList = &tdp[0]; - for(i=0; i < aDentries-1; i++) { - tdp[i].lruq.next = (struct afs_q *) (&tdp[i+1]); + for (i = 0; i < aDentries - 1; i++) { + tdp[i].lruq.next = (struct afs_q *)(&tdp[i + 1]); } - tdp[aDentries-1].lruq.next = (struct afs_q *) 0; + tdp[aDentries - 1].lruq.next = (struct afs_q *)0; - afs_stats_cmperf.cacheBlocksOrig = afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks = ablocks; + afs_stats_cmperf.cacheBlocksOrig = afs_stats_cmperf.cacheBlocksTotal = + afs_cacheBlocks = ablocks; afs_ComputeCacheParms(); /* compute parms based on cache size */ afs_dcentries = aDentries; afs_blocksUsed = 0; QInit(&afs_DLRU); - - } /* * shutdown_dcache * */ -void shutdown_dcache(void) +void +shutdown_dcache(void) { int i; @@ -2759,28 +3253,31 @@ void shutdown_dcache(void) afs_osi_Free(afs_indexTimes, afs_cacheFiles * sizeof(afs_hyper_t)); afs_osi_Free(afs_indexUnique, afs_cacheFiles * sizeof(afs_uint32)); afs_osi_Free(afs_indexFlags, afs_cacheFiles * sizeof(u_char)); - afs_osi_Free(afs_Initial_freeDSList, afs_dcentries * sizeof(struct dcache)); -#ifdef AFS_AIX32_ENV + afs_osi_Free(afs_Initial_freeDSList, + afs_dcentries * sizeof(struct dcache)); +#ifdef KERNEL_HAVE_PIN unpin((char *)afs_dcnextTbl, afs_cacheFiles * sizeof(afs_int32)); unpin((char *)afs_dvnextTbl, afs_cacheFiles * sizeof(afs_int32)); unpin((char *)afs_indexTable, afs_cacheFiles * sizeof(struct dcache *)); unpin((char *)afs_indexTimes, afs_cacheFiles * sizeof(afs_hyper_t)); unpin((char *)afs_indexUnique, afs_cacheFiles * sizeof(afs_uint32)); - unpin((u_char *)afs_indexFlags, afs_cacheFiles * sizeof(u_char)); + unpin((u_char *) afs_indexFlags, afs_cacheFiles * sizeof(u_char)); unpin(afs_Initial_freeDSList, afs_dcentries * sizeof(struct dcache)); #endif - for(i=0;i< afs_dhashsize;i++) { + for (i = 0; i < afs_dhashsize; i++) { afs_dvhashTbl[i] = NULLIDX; afs_dchashTbl[i] = NULLIDX; } + afs_osi_Free(afs_dvhashTbl, afs_dhashsize * sizeof(afs_int32)); + afs_osi_Free(afs_dchashTbl, afs_dhashsize * sizeof(afs_int32)); afs_blocksUsed = afs_dcentries = 0; hzero(afs_indexCounter); - afs_freeDCCount = 0; + afs_freeDCCount = 0; afs_freeDCList = NULLIDX; afs_discardDCList = NULLIDX; afs_freeDSList = afs_Initial_freeDSList = 0; diff --git a/src/afs/afs_dynroot.c b/src/afs/afs_dynroot.c index 724116625..a55949663 100644 --- a/src/afs/afs_dynroot.c +++ b/src/afs/afs_dynroot.c @@ -26,17 +26,17 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" -#include "../afs/afs_osi.h" -#include "../afsint/afsint.h" -#include "../afs/lock.h" +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" +#include "afs/afs_osi.h" +#include "afsint.h" +#include "afs/lock.h" -#include "../afs/prs_fs.h" -#include "../afs/dir.h" +#include "afs/prs_fs.h" +#include "afs/dir.h" #define AFS_DYNROOT_CELLNAME "dynroot" #define AFS_DYNROOT_VOLUME 1 @@ -91,22 +91,21 @@ static struct afs_dynSymlink *afs_dynSymlinkBase = NULL; static int afs_dynSymlinkIndex = 0; /* End of variables protected by afs_dynSymlinkLock */ -extern afs_int32 afs_cellindex; -extern afs_rwlock_t afs_xvcache; - /* * Set up a cell for dynroot if it's not there yet. */ -static int afs_dynrootCellInit() +static int +afs_dynrootCellInit() { if (afs_dynrootEnable && !afs_dynrootCell) { afs_int32 cellHosts[MAXCELLHOSTS]; struct cell *tc; int code; - + memset(cellHosts, 0, sizeof(cellHosts)); - code = afs_NewCell(AFS_DYNROOT_CELLNAME, cellHosts, CNoSUID | CNoAFSDB, - NULL, 0, 0, 0); + code = + afs_NewCell(AFS_DYNROOT_CELLNAME, cellHosts, CNoSUID | CNoAFSDB, + NULL, 0, 0, 0); if (code) return code; tc = afs_GetCellByName(AFS_DYNROOT_CELLNAME, READ_LOCK); @@ -115,6 +114,7 @@ static int afs_dynrootCellInit() afs_dynrootCell = tc->cellNum; afs_PutCell(tc, READ_LOCK); } + return 0; } @@ -124,23 +124,21 @@ static int afs_dynrootCellInit() int afs_IsDynrootFid(struct VenusFid *fid) { - return - (afs_dynrootEnable && - fid->Cell == afs_dynrootCell && - fid->Fid.Volume == AFS_DYNROOT_VOLUME && - fid->Fid.Vnode == AFS_DYNROOT_VNODE && - fid->Fid.Unique == AFS_DYNROOT_UNIQUE); + return (afs_dynrootEnable && fid->Cell == afs_dynrootCell + && fid->Fid.Volume == AFS_DYNROOT_VOLUME + && fid->Fid.Vnode == AFS_DYNROOT_VNODE + && fid->Fid.Unique == AFS_DYNROOT_UNIQUE); } /* * Obtain the magic dynroot volume Fid. */ void -afs_GetDynrootFid(struct VenusFid *fid) +afs_GetDynrootFid(struct VenusFid *fid) { - fid->Cell = afs_dynrootCell; + fid->Cell = afs_dynrootCell; fid->Fid.Volume = AFS_DYNROOT_VOLUME; - fid->Fid.Vnode = AFS_DYNROOT_VNODE; + fid->Fid.Vnode = AFS_DYNROOT_VNODE; fid->Fid.Unique = AFS_DYNROOT_UNIQUE; } @@ -148,8 +146,7 @@ afs_GetDynrootFid(struct VenusFid *fid) * Returns non-zero iff avc is a pointer to the dynroot /afs vnode. */ int -afs_IsDynroot(avc) - struct vcache *avc; +afs_IsDynroot(struct vcache *avc) { return afs_IsDynrootFid(&avc->fid); } @@ -159,7 +156,8 @@ afs_IsDynroot(avc) * appropriately so that the given file name can be appended. Used for * computing the size of a directory. */ -static void afs_dynroot_computeDirEnt(char *name, int *curPageP, int *curChunkP) +static void +afs_dynroot_computeDirEnt(char *name, int *curPageP, int *curChunkP) { int esize; @@ -177,14 +175,10 @@ static void afs_dynroot_computeDirEnt(char *name, int *curPageP, int *curChunkP) * the necessary entry. */ static void -afs_dynroot_addDirEnt(dirHeader, curPageP, curChunkP, name, vnode) - struct DirHeader *dirHeader; - int *curPageP; - int *curChunkP; - char *name; - int vnode; +afs_dynroot_addDirEnt(struct DirHeader *dirHeader, int *curPageP, + int *curChunkP, char *name, int vnode) { - char *dirBase = (char *) dirHeader; + char *dirBase = (char *)dirHeader; struct PageHeader *pageHeader; struct DirEntry *dirEntry; int sizeOfEntry, i, t1, t2; @@ -202,23 +196,23 @@ afs_dynroot_addDirEnt(dirHeader, curPageP, curChunkP, name, vnode) didNewPage = 1; } - pageHeader = (struct PageHeader *) (dirBase + curPage * AFS_PAGESIZE); + pageHeader = (struct PageHeader *)(dirBase + curPage * AFS_PAGESIZE); if (didNewPage) { pageHeader->pgcount = 0; pageHeader->tag = htons(1234); pageHeader->freecount = 0; pageHeader->freebitmap[0] = 0x01; - for (i = 1; i < EPP/8; i++) + for (i = 1; i < EPP / 8; i++) pageHeader->freebitmap[i] = 0; dirHeader->alloMap[curPage] = EPP - 1; } - dirEntry = (struct DirEntry *) (pageHeader + curChunk); - dirEntry->flag = 1; - dirEntry->length = 0; - dirEntry->next = 0; - dirEntry->fid.vnode = htonl(vnode); + dirEntry = (struct DirEntry *)(pageHeader + curChunk); + dirEntry->flag = 1; + dirEntry->length = 0; + dirEntry->next = 0; + dirEntry->fid.vnode = htonl(vnode); dirEntry->fid.vunique = htonl(1); strcpy(dirEntry->name, name); @@ -246,25 +240,26 @@ afs_dynroot_addDirEnt(dirHeader, curPageP, curChunkP, name, vnode) * Invalidate the /afs vnode for dynroot; called when the underlying * directory has changed and needs to be re-read. */ -void afs_DynrootInvalidate(void) +void +afs_DynrootInvalidate(void) { afs_int32 retry; struct vcache *tvc; struct VenusFid tfid; - + if (!afs_dynrootEnable) return; - + ObtainWriteLock(&afs_dynrootDirLock, 687); afs_dynrootVersion++; afs_dynrootVersionHigh = osi_Time(); ReleaseWriteLock(&afs_dynrootDirLock); - + afs_GetDynrootFid(&tfid); do { retry = 0; ObtainReadLock(&afs_xvcache); - tvc = afs_FindVCache(&tfid, 0, 0, &retry, 0); + tvc = afs_FindVCache(&tfid, &retry, 0); ReleaseReadLock(&afs_xvcache); } while (retry); if (tvc) { @@ -279,17 +274,17 @@ void afs_DynrootInvalidate(void) * cells. Useful when the list of cells has changed due to * an AFSDB lookup, for instance. */ -static void afs_RebuildDynroot(void) +static void +afs_RebuildDynroot(void) { int cellidx, maxcellidx, i; int aliasidx, maxaliasidx; struct cell *c; struct cell_alias *ca; int curChunk, curPage; - int dirSize, sizeOfCurEntry, dotLen; + int dirSize, dotLen; char *newDir, *dotCell; struct DirHeader *dirHeader; - struct DirEntry *dirEntry; int linkCount = 0; struct afs_dynSymlink *ts; int newVersion; @@ -307,55 +302,40 @@ static void afs_RebuildDynroot(void) /* Reserve space for "." and ".." */ curChunk += 2; - for (cellidx = 0; ; cellidx++) { + for (cellidx = 0;; cellidx++) { c = afs_GetCellByIndex(cellidx, READ_LOCK); - if (!c) break; - if (c->cellNum == afs_dynrootCell) continue; - - sizeOfCurEntry = afs_dir_NameBlobs(c->cellName); - if (curChunk + sizeOfCurEntry > EPP) { - curPage++; - curChunk = 1; - } - curChunk += sizeOfCurEntry; + if (!c) + break; + if (c->cellNum == afs_dynrootCell) + continue; dotLen = strlen(c->cellName) + 2; dotCell = afs_osi_Alloc(dotLen); strcpy(dotCell, "."); - strcat(dotCell, c->cellName); - sizeOfCurEntry = afs_dir_NameBlobs(dotCell); - if (curChunk + sizeOfCurEntry > EPP) { - curPage++; - curChunk = 1; - } - curChunk += sizeOfCurEntry; + afs_strcat(dotCell, c->cellName); + + afs_dynroot_computeDirEnt(c->cellName, &curPage, &curChunk); + afs_dynroot_computeDirEnt(dotCell, &curPage, &curChunk); afs_osi_Free(dotCell, dotLen); afs_PutCell(c, READ_LOCK); } maxcellidx = cellidx; - for (aliasidx = 0; ; aliasidx++) { + for (aliasidx = 0;; aliasidx++) { ca = afs_GetCellAlias(aliasidx); - if (!ca) break; - - sizeOfCurEntry = afs_dir_NameBlobs(ca->alias); - if (curChunk + sizeOfCurEntry > EPP) { - curPage++; - curChunk = 1; - } - curChunk += sizeOfCurEntry; + if (!ca) + break; - dotCell = afs_osi_Alloc(strlen(ca->alias) + 2); + dotLen = strlen(ca->alias) + 2; + dotCell = afs_osi_Alloc(dotLen); strcpy(dotCell, "."); - strcat(dotCell, ca->alias); - sizeOfCurEntry = afs_dir_NameBlobs(dotCell); - if (curChunk + sizeOfCurEntry > EPP) { - curPage++; - curChunk = 1; - } - curChunk += sizeOfCurEntry; + afs_strcat(dotCell, ca->alias); + + afs_dynroot_computeDirEnt(ca->alias, &curPage, &curChunk); + afs_dynroot_computeDirEnt(dotCell, &curPage, &curChunk); + afs_osi_Free(dotCell, dotLen); afs_PutCellAlias(ca); } maxaliasidx = aliasidx; @@ -363,12 +343,7 @@ static void afs_RebuildDynroot(void) ObtainReadLock(&afs_dynSymlinkLock); ts = afs_dynSymlinkBase; while (ts) { - sizeOfCurEntry = afs_dir_NameBlobs(ts->name); - if (curChunk + sizeOfCurEntry > EPP) { - curPage++; - curChunk = 1; - } - curChunk += sizeOfCurEntry; + afs_dynroot_computeDirEnt(ts->name, &curPage, &curChunk); ts = ts->next; } @@ -380,7 +355,7 @@ static void afs_RebuildDynroot(void) */ curChunk = 13; curPage = 0; - dirHeader = (struct DirHeader *) newDir; + dirHeader = (struct DirHeader *)newDir; dirHeader->header.pgcount = 0; dirHeader->header.tag = htons(1234); @@ -388,7 +363,7 @@ static void afs_RebuildDynroot(void) dirHeader->header.freebitmap[0] = 0xff; dirHeader->header.freebitmap[1] = 0x1f; - for (i = 2; i < EPP/8; i++) + for (i = 2; i < EPP / 8; i++) dirHeader->header.freebitmap[i] = 0; dirHeader->alloMap[0] = EPP - DHE - 1; for (i = 1; i < MAXPAGES; i++) @@ -403,54 +378,58 @@ static void afs_RebuildDynroot(void) for (cellidx = 0; cellidx < maxcellidx; cellidx++) { c = afs_GetCellByIndex(cellidx, READ_LOCK); - if (!c) continue; - if (c->cellNum == afs_dynrootCell) continue; + if (!c) + continue; + if (c->cellNum == afs_dynrootCell) + continue; dotLen = strlen(c->cellName) + 2; dotCell = afs_osi_Alloc(dotLen); strcpy(dotCell, "."); - strcat(dotCell, c->cellName); - afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, - c->cellName, VNUM_FROM_CIDX_RW(cellidx, 0)); - afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, - dotCell, VNUM_FROM_CIDX_RW(cellidx, 1)); + afs_strcat(dotCell, c->cellName); + afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, c->cellName, + VNUM_FROM_CIDX_RW(cellidx, 0)); + afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, dotCell, + VNUM_FROM_CIDX_RW(cellidx, 1)); + afs_osi_Free(dotCell, dotLen); linkCount += 2; - - afs_osi_Free(dotCell, dotLen); afs_PutCell(c, READ_LOCK); } for (aliasidx = 0; aliasidx < maxaliasidx; aliasidx++) { ca = afs_GetCellAlias(aliasidx); - if (!ca) continue; - - dotCell = afs_osi_Alloc(strlen(ca->alias) + 2); + if (!ca) + continue; + + dotLen = strlen(ca->alias) + 2; + dotCell = afs_osi_Alloc(dotLen); strcpy(dotCell, "."); - strcat(dotCell, ca->alias); - afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, - ca->alias, VNUM_FROM_CAIDX_RW(aliasidx, 0)); - afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, - dotCell, VNUM_FROM_CAIDX_RW(aliasidx, 1)); + afs_strcat(dotCell, ca->alias); + afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, ca->alias, + VNUM_FROM_CAIDX_RW(aliasidx, 0)); + afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, dotCell, + VNUM_FROM_CAIDX_RW(aliasidx, 1)); + afs_osi_Free(dotCell, dotLen); afs_PutCellAlias(ca); } - + ts = afs_dynSymlinkBase; while (ts) { int vnum = VNUM_FROM_TYPEID(VN_TYPE_SYMLINK, ts->index); - afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, - ts->name, vnum); + afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk, ts->name, vnum); ts = ts->next; } ReleaseReadLock(&afs_dynSymlinkLock); ObtainWriteLock(&afs_dynrootDirLock, 549); - if (afs_dynrootDir) afs_osi_Free(afs_dynrootDir, afs_dynrootDirLen); + if (afs_dynrootDir) + afs_osi_Free(afs_dynrootDir, afs_dynrootDirLen); afs_dynrootDir = newDir; afs_dynrootDirLen = dirSize; afs_dynrootDirLinkcnt = linkCount; - afs_dynrootVersion = newVersion; + afs_dynrootDirVersion = newVersion; ReleaseWriteLock(&afs_dynrootDirLock); } @@ -458,8 +437,9 @@ static void afs_RebuildDynroot(void) * Returns a pointer to the base of the dynroot directory in memory, * length thereof, and a FetchStatus. */ -void afs_GetDynroot(char **dynrootDir, int *dynrootLen, - struct AFSFetchStatus *status) +void +afs_GetDynroot(char **dynrootDir, int *dynrootLen, + struct AFSFetchStatus *status) { ObtainReadLock(&afs_dynrootDirLock); if (!afs_dynrootDir || afs_dynrootDirVersion != afs_dynrootVersion) { @@ -468,20 +448,22 @@ void afs_GetDynroot(char **dynrootDir, int *dynrootLen, ObtainReadLock(&afs_dynrootDirLock); } - if (dynrootDir) *dynrootDir = afs_dynrootDir; - if (dynrootLen) *dynrootLen = afs_dynrootDirLen; + if (dynrootDir) + *dynrootDir = afs_dynrootDir; + if (dynrootLen) + *dynrootLen = afs_dynrootDirLen; if (status) { memset(status, 0, sizeof(struct AFSFetchStatus)); - status->FileType = Directory; - status->LinkCount = afs_dynrootDirLinkcnt; - status->Length = afs_dynrootDirLen; - status->DataVersion = afs_dynrootVersion; - status->CallerAccess = PRSFS_LOOKUP | PRSFS_READ; + status->FileType = Directory; + status->LinkCount = afs_dynrootDirLinkcnt; + status->Length = afs_dynrootDirLen; + status->DataVersion = afs_dynrootVersion; + status->CallerAccess = PRSFS_LOOKUP | PRSFS_READ; status->AnonymousAccess = PRSFS_LOOKUP | PRSFS_READ; - status->UnixModeBits = 0755; - status->ParentVnode = 1; - status->ParentUnique = 1; + status->UnixModeBits = 0755; + status->ParentVnode = 1; + status->ParentUnique = 1; status->dataVersionHigh = afs_dynrootVersionHigh; } } @@ -490,7 +472,7 @@ void afs_GetDynroot(char **dynrootDir, int *dynrootLen, * Puts back the dynroot read lock. */ void -afs_PutDynroot() +afs_PutDynroot(void) { ReleaseReadLock(&afs_dynrootDirLock); } @@ -501,11 +483,10 @@ afs_PutDynroot() * FetchStatus will be filled in. */ int -afs_DynrootNewVnode(avc, status) - struct vcache *avc; - struct AFSFetchStatus *status; +afs_DynrootNewVnode(struct vcache *avc, struct AFSFetchStatus *status) { - if (!afs_dynrootEnable) return 0; + if (!afs_dynrootEnable) + return 0; if (afs_IsDynroot(avc)) { afs_GetDynroot(0, 0, status); @@ -516,8 +497,8 @@ afs_DynrootNewVnode(avc, status) /* * Check if this is an entry under /afs, e.g. /afs/cellname. */ - if (avc->fid.Cell == afs_dynrootCell && - avc->fid.Fid.Volume == AFS_DYNROOT_VOLUME) { + if (avc->fid.Cell == afs_dynrootCell + && avc->fid.Fid.Volume == AFS_DYNROOT_VOLUME) { struct cell *c; struct cell_alias *ca; @@ -525,13 +506,13 @@ afs_DynrootNewVnode(avc, status) memset(status, 0, sizeof(struct AFSFetchStatus)); - status->FileType = SymbolicLink; - status->LinkCount = 1; - status->DataVersion = 1; - status->CallerAccess = PRSFS_LOOKUP | PRSFS_READ; + status->FileType = SymbolicLink; + status->LinkCount = 1; + status->DataVersion = 1; + status->CallerAccess = PRSFS_LOOKUP | PRSFS_READ; status->AnonymousAccess = PRSFS_LOOKUP | PRSFS_READ; - status->ParentVnode = 1; - status->ParentUnique = 1; + status->ParentVnode = 1; + status->ParentUnique = 1; if (VNUM_TO_VNTYPE(avc->fid.Fid.Vnode) == VN_TYPE_SYMLINK) { struct afs_dynSymlink *ts; @@ -540,7 +521,8 @@ afs_DynrootNewVnode(avc, status) ObtainReadLock(&afs_dynSymlinkLock); ts = afs_dynSymlinkBase; while (ts) { - if (ts->index == index) break; + if (ts->index == index) + break; ts = ts->next; } @@ -549,7 +531,7 @@ afs_DynrootNewVnode(avc, status) avc->linkData = afs_osi_Alloc(linklen + 1); strcpy(avc->linkData, ts->target); - status->Length = linklen; + status->Length = linklen; status->UnixModeBits = 0755; } ReleaseReadLock(&afs_dynSymlinkLock); @@ -557,8 +539,8 @@ afs_DynrootNewVnode(avc, status) return ts ? 1 : 0; } - if (VNUM_TO_VNTYPE(avc->fid.Fid.Vnode) != VN_TYPE_CELL && - VNUM_TO_VNTYPE(avc->fid.Fid.Vnode) != VN_TYPE_ALIAS) { + if (VNUM_TO_VNTYPE(avc->fid.Fid.Vnode) != VN_TYPE_CELL + && VNUM_TO_VNTYPE(avc->fid.Fid.Vnode) != VN_TYPE_ALIAS) { afs_warn("dynroot vnode inconsistency, unknown VNTYPE %d\n", VNUM_TO_VNTYPE(avc->fid.Fid.Vnode)); return 0; @@ -592,7 +574,7 @@ afs_DynrootNewVnode(avc, status) linklen = rw + namelen; avc->linkData = afs_osi_Alloc(linklen + 1); strcpy(avc->linkData, rw ? "." : ""); - strcat(avc->linkData, realName); + afs_strcat(avc->linkData, realName); } status->UnixModeBits = 0755; @@ -612,8 +594,8 @@ afs_DynrootNewVnode(avc, status) linklen = 1 + namelen + 10; avc->linkData = afs_osi_Alloc(linklen + 1); strcpy(avc->linkData, rw ? "%" : "#"); - strcat(avc->linkData, c->cellName); - strcat(avc->linkData, ":root.cell"); + afs_strcat(avc->linkData, c->cellName); + afs_strcat(avc->linkData, ":root.cell"); status->UnixModeBits = 0644; afs_PutCell(c, READ_LOCK); @@ -630,8 +612,7 @@ afs_DynrootNewVnode(avc, status) * Enable or disable dynroot. Returns 0 if successful. */ int -afs_SetDynrootEnable(enable) - int enable; +afs_SetDynrootEnable(int enable) { afs_dynrootEnable = enable; return afs_dynrootCellInit(); @@ -641,7 +622,7 @@ afs_SetDynrootEnable(enable) * Check if dynroot support is enabled. */ int -afs_GetDynrootEnable() +afs_GetDynrootEnable(void) { return afs_dynrootEnable; } @@ -650,8 +631,7 @@ afs_GetDynrootEnable() * Remove a temporary symlink entry from /afs. */ int -afs_DynrootVOPRemove(struct vcache *avc, struct AFS_UCRED *acred, - char *aname) +afs_DynrootVOPRemove(struct vcache *avc, struct AFS_UCRED *acred, char *aname) { struct afs_dynSymlink **tpps; struct afs_dynSymlink *tps; @@ -683,7 +663,7 @@ afs_DynrootVOPRemove(struct vcache *avc, struct AFS_UCRED *acred, if (afs_CellOrAliasExists(aname)) return EROFS; - else + else return ENOENT; } @@ -691,19 +671,15 @@ afs_DynrootVOPRemove(struct vcache *avc, struct AFS_UCRED *acred, * Create a temporary symlink entry in /afs. */ int -afs_DynrootVOPSymlink(avc, acred, aname, atargetName) - struct vcache *avc; - struct AFS_UCRED *acred; - char *aname; - char *atargetName; +afs_DynrootVOPSymlink(struct vcache *avc, struct AFS_UCRED *acred, + char *aname, char *atargetName) { struct afs_dynSymlink *tps; if (acred->cr_uid) return EPERM; - if (afs_CellOrAliasExists(aname)) - return EEXIST; + return EEXIST; /* Check if it's already a symlink */ ObtainWriteLock(&afs_dynSymlinkLock, 91); diff --git a/src/afs/afs_exporter.c b/src/afs/afs_exporter.c index 8e7b48935..7d75c94f1 100644 --- a/src/afs/afs_exporter.c +++ b/src/afs/afs_exporter.c @@ -8,24 +8,25 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_exporter.c,v 1.1.1.5 2001/09/11 14:24:40 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_exporter.c,v 1.8 2003/07/15 23:14:12 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics gathering code */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics gathering code */ -struct afs_exporter *root_exported=0; /* Head of "exporters" link list */ -afs_lock_t afs_xexp; +struct afs_exporter *root_exported = 0; /* Head of "exporters" link list */ +afs_lock_t afs_xexp; /* Add a new "afs exporter" entry to the table of exporters. The default initial values of the entry are passed in as parameters. */ static afs_int32 init_xexported = 0; -struct afs_exporter *exporter_add(size, ops, state, type, data) -afs_int32 size, state, type; -struct exporterops *ops; -char *data; + +struct afs_exporter * +exporter_add(afs_int32 size, struct exporterops *ops, afs_int32 state, + afs_int32 type, char *data) { struct afs_exporter *ex, *op; afs_int32 length; @@ -36,14 +37,14 @@ char *data; LOCK_INIT(&afs_xexp, "afs_xexp"); } length = (size ? size : sizeof(struct afs_exporter)); - ex = (struct afs_exporter *) afs_osi_Alloc(length); + ex = (struct afs_exporter *)afs_osi_Alloc(length); memset((char *)ex, 0, length); - MObtainWriteLock(&afs_xexp,308); + MObtainWriteLock(&afs_xexp, 308); for (op = root_exported; op; op = op->exp_next) { if (!op->exp_next) break; } - if (op) + if (op) op->exp_next = ex; else root_exported = ex; @@ -58,8 +59,8 @@ char *data; /* Returns the "afs exporter" structure of type, "type". NULL is returned if not found */ -struct afs_exporter *exporter_find(type) -int type; +struct afs_exporter * +exporter_find(int type) { struct afs_exporter *op; @@ -76,7 +77,8 @@ int type; } -shutdown_exporter() +void +shutdown_exporter(void) { struct afs_exporter *ex, *op; diff --git a/src/afs/afs_init.c b/src/afs/afs_init.c index aa4a3458e..956a9778f 100644 --- a/src/afs/afs_init.c +++ b/src/afs/afs_init.c @@ -14,113 +14,36 @@ */ #include -#include "../afs/param.h" - -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_init.c,v 1.1.1.10 2003/04/13 19:02:36 hartmans Exp $"); - -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ - - -/* Imported variables */ -extern afs_int32 afs_waitForever; -extern short afs_waitForeverCount; -extern afs_int32 afs_FVIndex; -extern struct server *afs_setTimeHost; -extern struct server *afs_servers[NSERVERS]; -extern struct unixuser *afs_users[NUSERS]; -extern struct volume *afs_freeVolList; -extern struct volume *afs_volumes[NVOLS]; -extern afs_int32 afs_volCounter; - -extern afs_rwlock_t afs_xaxs; -extern afs_rwlock_t afs_xvolume; -extern afs_rwlock_t afs_xuser; -extern afs_rwlock_t afs_xserver; -extern afs_rwlock_t afs_xsrvAddr; -#ifndef AFS_AIX41_ENV -extern afs_lock_t osi_fsplock; -#endif -extern afs_lock_t osi_flplock; -extern afs_int32 fvTable[NFENTRIES]; - -/* afs_cell.c */ -extern afs_rwlock_t afs_xcell; -extern struct afs_q CellLRU; -extern afs_int32 afs_cellindex; -extern afs_int32 afs_nextCellNum; - -/* afs_conn.c */ -extern afs_rwlock_t afs_xconn; -extern afs_rwlock_t afs_xinterface; - -/* afs_mariner.c */ -extern struct rx_service *afs_server; - - -/* afs_mariner.c */ -extern afs_int32 afs_mariner; -extern afs_int32 afs_marinerHost; - -/* afs_volume.c */ -extern ino_t volumeInode; - -/* afs_osi_pag.c */ -extern afs_uint32 pag_epoch; - -/* afs_dcache.c */ -extern afs_rwlock_t afs_xdcache; -extern int cacheDiskType; -extern afs_int32 afs_fsfragsize; -extern ino_t cacheInode; -extern struct osi_file *afs_cacheInodep; -extern afs_int32 afs_freeDCList; /*Free list for disk cache entries*/ - +#include "afs/param.h" -/* afs_vcache.c */ -extern afs_rwlock_t afs_xvcache; -extern afs_rwlock_t afs_xvcb; +RCSID + ("$Header: /cvs/openafs/src/afs/afs_init.c,v 1.28 2004/05/08 04:23:56 shadow Exp $"); -/* VNOPS/afs_vnop_read.c */ -extern afs_int32 maxIHint; -extern afs_int32 nihints; /* # of above actually in-use */ -extern afs_int32 usedihint; - -/* afs_server.c */ -extern afs_int32 afs_setTime; -extern afs_rwlock_t afs_xsrvAddr; - -/* Imported functions. */ -extern struct rx_securityClass *rxnull_NewServerSecurityObject(); -extern int RXAFSCB_ExecuteRequest(); -extern int RXSTATS_ExecuteRequest(); - - -/* afs_osi.c */ -extern afs_lock_t afs_ftf; +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ /* Exported variables */ -struct osi_dev cacheDev; /*Cache device*/ -afs_int32 cacheInfoModTime; /*Last time cache info modified*/ +struct osi_dev cacheDev; /*Cache device */ +afs_int32 cacheInfoModTime; /*Last time cache info modified */ #if defined(AFS_OSF_ENV) || defined(AFS_DEC_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -struct mount *afs_cacheVfsp=0; +struct mount *afs_cacheVfsp = 0; #elif defined(AFS_LINUX20_ENV) struct super_block *afs_cacheSBp = 0; #else -struct vfs *afs_cacheVfsp=0; +struct vfs *afs_cacheVfsp = 0; #endif -afs_rwlock_t afs_puttofileLock; /* not used */ -char *afs_sysname = 0; /* So that superuser may change the - * local value of @sys */ +afs_rwlock_t afs_puttofileLock; /* not used */ +char *afs_sysname = 0; /* So that superuser may change the + * local value of @sys */ char *afs_sysnamelist[MAXNUMSYSNAMES]; /* For support of a list of sysname */ int afs_sysnamecount = 0; struct volume *Initialafs_freeVolList; int afs_memvolumes = 0; - -/* Local variables */ - +#if defined(AFS_XBSD_ENV) +static struct vnode *volumeVnode; +#endif /* * Initialization order is important. Must first call afs_CacheInit, @@ -156,17 +79,12 @@ int afs_memvolumes = 0; struct cm_initparams cm_initParams; static int afs_cacheinit_flag = 0; int -afs_CacheInit(astatSize, afiles, ablocks, aDentries, aVolumes, achunk, aflags, - ninodes, nusers) - afs_int32 afiles; - afs_int32 astatSize, ablocks; - afs_int32 achunk, aflags, ninodes, nusers; - afs_int32 aDentries; -{ /*afs_CacheInit*/ - extern int afs_memvolumes; - register afs_int32 i, preallocs; +afs_CacheInit(afs_int32 astatSize, afs_int32 afiles, afs_int32 ablocks, + afs_int32 aDentries, afs_int32 aVolumes, afs_int32 achunk, + afs_int32 aflags, afs_int32 ninodes, afs_int32 nusers) +{ + register afs_int32 i; register struct volume *tv; - long code; AFS_STATCNT(afs_CacheInit); /* @@ -195,29 +113,36 @@ afs_CacheInit(astatSize, afiles, ablocks, aDentries, aVolumes, achunk, aflags, #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - /* - * We want to also reserve space for the gnode struct which is associated - * with each vnode (vcache) one; we want to use the pinned pool for them - * since they're referenced at interrupt level. - */ - if (afs_stats_cmperf.SmallBlocksAlloced + astatSize < 3600) - preallocs = astatSize; - else { - preallocs = 3600 - afs_stats_cmperf.SmallBlocksAlloced; - if (preallocs <= 0) preallocs = 10; + { + afs_int32 preallocs; + + /* + * We want to also reserve space for the gnode struct which is associated + * with each vnode (vcache) one; we want to use the pinned pool for them + * since they're referenced at interrupt level. + */ + if (afs_stats_cmperf.SmallBlocksAlloced + astatSize < 3600) + preallocs = astatSize; + else { + preallocs = 3600 - afs_stats_cmperf.SmallBlocksAlloced; + if (preallocs <= 0) + preallocs = 10; + } + osi_AllocMoreSSpace(preallocs); } - osi_AllocMoreSSpace(preallocs); #endif /* * create volume list structure */ - if ( aVolumes < 50 ) aVolumes = 50; - if (aVolumes > 3000) aVolumes = 3000; - - tv = (struct volume *) afs_osi_Alloc(aVolumes * sizeof(struct volume)); - for (i=0;i 3000) + aVolumes = 3000; + + tv = (struct volume *)afs_osi_Alloc(aVolumes * sizeof(struct volume)); + for (i = 0; i < aVolumes - 1; i++) + tv[i].next = &tv[i + 1]; + tv[aVolumes - 1].next = NULL; afs_freeVolList = Initialafs_freeVolList = tv; afs_memvolumes = aVolumes; @@ -225,8 +150,13 @@ afs_CacheInit(astatSize, afiles, ablocks, aDentries, aVolumes, achunk, aflags, afs_cacheStats = astatSize; afs_vcacheInit(astatSize); afs_dcacheInit(afiles, ablocks, aDentries, achunk, aflags); +#ifdef AFS_64BIT_CLIENT +#ifdef AFS_VM_RDWR_ENV + afs_vmMappingEnd = AFS_CHUNKBASE(0x7fffffff); +#endif /* AFS_VM_RDWR_ENV */ +#endif /* AFS_64BIT_CLIENT */ -#if defined(AFS_AIX_ENV) +#if defined(AFS_AIX_ENV) && !defined(AFS_AIX51_ENV) { static void afs_procsize_init(void); @@ -242,13 +172,13 @@ afs_CacheInit(astatSize, afiles, ablocks, aDentries, aVolumes, achunk, aflags, cm_initParams.cmi_nVolumeCaches = aVolumes; cm_initParams.cmi_firstChunkSize = AFS_FIRSTCSIZE; cm_initParams.cmi_otherChunkSize = AFS_OTHERCSIZE; - cm_initParams.cmi_cacheSize = ablocks; + cm_initParams.cmi_cacheSize = afs_cacheBlocks; cm_initParams.cmi_setTime = afs_setTime; cm_initParams.cmi_memCache = (aflags & AFSCALL_INIT_MEMCACHE) ? 1 : 0; return 0; -} /*afs_CacheInit*/ +} /*afs_CacheInit */ /* @@ -262,17 +192,15 @@ afs_CacheInit(astatSize, afiles, ablocks, aDentries, aVolumes, achunk, aflags, */ void -afs_ComputeCacheParms() - -{ /*afs_ComputeCacheParms*/ - +afs_ComputeCacheParms(void) +{ register afs_int32 i; afs_int32 afs_maxCacheDirty; /* * Don't allow more than 2/3 of the files in the cache to be dirty. */ - afs_maxCacheDirty = (2*afs_cacheFiles) / 3; + afs_maxCacheDirty = (2 * afs_cacheFiles) / 3; /* * Also, don't allow more than 2/3 of the total space get filled @@ -283,84 +211,115 @@ afs_ComputeCacheParms() */ if (afs_cacheBlocks & 0xffe00000) { i = afs_cacheBlocks / (AFS_FIRSTCSIZE >> 10); - } - else { + } else { i = (afs_cacheBlocks << 10) / AFS_FIRSTCSIZE; } - i = (2*i) / 3; + i = (2 * i) / 3; if (afs_maxCacheDirty > i) afs_maxCacheDirty = i; if (afs_maxCacheDirty < 1) afs_maxCacheDirty = 1; afs_stats_cmperf.cacheMaxDirtyChunks = afs_maxCacheDirty; -} /*afs_ComputeCacheParms*/ +} /*afs_ComputeCacheParms */ /* - * afs_InitVolumeInfo - * - * Description: - * Set up the volume info storage file. + * LookupInodeByPath * - * Parameters: - * afile : the file to be declared to be the volume info storage - * file for AFS. It must be already truncated to 0 length. - * - * Environment: - * This function is called only during initialization. - * - * WARNING: Data will be written to this file over time by AFS. + * Look up inode given a file name. + * Optionally return the vnode too. + * If the vnode is not returned, we rele it. */ - -static int LookupInodeByPath(char *filename, ino_t *inode) +static int +LookupInodeByPath(char *filename, ino_t * inode, struct vnode **fvpp) { afs_int32 code; - + #ifdef AFS_LINUX22_ENV struct dentry *dp; code = gop_lookupname(filename, AFS_UIOSYS, 0, NULL, &dp); - if (code) return code; + if (code) + return code; *inode = dp->d_inode->i_ino; dput(dp); #else struct vnode *filevp; code = gop_lookupname(filename, AFS_UIOSYS, 0, NULL, &filevp); - if (code) return code; + if (code) + return code; *inode = afs_vnodeToInumber(filevp); -#ifdef AFS_DEC_ENV - grele(filevp); + if (fvpp) + *fvpp = filevp; + else { +#if defined(AFS_DEC_ENV) + grele(filevp); #else - AFS_RELE((struct vnode *)filevp); + AFS_RELE(filevp); #endif + } #endif /* AFS_LINUX22_ENV */ - + return 0; - } - -int afs_InitCellInfo(char *afile) +} + +int +afs_InitCellInfo(char *afile) { ino_t inode; int code; - - code = LookupInodeByPath(afile, &inode); + + code = LookupInodeByPath(afile, &inode, NULL); return afs_cellname_init(inode, code); } - -int afs_InitVolumeInfo(char *afile) + +/* + * afs_InitVolumeInfo + * + * Description: + * Set up the volume info storage file. + * + * Parameters: + * afile : the file to be declared to be the volume info storage + * file for AFS. It must be already truncated to 0 length. + * + * Environment: + * This function is called only during initialization. + * + * WARNING: Data will be written to this file over time by AFS. + */ + +int +afs_InitVolumeInfo(char *afile) { int code; struct osi_file *tfile; - struct vnode *filevp; - + AFS_STATCNT(afs_InitVolumeInfo); - code = LookupInodeByPath(afile, &volumeInode); - if (code) return code; +#if defined(AFS_XBSD_ENV) + /* + * On Open/Free/NetBSD, we can get into big trouble if we don't hold the volume file + * vnode. SetupVolume holds afs_xvolume lock exclusive. + * SetupVolume->GetVolSlot->UFSGetVolSlot->{GetVolCache or WriteVolCache} + * ->osi_UFSOpen->VFS_VGET()->ffs_vget->getnewvnode->vgone on some vnode. + * If it's AFS, then ->vclean->afs_nbsd_reclaim->FlushVCache->QueueVCB-> + * GetVolume->FindVolume-> waits on afs_xvolume lock ! + * + * In general, anything that's called with afs_xvolume locked must not + * end up calling getnewvnode(). The only cases I've found so far + * are things which try to get the volumeInode, and since we keep + * it in the cache... + */ + code = LookupInodeByPath(afile, &volumeInode, &volumeVnode); +#else + code = LookupInodeByPath(afile, &volumeInode, NULL); +#endif + if (code) + return code; tfile = afs_CFileOpen(volumeInode); afs_CFileTruncate(tfile, 0); afs_CFileClose(tfile); return 0; - -} /*afs_InitVolumeInfo*/ +} /* * afs_InitCacheInfo @@ -385,11 +344,9 @@ int afs_InitVolumeInfo(char *afile) * code. * */ -afs_InitCacheInfo(afile) - register char *afile; - -{ /*afs_InitCacheInfo*/ - +int +afs_InitCacheInfo(register char *afile) +{ register afs_int32 code; struct osi_stat tstat; register struct osi_file *tfile; @@ -398,86 +355,80 @@ afs_InitCacheInfo(afile) int goodFile; AFS_STATCNT(afs_InitCacheInfo); - if(cacheDiskType != AFS_FCACHE_TYPE_UFS) + if (cacheDiskType != AFS_FCACHE_TYPE_UFS) osi_Panic("afs_InitCacheInfo --- called for non-ufs cache!"); #ifdef AFS_LINUX22_ENV code = osi_InitCacheInfo(afile); - if (code) return code; + if (code) + return code; #else - code = gop_lookupname(afile, AFS_UIOSYS, 0, (struct vnode **) 0, &filevp); - if (code || !filevp) return ENOENT; + code = gop_lookupname(afile, AFS_UIOSYS, 0, NULL, &filevp); + if (code || !filevp) + return ENOENT; { #if defined(AFS_SUN56_ENV) - struct statvfs64 st; -#else -#if defined(AFS_HPUX102_ENV) - struct k_statvfs st; + struct statvfs64 st; +#elif defined(AFS_HPUX102_ENV) + struct k_statvfs st; +#elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) ||defined(AFS_HPUX100_ENV) + struct statvfs st; +#elif defined(AFS_DUX40_ENV) + struct nstatfs st; #else -#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) ||defined(AFS_HPUX100_ENV) - struct statvfs st; -#else -#if defined(AFS_DUX40_ENV) - struct nstatfs st; -#else - struct statfs st; -#endif /* DUX40 */ -#endif /* SUN5 SGI */ -#endif /* HP 10.20 */ + struct statfs st; #endif /* SUN56 */ #if defined(AFS_SGI_ENV) #ifdef AFS_SGI65_ENV - VFS_STATVFS(filevp->v_vfsp, &st, (struct vnode *)0, code); - if (!code) + VFS_STATVFS(filevp->v_vfsp, &st, NULL, code); + if (!code) #else - if (!VFS_STATFS(filevp->v_vfsp, &st, (struct vnode *)0)) + if (!VFS_STATFS(filevp->v_vfsp, &st, NULL)) #endif /* AFS_SGI65_ENV */ -#else /* AFS_SGI_ENV */ -#if defined(AFS_SUN5_ENV) || defined(AFS_HPUX100_ENV) - if (!VFS_STATVFS(filevp->v_vfsp, &st)) -#else -#ifdef AFS_OSF_ENV - - VFS_STATFS(filevp->v_vfsp, code); - /* struct copy */ - st = filevp->v_vfsp->m_stat; - if (code == 0) -#else /* AFS_OSF_ENV */ -#ifdef AFS_AIX41_ENV - if (!VFS_STATFS(filevp->v_vfsp, &st, &afs_osi_cred)) -#else -#ifdef AFS_LINUX20_ENV - { - KERNEL_SPACE_DECL; - TO_USER_SPACE(); - - VFS_STATFS(filevp->v_vfsp, &st); - TO_KERNEL_SPACE(); - } +#elif defined(AFS_SUN5_ENV) || defined(AFS_HPUX100_ENV) + if (!VFS_STATVFS(filevp->v_vfsp, &st)) +#elif defined(AFS_OSF_ENV) + + VFS_STATFS(filevp->v_vfsp, code); + /* struct copy */ + st = filevp->v_vfsp->m_stat; + if (code == 0) +#elif defined(AFS_AIX41_ENV) + if (!VFS_STATFS(filevp->v_vfsp, &st, &afs_osi_cred)) +#elif defined(AFS_LINUX20_ENV) + { + KERNEL_SPACE_DECL; + TO_USER_SPACE(); + + VFS_STATFS(filevp->v_vfsp, &st); + TO_KERNEL_SPACE(); + } +#elif defined(AFS_DARWIN_ENV) + if (!VFS_STATFS(filevp->v_mount, &st, current_proc())) +#elif defined(AFS_FBSD50_ENV) + if (!VFS_STATFS(filevp->v_mount, &st, curthread)) +#elif defined(AFS_XBSD_ENV) + if (!VFS_STATFS(filevp->v_mount, &st, curproc)) #else -#if defined(AFS_DARWIN_ENV) - if (!VFS_STATFS(filevp->v_mount, &st, current_proc())) -#else -#if defined(AFS_FBSD_ENV) - if (!VFS_STATFS(filevp->v_mount, &st, curproc)) -#else - if (!VFS_STATFS(filevp->v_vfsp, &st)) -#endif /* AFS_FBSD_ENV */ -#endif /* AFS_DARWIN_ENV */ -#endif /* AFS_LINUX20_ENV */ -#endif /* AIX41 */ -#endif /* OSF */ -#endif /* SUN5 HP10 */ -#endif /* SGI */ + if (!VFS_STATFS(filevp->v_vfsp, &st)) +#endif /* SGI... */ #if defined(AFS_SUN5_ENV) || defined(AFS_HPUX100_ENV) - afs_fsfragsize = st.f_frsize - 1; + afs_fsfragsize = st.f_frsize - 1; #else - afs_fsfragsize = st.f_bsize - 1; + afs_fsfragsize = st.f_bsize - 1; #endif } -#ifdef AFS_LINUX20_ENV +#if defined(AFS_LINUX20_ENV) cacheInode = filevp->i_ino; afs_cacheSBp = filevp->i_sb; +#elif defined(AFS_XBSD_ENV) + cacheInode = VTOI(filevp)->i_number; + cacheDev.mp = filevp->v_mount; + cacheDev.held_vnode = filevp; + vref(filevp); /* Make sure mount point stays busy. XXX */ +#if !defined(AFS_OBSD_ENV) + afs_cacheVfsp = filevp->v_vfsp; +#endif #else #if defined(AFS_SGI62_ENV) || defined(AFS_HAVE_VXFS) || defined(AFS_DARWIN_ENV) afs_InitDualFSCacheOps(filevp); @@ -486,7 +437,7 @@ afs_InitCacheInfo(afile) cacheDev.dev = afs_vnodeToDev(filevp); afs_cacheVfsp = filevp->v_vfsp; #endif /* AFS_LINUX20_ENV */ - AFS_RELE((struct vnode *)filevp); + AFS_RELE(filevp); #endif /* AFS_LINUX22_ENV */ tfile = osi_UFSOpen(cacheInode); afs_osi_Stat(tfile, &tstat); @@ -495,11 +446,10 @@ afs_InitCacheInfo(afile) goodFile = 0; if (code == sizeof(theader)) { /* read the header correctly */ - if (theader.magic == AFS_FHMAGIC && - theader.firstCSize == AFS_FIRSTCSIZE && - theader.otherCSize == AFS_OTHERCSIZE && - theader.version == AFS_CI_VERSION - ) + if (theader.magic == AFS_FHMAGIC + && theader.firstCSize == AFS_FIRSTCSIZE + && theader.otherCSize == AFS_OTHERCSIZE + && theader.version == AFS_CI_VERSION) goodFile = 1; } if (!goodFile) { @@ -522,12 +472,11 @@ afs_InitCacheInfo(afile) */ afs_cacheInodep = (struct osi_file *)tfile; return 0; - -} /*afs_InitCacheInfo*/ +} int afs_resourceinit_flag = 0; -afs_ResourceInit(preallocs) - int preallocs; +int +afs_ResourceInit(int preallocs) { register afs_int32 i; static struct rx_securityClass *secobj; @@ -540,35 +489,37 @@ afs_ResourceInit(preallocs) RWLOCK_INIT(&afs_icl_lock, "afs_icl_lock"); RWLOCK_INIT(&afs_xinterface, "afs_xinterface"); LOCK_INIT(&afs_puttofileLock, "afs_puttofileLock"); +#ifndef AFS_FBSD_ENV #ifndef AFS_AIX32_ENV LOCK_INIT(&osi_fsplock, "osi_fsplock"); #endif LOCK_INIT(&osi_flplock, "osi_flplock"); +#endif RWLOCK_INIT(&afs_xconn, "afs_xconn"); afs_CellInit(); - afs_InitCBQueue(1); /* initialize callback queues */ + afs_InitCBQueue(1); /* initialize callback queues */ if (afs_resourceinit_flag == 0) { afs_resourceinit_flag = 1; - for (i=0;i 256) && (preallocs < 3600)) - afs_preallocs = preallocs; - osi_AllocMoreSSpace(afs_preallocs); - osi_AllocMoreMSpace(100); - } + if ((preallocs > 256) && (preallocs < 3600)) + afs_preallocs = preallocs; + osi_AllocMoreSSpace(afs_preallocs); + osi_AllocMoreMSpace(100); + } #endif } - + secobj = rxnull_NewServerSecurityObject(); afs_server = rx_NewService(0, 1, "afs", &secobj, 1, RXAFSCB_ExecuteRequest); @@ -579,9 +530,9 @@ afs_ResourceInit(preallocs) afs_osi_Wakeup(&afs_server); /* wakeup anyone waiting for it */ return 0; -} /*afs_ResourceInit*/ +} /*afs_ResourceInit */ -#if defined(AFS_AIX_ENV) +#if defined(AFS_AIX_ENV) && !defined(AFS_AIX51_ENV) /* * AIX dynamic sizeof(struct proc) @@ -626,8 +577,11 @@ afs_ResourceInit(preallocs) static void afs_procsize_init(void) { - struct proc *p0; /* pointer to process 0 */ - struct proc *pN; /* pointer to process 0's first child */ + struct proc *p0; /* pointer to process 0 */ + struct proc *pN; /* pointer to process 0's first child */ +#ifdef AFS_AIX51_ENV + struct pvproc *pV; +#endif int pN_index; ptrdiff_t pN_offset; int procsize; @@ -637,8 +591,17 @@ afs_procsize_init(void) afs_gcpags = AFS_GCPAGS_EPROC0; return; } - +#ifdef AFS_AIX51_ENV + pN = (struct proc *)0; + pV = p0->p_pvprocp; + if (pV) { + pV = pV->pv_child; + if (pV) + pN = pV->pv_procp; + } +#else pN = p0->p_child; +#endif if (!pN) { afs_gcpags = AFS_GCPAGS_EPROCN; return; @@ -675,7 +638,6 @@ afs_procsize_init(void) afs_gcpags_procsize = procsize; } - #endif /* @@ -691,184 +653,181 @@ afs_procsize_init(void) * Nothing interesting. */ void -shutdown_cache() - -{ /*shutdown_cache*/ - register struct afs_cbr *tsp, *nsp; - extern int afs_cold_shutdown; - extern int pagCounter; - int i; - - AFS_STATCNT(shutdown_cache); - afs_WriteThroughDSlots(); - if (afs_cold_shutdown) { - afs_cacheinit_flag = 0; - shutdown_dcache(); - shutdown_vcache(); - - afs_cacheStats = 0; - afs_cacheFiles = afs_cacheBlocks = 0; - pag_epoch = maxIHint = nihints = usedihint = 0; - pagCounter = 0; - cacheInode = volumeInode = (ino_t)0; - +shutdown_cache(void) +{ + AFS_STATCNT(shutdown_cache); + afs_WriteThroughDSlots(); + if (afs_cold_shutdown) { + afs_cacheinit_flag = 0; + shutdown_dcache(); + shutdown_vcache(); + + afs_cacheStats = 0; + afs_cacheFiles = afs_cacheBlocks = 0; + pag_epoch = maxIHint = nihints = usedihint = 0; + pagCounter = 0; +#if defined(AFS_XBSD_ENV) + vrele(volumeVnode); /* let it go, finally. */ + volumeVnode = NULL; + if (cacheDev.held_vnode) { + vrele(cacheDev.held_vnode); + cacheDev.held_vnode = NULL; + } +#endif + cacheInode = volumeInode = (ino_t) 0; - cacheInfoModTime = 0; + cacheInfoModTime = 0; - afs_fsfragsize = 1023; - memset((char *)&afs_stats_cmperf, 0, sizeof(afs_stats_cmperf)); - memset((char *)&cacheDev, 0, sizeof(struct osi_dev)); - osi_dnlc_shutdown(); - } -} /*shutdown_cache*/ + afs_fsfragsize = 1023; + memset((char *)&afs_stats_cmperf, 0, sizeof(afs_stats_cmperf)); + memset((char *)&cacheDev, 0, sizeof(struct osi_dev)); + osi_dnlc_shutdown(); + } +} /*shutdown_cache */ -void shutdown_vnodeops() +void +shutdown_vnodeops(void) { - extern int afs_cold_shutdown; -#ifndef AFS_LINUX20_ENV - extern int afs_rd_stash_i; -#endif -#ifndef AFS_SUN5_ENV - extern int lastWarnTime; -#endif #if !defined(AFS_SGI_ENV) && !defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV) struct buf *afs_bread_freebp = 0; #endif - + AFS_STATCNT(shutdown_vnodeops); if (afs_cold_shutdown) { -#ifndef AFS_SUN5_ENV /* XXX */ - lastWarnTime = 0; +#ifndef AFS_SUN5_ENV /* XXX */ + lastWarnTime = 0; #endif #ifndef AFS_LINUX20_ENV - afs_rd_stash_i = 0; + afs_rd_stash_i = 0; #endif #if !defined(AFS_SGI_ENV) && !defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV) - afs_bread_freebp = 0; + afs_bread_freebp = 0; #endif - shutdown_mariner(); - } + shutdown_mariner(); + } } -void shutdown_AFS() - +void +shutdown_AFS(void) { int i; register struct srvAddr *sa; - extern int afs_cold_shutdown; AFS_STATCNT(shutdown_AFS); if (afs_cold_shutdown) { - afs_resourceinit_flag = 0; - /* - * Free Volumes table allocations - */ - { - struct volume *tv; - for (i = 0; i < NVOLS; i++) { - for (tv = afs_volumes[i]; tv; tv = tv->next) { - if (tv->name) { - afs_osi_Free(tv->name, strlen(tv->name)+1); - tv->name = 0; + afs_resourceinit_flag = 0; + /* + * Free Volumes table allocations + */ + { + struct volume *tv; + for (i = 0; i < NVOLS; i++) { + for (tv = afs_volumes[i]; tv; tv = tv->next) { + if (tv->name) { + afs_osi_Free(tv->name, strlen(tv->name) + 1); + tv->name = 0; + } } + afs_volumes[i] = 0; } - afs_volumes[i] = 0; } - } - - /* - * Free FreeVolList allocations - */ - afs_osi_Free(Initialafs_freeVolList, afs_memvolumes * sizeof(struct volume)); - afs_freeVolList = Initialafs_freeVolList = 0; - - /* XXX HACK fort MEM systems XXX - * - * For -memcache cache managers when we run out of free in memory volumes - * we simply malloc more; we won't be able to free those additional volumes. - */ - - - - /* - * Free Users table allocation - */ - { - struct unixuser *tu, *ntu; - for (i=0; i < NUSERS; i++) { - for (tu=afs_users[i]; tu; tu = ntu) { - ntu = tu->next; - if (tu->stp) - afs_osi_Free(tu->stp, tu->stLen); - if (tu->exporter) - EXP_RELE(tu->exporter); - afs_osi_Free(tu, sizeof(struct unixuser)); + + /* + * Free FreeVolList allocations + */ + afs_osi_Free(Initialafs_freeVolList, + afs_memvolumes * sizeof(struct volume)); + afs_freeVolList = Initialafs_freeVolList = 0; + + /* XXX HACK fort MEM systems XXX + * + * For -memcache cache managers when we run out of free in memory volumes + * we simply malloc more; we won't be able to free those additional volumes. + */ + + + + /* + * Free Users table allocation + */ + { + struct unixuser *tu, *ntu; + for (i = 0; i < NUSERS; i++) { + for (tu = afs_users[i]; tu; tu = ntu) { + ntu = tu->next; + if (tu->stp) + afs_osi_Free(tu->stp, tu->stLen); + if (tu->exporter) + EXP_RELE(tu->exporter); + afs_osi_Free(tu, sizeof(struct unixuser)); + } + afs_users[i] = 0; } - afs_users[i] = 0; } - } - - /* - * Free Servers table allocation - */ - { - struct server *ts, *nts; - struct conn *tc, *ntc; - register struct afs_cbr *tcbrp, *tbrp; - struct afs_cbr **lcbrpp; - - for (i=0; i < NSERVERS; i++) { - for (ts = afs_servers[i]; ts; ts = nts) { - nts = ts->next; - for (sa = ts->addr; sa; sa = sa->next_sa) { - if (sa->conns) { + + /* + * Free Servers table allocation + */ + { + struct server *ts, *nts; + struct conn *tc, *ntc; + register struct afs_cbr *tcbrp, *tbrp; + + for (i = 0; i < NSERVERS; i++) { + for (ts = afs_servers[i]; ts; ts = nts) { + nts = ts->next; + for (sa = ts->addr; sa; sa = sa->next_sa) { + if (sa->conns) { + /* + * Free all server's connection structs + */ + tc = sa->conns; + while (tc) { + ntc = tc->next; + AFS_GUNLOCK(); + rx_DestroyConnection(tc->id); + AFS_GLOCK(); + afs_osi_Free(tc, sizeof(struct conn)); + tc = ntc; + } + } + } + for (tcbrp = ts->cbrs; tcbrp; tcbrp = tbrp) { /* - * Free all server's connection structs + * Free all server's callback structs */ - tc = sa->conns; - while (tc) { - ntc = tc->next; - AFS_GUNLOCK(); - rx_DestroyConnection(tc->id); - AFS_GLOCK(); - afs_osi_Free(tc, sizeof(struct conn)); - tc = ntc; - } + tbrp = tcbrp->next; + afs_FreeCBR(tcbrp); } + afs_osi_Free(ts, sizeof(struct server)); } - for (tcbrp = ts->cbrs; tcbrp; tcbrp = tbrp) { - /* - * Free all server's callback structs - */ - tbrp = tcbrp->next; - afs_FreeCBR(tcbrp); - } - afs_osi_Free(ts, sizeof(struct server)); + afs_servers[i] = 0; } - afs_servers[i] = 0; } - } - for (i=0; i -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_lock.c,v 1.1.1.4 2001/07/14 22:19:22 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_lock.c,v 1.9 2003/07/15 23:14:12 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif - -int afs_trclock=0; +/* probably needed if lock_trace is enabled - should ifdef */ +int afs_trclock = 0; void Lock_Obtain(); void Lock_ReleaseR(); void Lock_ReleaseW(); -void Lock_Init(lock) - register struct afs_lock *lock; +void +Lock_Init(register struct afs_lock *lock) { AFS_STATCNT(Lock_Init); - lock -> readers_reading = 0; - lock -> excl_locked = 0; - lock -> wait_states = 0; - lock -> num_waiting = 0; + lock->readers_reading = 0; + lock->excl_locked = 0; + lock->wait_states = 0; + lock->num_waiting = 0; #if defined(INSTRUMENT_LOCKS) lock->pid_last_reader = 0; lock->pid_writer = 0; @@ -63,24 +57,23 @@ void Lock_Init(lock) lock->time_waiting.tv_usec = 0; } -void ObtainLock(lock, how, src_indicator) - register struct afs_lock *lock; - int how; - unsigned int src_indicator; +void +ObtainLock(register struct afs_lock *lock, int how, + unsigned int src_indicator) { switch (how) { - case READ_LOCK: + case READ_LOCK: if (!((lock)->excl_locked & WRITE_LOCK)) - (lock) -> readers_reading++; + (lock)->readers_reading++; else Afs_Lock_Obtain(lock, READ_LOCK); #if defined(INSTRUMENT_LOCKS) (lock)->pid_last_reader = MyPidxx; #endif /* INSTRUMENT_LOCKS */ break; - case WRITE_LOCK: + case WRITE_LOCK: if (!(lock)->excl_locked && !(lock)->readers_reading) - (lock) -> excl_locked = WRITE_LOCK; + (lock)->excl_locked = WRITE_LOCK; else Afs_Lock_Obtain(lock, WRITE_LOCK); #if defined(INSTRUMENT_LOCKS) @@ -88,9 +81,9 @@ void ObtainLock(lock, how, src_indicator) (lock)->src_indicator = src_indicator; #endif /* INSTRUMENT_LOCKS */ break; - case SHARED_LOCK: + case SHARED_LOCK: if (!(lock)->excl_locked) - (lock) -> excl_locked = SHARED_LOCK; + (lock)->excl_locked = SHARED_LOCK; else Afs_Lock_Obtain(lock, SHARED_LOCK); #if defined(INSTRUMENT_LOCKS) @@ -98,126 +91,130 @@ void ObtainLock(lock, how, src_indicator) (lock)->src_indicator = src_indicator; #endif /* INSTRUMENT_LOCKS */ break; - } + } } -void ReleaseLock(lock, how) - register struct afs_lock *lock; - int how; +void +ReleaseLock(register struct afs_lock *lock, int how) { if (how == READ_LOCK) { - if (!--lock->readers_reading && lock->wait_states) - { + if (!--lock->readers_reading && lock->wait_states) { #if defined(INSTRUMENT_LOCKS) - if ( lock->pid_last_reader == MyPidxx ) + if (lock->pid_last_reader == MyPidxx) lock->pid_last_reader = 0; #endif /* INSTRUMENT_LOCKS */ - Afs_Lock_ReleaseW(lock); + Afs_Lock_ReleaseW(lock); } } else if (how == WRITE_LOCK) { lock->excl_locked &= ~WRITE_LOCK; #if defined(INSTRUMENT_LOCKS) lock->pid_writer = 0; #endif /* INSTRUMENT_LOCKS */ - if (lock->wait_states) Afs_Lock_ReleaseR(lock); + if (lock->wait_states) + Afs_Lock_ReleaseR(lock); } else if (how == SHARED_LOCK) { lock->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK); #if defined(INSTRUMENT_LOCKS) lock->pid_writer = 0; #endif /* INSTRUMENT_LOCKS */ - if (lock->wait_states) Afs_Lock_ReleaseR(lock); + if (lock->wait_states) + Afs_Lock_ReleaseR(lock); } } -Afs_Lock_Obtain(lock, how) - register struct afs_lock *lock; - int how; +void +Afs_Lock_Obtain(register struct afs_lock *lock, int how) { osi_timeval_t tt1, tt2, et; + afs_uint32 us; AFS_STATCNT(Lock_Obtain); - + AFS_ASSERT_GLOCK(); osi_GetuTime(&tt1); - + switch (how) { - case READ_LOCK: lock->num_waiting++; - do { - lock -> wait_states |= READ_LOCK; - afs_osi_Sleep(&lock->readers_reading); - } while (lock->excl_locked & WRITE_LOCK); - lock->num_waiting--; - lock->readers_reading++; - break; - - case WRITE_LOCK: lock->num_waiting++; - do { - lock -> wait_states |= WRITE_LOCK; - afs_osi_Sleep(&lock->excl_locked); - } while (lock->excl_locked || lock->readers_reading); - lock->num_waiting--; - lock->excl_locked = WRITE_LOCK; - break; - - case SHARED_LOCK: lock->num_waiting++; - do { - lock->wait_states |= SHARED_LOCK; - afs_osi_Sleep(&lock->excl_locked); - } while (lock->excl_locked); - lock->num_waiting--; - lock->excl_locked = SHARED_LOCK; - break; - - case BOOSTED_LOCK: lock->num_waiting++; - do { - lock->wait_states |= WRITE_LOCK; - afs_osi_Sleep(&lock->excl_locked); - } while (lock->readers_reading); - lock->num_waiting--; - lock->excl_locked = WRITE_LOCK; - break; - - default: osi_Panic("afs locktype"); + case READ_LOCK: + lock->num_waiting++; + do { + lock->wait_states |= READ_LOCK; + afs_osi_Sleep(&lock->readers_reading); + } while (lock->excl_locked & WRITE_LOCK); + lock->num_waiting--; + lock->readers_reading++; + break; + + case WRITE_LOCK: + lock->num_waiting++; + do { + lock->wait_states |= WRITE_LOCK; + afs_osi_Sleep(&lock->excl_locked); + } while (lock->excl_locked || lock->readers_reading); + lock->num_waiting--; + lock->excl_locked = WRITE_LOCK; + break; + + case SHARED_LOCK: + lock->num_waiting++; + do { + lock->wait_states |= SHARED_LOCK; + afs_osi_Sleep(&lock->excl_locked); + } while (lock->excl_locked); + lock->num_waiting--; + lock->excl_locked = SHARED_LOCK; + break; + + case BOOSTED_LOCK: + lock->num_waiting++; + do { + lock->wait_states |= WRITE_LOCK; + afs_osi_Sleep(&lock->excl_locked); + } while (lock->readers_reading); + lock->num_waiting--; + lock->excl_locked = WRITE_LOCK; + break; + + default: + osi_Panic("afs locktype"); } osi_GetuTime(&tt2); afs_stats_GetDiff(et, tt1, tt2); afs_stats_AddTo((lock->time_waiting), et); + us = (et.tv_sec << 20) + et.tv_usec; if (afs_trclock) { - afs_Trace2(afs_iclSetp, CM_TRACE_LOCKSLEPT, ICL_TYPE_POINTER, lock, - ICL_TYPE_INT32, how); + afs_Trace3(afs_iclSetp, CM_TRACE_LOCKSLEPT, ICL_TYPE_INT32, us, + ICL_TYPE_POINTER, lock, ICL_TYPE_INT32, how); } } /* release a lock, giving preference to new readers */ -Afs_Lock_ReleaseR(lock) - register struct afs_lock *lock; +void +Afs_Lock_ReleaseR(register struct afs_lock *lock) { AFS_STATCNT(Lock_ReleaseR); AFS_ASSERT_GLOCK(); if (lock->wait_states & READ_LOCK) { lock->wait_states &= ~READ_LOCK; afs_osi_Wakeup(&lock->readers_reading); - } - else { + } else { lock->wait_states &= ~EXCL_LOCKS; afs_osi_Wakeup(&lock->excl_locked); } } /* release a lock, giving preference to new writers */ -Afs_Lock_ReleaseW(lock) - register struct afs_lock *lock; +void +Afs_Lock_ReleaseW(register struct afs_lock *lock) { AFS_STATCNT(Lock_ReleaseW); AFS_ASSERT_GLOCK(); if (lock->wait_states & EXCL_LOCKS) { lock->wait_states &= ~EXCL_LOCKS; afs_osi_Wakeup(&lock->excl_locked); - } - else { + } else { lock->wait_states &= ~READ_LOCK; afs_osi_Wakeup(&lock->readers_reading); } @@ -225,8 +222,8 @@ Afs_Lock_ReleaseW(lock) /* Wait for some change in the lock status. -Lock_Wait(lock) - register struct afs_lock *lock; { +void Lock_Wait(register struct afs_lock *lock) +{ AFS_STATCNT(Lock_Wait); if (lock->readers_reading || lock->excl_locked) return 1; lock->wait_states |= READ_LOCK; @@ -240,27 +237,27 @@ Lock_Wait(lock) */ /* release a write lock and sleep on an address, atomically */ -afs_osi_SleepR(addr, alock) -register char *addr; -register struct afs_lock *alock; { +void +afs_osi_SleepR(register char *addr, register struct afs_lock *alock) +{ AFS_STATCNT(osi_SleepR); ReleaseReadLock(alock); afs_osi_Sleep(addr); } /* release a write lock and sleep on an address, atomically */ -afs_osi_SleepW(addr, alock) -register char *addr; -register struct afs_lock *alock; { +void +afs_osi_SleepW(register char *addr, register struct afs_lock *alock) +{ AFS_STATCNT(osi_SleepW); ReleaseWriteLock(alock); afs_osi_Sleep(addr); } /* release a write lock and sleep on an address, atomically */ -afs_osi_SleepS(addr, alock) -register char *addr; -register struct afs_lock *alock; { +void +afs_osi_SleepS(register char *addr, register struct afs_lock *alock) +{ AFS_STATCNT(osi_SleepS); ReleaseSharedLock(alock); afs_osi_Sleep(addr); @@ -271,40 +268,39 @@ register struct afs_lock *alock; { /* operations on locks that don't mind if we lock the same thing twice. I'd like to dedicate this function to Sun Microsystems' Version 4.0 virtual memory system, without which this wouldn't have been necessary */ -void afs_BozonLock(alock, avc) -struct vcache *avc; -struct afs_bozoLock *alock; { +void +afs_BozonLock(struct afs_bozoLock *alock, struct vcache *avc) +{ AFS_STATCNT(afs_BozonLock); while (1) { if (alock->count == 0) { /* lock not held, we win */ #ifdef AFS_SUN5_ENV - alock->proc = (char *) ttoproc(curthread); + alock->proc = (char *)ttoproc(curthread); #else #ifdef AFS_64BITPOINTER_ENV /* To shut up SGI compiler on remark(1413) warnings. */ - alock->proc = (char *) (long)MyPidxx; + alock->proc = (char *)(long)MyPidxx; #else /* AFS_64BITPOINTER_ENV */ - alock->proc = (char *) MyPidxx; + alock->proc = (char *)MyPidxx; #endif /* AFS_64BITPOINTER_ENV */ #endif alock->count = 1; return; #ifdef AFS_SUN5_ENV - } else if (alock->proc == (char *) ttoproc(curthread)) { + } else if (alock->proc == (char *)ttoproc(curthread)) { #else #ifdef AFS_64BITPOINTER_ENV - /* To shut up SGI compiler on remark(1413) warnings. */ - } else if (alock->proc == (char *) (long)MyPidxx) { + /* To shut up SGI compiler on remark(1413) warnings. */ + } else if (alock->proc == (char *)(long)MyPidxx) { #else /* AFS_64BITPOINTER_ENV */ - } else if (alock->proc == (char *) MyPidxx) { + } else if (alock->proc == (char *)MyPidxx) { #endif /* AFS_64BITPOINTER_ENV */ #endif /* lock is held, but by us, so we win anyway */ alock->count++; return; - } - else { + } else { /* lock is held, and not by us; we wait */ alock->flags |= AFS_BOZONWAITING; afs_osi_Sleep(alock); @@ -313,9 +309,9 @@ struct afs_bozoLock *alock; { } /* releasing the same type of lock as defined above */ -void afs_BozonUnlock(alock, avc) -struct vcache *avc; -struct afs_bozoLock *alock; { +void +afs_BozonUnlock(struct afs_bozoLock *alock, struct vcache *avc) +{ AFS_STATCNT(afs_BozonUnlock); if (alock->count <= 0) osi_Panic("BozoUnlock"); @@ -327,38 +323,71 @@ struct afs_bozoLock *alock; { } } -void afs_BozonInit(alock, avc) -struct vcache *avc; -struct afs_bozoLock *alock; { +void +afs_BozonInit(struct afs_bozoLock *alock, struct vcache *avc) +{ AFS_STATCNT(afs_BozonInit); alock->count = 0; alock->flags = 0; - alock->proc = (char *) 0; + alock->proc = NULL; } -afs_CheckBozonLock(alock) -struct afs_bozoLock *alock; { +int +afs_CheckBozonLock(struct afs_bozoLock *alock) +{ AFS_STATCNT(afs_CheckBozonLock); if (alock->count || (alock->flags & AFS_BOZONWAITING)) return 1; return 0; } -afs_CheckBozonLockBlocking(alock) -struct afs_bozoLock *alock; { +int +afs_CheckBozonLockBlocking(struct afs_bozoLock *alock) +{ AFS_STATCNT(afs_CheckBozonLockBlocking); if (alock->count || (alock->flags & AFS_BOZONWAITING)) #ifdef AFS_SUN5_ENV - if (alock->proc != (char *) ttoproc(curthread)) + if (alock->proc != (char *)ttoproc(curthread)) #else #ifdef AFS_64BITPOINTER_ENV - /* To shut up SGI compiler on remark(1413) warnings. */ - if (alock->proc != (char *) (long)MyPidxx) + /* To shut up SGI compiler on remark(1413) warnings. */ + if (alock->proc != (char *)(long)MyPidxx) #else /* AFS_64BITPOINTER_ENV */ - if (alock->proc != (char *) MyPidxx) + if (alock->proc != (char *)MyPidxx) #endif /* AFS_64BITPOINTER_ENV */ #endif return 1; return 0; } #endif + +/* Not static - used conditionally if lock tracing is enabled */ +int +Afs_Lock_Trace(int op, struct afs_lock *alock, int type, char *file, int line) +{ + int traceok; + struct afs_icl_log *tlp; + struct afs_icl_set *tsp; + + if (!afs_trclock) + return 1; + if ((alock) == &afs_icl_lock) + return 1; + + ObtainReadLock(&afs_icl_lock); + traceok = 1; + for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) + if ((alock) == &tlp->lock) + traceok = 0; + for (tsp = afs_icl_allSets; tsp; tsp = tsp->nextp) + if ((alock) == &tsp->lock) + traceok = 0; + ReleaseReadLock(&afs_icl_lock); + if (!traceok) + return 1; + + afs_Trace4(afs_iclSetp, op, ICL_TYPE_STRING, (long)file, ICL_TYPE_INT32, + (long)line, ICL_TYPE_POINTER, (long)alock, ICL_TYPE_LONG, + (long)type); + return 0; +} diff --git a/src/afs/afs_mariner.c b/src/afs/afs_mariner.c index e414700be..03ed409e1 100644 --- a/src/afs/afs_mariner.c +++ b/src/afs/afs_mariner.c @@ -14,20 +14,21 @@ * Implements: */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_mariner.c,v 1.1.1.5 2002/09/26 18:57:52 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_mariner.c,v 1.8 2003/07/15 23:14:12 shadow Exp $"); -#include "../afs/sysincludes.h" /*Standard vendor system headers*/ -#include "../afs/afsincludes.h" /*AFS-based standard headers*/ -#include "../afs/afs_stats.h" /* statistics */ +#include "afs/sysincludes.h" /*Standard vendor system headers */ +#include "afsincludes.h" /*AFS-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ /* Exported variables */ struct rx_service *afs_server; -#define SMAR 20 /* size of a mariner name */ -#define NMAR 10 /* number of mariner names */ +#define SMAR 20 /* size of a mariner name */ +#define NMAR 10 /* number of mariner names */ static char marinerNames[NMAR][SMAR]; static struct vcache *marinerVCs[NMAR]; static int marinerPtr = 0; /* pointer to next mariner slot to use */ @@ -36,9 +37,9 @@ static int marinerPtr = 0; /* pointer to next mariner slot to use */ afs_int32 afs_mariner = 0; afs_int32 afs_marinerHost = 0; -afs_AddMarinerName(aname, avc) - register char *aname; - register struct vcache *avc; { +int +afs_AddMarinerName(register char *aname, register struct vcache *avc) +{ register int i; register char *tp; @@ -50,16 +51,17 @@ afs_AddMarinerName(aname, avc) } tp = marinerNames[i]; strncpy(tp, aname, SMAR); - tp[SMAR-1] = 0; + tp[SMAR - 1] = 0; marinerVCs[i] = avc; return 0; } -char *afs_GetMariner(avc) - register struct vcache *avc; { +char * +afs_GetMariner(register struct vcache *avc) +{ register int i; AFS_STATCNT(afs_GetMariner); - for(i=0; isocket, &taddr, &dvec, 1, len, 0); + (void)osi_NetSend(afs_server->socket, &taddr, &dvec, 1, len, 0); AFS_GLOCK(); osi_FreeSmallSpace(tp1); -} /*afs_MarinerLogFetch*/ +} /*afs_MarinerLogFetch */ -void afs_MarinerLog(astring, avc) - register struct vcache *avc; - register char *astring; +void +afs_MarinerLog(register char *astring, register struct vcache *avc) { struct sockaddr_in taddr; register char *tp, *tp1, *buf; @@ -116,8 +117,8 @@ void afs_MarinerLog(astring, avc) taddr.sin_port = htons(2106); #ifdef STRUCT_SOCKADDR_HAS_SA_LEN taddr.sin_len = sizeof(taddr); -#endif /* STRUCT_SOCKADDR_HAS_SA_LEN */ - tp = buf = (char *) osi_AllocSmallSpace(AFS_SMALLOCSIZ); +#endif /* AFS_OSF_ENV */ + tp = buf = (char *)osi_AllocSmallSpace(AFS_SMALLOCSIZ); strcpy(tp, astring); tp += strlen(astring); @@ -129,46 +130,21 @@ void afs_MarinerLog(astring, avc) /* note, console doesn't want a terminating null */ /* I don't care if mariner packets fail to be sent */ dvec.iov_base = buf; - dvec.iov_len = tp-buf; + dvec.iov_len = tp - buf; AFS_GUNLOCK(); - (void) osi_NetSend(afs_server->socket, &taddr, &dvec, 1, tp-buf, 0); + (void)osi_NetSend(afs_server->socket, &taddr, &dvec, 1, tp - buf, 0); AFS_GLOCK(); osi_FreeSmallSpace(buf); -} /*afs_MarinerLog*/ +} /*afs_MarinerLog */ -void shutdown_mariner(void) +void +shutdown_mariner(void) { int i; marinerPtr = 0; afs_mariner = 0; - for (i=0; i -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_memcache.c,v 1.1.1.5 2001/09/11 14:24:41 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_memcache.c,v 1.15 2003/07/15 23:14:12 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ #ifndef AFS_LINUX22_ENV -#include "../rpc/types.h" +#include "rpc/types.h" #endif #ifdef AFS_ALPHA_ENV #undef kmem_alloc @@ -22,19 +23,11 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_memcache.c,v 1.1.1.5 2001/09/11 #undef mem_alloc #undef mem_free #undef register -#endif /* AFS_ALPHA_ENV */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ +#endif /* AFS_ALPHA_ENV */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ /* memory cache routines */ - -struct memCacheEntry { - int size; /* # of valid bytes in this entry */ - int dataSize; /* size of allocated data area */ - afs_lock_t afs_memLock; - char *data; /* bytes */ -}; - static struct memCacheEntry *memCache; static int memCacheBlkSize = 8192; static int memMaxBlkNumber = 0; @@ -42,468 +35,477 @@ static int memAllocMaySleep = 0; extern int cacheDiskType; -afs_InitMemCache(size, blkSize, flags) - int size; - int blkSize; - int flags; - { - int index; - - AFS_STATCNT(afs_InitMemCache); - if(blkSize) - memCacheBlkSize = blkSize; - - memMaxBlkNumber = size / memCacheBlkSize; - memCache = (struct memCacheEntry *) - afs_osi_Alloc(memMaxBlkNumber * sizeof(struct memCacheEntry)); - if (flags & AFSCALL_INIT_MEMCACHE_SLEEP) { - memAllocMaySleep = 1; - } - - for(index = 0; index < memMaxBlkNumber; index++) { - char *blk; - (memCache+index)->size = 0; - (memCache+index)->dataSize = memCacheBlkSize; - LOCK_INIT(&((memCache+index)->afs_memLock), "afs_memLock"); - if (memAllocMaySleep) { - blk = afs_osi_Alloc(memCacheBlkSize); - } else { - blk = afs_osi_Alloc_NoSleep(memCacheBlkSize); - } - if (blk == NULL) - goto nomem; - (memCache+index)->data = blk; - memset((memCache+index)->data, 0, memCacheBlkSize); - } +int +afs_InitMemCache(int blkCount, int blkSize, int flags) +{ + int index; + + AFS_STATCNT(afs_InitMemCache); + if (blkSize) + memCacheBlkSize = blkSize; + + memMaxBlkNumber = blkCount; + memCache = (struct memCacheEntry *) + afs_osi_Alloc(memMaxBlkNumber * sizeof(struct memCacheEntry)); + if (flags & AFSCALL_INIT_MEMCACHE_SLEEP) { + memAllocMaySleep = 1; + } + + for (index = 0; index < memMaxBlkNumber; index++) { + char *blk; + (memCache + index)->size = 0; + (memCache + index)->dataSize = memCacheBlkSize; + LOCK_INIT(&((memCache + index)->afs_memLock), "afs_memLock"); + if (memAllocMaySleep) { + blk = afs_osi_Alloc(memCacheBlkSize); + } else { + blk = afs_osi_Alloc_NoSleep(memCacheBlkSize); + } + if (blk == NULL) + goto nomem; + (memCache + index)->data = blk; + memset((memCache + index)->data, 0, memCacheBlkSize); + } #if defined(AFS_SGI62_ENV) || defined(AFS_HAVE_VXFS) - afs_InitDualFSCacheOps((struct vnode*)0); + afs_InitDualFSCacheOps((struct vnode *)0); #endif - return 0; + return 0; -nomem: - printf("afsd: memCache allocation failure at %d KB.\n", - (index * memCacheBlkSize) / 1024); - while(--index >= 0) { - afs_osi_Free((memCache+index)->data, memCacheBlkSize); - (memCache+index)->data = NULL; - } - return ENOMEM; + nomem: + printf("afsd: memCache allocation failure at %d KB.\n", + (index * memCacheBlkSize) / 1024); + while (--index >= 0) { + afs_osi_Free((memCache + index)->data, memCacheBlkSize); + (memCache + index)->data = NULL; + } + return ENOMEM; - } +} -afs_MemCacheClose(file) - char *file; +int +afs_MemCacheClose(char *file) { return 0; } -void *afs_MemCacheOpen(ino_t blkno) - { - struct memCacheEntry *mep; +void * +afs_MemCacheOpen(ino_t blkno) +{ + struct memCacheEntry *mep; - if (blkno < 0 || blkno > memMaxBlkNumber) { - osi_Panic("afs_MemCacheOpen: invalid block #"); - } - mep = (memCache + blkno); - return (void *) mep; - } + if (blkno < 0 || blkno > memMaxBlkNumber) { + osi_Panic("afs_MemCacheOpen: invalid block #"); + } + mep = (memCache + blkno); + afs_Trace4(afs_iclSetp, CM_TRACE_MEMOPEN, ICL_TYPE_INT32, blkno, + ICL_TYPE_POINTER, mep, ICL_TYPE_POINTER, mep->data, + ICL_TYPE_STRING, mep->data); + return (void *)mep; +} /* * this routine simulates a read in the Memory Cache */ -afs_MemReadBlk(mceP, offset, dest, size) - int offset; - register struct memCacheEntry *mceP; - char *dest; - int size; - { - int bytesRead; - - MObtainReadLock(&mceP->afs_memLock); - AFS_STATCNT(afs_MemReadBlk); - if (offset < 0) { - MReleaseReadLock(&mceP->afs_memLock); - return 0; - } - /* use min of bytes in buffer or requested size */ - bytesRead = (size < mceP->size - offset) ? size : - mceP->size - offset; - - if(bytesRead > 0) { - AFS_GUNLOCK(); - memcpy(dest, mceP->data + offset, bytesRead); - AFS_GLOCK(); - } - else - bytesRead = 0; - - MReleaseReadLock(&mceP->afs_memLock); - return bytesRead; - } +int +afs_MemReadBlk(register struct memCacheEntry *mceP, int offset, char *dest, + int size) +{ + int bytesRead; + + MObtainReadLock(&mceP->afs_memLock); + AFS_STATCNT(afs_MemReadBlk); + if (offset < 0) { + MReleaseReadLock(&mceP->afs_memLock); + return 0; + } + /* use min of bytes in buffer or requested size */ + bytesRead = (size < mceP->size - offset) ? size : mceP->size - offset; + + if (bytesRead > 0) { + AFS_GUNLOCK(); + memcpy(dest, mceP->data + offset, bytesRead); + AFS_GLOCK(); + } else + bytesRead = 0; + + MReleaseReadLock(&mceP->afs_memLock); + return bytesRead; +} /* * this routine simulates a readv in the Memory Cache */ -afs_MemReadvBlk(mceP, offset, iov, nio, size) - int offset; - register struct memCacheEntry *mceP; - struct iovec *iov; - int nio; - int size; - { - int i; - int bytesRead; - int bytesToRead; - - MObtainReadLock(&mceP->afs_memLock); - AFS_STATCNT(afs_MemReadBlk); - if (offset < 0) { - MReleaseReadLock(&mceP->afs_memLock); - return 0; - } - /* use min of bytes in buffer or requested size */ - bytesRead = (size < mceP->size - offset) ? size : - mceP->size - offset; - - if(bytesRead > 0) { - for (i = 0 , size = bytesRead ; i < nio && size > 0 ; i++) { - bytesToRead = (size < iov[i].iov_len) ? size : iov[i].iov_len; - AFS_GUNLOCK(); - memcpy(iov[i].iov_base, mceP->data + offset, bytesToRead); - AFS_GLOCK(); - offset += bytesToRead; - size -= bytesToRead; - } - bytesRead -= size; - } else - bytesRead = 0; - - MReleaseReadLock(&mceP->afs_memLock); - return bytesRead; - } - -afs_MemReadUIO(blkno, uioP) - ino_t blkno; - struct uio *uioP; - { - register struct memCacheEntry *mceP = (struct memCacheEntry *)afs_MemCacheOpen(blkno); - int length = mceP->size - uioP->uio_offset; - afs_int32 code; - - AFS_STATCNT(afs_MemReadUIO); - MObtainReadLock(&mceP->afs_memLock); - length = (length < uioP->uio_resid) ? length : uioP->uio_resid; - AFS_UIOMOVE(mceP->data + uioP->uio_offset, length, UIO_READ, uioP, code); - MReleaseReadLock(&mceP->afs_memLock); - return code; - } +int +afs_MemReadvBlk(register struct memCacheEntry *mceP, int offset, + struct iovec *iov, int nio, int size) +{ + int i; + int bytesRead; + int bytesToRead; + + MObtainReadLock(&mceP->afs_memLock); + AFS_STATCNT(afs_MemReadBlk); + if (offset < 0) { + MReleaseReadLock(&mceP->afs_memLock); + return 0; + } + /* use min of bytes in buffer or requested size */ + bytesRead = (size < mceP->size - offset) ? size : mceP->size - offset; + + if (bytesRead > 0) { + for (i = 0, size = bytesRead; i < nio && size > 0; i++) { + bytesToRead = (size < iov[i].iov_len) ? size : iov[i].iov_len; + AFS_GUNLOCK(); + memcpy(iov[i].iov_base, mceP->data + offset, bytesToRead); + AFS_GLOCK(); + offset += bytesToRead; + size -= bytesToRead; + } + bytesRead -= size; + } else + bytesRead = 0; + + MReleaseReadLock(&mceP->afs_memLock); + return bytesRead; +} + +int +afs_MemReadUIO(ino_t blkno, struct uio *uioP) +{ + register struct memCacheEntry *mceP = + (struct memCacheEntry *)afs_MemCacheOpen(blkno); + int length = mceP->size - uioP->uio_offset; + afs_int32 code; + + AFS_STATCNT(afs_MemReadUIO); + MObtainReadLock(&mceP->afs_memLock); + length = (length < uioP->uio_resid) ? length : uioP->uio_resid; + AFS_UIOMOVE(mceP->data + uioP->uio_offset, length, UIO_READ, uioP, code); + MReleaseReadLock(&mceP->afs_memLock); + return code; +} /*XXX: this extends a block arbitrarily to support big directories */ -afs_MemWriteBlk(mceP, offset, src, size) - register struct memCacheEntry *mceP; - int offset; - char *src; - int size; - { - AFS_STATCNT(afs_MemWriteBlk); - MObtainWriteLock(&mceP->afs_memLock,560); - if (size + offset > mceP->dataSize) { - char *oldData = mceP->data; - - if (memAllocMaySleep) { - mceP->data = afs_osi_Alloc(size+offset); - } else { - mceP->data = afs_osi_Alloc_NoSleep(size+offset); - } - if ( mceP->data == NULL ) /* no available memory */ - { - mceP->data = oldData; /* revert back change that was made */ - MReleaseWriteLock(&mceP->afs_memLock); - afs_warn("afs: afs_MemWriteBlk mem alloc failure (%d bytes)\n", - size+offset); - return -ENOMEM; - } - - /* may overlap, but this is OK */ - AFS_GUNLOCK(); - memcpy(mceP->data, oldData, mceP->size); - AFS_GLOCK(); - afs_osi_Free(oldData,mceP->dataSize); - mceP->dataSize = size+offset; - } - AFS_GUNLOCK(); - if (mceP->size < offset) - memset(mceP->data+mceP->size, 0, offset-mceP->size); - memcpy(mceP->data + offset, src, size); - AFS_GLOCK(); - mceP->size = (size+offset < mceP->size) ? mceP->size : - size + offset; - - MReleaseWriteLock(&mceP->afs_memLock); - return size; - } +int +afs_MemWriteBlk(register struct memCacheEntry *mceP, int offset, char *src, + int size) +{ + AFS_STATCNT(afs_MemWriteBlk); + MObtainWriteLock(&mceP->afs_memLock, 560); + if (size + offset > mceP->dataSize) { + char *oldData = mceP->data; + + if (memAllocMaySleep) { + mceP->data = afs_osi_Alloc(size + offset); + } else { + mceP->data = afs_osi_Alloc_NoSleep(size + offset); + } + if (mceP->data == NULL) { /* no available memory */ + mceP->data = oldData; /* revert back change that was made */ + MReleaseWriteLock(&mceP->afs_memLock); + afs_warn("afs: afs_MemWriteBlk mem alloc failure (%d bytes)\n", + size + offset); + return -ENOMEM; + } + + /* may overlap, but this is OK */ + AFS_GUNLOCK(); + memcpy(mceP->data, oldData, mceP->size); + AFS_GLOCK(); + afs_osi_Free(oldData, mceP->dataSize); + mceP->dataSize = size + offset; + } + AFS_GUNLOCK(); + if (mceP->size < offset) + memset(mceP->data + mceP->size, 0, offset - mceP->size); + memcpy(mceP->data + offset, src, size); + AFS_GLOCK(); + mceP->size = (size + offset < mceP->size) ? mceP->size : size + offset; + + MReleaseWriteLock(&mceP->afs_memLock); + return size; +} /*XXX: this extends a block arbitrarily to support big directories */ -afs_MemWritevBlk(mceP, offset, iov, nio, size) - register struct memCacheEntry *mceP; - int offset; - struct iovec *iov; - int nio; - int size; - { - int i; - int bytesWritten; - int bytesToWrite; - AFS_STATCNT(afs_MemWriteBlk); - MObtainWriteLock(&mceP->afs_memLock,561); - if (size + offset > mceP->dataSize) { - char *oldData = mceP->data; - - mceP->data = afs_osi_Alloc(size+offset); - - /* may overlap, but this is OK */ - AFS_GUNLOCK(); - memcpy(mceP->data, oldData, mceP->size); - AFS_GLOCK(); - afs_osi_Free(oldData,mceP->dataSize); - mceP->dataSize = size+offset; - } - if (mceP->size < offset) - memset(mceP->data+mceP->size, 0, offset-mceP->size); - for (bytesWritten = 0, i = 0 ; i < nio && size > 0 ; i++) { - bytesToWrite = (size < iov[i].iov_len) ? size : iov[i].iov_len; - AFS_GUNLOCK(); - memcpy(mceP->data + offset, iov[i].iov_base, bytesToWrite); - AFS_GLOCK(); - offset += bytesToWrite; - bytesWritten += bytesToWrite; - size -= bytesToWrite; - } - mceP->size = (offset < mceP->size) ? mceP->size : offset; - - MReleaseWriteLock(&mceP->afs_memLock); - return bytesWritten; - } - -afs_MemWriteUIO(blkno, uioP) - ino_t blkno; - struct uio *uioP; - { - register struct memCacheEntry *mceP = (struct memCacheEntry *)afs_MemCacheOpen(blkno); - afs_int32 code; - - AFS_STATCNT(afs_MemWriteUIO); - MObtainWriteLock(&mceP->afs_memLock,312); - if(uioP->uio_resid + uioP->uio_offset > mceP->dataSize) { - char *oldData = mceP->data; - - mceP->data = afs_osi_Alloc(uioP->uio_resid + uioP->uio_offset); - - AFS_GUNLOCK(); - memcpy(mceP->data, oldData, mceP->size); - AFS_GLOCK(); - - afs_osi_Free(oldData,mceP->dataSize); - mceP->dataSize = uioP->uio_resid + uioP->uio_offset; - } - if (mceP->size < uioP->uio_offset) - memset(mceP->data+mceP->size, 0, (int)(uioP->uio_offset-mceP->size)); - AFS_UIOMOVE(mceP->data+uioP->uio_offset, uioP->uio_resid, UIO_WRITE, uioP, code); - if (uioP->uio_offset > mceP->size) - mceP->size = uioP->uio_offset; - - MReleaseWriteLock(&mceP->afs_memLock); - return code; - } - -afs_MemCacheTruncate(mceP, size) - register struct memCacheEntry *mceP; - int size; - { - AFS_STATCNT(afs_MemCacheTruncate); - - MObtainWriteLock(&mceP->afs_memLock,313); - /* old directory entry; g.c. */ - if(size == 0 && mceP->dataSize > memCacheBlkSize) { - afs_osi_Free(mceP->data, mceP->dataSize); - mceP->data = afs_osi_Alloc(memCacheBlkSize); - mceP->dataSize = memCacheBlkSize; - } - - if (size < mceP->size) - mceP->size = size; - - MReleaseWriteLock(&mceP->afs_memLock); - return 0; - } - -afs_MemCacheStoreProc(acall, mceP, alen, avc, shouldWake, abytesToXferP, abytesXferredP) - register struct memCacheEntry *mceP; - register struct rx_call *acall; - register afs_int32 alen; - struct vcache *avc; - int *shouldWake; - afs_int32 *abytesToXferP; - afs_int32 *abytesXferredP; - - { - - register afs_int32 code; - register int tlen; - int offset = 0; - struct iovec *tiov; /* no data copying with iovec */ - int tnio; /* temp for iovec size */ - - AFS_STATCNT(afs_MemCacheStoreProc); +int +afs_MemWritevBlk(register struct memCacheEntry *mceP, int offset, + struct iovec *iov, int nio, int size) +{ + int i; + int bytesWritten; + int bytesToWrite; + AFS_STATCNT(afs_MemWriteBlk); + MObtainWriteLock(&mceP->afs_memLock, 561); + if (offset + size > mceP->dataSize) { + char *oldData = mceP->data; + + mceP->data = afs_osi_Alloc(size + offset); + + /* may overlap, but this is OK */ + AFS_GUNLOCK(); + memcpy(mceP->data, oldData, mceP->size); + AFS_GLOCK(); + afs_osi_Free(oldData, mceP->dataSize); + mceP->dataSize = size + offset; + } + AFS_GUNLOCK(); + if (mceP->size < offset) + memset(mceP->data + mceP->size, 0, offset - mceP->size); + for (bytesWritten = 0, i = 0; i < nio && size > 0; i++) { + bytesToWrite = (size < iov[i].iov_len) ? size : iov[i].iov_len; + memcpy(mceP->data + offset, iov[i].iov_base, bytesToWrite); + offset += bytesToWrite; + bytesWritten += bytesToWrite; + size -= bytesToWrite; + } + mceP->size = (offset < mceP->size) ? mceP->size : offset; + AFS_GLOCK(); + + MReleaseWriteLock(&mceP->afs_memLock); + return bytesWritten; +} + +int +afs_MemWriteUIO(ino_t blkno, struct uio *uioP) +{ + register struct memCacheEntry *mceP = + (struct memCacheEntry *)afs_MemCacheOpen(blkno); + afs_int32 code; + + AFS_STATCNT(afs_MemWriteUIO); + MObtainWriteLock(&mceP->afs_memLock, 312); + if (uioP->uio_resid + uioP->uio_offset > mceP->dataSize) { + char *oldData = mceP->data; + + mceP->data = afs_osi_Alloc(uioP->uio_resid + uioP->uio_offset); + + AFS_GUNLOCK(); + memcpy(mceP->data, oldData, mceP->size); + AFS_GLOCK(); + + afs_osi_Free(oldData, mceP->dataSize); + mceP->dataSize = uioP->uio_resid + uioP->uio_offset; + } + if (mceP->size < uioP->uio_offset) + memset(mceP->data + mceP->size, 0, + (int)(uioP->uio_offset - mceP->size)); + AFS_UIOMOVE(mceP->data + uioP->uio_offset, uioP->uio_resid, UIO_WRITE, + uioP, code); + if (uioP->uio_offset > mceP->size) + mceP->size = uioP->uio_offset; + + MReleaseWriteLock(&mceP->afs_memLock); + return code; +} + +int +afs_MemCacheTruncate(register struct memCacheEntry *mceP, int size) +{ + AFS_STATCNT(afs_MemCacheTruncate); + + MObtainWriteLock(&mceP->afs_memLock, 313); + /* old directory entry; g.c. */ + if (size == 0 && mceP->dataSize > memCacheBlkSize) { + afs_osi_Free(mceP->data, mceP->dataSize); + mceP->data = afs_osi_Alloc(memCacheBlkSize); + mceP->dataSize = memCacheBlkSize; + } + + if (size < mceP->size) + mceP->size = size; + + MReleaseWriteLock(&mceP->afs_memLock); + return 0; +} + +int +afs_MemCacheStoreProc(register struct rx_call *acall, + register struct memCacheEntry *mceP, + register afs_int32 alen, struct vcache *avc, + int *shouldWake, afs_size_t * abytesToXferP, + afs_size_t * abytesXferredP, afs_int32 length) +{ + + register afs_int32 code; + register int tlen; + int offset = 0; + struct iovec *tiov; /* no data copying with iovec */ + int tnio; /* temp for iovec size */ + + AFS_STATCNT(afs_MemCacheStoreProc); #ifndef AFS_NOSTATS - /* - * In this case, alen is *always* the amount of data we'll be trying - * to ship here. - */ - *(abytesToXferP) = alen; - *(abytesXferredP) = 0; + /* + * In this case, alen is *always* the amount of data we'll be trying + * to ship here. + */ + *(abytesToXferP) = alen; + *(abytesXferredP) = 0; #endif /* AFS_NOSTATS */ - /* - * We need to alloc the iovecs on the heap so that they are "pinned" rather than - * declare them on the stack - defect 11272 - */ - tiov = (struct iovec *) osi_AllocSmallSpace(sizeof(struct iovec)*RX_MAXIOVECS); - if(!tiov) { - osi_Panic("afs_MemCacheFetchProc: osi_AllocSmallSpace for iovecs returned NULL\n"); - } - + /* + * We need to alloc the iovecs on the heap so that they are "pinned" rather than + * declare them on the stack - defect 11272 + */ + tiov = + (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec) * + RX_MAXIOVECS); + if (!tiov) { + osi_Panic + ("afs_MemCacheStoreProc: osi_AllocSmallSpace for iovecs returned NULL\n"); + } #ifdef notdef /* do this at a higher level now -- it's a parameter */ - /* for now, only do 'continue from close' code if file fits in one - chunk. Could clearly do better: if only one modified chunk - then can still do this. can do this on *last* modified chunk */ - tlen = avc->m.Length-1; /* byte position of last byte we'll store */ - if (shouldWake) { - if (AFS_CHUNK(tlen) != 0) *shouldWake = 0; - else *shouldWake = 1; - } + /* for now, only do 'continue from close' code if file fits in one + * chunk. Could clearly do better: if only one modified chunk + * then can still do this. can do this on *last* modified chunk */ + tlen = avc->m.Length - 1; /* byte position of last byte we'll store */ + if (shouldWake) { + if (AFS_CHUNK(tlen) != 0) + *shouldWake = 0; + else + *shouldWake = 1; + } #endif /* notdef */ - while (alen > 0) { - tlen = (alen > AFS_LRALLOCSIZ? AFS_LRALLOCSIZ : alen); - code = rx_WritevAlloc(acall, tiov, &tnio, RX_MAXIOVECS, tlen); - if (code <= 0) { - osi_FreeSmallSpace(tiov); - return -33; - } - tlen = code; - code = afs_MemReadvBlk(mceP, offset, tiov, tnio, tlen); - if (code != tlen) { - osi_FreeSmallSpace(tiov); - return -33; - } - code = rx_Writev(acall, tiov, tnio, tlen); + while (alen > 0) { + tlen = (alen > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : alen); + RX_AFS_GUNLOCK(); + code = rx_WritevAlloc(acall, tiov, &tnio, RX_MAXIOVECS, tlen); + RX_AFS_GLOCK(); + if (code <= 0) { + osi_FreeSmallSpace(tiov); + return -33; + } + tlen = code; + code = afs_MemReadvBlk(mceP, offset, tiov, tnio, tlen); + if (code != tlen) { + osi_FreeSmallSpace(tiov); + return -33; + } + RX_AFS_GUNLOCK(); + code = rx_Writev(acall, tiov, tnio, tlen); + RX_AFS_GLOCK(); #ifndef AFS_NOSTATS - (*abytesXferredP) += code; + (*abytesXferredP) += code; #endif /* AFS_NOSTATS */ - if (code != tlen) { - osi_FreeSmallSpace(tiov); - return -33; - } - offset += tlen; - alen -= tlen; - /* if file has been locked on server, can allow store to continue */ - if (shouldWake && *shouldWake && (rx_GetRemoteStatus(acall) & 1)) { - *shouldWake = 0; /* only do this once */ - afs_wakeup(avc); - } - } - osi_FreeSmallSpace(tiov); - return 0; - } - -afs_MemCacheFetchProc(acall, mceP, abase, adc, avc, abytesToXferP, abytesXferredP) - register struct rx_call *acall; - afs_int32 abase; - struct dcache *adc; - struct vcache *avc; - register struct memCacheEntry *mceP; - afs_int32 *abytesToXferP; - afs_int32 *abytesXferredP; - - { - afs_int32 length; - register afs_int32 code; - register int tlen, offset=0; - int moredata; - struct iovec *tiov; /* no data copying with iovec */ - int tnio; /* temp for iovec size */ - - AFS_STATCNT(afs_MemCacheFetchProc); + if (code != tlen) { + osi_FreeSmallSpace(tiov); + return -33; + } + offset += tlen; + alen -= tlen; + /* if file has been locked on server, can allow store to continue */ + if (shouldWake && *shouldWake && (rx_GetRemoteStatus(acall) & 1)) { + *shouldWake = 0; /* only do this once */ + afs_wakeup(avc); + } + } + osi_FreeSmallSpace(tiov); + return 0; +} + +int +afs_MemCacheFetchProc(register struct rx_call *acall, + register struct memCacheEntry *mceP, afs_size_t abase, + struct dcache *adc, struct vcache *avc, + afs_size_t * abytesToXferP, afs_size_t * abytesXferredP, + afs_int32 lengthFound) +{ + register afs_int32 code; + afs_int32 length; + int moredata = 0; + struct iovec *tiov; /* no data copying with iovec */ + register int tlen, offset = 0; + int tnio; /* temp for iovec size */ + + AFS_STATCNT(afs_MemCacheFetchProc); + length = lengthFound; + afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc, + ICL_TYPE_POINTER, mceP, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(abase), ICL_TYPE_INT32, length); #ifndef AFS_NOSTATS - (*abytesToXferP) = 0; - (*abytesXferredP) = 0; + (*abytesToXferP) = 0; + (*abytesXferredP) = 0; #endif /* AFS_NOSTATS */ - /* - * We need to alloc the iovecs on the heap so that they are "pinned" rather than - * declare them on the stack - defect 11272 - */ - tiov = (struct iovec *) osi_AllocSmallSpace(sizeof(struct iovec)*RX_MAXIOVECS); - if(!tiov) { - osi_Panic("afs_MemCacheFetchProc: osi_AllocSmallSpace for iovecs returned NULL\n"); - } - do { - code = rx_Read(acall, (char *)&length, sizeof(afs_int32)); - if (code != sizeof(afs_int32)) { - code = rx_Error(acall); - osi_FreeSmallSpace(tiov); - return (code?code:-1); /* try to return code, not -1 */ - } - length = ntohl(length); - /* - * The fetch protocol is extended for the AFS/DFS translator - * to allow multiple blocks of data, each with its own length, - * to be returned. As long as the top bit is set, there are more - * blocks expected. - * - * We do not do this for AFS file servers because they sometimes - * return large negative numbers as the transfer size. - */ - if (avc->states & CForeign) { - moredata = length & 0x80000000; - length &= ~0x80000000; - } else { - moredata = 0; - } + /* + * We need to alloc the iovecs on the heap so that they are "pinned" rather than + * declare them on the stack - defect 11272 + */ + tiov = + (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec) * + RX_MAXIOVECS); + if (!tiov) { + osi_Panic + ("afs_MemCacheFetchProc: osi_AllocSmallSpace for iovecs returned NULL\n"); + } + adc->validPos = abase; + do { + if (moredata) { + RX_AFS_GUNLOCK(); + code = rx_Read(acall, (char *)&length, sizeof(afs_int32)); + length = ntohl(length); + RX_AFS_GLOCK(); + if (code != sizeof(afs_int32)) { + code = rx_Error(acall); + osi_FreeSmallSpace(tiov); + return (code ? code : -1); /* try to return code, not -1 */ + } + } + /* + * The fetch protocol is extended for the AFS/DFS translator + * to allow multiple blocks of data, each with its own length, + * to be returned. As long as the top bit is set, there are more + * blocks expected. + * + * We do not do this for AFS file servers because they sometimes + * return large negative numbers as the transfer size. + */ + if (avc->states & CForeign) { + moredata = length & 0x80000000; + length &= ~0x80000000; + } else { + moredata = 0; + } #ifndef AFS_NOSTATS - (*abytesToXferP) += length; -#endif /* AFS_NOSTATS */ - while (length > 0) { - tlen = (length > AFS_LRALLOCSIZ? AFS_LRALLOCSIZ : length); - code = rx_Readv(acall, tiov, &tnio, RX_MAXIOVECS, tlen); + (*abytesToXferP) += length; +#endif /* AFS_NOSTATS */ + while (length > 0) { + tlen = (length > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : length); + RX_AFS_GUNLOCK(); + code = rx_Readv(acall, tiov, &tnio, RX_MAXIOVECS, tlen); + RX_AFS_GLOCK(); #ifndef AFS_NOSTATS - (*abytesXferredP) += code; -#endif /* AFS_NOSTATS */ - if (code <= 0) { - osi_FreeSmallSpace(tiov); - return -34; - } - tlen = code; - afs_MemWritevBlk(mceP, offset, tiov, tnio, tlen); - offset += tlen; - abase += tlen; - length -= tlen; - adc->validPos = abase; - if (adc->flags & DFWaiting) { - adc->flags &= ~DFWaiting; - afs_osi_Wakeup(&adc->validPos); - } - } - } while (moredata); - /* max of two sizes */ - osi_FreeSmallSpace(tiov); - return 0; - } - - -void shutdown_memcache() + (*abytesXferredP) += code; +#endif /* AFS_NOSTATS */ + if (code <= 0) { + afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ, + ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code, + ICL_TYPE_INT32, length); + osi_FreeSmallSpace(tiov); + return -34; + } + tlen = code; + afs_MemWritevBlk(mceP, offset, tiov, tnio, tlen); + offset += tlen; + abase += tlen; + length -= tlen; + adc->validPos = abase; + if (afs_osi_Wakeup(&adc->validPos) == 0) + afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING, + __FILE__, ICL_TYPE_INT32, __LINE__, + ICL_TYPE_POINTER, adc, ICL_TYPE_INT32, + adc->dflags); + } + } while (moredata); + /* max of two sizes */ + osi_FreeSmallSpace(tiov); + return 0; +} + + +void +shutdown_memcache(void) { register int index; @@ -511,9 +513,10 @@ void shutdown_memcache() return; memCacheBlkSize = 8192; for (index = 0; index < memMaxBlkNumber; index++) { - LOCK_INIT(&((memCache+index)->afs_memLock), "afs_memLock"); - afs_osi_Free((memCache+index)->data, (memCache+index)->dataSize); + LOCK_INIT(&((memCache + index)->afs_memLock), "afs_memLock"); + afs_osi_Free((memCache + index)->data, (memCache + index)->dataSize); } - afs_osi_Free((char *)memCache, memMaxBlkNumber * sizeof(struct memCacheEntry)); + afs_osi_Free((char *)memCache, + memMaxBlkNumber * sizeof(struct memCacheEntry)); memMaxBlkNumber = 0; } diff --git a/src/afs/afs_nfsclnt.c b/src/afs/afs_nfsclnt.c index 3d240a712..23ae86880 100644 --- a/src/afs/afs_nfsclnt.c +++ b/src/afs/afs_nfsclnt.c @@ -8,16 +8,17 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_nfsclnt.c,v 1.1.1.6 2002/09/26 18:57:52 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_nfsclnt.c,v 1.12 2004/03/17 06:43:34 shadow Exp $"); #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV) #ifndef AFS_DEC_ENV -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/nfsclient.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/nfsclient.h" int afs_nfsclient_reqhandler(), afs_nfsclient_hold(), afs_PutNfsClientPag(); int afs_nfsclient_sysname(), afs_nfsclient_GC(), afs_nfsclient_stats(); @@ -29,20 +30,21 @@ int afs_allnfsreqs, afs_nfscalls; struct exporterops nfs_exportops = { afs_nfsclient_reqhandler, afs_nfsclient_hold, - afs_PutNfsClientPag, /* Used to be afs_nfsclient_rele */ + afs_PutNfsClientPag, /* Used to be afs_nfsclient_rele */ afs_nfsclient_sysname, afs_nfsclient_GC, afs_nfsclient_stats, }; -struct nfsclientpag *afs_nfspags[NNFSCLIENTS]; -afs_lock_t afs_xnfspag /*, afs_xnfsreq */; -extern struct afs_exporter *afs_nfsexporter; +struct nfsclientpag *afs_nfspags[NNFSCLIENTS]; +afs_lock_t afs_xnfspag /*, afs_xnfsreq */ ; +extern struct afs_exporter *afs_nfsexporter; /* Creates an nfsclientpag structure for the (uid, host) pair if one doesn't exist. RefCount is incremented and it's time stamped. */ -static struct nfsclientpag *afs_GetNfsClientPag(uid, host) -register afs_int32 uid, host; +static struct nfsclientpag * +afs_GetNfsClientPag(uid, host) + register afs_int32 uid, host; { register struct nfsclientpag *np; register afs_int32 i, now; @@ -53,7 +55,7 @@ register afs_int32 uid, host; AFS_STATCNT(afs_GetNfsClientPag); i = NHash(host); now = osi_Time(); - MObtainWriteLock(&afs_xnfspag,314); + MObtainWriteLock(&afs_xnfspag, 314); for (np = afs_nfspags[i]; np; np = np->next) { if (np->uid == uid && np->host == host) { np->refCount++; @@ -71,7 +73,7 @@ register afs_int32 uid, host; return np; } } - np = (struct nfsclientpag *) afs_osi_Alloc(sizeof (struct nfsclientpag)); + np = (struct nfsclientpag *)afs_osi_Alloc(sizeof(struct nfsclientpag)); memset((char *)np, 0, sizeof(struct nfsclientpag)); /* Copy the necessary afs_exporter fields */ memcpy((char *)np, (char *)afs_nfsexporter, sizeof(struct afs_exporter)); @@ -88,8 +90,9 @@ register afs_int32 uid, host; /* Decrement refCount; must always match a previous afs_FindNfsClientPag/afs_GetNfsClientPag call . It's also called whenever a unixuser structure belonging to the remote user associated with the nfsclientpag structure, np, is garbage collected. */ -int afs_PutNfsClientPag(np) -register struct nfsclientpag *np; +int +afs_PutNfsClientPag(np) + register struct nfsclientpag *np; { #if defined(AFS_SGIMP_ENV) osi_Assert(ISAFS_GLOCK()); @@ -100,8 +103,9 @@ register struct nfsclientpag *np; /* Return the nfsclientpag structure associated with the (uid, host) or {pag, host} pair, if pag is nonzero. RefCount is incremented and it's time stamped. */ -static struct nfsclientpag *afs_FindNfsClientPag(uid, host, pag) -register afs_int32 uid, host, pag; +static struct nfsclientpag * +afs_FindNfsClientPag(uid, host, pag) + register afs_int32 uid, host, pag; { register struct nfsclientpag *np; register afs_int32 i; @@ -111,30 +115,30 @@ register afs_int32 uid, host, pag; #endif AFS_STATCNT(afs_FindNfsClientPag); i = NHash(host); - MObtainWriteLock(&afs_xnfspag,315); + MObtainWriteLock(&afs_xnfspag, 315); for (np = afs_nfspags[i]; np; np = np->next) { if (np->host == host) { - if ((pag && pag == np->pag) || (!pag && (uid == np->uid))) { - np->refCount++; - np->lastcall = osi_Time(); - MReleaseWriteLock(&afs_xnfspag); - return np; - } + if ((pag && pag == np->pag) || (!pag && (uid == np->uid))) { + np->refCount++; + np->lastcall = osi_Time(); + MReleaseWriteLock(&afs_xnfspag); + return np; + } } } /* still not there, try looking for a wildcard dude */ for (np = afs_nfspags[i]; np; np = np->next) { if (np->host == host) { - if (np->uid == NOPAG) { - np->refCount++; - np->lastcall = osi_Time(); - MReleaseWriteLock(&afs_xnfspag); - return np; - } + if (np->uid == NOPAG) { + np->refCount++; + np->lastcall = osi_Time(); + MReleaseWriteLock(&afs_xnfspag); + return np; + } } } MReleaseWriteLock(&afs_xnfspag); - return (struct nfsclientpag *) 0; + return NULL; } @@ -143,7 +147,8 @@ register afs_int32 uid, host, pag; */ struct afs_exporter *afs_nfsexported = 0; static afs_int32 init_nfsexporter = 0; -afs_nfsclient_init() { +afs_nfsclient_init() +{ #if defined(AFS_SGIMP_ENV) osi_Assert(ISAFS_GLOCK()); #endif @@ -152,7 +157,8 @@ afs_nfsclient_init() { init_nfsexporter = 1; LOCK_INIT(&afs_xnfspag, "afs_xnfspag"); - afs_nfsexported = exporter_add(0, &nfs_exportops, EXP_EXPORTED, EXP_NFS, (char *)0); + afs_nfsexported = + exporter_add(0, &nfs_exportops, EXP_EXPORTED, EXP_NFS, NULL); } } @@ -160,11 +166,12 @@ afs_nfsclient_init() { /* Main handler routine for the NFS exporter. It's called in the early * phases of any remote call (via the NFS server or pioctl). */ -int afs_nfsclient_reqhandler(exporter, cred, host, pagparam, outexporter) -register struct afs_exporter *exporter, **outexporter; -struct AFS_UCRED **cred; -register afs_int32 host; -afs_int32 *pagparam; +int +afs_nfsclient_reqhandler(exporter, cred, host, pagparam, outexporter) + register struct afs_exporter *exporter, **outexporter; + struct AFS_UCRED **cred; + register afs_int32 host; + afs_int32 *pagparam; { register struct nfsclientpag *np, *tnp; extern struct unixuser *afs_FindUser(), *afs_GetUser(); @@ -173,8 +180,9 @@ afs_int32 *pagparam; AFS_ASSERT_GLOCK(); AFS_STATCNT(afs_nfsclient_reqhandler); - if (!afs_nfsexporter) afs_nfsexporter = afs_nfsexported; - + if (!afs_nfsexporter) + afs_nfsexporter = afs_nfsexported; + afs_nfsexporter->exp_stats.calls++; if (!(afs_nfsexporter->exp_states & EXP_EXPORTED)) { /* No afs requests accepted as long as EXPORTED flag is turned 'off'. Set/Reset via a pioctl call (fs exportafs). Note that this is on top of the /etc/exports nfs requirement (i.e. /afs must be exported to all or whomever there too!) @@ -187,15 +195,15 @@ afs_int32 *pagparam; if (pag != NOPAG) { /* Do some minimal pag verification */ if (pag > getpag()) { - pag = NOPAG; /* treat it as not paged since couldn't be good */ + pag = NOPAG; /* treat it as not paged since couldn't be good */ } else { if (au = afs_FindUser(pag, -1, READ_LOCK)) { if (!au->exporter) { pag = NOPAG; afs_PutUser(au, READ_LOCK); - au = (struct unixuser *)0; + au = NULL; } - } else + } else pag = NOPAG; /* No unixuser struct so pag not trusted */ } } @@ -210,9 +218,10 @@ afs_int32 *pagparam; #else if (code = setpag(cred, -1, &pag, 1)) { #endif - if (au) afs_PutUser(au, READ_LOCK); + if (au) + afs_PutUser(au, READ_LOCK); /* ReleaseWriteLock(&afs_xnfsreq); */ -#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_SGI64_ENV) +#if defined(KERNEL_HAVE_UERROR) setuerror(code); #endif return (code); @@ -228,14 +237,15 @@ afs_int32 *pagparam; #endif afs_PutNfsClientPag(np); /* ReleaseWriteLock(&afs_xnfsreq); */ -#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_SGI64_ENV) +#if defined(KERNEL_HAVE_UERROR) setuerror(code); #endif return (code); } - } else if (au->exporter && ((struct afs_exporter *)np != au->exporter)) { + } else if (au->exporter + && ((struct afs_exporter *)np != au->exporter)) { tnp = (struct nfsclientpag *)au->exporter; - if (tnp->uid && (tnp->uid != (afs_int32)-2)) { /* allow "root" initiators */ + if (tnp->uid && (tnp->uid != (afs_int32) - 2)) { /* allow "root" initiators */ /* Pag doesn't belong to caller; treat it as an unpaged call too */ #ifdef AFS_OSF_ENV if (code = setpag(u.u_procp, cred, np->pag, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */ @@ -244,8 +254,8 @@ afs_int32 *pagparam; #endif afs_PutNfsClientPag(np); afs_PutUser(au, READ_LOCK); - /* ReleaseWriteLock(&afs_xnfsreq); */ -#if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_SGI64_ENV) + /* ReleaseWriteLock(&afs_xnfsreq); */ +#if defined(KERNEL_HAVE_UERROR) setuerror(code); #endif return (code); @@ -254,7 +264,8 @@ afs_int32 *pagparam; } } } - if (au) afs_PutUser(au, READ_LOCK); + if (au) + afs_PutUser(au, READ_LOCK); au = afs_GetUser(pag, -1, WRITE_LOCK); if (!(au->exporter)) { /* Created new unixuser struct */ np->refCount++; /* so it won't disappear */ @@ -264,9 +275,9 @@ afs_int32 *pagparam; *outexporter = (struct afs_exporter *)np; afs_PutUser(au, WRITE_LOCK); #ifdef AFS_OSF_ENV - (*cred)->cr_ruid = NFSXLATOR_CRED; /* Identify it as nfs xlator call */ + (*cred)->cr_ruid = NFSXLATOR_CRED; /* Identify it as nfs xlator call */ #else - (*cred)->cr_rgid = NFSXLATOR_CRED; /* Identify it as nfs xlator call */ + (*cred)->cr_rgid = NFSXLATOR_CRED; /* Identify it as nfs xlator call */ #endif /* ReleaseWriteLock(&afs_xnfsreq); */ return 0; @@ -274,8 +285,9 @@ afs_int32 *pagparam; /* It's called whenever a new unixuser structure is created for the remote user associated with the nfsclientpag structure, np */ -int afs_nfsclient_hold(np) -register struct nfsclientpag *np; +int +afs_nfsclient_hold(np) + register struct nfsclientpag *np; { #if defined(AFS_SGIMP_ENV) osi_Assert(ISAFS_GLOCK()); @@ -286,31 +298,46 @@ register struct nfsclientpag *np; /* if inname is non-null, a new system name value is set for the remote user (inname contains the new sysname). In all cases, outname returns the current sysname value for this remote user */ -int afs_nfsclient_sysname(np, inname, outname) -register struct nfsclientpag *np; -char *inname, *outname; +int +afs_nfsclient_sysname(register struct nfsclientpag *np, char *inname, + char **outname[], int *num) { + char *cp; + int count, t; #if defined(AFS_SGIMP_ENV) osi_Assert(ISAFS_GLOCK()); #endif AFS_STATCNT(afs_nfsclient_sysname); if (inname) { - if (!np->sysname) { - np->sysname = afs_osi_Alloc(MAXSYSNAME); + if (np->sysname) { + for(count=0; count < np->sysnamecount;++count) { + afs_osi_Free(np->sysname[count], MAXSYSNAME); + } + } + for(count=0; count < *num;++count) { + np->sysname[count]= afs_osi_Alloc(MAXSYSNAME); } - strcpy(np->sysname, inname); + cp = inname; + for(count=0; count < *num;++count) { + t = strlen(cp); + memcpy(np->sysname[count], cp, t+1); /* include null */ + cp += t+1; + } + np->sysnamecount = *num; } else if (!np->sysname) { - return ENODEV; /* XXX */ + return ENODEV; /* XXX */ } - strcpy(outname, np->sysname); + *outname = np->sysname; + *num = np->sysnamecount; return 0; } /* Garbage collect routine for the nfs exporter. When pag is -1 then all entries are removed (used by the nfsclient_shutdown routine); else if it's non zero then only the entry with that pag is removed, else all "timedout" entries are removed. TimedOut entries are those who have no "unixuser" structures associated with them (i.e. unixusercnt == 0) and they haven't had any activity the last NFSCLIENTGC seconds */ -int afs_nfsclient_GC(exporter, pag) -register struct afs_exporter *exporter; -register afs_int32 pag; +int +afs_nfsclient_GC(exporter, pag) + register struct afs_exporter *exporter; + register afs_int32 pag; { register struct nfsclientpag *np, **tnp, *nnp; register afs_int32 i, delflag; @@ -319,17 +346,19 @@ register afs_int32 pag; osi_Assert(ISAFS_GLOCK()); #endif AFS_STATCNT(afs_nfsclient_GC); - MObtainWriteLock(&afs_xnfspag,316); + MObtainWriteLock(&afs_xnfspag, 316); for (i = 0; i < NNFSCLIENTS; i++) { for (tnp = &afs_nfspags[i], np = *tnp; np; np = nnp) { nnp = np->next; delflag = 0; if (np->refCount == 0 && np->lastcall < osi_Time() - NFSCLIENTGC) delflag = 1; - if ((pag == -1) || (!pag && delflag) || (pag && (np->refCount == 0) && (np->pag == pag))) { + if ((pag == -1) || (!pag && delflag) + || (pag && (np->refCount == 0) && (np->pag == pag))) { *tnp = np->next; - if (np->sysname) afs_osi_Free(np->sysname, MAXSYSNAME); - afs_osi_Free(np, sizeof(struct nfsclientpag)); + if (np->sysname) + afs_osi_Free(np->sysname, MAXSYSNAME); + afs_osi_Free(np, sizeof(struct nfsclientpag)); } else { tnp = &np->next; } @@ -339,8 +368,9 @@ register afs_int32 pag; } -int afs_nfsclient_stats(export) -register struct afs_exporter *export; +int +afs_nfsclient_stats(export) + register struct afs_exporter *export; { /* Nothing much to do here yet since most important stats are collected directly in the afs_exporter structure itself */ AFS_STATCNT(afs_nfsclient_stats); @@ -359,37 +389,39 @@ char *afs_nfs_id = "AFSNFSTRANS"; /* afs_iauth_verify is the AFS authenticator for NFS. * * always returns 0. - */ -int afs_iauth_verify(long id, fsid_t *fsidp, long host, - int uid, struct AFS_UCRED *credp, struct exportinfo *exp) + */ +int +afs_iauth_verify(long id, fsid_t * fsidp, long host, int uid, + struct AFS_UCRED *credp, struct exportinfo *exp) { int code; struct nfsclientpag *nfs_pag; afs_int32 dummypag; struct afs_exporter *outexporter = 0; - + /* Still needs basic test to see if exporter is on. And need to check the * whole no submounts bit. */ if (id != (long)id) - return 0; /* not us. */ + return 0; /* not us. */ /* Only care if it's AFS */ if ((fsidp->val[0] != AFS_VFSMAGIC) || (fsidp->val[1] != AFS_VFSFSID)) { - return 0; + return 0; } AFS_GLOCK(); - code = afs_nfsclient_reqhandler((struct afs_exporter *)0, &credp, - host, &dummypag, &outexporter); + code = + afs_nfsclient_reqhandler((struct afs_exporter *)0, &credp, host, + &dummypag, &outexporter); if (!code && outexporter) EXP_RELE(outexporter); if (code) { /* ensure anonymous cred. */ - credp->cr_uid = credp->cr_ruid = (uid_t)-2; /* anonymous */ + credp->cr_uid = credp->cr_ruid = (uid_t) - 2; /* anonymous */ } /* Mark this thread as an NFS translator thread. */ @@ -402,7 +434,8 @@ int afs_iauth_verify(long id, fsid_t *fsidp, long host, /* afs_iauth_register - register the iauth verify routine. Returns 0 on success * and -1 on failure. Can fail because DFS has already registered. */ -int afs_iauth_register() +int +afs_iauth_register() { if (nfs_iauth_register((unsigned long)afs_nfs_id, afs_iauth_verify)) return -1; @@ -414,7 +447,8 @@ int afs_iauth_register() /* afs_iauth_unregister - unregister the iauth verify routine. Called on shutdown. */ -void afs_iauth_unregister() +void +afs_iauth_unregister() { if (afs_iauth_initd) nfs_iauth_unregister((unsigned long)afs_nfs_id); @@ -424,7 +458,8 @@ void afs_iauth_unregister() -shutdown_nfsclnt() { +shutdown_nfsclnt() +{ #if 0 extern int afs_allnfsreqs, afs_nfscalls; #endif @@ -432,7 +467,7 @@ shutdown_nfsclnt() { #if defined(AFS_SGIMP_ENV) osi_Assert(ISAFS_GLOCK()); #endif - AFS_STATCNT(afs_nfsclient_shutdown); + AFS_STATCNT(afs_nfsclient_shutdown); #ifdef AFS_AIX_IAUTH_ENV afs_iauth_register(); #endif @@ -445,4 +480,3 @@ shutdown_nfsclnt() { } #endif /* AFS_DEC_ENV */ #endif /* AFS_NONFSTRANS */ - diff --git a/src/afs/afs_nfsdisp.c b/src/afs/afs_nfsdisp.c index 5dcbee60c..b4e93b47b 100644 --- a/src/afs/afs_nfsdisp.c +++ b/src/afs/afs_nfsdisp.c @@ -8,54 +8,55 @@ * Implements: */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_nfsdisp.c,v 1.1.1.6 2003/04/13 19:02:36 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_nfsdisp.c,v 1.18 2003/07/15 23:14:12 shadow Exp $"); /* Ugly Ugly Ugly but precludes conflicting XDR macros; We want kernel xdr */ #define __XDR_INCLUDE__ -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#if defined(AFS_SUN55_ENV) && !defined(AFS_NONFSTRANS) -#include "../rpc/types.h" -#include "../rpc/auth.h" -#include "../rpc/auth_unix.h" -#include "../rpc/auth_des.h" +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#if defined(AFS_SUN55_ENV) && !defined(AFS_NONFSTRANS) +#include "rpc/types.h" +#include "rpc/auth.h" +#include "rpc/auth_unix.h" +#include "rpc/auth_des.h" #if !defined(AFS_SUN58_ENV) -#include "../rpc/auth_kerb.h" +#include "rpc/auth_kerb.h" #endif -#include "../sys/tiuser.h" -#include "../rpc/xdr.h" -#include "../rpc/svc.h" -#include "../nfs/nfs.h" -#include "../nfs/export.h" -#include "../nfs/nfs_clnt.h" -#include "../nfs/nfs_acl.h" -#include "../afs/afsincludes.h" -#include "../afs/afs_stats.h" -#include "../afs/exporter.h" - -static int xlatorinit_v2_done=0; -static int xlatorinit_v3_done=0; +#include "sys/tiuser.h" +#include "rpc/xdr.h" +#include "rpc/svc.h" +#include "nfs/nfs.h" +#include "nfs/export.h" +#include "nfs/nfs_clnt.h" +#include "nfs/nfs_acl.h" +#include "afs/afsincludes.h" +#include "afs/afs_stats.h" +#include "afs/exporter.h" + +static int xlatorinit_v2_done = 0; +static int xlatorinit_v3_done = 0; extern int afs_nobody; extern int afs_NFSRootOnly; struct rfs_disp_tbl { - void (*dis_proc)(); + void (*dis_proc) (); xdrproc_t dis_xdrargs; xdrproc_t dis_fastxdrargs; - int dis_argsz; - xdrproc_t dis_xdrres; - xdrproc_t dis_fastxdrres; - int dis_ressz; - void (*dis_resfree)(); - int dis_flags; - fhandle_t (*dis_getfh)(); + int dis_argsz; + xdrproc_t dis_xdrres; + xdrproc_t dis_fastxdrres; + int dis_ressz; + void (*dis_resfree) (); + int dis_flags; + fhandle_t(*dis_getfh) (); }; struct afs_nfs_disp_tbl { - void (*afs_proc)(); - void (*orig_proc)(); + void (*afs_proc) (); + void (*orig_proc) (); }; struct afs_nfs2_resp { enum nfsstat status; @@ -68,106 +69,109 @@ struct afs_nfs_disp_tbl afs_rfs_disp_tbl[RFS_NPROC]; struct afs_nfs_disp_tbl afs_acl_disp_tbl[ACL2_NPROC]; static int -is_afs_fh(fhandle_t *fhp) { - if ((fhp->fh_fsid.val[0] == AFS_VFSMAGIC) && - (fhp->fh_fsid.val[1] == AFS_VFSFSID)) +is_afs_fh(fhandle_t * fhp) +{ + if ((fhp->fh_fsid.val[0] == AFS_VFSMAGIC) + && (fhp->fh_fsid.val[1] == AFS_VFSFSID)) return 1; return 0; } afs_int32 -nfs2_to_afs_call(int which, caddr_t *args, fhandle_t **fhpp, fhandle_t **fh2pp) +nfs2_to_afs_call(int which, caddr_t * args, fhandle_t ** fhpp, + fhandle_t ** fh2pp) { struct vnode *vp; - fhandle_t *fhp1=0; - fhandle_t *fhp2=0; + fhandle_t *fhp1 = 0; + fhandle_t *fhp2 = 0; int errorcode; - - *fh2pp = (fhandle_t *)0; + + afs_Trace1(afs_iclSetp, CM_TRACE_NFSIN, ICL_TYPE_INT32, which); + *fh2pp = (fhandle_t *) 0; switch (which) { case RFS_GETATTR: case RFS_READLINK: case RFS_STATFS: - fhp1 = (fhandle_t *)args; + fhp1 = (fhandle_t *) args; break; case RFS_SETATTR: - { - struct nfssaargs *sargs = (struct nfssaargs *)args; - fhp1 = (fhandle_t *)&sargs->saa_fh; - break; - } + { + struct nfssaargs *sargs = (struct nfssaargs *)args; + fhp1 = (fhandle_t *) & sargs->saa_fh; + break; + } case RFS_LOOKUP: - { - struct nfsdiropargs *sargs = (struct nfsdiropargs *)args; - fhp1 = sargs->da_fhandle; - break; - } + { + struct nfsdiropargs *sargs = (struct nfsdiropargs *)args; + fhp1 = sargs->da_fhandle; + break; + } case RFS_READ: - { - struct nfsreadargs *sargs = (struct nfsreadargs *)args; - fhp1 = (fhandle_t *)&sargs->ra_fhandle; - break; - } + { + struct nfsreadargs *sargs = (struct nfsreadargs *)args; + fhp1 = (fhandle_t *) & sargs->ra_fhandle; + break; + } case RFS_WRITE: - { - struct nfswriteargs *sargs = (struct nfswriteargs *)args; - fhp1 = (fhandle_t *)&sargs->wa_fhandle; - break; - } + { + struct nfswriteargs *sargs = (struct nfswriteargs *)args; + fhp1 = (fhandle_t *) & sargs->wa_fhandle; + break; + } case RFS_CREATE: - { - struct nfscreatargs *sargs = (struct nfscreatargs *)args; - fhp1 = sargs->ca_da.da_fhandle; - break; - } + { + struct nfscreatargs *sargs = (struct nfscreatargs *)args; + fhp1 = sargs->ca_da.da_fhandle; + break; + } case RFS_REMOVE: - { - struct nfsdiropargs *sargs = (struct nfsdiropargs *)args; - fhp1 = sargs->da_fhandle; - break; - } + { + struct nfsdiropargs *sargs = (struct nfsdiropargs *)args; + fhp1 = sargs->da_fhandle; + break; + } case RFS_RENAME: - { - struct nfsrnmargs *sargs = (struct nfsrnmargs *)args; - fhp1 = sargs->rna_from.da_fhandle; - fhp2 = sargs->rna_to.da_fhandle; - break; - } + { + struct nfsrnmargs *sargs = (struct nfsrnmargs *)args; + fhp1 = sargs->rna_from.da_fhandle; + fhp2 = sargs->rna_to.da_fhandle; + break; + } case RFS_LINK: - { - struct nfslinkargs *sargs = (struct nfslinkargs *)args; - fhp1 = sargs->la_from; - fhp2 = sargs->la_to.da_fhandle; - break; - } + { + struct nfslinkargs *sargs = (struct nfslinkargs *)args; + fhp1 = sargs->la_from; + fhp2 = sargs->la_to.da_fhandle; + break; + } case RFS_SYMLINK: - { - struct nfsslargs *sargs = (struct nfsslargs *)args; - fhp1 = sargs->sla_from.da_fhandle; - break; - } + { + struct nfsslargs *sargs = (struct nfsslargs *)args; + fhp1 = sargs->sla_from.da_fhandle; + break; + } case RFS_MKDIR: - { - struct nfscreatargs *sargs = (struct nfscreatargs *)args; - fhp1 = sargs->ca_da.da_fhandle; - break; - } + { + struct nfscreatargs *sargs = (struct nfscreatargs *)args; + fhp1 = sargs->ca_da.da_fhandle; + break; + } case RFS_RMDIR: - { - struct nfsdiropargs *sargs = (struct nfsdiropargs *)args; - fhp1 = sargs->da_fhandle; - break; - } + { + struct nfsdiropargs *sargs = (struct nfsdiropargs *)args; + fhp1 = sargs->da_fhandle; + break; + } case RFS_READDIR: - { - struct nfsrddirargs *sargs = (struct nfsrddirargs *)args; - fhp1 = (fhandle_t *)&sargs->rda_fh; - break; - } + { + struct nfsrddirargs *sargs = (struct nfsrddirargs *)args; + fhp1 = (fhandle_t *) & sargs->rda_fh; + break; + } default: return NULL; } - + /* Ok if arg 1 is in AFS or if 2 args and arg 2 is in AFS */ if (is_afs_fh(fhp1)) { *fhpp = fhp1; @@ -184,70 +188,70 @@ nfs2_to_afs_call(int which, caddr_t *args, fhandle_t **fhpp, fhandle_t **fh2pp) } afs_int32 -acl2_to_afs_call(int which, caddr_t *args, fhandle_t **fhpp) +acl2_to_afs_call(int which, caddr_t * args, fhandle_t ** fhpp) { fhandle_t *fhp; - - switch(which) { + + switch (which) { case ACLPROC2_NULL: - { - return NULL; - } + { + return NULL; + } case ACLPROC2_GETACL: - { - struct GETACL2args *sargs = (struct GETACL2args *) args; - fhp = &sargs->fh; - break; - } + { + struct GETACL2args *sargs = (struct GETACL2args *)args; + fhp = &sargs->fh; + break; + } case ACLPROC2_SETACL: - { - struct SETACL2args *sargs = (struct SETACL2args *) args; - fhp = &sargs->fh; - break; - } + { + struct SETACL2args *sargs = (struct SETACL2args *)args; + fhp = &sargs->fh; + break; + } case ACLPROC2_GETATTR: - { - struct GETATTR2args *sargs = (struct GETATTR2args *) args; - fhp = &sargs->fh; - break; - } + { + struct GETATTR2args *sargs = (struct GETATTR2args *)args; + fhp = &sargs->fh; + break; + } case ACLPROC2_ACCESS: - { - struct ACCESS2args *sargs = (struct ACCESS2args *) args; - fhp = &sargs->fh; - break; - } + { + struct ACCESS2args *sargs = (struct ACCESS2args *)args; + fhp = &sargs->fh; + break; + } default: return NULL; } - + if (is_afs_fh(fhp)) { *fhpp = fhp; return 1; } - + return NULL; } int afs_nfs2_dispatcher(int type, afs_int32 which, char *argp, - struct exportinfo **expp, - struct svc_req *rp, struct AFS_UCRED *crp) + struct exportinfo **expp, struct svc_req *rp, + struct AFS_UCRED *crp) { afs_int32 call = 0; afs_int32 code = 0; afs_int32 client = 0; struct sockaddr *sa; - fhandle_t *fh = (fhandle_t *)argp; - fhandle_t *fh2 = (fhandle_t *)0; - + fhandle_t *fh = (fhandle_t *) argp; + fhandle_t *fh2 = (fhandle_t *) 0; + if (!xlatorinit_v2_done) return 2; - + sa = (struct sockaddr *)svc_getrpccaller(rp->rq_xprt)->buf; if (sa->sa_family == AF_INET) client = ((struct sockaddr_in *)sa)->sin_addr.s_addr; - + AFS_GLOCK(); code = 0; switch (type) { @@ -260,17 +264,16 @@ afs_nfs2_dispatcher(int type, afs_int32 which, char *argp, default: break; } - + if (code) { struct afs_exporter *out = 0; afs_int32 dummy; static int once = 0; struct SmallFid Sfid; - + memcpy((char *)&Sfid, fh->fh_data, SIZEOF_SMALLFID); - - afs_Trace2(afs_iclSetp, CM_TRACE_NFSIN1, - ICL_TYPE_POINTER, client, + + afs_Trace2(afs_iclSetp, CM_TRACE_NFSIN1, ICL_TYPE_POINTER, client, ICL_TYPE_FID, &Sfid); /* We ran */ @@ -279,16 +282,17 @@ afs_nfs2_dispatcher(int type, afs_int32 which, char *argp, afs_nobody = (*expp)->exi_export.ex_anon; once = 1; } - code = afs_nfsclient_reqhandler((struct afs_exporter *)0, &crp, - client, &dummy, &out); - + code = + afs_nfsclient_reqhandler((struct afs_exporter *)0, &crp, client, + &dummy, &out); + if (!code && out) EXP_RELE(out); - + if (code == EINVAL) call = 2; } - + AFS_GUNLOCK(); return call; } @@ -296,41 +300,40 @@ afs_nfs2_dispatcher(int type, afs_int32 which, char *argp, void afs_nfs2_smallfidder(struct nfsdiropres *dr) { - register fhandle_t *fhp = (fhandle_t *)&dr->dr_fhandle; + register fhandle_t *fhp = (fhandle_t *) & dr->dr_fhandle; afs_int32 addr[2]; struct vcache *vcp; - + #if defined(AFS_SUN57_64BIT_ENV) - /* See also afs_fid() */ + /* See also afs_fid() */ memcpy((char *)addr, fhp->fh_data, SIZEOF_SMALLFID); addr[1] = (addr[1] >> 48) & 0xffff; -#else +#else memcpy((char *)addr, fhp->fh_data, 2 * sizeof(long)); #endif - + AFS_GLOCK(); - vcp = VTOAFS((struct vnode*)addr[0]); - - if (addr[1] == AFS_XLATOR_MAGIC) - { + vcp = VTOAFS((struct vnode *)addr[0]); + + if (addr[1] == AFS_XLATOR_MAGIC) { if (dr->dr_status == NFS_OK) { struct SmallFid Sfid; struct cell *tcell; - + /* Make up and copy out a SmallFid */ tcell = afs_GetCell(vcp->fid.Cell, READ_LOCK); Sfid.Volume = vcp->fid.Fid.Volume; - Sfid.CellAndUnique = ((tcell->cellIndex << 24) | - (vcp->fid.Fid.Unique & 0xffffff)); + Sfid.CellAndUnique = + ((tcell->cellIndex << 24) | (vcp->fid.Fid.Unique & 0xffffff)); afs_PutCell(tcell, READ_LOCK); - Sfid.Vnode = (u_short)(vcp->fid.Fid.Vnode & 0xffff); + Sfid.Vnode = (u_short) (vcp->fid.Fid.Vnode & 0xffff); fhp->fh_len = SIZEOF_SMALLFID; - memcpy(dr->dr_fhandle.fh_data, (char*)&Sfid, fhp->fh_len); + memcpy(dr->dr_fhandle.fh_data, (char *)&Sfid, fhp->fh_len); afs_Trace3(afs_iclSetp, CM_TRACE_NFSOUT, ICL_TYPE_INT32, 0, - ICL_TYPE_POINTER, vcp, ICL_TYPE_FID, &Sfid); + ICL_TYPE_POINTER, vcp, ICL_TYPE_FID, &Sfid); } - + /* If we have a ref, release it */ if (vcp->vrefCount >= 1) AFS_RELE(AFSTOV(vcp)); @@ -344,7 +347,8 @@ afs_nfs2_noaccess(struct afs_nfs2_resp *resp) resp->status = NFSERR_ACCES; } -void afs_nfs2_null(char *args, char *xp, char *exp, char *rp, char *crp) +void +afs_nfs2_null(char *args, char *xp, char *exp, char *rp, char *crp) { } @@ -358,262 +362,353 @@ afs_nfs2_writecache(char *args, char *xp, char *exp, char *rp, char *crp) { } -void afs_nfs2_getattr(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_GETATTR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_GETATTR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_getattr(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_GETATTR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_GETATTR].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_setattr(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_SETATTR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_SETATTR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_setattr(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_SETATTR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_SETATTR].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_lookup(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_LOOKUP, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else { (*afs_rfs_disp_tbl[RFS_LOOKUP].orig_proc)(args, xp, exp, rp, crp); - if (afs_NFSRootOnly && call) afs_nfs2_smallfidder(xp); } - curthread->t_cred = svcred; - return; +void +afs_nfs2_lookup(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_LOOKUP, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else { + (*afs_rfs_disp_tbl[RFS_LOOKUP].orig_proc) (args, xp, exp, rp, crp); + if (afs_NFSRootOnly && call) + afs_nfs2_smallfidder(xp); + } + curthread->t_cred = svcred; + return; } -void afs_nfs2_readlink(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_READLINK, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_READLINK].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_readlink(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_READLINK, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_READLINK].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_read(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_READ, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_READ].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_read(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_READ, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_READ].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_write(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_WRITE, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_WRITE].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_write(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_WRITE, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_WRITE].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_create(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_CREATE, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else { (*afs_rfs_disp_tbl[RFS_CREATE].orig_proc)(args, xp, exp, rp, crp); - if (afs_NFSRootOnly && call) afs_nfs2_smallfidder(xp); } - curthread->t_cred = svcred; - return; +void +afs_nfs2_create(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_CREATE, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else { + (*afs_rfs_disp_tbl[RFS_CREATE].orig_proc) (args, xp, exp, rp, crp); + if (afs_NFSRootOnly && call) + afs_nfs2_smallfidder(xp); + } + curthread->t_cred = svcred; + return; } -void afs_nfs2_remove(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_REMOVE, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_REMOVE].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_remove(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_REMOVE, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_REMOVE].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_rename(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_RENAME, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_RENAME].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_rename(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_RENAME, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_RENAME].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_link(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_LINK, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_LINK].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_link(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_LINK, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_LINK].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_symlink(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_SYMLINK, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_SYMLINK].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_symlink(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_SYMLINK, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_SYMLINK].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_mkdir(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_MKDIR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else { (*afs_rfs_disp_tbl[RFS_MKDIR].orig_proc)(args, xp, exp, rp, crp); - if (afs_NFSRootOnly && call) afs_nfs2_smallfidder(xp); } - curthread->t_cred = svcred; - return; +void +afs_nfs2_mkdir(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_MKDIR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else { + (*afs_rfs_disp_tbl[RFS_MKDIR].orig_proc) (args, xp, exp, rp, crp); + if (afs_NFSRootOnly && call) + afs_nfs2_smallfidder(xp); + } + curthread->t_cred = svcred; + return; } -void afs_nfs2_rmdir(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_RMDIR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_RMDIR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_rmdir(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_RMDIR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_RMDIR].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_readdir(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_READDIR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_READDIR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_readdir(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_READDIR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_READDIR].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs2_statfs(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(0, RFS_STATFS, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_rfs_disp_tbl[RFS_STATFS].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs2_statfs(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs2_dispatcher(0, RFS_STATFS, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_rfs_disp_tbl[RFS_STATFS].orig_proc) (args, xp, exp, rp, crp); + curthread->t_cred = svcred; + return; } struct afs_nfs_disp_tbl afs_rfs_disp_tbl[RFS_NPROC] = { - { afs_nfs2_null }, - { afs_nfs2_getattr }, - { afs_nfs2_setattr }, - { afs_nfs2_root }, - { afs_nfs2_lookup }, - { afs_nfs2_readlink }, - { afs_nfs2_read }, - { afs_nfs2_writecache }, - { afs_nfs2_write }, - { afs_nfs2_create }, - { afs_nfs2_remove }, - { afs_nfs2_rename }, - { afs_nfs2_link }, - { afs_nfs2_symlink }, - { afs_nfs2_mkdir }, - { afs_nfs2_rmdir }, - { afs_nfs2_readdir }, - { afs_nfs2_statfs } + {afs_nfs2_null}, + {afs_nfs2_getattr}, + {afs_nfs2_setattr}, + {afs_nfs2_root}, + {afs_nfs2_lookup}, + {afs_nfs2_readlink}, + {afs_nfs2_read}, + {afs_nfs2_writecache}, + {afs_nfs2_write}, + {afs_nfs2_create}, + {afs_nfs2_remove}, + {afs_nfs2_rename}, + {afs_nfs2_link}, + {afs_nfs2_symlink}, + {afs_nfs2_mkdir}, + {afs_nfs2_rmdir}, + {afs_nfs2_readdir}, + {afs_nfs2_statfs} }; -void afs_acl2_getacl(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(1, ACLPROC2_GETACL, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_acl_disp_tbl[ACLPROC2_GETACL].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_acl2_getacl(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs2_dispatcher(1, ACLPROC2_GETACL, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_acl_disp_tbl[ACLPROC2_GETACL].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_acl2_setacl(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(1, ACLPROC2_SETACL, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_acl_disp_tbl[ACLPROC2_SETACL].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_acl2_setacl(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs2_dispatcher(1, ACLPROC2_SETACL, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_acl_disp_tbl[ACLPROC2_SETACL].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_acl2_getattr(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(1, ACLPROC2_GETATTR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_acl_disp_tbl[ACLPROC2_GETATTR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_acl2_getattr(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs2_dispatcher(1, ACLPROC2_GETATTR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_acl_disp_tbl[ACLPROC2_GETATTR].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_acl2_access(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs2_dispatcher(1, ACLPROC2_ACCESS, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); - else (*afs_acl_disp_tbl[ACLPROC2_ACCESS].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_acl2_access(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs2_dispatcher(1, ACLPROC2_ACCESS, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs2_noaccess((struct afs_nfs2_resp *)xp); + else + (*afs_acl_disp_tbl[ACLPROC2_ACCESS].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } struct afs_nfs_disp_tbl afs_acl_disp_tbl[5] = { - { afs_nfs2_null }, - { afs_acl2_getacl }, - { afs_acl2_setacl }, - { afs_acl2_getattr }, - { afs_acl2_access } + {afs_nfs2_null}, + {afs_acl2_getacl}, + {afs_acl2_setacl}, + {afs_acl2_getattr}, + {afs_acl2_access} }; /* Munge the dispatch tables to link us in first */ void afs_xlatorinit_v2(struct rfs_disp_tbl *_rfs_tbl, - struct rfs_disp_tbl *_acl_tbl) + struct rfs_disp_tbl *_acl_tbl) { int i; - - if (xlatorinit_v2_done++) return; - - for (i=0; i < RFS_NPROC; i++) { + + if (xlatorinit_v2_done++) + return; + + for (i = 0; i < RFS_NPROC; i++) { afs_rfs_disp_tbl[i].orig_proc = _rfs_tbl[i].dis_proc; _rfs_tbl[i].dis_proc = afs_rfs_disp_tbl[i].afs_proc; } - - for (i=0; i < 5; i++) { + + for (i = 0; i < 5; i++) { afs_acl_disp_tbl[i].orig_proc = _acl_tbl[i].dis_proc; _acl_tbl[i].dis_proc = afs_acl_disp_tbl[i].afs_proc; } @@ -637,9 +732,10 @@ struct afs_nfs3_resp { typedef struct afs_nfs3_resp afs_nfs3_resp; static int -is_afs_fh3(nfs_fh3 *fhp) { - if ((fhp->fh3_fsid.val[0] == AFS_VFSMAGIC) && - (fhp->fh3_fsid.val[1] == AFS_VFSFSID)) +is_afs_fh3(nfs_fh3 * fhp) +{ + if ((fhp->fh3_fsid.val[0] == AFS_VFSMAGIC) + && (fhp->fh3_fsid.val[1] == AFS_VFSFSID)) return 1; return 0; } @@ -652,152 +748,152 @@ afs_nfs3_noaccess(struct afs_nfs3_resp *resp) } afs_int32 -nfs3_to_afs_call(int which, caddr_t *args, nfs_fh3 **fhpp, nfs_fh3 **fh2pp) +nfs3_to_afs_call(int which, caddr_t * args, nfs_fh3 ** fhpp, nfs_fh3 ** fh2pp) { struct vnode *vp; - nfs_fh3 *fhp1=0; - nfs_fh3 *fhp2=0; + nfs_fh3 *fhp1 = 0; + nfs_fh3 *fhp2 = 0; int errorcode; - + afs_Trace1(afs_iclSetp, CM_TRACE_NFS3IN, ICL_TYPE_INT32, which); - *fh2pp = (nfs_fh3 *)0; + *fh2pp = (nfs_fh3 *) 0; switch (which) { case NFSPROC3_GETATTR: - { - GETATTR3args *arg = (GETATTR3args *)args; - fhp1 = (nfs_fh3 *) &arg->object; - break; - } + { + GETATTR3args *arg = (GETATTR3args *) args; + fhp1 = (nfs_fh3 *) & arg->object; + break; + } case NFSPROC3_SETATTR: - { - SETATTR3args *arg = (SETATTR3args *)args; - fhp1 = (nfs_fh3 *) &arg->object; - break; - } + { + SETATTR3args *arg = (SETATTR3args *) args; + fhp1 = (nfs_fh3 *) & arg->object; + break; + } case NFSPROC3_LOOKUP: - { - LOOKUP3args *arg = (LOOKUP3args *)args; + { + LOOKUP3args *arg = (LOOKUP3args *) args; #ifdef AFS_SUN58_ENV - fhp1 = (nfs_fh3 *) &arg->what.dirp; + fhp1 = (nfs_fh3 *) arg->what.dirp; #else - fhp1 = (nfs_fh3 *) &arg->what.dir; + fhp1 = (nfs_fh3 *) & arg->what.dir; #endif - break; - } + break; + } case NFSPROC3_ACCESS: - { - ACCESS3args *arg = (ACCESS3args *)args; - fhp1 = (nfs_fh3 *) &arg->object; - break; - } + { + ACCESS3args *arg = (ACCESS3args *) args; + fhp1 = (nfs_fh3 *) & arg->object; + break; + } case NFSPROC3_READLINK: - { - READLINK3args *arg = (READLINK3args *)args; - fhp1 = (nfs_fh3 *) &arg->symlink; - break; - } + { + READLINK3args *arg = (READLINK3args *) args; + fhp1 = (nfs_fh3 *) & arg->symlink; + break; + } case NFSPROC3_READ: - { - READ3args *arg = (READ3args *)args; - fhp1 = (nfs_fh3 *) &arg->file; - break; - } + { + READ3args *arg = (READ3args *) args; + fhp1 = (nfs_fh3 *) & arg->file; + break; + } case NFSPROC3_WRITE: - { - WRITE3args *arg = (WRITE3args *)args; - fhp1 = (nfs_fh3 *) &arg->file; - break; - } + { + WRITE3args *arg = (WRITE3args *) args; + fhp1 = (nfs_fh3 *) & arg->file; + break; + } case NFSPROC3_CREATE: - { - CREATE3args *arg = (CREATE3args *)args; - fhp1 = (nfs_fh3 *) &arg->where.dir; - break; - } + { + CREATE3args *arg = (CREATE3args *) args; + fhp1 = (nfs_fh3 *) & arg->where.dir; + break; + } case NFSPROC3_MKDIR: - { - MKDIR3args *arg = (MKDIR3args *)args; - fhp1 = (nfs_fh3 *) &arg->where.dir; - break; - } + { + MKDIR3args *arg = (MKDIR3args *) args; + fhp1 = (nfs_fh3 *) & arg->where.dir; + break; + } case NFSPROC3_SYMLINK: - { - SYMLINK3args *arg = (SYMLINK3args *)args; - fhp1 = (nfs_fh3 *) &arg->where.dir; - break; - } + { + SYMLINK3args *arg = (SYMLINK3args *) args; + fhp1 = (nfs_fh3 *) & arg->where.dir; + break; + } case NFSPROC3_MKNOD: - { - MKNOD3args *arg = (MKNOD3args *)args; - fhp1 = (nfs_fh3 *) &arg->where.dir; - break; - } + { + MKNOD3args *arg = (MKNOD3args *) args; + fhp1 = (nfs_fh3 *) & arg->where.dir; + break; + } case NFSPROC3_REMOVE: - { - REMOVE3args *arg = (REMOVE3args *)args; - fhp1 = (nfs_fh3 *) &arg->object.dir; - break; - } + { + REMOVE3args *arg = (REMOVE3args *) args; + fhp1 = (nfs_fh3 *) & arg->object.dir; + break; + } case NFSPROC3_RMDIR: - { - RMDIR3args *arg = (RMDIR3args *)args; - fhp1 = (nfs_fh3 *) &arg->object.dir; - break; - } + { + RMDIR3args *arg = (RMDIR3args *) args; + fhp1 = (nfs_fh3 *) & arg->object.dir; + break; + } case NFSPROC3_RENAME: - { - RENAME3args *arg = (RENAME3args *)args; - fhp1 = (nfs_fh3 *) &arg->from.dir; - fhp2 = (nfs_fh3 *) &arg->to.dir; - break; - } + { + RENAME3args *arg = (RENAME3args *) args; + fhp1 = (nfs_fh3 *) & arg->from.dir; + fhp2 = (nfs_fh3 *) & arg->to.dir; + break; + } case NFSPROC3_LINK: - { - LINK3args *arg = (LINK3args *)args; - fhp1 = (nfs_fh3 *) &arg->file; - fhp2 = (nfs_fh3 *) &arg->link.dir; - break; - } + { + LINK3args *arg = (LINK3args *) args; + fhp1 = (nfs_fh3 *) & arg->file; + fhp2 = (nfs_fh3 *) & arg->link.dir; + break; + } case NFSPROC3_READDIR: - { - READDIR3args *arg = (READDIR3args *)args; - fhp1 = (nfs_fh3 *) &arg->dir; - break; - } + { + READDIR3args *arg = (READDIR3args *) args; + fhp1 = (nfs_fh3 *) & arg->dir; + break; + } case NFSPROC3_READDIRPLUS: - { - READDIRPLUS3args *arg = (READDIRPLUS3args *)args; - fhp1 = (nfs_fh3 *) &arg->dir; - break; - } + { + READDIRPLUS3args *arg = (READDIRPLUS3args *) args; + fhp1 = (nfs_fh3 *) & arg->dir; + break; + } case NFSPROC3_FSSTAT: - { - FSSTAT3args *arg = (FSSTAT3args *)args; - fhp1 = (nfs_fh3 *) &arg->fsroot; - break; - } + { + FSSTAT3args *arg = (FSSTAT3args *) args; + fhp1 = (nfs_fh3 *) & arg->fsroot; + break; + } case NFSPROC3_FSINFO: - { - FSINFO3args *arg = (FSINFO3args *)args; - fhp1 = (nfs_fh3 *) &arg->fsroot; - break; - } + { + FSINFO3args *arg = (FSINFO3args *) args; + fhp1 = (nfs_fh3 *) & arg->fsroot; + break; + } case NFSPROC3_PATHCONF: - { - PATHCONF3args *arg = (PATHCONF3args *)args; - fhp1 = (nfs_fh3 *) &arg->object; - break; - } + { + PATHCONF3args *arg = (PATHCONF3args *) args; + fhp1 = (nfs_fh3 *) & arg->object; + break; + } case NFSPROC3_COMMIT: - { - COMMIT3args *arg = (COMMIT3args *)args; - fhp1 = (nfs_fh3 *) &arg->file; - break; - } + { + COMMIT3args *arg = (COMMIT3args *) args; + fhp1 = (nfs_fh3 *) & arg->file; + break; + } default: return NULL; } - + if (is_afs_fh3(fhp1)) { *fhpp = fhp1; if (fhp2) @@ -813,54 +909,54 @@ nfs3_to_afs_call(int which, caddr_t *args, nfs_fh3 **fhpp, nfs_fh3 **fh2pp) } afs_int32 -acl3_to_afs_call(int which, caddr_t *args, nfs_fh3 **fhpp) +acl3_to_afs_call(int which, caddr_t * args, nfs_fh3 ** fhpp) { nfs_fh3 *fhp; - - switch(which) { + + switch (which) { case ACLPROC3_GETACL: - { - struct GETACL3args *sargs = (struct GETACL3args *) args; - fhp = &sargs->fh; - break; - } + { + struct GETACL3args *sargs = (struct GETACL3args *)args; + fhp = &sargs->fh; + break; + } case ACLPROC3_SETACL: - { - struct SETACL3args *sargs = (struct SETACL3args *) args; - fhp = &sargs->fh; - break; - } + { + struct SETACL3args *sargs = (struct SETACL3args *)args; + fhp = &sargs->fh; + break; + } default: return NULL; } - + if (is_afs_fh3(fhp)) { *fhpp = fhp; return 1; } - + return NULL; } int afs_nfs3_dispatcher(int type, afs_int32 which, char *argp, - struct exportinfo **expp, - struct svc_req *rp, struct AFS_UCRED *crp) + struct exportinfo **expp, struct svc_req *rp, + struct AFS_UCRED *crp) { afs_int32 call = 0; afs_int32 code = 0; afs_int32 client = 0; struct sockaddr *sa; - nfs_fh3 *fh = (nfs_fh3 *)argp; - nfs_fh3 *fh2 = (nfs_fh3 *)0; - + nfs_fh3 *fh = (nfs_fh3 *) argp; + nfs_fh3 *fh2 = (nfs_fh3 *) 0; + if (!xlatorinit_v3_done) return 2; - + sa = (struct sockaddr *)svc_getrpccaller(rp->rq_xprt)->buf; - if (sa->sa_family == AF_INET) + if (sa->sa_family == AF_INET) client = ((struct sockaddr_in *)sa)->sin_addr.s_addr; - + AFS_GLOCK(); code = 0; switch (type) { @@ -873,17 +969,16 @@ afs_nfs3_dispatcher(int type, afs_int32 which, char *argp, default: break; } - + if (code) { struct afs_exporter *out = 0; afs_int32 dummy; static int once = 0; struct SmallFid Sfid; - + memcpy((char *)&Sfid, fh->fh3_data, SIZEOF_SMALLFID); - - afs_Trace2(afs_iclSetp, CM_TRACE_NFS3IN1, - ICL_TYPE_INT32, client, + + afs_Trace2(afs_iclSetp, CM_TRACE_NFS3IN1, ICL_TYPE_INT32, client, ICL_TYPE_FID, &Sfid); call = 1; @@ -891,17 +986,18 @@ afs_nfs3_dispatcher(int type, afs_int32 which, char *argp, afs_nobody = (*expp)->exi_export.ex_anon; once = 1; } - code = afs_nfsclient_reqhandler((struct afs_exporter *)0, &crp, - client, &dummy, &out); - + code = + afs_nfsclient_reqhandler((struct afs_exporter *)0, &crp, client, + &dummy, &out); + if (!code && out) EXP_RELE(out); - - + + if (code == EINVAL) call = 2; } - + AFS_GUNLOCK(); return call; } @@ -911,39 +1007,38 @@ afs_nfs3_smallfidder(struct nfs_fh3 *fhp, int status) { afs_int32 addr[2]; struct vcache *vcp; - + #if defined(AFS_SUN57_64BIT_ENV) - /* See also afs_fid() */ + /* See also afs_fid() */ memcpy((char *)addr, fhp->fh3_data, 10); addr[1] = (addr[1] >> 48) & 0xffff; -#else +#else memcpy((char *)addr, fhp->fh3_data, 2 * sizeof(long)); #endif - + AFS_GLOCK(); - vcp = VTOAFS((struct vnode*)addr[0]); - + vcp = VTOAFS((struct vnode *)addr[0]); + /* See also afs_osi_vget */ - if (addr[1] == AFS_XLATOR_MAGIC) - { + if (addr[1] == AFS_XLATOR_MAGIC) { if (status == NFS_OK) { struct SmallFid Sfid; struct cell *tcell; - - /* Make up and copy out a SmallFid */ + + /* Make up and copy out a SmallFid */ tcell = afs_GetCell(vcp->fid.Cell, READ_LOCK); Sfid.Volume = vcp->fid.Fid.Volume; - Sfid.CellAndUnique = ((tcell->cellIndex << 24) | - (vcp->fid.Fid.Unique & 0xffffff)); + Sfid.CellAndUnique = + ((tcell->cellIndex << 24) | (vcp->fid.Fid.Unique & 0xffffff)); afs_PutCell(tcell, READ_LOCK); - Sfid.Vnode = (u_short)(vcp->fid.Fid.Vnode & 0xffff); + Sfid.Vnode = (u_short) (vcp->fid.Fid.Vnode & 0xffff); fhp->fh3_len = SIZEOF_SMALLFID; - memcpy(fhp->fh3_data, (char*)&Sfid, fhp->fh3_len); + memcpy(fhp->fh3_data, (char *)&Sfid, fhp->fh3_len); afs_Trace3(afs_iclSetp, CM_TRACE_NFS3OUT, ICL_TYPE_INT32, status, ICL_TYPE_POINTER, vcp, ICL_TYPE_FID, &Sfid); } - + /* If we have a ref, release it */ if (vcp->vrefCount >= 1) AFS_RELE(AFSTOV(vcp)); @@ -951,340 +1046,491 @@ afs_nfs3_smallfidder(struct nfs_fh3 *fhp, int status) AFS_GUNLOCK(); } -void afs_nfs3_getattr(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_GETATTR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_GETATTR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_getattr(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_GETATTR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_GETATTR].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_setattr(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_SETATTR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_SETATTR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_setattr(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_SETATTR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_SETATTR].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_lookup(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_LOOKUP, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else { (*afs_rfs3_disp_tbl[NFSPROC3_LOOKUP].orig_proc)(args, xp, exp, rp, crp); - if (afs_NFSRootOnly && call) { - LOOKUP3res *resp = ( LOOKUP3res *)xp; - afs_nfs3_smallfidder( &resp->resok.object , resp->status); } } - curthread->t_cred = svcred; - return; +void +afs_nfs3_lookup(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_LOOKUP, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else { + (*afs_rfs3_disp_tbl[NFSPROC3_LOOKUP].orig_proc) (args, xp, exp, rp, + crp); + if (afs_NFSRootOnly && call) { + LOOKUP3res *resp = (LOOKUP3res *) xp; + afs_nfs3_smallfidder(&resp->resok.object, resp->status); + } + } + curthread->t_cred = svcred; + return; } -void afs_nfs3_access(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_ACCESS, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_ACCESS].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_access(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_ACCESS, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_ACCESS].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_readlink(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_READLINK, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_READLINK].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_readlink(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_READLINK, (char *)args, &exp, rp, + crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_READLINK].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_read(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_READ, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_READ].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_read(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs3_dispatcher(0, NFSPROC3_READ, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_READ].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_write(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_WRITE, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_WRITE].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_write(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_WRITE, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_WRITE].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_create(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_CREATE, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else { (*afs_rfs3_disp_tbl[NFSPROC3_CREATE].orig_proc)(args, xp, exp, rp, crp); - if (afs_NFSRootOnly && call) { - CREATE3res *resp = ( CREATE3res *)xp; - afs_nfs3_smallfidder( &resp->resok.obj.handle , resp->status); } } - curthread->t_cred = svcred; - return; + +void +afs_nfs3_create(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_CREATE, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else { + (*afs_rfs3_disp_tbl[NFSPROC3_CREATE].orig_proc) (args, xp, exp, rp, + crp); + if (afs_NFSRootOnly && call) { + CREATE3res *resp = (CREATE3res *) xp; + afs_nfs3_smallfidder(&resp->resok.obj.handle, resp->status); + } + } + curthread->t_cred = svcred; + return; } -void afs_nfs3_mkdir(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_MKDIR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else { (*afs_rfs3_disp_tbl[NFSPROC3_MKDIR].orig_proc)(args, xp, exp, rp, crp); - if (afs_NFSRootOnly && call) { - MKDIR3res *resp = ( MKDIR3res *)xp; - afs_nfs3_smallfidder( &resp->resok.obj.handle , resp->status); } } - curthread->t_cred = svcred; - return; +void +afs_nfs3_mkdir(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_MKDIR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else { + (*afs_rfs3_disp_tbl[NFSPROC3_MKDIR].orig_proc) (args, xp, exp, rp, + crp); + if (afs_NFSRootOnly && call) { + MKDIR3res *resp = (MKDIR3res *) xp; + afs_nfs3_smallfidder(&resp->resok.obj.handle, resp->status); + } + } + curthread->t_cred = svcred; + return; } -void afs_nfs3_symlink(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_SYMLINK, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else { (*afs_rfs3_disp_tbl[NFSPROC3_SYMLINK].orig_proc)(args, xp, exp, rp, crp); - if (afs_NFSRootOnly && call) { - SYMLINK3res *resp = ( SYMLINK3res *)xp; - afs_nfs3_smallfidder( &resp->resok.obj.handle , resp->status); } } - curthread->t_cred = svcred; - return; +void +afs_nfs3_symlink(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_SYMLINK, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else { + (*afs_rfs3_disp_tbl[NFSPROC3_SYMLINK].orig_proc) (args, xp, exp, rp, + crp); + if (afs_NFSRootOnly && call) { + SYMLINK3res *resp = (SYMLINK3res *) xp; + afs_nfs3_smallfidder(&resp->resok.obj.handle, resp->status); + } + } + curthread->t_cred = svcred; + return; } -void afs_nfs3_mknod(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_MKNOD, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else { (*afs_rfs3_disp_tbl[NFSPROC3_MKNOD].orig_proc)(args, xp, exp, rp, crp); - if (afs_NFSRootOnly && call) { - MKNOD3res *resp = ( MKNOD3res *)xp; - afs_nfs3_smallfidder( &resp->resok.obj.handle , resp->status); } } - curthread->t_cred = svcred; - return; +void +afs_nfs3_mknod(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_MKNOD, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else { + (*afs_rfs3_disp_tbl[NFSPROC3_MKNOD].orig_proc) (args, xp, exp, rp, + crp); + if (afs_NFSRootOnly && call) { + MKNOD3res *resp = (MKNOD3res *) xp; + afs_nfs3_smallfidder(&resp->resok.obj.handle, resp->status); + } + } + curthread->t_cred = svcred; + return; } -void afs_nfs3_remove(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_REMOVE, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_REMOVE].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_remove(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_REMOVE, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_REMOVE].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_rmdir(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_RMDIR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_RMDIR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_rmdir(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_RMDIR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_RMDIR].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_rename(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_RENAME, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_RENAME].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_rename(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_RENAME, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_RENAME].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_link(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_LINK, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_LINK].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_link(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = afs_nfs3_dispatcher(0, NFSPROC3_LINK, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_LINK].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_readdir(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_READDIR, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_READDIR].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_readdir(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_READDIR, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_READDIR].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_readdirplus(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_READDIRPLUS, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_READDIRPLUS].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_readdirplus(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_READDIRPLUS, (char *)args, &exp, rp, + crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_READDIRPLUS].orig_proc) (args, xp, exp, + rp, crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_fsstat(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_FSSTAT, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_FSSTAT].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_fsstat(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_FSSTAT, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_FSSTAT].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_fsinfo(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_FSINFO, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_FSINFO].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_fsinfo(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_FSINFO, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_FSINFO].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_pathconf(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_PATHCONF, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_PATHCONF].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_pathconf(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_PATHCONF, (char *)args, &exp, rp, + crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_PATHCONF].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_nfs3_commit(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - afs_nfs3_resp dummy; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(0, NFSPROC3_COMMIT, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_rfs3_disp_tbl[NFSPROC3_COMMIT].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_nfs3_commit(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + afs_nfs3_resp dummy; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(0, NFSPROC3_COMMIT, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_rfs3_disp_tbl[NFSPROC3_COMMIT].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } struct afs_nfs_disp_tbl afs_rfs3_disp_tbl[22] = { - { afs_nfs2_null }, - { afs_nfs3_getattr }, - { afs_nfs3_setattr }, - { afs_nfs3_lookup }, - { afs_nfs3_access }, - { afs_nfs3_readlink }, - { afs_nfs3_read }, - { afs_nfs3_write }, - { afs_nfs3_create }, - { afs_nfs3_mkdir }, - { afs_nfs3_symlink }, - { afs_nfs3_mknod }, - { afs_nfs3_remove }, - { afs_nfs3_rmdir }, - { afs_nfs3_rename }, - { afs_nfs3_link }, - { afs_nfs3_readdir }, - { afs_nfs3_readdirplus }, - { afs_nfs3_fsstat }, - { afs_nfs3_fsinfo }, - { afs_nfs3_pathconf }, - { afs_nfs3_commit } + {afs_nfs2_null}, + {afs_nfs3_getattr}, + {afs_nfs3_setattr}, + {afs_nfs3_lookup}, + {afs_nfs3_access}, + {afs_nfs3_readlink}, + {afs_nfs3_read}, + {afs_nfs3_write}, + {afs_nfs3_create}, + {afs_nfs3_mkdir}, + {afs_nfs3_symlink}, + {afs_nfs3_mknod}, + {afs_nfs3_remove}, + {afs_nfs3_rmdir}, + {afs_nfs3_rename}, + {afs_nfs3_link}, + {afs_nfs3_readdir}, + {afs_nfs3_readdirplus}, + {afs_nfs3_fsstat}, + {afs_nfs3_fsinfo}, + {afs_nfs3_pathconf}, + {afs_nfs3_commit} }; -void afs_acl3_getacl(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(1, ACLPROC3_GETACL, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_acl3_disp_tbl[ACLPROC3_GETACL].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_acl3_getacl(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(1, ACLPROC3_GETACL, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_acl3_disp_tbl[ACLPROC3_GETACL].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } -void afs_acl3_setacl(char *args, char *xp, char *exp, char *rp, char *crp) { - u_int call; - struct cred *svcred = curthread->t_cred; - curthread->t_cred = (struct cred*)crp; - call=afs_nfs3_dispatcher(1, ACLPROC3_SETACL, (char *)args, &exp, rp, crp); - if (call>1) afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); - else (*afs_acl3_disp_tbl[ACLPROC3_SETACL].orig_proc)(args, xp, exp, rp, crp); - curthread->t_cred = svcred; - return; +void +afs_acl3_setacl(char *args, char *xp, char *exp, char *rp, char *crp) +{ + u_int call; + struct cred *svcred = curthread->t_cred; + curthread->t_cred = (struct cred *)crp; + call = + afs_nfs3_dispatcher(1, ACLPROC3_SETACL, (char *)args, &exp, rp, crp); + if (call > 1) + afs_nfs3_noaccess((struct afs_nfs3_resp *)xp); + else + (*afs_acl3_disp_tbl[ACLPROC3_SETACL].orig_proc) (args, xp, exp, rp, + crp); + curthread->t_cred = svcred; + return; } struct afs_nfs_disp_tbl afs_acl3_disp_tbl[3] = { - { afs_nfs2_null }, - { afs_acl3_getacl }, - { afs_acl3_setacl }, + {afs_nfs2_null}, + {afs_acl3_getacl}, + {afs_acl3_setacl}, }; /* Munge the dispatch tables to link us in first */ void afs_xlatorinit_v3(struct rfs_disp_tbl *_rfs_tbl, - struct rfs_disp_tbl *_acl_tbl) + struct rfs_disp_tbl *_acl_tbl) { int i; - - if (xlatorinit_v3_done++) return; - - for (i=0; i < 22; i++) { + + if (xlatorinit_v3_done++) + return; + + for (i = 0; i < 22; i++) { afs_rfs3_disp_tbl[i].orig_proc = _rfs_tbl[i].dis_proc; _rfs_tbl[i].dis_proc = afs_rfs3_disp_tbl[i].afs_proc; } - - for (i=0; i < 3; i++) { + + for (i = 0; i < 3; i++) { afs_acl3_disp_tbl[i].orig_proc = _acl_tbl[i].dis_proc; _acl_tbl[i].dis_proc = afs_acl3_disp_tbl[i].afs_proc; } diff --git a/src/afs/afs_osi.c b/src/afs/afs_osi.c index 6936ff39b..145d6e465 100644 --- a/src/afs/afs_osi.c +++ b/src/afs/afs_osi.c @@ -1,26 +1,26 @@ /* * Copyright 2000, International Business Machines Corporation and others. * All Rights Reserved. - * + * * This software has been released under the terms of the IBM Public * License. For details, see the LICENSE file in the top-level source * directory or online at http://www.openafs.org/dl/license10.html */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_osi.c,v 1.1.1.14 2003/07/30 17:08:00 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_osi.c,v 1.44 2004/04/21 02:20:21 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ #ifdef AFS_AIX_ENV #include /* for vm_att(), vm_det() */ #endif -static char memZero; /* address of 0 bytes for kmem_alloc */ -extern int afs_osicred_initialized; +static char memZero; /* address of 0 bytes for kmem_alloc */ struct osimem { struct osimem *next; @@ -40,63 +40,76 @@ lock_t afs_event_lock; flid_t osi_flid; #endif -void osi_Init() +struct AFS_UCRED *afs_osi_credp; + +void +osi_Init(void) { static int once = 0; - if (once++ > 0) /* just in case */ + if (once++ > 0) /* just in case */ return; #if defined(AFS_HPUX_ENV) osi_InitGlock(); -#else /* AFS_HPUX_ENV */ +#else /* AFS_HPUX_ENV */ #if defined(AFS_GLOBAL_SUNLOCK) #if defined(AFS_SGI62_ENV) mutex_init(&afs_global_lock, MUTEX_DEFAULT, "afs_global_lock"); #elif defined(AFS_OSF_ENV) usimple_lock_init(&afs_global_lock); - afs_global_owner = (thread_t)0; -#elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) + afs_global_owner = (thread_t) 0; +#elif defined(AFS_FBSD50_ENV) + mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); +#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); afs_global_owner = 0; #elif defined(AFS_AIX41_ENV) - lock_alloc((void*)&afs_global_lock, LOCK_ALLOC_PIN, 1, 1); + lock_alloc((void *)&afs_global_lock, LOCK_ALLOC_PIN, 1, 1); simple_lock_init((void *)&afs_global_lock); -#else -#ifndef AFS_LINUX22_ENV - /* Linux initialization in osi directory. Should move the others. */ +#elif !defined(AFS_LINUX22_ENV) + /* Linux initialization in osi directory. Should move the others. */ mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL); -#endif #endif /* afs_rxglobal_lock is initialized in rx_Init. */ +#endif /* AFS_GLOBAL_SUNLOCK */ +#endif /* AFS_HPUX_ENV */ + + if (!afs_osicred_initialized) { +#if defined(AFS_LINUX26_ENV) + afs_osi_credp = crref(); +#elif defined(AFS_XBSD_ENV) + /* Can't just invent one, must use crget() because of mutex */ + afs_osi_credp = crdup(osi_curcred()); +#else + memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED)); + crhold(&afs_osi_cred); /* don't let it evaporate */ + afs_osi_credp = &afs_osi_cred; #endif -#endif /* AFS_HPUX_ENV */ - - if ( !afs_osicred_initialized ) - { - memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED)); - crhold(&afs_osi_cred); /* don't let it evaporate */ - afs_osicred_initialized = 1; - } + afs_osicred_initialized = 1; + } #ifdef AFS_SGI64_ENV - osi_flid.fl_pid = osi_flid.fl_sysid = 0; + osi_flid.fl_pid = osi_flid.fl_sysid = 0; #endif + + init_et_to_sys_error(); } -osi_Active(avc) -register struct vcache *avc; { +int +osi_Active(register struct vcache *avc) +{ AFS_STATCNT(osi_Active); -#if defined(AFS_SUN_ENV) || defined(AFS_AIX_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || (AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - if ((avc->opens > 0) || (avc->states & CMAPPED)) return 1; /* XXX: Warning, verify this XXX */ -#else -#if defined(AFS_MACH_ENV) - if (avc->opens > 0 || ((avc->v.v_flag & VTEXT) && !inode_uncache_try(avc))) return 1; -#else -#if defined(AFS_SGI_ENV) +#if defined(AFS_SUN_ENV) || defined(AFS_AIX_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || (AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + if ((avc->opens > 0) || (avc->states & CMAPPED)) + return 1; /* XXX: Warning, verify this XXX */ +#elif defined(AFS_MACH_ENV) + if (avc->opens > 0 + || ((avc->v.v_flag & VTEXT) && !inode_uncache_try(avc))) + return 1; +#elif defined(AFS_SGI_ENV) if ((avc->opens > 0) || AFS_VN_MAPPED(AFSTOV(avc))) - return 1; + return 1; #else - if (avc->opens > 0 || (AFSTOV(avc)->v_flag & VTEXT)) return(1); -#endif -#endif /* AFS_MACH_ENV */ + if (avc->opens > 0 || (AFSTOV(avc)->v_flag & VTEXT)) + return (1); #endif return 0; } @@ -110,25 +123,24 @@ register struct vcache *avc; { avc->pvnLock is already held, avc->lock is guaranteed not to be held (by us, of course). */ -void osi_FlushPages(avc, credp) - register struct vcache *avc; - struct AFS_UCRED *credp; +void +osi_FlushPages(register struct vcache *avc, struct AFS_UCRED *credp) { afs_hyper_t origDV; ObtainReadLock(&avc->lock); /* If we've already purged this version, or if we're the ones - writing this version, don't flush it (could lose the - data we're writing). */ - if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0) || - ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) { + * writing this version, don't flush it (could lose the + * data we're writing). */ + if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0) + || ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) { ReleaseReadLock(&avc->lock); return; } ReleaseReadLock(&avc->lock); - ObtainWriteLock(&avc->lock,10); + ObtainWriteLock(&avc->lock, 10); /* Check again */ - if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0) || - ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) { + if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0) + || ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) { ReleaseWriteLock(&avc->lock); return; } @@ -141,16 +153,16 @@ void osi_FlushPages(avc, credp) AFS_STATCNT(osi_FlushPages); hset(origDV, avc->m.DataVersion); afs_Trace3(afs_iclSetp, CM_TRACE_FLUSHPAGES, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, origDV.low, ICL_TYPE_INT32, avc->m.Length); + ICL_TYPE_INT32, origDV.low, ICL_TYPE_INT32, avc->m.Length); ReleaseWriteLock(&avc->lock); AFS_GUNLOCK(); osi_VM_FlushPages(avc, credp); AFS_GLOCK(); - ObtainWriteLock(&avc->lock,88); + ObtainWriteLock(&avc->lock, 88); /* do this last, and to original version, since stores may occur - while executing above PUTPAGE call */ + * while executing above PUTPAGE call */ hset(avc->mapDV, origDV); ReleaseWriteLock(&avc->lock); } @@ -166,30 +178,32 @@ afs_lock_t afs_ftf; /* flush text lock */ * shouldn't do anything that would discard newly written data before * it is written to the file system. */ -void osi_FlushText_really(vp) - register struct vcache *vp; { - afs_hyper_t fdv; /* version before which we'll flush */ +void +osi_FlushText_really(register struct vcache *vp) +{ + afs_hyper_t fdv; /* version before which we'll flush */ AFS_STATCNT(osi_FlushText); /* see if we've already flushed this data version */ - if (hcmp(vp->m.DataVersion, vp->flushDV) <= 0) return; + if (hcmp(vp->m.DataVersion, vp->flushDV) <= 0) + return; -#ifdef AFS_DEC_ENV +#ifdef AFS_DEC_ENV { - void afs_gfs_FlushText(); - afs_gfs_FlushText(vp); - return; + void afs_gfs_FlushText(); + afs_gfs_FlushText(vp); + return; } #else - MObtainWriteLock(&afs_ftf,317); + MObtainWriteLock(&afs_ftf, 317); hset(fdv, vp->m.DataVersion); - /* why this disgusting code below? - * xuntext, called by xrele, doesn't notice when it is called + /* why this disgusting code below? + * xuntext, called by xrele, doesn't notice when it is called * with a freed text object. Sun continually calls xrele or xuntext * without any locking, as long as VTEXT is set on the - * corresponding vnode. + * corresponding vnode. * But, if the text object is locked when you check the VTEXT * flag, several processes can wait in xuntext, waiting for the * text lock; when the second one finally enters xuntext's @@ -208,7 +222,7 @@ void osi_FlushText_really(vp) #if defined (AFS_HPUX_ENV) if (vp->v.v_flag & VTEXT) { - xrele(vp); + xrele(vp); if (vp->v.v_flag & VTEXT) { /* still has a text object? */ MReleaseWriteLock(&afs_ftf); @@ -235,36 +249,36 @@ void osi_FlushText_really(vp) * into some middle ground... */ static void -afs_gfs_FlushText(vp) - register struct vcache *vp; { - afs_hyper_t fdv; /* version before which we'll flush */ +afs_gfs_FlushText(register struct vcache *vp) +{ + afs_hyper_t fdv; /* version before which we'll flush */ register struct text *xp; - struct gnode * gp; + struct gnode *gp; - MObtainWriteLock(&afs_ftf,318); + MObtainWriteLock(&afs_ftf, 318); hset(fdv, vp->m.DataVersion); gp = afs_vntogn(vp); if (!gp) { - /* this happens frequently after cores are created. */ - MReleaseWriteLock(&afs_ftf); - return; + /* this happens frequently after cores are created. */ + MReleaseWriteLock(&afs_ftf); + return; } if (gp->g_flag & GTEXT) { if (gp->g_textp) { - xp = (struct text *) gp->g_textp ; - /* if text object is locked, give up */ - if (xp && (xp->x_flag & XLOCK)) { - MReleaseWriteLock(&afs_ftf); - return; - } - } - else xp = (struct text *) 0; + xp = (struct text *)gp->g_textp; + /* if text object is locked, give up */ + if (xp && (xp->x_flag & XLOCK)) { + MReleaseWriteLock(&afs_ftf); + return; + } + } else + xp = NULL; - if (gp->g_flag & GTEXT) {/* still has a text object? */ - xinval(gp); - } + if (gp->g_flag & GTEXT) { /* still has a text object? */ + xinval(gp); + } } /* next do the stuff that need not check for deadlock problems */ @@ -281,68 +295,68 @@ afs_gfs_FlushText(vp) #endif /* AFS_TEXT_ENV */ /* mask signals in afsds */ -void afs_osi_MaskSignals(){ +void +afs_osi_MaskSignals(void) +{ #ifdef AFS_LINUX22_ENV osi_linux_mask(); #endif } - + /* unmask signals in rxk listener */ -void afs_osi_UnmaskRxkSignals(){ +void +afs_osi_UnmaskRxkSignals(void) +{ } - + /* register rxk listener proc info */ -void afs_osi_RxkRegister(){ +void +afs_osi_RxkRegister(void) +{ #ifdef AFS_LINUX22_ENV osi_linux_rxkreg(); #endif } /* procedure for making our processes as invisible as we can */ -void afs_osi_Invisible() { +void +afs_osi_Invisible(void) +{ #ifdef AFS_LINUX22_ENV afs_osi_MaskSignals(); -#endif -#ifdef AFS_DEC_ENV +#elif defined(AFS_DEC_ENV) u.u_procp->p_type |= SSYS; -#endif -#if AFS_SUN5_ENV +#elif defined(AFS_SUN5_ENV) curproc->p_flag |= SSYS; -#endif -#if AFS_HPUX101_ENV +#elif defined(AFS_HPUX101_ENV) && !defined(AFS_HPUX1123_ENV) set_system_proc(u.u_procp); -#endif -#if defined(AFS_DARWIN_ENV) +#elif defined(AFS_DARWIN_ENV) /* maybe call init_process instead? */ current_proc()->p_flag |= P_SYSTEM; -#endif -#if defined(AFS_FBSD_ENV) +#elif defined(AFS_XBSD_ENV) curproc->p_flag |= P_SYSTEM; -#endif -#if defined(AFS_SGI_ENV) +#elif defined(AFS_SGI_ENV) vrelvm(); -#endif /* AFS_SGI_ENV */ +#endif AFS_STATCNT(osi_Invisible); } -#ifndef AFS_LINUX20_ENV /* Linux version in osi_misc.c */ +#if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV) /* set the real time */ -afs_osi_SetTime(atv) - register osi_timeval_t *atv; { - -#ifdef AFS_AIX32_ENV +void +afs_osi_SetTime(osi_timeval_t * atv) +{ +#if defined(AFS_AIX32_ENV) struct timestruc_t t; - t.tv_sec = atv->tv_sec; + t.tv_sec = atv->tv_sec; t.tv_nsec = atv->tv_usec * 1000; ksettimer(&t); /* Was -> settimer(TIMEOFDAY, &t); */ -#else -#ifdef AFS_SUN55_ENV +#elif defined(AFS_SUN55_ENV) stime(atv->tv_sec); -#else -#ifdef AFS_SUN5_ENV +#elif defined(AFS_SUN5_ENV) /* * To get more than second resolution we can use adjtime. The problem * is that the usecs from the server are wrong (by now) so it isn't @@ -351,44 +365,20 @@ afs_osi_SetTime(atv) struct stimea { time_t time; } sta; - extern int stime(struct stimea *time, rval_t *rvp); sta.time = atv->tv_sec; stime(&sta, NULL); -#else -#if defined(AFS_SGI_ENV) +#elif defined(AFS_SGI_ENV) struct stimea { sysarg_t time; } sta; - extern int stime(struct stimea *time); AFS_GUNLOCK(); sta.time = atv->tv_sec; stime(&sta); AFS_GLOCK(); -#else -#if defined(AFS_FBSD_ENV) - /* does not impliment security features of kern_time.c:settime() */ - struct timespec ts; - struct timeval tv,delta; - extern void (*lease_updatetime)(); - int s; - AFS_GUNLOCK(); - s=splclock(); - microtime(&tv); - delta=*atv; - timevalsub(&delta, &tv); - ts.tv_sec=atv->tv_sec; - ts.tv_nsec=atv->tv_usec * 1000; - set_timecounter(&ts); - (void) splsoftclock(); - lease_updatetime(delta.tv_sec); - splx(s); - resettodr(); - AFS_GLOCK(); -#else -#if defined(AFS_DARWIN_ENV) +#elif defined(AFS_DARWIN_ENV) AFS_GUNLOCK(); setthetime(atv); AFS_GLOCK(); @@ -400,115 +390,121 @@ afs_osi_SetTime(atv) #ifdef AFS_HPUX_ENV { #if !defined(AFS_HPUX1122_ENV) - /* drop the setting of the clock for now. spl7 is not - * known on hpux11.22 - */ - - register ulong_t s; - struct timeval t; - t.tv_sec = atv->tv_sec; - t.tv_usec = atv->tv_usec; - s = spl7(); time = t; (void) splx(s); - resettodr(atv); + /* drop the setting of the clock for now. spl7 is not + * known on hpux11.22 + */ + register ulong_t s; + struct timeval t; + t.tv_sec = atv->tv_sec; + t.tv_usec = atv->tv_usec; + s = spl7(); + time = t; + (void)splx(s); + resettodr(atv); #endif } #else { - register int s; - s = splclock(); time = *atv; (void) splx(s); + register int s; + s = splclock(); + time = *atv; + (void)splx(s); } resettodr(); #endif #ifdef AFS_AUX_ENV logtchg(atv->tv_sec); #endif -#endif /* AFS_DARWIN_ENV */ -#endif /* AFS_FBSD_ENV */ -#endif /* AFS_SGI_ENV */ -#endif /* AFS_SUN55_ENV */ -#endif /* AFS_SUN5_ENV */ -#endif /* AFS_AIX32_ENV */ +#endif /* AFS_DARWIN_ENV */ AFS_STATCNT(osi_SetTime); - return 0; } #endif /* AFS_LINUX20_ENV */ -void *afs_osi_Alloc(size_t x) +void * +afs_osi_Alloc(size_t x) { register struct osimem *tm = NULL; register int size; AFS_STATCNT(osi_Alloc); /* 0-length allocs may return NULL ptr from AFS_KALLOC, so we special-case - things so that NULL returned iff an error occurred */ - if (x == 0) return &memZero; + * things so that NULL returned iff an error occurred */ + if (x == 0) + return &memZero; AFS_STATS(afs_stats_cmperf.OutStandingAllocs++); AFS_STATS(afs_stats_cmperf.OutStandingMemUsage += x); #ifdef AFS_LINUX20_ENV return osi_linux_alloc(x, 1); +#elif defined(AFS_FBSD_ENV) + return osi_fbsd_alloc(x, 1); #else size = x; - tm = (struct osimem *) AFS_KALLOC(size); + tm = (struct osimem *)AFS_KALLOC(size); #ifdef AFS_SUN_ENV if (!tm) osi_Panic("osi_Alloc: Couldn't allocate %d bytes; out of memory!\n", size); #endif - return (char *) tm; + return (void *)tm; #endif } #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) -void *afs_osi_Alloc_NoSleep(size_t x) +void * +afs_osi_Alloc_NoSleep(size_t x) { register struct osimem *tm; register int size; AFS_STATCNT(osi_Alloc); /* 0-length allocs may return NULL ptr from AFS_KALLOC, so we special-case - things so that NULL returned iff an error occurred */ - if (x == 0) return &memZero; + * things so that NULL returned iff an error occurred */ + if (x == 0) + return &memZero; size = x; AFS_STATS(afs_stats_cmperf.OutStandingAllocs++); AFS_STATS(afs_stats_cmperf.OutStandingMemUsage += x); - tm = (struct osimem *) AFS_KALLOC_NOSLEEP(size); - return (char *) tm; + tm = (struct osimem *)AFS_KALLOC_NOSLEEP(size); + return (void *)tm; } -#endif /* SUN || SGI */ +#endif /* SUN || SGI */ -void afs_osi_Free(void *x, size_t asize) +void +afs_osi_Free(void *x, size_t asize) { - register struct osimem *tm, **lm, *um; - AFS_STATCNT(osi_Free); - if (x == &memZero) return; /* check for putting memZero back */ + if (x == &memZero) + return; /* check for putting memZero back */ AFS_STATS(afs_stats_cmperf.OutStandingAllocs--); AFS_STATS(afs_stats_cmperf.OutStandingMemUsage -= asize); -#ifdef AFS_LINUX20_ENV +#if defined(AFS_LINUX20_ENV) osi_linux_free(x); +#elif defined(AFS_FBSD_ENV) + osi_fbsd_free(x); #else AFS_KFREE((struct osimem *)x, asize); #endif } -void afs_osi_FreeStr(char *x) +void +afs_osi_FreeStr(char *x) { afs_osi_Free(x, strlen(x) + 1); } -/* ? is it moderately likely that there are dirty VM pages associated with +/* ? is it moderately likely that there are dirty VM pages associated with * this vnode? * * Prereqs: avc must be write-locked * - * System Dependencies: - *must* support each type of system for which - * memory mapped files are supported, even if all + * System Dependencies: - *must* support each type of system for which + * memory mapped files are supported, even if all * it does is return TRUE; * * NB: this routine should err on the side of caution for ProcessFS to work @@ -516,39 +512,37 @@ void afs_osi_FreeStr(char *x) */ #ifdef notdef int -osi_VMDirty_p(avc) - struct vcache *avc; +osi_VMDirty_p(struct vcache *avc) { int dirtyPages; if (avc->execsOrWriters <= 0) - return 0; /* can't be many dirty pages here, I guess */ - -#if defined (AFS_AIX32_ENV) + return 0; /* can't be many dirty pages here, I guess */ + +#if defined (AFS_AIX32_ENV) #ifdef notdef /* because of the level of hardware involvment with VM and all the * warnings about "This routine must be called at VMM interrupt * level", I thought it would be safest to disable interrupts while * looking at the software page fault table. */ - /* convert vm handle into index into array: I think that stoinio is + /* convert vm handle into index into array: I think that stoinio is * always zero... Look into this XXX */ #define VMHASH(handle) ( \ ( ((handle) & ~vmker.stoinio) \ ^ ((((handle) & ~vmker.stoinio) & vmker.stoimask) << vmker.stoihash) \ - ) & 0x000fffff) + ) & 0x000fffff) - if (avc->vmh) { + if (avc->segid) { unsigned int pagef, pri, index, next; - extern struct vmkerdata vmker; - index = VMHASH(avc->vmh); - if (scb_valid(index)) { /* could almost be an ASSERT */ + index = VMHASH(avc->segid); + if (scb_valid(index)) { /* could almost be an ASSERT */ pri = disable_ints(); for (pagef = scb_sidlist(index); pagef >= 0; pagef = next) { next = pft_sidfwd(pagef); - if (pft_modbit(pagef)) { /* has page frame been modified? */ + if (pft_modbit(pagef)) { /* has page frame been modified? */ enable_ints(pri); return 1; } @@ -562,15 +556,15 @@ osi_VMDirty_p(avc) #if defined (AFS_SUN_ENV) if (avc->states & CMAPPED) { - struct page * pg; - for (pg = avc->v.v_s.v_Pages ; pg ; pg = pg->p_vpnext) { + struct page *pg; + for (pg = avc->v.v_s.v_Pages; pg; pg = pg->p_vpnext) { if (pg->p_mod) { return 1; } } } #endif -return 0; + return 0; } #endif /* notdef */ @@ -590,9 +584,7 @@ return 0; * Locking: the vcache entry lock is held. It is dropped and re-obtained. */ void -osi_ReleaseVM(avc, acred) - struct vcache *avc; - struct AFS_UCRED *acred; +osi_ReleaseVM(struct vcache *avc, struct AFS_UCRED *acred) { #ifdef AFS_SUN5_ENV AFS_GUNLOCK(); @@ -608,25 +600,26 @@ osi_ReleaseVM(avc, acred) } -void shutdown_osi() +void +shutdown_osi(void) { - extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osi); if (afs_cold_shutdown) { - LOCK_INIT(&afs_ftf, "afs_ftf"); - } + LOCK_INIT(&afs_ftf, "afs_ftf"); + } } -afs_osi_suser(credp) - void * credp; +#ifndef AFS_OBSD_ENV +int +afs_osi_suser(void *credp) { -#ifdef AFS_SUN5_ENV - return afs_suser(credp); +#if defined(AFS_SUN5_ENV) + return afs_suser(credp); #else - return afs_suser(); + return afs_suser(); #endif } +#endif #if AFS_GCPAGS @@ -635,7 +628,8 @@ afs_osi_suser(credp) */ #if defined(AFS_SUN5_ENV) -void afs_osi_TraverseProcTable() +void +afs_osi_TraverseProcTable(void) { struct proc *prp; for (prp = practive; prp != NULL; prp = prp->p_next) { @@ -657,7 +651,8 @@ void afs_osi_TraverseProcTable() * changes. To be safe, we use both. */ -void afs_osi_TraverseProcTable() +void +afs_osi_TraverseProcTable(void) { register proc_t *p; int endchain = 0; @@ -675,7 +670,7 @@ void afs_osi_TraverseProcTable() * consistent view of the current set of creds. */ - for(p = proc; endchain == 0; p = &proc[p->p_fandx]) { + for (p = proc; endchain == 0; p = &proc[p->p_fandx]) { if (p->p_fandx == 0) { endchain = 1; } @@ -683,9 +678,9 @@ void afs_osi_TraverseProcTable() if (system_proc(p)) continue; - mp_mtproc_lock(p); + mp_mtproc_lock(p); afs_GCPAGs_perproc_func(p); - mp_mtproc_unlock(p); + mp_mtproc_unlock(p); } pcred_unlock(); @@ -698,34 +693,41 @@ void afs_osi_TraverseProcTable() #ifdef AFS_SGI65_ENV /* TODO: Fix this later. */ -static int SGI_ProcScanFunc(void *p, void *arg, int mode) +static int +SGI_ProcScanFunc(void *p, void *arg, int mode) { return 0; } -#else /* AFS_SGI65_ENV */ -static int SGI_ProcScanFunc(proc_t *p, void *arg, int mode) +#else /* AFS_SGI65_ENV */ +static int +SGI_ProcScanFunc(proc_t * p, void *arg, int mode) { - afs_int32 (*perproc_func)(struct proc *) = arg; - int code=0; + afs_int32(*perproc_func) (struct proc *) = arg; + int code = 0; /* we pass in the function pointer for arg, - * mode ==0 for startup call, ==1 for each valid proc, + * mode ==0 for startup call, ==1 for each valid proc, * and ==2 for terminate call. */ - if(mode == 1) { + if (mode == 1) { code = perproc_func(p); } return code; } -#endif /* AFS_SGI65_ENV */ +#endif /* AFS_SGI65_ENV */ -void afs_osi_TraverseProcTable() +void +afs_osi_TraverseProcTable(void) { procscan(SGI_ProcScanFunc, afs_GCPAGs_perproc_func); } -#endif /* AFS_SGI_ENV */ +#endif /* AFS_SGI_ENV */ #if defined(AFS_AIX_ENV) -void afs_osi_TraverseProcTable() +#ifdef AFS_AIX51_ENV +#define max_proc v.ve_proc +#endif +void +afs_osi_TraverseProcTable(void) { struct proc *p; int i; @@ -738,17 +740,27 @@ void afs_osi_TraverseProcTable() if (!afs_gcpags_procsize) return; +#ifndef AFS_AIX51_ENV simple_lock(&proc_tbl_lock); - for (p = (struct proc *)v.vb_proc, i = 0; - p < max_proc; +#endif + for (p = (struct proc *)v.vb_proc, i = 0; p < max_proc; p = (struct proc *)((char *)p + afs_gcpags_procsize), i++) { +#ifdef AFS_AIX51_ENV + if (p->p_pvprocp->pv_stat == SNONE) + continue; + if (p->p_pvprocp->pv_stat == SIDL) + continue; + if (p->p_pvprocp->pv_stat == SEXIT) + continue; +#else if (p->p_stat == SNONE) continue; if (p->p_stat == SIDL) continue; if (p->p_stat == SEXIT) continue; +#endif /* sanity check */ @@ -766,49 +778,52 @@ void afs_osi_TraverseProcTable() afs_GCPAGs_perproc_func(p); } +#ifndef AFS_AIX51_ENV simple_unlock(&proc_tbl_lock); +#endif } #endif #if defined(AFS_OSF_ENV) -void afs_osi_TraverseProcTable() +void +afs_osi_TraverseProcTable(void) { struct pid_entry *pe; #ifdef AFS_DUX50_ENV -extern struct pid_entry *pidtab; -extern int npid; #define pidNPID (pidtab + npid) #define PID_LOCK() #define PID_UNLOCK() #endif PID_LOCK(); for (pe = pidtab; pe < pidNPID; ++pe) { - if (pe->pe_proc != PROC_NULL) - afs_GCPAGs_perproc_func(pe->pe_proc); + if (pe->pe_proc != PROC_NULL) + afs_GCPAGs_perproc_func(pe->pe_proc); } PID_UNLOCK(); } #endif #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -void afs_osi_TraverseProcTable() -{ +void +afs_osi_TraverseProcTable(void) +{ struct proc *p; LIST_FOREACH(p, &allproc, p_list) { - if (p->p_stat == SIDL) - continue; - if (p->p_stat == SZOMB) - continue; - if (p->p_flag & P_SYSTEM) - continue; - afs_GCPAGs_perproc_func(p); + if (p->p_stat == SIDL) + continue; + if (p->p_stat == SZOMB) + continue; + if (p->p_flag & P_SYSTEM) + continue; + afs_GCPAGs_perproc_func(p); } -} +} #endif #if defined(AFS_LINUX22_ENV) -void afs_osi_TraverseProcTable() -{ +void +afs_osi_TraverseProcTable() +{ struct task_struct *p; #ifdef EXPORTED_TASKLIST_LOCK @@ -816,21 +831,21 @@ void afs_osi_TraverseProcTable() #endif #ifdef DEFINED_FOR_EACH_PROCESS for_each_process(p) if (p->pid) { - if (p->state & TASK_ZOMBIE) - continue; + if (p->state & TASK_ZOMBIE) + continue; afs_GCPAGs_perproc_func(p); } #else for_each_task(p) if (p->pid) { - if (p->state & TASK_ZOMBIE) - continue; + if (p->state & TASK_ZOMBIE) + continue; afs_GCPAGs_perproc_func(p); } #endif #ifdef EXPORTED_TASKLIST_LOCK read_unlock(&tasklist_lock); #endif -} +} #endif /* return a pointer (sometimes a static copy ) to the cred for a @@ -839,12 +854,14 @@ void afs_osi_TraverseProcTable() */ #if defined(AFS_SGI65_ENV) -const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pr) +const struct AFS_UCRED * +afs_osi_proc2cred(AFS_PROC * p) { return NULL; } #elif defined(AFS_HPUX_ENV) -const struct AFS_UCRED *afs_osi_proc2cred(proc_t *p) +const struct AFS_UCRED * +afs_osi_proc2cred(AFS_PROC * p) { if (!p) return; @@ -861,9 +878,6 @@ const struct AFS_UCRED *afs_osi_proc2cred(proc_t *p) /* GLOBAL DECLARATIONS */ -extern int xmattach(); /* fills out cross memory descriptor */ -extern int xmdetach(); /* decrements reference count to segment */ - /* * LOCKS: the caller must do * simple_lock(&proc_tbl_lock); @@ -871,7 +885,8 @@ extern int xmdetach(); /* decrements reference count to segment */ * around calls to this function. */ -const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pproc) +const struct AFS_UCRED * +afs_osi_proc2cred(AFS_PROC * pproc) { struct AFS_UCRED *pcred = 0; @@ -893,7 +908,7 @@ const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pproc) int xm; /* xmem result */ if (!pproc) { - return pcred; + return pcred; } /* @@ -914,46 +929,61 @@ const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pproc) xmem_userp = NULL; xm = XMEM_FAIL; /* simple_lock(&proc_tbl_lock); */ +#ifdef __64BIT__ + if (pproc->p_adspace != vm_handle(NULLSEGID, (int32long64_t) 0)) { +#else if (pproc->p_adspace != NULLSEGVAL) { +#endif +#ifdef AFS_AIX51_ENV + simple_lock(&pproc->p_pvprocp->pv_lock); +#else simple_lock(&pproc->p_lock); +#endif if (pproc->p_threadcount && +#ifdef AFS_AIX51_ENV + pproc->p_pvprocp->pv_threadlist) { +#else pproc->p_threadlist) { +#endif /* * arbitrarily pick the first thread in pproc */ struct thread *pproc_thread = +#ifdef AFS_AIX51_ENV + pproc->p_pvprocp->pv_threadlist; +#else pproc->p_threadlist; +#endif /* * location of 'struct user' in pproc's * address space */ - struct user *pproc_userp = - pproc_thread->t_userp; + struct user *pproc_userp = pproc_thread->t_userp; /* * create a pointer valid in my own address space */ - xmem_userp = - (struct user *)vm_att(pproc->p_adspace, - pproc_userp); + xmem_userp = (struct user *)vm_att(pproc->p_adspace, pproc_userp); dp.aspace_id = XMEM_INVAL; - xm = xmattach(xmem_userp, - sizeof(*xmem_userp), - &dp, SYS_ADSPACE); + xm = xmattach(xmem_userp, sizeof(*xmem_userp), &dp, SYS_ADSPACE); } +#ifdef AFS_AIX51_ENV + simple_unlock(&pproc->p_pvprocp->pv_lock); +#else simple_unlock(&pproc->p_lock); +#endif } /* simple_unlock(&proc_tbl_lock); */ if (xm == XMEM_SUCC) { - static struct AFS_UCRED cred; + static struct AFS_UCRED cred; /* * What locking should we use to protect access to the user @@ -974,81 +1004,87 @@ const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pproc) } #elif defined(AFS_OSF_ENV) -const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pr) +const struct AFS_UCRED * +afs_osi_proc2cred(AFS_PROC * pr) { - struct AFS_UCRED *rv=NULL; + struct AFS_UCRED *rv = NULL; - if(pr == NULL) { - return NULL; + if (pr == NULL) { + return NULL; } - if((pr->p_stat == SSLEEP) || - (pr->p_stat == SRUN) || - (pr->p_stat == SSTOP)) - rv = pr->p_rcred; + if ((pr->p_stat == SSLEEP) || (pr->p_stat == SRUN) + || (pr->p_stat == SSTOP)) + rv = pr->p_rcred; return rv; } #elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pr) -{ - struct AFS_UCRED *rv=NULL; +const struct AFS_UCRED * +afs_osi_proc2cred(AFS_PROC * pr) +{ + struct AFS_UCRED *rv = NULL; static struct AFS_UCRED cr; - if(pr == NULL) { - return NULL; + if (pr == NULL) { + return NULL; } - - if((pr->p_stat == SSLEEP) || - (pr->p_stat == SRUN) || - (pr->p_stat == SSTOP)) { - pcred_readlock(pr); - cr.cr_ref=1; - cr.cr_uid=pr->p_cred->pc_ucred->cr_uid; - cr.cr_ngroups=pr->p_cred->pc_ucred->cr_ngroups; - memcpy(cr.cr_groups, pr->p_cred->pc_ucred->cr_groups, NGROUPS * - sizeof(gid_t)); - pcred_unlock(pr); - rv = &cr; + + if ((pr->p_stat == SSLEEP) || (pr->p_stat == SRUN) + || (pr->p_stat == SSTOP)) { + pcred_readlock(pr); + cr.cr_ref = 1; + cr.cr_uid = pr->p_cred->pc_ucred->cr_uid; + cr.cr_ngroups = pr->p_cred->pc_ucred->cr_ngroups; + memcpy(cr.cr_groups, pr->p_cred->pc_ucred->cr_groups, + NGROUPS * sizeof(gid_t)); + pcred_unlock(pr); + rv = &cr; } - + return rv; -} +} #elif defined(AFS_LINUX22_ENV) -const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pr) -{ - struct AFS_UCRED *rv=NULL; +const struct AFS_UCRED * +afs_osi_proc2cred(AFS_PROC * pr) +{ + struct AFS_UCRED *rv = NULL; static struct AFS_UCRED cr; - if(pr == NULL) { - return NULL; + if (pr == NULL) { + return NULL; } - - if ((pr->state == TASK_RUNNING) || - (pr->state == TASK_INTERRUPTIBLE) || - (pr->state == TASK_UNINTERRUPTIBLE) || - (pr->state == TASK_STOPPED)) { - cr.cr_ref=1; - cr.cr_uid=pr->uid; - cr.cr_ngroups=pr->ngroups; + + if ((pr->state == TASK_RUNNING) || (pr->state == TASK_INTERRUPTIBLE) + || (pr->state == TASK_UNINTERRUPTIBLE) + || (pr->state == TASK_STOPPED)) { + cr.cr_ref = 1; + cr.cr_uid = pr->uid; +#if defined(AFS_LINUX26_ENV) + get_group_info(pr->group_info); + cr.cr_group_info = pr->group_info; +#else + cr.cr_ngroups = pr->ngroups; memcpy(cr.cr_groups, pr->groups, NGROUPS * sizeof(gid_t)); +#endif rv = &cr; } - + return rv; -} +} #else -const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pr) +const struct AFS_UCRED * +afs_osi_proc2cred(AFS_PROC * pr) { - struct AFS_UCRED *rv=NULL; + struct AFS_UCRED *rv = NULL; - if(pr == NULL) { - return NULL; + if (pr == NULL) { + return NULL; } - rv = pr->p_cred; + rv = pr->p_cred; return rv; } #endif -#endif /* AFS_GCPAGS */ +#endif /* AFS_GCPAGS */ diff --git a/src/afs/afs_osi.h b/src/afs/afs_osi.h index e708f4dd4..a573e8978 100644 --- a/src/afs/afs_osi.h +++ b/src/afs/afs_osi.h @@ -10,21 +10,27 @@ #ifndef _AFS_OSI_ #define _AFS_OSI_ -#include "../h/types.h" -#include "../h/param.h" +#include "h/types.h" +#include "h/param.h" + +#ifdef AFS_FBSD50_ENV +#include +#endif #ifdef AFS_LINUX20_ENV #ifndef _LINUX_CODA_FS_I #define _LINUX_CODA_FS_I #define _CODA_HEADER_ -struct coda_inode_info {}; +struct coda_inode_info { +}; #endif #ifndef _LINUX_XFS_FS_I #define _LINUX_XFS_FS_I -struct xfs_inode_info {}; +struct xfs_inode_info { +}; #endif -#include "../h/fs.h" -#include "../h/mm.h" +#include "h/fs.h" +#include "h/mm.h" #endif @@ -34,39 +40,55 @@ struct osi_socket { }; struct osi_stat { - afs_int32 size; /* file size in bytes */ - afs_int32 blksize; /* optimal transfer size in bytes */ - afs_int32 mtime; /* modification date */ - afs_int32 atime; /* access time */ + afs_int32 size; /* file size in bytes */ + afs_int32 blksize; /* optimal transfer size in bytes */ + afs_int32 mtime; /* modification date */ + afs_int32 atime; /* access time */ }; struct osi_file { - afs_int32 size; /* file size in bytes XXX Must be first field XXX */ + afs_int32 size; /* file size in bytes XXX Must be first field XXX */ #ifdef AFS_LINUX22_ENV - struct dentry dentry; /* merely to hold the pointer to the inode. */ - struct file file; /* May need this if we really open the file. */ + struct dentry dentry; /* merely to hold the pointer to the inode. */ + struct file file; /* May need this if we really open the file. */ #else struct vnode *vnode; #endif #if defined(AFS_HPUX102_ENV) k_off_t offset; +#else +#if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) + afs_offs_t offset; #else afs_int32 offset; #endif - int (*proc)(); /* proc, which, if not null, is called on writes */ - char *rock; /* rock passed to proc */ - ino_t inum; /* guarantee validity of hint */ +#endif + int (*proc) (struct osi_file * afile, afs_int32 code); /* proc, which, if not null, is called on writes */ + char *rock; /* rock passed to proc */ + ino_t inum; /* guarantee validity of hint */ #if defined(UKERNEL) - int fd; /* file descriptor for user space files */ -#endif /* defined(UKERNEL) */ + int fd; /* file descriptor for user space files */ +#endif /* defined(UKERNEL) */ }; struct osi_dev { +#if defined(AFS_XBSD_ENV) + struct mount *mp; + struct vnode *held_vnode; +#elif defined(AFS_AIX42_ENV) + dev_t dev; +#else afs_int32 dev; +#endif }; struct afs_osi_WaitHandle { - caddr_t proc; /* process waiting */ +#ifdef AFS_FBSD50_ENV + struct cv wh_condvar; + int wh_inited; /* XXX */ +#else + caddr_t proc; /* process waiting */ +#endif }; #define osi_SetFileProc(x,p) ((x)->proc=(p)) @@ -82,34 +104,24 @@ struct afs_osi_WaitHandle { #endif -#define AFSOP_STOP_RXEVENT 214 /* stop rx event deamon */ -#define AFSOP_STOP_COMPLETE 215 /* afs has been shutdown */ -#define AFSOP_STOP_RXK_LISTENER 217 /* stop rx listener daemon */ - +#define AFSOP_STOP_RXEVENT 214 /* stop rx event deamon */ +#define AFSOP_STOP_COMPLETE 215 /* afs has been shutdown */ +#define AFSOP_STOP_RXK_LISTENER 217 /* stop rx listener daemon */ -#define osi_NPACKETS 20 /* number of cluster pkts to alloc */ -extern struct osi_socket *osi_NewSocket(); +#define osi_NPACKETS 20 /* number of cluster pkts to alloc */ /* * Alloc declarations. */ -extern void *afs_osi_Alloc(size_t size); -extern void afs_osi_Free(void *x, size_t size); #define afs_osi_Alloc_NoSleep afs_osi_Alloc -extern void *osi_AllocSmallSpace(size_t size); -extern void osi_FreeSmallSpace(void *x); -extern void *osi_AllocMediumSpace(size_t size); -extern void osi_FreeMediumSpace(void *x); -extern void *osi_AllocLargeSpace(size_t size); -extern void osi_FreeLargeSpace(void *x); - /* * Vnode related macros */ +#ifndef AFS_OBSD_ENV #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -extern int (**afs_vnodeop_p)(); +extern int (**afs_vnodeop_p) (); #define IsAfsVnode(vc) ((vc)->v_op == afs_vnodeop_p) #define SetAfsVnode(vc) (vc)->v_op = afs_vnodeop_p #else @@ -120,15 +132,18 @@ extern struct vnodeops *afs_ops; #define vType(vc) (vc)->v.v_type #define vSetType(vc,type) (vc)->v.v_type = (type) #define vSetVfsp(vc,vfsp) (vc)->v.v_vfsp = (vfsp) +#endif #ifdef AFS_SGI65_ENV #define gop_lookupname(fnamep,segflg,followlink,dirvpp,compvpp) \ lookupname((fnamep),(segflg),(followlink),(dirvpp),(compvpp),\ NULL) #else +#ifndef AFS_OBSD_ENV #define gop_lookupname(fnamep,segflg,followlink,dirvpp,compvpp) \ lookupname((fnamep),(segflg),(followlink),(dirvpp),(compvpp)) #endif +#endif /* * In IRIX 6.5 we cannot have DEBUG turned on since certain @@ -141,7 +156,7 @@ extern struct vnodeops *afs_ops; */ #if !defined(AFS_SGI65_ENV) #ifndef DEBUG -#define DEBUG 1 /* Default is to enable debugging/logging */ +#define DEBUG 1 /* Default is to enable debugging/logging */ #endif #endif @@ -183,17 +198,30 @@ typedef struct timeval osi_timeval_t; * is going on in the system. So if ps cannot show thread IDs it is * likely to be the process ID instead. */ +#ifdef AFS_FBSD50_ENV +/* should use curthread, but 'ps' can't display it */ +#define osi_ThreadUnique() curproc +#else #define osi_ThreadUnique() getpid() +#endif #ifdef AFS_GLOBAL_SUNLOCK #define AFS_ASSERT_GLOCK() \ - (ISAFS_GLOCK() || (osi_Panic("afs global lock not held"), 0)) + (ISAFS_GLOCK() || (osi_Panic("afs global lock not held at %s:%d\n", __FILE__, __LINE__), 0)) #define AFS_ASSERT_RXGLOCK() \ - (ISAFS_RXGLOCK() || (osi_Panic("rx global lock not held"), 0)) + (ISAFS_RXGLOCK() || (osi_Panic("rx global lock not held at %s:%d\n", __FILE__, __LINE__), 0)) #endif /* AFS_GLOBAL_SUNLOCK */ +#ifdef RX_ENABLE_LOCKS +#define RX_AFS_GLOCK() AFS_GLOCK() +#define RX_AFS_GUNLOCK() AFS_GUNLOCK() +#else +#define RX_AFS_GLOCK() +#define RX_AFS_GUNLOCK() +#endif + #ifndef KERNEL @@ -227,6 +255,7 @@ typedef struct timeval osi_timeval_t; #else /* defined(UKERNEL) */ #define AFS_RELE(vp) do { AFS_GUNLOCK(); VN_RELE(vp); AFS_GLOCK(); } while (0) #endif /* defined(UKERNEL) */ + /* * For some reason we do bare refcount manipulation in some places, for some * platforms. The assumption is apparently that either we wouldn't call @@ -235,14 +264,14 @@ typedef struct timeval osi_timeval_t; * (Also, of course, the vnode is assumed to be one of ours. Can't use this * macro for V-file vnodes.) */ -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) /* Bare refcount manipulation would probably work on this platform, but just calling VREF does not */ #define AFS_FAST_HOLD(vp) osi_vnhold((vp),0) #else #define AFS_FAST_HOLD(vp) VN_HOLD(&(vp)->v) #endif -#define AFS_FAST_RELE(vp) AFS_RELE(&(vp)->v) +#define AFS_FAST_RELE(vp) AFS_RELE(AFSTOV(vp)) /* * MP safe versions of routines to copy memory between user space @@ -281,7 +310,7 @@ typedef struct timeval osi_timeval_t; AFS_GLOCK(); \ } while(0) -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE) \ do { \ int haveGlock = ISAFS_GLOCK(); \ @@ -292,7 +321,7 @@ typedef struct timeval osi_timeval_t; if (haveGlock) \ AFS_GLOCK(); \ } while(0) -#else /* AFS_OSF_ENV || AFS_FBSD_ENV */ +#else #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE) \ do { \ int haveGlock = ISAFS_GLOCK(); \ @@ -302,7 +331,7 @@ typedef struct timeval osi_timeval_t; if (haveGlock) \ AFS_GLOCK(); \ } while(0) -#endif /* AFS_OSF_ENV || AFS_FBSD_ENV */ +#endif #else /* AFS_GLOBAL_SUNLOCK */ @@ -321,7 +350,7 @@ typedef struct timeval osi_timeval_t; CODE = copyout((SRC),(DST),(LEN)); \ } while(0) -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE) \ do { \ (UIO)->uio_rw = (RW); \ @@ -364,34 +393,18 @@ typedef struct timeval osi_timeval_t; #define AfsLargeFileUio(uio) 0 #define AfsLargeFileSize(pos, off) 0 - -/* VM function prototypes. - */ -#if defined(AFS_SUN5_ENV) -extern int osi_VM_GetDownD(); -extern void osi_VM_PreTruncate(); -#endif -#if defined(AFS_SGI_ENV) -extern void osi_VM_FSyncInval(); -#endif -extern int osi_VM_FlushVCache(); -extern void osi_VM_StoreAllSegments(); -extern void osi_VM_TryToSmush(); -extern void osi_VM_FlushPages(); -extern void osi_VM_Truncate(); - -extern void osi_ReleaseVM(); - /* Now include system specific OSI header file. It will redefine macros * defined here as required by the OS. */ -#include "../afs/osi_machdep.h" +#include "osi_machdep.h" /* Declare any structures which use these macros after the OSI implementation * has had the opportunity to redefine them. */ -extern struct AFS_UCRED afs_osi_cred; - -#endif /* _AFS_OSI_ */ +extern struct AFS_UCRED afs_osi_cred, *afs_osi_credp; +#ifndef osi_curcred +#define osi_curcred() (u.u_cred) +#endif +#endif /* _AFS_OSI_ */ diff --git a/src/afs/afs_osi_alloc.c b/src/afs/afs_osi_alloc.c index d0065eded..ae342cb54 100644 --- a/src/afs/afs_osi_alloc.c +++ b/src/afs/afs_osi_alloc.c @@ -8,16 +8,18 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_osi_alloc.c,v 1.1.1.4 2001/07/14 22:19:22 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_osi_alloc.c,v 1.10 2004/03/10 23:01:51 rees Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#ifndef AFS_FBSD_ENV #ifdef AFS_AIX41_ENV #include "sys/lockl.h" #include "sys/sleep.h" @@ -32,29 +34,29 @@ afs_lock_t osi_fsplock; static struct osi_packet { struct osi_packet *next; -} *freePacketList = 0, *freeSmallList, *freeMediumList; +} *freePacketList = NULL, *freeSmallList; afs_lock_t osi_flplock; afs_int32 afs_preallocs = 512; /* Reserve space for all small allocs! */ -void osi_AllocMoreSSpace(preallocs) - register afs_int32 preallocs; +void +osi_AllocMoreSSpace(register afs_int32 preallocs) { register int i; char *p; - p = (char *) afs_osi_Alloc(AFS_SMALLOCSIZ * preallocs); -#ifdef AFS_AIX32_ENV + p = (char *)afs_osi_Alloc(AFS_SMALLOCSIZ * preallocs); +#ifdef KERNEL_HAVE_PIN pin(p, AFS_SMALLOCSIZ * preallocs); /* XXXX */ #endif - for (i=0; i < preallocs; i++, p += AFS_SMALLOCSIZ) { + for (i = 0; i < preallocs; i++, p += AFS_SMALLOCSIZ) { #ifdef AFS_AIX32_ENV - *p = '\0'; /* page fault it in. */ + *p = '\0'; /* page fault it in. */ #endif - osi_FreeSmallSpace((char *) p); + osi_FreeSmallSpace((char *)p); } afs_stats_cmperf.SmallBlocksAlloced += preallocs; - afs_stats_cmperf.SmallBlocksActive += preallocs; + afs_stats_cmperf.SmallBlocksActive += preallocs; } @@ -70,7 +72,7 @@ osi_FreeLargeSpace(void *adata) AFS_STATCNT(osi_FreeLargeSpace); afs_stats_cmperf.LargeBlocksActive--; - MObtainWriteLock(&osi_flplock,322); + MObtainWriteLock(&osi_flplock, 322); ((struct osi_packet *)adata)->next = freePacketList; freePacketList = adata; MReleaseWriteLock(&osi_flplock); @@ -92,42 +94,44 @@ osi_FreeSmallSpace(void *adata) AFS_STATCNT(osi_FreeSmallSpace); afs_stats_cmperf.SmallBlocksActive--; #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - x = splnet(); /*lockl(&osi_fsplock, LOCK_SHORT);*/ + x = splnet(); /*lockl(&osi_fsplock, LOCK_SHORT); */ #else - MObtainWriteLock(&osi_fsplock,323); + MObtainWriteLock(&osi_fsplock, 323); #endif ((struct osi_packet *)adata)->next = freeSmallList; freeSmallList = adata; #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - splx(x); /*unlockl(&osi_fsplock);*/ + splx(x); /*unlockl(&osi_fsplock); */ #else MReleaseWriteLock(&osi_fsplock); #endif } #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) -osi_AllocMoreMSpace(preallocs) - register afs_int32 preallocs; +static struct osi_packet *freeMediumList; + +osi_AllocMoreMSpace(register afs_int32 preallocs) { register int i; char *p; - p = (char *) afs_osi_Alloc(AFS_MDALLOCSIZ * preallocs); -#ifdef AFS_AIX32_ENV + p = (char *)afs_osi_Alloc(AFS_MDALLOCSIZ * preallocs); +#ifdef KERNEL_HAVE_PIN pin(p, AFS_MDALLOCSIZ * preallocs); /* XXXX */ #endif - for (i=0; i < preallocs; i++, p += AFS_MDALLOCSIZ) { + for (i = 0; i < preallocs; i++, p += AFS_MDALLOCSIZ) { #ifdef AFS_AIX32_ENV - *p = '\0'; /* page fault it in. */ + *p = '\0'; /* page fault it in. */ #endif - osi_FreeMediumSpace((char *) p); + osi_FreeMediumSpace((char *)p); } afs_stats_cmperf.MediumBlocksAlloced += preallocs; - afs_stats_cmperf.MediumBlocksActive += preallocs; + afs_stats_cmperf.MediumBlocksActive += preallocs; } -void *osi_AllocMediumSpace(size_t size) +void * +osi_AllocMediumSpace(size_t size) { register struct osi_packet *tp; #if defined(AFS_AIX32_ENV) @@ -138,13 +142,14 @@ void *osi_AllocMediumSpace(size_t size) #endif afs_stats_cmperf.MediumBlocksActive++; - retry: + retry: x = splnet(); tp = freeMediumList; - if ( tp ) freeMediumList = tp->next; + if (tp) + freeMediumList = tp->next; splx(x); if (!tp) { - osi_AllocMoreMSpace(AFS_MALLOC_LOW_WATER); + osi_AllocMoreMSpace(AFS_MALLOC_LOW_WATER); goto retry; } return tp; @@ -171,7 +176,8 @@ osi_FreeMediumSpace(void *adata) /* allocate space for sender */ -void *osi_AllocLargeSpace(size_t size) +void * +osi_AllocLargeSpace(size_t size) { register struct osi_packet *tp; @@ -185,22 +191,23 @@ void *osi_AllocLargeSpace(size_t size) char *p; afs_stats_cmperf.LargeBlocksAlloced++; - p = (char *) afs_osi_Alloc(AFS_LRALLOCSIZ); -#ifdef AFS_AIX32_ENV + p = (char *)afs_osi_Alloc(AFS_LRALLOCSIZ); +#ifdef KERNEL_HAVE_PIN /* * Need to pin this memory since under heavy conditions this memory - * could be swapped out; the problem is that we could inside rx where - * interrupts are disabled and thus we would panic if we don't pin it. - */ - pin(p, AFS_LRALLOCSIZ); + * could be swapped out; the problem is that we could inside rx where + * interrupts are disabled and thus we would panic if we don't pin it. + */ + pin(p, AFS_LRALLOCSIZ); #endif return p; } - MObtainWriteLock(&osi_flplock,324); + MObtainWriteLock(&osi_flplock, 324); tp = freePacketList; - if ( tp ) freePacketList = tp->next; + if (tp) + freePacketList = tp->next; MReleaseWriteLock(&osi_flplock); - return (char *) tp; + return (char *)tp; } #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) @@ -208,9 +215,9 @@ void *osi_AllocLargeSpace(size_t size) * XXX We could have used a macro around osi_AllocSmallSpace but it's * probably better like this so that we can remove this at some point. */ -char *osi_AllocSmall(size, morespace) - register afs_int32 morespace; /* 1 - means we called at splnet level */ - register afs_int32 size; +/* morespace 1 - means we called at splnet level */ +char * +osi_AllocSmall(register afs_int32 size, register afs_int32 morespace) { register struct osi_packet *tp; #if defined(AFS_AIX32_ENV) @@ -223,32 +230,37 @@ char *osi_AllocSmall(size, morespace) AFS_ASSERT_GLOCK(); AFS_STATCNT(osi_AllocSmallSpace); - if (size > AFS_SMALLOCSIZ) osi_Panic("osi_AllocSmall, size=%d", size); - if ((!morespace && - ((afs_stats_cmperf.SmallBlocksAlloced - afs_stats_cmperf.SmallBlocksActive) - <= AFS_SALLOC_LOW_WATER)) + if (size > AFS_SMALLOCSIZ) + osi_Panic("osi_AllocSmall, size=%d", size); + if ((!morespace + && + ((afs_stats_cmperf.SmallBlocksAlloced - + afs_stats_cmperf.SmallBlocksActive) + <= AFS_SALLOC_LOW_WATER)) || !freeSmallList) { osi_AllocMoreSSpace(AFS_SALLOC_LOW_WATER * 2); } afs_stats_cmperf.SmallBlocksActive++; #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - x = splnet(); /*lockl(&osi_fsplock, LOCK_SHORT);*/ + x = splnet(); /*lockl(&osi_fsplock, LOCK_SHORT); */ #else - MObtainWriteLock(&osi_fsplock,325); + MObtainWriteLock(&osi_fsplock, 325); #endif tp = freeSmallList; - if ( tp ) freeSmallList = tp->next; + if (tp) + freeSmallList = tp->next; #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - splx(x); /*unlockl(&osi_fsplock);*/ + splx(x); /*unlockl(&osi_fsplock); */ #else MReleaseWriteLock(&osi_fsplock); #endif - return (char *) tp; + return (char *)tp; } -osi_FreeSmall(adata) - register struct osi_packet *adata; { +int +osi_FreeSmall(register struct osi_packet *adata) +{ #if defined(AFS_AIX32_ENV) int x; #endif @@ -259,14 +271,14 @@ osi_FreeSmall(adata) AFS_STATCNT(osi_FreeSmallSpace); afs_stats_cmperf.SmallBlocksActive--; #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - x = splnet(); /*lockl(&osi_fsplock, LOCK_SHORT);*/ + x = splnet(); /*lockl(&osi_fsplock, LOCK_SHORT); */ #else - MObtainWriteLock(&osi_fsplock,326); + MObtainWriteLock(&osi_fsplock, 326); #endif adata->next = freeSmallList; freeSmallList = adata; #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - splx(x); /*unlockl(&osi_fsplock);*/ + splx(x); /*unlockl(&osi_fsplock); */ #else MReleaseWriteLock(&osi_fsplock); #endif @@ -275,7 +287,8 @@ osi_FreeSmall(adata) #endif /* AFS_AIX32_ENV || AFS_HPUX_ENV */ /* allocate space for sender */ -void *osi_AllocSmallSpace(size_t size) +void * +osi_AllocSmallSpace(size_t size) { register struct osi_packet *tp; #if defined(AFS_AIX32_ENV) @@ -286,15 +299,17 @@ void *osi_AllocSmallSpace(size_t size) #endif AFS_STATCNT(osi_AllocSmallSpace); - if (size > AFS_SMALLOCSIZ) osi_Panic("osi_AllocSmallS: size=%d\n", size); + if (size > AFS_SMALLOCSIZ) + osi_Panic("osi_AllocSmallS: size=%d\n", size); #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) /* * We're running out of free blocks (< 50); get some more ourselves so that * when we don't run out of them when called under splnet() (from rx); */ - if (((afs_stats_cmperf.SmallBlocksAlloced - afs_stats_cmperf.SmallBlocksActive) - <= AFS_SALLOC_LOW_WATER) || !freeSmallList) { + if (((afs_stats_cmperf.SmallBlocksAlloced - + afs_stats_cmperf.SmallBlocksActive) + <= AFS_SALLOC_LOW_WATER) || !freeSmallList) { osi_AllocMoreSSpace(AFS_SALLOC_LOW_WATER * 2); } #else @@ -306,50 +321,52 @@ void *osi_AllocSmallSpace(size_t size) #endif afs_stats_cmperf.SmallBlocksActive++; #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - x = splnet(); /*lockl(&osi_fsplock, LOCK_SHORT);*/ + x = splnet(); /*lockl(&osi_fsplock, LOCK_SHORT); */ #else - MObtainWriteLock(&osi_fsplock,327); + MObtainWriteLock(&osi_fsplock, 327); #endif tp = freeSmallList; - if ( tp ) freeSmallList = tp->next; + if (tp) + freeSmallList = tp->next; #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) - splx(x); /*unlockl(&osi_fsplock);*/ + splx(x); /*unlockl(&osi_fsplock); */ #else MReleaseWriteLock(&osi_fsplock); #endif - return (char *) tp; + return (char *)tp; } -void shutdown_osinet() -{ - extern int afs_cold_shutdown; +void +shutdown_osinet(void) +{ + extern int afs_cold_shutdown; - AFS_STATCNT(shutdown_osinet); - if (afs_cold_shutdown) { - struct osi_packet *tp; + AFS_STATCNT(shutdown_osinet); + if (afs_cold_shutdown) { + struct osi_packet *tp; - while (tp = freePacketList) { - freePacketList = tp->next; - afs_osi_Free(tp, AFS_LRALLOCSIZ); -#ifdef AFS_AIX32_ENV - unpin(tp, AFS_LRALLOCSIZ); + while ((tp = freePacketList)) { + freePacketList = tp->next; + afs_osi_Free(tp, AFS_LRALLOCSIZ); +#ifdef KERNEL_HAVE_PIN + unpin(tp, AFS_LRALLOCSIZ); #endif - } + } - while (tp = freeSmallList) { - freeSmallList = tp->next; - afs_osi_Free(tp, AFS_SMALLOCSIZ); -#ifdef AFS_AIX32_ENV - unpin(tp, AFS_SMALLOCSIZ); + while ((tp = freeSmallList)) { + freeSmallList = tp->next; + afs_osi_Free(tp, AFS_SMALLOCSIZ); +#ifdef KERNEL_HAVE_PIN + unpin(tp, AFS_SMALLOCSIZ); #endif - } - afs_preallocs = 512; + } + afs_preallocs = 512; #ifndef AFS_AIX32_ENV - LOCK_INIT(&osi_fsplock, "osi_fsplock"); + LOCK_INIT(&osi_fsplock, "osi_fsplock"); #endif - LOCK_INIT(&osi_flplock, "osi_flplock"); - } + LOCK_INIT(&osi_flplock, "osi_flplock"); + } } - +#endif diff --git a/src/afs/afs_osi_pag.c b/src/afs/afs_osi_pag.c index ed80eef36..036d33e89 100644 --- a/src/afs/afs_osi_pag.c +++ b/src/afs/afs_osi_pag.c @@ -20,16 +20,17 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_osi_pag.c,v 1.1.1.7 2003/04/13 19:02:37 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_osi_pag.c,v 1.20 2004/04/21 02:20:21 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" /* Imported variables */ @@ -70,7 +71,9 @@ afs_uint32 pagCounter = 0; * secure (although of course not absolutely secure). */ #if !defined(UKERNEL) || !defined(AFS_WEB_ENHANCEMENTS) -afs_uint32 genpag(void) { +afs_uint32 +genpag(void) +{ AFS_STATCNT(genpag); #ifdef AFS_LINUX20_ENV /* Ensure unique PAG's (mod 200 days) when reloading the client. */ @@ -80,7 +83,9 @@ afs_uint32 genpag(void) { #endif /* AFS_LINUX20_ENV */ } -afs_uint32 getpag(void) { +afs_uint32 +getpag(void) +{ AFS_STATCNT(getpag); #ifdef AFS_LINUX20_ENV /* Ensure unique PAG's (mod 200 days) when reloading the client. */ @@ -95,7 +100,9 @@ afs_uint32 getpag(void) { /* Web enhancement: we don't need to restrict pags to 41XXXXXX since * we are not sharing the space with anyone. So we use the full 32 bits. */ -afs_uint32 genpag(void) { +afs_uint32 +genpag(void) +{ AFS_STATCNT(genpag); #ifdef AFS_LINUX20_ENV return (pag_epoch + pagCounter++); @@ -104,7 +111,9 @@ afs_uint32 genpag(void) { #endif /* AFS_LINUX20_ENV */ } -afs_uint32 getpag(void) { +afs_uint32 +getpag(void) +{ AFS_STATCNT(getpag); #ifdef AFS_LINUX20_ENV /* Ensure unique PAG's (mod 200 days) when reloading the client. */ @@ -132,11 +141,11 @@ afs_uint32 getpag(void) { int #if defined(AFS_SUN5_ENV) -afs_setpag (struct AFS_UCRED **credpp) -#elif defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -afs_setpag (struct proc *p, void *args, int *retval) +afs_setpag(struct AFS_UCRED **credpp) +#elif defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) +afs_setpag(struct proc *p, void *args, int *retval) #else -afs_setpag (void) +afs_setpag(void) #endif { int code = 0; @@ -144,29 +153,30 @@ afs_setpag (void) #if defined(AFS_SGI53_ENV) && defined(MP) /* This is our first chance to get the global lock. */ AFS_GLOCK(); -#endif /* defined(AFS_SGI53_ENV) && defined(MP) */ +#endif /* defined(AFS_SGI53_ENV) && defined(MP) */ AFS_STATCNT(afs_setpag); -#ifdef AFS_SUN5_ENV +#if defined(AFS_SUN5_ENV) if (!afs_suser(*credpp)) +#elif defined(AFS_OBSD_ENV) + if (!afs_osi_suser(p->p_ucred)) #else if (!afs_suser()) #endif { - while (osi_Time() - pag_epoch < pagCounter ) { - afs_osi_Wait(1000, (struct afs_osi_WaitHandle *) 0, 0); - } + while (osi_Time() - pag_epoch < pagCounter) { + afs_osi_Wait(1000, (struct afs_osi_WaitHandle *)0, 0); + } } - #if defined(AFS_SUN5_ENV) code = AddPag(genpag(), credpp); -#elif defined(AFS_OSF_ENV) || defined(AFS_FBSD_ENV) +#elif defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV) code = AddPag(p, genpag(), &p->p_rcred); #elif defined(AFS_AIX41_ENV) { struct ucred *credp; struct ucred *credp0; - + credp = crref(); credp0 = credp; code = AddPag(genpag(), &credp); @@ -192,27 +202,25 @@ afs_setpag (void) code = AddPag(genpag(), &credp); crfree(credp); } -#elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#elif defined(AFS_DARWIN_ENV) { - struct ucred *credp=crdup(p->p_cred->pc_ucred); - code=AddPag(p, genpag(), &credp); - crfree(credp); + struct ucred *credp = crdup(p->p_cred->pc_ucred); + code = AddPag(p, genpag(), &credp); + crfree(credp); } #else code = AddPag(genpag(), &u.u_cred); #endif afs_Trace1(afs_iclSetp, CM_TRACE_SETPAG, ICL_TYPE_INT32, code); -#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(KERNEL_HAVE_UERROR) + if (!getuerror()) + setuerror(code); +#endif #if defined(AFS_SGI53_ENV) && defined(MP) AFS_GUNLOCK(); -#endif /* defined(AFS_SGI53_ENV) && defined(MP) */ - return (code); -#else - if (!getuerror()) - setuerror(code); +#endif /* defined(AFS_SGI53_ENV) && defined(MP) */ return (code); -#endif } #if defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS) @@ -225,11 +233,11 @@ afs_setpag (void) */ int #if defined(AFS_SUN5_ENV) -afs_setpag_val (struct AFS_UCRED **credpp, int pagval) -#elif defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -afs_setpag_val (struct proc *p, void *args, int *retval, int pagval) +afs_setpag_val(struct AFS_UCRED **credpp, int pagval) +#elif defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) +afs_setpag_val(struct proc *p, void *args, int *retval, int pagval) #else -afs_setpag_val (int pagval) +afs_setpag_val(int pagval) #endif { int code = 0; @@ -237,7 +245,7 @@ afs_setpag_val (int pagval) #if defined(AFS_SGI53_ENV) && defined(MP) /* This is our first chance to get the global lock. */ AFS_GLOCK(); -#endif /* defined(AFS_SGI53_ENV) && defined(MP) */ +#endif /* defined(AFS_SGI53_ENV) && defined(MP) */ AFS_STATCNT(afs_setpag); #ifdef AFS_SUN5_ENV @@ -246,20 +254,19 @@ afs_setpag_val (int pagval) if (!afs_suser()) #endif { - while (osi_Time() - pag_epoch < pagCounter ) { - afs_osi_Wait(1000, (struct afs_osi_WaitHandle *) 0, 0); - } + while (osi_Time() - pag_epoch < pagCounter) { + afs_osi_Wait(1000, (struct afs_osi_WaitHandle *)0, 0); + } } - #if defined(AFS_SUN5_ENV) code = AddPag(pagval, credpp); -#elif defined(AFS_OSF_ENV) || defined(AFS_FBSD_ENV) +#elif defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV) code = AddPag(p, pagval, &p->p_rcred); #elif defined(AFS_AIX41_ENV) { struct ucred *credp; struct ucred *credp0; - + credp = crref(); credp0 = credp; code = AddPag(pagval, &credp); @@ -285,85 +292,88 @@ afs_setpag_val (int pagval) code = AddPag(pagval, &credp); crfree(credp); } -#elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#elif defined(AFS_DARWIN_ENV) { - struct ucred *credp=crdup(p->p_cred->pc_ucred); - code=AddPag(p, pagval, &credp); - crfree(credp); + struct ucred *credp = crdup(p->p_cred->pc_ucred); + code = AddPag(p, pagval, &credp); + crfree(credp); } #else code = AddPag(pagval, &u.u_cred); #endif afs_Trace1(afs_iclSetp, CM_TRACE_SETPAG, ICL_TYPE_INT32, code); -#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(KERNEL_HAVE_UERROR) + if (!getuerror()) + setuerror(code); +#endif #if defined(AFS_SGI53_ENV) && defined(MP) AFS_GUNLOCK(); -#endif /* defined(AFS_SGI53_ENV) && defined(MP) */ - return (code); -#else - if (!getuerror()) - setuerror(code); +#endif /* defined(AFS_SGI53_ENV) && defined(MP) */ return (code); -#endif } -#endif /* UKERNEL && AFS_WEB_ENHANCEMENTS */ -#if defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS) -int afs_getpag_val() +int +afs_getpag_val() { - int pagvalue; - struct AFS_UCRED *credp = u.u_cred; - int gidset0, gidset1; - - gidset0 = credp->cr_groups[0]; - gidset1 = credp->cr_groups[1]; - pagvalue=afs_get_pag_from_groups(gidset0, gidset1); - return pagvalue; + int pagvalue; + struct AFS_UCRED *credp = u.u_cred; + int gidset0, gidset1; + + gidset0 = credp->cr_groups[0]; + gidset1 = credp->cr_groups[1]; + pagvalue = afs_get_pag_from_groups(gidset0, gidset1); + return pagvalue; } #endif /* UKERNEL && AFS_WEB_ENHANCEMENTS */ -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -int AddPag(struct proc *p, afs_int32 aval, struct AFS_UCRED **credpp) -#else /* AFS_OSF_ENV || AFS_FBSD_ENV */ -int AddPag(afs_int32 aval, struct AFS_UCRED **credpp) +/* Note - needs to be available on AIX, others can be static - rework this */ +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) +int +AddPag(struct proc *p, afs_int32 aval, struct AFS_UCRED **credpp) +#else +int +AddPag(afs_int32 aval, struct AFS_UCRED **credpp) #endif { afs_int32 newpag, code; + AFS_STATCNT(AddPag); -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - if (code = setpag(p, credpp, aval, &newpag, 0)) -#else /* AFS_OSF_ENV */ - if (code = setpag(credpp, aval, &newpag, 0)) -#endif -#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return (code); +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + if ((code = setpag(p, credpp, aval, &newpag, 0))) #else + if ((code = setpag(credpp, aval, &newpag, 0))) +#endif +#if defined(KERNEL_HAVE_UERROR) return (setuerror(code), code); +#else + return (code); #endif return 0; } -afs_InitReq(av, acred) - register struct vrequest *av; - struct AFS_UCRED *acred; { - +int +afs_InitReq(register struct vrequest *av, struct AFS_UCRED *acred) +{ AFS_STATCNT(afs_InitReq); - if (afs_shuttingdown) return EIO; + if (afs_shuttingdown) + return EIO; av->uid = PagInCred(acred); if (av->uid == NOPAG) { /* Afs doesn't use the unix uid for anuthing except a handle * with which to find the actual authentication tokens so I * think it's ok to use the real uid to make setuid - * programs (without setpag) to work properly. - */ -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - av->uid = acred->cr_uid; /* default when no pag is set */ - /* bsd creds don't have ruid */ + * programs (without setpag) to work properly. + */ +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + if (acred == NOCRED) + av->uid = -2; /* XXX nobody... ? */ + else + av->uid = acred->cr_uid; /* bsd creds don't have ruid */ #else - av->uid = acred->cr_ruid; /* default when no pag is set */ + av->uid = acred->cr_ruid; /* default when no pag is set */ #endif } av->initd = 0; @@ -372,7 +382,8 @@ afs_InitReq(av, acred) -afs_uint32 afs_get_pag_from_groups(gid_t g0a, gid_t g1a) +afs_uint32 +afs_get_pag_from_groups(gid_t g0a, gid_t g1a) { afs_uint32 g0 = g0a; afs_uint32 g1 = g1a; @@ -400,7 +411,8 @@ afs_uint32 afs_get_pag_from_groups(gid_t g0a, gid_t g1a) } -void afs_get_groups_from_pag(afs_uint32 pag, gid_t *g0p, gid_t *g1p) +void +afs_get_groups_from_pag(afs_uint32 pag, gid_t * g0p, gid_t * g1p) { unsigned short g0, g1; @@ -418,7 +430,8 @@ void afs_get_groups_from_pag(afs_uint32 pag, gid_t *g0p, gid_t *g1p) } -afs_int32 PagInCred(const struct AFS_UCRED *cred) +afs_int32 +PagInCred(const struct AFS_UCRED *cred) { afs_int32 pag; gid_t g0, g1; @@ -427,27 +440,42 @@ afs_int32 PagInCred(const struct AFS_UCRED *cred) if (cred == NULL) { return NOPAG; } -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) if (cred == NOCRED || cred == FSCRED) { - return NOPAG; + return NOPAG; } - if (cred->cr_ngroups < 3) return NOPAG; + if (cred->cr_ngroups < 3) + return NOPAG; /* gid is stored in cr_groups[0] */ g0 = cred->cr_groups[1]; g1 = cred->cr_groups[2]; #else -#ifdef AFS_AIX_ENV +#if defined(AFS_AIX51_ENV) + if (kcred_getpag(cred, PAG_AFS, &pag) < 0 || pag == 0) + pag = NOPAG; + return pag; +#elif defined(AFS_AIX_ENV) if (cred->cr_ngrps < 2) { return NOPAG; } -#else -#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DUX40_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_FBSD_ENV) - if (cred->cr_ngroups < 2) return NOPAG; -#endif +#elif defined(AFS_LINUX26_ENV) + if (cred->cr_group_info->ngroups < 2) + return NOPAG; +#elif defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DUX40_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_XBSD_ENV) + if (cred->cr_ngroups < 2) + return NOPAG; #endif +#if defined(AFS_AIX51_ENV) + g0 = cred->cr_groupset.gs_union.un_groups[0]; + g1 = cred->cr_groupset.gs_union.un_groups[1]; +#elif defined(AFS_LINUX26_ENV) + g0 = GROUP_AT(cred->cr_group_info, 0); + g1 = GROUP_AT(cred->cr_group_info, 1); +#else g0 = cred->cr_groups[0]; g1 = cred->cr_groups[1]; #endif - pag = (afs_int32)afs_get_pag_from_groups(g0, g1); +#endif + pag = (afs_int32) afs_get_pag_from_groups(g0, g1); return pag; } diff --git a/src/afs/afs_osi_uio.c b/src/afs/afs_osi_uio.c index ee17fa622..f3cf5a0ed 100644 --- a/src/afs/afs_osi_uio.c +++ b/src/afs/afs_osi_uio.c @@ -8,16 +8,17 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_osi_uio.c,v 1.1.1.5 2001/09/11 14:24:42 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_osi_uio.c,v 1.8 2003/07/15 23:14:12 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/nfsclient.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/nfsclient.h" +#include "afs/afs_osidnlc.h" /* @@ -25,29 +26,31 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_osi_uio.c,v 1.1.1.5 2001/09/11 */ /* routine to make copy of uio structure in ainuio, using aoutvec for space */ -afsio_copy(ainuio, aoutuio, aoutvec) -struct uio *ainuio, *aoutuio; -register struct iovec *aoutvec; { +int +afsio_copy(struct uio *ainuio, struct uio *aoutuio, + register struct iovec *aoutvec) +{ register int i; register struct iovec *tvec; AFS_STATCNT(afsio_copy); - if (ainuio->afsio_iovcnt > AFS_MAXIOVCNT) return EINVAL; + if (ainuio->afsio_iovcnt > AFS_MAXIOVCNT) + return EINVAL; memcpy((char *)aoutuio, (char *)ainuio, sizeof(struct uio)); tvec = ainuio->afsio_iov; aoutuio->afsio_iov = aoutvec; - for(i=0;iafsio_iovcnt;i++){ + for (i = 0; i < ainuio->afsio_iovcnt; i++) { memcpy((char *)aoutvec, (char *)tvec, sizeof(struct iovec)); - tvec++; /* too many compiler bugs to do this as one expr */ + tvec++; /* too many compiler bugs to do this as one expr */ aoutvec++; } return 0; } /* trim the uio structure to the specified size */ -afsio_trim(auio, asize) -register struct uio *auio; -register afs_int32 asize; { +int +afsio_trim(register struct uio *auio, register afs_int32 asize) +{ register int i; register struct iovec *tv; @@ -55,19 +58,19 @@ register afs_int32 asize; { auio->afsio_resid = asize; tv = auio->afsio_iov; /* It isn't clear that multiple iovecs work ok (hasn't been tested!) */ - for(i=0;;i++,tv++) { + for (i = 0;; i++, tv++) { if (i >= auio->afsio_iovcnt || asize <= 0) { /* we're done */ auio->afsio_iovcnt = i; break; } - if (tv->iov_len <= asize) + if (tv->iov_len <= asize) /* entire iovec is included */ - asize -= tv->iov_len; /* this many fewer bytes */ + asize -= tv->iov_len; /* this many fewer bytes */ else { /* this is the last one */ tv->iov_len = asize; - auio->afsio_iovcnt = i+1; + auio->afsio_iovcnt = i + 1; break; } } @@ -75,14 +78,14 @@ register afs_int32 asize; { } /* skip asize bytes in the current uio structure */ -afsio_skip(auio, asize) -register struct uio *auio; -register afs_int32 asize; { +int +afsio_skip(register struct uio *auio, register afs_int32 asize) +{ register struct iovec *tv; /* pointer to current iovec */ register int cnt; AFS_STATCNT(afsio_skip); - /* It isn't guaranteed that multiple iovecs work ok (hasn't been tested!) */ + /* It isn't guaranteed that multiple iovecs work ok (hasn't been tested!) */ while (asize > 0 && auio->afsio_resid) { tv = auio->afsio_iov; cnt = tv->iov_len; @@ -101,4 +104,3 @@ register afs_int32 asize; { } return 0; } - diff --git a/src/afs/afs_osi_vget.c b/src/afs/afs_osi_vget.c index d099028fa..8f6cdd7ab 100644 --- a/src/afs/afs_osi_vget.c +++ b/src/afs/afs_osi_vget.c @@ -12,20 +12,21 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_osi_vget.c,v 1.1.1.7 2003/04/13 19:02:37 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_osi_vget.c,v 1.10 2003/07/15 23:14:12 shadow Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* statistics stuff */ +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* statistics stuff */ #if !defined(AFS_LINUX20_ENV) /* This is the common part of the vget VFS call. */ -int afs_osi_vget(struct vcache **avcpp, struct fid *afidp, - struct vrequest *areqp) +int +afs_osi_vget(struct vcache **avcpp, struct fid *afidp, struct vrequest *areqp) { struct VenusFid vfid; struct SmallFid Sfid; @@ -58,16 +59,15 @@ int afs_osi_vget(struct vcache **avcpp, struct fid *afidp, * afs_GetVCache. */ - ret = afs_NFSFindVCache(avcpp, &vfid, 1); + ret = afs_NFSFindVCache(avcpp, &vfid); if (ret > 1) { /* More than one entry matches. */ code = ENOENT; - } - else if (ret == 0) { + } else if (ret == 0) { /* didn't find an entry. */ - *avcpp = afs_GetVCache(&vfid, &treq, (afs_int32 *)0, (struct vcache*)0, 0); + *avcpp = afs_GetVCache(&vfid, &treq, NULL, NULL); } - if (! *avcpp) { + if (!*avcpp) { code = ENOENT; } diff --git a/src/afs/afs_osidnlc.c b/src/afs/afs_osidnlc.c index bfeed8ef7..cabe4886f 100644 --- a/src/afs/afs_osidnlc.c +++ b/src/afs/afs_osidnlc.c @@ -8,16 +8,17 @@ */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_osidnlc.c,v 1.1.1.5 2001/09/11 14:24:43 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_osidnlc.c,v 1.8 2003/07/15 23:14:12 shadow Exp $"); -#include "../afs/sysincludes.h" /*Standard vendor system headers*/ -#include "../afs/afsincludes.h" /*AFS-based standard headers*/ +#include "afs/sysincludes.h" /*Standard vendor system headers */ +#include "afsincludes.h" /*AFS-based standard headers */ #include "afs/afs.h" -#include "../afs/lock.h" -#include "../afs/afs_stats.h" -#include "../afs/afs_osidnlc.h" +#include "afs/lock.h" +#include "afs/afs_stats.h" +#include "afs/afs_osidnlc.h" /* Things to do: * also cache failed lookups. @@ -34,8 +35,8 @@ extern struct afs_lock afs_xvcache; dnlcstats_t dnlcstats; #define NCSIZE 300 -#define NHSIZE 256 /* must be power of 2. == NHASHENT in dir package */ -struct nc *ncfreelist = (struct nc *)0; +#define NHSIZE 256 /* must be power of 2. == NHASHENT in dir package */ +struct nc *ncfreelist = NULL; static struct nc nameCache[NCSIZE]; struct nc *nameHash[NHSIZE]; /* Hash table invariants: @@ -43,460 +44,441 @@ struct nc *nameHash[NHSIZE]; * 2. A single element in a hash bucket has itself as prev and next. */ -typedef enum {osi_dnlc_enterT, InsertEntryT, osi_dnlc_lookupT, ScavengeEntryT, osi_dnlc_removeT, RemoveEntryT, osi_dnlc_purgedpT, osi_dnlc_purgevpT, osi_dnlc_purgeT } traceevt; +typedef enum { osi_dnlc_enterT, InsertEntryT, osi_dnlc_lookupT, + ScavengeEntryT, osi_dnlc_removeT, RemoveEntryT, osi_dnlc_purgedpT, + osi_dnlc_purgevpT, osi_dnlc_purgeT +} traceevt; -int afs_usednlc = 1; +int afs_usednlc = 1; struct dt { - traceevt event; - unsigned char slot; + traceevt event; + unsigned char slot; }; -struct dt dnlctracetable[256]; +struct dt dnlctracetable[256]; int dnlct; -#define TRACE(e,s) /* if (dnlct == 256) dnlct = 0; dnlctracetable[dnlct].event = e; dnlctracetable[dnlct++].slot = s; */ +#define TRACE(e,s) /* if (dnlct == 256) dnlct = 0; dnlctracetable[dnlct].event = e; dnlctracetable[dnlct++].slot = s; */ #define dnlcHash(ts, hval) for (hval=0; *ts; ts++) { hval *= 173; hval += *ts; } -static struct nc * GetMeAnEntry() { - static unsigned int nameptr = 0; /* next bucket to pull something from */ - struct nc *tnc; - int j; - - if (ncfreelist) { - tnc = ncfreelist; - ncfreelist = tnc->next; - return tnc; - } - - for (j=0; j= NHSIZE) - nameptr =0; - if (nameHash[nameptr]) - break; - } - - TRACE(ScavengeEntryT, nameptr); - tnc = nameHash[nameptr]; - if (!tnc) /* May want to consider changing this to return 0 */ - osi_Panic("null tnc in GetMeAnEntry"); - - if (tnc->prev == tnc) { /* only thing in list, don't screw around */ - nameHash[nameptr] = (struct nc *) 0; - return (tnc); - } +static struct nc * +GetMeAnEntry(void) +{ + static unsigned int nameptr = 0; /* next bucket to pull something from */ + struct nc *tnc; + int j; + + if (ncfreelist) { + tnc = ncfreelist; + ncfreelist = tnc->next; + return tnc; + } + + for (j = 0; j < NHSIZE + 2; j++, nameptr++) { + if (nameptr >= NHSIZE) + nameptr = 0; + if (nameHash[nameptr]) + break; + } + + TRACE(ScavengeEntryT, nameptr); + tnc = nameHash[nameptr]; + if (!tnc) /* May want to consider changing this to return 0 */ + osi_Panic("null tnc in GetMeAnEntry"); - tnc = tnc->prev; /* grab oldest one in this bucket */ - /* remove it from list */ - tnc->next->prev = tnc->prev; - tnc->prev->next = tnc->next; + if (tnc->prev == tnc) { /* only thing in list, don't screw around */ + nameHash[nameptr] = NULL; + return (tnc); + } + + tnc = tnc->prev; /* grab oldest one in this bucket */ + /* remove it from list */ + tnc->next->prev = tnc->prev; + tnc->prev->next = tnc->next; - return (tnc); + return (tnc); } -static void InsertEntry(tnc) - struct nc *tnc; +static void +InsertEntry(struct nc *tnc) { - unsigned int key; - key = tnc->key & (NHSIZE -1); - - TRACE(InsertEntryT, key); - if(!nameHash[key]) { - nameHash[key] = tnc; - tnc->next = tnc->prev = tnc; - } - else { - tnc->next = nameHash[key]; - tnc->prev = tnc->next->prev; - tnc->next->prev = tnc; - tnc->prev->next = tnc; - nameHash[key] = tnc; - } + unsigned int key; + key = tnc->key & (NHSIZE - 1); + + TRACE(InsertEntryT, key); + if (!nameHash[key]) { + nameHash[key] = tnc; + tnc->next = tnc->prev = tnc; + } else { + tnc->next = nameHash[key]; + tnc->prev = tnc->next->prev; + tnc->next->prev = tnc; + tnc->prev->next = tnc; + nameHash[key] = tnc; + } } -int osi_dnlc_enter ( adp, aname, avc, avno ) - struct vcache *adp; - char *aname; - struct vcache *avc; - afs_hyper_t *avno; +int +osi_dnlc_enter(struct vcache *adp, char *aname, struct vcache *avc, + afs_hyper_t * avno) { - struct nc *tnc; - unsigned int key, skey; - char *ts = aname; - int safety; - - if (!afs_usednlc) - return 0; - - TRACE(osi_dnlc_enterT, 0); - dnlcHash( ts, key ); /* leaves ts pointing at the NULL */ - if (ts - aname >= AFSNCNAMESIZE) { - return 0; - } - skey = key & (NHSIZE -1); - dnlcstats.enters++; + struct nc *tnc; + unsigned int key, skey; + char *ts = aname; + int safety; + + if (!afs_usednlc) + return 0; + + TRACE(osi_dnlc_enterT, 0); + dnlcHash(ts, key); /* leaves ts pointing at the NULL */ + if (ts - aname >= AFSNCNAMESIZE) { + return 0; + } + skey = key & (NHSIZE - 1); + dnlcstats.enters++; -retry: - ObtainWriteLock(&afs_xdnlc,222); + retry: + ObtainWriteLock(&afs_xdnlc, 222); - /* Only cache entries from the latest version of the directory */ - if (!(adp->states & CStatd) || !hsame(*avno, adp->m.DataVersion)) { - ReleaseWriteLock(&afs_xdnlc); - return 0; - } - - /* - * Make sure each directory entry gets cached no more than once. - */ - for (tnc = nameHash[skey], safety=0; tnc; tnc = tnc->next, safety++ ) { - if ((tnc->dirp == adp) && (!strcmp((char *)tnc->name, aname))) { - /* duplicate entry */ - break; - } - else if (tnc->next == nameHash[skey]) { /* end of list */ - tnc = NULL; - break; + /* Only cache entries from the latest version of the directory */ + if (!(adp->states & CStatd) || !hsame(*avno, adp->m.DataVersion)) { + ReleaseWriteLock(&afs_xdnlc); + return 0; } - else if (safety >NCSIZE) { - afs_warn("DNLC cycle"); - dnlcstats.cycles++; - ReleaseWriteLock(&afs_xdnlc); - osi_dnlc_purge(); - goto retry; + + /* + * Make sure each directory entry gets cached no more than once. + */ + for (tnc = nameHash[skey], safety = 0; tnc; tnc = tnc->next, safety++) { + if ((tnc->dirp == adp) && (!strcmp((char *)tnc->name, aname))) { + /* duplicate entry */ + break; + } else if (tnc->next == nameHash[skey]) { /* end of list */ + tnc = NULL; + break; + } else if (safety > NCSIZE) { + afs_warn("DNLC cycle"); + dnlcstats.cycles++; + ReleaseWriteLock(&afs_xdnlc); + osi_dnlc_purge(); + goto retry; + } } - } - if (tnc == NULL) { - tnc = GetMeAnEntry(); + if (tnc == NULL) { + tnc = GetMeAnEntry(); - tnc->dirp = adp; - tnc->vp = avc; - tnc->key = key; - memcpy((char *)tnc->name, aname, ts-aname+1); /* include the NULL */ + tnc->dirp = adp; + tnc->vp = avc; + tnc->key = key; + memcpy((char *)tnc->name, aname, ts - aname + 1); /* include the NULL */ - InsertEntry(tnc); - } else { - /* duplicate */ - tnc->vp = avc; - } - ReleaseWriteLock(&afs_xdnlc); + InsertEntry(tnc); + } else { + /* duplicate */ + tnc->vp = avc; + } + ReleaseWriteLock(&afs_xdnlc); -return 0; + return 0; } struct vcache * -osi_dnlc_lookup ( adp, aname, locktype ) - struct vcache *adp; - char *aname; - int locktype; +osi_dnlc_lookup(struct vcache *adp, char *aname, int locktype) { - struct vcache * tvc; - int LRUme; - unsigned int key, skey; - char *ts = aname; - struct nc * tnc, *tnc1=0; - int safety; - - if (!afs_usednlc) - return 0; - - dnlcHash( ts, key ); /* leaves ts pointing at the NULL */ - if (ts - aname >= AFSNCNAMESIZE) { - return 0; - } - skey = key & (NHSIZE -1); - - TRACE(osi_dnlc_lookupT, skey); - dnlcstats.lookups++; - - ObtainReadLock(&afs_xvcache); - ObtainReadLock(&afs_xdnlc); - - for ( tvc = (struct vcache *) 0, tnc = nameHash[skey], safety=0; - tnc; tnc = tnc->next, safety++ ) { - if ( /* (tnc->key == key) && */ (tnc->dirp == adp) - && (!strcmp((char *)tnc->name, aname))) { - tvc = tnc->vp; - tnc1 = tnc; - break; - } - else if (tnc->next == nameHash[skey]) { /* end of list */ - break; + struct vcache *tvc; + int LRUme; + unsigned int key, skey; + char *ts = aname; + struct nc *tnc, *tnc1 = 0; + int safety; + + if (!afs_usednlc) + return 0; + + dnlcHash(ts, key); /* leaves ts pointing at the NULL */ + if (ts - aname >= AFSNCNAMESIZE) { + return 0; } - else if (safety >NCSIZE) { - afs_warn("DNLC cycle"); - dnlcstats.cycles++; - ReleaseReadLock(&afs_xdnlc); - ReleaseReadLock(&afs_xvcache); - osi_dnlc_purge(); - return(0); + skey = key & (NHSIZE - 1); + + TRACE(osi_dnlc_lookupT, skey); + dnlcstats.lookups++; + + ObtainReadLock(&afs_xvcache); + ObtainReadLock(&afs_xdnlc); + + for (tvc = NULL, tnc = nameHash[skey], safety = 0; tnc; + tnc = tnc->next, safety++) { + if ( /* (tnc->key == key) && */ (tnc->dirp == adp) + && (!strcmp((char *)tnc->name, aname))) { + tvc = tnc->vp; + tnc1 = tnc; + break; + } else if (tnc->next == nameHash[skey]) { /* end of list */ + break; + } else if (safety > NCSIZE) { + afs_warn("DNLC cycle"); + dnlcstats.cycles++; + ReleaseReadLock(&afs_xdnlc); + ReleaseReadLock(&afs_xvcache); + osi_dnlc_purge(); + return (0); + } } - } - LRUme = 0; /* (tnc != nameHash[skey]); */ - ReleaseReadLock(&afs_xdnlc); + LRUme = 0; /* (tnc != nameHash[skey]); */ + ReleaseReadLock(&afs_xdnlc); - if (!tvc) { - ReleaseReadLock(&afs_xvcache); - dnlcstats.misses++; - } - else { + if (!tvc) { + ReleaseReadLock(&afs_xvcache); + dnlcstats.misses++; + } else { #ifdef AFS_OSF_ENV - VN_HOLD((vnode_t *)tvc); + VN_HOLD((vnode_t *) tvc); #else - osi_vnhold(tvc, 0); + osi_vnhold(tvc, 0); #endif - ReleaseReadLock(&afs_xvcache); + ReleaseReadLock(&afs_xvcache); #ifdef notdef - /* - * XX If LRUme ever is non-zero change the if statement around because - * aix's cc with optimizer on won't necessarily check things in order XX - */ - if (LRUme && (0 == NBObtainWriteLock(&afs_xdnlc))) { - /* don't block to do this */ - /* tnc might have been moved during race condition, */ - /* but it's always in a legit hash chain when a lock is granted, - * or else it's on the freelist so prev == NULL, - * so at worst this is redundant */ - /* Now that we've got it held, and a lock on the dnlc, we - * should check to be sure that there was no race, and - * bail out if there was. */ - if (tnc->prev) { - /* special case for only two elements on list - relative ordering - * doesn't change */ - if (tnc->prev != tnc->next) { - /* remove from old location */ - tnc->prev->next = tnc->next; - tnc->next->prev = tnc->prev; - /* insert into new location */ - tnc->next = nameHash[skey]; - tnc->prev = tnc->next->prev; - tnc->next->prev = tnc; - tnc->prev->next = tnc; + /* + * XX If LRUme ever is non-zero change the if statement around because + * aix's cc with optimizer on won't necessarily check things in order XX + */ + if (LRUme && (0 == NBObtainWriteLock(&afs_xdnlc))) { + /* don't block to do this */ + /* tnc might have been moved during race condition, */ + /* but it's always in a legit hash chain when a lock is granted, + * or else it's on the freelist so prev == NULL, + * so at worst this is redundant */ + /* Now that we've got it held, and a lock on the dnlc, we + * should check to be sure that there was no race, and + * bail out if there was. */ + if (tnc->prev) { + /* special case for only two elements on list - relative ordering + * doesn't change */ + if (tnc->prev != tnc->next) { + /* remove from old location */ + tnc->prev->next = tnc->next; + tnc->next->prev = tnc->prev; + /* insert into new location */ + tnc->next = nameHash[skey]; + tnc->prev = tnc->next->prev; + tnc->next->prev = tnc; + tnc->prev->next = tnc; + } + nameHash[skey] = tnc; + } + ReleaseWriteLock(&afs_xdnlc); } - nameHash[skey] = tnc; - } - ReleaseWriteLock(&afs_xdnlc); - } #endif - } + } -return tvc; + return tvc; } static void -RemoveEntry (tnc, key) - struct nc *tnc; - unsigned int key; +RemoveEntry(struct nc *tnc, unsigned int key) { - if (!tnc->prev) /* things on freelist always have null prev ptrs */ - osi_Panic("bogus free list"); - - TRACE(RemoveEntryT, key); - if (tnc == tnc->next) { /* only one in list */ - nameHash[key] = (struct nc *) 0; - } - else { - if (tnc == nameHash[key]) - nameHash[key] = tnc->next; - tnc->prev->next = tnc->next; - tnc->next->prev = tnc->prev; - } + if (!tnc->prev) /* things on freelist always have null prev ptrs */ + osi_Panic("bogus free list"); + + TRACE(RemoveEntryT, key); + if (tnc == tnc->next) { /* only one in list */ + nameHash[key] = NULL; + } else { + if (tnc == nameHash[key]) + nameHash[key] = tnc->next; + tnc->prev->next = tnc->next; + tnc->next->prev = tnc->prev; + } - tnc->prev = (struct nc *) 0; /* everything not in hash table has 0 prev */ - tnc->key = 0; /* just for safety's sake */ + tnc->prev = NULL; /* everything not in hash table has 0 prev */ + tnc->key = 0; /* just for safety's sake */ } -int -osi_dnlc_remove ( adp, aname, avc ) - struct vcache *adp; - char *aname; - struct vcache *avc; +int +osi_dnlc_remove(struct vcache *adp, char *aname, struct vcache *avc) { - unsigned int key, skey; - char *ts = aname; - struct nc *tnc; - - if (!afs_usednlc) - return 0; + unsigned int key, skey; + char *ts = aname; + struct nc *tnc; - TRACE( osi_dnlc_removeT, skey); - dnlcHash( ts, key ); /* leaves ts pointing at the NULL */ - if (ts - aname >= AFSNCNAMESIZE) { - return 0; - } - skey = key & (NHSIZE -1); - TRACE( osi_dnlc_removeT, skey); - dnlcstats.removes++; - ObtainReadLock(&afs_xdnlc); - - for (tnc = nameHash[skey]; tnc; tnc = tnc->next) { - if ((tnc->dirp == adp) && (tnc->key == key) - && (!strcmp((char *)tnc->name, aname))) { - tnc->dirp = (struct vcache *) 0; /* now it won't match anything */ - break; + if (!afs_usednlc) + return 0; + + TRACE(osi_dnlc_removeT, skey); + dnlcHash(ts, key); /* leaves ts pointing at the NULL */ + if (ts - aname >= AFSNCNAMESIZE) { + return 0; } - else if (tnc->next == nameHash[skey]) { /* end of list */ - tnc = (struct nc *) 0; - break; + skey = key & (NHSIZE - 1); + TRACE(osi_dnlc_removeT, skey); + dnlcstats.removes++; + ObtainReadLock(&afs_xdnlc); + + for (tnc = nameHash[skey]; tnc; tnc = tnc->next) { + if ((tnc->dirp == adp) && (tnc->key == key) + && (!strcmp((char *)tnc->name, aname))) { + tnc->dirp = NULL; /* now it won't match anything */ + break; + } else if (tnc->next == nameHash[skey]) { /* end of list */ + tnc = NULL; + break; + } } - } - ReleaseReadLock(&afs_xdnlc); + ReleaseReadLock(&afs_xdnlc); - if (!tnc) - return 0; + if (!tnc) + return 0; - /* there is a little race condition here, but it's relatively - * harmless. At worst, I wind up removing a mapping that I just - * created. */ - if (EWOULDBLOCK == NBObtainWriteLock(&afs_xdnlc,1)) { - return 0; /* no big deal, tnc will get recycled eventually */ - } - RemoveEntry(tnc, skey); - tnc->next = ncfreelist; - ncfreelist = tnc; - ReleaseWriteLock(&afs_xdnlc); - -return 0; + /* there is a little race condition here, but it's relatively + * harmless. At worst, I wind up removing a mapping that I just + * created. */ + if (EWOULDBLOCK == NBObtainWriteLock(&afs_xdnlc, 1)) { + return 0; /* no big deal, tnc will get recycled eventually */ + } + RemoveEntry(tnc, skey); + tnc->next = ncfreelist; + ncfreelist = tnc; + ReleaseWriteLock(&afs_xdnlc); + + return 0; } /* remove anything pertaining to this directory. I can invalidate * things without the lock, since I am just looking through the array, * but to move things off the lists or into the freelist, I need the * write lock */ -int -osi_dnlc_purgedp (adp) - struct vcache *adp; +int +osi_dnlc_purgedp(struct vcache *adp) { - int i; - int writelocked; - - if (!afs_usednlc) - return 0; - - dnlcstats.purgeds++; - TRACE( osi_dnlc_purgedpT, 0); - writelocked = (0 == NBObtainWriteLock(&afs_xdnlc,2)); - - for (i=0; i -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_pioctl.c,v 1.17 2003/07/30 17:23:43 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_pioctl.c,v 1.78 2004/04/18 06:13:47 kolya Exp $"); -#include "../afs/sysincludes.h" /* Standard vendor system headers */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ -#include "../afs/vice.h" -#include "../rx/rx_globals.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ +#ifdef AFS_OBSD_ENV +#include "h/syscallargs.h" +#endif +#ifdef AFS_FBSD50_ENV +#include "h/sysproto.h" +#endif +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#include "afs/vice.h" +#include "rx/rx_globals.h" -extern void afs_ComputePAGStats(); -extern struct vcache *afs_LookupVCache(); struct VenusFid afs_rootFid; -afs_int32 afs_waitForever=0; +afs_int32 afs_waitForever = 0; short afs_waitForeverCount = 0; -afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */ -extern afs_int32 PROBE_INTERVAL; - -extern int cacheDiskType; -extern afs_int32 afs_cacheBlocks; -extern struct afs_q CellLRU; -extern char *afs_indexFlags; /* only one: is there data there? */ -extern afs_int32 afs_blocksUsed; -extern struct unixuser *afs_users[NUSERS]; -extern struct server *afs_servers[NSERVERS]; -extern struct interfaceAddr afs_cb_interface; /* client interface addresses */ -extern afs_rwlock_t afs_xserver; -extern afs_rwlock_t afs_xinterface; -extern afs_rwlock_t afs_xcell; -extern afs_rwlock_t afs_xuser; -#ifndef AFS_FINEG_SUNLOCK -extern afs_rwlock_t afs_xconn; -#endif -extern afs_rwlock_t afs_xvolume; -extern afs_lock_t afs_xdcache; /* lock: alloc new disk cache entries */ -extern afs_rwlock_t afs_xvcache; -extern afs_rwlock_t afs_xcbhash; -extern afs_int32 afs_mariner, afs_marinerHost; -extern struct srvAddr *afs_srvAddrs[NSERVERS]; -extern int afs_resourceinit_flag; -extern afs_int32 cryptall; - -static int PBogus(), PSetAcl(), PGetAcl(), PSetTokens(), PGetVolumeStatus(); -static int PSetVolumeStatus(), PFlush(), PNewStatMount(), PGetTokens(), PUnlog(); -static int PCheckServers(), PCheckVolNames(), PCheckAuth(), PFindVolume(); -static int PViceAccess(), PSetCacheSize(), Prefetch(); -static int PRemoveCallBack(), PNewCell(), PListCells(), PRemoveMount(); -static int PMariner(), PGetUserCell(), PGetWSCell(), PGetFileCell(); -static int PVenusLogging(), PNoop(), PSetCellStatus(), PGetCellStatus(); -static int PFlushVolumeData(), PGetCacheSize(); -static int PSetSysName(),PGetFID(); -static int PGetVnodeXStatus(); -static int PSetSPrefs(), PGetSPrefs(), PGag(), PTwiddleRx(); -static int PSetSPrefs33(), PStoreBehind(), PGCPAGs(); -static int PGetCPrefs(), PSetCPrefs(); /* client network addresses */ -static int PGetInitParams(), PFlushMount(), PRxStatProc(), PRxStatPeer(); -static int PGetRxkcrypt(), PSetRxkcrypt(); -static int PPrefetchFromTape(), PResidencyCmd(); -static int PNewAlias(), PListAliases(); -int PExportAfs(); - -static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCRED **acred, struct AFS_UCRED *credp); - -extern struct cm_initparams cm_initParams; - -static int (*(VpioctlSw[]))() = { - PBogus, /* 0 */ - PSetAcl, /* 1 */ - PGetAcl, /* 2 */ - PSetTokens, /* 3 */ - PGetVolumeStatus, /* 4 */ - PSetVolumeStatus, /* 5 */ - PFlush, /* 6 */ - PBogus, /* 7 */ - PGetTokens, /* 8 */ - PUnlog, /* 9 */ - PCheckServers, /* 10 */ - PCheckVolNames, /* 11 */ - PCheckAuth, /* 12 */ - PBogus, /* 13 -- used to be quick check time */ - PFindVolume, /* 14*/ - PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */ - PBogus, /* 16 -- used to be testing code */ - PNoop, /* 17 -- used to be enable group */ - PNoop, /* 18 -- used to be disable group */ - PBogus, /* 19 -- used to be list group */ - PViceAccess, /* 20 */ - PUnlog, /* 21 -- unlog *is* unpag in this system */ - PGetFID, /* 22 -- get file ID */ - PBogus, /* 23 -- used to be waitforever */ - PSetCacheSize, /* 24 */ - PRemoveCallBack, /* 25 -- flush only the callback */ - PNewCell, /* 26 */ - PListCells, /* 27 */ - PRemoveMount, /* 28 -- delete mount point */ - PNewStatMount, /* 29 -- new style mount point stat */ - PGetFileCell, /* 30 -- get cell name for input file */ - PGetWSCell, /* 31 -- get cell name for workstation */ - PMariner, /* 32 - set/get mariner host */ - PGetUserCell, /* 33 -- get cell name for user */ - PVenusLogging, /* 34 -- Enable/Disable logging */ - PGetCellStatus, /* 35 */ - PSetCellStatus, /* 36 */ - PFlushVolumeData, /* 37 -- flush all data from a volume */ - PSetSysName, /* 38 - Set system name */ - PExportAfs, /* 39 - Export Afs to remote nfs clients */ - PGetCacheSize, /* 40 - get cache size and usage */ - PGetVnodeXStatus, /* 41 - get vcache's special status */ - PSetSPrefs33, /* 42 - Set CM Server preferences... */ - PGetSPrefs, /* 43 - Get CM Server preferences... */ - PGag, /* 44 - turn off/on all CM messages */ - PTwiddleRx, /* 45 - adjust some RX params */ - PSetSPrefs, /* 46 - Set CM Server preferences... */ - PStoreBehind, /* 47 - set degree of store behind to be done */ - PGCPAGs, /* 48 - disable automatic pag gc-ing */ - PGetInitParams, /* 49 - get initial cm params */ - PGetCPrefs, /* 50 - get client interface addresses */ - PSetCPrefs, /* 51 - set client interface addresses */ - PFlushMount, /* 52 - flush mount symlink data */ - PRxStatProc, /* 53 - control process RX statistics */ - PRxStatPeer, /* 54 - control peer RX statistics */ - PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */ - PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */ - PBogus, /* 57 -- arla: set file prio */ - PBogus, /* 58 -- arla: fallback getfh */ - PBogus, /* 59 -- arla: fallback fhopen */ - PBogus, /* 60 -- arla: controls xfsdebug */ - PBogus, /* 61 -- arla: controls arla debug */ - PBogus, /* 62 -- arla: debug interface */ - PBogus, /* 63 -- arla: print xfs status */ - PBogus, /* 64 -- arla: force cache check */ - PBogus, /* 65 -- arla: break callback */ - PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */ - PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */ - PBogus, /* 68 -- arla: fetch stats */ +afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */ + +#define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \ + char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \ + struct AFS_UCRED **acred) + +/* Prototypes for pioctl routines */ +DECL_PIOCTL(PGetFID); +DECL_PIOCTL(PSetAcl); +DECL_PIOCTL(PStoreBehind); +DECL_PIOCTL(PGCPAGs); +DECL_PIOCTL(PGetAcl); +DECL_PIOCTL(PNoop); +DECL_PIOCTL(PBogus); +DECL_PIOCTL(PGetFileCell); +DECL_PIOCTL(PGetWSCell); +DECL_PIOCTL(PGetUserCell); +DECL_PIOCTL(PSetTokens); +DECL_PIOCTL(PGetVolumeStatus); +DECL_PIOCTL(PSetVolumeStatus); +DECL_PIOCTL(PFlush); +DECL_PIOCTL(PNewStatMount); +DECL_PIOCTL(PGetTokens); +DECL_PIOCTL(PUnlog); +DECL_PIOCTL(PMariner); +DECL_PIOCTL(PCheckServers); +DECL_PIOCTL(PCheckVolNames); +DECL_PIOCTL(PCheckAuth); +DECL_PIOCTL(PFindVolume); +DECL_PIOCTL(PViceAccess); +DECL_PIOCTL(PSetCacheSize); +DECL_PIOCTL(PGetCacheSize); +DECL_PIOCTL(PRemoveCallBack); +DECL_PIOCTL(PNewCell); +DECL_PIOCTL(PNewAlias); +DECL_PIOCTL(PListCells); +DECL_PIOCTL(PListAliases); +DECL_PIOCTL(PRemoveMount); +DECL_PIOCTL(PVenusLogging); +DECL_PIOCTL(PGetCellStatus); +DECL_PIOCTL(PSetCellStatus); +DECL_PIOCTL(PFlushVolumeData); +DECL_PIOCTL(PGetVnodeXStatus); +DECL_PIOCTL(PSetSysName); +DECL_PIOCTL(PSetSPrefs); +DECL_PIOCTL(PSetSPrefs33); +DECL_PIOCTL(PGetSPrefs); +DECL_PIOCTL(PExportAfs); +DECL_PIOCTL(PGag); +DECL_PIOCTL(PTwiddleRx); +DECL_PIOCTL(PGetInitParams); +DECL_PIOCTL(PGetRxkcrypt); +DECL_PIOCTL(PSetRxkcrypt); +DECL_PIOCTL(PGetCPrefs); +DECL_PIOCTL(PSetCPrefs); +DECL_PIOCTL(PFlushMount); +DECL_PIOCTL(PRxStatProc); +DECL_PIOCTL(PRxStatPeer); +DECL_PIOCTL(PPrefetchFromTape); +DECL_PIOCTL(PResidencyCmd); + +/* + * A macro that says whether we're going to need HandleClientContext(). + * This is currently used only by the nfs translator. + */ +#if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV) +#define AFS_NEED_CLIENTCONTEXT +#endif + +/* Prototypes for private routines */ +#ifdef AFS_NEED_CLIENTCONTEXT +static int HandleClientContext(struct afs_ioctl *ablob, int *com, + struct AFS_UCRED **acred, + struct AFS_UCRED *credp); +#endif +int HandleIoctl(register struct vcache *avc, register afs_int32 acom, + struct afs_ioctl *adata); +int afs_HandlePioctl(struct vnode *avp, afs_int32 acom, + register struct afs_ioctl *ablob, int afollow, + struct AFS_UCRED **acred); +static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow, + struct AFS_UCRED *acred); + + +static int (*(VpioctlSw[])) () = { + PBogus, /* 0 */ + PSetAcl, /* 1 */ + PGetAcl, /* 2 */ + PSetTokens, /* 3 */ + PGetVolumeStatus, /* 4 */ + PSetVolumeStatus, /* 5 */ + PFlush, /* 6 */ + PBogus, /* 7 */ + PGetTokens, /* 8 */ + PUnlog, /* 9 */ + PCheckServers, /* 10 */ + PCheckVolNames, /* 11 */ + PCheckAuth, /* 12 */ + PBogus, /* 13 -- used to be quick check time */ + PFindVolume, /* 14 */ + PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */ + PBogus, /* 16 -- used to be testing code */ + PNoop, /* 17 -- used to be enable group */ + PNoop, /* 18 -- used to be disable group */ + PBogus, /* 19 -- used to be list group */ + PViceAccess, /* 20 */ + PUnlog, /* 21 -- unlog *is* unpag in this system */ + PGetFID, /* 22 -- get file ID */ + PBogus, /* 23 -- used to be waitforever */ + PSetCacheSize, /* 24 */ + PRemoveCallBack, /* 25 -- flush only the callback */ + PNewCell, /* 26 */ + PListCells, /* 27 */ + PRemoveMount, /* 28 -- delete mount point */ + PNewStatMount, /* 29 -- new style mount point stat */ + PGetFileCell, /* 30 -- get cell name for input file */ + PGetWSCell, /* 31 -- get cell name for workstation */ + PMariner, /* 32 - set/get mariner host */ + PGetUserCell, /* 33 -- get cell name for user */ + PVenusLogging, /* 34 -- Enable/Disable logging */ + PGetCellStatus, /* 35 */ + PSetCellStatus, /* 36 */ + PFlushVolumeData, /* 37 -- flush all data from a volume */ + PSetSysName, /* 38 - Set system name */ + PExportAfs, /* 39 - Export Afs to remote nfs clients */ + PGetCacheSize, /* 40 - get cache size and usage */ + PGetVnodeXStatus, /* 41 - get vcache's special status */ + PSetSPrefs33, /* 42 - Set CM Server preferences... */ + PGetSPrefs, /* 43 - Get CM Server preferences... */ + PGag, /* 44 - turn off/on all CM messages */ + PTwiddleRx, /* 45 - adjust some RX params */ + PSetSPrefs, /* 46 - Set CM Server preferences... */ + PStoreBehind, /* 47 - set degree of store behind to be done */ + PGCPAGs, /* 48 - disable automatic pag gc-ing */ + PGetInitParams, /* 49 - get initial cm params */ + PGetCPrefs, /* 50 - get client interface addresses */ + PSetCPrefs, /* 51 - set client interface addresses */ + PFlushMount, /* 52 - flush mount symlink data */ + PRxStatProc, /* 53 - control process RX statistics */ + PRxStatPeer, /* 54 - control peer RX statistics */ + PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */ + PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */ + PBogus, /* 57 -- arla: set file prio */ + PBogus, /* 58 -- arla: fallback getfh */ + PBogus, /* 59 -- arla: fallback fhopen */ + PBogus, /* 60 -- arla: controls xfsdebug */ + PBogus, /* 61 -- arla: controls arla debug */ + PBogus, /* 62 -- arla: debug interface */ + PBogus, /* 63 -- arla: print xfs status */ + PBogus, /* 64 -- arla: force cache check */ + PBogus, /* 65 -- arla: break callback */ + PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */ + PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */ + PBogus, /* 68 -- arla: fetch stats */ }; -static int (*(CpioctlSw[]))() = { - PBogus, /* 0 */ - PNewAlias, /* 1 -- create new cell alias */ - PListAliases, /* 2 -- list cell aliases */ +static int (*(CpioctlSw[])) () = { + PBogus, /* 0 */ + PNewAlias, /* 1 -- create new cell alias */ + PListAliases, /* 2 -- list cell aliases */ }; #define PSetClientContext 99 /* Special pioctl to setup caller's creds */ @@ -157,10 +196,10 @@ int afs_nobody = NFS_NOBODY; static void afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst) { - dst->in = (char *)(unsigned long)src->in; - dst->out = (char *)(unsigned long)src->out; - dst->in_size = src->in_size; - dst->out_size = src->out_size; + dst->in = (char *)(unsigned long)src->in; + dst->out = (char *)(unsigned long)src->out; + dst->in_size = src->in_size; + dst->out_size = src->out_size; } /* @@ -171,190 +210,201 @@ afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst) static int copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst) { - int code; + int code; +#if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) + struct afs_ioctl32 dst32; + + if (!(IS64U)) { + AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code); + if (!code) + afs_ioctl32_to_afs_ioctl(&dst32, dst); + return code; + } +#endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */ + #if defined(AFS_HPUX_64BIT_ENV) - struct afs_ioctl32 dst32; + struct afs_ioctl32 dst32; - if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */ - { - AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code); - if (!code) - afs_ioctl32_to_afs_ioctl(&dst32, dst); - return code; - } + if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */ + AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code); + if (!code) + afs_ioctl32_to_afs_ioctl(&dst32, dst); + return code; + } #endif /* defined(AFS_HPUX_64BIT_ENV) */ #if defined(AFS_SUN57_64BIT_ENV) - struct afs_ioctl32 dst32; + struct afs_ioctl32 dst32; - if (get_udatamodel() == DATAMODEL_ILP32) { - AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code); - if (!code) - afs_ioctl32_to_afs_ioctl(&dst32, dst); - return code; - } + if (get_udatamodel() == DATAMODEL_ILP32) { + AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code); + if (!code) + afs_ioctl32_to_afs_ioctl(&dst32, dst); + return code; + } #endif /* defined(AFS_SUN57_64BIT_ENV) */ #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) - struct afs_ioctl32 dst32; + struct afs_ioctl32 dst32; - if (!ABI_IS_64BIT(get_current_abi())) - { - AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code); - if (!code) - afs_ioctl32_to_afs_ioctl(&dst32, dst); - return code; - } + if (!ABI_IS_64BIT(get_current_abi())) { + AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code); + if (!code) + afs_ioctl32_to_afs_ioctl(&dst32, dst); + return code; + } #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */ -#if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) - struct afs_ioctl32 dst32; +#if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV) + struct afs_ioctl32 dst32; #ifdef AFS_SPARC64_LINUX24_ENV - if (current->thread.flags & SPARC_FLAG_32BIT) + if (current->thread.flags & SPARC_FLAG_32BIT) #elif defined(AFS_SPARC64_LINUX20_ENV) - if (current->tss.flags & SPARC_FLAG_32BIT) + if (current->tss.flags & SPARC_FLAG_32BIT) #elif defined(AFS_AMD64_LINUX20_ENV) - if (current->thread.flags & THREAD_IA32) + if (current->thread.flags & THREAD_IA32) +#elif defined(AFS_PPC64_LINUX20_ENV) + if (current->thread.flags & PPC_FLAG_32BIT) #else #error Not done for this linux type -#endif - { - AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code); - if (!code) - afs_ioctl32_to_afs_ioctl(&dst32, dst); - return code; - } +#endif + { + AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code); + if (!code) + afs_ioctl32_to_afs_ioctl(&dst32, dst); + return code; + } #endif /* defined(AFS_LINUX_64BIT_KERNEL) */ - AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code); - return code; + AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code); + return code; } -HandleIoctl(avc, acom, adata) - register struct vcache *avc; - register afs_int32 acom; - struct afs_ioctl *adata; { - register afs_int32 code; - - code = 0; - AFS_STATCNT(HandleIoctl); - - switch(acom & 0xff) { - case 1: - avc->states |= CSafeStore; - avc->asynchrony = 0; - break; - - /* case 2 used to be abort store, but this is no longer provided, - since it is impossible to implement under normal Unix. - */ - - case 3: { - /* return the name of the cell this file is open on */ - register struct cell *tcell; - register afs_int32 i; - - tcell = afs_GetCell(avc->fid.Cell, READ_LOCK); - if (tcell) { - i = strlen(tcell->cellName) + 1; /* bytes to copy out */ - - if (i > adata->out_size) { - /* 0 means we're not interested in the output */ - if (adata->out_size != 0) code = EFAULT; - } - else { - /* do the copy */ - AFS_COPYOUT(tcell->cellName, adata->out, i, code); - } - afs_PutCell(tcell, READ_LOCK); - } - else code = ENOTTY; - } - break; - - case 49: /* VIOC_GETINITPARAMS */ - if (adata->out_size < sizeof(struct cm_initparams)) { - code = EFAULT; - } - else { - AFS_COPYOUT(&cm_initParams, adata->out, - sizeof(struct cm_initparams), code); - } - break; - - default: - - code = EINVAL; - break; - } - return code; /* so far, none implemented */ - } - - +int +HandleIoctl(register struct vcache *avc, register afs_int32 acom, + struct afs_ioctl *adata) +{ + register afs_int32 code; + + code = 0; + AFS_STATCNT(HandleIoctl); + + switch (acom & 0xff) { + case 1: + avc->states |= CSafeStore; + avc->asynchrony = 0; + break; + + /* case 2 used to be abort store, but this is no longer provided, + * since it is impossible to implement under normal Unix. + */ + + case 3:{ + /* return the name of the cell this file is open on */ + register struct cell *tcell; + register afs_int32 i; + + tcell = afs_GetCell(avc->fid.Cell, READ_LOCK); + if (tcell) { + i = strlen(tcell->cellName) + 1; /* bytes to copy out */ + + if (i > adata->out_size) { + /* 0 means we're not interested in the output */ + if (adata->out_size != 0) + code = EFAULT; + } else { + /* do the copy */ + AFS_COPYOUT(tcell->cellName, adata->out, i, code); + } + afs_PutCell(tcell, READ_LOCK); + } else + code = ENOTTY; + } + break; + + case 49: /* VIOC_GETINITPARAMS */ + if (adata->out_size < sizeof(struct cm_initparams)) { + code = EFAULT; + } else { + AFS_COPYOUT(&cm_initParams, adata->out, + sizeof(struct cm_initparams), code); + } + break; + + default: + + code = EINVAL; +#ifdef AFS_AIX51_ENV + code = ENOSYS; +#endif + break; + } + return code; /* so far, none implemented */ +} + + #ifdef AFS_AIX_ENV /* For aix we don't temporarily bypass ioctl(2) but rather do our * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl * is now called from afs_gn_ioctl. */ -afs_ioctl(tvc, cmd, arg) - struct vcache *tvc; - int cmd; - int arg; -{ - struct afs_ioctl data; - int error = 0; - - AFS_STATCNT(afs_ioctl); - if (((cmd >> 8) & 0xff) == 'V') { - /* This is a VICEIOCTL call */ - AFS_COPYIN(arg, (caddr_t) &data, sizeof(data), error); - if (error) - return(error); - error = HandleIoctl(tvc, cmd, &data); - return(error); - } else { - /* No-op call; just return. */ - return(ENOTTY); - } +int +afs_ioctl(struct vcache *tvc, int cmd, int arg) +{ + struct afs_ioctl data; + int error = 0; + + AFS_STATCNT(afs_ioctl); + if (((cmd >> 8) & 0xff) == 'V') { + /* This is a VICEIOCTL call */ + AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error); + if (error) + return (error); + error = HandleIoctl(tvc, cmd, &data); + return (error); + } else { + /* No-op call; just return. */ + return (ENOTTY); + } } #endif /* AFS_AIX_ENV */ #if defined(AFS_SGI_ENV) -afs_ioctl(OSI_VN_DECL(tvc), int cmd, void * arg, int flag, cred_t *cr, rval_t *rvalp +afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr, + rval_t * rvalp #ifdef AFS_SGI65_ENV - , struct vopbd *vbds -#endif - ) -{ - struct afs_ioctl data; - int error = 0; - int locked; - - OSI_VN_CONVERT(tvc); - - AFS_STATCNT(afs_ioctl); - if (((cmd >> 8) & 0xff) == 'V') { - /* This is a VICEIOCTL call */ - error = copyin_afs_ioctl(arg, &data); - if (error) - return(error); - locked = ISAFS_GLOCK(); - if (!locked) - AFS_GLOCK(); - error = HandleIoctl(tvc, cmd, &data); - if (!locked) - AFS_GUNLOCK(); - return(error); - } else { - /* No-op call; just return. */ - return(ENOTTY); - } + , struct vopbd * vbds +#endif + ) +{ + struct afs_ioctl data; + int error = 0; + int locked; + + OSI_VN_CONVERT(tvc); + + AFS_STATCNT(afs_ioctl); + if (((cmd >> 8) & 0xff) == 'V') { + /* This is a VICEIOCTL call */ + error = copyin_afs_ioctl(arg, &data); + if (error) + return (error); + locked = ISAFS_GLOCK(); + if (!locked) + AFS_GLOCK(); + error = HandleIoctl(tvc, cmd, &data); + if (!locked) + AFS_GUNLOCK(); + return (error); + } else { + /* No-op call; just return. */ + return (ENOTTY); + } } #endif /* AFS_SGI_ENV */ - /* unlike most calls here, this one uses u.u_error to return error conditions, since this is really an intercepted chapter 2 call, rather than a vnode interface call. @@ -363,16 +413,28 @@ afs_ioctl(OSI_VN_DECL(tvc), int cmd, void * arg, int flag, cred_t *cr, rval_t *r #ifndef AFS_HPUX102_ENV #if !defined(AFS_SGI_ENV) #ifdef AFS_AIX32_ENV +#ifdef AFS_AIX51_ENV +#ifdef __64BIT__ +kioctl(fdes, com, arg, ext, arg2, arg3) +#else /* __64BIT__ */ +kioctl32(fdes, com, arg, ext, arg2, arg3) +#endif /* __64BIT__ */ + caddr_t arg2, arg3; +#else kioctl(fdes, com, arg, ext) +#endif int fdes, com; caddr_t arg, ext; { - struct a { - int fd, com; - caddr_t arg, ext; - } u_uap, *uap = &u_uap; + struct a { + int fd, com; + caddr_t arg, ext; +#ifdef AFS_AIX51_ENV + caddr_t arg2, arg3; +#endif + } u_uap, *uap = &u_uap; #else -#ifdef AFS_SUN5_ENV +#if defined(AFS_SUN5_ENV) struct afs_ioctl_sys { int fd; @@ -380,295 +442,304 @@ struct afs_ioctl_sys { int arg; }; -afs_xioctl (uap, rvp) - struct afs_ioctl_sys *uap; - rval_t *rvp; +afs_xioctl(uap, rvp) + struct afs_ioctl_sys *uap; + rval_t *rvp; { -#else -#ifdef AFS_OSF_ENV -afs_xioctl (p, args, retval) - struct proc *p; - void *args; - long *retval; +#elif defined(AFS_OSF_ENV) +afs_xioctl(p, args, retval) + struct proc *p; + void *args; + long *retval; { struct a { - long fd; - u_long com; - caddr_t arg; + long fd; + u_long com; + caddr_t arg; } *uap = (struct a *)args; -#else /* AFS_OSF_ENV */ -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#elif defined(AFS_FBSD50_ENV) +#define arg data +int +afs_xioctl(td, uap, retval) + struct thread *td; + register struct ioctl_args *uap; + register_t *retval; +{ + struct proc *p = td->td_proc; +#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) struct ioctl_args { - int fd; - u_long com; - caddr_t arg; + int fd; + u_long com; + caddr_t arg; }; -afs_xioctl(p, uap, retval) - struct proc *p; - register struct ioctl_args *uap; - register_t *retval; + +int +afs_xioctl(p, uap, retval) + struct proc *p; + register struct ioctl_args *uap; + register_t *retval; { -#else -#ifdef AFS_LINUX22_ENV +#elif defined(AFS_LINUX22_ENV) struct afs_ioctl_sys { unsigned int com; unsigned long arg; }; -asmlinkage int afs_xioctl(struct inode *ip, struct file *fp, - unsigned int com, unsigned long arg) +asmlinkage int +afs_xioctl(struct inode *ip, struct file *fp, unsigned int com, + unsigned long arg) { struct afs_ioctl_sys ua, *uap = &ua; #else -afs_xioctl () - { - register struct a { +int +afs_xioctl(void) +{ + register struct a { int fd; int com; caddr_t arg; - } *uap = (struct a *)u.u_ap; -#endif /* AFS_LINUX22_ENV */ -#endif /* AFS_DARWIN_ENV || AFS_FBSD_ENV */ -#endif /* AFS_OSF_ENV */ -#endif /* AFS_SUN5_ENV */ + } *uap = (struct a *)u.u_ap; +#endif /* AFS_SUN5_ENV */ #endif -#ifndef AFS_LINUX22_ENV -#if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) - struct file *fd; -#else - register struct file *fd; -#endif -#endif -#if defined(AFS_FBSD_ENV) - register struct filedesc *fdp; -#endif - register struct vcache *tvc; - register int ioctlDone = 0, code = 0; - - AFS_STATCNT(afs_xioctl); -#if defined(AFS_FBSD_ENV) - fdp=p->p_fd; - if ((u_int)uap->fd >= fdp->fd_nfiles || - (fd = fdp->fd_ofiles[uap->fd]) == NULL) - return EBADF; - if ((fd->f_flag & (FREAD | FWRITE)) == 0) - return EBADF; -#else -#if defined(AFS_DARWIN_ENV) - if ((code=fdgetf(p, uap->fd, &fd))) - return code; -#else -#ifdef AFS_LINUX22_ENV +#if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) + struct file *fd; +#elif !defined(AFS_LINUX22_ENV) + register struct file *fd; +#endif +#if defined(AFS_XBSD_ENV) + register struct filedesc *fdp; +#endif + register struct vcache *tvc; + register int ioctlDone = 0, code = 0; + + AFS_STATCNT(afs_xioctl); +#if defined(AFS_XBSD_ENV) + fdp = p->p_fd; + if ((u_int) uap->fd >= fdp->fd_nfiles + || (fd = fdp->fd_ofiles[uap->fd]) == NULL) + return EBADF; + if ((fd->f_flag & (FREAD | FWRITE)) == 0) + return EBADF; +#elif defined(AFS_DARWIN_ENV) + if ((code = fdgetf(p, uap->fd, &fd))) + return code; +#elif defined(AFS_LINUX22_ENV) ua.com = com; ua.arg = arg; -#else -#ifdef AFS_AIX32_ENV - uap->fd = fdes; - uap->com = com; - uap->arg = arg; - if (setuerror(getf(uap->fd, &fd))) { +#elif defined(AFS_AIX32_ENV) + uap->fd = fdes; + uap->com = com; + uap->arg = arg; +#ifdef AFS_AIX51_ENV + uap->arg2 = arg2; + uap->arg3 = arg3; +#endif + if (setuerror(getf(uap->fd, &fd))) { return -1; } -#else -#ifdef AFS_OSF_ENV +#elif defined(AFS_OSF_ENV) fd = NULL; if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state)) - return code; -#else /* AFS_OSF_ENV */ -#ifdef AFS_SUN5_ENV -#if defined(AFS_SUN57_ENV) - fd = getf(uap->fd); - if (!fd) return(EBADF); -#elif defined(AFS_SUN54_ENV) - fd = GETF(uap->fd); - if (!fd) return(EBADF); -#else - if (code = getf(uap->fd, &fd)) { - return (code); - } -#endif + return code; +#elif defined(AFS_SUN5_ENV) +# if defined(AFS_SUN57_ENV) + fd = getf(uap->fd); + if (!fd) + return (EBADF); +# elif defined(AFS_SUN54_ENV) + fd = GETF(uap->fd); + if (!fd) + return (EBADF); +# else + if (code = getf(uap->fd, &fd)) { + return (code); + } +# endif /* AFS_SUN57_ENV */ #else - fd = getf(uap->fd); - if (!fd) return; + fd = getf(uap->fd); + if (!fd) + return (EBADF); #endif -#endif -#endif -#endif -#endif -#endif - - /* first determine whether this is any sort of vnode */ -#ifdef AFS_LINUX22_ENV - tvc = VTOAFS(ip); - { + /* first determine whether this is any sort of vnode */ +#if defined(AFS_LINUX22_ENV) + tvc = VTOAFS(ip); + { #else -#ifdef AFS_SUN5_ENV - if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) { +#ifdef AFS_SUN5_ENV + if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) { #else - if (fd->f_type == DTYPE_VNODE) { + if (fd->f_type == DTYPE_VNODE) { #endif /* good, this is a vnode; next see if it is an AFS vnode */ #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */ +#elif defined(AFS_OBSD_ENV) + tvc = + IsAfsVnode((struct vnode *)fd-> + f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL; #else - tvc = VTOAFS((struct vnode*)fd->f_data); /* valid, given a vnode */ + tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */ #endif #endif /* AFS_LINUX22_ENV */ if (tvc && IsAfsVnode(AFSTOV(tvc))) { #ifdef AFS_DEC_ENV - tvc = VTOAFS(afs_gntovn((struct gnode *) tvc)); - if (!tvc) { /* shouldn't happen with held gnodes */ - u.u_error = ENOENT; - return; - } -#endif - /* This is an AFS vnode */ - if (((uap->com >> 8) & 0xff) == 'V') { - register struct afs_ioctl *datap; - AFS_GLOCK(); - datap = (struct afs_ioctl *) osi_AllocSmallSpace(AFS_SMALLOCSIZ); - AFS_COPYIN((char *)uap->arg, (caddr_t) datap, sizeof (struct afs_ioctl), code); - if (code) { - osi_FreeSmallSpace(datap); - AFS_GUNLOCK(); -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return code; -#else + tvc = VTOAFS(afs_gntovn((struct gnode *)tvc)); + if (!tvc) { /* shouldn't happen with held gnodes */ + u.u_error = ENOENT; + return; + } +#endif + /* This is an AFS vnode */ + if (((uap->com >> 8) & 0xff) == 'V') { + register struct afs_ioctl *datap; + AFS_GLOCK(); + datap = + (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ); + AFS_COPYIN((char *)uap->arg, (caddr_t) datap, + sizeof(struct afs_ioctl), code); + if (code) { + osi_FreeSmallSpace(datap); + AFS_GUNLOCK(); +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + return code; +#else #if defined(AFS_SUN5_ENV) #ifdef AFS_SUN54_ENV - releasef(uap->fd); + releasef(uap->fd); #else - releasef(fd); + releasef(fd); #endif - return (EFAULT); + return (EFAULT); #else #ifdef AFS_OSF_ENV #ifdef AFS_OSF30_ENV - FP_UNREF_ALWAYS(fd); + FP_UNREF_ALWAYS(fd); #else - FP_UNREF(fd); + FP_UNREF(fd); #endif - return code; -#else /* AFS_OSF_ENV */ + return code; +#else /* AFS_OSF_ENV */ #ifdef AFS_AIX41_ENV - ufdrele(uap->fd); + ufdrele(uap->fd); #endif #ifdef AFS_LINUX22_ENV - return -code; + return -code; #else - setuerror(code); - return; + setuerror(code); + return; #endif #endif #endif #endif - } - code = HandleIoctl(tvc, uap->com, datap); - osi_FreeSmallSpace(datap); - AFS_GUNLOCK(); - ioctlDone = 1; + } + code = HandleIoctl(tvc, uap->com, datap); + osi_FreeSmallSpace(datap); + AFS_GUNLOCK(); + ioctlDone = 1; #ifdef AFS_AIX41_ENV - ufdrele(uap->fd); + ufdrele(uap->fd); #endif #ifdef AFS_OSF_ENV #ifdef AFS_OSF30_ENV - FP_UNREF_ALWAYS(fd); + FP_UNREF_ALWAYS(fd); #else - FP_UNREF(fd); + FP_UNREF(fd); #endif #endif - } + } #if defined(AFS_LINUX22_ENV) - else - code = EINVAL; + else + code = EINVAL; #endif } - } + } - if (!ioctlDone) { + if (!ioctlDone) { #ifdef AFS_AIX41_ENV - ufdrele(uap->fd); - code = okioctl(fdes, com, arg, ext); - return code; -#else + ufdrele(uap->fd); +#ifdef AFS_AIX51_ENV +#ifdef __64BIT__ + code = okioctl(fdes, com, arg, ext, arg2, arg3); +#else /* __64BIT__ */ + code = okioctl32(fdes, com, arg, ext, arg2, arg3); +#endif /* __64BIT__ */ +#else /* !AFS_AIX51_ENV */ + code = okioctl(fdes, com, arg, ext); +#endif /* AFS_AIX51_ENV */ + return code; +#else /* !AFS_AIX41_ENV */ #ifdef AFS_AIX32_ENV - okioctl(fdes, com, arg, ext); -#else -#if defined(AFS_SUN5_ENV) + okioctl(fdes, com, arg, ext); +#elif defined(AFS_SUN5_ENV) #if defined(AFS_SUN57_ENV) releasef(uap->fd); #elif defined(AFS_SUN54_ENV) - RELEASEF(uap->fd); -#else - releasef(fd); -#endif - code = ioctl(uap, rvp); -#else -#if defined(AFS_FBSD_ENV) - return ioctl(p, uap); -#else -#if defined(AFS_DARWIN_ENV) - return ioctl(p, uap, retval); -#else -#ifdef AFS_OSF_ENV - code = ioctl(p, args, retval); + RELEASEF(uap->fd); +#else + releasef(fd); +#endif + code = ioctl(uap, rvp); +#elif defined(AFS_FBSD50_ENV) + return ioctl(td, uap); +#elif defined(AFS_FBSD_ENV) + return ioctl(p, uap); +#elif defined(AFS_OBSD_ENV) + code = sys_ioctl(p, uap, retval); +#elif defined(AFS_DARWIN_ENV) + return ioctl(p, uap, retval); +#elif defined(AFS_OSF_ENV) + code = ioctl(p, args, retval); #ifdef AFS_OSF30_ENV - FP_UNREF_ALWAYS(fd); + FP_UNREF_ALWAYS(fd); #else - FP_UNREF(fd); -#endif - return code; -#else /* AFS_OSF_ENV */ -#ifndef AFS_LINUX22_ENV - ioctl(); -#endif -#endif -#endif -#endif + FP_UNREF(fd); #endif + return code; +#elif !defined(AFS_LINUX22_ENV) + ioctl(); #endif #endif - } + } #ifdef AFS_SUN5_ENV - if (ioctlDone) + if (ioctlDone) #ifdef AFS_SUN54_ENV - releasef(uap->fd); + releasef(uap->fd); #else - releasef(fd); + releasef(fd); #endif - return (code); + return (code); #else #ifdef AFS_LINUX22_ENV - return -code; + return -code; #else -#if !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) - if (!getuerror()) - setuerror(code); +#if defined(KERNEL_HAVE_UERROR) + if (!getuerror()) + setuerror(code); #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV) - return (getuerror() ? -1 : u.u_ioctlrv); + return (getuerror()? -1 : u.u_ioctlrv); #else - return getuerror() ? -1 : 0; + return getuerror()? -1 : 0; #endif #endif #endif /* AFS_LINUX22_ENV */ -#endif /* AFS_SUN5_ENV */ -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return (code); +#endif /* AFS_SUN5_ENV */ +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + return (code); #endif - } +} #endif /* AFS_SGI_ENV */ #endif /* AFS_HPUX102_ENV */ - + #if defined(AFS_SGI_ENV) /* "pioctl" system call entry point; just pass argument to the parameterized - call below */ + * call below */ struct pioctlargs { - char *path; - sysarg_t cmd; - caddr_t cmarg; - sysarg_t follow; + char *path; + sysarg_t cmd; + caddr_t cmarg; + sysarg_t follow; }; int -afs_pioctl(struct pioctlargs *uap, rval_t *rvp) +afs_pioctl(struct pioctlargs *uap, rval_t * rvp) { int code; @@ -682,48 +753,63 @@ afs_pioctl(struct pioctlargs *uap, rval_t *rvp) return u.u_error; #endif } -#endif /* AFS_SGI_ENV */ -#ifdef AFS_OSF_ENV +#elif defined(AFS_OSF_ENV) afs_pioctl(p, args, retval) - struct proc *p; - void *args; - int *retval; + struct proc *p; + void *args; + int *retval; { struct a { - char *path; - int cmd; - caddr_t cmarg; - int follow; - } *uap = (struct a *) args; + char *path; + int cmd; + caddr_t cmarg; + int follow; + } *uap = (struct a *)args; AFS_STATCNT(afs_pioctl); return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow)); } -extern struct mount *afs_globalVFS; -#else /* AFS_OSF_ENV */ -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#elif defined(AFS_FBSD50_ENV) +int +afs_pioctl(td, args, retval) + struct thread *td; + void *args; + int *retval; +{ + struct a { + char *path; + int cmd; + caddr_t cmarg; + int follow; + } *uap = (struct a *)args; + + AFS_STATCNT(afs_pioctl); + return (afs_syscall_pioctl + (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred)); +} + +#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) +int afs_pioctl(p, args, retval) - struct proc *p; - void *args; - int *retval; + struct proc *p; + void *args; + int *retval; { struct a { - char *path; - int cmd; - caddr_t cmarg; - int follow; - } *uap = (struct a *) args; - + char *path; + int cmd; + caddr_t cmarg; + int follow; + } *uap = (struct a *)args; + AFS_STATCNT(afs_pioctl); - return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow, p->p_cred->pc_ucred)); -} + return (afs_syscall_pioctl + (uap->path, uap->cmd, uap->cmarg, uap->follow, + p->p_cred->pc_ucred)); +} -extern struct mount *afs_globalVFS; -#else /* AFS_OSF_ENV */ -extern struct vfs *afs_globalVFS; -#endif #endif /* macro to avoid adding any more #ifdef's to pioctl code. */ @@ -733,331 +819,260 @@ extern struct vfs *afs_globalVFS; #define PIOCTL_FREE_CRED() #endif +int #ifdef AFS_SUN5_ENV afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp) - rval_t *rvp; - struct AFS_UCRED *credp; + rval_t *rvp; + struct AFS_UCRED *credp; #else -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) afs_syscall_pioctl(path, com, cmarg, follow, credp) - struct AFS_UCRED *credp; + struct AFS_UCRED *credp; #else afs_syscall_pioctl(path, com, cmarg, follow) #endif #endif - char *path; - unsigned int com; - caddr_t cmarg; - int follow; + char *path; + unsigned int com; + caddr_t cmarg; + int follow; { struct afs_ioctl data; - struct AFS_UCRED *tmpcred, *foreigncreds = 0; + struct AFS_UCRED *tmpcred, *foreigncreds = NULL; register afs_int32 code = 0; struct vnode *vp; #ifdef AFS_DEC_ENV struct vnode *gp; #endif #ifdef AFS_AIX41_ENV - struct ucred *credp = crref(); /* don't free until done! */ + struct ucred *credp = crref(); /* don't free until done! */ #endif #ifdef AFS_LINUX22_ENV - cred_t *credp = crref(); /* don't free until done! */ + cred_t *credp = crref(); /* don't free until done! */ struct dentry *dp; - #endif + AFS_STATCNT(afs_syscall_pioctl); - if (follow) follow = 1; /* compat. with old venus */ + if (follow) + follow = 1; /* compat. with old venus */ code = copyin_afs_ioctl(cmarg, &data); if (code) { PIOCTL_FREE_CRED(); -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SGI64_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return (code); -#else +#if defined(KERNEL_HAVE_UERROR) setuerror(code); - return code; #endif - } + return (code); + } if ((com & 0xff) == PSetClientContext) { -#if defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return EINVAL; /* Not handling these yet. */ -#else -#if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) +#ifdef AFS_NEED_CLIENTCONTEXT +#if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) code = HandleClientContext(&data, &com, &foreigncreds, credp); #else -#if defined(AFS_HPUX101_ENV) - code=HandleClientContext(&data, &com, &foreigncreds, p_cred(u.u_procp)); -#else -#ifdef AFS_SGI_ENV - code = HandleClientContext(&data, &com, &foreigncreds, OSI_GET_CURRENT_CRED()); -#else - code = HandleClientContext(&data, &com, &foreigncreds, u.u_cred); -#endif /* AFS_SGI_ENV */ -#endif + code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred()); #endif -#endif - if (code) { - if (foreigncreds) { - crfree(foreigncreds); - } - PIOCTL_FREE_CRED(); -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SGI64_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return (code); + if (code) { + if (foreigncreds) { + crfree(foreigncreds); + } + PIOCTL_FREE_CRED(); +#if defined(KERNEL_HAVE_UERROR) + return (setuerror(code), code); #else - return (setuerror(code), code); + return (code); #endif - } - } -#if !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) + } +#else /* AFS_NEED_CLIENTCONTEXT */ + return EINVAL; +#endif /* AFS_NEED_CLIENTCONTEXT */ + } +#ifdef AFS_NEED_CLIENTCONTEXT if (foreigncreds) { - /* - * We could have done without temporary setting the u.u_cred below - * (foreigncreds could be passed as param the pioctl modules) - * but calls such as afs_osi_suser() doesn't allow that since it - * references u.u_cred directly. We could, of course, do something - * like afs_osi_suser(cred) which, I think, is better since it - * generalizes and supports multi cred environments... - */ + /* + * We could have done without temporary setting the u.u_cred below + * (foreigncreds could be passed as param the pioctl modules) + * but calls such as afs_osi_suser() doesn't allow that since it + * references u.u_cred directly. We could, of course, do something + * like afs_osi_suser(cred) which, I think, is better since it + * generalizes and supports multi cred environments... + */ #ifdef AFS_SUN5_ENV tmpcred = credp; credp = foreigncreds; -#else -#ifdef AFS_AIX41_ENV +#elif defined(AFS_AIX41_ENV) tmpcred = crref(); /* XXX */ crset(foreigncreds); -#else -#if defined(AFS_HPUX101_ENV) +#elif defined(AFS_HPUX101_ENV) tmpcred = p_cred(u.u_procp); set_p_cred(u.u_procp, foreigncreds); +#elif defined(AFS_SGI_ENV) + tmpcred = OSI_GET_CURRENT_CRED(); + OSI_SET_CURRENT_CRED(foreigncreds); #else -#ifdef AFS_SGI_ENV - tmpcred = OSI_GET_CURRENT_CRED(); - OSI_SET_CURRENT_CRED(foreigncreds); -#else - tmpcred = u.u_cred; - u.u_cred = foreigncreds; -#endif /* AFS_SGI64_ENV */ -#endif /* AFS_HPUX101_ENV */ -#endif + tmpcred = u.u_cred; + u.u_cred = foreigncreds; #endif } -#endif +#endif /* AFS_NEED_CLIENTCONTEXT */ if ((com & 0xff) == 15) { - /* special case prefetch so entire pathname eval occurs in helper process. - otherwise, the pioctl call is essentially useless */ -#if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - code = Prefetch(path, &data, follow, - foreigncreds ? foreigncreds : credp); -#else -#if defined(AFS_HPUX101_ENV) - code = Prefetch(path, &data, follow, p_cred(u.u_procp)); + /* special case prefetch so entire pathname eval occurs in helper process. + * otherwise, the pioctl call is essentially useless */ +#if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + code = + Prefetch(path, &data, follow, + foreigncreds ? foreigncreds : credp); #else -#ifdef AFS_SGI_ENV - code = Prefetch(path, &data, follow, OSI_GET_CURRENT_CRED()); -#else - code = Prefetch(path, &data, follow, u.u_cred); -#endif /* AFS_SGI64_ENV */ -#endif /* AFS_HPUX101_ENV */ + code = Prefetch(path, &data, follow, osi_curcred()); #endif -#if !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) - if (foreigncreds) { -#ifdef AFS_AIX41_ENV - crset(tmpcred); /* restore original credentials */ -#else -#if defined(AFS_HPUX101_ENV) - set_p_cred(u.u_procp, tmpcred); /* restore original credentials */ -#else -#ifndef AFS_SUN5_ENV -#ifdef AFS_SGI_ENV - OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */ -#else - u.u_cred = tmpcred; /* restore original credentials */ -#endif -#endif -#endif /* AFS_HPUX101_ENV */ - crfree(foreigncreds); -#endif - } -#endif /* AFS_LINUX22_ENV */ - PIOCTL_FREE_CRED(); -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SGI64_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return (code); -#else - return (setuerror(code), code); + vp = NULL; +#if defined(KERNEL_HAVE_UERROR) + setuerror(code); #endif + goto rescred; } if (path) { AFS_GUNLOCK(); #ifdef AFS_AIX41_ENV - code = lookupname(path, USR, follow, NULL, &vp, - foreigncreds ? foreigncreds : credp); + code = + lookupname(path, USR, follow, NULL, &vp, + foreigncreds ? foreigncreds : credp); #else #ifdef AFS_LINUX22_ENV - code = gop_lookupname(path, AFS_UIOUSER, follow, (struct vnode **) 0, &dp); + code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp); if (!code) vp = (struct vnode *)dp->d_inode; #else - code = gop_lookupname(path, AFS_UIOUSER, follow, (struct vnode **) 0, &vp); + code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp); #endif /* AFS_LINUX22_ENV */ #endif /* AFS_AIX41_ENV */ AFS_GLOCK(); if (code) { -#if !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) - if (foreigncreds) { -#ifdef AFS_AIX41_ENV - crset(tmpcred); /* restore original credentials */ -#else -#if defined(AFS_HPUX101_ENV) - set_p_cred(u.u_procp, tmpcred); /* restore original credentials */ -#else -#if !defined(AFS_SUN5_ENV) -#ifdef AFS_SGI_ENV - OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */ -#else - u.u_cred = tmpcred; /* restore original credentials */ -#endif /* AFS_SGI64_ENV */ -#endif -#endif /* AFS_HPUX101_ENV */ - crfree(foreigncreds); -#endif - } -#endif /* AFS_LINUX22_ENV */ - PIOCTL_FREE_CRED(); -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SGI64_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return (code); -#else - return(setuerror(code), code); + vp = NULL; +#if defined(KERNEL_HAVE_UERROR) + setuerror(code); #endif + goto rescred; } - } - else vp = (struct vnode *) 0; - + } else + vp = NULL; + /* now make the call if we were passed no file, or were passed an AFS file */ if (!vp || IsAfsVnode(vp)) { -#ifdef AFS_DEC_ENV - /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode. - * So, we must test in this part of the code. Also, must arrange to - * GRELE the original gnode pointer when we're done, since in Ultrix 4.0, - * we hold gnodes, whose references hold our vcache entries. - */ - if (vp) { - gp = vp; /* remember for "put" */ - vp = (struct vnode *) afs_gntovn(vp); /* get vcache from gp */ - } - else gp = (struct vnode *) 0; -#endif -#ifdef AFS_SUN5_ENV - code = afs_HandlePioctl(vp, com, &data, follow, &credp); -#else -#ifdef AFS_AIX41_ENV - { - struct ucred *cred1, *cred2; - - if (foreigncreds) { - cred1 = cred2 = foreigncreds; - } else { - cred1 = cred2 = credp; - } - code = afs_HandlePioctl(vp, com, &data, follow, &cred1); - if (cred1 != cred2) { - /* something changed the creds */ - crset(cred1); - } - } -#else -#if defined(AFS_HPUX101_ENV) - { - struct ucred *cred = p_cred(u.u_procp); - code = afs_HandlePioctl(vp, com, &data, follow, &cred); - } -#else -#ifdef AFS_SGI_ENV - { - struct cred *credp; - credp = OSI_GET_CURRENT_CRED(); - code = afs_HandlePioctl(vp, com, &data, follow, &credp); - } -#else -#if defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - code = afs_HandlePioctl(vp, com, &data, follow, &credp); +#if defined(AFS_DEC_ENV) + /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode. + * So, we must test in this part of the code. Also, must arrange to + * GRELE the original gnode pointer when we're done, since in Ultrix 4.0, + * we hold gnodes, whose references hold our vcache entries. + */ + if (vp) { + gp = vp; /* remember for "put" */ + vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */ + } else + gp = NULL; +#elif defined(AFS_SUN5_ENV) + code = afs_HandlePioctl(vp, com, &data, follow, &credp); +#elif defined(AFS_AIX41_ENV) + { + struct ucred *cred1, *cred2; + + if (foreigncreds) { + cred1 = cred2 = foreigncreds; + } else { + cred1 = cred2 = credp; + } + code = afs_HandlePioctl(vp, com, &data, follow, &cred1); + if (cred1 != cred2) { + /* something changed the creds */ + crset(cred1); + } + } +#elif defined(AFS_HPUX101_ENV) + { + struct ucred *cred = p_cred(u.u_procp); + code = afs_HandlePioctl(vp, com, &data, follow, &cred); + } +#elif defined(AFS_SGI_ENV) + { + struct cred *credp; + credp = OSI_GET_CURRENT_CRED(); + code = afs_HandlePioctl(vp, com, &data, follow, &credp); + } +#elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) + code = afs_HandlePioctl(vp, com, &data, follow, &credp); #else - code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred); + code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred); #endif -#endif /* AFS_SGI_ENV */ -#endif /* AFS_HPUX101_ENV */ -#endif /* AFS_AIX41_ENV */ -#endif /* AFS_SUN5_ENV */ } else { -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SGI64_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - code = EINVAL; /* not in /afs */ -#else +#if defined(KERNEL_HAVE_UERROR) setuerror(EINVAL); +#else + code = EINVAL; /* not in /afs */ #endif #ifdef AFS_DEC_ENV if (vp) { GRELE(vp); - vp = (struct vnode *) 0; + vp = NULL; } #endif } -#if !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) + rescred: +#if defined(AFS_NEED_CLIENTCONTEXT) if (foreigncreds) { #ifdef AFS_AIX41_ENV - crset(tmpcred); + crset(tmpcred); /* restore original credentials */ #else #if defined(AFS_HPUX101_ENV) - set_p_cred(u.u_procp, tmpcred); /* restore original credentials */ -#else -#ifndef AFS_SUN5_ENV -#ifdef AFS_SGI_ENV - OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */ -#else - u.u_cred = tmpcred; /* restore original credentials */ -#endif /* ASF_SGI64_ENV */ -#endif + set_p_cred(u.u_procp, tmpcred); /* restore original credentials */ +#elif defined(AFS_SGI_ENV) + OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */ +#elif !defined(AFS_SUN5_ENV) + osi_curcred() = tmpcred; /* restore original credentials */ #endif /* AFS_HPUX101_ENV */ crfree(foreigncreds); -#endif +#endif /* AIX41 */ } -#endif /* AFS_LINUX22_ENV */ +#endif /* AFS_NEED_CLIENTCONTEXT */ if (vp) { #ifdef AFS_LINUX22_ENV dput(dp); #else - AFS_RELE(vp); /* put vnode back */ + AFS_RELE(vp); /* put vnode back */ #endif } PIOCTL_FREE_CRED(); -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SGI64_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return (code); -#else - if (!getuerror()) - setuerror(code); +#if defined(KERNEL_HAVE_UERROR) + if (!getuerror()) + setuerror(code); return (getuerror()); +#else + return (code); #endif } - - -afs_HandlePioctl(avc, acom, ablob, afollow, acred) - struct vcache *avc; - afs_int32 acom; - struct AFS_UCRED **acred; - register struct afs_ioctl *ablob; - int afollow; + +#define MAXPIOCTLTOKENLEN \ +(3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN) + +int +afs_HandlePioctl(struct vnode *avp, afs_int32 acom, + register struct afs_ioctl *ablob, int afollow, + struct AFS_UCRED **acred) { + struct vcache *avc; struct vrequest treq; register afs_int32 code; register afs_int32 function, device; - afs_int32 inSize, outSize; + afs_int32 inSize, outSize, outSizeMax; char *inData, *outData; - int (*(*pioctlSw))(); + int (*(*pioctlSw)) (); int pioctlSwSize; struct afs_fakestat_state fakestate; + avc = avp ? VTOAFS(avp) : NULL; afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff, ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow); AFS_STATCNT(HandlePioctl); - if (code = afs_InitReq(&treq, *acred)) return code; + if ((code = afs_InitReq(&treq, *acred))) + return code; afs_InitFakeStat(&fakestate); if (avc) { code = afs_EvalFakeStat(&avc, &fakestate, &treq); @@ -1068,115 +1083,131 @@ afs_HandlePioctl(avc, acom, ablob, afollow, acred) } device = (acom & 0xff00) >> 8; switch (device) { - case 'V': /* Original pioctl's */ - pioctlSw = VpioctlSw; - pioctlSwSize = sizeof(VpioctlSw); - break; - case 'C': /* Coordinated/common pioctl's */ - pioctlSw = CpioctlSw; - pioctlSwSize = sizeof(CpioctlSw); - break; - default: - afs_PutFakeStat(&fakestate); - return EINVAL; + case 'V': /* Original pioctls */ + pioctlSw = VpioctlSw; + pioctlSwSize = sizeof(VpioctlSw); + break; + case 'C': /* Coordinated/common pioctls */ + pioctlSw = CpioctlSw; + pioctlSwSize = sizeof(CpioctlSw); + break; + default: + afs_PutFakeStat(&fakestate); + return EINVAL; } function = acom & 0xff; if (function >= (pioctlSwSize / sizeof(char *))) { afs_PutFakeStat(&fakestate); - return EINVAL; /* out of range */ + return EINVAL; /* out of range */ } inSize = ablob->in_size; /* Do all range checking before continuing */ - if (inSize >= PIGGYSIZE || inSize < 0 || ablob->out_size < 0) + if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0) return E2BIG; - inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ); - if (inSize > 0) { - AFS_COPYIN(ablob->in, inData, inSize, code); - inData[inSize]='\0'; + if (inSize > AFS_LRALLOCSIZ) { + inData = osi_AllocLargeSpace(inSize+1); + } else { + inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ); } - else code = 0; + if (!inData) + return ENOMEM; + if (inSize > 0) { + AFS_COPYIN(ablob->in, inData, inSize, code); + inData[inSize] = '\0'; + } else + code = 0; if (code) { - osi_FreeLargeSpace(inData); - afs_PutFakeStat(&fakestate); - return code; + if (inSize > AFS_LRALLOCSIZ) { + osi_Free(inData, inSize+1); + } else { + osi_FreeLargeSpace(inData); + } + afs_PutFakeStat(&fakestate); + return code; + } + if (function == 8 && device == 'V') { /* PGetTokens */ + outSizeMax = MAXPIOCTLTOKENLEN; + outData = osi_Alloc(outSizeMax); + } else { + outSizeMax = AFS_LRALLOCSIZ; + outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ); + } + if (!outData) { + if (inSize > AFS_LRALLOCSIZ) { + osi_Free(inData, inSize+1); + } else { + osi_FreeLargeSpace(inData); + } + return ENOMEM; } - outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ); outSize = 0; - if (function == 3 && device == 'V') /* PSetTokens */ - code = (*pioctlSw[function])(avc, function, &treq, inData, outData, inSize, &outSize, acred); - else - code = (*pioctlSw[function])(avc, function, &treq, inData, outData, inSize, &outSize, *acred); - osi_FreeLargeSpace(inData); + code = + (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize, + &outSize, acred); + if (inSize > AFS_LRALLOCSIZ) { + osi_Free(inData, inSize+1); + } else { + osi_FreeLargeSpace(inData); + } if (code == 0 && ablob->out_size > 0) { - if (outSize > ablob->out_size) outSize = ablob->out_size; - if (outSize >= PIGGYSIZE) code = E2BIG; - else if (outSize) { - outData[outSize]='\0'; - AFS_COPYOUT(outData, ablob->out, outSize, code); - } - } - osi_FreeLargeSpace(outData); + if (outSize > ablob->out_size) { + code = E2BIG; /* data wont fit in user buffer */ + } else if (outSize) { + AFS_COPYOUT(outData, ablob->out, outSize, code); + } + } + if (outSizeMax > AFS_LRALLOCSIZ) { + osi_Free(outData, outSizeMax); + } else { + osi_FreeLargeSpace(outData); + } afs_PutFakeStat(&fakestate); return afs_CheckCode(code, &treq, 41); - } - -static PGetFID(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { - register afs_int32 code; - +} + +DECL_PIOCTL(PGetFID) +{ AFS_STATCNT(PGetFID); - if (!avc) return EINVAL; + if (!avc) + return EINVAL; memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid)); *aoutSize = sizeof(struct VenusFid); return 0; - } - -static PSetAcl(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +} + +DECL_PIOCTL(PSetAcl) +{ register afs_int32 code; struct conn *tconn; struct AFSOpaque acl; struct AFSVolSync tsync; struct AFSFetchStatus OutStatus; XSTATS_DECLS; - + AFS_STATCNT(PSetAcl); if (!avc) - return EINVAL; - if ((acl.AFSOpaque_len = strlen(ain)+1) > 1000) - return EINVAL; + return EINVAL; + if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000) + return EINVAL; acl.AFSOpaque_val = ain; do { - tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK); - if (tconn) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_StoreACL(tconn->id, (struct AFSFid *) &avc->fid.Fid, - &acl, &OutStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tconn, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_STOREACL, SHARED_LOCK, (struct cell *)0)); + tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK); + if (tconn) { + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL); + RX_AFS_GUNLOCK(); + code = + RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid, + &acl, &OutStatus, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL, + SHARED_LOCK, NULL)); /* now we've forgotten all of the access info */ ObtainWriteLock(&afs_xcbhash, 455); @@ -1187,69 +1218,52 @@ static PSetAcl(avc, afun, areq, ain, aout, ainSize, aoutSize) if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR)) osi_dnlc_purgedp(avc); return code; - } +} int afs_defaultAsynchrony = 0; -static PStoreBehind(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ - struct AFS_UCRED *acred; -{ - afs_int32 code = 0; - struct sbstruct *sbr; - - sbr = (struct sbstruct *)ain; - if (sbr->sb_default != -1) { - if (afs_osi_suser(acred)) - afs_defaultAsynchrony = sbr->sb_default; - else code = EPERM; - } - - if (avc && (sbr->sb_thisfile != -1)) { - if (afs_AccessOK(avc, PRSFS_WRITE | PRSFS_ADMINISTER, - areq, DONT_CHECK_MODE_BITS)) - avc->asynchrony = sbr->sb_thisfile; - else code = EACCES; - } - - *aoutSize = sizeof(struct sbstruct); - sbr = (struct sbstruct *)aout; - sbr->sb_default = afs_defaultAsynchrony; - if (avc) { - sbr->sb_thisfile = avc->asynchrony; - } - - return code; -} - -static PGCPAGs(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ - struct AFS_UCRED *acred; -{ - if (!afs_osi_suser(acred)) { - return EACCES; - } - afs_gcpags = AFS_GCPAGS_USERDISABLED; - return 0; -} - - static PGetAcl(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PStoreBehind) +{ + afs_int32 code = 0; + struct sbstruct *sbr; + + sbr = (struct sbstruct *)ain; + if (sbr->sb_default != -1) { + if (afs_osi_suser(*acred)) + afs_defaultAsynchrony = sbr->sb_default; + else + code = EPERM; + } + + if (avc && (sbr->sb_thisfile != -1)) { + if (afs_AccessOK + (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS)) + avc->asynchrony = sbr->sb_thisfile; + else + code = EACCES; + } + + *aoutSize = sizeof(struct sbstruct); + sbr = (struct sbstruct *)aout; + sbr->sb_default = afs_defaultAsynchrony; + if (avc) { + sbr->sb_thisfile = avc->asynchrony; + } + + return code; +} + +DECL_PIOCTL(PGCPAGs) +{ + if (!afs_osi_suser(*acred)) { + return EACCES; + } + afs_gcpags = AFS_GCPAGS_USERDISABLED; + return 0; +} + +DECL_PIOCTL(PGetAcl) +{ struct AFSOpaque acl; struct AFSVolSync tsync; struct AFSFetchStatus OutStatus; @@ -1259,7 +1273,8 @@ static PGCPAGs(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) XSTATS_DECLS; AFS_STATCNT(PGetAcl); - if (!avc) return EINVAL; + if (!avc) + return EINVAL; Fid.Volume = avc->fid.Fid.Volume; Fid.Vnode = avc->fid.Fid.Vnode; Fid.Unique = avc->fid.Fid.Unique; @@ -1270,146 +1285,117 @@ static PGCPAGs(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) * we currently use the top 2-bytes (vals 0-4) to tell which * type of acl to bring back. Horrible hack but this will * cause the least number of changes to code size and interfaces. - */ + */ if (Fid.Vnode & 0xc0000000) return ERANGE; Fid.Vnode |= (ainSize << 30); } acl.AFSOpaque_val = aout; do { - tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK); - if (tconn) { - *aout = 0; - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_FetchACL(tconn->id, &Fid, - &acl, &OutStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tconn, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_FETCHACL, - SHARED_LOCK, (struct cell *)0)); + tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK); + if (tconn) { + *aout = 0; + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL); + RX_AFS_GUNLOCK(); + code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL, + SHARED_LOCK, NULL)); if (code == 0) { - *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len); + *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len); } return code; - } - - static PNoop() { +} + +DECL_PIOCTL(PNoop) +{ AFS_STATCNT(PNoop); return 0; - } - - static PBogus() { +} + +DECL_PIOCTL(PBogus) +{ AFS_STATCNT(PBogus); return EINVAL; - } - - static PGetFileCell(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +} + +DECL_PIOCTL(PGetFileCell) +{ register struct cell *tcell; - + AFS_STATCNT(PGetFileCell); - if (!avc) return EINVAL; + if (!avc) + return EINVAL; tcell = afs_GetCell(avc->fid.Cell, READ_LOCK); - if (!tcell) return ESRCH; + if (!tcell) + return ESRCH; strcpy(aout, tcell->cellName); afs_PutCell(tcell, READ_LOCK); *aoutSize = strlen(aout) + 1; return 0; - } - -static PGetWSCell(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ +} + +DECL_PIOCTL(PGetWSCell) { struct cell *tcell = NULL; - + AFS_STATCNT(PGetWSCell); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ tcell = afs_GetPrimaryCell(READ_LOCK); - if (!tcell) /* no primary cell? */ + if (!tcell) /* no primary cell? */ return ESRCH; strcpy(aout, tcell->cellName); *aoutSize = strlen(aout) + 1; afs_PutCell(tcell, READ_LOCK); return 0; } - - static PGetUserCell(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { + +DECL_PIOCTL(PGetUserCell) +{ register afs_int32 i; register struct unixuser *tu; register struct cell *tcell; - + AFS_STATCNT(PGetUserCell); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ /* return the cell name of the primary cell for this user */ i = UHash(areq->uid); - ObtainWriteLock(&afs_xuser,224); - for(tu = afs_users[i]; tu; tu = tu->next) { - if (tu->uid == areq->uid && (tu->states & UPrimary)) { - tu->refCount++; - ReleaseWriteLock(&afs_xuser); - break; - } + ObtainWriteLock(&afs_xuser, 224); + for (tu = afs_users[i]; tu; tu = tu->next) { + if (tu->uid == areq->uid && (tu->states & UPrimary)) { + tu->refCount++; + ReleaseWriteLock(&afs_xuser); + break; + } } if (tu) { - tcell = afs_GetCell(tu->cell, READ_LOCK); - afs_PutUser(tu, WRITE_LOCK); - if (!tcell) return ESRCH; - else { - strcpy(aout, tcell->cellName); - afs_PutCell(tcell, READ_LOCK); - *aoutSize = strlen(aout)+1; /* 1 for the null */ - } - } - else { - ReleaseWriteLock(&afs_xuser); - *aout = 0; - *aoutSize = 1; + tcell = afs_GetCell(tu->cell, READ_LOCK); + afs_PutUser(tu, WRITE_LOCK); + if (!tcell) + return ESRCH; + else { + strcpy(aout, tcell->cellName); + afs_PutCell(tcell, READ_LOCK); + *aoutSize = strlen(aout) + 1; /* 1 for the null */ + } + } else { + ReleaseWriteLock(&afs_xuser); + *aout = 0; + *aoutSize = 1; } return 0; - } - - static PSetTokens(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ - struct AFS_UCRED **acred; +} + +DECL_PIOCTL(PSetTokens) { afs_int32 i; register struct unixuser *tu; @@ -1419,59 +1405,61 @@ static PGetWSCell(avc, afun, areq, ain, aout, ainSize, aoutSize) int stLen; struct vrequest treq; afs_int32 flag, set_parent_pag = 0; - + AFS_STATCNT(PSetTokens); if (!afs_resourceinit_flag) { - return EIO; + return EIO; } memcpy((char *)&i, ain, sizeof(afs_int32)); ain += sizeof(afs_int32); - stp = ain; /* remember where the ticket is */ - if (i < 0 || i > 2000) return EINVAL; /* malloc may fail */ - if (i > MAXKTCTICKETLEN) return EINVAL; + stp = ain; /* remember where the ticket is */ + if (i < 0 || i > MAXKTCTICKETLEN) + return EINVAL; /* malloc may fail */ stLen = i; - ain += i; /* skip over ticket */ + ain += i; /* skip over ticket */ memcpy((char *)&i, ain, sizeof(afs_int32)); ain += sizeof(afs_int32); if (i != sizeof(struct ClearToken)) { - return EINVAL; + return EINVAL; } memcpy((char *)&clear, ain, sizeof(struct ClearToken)); - if (clear.AuthHandle == -1) clear.AuthHandle = 999; /* more rxvab compat stuff */ + if (clear.AuthHandle == -1) + clear.AuthHandle = 999; /* more rxvab compat stuff */ ain += sizeof(struct ClearToken); - if (ainSize != 2*sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) { - /* still stuff left? we've got primary flag and cell name. Set these */ - memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */ - ain += sizeof(afs_int32); /* skip id field */ - /* rest is cell name, look it up */ - /* some versions of gcc appear to need != 0 in order to get this right */ - if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */ - flag &= ~0x8000; - set_parent_pag = 1; - } - tcell = afs_GetCellByName(ain, READ_LOCK); - if (!tcell) goto nocell; - } - else { - /* default to primary cell, primary id */ - flag = 1; /* primary id */ - tcell = afs_GetPrimaryCell(READ_LOCK); - if (!tcell) goto nocell; + if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) { + /* still stuff left? we've got primary flag and cell name. Set these */ + memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */ + ain += sizeof(afs_int32); /* skip id field */ + /* rest is cell name, look it up */ + /* some versions of gcc appear to need != 0 in order to get this right */ + if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */ + flag &= ~0x8000; + set_parent_pag = 1; + } + tcell = afs_GetCellByName(ain, READ_LOCK); + if (!tcell) + goto nocell; + } else { + /* default to primary cell, primary id */ + flag = 1; /* primary id */ + tcell = afs_GetPrimaryCell(READ_LOCK); + if (!tcell) + goto nocell; } i = tcell->cellNum; afs_PutCell(tcell, READ_LOCK); if (set_parent_pag) { - int pag; -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) + afs_int32 pag; +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) #if defined(AFS_DARWIN_ENV) - struct proc *p=current_proc(); /* XXX */ + struct proc *p = current_proc(); /* XXX */ #else - struct proc *p=curproc; /* XXX */ + struct proc *p = curproc; /* XXX */ #endif - uprintf("Process %d (%s) tried to change pags in PSetTokens\n", - p->p_pid, p->p_comm); - if (!setpag(p, acred, -1, &pag, 1)) { -#else + uprintf("Process %d (%s) tried to change pags in PSetTokens\n", + p->p_pid, p->p_comm); + if (!setpag(p, acred, -1, &pag, 1)) { +#else #ifdef AFS_OSF_ENV if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */ #else @@ -1483,12 +1471,12 @@ static PGetWSCell(avc, afun, areq, ain, aout, ainSize, aoutSize) } } /* now we just set the tokens */ - tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */ + tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */ tu->vid = clear.ViceId; - if (tu->stp != (char *) 0) { - afs_osi_Free(tu->stp, tu->stLen); + if (tu->stp != NULL) { + afs_osi_Free(tu->stp, tu->stLen); } - tu->stp = (char *) afs_osi_Alloc(stLen); + tu->stp = (char *)afs_osi_Alloc(stLen); tu->stLen = stLen; memcpy(tu->stp, stp, stLen); tu->ct = clear; @@ -1499,7 +1487,7 @@ static PGetWSCell(avc, afun, areq, ain, aout, ainSize, aoutSize) tu->states |= UHasTokens; tu->states &= ~UTokensBad; afs_SetPrimary(tu, flag); - tu->tokenTime =osi_Time(); + tu->tokenTime = osi_Time(); afs_ResetUserConns(tu); afs_PutUser(tu, WRITE_LOCK); @@ -1507,84 +1495,77 @@ static PGetWSCell(avc, afun, areq, ain, aout, ainSize, aoutSize) nocell: { - int t1; - t1 = afs_initState; - if (t1 < 101) - return EIO; - else - return ESRCH; - } -} + int t1; + t1 = afs_initState; + if (t1 < 101) + return EIO; + else + return ESRCH; + } +} -static PGetVolumeStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PGetVolumeStatus) +{ char volName[32]; - char offLineMsg[256]; - char motd[256]; + char *offLineMsg = afs_osi_Alloc(256); + char *motd = afs_osi_Alloc(256); register struct conn *tc; - register afs_int32 code; + register afs_int32 code = 0; struct VolumeStatus volstat; register char *cp; char *Name, *OfflineMsg, *MOTD; XSTATS_DECLS; AFS_STATCNT(PGetVolumeStatus); - if (!avc) return EINVAL; + if (!avc) { + code = EINVAL; + goto out; + } Name = volName; OfflineMsg = offLineMsg; MOTD = motd; do { - tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); - if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat, - &Name, &OfflineMsg, &MOTD); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS, - SHARED_LOCK, (struct cell *)0)); - - if (code) return code; + tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); + if (tc) { + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS); + RX_AFS_GUNLOCK(); + code = + RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat, + &Name, &OfflineMsg, &MOTD); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS, + SHARED_LOCK, NULL)); + + if (code) + goto out; /* Copy all this junk into msg->im_data, keeping track of the lengths. */ cp = aout; memcpy(cp, (char *)&volstat, sizeof(VolumeStatus)); cp += sizeof(VolumeStatus); strcpy(cp, volName); - cp += strlen(volName)+1; + cp += strlen(volName) + 1; strcpy(cp, offLineMsg); - cp += strlen(offLineMsg)+1; + cp += strlen(offLineMsg) + 1; strcpy(cp, motd); - cp += strlen(motd)+1; + cp += strlen(motd) + 1; *aoutSize = (cp - aout); - return 0; + out: + afs_osi_Free(offLineMsg, 256); + afs_osi_Free(motd, 256); + return code; } -static PSetVolumeStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PSetVolumeStatus) +{ char volName[32]; - char offLineMsg[256]; - char motd[256]; + char *offLineMsg = afs_osi_Alloc(256); + char *motd = afs_osi_Alloc(256); register struct conn *tc; - register afs_int32 code; + register afs_int32 code = 0; struct AFSFetchVolumeStatus volstat; struct AFSStoreVolumeStatus storeStat; register struct volume *tvp; @@ -1592,31 +1573,43 @@ static PSetVolumeStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) XSTATS_DECLS; AFS_STATCNT(PSetVolumeStatus); - if (!avc) return EINVAL; + if (!avc) { + code = EINVAL; + goto out; + } - tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK); + tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK); if (tvp) { if (tvp->states & (VRO | VBackup)) { afs_PutVolume(tvp, READ_LOCK); - return EROFS; + code = EROFS; + goto out; } afs_PutVolume(tvp, READ_LOCK); - } else - return ENODEV; + } else { + code = ENODEV; + goto out; + } /* Copy the junk out, using cp as a roving pointer. */ cp = ain; memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus)); cp += sizeof(AFSFetchVolumeStatus); - if (strlen(cp) >= sizeof(volName)) - return E2BIG; + if (strlen(cp) >= sizeof(volName)) { + code = E2BIG; + goto out; + } strcpy(volName, cp); - cp += strlen(volName)+1; - if (strlen(cp) >= sizeof(offLineMsg)) - return E2BIG; + cp += strlen(volName) + 1; + if (strlen(cp) >= sizeof(offLineMsg)) { + code = E2BIG; + goto out; + } strcpy(offLineMsg, cp); - cp += strlen(offLineMsg)+1; - if (strlen(cp) >= sizeof(motd)) - return E2BIG; + cp += strlen(offLineMsg) + 1; + if (strlen(cp) >= sizeof(motd)) { + code = E2BIG; + goto out; + } strcpy(motd, cp); storeStat.Mask = 0; if (volstat.MinQuota != -1) { @@ -1630,66 +1623,59 @@ static PSetVolumeStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) do { tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, - &storeStat, volName, offLineMsg, motd); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS, - SHARED_LOCK, (struct cell *)0)); - - if (code) return code; + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS); + RX_AFS_GUNLOCK(); + code = + RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat, + volName, offLineMsg, motd); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS, + SHARED_LOCK, NULL)); + + if (code) + goto out; /* we are sending parms back to make compat. with prev system. should - change interface later to not ask for current status, just set new status */ + * change interface later to not ask for current status, just set new status */ cp = aout; memcpy(cp, (char *)&volstat, sizeof(VolumeStatus)); cp += sizeof(VolumeStatus); strcpy(cp, volName); - cp += strlen(volName)+1; + cp += strlen(volName) + 1; strcpy(cp, offLineMsg); - cp += strlen(offLineMsg)+1; + cp += strlen(offLineMsg) + 1; strcpy(cp, motd); - cp += strlen(motd)+1; + cp += strlen(motd) + 1; *aoutSize = cp - aout; - return 0; + out: + afs_osi_Free(offLineMsg, 256); + afs_osi_Free(motd, 256); + return code; } -static PFlush(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - register struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ - struct AFS_UCRED *acred; +DECL_PIOCTL(PFlush) { - AFS_STATCNT(PFlush); - if (!avc) return EINVAL; + if (!avc) + return EINVAL; #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */ #endif - ObtainWriteLock(&avc->lock,225); + ObtainWriteLock(&avc->lock, 225); ObtainWriteLock(&afs_xcbhash, 456); afs_DequeueCallback(avc); - avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */ + avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */ ReleaseWriteLock(&afs_xcbhash); /* now find the disk cache entries */ - afs_TryToSmush(avc, acred, 1); + afs_TryToSmush(avc, *acred, 1); osi_dnlc_purgedp(avc); afs_symhint_inval(avc); if (avc->linkData && !(avc->states & CCore)) { - afs_osi_Free(avc->linkData, strlen(avc->linkData)+1); - avc->linkData = (char *) 0; + afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1); + avc->linkData = NULL; } ReleaseWriteLock(&avc->lock); #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) @@ -1698,85 +1684,79 @@ static PFlush(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) return 0; } -static PNewStatMount(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PNewStatMount) +{ register afs_int32 code; register struct vcache *tvc; register struct dcache *tdc; struct VenusFid tfid; char *bufp; struct sysname_info sysState; - afs_int32 offset, len; + afs_size_t offset, len; AFS_STATCNT(PNewStatMount); - if (!avc) return EINVAL; + if (!avc) + return EINVAL; code = afs_VerifyVCache(avc, areq); - if (code) return code; + if (code) + return code; if (vType(avc) != VDIR) { return ENOTDIR; } - tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 1); - if (!tdc) return ENOENT; + tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); + if (!tdc) + return ENOENT; Check_AtSys(avc, ain, &sysState, areq); + ObtainReadLock(&tdc->lock); do { - code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid); + code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid); } while (code == ENOENT && Next_AtSys(avc, areq, &sysState)); + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); /* we're done with the data */ bufp = sysState.name; if (code) { - afs_PutDCache(tdc); goto out; } tfid.Cell = avc->fid.Cell; tfid.Fid.Volume = avc->fid.Fid.Volume; - afs_PutDCache(tdc); /* we're done with the data */ if (!tfid.Fid.Unique && (avc->states & CForeign)) { - tvc = afs_LookupVCache(&tfid, areq, (afs_int32 *)0, WRITE_LOCK, avc, bufp); + tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp); } else { - tvc = afs_GetVCache(&tfid, areq, (afs_int32 *)0, (struct vcache*)0, - WRITE_LOCK); + tvc = afs_GetVCache(&tfid, areq, NULL, NULL); } if (!tvc) { code = ENOENT; goto out; } if (tvc->mvstat != 1) { - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); code = EINVAL; goto out; } - ObtainWriteLock(&tvc->lock,226); + ObtainWriteLock(&tvc->lock, 226); code = afs_HandleLink(tvc, areq); if (code == 0) { if (tvc->linkData) { if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%')) - code = EINVAL; + code = EINVAL; else { /* we have the data */ strcpy(aout, tvc->linkData); - *aoutSize = strlen(tvc->linkData)+1; + *aoutSize = strlen(tvc->linkData) + 1; } - } else + } else code = EIO; } ReleaseWriteLock(&tvc->lock); - afs_PutVCache(tvc, WRITE_LOCK); -out: - if (sysState.allocked) osi_FreeLargeSpace(bufp); + afs_PutVCache(tvc); + out: + if (sysState.allocked) + osi_FreeLargeSpace(bufp); return code; } -static PGetTokens(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PGetTokens) +{ register struct cell *tcell; register afs_int32 i; register struct unixuser *tu; @@ -1785,36 +1765,37 @@ static PGetTokens(avc, afun, areq, ain, aout, ainSize, aoutSize) int newStyle; AFS_STATCNT(PGetTokens); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ /* weird interface. If input parameter is present, it is an integer and - we're supposed to return the parm'th tokens for this unix uid. - If not present, we just return tokens for cell 1. - If counter out of bounds, return EDOM. - If no tokens for the particular cell, return ENOTCONN. - Also, if this mysterious parm is present, we return, along with the - tokens, the primary cell indicator (an afs_int32 0) and the cell name - at the end, in that order. - */ - if (newStyle = (ainSize > 0)) { + * we're supposed to return the parm'th tokens for this unix uid. + * If not present, we just return tokens for cell 1. + * If counter out of bounds, return EDOM. + * If no tokens for the particular cell, return ENOTCONN. + * Also, if this mysterious parm is present, we return, along with the + * tokens, the primary cell indicator (an afs_int32 0) and the cell name + * at the end, in that order. + */ + if ((newStyle = (ainSize > 0))) { memcpy((char *)&iterator, ain, sizeof(afs_int32)); } i = UHash(areq->uid); ObtainReadLock(&afs_xuser); - for(tu = afs_users[i]; tu; tu=tu->next) { + for (tu = afs_users[i]; tu; tu = tu->next) { if (newStyle) { if (tu->uid == areq->uid && (tu->states & UHasTokens)) { - if (iterator-- == 0) break; /* are we done yet? */ + if (iterator-- == 0) + break; /* are we done yet? */ } - } - else { - if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell)) break; + } else { + if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell)) + break; } } if (tu) { /* - * No need to hold a read lock on each user entry + * No need to hold a read lock on each user entry */ tu->refCount++; } @@ -1823,7 +1804,8 @@ static PGetTokens(avc, afun, areq, ain, aout, ainSize, aoutSize) if (!tu) { return EDOM; } - if (((tu->states & UHasTokens) == 0) || (tu->ct.EndTimestamp < osi_Time())) { + if (((tu->states & UHasTokens) == 0) + || (tu->ct.EndTimestamp < osi_Time())) { tu->states |= (UTokensBad | UNeedsReset); afs_PutUser(tu, READ_LOCK); return ENOTCONN; @@ -1831,7 +1813,8 @@ static PGetTokens(avc, afun, areq, ain, aout, ainSize, aoutSize) /* use iterator for temp */ cp = aout; iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */ - if (iterator < 56) iterator = 56; /* # of bytes we're returning */ + if (iterator < 56) + iterator = 56; /* # of bytes we're returning */ memcpy(cp, (char *)&iterator, sizeof(afs_int32)); cp += sizeof(afs_int32); memcpy(cp, tu->stp, tu->stLen); /* copy out st */ @@ -1849,33 +1832,28 @@ static PGetTokens(avc, afun, areq, ain, aout, ainSize, aoutSize) tcell = afs_GetCell(tu->cell, READ_LOCK); if (tcell) { strcpy(cp, tcell->cellName); - cp += strlen(tcell->cellName)+1; + cp += strlen(tcell->cellName) + 1; afs_PutCell(tcell, READ_LOCK); - } - else *cp++ = 0; + } else + *cp++ = 0; } *aoutSize = cp - aout; afs_PutUser(tu, READ_LOCK); return 0; } -static PUnlog(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PUnlog) +{ register afs_int32 i; register struct unixuser *tu; AFS_STATCNT(PUnlog); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ i = UHash(areq->uid); - ObtainWriteLock(&afs_xuser,227); - for(tu=afs_users[i]; tu; tu=tu->next) { + ObtainWriteLock(&afs_xuser, 227); + for (tu = afs_users[i]; tu; tu = tu->next) { if (tu->uid == areq->uid) { tu->vid = UNDEFVID; tu->states &= ~UHasTokens; @@ -1893,42 +1871,37 @@ static PUnlog(avc, afun, areq, ain, aout, ainSize, aoutSize) */ afs_ResetUserConns(tu); tu->refCount--; - ObtainWriteLock(&afs_xuser,228); + ObtainWriteLock(&afs_xuser, 228); #ifdef UKERNEL - /* set the expire times to 0, causes - * afs_GCUserData to remove this entry - */ - tu->ct.EndTimestamp = 0; - tu->tokenTime = 0; -#endif /* UKERNEL */ + /* set the expire times to 0, causes + * afs_GCUserData to remove this entry + */ + tu->ct.EndTimestamp = 0; + tu->tokenTime = 0; +#endif /* UKERNEL */ } } ReleaseWriteLock(&afs_xuser); return 0; } -static PMariner(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PMariner) +{ afs_int32 newHostAddr; afs_int32 oldHostAddr; - + AFS_STATCNT(PMariner); if (afs_mariner) - memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost, sizeof(afs_int32)); + memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost, + sizeof(afs_int32)); else - oldHostAddr = 0xffffffff; /* disabled */ - + oldHostAddr = 0xffffffff; /* disabled */ + memcpy((char *)&newHostAddr, ain, sizeof(afs_int32)); if (newHostAddr == 0xffffffff) { /* disable mariner operations */ afs_mariner = 0; - } - else if (newHostAddr) { + } else if (newHostAddr) { afs_mariner = 1; afs_marinerHost = newHostAddr; } @@ -1937,141 +1910,127 @@ static PMariner(avc, afun, areq, ain, aout, ainSize, aoutSize) return 0; } -static PCheckServers(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ - struct AFS_UCRED *acred; +DECL_PIOCTL(PCheckServers) { register char *cp = 0; register int i; register struct server *ts; - afs_int32 temp, *lp = (afs_int32 *)ain, havecell=0; + afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0; struct cell *cellp; struct chservinfo *pcheck; AFS_STATCNT(PCheckServers); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ if (*lp == 0x12345678) { /* For afs3.3 version */ - pcheck=(struct chservinfo *)ain; + pcheck = (struct chservinfo *)ain; if (pcheck->tinterval >= 0) { - cp = aout; + cp = aout; memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32)); *aoutSize = sizeof(afs_int32); if (pcheck->tinterval > 0) { - if (!afs_osi_suser(acred)) + if (!afs_osi_suser(*acred)) return EACCES; - PROBE_INTERVAL=pcheck->tinterval; + PROBE_INTERVAL = pcheck->tinterval; } return 0; } if (pcheck->tsize) havecell = 1; - temp=pcheck->tflags; + temp = pcheck->tflags; cp = pcheck->tbuffer; - } else { /* For pre afs3.3 versions */ + } else { /* For pre afs3.3 versions */ memcpy((char *)&temp, ain, sizeof(afs_int32)); - cp = ain+sizeof(afs_int32); - if (ainSize > sizeof(afs_int32)) + cp = ain + sizeof(afs_int32); + if (ainSize > sizeof(afs_int32)) havecell = 1; } - /* + /* * 1: fast check, don't contact servers. * 2: local cell only. */ if (havecell) { /* have cell name, too */ cellp = afs_GetCellByName(cp, READ_LOCK); - if (!cellp) return ENOENT; - } - else cellp = (struct cell *) 0; + if (!cellp) + return ENOENT; + } else + cellp = NULL; if (!cellp && (temp & 2)) { /* use local cell */ cellp = afs_GetPrimaryCell(READ_LOCK); } - if (!(temp & 1)) { /* if not fast, call server checker routine */ + if (!(temp & 1)) { /* if not fast, call server checker routine */ afs_CheckServers(1, cellp); /* check down servers */ afs_CheckServers(0, cellp); /* check up servers */ } /* now return the current down server list */ cp = aout; ObtainReadLock(&afs_xserver); - for(i=0;inext) { - if (cellp && ts->cell != cellp) continue; /* cell spec'd and wrong */ - if ((ts->flags & SRVR_ISDOWN) && ts->addr->sa_portal != ts->cell->vlport) { + for (i = 0; i < NSERVERS; i++) { + for (ts = afs_servers[i]; ts; ts = ts->next) { + if (cellp && ts->cell != cellp) + continue; /* cell spec'd and wrong */ + if ((ts->flags & SRVR_ISDOWN) + && ts->addr->sa_portal != ts->cell->vlport) { memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32)); cp += sizeof(afs_int32); } } } ReleaseReadLock(&afs_xserver); - if (cellp) afs_PutCell(cellp, READ_LOCK); + if (cellp) + afs_PutCell(cellp, READ_LOCK); *aoutSize = cp - aout; return 0; } -static PCheckVolNames(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PCheckVolNames) +{ AFS_STATCNT(PCheckVolNames); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ afs_CheckRootVolume(); - afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | - AFS_VOLCHECK_EXPIRED | - AFS_VOLCHECK_BUSY | - AFS_VOLCHECK_MTPTS); + afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED | + AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS); return 0; } -static PCheckAuth(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { - int i; - struct srvAddr *sa; - struct conn *tc; - struct unixuser *tu; - afs_int32 retValue; - extern afs_rwlock_t afs_xsrvAddr; +DECL_PIOCTL(PCheckAuth) +{ + int i; + struct srvAddr *sa; + struct conn *tc; + struct unixuser *tu; + afs_int32 retValue; AFS_STATCNT(PCheckAuth); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ retValue = 0; - tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */ - if (!tu) retValue = EACCES; + tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */ + if (!tu) + retValue = EACCES; else { /* we have a user */ - ObtainReadLock(&afs_xsrvAddr); + ObtainReadLock(&afs_xsrvAddr); ObtainReadLock(&afs_xconn); /* any tokens set? */ - if ((tu->states & UHasTokens) == 0) retValue = EACCES; + if ((tu->states & UHasTokens) == 0) + retValue = EACCES; /* all connections in cell 1 working? */ - for(i=0;inext_bkt) { - for (tc = sa->conns; tc; tc=tc->next) { - if (tc->user == tu && (tu->states & UTokensBad)) - retValue = EACCES; - } + for (i = 0; i < NSERVERS; i++) { + for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) { + for (tc = sa->conns; tc; tc = tc->next) { + if (tc->user == tu && (tu->states & UTokensBad)) + retValue = EACCES; + } } } ReleaseReadLock(&afs_xsrvAddr); @@ -2083,60 +2042,57 @@ static PCheckAuth(avc, afun, areq, ain, aout, ainSize, aoutSize) return 0; } -static Prefetch(apath, adata, afollow, acred) -char *apath; -struct afs_ioctl *adata; -int afollow; -struct AFS_UCRED *acred; +static int +Prefetch(char *apath, struct afs_ioctl *adata, int afollow, + struct AFS_UCRED *acred) { register char *tp; register afs_int32 code; -#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) size_t bufferSize; #else u_int bufferSize; #endif AFS_STATCNT(Prefetch); - if (!apath) return EINVAL; + if (!apath) + return EINVAL; tp = osi_AllocLargeSpace(1024); AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code); if (code) { osi_FreeLargeSpace(tp); return code; } - if (afs_BBusy()) { /* do this as late as possible */ + if (afs_BBusy()) { /* do this as late as possible */ osi_FreeLargeSpace(tp); return EWOULDBLOCK; /* pretty close */ } - afs_BQueue(BOP_PATH, (struct vcache*)0, 0, 0, acred, (long)tp, 0L, 0L, 0L); + afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0, + (afs_size_t) 0, tp); return 0; } -static PFindVolume(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PFindVolume) +{ register struct volume *tvp; register struct server *ts; register afs_int32 i; register char *cp; - + AFS_STATCNT(PFindVolume); - if (!avc) return EINVAL; + if (!avc) + return EINVAL; tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK); if (tvp) { cp = aout; - for(i=0;iserverHost[i]; - if (!ts) break; + if (!ts) + break; memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32)); cp += sizeof(afs_int32); } - if (istates & CRO) return 0; /* read-only-ness can't change */ - ObtainWriteLock(&avc->lock,229); + if (!avc) + return EINVAL; + if (avc->states & CRO) + return 0; /* read-only-ness can't change */ + ObtainWriteLock(&avc->lock, 229); theFids.AFSCBFids_len = 1; theCBs.AFSCBs_len = 1; - theFids.AFSCBFids_val = (struct AFSFid *) &avc->fid.Fid; + theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid; theCBs.AFSCBs_val = CallBacks_Array; CallBacks_Array[0].CallBackType = CB_DROPPED; if (avc->callback) { do { tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS); + RX_AFS_GUNLOCK(); + code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs); + RX_AFS_GLOCK(); + XSTATS_END_TIME; } /* don't set code on failure since we wouldn't use it */ - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, - SHARED_LOCK, (struct cell *)0)); + } while (afs_Analyze + (tc, code, &avc->fid, areq, + AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL)); ObtainWriteLock(&afs_xcbhash, 457); afs_DequeueCallback(avc); @@ -2279,83 +2215,71 @@ static PRemoveCallBack(avc, afun, areq, ain, aout, ainSize, aoutSize) return 0; } -static PNewCell(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - struct AFS_UCRED *acred; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PNewCell) +{ /* create a new cell */ - afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic=0; - register struct cell *tcell; - char *newcell=0, *linkedcell=0, *tp= ain; - register afs_int32 code, linkedstate=0, ls; + afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0; + char *newcell = 0, *linkedcell = 0, *tp = ain; + register afs_int32 code, linkedstate = 0, ls; u_short fsport = 0, vlport = 0; afs_int32 scount; - + AFS_STATCNT(PNewCell); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ - if (!afs_osi_suser(acred)) + if (!afs_osi_suser(*acred)) return EACCES; memcpy((char *)&magic, tp, sizeof(afs_int32)); tp += sizeof(afs_int32); if (magic != 0x12345678) - return EINVAL; + return EINVAL; /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS * server addresses while the 3.5 fs newcell command passes * MAXHOSTS. To figure out which is which, check if the cellname * is good. */ - newcell = tp + (MAXCELLHOSTS+3)*sizeof(afs_int32); + newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32); scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS); /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */ memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32)); tp += (scount * sizeof(afs_int32)); - lp = (afs_int32 *)tp; + lp = (afs_int32 *) tp; fsport = *lp++; vlport = *lp++; - if (fsport < 1024) fsport = 0; /* Privileged ports not allowed */ - if (vlport < 1024) vlport = 0; /* Privileged ports not allowed */ + if (fsport < 1024) + fsport = 0; /* Privileged ports not allowed */ + if (vlport < 1024) + vlport = 0; /* Privileged ports not allowed */ tp += (3 * sizeof(afs_int32)); newcell = tp; if ((ls = *lp) & 1) { - linkedcell = tp + strlen(newcell)+1; - linkedstate |= CLinkedCell; + linkedcell = tp + strlen(newcell) + 1; + linkedstate |= CLinkedCell; } - linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */ - code = afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport, vlport, (int)0); + linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */ + code = + afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport, + vlport, (int)0); return code; } -static PNewAlias(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - struct AFS_UCRED *acred; - afs_int32 *aoutSize; /* set this */ +DECL_PIOCTL(PNewAlias) { /* create a new cell alias */ char *tp = ain; register afs_int32 code; char *realName, *aliasName; - - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ - if (!afs_osi_suser(acred)) + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ + + if (!afs_osi_suser(*acred)) return EACCES; aliasName = tp; @@ -2367,21 +2291,16 @@ static PNewAlias(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) return code; } -static PListCells(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PListCells) +{ afs_int32 whichCell; - register struct cell *tcell=0; + register struct cell *tcell = 0; register afs_int32 i; register char *cp, *tp = ain; AFS_STATCNT(PListCells); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ memcpy((char *)&whichCell, tp, sizeof(afs_int32)); tp += sizeof(afs_int32); @@ -2389,35 +2308,33 @@ static PListCells(avc, afun, areq, ain, aout, ainSize, aoutSize) if (tcell) { cp = aout; memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32)); - for(i=0;icellHosts[i] == 0) break; - memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip, sizeof(afs_int32)); + for (i = 0; i < MAXCELLHOSTS; i++) { + if (tcell->cellHosts[i] == 0) + break; + memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip, + sizeof(afs_int32)); cp += sizeof(afs_int32); } cp = aout + MAXCELLHOSTS * sizeof(afs_int32); strcpy(cp, tcell->cellName); - cp += strlen(tcell->cellName)+1; + cp += strlen(tcell->cellName) + 1; *aoutSize = cp - aout; afs_PutCell(tcell, READ_LOCK); } - if (tcell) return 0; - else return EDOM; + if (tcell) + return 0; + else + return EDOM; } -static PListAliases(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ +DECL_PIOCTL(PListAliases) { afs_int32 whichAlias; - register struct cell_alias *tcalias=0; + register struct cell_alias *tcalias = 0; register char *cp, *tp = ain; - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ if (ainSize < sizeof(afs_int32)) return EINVAL; @@ -2425,31 +2342,27 @@ static PListAliases(avc, afun, areq, ain, aout, ainSize, aoutSize) tp += sizeof(afs_int32); tcalias = afs_GetCellAlias(whichAlias); - if (tcalias) { + if (tcalias) { cp = aout; strcpy(cp, tcalias->alias); - cp += strlen(tcalias->alias)+1; + cp += strlen(tcalias->alias) + 1; strcpy(cp, tcalias->cell); - cp += strlen(tcalias->cell)+1; + cp += strlen(tcalias->cell) + 1; *aoutSize = cp - aout; afs_PutCellAlias(tcalias); } - if (tcalias) return 0; - else return EDOM; + if (tcalias) + return 0; + else + return EDOM; } -static PRemoveMount(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PRemoveMount) +{ register afs_int32 code; char *bufp; struct sysname_info sysState; - afs_int32 offset, len; + afs_size_t offset, len; register struct conn *tc; register struct dcache *tdc; register struct vcache *tvc; @@ -2462,17 +2375,23 @@ static PRemoveMount(avc, afun, areq, ain, aout, ainSize, aoutSize) /* "ain" is the name of the file in this dir to remove */ AFS_STATCNT(PRemoveMount); - if (!avc) return EINVAL; + if (!avc) + return EINVAL; code = afs_VerifyVCache(avc, areq); - if (code) return code; - if (vType(avc) != VDIR) return ENOTDIR; + if (code) + return code; + if (vType(avc) != VDIR) + return ENOTDIR; - tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 1); /* test for error below */ - if (!tdc) return ENOENT; + tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */ + if (!tdc) + return ENOENT; Check_AtSys(avc, ain, &sysState, areq); + ObtainReadLock(&tdc->lock); do { - code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid); + code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid); } while (code == ENOENT && Next_AtSys(avc, areq, &sysState)); + ReleaseReadLock(&tdc->lock); bufp = sysState.name; if (code) { afs_PutDCache(tdc); @@ -2480,11 +2399,10 @@ static PRemoveMount(avc, afun, areq, ain, aout, ainSize, aoutSize) } tfid.Cell = avc->fid.Cell; tfid.Fid.Volume = avc->fid.Fid.Volume; - if (!tfid.Fid.Unique && (avc->states & CForeign)) { - tvc = afs_LookupVCache(&tfid, areq, (afs_int32 *)0, WRITE_LOCK, avc, bufp); + if (!tfid.Fid.Unique && (avc->states & CForeign)) { + tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp); } else { - tvc = afs_GetVCache(&tfid, areq, (afs_int32 *)0, - (struct vcache*)0/*xxx avc?*/, WRITE_LOCK); + tvc = afs_GetVCache(&tfid, areq, NULL, NULL); } if (!tvc) { code = ENOENT; @@ -2493,55 +2411,53 @@ static PRemoveMount(avc, afun, areq, ain, aout, ainSize, aoutSize) } if (tvc->mvstat != 1) { afs_PutDCache(tdc); - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); code = EINVAL; goto out; } - ObtainWriteLock(&tvc->lock,230); + ObtainWriteLock(&tvc->lock, 230); code = afs_HandleLink(tvc, areq); if (!code) { if (tvc->linkData) { if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%')) - code = EINVAL; - } else + code = EINVAL; + } else code = EIO; } ReleaseWriteLock(&tvc->lock); osi_dnlc_purgedp(tvc); - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); if (code) { afs_PutDCache(tdc); goto out; } - ObtainWriteLock(&avc->lock,231); + ObtainWriteLock(&avc->lock, 231); osi_dnlc_remove(avc, bufp, tvc); do { tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_RemoveFile(tc->id, (struct AFSFid *) &avc->fid.Fid, - bufp, &OutDirStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_REMOVEFILE, - SHARED_LOCK, (struct cell *)0)); + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE); + RX_AFS_GUNLOCK(); + code = + RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp, + &OutDirStatus, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE, + SHARED_LOCK, NULL)); if (code) { - if (tdc) afs_PutDCache(tdc); + if (tdc) + afs_PutDCache(tdc); ReleaseWriteLock(&avc->lock); goto out; } if (tdc) { /* we have the thing in the cache */ + ObtainWriteLock(&tdc->lock, 661); if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) { /* we can do it locally */ code = afs_dir_Delete(&tdc->f.inode, bufp); @@ -2550,44 +2466,35 @@ static PRemoveMount(avc, afun, areq, ain, aout, ainSize, aoutSize) DZap(&tdc->f.inode); } } + ReleaseWriteLock(&tdc->lock); afs_PutDCache(tdc); /* drop ref count */ } - avc->states &= ~CUnique; /* For the dfs xlator */ + avc->states &= ~CUnique; /* For the dfs xlator */ ReleaseWriteLock(&avc->lock); code = 0; -out: - if (sysState.allocked) osi_FreeLargeSpace(bufp); - return code; + out: + if (sysState.allocked) + osi_FreeLargeSpace(bufp); + return code; } -static PVenusLogging(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - struct AFS_UCRED *acred; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PVenusLogging) +{ return EINVAL; /* OBSOLETE */ } -static PGetCellStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PGetCellStatus) +{ register struct cell *tcell; afs_int32 temp; AFS_STATCNT(PGetCellStatus); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ tcell = afs_GetCellByName(ain, READ_LOCK); - if (!tcell) return ENOENT; + if (!tcell) + return ENOENT; temp = tcell->states; afs_PutCell(tcell, READ_LOCK); memcpy(aout, (char *)&temp, sizeof(afs_int32)); @@ -2595,24 +2502,19 @@ static PGetCellStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) return 0; } -static PSetCellStatus(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - struct AFS_UCRED *acred; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PSetCellStatus) +{ register struct cell *tcell; afs_int32 temp; - - if (!afs_osi_suser(acred)) + + if (!afs_osi_suser(*acred)) return EACCES; - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ - tcell = afs_GetCellByName(ain+2*sizeof(afs_int32), WRITE_LOCK); - if (!tcell) return ENOENT; + tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK); + if (!tcell) + return ENOENT; memcpy((char *)&temp, ain, sizeof(afs_int32)); if (temp & CNoSUID) tcell->states |= CNoSUID; @@ -2622,16 +2524,8 @@ static PSetCellStatus(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) return 0; } -static PFlushVolumeData(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; /* set this */ -struct AFS_UCRED *acred; +DECL_PIOCTL(PFlushVolumeData) { - extern struct volume *afs_volumes[NVOLS]; register afs_int32 i; register struct dcache *tdc; register struct vcache *tvc; @@ -2641,24 +2535,24 @@ struct AFS_UCRED *acred; AFS_STATCNT(PFlushVolumeData); if (!avc) return EINVAL; - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ - volume = avc->fid.Fid.Volume; /* who to zap */ + volume = avc->fid.Fid.Volume; /* who to zap */ cell = avc->fid.Cell; - /* + /* * Clear stat'd flag from all vnodes from this volume; this will invalidate all * the vcaches associated with the volume. */ ObtainReadLock(&afs_xvcache); - for(i = 0; i < VCSIZE; i++) { - for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) { + for (i = 0; i < VCSIZE; i++) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) { #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) VN_HOLD(AFSTOV(tvc)); #else -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) osi_vnhold(tvc, 0); #else VREFCOUNT_INC(tvc); @@ -2668,7 +2562,7 @@ struct AFS_UCRED *acred; #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */ #endif - ObtainWriteLock(&tvc->lock,232); + ObtainWriteLock(&tvc->lock, 232); ObtainWriteLock(&afs_xcbhash, 458); afs_DequeueCallback(tvc); @@ -2676,7 +2570,7 @@ struct AFS_UCRED *acred; ReleaseWriteLock(&afs_xcbhash); if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)) osi_dnlc_purgedp(tvc); - afs_TryToSmush(tvc, acred, 1); + afs_TryToSmush(tvc, *acred, 1); ReleaseWriteLock(&tvc->lock); #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonUnlock(&tvc->pvnLock, tvc); @@ -2690,31 +2584,35 @@ struct AFS_UCRED *acred; ReleaseReadLock(&afs_xvcache); - MObtainWriteLock(&afs_xdcache,328); /* needed if you're going to flush any stuff */ - for(i=0;irefCount <= 1) { /* too high, in use by running sys call */ + MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */ + for (i = 0; i < afs_cacheFiles; i++) { + if (!(afs_indexFlags[i] & IFEverUsed)) + continue; /* never had any data */ + tdc = afs_GetDSlot(i, NULL); + if (tdc->refCount <= 1) { /* too high, in use by running sys call */ + ReleaseReadLock(&tdc->tlock); if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) { - if (! (afs_indexFlags[i] & IFDataMod)) { + if (!(afs_indexFlags[i] & IFDataMod)) { /* if the file is modified, but has a ref cnt of only 1, then - someone probably has the file open and is writing into it. - Better to skip flushing such a file, it will be brought back - immediately on the next write anyway. - - If we *must* flush, then this code has to be rearranged to call - afs_storeAllSegments() first */ - afs_FlushDCache(tdc); + * someone probably has the file open and is writing into it. + * Better to skip flushing such a file, it will be brought back + * immediately on the next write anyway. + * + * If we *must* flush, then this code has to be rearranged to call + * afs_storeAllSegments() first */ + afs_FlushDCache(tdc); } } + } else { + ReleaseReadLock(&tdc->tlock); } - tdc->refCount--; /* bumped by getdslot */ + afs_PutDCache(tdc); /* bumped by getdslot */ } MReleaseWriteLock(&afs_xdcache); ObtainReadLock(&afs_xvolume); - for (i=0;inext) { + for (i = 0; i < NVOLS; i++) { + for (tv = afs_volumes[i]; tv; tv = tv->next) { if (tv->volume == volume) { afs_ResetVolumeInfo(tv); break; @@ -2723,35 +2621,32 @@ struct AFS_UCRED *acred; } ReleaseReadLock(&afs_xvolume); - /* probably, a user is doing this, probably, because things are screwed up. + /* probably, a user is doing this, probably, because things are screwed up. * maybe it's the dnlc's fault? */ - osi_dnlc_purge(); + osi_dnlc_purge(); return 0; } -static PGetVnodeXStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ { +DECL_PIOCTL(PGetVnodeXStatus) +{ register afs_int32 code; struct vcxstat stat; afs_int32 mode, i; - + /* AFS_STATCNT(PGetVnodeXStatus); */ - if (!avc) return EINVAL; + if (!avc) + return EINVAL; code = afs_VerifyVCache(avc, areq); - if (code) return code; + if (code) + return code; if (vType(avc) == VDIR) mode = PRSFS_LOOKUP; else mode = PRSFS_READ; if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS)) - return EACCES; + return EACCES; stat.fid = avc->fid; hset32(stat.DataVersion, hgetlo(avc->m.DataVersion)); stat.lock = avc->lock; @@ -2760,13 +2655,13 @@ static PGetVnodeXStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) hset(stat.flushDV, avc->flushDV); hset(stat.mapDV, avc->mapDV); stat.truncPos = avc->truncPos; - { /* just grab the first two - won't break anything... */ - struct axscache *ac; + { /* just grab the first two - won't break anything... */ + struct axscache *ac; - for (i=0, ac=avc->Access; ac && i < CPSIZE; i++, ac=ac->next) { - stat.randomUid[i] = ac->uid; - stat.randomAccess[i] = ac->axess; - } + for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) { + stat.randomUid[i] = ac->uid; + stat.randomAccess[i] = ac->axess; + } } stat.callback = afs_data_pointer_to_int32(avc->callback); stat.cbExpires = avc->cbExpires; @@ -2786,34 +2681,23 @@ static PGetVnodeXStatus(avc, afun, areq, ain, aout, ainSize, aoutSize) /* (since we don't really believe remote uids anyway) */ /* outname[] shouldn't really be needed- this is left as an excercise */ /* for the reader. */ -static PSetSysName(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; /* set this */ -register struct AFS_UCRED *acred; -{ - char *cp, inname[MAXSYSNAME], outname[MAXSYSNAME]; - int setsysname, foundname=0; +DECL_PIOCTL(PSetSysName) +{ + char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME]; + int setsysname, foundname = 0; register struct afs_exporter *exporter; - extern struct unixuser *afs_FindUser(); - extern char *afs_sysname; - extern char *afs_sysnamelist[]; - extern int afs_sysnamecount; register struct unixuser *au; register afs_int32 pag, error; - int t, count; - + int t, count, num = 0; + char **sysnamelist[MAXSYSNAME]; AFS_STATCNT(PSetSysName); if (!afs_globalVFS) { - /* Afsd is NOT running; disable it */ -#if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SGI64_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - return (EINVAL); -#else + /* Afsd is NOT running; disable it */ +#if defined(KERNEL_HAVE_UERROR) return (setuerror(EINVAL), EINVAL); +#else + return (EINVAL); #endif } memset(inname, 0, MAXSYSNAME); @@ -2821,92 +2705,100 @@ register struct AFS_UCRED *acred; ain += sizeof(afs_int32); if (setsysname) { - /* Check my args */ - if (setsysname < 0 || setsysname > MAXNUMSYSNAMES) - return EINVAL; - for(cp = ain,count = 0;count < setsysname;count++) { - /* won't go past end of ain since maxsysname*num < ain length */ - t = strlen(cp); - if (t >= MAXSYSNAME || t <= 0) - return EINVAL; - /* check for names that can shoot us in the foot */ - if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0))) - return EINVAL; - cp += t+1; - } - /* args ok */ - - /* inname gets first entry in case we're being a translater */ - t = strlen(ain); - memcpy(inname, ain, t+1); /* include terminating null */ - ain += t + 1; - } - if (acred->cr_gid == RMTUSER_REQ) { /* Handles all exporters */ - pag = PagInCred(acred); + /* Check my args */ + if (setsysname < 0 || setsysname > MAXNUMSYSNAMES) + return EINVAL; + cp2 = ain; + for (cp = ain, count = 0; count < setsysname; count++) { + /* won't go past end of ain since maxsysname*num < ain length */ + t = strlen(cp); + if (t >= MAXSYSNAME || t <= 0) + return EINVAL; + /* check for names that can shoot us in the foot */ + if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0))) + return EINVAL; + cp += t + 1; + } + /* args ok */ + + /* inname gets first entry in case we're being a translator */ + t = strlen(ain); + memcpy(inname, ain, t + 1); /* include terminating null */ + ain += t + 1; + num = count; + } + if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */ + pag = PagInCred(*acred); if (pag == NOPAG) { - return EINVAL; /* Better than panicing */ + return EINVAL; /* Better than panicing */ } if (!(au = afs_FindUser(pag, -1, READ_LOCK))) { - return EINVAL; /* Better than panicing */ + return EINVAL; /* Better than panicing */ } if (!(exporter = au->exporter)) { afs_PutUser(au, READ_LOCK); - return EINVAL; /* Better than panicing */ + return EINVAL; /* Better than panicing */ } - error = EXP_SYSNAME(exporter, (setsysname? inname : (char *)0), outname); + error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist, + &num); if (error) { - if (error == ENODEV) foundname = 0; /* sysname not set yet! */ + if (error == ENODEV) + foundname = 0; /* sysname not set yet! */ else { afs_PutUser(au, READ_LOCK); return error; } + } else { + foundname = num; + strcpy(outname, (*sysnamelist)[0]); } - else foundname = 1; afs_PutUser(au, READ_LOCK); } else { - - /* Not xlating, so local case */ - if (!afs_sysname) osi_Panic("PSetSysName: !afs_sysname\n"); + /* Not xlating, so local case */ + if (!afs_sysname) + osi_Panic("PSetSysName: !afs_sysname\n"); if (!setsysname) { /* user just wants the info */ strcpy(outname, afs_sysname); foundname = afs_sysnamecount; - } else { /* Local guy; only root can change sysname */ - if (!afs_osi_suser(acred)) + *sysnamelist = afs_sysnamelist; + } else { /* Local guy; only root can change sysname */ + if (!afs_osi_suser(*acred)) return EACCES; - + /* clear @sys entries from the dnlc, once afs_lookup can - do lookups of @sys entries and thinks it can trust them */ + * do lookups of @sys entries and thinks it can trust them */ /* privs ok, store the entry, ... */ strcpy(afs_sysname, inname); - if (setsysname > 1) { /* ... or list */ - cp = ain; - for(count=1; count < setsysname;++count) { - if (!afs_sysnamelist[count]) - osi_Panic("PSetSysName: no afs_sysnamelist entry to write\n"); - t = strlen(cp); - memcpy(afs_sysnamelist[count], cp, t+1); /* include null */ - cp += t+1; - } + if (setsysname > 1) { /* ... or list */ + cp = ain; + for (count = 1; count < setsysname; ++count) { + if (!afs_sysnamelist[count]) + osi_Panic + ("PSetSysName: no afs_sysnamelist entry to write\n"); + t = strlen(cp); + memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */ + cp += t + 1; + } } afs_sysnamecount = setsysname; } } if (!setsysname) { - cp = aout; /* not changing so report back the count and ... */ + cp = aout; /* not changing so report back the count and ... */ memcpy(cp, (char *)&foundname, sizeof(afs_int32)); cp += sizeof(afs_int32); if (foundname) { - strcpy(cp, outname); /* ... the entry, ... */ - cp += strlen(outname)+1; - for(count=1; count < foundname; ++count) { /* ... or list. */ - /* Note: we don't support @sys lists for exporters */ - if (!afs_sysnamelist[count]) - osi_Panic("PSetSysName: no afs_sysnamelist entry to read\n"); - t = strlen(afs_sysnamelist[count]); - if (t >= MAXSYSNAME) - osi_Panic("PSetSysName: sysname entry garbled\n"); - strcpy(cp, afs_sysnamelist[count]); - cp += t + 1; + strcpy(cp, outname); /* ... the entry, ... */ + cp += strlen(outname) + 1; + for (count = 1; count < foundname; ++count) { /* ... or list. */ + if (!(*sysnamelist)[count]) + osi_Panic + ("PSetSysName: no afs_sysnamelist entry to read\n"); + t = strlen((*sysnamelist)[count]); + if (t >= MAXSYSNAME) + osi_Panic("PSetSysName: sysname entry garbled\n"); + strcpy(cp, (*sysnamelist)[count]); + cp += t + 1; } } *aoutSize = cp - aout; @@ -2918,285 +2810,262 @@ register struct AFS_UCRED *acred; * long-term solution here. For small n, though, it should be just * fine. Should consider special-casing the local cell for large n. * Likewise for PSetSPrefs. + * + * s - number of ids in array l[] -- NOT index of last id + * l - array of cell ids which have volumes that need to be sorted + * vlonly - sort vl servers or file servers? */ -static void *ReSortCells_cb(struct cell *cell, void *arg) +static void * +ReSortCells_cb(struct cell *cell, void *arg) { afs_int32 *p = (afs_int32 *) arg; afs_int32 *l = p + 1; int i, s = p[0]; - - for (i=0; icellNum) { ObtainWriteLock(&cell->lock, 690); afs_SortServers(cell->cellHosts, MAXCELLHOSTS); ReleaseWriteLock(&cell->lock); } } + + return NULL; } -static void ReSortCells(int s, afs_int32 *l, int vlonly) -{ - extern struct volume *afs_volumes[NVOLS]; /* volume hash table */ - - int i; - struct volume *j; - register int k; - - if (vlonly) { - afs_int32 *p; - p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s+1)); - p[0] = s; - memcpy(p+1, l, s * sizeof(afs_int32)); - afs_TraverseCells(&ReSortCells_cb, p); - afs_osi_Free(p, sizeof(afs_int32) * (s+1)); - return; - } - - ObtainReadLock(&afs_xvolume); - for (i= 0; i< NVOLS; i++) { - for (j=afs_volumes[i];j;j=j->next) { - for (k=0;kcell == l[k]) { - ObtainWriteLock(&j->lock,233); - afs_SortServers(j->serverHost, MAXHOSTS); - ReleaseWriteLock(&j->lock); - break; - } - } - } - ReleaseReadLock(&afs_xvolume); -} - -int debugsetsp = 0; - -static int afs_setsprefs(sp, num, vlonly) - struct spref *sp; - unsigned int num; - unsigned int vlonly; -{ - struct srvAddr *sa; - int i,j,k,matches,touchedSize; - struct server *srvr = NULL; - afs_int32 touched[34]; - int isfs; - - touchedSize=0; - for (k=0; k < num; sp++, k++) { - if (debugsetsp) { - printf ("sp host=%x, rank=%d\n",sp->host.s_addr, sp->rank); - } - matches=0; - ObtainReadLock(&afs_xserver); - - i = SHash(sp->host.s_addr); - for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) { - if (sa->sa_ip == sp->host.s_addr) { - srvr = sa->server; - isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport)) - || (sa->sa_portal == AFS_FSPORT); - if ((!vlonly && isfs) || (vlonly && !isfs)) { - matches++; - break; +static void +ReSortCells(int s, afs_int32 * l, int vlonly) +{ + int i; + struct volume *j; + register int k; + + if (vlonly) { + afs_int32 *p; + p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1)); + p[0] = s; + memcpy(p + 1, l, s * sizeof(afs_int32)); + afs_TraverseCells(&ReSortCells_cb, p); + afs_osi_Free(p, sizeof(afs_int32) * (s + 1)); + return; + } + + ObtainReadLock(&afs_xvolume); + for (i = 0; i < NVOLS; i++) { + for (j = afs_volumes[i]; j; j = j->next) { + for (k = 0; k < s; k++) + if (j->cell == l[k]) { + ObtainWriteLock(&j->lock, 233); + afs_SortServers(j->serverHost, MAXHOSTS); + ReleaseWriteLock(&j->lock); + break; + } + } + } + ReleaseReadLock(&afs_xvolume); +} + + +static int debugsetsp = 0; +static int +afs_setsprefs(sp, num, vlonly) + struct spref *sp; + unsigned int num; + unsigned int vlonly; +{ + struct srvAddr *sa; + int i, j, k, matches, touchedSize; + struct server *srvr = NULL; + afs_int32 touched[34]; + int isfs; + + touchedSize = 0; + for (k = 0; k < num; sp++, k++) { + if (debugsetsp) { + printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank); + } + matches = 0; + ObtainReadLock(&afs_xserver); + + i = SHash(sp->host.s_addr); + for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) { + if (sa->sa_ip == sp->host.s_addr) { + srvr = sa->server; + isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport)) + || (sa->sa_portal == AFS_FSPORT); + if ((!vlonly && isfs) || (vlonly && !isfs)) { + matches++; + break; + } + } + } + + if (sa && matches) { /* found one! */ + if (debugsetsp) { + printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank); + } + sa->sa_iprank = sp->rank + afs_randomMod15(); + afs_SortOneServer(sa->server); + + if (srvr->cell) { + /* if we don't know yet what cell it's in, this is moot */ + for (j = touchedSize - 1; + j >= 0 && touched[j] != srvr->cell->cellNum; j--) + /* is it in our list of touched cells ? */ ; + if (j < 0) { /* no, it's not */ + touched[touchedSize++] = srvr->cell->cellNum; + if (touchedSize >= 32) { /* watch for ovrflow */ + ReleaseReadLock(&afs_xserver); + ReSortCells(touchedSize, touched, vlonly); + touchedSize = 0; + ObtainReadLock(&afs_xserver); + } + } } - } - } - - if (sa && matches) { /* found one! */ - if (debugsetsp) { - printf ("sa ip=%x, ip_rank=%d\n",sa->sa_ip, sa->sa_iprank); - } - sa->sa_iprank = sp->rank + afs_randomMod15(); - afs_SortOneServer(sa->server); - - if (srvr->cell) { - /* if we don't know yet what cell it's in, this is moot */ - for (j=touchedSize-1; j>=0 && touched[j] != srvr->cell->cellNum; j--) - /* is it in our list of touched cells ? */ ; - if (j < 0) { /* no, it's not */ - touched[touchedSize++] = srvr->cell->cellNum; - if (touchedSize >= 32) { /* watch for ovrflow */ - ReleaseReadLock(&afs_xserver); - ReSortCells(touchedSize, touched, vlonly); - touchedSize=0; - ObtainReadLock(&afs_xserver); - } - } - } - } - - ReleaseReadLock(&afs_xserver); - /* if we didn't find one, start to create one. */ - /* Note that it doesn't have a cell yet... */ - if (!matches) { - afs_uint32 temp = sp->host.s_addr; - srvr = afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT), - WRITE_LOCK, (afsUUID *)0,0); - srvr->addr->sa_iprank = sp->rank + afs_randomMod15(); - afs_PutServer(srvr, WRITE_LOCK); - } - } /* for all cited preferences */ - - ReSortCells(touchedSize, touched, vlonly); - return 0; + } + + ReleaseReadLock(&afs_xserver); + /* if we didn't find one, start to create one. */ + /* Note that it doesn't have a cell yet... */ + if (!matches) { + afs_uint32 temp = sp->host.s_addr; + srvr = + afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT), + WRITE_LOCK, (afsUUID *) 0, 0); + srvr->addr->sa_iprank = sp->rank + afs_randomMod15(); + afs_PutServer(srvr, WRITE_LOCK); + } + } /* for all cited preferences */ + + ReSortCells(touchedSize, touched, vlonly); + return 0; } /* Note that this may only be performed by the local root user. - */ -static int -PSetSPrefs(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - struct AFS_UCRED *acred; - afs_int32 *aoutSize; -{ - struct setspref *ssp; - AFS_STATCNT(PSetSPrefs); - - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ - - if (!afs_osi_suser(acred)) - return EACCES; - - if (ainSize < sizeof(struct setspref)) - return EINVAL; + */ +DECL_PIOCTL(PSetSPrefs) +{ + struct setspref *ssp; + AFS_STATCNT(PSetSPrefs); - ssp = (struct setspref *)ain; - if (ainSize < sizeof(struct spref)*ssp->num_servers) - return EINVAL; + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ + + if (!afs_osi_suser(*acred)) + return EACCES; + + if (ainSize < sizeof(struct setspref)) + return EINVAL; - afs_setsprefs(&(ssp->servers[0]), ssp->num_servers, - (ssp->flags & DBservers)); - return 0; + ssp = (struct setspref *)ain; + if (ainSize < sizeof(struct spref) * ssp->num_servers) + return EINVAL; + + afs_setsprefs(&(ssp->servers[0]), ssp->num_servers, + (ssp->flags & DBservers)); + return 0; } -static int -PSetSPrefs33(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - struct AFS_UCRED *acred; - afs_int32 *aoutSize; +DECL_PIOCTL(PSetSPrefs33) { - struct spref *sp; - AFS_STATCNT(PSetSPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + struct spref *sp; + AFS_STATCNT(PSetSPrefs); + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ - if (!afs_osi_suser(acred)) - return EACCES; + if (!afs_osi_suser(*acred)) + return EACCES; - sp = (struct spref *)ain; - afs_setsprefs(sp, ainSize/(sizeof(struct spref)), 0 /*!vlonly*/); - return 0; + sp = (struct spref *)ain; + afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ ); + return 0; } /* some notes on the following code... * in the hash table of server structs, all servers with the same IP address - * will be on the same overflow chain. - * This could be sped slightly in some circumstances by having it cache the + * will be on the same overflow chain. + * This could be sped slightly in some circumstances by having it cache the * immediately previous slot in the hash table and some supporting information * Only reports file servers now. */ -static int - PGetSPrefs(avc, afun, areq, ain, aout, ainSize, aoutSize) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; -{ - struct sprefrequest *spin; /* input */ - struct sprefinfo *spout; /* output */ - struct spref *srvout; /* one output component */ - int i,j; /* counters for hash table traversal */ - struct server *srvr; /* one of CM's server structs */ - struct srvAddr *sa; - afs_uint32 prevh; - int vlonly; /* just return vlservers ? */ - int isfs; - - AFS_STATCNT(PGetSPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ - - - if (ainSize < sizeof (struct sprefrequest_33)) { - return ENOENT; - } - else { - spin = ((struct sprefrequest *) ain); - } - - if (ainSize > sizeof (struct sprefrequest_33)) { - vlonly = (spin->flags & DBservers); - } - else vlonly = 0; - - /* struct sprefinfo includes 1 server struct... that size gets added - * in during the loop that follows. - */ - *aoutSize = sizeof(struct sprefinfo) - sizeof (struct spref); - spout = (struct sprefinfo *) aout; - spout->next_offset = spin->offset; - spout->num_servers = 0; - srvout = spout->servers; - - ObtainReadLock(&afs_xserver); - for (i=0, j=0; j < NSERVERS; j++) { /* sift through hash table */ - for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) { - if (spin->offset > (unsigned short)i) { - continue; /* catch up to where we left off */ - } +DECL_PIOCTL(PGetSPrefs) +{ + struct sprefrequest *spin; /* input */ + struct sprefinfo *spout; /* output */ + struct spref *srvout; /* one output component */ + int i, j; /* counters for hash table traversal */ + struct server *srvr; /* one of CM's server structs */ + struct srvAddr *sa; + int vlonly; /* just return vlservers ? */ + int isfs; + + AFS_STATCNT(PGetSPrefs); + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ + + + if (ainSize < sizeof(struct sprefrequest_33)) { + return ENOENT; + } else { + spin = ((struct sprefrequest *)ain); + } + + if (ainSize > sizeof(struct sprefrequest_33)) { + vlonly = (spin->flags & DBservers); + } else + vlonly = 0; + + /* struct sprefinfo includes 1 server struct... that size gets added + * in during the loop that follows. + */ + *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref); + spout = (struct sprefinfo *)aout; + spout->next_offset = spin->offset; + spout->num_servers = 0; + srvout = spout->servers; + + ObtainReadLock(&afs_xserver); + for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */ + for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) { + if (spin->offset > (unsigned short)i) { + continue; /* catch up to where we left off */ + } spout->next_offset++; - + srvr = sa->server; - isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport)) - || (sa->sa_portal == AFS_FSPORT); - + isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport)) + || (sa->sa_portal == AFS_FSPORT); + if ((vlonly && isfs) || (!vlonly && !isfs)) { - /* only report ranks for vl servers */ - continue; + /* only report ranks for vl servers */ + continue; } - - srvout->host.s_addr = sa->sa_ip; - srvout->rank = sa->sa_iprank; - *aoutSize += sizeof(struct spref); - spout->num_servers++; - srvout++; - - if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) { - ReleaseReadLock(&afs_xserver); /* no more room! */ - return 0; - } - } - } - ReleaseReadLock(&afs_xserver); - - spout->next_offset = 0; /* start over from the beginning next time */ - return 0; + + srvout->host.s_addr = sa->sa_ip; + srvout->rank = sa->sa_iprank; + *aoutSize += sizeof(struct spref); + spout->num_servers++; + srvout++; + + if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) { + ReleaseReadLock(&afs_xserver); /* no more room! */ + return 0; + } + } + } + ReleaseReadLock(&afs_xserver); + + spout->next_offset = 0; /* start over from the beginning next time */ + return 0; } /* Enable/Disable the specified exporter. Must be root to disable an exporter */ -int afs_NFSRootOnly = 1; -/*static*/ PExportAfs(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; /* set this */ -struct AFS_UCRED *acred; -{ - afs_int32 export, newint=0, type, changestate, handleValue, convmode, pwsync, smounts; - extern struct afs_exporter *exporter_find(); +int afs_NFSRootOnly = 1; +DECL_PIOCTL(PExportAfs) +{ + afs_int32 export, newint = + 0, type, changestate, handleValue, convmode, pwsync, smounts; register struct afs_exporter *exporter; AFS_STATCNT(PExportAfs); @@ -3204,7 +3073,7 @@ struct AFS_UCRED *acred; type = handleValue >> 24; if (type == 0x71) { newint = 1; - type = 1; /* nfs */ + type = 1; /* nfs */ } exporter = exporter_find(type); if (newint) { @@ -3229,8 +3098,8 @@ struct AFS_UCRED *acred; memcpy(aout, (char *)&handleValue, sizeof(afs_int32)); *aoutSize = sizeof(afs_int32); } else { - if (!afs_osi_suser(acred)) - return EACCES; /* Only superuser can do this */ + if (!afs_osi_suser(*acred)) + return EACCES; /* Only superuser can do this */ if (newint) { if (export & 2) { if (export & 1) @@ -3288,94 +3157,71 @@ struct AFS_UCRED *acred; return 0; } -static int -PGag(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -struct AFS_UCRED *acred; -afs_int32 *aoutSize; /* set this */ +DECL_PIOCTL(PGag) { -struct gaginfo *gagflags; + struct gaginfo *gagflags; - if (!afs_osi_suser(acred)) - return EACCES; + if (!afs_osi_suser(*acred)) + return EACCES; - gagflags = (struct gaginfo *) ain; - afs_showflags = gagflags->showflags; + gagflags = (struct gaginfo *)ain; + afs_showflags = gagflags->showflags; - return 0; + return 0; } -static int -PTwiddleRx(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -struct AFS_UCRED *acred; -afs_int32 *aoutSize; -{ - struct rxparams *rxp; - - if (!afs_osi_suser(acred)) - return EACCES; - - rxp = (struct rxparams *) ain; - - if (rxp->rx_initReceiveWindow) - rx_initReceiveWindow = rxp->rx_initReceiveWindow; - if (rxp->rx_maxReceiveWindow) - rx_maxReceiveWindow = rxp->rx_maxReceiveWindow; - if (rxp->rx_initSendWindow) - rx_initSendWindow = rxp->rx_initSendWindow; - if (rxp->rx_maxSendWindow) - rx_maxSendWindow = rxp->rx_maxSendWindow; - if (rxp->rxi_nSendFrags) - rxi_nSendFrags = rxp->rxi_nSendFrags; - if (rxp->rxi_nRecvFrags) - rxi_nRecvFrags = rxp->rxi_nRecvFrags; - if (rxp->rxi_OrphanFragSize) - rxi_OrphanFragSize = rxp->rxi_OrphanFragSize; - if (rxp->rx_maxReceiveSize) - { - rx_maxReceiveSize = rxp->rx_maxReceiveSize; - rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize; - } - if (rxp->rx_MyMaxSendSize) - rx_MyMaxSendSize = rxp->rx_MyMaxSendSize; - - return 0; -} - -static int PGetInitParams(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - register char *ain; - char *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ +DECL_PIOCTL(PTwiddleRx) +{ + struct rxparams *rxp; + + if (!afs_osi_suser(*acred)) + return EACCES; + + rxp = (struct rxparams *)ain; + + if (rxp->rx_initReceiveWindow) + rx_initReceiveWindow = rxp->rx_initReceiveWindow; + if (rxp->rx_maxReceiveWindow) + rx_maxReceiveWindow = rxp->rx_maxReceiveWindow; + if (rxp->rx_initSendWindow) + rx_initSendWindow = rxp->rx_initSendWindow; + if (rxp->rx_maxSendWindow) + rx_maxSendWindow = rxp->rx_maxSendWindow; + if (rxp->rxi_nSendFrags) + rxi_nSendFrags = rxp->rxi_nSendFrags; + if (rxp->rxi_nRecvFrags) + rxi_nRecvFrags = rxp->rxi_nRecvFrags; + if (rxp->rxi_OrphanFragSize) + rxi_OrphanFragSize = rxp->rxi_OrphanFragSize; + if (rxp->rx_maxReceiveSize) { + rx_maxReceiveSize = rxp->rx_maxReceiveSize; + rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize; + } + if (rxp->rx_MyMaxSendSize) + rx_MyMaxSendSize = rxp->rx_MyMaxSendSize; + + return 0; +} + +DECL_PIOCTL(PGetInitParams) { if (sizeof(struct cm_initparams) > PIGGYSIZE) return E2BIG; - memcpy(aout, (char*)&cm_initParams, sizeof(struct cm_initparams)); + memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams)); *aoutSize = sizeof(struct cm_initparams); return 0; } #ifdef AFS_SGI65_ENV /* They took crget() from us, so fake it. */ -static cred_t *crget(void) +static cred_t * +crget(void) { cred_t *cr; cr = crdup(get_current_cred()); - memset((char*)cr, 0, sizeof(cred_t)); + memset((char *)cr, 0, sizeof(cred_t)); #if CELL || CELL_PREPARE cr->cr_id = -1; #endif @@ -3383,45 +3229,30 @@ static cred_t *crget(void) } #endif -static int -PGetRxkcrypt(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; -struct AFS_UCRED *acred; +DECL_PIOCTL(PGetRxkcrypt) { memcpy(aout, (char *)&cryptall, sizeof(afs_int32)); - *aoutSize=sizeof(afs_int32); + *aoutSize = sizeof(afs_int32); return 0; } -static int -PSetRxkcrypt(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; -struct AFS_UCRED *acred; +DECL_PIOCTL(PSetRxkcrypt) { afs_int32 tmpval; - if (!afs_osi_suser(acred)) - return EPERM; + if (!afs_osi_suser(*acred)) + return EPERM; if (ainSize != sizeof(afs_int32) || ain == NULL) - return EINVAL; + return EINVAL; memcpy((char *)&tmpval, ain, sizeof(afs_int32)); /* if new mappings added later this will need to be changed */ if (tmpval != 0 && tmpval != 1) - return EINVAL; + return EINVAL; cryptall = tmpval; return 0; } +#ifdef AFS_NEED_CLIENTCONTEXT /* * Create new credentials to correspond to a remote user with given * . This allows a server running as root to @@ -3430,46 +3261,44 @@ struct AFS_UCRED *acred; */ #define PSETPAG 110 #define PIOCTL_HEADER 6 -static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCRED **acred, struct AFS_UCRED *credp) +static int +HandleClientContext(struct afs_ioctl *ablob, int *com, + struct AFS_UCRED **acred, struct AFS_UCRED *credp) { char *ain, *inData; afs_uint32 hostaddr; afs_int32 uid, g0, g1, i, code, pag, exporter_type; - extern struct afs_exporter *exporter_find(); struct afs_exporter *exporter, *outexporter; struct AFS_UCRED *newcred; struct unixuser *au; -#if defined(AFS_DEC_ENV) || (defined(AFS_NONFSTRANS) && !defined(AFS_AIX_IAUTH_ENV)) - return EINVAL; /* NFS trans not supported for Ultrix */ -#else #if defined(AFS_SGIMP_ENV) osi_Assert(ISAFS_GLOCK()); #endif AFS_STATCNT(HandleClientContext); - if (ablob->in_size < PIOCTL_HEADER*sizeof(afs_int32)) { + if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) { /* Must at least include the PIOCTL_HEADER header words required by the protocol */ - return EINVAL; /* Too small to be good */ + return EINVAL; /* Too small to be good */ } ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ); - AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER*sizeof(afs_int32), code); + AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code); if (code) { osi_FreeLargeSpace(inData); return code; } /* Extract information for remote user */ - hostaddr = *((afs_uint32 *)ain); + hostaddr = *((afs_uint32 *) ain); ain += sizeof(hostaddr); - uid = *((afs_uint32 *)ain); + uid = *((afs_uint32 *) ain); ain += sizeof(uid); - g0 = *((afs_uint32 *)ain); + g0 = *((afs_uint32 *) ain); ain += sizeof(g0); - g1 = *((afs_uint32 *)ain); + g1 = *((afs_uint32 *) ain); ain += sizeof(g1); - *com = *((afs_uint32 *)ain); + *com = *((afs_uint32 *) ain); ain += sizeof(afs_int32); - exporter_type = *((afs_uint32 *)ain); /* In case we support more than NFS */ + exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */ /* * Of course, one must be root for most of these functions, but @@ -3478,46 +3307,49 @@ static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCR */ i = (*com) & 0xff; if (!afs_osi_suser(credp)) { -#ifdef AFS_SGI_ENV -#ifndef AFS_SGI64_ENV +#if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) /* Since SGI's suser() returns explicit failure after the call.. */ - u.u_error = 0; -#endif + u.u_error = 0; #endif /* check for acceptable opcodes for normal folks, which are, so far, * set tokens and unlog. */ - if (i != 9 && i != 3 && i != 38 && i != 8) { + if (i != 9 && i != 3 && i != 38 && i != 8) { osi_FreeLargeSpace(inData); return EACCES; } } - ablob->in_size -= PIOCTL_HEADER*sizeof(afs_int32); - ablob->in += PIOCTL_HEADER*sizeof(afs_int32); + ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32); + ablob->in += PIOCTL_HEADER * sizeof(afs_int32); osi_FreeLargeSpace(inData); if (uid == 0) { - /* - * We map uid 0 to nobody to match the mapping that the nfs - * server does and to ensure that the suser() calls in the afs - * code fails for remote client roots. - */ + /* + * We map uid 0 to nobody to match the mapping that the nfs + * server does and to ensure that the suser() calls in the afs + * code fails for remote client roots. + */ uid = afs_nobody; /* NFS_NOBODY == -2 */ } newcred = crget(); #ifdef AFS_AIX41_ENV - setuerror(0); + setuerror(0); #endif newcred->cr_gid = RMTUSER_REQ; +#ifdef AFS_AIX51_ENV + newcred->cr_groupset.gs_union.un_groups[0] = g0; + newcred->cr_groupset.gs_union.un_groups[1] = g1; +#else newcred->cr_groups[0] = g0; newcred->cr_groups[1] = g1; +#endif #ifdef AFS_AIX_ENV newcred->cr_ngrps = 2; #else #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) newcred->cr_ngroups = 2; #else - for (i=2; icr_groups[i] = NOGROUP; #endif #endif @@ -3526,8 +3358,8 @@ static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCR #endif if (!(exporter = exporter_find(exporter_type))) { /* Exporter wasn't initialized or an invalid exporter type */ - crfree(newcred); - return EINVAL; + crfree(newcred); + return EINVAL; } if (exporter->exp_states & EXP_PWSYNC) { if (uid != credp->cr_uid) { @@ -3535,212 +3367,191 @@ static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCR return ENOEXEC; /* XXX Find a better errno XXX */ } } - newcred->cr_uid = uid; /* Only temporary */ + newcred->cr_uid = uid; /* Only temporary */ code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter); /* The client's pag is the only unique identifier for it */ newcred->cr_uid = pag; *acred = newcred; if (!code && *com == PSETPAG) { - /* Special case for 'setpag' */ - afs_uint32 pagvalue = genpag(); - - au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */ - /* - * Note that we leave the 'outexporter' struct held so it won't - * dissappear on us - */ - au->exporter = outexporter; - if (ablob->out_size >= 4) { - AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32), code); - } - afs_PutUser(au, WRITE_LOCK); - if (code) return code; - return PSETPAG; /* Special return for setpag */ + /* Special case for 'setpag' */ + afs_uint32 pagvalue = genpag(); + + au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */ + /* + * Note that we leave the 'outexporter' struct held so it won't + * dissappear on us + */ + au->exporter = outexporter; + if (ablob->out_size >= 4) { + AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32), + code); + } + afs_PutUser(au, WRITE_LOCK); + if (code) + return code; + return PSETPAG; /* Special return for setpag */ } else if (!code) { EXP_RELE(outexporter); } return code; -#endif /*defined(AFS_DEC_ENV) || defined(AFS_NONFSTRANS)*/ } +#endif /* AFS_NEED_CLIENTCONTEXT */ /* get all interface addresses of this client */ -static int -PGetCPrefs(avc, afun, areq, ain, aout, ainSize, aoutSize) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; -{ - struct sprefrequest *spin; /* input */ - struct sprefinfo *spout; /* output */ - struct spref *srvout; /* one output component */ - int maxNumber; - int i,j; - - AFS_STATCNT(PGetCPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ - - if ( ainSize < sizeof (struct sprefrequest )) - return EINVAL; - - spin = (struct sprefrequest *) ain; - spout = (struct sprefinfo *) aout; - - maxNumber = spin->num_servers; /* max addrs this time */ - srvout = spout->servers; - - ObtainReadLock(&afs_xinterface); - - /* copy out the client interface information from the - ** kernel data structure "interface" to the output buffer - */ - for ( i=spin->offset, j=0; (i < afs_cb_interface.numberOfInterfaces) - && ( j< maxNumber) ; i++, j++, srvout++) - srvout->host.s_addr = afs_cb_interface.addr_in[i]; - - spout->num_servers = j; - *aoutSize = sizeof(struct sprefinfo) +(j-1)* sizeof (struct spref); - - if ( i >= afs_cb_interface.numberOfInterfaces ) - spout->next_offset = 0; /* start from beginning again */ - else - spout->next_offset = spin->offset + j; - - ReleaseReadLock(&afs_xinterface); - return 0; +DECL_PIOCTL(PGetCPrefs) +{ + struct sprefrequest *spin; /* input */ + struct sprefinfo *spout; /* output */ + struct spref *srvout; /* one output component */ + int maxNumber; + int i, j; + + AFS_STATCNT(PGetCPrefs); + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ + + if (ainSize < sizeof(struct sprefrequest)) + return EINVAL; + + spin = (struct sprefrequest *)ain; + spout = (struct sprefinfo *)aout; + + maxNumber = spin->num_servers; /* max addrs this time */ + srvout = spout->servers; + + ObtainReadLock(&afs_xinterface); + + /* copy out the client interface information from the + ** kernel data structure "interface" to the output buffer + */ + for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces) + && (j < maxNumber); i++, j++, srvout++) + srvout->host.s_addr = afs_cb_interface.addr_in[i]; + + spout->num_servers = j; + *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref); + + if (i >= afs_cb_interface.numberOfInterfaces) + spout->next_offset = 0; /* start from beginning again */ + else + spout->next_offset = spin->offset + j; + + ReleaseReadLock(&afs_xinterface); + return 0; } -static int -PSetCPrefs(avc, afun, areq, ain, aout, ainSize, aoutSize) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; +DECL_PIOCTL(PSetCPrefs) { - struct setspref *sin; - int i; + struct setspref *sin; + int i; - AFS_STATCNT(PSetCPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ - return EIO; /* Inappropriate ioctl for device */ + AFS_STATCNT(PSetCPrefs); + if (!afs_resourceinit_flag) /* afs daemons haven't started yet */ + return EIO; /* Inappropriate ioctl for device */ - sin = (struct setspref *)ain; + sin = (struct setspref *)ain; - if ( ainSize < sizeof(struct setspref) ) - return EINVAL; -#if 0 /* num_servers is unsigned */ - if ( sin->num_servers < 0 ) - return EINVAL; + if (ainSize < sizeof(struct setspref)) + return EINVAL; +#if 0 /* num_servers is unsigned */ + if (sin->num_servers < 0) + return EINVAL; #endif - if ( sin->num_servers > AFS_MAX_INTERFACE_ADDR) - return ENOMEM; + if (sin->num_servers > AFS_MAX_INTERFACE_ADDR) + return ENOMEM; - ObtainWriteLock(&afs_xinterface, 412); - afs_cb_interface.numberOfInterfaces = sin->num_servers; - for ( i=0; (unsigned short)i < sin->num_servers; i++) - afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr; + ObtainWriteLock(&afs_xinterface, 412); + afs_cb_interface.numberOfInterfaces = sin->num_servers; + for (i = 0; (unsigned short)i < sin->num_servers; i++) + afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr; - ReleaseWriteLock(&afs_xinterface); - return 0; + ReleaseWriteLock(&afs_xinterface); + return 0; } -static PFlushMount(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; - struct AFS_UCRED *acred; { +DECL_PIOCTL(PFlushMount) +{ register afs_int32 code; register struct vcache *tvc; register struct dcache *tdc; struct VenusFid tfid; char *bufp; struct sysname_info sysState; - afs_int32 offset, len; + afs_size_t offset, len; AFS_STATCNT(PFlushMount); - if (!avc) return EINVAL; + if (!avc) + return EINVAL; code = afs_VerifyVCache(avc, areq); - if (code) return code; + if (code) + return code; if (vType(avc) != VDIR) { return ENOTDIR; } - tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 1); - if (!tdc) return ENOENT; + tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); + if (!tdc) + return ENOENT; Check_AtSys(avc, ain, &sysState, areq); + ObtainReadLock(&tdc->lock); do { - code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid); + code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid); } while (code == ENOENT && Next_AtSys(avc, areq, &sysState)); + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); /* we're done with the data */ bufp = sysState.name; if (code) { - afs_PutDCache(tdc); goto out; } tfid.Cell = avc->fid.Cell; tfid.Fid.Volume = avc->fid.Fid.Volume; - afs_PutDCache(tdc); /* we're done with the data */ if (!tfid.Fid.Unique && (avc->states & CForeign)) { - tvc = afs_LookupVCache(&tfid, areq, (afs_int32 *)0, WRITE_LOCK, avc, bufp); + tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp); } else { - tvc = afs_GetVCache(&tfid, areq, (afs_int32 *)0, (struct vcache*)0, - WRITE_LOCK); + tvc = afs_GetVCache(&tfid, areq, NULL, NULL); } if (!tvc) { code = ENOENT; goto out; } if (tvc->mvstat != 1) { - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); code = EINVAL; goto out; } #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */ #endif - ObtainWriteLock(&tvc->lock,645); - ObtainWriteLock(&afs_xcbhash, 646); + ObtainWriteLock(&tvc->lock, 649); + ObtainWriteLock(&afs_xcbhash, 650); afs_DequeueCallback(tvc); - tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */ + tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */ ReleaseWriteLock(&afs_xcbhash); /* now find the disk cache entries */ - afs_TryToSmush(tvc, acred, 1); + afs_TryToSmush(tvc, *acred, 1); osi_dnlc_purgedp(tvc); afs_symhint_inval(tvc); if (tvc->linkData && !(tvc->states & CCore)) { - afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1); - tvc->linkData = (char *) 0; + afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1); + tvc->linkData = NULL; } ReleaseWriteLock(&tvc->lock); #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) afs_BozonUnlock(&tvc->pvnLock, tvc); #endif - afs_PutVCache(tvc, WRITE_LOCK); -out: - if (sysState.allocked) osi_FreeLargeSpace(bufp); + afs_PutVCache(tvc); + out: + if (sysState.allocked) + osi_FreeLargeSpace(bufp); return code; } -static PRxStatProc(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; - struct AFS_UCRED *acred; +DECL_PIOCTL(PRxStatProc) { int code = 0; afs_int32 flags; - if (!afs_osi_suser(acred)) { + if (!afs_osi_suser(*acred)) { code = EACCES; goto out; } @@ -3762,25 +3573,18 @@ static PRxStatProc(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) if (flags & AFSCALL_RXSTATS_CLEAR) { rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL); } -out: + out: *aoutSize = 0; return code; } -static PRxStatPeer(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; - struct AFS_UCRED *acred; +DECL_PIOCTL(PRxStatPeer) { int code = 0; afs_int32 flags; - if (!afs_osi_suser(acred)) { + if (!afs_osi_suser(*acred)) { code = EACCES; goto out; } @@ -3802,18 +3606,12 @@ static PRxStatPeer(avc, afun, areq, ain, aout, ainSize, aoutSize, acred) if (flags & AFSCALL_RXSTATS_CLEAR) { rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL); } -out: + out: *aoutSize = 0; return code; } -static PPrefetchFromTape(avc, afun, areq, ain, aout, ainSize, aoutSize) - struct vcache *avc; - int afun; - struct vrequest *areq; - char *ain, *aout; - afs_int32 ainSize; - afs_int32 *aoutSize; /* set this */ +DECL_PIOCTL(PPrefetchFromTape) { register afs_int32 code, code1; afs_int32 bytes; @@ -3825,76 +3623,61 @@ static PPrefetchFromTape(avc, afun, areq, ain, aout, ainSize, aoutSize) struct VenusFid tfid; struct AFSFid *Fid; struct vcache *tvc; - XSTATS_DECLS; AFS_STATCNT(PSetAcl); if (!avc) - return EINVAL; + return EINVAL; if (ain && (ainSize == 3 * sizeof(afs_int32))) - Fid = (struct AFSFid *) ain; + Fid = (struct AFSFid *)ain; else - Fid = &avc->fid.Fid; + Fid = &avc->fid.Fid; tfid.Cell = avc->fid.Cell; tfid.Fid.Volume = Fid->Volume; tfid.Fid.Vnode = Fid->Vnode; tfid.Fid.Unique = Fid->Unique; - tvc = afs_GetVCache(&tfid, areq, (afs_int32 *)0, (struct vcache *)0, - WRITE_LOCK); + tvc = afs_GetVCache(&tfid, areq, NULL, NULL); if (!tvc) { - afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, - ICL_TYPE_POINTER, tvc, - ICL_TYPE_FID, &tfid, - ICL_TYPE_FID, &avc->fid); - return ENOENT; + afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc, + ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid); + return ENOENT; } - afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, - ICL_TYPE_POINTER, tvc, - ICL_TYPE_FID, &tfid, - ICL_TYPE_FID, &tvc->fid); + afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc, + ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid); do { - tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK); - if (tc) { - -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - tcall = rx_NewCall(tc->id); - code = StartRXAFS_FetchData(tcall, - (struct AFSFid *) &tvc->fid.Fid, 0, 0); - if (!code) { - bytes = rx_Read(tcall, (char *) aout, sizeof(afs_int32)); - code = EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync); - } - code1 = rx_EndCall(tcall, code); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - } else - code = -1; - } while - (afs_Analyze(tc, code, &tvc->fid, areq, - AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, - (struct cell *)0)); + tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK); + if (tc) { + + RX_AFS_GUNLOCK(); + tcall = rx_NewCall(tc->id); + code = + StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0, + 0); + if (!code) { + bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32)); + code = + EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync); + } + code1 = rx_EndCall(tcall, code); + RX_AFS_GLOCK(); + } else + code = -1; + } while (afs_Analyze + (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, + SHARED_LOCK, NULL)); /* This call is done only to have the callback things handled correctly */ afs_FetchStatus(tvc, &tfid, areq, &OutStatus); - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); if (!code) { - *aoutSize = sizeof(afs_int32); + *aoutSize = sizeof(afs_int32); } return code; } -static PResidencyCmd(avc, afun, areq, ain, aout, ainSize, aoutSize) -struct vcache *avc; -int afun; -struct vrequest *areq; -char *ain, *aout; -afs_int32 ainSize; -afs_int32 *aoutSize; /* set this */ +DECL_PIOCTL(PResidencyCmd) { register afs_int32 code; struct conn *tc; @@ -3904,66 +3687,60 @@ afs_int32 *aoutSize; /* set this */ struct VenusFid tfid; struct AFSFid *Fid; - Inputs = (struct ResidencyCmdInputs *) ain; - Outputs = (struct ResidencyCmdOutputs *) aout; - if (!avc) return EINVAL; - if (!ain || ainSize != sizeof(struct ResidencyCmdInputs)) return EINVAL; + Inputs = (struct ResidencyCmdInputs *)ain; + Outputs = (struct ResidencyCmdOutputs *)aout; + if (!avc) + return EINVAL; + if (!ain || ainSize != sizeof(struct ResidencyCmdInputs)) + return EINVAL; Fid = &Inputs->fid; if (!Fid->Volume) - Fid = &avc->fid.Fid; + Fid = &avc->fid.Fid; tfid.Cell = avc->fid.Cell; tfid.Fid.Volume = Fid->Volume; tfid.Fid.Vnode = Fid->Vnode; tfid.Fid.Unique = Fid->Unique; - tvc = afs_GetVCache(&tfid, areq, (afs_int32 *)0, (struct vcache *)0, - WRITE_LOCK); - afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, - ICL_TYPE_POINTER, tvc, - ICL_TYPE_INT32, Inputs->command, - ICL_TYPE_FID, &tfid); + tvc = afs_GetVCache(&tfid, areq, NULL, NULL); + afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc, + ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid); if (!tvc) - return ENOENT; + return ENOENT; if (Inputs->command) { - do { - tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK); - if (tc) { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_ResidencyCmd(tc->id, Fid, - Inputs, - (struct ResidencyCmdOutputs *) aout); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - } else - code = -1; - } while - (afs_Analyze(tc, code, &tvc->fid, areq, - AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, - (struct cell *)0)); - /* This call is done to have the callback things handled correctly */ - afs_FetchStatus(tvc, &tfid, areq, &Outputs->status); - } else { /* just a status request, return also link data */ - code = 0; - Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status); - Outputs->chars[0] = 0; - if (vType(tvc) == VLNK) { - ObtainWriteLock(&tvc->lock,555); - if (afs_HandleLink(tvc, areq) == 0) - strncpy((char *) &Outputs->chars, tvc->linkData, MAXCMDCHARS); - ReleaseWriteLock(&tvc->lock); - } + do { + tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK); + if (tc) { + RX_AFS_GUNLOCK(); + code = + RXAFS_ResidencyCmd(tc->id, Fid, Inputs, + (struct ResidencyCmdOutputs *)aout); + RX_AFS_GLOCK(); + } else + code = -1; + } while (afs_Analyze + (tc, code, &tvc->fid, areq, + AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL)); + /* This call is done to have the callback things handled correctly */ + afs_FetchStatus(tvc, &tfid, areq, &Outputs->status); + } else { /* just a status request, return also link data */ + code = 0; + Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status); + Outputs->chars[0] = 0; + if (vType(tvc) == VLNK) { + ObtainWriteLock(&tvc->lock, 555); + if (afs_HandleLink(tvc, areq) == 0) + strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS); + ReleaseWriteLock(&tvc->lock); + } } - afs_PutVCache(tvc, WRITE_LOCK); + afs_PutVCache(tvc); if (!code) { - *aoutSize = sizeof(struct ResidencyCmdOutputs); + *aoutSize = sizeof(struct ResidencyCmdOutputs); } return code; -} +} diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index a10062325..43aa28236 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -11,20 +11,197 @@ #define _AFS_PROTOTYPES_H_ /* afs_analyze.c */ +extern void init_et_to_sys_error(void); extern void afs_FinalizeReq(struct vrequest *areq); +extern int afs_Analyze(register struct conn *aconn, afs_int32 acode, + struct VenusFid *afid, register struct vrequest *areq, + int op, afs_int32 locktype, struct cell *cellp); +extern int afs_CheckCode(afs_int32 acode, struct vrequest *areq, int where); +extern void afs_CopyError(register struct vrequest *afrom, + register struct vrequest *ato); +extern void init_sys_error_to_et(void); -extern int afs_Analyze(struct conn *aconn, afs_int32 acode, struct VenusFid *afid, - register struct vrequest *areq, int op, afs_int32 locktype, - struct cell *cellp); +/* afs_axscache.c */ +extern afs_rwlock_t afs_xaxs; +extern struct axscache *afs_SlowFindAxs(struct axscache **cachep, + afs_int32 id); +extern struct axscache *axs_Alloc(void); +extern void afs_RemoveAxs(struct axscache **headp, struct axscache *axsp); +extern void afs_FreeAllAxs(struct axscache **headp); + +/* afs_buffer.c */ +extern void DInit(int abuffers); +extern void *DRead(register afs_inode_t * fid, register int page); +extern void DRelease(register struct buffer *bp, int flag); +extern int DVOffset(register void *ap); +extern void DZap(afs_inode_t * fid); +extern void DFlush(void); +extern void *DNew(register afs_inode_t * fid, register int page); +extern void shutdown_bufferpackage(void); + +/* afs_call.c */ +extern int afs_cold_shutdown; +extern afs_int32 afs_setTime; +extern char afs_rootVolumeName[64]; +extern void afs_shutdown(void); +extern void afs_FlushCBs(void); +extern struct afs_icl_set *afs_icl_allSets; +extern int afs_icl_CreateLog(char *name, afs_int32 logSize, + struct afs_icl_log **outLogpp); +extern int afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, + afs_uint32 flags, + struct afs_icl_log **outLogpp); +extern int afs_icl_CopyOut(register struct afs_icl_log *logp, + afs_int32 * bufferp, afs_int32 * bufSizep, + afs_uint32 * cookiep, afs_int32 * flagsp); +extern int afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 * maxSizep, + afs_int32 * curSizep); +extern int afs_icl_LogHold(register struct afs_icl_log *logp); +extern int afs_icl_LogHoldNL(register struct afs_icl_log *logp); +extern int afs_icl_LogUse(register struct afs_icl_log *logp); +extern int afs_icl_LogFreeUse(register struct afs_icl_log *logp); +extern int afs_icl_LogSetSize(register struct afs_icl_log *logp, + afs_int32 logSize); +extern int afs_icl_ZapLog(register struct afs_icl_log *logp); +extern int afs_icl_LogRele(register struct afs_icl_log *logp); +extern int afs_icl_LogReleNL(register struct afs_icl_log *logp); +extern int afs_icl_ZeroLog(register struct afs_icl_log *logp); +extern int afs_icl_LogFree(register struct afs_icl_log *logp); +extern struct afs_icl_log *afs_icl_FindLog(char *name); +extern int + afs_icl_EnumerateLogs(int (*aproc) + + (char *name, char *arock, struct afs_icl_log * tp), + char *arock); +extern int afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp, + struct afs_icl_log *fatalLogp, + struct afs_icl_set **outSetpp); +extern int afs_icl_CreateSetWithFlags(char *name, + struct afs_icl_log *baseLogp, + struct afs_icl_log *fatalLogp, + afs_uint32 flags, + struct afs_icl_set **outSetpp); +extern int afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, + int setValue); +extern int afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, + int *getValuep); +extern int afs_icl_ZeroSet(struct afs_icl_set *setp); +extern int + afs_icl_EnumerateSets(int (*aproc) + + (char *name, char *arock, struct afs_icl_log * tp), + char *arock); +extern int afs_icl_AddLogToSet(struct afs_icl_set *setp, + struct afs_icl_log *newlogp); +extern int afs_icl_SetSetStat(struct afs_icl_set *setp, int op); +extern int afs_icl_SetHold(register struct afs_icl_set *setp); +extern int afs_icl_ZapSet(register struct afs_icl_set *setp); +extern int afs_icl_SetRele(register struct afs_icl_set *setp); +extern int afs_icl_SetFree(register struct afs_icl_set *setp); +extern struct afs_icl_set *afs_icl_FindSet(char *name); + +extern int afs_icl_Event4(register struct afs_icl_set *setp, + afs_int32 eventID, afs_int32 lAndT, long p1, + long p2, long p3, long p4); +extern int afs_icl_Event3(register struct afs_icl_set *setp, + afs_int32 eventID, afs_int32 lAndT, long p1, + long p2, long p3); +extern int afs_icl_Event2(register struct afs_icl_set *setp, + afs_int32 eventID, afs_int32 lAndT, long p1, + long p2); +extern int afs_icl_Event1(register struct afs_icl_set *setp, + afs_int32 eventID, afs_int32 lAndT, long p1); +extern int afs_icl_Event0(register struct afs_icl_set *setp, + afs_int32 eventID, afs_int32 lAndT); +extern void afs_icl_AppendRecord(register struct afs_icl_log *logp, + afs_int32 op, afs_int32 types, long p1, + long p2, long p3, long p4); + +extern int afs_CheckInit(void); +extern void afs_shutdown(void); +extern void shutdown_afstest(void); +extern void afs_shutdown_BKG(void); + + +/* afs_callback.c */ +extern afs_int32 afs_allCBs; +extern afs_int32 afs_oddCBs; +extern afs_int32 afs_evenCBs; +extern afs_int32 afs_allZaps; +extern afs_int32 afs_oddZaps; +extern afs_int32 afs_evenZaps; +extern afs_int32 afs_connectBacks; +extern unsigned long lastCallBack_vnode; +extern unsigned int lastCallBack_dv; +extern osi_timeval_t lastCallBack_time; +extern struct interfaceAddr afs_cb_interface; + +extern int afs_RXCallBackServer(void); +extern int SRXAFSCB_GetCE(struct rx_call *a_call, afs_int32 a_index, + struct AFSDBCacheEntry *a_result); +extern int SRXAFSCB_GetCE64(struct rx_call *a_call, afs_int32 a_index, + struct AFSDBCacheEntry64 *a_result); +extern int SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index, + struct AFSDBLock *a_result); +extern int SRXAFSCB_CallBack(struct rx_call *a_call, + register struct AFSCBFids *a_fids, + struct AFSCBs *a_callbacks); +extern int SRXAFSCB_Probe(struct rx_call *a_call); +extern int SRXAFSCB_InitCallBackState(struct rx_call *a_call); +extern int SRXAFSCB_XStatsVersion(struct rx_call *a_call, + afs_int32 * a_versionP); +extern int SRXAFSCB_GetXStats(struct rx_call *a_call, + afs_int32 a_clientVersionNum, + afs_int32 a_collectionNumber, + afs_int32 * a_srvVersionNumP, + afs_int32 * a_timeP, AFSCB_CollData * a_dataP); +extern int afs_RXCallBackServer(void); +extern int shutdown_CB(void); +extern int SRXAFSCB_InitCallBackState2(struct rx_call *a_call, + struct interfaceAddr *addr); +extern int SRXAFSCB_WhoAreYou(struct rx_call *a_call, + struct interfaceAddr *addr); +extern int SRXAFSCB_InitCallBackState3(struct rx_call *a_call, + afsUUID * a_uuid); +extern int SRXAFSCB_ProbeUuid(struct rx_call *a_call, afsUUID * a_uuid); +extern int SRXAFSCB_GetServerPrefs(struct rx_call *a_call, afs_int32 a_index, + afs_int32 * a_srvr_addr, + afs_int32 * a_srvr_rank); +extern int SRXAFSCB_GetCellServDB(struct rx_call *a_call, afs_int32 a_index, + char **a_name, serverList * a_hosts); +extern int SRXAFSCB_GetLocalCell(struct rx_call *a_call, char **a_name); +extern int SRXAFSCB_GetCacheConfig(struct rx_call *a_call, + afs_uint32 callerVersion, + afs_uint32 * serverVersion, + afs_uint32 * configCount, + cacheConfig * config); +extern int SRXAFSCB_FetchData(struct rx_call *rxcall, struct AFSFid *Fid, + afs_int32 Fd, afs_int64 Position, + afs_int64 Length, afs_int64 * TotalLength); +extern int SRXAFSCB_StoreData(struct rx_call *rxcall, struct AFSFid *Fid, + afs_int32 Fd, afs_int64 Position, + afs_int64 Length, afs_int64 * TotalLength); + + +/* afs_cbqueue.c */ +extern afs_rwlock_t afs_xcbhash; +extern void afs_QueueCallback(struct vcache *avc, unsigned int atime, + struct volume *avp); +extern void afs_CheckCallbacks(unsigned int secs); +extern void afs_FlushCBs(void); +extern void afs_FlushServerCBs(struct server *srvp); +extern int afs_BumpBase(void); +extern void afs_InitCBQueue(int doLockInit); +extern void afs_DequeueCallback(struct vcache *avc); /* afs_cell.c */ extern afs_rwlock_t afs_xcell; extern void afs_CellInit(void); extern void shutdown_cell(void); extern int afs_cellname_init(ino_t inode, int lookupcode); -extern int afs_cellname_write(); -extern afs_int32 afs_NewCell(char *acellName, afs_int32 *acellHosts, - int aflags, char *linkedcname, u_short fsport, +extern int afs_cellname_write(void); +extern afs_int32 afs_NewCell(char *acellName, afs_int32 * acellHosts, + int aflags, char *linkedcname, u_short fsport, u_short vlport, int timeout); extern afs_int32 afs_SetPrimaryCell(char *acellName); extern struct cell *afs_GetCell(afs_int32 acell, afs_int32 locktype); @@ -34,127 +211,880 @@ extern struct cell *afs_GetCellByName(char *acellName, afs_int32 locktype); extern struct cell *afs_GetPrimaryCell(afs_int32 locktype); extern int afs_IsPrimaryCellNum(afs_int32 cellnum); extern int afs_IsPrimaryCell(struct cell *cell); -extern void *afs_TraverseCells(void *(*cb)(struct cell *, void *), void *arg); +extern void *afs_TraverseCells(void *(*cb) (struct cell *, void *), + void *arg); extern int afs_CellOrAliasExists(char *aname); extern int afs_CellNumValid(afs_int32 cellnum); extern afs_int32 afs_NewCellAlias(char *alias, char *cell); extern struct cell_alias *afs_GetCellAlias(int index); +extern void afs_PutCellAlias(struct cell_alias *a); extern int afs_AFSDBHandler(char *acellName, int acellNameLen, - afs_int32 *kernelMsg); + afs_int32 * kernelMsg); extern void afs_LookupAFSDB(char *acellName); extern void afs_StopAFSDB(void); extern void afs_RemoveCellEntry(struct server *srvp); +/* afs_chunk.c */ +extern afs_int32 afs_FirstCSize; +extern afs_int32 afs_OtherCSize; +extern afs_int32 afs_LogChunk; + +/* afs_cell.c */ +extern struct cell *afs_GetRealCellByIndex(register afs_int32 cellindex, + afs_int32 locktype, + afs_int32 refresh); + /* afs_conn.c */ +extern afs_int32 cryptall; +extern afs_rwlock_t afs_xinterface; +extern afs_rwlock_t afs_xconn; +extern struct conn *afs_Conn(register struct VenusFid *afid, + register struct vrequest *areq, + afs_int32 locktype); extern struct conn *afs_ConnBySA(struct srvAddr *sap, unsigned short aport, - afs_int32 acell, struct unixuser *tu, - int force_if_down, afs_int32 create, afs_int32 locktype); + afs_int32 acell, struct unixuser *tu, + int force_if_down, afs_int32 create, + afs_int32 locktype); +extern struct conn *afs_ConnByMHosts(struct server *ahosts[], + unsigned short aport, afs_int32 acell, + register struct vrequest *areq, + afs_int32 locktype); +extern struct conn *afs_ConnByHost(struct server *aserver, + unsigned short aport, afs_int32 acell, + struct vrequest *areq, int aforce, + afs_int32 locktype); +extern void afs_PutConn(register struct conn *ac, afs_int32 locktype); +extern void ForceNewConnections(struct srvAddr *sap); + + +/* afs_daemons.c */ +extern afs_lock_t afs_xbrs; +extern short afs_brsWaiters; +extern short afs_brsDaemons; +extern struct brequest afs_brs[NBRS]; +extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler; +extern afs_int32 afs_gcpags; +extern afs_int32 afs_gcpags_procsize; +extern afs_int32 afs_CheckServerDaemonStarted; +extern afs_int32 PROBE_INTERVAL; + +extern void afs_Daemon(void); +extern struct brequest *afs_BQueue(register short aopcode, + register struct vcache *avc, + afs_int32 dontwait, afs_int32 ause, + struct AFS_UCRED *acred, + afs_size_t asparm0, afs_size_t asparm1, + void *apparm0); +extern void afs_CheckServerDaemon(void); +extern int afs_CheckRootVolume(void); +extern void afs_BRelease(register struct brequest *ab); +extern int afs_BBusy(void); +extern int afs_BioDaemon(afs_int32 nbiods); +extern void afs_BackgroundDaemon(void); +extern void shutdown_daemons(void); +extern int afs_sgidaemon(void); + /* afs_dcache.c */ +extern u_int afs_min_cache; +extern afs_int32 *afs_dvhashTbl; +extern afs_int32 afs_dhashsize; +extern afs_rwlock_t afs_xdcache; +extern afs_size_t afs_vmMappingEnd; +extern afs_int32 afs_blocksUsed; +extern afs_int32 afs_blocksDiscarded; +extern int afs_WaitForCacheDrain; extern int cacheDiskType; +extern unsigned char *afs_indexFlags; +extern struct afs_cacheOps *afs_cacheType; +extern ino_t cacheInode; +extern struct osi_file *afs_cacheInodep; extern void afs_dcacheInit(int afiles, int ablocks, int aDentries, int achunk, int aflags); +extern int afs_PutDCache(register struct dcache *adc); +extern void afs_FlushDCache(register struct dcache *adc); +extern void shutdown_dcache(void); +extern void afs_CacheTruncateDaemon(void); +extern afs_int32 afs_fsfragsize; +extern struct dcache *afs_MemGetDSlot(register afs_int32 aslot, + register struct dcache *tmpdc); +extern struct dcache *afs_GetDCache(register struct vcache *avc, + afs_size_t abyte, + register struct vrequest *areq, + afs_size_t * aoffset, afs_size_t * alen, + int aflags); +extern struct dcache *afs_FindDCache(register struct vcache *avc, + afs_size_t abyte); +extern void afs_StoreWarn(register afs_int32 acode, afs_int32 avolume, + register afs_int32 aflags); +extern void afs_MaybeWakeupTruncateDaemon(void); +extern void afs_CacheTruncateDaemon(void); +extern void afs_AdjustSize(register struct dcache *adc, + register afs_int32 newSize); +extern int afs_HashOutDCache(struct dcache *adc); +extern int afs_MaybeFreeDiscardedDCache(void); +extern int afs_RefDCache(struct dcache *adc); +extern void afs_TryToSmush(register struct vcache *avc, + struct AFS_UCRED *acred, int sync); +extern void updateV2DC(int lockVc, struct vcache *v, struct dcache *d, + int src); +extern void afs_WriteThroughDSlots(void); +extern struct dcache *afs_UFSGetDSlot(register afs_int32 aslot, + register struct dcache *tmpdc); +extern int afs_WriteDCache(register struct dcache *adc, int atime); +extern int afs_wakeup(register struct vcache *avc); +extern int afs_InitCacheFile(char *afile, ino_t ainode); + + +/* afs_dynroot.c */ +extern int afs_IsDynrootFid(struct VenusFid *fid); +extern void afs_GetDynrootFid(struct VenusFid *fid); +extern int afs_IsDynroot(struct vcache *avc); +extern void afs_DynrootInvalidate(void); +extern void afs_GetDynroot(char **dynrootDir, int *dynrootLen, + struct AFSFetchStatus *status); +extern void afs_PutDynroot(void); +extern int afs_DynrootNewVnode(struct vcache *avc, + struct AFSFetchStatus *status); +extern int afs_SetDynrootEnable(int enable); +extern int afs_GetDynrootEnable(void); +extern int afs_DynrootVOPRemove(struct vcache *avc, struct AFS_UCRED *acred, + char *aname); +extern int afs_DynrootVOPSymlink(struct vcache *avc, struct AFS_UCRED *acred, + char *aname, char *atargetName); + +/* afs_exporter.c */ +extern struct afs_exporter *root_exported; +extern struct afs_exporter *exporter_find(int type); + +/* afs_init.c */ +extern struct cm_initparams cm_initParams; +extern int afs_resourceinit_flag; +extern afs_rwlock_t afs_puttofileLock; +extern char *afs_sysname; +extern char *afs_sysnamelist[MAXNUMSYSNAMES]; +extern int afs_sysnamecount; +extern afs_int32 cacheInfoModTime; +extern int afs_CacheInit(afs_int32 astatSize, afs_int32 afiles, + afs_int32 ablocks, afs_int32 aDentries, + afs_int32 aVolumes, afs_int32 achunk, + afs_int32 aflags, afs_int32 ninodes, + afs_int32 nusers); +extern void afs_ComputeCacheParms(void); +extern int afs_InitCacheInfo(register char *afile); +extern int afs_InitVolumeInfo(char *afile); +extern int afs_InitCellInfo(char *afile); +extern int afs_ResourceInit(int preallocs); +extern void shutdown_cache(void); +extern void shutdown_vnodeops(void); +extern void shutdown_AFS(void); + +/* afs_lock.c */ +extern void Lock_Init(register struct afs_lock *lock); +extern void ObtainLock(register struct afs_lock *lock, int how, + unsigned int src_indicator); +extern void ReleaseLock(register struct afs_lock *lock, int how); +extern int Afs_Lock_Trace(int op, struct afs_lock *alock, int type, + char *file, int line); +extern void Afs_Lock_Obtain(register struct afs_lock *lock, int how); +extern void Afs_Lock_ReleaseR(register struct afs_lock *lock); +extern void Afs_Lock_ReleaseW(register struct afs_lock *lock); +extern void afs_osi_SleepR(register char *addr, + register struct afs_lock *alock); +extern void afs_osi_SleepW(register char *addr, + register struct afs_lock *alock); +extern void afs_osi_SleepS(register char *addr, + register struct afs_lock *alock); +#ifndef AFS_NOBOZO_LOCK +extern void afs_BozonLock(struct afs_bozoLock *alock, struct vcache *avc); +extern void afs_BozonUnlock(struct afs_bozoLock *alock, struct vcache *avc); +extern void afs_BozonInit(struct afs_bozoLock *alock, struct vcache *avc); +extern int afs_CheckBozonLock(struct afs_bozoLock *alock); +extern int afs_CheckBozonLockBlocking(struct afs_bozoLock *alock); +#endif + + + + +/* afs_mariner.c */ +extern afs_int32 afs_mariner; +extern afs_int32 afs_marinerHost; +extern struct rx_service *afs_server; +extern int afs_AddMarinerName(register char *aname, + register struct vcache *avc); +extern char *afs_GetMariner(register struct vcache *avc); +extern void afs_MarinerLogFetch(register struct vcache *avc, + register afs_int32 off, + register afs_int32 bytes, + register afs_int32 idx); +extern void afs_MarinerLog(register char *astring, + register struct vcache *avc); +extern void shutdown_mariner(void); + /* afs_memcache.c */ +extern int afs_InitMemCache(int blkCount, int blkSize, int flags); +extern int afs_MemCacheClose(char *file); extern void *afs_MemCacheOpen(ino_t blkno); +extern int afs_MemReadBlk(register struct memCacheEntry *mceP, int offset, + char *dest, int size); +extern int afs_MemReadvBlk(register struct memCacheEntry *mceP, int offset, + struct iovec *iov, int nio, int size); +extern int afs_MemReadUIO(ino_t blkno, struct uio *uioP); +extern int afs_MemWriteBlk(register struct memCacheEntry *mceP, int offset, + char *src, int size); +extern int afs_MemWritevBlk(register struct memCacheEntry *mceP, int offset, + struct iovec *iov, int nio, int size); +extern int afs_MemWriteUIO(ino_t blkno, struct uio *uioP); +extern int afs_MemCacheTruncate(register struct memCacheEntry *mceP, + int size); +extern int afs_MemCacheStoreProc(register struct rx_call *acall, + register struct memCacheEntry *mceP, + register afs_int32 alen, struct vcache *avc, + int *shouldWake, afs_size_t * abytesToXferP, + afs_size_t * abytesXferredP, + afs_int32 length); +extern int afs_MemCacheFetchProc(register struct rx_call *acall, + register struct memCacheEntry *mceP, + afs_size_t abase, struct dcache *adc, + struct vcache *avc, + afs_size_t * abytesToXferP, + afs_size_t * abytesXferredP, + afs_int32 lengthFound); +extern void shutdown_memcache(void); + + +/* afs_nfsclnt.c */ +extern struct afs_exporter *afs_nfsexported; +extern struct afs_exporter *afs_nfsexporter; /* afs_osi.c */ -#if AFS_GCPAGS -extern const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC *pr); +extern afs_lock_t afs_ftf; +extern void afs_osi_Invisible(void); +extern void afs_osi_RxkRegister(void); +extern void afs_osi_MaskSignals(void); +extern void afs_osi_UnmaskRxkSignals(void); +extern void *afs_osi_Alloc_debug(size_t x, char *func, int line); +#ifndef afs_osi_Alloc_NoSleep +extern void *afs_osi_Alloc_NoSleep(size_t x); +#endif +#ifndef afs_osi_Free +extern void afs_osi_Free(void *x, size_t asize); +#endif +extern void afs_osi_FreeStr(char *x); +extern void osi_Init(void); +extern int osi_Active(register struct vcache *avc); +extern void osi_FlushPages(register struct vcache *avc, + struct AFS_UCRED *credp); +extern void osi_FlushText_really(register struct vcache *vp); +extern void afs_osi_MaskSignals(void); +extern void afs_osi_UnmaskRxkSignals(void); +extern void afs_osi_RxkRegister(void); +extern void afs_osi_Invisible(void); +extern int osi_VMDirty_p(struct vcache *avc); +#ifndef UKERNEL +extern void osi_ReleaseVM(struct vcache *avc, struct AFS_UCRED *acred); +#endif +extern void shutdown_osi(void); +extern int afs_osi_suser(void *credp); extern void afs_osi_TraverseProcTable(void); -#endif /* AFS_GCPAGS */ +#if defined(KERNEL) && !defined(UKERNEL) && defined(AFS_PROC) +extern const struct AFS_UCRED *afs_osi_proc2cred(AFS_PROC * pr); +#endif /* afs_osi_pag.c */ +extern int afs_setpag(); extern afs_uint32 genpag(void); extern afs_uint32 getpag(void); -#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) extern int AddPag(struct proc *p, afs_int32 aval, struct AFS_UCRED **credpp); -#else /* AFS_OSF_ENV || AFS_FBSD_ENV */ +#else extern int AddPag(afs_int32 aval, struct AFS_UCRED **credpp); #endif -extern afs_uint32 afs_get_pag_from_groups(gid_t g0, gid_t g1); -extern void afs_get_groups_from_pag(afs_uint32 pag, gid_t *g0p, gid_t *g1p); +extern int afs_InitReq(register struct vrequest *av, struct AFS_UCRED *acred); +extern afs_uint32 afs_get_pag_from_groups(gid_t g0a, gid_t g1a); +extern void afs_get_groups_from_pag(afs_uint32 pag, gid_t * g0p, gid_t * g1p); extern afs_int32 PagInCred(const struct AFS_UCRED *cred); -/* OS/osi_sleep.c */ +/* afs_osi_alloc.c */ +#ifndef AFS_FBSD_ENV +extern afs_int32 afs_preallocs; +extern afs_lock_t osi_fsplock; +extern afs_lock_t osi_flplock; +#endif +extern void osi_FreeLargeSpace(void *adata); +extern void osi_FreeMediumSpace(void *adata); +extern void osi_FreeSmallSpace(void *adata); +extern void *osi_AllocLargeSpace(size_t size); +extern void *osi_AllocMediumSpace(size_t size); +extern void *osi_AllocSmallSpace(size_t size); +#ifndef osi_AllocSmall +extern char *osi_AllocSmall(register afs_int32 size, + register afs_int32 morespace); +#endif + +/* afs_osi_uio.c */ +extern int afsio_copy(struct uio *ainuio, struct uio *aoutuio, + struct iovec *aoutvec); +extern int afsio_trim(struct uio *auio, afs_int32 asize); +extern int afsio_skip(struct uio *auio, afs_int32 asize); + + + +/* ARCH/osi_misc.c */ +extern void osi_iput(struct inode *ip); +extern void afs_osi_SetTime(osi_timeval_t * atv); + +/* LINUX/osi_misc.c */ +#ifdef AFS_LINUX20_ENV +#ifdef AFS_LINUX24_ENV +extern int osi_lookupname(char *aname, uio_seg_t seg, int followlink, + vnode_t ** dirvpp, struct dentry **dpp); +extern int osi_InitCacheInfo(char *aname); +extern int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, + size_t asize, size_t * resid); +extern int osi_file_uio_rdwr(struct osi_file *osifile, uio_t * uiop, int rw); +extern void setup_uio(uio_t * uiop, struct iovec *iovecp, char *buf, + afs_offs_t pos, int count, uio_flag_t flag, + uio_seg_t seg); +extern int uiomove(char *dp, int length, uio_flag_t rw, uio_t * uiop); +extern void osi_linux_free_inode_pages(void); +extern void osi_clear_inode(struct inode *ip); +extern void check_bad_parent(struct dentry *dp); +#endif +extern void osi_linux_mask(void); +extern void osi_linux_unmask(void); +extern void osi_linux_rxkreg(void); +extern int setpag(cred_t ** cr, afs_uint32 pagvalue, afs_uint32 * newpag, + int change_parent); +#endif + + +/* ARCH/osi_sleep.c */ extern void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle); extern void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle); -extern int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok); +extern int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, + int aintok); +#ifndef afs_osi_Wakeup +extern int afs_osi_Wakeup(void *event); +#endif +#ifndef afs_osi_Sleep +extern void afs_osi_Sleep(void *event); +#endif +#ifndef afs_osi_SleepSig +extern int afs_osi_SleepSig(void *event); +#endif + + +/* ARCH/osi_inode.c */ +extern int afs_syscall_icreate(); +extern int afs_syscall_iopen(); +extern int afs_syscall_iincdec(); + + +/* ARCH/osi_file.c */ +extern int afs_osicred_initialized; +#if defined(AFS_SUN57_64BIT_ENV) || defined(AFS_SGI62_ENV) +extern void *osi_UFSOpen(ino_t ainode); +#else +extern void *osi_UFSOpen(afs_int32 ainode); +#endif +extern int afs_osi_Stat(register struct osi_file *afile, + register struct osi_stat *astat); +extern int osi_UFSClose(register struct osi_file *afile); +extern int osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize); +extern void osi_DisableAtimes(struct vnode *avp); +extern int afs_osi_Read(register struct osi_file *afile, int offset, + void *aptr, afs_int32 asize); +extern int afs_osi_Write(register struct osi_file *afile, afs_int32 offset, + void *aptr, afs_int32 asize); +extern int afs_osi_MapStrategy(int (*aproc) (struct buf * bp), + register struct buf *bp); +extern void shutdown_osifile(void); + + +/* ARCH/osi_groups.c */ +#ifdef AFS_XBSD_ENV +extern int setpag(struct proc *proc, struct ucred **cred, afs_uint32 pagvalue, + afs_uint32 * newpag, int change_parent); +#endif + + +/* ARCH/osi_vm.c */ +extern int osi_VM_FlushVCache(struct vcache *avc, int *slept); +extern void osi_VM_StoreAllSegments(struct vcache *avc); +extern void osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, + int sync); +extern void osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp); +extern void osi_VM_Truncate(struct vcache *avc, int alen, + struct AFS_UCRED *acred); +extern void osi_VM_TryReclaim(struct vcache *avc, int *slept); +extern void osi_VM_NukePages(struct vnode *vp, off_t offset, off_t size); +extern int osi_VM_Setup(struct vcache *avc, int force); + +#ifdef AFS_SUN5_ENV +extern int osi_VM_GetDownD(struct vcache *avc, struct dcache *adc); +extern void osi_VM_PreTruncate(struct vcache *avc, int alen, + struct AFS_UCRED *acred); +#endif + + +/* ARCH/osi_vnodeops.c */ +extern struct vnodeops Afs_vnodeops; +#if defined(AFS_OSF_ENV) +#if defined(AFS_OSF30_ENV) +extern int max_vnodes; /* number of total system vnodes */ +#else +extern int nvnode; /* number of total system vnodes */ +extern int numvnodes; /* number vnodes in use now */ +#endif +#ifdef AFS_DUX40_ENV +extern struct vfs_ubcops afs_ubcops; +#endif +#endif /* afs_osifile.c */ -#ifdef AFS_SGI62_ENV -extern void *osi_UFSOpen(ino_t); + +/* afs_osi_pag.c */ +extern afs_uint32 pag_epoch; +extern afs_uint32 pagCounter; + +/* OS/osi_vfsops.c */ +#if defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV) +extern struct mount *afs_globalVFS; #else -extern void *osi_UFSOpen(); +extern struct vfs *afs_globalVFS; +#endif +extern struct vcache *afs_globalVp; +#ifdef AFS_LINUX20_ENV +extern void vcache2inode(struct vcache *avc); #endif +/* afs_pioctl.c */ +extern struct VenusFid afs_rootFid; +extern afs_int32 afs_waitForever; +extern short afs_waitForeverCount; +extern afs_int32 afs_showflags; +extern int afs_defaultAsynchrony; +extern int afs_syscall_pioctl(); + +/* afs_segments.c */ +extern int afs_StoreMini(register struct vcache *avc, struct vrequest *areq); +extern int afs_StoreAllSegments(register struct vcache *avc, + struct vrequest *areq, int sync); +extern int afs_InvalidateAllSegments(struct vcache *avc); +extern int afs_TruncateAllSegments(register struct vcache *avc, + afs_size_t alen, struct vrequest *areq, + struct AFS_UCRED *acred); + /* afs_server.c */ -extern struct server *afs_FindServer (afs_int32 aserver, ushort aport, - afsUUID *uuidp, afs_int32 locktype); -extern struct server *afs_GetServer(afs_uint32 *aserver, afs_int32 nservers, +extern afs_rwlock_t afs_xsrvAddr; +extern afs_rwlock_t afs_xserver; +extern afs_rwlock_t afs_icl_lock; +extern struct srvAddr *afs_srvAddrs[NSERVERS]; +extern struct server *afs_servers[NSERVERS]; +extern int afs_totalServers; +extern struct server *afs_setTimeHost; +extern struct server *afs_FindServer(afs_int32 aserver, ushort aport, + afsUUID * uuidp, afs_int32 locktype); +extern struct server *afs_GetServer(afs_uint32 * aserver, afs_int32 nservers, afs_int32 acell, u_short aport, - afs_int32 locktype, afsUUID *uuidp, + afs_int32 locktype, afsUUID * uuidp, afs_int32 addr_uniquifier); extern void afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown); extern void afs_ServerDown(struct srvAddr *sa); +extern void afs_CountServers(void); +extern void afs_CheckServers(int adown, struct cell *acellp); +extern unsigned int afs_random(void); +extern int afs_randomMod15(void); +extern int afs_randomMod127(void); +extern void afs_SortOneServer(struct server *asp); +extern void afs_SortServers(struct server *aservers[], int count); +extern void afs_FlushServer(struct server *srvp); +extern void afs_RemoveSrvAddr(struct srvAddr *sap); +extern void afs_ActivateServer(struct srvAddr *sap); +#ifdef AFS_USERSPACE_IP_ADDR +extern int afsi_SetServerIPRank(struct srvAddr *sa, afs_int32 addr, + afs_uint32 subnetmask); +#else +#if (!defined(AFS_SUN5_ENV)) && defined(USEIFADDR) +void afsi_SetServerIPRank(struct srvAddr *sa, struct in_ifaddr *ifa); +#endif +#endif + + + +/* afs_osidnlc.c */ +extern int osi_dnlc_enter(struct vcache *adp, char *aname, struct vcache *avc, + afs_hyper_t * avno); +extern struct vcache *osi_dnlc_lookup(struct vcache *adp, char *aname, + int locktype); +extern int osi_dnlc_remove(struct vcache *adp, char *aname, + struct vcache *avc); +extern int osi_dnlc_purgedp(struct vcache *adp); +extern int osi_dnlc_purgevp(struct vcache *avc); +extern int osi_dnlc_purge(void); +extern int osi_dnlc_purgevol(struct VenusFid *fidp); +extern int osi_dnlc_init(void); +extern int osi_dnlc_shutdown(void); + + +/* afs_stat.c */ +extern struct afs_CMStats afs_cmstats; +extern struct afs_stats_CMPerf afs_stats_cmperf; +extern struct afs_stats_CMFullPerf afs_stats_cmfullperf; +extern afs_int32 afs_stats_XferSumBytes[AFS_STATS_NUM_FS_XFER_OPS]; +extern void afs_InitStats(void); +extern void afs_GetCMStat(char **ptr, unsigned *size); +#ifndef AFS_NOSTATS +extern void afs_AddToMean(struct afs_MeanStats *oldMean, afs_int32 newValue); +#endif + + +/* UKERNEL/afs_usrops.c */ +#ifdef UKERNEL +extern void uafs_Shutdown(void); +extern void osi_ReleaseVM(struct vcache *avc, int len, + struct usr_ucred *credp); +extern int osi_GetTime(struct timeval *tv); +#endif + + /* afs_user.c */ -extern struct unixuser *afs_FindUser(afs_int32 auid, afs_int32 acell, afs_int32 locktype); +extern afs_rwlock_t afs_xuser; +extern struct unixuser *afs_users[NUSERS]; +extern struct unixuser *afs_FindUser(afs_int32 auid, afs_int32 acell, + afs_int32 locktype); +extern struct unixuser *afs_GetUser(register afs_int32 auid, afs_int32 acell, + afs_int32 locktype); #if AFS_GCPAGS -extern afs_int32 afs_GCPAGs(afs_int32 *ReleasedCount); -extern void afs_GCPAGs_perproc_func(AFS_PROC *pproc); +extern afs_int32 afs_GCPAGs(afs_int32 * ReleasedCount); +extern void afs_GCPAGs_perproc_func(AFS_PROC * pproc); #endif /* AFS_GCPAGS */ +extern void afs_ComputePAGStats(void); +extern void afs_PutUser(register struct unixuser *au, afs_int32 locktype); +extern void afs_GCUserData(int aforce); +extern void afs_CheckTokenCache(void); +extern void afs_ResetAccessCache(afs_int32 uid, int alock); +extern void afs_ResetUserConns(register struct unixuser *auser); +extern void afs_SetPrimary(register struct unixuser *au, register int aflag); + /* afs_util.c */ +#ifndef afs_cv2string extern char *afs_cv2string(char *ttp, afs_uint32 aval); +#endif +#ifndef afs_strcasecmp extern int afs_strcasecmp(char *s1, char *s2); +#endif +#ifndef afs_strcat +extern char *afs_strcat(char *s1, char *s2); +#endif +#ifdef AFS_OBSD34_ENV +extern char *afs_strcpy(char *s1, char *s2); +#endif +#ifndef afs_strchr extern char *afs_strchr(char *s, int c); +#endif extern char *afs_strdup(char *s); extern void print_internet_address(char *preamble, struct srvAddr *sa, - char *postamble, int flag); + char *postamble, int flag); +extern afs_int32 afs_data_pointer_to_int32(const void *p); + +#if 0 /* problems - need to change to varargs, right now is incorrect usage + * throughout code */ +extern void afs_warn(char *a, long b, long c, long d, long e, long f, long g, + long h, long i, long j); +extern void afs_warnuser(char *a, long b, long c, long d, long e, long f, + long g, long h, long i, long j); +#else +extern void afs_warn(); +extern void afs_warnuser(); +#endif +extern void afs_CheckLocks(void); +extern int afs_badop(void); +extern int afs_noop(void); extern afs_int32 afs_data_pointer_to_int32(const void *p); + /* afs_vcache.c */ +extern afs_int32 afs_maxvcount; +extern afs_int32 afs_vcount; +extern int afsvnumbers; +extern afs_rwlock_t afs_xvcache; +extern afs_lock_t afs_xvcb; +extern struct vcache *freeVCList; +extern struct vcache *Initial_freeVCList; +extern struct afs_q VLRU; +extern afs_int32 vcachegen; +extern unsigned int afs_paniconwarn; +extern struct vcache *afs_vhashT[VCSIZE]; +extern afs_int32 afs_bulkStatsLost; +extern int afs_norefpanic; + void afs_vcacheInit(int astatSize); -extern struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit, - afs_int32 locktype, afs_int32 *retry, afs_int32 flag); +extern struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, + afs_int32 flag); extern afs_int32 afs_FetchStatus(struct vcache *avc, struct VenusFid *afid, - struct vrequest *areq, - struct AFSFetchStatus *Outsp); + struct vrequest *areq, + struct AFSFetchStatus *Outsp); extern afs_int32 afs_FlushVCBs(afs_int32 lockit); extern void afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred); extern struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq, - afs_int32 *cached, afs_int32 locktype, - struct vcache *adp, char *aname); + afs_int32 * cached, struct vcache *adp, + char *aname); extern int afs_FlushVCache(struct vcache *avc, int *slept); extern struct vcache *afs_GetRootVCache(struct VenusFid *afid, - struct vrequest *areq, afs_int32 *cached, - struct volume *tvolp, afs_int32 locktype); + struct vrequest *areq, + afs_int32 * cached, + struct volume *tvolp); extern struct vcache *afs_NewVCache(struct VenusFid *afid, - struct server *serverp, - afs_int32 lockit, afs_int32 locktype); + struct server *serverp); extern int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq); +extern struct vcache *afs_GetVCache(register struct VenusFid *afid, + struct vrequest *areq, afs_int32 * cached, + struct vcache *avc); +extern void afs_PutVCache(register struct vcache *avc); +extern void afs_ProcessFS(register struct vcache *avc, + register struct AFSFetchStatus *astat, + struct vrequest *areq); +extern struct afs_cbr *afs_AllocCBR(void); +extern int afs_FreeCBR(register struct afs_cbr *asp); +extern void afs_RemoveVCB(register struct VenusFid *afid); +extern void afs_FlushActiveVcaches(register afs_int32 doflocks); +extern int afs_WriteVCache(register struct vcache *avc, + register struct AFSStoreStatus *astatus, + struct vrequest *areq); +extern int afs_RemoteLookup(register struct VenusFid *afid, + struct vrequest *areq, char *name, + struct VenusFid *nfid, + struct AFSFetchStatus *OutStatusp, + struct AFSCallBack *CallBackp, + struct server **serverp, + struct AFSVolSync *tsyncp); +extern afs_int32 afs_NFSFindVCache(struct vcache **avcp, + struct VenusFid *afid); +extern void afs_vcacheInit(int astatSize); +extern void shutdown_vcache(void); +/* VNOPS/afs_vnop_access.c */ +extern afs_int32 afs_GetAccessBits(register struct vcache *avc, + register afs_int32 arights, + register struct vrequest *areq); +extern int afs_AccessOK(struct vcache *avc, afs_int32 arights, + struct vrequest *areq, afs_int32 check_mode_bits); +#if defined(AFS_SUN5_ENV) || (defined(AFS_SGI_ENV) && !defined(AFS_SGI65_ENV)) +extern int afs_access(OSI_VC_DECL(avc), register afs_int32 amode, int flags, + struct AFS_UCRED *acred); +#else +extern int afs_access(OSI_VC_DECL(avc), register afs_int32 amode, + struct AFS_UCRED *acred); +#endif +extern int afs_getRights(OSI_VC_DECL(avc), register afs_int32 arights, + struct AFS_UCRED *acred); + +/* VNOPS/afs_vnop_attrs.c */ +extern int afs_CopyOutAttrs(register struct vcache *avc, + register struct vattr *attrs); +#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) +extern int afs_getattr(OSI_VC_DECL(avc), struct vattr *attrs, int flags, + struct AFS_UCRED *acred); +#else +extern int afs_getattr(OSI_VC_DECL(avc), struct vattr *attrs, + struct AFS_UCRED *acred); +#endif +extern int afs_VAttrToAS(register struct vcache *avc, + register struct vattr *av, + register struct AFSStoreStatus *as); +#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) +extern int afs_setattr(OSI_VC_DECL(avc), register struct vattr *attrs, + int flags, struct AFS_UCRED *acred); +#else +extern int afs_setattr(OSI_VC_DECL(avc), register struct vattr *attrs, + struct AFS_UCRED *acred); +#endif + +/* VNOPS/afs_vnop_create.c */ +#ifdef AFS_OSF_ENV +extern int afs_create(struct nameidata *ndp, struct vattr *attrs); +#else /* AFS_OSF_ENV */ +#ifdef AFS_SGI64_ENV +extern int afs_create(OSI_VC_DECL(adp), char *aname, struct vattr *attrs, + int flags, int amode, struct vcache **avcp, + struct AFS_UCRED *acred); +#else /* AFS_SGI64_ENV */ +extern int afs_create(OSI_VC_DECL(adp), char *aname, struct vattr *attrs, + enum vcexcl aexcl, int amode, struct vcache **avcp, + struct AFS_UCRED *acred); +#endif /* AFS_SGI64_ENV */ +#endif /* AFS_OSF_ENV */ +extern int afs_LocalHero(register struct vcache *avc, + register struct dcache *adc, + register AFSFetchStatus * astat, register int aincr); + + +/* VNOPS/afs_vnop_flock.c */ +extern void lockIdSet(struct AFS_FLOCK *flock, struct SimpleLocks *slp, + int clid); +extern int HandleFlock(register struct vcache *avc, int acom, + struct vrequest *areq, pid_t clid, int onlymine); + + + +/* VNOPS/afs_vnop_lookup.c */ +extern int EvalMountPoint(register struct vcache *avc, struct vcache *advc, + struct volume **avolpp, + register struct vrequest *areq); +extern void afs_InitFakeStat(struct afs_fakestat_state *state); +extern int afs_EvalFakeStat(struct vcache **avcp, + struct afs_fakestat_state *state, + struct vrequest *areq); +extern int afs_TryEvalFakeStat(struct vcache **avcp, + struct afs_fakestat_state *state, + struct vrequest *areq); +extern void afs_PutFakeStat(struct afs_fakestat_state *state); +extern int afs_ENameOK(register char *aname); +extern void Check_AtSys(register struct vcache *avc, char *aname, + struct sysname_info *state, struct vrequest *areq); +extern int Next_AtSys(register struct vcache *avc, struct vrequest *areq, + struct sysname_info *state); +extern int afs_DoBulkStat(struct vcache *adp, long dirCookie, + struct vrequest *areqp); +extern int afs_lookup(); + + +/* VNOPS/afs_vnop_open.c */ +#ifdef AFS_SGI64_ENV +extern int afs_open(bhv_desc_t * bhv, struct vcache **avcp, afs_int32 aflags, + struct AFS_UCRED *acred); +#else +extern int afs_open(struct vcache **avcp, afs_int32 aflags, + struct AFS_UCRED *acred); +#endif + + +/* VNOPS/afs_vnop_read.c */ +extern afs_int32 maxIHint; +extern afs_int32 nihints; +extern afs_int32 usedihint; +extern int afs_MemRead(register struct vcache *avc, struct uio *auio, + struct AFS_UCRED *acred, daddr_t albn, + struct buf **abpp, int noLock); +extern int afs_UFSRead(register struct vcache *avc, struct uio *auio, + struct AFS_UCRED *acred, daddr_t albn, + struct buf **abpp, int noLock); + + +/* VNOPS/afs_vnop_readdir.c */ +extern int afs_rd_stash_i; + + +/* VNOPS/afs_vnop_remove.c */ +extern int afsremove(register struct vcache *adp, register struct dcache *tdc, + register struct vcache *tvc, char *aname, + struct AFS_UCRED *acred, struct vrequest *treqp); +extern int afs_remunlink(register struct vcache *avc, register int doit); + + +/* VNOPS/afs_vnop_rename.c */ +extern int afsrename(struct vcache *aodp, char *aname1, struct vcache *andp, + char *aname2, struct AFS_UCRED *acred, + struct vrequest *areq); + + +/* VNOPS/afs_vnop_symlink.c */ +extern int afs_MemHandleLink(register struct vcache *avc, + struct vrequest *areq); +extern int afs_UFSHandleLink(register struct vcache *avc, + struct vrequest *areq); + +/* VNOPS/afs_vnop_flock.c */ +extern afs_int32 lastWarnTime; + +/* VNOPS/afs_vnop_write.c */ +extern int afs_MemWrite(register struct vcache *avc, struct uio *auio, + int aio, struct AFS_UCRED *acred, int noLock); +extern int afs_StoreOnLastReference(register struct vcache *avc, + register struct vrequest *treq); +extern int afs_UFSWrite(register struct vcache *avc, struct uio *auio, + int aio, struct AFS_UCRED *acred, int noLock); +extern int afs_DoPartialWrite(register struct vcache *avc, + struct vrequest *areq); +extern int afs_closex(register struct file *afd); + +/* other VNOPS (please fix these) */ +extern int afs_close(); +extern int HandleIoctl(); +extern int afs_fsync(); +extern int afs_remove(); +extern int afs_link(); +extern int afs_rename(); +extern int afs_mkdir(); +extern int afs_rmdir(); +extern int afs_symlink(); +extern int afs_readdir(); +extern int afs_readlink(); +extern int afs_ustrategy(); +extern int afs_lockctl(); + /* afs_volume.c */ -extern struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype); +extern afs_int32 afs_FVIndex; +extern afs_int32 afs_volCounter; +extern afs_rwlock_t afs_xvolume; +extern struct volume *afs_volumes[NVOLS]; +extern ino_t volumeInode; +extern struct volume *afs_FindVolume(struct VenusFid *afid, + afs_int32 locktype); +extern struct volume *afs_freeVolList; +extern afs_int32 fvTable[NFENTRIES]; extern void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell); extern void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, - int acell); + int acell); extern void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, - int acell, struct cell *tcell, struct vrequest *areq); + int acell, struct cell *tcell, + struct vrequest *areq); extern void afs_ResetVolumeInfo(struct volume *tv); +extern struct volume *afs_MemGetVolSlot(void); +extern void afs_ResetVolumes(struct server *srvp); +extern struct volume *afs_GetVolume(struct VenusFid *afid, + struct vrequest *areq, + afs_int32 locktype); +extern struct volume *afs_GetVolumeByName(register char *aname, + afs_int32 acell, int agood, + struct vrequest *areq, + afs_int32 locktype); +extern struct volume *afs_UFSGetVolSlot(void); +extern void afs_CheckVolumeNames(int flags); -#if defined(AFS_SUN5_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_AIX_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -#include "../afs/osi_prototypes.h" -#endif +/* Prototypes for generated files that aren't really in src/afs/ */ + +/* afs_uuid.c */ +extern afs_int32 afs_uuid_equal(afsUUID * u1, afsUUID * u2); +extern afs_int32 afs_uuid_is_nil(afsUUID * u1); +extern void afs_htonuuid(afsUUID * uuidp); +extern void afs_ntohuuid(afsUUID * uuidp); +extern afs_int32 afs_uuid_create(afsUUID * uuid); +extern u_short afs_uuid_hash(afsUUID * uuid); + + +/* MISC PROTOTYPES - THESE SHOULD NOT BE HERE */ +/* MOVE THEM TO APPROPRIATE LOCATIONS */ +extern afs_int32 RXAFSCB_ExecuteRequest(struct rx_call *acall); +extern afs_int32 RXSTATS_ExecuteRequest(struct rx_call *acall); -#endif /* _AFS_PROTOTYPES_H_ */ + +#if defined(AFS_SUN5_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_AIX_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_SGI62_ENV) +#include "osi_prototypes.h" +#endif + +#endif /* _AFS_PROTOTYPES_H_ */ diff --git a/src/afs/afs_segments.c b/src/afs/afs_segments.c index 5140df4d3..b1f212a3c 100644 --- a/src/afs/afs_segments.c +++ b/src/afs/afs_segments.c @@ -11,30 +11,18 @@ * --------------------- Required definitions --------------------- */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_segments.c,v 1.1.1.8 2004/01/10 20:52:47 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_segments.c,v 1.16 2003/07/15 23:14:13 shadow Exp $"); -#include "../afs/sysincludes.h" /*Standard vendor system headers*/ -#include "../afs/afsincludes.h" /*AFS-based standard headers*/ -#include "../afs/afs_stats.h" /* statistics */ -#include "../afs/afs_cbqueue.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /*Standard vendor system headers */ +#include "afsincludes.h" /*AFS-based standard headers */ +#include "afs/afs_stats.h" /* statistics */ +#include "afs/afs_cbqueue.h" +#include "afs/afs_osidnlc.h" - - -/* Imported variables */ -extern afs_rwlock_t afs_xserver; -extern afs_rwlock_t afs_xdcache; -extern afs_rwlock_t afs_xcbhash; -extern afs_lock_t afs_ftf; -extern struct server *afs_servers[NSERVERS]; -extern afs_int32 afs_dhashsize; -extern afs_int32 *afs_dvhashTbl; -extern unsigned char *afs_indexFlags; /*(only one) Is there data there?*/ -extern int cacheDiskType; - -afs_uint32 afs_stampValue=0; +afs_uint32 afs_stampValue = 0; /* * afs_StoreMini @@ -49,80 +37,98 @@ afs_uint32 afs_stampValue=0; * We're write-locked upon entry. */ -int afs_StoreMini(avc, areq) - register struct vcache *avc; - struct vrequest *areq; - -{ /*afs_StoreMini*/ +int +afs_StoreMini(register struct vcache *avc, struct vrequest *areq) +{ register struct conn *tc; struct AFSStoreStatus InStatus; struct AFSFetchStatus OutStatus; struct AFSVolSync tsync; register afs_int32 code; register struct rx_call *tcall; - afs_int32 tlen; - XSTATS_DECLS - - AFS_STATCNT(afs_StoreMini); + afs_size_t tlen, xlen = 0; + XSTATS_DECLS AFS_STATCNT(afs_StoreMini); afs_Trace2(afs_iclSetp, CM_TRACE_STOREMINI, ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, avc->m.Length); tlen = avc->m.Length; - if (avc->truncPos < tlen) tlen = avc->truncPos; + if (avc->truncPos < tlen) + tlen = avc->truncPos; avc->truncPos = AFS_NOTRUNC; avc->states &= ~CExtendedFile; do { tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); if (tc) { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + retry: tcall = rx_NewCall(tc->id); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); /* Set the client mod time since we always want the file - * to have the client's mod time and not the server's one - * (to avoid problems with make, etc.) It almost always - * works fine with standard afs because them server/client - * times are in sync and more importantly this storemini - * it's a special call that would typically be followed by - * the proper store-data or store-status calls. - */ + * to have the client's mod time and not the server's one + * (to avoid problems with make, etc.) It almost always + * works fine with standard afs because them server/client + * times are in sync and more importantly this storemini + * it's a special call that would typically be followed by + * the proper store-data or store-status calls. + */ InStatus.Mask = AFS_SETMODTIME; InStatus.ClientModTime = avc->m.Date; XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = StartRXAFS_StoreData(tcall, - (struct AFSFid *)&avc->fid.Fid, - &InStatus, avc->m.Length, 0, tlen); + afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64, ICL_TYPE_FID, + &avc->fid.Fid, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(avc->m.Length), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(xlen), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(tlen)); + RX_AFS_GUNLOCK(); +#ifdef AFS_64BIT_CLIENT + if (!afs_serverHasNo64Bit(tc)) { + code = + StartRXAFS_StoreData64(tcall, + (struct AFSFid *)&avc->fid.Fid, + &InStatus, avc->m.Length, + (afs_size_t) 0, tlen); + } else { + afs_int32 l1, l2; + l1 = avc->m.Length; + l2 = tlen; + code = + StartRXAFS_StoreData(tcall, + (struct AFSFid *)&avc->fid.Fid, + &InStatus, l1, 0, l2); + } +#else /* AFS_64BIT_CLIENT */ + code = + StartRXAFS_StoreData(tcall, (struct AFSFid *)&avc->fid.Fid, + &InStatus, avc->m.Length, 0, tlen); +#endif /* AFS_64BIT_CLIENT */ if (code == 0) { code = EndRXAFS_StoreData(tcall, &OutStatus, &tsync); +#ifdef AFS_64BIT_CLIENT + if (code == RXGEN_OPCODE) { + afs_serverSetNo64Bit(tc); + code = rx_EndCall(tcall, code); + goto retry; + } +#endif /* AFS_64BIT_CLIENT */ } code = rx_EndCall(tcall, code); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_STOREDATA, - SHARED_LOCK, (struct cell *)0)); + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREDATA, + SHARED_LOCK, NULL)); if (code == 0) { afs_ProcessFS(avc, &OutStatus, areq); - } - else { + } else { /* blew it away */ - afs_InvalidateAllSegments(avc, 1); + afs_InvalidateAllSegments(avc); } return code; -} /*afs_StoreMini*/ +} /*afs_StoreMini */ unsigned int storeallmissing = 0; #define lmin(a,b) (((a) < (b)) ? (a) : (b)) @@ -142,52 +148,50 @@ unsigned int storeallmissing = 0; #if defined (AFS_HPUX_ENV) || defined(AFS_ULTRIX_ENV) int NCHUNKSATONCE = 3; #else -int NCHUNKSATONCE = 64 ; +int NCHUNKSATONCE = 64; #endif -int afs_dvhack=0; +int afs_dvhack = 0; -afs_StoreAllSegments(avc, areq, sync) - register struct vcache *avc; - struct vrequest *areq; - int sync; - -{ /*afs_StoreAllSegments*/ +int +afs_StoreAllSegments(register struct vcache *avc, struct vrequest *areq, + int sync) +{ register struct dcache *tdc; - register afs_int32 code=0; + register afs_int32 code = 0; register afs_int32 index; - register afs_int32 origCBs, foreign=0; + register afs_int32 origCBs, foreign = 0; int hash, stored; afs_hyper_t newDV, oldDV; /* DV when we start, and finish, respectively */ struct dcache **dcList, **dclist; - unsigned int i, j, minj, maxj, moredata, high, off; - unsigned long tlen; + unsigned int i, j, minj, moredata, high, off; + afs_size_t tlen; + afs_size_t maxStoredLength; /* highest offset we've written to server. */ int safety; - int maxStoredLength; /* highest offset we've written to server. */ #ifndef AFS_NOSTATS struct afs_stats_xferData *xferP; /* Ptr to this op's xfer struct */ - osi_timeval_t xferStartTime, /*FS xfer start time*/ - xferStopTime; /*FS xfer stop time*/ - afs_int32 bytesToXfer; /* # bytes to xfer*/ - afs_int32 bytesXferred; /* # bytes actually xferred*/ + osi_timeval_t xferStartTime, /*FS xfer start time */ + xferStopTime; /*FS xfer stop time */ + afs_size_t bytesToXfer; /* # bytes to xfer */ + afs_size_t bytesXferred; /* # bytes actually xferred */ #endif /* AFS_NOSTATS */ AFS_STATCNT(afs_StoreAllSegments); - + hset(oldDV, avc->m.DataVersion); hset(newDV, avc->m.DataVersion); hash = DVHash(&avc->fid); foreign = (avc->states & CForeign); - dcList = (struct dcache **) osi_AllocLargeSpace(AFS_LRALLOCSIZ); + dcList = (struct dcache **)osi_AllocLargeSpace(AFS_LRALLOCSIZ); afs_Trace2(afs_iclSetp, CM_TRACE_STOREALL, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length); + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length)); #if !defined(AFS_AIX32_ENV) && !defined(AFS_SGI65_ENV) /* In the aix vm implementation we need to do the vm_writep even * on the memcache case since that's we adjust the file's size * and finish flushing partial vm pages. */ - if (cacheDiskType != AFS_FCACHE_TYPE_MEM) + if (cacheDiskType != AFS_FCACHE_TYPE_MEM) #endif /* !AFS_AIX32_ENV && !AFS_SGI65_ENV */ { /* If we're not diskless, reading a file may stress the VM @@ -201,422 +205,557 @@ afs_StoreAllSegments(avc, areq, sync) * space. */ #if defined(AFS_SUN5_ENV) - if ( sync & AFS_VMSYNC_INVAL) /* invalidate VM pages */ - osi_VM_TryToSmush(avc, CRED() , 1 ); + if (sync & AFS_VMSYNC_INVAL) /* invalidate VM pages */ + osi_VM_TryToSmush(avc, CRED(), 1); else #endif osi_VM_StoreAllSegments(avc); } ConvertWToSLock(&avc->lock); - - /* - * Subsequent code expects a sorted list, and it expects all the - * chunks in the list to be contiguous, so we need a sort and a - * while loop in here, too - but this will work for a first pass... - * 92.10.05 - OK, there's a sort in here now. It's kind of a modified - * bin sort, I guess. Chunk numbers start with 0 - * - * - Have to get a write lock on xdcache because GetDSlot might need it (if - * the chunk doesn't have a dcache struct). - * This seems like overkill in most cases. - * - I'm not sure that it's safe to do "index = .hvNextp", then unlock - * xdcache, then relock xdcache and try to use index. It is done - * a lot elsewhere in the CM, but I'm not buying that argument. - * - should be able to check IFDataMod without doing the GetDSlot (just - * hold afs_xdcache). That way, it's easy to do this without the - * writelock on afs_xdcache, and we save unneccessary disk - * operations. I don't think that works, 'cuz the next pointers - * are still on disk. - */ + + /* + * Subsequent code expects a sorted list, and it expects all the + * chunks in the list to be contiguous, so we need a sort and a + * while loop in here, too - but this will work for a first pass... + * 92.10.05 - OK, there's a sort in here now. It's kind of a modified + * bin sort, I guess. Chunk numbers start with 0 + * + * - Have to get a write lock on xdcache because GetDSlot might need it (if + * the chunk doesn't have a dcache struct). + * This seems like overkill in most cases. + * - I'm not sure that it's safe to do "index = .hvNextp", then unlock + * xdcache, then relock xdcache and try to use index. It is done + * a lot elsewhere in the CM, but I'm not buying that argument. + * - should be able to check IFDataMod without doing the GetDSlot (just + * hold afs_xdcache). That way, it's easy to do this without the + * writelock on afs_xdcache, and we save unneccessary disk + * operations. I don't think that works, 'cuz the next pointers + * are still on disk. + */ origCBs = afs_allCBs; retry: maxStoredLength = 0; tlen = avc->m.Length; - minj = 0 ; + minj = 0; do { - memset((char *)dcList, 0, NCHUNKSATONCE * sizeof(struct dcache *)); - high = 0; - moredata = FALSE; - - /* lock and start over from beginning of hash chain - * in order to avoid a race condition. */ - MObtainWriteLock(&afs_xdcache,284); - index = afs_dvhashTbl[hash]; - - for(j=0; index != NULLIDX;) { - if ((afs_indexFlags[index] & IFDataMod) && - (afs_indexUnique[index] == avc->fid.Fid.Unique)) { - tdc = afs_GetDSlot(index, 0); /* refcount+1. */ - if (!FidCmp( &tdc->f.fid, &avc->fid ) && tdc->f.chunk >= minj ) { - - off = tdc->f.chunk - minj; - if (off < NCHUNKSATONCE) { - if ( dcList[ off ] ) - osi_Panic("dclist slot already in use!"); - dcList[ off ] = tdc; - if (off > high) - high = off; - tlen -= tdc->f.chunkBytes; /* shortcut: big win for little files */ - j++; - if (tlen <= 0) - break; - } - else { - moredata = TRUE; - lockedPutDCache(tdc); - if (j == NCHUNKSATONCE) - break; + memset((char *)dcList, 0, NCHUNKSATONCE * sizeof(struct dcache *)); + high = 0; + moredata = FALSE; + + /* lock and start over from beginning of hash chain + * in order to avoid a race condition. */ + MObtainWriteLock(&afs_xdcache, 284); + index = afs_dvhashTbl[hash]; + + for (j = 0; index != NULLIDX;) { + if ((afs_indexFlags[index] & IFDataMod) + && (afs_indexUnique[index] == avc->fid.Fid.Unique)) { + tdc = afs_GetDSlot(index, 0); /* refcount+1. */ + ReleaseReadLock(&tdc->tlock); + if (!FidCmp(&tdc->f.fid, &avc->fid) && tdc->f.chunk >= minj) { + off = tdc->f.chunk - minj; + if (off < NCHUNKSATONCE) { + if (dcList[off]) + osi_Panic("dclist slot already in use!"); + dcList[off] = tdc; + if (off > high) + high = off; + j++; + /* DCLOCKXXX: chunkBytes is protected by tdc->lock which we + * can't grab here, due to lock ordering with afs_xdcache. + * So, disable this shortcut for now. -- kolya 2001-10-13 + */ + /* shortcut: big win for little files */ + /* tlen -= tdc->f.chunkBytes; + * if (tlen <= 0) + * break; + */ + } else { + moredata = TRUE; + afs_PutDCache(tdc); + if (j == NCHUNKSATONCE) + break; + } + } else { + afs_PutDCache(tdc); + } } - } else { - lockedPutDCache(tdc); - } + index = afs_dvnextTbl[index]; } - index = afs_dvnextTbl[index]; - } - - MReleaseWriteLock(&afs_xdcache); - /* this guy writes chunks, puts back dcache structs, and bumps newDV */ - /* "moredata" just says "there are more dirty chunks yet to come". - */ - if (j) { - static afs_uint32 lp1 = 10000, lp2 = 10000; - struct AFSStoreStatus InStatus; - struct AFSFetchStatus OutStatus; - int doProcessFS = 0; - afs_uint32 base, bytes, nchunks; - int nomore; - unsigned int first; - int *shouldwake; - struct conn * tc; - struct osi_file * tfile; - struct rx_call * tcall; - extern int afs_defaultAsynchrony; - XSTATS_DECLS - - for (bytes = 0, j = 0; !code && j<=high; j++) { - if (dcList[j]) { - if (!bytes) - first = j; - bytes += dcList[j]->f.chunkBytes; - if ((dcList[j]->f.chunkBytes < afs_OtherCSize) - && (dcList[j]->f.chunk - minj < high) - && dcList[j+1]) { - int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes; - bytes += sbytes; - + MReleaseWriteLock(&afs_xdcache); - - } - } - if (bytes && (j==high || !dcList[j+1])) { - /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */ - base = AFS_CHUNKTOBASE(first + minj) ; - /* - * - * take a list of dcache structs and send them all off to the server - * the list must be in order, and the chunks contiguous. - * Note - there is no locking done by this code currently. For - * safety's sake, xdcache could be locked over the entire call. - * However, that pretty well ties up all the threads. Meantime, all - * the chunks _MUST_ have their refcounts bumped. - * The writes done before a store back will clear setuid-ness - * in cache file. - * We can permit CacheStoreProc to wake up the user process IFF we - * are doing the last RPC for this close, ie, storing back the last - * set of contiguous chunks of a file. - */ - - dclist = &dcList[first]; - nchunks = 1+j-first; - nomore = !(moredata || (j!=high)); - InStatus.ClientModTime = avc->m.Date; - InStatus.Mask = AFS_SETMODTIME; - if (sync & AFS_SYNC) { - InStatus.Mask |= AFS_FSYNC; - } - tlen = lmin(avc->m.Length, avc->truncPos); - - do { - stored = 0; - tc = afs_Conn(&avc->fid, areq); - if (tc) { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - tcall = rx_NewCall(tc->id); - code = StartRXAFS_StoreData(tcall, (struct AFSFid *) &avc->fid.Fid, - &InStatus, base, bytes, tlen); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - } else { - code = -1; - tcall = NULL; - } - if (!code) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA); - avc->truncPos = AFS_NOTRUNC; + /* this guy writes chunks, puts back dcache structs, and bumps newDV */ + /* "moredata" just says "there are more dirty chunks yet to come". + */ + if (j) { +#ifdef AFS_NOSTATS + static afs_uint32 lp1 = 10000, lp2 = 10000; +#endif + struct AFSStoreStatus InStatus; + struct AFSFetchStatus OutStatus; + int doProcessFS = 0; + afs_size_t base, bytes; + afs_uint32 nchunks; + int nomore; + unsigned int first; + int *shouldwake; + struct conn *tc; + struct osi_file *tfile; + struct rx_call *tcall; + XSTATS_DECLS for (bytes = 0, j = 0; !code && j <= high; j++) { + if (dcList[j]) { + ObtainSharedLock(&(dcList[j]->lock), 629); + if (!bytes) + first = j; + bytes += dcList[j]->f.chunkBytes; + if ((dcList[j]->f.chunkBytes < afs_OtherCSize) + && (dcList[j]->f.chunk - minj < high) + && dcList[j + 1]) { + int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes; + bytes += sbytes; + } } - for (i = 0; if.chunk); */ + base = AFS_CHUNKTOBASE(first + minj); + /* + * + * take a list of dcache structs and send them all off to the server + * the list must be in order, and the chunks contiguous. + * Note - there is no locking done by this code currently. For + * safety's sake, xdcache could be locked over the entire call. + * However, that pretty well ties up all the threads. Meantime, all + * the chunks _MUST_ have their refcounts bumped. + * The writes done before a store back will clear setuid-ness + * in cache file. + * We can permit CacheStoreProc to wake up the user process IFF we + * are doing the last RPC for this close, ie, storing back the last + * set of contiguous chunks of a file. + */ + + dclist = &dcList[first]; + nchunks = 1 + j - first; + nomore = !(moredata || (j != high)); + InStatus.ClientModTime = avc->m.Date; + InStatus.Mask = AFS_SETMODTIME; + if (sync & AFS_SYNC) { + InStatus.Mask |= AFS_FSYNC; } - shouldwake = 0; - if (nomore) { - if (avc->asynchrony == -1) { - if (afs_defaultAsynchrony > (bytes-stored)) { - shouldwake = &nomore; - } - } else if ((afs_uint32)avc->asynchrony >= (bytes-stored)) { - shouldwake = &nomore; - } - } - tfile = afs_CFileOpen(tdc->f.inode); + tlen = lmin(avc->m.Length, avc->truncPos); + afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64, + ICL_TYPE_FID, &avc->fid.Fid, ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET, + ICL_HANDLE_OFFSET(tlen)); + + do { + stored = 0; + tc = afs_Conn(&avc->fid, areq, 0); + if (tc) { + restart: + RX_AFS_GUNLOCK(); + tcall = rx_NewCall(tc->id); +#ifdef AFS_64BIT_CLIENT + if (!afs_serverHasNo64Bit(tc)) { + code = + StartRXAFS_StoreData64(tcall, + (struct AFSFid *) + &avc->fid.Fid, + &InStatus, base, + bytes, tlen); + } else { + if (tlen > 0xFFFFFFFF) { + code = EFBIG; + } else { + afs_int32 t1, t2, t3; + t1 = base; + t2 = bytes; + t3 = tlen; + code = + StartRXAFS_StoreData(tcall, + (struct AFSFid *) + &avc->fid.Fid, + &InStatus, t1, + t2, t3); + } + } +#else /* AFS_64BIT_CLIENT */ + code = + StartRXAFS_StoreData(tcall, + (struct AFSFid *)&avc-> + fid.Fid, &InStatus, base, + bytes, tlen); +#endif /* AFS_64BIT_CLIENT */ + RX_AFS_GLOCK(); + } else { + code = -1; + tcall = NULL; + } + if (!code) { + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA); + avc->truncPos = AFS_NOTRUNC; + } + for (i = 0; i < nchunks && !code; i++) { + tdc = dclist[i]; + if (!tdc) { + afs_warn("afs: missing dcache!\n"); + storeallmissing++; + continue; /* panic? */ + } + afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, + ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, + tdc->f.chunk, ICL_TYPE_INT32, + tdc->index, ICL_TYPE_INT32, + tdc->f.inode); + shouldwake = 0; + if (nomore) { + if (avc->asynchrony == -1) { + if (afs_defaultAsynchrony > + (bytes - stored)) { + shouldwake = &nomore; + } + } else if ((afs_uint32) avc->asynchrony >= + (bytes - stored)) { + shouldwake = &nomore; + } + } + tfile = afs_CFileOpen(tdc->f.inode); #ifndef AFS_NOSTATS - xferP = &(afs_stats_cmfullperf.rpc.fsXferTimes[AFS_STATS_FS_XFERIDX_STOREDATA]); - osi_GetuTime(&xferStartTime); - - code = afs_CacheStoreProc(tcall, tfile, tdc->f.chunkBytes, - avc, shouldwake, &bytesToXfer, - &bytesXferred); - - osi_GetuTime(&xferStopTime); - (xferP->numXfers)++; - if (!code) { - (xferP->numSuccesses)++; - afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] += bytesXferred; - (xferP->sumBytes) += (afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] >> 10); - afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] &= 0x3FF; - if (bytesXferred < xferP->minBytes) - xferP->minBytes = bytesXferred; - if (bytesXferred > xferP->maxBytes) - xferP->maxBytes = bytesXferred; - - /* - * Tally the size of the object. Note: we tally the actual size, - * NOT the number of bytes that made it out over the wire. - */ - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) - (xferP->count[0])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1) - (xferP->count[1])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2) - (xferP->count[2])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3) - (xferP->count[3])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4) - (xferP->count[4])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5) - (xferP->count[5])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6) - (xferP->count[6])++; - else - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7) - (xferP->count[7])++; - else - (xferP->count[8])++; - - afs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime); - afs_stats_AddTo((xferP->sumTime), elapsedTime); - afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime); - if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) { - afs_stats_TimeAssign((xferP->minTime), elapsedTime); - } - if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) { - afs_stats_TimeAssign((xferP->maxTime), elapsedTime); - } - } + xferP = + &(afs_stats_cmfullperf.rpc. + fsXferTimes + [AFS_STATS_FS_XFERIDX_STOREDATA]); + osi_GetuTime(&xferStartTime); + + code = + afs_CacheStoreProc(tcall, tfile, + tdc->f.chunkBytes, avc, + shouldwake, &bytesToXfer, + &bytesXferred); + + osi_GetuTime(&xferStopTime); + (xferP->numXfers)++; + if (!code) { + (xferP->numSuccesses)++; + afs_stats_XferSumBytes + [AFS_STATS_FS_XFERIDX_STOREDATA] += + bytesXferred; + (xferP->sumBytes) += + (afs_stats_XferSumBytes + [AFS_STATS_FS_XFERIDX_STOREDATA] >> 10); + afs_stats_XferSumBytes + [AFS_STATS_FS_XFERIDX_STOREDATA] &= 0x3FF; + if (bytesXferred < xferP->minBytes) + xferP->minBytes = bytesXferred; + if (bytesXferred > xferP->maxBytes) + xferP->maxBytes = bytesXferred; + + /* + * Tally the size of the object. Note: we tally the actual size, + * NOT the number of bytes that made it out over the wire. + */ + if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) + (xferP->count[0])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET1) + (xferP->count[1])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET2) + (xferP->count[2])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET3) + (xferP->count[3])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET4) + (xferP->count[4])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET5) + (xferP->count[5])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET6) + (xferP->count[6])++; + else if (bytesToXfer <= + AFS_STATS_MAXBYTES_BUCKET7) + (xferP->count[7])++; + else + (xferP->count[8])++; + + afs_stats_GetDiff(elapsedTime, xferStartTime, + xferStopTime); + afs_stats_AddTo((xferP->sumTime), + elapsedTime); + afs_stats_SquareAddTo((xferP->sqrTime), + elapsedTime); + if (afs_stats_TimeLessThan + (elapsedTime, (xferP->minTime))) { + afs_stats_TimeAssign((xferP->minTime), + elapsedTime); + } + if (afs_stats_TimeGreaterThan + (elapsedTime, (xferP->maxTime))) { + afs_stats_TimeAssign((xferP->maxTime), + elapsedTime); + } + } #else - code = afs_CacheStoreProc(tcall, tfile, tdc->f.chunkBytes, avc, - shouldwake, &lp1, &lp2); + code = + afs_CacheStoreProc(tcall, tfile, + tdc->f.chunkBytes, avc, + shouldwake, &lp1, &lp2); #endif /* AFS_NOSTATS */ - afs_CFileClose(tfile); - if ((tdc->f.chunkBytes < afs_OtherCSize) && - (i < (nchunks-1))) { - int bsent, tlen, tlen1=0, sbytes = afs_OtherCSize - tdc->f.chunkBytes; - char *tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ); - - while (sbytes > 0) { - tlen = (sbytes > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : sbytes); - memset(tbuffer, 0, tlen); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - bsent = rx_Write(tcall, tbuffer, tlen); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - - if (bsent != tlen) { - code = -33; /* XXX */ - break; - } - sbytes -= tlen; - } - osi_FreeLargeSpace(tbuffer); - } - stored += tdc->f.chunkBytes; - - /* ideally, I'd like to unlock the dcache and turn - * off the writing bit here, but that would - * require being able to retry StoreAllSegments in - * the event of a failure. It only really matters - * if user can't read from a 'locked' dcache or - * one which has the writing bit turned on. */ - } - if (!code) { - struct AFSVolSync tsync; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = EndRXAFS_StoreData(tcall, &OutStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - hadd32(newDV, 1); - XSTATS_END_TIME; - if (!code) doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */ - } - if (tcall) { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = rx_EndCall(tcall, code, avc, base); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - } - } while (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_STOREDATA, - SHARED_LOCK, (struct cell *)0)); - - /* put back all remaining locked dcache entries */ - for (i=0; iindex] & IFDataMod) { - afs_indexFlags[tdc->index] &= ~IFDataMod; - afs_stats_cmperf.cacheCurrDirtyChunks--; - afs_indexFlags[tdc->index] &= ~IFDirtyPages; - if ( sync & AFS_VMSYNC_INVAL ) - { - /* since we have invalidated all the pages of this - ** vnode by calling osi_VM_TryToSmush, we can - ** safely mark this dcache entry as not having - ** any pages. This vnode now becomes eligible for - ** reclamation by getDownD. - */ - afs_indexFlags[tdc->index] &= ~IFAnyPages; - } + afs_CFileClose(tfile); +#ifdef AFS_64BIT_CLIENT + if (code == RXGEN_OPCODE) { + afs_serverSetNo64Bit(tc); + goto restart; + } +#endif /* AFS_64BIT_CLIENT */ + if ((tdc->f.chunkBytes < afs_OtherCSize) + && (i < (nchunks - 1))) { + int bsent, tlen, sbytes = + afs_OtherCSize - tdc->f.chunkBytes; + char *tbuffer = + osi_AllocLargeSpace(AFS_LRALLOCSIZ); + + while (sbytes > 0) { + tlen = + (sbytes > + AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : + sbytes); + memset(tbuffer, 0, tlen); + RX_AFS_GUNLOCK(); + bsent = rx_Write(tcall, tbuffer, tlen); + RX_AFS_GLOCK(); + + if (bsent != tlen) { + code = -33; /* XXX */ + break; + } + sbytes -= tlen; + } + osi_FreeLargeSpace(tbuffer); + } + stored += tdc->f.chunkBytes; + + /* ideally, I'd like to unlock the dcache and turn + * off the writing bit here, but that would + * require being able to retry StoreAllSegments in + * the event of a failure. It only really matters + * if user can't read from a 'locked' dcache or + * one which has the writing bit turned on. */ + } + if (!code) { + struct AFSVolSync tsync; + RX_AFS_GUNLOCK(); + code = + EndRXAFS_StoreData(tcall, &OutStatus, &tsync); + RX_AFS_GLOCK(); + hadd32(newDV, 1); + XSTATS_END_TIME; + if (!code) + doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */ + } + if (tcall) { + afs_int32 code2; + RX_AFS_GUNLOCK(); + code2 = rx_EndCall(tcall, code); + RX_AFS_GLOCK(); + if (code2) + code = code2; + } + } while (afs_Analyze + (tc, code, &avc->fid, areq, + AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK, + NULL)); + + /* put back all remaining locked dcache entries */ + for (i = 0; i < nchunks; i++) { + tdc = dclist[i]; + if (!code) { + if (afs_indexFlags[tdc->index] & IFDataMod) { + /* + * LOCKXXX -- should hold afs_xdcache(W) when + * modifying afs_indexFlags. + */ + afs_indexFlags[tdc->index] &= ~IFDataMod; + afs_stats_cmperf.cacheCurrDirtyChunks--; + afs_indexFlags[tdc->index] &= ~IFDirtyPages; + if (sync & AFS_VMSYNC_INVAL) { + /* since we have invalidated all the pages of this + ** vnode by calling osi_VM_TryToSmush, we can + ** safely mark this dcache entry as not having + ** any pages. This vnode now becomes eligible for + ** reclamation by getDownD. + */ + afs_indexFlags[tdc->index] &= ~IFAnyPages; + } + } + } + UpgradeSToWLock(&tdc->lock, 628); + tdc->f.states &= ~DWriting; /* correct? */ + tdc->dflags |= DFEntryMod; + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); + /* Mark the entry as released */ + dclist[i] = NULL; + } + + if (doProcessFS) { + /* Now copy out return params */ + UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */ + afs_ProcessFS(avc, &OutStatus, areq); + /* Keep last (max) size of file on server to see if + * we need to call afs_StoreMini to extend the file. + */ + if (!moredata) + maxStoredLength = OutStatus.Length; + ConvertWToSLock(&avc->lock); + doProcessFS = 0; } + + if (code) { + for (j++; j <= high; j++) { + if (dcList[j]) { + ReleaseSharedLock(&(dcList[j]->lock)); + afs_PutDCache(dcList[j]); + /* Releasing entry */ + dcList[j] = NULL; + } + } + } + + afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE, + ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code); + bytes = 0; } - tdc->f.states &= ~DWriting; /* correct?*/ - tdc->flags |= DFEntryMod; - lockedPutDCache(tdc); } - if (doProcessFS) { - /* Now copy out return params */ - UpgradeSToWLock(&avc->lock,28); /* keep out others for a while */ - afs_ProcessFS(avc, &OutStatus, areq); - /* Keep last (max) size of file on server to see if - * we need to call afs_StoreMini to extend the file. - */ - if (!moredata) - maxStoredLength = OutStatus.Length; - ConvertWToSLock(&avc->lock); - doProcessFS = 0; + /* Release any zero-length dcache entries in our interval + * that we locked but didn't store back above. + */ + for (j = 0; j <= high; j++) { + tdc = dcList[j]; + if (tdc) { + osi_Assert(tdc->f.chunkBytes == 0); + ReleaseSharedLock(&tdc->lock); + afs_PutDCache(tdc); + } } + } + /* if (j) */ + minj += NCHUNKSATONCE; + } while (!code && moredata); - if (code) { - for (j++; j<=high; j++) - if ( dcList[j] ) - lockedPutDCache(dcList[j]); - } + UpgradeSToWLock(&avc->lock, 29); - afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE, - ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code); - bytes = 0; - } + /* send a trivial truncation store if did nothing else */ + if (code == 0) { + /* + * Call StoreMini if we haven't written enough data to extend the + * file at the fileserver to the client's notion of the file length. + */ + if ((avc->truncPos != AFS_NOTRUNC) || ((avc->states & CExtendedFile) + && (maxStoredLength < + avc->m.Length))) { + code = afs_StoreMini(avc, areq); + if (code == 0) + hadd32(newDV, 1); /* just bumped here, too */ } - } /* if (j) */ - - minj += NCHUNKSATONCE; - } while ( !code && moredata ); - - UpgradeSToWLock(&avc->lock,29); + avc->states &= ~CExtendedFile; + } - /* send a trivial truncation store if did nothing else */ - if (code == 0) { /* - * Call StoreMini if we haven't written enough data to extend the - * file at the fileserver to the client's notion of the file length. + * Finally, turn off DWriting, turn on DFEntryMod, + * update f.versionNo. + * A lot of this could be integrated into the loop above */ - if ((avc->truncPos != AFS_NOTRUNC) || - ((avc->states & CExtendedFile) && (maxStoredLength < avc->m.Length))) { - code = afs_StoreMini(avc, areq); - if (code == 0) - hadd32(newDV, 1); /* just bumped here, too */ - } - avc->states &= ~CExtendedFile; - } - - /* - * Finally, turn off DWriting, turn on DFEntryMod, - * update f.versionNo. - * A lot of this could be integrated into the loop above - */ if (!code) { afs_hyper_t h_unset; hones(h_unset); - MObtainWriteLock(&afs_xdcache,285); /* overkill, but it gets the - * lock in case GetDSlot needs it */ - for(safety = 0, index = afs_dvhashTbl[hash]; - index != NULLIDX && safety < afs_cacheFiles+2;) { - if (afs_indexUnique[index] == avc->fid.Fid.Unique) { - tdc = afs_GetDSlot(index, 0); + minj = 0; + + do { + moredata = FALSE; + memset((char *)dcList, 0, + NCHUNKSATONCE * sizeof(struct dcache *)); + + /* overkill, but it gets the lock in case GetDSlot needs it */ + MObtainWriteLock(&afs_xdcache, 285); + + for (j = 0, safety = 0, index = afs_dvhashTbl[hash]; + index != NULLIDX && safety < afs_cacheFiles + 2;) { + + if (afs_indexUnique[index] == avc->fid.Fid.Unique) { + tdc = afs_GetDSlot(index, 0); + ReleaseReadLock(&tdc->tlock); + + if (!FidCmp(&tdc->f.fid, &avc->fid) + && tdc->f.chunk >= minj) { + off = tdc->f.chunk - minj; + if (off < NCHUNKSATONCE) { + /* this is the file, and the correct chunk range */ + if (j >= NCHUNKSATONCE) + osi_Panic + ("Too many dcache entries in range\n"); + dcList[j++] = tdc; + } else { + moredata = TRUE; + afs_PutDCache(tdc); + if (j == NCHUNKSATONCE) + break; + } + } else { + afs_PutDCache(tdc); + } + } - if (!FidCmp(&tdc->f.fid, &avc->fid)) { - /* this is the file */ - /* was code here to clear IFDataMod, but it should only be done - * in storedcache and storealldcache. - */ - /* Only increase DV if we had up-to-date data to start with. - * Otherwise, we could be falsely upgrading an old chunk - * (that we never read) into one labelled with the current - * DV #. Also note that we check that no intervening stores - * occurred, otherwise we might mislabel cache information - * for a chunk that we didn't store this time - */ - /* Don't update the version number if it's not yet set. */ - if (code == 0 && (!hsame(tdc->f.versionNo, h_unset)) - && (hcmp(tdc->f.versionNo, oldDV) >= 0)) { - if ((!(afs_dvhack || foreign) && hsame(avc->m.DataVersion, newDV)) - || ((afs_dvhack || foreign) && (origCBs == afs_allCBs)) ) { - /* no error, this is the DV */ - hset(tdc->f.versionNo, avc->m.DataVersion); - tdc->flags |= DFEntryMod; - } + index = afs_dvnextTbl[index]; } - } - lockedPutDCache(tdc); - } - index = afs_dvnextTbl[index]; - } - MReleaseWriteLock(&afs_xdcache); + MReleaseWriteLock(&afs_xdcache); + + for (i = 0; i < j; i++) { + /* Iterate over the dcache entries we collected above */ + tdc = dcList[i]; + ObtainSharedLock(&tdc->lock, 677); + + /* was code here to clear IFDataMod, but it should only be done + * in storedcache and storealldcache. + */ + /* Only increase DV if we had up-to-date data to start with. + * Otherwise, we could be falsely upgrading an old chunk + * (that we never read) into one labelled with the current + * DV #. Also note that we check that no intervening stores + * occurred, otherwise we might mislabel cache information + * for a chunk that we didn't store this time + */ + /* Don't update the version number if it's not yet set. */ + if (!hsame(tdc->f.versionNo, h_unset) + && hcmp(tdc->f.versionNo, oldDV) >= 0) { + + if ((!(afs_dvhack || foreign) + && hsame(avc->m.DataVersion, newDV)) + || ((afs_dvhack || foreign) + && (origCBs == afs_allCBs))) { + /* no error, this is the DV */ + + UpgradeSToWLock(&tdc->lock, 678); + hset(tdc->f.versionNo, avc->m.DataVersion); + tdc->dflags |= DFEntryMod; + ConvertWToSLock(&tdc->lock); + } + } + + ReleaseSharedLock(&tdc->lock); + afs_PutDCache(tdc); + } + + minj += NCHUNKSATONCE; + + } while (moredata); } if (code) { @@ -627,20 +766,20 @@ afs_StoreAllSegments(avc, areq, sync) * fileserver. */ if (areq->permWriteError || (avc->states & (CCore1 | CCore))) { - afs_InvalidateAllSegments(avc, 1); + afs_InvalidateAllSegments(avc); } } afs_Trace3(afs_iclSetp, CM_TRACE_STOREALLDONE, ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, avc->m.Length, ICL_TYPE_INT32, code); - /* would like a Trace5, but it doesn't exist...*/ + /* would like a Trace5, but it doesn't exist... */ afs_Trace3(afs_iclSetp, CM_TRACE_AVCLOCKER, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->lock.wait_states, - ICL_TYPE_INT32, avc->lock.excl_locked); + ICL_TYPE_INT32, avc->lock.wait_states, ICL_TYPE_INT32, + avc->lock.excl_locked); afs_Trace4(afs_iclSetp, CM_TRACE_AVCLOCKEE, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->lock.wait_states, - ICL_TYPE_INT32, avc->lock.readers_reading, - ICL_TYPE_INT32, avc->lock.num_waiting ); - + ICL_TYPE_INT32, avc->lock.wait_states, ICL_TYPE_INT32, + avc->lock.readers_reading, ICL_TYPE_INT32, + avc->lock.num_waiting); + /* * Finally, if updated DataVersion matches newDV, we did all of the * stores. If mapDV indicates that the page cache was flushed up @@ -649,11 +788,11 @@ afs_StoreAllSegments(avc, areq, sync) * Turn off CDirty bit because the stored data is now in sync with server. */ if (code == 0 && hcmp(avc->mapDV, oldDV) >= 0) { - if ((!(afs_dvhack || foreign) && hsame(avc->m.DataVersion, newDV)) - || ((afs_dvhack || foreign) && (origCBs == afs_allCBs)) ) { - hset(avc->mapDV, newDV); - avc->states &= ~CDirty; - } + if ((!(afs_dvhack || foreign) && hsame(avc->m.DataVersion, newDV)) + || ((afs_dvhack || foreign) && (origCBs == afs_allCBs))) { + hset(avc->mapDV, newDV); + avc->states &= ~CDirty; + } } osi_FreeLargeSpace(dcList); @@ -662,8 +801,8 @@ afs_StoreAllSegments(avc, areq, sync) code = 0; return code; - -} /*afs_StoreAllSegments (new 03/02/94)*/ + +} /*afs_StoreAllSegments (new 03/02/94) */ /* @@ -674,33 +813,30 @@ afs_StoreAllSegments(avc, areq, sync) * * Parameters: * avc : Pointer to vcache entry. - * asetLock : If true, we are to set the afs_xdcache lock; otherwise, - * the caller has already done it. * * Environment: * For example, called after an error has been detected. Called - * with avc write-locked. + * with avc write-locked, and afs_xdcache unheld. */ - -afs_InvalidateAllSegments(avc, asetLock) - struct vcache *avc; - int asetLock; - -{ /*afs_InvalidateAllSegments*/ +int +afs_InvalidateAllSegments(struct vcache *avc) +{ struct dcache *tdc; afs_int32 hash; afs_int32 index; + struct dcache **dcList; + int i, dcListMax, dcListCount; AFS_STATCNT(afs_InvalidateAllSegments); afs_Trace2(afs_iclSetp, CM_TRACE_INVALL, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length); + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length)); hash = DVHash(&avc->fid); - avc->truncPos = AFS_NOTRUNC; /* don't truncate later */ - avc->states &= ~CExtendedFile; /* not any more */ + avc->truncPos = AFS_NOTRUNC; /* don't truncate later */ + avc->states &= ~CExtendedFile; /* not any more */ ObtainWriteLock(&afs_xcbhash, 459); afs_DequeueCallback(avc); - avc->states &= ~(CStatd|CDirty); /* mark status information as bad, too */ + avc->states &= ~(CStatd | CDirty); /* mark status information as bad, too */ ReleaseWriteLock(&afs_xcbhash); if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR)) osi_dnlc_purgedp(avc); @@ -713,31 +849,62 @@ afs_InvalidateAllSegments(avc, asetLock) * Block out others from screwing with this table; is a read lock * sufficient? */ - if (asetLock) MObtainWriteLock(&afs_xdcache,286); - for(index = afs_dvhashTbl[hash]; index != NULLIDX;) { - if (afs_indexUnique[index] == avc->fid.Fid.Unique) { - tdc = afs_GetDSlot(index, 0); - if (!FidCmp(&tdc->f.fid, &avc->fid)) { - /* same file? we'll zap it */ - if (afs_indexFlags[index] & IFDataMod) { - afs_stats_cmperf.cacheCurrDirtyChunks--; - /* don't write it back */ - afs_indexFlags[index] &= ~IFDataMod; - } - afs_indexFlags[index] &= ~IFAnyPages; - ZapDCE(tdc); - if (vType(avc) == VDIR) { - DZap(&tdc->f.inode); + MObtainWriteLock(&afs_xdcache, 286); + dcListMax = 0; + + for (index = afs_dvhashTbl[hash]; index != NULLIDX;) { + if (afs_indexUnique[index] == avc->fid.Fid.Unique) { + tdc = afs_GetDSlot(index, 0); + ReleaseReadLock(&tdc->tlock); + if (!FidCmp(&tdc->f.fid, &avc->fid)) + dcListMax++; + afs_PutDCache(tdc); + } + index = afs_dvnextTbl[index]; + } + + dcList = osi_Alloc(dcListMax * sizeof(struct dcache *)); + dcListCount = 0; + + for (index = afs_dvhashTbl[hash]; index != NULLIDX;) { + if (afs_indexUnique[index] == avc->fid.Fid.Unique) { + tdc = afs_GetDSlot(index, 0); + ReleaseReadLock(&tdc->tlock); + if (!FidCmp(&tdc->f.fid, &avc->fid)) { + /* same file? we'll zap it */ + if (afs_indexFlags[index] & IFDataMod) { + afs_stats_cmperf.cacheCurrDirtyChunks--; + /* don't write it back */ + afs_indexFlags[index] &= ~IFDataMod; + } + afs_indexFlags[index] &= ~IFAnyPages; + if (dcListCount < dcListMax) + dcList[dcListCount++] = tdc; + else + afs_PutDCache(tdc); + } else { + afs_PutDCache(tdc); } } - lockedPutDCache(tdc); - } - index = afs_dvnextTbl[index]; + index = afs_dvnextTbl[index]; } - if (asetLock) MReleaseWriteLock(&afs_xdcache); - return 0; + MReleaseWriteLock(&afs_xdcache); -} /*afs_InvalidateAllSegments*/ + for (i = 0; i < dcListCount; i++) { + tdc = dcList[i]; + + ObtainWriteLock(&tdc->lock, 679); + ZapDCE(tdc); + if (vType(avc) == VDIR) + DZap(&tdc->f.inode); + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); + } + + osi_Free(dcList, dcListMax * sizeof(struct dcache *)); + + return 0; +} /* @@ -755,20 +922,23 @@ afs_InvalidateAllSegments(avc, asetLock) * Called with avc write-locked; in VFS40 systems, pvnLock is also * held. */ -afs_TruncateAllSegments(avc, alen, areq, acred) - afs_int32 alen; - register struct vcache *avc; - struct vrequest *areq; - struct AFS_UCRED *acred; -{ /*afs_TruncateAllSegments*/ - +int +afs_TruncateAllSegments(register struct vcache *avc, afs_size_t alen, + struct vrequest *areq, struct AFS_UCRED *acred) +{ register struct dcache *tdc; register afs_int32 code; register afs_int32 index; afs_int32 newSize; + int dcCount, dcPos; + struct dcache **tdcArray; + AFS_STATCNT(afs_TruncateAllSegments); avc->m.Date = osi_Time(); + afs_Trace3(afs_iclSetp, CM_TRACE_TRUNCALL, ICL_TYPE_POINTER, avc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(alen)); if (alen >= avc->m.Length) { /* * Special speedup since Sun's vm extends the file this way; @@ -781,14 +951,8 @@ afs_TruncateAllSegments(avc, alen, areq, acred) */ avc->states |= CExtendedFile; avc->m.Length = alen; - afs_Trace3(afs_iclSetp, CM_TRACE_TRUNCALL1, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length, ICL_TYPE_INT32, alen); return 0; } - - afs_Trace3(afs_iclSetp, CM_TRACE_TRUNCALL2, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length, ICL_TYPE_INT32, alen); - #if (defined(AFS_SUN5_ENV)) /* Zero unused portion of last page */ @@ -809,33 +973,80 @@ afs_TruncateAllSegments(avc, alen, areq, acred) osi_VM_Truncate(avc, alen, acred); AFS_GLOCK(); - ObtainWriteLock(&avc->lock,79); + ObtainWriteLock(&avc->lock, 79); avc->m.Length = alen; - - if (alen < avc->truncPos) avc->truncPos = alen; + + if (alen < avc->truncPos) + avc->truncPos = alen; code = DVHash(&avc->fid); + /* block out others from screwing with this table */ - MObtainWriteLock(&afs_xdcache,287); - for(index = afs_dvhashTbl[code]; index != NULLIDX;) { - if (afs_indexUnique[index] == avc->fid.Fid.Unique) { - tdc = afs_GetDSlot(index, 0); - if (!FidCmp(&tdc->f.fid, &avc->fid)) { - /* same file, and modified, we'll store it back */ - newSize = alen - AFS_CHUNKTOBASE(tdc->f.chunk); - if (newSize < 0) newSize = 0; - if (newSize < tdc->f.chunkBytes) { - register struct osi_file *tfile; - tfile = afs_CFileOpen(tdc->f.inode); - afs_CFileTruncate(tfile, newSize); - afs_CFileClose(tfile); - afs_AdjustSize(tdc, newSize); + MObtainWriteLock(&afs_xdcache, 287); + + dcCount = 0; + for (index = afs_dvhashTbl[code]; index != NULLIDX;) { + if (afs_indexUnique[index] == avc->fid.Fid.Unique) { + tdc = afs_GetDSlot(index, 0); + ReleaseReadLock(&tdc->tlock); + if (!FidCmp(&tdc->f.fid, &avc->fid)) + dcCount++; + afs_PutDCache(tdc); + } + index = afs_dvnextTbl[index]; + } + + /* Now allocate space where we can save those dcache entries, and + * do a second pass over them.. Since we're holding xdcache, it + * shouldn't be changing. + */ + tdcArray = osi_Alloc(dcCount * sizeof(struct dcache *)); + dcPos = 0; + + for (index = afs_dvhashTbl[code]; index != NULLIDX;) { + if (afs_indexUnique[index] == avc->fid.Fid.Unique) { + tdc = afs_GetDSlot(index, 0); + ReleaseReadLock(&tdc->tlock); + if (!FidCmp(&tdc->f.fid, &avc->fid)) { + /* same file, and modified, we'll store it back */ + if (dcPos < dcCount) { + tdcArray[dcPos++] = tdc; + } else { + afs_PutDCache(tdc); + } + } else { + afs_PutDCache(tdc); } } - lockedPutDCache(tdc); - } - index = afs_dvnextTbl[index]; + index = afs_dvnextTbl[index]; } + + MReleaseWriteLock(&afs_xdcache); + + /* Now we loop over the array of dcache entries and truncate them */ + for (index = 0; index < dcPos; index++) { + struct osi_file *tfile; + + tdc = tdcArray[index]; + + newSize = alen - AFS_CHUNKTOBASE(tdc->f.chunk); + if (newSize < 0) + newSize = 0; + ObtainSharedLock(&tdc->lock, 672); + if (newSize < tdc->f.chunkBytes) { + UpgradeSToWLock(&tdc->lock, 673); + tfile = afs_CFileOpen(tdc->f.inode); + afs_CFileTruncate(tfile, newSize); + afs_CFileClose(tfile); + afs_AdjustSize(tdc, newSize); + ConvertWToSLock(&tdc->lock); + } + ReleaseSharedLock(&tdc->lock); + afs_PutDCache(tdc); + } + + osi_Free(tdcArray, dcCount * sizeof(struct dcache *)); + #if (defined(AFS_SUN5_ENV)) ObtainWriteLock(&avc->vlock, 547); if (--avc->activeV == 0 && (avc->vstates & VRevokeWait)) { @@ -844,9 +1055,5 @@ afs_TruncateAllSegments(avc, alen, areq, acred) } ReleaseWriteLock(&avc->vlock); #endif - MReleaseWriteLock(&afs_xdcache); return 0; - -} /*afs_TruncateAllSegments*/ - - +} diff --git a/src/afs/afs_server.c b/src/afs/afs_server.c index a40a8acc6..4688ac977 100644 --- a/src/afs/afs_server.c +++ b/src/afs/afs_server.c @@ -30,12 +30,13 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_server.c,v 1.1.1.15 2003/07/30 17:08:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_server.c,v 1.29 2004/05/08 04:23:56 shadow Exp $"); -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ #if !defined(UKERNEL) #if !defined(AFS_LINUX20_ENV) @@ -44,7 +45,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_server.c,v 1.1.1.15 2003/07/30 #include #ifdef AFS_SGI62_ENV -#include "../h/hashing.h" +#include "h/hashing.h" #endif #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV) #include @@ -54,8 +55,9 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_server.c,v 1.1.1.15 2003/07/30 #endif #endif /* !defined(UKERNEL) */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ +#include "rx/rx_multi.h" #if defined(AFS_SUN56_ENV) #include @@ -70,24 +72,18 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_server.c,v 1.1.1.15 2003/07/30 #include #endif -/* Imported variables */ -extern afs_int32 afs_setTime; -extern afs_int32 afs_waitForever; -extern short afs_waitForeverCount; - - /* Exported variables */ -afs_rwlock_t afs_xserver; /* allocation lock for servers */ -struct server *afs_setTimeHost=0; /* last host we used for time */ -struct server *afs_servers[NSERVERS]; /* Hashed by server`s uuid & 1st ip */ -afs_rwlock_t afs_xsrvAddr; /* allocation lock for srvAddrs */ -struct srvAddr *afs_srvAddrs[NSERVERS]; /* Hashed by server's ip */ +afs_rwlock_t afs_xserver; /* allocation lock for servers */ +struct server *afs_setTimeHost = 0; /* last host we used for time */ +struct server *afs_servers[NSERVERS]; /* Hashed by server`s uuid & 1st ip */ +afs_rwlock_t afs_xsrvAddr; /* allocation lock for srvAddrs */ +struct srvAddr *afs_srvAddrs[NSERVERS]; /* Hashed by server's ip */ /* debugging aids - number of alloc'd server and srvAddr structs. */ -int afs_reuseServers = 0; +int afs_reuseServers = 0; int afs_reuseSrvAddrs = 0; -int afs_totalServers = 0; +int afs_totalServers = 0; int afs_totalSrvAddrs = 0; @@ -133,20 +129,21 @@ GetUpDownStats(struct server *srv) * As advertised. *------------------------------------------------------------------------*/ -void afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown) +void +afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown) { register struct server *a_serverP = sa->server; register struct srvAddr *sap; - osi_timeval_t currTime, *currTimeP; /*Current time*/ - afs_int32 downTime; /*Computed downtime, in seconds*/ - struct afs_stats_SrvUpDownInfo *upDownP; /*Ptr to up/down info record*/ + osi_timeval_t currTime, *currTimeP; /*Current time */ + afs_int32 downTime; /*Computed downtime, in seconds */ + struct afs_stats_SrvUpDownInfo *upDownP; /*Ptr to up/down info record */ /* * If the server record is marked the same as the new status we've * been fed, then there isn't much to be done. */ - if (( a_isDown && (sa->sa_flags & SRVADDR_ISDOWN)) || - (!a_isDown && !(sa->sa_flags & SRVADDR_ISDOWN))) + if ((a_isDown && (sa->sa_flags & SRVADDR_ISDOWN)) + || (!a_isDown && !(sa->sa_flags & SRVADDR_ISDOWN))) return; if (a_isDown) { @@ -157,7 +154,7 @@ void afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown) * server's up/down stats */ return; } - } + } /* * All ips are down we treat the whole server down */ @@ -169,7 +166,7 @@ void afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown) afs_setTimeHost = 0; } else { sa->sa_flags &= ~SRVADDR_ISDOWN; - /* If any ips are up, the server is also marked up */ + /* If any ips are up, the server is also marked up */ a_serverP->flags &= ~SRVR_ISDOWN; for (sap = a_serverP->addr; sap; sap = sap->next_sa) { if (sap->sa_flags & SRVADDR_ISDOWN) { @@ -177,7 +174,7 @@ void afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown) * server's up/down stats */ return; } - } + } } #ifndef AFS_NOSTATS /* @@ -198,7 +195,7 @@ void afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown) (upDownP->numDownRecords)++; (upDownP->numUpRecords)--; - } /*Server being marked down*/ + } /*Server being marked down */ else { /* * Server going down -> up; remember everything about this @@ -214,70 +211,65 @@ void afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown) if (a_serverP->numDowntimeIncidents == 1) (upDownP->numRecordsNeverDown)--; upDownP->sumOfDowntimes += downTime; - if ((upDownP->shortestDowntime == 0) || - (downTime < upDownP->shortestDowntime)) + if ((upDownP->shortestDowntime == 0) + || (downTime < upDownP->shortestDowntime)) upDownP->shortestDowntime = downTime; - if ((upDownP->longestDowntime == 0) || - (downTime > upDownP->longestDowntime)) + if ((upDownP->longestDowntime == 0) + || (downTime > upDownP->longestDowntime)) upDownP->longestDowntime = downTime; if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET0) (upDownP->downDurations[0])++; - else - if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET1) - (upDownP->downDurations[1])++; - else - if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET2) - (upDownP->downDurations[2])++; - else - if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET3) - (upDownP->downDurations[3])++; - else - if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET4) - (upDownP->downDurations[4])++; - else - if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET5) - (upDownP->downDurations[5])++; + else if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET1) + (upDownP->downDurations[1])++; + else if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET2) + (upDownP->downDurations[2])++; + else if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET3) + (upDownP->downDurations[3])++; + else if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET4) + (upDownP->downDurations[4])++; + else if (downTime <= AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET5) + (upDownP->downDurations[5])++; else (upDownP->downDurations[6])++; - } /*Server being marked up*/ + } /*Server being marked up */ #endif -} /*MarkServerUpOrDown*/ +} /*MarkServerUpOrDown */ -void afs_ServerDown(struct srvAddr *sa) +void +afs_ServerDown(struct srvAddr *sa) { register struct server *aserver = sa->server; - register struct srvAddr *sap; AFS_STATCNT(ServerDown); if (aserver->flags & SRVR_ISDOWN || sa->sa_flags & SRVADDR_ISDOWN) return; afs_MarkServerUpOrDown(sa, SRVR_ISDOWN); if (sa->sa_portal == aserver->cell->vlport) - print_internet_address("afs: Lost contact with volume location server ", - sa, "", 1); + print_internet_address + ("afs: Lost contact with volume location server ", sa, "", 1); else - print_internet_address("afs: Lost contact with file server ", sa, "", 1); + print_internet_address("afs: Lost contact with file server ", sa, "", + 1); -} /*ServerDown*/ +} /*ServerDown */ /* return true if we have any callback promises from this server */ -static HaveCallBacksFrom(aserver) - struct server *aserver; - +static int +HaveCallBacksFrom(struct server *aserver) { register afs_int32 now; register int i; register struct vcache *tvc; AFS_STATCNT(HaveCallBacksFrom); - now = osi_Time(); /* for checking for expired callbacks */ - for(i=0;ihnext) { + now = osi_Time(); /* for checking for expired callbacks */ + for (i = 0; i < VCSIZE; i++) { /* for all guys in the hash table */ + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { /* * Check to see if this entry has an unexpired callback promise * from the required host @@ -289,12 +281,11 @@ static HaveCallBacksFrom(aserver) } return 0; -} /*HaveCallBacksFrom*/ +} /*HaveCallBacksFrom */ -static void CheckVLServer(sa, areq) - struct vrequest *areq; - register struct srvAddr *sa; +static void +CheckVLServer(register struct srvAddr *sa, struct vrequest *areq) { register struct server *aserver = sa->server; register struct conn *tc; @@ -302,25 +293,22 @@ static void CheckVLServer(sa, areq) AFS_STATCNT(CheckVLServer); /* Ping dead servers to see if they're back */ - if (!((aserver->flags & SRVR_ISDOWN) || (sa->sa_flags & SRVADDR_ISDOWN)) || (aserver->flags & SRVR_ISGONE)) + if (!((aserver->flags & SRVR_ISDOWN) || (sa->sa_flags & SRVADDR_ISDOWN)) + || (aserver->flags & SRVR_ISGONE)) return; if (!aserver->cell) - return; /* can't do much */ + return; /* can't do much */ - tc = afs_ConnByHost(aserver, aserver->cell->vlport, + tc = afs_ConnByHost(aserver, aserver->cell->vlport, aserver->cell->cellNum, areq, 1, SHARED_LOCK); if (!tc) return; rx_SetConnDeadTime(tc->id, 3); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); code = VL_ProbeServer(tc->id); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - rx_SetConnDeadTime(tc->id, AFS_RXDEADTIME); + RX_AFS_GLOCK(); + rx_SetConnDeadTime(tc->id, afs_rx_deadtime); afs_PutConn(tc, SHARED_LOCK); /* * If probe worked, or probe call not yet defined (for compatibility @@ -329,15 +317,15 @@ static void CheckVLServer(sa, areq) if (code == 0 || (code <= -450 && code >= -470)) { if (tc->srvr == sa) { afs_MarkServerUpOrDown(sa, 0); - print_internet_address("afs: volume location server ", - sa, " is back up", 2); + print_internet_address("afs: volume location server ", sa, + " is back up", 2); } } -} /*CheckVLServer*/ +} /*CheckVLServer */ -#ifndef AFS_MINCHANGE /* So that some can increase it in param.h */ +#ifndef AFS_MINCHANGE /* So that some can increase it in param.h */ #define AFS_MINCHANGE 2 /* min change we'll bother with */ #endif #ifndef AFS_MAXCHANGEBACK @@ -368,18 +356,17 @@ static void CheckVLServer(sa, areq) * entries. *------------------------------------------------------------------------*/ -void afs_CountServers() - -{ /*afs_CountServers*/ - - int currIdx; /*Curr idx into srv table*/ - struct server *currSrvP; /*Ptr to curr server record*/ - afs_int32 currChainLen; /*Length of curr hash chain*/ - osi_timeval_t currTime; /*Current time*/ - osi_timeval_t *currTimeP; /*Ptr to above*/ - afs_int32 srvRecordAge; /*Age of server record, in secs*/ +void +afs_CountServers(void) +{ + int currIdx; /*Curr idx into srv table */ + struct server *currSrvP; /*Ptr to curr server record */ + afs_int32 currChainLen; /*Length of curr hash chain */ + osi_timeval_t currTime; /*Current time */ + osi_timeval_t *currTimeP; /*Ptr to above */ + afs_int32 srvRecordAge; /*Age of server record, in secs */ struct afs_stats_SrvUpDownInfo *upDownP; /*Ptr to current up/down - info being manipulated*/ + * info being manipulated */ /* * Write-lock the server table so we don't get any interference. @@ -393,25 +380,29 @@ void afs_CountServers() */ afs_stats_cmperf.srvMaxChainLength = 0; - afs_stats_cmperf.fs_UpDown[0].sumOfRecordAges = 0; + afs_stats_cmperf.fs_UpDown[0].sumOfRecordAges = 0; afs_stats_cmperf.fs_UpDown[0].ageOfYoungestRecord = 0; - afs_stats_cmperf.fs_UpDown[0].ageOfOldestRecord = 0; - memset((char *) afs_stats_cmperf.fs_UpDown[0].downIncidents, 0, AFS_STATS_NUM_DOWNTIME_INCIDENTS_BUCKETS * sizeof(afs_int32)); + afs_stats_cmperf.fs_UpDown[0].ageOfOldestRecord = 0; + memset((char *)afs_stats_cmperf.fs_UpDown[0].downIncidents, 0, + AFS_STATS_NUM_DOWNTIME_INCIDENTS_BUCKETS * sizeof(afs_int32)); - afs_stats_cmperf.fs_UpDown[1].sumOfRecordAges = 0; + afs_stats_cmperf.fs_UpDown[1].sumOfRecordAges = 0; afs_stats_cmperf.fs_UpDown[1].ageOfYoungestRecord = 0; - afs_stats_cmperf.fs_UpDown[1].ageOfOldestRecord = 0; - memset((char *) afs_stats_cmperf.fs_UpDown[1].downIncidents, 0, AFS_STATS_NUM_DOWNTIME_INCIDENTS_BUCKETS * sizeof(afs_int32)); + afs_stats_cmperf.fs_UpDown[1].ageOfOldestRecord = 0; + memset((char *)afs_stats_cmperf.fs_UpDown[1].downIncidents, 0, + AFS_STATS_NUM_DOWNTIME_INCIDENTS_BUCKETS * sizeof(afs_int32)); - afs_stats_cmperf.vl_UpDown[0].sumOfRecordAges = 0; + afs_stats_cmperf.vl_UpDown[0].sumOfRecordAges = 0; afs_stats_cmperf.vl_UpDown[0].ageOfYoungestRecord = 0; - afs_stats_cmperf.vl_UpDown[0].ageOfOldestRecord = 0; - memset((char *) afs_stats_cmperf.vl_UpDown[0].downIncidents, 0, AFS_STATS_NUM_DOWNTIME_INCIDENTS_BUCKETS * sizeof(afs_int32)); + afs_stats_cmperf.vl_UpDown[0].ageOfOldestRecord = 0; + memset((char *)afs_stats_cmperf.vl_UpDown[0].downIncidents, 0, + AFS_STATS_NUM_DOWNTIME_INCIDENTS_BUCKETS * sizeof(afs_int32)); - afs_stats_cmperf.vl_UpDown[1].sumOfRecordAges = 0; + afs_stats_cmperf.vl_UpDown[1].sumOfRecordAges = 0; afs_stats_cmperf.vl_UpDown[1].ageOfYoungestRecord = 0; - afs_stats_cmperf.vl_UpDown[1].ageOfOldestRecord = 0; - memset((char *) afs_stats_cmperf.vl_UpDown[1].downIncidents, 0, AFS_STATS_NUM_DOWNTIME_INCIDENTS_BUCKETS * sizeof(afs_int32)); + afs_stats_cmperf.vl_UpDown[1].ageOfOldestRecord = 0; + memset((char *)afs_stats_cmperf.vl_UpDown[1].downIncidents, 0, + AFS_STATS_NUM_DOWNTIME_INCIDENTS_BUCKETS * sizeof(afs_int32)); /* * Compute the current time, used to figure out server record ages. @@ -424,7 +415,8 @@ void afs_CountServers() */ for (currIdx = 0; currIdx < NSERVERS; currIdx++) { currChainLen = 0; - for (currSrvP = afs_servers[currIdx]; currSrvP; currSrvP = currSrvP->next) { + for (currSrvP = afs_servers[currIdx]; currSrvP; + currSrvP = currSrvP->next) { /* * Bump the current chain length. */ @@ -434,8 +426,8 @@ void afs_CountServers() * Any further tallying for this record will only be done if it has * been activated. */ - if ( (currSrvP->flags & AFS_SERVER_FLAG_ACTIVATED) && - currSrvP->addr && currSrvP->cell ) { + if ((currSrvP->flags & AFS_SERVER_FLAG_ACTIVATED) + && currSrvP->addr && currSrvP->cell) { /* * Compute the current server record's age, then remember it @@ -444,38 +436,34 @@ void afs_CountServers() srvRecordAge = currTime.tv_sec - currSrvP->activationTime; upDownP = GetUpDownStats(currSrvP); upDownP->sumOfRecordAges += srvRecordAge; - if ((upDownP->ageOfYoungestRecord == 0) || - (srvRecordAge < upDownP->ageOfYoungestRecord)) + if ((upDownP->ageOfYoungestRecord == 0) + || (srvRecordAge < upDownP->ageOfYoungestRecord)) upDownP->ageOfYoungestRecord = srvRecordAge; - if ((upDownP->ageOfOldestRecord == 0) || - (srvRecordAge > upDownP->ageOfOldestRecord)) + if ((upDownP->ageOfOldestRecord == 0) + || (srvRecordAge > upDownP->ageOfOldestRecord)) upDownP->ageOfOldestRecord = srvRecordAge; - if (currSrvP->numDowntimeIncidents <= - AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET0) - (upDownP->downIncidents[0])++; - else - if (currSrvP->numDowntimeIncidents <= - AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET1) - (upDownP->downIncidents[1])++; - else - if (currSrvP->numDowntimeIncidents <= - AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET2) - (upDownP->downIncidents[2])++; - else - if (currSrvP->numDowntimeIncidents <= - AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET3) - (upDownP->downIncidents[3])++; - else - if (currSrvP->numDowntimeIncidents <= - AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET4) - (upDownP->downIncidents[4])++; - else - (upDownP->downIncidents[5])++; - - - } /*Current server has been active*/ - } /*Walk this chain*/ + if (currSrvP->numDowntimeIncidents <= + AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET0) + (upDownP->downIncidents[0])++; + else if (currSrvP->numDowntimeIncidents <= + AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET1) + (upDownP->downIncidents[1])++; + else if (currSrvP->numDowntimeIncidents <= + AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET2) + (upDownP->downIncidents[2])++; + else if (currSrvP->numDowntimeIncidents <= + AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET3) + (upDownP->downIncidents[3])++; + else if (currSrvP->numDowntimeIncidents <= + AFS_STATS_MAX_DOWNTIME_INCIDENTS_BUCKET4) + (upDownP->downIncidents[4])++; + else + (upDownP->downIncidents[5])++; + + + } /*Current server has been active */ + } /*Walk this chain */ /* * Before advancing to the next chain, remember facts about this one. @@ -489,22 +477,20 @@ void afs_CountServers() afs_stats_cmperf.srvMaxChainLength = currChainLen; if (currChainLen > afs_stats_cmperf.srvMaxChainLengthHWM) afs_stats_cmperf.srvMaxChainLengthHWM = currChainLen; - } /*Update chain length maximum*/ - } /*For each hash chain*/ + } /*Update chain length maximum */ + } /*For each hash chain */ /* * We're done. Unlock the server table before returning to our caller. */ ReleaseReadLock(&afs_xserver); -} /*afs_CountServers*/ +} /*afs_CountServers */ /* check down servers (if adown), or running servers (if !adown) */ -void afs_CheckServers(adown, acellp) - struct cell *acellp; - int adown; - +void +afs_CheckServers(int adown, struct cell *acellp) { struct vrequest treq; struct server *ts; @@ -519,33 +505,52 @@ void afs_CheckServers(adown, acellp) char tbuffer[CVBS]; int srvAddrCount; struct srvAddr **addrs; + struct conn **conns; + int nconns; + struct rx_connection **rxconns; + int nrxconns; + afs_int32 *conntimer, *deltas; XSTATS_DECLS; AFS_STATCNT(afs_CheckServers); - if (code = afs_InitReq(&treq, &afs_osi_cred)) return; - ObtainReadLock(&afs_xserver); /* Necessary? */ - ObtainReadLock(&afs_xsrvAddr); + + conns = (struct conn **)0; + rxconns = (struct rx_connection **) 0; + conntimer = 0; + nconns = 0; + + if ((code = afs_InitReq(&treq, afs_osi_credp))) + return; + ObtainReadLock(&afs_xserver); /* Necessary? */ + ObtainReadLock(&afs_xsrvAddr); srvAddrCount = 0; - for (i=0;inext_bkt) { + for (i = 0; i < NSERVERS; i++) { + for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) { srvAddrCount++; } } addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs)); j = 0; - for (i=0;inext_bkt) { - if (j >= srvAddrCount) break; + for (i = 0; i < NSERVERS; i++) { + for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) { + if (j >= srvAddrCount) + break; addrs[j++] = sa; } } - ReleaseReadLock(&afs_xsrvAddr); + ReleaseReadLock(&afs_xsrvAddr); ReleaseReadLock(&afs_xserver); - for (i=0; iserver; if (!ts) @@ -557,8 +562,8 @@ void afs_CheckServers(adown, acellp) if (acellp && acellp != ts->cell) continue; - if ((!adown && (sa->sa_flags & SRVADDR_ISDOWN)) || - (adown && !(sa->sa_flags & SRVADDR_ISDOWN))) + if ((!adown && (sa->sa_flags & SRVADDR_ISDOWN)) + || (adown && !(sa->sa_flags & SRVADDR_ISDOWN))) continue; /* check vlserver with special code */ @@ -567,115 +572,150 @@ void afs_CheckServers(adown, acellp) continue; } - if (!ts->cell) /* not really an active server, anyway, it must */ - continue; /* have just been added by setsprefs */ + if (!ts->cell) /* not really an active server, anyway, it must */ + continue; /* have just been added by setsprefs */ /* get a connection, even if host is down; bumps conn ref count */ tu = afs_GetUser(treq.uid, ts->cell->cellNum, SHARED_LOCK); tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu, - 1/*force*/, 1/*create*/, SHARED_LOCK); + 1 /*force */ , 1 /*create */ , SHARED_LOCK); afs_PutUser(tu, SHARED_LOCK); - if (!tc) continue; + if (!tc) + continue; - if ((sa->sa_flags & SRVADDR_ISDOWN) || HaveCallBacksFrom(ts) || - (tc->srvr->server == afs_setTimeHost)) { + if ((sa->sa_flags & SRVADDR_ISDOWN) || HaveCallBacksFrom(sa->server) + || (tc->srvr->server == afs_setTimeHost)) { + conns[nconns]=tc; + rxconns[nconns]=tc->id; if (sa->sa_flags & SRVADDR_ISDOWN) { rx_SetConnDeadTime(tc->id, 3); - setTimer = 1; + conntimer[nconns]=1; } else { - setTimer = 0; + conntimer[nconns]=0; } + nconns++; + } + } /* Outer loop over addrs */ - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETTIME); - start = osi_Time(); /* time the gettimeofday call */ -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_GetTime(tc->id, &tv.tv_sec, &tv.tv_usec); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + start = osi_Time(); /* time the gettimeofday call */ + AFS_GUNLOCK(); + multi_Rx(rxconns,nconns) + { + tv.tv_sec = tv.tv_usec = 0; + multi_RXAFS_GetTime(&tv.tv_sec, &tv.tv_usec); + tc = conns[multi_i]; + sa = tc->srvr; + if (conntimer[multi_i] == 0) + rx_SetConnDeadTime(tc->id, AFS_RXDEADTIME); end = osi_Time(); - XSTATS_END_TIME; - /* - * If we're supposed to set the time, and the call worked - * quickly (same second response) and this is the host we - * use for the time and the time is really different, then - * really set the time - */ - if (code == 0 && start == end && afs_setTime != 0 && - (tc->srvr->server == afs_setTimeHost || - /* Sync only to a server in the local cell */ - (afs_setTimeHost == (struct server *)0 && - afs_IsPrimaryCell(ts->cell)))) { - - char msgbuf[90]; /* strlen("afs: setting clock...") + slop */ + if ((start == end) && !multi_error) + deltas[multi_i] = end - tv.tv_sec; + if (( multi_error >= 0 ) && (sa->sa_flags & SRVADDR_ISDOWN) && (tc->srvr == sa)) { + /* server back up */ + print_internet_address("afs: file server ", sa, " is back up", 2); + + ObtainWriteLock(&afs_xserver, 244); + ObtainWriteLock(&afs_xsrvAddr, 245); + afs_MarkServerUpOrDown(sa, 0); + ReleaseWriteLock(&afs_xsrvAddr); + ReleaseWriteLock(&afs_xserver); + + if (afs_waitForeverCount) { + afs_osi_Wakeup(&afs_waitForever); + } + } else { + if (multi_error < 0) { + /* server crashed */ + afs_ServerDown(sa); + ForceNewConnections(sa); /* multi homed clients */ + } + } + + } multi_End; + AFS_GLOCK(); + + /* + * If we're supposed to set the time, and the call worked + * quickly (same second response) and this is the host we + * use for the time and the time is really different, then + * really set the time + */ + if (afs_setTime != 0) { + for (i=0; isrvr; + + if ((tc->srvr->server == afs_setTimeHost || + /* Sync only to a server in the local cell */ + (afs_setTimeHost == (struct server *)0 && + afs_IsPrimaryCell(sa->server->cell)))) { /* set the time */ + char msgbuf[90]; /* strlen("afs: setting clock...") + slop */ delta = end - tv.tv_sec; /* how many secs fast we are */ + + afs_setTimeHost = tc->srvr->server; /* see if clock has changed enough to make it worthwhile */ if (delta >= AFS_MINCHANGE || delta <= -AFS_MINCHANGE) { + end = osi_Time(); if (delta > AFS_MAXCHANGEBACK) { /* setting clock too far back, just do it a little */ tv.tv_sec = end - AFS_MAXCHANGEBACK; + } else { + tv.tv_sec = end - delta; } afs_osi_SetTime(&tv); if (delta > 0) { strcpy(msgbuf, "afs: setting clock back "); if (delta > AFS_MAXCHANGEBACK) { - afs_strcat(msgbuf, afs_cv2string(&tbuffer[CVBS], AFS_MAXCHANGEBACK)); + afs_strcat(msgbuf, + afs_cv2string(&tbuffer[CVBS], + AFS_MAXCHANGEBACK)); afs_strcat(msgbuf, " seconds (of "); - afs_strcat(msgbuf, afs_cv2string(&tbuffer[CVBS], delta - AFS_MAXCHANGEBACK)); + afs_strcat(msgbuf, + afs_cv2string(&tbuffer[CVBS], + delta - + AFS_MAXCHANGEBACK)); afs_strcat(msgbuf, ", via "); - print_internet_address(msgbuf, sa, "); clock is still fast.", 0); + print_internet_address(msgbuf, sa, + "); clock is still fast.", + 0); } else { - afs_strcat(msgbuf, afs_cv2string(&tbuffer[CVBS], delta)); + afs_strcat(msgbuf, + afs_cv2string(&tbuffer[CVBS], delta)); afs_strcat(msgbuf, " seconds (via "); print_internet_address(msgbuf, sa, ").", 0); } } else { strcpy(msgbuf, "afs: setting clock ahead "); - afs_strcat(msgbuf, afs_cv2string(&tbuffer[CVBS], -delta)); + afs_strcat(msgbuf, + afs_cv2string(&tbuffer[CVBS], -delta)); afs_strcat(msgbuf, " seconds (via "); print_internet_address(msgbuf, sa, ").", 0); } - } - afs_setTimeHost = tc->srvr->server; - } - if (setTimer) - rx_SetConnDeadTime(tc->id, AFS_RXDEADTIME); - if (code >= 0 && (sa->sa_flags & SRVADDR_ISDOWN) && (tc->srvr == sa)) { - /* server back up */ - print_internet_address("afs: file server ", sa, " is back up", 2); - - ObtainWriteLock(&afs_xserver, 244); - ObtainWriteLock(&afs_xsrvAddr, 245); - afs_MarkServerUpOrDown(sa, 0); - ReleaseWriteLock(&afs_xsrvAddr); - ReleaseWriteLock(&afs_xserver); - - if (afs_waitForeverCount) { - afs_osi_Wakeup(&afs_waitForever); - } - } else { - if (code < 0) { - /* server crashed */ - afs_ServerDown(sa); - ForceNewConnections(sa); /* multi homed clients */ + /* We're only going to set it once; why bother looping? */ + break; } } } - - afs_PutConn(tc, SHARED_LOCK); /* done with it now */ - } /* Outer loop over addrs */ - + } + for (i = 0; i < nconns; i++) { + afs_PutConn(conns[i], SHARED_LOCK); /* done with it now */ + } + afs_osi_Free(addrs, srvAddrCount * sizeof(*addrs)); - + afs_osi_Free(conns, j * sizeof(struct conn *)); + afs_osi_Free(rxconns, j * sizeof(struct rx_connection *)); + afs_osi_Free(conntimer, j * sizeof(afs_int32)); + afs_osi_Free(deltas, j * sizeof(afs_int32)); + } /*afs_CheckServers*/ /* find a server structure given the host address */ -struct server *afs_FindServer (afs_int32 aserver, ushort aport, - afsUUID *uuidp, afs_int32 locktype) +struct server * +afs_FindServer(afs_int32 aserver, ushort aport, afsUUID * uuidp, + afs_int32 locktype) { struct server *ts; struct srvAddr *sa; @@ -685,22 +725,23 @@ struct server *afs_FindServer (afs_int32 aserver, ushort aport, if (uuidp) { i = afs_uuid_hash(uuidp) % NSERVERS; for (ts = afs_servers[i]; ts; ts = ts->next) { - if ( (ts->flags & SRVR_MULTIHOMED) && - (memcmp((char *)uuidp, (char *)&ts->sr_uuid, sizeof(*uuidp)) == 0) && - (!ts->addr || (ts->addr->sa_portal == aport)) ) + if ((ts->flags & SRVR_MULTIHOMED) + && + (memcmp((char *)uuidp, (char *)&ts->sr_uuid, sizeof(*uuidp)) + == 0) && (!ts->addr || (ts->addr->sa_portal == aport))) return ts; } } else { i = SHash(aserver); for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) { if ((sa->sa_ip == aserver) && (sa->sa_portal == aport)) { - return sa->server; + return sa->server; } } } - return (struct server *)0; + return NULL; -} /*afs_FindServer*/ +} /*afs_FindServer */ /* some code for creating new server structs and setting preferences follows @@ -732,25 +773,24 @@ NB: Has to be unsigned, since shifts on signed quantities may preserve */ #define ranstage(x) (x)= (afs_uint32) (3141592621U*((afs_uint32)x)+1) -extern afs_int32 rxi_getaddr(); - -unsigned int afs_random() +unsigned int +afs_random(void) { static afs_int32 state = 0; register int i; AFS_STATCNT(afs_random); if (!state) { - osi_timeval_t t; + osi_timeval_t t; osi_GetTime(&t); /* * 0xfffffff0 was changed to (~0 << 4) since it works no matter how many * bits are in a tv_usec */ - state = (t.tv_usec & (~0 << 4) ) + (rxi_getaddr() & 0xff); + state = (t.tv_usec & (~0 << 4)) + (rxi_getaddr() & 0xff); state += (t.tv_sec & 0xff); - for (i=0;i<30;i++) { + for (i = 0; i < 30; i++) { ranstage(state); } } @@ -758,7 +798,7 @@ unsigned int afs_random() ranstage(state); return (state); -} /*afs_random*/ +} /*afs_random */ /* returns int 0..14 using the high bits of a pseudo-random number instead of the low bits, as the low bits are "less random" than the high ones... @@ -766,85 +806,90 @@ unsigned int afs_random() need to multiply by something with lots of ones in it, so multiply by 8 or 16 is right out. */ -int afs_randomMod15() +int +afs_randomMod15(void) { -afs_uint32 temp; + afs_uint32 temp; -temp = afs_random() >> 4; -temp = (temp *15) >> 28; + temp = afs_random() >> 4; + temp = (temp * 15) >> 28; -return temp; + return temp; } -int afs_randomMod127() +int +afs_randomMod127(void) { -afs_uint32 temp; + afs_uint32 temp; -temp = afs_random() >> 7; -temp = (temp *127) >> 25; + temp = afs_random() >> 7; + temp = (temp * 127) >> 25; -return temp; + return temp; } /* afs_SortOneServer() * Sort all of the srvAddrs, of a server struct, by rank from low to high. */ -void afs_SortOneServer(struct server *asp) +void +afs_SortOneServer(struct server *asp) { - struct srvAddr **rootsa, *lowsa, *tsa, *lowprev; - int lowrank, rank; - - for (rootsa=&(asp->addr); *rootsa; rootsa=&(lowsa->next_sa)) { - lowprev = (struct srvAddr *)0; - lowsa = *rootsa; /* lowest sa is the first one */ - lowrank = lowsa->sa_iprank; - - for (tsa=*rootsa; tsa->next_sa; tsa=tsa->next_sa) { - rank = tsa->next_sa->sa_iprank; - if (rank < lowrank) { - lowprev = tsa; - lowsa = tsa->next_sa; - lowrank = lowsa->sa_iprank; - } - } - if (lowprev) { /* found one lower, so rearrange them */ - lowprev->next_sa = lowsa->next_sa; - lowsa->next_sa = *rootsa; - *rootsa = lowsa; - } - } + struct srvAddr **rootsa, *lowsa, *tsa, *lowprev; + int lowrank, rank; + + for (rootsa = &(asp->addr); *rootsa; rootsa = &(lowsa->next_sa)) { + lowprev = NULL; + lowsa = *rootsa; /* lowest sa is the first one */ + lowrank = lowsa->sa_iprank; + + for (tsa = *rootsa; tsa->next_sa; tsa = tsa->next_sa) { + rank = tsa->next_sa->sa_iprank; + if (rank < lowrank) { + lowprev = tsa; + lowsa = tsa->next_sa; + lowrank = lowsa->sa_iprank; + } + } + if (lowprev) { /* found one lower, so rearrange them */ + lowprev->next_sa = lowsa->next_sa; + lowsa->next_sa = *rootsa; + *rootsa = lowsa; + } + } } - + /* afs_SortServer() * Sort the pointer to servers by the server's rank (its lowest rank). * It is assumed that the server already has its IP addrs sorted (the * first being its lowest rank: afs_GetServer() calls afs_SortOneServer()). */ -void afs_SortServers(struct server *aservers[], int count) +void +afs_SortServers(struct server *aservers[], int count) { struct server *ts; int i, j, low; AFS_STATCNT(afs_SortServers); - for (i=0; iaddr)) - break; - if ((!aservers[low]) || (!aservers[low]->addr)) - break; - if (aservers[j]->addr->sa_iprank < aservers[low]->addr->sa_iprank) { - low = j; - } - } - if (low != i) { - ts = aservers[i]; - aservers[i] = aservers[low]; - aservers[low] = ts; - } + for (i = 0; i < count; i++) { + if (!aservers[i]) + break; + for (low = i, j = i + 1; j <= count; j++) { + if ((!aservers[j]) || (!aservers[j]->addr)) + break; + if ((!aservers[low]) || (!aservers[low]->addr)) + break; + if (aservers[j]->addr->sa_iprank < aservers[low]->addr->sa_iprank) { + low = j; + } + } + if (low != i) { + ts = aservers[i]; + aservers[i] = aservers[low]; + aservers[low] = ts; + } } -} /*afs_SortServers*/ +} /*afs_SortServers */ /* afs_SetServerPrefs is rather system-dependent. It pokes around in kernel data structures to determine what the local IP addresses and subnet masks @@ -891,111 +936,105 @@ void afs_SortServers(struct server *aservers[], int count) #define USEIFADDR - + #if defined(AFS_SUN5_ENV) && ! defined(AFS_SUN56_ENV) #include /* IP interface structure, one per local address */ -typedef struct ipif_s { /**/ - struct ipif_s * ipif_next; - struct ill_s * ipif_ill; /* Back pointer to our ill */ - long ipif_id; /* Logical unit number */ - u_int ipif_mtu; /* Starts at ipif_ill->ill_max_frag */ - afs_int32 ipif_local_addr; /* Local IP address for this if. */ - afs_int32 ipif_net_mask; /* Net mask for this interface. */ - afs_int32 ipif_broadcast_addr; /* Broadcast addr for this interface. */ - afs_int32 ipif_pp_dst_addr; /* Point-to-point dest address. */ - u_int ipif_flags; /* Interface flags. */ - u_int ipif_metric; /* BSD if metric, for compatibility. */ - u_int ipif_ire_type; /* LOCAL or LOOPBACK */ - mblk_t * ipif_arp_down_mp; /* Allocated at time arp comes up to - * prevent awkward out of mem condition - * later - */ - mblk_t * ipif_saved_ire_mp; /* Allocated for each extra IRE_SUBNET/ - * RESOLVER on this interface so that - * they can survive ifconfig down. - */ - /* - * The packet counts in the ipif contain the sum of the - * packet counts in dead IREs that were affiliated with - * this ipif. - */ - u_long ipif_fo_pkt_count; /* Forwarded thru our dead IREs */ - u_long ipif_ib_pkt_count; /* Inbound packets for our dead IREs */ - u_long ipif_ob_pkt_count; /* Outbound packets to our dead IREs */ - unsigned int - ipif_multicast_up : 1, /* We have joined the allhosts group */ - : 0; +typedef struct ipif_s { + /**/ struct ipif_s *ipif_next; + struct ill_s *ipif_ill; /* Back pointer to our ill */ + long ipif_id; /* Logical unit number */ + u_int ipif_mtu; /* Starts at ipif_ill->ill_max_frag */ + afs_int32 ipif_local_addr; /* Local IP address for this if. */ + afs_int32 ipif_net_mask; /* Net mask for this interface. */ + afs_int32 ipif_broadcast_addr; /* Broadcast addr for this interface. */ + afs_int32 ipif_pp_dst_addr; /* Point-to-point dest address. */ + u_int ipif_flags; /* Interface flags. */ + u_int ipif_metric; /* BSD if metric, for compatibility. */ + u_int ipif_ire_type; /* LOCAL or LOOPBACK */ + mblk_t *ipif_arp_down_mp; /* Allocated at time arp comes up to + * prevent awkward out of mem condition + * later + */ + mblk_t *ipif_saved_ire_mp; /* Allocated for each extra IRE_SUBNET/ + * RESOLVER on this interface so that + * they can survive ifconfig down. + */ + /* + * The packet counts in the ipif contain the sum of the + * packet counts in dead IREs that were affiliated with + * this ipif. + */ + u_long ipif_fo_pkt_count; /* Forwarded thru our dead IREs */ + u_long ipif_ib_pkt_count; /* Inbound packets for our dead IREs */ + u_long ipif_ob_pkt_count; /* Outbound packets to our dead IREs */ + unsigned int + ipif_multicast_up:1, /* We have joined the allhosts group */ + : 0; } ipif_t; -typedef struct ipfb_s { /**/ - struct ipf_s * ipfb_ipf; /* List of ... */ - kmutex_t ipfb_lock; /* Protect all ipf in list */ +typedef struct ipfb_s { + /**/ struct ipf_s *ipfb_ipf; /* List of ... */ + kmutex_t ipfb_lock; /* Protect all ipf in list */ } ipfb_t; -typedef struct ilm_s { /**/ - afs_int32 ilm_addr; - int ilm_refcnt; - u_int ilm_timer; /* IGMP */ - struct ipif_s * ilm_ipif; /* Back pointer to ipif */ - struct ilm_s * ilm_next; /* Linked list for each ill */ +typedef struct ilm_s { + /**/ afs_int32 ilm_addr; + int ilm_refcnt; + u_int ilm_timer; /* IGMP */ + struct ipif_s *ilm_ipif; /* Back pointer to ipif */ + struct ilm_s *ilm_next; /* Linked list for each ill */ } ilm_t; -typedef struct ill_s { /**/ - struct ill_s * ill_next; /* Chained in at ill_g_head. */ - struct ill_s ** ill_ptpn; /* Pointer to previous next. */ - queue_t * ill_rq; /* Read queue. */ - queue_t * ill_wq; /* Write queue. */ - - int ill_error; /* Error value sent up by device. */ - - ipif_t * ill_ipif; /* Interface chain for this ILL. */ - u_int ill_ipif_up_count; /* Number of IPIFs currently up. */ - u_int ill_max_frag; /* Max IDU. */ - char * ill_name; /* Our name. */ - u_int ill_name_length; /* Name length, incl. terminator. */ - u_int ill_subnet_type; /* IRE_RESOLVER or IRE_SUBNET. */ - u_int ill_ppa; /* Physical Point of Attachment num. */ - u_long ill_sap; - int ill_sap_length; /* Including sign (for position) */ - u_int ill_phys_addr_length; /* Excluding the sap. */ - mblk_t * ill_frag_timer_mp; /* Reassembly timer state. */ - ipfb_t * ill_frag_hash_tbl; /* Fragment hash list head. */ - - queue_t * ill_bind_pending_q; /* Queue waiting for DL_BIND_ACK. */ - ipif_t * ill_ipif_pending; /* IPIF waiting for DL_BIND_ACK. */ - - /* ill_hdr_length and ill_hdr_mp will be non zero if - * the underlying device supports the M_DATA fastpath - */ - int ill_hdr_length; +typedef struct ill_s { + /**/ struct ill_s *ill_next; /* Chained in at ill_g_head. */ + struct ill_s **ill_ptpn; /* Pointer to previous next. */ + queue_t *ill_rq; /* Read queue. */ + queue_t *ill_wq; /* Write queue. */ + + int ill_error; /* Error value sent up by device. */ + + ipif_t *ill_ipif; /* Interface chain for this ILL. */ + u_int ill_ipif_up_count; /* Number of IPIFs currently up. */ + u_int ill_max_frag; /* Max IDU. */ + char *ill_name; /* Our name. */ + u_int ill_name_length; /* Name length, incl. terminator. */ + u_int ill_subnet_type; /* IRE_RESOLVER or IRE_SUBNET. */ + u_int ill_ppa; /* Physical Point of Attachment num. */ + u_long ill_sap; + int ill_sap_length; /* Including sign (for position) */ + u_int ill_phys_addr_length; /* Excluding the sap. */ + mblk_t *ill_frag_timer_mp; /* Reassembly timer state. */ + ipfb_t *ill_frag_hash_tbl; /* Fragment hash list head. */ + + queue_t *ill_bind_pending_q; /* Queue waiting for DL_BIND_ACK. */ + ipif_t *ill_ipif_pending; /* IPIF waiting for DL_BIND_ACK. */ + + /* ill_hdr_length and ill_hdr_mp will be non zero if + * the underlying device supports the M_DATA fastpath + */ + int ill_hdr_length; - ilm_t * ill_ilm; /* Multicast mebership for lower ill */ + ilm_t *ill_ilm; /* Multicast mebership for lower ill */ - /* All non-nil cells between 'ill_first_mp_to_free' and - * 'ill_last_mp_to_free' are freed in ill_delete. - */ + /* All non-nil cells between 'ill_first_mp_to_free' and + * 'ill_last_mp_to_free' are freed in ill_delete. + */ #define ill_first_mp_to_free ill_hdr_mp - mblk_t * ill_hdr_mp; /* Contains fastpath template */ - mblk_t * ill_bcast_mp; /* DLPI header for broadcasts. */ - mblk_t * ill_bind_pending; /* T_BIND_REQ awaiting completion. */ - mblk_t * ill_resolver_mp; /* Resolver template. */ - mblk_t * ill_attach_mp; - mblk_t * ill_bind_mp; - mblk_t * ill_unbind_mp; - mblk_t * ill_detach_mp; + mblk_t *ill_hdr_mp; /* Contains fastpath template */ + mblk_t *ill_bcast_mp; /* DLPI header for broadcasts. */ + mblk_t *ill_bind_pending; /* T_BIND_REQ awaiting completion. */ + mblk_t *ill_resolver_mp; /* Resolver template. */ + mblk_t *ill_attach_mp; + mblk_t *ill_bind_mp; + mblk_t *ill_unbind_mp; + mblk_t *ill_detach_mp; #define ill_last_mp_to_free ill_detach_mp - u_int - ill_frag_timer_running : 1, - ill_needs_attach : 1, - ill_is_ptp : 1, - ill_priv_stream : 1, - ill_unbind_pending : 1, - - ill_pad_to_bit_31 : 27; - MI_HRT_DCL(ill_rtime) - MI_HRT_DCL(ill_rtmp) + u_int ill_frag_timer_running:1, ill_needs_attach:1, ill_is_ptp:1, + ill_priv_stream:1, ill_unbind_pending:1, ill_pad_to_bit_31:27; + MI_HRT_DCL(ill_rtime) + MI_HRT_DCL(ill_rtmp) } ill_t; #endif @@ -1008,178 +1047,187 @@ typedef struct ill_s { /**/ * passed into the kernel at startup time through the AFSOP_ADVISEADDR * system call. These are stored in the data structure * called 'afs_cb_interface'. + * + * struct srvAddr *sa; remote server + * afs_int32 addr; one of my local addr in net order + * afs_uint32 subnetmask; subnet mask of local addr in net order + * */ -afsi_SetServerIPRank(sa, addr, subnetmask) - struct srvAddr *sa; /* remote server */ - afs_int32 addr; /* one of my local addr in net order */ - afs_uint32 subnetmask; /* subnet mask of local addr in net order */ +int +afsi_SetServerIPRank(struct srvAddr *sa, afs_int32 addr, + afs_uint32 subnetmask) { - afs_uint32 myAddr, myNet, mySubnet, netMask; - afs_uint32 serverAddr ; - - myAddr = ntohl(addr); /* one of my IP addr in host order */ - serverAddr = ntohl(sa->sa_ip); /* server's IP addr in host order */ - subnetmask = ntohl(subnetmask);/* subnet mask in host order */ - - if ( IN_CLASSA(myAddr) ) netMask = IN_CLASSA_NET; - else if ( IN_CLASSB(myAddr) ) netMask = IN_CLASSB_NET; - else if ( IN_CLASSC(myAddr) ) netMask = IN_CLASSC_NET; - else netMask = 0; - - myNet = myAddr & netMask; - mySubnet = myAddr & subnetmask; - - if ( (serverAddr & netMask ) == myNet ) { - if ( (serverAddr & subnetmask ) == mySubnet) { - if ( serverAddr == myAddr ) { /* same machine */ - sa->sa_iprank = afs_min(sa->sa_iprank, TOPR); - } else { /* same subnet */ - sa->sa_iprank = afs_min(sa->sa_iprank, HI); - } - } else { /* same net */ - sa->sa_iprank = afs_min(sa->sa_iprank, MED); - } - } + afs_uint32 myAddr, myNet, mySubnet, netMask; + afs_uint32 serverAddr; + + myAddr = ntohl(addr); /* one of my IP addr in host order */ + serverAddr = ntohl(sa->sa_ip); /* server's IP addr in host order */ + subnetmask = ntohl(subnetmask); /* subnet mask in host order */ + + if (IN_CLASSA(myAddr)) + netMask = IN_CLASSA_NET; + else if (IN_CLASSB(myAddr)) + netMask = IN_CLASSB_NET; + else if (IN_CLASSC(myAddr)) + netMask = IN_CLASSC_NET; + else + netMask = 0; + + myNet = myAddr & netMask; + mySubnet = myAddr & subnetmask; + + if ((serverAddr & netMask) == myNet) { + if ((serverAddr & subnetmask) == mySubnet) { + if (serverAddr == myAddr) { /* same machine */ + sa->sa_iprank = afs_min(sa->sa_iprank, TOPR); + } else { /* same subnet */ + sa->sa_iprank = afs_min(sa->sa_iprank, HI); + } + } else { /* same net */ + sa->sa_iprank = afs_min(sa->sa_iprank, MED); + } + } } #else /* AFS_USERSPACE_IP_ADDR */ #if (! defined(AFS_SUN5_ENV)) && !defined(AFS_DARWIN60_ENV) && defined(USEIFADDR) void -afsi_SetServerIPRank(sa, ifa) - struct srvAddr *sa; - struct in_ifaddr *ifa; +afsi_SetServerIPRank(struct srvAddr *sa, struct in_ifaddr *ifa) { struct sockaddr_in *sin; int t; - + if ((ntohl(sa->sa_ip) & ifa->ia_netmask) == ifa->ia_net) { if ((ntohl(sa->sa_ip) & ifa->ia_subnetmask) == ifa->ia_subnet) { - sin=IA_SIN(ifa); - if ( SA2ULONG(sin) == ntohl(sa->sa_ip)) { /* ie, ME!!! */ + sin = IA_SIN(ifa); + if (SA2ULONG(sin) == ntohl(sa->sa_ip)) { /* ie, ME!!! */ sa->sa_iprank = TOPR; - } else { - t = HI + ifa->ia_ifp->if_metric; /* case #2 */ + } else { + t = HI + ifa->ia_ifp->if_metric; /* case #2 */ if (sa->sa_iprank > t) sa->sa_iprank = t; } } else { - t = MED + ifa->ia_ifp->if_metric;/* case #3 */ + t = MED + ifa->ia_ifp->if_metric; /* case #3 */ if (sa->sa_iprank > t) sa->sa_iprank = t; } } #ifdef IFF_POINTTOPOINT /* check for case #4 -- point-to-point link */ - if ((ifa->ia_ifp->if_flags & IFF_POINTOPOINT) && - (SA2ULONG(IA_DST(ifa)) == ntohl(sa->sa_ip))) { - if (ifa->ia_ifp->if_metric >= (MAXDEFRANK - MED)/PPWEIGHT) + if ((ifa->ia_ifp->if_flags & IFF_POINTOPOINT) + && (SA2ULONG(IA_DST(ifa)) == ntohl(sa->sa_ip))) { + if (ifa->ia_ifp->if_metric >= (MAXDEFRANK - MED) / PPWEIGHT) t = MAXDEFRANK; - else + else t = MED + (PPWEIGHT << ifa->ia_ifp->if_metric); if (sa->sa_iprank > t) sa->sa_iprank = t; } #endif /* IFF_POINTTOPOINT */ } -#endif /*(!defined(AFS_SUN5_ENV)) && defined(USEIFADDR)*/ +#endif /*(!defined(AFS_SUN5_ENV)) && defined(USEIFADDR) */ #if defined(AFS_DARWIN60_ENV) && defined(USEIFADDR) #ifndef afs_min #define afs_min(A,B) ((A)<(B)) ? (A) : (B) #endif void afsi_SetServerIPRank(sa, ifa) - struct srvAddr *sa; - struct ifaddr *ifa; + struct srvAddr *sa; + struct ifaddr *ifa; { struct sockaddr_in *sin; int t; - - afs_uint32 subnetmask, myAddr, myNet, myDstaddr, mySubnet, netMask; - afs_uint32 serverAddr ; - - if (ifa->ifa_addr->sa_family != AF_INET) - return; - sin=(struct sockaddr_in *)ifa->ifa_addr; - myAddr = ntohl(sin->sin_addr.s_addr); /* one of my IP addr in host order */ - serverAddr = ntohl(sa->sa_ip); /* server's IP addr in host order */ - sin=(struct sockaddr_in *)ifa->ifa_netmask; - subnetmask = ntohl(sin->sin_addr.s_addr);/* subnet mask in host order */ - sin=(struct sockaddr_in *)ifa->ifa_dstaddr; - if (sin) - myDstaddr=sin->sin_addr.s_addr; - - if ( IN_CLASSA(myAddr) ) netMask = IN_CLASSA_NET; - else if ( IN_CLASSB(myAddr) ) netMask = IN_CLASSB_NET; - else if ( IN_CLASSC(myAddr) ) netMask = IN_CLASSC_NET; - else netMask = 0; - - myNet = myAddr & netMask; - mySubnet = myAddr & subnetmask; - - if ( (serverAddr & netMask ) == myNet ) { - if ( (serverAddr & subnetmask ) == mySubnet) { - if ( serverAddr == myAddr ) { /* same machine */ - sa->sa_iprank = afs_min(sa->sa_iprank, TOPR); - } else { /* same subnet */ - sa->sa_iprank = afs_min(sa->sa_iprank, HI + ifa->ifa_metric); - } - } else { /* same net */ - sa->sa_iprank = afs_min(sa->sa_iprank, MED + ifa->ifa_metric); - } - } + + afs_uint32 subnetmask, myAddr, myNet, myDstaddr, mySubnet, netMask; + afs_uint32 serverAddr; + + if (ifa->ifa_addr->sa_family != AF_INET) + return; + sin = (struct sockaddr_in *)ifa->ifa_addr; + myAddr = ntohl(sin->sin_addr.s_addr); /* one of my IP addr in host order */ + serverAddr = ntohl(sa->sa_ip); /* server's IP addr in host order */ + sin = (struct sockaddr_in *)ifa->ifa_netmask; + subnetmask = ntohl(sin->sin_addr.s_addr); /* subnet mask in host order */ + sin = (struct sockaddr_in *)ifa->ifa_dstaddr; + if (sin) + myDstaddr = sin->sin_addr.s_addr; + + if (IN_CLASSA(myAddr)) + netMask = IN_CLASSA_NET; + else if (IN_CLASSB(myAddr)) + netMask = IN_CLASSB_NET; + else if (IN_CLASSC(myAddr)) + netMask = IN_CLASSC_NET; + else + netMask = 0; + + myNet = myAddr & netMask; + mySubnet = myAddr & subnetmask; + + if ((serverAddr & netMask) == myNet) { + if ((serverAddr & subnetmask) == mySubnet) { + if (serverAddr == myAddr) { /* same machine */ + sa->sa_iprank = afs_min(sa->sa_iprank, TOPR); + } else { /* same subnet */ + sa->sa_iprank = afs_min(sa->sa_iprank, HI + ifa->ifa_metric); + } + } else { /* same net */ + sa->sa_iprank = afs_min(sa->sa_iprank, MED + ifa->ifa_metric); + } + } #ifdef IFF_POINTTOPOINT /* check for case #4 -- point-to-point link */ - if ((ifa->ia_ifp->if_flags & IFF_POINTOPOINT) && - (myDstaddr == serverAddr))) { - if (ifa->ia_ifp->if_metric >= (MAXDEFRANK - MED)/PPWEIGHT) + if ((ifa->ia_ifp->if_flags & IFF_POINTOPOINT) + && (myDstaddr == serverAddr)) + ) { + if (ifa->ia_ifp->if_metric >= (MAXDEFRANK - MED) / PPWEIGHT) t = MAXDEFRANK; - else + else t = MED + (PPWEIGHT << ifa->->ifa_metric); if (sa->sa_iprank > t) sa->sa_iprank = t; - } + } #endif /* IFF_POINTTOPOINT */ } -#endif /*(!defined(AFS_SUN5_ENV)) && defined(USEIFADDR)*/ +#endif /*(!defined(AFS_SUN5_ENV)) && defined(USEIFADDR) */ #endif /* else AFS_USERSPACE_IP_ADDR */ #ifdef AFS_SGI62_ENV static int -afsi_enum_set_rank(struct hashbucket *h, caddr_t mkey, caddr_t arg1, - caddr_t arg2) -{ - afsi_SetServerIPRank((struct srvAddr *)arg1, (struct in_ifaddr*)h); - return 0; /* Never match, so we enumerate everyone */ -} -#endif /* AFS_SGI62_ENV */ -static afs_SetServerPrefs(sa) - struct srvAddr *sa; -{ + afsi_enum_set_rank(struct hashbucket *h, caddr_t mkey, caddr_t arg1, + caddr_t arg2) { + afsi_SetServerIPRank((struct srvAddr *)arg1, (struct in_ifaddr *)h); + return 0; /* Never match, so we enumerate everyone */ +} +#endif /* AFS_SGI62_ENV */ +static int afs_SetServerPrefs(struct srvAddr *sa) { #if defined(AFS_USERSPACE_IP_ADDR) - extern interfaceAddr afs_cb_interface; int i; - sa->sa_iprank = LO; - for (i=0; isa_iprank = LO; + for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) { + afsi_SetServerIPRank(sa, afs_cb_interface.addr_in[i], + afs_cb_interface.subnetmask[i]); } -#else /* AFS_USERSPACE_IP_ADDR */ +#else /* AFS_USERSPACE_IP_ADDR */ #if defined(AFS_SUN5_ENV) extern struct ill_s *ill_g_headp; ill_t *ill; - ipif_t * ipif; + ipif_t *ipif; int subnet, subnetmask, net, netmask; - long *addr = (long *) ill_g_headp; - extern struct ifnet *rxi_FindIfnet(); + long *addr = (long *)ill_g_headp; - if (sa) sa->sa_iprank= 0; - for (ill = (struct ill_s *)*addr /*ill_g_headp*/; ill; ill = ill->ill_next ) { + if (sa) + sa->sa_iprank = 0; + for (ill = (struct ill_s *)*addr /*ill_g_headp */ ; ill; + ill = ill->ill_next) { #ifdef AFS_SUN58_ENV /* Make sure this is an IPv4 ILL */ - if (ill->ill_isv6) continue; + if (ill->ill_isv6) + continue; #endif - for (ipif = ill->ill_ipif; ipif; ipif = ipif->ipif_next ) { + for (ipif = ill->ill_ipif; ipif; ipif = ipif->ipif_next) { subnet = ipif->ipif_local_addr & ipif->ipif_net_mask; subnetmask = ipif->ipif_net_mask; /* @@ -1196,37 +1244,38 @@ static afs_SetServerPrefs(sa) netmask = 0; } net = ipif->ipif_local_addr & netmask; -#ifdef notdef +#ifdef notdef if (!s) { - if (ipif->ipif_local_addr != 0x7f000001) { /* ignore loopback */ + if (ipif->ipif_local_addr != 0x7f000001) { /* ignore loopback */ *cnt += 1; - if (*cnt > 16) return; + if (*cnt > 16) + return; *addrp++ = ipif->ipif_local_addr; } } else #endif /* notdef */ - { + { /* XXXXXX Do the individual ip ranking below XXXXX */ if ((sa->sa_ip & netmask) == net) { if ((sa->sa_ip & subnetmask) == subnet) { - if (ipif->ipif_local_addr == sa->sa_ip) { /* ie, ME! */ + if (ipif->ipif_local_addr == sa->sa_ip) { /* ie, ME! */ sa->sa_iprank = TOPR; - } else { - sa->sa_iprank = HI + ipif->ipif_metric; /* case #2 */ + } else { + sa->sa_iprank = HI + ipif->ipif_metric; /* case #2 */ } - } else { - sa->sa_iprank = MED + ipif->ipif_metric; /* case #3 */ + } else { + sa->sa_iprank = MED + ipif->ipif_metric; /* case #3 */ } } else { sa->sa_iprank = LO + ipif->ipif_metric; /* case #4 */ } /* check for case #5 -- point-to-point link */ - if ((ipif->ipif_flags & IFF_POINTOPOINT) && - (ipif->ipif_pp_dst_addr == sa->sa_ip )) { + if ((ipif->ipif_flags & IFF_POINTOPOINT) + && (ipif->ipif_pp_dst_addr == sa->sa_ip)) { - if (ipif->ipif_metric >= (MAXDEFRANK - MED)/PPWEIGHT) + if (ipif->ipif_metric >= (MAXDEFRANK - MED) / PPWEIGHT) sa->sa_iprank = MAXDEFRANK; - else + else sa->sa_iprank = MED + (PPWEIGHT << ipif->ipif_metric); } } @@ -1234,105 +1283,109 @@ static afs_SetServerPrefs(sa) } #else #ifndef USEIFADDR - struct ifnet *ifn = (struct ifnet *)0; - struct in_ifaddr *ifad = (struct in_ifaddr *) 0; + struct ifnet *ifn = NULL; + struct in_ifaddr *ifad = (struct in_ifaddr *)0; struct sockaddr_in *sin; if (!sa) { -#ifdef notdef /* clean up, remove this */ +#ifdef notdef /* clean up, remove this */ for (ifn = ifnet; ifn != NULL; ifn = ifn->if_next) { - for (ifad = ifn->if_addrlist; ifad != NULL; ifad = ifad->ifa_next){ - if ((IFADDR2SA(ifad)->sa_family == AF_INET) - && !(ifn->if_flags & IFF_LOOPBACK)) { - *cnt += 1; - if (*cnt > 16) return; - *addrp++ = ((struct sockaddr_in *) IFADDR2SA(ifad))->sin_addr.s_addr; + for (ifad = ifn->if_addrlist; ifad != NULL; ifad = ifad->ifa_next) { + if ((IFADDR2SA(ifad)->sa_family == AF_INET) + && !(ifn->if_flags & IFF_LOOPBACK)) { + *cnt += 1; + if (*cnt > 16) + return; + *addrp++ = + ((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr. + s_addr; } - } - } -#endif /* notdef */ + }} +#endif /* notdef */ return; } - sa->sa_iprank= 0; + sa->sa_iprank = 0; #ifdef ADAPT_MTU ifn = rxi_FindIfnet(sa->sa_ip, &ifad); #endif - if (ifn) { /* local, more or less */ + if (ifn) { /* local, more or less */ #ifdef IFF_LOOPBACK - if (ifn->if_flags & IFF_LOOPBACK) { - sa->sa_iprank = TOPR; - goto end; - } + if (ifn->if_flags & IFF_LOOPBACK) { + sa->sa_iprank = TOPR; + goto end; + } #endif /* IFF_LOOPBACK */ - sin = (struct sockaddr_in *) IA_SIN(ifad); - if (SA2ULONG(sin) == sa->sa_ip) { - sa->sa_iprank = TOPR; - goto end; - } -#ifdef IFF_BROADCAST - if (ifn->if_flags & IFF_BROADCAST) { - if (sa->sa_ip == (sa->sa_ip & SA2ULONG(IA_BROAD(ifad)))) { - sa->sa_iprank = HI; + sin = (struct sockaddr_in *)IA_SIN(ifad); + if (SA2ULONG(sin) == sa->sa_ip) { + sa->sa_iprank = TOPR; goto end; - } - } + } +#ifdef IFF_BROADCAST + if (ifn->if_flags & IFF_BROADCAST) { + if (sa->sa_ip == (sa->sa_ip & SA2ULONG(IA_BROAD(ifad)))) { + sa->sa_iprank = HI; + goto end; + } + } #endif /* IFF_BROADCAST */ #ifdef IFF_POINTOPOINT - if (ifn->if_flags & IFF_POINTOPOINT) { - if (sa->sa_ip == SA2ULONG(IA_DST(ifad))) { - if (ifn->if_metric > 4) { - sa->sa_iprank = LO; - goto end; - } - else sa->sa_iprank = ifn->if_metric; + if (ifn->if_flags & IFF_POINTOPOINT) { + if (sa->sa_ip == SA2ULONG(IA_DST(ifad))) { + if (ifn->if_metric > 4) { + sa->sa_iprank = LO; + goto end; + } else + sa->sa_iprank = ifn->if_metric; + } } - } #endif /* IFF_POINTOPOINT */ - sa->sa_iprank += MED + ifn->if_metric; /* couldn't find anything better */ + sa->sa_iprank += MED + ifn->if_metric; /* couldn't find anything better */ } - -#else /* USEIFADDR */ - - if (sa) sa->sa_iprank= LO; +#else /* USEIFADDR */ + + if (sa) + sa->sa_iprank = LO; #ifdef AFS_SGI62_ENV - (void) hash_enum(&hashinfo_inaddr, afsi_enum_set_rank, HTF_INET, NULL, - (caddr_t)sa, NULL); + (void)hash_enum(&hashinfo_inaddr, afsi_enum_set_rank, HTF_INET, NULL, + (caddr_t) sa, NULL); #elif defined(AFS_DARWIN60_ENV) { - struct ifnet *ifn; - struct ifaddr *ifa; - TAILQ_FOREACH(ifn , &ifnet, if_link) { - TAILQ_FOREACH(ifa , &ifn->if_addrhead, ifa_link) { - afsi_SetServerIPRank(sa, ifa); - } - } - } + struct ifnet *ifn; + struct ifaddr *ifa; + TAILQ_FOREACH(ifn, &ifnet, if_link) { + TAILQ_FOREACH(ifa, &ifn->if_addrhead, ifa_link) { + afsi_SetServerIPRank(sa, ifa); + }}} #elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) { - struct in_ifaddr *ifa; - TAILQ_FOREACH(ifa , &in_ifaddrhead, ia_link) { - afsi_SetServerIPRank(sa, ifa); - } + struct in_ifaddr *ifa; + TAILQ_FOREACH(ifa, &in_ifaddrhead, ia_link) { + afsi_SetServerIPRank(sa, ifa); + }} +#elif defined(AFS_OBSD_ENV) + { + extern struct in_ifaddrhead in_ifaddr; + struct in_ifaddr *ifa; + for (ifa = in_ifaddr.tqh_first; ifa; ifa = ifa->ia_list.tqe_next) + afsi_SetServerIPRank(sa, ifa); } #else { - extern struct in_ifaddr *in_ifaddr; struct in_ifaddr *ifa; - for ( ifa = in_ifaddr; ifa; ifa = ifa->ia_next ) { + for (ifa = in_ifaddr; ifa; ifa = ifa->ia_next) { afsi_SetServerIPRank(sa, ifa); - } - } + }} #endif + end: +#endif /* USEIFADDR */ +#endif /* AFS_SUN5_ENV */ +#endif /* else AFS_USERSPACE_IP_ADDR */ + if (sa) + sa->sa_iprank += afs_randomMod15(); -#endif /* USEIFADDR */ -#endif /* AFS_SUN5_ENV */ -#endif /* else AFS_USERSPACE_IP_ADDR */ - - end: - if (sa) sa->sa_iprank += afs_randomMod15(); + return 0; +} /* afs_SetServerPrefs */ -return 0; -} /* afs_SetServerPrefs */ #undef TOPR #undef HI #undef MED @@ -1344,52 +1397,51 @@ return 0; * clean up all other structures that may reference it. * The afs_xserver and afs_xsrvAddr locks are assumed taken. */ -void afs_FlushServer(srvp) - struct server *srvp; -{ - afs_int32 i; - struct server *ts, **pts; - - /* Find any volumes residing on this server and flush their state */ - afs_ResetVolumes(srvp); - - /* Flush all callbacks in the all vcaches for this specific server */ - afs_FlushServerCBs(srvp); - - /* Remove all the callbacks structs */ - if (srvp->cbrs) { - struct afs_cbr *cb, *cbnext; - extern afs_lock_t afs_xvcb; - - MObtainWriteLock(&afs_xvcb, 300); - for (cb=srvp->cbrs; cb; cb=cbnext) { - cbnext = cb->next; - afs_FreeCBR(cb); - } - srvp->cbrs = (struct afs_cbr *)0; - ReleaseWriteLock(&afs_xvcb); - } - - /* If no more srvAddr structs hanging off of this server struct, - * then clean it up. - */ - if (!srvp->addr) { - /* Remove the server structure from the cell list - if there */ - afs_RemoveCellEntry(srvp); - - /* Remove from the afs_servers hash chain */ - for (i=0; inext), ts=*pts) { - if (ts == srvp) break; +void afs_FlushServer(struct server *srvp) { + afs_int32 i; + struct server *ts, **pts; + + /* Find any volumes residing on this server and flush their state */ + afs_ResetVolumes(srvp); + + /* Flush all callbacks in the all vcaches for this specific server */ + afs_FlushServerCBs(srvp); + + /* Remove all the callbacks structs */ + if (srvp->cbrs) { + struct afs_cbr *cb, *cbnext; + + MObtainWriteLock(&afs_xvcb, 300); + for (cb = srvp->cbrs; cb; cb = cbnext) { + cbnext = cb->next; + afs_FreeCBR(cb); + } srvp->cbrs = (struct afs_cbr *)0; + ReleaseWriteLock(&afs_xvcb); + } + + /* If no more srvAddr structs hanging off of this server struct, + * then clean it up. + */ + if (!srvp->addr) { + /* Remove the server structure from the cell list - if there */ + afs_RemoveCellEntry(srvp); + + /* Remove from the afs_servers hash chain */ + for (i = 0; i < NSERVERS; i++) { + for (pts = &(afs_servers[i]), ts = *pts; ts; + pts = &(ts->next), ts = *pts) { + if (ts == srvp) + break; + } + if (ts) + break; + } + if (ts) { + *pts = ts->next; /* Found it. Remove it */ + afs_osi_Free(ts, sizeof(struct server)); /* Free it */ + afs_totalServers--; } - if (ts) break; - } - if (ts) { - *pts = ts->next; /* Found it. Remove it */ - afs_osi_Free(ts, sizeof(struct server)); /* Free it */ - afs_totalServers--; - } - } + } } /* afs_RemoveSrvAddr() @@ -1400,27 +1452,26 @@ void afs_FlushServer(srvp) * The afs_xserver and afs_xsrvAddr locks are assumed taken. * It is not removed from the afs_srvAddrs hash chain. */ -void afs_RemoveSrvAddr(sap) - struct srvAddr *sap; -{ - struct srvAddr **psa, *sa; - struct server *srv; - - if (!sap) return; - srv = sap->server; - - /* Find the srvAddr in the server's list and remove it */ - for (psa=&(srv->addr), sa=*psa; sa; psa=&(sa->next_sa), sa=*psa) { - if (sa == sap) break; - } - if (sa) { - *psa = sa->next_sa; - sa->next_sa = 0; - sa->server = 0; - - /* Flush the server struct since it's IP address has changed */ - afs_FlushServer(srv); - } +void afs_RemoveSrvAddr(struct srvAddr *sap) { + struct srvAddr **psa, *sa; + struct server *srv; + + if (!sap) + return; + srv = sap->server; + + /* Find the srvAddr in the server's list and remove it */ + for (psa = &(srv->addr), sa = *psa; sa; psa = &(sa->next_sa), sa = *psa) { + if (sa == sap) + break; + } if (sa) { + *psa = sa->next_sa; + sa->next_sa = 0; + sa->server = 0; + + /* Flush the server struct since it's IP address has changed */ + afs_FlushServer(srv); + } } /* afs_GetServer() @@ -1429,217 +1480,257 @@ void afs_RemoveSrvAddr(sap) * If one does not exist, then one will be created. * aserver and aport must be in NET byte order. */ -struct server *afs_GetServer(afs_uint32 *aserverp, afs_int32 nservers, +struct server *afs_GetServer(afs_uint32 * aserverp, afs_int32 nservers, afs_int32 acell, u_short aport, - afs_int32 locktype, afsUUID *uuidp, - afs_int32 addr_uniquifier) -{ - struct server *oldts=0, *ts, *newts, *orphts=0; - struct srvAddr *oldsa, *sa, *newsa, *nextsa, *orphsa; + afs_int32 locktype, afsUUID * uuidp, + afs_int32 addr_uniquifier) { + struct server *oldts = 0, *ts, *newts, *orphts = 0; + struct srvAddr *oldsa, *newsa, *nextsa, *orphsa; u_short fsport; - afs_int32 iphash, k, srvcount=0; + afs_int32 iphash, k, srvcount = 0; unsigned int srvhash; AFS_STATCNT(afs_GetServer); - ObtainSharedLock(&afs_xserver,13); + ObtainSharedLock(&afs_xserver, 13); /* Check if the server struct exists and is up to date */ if (!uuidp) { - if (nservers != 1) panic("afs_GetServer: incorect count of servers"); - ObtainReadLock(&afs_xsrvAddr); - ts = afs_FindServer(aserverp[0], aport, NULL, locktype); - ReleaseReadLock(&afs_xsrvAddr); - if (ts && !(ts->flags & SRVR_MULTIHOMED)) { - /* Found a server struct that is not multihomed and has the - * IP address associated with it. A correct match. - */ - ReleaseSharedLock(&afs_xserver); - return(ts); - } + if (nservers != 1) + panic("afs_GetServer: incorect count of servers"); + ObtainReadLock(&afs_xsrvAddr); + ts = afs_FindServer(aserverp[0], aport, NULL, locktype); + ReleaseReadLock(&afs_xsrvAddr); + if (ts && !(ts->flags & SRVR_MULTIHOMED)) { + /* Found a server struct that is not multihomed and has the + * IP address associated with it. A correct match. + */ + ReleaseSharedLock(&afs_xserver); + return (ts); + } } else { - if (nservers <= 0) panic("afs_GetServer: incorrect count of servers"); - ts = afs_FindServer(0, aport, uuidp, locktype); - if (ts && (ts->sr_addr_uniquifier == addr_uniquifier) && ts->addr) { - /* Found a server struct that is multihomed and same - * uniqufier (same IP addrs). The above if statement is the - * same as in InstallUVolumeEntry(). - */ - ReleaseSharedLock(&afs_xserver); - return ts; - } - if (ts) oldts = ts; /* Will reuse if same uuid */ + if (nservers <= 0) + panic("afs_GetServer: incorrect count of servers"); + ts = afs_FindServer(0, aport, uuidp, locktype); + if (ts && (ts->sr_addr_uniquifier == addr_uniquifier) && ts->addr) { + /* Found a server struct that is multihomed and same + * uniqufier (same IP addrs). The above if statement is the + * same as in InstallUVolumeEntry(). + */ + ReleaseSharedLock(&afs_xserver); + return ts; + } + if (ts) + oldts = ts; /* Will reuse if same uuid */ } - UpgradeSToWLock(&afs_xserver,36); - ObtainWriteLock(&afs_xsrvAddr,116); + UpgradeSToWLock(&afs_xserver, 36); + ObtainWriteLock(&afs_xsrvAddr, 116); srvcount = afs_totalServers; /* Reuse/allocate a new server structure */ if (oldts) { - newts = oldts; + newts = oldts; } else { - newts = (struct server *) afs_osi_Alloc(sizeof(struct server)); - if (!newts) panic("malloc of server struct"); - afs_totalServers++; - memset((char *)newts, 0, sizeof(struct server)); - - /* Add the server struct to the afs_servers[] hash chain */ - srvhash = (uuidp ? (afs_uuid_hash(uuidp)%NSERVERS) : SHash(aserverp[0])); - newts->next = afs_servers[srvhash]; - afs_servers[srvhash] = newts; + newts = (struct server *)afs_osi_Alloc(sizeof(struct server)); + if (!newts) + panic("malloc of server struct"); + afs_totalServers++; + memset((char *)newts, 0, sizeof(struct server)); + + /* Add the server struct to the afs_servers[] hash chain */ + srvhash = + (uuidp ? (afs_uuid_hash(uuidp) % NSERVERS) : SHash(aserverp[0])); + newts->next = afs_servers[srvhash]; + afs_servers[srvhash] = newts; } /* Initialize the server structure */ - if (uuidp) { /* Multihomed */ - newts->sr_uuid = *uuidp; - newts->sr_addr_uniquifier = addr_uniquifier; - newts->flags |= SRVR_MULTIHOMED; + if (uuidp) { /* Multihomed */ + newts->sr_uuid = *uuidp; + newts->sr_addr_uniquifier = addr_uniquifier; + newts->flags |= SRVR_MULTIHOMED; } - if (acell) newts->cell = afs_GetCell(acell, 0); + if (acell) + newts->cell = afs_GetCell(acell, 0); fsport = (newts->cell ? newts->cell->fsport : AFS_FSPORT); /* For each IP address we are registering */ - for (k=0; knext_bkt) { - if ( (oldsa->sa_ip == aserverp[k]) && (oldsa->sa_portal == aport) ) break; - } - if (oldsa && (oldsa->server != newts)) { - afs_RemoveSrvAddr(oldsa); /* Remove from its server struct */ - oldsa->next_sa = newts->addr; /* Add to the new server struct */ - newts->addr = oldsa; - } - - /* Reuse/allocate a new srvAddr structure */ - if (oldsa) { - newsa = oldsa; - } else { - newsa = (struct srvAddr *) afs_osi_Alloc(sizeof(struct srvAddr)); - if (!newsa) panic("malloc of srvAddr struct"); - afs_totalSrvAddrs++; - memset((char *)newsa, 0, sizeof(struct srvAddr)); - - /* Add the new srvAddr to the afs_srvAddrs[] hash chain */ - newsa->next_bkt = afs_srvAddrs[iphash]; - afs_srvAddrs[iphash] = newsa; - - /* Hang off of the server structure */ - newsa->next_sa = newts->addr; - newts->addr = newsa; - - /* Initialize the srvAddr Structure */ - newsa->sa_ip = aserverp[k]; - newsa->sa_portal = aport; - } - - /* Update the srvAddr Structure */ - newsa->server = newts; - if (newts->flags & SRVR_ISDOWN) - newsa->sa_flags |= SRVADDR_ISDOWN; - if (uuidp) newsa->sa_flags |= SRVADDR_MH; - else newsa->sa_flags &= ~SRVADDR_MH; - - /* Compute preference values and resort */ - if (!newsa->sa_iprank) { - if (aport == fsport) { - afs_SetServerPrefs(newsa); /* new fileserver rank */ - } else { - newsa->sa_iprank = 10000 + afs_randomMod127(); /* new vlserver rank */ - } - } + for (k = 0; k < nservers; k++) { + iphash = SHash(aserverp[k]); + + /* Check if the srvAddr structure already exists. If so, remove + * it from its server structure and add it to the new one. + */ + for (oldsa = afs_srvAddrs[iphash]; oldsa; oldsa = oldsa->next_bkt) { + if ((oldsa->sa_ip == aserverp[k]) && (oldsa->sa_portal == aport)) + break; + } + if (oldsa && (oldsa->server != newts)) { + afs_RemoveSrvAddr(oldsa); /* Remove from its server struct */ + oldsa->next_sa = newts->addr; /* Add to the new server struct */ + newts->addr = oldsa; + } + + /* Reuse/allocate a new srvAddr structure */ + if (oldsa) { + newsa = oldsa; + } else { + newsa = (struct srvAddr *)afs_osi_Alloc(sizeof(struct srvAddr)); + if (!newsa) + panic("malloc of srvAddr struct"); + afs_totalSrvAddrs++; + memset((char *)newsa, 0, sizeof(struct srvAddr)); + + /* Add the new srvAddr to the afs_srvAddrs[] hash chain */ + newsa->next_bkt = afs_srvAddrs[iphash]; + afs_srvAddrs[iphash] = newsa; + + /* Hang off of the server structure */ + newsa->next_sa = newts->addr; + newts->addr = newsa; + + /* Initialize the srvAddr Structure */ + newsa->sa_ip = aserverp[k]; + newsa->sa_portal = aport; + } + + /* Update the srvAddr Structure */ + newsa->server = newts; + if (newts->flags & SRVR_ISDOWN) + newsa->sa_flags |= SRVADDR_ISDOWN; + if (uuidp) + newsa->sa_flags |= SRVADDR_MH; + else + newsa->sa_flags &= ~SRVADDR_MH; + + /* Compute preference values and resort */ + if (!newsa->sa_iprank) { + if (aport == fsport) { + afs_SetServerPrefs(newsa); /* new fileserver rank */ + } else { + newsa->sa_iprank = 10000 + afs_randomMod127(); /* new vlserver rank */ + } + } } - afs_SortOneServer(newts); /* Sort by rank */ + afs_SortOneServer(newts); /* Sort by rank */ /* If we reused the server struct, remove any of its srvAddr * structs that will no longer be associated with this server. */ - if (oldts) { /* reused the server struct */ - for (orphsa=newts->addr; orphsa; orphsa=nextsa) { - nextsa = orphsa->next_sa; - for (k=0; ksa_ip == aserverp[k]) break; /* belongs */ - } - if (k < nservers) continue; /* belongs */ - - /* Have a srvAddr struct. Now get a server struct (if not already) */ - if (!orphts) { - orphts = (struct server *) afs_osi_Alloc(sizeof(struct server)); - if (!orphts) panic("malloc of lo server struct"); - memset((char *)orphts, 0, sizeof(struct server)); - afs_totalServers++; - - /* Add the orphaned server to the afs_servers[] hash chain. - * Its iphash does not matter since we never look up the server - * in the afs_servers table by its ip address (only by uuid - - * which this has none). - */ - iphash = SHash(aserverp[k]); - orphts->next = afs_servers[iphash]; - afs_servers[iphash] = orphts; - - if (acell) orphts->cell = afs_GetCell(acell, 0); - } - - /* Hang the srvAddr struct off of the server structure. The server - * may have multiple srvAddrs, but it won't be marked multihomed. - */ - afs_RemoveSrvAddr(orphsa); /* remove */ - orphsa->next_sa = orphts->addr; /* hang off server struct */ - orphts->addr = orphsa; - orphsa->server = orphts; - orphsa->sa_flags |= SRVADDR_NOUSE; /* flag indicating not in use */ - orphsa->sa_flags &= ~SRVADDR_MH; /* Not multihomed */ - } + if (oldts) { /* reused the server struct */ + for (orphsa = newts->addr; orphsa; orphsa = nextsa) { + nextsa = orphsa->next_sa; + for (k = 0; k < nservers; k++) { + if (orphsa->sa_ip == aserverp[k]) + break; /* belongs */ + } + if (k < nservers) + continue; /* belongs */ + + /* Have a srvAddr struct. Now get a server struct (if not already) */ + if (!orphts) { + orphts = + (struct server *)afs_osi_Alloc(sizeof(struct server)); + if (!orphts) + panic("malloc of lo server struct"); + memset((char *)orphts, 0, sizeof(struct server)); + afs_totalServers++; + + /* Add the orphaned server to the afs_servers[] hash chain. + * Its iphash does not matter since we never look up the server + * in the afs_servers table by its ip address (only by uuid - + * which this has none). + */ + iphash = SHash(aserverp[k]); + orphts->next = afs_servers[iphash]; + afs_servers[iphash] = orphts; + + if (acell) + orphts->cell = afs_GetCell(acell, 0); + } + + /* Hang the srvAddr struct off of the server structure. The server + * may have multiple srvAddrs, but it won't be marked multihomed. + */ + afs_RemoveSrvAddr(orphsa); /* remove */ + orphsa->next_sa = orphts->addr; /* hang off server struct */ + orphts->addr = orphsa; + orphsa->server = orphts; + orphsa->sa_flags |= SRVADDR_NOUSE; /* flag indicating not in use */ + orphsa->sa_flags &= ~SRVADDR_MH; /* Not multihomed */ + } } - srvcount = afs_totalServers - srvcount; /* # servers added and removed */ + srvcount = afs_totalServers - srvcount; /* # servers added and removed */ if (srvcount) { - struct afs_stats_SrvUpDownInfo *upDownP; - /* With the introduction of this new record, we need to adjust the - * proper individual & global server up/down info. - */ - upDownP = GetUpDownStats(newts); - upDownP->numTtlRecords += srvcount; - afs_stats_cmperf.srvRecords += srvcount; - if (afs_stats_cmperf.srvRecords > afs_stats_cmperf.srvRecordsHWM) - afs_stats_cmperf.srvRecordsHWM = afs_stats_cmperf.srvRecords; + struct afs_stats_SrvUpDownInfo *upDownP; + /* With the introduction of this new record, we need to adjust the + * proper individual & global server up/down info. + */ + upDownP = GetUpDownStats(newts); + upDownP->numTtlRecords += srvcount; + afs_stats_cmperf.srvRecords += srvcount; + if (afs_stats_cmperf.srvRecords > afs_stats_cmperf.srvRecordsHWM) + afs_stats_cmperf.srvRecordsHWM = afs_stats_cmperf.srvRecords; } - ReleaseWriteLock(&afs_xsrvAddr); + ReleaseWriteLock(&afs_xsrvAddr); ReleaseWriteLock(&afs_xserver); - return(newts); -} /* afs_GetServer */ + return (newts); +} /* afs_GetServer */ + +void afs_ActivateServer(struct srvAddr *sap) { + osi_timeval_t currTime; /*Filled with current time */ + osi_timeval_t *currTimeP; /*Ptr to above */ + struct afs_stats_SrvUpDownInfo *upDownP; /*Ptr to up/down info record */ + struct server *aserver = sap->server; + + if (!(aserver->flags & AFS_SERVER_FLAG_ACTIVATED)) { + /* + * This server record has not yet been activated. Go for it, + * recording its ``birth''. + */ + aserver->flags |= AFS_SERVER_FLAG_ACTIVATED; + currTimeP = &currTime; + osi_GetuTime(currTimeP); + aserver->activationTime = currTime.tv_sec; + upDownP = GetUpDownStats(aserver); + if (aserver->flags & SRVR_ISDOWN) { + upDownP->numDownRecords++; + } else { + upDownP->numUpRecords++; + upDownP->numRecordsNeverDown++; + } + } +} + -void afs_ActivateServer(sap) - struct srvAddr *sap; +void shutdown_server() { - osi_timeval_t currTime; /*Filled with current time*/ - osi_timeval_t *currTimeP; /*Ptr to above*/ - struct afs_stats_SrvUpDownInfo *upDownP; /*Ptr to up/down info record*/ - struct server *aserver = sap->server; - - if (!(aserver->flags & AFS_SERVER_FLAG_ACTIVATED)) { - /* - * This server record has not yet been activated. Go for it, - * recording its ``birth''. - */ - aserver->flags |= AFS_SERVER_FLAG_ACTIVATED; - currTimeP = &currTime; - osi_GetuTime(currTimeP); - aserver->activationTime = currTime.tv_sec; - upDownP = GetUpDownStats(aserver); - if (aserver->flags & SRVR_ISDOWN) { - upDownP->numDownRecords++; - } else { - upDownP->numUpRecords++; - upDownP->numRecordsNeverDown++; - } - } + int i; + + for (i = 0; i < NSERVERS; i++) { + struct server *ts, *next; + + ts = afs_servers[i]; + while(ts) { + next = ts->next; + afs_osi_Free(ts, sizeof(struct server)); + ts = next; + } + } + + for (i = 0; i < NSERVERS; i++) { + struct srvAddr *sa, *next; + + sa = afs_srvAddrs[i]; + while(sa) { + next = sa->next_bkt; + afs_osi_Free(sa, sizeof(struct srvAddr)); + sa = next; + } + } } diff --git a/src/afs/afs_stat.c b/src/afs/afs_stat.c index 537cf8122..c2665af01 100644 --- a/src/afs/afs_stat.c +++ b/src/afs/afs_stat.c @@ -10,12 +10,13 @@ /* statistics-gathering package */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_stat.c,v 1.1.1.5 2001/09/11 14:24:46 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_stat.c,v 1.9 2003/07/15 23:14:13 shadow Exp $"); -#include "../afs/sysincludes.h" /*Standard vendor system headers*/ -#include "../afs/afsincludes.h" /*AFS-based standard headers*/ +#include "afs/sysincludes.h" /*Standard vendor system headers */ +#include "afsincludes.h" /*AFS-based standard headers */ #include "afs_stats.h" struct afs_CMStats afs_cmstats; @@ -37,20 +38,20 @@ afs_int32 afs_stats_XferSumBytes[AFS_STATS_NUM_FS_XFER_OPS]; * Environment: * This routine should only be called once, at initialization time. */ -void afs_InitStats() - -{ /*afs_InitStats*/ - - struct afs_stats_opTimingData *opTimeP; /*Ptr to curr timing struct*/ - struct afs_stats_xferData *xferP; /*Ptr to curr xfer struct*/ - int currIdx; /*Current index*/ +void +afs_InitStats(void) +{ + struct afs_stats_opTimingData *opTimeP; /*Ptr to curr timing struct */ + struct afs_stats_xferData *xferP; /*Ptr to curr xfer struct */ + int currIdx; /*Current index */ /* * First step is to zero everything out. */ memset((char *)(&afs_cmstats), 0, sizeof(struct afs_CMStats)); memset((char *)(&afs_stats_cmperf), 0, sizeof(struct afs_stats_CMPerf)); - memset((char *)(&afs_stats_cmfullperf), 0, sizeof(struct afs_stats_CMFullPerf)); + memset((char *)(&afs_stats_cmfullperf), 0, + sizeof(struct afs_stats_CMFullPerf)); /* * Some fields really should be non-zero at the start, so set 'em up. @@ -58,11 +59,13 @@ void afs_InitStats() afs_stats_cmperf.srvNumBuckets = NSERVERS; opTimeP = &(afs_stats_cmfullperf.rpc.fsRPCTimes[0]); - for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++, opTimeP++) + for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; + currIdx++, opTimeP++) opTimeP->minTime.tv_sec = 999999; opTimeP = &(afs_stats_cmfullperf.rpc.cmRPCTimes[0]); - for (currIdx = 0; currIdx < AFS_STATS_NUM_CM_RPC_OPS; currIdx++, opTimeP++) + for (currIdx = 0; currIdx < AFS_STATS_NUM_CM_RPC_OPS; + currIdx++, opTimeP++) opTimeP->minTime.tv_sec = 999999; xferP = &(afs_stats_cmfullperf.rpc.fsXferTimes[0]); @@ -70,25 +73,20 @@ void afs_InitStats() xferP->minTime.tv_sec = 999999; xferP->minBytes = 999999999; } - -} /*afs_InitStats*/ - - +} -afs_GetCMStat(ptr, size) - char **ptr; /* memory area */ - unsigned *size; /* # of bytes */ - { +void +afs_GetCMStat(char **ptr, unsigned *size) +{ #ifndef AFS_NOSTATS - AFS_STATCNT(afs_GetCMStat); - *ptr = (char *)&afs_cmstats; - *size = sizeof(afs_cmstats); + AFS_STATCNT(afs_GetCMStat); + *ptr = (char *)&afs_cmstats; + *size = sizeof(afs_cmstats); #endif /* AFS_NOSTATS */ - } +} -afs_AddToMean(oldMean, newValue) - struct afs_MeanStats *oldMean; - afs_int32 newValue; - { - AFS_STATCNT(afs_AddToMean); - } +void +afs_AddToMean(struct afs_MeanStats *oldMean, afs_int32 newValue) +{ + AFS_STATCNT(afs_AddToMean); +} diff --git a/src/afs/afs_stats.h b/src/afs/afs_stats.h index 39dfcd0d0..35f6575a1 100644 --- a/src/afs/afs_stats.h +++ b/src/afs/afs_stats.h @@ -14,10 +14,10 @@ * The remainder of this file contains the statistics gathering stuff. */ -#ifndef __TRANSARC_AFS_STATS_H__ -#define __TRANSARC_AFS_STATS_H__ +#ifndef __OPENAFS_AFS_STATS_H__ +#define __OPENAFS_AFS_STATS_H__ -#include "../afs/param.h" +#include "afs/param.h" /* the following is to work around a VAX compiler limitation */ #if defined(vax) @@ -46,7 +46,7 @@ typedef struct timeval osi_timeval_t; #endif /* !KERNEL */ #define XSTATS_DECLS struct afs_stats_opTimingData *opP; \ - osi_timeval_t opStartTime, opStopTime, elapsedTime; + osi_timeval_t opStartTime, opStopTime, elapsedTime; #define XSTATS_START_TIME(arg) \ opP = &(afs_stats_cmfullperf.rpc.fsRPCTimes[arg]); \ @@ -82,567 +82,567 @@ struct afs_MeanStats { * function call. */ struct afs_CMCallStats { - afs_int32 C_afs_init; /* afs_aix_subr.c*/ - afs_int32 C_gop_rdwr; /* afs_aix_subr.c*/ - afs_int32 C_aix_gnode_rele; /* afs_aix_subr.c*/ - afs_int32 C_gettimeofday; /* afs_aix_subr.c*/ - afs_int32 C_m_cpytoc; /* afs_aix_subr.c*/ - afs_int32 C_aix_vattr_null; /* afs_aix_subr.c*/ - afs_int32 C_afs_gn_ftrunc; /* afs_aixops.c*/ - afs_int32 C_afs_gn_rdwr; /* afs_aixops.c*/ - afs_int32 C_afs_gn_ioctl; /* afs_aixops.c*/ - afs_int32 C_afs_gn_lockctl; /* afs_aixops.c*/ - afs_int32 C_afs_gn_readlink; /* afs_aixops.c*/ - afs_int32 C_afs_gn_readdir; /* afs_aixops.c*/ - afs_int32 C_afs_gn_select; /* afs_aixops.c*/ - afs_int32 C_afs_gn_strategy; /* afs_aixops.c*/ - afs_int32 C_afs_gn_symlink; /* afs_aixops.c*/ - afs_int32 C_afs_gn_revoke; /* afs_aixops.c*/ - afs_int32 C_afs_gn_link; /* afs_aixops.c*/ - afs_int32 C_afs_gn_mkdir; /* afs_aixops.c*/ - afs_int32 C_afs_gn_mknod; /* afs_aixops.c*/ - afs_int32 C_afs_gn_remove; /* afs_aixops.c*/ - afs_int32 C_afs_gn_rename; /* afs_aixops.c*/ - afs_int32 C_afs_gn_rmdir; /* afs_aixops.c*/ - afs_int32 C_afs_gn_fid; /* afs_aixops.c*/ - afs_int32 C_afs_gn_lookup; /* afs_aixops.c*/ - afs_int32 C_afs_gn_open; /* afs_aixops.c*/ - afs_int32 C_afs_gn_create; /* afs_aixops.c*/ - afs_int32 C_afs_gn_hold; /* afs_aixops.c*/ - afs_int32 C_afs_gn_close; /* afs_aixops.c*/ - afs_int32 C_afs_gn_map; /* afs_aixops.c*/ - afs_int32 C_afs_gn_rele; /* afs_aixops.c*/ - afs_int32 C_afs_gn_unmap; /* afs_aixops.c*/ - afs_int32 C_afs_gn_access; /* afs_aixops.c*/ - afs_int32 C_afs_gn_getattr; /* afs_aixops.c*/ - afs_int32 C_afs_gn_setattr; /* afs_aixops.c*/ - afs_int32 C_afs_gn_fclear; /* afs_aixops.c*/ - afs_int32 C_afs_gn_fsync; /* afs_aixops.c*/ - afs_int32 C_pHash; /* afs_buffer.c*/ - afs_int32 C_DInit; /* afs_buffer.c*/ - afs_int32 C_DRead; /* afs_buffer.c*/ - afs_int32 C_FixupBucket; /* afs_buffer.c*/ - afs_int32 C_afs_newslot; /* afs_buffer.c*/ - afs_int32 C_DRelease; /* afs_buffer.c*/ - afs_int32 C_DFlush; /* afs_buffer.c*/ - afs_int32 C_DFlushEntry; /* afs_buffer.c*/ - afs_int32 C_DVOffset; /* afs_buffer.c*/ - afs_int32 C_DZap; /* afs_buffer.c*/ - afs_int32 C_DNew; /* afs_buffer.c*/ - afs_int32 C_shutdown_bufferpackage; /* afs_buffer.c*/ - afs_int32 C_afs_CheckKnownBad; /* afs_cache.c*/ - afs_int32 C_afs_RemoveVCB; /* afs_cache.c*/ - afs_int32 C_afs_NewVCache; /* afs_cache.c*/ - afs_int32 C_afs_FlushActiveVcaches; /* afs_cache.c*/ - afs_int32 C_afs_VerifyVCache; /* afs_cache.c*/ - afs_int32 C_afs_WriteVCache; /* afs_cache.c*/ - afs_int32 C_afs_GetVCache; /* afs_cache.c*/ - afs_int32 C_afs_StuffVcache; /* afs_cache.c*/ - afs_int32 C_afs_FindVCache; /* afs_cache.c*/ - afs_int32 C_afs_PutDCache; /* afs_cache.c*/ - afs_int32 C_afs_PutVCache; /* afs_cache.c*/ - afs_int32 C_CacheStoreProc; /* afs_cache.c*/ - afs_int32 C_afs_FindDCache; /* afs_cache.c*/ - afs_int32 C_afs_TryToSmush; /* afs_cache.c*/ - afs_int32 C_afs_AdjustSize; /* afs_cache.c*/ - afs_int32 C_afs_CheckSize; /* afs_cache.c*/ - afs_int32 C_afs_StoreWarn; /* afs_cache.c*/ - afs_int32 C_CacheFetchProc; /* afs_cache.c*/ - afs_int32 C_UFS_CacheStoreProc; /* afs_cache.c*/ - afs_int32 C_UFS_CacheFetchProc; /* afs_cache.c*/ - afs_int32 C_afs_GetDCache; /* afs_cache.c*/ - afs_int32 C_afs_SimpleVStat; /* afs_cache.c*/ - afs_int32 C_afs_ProcessFS; /* afs_cache.c*/ - afs_int32 C_afs_InitCacheInfo; /* afs_cache.c*/ - afs_int32 C_afs_InitVolumeInfo; /* afs_cache.c*/ - afs_int32 C_afs_InitCacheFile; /* afs_cache.c*/ - afs_int32 C_afs_CacheInit; /* afs_cache.c*/ - afs_int32 C_afs_GetDSlot; /* afs_cache.c*/ - afs_int32 C_afs_WriteThroughDSlots; /* afs_cache.c*/ - afs_int32 C_afs_MemGetDSlot; /* afs_cache.c*/ - afs_int32 C_afs_UFSGetDSlot; /* afs_cache.c*/ - afs_int32 C_afs_StoreDCache; /* afs_cache.c*/ - afs_int32 C_afs_StoreMini; /* afs_cache.c*/ - afs_int32 C_shutdown_cache; /* afs_cache.c*/ - afs_int32 C_afs_StoreAllSegments; /* afs_cache.c*/ - afs_int32 C_afs_InvalidateAllSegments; /* afs_cache.c*/ - afs_int32 C_afs_TruncateAllSegments; /* afs_cache.c*/ - afs_int32 C_afs_CheckVolSync; /* afs_cache.c*/ - afs_int32 C_afs_wakeup; /* afs_cache.c*/ - afs_int32 C_afs_CFileOpen; /* afs_cache.c*/ - afs_int32 C_afs_CFileTruncate; /* afs_cache.c*/ - afs_int32 C_afs_GetDownD; /* afs_cache.c*/ - afs_int32 C_afs_WriteDCache; /* afs_cache.c*/ - afs_int32 C_afs_FlushDCache; /* afs_cache.c*/ - afs_int32 C_afs_GetDownDSlot; /* afs_cache.c*/ - afs_int32 C_afs_FlushVCache; /* afs_cache.c*/ - afs_int32 C_afs_GetDownV; /* afs_cache.c*/ - afs_int32 C_afs_QueueVCB; /* afs_cache.c*/ - afs_int32 C_afs_call; /* afs_call.c */ - afs_int32 C_afs_syscall_call; /* afs_call.c*/ - afs_int32 C_syscall; /* afs_call.c*/ - afs_int32 C_lpioctl; /* afs_call.c*/ - afs_int32 C_lsetpag; /* afs_call.c*/ - afs_int32 C_afs_syscall; /* afs_call.c*/ - afs_int32 C_afs_CheckInit; /* afs_call.c*/ - afs_int32 C_afs_shutdown; /* afs_call.c*/ - afs_int32 C_shutdown_BKG; /* afs_call.c*/ - afs_int32 C_shutdown_afstest; /* afs_call.c*/ - afs_int32 C_SRXAFSCB_GetCE; /* afs_callback.c*/ - afs_int32 C_ClearCallBack; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_GetLock; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_CallBack; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_InitCallBackState; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_Probe; /* afs_callback.c*/ - afs_int32 C_afs_RXCallBackServer; /* afs_callback.c*/ - afs_int32 C_shutdown_CB; /* afs_callback.c*/ - afs_int32 C_afs_Chunk; /* afs_chunk.c*/ - afs_int32 C_afs_ChunkBase; /* afs_chunk.c*/ - afs_int32 C_afs_ChunkOffset; /* afs_chunk.c*/ - afs_int32 C_afs_ChunkSize; /* afs_chunk.c*/ - afs_int32 C_afs_ChunkToBase; /* afs_chunk.c*/ - afs_int32 C_afs_ChunkToSize; /* afs_chunk.c*/ - afs_int32 C_afs_SetChunkSize; /* afs_chunk.c*/ - - afs_int32 C_afs_config; /* afs_config.c*/ - afs_int32 C_mem_freebytes; /* afs_config.c*/ - afs_int32 C_mem_getbytes; /* afs_config.c*/ - afs_int32 C_fpalloc; /* afs_config.c*/ - afs_int32 C_kluge_init; /* afs_config.c*/ - afs_int32 C_ufdalloc; /* afs_config.c*/ - afs_int32 C_ufdfree; /* afs_config.c*/ - afs_int32 C_commit; /* afs_config.c*/ - afs_int32 C_dev_ialloc; /* afs_config.c*/ - afs_int32 C_ffree; /* afs_config.c*/ - afs_int32 C_iget; /* afs_config.c*/ - afs_int32 C_iptovp; /* afs_config.c*/ - afs_int32 C_ilock; /* afs_config.c*/ - afs_int32 C_irele; /* afs_config.c*/ - afs_int32 C_iput; /* afs_config.c*/ - - afs_int32 C_afs_Daemon; /* afs_daemons.c*/ - afs_int32 C_afs_CheckRootVolume; /* afs_daemons.c*/ - afs_int32 C_BPath; /* afs_daemons.c*/ - afs_int32 C_BPrefetch; /* afs_daemons.c*/ - afs_int32 C_BStore; /* afs_daemons.c*/ - afs_int32 C_afs_BBusy; /* afs_daemons.c*/ - afs_int32 C_afs_BQueue; /* afs_daemons.c*/ - afs_int32 C_afs_BRelease; /* afs_daemons.c*/ - afs_int32 C_afs_BackgroundDaemon; /* afs_daemons.c*/ - afs_int32 C_shutdown_daemons; /* afs_daemons.c*/ - afs_int32 C_exporter_add; /* afs_exporter.c*/ - afs_int32 C_exporter_find; /* afs_exporter.c*/ - afs_int32 C_afs_gfs_kalloc; /* afs_gfs_subr.c*/ - afs_int32 C_IsAfsVnode; /* afs_gfs_subr.c*/ - afs_int32 C_SetAfsVnode; /* afs_gfs_subr.c*/ - afs_int32 C_afs_gfs_kfree; /* afs_gfs_subr.c*/ - afs_int32 C_gop_lookupname; /* afs_gfs_subr.c*/ - afs_int32 C_gfsvop_getattr; /* afs_gfs_subr.c*/ - afs_int32 C_gfsvop_rdwr; /* afs_gfs_subr.c*/ - afs_int32 C_afs_uniqtime; /* afs_gfs_subr.c*/ - afs_int32 C_gfs_vattr_null; /* afs_gfs_subr.c*/ - afs_int32 C_afs_lock; /* afs_gfsops.c*/ - afs_int32 C_afs_unlock; /* afs_gfsops.c*/ - afs_int32 C_afs_update; /* afs_gfsops.c*/ - afs_int32 C_afs_gclose; /* afs_gfsops.c*/ - afs_int32 C_afs_gopen; /* afs_gfsops.c*/ - afs_int32 C_afs_greadlink; /* afs_gfsops.c*/ - afs_int32 C_afs_select; /* afs_gfsops.c*/ - afs_int32 C_afs_gbmap; /* afs_gfsops.c*/ - afs_int32 C_afs_getfsdata; /* afs_gfsops.c*/ - afs_int32 C_afs_gsymlink; /* afs_gfsops.c*/ - afs_int32 C_afs_namei; /* afs_gfsops.c*/ - afs_int32 C_printgnode; /* afs_gfsops.c*/ - afs_int32 C_HaveGFSLock; /* afs_gfsops.c*/ - afs_int32 C_afs_gmount; /* afs_gfsops.c*/ - afs_int32 C_AddGFSLock; /* afs_gfsops.c*/ - afs_int32 C_RemoveGFSLock; /* afs_gfsops.c*/ - afs_int32 C_afs_grlock; /* afs_gfsops.c*/ - afs_int32 C_afs_gumount; /* afs_gfsops.c*/ - afs_int32 C_afs_gget; /* afs_gfsops.c*/ - afs_int32 C_afs_glink; /* afs_gfsops.c*/ - afs_int32 C_afs_gmkdir; /* afs_gfsops.c*/ - afs_int32 C_afs_sbupdate; /* afs_gfsops.c*/ - afs_int32 C_afs_unlink; /* afs_gfsops.c*/ - afs_int32 C_afs_grmdir; /* afs_gfsops.c*/ - afs_int32 C_afs_makenode; /* afs_gfsops.c*/ - afs_int32 C_afs_grename; /* afs_gfsops.c*/ - afs_int32 C_afs_rele; /* afs_gfsops.c*/ - afs_int32 C_afs_syncgp; /* afs_gfsops.c*/ - afs_int32 C_afs_getval; /* afs_gfsops.c*/ - afs_int32 C_afs_gfshack; /* afs_gfsops.c*/ - afs_int32 C_afs_trunc; /* afs_gfsops.c*/ - afs_int32 C_afs_rwgp; /* afs_gfsops.c*/ - afs_int32 C_afs_stat; /* afs_gfsops.c*/ - afs_int32 C_afsc_link; /* afs_hp_subr.c*/ - afs_int32 C_hpsobind; /* afs_hp_subr.c*/ - afs_int32 C_hpsoclose; /* afs_hp_subr.c*/ - afs_int32 C_hpsocreate; /* afs_hp_subr.c*/ - afs_int32 C_hpsoreserve; /* afs_hp_subr.c*/ - afs_int32 C_afs_vfs_mount; /* afs_hp_subr.c*/ - afs_int32 C_devtovfs; /* afs_istuff.c*/ - afs_int32 C_igetinode; /* afs_istuff.c*/ - afs_int32 C_afs_syscall_iopen; /* afs_istuff.c*/ - afs_int32 C_iopen; /* afs_istuff.c*/ - afs_int32 C_afs_syscall_iincdec; /* afs_istuff.c*/ - afs_int32 C_afs_syscall_ireadwrite; /* afs_istuff.c*/ - afs_int32 C_iincdec; /* afs_istuff.c*/ - afs_int32 C_ireadwrite; /* afs_istuff.c*/ - afs_int32 C_oiread; /* afs_istuff.c*/ - afs_int32 C_AHash; /* afs_istuff.c*/ - afs_int32 C_QTOA; /* afs_istuff.c*/ - afs_int32 C_afs_FindPartByDev; /* afs_istuff.c*/ - afs_int32 C_aux_init; /* afs_istuff.c*/ - afs_int32 C_afs_GetNewPart; /* afs_istuff.c*/ - afs_int32 C_afs_InitAuxVolFile; /* afs_istuff.c*/ - afs_int32 C_afs_CreateAuxEntry; /* afs_istuff.c*/ - afs_int32 C_afs_GetAuxSlot; /* afs_istuff.c*/ - afs_int32 C_afs_GetDownAux; /* afs_istuff.c*/ - afs_int32 C_afs_FlushAuxCache; /* afs_istuff.c*/ - afs_int32 C_afs_GetAuxInode; /* afs_istuff.c*/ - afs_int32 C_afs_PutAuxInode; /* afs_istuff.c*/ - afs_int32 C_afs_ReadAuxInode; /* afs_istuff.c*/ - afs_int32 C_afs_WriteAuxInode; /* afs_istuff.c*/ - afs_int32 C_afs_auxcall; /* afs_istuff.c*/ - afs_int32 C_tmpdbg_auxtbl; /* afs_istuff.c*/ - afs_int32 C_tmpdbg_parttbl; /* afs_istuff.c*/ - afs_int32 C_idec; /* afs_istuff.c*/ - afs_int32 C_iinc; /* afs_istuff.c*/ - afs_int32 C_iread; /* afs_istuff.c*/ - afs_int32 C_iwrite; /* afs_istuff.c*/ - afs_int32 C_getinode; /* afs_istuff.c*/ - afs_int32 C_trygetfs; /* afs_istuff.c*/ - afs_int32 C_iforget; /* afs_istuff.c*/ - afs_int32 C_afs_syscall_icreate; /* afs_istuff.c*/ - afs_int32 C_icreate; /* afs_istuff.c*/ - afs_int32 C_Lock_Init; /* afs_lock.c*/ - afs_int32 C_Lock_Obtain; /* afs_lock.c*/ - afs_int32 C_Lock_ReleaseR; /* afs_lock.c*/ - afs_int32 C_Lock_ReleaseW; /* afs_lock.c*/ - afs_int32 C_afs_BozonLock; /* afs_lock.c*/ - afs_int32 C_afs_BozonUnlock; /* afs_lock.c*/ - afs_int32 C_osi_SleepR; /* afs_lock.c*/ - afs_int32 C_osi_SleepS; /* afs_lock.c*/ - afs_int32 C_osi_SleepW; /* afs_lock.c*/ - afs_int32 C_osi_Sleep; /* afs_lock */ - afs_int32 C_afs_BozonInit; /* afs_lock.c*/ - afs_int32 C_afs_CheckBozonLock; /* afs_lock.c*/ - afs_int32 C_afs_CheckBozonLockBlocking; /* afs_lock.c*/ - afs_int32 C_xxxinit; /* afs_main.c*/ - afs_int32 C_KernelEntry; /* afs_main.c*/ - afs_int32 C_afs_InitMemCache; /* afs_memcache.c*/ - afs_int32 C_afs_LookupMCE; /* afs_memcache.c*/ - afs_int32 C_afs_MemReadBlk; /* afs_memcache.c*/ - afs_int32 C_afs_MemReadUIO; /* afs_memcache.c*/ - afs_int32 C_afs_MemWriteBlk; /* afs_memcache.c*/ - afs_int32 C_afs_MemCacheStoreProc; /* afs_memcache.c*/ - afs_int32 C_afs_MemCacheTruncate; /* afs_memcache.c*/ - afs_int32 C_afs_MemWriteUIO; /* afs_memcache.c*/ - afs_int32 C_afs_MemCacheFetchProc; /* afs_memcache.c*/ - afs_int32 C_afs_vnode_pager_create; /* afs_next_aux.c*/ - afs_int32 C_next_KernelEntry; /* afs_next_subr.c*/ - afs_int32 C_afs_GetNfsClientPag; /* afs_nfsclnt.c*/ - afs_int32 C_afs_FindNfsClientPag; /* afs_nfsclnt.c*/ - afs_int32 C_afs_PutNfsClientPag; /* afs_nfsclnt.c*/ - afs_int32 C_afs_nfsclient_reqhandler; /* afs_nfsclnt.c*/ - afs_int32 C_afs_nfsclient_GC; /* afs_nfsclnt.c*/ - afs_int32 C_afs_nfsclient_hold; /* afs_nfsclnt.c*/ - afs_int32 C_afs_nfsclient_stats; /* afs_nfsclnt.c*/ - afs_int32 C_afs_nfsclient_sysname; /* afs_nfsclnt.c*/ - afs_int32 C_afs_nfsclient_shutdown; /* afs_nfsclnt.c*/ + afs_int32 C_afs_init; /* afs_aix_subr.c */ + afs_int32 C_gop_rdwr; /* afs_aix_subr.c */ + afs_int32 C_aix_gnode_rele; /* afs_aix_subr.c */ + afs_int32 C_gettimeofday; /* afs_aix_subr.c */ + afs_int32 C_m_cpytoc; /* afs_aix_subr.c */ + afs_int32 C_aix_vattr_null; /* afs_aix_subr.c */ + afs_int32 C_afs_gn_ftrunc; /* afs_aixops.c */ + afs_int32 C_afs_gn_rdwr; /* afs_aixops.c */ + afs_int32 C_afs_gn_ioctl; /* afs_aixops.c */ + afs_int32 C_afs_gn_lockctl; /* afs_aixops.c */ + afs_int32 C_afs_gn_readlink; /* afs_aixops.c */ + afs_int32 C_afs_gn_readdir; /* afs_aixops.c */ + afs_int32 C_afs_gn_select; /* afs_aixops.c */ + afs_int32 C_afs_gn_strategy; /* afs_aixops.c */ + afs_int32 C_afs_gn_symlink; /* afs_aixops.c */ + afs_int32 C_afs_gn_revoke; /* afs_aixops.c */ + afs_int32 C_afs_gn_link; /* afs_aixops.c */ + afs_int32 C_afs_gn_mkdir; /* afs_aixops.c */ + afs_int32 C_afs_gn_mknod; /* afs_aixops.c */ + afs_int32 C_afs_gn_remove; /* afs_aixops.c */ + afs_int32 C_afs_gn_rename; /* afs_aixops.c */ + afs_int32 C_afs_gn_rmdir; /* afs_aixops.c */ + afs_int32 C_afs_gn_fid; /* afs_aixops.c */ + afs_int32 C_afs_gn_lookup; /* afs_aixops.c */ + afs_int32 C_afs_gn_open; /* afs_aixops.c */ + afs_int32 C_afs_gn_create; /* afs_aixops.c */ + afs_int32 C_afs_gn_hold; /* afs_aixops.c */ + afs_int32 C_afs_gn_close; /* afs_aixops.c */ + afs_int32 C_afs_gn_map; /* afs_aixops.c */ + afs_int32 C_afs_gn_rele; /* afs_aixops.c */ + afs_int32 C_afs_gn_unmap; /* afs_aixops.c */ + afs_int32 C_afs_gn_access; /* afs_aixops.c */ + afs_int32 C_afs_gn_getattr; /* afs_aixops.c */ + afs_int32 C_afs_gn_setattr; /* afs_aixops.c */ + afs_int32 C_afs_gn_fclear; /* afs_aixops.c */ + afs_int32 C_afs_gn_fsync; /* afs_aixops.c */ + afs_int32 C_pHash; /* afs_buffer.c */ + afs_int32 C_DInit; /* afs_buffer.c */ + afs_int32 C_DRead; /* afs_buffer.c */ + afs_int32 C_FixupBucket; /* afs_buffer.c */ + afs_int32 C_afs_newslot; /* afs_buffer.c */ + afs_int32 C_DRelease; /* afs_buffer.c */ + afs_int32 C_DFlush; /* afs_buffer.c */ + afs_int32 C_DFlushEntry; /* afs_buffer.c */ + afs_int32 C_DVOffset; /* afs_buffer.c */ + afs_int32 C_DZap; /* afs_buffer.c */ + afs_int32 C_DNew; /* afs_buffer.c */ + afs_int32 C_shutdown_bufferpackage; /* afs_buffer.c */ + afs_int32 C_afs_CheckKnownBad; /* afs_cache.c */ + afs_int32 C_afs_RemoveVCB; /* afs_cache.c */ + afs_int32 C_afs_NewVCache; /* afs_cache.c */ + afs_int32 C_afs_FlushActiveVcaches; /* afs_cache.c */ + afs_int32 C_afs_VerifyVCache; /* afs_cache.c */ + afs_int32 C_afs_WriteVCache; /* afs_cache.c */ + afs_int32 C_afs_GetVCache; /* afs_cache.c */ + afs_int32 C_afs_StuffVcache; /* afs_cache.c */ + afs_int32 C_afs_FindVCache; /* afs_cache.c */ + afs_int32 C_afs_PutDCache; /* afs_cache.c */ + afs_int32 C_afs_PutVCache; /* afs_cache.c */ + afs_int32 C_CacheStoreProc; /* afs_cache.c */ + afs_int32 C_afs_FindDCache; /* afs_cache.c */ + afs_int32 C_afs_TryToSmush; /* afs_cache.c */ + afs_int32 C_afs_AdjustSize; /* afs_cache.c */ + afs_int32 C_afs_CheckSize; /* afs_cache.c */ + afs_int32 C_afs_StoreWarn; /* afs_cache.c */ + afs_int32 C_CacheFetchProc; /* afs_cache.c */ + afs_int32 C_UFS_CacheStoreProc; /* afs_cache.c */ + afs_int32 C_UFS_CacheFetchProc; /* afs_cache.c */ + afs_int32 C_afs_GetDCache; /* afs_cache.c */ + afs_int32 C_afs_SimpleVStat; /* afs_cache.c */ + afs_int32 C_afs_ProcessFS; /* afs_cache.c */ + afs_int32 C_afs_InitCacheInfo; /* afs_cache.c */ + afs_int32 C_afs_InitVolumeInfo; /* afs_cache.c */ + afs_int32 C_afs_InitCacheFile; /* afs_cache.c */ + afs_int32 C_afs_CacheInit; /* afs_cache.c */ + afs_int32 C_afs_GetDSlot; /* afs_cache.c */ + afs_int32 C_afs_WriteThroughDSlots; /* afs_cache.c */ + afs_int32 C_afs_MemGetDSlot; /* afs_cache.c */ + afs_int32 C_afs_UFSGetDSlot; /* afs_cache.c */ + afs_int32 C_afs_StoreDCache; /* afs_cache.c */ + afs_int32 C_afs_StoreMini; /* afs_cache.c */ + afs_int32 C_shutdown_cache; /* afs_cache.c */ + afs_int32 C_afs_StoreAllSegments; /* afs_cache.c */ + afs_int32 C_afs_InvalidateAllSegments; /* afs_cache.c */ + afs_int32 C_afs_TruncateAllSegments; /* afs_cache.c */ + afs_int32 C_afs_CheckVolSync; /* afs_cache.c */ + afs_int32 C_afs_wakeup; /* afs_cache.c */ + afs_int32 C_afs_CFileOpen; /* afs_cache.c */ + afs_int32 C_afs_CFileTruncate; /* afs_cache.c */ + afs_int32 C_afs_GetDownD; /* afs_cache.c */ + afs_int32 C_afs_WriteDCache; /* afs_cache.c */ + afs_int32 C_afs_FlushDCache; /* afs_cache.c */ + afs_int32 C_afs_GetDownDSlot; /* afs_cache.c */ + afs_int32 C_afs_FlushVCache; /* afs_cache.c */ + afs_int32 C_afs_GetDownV; /* afs_cache.c */ + afs_int32 C_afs_QueueVCB; /* afs_cache.c */ + afs_int32 C_afs_call; /* afs_call.c */ + afs_int32 C_afs_syscall_call; /* afs_call.c */ + afs_int32 C_syscall; /* afs_call.c */ + afs_int32 C_lpioctl; /* afs_call.c */ + afs_int32 C_lsetpag; /* afs_call.c */ + afs_int32 C_afs_syscall; /* afs_call.c */ + afs_int32 C_afs_CheckInit; /* afs_call.c */ + afs_int32 C_afs_shutdown; /* afs_call.c */ + afs_int32 C_shutdown_BKG; /* afs_call.c */ + afs_int32 C_shutdown_afstest; /* afs_call.c */ + afs_int32 C_SRXAFSCB_GetCE; /* afs_callback.c */ + afs_int32 C_ClearCallBack; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_GetLock; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_CallBack; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_InitCallBackState; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_Probe; /* afs_callback.c */ + afs_int32 C_afs_RXCallBackServer; /* afs_callback.c */ + afs_int32 C_shutdown_CB; /* afs_callback.c */ + afs_int32 C_afs_Chunk; /* afs_chunk.c */ + afs_int32 C_afs_ChunkBase; /* afs_chunk.c */ + afs_int32 C_afs_ChunkOffset; /* afs_chunk.c */ + afs_int32 C_afs_ChunkSize; /* afs_chunk.c */ + afs_int32 C_afs_ChunkToBase; /* afs_chunk.c */ + afs_int32 C_afs_ChunkToSize; /* afs_chunk.c */ + afs_int32 C_afs_SetChunkSize; /* afs_chunk.c */ + + afs_int32 C_afs_config; /* afs_config.c */ + afs_int32 C_mem_freebytes; /* afs_config.c */ + afs_int32 C_mem_getbytes; /* afs_config.c */ + afs_int32 C_fpalloc; /* afs_config.c */ + afs_int32 C_kluge_init; /* afs_config.c */ + afs_int32 C_ufdalloc; /* afs_config.c */ + afs_int32 C_ufdfree; /* afs_config.c */ + afs_int32 C_commit; /* afs_config.c */ + afs_int32 C_dev_ialloc; /* afs_config.c */ + afs_int32 C_ffree; /* afs_config.c */ + afs_int32 C_iget; /* afs_config.c */ + afs_int32 C_iptovp; /* afs_config.c */ + afs_int32 C_ilock; /* afs_config.c */ + afs_int32 C_irele; /* afs_config.c */ + afs_int32 C_iput; /* afs_config.c */ + + afs_int32 C_afs_Daemon; /* afs_daemons.c */ + afs_int32 C_afs_CheckRootVolume; /* afs_daemons.c */ + afs_int32 C_BPath; /* afs_daemons.c */ + afs_int32 C_BPrefetch; /* afs_daemons.c */ + afs_int32 C_BStore; /* afs_daemons.c */ + afs_int32 C_afs_BBusy; /* afs_daemons.c */ + afs_int32 C_afs_BQueue; /* afs_daemons.c */ + afs_int32 C_afs_BRelease; /* afs_daemons.c */ + afs_int32 C_afs_BackgroundDaemon; /* afs_daemons.c */ + afs_int32 C_shutdown_daemons; /* afs_daemons.c */ + afs_int32 C_exporter_add; /* afs_exporter.c */ + afs_int32 C_exporter_find; /* afs_exporter.c */ + afs_int32 C_afs_gfs_kalloc; /* afs_gfs_subr.c */ + afs_int32 C_IsAfsVnode; /* afs_gfs_subr.c */ + afs_int32 C_SetAfsVnode; /* afs_gfs_subr.c */ + afs_int32 C_afs_gfs_kfree; /* afs_gfs_subr.c */ + afs_int32 C_gop_lookupname; /* afs_gfs_subr.c */ + afs_int32 C_gfsvop_getattr; /* afs_gfs_subr.c */ + afs_int32 C_gfsvop_rdwr; /* afs_gfs_subr.c */ + afs_int32 C_afs_uniqtime; /* afs_gfs_subr.c */ + afs_int32 C_gfs_vattr_null; /* afs_gfs_subr.c */ + afs_int32 C_afs_lock; /* afs_gfsops.c */ + afs_int32 C_afs_unlock; /* afs_gfsops.c */ + afs_int32 C_afs_update; /* afs_gfsops.c */ + afs_int32 C_afs_gclose; /* afs_gfsops.c */ + afs_int32 C_afs_gopen; /* afs_gfsops.c */ + afs_int32 C_afs_greadlink; /* afs_gfsops.c */ + afs_int32 C_afs_select; /* afs_gfsops.c */ + afs_int32 C_afs_gbmap; /* afs_gfsops.c */ + afs_int32 C_afs_getfsdata; /* afs_gfsops.c */ + afs_int32 C_afs_gsymlink; /* afs_gfsops.c */ + afs_int32 C_afs_namei; /* afs_gfsops.c */ + afs_int32 C_printgnode; /* afs_gfsops.c */ + afs_int32 C_HaveGFSLock; /* afs_gfsops.c */ + afs_int32 C_afs_gmount; /* afs_gfsops.c */ + afs_int32 C_AddGFSLock; /* afs_gfsops.c */ + afs_int32 C_RemoveGFSLock; /* afs_gfsops.c */ + afs_int32 C_afs_grlock; /* afs_gfsops.c */ + afs_int32 C_afs_gumount; /* afs_gfsops.c */ + afs_int32 C_afs_gget; /* afs_gfsops.c */ + afs_int32 C_afs_glink; /* afs_gfsops.c */ + afs_int32 C_afs_gmkdir; /* afs_gfsops.c */ + afs_int32 C_afs_sbupdate; /* afs_gfsops.c */ + afs_int32 C_afs_unlink; /* afs_gfsops.c */ + afs_int32 C_afs_grmdir; /* afs_gfsops.c */ + afs_int32 C_afs_makenode; /* afs_gfsops.c */ + afs_int32 C_afs_grename; /* afs_gfsops.c */ + afs_int32 C_afs_rele; /* afs_gfsops.c */ + afs_int32 C_afs_syncgp; /* afs_gfsops.c */ + afs_int32 C_afs_getval; /* afs_gfsops.c */ + afs_int32 C_afs_gfshack; /* afs_gfsops.c */ + afs_int32 C_afs_trunc; /* afs_gfsops.c */ + afs_int32 C_afs_rwgp; /* afs_gfsops.c */ + afs_int32 C_afs_stat; /* afs_gfsops.c */ + afs_int32 C_afsc_link; /* afs_hp_subr.c */ + afs_int32 C_hpsobind; /* afs_hp_subr.c */ + afs_int32 C_hpsoclose; /* afs_hp_subr.c */ + afs_int32 C_hpsocreate; /* afs_hp_subr.c */ + afs_int32 C_hpsoreserve; /* afs_hp_subr.c */ + afs_int32 C_afs_vfs_mount; /* afs_hp_subr.c */ + afs_int32 C_devtovfs; /* afs_istuff.c */ + afs_int32 C_igetinode; /* afs_istuff.c */ + afs_int32 C_afs_syscall_iopen; /* afs_istuff.c */ + afs_int32 C_iopen; /* afs_istuff.c */ + afs_int32 C_afs_syscall_iincdec; /* afs_istuff.c */ + afs_int32 C_afs_syscall_ireadwrite; /* afs_istuff.c */ + afs_int32 C_iincdec; /* afs_istuff.c */ + afs_int32 C_ireadwrite; /* afs_istuff.c */ + afs_int32 C_oiread; /* afs_istuff.c */ + afs_int32 C_AHash; /* afs_istuff.c */ + afs_int32 C_QTOA; /* afs_istuff.c */ + afs_int32 C_afs_FindPartByDev; /* afs_istuff.c */ + afs_int32 C_aux_init; /* afs_istuff.c */ + afs_int32 C_afs_GetNewPart; /* afs_istuff.c */ + afs_int32 C_afs_InitAuxVolFile; /* afs_istuff.c */ + afs_int32 C_afs_CreateAuxEntry; /* afs_istuff.c */ + afs_int32 C_afs_GetAuxSlot; /* afs_istuff.c */ + afs_int32 C_afs_GetDownAux; /* afs_istuff.c */ + afs_int32 C_afs_FlushAuxCache; /* afs_istuff.c */ + afs_int32 C_afs_GetAuxInode; /* afs_istuff.c */ + afs_int32 C_afs_PutAuxInode; /* afs_istuff.c */ + afs_int32 C_afs_ReadAuxInode; /* afs_istuff.c */ + afs_int32 C_afs_WriteAuxInode; /* afs_istuff.c */ + afs_int32 C_afs_auxcall; /* afs_istuff.c */ + afs_int32 C_tmpdbg_auxtbl; /* afs_istuff.c */ + afs_int32 C_tmpdbg_parttbl; /* afs_istuff.c */ + afs_int32 C_idec; /* afs_istuff.c */ + afs_int32 C_iinc; /* afs_istuff.c */ + afs_int32 C_iread; /* afs_istuff.c */ + afs_int32 C_iwrite; /* afs_istuff.c */ + afs_int32 C_getinode; /* afs_istuff.c */ + afs_int32 C_trygetfs; /* afs_istuff.c */ + afs_int32 C_iforget; /* afs_istuff.c */ + afs_int32 C_afs_syscall_icreate; /* afs_istuff.c */ + afs_int32 C_icreate; /* afs_istuff.c */ + afs_int32 C_Lock_Init; /* afs_lock.c */ + afs_int32 C_Lock_Obtain; /* afs_lock.c */ + afs_int32 C_Lock_ReleaseR; /* afs_lock.c */ + afs_int32 C_Lock_ReleaseW; /* afs_lock.c */ + afs_int32 C_afs_BozonLock; /* afs_lock.c */ + afs_int32 C_afs_BozonUnlock; /* afs_lock.c */ + afs_int32 C_osi_SleepR; /* afs_lock.c */ + afs_int32 C_osi_SleepS; /* afs_lock.c */ + afs_int32 C_osi_SleepW; /* afs_lock.c */ + afs_int32 C_osi_Sleep; /* afs_lock */ + afs_int32 C_afs_BozonInit; /* afs_lock.c */ + afs_int32 C_afs_CheckBozonLock; /* afs_lock.c */ + afs_int32 C_afs_CheckBozonLockBlocking; /* afs_lock.c */ + afs_int32 C_xxxinit; /* afs_main.c */ + afs_int32 C_KernelEntry; /* afs_main.c */ + afs_int32 C_afs_InitMemCache; /* afs_memcache.c */ + afs_int32 C_afs_LookupMCE; /* afs_memcache.c */ + afs_int32 C_afs_MemReadBlk; /* afs_memcache.c */ + afs_int32 C_afs_MemReadUIO; /* afs_memcache.c */ + afs_int32 C_afs_MemWriteBlk; /* afs_memcache.c */ + afs_int32 C_afs_MemCacheStoreProc; /* afs_memcache.c */ + afs_int32 C_afs_MemCacheTruncate; /* afs_memcache.c */ + afs_int32 C_afs_MemWriteUIO; /* afs_memcache.c */ + afs_int32 C_afs_MemCacheFetchProc; /* afs_memcache.c */ + afs_int32 C_afs_vnode_pager_create; /* afs_next_aux.c */ + afs_int32 C_next_KernelEntry; /* afs_next_subr.c */ + afs_int32 C_afs_GetNfsClientPag; /* afs_nfsclnt.c */ + afs_int32 C_afs_FindNfsClientPag; /* afs_nfsclnt.c */ + afs_int32 C_afs_PutNfsClientPag; /* afs_nfsclnt.c */ + afs_int32 C_afs_nfsclient_reqhandler; /* afs_nfsclnt.c */ + afs_int32 C_afs_nfsclient_GC; /* afs_nfsclnt.c */ + afs_int32 C_afs_nfsclient_hold; /* afs_nfsclnt.c */ + afs_int32 C_afs_nfsclient_stats; /* afs_nfsclnt.c */ + afs_int32 C_afs_nfsclient_sysname; /* afs_nfsclnt.c */ + afs_int32 C_afs_nfsclient_shutdown; /* afs_nfsclnt.c */ afs_int32 C_afs_rfs_readdir_fixup; /* afs_nfssrv.c */ - afs_int32 C_afs_rfs_dispatch; /* afs_nfssrv.c*/ - afs_int32 C_afs_xnfs_svc; /* afs_nfssrv.c*/ - afs_int32 C_afs_xdr_putrddirres; /* afs_nfssrv.c*/ - afs_int32 C_afs_rfs_readdir; /* afs_nfssrv.c*/ - afs_int32 C_afs_rfs_rddirfree; /* afs_nfssrv.c*/ - afs_int32 C_rfs_dupcreate; /* afs_nfssrv.c*/ - afs_int32 C_rfs_dupsetattr; /* afs_nfssrv.c*/ - afs_int32 C_Nfs2AfsCall; /* afs_nfssrv.c*/ - afs_int32 C_afs_sun_xuntext; /* afs_osi.c*/ - afs_int32 C_osi_Active; /* afs_osi.c*/ - afs_int32 C_osi_FlushPages; /* afs_osi.c*/ - afs_int32 C_osi_FlushText; /* afs_osi.c*/ - afs_int32 C_osi_CallProc; /* afs_osi.c*/ - afs_int32 C_osi_CancelProc; /* afs_osi.c*/ - afs_int32 C_osi_Invisible; /* afs_osi.c*/ - afs_int32 C_osi_Time; /* afs_osi.c*/ - afs_int32 C_osi_Alloc; /* afs_osi.c*/ - afs_int32 C_osi_SetTime; /* afs_osi.c*/ - afs_int32 C_osi_Dump; /* afs_osi.c*/ - afs_int32 C_osi_Free; /* afs_osi.c*/ - afs_int32 C_shutdown_osi; /* afs_osi.c*/ - afs_int32 C_osi_UFSOpen; /* afs_osifile.c*/ - afs_int32 C_osi_Close; /* afs_osifile.c*/ - afs_int32 C_osi_Stat; /* afs_osifile.c*/ - afs_int32 C_osi_Truncate; /* afs_osifile.c*/ - afs_int32 C_osi_Read; /* afs_osifile.c*/ - afs_int32 C_osi_Write; /* afs_osifile.c*/ - afs_int32 C_osi_MapStrategy; /* afs_osifile.c*/ - afs_int32 C_shutdown_osifile; /* afs_osifile.c*/ - afs_int32 C_osi_FreeLargeSpace; /* afs_osinet.c*/ - afs_int32 C_osi_FreeSmallSpace; /* afs_osinet.c*/ - afs_int32 C_pkt_iodone; /* afs_osinet.c*/ - afs_int32 C_shutdown_osinet; /* afs_osinet.c*/ - afs_int32 C_afs_cs; /* afs_osinet.c*/ - afs_int32 C_osi_AllocLargeSpace; /* afs_osinet.c*/ - afs_int32 C_osi_AllocSmallSpace; /* afs_osinet.c*/ - afs_int32 C_osi_CloseToTheEdge; /* afs_osinet.c*/ - afs_int32 C_osi_xgreedy; /* afs_osinet.c*/ - afs_int32 C_osi_FreeSocket; /* afs_osinet.c*/ - afs_int32 C_osi_NewSocket; /* afs_osinet.c*/ - afs_int32 C_trysblock; /* afs_osinet.c*/ - afs_int32 C_osi_NetSend; /* afs_osinet.c*/ - afs_int32 C_WaitHack; /* afs_osinet.c*/ - afs_int32 C_osi_CancelWait; /* afs_osinet.c*/ - afs_int32 C_osi_InitWaitHandle; /* afs_osinet.c*/ - afs_int32 C_osi_Wakeup; /* afs_osinet.c*/ - afs_int32 C_osi_Wait; /* afs_osinet.c*/ - afs_int32 C_dirp_Read; /* afs_physio.c*/ - afs_int32 C_dirp_SetCacheDev; /* afs_physio.c*/ - afs_int32 C_Die; /* afs_physio.c*/ - afs_int32 C_dirp_Cpy; /* afs_physio.c*/ - afs_int32 C_dirp_Eq; /* afs_physio.c*/ - afs_int32 C_dirp_Write; /* afs_physio.c*/ - afs_int32 C_dirp_Zap; /* afs_physio.c*/ - afs_int32 C_PSetVolumeStatus; /* afs_pioctl.c*/ - afs_int32 C_PFlush; /* afs_pioctl.c*/ - afs_int32 C_PNewStatMount; /* afs_pioctl.c*/ - afs_int32 C_PGetTokens; /* afs_pioctl.c*/ - afs_int32 C_PUnlog; /* afs_pioctl.c*/ - afs_int32 C_PCheckServers; /* afs_pioctl.c*/ - afs_int32 C_PMariner; /* afs_pioctl.c*/ - afs_int32 C_PCheckAuth; /* afs_pioctl.c*/ - afs_int32 C_PCheckVolNames; /* afs_pioctl.c*/ - afs_int32 C_PFindVolume; /* afs_pioctl.c*/ - afs_int32 C_Prefetch; /* afs_pioctl.c*/ - afs_int32 C_PGetCacheSize; /* afs_pioctl.c*/ - afs_int32 C_PRemoveCallBack; /* afs_pioctl.c*/ - afs_int32 C_PSetCacheSize; /* afs_pioctl.c*/ - afs_int32 C_PViceAccess; /* afs_pioctl.c*/ - afs_int32 C_PListCells; /* afs_pioctl.c*/ - afs_int32 C_PNewCell; /* afs_pioctl.c*/ - afs_int32 C_PRemoveMount; /* afs_pioctl.c*/ - afs_int32 C_HandleIoctl; /* afs_pioctl.c*/ - afs_int32 C__AFSIOCTL; /* afs_pioctl.c*/ - afs_int32 C__VALIDAFSIOCTL; /* afs_pioctl.c*/ - afs_int32 C_PGetCellStatus; /* afs_pioctl.c*/ - afs_int32 C_PSetCellStatus; /* afs_pioctl.c*/ - afs_int32 C_PVenusLogging; /* afs_pioctl.c*/ - afs_int32 C_PFlushVolumeData; /* afs_pioctl.c*/ - afs_int32 C_PSetSysName; /* afs_pioctl.c*/ - afs_int32 C_PExportAfs; /* afs_pioctl.c*/ - afs_int32 C_HandleClientContext; /* afs_pioctl.c*/ - afs_int32 C_afs_ioctl; /* afs_pioctl.c*/ - afs_int32 C_afs_xioctl; /* afs_pioctl.c*/ - afs_int32 C_afs_pioctl; /* afs_pioctl.c*/ - afs_int32 C_afs_syscall_pioctl; /* afs_pioctl.c*/ - afs_int32 C_HandlePioctl; /* afs_pioctl.c*/ - afs_int32 C_PGetAcl; /* afs_pioctl.c*/ - afs_int32 C_PGetFID; /* afs_pioctl.c*/ - afs_int32 C_PSetAcl; /* afs_pioctl.c*/ - afs_int32 C_PBogus; /* afs_pioctl.c*/ - afs_int32 C_PGetFileCell; /* afs_pioctl.c*/ - afs_int32 C_PGetWSCell; /* afs_pioctl.c*/ - afs_int32 C_PNoop; /* afs_pioctl.c*/ - afs_int32 C_PGetUserCell; /* afs_pioctl.c*/ - afs_int32 C_PSetTokens; /* afs_pioctl.c*/ - afs_int32 C_PGetVolumeStatus; /* afs_pioctl.c*/ - afs_int32 C_afs_ResetAccessCache; /* afs_resource.c*/ - afs_int32 C_afs_FindUser; /* afs_resource.c*/ - afs_int32 C_afs_ResetUserConns; /* afs_resource.c*/ - afs_int32 C_afs_ResourceInit; /* afs_resource.c*/ - afs_int32 C_afs_GetCell; /* afs_resource.c*/ - afs_int32 C_afs_GetCellByIndex; /* afs_resource.c*/ - afs_int32 C_afs_GetCellByName; /* afs_resource.c*/ - afs_int32 C_afs_GetRealCellByIndex; /* afs_resource.c*/ - afs_int32 C_afs_NewCell; /* afs_resource.c*/ - afs_int32 C_afs_GetUser; /* afs_resource.c*/ - afs_int32 C_afs_PutUser; /* afs_resource.c*/ - afs_int32 C_afs_SetPrimary; /* afs_resource.c*/ - afs_int32 C_CheckVLDB; /* afs_resource.c*/ - afs_int32 C_afs_GetVolume; /* afs_resource.c*/ - afs_int32 C_afs_GetVolumeByName; /* afs_resource.c*/ - afs_int32 C_InstallVolumeEntry; /* afs_resource.c*/ - afs_int32 C_InstallVolumeInfo; /* afs_resource.c*/ - afs_int32 C_afs_FindServer; /* afs_resource.c*/ - afs_int32 C_afs_PutVolume; /* afs_resource.c*/ - afs_int32 C_afs_random; /* afs_resource.c*/ - afs_int32 C_ranstage; /* afs_resource.c*/ - afs_int32 C_RemoveUserConns; /* afs_resource.c*/ - afs_int32 C_afs_MarinerLog; /* afs_resource.c*/ - afs_int32 C_afs_vtoi; /* afs_resource.c*/ - afs_int32 C_afs_GetServer; /* afs_resource.c*/ - afs_int32 C_afs_SortServers; /* afs_resource.c*/ - afs_int32 C_afs_Conn; /* afs_resource.c*/ - afs_int32 C_afs_ConnByHost; /* afs_resource.c*/ - afs_int32 C_afs_ConnByMHosts; /* afs_resource.c*/ - afs_int32 C_afs_Analyze; /* afs_resource.c*/ - afs_int32 C_afs_PutConn; /* afs_resource.c*/ - afs_int32 C_afs_ResetVolumeInfo; /* afs_resource.c*/ - afs_int32 C_StartLogFile; /* afs_resource.c*/ - afs_int32 C_afs_SetLogFile; /* afs_resource.c*/ - afs_int32 C_EndLogFile; /* afs_resource.c*/ - afs_int32 C_afs_dp; /* afs_resource.c*/ - afs_int32 C_fprf; /* afs_resource.c*/ - afs_int32 C_fprint; /* afs_resource.c*/ - afs_int32 C_fprintn; /* afs_resource.c*/ - afs_int32 C_afs_CheckLocks; /* afs_resource.c*/ - afs_int32 C_puttofile; /* afs_resource.c*/ - afs_int32 C_shutdown_AFS; /* afs_resource.c*/ - afs_int32 C_afs_CheckCacheResets; /* afs_resource.c*/ - afs_int32 C_afs_GCUserData; /* afs_resource.c*/ - afs_int32 C_VSleep; /* afs_resource.c*/ - afs_int32 C_afs_CheckCode; /* afs_resource.c*/ - afs_int32 C_afs_CopyError; /* afs_resource.c*/ - afs_int32 C_afs_FinalizeReq; /* afs_resource.c*/ - afs_int32 C_afs_cv2string; /* afs_resource.c*/ - afs_int32 C_afs_FindVolCache; /* afs_resource.c*/ - afs_int32 C_afs_GetVolCache; /* afs_resource.c*/ - afs_int32 C_afs_GetVolSlot; /* afs_resource.c*/ - afs_int32 C_afs_WriteVolCache; /* afs_resource.c*/ - afs_int32 C_afs_UFSGetVolSlot; /* afs_resource.c*/ - afs_int32 C_afs_CheckVolumeNames; /* afs_resource.c*/ - afs_int32 C_afs_MemGetVolSlot; /* afs_resource.c*/ - afs_int32 C_print_internet_address; /* afs_resource.c*/ - afs_int32 C_CheckVLServer; /* afs_resource.c*/ - afs_int32 C_HaveCallBacksFrom; /* afs_resource.c*/ - afs_int32 C_ServerDown; /* afs_resource.c*/ - afs_int32 C_afs_CheckServers; /* afs_resource.c*/ - afs_int32 C_afs_AddToMean; /* afs_stat.c*/ - afs_int32 C_afs_GetCMStat; /* afs_stat.c*/ - afs_int32 C_afs_getpage; /* afs_sun_subr.c*/ - afs_int32 C_afs_putpage; /* afs_sun_subr.c*/ - afs_int32 C_afs_nfsrdwr; /* afs_sun_subr.c*/ - afs_int32 C_afs_map; /* afs_sun_subr.c*/ - afs_int32 C_afs_cmp; /* afs_sun_subr.c*/ - afs_int32 C_afs_cntl; /* afs_sun_subr.c*/ - afs_int32 C_afs_dump; /* afs_sun_subr.c*/ - afs_int32 C_afs_realvp; /* afs_sun_subr.c*/ - afs_int32 C_afs_PageLeft; /* afs_sun_subr.c*/ - afs_int32 C_afsinit; /* afs_vfsops.c*/ - afs_int32 C_afs_mount; /* afs_vfsops.c*/ - afs_int32 C_afs_unmount; /* afs_vfsops.c*/ - afs_int32 C_afs_root; /* afs_vfsops.c*/ - afs_int32 C_afs_statfs; /* afs_vfsops.c*/ - afs_int32 C_afs_sync; /* afs_vfsops.c*/ - afs_int32 C_afs_vget; /* afs_vfsops.c*/ - afs_int32 C_afs_mountroot; /* afs_vfsops.c*/ - afs_int32 C_afs_swapvp; /* afs_vfsops.c*/ - afs_int32 C_afs_AddMarinerName; /* afs_vnodeops.c*/ - afs_int32 C_afs_setpag; /* afs_vnodeops.c*/ - afs_int32 C_genpag; /* afs_vnodeops.c*/ - afs_int32 C_getpag; /* afs_vnodeops.c*/ - afs_int32 C_afs_GetMariner; /* afs_vnodeops.c*/ - afs_int32 C_afs_badop; /* afs_vnodeops.c*/ - afs_int32 C_afs_index; /* afs_vnodeops.c*/ - afs_int32 C_afs_noop; /* afs_vnodeops.c*/ - afs_int32 C_afs_open; /* afs_vnodeops.c*/ - afs_int32 C_afs_closex; /* afs_vnodeops.c*/ - afs_int32 C_afs_close; /* afs_vnodeops.c*/ - afs_int32 C_afs_MemWrite; /* afs_vnodeops.c*/ - afs_int32 C_afs_write; /* afs_vnodeops.c*/ - afs_int32 C_afs_UFSWrite; /* afs_vnodeops.c*/ - afs_int32 C_afs_rdwr; /* afs_vnodeops.c*/ - afs_int32 C_afs_MemRead; /* afs_vnodeops.c*/ - afs_int32 C_afs_read; /* afs_vnodeops.c*/ - afs_int32 C_FIXUPSTUPIDINODE; /* afs_vnodeops.c*/ - afs_int32 C_afs_UFSRead; /* afs_vnodeops.c*/ - afs_int32 C_afs_CopyOutAttrs; /* afs_vnodeops.c*/ - afs_int32 C_afs_getattr; /* afs_vnodeops.c*/ - afs_int32 C_afs_VAttrToAS; /* afs_vnodeops.c*/ - afs_int32 C_afs_setattr; /* afs_vnodeops.c*/ - afs_int32 C_EvalMountPoint; /* afs_vnodeops.c*/ - afs_int32 C_afs_access; /* afs_vnodeops.c*/ - afs_int32 C_ENameOK; /* afs_vnodeops.c*/ - afs_int32 C_HandleAtName; /* afs_vnodeops.c*/ - afs_int32 C_getsysname; /* afs_vnodeops.c*/ - afs_int32 C_strcat; /* afs_vnodeops.c*/ - afs_int32 C_afs_lookup; /* afs_vnodeops.c*/ - afs_int32 C_afs_create; /* afs_vnodeops.c*/ - afs_int32 C_afs_LocalHero; /* afs_vnodeops.c*/ - afs_int32 C_FetchWholeEnchilada; /* afs_vnodeops.c*/ - afs_int32 C_afs_remove; /* afs_vnodeops.c*/ - afs_int32 C_afs_link; /* afs_vnodeops.c*/ - afs_int32 C_afs_rename; /* afs_vnodeops.c*/ - afs_int32 C_afs_InitReq; /* afs_vnodeops.c*/ - afs_int32 C_afs_mkdir; /* afs_vnodeops.c*/ - afs_int32 C_BlobScan; /* afs_vnodeops.c*/ - afs_int32 C_afs_rmdir; /* afs_vnodeops.c*/ - afs_int32 C_RecLen; /* afs_vnodeops.c*/ - afs_int32 C_RoundToInt; /* afs_vnodeops.c*/ - afs_int32 C_afs_readdir_with_offlist; /* afs_vnodeops.c*/ - afs_int32 C_DIRSIZ_LEN; /* afs_vnodeops.c*/ - afs_int32 C_afs_readdir_move; /* afs_vnodeops.c*/ - afs_int32 C_afs_readdir_iter; /* afs_vnodeops.c*/ - afs_int32 C_HandleFlock; /* afs_vnodeops.c*/ - afs_int32 C_afs_readdir; /* afs_vnodeops.c*/ - afs_int32 C_afs_symlink; /* afs_vnodeops.c*/ - afs_int32 C_afs_HandleLink; /* afs_vnodeops.c*/ - afs_int32 C_afs_MemHandleLink; /* afs_vnodeops.c*/ - afs_int32 C_afs_UFSHandleLink; /* afs_vnodeops.c*/ - afs_int32 C_afs_readlink; /* afs_vnodeops.c*/ - afs_int32 C_afs_fsync; /* afs_vnodeops.c*/ - afs_int32 C_afs_inactive; /* afs_vnodeops.c*/ - afs_int32 C_afs_ustrategy; /* afs_vnodeops.c*/ - afs_int32 C_afs_bread; /* afs_vnodeops.c*/ - afs_int32 C_afs_brelse; /* afs_vnodeops.c*/ - afs_int32 C_afs_bmap; /* afs_vnodeops.c*/ - afs_int32 C_afs_fid; /* afs_vnodeops.c*/ - afs_int32 C_afs_strategy; /* afs_vnodeops.c*/ - afs_int32 C_afs_FakeClose; /* afs_vnodeops.c*/ - afs_int32 C_afs_FakeOpen; /* afs_vnodeops.c*/ - afs_int32 C_afs_StoreOnLastReference; /* afs_vnodeops.c*/ - afs_int32 C_afs_GetAccessBits; /* afs_vnodeops.c*/ - afs_int32 C_afs_AccessOK; /* afs_vnodeops.c*/ - afs_int32 C_shutdown_vnodeops; /* afs_vnodeops.c*/ - afs_int32 C_afsio_copy; /* afs_vnodeops.c*/ - afs_int32 C_afsio_trim; /* afs_vnodeops.c*/ - afs_int32 C_afs_page_read; /* afs_vnodeops.c*/ - afs_int32 C_afs_page_write; /* afs_vnodeops.c*/ - afs_int32 C_afsio_skip; /* afs_vnodeops.c*/ - afs_int32 C_afs_read1dir; /* afs_vnodeops.c*/ - afs_int32 C_afs_get_groups_from_pag; /* afs_vnodeops.c*/ - afs_int32 C_afs_get_pag_from_groups; /* afs_vnodeops.c*/ - afs_int32 C_PagInCred; /* afs_vnodeops.c*/ - afs_int32 C_afs_getgroups; /* afs_vnodeops.c*/ - afs_int32 C_setpag; /* afs_vnodeops.c*/ - afs_int32 C_afs_setgroups; /* afs_vnodeops.c*/ - afs_int32 C_afs_page_in; /* afs_vnodeops.c*/ - afs_int32 C_afs_page_out; /* afs_vnodeops.c*/ - afs_int32 C_AddPag; /* afs_vnodeops.c*/ - afs_int32 C_afs_AdvanceFD; /* afs_vnodeops.c*/ - afs_int32 C_afs_lockf; /* afs_vnodeops.c*/ - afs_int32 C_afs_xsetgroups; /* afs_vnodeops.c*/ - afs_int32 C_afs_nlinks; /* afs_vnodeops.c*/ - afs_int32 C_DoLockWarning; /* afs_vnodeops.c*/ - afs_int32 C_afs_lockctl; /* afs_vnodeops.c*/ - afs_int32 C_afs_xflock; /* afs_vnodeops.c*/ - afs_int32 C_PSetSPrefs; /* afs_pioctl.c*/ - afs_int32 C_PGetSPrefs; /* afs_pioctl.c*/ - afs_int32 C_afs_warn; /* afs_resource.c */ - afs_int32 C_afs_warnuser; /* afs_resource.c */ - afs_int32 C_afs_pagein; /* afs_hp_subr.c*/ - afs_int32 C_afs_pageout; /* afs_hp_subr.c*/ - afs_int32 C_afs_hp_strategy; /* afs_hp_subr.c*/ - afs_int32 C_PGetCPrefs; /* afs_pioctl.c */ - afs_int32 C_PSetCPrefs; /* afs_pioctl.c */ - afs_int32 C_SRXAFSCB_WhoAreYou; /* afs_callback.c*/ - afs_int32 C_afs_DiscardDCache; /* afs_dcache.c*/ - afs_int32 C_afs_FreeDiscardedDCache; /* afs_dcache.c*/ - afs_int32 C_afs_MaybeFreeDiscardedDCache; /* afs_dcache.c*/ + afs_int32 C_afs_rfs_dispatch; /* afs_nfssrv.c */ + afs_int32 C_afs_xnfs_svc; /* afs_nfssrv.c */ + afs_int32 C_afs_xdr_putrddirres; /* afs_nfssrv.c */ + afs_int32 C_afs_rfs_readdir; /* afs_nfssrv.c */ + afs_int32 C_afs_rfs_rddirfree; /* afs_nfssrv.c */ + afs_int32 C_rfs_dupcreate; /* afs_nfssrv.c */ + afs_int32 C_rfs_dupsetattr; /* afs_nfssrv.c */ + afs_int32 C_Nfs2AfsCall; /* afs_nfssrv.c */ + afs_int32 C_afs_sun_xuntext; /* afs_osi.c */ + afs_int32 C_osi_Active; /* afs_osi.c */ + afs_int32 C_osi_FlushPages; /* afs_osi.c */ + afs_int32 C_osi_FlushText; /* afs_osi.c */ + afs_int32 C_osi_CallProc; /* afs_osi.c */ + afs_int32 C_osi_CancelProc; /* afs_osi.c */ + afs_int32 C_osi_Invisible; /* afs_osi.c */ + afs_int32 C_osi_Time; /* afs_osi.c */ + afs_int32 C_osi_Alloc; /* afs_osi.c */ + afs_int32 C_osi_SetTime; /* afs_osi.c */ + afs_int32 C_osi_Dump; /* afs_osi.c */ + afs_int32 C_osi_Free; /* afs_osi.c */ + afs_int32 C_shutdown_osi; /* afs_osi.c */ + afs_int32 C_osi_UFSOpen; /* afs_osifile.c */ + afs_int32 C_osi_Close; /* afs_osifile.c */ + afs_int32 C_osi_Stat; /* afs_osifile.c */ + afs_int32 C_osi_Truncate; /* afs_osifile.c */ + afs_int32 C_osi_Read; /* afs_osifile.c */ + afs_int32 C_osi_Write; /* afs_osifile.c */ + afs_int32 C_osi_MapStrategy; /* afs_osifile.c */ + afs_int32 C_shutdown_osifile; /* afs_osifile.c */ + afs_int32 C_osi_FreeLargeSpace; /* afs_osinet.c */ + afs_int32 C_osi_FreeSmallSpace; /* afs_osinet.c */ + afs_int32 C_pkt_iodone; /* afs_osinet.c */ + afs_int32 C_shutdown_osinet; /* afs_osinet.c */ + afs_int32 C_afs_cs; /* afs_osinet.c */ + afs_int32 C_osi_AllocLargeSpace; /* afs_osinet.c */ + afs_int32 C_osi_AllocSmallSpace; /* afs_osinet.c */ + afs_int32 C_osi_CloseToTheEdge; /* afs_osinet.c */ + afs_int32 C_osi_xgreedy; /* afs_osinet.c */ + afs_int32 C_osi_FreeSocket; /* afs_osinet.c */ + afs_int32 C_osi_NewSocket; /* afs_osinet.c */ + afs_int32 C_trysblock; /* afs_osinet.c */ + afs_int32 C_osi_NetSend; /* afs_osinet.c */ + afs_int32 C_WaitHack; /* afs_osinet.c */ + afs_int32 C_osi_CancelWait; /* afs_osinet.c */ + afs_int32 C_osi_InitWaitHandle; /* afs_osinet.c */ + afs_int32 C_osi_Wakeup; /* afs_osinet.c */ + afs_int32 C_osi_Wait; /* afs_osinet.c */ + afs_int32 C_dirp_Read; /* afs_physio.c */ + afs_int32 C_dirp_SetCacheDev; /* afs_physio.c */ + afs_int32 C_Die; /* afs_physio.c */ + afs_int32 C_dirp_Cpy; /* afs_physio.c */ + afs_int32 C_dirp_Eq; /* afs_physio.c */ + afs_int32 C_dirp_Write; /* afs_physio.c */ + afs_int32 C_dirp_Zap; /* afs_physio.c */ + afs_int32 C_PSetVolumeStatus; /* afs_pioctl.c */ + afs_int32 C_PFlush; /* afs_pioctl.c */ + afs_int32 C_PNewStatMount; /* afs_pioctl.c */ + afs_int32 C_PGetTokens; /* afs_pioctl.c */ + afs_int32 C_PUnlog; /* afs_pioctl.c */ + afs_int32 C_PCheckServers; /* afs_pioctl.c */ + afs_int32 C_PMariner; /* afs_pioctl.c */ + afs_int32 C_PCheckAuth; /* afs_pioctl.c */ + afs_int32 C_PCheckVolNames; /* afs_pioctl.c */ + afs_int32 C_PFindVolume; /* afs_pioctl.c */ + afs_int32 C_Prefetch; /* afs_pioctl.c */ + afs_int32 C_PGetCacheSize; /* afs_pioctl.c */ + afs_int32 C_PRemoveCallBack; /* afs_pioctl.c */ + afs_int32 C_PSetCacheSize; /* afs_pioctl.c */ + afs_int32 C_PViceAccess; /* afs_pioctl.c */ + afs_int32 C_PListCells; /* afs_pioctl.c */ + afs_int32 C_PNewCell; /* afs_pioctl.c */ + afs_int32 C_PRemoveMount; /* afs_pioctl.c */ + afs_int32 C_HandleIoctl; /* afs_pioctl.c */ + afs_int32 C__AFSIOCTL; /* afs_pioctl.c */ + afs_int32 C__VALIDAFSIOCTL; /* afs_pioctl.c */ + afs_int32 C_PGetCellStatus; /* afs_pioctl.c */ + afs_int32 C_PSetCellStatus; /* afs_pioctl.c */ + afs_int32 C_PVenusLogging; /* afs_pioctl.c */ + afs_int32 C_PFlushVolumeData; /* afs_pioctl.c */ + afs_int32 C_PSetSysName; /* afs_pioctl.c */ + afs_int32 C_PExportAfs; /* afs_pioctl.c */ + afs_int32 C_HandleClientContext; /* afs_pioctl.c */ + afs_int32 C_afs_ioctl; /* afs_pioctl.c */ + afs_int32 C_afs_xioctl; /* afs_pioctl.c */ + afs_int32 C_afs_pioctl; /* afs_pioctl.c */ + afs_int32 C_afs_syscall_pioctl; /* afs_pioctl.c */ + afs_int32 C_HandlePioctl; /* afs_pioctl.c */ + afs_int32 C_PGetAcl; /* afs_pioctl.c */ + afs_int32 C_PGetFID; /* afs_pioctl.c */ + afs_int32 C_PSetAcl; /* afs_pioctl.c */ + afs_int32 C_PBogus; /* afs_pioctl.c */ + afs_int32 C_PGetFileCell; /* afs_pioctl.c */ + afs_int32 C_PGetWSCell; /* afs_pioctl.c */ + afs_int32 C_PNoop; /* afs_pioctl.c */ + afs_int32 C_PGetUserCell; /* afs_pioctl.c */ + afs_int32 C_PSetTokens; /* afs_pioctl.c */ + afs_int32 C_PGetVolumeStatus; /* afs_pioctl.c */ + afs_int32 C_afs_ResetAccessCache; /* afs_resource.c */ + afs_int32 C_afs_FindUser; /* afs_resource.c */ + afs_int32 C_afs_ResetUserConns; /* afs_resource.c */ + afs_int32 C_afs_ResourceInit; /* afs_resource.c */ + afs_int32 C_afs_GetCell; /* afs_resource.c */ + afs_int32 C_afs_GetCellByIndex; /* afs_resource.c */ + afs_int32 C_afs_GetCellByName; /* afs_resource.c */ + afs_int32 C_afs_GetRealCellByIndex; /* afs_resource.c */ + afs_int32 C_afs_NewCell; /* afs_resource.c */ + afs_int32 C_afs_GetUser; /* afs_resource.c */ + afs_int32 C_afs_PutUser; /* afs_resource.c */ + afs_int32 C_afs_SetPrimary; /* afs_resource.c */ + afs_int32 C_CheckVLDB; /* afs_resource.c */ + afs_int32 C_afs_GetVolume; /* afs_resource.c */ + afs_int32 C_afs_GetVolumeByName; /* afs_resource.c */ + afs_int32 C_InstallVolumeEntry; /* afs_resource.c */ + afs_int32 C_InstallVolumeInfo; /* afs_resource.c */ + afs_int32 C_afs_FindServer; /* afs_resource.c */ + afs_int32 C_afs_PutVolume; /* afs_resource.c */ + afs_int32 C_afs_random; /* afs_resource.c */ + afs_int32 C_ranstage; /* afs_resource.c */ + afs_int32 C_RemoveUserConns; /* afs_resource.c */ + afs_int32 C_afs_MarinerLog; /* afs_resource.c */ + afs_int32 C_afs_vtoi; /* afs_resource.c */ + afs_int32 C_afs_GetServer; /* afs_resource.c */ + afs_int32 C_afs_SortServers; /* afs_resource.c */ + afs_int32 C_afs_Conn; /* afs_resource.c */ + afs_int32 C_afs_ConnByHost; /* afs_resource.c */ + afs_int32 C_afs_ConnByMHosts; /* afs_resource.c */ + afs_int32 C_afs_Analyze; /* afs_resource.c */ + afs_int32 C_afs_PutConn; /* afs_resource.c */ + afs_int32 C_afs_ResetVolumeInfo; /* afs_resource.c */ + afs_int32 C_StartLogFile; /* afs_resource.c */ + afs_int32 C_afs_SetLogFile; /* afs_resource.c */ + afs_int32 C_EndLogFile; /* afs_resource.c */ + afs_int32 C_afs_dp; /* afs_resource.c */ + afs_int32 C_fprf; /* afs_resource.c */ + afs_int32 C_fprint; /* afs_resource.c */ + afs_int32 C_fprintn; /* afs_resource.c */ + afs_int32 C_afs_CheckLocks; /* afs_resource.c */ + afs_int32 C_puttofile; /* afs_resource.c */ + afs_int32 C_shutdown_AFS; /* afs_resource.c */ + afs_int32 C_afs_CheckCacheResets; /* afs_resource.c */ + afs_int32 C_afs_GCUserData; /* afs_resource.c */ + afs_int32 C_VSleep; /* afs_resource.c */ + afs_int32 C_afs_CheckCode; /* afs_resource.c */ + afs_int32 C_afs_CopyError; /* afs_resource.c */ + afs_int32 C_afs_FinalizeReq; /* afs_resource.c */ + afs_int32 C_afs_cv2string; /* afs_resource.c */ + afs_int32 C_afs_FindVolCache; /* afs_resource.c */ + afs_int32 C_afs_GetVolCache; /* afs_resource.c */ + afs_int32 C_afs_GetVolSlot; /* afs_resource.c */ + afs_int32 C_afs_WriteVolCache; /* afs_resource.c */ + afs_int32 C_afs_UFSGetVolSlot; /* afs_resource.c */ + afs_int32 C_afs_CheckVolumeNames; /* afs_resource.c */ + afs_int32 C_afs_MemGetVolSlot; /* afs_resource.c */ + afs_int32 C_print_internet_address; /* afs_resource.c */ + afs_int32 C_CheckVLServer; /* afs_resource.c */ + afs_int32 C_HaveCallBacksFrom; /* afs_resource.c */ + afs_int32 C_ServerDown; /* afs_resource.c */ + afs_int32 C_afs_CheckServers; /* afs_resource.c */ + afs_int32 C_afs_AddToMean; /* afs_stat.c */ + afs_int32 C_afs_GetCMStat; /* afs_stat.c */ + afs_int32 C_afs_getpage; /* afs_sun_subr.c */ + afs_int32 C_afs_putpage; /* afs_sun_subr.c */ + afs_int32 C_afs_nfsrdwr; /* afs_sun_subr.c */ + afs_int32 C_afs_map; /* afs_sun_subr.c */ + afs_int32 C_afs_cmp; /* afs_sun_subr.c */ + afs_int32 C_afs_cntl; /* afs_sun_subr.c */ + afs_int32 C_afs_dump; /* afs_sun_subr.c */ + afs_int32 C_afs_realvp; /* afs_sun_subr.c */ + afs_int32 C_afs_PageLeft; /* afs_sun_subr.c */ + afs_int32 C_afsinit; /* afs_vfsops.c */ + afs_int32 C_afs_mount; /* afs_vfsops.c */ + afs_int32 C_afs_unmount; /* afs_vfsops.c */ + afs_int32 C_afs_root; /* afs_vfsops.c */ + afs_int32 C_afs_statfs; /* afs_vfsops.c */ + afs_int32 C_afs_sync; /* afs_vfsops.c */ + afs_int32 C_afs_vget; /* afs_vfsops.c */ + afs_int32 C_afs_mountroot; /* afs_vfsops.c */ + afs_int32 C_afs_swapvp; /* afs_vfsops.c */ + afs_int32 C_afs_AddMarinerName; /* afs_vnodeops.c */ + afs_int32 C_afs_setpag; /* afs_vnodeops.c */ + afs_int32 C_genpag; /* afs_vnodeops.c */ + afs_int32 C_getpag; /* afs_vnodeops.c */ + afs_int32 C_afs_GetMariner; /* afs_vnodeops.c */ + afs_int32 C_afs_badop; /* afs_vnodeops.c */ + afs_int32 C_afs_index; /* afs_vnodeops.c */ + afs_int32 C_afs_noop; /* afs_vnodeops.c */ + afs_int32 C_afs_open; /* afs_vnodeops.c */ + afs_int32 C_afs_closex; /* afs_vnodeops.c */ + afs_int32 C_afs_close; /* afs_vnodeops.c */ + afs_int32 C_afs_MemWrite; /* afs_vnodeops.c */ + afs_int32 C_afs_write; /* afs_vnodeops.c */ + afs_int32 C_afs_UFSWrite; /* afs_vnodeops.c */ + afs_int32 C_afs_rdwr; /* afs_vnodeops.c */ + afs_int32 C_afs_MemRead; /* afs_vnodeops.c */ + afs_int32 C_afs_read; /* afs_vnodeops.c */ + afs_int32 C_FIXUPSTUPIDINODE; /* afs_vnodeops.c */ + afs_int32 C_afs_UFSRead; /* afs_vnodeops.c */ + afs_int32 C_afs_CopyOutAttrs; /* afs_vnodeops.c */ + afs_int32 C_afs_getattr; /* afs_vnodeops.c */ + afs_int32 C_afs_VAttrToAS; /* afs_vnodeops.c */ + afs_int32 C_afs_setattr; /* afs_vnodeops.c */ + afs_int32 C_EvalMountPoint; /* afs_vnodeops.c */ + afs_int32 C_afs_access; /* afs_vnodeops.c */ + afs_int32 C_ENameOK; /* afs_vnodeops.c */ + afs_int32 C_HandleAtName; /* afs_vnodeops.c */ + afs_int32 C_getsysname; /* afs_vnodeops.c */ + afs_int32 C_strcat; /* afs_vnodeops.c */ + afs_int32 C_afs_lookup; /* afs_vnodeops.c */ + afs_int32 C_afs_create; /* afs_vnodeops.c */ + afs_int32 C_afs_LocalHero; /* afs_vnodeops.c */ + afs_int32 C_FetchWholeEnchilada; /* afs_vnodeops.c */ + afs_int32 C_afs_remove; /* afs_vnodeops.c */ + afs_int32 C_afs_link; /* afs_vnodeops.c */ + afs_int32 C_afs_rename; /* afs_vnodeops.c */ + afs_int32 C_afs_InitReq; /* afs_vnodeops.c */ + afs_int32 C_afs_mkdir; /* afs_vnodeops.c */ + afs_int32 C_BlobScan; /* afs_vnodeops.c */ + afs_int32 C_afs_rmdir; /* afs_vnodeops.c */ + afs_int32 C_RecLen; /* afs_vnodeops.c */ + afs_int32 C_RoundToInt; /* afs_vnodeops.c */ + afs_int32 C_afs_readdir_with_offlist; /* afs_vnodeops.c */ + afs_int32 C_DIRSIZ_LEN; /* afs_vnodeops.c */ + afs_int32 C_afs_readdir_move; /* afs_vnodeops.c */ + afs_int32 C_afs_readdir_iter; /* afs_vnodeops.c */ + afs_int32 C_HandleFlock; /* afs_vnodeops.c */ + afs_int32 C_afs_readdir; /* afs_vnodeops.c */ + afs_int32 C_afs_symlink; /* afs_vnodeops.c */ + afs_int32 C_afs_HandleLink; /* afs_vnodeops.c */ + afs_int32 C_afs_MemHandleLink; /* afs_vnodeops.c */ + afs_int32 C_afs_UFSHandleLink; /* afs_vnodeops.c */ + afs_int32 C_afs_readlink; /* afs_vnodeops.c */ + afs_int32 C_afs_fsync; /* afs_vnodeops.c */ + afs_int32 C_afs_inactive; /* afs_vnodeops.c */ + afs_int32 C_afs_ustrategy; /* afs_vnodeops.c */ + afs_int32 C_afs_bread; /* afs_vnodeops.c */ + afs_int32 C_afs_brelse; /* afs_vnodeops.c */ + afs_int32 C_afs_bmap; /* afs_vnodeops.c */ + afs_int32 C_afs_fid; /* afs_vnodeops.c */ + afs_int32 C_afs_strategy; /* afs_vnodeops.c */ + afs_int32 C_afs_FakeClose; /* afs_vnodeops.c */ + afs_int32 C_afs_FakeOpen; /* afs_vnodeops.c */ + afs_int32 C_afs_StoreOnLastReference; /* afs_vnodeops.c */ + afs_int32 C_afs_GetAccessBits; /* afs_vnodeops.c */ + afs_int32 C_afs_AccessOK; /* afs_vnodeops.c */ + afs_int32 C_shutdown_vnodeops; /* afs_vnodeops.c */ + afs_int32 C_afsio_copy; /* afs_vnodeops.c */ + afs_int32 C_afsio_trim; /* afs_vnodeops.c */ + afs_int32 C_afs_page_read; /* afs_vnodeops.c */ + afs_int32 C_afs_page_write; /* afs_vnodeops.c */ + afs_int32 C_afsio_skip; /* afs_vnodeops.c */ + afs_int32 C_afs_read1dir; /* afs_vnodeops.c */ + afs_int32 C_afs_get_groups_from_pag; /* afs_vnodeops.c */ + afs_int32 C_afs_get_pag_from_groups; /* afs_vnodeops.c */ + afs_int32 C_PagInCred; /* afs_vnodeops.c */ + afs_int32 C_afs_getgroups; /* afs_vnodeops.c */ + afs_int32 C_setpag; /* afs_vnodeops.c */ + afs_int32 C_afs_setgroups; /* afs_vnodeops.c */ + afs_int32 C_afs_page_in; /* afs_vnodeops.c */ + afs_int32 C_afs_page_out; /* afs_vnodeops.c */ + afs_int32 C_AddPag; /* afs_vnodeops.c */ + afs_int32 C_afs_AdvanceFD; /* afs_vnodeops.c */ + afs_int32 C_afs_lockf; /* afs_vnodeops.c */ + afs_int32 C_afs_xsetgroups; /* afs_vnodeops.c */ + afs_int32 C_afs_nlinks; /* afs_vnodeops.c */ + afs_int32 C_DoLockWarning; /* afs_vnodeops.c */ + afs_int32 C_afs_lockctl; /* afs_vnodeops.c */ + afs_int32 C_afs_xflock; /* afs_vnodeops.c */ + afs_int32 C_PSetSPrefs; /* afs_pioctl.c */ + afs_int32 C_PGetSPrefs; /* afs_pioctl.c */ + afs_int32 C_afs_warn; /* afs_resource.c */ + afs_int32 C_afs_warnuser; /* afs_resource.c */ + afs_int32 C_afs_pagein; /* afs_hp_subr.c */ + afs_int32 C_afs_pageout; /* afs_hp_subr.c */ + afs_int32 C_afs_hp_strategy; /* afs_hp_subr.c */ + afs_int32 C_PGetCPrefs; /* afs_pioctl.c */ + afs_int32 C_PSetCPrefs; /* afs_pioctl.c */ + afs_int32 C_SRXAFSCB_WhoAreYou; /* afs_callback.c */ + afs_int32 C_afs_DiscardDCache; /* afs_dcache.c */ + afs_int32 C_afs_FreeDiscardedDCache; /* afs_dcache.c */ + afs_int32 C_afs_MaybeFreeDiscardedDCache; /* afs_dcache.c */ afs_int32 C_PFlushMount; /* afs_pioctl.c */ - afs_int32 C_SRXAFSCB_GetServerPrefs; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_GetCellServDB; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_GetLocalCell; /* afs_callback.c*/ - afs_int32 C_afs_MarshallCacheConfig; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_GetCacheConfig; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_GetCE64; /* afs_callback.c*/ - afs_int32 C_SRXAFSCB_GetCellByNum; /* afs_callback.c*/ + afs_int32 C_SRXAFSCB_GetServerPrefs; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_GetCellServDB; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_GetLocalCell; /* afs_callback.c */ + afs_int32 C_afs_MarshallCacheConfig; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_GetCacheConfig; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_GetCE64; /* afs_callback.c */ + afs_int32 C_SRXAFSCB_GetCellByNum; /* afs_callback.c */ }; struct afs_CMMeanStats { - struct afs_MeanStats something; /* fill this in */ + struct afs_MeanStats something; /* fill this in */ }; struct afs_CMStats { @@ -668,12 +668,12 @@ extern struct afs_CMStats afs_cmstats; */ #define AFS_STATS_NUM_DOWNTIME_DURATION_BUCKETS 7 -#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET0 600 /*10 minutes*/ -#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET1 1800 /*30 minutes*/ -#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET2 3600 /*60 minutes*/ -#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET3 7200 /*2 hours*/ -#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET4 14400 /*4 hours*/ -#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET5 28800 /*8 hours*/ +#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET0 600 /*10 minutes */ +#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET1 1800 /*30 minutes */ +#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET2 3600 /*60 minutes */ +#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET3 7200 /*2 hours */ +#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET4 14400 /*4 hours */ +#define AFS_STATS_MAX_DOWNTIME_DURATION_BUCKET5 28800 /*8 hours */ /* * Constants to track downtime incidents: @@ -699,18 +699,18 @@ extern struct afs_CMStats afs_cmstats; * and those outside the client's cell. */ struct afs_stats_SrvUpDownInfo { - afs_int32 numTtlRecords; /*# records, active or inactive*/ - afs_int32 numUpRecords; /*# (active) records currently marked up*/ - afs_int32 numDownRecords; /*# (active) records currently marked down*/ - afs_int32 sumOfRecordAges; /*Sum of server record lifetimes*/ - afs_int32 ageOfYoungestRecord; /*Age of youngest server record*/ - afs_int32 ageOfOldestRecord; /*Age of oldest server record*/ - afs_int32 numDowntimeIncidents; /*Number of (completed) downtime incidents*/ - afs_int32 numRecordsNeverDown; /*Number of server records never marked down*/ - afs_int32 maxDowntimesInARecord; /*Max downtimes seen by any record*/ - afs_int32 sumOfDowntimes; /*Sum of all (completed) downtimes, in seconds*/ - afs_int32 shortestDowntime; /*Shortest downtime, in seconds*/ - afs_int32 longestDowntime; /*Longest downtime, in seconds*/ + afs_int32 numTtlRecords; /*# records, active or inactive */ + afs_int32 numUpRecords; /*# (active) records currently marked up */ + afs_int32 numDownRecords; /*# (active) records currently marked down */ + afs_int32 sumOfRecordAges; /*Sum of server record lifetimes */ + afs_int32 ageOfYoungestRecord; /*Age of youngest server record */ + afs_int32 ageOfOldestRecord; /*Age of oldest server record */ + afs_int32 numDowntimeIncidents; /*Number of (completed) downtime incidents */ + afs_int32 numRecordsNeverDown; /*Number of server records never marked down */ + afs_int32 maxDowntimesInARecord; /*Max downtimes seen by any record */ + afs_int32 sumOfDowntimes; /*Sum of all (completed) downtimes, in seconds */ + afs_int32 shortestDowntime; /*Shortest downtime, in seconds */ + afs_int32 longestDowntime; /*Longest downtime, in seconds */ /* * Arrays keeping distributions on downtime durations and number of * downtime incidents. @@ -729,39 +729,39 @@ struct afs_stats_SrvUpDownInfo { * Performance numbers for the Cache Manager. */ struct afs_stats_CMPerf { - afs_int32 numPerfCalls; /*# of performance calls rcvd*/ - - afs_int32 epoch; /*Cache Manager epoch time*/ - afs_int32 numCellsVisible; /*# cells we know about*/ - afs_int32 numCellsContacted; /*# cells corresponded with*/ - afs_int32 dlocalAccesses; /*# data accesses to files within cell*/ - afs_int32 vlocalAccesses; /*# stat accesses to files within cell*/ - afs_int32 dremoteAccesses; /*# data accesses to files outside of cell*/ - afs_int32 vremoteAccesses; /*# stat accesses to files outside of cell*/ - afs_int32 cacheNumEntries; /*# cache entries*/ - afs_int32 cacheBlocksTotal; /*# (1K) blocks configured for cache*/ - afs_int32 cacheBlocksInUse; /*# cache blocks actively in use*/ - afs_int32 cacheBlocksOrig; /*# cache blocks at bootup*/ - afs_int32 cacheMaxDirtyChunks; /*Max # dirty cache chunks tolerated*/ - afs_int32 cacheCurrDirtyChunks; /*Current # dirty cache chunks*/ - afs_int32 dcacheHits; /*# data files found in local cache*/ - afs_int32 vcacheHits; /*# stat entries found in local cache*/ - afs_int32 dcacheMisses; /*# data files NOT found in local cache*/ - afs_int32 vcacheMisses; /*# stat entries NOT found in local cache*/ - afs_int32 cacheFlushes; /*# files flushed from cache*/ - afs_int32 cacheFilesReused; /*# cache files reused*/ - afs_int32 ProtServerAddr; /*Addr of Protection Server used*/ - afs_int32 vcacheXAllocs; /* Additionally allocated vcaches */ - afs_int32 dcacheXAllocs; /* Additionally allocated dcaches */ + afs_int32 numPerfCalls; /*# of performance calls rcvd */ + + afs_int32 epoch; /*Cache Manager epoch time */ + afs_int32 numCellsVisible; /*# cells we know about */ + afs_int32 numCellsContacted; /*# cells corresponded with */ + afs_int32 dlocalAccesses; /*# data accesses to files within cell */ + afs_int32 vlocalAccesses; /*# stat accesses to files within cell */ + afs_int32 dremoteAccesses; /*# data accesses to files outside of cell */ + afs_int32 vremoteAccesses; /*# stat accesses to files outside of cell */ + afs_int32 cacheNumEntries; /*# cache entries */ + afs_int32 cacheBlocksTotal; /*# (1K) blocks configured for cache */ + afs_int32 cacheBlocksInUse; /*# cache blocks actively in use */ + afs_int32 cacheBlocksOrig; /*# cache blocks at bootup */ + afs_int32 cacheMaxDirtyChunks; /*Max # dirty cache chunks tolerated */ + afs_int32 cacheCurrDirtyChunks; /*Current # dirty cache chunks */ + afs_int32 dcacheHits; /*# data files found in local cache */ + afs_int32 vcacheHits; /*# stat entries found in local cache */ + afs_int32 dcacheMisses; /*# data files NOT found in local cache */ + afs_int32 vcacheMisses; /*# stat entries NOT found in local cache */ + afs_int32 cacheFlushes; /*# files flushed from cache */ + afs_int32 cacheFilesReused; /*# cache files reused */ + afs_int32 ProtServerAddr; /*Addr of Protection Server used */ + afs_int32 vcacheXAllocs; /* Additionally allocated vcaches */ + afs_int32 dcacheXAllocs; /* Additionally allocated dcaches */ /* * Some stats related to our buffer package */ - afs_int32 bufAlloced; /* # of buffers allocated by afs */ + afs_int32 bufAlloced; /* # of buffers allocated by afs */ afs_int32 bufHits; /* # of pages found on buffer cache */ - afs_int32 bufMisses; /* # of pages NOT found on buffer cache */ - afs_int32 bufFlushDirty; /* # of cached dirty bufs flushed because all busy */ - + afs_int32 bufMisses; /* # of pages NOT found on buffer cache */ + afs_int32 bufFlushDirty; /* # of cached dirty bufs flushed because all busy */ + /* * Stats that keep track of all allocated/used objects in CM */ @@ -779,9 +779,9 @@ struct afs_stats_CMPerf { /* * Accounting stats having to do with the server table & records. */ - afs_int32 srvRecords; /*# of servers currently on record*/ - afs_int32 srvRecordsHWM; /* Server record high water mark */ - afs_int32 srvNumBuckets; /* Num server hash chain buckets */ + afs_int32 srvRecords; /*# of servers currently on record */ + afs_int32 srvRecordsHWM; /* Server record high water mark */ + afs_int32 srvNumBuckets; /* Num server hash chain buckets */ afs_int32 srvMaxChainLength; /* Max server hash chain length */ afs_int32 srvMaxChainLengthHWM; /* Server hash chain high water mark */ @@ -789,7 +789,7 @@ struct afs_stats_CMPerf { * Stats having to do with the systype upon which the Cache Manager * is running. */ - afs_int32 sysName_ID; /*Sysname ID for host hardware*/ + afs_int32 sysName_ID; /*Sysname ID for host hardware */ /* * Stats recording downtime characteristics for each File Server and Volume @@ -805,7 +805,7 @@ struct afs_stats_CMPerf { /* * Spares for future expansion. */ - afs_int32 spare[13]; /*Spares*/ + afs_int32 spare[13]; /*Spares */ }; @@ -865,12 +865,12 @@ struct afs_stats_CMPerf { * Record to track timing numbers for each Cache Manager RPC operation. */ struct afs_stats_opTimingData { - afs_int32 numOps; /*Number of operations executed*/ - afs_int32 numSuccesses; /*Number of successful ops*/ - osi_timeval_t sumTime; /*Sum of sample timings*/ - osi_timeval_t sqrTime; /*Sum of squares of sample timings */ - osi_timeval_t minTime; /*Minimum timing value observed*/ - osi_timeval_t maxTime; /*Minimum timing value observed*/ + afs_int32 numOps; /*Number of operations executed */ + afs_int32 numSuccesses; /*Number of successful ops */ + osi_timeval_t sumTime; /*Sum of sample timings */ + osi_timeval_t sqrTime; /*Sum of squares of sample timings */ + osi_timeval_t minTime; /*Minimum timing value observed */ + osi_timeval_t maxTime; /*Minimum timing value observed */ }; /* @@ -891,16 +891,16 @@ struct afs_stats_opTimingData { * Record to track timings and byte sizes for data transfers. */ struct afs_stats_xferData { - afs_int32 numXfers; /*Number of successful xfers*/ - afs_int32 numSuccesses; /*Number of successful xfers*/ - osi_timeval_t sumTime; /*Sum of timing values*/ - osi_timeval_t sqrTime; /*Sum of squares of timing values */ - osi_timeval_t minTime; /*Minimum xfer time recorded*/ - osi_timeval_t maxTime; /*Maximum xfer time recorded*/ - afs_int32 sumBytes; /*Sum of KBytes transferred*/ - afs_int32 minBytes; /*Minimum value observed*/ - afs_int32 maxBytes; /*Maximum value observed*/ - afs_int32 count[AFS_STATS_NUM_XFER_BUCKETS]; /*Tally for each range of bytes*/ + afs_int32 numXfers; /*Number of successful xfers */ + afs_int32 numSuccesses; /*Number of successful xfers */ + osi_timeval_t sumTime; /*Sum of timing values */ + osi_timeval_t sqrTime; /*Sum of squares of timing values */ + osi_timeval_t minTime; /*Minimum xfer time recorded */ + osi_timeval_t maxTime; /*Maximum xfer time recorded */ + afs_int32 sumBytes; /*Sum of KBytes transferred */ + afs_int32 minBytes; /*Minimum value observed */ + afs_int32 maxBytes; /*Maximum value observed */ + afs_int32 count[AFS_STATS_NUM_XFER_BUCKETS]; /*Tally for each range of bytes */ }; /* @@ -1047,12 +1047,12 @@ struct afs_stats_xferData { * Structure recording RPC outcomes. */ struct afs_stats_RPCErrors { - afs_int32 err_Server; /*Server down error*/ - afs_int32 err_Network; /*Network error*/ - afs_int32 err_Protection; /*Protection violation*/ - afs_int32 err_Volume; /*Volume-related error*/ - afs_int32 err_VolumeBusies; /*"Volume busy conditions encountered*/ - afs_int32 err_Other; /*Misc other errors*/ + afs_int32 err_Server; /*Server down error */ + afs_int32 err_Network; /*Network error */ + afs_int32 err_Protection; /*Protection violation */ + afs_int32 err_Volume; /*Volume-related error */ + afs_int32 err_VolumeBusies; /*"Volume busy conditions encountered */ + afs_int32 err_Other; /*Misc other errors */ }; @@ -1061,13 +1061,13 @@ struct afs_stats_RPCErrors { */ struct afs_stats_RPCOpInfo { struct afs_stats_opTimingData - fsRPCTimes[AFS_STATS_NUM_FS_RPC_OPS]; /*Individual FS RPC op timings*/ + fsRPCTimes[AFS_STATS_NUM_FS_RPC_OPS]; /*Individual FS RPC op timings */ struct afs_stats_RPCErrors - fsRPCErrors[AFS_STATS_NUM_FS_RPC_OPS]; /*Individual FS RPC op errors*/ + fsRPCErrors[AFS_STATS_NUM_FS_RPC_OPS]; /*Individual FS RPC op errors */ struct afs_stats_xferData - fsXferTimes[AFS_STATS_NUM_FS_XFER_OPS]; /*Individual FS RPC xfer timings*/ + fsXferTimes[AFS_STATS_NUM_FS_XFER_OPS]; /*Individual FS RPC xfer timings */ struct afs_stats_opTimingData - cmRPCTimes[AFS_STATS_NUM_CM_RPC_OPS]; /*Individual CM RPC op timings*/ + cmRPCTimes[AFS_STATS_NUM_CM_RPC_OPS]; /*Individual CM RPC op timings */ }; /* @@ -1078,25 +1078,25 @@ struct afs_stats_AuthentInfo { * This first set of fields don't have any history - they are simply * snapshots of the system at the time of the probe. */ - afs_int32 curr_PAGs; /*Current number of PAGs*/ - afs_int32 curr_Records; /*Current # of records in table*/ + afs_int32 curr_PAGs; /*Current number of PAGs */ + afs_int32 curr_Records; /*Current # of records in table */ afs_int32 curr_AuthRecords; /*Current # of authenticated - records (w/valid ticket)*/ + * records (w/valid ticket) */ afs_int32 curr_UnauthRecords; /*Current # of unauthenticated - records (w/o any ticket at all)*/ - afs_int32 curr_MaxRecordsInPAG; /*Max records for a single PAG*/ - afs_int32 curr_LongestChain; /*Length of longest current hash chain*/ + * records (w/o any ticket at all) */ + afs_int32 curr_MaxRecordsInPAG; /*Max records for a single PAG */ + afs_int32 curr_LongestChain; /*Length of longest current hash chain */ /* * This second set of fields are values accumulated over the lifetme * of the current CM incarnation. */ - afs_int32 PAGCreations; /*# PAG creations*/ - afs_int32 TicketUpdates; /*# ticket additions/refreshes*/ - afs_int32 HWM_PAGs; /*High water mark - # PAGs*/ - afs_int32 HWM_Records; /* " - # records*/ - afs_int32 HWM_MaxRecordsInPAG; /* " - max records for a single PAG*/ - afs_int32 HWM_LongestChain; /* " - longest hash chain*/ + afs_int32 PAGCreations; /*# PAG creations */ + afs_int32 TicketUpdates; /*# ticket additions/refreshes */ + afs_int32 HWM_PAGs; /*High water mark - # PAGs */ + afs_int32 HWM_Records; /* " - # records */ + afs_int32 HWM_MaxRecordsInPAG; /* " - max records for a single PAG */ + afs_int32 HWM_LongestChain; /* " - longest hash chain */ }; /* @@ -1105,11 +1105,11 @@ struct afs_stats_AuthentInfo { * case of failure. */ struct afs_stats_AccessInfo { - afs_int32 unreplicatedRefs; /*# references to unreplicated data*/ - afs_int32 replicatedRefs; /*# references to replicated data*/ - afs_int32 numReplicasAccessed; /*# replicas accessed*/ - afs_int32 maxReplicasPerRef; /*Max # replicas accessed per ref*/ - afs_int32 refFirstReplicaOK; /*# references satisfied by 1st replica*/ + afs_int32 unreplicatedRefs; /*# references to unreplicated data */ + afs_int32 replicatedRefs; /*# references to replicated data */ + afs_int32 numReplicasAccessed; /*# replicas accessed */ + afs_int32 maxReplicasPerRef; /*Max # replicas accessed per ref */ + afs_int32 refFirstReplicaOK; /*# references satisfied by 1st replica */ }; /* @@ -1118,31 +1118,31 @@ struct afs_stats_AccessInfo { * Results cover all objects in the cache uniformly. */ struct afs_stats_AuthorInfo { - afs_int32 fileSameAuthor; /*File write by same author*/ - afs_int32 fileDiffAuthor; /*File write by diff author*/ - afs_int32 dirSameAuthor; /*Directory write by same author*/ - afs_int32 dirDiffAuthor; /*Directory write by diff author*/ + afs_int32 fileSameAuthor; /*File write by same author */ + afs_int32 fileDiffAuthor; /*File write by diff author */ + afs_int32 dirSameAuthor; /*Directory write by same author */ + afs_int32 dirDiffAuthor; /*Directory write by diff author */ }; /* * Structure holding ``full'' CM peformance measurements. */ struct afs_stats_CMFullPerf { - afs_int32 numFullPerfCalls; /*Number of accesses*/ - struct afs_stats_CMPerf perf; /*General performance stats*/ - struct afs_stats_RPCOpInfo rpc; /*RPC op stats*/ - struct afs_stats_AuthentInfo authent; /*Authentication stats*/ - struct afs_stats_AccessInfo accessinf; /*Access stats*/ - struct afs_stats_AuthorInfo author; /*Authorship stats*/ + afs_int32 numFullPerfCalls; /*Number of accesses */ + struct afs_stats_CMPerf perf; /*General performance stats */ + struct afs_stats_RPCOpInfo rpc; /*RPC op stats */ + struct afs_stats_AuthentInfo authent; /*Authentication stats */ + struct afs_stats_AccessInfo accessinf; /*Access stats */ + struct afs_stats_AuthorInfo author; /*Authorship stats */ }; /* * These are the storage declarations for the structures accessible * via the xstat package. */ -extern struct afs_stats_CMPerf afs_stats_cmperf; -extern struct afs_stats_CMFullPerf afs_stats_cmfullperf; -extern afs_int32 afs_stats_XferSumBytes[]; +/* extern struct afs_stats_CMPerf afs_stats_cmperf; */ +/* extern struct afs_stats_CMFullPerf afs_stats_cmfullperf; */ +/* extern afs_int32 afs_stats_XferSumBytes[]; */ #ifndef AFS_NOSTATS /* @@ -1159,4 +1159,4 @@ extern afs_int32 afs_stats_XferSumBytes[]; #endif /* AFS_NOSTATS */ -#endif /* __TRANSARC_AFS_STATS_H__ */ +#endif /* __OPENAFS_AFS_STATS_H__ */ diff --git a/src/afs/afs_trace.et b/src/afs/afs_trace.et index 24817af5a..854ea23ff 100644 --- a/src/afs/afs_trace.et +++ b/src/afs/afs_trace.et @@ -1,32 +1,31 @@ # Copyright 2000, International Business Machines Corporation and others. # All Rights Reserved. -# +# # This software has been released under the terms of the IBM Public # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html error_table 2 ZCM ec CM_TRACE_NULL, "dummy" - ec CM_TRACE_PAGEIN, "getapage vp 0x%lx off 0x%x len 0x%x rw=0x%x" + ec CM_TRACE_PAGEIN, "getapage vp 0x%lx off (0x%x, 0x%x) len 0x%x rw=0x%x" ec CM_TRACE_PAGEINDONE, "getapage done code 0x%x pg 0x%lx (0x%x)" - ec CM_TRACE_PAGEOUT, "putpage vp 0x%lx off 0x%x len 0x%x flags=0x%x" + ec CM_TRACE_PAGEOUT, "putpage vp 0x%lx off (0x%x, 0x%x) len 0x%x flags=0x%x" ec CM_TRACE_PAGEOUTDONE, "putpage done code 0x%x #dirty 0x%x" - ec CM_TRACE_PAGEOUTONE, "putApage vp 0x%lx pag 0x%lx len 0x%x off 0x%x" - ec CM_TRACE_VMRW, "vmrw vp 0x%lx, write=0x%x, off=0x%x, len=0x%x" + ec CM_TRACE_PAGEOUTONE, "putApage vp 0x%lx pag 0x%lx len 0x%x off (0x%x, 0x%x)" + ec CM_TRACE_VMRW, "vmrw vp 0x%lx, write=0x%x, off=(0x%x, 0x%x), len=(0x%x, 0x%x)" ec CM_TRACE_STRATEGYDONE, "strategy done vp 0x%lx code 0x%x left 0x%x" ec CM_TRACE_FLUSHV, "flushv vp 0x%lx states 0x%x" - ec CM_TRACE_GETDOWND, "getdownd vp 0x%lx skip 0x%x idxf 0x%x coff 0x%x" + ec CM_TRACE_GETDOWND, "getdownd vp 0x%lx skip 0x%x index %d coff (0x%x, 0x%x)" ec CM_TRACE_ACTCCORE, "ActiveCore vp 0x%lx XoW 0x%x" - ec CM_TRACE_WVCACHE, "RXAFS_StoreStatus vp 0x%lx len 0x%x" + ec CM_TRACE_WVCACHE, "RXAFS_StoreStatus vp 0x%lx len (0x%x, 0x%x)" ec CM_TRACE_TRYTOSMUSH, "TryToSmush vp 0x%lx len 0x%x" - ec CM_TRACE_STOREPROC, "StoreProc vp 0x%lx tlen 0x%x alen 0x%x" - ec CM_TRACE_FETCHPROC, "FetchProc vp 0x%lx pos 0x%x size 0x%x" - ec CM_TRACE_SIMPLEVSTAT, "SimpleVStat vp 0x%lx old len 0x%x new len 0x%x" - ec CM_TRACE_PROCESSFS, "ProcessFS vp 0x%lx old len 0x%x new len 0x%x" - ec CM_TRACE_STOREALL, "StoreAll vp 0x%lx len 0x%x" + ec CM_TRACE_STOREPROC, "StoreProc vp 0x%lx fid (%x:%d.%d.%d) m.Length (0x%x, 0x%x) alen 0x%x" + ec CM_TRACE_FETCHPROC, "FetchProc vp 0x%lx fid (%x:%d.%d.%d) pos (0x%x, 0x%x) size 0x%x" + ec CM_TRACE_SIMPLEVSTAT, "SimpleVStat vp 0x%lx old len (0x%x, 0x%x) new len (0x%x, 0x%x)" + ec CM_TRACE_PROCESSFS, "ProcessFS vp 0x%lx old len (0x%x, 0x%x) new len (0x%x, 0x%x)" + ec CM_TRACE_STOREALL, "StoreAll vp 0x%lx len (0x%x, 0x%x)" ec CM_TRACE_INVALL, "InvalAll vp 0x%lx len 0x%x" - ec CM_TRACE_TRUNCALL1, "TruncAll vp 0x%lx old len 0x%x new len 0x%x" - ec CM_TRACE_TRUNCALL2,"TruncAll vp 0x%lx vlen 0x%x len 0x%x" + ec CM_TRACE_TRUNCALL, "TruncAll vp 0x%lx old len (0x%x, 0x%x) new len (0x%x, 0x%x)" ec CM_TRACE_GNLINK, "Gn_link vp 0x%lx name %s (returns 0x%x)" ec CM_TRACE_GMKDIR, "Gn_mkdir vp 0x%lx name %s mode 0x%x (returns 0x%x)" @@ -45,7 +44,7 @@ error_table 2 ZCM ec CM_TRACE_GSETATTR, "Gn_setattr vp 0x%lx (returns 0x%x)" ec CM_TRACE_GFCLEAR, "Gn_fclear vp 0x%lx offset 0x%x len 0x%x (returns 0x%x)" ec CM_TRACE_GFSYNC, "Gn_fsync vp 0x%lx flags 0x%x (returns 0x%x)" - ec CM_TRACE_GFTRUNC, "Gn_ftrunc vp 0x%lx flags 0x%x len 0x%x (returns 0x%x)" + ec CM_TRACE_GFTRUNC, "Gn_ftrunc vp 0x%lx flags 0x%x len (0x%x, 0x%x) (returns 0x%x)" ec CM_TRACE_GRDWR, "Gn_rdwr vp 0x%lx flags 0x%x op 0x%x (returns 0x%x)" ec CM_TRACE_GLOCKCTL, "Gn_locktl vp 0x%lx cmd 0x%x (returns 0x%x)" ec CM_TRACE_GIOCTL, "Gn_ioctl vp 0x%lx cmd 0x%x (returns 0x%x)" @@ -56,7 +55,8 @@ error_table 2 ZCM ec CM_TRACE_STUFFVCACHE, "StuffVcache 0x%lx callback host 0x%lx expires %u (in %u secs)" ec CM_TRACE_GETDCACHE1, "Getdcache vp 0x%lx failed to find chunk 0x%x" ec CM_TRACE_GETDCACHE2, "GetdCache vp 0x%lx dcache 0x%lx dcache low-version 0x%x, vcache low-version 0x%x" - ec CM_TRACE_STOREMINI, "storemini vp 0x%lx length 0x%x" + ec CM_TRACE_GETDCACHE3, "GetdCache tlen 0x%x flags 0x%x abyte (0x%x, 0x%x) Position (0x%x, 0x%x)" + ec CM_TRACE_STOREMINI, "storemini vp 0x%lx length (0x%x, 0x%x)" ec CM_TRACE_STOREDCACHE, "StoreDCache vp 0x%lx chunk 0x%x length 0x%x at position 0x%x" ec CM_TRACE_STOREDCACHEDONE, "StoreDCache Done for vp 0x%lx (returns 0x%x)" ec CM_TRACE_STOREALLDONE, "StoreAll Done vp 0x%lx length 0x%x (returns 0x%x)" @@ -71,7 +71,7 @@ error_table 2 ZCM ec CM_TRACE_NFSOUT, "NfsOut op 0x%x vp 0x%lx fid (%x:%d.%d.%d)" ec CM_TRACE_NFSIN, "NfsIn op 0x%x" ec CM_TRACE_NFSIN1, "Nfs Root fid client 0x%lx fid (%x:%d.%d.%d)" - ec CM_TRACE_FLUSHPAGES, "flushpages vp 0x%x data version low 0x%x length 0x%x" + ec CM_TRACE_FLUSHPAGES, "flushpages vp 0x%lx data version low 0x%x length 0x%x" ec CM_TRACE_SYNCVM, "SyncVM vp 0x%lx length 0x%x" ec CM_TRACE_PIOCTL, "Pioctl command 0x%x for vp 0x%lx, follow=%d" ec CM_TRACE_CHECKCODE, "Returning code %d from %d" @@ -81,17 +81,17 @@ error_table 2 ZCM ec CM_TRACE_SETPAG, "Setpag returns 0x%x" ec CM_TRACE_OPEN, "Open 0x%x flags 0x%x" ec CM_TRACE_CLOSE, "Close 0x%lx flags 0x%x" - ec CM_TRACE_WRITE, "Write vp 0x%lx off 0x%x resid 0x%x file length 0x%x" - ec CM_TRACE_READ, "Read vp 0x%lx off 0x%x resid 0x%x file length 0x%x" - ec CM_TRACE_PARTIALWRITE, "Partial write vp 0x%lx length 0x%x" - ec CM_TRACE_GETATTR, "Getattr vp 0x%lx len 0x%x" - ec CM_TRACE_SETATTR, "Setattr vp 0x%lx len 0x%x" - ec CM_TRACE_ACCESS, "Access vp 0x%lx mode 0x%x len 0x%x" + ec CM_TRACE_WRITE, "Write vp 0x%lx off (0x%x, 0x%x) resid (0x%x, 0x%x) file length (0x%x, 0x%x)" + ec CM_TRACE_READ, "Read vp 0x%lx off (0x%x, 0x%x) resid 0x%x file length (0x%x, 0x%x)" + ec CM_TRACE_PARTIALWRITE, "Partial write vp 0x%lx length (0x%x, 0x%x)" + ec CM_TRACE_GETATTR, "Getattr vp 0x%lx len (0x%x, 0x%x)" + ec CM_TRACE_SETATTR, "Setattr vp 0x%lx mask 0x%x newlen (0x%x, 0x%x) oldlen (0x%x, 0x%x)" + ec CM_TRACE_ACCESS, "Access vp 0x%lx mode 0x%x len (0x%x, 0x%x)" ec CM_TRACE_LOOKUP, "Lookup adp 0x%lx name %s fid (%d:%d.%d.%d), code=%d" ec CM_TRACE_LOOKUP1, "Mount point is to vp 0x%lx fid (%d:%d.%d.%d)" ec CM_TRACE_CREATE, "create file in vp 0x%lx name %s mode 0x%x" ec CM_TRACE_REMOVE, "remove dir 0x%lx name %s" - ec CM_TRACE_LINK, "hard link dir 0x%lx vp %lx name %s" + ec CM_TRACE_LINK, "hard link dir 0x%lx vp 0x%lx name %s" ec CM_TRACE_RENAME, "Rename d1 0x%lx name %s to d2 0x%lx name %s" ec CM_TRACE_MKDIR, "Mkdir parent 0x%lx entry %s" ec CM_TRACE_RMDIR, "Rmdir parent 0x%lx entry %s" @@ -99,10 +99,10 @@ error_table 2 ZCM ec CM_TRACE_READLINK, "readlink 0x%lx" ec CM_TRACE_FSYNC, "fsync 0x%lx" - ec CM_TRACE_LOCKDONE, "Released lock 0x%lx level %d" - ec CM_TRACE_LOCKDOWN, "Downgraded lock 0x%lx to %d" - ec CM_TRACE_LOCKOBTAIN,"Obtained lock 0x%lx level %d" - ec CM_TRACE_LOCKSLEPT, "Slept for lock 0x%lx level %d" + ec CM_TRACE_LOCKDONE, "%s line %d: Released lock 0x%lx level %d" + ec CM_TRACE_LOCKDOWN, "%s line %d: Downgraded lock 0x%lx to %d" + ec CM_TRACE_LOCKOBTAIN,"%s line %d: Obtained lock 0x%lx level %d" + ec CM_TRACE_LOCKSLEPT, "Slept %lu us for lock 0x%lx level %d" ec CM_TRACE_PAGE_READ, "0x%lx called page_read (returned %d) states 0x%x" ec CM_TRACE_PAGE_WRITE, "0x%lx called page_write (returned %d) states 0x%x" @@ -122,15 +122,55 @@ error_table 2 ZCM ec CM_TRACE_NFS3IN1, "Nfs3 Root fid client 0x%lx fid (%x:%d.%d.%d)" ec CM_TRACE_VGET, "Vget vp 0x%lx uid %x fid (%x:%d.%d.%d)" ec CM_TRACE_VFSROOT, "vfs root vp 0x%lx, code %d" - ec CM_TRACE_READOP, "Iread ip 0x%lx pos 0x%x count 0x%x code %x" - ec CM_TRACE_WRITEOP, "Iwrite ip 0x%lx pos 0x%x count 0x%x code %x" + ec CM_TRACE_READOP, "Iread ip x%lx pos (0x%x, 0x%x) count 0x%x code %x" + ec CM_TRACE_WRITEOP, "Iwrite ip 0x%lx pos (0x%x, 0x%x) count 0x%x code %x" ec CM_TRACE_READPAGE, "Ireadpage ip 0x%lx pp 0x%x count 0x%x code %x" ec CM_TRACE_UPDATEPAGE, "Iupdatepage ip 0x%lx pp 0x%x count 0x%x code %d" ec CM_TRACE_VM_CLOSE, "VMclose ip 0x%lx mapcnt %d opens %d XoW %d" - ec CM_TRACE_PREFETCHCMD, "PrefetchCmd tvc 0x%x tfid (%d:%d.%d.%d) fid (%d:%d.%d.%d)" - ec CM_TRACE_RESIDCMD, "ResidencyCmd tvc 0x%x command %d fid (%d:%d.%d.%d)" - ec CM_TRACE_DENTRYDELETE, "d_delete inode 0x%x d_name %s/%s" + ec CM_TRACE_FETCH64, "FetchProc for vp = 0x%lx oldserver was %d, found length (0x%x, 0x%x)" + ec CM_TRACE_UFSLINK, "UFSHandleLink: vp = 0x%lx, tdc 0x%lx, len (0x%x, 0x%x)" + ec CM_TRACE_VMRDWR, "afs_vm_rdwr: vp = 0x%lx, xfrSize 0x%lx, toffset 0x%x" + ec CM_TRACE_READFAST, "ReadFast vp 0x%lx off (0x%x, 0x%x) resid 0x%x file length (0x%x, 0x%x)" + ec CM_TRACE_FETCH64CODE, "StartRX_FetchData64 for vp 0x%lx returned %d" + ec CM_TRACE_FETCH64LENG, "FetchData64 for vp 0xl%x code = %d, length = (0x%x, 0x%x)" + ec CM_TRACE_FETCH64READ, "FetchData64 for vp 0xl%x code = %d, length = 0x%x" + ec CM_TRACE_VMWRITE, "afs_vm_rdwr: vp 0x%lx offset (0x%x, 0x%x) length (0x%x, 0x%x)" + ec CM_TRACE_VMWRITE2, "afs_vm_rdwr: vp 0x%lx first page 0x%x pages %d" + ec CM_TRACE_VMSTOREALL, "osi_VM_StoreAllSegments for vp 0x%lx call %d" + ec CM_TRACE_PARTIALWRITE0, "Partial write currDirty %d maxDirty %d" + ec CM_TRACE_DIRECTRDWR, "direct_rdwr: vp 0x%lx offset (0x%x, 0x%x) resid 0x%x" + ec CM_TRACE_GOPRDWR, "gop_rdwr: offset (0x%x, 0x%x) len 0x%x resid 0x%x code %d" + ec CM_TRACE_GRDWR1, "Gn_rdwr error vp 0x%lx returns %d" + ec CM_TRACE_READTDC, "UFSRead: vp 0x%lx tdc 0x%lx at %d refcount 0x%x" + ec CM_TRACE_MEMFETCH, "MemFetch: vp 0x%lx mceP 0x%lx offset (0x%x, 0x%x) length 0x%x" + ec CM_TRACE_VMWRITE3, "afs_vm_rdwr: vp 0x%lx code %d" + ec CM_TRACE_STOREALL2, "StoreAll 2 vp 0x%lx chunk 0x%x index %d inode %d" + ec CM_TRACE_MEMOPEN, "MemOpen blkno %d mceP 0x%x data 0x%x = %s" + ec CM_TRACE_VCACHE2INODE, "vcache2inode: avc 0x%x event %d" + ec CM_TRACE_STOREDATA64, "StoreData64: fid (%d:%d.%d.%d) offs (0x%x, 0x%x) len (0x%x, 0x%x) file length (0x%x, 0x%x)" + ec CM_TRACE_RESIDCMD, "ResidencyCmd tvc 0x%x command %d fid (%d:%d.%d.%d)" + ec CM_TRACE_PREFETCHCMD, "PrefetchCmd tvc 0x%x tfid (%d:%d.%d.%d) fid (%d:%d.%d.%d)" + ec CM_TRACE_STOREPROC2, "StoreProc got (0x%x, 0x%x) length 0x%x" + ec CM_TRACE_ADJUSTSIZE, "AdjustSize index %d oldSize %d newSize %d blocksUsed %d" + ec CM_TRACE_SETLENGTH, "%s line %d: m.Length was (0x%x, 0x%x), now (0x%x, 0x%x)" + ec CM_TRACE_DCACHEWAIT, "%s line %d: waiting for 0x%x flags 0x%x" + ec CM_TRACE_VNODEREAD, "UFSRead: tdc 0x%lx, offset (0x%x, 0x%x) len (0x%x 0x%x)" + ec CM_TRACE_SLEEP, "Sleep: evp 0x%lx, count %d seq 0x%x evp->seq 0x%x" + ec CM_TRACE_WAKE, "Wakeup: evp 0x%lx, evp->seq 0x%x" + ec CM_TRACE_DENTRYDELETE, "d_delete inode 0x%x d_name %s/%s" ec CM_TRACE_DENTRYIPUT, "d_iput inode 0x%x d_name %s/%s" ec CM_TRACE_TRYFLUSHDCACHECHILDREN, "TryFlushDcacheChildren ip 0x%x name %s parent %s" + ec CM_TRACE_DCACHEWAKE, "%s line %d: waking up waiters for 0x%x flags 0x%x" + ec CM_TRACE_VERSIONNO, "At offset (0x%x, 0x%x) vc shows (0x%x, 0x%x), dc (0x%x, 0x%x)" + ec CM_TRACE_TIMESTAMP, "%s" + ec CM_TRACE_RXSLEEP, "osi_rxSleep() at %s line %d" + ec CM_TRACE_RXWAKE, "osi_rxWakeup() at %s line %d" + ec CM_TRACE_GNGETACL, "Gn_getacl vp 0x%lx (returns 0x%x)" + ec CM_TRACE_EINVAL, "EINVAL in %s at line %d" + ec CM_TRACE_VNODEREAD2, "negative length tdc 0x%lx validPos (0x%x, 0x%x) chunkBytes 0x%x dflags 0x%x" + ec CM_TRACE_WASHERE, "Was here: %s line %d, code = %d" + ec CM_TRACE_LOCKWAIT,"%s line %d: Waiting for lock 0x%lx level %d" + ec CM_TRACE_WRITEFAILED, "osi_Write failed len %ld resid %ld err %ld" + ec CM_TRACE_ADJUSTSIZE2, "AdjustSize dc = 0x%lx, chunkBytes = 0x%x used = %ld, diff = %ld" end diff --git a/src/afs/afs_user.c b/src/afs/afs_user.c index 27e70f086..c40c09a75 100644 --- a/src/afs/afs_user.c +++ b/src/afs/afs_user.c @@ -11,12 +11,13 @@ * Implements: */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_user.c,v 1.1.1.9 2003/07/30 17:08:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_user.c,v 1.15 2003/07/15 23:14:13 shadow Exp $"); -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ #if !defined(UKERNEL) #if !defined(AFS_LINUX20_ENV) @@ -25,15 +26,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_user.c,v 1.1.1.9 2003/07/30 17: #include #ifdef AFS_SGI62_ENV -#include "../h/hashing.h" +#include "h/hashing.h" #endif #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV) #include #endif /* ! AFS_HPUX110_ENV */ #endif /* !defined(UKERNEL) */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ #if defined(AFS_SUN56_ENV) #include @@ -45,14 +46,6 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_user.c,v 1.1.1.9 2003/07/30 17: #endif -/* Imported variables */ -extern afs_rwlock_t afs_xserver; -extern afs_rwlock_t afs_xsrvAddr; -extern afs_rwlock_t afs_xconn; -extern afs_rwlock_t afs_xvcache; -extern struct srvAddr *afs_srvAddrs[NSERVERS]; /* Hashed by server's ip */ -extern struct server *afs_servers[NSERVERS]; - /* Exported variables */ afs_rwlock_t afs_xuser; struct unixuser *afs_users[NUSERS]; @@ -65,8 +58,8 @@ void afs_ResetAccessCache(afs_int32 uid, int alock); * Called with afs_xuser, afs_xserver and afs_xconn locks held, to delete * appropriate conn structures for au */ -static void RemoveUserConns(au) - register struct unixuser *au; +static void +RemoveUserConns(register struct unixuser *au) { register int i; register struct server *ts; @@ -74,9 +67,9 @@ static void RemoveUserConns(au) register struct conn *tc, **lc; AFS_STATCNT(RemoveUserConns); - for (i=0;inext) { - for (sa = ts->addr; sa; sa = sa->next_sa) { + for (i = 0; i < NSERVERS; i++) { + for (ts = afs_servers[i]; ts; ts = ts->next) { + for (sa = ts->addr; sa; sa = sa->next_sa) { lc = &sa->conns; for (tc = *lc; tc; lc = &tc->next, tc = *lc) { if (tc->user == au && tc->refCount == 0) { @@ -85,14 +78,14 @@ static void RemoveUserConns(au) rx_DestroyConnection(tc->id); AFS_GLOCK(); afs_osi_Free(tc, sizeof(struct conn)); - break; /* at most one instance per server */ - } /*Found unreferenced connection for user*/ - } /*For each connection on the server*/ + break; /* at most one instance per server */ + } /*Found unreferenced connection for user */ + } /*For each connection on the server */ } - } /*For each server on chain*/ - } /*For each chain*/ + } /*For each server on chain */ + } /*For each chain */ -} /*RemoveUserConns*/ +} /*RemoveUserConns */ /* Called from afs_Daemon to garbage collect unixusers no longer using system, @@ -102,18 +95,20 @@ static void RemoveUserConns(au) * other epochs as soon as possible (old file servers act bizarrely when they * see epoch changes). */ -void afs_GCUserData(aforce) { +void +afs_GCUserData(int aforce) +{ register struct unixuser *tu, **lu, *nu; register int i; afs_int32 now, delFlag; AFS_STATCNT(afs_GCUserData); /* Obtain locks in valid order */ - ObtainWriteLock(&afs_xuser,95); + ObtainWriteLock(&afs_xuser, 95); ObtainReadLock(&afs_xserver); - ObtainWriteLock(&afs_xconn,96); + ObtainWriteLock(&afs_xconn, 96); now = osi_Time(); - for (i=0;ict.EndTimestamp < now - NOTOKTIMEOUT) delFlag = 1; - } - else { + } else { if (aforce || (tu->tokenTime < now - NOTOKTIMEOUT)) delFlag = 1; } @@ -140,8 +134,7 @@ void afs_GCUserData(aforce) { if (tu->exporter) EXP_RELE(tu->exporter); afs_osi_Free(tu, sizeof(struct unixuser)); - } - else { + } else { lu = &tu->next; } } @@ -150,7 +143,7 @@ void afs_GCUserData(aforce) { ReleaseWriteLock(&afs_xuser); ReleaseReadLock(&afs_xserver); -} /*afs_GCUserData*/ +} /*afs_GCUserData */ /* @@ -158,20 +151,19 @@ void afs_GCUserData(aforce) { * cache for these guys. Can't do this when token expiration detected, * since too many locks are set then. */ -void afs_CheckTokenCache() - +void +afs_CheckTokenCache(void) { register int i; register struct unixuser *tu; afs_int32 now; - register struct cell *tcell; AFS_STATCNT(afs_CheckCacheResets); ObtainReadLock(&afs_xvcache); ObtainReadLock(&afs_xuser); now = osi_Time(); - for (i=0;inext) { + for (i = 0; i < NUSERS; i++) { + for (tu = afs_users[i]; tu; tu = tu->next) { register afs_int32 uid; /* @@ -185,10 +177,10 @@ void afs_CheckTokenCache() * cache. */ #ifdef notdef - tcell = afs_GetCell(tu->cell); /* I really hate this message - MLK */ - afs_warn("afs: Tokens for user of AFS id %d for cell %s expired now\n", - tu->vid, tcell->cellName); + afs_warn + ("afs: Tokens for user of AFS id %d for cell %s expired now\n", + tu->vid, afs_GetCell(tu->cell)->cellName); #endif tu->states |= (UTokensBad | UNeedsReset); } @@ -203,57 +195,56 @@ void afs_CheckTokenCache() ReleaseReadLock(&afs_xuser); ReleaseReadLock(&afs_xvcache); -} /*afs_CheckTokenCache*/ +} /*afs_CheckTokenCache */ -void afs_ResetAccessCache(afs_int32 uid, int alock) +void +afs_ResetAccessCache(afs_int32 uid, int alock) { - register int i, j; + register int i; register struct vcache *tvc; struct axscache *ac; AFS_STATCNT(afs_ResetAccessCache); if (alock) ObtainReadLock(&afs_xvcache); - for(i=0;ihnext) { - /* really should do this under cache write lock, but that. - is hard to under locking hierarchy */ - if (tvc->Access && (ac = afs_FindAxs(tvc->Access, uid))) { - afs_RemoveAxs (&tvc->Access, ac); - } + for (i = 0; i < VCSIZE; i++) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { + /* really should do this under cache write lock, but that. + * is hard to under locking hierarchy */ + if (tvc->Access && (ac = afs_FindAxs(tvc->Access, uid))) { + afs_RemoveAxs(&tvc->Access, ac); + } } } if (alock) ReleaseReadLock(&afs_xvcache); -} /*afs_ResetAccessCache*/ +} /*afs_ResetAccessCache */ /* * Ensure all connections make use of new tokens. Discard incorrectly-cached * access info. */ -void afs_ResetUserConns (auser) - register struct unixuser *auser; - +void +afs_ResetUserConns(register struct unixuser *auser) { int i; - struct server *ts; struct srvAddr *sa; struct conn *tc; - + AFS_STATCNT(afs_ResetUserConns); ObtainReadLock(&afs_xsrvAddr); - ObtainWriteLock(&afs_xconn,98); + ObtainWriteLock(&afs_xconn, 98); - for (i=0;inext_bkt) { - for (tc = sa->conns; tc; tc=tc->next) { - if (tc->user == auser) { - tc->forceConnectFS = 1; - } + for (i = 0; i < NSERVERS; i++) { + for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) { + for (tc = sa->conns; tc; tc = tc->next) { + if (tc->user == auser) { + tc->forceConnectFS = 1; } + } } } @@ -261,18 +252,19 @@ void afs_ResetUserConns (auser) ReleaseReadLock(&afs_xsrvAddr); afs_ResetAccessCache(auser->uid, 1); auser->states &= ~UNeedsReset; -} /*afs_ResetUserConns*/ +} /*afs_ResetUserConns */ -struct unixuser *afs_FindUser(afs_int32 auid, afs_int32 acell, afs_int32 locktype) +struct unixuser * +afs_FindUser(afs_int32 auid, afs_int32 acell, afs_int32 locktype) { register struct unixuser *tu; register afs_int32 i; AFS_STATCNT(afs_FindUser); i = UHash(auid); - ObtainWriteLock(&afs_xuser,99); - for(tu = afs_users[i]; tu; tu = tu->next) { + ObtainWriteLock(&afs_xuser, 99); + for (tu = afs_users[i]; tu; tu = tu->next) { if (tu->uid == auid && ((tu->cell == acell) || (acell == -1))) { tu->refCount++; ReleaseWriteLock(&afs_xuser); @@ -280,9 +272,9 @@ struct unixuser *afs_FindUser(afs_int32 auid, afs_int32 acell, afs_int32 locktyp } } ReleaseWriteLock(&afs_xuser); - return (struct unixuser *) 0; + return NULL; -} /*afs_FindUser*/ +} /*afs_FindUser */ /*------------------------------------------------------------------------ @@ -307,17 +299,16 @@ struct unixuser *afs_FindUser(afs_int32 auid, afs_int32 acell, afs_int32 locktyp * As advertised. *------------------------------------------------------------------------*/ -void afs_ComputePAGStats() - -{ /*afs_ComputePAGStats*/ - - register struct unixuser *currPAGP; /*Ptr to curr PAG*/ - register struct unixuser *cmpPAGP; /*Ptr to PAG being compared*/ - register struct afs_stats_AuthentInfo *authP; /*Ptr to stats area*/ - int curr_Record; /*Curr record */ - int currChain; /*Curr hash chain*/ - int currChainLen; /*Length of curr hash chain*/ - int currPAGRecords; /*# records in curr PAG*/ +void +afs_ComputePAGStats(void) +{ + register struct unixuser *currPAGP; /*Ptr to curr PAG */ + register struct unixuser *cmpPAGP; /*Ptr to PAG being compared */ + register struct afs_stats_AuthentInfo *authP; /*Ptr to stats area */ + int curr_Record; /*Curr record */ + int currChain; /*Curr hash chain */ + int currChainLen; /*Length of curr hash chain */ + int currPAGRecords; /*# records in curr PAG */ /* * Lock out everyone else from scribbling on the PAG entries. @@ -331,18 +322,17 @@ void afs_ComputePAGStats() */ curr_Record = 0; authP = &(afs_stats_cmfullperf.authent); - authP->curr_PAGs = 0; - authP->curr_Records = 0; - authP->curr_AuthRecords = 0; - authP->curr_UnauthRecords = 0; - authP->curr_MaxRecordsInPAG = 0; - authP->curr_LongestChain = 0; + authP->curr_PAGs = 0; + authP->curr_Records = 0; + authP->curr_AuthRecords = 0; + authP->curr_UnauthRecords = 0; + authP->curr_MaxRecordsInPAG = 0; + authP->curr_LongestChain = 0; for (currChain = 0; currChain < NUSERS; currChain++) { currChainLen = 0; for (currPAGP = afs_users[currChain]; currPAGP; - currPAGP = currPAGP->next) - { + currPAGP = currPAGP->next) { /* * Bump the number of records on this current chain, along with * the total number of records in existence. @@ -360,14 +350,15 @@ void afs_ComputePAGStats() * If this PAG record has already been ``counted', namely * associated with a PAG and tallied, clear its bit and move on. */ - (authP->curr_Records)++; + (authP->curr_Records)++; if (currPAGP->states & UPAGCounted) { currPAGP->states &= ~UPAGCounted; continue; - } /*We've counted this one already*/ + } + /*We've counted this one already */ /* * Jot initial info down, then sweep down the rest of the hash * chain, looking for matching PAG entries. Note: to properly @@ -386,13 +377,13 @@ void afs_ComputePAGStats() */ cmpPAGP->states |= UPAGCounted; currPAGRecords++; - if ((cmpPAGP->states & UHasTokens) && - !(cmpPAGP->states & UTokensBad)) + if ((cmpPAGP->states & UHasTokens) + && !(cmpPAGP->states & UTokensBad)) (authP->curr_AuthRecords)++; else (authP->curr_UnauthRecords)++; - } /*Records belong to same PAG*/ - } /*Compare to rest of PAG records in chain*/ + } /*Records belong to same PAG */ + } /*Compare to rest of PAG records in chain */ /* * In the above comparisons, the current PAG record has been @@ -412,7 +403,7 @@ void afs_ComputePAGStats() if (currPAGRecords > authP->HWM_MaxRecordsInPAG) authP->HWM_MaxRecordsInPAG = currPAGRecords; } - } /*Sweep a hash chain*/ + } /*Sweep a hash chain */ /* * If the chain we just finished zipping through is the longest we've @@ -424,7 +415,7 @@ void afs_ComputePAGStats() authP->HWM_LongestChain = currChainLen; } - } /*For each hash chain in afs_user*/ + } /*For each hash chain in afs_user */ /* * Now that we've counted everything up, we can consider all-time @@ -440,25 +431,23 @@ void afs_ComputePAGStats() */ ReleaseReadLock(&afs_xuser); -} /*afs_ComputePAGStats*/ +} /*afs_ComputePAGStats */ -struct unixuser *afs_GetUser(auid, acell, locktype) - afs_int32 acell; - register afs_int32 auid; - afs_int32 locktype; +struct unixuser * +afs_GetUser(register afs_int32 auid, afs_int32 acell, afs_int32 locktype) { - register struct unixuser *tu, *pu=0; + register struct unixuser *tu, *pu = 0; register afs_int32 i; register afs_int32 RmtUser = 0; AFS_STATCNT(afs_GetUser); i = UHash(auid); - ObtainWriteLock(&afs_xuser,104); + ObtainWriteLock(&afs_xuser, 104); for (tu = afs_users[i]; tu; tu = tu->next) { if (tu->uid == auid) { RmtUser = 0; - pu = (struct unixuser *)0; + pu = NULL; if (tu->exporter) { RmtUser = 1; pu = tu; @@ -469,15 +458,14 @@ struct unixuser *afs_GetUser(auid, acell, locktype) tu->refCount++; ReleaseWriteLock(&afs_xuser); return tu; - } else - if (tu->cell == acell || acell == -1) { - tu->refCount++; - ReleaseWriteLock(&afs_xuser); - return tu; - } + } else if (tu->cell == acell || acell == -1) { + tu->refCount++; + ReleaseWriteLock(&afs_xuser); + return tu; + } } } - tu = (struct unixuser *) afs_osi_Alloc(sizeof(struct unixuser)); + tu = (struct unixuser *)afs_osi_Alloc(sizeof(struct unixuser)); #ifndef AFS_NOSTATS afs_stats_cmfullperf.authent.PAGCreations++; #endif /* AFS_NOSTATS */ @@ -491,8 +479,8 @@ struct unixuser *afs_GetUser(auid, acell, locktype) * we simply rerecord relevant information from the original * structure */ - if (pu && pu->exporter) { - (void) EXP_HOLD(tu->exporter = pu->exporter); + if (pu && pu->exporter) { + (void)EXP_HOLD(tu->exporter = pu->exporter); } } tu->uid = auid; @@ -503,26 +491,23 @@ struct unixuser *afs_GetUser(auid, acell, locktype) ReleaseWriteLock(&afs_xuser); return tu; -} /*afs_GetUser*/ +} /*afs_GetUser */ -void afs_PutUser(au, locktype) - register struct unixuser *au; - afs_int32 locktype; +void +afs_PutUser(register struct unixuser *au, afs_int32 locktype) { AFS_STATCNT(afs_PutUser); --au->refCount; -} /*afs_PutUser*/ +} /*afs_PutUser */ /* * Set the primary flag on a unixuser structure, ensuring that exactly one * dude has the flag set at any time for a particular unix uid. */ -void afs_SetPrimary(au, aflag) - register struct unixuser *au; - register int aflag; - +void +afs_SetPrimary(register struct unixuser *au, register int aflag) { register struct unixuser *tu; register int i; @@ -530,13 +515,13 @@ void afs_SetPrimary(au, aflag) AFS_STATCNT(afs_SetPrimary); i = UHash(au->uid); - pu = (struct unixuser *) 0; - ObtainWriteLock(&afs_xuser,105); + pu = NULL; + ObtainWriteLock(&afs_xuser, 105); /* * See if anyone is this uid's primary cell yet; recording in pu the * corresponding user */ - for (tu=afs_users[i]; tu; tu=tu->next) { + for (tu = afs_users[i]; tu; tu = tu->next) { if (tu->uid == au->uid && (tu->states & UPrimary)) { pu = tu; } @@ -548,25 +533,23 @@ void afs_SetPrimary(au, aflag) * people see a primary identity until now. */ pu->states &= ~UPrimary; - pu = (struct unixuser *) 0; + pu = NULL; } if (aflag == 1) { /* setting au to be primary */ - if (pu) pu->states &= ~UPrimary; + if (pu) + pu->states &= ~UPrimary; au->states |= UPrimary; - } - else - if (aflag == 0) { - /* we don't know if we're supposed to be primary or not */ - if (!pu || au == pu) { - au->states |= UPrimary; - } - else - au->states &= ~UPrimary; + } else if (aflag == 0) { + /* we don't know if we're supposed to be primary or not */ + if (!pu || au == pu) { + au->states |= UPrimary; + } else + au->states &= ~UPrimary; } ReleaseWriteLock(&afs_xuser); -} /*afs_SetPrimary*/ +} /*afs_SetPrimary */ #if AFS_GCPAGS @@ -584,7 +567,7 @@ void afs_SetPrimary(au, aflag) * the per process loop in GCPAGs doesn't have to * check processes without pags against the afs_users table. */ -static afs_int32 afs_GCPAGs_UIDBaseTokenCount=0; +static afs_int32 afs_GCPAGs_UIDBaseTokenCount = 0; /* * These variables keep track of the number of times @@ -592,13 +575,14 @@ static afs_int32 afs_GCPAGs_UIDBaseTokenCount=0; * walking the process table, there is something wrong and we should not * prematurely expire any tokens. */ -static size_t afs_GCPAGs_perproc_count=0; -static size_t afs_GCPAGs_cred_count=0; +static size_t afs_GCPAGs_perproc_count = 0; +static size_t afs_GCPAGs_cred_count = 0; /* * LOCKS: afs_GCPAGs_perproc_func requires write lock on afs_xuser */ -void afs_GCPAGs_perproc_func(AFS_PROC *pproc) +void +afs_GCPAGs_perproc_func(AFS_PROC * pproc) { afs_int32 pag, hash, uid; const struct AFS_UCRED *pcred; @@ -606,7 +590,7 @@ void afs_GCPAGs_perproc_func(AFS_PROC *pproc) afs_GCPAGs_perproc_count++; pcred = afs_osi_proc2cred(pproc); - if(!pcred) + if (!pcred) return; afs_GCPAGs_cred_count++; @@ -620,22 +604,22 @@ void afs_GCPAGs_perproc_func(AFS_PROC *pproc) hash = UHash(uid); /* if this token is PAG based, or it's UID based and - UID-based tokens exist */ - if((pag != NOPAG) || (afs_GCPAGs_UIDBaseTokenCount)) { + * UID-based tokens exist */ + if ((pag != NOPAG) || (afs_GCPAGs_UIDBaseTokenCount)) { /* find the entries for this uid in all cells and clear the not * referenced flag. Can't use afs_FindUser, because it just returns - * the specific cell asked for, or the first one found. - */ + * the specific cell asked for, or the first one found. + */ struct unixuser *pu; - for(pu = afs_users[hash]; pu; pu = pu->next) { + for (pu = afs_users[hash]; pu; pu = pu->next) { if (pu->uid == uid) { - if(pu->states & TMP_UPAGNotReferenced) { + if (pu->states & TMP_UPAGNotReferenced) { /* clear the 'deleteme' flag for this entry */ pu->states &= ~TMP_UPAGNotReferenced; - if(pag == NOPAG) { + if (pag == NOPAG) { /* This is a uid based token that hadn't - previously been cleared, so decrement the - outstanding uid based token count */ + * previously been cleared, so decrement the + * outstanding uid based token count */ afs_GCPAGs_UIDBaseTokenCount--; } } @@ -657,7 +641,8 @@ void afs_GCPAGs_perproc_func(AFS_PROC *pproc) * an entry in the login cache, so this routine is not needed. */ -afs_int32 afs_GCPAGs(afs_int32 *ReleasedCount) +afs_int32 +afs_GCPAGs(afs_int32 * ReleasedCount) { struct unixuser *pu; int i; @@ -669,10 +654,10 @@ afs_int32 afs_GCPAGs(afs_int32 *ReleasedCount) *ReleasedCount = 0; /* first, loop through afs_users, setting the temporary 'deleteme' flag */ - ObtainWriteLock(&afs_xuser,419); - afs_GCPAGs_UIDBaseTokenCount=0; - for(i=0; i < NUSERS; i++) { - for(pu = afs_users[i]; pu; pu = pu->next) { + ObtainWriteLock(&afs_xuser, 419); + afs_GCPAGs_UIDBaseTokenCount = 0; + for (i = 0; i < NUSERS; i++) { + for (pu = afs_users[i]; pu; pu = pu->next) { pu->states |= TMP_UPAGNotReferenced; if (((pu->uid >> 24) & 0xff) != 'A') { /* this is a uid-based token, */ @@ -686,8 +671,8 @@ afs_int32 afs_GCPAGs(afs_int32 *ReleasedCount) * for each process, mark it's PAGs (if any) in use. * i.e. clear the temporary deleteme flag. */ - afs_GCPAGs_perproc_count=0; - afs_GCPAGs_cred_count=0; + afs_GCPAGs_perproc_count = 0; + afs_GCPAGs_cred_count = 0; afs_osi_TraverseProcTable(); @@ -707,24 +692,24 @@ afs_int32 afs_GCPAGs(afs_int32 *ReleasedCount) * (temp deleteme flag still set) will be marked for later deletion, * by setting their expire times to 0. */ - for(i=0; i < NUSERS; i++) { - for(pu = afs_users[i]; pu; pu = pu->next) { - if(pu->states & TMP_UPAGNotReferenced) { - + for (i = 0; i < NUSERS; i++) { + for (pu = afs_users[i]; pu; pu = pu->next) { + if (pu->states & TMP_UPAGNotReferenced) { + /* clear the temp flag */ pu->states &= ~TMP_UPAGNotReferenced; - + /* Is this entry on behalf of a 'remote' user ? * i.e. nfs translator, etc. */ - if(!pu->exporter && afs_gcpags == AFS_GCPAGS_OK) { + if (!pu->exporter && afs_gcpags == AFS_GCPAGS_OK) { /* set the expire times to 0, causes * afs_GCUserData to remove this entry */ pu->ct.EndTimestamp = 0; pu->tokenTime = 0; - - (*ReleasedCount)++; /* remember how many we marked (info only) */ + + (*ReleasedCount)++; /* remember how many we marked (info only) */ } } } @@ -735,4 +720,4 @@ afs_int32 afs_GCPAGs(afs_int32 *ReleasedCount) return 0; } -#endif /* AFS_GCPAGS */ +#endif /* AFS_GCPAGS */ diff --git a/src/afs/afs_util.c b/src/afs/afs_util.c index 80428e244..a8ee024c5 100644 --- a/src/afs/afs_util.c +++ b/src/afs/afs_util.c @@ -13,12 +13,13 @@ * Implements: */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_util.c,v 1.1.1.10 2003/07/30 17:08:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_util.c,v 1.17 2003/07/15 23:14:13 shadow Exp $"); -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ #if !defined(UKERNEL) #if !defined(AFS_LINUX20_ENV) @@ -27,15 +28,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_util.c,v 1.1.1.10 2003/07/30 17 #include #ifdef AFS_SGI62_ENV -#include "../h/hashing.h" +#include "h/hashing.h" #endif #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV) #include #endif /* ! AFS_HPUX110_ENV */ #endif /* !defined(UKERNEL) */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ #if defined(AFS_SUN56_ENV) #include @@ -50,14 +51,14 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_util.c,v 1.1.1.10 2003/07/30 17 #include #endif -extern struct volume *afs_volumes[NVOLS]; - -char *afs_cv2string(char *ttp, afs_uint32 aval) +#ifndef afs_cv2string +char * +afs_cv2string(char *ttp, afs_uint32 aval) { register char *tp = ttp; - register int i; + register int i; int any; - + AFS_STATCNT(afs_cv2string); any = 0; *(--tp) = 0; @@ -71,74 +72,113 @@ char *afs_cv2string(char *ttp, afs_uint32 aval) *(--tp) = '0'; return tp; -} /*afs_cv2string*/ - -char *afs_strchr(char *s, int c) -{ - char *p; - - for (p = s; *p; p++) - if (*p == c) - return p; - return NULL; -} +} /*afs_cv2string */ +#endif -int afs_strcasecmp(char *s1, char *s2) +#ifndef afs_strcasecmp +int +afs_strcasecmp(char *s1, char *s2) { while (*s1 && *s2) { char c1, c2; c1 = *s1++; c2 = *s2++; - if (c1 >= 'A' && c1 <= 'Z') c1 += 0x20; - if (c2 >= 'A' && c2 <= 'Z') c2 += 0x20; + if (c1 >= 'A' && c1 <= 'Z') + c1 += 0x20; + if (c2 >= 'A' && c2 <= 'Z') + c2 += 0x20; if (c1 != c2) - return c1-c2; + return c1 - c2; } return *s1 - *s2; } +#endif + +#ifndef afs_strcat +char * +afs_strcat(char *s1, char *s2) +{ + char *os1; + + os1 = s1; + while (*s1++); + --s1; + while ((*s1++ = *s2++)); + return (os1); +} +#endif + +#ifdef AFS_OBSD34_ENV +char * +afs_strcpy(char *s1, char *s2) +{ + char *os1; + + os1 = s1; + while ((*s1++ = *s2++) != '\0'); + return os1; +} +#endif -char *afs_strdup(char *s) +#ifndef afs_strchr +char * +afs_strchr(char *s, int c) +{ + char *p; + + for (p = s; *p; p++) + if (*p == c) + return p; + return NULL; +} +#endif + +char * +afs_strdup(char *s) { char *n; int cc; cc = strlen(s) + 1; - n = (char *) afs_osi_Alloc(cc); + n = (char *)afs_osi_Alloc(cc); if (n) memcpy(n, s, cc); return n; } -void print_internet_address(char *preamble, struct srvAddr *sa, - char *postamble, int flag) +void +print_internet_address(char *preamble, struct srvAddr *sa, char *postamble, + int flag) { register struct server *aserver = sa->server; char *ptr = "\n"; afs_uint32 address; - + AFS_STATCNT(print_internet_address); address = ntohl(sa->sa_ip); if (aserver->flags & SRVR_MULTIHOMED) { if (flag == 1) { /* server down mesg */ if (!(aserver->flags & SRVR_ISDOWN)) - ptr = " (multi-homed address; other same-host interfaces maybe up)\n"; + ptr = + " (multi-homed address; other same-host interfaces maybe up)\n"; else ptr = " (all multi-homed ip addresses down for the server)\n"; } else if (flag == 2) { /* server up mesg */ - ptr = " (multi-homed address; other same-host interfaces may still be down)\n"; + ptr = + " (multi-homed address; other same-host interfaces may still be down)\n"; } } - afs_warn("%s%d.%d.%d.%d in cell %s%s%s", - preamble, (address >> 24), (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff, - aserver->cell->cellName, postamble, ptr); - afs_warnuser("%s%d.%d.%d.%d in cell %s%s%s", - preamble, (address >> 24), (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff, - aserver->cell->cellName, postamble, ptr); + afs_warn("%s%d.%d.%d.%d in cell %s%s%s", preamble, (address >> 24), + (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff, + aserver->cell->cellName, postamble, ptr); + afs_warnuser("%s%d.%d.%d.%d in cell %s%s%s", preamble, (address >> 24), + (address >> 16) & 0xff, (address >> 8) & 0xff, + (address) & 0xff, aserver->cell->cellName, postamble, ptr); -} /*print_internet_address*/ +} /*print_internet_address */ @@ -146,55 +186,66 @@ void print_internet_address(char *preamble, struct srvAddr *sa, * this code badly needs to be cleaned up... too many ugly ifdefs. * XXX */ -extern afs_int32 afs_showflags; - -afs_warn(a,b,c,d,e,f,g,h,i,j) -char *a; -#if defined(AFS_USE_VOID_PTR) -void *b, *c, *d, *e, *f, *g, *h, *i, *j; +#if 0 +void +afs_warn(char *a, long b, long c, long d, long e, long f, long g, long h, + long i, long j) +#else +void +afs_warn(a, b, c, d, e, f, g, h, i, j) + char *a; +#if defined( AFS_USE_VOID_PTR) + void *b, *c, *d, *e, *f, *g, *h, *i, *j; #else -long b,c,d,e,f,g,h,i,j; + long b, c, d, e, f, g, h, i, j; +#endif #endif { AFS_STATCNT(afs_warn); - - if (afs_showflags & GAGCONSOLE) - { + + if (afs_showflags & GAGCONSOLE) { #if defined(AFS_AIX_ENV) struct file *fd; /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */ - if (fp_open("/dev/console",O_WRONLY|O_NOCTTY|O_NDELAY, - 0666,0,FP_SYS,&fd) == 0) { + if (fp_open + ("/dev/console", O_WRONLY | O_NOCTTY | O_NDELAY, 0666, 0, FP_SYS, + &fd) == 0) { char buf[1024]; ssize_t len; ssize_t count; - sprintf(buf, a,b,c,d,e,f,g,h,i,j); + sprintf(buf, a, b, c, d, e, f, g, h, i, j); len = strlen(buf); fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count); fp_close(fd); } #else - printf(a,b,c,d,e,f,g,h,i,j); + printf(a, b, c, d, e, f, g, h, i, j); #endif } } -afs_warnuser(a,b,c,d,e,f,g,h,i,j) -char *a; -long b,c,d,e,f,g,h,i,j; +#if 0 +void +afs_warnuser(char *a, long b, long c, long d, long e, long f, long g, long h, + long i, long j) +#else +void +afs_warnuser(a, b, c, d, e, f, g, h, i, j) + char *a; + long b, c, d, e, f, g, h, i, j; +#endif { AFS_STATCNT(afs_warnuser); - if (afs_showflags & GAGUSER) - { + if (afs_showflags & GAGUSER) { #ifdef AFS_GLOBAL_SUNLOCK int haveGlock = ISAFS_GLOCK(); if (haveGlock) AFS_GUNLOCK(); #endif /* AFS_GLOBAL_SUNLOCK */ - uprintf(a,b,c,d,e,f,g,h,i,j); + uprintf(a, b, c, d, e, f, g, h, i, j); #ifdef AFS_GLOBAL_SUNLOCK if (haveGlock) @@ -205,69 +256,66 @@ long b,c,d,e,f,g,h,i,j; /* run everywhere, checking locks */ -void afs_CheckLocks() - +void +afs_CheckLocks(void) { - extern afs_rwlock_t afs_xconn, afs_xvolume, afs_xuser, afs_xcell; - extern afs_rwlock_t afs_xserver; - extern struct server *afs_servers[NSERVERS]; - extern struct unixuser *afs_users[NUSERS]; - extern unsigned char *afs_indexFlags; register int i; afs_warn("Looking for locked data structures.\n"); - afs_warn("conn %x, volume %x, user %x, cell %x, server %x\n", - afs_xconn, afs_xvolume, afs_xuser, afs_xcell, afs_xserver); + afs_warn("conn %x, volume %x, user %x, cell %x, server %x\n", afs_xconn, + afs_xvolume, afs_xuser, afs_xcell, afs_xserver); { register struct vcache *tvc; AFS_STATCNT(afs_CheckLocks); - for(i=0;ihnext) { + for (i = 0; i < VCSIZE; i++) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { #ifdef AFS_OSF_ENV if (VREFCOUNT(tvc) > 1) -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ if (VREFCOUNT(tvc)) #endif afs_warn("Stat cache entry at %x is held\n", tvc); if (CheckLock(&tvc->lock)) - afs_warn("Stat entry at %x is locked\n", tvc); + afs_warn("Stat entry at %x is locked\n", tvc); } } } { register struct dcache *tdc; - for (i=0;irefCount) afs_warn("Disk entry %d at %x is held\n", i, tdc); } if (afs_indexFlags[i] & IFDataMod) - afs_warn("Disk entry %d at %x has IFDataMod flag set.\n", i, tdc); + afs_warn("Disk entry %d at %x has IFDataMod flag set.\n", i, + tdc); } } { - struct srvAddr *sa; - struct server *ts; - struct conn *tc; - for (i=0;inext) { + struct srvAddr *sa; + struct server *ts; + struct conn *tc; + for (i = 0; i < NSERVERS; i++) { + for (ts = afs_servers[i]; ts; ts = ts->next) { if (ts->flags & SRVR_ISDOWN) printf("Server entry %x is marked down\n", ts); - for (sa = ts->addr; sa; sa = sa->next_sa) { - for (tc = sa->conns; tc; tc=tc->next) { - if (tc->refCount) - afs_warn("conn at %x (server %x) is held\n", tc, sa->sa_ip); + for (sa = ts->addr; sa; sa = sa->next_sa) { + for (tc = sa->conns; tc; tc = tc->next) { + if (tc->refCount) + afs_warn("conn at %x (server %x) is held\n", tc, + sa->sa_ip); } } } } } { - struct volume *tv; - for (i=0;inext) { + struct volume *tv; + for (i = 0; i < NVOLS; i++) { + for (tv = afs_volumes[i]; tv; tv = tv->next) { if (CheckLock(&tv->lock)) afs_warn("volume at %x is locked\n", tv); if (tv->refCount) @@ -276,11 +324,12 @@ void afs_CheckLocks() } } { - struct unixuser *tu; + struct unixuser *tu; - for (i=0;inext) { - if (tu->refCount) printf("user at %x is held\n", tu); + for (i = 0; i < NUSERS; i++) { + for (tu = afs_users[i]; tu; tu = tu->next) { + if (tu->refCount) + printf("user at %x is held\n", tu); } } } @@ -288,7 +337,9 @@ void afs_CheckLocks() } -int afs_noop() { +int +afs_noop(void) +{ AFS_STATCNT(afs_noop); #ifdef AFS_OSF30_ENV return (EOPNOTSUPP); @@ -297,10 +348,12 @@ int afs_noop() { #endif } -int afs_badop() { +int +afs_badop(void) +{ AFS_STATCNT(afs_badop); osi_Panic("afs bad vnode op"); - return 0; /* make SGI C compiler happy */ + return 0; } /* @@ -314,33 +367,33 @@ int afs_badop() { afs_int32 afs_data_pointer_to_int32(const void *p) { - union { - afs_int32 i32[sizeof(void *)/sizeof(afs_int32)]; - const void *p; - } ip; + union { + afs_int32 i32[sizeof(void *) / sizeof(afs_int32)]; + const void *p; + } ip; - int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */ + int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */ - /* set i32_sub */ + /* set i32_sub */ - { - /* used to determine the byte order of the system */ - - union { - char c[sizeof(int)/sizeof(char)]; - int i; - } ci; + { + /* used to determine the byte order of the system */ - ci.i = 1; - if (ci.c[0] == 1) { - /* little-endian system */ - i32_sub = 0; - } else { - /* big-endian system */ - i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1; - } + union { + char c[sizeof(int) / sizeof(char)]; + int i; + } ci; + + ci.i = 1; + if (ci.c[0] == 1) { + /* little-endian system */ + i32_sub = 0; + } else { + /* big-endian system */ + i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1; } + } - ip.p = p; - return ip.i32[i32_sub]; + ip.p = p; + return ip.i32[i32_sub]; } diff --git a/src/afs/afs_util.h b/src/afs/afs_util.h index d67fc5eb0..d5188df01 100644 --- a/src/afs/afs_util.h +++ b/src/afs/afs_util.h @@ -14,6 +14,6 @@ #define _AFS_UTIL_H_ /* Handy max length of a numeric string. */ -#define CVBS 12 /* max afs_int32 is 2^32 ~ 4*10^9, +1 for NULL, +luck */ +#define CVBS 12 /* max afs_int32 is 2^32 ~ 4*10^9, +1 for NULL, +luck */ #endif /* _AFS_UTIL_H_ */ diff --git a/src/afs/afs_vcache.c b/src/afs/afs_vcache.c index 05608e79a..5fde338b3 100644 --- a/src/afs/afs_vcache.c +++ b/src/afs/afs_vcache.c @@ -1,7 +1,7 @@ /* * Copyright 2000, International Business Machines Corporation and others. * All Rights Reserved. - * + * * This software has been released under the terms of the IBM Public * License. For details, see the LICENSE file in the top-level source * directory or online at http://www.openafs.org/dl/license10.html @@ -36,70 +36,73 @@ * */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_vcache.c,v 1.1.1.17 2003/07/30 17:08:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_vcache.c,v 1.62 2004/05/08 04:20:39 shadow Exp $"); -#include "../afs/sysincludes.h" /*Standard vendor system headers*/ -#include "../afs/afsincludes.h" /*AFS-based standard headers*/ -#include "../afs/afs_stats.h" -#include "../afs/afs_cbqueue.h" -#include "../afs/afs_osidnlc.h" +#include "afs/sysincludes.h" /*Standard vendor system headers */ +#include "afsincludes.h" /*AFS-based standard headers */ +#include "afs/afs_stats.h" +#include "afs/afs_cbqueue.h" +#include "afs/afs_osidnlc.h" #ifdef AFS_OSF_ENV -afs_int32 afs_maxvcount = 0; /* max number of vcache entries */ -afs_int32 afs_vcount = 0; /* number of vcache in use now */ -#if defined(AFS_OSF30_ENV) -extern int max_vnodes; /* number of total system vnodes */ -#else -extern int nvnode; /* number of total system vnodes */ -#endif -#ifndef AFS_OSF30_ENV -extern int numvnodes; /* number vnodes in use now */ -#endif +afs_int32 afs_maxvcount = 0; /* max number of vcache entries */ +afs_int32 afs_vcount = 0; /* number of vcache in use now */ #endif /* AFS_OSF_ENV */ + #ifdef AFS_SGI_ENV int afsvnumbers = 0; #endif -/* Imported variables */ -extern struct server *afs_servers[NSERVERS]; -extern afs_rwlock_t afs_xserver; -extern afs_rwlock_t afs_xcbhash; -extern struct vcache *afs_globalVp; -#ifdef AFS_OSF_ENV -extern struct mount *afs_globalVFS; -extern struct vnodeops Afs_vnodeops; -#elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -extern struct mount *afs_globalVFS; -#else -extern struct vfs *afs_globalVFS; -#endif /* AFS_OSF_ENV */ -#if defined(AFS_DUX40_ENV) -extern struct vfs_ubcops afs_ubcops; -#endif -#ifdef AFS_SGI62_ENV -extern struct vnodeops Afs_vnodeops; -#endif #ifdef AFS_SGI64_ENV char *makesname(); #endif /* AFS_SGI64_ENV */ - + /* Exported variables */ -afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries*/ -afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks*/ -struct vcache *freeVCList; /*Free list for stat cache entries*/ -struct vcache *Initial_freeVCList; /*Initial list for above*/ -struct afs_q VLRU; /*vcache LRU*/ +afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries */ +afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks */ +struct vcache *freeVCList; /*Free list for stat cache entries */ +struct vcache *Initial_freeVCList; /*Initial list for above */ +struct afs_q VLRU; /*vcache LRU */ afs_int32 vcachegen = 0; unsigned int afs_paniconwarn = 0; struct vcache *afs_vhashT[VCSIZE]; +static struct afs_cbr *afs_cbrHashT[CBRSIZE]; afs_int32 afs_bulkStatsLost; int afs_norefpanic = 0; /* Forward declarations */ static afs_int32 afs_QueueVCB(struct vcache *avc); +/* + * afs_HashCBRFid + * + * Generate an index into the hash table for a given Fid. + */ +static int +afs_HashCBRFid(struct AFSFid *fid) { + return (fid->Volume + fid->Vnode + fid->Unique) % CBRSIZE; +} + +/* + * afs_InsertHashCBR + * + * Insert a CBR entry into the hash table. + * Must be called with afs_xvcb held. + */ +static void +afs_InsertHashCBR(struct afs_cbr *cbr) { + int slot = afs_HashCBRFid(&cbr->fid); + + cbr->hash_next = afs_cbrHashT[slot]; + if (afs_cbrHashT[slot]) + afs_cbrHashT[slot]->hash_pprev = &cbr->hash_next; + + cbr->hash_pprev = &afs_cbrHashT[slot]; + afs_cbrHashT[slot] = cbr; +} /* * afs_FlushVCache @@ -115,16 +118,17 @@ static afs_int32 afs_QueueVCB(struct vcache *avc); * afs_xvcache lock must be held for writing upon entry to * prevent people from changing the vrefCount field, and to * protect the lruq and hnext fields. - * LOCK: afs_FlushVCache afs_xvcache W + * LOCK: afs_FlushVCache afs_xvcache W * REFCNT: vcache ref count must be zero on entry except for osf1 * RACE: lock is dropped and reobtained, permitting race in caller */ -int afs_FlushVCache(struct vcache *avc, int *slept) -{ /*afs_FlushVCache*/ +int +afs_FlushVCache(struct vcache *avc, int *slept) +{ /*afs_FlushVCache */ register afs_int32 i, code; - register struct vcache **uvc, *wvc, *tvc; + register struct vcache **uvc, *wvc; *slept = 0; AFS_STATCNT(afs_FlushVCache); @@ -144,13 +148,13 @@ int afs_FlushVCache(struct vcache *avc, int *slept) code = EBUSY; goto bad; } - if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */ - refpanic ("LRU vs. Free inconsistency"); + if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */ + refpanic("LRU vs. Free inconsistency"); } avc->states |= CVFlushed; /* pull the entry out of the lruq and put it on the free list */ QRemove(&avc->vlruq); - avc->vlruq.prev = avc->vlruq.next = (struct afs_q *) 0; + avc->vlruq.prev = avc->vlruq.next = (struct afs_q *)0; /* keep track of # of files that we bulk stat'd, but never used * before they got recycled. @@ -161,23 +165,33 @@ int afs_FlushVCache(struct vcache *avc, int *slept) /* remove entry from the hash chain */ i = VCHash(&avc->fid); uvc = &afs_vhashT[i]; - for(wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) { + for (wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) { if (avc == wvc) { *uvc = avc->hnext; - avc->hnext = (struct vcache *) NULL; + avc->hnext = (struct vcache *)NULL; break; } } - if (!wvc) osi_Panic("flushvcache"); /* not in correct hash bucket */ - if (avc->mvid) osi_FreeSmallSpace(avc->mvid); - avc->mvid = (struct VenusFid*)0; + if (!wvc) + osi_Panic("flushvcache"); /* not in correct hash bucket */ + if (avc->mvid) + osi_FreeSmallSpace(avc->mvid); + avc->mvid = (struct VenusFid *)0; if (avc->linkData) { - afs_osi_Free(avc->linkData, strlen(avc->linkData)+1); - avc->linkData = NULL; + afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1); + avc->linkData = NULL; + } +#if defined(AFS_XBSD_ENV) + /* OK, there are no internal vrefCounts, so there shouldn't + * be any more refs here. */ + if (avc->v) { + avc->v->v_data = NULL; /* remove from vnode */ + avc->v = NULL; /* also drop the ptr to vnode */ } +#endif afs_FreeAllAxs(&(avc->Access)); - /* we can't really give back callbacks on RO files, since the + /* we can't really give back callbacks on RO files, since the * server only tracks them on a per-volume basis, and we don't * know whether we still have some other files from the same * volume. */ @@ -185,58 +199,60 @@ int afs_FlushVCache(struct vcache *avc, int *slept) afs_QueueVCB(avc); } ObtainWriteLock(&afs_xcbhash, 460); - afs_DequeueCallback(avc); /* remove it from queued callbacks list */ + afs_DequeueCallback(avc); /* remove it from queued callbacks list */ avc->states &= ~(CStatd | CUnique); ReleaseWriteLock(&afs_xcbhash); afs_symhint_inval(avc); - if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (avc); /* if it (could be) a directory */ - else - osi_dnlc_purgevp (avc); + if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(avc); /* if it (could be) a directory */ + else + osi_dnlc_purgevp(avc); /* * Next, keep track of which vnodes we've deleted for create's * optimistic synchronization algorithm */ afs_allZaps++; - if (avc->fid.Fid.Vnode & 1) afs_oddZaps++; - else afs_evenZaps++; + if (avc->fid.Fid.Vnode & 1) + afs_oddZaps++; + else + afs_evenZaps++; #if !defined(AFS_OSF_ENV) /* put the entry in the free list */ avc->nextfree = freeVCList; freeVCList = avc; if (avc->vlruq.prev || avc->vlruq.next) { - refpanic ("LRU vs. Free inconsistency"); + refpanic("LRU vs. Free inconsistency"); } -#else +#else /* This should put it back on the vnode free list since usecount is 1 */ afs_vcount--; vSetType(avc, VREG); if (VREFCOUNT(avc) > 0) { - VN_UNLOCK(AFSTOV(avc)); - AFS_RELE(AFSTOV(avc)); + VN_UNLOCK(AFSTOV(avc)); + AFS_RELE(AFSTOV(avc)); } else { - if (afs_norefpanic) { - printf ("flush vc refcnt < 1"); - afs_norefpanic++; - (void) vgone(avc, VX_NOSLEEP, (struct vnodeops *) 0); - AFS_GLOCK(); - VN_UNLOCK(AFSTOV(avc)); - } - else osi_Panic ("flush vc refcnt < 1"); - } -#endif /* AFS_OSF_ENV */ + if (afs_norefpanic) { + printf("flush vc refcnt < 1"); + afs_norefpanic++; + (void)vgone(avc, VX_NOSLEEP, NULL); + AFS_GLOCK(); + VN_UNLOCK(AFSTOV(avc)); + } else + osi_Panic("flush vc refcnt < 1"); + } +#endif /* AFS_OSF_ENV */ avc->states |= CVFlushed; return 0; -bad: + bad: #ifdef AFS_OSF_ENV VN_UNLOCK(AFSTOV(avc)); #endif return code; -} /*afs_FlushVCache*/ +} /*afs_FlushVCache */ #ifndef AFS_SGI_ENV /* @@ -244,21 +260,20 @@ bad: * * The core of the inactive vnode op for all but IRIX. */ -void afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred) +void +afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred) { - extern afs_rwlock_t afs_xdcache, afs_xvcache; - AFS_STATCNT(afs_inactive); if (avc->states & CDirty) { - /* we can't keep trying to push back dirty data forever. Give up. */ - afs_InvalidateAllSegments(avc, 1/*set lock*/); /* turns off dirty bit */ + /* we can't keep trying to push back dirty data forever. Give up. */ + afs_InvalidateAllSegments(avc); /* turns off dirty bit */ } - avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */ - avc->states &= ~CDirty; /* Turn it off */ + avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */ + avc->states &= ~CDirty; /* Turn it off */ if (avc->states & CUnlinked) { - if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) { + if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) { avc->states |= CUnlinkedDel; - return; + return; } afs_remunlink(avc, 1); /* ignore any return code */ } @@ -276,7 +291,9 @@ void afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred) * held, so we don't have to worry about blocking in osi_Alloc. */ static struct afs_cbr *afs_cbrSpace = 0; -struct afs_cbr *afs_AllocCBR() { +struct afs_cbr * +afs_AllocCBR(void) +{ register struct afs_cbr *tsp; int i; @@ -285,14 +302,15 @@ struct afs_cbr *afs_AllocCBR() { /* don't allocate more than 2 * AFS_NCBRS for now */ afs_FlushVCBs(0); afs_stats_cmperf.CallBackFlushes++; - } - else { + } else { /* try allocating */ - tsp = (struct afs_cbr *) afs_osi_Alloc(AFS_NCBRS * sizeof(struct afs_cbr)); - for(i=0; i < AFS_NCBRS-1; i++) { - tsp[i].next = &tsp[i+1]; + tsp = + (struct afs_cbr *)afs_osi_Alloc(AFS_NCBRS * + sizeof(struct afs_cbr)); + for (i = 0; i < AFS_NCBRS - 1; i++) { + tsp[i].next = &tsp[i + 1]; } - tsp[AFS_NCBRS-1].next = 0; + tsp[AFS_NCBRS - 1].next = 0; afs_cbrSpace = tsp; afs_stats_cmperf.CallBackAlloced++; } @@ -305,15 +323,24 @@ struct afs_cbr *afs_AllocCBR() { /* * afs_FreeCBR * - * Description: free a callback return structure. + * Description: free a callback return structure, removing it from all lists. * * Parameters: * asp -- the address of the structure to free. * * Environment: the xvcb lock is held over these calls. */ -afs_FreeCBR(asp) -register struct afs_cbr *asp; { +int +afs_FreeCBR(register struct afs_cbr *asp) +{ + *(asp->pprev) = asp->next; + if (asp->next) + asp->next->pprev = asp->pprev; + + *(asp->hash_pprev) = asp->hash_next; + if (asp->hash_next) + asp->hash_next->hash_pprev = asp->hash_pprev; + asp->next = afs_cbrSpace; afs_cbrSpace = asp; return 0; @@ -329,9 +356,10 @@ register struct afs_cbr *asp; { * Environment: holds xvcb lock over RPC to guard against race conditions * when a new callback is granted for the same file later on. */ -afs_int32 afs_FlushVCBs (afs_int32 lockit) +afs_int32 +afs_FlushVCBs(afs_int32 lockit) { - struct AFSFid tfids[AFS_MAXCBRSCALL]; + struct AFSFid *tfids; struct AFSCallBack callBacks[1]; struct AFSCBFids fidArray; struct AFSCBs cbArray; @@ -343,89 +371,99 @@ afs_int32 afs_FlushVCBs (afs_int32 lockit) struct vrequest treq; struct conn *tc; int safety1, safety2, safety3; - extern int afs_totalServers; - XSTATS_DECLS - - if (code = afs_InitReq(&treq, &afs_osi_cred)) return code; + XSTATS_DECLS if ((code = afs_InitReq(&treq, afs_osi_credp))) + return code; treq.flags |= O_NONBLOCK; + tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL); - if (lockit) MObtainWriteLock(&afs_xvcb,273); + if (lockit) + MObtainWriteLock(&afs_xvcb, 273); ObtainReadLock(&afs_xserver); - for(i=0; inext, safety1++) { + for (i = 0; i < NSERVERS; i++) { + for (safety1 = 0, tsp = afs_servers[i]; + tsp && safety1 < afs_totalServers + 10; + tsp = tsp->next, safety1++) { /* don't have any */ - if (tsp->cbrs == (struct afs_cbr *) 0) continue; + if (tsp->cbrs == (struct afs_cbr *)0) + continue; /* otherwise, grab a block of AFS_MAXCBRSCALL from the list * and make an RPC, over and over again. */ - tcount = 0; /* number found so far */ - for (safety2 = 0; safety2 < afs_cacheStats ; safety2++) { + tcount = 0; /* number found so far */ + for (safety2 = 0; safety2 < afs_cacheStats; safety2++) { if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) { /* if buffer is full, or we've queued all we're going * to from this server, we should flush out the * callbacks. */ fidArray.AFSCBFids_len = tcount; - fidArray.AFSCBFids_val = (struct AFSFid *) tfids; + fidArray.AFSCBFids_val = (struct AFSFid *)tfids; cbArray.AFSCBs_len = 1; cbArray.AFSCBs_val = callBacks; + memset(&callBacks[0], 0, sizeof(callBacks[0])); callBacks[0].CallBackType = CB_EXCLUSIVE; - for (safety3 = 0; safety3 < MAXHOSTS*2; safety3++) { + for (safety3 = 0; safety3 < MAXHOSTS * 2; safety3++) { tc = afs_ConnByHost(tsp, tsp->cell->fsport, tsp->cell->cellNum, &treq, 0, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_GiveUpCallBacks(tc->id, &fidArray, - &cbArray); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - if (!afs_Analyze(tc, code, 0, &treq, - AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, - SHARED_LOCK, tsp->cell)) { - break; + XSTATS_START_TIME + (AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS); + RX_AFS_GUNLOCK(); + code = + RXAFS_GiveUpCallBacks(tc->id, &fidArray, + &cbArray); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + if (!afs_Analyze + (tc, code, 0, &treq, + AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, + tsp->cell)) { + break; } } /* ignore return code, since callbacks may have - * been returned anyway, we shouldn't leave them - * around to be returned again. - * - * Next, see if we are done with this server, and if so, - * break to deal with the next one. - */ - if (!tsp->cbrs) break; + * been returned anyway, we shouldn't leave them + * around to be returned again. + * + * Next, see if we are done with this server, and if so, + * break to deal with the next one. + */ + if (!tsp->cbrs) + break; tcount = 0; - } /* if to flush full buffer */ + } + /* if to flush full buffer */ /* if we make it here, we have an entry at the head of cbrs, * which we should copy to the file ID array and then free. */ tcbrp = tsp->cbrs; tfids[tcount++] = tcbrp->fid; - tsp->cbrs = tcbrp->next; + + /* Freeing the CBR will unlink it from the server's CBR list */ afs_FreeCBR(tcbrp); - } /* while loop for this one server */ + } /* while loop for this one server */ if (safety2 > afs_cacheStats) { - afs_warn("possible internal error afs_flushVCBs (%d)\n", safety2); + afs_warn("possible internal error afs_flushVCBs (%d)\n", + safety2); } - } /* for loop for this hash chain */ - } /* loop through all hash chains */ - if (safety1 > afs_totalServers+2) { - afs_warn("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n", safety1, afs_totalServers+2); - if (afs_paniconwarn) - osi_Panic("afs_flushVCBS safety1"); + } /* for loop for this hash chain */ + } /* loop through all hash chains */ + if (safety1 > afs_totalServers + 2) { + afs_warn + ("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n", + safety1, afs_totalServers + 2); + if (afs_paniconwarn) + osi_Panic("afs_flushVCBS safety1"); } ReleaseReadLock(&afs_xserver); - if (lockit) MReleaseWriteLock(&afs_xvcb); + if (lockit) + MReleaseWriteLock(&afs_xvcb); + afs_osi_Free(tfids, sizeof(struct AFSFid) * AFS_MAXCBRSCALL); return 0; } @@ -443,10 +481,11 @@ afs_int32 afs_FlushVCBs (afs_int32 lockit) * Called when the xvcache lock is already held. */ -static afs_int32 afs_QueueVCB(struct vcache *avc) +static afs_int32 +afs_QueueVCB(struct vcache *avc) { - register struct server *tsp; - register struct afs_cbr *tcbp; + struct server *tsp; + struct afs_cbr *tcbp; AFS_STATCNT(afs_QueueVCB); /* The callback is really just a struct server ptr. */ @@ -455,89 +494,139 @@ static afs_int32 afs_QueueVCB(struct vcache *avc) /* we now have a pointer to the server, so we just allocate * a queue entry and queue it. */ - MObtainWriteLock(&afs_xvcb,274); + MObtainWriteLock(&afs_xvcb, 274); tcbp = afs_AllocCBR(); tcbp->fid = avc->fid.Fid; + tcbp->next = tsp->cbrs; + if (tsp->cbrs) + tsp->cbrs->pprev = &tcbp->next; + tsp->cbrs = tcbp; + tcbp->pprev = &tsp->cbrs; + + afs_InsertHashCBR(tcbp); /* now release locks and return */ MReleaseWriteLock(&afs_xvcb); return 0; } -#ifdef AFS_LINUX22_ENV -static void __shrink_dcache_parent(struct dentry * parent) +/* + * afs_RemoveVCB + * + * Description: + * Remove a queued callback for a given Fid. + * + * Parameters: + * afid: The fid we want cleansed of queued callbacks. + * + * Environment: + * Locks xvcb and xserver locks. + * Typically called with xdcache, xvcache and/or individual vcache + * entries locked. + */ + +void +afs_RemoveVCB(struct VenusFid *afid) { - struct dentry *this_parent = parent; - struct list_head *next; - int found = 0; - LIST_HEAD(afs_dentry_unused); - -repeat: - next = this_parent->d_subdirs.next; -resume: - while (next != &this_parent->d_subdirs) { - struct list_head *tmp = next; - struct dentry *dentry = list_entry(tmp, struct dentry, d_child); - next = tmp->next; - if (!DCOUNT(dentry)) { - list_del(&dentry->d_lru); - list_add(&dentry->d_lru, afs_dentry_unused.prev); - found++; - } - /* - * Descend a level if the d_subdirs list is non-empty. - */ - if (!list_empty(&dentry->d_subdirs)) { - this_parent = dentry; - goto repeat; - } + int slot; + struct afs_cbr *cbr, *ncbr; + + AFS_STATCNT(afs_RemoveVCB); + MObtainWriteLock(&afs_xvcb, 275); + + slot = afs_HashCBRFid(&afid->Fid); + ncbr = afs_cbrHashT[slot]; + + while (ncbr) { + cbr = ncbr; + ncbr = cbr->hash_next; + + if (afid->Fid.Volume == cbr->fid.Volume && + afid->Fid.Vnode == cbr->fid.Vnode && + afid->Fid.Unique == cbr->fid.Unique) { + afs_FreeCBR(cbr); + } + } + + MReleaseWriteLock(&afs_xvcb); +} + +#if defined(AFS_LINUX22_ENV) && !defined(AFS_LINUX26_ENV) + +static void +__shrink_dcache_parent(struct dentry *parent) +{ + struct dentry *this_parent = parent; + struct list_head *next; + int found = 0; + LIST_HEAD(afs_dentry_unused); + + repeat: + next = this_parent->d_subdirs.next; + resume: + while (next != &this_parent->d_subdirs) { + struct list_head *tmp = next; + struct dentry *dentry = list_entry(tmp, struct dentry, d_child); + next = tmp->next; + if (!DCOUNT(dentry)) { + list_del(&dentry->d_lru); + list_add(&dentry->d_lru, afs_dentry_unused.prev); + found++; } /* - * All done at this level ... ascend and resume the search. + * Descend a level if the d_subdirs list is non-empty. */ - if (this_parent != parent) { - next = this_parent->d_child.next; - this_parent = this_parent->d_parent; - goto resume; + if (!list_empty(&dentry->d_subdirs)) { + this_parent = dentry; + goto repeat; } + } + /* + * All done at this level ... ascend and resume the search. + */ + if (this_parent != parent) { + next = this_parent->d_child.next; + this_parent = this_parent->d_parent; + goto resume; + } - for (;;) { - struct dentry *dentry; - struct list_head *tmp; + for (;;) { + struct dentry *dentry; + struct list_head *tmp; - tmp = afs_dentry_unused.prev; + tmp = afs_dentry_unused.prev; - if (tmp == &afs_dentry_unused) - break; + if (tmp == &afs_dentry_unused) + break; #ifdef AFS_LINUX24_ENV - list_del_init(tmp); + list_del_init(tmp); #else - list_del(tmp); - INIT_LIST_HEAD(tmp); + list_del(tmp); + INIT_LIST_HEAD(tmp); #endif /* AFS_LINUX24_ENV */ - dentry = list_entry(tmp, struct dentry, d_lru); + dentry = list_entry(tmp, struct dentry, d_lru); #ifdef AFS_LINUX24_ENV - /* Unused dentry with a count? */ - if (DCOUNT(dentry)) - BUG(); + /* Unused dentry with a count? */ + if (DCOUNT(dentry)) + BUG(); #endif - DGET(dentry); + DGET(dentry); #ifdef AFS_LINUX24_ENV - list_del_init(&dentry->d_hash); /* d_drop */ + list_del_init(&dentry->d_hash); /* d_drop */ #else - list_del(&dentry->d_hash); - INIT_LIST_HEAD(&dentry->d_hash); + list_del(&dentry->d_hash); + INIT_LIST_HEAD(&dentry->d_hash); #endif /* AFS_LINUX24_ENV */ - DUNLOCK(); - dput(dentry); - DLOCK(); - if (!--found) - break; - } + DUNLOCK(); + dput(dentry); + DLOCK(); + if (!--found) + break; + } } /* afs_TryFlushDcacheChildren -- Shakes loose vcache references held by @@ -549,7 +638,8 @@ resume: * * Tree traversal algorithm from fs/dcache.c: select_parent() */ -static void afs_TryFlushDcacheChildren(struct vcache *tvc) +static void +afs_TryFlushDcacheChildren(struct vcache *tvc) { struct inode *ip = AFSTOI(tvc); struct dentry *this_parent; @@ -557,9 +647,9 @@ static void afs_TryFlushDcacheChildren(struct vcache *tvc) struct list_head *cur; struct list_head *head = &ip->i_dentry; struct dentry *dentry; - + AFS_GUNLOCK(); -restart: + restart: #ifndef old_vcache_scheme DLOCK(); cur = head; @@ -567,39 +657,39 @@ restart: dentry = list_entry(cur, struct dentry, d_alias); afs_Trace3(afs_iclSetp, CM_TRACE_TRYFLUSHDCACHECHILDREN, - ICL_TYPE_POINTER, ip, - ICL_TYPE_STRING, dentry->d_parent->d_name.name, - ICL_TYPE_STRING, dentry->d_name.name); + ICL_TYPE_POINTER, ip, ICL_TYPE_STRING, + dentry->d_parent->d_name.name, ICL_TYPE_STRING, + dentry->d_name.name); - if (!list_empty(&dentry->d_hash) && !list_empty(&dentry->d_subdirs)) - __shrink_dcache_parent(dentry); + if (!list_empty(&dentry->d_hash) && !list_empty(&dentry->d_subdirs)) + __shrink_dcache_parent(dentry); - if (!DCOUNT(dentry)) { - DGET(dentry); -#ifdef AFS_LINUX24_ENV - list_del_init(&dentry->d_hash); /* d_drop */ + if (!DCOUNT(dentry)) { + DGET(dentry); +#ifdef AFS_LINUX24_ENV + list_del_init(&dentry->d_hash); /* d_drop */ #else list_del(&dentry->d_hash); INIT_LIST_HEAD(&dentry->d_hash); #endif /* AFS_LINUX24_ENV */ - DUNLOCK(); - dput(dentry); - goto restart; - } + DUNLOCK(); + dput(dentry); + goto restart; + } } DUNLOCK(); AFS_GLOCK(); #else -restart: + restart: DLOCK(); cur = head; while ((cur = cur->next) != head) { - dentry = list_entry(cur, struct dentry, d_alias); + dentry = list_entry(cur, struct dentry, d_alias); - afs_Trace3(afs_iclSetp, CM_TRACE_TRYFLUSHDCACHECHILDREN, - ICL_TYPE_POINTER, ip, - ICL_TYPE_STRING, dentry->d_parent->d_name.name, - ICL_TYPE_STRING, dentry->d_name.name); + afs_Trace3(afs_iclSetp, CM_TRACE_TRYFLUSHDCACHECHILDREN, + ICL_TYPE_POINTER, ip, ICL_TYPE_STRING, + dentry->d_parent->d_name.name, ICL_TYPE_STRING, + dentry->d_name.name); if (!DCOUNT(dentry)) { AFS_GUNLOCK(); @@ -614,63 +704,7 @@ restart: DUNLOCK(); #endif } -#endif /* AFS_LINUX22_ENV */ - -/* - * afs_RemoveVCB - * - * Description: - * Remove a queued callback by looking through all the servers - * to see if any have this callback queued. - * - * Parameters: - * afid: The fid we want cleansed of queued callbacks. - * - * Environment: - * Locks xvcb and xserver locks. - * Typically called with xdcache, xvcache and/or individual vcache - * entries locked. - */ - -afs_RemoveVCB(struct VenusFid *afid) -{ /*afs_RemoveVCB*/ - - register int i, j; - register struct server *tsp; - register struct afs_cbr *tcbrp; - struct afs_cbr **lcbrpp; - - AFS_STATCNT(afs_RemoveVCB); - MObtainWriteLock(&afs_xvcb,275); - ObtainReadLock(&afs_xserver); - for(i=0;inext) { - /* if cell is known, and is wrong, then skip this server */ - if (tsp->cell && tsp->cell->cellNum != afid->Cell) continue; - - /* - * Otherwise, iterate through file IDs we're sending to the - * server. - */ - lcbrpp = &tsp->cbrs; /* first queued return callback */ - for(tcbrp = *lcbrpp; tcbrp; lcbrpp = &tcbrp->next, tcbrp = *lcbrpp) { - if (afid->Fid.Volume == tcbrp->fid.Volume && - afid->Fid.Unique == tcbrp->fid.Unique && - afid->Fid.Vnode == tcbrp->fid.Vnode) { - *lcbrpp = tcbrp->next; /* unthread from list */ - afs_FreeCBR(tcbrp); - goto done; - } - } - } - } - done: - ReleaseReadLock(&afs_xserver); - MReleaseWriteLock(&afs_xvcb); - return 0; - -} /*afs_RemoveVCB*/ - +#endif /* AFS_LINUX22_ENV && !AFS_LINUX26_ENV */ /* * afs_NewVCache @@ -686,9 +720,9 @@ afs_RemoveVCB(struct VenusFid *afid) * afid : The file id of the file whose cache entry is being * created. */ -/* LOCK: afs_NewVCache afs_xvcache W */ -struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, - afs_int32 lockit, afs_int32 locktype) +/* LOCK: afs_NewVCache afs_xvcache W */ +struct vcache * +afs_NewVCache(struct VenusFid *afid, struct server *serverp) { struct vcache *tvc; afs_int32 i; @@ -697,131 +731,151 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, struct gnode *gnodepnt; #endif #ifdef AFS_MACH_ENV - struct vm_info * vm_info_ptr; + struct vm_info *vm_info_ptr; #endif /* AFS_MACH_ENV */ #ifdef AFS_OSF_ENV struct vcache *nvc; -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ struct afs_q *tq, *uq; int code, fv_slept; AFS_STATCNT(afs_NewVCache); #ifdef AFS_OSF_ENV #ifdef AFS_OSF30_ENV - if (afs_vcount >= afs_maxvcount) + if (afs_vcount >= afs_maxvcount) { #else /* * If we are using > 33 % of the total system vnodes for AFS vcache * entries or we are using the maximum number of vcache entries, * then free some. (if our usage is > 33% we should free some, if - * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode, + * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode, * we _must_ free some -- no choice). */ - if ( (( 3 * afs_vcount ) > nvnode) || ( afs_vcount >= afs_maxvcount )) + if (((3 * afs_vcount) > nvnode) || (afs_vcount >= afs_maxvcount)) { #endif - { - struct afs_q *tq, *uq; - int i; char *panicstr; + struct afs_q *tq, *uq; + int i; + char *panicstr; - i = 0; - for(tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) { + i = 0; + for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) { tvc = QTOV(tq); uq = QPrev(tq); - if (tvc->states & CVFlushed) - refpanic ("CVFlushed on VLRU"); + if (tvc->states & CVFlushed) + refpanic("CVFlushed on VLRU"); else if (i++ > afs_maxvcount) - refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)"); + refpanic("Exceeded pool of AFS vnodes(VLRU cycle?)"); else if (QNext(uq) != tq) - refpanic ("VLRU inconsistent"); - else if (VREFCOUNT(tvc) < 1) - refpanic ("refcnt 0 on VLRU"); + refpanic("VLRU inconsistent"); + else if (VREFCOUNT(tvc) < 1) + refpanic("refcnt 0 on VLRU"); - if ( VREFCOUNT(tvc) == 1 && tvc->opens == 0 + if (VREFCOUNT(tvc) == 1 && tvc->opens == 0 && (tvc->states & CUnlinkedDel) == 0) { code = afs_FlushVCache(tvc, &fv_slept); if (code == 0) { - anumber--; + anumber--; } if (fv_slept) { - uq = VLRU.prev; - i = 0; - continue; /* start over - may have raced. */ + uq = VLRU.prev; + i = 0; + continue; /* start over - may have raced. */ } } - if (tq == uq) break; - } - if (anumber == VCACHE_FREE) { - printf("NewVCache: warning none freed, using %d of %d\n", + if (tq == uq) + break; + } + if (anumber == VCACHE_FREE) { + printf("NewVCache: warning none freed, using %d of %d\n", afs_vcount, afs_maxvcount); if (afs_vcount >= afs_maxvcount) { osi_Panic("NewVCache - none freed"); - /* XXX instead of panicing, should do afs_maxvcount++ - and magic up another one */ + /* XXX instead of panicing, should do afs_maxvcount++ + * and magic up another one */ } - } - } + } + } AFS_GUNLOCK(); if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) { - /* What should we do ???? */ - osi_Panic("afs_NewVCache: no more vnodes"); + /* What should we do ???? */ + osi_Panic("afs_NewVCache: no more vnodes"); } AFS_GLOCK(); tvc = nvc; - tvc->nextfree = (struct vcache *)0; + tvc->nextfree = NULL; afs_vcount++; -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ /* pull out a free cache entry */ if (!freeVCList) { i = 0; - for(tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) { - tvc = QTOV(tq); - uq = QPrev(tq); + for (tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) { + tvc = QTOV(tq); + uq = QPrev(tq); - if (tvc->states & CVFlushed) + if (tvc->states & CVFlushed) { refpanic("CVFlushed on VLRU"); - else if (i++ > 2*afs_cacheStats) /* even allowing for a few xallocs...*/ + } else if (i++ > 2 * afs_cacheStats) { /* even allowing for a few xallocs... */ refpanic("Increase -stat parameter of afsd(VLRU cycle?)"); - else if (QNext(uq) != tq) + } else if (QNext(uq) != tq) { refpanic("VLRU inconsistent"); - + } #ifdef AFS_DARWIN_ENV - if (tvc->opens == 0 && ((tvc->states & CUnlinkedDel) == 0) && - VREFCOUNT(tvc) == 1 && UBCINFOEXISTS(&tvc->v)) { - osi_VM_TryReclaim(tvc, &fv_slept); - if (fv_slept) { - uq = VLRU.prev; - i = 0; - continue; /* start over - may have raced. */ - } - } -#endif -#if defined(AFS_LINUX22_ENV) - if (tvc != afs_globalVp && VREFCOUNT(tvc) && tvc->opens == 0) + if (tvc->opens == 0 && ((tvc->states & CUnlinkedDel) == 0) + && VREFCOUNT(tvc) == 1 && UBCINFOEXISTS(&tvc->v)) { + osi_VM_TryReclaim(tvc, &fv_slept); + if (fv_slept) { + uq = VLRU.prev; + i = 0; + continue; /* start over - may have raced. */ + } + } +#elif defined(AFS_LINUX22_ENV) + if (tvc != afs_globalVp && VREFCOUNT(tvc) && tvc->opens == 0) { +#if defined(AFS_LINUX26_ENV) + AFS_GUNLOCK(); + d_prune_aliases(AFSTOI(tvc)); + AFS_GLOCK(); +#else afs_TryFlushDcacheChildren(tvc); #endif + } +#endif - if (VREFCOUNT(tvc) == 0 && tvc->opens == 0 - && (tvc->states & CUnlinkedDel) == 0) { + if (VREFCOUNT(tvc) == 0 && tvc->opens == 0 + && (tvc->states & CUnlinkedDel) == 0) { +#if defined(AFS_XBSD_ENV) + /* + * vgone() reclaims the vnode, which calls afs_FlushVCache(), + * then it puts the vnode on the free list. + * If we don't do this we end up with a cleaned vnode that's + * not on the free list. + * XXX assume FreeBSD is the same for now. + */ + vgone(AFSTOV(tvc)); + code = fv_slept = 0; +#else code = afs_FlushVCache(tvc, &fv_slept); +#endif if (code == 0) { - anumber--; + anumber--; } if (fv_slept) { - uq = VLRU.prev; - i = 0; - continue; /* start over - may have raced. */ + uq = VLRU.prev; + i = 0; + continue; /* start over - may have raced. */ } - } - if (tq == uq ) break; + } + if (tq == uq) + break; } } if (!freeVCList) { /* none free, making one is better than a panic */ afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */ - tvc = (struct vcache *) afs_osi_Alloc(sizeof (struct vcache)); -#ifdef AFS_AIX32_ENV + tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache)); +#ifdef KERNEL_HAVE_PIN pin((char *)tvc, sizeof(struct vcache)); /* XXX */ #endif #ifdef AFS_MACH_ENV @@ -833,31 +887,39 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, */ #endif /* AFS_MACH_ENV */ #if defined(AFS_SGI_ENV) - { char name[METER_NAMSZ]; - memset(tvc, 0, sizeof(struct vcache)); - tvc->v.v_number = ++afsvnumbers; - tvc->vc_rwlockid = OSI_NO_LOCKID; - initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number)); + { + char name[METER_NAMSZ]; + memset(tvc, 0, sizeof(struct vcache)); + tvc->v.v_number = ++afsvnumbers; + tvc->vc_rwlockid = OSI_NO_LOCKID; + initnsema(&tvc->vc_rwlock, 1, + makesname(name, "vrw", tvc->v.v_number)); #ifndef AFS_SGI53_ENV - initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number)); + initnsema(&tvc->v.v_sync, 0, + makesname(name, "vsy", tvc->v.v_number)); #endif #ifndef AFS_SGI62_ENV - initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number)); + initnlock(&tvc->v.v_lock, + makesname(name, "vlk", tvc->v.v_number)); #endif } #endif /* AFS_SGI_ENV */ - } - else { - tvc = freeVCList; /* take from free list */ + } else { + tvc = freeVCList; /* take from free list */ freeVCList = tvc->nextfree; - tvc->nextfree = (struct vcache *)0; + tvc->nextfree = NULL; } -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ #ifdef AFS_MACH_ENV vm_info_ptr = tvc->v.v_vm_info; #endif /* AFS_MACH_ENV */ +#if defined(AFS_XBSD_ENV) + if (tvc->v) + panic("afs_NewVCache(): free vcache with vnode attached"); +#endif + #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) memset((char *)tvc, 0, sizeof(struct vcache)); #else @@ -873,9 +935,45 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, tvc->v.v_vm_info = vm_info_ptr; tvc->v.v_vm_info->pager = MEMORY_OBJECT_NULL; #endif /* AFS_MACH_ENV */ +#ifdef AFS_OBSD_ENV + AFS_GUNLOCK(); + afs_nbsd_getnewvnode(tvc); /* includes one refcount */ + AFS_GLOCK(); + lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0); +#endif +#ifdef AFS_FBSD_ENV + { + struct vnode *vp; + + AFS_GUNLOCK(); +#ifdef AFS_FBSD50_ENV + if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp)) +#else + if (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &vp)) +#endif + panic("afs getnewvnode"); /* can't happen */ + AFS_GLOCK(); + if (tvc->v != NULL) { + /* I'd like to know if this ever happens... + We don't drop global for the rest of this function, + so if we do lose the race, the other thread should + have found the same vnode and finished initializing + the vcache entry. Is it conceivable that this vcache + entry could be recycled during this interval? If so, + then there probably needs to be some sort of additional + mutual exclusion (an Embryonic flag would suffice). + -GAW */ + printf("afs_NewVCache: lost the race\n"); + return (tvc); + } + tvc->v = vp; + tvc->v->v_data = tvc; + lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0); + } +#endif tvc->parentVnode = 0; - tvc->mvid = (struct VenusFid *) 0; - tvc->linkData = (char *) 0; + tvc->mvid = NULL; + tvc->linkData = NULL; tvc->cbExpires = 0; tvc->opens = 0; tvc->execsOrWriters = 0; @@ -888,17 +986,85 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, tvc->vc_error = 0; afs_symhint_inval(tvc); #ifdef AFS_TEXT_ENV - tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV; + tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV; #endif hzero(tvc->mapDV); tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */ - hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */ + hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */ +#if defined(AFS_LINUX22_ENV) +{ + struct inode *ip = AFSTOI(tvc); + struct address_space *mapping = &ip->i_data; + +#if defined(AFS_LINUX26_ENV) + inode_init_once(ip); +#else + sema_init(&ip->i_sem, 1); + INIT_LIST_HEAD(&ip->i_hash); + INIT_LIST_HEAD(&ip->i_dentry); +#if defined(AFS_LINUX24_ENV) + sema_init(&ip->i_zombie, 1); + init_waitqueue_head(&ip->i_wait); + spin_lock_init(&ip->i_data.i_shared_lock); +#ifdef STRUCT_ADDRESS_SPACE_HAS_PAGE_LOCK + spin_lock_init(&ip->i_data.page_lock); +#endif + INIT_LIST_HEAD(&ip->i_data.clean_pages); + INIT_LIST_HEAD(&ip->i_data.dirty_pages); + INIT_LIST_HEAD(&ip->i_data.locked_pages); + INIT_LIST_HEAD(&ip->i_dirty_buffers); +#ifdef STRUCT_INODE_HAS_I_DIRTY_DATA_BUFFERS + INIT_LIST_HEAD(&ip->i_dirty_data_buffers); +#endif +#ifdef STRUCT_INODE_HAS_I_DEVICES + INIT_LIST_HEAD(&ip->i_devices); +#endif +#ifdef STRUCT_INODE_HAS_I_TRUNCATE_SEM + init_rwsem(&ip->i_truncate_sem); +#endif +#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM + init_rwsem(&ip->i_alloc_sem); +#endif + +#else /* AFS_LINUX22_ENV */ + sema_init(&ip->i_atomic_write, 1); + init_waitqueue(&ip->i_wait); +#endif +#endif + +#if defined(AFS_LINUX24_ENV) + mapping->host = ip; + ip->i_mapping = mapping; +#ifdef STRUCT_ADDRESS_SPACE_HAS_GFP_MASK + ip->i_data.gfp_mask = GFP_HIGHUSER; +#endif +#if defined(AFS_LINUX26_ENV) + mapping_set_gfp_mask(mapping, GFP_HIGHUSER); +{ + extern struct backing_dev_info afs_backing_dev_info; + + mapping->backing_dev_info = &afs_backing_dev_info; +} +#endif +#endif + +#if !defined(AFS_LINUX26_ENV) + if (afs_globalVFS) + ip->i_dev = afs_globalVFS->s_dev; +#endif + ip->i_sb = afs_globalVFS; + put_inode_on_dummy_list(ip); +} +#endif + #ifdef AFS_OSF_ENV /* Hold it for the LRU (should make count 2) */ VN_HOLD(AFSTOV(tvc)); -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ +#if !defined(AFS_XBSD_ENV) VREFCOUNT_SET(tvc, 1); /* us */ -#endif /* AFS_OSF_ENV */ +#endif /* AFS_XBSD_ENV */ +#endif /* AFS_OSF_ENV */ #ifdef AFS_AIX32_ENV LOCK_INIT(&tvc->pvmlock, "vcache pvmlock"); tvc->vmh = tvc->segid = NULL; @@ -909,17 +1075,17 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL); #if defined(AFS_SUN55_ENV) - /* This is required if the kaio (kernel aynchronous io) - ** module is installed. Inside the kernel, the function - ** check_vp( common/os/aio.c) checks to see if the kernel has - ** to provide asynchronous io for this vnode. This - ** function extracts the device number by following the - ** v_data field of the vnode. If we do not set this field - ** then the system panics. The value of the v_data field - ** is not really important for AFS vnodes because the kernel - ** does not do asynchronous io for regular files. Hence, - ** for the time being, we fill up the v_data field with the - ** vnode pointer itself. */ + /* This is required if the kaio (kernel aynchronous io) + ** module is installed. Inside the kernel, the function + ** check_vp( common/os/aio.c) checks to see if the kernel has + ** to provide asynchronous io for this vnode. This + ** function extracts the device number by following the + ** v_data field of the vnode. If we do not set this field + ** then the system panics. The value of the v_data field + ** is not really important for AFS vnodes because the kernel + ** does not do asynchronous io for regular files. Hence, + ** for the time being, we fill up the v_data field with the + ** vnode pointer itself. */ tvc->v.v_data = (char *)tvc; #endif /* AFS_SUN55_ENV */ #endif @@ -928,15 +1094,16 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, tvc->Access = NULL; tvc->callback = serverp; /* to minimize chance that clear - request is lost */ + * request is lost */ /* initialize vnode data, note vrefCount is v.v_count */ #ifdef AFS_AIX_ENV /* Don't forget to free the gnode space */ - tvc->v.v_gnode = gnodepnt = (struct gnode *) osi_AllocSmallSpace(sizeof(struct gnode)); + tvc->v.v_gnode = gnodepnt = + (struct gnode *)osi_AllocSmallSpace(sizeof(struct gnode)); memset((char *)gnodepnt, 0, sizeof(struct gnode)); #endif #ifdef AFS_SGI64_ENV - memset((void*)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc)); + memset((void *)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc)); bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops); #ifdef AFS_SGI65_ENV vn_bhv_head_init(&(tvc->v.v_bh), "afsvp"); @@ -946,7 +1113,7 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc)); #endif #ifdef AFS_SGI65_ENV - tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion*)tvc; + tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion *)tvc; #ifdef VNODE_TRACING tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0); #endif @@ -961,7 +1128,7 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number); #endif #ifdef INTR_KTHREADS - AFS_VN_INIT_BUF_LOCK(&(tvc->v)); + AFS_VN_INIT_BUF_LOCK(&(tvc->v)); #endif #else SetAfsVnode(AFSTOV(tvc)); @@ -969,38 +1136,31 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, #ifdef AFS_DARWIN_ENV tvc->v.v_ubcinfo = UBC_INFO_NULL; lockinit(&tvc->rwlock, PINOD, "vcache rwlock", 0, 0); - cache_purge(AFSTOV(tvc)); - tvc->v.v_data=tvc; - tvc->v.v_tag=VT_AFS; + cache_purge(AFSTOV(tvc)); + tvc->v.v_data = tvc; + tvc->v.v_tag = VT_AFS; /* VLISTNONE(&tvc->v); */ - tvc->v.v_freelist.tqe_next=0; - tvc->v.v_freelist.tqe_prev=(struct vnode **)0xdeadb; - /*tvc->vrefCount++;*/ -#endif -#ifdef AFS_FBSD_ENV - lockinit(&tvc->rwlock, PINOD, "vcache rwlock", 0, 0); - cache_purge(AFSTOV(tvc)); - tvc->v.v_data=tvc; - tvc->v.v_tag=VT_AFS; - tvc->v.v_usecount++; /* steal an extra ref for now so vfree never happens */ - /* This extra ref is dealt with above... */ + tvc->v.v_freelist.tqe_next = 0; + tvc->v.v_freelist.tqe_prev = (struct vnode **)0xdeadb; + /*tvc->vrefCount++; */ #endif /* * The proper value for mvstat (for root fids) is setup by the caller. */ - tvc->mvstat = 0; + tvc->mvstat = 0; if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1) - tvc->mvstat = 2; - if (afs_globalVFS == 0) osi_Panic("afs globalvfs"); + tvc->mvstat = 2; + if (afs_globalVFS == 0) + osi_Panic("afs globalvfs"); vSetVfsp(tvc, afs_globalVFS); vSetType(tvc, VREG); #ifdef AFS_AIX_ENV - tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */ + tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */ tvc->v.v_vfsprev = NULL; afs_globalVFS->vfs_vnodes = &tvc->v; if (tvc->v.v_vfsnext != NULL) tvc->v.v_vfsnext->v_vfsprev = &tvc->v; - tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us!*/ + tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us! */ gnodepnt->gn_vnode = &tvc->v; #endif #ifdef AFS_DEC_ENV @@ -1012,10 +1172,10 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, #ifdef AFS_OSF_ENV /* Is this needed??? */ insmntque(tvc, afs_globalVFS); -#endif /* AFS_OSF_ENV */ -#endif /* AFS_DUX40_ENV */ +#endif /* AFS_OSF_ENV */ +#endif /* AFS_DUX40_ENV */ #if defined(AFS_SGI_ENV) - VN_SET_DPAGES(&(tvc->v), (struct pfdat*)NULL); + VN_SET_DPAGES(&(tvc->v), (struct pfdat *)NULL); osi_Assert((tvc->v.v_flag & VINACT) == 0); tvc->v.v_flag = 0; osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0); @@ -1033,77 +1193,33 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, vn_initlist((struct vnlist *)&tvc->v); tvc->lastr = 0; #endif /* AFS_SGI_ENV */ -#if defined(AFS_LINUX22_ENV) - { - struct inode *ip = AFSTOI(tvc); - sema_init(&ip->i_sem, 1); -#if defined(AFS_LINUX24_ENV) - sema_init(&ip->i_zombie, 1); - init_waitqueue_head(&ip->i_wait); - spin_lock_init(&ip->i_data.i_shared_lock); -#ifdef STRUCT_ADDRESS_SPACE_HAS_PAGE_LOCK - spin_lock_init(&ip->i_data.page_lock); -#endif - INIT_LIST_HEAD(&ip->i_data.clean_pages); - INIT_LIST_HEAD(&ip->i_data.dirty_pages); - INIT_LIST_HEAD(&ip->i_data.locked_pages); - INIT_LIST_HEAD(&ip->i_dirty_buffers); -#ifdef STRUCT_INODE_HAS_I_DIRTY_DATA_BUFFERS - INIT_LIST_HEAD(&ip->i_dirty_data_buffers); -#endif -#ifdef STRUCT_INODE_HAS_I_DEVICES - INIT_LIST_HEAD(&ip->i_devices); -#endif - ip->i_data.host = (void*) ip; -#ifdef STRUCT_ADDRESS_SPACE_HAS_GFP_MASK - ip->i_data.gfp_mask = GFP_HIGHUSER; -#endif - ip->i_mapping = &ip->i_data; -#ifdef STRUCT_INODE_HAS_I_TRUNCATE_SEM - init_rwsem(&ip->i_truncate_sem); -#endif -#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM - init_rwsem(&ip->i_alloc_sem); -#endif -#else - sema_init(&ip->i_atomic_write, 1); - init_waitqueue(&ip->i_wait); -#endif - INIT_LIST_HEAD(&ip->i_hash); - INIT_LIST_HEAD(&ip->i_dentry); - if (afs_globalVFS) { - ip->i_dev = afs_globalVFS->s_dev; - ip->i_sb = afs_globalVFS; - } - } -#endif tvc->h1.dchint = 0; - osi_dnlc_purgedp(tvc); /* this may be overkill */ + osi_dnlc_purgedp(tvc); /* this may be overkill */ memset((char *)&(tvc->quick), 0, sizeof(struct vtodc)); memset((char *)&(tvc->callsort), 0, sizeof(struct afs_q)); - tvc->slocks = (struct SimpleLocks *)0; + tvc->slocks = NULL; i = VCHash(afid); tvc->hnext = afs_vhashT[i]; afs_vhashT[i] = tvc; if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("NewVCache VLRU inconsistent"); + refpanic("NewVCache VLRU inconsistent"); } - QAdd(&VLRU, &tvc->vlruq); /* put in lruq */ + QAdd(&VLRU, &tvc->vlruq); /* put in lruq */ if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("NewVCache VLRU inconsistent2"); + refpanic("NewVCache VLRU inconsistent2"); } if (tvc->vlruq.next->prev != &(tvc->vlruq)) { - refpanic ("NewVCache VLRU inconsistent3"); + refpanic("NewVCache VLRU inconsistent3"); } if (tvc->vlruq.prev->next != &(tvc->vlruq)) { - refpanic ("NewVCache VLRU inconsistent4"); + refpanic("NewVCache VLRU inconsistent4"); } vcachegen++; return tvc; -} /*afs_NewVCache*/ +} /*afs_NewVCache */ /* @@ -1117,54 +1233,44 @@ struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp, */ /* LOCK: afs_FlushActiveVcaches afs_xvcache N */ void -afs_FlushActiveVcaches(doflocks) - register afs_int32 doflocks; - -{ /*afs_FlushActiveVcaches*/ - +afs_FlushActiveVcaches(register afs_int32 doflocks) +{ register struct vcache *tvc; register int i; register struct conn *tc; register afs_int32 code; - register struct AFS_UCRED *cred; + register struct AFS_UCRED *cred = NULL; struct vrequest treq, ureq; struct AFSVolSync tsync; int didCore; - XSTATS_DECLS - - AFS_STATCNT(afs_FlushActiveVcaches); + XSTATS_DECLS AFS_STATCNT(afs_FlushActiveVcaches); ObtainReadLock(&afs_xvcache); - for(i=0;ihnext) { + for (i = 0; i < VCSIZE; i++) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { if (doflocks && tvc->flockCount != 0) { /* if this entry has an flock, send a keep-alive call out */ - osi_vnhold(tvc, 0); + osi_vnhold(tvc, 0); ReleaseReadLock(&afs_xvcache); - ObtainWriteLock(&tvc->lock,51); + ObtainWriteLock(&tvc->lock, 51); do { - afs_InitReq(&treq, &afs_osi_cred); + afs_InitReq(&treq, afs_osi_credp); treq.flags |= O_NONBLOCK; tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK); + RX_AFS_GUNLOCK(); + code = RXAFS_ExtendLock(tc->id, - (struct AFSFid *) &tvc->fid.Fid, + (struct AFSFid *)&tvc->fid.Fid, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &tvc->fid, &treq, - AFS_STATS_FS_RPCIDX_EXTENDLOCK, - SHARED_LOCK, (struct cell *)0)); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &tvc->fid, &treq, + AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL)); ReleaseWriteLock(&tvc->lock); ObtainReadLock(&afs_xvcache); @@ -1177,9 +1283,9 @@ afs_FlushActiveVcaches(doflocks) * this code. Also, drop the afs_xvcache lock while * getting vcache locks. */ - osi_vnhold(tvc,0); + osi_vnhold(tvc, 0); ReleaseReadLock(&afs_xvcache); -#if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) +#if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) afs_BozonLock(&tvc->pvnLock, tvc); #endif #if defined(AFS_SGI_ENV) @@ -1187,21 +1293,21 @@ afs_FlushActiveVcaches(doflocks) * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt */ osi_Assert(VREFCOUNT(tvc) > 0); - AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE); + AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE); #endif - ObtainWriteLock(&tvc->lock,52); + ObtainWriteLock(&tvc->lock, 52); if (tvc->states & CCore) { tvc->states &= ~CCore; /* XXXX Find better place-holder for cred XXXX */ - cred = (struct AFS_UCRED *) tvc->linkData; - tvc->linkData = (char *) 0; /* XXX */ + cred = (struct AFS_UCRED *)tvc->linkData; + tvc->linkData = NULL; /* XXX */ afs_InitReq(&ureq, cred); afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE, - ICL_TYPE_POINTER, tvc, - ICL_TYPE_INT32, tvc->execsOrWriters); + ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, + tvc->execsOrWriters); code = afs_StoreOnLastReference(tvc, &ureq); ReleaseWriteLock(&tvc->lock); -#if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) +#if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) afs_BozonUnlock(&tvc->pvnLock, tvc); #endif hzero(tvc->flushDV); @@ -1213,21 +1319,20 @@ afs_FlushActiveVcaches(doflocks) } } else if (tvc->states & CUnlinkedDel) { /* - * Ignore errors + * Ignore errors */ ReleaseWriteLock(&tvc->lock); -#if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) +#if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) afs_BozonUnlock(&tvc->pvnLock, tvc); #endif #if defined(AFS_SGI_ENV) - AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE); #endif afs_remunlink(tvc, 0); #if defined(AFS_SGI_ENV) - AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE); + AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE); #endif - } - else { + } else { /* lost (or won, perhaps) the race condition */ ReleaseWriteLock(&tvc->lock); #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) @@ -1235,7 +1340,7 @@ afs_FlushActiveVcaches(doflocks) #endif } #if defined(AFS_SGI_ENV) - AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE); + AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE); #endif ObtainReadLock(&afs_xvcache); AFS_FAST_RELE(tvc); @@ -1248,18 +1353,18 @@ afs_FlushActiveVcaches(doflocks) /* Matches write code setting CCore flag */ crfree(cred); } - } + } #ifdef AFS_DARWIN_ENV - if (VREFCOUNT(tvc) == 1 && UBCINFOEXISTS(&tvc->v)) { - if (tvc->opens) panic("flushactive open, hasubc, but refcnt 1"); - osi_VM_TryReclaim(tvc,0); + if (VREFCOUNT(tvc) == 1 && UBCINFOEXISTS(&tvc->v)) { + if (tvc->opens) + panic("flushactive open, hasubc, but refcnt 1"); + osi_VM_TryReclaim(tvc, 0); } #endif } } ReleaseReadLock(&afs_xvcache); - -} /*afs_FlushActiveVcaches*/ +} /* @@ -1267,12 +1372,12 @@ afs_FlushActiveVcaches(doflocks) * * Description: * Make sure a cache entry is up-to-date status-wise. - * + * * NOTE: everywhere that calls this can potentially be sped up * by checking CStatd first, and avoiding doing the InitReq * if this is up-to-date. * - * Anymore, the only places that call this KNOW already that the + * Anymore, the only places that call this KNOW already that the * vcache is not up-to-date, so we don't screw around. * * Parameters: @@ -1280,7 +1385,8 @@ afs_FlushActiveVcaches(doflocks) * areq : ??? */ -int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq) +int +afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq) { register struct vcache *tvc; @@ -1289,42 +1395,43 @@ int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq) #if defined(AFS_OSF_ENV) ObtainReadLock(&avc->lock); if (afs_IsWired(avc)) { - ReleaseReadLock(&avc->lock); - return 0; + ReleaseReadLock(&avc->lock); + return 0; } ReleaseReadLock(&avc->lock); #endif /* AFS_OSF_ENV */ /* otherwise we must fetch the status info */ - ObtainWriteLock(&avc->lock,53); + ObtainWriteLock(&avc->lock, 53); if (avc->states & CStatd) { ReleaseWriteLock(&avc->lock); return 0; } ObtainWriteLock(&afs_xcbhash, 461); - avc->states &= ~( CStatd | CUnique ); - avc->callback = (struct server *)0; + avc->states &= ~(CStatd | CUnique); + avc->callback = NULL; afs_DequeueCallback(avc); ReleaseWriteLock(&afs_xcbhash); ReleaseWriteLock(&avc->lock); - /* since we've been called back, or the callback has expired, - * it's possible that the contents of this directory, or this + /* since we've been called back, or the callback has expired, + * it's possible that the contents of this directory, or this * file's name have changed, thus invalidating the dnlc contents. */ - if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (avc); + if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(avc); else - osi_dnlc_purgevp (avc); - + osi_dnlc_purgevp(avc); + /* fetch the status info */ - tvc = afs_GetVCache(&avc->fid, areq, (afs_int32*)0, avc, READ_LOCK); - if (!tvc) return ENOENT; + tvc = afs_GetVCache(&avc->fid, areq, NULL, avc); + if (!tvc) + return ENOENT; /* Put it back; caller has already incremented vrefCount */ - afs_PutVCache(tvc, READ_LOCK); + afs_PutVCache(tvc); return 0; -} /*afs_VerifyVCache*/ +} /*afs_VerifyVCache */ /* @@ -1343,88 +1450,84 @@ int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq) * Callers: as of 1992-04-29, only called by WriteVCache */ static void -afs_SimpleVStat(avc, astat, areq) - register struct vcache *avc; - register struct AFSFetchStatus *astat; - struct vrequest *areq; -{ /*afs_SimpleVStat*/ - +afs_SimpleVStat(register struct vcache *avc, + register struct AFSFetchStatus *astat, struct vrequest *areq) +{ + afs_size_t length; AFS_STATCNT(afs_SimpleVStat); #ifdef AFS_SGI_ENV if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc) - && !AFS_VN_MAPPED((vnode_t*)avc)) + && !AFS_VN_MAPPED((vnode_t *) avc)) { #else - if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) + if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) { #endif - - { +#ifdef AFS_64BIT_CLIENT + FillInt64(length, astat->Length_hi, astat->Length); +#else /* AFS_64BIT_CLIENT */ + length = astat->Length; +#endif /* AFS_64BIT_CLIENT */ #if defined(AFS_SGI_ENV) - osi_Assert((valusema(&avc->vc_rwlock) <= 0) && - (OSI_GET_LOCKID() == avc->vc_rwlockid)); - if (astat->Length < avc->m.Length) { - vnode_t *vp = (vnode_t *)avc; - - osi_Assert(WriteLocked(&avc->lock)); - ReleaseWriteLock(&avc->lock); - AFS_GUNLOCK(); - PTOSSVP(vp, (off_t)astat->Length, (off_t)MAXLONG); - AFS_GLOCK(); - ObtainWriteLock(&avc->lock,67); - } -#endif - /* if writing the file, don't fetch over this value */ - afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, - ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length, - ICL_TYPE_INT32, astat->Length); - avc->m.Length = astat->Length; - avc->m.Date = astat->ClientModTime; + osi_Assert((valusema(&avc->vc_rwlock) <= 0) + && (OSI_GET_LOCKID() == avc->vc_rwlockid)); + if (length < avc->m.Length) { + vnode_t *vp = (vnode_t *) avc; + + osi_Assert(WriteLocked(&avc->lock)); + ReleaseWriteLock(&avc->lock); + AFS_GUNLOCK(); + PTOSSVP(vp, (off_t) length, (off_t) MAXLONG); + AFS_GLOCK(); + ObtainWriteLock(&avc->lock, 67); } +#endif + /* if writing the file, don't fetch over this value */ + afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length)); + avc->m.Length = length; + avc->m.Date = astat->ClientModTime; + } avc->m.Owner = astat->Owner; avc->m.Group = astat->Group; avc->m.Mode = astat->UnixModeBits; if (vType(avc) == VREG) { avc->m.Mode |= S_IFREG; - } - else if (vType(avc) == VDIR) { + } else if (vType(avc) == VDIR) { avc->m.Mode |= S_IFDIR; - } - else if (vType(avc) == VLNK) { - - - + } else if (vType(avc) == VLNK) { avc->m.Mode |= S_IFLNK; - if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1; + if ((avc->m.Mode & 0111) == 0) + avc->mvstat = 1; } if (avc->states & CForeign) { - struct axscache *ac; + struct axscache *ac; avc->anyAccess = astat->AnonymousAccess; #ifdef badidea - if ((astat->CallerAccess & ~astat->AnonymousAccess)) - /* USED TO SAY : - * Caller has at least one bit not covered by anonymous, and - * thus may have interesting rights. - * - * HOWEVER, this is a really bad idea, because any access query - * for bits which aren't covered by anonymous, on behalf of a user - * who doesn't have any special rights, will result in an answer of - * the form "I don't know, lets make a FetchStatus RPC and find out!" - * It's an especially bad idea under Ultrix, since (due to the lack of - * a proper access() call) it must perform several afs_access() calls - * in order to create magic mode bits that vary according to who makes - * the call. In other words, _every_ stat() generates a test for - * writeability... - */ + if ((astat->CallerAccess & ~astat->AnonymousAccess)) + /* USED TO SAY : + * Caller has at least one bit not covered by anonymous, and + * thus may have interesting rights. + * + * HOWEVER, this is a really bad idea, because any access query + * for bits which aren't covered by anonymous, on behalf of a user + * who doesn't have any special rights, will result in an answer of + * the form "I don't know, lets make a FetchStatus RPC and find out!" + * It's an especially bad idea under Ultrix, since (due to the lack of + * a proper access() call) it must perform several afs_access() calls + * in order to create magic mode bits that vary according to who makes + * the call. In other words, _every_ stat() generates a test for + * writeability... + */ #endif /* badidea */ - if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid))) - ac->axess = astat->CallerAccess; - else /* not found, add a new one if possible */ - afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess); + if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid))) + ac->axess = astat->CallerAccess; + else /* not found, add a new one if possible */ + afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess); } -} /*afs_SimpleVStat*/ +} /*afs_SimpleVStat */ /* @@ -1443,44 +1546,36 @@ afs_SimpleVStat(avc, astat, areq) * Must be called with a shared lock held on the vnode. */ -afs_WriteVCache(avc, astatus, areq) - register struct vcache *avc; - register struct AFSStoreStatus *astatus; - struct vrequest *areq; - -{ /*afs_WriteVCache*/ - afs_int32 code; - struct conn *tc; +int +afs_WriteVCache(register struct vcache *avc, + register struct AFSStoreStatus *astatus, + struct vrequest *areq) +{ + afs_int32 code; + struct conn *tc; struct AFSFetchStatus OutStatus; struct AFSVolSync tsync; - XSTATS_DECLS - - AFS_STATCNT(afs_WriteVCache); + XSTATS_DECLS AFS_STATCNT(afs_WriteVCache); afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length); + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length)); do { tc = afs_Conn(&avc->fid, areq, SHARED_LOCK); if (tc) { - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_StoreStatus(tc->id, - (struct AFSFid *) &avc->fid.Fid, - astatus, &OutStatus, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ - XSTATS_END_TIME; - } - else code = -1; - } while - (afs_Analyze(tc, code, &avc->fid, areq, - AFS_STATS_FS_RPCIDX_STORESTATUS, - SHARED_LOCK, (struct cell *)0)); + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS); + RX_AFS_GUNLOCK(); + code = + RXAFS_StoreStatus(tc->id, (struct AFSFid *)&avc->fid.Fid, + astatus, &OutStatus, &tsync); + RX_AFS_GLOCK(); + XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS, + SHARED_LOCK, NULL)); - UpgradeSToWLock(&avc->lock,20); + UpgradeSToWLock(&avc->lock, 20); if (code == 0) { /* success, do the changes locally */ afs_SimpleVStat(avc, &OutStatus, areq); @@ -1490,20 +1585,19 @@ afs_WriteVCache(avc, astatus, areq) * over a file being written. */ avc->m.Date = OutStatus.ClientModTime; - } - else { + } else { /* failure, set up to check with server next time */ ObtainWriteLock(&afs_xcbhash, 462); - afs_DequeueCallback(avc); - avc->states &= ~( CStatd | CUnique); /* turn off stat valid flag */ + afs_DequeueCallback(avc); + avc->states &= ~(CStatd | CUnique); /* turn off stat valid flag */ ReleaseWriteLock(&afs_xcbhash); - if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (avc); /* if it (could be) a directory */ + if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(avc); /* if it (could be) a directory */ } ConvertWToSLock(&avc->lock); return code; -} /*afs_WriteVCache*/ +} /*afs_WriteVCache */ /* * afs_ProcessFS @@ -1524,16 +1618,17 @@ afs_WriteVCache(avc, astatus, areq) * it sufficiently to be certain that it is adequate. */ void -afs_ProcessFS(avc, astat, areq) - register struct vcache *avc; - struct vrequest *areq; - register struct AFSFetchStatus *astat; - -{ /*afs_ProcessFS*/ - - register int i; +afs_ProcessFS(register struct vcache *avc, + register struct AFSFetchStatus *astat, struct vrequest *areq) +{ + afs_size_t length; AFS_STATCNT(afs_ProcessFS); +#ifdef AFS_64BIT_CLIENT + FillInt64(length, astat->Length_hi, astat->Length); +#else /* AFS_64BIT_CLIENT */ + length = astat->Length; +#endif /* AFS_64BIT_CLIENT */ /* WARNING: afs_DoBulkStat uses the Length field to store a sequence * number for each bulk status request. Under no circumstances * should afs_DoBulkStat store a sequence number if the new @@ -1542,20 +1637,19 @@ afs_ProcessFS(avc, astat, areq) * also need to change the conditional in afs_DoBulkStat. */ #ifdef AFS_SGI_ENV if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc) - && !AFS_VN_MAPPED((vnode_t*)avc)) + && !AFS_VN_MAPPED((vnode_t *) avc)) { #else - if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) + if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) { #endif - { - /* if we're writing or mapping this file, don't fetch over these - * values. - */ - afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc, - ICL_TYPE_INT32, avc->m.Length, - ICL_TYPE_INT32, astat->Length); - avc->m.Length = astat->Length; - avc->m.Date = astat->ClientModTime; - } + /* if we're writing or mapping this file, don't fetch over these + * values. + */ + afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc, + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length), + ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length)); + avc->m.Length = length; + avc->m.Date = astat->ClientModTime; + } hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion); avc->m.Owner = astat->Owner; avc->m.Mode = astat->UnixModeBits; @@ -1564,12 +1658,10 @@ afs_ProcessFS(avc, astat, areq) if (astat->FileType == File) { vSetType(avc, VREG); avc->m.Mode |= S_IFREG; - } - else if (astat->FileType == Directory) { + } else if (astat->FileType == Directory) { vSetType(avc, VDIR); avc->m.Mode |= S_IFDIR; - } - else if (astat->FileType == SymbolicLink) { + } else if (astat->FileType == SymbolicLink) { if (afs_fakestat_enable && (avc->m.Mode & 0111) == 0) { vSetType(avc, VDIR); avc->m.Mode |= S_IFDIR; @@ -1583,81 +1675,71 @@ afs_ProcessFS(avc, astat, areq) } avc->anyAccess = astat->AnonymousAccess; #ifdef badidea - if ((astat->CallerAccess & ~astat->AnonymousAccess)) - /* USED TO SAY : - * Caller has at least one bit not covered by anonymous, and - * thus may have interesting rights. - * - * HOWEVER, this is a really bad idea, because any access query - * for bits which aren't covered by anonymous, on behalf of a user - * who doesn't have any special rights, will result in an answer of - * the form "I don't know, lets make a FetchStatus RPC and find out!" - * It's an especially bad idea under Ultrix, since (due to the lack of - * a proper access() call) it must perform several afs_access() calls - * in order to create magic mode bits that vary according to who makes - * the call. In other words, _every_ stat() generates a test for - * writeability... - */ + if ((astat->CallerAccess & ~astat->AnonymousAccess)) + /* USED TO SAY : + * Caller has at least one bit not covered by anonymous, and + * thus may have interesting rights. + * + * HOWEVER, this is a really bad idea, because any access query + * for bits which aren't covered by anonymous, on behalf of a user + * who doesn't have any special rights, will result in an answer of + * the form "I don't know, lets make a FetchStatus RPC and find out!" + * It's an especially bad idea under Ultrix, since (due to the lack of + * a proper access() call) it must perform several afs_access() calls + * in order to create magic mode bits that vary according to who makes + * the call. In other words, _every_ stat() generates a test for + * writeability... + */ #endif /* badidea */ - { + { struct axscache *ac; if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid))) - ac->axess = astat->CallerAccess; - else /* not found, add a new one if possible */ - afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess); - } - + ac->axess = astat->CallerAccess; + else /* not found, add a new one if possible */ + afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess); + } #ifdef AFS_LINUX22_ENV - vcache2inode(avc); /* Set the inode attr cache */ + vcache2inode(avc); /* Set the inode attr cache */ #endif #ifdef AFS_DARWIN_ENV - osi_VM_Setup(avc,1); + osi_VM_Setup(avc, 1); #endif -} /*afs_ProcessFS*/ +} /*afs_ProcessFS */ -afs_RemoteLookup(afid, areq, name, nfid, OutStatusp, CallBackp, serverp, tsyncp) - register struct VenusFid *afid; - struct vrequest *areq; - char *name; - struct VenusFid *nfid; - struct AFSFetchStatus *OutStatusp; - struct AFSCallBack *CallBackp; - struct server **serverp; - struct AFSVolSync *tsyncp; +int +afs_RemoteLookup(register struct VenusFid *afid, struct vrequest *areq, + char *name, struct VenusFid *nfid, + struct AFSFetchStatus *OutStatusp, + struct AFSCallBack *CallBackp, struct server **serverp, + struct AFSVolSync *tsyncp) { - afs_int32 code, i; - register struct vcache *tvc; - struct volume *tvp; + afs_int32 code; afs_uint32 start; register struct conn *tc; struct AFSFetchStatus OutDirStatus; - XSTATS_DECLS - - if (!name) name = ""; /* XXX */ + XSTATS_DECLS if (!name) + name = ""; /* XXX */ do { tc = afs_Conn(afid, areq, SHARED_LOCK); if (tc) { - if (serverp) *serverp = tc->srvr->server; + if (serverp) + *serverp = tc->srvr->server; start = osi_Time(); XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_Lookup(tc->id, (struct AFSFid *) &afid->Fid, name, - (struct AFSFid *) &nfid->Fid, - OutStatusp, &OutDirStatus, CallBackp, tsyncp); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + code = + RXAFS_Lookup(tc->id, (struct AFSFid *)&afid->Fid, name, + (struct AFSFid *)&nfid->Fid, OutStatusp, + &OutDirStatus, CallBackp, tsyncp); + RX_AFS_GLOCK(); XSTATS_END_TIME; - } else + } else code = -1; - } while - (afs_Analyze(tc, code, afid, areq, - AFS_STATS_FS_RPCIDX_XLOOKUP, - SHARED_LOCK, (struct cell *)0)); + } while (afs_Analyze + (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK, + NULL)); return code; } @@ -1674,7 +1756,7 @@ afs_RemoteLookup(afid, areq, name, nfid, OutStatusp, CallBackp, serverp, tsyncp) * afid : File ID. * areq : Ptr to associated vrequest structure, specifying the * user whose authentication tokens will be used. - * avc : caller may already have a vcache for this file, which is + * avc : caller may already have a vcache for this file, which is * already held. * * Environment: @@ -1688,56 +1770,58 @@ afs_RemoteLookup(afid, areq, name, nfid, OutStatusp, CallBackp, serverp, tsyncp) * * 1. Lock all files first, then directories. * 2. Within a particular type, lock entries in Fid.Vnode order. - * + * * This locking hierarchy is convenient because it allows locking * of a parent dir cache entry, given a file (to check its access * control list). It also allows renames to be handled easily by * locking directories in a constant order. * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock. */ -struct vcache *afs_GetVCache(afid, areq, cached, avc, locktype) - register struct VenusFid *afid; - struct vrequest *areq; - afs_int32 *cached; - afs_int32 locktype; - struct vcache *avc; /* might have a vcache structure already, which must - * already be held by the caller */ -{ /*afs_GetVCache*/ - - afs_int32 code, i, newvcache=0; + /* might have a vcache structure already, which must + * already be held by the caller */ + +struct vcache * +afs_GetVCache(register struct VenusFid *afid, struct vrequest *areq, + afs_int32 * cached, struct vcache *avc) +{ + + afs_int32 code, newvcache = 0; register struct vcache *tvc; struct volume *tvp; afs_int32 retry; AFS_STATCNT(afs_GetVCache); - if (cached) *cached = 0; /* Init just in case */ + if (cached) + *cached = 0; /* Init just in case */ + +#if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) + loop: +#endif -loop: - ObtainSharedLock(&afs_xvcache,5); + ObtainSharedLock(&afs_xvcache, 5); - tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS | DO_VLRU ); + tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU); if (tvc && retry) { #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) ReleaseSharedLock(&afs_xvcache); spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD); goto loop; #endif - } - - if (tvc) { - if (cached) - *cached = 1; - if (tvc->states & CStatd) { - ReleaseSharedLock(&afs_xvcache); - return tvc; - } } - else { - UpgradeSToWLock(&afs_xvcache,21); + + if (tvc) { + if (cached) + *cached = 1; + if (tvc->states & CStatd) { + ReleaseSharedLock(&afs_xvcache); + return tvc; + } + } else { + UpgradeSToWLock(&afs_xvcache, 21); /* no cache entry, better grab one */ - tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK); + tvc = afs_NewVCache(afid, NULL); newvcache = 1; ConvertWToSLock(&afs_xvcache); @@ -1746,7 +1830,7 @@ loop: ReleaseSharedLock(&afs_xvcache); - ObtainWriteLock(&tvc->lock,54); + ObtainWriteLock(&tvc->lock, 54); if (tvc->states & CStatd) { #ifdef AFS_LINUX22_ENV @@ -1754,39 +1838,80 @@ loop: #endif ReleaseWriteLock(&tvc->lock); #ifdef AFS_DARWIN_ENV - osi_VM_Setup(tvc,0); + osi_VM_Setup(tvc, 0); #endif return tvc; } - #if defined(AFS_OSF_ENV) - if (afs_IsWired(tvc)) { - ReleaseWriteLock(&tvc->lock); - return tvc; - } + if (afs_IsWired(tvc)) { + ReleaseWriteLock(&tvc->lock); + return tvc; + } #endif /* AFS_OSF_ENV */ +#ifdef AFS_OBSD_ENV + VOP_LOCK(AFSTOV(tvc), LK_EXCLUSIVE | LK_RETRY, curproc); + uvm_vnp_uncache(AFSTOV(tvc)); + VOP_UNLOCK(AFSTOV(tvc), 0, curproc); +#endif +#ifdef AFS_FBSD_ENV + /* + * XXX - I really don't like this. Should try to understand better. + * It seems that sometimes, when we get called, we already hold the + * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache). + * We can't drop the vnode lock, because that could result in a race. + * Sometimes, though, we get here and don't hold the vnode lock. + * I hate code paths that sometimes hold locks and sometimes don't. + * In any event, the dodge we use here is to check whether the vnode + * is locked, and if it isn't, then we gain and drop it around the call + * to vinvalbuf; otherwise, we leave it alone. + */ + { + struct vnode *vp; + int iheldthelock; + + vp = AFSTOV(tvc); +#ifdef AFS_FBSD50_ENV + iheldthelock = VOP_ISLOCKED(vp, curthread); + if (!iheldthelock) + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread); + vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0); + if (!iheldthelock) + VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread); +#else + iheldthelock = VOP_ISLOCKED(vp, curproc); + if (!iheldthelock) + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc); + vinvalbuf(vp, V_SAVE, osi_curcred(), curproc, PINOD, 0); + if (!iheldthelock) + VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc); +#endif + } +#endif ObtainWriteLock(&afs_xcbhash, 464); - tvc->states &= ~CUnique; + tvc->states &= ~CUnique; tvc->callback = 0; afs_DequeueCallback(tvc); ReleaseWriteLock(&afs_xcbhash); /* It is always appropriate to throw away all the access rights? */ afs_FreeAllAxs(&(tvc->Access)); - tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */ + tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */ if (tvp) { if ((tvp->states & VForeign)) { - if (newvcache) tvc->states |= CForeign; - if (newvcache && (tvp->rootVnode == afid->Fid.Vnode) + if (newvcache) + tvc->states |= CForeign; + if (newvcache && (tvp->rootVnode == afid->Fid.Vnode) && (tvp->rootUnique == afid->Fid.Unique)) { tvc->mvstat = 2; - } + } } - if (tvp->states & VRO) tvc->states |= CRO; - if (tvp->states & VBackup) tvc->states |= CBackup; + if (tvp->states & VRO) + tvc->states |= CRO; + if (tvp->states & VBackup) + tvc->states |= CBackup; /* now copy ".." entry back out of volume structure, if necessary */ - if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) { + if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) { if (!tvc->mvid) tvc->mvid = (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid)); @@ -1815,21 +1940,21 @@ loop: ObtainReadLock(&afs_xvcache); AFS_FAST_RELE(tvc); ReleaseReadLock(&afs_xvcache); - return (struct vcache *) 0; + return NULL; } ReleaseWriteLock(&tvc->lock); return tvc; -} /*afs_GetVCache*/ +} /*afs_GetVCache */ -struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq, - afs_int32 *cached, afs_int32 locktype, - struct vcache *adp, char *aname) +struct vcache * +afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq, + afs_int32 * cached, struct vcache *adp, char *aname) { - afs_int32 code, now, newvcache=0, hash; + afs_int32 code, now, newvcache = 0; struct VenusFid nfid; register struct vcache *tvc; struct volume *tvp; @@ -1841,81 +1966,92 @@ struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq, afs_int32 retry; AFS_STATCNT(afs_GetVCache); - if (cached) *cached = 0; /* Init just in case */ + if (cached) + *cached = 0; /* Init just in case */ +#if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) loop1: +#endif + ObtainReadLock(&afs_xvcache); - tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS /* no vlru */); + tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ ); if (tvc) { - ReleaseReadLock(&afs_xvcache); - if (retry) { + ReleaseReadLock(&afs_xvcache); + if (retry) { #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) - spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD); - goto loop1; + spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD); + goto loop1; #endif - } - ObtainReadLock(&tvc->lock); + } + ObtainReadLock(&tvc->lock); - if (tvc->states & CStatd) { - if (cached) { - *cached = 1; + if (tvc->states & CStatd) { + if (cached) { + *cached = 1; + } + ReleaseReadLock(&tvc->lock); + return tvc; } - ReleaseReadLock(&tvc->lock); - return tvc; - } - tvc->states &= ~CUnique; + tvc->states &= ~CUnique; ReleaseReadLock(&tvc->lock); ObtainReadLock(&afs_xvcache); AFS_FAST_RELE(tvc); - } /* if (tvc) */ - + } + /* if (tvc) */ ReleaseReadLock(&afs_xvcache); /* lookup the file */ nfid = *afid; now = osi_Time(); origCBs = afs_allCBs; /* if anything changes, we don't have a cb */ - code = afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack, - &serverp, &tsync); + code = + afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack, + &serverp, &tsync); +#if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) loop2: - ObtainSharedLock(&afs_xvcache,6); - tvc = afs_FindVCache(&nfid, 0, 0, &retry, DO_VLRU /* no xstats now*/); +#endif + + ObtainSharedLock(&afs_xvcache, 6); + tvc = afs_FindVCache(&nfid, &retry, DO_VLRU /* no xstats now */ ); if (tvc && retry) { #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) - ReleaseSharedLock(&afs_xvcache); - spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD); - goto loop2; + ReleaseSharedLock(&afs_xvcache); + spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD); + goto loop2; #endif } if (!tvc) { - /* no cache entry, better grab one */ - UpgradeSToWLock(&afs_xvcache,22); - tvc = afs_NewVCache(&nfid, (struct server *)0, 1, WRITE_LOCK); + /* no cache entry, better grab one */ + UpgradeSToWLock(&afs_xvcache, 22); + tvc = afs_NewVCache(&nfid, serverp); newvcache = 1; - ConvertWToSLock(&afs_xvcache); + ConvertWToSLock(&afs_xvcache); } ReleaseSharedLock(&afs_xvcache); - ObtainWriteLock(&tvc->lock,55); - + ObtainWriteLock(&tvc->lock, 55); + /* It is always appropriate to throw away all the access rights? */ afs_FreeAllAxs(&(tvc->Access)); - tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */ + tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */ if (tvp) { if ((tvp->states & VForeign)) { - if (newvcache) tvc->states |= CForeign; + if (newvcache) + tvc->states |= CForeign; if (newvcache && (tvp->rootVnode == afid->Fid.Vnode) && (tvp->rootUnique == afid->Fid.Unique)) tvc->mvstat = 2; } - if (tvp->states & VRO) tvc->states |= CRO; - if (tvp->states & VBackup) tvc->states |= CBackup; + if (tvp->states & VRO) + tvc->states |= CRO; + if (tvp->states & VBackup) + tvc->states |= CBackup; /* now copy ".." entry back out of volume structure, if necessary */ - if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) { + if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) { if (!tvc->mvid) tvc->mvid = (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid)); @@ -1926,50 +2062,50 @@ struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq, if (code) { ObtainWriteLock(&afs_xcbhash, 465); afs_DequeueCallback(tvc); - tvc->states &= ~( CStatd | CUnique ); + tvc->states &= ~(CStatd | CUnique); ReleaseWriteLock(&afs_xcbhash); - if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (tvc); /* if it (could be) a directory */ - if ( tvp ) - afs_PutVolume(tvp, READ_LOCK); + if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(tvc); /* if it (could be) a directory */ + if (tvp) + afs_PutVolume(tvp, READ_LOCK); ReleaseWriteLock(&tvc->lock); ObtainReadLock(&afs_xvcache); AFS_FAST_RELE(tvc); ReleaseReadLock(&afs_xvcache); - return (struct vcache *) 0; + return NULL; } ObtainWriteLock(&afs_xcbhash, 466); if (origCBs == afs_allCBs) { if (CallBack.ExpirationTime) { tvc->callback = serverp; - tvc->cbExpires = CallBack.ExpirationTime+now; + tvc->cbExpires = CallBack.ExpirationTime + now; tvc->states |= CStatd | CUnique; tvc->states &= ~CBulkFetching; afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp); } else if (tvc->states & CRO) { /* adapt gives us an hour. */ - tvc->cbExpires = 3600+osi_Time(); /*XXX*/ - tvc->states |= CStatd | CUnique; + tvc->cbExpires = 3600 + osi_Time(); + /*XXX*/ tvc->states |= CStatd | CUnique; tvc->states &= ~CBulkFetching; - afs_QueueCallback(tvc, CBHash(3600), tvp); + afs_QueueCallback(tvc, CBHash(3600), tvp); } else { - tvc->callback = (struct server *)0; + tvc->callback = NULL; afs_DequeueCallback(tvc); - tvc->states &= ~(CStatd | CUnique); - if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (tvc); /* if it (could be) a directory */ + tvc->states &= ~(CStatd | CUnique); + if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(tvc); /* if it (could be) a directory */ } } else { afs_DequeueCallback(tvc); - tvc->states &= ~CStatd; - tvc->states &= ~CUnique; - tvc->callback = (struct server *)0; - if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (tvc); /* if it (could be) a directory */ - } + tvc->states &= ~CStatd; + tvc->states &= ~CUnique; + tvc->callback = NULL; + if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(tvc); /* if it (could be) a directory */ + } ReleaseWriteLock(&afs_xcbhash); - if ( tvp ) + if (tvp) afs_PutVolume(tvp, READ_LOCK); afs_ProcessFS(tvc, &OutStatus, areq); @@ -1978,11 +2114,11 @@ struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq, } -struct vcache *afs_GetRootVCache(struct VenusFid *afid, - struct vrequest *areq, afs_int32 *cached, - struct volume *tvolp, afs_int32 locktype) +struct vcache * +afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq, + afs_int32 * cached, struct volume *tvolp) { - afs_int32 code, i, newvcache = 0, haveStatus = 0; + afs_int32 code = 0, i, newvcache = 0, haveStatus = 0; afs_int32 getNewFid = 0; afs_uint32 start; struct VenusFid nfid; @@ -1991,50 +2127,51 @@ struct vcache *afs_GetRootVCache(struct VenusFid *afid, struct AFSFetchStatus OutStatus; struct AFSCallBack CallBack; struct AFSVolSync tsync; - int origCBs; + int origCBs = 0; start = osi_Time(); - newmtpt: + newmtpt: if (!tvolp->rootVnode || getNewFid) { struct VenusFid tfid; tfid = *afid; tfid.Fid.Vnode = 0; /* Means get rootfid of volume */ - origCBs = afs_allCBs; /* ignore InitCallBackState */ - code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid, - &OutStatus, &CallBack, &serverp, &tsync); + origCBs = afs_allCBs; /* ignore InitCallBackState */ + code = + afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack, + &serverp, &tsync); if (code) { - return (struct vcache *)0; + return NULL; } /* ReleaseReadLock(&tvolp->lock); */ - ObtainWriteLock(&tvolp->lock,56); + ObtainWriteLock(&tvolp->lock, 56); tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode; tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique; - ReleaseWriteLock(&tvolp->lock); + ReleaseWriteLock(&tvolp->lock); /* ObtainReadLock(&tvolp->lock);*/ haveStatus = 1; } else { afid->Fid.Vnode = tvolp->rootVnode; afid->Fid.Unique = tvolp->rootUnique; - } - - ObtainSharedLock(&afs_xvcache,7); + } + + ObtainSharedLock(&afs_xvcache, 7); i = VCHash(afid); for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { - if (!FidCmp(&(tvc->fid), afid)) { + if (!FidCmp(&(tvc->fid), afid)) { #ifdef AFS_OSF_ENV /* Grab this vnode, possibly reactivating from the free list */ - /* for the present (95.05.25) everything on the hash table is + /* for the present (95.05.25) everything on the hash table is * definitively NOT in the free list -- at least until afs_reclaim * can be safely implemented */ int vg; AFS_GUNLOCK(); - vg = vget(AFSTOV(tvc)); /* this bumps ref count */ + vg = vget(AFSTOV(tvc)); /* this bumps ref count */ AFS_GLOCK(); if (vg) - continue; -#endif /* AFS_OSF_ENV */ + continue; +#endif /* AFS_OSF_ENV */ break; } } @@ -2043,49 +2180,49 @@ struct vcache *afs_GetRootVCache(struct VenusFid *afid, /* Mount point no longer stat'd or unknown. FID may have changed. */ #ifdef AFS_OSF_ENV if (tvc) - AFS_RELE(tvc); + AFS_RELE(AFSTOV(tvc)); #endif - tvc = (struct vcache*)0; + tvc = NULL; getNewFid = 1; ReleaseSharedLock(&afs_xvcache); goto newmtpt; } if (!tvc) { - UpgradeSToWLock(&afs_xvcache,23); + UpgradeSToWLock(&afs_xvcache, 23); /* no cache entry, better grab one */ - tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK); + tvc = afs_NewVCache(afid, NULL); newvcache = 1; afs_stats_cmperf.vcacheMisses++; - } - else { - if (cached) *cached = 1; + } else { + if (cached) + *cached = 1; afs_stats_cmperf.vcacheHits++; #ifdef AFS_OSF_ENV /* we already bumped the ref count in the for loop above */ -#else /* AFS_OSF_ENV */ - osi_vnhold(tvc,0); +#else /* AFS_OSF_ENV */ + osi_vnhold(tvc, 0); #endif - UpgradeSToWLock(&afs_xvcache,24); + UpgradeSToWLock(&afs_xvcache, 24); if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("GRVC VLRU inconsistent0"); + refpanic("GRVC VLRU inconsistent0"); } if (tvc->vlruq.next->prev != &(tvc->vlruq)) { - refpanic ("GRVC VLRU inconsistent1"); + refpanic("GRVC VLRU inconsistent1"); } if (tvc->vlruq.prev->next != &(tvc->vlruq)) { - refpanic ("GRVC VLRU inconsistent2"); + refpanic("GRVC VLRU inconsistent2"); } - QRemove(&tvc->vlruq); /* move to lruq head */ + QRemove(&tvc->vlruq); /* move to lruq head */ QAdd(&VLRU, &tvc->vlruq); if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("GRVC VLRU inconsistent3"); + refpanic("GRVC VLRU inconsistent3"); } if (tvc->vlruq.next->prev != &(tvc->vlruq)) { - refpanic ("GRVC VLRU inconsistent4"); + refpanic("GRVC VLRU inconsistent4"); } if (tvc->vlruq.prev->next != &(tvc->vlruq)) { - refpanic ("GRVC VLRU inconsistent5"); + refpanic("GRVC VLRU inconsistent5"); } vcachegen++; } @@ -2094,30 +2231,34 @@ struct vcache *afs_GetRootVCache(struct VenusFid *afid, if (tvc->states & CStatd) { return tvc; - } else { + } else { - ObtainReadLock(&tvc->lock); - tvc->states &= ~CUnique; - tvc->callback = (struct server *)0; /* redundant, perhaps */ - ReleaseReadLock(&tvc->lock); + ObtainReadLock(&tvc->lock); + tvc->states &= ~CUnique; + tvc->callback = NULL; /* redundant, perhaps */ + ReleaseReadLock(&tvc->lock); } - ObtainWriteLock(&tvc->lock,57); + ObtainWriteLock(&tvc->lock, 57); /* It is always appropriate to throw away all the access rights? */ afs_FreeAllAxs(&(tvc->Access)); - if (newvcache) tvc->states |= CForeign; - if (tvolp->states & VRO) tvc->states |= CRO; - if (tvolp->states & VBackup) tvc->states |= CBackup; + if (newvcache) + tvc->states |= CForeign; + if (tvolp->states & VRO) + tvc->states |= CRO; + if (tvolp->states & VBackup) + tvc->states |= CBackup; /* now copy ".." entry back out of volume structure, if necessary */ - if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode) + if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode) && (tvolp->rootUnique == afid->Fid.Unique)) { tvc->mvstat = 2; } - if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) { + if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) { if (!tvc->mvid) - tvc->mvid = (struct VenusFid *)osi_AllocSmallSpace(sizeof(struct VenusFid)); + tvc->mvid = (struct VenusFid *) + osi_AllocSmallSpace(sizeof(struct VenusFid)); *tvc->mvid = tvolp->dotdot; } @@ -2129,52 +2270,53 @@ struct vcache *afs_GetRootVCache(struct VenusFid *afid, tfid = *afid; tfid.Fid.Vnode = 0; /* Means get rootfid of volume */ - origCBs = afs_allCBs; /* ignore InitCallBackState */ - code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid, &OutStatus, - &CallBack, &serverp, &tsync); + origCBs = afs_allCBs; /* ignore InitCallBackState */ + code = + afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack, + &serverp, &tsync); } if (code) { ObtainWriteLock(&afs_xcbhash, 467); afs_DequeueCallback(tvc); - tvc->callback = (struct server *)0; - tvc->states &= ~(CStatd|CUnique); + tvc->callback = NULL; + tvc->states &= ~(CStatd | CUnique); ReleaseWriteLock(&afs_xcbhash); - if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (tvc); /* if it (could be) a directory */ + if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(tvc); /* if it (could be) a directory */ ReleaseWriteLock(&tvc->lock); ObtainReadLock(&afs_xvcache); AFS_FAST_RELE(tvc); ReleaseReadLock(&afs_xvcache); - return (struct vcache *) 0; + return NULL; } - + ObtainWriteLock(&afs_xcbhash, 468); if (origCBs == afs_allCBs) { tvc->states |= CTruth; tvc->callback = serverp; - if (CallBack.ExpirationTime != 0) { - tvc->cbExpires = CallBack.ExpirationTime+start; + if (CallBack.ExpirationTime != 0) { + tvc->cbExpires = CallBack.ExpirationTime + start; tvc->states |= CStatd; tvc->states &= ~CBulkFetching; afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp); } else if (tvc->states & CRO) { /* adapt gives us an hour. */ - tvc->cbExpires = 3600+osi_Time(); /*XXX*/ - tvc->states |= CStatd; + tvc->cbExpires = 3600 + osi_Time(); + /*XXX*/ tvc->states |= CStatd; tvc->states &= ~CBulkFetching; afs_QueueCallback(tvc, CBHash(3600), tvolp); } } else { afs_DequeueCallback(tvc); - tvc->callback = (struct server *)0; + tvc->callback = NULL; tvc->states &= ~(CStatd | CUnique); - if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (tvc); /* if it (could be) a directory */ + if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(tvc); /* if it (could be) a directory */ } ReleaseWriteLock(&afs_xcbhash); afs_ProcessFS(tvc, &OutStatus, areq); - + ReleaseWriteLock(&tvc->lock); return tvc; } @@ -2182,100 +2324,92 @@ struct vcache *afs_GetRootVCache(struct VenusFid *afid, /* - * must be called with avc write-locked - * don't absolutely have to invalidate the hint unless the dv has + * must be called with avc write-locked + * don't absolutely have to invalidate the hint unless the dv has * changed, but be sure to get it right else there will be consistency bugs. */ -afs_int32 afs_FetchStatus(struct vcache *avc, struct VenusFid *afid, - struct vrequest *areq, struct AFSFetchStatus *Outsp) +afs_int32 +afs_FetchStatus(struct vcache * avc, struct VenusFid * afid, + struct vrequest * areq, struct AFSFetchStatus * Outsp) { - int code; - afs_uint32 start; - register struct conn *tc; - struct AFSCallBack CallBack; - struct AFSVolSync tsync; - struct volume* volp; - XSTATS_DECLS - + int code; + afs_uint32 start = 0; + register struct conn *tc; + struct AFSCallBack CallBack; + struct AFSVolSync tsync; + struct volume *volp; + XSTATS_DECLS do { tc = afs_Conn(afid, areq, SHARED_LOCK); - avc->quick.stamp = 0; avc->h1.dchint = NULL; /* invalidate hints */ + avc->quick.stamp = 0; + avc->h1.dchint = NULL; /* invalidate hints */ if (tc) { avc->callback = tc->srvr->server; start = osi_Time(); XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS); -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = RXAFS_FetchStatus(tc->id, - (struct AFSFid *) &afid->Fid, - Outsp, &CallBack, &tsync); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + code = + RXAFS_FetchStatus(tc->id, (struct AFSFid *)&afid->Fid, Outsp, + &CallBack, &tsync); + RX_AFS_GLOCK(); XSTATS_END_TIME; + } else + code = -1; + } while (afs_Analyze + (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS, + SHARED_LOCK, NULL)); + + if (!code) { + afs_ProcessFS(avc, Outsp, areq); + volp = afs_GetVolume(afid, areq, READ_LOCK); + ObtainWriteLock(&afs_xcbhash, 469); + avc->states |= CTruth; + if (avc->callback /* check for race */ ) { + if (CallBack.ExpirationTime != 0) { + avc->cbExpires = CallBack.ExpirationTime + start; + avc->states |= CStatd; + avc->states &= ~CBulkFetching; + afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp); + } else if (avc->states & CRO) { /* ordinary callback on a read-only volume -- AFS 3.2 style */ + avc->cbExpires = 3600 + start; + avc->states |= CStatd; + avc->states &= ~CBulkFetching; + afs_QueueCallback(avc, CBHash(3600), volp); + } else { + afs_DequeueCallback(avc); + avc->callback = NULL; + avc->states &= ~(CStatd | CUnique); + if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(avc); /* if it (could be) a directory */ + } + } else { + afs_DequeueCallback(avc); + avc->callback = NULL; + avc->states &= ~(CStatd | CUnique); + if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(avc); /* if it (could be) a directory */ } - else code = -1; - } while - (afs_Analyze(tc, code, afid, areq, - AFS_STATS_FS_RPCIDX_FETCHSTATUS, - SHARED_LOCK, (struct cell *)0)); - -if (!code) { - afs_ProcessFS(avc, Outsp, areq); - volp = afs_GetVolume(afid, areq, READ_LOCK); - ObtainWriteLock(&afs_xcbhash, 469); - avc->states |= CTruth; - if (avc->callback /* check for race */) { - if (CallBack.ExpirationTime != 0) { - avc->cbExpires = CallBack.ExpirationTime+start; - avc->states |= CStatd; - avc->states &= ~CBulkFetching; - afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp); - } - else if (avc->states & CRO) - { /* ordinary callback on a read-only volume -- AFS 3.2 style */ - avc->cbExpires = 3600+start; - avc->states |= CStatd; - avc->states &= ~CBulkFetching; - afs_QueueCallback(avc, CBHash(3600), volp); - } - else { - afs_DequeueCallback(avc); - avc->callback = (struct server *)0; - avc->states &= ~(CStatd|CUnique); - if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (avc); /* if it (could be) a directory */ - } - } - else { - afs_DequeueCallback(avc); - avc->callback = (struct server *)0; - avc->states &= ~(CStatd|CUnique); - if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (avc); /* if it (could be) a directory */ - } - ReleaseWriteLock(&afs_xcbhash); - if ( volp ) - afs_PutVolume(volp, READ_LOCK); -} -else { /* used to undo the local callback, but that's too extreme. - * There are plenty of good reasons that fetchstatus might return - * an error, such as EPERM. If we have the vnode cached, statd, - * with callback, might as well keep track of the fact that we - * don't have access... - */ - if (code == EPERM || code == EACCES) { - struct axscache *ac; - if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid))) - ac->axess = 0; - else /* not found, add a new one if possible */ - afs_AddAxs(avc->Access, areq->uid, 0); - } -} -return code; + ReleaseWriteLock(&afs_xcbhash); + if (volp) + afs_PutVolume(volp, READ_LOCK); + } else { + /* used to undo the local callback, but that's too extreme. + * There are plenty of good reasons that fetchstatus might return + * an error, such as EPERM. If we have the vnode cached, statd, + * with callback, might as well keep track of the fact that we + * don't have access... + */ + if (code == EPERM || code == EACCES) { + struct axscache *ac; + if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid))) + ac->axess = 0; + else /* not found, add a new one if possible */ + afs_AddAxs(avc->Access, areq->uid, 0); + } + } + return code; } #if 0 @@ -2296,16 +2430,12 @@ return code; * Nothing interesting. */ void -afs_StuffVcache(afid, OutStatus, CallBack, tc, areq) - register struct VenusFid *afid; - struct AFSFetchStatus *OutStatus; - struct AFSCallBack *CallBack; - register struct conn *tc; - struct vrequest *areq; - -{ /*afs_StuffVcache*/ - - register afs_int32 code, i, newvcache=0; +afs_StuffVcache(register struct VenusFid *afid, + struct AFSFetchStatus *OutStatus, + struct AFSCallBack *CallBack, register struct conn *tc, + struct vrequest *areq) +{ + register afs_int32 code, i, newvcache = 0; register struct vcache *tvc; struct AFSVolSync tsync; struct volume *tvp; @@ -2318,48 +2448,52 @@ afs_StuffVcache(afid, OutStatus, CallBack, tc, areq) #endif loop: - ObtainSharedLock(&afs_xvcache,8); + ObtainSharedLock(&afs_xvcache, 8); - tvc = afs_FindVCache(afid, 0, 0, &retry, DO_VLRU /* no stats */); + tvc = afs_FindVCache(afid, &retry, DO_VLRU /* no stats */ ); if (tvc && retry) { #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) ReleaseSharedLock(&afs_xvcache); spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD); goto loop; #endif - } + } if (!tvc) { /* no cache entry, better grab one */ - UpgradeSToWLock(&afs_xvcache,25); - tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK); + UpgradeSToWLock(&afs_xvcache, 25); + tvc = afs_NewVCache(afid, NULL); newvcache = 1; ConvertWToSLock(&afs_xvcache); } ReleaseSharedLock(&afs_xvcache); - ObtainWriteLock(&tvc->lock,58); + ObtainWriteLock(&tvc->lock, 58); tvc->states &= ~CStatd; - if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (tvc); /* if it (could be) a directory */ + if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(tvc); /* if it (could be) a directory */ /* Is it always appropriate to throw away all the access rights? */ afs_FreeAllAxs(&(tvc->Access)); - /*Copy useful per-volume info*/ - tvp = afs_GetVolume(afid, areq, READ_LOCK); + /*Copy useful per-volume info */ + tvp = afs_GetVolume(afid, areq, READ_LOCK); if (tvp) { - if (newvcache && (tvp->states & VForeign)) tvc->states |= CForeign; - if (tvp->states & VRO) tvc->states |= CRO; - if (tvp->states & VBackup) tvc->states |= CBackup; + if (newvcache && (tvp->states & VForeign)) + tvc->states |= CForeign; + if (tvp->states & VRO) + tvc->states |= CRO; + if (tvp->states & VBackup) + tvc->states |= CBackup; /* * Now, copy ".." entry back out of volume structure, if * necessary */ - if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) { - if (!tvc->mvid) tvc->mvid = - (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid)); + if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) { + if (!tvc->mvid) + tvc->mvid = (struct VenusFid *) + osi_AllocSmallSpace(sizeof(struct VenusFid)); *tvc->mvid = tvp->dotdot; } } @@ -2368,55 +2502,53 @@ afs_StuffVcache(afid, OutStatus, CallBack, tc, areq) afs_ProcessFS(tvc, OutStatus, areq); tvc->callback = tc->srvr->server; - /* we use osi_Time twice below. Ideally, we would use the time at which + /* we use osi_Time twice below. Ideally, we would use the time at which * the FetchStatus call began, instead, but we don't have it here. So we - * make do with "now". In the CRO case, it doesn't really matter. In - * the other case, we hope that the difference between "now" and when the + * make do with "now". In the CRO case, it doesn't really matter. In + * the other case, we hope that the difference between "now" and when the * call actually began execution on the server won't be larger than the - * padding which the server keeps. Subtract 1 second anyway, to be on + * padding which the server keeps. Subtract 1 second anyway, to be on * the safe side. Can't subtract more because we don't know how big * ExpirationTime is. Possible consistency problems may arise if the call * timeout period becomes longer than the server's expiration padding. */ ObtainWriteLock(&afs_xcbhash, 470); if (CallBack->ExpirationTime != 0) { - tvc->cbExpires = CallBack->ExpirationTime+osi_Time()-1; + tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1; tvc->states |= CStatd; tvc->states &= ~CBulkFetching; afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp); - } - else if (tvc->states & CRO) { - /* old-fashioned AFS 3.2 style */ - tvc->cbExpires = 3600+osi_Time(); /*XXX*/ - tvc->states |= CStatd; - tvc->states &= ~CBulkFetching; - afs_QueueCallback(tvc, CBHash(3600), tvp); - } - else { - afs_DequeueCallback(tvc); - tvc->callback = (struct server *)0; - tvc->states &= ~(CStatd|CUnique); - if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) - osi_dnlc_purgedp (tvc); /* if it (could be) a directory */ + } else if (tvc->states & CRO) { + /* old-fashioned AFS 3.2 style */ + tvc->cbExpires = 3600 + osi_Time(); + /*XXX*/ tvc->states |= CStatd; + tvc->states &= ~CBulkFetching; + afs_QueueCallback(tvc, CBHash(3600), tvp); + } else { + afs_DequeueCallback(tvc); + tvc->callback = NULL; + tvc->states &= ~(CStatd | CUnique); + if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1)) + osi_dnlc_purgedp(tvc); /* if it (could be) a directory */ } ReleaseWriteLock(&afs_xcbhash); - if ( tvp ) + if (tvp) afs_PutVolume(tvp, READ_LOCK); - + /* look in per-pag cache */ - if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid))) - ac->axess = OutStatus->CallerAccess; /* substitute pags */ - else /* not found, add a new one if possible */ - afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess); + if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid))) + ac->axess = OutStatus->CallerAccess; /* substitute pags */ + else /* not found, add a new one if possible */ + afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess); ReleaseWriteLock(&tvc->lock); afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc, - ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32, tvc->cbExpires, - ICL_TYPE_INT32, tvc->cbExpires-osi_Time()); + ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32, + tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time()); /* * Release ref count... hope this guy stays around... */ - afs_PutVCache(tvc, WRITE_LOCK); -} /*afs_StuffVcache*/ + afs_PutVCache(tvc); +} /*afs_StuffVcache */ #endif /* @@ -2432,11 +2564,8 @@ afs_StuffVcache(afid, OutStatus, CallBack, tc, areq) * Nothing interesting. */ void -afs_PutVCache(avc, locktype) - register struct vcache *avc; - afs_int32 locktype; -{ /*afs_PutVCache*/ - +afs_PutVCache(register struct vcache *avc) +{ AFS_STATCNT(afs_PutVCache); /* * Can we use a read lock here? @@ -2444,7 +2573,7 @@ afs_PutVCache(avc, locktype) ObtainReadLock(&afs_xvcache); AFS_FAST_RELE(avc); ReleaseReadLock(&afs_xvcache); -} /*afs_PutVCache*/ +} /*afs_PutVCache */ /* * afs_FindVCache @@ -2454,7 +2583,7 @@ afs_PutVCache(avc, locktype) * * Parameters: * afid : Pointer to the fid whose cache entry we desire. - * retry: (SGI-specific) tell the caller to drop the lock on xvcache, + * retry: (SGI-specific) tell the caller to drop the lock on xvcache, * unlock the vnode, and try again. * flags: bit 1 to specify whether to compute hit statistics. Not * set if FindVCache is called as part of internal bookkeeping. @@ -2465,8 +2594,8 @@ afs_PutVCache(avc, locktype) * must be shared-- we upgrade it here. */ -struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit, - afs_int32 locktype, afs_int32 *retry, afs_int32 flag) +struct vcache * +afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag) { register struct vcache *tvc; @@ -2475,78 +2604,80 @@ struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit, AFS_STATCNT(afs_FindVCache); i = VCHash(afid); - for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { - if (FidMatches(afid, tvc)) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { + if (FidMatches(afid, tvc)) { #ifdef AFS_OSF_ENV - /* Grab this vnode, possibly reactivating from the free list */ + /* Grab this vnode, possibly reactivating from the free list */ int vg; AFS_GUNLOCK(); - vg = vget(AFSTOV(tvc)); + vg = vget(AFSTOV(tvc)); AFS_GLOCK(); if (vg) - continue; -#endif /* AFS_OSF_ENV */ + continue; +#endif /* AFS_OSF_ENV */ break; } } /* should I have a read lock on the vnode here? */ if (tvc) { - if (retry) *retry = 0; + if (retry) + *retry = 0; #if !defined(AFS_OSF_ENV) - osi_vnhold(tvc, retry); /* already held, above */ - if (retry && *retry) - return 0; + osi_vnhold(tvc, retry); /* already held, above */ + if (retry && *retry) + return 0; #endif /* * only move to front of vlru if we have proper vcache locking) */ if (flag & DO_VLRU) { - if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("FindVC VLRU inconsistent1"); - } - if (tvc->vlruq.next->prev != &(tvc->vlruq)) { - refpanic ("FindVC VLRU inconsistent1"); - } - if (tvc->vlruq.prev->next != &(tvc->vlruq)) { - refpanic ("FindVC VLRU inconsistent2"); - } - UpgradeSToWLock(&afs_xvcache,26); + if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { + refpanic("FindVC VLRU inconsistent1"); + } + if (tvc->vlruq.next->prev != &(tvc->vlruq)) { + refpanic("FindVC VLRU inconsistent1"); + } + if (tvc->vlruq.prev->next != &(tvc->vlruq)) { + refpanic("FindVC VLRU inconsistent2"); + } + UpgradeSToWLock(&afs_xvcache, 26); QRemove(&tvc->vlruq); QAdd(&VLRU, &tvc->vlruq); ConvertWToSLock(&afs_xvcache); - if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("FindVC VLRU inconsistent1"); - } - if (tvc->vlruq.next->prev != &(tvc->vlruq)) { - refpanic ("FindVC VLRU inconsistent2"); - } - if (tvc->vlruq.prev->next != &(tvc->vlruq)) { - refpanic ("FindVC VLRU inconsistent3"); - } + if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { + refpanic("FindVC VLRU inconsistent1"); + } + if (tvc->vlruq.next->prev != &(tvc->vlruq)) { + refpanic("FindVC VLRU inconsistent2"); + } + if (tvc->vlruq.prev->next != &(tvc->vlruq)) { + refpanic("FindVC VLRU inconsistent3"); + } } vcachegen++; - } + } if (flag & DO_STATS) { - if (tvc) afs_stats_cmperf.vcacheHits++; - else afs_stats_cmperf.vcacheMisses++; - if (afs_IsPrimaryCellNum(afid->Cell)) - afs_stats_cmperf.vlocalAccesses++; - else - afs_stats_cmperf.vremoteAccesses++; + if (tvc) + afs_stats_cmperf.vcacheHits++; + else + afs_stats_cmperf.vcacheMisses++; + if (afs_IsPrimaryCellNum(afid->Cell)) + afs_stats_cmperf.vlocalAccesses++; + else + afs_stats_cmperf.vremoteAccesses++; } - #ifdef AFS_LINUX22_ENV if (tvc && (tvc->states & CStatd)) - vcache2inode(tvc); /* mainly to reset i_nlink */ + vcache2inode(tvc); /* mainly to reset i_nlink */ #endif #ifdef AFS_DARWIN_ENV if (tvc) - osi_VM_Setup(tvc, 0); + osi_VM_Setup(tvc, 0); #endif return tvc; -} /*afs_FindVCache*/ +} /*afs_FindVCache */ /* * afs_NFSFindVCache @@ -2558,7 +2689,7 @@ struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit, * Parameters: * avcp : Fill in pointer if we found one and only one. * afid : Pointer to the fid whose cache entry we desire. - * retry: (SGI-specific) tell the caller to drop the lock on xvcache, + * retry: (SGI-specific) tell the caller to drop the lock on xvcache, * unlock the vnode, and try again. * flags: bit 1 to specify whether to compute hit statistics. Not * set if FindVCache is called as part of internal bookkeeping. @@ -2572,45 +2703,43 @@ struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit, * number of matches found. */ -int afs_duplicate_nfs_fids=0; - -afs_int32 afs_NFSFindVCache(avcp, afid, lockit) - struct vcache **avcp; - struct VenusFid *afid; - afs_int32 lockit; -{ /*afs_FindVCache*/ +int afs_duplicate_nfs_fids = 0; +afs_int32 +afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid) +{ register struct vcache *tvc; afs_int32 i; - afs_int32 retry = 0; afs_int32 count = 0; struct vcache *found_tvc = NULL; AFS_STATCNT(afs_FindVCache); - loop: +#if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) + loop: +#endif - ObtainSharedLock(&afs_xvcache,331); + ObtainSharedLock(&afs_xvcache, 331); i = VCHash(afid); - for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { /* Match only on what we have.... */ - if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode) + if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode) && (tvc->fid.Fid.Volume == afid->Fid.Volume) && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique) && (tvc->fid.Cell == afid->Cell)) { #ifdef AFS_OSF_ENV - /* Grab this vnode, possibly reactivating from the free list */ + /* Grab this vnode, possibly reactivating from the free list */ int vg; AFS_GUNLOCK(); - vg = vget(AFSTOV(tvc)); + vg = vget(AFSTOV(tvc)); AFS_GLOCK(); if (vg) { /* This vnode no longer exists. */ - continue; + continue; } -#endif /* AFS_OSF_ENV */ - count ++; +#endif /* AFS_OSF_ENV */ + count++; if (found_tvc) { /* Duplicates */ #ifdef AFS_OSF_ENV @@ -2630,60 +2759,63 @@ afs_int32 afs_NFSFindVCache(avcp, afid, lockit) /* should I have a read lock on the vnode here? */ if (tvc) { #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV) - osi_vnhold(tvc, &retry); + afs_int32 retry = 0; + osi_vnhold(tvc, &retry); if (retry) { count = 0; - found_tvc = (struct vcache*)0; + found_tvc = (struct vcache *)0; ReleaseSharedLock(&afs_xvcache); spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD); goto loop; } #else #if !defined(AFS_OSF_ENV) - osi_vnhold(tvc, (int*)0); /* already held, above */ + osi_vnhold(tvc, (int *)0); /* already held, above */ #endif #endif /* * We obtained the xvcache lock above. */ if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("FindVC VLRU inconsistent1"); + refpanic("FindVC VLRU inconsistent1"); } if (tvc->vlruq.next->prev != &(tvc->vlruq)) { - refpanic ("FindVC VLRU inconsistent1"); + refpanic("FindVC VLRU inconsistent1"); } if (tvc->vlruq.prev->next != &(tvc->vlruq)) { - refpanic ("FindVC VLRU inconsistent2"); + refpanic("FindVC VLRU inconsistent2"); } - UpgradeSToWLock(&afs_xvcache,568); + UpgradeSToWLock(&afs_xvcache, 568); QRemove(&tvc->vlruq); QAdd(&VLRU, &tvc->vlruq); ConvertWToSLock(&afs_xvcache); if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) { - refpanic ("FindVC VLRU inconsistent1"); + refpanic("FindVC VLRU inconsistent1"); } if (tvc->vlruq.next->prev != &(tvc->vlruq)) { - refpanic ("FindVC VLRU inconsistent2"); + refpanic("FindVC VLRU inconsistent2"); } if (tvc->vlruq.prev->next != &(tvc->vlruq)) { - refpanic ("FindVC VLRU inconsistent3"); + refpanic("FindVC VLRU inconsistent3"); } } vcachegen++; - if (tvc) afs_stats_cmperf.vcacheHits++; - else afs_stats_cmperf.vcacheMisses++; + if (tvc) + afs_stats_cmperf.vcacheHits++; + else + afs_stats_cmperf.vcacheMisses++; if (afs_IsPrimaryCellNum(afid->Cell)) - afs_stats_cmperf.vlocalAccesses++; + afs_stats_cmperf.vlocalAccesses++; else - afs_stats_cmperf.vremoteAccesses++; + afs_stats_cmperf.vremoteAccesses++; - *avcp = tvc; /* May be null */ + *avcp = tvc; /* May be null */ ReleaseSharedLock(&afs_xvcache); return (tvc ? 1 : 0); -} /*afs_NFSFindVCache*/ +} /*afs_NFSFindVCache */ @@ -2693,23 +2825,24 @@ afs_int32 afs_NFSFindVCache(avcp, afid, lockit) * * Initialize vcache related variables */ -void afs_vcacheInit(int astatSize) +void +afs_vcacheInit(int astatSize) { register struct vcache *tvp; int i; #if defined(AFS_OSF_ENV) if (!afs_maxvcount) { #if defined(AFS_OSF30_ENV) - afs_maxvcount = max_vnodes/2; /* limit ourselves to half the total */ + afs_maxvcount = max_vnodes / 2; /* limit ourselves to half the total */ #else - afs_maxvcount = nvnode/2; /* limit ourselves to half the total */ -#endif - if (astatSize < afs_maxvcount) { - afs_maxvcount = astatSize; - } + afs_maxvcount = nvnode / 2; /* limit ourselves to half the total */ +#endif + if (astatSize < afs_maxvcount) { + afs_maxvcount = astatSize; + } } -#else /* AFS_OSF_ENV */ - freeVCList = (struct vcache *)0; +#else /* AFS_OSF_ENV */ + freeVCList = NULL; #endif RWLOCK_INIT(&afs_xvcache, "afs_xvcache"); @@ -2717,29 +2850,30 @@ void afs_vcacheInit(int astatSize) #if !defined(AFS_OSF_ENV) /* Allocate and thread the struct vcache entries */ - tvp = (struct vcache *) afs_osi_Alloc(astatSize * sizeof(struct vcache)); - memset((char *)tvp, 0, sizeof(struct vcache)*astatSize); + tvp = (struct vcache *)afs_osi_Alloc(astatSize * sizeof(struct vcache)); + memset((char *)tvp, 0, sizeof(struct vcache) * astatSize); Initial_freeVCList = tvp; freeVCList = &(tvp[0]); - for(i=0; i < astatSize-1; i++) { - tvp[i].nextfree = &(tvp[i+1]); - } - tvp[astatSize-1].nextfree = (struct vcache *) 0; -#ifdef AFS_AIX32_ENV - pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */ + for (i = 0; i < astatSize - 1; i++) { + tvp[i].nextfree = &(tvp[i + 1]); + } + tvp[astatSize - 1].nextfree = NULL; +#ifdef KERNEL_HAVE_PIN + pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */ #endif #endif #if defined(AFS_SGI_ENV) - for(i=0; i < astatSize; i++) { + for (i = 0; i < astatSize; i++) { char name[METER_NAMSZ]; struct vcache *tvc = &tvp[i]; tvc->v.v_number = ++afsvnumbers; tvc->vc_rwlockid = OSI_NO_LOCKID; - initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number)); + initnsema(&tvc->vc_rwlock, 1, + makesname(name, "vrw", tvc->v.v_number)); #ifndef AFS_SGI53_ENV initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number)); #endif @@ -2758,7 +2892,8 @@ void afs_vcacheInit(int astatSize) * shutdown_vcache * */ -void shutdown_vcache(void) +void +shutdown_vcache(void) { int i; struct afs_cbr *tsp, *nsp; @@ -2767,12 +2902,6 @@ void shutdown_vcache(void) * free vcache entries and all the vcache entries are active ones then we allocate * an additional one - admittedly we almost never had that occur. */ -#if !defined(AFS_OSF_ENV) - afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache)); -#endif -#ifdef AFS_AIX32_ENV - unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache)); -#endif { register struct afs_q *tq, *uq; @@ -2782,24 +2911,24 @@ void shutdown_vcache(void) uq = QPrev(tq); if (tvc->mvid) { osi_FreeSmallSpace(tvc->mvid); - tvc->mvid = (struct VenusFid*)0; + tvc->mvid = (struct VenusFid *)0; } #ifdef AFS_AIX_ENV aix_gnode_rele(AFSTOV(tvc)); #endif if (tvc->linkData) { - afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1); + afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1); tvc->linkData = 0; } } - /* - * Also free the remaining ones in the Cache + /* + * Also free the remaining ones in the Cache */ - for (i=0; i < VCSIZE; i++) { + for (i = 0; i < VCSIZE; i++) { for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { if (tvc->mvid) { osi_FreeSmallSpace(tvc->mvid); - tvc->mvid = (struct VenusFid*)0; + tvc->mvid = (struct VenusFid *)0; } #ifdef AFS_AIX_ENV if (tvc->v.v_gnode) @@ -2810,7 +2939,8 @@ void shutdown_vcache(void) vms_delete(tvc->segid); AFS_GLOCK(); tvc->segid = tvc->vmh = NULL; - if (VREFCOUNT(tvc)) osi_Panic("flushVcache: vm race"); + if (VREFCOUNT(tvc)) + osi_Panic("flushVcache: vm race"); } if (tvc->credp) { crfree(tvc->credp); @@ -2825,7 +2955,7 @@ void shutdown_vcache(void) } #endif if (tvc->linkData) { - afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1); + afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1); tvc->linkData = 0; } @@ -2837,12 +2967,18 @@ void shutdown_vcache(void) /* * Free any leftover callback queue */ - for (tsp = afs_cbrSpace; tsp; tsp = nsp ) { + for (tsp = afs_cbrSpace; tsp; tsp = nsp) { nsp = tsp->next; afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr)); } afs_cbrSpace = 0; +#if !defined(AFS_OSF_ENV) + afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache)); +#endif +#ifdef KERNEL_HAVE_PIN + unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache)); +#endif #if !defined(AFS_OSF_ENV) freeVCList = Initial_freeVCList = 0; #endif diff --git a/src/afs/afs_volume.c b/src/afs/afs_volume.c index 45734c716..dc5321645 100644 --- a/src/afs/afs_volume.c +++ b/src/afs/afs_volume.c @@ -16,12 +16,13 @@ * afs_FindVolume */ #include -#include "../afs/param.h" +#include "afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_volume.c,v 1.1.1.13 2003/07/30 17:08:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/afs/afs_volume.c,v 1.26 2003/08/27 21:43:16 rees Exp $"); -#include "../afs/stds.h" -#include "../afs/sysincludes.h" /* Standard vendor system headers */ +#include "afs/stds.h" +#include "afs/sysincludes.h" /* Standard vendor system headers */ #if !defined(UKERNEL) #if !defined(AFS_LINUX20_ENV) @@ -30,15 +31,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_volume.c,v 1.1.1.13 2003/07/30 #include #ifdef AFS_SGI62_ENV -#include "../h/hashing.h" +#include "h/hashing.h" #endif #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV) #include #endif /* ! AFS_HPUX110_ENV */ #endif /* !defined(UKERNEL) */ -#include "../afs/afsincludes.h" /* Afs-based standard headers */ -#include "../afs/afs_stats.h" /* afs statistics */ +#include "afsincludes.h" /* Afs-based standard headers */ +#include "afs/afs_stats.h" /* afs statistics */ #if defined(AFS_SUN56_ENV) #include @@ -49,14 +50,6 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_volume.c,v 1.1.1.13 2003/07/30 #include #endif -/* Imported variables */ -extern afs_rwlock_t afs_xserver; -extern afs_rwlock_t afs_xsrvAddr; -extern afs_rwlock_t afs_xvcache; -extern afs_rwlock_t afs_xcbhash; -extern struct srvAddr *afs_srvAddrs[NSERVERS]; /* Hashed by server's ip */ -extern int afs_totalSrvAddrs; - /* In case we don't have the vl error table yet. */ #ifndef ERROR_TABLE_BASE_VL #define ERROR_TABLE_BASE_VL (363520L) @@ -64,38 +57,39 @@ extern int afs_totalSrvAddrs; #endif /* vlserver error base define */ /* Exported variables */ -ino_t volumeInode; /*Inode for VolumeItems file*/ -afs_rwlock_t afs_xvolume; /* allocation lock for volumes */ +ino_t volumeInode; /*Inode for VolumeItems file */ +afs_rwlock_t afs_xvolume; /* allocation lock for volumes */ struct volume *afs_freeVolList; struct volume *afs_volumes[NVOLS]; -afs_int32 afs_volCounter = 1; /* for allocating volume indices */ +afs_int32 afs_volCounter = 1; /* for allocating volume indices */ afs_int32 fvTable[NFENTRIES]; /* Forward declarations */ -static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood, - struct vrequest *areq, afs_int32 locktype); +static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, + int agood, struct vrequest *areq, + afs_int32 locktype); static struct volume *afs_NewDynrootVolume(struct VenusFid *fid); -static inVolList(); +static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID, + afs_int32 * cID); /* Convert a volume name to a #; return 0 if can't parse as a number */ -static int afs_vtoi(aname) - register char *aname; - +static int +afs_vtoi(register char *aname) { register afs_int32 temp; register int tc; temp = 0; AFS_STATCNT(afs_vtoi); - while(tc = *aname++) { - if (tc > '9' || tc < '0') - return 0; /* invalid name */ + while ((tc = *aname++)) { + if (tc > '9' || tc < '0') + return 0; /* invalid name */ temp *= 10; temp += tc - '0'; } return temp; -} /*afs_vtoi*/ +} /*afs_vtoi */ /* @@ -110,8 +104,8 @@ afs_int32 afs_FVIndex = -1; /* UFS specific version of afs_GetVolSlot */ -struct volume *afs_UFSGetVolSlot() - +struct volume * +afs_UFSGetVolSlot(void) { register struct volume *tv, **lv; struct osi_file *tfile; @@ -125,11 +119,11 @@ struct volume *afs_UFSGetVolSlot() bestTime = 0x7fffffff; bestVp = 0; bestLp = 0; - for (i=0;inext, tv = *lv) { - if (tv->refCount == 0) { /* is this one available? */ - if (tv->accessTime < bestTime) { /* best one available? */ + if (tv->refCount == 0) { /* is this one available? */ + if (tv->accessTime < bestTime) { /* best one available? */ bestTime = tv->accessTime; bestLp = lv; bestVp = tv; @@ -142,25 +136,25 @@ struct volume *afs_UFSGetVolSlot() tv = bestVp; *bestLp = tv->next; if (tv->name) - afs_osi_Free(tv->name, strlen(tv->name)+1); - tv->name = (char *) 0; + afs_osi_Free(tv->name, strlen(tv->name) + 1); + tv->name = NULL; /* now write out volume structure to file */ if (tv->vtix < 0) { tv->vtix = afs_volCounter++; /* now put on hash chain */ i = FVHash(tv->cell, tv->volume); staticFVolume.next = fvTable[i]; - fvTable[i]=tv->vtix; - } - else { + fvTable[i] = tv->vtix; + } else { /* * Haul the guy in from disk so we don't overwrite hash table * next chain */ if (afs_FVIndex != tv->vtix) { tfile = osi_UFSOpen(volumeInode); - code = afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix, - &staticFVolume, sizeof(struct fvolume)); + code = + afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix, + &staticFVolume, sizeof(struct fvolume)); if (code != sizeof(struct fvolume)) osi_Panic("read volumeinfo"); osi_UFSClose(tfile); @@ -175,74 +169,71 @@ struct volume *afs_UFSGetVolSlot() staticFVolume.rootVnode = tv->rootVnode; staticFVolume.rootUnique = tv->rootUnique; tfile = osi_UFSOpen(volumeInode); - code = afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex, - &staticFVolume, sizeof(struct fvolume)); + code = + afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex, + &staticFVolume, sizeof(struct fvolume)); if (code != sizeof(struct fvolume)) osi_Panic("write volumeinfo"); - osi_UFSClose(tfile); - } - else { + osi_UFSClose(tfile); + } else { tv = afs_freeVolList; afs_freeVolList = tv->next; } return tv; -} /*afs_UFSGetVolSlot*/ - +} /*afs_UFSGetVolSlot */ -struct volume *afs_MemGetVolSlot() +struct volume * +afs_MemGetVolSlot(void) { - register struct volume *tv, **lv; - register afs_int32 i; - afs_int32 bestTime; - struct volume *bestVp, **bestLp; + register struct volume *tv; AFS_STATCNT(afs_MemGetVolSlot); if (!afs_freeVolList) { struct volume *newVp; - newVp = (struct volume *) afs_osi_Alloc(sizeof(struct volume)); + newVp = (struct volume *)afs_osi_Alloc(sizeof(struct volume)); - newVp->next = (struct volume *)0; + newVp->next = NULL; afs_freeVolList = newVp; } tv = afs_freeVolList; afs_freeVolList = tv->next; return tv; -} /*afs_MemGetVolSlot*/ +} /*afs_MemGetVolSlot */ /* afs_ResetVolumes() * Reset volume inforamation for all volume structs that * point to a speicific server. */ -void afs_ResetVolumes(struct server *srvp) +void +afs_ResetVolumes(struct server *srvp) { - int j, k; - struct volume *vp; - - /* Find any volumes residing on this server and flush their state */ - for (j=0; jnext) { - for (k=0; kserverHost[k] == srvp)) { - vp->serverHost[k] = 0; - afs_ResetVolumeInfo(vp); - break; - } + int j, k; + struct volume *vp; + + /* Find any volumes residing on this server and flush their state */ + for (j = 0; j < NVOLS; j++) { + for (vp = afs_volumes[j]; vp; vp = vp->next) { + for (k = 0; k < MAXHOSTS; k++) { + if (!srvp || (vp->serverHost[k] == srvp)) { + vp->serverHost[k] = 0; + afs_ResetVolumeInfo(vp); + break; + } + } } - } - } + } } /* reset volume name to volume id mapping cache */ -void afs_CheckVolumeNames(flags) - int flags; +void +afs_CheckVolumeNames(int flags) { - afs_int32 i,j; - extern int osi_dnlc_purge(); + afs_int32 i, j; struct volume *tv; unsigned int now; struct vcache *tvc; @@ -251,38 +242,38 @@ void afs_CheckVolumeNames(flags) nvols = 0; volumeID = cellID = NULL; - vsize=0; + vsize = 0; ObtainReadLock(&afs_xvolume); if (flags & AFS_VOLCHECK_EXPIRED) { /* * allocate space to hold the volumeIDs and cellIDs, only if * we will be invalidating the mountpoints later on */ - for (i=0; i< NVOLS; i++) - for (tv = afs_volumes[i]; tv; tv=tv->next) + for (i = 0; i < NVOLS; i++) + for (tv = afs_volumes[i]; tv; tv = tv->next) ++vsize; volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID)); - cellID = (volumeID) ? volumeID + vsize : 0; + cellID = (volumeID) ? volumeID + vsize : 0; } now = osi_Time(); - for (i=0;inext) { + for (i = 0; i < NVOLS; i++) { + for (tv = afs_volumes[i]; tv; tv = tv->next) { if (flags & AFS_VOLCHECK_EXPIRED) { - if ( ((tv->expireTime<(now+10)) && (tv->states & VRO)) || - (flags & AFS_VOLCHECK_FORCE)){ - afs_ResetVolumeInfo(tv); /* also resets status */ + if (((tv->expireTime < (now + 10)) && (tv->states & VRO)) + || (flags & AFS_VOLCHECK_FORCE)) { + afs_ResetVolumeInfo(tv); /* also resets status */ if (volumeID) { volumeID[nvols] = tv->volume; - cellID[nvols] = tv->cell; + cellID[nvols] = tv->cell; } ++nvols; continue; } } if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) { - for (j=0; jstatus[j] = not_busy; } @@ -294,31 +285,32 @@ void afs_CheckVolumeNames(flags) /* next ensure all mt points are re-evaluated */ if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) { ObtainReadLock(&afs_xvcache); - for(i=0;ihnext) { + for (i = 0; i < VCSIZE; i++) { + for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) { /* if the volume of "mvid" of the vcache entry is among the - * ones we found earlier, then we re-evaluate it. Also, if the - * force bit is set or we explicitly asked to reevaluate the - * mt-pts, we clean the cmvalid bit */ + * ones we found earlier, then we re-evaluate it. Also, if the + * force bit is set or we explicitly asked to reevaluate the + * mt-pts, we clean the cmvalid bit */ - if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) || - (tvc->mvid && - inVolList(tvc->mvid, nvols, volumeID, cellID))) + if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) + || (tvc->mvid + && inVolList(tvc->mvid, nvols, volumeID, cellID))) tvc->states &= ~CMValid; /* If the volume that this file belongs to was reset earlier, * then we should remove its callback. * Again, if forced, always do it. */ - if ((tvc->states & CRO) && - (inVolList(&tvc->fid, nvols, volumeID, cellID) || - (flags & AFS_VOLCHECK_FORCE))) { + if ((tvc->states & CRO) + && (inVolList(&tvc->fid, nvols, volumeID, cellID) + || (flags & AFS_VOLCHECK_FORCE))) { AFS_FAST_HOLD(tvc); ReleaseReadLock(&afs_xvcache); ObtainWriteLock(&afs_xcbhash, 485); + /* LOCKXXX: We aren't holding tvc write lock? */ afs_DequeueCallback(tvc); tvc->states &= ~CStatd; ReleaseWriteLock(&afs_xcbhash); @@ -332,27 +324,27 @@ void afs_CheckVolumeNames(flags) } } } - osi_dnlc_purge (); /* definitely overkill, but it's safer this way. */ + osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */ ReleaseReadLock(&afs_xvcache); } if (volumeID) afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID)); -} /*afs_CheckVolumeNames*/ +} /*afs_CheckVolumeNames */ -static inVolList(fid, nvols, vID, cID) - struct VenusFid *fid; - afs_int32 nvols, *vID, *cID; +static int +inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID, + afs_int32 * cID) { afs_int32 i; /* if no arrays present, be conservative and return true */ - if ( nvols && (!vID || !cID)) + if (nvols && (!vID || !cID)) return 1; - for (i=0; i< nvols; ++i) { + for (i = 0; i < nvols; ++i) { if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i]) return 1; } @@ -368,7 +360,8 @@ static inVolList(fid, nvols, vID, cID) * * Environment: Must be called with afs_xvolume unlocked. */ -struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype) +struct volume * +afs_FindVolume(struct VenusFid *afid, afs_int32 locktype) { struct volume *tv; afs_int32 i; @@ -377,17 +370,17 @@ struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype) return NULL; i = VHash(afid->Fid.Volume); - ObtainWriteLock(&afs_xvolume,106); - for (tv = afs_volumes[i]; tv; tv=tv->next) { + ObtainWriteLock(&afs_xvolume, 106); + for (tv = afs_volumes[i]; tv; tv = tv->next) { if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell && (tv->states & VRecheck) == 0) { tv->refCount++; break; - } + } } ReleaseWriteLock(&afs_xvolume); - return tv; /* NULL if we didn't find it */ -} /*afs_FindVolume*/ + return tv; /* NULL if we didn't find it */ +} /*afs_FindVolume */ @@ -395,10 +388,9 @@ struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype) * Note that areq may be null, in which case we don't bother to set any * request status information. */ -struct volume *afs_GetVolume(afid, areq, locktype) - struct vrequest *areq; - struct VenusFid *afid; - afs_int32 locktype; +struct volume * +afs_GetVolume(struct VenusFid *afid, struct vrequest *areq, + afs_int32 locktype) { struct volume *tv; char *bp, tbuf[CVBS]; @@ -406,42 +398,39 @@ struct volume *afs_GetVolume(afid, areq, locktype) tv = afs_FindVolume(afid, locktype); if (!tv) { - if (afs_IsDynrootFid(afid)) { - tv = afs_NewDynrootVolume(afid); - } else { - bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume); - tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype); - } + if (afs_IsDynrootFid(afid)) { + tv = afs_NewDynrootVolume(afid); + } else { + bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume); + tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype); + } } return tv; -} /*afs_GetVolume*/ +} /*afs_GetVolume */ -static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq) - char *aname; - char *ve; - afs_int32 volid, agood, type; - struct cell *tcell; - struct vrequest *areq; +static struct volume * +afs_SetupVolume(afs_int32 volid, char *aname, char *ve, struct cell *tcell, + afs_int32 agood, afs_int32 type, struct vrequest *areq) { struct volume *tv; struct vldbentry *ove = (struct vldbentry *)ve; struct nvldbentry *nve = (struct nvldbentry *)ve; struct uvldbentry *uve = (struct uvldbentry *)ve; - int whichType; /* which type of volume to look for */ - int i, j, err=0; + int whichType; /* which type of volume to look for */ + int i, j, err = 0; if (!volid) { - int len; + int len; /* special hint from file server to use vlserver */ len = strlen(aname); - if (len >= 8 && strcmp(aname+len-7, ".backup") == 0) + if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0) whichType = BACKVOL; - else if (len >= 10 && strcmp(aname+len-9, ".readonly")==0) + else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0) whichType = ROVOL; - else + else whichType = RWVOL; /* figure out which one we're really interested in (a set is returned) */ @@ -449,26 +438,24 @@ static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq if (volid == 0) { if (type == 2) { volid = uve->volumeId[whichType]; - } - else if (type == 1) { + } else if (type == 1) { volid = nve->volumeId[whichType]; - } - else { + } else { volid = ove->volumeId[whichType]; } } } - - ObtainWriteLock(&afs_xvolume,108); + + ObtainWriteLock(&afs_xvolume, 108); i = VHash(volid); - for (tv = afs_volumes[i]; tv; tv=tv->next) { + for (tv = afs_volumes[i]; tv; tv = tv->next) { if (tv->volume == volid && tv->cell == tcell->cellNum) { break; } } if (!tv) { - struct fvolume *tf=0; + struct fvolume *tf = 0; tv = afs_GetVolSlot(); memset((char *)tv, 0, sizeof(struct volume)); @@ -477,11 +464,13 @@ static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq tv->next = afs_volumes[i]; /* thread into list */ afs_volumes[i] = tv; tv->volume = volid; - for (j=fvTable[FVHash(tv->cell,volid)]; j!=0; j=tf->next) { + for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) { if (afs_FVIndex != j) { struct osi_file *tfile; tfile = osi_UFSOpen(volumeInode); - err = afs_osi_Read(tfile, sizeof(struct fvolume) * j, &staticFVolume, sizeof(struct fvolume)); + err = + afs_osi_Read(tfile, sizeof(struct fvolume) * j, + &staticFVolume, sizeof(struct fvolume)); if (err != sizeof(struct fvolume)) osi_Panic("read volumeinfo2"); osi_UFSClose(tfile); @@ -495,22 +484,21 @@ static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq tv->vtix = afs_FVIndex; tv->mtpoint = tf->mtpoint; tv->dotdot = tf->dotdot; - tv->rootVnode = tf->rootVnode; - tv->rootUnique = tf->rootUnique; + tv->rootVnode = tf->rootVnode; + tv->rootUnique = tf->rootUnique; } else { tv->vtix = -1; tv->rootVnode = tv->rootUnique = 0; } } tv->refCount++; - tv->states &= ~VRecheck; /* just checked it */ + tv->states &= ~VRecheck; /* just checked it */ tv->accessTime = osi_Time(); ReleaseWriteLock(&afs_xvolume); - ObtainWriteLock(&tv->lock,111); + ObtainWriteLock(&tv->lock, 111); if (type == 2) { InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq); - } - else if (type == 1) + } else if (type == 1) InstallNVolumeEntry(tv, nve, tcell->cellNum); else InstallVolumeEntry(tv, ove, tcell->cellNum); @@ -520,30 +508,27 @@ static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq strcpy(tv->name, aname); } } - for (i=0; istatus[i] = not_busy; + for (i = 0; i < NMAXNSERVERS; i++) { + tv->status[i] = not_busy; } ReleaseWriteLock(&tv->lock); return tv; } -struct volume *afs_GetVolumeByName(aname, acell, agood, areq, locktype) - struct vrequest *areq; - afs_int32 acell; - int agood; - register char *aname; - afs_int32 locktype; +struct volume * +afs_GetVolumeByName(register char *aname, afs_int32 acell, int agood, + struct vrequest *areq, afs_int32 locktype) { - afs_int32 i; - struct volume *tv; + afs_int32 i; + struct volume *tv; AFS_STATCNT(afs_GetVolumeByName); - ObtainWriteLock(&afs_xvolume,112); - for (i=0;inext) { - if (tv->name && !strcmp(aname,tv->name) && tv->cell == acell - && (tv->states&VRecheck) == 0) { + ObtainWriteLock(&afs_xvolume, 112); + for (i = 0; i < NVOLS; i++) { + for (tv = afs_volumes[i]; tv; tv = tv->next) { + if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell + && (tv->states & VRecheck) == 0) { tv->refCount++; ReleaseWriteLock(&afs_xvolume); return tv; @@ -553,38 +538,43 @@ struct volume *afs_GetVolumeByName(aname, acell, agood, areq, locktype) ReleaseWriteLock(&afs_xvolume); - tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype); - return(tv); + tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype); + return (tv); } -static struct volume *afs_NewDynrootVolume(struct VenusFid *fid) { +static struct volume * +afs_NewDynrootVolume(struct VenusFid *fid) +{ struct cell *tcell; struct volume *tv; - struct vldbentry tve; + struct vldbentry *tve; char *bp, tbuf[CVBS]; tcell = afs_GetCell(fid->Cell, READ_LOCK); if (!tcell) - return (struct volume *) 0; + return NULL; + tve = afs_osi_Alloc(sizeof(*tve)); if (!(tcell->states & CHasVolRef)) tcell->states |= CHasVolRef; bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume); - memset(&tve, 0, sizeof(tve)); - strcpy(tve.name, "local-dynroot"); - tve.volumeId[ROVOL] = fid->Fid.Volume; - tve.flags = VLF_ROEXISTS; + memset(tve, 0, sizeof(*tve)); + strcpy(tve->name, "local-dynroot"); + tve->volumeId[ROVOL] = fid->Fid.Volume; + tve->flags = VLF_ROEXISTS; - tv = afs_SetupVolume(0, bp, (char *) &tve, tcell, 0, 0, 0); + tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0); afs_PutCell(tcell, READ_LOCK); + afs_osi_Free(tve, sizeof(*tve)); return tv; } int lastnvcode; -static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood, - struct vrequest *areq, afs_int32 locktype) +static struct volume * +afs_NewVolumeByName(char *aname, afs_int32 acell, int agood, + struct vrequest *areq, afs_int32 locktype) { - afs_int32 code, i, type=0; + afs_int32 code, type = 0; struct volume *tv, *tv1; struct vldbentry *tve; struct nvldbentry *ntve; @@ -593,91 +583,70 @@ static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agoo char *tbuffer, *ve; struct conn *tconn; struct vrequest treq; - XSTATS_DECLS; if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */ - return (struct volume *) 0; + return NULL; tcell = afs_GetCell(acell, READ_LOCK); if (!tcell) { - return (struct volume *) 0; + return NULL; } /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */ - if (!areq) areq = &treq; + if (!areq) + areq = &treq; afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname, - ICL_TYPE_POINTER, aname); + ICL_TYPE_POINTER, aname); tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ); - tve = (struct vldbentry *) (tbuffer+1024); + tve = (struct vldbentry *)(tbuffer + 1024); ntve = (struct nvldbentry *)tve; utve = (struct uvldbentry *)tve; - afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */ + afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */ do { - tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, - tcell->cellNum, &treq, SHARED_LOCK); + tconn = + afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum, + &treq, SHARED_LOCK); if (tconn) { if (tconn->srvr->server->flags & SNO_LHOSTS) { type = 0; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); code = VL_GetEntryByNameO(tconn->id, aname, tve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); } else if (tconn->srvr->server->flags & SYES_LHOSTS) { type = 1; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); code = VL_GetEntryByNameN(tconn->id, aname, ntve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); } else { type = 2; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); code = VL_GetEntryByNameU(tconn->id, aname, utve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); if (!(tconn->srvr->server->flags & SVLSRV_UUID)) { if (code == RXGEN_OPCODE) { type = 1; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = VL_GetEntryByNameN(tconn->id, aname, ntve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + code = VL_GetEntryByNameN(tconn->id, aname, ntve); + RX_AFS_GLOCK(); if (code == RXGEN_OPCODE) { type = 0; tconn->srvr->server->flags |= SNO_LHOSTS; -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); code = VL_GetEntryByNameO(tconn->id, aname, tve); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GLOCK(); } else if (!code) tconn->srvr->server->flags |= SYES_LHOSTS; } else if (!code) - tconn->srvr->server->flags |= SVLSRV_UUID; + tconn->srvr->server->flags |= SVLSRV_UUID; } lastnvcode = code; } } else code = -1; - } while - (afs_Analyze(tconn, code, (struct VenusFid *) 0, &treq, - -1, /* no op code for this */ - SHARED_LOCK, tcell)); + } while (afs_Analyze(tconn, code, NULL, &treq, -1, /* no op code for this */ + SHARED_LOCK, tcell)); if (code) { /* If the client has yet to contact this cell and contact failed due @@ -689,8 +658,9 @@ static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agoo int i; struct server *sp; struct srvAddr *sap; - for (i=0; icellHosts[i]) == (struct server *) 0) break; + for (i = 0; i < MAXCELLHOSTS; i++) { + if ((sp = tcell->cellHosts[i]) == NULL) + break; for (sap = sp->addr; sap; sap = sap->next_sa) afs_MarkServerUpOrDown(sap, 0); } @@ -698,7 +668,7 @@ static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agoo afs_CopyError(&treq, areq); osi_FreeLargeSpace(tbuffer); afs_PutCell(tcell, READ_LOCK); - return (struct volume *) 0; + return NULL; } /* * Check to see if this cell has not yet referenced a volume. If @@ -709,8 +679,8 @@ static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agoo if (!(tcell->states & CHasVolRef)) { tcell->states |= CHasVolRef; afs_stats_cmperf.numCellsContacted++; - } /*First time a volume in this cell has been referenced*/ - + } + /*First time a volume in this cell has been referenced */ if (type == 2) ve = (char *)utve; else if (type == 1) @@ -718,24 +688,34 @@ static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agoo else ve = (char *)tve; tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq); - if ((agood == 2) && tv->roVol) { + if ((agood == 3) && tv->backVol) { + /* + * This means that very soon we'll ask for the BK volume so + * we'll prefetch it (well we did already.) + */ + tv1 = + afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, areq); + tv1->refCount--; + } + if ((agood >= 2) && tv->roVol) { /* * This means that very soon we'll ask for the RO volume so * we'll prefetch it (well we did already.) */ - tv1 = afs_SetupVolume(tv->roVol, (char *)0, ve, tcell, 0, type, areq); + tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq); tv1->refCount--; } osi_FreeLargeSpace(tbuffer); afs_PutCell(tcell, READ_LOCK); return tv; -} /*afs_NewVolumeByName*/ +} /*afs_NewVolumeByName */ /* call this with the volume structure locked; used for new-style vldb requests */ -void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell) +void +InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell) { register struct server *ts; struct cell *cellp; @@ -747,24 +727,23 @@ void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell) /* Determine the type of volume we want */ if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) { - mask = VLSF_RWVOL; - } - else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) { - mask = VLSF_ROVOL; - av->states |= VRO; - } - else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) { - /* backup always is on the same volume as parent */ - mask = VLSF_RWVOL; - av->states |= (VRO|VBackup); - } - else { - mask = 0; /* Can't find volume in vldb entry */ + mask = VLSF_RWVOL; + } else if ((ve->flags & VLF_ROEXISTS) + && (av->volume == ve->volumeId[ROVOL])) { + mask = VLSF_ROVOL; + av->states |= VRO; + } else if ((ve->flags & VLF_BACKEXISTS) + && (av->volume == ve->volumeId[BACKVOL])) { + /* backup always is on the same volume as parent */ + mask = VLSF_RWVOL; + av->states |= (VRO | VBackup); + } else { + mask = 0; /* Can't find volume in vldb entry */ } /* fill in volume types */ - av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0); - av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0); + av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0); + av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0); av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0); if (ve->flags & VLF_DFSFILESET) @@ -772,14 +751,25 @@ void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell) cellp = afs_GetCell(acell, 0); + /* This volume, av, is locked. Zero out the serverHosts[] array + * so that if afs_GetServer() decides to replace the server + * struct, we don't deadlock trying to afs_ResetVolumeInfo() + * this volume. + */ + for (j = 0; j < MAXHOSTS; j++) { + av->serverHost[j] = 0; + } + /* Step through the VLDB entry making sure each server listed is there */ - for (i=0,j=0; inServers; i++) { - if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) { - continue; /* wrong volume or don't use this volume */ + for (i = 0, j = 0; i < ve->nServers; i++) { + if (((ve->serverFlags[i] & mask) == 0) + || (ve->serverFlags[i] & VLSF_DONTUSE)) { + continue; /* wrong volume or don't use this volume */ } temp = htonl(ve->serverNumber[i]); - ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0); + ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, + (afsUUID *) 0, 0); av->serverHost[j] = ts; /* @@ -789,7 +779,7 @@ void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell) * follows later on it will find the server entry thus it will * simply return without setting any fields, so we set the * field ourselves below. - */ + */ if (!ts->cell) ts->cell = cellp; afs_PutServer(ts, WRITE_LOCK); @@ -799,10 +789,11 @@ void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell) av->serverHost[j++] = 0; } afs_SortServers(av->serverHost, MAXHOSTS); -} /*InstallVolumeEntry*/ +} /*InstallVolumeEntry */ -void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell) +void +InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell) { register struct server *ts; struct cell *cellp; @@ -814,24 +805,23 @@ void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell) /* Determine type of volume we want */ if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) { - mask = VLSF_RWVOL; - } - else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) { - mask = VLSF_ROVOL; - av->states |= VRO; - } - else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) { - /* backup always is on the same volume as parent */ - mask = VLSF_RWVOL; - av->states |= (VRO|VBackup); - } - else { - mask = 0; /* Can't find volume in vldb entry */ + mask = VLSF_RWVOL; + } else if ((ve->flags & VLF_ROEXISTS) + && (av->volume == ve->volumeId[ROVOL])) { + mask = VLSF_ROVOL; + av->states |= VRO; + } else if ((ve->flags & VLF_BACKEXISTS) + && (av->volume == ve->volumeId[BACKVOL])) { + /* backup always is on the same volume as parent */ + mask = VLSF_RWVOL; + av->states |= (VRO | VBackup); + } else { + mask = 0; /* Can't find volume in vldb entry */ } /* fill in volume types */ - av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0); - av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0); + av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0); + av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0); av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0); if (ve->flags & VLF_DFSFILESET) @@ -839,14 +829,25 @@ void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell) cellp = afs_GetCell(acell, 0); + /* This volume, av, is locked. Zero out the serverHosts[] array + * so that if afs_GetServer() decides to replace the server + * struct, we don't deadlock trying to afs_ResetVolumeInfo() + * this volume. + */ + for (j = 0; j < MAXHOSTS; j++) { + av->serverHost[j] = 0; + } + /* Step through the VLDB entry making sure each server listed is there */ - for (i=0,j=0; inServers; i++) { - if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) { - continue; /* wrong volume or don't use this volume */ + for (i = 0, j = 0; i < ve->nServers; i++) { + if (((ve->serverFlags[i] & mask) == 0) + || (ve->serverFlags[i] & VLSF_DONTUSE)) { + continue; /* wrong volume or don't use this volume */ } temp = htonl(ve->serverNumber[i]); - ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0); + ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, + (afsUUID *) 0, 0); av->serverHost[j] = ts; /* * The cell field could be 0 if the server entry was created @@ -855,7 +856,7 @@ void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell) * follows later on it will find the server entry thus it will * simply return without setting any fields, so we set the * field ourselves below. - */ + */ if (!ts->cell) ts->cell = cellp; afs_PutServer(ts, WRITE_LOCK); @@ -865,43 +866,42 @@ void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell) av->serverHost[j++] = 0; } afs_SortServers(av->serverHost, MAXHOSTS); -} /*InstallNVolumeEntry*/ +} /*InstallNVolumeEntry */ -void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, - int acell, struct cell *tcell, struct vrequest *areq) +void +InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell, + struct cell *tcell, struct vrequest *areq) { - register struct srvAddr *sa; register struct server *ts; struct conn *tconn; struct cell *cellp; register int i, j; afs_uint32 serverid; afs_int32 mask; - int hash, k; + int k; AFS_STATCNT(InstallVolumeEntry); /* Determine type of volume we want */ if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) { - mask = VLSF_RWVOL; - } - else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) { - mask = VLSF_ROVOL; - av->states |= VRO; - } - else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) { - /* backup always is on the same volume as parent */ - mask = VLSF_RWVOL; - av->states |= (VRO|VBackup); - } - else { - mask = 0; /* Can't find volume in vldb entry */ + mask = VLSF_RWVOL; + } else if ((ve->flags & VLF_ROEXISTS) + && av->volume == ve->volumeId[ROVOL]) { + mask = VLSF_ROVOL; + av->states |= VRO; + } else if ((ve->flags & VLF_BACKEXISTS) + && (av->volume == ve->volumeId[BACKVOL])) { + /* backup always is on the same volume as parent */ + mask = VLSF_RWVOL; + av->states |= (VRO | VBackup); + } else { + mask = 0; /* Can't find volume in vldb entry */ } /* fill in volume types */ - av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0); - av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0); + av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0); + av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0); av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0); if (ve->flags & VLF_DFSFILESET) @@ -914,8 +914,8 @@ void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, * struct, we don't deadlock trying to afs_ResetVolumeInfo() * this volume. */ - for (j=0; jserverHost[j] = 0; + for (j = 0; j < MAXHOSTS; j++) { + av->serverHost[j] = 0; } /* Gather the list of servers the VLDB says the volume is on @@ -923,19 +923,22 @@ void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, * is not found, then get the list of addresses for the * server, VL_GetAddrsU(), and create a server struct, afs_GetServer(). */ - for (i=0,j=0; inServers; i++) { - if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) { - continue; /* wrong volume don't use this volume */ + for (i = 0, j = 0; i < ve->nServers; i++) { + if (((ve->serverFlags[i] & mask) == 0) + || (ve->serverFlags[i] & VLSF_DONTUSE)) { + continue; /* wrong volume don't use this volume */ } if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) { /* The server has no uuid */ serverid = htonl(ve->serverNumber[i].time_low); - ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0); + ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, + (afsUUID *) 0, 0); } else { ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0); - if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) { - /* uuid, uniquifier, and portal are the same */ + if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) + && ts->addr) { + /* uuid, uniquifier, and portal are the same */ } else { afs_uint32 *addrp, nentries, code, unique; bulkaddrs addrs; @@ -948,16 +951,15 @@ void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, memset((char *)&uuid, 0, sizeof(uuid)); memset((char *)&addrs, 0, sizeof(addrs)); do { - tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, - tcell->cellNum, areq, SHARED_LOCK); + tconn = + afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, + tcell->cellNum, areq, SHARED_LOCK); if (tconn) { -#ifdef RX_ENABLE_LOCKS - AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ - code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs); -#ifdef RX_ENABLE_LOCKS - AFS_GLOCK(); -#endif /* RX_ENABLE_LOCKS */ + RX_AFS_GUNLOCK(); + code = + VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, + &nentries, &addrs); + RX_AFS_GLOCK(); } else { code = -1; } @@ -966,8 +968,8 @@ void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, if (code == 0 && nentries == 0) code = VL_NOENT; - } while (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq, - -1, SHARED_LOCK, tcell)); + } while (afs_Analyze + (tconn, code, NULL, areq, -1, SHARED_LOCK, tcell)); if (code) { /* Better handing of such failures; for now we'll simply retry this call */ areq->volumeError = 1; @@ -976,12 +978,13 @@ void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, addrp = addrs.bulkaddrs_val; for (k = 0; k < nentries; k++) { - addrp[k] = htonl(addrp[k]); + addrp[k] = htonl(addrp[k]); } ts = afs_GetServer(addrp, nentries, acell, cellp->fsport, WRITE_LOCK, &ve->serverNumber[i], ve->serverUnique[i]); - afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp)); + afs_osi_Free(addrs.bulkaddrs_val, + addrs.bulkaddrs_len * sizeof(*addrp)); } } av->serverHost[j] = ts; @@ -992,7 +995,7 @@ void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, * follows later on it will find the server entry thus it will * simply return without setting any fields, so we set the * field ourselves below. - */ + */ if (!ts->cell) ts->cell = cellp; afs_PutServer(ts, WRITE_LOCK); @@ -1000,21 +1003,22 @@ void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, } afs_SortServers(av->serverHost, MAXHOSTS); -} /*InstallVolumeEntry*/ +} /*InstallVolumeEntry */ -void afs_ResetVolumeInfo(struct volume *tv) +void +afs_ResetVolumeInfo(struct volume *tv) { int i; AFS_STATCNT(afs_ResetVolumeInfo); - ObtainWriteLock(&tv->lock,117); + ObtainWriteLock(&tv->lock, 117); tv->states |= VRecheck; - for (i=0; istatus[i] = not_busy; + for (i = 0; i < MAXHOSTS; i++) + tv->status[i] = not_busy; if (tv->name) { - afs_osi_Free(tv->name, strlen(tv->name)+1); - tv->name = (char *) 0; - } + afs_osi_Free(tv->name, strlen(tv->name) + 1); + tv->name = NULL; + } ReleaseWriteLock(&tv->lock); -} /*afs_ResetVolumeInfo*/ +} diff --git a/src/afs/afsincludes.h b/src/afs/afsincludes.h index 613d996f1..98bb63351 100644 --- a/src/afs/afsincludes.h +++ b/src/afs/afsincludes.h @@ -7,30 +7,34 @@ * directory or online at http://www.openafs.org/dl/license10.html */ +#ifdef UKERNEL +#include +#else + #include /* AFS based headers */ -#include "../afs/stds.h" +#include "afs/stds.h" #ifdef AFS_AIX_ENV -#include "../afs/osi_vfs.h" +#include "osi_vfs.h" #else #ifdef AFS_DEC_ENV -#include "../afs/gfs_vfs.h" -#include "../afs/gfs_vnode.h" +#include "afs/gfs_vfs.h" +#include "afs/gfs_vnode.h" #else #ifdef AFS_HPUX_ENV -#include "../afs/osi_vfs.h" +#include "osi_vfs.h" #endif /* AFS_HPUX_ENV */ #endif /* AFS_DEC_ENV */ #endif /* AFS_AIX_ENV */ #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV) -#include "../afs/osi_vfs.h" +#include "osi_vfs.h" #endif -#include "../afs/afs_osi.h" -#include "../rx/rx.h" -#include "../afs/lock.h" -#include "../afs/volerrors.h" -#include "../afs/voldefs.h" +#include "rx/rx.h" +#include "afs/afs_osi.h" +#include "afs/lock.h" +#include "afs/volerrors.h" +#include "afs/voldefs.h" #ifdef AFS_LINUX20_ENV #ifdef TRUE #undef TRUE @@ -41,18 +45,21 @@ #undef __NFDBITS #undef __FDMASK #endif -#include "../afsint/afsint.h" -#include "../afs/exporter.h" -#include "../afsint/vldbint.h" -#include "../afs/afs.h" -#include "../afs/afs_chunkops.h" -/*#include "../afs/auxinode.h" -- used only in afs_istuff.c */ -#include "../afs/rxkad.h" -#include "../afs/prs_fs.h" -#include "../afs/dir.h" -#include "../afs/afs_axscache.h" -#include "../afs/icl.h" -#include "../afs/afs_prototypes.h" +#include "afsint.h" +#include "afs/exporter.h" +#include "vldbint.h" +#include "afs/afs.h" +#include "afs/afs_chunkops.h" +/*#include "afs/auxinode.h" -- used only in afs_istuff.c */ +#include "rx/rxkad.h" +#include "afs/prs_fs.h" +#include "afs/dir.h" +#include "afs/afs_axscache.h" +#include "afs/icl.h" +#include "afs/afs_stats.h" +#include "afs/afs_prototypes.h" #if defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) -#include "../afs/osi_machdep.h" +#include "osi_machdep.h" +#endif + #endif diff --git a/src/afs/exporter.h b/src/afs/exporter.h index fa3745cac..61371b46a 100644 --- a/src/afs/exporter.h +++ b/src/afs/exporter.h @@ -34,12 +34,12 @@ */ #if defined(AFS_SUN57_64BIT_ENV) || defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZPTR==64)) || defined(AFS_LINUX_64BIT_KERNEL) -#define AFS_XLATOR_MAGIC 0x8765 /* XXX */ +#define AFS_XLATOR_MAGIC 0x8765 /* XXX */ #else #define AFS_XLATOR_MAGIC 0x87654321 #endif -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) #define AFS_NFSXLATORREQ(cred) 0 #else #ifdef AFS_OSF_ENV @@ -49,34 +49,34 @@ #endif #endif -struct exporterops { - int (*export_reqhandler)(); - int (*export_hold)(); - int (*export_rele)(); - int (*export_sysname)(); - int (*export_garbagecollect)(); - int (*export_statistics)(); +struct exporterops { + int (*export_reqhandler) (); + int (*export_hold) (); + int (*export_rele) (); + int (*export_sysname) (); + int (*export_garbagecollect) (); + int (*export_statistics) (); }; struct exporterstats { - afs_int32 calls; /* # of calls to the exporter */ - afs_int32 rejectedcalls; /* # of afs rejected calls */ - afs_int32 nopag; /* # of unpagged remote calls */ - afs_int32 invalidpag; /* # of invalid pag calls */ + afs_int32 calls; /* # of calls to the exporter */ + afs_int32 rejectedcalls; /* # of afs rejected calls */ + afs_int32 nopag; /* # of unpagged remote calls */ + afs_int32 invalidpag; /* # of invalid pag calls */ }; struct afs_exporter { - struct afs_exporter *exp_next; - struct exporterops *exp_op; - afs_int32 exp_states; - afs_int32 exp_type; - struct exporterstats exp_stats; - char *exp_data; + struct afs_exporter *exp_next; + struct exporterops *exp_op; + afs_int32 exp_states; + afs_int32 exp_type; + struct exporterstats exp_stats; + char *exp_data; }; /* exp_type values */ -#define EXP_NULL 0 /* Undefined */ -#define EXP_NFS 1 /* Nfs/Afs translator */ +#define EXP_NULL 0 /* Undefined */ +#define EXP_NFS 1 /* Nfs/Afs translator */ /* exp_states values */ #define EXP_EXPORTED 1 @@ -93,8 +93,8 @@ struct afs_exporter { (*(EXP)->exp_op->export_hold)(EXP) #define EXP_RELE(EXP) \ (*(EXP)->exp_op->export_rele)(EXP) -#define EXP_SYSNAME(EXP, INNAME, OUTNAME) \ - (*(EXP)->exp_op->export_sysname)(EXP, INNAME, OUTNAME) +#define EXP_SYSNAME(EXP, INNAME, OUTNAME, NUM) \ + (*(EXP)->exp_op->export_sysname)(EXP, INNAME, OUTNAME, NUM) #define EXP_GC(EXP, param) \ (*(EXP)->exp_op->export_garbagecollect)(EXP, param) #define EXP_STATISTICS(EXP) \ diff --git a/src/afs/lock.h b/src/afs/lock.h index 02adc8629..4b449d7e1 100644 --- a/src/afs/lock.h +++ b/src/afs/lock.h @@ -10,42 +10,35 @@ #ifndef __AFSLOCK_INCLUDE__ #define __AFSLOCK_INCLUDE__ 1 +#if !defined(KERNEL) && !defined(KDUMP_KERNEL) +#error Do not include afs/lock.h except for kernel code. +#endif + /* * (C) COPYRIGHT IBM CORPORATION 1987 * LICENSED MATERIALS - PROPERTY OF IBM */ -/* The following macros allow multi statement macros to be defined safely, i.e. - - the multi statement macro can be the object of an if statement; - - the call to the multi statement macro may be legally followed by a semi-colon. - BEGINMAC and ENDMAC have been tested with both the portable C compiler and - Hi-C. Both compilers were from the Palo Alto 4.2BSD software releases, and - both optimized out the constant loop code. For an example of the use - of BEGINMAC and ENDMAC, see the definition for ReleaseWriteLock, below. - An alternative to this, using "if(1)" for BEGINMAC is not used because it - may generate worse code with pcc, and may generate warning messages with hi-C. -*/ - #if (defined(AFS_SUN5_ENV)) || defined(AFS_OSF_ENV) #define AFS_NOBOZO_LOCK #endif #if !defined(AFS_OSF20_ENV) || defined(AFS_OSF30_ENV) || defined(AFS_OSF32_ENV) /* We do not instrument locks on osf20 because the vcache structure - ** exceeds the maximim possible limit for a vnode. - */ + ** exceeds the maximim possible limit for a vnode. + */ #define INSTRUMENT_LOCKS /* This is the max lock number in use. Please update it if you add any new * lock numbers. */ -#define MAX_LOCK_NUMBER 572 -#endif +#define MAX_LOCK_NUMBER 700 +#endif struct afs_bozoLock { - short count; /* count of excl locks */ - char flags; /* bit 1: is anyone waiting? */ - char spare; /* for later */ - char *proc; /* process holding the lock, really a struct proc * */ + short count; /* count of excl locks */ + char flags; /* bit 1: is anyone waiting? */ + char spare; /* for later */ + char *proc; /* process holding the lock, really a struct proc * */ }; #ifndef AFS_NOBOZO_LOCK typedef struct afs_bozoLock afs_bozoLock_t; @@ -62,7 +55,7 @@ typedef struct afs_bozoLock afs_bozoLock_t; #define afs_CheckBozonLockBlocking(lock) 0 #endif -#define AFS_BOZONWAITING 1 /* someone is waiting for this lock */ +#define AFS_BOZONWAITING 1 /* someone is waiting for this lock */ #undef MObtainWriteLock /* Defined also in ../rx/rx_machdep.h" */ #undef MReleaseWriteLock @@ -83,6 +76,17 @@ typedef struct afs_bozoLock afs_bozoLock_t; #undef LOCK_INIT #define LOCK_INIT(lock, nm) Lock_Init(lock) +/* The following macros allow multi statement macros to be defined safely, i.e. + - the multi statement macro can be the object of an if statement; + - the call to the multi statement macro may be legally followed by a semi-colon. + BEGINMAC and ENDMAC have been tested with both the portable C compiler and + Hi-C. Both compilers were from the Palo Alto 4.2BSD software releases, and + both optimized out the constant loop code. For an example of the use + of BEGINMAC and ENDMAC, see the definition for ReleaseWriteLock, below. + An alternative to this, using "if(1)" for BEGINMAC is not used because it + may generate worse code with pcc, and may generate warning messages with hi-C. +*/ + #define BEGINMAC do { #define ENDMAC } while (0) @@ -119,26 +123,26 @@ extern tid_t thread_self(); #endif /* AFS_SGI64_ENV */ #endif /* AFS_HPUX101_ENV */ #endif /* AFS_AIX41_ENV */ -#endif +#endif /* all locks wait on excl_locked except for READ_LOCK, which waits on readers_reading */ struct afs_lock { - unsigned char wait_states; /* type of lockers waiting */ - unsigned char excl_locked; /* anyone have boosted, shared or write lock? */ - unsigned short readers_reading;/* # readers actually with read locks */ - unsigned short num_waiting; /* probably need this soon */ - unsigned short spare; /* not used now */ - osi_timeval_t time_waiting; /* for statistics gathering */ + unsigned char wait_states; /* type of lockers waiting */ + unsigned char excl_locked; /* anyone have boosted, shared or write lock? */ + unsigned short readers_reading; /* # readers actually with read locks */ + unsigned short num_waiting; /* probably need this soon */ + unsigned short spare; /* not used now */ + osi_timeval_t time_waiting; /* for statistics gathering */ #if defined(INSTRUMENT_LOCKS) /* the following are useful for debugging - ** the field 'src_indicator' is updated only by ObtainLock() and - ** only for writes/shared locks. Hence, it indictes where in the - ** source code the shared/write lock was set. - */ - unsigned int pid_last_reader;/* proceess id of last reader */ - unsigned int pid_writer; /* process id of writer, else 0 */ - unsigned int src_indicator; /* third param to ObtainLock()*/ -#endif /* INSTRUMENT_LOCKS */ + ** the field 'src_indicator' is updated only by ObtainLock() and + ** only for writes/shared locks. Hence, it indictes where in the + ** source code the shared/write lock was set. + */ + unsigned int pid_last_reader; /* proceess id of last reader */ + unsigned int pid_writer; /* process id of writer, else 0 */ + unsigned int src_indicator; /* third param to ObtainLock() */ +#endif /* INSTRUMENT_LOCKS */ }; typedef struct afs_lock afs_lock_t; typedef struct afs_lock afs_rwlock_t; @@ -156,11 +160,20 @@ typedef struct afs_lock afs_rwlock_t; #include "icl.h" extern int afs_trclock; + +#define AFS_LOCK_TRACE_ENABLE 0 +#if AFS_LOCK_TRACE_ENABLE +#define AFS_LOCK_TRACE(op, lock, type) \ + if (afs_trclock) Afs_Lock_Trace(op, lock, type, __FILE__, __LINE__); +#else +#define AFS_LOCK_TRACE(op, lock, type) +#endif + #if defined(INSTRUMENT_LOCKS) #define ObtainReadLock(lock)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, READ_LOCK);\ if (!((lock)->excl_locked & WRITE_LOCK)) \ ((lock)->readers_reading)++; \ else \ @@ -170,7 +183,7 @@ extern int afs_trclock; #define ObtainWriteLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)WRITE_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, WRITE_LOCK);\ if (!(lock)->excl_locked && !(lock)->readers_reading)\ (lock) -> excl_locked = WRITE_LOCK;\ else\ @@ -183,7 +196,7 @@ extern int afs_trclock; #define ObtainSharedLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, SHARED_LOCK);\ if (!(lock)->excl_locked)\ (lock) -> excl_locked = SHARED_LOCK;\ else\ @@ -196,7 +209,7 @@ extern int afs_trclock; #define UpgradeSToWLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)BOOSTED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, BOOSTED_LOCK);\ if (!(lock)->readers_reading)\ (lock)->excl_locked = WRITE_LOCK;\ else\ @@ -208,7 +221,7 @@ extern int afs_trclock; /* this must only be called with a WRITE or boosted SHARED lock! */ #define ConvertWToSLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, SHARED_LOCK);\ (lock)->excl_locked = SHARED_LOCK; \ if((lock)->wait_states) \ Afs_Lock_ReleaseR(lock); \ @@ -216,7 +229,7 @@ extern int afs_trclock; #define ConvertWToRLock(lock) \ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, READ_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ ((lock)->readers_reading)++;\ (lock)->pid_last_reader = MyPidxx ; \ @@ -226,7 +239,7 @@ extern int afs_trclock; #define ConvertSToRLock(lock) \ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, READ_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ ((lock)->readers_reading)++;\ (lock)->pid_last_reader = MyPidxx ; \ @@ -236,7 +249,7 @@ extern int afs_trclock; #define ReleaseReadLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, READ_LOCK);\ if (!(--((lock)->readers_reading)) && (lock)->wait_states)\ Afs_Lock_ReleaseW(lock) ; \ if ( (lock)->pid_last_reader == MyPidxx ) \ @@ -245,7 +258,7 @@ extern int afs_trclock; #define ReleaseWriteLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)WRITE_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, WRITE_LOCK);\ (lock)->excl_locked &= ~WRITE_LOCK;\ if ((lock)->wait_states) Afs_Lock_ReleaseR(lock);\ (lock)->pid_writer=0; \ @@ -254,7 +267,7 @@ extern int afs_trclock; /* can be used on shared or boosted (write) locks */ #define ReleaseSharedLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, SHARED_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ if ((lock)->wait_states) Afs_Lock_ReleaseR(lock);\ (lock)->pid_writer=0; \ @@ -264,7 +277,7 @@ extern int afs_trclock; #define ObtainReadLock(lock)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, READ_LOCK);\ if (!((lock)->excl_locked & WRITE_LOCK)) \ ((lock)->readers_reading)++; \ else \ @@ -273,7 +286,7 @@ extern int afs_trclock; #define ObtainWriteLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)WRITE_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, WRITE_LOCK);\ if (!(lock)->excl_locked && !(lock)->readers_reading)\ (lock) -> excl_locked = WRITE_LOCK;\ else\ @@ -284,7 +297,7 @@ extern int afs_trclock; #define ObtainSharedLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, SHARED_LOCK);\ if (!(lock)->excl_locked)\ (lock) -> excl_locked = SHARED_LOCK;\ else\ @@ -292,10 +305,10 @@ extern int afs_trclock; ENDMAC #define NBObtainSharedLock(lock, src) (((lock)->excl_locked) ? EWOULDBLOCK : (((lock) -> excl_locked = SHARED_LOCK), 0)) - + #define UpgradeSToWLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)BOOSTED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, BOOSTED_LOCK);\ if (!(lock)->readers_reading)\ (lock)->excl_locked = WRITE_LOCK;\ else\ @@ -305,7 +318,7 @@ extern int afs_trclock; /* this must only be called with a WRITE or boosted SHARED lock! */ #define ConvertWToSLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, SHARED_LOCK);\ (lock)->excl_locked = SHARED_LOCK; \ if((lock)->wait_states) \ Afs_Lock_ReleaseR(lock); \ @@ -313,7 +326,7 @@ extern int afs_trclock; #define ConvertWToRLock(lock) \ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, READ_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ ((lock)->readers_reading)++;\ Afs_Lock_ReleaseR(lock);\ @@ -321,7 +334,7 @@ extern int afs_trclock; #define ConvertSToRLock(lock) \ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, READ_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ ((lock)->readers_reading)++;\ Afs_Lock_ReleaseR(lock);\ @@ -329,14 +342,14 @@ extern int afs_trclock; #define ReleaseReadLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, READ_LOCK);\ if (!(--((lock)->readers_reading)) && (lock)->wait_states)\ Afs_Lock_ReleaseW(lock) ; \ ENDMAC #define ReleaseWriteLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)WRITE_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, WRITE_LOCK);\ (lock)->excl_locked &= ~WRITE_LOCK;\ if ((lock)->wait_states) Afs_Lock_ReleaseR(lock);\ ENDMAC @@ -344,7 +357,7 @@ extern int afs_trclock; /* can be used on shared or boosted (write) locks */ #define ReleaseSharedLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, SHARED_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ if ((lock)->wait_states) Afs_Lock_ReleaseR(lock);\ ENDMAC diff --git a/src/afs/longc_procs.h b/src/afs/longc_procs.h index 758d7e94b..6f8d24212 100644 --- a/src/afs/longc_procs.h +++ b/src/afs/longc_procs.h @@ -35,12 +35,12 @@ struct afs_longcall_procs { int (*LC_strncpy) (); int (*LC_flock) (); int (*LC_setgroups) (); - struct ucred * (*LC_crcopy) (); - struct ucred * (*LC_crget) (); + struct ucred *(*LC_crcopy) (); + struct ucred *(*LC_crget) (); int (*LC_crhold) (); int (*LC_ip_stripoptions) (); int (*LC_in_cksum) (); - struct mbuf * (*LC_m_pullup) (); + struct mbuf *(*LC_m_pullup) (); int (*LC_resettodr) (); int (*LC_untimeout) (); int (*LC_timeout) (); @@ -52,13 +52,13 @@ struct afs_longcall_procs { int (*LC_m_freem) (); int (*LC_soclose) (); int (*LC_sobind) (); - struct mbuf * (*LC_m_get) (); + struct mbuf *(*LC_m_get) (); int (*LC_socreate) (); int (*LC_soreserve) (); #if defined(AFS_DECOSF_ENV) int (*LC_getf) (); -#else /* AFS_DECOSF_ENV */ - struct file * (*LC_getf) (); +#else /* AFS_DECOSF_ENV */ + struct file *(*LC_getf) (); #endif int (*LC_splx) (); int (*LC_microtime) (); @@ -72,7 +72,7 @@ struct afs_longcall_procs { int (*LC_gfs_unlock) (); int (*LC_gfs_lock) (); int (*LC_gput) (); - struct inode * (*LC_ufs_galloc) (); + struct inode *(*LC_ufs_galloc) (); int (*LC_gno_close) (); int (*LC_km_alloc) (); int (*LC_km_free) (); @@ -80,14 +80,14 @@ struct afs_longcall_procs { int (*LC_nuxi_l) (); int (*LC_nuxi_s) (); - struct inode * (*LC_gfs_gget) (); + struct inode *(*LC_gfs_gget) (); int (*LC_binval) (); int (*LC_splclock) (); int (*LC_xumount) (); int (*LC_bflush) (); int (*LC_blkclr) (); int (*LC_vmaccess) (); - struct gnode * (*LC_gfs_namei) (); + struct gnode *(*LC_gfs_namei) (); int (*LC_getpdev) (); int (*LC_check_mountp) (); int (*LC_access) (); @@ -96,7 +96,7 @@ struct afs_longcall_procs { int (*LC_imin) (); int (*LC_setjmp) (); - struct gnode * (*LC_gget) (); + struct gnode *(*LC_gget) (); void (*LC_grele) (); void (*LC_gref) (); int (*LC_xdr_char) (); @@ -107,13 +107,13 @@ struct afs_longcall_procs { int (*LC_smp_owner) (); int (*LC_xinval) (); int (*LC_cacheinvalall) (); - int (*LC_psignal)(); - int (*LC_ufs_rwgp_lock)(); + int (*LC_psignal) (); + int (*LC_ufs_rwgp_lock) (); #else int (*LC_iunlock) (); int (*LC_ilock) (); int (*LC_iput) (); - struct inode * (*LC_ialloc) (); + struct inode *(*LC_ialloc) (); int (*LC_vno_close) (); int (*LC_kmem_alloc) (); int (*LC_kmem_free) (); @@ -125,22 +125,22 @@ struct afs_longcall_procs { int (*LC_vn_rele) (); int (*LC_vn_rdwr) (); int (*LC_mapout) (); - struct mount * (*LC_getmp) (); - struct inode * (*LC_iget) (); - struct mbuf * (*LC_m_more) (); + struct mount *(*LC_getmp) (); + struct inode *(*LC_iget) (); + struct mbuf *(*LC_m_more) (); int (*LC__spl1) (); #endif int (*LC_rdwri) (); - struct file * (*LC_falloc) (); + struct file *(*LC_falloc) (); int (*LC_rmfree) (); int (*LC_mapin) (); long (*LC_rmalloc) (); - struct pte * (*LC_vtopte) (); + struct pte *(*LC_vtopte) (); int (*LC_vattr_null) (); int (*LC_strlen) (); int (*LC_bcopy) (); int (*LC_brelse) (); - struct buf * (*LC_geteblk) (); + struct buf *(*LC_geteblk) (); int (*LC_panic) (); int (*LC_strcpy) (); int (*LC_printf) (); @@ -159,16 +159,16 @@ struct afs_longcall_procs { int (*LC_closef) (); int (*LC_fake_inode_init) (); int (*LC_getnewvnode) (); - struct mount * (*LC_getvfs) (); + struct mount *(*LC_getvfs) (); int (*LC_idrop) (); int (*LC_insmntque) (); int (*LC_ioctl_base) (); - caddr_t (*LC_kalloc) (); + caddr_t(*LC_kalloc) (); void (*LC_kfree) (); void (*LC_lock_done) (); - struct mbuf * (*LC_m_getclr) (); - struct mbuf * (*LC_m_retry) (); - struct mbuf * (*LC_m_retryhdr) (); + struct mbuf *(*LC_m_getclr) (); + struct mbuf *(*LC_m_retry) (); + struct mbuf *(*LC_m_retryhdr) (); int (*LC_mpsleep) (); int (*LC_namei) (); unsigned int (*LC_nuxi_32) (); @@ -197,7 +197,7 @@ struct afs_longcall_procs { */ void (*LC_vrele) (); int (*LC_xdr_char) (); -#endif /* AFS_DECOSF_ENV */ +#endif /* AFS_DECOSF_ENV */ }; extern struct afs_longcall_procs afs_longcall_procs; @@ -206,7 +206,7 @@ extern struct afs_longcall_procs afs_longcall_procs; #if defined(AFS_DECOSF_ENV) #undef kmem_alloc #undef kmem_free -#endif /* AFS_DECOSF_ENV */ +#endif /* AFS_DECOSF_ENV */ #define crfree (*afs_longcall_procs.LC_crfree) #define suser (*afs_longcall_procs.LC_suser) @@ -398,7 +398,7 @@ extern struct afs_longcall_procs afs_longcall_procs; */ #define vrele (*afs_longcall_procs.LC_vrele) #define xdr_char (*afs_longcall_procs.LC_xdr_char) -#endif /* AFS_DECOSF_ENV */ +#endif /* AFS_DECOSF_ENV */ #endif /* LONGCALL_NO_MACROS */ diff --git a/src/afs/nfsclient.h b/src/afs/nfsclient.h index e4e4d1d22..0db9d3cda 100644 --- a/src/afs/nfsclient.h +++ b/src/afs/nfsclient.h @@ -12,26 +12,26 @@ #define NNFSCLIENTS 32 /* Hash table size for afs_nfspags table */ #define NHash(host) ((host) & (NNFSCLIENTS-1)) -#define NFSCLIENTGC (24*3600) /* time after which to GC nfsclientpag structs */ +#define NFSCLIENTGC (24*3600) /* time after which to GC nfsclientpag structs */ #define NFSXLATOR_CRED 0xaaaa struct nfsclientpag { /* From here to .... */ - struct nfsclientpag *next; /* Next hash pointer */ - struct exporterops *nfs_ops; + struct nfsclientpag *next; /* Next hash pointer */ + struct exporterops *nfs_ops; afs_int32 states; afs_int32 type; struct exporterstats nfs_stats; /* .... here is also an overlay to the afs_exporter structure */ afs_int32 refCount; /* Ref count for packages using this */ - afs_int32 uid; /* search based on uid and ... */ - afs_int32 host; /* ... nfs client's host ip address */ - afs_int32 pag; /* active pag for all (uid, host) "unpaged" conns */ - char *sysname; /* user's "@sys" value; also kept in unixuser */ + afs_int32 uid; /* search based on uid and ... */ + afs_int32 host; /* ... nfs client's host ip address */ + afs_int32 pag; /* active pag for all (uid, host) "unpaged" conns */ + char *sysname[MAXNUMSYSNAMES];/* user's "@sys" value; also kept in unixuser */ + int sysnamecount; /* number of sysnames */ afs_int32 lastcall; /* Used for timing out nfsclientpag structs */ }; #endif /* __NFSCLIENT__ */ - diff --git a/src/afs/sysincludes.h b/src/afs/sysincludes.h index 4539cf9d2..2146b7e58 100644 --- a/src/afs/sysincludes.h +++ b/src/afs/sysincludes.h @@ -7,6 +7,10 @@ * directory or online at http://www.openafs.org/dl/license10.html */ +#ifdef UKERNEL +#include +#else + #ifndef __AFS_SYSINCLUDESH__ #define __AFS_SYSINCLUDESH__ 1 @@ -19,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -36,12 +39,15 @@ #include #include #include +#include #include +#ifndef MLEN #include +#include +#endif #include -#include -#include -#include +#include +#include #else /* AFS_OBSD_ENV */ #ifdef AFS_LINUX22_ENV #include @@ -54,14 +60,21 @@ #include #include #include +#if defined(AFS_LINUX26_ENV) +#include +#include +#include +#endif /* Avoid conflicts with coda overloading AFS type namespace. Must precede * inclusion of uaccess.h. */ #define _LINUX_CODA_FS_I #define _CFS_HEADER_ -struct coda_inode_info {}; +struct coda_inode_info { +}; #define _LINUX_XFS_FS_I -struct xfs_inode_info {}; +struct xfs_inode_info { +}; #include #include #include @@ -78,33 +91,38 @@ struct xfs_inode_info {}; #else /* AFS_LINUX22_ENV */ #if defined(AFS_DARWIN_ENV) -#define _MACH_ETAP_H_ -typedef unsigned short etap_event_t; +#ifndef _MACH_ETAP_H_ +#define _MACH_ETAP_H_ +typedef unsigned short etap_event_t; +#endif #endif #if !defined(AFS_OSF_ENV) -#include "../h/errno.h" -#include "../h/types.h" -#include "../h/param.h" +#include "h/errno.h" +#include "h/types.h" +#include "h/param.h" #ifdef AFS_AUX_ENV #ifdef PAGING -#include "../h/mmu.h" -#include "../h/seg.h" -#include "../h/page.h" -#include "../h/region.h" +#include "h/mmu.h" +#include "h/seg.h" +#include "h/page.h" +#include "h/region.h" #endif /* PAGING */ -#include "../h/sysmacros.h" -#include "../h/signal.h" -#include "../h/var.h" +#include "h/sysmacros.h" +#include "h/signal.h" +#include "h/var.h" #endif /* AFS_AUX_ENV */ -#include "../h/systm.h" -#include "../h/time.h" +#include "h/systm.h" +#include "h/time.h" #ifdef AFS_AIX_ENV #ifdef AFS_AIX41_ENV #include "sys/statfs.h" #endif +#ifdef AFS_AIX51_ENV +#include "sys/acl.h" +#endif #include "../h/file.h" #include "../h/fullstat.h" #include "../h/vattr.h" @@ -114,18 +132,18 @@ typedef unsigned short etap_event_t; #if defined(AFS_SGI_ENV) #include "values.h" -#include "../sys/sema.h" -#include "../sys/cmn_err.h" +#include "sys/sema.h" +#include "sys/cmn_err.h" #ifdef AFS_SGI64_ENV #include #endif /* AFS_SGI64_ENV */ -#include "../fs/efs_inode.h" +#include "fs/efs_inode.h" #ifdef AFS_SGI_EFS_IOPS_ENV -#include "../sgiefs/efs.h" +#include "sgiefs/efs.h" #endif -#include "../sys/kmem.h" -#include "../sys/cred.h" -#include "../sys/resource.h" +#include "sys/kmem.h" +#include "sys/cred.h" +#include "sys/resource.h" /* * ../sys/debug.h defines ASSERT(), but it is nontrivial only if DEBUG @@ -138,20 +156,20 @@ typedef unsigned short etap_event_t; */ #if defined(AFS_SGI65_ENV) && !defined(DEBUG) #define DEBUG -#include "../sys/debug.h" +#include "sys/debug.h" #undef DEBUG #else -#include "../sys/debug.h" +#include "sys/debug.h" #endif -#include "../sys/statvfs.h" -#include "../sys/sysmacros.h" -#include "../sys/fs_subr.h" -#include "../sys/siginfo.h" -#endif /* AFS_SGI_ENV */ +#include "sys/statvfs.h" +#include "sys/sysmacros.h" +#include "sys/fs_subr.h" +#include "sys/siginfo.h" +#endif /* AFS_SGI_ENV */ #if !defined(AFS_AIX_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_SGI_ENV) -# include "../h/kernel.h" +# include "h/kernel.h" #endif /* !SUN5 && !SGI */ #ifdef AFS_SUN5_ENV @@ -159,45 +177,49 @@ typedef unsigned short etap_event_t; #endif #if defined(AFS_SUN56_ENV) -#include "../h/vfs.h" /* stops SUN56 socketvar.h warnings */ -#include "../h/stropts.h" /* stops SUN56 socketvar.h warnings */ -#include "../h/stream.h" /* stops SUN56 socketvar.h errors */ +#include "h/vfs.h" /* stops SUN56 socketvar.h warnings */ +#include "h/stropts.h" /* stops SUN56 socketvar.h warnings */ +#include "h/stream.h" /* stops SUN56 socketvar.h errors */ #endif -#include "../h/socket.h" -#include "../h/socketvar.h" -#include "../h/protosw.h" +#include "h/socket.h" +#include "h/socketvar.h" +#include "h/protosw.h" #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_FBSD_ENV) -# include "../h/dirent.h" +# include "h/dirent.h" # ifdef AFS_SUN5_ENV -# include "../h/sysmacros.h" -# include "../h/fs/ufs_fsdir.h" +# include "h/sysmacros.h" +# include "h/fs/ufs_fsdir.h" # endif /* AFS_SUN5_ENV */ #else -# include "../h/dir.h" +# include "h/dir.h" #endif /* SGI || SUN || HPUX */ #ifdef AFS_DEC_ENV -# include "../h/smp_lock.h" +# include "h/smp_lock.h" #endif /* AFS_DEC_ENV */ #if !defined(AFS_SGI64_ENV) && !defined(AFS_FBSD_ENV) -#include "../h/user.h" +#include "h/user.h" #endif /* AFS_SGI64_ENV */ #define MACH_USER_API 1 -#include "../h/file.h" -#include "../h/uio.h" -#include "../h/buf.h" -#include "../h/stat.h" +#if defined(AFS_FBSD50_ENV) +#include "h/bio.h" +#include "h/filedesc.h" +#endif +#include "h/file.h" +#include "h/uio.h" +#include "h/buf.h" +#include "h/stat.h" /* ----- The following mainly deal with vnodes/inodes stuff ------ */ #ifdef AFS_DEC_ENV -# include "../h/mount.h" -# include "../machine/psl.h" -# include "../afs/gfs_vnode.h" +# include "h/mount.h" +# include "machine/psl.h" +# include "afs/gfs_vnode.h" #endif #ifdef AFS_MACH_ENV @@ -213,23 +235,30 @@ typedef unsigned short etap_event_t; #ifndef AFS_DEC_ENV # ifdef AFS_SUN5_ENV -# include "../h/statvfs.h" +# include "h/statvfs.h" # endif /* AFS_SUN5_ENV */ # ifdef AFS_HPUX_ENV struct vfspage; /* for vnode.h compiler warnings */ -# include "../h/swap.h" /* for struct swpdbd, for vnode.h compiler warnings */ -# include "../h/dbd.h" /* for union idbd, for vnode.h compiler warnings */ +# include "h/swap.h" /* for struct swpdbd, for vnode.h compiler warnings */ +# include "h/dbd.h" /* for union idbd, for vnode.h compiler warnings */ #ifdef AFS_HPUX110_ENV -# include "../h/resource.h" +# include "h/resource.h" +#endif +#ifdef AFS_HPUX1123_ENV +# include +# include #endif # endif /* AFS_HPUX_ENV */ -#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD40_ENV) +#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) +# if defined(AFS_FBSD50_ENV) +struct vop_getwritemount_args; +# endif # include -# include +# include # include -# include -# include -# include +# include +# include +# include #ifndef AFS_FBSD_ENV # include #define timeout_fcn_t mach_timeout_fcn_t @@ -251,16 +280,16 @@ MALLOC_DECLARE(M_AFS); # include # include #else -# include "../h/vfs.h" -# include "../h/vnode.h" +# include "h/vfs.h" +# include "h/vnode.h" # ifdef AFS_SUN5_ENV -# include "../h/fs/ufs_inode.h" -# include "../h/fs/ufs_mount.h" +# include "h/fs/ufs_inode.h" +# include "h/fs/ufs_mount.h" # else # if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV) -# include "../ufs/inode.h" +# include "ufs/inode.h" # if !defined(AFS_SGI_ENV) && !defined(AFS_HPUX_ENV) -# include "../ufs/mount.h" +# include "ufs/mount.h" # endif /* !AFS_HPUX_ENV */ # endif /* !AFS_AIX32_ENV */ # endif /* AFS_SUN5_ENV */ @@ -268,57 +297,57 @@ MALLOC_DECLARE(M_AFS); #endif /* AFS_DEC_ENV */ /* These mainly deal with networking and rpc headers */ -#include "../netinet/in.h" -#undef MFREE /* defined at mount.h for AIX */ +#include "netinet/in.h" +#undef MFREE /* defined at mount.h for AIX */ #ifdef AFS_SUN5_ENV -# include "../h/time.h" +# include "h/time.h" #else #if !defined(AFS_HPUX_ENV) -# include "../h/mbuf.h" +# include "h/mbuf.h" #endif #endif /* AFS_SUN5_ENV */ -#include "../rpc/types.h" -#include "../rx/xdr.h" +#include "rpc/types.h" +#include "rx/xdr.h" #ifdef AFS_AIX32_ENV # include "net/spl.h" #endif /* Miscellaneous headers */ -#include "../h/proc.h" +#include "h/proc.h" #if !defined(AFS_FBSD_ENV) -#include "../h/ioctl.h" +#include "h/ioctl.h" #endif /* AFS_FBSD_ENV */ -#if defined(AFS_HPUX101_ENV) -#include "../h/proc_iface.h" -#include "../h/vas.h" +#if defined(AFS_HPUX101_ENV) && !defined(AFS_HPUX1123_ENV) +#include "h/proc_iface.h" +#include "h/vas.h" #endif #if defined(AFS_HPUX102_ENV) -#include "../h/unistd.h" -#include "../h/tty.h" +#include "h/unistd.h" +#include "h/tty.h" #endif #if !defined(AFS_SGI_ENV) && !defined(AFS_SUN_ENV) && !defined(AFS_MACH_ENV) && !defined(AFS_AIX32_ENV) && !defined(AFS_HPUX_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) -# include "../h/text.h" -#endif +# include "h/text.h" +#endif #if defined(AFS_AIX_ENV) || defined(AFS_DEC_ENV) -# include "../h/flock.h" /* fcntl.h is a user-level include in aix */ +# include "h/flock.h" /* fcntl.h is a user-level include in aix */ #else -# include "../h/fcntl.h" +# include "h/fcntl.h" #endif /* AIX || DEC */ #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV) -# include "../h/unistd.h" +# include "h/unistd.h" #endif /* SGI || SUN */ #ifdef AFS_AIX32_ENV -# include "../h/vmuser.h" +# include "h/vmuser.h" #endif /* AFS_AIX32_ENV */ #if defined(AFS_SUN5_ENV) @@ -330,7 +359,7 @@ MALLOC_DECLARE(M_AFS); #include #endif -#else /* ! AFS_OSF_ENV */ +#else /* ! AFS_OSF_ENV */ /* All of the OSF/1 stuff is here */ #include #include @@ -372,14 +401,16 @@ MALLOC_DECLARE(M_AFS); #undef mem_alloc #undef mem_free #undef register -#endif /* AFS_ALPHA_ENV */ +#endif /* AFS_ALPHA_ENV */ #include #include #include -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ #endif /* AFS_LINUX22_ENV */ #endif /* AFS_OBSD_ENV */ #endif /* __AFS_SYSINCLUDESH__ so idempotent */ + +#endif diff --git a/src/afs/voldefs.h b/src/afs/voldefs.h index 4b9c3f2f2..633cd952f 100644 --- a/src/afs/voldefs.h +++ b/src/afs/voldefs.h @@ -28,7 +28,7 @@ /* All volumes will have a volume header name in this format */ #define VFORMAT "V%010lu.vol" #define VMAXPATHLEN 64 /* Maximum length (including null) of a volume - external path name */ + * external path name */ /* Values for connect parameter to VInitVolumePackage */ #define CONNECT_FS 1 diff --git a/src/afs/volerrors.h b/src/afs/volerrors.h index de88fa377..ee804c4a9 100644 --- a/src/afs/volerrors.h +++ b/src/afs/volerrors.h @@ -31,23 +31,23 @@ #define VSALVAGE 101 /* Volume needs salvage */ #define VNOVNODE 102 /* Bad vnode number quoted */ #define VNOVOL 103 /* Volume not attached, doesn't exist, - not created or not online */ + * not created or not online */ #define VVOLEXISTS 104 /* Volume already exists */ #define VNOSERVICE 105 /* Volume is not in service (i.e. it's - is out of funds, is obsolete, or somesuch) */ + * is out of funds, is obsolete, or somesuch) */ #define VOFFLINE 106 /* Volume is off line, for the reason - given in the offline message */ + * given in the offline message */ #define VONLINE 107 /* Volume is already on line */ -#define VDISKFULL 108 /* ENOSPC - Partition is "full", i.e. rougly within - n% of full */ +#define VDISKFULL 108 /* ENOSPC - Partition is "full", i.e. rougly within + * n% of full */ #define VOVERQUOTA 109 /* EDQUOT - Volume max quota exceeded */ #define VBUSY 110 /* Volume temporarily unavailable; try again. - The volume should be available again shortly; if - it isn't something is wrong. Not normally to be - propagated to the application level */ + * The volume should be available again shortly; if + * it isn't something is wrong. Not normally to be + * propagated to the application level */ #define VMOVED 111 /* Volume has moved to another server; do a VGetVolumeInfo - to THIS server to find out where */ + * to THIS server to find out where */ -#define VRESTARTING -100 /* server is restarting, otherwise similar to - VBUSY above. This is negative so that old - cache managers treat it as "server is down"*/ +#define VRESTARTING -100 /* server is restarting, otherwise similar to + * VBUSY above. This is negative so that old + * cache managers treat it as "server is down" */ diff --git a/src/gtx/Makefile.in b/src/gtx/Makefile.in index 3f6865f90..bbadd6b52 100644 --- a/src/gtx/Makefile.in +++ b/src/gtx/Makefile.in @@ -7,34 +7,9 @@ # Makefile for gtx, a display-independent, object-oriented window toolkit. -DEST=@DEST@ -TOP_INCDIR=@TOP_INCDIR@ -TOP_LIBDIR=@TOP_LIBDIR@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ -libexecdir=@libexecdir@ -libdir=@libdir@ -includedir=@includedir@ -mandir=@mandir@ -afssrvbindir=@afssrvbindir@ -afssrvsbindir=@afssrvsbindir@ -afssrvlibexecdir=@afssrvlibexecdir@ -RXGEN=${TOP_SRCDIR}/rxgen/rxgen -TOP_SRCDIR=@TOP_SRCDIR@ -SYS_NAME=@AFS_SYSNAME@ - -SHELL=/bin/sh - -include ../config/Makefile.${SYS_NAME} - -COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et -CFLAGS=${DBUG} -I. -I${TOP_SRCDIR}/config \ - -I${TOP_INCDIR} -I${TOP_INCDIR}/afs ${XCFLAGS} -LDFLAGS = ${XLDFLAGS} -#RPCINCLS=${SRCDIR}/include/lwp.h ${SRCDIR}/include/rx/rx.h bosint.h -RPCINCLS= +srcdir=@srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config + INCLS=gtxobjects.h \ gtxwindows.h \ gtxcurseswin.h \ @@ -47,7 +22,6 @@ INCLS=gtxobjects.h \ gtxtextobj.h \ gtxframe.h \ gtxobjdict.h \ - ${RPCINCLS} \ ${TOP_INCDIR}/afs/keys.h \ ${TOP_INCDIR}/afs/cellconfig.h \ ${TOP_INCDIR}/afs/cmd.h @@ -94,32 +68,30 @@ DICT_OBJS=objdict.o CB_SRCS=textcb.c CB_OBJS=textcb.o -#ERROBJS=err.o -ERRSRCS= -ERROJBS= - -include ../config/Makefile.version - -noversion: install - -all: libgtx.a gtxtest - ${INSTALL} gtx*.h ${TOP_INCDIR}/afs - ${INSTALL} libgtx.a ${TOP_LIBDIR} +all: gtxtest \ + ${TOP_LIBDIR}/libgtx.a \ + ${TOP_INCDIR}/afs/gtxcurseswin.h \ + ${TOP_INCDIR}/afs/gtxdumbwin.h \ + ${TOP_INCDIR}/afs/gtxframe.h \ + ${TOP_INCDIR}/afs/gtxinput.h \ + ${TOP_INCDIR}/afs/gtxkeymap.h \ + ${TOP_INCDIR}/afs/gtxlightobj.h \ + ${TOP_INCDIR}/afs/gtxobjdict.h \ + ${TOP_INCDIR}/afs/gtxobjects.h \ + ${TOP_INCDIR}/afs/gtxtextcb.h \ + ${TOP_INCDIR}/afs/gtxtextobj.h \ + ${TOP_INCDIR}/afs/gtxwindows.h \ + ${TOP_INCDIR}/afs/gtxX11win.h tests: object_test screen_test curses_test cb_test gtxtest # All objects in the library -LIBSRCS = ${KEYMAP_SRCS} ${WINDOW_SRCS} ${OBJECT_SRCS} ${DICT_SRCS} \ - ${ERRSRCS} ${CB_SRCS} -LIBOBJS = $(KEYMAP_OBJS) ${WINDOW_OBJS} ${OBJECT_OBJS} ${DICT_OBJS} \ - ${ERROBJS} ${CB_OBJS} +LIBSRCS = ${KEYMAP_SRCS} ${WINDOW_SRCS} ${OBJECT_SRCS} ${DICT_SRCS} ${CB_SRCS} +LIBOBJS = $(KEYMAP_OBJS) ${WINDOW_OBJS} ${OBJECT_OBJS} ${DICT_OBJS} ${CB_OBJS} ${LIBSRCS}: ${INCLS} $(LIBOBJS): ${INCLS} -err.c: err.et - $(RM) -f err.h err.c; $(COMPILE_ET) err -h err - keymap.o: keymap.c ${INCLS} frame.o: frame.c $(INCLS) @@ -169,21 +141,168 @@ object_test: object_test.o ${WINDOW_OBJS} ${DICT_OBJS} ${OBJECT_OBJS} ${CB_OBJS} ${CC} ${CFLAGS} -o object_test object_test.o ${WINDOW_OBJS} ${DICT_OBJS} ${OBJECT_OBJS} ${CB_OBJS} ${LIBS} ${EXTRA_LIBS} # -# Misc others +# Installation targets # libgtx.a: ${LIBOBJS} AFS_component_version_number.o -$(RM) -f $@ $(AR) crv $@ ${LIBOBJS} AFS_component_version_number.o ${RANLIB} $@ -install: libgtx.a - ${INSTALL} gtx*.h ${DESTDIR}${includedir}/afs - ${INSTALL} libgtx.a ${DESTDIR}${libdir}/afs +install: \ + ${DESTDIR}${libdir}/afs/libgtx.a \ + ${DESTDIR}${includedir}/afs/gtxcurseswin.h \ + ${DESTDIR}${includedir}/afs/gtxdumbwin.h \ + ${DESTDIR}${includedir}/afs/gtxframe.h \ + ${DESTDIR}${includedir}/afs/gtxinput.h \ + ${DESTDIR}${includedir}/afs/gtxkeymap.h \ + ${DESTDIR}${includedir}/afs/gtxlightobj.h \ + ${DESTDIR}${includedir}/afs/gtxobjdict.h \ + ${DESTDIR}${includedir}/afs/gtxobjects.h \ + ${DESTDIR}${includedir}/afs/gtxtextcb.h \ + ${DESTDIR}${includedir}/afs/gtxtextobj.h \ + ${DESTDIR}${includedir}/afs/gtxwindows.h \ + ${DESTDIR}${includedir}/afs/gtxX11win.h + +${DESTDIR}${libdir}/afs/libgtx.a: libgtx.a + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxcurseswin.h: gtxcurseswin.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxdumbwin.h: gtxdumbwin.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxframe.h: gtxframe.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxinput.h: gtxinput.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxkeymap.h: gtxkeymap.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxlightobj.h: gtxlightobj.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxobjdict.h: gtxobjdict.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxobjects.h: gtxobjects.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxtextcb.h: gtxtextcb.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxtextobj.h: gtxtextobj.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxwindows.h: gtxwindows.h + ${INSTALL} $? $@ + +${DESTDIR}${includedir}/afs/gtxX11win.h: gtxX11win.h + ${INSTALL} $? $@ + +dest: \ + ${DEST}/lib/afs/libgtx.a \ + ${DEST}/include/afs/gtxcurseswin.h \ + ${DEST}/include/afs/gtxdumbwin.h \ + ${DEST}/include/afs/gtxframe.h \ + ${DEST}/include/afs/gtxinput.h \ + ${DEST}/include/afs/gtxkeymap.h \ + ${DEST}/include/afs/gtxlightobj.h \ + ${DEST}/include/afs/gtxobjdict.h \ + ${DEST}/include/afs/gtxobjects.h \ + ${DEST}/include/afs/gtxtextcb.h \ + ${DEST}/include/afs/gtxtextobj.h \ + ${DEST}/include/afs/gtxwindows.h \ + ${DEST}/include/afs/gtxX11win.h + +${DEST}/lib/afs/libgtx.a: libgtx.a + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxcurseswin.h: gtxcurseswin.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxdumbwin.h: gtxdumbwin.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxframe.h: gtxframe.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxinput.h: gtxinput.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxkeymap.h: gtxkeymap.h + ${INSTALL} $? $@ +${DEST}/include/afs/gtxlightobj.h: gtxlightobj.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxobjdict.h: gtxobjdict.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxobjects.h: gtxobjects.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxtextcb.h: gtxtextcb.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxtextobj.h: gtxtextobj.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxwindows.h: gtxwindows.h + ${INSTALL} $? $@ + +${DEST}/include/afs/gtxX11win.h: gtxX11win.h + ${INSTALL} $? $@ + + +${TOP_LIBDIR}/libgtx.a: libgtx.a + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxcurseswin.h: gtxcurseswin.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxdumbwin.h: gtxdumbwin.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxframe.h: gtxframe.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxinput.h: gtxinput.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxkeymap.h: gtxkeymap.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxlightobj.h: gtxlightobj.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxobjdict.h: gtxobjdict.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxobjects.h: gtxobjects.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxtextcb.h: gtxtextcb.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxtextobj.h: gtxtextobj.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxwindows.h: gtxwindows.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/gtxX11win.h: gtxX11win.h + ${INSTALL} $? $@ + + +# +# Misc targets +# clean: - $(RM) -f *.o *.a *.ln object_test screen_test curses_test err.c core cb_test gtxtest AFS_component_version_number.c + $(RM) -f *.o *.a *.ln object_test screen_test curses_test core cb_test gtxtest AFS_component_version_number.c + +include ../config/Makefile.version -dest: libgtx.a - ${INSTALL} gtx*.h ${DEST}/include/afs - ${INSTALL} libgtx.a ${DEST}/lib/afs diff --git a/src/gtx/X11windows.c b/src/gtx/X11windows.c index 6dc2a6ac8..92ded05ed 100644 --- a/src/gtx/X11windows.c +++ b/src/gtx/X11windows.c @@ -18,16 +18,17 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/X11windows.c,v 1.1.1.4 2001/07/14 22:21:58 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/X11windows.c,v 1.6 2003/07/15 23:15:11 shadow Exp $"); -#include "gtxX11win.h" /*Interface definition*/ -#include /*Standard I/O package*/ +#include "gtxX11win.h" /*Interface definition */ +#include /*Standard I/O package */ #if !defined(NeXT) -extern int errno; /*System error number*/ +extern int errno; /*System error number */ #endif /* NeXT */ -int X11_debug; /*Is debugging turned on?*/ -static char mn[] = "gator_X11windows"; /*Module name*/ +int X11_debug; /*Is debugging turned on? */ +static char mn[] = "gator_X11windows"; /*Module name */ /* * Version of standard operations for a X11 window. @@ -79,12 +80,13 @@ struct gwinbaseops gator_X11_gwinbops = { * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_init(adebug) - int adebug; +int +gator_X11gwin_init(adebug) + int adebug; -{ /*gator_X11gwin_init*/ +{ /*gator_X11gwin_init */ - static char rn[] = "gator_X11gwin_init"; /*Routine name*/ + static char rn[] = "gator_X11gwin_init"; /*Routine name */ /* * Remember if we'll be doing debugging, init X11 and clear the @@ -98,9 +100,9 @@ int gator_X11gwin_init(adebug) /* * We return success, fill this routine it at some point. */ - return(0); + return (0); -} /*gator_X11gwin_init*/ +} /*gator_X11gwin_init */ /*------------------------------------------------------------------------ * gator_X11gwin_create @@ -122,19 +124,20 @@ int gator_X11gwin_init(adebug) * As advertised. *------------------------------------------------------------------------*/ -struct gwin *gator_X11gwin_create(params) - struct gator_X11gwin_params *params; +struct gwin * +gator_X11gwin_create(params) + struct gator_X11gwin_params *params; -{ /*gator_X11gwin_create*/ +{ /*gator_X11gwin_create */ - static char rn[] = "gator_X11gwin_create"; /*Routine name*/ + static char rn[] = "gator_X11gwin_create"; /*Routine name */ if (X11_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); - return((struct gwin *)0); + return (NULL); -} /*gator_X11gwin_create*/ +} /*gator_X11gwin_create */ /*------------------------------------------------------------------------ * gator_X11gwin_cleanup @@ -156,19 +159,20 @@ struct gwin *gator_X11gwin_create(params) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_cleanup(gwp) - struct gwin *gwp; +int +gator_X11gwin_cleanup(gwp) + struct gwin *gwp; -{ /*gator_X11gwin_cleanup*/ +{ /*gator_X11gwin_cleanup */ - static char rn[] = "gator_X11gwin_cleanup"; /*Routine name*/ + static char rn[] = "gator_X11gwin_cleanup"; /*Routine name */ if (X11_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); - return(0); + return (0); -} /*gator_X11gwin_cleanup*/ +} /*gator_X11gwin_cleanup */ /*------------------------------------------------------------------------ * gator_X11gwin_box @@ -191,19 +195,20 @@ int gator_X11gwin_cleanup(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_box(gwp) - struct gwin *gwp; +int +gator_X11gwin_box(gwp) + struct gwin *gwp; -{ /*gator_X11gwin_box*/ +{ /*gator_X11gwin_box */ - static char rn[] = "gator_X11gwin_box"; /*Routine name*/ + static char rn[] = "gator_X11gwin_box"; /*Routine name */ if (X11_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); - return(0); + return (0); -} /*gator_X11gwin_box*/ +} /*gator_X11gwin_box */ /*------------------------------------------------------------------------ * gator_X11gwin_clear @@ -225,19 +230,20 @@ int gator_X11gwin_box(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_clear(gwp) - struct gwin *gwp; +int +gator_X11gwin_clear(gwp) + struct gwin *gwp; -{ /*gator_X11gwin_clear*/ +{ /*gator_X11gwin_clear */ - static char rn[] = "gator_X11gwin_clear"; /*Routine name*/ + static char rn[] = "gator_X11gwin_clear"; /*Routine name */ if (X11_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); - return(0); + return (0); -} /*gator_X11gwin_clear*/ +} /*gator_X11gwin_clear */ /*------------------------------------------------------------------------ * gator_X11gwin_destroy @@ -259,19 +265,20 @@ int gator_X11gwin_clear(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_destroy(gwp) - struct gwin *gwp; +int +gator_X11gwin_destroy(gwp) + struct gwin *gwp; -{ /*gator_X11gwin_destroy*/ +{ /*gator_X11gwin_destroy */ - static char rn[] = "gator_X11gwin_destroy"; /*Routine name*/ + static char rn[] = "gator_X11gwin_destroy"; /*Routine name */ if (X11_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); - return(0); + return (0); -} /*gator_X11gwin_destroy*/ +} /*gator_X11gwin_destroy */ /*------------------------------------------------------------------------ * gator_X11gwin_display @@ -293,19 +300,20 @@ int gator_X11gwin_destroy(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_display(gwp) - struct gwin *gwp; +int +gator_X11gwin_display(gwp) + struct gwin *gwp; -{ /*gator_X11gwin_display*/ +{ /*gator_X11gwin_display */ - static char rn[] = "gator_X11gwin_display"; /*Routine name*/ + static char rn[] = "gator_X11gwin_display"; /*Routine name */ if (X11_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); - return(0); + return (0); -} /*gator_X11gwin_display*/ +} /*gator_X11gwin_display */ /*------------------------------------------------------------------------ * gator_X11gwin_drawline @@ -330,20 +338,22 @@ int gator_X11gwin_display(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_drawline(gwp, params) - struct gwin *gwp; - struct gwin_lineparams *params; +int +gator_X11gwin_drawline(gwp, params) + struct gwin *gwp; + struct gwin_lineparams *params; -{ /*gator_X11gwin_drawline*/ +{ /*gator_X11gwin_drawline */ - static char rn[] = "gator_X11gwin_drawline"; /*Routine name*/ + static char rn[] = "gator_X11gwin_drawline"; /*Routine name */ if (X11_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(0); + return (0); -} /*gator_X11gwin_drawline*/ +} /*gator_X11gwin_drawline */ /*------------------------------------------------------------------------ * gator_X11gwin_drawrectangle @@ -367,20 +377,22 @@ int gator_X11gwin_drawline(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_drawrectangle(gwp, params) - struct gwin *gwp; - struct gwin_rectparams *params; +int +gator_X11gwin_drawrectangle(gwp, params) + struct gwin *gwp; + struct gwin_rectparams *params; -{ /*gator_X11gwin_drawrectangle*/ +{ /*gator_X11gwin_drawrectangle */ - static char rn[] = "gator_X11gwin_drawrectangle"; /*Routine name*/ + static char rn[] = "gator_X11gwin_drawrectangle"; /*Routine name */ if (X11_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(0); + return (0); -} /*gator_X11gwin_drawrectangle*/ +} /*gator_X11gwin_drawrectangle */ /*------------------------------------------------------------------------ * gator_X11gwin_drawchar @@ -404,20 +416,21 @@ int gator_X11gwin_drawrectangle(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_drawchar(gwp, params) - struct gwin *gwp; - struct gwin_charparams *params; +int +gator_X11gwin_drawchar(gwp, params) + struct gwin *gwp; + struct gwin_charparams *params; -{ /*gator_X11gwin_drawchar*/ +{ /*gator_X11gwin_drawchar */ - static char rn[] = "gator_X11gwin_drawchar"; /*Routine name*/ + static char rn[] = "gator_X11gwin_drawchar"; /*Routine name */ if (X11_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); - return(0); + return (0); -} /*gator_X11gwin_drawchar*/ +} /*gator_X11gwin_drawchar */ /*------------------------------------------------------------------------ * gator_X11gwin_drawstring @@ -441,20 +454,21 @@ int gator_X11gwin_drawchar(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_drawstring(gwp, params) - struct gwin *gwp; - struct gwin_strparams *params; +int +gator_X11gwin_drawstring(gwp, params) + struct gwin *gwp; + struct gwin_strparams *params; -{ /*gator_X11gwin_drawstring*/ +{ /*gator_X11gwin_drawstring */ - static char rn[] = "gator_X11gwin_drawstring"; /*Routine name*/ + static char rn[] = "gator_X11gwin_drawstring"; /*Routine name */ if (X11_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); - return(0); + return (0); -} /*gator_X11gwin_drawstring*/ +} /*gator_X11gwin_drawstring */ /*------------------------------------------------------------------------ * gator_X11gwin_invert @@ -478,20 +492,22 @@ int gator_X11gwin_drawstring(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_invert(gwp, params) - struct gwin *gwp; - struct gwin_invparams *params; +int +gator_X11gwin_invert(gwp, params) + struct gwin *gwp; + struct gwin_invparams *params; -{ /*gator_X11gwin_invert*/ +{ /*gator_X11gwin_invert */ - static char rn[] = "gator_X11gwin_invert"; /*Routine name*/ + static char rn[] = "gator_X11gwin_invert"; /*Routine name */ if (X11_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(0); + return (0); -} /*gator_X11gwin_invert*/ +} /*gator_X11gwin_invert */ /*------------------------------------------------------------------------ * gator_X11gwin_getchar @@ -513,19 +529,21 @@ int gator_X11gwin_invert(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_getchar(gwp) - struct gwin *gwp; +int +gator_X11gwin_getchar(gwp) + struct gwin *gwp; -{ /*gator_X11gwin_getchar*/ +{ /*gator_X11gwin_getchar */ - static char rn[] = "gator_X11gwin_getchar"; /*Routine name*/ + static char rn[] = "gator_X11gwin_getchar"; /*Routine name */ if (X11_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(-1); + return (-1); -} /*gator_X11gwin_getchar*/ +} /*gator_X11gwin_getchar */ /*------------------------------------------------------------------------ * gator_X11gwin_getdimensions @@ -548,20 +566,22 @@ int gator_X11gwin_getchar(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_getdimensions(gwp, aparms) - struct gwin *gwp; - struct gwin_sizeparams *aparms; +int +gator_X11gwin_getdimensions(gwp, aparms) + struct gwin *gwp; + struct gwin_sizeparams *aparms; -{/*gator_X11gwin_getdimensions*/ +{ /*gator_X11gwin_getdimensions */ - static char rn[] = "gator_X11gwin_getdimensions"; /*Routine name*/ + static char rn[] = "gator_X11gwin_getdimensions"; /*Routine name */ if (X11_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(-1); + return (-1); -} /*gator_X11gwin_getdimensions*/ +} /*gator_X11gwin_getdimensions */ /*------------------------------------------------------------------------ * gator_X11gwin_wait @@ -583,16 +603,18 @@ int gator_X11gwin_getdimensions(gwp, aparms) * As advertised. *------------------------------------------------------------------------*/ -int gator_X11gwin_wait(gwp) - struct gwin *gwp; +int +gator_X11gwin_wait(gwp) + struct gwin *gwp; -{ /*gator_X11gwin_wait*/ +{ /*gator_X11gwin_wait */ - static char rn[] = "gator_X11gwin_wait"; /*Routine name*/ + static char rn[] = "gator_X11gwin_wait"; /*Routine name */ if (X11_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(-1); + return (-1); -} /*gator_X11gwin_wait*/ +} /*gator_X11gwin_wait */ diff --git a/src/gtx/cb_test.c b/src/gtx/cb_test.c index 163c8cb6d..81bd06922 100644 --- a/src/gtx/cb_test.c +++ b/src/gtx/cb_test.c @@ -14,71 +14,74 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/cb_test.c,v 1.1.1.4 2001/07/14 22:21:58 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/cb_test.c,v 1.5 2003/07/15 23:15:12 shadow Exp $"); -#include "gtxtextcb.h" /*Module interface*/ +#include "gtxtextcb.h" /*Module interface */ #include "AFS_component_version_number.c" main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; -{ /*main*/ +{ /*main */ - register afs_int32 code; /*Return code*/ - struct gator_textcb_hdr *newCB; /*Ptr to new CB hdr*/ - char buf[1024]; /*Text buffer*/ - int do_debugging; /*Print out debugging info?*/ - int i, j, k; /*Loop variables*/ - struct gator_textcb_entry *curr_ent; /*Ptr to text entry*/ - char *curr_char; /*Current char to print*/ + register afs_int32 code; /*Return code */ + struct gator_textcb_hdr *newCB; /*Ptr to new CB hdr */ + char buf[1024]; /*Text buffer */ + int do_debugging; /*Print out debugging info? */ + int i, j, k; /*Loop variables */ + struct gator_textcb_entry *curr_ent; /*Ptr to text entry */ + char *curr_char; /*Current char to print */ printf("\nTesting the gator text object circular buffer package\n\n"); printf("Enter 1 to turn debugging on, 0 otherwise: "); scanf("%d", &do_debugging); - printf("Initializing CB package: debugging %s\n", (do_debugging ? "YES" : "NO")); + printf("Initializing CB package: debugging %s\n", + (do_debugging ? "YES" : "NO")); code = gator_textcb_Init(do_debugging); if (code) { - printf("Initialization failed\n"); - exit(-1); + printf("Initialization failed\n"); + exit(-1); } printf("Creating a CB with up to 100 entries of 80 chars each\n"); newCB = gator_textcb_Create(100, 80); if (newCB == (struct gator_textcb_hdr *)0) { - printf("Can't create new circular buffer."); - exit(-1); + printf("Can't create new circular buffer."); + exit(-1); } /* - * Start writing stuff to this circ buff. - */ + * Start writing stuff to this circ buff. + */ printf("First write\n"); sprintf(buf, "%s", "0123456789"); code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 0); if (code) - printf("First write failed, code is %d\n", code); + printf("First write failed, code is %d\n", code); printf("Second write, highlighted\n"); code = gator_textcb_Write(newCB, buf, 10, 1, 0); if (code) - printf("Second write failed, code is %d\n", code); + printf("Second write failed, code is %d\n", code); printf("Third write, bulk\n"); - sprintf(buf, "%s", "Now is the time for all good men to come to the aid of their country"); + sprintf(buf, "%s", + "Now is the time for all good men to come to the aid of their country"); code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 1); if (code) - printf("Third write failed, code is %d\n", code); + printf("Third write failed, code is %d\n", code); printf("Writing out 3 blank lines\n"); code = gator_textcb_BlankLine(newCB, 3); if (code) - printf("Blank lines failed with error %d\n", code); + printf("Blank lines failed with error %d\n", code); /* - * Print out the CB status. - */ + * Print out the CB status. + */ printf("\nStatus of the circular buffer after the writes:\n"); printf("\tmaxEntriesStored: %d\n", newCB->maxEntriesStored); printf("\tmaxCharsPerEntry: %d\n", newCB->maxCharsPerEntry); @@ -92,44 +95,43 @@ main(argc, argv) curr_ent = newCB->entry + newCB->oldestEntIdx; for (j = 0, i = newCB->oldestEntIdx; j < 5; j++) { - printf("\nEntry %d, idx %d\n", curr_ent->ID, i); - printf("\thighlight : %d\n", curr_ent->highlight); - printf("\tnumInversions : %d\n", curr_ent->numInversions); - printf("\tinversions : "); - for (k=0; k < GATOR_TEXTCB_MAXINVERSIONS; k++) - printf("%d ", curr_ent->inversion[k]); - printf("\n"); - printf("\tcharsUsed : %d\n", curr_ent->charsUsed); - printf("\ttextp : '"); - curr_char = curr_ent->textp; - for (k=0; k < curr_ent->charsUsed; k++) - printf("%c", *curr_char++); - printf("'\n"); - if (i == newCB->maxEntriesStored - 1) { - i = 0; - curr_ent = newCB->entry; - } - else { - i++; - curr_ent++; - } - } /*for loop*/ + printf("\nEntry %d, idx %d\n", curr_ent->ID, i); + printf("\thighlight : %d\n", curr_ent->highlight); + printf("\tnumInversions : %d\n", curr_ent->numInversions); + printf("\tinversions : "); + for (k = 0; k < GATOR_TEXTCB_MAXINVERSIONS; k++) + printf("%d ", curr_ent->inversion[k]); + printf("\n"); + printf("\tcharsUsed : %d\n", curr_ent->charsUsed); + printf("\ttextp : '"); + curr_char = curr_ent->textp; + for (k = 0; k < curr_ent->charsUsed; k++) + printf("%c", *curr_char++); + printf("'\n"); + if (i == newCB->maxEntriesStored - 1) { + i = 0; + curr_ent = newCB->entry; + } else { + i++; + curr_ent++; + } + } /*for loop */ printf("\nMaking small writes ('a') to force the buffer to circulate\n"); printf("Enter any number to continue: "); scanf("%d", &i); sprintf(buf, "%s", "a"); - for (i=0; i < 100; i++) { - printf("#"); - code = gator_textcb_Write(newCB, buf, 1, 0, 1 /*skip*/); - if (code) - printf("Small write %d failed, code is %d\n", i, code); + for (i = 0; i < 100; i++) { + printf("#"); + code = gator_textcb_Write(newCB, buf, 1, 0, 1 /*skip */ ); + if (code) + printf("Small write %d failed, code is %d\n", i, code); } printf("\n"); /* - * Print out the CB status. - */ + * Print out the CB status. + */ printf("\nStatus of the circular buffer after the writes:\n"); printf("\tmaxEntriesStored: %d\n", newCB->maxEntriesStored); printf("\tmaxCharsPerEntry: %d\n", newCB->maxCharsPerEntry); @@ -143,41 +145,40 @@ main(argc, argv) curr_ent = newCB->entry + newCB->oldestEntIdx; for (j = 0, i = newCB->oldestEntIdx; j < 100; j++) { - printf("\nEntry %d, idx %d\n", curr_ent->ID, i); - printf("\thighlight : %d\n", curr_ent->highlight); - printf("\tnumInversions : %d\n", curr_ent->numInversions); - printf("\tinversions : "); - for (k=0; k < GATOR_TEXTCB_MAXINVERSIONS; k++) - printf("%d ", curr_ent->inversion[k]); - printf("\n"); - printf("\tcharsUsed : %d\n", curr_ent->charsUsed); - printf("\ttextp : '"); - curr_char = curr_ent->textp; - for (k=0; k < curr_ent->charsUsed; k++) - printf("%c", *curr_char++); - printf("'\n"); - if (i == newCB->maxEntriesStored - 1) { - i = 0; - curr_ent = newCB->entry; - } - else { - i++; - curr_ent++; - } - } /*for loop*/ + printf("\nEntry %d, idx %d\n", curr_ent->ID, i); + printf("\thighlight : %d\n", curr_ent->highlight); + printf("\tnumInversions : %d\n", curr_ent->numInversions); + printf("\tinversions : "); + for (k = 0; k < GATOR_TEXTCB_MAXINVERSIONS; k++) + printf("%d ", curr_ent->inversion[k]); + printf("\n"); + printf("\tcharsUsed : %d\n", curr_ent->charsUsed); + printf("\ttextp : '"); + curr_char = curr_ent->textp; + for (k = 0; k < curr_ent->charsUsed; k++) + printf("%c", *curr_char++); + printf("'\n"); + if (i == newCB->maxEntriesStored - 1) { + i = 0; + curr_ent = newCB->entry; + } else { + i++; + curr_ent++; + } + } /*for loop */ /* - * Clean-up time! - */ + * Clean-up time! + */ code = gator_textcb_Delete(newCB); if (code) { - printf("CB deletion failed, code is %d\n", code); - exit(-1); + printf("CB deletion failed, code is %d\n", code); + exit(-1); } /* - * It worked, mon! Goombay!! - */ + * It worked, mon! Goombay!! + */ exit(0); -} /*main*/ +} /*main */ diff --git a/src/gtx/curses_test.c b/src/gtx/curses_test.c index ea31eeaaf..cf0f84758 100644 --- a/src/gtx/curses_test.c +++ b/src/gtx/curses_test.c @@ -14,7 +14,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/curses_test.c,v 1.1.1.4 2001/07/14 22:21:58 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/curses_test.c,v 1.5 2003/07/15 23:15:12 shadow Exp $"); #if defined(AFS_HPUX110_ENV) && !defined(__HP_CURSES) #define __HP_CURSES @@ -25,10 +26,10 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/curses_test.c,v 1.1.1.4 2001/07/14 #include "AFS_component_version_number.c" main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; -{ /*main*/ +{ /*main */ WINDOW *mainscr; char str[128]; @@ -46,14 +47,13 @@ main(argc, argv) standend(); #if 0 - box - addstr("Enter a string and a number: "); + box addstr("Enter a string and a number: "); refresh(); scanw(stdscr, "%s %d", str, &i); wprintw(stdscr, "String was '%s', number was %d\n", str, i); refresh(); -#endif 0 +#endif /* 0 */ endwin(); -} /*main*/ +} /*main */ diff --git a/src/gtx/curseswindows.c b/src/gtx/curseswindows.c index c54abc46e..f439429f9 100644 --- a/src/gtx/curseswindows.c +++ b/src/gtx/curseswindows.c @@ -18,7 +18,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/curseswindows.c,v 1.2 2003/01/02 03:55:50 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/curseswindows.c,v 1.10 2003/07/15 23:15:12 shadow Exp $"); #if defined(AFS_HPUX110_ENV) && !defined(__HP_CURSES) @@ -26,7 +27,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/curseswindows.c,v 1.2 2003/01/02 03 #endif #ifndef AFS_SUN5_ENV -#include /*Curses library*/ +#include /*Curses library */ #endif #include #include @@ -37,14 +38,23 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/curseswindows.c,v 1.2 2003/01/02 03 #include #include -#include "gtxcurseswin.h" /*Interface definition*/ +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#include + +#include "gtxcurseswin.h" /*Interface definition */ #include "gtxobjects.h" #include "gtxframe.h" -int curses_debug; /*Is debugging turned on?*/ -static char mn[] = "gator_curseswindows"; /*Module name*/ +int curses_debug; /*Is debugging turned on? */ +static char mn[] = "gator_curseswindows"; /*Module name */ /* * Version of standard operations for a curses window. @@ -97,13 +107,14 @@ struct gwinbaseops gator_curses_gwinbops = { * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_init(adebug) - int adebug; +int +gator_cursesgwin_init(adebug) + int adebug; -{ /*gator_cursesgwin_init*/ +{ /*gator_cursesgwin_init */ - static char rn[] = "gator_cursesgwin_init"; /*Routine name*/ - struct gator_cursesgwin *c_data; /*Ptr to curses-specific data*/ + static char rn[] = "gator_cursesgwin_init"; /*Routine name */ + struct gator_cursesgwin *c_data; /*Ptr to curses-specific data */ /* * Remember if we'll be doing debugging, then init the curses package. @@ -118,33 +129,38 @@ int gator_cursesgwin_init(adebug) * Fill out the base window structure for curses. */ if (curses_debug) - fprintf(stderr, "[%s:%s] Allocating %d bytes for curses window private space in base window\n", mn, rn, sizeof(struct gator_cursesgwin)); - c_data = (struct gator_cursesgwin *) malloc(sizeof(struct gator_cursesgwin)); - if (c_data == (struct gator_cursesgwin *)0){ - fprintf(stderr, "[%s:%s] Can't allocate %d bytes for curses window private space in base window\n", mn, rn, sizeof(struct gator_cursesgwin)); - return(-1); + fprintf(stderr, + "[%s:%s] Allocating %d bytes for curses window private space in base window\n", + mn, rn, sizeof(struct gator_cursesgwin)); + c_data = + (struct gator_cursesgwin *)malloc(sizeof(struct gator_cursesgwin)); + if (c_data == (struct gator_cursesgwin *)0) { + fprintf(stderr, + "[%s:%s] Can't allocate %d bytes for curses window private space in base window\n", + mn, rn, sizeof(struct gator_cursesgwin)); + return (-1); } /* * Fill in the curses-specific base window info. We assume that chars are 8x13. */ - c_data->wp = stdscr; - c_data->charwidth = 8; - c_data->charheight = 13; - c_data->box_vertchar = '|'; + c_data->wp = stdscr; + c_data->charwidth = 8; + c_data->charheight = 13; + c_data->box_vertchar = '|'; c_data->box_horizchar = '-'; /* * Fill in the generic base window info. */ - gator_basegwin.w_type = GATOR_WIN_CURSES; - gator_basegwin.w_x = 0; - gator_basegwin.w_y = 0; - gator_basegwin.w_width = c_data->charwidth * COLS; - gator_basegwin.w_height = c_data->charheight * LINES; + gator_basegwin.w_type = GATOR_WIN_CURSES; + gator_basegwin.w_x = 0; + gator_basegwin.w_y = 0; + gator_basegwin.w_width = c_data->charwidth * COLS; + gator_basegwin.w_height = c_data->charheight * LINES; gator_basegwin.w_changed = 0; - gator_basegwin.w_op = &curses_gwinops; - gator_basegwin.w_parent = (struct gwin *)0; + gator_basegwin.w_op = &curses_gwinops; + gator_basegwin.w_parent = NULL; /* * Plug the private data into the generic part of the base window. @@ -154,7 +170,7 @@ int gator_cursesgwin_init(adebug) /* * Now, set the terminal into the right mode for handling input */ - raw(); /* curses raw mode */ + raw(); /* curses raw mode */ /* init the frame */ gator_basegwin.w_frame = gtxframe_Create(); @@ -163,9 +179,9 @@ int gator_cursesgwin_init(adebug) * Clear out the screen and return the good news. */ wclear(((struct gator_cursesgwin *)(gator_basegwin.w_data))->wp); - return(0); + return (0); -} /*gator_cursesgwin_init*/ +} /*gator_cursesgwin_init */ /*------------------------------------------------------------------------ * gator_cursesgwin_create @@ -187,60 +203,72 @@ int gator_cursesgwin_init(adebug) * As advertised. *------------------------------------------------------------------------*/ -struct gwin *gator_cursesgwin_create(params) - struct gator_cursesgwin_params *params; +struct gwin * +gator_cursesgwin_create(params) + struct gator_cursesgwin_params *params; -{ /*gator_cursesgwin_create*/ +{ /*gator_cursesgwin_create */ - static char rn[] = "gator_cursesgwin_create"; /*Routine name*/ - struct gwin *newgwin; /*Ptr to new curses window*/ - struct gator_cursesgwin *c_data; /*Ptr to curses-specific data*/ - WINDOW *newcursgwin; /*Ptr to new curses window*/ + static char rn[] = "gator_cursesgwin_create"; /*Routine name */ + struct gwin *newgwin; /*Ptr to new curses window */ + struct gator_cursesgwin *c_data; /*Ptr to curses-specific data */ + WINDOW *newcursgwin; /*Ptr to new curses window */ if (curses_debug) - fprintf(stderr, "[%s:%s] Allocating %d bytes for new gwin structure\n", mn, rn, sizeof(struct gwin)); - newgwin = (struct gwin *) malloc(sizeof(struct gwin)); - if (newgwin == (struct gwin *)0) { - fprintf(stderr, "[%s:%s] Can't malloc() %d bytes for new gwin structure: Errno is %d\n", mn, rn, sizeof(struct gwin), errno); - return((struct gwin *)0); + fprintf(stderr, + "[%s:%s] Allocating %d bytes for new gwin structure\n", mn, + rn, sizeof(struct gwin)); + newgwin = (struct gwin *)malloc(sizeof(struct gwin)); + if (newgwin == NULL) { + fprintf(stderr, + "[%s:%s] Can't malloc() %d bytes for new gwin structure: Errno is %d\n", + mn, rn, sizeof(struct gwin), errno); + return (NULL); } - newgwin->w_type = GATOR_WIN_CURSES; - newgwin->w_x = params->gwin_params.cr_x; - newgwin->w_y = params->gwin_params.cr_y; - newgwin->w_width = params->gwin_params.cr_width; - newgwin->w_height = params->gwin_params.cr_height; - newgwin->w_changed = 1; - newgwin->w_op = &curses_gwinops; - newgwin->w_parent = params->gwin_params.cr_parentwin; + newgwin->w_type = GATOR_WIN_CURSES; + newgwin->w_x = params->gwin_params.cr_x; + newgwin->w_y = params->gwin_params.cr_y; + newgwin->w_width = params->gwin_params.cr_width; + newgwin->w_height = params->gwin_params.cr_height; + newgwin->w_changed = 1; + newgwin->w_op = &curses_gwinops; + newgwin->w_parent = params->gwin_params.cr_parentwin; if (curses_debug) - fprintf(stderr, "[%s:%s] Allocating %d bytes for curses window private space\n", mn, rn, sizeof(struct gator_cursesgwin)); - c_data = (struct gator_cursesgwin *) malloc(sizeof(struct gator_cursesgwin)); - if (c_data == (struct gator_cursesgwin *)0){ - fprintf(stderr, "[%s:%s] Can't allocate %d bytes for curses window private space\n", mn, rn, sizeof(struct gator_cursesgwin)); + fprintf(stderr, + "[%s:%s] Allocating %d bytes for curses window private space\n", + mn, rn, sizeof(struct gator_cursesgwin)); + c_data = + (struct gator_cursesgwin *)malloc(sizeof(struct gator_cursesgwin)); + if (c_data == (struct gator_cursesgwin *)0) { + fprintf(stderr, + "[%s:%s] Can't allocate %d bytes for curses window private space\n", + mn, rn, sizeof(struct gator_cursesgwin)); free(newgwin); - return((struct gwin *)0); + return (NULL); } - newcursgwin = newwin(newgwin->w_height, /*Number of lines*/ - newgwin->w_width, /*Number of columns*/ - newgwin->w_y, /*Beginning y value*/ - newgwin->w_x); /*Beginning x value*/ - if (newcursgwin == (WINDOW *)0) { - fprintf(stderr, "[%s:%s] Failed to create curses window via newwin()\n", mn, rn); + newcursgwin = newwin(newgwin->w_height, /*Number of lines */ + newgwin->w_width, /*Number of columns */ + newgwin->w_y, /*Beginning y value */ + newgwin->w_x); /*Beginning x value */ + if (newcursgwin == (WINDOW *) 0) { + fprintf(stderr, + "[%s:%s] Failed to create curses window via newwin()\n", mn, + rn); free(newgwin); free(c_data); - return((struct gwin *)0); + return (NULL); } /* * Now, fill in the curses-specific window info. */ - c_data->wp = newcursgwin; - c_data->charwidth = params->charwidth; - c_data->charheight = params->charheight; - c_data->box_vertchar = params->box_vertchar; + c_data->wp = newcursgwin; + c_data->charwidth = params->charwidth; + c_data->charheight = params->charheight; + c_data->box_vertchar = params->box_vertchar; c_data->box_horizchar = params->box_horizchar; /* @@ -252,10 +280,10 @@ struct gwin *gator_cursesgwin_create(params) * Plug the curses private data into the generic window object, then * return the new window's info. */ - newgwin->w_data = (int *) c_data; - return(newgwin); + newgwin->w_data = (int *)c_data; + return (newgwin); -} /*gator_cursesgwin_create*/ +} /*gator_cursesgwin_create */ /*------------------------------------------------------------------------ * gator_cursesgwin_cleanup @@ -277,13 +305,14 @@ struct gwin *gator_cursesgwin_create(params) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_cleanup(gwp) - struct gwin *gwp; +int +gator_cursesgwin_cleanup(gwp) + struct gwin *gwp; -{ /*gator_cursesgwin_cleanup*/ +{ /*gator_cursesgwin_cleanup */ - static char rn[] = "gator_cursesgwin_cleanup"; /*Routine name*/ - struct gator_cursesgwin *cwp; /*Curses private area ptr*/ + static char rn[] = "gator_cursesgwin_cleanup"; /*Routine name */ + struct gator_cursesgwin *cwp; /*Curses private area ptr */ cwp = (struct gator_cursesgwin *)(gwp->w_data); @@ -292,7 +321,8 @@ int gator_cursesgwin_cleanup(gwp) * want to clear the screen before we go. */ if (curses_debug) - fprintf(stderr, "[%s:%s] Calling wclear() on window at 0x%x\n", mn, rn, cwp->wp); + fprintf(stderr, "[%s:%s] Calling wclear() on window at 0x%x\n", mn, + rn, cwp->wp); wclear(cwp->wp); wrefresh(cwp->wp); @@ -305,9 +335,9 @@ int gator_cursesgwin_cleanup(gwp) fprintf(stderr, "[%s:%s] Calling endwin()\n", mn, rn); endwin(); - return(0); + return (0); -} /*gator_cursesgwin_cleanup*/ +} /*gator_cursesgwin_cleanup */ /*------------------------------------------------------------------------ * gator_cursesgwin_box @@ -330,22 +360,24 @@ int gator_cursesgwin_cleanup(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_box(gwp) - struct gwin *gwp; +int +gator_cursesgwin_box(gwp) + struct gwin *gwp; -{ /*gator_cursesgwin_box*/ +{ /*gator_cursesgwin_box */ - static char rn[] = "gator_cursesgwin_box"; /*Routine name*/ - struct gator_cursesgwin *cwp; /*Ptr to curses private area*/ + static char rn[] = "gator_cursesgwin_box"; /*Routine name */ + struct gator_cursesgwin *cwp; /*Ptr to curses private area */ cwp = (struct gator_cursesgwin *)(gwp->w_data); if (curses_debug) - fprintf(stderr, "[%s:%s] Calling box() on window at 0x%x\n", mn, rn, cwp->wp); + fprintf(stderr, "[%s:%s] Calling box() on window at 0x%x\n", mn, rn, + cwp->wp); box(cwp->wp, cwp->box_vertchar, cwp->box_horizchar); - return(0); + return (0); -} /*gator_cursesgwin_box*/ +} /*gator_cursesgwin_box */ /*------------------------------------------------------------------------ * gator_cursesgwin_clear @@ -367,25 +399,27 @@ int gator_cursesgwin_box(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_clear(gwp) - struct gwin *gwp; +int +gator_cursesgwin_clear(gwp) + struct gwin *gwp; -{ /*gator_cursesgwin_clear*/ +{ /*gator_cursesgwin_clear */ - static char rn[] = "gator_cursesgwin_clear"; /*Routine name*/ - struct gator_cursesgwin *cwp; /*Ptr to curses private area*/ + static char rn[] = "gator_cursesgwin_clear"; /*Routine name */ + struct gator_cursesgwin *cwp; /*Ptr to curses private area */ /* * Clearing windows is very easy in curses; just one call will do it. */ cwp = (struct gator_cursesgwin *)(gwp->w_data); if (curses_debug) - fprintf(stderr, "[%s:%s] Calling wclear() on window at 0x%x\n", mn, rn, cwp->wp); + fprintf(stderr, "[%s:%s] Calling wclear() on window at 0x%x\n", mn, + rn, cwp->wp); wclear(cwp->wp); - return(0); + return (0); -} /*gator_cursesgwin_clear*/ +} /*gator_cursesgwin_clear */ /*------------------------------------------------------------------------ * gator_cursesgwin_destroy @@ -407,22 +441,24 @@ int gator_cursesgwin_clear(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_destroy(gwp) - struct gwin *gwp; +int +gator_cursesgwin_destroy(gwp) + struct gwin *gwp; -{ /*gator_cursesgwin_destroy*/ +{ /*gator_cursesgwin_destroy */ - static char rn[] = "gator_cursesgwin_destroy"; /*Routine name*/ - struct gator_cursesgwin *cwp; /*Ptr to curses private area*/ + static char rn[] = "gator_cursesgwin_destroy"; /*Routine name */ + struct gator_cursesgwin *cwp; /*Ptr to curses private area */ cwp = (struct gator_cursesgwin *)(gwp->w_data); if (curses_debug) - fprintf(stderr, "[%s:%s] Calling delwin() on window at 0x%x\n", mn, rn, cwp->wp); + fprintf(stderr, "[%s:%s] Calling delwin() on window at 0x%x\n", mn, + rn, cwp->wp); delwin(cwp->wp); - return(0); + return (0); -} /*gator_cursesgwin_destroy*/ +} /*gator_cursesgwin_destroy */ /*------------------------------------------------------------------------ * gator_cursesgwin_display @@ -444,21 +480,22 @@ int gator_cursesgwin_destroy(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_display(gwp) - struct gwin *gwp; +int +gator_cursesgwin_display(gwp) + struct gwin *gwp; -{ /*gator_cursesgwin_display*/ +{ /*gator_cursesgwin_display */ - struct gator_cursesgwin *cwp; /*Curses private area ptr*/ + struct gator_cursesgwin *cwp; /*Curses private area ptr */ cwp = (struct gator_cursesgwin *)(gwp->w_data); - wclear(cwp->wp); /* clear screen */ + wclear(cwp->wp); /* clear screen */ gtxframe_Display(gwp->w_frame, gwp); /* display the frame */ - wrefresh(cwp->wp); /* redraw the guy */ - return(0); + wrefresh(cwp->wp); /* redraw the guy */ + return (0); -} /*gator_cursesgwin_display*/ +} /*gator_cursesgwin_display */ /*------------------------------------------------------------------------ * gator_cursesgwin_drawline @@ -483,20 +520,22 @@ int gator_cursesgwin_display(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_drawline(gwp, params) - struct gwin *gwp; - struct gwin_lineparams *params; +int +gator_cursesgwin_drawline(gwp, params) + struct gwin *gwp; + struct gwin_lineparams *params; -{ /*gator_cursesgwin_drawline*/ +{ /*gator_cursesgwin_drawline */ - static char rn[] = "gator_cursesgwin_drawline"; /*Routine name*/ + static char rn[] = "gator_cursesgwin_drawline"; /*Routine name */ if (curses_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(0); + return (0); -} /*gator_cursesgwin_drawline*/ +} /*gator_cursesgwin_drawline */ /*------------------------------------------------------------------------ * gator_cursesgwin_drawrectangle @@ -520,20 +559,22 @@ int gator_cursesgwin_drawline(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_drawrectangle(gwp, params) - struct gwin *gwp; - struct gwin_rectparams *params; +int +gator_cursesgwin_drawrectangle(gwp, params) + struct gwin *gwp; + struct gwin_rectparams *params; -{ /*gator_cursesgwin_drawrectangle*/ +{ /*gator_cursesgwin_drawrectangle */ - static char rn[] = "gator_cursesgwin_drawrectangle"; /*Routine name*/ + static char rn[] = "gator_cursesgwin_drawrectangle"; /*Routine name */ if (curses_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(0); + return (0); -} /*gator_cursesgwin_drawrectangle*/ +} /*gator_cursesgwin_drawrectangle */ /*------------------------------------------------------------------------ * gator_cursesgwin_drawchar @@ -557,21 +598,25 @@ int gator_cursesgwin_drawrectangle(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_drawchar(gwp, params) - struct gwin *gwp; - struct gwin_charparams *params; +int +gator_cursesgwin_drawchar(gwp, params) + struct gwin *gwp; + struct gwin_charparams *params; -{ /*gator_cursesgwin_drawchar*/ +{ /*gator_cursesgwin_drawchar */ - static char rn[] = "gator_cursesgwin_drawchar"; /*Routine name*/ - struct gator_cursesgwin *cwp; /*Ptr to curses private area*/ - int curses_x, curses_y; /*Mapped x,y positions*/ + static char rn[] = "gator_cursesgwin_drawchar"; /*Routine name */ + struct gator_cursesgwin *cwp; /*Ptr to curses private area */ + int curses_x, curses_y; /*Mapped x,y positions */ cwp = (struct gator_cursesgwin *)(gwp->w_data); curses_x = GATOR_MAP_X_TO_COL(cwp, params->x); curses_y = GATOR_MAP_Y_TO_LINE(cwp, params->y); if (curses_debug) - fprintf(stderr, "[%s:%s] Drawing char '%c' on window at 0x%x at (%d, %d) [line %d, column %d]%s\n", mn, rn, params->c, cwp->wp, params->x, params->y, curses_y, curses_x, (params->highlight ? ", using standout mode" : "")); + fprintf(stderr, + "[%s:%s] Drawing char '%c' on window at 0x%x at (%d, %d) [line %d, column %d]%s\n", + mn, rn, params->c, cwp->wp, params->x, params->y, curses_y, + curses_x, (params->highlight ? ", using standout mode" : "")); wmove(cwp->wp, curses_y, curses_x); if (params->highlight) wstandout(cwp->wp); @@ -579,9 +624,9 @@ int gator_cursesgwin_drawchar(gwp, params) if (params->highlight) wstandend(cwp->wp); - return(0); + return (0); -} /*gator_cursesgwin_drawchar*/ +} /*gator_cursesgwin_drawchar */ /*------------------------------------------------------------------------ * gator_cursesgwin_drawstring @@ -605,21 +650,25 @@ int gator_cursesgwin_drawchar(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_drawstring(gwp, params) - struct gwin *gwp; - struct gwin_strparams *params; +int +gator_cursesgwin_drawstring(gwp, params) + struct gwin *gwp; + struct gwin_strparams *params; -{ /*gator_cursesgwin_drawstring*/ +{ /*gator_cursesgwin_drawstring */ - static char rn[] = "gator_cursesgwin_drawstring"; /*Routine name*/ - struct gator_cursesgwin *cwp; /*Ptr to curses private area*/ - int curses_x, curses_y; /*Mapped x,y positions*/ + static char rn[] = "gator_cursesgwin_drawstring"; /*Routine name */ + struct gator_cursesgwin *cwp; /*Ptr to curses private area */ + int curses_x, curses_y; /*Mapped x,y positions */ cwp = (struct gator_cursesgwin *)(gwp->w_data); curses_x = GATOR_MAP_X_TO_COL(cwp, params->x); curses_y = GATOR_MAP_Y_TO_LINE(cwp, params->y); if (curses_debug) - fprintf(stderr, "[%s:%s] Drawing string '%s' on window at 0x%x at (%d, %d) [line %d, column %d]%s\n", mn, rn, params->s, cwp->wp, params->x, params->y, curses_y, curses_x, (params->highlight ? ", using standout mode" : "")); + fprintf(stderr, + "[%s:%s] Drawing string '%s' on window at 0x%x at (%d, %d) [line %d, column %d]%s\n", + mn, rn, params->s, cwp->wp, params->x, params->y, curses_y, + curses_x, (params->highlight ? ", using standout mode" : "")); wmove(cwp->wp, curses_y, curses_x); if (params->highlight) wstandout(cwp->wp); @@ -627,9 +676,9 @@ int gator_cursesgwin_drawstring(gwp, params) if (params->highlight) wstandend(cwp->wp); - return(0); + return (0); -} /*gator_cursesgwin_drawstring*/ +} /*gator_cursesgwin_drawstring */ /*------------------------------------------------------------------------ * gator_cursesgwin_invert @@ -653,20 +702,22 @@ int gator_cursesgwin_drawstring(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_invert(gwp, params) - struct gwin *gwp; - struct gwin_invparams *params; +int +gator_cursesgwin_invert(gwp, params) + struct gwin *gwp; + struct gwin_invparams *params; -{ /*gator_cursesgwin_invert*/ +{ /*gator_cursesgwin_invert */ - static char rn[] = "gator_cursesgwin_invert"; /*Routine name*/ + static char rn[] = "gator_cursesgwin_invert"; /*Routine name */ if (curses_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(0); + return (0); -} /*gator_cursesgwin_invert*/ +} /*gator_cursesgwin_invert */ /*------------------------------------------------------------------------ * gator_cursesgwin_getchar @@ -688,14 +739,15 @@ int gator_cursesgwin_invert(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_getchar(gwp) - struct gwin *gwp; +int +gator_cursesgwin_getchar(gwp) + struct gwin *gwp; -{ /*gator_cursesgwin_getchar*/ +{ /*gator_cursesgwin_getchar */ - return(getc(stdin)); + return (getc(stdin)); -} /*gator_cursesgwin_getchar*/ +} /*gator_cursesgwin_getchar */ /*------------------------------------------------------------------------ * gator_cursesgwin_wait @@ -717,16 +769,17 @@ int gator_cursesgwin_getchar(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_wait(gwp) - struct gwin *gwp; +int +gator_cursesgwin_wait(gwp) + struct gwin *gwp; -{ /*gator_cursesgwin_wait*/ +{ /*gator_cursesgwin_wait */ while (!LWP_WaitForKeystroke(-1)); - return(0); + return (0); -} /*gator_cursesgwin_wait*/ +} /*gator_cursesgwin_wait */ /*------------------------------------------------------------------------ * gator_cursesgwin_getdimensions @@ -749,23 +802,27 @@ int gator_cursesgwin_wait(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_cursesgwin_getdimensions(gwp, aparms) - struct gwin_sizeparams *aparms; - struct gwin *gwp; +int +gator_cursesgwin_getdimensions(gwp, aparms) + struct gwin_sizeparams *aparms; + struct gwin *gwp; -{ /*gator_cursesgwin_getdimensions*/ +{ /*gator_cursesgwin_getdimensions */ - struct gator_cursesgwin *cwp; /*Curses-specific data*/ + struct gator_cursesgwin *cwp; /*Curses-specific data */ cwp = (struct gator_cursesgwin *)(gwp->w_data); #if defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN60_ENV) aparms->maxx = cwp->wp->maxx; aparms->maxy = cwp->wp->maxy; +#elif defined(AFS_NBSD_ENV) + aparms->maxx = getmaxx(cwp->wp); + aparms->maxy = getmaxy(cwp->wp); #else aparms->maxx = cwp->wp->_maxx; aparms->maxy = cwp->wp->_maxy; #endif - return(0); + return (0); -} /*gator_cursesgwin_getdimensions*/ +} /*gator_cursesgwin_getdimensions */ diff --git a/src/gtx/dumbwindows.c b/src/gtx/dumbwindows.c index 29f0943f7..aa62270d7 100644 --- a/src/gtx/dumbwindows.c +++ b/src/gtx/dumbwindows.c @@ -16,14 +16,15 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/dumbwindows.c,v 1.2 2003/01/02 03:55:50 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/dumbwindows.c,v 1.7 2003/07/15 23:15:12 shadow Exp $"); -#include "gtxdumbwin.h" /*Interface definition*/ -#include /*Standard I/O package*/ +#include "gtxdumbwin.h" /*Interface definition */ +#include /*Standard I/O package */ #include -int dumb_debug; /*Is debugging turned on?*/ -static char mn[] = "gator_dumbwindows"; /*Module name*/ +int dumb_debug; /*Is debugging turned on? */ +static char mn[] = "gator_dumbwindows"; /*Module name */ /* * Version of standard operations for a dumb window. @@ -75,12 +76,13 @@ struct gwinbaseops gator_dumb_gwinbops = { * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_init(adebug) - int adebug; +int +gator_dumbgwin_init(adebug) + int adebug; -{ /*gator_dumbgwin_init*/ +{ /*gator_dumbgwin_init */ - static char rn[] = "gator_dumbgwin_init"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_init"; /*Routine name */ /* * Remember if we'll be doing debugging, init dumb and clear the @@ -94,9 +96,9 @@ int gator_dumbgwin_init(adebug) /* * We always return success here. */ - return(0); + return (0); -} /*gator_dumbgwin_init*/ +} /*gator_dumbgwin_init */ /*------------------------------------------------------------------------ * gator_dumbgwin_create @@ -118,22 +120,23 @@ int gator_dumbgwin_init(adebug) * As advertised. *------------------------------------------------------------------------*/ -struct gwin *gator_dumbgwin_create(params) - struct gator_dumbgwin_params *params; +struct gwin * +gator_dumbgwin_create(params) + struct gator_dumbgwin_params *params; -{ /*gator_dumbgwin_create*/ +{ /*gator_dumbgwin_create */ - static char rn[] = "gator_dumbgwin_create"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_create"; /*Routine name */ if (dumb_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* - * Return failure here, fill this routine in at some point. - */ - return((struct gwin *)0); + * Return failure here, fill this routine in at some point. + */ + return (NULL); -} /*gator_dumbgwin_create*/ +} /*gator_dumbgwin_create */ /*------------------------------------------------------------------------ * gator_dumbgwin_cleanup @@ -155,12 +158,13 @@ struct gwin *gator_dumbgwin_create(params) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_cleanup(gwp) - struct gwin *gwp; +int +gator_dumbgwin_cleanup(gwp) + struct gwin *gwp; -{ /*gator_dumbgwin_cleanup*/ +{ /*gator_dumbgwin_cleanup */ - static char rn[] = "gator_dumbgwin_cleanup"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_cleanup"; /*Routine name */ if (dumb_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); @@ -168,9 +172,9 @@ int gator_dumbgwin_cleanup(gwp) /* * Return success here, fill this routine in at some point. */ - return(0); + return (0); -} /*gator_dumbgwin_cleanup*/ +} /*gator_dumbgwin_cleanup */ /*------------------------------------------------------------------------ * gator_dumbgwin_box @@ -193,22 +197,23 @@ int gator_dumbgwin_cleanup(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_box(gwp) - struct gwin *gwp; +int +gator_dumbgwin_box(gwp) + struct gwin *gwp; -{ /*gator_dumbgwin_box*/ +{ /*gator_dumbgwin_box */ - static char rn[] = "gator_dumbgwin_box"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_box"; /*Routine name */ if (dumb_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* - * Return success here, fill in the routine at some point. - */ - return(0); + * Return success here, fill in the routine at some point. + */ + return (0); -} /*gator_dumbgwin_box*/ +} /*gator_dumbgwin_box */ /*------------------------------------------------------------------------ * gator_dumbgwin_clear @@ -230,22 +235,23 @@ int gator_dumbgwin_box(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_clear(gwp) - struct gwin *gwp; +int +gator_dumbgwin_clear(gwp) + struct gwin *gwp; -{ /*gator_dumbgwin_clear*/ +{ /*gator_dumbgwin_clear */ - static char rn[] = "gator_dumbgwin_clear"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_clear"; /*Routine name */ if (dumb_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* - * Return success, fill in this routine at some point. - */ - return(0); + * Return success, fill in this routine at some point. + */ + return (0); -} /*gator_dumbgwin_clear*/ +} /*gator_dumbgwin_clear */ /*------------------------------------------------------------------------ * gator_dumbgwin_destroy @@ -267,19 +273,20 @@ int gator_dumbgwin_clear(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_destroy(gwp) - struct gwin *gwp; +int +gator_dumbgwin_destroy(gwp) + struct gwin *gwp; -{ /*gator_dumbgwin_destroy*/ +{ /*gator_dumbgwin_destroy */ - static char rn[] = "gator_dumbgwin_destroy"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_destroy"; /*Routine name */ if (dumb_debug) fprintf(stderr, "[%s:%s] Called", mn, rn); - return(0); + return (0); -} /*gator_dumbgwin_destroy*/ +} /*gator_dumbgwin_destroy */ /*------------------------------------------------------------------------ * gator_dumbgwin_display @@ -301,22 +308,23 @@ int gator_dumbgwin_destroy(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_display(gwp) - struct gwin *gwp; +int +gator_dumbgwin_display(gwp) + struct gwin *gwp; -{ /*gator_dumbgwin_display*/ +{ /*gator_dumbgwin_display */ - static char rn[] = "gator_dumbgwin_display"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_display"; /*Routine name */ if (dumb_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* - * Return success, fill in this routine at some point. - */ - return(0); + * Return success, fill in this routine at some point. + */ + return (0); -} /*gator_dumbgwin_display*/ +} /*gator_dumbgwin_display */ /*------------------------------------------------------------------------ * gator_dumbgwin_drawline @@ -341,23 +349,25 @@ int gator_dumbgwin_display(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_drawline(gwp, params) - struct gwin *gwp; - struct gwin_lineparams *params; +int +gator_dumbgwin_drawline(gwp, params) + struct gwin *gwp; + struct gwin_lineparams *params; -{ /*gator_dumbgwin_drawline*/ +{ /*gator_dumbgwin_drawline */ - static char rn[] = "gator_dumbgwin_drawline"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_drawline"; /*Routine name */ if (dumb_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); /* - * Return success, fill in this routine at some point. - */ - return(0); + * Return success, fill in this routine at some point. + */ + return (0); -} /*gator_dumbgwin_drawline*/ +} /*gator_dumbgwin_drawline */ /*------------------------------------------------------------------------ * gator_dumbgwin_drawrectangle @@ -381,23 +391,25 @@ int gator_dumbgwin_drawline(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_drawrectangle(gwp, params) - struct gwin *gwp; - struct gwin_rectparams *params; +int +gator_dumbgwin_drawrectangle(gwp, params) + struct gwin *gwp; + struct gwin_rectparams *params; -{ /*gator_dumbgwin_drawrectangle*/ +{ /*gator_dumbgwin_drawrectangle */ - static char rn[] = "gator_dumbgwin_drawrectangle"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_drawrectangle"; /*Routine name */ if (dumb_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); /* - * Return success, fill in this routine at some point. - */ - return(0); + * Return success, fill in this routine at some point. + */ + return (0); -} /*gator_dumbgwin_drawrectangle*/ +} /*gator_dumbgwin_drawrectangle */ /*------------------------------------------------------------------------ * gator_dumbgwin_drawchar @@ -421,23 +433,24 @@ int gator_dumbgwin_drawrectangle(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_drawchar(gwp, params) - struct gwin *gwp; - struct gwin_charparams *params; +int +gator_dumbgwin_drawchar(gwp, params) + struct gwin *gwp; + struct gwin_charparams *params; -{ /*gator_dumbgwin_drawchar*/ +{ /*gator_dumbgwin_drawchar */ - static char rn[] = "gator_dumbgwin_drawchar"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_drawchar"; /*Routine name */ if (dumb_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* - * Return success, fill in this routine at some point. - */ - return(0); + * Return success, fill in this routine at some point. + */ + return (0); -} /*gator_dumbgwin_drawchar*/ +} /*gator_dumbgwin_drawchar */ /*------------------------------------------------------------------------ * gator_dumbgwin_drawstring @@ -461,23 +474,24 @@ int gator_dumbgwin_drawchar(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_drawstring(gwp, params) - struct gwin *gwp; - struct gwin_strparams *params; +int +gator_dumbgwin_drawstring(gwp, params) + struct gwin *gwp; + struct gwin_strparams *params; -{ /*gator_dumbgwin_drawstring*/ +{ /*gator_dumbgwin_drawstring */ - static char rn[] = "gator_dumbgwin_drawstring"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_drawstring"; /*Routine name */ if (dumb_debug) fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* - * Return success, fill in this routine at some point. - */ - return(0); + * Return success, fill in this routine at some point. + */ + return (0); -} /*gator_dumbgwin_drawstring*/ +} /*gator_dumbgwin_drawstring */ /*------------------------------------------------------------------------ * gator_dumbgwin_invert @@ -501,23 +515,25 @@ int gator_dumbgwin_drawstring(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_invert(gwp, params) - struct gwin *gwp; - struct gwin_invparams *params; +int +gator_dumbgwin_invert(gwp, params) + struct gwin *gwp; + struct gwin_invparams *params; -{ /*gator_dumbgwin_invert*/ +{ /*gator_dumbgwin_invert */ - static char rn[] = "gator_dumbgwin_invert"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_invert"; /*Routine name */ if (dumb_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); /* - * Return success, fill in this routine at some point. - */ - return(0); + * Return success, fill in this routine at some point. + */ + return (0); -} /*gator_dumbgwin_invert*/ +} /*gator_dumbgwin_invert */ /*------------------------------------------------------------------------ * gator_dumbgwin_getchar @@ -539,19 +555,21 @@ int gator_dumbgwin_invert(gwp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_getchar(gwp) - struct gwin *gwp; +int +gator_dumbgwin_getchar(gwp) + struct gwin *gwp; -{ /*gator_dumbgwin_getchar*/ +{ /*gator_dumbgwin_getchar */ - static char rn[] = "gator_dumbgwin_getchar"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_getchar"; /*Routine name */ if (dumb_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(-1); + return (-1); -} /*gator_dumbgwin_getchar*/ +} /*gator_dumbgwin_getchar */ /*------------------------------------------------------------------------ * gator_dumbgwin_getdimensions @@ -574,20 +592,22 @@ int gator_dumbgwin_getchar(gwp) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_getdimensions(gwp, aparms) - struct gwin *gwp; - struct gwin_sizeparams *aparms; +int +gator_dumbgwin_getdimensions(gwp, aparms) + struct gwin *gwp; + struct gwin_sizeparams *aparms; -{/*gator_dumbgwin_getdimensions*/ +{ /*gator_dumbgwin_getdimensions */ - static char rn[] = "gator_dumbgwin_getdimensions"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_getdimensions"; /*Routine name */ if (dumb_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(-1); + return (-1); -} /*gator_dumbgwin_getdimensions*/ +} /*gator_dumbgwin_getdimensions */ /*------------------------------------------------------------------------ * gator_dumbgwin_wait @@ -609,16 +629,18 @@ int gator_dumbgwin_getdimensions(gwp, aparms) * As advertised. *------------------------------------------------------------------------*/ -int gator_dumbgwin_wait(gwp) - struct gwin *gwp; +int +gator_dumbgwin_wait(gwp) + struct gwin *gwp; -{ /*gator_dumbgwin_wait*/ +{ /*gator_dumbgwin_wait */ - static char rn[] = "gator_dumbgwin_wait"; /*Routine name*/ + static char rn[] = "gator_dumbgwin_wait"; /*Routine name */ if (dumb_debug) - fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, rn); + fprintf(stderr, "[%s:%s] This routine is currently a no-op\n", mn, + rn); - return(-1); + return (-1); -} /*gator_dumbgwin_wait*/ +} /*gator_dumbgwin_wait */ diff --git a/src/gtx/frame.c b/src/gtx/frame.c index ec2205297..1922c9d9b 100644 --- a/src/gtx/frame.c +++ b/src/gtx/frame.c @@ -11,13 +11,23 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/frame.c,v 1.1.1.5 2001/09/11 14:32:44 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/frame.c,v 1.7 2003/07/15 23:15:12 shadow Exp $"); #ifdef AFS_HPUX_ENV #include #endif #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#include + #include "gtxobjects.h" #include "gtxwindows.h" #include "gtxcurseswin.h" @@ -26,39 +36,45 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/frame.c,v 1.1.1.5 2001/09/11 14:32: #include "gtxframe.h" extern char *gtx_CopyString(); -static struct keymap_map *recursiveMap=0; -static char menubuffer[1024]; /*Buffer for menu selections*/ -int gtxframe_exitValue = 0; /*Program exit value*/ +static struct keymap_map *recursiveMap = 0; +static char menubuffer[1024]; /*Buffer for menu selections */ +int gtxframe_exitValue = 0; /*Program exit value */ gtxframe_CtrlUCmd(awindow, arock) -char *arock; -struct gwin *awindow; { + char *arock; + struct gwin *awindow; +{ struct gtx_frame *tframe; tframe = awindow->w_frame; - if (!tframe->defaultLine) return -1; + if (!tframe->defaultLine) + return -1; *(tframe->defaultLine) = 0; return 0; } gtxframe_CtrlHCmd(awindow, arock) -char *arock; -struct gwin *awindow; { + char *arock; + struct gwin *awindow; +{ register struct gtx_frame *tframe; register char *tp; register int pos; tframe = awindow->w_frame; - if (!(tp=tframe->defaultLine)) return -1; + if (!(tp = tframe->defaultLine)) + return -1; pos = strlen(tp); - if (pos == 0) return 0; /* rubout at the end of the line */ - tp[pos-1] = 0; + if (pos == 0) + return 0; /* rubout at the end of the line */ + tp[pos - 1] = 0; return 0; } gtxframe_RecursiveEndCmd(awindow, arock) -char *arock; -register struct gwin *awindow; { + char *arock; + register struct gwin *awindow; +{ register struct gtx_frame *tframe; tframe = awindow->w_frame; @@ -68,8 +84,9 @@ register struct gwin *awindow; { } gtxframe_RecursiveErrCmd(awindow, arock) -char *arock; -register struct gwin *awindow; { + char *arock; + register struct gwin *awindow; +{ register struct gtx_frame *tframe; tframe = awindow->w_frame; @@ -79,74 +96,55 @@ register struct gwin *awindow; { } gtxframe_SelfInsertCmd(awindow, arock) -int arock; -struct gwin *awindow; { + int arock; + struct gwin *awindow; +{ register struct gtx_frame *tframe; register int pos; register char *tp; tframe = awindow->w_frame; - if (!(tp = tframe->defaultLine)) return -1; + if (!(tp = tframe->defaultLine)) + return -1; pos = strlen(tp); - tp[pos] = arock; /* arock has char to insert */ - tp[pos+1] = 0; /* null-terminate it, too */ + tp[pos] = arock; /* arock has char to insert */ + tp[pos + 1] = 0; /* null-terminate it, too */ return 0; } /* save map, setup recursive map and install it */ -static SaveMap(aframe) -register struct gtx_frame *aframe; { +static +SaveMap(aframe) + register struct gtx_frame *aframe; +{ char tstring[2]; register int i; if (!recursiveMap) { /* setup recursive edit map if not previously done */ recursiveMap = keymap_Create(); - keymap_BindToString(recursiveMap, - "\010", - gtxframe_CtrlHCmd, - (char *) 0, - (char *) 0); - keymap_BindToString(recursiveMap, - "\177",gtxframe_CtrlHCmd, - (char *) 0, - (char *) 0); - keymap_BindToString(recursiveMap, - "\025", - gtxframe_CtrlUCmd, - (char *) 0, - (char *) 0); - keymap_BindToString(recursiveMap, - "\033", - gtxframe_RecursiveEndCmd, - (char *) 0, - (char *) 0); - keymap_BindToString(recursiveMap, - "\015", - gtxframe_RecursiveEndCmd, - (char *) 0, - (char *) 0); - keymap_BindToString(recursiveMap, - "\012", - gtxframe_RecursiveEndCmd, - (char *) 0, - (char *) 0); - keymap_BindToString(recursiveMap, - "\003", - gtxframe_RecursiveErrCmd, - (char *) 0, - (char *) 0); - keymap_BindToString(recursiveMap, - "\007", - gtxframe_RecursiveErrCmd, - (char *) 0, - (char *) 0); - - for(i=040; i<0177; i++) { + keymap_BindToString(recursiveMap, "\010", gtxframe_CtrlHCmd, NULL, + NULL); + keymap_BindToString(recursiveMap, "\177", gtxframe_CtrlHCmd, NULL, + NULL); + keymap_BindToString(recursiveMap, "\025", gtxframe_CtrlUCmd, NULL, + NULL); + keymap_BindToString(recursiveMap, "\033", gtxframe_RecursiveEndCmd, + NULL, NULL); + keymap_BindToString(recursiveMap, "\015", gtxframe_RecursiveEndCmd, + NULL, NULL); + keymap_BindToString(recursiveMap, "\012", gtxframe_RecursiveEndCmd, + NULL, NULL); + keymap_BindToString(recursiveMap, "\003", gtxframe_RecursiveErrCmd, + NULL, NULL); + keymap_BindToString(recursiveMap, "\007", gtxframe_RecursiveErrCmd, + NULL, NULL); + + for (i = 040; i < 0177; i++) { tstring[0] = i; tstring[1] = 0; keymap_BindToString(recursiveMap, tstring, gtxframe_SelfInsertCmd, - (char *) 0, i); + NULL, i); } } aframe->savemap = aframe->keymap; @@ -156,50 +154,56 @@ register struct gtx_frame *aframe; { } /* Restore map to previous value */ -static RestoreMap(aframe) -register struct gtx_frame *aframe; { +static +RestoreMap(aframe) + register struct gtx_frame *aframe; +{ aframe->keymap = aframe->savemap; - aframe->savemap = (struct keymap_map *) 0; + aframe->savemap = (struct keymap_map *)0; keymap_InitState(aframe->keystate, aframe->keymap); return 0; } gtxframe_SetFrame(awin, aframe) -struct gtx_frame *aframe; -struct gwin *awin; { + struct gtx_frame *aframe; + struct gwin *awin; +{ if (awin->w_frame) { /* Unthread this frame */ - awin->w_frame->window = (struct gwin *) 0; + awin->w_frame->window = NULL; } awin->w_frame = aframe; aframe->window = awin; /* Set frame's window ptr */ return 0; } -struct gtx_frame *gtxframe_GetFrame(awin) -struct gwin *awin; { +struct gtx_frame * +gtxframe_GetFrame(awin) + struct gwin *awin; +{ return awin->w_frame; } /* Add a menu string to display list */ gtxframe_AddMenu(aframe, alabel, astring) -char *alabel; -char *astring; -struct gtx_frame *aframe; { + char *alabel; + char *astring; + struct gtx_frame *aframe; +{ register struct gtxframe_menu *tmenu; if (aframe->menus) - for(tmenu = aframe->menus; tmenu; tmenu = tmenu->next) { - if (strcmp(alabel, tmenu->name)==0) break; - } - else - tmenu = (struct gtxframe_menu *)0; + for (tmenu = aframe->menus; tmenu; tmenu = tmenu->next) { + if (strcmp(alabel, tmenu->name) == 0) + break; + } else + tmenu = (struct gtxframe_menu *)0; if (!tmenu) { /* Handle everything but the command string, which is handled by the - common-case code below */ - tmenu = (struct gtxframe_menu *) malloc(sizeof(*tmenu)); + * common-case code below */ + tmenu = (struct gtxframe_menu *)malloc(sizeof(*tmenu)); if (tmenu == (struct gtxframe_menu *)0) - return(-1); + return (-1); memset(tmenu, 0, sizeof(*tmenu)); tmenu->next = aframe->menus; aframe->menus = tmenu; @@ -207,59 +211,62 @@ struct gtx_frame *aframe; { } /* - * Common case: redo the string labels. Note: at this point, tmenu - * points to a valid menu. - */ + * Common case: redo the string labels. Note: at this point, tmenu + * points to a valid menu. + */ if (tmenu->cmdString) - free(tmenu->cmdString); + free(tmenu->cmdString); tmenu->cmdString = gtx_CopyString(astring); return 0; } /* Delete a given menu from a frame*/ gtxframe_DeleteMenu(aframe, alabel) -struct gtx_frame *aframe; -char *alabel; { + struct gtx_frame *aframe; + char *alabel; +{ register struct gtxframe_menu *tm, **lm; - for(lm = &aframe->menus, tm = *lm; tm; lm = &tm->next, tm = *lm) { + for (lm = &aframe->menus, tm = *lm; tm; lm = &tm->next, tm = *lm) { if (strcmp(alabel, tm->name) == 0) { /* found it, remove and return success */ - *lm = tm->next; /* unthread from list */ + *lm = tm->next; /* unthread from list */ free(tm->name); free(tm->cmdString); free(tm); - return(0); + return (0); } } - return(-1); /* failed to find entry to delete */ + return (-1); /* failed to find entry to delete */ } /* Function to remove all known menus */ gtxframe_ClearMenus(aframe) -struct gtx_frame *aframe; { + struct gtx_frame *aframe; +{ register struct gtxframe_menu *tm, *nm; if (aframe->menus != (struct gtxframe_menu *)0) { - for(tm=aframe->menus; tm; tm=nm) { - nm = tm->next; - free(tm->name); - free(tm->cmdString); - free(tm); - } + for (tm = aframe->menus; tm; tm = nm) { + nm = tm->next; + free(tm->name); + free(tm->cmdString); + free(tm); + } } - aframe->menus = (struct gtxframe_menu *) 0; + aframe->menus = (struct gtxframe_menu *)0; return 0; } gtxframe_AskForString(aframe, aprompt, adefault, aresult, aresultSize) -register struct gtx_frame *aframe; -char *aprompt; -char *adefault; -char *aresult; -int aresultSize; { + register struct gtx_frame *aframe; + char *aprompt; + char *adefault; + char *aresult; + int aresultSize; +{ register int code; register char *tp; @@ -272,9 +279,9 @@ int aresultSize; { if (aframe->defaultLine) free(aframe->defaultLine); aframe->promptLine = gtx_CopyString(aprompt); - tp = aframe->defaultLine = (char *) malloc(1024); - if (tp == (char *)0) - return(-1); + tp = aframe->defaultLine = (char *)malloc(1024); + if (tp == NULL) + return (-1); if (adefault) strcpy(tp, adefault); else @@ -290,7 +297,7 @@ int aresultSize; { goto done; } code = strlen(tp); - if (code+1 > aresultSize) { + if (code + 1 > aresultSize) { code = -2; goto done; } @@ -304,39 +311,44 @@ int aresultSize; { free(aframe->promptLine); if (aframe->defaultLine) free(aframe->defaultLine); - aframe->defaultLine = aframe->promptLine = (char *) 0; + aframe->defaultLine = aframe->promptLine = NULL; if (code) gtxframe_DisplayString(aframe, "[Aborted]"); - return(code); + return (code); } gtxframe_DisplayString(aframe, amsgLine) -char *amsgLine; -register struct gtx_frame *aframe; { + char *amsgLine; + register struct gtx_frame *aframe; +{ if (aframe->messageLine) - free(aframe->messageLine); + free(aframe->messageLine); aframe->messageLine = gtx_CopyString(amsgLine); } /* Called by input processor to try to clear the dude */ gtxframe_ClearMessageLine(aframe) -struct gtx_frame *aframe; { + struct gtx_frame *aframe; +{ /* If we haven't shown message long enough yet, just return */ if (aframe->flags & GTXFRAME_NEWDISPLAY) - return(0); + return (0); if (aframe->messageLine) free(aframe->messageLine); - aframe->messageLine = (char *) 0; - return(0); + aframe->messageLine = NULL; + return (0); } -static ShowMessageLine(aframe) -struct gtx_frame *aframe; { +static +ShowMessageLine(aframe) + struct gtx_frame *aframe; +{ struct gwin_strparams strparms; struct gwin_sizeparams sizeparms; register char *tp; - if (!aframe->window) return -1; + if (!aframe->window) + return -1; /* First, find window size */ WOP_GETDIMENSIONS(aframe->window, &sizeparms); @@ -344,34 +356,34 @@ struct gtx_frame *aframe; { if (aframe->promptLine) { memset(&strparms, 0, sizeof(strparms)); strparms.x = 0; - strparms.y = sizeparms.maxy-1; + strparms.y = sizeparms.maxy - 1; strparms.highlight = 1; - tp = strparms.s = (char *) malloc(1024); + tp = strparms.s = (char *)malloc(1024); strcpy(tp, aframe->promptLine); strcat(tp, aframe->defaultLine); WOP_DRAWSTRING(aframe->window, &strparms); aframe->flags |= GTXFRAME_NEWDISPLAY; - } - else if (aframe->messageLine) { + } else if (aframe->messageLine) { /* Otherwise we're visible, print the message at the bottom */ memset(&strparms, 0, sizeof(strparms)); strparms.highlight = 1; strparms.x = 0; - strparms.y = sizeparms.maxy-1; + strparms.y = sizeparms.maxy - 1; strparms.s = aframe->messageLine; WOP_DRAWSTRING(aframe->window, &strparms); aframe->flags |= GTXFRAME_NEWDISPLAY; } - return(0); + return (0); } /* Exit function, returning whatever has been put in its argument */ -int gtxframe_ExitCmd(a_exitValuep) - char *a_exitValuep; +int +gtxframe_ExitCmd(a_exitValuep) + char *a_exitValuep; -{ /*gtxframe_ExitCmd*/ +{ /*gtxframe_ExitCmd */ - int exitval; /*Value we've been asked to exit with*/ + int exitval; /*Value we've been asked to exit with */ /* This next call should be type independent! */ gator_cursesgwin_cleanup(&gator_basegwin); @@ -379,166 +391,170 @@ int gtxframe_ExitCmd(a_exitValuep) exitval = *((int *)(a_exitValuep)); exit(exitval); -} /*gtxframe_ExitCmd*/ +} /*gtxframe_ExitCmd */ -struct gtx_frame *gtxframe_Create() { +struct gtx_frame * +gtxframe_Create() +{ struct gtx_frame *tframe; struct keymap_map *newkeymap; struct keymap_state *newkeystate; /* - * Allocate all the pieces first: frame, keymap, and key state. - */ - tframe = (struct gtx_frame *) malloc (sizeof(struct gtx_frame)); + * Allocate all the pieces first: frame, keymap, and key state. + */ + tframe = (struct gtx_frame *)malloc(sizeof(struct gtx_frame)); if (tframe == (struct gtx_frame *)0) { - return((struct gtx_frame *)0); + return ((struct gtx_frame *)0); } newkeymap = keymap_Create(); if (newkeymap == (struct keymap_map *)0) { - /* - * Get rid of the frame before exiting. - */ - free(tframe); - return((struct gtx_frame *)0); + /* + * Get rid of the frame before exiting. + */ + free(tframe); + return ((struct gtx_frame *)0); } newkeystate = (struct keymap_state *) - malloc(sizeof(struct keymap_state)); + malloc(sizeof(struct keymap_state)); if (newkeystate == (struct keymap_state *)0) { - /* - * Get rid of the frame AND the keymap before exiting. - */ - free(tframe); - free(newkeymap); - return((struct gtx_frame *)0); + /* + * Get rid of the frame AND the keymap before exiting. + */ + free(tframe); + free(newkeymap); + return ((struct gtx_frame *)0); } /* - * Now that all the pieces exist, fill them in and stick them in - * the right places. - */ + * Now that all the pieces exist, fill them in and stick them in + * the right places. + */ memset(tframe, 0, sizeof(struct gtx_frame)); - tframe->keymap = newkeymap; + tframe->keymap = newkeymap; tframe->keystate = newkeystate; keymap_InitState(tframe->keystate, tframe->keymap); - keymap_BindToString(tframe->keymap, - "\003", - gtxframe_ExitCmd, - "ExitCmd", - (char *) (>xframe_exitValue)); + keymap_BindToString(tframe->keymap, "\003", gtxframe_ExitCmd, "ExitCmd", + (char *)(>xframe_exitValue)); /* - * At this point, we return successfully. - */ - return(tframe); + * At this point, we return successfully. + */ + return (tframe); } gtxframe_Delete(aframe) -register struct gtx_frame *aframe; { + register struct gtx_frame *aframe; +{ keymap_Delete(aframe->keymap); free(aframe->keystate); if (aframe->messageLine) - free(aframe->messageLine); + free(aframe->messageLine); free(aframe); return 0; } gtxframe_Display(aframe, awm) -struct gwin *awm; -register struct gtx_frame *aframe; { + struct gwin *awm; + register struct gtx_frame *aframe; +{ register struct gtxframe_dlist *tlist; register struct gtxframe_menu *tm; struct gwin_strparams strparms; /* Run through the menus, displaying them on the top line */ *menubuffer = 0; - for(tm = aframe->menus; tm; tm = tm->next) { + for (tm = aframe->menus; tm; tm = tm->next) { strcat(menubuffer, tm->name); strcat(menubuffer, ":"); strcat(menubuffer, tm->cmdString); strcat(menubuffer, " "); } if (menubuffer[0] != 0) { - memset(&strparms, 0, sizeof(strparms)); - strparms.x = 0; - strparms.y = 0; - strparms.s = menubuffer; - strparms.highlight = 1; - WOP_DRAWSTRING(awm, &strparms); + memset(&strparms, 0, sizeof(strparms)); + strparms.x = 0; + strparms.y = 0; + strparms.s = menubuffer; + strparms.highlight = 1; + WOP_DRAWSTRING(awm, &strparms); } /* Run through the display list, displaying all objects */ - for(tlist=aframe->display; tlist; tlist=tlist->next) { + for (tlist = aframe->display; tlist; tlist = tlist->next) { OOP_DISPLAY(((struct onode *)(tlist->data))); } /* Finally, show the message line */ ShowMessageLine(awm->w_frame); - return(0); + return (0); } /* Add an object to a window's display list */ gtxframe_AddToList(aframe, aobj) -struct onode *aobj; -register struct gtx_frame *aframe; { + struct onode *aobj; + register struct gtx_frame *aframe; +{ register struct gtxframe_dlist *tlist; - for(tlist = aframe->display; tlist; tlist=tlist->next) { - if (tlist->data == (char *) aobj) { - /* - * Don't add the same thing twice. - */ - return(-1); + for (tlist = aframe->display; tlist; tlist = tlist->next) { + if (tlist->data == (char *)aobj) { + /* + * Don't add the same thing twice. + */ + return (-1); } } /* - * OK, it's not alreadyt there. Create a new list object, fill it - * in, and splice it on. - */ - tlist = (struct gtxframe_dlist *) malloc(sizeof(struct gtxframe_dlist)); + * OK, it's not alreadyt there. Create a new list object, fill it + * in, and splice it on. + */ + tlist = (struct gtxframe_dlist *)malloc(sizeof(struct gtxframe_dlist)); if (tlist == (struct gtxframe_dlist *)0) - return(-1); - tlist->data = (char *) aobj; + return (-1); + tlist->data = (char *)aobj; tlist->next = aframe->display; aframe->display = tlist; - return(0); + return (0); } /* Remove an object from a display list, if it is already there */ gtxframe_RemoveFromList(aframe, aobj) -struct onode *aobj; -register struct gtx_frame *aframe; { + struct onode *aobj; + register struct gtx_frame *aframe; +{ register struct gtxframe_dlist *tlist, **plist; - + plist = &aframe->display; - for(tlist = *plist; tlist; plist = &tlist->next, tlist = *plist) { - if (tlist->data == (char *) aobj) { + for (tlist = *plist; tlist; plist = &tlist->next, tlist = *plist) { + if (tlist->data == (char *)aobj) { *plist = tlist->next; free(tlist); return 0; } } - return(-1); /* Item not found */ + return (-1); /* Item not found */ } /* Clear out everything on the display list for the given frame*/ gtxframe_ClearList(aframe) -register struct gtx_frame *aframe; { + register struct gtx_frame *aframe; +{ register struct gtxframe_dlist *tlist, *nlist; if (aframe->display != (struct gtxframe_dlist *)0) { - /* - * Throw away each display list structure (we have at least - * one). - */ - for(tlist = aframe->display; tlist; tlist = nlist) { - nlist = tlist->next; - free(tlist); - } + /* + * Throw away each display list structure (we have at least + * one). + */ + for (tlist = aframe->display; tlist; tlist = nlist) { + nlist = tlist->next; + free(tlist); + } } - aframe->display = (struct gtxframe_dlist *) 0; + aframe->display = (struct gtxframe_dlist *)0; return 0; } diff --git a/src/gtx/gtxX11win.h b/src/gtx/gtxX11win.h index fe16a13ed..c1bfe3a5c 100644 --- a/src/gtx/gtxX11win.h +++ b/src/gtx/gtxX11win.h @@ -10,7 +10,7 @@ #ifndef __gator_X11windows_h #define __gator_X11windows_h 1 -#include "gtxwindows.h" /*Base gator window dfns */ +#include "gtxwindows.h" /*Base gator window dfns */ /*Value for gwin w_type field*/ #define GATOR_WIN_X11 3 @@ -18,19 +18,19 @@ /*Private data for a X11 gwin*/ #if 0 struct gator_X11gwin { - WINDOW *wp; /*Window pointer*/ - int charwidth; /*Character width in pixels*/ - int charheight; /*Character height in pixels*/ - char box_vertchar; /*Vertical char for boxing purposes*/ - char box_horizchar; /*Horizontal char for boxing purposes*/ + WINDOW *wp; /*Window pointer */ + int charwidth; /*Character width in pixels */ + int charheight; /*Character height in pixels */ + char box_vertchar; /*Vertical char for boxing purposes */ + char box_horizchar; /*Horizontal char for boxing purposes */ }; #endif /* 0 */ /*X11 gwin's creation parameters*/ struct gator_X11gwin_params { - struct gwin_createparams gwin_params; /*Basic params for the window*/ - char box_vertchar; /*Vertical char for boxing purposes*/ - char box_horizchar; /*Horizontal char for boxing purposes*/ + struct gwin_createparams gwin_params; /*Basic params for the window */ + char box_vertchar; /*Vertical char for boxing purposes */ + char box_horizchar; /*Horizontal char for boxing purposes */ }; /*X11 initialization routine*/ @@ -41,11 +41,11 @@ extern int gator_X11gwin_init(); * Initialize the X11 window package. * * Args: - * int adebug: Is debugging turned on? + * int adebug: Is debugging turned on? * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ /*X11 window's creation routine*/ @@ -56,11 +56,11 @@ extern struct gwin *gator_X11gwin_create(); * Create a X11 window. * * Args: - * struct gator_X11gwin_params *params : Ptr to creation parameters. + * struct gator_X11gwin_params *params : Ptr to creation parameters. * * Returns: - * Ptr to the created X11 window structure if successful, - * Error value otherwise. + * Ptr to the created X11 window structure if successful, + * Error value otherwise. */ /*X11 cleanup routine*/ @@ -71,11 +71,11 @@ extern int gator_X11gwin_cleanup(); * Clean up after the X11 window package. * * Args: - * struct gwin *gwp : Ptr to base window. + * struct gwin *gwp : Ptr to base window. * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ extern struct gwinbaseops gator_X11_gwinbops; @@ -88,12 +88,12 @@ extern int gator_X11gwin_box(); * Draw a box around the given X11 window. * * Args: - * struct gwin *gwp : Ptr to the X11 window to draw - * a box around. + * struct gwin *gwp : Ptr to the X11 window to draw + * a box around. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_clear(); @@ -102,12 +102,12 @@ extern int gator_X11gwin_clear(); * Clear out the given X11 window. * * Args: - * struct gwin *gwp : Ptr to the X11 window to clear - * out. + * struct gwin *gwp : Ptr to the X11 window to clear + * out. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_destroy(); @@ -116,11 +116,11 @@ extern int gator_X11gwin_destroy(); * Destroy the given X11 window. * * Args: - * struct gwin *gwp : Ptr to the X11 window to destroy. + * struct gwin *gwp : Ptr to the X11 window to destroy. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_display(); @@ -129,11 +129,11 @@ extern int gator_X11gwin_display(); * Display/redraw the given X11 window. * * Args: - * struct gwin *gwp : Ptr to the X11 window to draw. + * struct gwin *gwp : Ptr to the X11 window to draw. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_drawline(); @@ -143,13 +143,13 @@ extern int gator_X11gwin_drawline(); * window. * * Args: - * struct gwin *gwp : Ptr to the X11 window in which - * the line is to be drawn. - * struct gwin_lineparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the X11 window in which + * the line is to be drawn. + * struct gwin_lineparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_drawrectangle(); @@ -158,13 +158,13 @@ extern int gator_X11gwin_drawrectangle(); * Draw a rectangle in the given X11 window. * * Args: - * struct gwin *gwp : Ptr to the X11 window in which - * the rectangle is to be drawn. - * struct gwin_rectparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the X11 window in which + * the rectangle is to be drawn. + * struct gwin_rectparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_drawchar(); @@ -173,13 +173,13 @@ extern int gator_X11gwin_drawchar(); * Draw a character in the given X11 window. * * Args: - * struct gwin *gwp : Ptr to the X11 window in which - * the character is to be drawn. - * struct gwin_charparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the X11 window in which + * the character is to be drawn. + * struct gwin_charparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_drawstring(); @@ -188,13 +188,13 @@ extern int gator_X11gwin_drawstring(); * Draw a string in the given X11 window. * * Args: - * struct gwin *gwp : Ptr to the X11 window in which - * the string is to be drawn. - * struct gwin_strparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the X11 window in which + * the string is to be drawn. + * struct gwin_strparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_invert(); @@ -203,13 +203,13 @@ extern int gator_X11gwin_invert(); * Invert a region in the given X11 window. * * Args: - * struct gwin *gwp : Ptr to the X11 window in which - * the inverted region lies. - * struct gwin_invparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the X11 window in which + * the inverted region lies. + * struct gwin_invparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_X11gwin_getchar(); diff --git a/src/gtx/gtxcurseswin.h b/src/gtx/gtxcurseswin.h index 1267a650b..c47339471 100644 --- a/src/gtx/gtxcurseswin.h +++ b/src/gtx/gtxcurseswin.h @@ -10,14 +10,14 @@ #ifndef __gator_curseswindows_h #define __gator_curseswindows_h 1 -#include "gtxwindows.h" /*Base gator window dfns*/ +#include "gtxwindows.h" /*Base gator window dfns */ #if defined(AFS_HPUX110_ENV) && !defined(__HP_CURSES) #define __HP_CURSES #endif #ifdef AFS_LINUX20_ENV -#include /*Curses library*/ +#include /*Curses library */ #else -#include /*Curses library*/ +#include /*Curses library */ #endif /*Value for gwin w_type field*/ @@ -25,20 +25,20 @@ /*Private data for a curses gwin*/ struct gator_cursesgwin { - WINDOW *wp; /*Window pointer*/ - int charwidth; /*Character width in pixels*/ - int charheight; /*Character height in pixels*/ - char box_vertchar; /*Vertical char for boxing purposes*/ - char box_horizchar; /*Horizontal char for boxing purposes*/ + WINDOW *wp; /*Window pointer */ + int charwidth; /*Character width in pixels */ + int charheight; /*Character height in pixels */ + char box_vertchar; /*Vertical char for boxing purposes */ + char box_horizchar; /*Horizontal char for boxing purposes */ }; /*Curses gwin's creation parameters*/ struct gator_cursesgwin_params { - struct gwin_createparams gwin_params; /*Basic params for the window*/ - int charwidth; /*Character width in pixels*/ - int charheight; /*Character height in pixels*/ - char box_vertchar; /*Vertical char for boxing purposes*/ - char box_horizchar; /*Horizontal char for boxing purposes*/ + struct gwin_createparams gwin_params; /*Basic params for the window */ + int charwidth; /*Character width in pixels */ + int charheight; /*Character height in pixels */ + char box_vertchar; /*Vertical char for boxing purposes */ + char box_horizchar; /*Horizontal char for boxing purposes */ }; /*Curses initialization routine*/ @@ -49,11 +49,11 @@ extern int gator_cursesgwin_init(); * Initialize the curses window package. * * Args: - * int adebug: Is debugging turned on? + * int adebug: Is debugging turned on? * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ /*Curses window's creation routine*/ @@ -64,11 +64,11 @@ extern struct gwin *gator_cursesgwin_create(); * Create a curses window. * * Args: - * struct gator_cursesgwin_params *params : Ptr to creation parameters. + * struct gator_cursesgwin_params *params : Ptr to creation parameters. * * Returns: - * Ptr to the created curses window structure if successful, - * Error value otherwise. + * Ptr to the created curses window structure if successful, + * Error value otherwise. */ /*Curses cleanup routine*/ @@ -79,11 +79,11 @@ extern int gator_cursesgwin_cleanup(); * Clean up after the curses window package. * * Args: - * struct gwin *gwp : Ptr to base window. + * struct gwin *gwp : Ptr to base window. * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ extern struct gwinbaseops gator_curses_gwinbops; @@ -96,12 +96,12 @@ extern int gator_cursesgwin_box(); * Draw a box around the given curses window. * * Args: - * struct gwin *gwp : Ptr to the curses window to draw - * a box around. + * struct gwin *gwp : Ptr to the curses window to draw + * a box around. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_clear(); @@ -110,12 +110,12 @@ extern int gator_cursesgwin_clear(); * Clear out the given curses window. * * Args: - * struct gwin *gwp : Ptr to the curses window to clear - * out. + * struct gwin *gwp : Ptr to the curses window to clear + * out. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_destroy(); @@ -124,11 +124,11 @@ extern int gator_cursesgwin_destroy(); * Destroy the given curses window. * * Args: - * struct gwin *gwp : Ptr to the curses window to destroy. + * struct gwin *gwp : Ptr to the curses window to destroy. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_display(); @@ -137,11 +137,11 @@ extern int gator_cursesgwin_display(); * Display/redraw the given curses window. * * Args: - * struct gwin *gwp : Ptr to the curses window to draw. + * struct gwin *gwp : Ptr to the curses window to draw. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_drawline(); @@ -151,13 +151,13 @@ extern int gator_cursesgwin_drawline(); * window. * * Args: - * struct gwin *gwp : Ptr to the curses window in which - * the line is to be drawn. - * struct gwin_lineparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the curses window in which + * the line is to be drawn. + * struct gwin_lineparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_drawrectangle(); @@ -166,13 +166,13 @@ extern int gator_cursesgwin_drawrectangle(); * Draw a rectangle in the given curses window. * * Args: - * struct gwin *gwp : Ptr to the curses window in which - * the rectangle is to be drawn. - * struct gwin_rectparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the curses window in which + * the rectangle is to be drawn. + * struct gwin_rectparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_drawchar(); @@ -181,13 +181,13 @@ extern int gator_cursesgwin_drawchar(); * Draw a character in the given curses window. * * Args: - * struct gwin *gwp : Ptr to the curses window in which - * the character is to be drawn. - * struct gwin_charparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the curses window in which + * the character is to be drawn. + * struct gwin_charparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_drawstring(); @@ -196,13 +196,13 @@ extern int gator_cursesgwin_drawstring(); * Draw a string in the given curses window. * * Args: - * struct gwin *gwp : Ptr to the curses window in which - * the string is to be drawn. - * struct gwin_strparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the curses window in which + * the string is to be drawn. + * struct gwin_strparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_invert(); @@ -211,13 +211,13 @@ extern int gator_cursesgwin_invert(); * Invert a region in the given curses window. * * Args: - * struct gwin *gwp : Ptr to the curses window in which - * the inverted region lies. - * struct gwin_invparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the curses window in which + * the inverted region lies. + * struct gwin_invparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_cursesgwin_getchar(); diff --git a/src/gtx/gtxdumbwin.h b/src/gtx/gtxdumbwin.h index 03197344a..ce24ca92d 100644 --- a/src/gtx/gtxdumbwin.h +++ b/src/gtx/gtxdumbwin.h @@ -10,7 +10,7 @@ #ifndef __gator_dumbwindows_h #define __gator_dumbwindows_h 1 -#include "gtxwindows.h" /*Base gator window dfns*/ +#include "gtxwindows.h" /*Base gator window dfns */ /*Value for gwin w_type field*/ #define GATOR_WIN_DUMB 1 @@ -18,19 +18,19 @@ /*Private data for a dumb gwin*/ #if 0 struct gator_dumbgwin { - WINDOW *wp; /*Window pointer*/ - int charwidth; /*Character width in pixels*/ - int charheight; /*Character height in pixels*/ - char box_vertchar; /*Vertical char for boxing purposes*/ - char box_horizchar; /*Horizontal char for boxing purposes*/ + WINDOW *wp; /*Window pointer */ + int charwidth; /*Character width in pixels */ + int charheight; /*Character height in pixels */ + char box_vertchar; /*Vertical char for boxing purposes */ + char box_horizchar; /*Horizontal char for boxing purposes */ }; #endif /* 0 */ /*Dumb gwin's creation parameters*/ struct gator_dumbgwin_params { - struct gwin_createparams gwin_params; /*Basic params for the window*/ - char box_vertchar; /*Vertical char for boxing purposes*/ - char box_horizchar; /*Horizontal char for boxing purposes*/ + struct gwin_createparams gwin_params; /*Basic params for the window */ + char box_vertchar; /*Vertical char for boxing purposes */ + char box_horizchar; /*Horizontal char for boxing purposes */ }; /*Dumb windows initialization routine*/ @@ -41,11 +41,11 @@ extern int gator_dumbgwin_init(); * Initialize the dumb window package. * * Args: - * int adebug: Is debugging turned on? + * int adebug: Is debugging turned on? * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ /*Dumb window's creation routine*/ @@ -56,11 +56,11 @@ extern struct gwin *gator_dumbgwin_create(); * Create a dumb window. * * Args: - * struct gator_dumbgwin_params *params : Ptr to creation parameters. + * struct gator_dumbgwin_params *params : Ptr to creation parameters. * * Returns: - * Ptr to the created dumb window structure if successful, - * Error value otherwise. + * Ptr to the created dumb window structure if successful, + * Error value otherwise. */ /*Dumb cleanup routine*/ @@ -71,11 +71,11 @@ extern int gator_dumbgwin_cleanup(); * Clean up after the dumb window package. * * Args: - * struct gwin *gwp : Ptr to base window. + * struct gwin *gwp : Ptr to base window. * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ extern struct gwinbaseops gator_dumb_gwinbops; @@ -88,12 +88,12 @@ extern int gator_dumbgwin_box(); * Draw a box around the given dumb window. * * Args: - * struct gwin *gwp : Ptr to the dumb window to draw - * a box around. + * struct gwin *gwp : Ptr to the dumb window to draw + * a box around. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_clear(); @@ -102,12 +102,12 @@ extern int gator_dumbgwin_clear(); * Clear out the given dumb window. * * Args: - * struct gwin *gwp : Ptr to the dumb window to clear - * out. + * struct gwin *gwp : Ptr to the dumb window to clear + * out. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_destroy(); @@ -116,11 +116,11 @@ extern int gator_dumbgwin_destroy(); * Destroy the given dumb window. * * Args: - * struct gwin *gwp : Ptr to the dumb window to destroy. + * struct gwin *gwp : Ptr to the dumb window to destroy. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_display(); @@ -129,11 +129,11 @@ extern int gator_dumbgwin_display(); * Display/redraw the given dumb window. * * Args: - * struct gwin *gwp : Ptr to the dumb window to draw. + * struct gwin *gwp : Ptr to the dumb window to draw. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_drawline(); @@ -143,13 +143,13 @@ extern int gator_dumbgwin_drawline(); * window. * * Args: - * struct gwin *gwp : Ptr to the dumb window in which - * the line is to be drawn. - * struct gwin_lineparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the dumb window in which + * the line is to be drawn. + * struct gwin_lineparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_drawrectangle(); @@ -158,13 +158,13 @@ extern int gator_dumbgwin_drawrectangle(); * Draw a rectangle in the given dumb window. * * Args: - * struct gwin *gwp : Ptr to the dumb window in which - * the rectangle is to be drawn. - * struct gwin_rectparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the dumb window in which + * the rectangle is to be drawn. + * struct gwin_rectparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_drawchar(); @@ -173,13 +173,13 @@ extern int gator_dumbgwin_drawchar(); * Draw a character in the given dumb window. * * Args: - * struct gwin *gwp : Ptr to the dumb window in which - * the character is to be drawn. - * struct gwin_charparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the dumb window in which + * the character is to be drawn. + * struct gwin_charparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_drawstring(); @@ -188,13 +188,13 @@ extern int gator_dumbgwin_drawstring(); * Draw a string in the given dumb window. * * Args: - * struct gwin *gwp : Ptr to the dumb window in which - * the string is to be drawn. - * struct gwin_strparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the dumb window in which + * the string is to be drawn. + * struct gwin_strparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_invert(); @@ -203,13 +203,13 @@ extern int gator_dumbgwin_invert(); * Invert a region in the given dumb window. * * Args: - * struct gwin *gwp : Ptr to the dumb window in which - * the inverted region lies. - * struct gwin_invparams *params : Ptr to other params. + * struct gwin *gwp : Ptr to the dumb window in which + * the inverted region lies. + * struct gwin_invparams *params : Ptr to other params. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_dumbgwin_getchar(); diff --git a/src/gtx/gtxframe.h b/src/gtx/gtxframe.h index 647c5f586..d3a3ef62b 100644 --- a/src/gtx/gtxframe.h +++ b/src/gtx/gtxframe.h @@ -21,15 +21,15 @@ struct gtxframe_menu { }; struct gtx_frame { - struct keymap_map *keymap; /*Map for handling keystrokes */ - struct keymap_map *savemap; /* Map saved during recursive edit */ + struct keymap_map *keymap; /*Map for handling keystrokes */ + struct keymap_map *savemap; /* Map saved during recursive edit */ struct keymap_state *keystate; /*Associated key state */ struct gtxframe_dlist *display; /*Display list */ struct gtxframe_menu *menus; /* Menu list */ - char *messageLine; /* message line */ - char *promptLine; /* prompt for a response */ - char *defaultLine; /* default response */ - struct gwin *window; /* window we're currently showing on */ + char *messageLine; /* message line */ + char *promptLine; /* prompt for a response */ + char *defaultLine; /* default response */ + struct gwin *window; /* window we're currently showing on */ int flags; }; diff --git a/src/gtx/gtxkeymap.h b/src/gtx/gtxkeymap.h index f708bc0ba..bcbc1f71b 100644 --- a/src/gtx/gtxkeymap.h +++ b/src/gtx/gtxkeymap.h @@ -14,26 +14,26 @@ #define KEYMAP_NENTRIES 256 /* types of keymaps */ -#define KEYMAP_EMPTY 0 /* nothing in this slot */ -#define KEYMAP_PROC 1 /* procedure in this slot */ -#define KEYMAP_SUBMAP 2 /* submap in this slot */ +#define KEYMAP_EMPTY 0 /* nothing in this slot */ +#define KEYMAP_PROC 1 /* procedure in this slot */ +#define KEYMAP_SUBMAP 2 /* submap in this slot */ /* one per entry */ struct keymap_entry { - char type; /* type, e.g. submap, etc */ - char pad[3]; /* padding */ - char *name; /* descriptive name of function, if function */ - union { /* value (proc, submap, etc) */ - int (*proc)(); + char type; /* type, e.g. submap, etc */ + char pad[3]; /* padding */ + char *name; /* descriptive name of function, if function */ + union { /* value (proc, submap, etc) */ + int (*proc) (); struct keymap_map *submap; char *generic; } u; - char *rock; /* rock to use */ + char *rock; /* rock to use */ }; struct keymap_map { - short refcount; /* reference count */ - char pad[2]; /* padding to afs_int32 boundary */ + short refcount; /* reference count */ + char pad[2]; /* padding to afs_int32 boundary */ struct keymap_entry entries[KEYMAP_NENTRIES]; }; @@ -49,4 +49,4 @@ extern int keymap_InitState(); extern int keymap_ProcessState(); extern int keymap_ResetState(); -#endif /* define for file */ +#endif /* define for file */ diff --git a/src/gtx/gtxlightobj.h b/src/gtx/gtxlightobj.h index 213def681..c3ae51c56 100644 --- a/src/gtx/gtxlightobj.h +++ b/src/gtx/gtxlightobj.h @@ -10,36 +10,36 @@ #ifndef __gator_lightobject_h #define __gator_lightobject_h 1 -#include "gtxobjects.h" /*Basic gator object definitions*/ +#include "gtxobjects.h" /*Basic gator object definitions */ /*Value for onode o_type field*/ #define GATOR_OBJ_LIGHT 1 /*Light masks*/ -#define GATOR_LIGHTMASK_OUTLINE 0x1 /*Outline the light?*/ -#define GATOR_LIGHTMASK_INVVIDEO 0x2 /*Show light in inverse video?*/ -#define GATOR_LIGHTMASK_FLASH 0x4 /*Flash light when turned on?*/ -#define GATOR_LIGHTMASK_FLASHCYCLE 0x8 /*Current flash cycle*/ +#define GATOR_LIGHTMASK_OUTLINE 0x1 /*Outline the light? */ +#define GATOR_LIGHTMASK_INVVIDEO 0x2 /*Show light in inverse video? */ +#define GATOR_LIGHTMASK_FLASH 0x4 /*Flash light when turned on? */ +#define GATOR_LIGHTMASK_FLASHCYCLE 0x8 /*Current flash cycle */ -#define GATOR_LABEL_CHARS 128 /*Max chars in light label*/ +#define GATOR_LABEL_CHARS 128 /*Max chars in light label */ /*Private data for light onode*/ struct gator_lightobj { - int *llrock; /*Rock for lower-level graphics layer*/ - int setting; /*Is light on or off*/ - int appearance; /*Bit array describing light's appearance*/ - int flashfreq; /*Flashing frequency in msecs*/ - int lasttoggletime; /*Last time ``flashed''*/ - char label[GATOR_LABEL_CHARS]; /*Light label*/ + int *llrock; /*Rock for lower-level graphics layer */ + int setting; /*Is light on or off */ + int appearance; /*Bit array describing light's appearance */ + int flashfreq; /*Flashing frequency in msecs */ + int lasttoggletime; /*Last time ``flashed'' */ + char label[GATOR_LABEL_CHARS]; /*Light label */ }; /*Light object's creation parameters*/ struct gator_light_crparams { - struct onode_createparams onode_params; /*Creation params for the whole onode*/ - int appearance; /*General appearance*/ - int flashfreq; /*Flash frequency in msecs, if any*/ - char label[GATOR_LABEL_CHARS]; /*Light label*/ - int label_x, label_y; /*X,Y offsets for label within light*/ + struct onode_createparams onode_params; /*Creation params for the whole onode */ + int appearance; /*General appearance */ + int flashfreq; /*Flash frequency in msecs, if any */ + char label[GATOR_LABEL_CHARS]; /*Light label */ + int label_x, label_y; /*X,Y offsets for label within light */ }; /*Light object's creation routine*/ @@ -50,14 +50,14 @@ extern int gator_light_create(); * Create a gator light object. * * Args: - * struct onode *light_onp : Ptr to the light onode to fill out. - * struct onode_createparams *params : Ptr to creation params. + * struct onode *light_onp : Ptr to the light onode to fill out. + * struct onode_createparams *params : Ptr to creation params. * (Note: this actually points to a gator_light_crparams * structure, but we use the generic version of the ptr) * * Returns: - * Zero if successful, - * Error value otherwise. + * Zero if successful, + * Error value otherwise. */ /*Light object's generic onode routines*/ @@ -68,11 +68,11 @@ extern int gator_light_destroy(); * Destroy a gator light object. * * Args: - * struct onode *onp : Ptr to the light onode to delete. + * struct onode *onp : Ptr to the light onode to delete. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_light_display(); @@ -81,11 +81,11 @@ extern int gator_light_display(); * Display/redraw a gator light object. * * Args: - * struct onode *onp: Ptr to the light onode to display. + * struct onode *onp: Ptr to the light onode to display. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_light_release(); @@ -94,12 +94,12 @@ extern int gator_light_release(); * Drop the refcount on a gator light object. * * Args: - * struct onode *onp : Ptr to the onode whose refcount is + * struct onode *onp : Ptr to the onode whose refcount is * to be dropped. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ /* @@ -112,12 +112,12 @@ extern int gator_light_set(); * Set the value of the given gator light object. * * Args: - * struct onode *onp : Ptr to the light onode to be set. - * int setting : Non-zero for ``on'', zero for ``off''. + * struct onode *onp : Ptr to the light onode to be set. + * int setting : Non-zero for ``on'', zero for ``off''. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ /* diff --git a/src/gtx/gtxobjdict.h b/src/gtx/gtxobjdict.h index a75433364..598a1f8f3 100644 --- a/src/gtx/gtxobjdict.h +++ b/src/gtx/gtxobjdict.h @@ -16,7 +16,7 @@ * Definitions for the gator object dictionary. *--------------------------------------------------------------------------------*/ -#include "gtxobjects.h" /*Standard gator object defns*/ +#include "gtxobjects.h" /*Standard gator object defns */ extern int gator_objdict_init(); /* @@ -24,11 +24,11 @@ extern int gator_objdict_init(); * Initialize the gator object dictionary package. * * Args: - * int adebug: Is debugging output turned on? + * int adebug: Is debugging output turned on? * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ extern int gator_objdict_add(); @@ -37,11 +37,11 @@ extern int gator_objdict_add(); * Add an entry to the gator object dictionary. * * Args: - * struct onode *objtoadd: Ptr to object to add. + * struct onode *objtoadd: Ptr to object to add. * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ extern int gator_objdict_delete(); @@ -50,11 +50,11 @@ extern int gator_objdict_delete(); * Delete an entry from the gator object dictionary. * * Args: - * struct onode *objtodelete: Ptr to object to delete. + * struct onode *objtodelete: Ptr to object to delete. * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ extern struct onode *gator_objdict_lookup(); @@ -63,11 +63,11 @@ extern struct onode *gator_objdict_lookup(); * Look up a gator object by name. * * Args: - * char *nametofind: String name of desired onode. + * char *nametofind: String name of desired onode. * * Returns: - * Ptr to desired onode if successful, - * Null pointer otherwise. + * Ptr to desired onode if successful, + * Null pointer otherwise. */ #endif /* __gator_objdict_h */ diff --git a/src/gtx/gtxobjects.h b/src/gtx/gtxobjects.h index 71a930216..6a3d92435 100644 --- a/src/gtx/gtxobjects.h +++ b/src/gtx/gtxobjects.h @@ -16,7 +16,7 @@ * Constants and data structures defining the basis for a gator object. *--------------------------------------------------------------------------------*/ -#include "gtxwindows.h" /*Standard window defs & ops*/ +#include "gtxwindows.h" /*Standard window defs & ops */ /*Max number of chars in an object name*/ #define GATOR_OBJNAMELEN 128 @@ -26,20 +26,20 @@ * onode for each gator object. */ struct onode { - int o_type; /*Object type*/ - char o_name[GATOR_OBJNAMELEN]; /*Object's string name*/ - int o_x, o_y; /*X and Y coordinates*/ - int o_width, o_height; /*Width & height in pixels*/ - int o_changed; /*Changed since last refresh?*/ - short o_refcount; /*Reference count*/ - struct gwin *o_window; /*Object's associated graphical window*/ - struct onodeops *o_op; /*Object's operations*/ - struct onode *o_home; /*Ptr to home object*/ - struct onode *o_help; /*Ptr to help object, if any*/ - struct onode *o_nextobj; /*Ptr to next queued object, if any*/ - struct onode *o_upobj; /*Ptr to parent (up) object, if any*/ - struct onode *o_downobj; /*Ptr to child (down) object, if any*/ - int *o_data; /*Ptr to object's private data region*/ + int o_type; /*Object type */ + char o_name[GATOR_OBJNAMELEN]; /*Object's string name */ + int o_x, o_y; /*X and Y coordinates */ + int o_width, o_height; /*Width & height in pixels */ + int o_changed; /*Changed since last refresh? */ + short o_refcount; /*Reference count */ + struct gwin *o_window; /*Object's associated graphical window */ + struct onodeops *o_op; /*Object's operations */ + struct onode *o_home; /*Ptr to home object */ + struct onode *o_help; /*Ptr to help object, if any */ + struct onode *o_nextobj; /*Ptr to next queued object, if any */ + struct onode *o_upobj; /*Ptr to parent (up) object, if any */ + struct onode *o_downobj; /*Ptr to child (down) object, if any */ + int *o_data; /*Ptr to object's private data region */ }; /* @@ -50,9 +50,9 @@ struct onode { * slots. */ struct onodeops { - int (*on_destroy)(); /*Destroy an onode*/ - int (*on_display)(); /*Display an onode*/ - int (*on_release)(); /*Decrement an onode ref count*/ + int (*on_destroy) (); /*Destroy an onode */ + int (*on_display) (); /*Display an onode */ + int (*on_release) (); /*Decrement an onode ref count */ }; /* @@ -66,23 +66,23 @@ struct onodeops { * Initialization parameters for an onode. */ struct onode_initparams { - int i_debug; /*Turn debugging on?*/ - struct gwin_initparams *i_gwparams; /*Ptr to window init params*/ + int i_debug; /*Turn debugging on? */ + struct gwin_initparams *i_gwparams; /*Ptr to window init params */ }; /* * Creation parameters for an onode. */ struct onode_createparams { - int cr_type; /*Type of onode*/ - char cr_name[GATOR_OBJNAMELEN]; /*Object name*/ - int cr_x, cr_y; /*X and Y coordinates*/ - int cr_width, cr_height; /*Width & height in pixels*/ - struct gwin *cr_window; /*Graphical window to use*/ - struct onode *cr_home_obj; /*Home object*/ - struct onode *cr_prev_obj; /*Object having this one as next*/ - struct onode *cr_parent_obj; /*This object's parent*/ - char *cr_helpstring; /*Ptr to object's help text*/ + int cr_type; /*Type of onode */ + char cr_name[GATOR_OBJNAMELEN]; /*Object name */ + int cr_x, cr_y; /*X and Y coordinates */ + int cr_width, cr_height; /*Width & height in pixels */ + struct gwin *cr_window; /*Graphical window to use */ + struct onode *cr_home_obj; /*Home object */ + struct onode *cr_prev_obj; /*Object having this one as next */ + struct onode *cr_parent_obj; /*This object's parent */ + char *cr_helpstring; /*Ptr to object's help text */ }; /* @@ -96,11 +96,11 @@ extern int gator_objects_init(); * Initialize the gator object package. * * Args: - * struct onode_initparams *params: Initialization parameters. + * struct onode_initparams *params: Initialization parameters. * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ extern struct onode *gator_objects_create(); @@ -109,11 +109,11 @@ extern struct onode *gator_objects_create(); * Create an onode of the given type. * * Args: - * struct onode_createparams *params: Ptr to creation params. + * struct onode_createparams *params: Ptr to creation params. * * Returns: - * Ptr to newly-created onode if successful, - * Null pointer otherwise. + * Ptr to newly-created onode if successful, + * Null pointer otherwise. */ extern struct onode *gator_objects_lookup(); @@ -122,11 +122,11 @@ extern struct onode *gator_objects_lookup(); * Look up a gator onode by name. * * Args: - * char *onode_name: Onode string name to find. + * char *onode_name: Onode string name to find. * * Returns: - * Ptr to onode matching the given name if one exists, - * Null pointer otherwise. + * Ptr to onode matching the given name if one exists, + * Null pointer otherwise. */ #endif /* __gator_objects_h */ diff --git a/src/gtx/gtxtest.c b/src/gtx/gtxtest.c index cbc67ce57..06c7b33d2 100644 --- a/src/gtx/gtxtest.c +++ b/src/gtx/gtxtest.c @@ -10,7 +10,17 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/gtxtest.c,v 1.1.1.4 2001/07/14 22:22:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/gtxtest.c,v 1.6 2003/07/15 23:15:12 shadow Exp $"); + + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include "gtxwindows.h" #include "gtxobjects.h" @@ -23,23 +33,25 @@ struct gtx_frame *frameA, *frameB; struct onode *objectA, *objectB; struct onode *lightA, *lightB; -static int ChangeMenuCmd(awin, arock) -afs_int32 arock; -register struct gwin *awin; { +static int +ChangeMenuCmd(awin, arock) + afs_int32 arock; + register struct gwin *awin; +{ register struct gtx_frame *tf; register afs_int32 code; tf = awin->w_frame; - if (!tf) return -1; + if (!tf) + return -1; if (arock == 1) { gtxframe_ClearMenus(tf); - } - else if (arock == 2) { + } else if (arock == 2) { code = gtxframe_DeleteMenu(tf, "NewLabel"); - if (code) gtxframe_DisplayString(tf, "Can't delete menu!"); - } - else if (arock == 3) { + if (code) + gtxframe_DisplayString(tf, "Can't delete menu!"); + } else if (arock == 3) { code = gtxframe_ClearMenus(tf); gtxframe_AddMenu(frameA, "FrameB", "b"); gtxframe_AddMenu(frameA, "NewLabel", "c"); @@ -47,23 +59,25 @@ register struct gwin *awin; { return 0; } -static int ChangeListCmd(awin, arock) -afs_int32 arock; -register struct gwin *awin; { +static int +ChangeListCmd(awin, arock) + afs_int32 arock; + register struct gwin *awin; +{ register struct gtx_frame *tf; register afs_int32 code; tf = awin->w_frame; - if (!tf) return -1; + if (!tf) + return -1; if (arock == 1) { gtxframe_ClearList(tf); - } - else if (arock == 2) { + } else if (arock == 2) { code = gtxframe_RemoveFromList(tf, lightA); - if (code) gtxframe_DisplayString(tf, "Can't delete light!"); - } - else if (arock == 3) { + if (code) + gtxframe_DisplayString(tf, "Can't delete light!"); + } else if (arock == 3) { code = gtxframe_ClearList(tf); gtxframe_AddToList(frameA, objectA); gtxframe_AddToList(frameA, lightA); @@ -71,19 +85,25 @@ register struct gwin *awin; { return 0; } -static int NoCallCmd(awin) -struct gwin *awin; { - gtxframe_DisplayString(awin->w_frame, "Function should be mapped on '$d', not 'd'"); +static int +NoCallCmd(awin) + struct gwin *awin; +{ + gtxframe_DisplayString(awin->w_frame, + "Function should be mapped on '$d', not 'd'"); return 0; } -static int ChangeCmd(awin) -struct gwin *awin; { +static int +ChangeCmd(awin) + struct gwin *awin; +{ char tbuffer[100]; register afs_int32 code; - code = gtxframe_AskForString(awin->w_frame, "New object string: ", "TestNew", - tbuffer, sizeof(tbuffer)); + code = + gtxframe_AskForString(awin->w_frame, "New object string: ", "TestNew", + tbuffer, sizeof(tbuffer)); if (code == 0) { /* have new value, write it to object A */ gator_text_Write(objectA, tbuffer, 0, 0, 0); @@ -91,27 +111,35 @@ struct gwin *awin; { return 0; } -static int StupidCmd(awin) -struct gwin *awin; { - gtxframe_DisplayString(awin->w_frame, "You're already showing that frame!"); +static int +StupidCmd(awin) + struct gwin *awin; +{ + gtxframe_DisplayString(awin->w_frame, + "You're already showing that frame!"); return 0; } -static int SwitchToACmd(awin) -struct gwin *awin; { +static int +SwitchToACmd(awin) + struct gwin *awin; +{ gtxframe_SetFrame(awin, frameA); return 0; } -static int SwitchToBCmd(awin) -struct gwin *awin; { +static int +SwitchToBCmd(awin) + struct gwin *awin; +{ gtxframe_SetFrame(awin, frameB); return 0; } #include "AFS_component_version_number.c" -main() { +main() +{ struct gwin *win; struct gator_textobj_params textcrparams; struct gator_light_crparams lightcrparams; @@ -120,59 +148,62 @@ main() { win = gtx_Init(0, -1); /* create a couple of objects, a and b, and have the "a" and "b" keys - switch the display from one to the other */ - textcrparams.onode_params.cr_type = GATOR_OBJ_TEXT; + * switch the display from one to the other */ + textcrparams.onode_params.cr_type = GATOR_OBJ_TEXT; strcpy(textcrparams.onode_params.cr_name, "Text1-A"); - textcrparams.onode_params.cr_x = 30; - textcrparams.onode_params.cr_y = 10; - textcrparams.onode_params.cr_width = 35; - textcrparams.onode_params.cr_height = 7; - textcrparams.onode_params.cr_window = win; /* ???? */ - textcrparams.onode_params.cr_home_obj = (struct onode *)0; - textcrparams.onode_params.cr_prev_obj = (struct onode *)0; - textcrparams.onode_params.cr_parent_obj = (struct onode *)0; + textcrparams.onode_params.cr_x = 30; + textcrparams.onode_params.cr_y = 10; + textcrparams.onode_params.cr_width = 35; + textcrparams.onode_params.cr_height = 7; + textcrparams.onode_params.cr_window = win; /* ???? */ + textcrparams.onode_params.cr_home_obj = NULL; + textcrparams.onode_params.cr_prev_obj = NULL; + textcrparams.onode_params.cr_parent_obj = NULL; textcrparams.onode_params.cr_helpstring = "Help string for text"; - textcrparams.maxEntries = 7; + textcrparams.maxEntries = 7; textcrparams.maxCharsPerEntry = 35; - objectA = gator_objects_create((struct onode_createparams *)(&textcrparams)); + objectA = + gator_objects_create((struct onode_createparams *)(&textcrparams)); gator_text_Write(objectA, "This is object A", 0, 0, 0); - + /* create a couple of objects, a and b, and have the "a" and "b" keys - switch the display from one to the other */ - textcrparams.onode_params.cr_type = GATOR_OBJ_TEXT; + * switch the display from one to the other */ + textcrparams.onode_params.cr_type = GATOR_OBJ_TEXT; strcpy(textcrparams.onode_params.cr_name, "Text2-B"); - textcrparams.onode_params.cr_x = 30; - textcrparams.onode_params.cr_y = 10; - textcrparams.onode_params.cr_width = 35; - textcrparams.onode_params.cr_height = 7; - textcrparams.onode_params.cr_window = win; /* ???? */ - textcrparams.onode_params.cr_home_obj = (struct onode *)0; - textcrparams.onode_params.cr_prev_obj = (struct onode *)0; - textcrparams.onode_params.cr_parent_obj = (struct onode *)0; + textcrparams.onode_params.cr_x = 30; + textcrparams.onode_params.cr_y = 10; + textcrparams.onode_params.cr_width = 35; + textcrparams.onode_params.cr_height = 7; + textcrparams.onode_params.cr_window = win; /* ???? */ + textcrparams.onode_params.cr_home_obj = NULL; + textcrparams.onode_params.cr_prev_obj = NULL; + textcrparams.onode_params.cr_parent_obj = NULL; textcrparams.onode_params.cr_helpstring = "Help string for text"; - textcrparams.maxEntries = 7; + textcrparams.maxEntries = 7; textcrparams.maxCharsPerEntry = 35; - objectB = gator_objects_create((struct onode_createparams *)(&textcrparams)); + objectB = + gator_objects_create((struct onode_createparams *)(&textcrparams)); gator_text_Write(objectB, "This is object B", 0, 0, 0); - lightcrparams.onode_params.cr_type = GATOR_OBJ_LIGHT; - lightcrparams.onode_params.cr_x = 10; - lightcrparams.onode_params.cr_y = 10; - lightcrparams.onode_params.cr_width = 10; - lightcrparams.onode_params.cr_height = 10; - lightcrparams.onode_params.cr_window = win; /* ???? */ - lightcrparams.onode_params.cr_home_obj = (struct onode *)0; - lightcrparams.onode_params.cr_prev_obj = (struct onode *)0; - lightcrparams.onode_params.cr_parent_obj = (struct onode *)0; + lightcrparams.onode_params.cr_type = GATOR_OBJ_LIGHT; + lightcrparams.onode_params.cr_x = 10; + lightcrparams.onode_params.cr_y = 10; + lightcrparams.onode_params.cr_width = 10; + lightcrparams.onode_params.cr_height = 10; + lightcrparams.onode_params.cr_window = win; /* ???? */ + lightcrparams.onode_params.cr_home_obj = NULL; + lightcrparams.onode_params.cr_prev_obj = NULL; + lightcrparams.onode_params.cr_parent_obj = NULL; lightcrparams.onode_params.cr_helpstring = "Help string for text"; strcpy(lightcrparams.label, "Light-1"); lightcrparams.label_x = 0; lightcrparams.label_y = 0; lightcrparams.flashfreq = 100; lightcrparams.appearance = GATOR_LIGHTMASK_INVVIDEO; - lightA = gator_objects_create((struct onode_createparams *)(&lightcrparams)); + lightA = + gator_objects_create((struct onode_createparams *)(&lightcrparams)); /* create basic frames */ frameA = gtxframe_Create(); @@ -182,26 +213,32 @@ main() { gtxframe_ClearList(frameA); gtxframe_AddToList(frameA, objectA); gtxframe_AddToList(frameA, lightA); - keymap_BindToString(frameA->keymap, "b", SwitchToBCmd, (char *) 0, (char *) 0); - keymap_BindToString(frameA->keymap, "a", StupidCmd, (char *) 0, (char *) 0); - keymap_BindToString(frameA->keymap, "c", ChangeCmd, (char *) 0, (char *) 0); - keymap_BindToString(frameA->keymap, "\033a", ChangeMenuCmd, "ChangeMenu", (char *) 1); - keymap_BindToString(frameA->keymap, "\033b", ChangeMenuCmd, "ChangeMenu", (char *) 2); - keymap_BindToString(frameA->keymap, "\033c", ChangeMenuCmd, "ChangeMenu", (char *) 3); - keymap_BindToString(frameA->keymap, "\0331", ChangeListCmd, "ChangeList", (char *) 1); - keymap_BindToString(frameA->keymap, "\0332", ChangeListCmd, "ChangeList", (char *) 2); - keymap_BindToString(frameA->keymap, "\0333", ChangeListCmd, "ChangeList", (char *) 3); + keymap_BindToString(frameA->keymap, "b", SwitchToBCmd, NULL, NULL); + keymap_BindToString(frameA->keymap, "a", StupidCmd, NULL, NULL); + keymap_BindToString(frameA->keymap, "c", ChangeCmd, NULL, NULL); + keymap_BindToString(frameA->keymap, "\033a", ChangeMenuCmd, "ChangeMenu", + (char *)1); + keymap_BindToString(frameA->keymap, "\033b", ChangeMenuCmd, "ChangeMenu", + (char *)2); + keymap_BindToString(frameA->keymap, "\033c", ChangeMenuCmd, "ChangeMenu", + (char *)3); + keymap_BindToString(frameA->keymap, "\0331", ChangeListCmd, "ChangeList", + (char *)1); + keymap_BindToString(frameA->keymap, "\0332", ChangeListCmd, "ChangeList", + (char *)2); + keymap_BindToString(frameA->keymap, "\0333", ChangeListCmd, "ChangeList", + (char *)3); gtxframe_AddMenu(frameA, "FrameB", "b"); gtxframe_AddMenu(frameA, "NewLabel", "c"); /* setup B's frame */ gtxframe_ClearList(frameB); gtxframe_AddToList(frameB, objectB); - keymap_BindToString(frameB->keymap, "a", SwitchToACmd, (char *) 0, (char *) 0); - keymap_BindToString(frameB->keymap, "b", StupidCmd, (char *) 0, (char *) 0); - keymap_BindToString(frameB->keymap, "d", NoCallCmd, (char *) 0, (char *) 0); - keymap_BindToString(frameB->keymap, "d", (int (*)()) 0, (char *) 0, (char *) 0); - keymap_BindToString(frameB->keymap, "\033d", NoCallCmd, (char *) 0, (char *) 0); + keymap_BindToString(frameB->keymap, "a", SwitchToACmd, NULL, NULL); + keymap_BindToString(frameB->keymap, "b", StupidCmd, NULL, NULL); + keymap_BindToString(frameB->keymap, "d", NoCallCmd, NULL, NULL); + keymap_BindToString(frameB->keymap, "d", (int (*)())0, NULL, NULL); + keymap_BindToString(frameB->keymap, "\033d", NoCallCmd, NULL, NULL); gtxframe_AddMenu(frameB, "FrameA", "a"); /* finally setup the first window */ @@ -209,9 +246,9 @@ main() { gtxframe_SetFrame(win, frameA); /* play with maps for a while */ - tmap = (struct keymap_map *) keymap_Create(); - keymap_BindToString(tmap, "d", NoCallCmd, "test", (char *) 1); - keymap_BindToString(tmap, "cd", NoCallCmd, "bozo", (char *) 0); + tmap = (struct keymap_map *)keymap_Create(); + keymap_BindToString(tmap, "d", NoCallCmd, "test", (char *)1); + keymap_BindToString(tmap, "cd", NoCallCmd, "bozo", NULL); keymap_Delete(tmap); gtx_InputServer(win); diff --git a/src/gtx/gtxtextcb.h b/src/gtx/gtxtextcb.h index b20cfdcfa..0a5540e48 100644 --- a/src/gtx/gtxtextcb.h +++ b/src/gtx/gtxtextcb.h @@ -18,20 +18,20 @@ * *------------------------------------------------------------------------*/ -#include /*AFS locks*/ +#include /*AFS locks */ -#define GATOR_TEXTCB_MAXINVERSIONS 10 /*Max highlight inversions*/ +#define GATOR_TEXTCB_MAXINVERSIONS 10 /*Max highlight inversions */ /* * Description of the text hanging off each circular buffer entry. */ struct gator_textcb_entry { - int ID; /*Overall ID (number)*/ - int highlight; /*(Starting) highlight value*/ - int inversion[GATOR_TEXTCB_MAXINVERSIONS]; /*Highlighting inversions*/ - int numInversions; /*Num of above inversions*/ - int charsUsed; /*Num chars used*/ - char *textp; /*Ptr to text buffer itself*/ + int ID; /*Overall ID (number) */ + int highlight; /*(Starting) highlight value */ + int inversion[GATOR_TEXTCB_MAXINVERSIONS]; /*Highlighting inversions */ + int numInversions; /*Num of above inversions */ + int charsUsed; /*Num chars used */ + char *textp; /*Ptr to text buffer itself */ }; /* @@ -40,15 +40,15 @@ struct gator_textcb_entry { * terminate each line. */ struct gator_textcb_hdr { - struct Lock cbLock; /*Lock for this circular buffer*/ - int maxEntriesStored; /*Max num. text entries we store*/ - int maxCharsPerEntry; /*Max characters in each entry*/ - int currEnt; /*Entry currently being written*/ - int currEntIdx; /*Index of current entry*/ - int oldestEnt; /*Oldest entry stored*/ - int oldestEntIdx; /*Index of oldest entry*/ - struct gator_textcb_entry *entry; /*Ptr to array of text entries*/ - char *blankLine; /*Ptr to blank line*/ + struct Lock cbLock; /*Lock for this circular buffer */ + int maxEntriesStored; /*Max num. text entries we store */ + int maxCharsPerEntry; /*Max characters in each entry */ + int currEnt; /*Entry currently being written */ + int currEntIdx; /*Index of current entry */ + int oldestEnt; /*Oldest entry stored */ + int oldestEntIdx; /*Index of oldest entry */ + struct gator_textcb_entry *entry; /*Ptr to array of text entries */ + char *blankLine; /*Ptr to blank line */ }; /* @@ -64,7 +64,7 @@ extern int gator_textcb_Init(); * * Returns: * Zero if successful, - * Error code otherwise. + * Error code otherwise. */ extern struct gator_textcb_hdr *gator_textcb_Create(); @@ -73,27 +73,27 @@ extern struct gator_textcb_hdr *gator_textcb_Create(); * Create a new text circular buffer. * * Args: - * int a_maxEntriesStored : How many entries should it have? - * int a_maxCharsPerEntry : Max chars in each entry. + * int a_maxEntriesStored : How many entries should it have? + * int a_maxCharsPerEntry : Max chars in each entry. * * Returns: * Ptr to the fully-initialized circular buffer hdr if successful, - * Null pointer otherwise. + * Null pointer otherwise. */ extern int gator_textcb_Write(); /* * Summary: * Write the given string to the text circular buffer. Line - * breaks are caused either by overflowing the current text - * line or via explicit '\n's. + * breaks are caused either by overflowing the current text + * line or via explicit '\n's. * * Args: - * struct gator_textcb_hdr *a_cbhdr : Ptr to circ buff hdr. - * char *a_textToWrite : Ptr to text to insert. - * int a_numChars : Number of chars to write. - * int a_highlight : Use highlighting? - * int a_skip; : Force a skip to the next line? + * struct gator_textcb_hdr *a_cbhdr : Ptr to circ buff hdr. + * char *a_textToWrite : Ptr to text to insert. + * int a_numChars : Number of chars to write. + * int a_highlight : Use highlighting? + * int a_skip; : Force a skip to the next line? * * Returns: * Zero if successful, @@ -104,11 +104,11 @@ extern int gator_textcb_BlankLine(); /* * Summary: * Write out some number of blank lines to the given circular - * buffer. + * buffer. * * Args: - * struct gator_textcb_hdr *a_cbhdr : Ptr to circ buff hdr. - * int a_numBlanks : Num. blank lines to write. + * struct gator_textcb_hdr *a_cbhdr : Ptr to circ buff hdr. + * int a_numBlanks : Num. blank lines to write. * * Returns: * Zero if successful, @@ -119,11 +119,11 @@ extern int gator_textcb_Delete(); /* * Summary: * Delete the storage used by the given circular buffer, including - * the header itself. + * the header itself. * * Args: - * struct gator_textcb_hdr *a_cbhdr : Ptr to the header of the - * circ buffer to reap. + * struct gator_textcb_hdr *a_cbhdr : Ptr to the header of the + * circ buffer to reap. * * Returns: * Zero if successful, diff --git a/src/gtx/gtxtextobj.h b/src/gtx/gtxtextobj.h index 4c2fa5d03..f67b00dde 100644 --- a/src/gtx/gtxtextobj.h +++ b/src/gtx/gtxtextobj.h @@ -10,8 +10,8 @@ #ifndef __gator_textobject_h #define __gator_textobject_h 1 -#include "gtxobjects.h" /*Basic gator object definitions*/ -#include "gtxtextcb.h" /*Text object's circular buffer facility*/ +#include "gtxobjects.h" /*Basic gator object definitions */ +#include "gtxtextcb.h" /*Text object's circular buffer facility */ /*Value for onode o_type field*/ #define GATOR_OBJ_TEXT 0 @@ -22,18 +22,18 @@ /*Private data for text onode*/ struct gator_textobj { - int *llrock; /*Rock for lower-level graphics layer*/ - int numLines; /*Num lines we can display*/ - struct gator_textcb_hdr *cbHdr; /*Ptr to circular buffer header*/ - int firstEntShown; /*ID of first text entry displayed*/ - int lastEntShown; /*ID of last text entry displayed*/ + int *llrock; /*Rock for lower-level graphics layer */ + int numLines; /*Num lines we can display */ + struct gator_textcb_hdr *cbHdr; /*Ptr to circular buffer header */ + int firstEntShown; /*ID of first text entry displayed */ + int lastEntShown; /*ID of last text entry displayed */ }; /*Text object's creation parameters*/ struct gator_textobj_params { - struct onode_createparams onode_params; /*Params for the whole onode*/ - int maxEntries; /*Max text entries to store*/ - int maxCharsPerEntry; /*Max chars per text entry*/ + struct onode_createparams onode_params; /*Params for the whole onode */ + int maxEntries; /*Max text entries to store */ + int maxCharsPerEntry; /*Max chars per text entry */ }; /*Text object's creation routine*/ @@ -44,14 +44,14 @@ extern int gator_text_create(); * Create a gator text object. * * Args: - * struct onode *text_onp : Ptr to the text onode to fill out. - * struct onode_createparams *params : Ptr to creation params. + * struct onode *text_onp : Ptr to the text onode to fill out. + * struct onode_createparams *params : Ptr to creation params. * (Note: this actually points to a gator_text_crparams * structure, but we use the generic version of the ptr) * * Returns: - * Zero if successful, - * Error value otherwise. + * Zero if successful, + * Error value otherwise. */ /*Text object's generic onode routines*/ @@ -62,11 +62,11 @@ extern int gator_text_destroy(); * Destroy a gator text object. * * Args: - * struct onode *onp : Ptr to the text onode to delete. + * struct onode *onp : Ptr to the text onode to delete. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_text_display(); @@ -75,11 +75,11 @@ extern int gator_text_display(); * Display/redraw a gator text object. * * Args: - * struct onode *onp: Ptr to the text onode to display. + * struct onode *onp: Ptr to the text onode to display. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_text_release(); @@ -88,12 +88,12 @@ extern int gator_text_release(); * Drop the refcount on a gator text object. * * Args: - * struct onode *onp : Ptr to the onode whose refcount is - * to be dropped. + * struct onode *onp : Ptr to the onode whose refcount is + * to be dropped. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ /* @@ -106,13 +106,13 @@ extern int gator_text_Scroll(); * Scroll a text object some number of lines. * * Args: - * struct onode *onp : Ptr to the text onode to be scrolled. - * int nlines : Number of lines to scroll. - * int down : Scroll down? + * struct onode *onp : Ptr to the text onode to be scrolled. + * int nlines : Number of lines to scroll. + * int down : Scroll down? * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_text_Write(); @@ -121,16 +121,16 @@ extern int gator_text_Write(); * Write the given string to the end of the gator text object. * * Args: - * struct onode *onp : Ptr to the text onode to which we're - * writing. - * char *strToWrite : String to write. - * int numChars : Number of chars to write. - * int highlight : Use highlighting? - * int skip : Force a skip to the next line? + * struct onode *onp : Ptr to the text onode to which we're + * writing. + * char *strToWrite : String to write. + * int numChars : Number of chars to write. + * int highlight : Use highlighting? + * int skip : Force a skip to the next line? * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ extern int gator_text_BlankLine(); @@ -139,12 +139,12 @@ extern int gator_text_BlankLine(); * Write a given number of blank lines to the given text object. * * Args: - * struct onode *onp : Ptr to the onode to which we're writing. - * int numBlanks : Number of blank lines to write. + * struct onode *onp : Ptr to the onode to which we're writing. + * int numBlanks : Number of blank lines to write. * * Returns: - * 0: Success. - * Error value otherwise. + * 0: Success. + * Error value otherwise. */ /* diff --git a/src/gtx/gtxwindows.h b/src/gtx/gtxwindows.h index 3f8b0ca0f..9a11e9fc0 100644 --- a/src/gtx/gtxwindows.h +++ b/src/gtx/gtxwindows.h @@ -21,14 +21,14 @@ * Gator window definition. */ struct gwin { - int w_type; /*Type of window*/ - int w_x, w_y; /*X and Y coordinates*/ - int w_width, w_height; /*Width & height in pixels*/ - int w_changed; /*Does the window need to be refreshed?*/ - struct gwinops *w_op; /*Ptr to the operations defined on the window*/ - struct gwin *w_parent; /*Parent window, if any*/ + int w_type; /*Type of window */ + int w_x, w_y; /*X and Y coordinates */ + int w_width, w_height; /*Width & height in pixels */ + int w_changed; /*Does the window need to be refreshed? */ + struct gwinops *w_op; /*Ptr to the operations defined on the window */ + struct gwin *w_parent; /*Parent window, if any */ struct gtx_frame *w_frame; /*Frame information */ - int *w_data; /*Ptr to info describing the window*/ + int *w_data; /*Ptr to info describing the window */ }; /* @@ -43,87 +43,87 @@ struct gwin_dlist { * Initialization parameters for the gator window package. */ struct gwin_initparams { - int i_type; /*Type of lower-level graphics package used*/ - int i_x, i_y; /*X, Y coordinates of the screen area*/ - int i_width, i_height; /*Width, height of the screen area*/ - int i_debug; /*Should debugging be turned on?*/ + int i_type; /*Type of lower-level graphics package used */ + int i_x, i_y; /*X, Y coordinates of the screen area */ + int i_width, i_height; /*Width, height of the screen area */ + int i_debug; /*Should debugging be turned on? */ }; /* * Creation parameters for gator windows. */ struct gwin_createparams { - int cr_type; /*Type of window*/ - int cr_x, cr_y; /*X and Y coordinates*/ - int cr_width, cr_height; /*Width & height in pixels*/ - struct gwin *cr_parentwin; /*Ptr to parent window structure*/ + int cr_type; /*Type of window */ + int cr_x, cr_y; /*X and Y coordinates */ + int cr_width, cr_height; /*Width & height in pixels */ + struct gwin *cr_parentwin; /*Ptr to parent window structure */ }; /* * Line-drawing parameters. */ struct gwin_lineparams { - int x1, y1; /*X, Y coordinates of first point*/ - int x2, y2; /*X, Y coordinates of second point*/ + int x1, y1; /*X, Y coordinates of first point */ + int x2, y2; /*X, Y coordinates of second point */ }; /* * Rectangle-drawing parameters. */ struct gwin_rectparams { - int x, y; /*X, Y coordinates of rectangle's origin*/ - int width, height; /*Rectangle width & height*/ + int x, y; /*X, Y coordinates of rectangle's origin */ + int width, height; /*Rectangle width & height */ }; /* * Size params. */ struct gwin_sizeparams { - int maxx, maxy; /* x,y size */ + int maxx, maxy; /* x,y size */ }; /* * Char-drawing parameters. */ struct gwin_charparams { - int x, y; /*X, Y coordinates of char origin*/ - char c; /*Char to draw*/ - int highlight; /*Print in highlight/standout mode?*/ + int x, y; /*X, Y coordinates of char origin */ + char c; /*Char to draw */ + int highlight; /*Print in highlight/standout mode? */ }; /* * String-drawing parameters. */ struct gwin_strparams { - int x, y; /*X, Y coordinates of string*/ - int highlight; /*Print in highlight/standout mode?*/ - char *s; /*String to draw*/ + int x, y; /*X, Y coordinates of string */ + int highlight; /*Print in highlight/standout mode? */ + char *s; /*String to draw */ }; /* * Inversion parameters. */ struct gwin_invparams { - int x, y; /*X, Y coordinates of origin*/ - int width, height; /*Width & height of rectangle to invert*/ + int x, y; /*X, Y coordinates of origin */ + int width, height; /*Width & height of rectangle to invert */ }; /* * Operations on gator windows. */ struct gwinops { - int (*gw_box)(); /* Draw a box around the given window*/ - int (*gw_clear)(); /* Clear out a window*/ - int (*gw_destroy)(); /* Destroy a window*/ - int (*gw_display)(); /* [Re]display a window*/ - int (*gw_drawline)(); /* Draw a line between two points*/ - int (*gw_drawrectangle)(); /* Draw a rectangle at the given loc & dimensions*/ - int (*gw_drawchar)(); /* Draw a char at the given location*/ - int (*gw_drawstring)(); /* Draw a char string at the given location*/ - int (*gw_invert)(); /* Invert region*/ - int (*gw_getchar)(); /* Get a character from a window */ - int (*gw_getdimensions)(); /* Get dimensions of a window */ - int (*gw_wait)(); /* Wait for input */ + int (*gw_box) (); /* Draw a box around the given window */ + int (*gw_clear) (); /* Clear out a window */ + int (*gw_destroy) (); /* Destroy a window */ + int (*gw_display) (); /* [Re]display a window */ + int (*gw_drawline) (); /* Draw a line between two points */ + int (*gw_drawrectangle) (); /* Draw a rectangle at the given loc & dimensions */ + int (*gw_drawchar) (); /* Draw a char at the given location */ + int (*gw_drawstring) (); /* Draw a char string at the given location */ + int (*gw_invert) (); /* Invert region */ + int (*gw_getchar) (); /* Get a character from a window */ + int (*gw_getdimensions) (); /* Get dimensions of a window */ + int (*gw_wait) (); /* Wait for input */ }; /* @@ -146,8 +146,8 @@ struct gwinops { * Base operations on the lower-level window system. */ struct gwinbaseops { - struct gwin *(*gw_createwin)(); /*Create a window*/ - int (*gw_cleanup)(); /*Clean up before program exit*/ + struct gwin *(*gw_createwin) (); /*Create a window */ + int (*gw_cleanup) (); /*Clean up before program exit */ }; /* @@ -172,11 +172,11 @@ extern int gw_init(); * Initialize the gator window package. * * Args: - * struct gwin_initparams *params: Ptr to initialization params. + * struct gwin_initparams *params: Ptr to initialization params. * * Returns: - * 0 on success, - * Error value otherwise. + * 0 on success, + * Error value otherwise. */ /* initialize the whole gator toolkit package */ diff --git a/src/gtx/input.c b/src/gtx/input.c index b7647579d..5ef508ce0 100644 --- a/src/gtx/input.c +++ b/src/gtx/input.c @@ -11,7 +11,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/input.c,v 1.1.1.4 2001/07/14 22:22:03 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/input.c,v 1.7 2003/07/15 23:15:12 shadow Exp $"); #ifdef AFS_HPUX_ENV #include @@ -29,12 +30,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/input.c,v 1.1.1.4 2001/07/14 22:22: /* process input */ gtx_InputServer(awin) -register struct gwin *awin; { + register struct gwin *awin; +{ register int tc; register int code; register struct gtx_frame *tframe; - WOP_DISPLAY(awin); /* start off with a clean display */ + WOP_DISPLAY(awin); /* start off with a clean display */ while (1) { /* get a character from the generic window */ tframe = awin->w_frame; @@ -45,7 +47,8 @@ register struct gwin *awin; { } tc = WOP_GETCHAR(awin); tframe->flags &= ~GTXFRAME_NEWDISPLAY; /* OK to clear now */ - if (tc < 0) break; /* EOF or some such */ + if (tc < 0) + break; /* EOF or some such */ /* otherwise, process the character and go get a new one */ gtxframe_ClearMessageLine(tframe); tframe->flags &= ~(GTXFRAME_RECURSIVEEND | GTXFRAME_RECURSIVEERR); @@ -60,22 +63,24 @@ register struct gwin *awin; { } } -struct gwin *gtx_Init(astartInput, atype) -int atype; /* type of window to create */ -int astartInput; { +struct gwin * +gtx_Init(astartInput, atype) + int atype; /* type of window to create */ + int astartInput; +{ PROCESS junk; - struct onode_initparams oi_params; /* object init params*/ - struct gwin_initparams wi_params; /* window initialization params*/ + struct onode_initparams oi_params; /* object init params */ + struct gwin_initparams wi_params; /* window initialization params */ register struct gwin *twin; register int code; /* setup the main window structure */ - wi_params.i_type = GATOR_WIN_CURSES; - wi_params.i_x = 0; - wi_params.i_y = 0; - wi_params.i_width = 80; + wi_params.i_type = GATOR_WIN_CURSES; + wi_params.i_x = 0; + wi_params.i_y = 0; + wi_params.i_width = 80; wi_params.i_height = 200; - wi_params.i_debug = 0; /* or 1 if we want debugging done */ + wi_params.i_debug = 0; /* or 1 if we want debugging done */ /* * Set up the basic onode initialization parameters, throwing in @@ -85,13 +90,15 @@ int astartInput; { oi_params.i_gwparams = &wi_params; code = gator_objects_init(&oi_params); - if (code) return (struct gwin *) 0; - + if (code) + return NULL; + /* if we start input thread */ - IOMGR_Initialize(); /* input thread uses it */ + IOMGR_Initialize(); /* input thread uses it */ if (astartInput) - code = LWP_CreateProcess(gtx_InputServer, 8192, LWP_NORMAL_PRIORITY, - 0, "gx-listener", &junk); + code = + LWP_CreateProcess(gtx_InputServer, 8192, LWP_NORMAL_PRIORITY, + (void *)0, "gx-listener", &junk); /* all done */ twin = &gator_basegwin; return twin; diff --git a/src/gtx/keymap.c b/src/gtx/keymap.c index 29ef139d6..cc2140035 100644 --- a/src/gtx/keymap.c +++ b/src/gtx/keymap.c @@ -10,51 +10,69 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/keymap.c,v 1.1.1.5 2001/09/11 14:32:46 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/keymap.c,v 1.7 2003/07/15 23:15:13 shadow Exp $"); + + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#include #include "gtxkeymap.h" -struct keymap_map *keymap_Create() { +struct keymap_map * +keymap_Create() +{ register struct keymap_map *tmap; - tmap = (struct keymap_map *) malloc(sizeof(struct keymap_map)); + tmap = (struct keymap_map *)malloc(sizeof(struct keymap_map)); if (tmap != (struct keymap_map *)0) - memset(tmap, 0, sizeof(*tmap)); - return(tmap); + memset(tmap, 0, sizeof(*tmap)); + return (tmap); } /* make a copy of a string; generic utility */ -char *gtx_CopyString(aval) -register char *aval; { +char * +gtx_CopyString(aval) + register char *aval; +{ register char *tp; - if (!aval) return (char *) 0; /* propagate null strings around */ - tp = (char *) malloc(strlen(aval)+1); - if (tp != (char *)0) - strcpy(tp, aval); - return(tp); + if (!aval) + return NULL; /* propagate null strings around */ + tp = (char *)malloc(strlen(aval) + 1); + if (tp != NULL) + strcpy(tp, aval); + return (tp); } -static int BindIt(amap, aslot, atype, aproc, aname, arock) -struct keymap_map *amap; -char *arock; -int aslot; -int atype; -char *aproc; -char *aname; { +static int +BindIt(amap, aslot, atype, aproc, aname, arock) + struct keymap_map *amap; + char *arock; + int aslot; + int atype; + char *aproc; + char *aname; +{ register char *tp; register struct keymap_entry *tentry; - if (aslot < 0 || aslot >= KEYMAP_NENTRIES) return -1; + if (aslot < 0 || aslot >= KEYMAP_NENTRIES) + return -1; tentry = &amap->entries[aslot]; tentry->type = atype; - if (tp=tentry->name) + if (tp = tentry->name) free(tp); if (atype == KEYMAP_EMPTY) { - tentry->u.generic = (char *) 0; - tentry->name = (char *) 0; - } - else { + tentry->u.generic = NULL; + tentry->name = NULL; + } else { tentry->name = gtx_CopyString(aname); tentry->u.generic = aproc; } @@ -63,11 +81,12 @@ char *aname; { } keymap_BindToString(amap, astring, aproc, aname, arock) -register struct keymap_map *amap; -char *astring; -char *arock; -int (*aproc)(); -char *aname; { + register struct keymap_map *amap; + char *astring; + char *arock; + int (*aproc) (); + char *aname; +{ register char *cptr; register int tc; register afs_int32 code; @@ -75,46 +94,49 @@ char *aname; { cptr = astring; /* walk down string, building submaps if possible, until we get to function - at the end */ + * at the end */ while (tc = *cptr++) { /* see if we should do submap or final function */ if (*cptr == 0) { /* we're peeking: already skipped command char */ /* last character, do final function */ - if (!aproc) /* delete the entry */ - code = BindIt(amap, tc, KEYMAP_EMPTY, (char *) 0, - (char *) 0, (char *) 0); + if (!aproc) /* delete the entry */ + code = BindIt(amap, tc, KEYMAP_EMPTY, NULL, NULL, NULL); else - code = BindIt(amap, tc, KEYMAP_PROC, (char *) aproc, aname, arock); - if (code) return code; - } - else { + code = + BindIt(amap, tc, KEYMAP_PROC, (char *)aproc, aname, + arock); + if (code) + return code; + } else { /* more characters after this; do submap */ if (amap->entries[tc].type != KEYMAP_SUBMAP) { tmap = keymap_Create(); - code = BindIt(amap, tc, KEYMAP_SUBMAP, (char *) tmap, - (char *) 0, (char *) 0); - } - else { + code = + BindIt(amap, tc, KEYMAP_SUBMAP, (char *)tmap, NULL, NULL); + } else { tmap = amap->entries[tc].u.submap; code = 0; } - if (code) return code; + if (code) + return code; amap = tmap; /* continue processing this map */ } - } /* while loop */ + } /* while loop */ /* here when all characters are gone */ return 0; } /* delete a keymap and all of its recursively-included maps */ keymap_Delete(amap) -register struct keymap_map *amap; { + register struct keymap_map *amap; +{ register int i; register struct keymap_entry *tentry; - for(i=0;ientries[i]; - if (tentry->name) free(tentry->name); + if (tentry->name) + free(tentry->name); if (tentry->type == KEYMAP_SUBMAP) keymap_Delete(tentry->u.submap); } @@ -123,8 +145,9 @@ register struct keymap_map *amap; { } keymap_InitState(astate, amap) -register struct keymap_state *astate; -struct keymap_map *amap; { + register struct keymap_state *astate; + struct keymap_map *amap; +{ memset(astate, 0, sizeof(*astate)); astate->initMap = amap; astate->currentMap = amap; @@ -132,28 +155,30 @@ struct keymap_map *amap; { } keymap_ProcessKey(astate, akey, arock) -register struct keymap_state *astate; -char *arock; -register int akey; { + register struct keymap_state *astate; + char *arock; + register int akey; +{ register struct keymap_entry *tentry; register afs_int32 code; - if (akey < 0 || akey >= KEYMAP_NENTRIES) return -1; + if (akey < 0 || akey >= KEYMAP_NENTRIES) + return -1; tentry = &astate->currentMap->entries[akey]; code = 0; - switch(tentry->type) { - case KEYMAP_EMPTY: + switch (tentry->type) { + case KEYMAP_EMPTY: keymap_ResetState(astate); return -1; /* break; */ /* break commented out because of return above causing compiler warnings */ - case KEYMAP_SUBMAP: + case KEYMAP_SUBMAP: astate->currentMap = tentry->u.submap; break; - case KEYMAP_PROC: - code = (*tentry->u.proc)(arock, tentry->rock); + case KEYMAP_PROC: + code = (*tentry->u.proc) (arock, tentry->rock); keymap_ResetState(astate); break; } @@ -161,6 +186,7 @@ register int akey; { } keymap_ResetState(astate) -register struct keymap_state *astate; { + register struct keymap_state *astate; +{ return keymap_InitState(astate, astate->initMap); } diff --git a/src/gtx/lightobject.c b/src/gtx/lightobject.c index 3fb94352e..583810a2e 100644 --- a/src/gtx/lightobject.c +++ b/src/gtx/lightobject.c @@ -16,12 +16,23 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/lightobject.c,v 1.1.1.4 2001/07/14 22:22:02 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/lightobject.c,v 1.6 2003/07/15 23:15:13 shadow Exp $"); -#include "gtxlightobj.h" /*Interface for this module*/ -#include /*Standard I/O stuff*/ +#include "gtxlightobj.h" /*Interface for this module */ +#include /*Standard I/O stuff */ #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#include + + /*Externally-advertised array of light onode operations*/ struct onodeops gator_light_ops = { gator_light_destroy, @@ -29,7 +40,7 @@ struct onodeops gator_light_ops = { gator_light_release }; -static char mn[] = "gator_lightobject"; /*Module name*/ +static char mn[] = "gator_lightobject"; /*Module name */ /*------------------------------------------------------------------------ * gator_light_create @@ -56,62 +67,74 @@ static char mn[] = "gator_lightobject"; /*Module name*/ * garbage-collected upon failure. *------------------------------------------------------------------------*/ -int gator_light_create(light_onp, params) - struct onode *light_onp; - struct onode_createparams *params; +int +gator_light_create(light_onp, params) + struct onode *light_onp; + struct onode_createparams *params; -{ /*gator_light_create*/ +{ /*gator_light_create */ - static char rn[] = "gator_light_create"; /*Routine name*/ - struct gator_light_crparams *light_params; /*My specific creation params*/ - struct gator_lightobj *light_data; /*Ptr to private data*/ - struct gwin_strparams *light_strparams; /*Light label params*/ + static char rn[] = "gator_light_create"; /*Routine name */ + struct gator_light_crparams *light_params; /*My specific creation params */ + struct gator_lightobj *light_data; /*Ptr to private data */ + struct gwin_strparams *light_strparams; /*Light label params */ light_params = (struct gator_light_crparams *)params; if (objects_debug) { - fprintf(stderr, "[%s:%s] Private data passed to light object:\n", mn, rn); - fprintf(stderr, "\tAppearance: %d, flashfreq: %d, label at offset (%d, %d): '%s'\n", light_params->appearance, light_params->flashfreq, light_params->label_x, light_params->label_y, light_params->label); + fprintf(stderr, "[%s:%s] Private data passed to light object:\n", mn, + rn); + fprintf(stderr, + "\tAppearance: %d, flashfreq: %d, label at offset (%d, %d): '%s'\n", + light_params->appearance, light_params->flashfreq, + light_params->label_x, light_params->label_y, + light_params->label); } /* - * Allocate the private data area, including the lower-level - * structure, then fill it in. - */ - light_data = (struct gator_lightobj *)malloc(sizeof(struct gator_lightobj)); + * Allocate the private data area, including the lower-level + * structure, then fill it in. + */ + light_data = + (struct gator_lightobj *)malloc(sizeof(struct gator_lightobj)); if (light_data == (struct gator_lightobj *)0) { - fprintf(stderr, "[%s:%s] Can't allocate %d bytes for light object private data region, errno is %d\n", mn, rn, sizeof(struct gator_lightobj), errno); - return(errno); + fprintf(stderr, + "[%s:%s] Can't allocate %d bytes for light object private data region, errno is %d\n", + mn, rn, sizeof(struct gator_lightobj), errno); + return (errno); } - light_strparams = (struct gwin_strparams *)malloc(sizeof(struct gwin_strparams)); + light_strparams = + (struct gwin_strparams *)malloc(sizeof(struct gwin_strparams)); if (light_strparams == (struct gwin_strparams *)0) { - fprintf(stderr, "[%s:%s] Can't allocate %d bytes for light object label in private data region, errno is %d\n", mn, rn, sizeof(struct gwin_strparams), errno); - free(light_data); - return(errno); + fprintf(stderr, + "[%s:%s] Can't allocate %d bytes for light object label in private data region, errno is %d\n", + mn, rn, sizeof(struct gwin_strparams), errno); + free(light_data); + return (errno); } /* - * Now that we have the private structures allocated, set them up. - */ - light_data->setting = 0; - light_data->appearance = light_params->appearance; - light_data->flashfreq = light_params->flashfreq; + * Now that we have the private structures allocated, set them up. + */ + light_data->setting = 0; + light_data->appearance = light_params->appearance; + light_data->flashfreq = light_params->flashfreq; light_data->lasttoggletime = 0; strcpy(light_data->label, light_params->label); - light_strparams->x = light_onp->o_x + light_params->label_x; - light_strparams->y = light_onp->o_y + light_params->label_y; - light_strparams->s = light_data->label; + light_strparams->x = light_onp->o_x + light_params->label_x; + light_strparams->y = light_onp->o_y + light_params->label_y; + light_strparams->s = light_data->label; light_strparams->highlight = 0; - light_data->llrock = (int *)light_strparams; + light_data->llrock = (int *)light_strparams; /* - * Attach the private data to the onode, then return the happy news. - */ + * Attach the private data to the onode, then return the happy news. + */ light_onp->o_data = (int *)light_data; - return(0); + return (0); -} /*gator_light_create*/ +} /*gator_light_create */ /*------------------------------------------------------------------------ * gator_light_destroy @@ -133,17 +156,18 @@ int gator_light_create(light_onp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_light_destroy(onp) - struct onode *onp; +int +gator_light_destroy(onp) + struct onode *onp; -{ /*gator_light_destroy*/ +{ /*gator_light_destroy */ /* - * For now, this is a no-op. - */ - return(0); + * For now, this is a no-op. + */ + return (0); -} /*gator_light_destroy*/ +} /*gator_light_destroy */ /*------------------------------------------------------------------------ * gator_light_display @@ -168,27 +192,30 @@ int gator_light_destroy(onp) * As advertised. *------------------------------------------------------------------------*/ -int gator_light_display(onp) - struct onode *onp; +int +gator_light_display(onp) + struct onode *onp; -{ /*gator_light_display*/ +{ /*gator_light_display */ - static char rn[] = "gator_light_display"; /*Routine name*/ - struct gator_lightobj *light_data; /*Ptr to light obj data*/ - struct gwin_strparams *label_strparams; /*String-drawing params*/ + static char rn[] = "gator_light_display"; /*Routine name */ + struct gator_lightobj *light_data; /*Ptr to light obj data */ + struct gwin_strparams *label_strparams; /*String-drawing params */ /* - * Draw the label, with proper highlighting depending on whether - * the light is on. - */ + * Draw the label, with proper highlighting depending on whether + * the light is on. + */ light_data = (struct gator_lightobj *)(onp->o_data); label_strparams = (struct gwin_strparams *)(light_data->llrock); if (objects_debug) - fprintf(stderr, "[%s:%s] Printing out light label '%s' at (%d, %d)\n", mn, rn, label_strparams->s, label_strparams->x, label_strparams->y); + fprintf(stderr, "[%s:%s] Printing out light label '%s' at (%d, %d)\n", + mn, rn, label_strparams->s, label_strparams->x, + label_strparams->y); WOP_DRAWSTRING(onp->o_window, label_strparams); - return(0); + return (0); -} /*gator_light_display*/ +} /*gator_light_display */ /*------------------------------------------------------------------------ * gator_light_release @@ -211,17 +238,18 @@ int gator_light_display(onp) * As advertised. *------------------------------------------------------------------------*/ -int gator_light_release(onp) - struct onode *onp; +int +gator_light_release(onp) + struct onode *onp; -{ /*gator_light_release*/ +{ /*gator_light_release */ /* - * For now, this is a no-op. - */ - return(0); + * For now, this is a no-op. + */ + return (0); -} /*gator_light_release*/ +} /*gator_light_release */ /*------------------------------------------------------------------------ * gator_light_set @@ -246,27 +274,29 @@ int gator_light_release(onp) * Does NOT redisplay the light object. *------------------------------------------------------------------------*/ -int gator_light_set(onp, setting) - struct onode *onp; - int setting; +int +gator_light_set(onp, setting) + struct onode *onp; + int setting; -{ /*gator_light_set*/ +{ /*gator_light_set */ - static char rn[] = "gator_light_set"; /*Routine name*/ - struct gator_lightobj *light_data; /*Ptr to light obj data*/ - struct gwin_strparams *label_strparams; /*String-drawing params*/ + static char rn[] = "gator_light_set"; /*Routine name */ + struct gator_lightobj *light_data; /*Ptr to light obj data */ + struct gwin_strparams *label_strparams; /*String-drawing params */ /* - * Set the object correctly, then set the highlight field in - * the lower-level rock. - */ + * Set the object correctly, then set the highlight field in + * the lower-level rock. + */ light_data = (struct gator_lightobj *)(onp->o_data); label_strparams = (struct gwin_strparams *)(light_data->llrock); if (objects_debug) - fprintf(stderr, "[%s:%s] Setting light object at 0x%x to %d (%s)", mn, rn, onp, setting, (setting? "ON" : "OFF")); - light_data->setting = setting; + fprintf(stderr, "[%s:%s] Setting light object at 0x%x to %d (%s)", mn, + rn, onp, setting, (setting ? "ON" : "OFF")); + light_data->setting = setting; label_strparams->highlight = setting; - return(0); + return (0); -} /*gator_light_set*/ +} /*gator_light_set */ diff --git a/src/gtx/objdict.c b/src/gtx/objdict.c index c9f636afa..221719091 100644 --- a/src/gtx/objdict.c +++ b/src/gtx/objdict.c @@ -16,13 +16,14 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/objdict.c,v 1.1.1.4 2001/07/14 22:22:04 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/objdict.c,v 1.6 2003/07/15 23:15:13 shadow Exp $"); -#include "gtxobjdict.h" /*Interface for this module*/ -#include /*Standard I/O package*/ +#include "gtxobjdict.h" /*Interface for this module */ +#include /*Standard I/O package */ -static char mn[] = "gator_objdict"; /*Module name*/ -static int objdict_debug; /*Is debugging turned on?*/ +static char mn[] = "gator_objdict"; /*Module name */ +static int objdict_debug; /*Is debugging turned on? */ /*------------------------------------------------------------------------ * gator_objdict_init @@ -45,27 +46,28 @@ static int objdict_debug; /*Is debugging turned on?*/ * As advertised. *------------------------------------------------------------------------*/ -int gator_objdict_init(adebug) - int adebug; +int +gator_objdict_init(adebug) + int adebug; -{ /*gator_objdict_init*/ +{ /*gator_objdict_init */ - static char rn[] = "gator_objdict_init"; /*Routine name*/ + static char rn[] = "gator_objdict_init"; /*Routine name */ /* - * Remember what our debugging setting is. - */ + * Remember what our debugging setting is. + */ objdict_debug = adebug; if (objdict_debug) - fprintf(stderr, "[%s:%s] Called\n", mn, rn); + fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* * Finally, return the good news. */ - return(0); + return (0); -} /*gator_objdict_init*/ +} /*gator_objdict_init */ /*------------------------------------------------------------------------ * gator_objdict_add @@ -87,22 +89,23 @@ int gator_objdict_init(adebug) * As advertised. *------------------------------------------------------------------------*/ -int gator_objdict_add(objtoadd) - struct onode *objtoadd; +int +gator_objdict_add(objtoadd) + struct onode *objtoadd; -{ /*gator_objdict_add*/ +{ /*gator_objdict_add */ - static char rn[] = "gator_objdict_add"; /*Routine name*/ + static char rn[] = "gator_objdict_add"; /*Routine name */ if (objdict_debug) - fprintf(stderr, "[%s:%s] Called\n", mn, rn); + fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* * Finally, return the good news. */ - return(0); + return (0); -} /*gator_objdict_add*/ +} /*gator_objdict_add */ /*------------------------------------------------------------------------ * gator_objdict_delete @@ -124,22 +127,23 @@ int gator_objdict_add(objtoadd) * As advertised. *------------------------------------------------------------------------*/ -int gator_objdict_delete(objtodelete) - struct onode *objtodelete; +int +gator_objdict_delete(objtodelete) + struct onode *objtodelete; -{ /*gator_objdict_delete*/ +{ /*gator_objdict_delete */ - static char rn[] = "gator_objdict_delete"; /*Routine name*/ + static char rn[] = "gator_objdict_delete"; /*Routine name */ if (objdict_debug) - fprintf(stderr, "[%s:%s] Called\n", mn, rn); + fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* * Finally, return the good news. */ - return(0); + return (0); -} /*gator_objdict_delete*/ +} /*gator_objdict_delete */ /*------------------------------------------------------------------------ * gator_objdict_lookup @@ -161,19 +165,20 @@ int gator_objdict_delete(objtodelete) * As advertised. *------------------------------------------------------------------------*/ -struct onode *gator_objdict_lookup(nametofind) - char *nametofind; +struct onode * +gator_objdict_lookup(nametofind) + char *nametofind; -{ /*gator_objdict_lookup*/ +{ /*gator_objdict_lookup */ - static char rn[] = "gator_objdict_lookup"; /*Routine name*/ + static char rn[] = "gator_objdict_lookup"; /*Routine name */ if (objdict_debug) - fprintf(stderr, "[%s:%s] Called\n", mn, rn); + fprintf(stderr, "[%s:%s] Called\n", mn, rn); /* * Finally, return the good news. */ - return((struct onode *)0); + return (NULL); -} /*gator_objdict_lookup*/ +} /*gator_objdict_lookup */ diff --git a/src/gtx/object_test.c b/src/gtx/object_test.c index 4db38766d..2e035596f 100644 --- a/src/gtx/object_test.c +++ b/src/gtx/object_test.c @@ -14,18 +14,19 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/object_test.c,v 1.2 2003/01/02 03:55:50 hartmans Exp $"); - -#include "gtxscreenobj.h" /*Gator screen object interface*/ -#include "gtxtextobj.h" /*Gator text object interface*/ -#include "gtxlightobj.h" /*Gator light object interface*/ -#include "gtxwindows.h" /*Gator generic window package*/ -#include "gtxcurseswin.h" /*Gator curses window package*/ -#include "gtxdumbwin.h" /*Gator dumb terminal window package*/ -#include "gtxX11win.h" /*Gator X11 window package*/ +RCSID + ("$Header: /cvs/openafs/src/gtx/object_test.c,v 1.7 2003/07/15 23:15:13 shadow Exp $"); + +#include "gtxscreenobj.h" /*Gator screen object interface */ +#include "gtxtextobj.h" /*Gator text object interface */ +#include "gtxlightobj.h" /*Gator light object interface */ +#include "gtxwindows.h" /*Gator generic window package */ +#include "gtxcurseswin.h" /*Gator curses window package */ +#include "gtxdumbwin.h" /*Gator dumb terminal window package */ +#include "gtxX11win.h" /*Gator X11 window package */ #include -#include /*Standard I/O stuff*/ -#include /*Command interpretation library*/ +#include /*Standard I/O stuff */ +#include /*Command interpretation library */ /* @@ -34,8 +35,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/object_test.c,v 1.2 2003/01/02 03:5 #define P_PACKAGE 0 #define P_DEBUG 1 -static char pn[] = "object_test"; /*Program name*/ -static int object_debug = 0; /*Is debugging turned on?*/ +static char pn[] = "object_test"; /*Program name */ +static int object_debug = 0; /*Is debugging turned on? */ /*-------------------------------------------------------------------------------- * test_objects @@ -57,88 +58,94 @@ static int object_debug = 0; /*Is debugging turned on?*/ * As advertised. *--------------------------------------------------------------------------------*/ -static int test_objects(pkg) - int pkg; +static int +test_objects(pkg) + int pkg; -{ /*test_objects*/ +{ /*test_objects */ - static char rn[] = "test_objects"; /*Routine name*/ - register int code; /*Return code*/ - struct onode_initparams oi_params; /*Init params*/ - struct gwin_initparams wi_params; /*Window initialization params*/ + static char rn[] = "test_objects"; /*Routine name */ + register int code; /*Return code */ + struct onode_initparams oi_params; /*Init params */ + struct gwin_initparams wi_params; /*Window initialization params */ #if 0 - /*We don't need these, do we?*/ - struct gator_cursesgwin_params c_crparams; /*Curses window creation params*/ - struct gator_dumbgwin_params d_crparams; /*Dumb terminal window creation params*/ - struct gator_X11gwin_params x_crparams; /*X11 window creation params*/ -#endif 0 - struct gator_light_crparams light_crparams; /*Light creation params*/ - char helpstring1[128]; /*Help string to use*/ - char helpstring2[128]; /*Help string to use*/ - char helpstring3[128]; /*Help string to use*/ - char helpstring4[128]; /*Help string to use*/ - char helpstringt1[128]; /*Help string to use*/ - struct onode *light_onp1; /*Ptr to light onode*/ - struct onode *light_onp2; /*Ptr to another light onode*/ - struct onode *light_onp3; /*Ptr to another light onode*/ - struct onode *light_onp4; /*Ptr to another light onode*/ - struct onode *text_onp1; /*Ptr to text onode*/ - int i; /*Generic loop variable*/ - int setting; /*Current light setting*/ - struct gator_textobj_params text_crparams; /*Text creation params*/ - char s[128]; /*Another string*/ - struct gwin_strparams strparams; /*String-drawing params*/ + /*We don't need these, do we? */ + struct gator_cursesgwin_params c_crparams; /*Curses window creation params */ + struct gator_dumbgwin_params d_crparams; /*Dumb terminal window creation params */ + struct gator_X11gwin_params x_crparams; /*X11 window creation params */ +#endif /* 0 */ + struct gator_light_crparams light_crparams; /*Light creation params */ + char helpstring1[128]; /*Help string to use */ + char helpstring2[128]; /*Help string to use */ + char helpstring3[128]; /*Help string to use */ + char helpstring4[128]; /*Help string to use */ + char helpstringt1[128]; /*Help string to use */ + struct onode *light_onp1; /*Ptr to light onode */ + struct onode *light_onp2; /*Ptr to another light onode */ + struct onode *light_onp3; /*Ptr to another light onode */ + struct onode *light_onp4; /*Ptr to another light onode */ + struct onode *text_onp1; /*Ptr to text onode */ + int i; /*Generic loop variable */ + int setting; /*Current light setting */ + struct gator_textobj_params text_crparams; /*Text creation params */ + char s[128]; /*Another string */ + struct gwin_strparams strparams; /*String-drawing params */ /* * Initialize the chosen gator window package. */ if (object_debug) - fprintf(stderr, "[%s:%s] Setting up initialization params for window package %d\n", pn, rn, pkg); - wi_params.i_type = pkg; - wi_params.i_x = 0; - wi_params.i_y = 0; - wi_params.i_width = 80; + fprintf(stderr, + "[%s:%s] Setting up initialization params for window package %d\n", + pn, rn, pkg); + wi_params.i_type = pkg; + wi_params.i_x = 0; + wi_params.i_y = 0; + wi_params.i_width = 80; wi_params.i_height = 200; - wi_params.i_debug = object_debug; + wi_params.i_debug = object_debug; /* - * Set up the basic onode initialization parameters, throwing in - * the graphics-specific stuff. - */ + * Set up the basic onode initialization parameters, throwing in + * the graphics-specific stuff. + */ oi_params.i_debug = object_debug; oi_params.i_gwparams = &wi_params; code = gator_objects_init(&oi_params); if (code) { - fprintf(stderr, "[%s:%s] Can't initialize gator objects package for window system %d; error is: %d\n", pn, rn, pkg, code); - return(code); + fprintf(stderr, + "[%s:%s] Can't initialize gator objects package for window system %d; error is: %d\n", + pn, rn, pkg, code); + return (code); } /* - * Set up some light objects and put them up on the screen. - */ + * Set up some light objects and put them up on the screen. + */ sprintf(helpstring1, "%s", "Help string for light 1"); - light_crparams.onode_params.cr_type = GATOR_OBJ_LIGHT; + light_crparams.onode_params.cr_type = GATOR_OBJ_LIGHT; sprintf(light_crparams.onode_params.cr_name, "%s", "Light1"); - light_crparams.onode_params.cr_x = 10; - light_crparams.onode_params.cr_y = 10; - light_crparams.onode_params.cr_width = 10; - light_crparams.onode_params.cr_height = 1; - light_crparams.onode_params.cr_window = &gator_basegwin; - light_crparams.onode_params.cr_home_obj = (struct onode *)0; - light_crparams.onode_params.cr_prev_obj = (struct onode *)0; - light_crparams.onode_params.cr_parent_obj = (struct onode *)0; + light_crparams.onode_params.cr_x = 10; + light_crparams.onode_params.cr_y = 10; + light_crparams.onode_params.cr_width = 10; + light_crparams.onode_params.cr_height = 1; + light_crparams.onode_params.cr_window = &gator_basegwin; + light_crparams.onode_params.cr_home_obj = NULL; + light_crparams.onode_params.cr_prev_obj = NULL; + light_crparams.onode_params.cr_parent_obj = NULL; light_crparams.onode_params.cr_helpstring = helpstring1; light_crparams.appearance = 0; - light_crparams.flashfreq = 0; + light_crparams.flashfreq = 0; sprintf(light_crparams.label, "%s", "Light 1 "); light_crparams.label_x = 0; light_crparams.label_y = 0; - light_onp1 = gator_objects_create((struct onode_createparams *)(&light_crparams)); - if (light_onp1 == (struct onode *)0) { - fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn); - exit(-1); + light_onp1 = + gator_objects_create((struct onode_createparams *)(&light_crparams)); + if (light_onp1 == NULL) { + fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn); + exit(-1); } sprintf(helpstring2, "%s", "Help string for light 2"); @@ -147,10 +154,11 @@ static int test_objects(pkg) light_crparams.onode_params.cr_y = 12; sprintf(light_crparams.onode_params.cr_name, "%s", "Light2"); sprintf(light_crparams.label, "%s", "Light 2 "); - light_onp2 = gator_objects_create((struct onode_createparams *)(&light_crparams)); - if (light_onp2 == (struct onode *)0) { - fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn); - exit(-1); + light_onp2 = + gator_objects_create((struct onode_createparams *)(&light_crparams)); + if (light_onp2 == NULL) { + fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn); + exit(-1); } sprintf(helpstring3, "%s", "Help string for light 3"); @@ -159,10 +167,11 @@ static int test_objects(pkg) light_crparams.onode_params.cr_y = 14; sprintf(light_crparams.onode_params.cr_name, "%s", "Light3"); sprintf(light_crparams.label, "%s", "Light 3 "); - light_onp3 = gator_objects_create((struct onode_createparams *)(&light_crparams)); - if (light_onp3 == (struct onode *)0) { - fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn); - exit(-1); + light_onp3 = + gator_objects_create((struct onode_createparams *)(&light_crparams)); + if (light_onp3 == NULL) { + fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn); + exit(-1); } sprintf(helpstring4, "%s", "Help string for light 4"); @@ -171,158 +180,189 @@ static int test_objects(pkg) light_crparams.onode_params.cr_y = 10; sprintf(light_crparams.onode_params.cr_name, "%s", "Light4"); sprintf(light_crparams.label, "%s", "Light 4 "); - light_onp4 = gator_objects_create((struct onode_createparams *)(&light_crparams)); - if (light_onp4 == (struct onode *)0) { - fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn); - exit(-1); + light_onp4 = + gator_objects_create((struct onode_createparams *)(&light_crparams)); + if (light_onp4 == NULL) { + fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn); + exit(-1); } /* - * Create a text object, too. - */ + * Create a text object, too. + */ sprintf(helpstringt1, "%s", "Help string for text"); - text_crparams.onode_params.cr_type = GATOR_OBJ_TEXT; + text_crparams.onode_params.cr_type = GATOR_OBJ_TEXT; sprintf(text_crparams.onode_params.cr_name, "%s", "Text1"); - text_crparams.onode_params.cr_x = 30; - text_crparams.onode_params.cr_y = 10; - text_crparams.onode_params.cr_width = 35; - text_crparams.onode_params.cr_height = 7; - text_crparams.onode_params.cr_window = &gator_basegwin; - text_crparams.onode_params.cr_home_obj = (struct onode *)0; - text_crparams.onode_params.cr_prev_obj = (struct onode *)0; - text_crparams.onode_params.cr_parent_obj = (struct onode *)0; + text_crparams.onode_params.cr_x = 30; + text_crparams.onode_params.cr_y = 10; + text_crparams.onode_params.cr_width = 35; + text_crparams.onode_params.cr_height = 7; + text_crparams.onode_params.cr_window = &gator_basegwin; + text_crparams.onode_params.cr_home_obj = NULL; + text_crparams.onode_params.cr_prev_obj = NULL; + text_crparams.onode_params.cr_parent_obj = NULL; text_crparams.onode_params.cr_helpstring = helpstringt1; - text_crparams.maxEntries = 7; + text_crparams.maxEntries = 7; text_crparams.maxCharsPerEntry = 35; - text_onp1 = gator_objects_create((struct onode_createparams *)(&text_crparams)); - if (text_onp1 == (struct onode *)0) { - fprintf(stderr, "[%s:%s] Can't create text object\n", pn, rn); - exit(-1); + text_onp1 = + gator_objects_create((struct onode_createparams *)(&text_crparams)); + if (text_onp1 == NULL) { + fprintf(stderr, "[%s:%s] Can't create text object\n", pn, rn); + exit(-1); } OOP_DISPLAY(text_onp1); sleep(2); /* - * Now that we have our lights, turn them on and off a few times. - */ + * Now that we have our lights, turn them on and off a few times. + */ setting = 1; sprintf(s, "%s", "ABCD"); - strparams.x = 0; - strparams.y = 0; - strparams.s = s; - strparams.highlight = 0; - - for (i=0; i<10; i++) { - code = gator_light_set(light_onp1, setting); - if (code) - fprintf(stderr, "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, rn, light_onp1, setting, (setting? "ON" : "OFF")); - else - OOP_DISPLAY(light_onp1); - - code = gator_light_set(light_onp2, setting); - if (code) - fprintf(stderr, "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, rn, light_onp2, setting, (setting? "ON" : "OFF")); - else - OOP_DISPLAY(light_onp2); - - code = gator_light_set(light_onp3, setting); - if (code) - fprintf(stderr, "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, rn, light_onp3, setting, (setting? "ON" : "OFF")); - else - OOP_DISPLAY(light_onp3); - - code = gator_light_set(light_onp4, setting); - if (code) - fprintf(stderr, "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, rn, light_onp4, setting, (setting? "ON" : "OFF")); - else - OOP_DISPLAY(light_onp4); - setting = (setting? 0 : 1); - - sleep(1); - - WOP_DRAWSTRING(text_onp1->o_window, &strparams); - strparams.x++; - strparams.y++; - sleep(1); - - } /*Flash loop*/ + strparams.x = 0; + strparams.y = 0; + strparams.s = s; + strparams.highlight = 0; + + for (i = 0; i < 10; i++) { + code = gator_light_set(light_onp1, setting); + if (code) + fprintf(stderr, + "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, + rn, light_onp1, setting, (setting ? "ON" : "OFF")); + else + OOP_DISPLAY(light_onp1); + + code = gator_light_set(light_onp2, setting); + if (code) + fprintf(stderr, + "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, + rn, light_onp2, setting, (setting ? "ON" : "OFF")); + else + OOP_DISPLAY(light_onp2); + + code = gator_light_set(light_onp3, setting); + if (code) + fprintf(stderr, + "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, + rn, light_onp3, setting, (setting ? "ON" : "OFF")); + else + OOP_DISPLAY(light_onp3); + + code = gator_light_set(light_onp4, setting); + if (code) + fprintf(stderr, + "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, + rn, light_onp4, setting, (setting ? "ON" : "OFF")); + else + OOP_DISPLAY(light_onp4); + setting = (setting ? 0 : 1); + + sleep(1); + + WOP_DRAWSTRING(text_onp1->o_window, &strparams); + strparams.x++; + strparams.y++; + sleep(1); + + } /*Flash loop */ OOP_DISPLAY(text_onp1); /* - * Start writing stuff to our text object. - */ + * Start writing stuff to our text object. + */ sprintf(s, "%s", "This is the first line"); code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); if (code) - fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code); + fprintf(stderr, + "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", + pn, rn, s, strlen(s), text_onp1, code); sleep(2); sprintf(s, "%s", "This is the"); code = gator_text_Write(text_onp1, s, strlen(s), 0, 0); if (code) - fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code); + fprintf(stderr, + "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", + pn, rn, s, strlen(s), text_onp1, code); sleep(2); sprintf(s, "%s", " second line"); code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); if (code) - fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code); + fprintf(stderr, + "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", + pn, rn, s, strlen(s), text_onp1, code); sleep(2); sprintf(s, "%s", "This is the highlighted third line"); code = gator_text_Write(text_onp1, s, strlen(s), 1, 1); if (code) - fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code); + fprintf(stderr, + "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", + pn, rn, s, strlen(s), text_onp1, code); sleep(2); - sprintf(s, "%s", "This is the very, very, very, very, very, very, very long fourth line"); + sprintf(s, "%s", + "This is the very, very, very, very, very, very, very long fourth line"); code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); if (code) - fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code); + fprintf(stderr, + "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", + pn, rn, s, strlen(s), text_onp1, code); sleep(2); sprintf(s, "%s", "This is line 5"); code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); if (code) - fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code); + fprintf(stderr, + "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", + pn, rn, s, strlen(s), text_onp1, code); sleep(2); sprintf(s, "%s", "This is line 6"); code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); if (code) - fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code); + fprintf(stderr, + "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", + pn, rn, s, strlen(s), text_onp1, code); sleep(2); sprintf(s, "%s", "This is line 7"); code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); if (code) - fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code); + fprintf(stderr, + "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", + pn, rn, s, strlen(s), text_onp1, code); sleep(4); /* - * Now, try to scroll the sucker. - */ - for (i = 0; i<10; i++) { - code = gator_text_Scroll(text_onp1, 1, GATOR_TEXT_SCROLL_UP); - if (code) - fprintf(stderr, "[%s:%s] Can't scroll up 1 line in text object at 0x%x\n", pn, rn, text_onp1); - sleep(2); + * Now, try to scroll the sucker. + */ + for (i = 0; i < 10; i++) { + code = gator_text_Scroll(text_onp1, 1, GATOR_TEXT_SCROLL_UP); + if (code) + fprintf(stderr, + "[%s:%s] Can't scroll up 1 line in text object at 0x%x\n", + pn, rn, text_onp1); + sleep(2); } for (i = 0; i < 10; i++) { - code = gator_text_Scroll(text_onp1, 2, GATOR_TEXT_SCROLL_DOWN); - fprintf(stderr, "[%s:%s] Can't scroll down 2 lines in text object at 0x%x\n", pn, rn, text_onp1); - sleep(2); + code = gator_text_Scroll(text_onp1, 2, GATOR_TEXT_SCROLL_DOWN); + fprintf(stderr, + "[%s:%s] Can't scroll down 2 lines in text object at 0x%x\n", + pn, rn, text_onp1); + sleep(2); } /* - * Before leaving, we clean up our windows. - */ + * Before leaving, we clean up our windows. + */ WOP_CLEANUP(&gator_basegwin); -} /*test_objects*/ +} /*test_objects */ /*------------------------------------------------------------------------ * object_testInit @@ -345,33 +385,35 @@ static int test_objects(pkg) * Initializes this program. *------------------------------------------------------------------------*/ -static int object_testInit(as, arock) - struct cmd_syndesc *as; - char *arock; +static int +object_testInit(as, arock) + struct cmd_syndesc *as; + char *arock; -{ /*object_testInit*/ +{ /*object_testInit */ - static char rn[] = "object_testInit"; /*Routine name*/ - int wpkg_to_use; /*Window package to use*/ + static char rn[] = "object_testInit"; /*Routine name */ + int wpkg_to_use; /*Window package to use */ if (as->parms[P_DEBUG].items != 0) object_debug = 1; wpkg_to_use = atoi(as->parms[P_PACKAGE].items->data); - fprintf(stderr, "[%s:%s] Using graphics package %d: ", pn, rn, wpkg_to_use); + fprintf(stderr, "[%s:%s] Using graphics package %d: ", pn, rn, + wpkg_to_use); switch (wpkg_to_use) { - case GATOR_WIN_CURSES: - fprintf(stderr, "curses\n"); - break; - case GATOR_WIN_DUMB: - fprintf(stderr, "dumb terminal\n"); - break; - case GATOR_WIN_X11: - fprintf(stderr, "X11\n"); - break; - default: - fprintf(stderr, "Illegal graphics package: %d\n", wpkg_to_use); - exit(-1); - } /*end switch (wpkg_to_use)*/ + case GATOR_WIN_CURSES: + fprintf(stderr, "curses\n"); + break; + case GATOR_WIN_DUMB: + fprintf(stderr, "dumb terminal\n"); + break; + case GATOR_WIN_X11: + fprintf(stderr, "X11\n"); + break; + default: + fprintf(stderr, "Illegal graphics package: %d\n", wpkg_to_use); + exit(-1); + } /*end switch (wpkg_to_use) */ /* * Now, drive the sucker. @@ -381,21 +423,21 @@ static int object_testInit(as, arock) /* * We initialized (and ran) correctly, so return the good news. */ - return(0); + return (0); -} /*object_testInit*/ +} /*object_testInit */ #include "AFS_component_version_number.c" main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; -{ /*main*/ +{ /*main */ - static char rn[] = "main"; /*Routine name*/ - register afs_int32 code; /*Return code*/ - register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor*/ + static char rn[] = "main"; /*Routine name */ + register afs_int32 code; /*Return code */ + register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor */ /* * Set up the commands we understand. @@ -404,8 +446,7 @@ main(argc, argv) "Initialize the program"); cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED, "Graphics package to use"); - cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, - "Turn debugging on"); + cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Turn debugging on"); /* * Parse command-line switches & execute the test, then get the heck @@ -413,8 +454,9 @@ main(argc, argv) */ code = cmd_Dispatch(argc, argv); if (code) { - fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code); + fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", + pn, rn, code); exit(1); } -} /*main*/ +} /*main */ diff --git a/src/gtx/objects.c b/src/gtx/objects.c index 693c73231..5700d6f72 100644 --- a/src/gtx/objects.c +++ b/src/gtx/objects.c @@ -16,24 +16,36 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/objects.c,v 1.1.1.4 2001/07/14 22:22:05 hartmans Exp $"); - -#include "gtxobjects.h" /*Interface for this module*/ -#include "gtxtextobj.h" /*Text object interface*/ -#include "gtxlightobj.h" /*Light object interface*/ -#include "gtxobjdict.h" /*Object dictionary module*/ -#include /*Standard I/O stuff*/ +RCSID + ("$Header: /cvs/openafs/src/gtx/objects.c,v 1.6 2003/07/15 23:15:13 shadow Exp $"); + +#include "gtxobjects.h" /*Interface for this module */ +#include "gtxtextobj.h" /*Text object interface */ +#include "gtxlightobj.h" /*Light object interface */ +#include "gtxobjdict.h" /*Object dictionary module */ +#include /*Standard I/O stuff */ #include + + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#include + /* * Number of known gator object types. */ #define GATOR_NUM_OBJTYPES 3 -static char mn[] = "gator_objects"; /*Module name*/ -int objects_debug; /*Is debugging output on?*/ +static char mn[] = "gator_objects"; /*Module name */ +int objects_debug; /*Is debugging output on? */ -int (*on_create[GATOR_NUM_OBJTYPES])(); /*Array of ptrs to creation functions*/ -struct onodeops objops[GATOR_NUM_OBJTYPES]; /*Per-type op arrays*/ +int (*on_create[GATOR_NUM_OBJTYPES]) (); /*Array of ptrs to creation functions */ +struct onodeops objops[GATOR_NUM_OBJTYPES]; /*Per-type op arrays */ /*-------------------------------------------------------------------------------- @@ -57,24 +69,25 @@ struct onodeops objops[GATOR_NUM_OBJTYPES]; /*Per-type op arrays*/ * *--------------------------------------------------------------------------------*/ -int gator_objects_init(params) - struct onode_initparams *params; +int +gator_objects_init(params) + struct onode_initparams *params; -{ /*gator_objects_init*/ +{ /*gator_objects_init */ - static char rn[] = "gator_objects_init"; /*Routine name*/ - static int initialized = 0; /*Have we been called?*/ - register int code; /*Return code*/ + static char rn[] = "gator_objects_init"; /*Routine name */ + static int initialized = 0; /*Have we been called? */ + register int code; /*Return code */ /* * If we've already been called, just return. */ if (initialized) { - initialized++; - if (objects_debug) - fprintf(stderr, "[%s:%s] Called more than once!! (%d time[s])\n", - mn, rn, initialized); - return(0); + initialized++; + if (objects_debug) + fprintf(stderr, "[%s:%s] Called more than once!! (%d time[s])\n", + mn, rn, initialized); + return (0); } /* @@ -86,49 +99,61 @@ int gator_objects_init(params) * Set up the onode op array, one entry for each known gator object type. */ if (objects_debug) - fprintf(stderr, "[%s:%s] Setting up objops array\n", mn, rn); - objops[GATOR_OBJ_TEXT] = gator_text_ops; - objops[GATOR_OBJ_LIGHT] = gator_light_ops; + fprintf(stderr, "[%s:%s] Setting up objops array\n", mn, rn); + objops[GATOR_OBJ_TEXT] = gator_text_ops; + objops[GATOR_OBJ_LIGHT] = gator_light_ops; /* - * Initialize the object dictionary. - */ + * Initialize the object dictionary. + */ if (objects_debug) - fprintf(stderr, "[%s:%s] Initializing object dictionary\n", mn, rn); + fprintf(stderr, "[%s:%s] Initializing object dictionary\n", mn, rn); code = gator_objdict_init(objects_debug); if (code) { - fprintf(stderr, "[%s:%s] Can't initialize object dictionary: error code is %d\n", mn, rn, code); - return(code); + fprintf(stderr, + "[%s:%s] Can't initialize object dictionary: error code is %d\n", + mn, rn, code); + return (code); } /* - * Initialize the chosen window package. Remember the base window - * is accessible as gator_basegwin. - */ + * Initialize the chosen window package. Remember the base window + * is accessible as gator_basegwin. + */ if (objects_debug) { - fprintf(stderr, "[%s:%s] Initializing gator window module for package %d.\n", mn, rn, params->i_gwparams->i_type); - fprintf(stderr, "\tWindow init params are: type %d, (%d, %d), width=%d, height=%d, debug=%d\n", params->i_gwparams->i_type, params->i_gwparams->i_x, params->i_gwparams->i_y, params->i_gwparams->i_width, params->i_gwparams->i_height, params->i_gwparams->i_debug); + fprintf(stderr, + "[%s:%s] Initializing gator window module for package %d.\n", + mn, rn, params->i_gwparams->i_type); + fprintf(stderr, + "\tWindow init params are: type %d, (%d, %d), width=%d, height=%d, debug=%d\n", + params->i_gwparams->i_type, params->i_gwparams->i_x, + params->i_gwparams->i_y, params->i_gwparams->i_width, + params->i_gwparams->i_height, params->i_gwparams->i_debug); } code = gw_init(params->i_gwparams); if (code) { - fprintf(stderr, "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", mn, rn, params->i_gwparams->i_type, code); - return(code); + fprintf(stderr, + "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", + mn, rn, params->i_gwparams->i_type, code); + return (code); } /* - * Set up the array of creation functions. - */ + * Set up the array of creation functions. + */ if (objects_debug) - fprintf(stderr, "[%s:%s] Initializing gator object creation function array.\n", mn, rn); - on_create[GATOR_OBJ_TEXT] = gator_text_create; - on_create[GATOR_OBJ_LIGHT] = gator_light_create; + fprintf(stderr, + "[%s:%s] Initializing gator object creation function array.\n", + mn, rn); + on_create[GATOR_OBJ_TEXT] = gator_text_create; + on_create[GATOR_OBJ_LIGHT] = gator_light_create; /* * Finally, return the good news. */ - return(0); + return (0); -} /*gator_objects_init*/ +} /*gator_objects_init */ /*-------------------------------------------------------------------------------- * gator_objects_create @@ -150,88 +175,106 @@ int gator_objects_init(params) * As advertised. *--------------------------------------------------------------------------------*/ -struct onode *gator_objects_create(params) - struct onode_createparams *params; +struct onode * +gator_objects_create(params) + struct onode_createparams *params; -{ /*gator_objects_create*/ +{ /*gator_objects_create */ - static char rn[] = "gator_objects_create"; /*Routine name*/ - register int code; /*Return code*/ - struct onode *new_onode; /*Ptr to new onode*/ + static char rn[] = "gator_objects_create"; /*Routine name */ + register int code; /*Return code */ + struct onode *new_onode; /*Ptr to new onode */ if (objects_debug) { - fprintf(stderr, "[%s:%s] Creating onode type %d, named '%s'\n", mn, rn, params->cr_type, params->cr_name); - fprintf(stderr, "\tOrigin at (%d, %d)\n", params->cr_x, params->cr_y); - fprintf(stderr, "\tWidth=%d, height=%d\n", params->cr_width, params->cr_height); - fprintf(stderr, "\tHelpstring='%s'\n", params->cr_helpstring); - fprintf(stderr, "\tWindow struct at 0x%x\n", params->cr_window); + fprintf(stderr, "[%s:%s] Creating onode type %d, named '%s'\n", mn, + rn, params->cr_type, params->cr_name); + fprintf(stderr, "\tOrigin at (%d, %d)\n", params->cr_x, params->cr_y); + fprintf(stderr, "\tWidth=%d, height=%d\n", params->cr_width, + params->cr_height); + fprintf(stderr, "\tHelpstring='%s'\n", params->cr_helpstring); + fprintf(stderr, "\tWindow struct at 0x%x\n", params->cr_window); } if (objects_debug) - fprintf(stderr, "[%s:%s] Allocating %d bytes for new onode structure\n", mn, rn, sizeof(struct onode)); + fprintf(stderr, + "[%s:%s] Allocating %d bytes for new onode structure\n", mn, + rn, sizeof(struct onode)); new_onode = (struct onode *)malloc(sizeof(struct onode)); - if (new_onode == (struct onode *)0) { - fprintf(stderr, "[%s:%s] Can't allocate %d bytes for new onode structure; errno is %d\n", mn, rn, sizeof(struct onode), errno); - return((struct onode *)0); + if (new_onode == NULL) { + fprintf(stderr, + "[%s:%s] Can't allocate %d bytes for new onode structure; errno is %d\n", + mn, rn, sizeof(struct onode), errno); + return (NULL); } /* - * Fill in the onode fields we can do right away. - * **** Don't do anything with cr_helpstring yet - eventually, - * we'll create a scrollable text help object with it **** - */ + * Fill in the onode fields we can do right away. + * **** Don't do anything with cr_helpstring yet - eventually, + * we'll create a scrollable text help object with it **** + */ if (objects_debug) - fprintf(stderr, "[%s:%s] Filling in onode fields\n", mn, rn, sizeof(struct onode)); - new_onode->o_type = params->cr_type; + fprintf(stderr, "[%s:%s] Filling in onode fields\n", mn, rn, + sizeof(struct onode)); + new_onode->o_type = params->cr_type; strcpy(new_onode->o_name, params->cr_name); - new_onode->o_x = params->cr_x; - new_onode->o_y = params->cr_y; - new_onode->o_width = params->cr_width; - new_onode->o_height = params->cr_height; - new_onode->o_changed = 1; + new_onode->o_x = params->cr_x; + new_onode->o_y = params->cr_y; + new_onode->o_width = params->cr_width; + new_onode->o_height = params->cr_height; + new_onode->o_changed = 1; new_onode->o_refcount = 1; - new_onode->o_window = params->cr_window; - new_onode->o_op = &(objops[params->cr_type]); - new_onode->o_home = params->cr_home_obj; - new_onode->o_help = (struct onode *)0; - new_onode->o_nextobj = (struct onode *)0; - new_onode->o_upobj = params->cr_parent_obj; - new_onode->o_downobj = (struct onode *)0; + new_onode->o_window = params->cr_window; + new_onode->o_op = &(objops[params->cr_type]); + new_onode->o_home = params->cr_home_obj; + new_onode->o_help = NULL; + new_onode->o_nextobj = NULL; + new_onode->o_upobj = params->cr_parent_obj; + new_onode->o_downobj = NULL; /* - * Call the proper routine to initialize the private parts of the - * given object. - */ + * Call the proper routine to initialize the private parts of the + * given object. + */ if (objects_debug) - fprintf(stderr, "[%s:%s] Calling the creation routine for gator object type %d\n", mn, rn, params->cr_type); - code = (on_create[params->cr_type])(new_onode, params); + fprintf(stderr, + "[%s:%s] Calling the creation routine for gator object type %d\n", + mn, rn, params->cr_type); + code = (on_create[params->cr_type]) (new_onode, params); if (code) { - if (objects_debug) - fprintf(stderr, "[%s:%s] Error %d in creation routine for gator object type %d\n", mn, rn, code, params->cr_type); - free(new_onode); - return((struct onode *)0); + if (objects_debug) + fprintf(stderr, + "[%s:%s] Error %d in creation routine for gator object type %d\n", + mn, rn, code, params->cr_type); + free(new_onode); + return (NULL); } /* - * Set the links on the parent and previous objects, if so directed. - */ - if (params->cr_prev_obj != (struct onode *)0) { - if (objects_debug) - fprintf(stderr, "[%s:%s] Setting o_nextobj pointer in the previous object located at 0x%x (previous value was 0x%x)\n", mn, rn, params->cr_prev_obj, params->cr_prev_obj->o_nextobj); - params->cr_prev_obj->o_nextobj = new_onode; + * Set the links on the parent and previous objects, if so directed. + */ + if (params->cr_prev_obj != NULL) { + if (objects_debug) + fprintf(stderr, + "[%s:%s] Setting o_nextobj pointer in the previous object located at 0x%x (previous value was 0x%x)\n", + mn, rn, params->cr_prev_obj, + params->cr_prev_obj->o_nextobj); + params->cr_prev_obj->o_nextobj = new_onode; } - if (params->cr_parent_obj != (struct onode *)0) { - if (objects_debug) - fprintf(stderr, "[%s:%s] Setting o_downobj pointer in the parent object located at 0x%x (previous value was 0x%x)\n", mn, rn, params->cr_parent_obj, params->cr_parent_obj->o_downobj); - params->cr_parent_obj->o_downobj = new_onode; + if (params->cr_parent_obj != NULL) { + if (objects_debug) + fprintf(stderr, + "[%s:%s] Setting o_downobj pointer in the parent object located at 0x%x (previous value was 0x%x)\n", + mn, rn, params->cr_parent_obj, + params->cr_parent_obj->o_downobj); + params->cr_parent_obj->o_downobj = new_onode; } /* - * Return the location of the completely-initialized onode object. - */ - return(new_onode); + * Return the location of the completely-initialized onode object. + */ + return (new_onode); -} /*gator_objects_create*/ +} /*gator_objects_create */ /*-------------------------------------------------------------------------------- * gator_objects_lookup @@ -253,18 +296,20 @@ struct onode *gator_objects_create(params) * As advertised. *--------------------------------------------------------------------------------*/ -struct onode *gator_objects_lookup(onode_name) - char *onode_name; +struct onode * +gator_objects_lookup(onode_name) + char *onode_name; -{ /*gator_objects_lookup*/ +{ /*gator_objects_lookup */ - static char rn[] = "gator_objects_lookup"; /*Routine name*/ + static char rn[] = "gator_objects_lookup"; /*Routine name */ /* * Life is very simple here - just call the dictionary routine. */ if (objects_debug) - fprintf(stderr, "[%s:%s] Looking up gator object '%s'\n", mn, rn, onode_name); - return(gator_objdict_lookup(onode_name)); + fprintf(stderr, "[%s:%s] Looking up gator object '%s'\n", mn, rn, + onode_name); + return (gator_objdict_lookup(onode_name)); -} /*gator_objects_lookup*/ +} /*gator_objects_lookup */ diff --git a/src/gtx/screen_test.c b/src/gtx/screen_test.c index f576bd143..03dd8d36c 100644 --- a/src/gtx/screen_test.c +++ b/src/gtx/screen_test.c @@ -14,13 +14,14 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/screen_test.c,v 1.2 2003/01/02 03:55:50 hartmans Exp $"); - -#include "gtxwindows.h" /*Generalized window interface*/ -#include "gtxcurseswin.h" /*Curses window interface*/ -#include "gtxdumbwin.h" /*Dumb terminal window interface*/ -#include "gtxX11win.h" /*X11 window interface*/ -#include /*Command interpretation library*/ +RCSID + ("$Header: /cvs/openafs/src/gtx/screen_test.c,v 1.7 2003/07/15 23:15:13 shadow Exp $"); + +#include "gtxwindows.h" /*Generalized window interface */ +#include "gtxcurseswin.h" /*Curses window interface */ +#include "gtxdumbwin.h" /*Dumb terminal window interface */ +#include "gtxX11win.h" /*X11 window interface */ +#include /*Command interpretation library */ #include @@ -30,8 +31,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/screen_test.c,v 1.2 2003/01/02 03:5 #define P_PACKAGE 0 #define P_DEBUG 1 -static char pn[] = "screen_test"; /*Program name*/ -static int screen_debug = 0; /*Is debugging turned on?*/ +static char pn[] = "screen_test"; /*Program name */ +static int screen_debug = 0; /*Is debugging turned on? */ /*-------------------------------------------------------------------------------- * test_this_package @@ -54,62 +55,66 @@ static int screen_debug = 0; /*Is debugging turned on?*/ * As advertised. *--------------------------------------------------------------------------------*/ -static int test_this_package(pkg) - int pkg; - -{ /*test_this_package*/ - - static char rn[] = "test_this_package"; /*Routine name*/ - register int code; /*Return code*/ - struct gwin_initparams init_params; /*Window initialization params*/ - struct gator_cursesgwin_params c_crparams; /*Curses window creation params*/ - struct gator_dumbgwin_params d_crparams; /*Dumb terminal window creation params*/ - struct gator_X11gwin_params x_crparams; /*X11 window creation params*/ - struct gwin *newwin; /*New (sub)window*/ - struct gwin_strparams strparams; /*String-drawing params*/ - struct gwin_charparams charparams; /*Char-drawing params*/ - char s[128]; /*Test string*/ - int currx, curry; /*Sliding values of x & y*/ - int currhighlight; /*Highlight this time around?*/ +static int +test_this_package(pkg) + int pkg; + +{ /*test_this_package */ + + static char rn[] = "test_this_package"; /*Routine name */ + register int code; /*Return code */ + struct gwin_initparams init_params; /*Window initialization params */ + struct gator_cursesgwin_params c_crparams; /*Curses window creation params */ + struct gator_dumbgwin_params d_crparams; /*Dumb terminal window creation params */ + struct gator_X11gwin_params x_crparams; /*X11 window creation params */ + struct gwin *newwin; /*New (sub)window */ + struct gwin_strparams strparams; /*String-drawing params */ + struct gwin_charparams charparams; /*Char-drawing params */ + char s[128]; /*Test string */ + int currx, curry; /*Sliding values of x & y */ + int currhighlight; /*Highlight this time around? */ /* * Initialize the gator window package to drive the desired subsystem. */ - init_params.i_type = pkg; - init_params.i_x = 0; - init_params.i_y = 0; - init_params.i_width = 80; + init_params.i_type = pkg; + init_params.i_x = 0; + init_params.i_y = 0; + init_params.i_width = 80; init_params.i_height = 200; - init_params.i_debug = screen_debug; + init_params.i_debug = screen_debug; code = gw_init(&init_params); if (code) { - fprintf(stderr, "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", pn, rn, pkg, code); - return(code); + fprintf(stderr, + "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", + pn, rn, pkg, code); + return (code); } sprintf(s, "Screen has %d lines", LINES); - strparams.x = 5; - strparams.y = LINES / 2; - strparams.s = s; - strparams.highlight = 0; + strparams.x = 5; + strparams.y = LINES / 2; + strparams.s = s; + strparams.highlight = 0; WOP_DRAWSTRING(&gator_basegwin, &strparams); sprintf(s, "and %d columns", COLS); - strparams.x = 5; - strparams.y = strparams.y + 1; - strparams.s = s; - strparams.highlight = 1; + strparams.x = 5; + strparams.y = strparams.y + 1; + strparams.s = s; + strparams.highlight = 1; WOP_DRAWSTRING(&gator_basegwin, &strparams); /* * Draw a set of chars down a diagonal, pausing inbetween. */ currhighlight = 1; - for (currx = curry = 0; (currx < COLS) && (curry < LINES); currx++, curry++) { - charparams.x = currx; - charparams.y = curry; - charparams.c = 'x'; + for (currx = curry = 0; (currx < COLS) && (curry < LINES); + currx++, curry++) { + charparams.x = currx; + charparams.y = curry; + charparams.c = 'x'; charparams.highlight = currhighlight; currhighlight = (currhighlight ? 0 : 1); WOP_DRAWCHAR(&gator_basegwin, &charparams); @@ -120,50 +125,49 @@ static int test_this_package(pkg) /* * Fill in the new window creation parameters and go for it. */ - c_crparams.gwin_params.cr_type = pkg; - c_crparams.gwin_params.cr_x = 40; - c_crparams.gwin_params.cr_y = 5; - c_crparams.gwin_params.cr_width = 20; - c_crparams.gwin_params.cr_height = 10; + c_crparams.gwin_params.cr_type = pkg; + c_crparams.gwin_params.cr_x = 40; + c_crparams.gwin_params.cr_y = 5; + c_crparams.gwin_params.cr_width = 20; + c_crparams.gwin_params.cr_height = 10; c_crparams.gwin_params.cr_parentwin = (struct gwin *)(&gator_basegwin); - c_crparams.charwidth = 8; - c_crparams.charheight = 13; - c_crparams.box_vertchar = '|'; + c_crparams.charwidth = 8; + c_crparams.charheight = 13; + c_crparams.box_vertchar = '|'; c_crparams.box_horizchar = '-'; newwin = WOP_CREATE(&c_crparams); - if (newwin == (struct gwin *)0) { + if (newwin == NULL) { fprintf(stderr, "[%s:%s] Can't create a new window\n", pn, rn); - } - else - if (screen_debug) - fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn, newwin); + } else if (screen_debug) + fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn, + newwin); /* * Draw something to the new window; first, a highlighted banner. */ sprintf(s, "%s", "Sub-window "); - strparams.x = 1; - strparams.y = 1; - strparams.s = s; - strparams.highlight = 1; + strparams.x = 1; + strparams.y = 1; + strparams.s = s; + strparams.highlight = 1; WOP_DRAWSTRING(newwin, &strparams); /* * Next, draw an `x' at each corner. */ - charparams.c = 'x'; + charparams.c = 'x'; charparams.highlight = 1; - charparams.x = 1; - charparams.y = 2; + charparams.x = 1; + charparams.y = 2; WOP_DRAWCHAR(newwin, &charparams); - charparams.x = 18; - charparams.y = 2; + charparams.x = 18; + charparams.y = 2; WOP_DRAWCHAR(newwin, &charparams); - charparams.x = 1; - charparams.y = 8; + charparams.x = 1; + charparams.y = 8; WOP_DRAWCHAR(newwin, &charparams); - charparams.x = 18; - charparams.y = 8; + charparams.x = 18; + charparams.y = 8; WOP_DRAWCHAR(newwin, &charparams); /* @@ -172,20 +176,20 @@ static int test_this_package(pkg) WOP_BOX(newwin); /* - * Draw a few other things in the original window. - */ + * Draw a few other things in the original window. + */ sprintf(s, "Screen has %d lines", LINES); - strparams.x = 5; - strparams.y = LINES / 2; - strparams.s = s; - strparams.highlight = 0; + strparams.x = 5; + strparams.y = LINES / 2; + strparams.s = s; + strparams.highlight = 0; WOP_DRAWSTRING(&gator_basegwin, &strparams); sprintf(s, "and %d columns", COLS); - strparams.x = 5; - strparams.y = strparams.y + 1; - strparams.s = s; - strparams.highlight = 1; + strparams.x = 5; + strparams.y = strparams.y + 1; + strparams.s = s; + strparams.highlight = 1; WOP_DRAWSTRING(&gator_basegwin, &strparams); /* @@ -196,7 +200,7 @@ static int test_this_package(pkg) WOP_DISPLAY(&gator_basegwin); WOP_CLEANUP(&gator_basegwin); -} /*test_this_package*/ +} /*test_this_package */ /*-------------------------------------------------------------------------------- * screen_testInit @@ -219,32 +223,34 @@ static int test_this_package(pkg) * Initializes this program. *--------------------------------------------------------------------------------*/ -static int screen_testInit(as, arock) - struct cmd_syndesc *as; - char *arock; +static int +screen_testInit(as, arock) + struct cmd_syndesc *as; + char *arock; -{ /*screen_testInit*/ +{ /*screen_testInit */ - static char rn[] = "screen_testInit"; /*Routine name*/ - int pkg_to_test; /*Which package to test*/ + static char rn[] = "screen_testInit"; /*Routine name */ + int pkg_to_test; /*Which package to test */ if (as->parms[P_DEBUG].items != 0) screen_debug = 1; pkg_to_test = atoi(as->parms[P_PACKAGE].items->data); - fprintf(stderr, "[%s:%s] Testing graphics package %d: ", pn, rn, pkg_to_test); + fprintf(stderr, "[%s:%s] Testing graphics package %d: ", pn, rn, + pkg_to_test); switch (pkg_to_test) { - case GATOR_WIN_CURSES: - fprintf(stderr, "curses\n"); - break; - case GATOR_WIN_DUMB: - fprintf(stderr, "dumb terminal\n"); - break; - case GATOR_WIN_X11: - fprintf(stderr, "X11\n"); - break; - default: - fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test); - } /*end switch (pkg_to_test)*/ + case GATOR_WIN_CURSES: + fprintf(stderr, "curses\n"); + break; + case GATOR_WIN_DUMB: + fprintf(stderr, "dumb terminal\n"); + break; + case GATOR_WIN_X11: + fprintf(stderr, "X11\n"); + break; + default: + fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test); + } /*end switch (pkg_to_test) */ /* * Now, drive the sucker. @@ -254,37 +260,40 @@ static int screen_testInit(as, arock) /* * We initialized (and ran) correctly, so return the good news. */ - return(0); + return (0); -} /*screen_testInit*/ +} /*screen_testInit */ #include "AFS_component_version_number.c" main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; -{ /*main*/ +{ /*main */ - static char rn[] = "main"; /*Routine name*/ - register afs_int32 code; /*Return code*/ - register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor*/ + static char rn[] = "main"; /*Routine name */ + register afs_int32 code; /*Return code */ + register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor */ /* * There really aren't any opcodes here, but we do want to interpret switches * from the command line. So, all we need do is set up the initcmd ``opcode''. */ - ts = cmd_CreateSyntax("initcmd", screen_testInit, 0, "Initialize, interpret command line"); - cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED, "Graphics package to use"); - cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Turn debugging on"); + ts = cmd_CreateSyntax("initcmd", screen_testInit, 0, + "Initialize, interpret command line"); + cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED, + "Graphics package to use"); + cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Turn debugging on"); /* * Parse command-line switches & execute the test, then get the heck out of here. */ code = cmd_Dispatch(argc, argv); if (code) { - fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code); + fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", + pn, rn, code); exit(1); } -} /*main*/ +} /*main */ diff --git a/src/gtx/textcb.c b/src/gtx/textcb.c index 8ada5dbc2..ce1b7bc74 100644 --- a/src/gtx/textcb.c +++ b/src/gtx/textcb.c @@ -16,13 +16,23 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/textcb.c,v 1.1.1.5 2001/09/11 14:32:47 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/textcb.c,v 1.7 2003/07/15 23:15:13 shadow Exp $"); -#include "gtxtextcb.h" /*Module interface*/ -#include /*Standard I/O stuff*/ +#include "gtxtextcb.h" /*Module interface */ +#include /*Standard I/O stuff */ #include -static int gator_textcb_debug; /*Is debugging output turned on?*/ +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#include + +static int gator_textcb_debug; /*Is debugging output turned on? */ /*------------------------------------------------------------------------ * gator_textcb_Init @@ -44,25 +54,26 @@ static int gator_textcb_debug; /*Is debugging output turned on?*/ * Just remembers if debugging output should be generated. *------------------------------------------------------------------------*/ -int gator_textcb_Init(a_debug) - int a_debug; +int +gator_textcb_Init(a_debug) + int a_debug; -{ /*gator_textcb_Init*/ +{ /*gator_textcb_Init */ - static int initd; /*Have we been called already?*/ - static char rn[] = "gator_textcb_Init"; /*Routine name*/ + static int initd; /*Have we been called already? */ + static char rn[] = "gator_textcb_Init"; /*Routine name */ if (initd) { - fprintf(stderr, "[%s] Initialization routine called multiple times!!\n", rn); - return(0); - } - else - initd = 1; + fprintf(stderr, + "[%s] Initialization routine called multiple times!!\n", rn); + return (0); + } else + initd = 1; gator_textcb_debug = a_debug; - return(0); + return (0); -} /*gator_textcb_Init*/ +} /*gator_textcb_Init */ /*------------------------------------------------------------------------ * gator_textcb_Create @@ -85,135 +96,151 @@ int gator_textcb_Init(a_debug) * As advertised; space is allocated for the circ buff. *------------------------------------------------------------------------*/ -struct gator_textcb_hdr *gator_textcb_Create(a_maxEntriesStored, a_maxCharsPerEntry) - int a_maxEntriesStored; - int a_maxCharsPerEntry; - -{ /*gator_textcb_Create*/ - - static char rn[] = "gator_textcb_Create"; /*Routine name*/ - char *newBuff; /*Ptr to new text buffer*/ - struct gator_textcb_entry *newEntries; /*Ptr to new text entries*/ - struct gator_textcb_hdr *newHdr; /*Ptr to new text hdr*/ - int bytesToAllocate; /*Num bytes to allocate*/ - int numBuffBytes; /*Num bytes in text buffer*/ - int curr_ent_num; /*Current entry number*/ - struct gator_textcb_entry *curr_ent; /*Ptr to current entry*/ - char *curr_buff; /*Ptr to current buff pos*/ - int curr_inv; /*Current inversion idx*/ - char *blankLine; /*Ptr to blank line*/ - int i; /*Loop variable*/ +struct gator_textcb_hdr * +gator_textcb_Create(a_maxEntriesStored, a_maxCharsPerEntry) + int a_maxEntriesStored; + int a_maxCharsPerEntry; + +{ /*gator_textcb_Create */ + + static char rn[] = "gator_textcb_Create"; /*Routine name */ + char *newBuff; /*Ptr to new text buffer */ + struct gator_textcb_entry *newEntries; /*Ptr to new text entries */ + struct gator_textcb_hdr *newHdr; /*Ptr to new text hdr */ + int bytesToAllocate; /*Num bytes to allocate */ + int numBuffBytes; /*Num bytes in text buffer */ + int curr_ent_num; /*Current entry number */ + struct gator_textcb_entry *curr_ent; /*Ptr to current entry */ + char *curr_buff; /*Ptr to current buff pos */ + int curr_inv; /*Current inversion idx */ + char *blankLine; /*Ptr to blank line */ + int i; /*Loop variable */ /* - * Start off by allocating the text buffer itself. Don't forget we - * need to allocate one more character per line, to make sure we can - * always null-terminate them. We also need to allocate the blank - * line buffer. - */ - numBuffBytes = bytesToAllocate = a_maxEntriesStored * - (a_maxCharsPerEntry + 1); + * Start off by allocating the text buffer itself. Don't forget we + * need to allocate one more character per line, to make sure we can + * always null-terminate them. We also need to allocate the blank + * line buffer. + */ + numBuffBytes = bytesToAllocate = + a_maxEntriesStored * (a_maxCharsPerEntry + 1); if (gator_textcb_debug) - fprintf(stderr, "[%s] Allocating %d bytes for the text buffer\n", rn, bytesToAllocate); - newBuff = (char *) malloc(bytesToAllocate); - if (newBuff == (char *)0) { - fprintf(stderr, "[%s] Can't allocate %d bytes for text buffer; errno is %d\n", rn, bytesToAllocate, errno); - return((struct gator_textcb_hdr *)0); - } - else - if (gator_textcb_debug) + fprintf(stderr, "[%s] Allocating %d bytes for the text buffer\n", rn, + bytesToAllocate); + newBuff = (char *)malloc(bytesToAllocate); + if (newBuff == NULL) { + fprintf(stderr, + "[%s] Can't allocate %d bytes for text buffer; errno is %d\n", + rn, bytesToAllocate, errno); + return ((struct gator_textcb_hdr *)0); + } else if (gator_textcb_debug) fprintf(stderr, "[%s] Text buffer allocated at 0x%x\n", rn, newBuff); - blankLine = (char *) malloc(a_maxCharsPerEntry + 1); - if (blankLine == (char *)0) { - fprintf(stderr, "[%s] Can't allocate %d bytes for blank line buffer; errno is %d\n", rn, a_maxCharsPerEntry+1, errno); - free(newBuff); - return((struct gator_textcb_hdr *)0); + blankLine = (char *)malloc(a_maxCharsPerEntry + 1); + if (blankLine == NULL) { + fprintf(stderr, + "[%s] Can't allocate %d bytes for blank line buffer; errno is %d\n", + rn, a_maxCharsPerEntry + 1, errno); + free(newBuff); + return ((struct gator_textcb_hdr *)0); } /* - * Next, allocate the entry array. - */ + * Next, allocate the entry array. + */ bytesToAllocate = a_maxEntriesStored * sizeof(struct gator_textcb_entry); if (gator_textcb_debug) - fprintf(stderr, "[%s] Allocating %d bytes for the %d text entry array items\n", rn, bytesToAllocate, a_maxEntriesStored); - newEntries = (struct gator_textcb_entry *) malloc(bytesToAllocate); + fprintf(stderr, + "[%s] Allocating %d bytes for the %d text entry array items\n", + rn, bytesToAllocate, a_maxEntriesStored); + newEntries = (struct gator_textcb_entry *)malloc(bytesToAllocate); if (newEntries == (struct gator_textcb_entry *)0) { - fprintf(stderr, "[%s] Can't allocate %d bytes for the %d-member text entry array; errno is %d\n", rn, bytesToAllocate, a_maxEntriesStored, errno); - free(newBuff); - free(blankLine); - return((struct gator_textcb_hdr *)0); - } - else - if (gator_textcb_debug) - fprintf(stderr, "[%s] Text buffer entry array allocated at 0x%x\n", rn, newEntries); + fprintf(stderr, + "[%s] Can't allocate %d bytes for the %d-member text entry array; errno is %d\n", + rn, bytesToAllocate, a_maxEntriesStored, errno); + free(newBuff); + free(blankLine); + return ((struct gator_textcb_hdr *)0); + } else if (gator_textcb_debug) + fprintf(stderr, "[%s] Text buffer entry array allocated at 0x%x\n", + rn, newEntries); /* - * Finish off by allocating the text circular buffer header. - */ + * Finish off by allocating the text circular buffer header. + */ bytesToAllocate = sizeof(struct gator_textcb_hdr); if (gator_textcb_debug) - fprintf(stderr, "[%s] Allocating %d bytes for the text circular buffer header\n", rn, bytesToAllocate); - newHdr = (struct gator_textcb_hdr *) malloc(bytesToAllocate); + fprintf(stderr, + "[%s] Allocating %d bytes for the text circular buffer header\n", + rn, bytesToAllocate); + newHdr = (struct gator_textcb_hdr *)malloc(bytesToAllocate); if (newHdr == (struct gator_textcb_hdr *)0) { - fprintf(stderr, "[%s] Can't allocate %d bytes for text circular buffer header; errno is %d\n", rn, bytesToAllocate, errno); - free(newBuff); - free(blankLine); - free(newEntries); - return((struct gator_textcb_hdr *)0); - } - else - if (gator_textcb_debug) - fprintf(stderr, "[%s] Text circular buffer header allocated at 0x%x\n", rn, newHdr); + fprintf(stderr, + "[%s] Can't allocate %d bytes for text circular buffer header; errno is %d\n", + rn, bytesToAllocate, errno); + free(newBuff); + free(blankLine); + free(newEntries); + return ((struct gator_textcb_hdr *)0); + } else if (gator_textcb_debug) + fprintf(stderr, + "[%s] Text circular buffer header allocated at 0x%x\n", rn, + newHdr); /* - * Now, just initialize all the pieces and plug them in. - */ + * Now, just initialize all the pieces and plug them in. + */ if (gator_textcb_debug) - fprintf(stderr, "[%s] Zeroing %d bytes in text buffer at 0x%x\n", rn, numBuffBytes, newBuff); + fprintf(stderr, "[%s] Zeroing %d bytes in text buffer at 0x%x\n", rn, + numBuffBytes, newBuff); memset(newBuff, 0, numBuffBytes); if (gator_textcb_debug) - fprintf(stderr, "[%s] Initializing blank line buffer at 0x%x\n", rn, blankLine); - for (i=0; i < a_maxCharsPerEntry; i++) - *(blankLine+i) = ' '; - *(blankLine+a_maxCharsPerEntry) = '\0'; + fprintf(stderr, "[%s] Initializing blank line buffer at 0x%x\n", rn, + blankLine); + for (i = 0; i < a_maxCharsPerEntry; i++) + *(blankLine + i) = ' '; + *(blankLine + a_maxCharsPerEntry) = '\0'; /* - * Initialize each buffer entry. - */ + * Initialize each buffer entry. + */ for (curr_ent_num = 0, curr_buff = newBuff, curr_ent = newEntries; curr_ent_num < a_maxEntriesStored; - curr_ent++, curr_ent_num++, curr_buff += (a_maxCharsPerEntry+1)) { - if (gator_textcb_debug) - fprintf(stderr, "[%s] Initializing buffer entry %d; its text buffer address is 0x%x\n", rn, curr_ent_num, curr_buff); - curr_ent->ID = 0; - curr_ent->highlight = 0; - curr_ent->numInversions = 0; - curr_ent->charsUsed = 0; - curr_ent->textp = curr_buff; - memcpy(curr_ent->textp, blankLine, a_maxCharsPerEntry+1); - for (curr_inv = 0; curr_inv < GATOR_TEXTCB_MAXINVERSIONS; curr_inv++) - curr_ent->inversion[curr_inv] = 0; - - } /*Init each buffer entry*/ + curr_ent++, curr_ent_num++, curr_buff += (a_maxCharsPerEntry + 1)) { + if (gator_textcb_debug) + fprintf(stderr, + "[%s] Initializing buffer entry %d; its text buffer address is 0x%x\n", + rn, curr_ent_num, curr_buff); + curr_ent->ID = 0; + curr_ent->highlight = 0; + curr_ent->numInversions = 0; + curr_ent->charsUsed = 0; + curr_ent->textp = curr_buff; + memcpy(curr_ent->textp, blankLine, a_maxCharsPerEntry + 1); + for (curr_inv = 0; curr_inv < GATOR_TEXTCB_MAXINVERSIONS; curr_inv++) + curr_ent->inversion[curr_inv] = 0; + + } /*Init each buffer entry */ if (gator_textcb_debug) - fprintf(stderr, "[%s] Filling in circ buff header at 0x%x\n", rn, newHdr); + fprintf(stderr, "[%s] Filling in circ buff header at 0x%x\n", rn, + newHdr); Lock_Init(&(newHdr->cbLock)); - newHdr->maxEntriesStored = a_maxEntriesStored; - newHdr->maxCharsPerEntry = a_maxCharsPerEntry; - newHdr->currEnt = 0; - newHdr->currEntIdx = 0; - newHdr->oldestEnt = 0; - newHdr->oldestEntIdx = 0; - newHdr->entry = newEntries; - newHdr->blankLine = blankLine; + newHdr->maxEntriesStored = a_maxEntriesStored; + newHdr->maxCharsPerEntry = a_maxCharsPerEntry; + newHdr->currEnt = 0; + newHdr->currEntIdx = 0; + newHdr->oldestEnt = 0; + newHdr->oldestEntIdx = 0; + newHdr->entry = newEntries; + newHdr->blankLine = blankLine; /* - * Finally, return the location of the new header. - */ - return(newHdr); + * Finally, return the location of the new header. + */ + return (newHdr); -} /*gator_textcb_Create*/ +} /*gator_textcb_Create */ /*------------------------------------------------------------------------ * bumpCB @@ -234,62 +261,73 @@ struct gator_textcb_hdr *gator_textcb_Create(a_maxEntriesStored, a_maxCharsPerEn * As advertised. *------------------------------------------------------------------------*/ -static struct gator_textcb_entry *bumpEntry(a_cbhdr) - struct gator_textcb_hdr *a_cbhdr; +static struct gator_textcb_entry * +bumpEntry(a_cbhdr) + struct gator_textcb_hdr *a_cbhdr; -{ /*bumpEntry*/ +{ /*bumpEntry */ - static char rn[] = "bumpEntry"; /*Routine name*/ - struct gator_textcb_entry *curr_ent; /*Ptr to current entry*/ - int inv; /*Inversion number*/ + static char rn[] = "bumpEntry"; /*Routine name */ + struct gator_textcb_entry *curr_ent; /*Ptr to current entry */ + int inv; /*Inversion number */ /* * Bump the total number of writes, and don't forget to advance * the oldest entry, if appropriate. */ if (gator_textcb_debug) - fprintf(stderr, "[%s]: Bumping entry for circular buffer at 0x%x; current values: currEnt=%d (idx %d), oldestEnt=%d (idx %d), maxEntriesStored=%d\n", rn, a_cbhdr, a_cbhdr->currEnt, a_cbhdr->currEntIdx, a_cbhdr->oldestEnt, a_cbhdr->oldestEntIdx, a_cbhdr->maxEntriesStored); + fprintf(stderr, + "[%s]: Bumping entry for circular buffer at 0x%x; current values: currEnt=%d (idx %d), oldestEnt=%d (idx %d), maxEntriesStored=%d\n", + rn, a_cbhdr, a_cbhdr->currEnt, a_cbhdr->currEntIdx, + a_cbhdr->oldestEnt, a_cbhdr->oldestEntIdx, + a_cbhdr->maxEntriesStored); a_cbhdr->currEnt++; if (++(a_cbhdr->currEntIdx) >= a_cbhdr->maxEntriesStored) - a_cbhdr->currEntIdx = 0; + a_cbhdr->currEntIdx = 0; curr_ent = a_cbhdr->entry + a_cbhdr->currEntIdx; if (gator_textcb_debug) - fprintf(stderr, "[%s] Zeroing entry %d (idx %d) at 0x%x\n", rn, a_cbhdr->currEnt, a_cbhdr->currEntIdx, curr_ent); - - curr_ent->ID = a_cbhdr->currEnt; - curr_ent->highlight = 0; + fprintf(stderr, "[%s] Zeroing entry %d (idx %d) at 0x%x\n", rn, + a_cbhdr->currEnt, a_cbhdr->currEntIdx, curr_ent); + + curr_ent->ID = a_cbhdr->currEnt; + curr_ent->highlight = 0; curr_ent->numInversions = 0; - curr_ent->charsUsed = 0; + curr_ent->charsUsed = 0; /* - * Copy over a blank line into the one we're initializing. We - * copy over the trailing null, too. - */ - memcpy(curr_ent->textp, a_cbhdr->blankLine, a_cbhdr->maxCharsPerEntry+1); - for (inv=0; inv < GATOR_TEXTCB_MAXINVERSIONS; inv++) - curr_ent->inversion[inv] = 0; + * Copy over a blank line into the one we're initializing. We + * copy over the trailing null, too. + */ + memcpy(curr_ent->textp, a_cbhdr->blankLine, + a_cbhdr->maxCharsPerEntry + 1); + for (inv = 0; inv < GATOR_TEXTCB_MAXINVERSIONS; inv++) + curr_ent->inversion[inv] = 0; /* - * If we've already stated circulating in the buffer, remember to - * bump the oldest entry info too. - */ + * If we've already stated circulating in the buffer, remember to + * bump the oldest entry info too. + */ if (a_cbhdr->currEnt >= a_cbhdr->maxEntriesStored) { - if (gator_textcb_debug) - fprintf(stderr, "[%s]: Advancing oldest entry number & index; was entry %d, index %d, now ", rn, a_cbhdr->oldestEnt, a_cbhdr->oldestEntIdx); - a_cbhdr->oldestEnt++; - if (++(a_cbhdr->oldestEntIdx) >= a_cbhdr->maxEntriesStored) - a_cbhdr->oldestEntIdx = 0; - if (gator_textcb_debug) - fprintf(stderr, "entry %d, index %d\n", a_cbhdr->oldestEnt, a_cbhdr->oldestEntIdx); - } /*Bump oldest entry info*/ + if (gator_textcb_debug) + fprintf(stderr, + "[%s]: Advancing oldest entry number & index; was entry %d, index %d, now ", + rn, a_cbhdr->oldestEnt, a_cbhdr->oldestEntIdx); + a_cbhdr->oldestEnt++; + if (++(a_cbhdr->oldestEntIdx) >= a_cbhdr->maxEntriesStored) + a_cbhdr->oldestEntIdx = 0; + if (gator_textcb_debug) + fprintf(stderr, "entry %d, index %d\n", a_cbhdr->oldestEnt, + a_cbhdr->oldestEntIdx); + } + /*Bump oldest entry info */ /* - * Finally, return the address of the newest current entry. - */ - return(curr_ent); + * Finally, return the address of the newest current entry. + */ + return (curr_ent); -} /*bumpEntry*/ +} /*bumpEntry */ /*------------------------------------------------------------------------ * gator_textcb_Write @@ -318,131 +356,151 @@ static struct gator_textcb_entry *bumpEntry(a_cbhdr) * As advertised. *------------------------------------------------------------------------*/ -int gator_textcb_Write(a_cbhdr, a_textToWrite, a_numChars, a_highlight, a_skip) - struct gator_textcb_hdr *a_cbhdr; - char *a_textToWrite; - int a_numChars; - int a_highlight; - int a_skip; +int +gator_textcb_Write(a_cbhdr, a_textToWrite, a_numChars, a_highlight, a_skip) + struct gator_textcb_hdr *a_cbhdr; + char *a_textToWrite; + int a_numChars; + int a_highlight; + int a_skip; -{ /*gator_textcb_Write*/ +{ /*gator_textcb_Write */ - static char rn[] = "gator_textcb_Write"; /*Routine name*/ - struct gator_textcb_entry *curr_ent; /*Ptr to current text entry*/ - int curr_ent_idx; /*Index of current entry*/ - int max_chars; /*Max chars per entry*/ - int chars_to_copy; /*Num chars to copy in*/ - int effective_highlight; /*Tmp highlight value*/ - char *dest; /*Destination of char copy*/ + static char rn[] = "gator_textcb_Write"; /*Routine name */ + struct gator_textcb_entry *curr_ent; /*Ptr to current text entry */ + int curr_ent_idx; /*Index of current entry */ + int max_chars; /*Max chars per entry */ + int chars_to_copy; /*Num chars to copy in */ + int effective_highlight; /*Tmp highlight value */ + char *dest; /*Destination of char copy */ /* - * Make sure we haven't been passed a bogus buffer, and lock it - * before we start. - */ + * Make sure we haven't been passed a bogus buffer, and lock it + * before we start. + */ if (a_cbhdr == (struct gator_textcb_hdr *)0) { - fprintf(stderr, "[%s]: Null pointer passed in for circ buff header!! Aborting write operation.\n", rn); - return(-1); + fprintf(stderr, + "[%s]: Null pointer passed in for circ buff header!! Aborting write operation.\n", + rn); + return (-1); } ObtainWriteLock(&(a_cbhdr->cbLock)); - curr_ent_idx = a_cbhdr->currEntIdx; - curr_ent = (a_cbhdr->entry) + curr_ent_idx; - max_chars = a_cbhdr->maxCharsPerEntry; + curr_ent_idx = a_cbhdr->currEntIdx; + curr_ent = (a_cbhdr->entry) + curr_ent_idx; + max_chars = a_cbhdr->maxCharsPerEntry; effective_highlight = curr_ent->highlight; if (curr_ent->numInversions % 2) - effective_highlight = (effective_highlight ? 0 : 1); + effective_highlight = (effective_highlight ? 0 : 1); if (gator_textcb_debug) - fprintf(stderr, "[%s]: Current entry: %d (at index %d, keeping %d max), effective highlight: %d, located at 0x%x\n", rn, a_cbhdr->currEnt, curr_ent_idx, a_cbhdr->maxEntriesStored, effective_highlight, curr_ent); + fprintf(stderr, + "[%s]: Current entry: %d (at index %d, keeping %d max), effective highlight: %d, located at 0x%x\n", + rn, a_cbhdr->currEnt, curr_ent_idx, a_cbhdr->maxEntriesStored, + effective_highlight, curr_ent); while (a_numChars > 0) { - /* - * There are still characters to stuff into our circular buffer. - */ - if (gator_textcb_debug) - fprintf(stderr, "[%s]: Top of write loop: %d char(s) left to write.\n", rn, a_numChars); - - if (curr_ent->charsUsed >= max_chars) { /* - * Bump the entry in the given circular buffer. - */ - if (gator_textcb_debug) - fprintf(stderr, "[%s]: Entry %d at index %d full, advancing to next one.\n", rn, a_cbhdr->currEnt, curr_ent_idx); - curr_ent = bumpEntry(a_cbhdr); - curr_ent_idx = a_cbhdr->currEntIdx; + * There are still characters to stuff into our circular buffer. + */ if (gator_textcb_debug) - fprintf(stderr, "[%s] New CB entry info: currEnt=%d (idx %d), oldestEnt=%d (idx %d), curr entry ptr is 0x%x\n", rn, a_cbhdr->currEnt, a_cbhdr->currEntIdx, a_cbhdr->oldestEnt, a_cbhdr->oldestEntIdx, curr_ent); - } /*Bump current entry*/ - - /* - * At this point, the current entry has room for at least one more - * character, and we have at least one more character to write. - * Insert as much from the user text as possible. - */ - chars_to_copy = max_chars - curr_ent->charsUsed; - if (a_numChars < chars_to_copy) - chars_to_copy = a_numChars; - dest = curr_ent->textp + curr_ent->charsUsed; - if (gator_textcb_debug) - fprintf(stderr, "[%s]: Copying %d char(s) into current entry at 0x%x (entry buffer starts at 0x%x)\n", rn, chars_to_copy, dest, curr_ent->textp); - - /* - * Handle highlighting and inversions. - */ - if (curr_ent->charsUsed == 0) { - /* - * No chars yet, so this sets the highlight field. - */ - effective_highlight = curr_ent->highlight = a_highlight; - } - else if (effective_highlight != a_highlight) { + fprintf(stderr, + "[%s]: Top of write loop: %d char(s) left to write.\n", + rn, a_numChars); + + if (curr_ent->charsUsed >= max_chars) { + /* + * Bump the entry in the given circular buffer. + */ + if (gator_textcb_debug) + fprintf(stderr, + "[%s]: Entry %d at index %d full, advancing to next one.\n", + rn, a_cbhdr->currEnt, curr_ent_idx); + curr_ent = bumpEntry(a_cbhdr); + curr_ent_idx = a_cbhdr->currEntIdx; + if (gator_textcb_debug) + fprintf(stderr, + "[%s] New CB entry info: currEnt=%d (idx %d), oldestEnt=%d (idx %d), curr entry ptr is 0x%x\n", + rn, a_cbhdr->currEnt, a_cbhdr->currEntIdx, + a_cbhdr->oldestEnt, a_cbhdr->oldestEntIdx, curr_ent); + } + + /*Bump current entry */ /* - * We need a new inversion, if there's room. - */ + * At this point, the current entry has room for at least one more + * character, and we have at least one more character to write. + * Insert as much from the user text as possible. + */ + chars_to_copy = max_chars - curr_ent->charsUsed; + if (a_numChars < chars_to_copy) + chars_to_copy = a_numChars; + dest = curr_ent->textp + curr_ent->charsUsed; if (gator_textcb_debug) - fprintf(stderr, "[%s]: Highlight mismatch, recording inversion at char loc %d\n", rn, curr_ent->charsUsed); - if (curr_ent->numInversions < GATOR_TEXTCB_MAXINVERSIONS) { - effective_highlight = a_highlight; - curr_ent->inversion[curr_ent->numInversions] = curr_ent->charsUsed; - curr_ent->numInversions++; + fprintf(stderr, + "[%s]: Copying %d char(s) into current entry at 0x%x (entry buffer starts at 0x%x)\n", + rn, chars_to_copy, dest, curr_ent->textp); + + /* + * Handle highlighting and inversions. + */ + if (curr_ent->charsUsed == 0) { + /* + * No chars yet, so this sets the highlight field. + */ + effective_highlight = curr_ent->highlight = a_highlight; + } else if (effective_highlight != a_highlight) { + /* + * We need a new inversion, if there's room. + */ + if (gator_textcb_debug) + fprintf(stderr, + "[%s]: Highlight mismatch, recording inversion at char loc %d\n", + rn, curr_ent->charsUsed); + if (curr_ent->numInversions < GATOR_TEXTCB_MAXINVERSIONS) { + effective_highlight = a_highlight; + curr_ent->inversion[curr_ent->numInversions] = + curr_ent->charsUsed; + curr_ent->numInversions++; + } else if (gator_textcb_debug) + fprintf(stderr, "[%s]: Out of inversions!!\n", rn); } - else - if (gator_textcb_debug) - fprintf(stderr, "[%s]: Out of inversions!!\n", rn); - } /*Handle inversion*/ - - /* - * Move the string chunk into its place in the buffer, bump the - * number of chars used in the current entry. - */ - strncpy(dest, a_textToWrite, chars_to_copy); - curr_ent->charsUsed += chars_to_copy; - a_textToWrite += chars_to_copy; - a_numChars -= chars_to_copy; - - } /*while (a_numChars > 0)*/ + + /*Handle inversion */ + /* + * Move the string chunk into its place in the buffer, bump the + * number of chars used in the current entry. + */ + strncpy(dest, a_textToWrite, chars_to_copy); + curr_ent->charsUsed += chars_to_copy; + a_textToWrite += chars_to_copy; + a_numChars -= chars_to_copy; + + } /*while (a_numChars > 0) */ /* - * All characters have been copied in. Handle the case where we've - * been asked to skip to the next entry, even if there's still room - * in the current one. - */ + * All characters have been copied in. Handle the case where we've + * been asked to skip to the next entry, even if there's still room + * in the current one. + */ if (a_skip) { - if (gator_textcb_debug) - fprintf(stderr, "[%s] Handling request to skip to next entry\n", rn); - if (curr_ent->charsUsed > 0) - curr_ent = bumpEntry(a_cbhdr); - else if (gator_textcb_debug) - fprintf(stderr, "[%s] Not skipping, we're already on a fresh entry\n", rn); - } /*Skip to the next entry*/ + fprintf(stderr, "[%s] Handling request to skip to next entry\n", + rn); + if (curr_ent->charsUsed > 0) + curr_ent = bumpEntry(a_cbhdr); + else if (gator_textcb_debug) + fprintf(stderr, + "[%s] Not skipping, we're already on a fresh entry\n", + rn); + } + /*Skip to the next entry */ /* - * We can now unlock the CB and return successfully. - */ + * We can now unlock the CB and return successfully. + */ ReleaseWriteLock(&(a_cbhdr->cbLock)); - return(0); + return (0); -} /*gator_textcb_Write*/ +} /*gator_textcb_Write */ /*------------------------------------------------------------------------ * gator_textcb_BlankLine @@ -467,39 +525,40 @@ int gator_textcb_Write(a_cbhdr, a_textToWrite, a_numChars, a_highlight, a_skip) * As advertised. *------------------------------------------------------------------------*/ -int gator_textcb_BlankLine(a_cbhdr, a_numBlanks) - struct gator_textcb_hdr *a_cbhdr; - int a_numBlanks; +int +gator_textcb_BlankLine(a_cbhdr, a_numBlanks) + struct gator_textcb_hdr *a_cbhdr; + int a_numBlanks; -{ /*gator_textcb_BlankLine*/ +{ /*gator_textcb_BlankLine */ - static char rn[] = "gator_textcb_BlankLine"; /*Routine name*/ + static char rn[] = "gator_textcb_BlankLine"; /*Routine name */ if (gator_textcb_debug) - fprintf(stderr, "[%s] Putting out %d blank lines to the CB at 0x%x\n", - rn, a_numBlanks, a_cbhdr); + fprintf(stderr, "[%s] Putting out %d blank lines to the CB at 0x%x\n", + rn, a_numBlanks, a_cbhdr); if (a_cbhdr == (struct gator_textcb_hdr *)0) { - if (gator_textcb_debug) - fprintf(stderr, "[%s] Null pointer passed for CB hdr!!\n", rn); - return(-1); + if (gator_textcb_debug) + fprintf(stderr, "[%s] Null pointer passed for CB hdr!!\n", rn); + return (-1); } while (a_numBlanks > 0) { - /* - * The bumpEntry routine returns a struct gator_textcb_entry - * pointer, but we don't need it here, so we don't assign it. - */ - bumpEntry(a_cbhdr); - a_numBlanks--; + /* + * The bumpEntry routine returns a struct gator_textcb_entry + * pointer, but we don't need it here, so we don't assign it. + */ + bumpEntry(a_cbhdr); + a_numBlanks--; } /* - * Return happily and successfully. - */ - return(0); + * Return happily and successfully. + */ + return (0); -} /*gator_textcb_Write*/ +} /*gator_textcb_Write */ /*------------------------------------------------------------------------ * gator_textcb_Delete @@ -526,46 +585,49 @@ int gator_textcb_BlankLine(a_cbhdr, a_numBlanks) * As advertised. *------------------------------------------------------------------------*/ -int gator_textcb_Delete(a_cbhdr) - struct gator_textcb_hdr *a_cbhdr; +int +gator_textcb_Delete(a_cbhdr) + struct gator_textcb_hdr *a_cbhdr; -{ /*gator_textcb_Delete*/ +{ /*gator_textcb_Delete */ - static char rn[] = "gator_textcb_Delete"; /*Routine name*/ + static char rn[] = "gator_textcb_Delete"; /*Routine name */ if (gator_textcb_debug) - fprintf(stderr, "[%s]: Deleting text circular buffer at 0x%x\n", - rn, a_cbhdr); + fprintf(stderr, "[%s]: Deleting text circular buffer at 0x%x\n", rn, + a_cbhdr); ObtainWriteLock(&(a_cbhdr->cbLock)); /* - * The beginning of the text buffer itself is pointed to by the - * first text entry. - */ + * The beginning of the text buffer itself is pointed to by the + * first text entry. + */ if (gator_textcb_debug) - fprintf(stderr, "[%s]: Freeing text buffer proper at 0x%x (%d bytes)\n", - rn, a_cbhdr->entry[0].textp, - (a_cbhdr->maxEntriesStored * a_cbhdr->maxCharsPerEntry)); + fprintf(stderr, + "[%s]: Freeing text buffer proper at 0x%x (%d bytes)\n", rn, + a_cbhdr->entry[0].textp, + (a_cbhdr->maxEntriesStored * a_cbhdr->maxCharsPerEntry)); free(a_cbhdr->entry[0].textp); - a_cbhdr->entry[0].textp = (char *)0; + a_cbhdr->entry[0].textp = NULL; if (gator_textcb_debug) - fprintf(stderr, "[%s]: Freeing text entry array at 0x%x (%d bytes)\n", - rn, a_cbhdr->entry, - (a_cbhdr->maxEntriesStored * sizeof(struct gator_textcb_entry))); + fprintf(stderr, "[%s]: Freeing text entry array at 0x%x (%d bytes)\n", + rn, a_cbhdr->entry, + (a_cbhdr->maxEntriesStored * + sizeof(struct gator_textcb_entry))); free(a_cbhdr->entry); a_cbhdr->entry = (struct gator_textcb_entry *)0; free(a_cbhdr->blankLine); - a_cbhdr->blankLine = (char *)0; + a_cbhdr->blankLine = NULL; /* - * Release the write lock on it, then free the header itself. - */ + * Release the write lock on it, then free the header itself. + */ ReleaseWriteLock(&(a_cbhdr->cbLock)); if (gator_textcb_debug) - fprintf(stderr, "[%s] Freeing cicular buffer header at 0x%x\n", - rn, a_cbhdr); + fprintf(stderr, "[%s] Freeing cicular buffer header at 0x%x\n", rn, + a_cbhdr); free(a_cbhdr); - return(0); + return (0); -} /*gator_textcb_Delete*/ +} /*gator_textcb_Delete */ diff --git a/src/gtx/textobject.c b/src/gtx/textobject.c index 6d8802d91..fec1fbadf 100644 --- a/src/gtx/textobject.c +++ b/src/gtx/textobject.c @@ -15,16 +15,26 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/textobject.c,v 1.1.1.4 2001/07/14 22:22:05 hartmans Exp $"); - -#include "gtxtextobj.h" /*Interface for this module*/ -#include "gtxwindows.h" /*Gator window interface*/ -#include "gtxcurseswin.h" /*Gator curses window interface*/ -#include "gtxdumbwin.h" /*Gator dumb terminal window interface*/ -#include "gtxX11win.h" /*Gator X11 window interface*/ -#include /*Standard I/O stuff*/ +RCSID + ("$Header: /cvs/openafs/src/gtx/textobject.c,v 1.6 2003/07/15 23:15:13 shadow Exp $"); + +#include "gtxtextobj.h" /*Interface for this module */ +#include "gtxwindows.h" /*Gator window interface */ +#include "gtxcurseswin.h" /*Gator curses window interface */ +#include "gtxdumbwin.h" /*Gator dumb terminal window interface */ +#include "gtxX11win.h" /*Gator X11 window interface */ +#include /*Standard I/O stuff */ #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#include + /*Externally-advertised array of text onode operations*/ struct onodeops gator_text_ops = { gator_text_destroy, @@ -32,7 +42,7 @@ struct onodeops gator_text_ops = { gator_text_release }; -static char mn[] = "gator_textobject"; /*Module name*/ +static char mn[] = "gator_textobject"; /*Module name */ #define GATOR_TEXTCB_DO_BOX 0 @@ -62,67 +72,78 @@ static char mn[] = "gator_textobject"; /*Module name*/ * structure. On failure, it remains unchanged. *------------------------------------------------------------------------*/ -int gator_text_create(text_onp, params) - struct onode *text_onp; - struct onode_createparams *params; +int +gator_text_create(text_onp, params) + struct onode *text_onp; + struct onode_createparams *params; -{ /*gator_text_create*/ +{ /*gator_text_create */ - static char rn[] = "gator_text_create"; /*Routine name*/ - struct gator_textobj_params *text_params; /*My specific creation params*/ - struct gator_textobj *text_data; /*Ptr to private data*/ - struct gator_textcb_hdr *newCB; /*Ptr to CB hdr*/ + static char rn[] = "gator_text_create"; /*Routine name */ + struct gator_textobj_params *text_params; /*My specific creation params */ + struct gator_textobj *text_data; /*Ptr to private data */ + struct gator_textcb_hdr *newCB; /*Ptr to CB hdr */ text_params = (struct gator_textobj_params *)params; if (objects_debug) { - fprintf(stderr, "[%s:%s] Private data passed to text object at 0x%x:\n", mn, rn, text_onp); - fprintf(stderr, "\tmaxEntries: %d, maxCharsPerEntry: %d\n", - text_params->maxEntries, text_params->maxCharsPerEntry); + fprintf(stderr, + "[%s:%s] Private data passed to text object at 0x%x:\n", mn, + rn, text_onp); + fprintf(stderr, "\tmaxEntries: %d, maxCharsPerEntry: %d\n", + text_params->maxEntries, text_params->maxCharsPerEntry); } /* - * Allocate the private data area. - */ + * Allocate the private data area. + */ if (objects_debug) - fprintf(stderr, "[%s:%s] Allocating %d bytes for text object private data region\n", mn, rn, sizeof(struct gator_textobj)); - text_data = (struct gator_textobj *) malloc(sizeof(struct gator_textobj)); + fprintf(stderr, + "[%s:%s] Allocating %d bytes for text object private data region\n", + mn, rn, sizeof(struct gator_textobj)); + text_data = (struct gator_textobj *)malloc(sizeof(struct gator_textobj)); if (text_data == (struct gator_textobj *)0) { - fprintf(stderr, "[%s:%s] Can't allocate %d bytes for text object private data region, errno is %d\n", mn, rn, sizeof(struct gator_textobj), errno); - return(errno); + fprintf(stderr, + "[%s:%s] Can't allocate %d bytes for text object private data region, errno is %d\n", + mn, rn, sizeof(struct gator_textobj), errno); + return (errno); } /* - * Create the text circular buffer for this new object. - */ + * Create the text circular buffer for this new object. + */ if (objects_debug) - fprintf(stderr, "[%s:%s] Creating circular buffer, %dx%d chars\n", mn, rn, text_params->maxEntries, text_params->maxCharsPerEntry); - newCB = gator_textcb_Create(text_params->maxEntries, - text_params->maxCharsPerEntry); - if (newCB == (struct gator_textcb_hdr *)0) { - fprintf(stderr, "[%s:%s] Can't create text object circular buffer\n", mn, rn); + fprintf(stderr, "[%s:%s] Creating circular buffer, %dx%d chars\n", mn, + rn, text_params->maxEntries, text_params->maxCharsPerEntry); + newCB = + gator_textcb_Create(text_params->maxEntries, + text_params->maxCharsPerEntry); + if (newCB == (struct gator_textcb_hdr *)0) { + fprintf(stderr, "[%s:%s] Can't create text object circular buffer\n", + mn, rn); free(text_data); - return(-1); - } + return (-1); + } /* - * Now that we have the private structures allocated, set them up. - */ - text_data->llrock = (int *)0; - text_data->numLines = text_onp->o_height; - text_data->cbHdr = newCB; - text_data->firstEntShown = 0; - text_data->lastEntShown = 0; + * Now that we have the private structures allocated, set them up. + */ + text_data->llrock = (int *)0; + text_data->numLines = text_onp->o_height; + text_data->cbHdr = newCB; + text_data->firstEntShown = 0; + text_data->lastEntShown = 0; if (objects_debug) - fprintf(stderr, "[%s:%s] Number of lines in window: %d: ", mn, rn, text_data->numLines); + fprintf(stderr, "[%s:%s] Number of lines in window: %d: ", mn, rn, + text_data->numLines); /* - * Attach the text-specific private - * data to the generic onode and return the happy news. - */ - text_onp->o_data = (int *)text_data; - return(0); + * Attach the text-specific private + * data to the generic onode and return the happy news. + */ + text_onp->o_data = (int *)text_data; + return (0); -} /*gator_text_create*/ +} /*gator_text_create */ /*------------------------------------------------------------------------ * gator_text_destroy @@ -144,17 +165,18 @@ int gator_text_create(text_onp, params) * As advertised. *------------------------------------------------------------------------*/ -int gator_text_destroy(onp) - struct onode *onp; +int +gator_text_destroy(onp) + struct onode *onp; -{ /*gator_text_destroy*/ +{ /*gator_text_destroy */ - /* - * For now, this is a no-op. - */ - return(0); + /* + * For now, this is a no-op. + */ + return (0); -} /*gator_text_destroy*/ +} /*gator_text_destroy */ /*------------------------------------------------------------------------ * gator_text_display @@ -176,97 +198,103 @@ int gator_text_destroy(onp) * As advertised. *------------------------------------------------------------------------*/ -int gator_text_display(onp) - struct onode *onp; +int +gator_text_display(onp) + struct onode *onp; -{ /*gator_text_display*/ +{ /*gator_text_display */ - static char rn[] = "gator_text_display"; /*Routine name*/ - struct gator_textobj *text_data; /*Ptr to text obj data*/ - struct gator_textcb_hdr *cbHdr; /*Ptr to CB header*/ - struct gwin_strparams strparams; /*String-drawing params*/ - int currLine; /*Current line being updated*/ - int currLinesUsed; /*Num screen lines used*/ - int currIdx; /*Current line index*/ - int currEnt; /*Current entry being drawn*/ - struct gator_textcb_entry *curr_ent; /*Ptr to current entry*/ + static char rn[] = "gator_text_display"; /*Routine name */ + struct gator_textobj *text_data; /*Ptr to text obj data */ + struct gator_textcb_hdr *cbHdr; /*Ptr to CB header */ + struct gwin_strparams strparams; /*String-drawing params */ + int currLine; /*Current line being updated */ + int currLinesUsed; /*Num screen lines used */ + int currIdx; /*Current line index */ + int currEnt; /*Current entry being drawn */ + struct gator_textcb_entry *curr_ent; /*Ptr to current entry */ if (objects_debug) - fprintf(stderr, "[%s:%s] Displaying text object at 0x%x\n", mn, rn, onp); + fprintf(stderr, "[%s:%s] Displaying text object at 0x%x\n", mn, rn, + onp); text_data = (struct gator_textobj *)(onp->o_data); cbHdr = text_data->cbHdr; if (objects_debug) - fprintf(stderr, "[%s:%s] Displaying text object at 0x%x, object-specific data at 0x%x\n", mn, rn, onp, text_data); + fprintf(stderr, + "[%s:%s] Displaying text object at 0x%x, object-specific data at 0x%x\n", + mn, rn, onp, text_data); /* - * Update each line in the screen buffer with its proper contents. - */ + * Update each line in the screen buffer with its proper contents. + */ currEnt = text_data->firstEntShown; currLinesUsed = text_data->lastEntShown - currEnt + 1; - currIdx = (cbHdr->oldestEntIdx + (currEnt - cbHdr->oldestEnt)) % cbHdr->maxEntriesStored; + currIdx = + (cbHdr->oldestEntIdx + + (currEnt - cbHdr->oldestEnt)) % cbHdr->maxEntriesStored; curr_ent = cbHdr->entry + currIdx; if (objects_debug) - fprintf(stderr, "[%s:%s] Drawing %d populated lines, starting with entry %d (index %d) at 0x%x\n", mn, rn, currLinesUsed, currEnt, currIdx, curr_ent); + fprintf(stderr, + "[%s:%s] Drawing %d populated lines, starting with entry %d (index %d) at 0x%x\n", + mn, rn, currLinesUsed, currEnt, currIdx, curr_ent); strparams.x = onp->o_x; strparams.y = onp->o_y; for (currLine = 0; currLine < text_data->numLines; currLine++) { - /* - * Draw the current entry. - */ - if (currLinesUsed > 0) { /* - * Drawing a populated line. We need to iterate if there are - * inversions (I don't feel like doing this now). - */ - strparams.s = curr_ent->textp; - strparams.highlight = curr_ent->highlight; - WOP_DRAWSTRING(onp->o_window, &strparams); - - currLinesUsed--; - currEnt++; - currIdx++; - if (currIdx >= cbHdr->maxEntriesStored) { - currIdx = 0; - curr_ent = cbHdr->entry; + * Draw the current entry. + */ + if (currLinesUsed > 0) { + /* + * Drawing a populated line. We need to iterate if there are + * inversions (I don't feel like doing this now). + */ + strparams.s = curr_ent->textp; + strparams.highlight = curr_ent->highlight; + WOP_DRAWSTRING(onp->o_window, &strparams); + + currLinesUsed--; + currEnt++; + currIdx++; + if (currIdx >= cbHdr->maxEntriesStored) { + currIdx = 0; + curr_ent = cbHdr->entry; + } else + curr_ent++; + } else { + /* + * Draw a blank line. + */ + strparams.s = cbHdr->blankLine; + strparams.highlight = 0; + WOP_DRAWSTRING(onp->o_window, &strparams); } - else - curr_ent++; - } - else { + /* - * Draw a blank line. - */ - strparams.s = cbHdr->blankLine; - strparams.highlight = 0; - WOP_DRAWSTRING(onp->o_window, &strparams); - } - - /* - * Adjust the X and Y locations. - */ - strparams.x = 0; - strparams.y++; - - } /*Update loop*/ + * Adjust the X and Y locations. + */ + strparams.x = 0; + strparams.y++; + + } /*Update loop */ /* - * Box the window before we leave. - */ + * Box the window before we leave. + */ #if GATOR_TEXTCB_DO_BOX if (objects_debug) - fprintf(stderr, "[%s:%s] Boxing window structure at 0x%x\n", - mn, rn, onp->o_window); + fprintf(stderr, "[%s:%s] Boxing window structure at 0x%x\n", mn, rn, + onp->o_window); WOP_BOX(onp->o_window); #endif /* GATOR_TEXTCB_DO_BOX */ /* * For now, this is all we do. */ - return(0); + return (0); -} /*gator_text_display*/ +} /*gator_text_display */ /*------------------------------------------------------------------------ * gator_text_release @@ -289,17 +317,18 @@ int gator_text_display(onp) * As advertised. *------------------------------------------------------------------------*/ -int gator_text_release(onp) - struct onode *onp; +int +gator_text_release(onp) + struct onode *onp; -{ /*gator_text_release*/ +{ /*gator_text_release */ - /* - * For now, this is a no-op. - */ - return(0); + /* + * For now, this is a no-op. + */ + return (0); -} /*gator_text_release*/ +} /*gator_text_release */ /*------------------------------------------------------------------------ * gator_text_Scroll @@ -324,15 +353,16 @@ int gator_text_release(onp) * As advertised. *------------------------------------------------------------------------*/ -int gator_text_Scroll(onp, nlines, direction) - struct onode *onp; - int nlines; - int direction; +int +gator_text_Scroll(onp, nlines, direction) + struct onode *onp; + int nlines; + int direction; -{ /*gator_text_Scroll*/ +{ /*gator_text_Scroll */ - static char rn[] = "gator_text_Scroll"; /*Routine name*/ - struct gator_textobj *text_data; /*Ptr to text obj data*/ + static char rn[] = "gator_text_Scroll"; /*Routine name */ + struct gator_textobj *text_data; /*Ptr to text obj data */ /* * We move the markers for first & last entries displayed, depending @@ -340,42 +370,44 @@ int gator_text_Scroll(onp, nlines, direction) * the window empty. */ if (objects_debug) - fprintf(stderr, "[%s:%s] Scrolling text object at 0x%x %d lines %s\n", mn, rn, nlines, (direction == GATOR_TEXT_SCROLL_UP) ? "UP" : "DOWN"); + fprintf(stderr, "[%s:%s] Scrolling text object at 0x%x %d lines %s\n", + mn, rn, nlines, + (direction == GATOR_TEXT_SCROLL_UP) ? "UP" : "DOWN"); text_data = (struct gator_textobj *)(onp->o_data); if (direction == GATOR_TEXT_SCROLL_DOWN) { - /* - * Move the object's text ``down'' by sliding the window up. - */ - text_data->firstEntShown -= nlines; - if (text_data->firstEntShown < text_data->cbHdr->oldestEnt) - text_data->firstEntShown = text_data->cbHdr->oldestEnt; - - text_data->lastEntShown -= nlines; - if (text_data->lastEntShown < text_data->cbHdr->oldestEnt) - text_data->lastEntShown = text_data->cbHdr->oldestEnt; - - } /*Moving down*/ + /* + * Move the object's text ``down'' by sliding the window up. + */ + text_data->firstEntShown -= nlines; + if (text_data->firstEntShown < text_data->cbHdr->oldestEnt) + text_data->firstEntShown = text_data->cbHdr->oldestEnt; + + text_data->lastEntShown -= nlines; + if (text_data->lastEntShown < text_data->cbHdr->oldestEnt) + text_data->lastEntShown = text_data->cbHdr->oldestEnt; + + } /*Moving down */ else { - /* - * Move the object's text ``up'' by sliding the window down. - */ - text_data->firstEntShown += nlines; - if (text_data->firstEntShown > text_data->cbHdr->currEnt) - text_data->firstEntShown = text_data->cbHdr->currEnt; - - text_data->lastEntShown += nlines; - if (text_data->lastEntShown > text_data->cbHdr->currEnt) - text_data->lastEntShown = text_data->cbHdr->currEnt; - - } /*Moving up*/ + /* + * Move the object's text ``up'' by sliding the window down. + */ + text_data->firstEntShown += nlines; + if (text_data->firstEntShown > text_data->cbHdr->currEnt) + text_data->firstEntShown = text_data->cbHdr->currEnt; + + text_data->lastEntShown += nlines; + if (text_data->lastEntShown > text_data->cbHdr->currEnt) + text_data->lastEntShown = text_data->cbHdr->currEnt; + + } /*Moving up */ /* * Return the happy news. */ - return(0); + return (0); -} /*gator_text_Scroll*/ +} /*gator_text_Scroll */ /*------------------------------------------------------------------------ * gator_text_Write @@ -402,113 +434,130 @@ int gator_text_Scroll(onp, nlines, direction) * As advertised. *------------------------------------------------------------------------*/ -int gator_text_Write(onp, strToWrite, numChars, highlight, skip) - struct onode *onp; - char *strToWrite; - int numChars; - int highlight; - int skip; - -{ /*gator_text_Write*/ - - static char rn[] = "gator_text_Write"; /*Routine name*/ - register int code; /*Return value on routines*/ - struct gator_textobj *text_data; /*Ptr to text obj data*/ - struct gator_textcb_hdr *cbHdr; /*Ptr to text CB header*/ - int i; /*Loop variable*/ - int oldCurrEnt; /*CB's old currEnt value*/ - int redisplay; /*Redisplay after write?*/ - int shownDiff; /*Diff between 1st & last lines*/ - int writeDiff; /*Num lines really written*/ - int bumpAmount; /*Amount to bump count*/ +int +gator_text_Write(onp, strToWrite, numChars, highlight, skip) + struct onode *onp; + char *strToWrite; + int numChars; + int highlight; + int skip; + +{ /*gator_text_Write */ + + static char rn[] = "gator_text_Write"; /*Routine name */ + register int code; /*Return value on routines */ + struct gator_textobj *text_data; /*Ptr to text obj data */ + struct gator_textcb_hdr *cbHdr; /*Ptr to text CB header */ + int i; /*Loop variable */ + int oldCurrEnt; /*CB's old currEnt value */ + int redisplay; /*Redisplay after write? */ + int shownDiff; /*Diff between 1st & last lines */ + int writeDiff; /*Num lines really written */ + int bumpAmount; /*Amount to bump count */ /* - * - */ + * + */ if (objects_debug) { - fprintf(stderr, "[%s:%s] Writing %d chars to text object at 0x%x (highlight=%d, skip=%d: '", rn, numChars, onp, highlight, skip); - for (i=0; i < numChars; i++) - fprintf(stderr, "%c", strToWrite+i); - fprintf(stderr, "\n"); + fprintf(stderr, + "[%s:%s] Writing %d chars to text object at 0x%x (highlight=%d, skip=%d: '", + rn, numChars, onp, highlight, skip); + for (i = 0; i < numChars; i++) + fprintf(stderr, "%c", strToWrite + i); + fprintf(stderr, "\n"); } - if (numChars == 0) numChars = strlen(strToWrite); /* simplify caller */ + if (numChars == 0) + numChars = strlen(strToWrite); /* simplify caller */ text_data = (struct gator_textobj *)(onp->o_data); cbHdr = text_data->cbHdr; if (cbHdr == (struct gator_textcb_hdr *)0) { - fprintf(stderr, "[%s:%s] Text object missing its circular buffer!\n", mn, rn); - return(-1); + fprintf(stderr, "[%s:%s] Text object missing its circular buffer!\n", + mn, rn); + return (-1); } /* - * If the current CB entry is being displayed, we track the write - * visually and redisplay. - */ - if ((cbHdr->currEnt <= text_data->lastEntShown) && - (cbHdr->currEnt >= text_data->firstEntShown)) { - if (objects_debug) - fprintf(stderr, "[%s:%s] Current entry is on screen. Tracking this write\n", mn, rn); - oldCurrEnt = cbHdr->currEnt; - redisplay = 1; - } - else { - if (objects_debug) - fprintf(stderr, "[%s:%s] Current entry NOT on screen, not tracking write\n", mn, rn); - redisplay = 0; + * If the current CB entry is being displayed, we track the write + * visually and redisplay. + */ + if ((cbHdr->currEnt <= text_data->lastEntShown) + && (cbHdr->currEnt >= text_data->firstEntShown)) { + if (objects_debug) + fprintf(stderr, + "[%s:%s] Current entry is on screen. Tracking this write\n", + mn, rn); + oldCurrEnt = cbHdr->currEnt; + redisplay = 1; + } else { + if (objects_debug) + fprintf(stderr, + "[%s:%s] Current entry NOT on screen, not tracking write\n", + mn, rn); + redisplay = 0; } if (redisplay) { - /* - * We're tracking the write. Compute the number of screen lines - * actually written and adjust our own numbers, then call the - * display function. - */ - shownDiff = text_data->lastEntShown - text_data->firstEntShown; - writeDiff = cbHdr->currEnt - oldCurrEnt; - if (objects_debug) - fprintf(stderr, "[%s:%s] Preparing to redisplay. Difference in shown lines=%d, difference in written lines=%d\n", mn, rn, shownDiff, writeDiff); - if (shownDiff < (text_data->numLines - 1)) { /* - * We weren't showing a full screen of stuff. Bump the last - * line shown by the minimum of the number of free lines still - * on the screen and the number of new lines actually written. - */ - bumpAmount = (text_data->numLines - 1) - shownDiff; - if (writeDiff < bumpAmount) - bumpAmount = writeDiff; - text_data->lastEntShown += bumpAmount; - writeDiff -= bumpAmount; - if (objects_debug) - fprintf(stderr, "[%s:%s] Empty lines appeared on screen, bumping bottom line shown by %d; new writeDiff is %d\n", mn, rn, bumpAmount, writeDiff); - } - - /* - * If we have any more lines that were written not taken care - * of by the above, we just bump the counters. - */ - if (writeDiff > 0) { + * We're tracking the write. Compute the number of screen lines + * actually written and adjust our own numbers, then call the + * display function. + */ + shownDiff = text_data->lastEntShown - text_data->firstEntShown; + writeDiff = cbHdr->currEnt - oldCurrEnt; if (objects_debug) - fprintf(stderr, "[%s:%s] Still more lines need to be tracked. Moving first & last shown down by %d\n", mn, rn, writeDiff); - text_data->firstEntShown += writeDiff; - text_data->lastEntShown += writeDiff; - } - } /*Redisplay needed*/ + fprintf(stderr, + "[%s:%s] Preparing to redisplay. Difference in shown lines=%d, difference in written lines=%d\n", + mn, rn, shownDiff, writeDiff); + if (shownDiff < (text_data->numLines - 1)) { + /* + * We weren't showing a full screen of stuff. Bump the last + * line shown by the minimum of the number of free lines still + * on the screen and the number of new lines actually written. + */ + bumpAmount = (text_data->numLines - 1) - shownDiff; + if (writeDiff < bumpAmount) + bumpAmount = writeDiff; + text_data->lastEntShown += bumpAmount; + writeDiff -= bumpAmount; + if (objects_debug) + fprintf(stderr, + "[%s:%s] Empty lines appeared on screen, bumping bottom line shown by %d; new writeDiff is %d\n", + mn, rn, bumpAmount, writeDiff); + } + + /* + * If we have any more lines that were written not taken care + * of by the above, we just bump the counters. + */ + if (writeDiff > 0) { + if (objects_debug) + fprintf(stderr, + "[%s:%s] Still more lines need to be tracked. Moving first & last shown down by %d\n", + mn, rn, writeDiff); + text_data->firstEntShown += writeDiff; + text_data->lastEntShown += writeDiff; + } + } + /*Redisplay needed */ /* * Simply call the circular buffer write op. */ code = gator_textcb_Write(cbHdr, strToWrite, numChars, highlight, skip); if (code) { - fprintf(stderr, "[%s:%s] Can't write to text object's circular buffer, errror code is %d\n", mn, rn, code); - return(code); + fprintf(stderr, + "[%s:%s] Can't write to text object's circular buffer, errror code is %d\n", + mn, rn, code); + return (code); } /* * Everything went well. Return the happy news. */ - return(0); + return (0); -} /*gator_text_Write*/ +} /*gator_text_Write */ /*------------------------------------------------------------------------ * gator_text_BlankLine @@ -531,42 +580,47 @@ int gator_text_Write(onp, strToWrite, numChars, highlight, skip) * As advertised. *------------------------------------------------------------------------*/ -int gator_text_BlankLine(onp, numBlanks) - struct onode *onp; - int numBlanks; +int +gator_text_BlankLine(onp, numBlanks) + struct onode *onp; + int numBlanks; -{ /*gator_text_BlankLine*/ +{ /*gator_text_BlankLine */ - static char rn[] = "gator_text_BlankLine"; /*Routine name*/ - register int code; /*Return value on routines*/ - struct gator_textobj *text_data; /*Ptr to text obj data*/ + static char rn[] = "gator_text_BlankLine"; /*Routine name */ + register int code; /*Return value on routines */ + struct gator_textobj *text_data; /*Ptr to text obj data */ /* * We just call the circular buffer routine directly. */ if (objects_debug) - fprintf(stderr, "[%s:%s] Writing %d blank lines to text object at 0x%x\n", mn, rn, numBlanks, onp); + fprintf(stderr, + "[%s:%s] Writing %d blank lines to text object at 0x%x\n", mn, + rn, numBlanks, onp); text_data = (struct gator_textobj *)(onp->o_data); code = gator_textcb_BlankLine(text_data->cbHdr, numBlanks); if (code) { - fprintf(stderr, "[%s:%s] Can't write %d blank lines to text object at 0x%x\n", mn, rn, numBlanks, onp); - return(code); + fprintf(stderr, + "[%s:%s] Can't write %d blank lines to text object at 0x%x\n", + mn, rn, numBlanks, onp); + return (code); } /* - * Blank lines written successfully. Adjust what lines are currently - * shown. Iff we were tracking the end of the buffer, we have to - * follow the blank lines. - */ + * Blank lines written successfully. Adjust what lines are currently + * shown. Iff we were tracking the end of the buffer, we have to + * follow the blank lines. + */ if (text_data->lastEntShown == text_data->cbHdr->currEnt - numBlanks) { - text_data->firstEntShown += numBlanks; - text_data->lastEntShown += numBlanks; + text_data->firstEntShown += numBlanks; + text_data->lastEntShown += numBlanks; } /* - * Return the happy news. - */ - return(0); + * Return the happy news. + */ + return (0); -} /*gator_text_BlankLine*/ +} /*gator_text_BlankLine */ diff --git a/src/gtx/windows.c b/src/gtx/windows.c index bc3b5829e..4455dd933 100644 --- a/src/gtx/windows.c +++ b/src/gtx/windows.c @@ -18,21 +18,22 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/gtx/windows.c,v 1.1.1.4 2001/07/14 22:22:05 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/gtx/windows.c,v 1.6 2003/07/15 23:15:13 shadow Exp $"); /* On DUX "IN" is a variable in curses.h, so this can be a bit of a problem */ #ifdef IN #undef IN #endif -#include "gtxwindows.h" /*Interface for this module*/ -#include "gtxcurseswin.h" /*Interface for the curses module*/ -#include "gtxdumbwin.h" /*Interface for the dumb terminal module*/ -#include "gtxX11win.h" /*Interface for the X11 module*/ +#include "gtxwindows.h" /*Interface for this module */ +#include "gtxcurseswin.h" /*Interface for the curses module */ +#include "gtxdumbwin.h" /*Interface for the dumb terminal module */ +#include "gtxX11win.h" /*Interface for the X11 module */ -static char mn[] = "gator_windows"; /*Module name*/ -struct gwinbaseops gwinbops; /*Base window operation fn array*/ -struct gwin gator_basegwin; /*Base gator window*/ +static char mn[] = "gator_windows"; /*Module name */ +struct gwinbaseops gwinbops; /*Base window operation fn array */ +struct gwin gator_basegwin; /*Base gator window */ /*-------------------------------------------------------------------------------- * gw_init @@ -57,73 +58,84 @@ struct gwin gator_basegwin; /*Base gator window*/ * base window. *--------------------------------------------------------------------------------*/ -int gw_init(params) - struct gwin_initparams *params; +int +gw_init(params) + struct gwin_initparams *params; -{ /*gw_init*/ +{ /*gw_init */ - static char rn[] = "gw_init"; /*Routine name*/ - register int code; /*Return code*/ - int gwin_debug; /*Is debugging turned on?*/ + static char rn[] = "gw_init"; /*Routine name */ + register int code; /*Return code */ + int gwin_debug; /*Is debugging turned on? */ /* * Remember our debugging level. */ gwin_debug = params->i_debug; if (gwin_debug) - fprintf(stderr, "[%s:%s] Window debugging turned on\n", mn, rn); + fprintf(stderr, "[%s:%s] Window debugging turned on\n", mn, rn); /* * What we do/call depends on the type of lower-level graphics * package we'll be using. */ switch (params->i_type) { - case GATOR_WIN_DUMB: /*Dumb terminal*/ - if (gwin_debug) - fprintf(stderr, "[%s:%s] Initializing for the dumb terminal package\n", mn, rn); - gwinbops = gator_dumb_gwinbops; - code = gator_dumbgwin_init(gwin_debug); - if (code) { - fprintf(stderr, "[%s:%s] Error in dumb terminal initialization routine, gator_dumbgwin_init(): %d\n", mn, rn, code); - return(code); - } - break; - - case GATOR_WIN_CURSES: /*Curses*/ - if (gwin_debug) - fprintf(stderr, "[%s:%s] Initializing for the curses package\n", mn, rn); - gwinbops = gator_curses_gwinbops; - code = gator_cursesgwin_init(gwin_debug); - if (code) { - fprintf(stderr, "[%s:%s] Error in curses initialization routine, gator_cursesgwin_init(): %d\n", mn, rn, code); - return(code); - } - break; - - case GATOR_WIN_X11: /*X11*/ - if (gwin_debug) - fprintf(stderr, "[%s:%s] Initializing for the X11 package\n", mn, rn); - gwinbops = gator_X11_gwinbops; - code = gator_X11gwin_init(params); - if (code) { - fprintf(stderr, "[%s:%s] Error in X11 initialization routine, gator_X11gwin_init(): %d\n", mn, rn, code); - return(code); - } - break; - - default: - fprintf(stderr, "[%s:%s] Illegal choice of graphics system: %d\n", - mn, rn, params->i_type); - fprintf(stderr, "\tLegal choices are:\n"); - fprintf(stderr, "\t\t%d: Dumb terminal\n", GATOR_WIN_DUMB); - fprintf(stderr, "\t\t%d: Curses\n", GATOR_WIN_CURSES); - fprintf(stderr, "\t\t%d: X11\n", GATOR_WIN_X11); - return(-1); - } /*end switch (params->i_type)*/ + case GATOR_WIN_DUMB: /*Dumb terminal */ + if (gwin_debug) + fprintf(stderr, + "[%s:%s] Initializing for the dumb terminal package\n", + mn, rn); + gwinbops = gator_dumb_gwinbops; + code = gator_dumbgwin_init(gwin_debug); + if (code) { + fprintf(stderr, + "[%s:%s] Error in dumb terminal initialization routine, gator_dumbgwin_init(): %d\n", + mn, rn, code); + return (code); + } + break; + + case GATOR_WIN_CURSES: /*Curses */ + if (gwin_debug) + fprintf(stderr, "[%s:%s] Initializing for the curses package\n", + mn, rn); + gwinbops = gator_curses_gwinbops; + code = gator_cursesgwin_init(gwin_debug); + if (code) { + fprintf(stderr, + "[%s:%s] Error in curses initialization routine, gator_cursesgwin_init(): %d\n", + mn, rn, code); + return (code); + } + break; + + case GATOR_WIN_X11: /*X11 */ + if (gwin_debug) + fprintf(stderr, "[%s:%s] Initializing for the X11 package\n", mn, + rn); + gwinbops = gator_X11_gwinbops; + code = gator_X11gwin_init(params); + if (code) { + fprintf(stderr, + "[%s:%s] Error in X11 initialization routine, gator_X11gwin_init(): %d\n", + mn, rn, code); + return (code); + } + break; + + default: + fprintf(stderr, "[%s:%s] Illegal choice of graphics system: %d\n", mn, + rn, params->i_type); + fprintf(stderr, "\tLegal choices are:\n"); + fprintf(stderr, "\t\t%d: Dumb terminal\n", GATOR_WIN_DUMB); + fprintf(stderr, "\t\t%d: Curses\n", GATOR_WIN_CURSES); + fprintf(stderr, "\t\t%d: X11\n", GATOR_WIN_X11); + return (-1); + } /*end switch (params->i_type) */ /* * Finally, return the good news. */ - return(0); + return (0); -} /*gw_init*/ +} /*gw_init */ diff --git a/src/uss/Makefile.in b/src/uss/Makefile.in index 2924b0a15..ad48e0895 100644 --- a/src/uss/Makefile.in +++ b/src/uss/Makefile.in @@ -5,34 +5,14 @@ # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html -# uss Makefile - -DEST=@DEST@ -TOP_INCDIR=@TOP_INCDIR@ -TOP_LIBDIR=@TOP_LIBDIR@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ -libexecdir=@libexecdir@ -libdir=@libdir@ -includedir=@includedir@ -mandir=@mandir@ -afssrvbindir=@afssrvbindir@ -afssrvsbindir=@afssrvsbindir@ -afssrvlibexecdir=@afssrvlibexecdir@ -COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et -RXGEN=${TOP_SRCDIR}/rxgen/rxgen -TOP_SRCDIR=@TOP_SRCDIR@ -SYS_NAME=@AFS_SYSNAME@ - -SHELL=/bin/sh - -include ../config/Makefile.${SYS_NAME} +srcdir=@srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config + + all: uss -CFLAGS=${DBUG} -I${TOP_SRCDIR}/config \ +CFLAGS=-I. -I${srcdir} ${DBUG} -I${TOP_OBJDIR}/src/config \ -I${TOP_INCDIR} -I. ${XCFLAGS} # @@ -69,34 +49,34 @@ uss: uss.o ${OBJS} ${CC} ${CFLAGS} -o uss uss.o ${OBJS} ${LIBS} uss.o: uss.c AFS_component_version_number.c - ${CC} -c ${CFLAGS} uss.c + ${CC} -c ${CFLAGS} ${srcdir}/uss.c uss_procs.o : uss_procs.c - ${CC} -c ${CFLAGS} uss_procs.c + ${CC} -c ${CFLAGS} ${srcdir}/uss_procs.c uss_common.o : uss_common.c - ${CC} -c ${CFLAGS} uss_common.c + ${CC} -c ${CFLAGS} ${srcdir}/uss_common.c uss_vol.o : uss_vol.c - ${CC} -c ${CFLAGS} uss_vol.c + ${CC} -c ${CFLAGS} ${srcdir}/uss_vol.c uss_acl.o : uss_acl.c - ${CC} -c ${CFLAGS} uss_acl.c + ${CC} -c ${CFLAGS} ${srcdir}/uss_acl.c uss_ptserver.o : uss_ptserver.c - ${CC} -c ${CFLAGS} uss_ptserver.c + ${CC} -c ${CFLAGS} ${srcdir}/uss_ptserver.c uss_kauth.o : uss_kauth.c - ${CC} -c ${CFLAGS} uss_kauth.c + ${CC} -c ${CFLAGS} ${srcdir}/uss_kauth.c uss_fs.o : uss_fs.c - ${CC} -c ${CFLAGS} uss_fs.c + ${CC} -c ${CFLAGS} ${srcdir}/uss_fs.c lex.yy.o : lex.yy.c y.tab.c ${CC} -c ${CFLAGS} lex.yy.c -lex.yy.c : lex.c - ${LEX} lex.c +lex.yy.c : lex.l + ${LEX} ${srcdir}/lex.l y.tab.o : y.tab.c ${CC} -c ${CFLAGS} y.tab.c @@ -118,7 +98,7 @@ uss_kauth.c: uss_kauth.h uss_common.h uss_fs.c: uss_fs.h y.tab.c : grammar.y - ${YACC} -d grammar.y + ${YACC} -d ${srcdir}/grammar.y # # Installation targets diff --git a/src/uss/grammar.y b/src/uss/grammar.y index 01d804d00..697a14d5f 100644 --- a/src/uss/grammar.y +++ b/src/uss/grammar.y @@ -8,7 +8,18 @@ * directory or online at http://www.openafs.org/dl/license10.html */ +#include +#include #include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + extern int line; extern int uss_perr; %} diff --git a/src/uss/sample.template b/src/uss/sample.template index 05be914a8..1ad8c6d81 100644 --- a/src/uss/sample.template +++ b/src/uss/sample.template @@ -8,10 +8,6 @@ # Sample template for use with the uss, the AFS user account facility. # # -# Transarc Corporation -# (C) Copyright 1990 Transarc Corporation -# All rights reserved -# # By convention: # $USER = User's login name # $UID = User's uid diff --git a/src/uss/uss.c b/src/uss/uss.c index b31c6e977..a1a0f821f 100644 --- a/src/uss/uss.c +++ b/src/uss/uss.c @@ -18,18 +18,28 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss.c,v 1.1.1.6 2001/10/14 18:06:53 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/uss/uss.c,v 1.8 2004/03/15 18:51:03 shadow Exp $"); #ifdef AFS_AIX32_ENV #include #endif -#include "uss_common.h" /*Common uss definitions, globals*/ -#include "uss_procs.h" /*Main uss operations*/ -#include "uss_kauth.h" /*AuthServer routines*/ -#include "uss_fs.h" /*CacheManager ops*/ -#include /*Command line parsing*/ -#include /*Cell config defs*/ -#include /*MAXKTCREALMLEN & MAXKTCNAMELEN*/ + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + +#include "uss_common.h" /*Common uss definitions, globals */ +#include "uss_procs.h" /*Main uss operations */ +#include "uss_kauth.h" /*AuthServer routines */ +#include "uss_fs.h" /*CacheManager ops */ +#include /*Command line parsing */ +#include /*Cell config defs */ +#include /*MAXKTCREALMLEN & MAXKTCNAMELEN */ #include /* @@ -43,8 +53,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss.c,v 1.1.1.6 2001/10/14 18:06:53 /* * ---------------------- Exported variables ---------------------- */ -char *uss_fs_InBuff = (char *)0; /*Cache Manager input buff*/ -char *uss_fs_OutBuff = (char *)0; /*Cache Manager output buff*/ +char *uss_fs_InBuff = NULL; /*Cache Manager input buff */ +char *uss_fs_OutBuff = NULL; /*Cache Manager output buff */ /* * Set up convenient tags for the command line parameter indicies. @@ -55,10 +65,10 @@ char *uss_fs_OutBuff = (char *)0; /*Cache Manager output buff*/ #define AUP_REALNAME 1 #define AUP_PASSWD 2 #define AUP_PWEXPIRES 3 -#define AUP_SERVER 4 /* was 3 */ -#define AUP_PART 5 /* was 4 */ -#define AUP_MNTPT 6 /* was 5 */ -#define AUP_UID 7 /* was 6 */ +#define AUP_SERVER 4 /* was 3 */ +#define AUP_PART 5 /* was 4 */ +#define AUP_MNTPT 6 /* was 5 */ +#define AUP_UID 7 /* was 6 */ /*Bulk*/ #define ABULK_FILE 0 @@ -77,26 +87,25 @@ extern int uss_perr; #define PVP_VOLFILE 1 /*Common ones*/ -#define AUSS_TEMPLATE 10 /* was 7 */ -#define AUSS_VERBOSE 11 /* was 8 */ -#define AUSS_VAR 12 /* was 9 */ -#define AUSS_CELL 13 /* was 10 */ -#define AUSS_ADMIN 14 /* was 11 */ -#define AUSS_DRYRUN 15 /* was 12 */ -#define AUSS_SKIPAUTH 16 /* was 13 */ -#define AUSS_OVERWRITE 17 /* was 14 */ -#define AUSS_PWEXPIRES 18 /* was 15 */ -#define AUSS_PIPE 19 /* was 16 */ +#define AUSS_TEMPLATE 10 /* was 7 */ +#define AUSS_VERBOSE 11 /* was 8 */ +#define AUSS_VAR 12 /* was 9 */ +#define AUSS_CELL 13 /* was 10 */ +#define AUSS_ADMIN 14 /* was 11 */ +#define AUSS_DRYRUN 15 /* was 12 */ +#define AUSS_SKIPAUTH 16 /* was 13 */ +#define AUSS_OVERWRITE 17 /* was 14 */ +#define AUSS_PWEXPIRES 18 /* was 15 */ +#define AUSS_PIPE 19 /* was 16 */ #undef USS_DB -static char Template[300]= - "uss.template"; /*Default name*/ +static char Template[300] = "uss.template"; /*Default name */ -extern FILE *yyin, *yyout; /*YACC input & output files*/ +extern FILE *yyin, *yyout; /*YACC input & output files */ extern int doUnlog; int uss_BulkExpires = 0; -int local_Cell=1; +int local_Cell = 1; static int DoAdd(); @@ -120,12 +129,13 @@ static int DoAdd(); * As advertised. *------------------------------------------------------------------------*/ -static afs_int32 GetCommon(a_as) - register struct cmd_syndesc *a_as; +static afs_int32 +GetCommon(a_as) + register struct cmd_syndesc *a_as; -{ /*GetCommon*/ +{ /*GetCommon */ - int code; /*Result of ka_LocalCell*/ + int code; /*Result of ka_LocalCell */ if (strcmp(a_as->name, "help") == 0) return; @@ -133,28 +143,26 @@ static afs_int32 GetCommon(a_as) strcpy(Template, a_as->parms[AUSS_TEMPLATE].items->data); if (a_as->parms[AUSS_VERBOSE].items) uss_verbose = 1; - else + else uss_verbose = 0; code = ka_CellConfig(AFSDIR_CLIENT_ETC_DIRPATH); if (code) fprintf(stderr, "%s: ** Call to ka_CellConfig() failed (code=%d)\n", uss_whoami, code); - + if (a_as->parms[AUSS_CELL].items) { char local_cell[MAXKTCREALMLEN]; - if (ka_ExpandCell(a_as->parms[AUSS_CELL].items->data, - uss_Cell, - 0/*local*/)) { - fprintf(stderr, - "%s: ** Unknown or ambiguous cell name: %s\n", + if (ka_ExpandCell + (a_as->parms[AUSS_CELL].items->data, uss_Cell, 0 /*local */ )) { + fprintf(stderr, "%s: ** Unknown or ambiguous cell name: %s\n", uss_whoami, a_as->parms[AUSS_CELL].items->data); exit(-1); } /* * Get the local cell name */ - if (ka_ExpandCell((char*)0, local_cell, 0/*local*/)) { + if (ka_ExpandCell((char *)0, local_cell, 0 /*local */ )) { fprintf(stderr, "Can't get local cellname\n"); exit(-1); } @@ -164,23 +172,21 @@ static afs_int32 GetCommon(a_as) */ local_Cell = 0; } - } - else { + } else { /* * Get the local cell name */ - if (ka_ExpandCell((char*)0, uss_Cell, 0/*local*/)) { + if (ka_ExpandCell((char *)0, uss_Cell, 0 /*local */ )) { fprintf(stderr, "Can't get local cellname\n"); exit(-1); } if (uss_verbose) - fprintf(stderr, "No cell specified; assuming '%s'.\n", - uss_Cell); + fprintf(stderr, "No cell specified; assuming '%s'.\n", uss_Cell); } - return(0); + return (0); -} /*GetCommon*/ +} /*GetCommon */ /*----------------------------------------------------------------------- @@ -209,24 +215,22 @@ static afs_int32 GetCommon(a_as) * As advertised. *------------------------------------------------------------------------*/ -static int SaveRestoreInfo() +static int +SaveRestoreInfo() +{ /*SaveRestoreInfo */ -{ /*SaveRestoreInfo*/ - - static char rn[] = - "uss:SaveRestoreInfo"; /*Routine name*/ - register afs_int32 code; /*Return code*/ - afs_int32 deletedUid; /*Uid to be nuked*/ + static char rn[] = "uss:SaveRestoreInfo"; /*Routine name */ + register afs_int32 code; /*Return code */ + afs_int32 deletedUid; /*Uid to be nuked */ /* * Translate the user name to the user ID. */ code = uss_ptserver_XlateUser(uss_User, &deletedUid); if (code) - return(code); + return (code); #ifdef USS_DB - printf("%s: User '%s' translated to uid %d\n", - rn, uss_User, deletedUid); + printf("%s: User '%s' translated to uid %d\n", rn, uss_User, deletedUid); #endif /* USS_DB */ sprintf(uss_Uid, "%d", deletedUid); @@ -237,14 +241,14 @@ static int SaveRestoreInfo() */ code = uss_vol_GetVolInfoFromMountPoint(uss_MountPoint); if (code) - return(code); + return (code); /* * Report back that we did fine. */ - return(0); + return (0); -} /*SaveRestoreInfo*/ +} /*SaveRestoreInfo */ /*----------------------------------------------------------------------- @@ -269,18 +273,18 @@ static int SaveRestoreInfo() * As advertised. *------------------------------------------------------------------------*/ -static int DoDelete() - -{ /*DoDelete*/ +static int +DoDelete() +{ /*DoDelete */ - int code; /*Return code*/ + int code; /*Return code */ /* * Make sure the user name is a lega one. */ code = uss_kauth_CheckUserName(); if (code) - return(code); + return (code); /* * Store all the info about the account before actually doing @@ -288,23 +292,24 @@ static int DoDelete() */ code = SaveRestoreInfo(); if (code) - return(code); + return (code); if ((uss_VolumeID != 0) && (uss_MountPoint[0] != '\0')) { /* * Unmount the user's volume from the file system. */ - if (uss_verbose) { - fprintf(stderr, "Unmounting volume '%s' (ID %u) mounted at '%s'\n", - uss_Volume, uss_VolumeID, uss_MountPoint); + if (uss_verbose) { + fprintf(stderr, + "Unmounting volume '%s' (ID %u) mounted at '%s'\n", + uss_Volume, uss_VolumeID, uss_MountPoint); } code = uss_fs_RmMountPoint(uss_MountPoint); if (code) { if (uss_verbose) - fprintf(stderr, "%s: Can't remove mountpoint '%s'\n", - uss_whoami, uss_MountPoint); - return(code); /* Must return - we may have incorrect volume */ + fprintf(stderr, "%s: Can't remove mountpoint '%s'\n", + uss_whoami, uss_MountPoint); + return (code); /* Must return - we may have incorrect volume */ } } @@ -313,44 +318,39 @@ static int DoDelete() * then do so. */ if (!uss_SaveVolume && (uss_VolumeID != 0)) { - if (uss_verbose) { - fprintf(stderr, "Deleting volume '%s' (ID %u)\n", - uss_Volume, uss_VolumeID); + if (uss_verbose) { + fprintf(stderr, "Deleting volume '%s' (ID %u)\n", uss_Volume, + uss_VolumeID); } - code = uss_vol_DeleteVol(uss_Volume, - uss_VolumeID, - uss_Server, - uss_ServerID, - uss_Partition, - uss_PartitionID); + code = + uss_vol_DeleteVol(uss_Volume, uss_VolumeID, uss_Server, + uss_ServerID, uss_Partition, uss_PartitionID); if (code) { if (uss_verbose) - fprintf(stderr, "%s: Can't delete volume '%s' (ID %u)\n", + fprintf(stderr, "%s: Can't delete volume '%s' (ID %u)\n", uss_whoami, uss_Volume, uss_VolumeID); - return(code); + return (code); } - } - else - if (uss_verbose && (uss_MountPoint[0] != '\0')) - printf("%s: Warning: Not attempting to delete volume at '%s'\n", - uss_whoami, uss_MountPoint); + } else if (uss_verbose && (uss_MountPoint[0] != '\0')) + printf("%s: Warning: Not attempting to delete volume at '%s'\n", + uss_whoami, uss_MountPoint); /* * Get rid of the user's authentication entry. */ code = uss_kauth_DelUser(uss_User); if (code) - return(code); + return (code); /* * Finally, remove the user's AFS ID from the Protection DB and * return that result. */ code = uss_ptserver_DelUser(uss_User); - return(code); - -} /*DoDelete*/ + return (code); + +} /*DoDelete */ /*----------------------------------------------------------------------- @@ -375,11 +375,12 @@ static int DoDelete() * As advertised. *------------------------------------------------------------------------*/ -static int DelUser(a_as, a_rock) +static int +DelUser(a_as, a_rock) struct cmd_syndesc *a_as; char *a_rock; -{ /*DelUser*/ +{ /*DelUser */ int code; @@ -388,13 +389,13 @@ static int DelUser(a_as, a_rock) * global field settings. */ uss_common_Reset(); - + /* * Pull out the fields as passed in by the caller on the command * line. */ strcpy(uss_User, a_as->parms[DUP_USER].items->data); - if (a_as->parms[DUP_MNTPT].items) + if (a_as->parms[DUP_MNTPT].items) strcpy(uss_MountPoint, a_as->parms[DUP_MNTPT].items->data); #if USS_FUTURE_FEATURES #if USS_DONT_HIDE_SOME_FEATURES @@ -407,11 +408,9 @@ static int DelUser(a_as, a_rock) uss_SaveVolume = 1; */ - if (a_as->parms[2].items) - { - uss_SaveVolume = 1; - } - + if (a_as->parms[2].items) { + uss_SaveVolume = 1; + } #if USS_FUTURE_FEATURES #if USS_DONT_HIDE_SOME_FEATURES if (a_as->parms[DUP_PWDPATH].items) @@ -428,28 +427,27 @@ static int DelUser(a_as, a_rock) if (a_as->parms[AUSS_ADMIN].items) { strcpy(uss_Administrator, a_as->parms[AUSS_ADMIN].items->data); /* fprintf(stderr, "debugging: uss_Administrator set to '%s'\n", - uss_Administrator);*/ - } - else { - /* fprintf(stderr, "debugging: No administrator value given\n");*/ + * uss_Administrator); */ + } else { + /* fprintf(stderr, "debugging: No administrator value given\n"); */ uss_Administrator[0] = '\0'; } - + /* * Initialize uss_AccountCreator(). */ code = uss_kauth_InitAccountCreator(); if (code) - return(code); + return (code); /* * Now that the command line arguments are parsed and properly stored, * go for it! */ - return(DoDelete()); + return (DoDelete()); -} /*DelUser*/ +} /*DelUser */ /*----------------------------------------------------------------------- @@ -474,16 +472,17 @@ static int DelUser(a_as, a_rock) * As advertised. *------------------------------------------------------------------------*/ -static int PurgeVolumes(a_as, a_rock) +static int +PurgeVolumes(a_as, a_rock) struct cmd_syndesc *a_as; char *a_rock; -{ /*PurgeVolumes*/ +{ /*PurgeVolumes */ fprintf(stderr, "Sorry, purgevolumes has not yet been implemented.\n"); - return(0); + return (0); -} /*PurgeVolumes*/ +} /*PurgeVolumes */ /*----------------------------------------------------------------------- @@ -508,16 +507,17 @@ static int PurgeVolumes(a_as, a_rock) * As advertised. *------------------------------------------------------------------------*/ -static int RestoreUser(a_as, a_rock) +static int +RestoreUser(a_as, a_rock) struct cmd_syndesc *a_as; char *a_rock; -{ /*RestoreUser*/ +{ /*RestoreUser */ fprintf(stderr, "Sorry, restoreuser has not yet been implemented.\n"); - return(0); + return (0); -} /*RestoreUser*/ +} /*RestoreUser */ /*----------------------------------------------------------------------- @@ -543,19 +543,19 @@ static int RestoreUser(a_as, a_rock) * As advertised. *------------------------------------------------------------------------*/ -static int DoBulkAddLine(a_buf, a_tp) - char *a_buf; - char *a_tp; +static int +DoBulkAddLine(a_buf, a_tp) + char *a_buf; + char *a_tp; -{ /*DoBulkAddLine*/ +{ /*DoBulkAddLine */ - register int i; /*Loop variable*/ - static char rn[] = "DoBulkAddLine"; /*Routine name*/ - int overflow; /*Overflow in field copy?*/ + register int i; /*Loop variable */ + static char rn[] = "DoBulkAddLine"; /*Routine name */ + int overflow; /*Overflow in field copy? */ #ifdef USS_DB - printf("%s: Command buffer left to parse: '%s'\n", - rn, a_tp); + printf("%s: Command buffer left to parse: '%s'\n", rn, a_tp); #endif /* USS_DB */ uss_Expires = uss_BulkExpires; @@ -567,21 +567,23 @@ static int DoBulkAddLine(a_buf, a_tp) fprintf(stderr, "%s: * User field in add cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_UserLen, uss_User); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) { fprintf(stderr, "%s: * The user field must appear in a bulk add command.\n", uss_whoami); - return(-1); + return (-1); } - a_tp = uss_common_FieldCp(uss_RealName, a_tp, ':', uss_RealNameLen, &overflow); + a_tp = + uss_common_FieldCp(uss_RealName, a_tp, ':', uss_RealNameLen, + &overflow); if (overflow) { fprintf(stderr, "%s: * Real name field in add cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_RealNameLen, uss_RealName); - return(-1); + return (-1); } if (uss_RealName[0] == '\0') { /* @@ -590,17 +592,16 @@ static int DoBulkAddLine(a_buf, a_tp) */ sprintf(uss_RealName, "%s", uss_User); if (uss_verbose) - fprintf(stderr, - "%s: Using default real name, '%s'\n", - uss_whoami, uss_User); - } /*Use default full name*/ - + fprintf(stderr, "%s: Using default real name, '%s'\n", uss_whoami, + uss_User); + } + /*Use default full name */ a_tp = uss_common_FieldCp(uss_Pwd, a_tp, ':', uss_PwdLen, &overflow); if (overflow) { fprintf(stderr, "%s: * Password field in add cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_PwdLen, uss_Pwd); - return(-1); + return (-1); } if (uss_Pwd[0] == '\0') { /* @@ -609,71 +610,73 @@ static int DoBulkAddLine(a_buf, a_tp) */ sprintf(uss_Pwd, "%s", uss_DEFAULT_PASSWORD); if (uss_verbose) - fprintf(stderr, - "%s: Using default password, '%s'\n", - uss_whoami, uss_Pwd); - } /*Use default password*/ + fprintf(stderr, "%s: Using default password, '%s'\n", uss_whoami, + uss_Pwd); + } /*Use default password */ if ((*a_tp == '\0') || (*a_tp == '\n')) goto DoBulkAddLine_ParsingDone; - + { - char temp[10]; - a_tp = uss_common_FieldCp(temp, a_tp, ':', 9, &overflow); - if (overflow) { - fprintf(stderr, - "%s: * Password expiration time is longer than %d characters, ignoring...\n", - uss_whoami, 9); - } - if (temp[0] == '\0') { - /* Expiration time not specified. Use default */ - if (uss_verbose) - fprintf(stderr, "%s: Using default expiration time, '%d'\n", - uss_whoami, uss_Expires); - } - else { - int te; - te = atoi(temp); - if (te < 0 || te > 254) { - fprintf(stderr, - "%s: * Password Expiration must be in [0..254] days, using default %d\n", - uss_whoami, uss_Expires); + char temp[10]; + a_tp = uss_common_FieldCp(temp, a_tp, ':', 9, &overflow); + if (overflow) { + fprintf(stderr, + "%s: * Password expiration time is longer than %d characters, ignoring...\n", + uss_whoami, 9); + } + if (temp[0] == '\0') { + /* Expiration time not specified. Use default */ + if (uss_verbose) + fprintf(stderr, "%s: Using default expiration time, '%d'\n", + uss_whoami, uss_Expires); + } else { + int te; + te = atoi(temp); + if (te < 0 || te > 254) { + fprintf(stderr, + "%s: * Password Expiration must be in [0..254] days, using default %d\n", + uss_whoami, uss_Expires); + } else + uss_Expires = te; } - else uss_Expires = te; - } - if ((*a_tp == '\0') || (*a_tp == '\n')) - goto DoBulkAddLine_ParsingDone; + if ((*a_tp == '\0') || (*a_tp == '\n')) + goto DoBulkAddLine_ParsingDone; } - a_tp = uss_common_FieldCp(uss_Server, a_tp, ':', uss_ServerLen, &overflow); + a_tp = + uss_common_FieldCp(uss_Server, a_tp, ':', uss_ServerLen, &overflow); if (overflow) { fprintf(stderr, "%s: * Server field in add cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_ServerLen, uss_Server); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) goto DoBulkAddLine_ParsingDone; - a_tp = uss_common_FieldCp(uss_Partition, a_tp, ':', uss_PartitionLen, &overflow); + a_tp = + uss_common_FieldCp(uss_Partition, a_tp, ':', uss_PartitionLen, + &overflow); if (overflow) { fprintf(stderr, "%s: * Partition field in add cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_PartitionLen, uss_Partition); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) goto DoBulkAddLine_ParsingDone; - a_tp = uss_common_FieldCp(uss_MountPoint, a_tp, ':', uss_MountPointLen, - &overflow); + a_tp = + uss_common_FieldCp(uss_MountPoint, a_tp, ':', uss_MountPointLen, + &overflow); if (overflow) { fprintf(stderr, "%s: * Mountpoint field in add cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_MountPointLen, uss_MountPoint); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) goto DoBulkAddLine_ParsingDone; @@ -683,36 +686,36 @@ static int DoBulkAddLine(a_buf, a_tp) fprintf(stderr, "%s: * UID field in add cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_UidLen, uss_Uid); - return(-1); + return (-1); } uss_DesiredUID = atoi(uss_Uid); if ((*a_tp == '\0') || (*a_tp == '\n')) goto DoBulkAddLine_ParsingDone; for (uss_VarMax = 1; uss_VarMax < 10; uss_VarMax++) { - a_tp = uss_common_FieldCp(uss_Var[uss_VarMax], - a_tp, - ':', - uss_MAX_ARG_SIZE, - &overflow); + a_tp = + uss_common_FieldCp(uss_Var[uss_VarMax], a_tp, ':', + uss_MAX_ARG_SIZE, &overflow); if (overflow) { fprintf(stderr, "%s: * Variable %d field in add cmd too long (max is %d chars; truncated value is '%s')\n", - uss_whoami, uss_VarMax, uss_MAX_ARG_SIZE, uss_Var[uss_VarMax]); - return(-1); + uss_whoami, uss_VarMax, uss_MAX_ARG_SIZE, + uss_Var[uss_VarMax]); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) goto DoBulkAddLine_ParsingDone; } -DoBulkAddLine_ParsingDone: + DoBulkAddLine_ParsingDone: /* * If there's anything left on the line, we ignore it. Announce * the bulk add parameters we've parsed or filled in if we're * being verbose, then go for it. */ if (uss_verbose) { - fprintf(stderr, "\nAdding user '%s' ('%s'), password='%s' on server '%s', partition '%s', home directory='%s'", + fprintf(stderr, + "\nAdding user '%s' ('%s'), password='%s' on server '%s', partition '%s', home directory='%s'", uss_User, uss_RealName, uss_Pwd, (uss_Server[0] != '\0' ? uss_Server : ""), (uss_Partition[0] != '\0' ? uss_Partition : ""), @@ -727,14 +730,15 @@ DoBulkAddLine_ParsingDone: } if (uss_VarMax > 0) fprintf(stderr, "\n"); - } /*Verbose status of add command*/ - + } + + /*Verbose status of add command */ /* * Now do the real work. */ - return(DoAdd()); + return (DoAdd()); -} /*DoBulkAddLine*/ +} /*DoBulkAddLine */ /*----------------------------------------------------------------------- @@ -760,14 +764,15 @@ DoBulkAddLine_ParsingDone: * As advertised. *------------------------------------------------------------------------*/ -static int DoBulkDeleteLine(a_buf, a_tp) - char *a_buf; - char *a_tp; +static int +DoBulkDeleteLine(a_buf, a_tp) + char *a_buf; + char *a_tp; -{ /*DoBulkDeleteLine*/ +{ /*DoBulkDeleteLine */ - char volField[32]; /*Value of optional vol disposition field*/ - int overflow; /*Was there an overflow in field copying?*/ + char volField[32]; /*Value of optional vol disposition field */ + int overflow; /*Was there an overflow in field copying? */ /* * Pull out all the fields. @@ -777,18 +782,19 @@ static int DoBulkDeleteLine(a_buf, a_tp) fprintf(stderr, "%s: * User field in delete cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_UserLen, uss_User); - return(-1); + return (-1); } if ((uss_User[0] == '\0') || (*a_tp == '\0') || (*a_tp == '\n')) goto Delete_MissingRequiredParam; - a_tp = uss_common_FieldCp(uss_MountPoint, a_tp, ':', uss_MountPointLen, - &overflow); + a_tp = + uss_common_FieldCp(uss_MountPoint, a_tp, ':', uss_MountPointLen, + &overflow); if (overflow) { fprintf(stderr, "%s: * Mountpoint field in delete cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_MountPointLen, uss_MountPoint); - return(-1); + return (-1); } #if USS_FUTURE_FEATURES #if USS_DONT_HIDE_SOME_FEATURES @@ -802,35 +808,39 @@ static int DoBulkDeleteLine(a_buf, a_tp) #if USS_FUTURE_FEATURES #if USS_DONT_HIDE_SOME_FEATURES - a_tp = uss_common_FieldCp(uss_RestoreDir, a_tp, ':', uss_RestoreDirLen, - &overflow); + a_tp = + uss_common_FieldCp(uss_RestoreDir, a_tp, ':', uss_RestoreDirLen, + &overflow); if (overflow) { fprintf(stderr, "%s: * RestoreDir field in delete cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_RestoreDirLen, uss_RestoreDir); - return(-1); + return (-1); } if (uss_RestoreDir[0] == '\0') goto Delete_MissingRequiredParam; if ((*a_tp == '\0') || (*a_tp == '\n')) goto Delete_ParsingDone; - a_tp = uss_common_FieldCp(uss_PwdPath, a_tp, ':', uss_PwdPathLen, &overflow); + a_tp = + uss_common_FieldCp(uss_PwdPath, a_tp, ':', uss_PwdPathLen, &overflow); if (overflow) { fprintf(stderr, "%s: * Password path field in delete cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_PwdPathLen, uss_PwdPath); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) goto Delete_ParsingDone; - a_tp = uss_common_FieldCp(uss_PwdFormat, a_tp, ':', uss_PwdFormatLen, &overflow); + a_tp = + uss_common_FieldCp(uss_PwdFormat, a_tp, ':', uss_PwdFormatLen, + &overflow); if (overflow) { fprintf(stderr, "%s: * Password format field in delete cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_PwdFormatLen, uss_PwdFormat); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) goto Delete_ParsingDone; @@ -842,7 +852,7 @@ static int DoBulkDeleteLine(a_buf, a_tp) fprintf(stderr, "%s: * Volume save/del field in delete cmd too long (max is 32 chars; truncated value is '%s')\n", uss_whoami, volField); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) goto Delete_ParsingDone; @@ -867,28 +877,28 @@ static int DoBulkDeleteLine(a_buf, a_tp) uss_PwdFormat); #endif /* USS_DONT_HIDE_SOME_FEATURES */ #else - fprintf(stderr, - "\nDeleting user '%s' mounted at '%s'", - uss_User, uss_MountPoint); + fprintf(stderr, "\nDeleting user '%s' mounted at '%s'", uss_User, + uss_MountPoint); #endif /* USS_FUTURE_FEATURES */ if (uss_SaveVolume) fprintf(stderr, ", saving user's volume\n"); else fprintf(stderr, ", deleting user's volume\n"); - } /*Verbose status of delete command*/ + } + /*Verbose status of delete command */ /* * Now do the real work. */ - return(DoDelete()); + return (DoDelete()); Delete_MissingRequiredParam: fprintf(stderr, "%s: * All of the user, mountpoint, and restoredir fields must appear in a bulk delete command line.\n", uss_whoami); - return(-1); + return (-1); -} /*DoBulkDeleteLine*/ +} /*DoBulkDeleteLine */ #if USS_FUTURE_FEATURES #if USS_DONT_HIDE_SOME_FEATURES @@ -914,14 +924,15 @@ static int DoBulkDeleteLine(a_buf, a_tp) * As advertised. *------------------------------------------------------------------------*/ -static int DoBulkPurgeVolumeLine(a_buf, a_tp) - char *a_buf; - char *a_tp; +static int +DoBulkPurgeVolumeLine(a_buf, a_tp) + char *a_buf; + char *a_tp; -{ /*DoBulkPurgeVolumeLine*/ +{ /*DoBulkPurgeVolumeLine */ - register int i; /*Loop variable*/ - int overflow; /*Did a field copy overflow happen?*/ + register int i; /*Loop variable */ + int overflow; /*Did a field copy overflow happen? */ /* * Pull out all the fields. @@ -931,21 +942,23 @@ static int DoBulkPurgeVolumeLine(a_buf, a_tp) fprintf(stderr, "%s: * User field in purgevolume cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_UserLen, uss_User); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) { fprintf(stderr, "%s: * The user field must appear in a bulk add command.\n", uss_whoami); - return(-1); + return (-1); } - a_tp = uss_common_FieldCp(uss_RealName, a_tp, ':', uss_RealNameLen, &overflow); + a_tp = + uss_common_FieldCp(uss_RealName, a_tp, ':', uss_RealNameLen, + &overflow); if (overflow) { fprintf(stderr, "%s: * Real name field in purgevolume cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_RealNameLen, uss_RealName); - return(-1); + return (-1); } if (uss_RealName[0] == '\0') { /* @@ -954,17 +967,16 @@ static int DoBulkPurgeVolumeLine(a_buf, a_tp) */ sprintf(uss_RealName, "%s", uss_User); if (uss_verbose) - fprintf(stderr, - "%s: Using default real name, '%s'\n", - uss_whoami, uss_User); - } /*Use default full name*/ - + fprintf(stderr, "%s: Using default real name, '%s'\n", uss_whoami, + uss_User); + } + /*Use default full name */ a_tp = uss_common_FieldCp(uss_Pwd, a_tp, ':', uss_PwdLen, &overflow); if (overflow) { fprintf(stderr, "%s: * Password field in purgevolume cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_PwdLen, uss_Pwd); - return(-1); + return (-1); } if (uss_Pwd[0] == '\0') { /* @@ -973,69 +985,66 @@ static int DoBulkPurgeVolumeLine(a_buf, a_tp) */ sprintf(uss_Pwd, "%s", uss_DEFAULT_PASSWORD); if (uss_verbose) - fprintf(stderr, - "%s: Using default password, '%s'\n", - uss_whoami, uss_Pwd); - } /*Use default password*/ + fprintf(stderr, "%s: Using default password, '%s'\n", uss_whoami, + uss_Pwd); + } /*Use default password */ if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); - a_tp = uss_common_FieldCp(uss_Server, a_tp, ':', uss_ServerLen, &overflow); + a_tp = + uss_common_FieldCp(uss_Server, a_tp, ':', uss_ServerLen, &overflow); if (overflow) { - fprintf(stderr, - "%s: * Server field too long (max is %d chars)\n", + fprintf(stderr, "%s: * Server field too long (max is %d chars)\n", uss_whoami, uss_ServerLen); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); - a_tp = uss_common_FieldCp(uss_Partition, a_tp, ':', uss_PartitionLen, &overflow); + a_tp = + uss_common_FieldCp(uss_Partition, a_tp, ':', uss_PartitionLen, + &overflow); if (overflow) { - fprintf(stderr, - "%s: * Partition field too long (max is %d chars)\n", + fprintf(stderr, "%s: * Partition field too long (max is %d chars)\n", uss_whoami, uss_PartitionLen); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); - a_tp = uss_common_FieldCp(uss_MountPoint, a_tp, ':', uss_MountPointLen, - &overflow); + a_tp = + uss_common_FieldCp(uss_MountPoint, a_tp, ':', uss_MountPointLen, + &overflow); if (overflow) { - fprintf(stderr, - "%s: * Mountpoint field too long (max is %d chars)\n", + fprintf(stderr, "%s: * Mountpoint field too long (max is %d chars)\n", uss_whoami, uss_MountPointLen); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); a_tp = uss_common_FieldCp(uss_Uid, a_tp, ':', uss_UidLen, &overflow); if (overflow) { - fprintf(stderr, - "%s: * UID field too long (max is %d chars)\n", + fprintf(stderr, "%s: * UID field too long (max is %d chars)\n", uss_whoami, uss_UidLen); - return(-1); + return (-1); } uss_DesiredUID = atoi(uss_Uid); if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); for (uss_VarMax = 1; uss_VarMax < 10; uss_VarMax++) { - a_tp = uss_common_FieldCp(uss_Var[uss_VarMax], - a_tp, - ':', - uss_MAX_ARG_SIZE, - &overflow); + a_tp = + uss_common_FieldCp(uss_Var[uss_VarMax], a_tp, ':', + uss_MAX_ARG_SIZE, &overflow); if (overflow) { fprintf(stderr, "%s: * Variable %d field too long (max is %d chars)\n", uss_whoami, uss_VarMax, uss_MAX_ARG_SIZE); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); } /* @@ -1044,7 +1053,8 @@ static int DoBulkPurgeVolumeLine(a_buf, a_tp) * being verbose, then go for it. */ if (uss_verbose) { - fprintf(stderr, "\nAdding user '%s' ('%s'), password='%s' on server '%s', partition '%s', home directory='%s'", + fprintf(stderr, + "\nAdding user '%s' ('%s'), password='%s' on server '%s', partition '%s', home directory='%s'", uss_User, uss_RealName, uss_Pwd, (uss_Server[0] != '\0' ? uss_Server : ""), (uss_Partition[0] != '\0' ? uss_Partition : ""), @@ -1059,14 +1069,15 @@ static int DoBulkPurgeVolumeLine(a_buf, a_tp) } if (uss_VarMax > 0) fprintf(stderr, "\n"); - } /*Verbose status of add command*/ - + } + + /*Verbose status of add command */ /* * Now do the real work. */ - return(DoAdd()); + return (DoAdd()); -} /*DoBulkPurgeVolumeLine*/ +} /*DoBulkPurgeVolumeLine */ #endif /* USS_DONT_HIDE_SOME_FEATURES */ #endif /* USS_FUTURE_FEATURES */ @@ -1094,38 +1105,39 @@ static int DoBulkPurgeVolumeLine(a_buf, a_tp) * As advertised. *------------------------------------------------------------------------*/ -static int DoBulkRestoreLine(a_buf, a_tp) - char *a_buf; - char *a_tp; +static int +DoBulkRestoreLine(a_buf, a_tp) + char *a_buf; + char *a_tp; -{ /*DoBulkRestoreLine*/ +{ /*DoBulkRestoreLine */ - register int i; /*Loop variable*/ - int overflow; /*Overflow occur on field copy?*/ + register int i; /*Loop variable */ + int overflow; /*Overflow occur on field copy? */ /* * Pull out all the fields. */ a_tp = uss_common_FieldCp(uss_User, a_tp, ':', uss_UserLen, &overflow); if (overflow) { - fprintf(stderr, - "%s: * User field too long (max is %d chars)\n", + fprintf(stderr, "%s: * User field too long (max is %d chars)\n", uss_whoami, uss_UserLen); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) { fprintf(stderr, "%s: * The user field must appear in a bulk add command.\n", uss_whoami); - return(-1); + return (-1); } - a_tp = uss_common_FieldCp(uss_RealName, a_tp, ':', uss_RealNameLen, &overflow); + a_tp = + uss_common_FieldCp(uss_RealName, a_tp, ':', uss_RealNameLen, + &overflow); if (overflow) { - fprintf(stderr, - "%s: * Real name field too long (max is %d chars)\n", + fprintf(stderr, "%s: * Real name field too long (max is %d chars)\n", uss_whoami, uss_RealNameLen); - return(-1); + return (-1); } if (uss_RealName[0] == '\0') { /* @@ -1134,17 +1146,15 @@ static int DoBulkRestoreLine(a_buf, a_tp) */ sprintf(uss_RealName, "%s", uss_User); if (uss_verbose) - fprintf(stderr, - "%s: Using default real name, '%s'\n", - uss_whoami, uss_User); - } /*Use default full name*/ - + fprintf(stderr, "%s: Using default real name, '%s'\n", uss_whoami, + uss_User); + } + /*Use default full name */ a_tp = uss_common_FieldCp(uss_Pwd, a_tp, ':', uss_PwdLen, &overflow); if (overflow) { - fprintf(stderr, - "%s: * Password field too long (max is %d chars)\n", + fprintf(stderr, "%s: * Password field too long (max is %d chars)\n", uss_whoami, uss_PwdLen); - return(-1); + return (-1); } if (uss_Pwd[0] == '\0') { /* @@ -1153,70 +1163,66 @@ static int DoBulkRestoreLine(a_buf, a_tp) */ sprintf(uss_Pwd, "%s", uss_DEFAULT_PASSWORD); if (uss_verbose) - fprintf(stderr, - "%s: Using default password, '%s'\n", - uss_whoami, uss_Pwd); - } /*Use default password*/ + fprintf(stderr, "%s: Using default password, '%s'\n", uss_whoami, + uss_Pwd); + } /*Use default password */ if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); - a_tp = uss_common_FieldCp(uss_Server, a_tp, ':', uss_ServerLen, &overflow); + a_tp = + uss_common_FieldCp(uss_Server, a_tp, ':', uss_ServerLen, &overflow); if (overflow) { - fprintf(stderr, - "%s: * Server field too long (max is %d chars)\n", + fprintf(stderr, "%s: * Server field too long (max is %d chars)\n", uss_whoami, uss_ServerLen); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); - a_tp = uss_common_FieldCp(uss_Partition, a_tp, ':', uss_PartitionLen, - &overflow); + a_tp = + uss_common_FieldCp(uss_Partition, a_tp, ':', uss_PartitionLen, + &overflow); if (overflow) { - fprintf(stderr, - "%s: * Partition field too long (max is %d chars)\n", + fprintf(stderr, "%s: * Partition field too long (max is %d chars)\n", uss_whoami, uss_PartitionLen); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); - a_tp = uss_common_FieldCp(uss_MountPoint, a_tp, ':', uss_MountPointLen, - &overflow); + a_tp = + uss_common_FieldCp(uss_MountPoint, a_tp, ':', uss_MountPointLen, + &overflow); if (overflow) { - fprintf(stderr, - "%s: * mountpoint field too long (max is %d chars)\n", + fprintf(stderr, "%s: * mountpoint field too long (max is %d chars)\n", uss_whoami, uss_MountPointLen); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); a_tp = uss_common_FieldCp(uss_Uid, a_tp, ':', uss_UidLen, &overflow); if (overflow) { - fprintf(stderr, - "%s: * UID field too long (max is %d chars)\n", + fprintf(stderr, "%s: * UID field too long (max is %d chars)\n", uss_whoami, uss_UidLen); - return(-1); + return (-1); } uss_DesiredUID = atoi(uss_Uid); if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); for (uss_VarMax = 1; uss_VarMax < 10; uss_VarMax++) { - a_tp = uss_common_FieldCp(uss_Var[uss_VarMax], - a_tp, - ':', - uss_MAX_ARG_SIZE, - &overflow); + a_tp = + uss_common_FieldCp(uss_Var[uss_VarMax], a_tp, ':', + uss_MAX_ARG_SIZE, &overflow); if (overflow) { fprintf(stderr, "%s: * Variable %d field too long (max is %d chars)\n", uss_whoami, uss_VarMax, uss_MAX_ARG_SIZE); - return(-1); + return (-1); } if ((*a_tp == '\0') || (*a_tp == '\n')) - return(0); + return (0); } /* @@ -1225,7 +1231,8 @@ static int DoBulkRestoreLine(a_buf, a_tp) * being verbose, then go for it. */ if (uss_verbose) { - fprintf(stderr, "\nAdding user '%s' ('%s'), password='%s' on server '%s', partition '%s', home directory='%s'", + fprintf(stderr, + "\nAdding user '%s' ('%s'), password='%s' on server '%s', partition '%s', home directory='%s'", uss_User, uss_RealName, uss_Pwd, (uss_Server[0] != '\0' ? uss_Server : ""), (uss_Partition[0] != '\0' ? uss_Partition : ""), @@ -1240,14 +1247,15 @@ static int DoBulkRestoreLine(a_buf, a_tp) } if (uss_VarMax > 0) fprintf(stderr, "\n"); - } /*Verbose status of add command*/ - + } + + /*Verbose status of add command */ /* * Now do the real work. */ - return(DoRestore()); + return (DoRestore()); -} /*DoBulkRestoreLine*/ +} /*DoBulkRestoreLine */ #endif /* USS_DONT_HIDE_SOME_FEATURES */ #endif /* USS_FUTURE_FEATURES */ @@ -1274,21 +1282,22 @@ static int DoBulkRestoreLine(a_buf, a_tp) * As advertised. *------------------------------------------------------------------------*/ -static int DoBulkExecLine(a_buf, a_tp) - char *a_buf; - char *a_tp; +static int +DoBulkExecLine(a_buf, a_tp) + char *a_buf; + char *a_tp; -{ /*DoBulkExecLine*/ +{ /*DoBulkExecLine */ - register afs_int32 code; /*Return code*/ + register afs_int32 code; /*Return code */ /* * Really, uss_procs_Exec does all the work for us! */ code = uss_procs_Exec(a_tp); - return(code); + return (code); -} /*DoBulkExecLine*/ +} /*DoBulkExecLine */ /*----------------------------------------------------------------------- @@ -1313,11 +1322,12 @@ static int DoBulkExecLine(a_buf, a_tp) * As advertised. *------------------------------------------------------------------------*/ extern int Pipe; -static int HandleBulk(a_as, a_rock) +static int +HandleBulk(a_as, a_rock) register struct cmd_syndesc *a_as; char *a_rock; -{ /*HandleBulk*/ +{ /*HandleBulk */ #define USS_BULK_CMD_CHARS 128 #define USS_BULK_BUF_CHARS 1024 @@ -1328,20 +1338,19 @@ static int HandleBulk(a_as, a_rock) int overflow; int code; - int line_no=0; - int error; - char tbuf[USS_BULK_BUF_CHARS]; + int line_no = 0; + int error; + char tbuf[USS_BULK_BUF_CHARS]; /* * Open up the bulk file, croak if we can't. */ if ((infile = fopen(a_as->parms[ABULK_FILE].items->data, "r")) == NULL) { - fprintf(stderr, - "%s: * Failed to open input file %s\n", - uss_whoami, a_as->parms[ABULK_FILE].items->data); - return(-1); + fprintf(stderr, "%s: * Failed to open input file %s\n", uss_whoami, + a_as->parms[ABULK_FILE].items->data); + return (-1); } - + /* * Pull out the other fields as passed in by the caller on the * command line. @@ -1362,41 +1371,43 @@ static int HandleBulk(a_as, a_rock) if (a_as->parms[AUSS_PWEXPIRES].items) { uss_BulkExpires = atoi(a_as->parms[AUSS_PWEXPIRES].items->data); if (uss_BulkExpires < 0 || uss_BulkExpires > 254) { - fprintf(stderr,"%s: Password Expiration must be in [0..255] days\n", - uss_whoami); - return(-1); + fprintf(stderr, + "%s: Password Expiration must be in [0..255] days\n", + uss_whoami); + return (-1); } - } - else - uss_BulkExpires = 0; - + } else + uss_BulkExpires = 0; + /* * Initialize uss_AccountCreator(). */ code = uss_kauth_InitAccountCreator(); if (code) - return(code); + return (code); /* * Process all the lines in the bulk command file. */ - uss_VarMax = 0; /*No uss vars picked up yet*/ + uss_VarMax = 0; /*No uss vars picked up yet */ while (fgets(buf, sizeof(buf), infile) != NULL) { /* skip blank line */ - if(buf[0]=='\n') - continue; + if (buf[0] == '\n') + continue; /* After executing the line, print the line and the result */ if (line_no) { - if (error == UNOQUORUM) { - IOMGR_Sleep(1); - } + if (error == UNOQUORUM) { + IOMGR_Sleep(1); + } - if (!error) error = uss_perr; - printf("LINE %d %s %s", line_no, (error?"FAIL":"SUCCESS"), tbuf); - fflush(stdout); + if (!error) + error = uss_perr; + printf("LINE %d %s %s", line_no, (error ? "FAIL" : "SUCCESS"), + tbuf); + fflush(stdout); } /* @@ -1405,68 +1416,68 @@ static int HandleBulk(a_as, a_rock) */ uss_common_Reset(); - sprintf(tbuf,"%s",buf); + strncpy(tbuf, buf, USS_BULK_BUF_CHARS-1); /* - First line of file = line 1. - */ + * First line of file = line 1. + */ ++line_no; /* * Get the opcode and act upon it. - */ - tp = uss_common_FieldCp(cmd, buf, ' ', USS_BULK_CMD_CHARS, &overflow); + */ + tp = uss_common_FieldCp(cmd, buf, ' ', USS_BULK_CMD_CHARS, &overflow); if (overflow) { fprintf(stderr, "%s: * Bulk opcode field too long (max is %d chars)\n", uss_whoami, USS_BULK_CMD_CHARS); - error = -1; - continue; + error = -1; + continue; /* return(-1); */ } if (strcmp(cmd, "add") == 0) { - error=DoBulkAddLine(buf, tp); + error = DoBulkAddLine(buf, tp); continue; } if (strcmp(cmd, "delete") == 0) { - error=DoBulkDeleteLine(buf, tp); + error = DoBulkDeleteLine(buf, tp); continue; } if (strcmp(cmd, "delvolume") == 0) { uss_SaveVolume = 0; - error=0; + error = 0; continue; } #if USS_FUTURE_FEATURES #if USS_DONT_HIDE_SOME_FEATURES if (strcmp(cmd, "purgevolume") == 0) { - error=DoBulkPurgeVolumeLine(buf, tp); + error = DoBulkPurgeVolumeLine(buf, tp); continue; } if (strcmp(cmd, "pwdformat") == 0) { - /*Set the password format here*/ + /*Set the password format here */ continue; } if (strcmp(cmd, "pwdpath") == 0) { - /*Set the password path here*/ + /*Set the password path here */ continue; } if (strcmp(cmd, "restore") == 0) { - error=DoBulkRestoreLine(buf, tp); + error = DoBulkRestoreLine(buf, tp); continue; } #endif /* USS_DONT_HIDE_SOME_FEATURES */ #endif /* USS_FUTURE_FEATURES */ if (strcmp(cmd, "savevolume") == 0) { - /*Set the savevolume flag here*/ + /*Set the savevolume flag here */ continue; } if (strcmp(cmd, "exec") == 0) { - error=DoBulkExecLine(buf, tp); + error = DoBulkExecLine(buf, tp); continue; } @@ -1480,24 +1491,25 @@ static int HandleBulk(a_as, a_rock) "%s: ** Unrecognized command ('%s') in bulk file\n", uss_whoami, cmd); - error = -1; - continue; + error = -1; + continue; /* return(-1); */ - } /*Bad bulk line*/ - } /*Process a line in the bulk file*/ + } /*Bad bulk line */ + } /*Process a line in the bulk file */ /* Last line. */ if (line_no) { - if (!error) error = uss_perr; - printf("LINE %d %s %s", line_no, (error?"FAIL":"SUCCESS"), tbuf); - fflush(stdout); + if (!error) + error = uss_perr; + printf("LINE %d %s %s", line_no, (error ? "FAIL" : "SUCCESS"), tbuf); + fflush(stdout); } - return(0); -} /*HandleBulk*/ + return (0); +} /*HandleBulk */ /*----------------------------------------------------------------------- @@ -1522,11 +1534,12 @@ static int HandleBulk(a_as, a_rock) * As advertised. *------------------------------------------------------------------------*/ -static int AddUser(a_as, a_rock) +static int +AddUser(a_as, a_rock) register struct cmd_syndesc *a_as; char *a_rock; -{ /*AddUser*/ +{ /*AddUser */ int i; register struct cmd_item *ti; @@ -1537,7 +1550,7 @@ static int AddUser(a_as, a_rock) * global field settings. */ uss_common_Reset(); - + /* * Pull out the fields as passed in by the caller on the command * line. @@ -1564,13 +1577,13 @@ static int AddUser(a_as, a_rock) if (a_as->parms[AUP_PWEXPIRES].items) { uss_Expires = atoi(a_as->parms[AUP_PWEXPIRES].items->data); if (uss_Expires < 0 || uss_Expires > 254) { - fprintf(stderr,"%s: Password Expiration must be in [0..255] days\n", - uss_whoami); - return(-1); + fprintf(stderr, + "%s: Password Expiration must be in [0..255] days\n", + uss_whoami); + return (-1); } - } - else - uss_Expires = 0; + } else + uss_Expires = 0; if (a_as->parms[AUSS_DRYRUN].items) uss_DryRun = 1; @@ -1581,49 +1594,49 @@ static int AddUser(a_as, a_rock) if (a_as->parms[AUSS_ADMIN].items) { strcpy(uss_Administrator, a_as->parms[AUSS_ADMIN].items->data); /* fprintf(stderr, "debugging: uss_Administrator set to '%s'\n", - uss_Administrator);*/ - } - else { - /* fprintf(stderr, "debugging: No administrator value given\n");*/ + * uss_Administrator); */ + } else { + /* fprintf(stderr, "debugging: No administrator value given\n"); */ uss_Administrator[0] = '\0'; } - + if (a_as->parms[AUSS_VAR].items) { for (ti = a_as->parms[AUSS_VAR].items; ti; ti = ti->next) { i = atoi(ti->data); - if (i <0 || i>9 || (i==0 && *ti->data != '0')) { + if (i < 0 || i > 9 || (i == 0 && *ti->data != '0')) { fprintf(stderr, "%s: Bad -var format: must be '0 val0 1 val1 ... 9 val9'\n", uss_whoami); - return(-1); + return (-1); } ti = ti->next; if (!ti) { fprintf(stderr, "%s: -var values must appear in pairs: 'Num val'\n", uss_whoami); - return(-1); + return (-1); } strcpy(uss_Var[i], ti->data); - if (i > uss_VarMax) + if (i > uss_VarMax) uss_VarMax = i; - } /*Remember each VAR item*/ - } /*VAR items exist*/ + } /*Remember each VAR item */ + } + /*VAR items exist */ /* * Initialize uss_AccountCreator(). */ code = uss_kauth_InitAccountCreator(); if (code) - return(code); + return (code); /* * Now that the command line arguments are parsed and properly stored, * go for it! */ - return(DoAdd()); + return (DoAdd()); -} /*AddUser*/ +} /*AddUser */ /*----------------------------------------------------------------------- @@ -1648,18 +1661,18 @@ static int AddUser(a_as, a_rock) * As advertised. *------------------------------------------------------------------------*/ -static int DoAdd() - -{ /*DoAdd*/ +static int +DoAdd() +{ /*DoAdd */ - int code; /*Return code*/ + int code; /*Return code */ /* * Make sure the user name is legal. */ code = uss_kauth_CheckUserName(); if (code) - return(code); + return (code); /* * This time around, we start off assuming the global value of the @@ -1673,14 +1686,12 @@ static int DoAdd() */ if (yyin == NULL) { if ((yyin = uss_procs_FindAndOpen(Template)) == NULL) { - fprintf(stderr, - "%s: ** Can't open template file '%s'\n", + fprintf(stderr, "%s: ** Can't open template file '%s'\n", uss_whoami, Template); - return(-1); + return (-1); } yyout = fopen("/dev/null", "w"); - } - else + } else rewind(yyin); /* @@ -1688,10 +1699,9 @@ static int DoAdd() */ code = uss_ptserver_AddUser(uss_User, uss_Uid); if (code) { - fprintf(stderr, - "%s: Failed to add user '%s' to the Protection DB\n", + fprintf(stderr, "%s: Failed to add user '%s' to the Protection DB\n", uss_whoami, uss_User); - return(code); + return (code); } /* @@ -1699,12 +1709,11 @@ static int DoAdd() */ code = uss_kauth_AddUser(uss_User, uss_Pwd); if (code) { - fprintf(stderr, - "%s: Can't add user '%s' to the Authentication DB\n", + fprintf(stderr, "%s: Can't add user '%s' to the Authentication DB\n", uss_whoami, uss_User); - return(code); + return (code); } - + /* * Process the items covered by the template file. */ @@ -1715,9 +1724,9 @@ static int DoAdd() * Finally, clean up after ourselves, removing the uss_AccountCreator * from various of the new user's ACLs. */ - return(uss_acl_CleanUp()); + return (uss_acl_CleanUp()); -} /*DoAdd*/ +} /*DoAdd */ #if USS_FUTURE_FEATURES @@ -1743,13 +1752,13 @@ static int DoAdd() * As advertised. *------------------------------------------------------------------------*/ -static int DoRestore() - -{ /*DoRestore*/ +static int +DoRestore() +{ /*DoRestore */ - return(0); + return (0); -} /*DoRestore*/ +} /*DoRestore */ #endif /* USS_DONT_HIDE_SOME_FEATURES */ #endif /* USS_FUTURE_FEATURES */ @@ -1773,9 +1782,9 @@ static int DoRestore() * As advertised. *------------------------------------------------------------------------*/ -void InitETTables() - -{ /*InitETTables*/ +void +InitETTables() +{ /*InitETTables */ /* @@ -1791,26 +1800,27 @@ void InitETTables() initialize_PT_error_table(); initialize_U_error_table(); -} /*InitETTables*/ +} /*InitETTables */ -int osi_audit() +int +osi_audit() { /* this sucks but it works for now. */ -return 0; + return 0; } #include "AFS_component_version_number.c" -main(argc,argv) +main(argc, argv) int argc; char *argv[]; -{ /*Main routine*/ +{ /*Main routine */ - register struct cmd_syndesc *cs; /*Command line syntax descriptor*/ - register afs_int32 code; /*Return code*/ + register struct cmd_syndesc *cs; /*Command line syntax descriptor */ + register afs_int32 code; /*Return code */ #ifdef AFS_AIX32_ENV /* @@ -1820,7 +1830,7 @@ main(argc,argv) * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; @@ -1828,24 +1838,22 @@ main(argc,argv) sigaction(SIGSEGV, &nsa, NULL); #endif strcpy(uss_whoami, argv[0]); - yyin = (FILE *)NULL; + yyin = (FILE *) NULL; - uss_fs_InBuff = (char*)malloc(USS_FS_MAX_SIZE); /*Cache Manager input buff*/ - uss_fs_OutBuff = (char*)malloc(USS_FS_MAX_SIZE); /*Cache Manager output buff*/ + uss_fs_InBuff = (char *)malloc(USS_FS_MAX_SIZE); /*Cache Manager input buff */ + uss_fs_OutBuff = (char *)malloc(USS_FS_MAX_SIZE); /*Cache Manager output buff */ if (!uss_fs_InBuff || !uss_fs_OutBuff) { - fprintf(stderr, "%s: Can't malloc in/out buffers\n", uss_whoami); - exit(-1); + fprintf(stderr, "%s: Can't malloc in/out buffers\n", uss_whoami); + exit(-1); } - /* ----------------------------- add -----------------------------*/ + /* ----------------------------- add ----------------------------- */ cs = cmd_CreateSyntax("add", AddUser, 0, "create a new user account"); - cmd_AddParm(cs, "-user", CMD_SINGLE, 0, - "login name"); + cmd_AddParm(cs, "-user", CMD_SINGLE, 0, "login name"); cmd_AddParm(cs, "-realname", CMD_SINGLE, CMD_OPTIONAL, "full name in quotes"); - cmd_AddParm(cs, "-pass", CMD_SINGLE, CMD_OPTIONAL, - "initial password"); + cmd_AddParm(cs, "-pass", CMD_SINGLE, CMD_OPTIONAL, "initial password"); /* new parm */ cmd_AddParm(cs, "-pwexpires", CMD_SINGLE, CMD_OPTIONAL, "password expires in [0..254] days (0 => never)"); @@ -1860,12 +1868,10 @@ main(argc,argv) cmd_Seek(cs, AUSS_TEMPLATE); cmd_AddParm(cs, "-template", CMD_SINGLE, CMD_OPTIONAL, "pathname of template file"); - cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, - "verbose operation"); - cmd_AddParm(cs, "-var", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, + cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose operation"); + cmd_AddParm(cs, "-var", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, "auxiliary argument pairs (Num val)"); - cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, - "cell name"); + cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_AddParm(cs, "-admin", CMD_SINGLE, CMD_OPTIONAL, "administrator to authenticate"); cmd_AddParm(cs, "-dryrun", CMD_FLAG, CMD_OPTIONAL, @@ -1876,19 +1882,16 @@ main(argc,argv) "Overwrite pre-existing files in user home directory tree"); - /* ---------------------------- bulk -----------------------------*/ + /* ---------------------------- bulk ----------------------------- */ cs = cmd_CreateSyntax("bulk", HandleBulk, 0, "bulk input mode"); - cmd_AddParm(cs, "-file", CMD_SINGLE, 0, - "bulk input file"); + cmd_AddParm(cs, "-file", CMD_SINGLE, 0, "bulk input file"); cmd_Seek(cs, AUSS_TEMPLATE); cmd_AddParm(cs, "-template", CMD_SINGLE, CMD_OPTIONAL, "pathname of template file"); - cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, - "verbose operation"); + cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose operation"); cmd_Seek(cs, AUSS_CELL); - cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, - "cell name"); + cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_AddParm(cs, "-admin", CMD_SINGLE, CMD_OPTIONAL, "administrator to authenticate"); cmd_AddParm(cs, "-dryrun", CMD_FLAG, CMD_OPTIONAL, @@ -1903,12 +1906,11 @@ main(argc,argv) cmd_Seek(cs, AUSS_PIPE); cmd_AddParm(cs, "-pipe", CMD_FLAG, CMD_OPTIONAL, "don't prompt for passwd; get it from standard input"); - - /* ---------------------------- delete ---------------------------*/ + + /* ---------------------------- delete --------------------------- */ cs = cmd_CreateSyntax("delete", DelUser, 0, "delete a user account"); - cmd_AddParm(cs, "-user", CMD_SINGLE, 0, - "login name"); + cmd_AddParm(cs, "-user", CMD_SINGLE, 0, "login name"); cmd_AddParm(cs, "-mountpoint", CMD_SINGLE, CMD_OPTIONAL, "mountpoint for user's volume"); #if USS_FUTURE_FEATURES @@ -1928,11 +1930,9 @@ main(argc,argv) #endif /* USS_DONT_HIDE_SOME_FEATURES */ #endif /* USS_FUTURE_FEATURES */ cmd_Seek(cs, AUSS_VERBOSE); - cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, - "verbose operation"); + cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose operation"); cmd_Seek(cs, AUSS_CELL); - cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, - "cell name"); + cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_AddParm(cs, "-admin", CMD_SINGLE, CMD_OPTIONAL, "administrator to authenticate"); cmd_AddParm(cs, "-dryrun", CMD_FLAG, CMD_OPTIONAL, @@ -1941,20 +1941,18 @@ main(argc,argv) "ignore all contact with the authentication server (kaserver)"); #if USS_FUTURE_FEATURES #if USS_DONT_HIDE_SOME_FEATURES - /* ------------------------- purgevolumes ------------------------*/ + /* ------------------------- purgevolumes ------------------------ */ cs = cmd_CreateSyntax("purgevolumes", PurgeVolumes, 0, "destroy a deleted user's volume"); - cmd_AddParm(cs, "-volname", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, + cmd_AddParm(cs, "-volname", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, "Name(s) of volume(s) to destroy"); cmd_AddParm(cs, "-volfile", CMD_SINGLE, CMD_OPTIONAL, "pathname to volume purge file"); cmd_Seek(cs, AUSS_VERBOSE); - cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, - "verbose operation"); + cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose operation"); cmd_Seek(cs, AUSS_CELL); - cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, - "cell name"); + cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_AddParm(cs, "-admin", CMD_SINGLE, CMD_OPTIONAL, "administrator to authenticate"); cmd_AddParm(cs, "-dryrun", CMD_FLAG, CMD_OPTIONAL, @@ -1966,18 +1964,14 @@ main(argc,argv) #if USS_FUTURE_FEATURES #if USS_DONT_HIDE_SOME_FEATURES - /* ---------------------------- restore --------------------------*/ + /* ---------------------------- restore -------------------------- */ cs = cmd_CreateSyntax("restore", RestoreUser, 0, "restore a deleted user account"); - cmd_AddParm(cs, "-user", CMD_SINGLE, 0, - "login name to restore"); - cmd_AddParm(cs, "-uid", CMD_SINGLE, 0, - "user id number"); - cmd_AddParm(cs, "-mount", CMD_SINGLE, 0, - "mountpoint for user's volume"); - cmd_AddParm(cs, "-volname", CMD_SINGLE, 0, - "name of user's volume"); + cmd_AddParm(cs, "-user", CMD_SINGLE, 0, "login name to restore"); + cmd_AddParm(cs, "-uid", CMD_SINGLE, 0, "user id number"); + cmd_AddParm(cs, "-mount", CMD_SINGLE, 0, "mountpoint for user's volume"); + cmd_AddParm(cs, "-volname", CMD_SINGLE, 0, "name of user's volume"); cmd_AddParm(cs, "-realname", CMD_SINGLE, CMD_OPTIONAL, "user's full name"); cmd_AddParm(cs, "-server", CMD_SINGLE, CMD_OPTIONAL, @@ -1989,11 +1983,9 @@ main(argc,argv) cmd_AddParm(cs, "-pwdformat", CMD_SINGLE, CMD_OPTIONAL, "password entry format"); cmd_Seek(cs, AUSS_VERBOSE); - cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, - "verbose operation"); + cmd_AddParm(cs, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose operation"); cmd_Seek(cs, AUSS_CELL); - cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, - "cell name"); + cmd_AddParm(cs, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_AddParm(cs, "-admin", CMD_SINGLE, CMD_OPTIONAL, "administrator to authenticate"); cmd_AddParm(cs, "-dryrun", CMD_FLAG, CMD_OPTIONAL, @@ -2010,7 +2002,7 @@ main(argc,argv) */ InitETTables(); uss_common_Init(); - cmd_SetBeforeProc(GetCommon, (char *)0); + cmd_SetBeforeProc(GetCommon, NULL); /* * Execute the parsed command. @@ -2018,13 +2010,12 @@ main(argc,argv) code = cmd_Dispatch(argc, argv); #if 0 if (code) { - fprintf(stderr, - "%s: Call to cmd_Dispatch() failed; code is %d\n", - uss_whoami, code); - exit(-1); + fprintf(stderr, "%s: Call to cmd_Dispatch() failed; code is %d\n", + uss_whoami, code); + exit(-1); } #endif /* 0 */ if (doUnlog) { code = uss_fs_UnlogToken(uss_Cell); } -} /*Main routine*/ +} /*Main routine */ diff --git a/src/uss/uss_acl.c b/src/uss/uss_acl.c index 94ffcb334..442c15feb 100644 --- a/src/uss/uss_acl.c +++ b/src/uss/uss_acl.c @@ -18,7 +18,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_acl.c,v 1.1.1.4 2001/07/14 22:24:14 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/uss/uss_acl.c,v 1.6 2003/07/15 23:17:12 shadow Exp $"); #include "uss_acl.h" #include "uss_common.h" @@ -28,6 +29,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_acl.c,v 1.1.1.4 2001/07/14 22:2 #include #include #include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #undef VIRTUE #undef VICE #include @@ -76,25 +86,28 @@ static int PruneList(); * As advertised. *------------------------------------------------------------------------*/ -static foldcmp(a_str1, a_str2) - register char *a_str1; - register char *a_str2; +static +foldcmp(a_str1, a_str2) + register char *a_str1; + register char *a_str2; -{ /*foldcmp*/ +{ /*foldcmp */ register char t, u; while (1) { - t = *a_str1++; - u = *a_str2++; - if (t >= 'A' && t <= 'Z') t += 0x20; - if (u >= 'A' && u <= 'Z') u += 0x20; - if (t != u) - return(1); /*Difference*/ - if (t == 0) - return(0); /*Match*/ + t = *a_str1++; + u = *a_str2++; + if (t >= 'A' && t <= 'Z') + t += 0x20; + if (u >= 'A' && u <= 'Z') + u += 0x20; + if (t != u) + return (1); /*Difference */ + if (t == 0) + return (0); /*Match */ } -} /*foldcmp*/ +} /*foldcmp */ /*------------------------------------------------------------------------ @@ -118,63 +131,59 @@ static foldcmp(a_str1, a_str2) * passed in. *------------------------------------------------------------------------*/ -static afs_int32 Convert(a_rights) - register char *a_rights; +static afs_int32 +Convert(a_rights) + register char *a_rights; -{ /*Convert*/ +{ /*Convert */ register int i, len; afs_int32 mode; register char tc; - if (!strcmp(a_rights,"read")) - return(PRSFS_READ | PRSFS_LOOKUP); + if (!strcmp(a_rights, "read")) + return (PRSFS_READ | PRSFS_LOOKUP); if (!strcmp(a_rights, "write")) - return(PRSFS_READ - | PRSFS_LOOKUP - | PRSFS_INSERT - | PRSFS_DELETE - | PRSFS_WRITE - | PRSFS_LOCK); + return (PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | + PRSFS_WRITE | PRSFS_LOCK); if (!strcmp(a_rights, "mail")) - return(PRSFS_INSERT - | PRSFS_LOCK - | PRSFS_LOOKUP); + return (PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP); if (!strcmp(a_rights, "all")) - return(PRSFS_READ - | PRSFS_LOOKUP - | PRSFS_INSERT - | PRSFS_DELETE - | PRSFS_WRITE - | PRSFS_LOCK - | PRSFS_ADMINISTER); + return (PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | + PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER); if (!strcmp(a_rights, "none")) - return(0); + return (0); len = strlen(a_rights); mode = 0; for (i = 0; i < len; i++) { - tc = *a_rights++; - if (tc == 'r') mode |= PRSFS_READ; - else if (tc == 'l') mode |= PRSFS_LOOKUP; - else if (tc == 'i') mode |= PRSFS_INSERT; - else if (tc == 'd') mode |= PRSFS_DELETE; - else if (tc == 'w') mode |= PRSFS_WRITE; - else if (tc == 'k') mode |= PRSFS_LOCK; - else if (tc == 'a') mode |= PRSFS_ADMINISTER; - else { - printf("%s: Bogus rights character '%c'.\n", - uss_whoami, tc); - exit(1); + tc = *a_rights++; + if (tc == 'r') + mode |= PRSFS_READ; + else if (tc == 'l') + mode |= PRSFS_LOOKUP; + else if (tc == 'i') + mode |= PRSFS_INSERT; + else if (tc == 'd') + mode |= PRSFS_DELETE; + else if (tc == 'w') + mode |= PRSFS_WRITE; + else if (tc == 'k') + mode |= PRSFS_LOCK; + else if (tc == 'a') + mode |= PRSFS_ADMINISTER; + else { + printf("%s: Bogus rights character '%c'.\n", uss_whoami, tc); + exit(1); } } - return(mode); + return (mode); -} /*Convert*/ +} /*Convert */ /*------------------------------------------------------------------------ @@ -197,20 +206,21 @@ static afs_int32 Convert(a_rights) * As advertised. *------------------------------------------------------------------------*/ -static struct AclEntry *FindList(a_alist, a_name) - register struct AclEntry *a_alist; - char *a_name; +static struct AclEntry * +FindList(a_alist, a_name) + register struct AclEntry *a_alist; + char *a_name; -{ /*FindList*/ +{ /*FindList */ while (a_alist) { - if (!foldcmp(a_alist->name, a_name)) - return(a_alist); - a_alist = a_alist->next; + if (!foldcmp(a_alist->name, a_name)) + return (a_alist); + a_alist = a_alist->next; } - return(0); + return (0); -} /*FindList*/ +} /*FindList */ /*------------------------------------------------------------------------ @@ -237,51 +247,51 @@ static struct AclEntry *FindList(a_alist, a_name) * As advertised. *------------------------------------------------------------------------*/ -static void ChangeList (a_al, a_plus, a_name, a_rights) - struct Acl *a_al; - afs_int32 a_plus; - char *a_name; - afs_int32 a_rights; +static void +ChangeList(a_al, a_plus, a_name, a_rights) + struct Acl *a_al; + afs_int32 a_plus; + char *a_name; + afs_int32 a_rights; -{ /*ChangeList*/ +{ /*ChangeList */ struct AclEntry *tlist; tlist = (a_plus ? a_al->pluslist : a_al->minuslist); tlist = FindList(tlist, a_name); if (tlist) { - /* + /* * Found the item already in the list. */ - tlist->rights = a_rights; - if (a_plus) - a_al->nplus -= PruneList(&a_al->pluslist); - else - a_al->nminus -= PruneList(&a_al->minuslist); - return; + tlist->rights = a_rights; + if (a_plus) + a_al->nplus -= PruneList(&a_al->pluslist); + else + a_al->nminus -= PruneList(&a_al->minuslist); + return; } /* * Otherwise, we make a new item and plug in the new data. */ - tlist = (struct AclEntry *) malloc(sizeof(struct AclEntry)); + tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry)); strcpy(tlist->name, a_name); tlist->rights = a_rights; if (a_plus) { - tlist->next = a_al->pluslist; - a_al->pluslist = tlist; - a_al->nplus++; - if (a_rights == 0) + tlist->next = a_al->pluslist; + a_al->pluslist = tlist; + a_al->nplus++; + if (a_rights == 0) a_al->nplus -= PruneList(&a_al->pluslist); - } - else { - tlist->next = a_al->minuslist; - a_al->minuslist = tlist; - a_al->nminus++; - if (a_rights == 0) + } else { + tlist->next = a_al->minuslist; + a_al->minuslist = tlist; + a_al->nminus++; + if (a_rights == 0) a_al->nminus -= PruneList(&a_al->minuslist); } -} /*ChangeList*/ +} /*ChangeList */ /*------------------------------------------------------------------------ @@ -303,10 +313,11 @@ static void ChangeList (a_al, a_plus, a_name, a_rights) * As advertised. *------------------------------------------------------------------------*/ -static int PruneList (a_aclPP) - struct AclEntry **a_aclPP; +static int +PruneList(a_aclPP) + struct AclEntry **a_aclPP; -{ /*PruneList*/ +{ /*PruneList */ struct AclEntry **lPP; struct AclEntry *tP, *nP; @@ -315,21 +326,20 @@ static int PruneList (a_aclPP) ctr = 0; lPP = a_aclPP; for (tP = *a_aclPP; tP; tP = nP) { - if (tP->rights == 0) { - *lPP = tP->next; - nP = tP->next; - free(tP); - ctr++; - } - else { - nP = tP->next; - lPP = &tP->next; + if (tP->rights == 0) { + *lPP = tP->next; + nP = tP->next; + free(tP); + ctr++; + } else { + nP = tP->next; + lPP = &tP->next; } } - return(ctr); + return (ctr); -} /*PruneList*/ +} /*PruneList */ /*------------------------------------------------------------------------ @@ -351,16 +361,18 @@ static int PruneList (a_aclPP) * As advertised. *------------------------------------------------------------------------*/ -static char *SkipLine(a_str) - register char *a_str; +static char * +SkipLine(a_str) + register char *a_str; -{ /*SkipLine*/ +{ /*SkipLine */ - while (*a_str !='\n') a_str++; + while (*a_str != '\n') + a_str++; a_str++; - return(a_str); + return (a_str); -} /*SkipLine*/ +} /*SkipLine */ /*------------------------------------------------------------------------ @@ -382,18 +394,18 @@ static char *SkipLine(a_str) * As advertised. *------------------------------------------------------------------------*/ -static struct Acl *EmptyAcl() - -{ /*EmptyAcl*/ +static struct Acl * +EmptyAcl() +{ /*EmptyAcl */ register struct Acl *tp; - tp = (struct Acl *) malloc(sizeof (struct Acl)); + tp = (struct Acl *)malloc(sizeof(struct Acl)); tp->nplus = tp->nminus = 0; tp->pluslist = tp->minuslist = 0; - return(tp); + return (tp); -} /*EmptyAcl*/ +} /*EmptyAcl */ /*------------------------------------------------------------------------ @@ -416,10 +428,11 @@ static struct Acl *EmptyAcl() * As advertised. *------------------------------------------------------------------------*/ -static struct Acl *ParseAcl(a_str) - char *a_str; +static struct Acl * +ParseAcl(a_str) + char *a_str; -{ /*ParseAcl*/ +{ /*ParseAcl */ int nplus, nminus, i, trights; char tname[MAXNAME]; @@ -438,7 +451,7 @@ static struct Acl *ParseAcl(a_str) /* * Allocate and initialize the first entry. */ - ta = (struct Acl *) malloc(sizeof (struct Acl)); + ta = (struct Acl *)malloc(sizeof(struct Acl)); ta->nplus = nplus; ta->nminus = nminus; @@ -447,18 +460,18 @@ static struct Acl *ParseAcl(a_str) */ last = 0; first = 0; - for(i = 0; i < nplus; i++) { - sscanf(a_str, "%100s %d", tname, &trights); - a_str = SkipLine(a_str); - tl = (struct AclEntry *) malloc(sizeof(struct AclEntry)); - if (!first) + for (i = 0; i < nplus; i++) { + sscanf(a_str, "%100s %d", tname, &trights); + a_str = SkipLine(a_str); + tl = (struct AclEntry *)malloc(sizeof(struct AclEntry)); + if (!first) first = tl; - strcpy(tl->name, tname); - tl->rights = trights; - tl->next = 0; - if (last) + strcpy(tl->name, tname); + tl->rights = trights; + tl->next = 0; + if (last) last->next = tl; - last = tl; + last = tl; } ta->pluslist = first; @@ -468,23 +481,23 @@ static struct Acl *ParseAcl(a_str) last = 0; first = 0; for (i = 0; i < nminus; i++) { - sscanf(a_str, "%100s %d", tname, &trights); - a_str = SkipLine(a_str); - tl = (struct AclEntry *) malloc(sizeof (struct AclEntry)); - if (!first) + sscanf(a_str, "%100s %d", tname, &trights); + a_str = SkipLine(a_str); + tl = (struct AclEntry *)malloc(sizeof(struct AclEntry)); + if (!first) first = tl; - strcpy(tl->name, tname); - tl->rights = trights; - tl->next = 0; - if (last) + strcpy(tl->name, tname); + tl->rights = trights; + tl->next = 0; + if (last) last->next = tl; - last = tl; + last = tl; } ta->minuslist = first; - return(ta); + return (ta); -} /*ParseAcl*/ +} /*ParseAcl */ /*------------------------------------------------------------------------ @@ -507,10 +520,11 @@ static struct Acl *ParseAcl(a_str) * As advertised. *------------------------------------------------------------------------*/ -static char *AclToString(a_acl) - struct Acl *a_acl; +static char * +AclToString(a_acl) + struct Acl *a_acl; -{ /*AclToString*/ +{ /*AclToString */ static char mydata[MAXSIZE]; char tstring[MAXSIZE]; @@ -525,20 +539,20 @@ static char *AclToString(a_acl) * Externalize the positive list. */ for (tp = a_acl->pluslist; tp; tp = tp->next) { - sprintf(tstring, "%s %d\n", tp->name, tp->rights); - strcat(mydata, tstring); + sprintf(tstring, "%s %d\n", tp->name, tp->rights); + strcat(mydata, tstring); } /* * Externalize the negative list. */ for (tp = a_acl->minuslist; tp; tp = tp->next) { - sprintf(tstring, "%s %d\n", tp->name, tp->rights); - strcat(mydata, tstring); + sprintf(tstring, "%s %d\n", tp->name, tp->rights); + strcat(mydata, tstring); } - return(mydata); + return (mydata); -} /*AclToString*/ +} /*AclToString */ /*------------------------------------------------------------------------ @@ -553,12 +567,13 @@ static char *AclToString(a_acl) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_acl_SetAccess(a_access, a_clear, a_negative) - char *a_access; - int a_clear; - int a_negative; +afs_int32 +uss_acl_SetAccess(a_access, a_clear, a_negative) + char *a_access; + int a_clear; + int a_negative; -{ /*uss_acl_SetAccess*/ +{ /*uss_acl_SetAccess */ register afs_int32 code; static char rn[] = "uss_acl_SetAccess"; @@ -578,10 +593,9 @@ afs_int32 uss_acl_SetAccess(a_access, a_clear, a_negative) tp = uss_common_FieldCp(path_field, a_access, ' ', sizeof(path_field), &overflow); if (overflow) { - fprintf(stderr, - "%s: * Pathname field too long (max is %d chars)\n", + fprintf(stderr, "%s: * Pathname field too long (max is %d chars)\n", uss_whoami, sizeof(path_field)); - return(-1); + return (-1); } /* @@ -590,18 +604,18 @@ afs_int32 uss_acl_SetAccess(a_access, a_clear, a_negative) */ code = uss_fs_GetACL(path_field, tmp_str, MAXSIZE); if (code) { - com_err(uss_whoami, code, - "while getting access list for %s", path_field); + com_err(uss_whoami, code, "while getting access list for %s", + path_field); #ifdef USS_ACL_DB - printf("%s: Error code from uss_fs_GetACL %d, errno %d\n", - rn, code, errno); + printf("%s: Error code from uss_fs_GetACL %d, errno %d\n", rn, code, + errno); #endif /* USS_ACL_DB */ - return(code); + return (code); } #ifdef USS_ACL_DB else - printf("%s: ACL for pathname '%s' is: '%s'\n", - rn, path_field, tmp_str); + printf("%s: ACL for pathname '%s' is: '%s'\n", rn, path_field, + tmp_str); #endif /* USS_ACL_DB */ /* @@ -616,25 +630,23 @@ afs_int32 uss_acl_SetAccess(a_access, a_clear, a_negative) * For each given entry, pull out the information and alter the * internalized ACL to reflect it. */ - while(*tp != '\0') { + while (*tp != '\0') { tp = uss_common_FieldCp(user_field, tp, ' ', 64, &overflow); if (overflow) { - fprintf(stderr, - "%s: * User field too long (max is 64 chars)\n", + fprintf(stderr, "%s: * User field too long (max is 64 chars)\n", uss_whoami); - return(-1); + return (-1); } if (*tp == '\0') { printf("%s: Missing second half of user/access pair.\n", uss_whoami); - return(1); + return (1); } tp = uss_common_FieldCp(rights_field, tp, ' ', 64, &overflow); if (overflow) { - fprintf(stderr, - "%s: * Rights field too long (max is 64 chars)\n", + fprintf(stderr, "%s: * Rights field too long (max is 64 chars)\n", uss_whoami); - return(-1); + return (-1); } rights = Convert(rights_field); ChangeList(ta, plusp, user_field, rights); @@ -645,30 +657,30 @@ afs_int32 uss_acl_SetAccess(a_access, a_clear, a_negative) * to the Cache Manager. */ externalizedACL = AclToString(ta); - code = uss_fs_SetACL(path_field, externalizedACL, - strlen(externalizedACL)+1); + code = + uss_fs_SetACL(path_field, externalizedACL, + strlen(externalizedACL) + 1); if (code) { #ifdef USS_ACL_DB - printf("%s: uss_fs_SetACL() failed, code is %d, errno is %d\n", - rn, code, errno); + printf("%s: uss_fs_SetACL() failed, code is %d, errno is %d\n", rn, + code, errno); #endif /* USS_ACL_DB */ if (errno == EINVAL) { - printf("Can't set ACL for directory '%s' to '%s'\n", - path_field, externalizedACL); + printf("Can't set ACL for directory '%s' to '%s'\n", path_field, + externalizedACL); printf("Invalid argument, possible reasons include:\n"); printf("\t1. File not in AFS, or\n"); printf("\t2. Too many users on the ACL, or\n"); printf("\t3. Non-existent user or group on ACL.\n"); - return(code); - } - else { + return (code); + } else { com_err(uss_whoami, code, "while setting the access list"); - return(code); + return (code); } } - return(0); + return (0); -} /*uss_acl_SetAccess*/ +} /*uss_acl_SetAccess */ /*------------------------------------------------------------------------ @@ -681,11 +693,12 @@ afs_int32 uss_acl_SetAccess(a_access, a_clear, a_negative) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_acl_SetDiskQuota(a_path, a_q) - char *a_path; - int a_q; +afs_int32 +uss_acl_SetDiskQuota(a_path, a_q) + char *a_path; + int a_q; -{ /*uss_acl_SetDiskQuota*/ +{ /*uss_acl_SetDiskQuota */ register afs_int32 code; static char rn[] = "uss_acl_SetDiskQuota"; @@ -699,29 +712,29 @@ afs_int32 uss_acl_SetDiskQuota(a_path, a_q) "Setting disk quota on volume mounted at '%s' to %d blocks\n", a_path, a_q); - status = (uss_VolumeStatus_t *)tmp_str; + status = (uss_VolumeStatus_t *) tmp_str; status->MinQuota = status->MaxQuota = -1; - name = motd = offmsg = (char *) 0; + name = motd = offmsg = NULL; status->MaxQuota = a_q; input = (char *)status + sizeof(*status); - *(input++) = '\0'; - *(input++) = '\0'; - *(input++) = '\0'; + *(input++) = '\0'; + *(input++) = '\0'; + *(input++) = '\0'; - code = uss_fs_SetVolStat(a_path, tmp_str, sizeof(*status)+3); + code = uss_fs_SetVolStat(a_path, tmp_str, sizeof(*status) + 3); if (code) { com_err(uss_whoami, code, "while setting disk quota"); #ifdef USS_ACL_DB - printf("%s: uss_fs_SetVolStat() error code: %d, errno is %d\n", - rn, code, errno); + printf("%s: uss_fs_SetVolStat() error code: %d, errno is %d\n", rn, + code, errno); #endif /* USS_ACL_DB */ - return(code); + return (code); } - return(0); + return (0); -} /*uss_acl_SetDiskQuota*/ +} /*uss_acl_SetDiskQuota */ /*----------------------------------------------------------------------- @@ -735,9 +748,9 @@ afs_int32 uss_acl_SetDiskQuota(a_path, a_q) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_acl_CleanUp() - -{ /*uss_acl_CleanUp*/ +afs_int32 +uss_acl_CleanUp() +{ /*uss_acl_CleanUp */ static char rn[] = "uss_acl_CleanUp"; struct uss_subdir *t, *old_t = NULL; @@ -755,21 +768,20 @@ afs_int32 uss_acl_CleanUp() if (!uss_DryRun) uss_acl_SetAccess(tmp_str, 1, 0); else - fprintf(stderr, - "\t[Dry run: uss_acl_SetAccess(%s) on '%s']\n", + fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s) on '%s']\n", tmp_str, t->path); free(t->path); if (old_t) free(old_t); old_t = t; - } /*Remove caller from user directory ACL*/ - + } /*Remove caller from user directory ACL */ + if (old_t) free(old_t); /* * Return successfully. */ - return(0); + return (0); -} /*uss_acl_CleanUp*/ +} /*uss_acl_CleanUp */ diff --git a/src/uss/uss_acl.h b/src/uss/uss_acl.h index 0c5b8da17..0b05249df 100644 --- a/src/uss/uss_acl.h +++ b/src/uss/uss_acl.h @@ -23,13 +23,13 @@ extern afs_int32 uss_acl_SetAccess(); * Set the value of the given ACL. * * Args: - * a_access : Ptr to the pathname & ACL to set. - * a_clear : Should we clear out the ACL first? - * a_negative : Set the negative list? + * a_access : Ptr to the pathname & ACL to set. + * a_clear : Should we clear out the ACL first? + * a_negative : Set the negative list? * * Returns: - * 0 if everything went well, - * Lower-level code otherwise. + * 0 if everything went well, + * Lower-level code otherwise. */ extern afs_int32 uss_acl_SetDiskQuota(); @@ -38,12 +38,12 @@ extern afs_int32 uss_acl_SetDiskQuota(); * Set the initial disk quota for a user. * * Args: - * a_path : Pathname for volume mountpoint. - * a_q : Quota value. + * a_path : Pathname for volume mountpoint. + * a_q : Quota value. * * Returns: - * 0 if everything went well, - * Lower-level code otherwise. + * 0 if everything went well, + * Lower-level code otherwise. */ extern afs_int32 uss_acl_CleanUp(); @@ -54,10 +54,10 @@ extern afs_int32 uss_acl_CleanUp(); * manipulation. * * Args: - * None. + * None. * * Returns: - * 0 (always) + * 0 (always) */ #endif /* _USS_ACL_H_ */ diff --git a/src/uss/uss_common.c b/src/uss/uss_common.c index 9fce72f8e..e2a9b25aa 100644 --- a/src/uss/uss_common.c +++ b/src/uss/uss_common.c @@ -18,10 +18,20 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_common.c,v 1.1.1.4 2001/07/14 22:24:13 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/uss/uss_common.c,v 1.6 2003/07/15 23:17:12 shadow Exp $"); -#include "uss_common.h" /*Interface definitions*/ -#include /*MAXKTCREALMLEN & MAXKTCNAMELEN*/ +#include "uss_common.h" /*Interface definitions */ +#include /*MAXKTCREALMLEN & MAXKTCNAMELEN */ + + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif /* @@ -30,58 +40,58 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_common.c,v 1.1.1.4 2001/07/14 2 #define uss_AutoLen 300 #define uss_NumVars 10 -char uss_User[uss_UserLen+1]; /*User's account name*/ -char uss_Uid[uss_UidLen+1]; /*User's uid*/ -char uss_Server[uss_ServerLen+1]; /*FileServer hosting user's volume*/ -char uss_Partition[uss_PartitionLen+1]; /*FileServer partition for above*/ -char uss_MountPoint[uss_MountPointLen+1]; /*Mountpoint for user's volume*/ -char uss_RealName[uss_RealNameLen+1]; /*User's full name*/ -char uss_Pwd[uss_PwdLen+1]; /*User password*/ -char uss_PwdPath[uss_PwdPathLen+1]; /*Curr pathname to password file*/ -char uss_PwdFormat[uss_PwdFormatLen+1]; /*Curr password entry format*/ -char uss_RestoreDir[uss_RestoreDirLen+1]; /*Curr directory for restore info*/ -char uss_Auto[uss_AutoLen+1]; /*Curr choice of AUTO value*/ -char uss_Var[uss_NumVars][uss_MAX_ARG_SIZE]; /*$1, $2, ... command variables*/ -int uss_VarMax = 0; /*Largest index in above*/ -char uss_Volume[uss_VolumeLen+1]; /*Name of user's volume*/ -afs_int32 uss_VolumeID; /*Numerical volume ID*/ -afs_int32 uss_ServerID; /*Numerical server ID*/ -afs_int32 uss_PartitionID; /*Numerical partition ID*/ -char uss_DirPool[100][uss_DirPoolLen]; /*List of all acceptable subdirs*/ +char uss_User[uss_UserLen + 1]; /*User's account name */ +char uss_Uid[uss_UidLen + 1]; /*User's uid */ +char uss_Server[uss_ServerLen + 1]; /*FileServer hosting user's volume */ +char uss_Partition[uss_PartitionLen + 1]; /*FileServer partition for above */ +char uss_MountPoint[uss_MountPointLen + 1]; /*Mountpoint for user's volume */ +char uss_RealName[uss_RealNameLen + 1]; /*User's full name */ +char uss_Pwd[uss_PwdLen + 1]; /*User password */ +char uss_PwdPath[uss_PwdPathLen + 1]; /*Curr pathname to password file */ +char uss_PwdFormat[uss_PwdFormatLen + 1]; /*Curr password entry format */ +char uss_RestoreDir[uss_RestoreDirLen + 1]; /*Curr directory for restore info */ +char uss_Auto[uss_AutoLen + 1]; /*Curr choice of AUTO value */ +char uss_Var[uss_NumVars][uss_MAX_ARG_SIZE]; /*$1, $2, ... command variables */ +int uss_VarMax = 0; /*Largest index in above */ +char uss_Volume[uss_VolumeLen + 1]; /*Name of user's volume */ +afs_int32 uss_VolumeID; /*Numerical volume ID */ +afs_int32 uss_ServerID; /*Numerical server ID */ +afs_int32 uss_PartitionID; /*Numerical partition ID */ +char uss_DirPool[100][uss_DirPoolLen]; /*List of all acceptable subdirs */ /* * Values saved across invocations. */ -char uss_PwdPath_Saved[uss_PwdPathLen]; /*Pathname to saved pwd file*/ -char uss_PwdFormat_Saved[uss_PwdFormatLen]; /*Saved pwd entry format*/ -char uss_RestoreDir_Saved[uss_RestoreDirLen]; /*Saved dir for restore info*/ - -int uss_NumGroups = 0; /*Number of $AUTO entries*/ -int uss_SaveVolume; /*Save current user volume?*/ -int uss_SaveVolume_Saved; /*Saved value of above*/ -int uss_DryRun = 0; /*Is this a dry run?*/ -int uss_SkipKaserver = 0; /*Don't talk to kaserver*/ -int uss_Overwrite = 0; /*Overwrite user files?*/ -int uss_OverwriteThisOne; /*Overwrite on this pass?*/ -char uss_Administrator[64]; /*Name of admin account*/ -char uss_AccountCreator[MAXKTCNAMELEN]; /*Principal running this program*/ -afs_int32 uss_DesiredUID; /*Uid to assign the user*/ -afs_int32 uss_Expires; /*How long between password expires*/ -char uss_Cell[MAXKTCREALMLEN]; /*Cell in which account lives*/ -char uss_ConfDir[uss_PATH_SIZE]; /*Config directory*/ -int uss_verbose = 0; /*Are we being verbose?*/ -int uss_ignoreFlag = 0; /*Ignore yyparse errors?*/ +char uss_PwdPath_Saved[uss_PwdPathLen]; /*Pathname to saved pwd file */ +char uss_PwdFormat_Saved[uss_PwdFormatLen]; /*Saved pwd entry format */ +char uss_RestoreDir_Saved[uss_RestoreDirLen]; /*Saved dir for restore info */ + +int uss_NumGroups = 0; /*Number of $AUTO entries */ +int uss_SaveVolume; /*Save current user volume? */ +int uss_SaveVolume_Saved; /*Saved value of above */ +int uss_DryRun = 0; /*Is this a dry run? */ +int uss_SkipKaserver = 0; /*Don't talk to kaserver */ +int uss_Overwrite = 0; /*Overwrite user files? */ +int uss_OverwriteThisOne; /*Overwrite on this pass? */ +char uss_Administrator[64]; /*Name of admin account */ +char uss_AccountCreator[MAXKTCNAMELEN]; /*Principal running this program */ +afs_int32 uss_DesiredUID; /*Uid to assign the user */ +afs_int32 uss_Expires; /*How long between password expires */ +char uss_Cell[MAXKTCREALMLEN]; /*Cell in which account lives */ +char uss_ConfDir[uss_PATH_SIZE]; /*Config directory */ +int uss_verbose = 0; /*Are we being verbose? */ +int uss_ignoreFlag = 0; /*Ignore yyparse errors? */ int uss_perr = 0; -char uss_whoami[64]; /*Program name used*/ -int uss_syntax_err = 0; /*YACC syntax error?*/ -struct uss_subdir *uss_currentDir = NULL; /*Current directory*/ +char uss_whoami[64]; /*Program name used */ +int uss_syntax_err = 0; /*YACC syntax error? */ +struct uss_subdir *uss_currentDir = NULL; /*Current directory */ /* * ----------------------- Private variables ---------------------- */ -static int initDone = 0; /*Have we been initialized?*/ +static int initDone = 0; /*Have we been initialized? */ /*------------------------------------------------------------------------ @@ -103,24 +113,24 @@ static int initDone = 0; /*Have we been initialized?*/ * As advertised. *------------------------------------------------------------------------*/ -void uss_common_Init() - -{ /*uss_common_Init*/ +void +uss_common_Init() +{ /*uss_common_Init */ - extern int line; /*Current template line*/ + extern int line; /*Current template line */ if (initDone) return; strcpy(uss_ConfDir, AFSDIR_CLIENT_ETC_DIRPATH); - uss_PwdPath_Saved[0]= '\0'; - uss_PwdFormat_Saved[0]= '\0'; - uss_RestoreDir_Saved[0]= '\0'; + uss_PwdPath_Saved[0] = '\0'; + uss_PwdFormat_Saved[0] = '\0'; + uss_RestoreDir_Saved[0] = '\0'; uss_SaveVolume_Saved = 0; uss_syntax_err = 0; line = 1; -} /*uss_common_Init*/ +} /*uss_common_Init */ /*------------------------------------------------------------------------ @@ -143,12 +153,12 @@ void uss_common_Init() * As advertised. *------------------------------------------------------------------------*/ -void uss_common_Reset() +void +uss_common_Reset() +{ /*uss_common_Reset */ -{ /*uss_common_Reset*/ - - extern int line; /*Current template line*/ - int i; /*Loop variable*/ + extern int line; /*Current template line */ + int i; /*Loop variable */ uss_ignoreFlag = 0; uss_NumGroups = 0; @@ -156,19 +166,19 @@ void uss_common_Reset() uss_currentDir = NULL; uss_DesiredUID = 0; uss_VarMax = 0; - uss_User[0]= '\0'; - uss_Uid[0]= '\0'; - uss_Server[0]= '\0'; - uss_Partition[0]= '\0'; - uss_MountPoint[0]= '\0'; - uss_RealName[0]= '\0'; + uss_User[0] = '\0'; + uss_Uid[0] = '\0'; + uss_Server[0] = '\0'; + uss_Partition[0] = '\0'; + uss_MountPoint[0] = '\0'; + uss_RealName[0] = '\0'; sprintf(uss_Pwd, "%s", uss_DEFAULT_PASSWORD); strcpy(uss_PwdPath, uss_PwdPath_Saved); strcpy(uss_PwdFormat, uss_PwdFormat_Saved); strcpy(uss_RestoreDir, uss_RestoreDir_Saved); uss_SaveVolume = uss_SaveVolume_Saved; - uss_Auto[0]= '\0'; - for(i = 1; i < 10; i++) + uss_Auto[0] = '\0'; + for (i = 1; i < 10; i++) uss_Var[i][0] = '\0'; /* @@ -179,7 +189,7 @@ void uss_common_Reset() line = 1; uss_syntax_err = 0; -} /*uss_common_Reset*/ +} /*uss_common_Reset */ /*------------------------------------------------------------------------ @@ -192,16 +202,17 @@ void uss_common_Reset() * As advertised. *------------------------------------------------------------------------*/ -char *uss_common_FieldCp(a_to, a_from, a_separator, a_maxChars, a_overflowP) - char *a_to; - char *a_from; - char a_separator; - int a_maxChars; - int *a_overflowP; - -{ /*uss_common_FieldCp*/ +char * +uss_common_FieldCp(a_to, a_from, a_separator, a_maxChars, a_overflowP) + char *a_to; + char *a_from; + char a_separator; + int a_maxChars; + int *a_overflowP; + +{ /*uss_common_FieldCp */ - register int chars_read; /*Number of chars read so far*/ + register int chars_read; /*Number of chars read so far */ chars_read = 0; *a_overflowP = 0; @@ -211,9 +222,7 @@ char *uss_common_FieldCp(a_to, a_from, a_separator, a_maxChars, a_overflowP) */ a_maxChars++; - while (*a_from != a_separator && - *a_from != '\0' && - *a_from != '\n') { + while (*a_from != a_separator && *a_from != '\0' && *a_from != '\n') { *a_to++ = *a_from++; if (++chars_read >= a_maxChars) { /* @@ -225,21 +234,18 @@ char *uss_common_FieldCp(a_to, a_from, a_separator, a_maxChars, a_overflowP) *a_overflowP = 1; a_to--; #if 0 - printf("*** Skipping overflow char '%c'\n", - *(a_from-1)); + printf("*** Skipping overflow char '%c'\n", *(a_from - 1)); #endif /* 0 */ - while (*a_from != a_separator && - *a_from != '\0' && - *a_from != '\n') { + while (*a_from != a_separator && *a_from != '\0' + && *a_from != '\n') { #if 0 - printf("*** Skipping overflow char '%c'\n", - *a_from); + printf("*** Skipping overflow char '%c'\n", *a_from); #endif /* 0 */ a_from++; - } /*Skip over excess chars*/ + } /*Skip over excess chars */ break; - } /*Found overflow*/ - } /*Read til end of field*/ + } /*Found overflow */ + } /*Read til end of field */ /* * Make sure we return a null-terminated string. @@ -251,7 +257,7 @@ char *uss_common_FieldCp(a_to, a_from, a_separator, a_maxChars, a_overflowP) * to one. */ if (a_separator == ' ') - while((*a_from == ' ') && (*(a_from+1) == ' ')) + while ((*a_from == ' ') && (*(a_from + 1) == ' ')) a_from++; /* @@ -259,8 +265,8 @@ char *uss_common_FieldCp(a_to, a_from, a_separator, a_maxChars, a_overflowP) * the position of the null, if that's what was left. */ if (*a_from == '\0') - return(a_from); + return (a_from); else - return(++a_from); + return (++a_from); -} /*uss_common_FieldCp*/ +} /*uss_common_FieldCp */ diff --git a/src/uss/uss_common.h b/src/uss/uss_common.h index 7477e61e9..3b2f4ec40 100644 --- a/src/uss/uss_common.h +++ b/src/uss/uss_common.h @@ -19,8 +19,8 @@ /* * --------------------- Required definitions --------------------- */ -#include /*Ditto*/ -#include /*I/O stuff*/ +#include /*Ditto */ +#include /*I/O stuff */ #include #include #ifdef HAVE_STRING_H @@ -31,7 +31,6 @@ #endif #endif - /* * --------------------- Exported definitions --------------------- */ @@ -67,7 +66,7 @@ #define uss_VolumeLen 300 #define uss_DirPoolLen 300 -#if !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) extern char *sys_errlist[]; #endif @@ -77,9 +76,9 @@ extern char *sys_errlist[]; * access to each directory. */ struct uss_subdir { - struct uss_subdir *previous; /*Back ptr*/ - char *path; /*Pathname to dir*/ - char *finalACL; /*Final ACL for dir*/ + struct uss_subdir *previous; /*Back ptr */ + char *path; /*Pathname to dir */ + char *finalACL; /*Final ACL for dir */ }; /* @@ -107,46 +106,46 @@ typedef struct uss_VolumeStatus uss_VolumeStatus_t; /* * ---------------------- Exported variables ---------------------- */ -extern char uss_User[]; /*User's account name*/ -extern char uss_Uid[]; /*User's uid*/ -extern char uss_Server[]; /*FileServer hosting user's volume*/ -extern char uss_Partition[]; /*FileServer partition for above*/ -extern char uss_MountPoint[]; /*Mountpoint for user's volume*/ -extern char uss_RealName[]; /*User's full name*/ -extern char uss_Pwd[]; /*User's password*/ -extern char uss_PwdPath[]; /*Current pathname to password file*/ -extern char uss_PwdPath_Saved[]; /*Saved pathname to password file*/ -extern char uss_PwdFormat[]; /*Current password entry format*/ -extern char uss_PwdFormat_Saved[]; /*Saved password entry format*/ -extern char uss_RestoreDir[]; /*Current directory for restore info*/ -extern char uss_RestoreDir_Saved[]; /*Saved directory for restore info*/ -extern char uss_Auto[]; /*Current choice of AUTO value*/ -extern char uss_Var[][uss_MAX_ARG_SIZE]; /*$1, $2, ... command variables*/ -extern int uss_VarMax; /*Largest index in above*/ -extern char uss_Volume[]; /*Name of user's volume*/ -extern afs_int32 uss_VolumeID; /*Numerical volume ID*/ -extern afs_int32 uss_ServerID; /*Numerical server ID*/ -extern afs_int32 uss_PartitionID; /*Numerical partition ID*/ -extern char uss_DirPool[][uss_DirPoolLen]; /*List of all acceptable subdirs*/ - -extern int uss_NumGroups; /*Number of $AUTO entries*/ -extern int uss_SaveVolume; /*Save current user volume?*/ -extern int uss_SaveVolume_Saved; /*Saved value of above*/ -extern int uss_DryRun; /*Is this a dry run?*/ -extern int uss_Overwrite; /*Overwrite user files?*/ -extern int uss_SkipKaserver; /*Ignore calls to Kaserver*/ -extern int uss_OverwriteThisOne; /*Overwrite on this pass?*/ -extern char uss_Administrator[]; /*Name of admin account*/ -extern char uss_AccountCreator[]; /*Principal running this program*/ -extern afs_int32 uss_DesiredUID; /*UID to assign the user*/ -extern afs_int32 uss_Expires; /*Password lifetime*/ -extern char uss_Cell[]; /*Cell in which account lives*/ -extern char uss_ConfDir[]; /*Config directory*/ -extern int uss_verbose; /*Should we be verbose?*/ -extern int uss_ignoreFlag; /*Ignore yyparse errors?*/ -extern char uss_whoami[]; /*Program name used*/ -extern int uss_syntax_err; /*YACC syntax error?*/ -extern struct uss_subdir *uss_currentDir; /*Current directory*/ +extern char uss_User[]; /*User's account name */ +extern char uss_Uid[]; /*User's uid */ +extern char uss_Server[]; /*FileServer hosting user's volume */ +extern char uss_Partition[]; /*FileServer partition for above */ +extern char uss_MountPoint[]; /*Mountpoint for user's volume */ +extern char uss_RealName[]; /*User's full name */ +extern char uss_Pwd[]; /*User's password */ +extern char uss_PwdPath[]; /*Current pathname to password file */ +extern char uss_PwdPath_Saved[]; /*Saved pathname to password file */ +extern char uss_PwdFormat[]; /*Current password entry format */ +extern char uss_PwdFormat_Saved[]; /*Saved password entry format */ +extern char uss_RestoreDir[]; /*Current directory for restore info */ +extern char uss_RestoreDir_Saved[]; /*Saved directory for restore info */ +extern char uss_Auto[]; /*Current choice of AUTO value */ +extern char uss_Var[][uss_MAX_ARG_SIZE]; /*$1, $2, ... command variables */ +extern int uss_VarMax; /*Largest index in above */ +extern char uss_Volume[]; /*Name of user's volume */ +extern afs_int32 uss_VolumeID; /*Numerical volume ID */ +extern afs_int32 uss_ServerID; /*Numerical server ID */ +extern afs_int32 uss_PartitionID; /*Numerical partition ID */ +extern char uss_DirPool[][uss_DirPoolLen]; /*List of all acceptable subdirs */ + +extern int uss_NumGroups; /*Number of $AUTO entries */ +extern int uss_SaveVolume; /*Save current user volume? */ +extern int uss_SaveVolume_Saved; /*Saved value of above */ +extern int uss_DryRun; /*Is this a dry run? */ +extern int uss_Overwrite; /*Overwrite user files? */ +extern int uss_SkipKaserver; /*Ignore calls to Kaserver */ +extern int uss_OverwriteThisOne; /*Overwrite on this pass? */ +extern char uss_Administrator[]; /*Name of admin account */ +extern char uss_AccountCreator[]; /*Principal running this program */ +extern afs_int32 uss_DesiredUID; /*UID to assign the user */ +extern afs_int32 uss_Expires; /*Password lifetime */ +extern char uss_Cell[]; /*Cell in which account lives */ +extern char uss_ConfDir[]; /*Config directory */ +extern int uss_verbose; /*Should we be verbose? */ +extern int uss_ignoreFlag; /*Ignore yyparse errors? */ +extern char uss_whoami[]; /*Program name used */ +extern int uss_syntax_err; /*YACC syntax error? */ +extern struct uss_subdir *uss_currentDir; /*Current directory */ /* @@ -156,44 +155,44 @@ extern void uss_common_Init(); /* * Summary: * Set up various common uss variables, especially the saved - * ones. + * ones. * * Args: - * None. + * None. * * Returns: - * Nothing. + * Nothing. */ extern void uss_common_Reset(); /* * Summary: * Reset some common uss variables to their idle or - * saved states. + * saved states. * * Args: - * None. + * None. * * Returns: - * Nothing. + * Nothing. */ extern char *uss_common_FieldCp(); /* * Summary: * Copy a ``field'', as terminated by the given separator, or - * up to a certain specified length. Gripe if there was an - * overflow. + * up to a certain specified length. Gripe if there was an + * overflow. * * Args: - * char *a_to : Destination of the copy. - * char *a_from : Source of the copy. - * char a_separator : Separator character to look for. - * int a_maxChars : Max chars to copy. - * int *a_overflowP : Was there an overflow? + * char *a_to : Destination of the copy. + * char *a_from : Source of the copy. + * char a_separator : Separator character to look for. + * int a_maxChars : Max chars to copy. + * int *a_overflowP : Was there an overflow? * * Returns: - * Ptr to the next location to read from. + * Ptr to the next location to read from. */ #endif /* _USS_COMMON_H_ */ diff --git a/src/uss/uss_fs.c b/src/uss/uss_fs.c index c4a9a0767..6e2277db2 100644 --- a/src/uss/uss_fs.c +++ b/src/uss/uss_fs.c @@ -18,23 +18,30 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_fs.c,v 1.2 2003/01/02 03:55:51 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/uss/uss_fs.c,v 1.8 2003/07/15 23:17:12 shadow Exp $"); -#include "uss_fs.h" /*Interface to this module*/ +#include "uss_fs.h" /*Interface to this module */ #include -#include +#include #include -#include #ifdef AFS_SUN5_ENV #include #endif -#include #include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include "uss_common.h" - /* * ---------------------- Private definitions --------------------- */ @@ -44,8 +51,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_fs.c,v 1.2 2003/01/02 03:55:51 /* * ------------------------ Private globals ----------------------- */ -static struct ViceIoctl blob; /*Param-passing area*/ -static struct ViceIoctl *blobP = &blob; /*Ptr to above*/ +static struct ViceIoctl blob; /*Param-passing area */ +static struct ViceIoctl *blobP = &blob; /*Ptr to above */ /*------------------------------------------------------------------------ @@ -68,27 +75,28 @@ static struct ViceIoctl *blobP = &blob; /*Ptr to above*/ * As advertised. *------------------------------------------------------------------------*/ -static int InAFS(a_path) - register char *a_path; +static int +InAFS(a_path) + register char *a_path; -{ /*InAFS*/ +{ /*InAFS */ static char rn[] = "uss_fs:InAFS"; register afs_int32 code; - blob.in = (char *)0; - blob.in_size = 0; + blob.in = NULL; + blob.in_size = 0; blob.out_size = USS_FS_MAX_SIZE; - blob.out = uss_fs_OutBuff; + blob.out = uss_fs_OutBuff; code = pioctl(a_path, VIOC_FILE_CELL_NAME, blobP, 1); if (code) { if ((errno == EINVAL) || (errno == ENOENT)) - return(0); + return (0); } - return(1); + return (1); -} /*InAFS*/ +} /*InAFS */ /*------------------------------------------------------------------------ @@ -114,12 +122,13 @@ static int InAFS(a_path) * As advertised. *------------------------------------------------------------------------*/ -static char *ParentAndComponent(a_path, a_parentBuff, a_componentPP) - char *a_path; - char *a_parentBuff; - char **a_componentPP; +static char * +ParentAndComponent(a_path, a_parentBuff, a_componentPP) + char *a_path; + char *a_parentBuff; + char **a_componentPP; -{ /*ParentAndComponent*/ +{ /*ParentAndComponent */ static char rn[] = "uss_fs:Parent"; char *rightSlashP; @@ -132,19 +141,18 @@ static char *ParentAndComponent(a_path, a_parentBuff, a_componentPP) * we cheat and return ``.''. */ strcpy(a_parentBuff, a_path); - rightSlashP = (char *) strrchr(a_parentBuff, '/'); + rightSlashP = (char *)strrchr(a_parentBuff, '/'); if (rightSlashP) { *rightSlashP = 0; - *a_componentPP = rightSlashP+1; - } - else { + *a_componentPP = rightSlashP + 1; + } else { strcpy(a_parentBuff, "."); *a_componentPP = a_path; } - return(a_parentBuff); + return (a_parentBuff); -} /*ParentAndComponent*/ +} /*ParentAndComponent */ /*------------------------------------------------------------------------ @@ -172,13 +180,14 @@ static char *ParentAndComponent(a_path, a_parentBuff, a_componentPP) * As advertised. *------------------------------------------------------------------------*/ -static int CarefulPioctl(a_path, a_opcode, a_blobP, a_sl) - char *a_path; - int a_opcode; - struct ViceIoctl *a_blobP; - int a_sl; +static int +CarefulPioctl(a_path, a_opcode, a_blobP, a_sl) + char *a_path; + int a_opcode; + struct ViceIoctl *a_blobP; + int a_sl; -{ /*CarefulPioctl*/ +{ /*CarefulPioctl */ static char rn[] = "uss_fs:CarefulPioctl"; register afs_int32 code; @@ -193,11 +202,10 @@ static int CarefulPioctl(a_path, a_opcode, a_blobP, a_sl) code = pioctl(a_path, a_opcode, a_blobP, a_sl); #ifdef USS_FS_DB if (code) - printf("%s: First pioctl call fails, errno is %d\n", - rn, errno); + printf("%s: First pioctl call fails, errno is %d\n", rn, errno); #endif /* USS_FS_DB */ if ((code == 0) || (code && (errno != ENODEV))) - return(code); + return (code); /* * Hmm, it's possible out volume mappings are stale. Let's @@ -208,9 +216,9 @@ static int CarefulPioctl(a_path, a_opcode, a_blobP, a_sl) #endif /* USS_FS_DB */ code = uss_fs_CkBackups(); code = pioctl(a_path, a_opcode, a_blobP, a_sl); - return(code); + return (code); -} /*CarefulPioctl*/ +} /*CarefulPioctl */ /*------------------------------------------------------------------------ @@ -223,24 +231,25 @@ static int CarefulPioctl(a_path, a_opcode, a_blobP, a_sl) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_fs_GetACL(a_dirPath, a_aclBuff, a_aclBuffBytes) - char *a_dirPath; - char *a_aclBuff; - afs_int32 a_aclBuffBytes; +afs_int32 +uss_fs_GetACL(a_dirPath, a_aclBuff, a_aclBuffBytes) + char *a_dirPath; + char *a_aclBuff; + afs_int32 a_aclBuffBytes; -{ /*uss_fs_GetACL*/ +{ /*uss_fs_GetACL */ - static char rn[] = "uss_fs_GetACL"; /*Routine name*/ - register afs_int32 code; /*pioctl() result*/ + static char rn[] = "uss_fs_GetACL"; /*Routine name */ + register afs_int32 code; /*pioctl() result */ - blob.in = (char *)0; - blob.in_size = 0; - blob.out = a_aclBuff; + blob.in = NULL; + blob.in_size = 0; + blob.out = a_aclBuff; blob.out_size = a_aclBuffBytes; #ifdef USS_FS_DB - printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", - rn, blob.in, blob.in_size, blob.out, blob.out_size); + printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in, + blob.in_size, blob.out, blob.out_size); #endif /* USS_FS_DB */ code = CarefulPioctl(a_dirPath, VIOCGETAL, blobP, 1); @@ -250,9 +259,9 @@ afs_int32 uss_fs_GetACL(a_dirPath, a_aclBuff, a_aclBuffBytes) printf("%s: pioctl() failed, errno %d\n", rn, errno); #endif /* USS_FS_DB */ - return(code); + return (code); -} /*uss_fs_GetACL*/ +} /*uss_fs_GetACL */ /*------------------------------------------------------------------------ @@ -265,26 +274,26 @@ afs_int32 uss_fs_GetACL(a_dirPath, a_aclBuff, a_aclBuffBytes) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_fs_SetACL(a_dirPath, a_aclBuff, a_aclBuffBytes) - char *a_dirPath; - char *a_aclBuff; - afs_int32 a_aclBuffBytes; +afs_int32 +uss_fs_SetACL(a_dirPath, a_aclBuff, a_aclBuffBytes) + char *a_dirPath; + char *a_aclBuff; + afs_int32 a_aclBuffBytes; -{ /*uss_fs_SetACL*/ +{ /*uss_fs_SetACL */ - static char rn[] = "uss_fs_SetACL"; /*Routine name*/ - register afs_int32 code; /*pioctl() result*/ + static char rn[] = "uss_fs_SetACL"; /*Routine name */ + register afs_int32 code; /*pioctl() result */ - blob.in = a_aclBuff; - blob.in_size = a_aclBuffBytes; - blob.out = (char *)0; + blob.in = a_aclBuff; + blob.in_size = a_aclBuffBytes; + blob.out = NULL; blob.out_size = 0; #ifdef USS_FS_DB - printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", - rn, blob.in, blob.in_size, blob.out, blob.out_size); - printf("%s: ACL value for dir '%s' is '%s'\n", - rn, a_dirPath, a_aclBuff); + printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in, + blob.in_size, blob.out, blob.out_size); + printf("%s: ACL value for dir '%s' is '%s'\n", rn, a_dirPath, a_aclBuff); #endif /* USS_FS_DB */ code = CarefulPioctl(a_dirPath, VIOCSETAL, blobP, 1); @@ -294,9 +303,9 @@ afs_int32 uss_fs_SetACL(a_dirPath, a_aclBuff, a_aclBuffBytes) printf("%s: pioctl() failed, errno %d", rn, errno); #endif /* USS_FS_DB */ - return(code); + return (code); -} /*uss_fs_SetACL*/ +} /*uss_fs_SetACL */ /*------------------------------------------------------------------------ @@ -309,24 +318,25 @@ afs_int32 uss_fs_SetACL(a_dirPath, a_aclBuff, a_aclBuffBytes) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_fs_GetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes) - char *a_mountpoint; - char *a_volStatBuff; - afs_int32 a_volStatBuffBytes; +afs_int32 +uss_fs_GetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes) + char *a_mountpoint; + char *a_volStatBuff; + afs_int32 a_volStatBuffBytes; -{ /*uss_fs_GetVolStat*/ +{ /*uss_fs_GetVolStat */ - static char rn[] = "uss_fs_GetVolStat"; /*Routine name*/ - register afs_int32 code; /*pioctl() result*/ + static char rn[] = "uss_fs_GetVolStat"; /*Routine name */ + register afs_int32 code; /*pioctl() result */ - blob.in = (char *)0; - blob.in_size = 0; - blob.out = a_volStatBuff; + blob.in = NULL; + blob.in_size = 0; + blob.out = a_volStatBuff; blob.out_size = a_volStatBuffBytes; #ifdef USS_FS_DB - printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", - rn, blob.in, blob.in_size, blob.out, blob.out_size); + printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in, + blob.in_size, blob.out, blob.out_size); #endif /* USS_FS_DB */ code = CarefulPioctl(a_mountpoint, VIOCGETVOLSTAT, blobP, 1); @@ -336,9 +346,9 @@ afs_int32 uss_fs_GetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes) printf("%s: pioctl() failed, errno %d", rn, errno); #endif /* USS_FS_DB */ - return(code); + return (code); -} /*uss_fs_GetVolStat*/ +} /*uss_fs_GetVolStat */ /*------------------------------------------------------------------------ @@ -351,24 +361,25 @@ afs_int32 uss_fs_GetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_fs_SetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes) - char *a_mountpoint; - char *a_volStatBuff; - afs_int32 a_volStatBuffBytes; +afs_int32 +uss_fs_SetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes) + char *a_mountpoint; + char *a_volStatBuff; + afs_int32 a_volStatBuffBytes; -{ /*uss_fs_SetVolStat*/ +{ /*uss_fs_SetVolStat */ - static char rn[] = "uss_fs_SetVolStat"; /*Routine name*/ - register afs_int32 code; /*pioctl() result*/ + static char rn[] = "uss_fs_SetVolStat"; /*Routine name */ + register afs_int32 code; /*pioctl() result */ - blob.in = a_volStatBuff; - blob.in_size = a_volStatBuffBytes; - blob.out = a_volStatBuff; + blob.in = a_volStatBuff; + blob.in_size = a_volStatBuffBytes; + blob.out = a_volStatBuff; blob.out_size = USS_FS_MAX_SIZE; #ifdef USS_FS_DB - printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", - rn, blob.in, blob.in_size, blob.out, blob.out_size); + printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in, + blob.in_size, blob.out, blob.out_size); #endif /* USS_FS_DB */ code = CarefulPioctl(a_mountpoint, VIOCSETVOLSTAT, blobP, 1); @@ -378,9 +389,9 @@ afs_int32 uss_fs_SetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes) printf("%s: pioctl() failed, errno %d", rn, errno); #endif /* USS_FS_DB */ - return(code); + return (code); -} /*uss_fs_SetVolStat*/ +} /*uss_fs_SetVolStat */ /*------------------------------------------------------------------------ @@ -393,35 +404,35 @@ afs_int32 uss_fs_SetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_fs_CkBackups() +afs_int32 +uss_fs_CkBackups() +{ /*uss_fs_CkBackups */ -{ /*uss_fs_CkBackups*/ + static char rn[] = "uss_fs_CkBackups"; /*Routine name */ + register afs_int32 code; /*pioctl() result */ - static char rn[] = "uss_fs_CkBackups"; /*Routine name*/ - register afs_int32 code; /*pioctl() result*/ - - blob.in = (char *)0; - blob.in_size = 0; - blob.out = (char *)0; + blob.in = NULL; + blob.in_size = 0; + blob.out = NULL; blob.out_size = 0; - + #ifdef USS_FS_DB - printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", - rn, blob.in, blob.in_size, blob.out, blob.out_size); + printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in, + blob.in_size, blob.out, blob.out_size); #endif /* USS_FS_DB */ - code = pioctl((char *)0, /*No pathname needed here*/ - VIOCCKBACK, /*CheckBackups*/ - &blob, /*Params*/ - 1); /*Symlink disposition*/ + code = pioctl(NULL, /*No pathname needed here */ + VIOCCKBACK, /*CheckBackups */ + &blob, /*Params */ + 1); /*Symlink disposition */ #ifdef USS_FS_DB if (code) printf("%s: pioctl() failed, errno %d", rn, errno); #endif /* USS_FS_DB */ - return(code); + return (code); -} /*uss_fs_CkBackups*/ +} /*uss_fs_CkBackups */ /*------------------------------------------------------------------------ @@ -434,21 +445,23 @@ afs_int32 uss_fs_CkBackups() * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_fs_MkMountPoint(a_volname, a_cellname, a_rw, a_mountpoint) - char *a_volname; - char *a_cellname; - afs_int32 a_rw; - char *a_mountpoint; +afs_int32 +uss_fs_MkMountPoint(a_volname, a_cellname, a_rw, a_mountpoint) + char *a_volname; + char *a_cellname; + afs_int32 a_rw; + char *a_mountpoint; -{ /*uss_fs_MkMountPoint*/ +{ /*uss_fs_MkMountPoint */ extern int local_Cell; - static char rn[] = "uss_fs_MkMountPoint"; /*Routine name*/ - register afs_int32 code; /*pioctl() result*/ - char *tp; /*Temporary*/ + static char rn[] = "uss_fs_MkMountPoint"; /*Routine name */ + register afs_int32 code; /*pioctl() result */ + char *tp; /*Temporary */ #ifdef USS_FS_DB - printf("%s: a_volname='%s', a_cellname='%s', a_rw=%d, a_mountpoint='%s'\n", - rn, a_volname, a_cellname, a_rw, a_mountpoint); + printf + ("%s: a_volname='%s', a_cellname='%s', a_rw=%d, a_mountpoint='%s'\n", + rn, a_volname, a_cellname, a_rw, a_mountpoint); #endif /* USS_FS_DB */ /* @@ -456,7 +469,7 @@ afs_int32 uss_fs_MkMountPoint(a_volname, a_cellname, a_rw, a_mountpoint) */ if (!InAFS(ParentAndComponent(a_mountpoint, uss_fs_OutBuff, &tp))) { printf("%s: Mountpoints must be created within AFS\n", rn); - return(-1); + return (-1); } /* @@ -465,13 +478,9 @@ afs_int32 uss_fs_MkMountPoint(a_volname, a_cellname, a_rw, a_mountpoint) * char, by convention, is a dot. */ if (local_Cell) { - sprintf(uss_fs_OutBuff, "%s%s.", - (a_rw ? "%" : "#"), - a_volname); + sprintf(uss_fs_OutBuff, "%s%s.", (a_rw ? "%" : "#"), a_volname); } else { - sprintf(uss_fs_OutBuff, "%s%s:%s.", - (a_rw ? "%" : "#"), - a_cellname, + sprintf(uss_fs_OutBuff, "%s%s:%s.", (a_rw ? "%" : "#"), a_cellname, a_volname); } @@ -481,13 +490,13 @@ afs_int32 uss_fs_MkMountPoint(a_volname, a_cellname, a_rw, a_mountpoint) code = symlink(uss_fs_OutBuff, a_mountpoint); if (code) { #ifdef USS_FS_DB - printf("%s: Mountpoint creation (symlink) failed, errno is %d\n", - rn, errno); + printf("%s: Mountpoint creation (symlink) failed, errno is %d\n", rn, + errno); #endif /* USS_FS_DB */ - return(-1); + return (-1); } -} /*uss_fs_MkMountPoint*/ +} /*uss_fs_MkMountPoint */ /*------------------------------------------------------------------------ @@ -500,26 +509,25 @@ afs_int32 uss_fs_MkMountPoint(a_volname, a_cellname, a_rw, a_mountpoint) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_fs_RmMountPoint(a_mountpoint) - char *a_mountpoint; +afs_int32 +uss_fs_RmMountPoint(a_mountpoint) + char *a_mountpoint; -{ /*uss_fs_RmMountPoint*/ +{ /*uss_fs_RmMountPoint */ - static char rn[] = "uss_fs_RmMountPoint"; /*Routine name*/ - register afs_int32 code; /*pioctl() result*/ - char *parentDirP; /*Ptr to parent*/ - char *componentP; /*Ptr to last component*/ + static char rn[] = "uss_fs_RmMountPoint"; /*Routine name */ + register afs_int32 code; /*pioctl() result */ + char *parentDirP; /*Ptr to parent */ + char *componentP; /*Ptr to last component */ /* * Get the parent & final component names. */ - parentDirP = ParentAndComponent(a_mountpoint, - uss_fs_InBuff, - &componentP); + parentDirP = ParentAndComponent(a_mountpoint, uss_fs_InBuff, &componentP); - blob.in = componentP; - blob.in_size = strlen(componentP) + 1; - blob.out = uss_fs_OutBuff; + blob.in = componentP; + blob.in_size = strlen(componentP) + 1; + blob.out = uss_fs_OutBuff; blob.out_size = USS_FS_MAX_SIZE; #ifdef USS_FS_DB @@ -533,23 +541,23 @@ afs_int32 uss_fs_RmMountPoint(a_mountpoint) printf("%s: STAT_MT_PT pioctl() failed, errno %d", rn, errno); #endif /* USS_FS_DB */ if (errno == EINVAL) - printf("%s: '%s' is not a mountpoint\n", - rn, a_mountpoint); - return(code); + printf("%s: '%s' is not a mountpoint\n", rn, a_mountpoint); + return (code); } /* * Now that we know we have a proper mountpoint, nuke it. */ - blob.in = componentP; - blob.in_size = strlen(componentP) + 1; - blob.out = (char *)0; + blob.in = componentP; + blob.in_size = strlen(componentP) + 1; + blob.out = NULL; blob.out_size = 0; if (!uss_DryRun) { #ifdef USS_FS_DB - printf("%s: AFS_DELETE_MT_PT, in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", - rn, blob.in, blob.in_size, blob.out, blob.out_size); + printf + ("%s: AFS_DELETE_MT_PT, in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", + rn, blob.in, blob.in_size, blob.out, blob.out_size); #endif /* USS_FS_DB */ code = pioctl(parentDirP, VIOC_AFS_DELETE_MT_PT, blobP, 1); @@ -557,18 +565,18 @@ afs_int32 uss_fs_RmMountPoint(a_mountpoint) #ifdef USS_FS_DB printf("%s: DELETE_MT_PT pioctl() failed, errno %d", rn, errno); #endif /* USS_FS_DB */ - } + } } else printf("\t[Dry run - mount point '%s' NOT removed]\n", componentP); - return(code); + return (code); -} /*uss_fs_RmMountPoint*/ +} /*uss_fs_RmMountPoint */ #include struct tokenInfo { - struct ktc_token token; + struct ktc_token token; struct ktc_principal service; struct ktc_principal client; int deleted; @@ -580,25 +588,27 @@ struct tokenInfo { * Ugly, but it works. */ uss_fs_UnlogToken(celln) - char *celln; + char *celln; { unsigned count = 0, index, index2; - afs_int32 code = 0, cnt=0; + afs_int32 code = 0, cnt = 0; struct ktc_principal serviceName; struct tokenInfo *tokenInfoP, *tp; do { code = ktc_ListTokens(count, &count, &serviceName); cnt++; - } while(!code); + } while (!code); count = cnt - 1; - tokenInfoP = (struct tokenInfo *)malloc((sizeof(struct tokenInfo)*count)); - for (code = index = index2= 0; (!code) && (index < count); index++) { - tp = tokenInfoP+index; + tokenInfoP = + (struct tokenInfo *)malloc((sizeof(struct tokenInfo) * count)); + for (code = index = index2 = 0; (!code) && (index < count); index++) { + tp = tokenInfoP + index; code = ktc_ListTokens(index2, &index2, &tp->service); if (!code) { - code = ktc_GetToken(&tp->service, &tp->token, sizeof(struct ktc_token), - &tp->client); + code = + ktc_GetToken(&tp->service, &tp->token, + sizeof(struct ktc_token), &tp->client); if (!code) { tp->deleted = (!strcmp(celln, tp->client.cell) ? 1 : 0); if (tp->deleted) @@ -606,21 +616,21 @@ uss_fs_UnlogToken(celln) } } } - if (code = ktc_ForgetAllTokens ()) { - printf("uss_fs_UnlogToken: could not discard tickets, code %d\n", code); + if (code = ktc_ForgetAllTokens()) { + printf("uss_fs_UnlogToken: could not discard tickets, code %d\n", + code); exit(1); } - for (code = index = 0; index < count ; index++) { - tp = tokenInfoP+index; + for (code = index = 0; index < count; index++) { + tp = tokenInfoP + index; if (!(tp->deleted)) { code = ktc_SetToken(&tp->service, &tp->token, &tp->client, 0); if (code) { - printf("uss_fs_UnlogToken: Couldn't re-register token, code = %d\n", - code); + printf + ("uss_fs_UnlogToken: Couldn't re-register token, code = %d\n", + code); } } } return 0; } - - diff --git a/src/uss/uss_fs.h b/src/uss/uss_fs.h index e69a9f91e..9f22d9618 100644 --- a/src/uss/uss_fs.h +++ b/src/uss/uss_fs.h @@ -24,8 +24,8 @@ /* * ---------------------- Exported variables ---------------------- */ -extern char *uss_fs_InBuff; /*Cache Manager input buff*/ -extern char *uss_fs_OutBuff; /*Cache Manager output buff*/ +extern char *uss_fs_InBuff; /*Cache Manager input buff */ +extern char *uss_fs_OutBuff; /*Cache Manager output buff */ /* @@ -37,14 +37,14 @@ extern afs_int32 uss_fs_GetACL(); * Given the pathname for a directory, return its ACL. * * Args: - * char *a_dirPath : Directory pathname. - * char *a_aclBuff : Ptr to the buffer in which to put - * the directory's ACL. - * afs_int32 a_aclBuffBytes : Size of the above. + * char *a_dirPath : Directory pathname. + * char *a_aclBuff : Ptr to the buffer in which to put + * the directory's ACL. + * afs_int32 a_aclBuffBytes : Size of the above. * * Returns: - * 0 if everything went well, - * -1 otherwise, with errno set to the error. + * 0 if everything went well, + * -1 otherwise, with errno set to the error. */ extern afs_int32 uss_fs_SetACL(); @@ -53,79 +53,79 @@ extern afs_int32 uss_fs_SetACL(); * Set the ACL on the specified directory. * * Args: - * char *a_dirpath : Directory pathname. - * char *a_aclBuff : Ptr to the buffer from which to get - * the directory's ACL. - * afs_int32 a_aclBuffBytes : Size of the above. + * char *a_dirpath : Directory pathname. + * char *a_aclBuff : Ptr to the buffer from which to get + * the directory's ACL. + * afs_int32 a_aclBuffBytes : Size of the above. * * Returns: - * 0 if everything went well, - * -1 otherwise, with errno set to the error. + * 0 if everything went well, + * -1 otherwise, with errno set to the error. */ extern afs_int32 uss_fs_GetVolStat(); /* * Summary: * Given the pathname of an AFS mountpoint, find out what you - * can about the volume mounted there. + * can about the volume mounted there. * * Args: - * char *a_mountpoint : Mountpoint pathname. - * char *a_volStatBuff : Buffer to hold the status. - * afs_int32 a_volStatBuffBytes : Length of above. + * char *a_mountpoint : Mountpoint pathname. + * char *a_volStatBuff : Buffer to hold the status. + * afs_int32 a_volStatBuffBytes : Length of above. * * Returns: - * 0 if everything went well, - * -1 otherwise, with errno set to the error. + * 0 if everything went well, + * -1 otherwise, with errno set to the error. */ extern afs_int32 uss_fs_SetVolStat(); /* * Summary: * Given the pathname of an AFS mountpoint, set the status info - * for the volume mounted there. + * for the volume mounted there. * * Args: - * char *a_mountpoint : Mountpoint pathname. - * char *a_volStatBuff : Buffer holding the status. - * afs_int32 a_volStatBuffBytes : Length of above. + * char *a_mountpoint : Mountpoint pathname. + * char *a_volStatBuff : Buffer holding the status. + * afs_int32 a_volStatBuffBytes : Length of above. * * Returns: - * 0 if everything went well, - * -1 otherwise, with errno set to the error. + * 0 if everything went well, + * -1 otherwise, with errno set to the error. */ extern afs_int32 uss_fs_CkBackups(); /* * Summary: * Make sure the CacheManager doesn't have any stale volume - * mappings. + * mappings. * * Args: - * None. + * None. * * Returns: - * 0 if everything went well, - * -1 otherwise, with errno set to the error. + * 0 if everything went well, + * -1 otherwise, with errno set to the error. */ extern afs_int32 uss_fs_MkMountPoint(); /* * Summary: *NEW* * Given the name of the volume, the cell it lives in, - * whether we want the read/write version mounted, and - * the pathname for the desired mountpoint, go ahead and - * create it. + * whether we want the read/write version mounted, and + * the pathname for the desired mountpoint, go ahead and + * create it. * * Args: - * char *a_volname : Name of volume to mount. - * char *a_cellname : Name of cell where volume lives. - * afs_int32 a_rw : Read/write mount? - * char *a_mountpoint : Name desired for the mountpoint. + * char *a_volname : Name of volume to mount. + * char *a_cellname : Name of cell where volume lives. + * afs_int32 a_rw : Read/write mount? + * char *a_mountpoint : Name desired for the mountpoint. * * Returns: - * 0 if everything went well, - * -1 otherwise, with errno set to the error. + * 0 if everything went well, + * -1 otherwise, with errno set to the error. */ extern afs_int32 uss_fs_RmMountPoint(); @@ -134,11 +134,11 @@ extern afs_int32 uss_fs_RmMountPoint(); * Delete the given mountpoint. * * Args: - * char *a_mountpoint : Name of the mountpoint to delete. + * char *a_mountpoint : Name of the mountpoint to delete. * * Returns: - * 0 if everything went well, - * -1 otherwise, with errno set to the error. + * 0 if everything went well, + * -1 otherwise, with errno set to the error. */ #endif /* _USS_FS_H_ */ diff --git a/src/uss/uss_kauth.c b/src/uss/uss_kauth.c index 1a3562960..22efad00c 100644 --- a/src/uss/uss_kauth.c +++ b/src/uss/uss_kauth.c @@ -18,36 +18,41 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_kauth.c,v 1.2 2003/01/02 03:55:51 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/uss/uss_kauth.c,v 1.10 2004/03/15 18:51:04 shadow Exp $"); -#include "uss_kauth.h" /*Module interface*/ -#include "uss_common.h" /*Common defs & operations*/ +#include "uss_kauth.h" /*Module interface */ +#include "uss_common.h" /*Common defs & operations */ #include #include -#include -#include /*MAXKTCREALMLEN*/ -#include /* pack_long */ -extern afs_int32 KAM_CreateUser(); +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#include +#include /*MAXKTCREALMLEN*/ +#include /* pack_long */ #define uss_kauth_MAX_SIZE 2048 - #undef USS_KAUTH_DB - /* * ---------------------- Exported variables ---------------------- */ -struct ubik_client *uconn_kauthP; /*Ubik connections - to AuthServers*/ +struct ubik_client *uconn_kauthP; /*Ubik connections + * to AuthServers */ /* * ------------------------ Private globals ----------------------- */ -static int initDone = 0; /*Module initialized?*/ -static char CreatorInstance[MAXKTCNAMELEN]; /*Instance string*/ -static char UserPrincipal[MAXKTCNAMELEN]; /*Parsed user principal*/ -static char UserInstance[MAXKTCNAMELEN]; /*Parsed user instance*/ -static char UserCell[MAXKTCREALMLEN]; /*Parsed user cell*/ +static int initDone = 0; /*Module initialized? */ +static char CreatorInstance[MAXKTCNAMELEN]; /*Instance string */ +static char UserPrincipal[MAXKTCNAMELEN]; /*Parsed user principal */ +static char UserInstance[MAXKTCNAMELEN]; /*Parsed user instance */ +static char UserCell[MAXKTCREALMLEN]; /*Parsed user cell */ int doUnlog = 0; /*----------------------------------------------------------------------- @@ -60,9 +65,9 @@ int doUnlog = 0; * As advertised. *-----------------------------------------------------------------------*/ -afs_int32 uss_kauth_InitAccountCreator() - -{ /*uss_kauth_InitAccountCreator*/ +afs_int32 +uss_kauth_InitAccountCreator() +{ /*uss_kauth_InitAccountCreator */ char *name; struct passwd *pw; @@ -75,48 +80,45 @@ afs_int32 uss_kauth_InitAccountCreator() * gleaned from the password info. */ if (uss_Administrator[0] != '\0') { - name = uss_Administrator; - } - else { /* Administrator name not passed in */ - pw = getpwuid(getuid()); - if (pw == 0) { - fprintf(stderr, - "%s: Can't figure out your name from your user id.\n", - uss_whoami); - return(1); - } - name = pw->pw_name; + name = uss_Administrator; + } else { /* Administrator name not passed in */ + pw = getpwuid(getuid()); + if (pw == 0) { + fprintf(stderr, + "%s: Can't figure out your name from your user id.\n", + uss_whoami); + return (1); + } + name = pw->pw_name; } /* Break the *name into principal and instance */ dotPosition = strcspn(name, "."); if (dotPosition >= MAXKTCNAMELEN) { - fprintf(stderr, "Admin principal name too long.\n"); - return(1); + fprintf(stderr, "Admin principal name too long.\n"); + return (1); } strncpy(uss_AccountCreator, name, dotPosition); uss_AccountCreator[dotPosition] = '\0'; name += dotPosition; if (name[0] == '.') { - name++; - if (strlen(name) >= MAXKTCNAMELEN) { - fprintf(stderr, "Admin instance name too long.\n"); - return(1); - } - strcpy(CreatorInstance, name); - } - else { - CreatorInstance[0] = '\0'; + name++; + if (strlen(name) >= MAXKTCNAMELEN) { + fprintf(stderr, "Admin instance name too long.\n"); + return (1); + } + strcpy(CreatorInstance, name); + } else { + CreatorInstance[0] = '\0'; } #ifdef USS_KAUTH_DB_INSTANCE - fprintf(stderr, - "%s: Starting CreatorInstance is '%s', %d bytes\n", + fprintf(stderr, "%s: Starting CreatorInstance is '%s', %d bytes\n", uss_whoami, CreatorInstance, strlen(CreatorInstance)); #endif /* USS_KAUTH_DB_INSTANCE */ - - return(0); + + return (0); } /*----------------------------------------------------------------------- @@ -143,28 +145,31 @@ afs_int32 uss_kauth_InitAccountCreator() * As advertised. *------------------------------------------------------------------------*/ -int Pipe=0; -static char *getpipepass() { +int Pipe = 0; +static char * +getpipepass() +{ static char gpbuf[BUFSIZ]; /* read a password from stdin, stop on \n or eof */ register int i, tc; memset(gpbuf, 0, sizeof(gpbuf)); - for(i=0; i<(sizeof(gpbuf)-1); i++) { + for (i = 0; i < (sizeof(gpbuf) - 1); i++) { tc = fgetc(stdin); - if (tc == '\n' || tc == EOF) break; + if (tc == '\n' || tc == EOF) + break; gpbuf[i] = tc; } return gpbuf; } -afs_int32 InitThisModule() - -{ /*InitThisModule*/ +afs_int32 +InitThisModule() +{ /*InitThisModule */ static char rn[] = "uss_kauth:InitThisModule"; register afs_int32 code; - char *name, prompt[2*MAXKTCNAMELEN+20]; + char *name, prompt[2 * MAXKTCNAMELEN + 20]; char *reasonString, longPassBuff[1024], shortPassBuff[9]; struct ktc_encryptionKey key; struct ktc_token token, tok; @@ -174,13 +179,15 @@ afs_int32 InitThisModule() * Only call this routine once. */ if (initDone) - return(0); + return (0); /* * Pull out the caller's administrator token if they have one. */ - code = ka_GetAdminToken(0, 0, uss_Cell, 0, 10*60*60, &token, 0/*new*/); + code = + ka_GetAdminToken(0, 0, uss_Cell, 0, 10 * 60 * 60, &token, + 0 /*new */ ); if (code) { if (Pipe) { strncpy(longPassBuff, getpipepass(), sizeof(longPassBuff)); @@ -191,30 +198,25 @@ afs_int32 InitThisModule() */ sprintf(prompt, "Password for '%s", uss_AccountCreator); if (CreatorInstance[0]) - sprintf(prompt+strlen(prompt), ".%s", CreatorInstance); + sprintf(prompt + strlen(prompt), ".%s", CreatorInstance); strcat(prompt, "': "); - code = - ka_UserReadPassword(prompt, /*Prompt to use*/ - longPassBuff, /*Long pwd buffer*/ - sizeof(longPassBuff), /*Size of above*/ - &reasonString); + code = ka_UserReadPassword(prompt, /*Prompt to use */ + longPassBuff, /*Long pwd buffer */ + sizeof(longPassBuff), /*Size of above */ + &reasonString); if (code) { com_err(uss_whoami, code, "while getting password "); #ifdef USS_KAUTH_DB - printf("%s: Error code from ka_UserReadPassword(): %d\n", - rn, code); + printf("%s: Error code from ka_UserReadPassword(): %d\n", rn, + code); #endif /* USS_KAUTH_DB */ - return(code); + return (code); } } ka_StringToKey(longPassBuff, uss_Cell, &key); - code = ka_GetAdminToken(uss_AccountCreator, - CreatorInstance, - uss_Cell, - &key, - 24*60*60, - &token, - 0 /*new*/); + code = + ka_GetAdminToken(uss_AccountCreator, CreatorInstance, uss_Cell, + &key, 24 * 60 * 60, &token, 0 /*new */ ); if (code) { if ((code == KABADREQUEST) && (strlen(longPassBuff) > 8)) { /* @@ -227,36 +229,34 @@ afs_int32 InitThisModule() com_err(uss_whoami, code, "while getting administrator token (trying shortened password next...)"); #ifdef USS_KAUTH_DB - printf("%s: Error code from ka_GetAdminToken: %d\n", - rn, code); + printf("%s: Error code from ka_GetAdminToken: %d\n", rn, + code); #endif /* USS_KAUTH_DB */ strncpy(shortPassBuff, longPassBuff, 8); shortPassBuff[8] = 0; ka_StringToKey(shortPassBuff, uss_Cell, &key); - code = ka_GetAdminToken(uss_AccountCreator, - CreatorInstance, - uss_Cell, - &key, - 24*60*60, - &token, - 0 /*new*/); + code = + ka_GetAdminToken(uss_AccountCreator, CreatorInstance, + uss_Cell, &key, 24 * 60 * 60, &token, + 0 /*new */ ); if (code) { com_err(uss_whoami, code, "while getting administrator token (possibly wrong password, or not an administrative account)"); #ifdef USS_KAUTH_DB - printf("%s: Error code from ka_GetAdminToken: %d\n", - rn, code); + printf("%s: Error code from ka_GetAdminToken: %d\n", rn, + code); #endif /* USS_KAUTH_DB */ - return(code); - } - else { + return (code); + } else { /* * The silly administrator has a long password! Tell * him or her off in a polite way. */ - printf("%s: Shortened password accepted by the Authentication Server\n", uss_whoami); + printf + ("%s: Shortened password accepted by the Authentication Server\n", + uss_whoami); } - } /*Try a shorter password*/ + } /*Try a shorter password */ else { /* * We failed to get an admin token, but the password is @@ -265,14 +265,15 @@ afs_int32 InitThisModule() com_err(uss_whoami, code, "while getting administrator token (possibly wrong password, or not an administrative account)"); #ifdef USS_KAUTH_DB - printf("%s: Error code from ka_GetAdminToken: %d\n", - rn, code); + printf("%s: Error code from ka_GetAdminToken: %d\n", rn, + code); #endif /* USS_KAUTH_DB */ - return(code); - } /*Even the shorter password didn't work*/ - } /*Key from given password didn't work*/ - } /*First attempt to get admin token failed*/ - + return (code); + } /*Even the shorter password didn't work */ + } /*Key from given password didn't work */ + } + + /*First attempt to get admin token failed */ /* * At this point, we have acquired an administrator token. Let's * proceed to set up a connection to the AuthServer. @@ -286,16 +287,16 @@ afs_int32 InitThisModule() /* * Set up the connection to the AuthServer read/write site. */ - code = ka_AuthServerConn(uss_Cell, KA_MAINTENANCE_SERVICE, - &token, &uconn_kauthP); + code = + ka_AuthServerConn(uss_Cell, KA_MAINTENANCE_SERVICE, &token, + &uconn_kauthP); if (code) { com_err(uss_whoami, code, "while establishing Authentication Server connection"); #ifdef USS_KAUTH_DB - printf("%s: Error code from ka_AuthServerConn: %d\n", - rn, code); + printf("%s: Error code from ka_AuthServerConn: %d\n", rn, code); #endif /* USS_KAUTH_DB */ - return(code); + return (code); } if (uss_Administrator[0]) { @@ -304,24 +305,28 @@ afs_int32 InitThisModule() * various pioctl or calls to protection server that require tokens. Remember * to remove this tokens at the end of the program... */ - strcpy (Name.name, "afs"); + strcpy(Name.name, "afs"); Name.instance[0] = '\0'; - strncpy (Name.cell, uss_Cell, sizeof(Name.cell)); - if (code = ktc_GetToken (&Name, &token, sizeof(struct ktc_token), &tok)) { - code = ka_UserAuthenticateLife (0, uss_AccountCreator, CreatorInstance, - uss_Cell,longPassBuff,10*60*60,&reasonString); + strncpy(Name.cell, uss_Cell, sizeof(Name.cell)); + if (code = + ktc_GetToken(&Name, &token, sizeof(struct ktc_token), &tok)) { + code = + ka_UserAuthenticateLife(0, uss_AccountCreator, + CreatorInstance, uss_Cell, + longPassBuff, 10 * 60 * 60, + &reasonString); if (!code) doUnlog = 1; } } - + /* * Declare our success. */ initDone = 1; - return(0); + return (0); -} /*InitThisModule*/ +} /*InitThisModule */ /*----------------------------------------------------------------------- @@ -335,13 +340,14 @@ afs_int32 InitThisModule() * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_kauth_AddUser(a_user, a_passwd) - char *a_user; - char *a_passwd; +afs_int32 +uss_kauth_AddUser(a_user, a_passwd) + char *a_user; + char *a_passwd; -{ /*uss_kauth_AddUser*/ +{ /*uss_kauth_AddUser */ - static char rn[] = "uss_kauth_AddUser"; /*Routine name*/ + static char rn[] = "uss_kauth_AddUser"; /*Routine name */ struct ktc_encryptionKey key; afs_int32 code; @@ -351,8 +357,9 @@ afs_int32 uss_kauth_AddUser(a_user, a_passwd) * Amasingly people want to update it (most likely kerberos) themselves... */ if (uss_verbose) - printf("[Skip Kaserver option - Adding of user %s in Authentication DB not done]\n", - a_user); + printf + ("[Skip Kaserver option - Adding of user %s in Authentication DB not done]\n", + a_user); return 0; } @@ -383,39 +390,33 @@ afs_int32 uss_kauth_AddUser(a_user, a_passwd) "%s: KAM_CreateUser: user='%s', CreatorInstance='%s', %d bytes\n", rn, a_user, CreatorInstance, strlen(CreatorInstance)); #endif /* USS_KAUTH_DB_INSTANCE */ - code = ubik_Call(KAM_CreateUser, - uconn_kauthP, - 0, - a_user, - UserInstance, /*set by CheckUsername()*/ + code = ubik_Call(KAM_CreateUser, uconn_kauthP, 0, a_user, UserInstance, /*set by CheckUsername() */ key); if (code) { - if (code == KAEXIST){ + if (code == KAEXIST) { if (uss_verbose) fprintf(stderr, "%s: Warning: User '%s' already in Authentication DB\n", uss_whoami, a_user); - } - else { + } else { com_err(uss_whoami, code, "while adding user '%s' to Authentication DB", a_user); #ifdef USS_KAUTH_DB - printf("%s: Error code from KAM_CreateUser: %d\n", - rn, code); + printf("%s: Error code from KAM_CreateUser: %d\n", rn, code); #endif /* USS_KAUTH_DB */ - return(code); + return (code); } - } /*KAM_CreateUser failed*/ - } /*Not a dry run*/ + } /*KAM_CreateUser failed */ + } /*Not a dry run */ else fprintf(stderr, "\t[Dry run - user '%s' NOT added to Authentication DB]\n", a_user); - return(0); + return (0); -} /*uss_kauth_AddUser*/ +} /*uss_kauth_AddUser */ /*----------------------------------------------------------------------- @@ -429,13 +430,14 @@ afs_int32 uss_kauth_AddUser(a_user, a_passwd) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_kauth_DelUser(a_user) - char *a_user; +afs_int32 +uss_kauth_DelUser(a_user) + char *a_user; -{ /*uss_kauth_DelUser*/ +{ /*uss_kauth_DelUser */ - static char rn[] = "uss_kauth_DelUser"; /*Routine name*/ - register afs_int32 code; /*Return code*/ + static char rn[] = "uss_kauth_DelUser"; /*Routine name */ + register afs_int32 code; /*Return code */ if (uss_SkipKaserver) { /* @@ -443,8 +445,9 @@ afs_int32 uss_kauth_DelUser(a_user) * Amasingly people want to update it (most likely kerberos) themselves... */ if (uss_verbose) - printf("[Skip Kaserver option - Deleting of user %s in Authentication DB not done]\n", - a_user); + printf + ("[Skip Kaserver option - Deleting of user %s in Authentication DB not done]\n", + a_user); return 0; } @@ -464,38 +467,36 @@ afs_int32 uss_kauth_DelUser(a_user) uss_whoami, a_user, CreatorInstance); #endif /* USS_KAUTH_DB_INSTANCE */ if (uss_verbose) - printf("Deleting user '%s' from Authentication DB\n", - a_user); - code = ubik_Call(KAM_DeleteUser, /*Procedure to call*/ - uconn_kauthP, /*Ubik client connection struct*/ - 0, /*Flags*/ - a_user, /*User name to delete*/ - UserInstance); /*set in CheckUserName()*/ + printf("Deleting user '%s' from Authentication DB\n", a_user); + code = ubik_Call(KAM_DeleteUser, /*Procedure to call */ + uconn_kauthP, /*Ubik client connection struct */ + 0, /*Flags */ + a_user, /*User name to delete */ + UserInstance); /*set in CheckUserName() */ if (code) { if (code == KANOENT) { if (uss_verbose) - printf("%s: No entry for user '%s' in Authentication DB\n", - uss_whoami, a_user); - return(0); - } - else { + printf + ("%s: No entry for user '%s' in Authentication DB\n", + uss_whoami, a_user); + return (0); + } else { com_err(uss_whoami, code, "while deleting entry in Authentication DB\n"); #ifdef USS_KAUTH_DB - printf("%s: Error code from KAM_DeleteUser: %d\n", - rn, code); + printf("%s: Error code from KAM_DeleteUser: %d\n", rn, code); #endif /* USS_KAUTH_DB */ - return(code); + return (code); } - } /*KAM_DeleteUser failed*/ - } /*Not a dry run*/ + } /*KAM_DeleteUser failed */ + } /*Not a dry run */ else printf("\t[Dry run - user '%s' NOT deleted from Authentication DB]\n", a_user); - return(0); + return (0); -} /*uss_kauth_DelUser*/ +} /*uss_kauth_DelUser */ /*----------------------------------------------------------------------- @@ -509,12 +510,12 @@ afs_int32 uss_kauth_DelUser(a_user) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_kauth_CheckUserName() +afs_int32 +uss_kauth_CheckUserName() +{ /*uss_kauth_CheckUserName */ -{ /*uss_kauth_CheckUserName*/ - - static char rn[] = "uss_kauth_CheckUserName"; /*Routine name*/ - register afs_int32 code; /*Return code*/ + static char rn[] = "uss_kauth_CheckUserName"; /*Routine name */ + register afs_int32 code; /*Return code */ if (uss_SkipKaserver) { /* @@ -522,7 +523,8 @@ afs_int32 uss_kauth_CheckUserName() * Amasingly people want to update it (most likely kerberos) themselves... */ if (uss_verbose) - printf("[Skip Kaserver option - Checking of user name in Authentication DB not done]\n"); + printf + ("[Skip Kaserver option - Checking of user name in Authentication DB not done]\n"); return 0; } @@ -539,30 +541,30 @@ afs_int32 uss_kauth_CheckUserName() /* * Use the AuthServer's own routine to decide if the parsed user name * is legal. Specifically, it can't have any weird characters or - * embedded instance or cell names. + * embedded instance or cell names. */ - code = ka_ParseLoginName(uss_User, - UserPrincipal, UserInstance, UserCell); + code = ka_ParseLoginName(uss_User, UserPrincipal, UserInstance, UserCell); if (strlen(UserInstance) > 0) { - fprintf(stderr, "%s: User name can't have an instance string ('%s')\n", + fprintf(stderr, + "%s: User name can't have an instance string ('%s')\n", uss_whoami, UserInstance); - return(-1); + return (-1); } if (strlen(UserCell) > 0) { fprintf(stderr, "%s: User name can't have a cell string ('%s')\n", uss_whoami, UserCell); - return(-1); + return (-1); } if (strchr(UserPrincipal, ':') != NULL) { - fprintf(stderr, "%s: User name '%s' can't have a colon\n", - uss_whoami, UserPrincipal); - return(-1); + fprintf(stderr, "%s: User name '%s' can't have a colon\n", uss_whoami, + UserPrincipal); + return (-1); } if (strlen(UserPrincipal) > 8) { fprintf(stderr, "%s: User name '%s' must have 8 or fewer characters\n", uss_whoami, UserPrincipal); - return(-1); + return (-1); } /* @@ -570,9 +572,9 @@ afs_int32 uss_kauth_CheckUserName() * value. */ strcpy(uss_User, UserPrincipal); - return(0); + return (0); -} /*uss_kauth_CheckUserName*/ +} /*uss_kauth_CheckUserName */ /* @@ -586,13 +588,14 @@ afs_int32 uss_kauth_CheckUserName() * As advertised. */ -afs_int32 uss_kauth_SetFields(username, expirestring, reuse, failures, lockout) - char *reuse; - char *username; - char *expirestring; - char *failures; - char *lockout; -{ +afs_int32 +uss_kauth_SetFields(username, expirestring, reuse, failures, lockout) + char *reuse; + char *username; + char *expirestring; + char *failures; + char *lockout; +{ static char rn[] = "uss_kauth_SetFields"; afs_int32 code; char misc_auth_bytes[4]; @@ -604,72 +607,77 @@ afs_int32 uss_kauth_SetFields(username, expirestring, reuse, failures, lockout) afs_int32 was_spare = 0; char instance = '\0'; int pwexpiry; - int nfailures, locktime; + int nfailures, locktime, hrs, mins; - if (strlen (username) > uss_UserLen) { - fprintf(stderr, + if (strlen(username) > uss_UserLen) { + fprintf(stderr, "%s: * User field in add cmd too long (max is %d chars; truncated value is '%s')\n", uss_whoami, uss_UserLen, uss_User); - return(-1); + return (-1); } - strcpy (uss_User, username); + strcpy(uss_User, username); code = uss_kauth_CheckUserName(); if (code) - return (code); + return (code); /* no point in doing this any sooner than necessary */ - for (i=0;i<4;misc_auth_bytes[i++] = 0); + for (i = 0; i < 4; misc_auth_bytes[i++] = 0); pwexpiry = atoi(expirestring); - if (pwexpiry <0 || pwexpiry >254) { - fprintf(stderr,"Password lifetime range must be [0..254] days.\n"); - fprintf(stderr,"Zero represents an unlimited lifetime.\n"); - fprintf(stderr,"Continuing with default lifetime == 0 for user %s.\n", - username); - } - else { - misc_auth_bytes[0] = pwexpiry+1; + if (pwexpiry < 0 || pwexpiry > 254) { + fprintf(stderr, "Password lifetime range must be [0..254] days.\n"); + fprintf(stderr, "Zero represents an unlimited lifetime.\n"); + fprintf(stderr, + "Continuing with default lifetime == 0 for user %s.\n", + username); + pwexpiry = 0; } - - if (!strcmp(reuse, "reuse")) { - misc_auth_bytes[1] = KA_REUSEPW; - } - else if (!strcmp(reuse, "noreuse")) { - misc_auth_bytes[1] = KA_NOREUSEPW; - } - else { - misc_auth_bytes[1] = KA_REUSEPW; - fprintf(stderr, - "must specify \"reuse\" or \"noreuse\": \"reuse\" assumed\n"); + misc_auth_bytes[0] = pwexpiry + 1; + + if (!strcmp(reuse, "noreuse")) { + misc_auth_bytes[1] = KA_NOREUSEPW; + } else { + misc_auth_bytes[1] = KA_REUSEPW; + if (strcmp(reuse, "reuse")) + fprintf(stderr, "must specify \"reuse\" or \"noreuse\": \"reuse\" assumed\n"); } nfailures = atoi(failures); - if (nfailures <0 || nfailures >254) { - fprintf(stderr,"Failure limit must be in [0..254].\n"); - fprintf(stderr,"Zero represents unlimited login attempts.\n"); - fprintf(stderr,"Continuing with limit == 254 for user %s.\n", - username); - misc_auth_bytes[2] = 255; - } - else - misc_auth_bytes[2] = nfailures+1; - - locktime = ktime_Str2int32(lockout); - if (locktime < 0 || locktime > 36*60 ) { - fprintf(stderr,"Lockout times must be either minutes or hh:mm.\n"); - fprintf(stderr,"Lockout times must be less than 36 hours.\n"); - fprintf(stderr,"Continuing with lock time == forever for user %s.\n", - username); - } - else { - locktime = (locktime * 60) >> 9; - misc_auth_bytes[3] = locktime +1; + if (nfailures < 0 || nfailures > 254) { + fprintf(stderr, "Failure limit must be in [0..254].\n"); + fprintf(stderr, "Zero represents unlimited login attempts.\n"); + fprintf(stderr, "Continuing with limit == 254 for user %s.\n", + username); + misc_auth_bytes[2] = 255; + } else + misc_auth_bytes[2] = nfailures + 1; + + hrs = 0; + if (strchr(lockout, ':')) + sscanf(lockout, "%d:%d", &hrs, &mins); + else + sscanf(lockout, "%d", &mins); + + locktime = hrs*60 + mins; + if (hrs < 0 || hrs > 36 || mins < 0) { + fprintf(stderr,"Lockout times must be either minutes or hh:mm.\n"); + fprintf(stderr,"Lockout times must be less than 36 hours.\n"); + return KABADCMD; + } else if (locktime > 36*60) { + fprintf(stderr, "Lockout times must be either minutes or hh:mm.\n"); + fprintf(stderr, "Lockout times must be less than 36 hours.\n"); + fprintf(stderr, "Continuing with lock time == forever for user %s.\n", + username); + misc_auth_bytes[3] = 1; + } else { + locktime = (locktime * 60 + 511) >> 9; /* ceil(l*60/512) */ + misc_auth_bytes[3] = locktime + 1; } - + if (uss_SkipKaserver) { - if (uss_verbose) - printf("[Skipping Kaserver as requested]\n"); + if (uss_verbose) + printf("[Skipping Kaserver as requested]\n"); return 0; } @@ -687,48 +695,32 @@ afs_int32 uss_kauth_SetFields(username, expirestring, reuse, failures, lockout) if (uss_verbose) fprintf(stderr, "Setting options for '%s' in database.\n", username); - + was_spare = pack_long(misc_auth_bytes); - if (was_spare || flags || expiration || - lifetime || (maxAssociates >= 0)) { + if (was_spare || flags || expiration || lifetime + || (maxAssociates >= 0)) { if (!expiration) expiration = uss_Expires; - code = ubik_Call( KAM_SetFields, uconn_kauthP, 0, username, &instance, - flags, expiration, lifetime, maxAssociates, - was_spare, /* spare */ 0); - } - else fprintf (stderr, - "Must specify one of the optional parameters. Continuing...\n"); + code = + ubik_Call(KAM_SetFields, uconn_kauthP, 0, username, &instance, + flags, expiration, lifetime, maxAssociates, + was_spare, /* spare */ 0); + } else + fprintf(stderr, + "Must specify one of the optional parameters. Continuing...\n"); if (code) { - com_err (uss_whoami, code, - "calling KAM_SetFields for %s.%s", username, instance); + com_err(uss_whoami, code, "calling KAM_SetFields for %s.%s", + username, instance); - return(code); + return (code); } - } /*Not a dry run*/ + } /*Not a dry run */ else - fprintf(stderr, - "\t[Dry run - user '%s' NOT changed.]\n", - username); - - return(0); - -} /*uss_kauth_SetFields */ - - - - - - - - - - - - - + fprintf(stderr, "\t[Dry run - user '%s' NOT changed.]\n", username); + return (0); +} /*uss_kauth_SetFields */ diff --git a/src/uss/uss_kauth.h b/src/uss/uss_kauth.h index 8d4bc4e2d..4fd7ebff6 100644 --- a/src/uss/uss_kauth.h +++ b/src/uss/uss_kauth.h @@ -47,13 +47,13 @@ extern afs_int32 uss_kauth_AddUser(); * Register the given user with the Authentication Server. * * Args: - * char *a_user : Name of the user to register. - * char *a_passwd : User's (cleartext) password. + * char *a_user : Name of the user to register. + * char *a_passwd : User's (cleartext) password. * * Returns: - * 0 if everything went well, - * 1 if there was a problem encountered in this function, or - * Code returned from a lower-level call. + * 0 if everything went well, + * 1 if there was a problem encountered in this function, or + * Code returned from a lower-level call. */ extern afs_int32 uss_kauth_DelUser(); @@ -62,12 +62,12 @@ extern afs_int32 uss_kauth_DelUser(); * Delete the given user from the Authentication Database. * * Args: - * char *a_user : Name of the user to delete. + * char *a_user : Name of the user to delete. * * Returns: - * 0 if everything went well, - * 1 if there was a problem encountered in this function, or - * Code returned from a lower-level call. + * 0 if everything went well, + * 1 if there was a problem encountered in this function, or + * Code returned from a lower-level call. */ extern afs_int32 uss_kauth_CheckUserName(); @@ -76,11 +76,11 @@ extern afs_int32 uss_kauth_CheckUserName(); * Make sure the parsed user name is a legal one. * * Args: - * None. + * None. * * Returns: - * 0 if everything went well, - * 1 if the user name is not legal. + * 0 if everything went well, + * 1 if the user name is not legal. */ #endif /* _USS_KAUTH_H_ */ diff --git a/src/uss/uss_procs.c b/src/uss/uss_procs.c index a4bdd4624..c0b8c8601 100644 --- a/src/uss/uss_procs.c +++ b/src/uss/uss_procs.c @@ -18,20 +18,21 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_procs.c,v 1.3 2003/07/30 17:23:45 hartmans Exp $"); - -#include "uss_procs.h" /*Module interface*/ -#include "uss_common.h" /*Common defs & operations*/ -#include "uss_acl.h" /*ACL-related operations*/ -#include /*Unix error codes*/ -#include /*Password info*/ -#include /*Stat defs*/ -#include /*Directory package*/ -#include /*O_EXCL, O_CREAT, etc*/ +RCSID + ("$Header: /cvs/openafs/src/uss/uss_procs.c,v 1.9 2003/07/15 23:17:12 shadow Exp $"); + +#include "uss_procs.h" /*Module interface */ +#include "uss_common.h" /*Common defs & operations */ +#include "uss_acl.h" /*ACL-related operations */ +#include /*Unix error codes */ +#include /*Password info */ +#include /*Stat defs */ +#include /*Directory package */ +#include /*O_EXCL, O_CREAT, etc */ #ifdef AFS_SUN5_ENV #include #endif -#include /*MAXKTCREALMLEN*/ + #ifdef HAVE_STRING_H #include #else @@ -40,12 +41,11 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_procs.c,v 1.3 2003/07/30 17:23: #endif #endif +#include /*MAXKTCREALMLEN*/ #undef USS_PROCS_DB #undef USS_PROCS_DB_INSTANCE #undef USS_PROCS_DB_BUILDDIR - #define uss_procs_MAX_SIZE 2048 - char temp[1000]; extern int line; @@ -62,13 +62,14 @@ static int Echo(); * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_procs_BuildDir(a_path, a_mode, a_owner, a_access) - char *a_path; - char *a_mode; - char *a_owner; - char *a_access; +afs_int32 +uss_procs_BuildDir(a_path, a_mode, a_owner, a_access) + char *a_path; + char *a_mode; + char *a_owner; + char *a_access; -{ /*uss_procs_BuildDir*/ +{ /*uss_procs_BuildDir */ int m, o; char buf[1000]; @@ -79,11 +80,11 @@ afs_int32 uss_procs_BuildDir(a_path, a_mode, a_owner, a_access) * Don't do anything if there's already a problem. */ if (uss_syntax_err) - return(1); - + return (1); + if (uss_verbose) - printf("Building directory '%s'; owner: '%s', ACL: '%s'\n", - a_path, a_owner, a_access); + printf("Building directory '%s'; owner: '%s', ACL: '%s'\n", a_path, + a_owner, a_access); /* * If we've not been given permission to overwrite things, make sure @@ -94,7 +95,7 @@ afs_int32 uss_procs_BuildDir(a_path, a_mode, a_owner, a_access) if (!stat(temp, &stbuf)) { if (uss_verbose) printf("\t[Directory exists, NOT overwriting it]\n"); - return(0); + return (0); } } @@ -114,72 +115,70 @@ afs_int32 uss_procs_BuildDir(a_path, a_mode, a_owner, a_access) uss_procs_PrintErr(line, "Failed to create directory '%s': %s\n", a_path, strerror(errno)); - return(1); - } /*Directory didn't exist*/ - } /*Create the directory*/ - } /*Not a dry run*/ + return (1); + } /*Directory didn't exist */ + } /*Create the directory */ + } /*Not a dry run */ else { if (uss_OverwriteThisOne) - fprintf(stderr, "\t[Dry run: mkdir %s, mode %o]\n", - a_path, m); - } /*Dry run*/ + fprintf(stderr, "\t[Dry run: mkdir %s, mode %o]\n", a_path, m); + } /*Dry run */ if (!uss_DryRun) { if (chmod(a_path, m)) { uss_procs_PrintErr(line, - "Can't chmod() directory '%s' to be '%s' : %s\n", - a_path, a_mode, strerror(errno)); - return(1); - } /* chmod the directory */ + "Can't chmod() directory '%s' to be '%s' : %s\n", + a_path, a_mode, strerror(errno)); + return (1); + } /* chmod the directory */ if (chown(a_path, o, -1)) { uss_procs_PrintErr(line, "Can't chown() directory '%s' to be owned by '%s' (uid %d): %s\n", a_path, a_owner, o, strerror(errno)); - return(1); - } /*Couldn't chown*/ - } /*Not a dry run*/ + return (1); + } /*Couldn't chown */ + } /*Not a dry run */ else { fprintf(stderr, "\t[Dry run: chown() directory '%s' to be owned by user]\n", a_path); - } /*Dry run*/ + } /*Dry run */ /* - * Set the ACL for this new directory so that the uss_AccountCreator - * is the only party that has rights. This will be corrected as the - * final action performed on the account. - */ + * Set the ACL for this new directory so that the uss_AccountCreator + * is the only party that has rights. This will be corrected as the + * final action performed on the account. + */ sprintf(buf, "%s %s all", a_path, uss_AccountCreator); if (!uss_DryRun) { if (uss_verbose) - fprintf(stderr, - "Setting ACL: '%s'\n", buf); + fprintf(stderr, "Setting ACL: '%s'\n", buf); if (uss_acl_SetAccess(buf, 1, 0)) - return(1); - } /*Not a dry run*/ + return (1); + } /*Not a dry run */ else { - fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s) on '%s']\n", - buf, a_path); - } /*Dry run*/ + fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s) on '%s']\n", buf, + a_path); + } /*Dry run */ /* * Use our linked list to remember this directory's true ACL setting so * we may set it correctly at the tail end of the account creation. */ - new_dir = (struct uss_subdir *) malloc(sizeof(struct uss_subdir)); + new_dir = (struct uss_subdir *)malloc(sizeof(struct uss_subdir)); new_dir->previous = uss_currentDir; - new_dir->path = (char *) malloc(strlen(a_path)+1); + new_dir->path = (char *)malloc(strlen(a_path) + 1); strcpy(new_dir->path, a_path); - new_dir->finalACL = (char *) malloc(strlen(a_access)+1); + new_dir->finalACL = (char *)malloc(strlen(a_access) + 1); strcpy(new_dir->finalACL, a_access); uss_currentDir = new_dir; /* * Return the happy news. */ - return(0); + return (0); -} /*uss_procs_BuildDir*/ +} /*uss_procs_BuildDir */ /*----------------------------------------------------------------------- @@ -192,14 +191,15 @@ afs_int32 uss_procs_BuildDir(a_path, a_mode, a_owner, a_access) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_procs_CpFile(a_path, a_mode, a_owner, a_proto) - char *a_path; - char *a_mode; - char *a_owner; - char *a_proto; - -{ /*uss_procs_CpFile*/ - +afs_int32 +uss_procs_CpFile(a_path, a_mode, a_owner, a_proto) + char *a_path; + char *a_mode; + char *a_owner; + char *a_proto; + +{ /*uss_procs_CpFile */ + int m, o; struct stat stbuf; char *cp; @@ -208,7 +208,7 @@ afs_int32 uss_procs_CpFile(a_path, a_mode, a_owner, a_proto) * Don't do anything if something has already gone wrong. */ if (uss_syntax_err) - return(1); + return (1); if (uss_verbose) printf("Installing '%s'\n", a_path); @@ -222,7 +222,7 @@ afs_int32 uss_procs_CpFile(a_path, a_mode, a_owner, a_proto) if (!stat(temp, &stbuf)) { if (uss_verbose) printf("\t[Entry exists, NOT overwriting it]\n"); - return(0); + return (0); } } @@ -232,32 +232,30 @@ afs_int32 uss_procs_CpFile(a_path, a_mode, a_owner, a_proto) strcpy(temp, a_proto); if (stat(temp, &stbuf)) { - uss_procs_PrintErr(line, "Failed to stat '%s': %s\n", - a_proto, strerror(errno)); - return(1); + uss_procs_PrintErr(line, "Failed to stat '%s': %s\n", a_proto, + strerror(errno)); + return (1); } if (stbuf.st_mode & S_IFDIR) { if ((cp = strrchr(a_path, '/')) == NULL) { strcat(a_proto, "/"); strcat(a_proto, a_path); - } - else { + } else { /* * Append the last part (file name). */ strcat(a_proto, cp); } - } /*Target is a directory*/ - + } + /*Target is a directory */ if (!uss_DryRun) { if (Copy(a_proto, a_path, m)) { - uss_procs_PrintErr(line, - "Failed to copy '%s' to '%s'\n", - a_proto, a_path); - return(1); - } /*Copy failed*/ - } /*Not a dry run*/ + uss_procs_PrintErr(line, "Failed to copy '%s' to '%s'\n", a_proto, + a_path); + return (1); + } /*Copy failed */ + } /*Not a dry run */ else { fprintf(stderr, "\t[Dry run: Copying '%s' to '%s', mode %o]\n", a_proto, a_path, m); @@ -268,20 +266,21 @@ afs_int32 uss_procs_CpFile(a_path, a_mode, a_owner, a_proto) uss_procs_PrintErr(line, "Can't chown() file '%s' to be owned by '%s' (uid %d): %s\n", a_path, a_owner, o, strerror(errno)); - return(1); - } /*chown failed*/ - } /*Not a dry run*/ + return (1); + } /*chown failed */ + } /*Not a dry run */ else { - fprintf(stderr, "\t[Dry run: chown() file '%s' to be owned by user]\n", + fprintf(stderr, + "\t[Dry run: chown() file '%s' to be owned by user]\n", a_path); - } /*Dry run*/ + } /*Dry run */ /* * Return the happy news. */ - return(0); - -} /*uss_procs_CpFile*/ + return (0); + +} /*uss_procs_CpFile */ /*----------------------------------------------------------------------- @@ -294,26 +293,27 @@ afs_int32 uss_procs_CpFile(a_path, a_mode, a_owner, a_proto) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_procs_EchoToFile(a_path, a_mode, a_owner, a_content) - char *a_path; - char *a_mode; - char *a_owner; - char *a_content; - -{ /*uss_procs_EchoToFile*/ - +afs_int32 +uss_procs_EchoToFile(a_path, a_mode, a_owner, a_content) + char *a_path; + char *a_mode; + char *a_owner; + char *a_content; + +{ /*uss_procs_EchoToFile */ + int m, o; struct stat stbuf; - + /* * Don't do anything if something has already gone wrong. */ if (uss_syntax_err) - return(1); - + return (1); + if (uss_verbose) printf("Echoing to '%s'\n", a_path); - + /* * If we've not been given permission to overwrite things, make sure * the target doesn't exist before doing anything. @@ -323,46 +323,46 @@ afs_int32 uss_procs_EchoToFile(a_path, a_mode, a_owner, a_content) if (!stat(temp, &stbuf)) { if (uss_verbose) printf("\t[Entry exists, NOT overwriting it]\n"); - return(0); + return (0); } } - + sscanf(a_mode, "%o", &m); o = uss_procs_GetOwner(a_owner); - + if (!uss_DryRun) { - if (Echo(a_content, a_path, m)){ + if (Echo(a_content, a_path, m)) { uss_procs_PrintErr(line, "Failed to echo string '%s' to file '%s'\n", a_content, a_path); - return(1); + return (1); } - } /*Not a dry run*/ + } /*Not a dry run */ else { fprintf(stderr, "\t[Dry run: Echoing '%s' into file '%s']\n", a_content, a_path); - } /*Dry run*/ - + } /*Dry run */ + if (!uss_DryRun) { - if (chown(a_path, o, -1)){ + if (chown(a_path, o, -1)) { uss_procs_PrintErr(line, "Can't chown() file '%s' to be owned by '%s' (uid %d): %s\n", a_path, a_owner, o, strerror(errno)); - return(1); + return (1); } - } /*Not a dry run*/ + } /*Not a dry run */ else { fprintf(stderr, "\t[Dry run: chown() file '%s' to be owned by user]\n", a_path); - } /*Dry run*/ - + } /*Dry run */ + /* * Return the happy news. */ - return(0); - -} /*uss_procs_EchoToFile*/ + return (0); + +} /*uss_procs_EchoToFile */ /*----------------------------------------------------------------------- @@ -376,32 +376,32 @@ afs_int32 uss_procs_EchoToFile(a_path, a_mode, a_owner, a_content) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_procs_Exec(a_command) - char *a_command; +afs_int32 +uss_procs_Exec(a_command) + char *a_command; -{ /*uss_procs_Exec*/ +{ /*uss_procs_Exec */ if (uss_verbose) - printf("Running '%s'\n", a_command); + printf("Running '%s'\n", a_command); if (!uss_DryRun) { - if (system(a_command)) { - uss_procs_PrintErr(line, - "Failed to run the '%s' command: %s\n", - a_command, strerror(errno)); - return(1); - } - } /*Not a dry run*/ + if (system(a_command)) { + uss_procs_PrintErr(line, "Failed to run the '%s' command: %s\n", + a_command, strerror(errno)); + return (1); + } + } /*Not a dry run */ else { - fprintf(stderr, "\t[Dry run: executing '%s']\n", a_command); - } /*Dry run*/ + fprintf(stderr, "\t[Dry run: executing '%s']\n", a_command); + } /*Dry run */ /* * Return the happy news. */ - return(0); + return (0); -} /*uss_procs_Exec*/ +} /*uss_procs_Exec */ /*----------------------------------------------------------------------- @@ -414,72 +414,73 @@ afs_int32 uss_procs_Exec(a_command) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_procs_SetLink(a_path1, a_path2, a_type) - char *a_path1; - char *a_path2; - char a_type; +afs_int32 +uss_procs_SetLink(a_path1, a_path2, a_type) + char *a_path1; + char *a_path2; + char a_type; -{ /*uss_procs_SetLink*/ +{ /*uss_procs_SetLink */ struct stat stbuf; if (uss_verbose) - printf("Setting link '%s' to '%s'\n", a_path1, a_path2); + printf("Setting link '%s' to '%s'\n", a_path1, a_path2); /* * If we've not been given permission to overwrite things, make sure * the target doesn't exist before doing anything. */ if (!uss_OverwriteThisOne) { - strcpy(temp, a_path2); - if (!stat(temp, &stbuf)) { - if (uss_verbose) - printf("\t[Entry exists, NOT overwriting it]\n"); - return(0); - } + strcpy(temp, a_path2); + if (!stat(temp, &stbuf)) { + if (uss_verbose) + printf("\t[Entry exists, NOT overwriting it]\n"); + return (0); + } } if (a_type == 's') { - /* - * Symbolic link. - */ - if (!uss_DryRun) { - if (symlink(a_path1, a_path2)) { - uss_procs_PrintErr(line, - "Failed to make symlink '%s' to '%s': %s\n", - a_path1, a_path2, strerror(errno)); - return(1); - } - } /*Dry run*/ - else { - fprintf(stderr, "\t[Dry run: Making symlink '%s' to '%s']\n", - a_path1, a_path2); - } /*Not a dry run*/ - } /*Symbolic link*/ + /* + * Symbolic link. + */ + if (!uss_DryRun) { + if (symlink(a_path1, a_path2)) { + uss_procs_PrintErr(line, + "Failed to make symlink '%s' to '%s': %s\n", + a_path1, a_path2, strerror(errno)); + return (1); + } + } /*Dry run */ + else { + fprintf(stderr, "\t[Dry run: Making symlink '%s' to '%s']\n", + a_path1, a_path2); + } /*Not a dry run */ + } /*Symbolic link */ else { - /* - * Hard link. - */ - if (!uss_DryRun) { - if (link(a_path1, a_path2)) { - uss_procs_PrintErr(line, - "Failed to make hard link '%s' to '%s': %s\n", - a_path1, a_path2, strerror(errno)); - return(1); - } - } /*Dry run*/ - else { - fprintf(stderr, "\t[Dry run: Making hard link '%s' to '%s']\n", - a_path1, a_path2); - } /*Not a dry run*/ - } /*Hard link*/ + /* + * Hard link. + */ + if (!uss_DryRun) { + if (link(a_path1, a_path2)) { + uss_procs_PrintErr(line, + "Failed to make hard link '%s' to '%s': %s\n", + a_path1, a_path2, strerror(errno)); + return (1); + } + } /*Dry run */ + else { + fprintf(stderr, "\t[Dry run: Making hard link '%s' to '%s']\n", + a_path1, a_path2); + } /*Not a dry run */ + } /*Hard link */ /* - * Return the happy news. - */ - return(0); + * Return the happy news. + */ + return (0); -} /*uss_procs_SetLink*/ +} /*uss_procs_SetLink */ /*----------------------------------------------------------------------- @@ -492,13 +493,14 @@ afs_int32 uss_procs_SetLink(a_path1, a_path2, a_type) * As advertised. *------------------------------------------------------------------------*/ -int uss_procs_GetOwner(a_ownerStr) - char *a_ownerStr; +int +uss_procs_GetOwner(a_ownerStr) + char *a_ownerStr; -{ /*uss_procs_GetOwner*/ +{ /*uss_procs_GetOwner */ - struct passwd *pw; /*Ptr to password file entry*/ - int ownerID; /*Numerical owner*/ + struct passwd *pw; /*Ptr to password file entry */ + int ownerID; /*Numerical owner */ ownerID = atoi(a_ownerStr); if ((ownerID == 0) && (a_ownerStr[0] != '0')) { @@ -506,17 +508,15 @@ int uss_procs_GetOwner(a_ownerStr) * The owner is not in numerical format */ if ((pw = getpwnam(a_ownerStr)) == NULL) { - uss_procs_PrintErr(line, - "Owner '%s' is an unknown user\n", + uss_procs_PrintErr(line, "Owner '%s' is an unknown user\n", a_ownerStr); - return(1); + return (1); } - return(pw->pw_uid); - } - else - return(ownerID); + return (pw->pw_uid); + } else + return (ownerID); -} /*uss_procs_GetOwner*/ +} /*uss_procs_GetOwner */ /*----------------------------------------------------------------------- * static Copy @@ -540,12 +540,13 @@ int uss_procs_GetOwner(a_ownerStr) * As advertised. *------------------------------------------------------------------------*/ -static int Copy(a_from, a_to, a_mode) - char *a_from; - char *a_to; - int a_mode; +static int +Copy(a_from, a_to, a_mode) + char *a_from; + char *a_to; + int a_mode; -{ /*Copy*/ +{ /*Copy */ register int fd1, fd2; char buf[BUFSIZ]; @@ -565,20 +566,20 @@ static int Copy(a_from, a_to, a_mode) uss_procs_PrintErr(line, "%s: Failed to open '%s' for overwrite: %s.\n", uss_whoami, a_to, strerror(errno)); - return(1); + return (1); } } else { uss_procs_PrintErr(line, "%s: Failed to open '%s': %s.\n", uss_whoami, a_to, strerror(errno)); - return(1); + return (1); } } if ((fd2 = open(a_from, O_RDONLY, 0)) < 0) { - uss_procs_PrintErr(line, "%s: Error reading '%s': %s\n", - uss_whoami, a_from, strerror(errno)); + uss_procs_PrintErr(line, "%s: Error reading '%s': %s\n", uss_whoami, + a_from, strerror(errno)); close(fd1); - return(1); + return (1); } while ((cnt = read(fd2, buf, BUFSIZ)) == BUFSIZ) write(fd1, buf, cnt); @@ -586,17 +587,16 @@ static int Copy(a_from, a_to, a_mode) write(fd1, buf, cnt); rc = close(fd1); if (rc) { - uss_procs_PrintErr(line, - "Failed to close '%s' %s\n", - a_to, strerror(errno)); - return(1); + uss_procs_PrintErr(line, "Failed to close '%s' %s\n", a_to, + strerror(errno)); + return (1); } - if(rc = close(fd2)) + if (rc = close(fd2)) uss_procs_PrintErr(line, "Warning: Failed to close '%s': %s\n", a_from, strerror(errno)); - return(0); + return (0); -} /*Copy*/ +} /*Copy */ /*----------------------------------------------------------------------- * static Echo @@ -620,12 +620,13 @@ static int Copy(a_from, a_to, a_mode) * As advertised. *------------------------------------------------------------------------*/ -static int Echo(a_s, a_f, a_mode) - char *a_s; - char *a_f; - int a_mode; +static int +Echo(a_s, a_f, a_mode) + char *a_s; + char *a_f; + int a_mode; -{ /*Echo*/ +{ /*Echo */ register int fd; @@ -647,24 +648,24 @@ static int Echo(a_s, a_f, a_mode) uss_procs_PrintErr(line, "%s: Failed to open '%s' for overwrite: %s.\n", uss_whoami, a_f, strerror(errno)); - return(1); + return (1); } } else { uss_procs_PrintErr(line, "%s: Failed to open '%s': %s. \n", uss_whoami, a_f, strerror(errno)); - return(1); + return (1); } } write(fd, a_s, strlen(a_s)); write(fd, "\n", 1); - if (close(fd)){ - uss_procs_PrintErr(line, "Failed to close '%s': %s\n", - a_f, strerror(errno)); - return(1); + if (close(fd)) { + uss_procs_PrintErr(line, "Failed to close '%s': %s\n", a_f, + strerror(errno)); + return (1); } - return(0); + return (0); -} /*Echo*/ +} /*Echo */ /*----------------------------------------------------------------------- * static uss_procs_PickADir @@ -690,41 +691,44 @@ static int Echo(a_s, a_f, a_mode) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_procs_PickADir(path, cp) - char *path; - char *cp; +afs_int32 +uss_procs_PickADir(path, cp) + char *path; + char *cp; -{ /*uss_procs_PickADir*/ +{ /*uss_procs_PickADir */ - char cd[300]; /*Current directory for search*/ + char cd[300]; /*Current directory for search */ int i, count, MinIndex, mina = 10000; struct dirent *dp; DIR *dirp; char dirname[300]; - if (uss_NumGroups == 0){ - fprintf(stderr,"%s: No choice yet given to replace $AUTO\n", + if (uss_NumGroups == 0) { + fprintf(stderr, "%s: No choice yet given to replace $AUTO\n", uss_whoami); - fprintf(stderr,"%s: Use the G command before $AUTO in config file\n", + fprintf(stderr, "%s: Use the G command before $AUTO in config file\n", uss_whoami); - return(-1); + return (-1); } if (uss_Auto[0] != '\0') - return(0); /* we have already done this for this user */ + return (0); /* we have already done this for this user */ - if (*(cp-1) == '/') { /*it's ..../$AUTO*/ + if (*(cp - 1) == '/') { /*it's ..../$AUTO */ for (i = 0; &path[i] != cp; i++) cd[i] = path[i]; cd[i] = '\0'; - } - else { - if (path != cp){ - fprintf(stderr,"%s: $AUTO must be used to replace the whole path or the whole name of a subdirectory. Found: %s$AUTO\n", uss_whoami, path); - return(-1); + } else { + if (path != cp) { + fprintf(stderr, + "%s: $AUTO must be used to replace the whole path or the whole name of a subdirectory. Found: %s$AUTO\n", + uss_whoami, path); + return (-1); } - cd[0] = '/'; cd[1] = '\0'; + cd[0] = '/'; + cd[1] = '\0'; } /* @@ -732,19 +736,19 @@ afs_int32 uss_procs_PickADir(path, cp) * subdirs (by G in template), count the number of entries in * each and pick the minimum. */ - for (i=0; i < uss_NumGroups; i++) { + for (i = 0; i < uss_NumGroups; i++) { sprintf(dirname, "%s/%s", cd, uss_DirPool[i]); if ((dirp = opendir(dirname)) == NULL) { if (errno != ENOTDIR) fprintf(stderr, "%s: Warning: Can't open dir '%s' (errno=%d). Skipped.\n", uss_whoami, dirname, errno); - continue; /*Skip and continue anyway*/ + continue; /*Skip and continue anyway */ } count = 0; for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) if (dp->d_name[0] != '.') - count++; /* forget about files starting with .*/ + count++; /* forget about files starting with . */ #ifdef USS_PROCS_DB printf("debug: Dir '%s' has %d entries\n", dirname, count); #endif /* USS_PROCS_DB */ @@ -754,20 +758,19 @@ afs_int32 uss_procs_PickADir(path, cp) } closedir(dirp); } - if (mina == 10000) { /* We found nothing */ - fprintf(stderr,"%s: Warning: No valid choice to replace $AUTO\n", + if (mina == 10000) { /* We found nothing */ + fprintf(stderr, "%s: Warning: No valid choice to replace $AUTO\n", uss_whoami); - uss_Auto[0]= '\0'; - } - else { + uss_Auto[0] = '\0'; + } else { strcpy(uss_Auto, uss_DirPool[MinIndex]); if (uss_verbose) printf("Picking dir w/minimum number of entries: '%s'\n", uss_Auto); } - return(0); + return (0); -} /*uss_procs_PickADir*/ +} /*uss_procs_PickADir */ /*----------------------------------------------------------------------- * EXPORTED uss_procs_AddToDirPool @@ -779,11 +782,12 @@ afs_int32 uss_procs_PickADir(path, cp) * As advertised. *------------------------------------------------------------------------*/ -int uss_procs_AddToDirPool(a_dirToAdd) - char *a_dirToAdd; +int +uss_procs_AddToDirPool(a_dirToAdd) + char *a_dirToAdd; { if (uss_NumGroups > 99) { - return(-1); + return (-1); } strcpy(uss_DirPool[uss_NumGroups++], a_dirToAdd); return 0; @@ -799,19 +803,20 @@ int uss_procs_AddToDirPool(a_dirToAdd) * As advertised. *------------------------------------------------------------------------*/ -FILE *uss_procs_FindAndOpen(a_fileToOpen) - char *a_fileToOpen; +FILE * +uss_procs_FindAndOpen(a_fileToOpen) + char *a_fileToOpen; -{ /*uss_procs_FindAndOpen*/ +{ /*uss_procs_FindAndOpen */ #define NUM_TPL_PATHS 3 - FILE *rv; /*Template file descriptor*/ - int i; /*Loop counter*/ - char tmp_str[uss_MAX_SIZE]; /*Tmp string*/ + FILE *rv; /*Template file descriptor */ + int i; /*Loop counter */ + char tmp_str[uss_MAX_SIZE]; /*Tmp string */ static char - TemplatePath[NUM_TPL_PATHS][1024]; /*Template directories*/ - int cant_read; /*Can't read the file?*/ + TemplatePath[NUM_TPL_PATHS][1024]; /*Template directories */ + int cant_read; /*Can't read the file? */ /* * If a full pathname was given, just take it as is. @@ -819,18 +824,17 @@ FILE *uss_procs_FindAndOpen(a_fileToOpen) if (strchr(a_fileToOpen, '/')) { strcpy(tmp_str, a_fileToOpen); rv = fopen(a_fileToOpen, "r"); - } - else { + } else { /* * A relative pathname was given. Try to find the file in each of * the default template directories. */ cant_read = 0; - + sprintf(TemplatePath[0], "%s", "."); sprintf(TemplatePath[1], "/afs/%s/common/uss", uss_Cell); sprintf(TemplatePath[2], "%s", "/etc"); - + for (i = 0; i < NUM_TPL_PATHS; i++) { sprintf(tmp_str, "%s/%s", TemplatePath[i], a_fileToOpen); if ((rv = fopen(tmp_str, "r")) != NULL) @@ -844,8 +848,8 @@ FILE *uss_procs_FindAndOpen(a_fileToOpen) cant_read = 1; break; } - } /*Look in template directories*/ - + } /*Look in template directories */ + /* * If we found and opened the file, we're happy. Otherwise, * print out what went wrong. @@ -853,33 +857,31 @@ FILE *uss_procs_FindAndOpen(a_fileToOpen) if (rv != NULL) { if (uss_verbose) fprintf(stderr, "Using template '%s'\n", tmp_str); - } /*Got it*/ + } /*Got it */ else { /* * Check to see if we specifically found the file but * couldn't read it. */ if (cant_read) - fprintf(stderr, - "%s: Can't open template '%s': %s\n", + fprintf(stderr, "%s: Can't open template '%s': %s\n", uss_whoami, tmp_str, strerror(errno)); else { - fprintf(stderr, - "%s: Can't find template '%s' in searchlist", + fprintf(stderr, "%s: Can't find template '%s' in searchlist", uss_whoami, a_fileToOpen); for (i = 0; i < NUM_TPL_PATHS; i++) fprintf(stderr, " '%s'", TemplatePath[i]); fprintf(stderr, "\n"); - } /*Can't find template*/ - } /*Didn't get it*/ - } /*Relative pathname given*/ - + } /*Can't find template */ + } /*Didn't get it */ + } /*Relative pathname given */ + /* * Whatever happened, return what we got. */ - return(rv); + return (rv); -} /*uss_procs_FindAndOpen*/ +} /*uss_procs_FindAndOpen */ /*----------------------------------------------------------------------- @@ -892,19 +894,20 @@ FILE *uss_procs_FindAndOpen(a_fileToOpen) * As advertised. *------------------------------------------------------------------------*/ -void uss_procs_PrintErr(a_lineNum, a_fmt, a_1, a_2, a_3, a_4, a_5) - int a_lineNum; - char *a_fmt; - char *a_1; - char *a_2; - char *a_3; - char *a_4; - char *a_5; +void +uss_procs_PrintErr(a_lineNum, a_fmt, a_1, a_2, a_3, a_4, a_5) + int a_lineNum; + char *a_fmt; + char *a_1; + char *a_2; + char *a_3; + char *a_4; + char *a_5; -{ /*uss_procs_PrintErr*/ +{ /*uss_procs_PrintErr */ uss_syntax_err++; - fprintf(stderr,"%s: Template file, line %d: ", uss_whoami, a_lineNum); + fprintf(stderr, "%s: Template file, line %d: ", uss_whoami, a_lineNum); fprintf(stderr, a_fmt, a_1, a_2, a_3, a_4, a_5); -} /*uss_procs_PrintErr*/ +} /*uss_procs_PrintErr */ diff --git a/src/uss/uss_procs.h b/src/uss/uss_procs.h index e91db59c6..4167bed1e 100644 --- a/src/uss/uss_procs.h +++ b/src/uss/uss_procs.h @@ -19,7 +19,7 @@ /* * --------------------- Required definitions --------------------- */ -#include "uss_common.h" /*Commons uss definitions*/ +#include "uss_common.h" /*Commons uss definitions */ /* @@ -38,15 +38,15 @@ extern afs_int32 uss_procs_BuildDir(); * Create and fully set up a directory for the user. * * Args: - * char *a_path : Pathname of directory to create. - * char *a_mode : Unix mode to set for directory. - * char *a_owner : Directory's owner. - * char *a_access : ACL to set on the directory. + * char *a_path : Pathname of directory to create. + * char *a_mode : Unix mode to set for directory. + * char *a_owner : Directory's owner. + * char *a_access : ACL to set on the directory. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ extern afs_int32 uss_procs_CpFile(); @@ -55,15 +55,15 @@ extern afs_int32 uss_procs_CpFile(); * Copy the given file to the user's directory. * * Args: - * char *a_path : Pathname of file to create. - * char *a_mode : Unix mode to set for file. - * char *a_owner : File's owner. - * char *a_proto : Prototype to copy from. + * char *a_path : Pathname of file to create. + * char *a_mode : Unix mode to set for file. + * char *a_owner : File's owner. + * char *a_proto : Prototype to copy from. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ extern afs_int32 uss_procs_EchoToFile(); @@ -72,15 +72,15 @@ extern afs_int32 uss_procs_EchoToFile(); * Put the specified contents into the given file. * * Args: - * a_path : Pathname of file to fill in. - * a_mode : Unix mode to set for file. - * a_owner : File's owner. - * a_content : Value to insert into file. + * a_path : Pathname of file to fill in. + * a_mode : Unix mode to set for file. + * a_owner : File's owner. + * a_content : Value to insert into file. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ extern afs_int32 uss_procs_Exec(); @@ -89,12 +89,12 @@ extern afs_int32 uss_procs_Exec(); * Execute the given Unix command. * * Args: - * char *a_command : Unix command to execute. + * char *a_command : Unix command to execute. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ extern afs_int32 uss_procs_SetLink(); @@ -103,14 +103,14 @@ extern afs_int32 uss_procs_SetLink(); * Create either the given symbolic or hard link. * * Args: - * char *a_path1 : Name of the link itself. - * char *a_path2 : Name of what the link points to. - * char a_type : Specifies either a symbolic or hard link. + * char *a_path1 : Name of the link itself. + * char *a_path2 : Name of what the link points to. + * char a_type : Specifies either a symbolic or hard link. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ extern int uss_procs_AddToDirPool(); @@ -119,10 +119,10 @@ extern int uss_procs_AddToDirPool(); * Add the given pathname to the $AUTH directory pool * * Args: - * char *a_dirToAdd : Name of directory to add. + * char *a_dirToAdd : Name of directory to add. * * Returns: - * Result of addition. + * Result of addition. */ extern FILE *uss_procs_FindAndOpen(); @@ -133,11 +133,11 @@ extern FILE *uss_procs_FindAndOpen(); * directly. Otherwise, use the default pathname prefixes. * * Args: - * char *a_fileToOpen : Name of file to open. + * char *a_fileToOpen : Name of file to open. * * Returns: - * The file descriptor for the open file (if it could be done), - * NULL otherwise. + * The file descriptor for the open file (if it could be done), + * NULL otherwise. */ extern void uss_procs_PrintErr(); @@ -146,16 +146,16 @@ extern void uss_procs_PrintErr(); * Print out an error connected with template file parsing. * * Args: - * int a_lineNum : Template file line number having the error. - * char *a_fmt : Format string to use. - * char *a_1 : First arg to print. - * char *a_2 : Second ... - * char *a_3 : Third ... - * char *a_4 : Fourth ... - * char *a_5 : Fifth ... + * int a_lineNum : Template file line number having the error. + * char *a_fmt : Format string to use. + * char *a_1 : First arg to print. + * char *a_2 : Second ... + * char *a_3 : Third ... + * char *a_4 : Fourth ... + * char *a_5 : Fifth ... * * Returns: - * Nothing. + * Nothing. */ extern int uss_procs_GetOwner(); @@ -164,10 +164,10 @@ extern int uss_procs_GetOwner(); * Translate the owner string to the owner uid. * * Args: - * char *a_ownerStr : Name of the owner. + * char *a_ownerStr : Name of the owner. * * Returns: - * Owner's uid. + * Owner's uid. */ #endif /* _USS_PROCS_H_ */ diff --git a/src/uss/uss_ptserver.c b/src/uss/uss_ptserver.c index c850096ca..684e2a864 100644 --- a/src/uss/uss_ptserver.c +++ b/src/uss/uss_ptserver.c @@ -18,12 +18,13 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_ptserver.c,v 1.2 2003/01/02 03:55:52 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/uss/uss_ptserver.c,v 1.7 2003/07/15 23:17:12 shadow Exp $"); -#include "uss_ptserver.h" /*Module interface*/ -#include /*Protection Server client interface*/ -#include /*Protection Server error codes*/ -#include /*Error code xlation*/ +#include "uss_ptserver.h" /*Module interface */ +#include /*Protection Server client interface */ +#include /*Protection Server error codes */ +#include /*Error code xlation */ #undef USS_PTSERVER_DB @@ -40,7 +41,7 @@ extern int line; /* * ------------------------ Private globals ----------------------- */ -static int initDone = 0; /*Module initialized?*/ +static int initDone = 0; /*Module initialized? */ /*----------------------------------------------------------------------- @@ -64,40 +65,40 @@ static int initDone = 0; /*Module initialized?*/ * As advertised. *------------------------------------------------------------------------*/ -static afs_int32 InitThisModule() +static afs_int32 +InitThisModule() +{ /*InitThisModule */ -{ /*InitThisModule*/ - - static char rn[] = - "uss_ptserver:InitThisModule"; /*Routine name*/ - register afs_int32 code; /*Return code*/ + static char rn[] = "uss_ptserver:InitThisModule"; /*Routine name */ + register afs_int32 code; /*Return code */ /* * Only once, guys. */ if (initDone) - return(0); + return (0); /* * Connect up with the Protection Server. */ #ifdef USS_PTSERVER_DB - printf("%s: Initializing Protection Server: security=1, confdir = '%s', cell = '%s'\n", - rn, uss_ConfDir, uss_Cell); + printf + ("%s: Initializing Protection Server: security=1, confdir = '%s', cell = '%s'\n", + rn, uss_ConfDir, uss_Cell); #endif /* USS_PTSERVER_DB */ - code = pr_Initialize(1, /*Security level*/ - uss_ConfDir, /*Config directory*/ - uss_Cell); /*Cell to touch*/ + code = pr_Initialize(1, /*Security level */ + uss_ConfDir, /*Config directory */ + uss_Cell); /*Cell to touch */ if (code) { com_err(uss_whoami, code, "while initializing Protection Server library"); - return(code); + return (code); } initDone = 1; - return(0); + return (0); -} /*InitThisModule*/ +} /*InitThisModule */ /*----------------------------------------------------------------------- @@ -111,40 +112,41 @@ static afs_int32 InitThisModule() * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_ptserver_AddUser(a_user, a_uid) - char *a_user; - char *a_uid; +afs_int32 +uss_ptserver_AddUser(a_user, a_uid) + char *a_user; + char *a_uid; + +{ /*uss_ptserver_AddUser */ -{ /*uss_ptserver_AddUser*/ + afs_int32 code; /*Various return codes */ + afs_int32 id = uss_DesiredUID; /*ID desired for user, if any */ + afs_int32 mappedUserID; /*ID user already has */ - afs_int32 code; /*Various return codes*/ - afs_int32 id = uss_DesiredUID; /*ID desired for user, if any*/ - afs_int32 mappedUserID; /*ID user already has*/ - if (uss_verbose) { - fprintf(stderr, "Adding user '%s' to the Protection DB\n", - a_user); + fprintf(stderr, "Adding user '%s' to the Protection DB\n", a_user); if (id) fprintf(stderr, "\t[Presetting uid to %d]\n", id); } - + /* * Make sure we're initialized before doing anything. */ if (!initDone) { code = InitThisModule(); if (code) - return(code); + return (code); } - + /* * If this is a dry run, we still need to setup the uid before * returning. */ if (uss_DryRun) { - fprintf(stderr, "\t[Dry run - user %d not created]\n", uss_DesiredUID); + fprintf(stderr, "\t[Dry run - user %d not created]\n", + uss_DesiredUID); sprintf(a_uid, "%d", uss_DesiredUID); - return(0); + return (0); } /* @@ -152,7 +154,7 @@ afs_int32 uss_ptserver_AddUser(a_user, a_uid) */ code = pr_CreateUser(a_user, &id); if (code) { - if (code == PREXIST || code == PRIDEXIST) { + if (code == PREXIST || code == PRIDEXIST) { if (code == PREXIST) fprintf(stderr, "%s: Warning: '%s' already in the Protection DB\n", @@ -176,43 +178,41 @@ afs_int32 uss_ptserver_AddUser(a_user, a_uid) if (code = pr_SNameToId(a_user, &mappedUserID)) { com_err(uss_whoami, code, "while getting uid from Protection Server"); - return(code); + return (code); } if (mappedUserID == ANONYMOUSID) { fprintf(stderr, "%s: User '%s' unknown, yet given id (%d) already has a mapping!\n", uss_whoami, a_user, id); - return(PRIDEXIST); + return (PRIDEXIST); } if (id == 0) id = mappedUserID; - else - if (mappedUserID != id) { - fprintf(stderr, - "%s: User '%s' already has id %d; won't assign id %d\n", - uss_whoami, a_user, mappedUserID, id); - return(PRIDEXIST); - } - } - else { + else if (mappedUserID != id) { + fprintf(stderr, + "%s: User '%s' already has id %d; won't assign id %d\n", + uss_whoami, a_user, mappedUserID, id); + return (PRIDEXIST); + } + } else { /* * Got a fatal error. */ com_err(uss_whoami, code, "while accessing Protection Server"); - return(code); + return (code); } - } /*Create the user's protection entry*/ - + } + /*Create the user's protection entry */ sprintf(a_uid, "%d", id); if (uss_verbose) fprintf(stderr, "The uid for user '%s' is %s\n", a_user, a_uid); - + /* * Return sweetness & light. */ - return(0); + return (0); -} /*uss_ptserver_AddUser*/ +} /*uss_ptserver_AddUser */ /*----------------------------------------------------------------------- @@ -225,27 +225,28 @@ afs_int32 uss_ptserver_AddUser(a_user, a_uid) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_ptserver_DelUser(a_name) - char *a_name; +afs_int32 +uss_ptserver_DelUser(a_name) + char *a_name; -{ /*uss_ptserver_DelUser*/ +{ /*uss_ptserver_DelUser */ + + afs_int32 code; /*Various return codes */ - afs_int32 code; /*Various return codes*/ - /* * Make sure we're initialized before doing anything. */ if (!initDone) { code = InitThisModule(); if (code) - return(code); + return (code); } if (uss_DryRun) { fprintf(stderr, "\t[Dry run - user '%s' not deleted from Protection DB]\n", a_name); - return(0); + return (0); } if (uss_verbose) @@ -257,7 +258,7 @@ afs_int32 uss_ptserver_DelUser(a_name) */ code = pr_Delete(a_name); if (code) { - if (code == PRNOENT) { + if (code == PRNOENT) { /* * There's no entry for that user in the Protection DB, * so our job is done. @@ -265,20 +266,21 @@ afs_int32 uss_ptserver_DelUser(a_name) fprintf(stderr, "%s: Warning: User '%s' not found in Protection DB\n", uss_whoami, a_name); - } /*User not registered*/ + } /*User not registered */ else { com_err(uss_whoami, code, "while deleting user from Protection DB"); - return(code); - } /*Fatal PTS error*/ - } /*Error in deletion*/ - + return (code); + } /*Fatal PTS error */ + } + + /*Error in deletion */ /* * Return sweetness & light. */ - return(0); + return (0); -} /*uss_ptserver_DelUser*/ +} /*uss_ptserver_DelUser */ /*----------------------------------------------------------------------- @@ -291,14 +293,15 @@ afs_int32 uss_ptserver_DelUser(a_name) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_ptserver_XlateUser(a_user, a_uidP) - char *a_user; - afs_int32 *a_uidP; +afs_int32 +uss_ptserver_XlateUser(a_user, a_uidP) + char *a_user; + afs_int32 *a_uidP; -{ /*uss_ptserver_XlateUser*/ +{ /*uss_ptserver_XlateUser */ - static char rn[] = "uss_ptserver_XlateUser"; /*Routine name*/ - register afs_int32 code; /*Various return codes*/ + static char rn[] = "uss_ptserver_XlateUser"; /*Routine name */ + register afs_int32 code; /*Various return codes */ if (uss_verbose) fprintf(stderr, "Translating user '%s' via the Protection DB\n", @@ -310,7 +313,7 @@ afs_int32 uss_ptserver_XlateUser(a_user, a_uidP) if (!initDone) { code = InitThisModule(); if (code) - return(code); + return (code); } /* @@ -324,13 +327,12 @@ afs_int32 uss_ptserver_XlateUser(a_user, a_uidP) code = pr_SNameToId(a_user, a_uidP); if (code) { com_err(uss_whoami, code, "while getting uid from Protection DB"); - return(code); + return (code); } if (*a_uidP == ANONYMOUSID) { - fprintf(stderr, - "%s: No entry for user '%s' in the Protection DB\n", + fprintf(stderr, "%s: No entry for user '%s' in the Protection DB\n", uss_whoami, a_user); - return(code); + return (code); } /* @@ -339,6 +341,6 @@ afs_int32 uss_ptserver_XlateUser(a_user, a_uidP) #ifdef USS_PTSERVER_DB printf("%s: User '%s' maps to uid %d\n", rn, a_user, *a_uidP); #endif /* USS_PTSERVER_DB */ - return(0); + return (0); -} /*uss_ptserver_XlateUser*/ +} /*uss_ptserver_XlateUser */ diff --git a/src/uss/uss_ptserver.h b/src/uss/uss_ptserver.h index b8ff8ffb8..cbcde2965 100644 --- a/src/uss/uss_ptserver.h +++ b/src/uss/uss_ptserver.h @@ -18,7 +18,7 @@ /* * --------------------- Required definitions --------------------- */ -#include "uss_common.h" /*Commons uss definitions*/ +#include "uss_common.h" /*Commons uss definitions */ /* @@ -30,13 +30,13 @@ extern afs_int32 uss_ptserver_AddUser(); * Register the given user with the Protection Server. * * Args: - * char *a_user : Name of the user to register. - * char *a_uid : Points to the uid registered for the named user. + * char *a_user : Name of the user to register. + * char *a_uid : Points to the uid registered for the named user. * * Returns: - * 0 if everything went well, - * PRIDEXIST if the chosen uid already exists, or - * Code returned from a lower-level call. + * 0 if everything went well, + * PRIDEXIST if the chosen uid already exists, or + * Code returned from a lower-level call. */ extern afs_int32 uss_ptserver_DelUser(); @@ -45,26 +45,26 @@ extern afs_int32 uss_ptserver_DelUser(); * Delete the given user from the Protection Server. * * Args: - * char *a_name : User name to delete. + * char *a_name : User name to delete. * * Returns: - * 0 if everything went well, or - * Code returned from a lower-level call. + * 0 if everything went well, or + * Code returned from a lower-level call. */ extern afs_int32 uss_ptserver_XlateUser(); /* * Summary: * Ask the Protection Server to translate the given user - * name to its corresponding AFS uid. + * name to its corresponding AFS uid. * * Args: - * char *a_user : Name of the user to translate. - * afs_int32 *a_uidP : Points to the uid registered for the named user. + * char *a_user : Name of the user to translate. + * afs_int32 *a_uidP : Points to the uid registered for the named user. * * Returns: - * 0 if everything went well, - * Code returned from a lower-level call. + * 0 if everything went well, + * Code returned from a lower-level call. */ #endif /* _USS_PTSERVER_H_ */ diff --git a/src/uss/uss_vol.c b/src/uss/uss_vol.c index 728846570..d4952d4f8 100644 --- a/src/uss/uss_vol.c +++ b/src/uss/uss_vol.c @@ -18,16 +18,26 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_vol.c,v 1.3 2003/07/30 17:23:45 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/uss/uss_vol.c,v 1.10 2003/07/15 23:17:12 shadow Exp $"); -#include "uss_vol.h" /*Interface to this module*/ -#include "uss_common.h" /*Common definitions*/ -#include "uss_procs.h" /*Defs from procs module*/ -#include "uss_fs.h" /*CacheManager ops*/ +#include "uss_vol.h" /*Interface to this module */ +#include "uss_common.h" /*Common definitions */ +#include "uss_procs.h" /*Defs from procs module */ +#include "uss_fs.h" /*CacheManager ops */ #include #include #include #include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include @@ -39,7 +49,6 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/uss/uss_vol.c,v 1.3 2003/07/30 17:23:45 #include extern struct rx_connection *UV_Bind(); -extern struct rx_securityClass *rxnull_NewClientSecurityObject(); extern int line; extern int VL_GetEntryByID(); extern char *hostutil_GetNameByINet(); @@ -61,17 +70,17 @@ extern char *hostutil_GetNameByINet(); * is why we have two names here. Thus, the UV_CreateVolume() * will work and we can avoid nasty little core dumps. */ -struct ubik_client *uconn_vldbP; /*Ubik connection struct*/ -struct ubik_client *cstruct; /*Required name for above*/ +struct ubik_client *uconn_vldbP; /*Ubik connection struct */ +struct ubik_client *cstruct; /*Required name for above */ /* * ------------------------ Private globals ----------------------- */ -static int initDone = 0; /*Module initialized?*/ -static int NoAuthFlag = 0; /*Use -noauth?*/ +static int initDone = 0; /*Module initialized? */ +static int NoAuthFlag = 0; /*Use -noauth? */ static struct rx_connection - *serverconns[VLDB_MAXSERVERS]; /*Connection(s) to VLDB - server(s)*/ + *serverconns[VLDB_MAXSERVERS]; /*Connection(s) to VLDB + * server(s) */ /*----------------------------------------------------------------------- @@ -98,22 +107,23 @@ static struct rx_connection * As advertised. *------------------------------------------------------------------------*/ -static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName) - int a_noAuthFlag; - char *a_confDir; - char *a_cellName; +static afs_int32 +InitThisModule(a_noAuthFlag, a_confDir, a_cellName) + int a_noAuthFlag; + char *a_confDir; + char *a_cellName; -{ /*InitThisModule*/ +{ /*InitThisModule */ static char rn[] = "uss_vol:InitThisModule"; - register afs_int32 code; /*Return code*/ - struct afsconf_dir *tdir; /*Ptr to conf dir info*/ - struct afsconf_cell info; /*Info about chosen cell*/ - struct ktc_principal sname; /*Service name*/ - struct ktc_token ttoken; /*Service ticket*/ - afs_int32 scIndex; /*Chosen security index*/ - struct rx_securityClass *sc; /*Generated security object*/ - afs_int32 i; /*Loop index*/ + register afs_int32 code; /*Return code */ + struct afsconf_dir *tdir; /*Ptr to conf dir info */ + struct afsconf_cell info; /*Info about chosen cell */ + struct ktc_principal sname; /*Service name */ + struct ktc_token ttoken; /*Service ticket */ + afs_int32 scIndex; /*Chosen security index */ + struct rx_securityClass *sc; /*Generated security object */ + afs_int32 i; /*Loop index */ /* * Only once, guys, will 'ya? @@ -122,19 +132,19 @@ static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName) #ifdef USS_VOL_DB printf("[%s] Called multiple times!\n", rn); #endif /* USS_VOL_DB */ - return(0); + return (0); } /* * Set up our Rx environment. */ #ifdef USS_VOL_DB - printf("[%s] Initializing Rx environment\n", rn); + printf("[%s] Initializing Rx environment\n", rn); #endif /* USS_VOL_DB */ code = rx_Init(0); if (code) { - fprintf(stderr,"%s: Couldn't initialize Rx.\n", uss_whoami); - return(code); + fprintf(stderr, "%s: Couldn't initialize Rx.\n", uss_whoami); + return (code); } rx_SetRxDeadTime(50); @@ -142,23 +152,22 @@ static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName) * Find out all about our configuration. */ #ifdef USS_VOL_DB - printf("[%s] Handling configuration info\n", rn); + printf("[%s] Handling configuration info\n", rn); #endif /* USS_VOL_DB */ tdir = afsconf_Open(a_confDir); if (!tdir) { fprintf(stderr, "%s: Couldn't open configuration directory (%s).\n", uss_whoami, a_confDir); - return(-1); + return (-1); } code = afsconf_GetCellInfo(tdir, a_cellName, AFSCONF_VLDBSERVICE, &info); if (code) { - printf("%s: Can't find VLDB server(s) for cell %s\n", - uss_whoami, a_cellName); + printf("%s: Can't find VLDB server(s) for cell %s\n", uss_whoami, + a_cellName); exit(1); } - #ifdef USS_VOL_DB - printf("[%s] Getting tickets if needed\n", rn); + printf("[%s] Getting tickets if needed\n", rn); #endif /* USS_VOL_DB */ if (!a_noAuthFlag) { /* @@ -167,26 +176,25 @@ static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName) strcpy(sname.cell, info.name); sname.instance[0] = 0; strcpy(sname.name, "afs"); - code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0); + code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL); if (code) { fprintf(stderr, "%s: Couldn't get AFS tokens, running unauthenticated.\n", uss_whoami); scIndex = 0; - } - else { + } else { /* * We got a ticket, go for an authenticated connection. */ - if (ttoken.kvno >= 0 && ttoken.kvno <= 255) - scIndex = 2; /*Kerberos*/ + if (ttoken.kvno >= 0 && ttoken.kvno <= 255) + scIndex = 2; /*Kerberos */ else { fprintf(stderr, "%s: Funny kvno (%d) in ticket, proceeding\n", - uss_whoami, ttoken.kvno); + uss_whoami, ttoken.kvno); scIndex = 2; } - } /*Got a ticket*/ - } /*Authentication desired*/ + } /*Got a ticket */ + } /*Authentication desired */ else scIndex = 0; @@ -194,35 +202,32 @@ static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName) * Generate the appropriate security object for the connection. */ #ifdef USS_VOL_DB - printf("[%s] Generating Rx security object\n", rn); + printf("[%s] Generating Rx security object\n", rn); #endif /* USS_VOL_DB */ - switch(scIndex) { - case 0: - sc = (struct rx_securityClass *) - rxnull_NewClientSecurityObject(); - break; - - case 1: - break; - - case 2: - sc = (struct rx_securityClass *) - rxkad_NewClientSecurityObject(rxkad_clear, - &ttoken.sessionKey, - ttoken.kvno, - ttoken.ticketLen, - ttoken.ticket); - break; + switch (scIndex) { + case 0: + sc = (struct rx_securityClass *) + rxnull_NewClientSecurityObject(); + break; + + case 1: + break; + + case 2: + sc = (struct rx_securityClass *) + rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey, + ttoken.kvno, ttoken.ticketLen, + ttoken.ticket); + break; } /* * Tell UV module about default authentication. */ #ifdef USS_VOL_DB - printf("[%s] Setting UV security: obj 0x%x, index %d\n", - rn, sc, scIndex); + printf("[%s] Setting UV security: obj 0x%x, index %d\n", rn, sc, scIndex); #endif /* USS_VOL_DB */ - UV_SetSecurity(sc, scIndex); + UV_SetSecurity(sc, scIndex); if (info.numServers > VLDB_MAXSERVERS) { fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", uss_whoami, info.numServers, VLDB_MAXSERVERS); @@ -234,32 +239,30 @@ static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName) */ for (i = 0; i < info.numServers; i++) { #ifdef USS_VOL_DB - printf("[%s] Connecting to VLDB server 0x%x, port %d, service id %d\n", - rn, info.hostAddr[i].sin_addr.s_addr, - info.hostAddr[i].sin_port, - USER_SERVICE_ID); + printf + ("[%s] Connecting to VLDB server 0x%x, port %d, service id %d\n", + rn, info.hostAddr[i].sin_addr.s_addr, info.hostAddr[i].sin_port, + USER_SERVICE_ID); #endif /* USS_VOL_DB */ - serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr, - info.hostAddr[i].sin_port, - USER_SERVICE_ID, - sc, - scIndex); + serverconns[i] = + rx_NewConnection(info.hostAddr[i].sin_addr.s_addr, + info.hostAddr[i].sin_port, USER_SERVICE_ID, sc, + scIndex); } /* * Set up to execute Ubik transactions on the VLDB. */ #ifdef USS_VOL_DB - printf("[%s] Initializing Ubik interface\n", rn); + printf("[%s] Initializing Ubik interface\n", rn); #endif /* USS_VOL_DB */ code = ubik_ClientInit(serverconns, &uconn_vldbP); if (code) { fprintf(stderr, "%s: Ubik client init failed.\n", uss_whoami); - return(code); + return (code); } #ifdef USS_VOL_DB - printf("[%s] VLDB ubik connection structure at 0x%x\n", - rn, uconn_vldbP); + printf("[%s] VLDB ubik connection structure at 0x%x\n", rn, uconn_vldbP); #endif /* USS_VOL_DB */ /* @@ -272,9 +275,9 @@ static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName) * Success! */ initDone = 1; - return(0); + return (0); -} /*InitThisModule*/ +} /*InitThisModule */ /*----------------------------------------------------------------------- @@ -301,15 +304,16 @@ static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName) char *hostutil_GetNameByINet(); -static void HostIDToHostName(a_hostID, a_hostName) - afs_int32 a_hostID; - char *a_hostName; +static void +HostIDToHostName(a_hostID, a_hostName) + afs_int32 a_hostID; + char *a_hostName; -{ /*HostIDToHostName*/ +{ /*HostIDToHostName */ strcpy(a_hostName, hostutil_GetNameByINet(a_hostID)); -} /*HostIDToHostName*/ +} /*HostIDToHostName */ /*----------------------------------------------------------------------- @@ -334,41 +338,41 @@ static void HostIDToHostName(a_hostID, a_hostName) * As advertised. *------------------------------------------------------------------------*/ -static afs_int32 PartIDToPartName(a_partID, a_partName) - afs_int32 a_partID; - char *a_partName; +static afs_int32 +PartIDToPartName(a_partID, a_partName) + afs_int32 a_partID; + char *a_partName; -{ /*PartIDToPartName*/ +{ /*PartIDToPartName */ static char rn[] = "PartIDToPartName"; #ifdef USS_VOL_DB - printf("[%s] Translating partition id %d to its name\n", - rn, a_partID); + printf("[%s] Translating partition id %d to its name\n", rn, a_partID); #endif /* USS_VOL_DB */ - + if ((a_partID < 0) || (a_partID > VOLMAXPARTS)) - return(-1); + return (-1); - if(a_partID < 26) { - strcpy(a_partName,"/vicep"); + if (a_partID < 26) { + strcpy(a_partName, "/vicep"); a_partName[6] = a_partID + 'a'; a_partName[7] = '\0'; } else { - strcpy(a_partName,"/vicep"); + strcpy(a_partName, "/vicep"); a_partID -= 26; - a_partName[6] = 'a' + (a_partID/26); - a_partName[7] = 'a' + (a_partID%26); + a_partName[6] = 'a' + (a_partID / 26); + a_partName[7] = 'a' + (a_partID % 26); a_partName[8] = '\0'; } #ifdef USS_VOL_DB - printf("[%s] Translation for part ID %d is '%s'\n", - rn, a_partID, a_partName); + printf("[%s] Translation for part ID %d is '%s'\n", rn, a_partID, + a_partName); #endif /* USS_VOL_DB */ - return(0); + return (0); -} /*PartIDToPartName*/ +} /*PartIDToPartName */ /*------------------------------------------------------------------------ @@ -381,10 +385,11 @@ static afs_int32 PartIDToPartName(a_partID, a_partName) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_vol_GetServer(a_name) - char *a_name; +afs_int32 +uss_vol_GetServer(a_name) + char *a_name; -{ /*uss_vol_GetServer*/ +{ /*uss_vol_GetServer */ register struct hostent *th; afs_int32 addr; @@ -397,17 +402,19 @@ afs_int32 uss_vol_GetServer(a_name) * Parsed as 128.2.9.4, or similar; return it in network * byte order (128 in byte 0). */ - addr = (((afs_int32)b1)<<24) | (((afs_int32)b2)<<16) | (((afs_int32)b3)<<8) | (afs_int32)b4; + addr = + (((afs_int32) b1) << 24) | (((afs_int32) b2) << 16) | + (((afs_int32) b3) << 8) | (afs_int32) b4; return htonl(addr); } th = gethostbyname(a_name); if (!th) - return(0); + return (0); memcpy(&addr, th->h_addr, sizeof(addr)); - return(addr); + return (addr); -} /*uss_vol_GetServer*/ +} /*uss_vol_GetServer */ /*------------------------------------------------------------------------ * static GetVolumeType @@ -429,23 +436,22 @@ afs_int32 uss_vol_GetServer(a_name) * As advertised. *------------------------------------------------------------------------*/ -static afs_int32 GetVolumeType(a_type) - char *a_type; +static afs_int32 +GetVolumeType(a_type) + char *a_type; -{ /*GetVolumeType*/ +{ /*GetVolumeType */ - if(!strcmp(a_type,"ro")) - return(ROVOL); + if (!strcmp(a_type, "ro")) + return (ROVOL); + else if (!strcmp(a_type, "rw")) + return (RWVOL); + else if (!strcmp(a_type, "bk")) + return (BACKVOL); else - if(!strcmp(a_type, "rw")) - return(RWVOL); - else - if(!strcmp(a_type,"bk")) - return(BACKVOL); - else - return(-1); + return (-1); -} /*GetVolumeType*/ +} /*GetVolumeType */ /*------------------------------------------------------------------------ @@ -458,23 +464,24 @@ static afs_int32 GetVolumeType(a_type) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_vol_GetPartitionID(a_name) - char *a_name; +afs_int32 +uss_vol_GetPartitionID(a_name) + char *a_name; -{ /*uss_vol_GetPartitionID*/ +{ /*uss_vol_GetPartitionID */ register char tc; char ascii[3]; tc = *a_name; if (tc == 0) - return(-1); + return (-1); /* * Numbers go straight through. */ if (tc >= '0' && tc <= '9') { - return(atoi(a_name)); + return (atoi(a_name)); } /* @@ -484,13 +491,11 @@ afs_int32 uss_vol_GetPartitionID(a_name) if (strlen(a_name) <= 2) { strcpy(ascii, a_name); } else if (!strncmp(a_name, "/vicep", 6)) { - strncpy(ascii, a_name+6, 2); - } - else if (!strncmp(a_name, "vicep", 5)) { - strncpy(ascii, a_name+5, 2); - } - else - return(-1); + strncpy(ascii, a_name + 6, 2); + } else if (!strncmp(a_name, "vicep", 5)) { + strncpy(ascii, a_name + 5, 2); + } else + return (-1); /* * Now, partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, @@ -500,21 +505,20 @@ afs_int32 uss_vol_GetPartitionID(a_name) /* * Single-char name, 0..25 */ - if (ascii[0] < 'a' || ascii[0] > 'z') - return(-1); /* wrongo */ - return(ascii[0] - 'a'); - } - else { + if (ascii[0] < 'a' || ascii[0] > 'z') + return (-1); /* wrongo */ + return (ascii[0] - 'a'); + } else { /* * Two-char name, 26 .. */ - if (ascii[0] < 'a' || ascii[0] > 'z') - return(-1); - if (ascii[1] < 'a' || ascii[1] > 'z') - return(-1); - return((ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26); + if (ascii[0] < 'a' || ascii[0] > 'z') + return (-1); + if (ascii[1] < 'a' || ascii[1] > 'z') + return (-1); + return ((ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26); } -} /*uss_vol_GetPartitionID*/ +} /*uss_vol_GetPartitionID */ /*----------------------------------------------------------------------- @@ -546,35 +550,36 @@ afs_int32 uss_vol_GetPartitionID(a_name) * mountpoint. *------------------------------------------------------------------------*/ -static int CheckDoubleMount(a_mp, a_oldmp) - char *a_mp; - char *a_oldmp; +static int +CheckDoubleMount(a_mp, a_oldmp) + char *a_mp; + char *a_oldmp; -{ /*CheckDoubleMount*/ +{ /*CheckDoubleMount */ static char rn[] = "uss_vol:CheckDoubleMount"; int start, len, mlen, tlen; int i = 0; struct passwd *pws; struct stat stbuf; - + pws = getpwuid(atoi(uss_Uid)); - if (pws != (struct passwd *)0) { + if (pws != NULL) { /* * User exists in the password file, so they've been fully * created and integrated. Return the ``ancient'' mountpoint. */ strcpy(a_oldmp, pws->pw_dir); - return(uss_procs_ANCIENT); + return (uss_procs_ANCIENT); } - + if (uss_NumGroups) { /* * $AUTO used. Search among the possible directories. */ len = strlen(uss_Auto); mlen = strlen(a_mp); - while(strncmp(&a_mp[i], uss_Auto, len)) { + while (strncmp(&a_mp[i], uss_Auto, len)) { a_oldmp[i] = a_mp[i]; if (++i > (mlen - len)) { i = -1; @@ -591,30 +596,31 @@ static int CheckDoubleMount(a_mp, a_oldmp) */ tlen = strlen(uss_DirPool[i]); strncpy(&a_oldmp[start], uss_DirPool[i], tlen); - strcpy(&a_oldmp[start+tlen], &a_mp[start+len]); + strcpy(&a_oldmp[start + tlen], &a_mp[start + len]); #ifdef USS_VOL_DB - printf("%s: Checking '%s' for mount point\n", - rn, a_oldmp); + printf("%s: Checking '%s' for mount point\n", rn, a_oldmp); #endif /* USS_VOL_DB */ - if(lstat(a_oldmp, &stbuf) == 0) /*mp exists*/ - if (strcmp(a_oldmp, a_mp)) /* and is different */ - /* + if (lstat(a_oldmp, &stbuf) == 0) /*mp exists */ + if (strcmp(a_oldmp, a_mp)) + /* and is different */ + /* * The old mount point exists and is different * from the current one, so return the fact * that we have a ``young'' mountpoint. */ - return(uss_procs_YOUNG); - } /*Check each $AUTO directory*/ + return (uss_procs_YOUNG); + } /*Check each $AUTO directory */ } - } /*$AUTO has been used*/ - + } + + /*$AUTO has been used */ /* * No luck finding the old mount point, so we just return that * this is the first time we've seen this volume. */ - return(0); - -} /*CheckDoubleMount*/ + return (0); + +} /*CheckDoubleMount */ /*------------------------------------------------------------------------ @@ -627,41 +633,43 @@ static int CheckDoubleMount(a_mp, a_oldmp) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, a_owner, a_acl) - char *a_volname; - char *a_server; - char *a_partition; - char *a_quota; - char *a_mpoint; - char *a_owner; - char *a_acl; - -{ /*uss_vol_CreateVol*/ - - static char rn[] = - "uss_vol_CreateVol"; /*Routine name*/ - afs_int32 pname; /*Partition name*/ - afs_int32 volid, code; /*Volume ID, return code*/ - afs_int32 saddr; /*Socket info for server*/ - int VolExistFlag = 0; /*Does the volume exist?*/ - int mpExistFlag = 0; /*Does the mountpoint exist?*/ - char *Oldmpoint = NULL; /*Old mountpoint name, if any*/ - char tmp_str[uss_MAX_SIZE]; /*Useful string buffer*/ - int o; /*Owner's user id*/ - char userinput[64]; /*User's input*/ - struct uss_subdir *new_dir; /*Used to remember original ACL*/ +afs_int32 +uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, + a_owner, a_acl) + char *a_volname; + char *a_server; + char *a_partition; + char *a_quota; + char *a_mpoint; + char *a_owner; + char *a_acl; + +{ /*uss_vol_CreateVol */ + + static char rn[] = "uss_vol_CreateVol"; /*Routine name */ + afs_int32 pname; /*Partition name */ + afs_int32 volid, code; /*Volume ID, return code */ + afs_int32 saddr; /*Socket info for server */ + int VolExistFlag = 0; /*Does the volume exist? */ + int mpExistFlag = 0; /*Does the mountpoint exist? */ + char *Oldmpoint = NULL; /*Old mountpoint name, if any */ + char tmp_str[uss_MAX_SIZE]; /*Useful string buffer */ + int o; /*Owner's user id */ + char userinput[64]; /*User's input */ + struct uss_subdir *new_dir; /*Used to remember original ACL */ /* * Don't do anything if there's already a problem. */ if (uss_syntax_err) - return(1); + return (1); #ifdef USS_VOL_DB fprintf(stderr, "%s:uss_vol_CreateVol params:\n", rn); - fprintf(stderr, "%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n", - rn, a_volname, a_server, a_partition, a_quota, a_mpoint, - a_owner, a_acl); + fprintf(stderr, + "%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n", + rn, a_volname, a_server, a_partition, a_quota, a_mpoint, a_owner, + a_acl); #endif /* USS_VOL_DB */ /* @@ -671,57 +679,58 @@ afs_int32 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, */ if (uss_Server[0] != '\0') { #ifdef USS_VOL_DB_SHOW_OVERRIDES - if (uss_verbose) - fprintf(stderr, - "%s: Overriding server field: template value is '%s', overridden to '%s'\n", - rn, a_server, uss_Server); + if (uss_verbose) + fprintf(stderr, + "%s: Overriding server field: template value is '%s', overridden to '%s'\n", + rn, a_server, uss_Server); #endif /* USS_VOL_DB_SHOW_OVERRIDES */ - a_server = uss_Server; + a_server = uss_Server; } if (uss_Partition[0] != '\0') { #ifdef USS_VOL_DB_SHOW_OVERRIDES - if (uss_verbose) - fprintf(stderr, "%s: Overriding partition field: template value is '%s', overridden to '%s'\n", - rn, a_partition, uss_Partition); + if (uss_verbose) + fprintf(stderr, + "%s: Overriding partition field: template value is '%s', overridden to '%s'\n", + rn, a_partition, uss_Partition); #endif /* USS_VOL_DB_SHOW_OVERRIDES */ - a_partition = uss_Partition; + a_partition = uss_Partition; } if (uss_MountPoint[0] != '\0') { #ifdef USS_VOL_DB_SHOW_OVERRIDES - if (uss_verbose) - fprintf(stderr, "%s: overriding mountpoint field: template value is '%s', overridden to '%s'\n", - rn, a_mpoint, uss_MountPoint); + if (uss_verbose) + fprintf(stderr, + "%s: overriding mountpoint field: template value is '%s', overridden to '%s'\n", + rn, a_mpoint, uss_MountPoint); #endif /* USS_VOL_DB_SHOW_OVERRIDES */ - a_mpoint = uss_MountPoint; + a_mpoint = uss_MountPoint; } - #ifdef USS_VOL_DB_SHOW_OVERRIDES printf("%s: Params after overrides:\n", uss_whoami); - printf("%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n", - uss_whoami, a_volname, a_server, a_partition, a_quota, - a_mpoint, a_owner, a_acl); + printf + ("%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n", + uss_whoami, a_volname, a_server, a_partition, a_quota, a_mpoint, + a_owner, a_acl); #endif /* USS_VOL_DB_SHOW_OVERRIDES */ if (uss_verbose) fprintf(stderr, "Creating volume '%s' on server '%s', partition '%s'\n", a_volname, a_server, a_partition); - + saddr = uss_vol_GetServer(a_server); if (!saddr) { uss_procs_PrintErr(line, "File server '%s' not found in config info\n", a_server); - return(1); + return (1); } pname = uss_vol_GetPartitionID(a_partition); if (pname < 0) { - uss_procs_PrintErr(line, - "Couldn't interpret partition name '%s'\n", - a_partition); - return(1); + uss_procs_PrintErr(line, "Couldn't interpret partition name '%s'\n", + a_partition); + return (1); } /* @@ -733,54 +742,54 @@ afs_int32 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, if (code) { com_err(uss_whoami, code, "while inititializing VLDB connection(s)\n"); - return(code); + return (code); } - } /*Initialize VLDB connection(s)*/ - + } + /*Initialize VLDB connection(s) */ if (!uss_DryRun) { #ifdef USS_VOL_DB - printf("%s: Creating volume on srv 0x%x, part %d, vol name '%s'\n", - rn, saddr, pname, a_volname); + printf("%s: Creating volume on srv 0x%x, part %d, vol name '%s'\n", + rn, saddr, pname, a_volname); #endif /* USS_VOL_DB */ - code = UV_CreateVolume(saddr, pname, a_volname, &volid); - if (code) { - if (code == VL_NAMEEXIST){ - VolExistFlag = 1; - fprintf(stderr, - "%s: Warning; Volume '%s' exists, using existing one.\n", - uss_whoami, a_volname); - - /* - * We should get the volid here if we want to use it, but - * we don't need it right now. What we DO need, though, is - * to ask our caller if it's OK to overwrite the user's files - * if they're pre-existing. - */ - if (!uss_OverwriteThisOne) { - printf("Overwrite files in pre-existing '%s' volume? [y, n]: ", - a_volname); - scanf("%s", userinput); - if ((userinput[0] == 'y') || (userinput[0] == 'Y')) { - printf("\t[Overwriting allowed]\n"); - uss_OverwriteThisOne = 1; - } - else - printf("\t[Overwriting not permitted]\n"); - } /*Overwriting not previously allowed*/ - } /*Volume already existed*/ - else { - uss_procs_PrintErr(line, - "Couldn't create volume '%s' [error %d]: %s\n", - a_volname, code, strerror(errno)); - return(1); - } /*Failure was NOT because it already existed*/ - } /*UV_CreateVolume failed*/ - } /*Not a dry run*/ + code = UV_CreateVolume(saddr, pname, a_volname, &volid); + if (code) { + if (code == VL_NAMEEXIST) { + VolExistFlag = 1; + fprintf(stderr, + "%s: Warning; Volume '%s' exists, using existing one.\n", + uss_whoami, a_volname); + + /* + * We should get the volid here if we want to use it, but + * we don't need it right now. What we DO need, though, is + * to ask our caller if it's OK to overwrite the user's files + * if they're pre-existing. + */ + if (!uss_OverwriteThisOne) { + printf + ("Overwrite files in pre-existing '%s' volume? [y, n]: ", + a_volname); + scanf("%s", userinput); + if ((userinput[0] == 'y') || (userinput[0] == 'Y')) { + printf("\t[Overwriting allowed]\n"); + uss_OverwriteThisOne = 1; + } else + printf("\t[Overwriting not permitted]\n"); + } /*Overwriting not previously allowed */ + } /*Volume already existed */ + else { + uss_procs_PrintErr(line, + "Couldn't create volume '%s' [error %d]: %s\n", + a_volname, code, strerror(errno)); + return (1); + } /*Failure was NOT because it already existed */ + } /*UV_CreateVolume failed */ + } /*Not a dry run */ else { - fprintf(stderr, - "\t[Dry run: Creating volume '%s' on '%s', partition '%s']\n", - a_volname, a_server, a_partition); - } /*Not a dry run*/ + fprintf(stderr, + "\t[Dry run: Creating volume '%s' on '%s', partition '%s']\n", + a_volname, a_server, a_partition); + } /*Not a dry run */ /* OK, we want to make sure we don't double-mount the volume. * If the volume existed, it can be the case that it is @@ -789,19 +798,20 @@ afs_int32 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, * the code if we're doing a dry run. */ if (VolExistFlag) { - if ((Oldmpoint = (char *) malloc(strlen(a_mpoint)+50)) == NULL){ - fprintf(stderr, "%s: No more memory!\n", uss_whoami); - return(1); + if ((Oldmpoint = (char *)malloc(strlen(a_mpoint) + 50)) == NULL) { + fprintf(stderr, "%s: No more memory!\n", uss_whoami); + return (1); } mpExistFlag = CheckDoubleMount(a_mpoint, Oldmpoint); - if(mpExistFlag == uss_procs_ANCIENT) { + if (mpExistFlag == uss_procs_ANCIENT) { fprintf(stderr, - "%s:\t*** WARNING ***; This user (%s) is already in passwd file (or equivalent). IGNORED.\n", uss_whoami, uss_User); + "%s:\t*** WARNING ***; This user (%s) is already in passwd file (or equivalent). IGNORED.\n", + uss_whoami, uss_User); free(Oldmpoint); - uss_syntax_err = 1; /*I know, I know, it's not a SYNTAX error*/ + uss_syntax_err = 1; /*I know, I know, it's not a SYNTAX error */ uss_ignoreFlag = 1; - return(0); + return (0); } if (mpExistFlag == uss_procs_YOUNG) { fprintf(stderr, @@ -821,59 +831,60 @@ afs_int32 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, else sprintf(tmp_str, "#%s:%s.", uss_Cell, a_volname); if (!uss_DryRun) { - if (symlink(tmp_str, a_mpoint)) { - if (errno == EEXIST) { - fprintf(stderr, - "%s: Warning: Mount point '%s' already exists.\n", - uss_whoami, a_mpoint); - } - else { - fprintf(stderr,"%s: Can't mount volume '%s' on '%s': %s\n", - uss_whoami, a_volname, a_mpoint, strerror(errno)); - if (Oldmpoint) - free(Oldmpoint); - return(1); - } /*There was already something mounted there*/ - } /*Mount failed*/ - } /*Dry run*/ + if (symlink(tmp_str, a_mpoint)) { + if (errno == EEXIST) { + fprintf(stderr, + "%s: Warning: Mount point '%s' already exists.\n", + uss_whoami, a_mpoint); + } else { + fprintf(stderr, + "%s: Can't mount volume '%s' on '%s': %s\n", + uss_whoami, a_volname, a_mpoint, strerror(errno)); + if (Oldmpoint) + free(Oldmpoint); + return (1); + } /*There was already something mounted there */ + } /*Mount failed */ + } /*Dry run */ else { - fprintf(stderr, "\t[Dry run: Mounting '%s' at '%s']\n", - tmp_str, a_mpoint); - } /*Not a dry run*/ - } /*Mount point didn't already exist*/ + fprintf(stderr, "\t[Dry run: Mounting '%s' at '%s']\n", tmp_str, + a_mpoint); + } /*Not a dry run */ + } + /*Mount point didn't already exist */ /* * Set the volume disk quota. */ if (!uss_DryRun) { - if (code = uss_acl_SetDiskQuota(a_mpoint, atoi(a_quota))) - return(code); - } /*Dry run*/ + if (code = uss_acl_SetDiskQuota(a_mpoint, atoi(a_quota))) + return (code); + } /*Dry run */ else { - fprintf(stderr, - "\t[Dry run: Setting disk quota for '%s' to %s blocks]\n", - a_mpoint, a_quota); - } /*Not a dry run*/ + fprintf(stderr, + "\t[Dry run: Setting disk quota for '%s' to %s blocks]\n", + a_mpoint, a_quota); + } /*Not a dry run */ - /*Copy mpoint into $MTPT for others to use*/ + /*Copy mpoint into $MTPT for others to use */ strcpy(uss_MountPoint, a_mpoint); o = uss_procs_GetOwner(a_owner); if (!uss_DryRun) { - if (chown(a_mpoint, o, -1)) { - fprintf(stderr, - "%s: Can't chown() mountpoint '%s' to owner '%s' (uid %d): %s\n", - uss_whoami, a_mpoint, a_owner, o, strerror(errno)); - if (Oldmpoint) - free(Oldmpoint); - return(1); - } /*chown failed*/ - } /*Dry run*/ + if (chown(a_mpoint, o, -1)) { + fprintf(stderr, + "%s: Can't chown() mountpoint '%s' to owner '%s' (uid %d): %s\n", + uss_whoami, a_mpoint, a_owner, o, strerror(errno)); + if (Oldmpoint) + free(Oldmpoint); + return (1); + } /*chown failed */ + } /*Dry run */ else { - fprintf(stderr, - "\t[Dry run: chown() mountpoint '%s' to be owned by user]\n", - a_mpoint); - } /*Not a dry run*/ + fprintf(stderr, + "\t[Dry run: chown() mountpoint '%s' to be owned by user]\n", + a_mpoint); + } /*Not a dry run */ /* * Set the ACL on the user's home directory so that, for the duration of @@ -883,30 +894,29 @@ afs_int32 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, * properly, as well as all ACLs of future subdirectories,as the very last * thing we do to the new account. */ - new_dir = (struct uss_subdir *) malloc(sizeof(struct uss_subdir)); + new_dir = (struct uss_subdir *)malloc(sizeof(struct uss_subdir)); new_dir->previous = uss_currentDir; - new_dir->path = (char *) malloc(strlen(a_mpoint)+1); + new_dir->path = (char *)malloc(strlen(a_mpoint) + 1); strcpy(new_dir->path, a_mpoint); - new_dir->finalACL = (char *) malloc(strlen(a_acl)+1); + new_dir->finalACL = (char *)malloc(strlen(a_acl) + 1); strcpy(new_dir->finalACL, a_acl); uss_currentDir = new_dir; sprintf(tmp_str, "%s %s all", a_mpoint, uss_AccountCreator); if (Oldmpoint) - free(Oldmpoint); + free(Oldmpoint); if (!uss_DryRun) { if (uss_verbose) - fprintf(stderr, "Setting ACL: '%s'\n", - tmp_str); + fprintf(stderr, "Setting ACL: '%s'\n", tmp_str); if (uss_acl_SetAccess(tmp_str, 1, 0)) - return(1); - } /*For real*/ + return (1); + } /*For real */ else { - fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s)]\n", tmp_str); + fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s)]\n", tmp_str); } - return(0); -} /*uss_vol_CreateVol*/ + return (0); +} /*uss_vol_CreateVol */ /*------------------------------------------------------------------------ @@ -919,18 +929,20 @@ afs_int32 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_vol_DeleteVol(a_volName, a_volID, a_servName, a_servID, a_partName, a_partID) - char *a_volName; - afs_int32 a_volID; - char *a_servName; - afs_int32 a_servID; - char *a_partName; - afs_int32 a_partID; +afs_int32 +uss_vol_DeleteVol(a_volName, a_volID, a_servName, a_servID, a_partName, + a_partID) + char *a_volName; + afs_int32 a_volID; + char *a_servName; + afs_int32 a_servID; + char *a_partName; + afs_int32 a_partID; -{ /*uss_vol_DeleteVol*/ +{ /*uss_vol_DeleteVol */ - static char rn[] = "uss_vol_DeleteVol"; /*Routine name*/ - register afs_int32 code; /*Return code*/ + static char rn[] = "uss_vol_DeleteVol"; /*Routine name */ + register afs_int32 code; /*Return code */ /* * Make sure we've initialized our VLDB connection(s) before @@ -939,7 +951,7 @@ afs_int32 uss_vol_DeleteVol(a_volName, a_volID, a_servName, a_servID, a_partName if (!initDone) { code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell); if (code) - return(code); + return (code); } if (!uss_DryRun) { @@ -947,21 +959,21 @@ afs_int32 uss_vol_DeleteVol(a_volName, a_volID, a_servName, a_servID, a_partName * Go for the deletion. */ #ifdef USS_VOL_DB - printf("%s: Deleting volume '%s' (ID %d) on FileServer '%s' (0x%x), partition '%s' (%d)\n", - rn, a_volName, a_volID, a_servName, a_servID, - a_partName, a_partID); + printf + ("%s: Deleting volume '%s' (ID %d) on FileServer '%s' (0x%x), partition '%s' (%d)\n", + rn, a_volName, a_volID, a_servName, a_servID, a_partName, + a_partID); #endif /* USS_VOL_DB */ code = UV_DeleteVolume(a_servID, a_partID, a_volID); if (code) - printf("%s: Can't delete volume '%s'\n", - uss_whoami, a_volName); + printf("%s: Can't delete volume '%s'\n", uss_whoami, a_volName); } else printf("\t[Dry run - volume '%s' NOT removed]\n", a_volName); - return(code); + return (code); -} /*uss_vol_DeleteVol*/ +} /*uss_vol_DeleteVol */ /*------------------------------------------------------------------------ @@ -987,12 +999,13 @@ afs_int32 uss_vol_DeleteVol(a_volName, a_volID, a_servName, a_servID, a_partName * As advertised. *------------------------------------------------------------------------*/ -static afs_int32 GetServerAndPart(a_vldbEntryP, a_servIDP, a_partIDP) - struct vldbentry *a_vldbEntryP; - afs_int32 *a_servIDP; - afs_int32 *a_partIDP; +static afs_int32 +GetServerAndPart(a_vldbEntryP, a_servIDP, a_partIDP) + struct vldbentry *a_vldbEntryP; + afs_int32 *a_servIDP; + afs_int32 *a_partIDP; -{ /*GetServerAndPart*/ +{ /*GetServerAndPart */ /* * It really looks like all we need to do is pull off the @@ -1000,9 +1013,9 @@ static afs_int32 GetServerAndPart(a_vldbEntryP, a_servIDP, a_partIDP) */ *a_servIDP = a_vldbEntryP->serverNumber[0]; *a_partIDP = a_vldbEntryP->serverPartition[0]; - return(0); + return (0); -} /*GetServerAndPart*/ +} /*GetServerAndPart */ /*------------------------------------------------------------------------ @@ -1015,34 +1028,31 @@ static afs_int32 GetServerAndPart(a_vldbEntryP, a_servIDP, a_partIDP) * As advertised. *------------------------------------------------------------------------*/ -afs_int32 uss_vol_GetVolInfoFromMountPoint(a_mountpoint) - char *a_mountpoint; +afs_int32 +uss_vol_GetVolInfoFromMountPoint(a_mountpoint) + char *a_mountpoint; -{ /*uss_vol_GetVolInfoFromMountPoint*/ +{ /*uss_vol_GetVolInfoFromMountPoint */ static char rn[] = "uss_vol_GetVolInfoFromMountPoint"; - register afs_int32 code; /*Return code*/ - uss_VolumeStatus_t *statusP; /*Ptr to returned status*/ - afs_int32 volID; /*Volume ID*/ - struct vldbentry vldbEntry; /*VLDB entry for volume*/ - afs_int32 serverID; /*Addr of host FileServer*/ - afs_int32 partID; /*Volume's partition ID*/ + register afs_int32 code; /*Return code */ + uss_VolumeStatus_t *statusP; /*Ptr to returned status */ + afs_int32 volID; /*Volume ID */ + struct vldbentry vldbEntry; /*VLDB entry for volume */ + afs_int32 serverID; /*Addr of host FileServer */ + afs_int32 partID; /*Volume's partition ID */ /* * Set up to ask the CacheManager to give us all the info * it has about the given mountpoint. */ - code = uss_fs_GetVolStat(a_mountpoint, - uss_fs_OutBuff, - USS_FS_MAX_SIZE); + code = uss_fs_GetVolStat(a_mountpoint, uss_fs_OutBuff, USS_FS_MAX_SIZE); #ifdef USS_VOL_DB - printf("[%s] Result of uss_fs_GetVolStat: code = %d, errno = %d\n", - rn, code, errno); + printf("[%s] Result of uss_fs_GetVolStat: code = %d, errno = %d\n", rn, + code, errno); #endif /* USS_VOL_DB */ if (code) { - if (errno == EINVAL || - errno == ENOENT || - errno == ENODEV) { + if (errno == EINVAL || errno == ENOENT || errno == ENODEV) { /* * We were given a mountpoint pathname that doesn't * point to a volume, or a mountpoint that has already @@ -1057,8 +1067,8 @@ afs_int32 uss_vol_GetVolInfoFromMountPoint(a_mountpoint) uss_ServerID = 0; uss_PartitionID = 0; if (uss_verbose) { - printf("%s: Warning: Mountpoint pathname '%s': ", - uss_whoami, a_mountpoint); + printf("%s: Warning: Mountpoint pathname '%s': ", uss_whoami, + a_mountpoint); if (errno == EINVAL) printf("Volume not reachable\n"); else if (errno == ENODEV) @@ -1066,28 +1076,27 @@ afs_int32 uss_vol_GetVolInfoFromMountPoint(a_mountpoint) else printf("Not found\n"); } - return(0); - } - else { + return (0); + } else { printf("%s: Can't get volume information from mountpoint '%s'\n", uss_whoami, a_mountpoint); - return(code); + return (code); } - } /*Can't get volume status*/ + } + /*Can't get volume status */ /* * Pull out the volume name from the returned information and store * it in the common area. It resides right after the basic volume * status structure. */ - statusP = (uss_VolumeStatus_t *)uss_fs_OutBuff; + statusP = (uss_VolumeStatus_t *) uss_fs_OutBuff; strcpy(uss_Volume, (((char *)statusP) + sizeof(*statusP))); volID = statusP->Vid; uss_VolumeID = volID; if (volID == 0) { - printf("%s: Illegal volume ID: %d\n", - uss_whoami, volID); - return(-1); + printf("%s: Illegal volume ID: %d\n", uss_whoami, volID); + return (-1); } /* @@ -1097,13 +1106,13 @@ afs_int32 uss_vol_GetVolInfoFromMountPoint(a_mountpoint) if (!initDone) { code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell); if (code) - return(code); + return (code); } code = ubik_Call(VL_GetEntryByID, uconn_vldbP, 0, volID, -1, &vldbEntry); if (code) { - printf("%s: Can't fetch VLDB entry for volume ID %d\n", - uss_whoami, volID); - return(code); + printf("%s: Can't fetch VLDB entry for volume ID %d\n", uss_whoami, + volID); + return (code); } /* @@ -1115,12 +1124,12 @@ afs_int32 uss_vol_GetVolInfoFromMountPoint(a_mountpoint) if (vldbEntry.volumeId[RWVOL] != volID) { printf("%s: Volume '%s' (ID %d) is not a read/write volume!!\n", uss_whoami, uss_Volume, volID); - return(-1); + return (-1); } if (vldbEntry.nServers != 1) { printf("s: Volume '%s' (ID %d) exists on multiple servers!!\n", uss_whoami, uss_Volume, volID); - return(-1); + return (-1); } /* @@ -1129,9 +1138,10 @@ afs_int32 uss_vol_GetVolInfoFromMountPoint(a_mountpoint) */ code = GetServerAndPart(&vldbEntry, &serverID, &partID); if (code) { - printf("%s: Can't get server/partition info from VLDB entry for volume '%s' (ID %d)\n", - uss_whoami, uss_Volume, volID); - return(-1); + printf + ("%s: Can't get server/partition info from VLDB entry for volume '%s' (ID %d)\n", + uss_whoami, uss_Volume, volID); + return (-1); } /* @@ -1142,19 +1152,19 @@ afs_int32 uss_vol_GetVolInfoFromMountPoint(a_mountpoint) uss_PartitionID = partID; HostIDToHostName(serverID, uss_Server); #ifdef USS_VOL_DB - printf("[%s] Server ID 0x%x translated to '%s'\n", - rn, serverID, uss_Server); + printf("[%s] Server ID 0x%x translated to '%s'\n", rn, serverID, + uss_Server); #endif /* USS_VOL_DB */ code = PartIDToPartName(partID, uss_Partition); if (code) { printf("%s: Error translating partition ID %d to partition name\n", uss_whoami, partID); - return(code); + return (code); } - + /* * We got it, home boy. */ - return(0); + return (0); -} /*uss_vol_GetVolInfoFromMountPoint*/ +} /*uss_vol_GetVolInfoFromMountPoint */ diff --git a/src/uss/uss_vol.h b/src/uss/uss_vol.h index fce17d7bd..f2fc7c89f 100644 --- a/src/uss/uss_vol.h +++ b/src/uss/uss_vol.h @@ -24,10 +24,10 @@ extern afs_int32 uss_vol_GetServer(); * Given the string name of a desired host, find its address. * * Args: - * a_name : String name of desired host. + * a_name : String name of desired host. * * Returns: - * Host address in network byte order. + * Host address in network byte order. */ extern afs_int32 uss_vol_GetPartitionID(); @@ -36,31 +36,31 @@ extern afs_int32 uss_vol_GetPartitionID(); * Get partition id from a name. * * Args: - * a_name : Name of the partition ID. + * a_name : Name of the partition ID. * * Returns: - * Numeric partition name, or -1 on failure. + * Numeric partition name, or -1 on failure. */ extern afs_int32 uss_vol_CreateVol(); /* * Summary: * Create a volume, set its disk quota, and mount it at the - * given place. Also, set the mountpoint's ACL. + * given place. Also, set the mountpoint's ACL. * * Args: - * char *a_volname : Volume name to mount. - * char *a_server : FileServer housing the volume - * char *a_partition : Partition housing the volume - * char *a_quota : Initial quota - * char *a_mpoint : Mountpoint to assign it - * char *a_owner : Name of mountpoint's owner - * char *a_acl : ACL for mountpoint. + * char *a_volname : Volume name to mount. + * char *a_server : FileServer housing the volume + * char *a_partition : Partition housing the volume + * char *a_quota : Initial quota + * char *a_mpoint : Mountpoint to assign it + * char *a_owner : Name of mountpoint's owner + * char *a_acl : ACL for mountpoint. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ extern afs_int32 uss_vol_DeleteVol(); @@ -69,33 +69,33 @@ extern afs_int32 uss_vol_DeleteVol(); * Delete the given volume. * * Args: - * char *a_volName : Name of the volume to delete. - * afs_int32 a_volID : Numerical volume ID. - * char *a_servName : Name of the server hosting the volume. - * afs_int32 a_servID : Numerical server ID. - * char *a_partName : Name of the home server partition. - * afs_int32 a_volID : Numerical partition ID. + * char *a_volName : Name of the volume to delete. + * afs_int32 a_volID : Numerical volume ID. + * char *a_servName : Name of the server hosting the volume. + * afs_int32 a_servID : Numerical server ID. + * char *a_partName : Name of the home server partition. + * afs_int32 a_volID : Numerical partition ID. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ extern afs_int32 uss_vol_GetVolInfoFromMountPoint(); /* * Summary: * Given a mountpoint, pull out the name of the volume mounted - * there, along with the name of the FileServer and partition - * hosting it, putting them all in common locations. + * there, along with the name of the FileServer and partition + * hosting it, putting them all in common locations. * * Args: - * char *a_mountpoint : Name of the mountpoint. + * char *a_mountpoint : Name of the mountpoint. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ extern afs_int32 uss_vol_DeleteMountPoint(); @@ -104,12 +104,12 @@ extern afs_int32 uss_vol_DeleteMountPoint(); * Given a mountpoint, nuke it. * * Args: - * char *a_mountpoint : Name of the mountpoint. + * char *a_mountpoint : Name of the mountpoint. * * Returns: - * 0 if everything went well, - * 1 if there was a problem in the routine itself, or - * Other error code if problem occurred in lower-level call. + * 0 if everything went well, + * 1 if there was a problem in the routine itself, or + * Other error code if problem occurred in lower-level call. */ #endif /* _USS_VOL_H_ */ diff --git a/src/venus/.cvsignore b/src/venus/.cvsignore index 947761a9b..709f7e51e 100644 --- a/src/venus/.cvsignore +++ b/src/venus/.cvsignore @@ -1,5 +1,4 @@ AFS_component_version_number.c -livesys Makefile cmdebug fs @@ -8,3 +7,4 @@ kdump-* up kdump kdump64 +livesys diff --git a/src/venus/Makefile.in b/src/venus/Makefile.in index 5bd1b1109..c0bddbba1 100644 --- a/src/venus/Makefile.in +++ b/src/venus/Makefile.in @@ -5,36 +5,8 @@ # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html -DEST=@DEST@ -TOP_INCDIR=@TOP_INCDIR@ -TOP_LIBDIR=@TOP_LIBDIR@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ -libexecdir=@libexecdir@ -libdir=@libdir@ -includedir=@includedir@ -mandir=@mandir@ -afssrvbindir=@afssrvbindir@ -afssrvsbindir=@afssrvsbindir@ -afssrvlibexecdir=@afssrvlibexecdir@ -COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et -RXGEN=${TOP_SRCDIR}/rxgen/rxgen -TOP_SRCDIR=@TOP_SRCDIR@ -SYS_NAME=@AFS_SYSNAME@ - -SHELL = /bin/sh - -LINUX_KERNEL_PATH=@LINUX_KERNEL_PATH@ -LINUX_VERSION=@LINUX_VERSION@ - -include ../config/Makefile.${SYS_NAME} - -INSTALLex = ${INSTALL} -m 755 -CCXPG2= /usr/xpg2bin/cc - -CFLAGS=${OPTMZ} ${DBG} -I${TOP_INCDIR} -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS} +srcdir=@srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config INCLS=${TOP_INCDIR}/afs/afsint.h \ ${TOP_INCDIR}/afs/cmd.h \ @@ -52,9 +24,9 @@ FSLIBS=${TOP_LIBDIR}/libsys.a \ ${TOP_LIBDIR}/libdes.a \ ${TOP_LIBDIR}/librx.a \ ${TOP_LIBDIR}/libsys.a \ - $(TOP_LIBDIR)/util.a \ ${TOP_LIBDIR}/liblwp.a \ - ${TOP_LIBDIR}/libaudit.a + ${TOP_LIBDIR}/libaudit.a \ + $(TOP_LIBDIR)/libafsutil.a CMLIBS=${TOP_LIBDIR}/libsys.a \ ${TOP_LIBDIR}/libafsint.a \ @@ -64,8 +36,8 @@ CMLIBS=${TOP_LIBDIR}/libsys.a \ ${TOP_LIBDIR}/libcmd.a \ ${TOP_LIBDIR}/librx.a \ ${TOP_LIBDIR}/libsys.a \ - $(TOP_LIBDIR)/util.a \ - ${TOP_LIBDIR}/liblwp.a + ${TOP_LIBDIR}/liblwp.a \ + $(TOP_LIBDIR)/libafsutil.a LIBS = ${FSLIBS} @@ -105,7 +77,7 @@ ${DEST}/etc/${KDUMP}: ${KDUMP} -set -x; \ case ${SYS_NAME} in \ sgi_6? ) \ - ${INSTALLex} -f kdump.sh.sgi_ipnos ${DEST}/etc/kdump; \ + ${INSTALLex} -f ${srcdir}/kdump.sh.sgi_ipnos ${DEST}/etc/kdump; \ ln -fs kdump ${DEST}/etc/kdump32; \ ln -fs kdump.IP20 ${DEST}/etc/kdump.IP22; \ ln -fs kdump.IP20 ${DEST}/etc/kdump.IP32; \ @@ -113,24 +85,27 @@ ${DEST}/etc/${KDUMP}: ${KDUMP} do ${INSTALL} -s $$f ${DEST}/etc/$$f || exit $$? ; \ done ;; \ sun*_5[789] ) \ - ${INSTALLex} -f kdump.sh.solaris7 ${DEST}/etc/kdump; \ - ${INSTALL} -s -f $? $@ ;; \ + ${INSTALLex} -f ${srcdir}/kdump.sh.solaris7 ${DEST}/etc/kdump; \ + ${INSTALL} -s -f $? $@;; \ + *alpha_linux* ) \ + ${INSTALLex} -f ${srcdir}/kdump.sh.linux ${DEST}/etc/kdump; \ + ${INSTALL} -s kdump-alpha_linux-${LINUX_VERSION} $@ ;; \ *linux* ) \ - ${INSTALLex} -f kdump.sh.linux ${DEST}/etc/kdump; \ - ${INSTALL} -s $? $@ ;; \ + ${INSTALLex} -f ${srcdir}/kdump.sh.linux ${DEST}/etc/kdump; \ + ${INSTALL} -s kdump-linux-${LINUX_VERSION} $@ ;; \ hp_ux11* ) \ - ${INSTALLex} -f kdump.sh.hp_ux11 ${DEST}/etc/kdump; \ + ${INSTALLex} -f ${srcdir}/kdump.sh.hp_ux11 ${DEST}/etc/kdump; \ ${INSTALL} -s -f $? $@;; \ - ia64_hpux11* ) \ - echo skipping kdump for ${SYS_NAME} ;; \ + *nbsd*) \ + ;; \ *) \ ${INSTALL} -s $? $@ ;; \ esac -${DEST}/etc/kdump64: kdump64 +${DEST}/etc/${KDUMP64}: ${KDUMP64} -set -x; \ case ${SYS_NAME} in \ - sun4x_5[789] | hp_ux11* ) \ + sun4x_5[789] | hp_ux11* |sunx86_5[789] ) \ ${INSTALL} -s $? $@ ;;\ * ) \ echo skipping kdump64 for ${SYS_NAME} ;; \ @@ -150,13 +125,13 @@ fs: fs.o $(LIBS) livesys.o: livesys.c ${INCLS} AFS_component_version_number.c livesys: livesys.c $(LIBS) - ${CC} -o livesys $(CFLAGS) livesys.c $(LIBS) ${XLIBS} + ${CC} ${CFLAGS} -o livesys ${srcdir}/livesys.c $(LIBS) ${XLIBS} twiddle: twiddle.c $(LIBS) - ${CC} -o twiddle $(CFLAGS) twiddle.c $(LIBS) ${XLIBS} + ${CC} ${CFLAGS} -o twiddle ${srcdir}/twiddle.c $(LIBS) ${XLIBS} gcpags: gcpags.c $(LIBS) - ${CC} -o gcpags $(CFLAGS) gcpags.c $(LIBS) ${XLIBS} + ${CC} ${CFLAGS} -o gcpags ${srcdir}/gcpags.c $(LIBS) ${XLIBS} whatfid.o: whatfid.c ${INCLS} AFS_component_version_number.c @@ -166,11 +141,11 @@ whatfid: whatfid.o ${LIBS} fstrace.o: fstrace.c AFS_component_version_number.c case ${SYS_NAME} in \ sun4_411 | sun4c_411 | sun4m_412 ) \ - ${CCXPG2} -I${TOP_SRCDIR}/config -I${TOP_INCDIR} -I${TOP_INCDIR} -c fstrace.c ;; \ + ${CCXPG2} ${DBG} ${OPTMZ} -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} -I${TOP_INCDIR} -c ${srcdir}/fstrace.c ;; \ sun*_4* ) \ - ${CC} -I/usr/xpg2include -I/usr/5include -I${TOP_SRCDIR}/config -I${TOP_INCDIR} -I${TOP_INCDIR} -c fstrace.c ;; \ + ${CC} ${DBG} ${OPTMZ} -I/usr/xpg2include -I/usr/5include -g -I${TOP_SRCDIR}/config -I${TOP_INCDIR} -I${TOP_INCDIR} -c fstrace.c ;; \ * ) \ - ${CC} ${CFLAGS} -I${TOP_SRCDIR}/config -I${TOP_INCDIR} -I${TOP_INCDIR} -c fstrace.c ;; \ + ${CC} ${CFLAGS} -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} -I${TOP_INCDIR} -c ${srcdir}/fstrace.c ;; \ esac fstrace: fstrace.o @@ -180,9 +155,9 @@ fstrace: fstrace.o sun4_411 | sun4c_411 | sun4m_412 ) \ ${CCXPG2} ${CFLAGS} -o fstrace fstrace.o ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ;; \ sun*_4* ) \ - ${CC} -L/usr/xpg2lib -L/usr/5lib ${CFLAGS} -o fstrace fstrace.o ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a -lxpg ;; \ + ${CC} -L/usr/xpg2lib -L/usr/5lib ${CFLAGS} -g -o fstrace fstrace.o ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a -lxpg ;; \ hp700_ux100 | hp800_ux100 | hp?00_ux10? | hp_ux10? | hp_ux11?) \ - ${CC} -I${TOP_SRCDIR}/config -o fstrace fstrace.o ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ;; \ + ${CC} -I${TOP_OBJDIR}/src/config -o fstrace fstrace.o ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ;; \ * ) \ ${CC} ${CFLAGS} -o fstrace fstrace.o ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ;; \ esac @@ -192,15 +167,51 @@ cmdebug.o: cmdebug.c ${INCLS} AFS_component_version_number.c cmdebug: cmdebug.o ${CMLIBS} $(CC) -o cmdebug cmdebug.o ${CFLAGS} ${CMLIBS} ${XLIBS} +# +# Kernel info dumper - these are done with submakes so that +# the build process does not attempt to rebuild them every time it runs. +# + +# *linux* - Builds kdump-X.Y.Z according to kernel version +kdump-linux-@LINUX_VERSION@.o: kdump.c ${INCLS} AFS_component_version_number.c + ${CC} ${KERN_DBG} ${KERN_OPTMZ} -I${LINUX_KERNEL_PATH}/include -I${TOP_INCDIR}/afs \ + -I${TOP_OBJDIR}/src \ + -I${TOP_OBJDIR}/src/afs/${MKAFS_OSTYPE} \ + -I${TOP_OBJDIR}/src/config -I${TOP_OBJDIR}/src/libafs/afs \ + -I${TOP_SRCDIR} -I${TOP_SRCDIR}/afs/${MKAFS_OSTYPE} \ + -I${TOP_INCDIR} ${XCFLAGS} -o kdump-linux-${LINUX_VERSION}.o \ + -c ${srcdir}/kdump.c + +kdump-linux-@LINUX_VERSION@: kdump-linux-@LINUX_VERSION@.o + ${CC} ${KERN_DBG} ${KERN_OPTMZ} -o kdump-linux-${LINUX_VERSION} kdump-linux-${LINUX_VERSION}.o \ + ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ${XLIBS} + +# *alpha_linux* - Builds kdump-X.Y.Z according to kernel version +kdump-alpha_linux-@LINUX_VERSION@.o: kdump.c ${INCLS} AFS_component_version_number.c + ${CC} ${KERN_DBG} ${KERN_OPTMZ} -I${LINUX_KERNEL_PATH}/include -I${TOP_INCDIR}/afs \ + -I${TOP_OBJDIR}/src \ + -I${TOP_OBJDIR}/src/afs/${MKAFS_OSTYPE} \ + -I${TOP_OBJDIR}/src/config -I${TOP_OBJDIR}/src/libafs/afs \ + -I${TOP_SRCDIR} -I${TOP_SRCDIR}/afs/${MKAFS_OSTYPE} \ + -I${TOP_INCDIR} ${XCFLAGS} -mno-fp-regs -ffixed-8 \ + -o kdump-alpha_linux-${LINUX_VERSION}.o -c ${srcdir}/kdump.c ;; \ + +kdump-alpha_linux-@LINUX_VERSION@: kdump-alpha_linux-@LINUX_VERSION@.o + ${CC} ${KERN_DBG} ${KERN_OPTMZ} -o kdump-alpha_linux-${LINUX_VERSION} kdump-alpha_linux-${LINUX_VERSION}.o \ + ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ${XLIBS} + +# +# Default target +# ${KDUMP}.o: kdump.c ${INCLS} AFS_component_version_number.c -set -x; \ case ${SYS_NAME} in \ alpha_linux* ) \ - ${CC} -I${LINUX_KERNEL_PATH}/include -I${TOP_INCDIR} -I${TOP_SRCDIR}/config -I${TOP_SRCDIR}/libafs/afs -I${TOP_INCDIR} ${XCFLAGS} -mno-fp-regs -ffixed-8 -o kdump-${LINUX_VERSION}.o -c kdump.c ;; \ + $(MAKE) kdump-alpha_linux-${LINUX_VERSION}.o ;; \ *linux* ) \ - ${CC} -I${LINUX_KERNEL_PATH}/include -I${TOP_INCDIR} -I${TOP_SRCDIR}/config -I${TOP_SRCDIR}/libafs/afs -I${TOP_INCDIR} ${XCFLAGS} -o kdump-${LINUX_VERSION}.o -c kdump.c ;; \ + $(MAKE) kdump-linux-${LINUX_VERSION}.o ;; \ alpha_osf1 | alpha_osf20 | alpha_osf30 | alpha_osf32 | alpha_osf32c| alpha_dux?? ) \ - ${CC} ${CFLAGS} -I/usr/sys/include -I/usr/sys/BINARY -I/usr/sys/AFS -DDEBUGGER -c kdump.c ;;\ + ${CC} ${CFLAGS} -I/usr/sys/include -I/usr/sys/BINARY -I/usr/sys/AFS -DDEBUGGER -c ${srcdir}/kdump.c ;;\ sgi_6? ) \ for f in ../libafs/STATIC.IP*/CPU_KDEFS; \ do IP=`expr "$$f" : '../libafs/STATIC.\(IP..\)'`; \ @@ -209,40 +220,42 @@ ${KDUMP}.o: kdump.c ${INCLS} AFS_component_version_number.c echo CPU_KDEFS = $$CPU_KDEFS; \ case $$CPU_KDEFS in \ *-64*) ${CC} -D_KMEMUSER -woff 1178 \ - -I${TOP_INCDIR} \ - -I${TOP_SRCDIR}/config \ + ${KERN_DBG} ${KERN_OPTMZ} -I${TOP_INCDIR} \ + -I${TOP_OBJDIR}/src/config \ $$CPU_KDEFS \ ${XCFLAGS64} \ - -c kdump.c -o kdump.$$IP.o \ + -c ${srcdir}/kdump.c -o kdump.$$IP.o \ ;; \ *) ${CC} -D_KMEMUSER -woff 1178 \ - -I${TOP_INCDIR} \ - -I${TOP_SRCDIR}/config \ + ${KERN_DBG} ${KERN_OPTMZ} -I${TOP_INCDIR} \ + -I${TOP_OBJDIR}/src/config \ $$CPU_KDEFS \ ${XCFLAGS} -DAFS_32BIT_KERNEL_ENV \ - -c kdump.c -o kdump.$$IP.o \ + -c ${srcdir}/kdump.c -o kdump.$$IP.o \ ;; \ esac || exit $$?; \ done \ ;; \ + *nbsd*) \ + touch kdump.o ;; \ *) \ - ${CC} -I${TOP_INCDIR} -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS} -c kdump.c ;; \ + ${CC} ${KERN_DBG} ${KERN_OPTMZ} -I${TOP_SRCDIR} -I${TOP_INCDIR}/afs -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} ${XCFLAGS} -o ${KDUMP}.o -c ${srcdir}/kdump.c ;; \ esac ; -kdump64.o : kdump.c ${INCLS} AFS_component_version_number.c +${KDUMP64}.o : kdump.c ${INCLS} AFS_component_version_number.c -set -x; \ case ${SYS_NAME} in \ - sun4x_5[789] | hp_ux11* ) \ - ${CC} -I${TOP_INCDIR} -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS64} -o kdump64.o -c kdump.c ;; \ + sun4x_5[789] | hp_ux11* |sunx86_5[789] ) \ + ${CC} ${KERN_DBG} ${KERN_OPTMZ} -I${TOP_SRCDIR} -I${TOP_INCDIR}/afs -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} ${XCFLAGS64} -o ${KDUMP64}.o -c ${srcdir}/kdump.c ;; \ esac ${KDUMP}: ${KDUMP}.o -set -x; \ case ${SYS_NAME} in \ - sun4c_51 | sun4c_52 | sun4m_51 | sun4m_52 | sun4c_53 | sun4m_53 | sun4_53 | sun4_54 | sun4c_54 | sun4m_54 | sunx86_54) \ - ${CC} -o kdump kdump.o ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a /usr/lib/libkvm.a -lelf ${XLIBS} ;; \ + sun4c_51 | sun4c_52 | sun4m_51 | sun4m_52 | sun4c_53 | sun4m_53 | sun4_53 | sun4_54 | sun4c_54 | sun4m_54 | sunx86_5? ) \ + ${CC} -o ${KDUMP} ${KDUMP}.o ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a /usr/lib/libkvm.a -lelf ${XLIBS} ;; \ sun*_5? ) \ - ${CC} -o kdump kdump.o ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ${XLIBELFA} ${XLIBKVM} ${XLIBS} ;; \ + ${CC} -o ${KDUMP} ${KDUMP}.o ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ${XLIBELFA} ${XLIBKVM} ${XLIBS} ;; \ sgi_6? ) \ for f in ../libafs/STATIC.IP*/CPU_KDEFS; \ do IP=`expr "$$f" : '../libafs/STATIC.\(IP..\)'`; \ @@ -262,21 +275,24 @@ ${KDUMP}: ${KDUMP}.o ;; \ esac || exit $$? ; \ done ;; \ + *alpha_linux* ) \ + $(MAKE) kdump-alpha_linux-@LINUX_VERSION@ ;; \ *linux* ) \ - ${CC} -o kdump-${LINUX_VERSION} kdump-${LINUX_VERSION}.o ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ${XLIBS} ;; \ + $(MAKE) kdump-linux-@LINUX_VERSION@ ;; \ alpha_osf1 | alpha_osf20 | alpha_osf30 | alpha_osf32 | alpha_osf32c | alpha_dux??) \ ${CC} -o kdump kdump.o ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ${XLIBS} -ll -lmld;; \ ncrx86_* ) ${CC} -o kdump kdump.o ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a -lelf ${XLIBS} ;; \ + *nbsd*) touch kdump ;; \ * ) ${CC} -o kdump kdump.o ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a ${XLIBS} ;; \ esac ## kdump to read from 64 bit kernel dumps -kdump64 : kdump64.o +${KDUMP64}: ${KDUMP64}.o -set -x; \ case ${SYS_NAME} in \ - sun4x_5[789] | hp_ux11* ) \ - ${CC} ${XCFLAGS64} -o kdump64 kdump64.o ${TOP_LIBDIR}/libcmd64.a ${XLIBELFA} ${XLIBKVM} ${XLIBS} ;; \ + sun4x_5[789] | hp_ux11* |sunx86_5[789] ) \ + ${CC} ${XCFLAGS64} -o ${KDUMP64} ${KDUMP64}.o ${TOP_LIBDIR}/libcmd64.a ${XLIBELFA} ${XLIBKVM} ${XLIBS} ;; \ esac # @@ -297,7 +313,7 @@ install: \ # clean: - $(RM) -f *.o *.a up fs kdump-* kdump kdump64 core cmdebug AFS_component_version_number.c fstrace gcpags livesys + $(RM) -f *.o *.a up fs kdump-* kdump kdump64 core cmdebug AFS_component_version_number.c fstrace gcpags test: cd test; $(MAKE) @@ -338,7 +354,7 @@ ${DESTDIR}${sbindir}/${KDUMP}: ${KDUMP} ${INSTALL} -s -f $? $@;; \ *linux* ) \ ${INSTALLex} -f kdump.sh.linux ${DESTDIR}${sbindir}/kdump; \ - ${INSTALL} -s @? $@ ;; \ + ${INSTALL} -s $? $@ ;; \ hp_ux11* ) \ ${INSTALLex} -f kdump.sh.hp_ux11 ${DESTDIR}${sbindir}/kdump; \ ${INSTALL} -s -f $? $@;; \ diff --git a/src/venus/cacheout.c b/src/venus/cacheout.c index 59b4e4017..98aee9c2d 100644 --- a/src/venus/cacheout.c +++ b/src/venus/cacheout.c @@ -12,7 +12,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/cacheout.c,v 1.1.1.5 2001/09/11 14:35:22 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/cacheout.c,v 1.8 2003/07/15 23:17:19 shadow Exp $"); #include #include @@ -36,24 +37,20 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/cacheout.c,v 1.1.1.5 2001/09/11 1 File servers in NW byte order. */ -int server_count=0; +int server_count = 0; afs_int32 server_id[256]; struct ubik_client *client; -struct ViceIds -{ - int ViceIds_len; - afs_int32 *ViceIds_val; -} -; +struct ViceIds { + int ViceIds_len; + afs_int32 *ViceIds_val; +}; -struct IPAddrs -{ - int IPAddrs_len; - afs_int32 *IPAddrs_val; -} -; +struct IPAddrs { + int IPAddrs_len; + afs_int32 *IPAddrs_val; +}; struct ubik_dbase *VL_dbase; struct afsconf_dir *vldb_confdir; @@ -66,91 +63,86 @@ struct rx_securityClass *junk; extern int VL_GetAddrs(); -afs_int32 InvalidateCache(as) -struct cmd_syndesc *as; +afs_int32 +InvalidateCache(as) + struct cmd_syndesc *as; { - afs_int32 code=0; - struct cmd_item *u; - struct rx_connection *conn; - int i; - afs_int32 port=7000; + afs_int32 code = 0; + struct cmd_item *u; + struct rx_connection *conn; + int i; + afs_int32 port = 7000; - afs_int32 spare1=0; - afs_int32 spare2,spare3; + afs_int32 spare1 = 0; + afs_int32 spare2, spare3; - afs_int32 id[256]; - afs_int32 ip[256]; + afs_int32 id[256]; + afs_int32 ip[256]; - struct ViceIds vid; - struct IPAddrs ipa; + struct ViceIds vid; + struct IPAddrs ipa; - code=ListServers(); - if(code) - return code; + code = ListServers(); + if (code) + return code; - /* make sure something there */ + /* make sure something there */ - if( !as->parms[0].items && !as->parms[1].items) - { - printf("Use -help flag for list of optional argmuments\n"); - return 1; - } + if (!as->parms[0].items && !as->parms[1].items) { + printf("Use -help flag for list of optional argmuments\n"); + return 1; + } - /* get user ids */ + /* get user ids */ - for(i=0,u=as->parms[0].items;i<255 && u;++i,u=u->next) - { - code=util_GetInt32(u->data,&id[i]); - if(code) - { - printf("Fatal error: bad conversion to long for %s\n",u->data); - return code; - } + for (i = 0, u = as->parms[0].items; i < 255 && u; ++i, u = u->next) { + code = util_GetInt32(u->data, &id[i]); + if (code) { + printf("Fatal error: bad conversion to long for %s\n", u->data); + return code; } + } - id[i]=0; - vid.ViceIds_len=i; - vid.ViceIds_val=id; + id[i] = 0; + vid.ViceIds_len = i; + vid.ViceIds_val = id; - /* get IP addresses, convert to NW byte order */ + /* get IP addresses, convert to NW byte order */ - for(i=0,u=as->parms[1].items;i<255 && u;++i,u=u->next) - ip[i]=inet_addr(u->data); + for (i = 0, u = as->parms[1].items; i < 255 && u; ++i, u = u->next) + ip[i] = inet_addr(u->data); - ip[i]=0; - ipa.IPAddrs_len=i; - ipa.IPAddrs_val=ip; + ip[i] = 0; + ipa.IPAddrs_len = i; + ipa.IPAddrs_val = ip; - for(i=0;i= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1) + && (index <= VL_MHSRV_PERBLK)) { + m_attrs.Mask = VLADDR_INDEX; + m_attrs.index = (base * VL_MHSRV_PERBLK) + index; + m_nentries = 0; + m_addrs.bulkaddrs_val = 0; + m_addrs.bulkaddrs_len = 0; + code = + ubik_Call(VL_GetAddrsU, client, 0, &m_attrs, &m_uuid, + &m_unique, &m_nentries, &m_addrs); + if (vcode) + return code; + + m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val; + for (j = 0; j < m_nentries; j++, m_addrp++) { + server_id[i] = *m_addrp; + *m_addrp = htonl(*m_addrp); + printf("host %s\n", hostutil_GetNameByINet(*p)); + } + } + } else { + server_id[i] = *p; + *p = htonl(*p); + printf("host %s\n", hostutil_GetNameByINet(*p)); + } + } + return code; } -afs_int32 GetServerList() +afs_int32 +GetServerList() { - afs_int32 code; - int i; + afs_int32 code; + int i; - code=ListServers(); - if(code) - return(code); + code = ListServers(); + if (code) + return (code); - printf("There are %d file servers in the cell\n\n",server_count); - fflush(stdout); - for(i=0;iparms[2].items) /* if -cell specified */ + if (as->parms[2].items) /* if -cell specified */ tcell = as->parms[2].items->data; - code = afsconf_GetCellInfo(tdir, tcell, AFSCONF_VLDBSERVICE,&info); + code = afsconf_GetCellInfo(tdir, tcell, AFSCONF_VLDBSERVICE, &info); if (info.numServers > MAXSERVERS) printf("Warning: could not init cell info.\n"); - for(i=0;i #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/cmdebug.c,v 1.1.1.6 2003/04/13 19:08:08 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/cmdebug.c,v 1.15 2003/07/15 23:17:20 shadow Exp $"); #include @@ -18,6 +19,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/cmdebug.c,v 1.1.1.6 2003/04/13 19 #include #include #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #ifdef AFS_AIX32_ENV #include #endif @@ -25,20 +33,94 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/cmdebug.c,v 1.1.1.6 2003/04/13 19 #include #include #include +#include -extern struct rx_securityClass *rxnull_NewServerSecurityObject(); extern struct hostent *hostutil_GetHostByName(); -static IsLocked(alock) -register struct AFSDBLockDesc *alock; { - if (alock->waitStates || alock->exclLocked - || alock->numWaiting || alock->readersReading) +static +PrintCacheConfig(aconn) + struct rx_connection *aconn; +{ + struct cacheConfig c; + afs_uint32 srv_ver, conflen; + int code; + + c.cacheConfig_len = 0; + c.cacheConfig_val = NULL; + code = RXAFSCB_GetCacheConfig(aconn, 1, &srv_ver, &conflen, &c); + if (code) { + printf("cmdebug: error checking cache config: %s\n", + error_message(code)); + return 0; + } + + if (srv_ver == AFS_CLIENT_RETRIEVAL_FIRST_EDITION) { + struct cm_initparams_v1 *c1; + + if (c.cacheConfig_len != sizeof(*c1) / sizeof(afs_uint32)) { + printf("cmdebug: configuration data size mismatch (%d != %d)\n", + c.cacheConfig_len, sizeof(*c1) / sizeof(afs_uint32)); + return 0; + } + + c1 = (struct cm_initparams_v1 *)c.cacheConfig_val; + printf("Chunk files: %d\n", c1->nChunkFiles); + printf("Stat caches: %d\n", c1->nStatCaches); + printf("Data caches: %d\n", c1->nDataCaches); + printf("Volume caches: %d\n", c1->nVolumeCaches); + printf("Chunk size: %d", c1->otherChunkSize); + if (c1->firstChunkSize != c1->otherChunkSize) + printf(" (first: %d)", c1->firstChunkSize); + printf("\n"); + printf("Cache size: %d kB\n", c1->cacheSize); + printf("Set time: %s\n", c1->setTime ? "yes" : "no"); + printf("Cache type: %s\n", c1->memCache ? "memory" : "disk"); + } else { + printf("cmdebug: unsupported server version %d\n", srv_ver); + } +} + +static +PrintInterfaces(aconn) + struct rx_connection *aconn; +{ + struct interfaceAddr addr; + int i, code; + + code = RXAFSCB_WhoAreYou(aconn, &addr); + if (code) { + printf("cmdebug: error checking interfaces: %s\n", + error_message(code)); + return 0; + } + + printf("Host interfaces:\n"); + for (i = 0; i < addr.numberOfInterfaces; i++) { + printf("%s", afs_inet_ntoa(htonl(addr.addr_in[i]))); + if (addr.subnetmask[i]) + printf(", netmask %s", afs_inet_ntoa(htonl(addr.subnetmask[i]))); + if (addr.mtu[i]) + printf(", MTU %d", addr.mtu[i]); + printf("\n"); + } + + return 0; +} + +static +IsLocked(alock) + register struct AFSDBLockDesc *alock; +{ + if (alock->waitStates || alock->exclLocked || alock->numWaiting + || alock->readersReading) return 1; return 0; } -static PrintLock(alock) -register struct AFSDBLockDesc *alock; { +static +PrintLock(alock) + register struct AFSDBLockDesc *alock; +{ printf("("); if (alock->waitStates) { if (alock->waitStates & READ_LOCK) @@ -47,36 +129,41 @@ register struct AFSDBLockDesc *alock; { printf("writer_waiting"); if (alock->waitStates & SHARED_LOCK) printf("upgrade_waiting"); - } - else + } else printf("none_waiting"); if (alock->exclLocked) { if (alock->exclLocked & WRITE_LOCK) printf(", write_locked"); if (alock->exclLocked & SHARED_LOCK) printf(", upgrade_locked"); - printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator); + printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator); } if (alock->readersReading) - printf(", %d read_locks(pid:%d)", alock->readersReading,alock->pid_last_reader); - if (alock->numWaiting) printf(", %d waiters", alock->numWaiting); + printf(", %d read_locks(pid:%d)", alock->readersReading, + alock->pid_last_reader); + if (alock->numWaiting) + printf(", %d waiters", alock->numWaiting); printf(")"); return 0; } -static PrintLocks(aconn, aint32) -int aint32; -register struct rx_connection *aconn; { +static +PrintLocks(aconn, aint32) + int aint32; + register struct rx_connection *aconn; +{ register int i; struct AFSDBLock lock; afs_int32 code; - for(i=0;i<1000;i++) { + for (i = 0; i < 1000; i++) { code = RXAFSCB_GetLock(aconn, i, &lock); if (code) { - if (code == 1) break; + if (code == 1) + break; /* otherwise we have an unrecognized error */ - printf("cmdebug: error checking locks: %s\n", error_message(code)); + printf("cmdebug: error checking locks: %s\n", + error_message(code)); return code; } /* here we have the lock information, so display it, perhaps */ @@ -95,7 +182,8 @@ struct cell_cache { struct cell_cache *next; }; -static char *GetCellName(struct rx_connection *aconn, afs_int32 cellnum) +static char * +GetCellName(struct rx_connection *aconn, afs_int32 cellnum) { static int no_getcellbynum; static struct cell_cache *cache; @@ -122,7 +210,7 @@ static char *GetCellName(struct rx_connection *aconn, afs_int32 cellnum) } if (sl.serverList_val) - free (sl.serverList_val); + free(sl.serverList_val); tcp = malloc(sizeof(struct cell_cache)); tcp->next = cache; tcp->cellnum = cellnum; @@ -132,17 +220,19 @@ static char *GetCellName(struct rx_connection *aconn, afs_int32 cellnum) return cellname; } -static PrintCacheEntries(struct rx_connection *aconn, int aint32) +static int +PrintCacheEntries32(struct rx_connection *aconn, int aint32) { register int i; register afs_int32 code; struct AFSDBCacheEntry centry; char *cellname; - for(i=0;i<10000;i++) { + for (i = 0; i < 10000; i++) { code = RXAFSCB_GetCE(aconn, i, ¢ry); if (code) { - if (code == 1) break; + if (code == 1) + break; printf("cmdebug: failed to get cache entry %d (%s)\n", i, error_message(code)); return code; @@ -151,11 +241,13 @@ static PrintCacheEntries(struct rx_connection *aconn, int aint32) if (centry.addr == 0) { /* PS output */ printf("Proc %4d sleeping at %08x, pri %3d\n", - centry.netFid.Vnode, centry.netFid.Volume, centry.netFid.Unique-25); + centry.netFid.Vnode, centry.netFid.Volume, + centry.netFid.Unique - 25); continue; } - if (!aint32 && !IsLocked(¢ry.lock)) continue; + if (!aint32 && !IsLocked(¢ry.lock)) + continue; /* otherwise print this entry */ printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr, @@ -173,31 +265,146 @@ static PrintCacheEntries(struct rx_connection *aconn, int aint32) PrintLock(¢ry.lock); printf("\n"); } - printf(" %d bytes\tDV %d refcnt %d\n", centry.Length, centry.DataVersion, centry.refCount); - printf(" callback %08x\texpires %u\n", centry.callback, centry.cbExpires); + printf(" %d bytes\tDV %d refcnt %d\n", centry.Length, + centry.DataVersion, centry.refCount); + printf(" callback %08x\texpires %u\n", centry.callback, + centry.cbExpires); printf(" %d opens\t%d writers\n", centry.opens, centry.writers); /* now display states */ printf(" "); - if (centry.mvstat == 0) printf("normal file"); - else if (centry.mvstat == 1) printf("mount point"); - else if (centry.mvstat == 2) printf("volume root"); - else printf("bogus mvstat %d", centry.mvstat); + if (centry.mvstat == 0) + printf("normal file"); + else if (centry.mvstat == 1) + printf("mount point"); + else if (centry.mvstat == 2) + printf("volume root"); + else + printf("bogus mvstat %d", centry.mvstat); printf("\n states (0x%x)", centry.states); - if (centry.states & 1) printf(", stat'd"); - if (centry.states & 2) printf(", backup"); - if (centry.states & 4) printf(", read-only"); - if (centry.states & 8) printf(", mt pt valid"); - if (centry.states & 0x10) printf(", pending core"); - if (centry.states & 0x40) printf(", wait-for-store"); - if (centry.states & 0x80) printf(", mapped"); + if (centry.states & 1) + printf(", stat'd"); + if (centry.states & 2) + printf(", backup"); + if (centry.states & 4) + printf(", read-only"); + if (centry.states & 8) + printf(", mt pt valid"); + if (centry.states & 0x10) + printf(", pending core"); + if (centry.states & 0x40) + printf(", wait-for-store"); + if (centry.states & 0x80) + printf(", mapped"); printf("\n"); } return 0; } -static CommandProc(as) -struct cmd_syndesc *as; { +static int +PrintCacheEntries64(struct rx_connection *aconn, int aint32) +{ + register int i; + register afs_int32 code; + struct AFSDBCacheEntry64 centry; + char *cellname; + int ce64 = 0; + + for (i = 0; i < 10000; i++) { + code = RXAFSCB_GetCE64(aconn, i, ¢ry); + if (code) { + if (code == 1) + break; + printf("cmdebug: failed to get cache entry %d (%s)\n", i, + error_message(code)); + return code; + } + + if (centry.addr == 0) { + /* PS output */ + printf("Proc %4d sleeping at %08x, pri %3d\n", + centry.netFid.Vnode, centry.netFid.Volume, + centry.netFid.Unique - 25); + continue; + } + + if (!aint32 && !IsLocked(¢ry.lock)) + continue; + + /* otherwise print this entry */ + printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr, + centry.cell, centry.netFid.Volume, centry.netFid.Vnode, + centry.netFid.Unique); + + cellname = GetCellName(aconn, centry.cell); + if (cellname) + printf(" [%s]\n", cellname); + else + printf("\n"); + + if (IsLocked(¢ry.lock)) { + printf(" locks: "); + PrintLock(¢ry.lock); + printf("\n"); + } +#ifdef AFS_64BIT_ENV + printf(" %lld bytes\tDV %d refcnt %d\n", centry.Length, + centry.DataVersion, centry.refCount); +#else + printf(" %d bytes\tDV %d refcnt %d\n", centry.Length, + centry.DataVersion, centry.refCount); +#endif + printf(" callback %08x\texpires %u\n", centry.callback, + centry.cbExpires); + printf(" %d opens\t%d writers\n", centry.opens, centry.writers); + + /* now display states */ + printf(" "); + if (centry.mvstat == 0) + printf("normal file"); + else if (centry.mvstat == 1) + printf("mount point"); + else if (centry.mvstat == 2) + printf("volume root"); + else + printf("bogus mvstat %d", centry.mvstat); + printf("\n states (0x%x)", centry.states); + if (centry.states & 1) + printf(", stat'd"); + if (centry.states & 2) + printf(", backup"); + if (centry.states & 4) + printf(", read-only"); + if (centry.states & 8) + printf(", mt pt valid"); + if (centry.states & 0x10) + printf(", pending core"); + if (centry.states & 0x40) + printf(", wait-for-store"); + if (centry.states & 0x80) + printf(", mapped"); + printf("\n"); + } + return 0; +} + +static int +PrintCacheEntries(struct rx_connection *aconn, int aint32) +{ + register afs_int32 code; + struct AFSDBCacheEntry64 centry64; + + code = RXAFSCB_GetCE64(aconn, 0, ¢ry64); + if (code != RXGEN_OPCODE) + return PrintCacheEntries64(aconn, aint32); + else + return PrintCacheEntries32(aconn, aint32); +} + +static +CommandProc(as) + struct cmd_syndesc *as; +{ struct rx_connection *conn; register char *hostName; register struct hostent *thp; @@ -220,11 +427,24 @@ struct cmd_syndesc *as; { secobj = rxnull_NewServerSecurityObject(); conn = rx_NewConnection(addr, htons(port), 1, secobj, 0); if (!conn) { - printf("cmdebug: failed to create connection for host %s\n", hostName); + printf("cmdebug: failed to create connection for host %s\n", + hostName); exit(1); } - if (as->parms[2].items) int32p = 1; - else int32p = 0; + if (as->parms[3].items) { + /* -addrs */ + PrintInterfaces(conn); + return 0; + } + if (as->parms[4].items) { + /* -cache */ + PrintCacheConfig(conn); + return 0; + } + if (as->parms[2].items) + int32p = 1; + else + int32p = 0; PrintLocks(conn, int32p); PrintCacheEntries(conn, int32p); return 0; @@ -233,8 +453,9 @@ struct cmd_syndesc *as; { #include "AFS_component_version_number.c" main(argc, argv) -int argc; -char **argv; { + int argc; + char **argv; +{ register struct cmd_syndesc *ts; #ifdef AFS_AIX32_ENV @@ -245,7 +466,7 @@ char **argv; { * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; @@ -253,10 +474,14 @@ char **argv; { #endif rx_Init(0); - ts = cmd_CreateSyntax((char *) 0, CommandProc, 0, "probe unik server"); + ts = cmd_CreateSyntax(NULL, CommandProc, 0, "probe unik server"); cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine"); cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port"); cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info"); + cmd_AddParm(ts, "-addrs", CMD_FLAG, CMD_OPTIONAL, + "print only host interfaces"); + cmd_AddParm(ts, "-cache", CMD_FLAG, CMD_OPTIONAL, + "print only cache configuration"); cmd_Dispatch(argc, argv); exit(0); diff --git a/src/venus/fs.c b/src/venus/fs.c index b821d593b..e72171350 100644 --- a/src/venus/fs.c +++ b/src/venus/fs.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/fs.c,v 1.3 2003/07/30 17:23:46 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/fs.c,v 1.23 2004/04/18 06:09:49 kolya Exp $"); #include #include @@ -27,6 +28,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/fs.c,v 1.3 2003/07/30 17:23:46 ha #ifdef AFS_AIX32_ENV #include #endif + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #undef VIRTUE #undef VICE #include "afs/prs_fs.h" @@ -40,16 +50,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/fs.c,v 1.3 2003/07/30 17:23:46 ha #include #include #include -#include #include #include -#ifdef HAVE_STRING_H -#include -#else -#ifdef HAVE_STRINGS_H -#include -#endif -#endif #include #include @@ -59,8 +61,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/fs.c,v 1.3 2003/07/30 17:23:46 ha #define MAXCELLHOSTS 8 #define MAXNAME 100 #define MAXSIZE 2048 -#define MAXINSIZE 1300 /* pioctl complains if data is larger than this */ -#define VMSGSIZE 128 /* size of msg buf in volume hdr */ +#define MAXINSIZE 1300 /* pioctl complains if data is larger than this */ +#define VMSGSIZE 128 /* size of msg buf in volume hdr */ static char space[MAXSIZE]; static char tspace[1024]; @@ -71,7 +73,6 @@ static int RxStatProcCmd(), RxStatPeerCmd(); extern char *hostutil_GetNameByINet(); extern struct hostent *hostutil_GetHostByName(); -extern afs_int32 VL_GetEntryByNameO(); extern struct cmd_syndesc *cmd_CreateSyntax(); @@ -95,10 +96,10 @@ static void Die(); typedef char sec_rgy_name_t[1025]; /* A DCE definition */ struct Acl { - int dfs; /* Originally true if a dfs acl; now also the type - of the acl (1, 2, or 3, corresponding to object, - initial dir, or initial object). */ - sec_rgy_name_t cell; /* DFS cell name */ + int dfs; /* Originally true if a dfs acl; now also the type + * of the acl (1, 2, or 3, corresponding to object, + * initial dir, or initial object). */ + sec_rgy_name_t cell; /* DFS cell name */ int nplus; int nminus; struct AclEntry *pluslist; @@ -111,27 +112,34 @@ struct AclEntry { afs_int32 rights; }; -static void ZapAcl(acl) - struct Acl *acl; +static void +ZapAcl(acl) + struct Acl *acl; { - if (!acl) return; + if (!acl) + return; ZapList(acl->pluslist); ZapList(acl->minuslist); free(acl); } -static foldcmp(a, b) - char *a; - char *b; +static +foldcmp(a, b) + char *a; + char *b; { char t, u; while (1) { - t = *a++; - u = *b++; - if (t >= 'A' && t <= 'Z') t += 0x20; - if (u >= 'A' && u <= 'Z') u += 0x20; - if (t != u) return 1; - if (t == 0) return 0; + t = *a++; + u = *b++; + if (t >= 'A' && t <= 'Z') + t += 0x20; + if (u >= 'A' && u <= 'Z') + u += 0x20; + if (t != u) + return 1; + if (t == 0) + return 0; } } @@ -151,14 +159,14 @@ static foldcmp(a, b) #define DFS_DELETE 0x20 /* the application definable ones (backwards from AFS) */ -#define DFS_USR0 0x80000000 /* "A" bit */ -#define DFS_USR1 0x40000000 /* "B" bit */ -#define DFS_USR2 0x20000000 /* "C" bit */ -#define DFS_USR3 0x10000000 /* "D" bit */ -#define DFS_USR4 0x08000000 /* "E" bit */ -#define DFS_USR5 0x04000000 /* "F" bit */ -#define DFS_USR6 0x02000000 /* "G" bit */ -#define DFS_USR7 0x01000000 /* "H" bit */ +#define DFS_USR0 0x80000000 /* "A" bit */ +#define DFS_USR1 0x40000000 /* "B" bit */ +#define DFS_USR2 0x20000000 /* "C" bit */ +#define DFS_USR3 0x10000000 /* "D" bit */ +#define DFS_USR4 0x08000000 /* "E" bit */ +#define DFS_USR5 0x04000000 /* "F" bit */ +#define DFS_USR6 0x02000000 /* "G" bit */ +#define DFS_USR7 0x01000000 /* "H" bit */ #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\ DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7) @@ -172,9 +180,9 @@ static int parm_setacl_id, parm_copyacl_id, parm_listacl_id; * Determine whether either the -id or -if switches are present, and * return 0, 1 or 2, as appropriate. Abort if both switches are present. */ -static int getidf(as, id) - struct cmd_syndesc *as; - int id; /* Offset of -id switch; -if is next switch */ +/* int id; Offset of -id switch; -if is next switch */ +static int +getidf(struct cmd_syndesc *as, int id) { int idf = 0; @@ -185,57 +193,97 @@ static int getidf(as, id) idf |= 2; } if (idf == 3) { - fprintf - (stderr, - "%s: you may specify either -id or -if, but not both switches\n", - pn); + fprintf(stderr, + "%s: you may specify either -id or -if, but not both switches\n", + pn); exit(1); } return idf; } -static int PRights(arights, dfs) - afs_int32 arights; - int dfs; +static int +PRights(afs_int32 arights, int dfs) { if (!dfs) { - if (arights & PRSFS_READ) printf("r"); - if (arights & PRSFS_LOOKUP) printf("l"); - if (arights & PRSFS_INSERT) printf("i"); - if (arights & PRSFS_DELETE) printf("d"); - if (arights & PRSFS_WRITE) printf("w"); - if (arights & PRSFS_LOCK) printf("k"); - if (arights & PRSFS_ADMINISTER) printf("a"); - if (arights & PRSFS_USR0) printf("A"); - if (arights & PRSFS_USR1) printf("B"); - if (arights & PRSFS_USR2) printf("C"); - if (arights & PRSFS_USR3) printf("D"); - if (arights & PRSFS_USR4) printf("E"); - if (arights & PRSFS_USR5) printf("F"); - if (arights & PRSFS_USR6) printf("G"); - if (arights & PRSFS_USR7) printf("H"); + if (arights & PRSFS_READ) + printf("r"); + if (arights & PRSFS_LOOKUP) + printf("l"); + if (arights & PRSFS_INSERT) + printf("i"); + if (arights & PRSFS_DELETE) + printf("d"); + if (arights & PRSFS_WRITE) + printf("w"); + if (arights & PRSFS_LOCK) + printf("k"); + if (arights & PRSFS_ADMINISTER) + printf("a"); + if (arights & PRSFS_USR0) + printf("A"); + if (arights & PRSFS_USR1) + printf("B"); + if (arights & PRSFS_USR2) + printf("C"); + if (arights & PRSFS_USR3) + printf("D"); + if (arights & PRSFS_USR4) + printf("E"); + if (arights & PRSFS_USR5) + printf("F"); + if (arights & PRSFS_USR6) + printf("G"); + if (arights & PRSFS_USR7) + printf("H"); } else { - if (arights & DFS_READ) printf("r"); else printf("-"); - if (arights & DFS_WRITE) printf("w"); else printf("-"); - if (arights & DFS_EXECUTE) printf("x"); else printf("-"); - if (arights & DFS_CONTROL) printf("c"); else printf("-"); - if (arights & DFS_INSERT) printf("i"); else printf("-"); - if (arights & DFS_DELETE) printf("d"); else printf("-"); - if (arights & (DFS_USRALL)) printf("+"); - if (arights & DFS_USR0) printf("A"); - if (arights & DFS_USR1) printf("B"); - if (arights & DFS_USR2) printf("C"); - if (arights & DFS_USR3) printf("D"); - if (arights & DFS_USR4) printf("E"); - if (arights & DFS_USR5) printf("F"); - if (arights & DFS_USR6) printf("G"); - if (arights & DFS_USR7) printf("H"); + if (arights & DFS_READ) + printf("r"); + else + printf("-"); + if (arights & DFS_WRITE) + printf("w"); + else + printf("-"); + if (arights & DFS_EXECUTE) + printf("x"); + else + printf("-"); + if (arights & DFS_CONTROL) + printf("c"); + else + printf("-"); + if (arights & DFS_INSERT) + printf("i"); + else + printf("-"); + if (arights & DFS_DELETE) + printf("d"); + else + printf("-"); + if (arights & (DFS_USRALL)) + printf("+"); + if (arights & DFS_USR0) + printf("A"); + if (arights & DFS_USR1) + printf("B"); + if (arights & DFS_USR2) + printf("C"); + if (arights & DFS_USR3) + printf("D"); + if (arights & DFS_USR4) + printf("E"); + if (arights & DFS_USR5) + printf("F"); + if (arights & DFS_USR6) + printf("G"); + if (arights & DFS_USR7) + printf("H"); } } /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */ -static int InAFS(apath) - char *apath; +static int +InAFS(char *apath) { struct ViceIoctl blob; afs_int32 code; @@ -246,98 +294,140 @@ static int InAFS(apath) code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1); if (code) { - if ((errno == EINVAL) || (errno == ENOENT)) return 0; + if ((errno == EINVAL) || (errno == ENOENT)) + return 0; } return 1; } /* return a static pointer to a buffer */ -static char *Parent(apath) - char *apath; +static char * +Parent(char *apath) { char *tp; strcpy(tspace, apath); tp = strrchr(tspace, '/'); if (tp) { *tp = 0; - } - else strcpy(tspace, "."); + } else + strcpy(tspace, "."); return tspace; } -enum rtype {add, destroy, deny}; +enum rtype { add, destroy, deny }; -static afs_int32 Convert(arights, dfs, rtypep) - char *arights; - int dfs; - enum rtype *rtypep; +static afs_int32 +Convert(char *arights, int dfs, enum rtype *rtypep) { int i, len; afs_int32 mode; char tc; - *rtypep = add; /* add rights, by default */ + *rtypep = add; /* add rights, by default */ if (dfs) { if (!strcmp(arights, "null")) { *rtypep = deny; return 0; } - if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE; - if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE; - if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL; + if (!strcmp(arights, "read")) + return DFS_READ | DFS_EXECUTE; + if (!strcmp(arights, "write")) + return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | + DFS_WRITE; + if (!strcmp(arights, "all")) + return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | + DFS_WRITE | DFS_CONTROL; } else { - if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP; - if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK; - if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP; - if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER; + if (!strcmp(arights, "read")) + return PRSFS_READ | PRSFS_LOOKUP; + if (!strcmp(arights, "write")) + return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | + PRSFS_WRITE | PRSFS_LOCK; + if (!strcmp(arights, "mail")) + return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP; + if (!strcmp(arights, "all")) + return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | + PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER; } if (!strcmp(arights, "none")) { - *rtypep = destroy; /* Remove entire entry */ + *rtypep = destroy; /* Remove entire entry */ return 0; } len = strlen(arights); mode = 0; - for(i=0;iname, aname)) return alist; - alist = alist->next; + if (!foldcmp(alist->name, aname)) + return alist; + alist = alist->next; } return 0; } /* if no parm specified in a particular slot, set parm to be "." instead */ -static void SetDotDefault(aitemp) - struct cmd_item **aitemp; +static void +SetDotDefault(struct cmd_item **aitemp) { struct cmd_item *ti; - if (*aitemp) return; /* already has value */ + if (*aitemp) + return; /* already has value */ /* otherwise, allocate an item representing "." */ - ti = (struct cmd_item *) malloc(sizeof(struct cmd_item)); + ti = (struct cmd_item *)malloc(sizeof(struct cmd_item)); assert(ti); - ti->next = (struct cmd_item *) 0; - ti->data = (char *) malloc(2); + ti->next = (struct cmd_item *)0; + ti->data = (char *)malloc(2); assert(ti->data); strcpy(ti->data, "."); *aitemp = ti; } -static void ChangeList(al, plus, aname, arights) - struct Acl *al; - afs_int32 plus; - char *aname; - afs_int32 arights; +static void +ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights) { struct AclEntry *tlist; tlist = (plus ? al->pluslist : al->minuslist); - tlist = FindList (tlist, aname); + tlist = FindList(tlist, aname); if (tlist) { - /* Found the item already in the list. */ - tlist->rights = arights; - if (plus) - al->nplus -= PruneList(&al->pluslist, al->dfs); - else - al->nminus -= PruneList(&al->minuslist, al->dfs); - return; + /* Found the item already in the list. */ + tlist->rights = arights; + if (plus) + al->nplus -= PruneList(&al->pluslist, al->dfs); + else + al->nminus -= PruneList(&al->minuslist, al->dfs); + return; } /* Otherwise we make a new item and plug in the new data. */ - tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry)); + tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry)); assert(tlist); strcpy(tlist->name, aname); tlist->rights = arights; if (plus) { - tlist->next = al->pluslist; - al->pluslist = tlist; - al->nplus++; - if (arights == 0 || arights == -1) + tlist->next = al->pluslist; + al->pluslist = tlist; + al->nplus++; + if (arights == 0 || arights == -1) al->nplus -= PruneList(&al->pluslist, al->dfs); - } - else { - tlist->next = al->minuslist; - al->minuslist = tlist; - al->nminus++; - if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs); + } else { + tlist->next = al->minuslist; + al->minuslist = tlist; + al->nminus++; + if (arights == 0) + al->nminus -= PruneList(&al->minuslist, al->dfs); } } -static void ZapList(alist) - struct AclEntry *alist; +static void +ZapList(struct AclEntry *alist) { struct AclEntry *tp, *np; for (tp = alist; tp; tp = np) { - np = tp->next; - free(tp); + np = tp->next; + free(tp); } } -static int PruneList(ae, dfs) - struct AclEntry **ae; - int dfs; +static int +PruneList(struct AclEntry **ae, int dfs) { struct AclEntry **lp; struct AclEntry *te, *ne; afs_int32 ctr; ctr = 0; lp = ae; - for(te = *ae;te;te=ne) { - if ((!dfs && te->rights == 0) || te->rights == -1) { - *lp = te->next; - ne = te->next; - free(te); - ctr++; - } - else { - ne = te->next; - lp = &te->next; + for (te = *ae; te; te = ne) { + if ((!dfs && te->rights == 0) || te->rights == -1) { + *lp = te->next; + ne = te->next; + free(te); + ctr++; + } else { + ne = te->next; + lp = &te->next; } } return ctr; } -static char *SkipLine(astr) - char *astr; +static char * +SkipLine(char *astr) { - while (*astr !='\n') astr++; + while (*astr != '\n') + astr++; astr++; return astr; } @@ -459,13 +546,13 @@ static char *SkipLine(astr) * assume that the acl is AFS: for DFS, the user can always resort to * acl_edit, but for AFS there may be no other way out). */ -static struct Acl *EmptyAcl(astr) - char *astr; +static struct Acl * +EmptyAcl(char *astr) { struct Acl *tp; int junk; - tp = (struct Acl *)malloc(sizeof (struct Acl)); + tp = (struct Acl *)malloc(sizeof(struct Acl)); assert(tp); tp->nplus = tp->nminus = 0; tp->pluslist = tp->minuslist = 0; @@ -474,15 +561,15 @@ static struct Acl *EmptyAcl(astr) return tp; } -static struct Acl *ParseAcl(astr) - char *astr; +static struct Acl * +ParseAcl(char *astr) { int nplus, nminus, i, trights; char tname[MAXNAME]; struct AclEntry *first, *last, *tl; struct Acl *ta; - ta = (struct Acl *) malloc (sizeof (struct Acl)); + ta = (struct Acl *)malloc(sizeof(struct Acl)); assert(ta); ta->dfs = 0; sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell); @@ -495,132 +582,149 @@ static struct Acl *ParseAcl(astr) last = 0; first = 0; - for(i=0;iname, tname); - tl->rights = trights; - tl->next = 0; - if (last) last->next = tl; - last = tl; + if (!first) + first = tl; + strcpy(tl->name, tname); + tl->rights = trights; + tl->next = 0; + if (last) + last->next = tl; + last = tl; } ta->pluslist = first; last = 0; first = 0; - for(i=0;iname, tname); - tl->rights = trights; - tl->next = 0; - if (last) last->next = tl; - last = tl; + if (!first) + first = tl; + strcpy(tl->name, tname); + tl->rights = trights; + tl->next = 0; + if (last) + last->next = tl; + last = tl; } ta->minuslist = first; return ta; } -static PrintStatus(status, name, offmsg) - VolumeStatus *status; - char *name; - char *offmsg; +static int +PrintStatus(VolumeStatus * status, char *name, char *offmsg) { - printf("Volume status for vid = %u named %s\n",status->Vid, name); + printf("Volume status for vid = %u named %s\n", status->Vid, name); if (*offmsg != 0) - printf("Current offline message is %s\n",offmsg); + printf("Current offline message is %s\n", offmsg); printf("Current disk quota is "); - if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota); - else printf("unlimited\n"); - printf("Current blocks used are %d\n",status->BlocksInUse); - printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks); + if (status->MaxQuota != 0) + printf("%d\n", status->MaxQuota); + else + printf("unlimited\n"); + printf("Current blocks used are %d\n", status->BlocksInUse); + printf("The partition has %d blocks available out of %d\n\n", + status->PartBlocksAvail, status->PartMaxBlocks); + return 0; } -static QuickPrintStatus(status, name) - VolumeStatus *status; - char *name; +static int +QuickPrintStatus(VolumeStatus * status, char *name) { - double QuotaUsed =0.0; - double PartUsed =0.0; + double QuotaUsed = 0.0; + double PartUsed = 0.0; int WARN = 0; - printf("%-25.25s",name); + printf("%-25.25s", name); if (status->MaxQuota != 0) { printf("%10d%10d", status->MaxQuota, status->BlocksInUse); - QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0); + QuotaUsed = + ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0); } else { printf(" no limit%10d", status->BlocksInUse); } if (QuotaUsed > 90.0) { printf("%5.0f%%<<", QuotaUsed); WARN = 1; - } - else printf("%5.0f%% ", QuotaUsed); - PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0)); + } else + printf("%5.0f%% ", QuotaUsed); + PartUsed = + (100.0 - + ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) * + 100.0)); if (PartUsed > 97.0) { printf("%9.0f%%<<", PartUsed); WARN = 1; - } - else printf("%9.0f%% ", PartUsed); - if (WARN){ + } else + printf("%9.0f%% ", PartUsed); + if (WARN) { printf(" <PartMaxBlocks, + status->PartMaxBlocks - status->PartBlocksAvail, + status->PartBlocksAvail); - printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail); - - PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0)); - if (PartUsed > 90.0){ + PartUsed = + (100.0 - + ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) * + 100.0)); + if (PartUsed > 90.0) { printf(" %4.0f%%<<", PartUsed); WARN = 1; - } - else printf(" %4.0f%% ", PartUsed); - if (WARN){ + } else + printf(" %4.0f%% ", PartUsed); + if (WARN) { printf(" <dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell); - else dfsstring[0] = '\0'; + if (acl->dfs) + sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell); + else + dfsstring[0] = '\0'; sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus); - for(tp = acl->pluslist;tp;tp=tp->next) { - sprintf(tstring, "%s %d\n", tp->name, tp->rights); - strcat(mydata, tstring); + for (tp = acl->pluslist; tp; tp = tp->next) { + sprintf(tstring, "%s %d\n", tp->name, tp->rights); + strcat(mydata, tstring); } - for(tp = acl->minuslist;tp;tp=tp->next) { - sprintf(tstring, "%s %d\n", tp->name, tp->rights); - strcat(mydata, tstring); + for (tp = acl->minuslist; tp; tp = tp->next) { + sprintf(tstring, "%s %d\n", tp->name, tp->rights); + strcat(mydata, tstring); } return mydata; } -static SetACLCmd(as) - struct cmd_syndesc *as; +static int +SetACLCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -632,10 +736,12 @@ static SetACLCmd(as) int idf = getidf(as, parm_setacl_id); int error = 0; - if (as->parms[2].items) clear=1; - else clear=0; + if (as->parms[2].items) + clear = 1; + else + clear = 0; plusp = !(as->parms[3].items); - for(ti=as->parms[0].items; ti;ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { blob.out_size = MAXSIZE; blob.in_size = idf; blob.in = blob.out = space; @@ -646,7 +752,8 @@ static SetACLCmd(as) continue; } - if (ta) ZapAcl(ta); + if (ta) + ZapAcl(ta); ta = ParseAcl(space); if (!plusp && ta->dfs) { fprintf(stderr, @@ -657,32 +764,38 @@ static SetACLCmd(as) continue; } - if (ta) ZapAcl(ta); - if (clear) ta = EmptyAcl(space); - else ta = ParseAcl(space); + if (ta) + ZapAcl(ta); + if (clear) + ta = EmptyAcl(space); + else + ta = ParseAcl(space); CleanAcl(ta, ti->data); - for(ui=as->parms[1].items; ui; ui=ui->next->next) { + for (ui = as->parms[1].items; ui; ui = ui->next->next) { enum rtype rtype; if (!ui->next) { - fprintf(stderr, "%s: Missing second half of user/access pair.\n", pn); + fprintf(stderr, + "%s: Missing second half of user/access pair.\n", pn); ZapAcl(ta); return 1; } rights = Convert(ui->next->data, ta->dfs, &rtype); if (rtype == destroy && !ta->dfs) { - struct AclEntry *tlist; + struct AclEntry *tlist; - tlist = (plusp ? ta->pluslist : ta->minuslist); + tlist = (plusp ? ta->pluslist : ta->minuslist); if (!FindList(tlist, ui->data)) - continue; + continue; } - if (rtype == deny && !ta->dfs) plusp = 0; - if (rtype == destroy && ta->dfs) rights = -1; + if (rtype == deny && !ta->dfs) + plusp = 0; + if (rtype == destroy && ta->dfs) + rights = -1; ChangeList(ta, plusp, ui->data, rights); } blob.in = AclToString(ta); - blob.out_size=0; - blob.in_size = 1+strlen(blob.in); + blob.out_size = 0; + blob.in_size = 1 + strlen(blob.in); code = pioctl(ti->data, VIOCSETAL, &blob, 1); if (code) { if (errno == EINVAL) { @@ -691,55 +804,61 @@ static SetACLCmd(as) if (!fsenv) { fsenv = (char *)getenv("FS_EXPERT"); } - fprintf(stderr, "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n", pn); + fprintf(stderr, + "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n", + pn); if (!fsenv) { fprintf(stderr, - "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", - "\nPossible reasons for this include:\n\n", - " -You may have specified an inappropriate combination of rights.\n", - " For example, some DFS-supported filesystems may not allow you to\n", - " drop the \"c\" right from \"user_obj\".\n\n", - " -A mask_obj may be required (it is likely required by the underlying\n", - " filesystem if you try to set anything other than the basic \"user_obj\"\n", - " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n", - " does not automatically create or update the mask_obj. Try setting\n", - " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n", - " users or groups. You can do this with a single command, such as\n", - " \"fs sa mask_obj all user:somename read\"\n\n", - " -A specified user or group may not exist.\n\n", - " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n", - " This is probably not allowed by the underlying file system.\n\n", - " -If you add a user or group to a DFS ACL, remember that it must be\n", - " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n", - " may be local requirements on the format of the user or group name.\n", - " Check with your cell administrator.\n\n", - " -Or numerous other possibilities. It would be great if we could be more\n", - " precise about the actual problem, but for various reasons, this is\n", - " impractical via this interface. If you can't figure it out, you\n", - " might try logging into a DCE-equipped machine and use acl_edit (or\n", - " whatever is provided). You may get better results. Good luck!\n\n", - " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n"); + "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", + "\nPossible reasons for this include:\n\n", + " -You may have specified an inappropriate combination of rights.\n", + " For example, some DFS-supported filesystems may not allow you to\n", + " drop the \"c\" right from \"user_obj\".\n\n", + " -A mask_obj may be required (it is likely required by the underlying\n", + " filesystem if you try to set anything other than the basic \"user_obj\"\n", + " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n", + " does not automatically create or update the mask_obj. Try setting\n", + " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n", + " users or groups. You can do this with a single command, such as\n", + " \"fs sa mask_obj all user:somename read\"\n\n", + " -A specified user or group may not exist.\n\n", + " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n", + " This is probably not allowed by the underlying file system.\n\n", + " -If you add a user or group to a DFS ACL, remember that it must be\n", + " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n", + " may be local requirements on the format of the user or group name.\n", + " Check with your cell administrator.\n\n", + " -Or numerous other possibilities. It would be great if we could be more\n", + " precise about the actual problem, but for various reasons, this is\n", + " impractical via this interface. If you can't figure it out, you\n", + " might try logging into a DCE-equipped machine and use acl_edit (or\n", + " whatever is provided). You may get better results. Good luck!\n\n", + " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n"); } } else { - fprintf(stderr, "%s: Invalid argument, possible reasons include:\n", pn); + fprintf(stderr, + "%s: Invalid argument, possible reasons include:\n", + pn); fprintf(stderr, "\t-File not in AFS\n"); - fprintf(stderr, "\t-Too many users on access control list\n"); - fprintf(stderr, "\t-Tried to add non-existent user to access control list\n"); + fprintf(stderr, + "\t-Too many users on access control list\n"); + fprintf(stderr, + "\t-Tried to add non-existent user to access control list\n"); } - } - else { + } else { Die(errno, ti->data); } error = 1; } } - if (ta) ZapAcl(ta); + if (ta) + ZapAcl(ta); return error; } -static CopyACLCmd(as) - struct cmd_syndesc *as; +static int +CopyACLCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -752,8 +871,10 @@ static CopyACLCmd(as) int idf = getidf(as, parm_copyacl_id); int error = 0; - if (as->parms[2].items) clear=1; - else clear=0; + if (as->parms[2].items) + clear = 1; + else + clear = 0; blob.out_size = MAXSIZE; blob.in_size = idf; blob.in = blob.out = space; @@ -764,7 +885,7 @@ static CopyACLCmd(as) } fa = ParseAcl(space); CleanAcl(fa, as->parms[0].items->data); - for (ti=as->parms[1].items; ti;ti=ti->next) { + for (ti = as->parms[1].items; ti; ti = ti->next) { blob.out_size = MAXSIZE; blob.in_size = idf; blob.in = blob.out = space; @@ -775,96 +896,106 @@ static CopyACLCmd(as) continue; } - if (ta) ZapAcl(ta); - if (clear) ta = EmptyAcl(space); - else ta = ParseAcl(space); + if (ta) + ZapAcl(ta); + if (clear) + ta = EmptyAcl(space); + else + ta = ParseAcl(space); CleanAcl(ta, ti->data); if (ta->dfs != fa->dfs) { - fprintf(stderr, "%s: incompatible file system types: acl not copied to %s; aborted\n", pn, ti->data); + fprintf(stderr, + "%s: incompatible file system types: acl not copied to %s; aborted\n", + pn, ti->data); error = 1; continue; } if (ta->dfs) { - if (! clear && strcmp(ta->cell, fa->cell) != 0) { - fprintf(stderr, "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", pn, ti->data); + if (!clear && strcmp(ta->cell, fa->cell) != 0) { + fprintf(stderr, + "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", + pn, ti->data); error = 1; continue; } strcpy(ta->cell, fa->cell); } - for (tp = fa->pluslist;tp;tp=tp->next) + for (tp = fa->pluslist; tp; tp = tp->next) ChangeList(ta, 1, tp->name, tp->rights); - for (tp = fa->minuslist;tp;tp=tp->next) + for (tp = fa->minuslist; tp; tp = tp->next) ChangeList(ta, 0, tp->name, tp->rights); blob.in = AclToString(ta); - blob.out_size=0; - blob.in_size = 1+strlen(blob.in); + blob.out_size = 0; + blob.in_size = 1 + strlen(blob.in); code = pioctl(ti->data, VIOCSETAL, &blob, 1); if (code) { if (errno == EINVAL) { - fprintf(stderr, "%s: Invalid argument, possible reasons include:\n", pn); + fprintf(stderr, + "%s: Invalid argument, possible reasons include:\n", + pn); fprintf(stderr, "\t-File not in AFS\n"); - } - else { + } else { Die(errno, ti->data); } error = 1; } } - if (ta) ZapAcl(ta); + if (ta) + ZapAcl(ta); ZapAcl(fa); return error; } /* pioctl() call to get the cellname of a pathname */ -static afs_int32 GetCell(fname, cellname) - char *fname, *cellname; +static afs_int32 +GetCell(char *fname, char *cellname) { - afs_int32 code; - struct ViceIoctl blob; + afs_int32 code; + struct ViceIoctl blob; - blob.in_size = 0; - blob.out_size = MAXCELLCHARS; - blob.out = cellname; + blob.in_size = 0; + blob.out_size = MAXCELLCHARS; + blob.out = cellname; - code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1); - return code ? errno : 0; + code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1); + return code ? errno : 0; } /* Check if a username is valid: If it contains only digits (or a * negative sign), then it might be bad. We then query the ptserver * to see. */ -static BadName(aname, fname) - char *aname, *fname; +static +BadName(char *aname, char *fname) { - afs_int32 tc, code, id; - char *nm; + afs_int32 tc, code, id; + char *nm; char cell[MAXCELLCHARS]; - for (nm=aname; tc=*nm; nm++) { + for (nm = aname; tc = *nm; nm++) { /* all must be '-' or digit to be bad */ - if (tc != '-' && (tc < '0' || tc > '9')) return 0; + if (tc != '-' && (tc < '0' || tc > '9')) + return 0; } /* Go to the PRDB and see if this all number username is valid */ code = GetCell(fname, cell); - if (code) return 0; + if (code) + return 0; pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell); code = pr_SNameToId(aname, &id); pr_End(); /* 1=>Not-valid; 0=>Valid */ - return ((!code && (id==ANONYMOUSID)) ? 1 : 0); + return ((!code && (id == ANONYMOUSID)) ? 1 : 0); } /* clean up an access control list of its bad entries; return 1 if we made any changes to the list, and 0 otherwise */ -static CleanAcl(aa, fname) - struct Acl *aa; - char *fname; /* The file name */ +static +CleanAcl(struct Acl *aa, char *fname) { struct AclEntry *te, **le, *ne; int changes; @@ -874,32 +1005,30 @@ static CleanAcl(aa, fname) return 0; /* prune out bad entries */ - changes = 0; /* count deleted entries */ + changes = 0; /* count deleted entries */ le = &aa->pluslist; - for(te = aa->pluslist; te; te=ne) { + for (te = aa->pluslist; te; te = ne) { ne = te->next; - if (BadName(te->name,fname)) { + if (BadName(te->name, fname)) { /* zap this dude */ *le = te->next; aa->nplus--; free(te); changes++; - } - else { + } else { le = &te->next; } } le = &aa->minuslist; - for(te = aa->minuslist; te; te=ne) { + for (te = aa->minuslist; te; te = ne) { ne = te->next; - if (BadName(te->name,fname)) { + if (BadName(te->name, fname)) { /* zap this dude */ *le = te->next; aa->nminus--; free(te); changes++; - } - else { + } else { le = &te->next; } } @@ -908,8 +1037,8 @@ static CleanAcl(aa, fname) /* clean up an acl to not have bogus entries */ -static CleanACLCmd(as) - struct cmd_syndesc *as; +static int +CleanACLCmd(struct cmd_syndesc *as) { afs_int32 code; struct Acl *ta = 0; @@ -920,7 +1049,7 @@ static CleanACLCmd(as) int error = 0; SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { blob.out_size = MAXSIZE; blob.in_size = 0; blob.out = space; @@ -931,7 +1060,8 @@ static CleanACLCmd(as) continue; } - if (ta) ZapAcl(ta); + if (ta) + ZapAcl(ta); ta = ParseAcl(space); if (ta->dfs) { fprintf(stderr, @@ -945,17 +1075,20 @@ static CleanACLCmd(as) if (changes) { /* now set the acl */ - blob.in=AclToString(ta); - blob.in_size = strlen(blob.in)+1; + blob.in = AclToString(ta); + blob.in_size = strlen(blob.in) + 1; blob.out_size = 0; code = pioctl(ti->data, VIOCSETAL, &blob, 1); if (code) { if (errno == EINVAL) { - fprintf(stderr, "%s: Invalid argument, possible reasons include\n", pn); + fprintf(stderr, + "%s: Invalid argument, possible reasons include\n", + pn); fprintf(stderr, "%s: File not in vice or\n", pn); - fprintf(stderr, "%s: Too many users on access control list or\n", pn); - } - else { + fprintf(stderr, + "%s: Too many users on access control list or\n", + pn); + } else { Die(errno, ti->data); } error = 1; @@ -965,8 +1098,9 @@ static CleanACLCmd(as) /* now list the updated acl */ printf("Access list for %s is now\n", ti->data); if (ta->nplus > 0) { - if (!ta->dfs) printf("Normal rights:\n"); - for(te = ta->pluslist;te;te=te->next) { + if (!ta->dfs) + printf("Normal rights:\n"); + for (te = ta->pluslist; te; te = te->next) { printf(" %s ", te->name); PRights(te->rights, ta->dfs); printf("\n"); @@ -974,23 +1108,24 @@ static CleanACLCmd(as) } if (ta->nminus > 0) { printf("Negative rights:\n"); - for(te = ta->minuslist;te;te=te->next) { + for (te = ta->minuslist; te; te = te->next) { printf(" %s ", te->name); PRights(te->rights, ta->dfs); printf("\n"); } } - if (ti->next) printf("\n"); - } - else + if (ti->next) + printf("\n"); + } else printf("Access list for %s is fine.\n", ti->data); } - if (ta) ZapAcl(ta); + if (ta) + ZapAcl(ta); return error; } -static ListACLCmd(as) - struct cmd_syndesc *as; +static int +ListACLCmd(struct cmd_syndesc *as) { afs_int32 code; struct Acl *ta; @@ -1001,7 +1136,7 @@ static ListACLCmd(as) int error = 0; SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { blob.out_size = MAXSIZE; blob.in_size = idf; blob.in = blob.out = space; @@ -1030,8 +1165,9 @@ static ListACLCmd(as) printf(" Default cell = %s\n", ta->cell); } if (ta->nplus > 0) { - if (!ta->dfs) printf("Normal rights:\n"); - for(te = ta->pluslist;te;te=te->next) { + if (!ta->dfs) + printf("Normal rights:\n"); + for (te = ta->pluslist; te; te = te->next) { printf(" %s ", te->name); PRights(te->rights, ta->dfs); printf("\n"); @@ -1039,20 +1175,21 @@ static ListACLCmd(as) } if (ta->nminus > 0) { printf("Negative rights:\n"); - for(te = ta->minuslist;te;te=te->next) { + for (te = ta->minuslist; te; te = te->next) { printf(" %s ", te->name); PRights(te->rights, ta->dfs); printf("\n"); } } - if (ti->next) printf("\n"); + if (ti->next) + printf("\n"); ZapAcl(ta); } return error; } -static FlushVolumeCmd(as) - struct cmd_syndesc *as; +static int +FlushVolumeCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1060,7 +1197,7 @@ static FlushVolumeCmd(as) int error = 0; SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { blob.in_size = blob.out_size = 0; code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0); if (code) { @@ -1073,22 +1210,22 @@ static FlushVolumeCmd(as) return error; } -static FlushCmd(as) - struct cmd_syndesc *as; +static int +FlushCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; struct cmd_item *ti; int error = 0; - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { blob.in_size = blob.out_size = 0; code = pioctl(ti->data, VIOCFLUSH, &blob, 0); if (code) { if (errno == EMFILE) { - fprintf(stderr, "%s: Can't flush active file %s\n", pn, ti->data); - } - else { + fprintf(stderr, "%s: Can't flush active file %s\n", pn, + ti->data); + } else { fprintf(stderr, "%s: Error flushing file ", pn); perror(ti->data); } @@ -1100,8 +1237,8 @@ static FlushCmd(as) } /* all this command does is repackage its args and call SetVolCmd */ -static SetQuotaCmd(as) - struct cmd_syndesc *as; +static int +SetQuotaCmd(struct cmd_syndesc *as) { struct cmd_syndesc ts; @@ -1110,8 +1247,8 @@ static SetQuotaCmd(as) return SetVolCmd(&ts); } -static SetVolCmd(as) - struct cmd_syndesc *as; +static int +SetVolCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1121,15 +1258,15 @@ static SetVolCmd(as) int error = 0; SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ blob.out_size = MAXSIZE; blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */ blob.out = space; blob.in = space; - status = (VolumeStatus *)space; + status = (VolumeStatus *) space; status->MinQuota = status->MaxQuota = -1; - offmsg = (char *) 0; + offmsg = NULL; if (as->parms[1].items) { code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota); if (code) { @@ -1138,23 +1275,25 @@ static SetVolCmd(as) continue; } } - if (as->parms[2].items) offmsg = as->parms[2].items->data; + if (as->parms[2].items) + offmsg = as->parms[2].items->data; input = (char *)status + sizeof(*status); *(input++) = '\0'; /* never set name: this call doesn't change vldb */ - if(offmsg) { + if (offmsg) { if (strlen(offmsg) >= VMSGSIZE) { - fprintf(stderr, "%s: message must be shorter than %d characters\n", + fprintf(stderr, + "%s: message must be shorter than %d characters\n", pn, VMSGSIZE); error = 1; continue; } - strcpy(input,offmsg); + strcpy(input, offmsg); blob.in_size += strlen(offmsg); input += strlen(offmsg) + 1; - } - else *(input++) = '\0'; - *(input++) = '\0'; /* Pad for old style volume "motd" */ - code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1); + } else + *(input++) = '\0'; + *(input++) = '\0'; /* Pad for old style volume "motd" */ + code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1); if (code) { Die(errno, ti->data); error = 1; @@ -1163,8 +1302,17 @@ static SetVolCmd(as) return error; } -static ExamineCmd(as) - struct cmd_syndesc *as; +/* + * Why is VenusFid declared in the kernel-only section of afs.h, + * if it's the exported interface of the cache manager? + */ +struct VenusFid { + afs_int32 Cell; + AFSFid Fid; +}; + +static int +ExamineCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1174,7 +1322,9 @@ static ExamineCmd(as) int error = 0; SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { + struct VenusFid vfid; + /* once per file */ blob.out_size = MAXSIZE; blob.in_size = 0; @@ -1185,16 +1335,25 @@ static ExamineCmd(as) error = 1; continue; } - status = (VolumeStatus *)space; + status = (VolumeStatus *) space; name = (char *)status + sizeof(*status); offmsg = name + strlen(name) + 1; + + blob.out_size = sizeof(struct VenusFid); + blob.out = (char *) &vfid; + if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) { + printf("File %s (%u.%u.%u) contained in volume %u\n", + ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique, + vfid.Fid.Volume); + } + PrintStatus(status, name, offmsg); } return error; } -static ListQuotaCmd(as) - struct cmd_syndesc *as; +static int +ListQuotaCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1203,10 +1362,10 @@ static ListQuotaCmd(as) char *name; int error = 0; - printf("%-25s%-10s%-10s%-7s%-11s\n", - "Volume Name"," Quota", " Used", " %Used", " Partition"); + printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota", + " Used", " %Used", " Partition"); SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ blob.out_size = MAXSIZE; blob.in_size = 0; @@ -1217,15 +1376,15 @@ static ListQuotaCmd(as) error = 1; continue; } - status = (VolumeStatus *)space; + status = (VolumeStatus *) space; name = (char *)status + sizeof(*status); QuickPrintStatus(status, name); } return error; } -static WhereIsCmd(as) - struct cmd_syndesc *as; +static int +WhereIsCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1236,7 +1395,7 @@ static WhereIsCmd(as) int error = 0; SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ blob.out_size = MAXSIZE; blob.in_size = 0; @@ -1249,9 +1408,11 @@ static WhereIsCmd(as) continue; } hosts = (afs_int32 *) space; - printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s"); - for(j=0; jdata, + (hosts[0] && !hosts[1]) ? "" : "s"); + for (j = 0; j < MAXHOSTS; j++) { + if (hosts[j] == 0) + break; tp = hostutil_GetNameByINet(hosts[j]); printf("%s ", tp); } @@ -1261,8 +1422,8 @@ static WhereIsCmd(as) } -static DiskFreeCmd(as) - struct cmd_syndesc *as; +static int +DiskFreeCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1271,10 +1432,10 @@ static DiskFreeCmd(as) struct VolumeStatus *status; int error = 0; - printf("%-25s%-10s%-10s%-10s%-6s\n", - "Volume Name"," kbytes", " used", " avail", " %used"); + printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes", + " used", " avail", " %used"); SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ blob.out_size = MAXSIZE; blob.in_size = 0; @@ -1285,15 +1446,15 @@ static DiskFreeCmd(as) error = 1; continue; } - status = (VolumeStatus *)space; + status = (VolumeStatus *) space; name = (char *)status + sizeof(*status); QuickPrintSpace(status, name); } return error; } -static QuotaCmd(as) - struct cmd_syndesc *as; +static int +QuotaCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1303,7 +1464,7 @@ static QuotaCmd(as) int error = 0; SetDotDefault(&as->parms[0].items); - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ blob.out_size = MAXSIZE; blob.in_size = 0; @@ -1314,41 +1475,43 @@ static QuotaCmd(as) error = 1; continue; } - status = (VolumeStatus *)space; - if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0); - else quotaPct = 0.0; + status = (VolumeStatus *) space; + if (status->MaxQuota) + quotaPct = + ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0); + else + quotaPct = 0.0; printf("%2.0f%% of quota used.\n", quotaPct); } return error; } -static ListMountCmd(as) - struct cmd_syndesc *as; +static int +ListMountCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; struct cmd_item *ti; - char orig_name[1024]; /*Original name, may be modified*/ - char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/ - char parent_dir[1024]; /*Parent directory of true name*/ - char *last_component; /*Last component of true name*/ - struct stat statbuff; /*Buffer for status info*/ - int link_chars_read; /*Num chars read in readlink()*/ - int thru_symlink; /*Did we get to a mount point via a symlink?*/ + char orig_name[1024]; /*Original name, may be modified */ + char true_name[1024]; /*``True'' dirname (e.g., symlink target) */ + char parent_dir[1024]; /*Parent directory of true name */ + char *last_component; /*Last component of true name */ + struct stat statbuff; /*Buffer for status info */ + int link_chars_read; /*Num chars read in readlink() */ + int thru_symlink; /*Did we get to a mount point via a symlink? */ int error = 0; - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ thru_symlink = 0; - sprintf(orig_name, "%s%s", - (ti->data[0] == '/') ? "" : "./", + sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./", ti->data); if (lstat(orig_name, &statbuff) < 0) { /* if lstat fails, we should still try the pioctl, since it - may work (for example, lstat will fail, but pioctl will - work if the volume of offline (returning ENODEV). */ - statbuff.st_mode = S_IFDIR; /* lie like pros */ + * may work (for example, lstat will fail, but pioctl will + * work if the volume of offline (returning ENODEV). */ + statbuff.st_mode = S_IFDIR; /* lie like pros */ } /* @@ -1362,8 +1525,9 @@ static ListMountCmd(as) */ link_chars_read = readlink(orig_name, true_name, 1024); if (link_chars_read <= 0) { - fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n", - pn, orig_name); + fprintf(stderr, + "%s: Can't read target name for '%s' symbolic link!\n", + pn, orig_name); error = 1; continue; } @@ -1380,18 +1544,17 @@ static ListMountCmd(as) * name (we know there is one) and splice in the symlink value. */ if (true_name[0] != '/') { - last_component = (char *) strrchr(orig_name, '/'); + last_component = (char *)strrchr(orig_name, '/'); strcpy(++last_component, true_name); strcpy(true_name, orig_name); } - } - else + } else strcpy(true_name, orig_name); /* * Find rightmost slash, if any. */ - last_component = (char *) strrchr(true_name, '/'); + last_component = (char *)strrchr(true_name, '/'); if (last_component) { /* * Found it. Designate everything before it as the parent directory, @@ -1399,9 +1562,8 @@ static ListMountCmd(as) */ strncpy(parent_dir, true_name, last_component - true_name); parent_dir[last_component - true_name] = 0; - last_component++; /*Skip the slash*/ - } - else { + last_component++; /*Skip the slash */ + } else { /* * No slash appears in the given file name. Set parent_dir to the current * directory, and the last component as the given name. @@ -1410,15 +1572,19 @@ static ListMountCmd(as) last_component = true_name; } - if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) { - fprintf(stderr, "%s: you may not use '.' or '..' as the last component\n", pn); - fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n", pn); + if (strcmp(last_component, ".") == 0 + || strcmp(last_component, "..") == 0) { + fprintf(stderr, + "%s: you may not use '.' or '..' as the last component\n", + pn); + fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n", + pn); error = 1; continue; } blob.in = last_component; - blob.in_size = strlen(last_component)+1; + blob.in_size = strlen(last_component) + 1; blob.out_size = MAXSIZE; blob.out = space; memset(space, 0, MAXSIZE); @@ -1426,17 +1592,13 @@ static ListMountCmd(as) code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1); if (code == 0) { - printf("'%s' is a %smount point for volume '%s'\n", - ti->data, + printf("'%s' is a %smount point for volume '%s'\n", ti->data, (thru_symlink ? "symbolic link, leading to a " : ""), space); - } - else { + } else { if (errno == EINVAL) { - fprintf(stderr, "'%s' is not a mount point.\n", - ti->data); - } - else { + fprintf(stderr, "'%s' is not a mount point.\n", ti->data); + } else { Die(errno, (ti->data ? ti->data : parent_dir)); } error = 1; @@ -1445,8 +1607,8 @@ static ListMountCmd(as) return error; } -static MakeMountCmd(as) - struct cmd_syndesc *as; +static +MakeMountCmd(struct cmd_syndesc *as) { afs_int32 code; char *cellName, *volName, *tmpName; @@ -1467,11 +1629,13 @@ defect #3069 if (as->parms[2].items) /* cell name specified */ cellName = as->parms[2].items->data; else - cellName = (char *) 0; + cellName = NULL; volName = as->parms[1].items->data; if (strlen(volName) >= 64) { - fprintf(stderr, "%s: volume name too long (length must be < 64 characters)\n", pn); + fprintf(stderr, + "%s: volume name too long (length must be < 64 characters)\n", + pn); return 1; } @@ -1480,7 +1644,7 @@ defect #3069 if (tmpName = strchr(volName, ':')) { *tmpName = '\0'; if (cellName) { - if (strcasecmp(cellName,volName)) { + if (strcasecmp(cellName, volName)) { fprintf(stderr, "%s: cellnames do not match.\n", pn); return 1; } @@ -1490,7 +1654,9 @@ defect #3069 } if (!InAFS(Parent(as->parms[0].items->data))) { - fprintf(stderr, "%s: mount points must be created within the AFS file system\n", pn); + fprintf(stderr, + "%s: mount points must be created within the AFS file system\n", + pn); return 1; } @@ -1498,10 +1664,12 @@ defect #3069 blob.in_size = 0; blob.out_size = MAXSIZE; blob.out = space; - code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1); + code = + pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, + &blob, 1); } - code = GetCellName(cellName?cellName:space, &info); + code = GetCellName(cellName ? cellName : space, &info); if (code) { return 1; } @@ -1511,9 +1679,12 @@ defect #3069 code = VLDBInit(1, &info); if (code == 0) { /* make the check. Don't complain if there are problems with init */ - code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry); + code = + ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, + &vldbEntry); if (code == VL_NOENT) { - fprintf(stderr, "%s: warning, volume %s does not exist in cell %s.\n", + fprintf(stderr, + "%s: warning, volume %s does not exist in cell %s.\n", pn, volName, cellName ? cellName : space); } } @@ -1544,10 +1715,10 @@ defect #3069 * (or ``.'' if none is provided) * tp: Set to point to the actual name of the mount point to nuke. */ -static RemoveMountCmd(as) - struct cmd_syndesc *as; +static int +RemoveMountCmd(struct cmd_syndesc *as) { - afs_int32 code=0; + afs_int32 code = 0; struct ViceIoctl blob; struct cmd_item *ti; char tbuffer[1024]; @@ -1555,36 +1726,35 @@ static RemoveMountCmd(as) char *tp; int error = 0; - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ - tp = (char *) strrchr(ti->data, '/'); + tp = (char *)strrchr(ti->data, '/'); if (tp) { - strncpy(tbuffer, ti->data, code=tp-ti->data); /* the dir name */ + strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */ tbuffer[code] = 0; - tp++; /* skip the slash */ - } - else { + tp++; /* skip the slash */ + } else { strcpy(tbuffer, "."); tp = ti->data; } blob.in = tp; - blob.in_size = strlen(tp)+1; + blob.in_size = strlen(tp) + 1; blob.out = lsbuffer; blob.out_size = sizeof(lsbuffer); code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0); if (code) { if (errno == EINVAL) { - fprintf(stderr, "%s: '%s' is not a mount point.\n", pn, ti->data); - } - else { + fprintf(stderr, "%s: '%s' is not a mount point.\n", pn, + ti->data); + } else { Die(errno, ti->data); } error = 1; - continue; /* don't bother trying */ + continue; /* don't bother trying */ } blob.out_size = 0; blob.in = tp; - blob.in_size = strlen(tp)+1; + blob.in_size = strlen(tp) + 1; code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0); if (code) { Die(errno, ti->data); @@ -1597,8 +1767,8 @@ static RemoveMountCmd(as) /* */ -static CheckServersCmd(as) - struct cmd_syndesc *as; +static int +CheckServersCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1611,20 +1781,22 @@ static CheckServersCmd(as) struct chservinfo checkserv; memset(&checkserv, 0, sizeof(struct chservinfo)); - blob.in_size=sizeof(struct chservinfo); - blob.in=(caddr_t)&checkserv; + blob.in_size = sizeof(struct chservinfo); + blob.in = (caddr_t) & checkserv; blob.out_size = MAXSIZE; blob.out = space; memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */ /* prepare flags for checkservers command */ - temp = 2; /* default to checking local cell only */ - if (as->parms[2].items) temp |= 1; /* set fast flag */ - if (as->parms[1].items) temp &= ~2; /* turn off local cell check */ + temp = 2; /* default to checking local cell only */ + if (as->parms[2].items) + temp |= 1; /* set fast flag */ + if (as->parms[1].items) + temp &= ~2; /* turn off local cell check */ checkserv.magic = 0x12345678; /* XXX */ - checkserv.tflags=temp; + checkserv.tflags = temp; /* now copy in optional cell name, if specified */ if (as->parms[0].items) { @@ -1632,28 +1804,27 @@ static CheckServersCmd(as) if (code) { return 1; } - strcpy(checkserv.tbuffer,info.name); - checkserv.tsize=strlen(info.name)+1; - } - else { - strcpy(checkserv.tbuffer,"\0"); - checkserv.tsize=0; + strcpy(checkserv.tbuffer, info.name); + checkserv.tsize = strlen(info.name) + 1; + } else { + strcpy(checkserv.tbuffer, "\0"); + checkserv.tsize = 0; } - if(as->parms[3].items) { - checkserv.tinterval=atol(as->parms[3].items->data); + if (as->parms[3].items) { + checkserv.tinterval = atol(as->parms[3].items->data); /* sanity check */ - if(checkserv.tinterval<0) { - printf("Warning: The negative -interval is ignored; treated as an inquiry\n"); - checkserv.tinterval=0; - } - else if(checkserv.tinterval> 600) { - printf("Warning: The maximum -interval value is 10 mins (600 secs)\n"); - checkserv.tinterval=600; /* 10 min max interval */ + if (checkserv.tinterval < 0) { + printf + ("Warning: The negative -interval is ignored; treated as an inquiry\n"); + checkserv.tinterval = 0; + } else if (checkserv.tinterval > 600) { + printf + ("Warning: The maximum -interval value is 10 mins (600 secs)\n"); + checkserv.tinterval = 600; /* 10 min max interval */ } - } - else { + } else { checkserv.tinterval = -1; /* don't change current interval */ } @@ -1669,33 +1840,36 @@ static CheckServersCmd(as) memcpy(&temp, space, sizeof(afs_int32)); if (checkserv.tinterval >= 0) { if (checkserv.tinterval > 0) - printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n", - checkserv.tinterval, temp); + printf + ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n", + checkserv.tinterval, temp); else - printf("The current down server probe interval is %d secs\n", temp); + printf("The current down server probe interval is %d secs\n", + temp); return 0; } if (temp == 0) { printf("All servers are running.\n"); - } - else { - printf("These servers unavailable due to network or server problems: "); - for(j=0; ; j++) { - memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32)); - if (temp == 0) break; + } else { + printf + ("These servers unavailable due to network or server problems: "); + for (j = 0;; j++) { + memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32)); + if (temp == 0) + break; tp = hostutil_GetNameByINet(temp); printf(" %s", tp); } printf(".\n"); - code = 1; /* XXX */ + code = 1; /* XXX */ } return code; } -static MessagesCmd(as) - struct cmd_syndesc *as; +static int +MessagesCmd(struct cmd_syndesc *as) { - afs_int32 code=0; + afs_int32 code = 0; struct ViceIoctl blob; afs_int32 j; afs_int32 temp; @@ -1704,19 +1878,19 @@ static MessagesCmd(as) memset(&gagflags, 0, sizeof(struct gaginfo)); blob.in_size = sizeof(struct gaginfo); - blob.in = (caddr_t) &gagflags; + blob.in = (caddr_t) & gagflags; blob.out_size = MAXSIZE; blob.out = space; memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */ if (show = as->parms[0].items) { - if (!strcasecmp (show->data, "user")) + if (!strcasecmp(show->data, "user")) gagflags.showflags |= GAGUSER; - else if (!strcasecmp (show->data, "console")) + else if (!strcasecmp(show->data, "console")) gagflags.showflags |= GAGCONSOLE; - else if (!strcasecmp (show->data, "all")) + else if (!strcasecmp(show->data, "all")) gagflags.showflags |= GAGCONSOLE | GAGUSER; - else if (!strcasecmp (show->data, "none")) + else if (!strcasecmp(show->data, "none")) /* do nothing */ ; else { fprintf(stderr, @@ -1738,8 +1912,8 @@ static MessagesCmd(as) return 0; } -static CheckVolumesCmd(as) - struct cmd_syndesc *as; +static int +CheckVolumesCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1756,8 +1930,8 @@ static CheckVolumesCmd(as) return 0; } -static SetCacheSizeCmd(as) - struct cmd_syndesc *as; +static int +SetCacheSizeCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -1770,22 +1944,22 @@ static SetCacheSizeCmd(as) if (as->parms[0].items) { code = util_GetInt32(as->parms[0].items->data, &temp); if (code) { - fprintf(stderr, "%s: bad integer specified for cache size.\n", pn); + fprintf(stderr, "%s: bad integer specified for cache size.\n", + pn); return 1; } - } - else + } else temp = 0; - blob.in = (char *) &temp; + blob.in = (char *)&temp; blob.in_size = sizeof(afs_int32); blob.out_size = 0; code = pioctl(0, VIOCSETCACHESIZE, &blob, 1); if (code) { if (errno == EROFS) { - printf("'fs setcache' not allowed on memory cache based cache managers.\n"); - } - else { - Die(errno, (char *) 0); + printf + ("'fs setcache' not allowed on memory cache based cache managers.\n"); + } else { + Die(errno, NULL); } return 1; } @@ -1795,32 +1969,33 @@ static SetCacheSizeCmd(as) } #define MAXGCSIZE 16 -static GetCacheParmsCmd(as) - struct cmd_syndesc *as; +static int +GetCacheParmsCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; afs_int32 parms[MAXGCSIZE]; - memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */ - blob.in = (char *) 0; + memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */ + blob.in = NULL; blob.in_size = 0; blob.out_size = sizeof(parms); - blob.out = (char *) parms; + blob.out = (char *)parms; code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1); if (code) { - Die(errno, (char *) 0); + Die(errno, NULL); return 1; } printf("AFS using %d of the cache's available %d 1K byte blocks.\n", parms[1], parms[0]); if (parms[1] > parms[0]) - printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n"); + printf + ("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n"); return 0; } -static ListCellsCmd(as) - struct cmd_syndesc *as; +static int +ListCellsCmd(struct cmd_syndesc *as) { afs_int32 code; afs_int32 i, j; @@ -1829,10 +2004,10 @@ static ListCellsCmd(as) struct ViceIoctl blob; int resolve; - resolve = !(as->parms[0].items); /* -numeric */ + resolve = !(as->parms[0].items); /* -numeric */ - for(i=0;;i++) { - tp = space; + for (i = 0;; i++) { + tp = space; memcpy(tp, &i, sizeof(afs_int32)); blob.out_size = MAXSIZE; blob.in_size = sizeof(afs_int32); @@ -1840,28 +2015,28 @@ static ListCellsCmd(as) blob.out = space; code = pioctl(0, VIOCGETCELL, &blob, 1); if (code < 0) { - if (errno == EDOM) break; /* done with the list */ + if (errno == EDOM) + break; /* done with the list */ Die(errno, 0); return 1; } tp = space; - printf("Cell %s on hosts", tp+MAXCELLHOSTS*sizeof(afs_int32)); - for(j=0; j < MAXCELLHOSTS; j++) { + printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32)); + for (j = 0; j < MAXCELLHOSTS; j++) { afs_int32 addr; char *name, tbuffer[20]; - memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32)); - if (addr == 0) break; + memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32)); + if (addr == 0) + break; if (resolve) { - name = hostutil_GetNameByINet(addr); - } - else { - addr = ntohl(addr); - sprintf(tbuffer, "%d.%d.%d.%d", - (addr>>24) & 0xff, (addr>>16) & 0xff, - (addr>>8) & 0xff, addr & 0xff); - name = tbuffer; + name = hostutil_GetNameByINet(addr); + } else { + addr = ntohl(addr); + sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, + (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); + name = tbuffer; } printf(" %s", name); } @@ -1870,14 +2045,14 @@ static ListCellsCmd(as) return 0; } -static ListAliasesCmd(as) - struct cmd_syndesc *as; +static int +ListAliasesCmd(struct cmd_syndesc *as) { afs_int32 code, i; char *tp, *aliasName, *realName; struct ViceIoctl blob; - for(i=0;;i++) { + for (i = 0;; i++) { tp = space; memcpy(tp, &i, sizeof(afs_int32)); blob.out_size = MAXSIZE; @@ -1886,7 +2061,8 @@ static ListAliasesCmd(as) blob.out = space; code = pioctl(0, VIOC_GETALIAS, &blob, 1); if (code < 0) { - if (errno == EDOM) break; /* done with the list */ + if (errno == EDOM) + break; /* done with the list */ Die(errno, 0); return 1; } @@ -1899,16 +2075,16 @@ static ListAliasesCmd(as) return 0; } -static NewCellCmd(as) - struct cmd_syndesc *as; +static int +NewCellCmd(struct cmd_syndesc *as) { - afs_int32 code, linkedstate=0, size=0, *lp; + afs_int32 code, linkedstate = 0, size = 0, *lp; struct ViceIoctl blob; struct cmd_item *ti; - char *tp, *cellname=0; + char *tp, *cellname = 0; struct hostent *thp; afs_int32 fsport = 0, vlport = 0; - afs_int32 magic, scount; /* Number of servers to pass in pioctl call */ + afs_int32 magic, scount; /* Number of servers to pass in pioctl call */ /* Yuck! * With the NEWCELL pioctl call, 3.4 clients take an array of @@ -1920,39 +2096,39 @@ static NewCellCmd(as) * and we'll assume a 3.5 client. */ tp = space; - lp = (afs_int32 *)tp; - *lp++ = 0; /* first cell entry */ - *lp = 0x12345678; /* magic */ + lp = (afs_int32 *) tp; + *lp++ = 0; /* first cell entry */ + *lp = 0x12345678; /* magic */ blob.out_size = MAXSIZE; - blob.in_size = sizeof(afs_int32) + sizeof(afs_int32); - blob.in = space; - blob.out = space; + blob.in_size = sizeof(afs_int32) + sizeof(afs_int32); + blob.in = space; + blob.out = space; code = pioctl(0, VIOCGETCELL, &blob, 1); if (code < 0 && errno != EDOM) { - Die(errno, 0); - return 1; + Die(errno, 0); + return 1; } if (code < 1 && errno == EDOM) { - scount = MAXHOSTS; + scount = MAXHOSTS; } else { - tp = space; - cellname = tp + MAXCELLHOSTS*sizeof(afs_int32); - scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS); + tp = space; + cellname = tp + MAXCELLHOSTS * sizeof(afs_int32); + scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS); } /* Now setup and do the NEWCELL pioctl call */ - memset(space, 0, (scount+1) * sizeof(afs_int32)); + memset(space, 0, (scount + 1) * sizeof(afs_int32)); tp = space; - lp = (afs_int32 *)tp; + lp = (afs_int32 *) tp; *lp++ = 0x12345678; tp += sizeof(afs_int32); - for(ti=as->parms[1].items; ti; ti=ti->next) { + for (ti = as->parms[1].items; ti; ti = ti->next) { thp = hostutil_GetHostByName(ti->data); if (!thp) { - fprintf(stderr, "%s: Host %s not found in host table, skipping it.\n", - pn, ti->data); - } - else { + fprintf(stderr, + "%s: Host %s not found in host table, skipping it.\n", pn, + ti->data); + } else { memcpy(tp, thp->h_addr, sizeof(afs_int32)); tp += sizeof(afs_int32); } @@ -1969,27 +2145,32 @@ static NewCellCmd(as) if (as->parms[3].items) { code = util_GetInt32(as->parms[3].items->data, &vlport); if (code) { - fprintf(stderr, "%s: bad integer specified for the fileserver port.\n", pn); + fprintf(stderr, + "%s: bad integer specified for the fileserver port.\n", + pn); return 1; } } if (as->parms[4].items) { code = util_GetInt32(as->parms[4].items->data, &fsport); if (code) { - fprintf(stderr, "%s: bad integer specified for the vldb server port.\n", pn); + fprintf(stderr, + "%s: bad integer specified for the vldb server port.\n", + pn); return 1; } } #endif - tp = (char *)(space + (scount+1) *sizeof(afs_int32)); - lp = (afs_int32 *)tp; + tp = (char *)(space + (scount + 1) * sizeof(afs_int32)); + lp = (afs_int32 *) tp; *lp++ = fsport; *lp++ = vlport; *lp = linkedstate; - strcpy(space + ((scount+4) * sizeof(afs_int32)), as->parms[0].items->data); - size = ((scount+4) * sizeof(afs_int32)) - + strlen(as->parms[0].items->data) - + 1 /* for null */; + strcpy(space + ((scount + 4) * sizeof(afs_int32)), + as->parms[0].items->data); + size = ((scount + 4) * sizeof(afs_int32)) + + strlen(as->parms[0].items->data) + + 1 /* for null */ ; tp = (char *)(space + size); if (linkedstate) { strcpy(tp, cellname); @@ -2006,8 +2187,8 @@ static NewCellCmd(as) return 0; } -static NewAliasCmd(as) - struct cmd_syndesc *as; +static int +NewAliasCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -2030,8 +2211,9 @@ static NewAliasCmd(as) code = pioctl(0, VIOC_NEWALIAS, &blob, 1); if (code < 0) { if (errno == EEXIST) { - fprintf(stderr, "%s: cell name `%s' in use by an existing cell.\n", - pn, aliasName); + fprintf(stderr, + "%s: cell name `%s' in use by an existing cell.\n", pn, + aliasName); } else { Die(errno, 0); } @@ -2040,45 +2222,45 @@ static NewAliasCmd(as) return 0; } -static WhichCellCmd(as) - struct cmd_syndesc *as; -{ - afs_int32 code; - struct cmd_item *ti; - int error = 0; - char cell[MAXCELLCHARS]; - - SetDotDefault(&as->parms[0].items); - for (ti=as->parms[0].items; ti; ti=ti->next) { - code = GetCell(ti->data, cell); - if (code) { - if (errno == ENOENT) - fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data); - else - Die(errno, ti->data); - error = 1; - continue; - } +static int +WhichCellCmd(struct cmd_syndesc *as) +{ + afs_int32 code; + struct cmd_item *ti; + int error = 0; + char cell[MAXCELLCHARS]; + + SetDotDefault(&as->parms[0].items); + for (ti = as->parms[0].items; ti; ti = ti->next) { + code = GetCell(ti->data, cell); + if (code) { + if (errno == ENOENT) + fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data); + else + Die(errno, ti->data); + error = 1; + continue; + } - printf("File %s lives in cell '%s'\n", ti->data, cell); - } - return error; + printf("File %s lives in cell '%s'\n", ti->data, cell); + } + return error; } -static WSCellCmd(as) - struct cmd_syndesc *as; +static int +WSCellCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; blob.in_size = 0; - blob.in = (char *) 0; + blob.in = NULL; blob.out_size = MAXSIZE; blob.out = space; - code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1); + code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1); if (code) { - Die(errno, (char *) 0); + Die(errno, NULL); return 1; } @@ -2095,8 +2277,8 @@ static PrimaryCellCmd(as) } */ -static MonitorCmd(as) - struct cmd_syndesc *as; +static int +MonitorCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -2116,27 +2298,27 @@ static MonitorCmd(as) thp = hostutil_GetHostByName(ti->data); if (!thp) { if (!strcmp(ti->data, "localhost")) { - fprintf(stderr, "localhost not in host table, assuming 127.0.0.1\n"); + fprintf(stderr, + "localhost not in host table, assuming 127.0.0.1\n"); hostAddr = htonl(0x7f000001); - } - else { - fprintf(stderr, "host %s not found in host table.\n", ti->data); + } else { + fprintf(stderr, "host %s not found in host table.\n", + ti->data); return 1; } - } - else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32)); + } else + memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32)); } - } - else { - hostAddr = 0; /* means don't set host */ - setp = 0; /* aren't setting host */ + } else { + hostAddr = 0; /* means don't set host */ + setp = 0; /* aren't setting host */ } /* now do operation */ blob.in_size = sizeof(afs_int32); blob.out_size = sizeof(afs_int32); - blob.in = (char *) &hostAddr; - blob.out = (char *) &hostAddr; + blob.in = (char *)&hostAddr; + blob.out = (char *)&hostAddr; code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1); if (code) { Die(errno, 0); @@ -2144,13 +2326,11 @@ static MonitorCmd(as) } if (setp) { printf("%s: new monitor host set.\n", pn); - } - else { + } else { /* now decode old address */ if (hostAddr == 0xffffffff) { printf("Cache monitoring is currently disabled.\n"); - } - else { + } else { tp = hostutil_GetNameByINet(hostAddr); printf("Using host %s for monitor services.\n", tp); } @@ -2158,8 +2338,8 @@ static MonitorCmd(as) return 0; } -static SysNameCmd(as) - struct cmd_syndesc *as; +static int +SysNameCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -2173,12 +2353,13 @@ static SysNameCmd(as) blob.out_size = MAXSIZE; blob.in_size = sizeof(afs_int32); input += sizeof(afs_int32); - for(; ti; ti=ti->next) { + for (; ti; ti = ti->next) { setp++; blob.in_size += strlen(ti->data) + 1; if (blob.in_size > MAXSIZE) { - fprintf(stderr, "%s: sysname%s too long.\n", pn, setp > 1 ? "s" : ""); - return 1; + fprintf(stderr, "%s: sysname%s too long.\n", pn, + setp > 1 ? "s" : ""); + return 1; } strcpy(input, ti->data); input += strlen(ti->data); @@ -2201,34 +2382,40 @@ static SysNameCmd(as) fprintf(stderr, "No sysname name value was found\n"); return 1; } - printf("Current sysname%s is", setp>1 ? " list" : ""); - for(;setp>0;--setp) { - printf(" \'%s\'", input); - input += strlen(input) + 1; + printf("Current sysname%s is", setp > 1 ? " list" : ""); + for (; setp > 0; --setp) { + printf(" \'%s\'", input); + input += strlen(input) + 1; } printf("\n"); return 0; } -static char *exported_types[] = {"null", "nfs", ""}; -static ExportAfsCmd(as) - struct cmd_syndesc *as; +static char *exported_types[] = { "null", "nfs", "" }; +static int +ExportAfsCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; struct cmd_item *ti; - int export=0, type=0, mode = 0, exp = 0, exportcall, pwsync=0, smounts=0; + int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync = + 0, smounts = 0; ti = as->parms[0].items; - if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */ + if (strcmp(ti->data, "nfs") == 0) + type = 0x71; /* NFS */ else { - fprintf(stderr, "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data); + fprintf(stderr, + "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", + ti->data); return 1; } ti = as->parms[1].items; if (ti) { - if (strcmp(ti->data, "on") == 0) export = 3; - else if (strcmp(ti->data, "off") == 0) export = 2; + if (strcmp(ti->data, "on") == 0) + export = 3; + else if (strcmp(ti->data, "off") == 0) + export = 2; else { fprintf(stderr, "Illegal argument %s\n", ti->data); return 1; @@ -2236,42 +2423,50 @@ static ExportAfsCmd(as) exp = 1; } if (ti = as->parms[2].items) { /* -noconvert */ - if (strcmp(ti->data, "on") == 0) mode = 2; - else if (strcmp(ti->data, "off") == 0) mode = 3; + if (strcmp(ti->data, "on") == 0) + mode = 2; + else if (strcmp(ti->data, "off") == 0) + mode = 3; else { fprintf(stderr, "Illegal argument %s\n", ti->data); return 1; } } if (ti = as->parms[3].items) { /* -uidcheck */ - if (strcmp(ti->data, "on") == 0) pwsync = 3; - else if (strcmp(ti->data, "off") == 0) pwsync = 2; + if (strcmp(ti->data, "on") == 0) + pwsync = 3; + else if (strcmp(ti->data, "off") == 0) + pwsync = 2; else { fprintf(stderr, "Illegal argument %s\n", ti->data); return 1; } } if (ti = as->parms[4].items) { /* -submounts */ - if (strcmp(ti->data, "on") == 0) smounts = 3; - else if (strcmp(ti->data, "off") == 0) smounts = 2; + if (strcmp(ti->data, "on") == 0) + smounts = 3; + else if (strcmp(ti->data, "off") == 0) + smounts = 2; else { fprintf(stderr, "Illegal argument %s\n", ti->data); return 1; } } - exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export; + exportcall = + (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export; type &= ~0x70; /* make the call */ - blob.in = (char *) &exportcall; + blob.in = (char *)&exportcall; blob.in_size = sizeof(afs_int32); - blob.out = (char *) &exportcall; + blob.out = (char *)&exportcall; blob.out_size = sizeof(afs_int32); code = pioctl(0, VIOC_EXPORTAFS, &blob, 1); if (code) { if (errno == ENODEV) { - fprintf(stderr, "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]); - } - else { + fprintf(stderr, + "Sorry, the %s-exporter type is currently not supported on this AFS client\n", + exported_types[type]); + } else { Die(errno, 0); } return 1; @@ -2281,24 +2476,23 @@ static ExportAfsCmd(as) printf("'%s' translator is enabled with the following options:\n", exported_types[type]); printf("\tRunning in %s mode\n", - (exportcall & 2 ? "strict unix" - : "convert owner mode bits to world/other")); + (exportcall & 2 ? "strict unix" : + "convert owner mode bits to world/other")); printf("\tRunning in %s mode\n", - (exportcall & 4 ? "strict 'passwd sync'" - : "no 'passwd sync'")); + (exportcall & 4 ? "strict 'passwd sync'" : + "no 'passwd sync'")); printf("\t%s\n", - (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" - : "Only mounts to /afs allowed")); - } - else { + (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : + "Only mounts to /afs allowed")); + } else { printf("'%s' translator is disabled\n", exported_types[type]); } return 0; } -static GetCellCmd(as) - struct cmd_syndesc *as; +static int +GetCellCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -2310,22 +2504,23 @@ static GetCellCmd(as) } args; int error = 0; - memset(&args, '\0', sizeof args); /* avoid Purify UMR error */ - for(ti=as->parms[0].items; ti; ti=ti->next) { + memset(&args, '\0', sizeof args); /* avoid Purify UMR error */ + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per cell */ blob.out_size = sizeof(args); - blob.out = (caddr_t) &args; + blob.out = (caddr_t) & args; code = GetCellName(ti->data, &info); if (code) { error = 1; continue; } - blob.in_size = 1+strlen(info.name); + blob.in_size = 1 + strlen(info.name); blob.in = info.name; code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1); if (code) { if (errno == ENOENT) - fprintf(stderr, "%s: the cell named '%s' does not exist\n", pn, info.name); + fprintf(stderr, "%s: the cell named '%s' does not exist\n", + pn, info.name); else Die(errno, info.name); error = 1; @@ -2333,18 +2528,22 @@ static GetCellCmd(as) } printf("Cell %s status: ", info.name); #ifdef notdef - if (args.stat & 1) printf("primary "); + if (args.stat & 1) + printf("primary "); #endif - if (args.stat & 2) printf("no setuid allowed"); - else printf("setuid allowed"); - if (args.stat & 4) printf(", using old VLDB"); + if (args.stat & 2) + printf("no setuid allowed"); + else + printf("setuid allowed"); + if (args.stat & 4) + printf(", using old VLDB"); printf("\n"); } return error; } -static SetCellCmd(as) - struct cmd_syndesc *as; +static int +SetCellCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; @@ -2367,10 +2566,11 @@ static SetCellCmd(as) args.stat = 0; args.junk = 0; - if (! as->parms[1].items) args.stat |= 2; /* default to -nosuid */ + if (!as->parms[1].items) + args.stat |= 2; /* default to -nosuid */ /* set stat for all listed cells */ - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per cell */ code = GetCellName(ti->data, &info); if (code) { @@ -2379,7 +2579,7 @@ static SetCellCmd(as) } strcpy(args.cname, info.name); blob.in_size = sizeof(args); - blob.in = (caddr_t) &args; + blob.in = (caddr_t) & args; blob.out_size = 0; blob.out = (caddr_t) 0; code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1); @@ -2391,16 +2591,16 @@ static SetCellCmd(as) return error; } -static GetCellName(cellName, info) - char *cellName; - struct afsconf_cell *info; +static int +GetCellName(char *cellName, struct afsconf_cell *info) { struct afsconf_dir *tdir; int code; tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH); if (!tdir) { - fprintf(stderr, "Could not process files in configuration directory (%s).\n", + fprintf(stderr, + "Could not process files in configuration directory (%s).\n", AFSDIR_CLIENT_ETC_DIRPATH); return -1; } @@ -2416,9 +2616,8 @@ static GetCellName(cellName, info) } -static VLDBInit(noAuthFlag, info) - int noAuthFlag; - struct afsconf_cell *info; +static int +VLDBInit(int noAuthFlag, struct afsconf_cell *info) { afs_int32 code; struct ktc_principal sname; @@ -2435,29 +2634,31 @@ static VLDBInit(noAuthFlag, info) } rxInitDone = 1; rx_SetRxDeadTime(50); - if (!noAuthFlag) { /* we don't need tickets for null */ + if (!noAuthFlag) { /* we don't need tickets for null */ strcpy(sname.cell, info->name); sname.instance[0] = 0; strcpy(sname.name, "afs"); - code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0); + code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL); if (code) { - fprintf(stderr, "%s: Could not get afs tokens, running unauthenticated.\n", pn); + fprintf(stderr, + "%s: Could not get afs tokens, running unauthenticated.\n", + pn); scIndex = 0; - } - else { + } else { /* got a ticket */ - if (ttoken.kvno >= 0 && ttoken.kvno <= 255) scIndex = 2; /* kerberos */ + if (ttoken.kvno >= 0 && ttoken.kvno <= 255) + scIndex = 2; /* kerberos */ else { fprintf(stderr, "%s: funny kvno (%d) in ticket, proceeding\n", pn, ttoken.kvno); scIndex = 2; } } - } - else scIndex = 0; /* don't authenticate */ + } else + scIndex = 0; /* don't authenticate */ switch (scIndex) { case 0: - sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject(); + sc = rxnull_NewClientSecurityObject(); break; case 1: @@ -2470,15 +2671,16 @@ static VLDBInit(noAuthFlag, info) break; } if (info->numServers > VLDB_MAXSERVERS) { - fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", - pn, info->numServers, VLDB_MAXSERVERS); + fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", pn, + info->numServers, VLDB_MAXSERVERS); exit(1); } memset(serverconns, 0, sizeof(serverconns)); - for (i = 0;inumServers;i++) - serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr, - info->hostAddr[i].sin_port, USER_SERVICE_ID, - sc, scIndex); + for (i = 0; i < info->numServers; i++) + serverconns[i] = + rx_NewConnection(info->hostAddr[i].sin_addr.s_addr, + info->hostAddr[i].sin_port, USER_SERVICE_ID, sc, + scIndex); code = ubik_ClientInit(serverconns, &uclient); @@ -2507,7 +2709,8 @@ static int debug = 0; * 0 on success, * errno value if error and no error message printed */ -static pokeServers() +static int +pokeServers(void) { int code; @@ -2516,7 +2719,7 @@ static pokeServers() struct setspref *ssp; ssp = (struct setspref *)gblob.in; if (!(ssp->flags & DBservers)) { - gblob.in = (void *) &(ssp->servers[0]); + gblob.in = (void *)&(ssp->servers[0]); gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp; code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1); return code ? errno : 0; @@ -2534,11 +2737,10 @@ static pokeServers() * 0 on success, * errno value if error and no error message printed */ -static addServer(name, rank) - char *name; - afs_int32 rank; +static int +addServer(char *name, afs_int32 rank) { - int t,code; + int t, code; struct setspref *ssp; struct spref *sp; struct hostent *thostent; @@ -2547,7 +2749,7 @@ static addServer(name, rank) #ifndef MAXUSHORT #ifdef MAXSHORT -#define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */ +#define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */ #else #define MAXUSHORT ((unsigned short) ~0) #endif @@ -2564,27 +2766,29 @@ static addServer(name, rank) for (t = 0; thostent->h_addr_list[t]; t++) { if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) { code = pokeServers(); - if (code) error = code; + if (code) + error = code; ssp->num_servers = 0; } - sp = (struct spref *) (gblob.in + gblob.in_size); - memcpy(&(sp->server.s_addr), thostent->h_addr_list[t], sizeof(afs_uint32)); + sp = (struct spref *)(gblob.in + gblob.in_size); + memcpy(&(sp->server.s_addr), thostent->h_addr_list[t], + sizeof(afs_uint32)); sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank); gblob.in_size += sizeof(struct spref); ssp->num_servers++; if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n", - name,sp->rank,sp->server.s_addr); + name, sp->rank, sp->server.s_addr); } return error; } -static SetPrefCmd(as) - struct cmd_syndesc *as; +static int +SetPrefCmd(struct cmd_syndesc *as) { FILE *infd; afs_int32 code; @@ -2592,13 +2796,13 @@ static SetPrefCmd(as) char name[80]; afs_int32 rank; struct setspref *ssp; - int error = 0; /* -1 means error message printed, - * >0 means errno value for unprinted message */ + int error = 0; /* -1 means error message printed, + * >0 means errno value for unprinted message */ ssp = (struct setspref *)space; ssp->flags = 0; ssp->num_servers = 0; - gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp; + gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp; gblob.in = space; gblob.out = space; gblob.out_size = MAXSIZE; @@ -2609,62 +2813,67 @@ static SetPrefCmd(as) return 1; } - ti = as->parms[2].items; /* -file */ + ti = as->parms[2].items; /* -file */ if (ti) { - if (debug) fprintf(stderr, "opening file %s\n",ti->data); - if (!(infd = fopen(ti->data,"r"))) { + if (debug) + fprintf(stderr, "opening file %s\n", ti->data); + if (!(infd = fopen(ti->data, "r"))) { perror(ti->data); error = -1; - } - else { + } else { while (fscanf(infd, "%79s%ld", name, &rank) != EOF) { - code = addServer(name, (unsigned short) rank); - if (code) error = code; + code = addServer(name, (unsigned short)rank); + if (code) + error = code; } } } - ti = as->parms[3].items; /* -stdin */ + ti = as->parms[3].items; /* -stdin */ if (ti) { while (scanf("%79s%ld", name, &rank) != EOF) { - code = addServer(name, (unsigned short) rank); - if (code) error = code; + code = addServer(name, (unsigned short)rank); + if (code) + error = code; } } - for (ti = as->parms[0].items;ti;ti=ti->next) { /* list of servers, ranks */ + for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */ if (ti) { if (!ti->next) { break; } - code = addServer(ti->data, (unsigned short) atol(ti->next->data)); - if (code) error = code; + code = addServer(ti->data, (unsigned short)atol(ti->next->data)); + if (code) + error = code; if (debug) printf("set fs prefs %s %s\n", ti->data, ti->next->data); - ti=ti->next; + ti = ti->next; } } code = pokeServers(); - if (code) error = code; + if (code) + error = code; if (debug) - printf("now working on vlservers, code=%d\n",code); + printf("now working on vlservers, code=%d\n", code); ssp = (struct setspref *)space; ssp->flags = DBservers; ssp->num_servers = 0; - gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp; + gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp; gblob.in = space; - for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */ + for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */ if (ti) { if (!ti->next) { break; } - code = addServer(ti->data, (unsigned short) atol(ti->next->data)); - if (code) error = code; + code = addServer(ti->data, (unsigned short)atol(ti->next->data)); + if (code) + error = code; if (debug) printf("set vl prefs %s %s\n", ti->data, ti->next->data); - ti=ti->next; + ti = ti->next; } } @@ -2672,7 +2881,8 @@ static SetPrefCmd(as) if (debug) printf("now poking vlservers\n"); code = pokeServers(); - if (code) error = code; + if (code) + error = code; } if (error > 0) @@ -2683,14 +2893,14 @@ static SetPrefCmd(as) -static GetPrefCmd(as) - struct cmd_syndesc *as; +static int +GetPrefCmd(struct cmd_syndesc *as) { afs_int32 code; struct cmd_item *ti; char *name, tbuffer[20]; - afs_int32 rank,addr; - FILE * outfd; + afs_int32 rank, addr; + FILE *outfd; int resolve; int vlservers = 0; struct ViceIoctl blob; @@ -2698,31 +2908,33 @@ static GetPrefCmd(as) struct sprefinfo *out; int i; - ti = as->parms[0].items; /* -file */ + ti = as->parms[0].items; /* -file */ if (ti) { - if (debug) fprintf(stderr, "opening file %s\n",ti->data); - if (!(outfd = freopen(ti->data,"w",stdout))) { + if (debug) + fprintf(stderr, "opening file %s\n", ti->data); + if (!(outfd = freopen(ti->data, "w", stdout))) { perror(ti->data); return 1; } } - ti = as->parms[1].items; /* -numeric */ + ti = as->parms[1].items; /* -numeric */ resolve = !(ti); - ti = as->parms[2].items; /* -vlservers */ + ti = as->parms[2].items; /* -vlservers */ vlservers |= (ti ? DBservers : 0); - /* ti = as->parms[3].items; -cell */ + /* ti = as->parms[3].items; -cell */ in = (struct sprefrequest *)space; in->offset = 0; do { - blob.in_size=sizeof(struct sprefrequest); + blob.in_size = sizeof(struct sprefrequest); blob.in = (char *)in; blob.out = space; blob.out_size = MAXSIZE; - in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct spref); + in->num_servers = + (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref); in->flags = vlservers; code = pioctl(0, VIOC_GETSPREFS, &blob, 1); @@ -2731,20 +2943,18 @@ static GetPrefCmd(as) return 1; } - out = (struct sprefinfo *) blob.out; + out = (struct sprefinfo *)blob.out; - for (i=0;inum_servers;i++) { + for (i = 0; i < out->num_servers; i++) { if (resolve) { name = hostutil_GetNameByINet(out->servers[i].server.s_addr); - } - else { + } else { addr = ntohl(out->servers[i].server.s_addr); - sprintf(tbuffer, "%d.%d.%d.%d", - (addr>>24) & 0xff, (addr>>16) & 0xff, - (addr>>8) & 0xff, addr & 0xff); - name=tbuffer; + sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, + (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); + name = tbuffer; } - printf("%-50s %5u\n",name,out->servers[i].rank); + printf("%-50s %5u\n", name, out->servers[i].rank); } in->offset = out->next_offset; @@ -2753,10 +2963,10 @@ static GetPrefCmd(as) return 0; } -static StoreBehindCmd(as) - struct cmd_syndesc *as; +static int +StoreBehindCmd(struct cmd_syndesc *as) { - afs_int32 code=0; + afs_int32 code = 0; struct ViceIoctl blob; struct cmd_item *ti; struct sbstruct tsb, tsb2; @@ -2766,44 +2976,45 @@ static StoreBehindCmd(as) int error = 0; tsb.sb_thisfile = -1; - ti=as->parms[0].items; /* -kbytes */ + ti = as->parms[0].items; /* -kbytes */ if (ti) { if (!as->parms[1].items) { - fprintf(stderr, "%s: you must specify -files with -kbytes.\n", pn); + fprintf(stderr, "%s: you must specify -files with -kbytes.\n", + pn); return 1; } - tsb.sb_thisfile = strtol(ti->data,&t,10) * 1024; - if ((tsb.sb_thisfile < 0) || (t != ti->data+strlen(ti->data))) { - fprintf(stderr, "%s: %s must be 0 or a positive number.\n", - pn, ti->data); + tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024; + if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) { + fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn, + ti->data); return 1; } } - allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */ - ti=as->parms[2].items; /* -allfiles */ + allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */ + ti = as->parms[2].items; /* -allfiles */ if (ti) { - allfiles = strtol(ti->data,&t,10) * 1024; - if ((allfiles < 0) || (t != ti->data+strlen(ti->data))) { - fprintf(stderr, "%s: %s must be 0 or a positive number.\n", - pn, ti->data); + allfiles = strtol(ti->data, &t, 10) * 1024; + if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) { + fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn, + ti->data); return 1; } } /* -verbose or -file only or no options */ - if (as->parms[3].items || - (as->parms[1].items && !as->parms[0].items) || - (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items)) - verbose = 1; + if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items) + || (!as->parms[0].items && !as->parms[1].items + && !as->parms[2].items)) + verbose = 1; - blob.in = (char *)&tsb; + blob.in = (char *)&tsb; blob.out = (char *)&tsb2; blob.in_size = blob.out_size = sizeof(struct sbstruct); memset(&tsb2, 0, sizeof(tsb2)); /* once per -file */ - for (ti=as->parms[1].items; ti; ti=ti->next) { + for (ti = as->parms[1].items; ti; ti = ti->next) { /* Do this solely to see if the file is there */ code = pioctl(ti->data, VIOCWHEREIS, &blob, 1); if (code) { @@ -2823,11 +3034,10 @@ static StoreBehindCmd(as) if (tsb2.sb_thisfile == -1) { fprintf(stdout, "Will store %s according to default.\n", ti->data); - } - else { + } else { fprintf(stdout, "Will store up to %d kbytes of %s asynchronously.\n", - (tsb2.sb_thisfile/1024), ti->data); + (tsb2.sb_thisfile / 1024), ti->data); } } } @@ -2839,7 +3049,7 @@ static StoreBehindCmd(as) tsb.sb_default = allfiles; code = pioctl(0, VIOC_STORBEHIND, &blob, 1); if (code) { - Die(errno, ((allfiles == -1)?0:"-allfiles")); + Die(errno, ((allfiles == -1) ? 0 : "-allfiles")); error = 1; } } @@ -2847,72 +3057,72 @@ static StoreBehindCmd(as) /* Having no arguments also reports the default store asynchrony */ if (verbose && (blob.out_size == sizeof(tsb2))) { fprintf(stdout, "Default store asynchrony is %d kbytes.\n", - (tsb2.sb_default/1024)); + (tsb2.sb_default / 1024)); } return error; } -static afs_int32 SetCryptCmd(as) - struct cmd_syndesc *as; +static afs_int32 +SetCryptCmd(struct cmd_syndesc *as) { afs_int32 code = 0, flag; struct ViceIoctl blob; char *tp; - + tp = as->parms[0].items->data; if (strcmp(tp, "on") == 0) - flag = 1; + flag = 1; else if (strcmp(tp, "off") == 0) - flag = 0; + flag = 0; else { - fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp); - return EINVAL; + fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp); + return EINVAL; } - blob.in = (char *) &flag; + blob.in = (char *)&flag; blob.in_size = sizeof(flag); blob.out_size = 0; code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1); if (code) - Die(errno, (char *) 0); + Die(errno, NULL); return 0; } -static afs_int32 GetCryptCmd(as) - struct cmd_syndesc *as; +static afs_int32 +GetCryptCmd(struct cmd_syndesc *as) { afs_int32 code = 0, flag; struct ViceIoctl blob; char *tp; - - blob.in = (char *) 0; + + blob.in = NULL; blob.in_size = 0; blob.out_size = sizeof(flag); blob.out = space; code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1); - if (code) Die(errno, (char *) 0); + if (code) + Die(errno, NULL); else { - tp = space; - memcpy(&flag, tp, sizeof(afs_int32)); - printf("Security level is currently "); - if (flag == 1) - printf("crypt (data security).\n"); - else - printf("clear.\n"); + tp = space; + memcpy(&flag, tp, sizeof(afs_int32)); + printf("Security level is currently "); + if (flag == 1) + printf("crypt (data security).\n"); + else + printf("clear.\n"); } return 0; } #include "AFS_component_version_number.c" -main(argc, argv) - int argc; - char **argv; +int +main(int argc, char **argv) { afs_int32 code; struct cmd_syndesc *ts; @@ -2933,22 +3143,31 @@ main(argc, argv) #endif /* try to find volume location information */ - ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0, "get client network interface addresses"); + ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0, + "get client network interface addresses"); cmd_CreateAlias(ts, "gc"); - ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0, "set client network interface addresses"); - cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "client network interfaces"); + ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0, + "set client network interface addresses"); + cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, + "client network interfaces"); cmd_CreateAlias(ts, "sc"); - ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks"); - cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks"); - cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks"); - cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file"); + ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, + "set server ranks"); + cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, + "fileserver names and ranks"); + cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, + "VL server names and ranks"); + cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, + "input from named file"); cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin"); cmd_CreateAlias(ts, "sp"); - ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks"); - cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file"); + ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, + "get server ranks"); + cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, + "output to named file"); cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only"); cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers"); /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */ @@ -2958,26 +3177,35 @@ main(argc, argv) cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory"); cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries"); cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list"); - cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights"); + cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, + "apply to negative rights"); parm_setacl_id = ts->nParms; - cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)"); - cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)"); + cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, + "initial directory acl (DFS only)"); + cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, + "initial file acl (DFS only)"); cmd_CreateAlias(ts, "sa"); - ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list"); + ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, + "list access control list"); cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); parm_listacl_id = ts->nParms; cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl"); cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl"); cmd_CreateAlias(ts, "la"); - ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list"); + ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, + "clean up access control list"); cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list"); - cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)"); - cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)"); - cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list"); + ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, + "copy access control list"); + cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, + "source directory (or DFS file)"); + cmd_AddParm(ts, "-todir", CMD_LIST, 0, + "destination directory (or DFS file)"); + cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, + "first clear dest access list"); parm_copyacl_id = ts->nParms; cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl"); cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl"); @@ -2986,23 +3214,29 @@ main(argc, argv) ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache"); cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0, "flush mount symlink from cache"); + ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0, + "flush mount symlink from cache"); cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status"); cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units"); + cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, + "disk space quota in 1K units"); #ifdef notdef - cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed"); + cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, + "disk space guaranteed"); cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day"); #endif - cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message"); + cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, + "offline message"); cmd_CreateAlias(ts, "sv"); - ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages"); - cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]"); + ts = cmd_CreateSyntax("messages", MessagesCmd, 0, + "control Cache Manager messages"); + cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, + "[user|console|all|none]"); - ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status"); + ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status"); cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); cmd_CreateAlias(ts, "lv"); cmd_CreateAlias(ts, "listvol"); @@ -3011,7 +3245,8 @@ main(argc, argv) cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); cmd_CreateAlias(ts, "lq"); - ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage"); + ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, + "show server disk space usage"); cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); cmd_CreateAlias(ts, "df"); @@ -3026,7 +3261,8 @@ main(argc, argv) cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name"); cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume"); - cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB"); + cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, + "don't check name with VLDB"); /* @@ -3039,28 +3275,38 @@ defect 3069 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point"); cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory"); - ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers"); + ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, + "check local cell's servers"); cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check"); cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells"); - cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check"); - cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes"); + cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, + "just list, don't check"); + cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL, + "seconds between probes"); - ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings"); + ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, 0, + "check volumeID/name mappings"); cmd_CreateAlias(ts, "checkbackups"); - ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size"); - cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)"); + ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, + "set cache size"); + cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, + "size in 1K byte blocks (0 => reset)"); cmd_CreateAlias(ts, "cachesize"); - cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value"); + cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, + "reset size back to boot value"); - ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info"); + ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, + "get cache usage info"); - ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells"); + ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, + "list configured cells"); cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only"); - ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, 0, "list configured cell aliases"); + ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, 0, + "list configured cell aliases"); ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota"); cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path"); @@ -3073,9 +3319,11 @@ defect 3069 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell"); cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name"); cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers"); - cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name"); + cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, + "linked cell name"); - ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0, "configure new cell alias"); + ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0, + "configure new cell alias"); cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name"); cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell"); @@ -3086,8 +3334,10 @@ defect 3069 * supported in the cache manager. It is not a way to run two servers at the * same host, since the cache manager cannot properly distinguish those two hosts. */ - cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port"); - cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port"); + cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, + "cell's fileserver port"); + cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, + "cell's vldb server port"); #endif ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell"); @@ -3103,8 +3353,9 @@ defect 3069 */ /* set cache monitor host address */ - ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *) CMD_HIDDEN); - cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'"); + ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *)CMD_HIDDEN); + cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, + "host name or 'off'"); cmd_CreateAlias(ts, "mariner"); ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status"); @@ -3113,67 +3364,74 @@ defect 3069 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status"); cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name"); cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs"); - cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs"); + cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, + "disallow setuid programs"); - ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume"); + ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, + "flush all data in volume"); cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value"); + ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, + "get/set sysname (i.e. @sys) value"); cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname"); - ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS"); + ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, + "enable/disable translators to AFS"); cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name"); - cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator (on | off)"); - cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode (on | off)"); - cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode (on | off)"); - cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. (on | off)"); + cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, + "start/stop translator (on | off)"); + cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, + "convert from afs to unix mode (on | off)"); + cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, + "run on strict 'uid check' mode (on | off)"); + cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, + "allow nfs mounts to subdirs of /afs/.. (on | off)"); ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0, "store to server after file close"); - cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names"); + cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, + "asynchrony for specified names"); cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames"); - cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)"); + cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, + "new default (KB)"); cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status"); cmd_CreateAlias(ts, "sb"); - ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag"); + ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, + "set cache manager encryption flag"); cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off"); - ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "set cache manager encryption flag"); + ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, + "set cache manager encryption flag"); ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0, "Manage per process RX statistics"); - cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, - "Enable RX stats"); - cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, - "Disable RX stats"); - cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, - "Clear RX stats"); + cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats"); + cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats"); + cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats"); ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0, "Manage per peer RX statistics"); - cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, - "Enable RX stats"); - cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, - "Disable RX stats"); - cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, - "Clear RX stats"); + cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats"); + cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats"); + cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats"); code = cmd_Dispatch(argc, argv); - if (rxInitDone) rx_Finalize(); + if (rxInitDone) + rx_Finalize(); return code; } -static void Die(errnum, filename) - int errnum; - char *filename; +static void +Die(int errnum, char *filename) { switch (errnum) { case EINVAL: if (filename) - fprintf(stderr, "%s: Invalid argument; it is possible that %s is not in AFS.\n", + fprintf(stderr, + "%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename); else fprintf(stderr, "%s: Invalid argument.\n", pn); @@ -3185,15 +3443,18 @@ static void Die(errnum, filename) fprintf(stderr, "%s: no such file returned\n", pn); break; case EROFS: - fprintf(stderr, "%s: You can not change a backup or readonly volume\n", pn); + fprintf(stderr, + "%s: You can not change a backup or readonly volume\n", pn); break; case EACCES: case EPERM: if (filename) - fprintf(stderr, "%s: You don't have the required access rights on '%s'\n", + fprintf(stderr, + "%s: You don't have the required access rights on '%s'\n", pn, filename); else - fprintf(stderr, "%s: You do not have the required rights to do this operation\n", + fprintf(stderr, + "%s: You do not have the required rights to do this operation\n", pn); break; default: @@ -3208,8 +3469,7 @@ static void Die(errnum, filename) /* get clients interface addresses */ static int -GetClientAddrsCmd(as) - struct cmd_syndesc *as; +GetClientAddrsCmd(struct cmd_syndesc *as) { afs_int32 code; struct cmd_item *ti; @@ -3221,14 +3481,14 @@ GetClientAddrsCmd(as) in = (struct sprefrequest *)space; in->offset = 0; - do - { - blob.in_size=sizeof(struct sprefrequest); + do { + blob.in_size = sizeof(struct sprefrequest); blob.in = (char *)in; blob.out = space; blob.out_size = MAXSIZE; - in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct spref); + in->num_servers = + (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref); /* returns addr in network byte order */ code = pioctl(0, VIOC_GETCPREFS, &blob, 1); if (code) { @@ -3238,15 +3498,14 @@ GetClientAddrsCmd(as) { int i; - out = (struct sprefinfo *) blob.out; - for (i=0; i < out->num_servers; i++) { + out = (struct sprefinfo *)blob.out; + for (i = 0; i < out->num_servers; i++) { afs_int32 addr; char tbuffer[32]; addr = ntohl(out->servers[i].server.s_addr); - sprintf(tbuffer, "%d.%d.%d.%d", - (addr>>24) & 0xff, (addr>>16) & 0xff, - (addr>>8) & 0xff, addr & 0xff); - printf ("%-50s\n", tbuffer); + sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, + (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); + printf("%-50s\n", tbuffer); } in->offset = out->next_offset; } @@ -3256,8 +3515,7 @@ GetClientAddrsCmd(as) } static int -SetClientAddrsCmd(as) - struct cmd_syndesc *as; +SetClientAddrsCmd(struct cmd_syndesc *as) { afs_int32 code, addr; struct cmd_item *ti; @@ -3265,8 +3523,8 @@ SetClientAddrsCmd(as) struct ViceIoctl blob; struct setspref *ssp; int sizeUsed = 0, i, flag; - afs_int32 existingAddr[1024]; /* existing addresses on this host */ - int existNu; + afs_int32 existingAddr[1024]; /* existing addresses on this host */ + int existNu; int error = 0; ssp = (struct setspref *)space; @@ -3281,29 +3539,30 @@ SetClientAddrsCmd(as) } /* extract all existing interface addresses */ - existNu = rx_getAllAddr(existingAddr,1024); + existNu = rx_getAllAddr(existingAddr, 1024); if (existNu < 0) return 1; - sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */ - for (ti = as->parms[0].items;ti;ti=ti->next) { + sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */ + for (ti = as->parms[0].items; ti; ti = ti->next) { if (sizeUsed >= sizeof(space)) { fprintf(stderr, "No more space\n"); return 1; } - addr = extractAddr(ti->data, 20); /* network order */ + addr = extractAddr(ti->data, 20); /* network order */ if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) { - fprintf(stderr, "Error in specifying address: %s..ignoring\n", ti->data); + fprintf(stderr, "Error in specifying address: %s..ignoring\n", + ti->data); error = 1; continue; } /* see if it is an address that really exists */ - for (flag = 0, i=0; i < existNu; i++) + for (flag = 0, i = 0; i < existNu; i++) if (existingAddr[i] == addr) { flag = 1; break; } - if (!flag) { /* this is an nonexistent address */ + if (!flag) { /* this is an nonexistent address */ fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr); error = 1; continue; @@ -3320,7 +3579,7 @@ SetClientAddrsCmd(as) } blob.in_size = sizeUsed - sizeof(struct spref); - code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */ + code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */ if (code) { Die(errno, 0); error = 1; @@ -3330,33 +3589,31 @@ SetClientAddrsCmd(as) } static int -FlushMountCmd(as) - struct cmd_syndesc *as; +FlushMountCmd(struct cmd_syndesc *as) { afs_int32 code; struct ViceIoctl blob; struct cmd_item *ti; - char orig_name[1024]; /*Original name, may be modified*/ - char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/ - char parent_dir[1024]; /*Parent directory of true name*/ - char *last_component; /*Last component of true name*/ - struct stat statbuff; /*Buffer for status info*/ - int link_chars_read; /*Num chars read in readlink()*/ - int thru_symlink; /*Did we get to a mount point via a symlink?*/ + char orig_name[1024]; /*Original name, may be modified */ + char true_name[1024]; /*``True'' dirname (e.g., symlink target) */ + char parent_dir[1024]; /*Parent directory of true name */ + char *last_component; /*Last component of true name */ + struct stat statbuff; /*Buffer for status info */ + int link_chars_read; /*Num chars read in readlink() */ + int thru_symlink; /*Did we get to a mount point via a symlink? */ int error = 0; - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ thru_symlink = 0; - sprintf(orig_name, "%s%s", - (ti->data[0] == '/') ? "" : "./", + sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./", ti->data); if (lstat(orig_name, &statbuff) < 0) { /* if lstat fails, we should still try the pioctl, since it - may work (for example, lstat will fail, but pioctl will - work if the volume of offline (returning ENODEV). */ - statbuff.st_mode = S_IFDIR; /* lie like pros */ + * may work (for example, lstat will fail, but pioctl will + * work if the volume of offline (returning ENODEV). */ + statbuff.st_mode = S_IFDIR; /* lie like pros */ } /* @@ -3370,8 +3627,9 @@ FlushMountCmd(as) */ link_chars_read = readlink(orig_name, true_name, 1024); if (link_chars_read <= 0) { - fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n", - pn, orig_name); + fprintf(stderr, + "%s: Can't read target name for '%s' symbolic link!\n", + pn, orig_name); error = 1; continue; } @@ -3388,18 +3646,17 @@ FlushMountCmd(as) * name (we know there is one) and splice in the symlink value. */ if (true_name[0] != '/') { - last_component = (char *) strrchr(orig_name, '/'); + last_component = (char *)strrchr(orig_name, '/'); strcpy(++last_component, true_name); strcpy(true_name, orig_name); } - } - else + } else strcpy(true_name, orig_name); /* * Find rightmost slash, if any. */ - last_component = (char *) strrchr(true_name, '/'); + last_component = (char *)strrchr(true_name, '/'); if (last_component) { /* * Found it. Designate everything before it as the parent directory, @@ -3407,9 +3664,8 @@ FlushMountCmd(as) */ strncpy(parent_dir, true_name, last_component - true_name); parent_dir[last_component - true_name] = 0; - last_component++; /*Skip the slash*/ - } - else { + last_component++; /*Skip the slash */ + } else { /* * No slash appears in the given file name. Set parent_dir to the current * directory, and the last component as the given name. @@ -3418,15 +3674,19 @@ FlushMountCmd(as) last_component = true_name; } - if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) { - fprintf(stderr, "%s: you may not use '.' or '..' as the last component\n", pn); - fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n", pn); + if (strcmp(last_component, ".") == 0 + || strcmp(last_component, "..") == 0) { + fprintf(stderr, + "%s: you may not use '.' or '..' as the last component\n", + pn); + fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n", + pn); error = 1; continue; } blob.in = last_component; - blob.in_size = strlen(last_component)+1; + blob.in_size = strlen(last_component) + 1; blob.out_size = 0; memset(space, 0, MAXSIZE); @@ -3434,10 +3694,8 @@ FlushMountCmd(as) if (code != 0) { if (errno == EINVAL) { - fprintf(stderr, "'%s' is not a mount point.\n", - ti->data); - } - else { + fprintf(stderr, "'%s' is not a mount point.\n", ti->data); + } else { Die(errno, (ti->data ? ti->data : parent_dir)); } error = 1; @@ -3447,21 +3705,20 @@ FlushMountCmd(as) } static int -RxStatProcCmd(as) - struct cmd_syndesc *as; +RxStatProcCmd(struct cmd_syndesc *as) { afs_int32 code; afs_int32 flags = 0; struct ViceIoctl blob; struct cmd_item *ti; - if (as->parms[0].items) { /* -enable*/ + if (as->parms[0].items) { /* -enable */ flags |= AFSCALL_RXSTATS_ENABLE; } - if (as->parms[1].items) { /* -disable*/ + if (as->parms[1].items) { /* -disable */ flags |= AFSCALL_RXSTATS_DISABLE; } - if (as->parms[2].items) { /* -clear*/ + if (as->parms[2].items) { /* -clear */ flags |= AFSCALL_RXSTATS_CLEAR; } if (flags == 0) { @@ -3483,21 +3740,20 @@ RxStatProcCmd(as) } static int -RxStatPeerCmd(as) - struct cmd_syndesc *as; +RxStatPeerCmd(struct cmd_syndesc *as) { afs_int32 code; afs_int32 flags = 0; struct ViceIoctl blob; struct cmd_item *ti; - if (as->parms[0].items) { /* -enable*/ + if (as->parms[0].items) { /* -enable */ flags |= AFSCALL_RXSTATS_ENABLE; } - if (as->parms[1].items) { /* -disable*/ + if (as->parms[1].items) { /* -disable */ flags |= AFSCALL_RXSTATS_DISABLE; } - if (as->parms[2].items) { /* -clear*/ + if (as->parms[2].items) { /* -clear */ flags |= AFSCALL_RXSTATS_CLEAR; } if (flags == 0) { diff --git a/src/venus/fstrace.c b/src/venus/fstrace.c index 38842176e..926ed14c1 100644 --- a/src/venus/fstrace.c +++ b/src/venus/fstrace.c @@ -13,7 +13,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/fstrace.c,v 1.8 2003/04/13 19:32:24 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/fstrace.c,v 1.16 2003/09/24 19:26:54 shadow Exp $"); #include #include @@ -25,37 +26,46 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/fstrace.c,v 1.8 2003/04/13 19:32: #include #undef abs #include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include #include #include -#if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV) +#if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) /* For SGI 6.2, this is changed to 1 if it's a 32 bit kernel. */ int afs_icl_sizeofLong = 2; #else int afs_icl_sizeofLong = 1; #endif -#ifdef AFS_SGI61_ENV +#if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) int afs_64bit_kernel = 1; /* Default for 6.2+, and always for 6.1 */ extern int afs_icl_sizeofLong; /* Used in ICL_SIZEHACK() */ #ifdef AFS_SGI62_ENV #include /* If _SC_KERN_POINTERS not in sysconf, then we can assume a 32 bit abi. */ -void set_kernel_sizeof_long(void) +void +set_kernel_sizeof_long(void) { int retval; - - + + retval = sysconf(_SC_KERN_POINTERS); if (retval == 64) { afs_64bit_kernel = 1; afs_icl_sizeofLong = 2; - } - else { + } else { afs_64bit_kernel = 0; afs_icl_sizeofLong = 1; } @@ -78,14 +88,14 @@ struct logInfo { char dumpFileName[256] = ""; RegisterIclDumpFileName(name) -char *name; + char *name; { - (void) sprintf(dumpFileName, "icl.%.250s", name); + (void)sprintf(dumpFileName, "icl.%.250s", name); } /* define globals to use for bulk info */ -afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *)0; -afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *)0; +afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *) 0; +afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *) 0; struct afs_icl_set *icl_allSets = 0; @@ -94,9 +104,10 @@ char *name; /* given a type and an address, get the size of the thing * in words. */ -static icl_GetSize(type, addr) - afs_int32 type; - char *addr; +static +icl_GetSize(type, addr) + afs_int32 type; + char *addr; { int rsize; int tsize; @@ -111,12 +122,13 @@ static icl_GetSize(type, addr) * by typesp. Also watch for prematurely running out of parameters * before the string is gone. */ -#ifdef AFS_SGI61_ENV -static int CheckTypes(bufferp, typesp, typeCount, outMsgBuffer) - char *bufferp; - int *typesp; - int typeCount; - char *outMsgBuffer; +#if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) +static int +CheckTypes(bufferp, typesp, typeCount, outMsgBuffer) + char *bufferp; + int *typesp; + int typeCount; + char *outMsgBuffer; { register char tc; int inPercent; @@ -124,13 +136,14 @@ static int CheckTypes(bufferp, typesp, typeCount, outMsgBuffer) inPercent = 0; tix = 0; - for(tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) { + for (tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) { *outMsgBuffer = tc; if (tc == 0) { /* hit end of string. We win as long as we aren't * in a '%'. */ - if (inPercent) return 0; + if (inPercent) + return 0; else return 1; } @@ -147,7 +160,7 @@ static int CheckTypes(bufferp, typesp, typeCount, outMsgBuffer) if (tc == 'l') { /* 'l' is a type modifier. */ outMsgBuffer--; - continue; + continue; } /* otherwise, we've finally gotten to the type-describing * character. Make sure there's a type descriptor, and then @@ -156,14 +169,13 @@ static int CheckTypes(bufferp, typesp, typeCount, outMsgBuffer) inPercent = 0; if (tix > typeCount) return 0; /* no more type descriptors left */ - if (tc == 's' ) { + if (tc == 's') { if (typesp[tix] != 1) /* not a string descriptor */ return 0; outMsgBuffer--; *outMsgBuffer = (char)1; } - if (tc == 'u' || tc == 'x' || tc == 'd' - || tc == 'o') { + if (tc == 'u' || tc == 'x' || tc == 'd' || tc == 'o') { if (typesp[tix] != 0) return 0; /* not an integer descriptor */ outMsgBuffer--; @@ -190,10 +202,11 @@ static int CheckTypes(bufferp, typesp, typeCount, outMsgBuffer) /* not reached */ } #else /* AFS_SGI61_ENV */ -static CheckTypes(bufferp, typesp, typeCount) - char *bufferp; - int *typesp; - int typeCount; +static +CheckTypes(bufferp, typesp, typeCount) + char *bufferp; + int *typesp; + int typeCount; { register char tc; int inPercent; @@ -201,20 +214,23 @@ static CheckTypes(bufferp, typesp, typeCount) inPercent = 0; tix = 0; - for(tc = *bufferp;; tc = *(++bufferp)) { + for (tc = *bufferp;; tc = *(++bufferp)) { if (tc == 0) { /* hit end of string. We win as long as we aren't * in a '%'. */ - if (inPercent) return 0; - else return 1; + if (inPercent) + return 0; + else + return 1; } if (tc == '%') { inPercent = 1 - inPercent; continue; } if (inPercent) { - if (tc >= '0' && tc <= '9') continue; /* skip digits in % string */ + if (tc >= '0' && tc <= '9') + continue; /* skip digits in % string */ /* otherwise, we've finally gotten to the type-describing * character. Make sure there's a type descriptor, and then * check the type descriptor. @@ -242,17 +258,18 @@ static CheckTypes(bufferp, typesp, typeCount) #if defined(AFS_SGI61_ENV) && !defined(AFS_SGI62_ENV) #define uint64_t long long #endif -static DisplayRecord(outFilep, alp, rsize) - FILE *outFilep; - register afs_int32 *alp; - afs_int32 rsize; +static +DisplayRecord(outFilep, alp, rsize) + FILE *outFilep; + register afs_int32 *alp; + afs_int32 rsize; { char msgBuffer[1024]; -#ifdef AFS_SGI61_ENV +#if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) char outMsgBuffer[1024]; uint64_t tempParam; uint64_t printfParms[ICL_MAXEXPANSION * /* max parms */ 4]; - char *printfStrings[ICL_MAXEXPANSION * /* max parms */ 4]; + char *printfStrings[ICL_MAXEXPANSION * /* max parms */ 4]; #else /* AFS_SGI61_ENV */ long printfParms[ICL_MAXEXPANSION * /* max parms */ 4]; #endif /* AFS_SGI61_ENV */ @@ -270,17 +287,17 @@ static DisplayRecord(outFilep, alp, rsize) afs_int32 *tlp; /* decode parameters */ - temp = alp[0]; /* type encoded in low-order 24 bits, t0 high */ + temp = alp[0]; /* type encoded in low-order 24 bits, t0 high */ pix = 4; pfpix = 0; pftix = 0; /* init things */ - for(i=0; i<4*ICL_MAXEXPANSION; i++) - printfParms[i] = 0; + for (i = 0; i < 4 * ICL_MAXEXPANSION; i++) + printfParms[i] = 0; /* decode each parameter, getting addrs for afs_hyper_t and strings */ - for(i=0; !done && i<4; i++) { - type = (temp >> (18 - i*6)) & 0x3f; + for (i = 0; !done && i < 4; i++) { + type = (temp >> (18 - i * 6)) & 0x3f; switch (type) { case ICL_TYPE_NONE: done = 1; @@ -288,16 +305,16 @@ static DisplayRecord(outFilep, alp, rsize) case ICL_TYPE_LONG: case ICL_TYPE_POINTER: printfTypes[pftix++] = 0; -#ifdef AFS_SGI61_ENV +#if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) printfParms[pfpix] = alp[pix]; printfParms[pfpix] &= 0xffffffff; if (afs_64bit_kernel) { printfParms[pfpix] <<= 32; - printfParms[pfpix] |= alp[pix+1]; + printfParms[pfpix] |= alp[pix + 1]; } #else /* AFS_SGI61_ENV */ #ifdef AFS_ALPHA_ENV - printfParms[pfpix] = alp[pix+1]; + printfParms[pfpix] = alp[pix + 1]; printfParms[pfpix] |= (alp[pix] <<= 32); #else /* AFS_ALPHA_ENV */ printfParms[pfpix] = alp[pix]; @@ -310,35 +327,36 @@ static DisplayRecord(outFilep, alp, rsize) printfParms[pfpix++] = alp[pix]; break; case ICL_TYPE_HYPER: + case ICL_TYPE_INT64: printfTypes[pftix++] = 0; printfParms[pfpix++] = alp[pix]; printfTypes[pftix++] = 0; - printfParms[pfpix++] = alp[pix+1]; + printfParms[pfpix++] = alp[pix + 1]; break; case ICL_TYPE_FID: printfTypes[pftix++] = 0; printfParms[pfpix++] = alp[pix]; printfTypes[pftix++] = 0; - printfParms[pfpix++] = alp[pix+1]; + printfParms[pfpix++] = alp[pix + 1]; printfTypes[pftix++] = 0; - printfParms[pfpix++] = alp[pix+2]; + printfParms[pfpix++] = alp[pix + 2]; printfTypes[pftix++] = 0; - printfParms[pfpix++] = alp[pix+3]; + printfParms[pfpix++] = alp[pix + 3]; break; case ICL_TYPE_STRING: printfTypes[pftix++] = 1; #ifdef AFS_SGI64_ENV - printfStrings[pfpix++] = (char*) &alp[pix]; + printfStrings[pfpix++] = (char *)&alp[pix]; #else /* AFS_SGI64_ENV */ -#ifdef AFS_SGI61_ENV - printfStrings[pfpix++] = (char *) &alp[pix]; +#if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) + printfStrings[pfpix++] = (char *)&alp[pix]; #else /* AFS_SGI61_ENV */ - printfParms[pfpix++] = (long) &alp[pix]; + printfParms[pfpix++] = (long)&alp[pix]; #endif /* AFS_SGI61_ENV */ #endif /* AFS_SGI64_ENV */ break; case ICL_TYPE_UNIXDATE: - printfParms[pfpix++] = (long) ctime((time_t *)&alp[pix]); + printfParms[pfpix++] = (long)ctime((time_t *) & alp[pix]); break; default: printf("DisplayRecord: Bad type %d in decode switch.\n", type); @@ -348,7 +366,7 @@ static DisplayRecord(outFilep, alp, rsize) if (done) break; - pix += icl_GetSize(type, (char *) &alp[pix]); + pix += icl_GetSize(type, (char *)&alp[pix]); } /* next, try to decode the opcode into a printf string */ @@ -359,45 +377,45 @@ static DisplayRecord(outFilep, alp, rsize) */ printed = 0; if (status == 0) { -#ifdef AFS_SGI61_ENV +#if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) if (CheckTypes(msgBuffer, printfTypes, pftix, outMsgBuffer)) { /* we have a string to use, but it ends "(dfs / zcm)", * so we remove the extra gunk. */ j = strlen(outMsgBuffer); if (j > 12) { - outMsgBuffer[j-11] = 0; + outMsgBuffer[j - 11] = 0; j -= 11; } pfpix = 0; - fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3]/1000000, + fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000, alp[3] % 1000000, alp[2]); - for (i=0; i 5) fputc(outMsgBuffer[i], outFilep); else { switch (outMsgBuffer[i]) { - case 0: /* done */ + case 0: /* done */ break; - case 1: /* string */ + case 1: /* string */ fprintf(outFilep, "%s", printfStrings[pfpix++]); break; - case 2: /* signed integer */ + case 2: /* signed integer */ fprintf(outFilep, "%lld", printfParms[pfpix++]); break; - case 3: /* unsigned integer */ + case 3: /* unsigned integer */ fprintf(outFilep, "%llu", printfParms[pfpix++]); break; - case 4: /* octal integer */ + case 4: /* octal integer */ fprintf(outFilep, "%llo", printfParms[pfpix++]); break; - case 5: /* hex integer */ + case 5: /* hex integer */ fprintf(outFilep, "%llx", printfParms[pfpix++]); break; default: fprintf(outFilep, "fstrace: Bad char %d in outMsgBuffer for parm %d\n", - outMsgBuffer[i], pfpix); + outMsgBuffer[i], pfpix); fprintf(outFilep, "fstrace: msgBuffer='%s'\n", msgBuffer); break; @@ -413,8 +431,9 @@ static DisplayRecord(outFilep, alp, rsize) * so we remove the extra gunk. */ j = strlen(msgBuffer); - if (j > 12) msgBuffer[j-11] = 0; - fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3]/1000000, + if (j > 12) + msgBuffer[j - 11] = 0; + fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000, alp[3] % 1000000, alp[2]); fprintf(outFilep, msgBuffer, printfParms[0], printfParms[1], printfParms[2], printfParms[3], printfParms[4], @@ -433,17 +452,16 @@ static DisplayRecord(outFilep, alp, rsize) } if (!printed) { if (alp[1] == ICL_INFO_TIMESTAMP) { - fprintf(outFilep, "time %d.%06d, pid %u: %s\n", - alp[3]/1000000, alp[3] % 1000000, alp[2], - ctime((time_t *)&alp[4])); + fprintf(outFilep, "time %d.%06d, pid %u: %s\n", alp[3] / 1000000, + alp[3] % 1000000, alp[2], ctime((time_t *) & alp[4])); } else { - fprintf(outFilep, "raw op %d, time %d.%06d, pid %u\n", - alp[1], alp[3]/1000000, alp[3] % 1000000, alp[2]); + fprintf(outFilep, "raw op %d, time %d.%06d, pid %u\n", alp[1], + alp[3] / 1000000, alp[3] % 1000000, alp[2]); /* now decode each parameter and print it */ pix = 4; done = 0; - for(i=0; !done && i<4; i++) { - type = (temp >> (18 - i*6)) & 0x3f; + for (i = 0; !done && i < 4; i++) { + type = (temp >> (18 - i * 6)) & 0x3f; switch (type) { case ICL_TYPE_NONE: done = 1; @@ -455,7 +473,7 @@ static DisplayRecord(outFilep, alp, rsize) #ifdef AFS_SGI61_ENV tempParam = alp[pix]; tempParam <<= 32; - tempParam |= alp[pix+1]; + tempParam |= alp[pix + 1]; fprintf(outFilep, "p%d:%lld ", i, tempParam); #else /* AFS_SGI61_ENV */ fprintf(outFilep, "p%d:%d ", i, alp[pix]); @@ -465,35 +483,39 @@ static DisplayRecord(outFilep, alp, rsize) #ifdef AFS_SGI61_ENV tempParam = alp[pix]; tempParam <<= 32; - tempParam |= alp[pix+1]; + tempParam |= alp[pix + 1]; fprintf(outFilep, "p%d:0x%llx ", i, tempParam); #else /* AFS_SGI61_ENV */ fprintf(outFilep, "p%d:0x%x ", i, alp[pix]); #endif /* AFS_SGI61_ENV */ break; case ICL_TYPE_HYPER: - fprintf(outFilep, "p%d:%x.%x ", i, alp[pix], alp[pix+1]); + case ICL_TYPE_INT64: + fprintf(outFilep, "p%d:%x.%x ", i, alp[pix], + alp[pix + 1]); break; case ICL_TYPE_FID: - fprintf(outFilep, "p%d:%d.%d.%d.%d ", i, alp[pix], - alp[pix+1], alp[pix+2], alp[pix+3]); + fprintf(outFilep, "p%d:%d.%d.%d.%d ", i, alp[pix], + alp[pix + 1], alp[pix + 2], alp[pix + 3]); break; case ICL_TYPE_STRING: - fprintf(outFilep, "p%d:%s ", i, (char *) &alp[pix]); + fprintf(outFilep, "p%d:%s ", i, (char *)&alp[pix]); break; case ICL_TYPE_UNIXDATE: - fprintf(outFilep, "p%d:%s ", i, ctime((time_t *)&alp[pix])); + fprintf(outFilep, "p%d:%s ", i, + ctime((time_t *) & alp[pix])); break; default: - printf("DisplayRecord: Bad type %d in raw print switch.\n", - type); + printf + ("DisplayRecord: Bad type %d in raw print switch.\n", + type); done = 1; break; } if (done) break; - pix += icl_GetSize(type, (char *) &alp[pix]); + pix += icl_GetSize(type, (char *)&alp[pix]); } } fprintf(outFilep, "\n"); /* done with line */ @@ -510,50 +532,53 @@ static DisplayRecord(outFilep, alp, rsize) #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV) #include -static nl_catd catopen1(); -nl_catd NLcatopen(); -static nl_catd _do1_open(); +static nl_catd catopen1(); +nl_catd NLcatopen(); +static nl_catd _do1_open(); static nl_catd cat_already_open(); -static int make_sets(); +static int make_sets(); static FILE *open1catfile(); static void add_open_cat(); static void cat_hard_close(); extern char *strchr(); -static int catpid[NL_MAXOPEN]; +static int catpid[NL_MAXOPEN]; static CATD *catsopen[NL_MAXOPEN]; #define PATH_FORMAT "/usr/lib/nls/msg/%L/%N:/etc/nls/msg/%L/%N" #define DEFAULT_LANG "C" #define TOO_MANY_HOLES(num_holes, num_non_holes) \ (((num_holes) > 100) && ((num_holes) > (num_non_holes))) -char *rmalloc(n) -int n; +char * +rmalloc(n) + int n; /*---- n: the number of bytes to be malloc'ed ----*/ { - char *t; + char *t; - t = (char *) malloc(n); - if (!t) - printf("Failed to get mem\n"); - return(t); + t = (char *)malloc(n); + if (!t) + printf("Failed to get mem\n"); + return (t); } + #ifdef notdef #endif -nl_catd catopen1 (cat, dummy) -char *cat; -int dummy; +nl_catd +catopen1(cat, dummy) + char *cat; + int dummy; /*---- char *cat: the name of the cat to be opened ----*/ /*---- int dummy: dummy variable ----*/ { - int errno_save; - nl_catd _do_open(); /*---- routine that actually opens + int errno_save; + nl_catd _do_open(); /*---- routine that actually opens the catalog ---- */ - CATD *catd; + CATD *catd; - errno_save = errno; + errno_save = errno; /* if (catd = cat_already_open(cat)) { @@ -561,66 +586,68 @@ int dummy; return(catd); } */ - catd = (CATD *)rmalloc (sizeof(CATD)); - if ( catd == NULL ) - return(CATD_ERR); - catd->_name = (char *)rmalloc(strlen(cat) + 1); - if ( catd->_name == NULL ) - return(CATD_ERR); - strcpy(catd->_name,cat); - catd->_fd = FALSE; - catd->_magic = CAT_MAGIC; - catd->_mem = FALSE; + catd = (CATD *) rmalloc(sizeof(CATD)); + if (catd == NULL) + return (CATD_ERR); + catd->_name = (char *)rmalloc(strlen(cat) + 1); + if (catd->_name == NULL) + return (CATD_ERR); + strcpy(catd->_name, cat); + catd->_fd = FALSE; + catd->_magic = CAT_MAGIC; + catd->_mem = FALSE; #ifndef AFS_OSF20_ENV - catd->_pid = getpid(); + catd->_pid = getpid(); #endif - catd->_count = 1; - if (_do1_open(catd) != CATD_ERR) - return(catd); - else { - free(catd->_name); - free(catd); - return(CATD_ERR); - } + catd->_count = 1; + if (_do1_open(catd) != CATD_ERR) + return (catd); + else { + free(catd->_name); + free(catd); + return (CATD_ERR); + } } -nl_catd _do1_open(catd) -nl_catd catd; +nl_catd +_do1_open(catd) + nl_catd catd; /*---- pointer to the partially set up cat descriptor ----*/ { - int make_sets(); /*---- routine to unpack the sets into + int make_sets(); /*---- routine to unpack the sets into fast acccess mode ----*/ - void add_open_cat(); /*---- routine to keep a list of + void add_open_cat(); /*---- routine to keep a list of opened cats ----*/ - /*long*/ int magic; - int i; /*---- Misc counter(s) used for loop */ - struct _catset cs; - int errno_save; - int num_holes; - - errno_save = errno; - - catd->_fd = open1catfile( catd->_name ); - if ( !catd->_fd ) { - return( CATD_ERR ); - } - fread((void *)&magic,(size_t)4,(size_t)1,catd->_fd); - if (magic != CAT_MAGIC){ -printf("Magic was %x instead of %x -> %x\n", magic, CAT_MAGIC, CATD_ERR); + /*long */ int magic; + int i; /*---- Misc counter(s) used for loop */ + struct _catset cs; + int errno_save; + int num_holes; + + errno_save = errno; + + catd->_fd = open1catfile(catd->_name); + if (!catd->_fd) { + return (CATD_ERR); + } + fread((void *)&magic, (size_t) 4, (size_t) 1, catd->_fd); + if (magic != CAT_MAGIC) { + printf("Magic was %x instead of %x -> %x\n", magic, CAT_MAGIC, + CATD_ERR); /* fclose(catd->_fd); catd->_fd = NULL; return( CATD_ERR ); */ - } -/* if ((catd->_mem = shmat((int)fileno(catd->_fd), (char *)0, SHM_MAP | SHM_RDONLY)) + } +/* if ((catd->_mem = shmat((int)fileno(catd->_fd), NULL, SHM_MAP | SHM_RDONLY)) == (char * )ERR ) { */ - if (1) { /* disable the shmat, share memory segemnt */ + if (1) { /* disable the shmat, share memory segemnt */ /*______________________________________________________________________ If the file can not be mapped then simulate mapping for the index @@ -628,121 +655,122 @@ printf("Magic was %x instead of %x -> %x\n", magic, CAT_MAGIC, CATD_ERR); enough for the index table and read the whole thing in) ______________________________________________________________________*/ - /* reset the file pointer to the beginning of catalog */ - fseek(catd->_fd,(long)0,0); + /* reset the file pointer to the beginning of catalog */ + fseek(catd->_fd, (long)0, 0); - /* malloc the header, if fails return error */ - catd->_hd = (struct _header *) rmalloc(sizeof(struct _header)); - if ( catd->_hd == NULL ) - return(CATD_ERR); + /* malloc the header, if fails return error */ + catd->_hd = (struct _header *)rmalloc(sizeof(struct _header)); + if (catd->_hd == NULL) + return (CATD_ERR); - /* read in the whole header */ - fread((void *)catd->_hd,(size_t)sizeof(struct _header),(size_t)1,catd->_fd); + /* read in the whole header */ + fread((void *)catd->_hd, (size_t) sizeof(struct _header), (size_t) 1, + catd->_fd); - /* cs is a dummpy to hold a set temperorily. The purpose of */ - /* this for loop is to fread the whole catalog so that the */ - /* file pointer will be moved to the end of the catalog. */ - for (i = 0 ; i < catd->_hd->_n_sets ; i++) { - fread((void *)&cs,(size_t)4,(size_t)1,catd->_fd); - fseek(catd->_fd, (long)(cs._n_msgs * sizeof(struct _msgptr)),1); - } + /* cs is a dummpy to hold a set temperorily. The purpose of */ + /* this for loop is to fread the whole catalog so that the */ + /* file pointer will be moved to the end of the catalog. */ + for (i = 0; i < catd->_hd->_n_sets; i++) { + fread((void *)&cs, (size_t) 4, (size_t) 1, catd->_fd); + fseek(catd->_fd, (long)(cs._n_msgs * sizeof(struct _msgptr)), 1); + } - /* after the for loop, ftell returns the byte offset of the */ - /* end of the catalog relative to the begining of the file. */ - /* i.e. i contains the byte offset of the whole catalog. */ - i = ftell(catd->_fd); - - /* malloc _mem as a temp pointer to hold the entire catalog. */ - catd->_mem = (char *)rmalloc(i); - if ( catd->_mem == NULL ) - return(CATD_ERR); - - /* reset the file pointer to the begining. */ - fseek(catd->_fd,(long)0,0); - - /* read in the whole catalog into _mem */ - fread((void *)catd->_mem,(size_t)i,(size_t)1,catd->_fd); - - /* - * If there aren't many holes in the set numbers, - * fully expand the compacted set array from the - * catalog. Then in catgets(), we'll be able to use - * the set number to index directly into the expanded - * array. - * - * If there are a lot of holes, leave the set array - * compacted. In catgets(), we'll search through it - * for the requested set. - */ - - num_holes = catd->_hd->_setmax - catd->_hd->_n_sets; - if (!TOO_MANY_HOLES(num_holes, catd->_hd->_n_sets)) { - catd->_sets_expanded = TRUE; - catd->_n_sets = catd->_hd->_setmax; - } - else { - catd->_sets_expanded = FALSE; - catd->_n_sets = catd->_hd->_n_sets - 1; - } + /* after the for loop, ftell returns the byte offset of the */ + /* end of the catalog relative to the begining of the file. */ + /* i.e. i contains the byte offset of the whole catalog. */ + i = ftell(catd->_fd); - /* malloc one extra set more than the max. set index */ - catd->_set = (struct _catset *) rmalloc((catd->_n_sets+1)* - sizeof (struct _catset)); - if ( catd->_set == NULL ) - return(CATD_ERR); - - /* save the max. set number in catd->_setmax */ - catd->_setmax = catd->_hd->_setmax; - /* call make_set to malloc memory for every message */ - if(make_sets(catd) == -1) - return (CATD_ERR); - free(catd->_mem); - catd->_mem = FALSE; - add_open_cat(catd); - return(catd); - } - else { + /* malloc _mem as a temp pointer to hold the entire catalog. */ + catd->_mem = (char *)rmalloc(i); + if (catd->_mem == NULL) + return (CATD_ERR); + + /* reset the file pointer to the begining. */ + fseek(catd->_fd, (long)0, 0); + + /* read in the whole catalog into _mem */ + fread((void *)catd->_mem, (size_t) i, (size_t) 1, catd->_fd); + + /* + * If there aren't many holes in the set numbers, + * fully expand the compacted set array from the + * catalog. Then in catgets(), we'll be able to use + * the set number to index directly into the expanded + * array. + * + * If there are a lot of holes, leave the set array + * compacted. In catgets(), we'll search through it + * for the requested set. + */ + + num_holes = catd->_hd->_setmax - catd->_hd->_n_sets; + if (!TOO_MANY_HOLES(num_holes, catd->_hd->_n_sets)) { + catd->_sets_expanded = TRUE; + catd->_n_sets = catd->_hd->_setmax; + } else { + catd->_sets_expanded = FALSE; + catd->_n_sets = catd->_hd->_n_sets - 1; + } + + /* malloc one extra set more than the max. set index */ + catd->_set = + (struct _catset *)rmalloc((catd->_n_sets + 1) * + sizeof(struct _catset)); + if (catd->_set == NULL) + return (CATD_ERR); + + /* save the max. set number in catd->_setmax */ + catd->_setmax = catd->_hd->_setmax; + /* call make_set to malloc memory for every message */ + if (make_sets(catd) == -1) + return (CATD_ERR); + free(catd->_mem); + catd->_mem = FALSE; + add_open_cat(catd); + return (catd); + } else { /*______________________________________________________________________ Normal mapping has occurred, set a few things up and call make_sets ______________________________________________________________________*/ - catd->_hd =( struct _header * )( catd->_mem ); - catd->_setmax = catd->_hd->_setmax; - catd->_set = (struct _catset *) rmalloc((catd->_hd->_setmax+1)* - sizeof (struct _catset)); - if ( catd->_set == NULL ) - return(CATD_ERR); - if(make_sets(catd) == -1) - return (CATD_ERR); - add_open_cat(catd); - return(catd); - } + catd->_hd = (struct _header *)(catd->_mem); + catd->_setmax = catd->_hd->_setmax; + catd->_set = + (struct _catset *)rmalloc((catd->_hd->_setmax + 1) * + sizeof(struct _catset)); + if (catd->_set == NULL) + return (CATD_ERR); + if (make_sets(catd) == -1) + return (CATD_ERR); + add_open_cat(catd); + return (catd); + } } -static void add_open_cat(catd) -nl_catd catd; - /*---- catd to be added to the list of catalogs ----*/ +static void +add_open_cat(catd) + nl_catd catd; + /*---- catd to be added to the list of catalogs ----*/ { - int i = 0; /*---- Misc counter(s) used for loops ----*/ - while (i < NL_MAXOPEN && catsopen[i]) { - if (!strcmp(catd->_name,catsopen[i]->_name) + int i = 0; /*---- Misc counter(s) used for loops ----*/ + while (i < NL_MAXOPEN && catsopen[i]) { + if (!strcmp(catd->_name, catsopen[i]->_name) #ifndef AFS_OSF20_ENV - && getpid()==catsopen[i]->_pid) + && getpid() == catsopen[i]->_pid) #else - - ) + ) #endif - return; /*---- The catalog is already here ----*/ - i++; - } + return; /*---- The catalog is already here ----*/ + i++; + } - if (i < NL_MAXOPEN) { - catsopen[i] = catd; - catpid[i] = getpid(); - } + if (i < NL_MAXOPEN) { + catsopen[i] = catd; + catpid[i] = getpid(); + } } @@ -761,88 +789,88 @@ nl_catd catd; */ -static int make_sets(catd) -nl_catd catd; -{ - struct _catset *cset; - char *base = catd->_mem; - int n_sets = catd->_hd->_n_sets; - int i; /*---- Misc counter(s) used for loops ----*/ - int j; /*---- Misc counter(s) used for loops ----*/ - int msgmax; /*---- The maximum number of _messages in a set ----*/ - char *cmpct_set_ptr; /*---- pointer into the index table ----*/ - struct _catset cs; /*---- used to look at the sets in the table -*/ - int num_holes; - - cmpct_set_ptr = base + sizeof(struct _header); - - for (i = 0 ; i < n_sets ; i++) { - /* loop through each compacted set */ - - cs = *(struct _catset *)cmpct_set_ptr; - /* set the _catset ptr to the base of the current - compacted set. */ - - cs._mp = (struct _msgptr *)(cmpct_set_ptr + - 2 * sizeof(unsigned short)); - /* set the ms array ptr to the base of - compacted array of _msgptr's */ - - cset = (catd->_sets_expanded) ? - &catd->_set[cs._setno] : &catd->_set[i]; - - /* - * If there aren't many holes in the message numbers, - * fully expand the compacted message array from the - * catalog. Then in catgets(), we'll be able to use - * the message number to index directly into the - * expanded array. - * - * If there are many holes, leave the message array - * compacted. In catgets(), we'll search through it - * for the requested message. - */ - - msgmax = cs._mp[cs._n_msgs - 1]._msgno; - num_holes = msgmax - cs._n_msgs; - if (!TOO_MANY_HOLES(num_holes, cs._n_msgs)) { - cset->_msgs_expanded = TRUE; - cset->_n_msgs = msgmax; - } - else { - cset->_msgs_expanded = FALSE; - cset->_n_msgs = cs._n_msgs - 1; - } +static int +make_sets(catd) + nl_catd catd; +{ + struct _catset *cset; + char *base = catd->_mem; + int n_sets = catd->_hd->_n_sets; + int i; /*---- Misc counter(s) used for loops ----*/ + int j; /*---- Misc counter(s) used for loops ----*/ + int msgmax; /*---- The maximum number of _messages in a set ----*/ + char *cmpct_set_ptr; /*---- pointer into the index table ----*/ + struct _catset cs; /*---- used to look at the sets in the table -*/ + int num_holes; - cset->_mp = (struct _msgptr *) rmalloc((1 + cset->_n_msgs) * - sizeof(struct _msgptr)); - if (cset->_mp == NULL) - return (-1); + cmpct_set_ptr = base + sizeof(struct _header); - cset->_msgtxt = (char **) rmalloc((1 + cset->_n_msgs) * - sizeof(char *)); - if (cset->_msgtxt == NULL) - return (-1); + for (i = 0; i < n_sets; i++) { + /* loop through each compacted set */ - if (cset->_msgs_expanded) { - for (j = 0 ; j < cs._n_msgs ; j++) { - cset->_mp[cs._mp[j]._msgno] = cs._mp[j]; - } - } - else { - for (j = 0 ; j < cs._n_msgs ; j++) { - cset->_mp[j] = cs._mp[j]; - } - } + cs = *(struct _catset *)cmpct_set_ptr; + /* set the _catset ptr to the base of the current + * compacted set. */ - cset->_setno = cs._setno; - /* Superfluous but should have the correct data. Increment - the base of the set pointer. */ + cs._mp = + (struct _msgptr *)(cmpct_set_ptr + 2 * sizeof(unsigned short)); + /* set the ms array ptr to the base of + * compacted array of _msgptr's */ - cmpct_set_ptr += 2 * sizeof(unsigned short) + cs._n_msgs * - sizeof(struct _msgptr); + cset = + (catd->_sets_expanded) ? &catd->_set[cs._setno] : &catd->_set[i]; + + /* + * If there aren't many holes in the message numbers, + * fully expand the compacted message array from the + * catalog. Then in catgets(), we'll be able to use + * the message number to index directly into the + * expanded array. + * + * If there are many holes, leave the message array + * compacted. In catgets(), we'll search through it + * for the requested message. + */ + + msgmax = cs._mp[cs._n_msgs - 1]._msgno; + num_holes = msgmax - cs._n_msgs; + if (!TOO_MANY_HOLES(num_holes, cs._n_msgs)) { + cset->_msgs_expanded = TRUE; + cset->_n_msgs = msgmax; + } else { + cset->_msgs_expanded = FALSE; + cset->_n_msgs = cs._n_msgs - 1; + } + + cset->_mp = + (struct _msgptr *)rmalloc((1 + cset->_n_msgs) * + sizeof(struct _msgptr)); + if (cset->_mp == NULL) + return (-1); + + cset->_msgtxt = + (char **)rmalloc((1 + cset->_n_msgs) * sizeof(char *)); + if (cset->_msgtxt == NULL) + return (-1); + + if (cset->_msgs_expanded) { + for (j = 0; j < cs._n_msgs; j++) { + cset->_mp[cs._mp[j]._msgno] = cs._mp[j]; + } + } else { + for (j = 0; j < cs._n_msgs; j++) { + cset->_mp[j] = cs._mp[j]; + } } - return(0); + + cset->_setno = cs._setno; + /* Superfluous but should have the correct data. Increment + * the base of the set pointer. */ + + cmpct_set_ptr += + 2 * sizeof(unsigned short) + cs._n_msgs * sizeof(struct _msgptr); + } + return (0); } @@ -862,161 +890,160 @@ nl_catd catd; * failure. */ -static FILE *open1catfile(file) -char *file; -{ - extern char *getenv(); - char fl[PATH_MAX]; /*---- place to hold full path ----*/ - char *nlspath; /*---- pointer to the nlspath val ----*/ - FILE *fp; /*---- file pointer ----*/ - char cpth[PATH_MAX]; /*---- current value of nlspath ----*/ - char *p,*np; - char *fulllang; /* %L language value */ - char lang[PATH_MAX]; /* %l language value */ - char *territory; /* %t language value */ - char *codeset; /* %c language value */ - char *ptr; /* for decompose of $LANG */ - char *str; - char *optr; - int nchars; - int lenstr; - char outptr[PATH_MAX]; - int valid; - - if (strchr(file,'/')) { - if ((fp = fopen(file,"r"))) - { fcntl(fileno(fp),F_SETFD,1); - /* set the close-on-exec flag for - child process */ - return(fp); - } +static FILE * +open1catfile(file) + char *file; +{ + extern char *getenv(); + char fl[PATH_MAX]; /*---- place to hold full path ----*/ + char *nlspath; /*---- pointer to the nlspath val ----*/ + FILE *fp; /*---- file pointer ----*/ + char cpth[PATH_MAX]; /*---- current value of nlspath ----*/ + char *p, *np; + char *fulllang; /* %L language value */ + char lang[PATH_MAX]; /* %l language value */ + char *territory; /* %t language value */ + char *codeset; /* %c language value */ + char *ptr; /* for decompose of $LANG */ + char *str; + char *optr; + int nchars; + int lenstr; + char outptr[PATH_MAX]; + int valid; + + if (strchr(file, '/')) { + if ((fp = fopen(file, "r"))) { + fcntl(fileno(fp), F_SETFD, 1); + /* set the close-on-exec flag for + * child process */ + return (fp); } - else { - if (!(nlspath = getenv("NLSPATH"))) - nlspath = PATH_FORMAT; - if (!(fulllang = getenv("LANG"))) - fulllang = DEFAULT_LANG; - if (fulllang == DEFAULT_LANG) - nlspath = PATH_FORMAT; /* if fullang is C, use the - the default nlspath: */ - - /* - ** LANG is a composite of three fields: - ** language_territory.codeset - ** and we're going to break it into those - ** three fields. - */ - - strcpy(lang, fulllang); - - territory = ""; - codeset = ""; - - ptr = strchr( lang, '_' ); - if (ptr != NULL) { - territory = ptr+1; - *ptr = '\0'; - ptr = strchr(territory, '.'); - if (ptr != NULL) { - codeset = ptr+1; - *ptr = '\0'; - } - } else { - ptr = strchr( lang, '.' ); - if (ptr != NULL) { - codeset = ptr+1; - *ptr = '\0'; - } - } + } else { + if (!(nlspath = getenv("NLSPATH"))) + nlspath = PATH_FORMAT; + if (!(fulllang = getenv("LANG"))) + fulllang = DEFAULT_LANG; + if (fulllang == DEFAULT_LANG) + nlspath = PATH_FORMAT; /* if fullang is C, use the + * the default nlspath: */ + + /* + ** LANG is a composite of three fields: + ** language_territory.codeset + ** and we're going to break it into those + ** three fields. + */ - np = nlspath; - while (*np) { - p = cpth; - while (*np && *np != ':') - *p++ = *np++; - *p = '\0'; - if (*np) /*---- iff on a colon then advance --*/ - np++; - valid = 0; - if (strlen(cpth)) { - ptr = cpth; - optr = outptr; - - nchars = 0; - while (*ptr != '\0') { - while ((*ptr != '\0') && (*ptr != '%') - && (nchars < PATH_MAX)) { - *(optr++) = *(ptr++); - nchars++; - } - if (*ptr == '%') { - switch (*(++ptr)) { - case '%': - str = "%"; - break; - case 'L': - str = fulllang; - break; - case 'N': - valid = 1; - str = file; - break; - case 'l': - str = lang; - break; - case 't': - str = territory; - break; - case 'c': - str = codeset; - break; - default: - str = ""; - break; - } - lenstr = strlen(str); - nchars += lenstr; - if (nchars < PATH_MAX) { - strcpy(optr, str); - optr += lenstr; - } else { - break; - } - ptr++; - } else { - if (nchars >= PATH_MAX) { - break; - } - } - } - *optr = '\0'; - strcpy(cpth, outptr); + strcpy(lang, fulllang); + + territory = ""; + codeset = ""; + + ptr = strchr(lang, '_'); + if (ptr != NULL) { + territory = ptr + 1; + *ptr = '\0'; + ptr = strchr(territory, '.'); + if (ptr != NULL) { + codeset = ptr + 1; + *ptr = '\0'; + } + } else { + ptr = strchr(lang, '.'); + if (ptr != NULL) { + codeset = ptr + 1; + *ptr = '\0'; + } + } + + np = nlspath; + while (*np) { + p = cpth; + while (*np && *np != ':') + *p++ = *np++; + *p = '\0'; + if (*np) /*---- iff on a colon then advance --*/ + np++; + valid = 0; + if (strlen(cpth)) { + ptr = cpth; + optr = outptr; + + nchars = 0; + while (*ptr != '\0') { + while ((*ptr != '\0') && (*ptr != '%') + && (nchars < PATH_MAX)) { + *(optr++) = *(ptr++); + nchars++; + } + if (*ptr == '%') { + switch (*(++ptr)) { + case '%': + str = "%"; + break; + case 'L': + str = fulllang; + break; + case 'N': + valid = 1; + str = file; + break; + case 'l': + str = lang; + break; + case 't': + str = territory; + break; + case 'c': + str = codeset; + break; + default: + str = ""; + break; } - else { /*---- iff leading | trailing | - adjacent colons ... --*/ - valid = 1; - strcpy(cpth,file); + lenstr = strlen(str); + nchars += lenstr; + if (nchars < PATH_MAX) { + strcpy(optr, str); + optr += lenstr; + } else { + break; + } + ptr++; + } else { + if (nchars >= PATH_MAX) { + break; } - if (valid == 1 && (fp = fopen(cpth,"r"))) - { fcntl(fileno(fp),F_SETFD,1); - /* set the close-on-exec flag for - child process */ - return(fp); - } + } } - if (fp = fopen(file,"r")) - { fcntl(fileno(fp),F_SETFD,1); - /* set the close-on-exec flag for - child process */ - return(fp); - } + *optr = '\0'; + strcpy(cpth, outptr); + } else { /*---- iff leading | trailing | + adjacent colons ... --*/ + valid = 1; + strcpy(cpth, file); + } + if (valid == 1 && (fp = fopen(cpth, "r"))) { + fcntl(fileno(fp), F_SETFD, 1); + /* set the close-on-exec flag for + * child process */ + return (fp); + } + } + if (fp = fopen(file, "r")) { + fcntl(fileno(fp), F_SETFD, 1); + /* set the close-on-exec flag for + * child process */ + return (fp); } - return (NULL); + } + return (NULL); } - - + + /* * @@ -1032,194 +1059,192 @@ char *file; * a NULL pointer if no CATD exists. */ -static nl_catd cat_already_open(cat) -char *cat; +static nl_catd +cat_already_open(cat) + char *cat; /*---- name of the catalog to be opened ----*/ { - int i; /*---- Misc counter(s) used for loops ----*/ - - for (i = 0 ; i < NL_MAXOPEN && catsopen[i] ; i++) { + int i; /*---- Misc counter(s) used for loops ----*/ + + for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) { #ifndef AFS_OSF20_ENV - if (!strcmp(cat,catsopen[i]->_name) && getpid()==catsopen[i]->_pid) { + if (!strcmp(cat, catsopen[i]->_name) && getpid() == catsopen[i]->_pid) { #else - if (!strcmp(cat,catsopen[i]->_name)) { + if (!strcmp(cat, catsopen[i]->_name)) { #endif - return(catsopen[i]); - } + return (catsopen[i]); } - return(0); + } + return (0); } -int catclose1(catd) /*---- the catd to be closed ----*/ -nl_catd catd; /*---- the catd to be closed ----*/ +int +catclose1(catd) /*---- the catd to be closed ----*/ + nl_catd catd; /*---- the catd to be closed ----*/ { - int i; + int i; - if (catd == CATD_ERR) - return(-1); - for (i=0; i< NL_MAXOPEN && catsopen[i]; i++) { + if (catd == CATD_ERR) + return (-1); + for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) { #ifndef AFS_OSF20_ENV - if (catd == catsopen[i] && getpid()==catsopen[i]->_pid) + if (catd == catsopen[i] && getpid() == catsopen[i]->_pid) #else - if (catd == catsopen[i]) + if (catd == catsopen[i]) #endif - break; - } - if (i == NL_MAXOPEN || catsopen[i] == NULL) - return (-1); - if (catd->_fd == (FILE *)NULL) + break; + } + if (i == NL_MAXOPEN || catsopen[i] == NULL) + return (-1); + if (catd->_fd == (FILE *) NULL) /*---- return if this is an extra open or a bad catalog discriptor ----*/ - return(-1); - if (cat_already_open(catd->_name)) { - if (catd->_count == 1) { - cat_hard_close(catd); - return (0); /*--- the last legal clsoe ---*/ - } - else if (catd->_count > 1) { - catd->_count = catd->_count - 1; - return(0); /*--- a legal close ---*/ - } - else - return (-1); /*--- an extra illegal close ---*/ - } - else { - return(-1); - } + return (-1); + if (cat_already_open(catd->_name)) { + if (catd->_count == 1) { + cat_hard_close(catd); + return (0); /*--- the last legal clsoe ---*/ + } else if (catd->_count > 1) { + catd->_count = catd->_count - 1; + return (0); /*--- a legal close ---*/ + } else + return (-1); /*--- an extra illegal close ---*/ + } else { + return (-1); + } } -static void cat_hard_close(catd) -nl_catd catd; +static void +cat_hard_close(catd) + nl_catd catd; /*---- the catd to be closed ----*/ { - int i; /*---- Misc counter(s) used for loops ----*/ - int j; /*---- Misc counter ----*/ + int i; /*---- Misc counter(s) used for loops ----*/ + int j; /*---- Misc counter ----*/ + + if (catd == CATD_ERR) + return; - if (catd == CATD_ERR) - return; - /*______________________________________________________________________ remove any entry for the catalog in the catsopen array ______________________________________________________________________*/ - for (i = 0 ; i < NL_MAXOPEN && catsopen[i] ; i++) { - if (catd == catsopen[i]) { - for (; i < NL_MAXOPEN-1; i++) { - catsopen[i] = catsopen[i+1]; - catpid[i] = catpid[i+1]; - } - catsopen[i] = NULL; - catpid[i] = 0; - } + for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) { + if (catd == catsopen[i]) { + for (; i < NL_MAXOPEN - 1; i++) { + catsopen[i] = catsopen[i + 1]; + catpid[i] = catpid[i + 1]; + } + catsopen[i] = NULL; + catpid[i] = 0; } + } /*______________________________________________________________________ close the cat and free up the memory ______________________________________________________________________*/ - if (catd->_mem == FALSE) - { - for (i = 0 ; i <= catd->_n_sets ; i++) { - if (catd->_set[i]._mp) - free(catd->_set[i]._mp); - /*---- free the _message pointer arrays ----*/ - - if (catd->_set[i]._msgtxt) { - for (j = 0 ; j <= catd->_set[i]._n_msgs ; j++) { - if (catd->_set[i]._msgtxt[j]) { + if (catd->_mem == FALSE) { + for (i = 0; i <= catd->_n_sets; i++) { + if (catd->_set[i]._mp) + free(catd->_set[i]._mp); + /*---- free the _message pointer arrays ----*/ + + if (catd->_set[i]._msgtxt) { + for (j = 0; j <= catd->_set[i]._n_msgs; j++) { + if (catd->_set[i]._msgtxt[j]) { /* free(catd->_set[i]._msgtxt[j]);*/ - } - } - if (catd->_set[i]._msgtxt) - free(catd->_set[i]._msgtxt); + } } + if (catd->_set[i]._msgtxt) + free(catd->_set[i]._msgtxt); + } } - } + } - if (catd->_fd) - fclose(catd->_fd); /*---- close the ctatlog ----*/ - if (catd->_set) - free(catd->_set); /*---- free the sets ----*/ - if (catd->_name) - free(catd->_name); /*---- free the name ----*/ - if (catd->_hd) - free(catd->_hd); /*---- free the header ----*/ - if (catd) - free(catd); /*---- free the catd ----*/ + if (catd->_fd) + fclose(catd->_fd); /*---- close the ctatlog ----*/ + if (catd->_set) + free(catd->_set); /*---- free the sets ----*/ + if (catd->_name) + free(catd->_name); /*---- free the name ----*/ + if (catd->_hd) + free(catd->_hd); /*---- free the header ----*/ + if (catd) + free(catd); /*---- free the catd ----*/ } -static char *_do1_read_msg(nl_catd catd,int setno,int msgno) +static char * +_do1_read_msg(nl_catd catd, int setno, int msgno) /*---- catd: the catd of the catalog to be read from ----*/ /*---- setno: the set number of the message ----*/ /*---- msgno: the msgno of the message ----*/ - { - nl_catd catd1; /*--- catd for different process ----*/ - char *_read1_msg(); + nl_catd catd1; /*--- catd for different process ----*/ + char *_read1_msg(); #ifndef AFS_OSF20_ENV - if (getpid() == catd->_pid) + if (getpid() == catd->_pid) #else - if (1) + if (1) #endif - return (_read1_msg (catd, setno, msgno)); - else { - /* - * Since our pid is different from the one in - * catd, catd must have come from a catopen() - * in our parent. We need a catd of our own. - * The first time through here, the call to - * catopen() creates a new catd and we try to - * open its message catalog. After that, the - * catopen() just retrieves the catd. - */ - if (((catd1 = catopen1(catd->_name, 0)) != CATD_ERR) && - ((catd1->_fd == NL_FILE_CLOSED && - _do1_open(catd1) != CATD_ERR) || - (catd1->_fd != NL_FILE_UNUSED))) - return (_read1_msg(catd1,setno,msgno)); - else - return(NULL); - } + return (_read1_msg(catd, setno, msgno)); + else { + /* + * Since our pid is different from the one in + * catd, catd must have come from a catopen() + * in our parent. We need a catd of our own. + * The first time through here, the call to + * catopen() creates a new catd and we try to + * open its message catalog. After that, the + * catopen() just retrieves the catd. + */ + if (((catd1 = catopen1(catd->_name, 0)) != CATD_ERR) + && ((catd1->_fd == NL_FILE_CLOSED && _do1_open(catd1) != CATD_ERR) + || (catd1->_fd != NL_FILE_UNUSED))) + return (_read1_msg(catd1, setno, msgno)); + else + return (NULL); + } } - + struct _catset *_cat1_get_catset(); static struct _msgptr *_cat1_get_msgptr(); -static char *_read1_msg(nl_catd catd,int setno,int msgno) - -{ - struct _catset *set; /*--- ptr to set's _catset structure ---*/ - struct _msgptr *msg; /*--- ptr to msg's _msgptr structure ---*/ - char **msgtxt; /*--- temporary pointer to the message text +static char * +_read1_msg(nl_catd catd, int setno, int msgno) +{ + struct _catset *set; /*--- ptr to set's _catset structure ---*/ + struct _msgptr *msg; /*--- ptr to msg's _msgptr structure ---*/ + char **msgtxt; /*--- temporary pointer to the message text for speed. ----*/ - set = _cat1_get_catset(catd, setno); - if (set) { - msg = _cat1_get_msgptr(set, msgno); - if (msg) { - msgtxt = &set->_msgtxt[msg - set->_mp]; - if (1/*!*msgtxt*/) { - *msgtxt = (char *) malloc(msg->_msglen + 1); - if (!*msgtxt) - return(NULL); - - fseek(catd->_fd, (long) msg->_offset, 0); - if (fread((void *) *msgtxt, - (size_t) (msg->_msglen + 1), - (size_t) 1, catd->_fd) != 1) - return(NULL); - } + set = _cat1_get_catset(catd, setno); + if (set) { + msg = _cat1_get_msgptr(set, msgno); + if (msg) { + msgtxt = &set->_msgtxt[msg - set->_mp]; + if (1 /*!*msgtxt */ ) { + *msgtxt = (char *)malloc(msg->_msglen + 1); + if (!*msgtxt) + return (NULL); + + fseek(catd->_fd, (long)msg->_offset, 0); + if (fread + ((void *)*msgtxt, (size_t) (msg->_msglen + 1), (size_t) 1, + catd->_fd) != 1) + return (NULL); + } - return(*msgtxt); - } + return (*msgtxt); } - return(NULL); + } + return (NULL); } /* @@ -1235,20 +1260,20 @@ static char *_read1_msg(nl_catd catd,int setno,int msgno) * is less than, equal to, or greater than the set number of * the _catset structure. * - */ + */ static int compare_sets(const void *key, const void *element) { - int *setno = (int *) key; - struct _catset *set = (struct _catset *) element; + int *setno = (int *)key; + struct _catset *set = (struct _catset *)element; - if (*setno < set->_setno) - return -1; - if (*setno > set->_setno) - return 1; + if (*setno < set->_setno) + return -1; + if (*setno > set->_setno) + return 1; - return 0; + return 0; } @@ -1265,42 +1290,42 @@ compare_sets(const void *key, const void *element) * RETURNS: Returns a pointer to the set on success. * On any error, returns NULL. * - */ + */ -struct _catset *_cat1_get_catset(nl_catd catd, int setno) +struct _catset * +_cat1_get_catset(nl_catd catd, int setno) { - struct _catset *set; + struct _catset *set; - if ((catd == (nl_catd) NULL) || (catd == CATD_ERR)) - return (struct _catset *) NULL; + if ((catd == (nl_catd) NULL) || (catd == CATD_ERR)) + return (struct _catset *)NULL; - if (catd->_sets_expanded) { - if ((setno < 0) || (setno > catd->_n_sets)) - return (struct _catset *) NULL; + if (catd->_sets_expanded) { + if ((setno < 0) || (setno > catd->_n_sets)) + return (struct _catset *)NULL; - set = &catd->_set[setno]; + set = &catd->_set[setno]; - /* - * Catch empty elements in the array. They aren't - * real sets. - */ + /* + * Catch empty elements in the array. They aren't + * real sets. + */ - if (set->_mp == (struct _msgptr *) NULL) - return (struct _catset *) NULL; - } - else { - set = (struct _catset *) bsearch((void *) &setno, - catd->_set, catd->_n_sets + 1, - sizeof(struct _catset), - compare_sets); - - /* - * Since the sets are compacted, there aren't any - * empty elements in the array to check for. - */ - } + if (set->_mp == (struct _msgptr *)NULL) + return (struct _catset *)NULL; + } else { + set = + (struct _catset *)bsearch((void *)&setno, catd->_set, + catd->_n_sets + 1, + sizeof(struct _catset), compare_sets); + + /* + * Since the sets are compacted, there aren't any + * empty elements in the array to check for. + */ + } - return set; + return set; } @@ -1317,20 +1342,20 @@ struct _catset *_cat1_get_catset(nl_catd catd, int setno) * number is less than, equal to, or greater than the message * number of the _msgptr structure. * - */ + */ static int compare_msgs(const void *key, const void *element) { - int *msgno = (int *) key; - struct _msgptr *msg = (struct _msgptr *) element; + int *msgno = (int *)key; + struct _msgptr *msg = (struct _msgptr *)element; - if (*msgno < msg->_msgno) - return -1; - if (*msgno > msg->_msgno) - return 1; + if (*msgno < msg->_msgno) + return -1; + if (*msgno > msg->_msgno) + return 1; - return 0; + return 0; } /* @@ -1347,86 +1372,85 @@ compare_msgs(const void *key, const void *element) * RETURNS: Returns a pointer to the message on success. * On any error, returns NULL. * - */ -static struct _msgptr *_cat1_get_msgptr(struct _catset *set, int msgno) -{ - struct _msgptr *msg; - - if (set == (struct _catset *) NULL) - return (struct _msgptr *) NULL; - - if (set->_mp == (struct _msgptr *) NULL) /* empty set */ - return (struct _msgptr *) NULL; - - if (set->_msgs_expanded) { - if ((msgno < 0) || (msgno > set->_n_msgs)) - return (struct _msgptr *) NULL; - - msg = &set->_mp[msgno]; - - /* - * Catch empty elements in the array. They aren't - * real messages. - */ - - if (!msg->_offset) - return (struct _msgptr *) NULL; - } - else { - msg = (struct _msgptr *) bsearch((void *) &msgno, - set->_mp, set->_n_msgs + 1, - sizeof(struct _msgptr), - compare_msgs); - - /* - * Since the messages are compacted, there aren't any - * empty elements in the array to check for. - */ - } - - return msg; -} - -char *catgets1(nl_catd catd,int setno,int msgno,char *def) - /*---- catd: the catd to get the message from ----*/ - /*---- setno: the set number of the message ----*/ - /*---- msgno: the message number of the message ----*/ - /*---- def: the default string to be returned ----*/ - -{ - int errno_save; - char *_do_read_msg(); - char *m; - errno_save = errno; - - if (catd == NULL || catd == CATD_ERR || - catd->_magic != CAT_MAGIC || catd->_fd == NL_FILE_UNUSED) { - return(def); + */ +static struct _msgptr * +_cat1_get_msgptr(struct _catset *set, int msgno) +{ + struct _msgptr *msg; + + if (set == (struct _catset *)NULL) + return (struct _msgptr *)NULL; + + if (set->_mp == (struct _msgptr *)NULL) /* empty set */ + return (struct _msgptr *)NULL; + + if (set->_msgs_expanded) { + if ((msgno < 0) || (msgno > set->_n_msgs)) + return (struct _msgptr *)NULL; + + msg = &set->_mp[msgno]; + + /* + * Catch empty elements in the array. They aren't + * real messages. + */ + + if (!msg->_offset) + return (struct _msgptr *)NULL; + } else { + msg = + (struct _msgptr *)bsearch((void *)&msgno, set->_mp, + set->_n_msgs + 1, + sizeof(struct _msgptr), compare_msgs); + + /* + * Since the messages are compacted, there aren't any + * empty elements in the array to check for. + */ + } + + return msg; +} + +char * +catgets1(nl_catd catd, int setno, int msgno, char *def) + /*---- catd: the catd to get the message from ----*/ + /*---- setno: the set number of the message ----*/ + /*---- msgno: the message number of the message ----*/ + /*---- def: the default string to be returned ----*/ +{ + int errno_save; + char *_do_read_msg(); + char *m; + errno_save = errno; + + if (catd == NULL || catd == CATD_ERR || catd->_magic != CAT_MAGIC + || catd->_fd == NL_FILE_UNUSED) { + return (def); + } + if (catd->_fd == NL_FILE_CLOSED) { + catd = _do1_open(catd); + if (catd == CATD_ERR) + return (def); + } + + if (catd->_mem) { /*---- for mapped files ----*/ + if (setno <= catd->_hd->_setmax) { + if (msgno < catd->_set[setno]._n_msgs) { + if (catd->_set[setno]._mp[msgno]._offset) { + return (catd->_mem + + catd->_set[setno]._mp[msgno]._offset); + } } - if (catd->_fd == NL_FILE_CLOSED) { - catd = _do1_open(catd); - if (catd == CATD_ERR) - return(def); - } - - if (catd->_mem) { /*---- for mapped files ----*/ - if (setno <= catd->_hd->_setmax) { - if (msgno < catd->_set[setno]._n_msgs) { - if (catd->_set[setno]._mp[msgno]._offset) { - return(catd->_mem + - catd->_set[setno]._mp[msgno]._offset); - } - } - } - return(def); - } - else { /*---- for unmapped files ----*/ - m = _do1_read_msg(catd,setno,msgno); - if(m == NULL) - return(def); - else - return(m); - } + } + return (def); + } else { /*---- for unmapped files ----*/ + m = _do1_read_msg(catd, setno, msgno); + if (m == NULL) + return (def); + else + return (m); + } } #endif @@ -1452,63 +1476,63 @@ char *catgets1(nl_catd catd,int setno,int msgno,char *def) #define RPC_NLS_FORMAT "%s.cat" #endif -dce1_error_inq_text (status_to_convert, error_text, status) -afs_uint32 status_to_convert; -unsigned char *error_text; -int *status; - -{ - unsigned short facility_code; - unsigned short component_code; - unsigned short status_code; - unsigned short i, failed=0; - nl_catd catd; - char component_name[4]; - char *facility_name; - char filename_prefix[7]; - char nls_filename[11]; - char alt_filename[80]; - char *message; +dce1_error_inq_text(status_to_convert, error_text, status) + afs_uint32 status_to_convert; + unsigned char *error_text; + int *status; + +{ + unsigned short facility_code; + unsigned short component_code; + unsigned short status_code; + unsigned short i, failed = 0; + nl_catd catd; + char component_name[4]; + char *facility_name; + char filename_prefix[7]; + char nls_filename[11]; + char alt_filename[80]; + char *message; int J; static char *facility_names[] = { - "xxx", - "afs" + "xxx", + "afs" }; /* * set up output status for future error returns */ - if (status != NULL) - { - *status = -1; + if (status != NULL) { + *status = -1; } /* * check for ok input status */ - if (status_to_convert == 0) - { - if (status != NULL) - { - *status = 0; - } - strcpy ((char *)error_text, "successful completion"); - return; + if (status_to_convert == 0) { + if (status != NULL) { + *status = 0; + } + strcpy((char *)error_text, "successful completion"); + return; } /* * extract the component, facility and status codes */ - facility_code = (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT; - component_code = (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT; - status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT; + facility_code = + (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT; + component_code = + (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT; + status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT; /* * see if this is a recognized facility */ - if (facility_code == 0 || facility_code > sizeof (facility_names) / sizeof (char *)) - { - sprintf ((char *) error_text, "status %08x (unknown facility)", status_to_convert); - return; + if (facility_code == 0 + || facility_code > sizeof(facility_names) / sizeof(char *)) { + sprintf((char *)error_text, "status %08x (unknown facility)", + status_to_convert); + return; } facility_name = facility_names[facility_code - 1]; /* @@ -1520,102 +1544,96 @@ int *status; component_code /= 40; component_name[1] = component_code % 40; component_name[0] = component_code / 40; - for (i = 0; i < 3; i++) - { - component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27); + for (i = 0; i < 3; i++) { + component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27); } - sprintf (filename_prefix, "%3s%3s", facility_name, component_name); - sprintf (nls_filename, RPC_NLS_FORMAT, filename_prefix); + sprintf(filename_prefix, "%3s%3s", facility_name, component_name); + sprintf(nls_filename, RPC_NLS_FORMAT, filename_prefix); /* * Open the message file */ #if defined(AFS_OSF_ENV) #if defined(AFS_OSF20_ENV) - catd = (nl_catd) catopen (nls_filename, 0); + catd = (nl_catd) catopen(nls_filename, 0); #else - catd = (nl_catd) catopen1 (nls_filename, 0); + catd = (nl_catd) catopen1(nls_filename, 0); #endif #else - J = (int) catopen (nls_filename, 0); - catd = (nl_catd)J; + J = (int)catopen(nls_filename, 0); + catd = (nl_catd) J; #endif - if (catd == (nl_catd) -1) - { - /* - * If we did not succeed in opening message file using NLSPATH, - * try to open the message file in a well-known default area - */ -tryagain: + if (catd == (nl_catd) - 1) { + /* + * If we did not succeed in opening message file using NLSPATH, + * try to open the message file in a well-known default area + */ + tryagain: #ifndef RPC_DEFAULT_NLSPATH - sprintf(alt_filename, "%s/C/%s.cat", AFSDIR_CLIENT_ETC_DIRPATH, filename_prefix); + sprintf(alt_filename, "%s/C/%s.cat", AFSDIR_CLIENT_ETC_DIRPATH, + filename_prefix); #else - sprintf (alt_filename, RPC_DEFAULT_NLSPATH, filename_prefix); + sprintf(alt_filename, RPC_DEFAULT_NLSPATH, filename_prefix); #endif #if defined(AFS_OSF_ENV) #if defined(AFS_OSF20_ENV) - catd = (nl_catd) catopen (alt_filename, 0); + catd = (nl_catd) catopen(alt_filename, 0); #else - catd = (nl_catd) catopen1 (alt_filename, 0); + catd = (nl_catd) catopen1(alt_filename, 0); #endif #else - J = (int) catopen (alt_filename, 0); - catd = (nl_catd)J; + J = (int)catopen(alt_filename, 0); + catd = (nl_catd) J; #endif - if (catd == (nl_catd) -1) - { - sprintf ((char *) error_text, "status %08x (%s / %s)", - status_to_convert, facility_name, component_name); - return; - } - } + if (catd == (nl_catd) - 1) { + sprintf((char *)error_text, "status %08x (%s / %s)", + status_to_convert, facility_name, component_name); + return; + } + } /* * try to get the specified message from the file */ #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV) - message = (char *) catgets1 (catd, 1, status_code, NO_MESSAGE); + message = (char *)catgets1(catd, 1, status_code, NO_MESSAGE); #else - message = (char *) catgets (catd, 1, status_code, NO_MESSAGE); + message = (char *)catgets(catd, 1, status_code, NO_MESSAGE); #endif /* * if everything went well, return the resulting message */ - if (strcmp (message, NO_MESSAGE) != 0) - { - sprintf ((char *) error_text, "%s (%s / %s)", - message, facility_name, component_name); - if (status != NULL) - { - *status = 0; - } - } - else - { + if (strcmp(message, NO_MESSAGE) != 0) { + sprintf((char *)error_text, "%s (%s / %s)", message, facility_name, + component_name); + if (status != NULL) { + *status = 0; + } + } else { if (!failed) { failed = 1; #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV) - catclose1 (catd); + catclose1(catd); #else - catclose (catd); + catclose(catd); #endif goto tryagain; } - sprintf ((char *) error_text, "status %08x (%s / %s)", - status_to_convert, facility_name, component_name); + sprintf((char *)error_text, "status %08x (%s / %s)", + status_to_convert, facility_name, component_name); } #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV) - catclose1 (catd); + catclose1(catd); #else - catclose (catd); + catclose(catd); #endif -} +} icl_DumpKernel(outFilep, setname) - FILE *outFilep; - char *setname; + FILE *outFilep; + char *setname; { afs_int32 bufferSize = 0; afs_int32 *bufferp; @@ -1629,13 +1647,13 @@ icl_DumpKernel(outFilep, setname) struct logInfo *lip; /* first, enumerate the logs we're interested in */ - if (setname) - { + if (setname) { int found = 0; /* dump logs for a particular set */ - for(i=0; i < ICL_LOGSPERSET; i++) { - code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, - (long) setname, i, (long) tname, sizeof(tname)); + for (i = 0; i < ICL_LOGSPERSET; i++) { + code = + afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname, + i, (long)tname, sizeof(tname)); if (code) { if (errno == EBADF) { code = 0; @@ -1643,59 +1661,64 @@ icl_DumpKernel(outFilep, setname) } break; } - code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, - (long) tname, (long) &dummy, (long) &dummy2, 0); + code = + afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname, + (long)&dummy, (long)&dummy2, 0); if (code) break; found++; if (dummy > bufferSize) /* find biggest log */ bufferSize = dummy; - lip = (struct logInfo *) malloc(sizeof(struct logInfo)); + lip = (struct logInfo *)malloc(sizeof(struct logInfo)); memset((char *)lip, 0, sizeof(*lip)); lip->nextp = allInfo; allInfo = lip; - lip->name = (char *) malloc(strlen(tname)+1); + lip->name = (char *)malloc(strlen(tname) + 1); strcpy(lip->name, tname); } i = found; - } - else - { + } else { /* dump all logs */ - for(i=0;i<1000;i++) { - code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, - i, (long) tname, sizeof(tname), (long) &dummy); - if (code) break; + for (i = 0; i < 1000; i++) { + code = + afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname, + sizeof(tname), (long)&dummy); + if (code) + break; if (dummy > bufferSize) /* find biggest log */ bufferSize = dummy; - lip = (struct logInfo *) malloc(sizeof(struct logInfo)); + lip = (struct logInfo *)malloc(sizeof(struct logInfo)); memset((char *)lip, 0, sizeof(*lip)); lip->nextp = allInfo; allInfo = lip; - lip->name = (char *) malloc(strlen(tname)+1); + lip->name = (char *)malloc(strlen(tname) + 1); strcpy(lip->name, tname); } } - if (bufferSize == 0) return -1; + if (bufferSize == 0) + return -1; bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize); - if (!bufferp) return -1; + if (!bufferp) + return -1; fprintf(outFilep, "Found %d logs.\n", i); /* now print out the contents of each log */ - for(lip = allInfo; lip; lip=lip->nextp) { + for (lip = allInfo; lip; lip = lip->nextp) { fprintf(outFilep, "\nContents of log %s:\n", lip->name); /* read out everything first; gets a more consistent * snapshot. */ nwords = 0; /* total words copied out */ - for(i=0;;) { + for (i = 0;;) { /* display all the entries in the log */ - if (bufferSize - nwords <= 0) break; /* filled whole buffer */ - code = afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT, - (long) lip->name, (long) (bufferp+nwords), - bufferSize - nwords, (long) &i); + if (bufferSize - nwords <= 0) + break; /* filled whole buffer */ + code = + afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT, (long)lip->name, + (long)(bufferp + nwords), bufferSize - nwords, + (long)&i); if (code < 0) { /* otherwise we've got an error */ fprintf(outFilep, "Returned error %d dumping log.\n", errno); @@ -1713,14 +1736,14 @@ icl_DumpKernel(outFilep, setname) } nwords += code; i += code; - } /* for loop over all cookies */ + } /* for loop over all cookies */ /* otherwise we should display all of the log entries here. * Note that a record may end in the middle, in which case * we should start over with the cookie value of the start * of that record. */ - for(ix = 0; ix> 24) & 0xff; if (rlength <= 0) { @@ -1729,7 +1752,7 @@ icl_DumpKernel(outFilep, setname) goto done; } /* ensure that entire record fits */ - if (ix+rlength > nwords) { + if (ix + rlength > nwords) { /* doesn't fit, adjust cookie and break */ break; } @@ -1740,17 +1763,17 @@ icl_DumpKernel(outFilep, setname) /* obsolete: read entire buffer first */ i += rlength; /* update cookie value, too */ #endif - } /* for loop displaying buffer */ - } /* for loop over all logs */ + } /* for loop displaying buffer */ + } /* for loop over all logs */ done: free(bufferp); - return(retVal); + return (retVal); } /* clear out log 'name' */ icl_ClearLog(name) - char *name; + char *name; { afs_int32 code; @@ -1760,11 +1783,11 @@ icl_ClearLog(name) /* clear out set 'name' */ icl_ClearSet(name) - char *name; + char *name; { afs_int32 code; - code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long) name, 0, 0, 0); + code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long)name, 0, 0, 0); return code; } @@ -1778,31 +1801,35 @@ icl_ClearAll() } /* list out all available sets to outFileP */ -int icl_ListSets(outFileP) - FILE *outFileP; +int +icl_ListSets(outFileP) + FILE *outFileP; { int i; afs_int32 code = 0; afs_int32 states; char tname[64]; - for(i=0;i<1000;i++) { - code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS, - i, (long) tname, sizeof(tname), (long) &states); - if (code) break; - (void) fprintf(outFileP, "%s %s%s%s\n", tname, - (states & ICL_SETF_ACTIVE) ? "active" : "inactive", - (states & ICL_SETF_FREED) ? " (dormant)" : "", - (states & ICL_SETF_PERSISTENT) ? " persistent" : ""); + for (i = 0; i < 1000; i++) { + code = + afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS, i, (long)tname, + sizeof(tname), (long)&states); + if (code) + break; + (void)fprintf(outFileP, "%s %s%s%s\n", tname, + (states & ICL_SETF_ACTIVE) ? "active" : "inactive", + (states & ICL_SETF_FREED) ? " (dormant)" : "", + (states & ICL_SETF_PERSISTENT) ? " persistent" : ""); } return 0; } /* list out all available logs to outFileP */ -int icl_ListLogs(outFileP, int32flg) - FILE *outFileP; - int int32flg; +int +icl_ListLogs(outFileP, int32flg) + FILE *outFileP; + int int32flg; { int i; int allocated; @@ -1810,32 +1837,35 @@ int icl_ListLogs(outFileP, int32flg) afs_int32 logSize; char tname[64]; - for(i=0;i<1000;i++) { - code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, - i, (long) tname, sizeof(tname), (long) &logSize); - if (code) break; - if (int32flg) - { + for (i = 0; i < 1000; i++) { + code = + afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname, + sizeof(tname), (long)&logSize); + if (code) + break; + if (int32flg) { /* get more information on the log */ - code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) tname, - (long) &logSize, (long) &allocated, 0); + code = + afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname, + (long)&logSize, (long)&allocated, 0); if (code) break; - (void) fprintf(outFileP, "%s : %d kbytes (%s)\n", tname, logSize/1024, - allocated ? "allocated" : "unallocated"); - } - else - (void) fprintf(outFileP, "%s\n", tname); + (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname, + logSize / 1024, + allocated ? "allocated" : "unallocated"); + } else + (void)fprintf(outFileP, "%s\n", tname); } return 0; } /* list out all available logs to outFileP */ -int icl_ListLogsBySet(outFileP, setname, int32flg) - FILE *outFileP; - char *setname; - int int32flg; +int +icl_ListLogsBySet(outFileP, setname, int32flg) + FILE *outFileP; + char *setname; + int int32flg; { int i; afs_int32 code = 0; @@ -1843,9 +1873,10 @@ int icl_ListLogsBySet(outFileP, setname, int32flg) int allocated; char tname[64]; - for(i=0; i < ICL_LOGSPERSET; i++) { - code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, - (long) setname, i, (long) tname, sizeof(tname)); + for (i = 0; i < ICL_LOGSPERSET; i++) { + code = + afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname, i, + (long)tname, sizeof(tname)); if (code) { if (errno == EBADF) { code = 0; @@ -1853,37 +1884,39 @@ int icl_ListLogsBySet(outFileP, setname, int32flg) } break; } - if (int32flg) - { + if (int32flg) { /* get more information on the log */ - code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) tname, - (long) &logSize, (long) &allocated, 0); + code = + afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname, + (long)&logSize, (long)&allocated, 0); if (code) break; - (void) fprintf(outFileP, "%s : %d kbytes (%s)\n", tname, logSize/1024, - allocated ? "allocated" : "unallocated"); - } - else - (void) fprintf(outFileP, "%s\n", tname); + (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname, + logSize / 1024, + allocated ? "allocated" : "unallocated"); + } else + (void)fprintf(outFileP, "%s\n", tname); } return code; } /* activate/deactivate/free specified set */ -int icl_ChangeSetState(name, op) - char *name; - afs_int32 op; +int +icl_ChangeSetState(name, op) + char *name; + afs_int32 op; { afs_int32 code; - code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long) name, op, 0, 0); + code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long)name, op, 0, 0); return code; } /* activate/deactivate/free all sets */ -int icl_ChangeAllSetState(op) - afs_int32 op; +int +icl_ChangeAllSetState(op) + afs_int32 op; { afs_int32 code; @@ -1892,43 +1925,50 @@ int icl_ChangeAllSetState(op) } /* set size if log */ -int icl_ChangeLogSize(name, logSize) - char *name; - afs_int32 logSize; +int +icl_ChangeLogSize(name, logSize) + char *name; + afs_int32 logSize; { afs_int32 code; - code = afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0, 0); + code = + afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0, + 0); return code; } /* get logsize of specified log */ -int icl_GetLogsize(logname, logSizeP, allocatedP) - char *logname; - afs_int32 *logSizeP; - int *allocatedP; +int +icl_GetLogsize(logname, logSizeP, allocatedP) + char *logname; + afs_int32 *logSizeP; + int *allocatedP; { afs_int32 code; - code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) logname, - (long) logSizeP, (long) allocatedP, 0); + code = + afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname, + (long)logSizeP, (long)allocatedP, 0); return code; } /* get state of specified set */ -int icl_GetSetState(setname, stateP) - char *setname; - afs_int32 *stateP; +int +icl_GetSetState(setname, stateP) + char *setname; + afs_int32 *stateP; { afs_int32 code; - code = afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long) setname, - (long) stateP, 0, 0); + code = + afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long)setname, + (long)stateP, 0, 0); return code; } icl_TailKernel(outFilep, logname, waitTime) - FILE *outFilep; - char *logname; - afs_int32 waitTime; + FILE *outFilep; + char *logname; + afs_int32 waitTime; { afs_int32 bufferSize = 0; afs_int32 newBufferSize; @@ -1942,46 +1982,46 @@ icl_TailKernel(outFilep, logname, waitTime) struct logInfo *lip; /* get information about the specified log */ - code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, - (long) logname, (long) &bufferSize, (long) &allocated, 0); - if (code) - { + code = + afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname, + (long)&bufferSize, (long)&allocated, 0); + if (code) { if (errno == ENOENT) - (void) fprintf(stderr, "'%s' not found\n", logname); + (void)fprintf(stderr, "'%s' not found\n", logname); else - (void) fprintf(stderr, "cannot get information on log '%s' (errno = %d)\n", - logname, errno); + (void)fprintf(stderr, + "cannot get information on log '%s' (errno = %d)\n", + logname, errno); return -1; } - if (!allocated) - { - (void) fprintf(stderr, "'%s' not allocated\n", logname); + if (!allocated) { + (void)fprintf(stderr, "'%s' not allocated\n", logname); return 0; } - if (bufferSize == 0) return -1; + if (bufferSize == 0) + return -1; bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize); - if (!bufferp) - { - (void) fprintf(stderr, "cannot allocate %d words for buffer\n", - bufferSize); + if (!bufferp) { + (void)fprintf(stderr, "cannot allocate %d words for buffer\n", + bufferSize); return -1; } /* start "infinite" loop */ - for(;;) - { + for (;;) { /* read out all that's currently there */ nwords = 0; /* total words copied out */ - i = 0; /* initialize cookie */ - for(;;) { + i = 0; /* initialize cookie */ + for (;;) { /* display all the entries in the log */ - if (bufferSize - nwords <= 0) - break; /* filled whole buffer, clear when done */ - code = afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR, - (long) logname, (long) (bufferp+nwords), - bufferSize - nwords, (long) &i); + if (bufferSize - nwords <= 0) + break; /* filled whole buffer, clear when done */ + code = + afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR, (long)logname, + (long)(bufferp + nwords), bufferSize - nwords, + (long)&i); if (code < 0) { /* otherwise we've got an error */ fprintf(stderr, "returned error %d dumping log.\n", errno); @@ -1998,18 +2038,18 @@ icl_TailKernel(outFilep, logname, waitTime) } nwords += code; i += code; - } /* for loop over all cookies */ + } /* for loop over all cookies */ /* otherwise we should display all of the log entries here. * Note that a record may end in the middle, in which case * we should start over with the cookie value of the start * of that record. */ - for(ix = 0; ix> 24) & 0xff; /* ensure that entire record fits */ - if (ix+rlength > nwords) { + if (ix + rlength > nwords) { /* doesn't fit, adjust cookie and break */ if (rlength <= 0) { fprintf(stderr, "BOGUS: 0 length record\n"); @@ -2021,63 +2061,59 @@ icl_TailKernel(outFilep, logname, waitTime) /* print the record */ DisplayRecord(outFilep, &bufferp[ix], rlength); ix += rlength; - } /* for loop displaying buffer */ + } /* for loop displaying buffer */ if (waitTime) sleep(waitTime); /* see if things have changed */ - code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, - (long) logname, (long) &newBufferSize, - (long) &allocated, 0); - if (code) - { + code = + afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname, + (long)&newBufferSize, (long)&allocated, 0); + if (code) { if (errno == ENOENT) - (void) fprintf(stderr, "'%s' not found\n", logname); + (void)fprintf(stderr, "'%s' not found\n", logname); else - (void) fprintf(stderr, "cannot get information on log '%s' (errno = %d)\n", - logname, errno); + (void)fprintf(stderr, + "cannot get information on log '%s' (errno = %d)\n", + logname, errno); retVal = -1; goto tail_done; } - - if (!allocated) - { - (void) fprintf(stderr, "'%s' no int32er allocated\n", logname); + + if (!allocated) { + (void)fprintf(stderr, "'%s' no int32er allocated\n", logname); retVal = -1; goto tail_done; } - - if (bufferSize == 0) - { - (void) fprintf(stderr, "buffer size has become 0\n"); + + if (bufferSize == 0) { + (void)fprintf(stderr, "buffer size has become 0\n"); retVal = -1; goto tail_done; } - if (bufferSize != newBufferSize) - { + if (bufferSize != newBufferSize) { /* have to reallocate a buffer */ bufferSize = newBufferSize; free(bufferp); bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize); - if (!bufferp) - { - (void) fprintf(stderr, "cannot allocate %d words for buffer\n", - bufferSize); + if (!bufferp) { + (void)fprintf(stderr, "cannot allocate %d words for buffer\n", + bufferSize); retVal = -1; goto tail_done; } } - } /* infinite loop */ + } /* infinite loop */ tail_done: free(bufferp); - return(retVal); + return (retVal); } #if !defined(AFS_SGI_ENV) -afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6) -long call, parm0, parm1, parm2, parm3, parm4, parm5, parm6; +afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6) + long call, parm0, parm1, parm2, parm3, parm4, parm5, parm6; { int code; #ifdef AFS_LINUX20_ENV @@ -2098,29 +2134,25 @@ long call, parm0, parm1, parm2, parm3, parm4, parm5, parm6; /* Linux can only handle 5 arguments in the actual syscall. */ if (call == AFSCALL_ICL) { code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, eparm); - } - else { + } else { code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3); } #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) /* on sparc this function returns none value, so do it myself */ - __asm__ __volatile__ ( - "mov %o0, %i0\n\t" - "ret\n\t" - "restore"); + __asm__ __volatile__("mov %o0, %i0; ret; restore"); #endif #else #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV) - code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4); + code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4); #else #if defined(AFS_SGI_ENV) - code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */ + code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */ #else code = syscall(AFSCALL_ICL, parm0, parm1, parm2, parm3, parm4); #endif #endif - return code; #endif /* AFS_LINUX20_ENV */ + return code; } #endif @@ -2140,12 +2172,13 @@ icl_Init() } icl_CreateSet(name, baseLogp, fatalLogp, outSetpp) - char *name; - struct afs_icl_log *baseLogp; - struct afs_icl_log *fatalLogp; - struct afs_icl_set **outSetpp; + char *name; + struct afs_icl_log *baseLogp; + struct afs_icl_log *fatalLogp; + struct afs_icl_set **outSetpp; { - return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags*/0, outSetpp); + return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags */ 0, + outSetpp); } /* create a set, given pointers to base and fatal logs, if any. @@ -2155,30 +2188,30 @@ icl_CreateSet(name, baseLogp, fatalLogp, outSetpp) * those references will be released. */ icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp) - char *name; - struct afs_icl_log *baseLogp; - struct afs_icl_log *fatalLogp; - afs_uint32 flags; - struct afs_icl_set **outSetpp; + char *name; + struct afs_icl_log *baseLogp; + struct afs_icl_log *fatalLogp; + afs_uint32 flags; + struct afs_icl_set **outSetpp; { register struct afs_icl_set *setp; register int i; afs_int32 states = ICL_DEFAULT_SET_STATES; - if (!icl_inited) icl_Init(); + if (!icl_inited) + icl_Init(); for (setp = icl_allSets; setp; setp = setp->nextp) { if (strcmp(setp->name, name) == 0) { setp->refCount++; *outSetpp = setp; - if (flags & ICL_CRSET_FLAG_PERSISTENT) - { + if (flags & ICL_CRSET_FLAG_PERSISTENT) { setp->states |= ICL_SETF_PERSISTENT; } return 0; } } - + /* determine initial state */ if (flags & ICL_CRSET_FLAG_DEFAULT_ON) states = ICL_SETF_ACTIVE; @@ -2187,18 +2220,18 @@ icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp) if (flags & ICL_CRSET_FLAG_PERSISTENT) states |= ICL_SETF_PERSISTENT; - setp = (struct afs_icl_set *) osi_Alloc(sizeof(struct afs_icl_set)); - memset((caddr_t)setp, 0, sizeof(*setp)); + setp = (struct afs_icl_set *)osi_Alloc(sizeof(struct afs_icl_set)); + memset((caddr_t) setp, 0, sizeof(*setp)); setp->refCount = 1; if (states & ICL_SETF_FREED) states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */ setp->states = states; - setp->name = (char *)osi_Alloc(strlen(name)+1); + setp->name = (char *)osi_Alloc(strlen(name) + 1); strcpy(setp->name, name); setp->nevents = ICL_DEFAULTEVENTS; setp->eventFlags = (char *)osi_Alloc(ICL_DEFAULTEVENTS); - for(i=0; ieventFlags[i] = 0xff; /* default to enabled */ /* update this global info under the icl_lock */ @@ -2225,9 +2258,9 @@ icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp) /* function to change event enabling information for a particular set */ icl_SetEnable(setp, eventID, setValue) - struct afs_icl_set *setp; - afs_int32 eventID; - int setValue; + struct afs_icl_set *setp; + afs_int32 eventID; + int setValue; { char *tp; @@ -2247,9 +2280,9 @@ icl_SetEnable(setp, eventID, setValue) * otherwise it is enabled. All events start out enabled by default. */ icl_GetEnable(setp, eventID, getValuep) - struct afs_icl_set *setp; - afs_int32 eventID; - int *getValuep; + struct afs_icl_set *setp; + afs_int32 eventID; + int *getValuep; { if (!ICL_EVENTOK(setp, eventID)) { return -1; @@ -2263,7 +2296,7 @@ icl_GetEnable(setp, eventID, getValuep) /* hold and release event sets */ icl_SetHold(setp) - register struct afs_icl_set *setp; + register struct afs_icl_set *setp; { setp->refCount++; return 0; @@ -2271,24 +2304,24 @@ icl_SetHold(setp) /* free a set. Called with icl_lock locked */ icl_ZapSet(setp) - register struct afs_icl_set *setp; + register struct afs_icl_set *setp; { register struct afs_icl_set **lpp, *tp; int i; register struct afs_icl_log *tlp; - for(lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) { + for (lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) { if (tp == setp) { /* found the dude we want to remove */ *lpp = setp->nextp; - osi_Free(setp->name, 1+strlen(setp->name)); + osi_Free(setp->name, 1 + strlen(setp->name)); osi_Free(setp->eventFlags, ICL_EVENTBYTES(setp->nevents)); - for(i=0; i < ICL_LOGSPERSET; i++) { + for (i = 0; i < ICL_LOGSPERSET; i++) { if (tlp = setp->logs[i]) icl_LogReleNL(tlp); } osi_Free(setp, sizeof(struct afs_icl_set)); - break; /* won't find it twice */ + break; /* won't find it twice */ } } return 0; @@ -2296,7 +2329,7 @@ icl_ZapSet(setp) /* do the release, watching for deleted entries */ icl_SetRele(setp) - register struct afs_icl_set *setp; + register struct afs_icl_set *setp; { if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) { icl_ZapSet(setp); /* destroys setp's lock! */ @@ -2306,7 +2339,7 @@ icl_SetRele(setp) /* free a set entry, dropping its reference count */ icl_SetFree(setp) - register struct afs_icl_set *setp; + register struct afs_icl_set *setp; { setp->states |= ICL_SETF_DELETED; icl_SetRele(setp); @@ -2314,12 +2347,13 @@ icl_SetFree(setp) } /* find a set by name, returning it held */ -struct afs_icl_set *icl_FindSet(name) - char *name; +struct afs_icl_set * +icl_FindSet(name) + char *name; { register struct afs_icl_set *tp; - for(tp = icl_allSets; tp; tp=tp->nextp) { + for (tp = icl_allSets; tp; tp = tp->nextp) { if (strcmp(tp->name, name) == 0) { /* this is the dude we want */ tp->refCount++; @@ -2331,19 +2365,20 @@ struct afs_icl_set *icl_FindSet(name) /* zero out all the logs in the set */ icl_ZeroSet(setp) - struct afs_icl_set *setp; + struct afs_icl_set *setp; { register int i; int code = 0; int tcode; struct afs_icl_log *logp; - - for(i = 0; i < ICL_LOGSPERSET; i++) { + + for (i = 0; i < ICL_LOGSPERSET; i++) { logp = setp->logs[i]; if (logp) { icl_LogHold(logp); tcode = icl_ZeroLog(logp); - if (tcode != 0) code = tcode; /* save the last bad one */ + if (tcode != 0) + code = tcode; /* save the last bad one */ icl_LogRele(logp); } } @@ -2351,33 +2386,34 @@ icl_ZeroSet(setp) } icl_EnumerateSets(aproc, arock) - int (*aproc)(); - char *arock; + int (*aproc) (); + char *arock; { register struct afs_icl_set *tp, *np; register afs_int32 code; code = 0; - for(tp = icl_allSets; tp; tp=np) { - tp->refCount++; /* hold this guy */ - code = (*aproc)(tp->name, arock, tp); - np = tp->nextp; /* tp may disappear next, but not np */ + for (tp = icl_allSets; tp; tp = np) { + tp->refCount++; /* hold this guy */ + code = (*aproc) (tp->name, arock, tp); + np = tp->nextp; /* tp may disappear next, but not np */ if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED)) icl_ZapSet(tp); - if (code) break; + if (code) + break; } return code; } icl_AddLogToSet(setp, newlogp) - struct afs_icl_set *setp; - struct afs_icl_log *newlogp; + struct afs_icl_set *setp; + struct afs_icl_log *newlogp; { register int i; int code = -1; struct afs_icl_log *logp; - - for(i = 0; i < ICL_LOGSPERSET; i++) { + + for (i = 0; i < ICL_LOGSPERSET; i++) { if (!setp->logs[i]) { setp->logs[i] = newlogp; code = i; @@ -2393,14 +2429,14 @@ icl_AddLogToSet(setp, newlogp) } icl_SetSetStat(setp, op) - struct afs_icl_set *setp; - int op; + struct afs_icl_set *setp; + int op; { int i; afs_int32 code; struct afs_icl_log *logp; - switch(op) { + switch (op) { case ICL_OP_SS_ACTIVATE: /* activate a log */ /* * If we are not already active, see if we have released @@ -2410,7 +2446,7 @@ icl_SetSetStat(setp, op) if (!(setp->states & ICL_SETF_ACTIVE)) { if (setp->states & ICL_SETF_FREED) { /* have to reassert desire for logs */ - for(i = 0; i < ICL_LOGSPERSET; i++) { + for (i = 0; i < ICL_LOGSPERSET; i++) { logp = setp->logs[i]; if (logp) { icl_LogHold(logp); @@ -2440,7 +2476,7 @@ icl_SetSetStat(setp, op) code = EINVAL; else { if (!(setp->states & ICL_SETF_FREED)) { - for(i = 0; i < ICL_LOGSPERSET; i++) { + for (i = 0; i < ICL_LOGSPERSET; i++) { logp = setp->logs[i]; if (logp) { icl_LogHold(logp); @@ -2465,7 +2501,7 @@ struct afs_icl_log *afs_icl_allLogs = 0; /* hold and release logs */ icl_LogHold(logp) - register struct afs_icl_log *logp; + register struct afs_icl_log *logp; { logp->refCount++; return 0; @@ -2473,7 +2509,7 @@ icl_LogHold(logp) /* hold and release logs, called with lock already held */ icl_LogHoldNL(logp) - register struct afs_icl_log *logp; + register struct afs_icl_log *logp; { logp->refCount++; return 0; @@ -2481,15 +2517,16 @@ icl_LogHoldNL(logp) /* keep track of how many sets believe the log itself is allocated */ icl_LogUse(logp) - register struct afs_icl_log *logp; + register struct afs_icl_log *logp; { if (logp->setCount == 0) { /* this is the first set actually using the log -- allocate it */ - if (logp->logSize == 0) { + if (logp->logSize == 0) { /* we weren't passed in a hint and it wasn't set */ logp->logSize = ICL_DEFAULT_LOGSIZE; } - logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize); + logp->datap = + (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize); } logp->setCount++; return 0; @@ -2497,28 +2534,27 @@ icl_LogUse(logp) /* decrement the number of real users of the log, free if possible */ icl_LogFreeUse(logp) - register struct afs_icl_log *logp; + register struct afs_icl_log *logp; { if (--logp->setCount == 0) { - /* no more users -- free it (but keep log structure around)*/ + /* no more users -- free it (but keep log structure around) */ osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize); logp->firstUsed = logp->firstFree = 0; logp->logElements = 0; - logp->datap = (afs_int32 *)0; + logp->datap = NULL; } return 0; } /* set the size of the log to 'logSize' */ icl_LogSetSize(logp, logSize) - register struct afs_icl_log *logp; - afs_int32 logSize; -{ + register struct afs_icl_log *logp; + afs_int32 logSize; +{ if (!logp->datap) { /* nothing to worry about since it's not allocated */ logp->logSize = logSize; - } - else { + } else { /* reset log */ logp->firstUsed = logp->firstFree = 0; logp->logElements = 0; @@ -2534,18 +2570,18 @@ icl_LogSetSize(logp, logSize) /* free a log. Called with icl_lock locked. */ icl_ZapLog(logp) - register struct afs_icl_log *logp; + register struct afs_icl_log *logp; { register struct afs_icl_log **lpp, *tp; - for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) { + for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) { if (tp == logp) { /* found the dude we want to remove */ *lpp = logp->nextp; - osi_Free(logp->name, 1+strlen(logp->name)); + osi_Free(logp->name, 1 + strlen(logp->name)); osi_Free(logp->datap, logp->logSize * sizeof(afs_int32)); osi_Free(logp, sizeof(struct icl_log)); - break; /* won't find it twice */ + break; /* won't find it twice */ } } return 0; @@ -2553,7 +2589,7 @@ icl_ZapLog(logp) /* do the release, watching for deleted entries */ icl_LogRele(logp) - register struct afs_icl_log *logp; + register struct afs_icl_log *logp; { if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) { icl_ZapLog(logp); /* destroys logp's lock! */ @@ -2563,7 +2599,7 @@ icl_LogRele(logp) /* do the release, watching for deleted entries, log already held */ icl_LogReleNL(logp) - register struct afs_icl_log *logp; + register struct afs_icl_log *logp; { if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) { icl_ZapLog(logp); /* destroys logp's lock! */ @@ -2572,8 +2608,8 @@ icl_LogReleNL(logp) } /* zero out the log */ -icl_ZeroLog(logp) - register struct afs_icl_log *logp; +int +icl_ZeroLog(register struct afs_icl_log *logp) { logp->firstUsed = logp->firstFree = 0; logp->logElements = 0; @@ -2582,7 +2618,7 @@ icl_ZeroLog(logp) /* free a log entry, and drop its reference count */ icl_LogFree(logp) - register struct afs_icl_log *logp; + register struct afs_icl_log *logp; { logp->states |= ICL_LOGF_DELETED; icl_LogRele(logp); @@ -2590,38 +2626,41 @@ icl_LogFree(logp) } -icl_EnumerateLogs(aproc, arock) - int (*aproc)(); - char *arock; +int +icl_EnumerateLogs(int (*aproc) + (char *name, char *arock, struct afs_icl_log * tp), + char *arock) { register struct afs_icl_log *tp; register afs_int32 code; code = 0; - for(tp = afs_icl_allLogs; tp; tp=tp->nextp) { - tp->refCount++; /* hold this guy */ - code = (*aproc)(tp->name, arock, tp); + for (tp = afs_icl_allLogs; tp; tp = tp->nextp) { + tp->refCount++; /* hold this guy */ + code = (*aproc) (tp->name, arock, tp); if (--tp->refCount == 0) icl_ZapLog(tp); - if (code) break; + if (code) + break; } return code; } -afs_icl_bulkSetinfo_t *GetBulkSetInfo() +afs_icl_bulkSetinfo_t * +GetBulkSetInfo() { unsigned int infoSize; - infoSize = sizeof(afs_icl_bulkSetinfo_t) + - (ICL_RPC_MAX_SETS-1) * sizeof(afs_icl_setinfo_t); - if (!setInfo) - { - setInfo = (afs_icl_bulkSetinfo_t *)malloc(infoSize); - if (!setInfo) - { - (void) fprintf(stderr, "Could not allocate the memory for bulk set info structure\n"); - exit (1); + infoSize = + sizeof(afs_icl_bulkSetinfo_t) + (ICL_RPC_MAX_SETS - + 1) * sizeof(afs_icl_setinfo_t); + if (!setInfo) { + setInfo = (afs_icl_bulkSetinfo_t *) malloc(infoSize); + if (!setInfo) { + (void)fprintf(stderr, + "Could not allocate the memory for bulk set info structure\n"); + exit(1); } } memset((char *)setInfo, 0, infoSize); @@ -2629,18 +2668,20 @@ afs_icl_bulkSetinfo_t *GetBulkSetInfo() return setInfo; } -afs_icl_bulkLoginfo_t *GetBulkLogInfo() -{ unsigned int infoSize; +afs_icl_bulkLoginfo_t * +GetBulkLogInfo() +{ + unsigned int infoSize; - infoSize = sizeof(afs_icl_bulkLoginfo_t) + - (ICL_RPC_MAX_LOGS-1) * sizeof(afs_icl_loginfo_t); - if (!logInfo) - { - logInfo = (afs_icl_bulkLoginfo_t *)malloc(infoSize); - if (!logInfo) - { - (void) fprintf(stderr, "Could not allocate the memory for bulk log info structure\n"); - exit (1); + infoSize = + sizeof(afs_icl_bulkLoginfo_t) + (ICL_RPC_MAX_LOGS - + 1) * sizeof(afs_icl_loginfo_t); + if (!logInfo) { + logInfo = (afs_icl_bulkLoginfo_t *) malloc(infoSize); + if (!logInfo) { + (void)fprintf(stderr, + "Could not allocate the memory for bulk log info structure\n"); + exit(1); } } @@ -2649,42 +2690,39 @@ afs_icl_bulkLoginfo_t *GetBulkLogInfo() } -static DoDump(as, arock) - register struct cmd_syndesc *as; - char *arock; +static +DoDump(as, arock) + register struct cmd_syndesc *as; + char *arock; { afs_int32 code = 0; afs_int32 tcode; - afs_int32 waitTime = 10 /* seconds */; + afs_int32 waitTime = 10 /* seconds */ ; int error = 0; char *logname; char *filename; FILE *outfp = stdout; time_t startTime; - struct cmd_item * itemp; + struct cmd_item *itemp; if (geteuid() != 0) { printf("fstrace must be run as root\n"); exit(1); } - if (as->parms[3].items) { - if (!as->parms[1].items) - { - (void) fprintf(stderr, "-sleep can only be used with -follow\n"); + if (as->parms[3].items) { + if (!as->parms[1].items) { + (void)fprintf(stderr, "-sleep can only be used with -follow\n"); return 1; } - waitTime = strtol(as->parms[3].items->data, - (char **)0, 0); + waitTime = strtol(as->parms[3].items->data, NULL, 0); } - if (as->parms[2].items) - { + if (as->parms[2].items) { /* try to open the specified output file */ - if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL) - { - (void) fprintf(stderr, "Cannot open file '%s' for writing\n", - as->parms[2].items->data); + if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL) { + (void)fprintf(stderr, "Cannot open file '%s' for writing\n", + as->parms[2].items->data); return 1; } } @@ -2693,100 +2731,107 @@ static DoDump(as, arock) #else startTime = time(0); #endif - (void) fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n", - ctime(&startTime)); + (void)fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n", + ctime(&startTime)); - if (as->parms[0].items) - { - for (itemp = as->parms[0].items; itemp; itemp = itemp->next) - { + if (as->parms[0].items) { + for (itemp = as->parms[0].items; itemp; itemp = itemp->next) { tcode = icl_DumpKernel(outfp, itemp->data); - if (tcode) - { - (void) fprintf(stderr, "Unable to dump set %s (errno = %d)\n", - itemp->data, errno); + if (tcode) { + (void)fprintf(stderr, "Unable to dump set %s (errno = %d)\n", + itemp->data, errno); code = tcode; } } - } else if (as->parms[1].items) { + } else if (as->parms[1].items) { logname = as->parms[1].items->data; code = icl_TailKernel(outfp, logname, waitTime); if (code) { - (void) fprintf(stderr, "Error tailing kernel log '%s' (errno = %d)\n", - logname, errno); + (void)fprintf(stderr, + "Error tailing kernel log '%s' (errno = %d)\n", + logname, errno); } } else code = icl_DumpKernel(outfp, NULL); - (void) fprintf(outfp, "\nAFS Trace Dump - %s\n", - code ? "FAILED" : "Completed"); + (void)fprintf(outfp, "\nAFS Trace Dump - %s\n", + code ? "FAILED" : "Completed"); if (outfp != stdout) - (void) fclose(outfp); + (void)fclose(outfp); return code; } -static void SetUpDump() +static void +SetUpDump() { struct cmd_syndesc *dumpSyntax; - - dumpSyntax = cmd_CreateSyntax("dump", DoDump, (char *)NULL, "dump AFS trace logs"); + + dumpSyntax = + cmd_CreateSyntax("dump", DoDump, (char *)NULL, "dump AFS trace logs"); (void)cmd_AddParm(dumpSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name"); - (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL, "log_name"); - (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL, "output_filename"); - (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds_between_reads"); + (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL, + "log_name"); + (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL, + "output_filename"); + (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL, + "seconds_between_reads"); } -static DoShowLog(as, arock) - register struct cmd_syndesc *as; - char *arock; +static +DoShowLog(as, arock) + register struct cmd_syndesc *as; + char *arock; { afs_int32 retVal = 0; afs_int32 code = 0; afs_int32 logSize; int allocated; - int int32flg=0; - struct cmd_item * itemp; + int int32flg = 0; + struct cmd_item *itemp; if (geteuid() != 0) { printf("fstrace must be run as root\n"); exit(1); } - if (as->parms[2].items) int32flg = 1; + if (as->parms[2].items) + int32flg = 1; - if (as->parms[0].items) { + if (as->parms[0].items) { /* enumerate logs for the specified sets */ for (itemp = as->parms[0].items; itemp; itemp = itemp->next) { - (void) fprintf(stdout, "Logs for set '%s':\n", itemp->data); + (void)fprintf(stdout, "Logs for set '%s':\n", itemp->data); code = icl_ListLogsBySet(stdout, itemp->data, int32flg); if (code) { - (void) fprintf(stderr, "Error in enumerating set %s (errno = %d)\n", - itemp->data, errno); + (void)fprintf(stderr, + "Error in enumerating set %s (errno = %d)\n", + itemp->data, errno); retVal = code; } } - } - else if (as->parms[1].items) { + } else if (as->parms[1].items) { /* print out log information */ for (itemp = as->parms[1].items; itemp; itemp = itemp->next) { code = icl_GetLogsize(itemp->data, &logSize, &allocated); if (!code) - (void) fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data, - logSize/1024, allocated ? "allocated" : "unallocated"); + (void)fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data, + logSize / 1024, + allocated ? "allocated" : "unallocated"); else { - (void) fprintf(stderr, "Could not find log '%s' (errno = %d)\n", - itemp->data, errno); + (void)fprintf(stderr, + "Could not find log '%s' (errno = %d)\n", + itemp->data, errno); retVal = code; } } - } - else { + } else { /* show all logs */ - (void) fprintf(stdout, "Available logs:\n"); + (void)fprintf(stdout, "Available logs:\n"); code = icl_ListLogs(stdout, int32flg); if (code) { - (void) fprintf(stderr, "Error in listing logs (errno = %d)\n", errno); + (void)fprintf(stderr, "Error in listing logs (errno = %d)\n", + errno); retVal = code; } } @@ -2794,51 +2839,57 @@ static DoShowLog(as, arock) return retVal; } -static void SetUpShowLog() +static void +SetUpShowLog() { struct cmd_syndesc *showSyntax; - - showSyntax = cmd_CreateSyntax("lslog", DoShowLog, (char *)NULL,"list available logs"); - (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name"); - (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL,"log_name"); - (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL,""); + + showSyntax = + cmd_CreateSyntax("lslog", DoShowLog, (char *)NULL, + "list available logs"); + (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name"); + (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL, "log_name"); + (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL, ""); } -static DoShowSet(as, arock) - register struct cmd_syndesc *as; - char *arock; +static +DoShowSet(as, arock) + register struct cmd_syndesc *as; + char *arock; { afs_int32 retVal = 0; afs_int32 code = 0; afs_int32 state; - struct cmd_item * itemp; + struct cmd_item *itemp; if (geteuid() != 0) { printf("fstrace must be run as root\n"); exit(1); } - if (as->parms[0].items) { + if (as->parms[0].items) { /* print information on the specified sets */ for (itemp = as->parms[0].items; itemp; itemp = itemp->next) { code = icl_GetSetState(itemp->data, &state); if (code) { - (void) fprintf(stderr, "Error getting status on set %s (errno = %d)\n", - itemp->data, errno); + (void)fprintf(stderr, + "Error getting status on set %s (errno = %d)\n", + itemp->data, errno); retVal = code; - } - else - (void) fprintf(stdout, "Set %s: %s%s%s\n", itemp->data, - (state & ICL_SETF_ACTIVE) ? "active" : "inactive", - (state & ICL_SETF_FREED) ? " (dormant)" : "", - (state & ICL_SETF_PERSISTENT) ? " persistent" : ""); + } else + (void)fprintf(stdout, "Set %s: %s%s%s\n", itemp->data, + (state & ICL_SETF_ACTIVE) ? "active" : + "inactive", + (state & ICL_SETF_FREED) ? " (dormant)" : "", + (state & ICL_SETF_PERSISTENT) ? " persistent" : + ""); } - } - else { + } else { /* show all sets */ - (void) fprintf(stdout, "Available sets:\n"); + (void)fprintf(stdout, "Available sets:\n"); code = icl_ListSets(stdout); if (code) { - (void) fprintf(stderr, "Error in listing sets (errno = %d)\n", errno); + (void)fprintf(stderr, "Error in listing sets (errno = %d)\n", + errno); retVal = code; } } @@ -2846,52 +2897,58 @@ static DoShowSet(as, arock) return retVal; } -static void SetUpShowSet() +static void +SetUpShowSet() { struct cmd_syndesc *showSyntax; - - showSyntax = cmd_CreateSyntax("lsset", DoShowSet, (char *)NULL, "list available event sets"); + + showSyntax = + cmd_CreateSyntax("lsset", DoShowSet, (char *)NULL, + "list available event sets"); (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name"); } -static DoClear(as, arock) - register struct cmd_syndesc *as; - char *arock; +static +DoClear(as, arock) + register struct cmd_syndesc *as; + char *arock; { afs_int32 retVal = 0; afs_int32 code = 0; - struct cmd_item * itemp; + struct cmd_item *itemp; if (geteuid() != 0) { printf("fstrace must be run as root\n"); exit(1); } - if (as->parms[0].items) { + if (as->parms[0].items) { /* clear logs for the specified sets */ for (itemp = as->parms[0].items; itemp; itemp = itemp->next) { code = icl_ClearSet(itemp->data); if (code) { - (void) fprintf(stderr, "Error in clearing set %s (errno = %d)\n", - itemp->data, errno); + (void)fprintf(stderr, + "Error in clearing set %s (errno = %d)\n", + itemp->data, errno); retVal = code; } } - } else if (as->parms[1].items) { + } else if (as->parms[1].items) { /* clear specified log */ for (itemp = as->parms[0].items; itemp; itemp = itemp->next) { code = icl_ClearLog(itemp->data); if (code) { - (void) fprintf(stderr, "Error in clearing log %s (errno = %d)\n", - itemp->data, errno); + (void)fprintf(stderr, + "Error in clearing log %s (errno = %d)\n", + itemp->data, errno); retVal = code; } } - } - else { + } else { /* clear all logs */ code = icl_ClearAll(); if (code) { - (void) fprintf(stderr, "Error in clearing logs (errno = %d)\n", errno); + (void)fprintf(stderr, "Error in clearing logs (errno = %d)\n", + errno); retVal = code; } } @@ -2899,25 +2956,31 @@ static DoClear(as, arock) return retVal; } -static void SetUpClear() +static void +SetUpClear() { struct cmd_syndesc *clearSyntax; - - clearSyntax = cmd_CreateSyntax("clear", DoClear, (char *)NULL, "clear logs by logname or by event set"); - (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name"); - (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL, "log_name"); + + clearSyntax = + cmd_CreateSyntax("clear", DoClear, (char *)NULL, + "clear logs by logname or by event set"); + (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL, + "set_name"); + (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL, + "log_name"); } -static DoSet(as, arock) - register struct cmd_syndesc *as; - char *arock; +static +DoSet(as, arock) + register struct cmd_syndesc *as; + char *arock; { afs_int32 retVal = 0; afs_int32 code = 0; int op; int doFree = 0; char *operation; - struct cmd_item * itemp; + struct cmd_item *itemp; if (geteuid() != 0) { printf("fstrace must be run as root\n"); @@ -2939,39 +3002,41 @@ static DoSet(as, arock) operation = "active"; } - if (as->parms[0].items) { + if (as->parms[0].items) { /* activate specified sets */ for (itemp = as->parms[0].items; itemp; itemp = itemp->next) { code = icl_ChangeSetState(itemp->data, op); if (code) { - (void) fprintf(stderr, "cannot set state of %s to %s (errno = %d)\n", - itemp->data, operation, errno); + (void)fprintf(stderr, + "cannot set state of %s to %s (errno = %d)\n", + itemp->data, operation, errno); retVal = code; - } - else if (doFree) { + } else if (doFree) { /* try to make it dormant as well */ code = icl_ChangeSetState(itemp->data, ICL_OP_SS_FREE); if (code) { - (void) fprintf(stderr, "cannot set state of %s to dormant (errno = %d)\n", - itemp->data, errno); + (void)fprintf(stderr, + "cannot set state of %s to dormant (errno = %d)\n", + itemp->data, errno); retVal = code; } } } - } - else { + } else { /* show all sets */ code = icl_ChangeAllSetState(op); if (code) { - (void) fprintf(stderr, "cannot set the state of all sets to %s (errno = %d)\n", - operation, errno); + (void)fprintf(stderr, + "cannot set the state of all sets to %s (errno = %d)\n", + operation, errno); retVal = code; - } - else if (doFree) { + } else if (doFree) { /* try to make it dormant as well */ code = icl_ChangeAllSetState(ICL_OP_SS_FREE); if (code) { - (void) fprintf(stderr, "cannot set the state of all sets to dormant (errno = %d)\n", errno); + (void)fprintf(stderr, + "cannot set the state of all sets to dormant (errno = %d)\n", + errno); retVal = code; } } @@ -2980,25 +3045,29 @@ static DoSet(as, arock) return retVal; } -static void SetUpSet() +static void +SetUpSet() { struct cmd_syndesc *setSyntax; - - setSyntax = cmd_CreateSyntax("setset", DoSet, (char *)NULL,"set state of event sets"); - (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name"); - (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL,""); + + setSyntax = + cmd_CreateSyntax("setset", DoSet, (char *)NULL, + "set state of event sets"); + (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name"); + (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL, ""); (void)cmd_AddParm(setSyntax, "-inactive", CMD_FLAG, CMD_OPTIONAL, ""); - (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL,""); + (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL, ""); } -static DoResize(as, arock) - register struct cmd_syndesc *as; - char *arock; +static +DoResize(as, arock) + register struct cmd_syndesc *as; + char *arock; { afs_int32 retVal = 0; afs_int32 code = 0; afs_int32 bufferSize; - struct cmd_item * itemp; + struct cmd_item *itemp; if (geteuid() != 0) { printf("fstrace must be run as root\n"); @@ -3015,8 +3084,9 @@ static DoResize(as, arock) for (; itemp; itemp = itemp->next) { code = icl_ChangeLogSize(itemp->data, bufferSize); if (code) { - (void) fprintf(stderr, "Error in changing log %s buffer size (errno = %d)\n", - itemp->data, errno); + (void)fprintf(stderr, + "Error in changing log %s buffer size (errno = %d)\n", + itemp->data, errno); retVal = code; } } @@ -3024,7 +3094,9 @@ static DoResize(as, arock) /* Use the only current support log, "cmfx" */ code = icl_ChangeLogSize("cmfx", bufferSize); if (code) { - (void) fprintf(stderr, "Error in changing log cmfx buffer size (errno = %d)\n", errno); + (void)fprintf(stderr, + "Error in changing log cmfx buffer size (errno = %d)\n", + errno); retVal = code; } } @@ -3032,20 +3104,25 @@ static DoResize(as, arock) return retVal; } -static void SetUpResize() +static void +SetUpResize() { struct cmd_syndesc *setsizeSyntax; - - setsizeSyntax = cmd_CreateSyntax("setlog", DoResize, (char *)NULL, "set the size of a log"); - (void)cmd_AddParm(setsizeSyntax, "-log", CMD_LIST, CMD_OPTIONAL,"log_name"); - (void)cmd_AddParm(setsizeSyntax, "-buffersize", CMD_SINGLE, CMD_REQUIRED, "1-kilobyte_units"); + + setsizeSyntax = + cmd_CreateSyntax("setlog", DoResize, (char *)NULL, + "set the size of a log"); + (void)cmd_AddParm(setsizeSyntax, "-log", CMD_LIST, CMD_OPTIONAL, + "log_name"); + (void)cmd_AddParm(setsizeSyntax, "-buffersize", CMD_SINGLE, CMD_REQUIRED, + "1-kilobyte_units"); } #include "AFS_component_version_number.c" main(argc, argv) - IN int argc; - IN char *argv[]; + IN int argc; + IN char *argv[]; { setlocale(LC_ALL, ""); #ifdef AFS_SGI62_ENV @@ -3060,14 +3137,13 @@ main(argc, argv) SetUpSet(); SetUpResize(); - return(cmd_Dispatch(argc, argv)); + return (cmd_Dispatch(argc, argv)); } #else #include "AFS_component_version_number.c" -main() { - printf("fstrace is NOT supported for this OS\n"); +main() +{ + printf("fstrace is NOT supported for this OS\n"); } #endif - - diff --git a/src/venus/gcpags.c b/src/venus/gcpags.c index c19bcbf9a..e0c754bbf 100644 --- a/src/venus/gcpags.c +++ b/src/venus/gcpags.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/gcpags.c,v 1.1.1.4 2001/07/14 22:24:36 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/gcpags.c,v 1.5 2003/07/15 23:17:22 shadow Exp $"); #include #include @@ -41,17 +42,18 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/gcpags.c,v 1.1.1.4 2001/07/14 22: #include "AFS_component_version_number.c" main(argc, argv) -int argc; -char **argv; { - afs_int32 code=0; + int argc; + char **argv; +{ + afs_int32 code = 0; struct ViceIoctl blob; - + blob.in = 0; blob.out = 0; blob.in_size = 0; blob.out_size = 0; code = pioctl(0, VIOC_GCPAGS, &blob, 1); - if(code) + if (code) perror("disable gcpags failed"); exit(code); diff --git a/src/venus/kdump.c b/src/venus/kdump.c index a02a4577f..a028f8bfc 100644 --- a/src/venus/kdump.c +++ b/src/venus/kdump.c @@ -10,16 +10,21 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/kdump.c,v 1.8 2003/07/30 17:23:46 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/kdump.c,v 1.32 2004/05/11 19:52:28 shadow Exp $"); #include #include -#include /* for malloc() */ +#include /* for malloc() */ +/* Here be hacks. */ #ifdef AFS_LINUX24_ENV #define __KERNEL__ #include #define _STRING_H 1 +#define _SYS_STATFS_H 1 +#define _BITS_SIGCONTEXT_H 1 +#undef USE_UCONTEXT #endif #include @@ -36,17 +41,31 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/kdump.c,v 1.8 2003/07/30 17:23:46 #define _LINUX_CODA_FS_I #define _LINUX_NTFS_FS_SB_H #define _LINUX_NTFS_FS_I_H -struct sysv_sb_info {}; -struct affs_sb_info {}; -struct ufs_sb_info {}; -struct nfs_sb_info {}; -struct nfs_inode_info {}; -struct sysv_inode_info {}; -struct coda_inode_info{}; -struct affs_inode_info {}; -struct nfs_lock_info {}; -struct ntfs_sb_info{}; -struct ntfs_inode_info{}; +#define _NCP_FS_SB +struct sysv_sb_info { +}; +struct affs_sb_info { +}; +struct ufs_sb_info { +}; +struct nfs_sb_info { +}; +struct nfs_inode_info { +}; +struct sysv_inode_info { +}; +struct coda_inode_info { +}; +struct affs_inode_info { +}; +struct nfs_lock_info { +}; +struct ntfs_sb_info { +}; +struct ntfs_inode_info { +}; +struct ncp_sb_info { +}; #include #define u32 unsigned int #define s32 int @@ -134,16 +153,16 @@ struct ntfs_inode_info{}; #undef _KERNEL #endif -#ifdef AFS_SUN5_ENV /*XXXXX*/ +#ifdef AFS_SUN5_ENV /*XXXXX*/ #include struct vnode foo; #ifdef AFS_SUN54_ENV #else #ifdef AFS_SUN52_ENV -typedef struct stat_mutex stat_mutex_t; +typedef struct stat_mutex stat_mutex_t; #define kmutex_t stat_mutex_t #else -typedef struct adaptive_mutex2 adaptive_mutex2_t; +typedef struct adaptive_mutex2 adaptive_mutex2_t; #define kmutex_t adaptive_mutex2_t #endif #endif @@ -197,11 +216,11 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t; #include /* inet_ntoa() */ #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) -#ifdef AFS_SGI_ENV +#ifdef AFS_SGI_ENV #include #endif /* AFS_SGI_ENV */ #else -#ifdef AFS_MACH_ENV +#ifdef AFS_MACH_ENV #include #include #include @@ -209,13 +228,13 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t; #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) #include #include -#include +#include #include -#include +#include #else #include "sys/vfs.h" #ifdef AFS_LINUX20_ENV -#define UIO_MAXIOV 1 /* don't care */ +#define UIO_MAXIOV 1 /* don't care */ #if __GLIBC_MINOR__ == 0 #include #endif @@ -247,16 +266,14 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t; #endif /* AFS_SPARC64_LINUX20_ENV */ #endif /* AFS_S390_LINUX20_ENV */ struct timezone { - int a,b; + int a, b; }; -#if 0/*ndef AFS_ALPHA_LINUX20_ENV*/ -#ifndef AFS_LINUX24_ENV +#if 0 /*ndef AFS_ALPHA_LINUX20_ENV */ typedef struct timeval { int tv_sec; int tv_usec; -} timeval_t; /* Needed here since KERNEL defined. */ -#endif -#endif /*AFS_ALPHA_LINUX20_ENV*/ +} timeval_t; /* Needed here since KERNEL defined. */ +#endif /*AFS_ALPHA_LINUX20_ENV */ #if defined(AFSBIG_ENDIAN) #define _LINUX_BYTEORDER_BIG_ENDIAN_H #else @@ -276,23 +293,23 @@ typedef struct timeval { #endif #else /* AFS_LINUX20_ENV */ #ifdef AFS_HPUX110_ENV -#define KERNEL -#define _KERNEL 1 +#define KERNEL +#define _KERNEL 1 /* Declare following so sys/vnode.h will compile with KERNEL defined */ #define FILE FILe -typedef enum _spustate { /* FROM /etc/conf/h/_types.h */ - SPUSTATE_NONE = 0, /* must be 0 for proper initialization */ - SPUSTATE_IDLE, /* spu is idle */ - SPUSTATE_USER, /* spu is in user mode */ - SPUSTATE_SYSTEM, /* spu is in system mode */ - SPUSTATE_UNKNOWN, /* utility code for NEW_INTERVAL() */ - SPUSTATE_NOCHANGE /* utility code for NEW_INTERVAL() */ +typedef enum _spustate { /* FROM /etc/conf/h/_types.h */ + SPUSTATE_NONE = 0, /* must be 0 for proper initialization */ + SPUSTATE_IDLE, /* spu is idle */ + SPUSTATE_USER, /* spu is in user mode */ + SPUSTATE_SYSTEM, /* spu is in system mode */ + SPUSTATE_UNKNOWN, /* utility code for NEW_INTERVAL() */ + SPUSTATE_NOCHANGE /* utility code for NEW_INTERVAL() */ } spustate_t; #define k_off_t off_t #include "sys/vnode.h" #undef KERNEL #undef _KERNEL -#else /* AFS_HPUX110_ENV */ +#else /* AFS_HPUX110_ENV */ #include "sys/vnode.h" #endif /* else AFS_HPUX110_ENV */ #endif /* else AFS_LINUX20_ENV */ @@ -343,8 +360,8 @@ typedef kcondvar_t afs_kcondvar_t; #ifdef AFS_DUX40_ENV #define RX_ENABLE_LOCKS typedef struct { - unsigned long lock; - void *owner; + unsigned long lock; + void *owner; } afs_kmutex_t; typedef int afs_kcondvar_t; #endif /* AFS_DUX40_ENV */ @@ -352,16 +369,16 @@ typedef int afs_kcondvar_t; #ifdef AFS_HPUX110_ENV #define RX_ENABLE_LOCKS typedef struct { - void *s_lock; - int count; - long sa_fill1; - void *wait_list; - void *sa_fill2[2]; - int sa_fill2b[2]; - long sa_fill2c[3]; - int sa_fill2d[16]; - int order; - int sa_fill3; + void *s_lock; + int count; + long sa_fill1; + void *wait_list; + void *sa_fill2[2]; + int sa_fill2b[2]; + long sa_fill2c[3]; + int sa_fill2d[16]; + int order; + int sa_fill3; } afs_kmutex_t; typedef char *afs_kcondvar_t; #endif /* AFS_HPUX110_ENV */ @@ -389,13 +406,12 @@ typedef void *afs_kcondvar_t; #endif /* AFS_LINUX20_ENV */ #include -#include /*#include "afs/osi.h"*/ typedef struct { int tv_sec; int tv_usec; -} osi_timeval_t; /* Needed here since KERNEL defined. */ +} osi_timeval_t; /* Needed here since KERNEL defined. */ /*#include "afs/volerrors.h"*/ #ifdef AFS_LINUX20_ENV @@ -403,8 +419,8 @@ typedef struct { #endif #include -#include "../vlserver/vldbint.h" -#include "../afs/lock.h" +#include "vlserver/vldbint.h" +#include "afs/lock.h" #define KERNEL @@ -424,9 +440,10 @@ extern off64_t lseek64(); #define KDUMP_SIZE_T int #endif /* AFS_SGI61_ENV */ -#include "../afs/afs.h" /* XXXX Getting it from the obj tree XXX */ -#include "../afs/afs_axscache.h" /* XXXX Getting it from the obj tree XXX */ +#include "afs/afs.h" /* XXXX Getting it from the obj tree XXX */ +#include "afs/afs_axscache.h" /* XXXX Getting it from the obj tree XXX */ #include +#include #include #include @@ -457,9 +474,9 @@ extern off64_t lseek64(); #else #define UNIX "/vmunix" #endif -#endif /* AFS_HPUX_ENV */ -#endif /* AFS_HPUX100_ENV */ -#endif /* AFS_SGI_ENV */ +#endif /* AFS_HPUX_ENV */ +#endif /* AFS_HPUX100_ENV */ +#endif /* AFS_SGI_ENV */ #if defined(AFS_SUN5_ENV) #define CORE "/dev/mem" @@ -476,7 +493,7 @@ void print_DdcnextTbl(); void print_DindexFlags(); void print_buffers(); void print_allocs(); -void kread(int kmem,off_t loc,void *buf,KDUMP_SIZE_T len); +void kread(int kmem, off_t loc, void *buf, KDUMP_SIZE_T len); void print_exporter(); void print_nfsclient(); void print_unixuser(); @@ -521,35 +538,10 @@ extern struct cmd_syndesc *cmd_CreateSyntax(); #endif int opencore(); -/* Note: this should agree with the definition in afs_buffer.c */ -#if defined(AFS_OSF_ENV) -#define AFS_USEBUFFERS 1 -#endif - -struct buffer { -#ifdef AFS_SGI62_ENV - ino64_t fid[1]; -#else - afs_int32 fid[1]; -#endif - afs_int32 page; - afs_int32 accesstime; - struct buffer *hashNext; - char *data; - char lockers; - char b_dirty; - char hashIndex; -#if AFS_USEBUFFERS - struct buf *bufp; -#endif - afs_rwlock_t lock; /* the lock for this structure */ -}; - - #if defined(AFS_HPUX_ENV) && defined(__LP64__) #define afs_nlist nlist64 #define AFSNLIST(N, C) nlist64((N), (C)) -#else /* defined(AFS_HPUX_ENV) && defined(__LP64__) */ +#else /* defined(AFS_HPUX_ENV) && defined(__LP64__) */ #ifdef AFS_SGI61_ENV #ifdef AFS_32BIT_KERNEL_ENV #define afs_nlist nlist @@ -569,16 +561,20 @@ struct afs_nlist { #endif /* AFS_LINUX20_ENV */ #define AFSNLIST(N, C) nlist((N), (C)) #endif /* AFS_SGI61_ENV */ -#endif /* defined(AFS_HPUX_ENV) && defined(__LP64__) */ +#endif /* defined(AFS_HPUX_ENV) && defined(__LP64__) */ char *obj = UNIX, *core = CORE; int kmem; -int Dcells = 0, Dusers = 0, Dservers = 0, Dconns = 0, Dvols = 0, Ddvols = 0, mem = 0; -int Dvstats = 0, Ddstats = 0, Dnfs = 0, Dglobals = 0, Dstats = 0, Dlocks = 0, Dall = 1; -int Dindextimes = 0, Dindexflags = 0, Dvnodes = 0, Dbuffers=0, DCallbacks = 0, Dallocs=0, UserLevel=0; +int Dcells = 0, Dusers = 0, Dservers = 0, Dconns = 0, Dvols = 0, Ddvols = + 0, mem = 0; +int Dvstats = 0, Ddstats = 0, Dnfs = 0, Dglobals = 0, Dstats = 0, Dlocks = + 0, Dall = 1; +int Dindextimes = 0, Dindexflags = 0, Dvnodes = 0, Dbuffers = 0, DCallbacks = + 0, Dallocs = 0, UserLevel = 0; int DdvnextTbl = 0, DdcnextTbl = 0; -int Nconns = 0, Drxstats = 0, Drx = 0, Dbkg=0, Dvlru=0, Ddlru=0, Dcallout=0; +int Nconns = 0, Drxstats = 0, Drx = 0, Dbkg = 0, Dvlru = 0, Ddlru = + 0, Dcallout = 0; int Ddnlc = 0; int Dgcpags = 0; @@ -590,36 +586,37 @@ int Dgcpags = 0; #include #include #ifndef AFS_SUN54_ENV -typedef ulong_t k_fltset_t; /* XXXXXXXXXXX */ -#endif /* !AFS_SUN54_ENV */ +typedef ulong_t k_fltset_t; /* XXXXXXXXXXX */ +#endif /* !AFS_SUN54_ENV */ #include #include -#define _NLIST_H /* XXXXXXXXXXXXX */ +#define _NLIST_H /* XXXXXXXXXXXXX */ #include kvm_t *kd; -#endif /* defined(AFS_SUN5_ENV) */ +#endif /* defined(AFS_SUN5_ENV) */ /* Pretty Printers - print real IP addresses and the like if running * in interpret_mode. */ int pretty = 1; -char *PrintIPAddr(int addr) +char * +PrintIPAddr(int addr) { static char str[32]; struct in_addr in_addr; if (pretty) { - if (addr == 1) { - strcpy(str, "local"); - } else { - in_addr.s_addr = addr; - (void) strcpy(str, inet_ntoa(in_addr)); - } + if (addr == 1) { + strcpy(str, "local"); + } else { + in_addr.s_addr = addr; + (void)strcpy(str, inet_ntoa(in_addr)); + } } else { - (void) sprintf(str, "%x", addr); + (void)sprintf(str, "%x", addr); } - return (char*)str; + return (char *)str; } #ifdef AFS_LINUX20_ENV @@ -647,15 +644,17 @@ int availksyms = 0; #define MAXLINE 1024 -int compare_strings(const void *a, const void *b) +int +compare_strings(const void *a, const void *b) { - symlist_t *syma = (symlist_t*)a; - symlist_t *symb = (symlist_t*)b; + symlist_t *syma = (symlist_t *) a; + symlist_t *symb = (symlist_t *) b; return strcmp(syma->s_name, symb->s_name); } /* Read in all the kernel symbols */ -void read_ksyms(void) +void +read_ksyms(void) { FILE *fp; char line[MAXLINE]; @@ -671,7 +670,7 @@ void read_ksyms(void) } availksyms = KSYM_ALLOC_BASE; - ksyms = (symlist_t*)malloc(availksyms * sizeof(symlist_t)); + ksyms = (symlist_t *) malloc(availksyms * sizeof(symlist_t)); if (!ksyms) { printf("Can't malloc %d elements for symbol list.\n", availksyms); exit(1); @@ -681,7 +680,8 @@ void read_ksyms(void) while (fgets(line, MAXLINE, fp)) { if (nksyms >= availksyms) { availksyms += KSYM_ALLOC_STEP; - ksyms = (symlist_t*)realloc(ksyms, availksyms * sizeof(symlist_t)); + ksyms = + (symlist_t *) realloc(ksyms, availksyms * sizeof(symlist_t)); if (!ksyms) { printf("Failed to realloc %d symbols.\n", availksyms); exit(1); @@ -690,23 +690,25 @@ void read_ksyms(void) ksyms[nksyms].s_value = (int)strtoul(line, &p, 16); p++; q = strchr(p, '\t'); - if (q) *q = '\0'; + if (q) + *q = '\0'; if (strlen(p) >= MAXLINE) { printf("Symbol '%s' too long, ignoring it.\n", p); continue; } - (void) strcpy(ksyms[nksyms].s_name, p); + (void)strcpy(ksyms[nksyms].s_name, p); nksyms++; } /* Sort them in lexical order */ qsort(ksyms, nksyms, sizeof(symlist_t), compare_strings); -} +} /* find_symbol returns 0 if not found, otherwise value for symbol */ -int find_symbol(char *name) +int +find_symbol(char *name) { symlist_t *tmp; symlist_t entry; @@ -714,17 +716,19 @@ int find_symbol(char *name) if (!ksyms) read_ksyms(); - (void) strcpy(entry.s_name, name); - tmp = (symlist_t*)bsearch(&entry, ksyms, nksyms, sizeof(symlist_t), + (void)strcpy(entry.s_name, name); + tmp = + (symlist_t *) bsearch(&entry, ksyms, nksyms, sizeof(symlist_t), compare_strings); return tmp ? tmp->s_value : 0; } /* nlist fills in values in list until a null name is found. */ -int nlist(void *notused, struct afs_nlist *nlp) +int +nlist(void *notused, struct afs_nlist *nlp) { - for ( ; nlp->n_name && *nlp->n_name; nlp++) + for (; nlp->n_name && *nlp->n_name; nlp++) nlp->n_value = find_symbol(nlp->n_name); return 0; @@ -734,21 +738,23 @@ int nlist(void *notused, struct afs_nlist *nlp) #if defined(AFS_SUN5_ENV) #ifdef _LP64 -Elf64_Sym *tbl; +Elf64_Sym *tbl; #else -Elf32_Sym *tbl; /* symbol tbl */ +Elf32_Sym *tbl; /* symbol tbl */ #endif -char *tblp; /* ptr to symbol tbl */ +char *tblp; /* ptr to symbol tbl */ int scnt = 0; #ifdef _LP64 -Elf64_Sym *symsrch(s) - char *s; +Elf64_Sym * +symsrch(s) + char *s; { Elf64_Sym *sp; #else -Elf32_Sym *symsrch(s) - char *s; +Elf32_Sym * +symsrch(s) + char *s; { Elf32_Sym *sp; #endif /** _LP64 **/ @@ -761,122 +767,125 @@ Elf32_Sym *symsrch(s) #else type = ELF32_ST_TYPE(sp->st_info); #endif /** _LP64 **/ - if (((type == STB_LOCAL) || (type == STB_GLOBAL) || - (type == STB_WEAK)) && ((afs_uint32)sp->st_value >= 0x10000)) { + if (((type == STB_LOCAL) || (type == STB_GLOBAL) + || (type == STB_WEAK)) + && ((afs_uint32) sp->st_value >= 0x10000)) { name = tblp + sp->st_name; - if (!strcmp(name, s)) + if (!strcmp(name, s)) return (sp); } } return (0); } -#endif /*defined(AFS_SUN5_ENV)*/ +#endif /*defined(AFS_SUN5_ENV) */ #ifndef AFS_KDUMP_LIB -static cmdproc(as, arock) -register struct cmd_syndesc *as; -afs_int32 arock; { +static +cmdproc(as, arock) + register struct cmd_syndesc *as; + afs_int32 arock; +{ register afs_int32 code = 0; - if (as->parms[0].items) { /* -kobj */ + if (as->parms[0].items) { /* -kobj */ obj = as->parms[0].items->data; - } - if (as->parms[1].items) { /* -kcore */ + } + if (as->parms[1].items) { /* -kcore */ core = as->parms[1].items->data; - } - if (as->parms[2].items) { /* -cells */ + } + if (as->parms[2].items) { /* -cells */ Dcells = 1, Dall = 0; - } - if (as->parms[3].items) { /* -users */ + } + if (as->parms[3].items) { /* -users */ Dusers = 1, Dall = 0; - } - if (as->parms[4].items) { /* -servers */ + } + if (as->parms[4].items) { /* -servers */ Dservers = 1, Dall = 0; - } - if (as->parms[5].items) { /* -conns */ + } + if (as->parms[5].items) { /* -conns */ Dconns = 1, Dall = 0; - } - if (as->parms[6].items) { /* -volumes */ + } + if (as->parms[6].items) { /* -volumes */ Dvols = 1, Dall = 0; - } - if (as->parms[7].items) { /* -dvolumes */ + } + if (as->parms[7].items) { /* -dvolumes */ Ddvols = 1, Dall = 0; - } - if (as->parms[8].items) { /* -vstats */ + } + if (as->parms[8].items) { /* -vstats */ Dvstats = 1, Dall = 0; - } - if (as->parms[9].items) { /* -dstats */ + } + if (as->parms[9].items) { /* -dstats */ Ddstats = 1, Dall = 0; - } - if (as->parms[10].items) { /* -nfstats */ + } + if (as->parms[10].items) { /* -nfstats */ Dnfs = 1, Dall = 0; - } - if (as->parms[11].items) { /* -globals */ + } + if (as->parms[11].items) { /* -globals */ Dglobals = 1, Dall = 0; - } - if (as->parms[12].items) { /* -stats */ + } + if (as->parms[12].items) { /* -stats */ Dstats = 1, Dall = 0; - } - if (as->parms[13].items) { /* -locks */ + } + if (as->parms[13].items) { /* -locks */ Dlocks = 1, Dall = 0; - } - if (as->parms[14].items) { /* -mem */ + } + if (as->parms[14].items) { /* -mem */ mem = 1; - } - if (as->parms[15].items) { /* -rxstats */ + } + if (as->parms[15].items) { /* -rxstats */ Drxstats = 1, Dall = 0; - } - if (as->parms[16].items) { /* -rx */ + } + if (as->parms[16].items) { /* -rx */ Drx = 1, Dall = 0; - } - if (as->parms[17].items) { /* -timestable */ + } + if (as->parms[17].items) { /* -timestable */ Dindextimes = 1, Dall = 0; - } - if (as->parms[18].items) { /* -flagstable */ + } + if (as->parms[18].items) { /* -flagstable */ Dindexflags = 1, Dall = 0; - } - if (as->parms[19].items) { /* -cbhash */ + } + if (as->parms[19].items) { /* -cbhash */ DCallbacks = 1, Dall = 0; - } - if (as->parms[20].items) { /* -vnodes */ + } + if (as->parms[20].items) { /* -vnodes */ Dvnodes = 1, Dall = 0; - } - if (as->parms[21].items) { /* -buffers */ + } + if (as->parms[21].items) { /* -buffers */ Dbuffers = 1, Dall = 0; - } - if (as->parms[22].items) { /* -allocedmem */ + } + if (as->parms[22].items) { /* -allocedmem */ Dallocs = 1, Dall = 0; - } - if (as->parms[23].items) { /* -user */ + } + if (as->parms[23].items) { /* -user */ UserLevel = 1; - } - if (as->parms[24].items) { /* -bkg */ + } + if (as->parms[24].items) { /* -bkg */ Dbkg = 1, Dall = 0; - } - if (as->parms[25].items) { /* -vlru */ + } + if (as->parms[25].items) { /* -vlru */ Dvlru = 1, Dall = 0; - } - if (as->parms[26].items) { /* -callout */ + } + if (as->parms[26].items) { /* -callout */ Dcallout = 1, Dall = 0; - } - if (as->parms[27].items) { /* -dnlc */ + } + if (as->parms[27].items) { /* -dnlc */ Ddnlc = 1, Dall = 0; - } - if (as->parms[28].items) { /* -dlru */ + } + if (as->parms[28].items) { /* -dlru */ Ddlru = 1, Dall = 0; } - if (as->parms[29].items) { /* -raw */ + if (as->parms[29].items) { /* -raw */ pretty = 0; } - if (as->parms[30].items) { /* -gcpags */ + if (as->parms[30].items) { /* -gcpags */ Dgcpags = 1, Dall = 0; } - if (as->parms[31].items) { /* -dhash */ + if (as->parms[31].items) { /* -dhash */ DdvnextTbl = 1, DdcnextTbl = 1, Dall = 0; } @@ -887,55 +896,76 @@ afs_int32 arock; { #include "AFS_component_version_number.c" main(argc, argv) -int argc; -char **argv; { + int argc; + char **argv; +{ register struct cmd_syndesc *ts; register afs_int32 code; #ifdef AFS_AIX32_ENV struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGSEGV, &nsa, NULL); #endif - ts = cmd_CreateSyntax((char *) 0, cmdproc, 0, "Read internal cache manager structs"); - cmd_AddParm(ts, "-kobj", CMD_SINGLE, CMD_OPTIONAL, "kernel object (default /vmunix)"); - cmd_AddParm(ts, "-kcore", CMD_SINGLE, CMD_OPTIONAL, "kernel core image (default /dev/kmem)"); + ts = cmd_CreateSyntax(NULL, cmdproc, 0, + "Read internal cache manager structs"); + cmd_AddParm(ts, "-kobj", CMD_SINGLE, CMD_OPTIONAL, + "kernel object (default /vmunix)"); + cmd_AddParm(ts, "-kcore", CMD_SINGLE, CMD_OPTIONAL, + "kernel core image (default /dev/kmem)"); cmd_AddParm(ts, "-cells", CMD_FLAG, CMD_OPTIONAL, "cell state"); cmd_AddParm(ts, "-users", CMD_FLAG, CMD_OPTIONAL, "users state"); cmd_AddParm(ts, "-servers", CMD_FLAG, CMD_OPTIONAL, "servers state"); cmd_AddParm(ts, "-conns", CMD_FLAG, CMD_OPTIONAL, "conns state"); - cmd_AddParm(ts, "-volumes", CMD_FLAG, CMD_OPTIONAL, "incore volume state"); + cmd_AddParm(ts, "-volumes", CMD_FLAG, CMD_OPTIONAL, + "incore volume state"); cmd_AddParm(ts, "-dvolumes", CMD_FLAG, CMD_OPTIONAL, "disk volume state"); cmd_AddParm(ts, "-vstats", CMD_FLAG, CMD_OPTIONAL, "stat file state"); cmd_AddParm(ts, "-dstats", CMD_FLAG, CMD_OPTIONAL, "file data state"); - cmd_AddParm(ts, "-nfstats", CMD_FLAG, CMD_OPTIONAL, "nfs translator state"); - cmd_AddParm(ts, "-globals", CMD_FLAG, CMD_OPTIONAL, "general global state"); - cmd_AddParm(ts, "-stats", CMD_FLAG, CMD_OPTIONAL, "general cm performance state"); - cmd_AddParm(ts, "-locks", CMD_FLAG, CMD_OPTIONAL, "global cm related locks state"); - cmd_AddParm(ts, "-mem", CMD_FLAG, CMD_OPTIONAL, "core represents the physical mem (i.e. /dev/mem) and not virtual"); - cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, "general rx statistics"); + cmd_AddParm(ts, "-nfstats", CMD_FLAG, CMD_OPTIONAL, + "nfs translator state"); + cmd_AddParm(ts, "-globals", CMD_FLAG, CMD_OPTIONAL, + "general global state"); + cmd_AddParm(ts, "-stats", CMD_FLAG, CMD_OPTIONAL, + "general cm performance state"); + cmd_AddParm(ts, "-locks", CMD_FLAG, CMD_OPTIONAL, + "global cm related locks state"); + cmd_AddParm(ts, "-mem", CMD_FLAG, CMD_OPTIONAL, + "core represents the physical mem (i.e. /dev/mem) and not virtual"); + cmd_AddParm(ts, "-rxstats", CMD_FLAG, CMD_OPTIONAL, + "general rx statistics"); cmd_AddParm(ts, "-rx", CMD_FLAG, CMD_OPTIONAL, "all info about rx"); - cmd_AddParm(ts, "-timestable", CMD_FLAG, CMD_OPTIONAL, "dcache LRU info table"); - cmd_AddParm(ts, "-flagstable", CMD_FLAG, CMD_OPTIONAL, "dcache flags info table"); - cmd_AddParm(ts, "-cbhash", CMD_FLAG, CMD_OPTIONAL, "vcache hashed by cbExpires"); + cmd_AddParm(ts, "-timestable", CMD_FLAG, CMD_OPTIONAL, + "dcache LRU info table"); + cmd_AddParm(ts, "-flagstable", CMD_FLAG, CMD_OPTIONAL, + "dcache flags info table"); + cmd_AddParm(ts, "-cbhash", CMD_FLAG, CMD_OPTIONAL, + "vcache hashed by cbExpires"); cmd_AddParm(ts, "-vnodes", CMD_FLAG, CMD_OPTIONAL, "afs vnodes"); - cmd_AddParm(ts, "-buffers", CMD_FLAG, CMD_OPTIONAL, "afs dir buffer cache"); - cmd_AddParm(ts, "-allocedmem", CMD_FLAG, CMD_OPTIONAL, "allocated memory"); - cmd_AddParm(ts, "-user", CMD_FLAG, CMD_OPTIONAL, "core is from a user-level program"); + cmd_AddParm(ts, "-buffers", CMD_FLAG, CMD_OPTIONAL, + "afs dir buffer cache"); + cmd_AddParm(ts, "-allocedmem", CMD_FLAG, CMD_OPTIONAL, + "allocated memory"); + cmd_AddParm(ts, "-user", CMD_FLAG, CMD_OPTIONAL, + "core is from a user-level program"); cmd_AddParm(ts, "-bkg", CMD_FLAG, CMD_OPTIONAL, "background daemon info"); cmd_AddParm(ts, "-vlru", CMD_FLAG, CMD_OPTIONAL, "vcache lru list"); - cmd_AddParm(ts, "-callout", CMD_FLAG, CMD_OPTIONAL, "callout info (aix only)"); - cmd_AddParm(ts, "-dnlc", CMD_FLAG, CMD_OPTIONAL, "DNLC table,freelist,trace"); + cmd_AddParm(ts, "-callout", CMD_FLAG, CMD_OPTIONAL, + "callout info (aix only)"); + cmd_AddParm(ts, "-dnlc", CMD_FLAG, CMD_OPTIONAL, + "DNLC table,freelist,trace"); cmd_AddParm(ts, "-dlru", CMD_FLAG, CMD_OPTIONAL, "dcache lru list"); cmd_AddParm(ts, "-raw", CMD_FLAG, CMD_OPTIONAL, "show raw values"); - cmd_AddParm(ts, "-gcpags", CMD_FLAG, CMD_OPTIONAL, "PAG garbage collection info"); - cmd_AddParm(ts, "-dhash", CMD_FLAG, CMD_OPTIONAL, "show dcache hash chains"); + cmd_AddParm(ts, "-gcpags", CMD_FLAG, CMD_OPTIONAL, + "PAG garbage collection info"); + cmd_AddParm(ts, "-dhash", CMD_FLAG, CMD_OPTIONAL, + "show dcache hash chains"); code = cmd_Dispatch(argc, argv); return code; @@ -944,9 +974,9 @@ char **argv; { #ifdef AFS_AIX_ENV #ifndef AFS_KDUMP_LIB -Knlist(sp, cnt, size) -struct afs_nlist *sp; -int cnt, size; +Knlist(sp, cnt, size) + struct afs_nlist *sp; + int cnt, size; { register int code; @@ -961,68 +991,66 @@ int cnt, size; #if !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) int -findsym( char *sname, off_t *offset ) +findsym(char *sname, off_t * offset) { #if defined(AFS_SUN5_ENV) #ifdef _LP64 - Elf64_Sym *ss_ans; + Elf64_Sym *ss_ans; #else - Elf32_Sym *ss_ans; + Elf32_Sym *ss_ans; #endif - ss_ans = symsrch(sname); - if (!ss_ans) { - printf("(WARNING) Couldn't find %s in %s. Proceeding..\n", - sname, obj); + ss_ans = symsrch(sname); + if (!ss_ans) { + printf("(WARNING) Couldn't find %s in %s. Proceeding..\n", sname, + obj); + *offset = 0; + return 0; + } + *offset = ss_ans->st_value; + return 1; +#else /* defined(AFS_SUN5_ENV) */ +#if defined(AFS_AIX_ENV) + if (!UserLevel) { + struct afs_nlist nl; + nl.n_name = sname; + if (Knlist(&nl, 1, sizeof nl) == -1) { + printf("(WARNING) knlist: couldn't find %s. Proceeding...", + sname); *offset = 0; return 0; } - *offset = ss_ans->st_value; + *offset = nl.n_value; return 1; -#else /* defined(AFS_SUN5_ENV) */ -#if defined(AFS_AIX_ENV) - if (!UserLevel) { - struct afs_nlist nl; - nl.n_name = sname; - if (Knlist(&nl, 1, sizeof nl) == -1 ) { - printf("(WARNING) knlist: couldn't find %s. Proceeding...", - sname); - *offset = 0; - return 0; - } - *offset = nl.n_value; - return 1; - } -#endif /* defined(AFS_AIX_ENV) */ - { - struct afs_nlist request[2]; - - memset(request, 0, sizeof request); - request[0].n_name = sname; - if (AFSNLIST(obj, request) < 0) { - fprintf(stderr, "nlist(%s, %s) failure: %d (%s)\n", - obj, sname, - errno, strerror(errno)); - exit(1); - } + } +#endif /* defined(AFS_AIX_ENV) */ + { + struct afs_nlist request[2]; + memset(request, 0, sizeof request); + request[0].n_name = sname; + if (AFSNLIST(obj, request) < 0) { + fprintf(stderr, "nlist(%s, %s) failure: %d (%s)\n", obj, sname, + errno, strerror(errno)); + exit(1); + } #if defined(AFS_OSF_ENV) - if (mem) { - long X; + if (mem) { + long X; - X = coreadj(request[0].n_value); - request[0].n_value = X; - } -#endif /* defined(AFS_OSF_ENV) */ + X = coreadj(request[0].n_value); + request[0].n_value = X; + } +#endif /* defined(AFS_OSF_ENV) */ - *offset = request[0].n_value; - if (!request[0].n_value) { - printf("(WARNING) Couldn't find %s in %s. Proceeding..\n", - sname, obj); - return 0; - } - return 1; + *offset = request[0].n_value; + if (!request[0].n_value) { + printf("(WARNING) Couldn't find %s in %s. Proceeding..\n", sname, + obj); + return 0; } -#endif /* defined(AFS_SUN5_ENV) */ + return 1; + } +#endif /* defined(AFS_SUN5_ENV) */ } #endif @@ -1032,7 +1060,7 @@ kdump() { int cell, cnt, cnt1; #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) - printf("Kdump not supported\n"); + printf("Kdump not supported\n"); #else #ifndef AFS_KDUMP_LIB @@ -1044,7 +1072,7 @@ kdump() /* Test to see if kernel is using RX_ENABLE_LOCKS in rx structs. */ #ifdef AFS_SGI53_ENV #ifdef AFS_SGI64_ENV - use_rx_lock = 1; /* Always using fine gain locking. */ + use_rx_lock = 1; /* Always using fine gain locking. */ #else use_rx_lock = (sysmp(MP_NPROCS) > 1) ? 1 : 0; #endif @@ -1052,21 +1080,21 @@ kdump() #endif /* KDUMP_RX_LOCK */ if (Dcells || Dall) { - print_cells(1); /* Handle the afs_cells structures */ + print_cells(1); /* Handle the afs_cells structures */ print_cellaliases(1); print_cellnames(1); } if (Dusers || Dall) { - print_users(1); /* Handle the afs_users structs */ - } + print_users(1); /* Handle the afs_users structs */ + } if (Dservers || Dall) { - print_servers(1);/* Handle the afs_servers structs */ + print_servers(1); /* Handle the afs_servers structs */ } if (Dconns) { - print_Conns(1); /* Handle the afs_servers structs */ + print_Conns(1); /* Handle the afs_servers structs */ } if (Dvols || Dall) { @@ -1074,11 +1102,12 @@ kdump() } if (Ddvols || Dall) { - printf("\n\nIGNORE reading the 'volumeinfo' file for now (NOT IMPORTANT)!\n"); + printf + ("\n\nIGNORE reading the 'volumeinfo' file for now (NOT IMPORTANT)!\n"); } if (DCallbacks || Dall) { - print_cbHash(1); /* Handle the cbHashT table of queued vcaches */ + print_cbHash(1); /* Handle the cbHashT table of queued vcaches */ } if (Dvstats || Dall || Dvnodes) { @@ -1090,19 +1119,19 @@ kdump() } if (Dindextimes || Dall) { - print_DindexTimes(1); + print_DindexTimes(1); } if (Dindexflags || Dall) { - print_DindexFlags(1); + print_DindexFlags(1); } if (DdvnextTbl || Dall) { - print_DdvnextTbl(1); + print_DdvnextTbl(1); } if (DdcnextTbl || Dall) { - print_DdcnextTbl(1); + print_DdcnextTbl(1); } if (Dbuffers || Dall) { @@ -1119,12 +1148,12 @@ kdump() struct afs_stats_CMPerf afs_cmperfstats; printf("\n\nPrinting count references to cm-related functions..\n\n"); - findsym( "afs_cmstats", &symoff); - kread(kmem, symoff, (char *) &afs_cmstats, sizeof afs_cmstats); + findsym("afs_cmstats", &symoff); + kread(kmem, symoff, (char *)&afs_cmstats, sizeof afs_cmstats); print_cmstats(&afs_cmstats); printf("\n\nPrinting some cm struct performance stats..\n\n"); - findsym( "afs_stats_cmperf", &symoff); - kread(kmem, symoff, (char *) &afs_cmperfstats, sizeof afs_cmperfstats); + findsym("afs_stats_cmperf", &symoff); + kread(kmem, symoff, (char *)&afs_cmperfstats, sizeof afs_cmperfstats); print_cmperfstats(&afs_cmperfstats); } @@ -1147,7 +1176,7 @@ kdump() } if (Drxstats || Dall) { print_rxstats(kmem); - } + } if (Drx || Dall) { print_rx(kmem); } @@ -1157,10 +1186,10 @@ kdump() } #endif if (Dcallout || Dall) { - print_callout(kmem); + print_callout(kmem); } if (Ddnlc || Dall) { - print_dnlc(kmem); + print_dnlc(kmem); } if (Dgcpags || Dall) { print_gcpags(1); @@ -1170,110 +1199,124 @@ kdump() } #if !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) -int Sum_cellnames=0, Sum_userstp=0, Sum_volnames=0, Sum_exps=0, Sum_nfssysnames=0; -int Sum_vcachemvids=0, Sum_vcachelinkData=0, Sum_vcacheacc=0, Sum_vcachelocks=0; -int Sum_cellaliases=0, Sum_cellname_names=0; +int Sum_cellnames = 0, Sum_userstp = 0, Sum_volnames = 0, Sum_exps = + 0, Sum_nfssysnames = 0; +int Sum_vcachemvids = 0, Sum_vcachelinkData = 0, Sum_vcacheacc = + 0, Sum_vcachelocks = 0; +int Sum_cellaliases = 0, Sum_cellname_names = 0; -int print_cells(pnt) -int pnt; +int +print_cells(pnt) + int pnt; { off_t symoff; - struct cell *cells, cle, *clentry = &cle, *clep; - long j=0, cell; + struct cell *cells, cle, *clentry = &cle, *clep; + long j = 0, cell; struct afs_q CellLRU, lru, *vu = &lru, *tq, *uq; u_long lru_addr; - if (pnt) printf("\n\nPrinting Cells' LRU list...\n"); - findsym( "CellLRU", &symoff); - kread(kmem, symoff, (char *) &CellLRU, sizeof CellLRU); - lru_addr = (u_long)symoff; - for (tq = CellLRU.next; (u_long)tq != lru_addr; tq = uq) { + if (pnt) + printf("\n\nPrinting Cells' LRU list...\n"); + findsym("CellLRU", &symoff); + kread(kmem, symoff, (char *)&CellLRU, sizeof CellLRU); + lru_addr = (u_long) symoff; + for (tq = CellLRU.next; (u_long) tq != lru_addr; tq = uq) { clep = QTOC(tq); - kread(kmem, (off_t)tq, (char *)vu, sizeof CellLRU); + kread(kmem, (off_t) tq, (char *)vu, sizeof CellLRU); uq = vu->next; - kread(kmem, (off_t)clep, (char *) clentry, sizeof *clentry); + kread(kmem, (off_t) clep, (char *)clentry, sizeof *clentry); print_cell(kmem, clentry, clep, pnt); j++; } - if (pnt) printf("... found %d 'afs_cells' entries\n", j); + if (pnt) + printf("... found %d 'afs_cells' entries\n", j); return j; } -int print_cellaliases(int pnt) +int +print_cellaliases(int pnt) { off_t symoff; struct cell_alias *ca, cae; long j = 0; - if (pnt) printf("\n\nPrinting cell_alias list...\n"); - findsym( "afs_cellalias_head", &symoff); - kread(kmem, symoff, (char *) &ca, sizeof ca); + if (pnt) + printf("\n\nPrinting cell_alias list...\n"); + findsym("afs_cellalias_head", &symoff); + kread(kmem, symoff, (char *)&ca, sizeof ca); while (ca) { char alias[100], cell[100]; - kread(kmem, (off_t) ca, (char *) &cae, sizeof cae); - kread(kmem, (off_t) cae.alias, alias, (KDUMP_SIZE_T)40); + kread(kmem, (off_t) ca, (char *)&cae, sizeof cae); + kread(kmem, (off_t) cae.alias, alias, (KDUMP_SIZE_T) 40); alias[40] = '\0'; Sum_cellaliases += strlen(alias) + 1; - kread(kmem, (off_t) cae.cell, cell, (KDUMP_SIZE_T)40); + kread(kmem, (off_t) cae.cell, cell, (KDUMP_SIZE_T) 40); cell[40] = '\0'; Sum_cellaliases += strlen(cell) + 1; if (pnt) - printf("%x: alias=%s cell=%s index=%d\n", - ca, alias, cell, cae.index); + printf("%x: alias=%s cell=%s index=%d\n", ca, alias, cell, + cae.index); ca = cae.next; j++; } - if (pnt) printf("... found %d 'cell_alias' entries\n", j); + if (pnt) + printf("... found %d 'cell_alias' entries\n", j); return j; } -int print_cellnames(int pnt) +int +print_cellnames(int pnt) { off_t symoff; struct cell_name *cn, cne; long j = 0; - if (pnt) printf("\n\nPrinting cell_name list...\n"); - findsym( "afs_cellname_head", &symoff); - kread(kmem, symoff, (char *) &cn, sizeof cn); + if (pnt) + printf("\n\nPrinting cell_name list...\n"); + findsym("afs_cellname_head", &symoff); + kread(kmem, symoff, (char *)&cn, sizeof cn); while (cn) { char cellname[100]; - kread(kmem, (off_t) cn, (char *) &cne, sizeof cne); - kread(kmem, (off_t) cne.cellname, cellname, (KDUMP_SIZE_T)40); + kread(kmem, (off_t) cn, (char *)&cne, sizeof cne); + kread(kmem, (off_t) cne.cellname, cellname, (KDUMP_SIZE_T) 40); cellname[40] = '\0'; Sum_cellname_names += strlen(cellname) + 1; if (pnt) - printf("%x: cellnum=%d cellname=%s used=%d\n", - cn, cne.cellnum, cellname, cne.used); + printf("%x: cellnum=%d cellname=%s used=%d\n", cn, cne.cellnum, + cellname, cne.used); cn = cne.next; j++; } - if (pnt) printf("... found %d 'cell_name' entries\n", j); + if (pnt) + printf("... found %d 'cell_name' entries\n", j); return j; } -int print_users(pnt) -int pnt; +int +print_users(pnt) + int pnt; { off_t symoff; - struct unixuser *afs_users[NUSERS], ue,*uentry= &ue, *uep; + struct unixuser *afs_users[NUSERS], ue, *uentry = &ue, *uep; int i, j; - if (pnt) printf("\n\nPrinting 'afs_users' structures...\n"); - findsym( "afs_users", &symoff); - kread(kmem, symoff, (char *) afs_users, sizeof afs_users); - for (i=0,j=0; i < NUSERS; i++) { + if (pnt) + printf("\n\nPrinting 'afs_users' structures...\n"); + findsym("afs_users", &symoff); + kread(kmem, symoff, (char *)afs_users, sizeof afs_users); + for (i = 0, j = 0; i < NUSERS; i++) { for (uep = afs_users[i]; uep; uep = uentry->next, j++) { kread(kmem, (off_t) uep, (char *)uentry, sizeof *uentry); print_unixuser(kmem, uentry, uep, pnt); } } - if (pnt) printf("... found %d 'afs_users' entries\n", j); + if (pnt) + printf("... found %d 'afs_users' entries\n", j); return j; } @@ -1281,8 +1324,9 @@ struct server **serversFound = NULL; afs_int32 NserversFound = 0; #define SF_ALLOCATION_STEP 500 -int add_found_server(sep) -struct server *sep; +int +add_found_server(sep) + struct server *sep; { static afs_int32 NserversAllocated = 0; static afs_int32 failed = 0; @@ -1294,17 +1338,17 @@ struct server *sep; NserversAllocated += SF_ALLOCATION_STEP; if (!serversFound) { serversFound = - (struct server **)malloc(NserversAllocated - * sizeof(struct server *)); + (struct server **)malloc(NserversAllocated * + sizeof(struct server *)); } else { serversFound = - (struct server **)realloc((char*)serversFound, - NserversAllocated - * sizeof(struct server *)); + (struct server **)realloc((char *)serversFound, + NserversAllocated * + sizeof(struct server *)); } if (!serversFound) { printf("Can't allocate %lu bytes for list of found servers.\n", - NserversAllocated * sizeof(struct server *)); + NserversAllocated * sizeof(struct server *)); failed = 1; NserversFound = 0; return -1; @@ -1314,20 +1358,22 @@ struct server *sep; return 0; } -int find_server(sep) -struct server *sep; +int +find_server(sep) + struct server *sep; { int i; - for (i=0; inext, nServers++) { kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); if (pnt && !failed) { - if (add_found_server(sep)<0) + if (add_found_server(sep) < 0) failed = 1; } if (pnt) @@ -1367,7 +1413,7 @@ int pnt; else printf("... found %d 'afs_servers' entries\n", nServers); printf("Chain lengths:\n"); - for (i=0; inext=%lx\n", - sa.server, sentry->next); + printf + ("ERROR: Server missing from hash chain: server=%lx, server->next=%lx\n", + sa.server, sentry->next); print_server(kmem, sentry, sa.server, 1, pnt); - printf("----------------------------------------------------\n"); + printf + ("----------------------------------------------------\n"); } } } } - printf("... found %d 'afs_srvAddr' entries, %d alloc'd (not in server struct)\n", - nSrvAddrs, nSrvAddrStructs); + printf + ("... found %d 'afs_srvAddr' entries, %d alloc'd (not in server struct)\n", + nSrvAddrs, nSrvAddrStructs); printf("Chain lengths:\n"); - for (i=0; inext, j++) { kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); print_server(kmem, sentry, sep, 2, pnt); } } - if (pnt) printf("... found %d 'afs_conns' entries\n", Nconns); + if (pnt) + printf("... found %d 'afs_conns' entries\n", Nconns); } -int print_volumes(pnt) -int pnt; +int +print_volumes(pnt) + int pnt; { off_t symoff; struct volume *afs_volumes[NVOLS], ve, *ventry = &ve, *vep; afs_int32 i, j; - if (pnt) printf("\n\nPrinting 'afs_volumes' structures...\n"); - findsym( "afs_volumes", &symoff); - kread(kmem, symoff, (char *) afs_volumes, NVOLS * sizeof(long)); - for (i=0, j=0; i < NVOLS; i++) { + if (pnt) + printf("\n\nPrinting 'afs_volumes' structures...\n"); + findsym("afs_volumes", &symoff); + kread(kmem, symoff, (char *)afs_volumes, NVOLS * sizeof(long)); + for (i = 0, j = 0; i < NVOLS; i++) { for (vep = afs_volumes[i]; vep; vep = ventry->next, j++) { kread(kmem, (off_t) vep, (char *)ventry, sizeof *ventry); print_volume(kmem, ventry, vep, pnt); } } - if (pnt) printf("... found %d 'afs_volumes' entries\n", j); + if (pnt) + printf("... found %d 'afs_volumes' entries\n", j); return (j); } -void print_cbHash(pnt) -int pnt; +void +print_cbHash(pnt) + int pnt; { off_t symoff; struct afs_q cbHashT[CBHTSIZE]; afs_int32 i, j; - if (pnt) printf("\n\nPrinting 'cbHashT' table...\n"); - findsym( "cbHashT", &symoff); - kread(kmem, symoff, (char *) cbHashT, sizeof cbHashT); - for (i=0; i < CBHTSIZE; i++) { - if (pnt) printf("%lx: %x %x\n", (long)symoff+8*i, cbHashT[i].prev, cbHashT[i].next); + if (pnt) + printf("\n\nPrinting 'cbHashT' table...\n"); + findsym("cbHashT", &symoff); + kread(kmem, symoff, (char *)cbHashT, sizeof cbHashT); + for (i = 0; i < CBHTSIZE; i++) { + if (pnt) + printf("%lx: %x %x\n", (long)symoff + 8 * i, cbHashT[i].prev, + cbHashT[i].next); } - if (pnt) printf("... that should be %d callback hash entries\n", i); + if (pnt) + printf("... that should be %d callback hash entries\n", i); } -int print_vcaches(pnt) -int pnt; +int +print_vcaches(pnt) + int pnt; { off_t symoff; struct vcache *afs_vhashTable[VCSIZE], Ve, *Ventry = &Ve, *Vep; afs_int32 i, j; - if (pnt) printf("\n\nPrinting afs_vcaches structures...\n"); - if (pnt) printf("print_vcaches: sizeof(struct vcache) = %ld\n", (long) sizeof(struct vcache)); - findsym( "afs_vhashT", &symoff); - kread(kmem, symoff, (char *) afs_vhashTable, sizeof afs_vhashTable); - for (i=0, j=0; i < VCSIZE; i++) { + if (pnt) + printf("\n\nPrinting afs_vcaches structures...\n"); + if (pnt) + printf("print_vcaches: sizeof(struct vcache) = %ld\n", + (long)sizeof(struct vcache)); + findsym("afs_vhashT", &symoff); + kread(kmem, symoff, (char *)afs_vhashTable, sizeof afs_vhashTable); + for (i = 0, j = 0; i < VCSIZE; i++) { if (pnt) printf("Printing hash chain %d...\n", i); for (Vep = afs_vhashTable[i]; Vep; Vep = Ventry->hnext, j++) { kread(kmem, (off_t) Vep, (char *)Ventry, sizeof *Ventry); - if (Dvstats || Dall || !pnt) + if (Dvstats || Dall || !pnt) print_vcache(kmem, Ventry, Vep, pnt); - if (Dvnodes || Dall) + if (Dvnodes || Dall) print_vnode(kmem, Ventry, Vep, pnt); } } - if (pnt) printf("... found %d 'afs_vcaches' entries\n", j); + if (pnt) + printf("... found %d 'afs_vcaches' entries\n", j); return j; } -int print_dcaches(pnt) -int pnt; +int +print_dcaches(pnt) + int pnt; { off_t symoff; long table, *ptr; @@ -1533,51 +1605,58 @@ int pnt; struct afs_q dlru; /* Handle the afs_dcaches structs */ - if (pnt) printf("\n\nPrinting afs_dcache related structures...\n"); - findsym( "afs_cacheFiles", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); - findsym( "afs_indexTable", &symoff); - kread(kmem, symoff, (char *) &table, sizeof(long)); - ptr = (long *) malloc(count * sizeof(long)); - kread(kmem, table, (char *) ptr, count * sizeof(long)); - for (i=0, j=0; i < count; i++) { + if (pnt) + printf("\n\nPrinting afs_dcache related structures...\n"); + findsym("afs_cacheFiles", &symoff); + kread(kmem, symoff, (char *)&count, sizeof count); + findsym("afs_indexTable", &symoff); + kread(kmem, symoff, (char *)&table, sizeof(long)); + ptr = (long *)malloc(count * sizeof(long)); + kread(kmem, table, (char *)ptr, count * sizeof(long)); + for (i = 0, j = 0; i < count; i++) { if (dp = (struct dcache *)ptr[i]) { - if (pnt) printf("afs_indexTable[%d] %x: ", i, dp); + if (pnt) + printf("afs_indexTable[%d] %x: ", i, dp); kread(kmem, (off_t) dp, (char *)dcp, sizeof *dcp); print_dcache(kmem, dcp, dp, pnt); j++; } } - if (pnt) printf("... found %d 'dcache' entries\n", j); - findsym( "afs_DLRU", &symoff); - kread(kmem, symoff, (char *) &dlru, sizeof(struct afs_q)); - if (pnt) printf("DLRU next=0x%x, prev=0x%x\n", dlru.next, dlru.prev); + if (pnt) + printf("... found %d 'dcache' entries\n", j); + findsym("afs_DLRU", &symoff); + kread(kmem, symoff, (char *)&dlru, sizeof(struct afs_q)); + if (pnt) + printf("DLRU next=0x%x, prev=0x%x\n", dlru.next, dlru.prev); free(ptr); - + return j; } -void print_DindexTimes(pnt) -int pnt; +void +print_DindexTimes(pnt) + int pnt; { off_t symoff; long table; afs_hyper_t *ptr; - afs_int32 temp, * indexTime = &temp; + afs_int32 temp, *indexTime = &temp; afs_int32 i, j, count; /* Handle the afs_indexTimes array */ - if (pnt) printf("\n\nPrinting afs_indexTimes[]...\n"); - findsym( "afs_cacheFiles", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); - findsym( "afs_indexTimes", &symoff); - kread(kmem, symoff, (char *) &table, sizeof(long)); + if (pnt) + printf("\n\nPrinting afs_indexTimes[]...\n"); + findsym("afs_cacheFiles", &symoff); + kread(kmem, symoff, (char *)&count, sizeof count); + findsym("afs_indexTimes", &symoff); + kread(kmem, symoff, (char *)&table, sizeof(long)); ptr = (afs_hyper_t *) malloc(count * sizeof(afs_hyper_t)); - kread(kmem, table, (char *) ptr, count * sizeof(afs_hyper_t)); - for (i=0, j=0; i < count; i++) { - if (pnt) printf("afs_indexTimes[%d]\t%10d.%d\n", i, - ptr[i].high, ptr[i].low); + kread(kmem, table, (char *)ptr, count * sizeof(afs_hyper_t)); + for (i = 0, j = 0; i < count; i++) { + if (pnt) + printf("afs_indexTimes[%d]\t%10d.%d\n", i, ptr[i].high, + ptr[i].low); /* if (dp = (struct dcache *)ptr[i]) { printf("afs_indexTable[%d] %lx: ", i, dp); kread(kmem, (off_t) dp, (char *)dcp, sizeof *dcp); @@ -1586,92 +1665,106 @@ int pnt; */ j++; } - if (pnt) printf("afs_indexTimes has %d entries\n", j); + if (pnt) + printf("afs_indexTimes has %d entries\n", j); free(ptr); } -void print_DdvnextTbl(pnt) -int pnt; +void +print_DdvnextTbl(pnt) + int pnt; { off_t symoff; long table; afs_int32 *ptr; - afs_int32 temp, * indexTime = &temp; + afs_int32 temp, *indexTime = &temp; afs_int32 i, j, count; /* Handle the afs_dvnextTbl arrays */ - if (pnt) printf("\n\nPrinting afs_dvnextTbl[]...\n"); - findsym( "afs_cacheFiles", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); - findsym( "afs_dvnextTbl", &symoff); - kread(kmem, symoff, (char *) &table, sizeof(long)); + if (pnt) + printf("\n\nPrinting afs_dvnextTbl[]...\n"); + findsym("afs_cacheFiles", &symoff); + kread(kmem, symoff, (char *)&count, sizeof count); + findsym("afs_dvnextTbl", &symoff); + kread(kmem, symoff, (char *)&table, sizeof(long)); ptr = (afs_int32 *) malloc(count * sizeof(afs_int32)); - kread(kmem, table, (char *) ptr, count * sizeof(afs_int32)); - for (i=0, j=0; i < count; i++) { - if (pnt) printf("afs_dvnextTbl[%d]\t%d\n", i, ptr[i]); + kread(kmem, table, (char *)ptr, count * sizeof(afs_int32)); + for (i = 0, j = 0; i < count; i++) { + if (pnt) + printf("afs_dvnextTbl[%d]\t%d\n", i, ptr[i]); j++; } - if (pnt) printf("afs_dvnextTbl has %d entries\n", j); + if (pnt) + printf("afs_dvnextTbl has %d entries\n", j); free(ptr); } -void print_DdcnextTbl(pnt) -int pnt; +void +print_DdcnextTbl(pnt) + int pnt; { off_t symoff; long table; afs_int32 *ptr; - afs_int32 temp, * indexTime = &temp; + afs_int32 temp, *indexTime = &temp; afs_int32 i, j, count; /* Handle the afs_dcnextTbl arrays */ - if (pnt) printf("\n\nPrinting afs_dcnextTbl[]...\n"); - findsym( "afs_cacheFiles", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); - findsym( "afs_dcnextTbl", &symoff); - kread(kmem, symoff, (char *) &table, sizeof(long)); + if (pnt) + printf("\n\nPrinting afs_dcnextTbl[]...\n"); + findsym("afs_cacheFiles", &symoff); + kread(kmem, symoff, (char *)&count, sizeof count); + findsym("afs_dcnextTbl", &symoff); + kread(kmem, symoff, (char *)&table, sizeof(long)); ptr = (afs_int32 *) malloc(count * sizeof(afs_int32)); - kread(kmem, table, (char *) ptr, count * sizeof(afs_int32)); - for (i=0, j=0; i < count; i++) { - if (pnt) printf("afs_dcnextTbl[%d]\t%d\n", i, ptr[i]); + kread(kmem, table, (char *)ptr, count * sizeof(afs_int32)); + for (i = 0, j = 0; i < count; i++) { + if (pnt) + printf("afs_dcnextTbl[%d]\t%d\n", i, ptr[i]); j++; } - if (pnt) printf("afs_dcnextTbl has %d entries\n", j); + if (pnt) + printf("afs_dcnextTbl has %d entries\n", j); free(ptr); } -void print_DindexFlags(pnt) -int pnt; +void +print_DindexFlags(pnt) + int pnt; { off_t symoff; afs_int32 count; long table; unsigned char *flags; - afs_int32 temp, * indexTime = &temp; + afs_int32 temp, *indexTime = &temp; afs_int32 i, j; /* Handle the afs_indexFlags array */ - if (pnt) printf("\n\nPrinting afs_indexFlags[]...\n"); - findsym( "afs_cacheFiles", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); - findsym( "afs_indexFlags", &symoff); - kread(kmem, symoff, (char *) &table, sizeof(long)); - flags = (unsigned char *) malloc(count * sizeof(char)); + if (pnt) + printf("\n\nPrinting afs_indexFlags[]...\n"); + findsym("afs_cacheFiles", &symoff); + kread(kmem, symoff, (char *)&count, sizeof count); + findsym("afs_indexFlags", &symoff); + kread(kmem, symoff, (char *)&table, sizeof(long)); + flags = (unsigned char *)malloc(count * sizeof(char)); kread(kmem, table, flags, count * sizeof(char)); - for (i=0, j=0; i < count; i++) { - if (pnt) printf("afs_indexFlags[%d]\t%4u\n", i, flags[i]); + for (i = 0, j = 0; i < count; i++) { + if (pnt) + printf("afs_indexFlags[%d]\t%4u\n", i, flags[i]); j++; } - if (pnt) printf("afs_indexFlags has %d entries\n", j); + if (pnt) + printf("afs_indexFlags has %d entries\n", j); free(flags); } -void print_buffers(pnt) -int pnt; +void +print_buffers(pnt) + int pnt; { off_t symoff; long table; @@ -1680,62 +1773,75 @@ int pnt; struct buffer *bp; afs_int32 i, j; - if (pnt) printf("\n\nPrinting 'buffers' table...\n"); - findsym( "Buffers", &symoff); - kread(kmem, symoff, (char *) &table, sizeof(long)); - findsym( "nbuffers", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(int)); - buffers = (unsigned char *) malloc(count * sizeof(struct buffer)); + if (pnt) + printf("\n\nPrinting 'buffers' table...\n"); + findsym("Buffers", &symoff); + kread(kmem, symoff, (char *)&table, sizeof(long)); + findsym("nbuffers", &symoff); + kread(kmem, symoff, (char *)&count, sizeof(int)); + buffers = (unsigned char *)malloc(count * sizeof(struct buffer)); kread(kmem, table, buffers, count * sizeof(struct buffer)); bp = (struct buffer *)buffers; - for (i=0, j=0; i < count; i++, bp++) { + for (i = 0, j = 0; i < count; i++, bp++) { #ifdef AFS_SGI62_ENV - if (pnt) printf("Buffer #%d:\tfid=%llu page=%d, accTime=%d,\n\tHash=%x, data=%x, lockers=%x, dirty=%d, hashI=%d\n", - i, bp->fid[0], bp->page, bp->accesstime, - bp->hashNext, bp->data, bp->lockers, bp->b_dirty, bp->hashIndex); + if (pnt) + printf + ("Buffer #%d:\tfid=%llu page=%d, accTime=%d,\n\tHash=%x, data=%x, lockers=%x, dirty=%d, hashI=%d\n", + i, bp->fid[0], bp->page, bp->accesstime, bp->hashNext, + bp->data, bp->lockers, bp->dirty, bp->hashIndex); #else - if (pnt) printf("Buffer #%d:\tfid=%lu page=%d, accTime=%d,\n\tHash=%x, data=%x, lockers=%x, dirty=%d, hashI=%d\n", - i, bp->fid[0], bp->page, bp->accesstime, - bp->hashNext, bp->data, bp->lockers, bp->b_dirty, bp->hashIndex); + if (pnt) + printf + ("Buffer #%d:\tfid=%lu page=%d, accTime=%d,\n\tHash=%x, data=%x, lockers=%x, dirty=%d, hashI=%d\n", + i, bp->fid[0], bp->page, bp->accesstime, bp->hashNext, + bp->data, bp->lockers, bp->dirty, bp->hashIndex); #endif j++; } - if (pnt) printf("\n\t ... that should be %d buffer entries\n", i); + if (pnt) + printf("\n\t ... that should be %d buffer entries\n", i); } -int print_nfss(pnt) -int pnt; +int +print_nfss(pnt) + int pnt; { off_t symoff; struct afs_exporter *exp_entry, ex, *exp = &ex, *exp1; - struct nfsclientpag *afs_nfspags[NNFSCLIENTS], e, *entry = &e, *ep; + struct nfsclientpag *afs_nfspags[NNFSCLIENTS], e, *entry = &e, *ep; long i, j, cell; /* Handle the afs_exporter structures */ - if (pnt) printf("\n\nPrinting 'afs_exporters' link list...\n"); - findsym( "root_exported", &symoff); - kread(kmem, symoff, (char *) &cell, sizeof(long)); - for (exp1 = (struct afs_exporter *) cell, j=0; exp1; exp1 = exp->exp_next, j++) { - kread(kmem, (off_t)exp1, (char *) exp, sizeof *exp); - if (pnt) printf("AFS_EXPORTER(%x): \n", exp1); + if (pnt) + printf("\n\nPrinting 'afs_exporters' link list...\n"); + findsym("root_exported", &symoff); + kread(kmem, symoff, (char *)&cell, sizeof(long)); + for (exp1 = (struct afs_exporter *)cell, j = 0; exp1; + exp1 = exp->exp_next, j++) { + kread(kmem, (off_t) exp1, (char *)exp, sizeof *exp); + if (pnt) + printf("AFS_EXPORTER(%x): \n", exp1); print_exporter(kmem, exp, exp1, pnt); Sum_exps++; } - if (pnt) printf("... found %d 'afs_exporters' entries\n", j); + if (pnt) + printf("... found %d 'afs_exporters' entries\n", j); /* Handle the afs_nfsclientpags structs */ - if (pnt) printf("\n\nPrinting 'afs_nfsclientpags' structures...\n"); - if (!findsym( "afs_nfspags", &symoff)) + if (pnt) + printf("\n\nPrinting 'afs_nfsclientpags' structures...\n"); + if (!findsym("afs_nfspags", &symoff)) return 0; - kread(kmem, symoff, (char *) afs_nfspags, sizeof afs_nfspags); - for (i=0,j=0; i < NNFSCLIENTS; i++) { + kread(kmem, symoff, (char *)afs_nfspags, sizeof afs_nfspags); + for (i = 0, j = 0; i < NNFSCLIENTS; i++) { for (ep = afs_nfspags[i]; ep; ep = entry->next, j++) { - kread(kmem, (off_t) ep, (char *) entry, sizeof *entry); + kread(kmem, (off_t) ep, (char *)entry, sizeof *entry); print_nfsclient(kmem, entry, ep, pnt); } } - if (pnt) printf("... found %d 'afs_nfsclientpags' entries\n", j); + if (pnt) + printf("... found %d 'afs_nfsclientpags' entries\n", j); return j; } @@ -1746,8 +1852,8 @@ typedef struct event { int refcount; /* Is it in use? */ kcondvar_t cond; /* Currently associated condition variable */ int seq; /* Sequence number: this is incremented - by wakeup calls; wait will not return until - it changes */ + * by wakeup calls; wait will not return until + * it changes */ } event_t; #endif @@ -1759,13 +1865,14 @@ typedef struct event { #define KM_TYPE 1 #define VM_TYPE 2 struct osi_linux_mem { - int mem_next; /* types are or'd into low bits of next */ + int mem_next; /* types are or'd into low bits of next */ char data[1]; }; #define MEMTYPE(A) ((A) & 0x3) #define MEMADDR(A) ((struct osi_linux_mem*)((A) & (~0x3))) #define PR_MEMTYPE(A) ((MEMTYPE(A) == KM_TYPE) ? "phys" : "virt") -void print_alloced_memlist(void) +void +print_alloced_memlist(void) { off_t symoff; struct osi_linux_mem *memp, memlist, next; @@ -1773,121 +1880,149 @@ void print_alloced_memlist(void) int count; int n = 0; - findsym( "afs_linux_memlist_size", &symoff); - kread(kmem, symoff, (char*) &count, sizeof count); - findsym( "afs_linux_memlist", &symoff); - kread(kmem, symoff, (char*) &memp, sizeof memp); + findsym("afs_linux_memlist_size", &symoff); + kread(kmem, symoff, (char *)&count, sizeof count); + findsym("afs_linux_memlist", &symoff); + kread(kmem, symoff, (char *)&memp, sizeof memp); if (memp) { - kread(kmem, (int)memp, (char*) &next, sizeof next); - } - else { + kread(kmem, (int)memp, (char *)&next, sizeof next); + } else { memset(&next, 0, sizeof next); } printf("Allocated memory list: %d elements\n", count); printf("%20s %4s %10s\n", "Address", "Type", "Next"); - printf("%20lx %4s %10x\n", (long)((char*)memp) + MEM_SPACE, + printf("%20lx %4s %10x\n", (long)((char *)memp) + MEM_SPACE, PR_MEMTYPE(next.mem_next), next.mem_next); n = 1; while (next_addr = (off_t) MEMADDR(next.mem_next)) { - n ++; + n++; memlist = next; - kread(kmem, next_addr, (char*) &next, sizeof next); - printf("%20lx %4s %10x\n", (long) next_addr+MEM_SPACE, + kread(kmem, next_addr, (char *)&next, sizeof next); + printf("%20lx %4s %10x\n", (long)next_addr + MEM_SPACE, PR_MEMTYPE(next.mem_next), next.mem_next); } - printf("Found %d elements in allocated memory list, expected %d\n", - n, count); + printf("Found %d elements in allocated memory list, expected %d\n", n, + count); } #endif -void print_allocs(pnt) -int pnt; +void +print_allocs(pnt) + int pnt; { off_t symoff; - long count, i, j, k, l, m, n, T=0, tvs; + long count, i, j, k, l, m, n, T = 0, tvs; struct afs_CMStats afs_cmstats; struct afs_stats_CMPerf afs_cmperfstats; - findsym( "afs_cmstats", &symoff); - kread(kmem, symoff, (char *) &afs_cmstats, sizeof afs_cmstats); - findsym( "afs_stats_cmperf", &symoff); - kread(kmem, symoff, (char *) &afs_cmperfstats, sizeof afs_cmperfstats); + findsym("afs_cmstats", &symoff); + kread(kmem, symoff, (char *)&afs_cmstats, sizeof afs_cmstats); + findsym("afs_stats_cmperf", &symoff); + kread(kmem, symoff, (char *)&afs_cmperfstats, sizeof afs_cmperfstats); T += MAXSYSNAME; printf("\n\n%20s:\t%8d bytes\n", "Sysname area", MAXSYSNAME); - Sum_cellnames=0; + Sum_cellnames = 0; i = print_cells(0); j = (i * sizeof(struct cell)) + Sum_cellnames; T += j; - printf("%20s:\t%8d bytes\t[%d cells/%d bytes each + %d bytes for cell names]\n", "Cell package", j, i, sizeof(struct cell), Sum_cellnames); + printf + ("%20s:\t%8d bytes\t[%d cells/%d bytes each + %d bytes for cell names]\n", + "Cell package", j, i, sizeof(struct cell), Sum_cellnames); - Sum_cellaliases=0; + Sum_cellaliases = 0; i = print_cellaliases(0); j = (i * sizeof(struct cell_alias)) + Sum_cellaliases; T += j; - printf("%20s:\t%8d bytes\t[%d cell_aliases/%d bytes each + %d bytes for cell names]\n", "Cell package", j, i, sizeof(struct cell_alias), Sum_cellaliases); + printf + ("%20s:\t%8d bytes\t[%d cell_aliases/%d bytes each + %d bytes for cell names]\n", + "Cell package", j, i, sizeof(struct cell_alias), Sum_cellaliases); - Sum_cellname_names=0; + Sum_cellname_names = 0; i = print_cellnames(0); j = (i * sizeof(struct cell_name)) + Sum_cellname_names; T += j; - printf("%20s:\t%8d bytes\t[%d cell_names/%d bytes each + %d bytes for cell name strings]\n", "Cell package", j, i, sizeof(struct cell_name), Sum_cellname_names); + printf + ("%20s:\t%8d bytes\t[%d cell_names/%d bytes each + %d bytes for cell name strings]\n", + "Cell package", j, i, sizeof(struct cell_name), Sum_cellname_names); - Sum_userstp=0; + Sum_userstp = 0; i = print_users(0); j = (i * sizeof(struct unixuser)) + Sum_userstp; T += j; - printf("%20s:\t%8d bytes\t[%d users/%d bytes each + %d bytes for secret tokens]\n", "User package", j, i, sizeof(struct unixuser), Sum_userstp); + printf + ("%20s:\t%8d bytes\t[%d users/%d bytes each + %d bytes for secret tokens]\n", + "User package", j, i, sizeof(struct unixuser), Sum_userstp); i = print_servers(0); j = (i * sizeof(struct server)); T += j; - printf("%20s:\t%8d bytes\t[%d servers/%d bytes each]\n", "Server package", j, i, sizeof(struct server)); + printf("%20s:\t%8d bytes\t[%d servers/%d bytes each]\n", "Server package", + j, i, sizeof(struct server)); j = (Nconns * sizeof(struct conn)); T += j; - printf("%20s:\t%8d bytes\t[%d conns/%d bytes each]\n", "Connection package", j, Nconns, sizeof(struct conn)); - - i = (AFS_NCBRS * sizeof(struct afs_cbr)) * (j = afs_cmperfstats.CallBackAlloced); + printf("%20s:\t%8d bytes\t[%d conns/%d bytes each]\n", + "Connection package", j, Nconns, sizeof(struct conn)); + + i = (AFS_NCBRS * sizeof(struct afs_cbr)) * (j = + afs_cmperfstats. + CallBackAlloced); T += i; if (i) - printf("%20s:\t%8d bytes\t[%d cbs/%d bytes each]\n", "Server CB free pool", i, (j * AFS_NCBRS), sizeof(struct afs_cbr)); + printf("%20s:\t%8d bytes\t[%d cbs/%d bytes each]\n", + "Server CB free pool", i, (j * AFS_NCBRS), + sizeof(struct afs_cbr)); - Sum_volnames=0; + Sum_volnames = 0; i = print_volumes(0); j = (MAXVOLS * sizeof(struct volume)) + Sum_volnames; T += j; - printf("%20s:\t%8d bytes\t[%d volumes/%d bytes each + %d bytes for volnames - %d active entries]\n", "Volume package", j, MAXVOLS, sizeof(struct volume), Sum_volnames, i); + printf + ("%20s:\t%8d bytes\t[%d volumes/%d bytes each + %d bytes for volnames - %d active entries]\n", + "Volume package", j, MAXVOLS, sizeof(struct volume), Sum_volnames, + i); - Sum_vcachemvids = Sum_vcachelinkData = Sum_vcacheacc = Sum_vcachelocks = 0; + Sum_vcachemvids = Sum_vcachelinkData = Sum_vcacheacc = Sum_vcachelocks = + 0; tvs = i = print_vcaches(0); j = (i * sizeof(struct vcache)); /* T += j;*/ /* printf("%20s:\t%d bytes\t[%d vcaches/%d bytes each]\n", "Vcache package", j, i, sizeof(struct vcache));*/ #ifdef AFS_AIX32_ENV - i = (tvs + Sum_vcachemvids + Sum_vcachelinkData + Sum_vcachelocks) * AFS_SMALLOCSIZ; - printf("%20s:\t%8d bytes\t[%d act gnodes, %d mount pnts, %d symbolic links, %d unix locks]\n", - "[VC use of sml fp]*",i, tvs, Sum_vcachemvids, Sum_vcachelinkData, Sum_vcachelocks); + i = (tvs + Sum_vcachemvids + Sum_vcachelinkData + + Sum_vcachelocks) * AFS_SMALLOCSIZ; + printf + ("%20s:\t%8d bytes\t[%d act gnodes, %d mount pnts, %d symbolic links, %d unix locks]\n", + "[VC use of sml fp]*", i, tvs, Sum_vcachemvids, Sum_vcachelinkData, + Sum_vcachelocks); #else - i = (Sum_vcachemvids + Sum_vcachelinkData + Sum_vcachelocks) * AFS_SMALLOCSIZ; - printf("%20s:\t8%d bytes\t[%d mount pnts, %d symbolic links, %d unix locks]\n", - "[VC use of sml fp]*",i, Sum_vcachemvids, Sum_vcachelinkData, Sum_vcachelocks); + i = (Sum_vcachemvids + Sum_vcachelinkData + + Sum_vcachelocks) * AFS_SMALLOCSIZ; + printf + ("%20s:\t8%d bytes\t[%d mount pnts, %d symbolic links, %d unix locks]\n", + "[VC use of sml fp]*", i, Sum_vcachemvids, Sum_vcachelinkData, + Sum_vcachelocks); #endif #define NAXSs (1000 / sizeof(struct axscache)) #ifdef AFS32 i = (NAXSs * sizeof(struct axscache)); T += i; - printf("%20s:\t%8d bytes\t[%d access used by vcaches/%d bytes each]\n", "ACL List free pool", i, Sum_vcacheacc, sizeof(struct axscache)); + printf("%20s:\t%8d bytes\t[%d access used by vcaches/%d bytes each]\n", + "ACL List free pool", i, Sum_vcacheacc, sizeof(struct axscache)); #else { - struct axscache *xp, xpe, *nxp = &xpe; - - findsym( "afs_xaxscnt", &symoff); - kread(kmem, symoff, (char *) &i, sizeof i); - j = i * (NAXSs * sizeof(struct axscache)); - T += j; - printf("%20s:\t%8d bytes\t[%d access used by vcaches/%d bytes each - %d blocks of %d]\n", "ACL List free pool", j, Sum_vcacheacc, sizeof(struct axscache), i, (NAXSs * sizeof(struct axscache))); + struct axscache *xp, xpe, *nxp = &xpe; + + findsym("afs_xaxscnt", &symoff); + kread(kmem, symoff, (char *)&i, sizeof i); + j = i * (NAXSs * sizeof(struct axscache)); + T += j; + printf + ("%20s:\t%8d bytes\t[%d access used by vcaches/%d bytes each - %d blocks of %d]\n", + "ACL List free pool", j, Sum_vcacheacc, sizeof(struct axscache), + i, (NAXSs * sizeof(struct axscache))); } #endif @@ -1895,43 +2030,54 @@ int pnt; i = print_dcaches(0); j = (i * sizeof(struct dcache)); T += j; - printf("%20s:\t%8d bytes\t[%d dcaches/%d bytes each - ONLY USED COUNTED]\n", "Dcache package", j, i, sizeof(struct dcache)); + printf + ("%20s:\t%8d bytes\t[%d dcaches/%d bytes each - ONLY USED COUNTED]\n", + "Dcache package", j, i, sizeof(struct dcache)); #else - findsym( "afs_dcentries", &symoff); - kread(kmem, symoff, (char *) &i, sizeof i); + findsym("afs_dcentries", &symoff); + kread(kmem, symoff, (char *)&i, sizeof i); j = (i * sizeof(struct dcache)); T += j; - printf("%20s:\t%8d bytes\t[%d dcaches/%d bytes each]\n", "Dcache package", j, i, sizeof(struct dcache)); + printf("%20s:\t%8d bytes\t[%d dcaches/%d bytes each]\n", "Dcache package", + j, i, sizeof(struct dcache)); #endif - findsym( "afs_cacheFiles", &symoff); - kread(kmem, symoff, (char *) &i, sizeof i); - findsym( "afs_cacheStats", &symoff); - kread(kmem, symoff, (char *) &j, sizeof j); + findsym("afs_cacheFiles", &symoff); + kread(kmem, symoff, (char *)&i, sizeof i); + findsym("afs_cacheStats", &symoff); + kread(kmem, symoff, (char *)&j, sizeof j); k = (j * sizeof(struct vcache)); - printf("%20s:\t%8d bytes\t[%d free vcaches/%d bytes each - %d active entries]\n", "Vcache free list", k, j, sizeof(struct vcache), tvs); - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Dcache Index Table", i * 4, i, 4); + printf + ("%20s:\t%8d bytes\t[%d free vcaches/%d bytes each - %d active entries]\n", + "Vcache free list", k, j, sizeof(struct vcache), tvs); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", + "Dcache Index Table", i * 4, i, 4); #ifndef AFS32 - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Dcache Index Times", i * 8, i, 8); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", + "Dcache Index Times", i * 8, i, 8); #else - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Dcache Index Times", i * 4, i, 4); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", + "Dcache Index Times", i * 4, i, 4); #endif - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Dcache Index Flags", i, i, 1); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", + "Dcache Index Flags", i, i, 1); /* printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Dcache free list", i, i, 1);*/ #ifndef AFS32 - T += k + (i*4)+ (i*8) + i; + T += k + (i * 4) + (i * 8) + i; #else - T += k + (i*4)+ (i*4) + i; + T += k + (i * 4) + (i * 4) + i; #endif i = (j = afs_cmperfstats.bufAlloced) * sizeof(struct buffer); T += i; - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Buffer package", i, j, sizeof(struct buffer)); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Buffer package", + i, j, sizeof(struct buffer)); #if !AFS_USEBUFFERS #define AFS_BUFFER_PAGESIZE 2048 i = j * AFS_BUFFER_PAGESIZE; T += i; - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Xtra Buffer pkg area", i, j, AFS_BUFFER_PAGESIZE); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", + "Xtra Buffer pkg area", i, j, AFS_BUFFER_PAGESIZE); #endif Sum_exps = 0; @@ -1940,75 +2086,88 @@ int pnt; k = Sum_exps * sizeof(struct afs_exporter); T += k; if (k) - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Xlator Exporter list", k, Sum_exps, sizeof(struct afs_exporter)); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", + "Xlator Exporter list", k, Sum_exps, + sizeof(struct afs_exporter)); j = (i * sizeof(struct nfsclientpag)) + Sum_nfssysnames; T += j; if (j) - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each + %d for remote sysnames]\n", "Xlator Nfs clnt pkg", j, i, sizeof(struct nfsclientpag), Sum_nfssysnames); + printf + ("%20s:\t%8d bytes\t[%d entries/%d bytes each + %d for remote sysnames]\n", + "Xlator Nfs clnt pkg", j, i, sizeof(struct nfsclientpag), + Sum_nfssysnames); i = (j = afs_cmperfstats.LargeBlocksAlloced) * AFS_LRALLOCSIZ; T += i; - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each - %d active entries]\n", "Large Free Pool", - i, j, AFS_LRALLOCSIZ, afs_cmperfstats.LargeBlocksActive); + printf + ("%20s:\t%8d bytes\t[%d entries/%d bytes each - %d active entries]\n", + "Large Free Pool", i, j, AFS_LRALLOCSIZ, + afs_cmperfstats.LargeBlocksActive); i = (j = afs_cmperfstats.SmallBlocksAlloced) * AFS_SMALLOCSIZ; T += i; - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each - %d active entries]\n", "Small Free Pool", - i, j, AFS_SMALLOCSIZ, afs_cmperfstats.SmallBlocksActive); + printf + ("%20s:\t%8d bytes\t[%d entries/%d bytes each - %d active entries]\n", + "Small Free Pool", i, j, AFS_SMALLOCSIZ, + afs_cmperfstats.SmallBlocksActive); #if defined(AFS_GLOBAL_SUNLOCK) && !defined(AFS_HPUX_ENV) && !defined(AFS_AIX41_ENV) - findsym( "afs_evhashcnt", &symoff); - kread(kmem, symoff, (char *) &j, sizeof j); + findsym("afs_evhashcnt", &symoff); + kread(kmem, symoff, (char *)&j, sizeof j); i = (j * sizeof(event_t)); T += i; - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "afs glock Event Pool", i, j, sizeof(event_t)); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", + "afs glock Event Pool", i, j, sizeof(event_t)); /* printf("XXXXXXX Count event queue allocs!!!! XXXXXX\n");*/ #endif - i = j =0; - if (findsym( "rxevent_nFree", &symoff)) - kread(kmem, symoff, (char *) &j, sizeof j); - if (findsym( "rxevent_nPosted", &symoff)) - kread(kmem, symoff, (char *) &i, sizeof i); + i = j = 0; + if (findsym("rxevent_nFree", &symoff)) + kread(kmem, symoff, (char *)&j, sizeof j); + if (findsym("rxevent_nPosted", &symoff)) + kread(kmem, symoff, (char *)&i, sizeof i); k = (i + j) * sizeof(struct rxevent); if (k) { T += k; - printf("%20s:\t%8d bytes\t[%d free, %d posted/%d bytes each]\n", "Rx event pkg", - k, j, i, sizeof(struct rxevent)); + printf("%20s:\t%8d bytes\t[%d free, %d posted/%d bytes each]\n", + "Rx event pkg", k, j, i, sizeof(struct rxevent)); } else { T += (k = 20 * sizeof(struct rxevent)); - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each - THIS IS MIN ALLOC/NOT ACTUAL]\n", "Rx event pkg", - k, 20, sizeof(struct rxevent)); + printf + ("%20s:\t%8d bytes\t[%d entries/%d bytes each - THIS IS MIN ALLOC/NOT ACTUAL]\n", + "Rx event pkg", k, 20, sizeof(struct rxevent)); } findsym("rx_nFreePackets", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); /* findsym("rx_initSendWindow", &symoff); kread(kmem, symoff, (char *) &i, sizeof i); */ - i=0; + i = 0; findsym("rx_nPackets", &symoff); - kread(kmem, symoff, (char *) &j, sizeof j); + kread(kmem, symoff, (char *)&j, sizeof j); k = (j + i + 2) * sizeof(struct rx_packet); T += k; - printf("%20s:\t%8d bytes\t[%d free packets/%d bytes each]\n", "Rx packet freelist", - k, count, sizeof(struct rx_packet)); + printf("%20s:\t%8d bytes\t[%d free packets/%d bytes each]\n", + "Rx packet freelist", k, count, sizeof(struct rx_packet)); #define rx_hashTableSize 256 /* XXX */ - i = (rx_hashTableSize*sizeof(struct rx_connection *)); - j = (rx_hashTableSize*sizeof(struct rx_peer *)); + i = (rx_hashTableSize * sizeof(struct rx_connection *)); + j = (rx_hashTableSize * sizeof(struct rx_peer *)); k = i + j; T += k; - printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Rx conn/peer tables", - k, rx_hashTableSize, sizeof(struct rx_connection *)); - - findsym( "rxi_Alloccnt", &symoff); - kread(kmem, symoff, (char *) &j, sizeof j); - findsym( "rxi_Allocsize", &symoff); - kread(kmem, symoff, (char *) &i, sizeof i); + printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", + "Rx conn/peer tables", k, rx_hashTableSize, + sizeof(struct rx_connection *)); + + findsym("rxi_Alloccnt", &symoff); + kread(kmem, symoff, (char *)&j, sizeof j); + findsym("rxi_Allocsize", &symoff); + kread(kmem, symoff, (char *)&i, sizeof i); T += i; - printf("%20s:\t%8d bytes\t[%d outstanding allocs]\n", "RX misc allocs", i, j); + printf("%20s:\t%8d bytes\t[%d outstanding allocs]\n", "RX misc allocs", i, + j); j = afs_cmperfstats.OutStandingMemUsage; @@ -2016,7 +2175,8 @@ int pnt; printf("%20s:\t%8d bytes\n", "Accounted-for mem", T); printf("%20s:\t%8d bytes\n", "Non acc'd-for mem", j - T); - printf("\n\nNOTE:\n\tAll [...]* entries above aren't counted towards the total mem since they're redundant\n"); + printf + ("\n\nNOTE:\n\tAll [...]* entries above aren't counted towards the total mem since they're redundant\n"); #ifdef AFS_LINUX22_ENV if (pnt) @@ -2025,17 +2185,18 @@ int pnt; } #if defined(sparc) && !defined(__linux__) -int readmem(kmem, buf, vad, len) - int kmem, len; +int +readmem(kmem, buf, vad, len) + int kmem, len; #ifdef AFS_SUN57_ENV - uintptr_t vad; + uintptr_t vad; #else - int vad; + int vad; #endif /** AFS_SUN57_ENV **/ - char *buf; + char *buf; { int newlen; - if (( newlen = kvm_kread(kd, vad, buf, len) ) != len) { + if ((newlen = kvm_kread(kd, vad, buf, len)) != len) { printf("Couldn't process dumpfile with supplied namelist %s\n", obj); exit(1); } @@ -2043,67 +2204,81 @@ int readmem(kmem, buf, vad, len) #endif #ifdef AFS_OSF_ENV -static read_addr(int fd, unsigned long addr, unsigned long *val) { - if (lseek(fd, addr, SEEK_SET) == -1) return(0); - if (read(fd, val, sizeof(long)) != sizeof(long)) return(0); - return(1); +static +read_addr(int fd, unsigned long addr, unsigned long *val) +{ + if (lseek(fd, addr, SEEK_SET) == -1) + return (0); + if (read(fd, val, sizeof(long)) != sizeof(long)) + return (0); + return (1); } static pt_entry_t *ptes = NULL; -static addr_to_offset(unsigned long addr, unsigned long *ret, int fd) +static +addr_to_offset(unsigned long addr, unsigned long *ret, int fd) { off_t symoff; - pt_entry_t pte, *val; + pt_entry_t pte, *val; char *str, *ptr; - if (IS_SEG1_VA(addr)){ - if(ptes == NULL){ + if (IS_SEG1_VA(addr)) { + if (ptes == NULL) { int i, loc; unsigned long loc1, loc2[2]; - findsym ("kernel_pmap", &symoff); + findsym("kernel_pmap", &symoff); loc1 = coreadj(symoff); - /*printf("ptes=%lx -> %lx\n", symoff, loc1);*/ - if (lseek(fd, loc1, L_SET/*0*/) != loc1) { + /*printf("ptes=%lx -> %lx\n", symoff, loc1); */ + if (lseek(fd, loc1, L_SET /*0 */ ) != loc1) { perror("lseek"); exit(1); } if ((i = read(fd, (char *)&loc1, sizeof(long))) != sizeof(long)) { printf("Read of kerne_map failed\n"); - return; /*exit(1);*/ + return; /*exit(1); */ } loc = loc1; - /*printf("loc1 %lx -> %lx\n", loc1, loc);*/ - if (lseek(fd, loc, L_SET/*0*/) != loc) { + /*printf("loc1 %lx -> %lx\n", loc1, loc); */ + if (lseek(fd, loc, L_SET /*0 */ ) != loc) { perror("lseek"); exit(1); } - if ((i = read(fd, (char *)loc2, 2*sizeof(long))) != 2*sizeof(long)) { + if ((i = + read(fd, (char *)loc2, + 2 * sizeof(long))) != 2 * sizeof(long)) { printf("Read of kerne_map failed\n"); - return; /*exit(1);*/ + return; /*exit(1); */ } ptes = (pt_entry_t *) loc2[1]; - /*printf("ptes=%lx\n", ptes);*/ + /*printf("ptes=%lx\n", ptes); */ } - if(!addr_to_offset((unsigned long) (ptes + LEVEL1_PT_OFFSET(addr)), (unsigned long *) &val, fd)) return(0); - if(!read_addr(fd, (unsigned long) val, (unsigned long *) &pte)) return(0); + if (!addr_to_offset + ((unsigned long)(ptes + LEVEL1_PT_OFFSET(addr)), + (unsigned long *)&val, fd)) + return (0); + if (!read_addr(fd, (unsigned long)val, (unsigned long *)&pte)) + return (0); val = ((pt_entry_t *) PTETOPHYS(&pte)) + LEVEL2_PT_OFFSET(addr); - if(!read_addr(fd, (unsigned long) val, (unsigned long *) &pte)) return(0); + if (!read_addr(fd, (unsigned long)val, (unsigned long *)&pte)) + return (0); val = ((pt_entry_t *) PTETOPHYS(&pte)) + LEVEL3_PT_OFFSET(addr); - if(!read_addr(fd, (unsigned long) val, (unsigned long *) &pte)) return(0); - *ret = PTETOPHYS(&pte) + (addr & ((1 << PGSHIFT) - 1)); - return(1); - } else if(IS_KSEG_VA(addr)) { + if (!read_addr(fd, (unsigned long)val, (unsigned long *)&pte)) + return (0); + *ret = PTETOPHYS(&pte) + (addr & ((1 << PGSHIFT) - 1)); + return (1); + } else if (IS_KSEG_VA(addr)) { *ret = KSEG_TO_PHYS(addr); - return(1); + return (1); } else { - return(0); + return (0); } } #endif #ifndef AFS_KDUMP_LIB -void kread(int kmem,off_t loc,void *buf,KDUMP_SIZE_T len) +void +kread(int kmem, off_t loc, void *buf, KDUMP_SIZE_T len) { int i; @@ -2113,7 +2288,7 @@ void kread(int kmem,off_t loc,void *buf,KDUMP_SIZE_T len) if (mem) { unsigned long ret; i = addr_to_offset(loc, &ret, kmem); - if (i == 1) + if (i == 1) loc = ret; else { unsigned long loc1; @@ -2126,7 +2301,7 @@ void kread(int kmem,off_t loc,void *buf,KDUMP_SIZE_T len) #ifndef AFS_SUN5_ENV if (mem) { #endif - readmem(kmem, buf, (off_t)loc, len); + readmem(kmem, buf, (off_t) loc, len); return; #ifndef AFS_SUN5_ENV } @@ -2135,25 +2310,28 @@ void kread(int kmem,off_t loc,void *buf,KDUMP_SIZE_T len) #endif #if ! defined(AFS_SUN5_ENV) #if defined(AFS_SGI61_ENV) && !defined(AFS_32BIT_KERNEL_ENV) - if (lseek64(kmem, loc, L_SET/*0*/) != loc) + if (lseek64(kmem, loc, L_SET /*0 */ ) != loc) #else - if (lseek(kmem, loc, L_SET/*0*/) != loc) + if (lseek(kmem, loc, L_SET /*0 */ ) != loc) #endif - { - perror("lseek"); - exit(1); - } - if ((i = read(kmem, buf, len)) != len) { - printf("WARNING: Read failed: "); - if (sizeof(loc) > sizeof(long)) { - printf("loc=%llx", loc); - } else { - printf("loc=%lx", (long) loc); - } - printf(", buf=%lx, len=%ld, i=%d, errno=%d\n", - (long) buf, (long) len, i, errno); - return; /*exit(1);*/ + { + perror("lseek"); + exit(1); } + if (loc == 0) + printf("WARNING: Read failed: loc=0\n"); + else + if ((i = read(kmem, buf, len)) != len) { + printf("WARNING: Read failed: "); + if (sizeof(loc) > sizeof(long)) { + printf("loc=%llx", loc); + } else { + printf("loc=%lx", (long)loc); + } + printf(", buf=%lx, len=%ld, i=%d, errno=%d\n", (long)buf, + (long)len, i, errno); + return; /*exit(1); */ + } #endif } #endif /* AFS_KDUMP_LIB */ @@ -2166,29 +2344,30 @@ void kread(int kmem,off_t loc,void *buf,KDUMP_SIZE_T len) * the macro RDSYMBOLS */ -rdsymbols() { +rdsymbols() +{ - FILE *fp; - Elf *efd; - Elf_Scn *cn = NULL; + FILE *fp; + Elf *efd; + Elf_Scn *cn = NULL; #ifdef _LP64 - Elf64_Shdr *shdr; - Elf64_Sym *stbl, *p1, *p2; - Elf64_Shdr * ( * elf_getshdr)(Elf_Scn *) = elf64_getshdr; + Elf64_Shdr *shdr; + Elf64_Sym *stbl, *p1, *p2; + Elf64_Shdr *(*elf_getshdr) (Elf_Scn *) = elf64_getshdr; #else Elf32_Shdr *shdr; - Elf32_Sym *stbl, *p1, *p2; - Elf32_Shdr * ( * elf_getshdr)(Elf_Scn *) = elf32_getshdr; + Elf32_Sym *stbl, *p1, *p2; + Elf32_Shdr *(*elf_getshdr) (Elf_Scn *) = elf32_getshdr; #endif - Elf_Data *dp = NULL, *sdp = NULL; + Elf_Data *dp = NULL, *sdp = NULL; - int nsyms, i, fd; + int nsyms, i, fd; if (!(fp = fopen(obj, "r"))) { - printf("Can't open %s (%d)\n", core, errno); - exit(1); + printf("Can't open %s (%d)\n", core, errno); + exit(1); } - + fd = fileno(fp); lseek(fd, 0L, 0); if ((efd = elf_begin(fd, ELF_C_READ, 0)) == NULL) { @@ -2197,15 +2376,15 @@ rdsymbols() { } while (cn = elf_nextscn(efd, cn)) { if ((shdr = elf_getshdr(cn)) == NULL) { - elf_end(efd); + elf_end(efd); printf("Can't read section header (%d)\n", errno); exit(1); } if (shdr->sh_type == SHT_SYMTAB) break; - } + } dp = elf_getdata(cn, dp); - p1 = stbl = (void *) dp->d_buf; + p1 = stbl = (void *)dp->d_buf; nsyms = dp->d_size / sizeof(*stbl); cn = elf_getscn(efd, shdr->sh_link); sdp = elf_getdata(cn, sdp); @@ -2227,8 +2406,9 @@ rdsymbols() { #endif /** AFS_SUN5_ENV **/ -int opencore(core) - char *core; +int +opencore(core) + char *core; { #ifdef AFS_KDUMP_LIB return 0; @@ -2241,63 +2421,66 @@ int opencore(core) #endif if ((kd = kvm_open(obj, core, NULL, O_RDONLY, "crash")) == NULL) { - printf("Can't open kvm - core file %s\n", core); + printf("Can't open kvm - core file %s\n", core); exit(1); } - #ifndef AFS_SUN5_ENV - } else + } else #endif #ifdef AFS_SUN5_ENV - rdsymbols(); + rdsymbols(); #endif #endif /* sparc */ - { - if ((fd = open(core, O_RDONLY)) < 0) { - perror(core); - exit(1); + { + if ((fd = open(core, O_RDONLY)) < 0) { + perror(core); + exit(1); + } + return fd; } - return fd; - } #endif /* AFS_KDUMP_LIB */ } -void print_exporter(kmem, exporter, ptr, pnt) - int kmem, pnt; - struct afs_exporter *exporter, *ptr; +void +print_exporter(kmem, exporter, ptr, pnt) + int kmem, pnt; + struct afs_exporter *exporter, *ptr; { if (pnt) { - printf("\tstates=%x, type=%x, *data=%lx\n", - exporter->exp_states, exporter->exp_type, exporter->exp_data); - printf("\texp_stats (calls=%d, rejectedcalls=%d, nopag=%d, invalidpag=%d)\n", - exporter->exp_stats.calls, exporter->exp_stats.rejectedcalls, - exporter->exp_stats.nopag, exporter->exp_stats.invalidpag); + printf("\tstates=%x, type=%x, *data=%lx\n", exporter->exp_states, + exporter->exp_type, exporter->exp_data); + printf + ("\texp_stats (calls=%d, rejectedcalls=%d, nopag=%d, invalidpag=%d)\n", + exporter->exp_stats.calls, exporter->exp_stats.rejectedcalls, + exporter->exp_stats.nopag, exporter->exp_stats.invalidpag); } } -void print_nfsclient(kmem, ep, ptr, pnt) - int kmem, pnt; - struct nfsclientpag *ep, *ptr; +void +print_nfsclient(kmem, ep, ptr, pnt) + int kmem, pnt; + struct nfsclientpag *ep, *ptr; { char sysname[100]; if (ep->sysname) { - kread(kmem, (off_t) ep->sysname, sysname, (KDUMP_SIZE_T)30); + kread(kmem, (off_t) ep->sysname, sysname, (KDUMP_SIZE_T) 30); Sum_nfssysnames += MAXSYSNAME; } - if (pnt) printf("%lx: uid=%d, host=%x, pag=%x, @sys=%s, lastt=%d, ref=%d\n", - ptr, ep->uid, ep->host , ep->pag, (ep->sysname ? sysname : "nil"), - ep->lastcall, ep->refCount); + if (pnt) + printf("%lx: uid=%d, host=%x, pag=%x, @sys=%s, lastt=%d, ref=%d\n", + ptr, ep->uid, ep->host, ep->pag, + (ep->sysname ? sysname : "nil"), ep->lastcall, ep->refCount); } #if defined(AFS_SUN5_ENV) pmutex(sp, mp) -char *sp; -kmutex_t *mp; + char *sp; + kmutex_t *mp; { #ifdef AFS_SUN54_ENV @@ -2310,48 +2493,54 @@ kmutex_t *mp; #endif -void print_unixuser(kmem, uep, ptr, pnt) - int kmem, pnt; - struct unixuser *uep, *ptr; +void +print_unixuser(kmem, uep, ptr, pnt) + int kmem, pnt; + struct unixuser *uep, *ptr; { Sum_userstp += uep->stLen; if (pnt) { - printf("%lx: uid=x%x, cell=%x, vid=%d, refc=%d, states=%x, tokTime=%d, tikLen=%d\n", - ptr, uep->uid, uep->cell, uep->vid, uep->refCount, uep->states, - uep->tokenTime, uep->stLen); - printf("\tstp=%lx, clearTok[Han=x%x, x<%x,%x,%x,%x,%x,%x,%x,%x>, vid=%d, Bt=%d, Et=%d], exporter=%lx\n", - uep->stp, uep->ct.AuthHandle, - uep->ct.HandShakeKey[0], uep->ct.HandShakeKey[1], uep->ct.HandShakeKey[2], - uep->ct.HandShakeKey[3], uep->ct.HandShakeKey[4], uep->ct.HandShakeKey[5], - uep->ct.HandShakeKey[6], uep->ct.HandShakeKey[7], uep->ct.ViceId, - uep->ct.BeginTimestamp, uep->ct.EndTimestamp, uep->exporter); + printf + ("%lx: uid=x%x, cell=%x, vid=%d, refc=%d, states=%x, tokTime=%d, tikLen=%d\n", + ptr, uep->uid, uep->cell, uep->vid, uep->refCount, uep->states, + uep->tokenTime, uep->stLen); + printf + ("\tstp=%lx, clearTok[Han=x%x, x<%x,%x,%x,%x,%x,%x,%x,%x>, vid=%d, Bt=%d, Et=%d], exporter=%lx\n", + uep->stp, uep->ct.AuthHandle, uep->ct.HandShakeKey[0], + uep->ct.HandShakeKey[1], uep->ct.HandShakeKey[2], + uep->ct.HandShakeKey[3], uep->ct.HandShakeKey[4], + uep->ct.HandShakeKey[5], uep->ct.HandShakeKey[6], + uep->ct.HandShakeKey[7], uep->ct.ViceId, uep->ct.BeginTimestamp, + uep->ct.EndTimestamp, uep->exporter); } } -void print_cell(kmem, clep, ptr, pnt) - int kmem, pnt; - struct cell *clep, *ptr; +void +print_cell(kmem, clep, ptr, pnt) + int kmem, pnt; + struct cell *clep, *ptr; { int i; char cellName[100]; struct in_addr in; - kread(kmem, (off_t) clep->cellName, cellName, (KDUMP_SIZE_T)40); + kread(kmem, (off_t) clep->cellName, cellName, (KDUMP_SIZE_T) 40); cellName[40] = 0; - Sum_cellnames += strlen(cellName)+1; + Sum_cellnames += strlen(cellName) + 1; if (pnt) { - printf("%lx: cellname=%s, states=%x, cnum=%d, cindex=%d fsport=%d vlport=%d timeout=%d cnamep=%x\n", ptr, - cellName, clep->states, clep->cellNum, clep->cellIndex, - clep->fsport, clep->vlport, clep->timeout, clep->cnamep); - + printf + ("%lx: cellname=%s, states=%x, cnum=%d, cindex=%d fsport=%d vlport=%d timeout=%d cnamep=%x\n", + ptr, cellName, clep->states, clep->cellNum, clep->cellIndex, + clep->fsport, clep->vlport, clep->timeout, clep->cnamep); #ifdef AFS33 if (clep->lcellp) printf("\tlinked cellp %lx\n", clep->lcellp); #endif printf("\tCell's servers: "); - for (i=0; icellHosts[i] == 0)) break; + for (i = 0; i < MAXCELLHOSTS; i++) { + if (pretty && (clep->cellHosts[i] == 0)) + break; printf("[%lx] ", clep->cellHosts[i]); } printf("\n"); @@ -2359,41 +2548,50 @@ void print_cell(kmem, clep, ptr, pnt) } -void print_server(kmem, sep, ptr, conns, pnt) - int kmem, conns, pnt; - struct server *sep, *ptr; +void +print_server(kmem, sep, ptr, conns, pnt) + int kmem, conns, pnt; + struct server *sep, *ptr; { struct srvAddr sa, *sap = &sa, *sap1; - int j, mh=0, cnt; + int j, mh = 0, cnt; if (conns != 2 && pnt) { - printf("%lx: cell=%lx, addr=%lx, flags=0x%x, actTime=%x, lastDownS=%x, numDownIn=%d, sumofDownt=%d\n", - ptr, sep->cell, sep->addr, sep->flags, - sep->activationTime, sep->lastDowntimeStart, sep->numDowntimeIncidents, - sep->sumOfDowntimes); + printf + ("%lx: cell=%lx, addr=%lx, flags=0x%x, actTime=%x, lastDownS=%x, numDownIn=%d, sumofDownt=%d\n", + ptr, sep->cell, sep->addr, sep->flags, sep->activationTime, + sep->lastDowntimeStart, sep->numDowntimeIncidents, + sep->sumOfDowntimes); if (sep->flags & SRVR_MULTIHOMED) { if (pnt) { - printf("\tuuid=[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x] addr_uniquifier=%x\n", - sep->sr_uuid.time_low, sep->sr_uuid.time_mid, sep->sr_uuid.time_hi_and_version, - sep->sr_uuid.clock_seq_hi_and_reserved, sep->sr_uuid.clock_seq_low, sep->sr_uuid.node[0], - sep->sr_uuid.node[1], sep->sr_uuid.node[2], sep->sr_uuid.node[3], sep->sr_uuid.node[4], - sep->sr_uuid.node[5], sep->sr_addr_uniquifier); + printf + ("\tuuid=[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x] addr_uniquifier=%x\n", + sep->sr_uuid.time_low, sep->sr_uuid.time_mid, + sep->sr_uuid.time_hi_and_version, + sep->sr_uuid.clock_seq_hi_and_reserved, + sep->sr_uuid.clock_seq_low, sep->sr_uuid.node[0], + sep->sr_uuid.node[1], sep->sr_uuid.node[2], + sep->sr_uuid.node[3], sep->sr_uuid.node[4], + sep->sr_uuid.node[5], sep->sr_addr_uniquifier); } mh = 1; } - for (j=0, cnt=1, sap1 = sep->addr; sap1; sap1 = sap->next_sa, j++, cnt++) { - kread(kmem, (off_t)sap1, (char *)sap, sizeof(*sap)); + for (j = 0, cnt = 1, sap1 = sep->addr; sap1; + sap1 = sap->next_sa, j++, cnt++) { + kread(kmem, (off_t) sap1, (char *)sap, sizeof(*sap)); if (pnt) { - if (mh) { - printf("\t #%d ip-addr(%lx): [sa_ip=%s, sa_port=%d, sa_iprank=%d, sa_flags=%x, conns=%lx, server=%lx, next_bkt=%lx]\n", - cnt, sap1, PrintIPAddr(sap->sa_ip), sap->sa_portal, - sap->sa_iprank, sap->sa_flags, sap->conns, - sap->server, sap->next_bkt); + if (mh) { + printf + ("\t #%d ip-addr(%lx): [sa_ip=%s, sa_port=%d, sa_iprank=%d, sa_flags=%x, conns=%lx, server=%lx, next_bkt=%lx]\n", + cnt, sap1, PrintIPAddr(sap->sa_ip), sap->sa_portal, + sap->sa_iprank, sap->sa_flags, sap->conns, + sap->server, sap->next_bkt); } else { - printf("\t[sa_ip=%s, sa_port=%d, sa_iprank=%d, sa_flags=%x, conns=%lx, server=%lx, nexth=%lx]\n", - PrintIPAddr(sap->sa_ip), sap->sa_portal, sap->sa_iprank, - sap->sa_flags, sap->conns, sap->server, - sap->next_bkt); + printf + ("\t[sa_ip=%s, sa_port=%d, sa_iprank=%d, sa_flags=%x, conns=%lx, server=%lx, nexth=%lx]\n", + PrintIPAddr(sap->sa_ip), sap->sa_portal, + sap->sa_iprank, sap->sa_flags, sap->conns, + sap->server, sap->next_bkt); } } } @@ -2402,28 +2600,29 @@ void print_server(kmem, sep, ptr, conns, pnt) struct afs_cbr cba, *cbsap = &cba, *cbsap1; printf(" Callbacks to be returned:\n"); - for (j=0, cbsap1 = sep->cbrs; cbsap1; cbsap1 = cbsap->next, j++) { - kread(kmem, (off_t)cbsap1, (char *)cbsap, sizeof(*cbsap)); + for (j = 0, cbsap1 = sep->cbrs; cbsap1; cbsap1 = cbsap->next, j++) { + kread(kmem, (off_t) cbsap1, (char *)cbsap, sizeof(*cbsap)); printf(" #%2d) %lx [v=%d, n=%d, u=%d]\n", j, cbsap1, cbsap->fid.Volume, cbsap->fid.Vnode, cbsap->fid.Unique); } } if (conns) { - for (j=0, sap1 = sep->addr; sap1; sap1 = sap->next_sa, j++) { - kread(kmem, (off_t)sap1, (char *)sap, sizeof(*sap)); + for (j = 0, sap1 = sep->addr; sap1; sap1 = sap->next_sa, j++) { + kread(kmem, (off_t) sap1, (char *)sap, sizeof(*sap)); print_conns(kmem, sap1, sap->conns, conns, pnt); } - } else - if (pnt) printf("\n"); + } else if (pnt) + printf("\n"); } -void print_conns(kmem, srv, conns, Con, pnt) - int kmem, Con, pnt; - struct srvAddr *srv; - struct conn *conns; +void +print_conns(kmem, srv, conns, Con, pnt) + int kmem, Con, pnt; + struct srvAddr *srv; + struct conn *conns; { - struct conn *cep, ce, *centry= &ce; + struct conn *cep, ce, *centry = &ce; int i = 1; cep = (struct conn *)conns; @@ -2436,27 +2635,30 @@ void print_conns(kmem, srv, conns, Con, pnt) for (; cep; cep = centry->next, Nconns++, i++) { if (pnt && Con != 2) printf("\t #%d> ", i); - kread(kmem, (off_t)cep, (char *) centry, sizeof *centry); + kread(kmem, (off_t) cep, (char *)centry, sizeof *centry); print_conn(kmem, centry, cep, pnt); } } -void print_conn(kmem, conns, ptr, pnt) - int kmem, pnt; - struct conn *conns, *ptr; +void +print_conn(kmem, conns, ptr, pnt) + int kmem, pnt; + struct conn *conns, *ptr; { - if (!pnt) return; + if (!pnt) + return; printf("%lx: user=%lx, rx=%lx, srvr=%lx, ref=%d, port=%d, forceC=%d\n", - ptr, conns->user, conns->id, conns->srvr, conns->refCount, + ptr, conns->user, conns->id, conns->srvr, conns->refCount, conns->port, conns->forceConnectFS); } -void print_volume(kmem, vep, ptr, pnt) - int kmem, pnt; - struct volume *vep, *ptr; +void +print_volume(kmem, vep, ptr, pnt) + int kmem, pnt; + struct volume *vep, *ptr; { int i; afs_int32 *loc; @@ -2464,29 +2666,34 @@ void print_volume(kmem, vep, ptr, pnt) - loc = (afs_int32 *)&vep->lock; - if (vep->name) { - kread(kmem, (off_t) vep->name, Volname, (KDUMP_SIZE_T)40); - Sum_volnames += strlen(Volname)+1; + loc = (afs_int32 *) & vep->lock; + if (vep->name) { + kread(kmem, (off_t) vep->name, Volname, (KDUMP_SIZE_T) 40); + Sum_volnames += strlen(Volname) + 1; } - if (!pnt) return; - printf("%lx: cell=%x, vol=%d, name=%s, roVol=%d, backVol=%d\n", - ptr, vep->cell, vep->volume, (vep->name ? Volname:"nil"), vep->roVol, vep->backVol); + if (!pnt) + return; + printf("%lx: cell=%x, vol=%d, name=%s, roVol=%d, backVol=%d\n", ptr, + vep->cell, vep->volume, (vep->name ? Volname : "nil"), vep->roVol, + vep->backVol); #ifdef AFS33 - printf("\trwVol=%d, AcTime=%d, copyDate=%d, expTime=%d, vtix=%d, refC=%d, states=%x\n", - vep->rwVol, vep->accessTime, vep->copyDate, vep->expireTime, - vep->vtix, vep->refCount, vep->states); + printf + ("\trwVol=%d, AcTime=%d, copyDate=%d, expTime=%d, vtix=%d, refC=%d, states=%x\n", + vep->rwVol, vep->accessTime, vep->copyDate, vep->expireTime, + vep->vtix, vep->refCount, vep->states); #else - printf("\trwVol=%d, AcTime=%d, copyDate=%d, vtix=%d, refC=%d, states=%x\n", - vep->rwVol, vep->accessTime, vep->copyDate, vep->vtix, vep->refCount, vep->states); + printf + ("\trwVol=%d, AcTime=%d, copyDate=%d, vtix=%d, refC=%d, states=%x\n", + vep->rwVol, vep->accessTime, vep->copyDate, vep->vtix, vep->refCount, + vep->states); #endif printf("\tVolume's statuses: "); - for (i=0; i < MAXHOSTS && vep->serverHost[i]; i++) + for (i = 0; i < MAXHOSTS && vep->serverHost[i]; i++) printf("[%d] ", vep->status[i]); printf("\n"); printf("\tVolume's servers: "); - for (i=0; i < MAXHOSTS && vep->serverHost[i]; i++) + for (i = 0; i < MAXHOSTS && vep->serverHost[i]; i++) printf("[%lx] ", vep->serverHost[i]); printf("\n"); @@ -2498,31 +2705,35 @@ void print_volume(kmem, vep, ptr, pnt) #ifdef AFS33 if (vep->rootVnode) - printf("\trootVnode = %d, rootUnique = %d\n", vep->rootVnode, vep->rootUnique); + printf("\trootVnode = %d, rootUnique = %d\n", vep->rootVnode, + vep->rootUnique); #endif printf("\tlock=0x%x\n", *loc); } -void print_venusfid(string, vid) - char *string; - struct VenusFid *vid; +void +print_venusfid(string, vid) + char *string; + struct VenusFid *vid; { - printf("%s(c=%x, v=%d, n=%d, u=%d)", - string, vid->Cell, vid->Fid.Volume, vid->Fid.Vnode, vid->Fid.Unique); + printf("%s(c=%x, v=%d, n=%d, u=%d)", string, vid->Cell, vid->Fid.Volume, + vid->Fid.Vnode, vid->Fid.Unique); } -void print_vnode(kmem, vep, ptr, pnt) - int kmem, pnt; - struct vnode *vep, *ptr; +void +print_vnode(kmem, vep, ptr, pnt) + int kmem, pnt; + struct vnode *vep, *ptr; { #ifdef AFS_AIX_ENV struct gnode gnode; struct gnode *save_gnode; #endif /* AFS_AIX_ENV */ - if (!pnt) return; + if (!pnt) + return; printf("\n"); #ifdef AFS_AIX_ENV save_gnode = vep->v_gnode; @@ -2531,10 +2742,12 @@ void print_vnode(kmem, vep, ptr, pnt) #endif /* AFS_AIX_ENV */ #ifdef AFS_SUN5_ENV - printf("%x: v_type=%d, v_flag=%d, v_count=%d, \n", - ptr, vep->v_type, vep->v_flag, vep->v_count); - printf("\tv_v_stream=%x, v_pages=0x%x, v_mountdhere=%d, v_rdev=%d, v_vfsp=0x%x, v_filocks=0x%x\n", - vep->v_stream, vep->v_pages, vep->v_vfsmountedhere, vep->v_rdev, vep->v_vfsp, vep->v_filocks); + printf("%x: v_type=%d, v_flag=%d, v_count=%d, \n", ptr, vep->v_type, + vep->v_flag, vep->v_count); + printf + ("\tv_v_stream=%x, v_pages=0x%x, v_mountdhere=%d, v_rdev=%d, v_vfsp=0x%x, v_filocks=0x%x\n", + vep->v_stream, vep->v_pages, vep->v_vfsmountedhere, vep->v_rdev, + vep->v_vfsp, vep->v_filocks); pmutex("\tVnode", &vep->v_lock); printf("\tCond v: 0x%x\n", vep->v_cv); #endif @@ -2551,39 +2764,47 @@ void print_vnode(kmem, vep, ptr, pnt) #endif #ifdef AFS_LINUX22_ENV /* Print out the stat cache and other inode info. */ - printf("\ti_ino=%d, i_mode=%x, i_nlink=%d, i_uid=%d, i_gid=%d, i_size=%d\n", - vep->i_ino, vep->i_mode, vep->i_nlink, vep->i_uid, vep->i_gid, - vep->i_size); -#ifndef AFS_LINUX24_ENV - printf("\ti_atime=%u, i_mtime=%u, i_ctime=%u, i_version=%u, i_nrpages=%u\n", - vep->i_atime, vep->i_mtime, vep->i_ctime, vep->i_version, - vep->i_nrpages); + printf + ("\ti_ino=%d, i_mode=%x, i_nlink=%d, i_uid=%d, i_gid=%d, i_size=%d\n", + vep->i_ino, vep->i_mode, vep->i_nlink, vep->i_uid, vep->i_gid, + vep->i_size); +#ifdef AFS_LINUX24_ENV + printf + ("\ti_atime=%u, i_mtime=%u, i_ctime=%u, i_version=%u, i_nrpages=%u\n", + vep->i_atime, vep->i_mtime, vep->i_ctime, vep->i_version, + vep->i_data.nrpages); #else - printf("\ti_atime=%u, i_mtime=%u, i_ctime=%u, i_version=%u\n", - vep->i_atime, vep->i_mtime, vep->i_ctime, vep->i_version - ); + printf + ("\ti_atime=%u, i_mtime=%u, i_ctime=%u, i_version=%u, i_nrpages=%u\n", + vep->i_atime, vep->i_mtime, vep->i_ctime, vep->i_version, + vep->i_nrpages); #endif - printf("\ti_op=0x%x, i_dev=0x%x, i_rdev=0x%x, i_sb=0x%x\n", - vep->i_op, vep->i_dev, vep->i_rdev, vep->i_sb); + printf("\ti_op=0x%x, i_dev=0x%x, i_rdev=0x%x, i_sb=0x%x\n", vep->i_op, + vep->i_dev, vep->i_rdev, vep->i_sb); #ifdef AFS_LINUX24_ENV - printf("\ti_sem: count=%d, sleepers=%d, wait=0x%x\n", - vep->i_sem.count, vep->i_sem.sleepers, vep->i_sem.wait); +#ifdef AFS_PARISC_LINUX24_ENV + printf("\ti_sem: count=%d, wait=0x%x\n", vep->i_sem.count, + vep->i_sem.wait); #else - printf("\ti_sem: count=%d, waking=%d, wait=0x%x\n", - vep->i_sem.count, vep->i_sem.waking, vep->i_sem.wait); + printf("\ti_sem: count=%d, sleepers=%d, wait=0x%x\n", vep->i_sem.count, + vep->i_sem.sleepers, vep->i_sem.wait); +#endif +#else + printf("\ti_sem: count=%d, waking=%d, wait=0x%x\n", vep->i_sem.count, + vep->i_sem.waking, vep->i_sem.wait); #endif printf("\ti_hash=0x%x:0x%x, i_list=0x%x:0x%x, i_dentry=0x%x:0x%x\n", - vep->i_hash.prev, vep->i_hash.next, - vep->i_list.prev, vep->i_list.next, - vep->i_dentry.prev, vep->i_dentry.next); + vep->i_hash.prev, vep->i_hash.next, vep->i_list.prev, + vep->i_list.next, vep->i_dentry.prev, vep->i_dentry.next); #endif /* AFS_LINUX22_ENV */ } -void print_vcache(kmem, vep, ptr, pnt) - int kmem, pnt; - struct vcache *vep, *ptr; +void +print_vcache(kmem, vep, ptr, pnt) + int kmem, pnt; + struct vcache *vep, *ptr; { - long *loc, j=0; + long *loc, j = 0; char *cloc; struct VenusFid vid; struct axscache acc, *accp = &acc, *acp; @@ -2591,99 +2812,129 @@ void print_vcache(kmem, vep, ptr, pnt) char linkchar; if (vep->mvid) { - kread(kmem, (off_t) vep->mvid, (char *)&vid, sizeof(struct VenusFid)); + kread(kmem, (off_t) vep->mvid, (char *)&vid, sizeof(struct VenusFid)); Sum_vcachemvids++; } - if (vep->linkData) + if (vep->linkData) Sum_vcachelinkData++; loc = (long *)&vep->lock; - if (pnt) { - if (!Dvnodes) printf("\n"); + if (pnt) { + if (!Dvnodes) + printf("\n"); #ifdef AFS33 printf("%lx: refC=%d, pv=%d, pu=%d, flushDv=%d.%d, mapDV=%d.%d, ", - ptr, vep->vrefCount, vep->parentVnode, vep->parentUnique, - vep->flushDV.high, vep->flushDV.low, - vep->mapDV.high, vep->mapDV.low); + ptr, vep->vrefCount, vep->parentVnode, vep->parentUnique, + vep->flushDV.high, vep->flushDV.low, vep->mapDV.high, + vep->mapDV.low); +#ifdef AFS_64BIT_CLIENT + printf + ("truncPos=(0x%x, 0x%x),\n\tcallb=x%lx, cbE=%d, opens=%d, XoW=%d, ", + (int)vep->truncPos >> 32, (int)vep->truncPos & 0xffffffff, + vep->callback, vep->cbExpires, vep->opens, vep->execsOrWriters); +#else /* AFS_64BIT_CLIENT */ printf("truncPos=%d,\n\tcallb=x%lx, cbE=%d, opens=%d, XoW=%d, ", - vep->truncPos, vep->callback, vep->cbExpires, vep->opens, + vep->truncPos, vep->callback, vep->cbExpires, vep->opens, vep->execsOrWriters); - printf("flcnt=%d, mvstat=%d\n", - vep->flockCount, vep->mvstat); +#endif /* AFS_64BIT_CLIENT */ + printf("flcnt=%d, mvstat=%d\n", vep->flockCount, vep->mvstat); printf("\tstates=x%x, ", vep->states); #ifdef AFS_SUN5_ENV printf("vstates=x%x, ", vep->vstates); -#endif /* AFS_SUN5_ENV */ +#endif /* AFS_SUN5_ENV */ printf("dchint=%x, anyA=0x%x\n", vep->h1.dchint, vep->anyAccess); +#ifdef AFS_64BIT_CLIENT + printf("\tquick[dc=%x, stamp=%x, f=%x, min=%d, len=(0x%x, 0x%x)]\n", + vep->quick.dc, vep->quick.stamp, vep->quick.f, + vep->quick.minLoc, (int)vep->quick.len >> 32, + (int)vep->quick.len & 0xffffffff); + printf + ("\tmstat[len=(0x%x, 0x%x), DV=%d.%d, Date=%d, Owner=%d, Group=%d, Mode=0%o, linkc=%d]\n", + (int)vep->m.Length >> 32, (int)vep->m.Length & 0xffffffff, + vep->m.DataVersion.high, vep->m.DataVersion.low, vep->m.Date, + vep->m.Owner, vep->m.Group, vep->m.Mode, vep->m.LinkCount); +#else /* AFS_64BIT_CLIENT */ printf("\tquick[dc=%x, stamp=%x, f=%x, min=%d, len=%d]\n", vep->quick.dc, vep->quick.stamp, vep->quick.f, vep->quick.minLoc, vep->quick.len); - printf("\tmstat[len=%d, DV=%d.%d, Date=%d, Owner=%d, Group=%d, Mode=0%o, linkc=%d]\n", - vep->m.Length, vep->m.DataVersion.high, - vep->m.DataVersion.low, vep->m.Date, vep->m.Owner, - vep->m.Group, vep->m.Mode, vep->m.LinkCount); + printf + ("\tmstat[len=%d, DV=%d.%d, Date=%d, Owner=%d, Group=%d, Mode=0%o, linkc=%d]\n", + vep->m.Length, vep->m.DataVersion.high, vep->m.DataVersion.low, + vep->m.Date, vep->m.Owner, vep->m.Group, vep->m.Mode, + vep->m.LinkCount); +#endif /* AFS_64BIT_CLIENT */ #else /* AFS33 */ - printf("%x: refC=%d, pv=%d, pu=%d, flushDv=%d, mapDV=%d, truncPos=%d\n", - ptr, vep->vrefCount, vep->parentVnode, vep->parentUnique, vep->flushDV, - vep->mapDV, vep->truncPos); + printf + ("%x: refC=%d, pv=%d, pu=%d, flushDv=%d, mapDV=%d, truncPos=%d\n", + ptr, vep->vrefCount, vep->parentVnode, vep->parentUnique, + vep->flushDV, vep->mapDV, vep->truncPos); printf("\tcallb=x%x, cbE=%d, opens=%d, XoW=%d, flcnt=%d, mvstat=%d\n", vep->callback, vep->cbExpires, vep->opens, vep->execsOrWriters, vep->flockCount, vep->mvstat); - printf("\tstates=x%x, dchint=%x, anyA=0x%x\n", - vep->states, vep->h1.dchint, vep->anyAccess); - printf("\tmstat[len=%d, DV=%d, Date=%d, Owner=%d, Group=%d, Mode=%d, linkc=%d]\n", - vep->m.Length, vep->m.DataVersion, vep->m.Date, vep->m.Owner, - vep->m.Group, vep->m.Mode, vep->m.LinkCount); + printf("\tstates=x%x, dchint=%x, anyA=0x%x\n", vep->states, + vep->h1.dchint, vep->anyAccess); + printf + ("\tmstat[len=%d, DV=%d, Date=%d, Owner=%d, Group=%d, Mode=%d, linkc=%d]\n", + vep->m.Length, vep->m.DataVersion, vep->m.Date, vep->m.Owner, + vep->m.Group, vep->m.Mode, vep->m.LinkCount); #endif /* AFS33 */ #ifdef AFS_AIX32_ENV - loc = (afs_int32 *)&vep->pvmlock; - printf("\tpvmlock=x%x, segid=%X, credp=%lx\n", *loc, vep->segid, vep->credp); + loc = (afs_int32 *) & vep->pvmlock; + printf("\tpvmlock=x%x, segid=%X, credp=%lx\n", *loc, vep->segid, + vep->credp); #endif - printf("\tlock [wait=%x excl=%x readers=%x #waiting=%x last_reader=%d writer=%d src=%d]\n", - vep->lock.wait_states, vep->lock.excl_locked, vep->lock.readers_reading, - vep->lock.num_waiting, vep->lock.pid_last_reader, vep->lock.pid_writer, - vep->lock.src_indicator); - print_venusfid("\tfid", &vep->fid); - if (vep->mvid) { - printf(" "); - print_venusfid("mvid", &vid); - } - printf("\n"); + printf + ("\tlock [wait=%x excl=%x readers=%x #waiting=%x last_reader=%d writer=%d src=%d]\n", + vep->lock.wait_states, vep->lock.excl_locked, + vep->lock.readers_reading, vep->lock.num_waiting, + vep->lock.pid_last_reader, vep->lock.pid_writer, + vep->lock.src_indicator); + print_venusfid("\tfid", &vep->fid); + if (vep->mvid) { + printf(" "); + print_venusfid("mvid", &vid); + } + printf("\n"); } if (vep->Access) { - if (pnt) printf("\tAccess Link list: %x\n", vep->Access); - for (j=0, acp = vep->Access; acp; acp = accp->next, j++) { + if (pnt) + printf("\tAccess Link list: %x\n", vep->Access); + for (j = 0, acp = vep->Access; acp; acp = accp->next, j++) { kread(kmem, (off_t) acp, (char *)accp, sizeof(*accp)); Sum_vcacheacc++; - if (pnt) printf("\t %lx: %d) uid=0x%x, access=0x%x, next=%lx\n", acp, j, accp->uid, accp->axess, accp->next); + if (pnt) + printf("\t %lx: %d) uid=0x%x, access=0x%x, next=%lx\n", acp, + j, accp->uid, accp->axess, accp->next); } } if (vep->slocks) { - if (pnt) printf("\tLocking Link list: %lx\n", vep->slocks); + if (pnt) + printf("\tLocking Link list: %lx\n", vep->slocks); } #ifdef AFS33 - if (pnt) printf("\tCallbacks queue prev= %lx next= %lx\n", - vep->callsort.prev, vep->callsort.next); + if (pnt) + printf("\tCallbacks queue prev= %lx next= %lx\n", vep->callsort.prev, + vep->callsort.next); #endif - printf("\tvlruq.prev=%lx, vlruq.next=%lx\n", - vep->vlruq.prev, vep->vlruq.next); + printf("\tvlruq.prev=%lx, vlruq.next=%lx\n", vep->vlruq.prev, + vep->vlruq.next); /* For defect 7733 - Print linkData field for symlinks */ if (pnt) { - if (vep->linkData) { - cloc = (char *)vep->linkData; - printf("\tSymlink information = '"); - while(1) { - kread(kmem, (off_t) cloc, &linkchar, (KDUMP_SIZE_T)1); - cloc++; - if (linkchar == '\0') { - printf("'\n"); - break; - } else { - printf("%c", linkchar); - } + if (vep->linkData) { + cloc = (char *)vep->linkData; + printf("\tSymlink information = '"); + while (1) { + kread(kmem, (off_t) cloc, &linkchar, (KDUMP_SIZE_T) 1); + cloc++; + if (linkchar == '\0') { + printf("'\n"); + break; + } else { + printf("%c", linkchar); } - } + } + } } #ifdef AFS_LINUX22_ENV printf("\tflushcnt=%d, mapcnt=%d\n", vep->flushcnt, vep->mapcnt); @@ -2691,135 +2942,145 @@ void print_vcache(kmem, vep, ptr, pnt) } -void print_dcache(kmem, dcp, dp, pnt) - int kmem, pnt; - struct dcache *dcp, *dp; +void +print_dcache(kmem, dcp, dp, pnt) + int kmem, pnt; + struct dcache *dcp, *dp; { - if (!pnt) return; + if (!pnt) + return; printf("%lx: ", dp); print_venusfid(" fid", &dcp->f.fid); - printf("refcnt=%d, flags=%x, validPos=%d\n", - dcp->refCount, dcp->flags, dcp->validPos); + printf("refcnt=%d, dflags=%x, mflags=%x, validPos=%d\n", dcp->refCount, + dcp->dflags, dcp->mflags, dcp->validPos); #ifdef AFS33 - printf("\tf.modtime=%d, f.versNo=%d.%d\n", - dcp->f.modTime, + printf("\tf.modtime=%d, f.versNo=%d.%d\n", dcp->f.modTime, dcp->f.versionNo.high, dcp->f.versionNo.low); #else printf("\tf.hvn=%d, f.hcn=%d, f.modtime=%d, f.versNo=%d\n", dcp->f.hvNextp, dcp->f.hcNextp, dcp->f.modTime, dcp->f.versionNo); #endif #ifdef AFS_SGI62_ENV - printf("\tf.chunk=%d, f.inode=%lld, f.chunkBytes=%d, f.states=%x, stamp=%x\n", - dcp->f.chunk, dcp->f.inode, dcp->f.chunkBytes, dcp->f.states, - dcp->stamp); + printf + ("\tf.chunk=%d, f.inode=%lld, f.chunkBytes=%d, f.states=%x, stamp=%x\n", + dcp->f.chunk, dcp->f.inode, dcp->f.chunkBytes, dcp->f.states, + dcp->stamp); #else - printf("\tf.chunk=%d, f.inode=%d, f.chunkBytes=%d, f.states=%x, stamp=%x\n", - dcp->f.chunk, dcp->f.inode, dcp->f.chunkBytes, dcp->f.states, - dcp->stamp); + printf + ("\tf.chunk=%d, f.inode=%d, f.chunkBytes=%d, f.states=%x, stamp=%x\n", + dcp->f.chunk, dcp->f.inode, dcp->f.chunkBytes, dcp->f.states, + dcp->stamp); #endif printf("\tlruq.prev=%lx, lruq.next=%lx, index=%d, ihint=%x\n", dcp->lruq.prev, dcp->lruq.next, dcp->index, dcp->ihint); } -void print_bkg(kmem) - int kmem; +void +print_bkg(kmem) + int kmem; { off_t symoff; - struct brequest afs_brs[NBRS], ue,*uentry= &ue, *uep; + struct brequest afs_brs[NBRS], ue, *uentry = &ue, *uep; afs_int32 count, i, j; short scount; printf("\n\nPrinting some background daemon info...\n\n"); - findsym ("afs_brsWaiters", &symoff); - kread(kmem, symoff, (char *) &scount, sizeof scount); + findsym("afs_brsWaiters", &symoff); + kread(kmem, symoff, (char *)&scount, sizeof scount); printf("Number of processes waiting for bkg daemon %d\n", scount); - findsym ("afs_brsDaemons", &symoff); - kread(kmem, symoff, (char *) &scount, sizeof scount); + findsym("afs_brsDaemons", &symoff); + kread(kmem, symoff, (char *)&scount, sizeof scount); printf("Number of free bkg daemons %d\n", scount); - findsym ("afs_brs", &symoff); - kread(kmem, symoff, (char *) afs_brs, sizeof afs_brs); - printf("Print the current bkg process table\n"); - for (i=0,j=0; i < NBRS; i++, j++) { + findsym("afs_brs", &symoff); + kread(kmem, symoff, (char *)afs_brs, sizeof afs_brs); + printf("Print the current bkg process table\n"); + for (i = 0, j = 0; i < NBRS; i++, j++) { /* kread(kmem, (off_t) afs_brs[i], (char *)uentry, sizeof *uentry);*/ uentry = &afs_brs[i]; - if (uentry->refCount == 0) break; - printf("[%d] vcache=0x%lx, cred=0x%lx, code=%d, refCount=%d, opcode=%d, flags=%x [%lx, %lx, %lx, %lx]\n", - i, uentry->vnode, uentry->cred, uentry->code, uentry->refCount, uentry->opcode, uentry->flags, - uentry->parm[0], uentry->parm[1], uentry->parm[2], uentry->parm[3]); + if (uentry->refCount == 0) + break; + printf + ("[%d] vcache=0x%lx, cred=0x%lx, code=%d, refCount=%d, opcode=%d, flags=%x [%lx, %lx, %lx, %lx]\n", + i, uentry->vc, uentry->cred, uentry->code, uentry->refCount, + uentry->opcode, uentry->flags, uentry->size_parm[0], + uentry->size_parm[1], uentry->ptr_parm[0], uentry->ptr_parm[1]); } printf("... found %d active 'afs_brs' entries\n", j); } -void print_vlru(kmem) - int kmem; +void +print_vlru(kmem) + int kmem; { off_t symoff; struct vcache Ve, *Ventry = &Ve, *Vep, *tvc; struct afs_q VLRU, vlru, *vu = &vlru, *tq, *uq; u_long vlru_addr, l1, l2, l3; - afs_int32 count, i, j=0, maxvcount, vcount, nvnode; + afs_int32 count, i, j = 0, maxvcount, vcount, nvnode; short scount; printf("\n\nPrinting vcache VLRU info (oldest first)...\n\n"); - findsym( "afs_cacheStats", &symoff); - kread(kmem, symoff, (char *) &maxvcount, sizeof maxvcount); + findsym("afs_cacheStats", &symoff); + kread(kmem, symoff, (char *)&maxvcount, sizeof maxvcount); #ifdef AFS_OSF_ENV - findsym ("afs_maxvcount", &symoff); - kread(kmem, symoff, (char *) &maxvcount, sizeof maxvcount); - findsym ("afs_vcount", &symoff); - kread(kmem, symoff, (char *) &vcount, sizeof vcount); - findsym ("max_vnodes", &symoff); - kread(kmem, symoff, (char *) &nvnode, sizeof nvnode); + findsym("afs_maxvcount", &symoff); + kread(kmem, symoff, (char *)&maxvcount, sizeof maxvcount); + findsym("afs_vcount", &symoff); + kread(kmem, symoff, (char *)&vcount, sizeof vcount); + findsym("max_vnodes", &symoff); + kread(kmem, symoff, (char *)&nvnode, sizeof nvnode); printf("max number of vcache entries = %d\n", maxvcount); printf("number of vcaches in use = %d\n", vcount); printf("total number of system vnode entries = %d\n", nvnode); #endif - findsym ("VLRU", &symoff); - kread(kmem, symoff, (char *) &VLRU, sizeof VLRU); - vlru_addr = (u_long)symoff; - for (tq = VLRU.prev; (u_long)tq != vlru_addr; tq = uq) { + findsym("VLRU", &symoff); + kread(kmem, symoff, (char *)&VLRU, sizeof VLRU); + vlru_addr = (u_long) symoff; + for (tq = VLRU.prev; (u_long) tq != vlru_addr; tq = uq) { tvc = QTOV(tq); - kread(kmem, (off_t)tq, (char *)vu, sizeof VLRU); + kread(kmem, (off_t) tq, (char *)vu, sizeof VLRU); uq = vu->prev; - kread(kmem, (off_t)tvc, (char *)Ventry, sizeof *Ventry); + kread(kmem, (off_t) tvc, (char *)Ventry, sizeof *Ventry); print_vcache(kmem, Ventry, tvc, 1); j++; } printf("... found %d active vcache entries in the VLRU\n", j); } -void print_dlru(kmem) - int kmem; +void +print_dlru(kmem) + int kmem; { off_t symoff; struct dcache Ve, *Ventry = &Ve, *Vep, *tdc; struct afs_q DLRU, dlru, *vu = &dlru, *tq, *uq; u_long dlru_addr, l1, l2, l3; - afs_int32 count, i, j=0, maxvcount, vcount, nvnode; + afs_int32 count, i, j = 0, maxvcount, vcount, nvnode; short scount; printf("\n\nPrinting vcache DLRU info...\n\n"); - findsym ("afs_DLRU", &symoff); - kread(kmem, symoff, (char *) &DLRU, sizeof DLRU); - dlru_addr = (u_long)symoff; - for (tq = DLRU.prev; (u_long)tq != dlru_addr; tq = uq) { - tdc = (struct dcache *) tq; - kread(kmem, (off_t)tq, (char *)vu, sizeof DLRU); + findsym("afs_DLRU", &symoff); + kread(kmem, symoff, (char *)&DLRU, sizeof DLRU); + dlru_addr = (u_long) symoff; + for (tq = DLRU.prev; (u_long) tq != dlru_addr; tq = uq) { + tdc = (struct dcache *)tq; + kread(kmem, (off_t) tq, (char *)vu, sizeof DLRU); uq = vu->prev; - kread(kmem, (off_t)tdc, (char *)Ventry, sizeof *Ventry); + kread(kmem, (off_t) tdc, (char *)Ventry, sizeof *Ventry); print_dcache(kmem, Ventry, tdc, 1); j++; } printf("... found %d active dcache entries in the DLRU\n\n\n", j); findsym("afs_freeDSList", &symoff); - kread(kmem, symoff, (char *) &dlru_addr, sizeof dlru_addr); + kread(kmem, symoff, (char *)&dlru_addr, sizeof dlru_addr); printf("\tfreeDSList link list starts at 0x%x\n", dlru_addr); - j=0; - for (tdc = (struct dcache *)dlru_addr; tdc; tdc = (struct dcache *)Ventry->lruq.next) { - kread(kmem, (off_t)tdc, (char *)Ventry, sizeof *Ventry); + j = 0; + for (tdc = (struct dcache *)dlru_addr; tdc; + tdc = (struct dcache *)Ventry->lruq.next) { + kread(kmem, (off_t) tdc, (char *)Ventry, sizeof *Ventry); print_dcache(kmem, Ventry, tdc, 1); j++; /* printf("%3d) %x\n", j, tdc);*/ @@ -2827,20 +3088,23 @@ void print_dlru(kmem) printf("... found %d dcache entries in the freeDSList\n", j); } -int print_gcpags(pnt) -int pnt; +int +print_gcpags(pnt) + int pnt; { off_t symoff; afs_int32 afs_gcpags; afs_int32 afs_gcpags_procsize; - if (pnt) printf("\n\nPrinting GCPAGS structures...\n"); + if (pnt) + printf("\n\nPrinting GCPAGS structures...\n"); - findsym( "afs_gcpags", &symoff); - kread(kmem, symoff, (char*)&afs_gcpags, sizeof afs_gcpags); + findsym("afs_gcpags", &symoff); + kread(kmem, symoff, (char *)&afs_gcpags, sizeof afs_gcpags); - findsym( "afs_gcpags_procsize", &symoff); - kread(kmem, symoff, (char*)&afs_gcpags_procsize, sizeof afs_gcpags_procsize); + findsym("afs_gcpags_procsize", &symoff); + kread(kmem, symoff, (char *)&afs_gcpags_procsize, + sizeof afs_gcpags_procsize); printf("afs_gcpags=%d\n", afs_gcpags); printf("afs_gcpags_procsize=%d\n", afs_gcpags_procsize); @@ -2850,27 +3114,28 @@ int pnt; #ifdef AFS_AIX_ENV -#include /* to define the assert and ASSERT macros */ -#include /* For the timer related defines */ -#include /* for the serialization defines */ -#include /* for the parameters to xmalloc() */ - -struct tos { - struct tos *toprev; /* previous tos in callout table*/ - struct tos *tonext; /* next tos in callout table */ - struct trb *trb; /* this timer request block */ - afs_int32 type; - long p1; +#include /* to define the assert and ASSERT macros */ +#include /* For the timer related defines */ +#include /* for the serialization defines */ +#include /* for the parameters to xmalloc() */ + +struct tos { + struct tos *toprev; /* previous tos in callout table */ + struct tos *tonext; /* next tos in callout table */ + struct trb *trb; /* this timer request block */ + afs_int32 type; + long p1; }; -struct callo { - int ncallo; /* number of callout table elements */ - struct tos *head; /* callout table head element */ +struct callo { + int ncallo; /* number of callout table elements */ + struct tos *head; /* callout table head element */ }; #endif -void print_callout(kmem) - int kmem; +void +print_callout(kmem) + int kmem; { off_t symoff; #ifndef AFS_AIX_ENV @@ -2879,72 +3144,77 @@ void print_callout(kmem) struct callo Co, *Coe = &Co, *Cop; struct tos To, *Toe = &To, *tos; struct trb Trb, *Trbe = &Trb, *trb; - register int i =0; + register int i = 0; printf("\n\nPrinting callout table info...\n\n"); - findsym ("afs_callo", &symoff); - kread(kmem, symoff, (char *) &Co, sizeof Co); + findsym("afs_callo", &symoff); + kread(kmem, symoff, (char *)&Co, sizeof Co); printf("Number of callouts %d\n", Co.ncallo); if (Co.ncallo > 0) { printf("Count\tType\taddr\tfunc\tdata\n"); - for (tos = Co.head; tos != NULL; tos = Toe->tonext) { + for (tos = Co.head; tos != NULL; tos = Toe->tonext) { i++; - kread(kmem, (off_t) tos, (char *) &To, sizeof To); - kread(kmem, (off_t) Toe->trb, (char *) &Trb, sizeof Trb); - printf("%d\t%d\t%x\t%x\t%x\n", i, Toe->type, Toe->p1, Trbe->tof, Trbe->func_data); + kread(kmem, (off_t) tos, (char *)&To, sizeof To); + kread(kmem, (off_t) Toe->trb, (char *)&Trb, sizeof Trb); + printf("%d\t%d\t%x\t%x\t%x\n", i, Toe->type, Toe->p1, Trbe->tof, + Trbe->func_data); } } #endif } -void print_dnlc(kmem) - int kmem; +void +print_dnlc(kmem) + int kmem; { - struct nc * nameHash[256]; + struct nc *nameHash[256]; } -void print_global_locks(kmem) - int kmem; +void +print_global_locks(kmem) + int kmem; { off_t symoff; afs_int32 count; int i; static struct { - char *name; - } locks[] = { { "afs_xvcache" }, - { "afs_xdcache" }, - { "afs_xserver" }, - { "afs_xvcb" }, - { "afs_xbrs" }, - { "afs_xcell" }, - { "afs_xconn" }, - { "afs_xuser" }, - { "afs_xvolume" }, + char *name; + } locks[] = { { + "afs_xvcache"}, { + "afs_xdcache"}, { + "afs_xserver"}, { + "afs_xvcb"}, { + "afs_xbrs"}, { + "afs_xcell"}, { + "afs_xconn"}, { + "afs_xuser"}, { + "afs_xvolume"}, #ifndef AFS_AIX_ENV - { "osi_fsplock" }, + { + "osi_fsplock"}, #endif - { "osi_flplock" }, - { "afs_xcbhash" }, - { "afs_xinterface" }, - - { 0 }, - }; + { + "osi_flplock"}, { + "afs_xcbhash"}, { + "afs_xinterface"}, { + 0},}; printf("\n\nPrinting afs global locks...\n\n"); - for (i=0; locks[i].name; i++) { - findsym( locks[i].name, &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); - printf("%s = 0x%x\n", locks[i].name, count); + for (i = 0; locks[i].name; i++) { + findsym(locks[i].name, &symoff); + kread(kmem, symoff, (char *)&count, sizeof count); + printf("%s = 0x%x\n", locks[i].name, count); } } -void print_global_afs_resource(kmem) - int kmem; +void +print_global_afs_resource(kmem) + int kmem; { off_t symoff; char sysname[100]; @@ -2952,122 +3222,124 @@ void print_global_afs_resource(kmem) long addr; printf("\n\nPrinting some general resource related globals...\n\n"); - findsym ("afs_setTimeHost",&symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + findsym("afs_setTimeHost", &symoff); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_setTimeHost = 0x%x\n", count); findsym("afs_volCounter", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_volCounter = 0x%x\n", count); findsym("afs_cellindex", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_cellIndex = 0x%x\n", count); findsym("afs_marinerHost", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_marinerHost = 0x%x\n", count); findsym("afs_sysname", &symoff); - kread(kmem, symoff, (char *) &addr, sizeof addr); + kread(kmem, symoff, (char *)&addr, sizeof addr); #ifdef AFS_HPUX_ENV printf("\tafs_sysname = %d\n", addr); #else - kread(kmem, (off_t)addr, sysname, (KDUMP_SIZE_T)30); + kread(kmem, (off_t) addr, sysname, (KDUMP_SIZE_T) 30); printf("\tafs_sysname = %s\n", sysname); #endif #ifdef AFS_SGI65_ENV findsym("afs_ipno", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tCPU BOARD = IP%d\n", count); #endif } -void print_global_afs_cache(kmem) - int kmem; +void +print_global_afs_cache(kmem) + int kmem; { off_t symoff; char sysname[100]; afs_int32 count; #ifdef AFS_SGI62_ENV ino64_t inode; -#endif +#endif #ifndef AFS32 afs_hyper_t h; #endif printf("\n\nPrinting some general cache related globals...\n\n"); findsym("afs_mariner", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_mariner = 0x%x\n", count); #ifndef AFS_OSF_ENV findsym("freeVCList", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_freeVCList = 0x%x XXX\n", count); #endif findsym("afs_freeDCList", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tfreeDCList = 0x%x\n", count); findsym("afs_freeDCCount", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tfreeDCCount = 0x%x (%d)\n", count, count); findsym("afs_discardDCList", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tdiscardDCList = 0x%x\n", count); findsym("afs_discardDCCount", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tdiscardDCCount = 0x%x (%d)\n", count, count); findsym("afs_freeDSList", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tfreeDSList= 0x%x XXXX\n", count); #ifdef AFS_SGI62_ENV findsym("cacheInode", &symoff); - kread(kmem, symoff, (char *) &inode, sizeof inode); + kread(kmem, symoff, (char *)&inode, sizeof inode); printf("\tcacheInode = 0x%llx (%lld)\n", inode, inode); findsym("volumeInode", &symoff); - kread(kmem, symoff, (char *) &inode, sizeof inode); + kread(kmem, symoff, (char *)&inode, sizeof inode); printf("\tvolumeInode = 0x%llx (%lld)\n", inode, inode); #else findsym("cacheInode", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tcacheInode = 0x%x (%d)\n", count, count); findsym("volumeInode", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tvolumeInode = 0x%x (%d)\n", count, count); #endif findsym("cacheDiskType", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tcacheDiskType = 0x%x (%d)\n", count, count); #ifndef AFS32 findsym("afs_indexCounter", &symoff); - kread(kmem, symoff, (char *) &h, sizeof (struct afs_hyper_t)); - printf("\tafs_indexCounter = 0x%X.%X (%d.%d)\n", h.high, h.low, h.high, h.low); + kread(kmem, symoff, (char *)&h, sizeof(struct afs_hyper_t)); + printf("\tafs_indexCounter = 0x%X.%X (%d.%d)\n", h.high, h.low, h.high, + h.low); #endif findsym("afs_cacheFiles", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_cacheFiles = 0x%x (%d)\n", count, count); findsym("afs_cacheBlocks", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_cacheBlocks = 0x%x (%d)\n", count, count); findsym("afs_cacheStats", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_cacheStats = 0x%x (%d)\n", count, count); findsym("afs_blocksUsed", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_blocksUsed = 0x%x (%d)\n", count, count); findsym("afs_blocksDiscarded", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_blocksDiscarded = 0x%x (%d)\n", count, count); findsym("afs_fsfragsize", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_fsfragsize = 0x%x\n", count); findsym("afs_WaitForCacheDrain", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_WaitForCacheDrain = 0x%x (%d)\n", count, count); findsym("afs_CacheTooFull", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tafs_CacheTooFull = 0x%x (%d)\n", count, count); if (findsym("pagCounter", &symoff)) { - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\tpagCounter = 0x%x (%d)\n", count, count); } else { printf("Ignoring pagCounter\n"); @@ -3075,8 +3347,9 @@ void print_global_afs_cache(kmem) } -void print_rxstats(kmem) - int kmem; +void +print_rxstats(kmem) + int kmem; { off_t symoff; char sysname[100]; @@ -3085,7 +3358,7 @@ void print_rxstats(kmem) printf("\n\nPrinting some general RX stats...\n\n"); findsym("rx_stats", &symoff); - kread(kmem, symoff, (char *) &rx_stats, sizeof rx_stats); + kread(kmem, symoff, (char *)&rx_stats, sizeof rx_stats); printf("\t\tpacketRequests = %d\n", rx_stats.packetRequests); printf("\t\tnoPackets[%d] = %d\n", RX_PACKET_CLASS_RECEIVE, rx_stats.receivePktAllocFailures); @@ -3101,16 +3374,17 @@ void print_rxstats(kmem) printf("\t\tbogusPacketOnRead = %d\n", rx_stats.bogusPacketOnRead); printf("\t\tbogusHost = %d\n", rx_stats.bogusHost); printf("\t\tnoPacketOnRead = %d\n", rx_stats.noPacketOnRead); - printf("\t\tnoPacketBuffersOnRead = %d\n", rx_stats.noPacketBuffersOnRead); + printf("\t\tnoPacketBuffersOnRead = %d\n", + rx_stats.noPacketBuffersOnRead); printf("\t\tselects = %d\n", rx_stats.selects); printf("\t\tsendSelects = %d\n", rx_stats.sendSelects); - for (i=0; i < RX_N_PACKET_TYPES; i++) + for (i = 0; i < RX_N_PACKET_TYPES; i++) printf("\t\tpacketsRead[%d] = %d\n", i, rx_stats.packetsRead[i]); printf("\t\tdataPacketsRead = %d\n", rx_stats.dataPacketsRead); printf("\t\tackPacketsRead = %d\n", rx_stats.ackPacketsRead); printf("\t\tdupPacketsRead = %d\n", rx_stats.dupPacketsRead); printf("\t\tspuriousPacketsRead = %d\n", rx_stats.spuriousPacketsRead); - for (i=0; i < RX_N_PACKET_TYPES; i++) + for (i = 0; i < RX_N_PACKET_TYPES; i++) printf("\t\tpacketsSent[%d] = %d\n", i, rx_stats.packetsSent[i]); printf("\t\tackPacketsSent = %d\n", rx_stats.ackPacketsSent); printf("\t\tpingPacketsSent = %d\n", rx_stats.pingPacketsSent); @@ -3120,9 +3394,12 @@ void print_rxstats(kmem) printf("\t\tdataPacketsReSent = %d\n", rx_stats.dataPacketsReSent); printf("\t\tdataPacketsPushed = %d\n", rx_stats.dataPacketsPushed); printf("\t\tignoreAckedPacket = %d\n", rx_stats.ignoreAckedPacket); - printf("\t\ttotalRtt = %d sec, %d usec\n", rx_stats.totalRtt.sec, rx_stats.totalRtt.usec); - printf("\t\tminRtt = %d sec, %d usec\n", rx_stats.minRtt.sec, rx_stats.minRtt.usec); - printf("\t\tmaxRtt = %d sec, %d usec\n", rx_stats.maxRtt.sec, rx_stats.maxRtt.usec); + printf("\t\ttotalRtt = %d sec, %d usec\n", rx_stats.totalRtt.sec, + rx_stats.totalRtt.usec); + printf("\t\tminRtt = %d sec, %d usec\n", rx_stats.minRtt.sec, + rx_stats.minRtt.usec); + printf("\t\tmaxRtt = %d sec, %d usec\n", rx_stats.maxRtt.sec, + rx_stats.maxRtt.usec); printf("\t\tnRttSamples = %d\n", rx_stats.nRttSamples); printf("\t\tnServerConns = %d\n", rx_stats.nServerConns); printf("\t\tnClientConns = %d\n", rx_stats.nClientConns); @@ -3134,8 +3411,9 @@ void print_rxstats(kmem) } -void print_rx(kmem) - int kmem; +void +print_rx(kmem) + int kmem; { off_t symoff; char sysname[100], c; @@ -3145,97 +3423,97 @@ void print_rx(kmem) printf("\n\nPrinting some RX globals...\n\n"); findsym("rx_extraQuota", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_extraQuota = %d\n", count); findsym("rx_extraPackets", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_extraPackets = %d\n", count); findsym("rx_stackSize", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_stackSize = %d\n", count); findsym("rx_connDeadTime", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_connDeadTime = %d\n", count); findsym("rx_idleConnectionTime", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_idleConnectionTime = %d\n", count); findsym("rx_idlePeerTime", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_idlePeerTime = %d\n", count); findsym("rx_initSendWindow", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_initSendWindow = %d\n", count); findsym("rxi_nSendFrags", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trxi_nSendFrags = %d\n", count); findsym("rx_nPackets", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_nPackets = %d\n", count); findsym("rx_nFreePackets", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_nFreePackets = %d\n", count); findsym("rx_socket", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_socket = 0x%x\n", count); findsym("rx_port", &symoff); - kread(kmem, symoff, (char *) &sm, sizeof sm); + kread(kmem, symoff, (char *)&sm, sizeof sm); printf("\trx_Port = %d\n", sm); findsym("rx_packetQuota", &symoff); - kread(kmem, symoff, (char *) ar, sizeof ar); + kread(kmem, symoff, (char *)ar, sizeof ar); - for (i=0; i < RX_N_PACKET_CLASSES; i++) + for (i = 0; i < RX_N_PACKET_CLASSES; i++) printf("\trx_packetQuota[%d] = %d\n", i, ar[i]); findsym("rx_nextCid", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_nextCid = 0x%x\n", count); findsym("rx_epoch", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trx_epoch = 0u%u\n", count); findsym("rx_waitingForPackets", &symoff); - kread(kmem, symoff, (char *) &c, sizeof(c)); + kread(kmem, symoff, (char *)&c, sizeof(c)); printf("\trx_waitingForPackets = %x\n", (int)c); findsym("rxi_nCalls", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trxi_nCalls = %d\n", count); findsym("rxi_dataQuota", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trxi_dataQuota = %d\n", count); #ifdef AFS_AIX_ENV if (findsym("rxi_Alloccnt", &symoff)) { - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trxi_Alloccnt = %d\n", count); } if (findsym("rxi_Allocsize", &symoff)) { - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trxi_Allocsize = %d\n", count); } #endif findsym("rxi_availProcs", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trxi_availProcs = %d\n", count); findsym("rxi_totalMin", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trxi_totalMin = %d\n", count); findsym("rxi_minDeficit", &symoff); - kread(kmem, symoff, (char *) &count, sizeof count); + kread(kmem, symoff, (char *)&count, sizeof count); printf("\trxi_minDeficit = %d\n", count); print_services(kmem); @@ -3244,8 +3522,7 @@ void print_rx(kmem) print_peertable_lock(kmem); print_conntable_lock(kmem); print_calltable_lock(kmem); - } - else { + } else { print_peertable(kmem); print_conntable(kmem); print_calltable(kmem); @@ -3260,8 +3537,9 @@ void print_rx(kmem) } -void print_services(kmem) - afs_int32 kmem; +void +print_services(kmem) + afs_int32 kmem; { off_t symoff; struct rx_service *rx_services[RX_MAX_SERVICES], se, *sentry = &se, *sep; @@ -3269,20 +3547,25 @@ void print_services(kmem) afs_int32 count, i, j; findsym("rx_services", &symoff); - kread(kmem, symoff, (char *) rx_services, RX_MAX_SERVICES * sizeof(long)); + kread(kmem, symoff, (char *)rx_services, RX_MAX_SERVICES * sizeof(long)); printf("\n\nPrinting all 'rx_services' structures...\n"); - for (i=0, j=0; i < RX_MAX_SERVICES; i++) { + for (i = 0, j = 0; i < RX_MAX_SERVICES; i++) { if (rx_services[i]) { j++; - kread(kmem, (off_t) rx_services[i], (char *)sentry, sizeof *sentry); + kread(kmem, (off_t) rx_services[i], (char *)sentry, + sizeof *sentry); kread(kmem, (off_t) sentry->serviceName, sysname, - (KDUMP_SIZE_T)40); - printf("\t%lx: serviceId=%d, port=%d, serviceName=%s, socket=0x%x\n", - rx_services[i], sentry->serviceId, sentry->servicePort, sysname, sentry->socket); - printf("\t\tnSecObj=%d, nReqRunning=%d, maxProcs=%d, minProcs=%d, connDeadTime=%d, idleDeadTime=%d\n", - sentry->nSecurityObjects, sentry->nRequestsRunning, sentry->maxProcs, sentry->minProcs, - sentry->connDeadTime, sentry->idleDeadTime); + (KDUMP_SIZE_T) 40); + printf + ("\t%lx: serviceId=%d, port=%d, serviceName=%s, socket=0x%x\n", + rx_services[i], sentry->serviceId, sentry->servicePort, + sysname, sentry->socket); + printf + ("\t\tnSecObj=%d, nReqRunning=%d, maxProcs=%d, minProcs=%d, connDeadTime=%d, idleDeadTime=%d\n", + sentry->nSecurityObjects, sentry->nRequestsRunning, + sentry->maxProcs, sentry->minProcs, sentry->connDeadTime, + sentry->idleDeadTime); } } printf("... found %d 'rx_services' entries in the table\n", j); @@ -3290,38 +3573,39 @@ void print_services(kmem) #ifdef KDUMP_RX_LOCK -void print_peertable_lock(kmem) - afs_int32 kmem; +void +print_peertable_lock(kmem) + afs_int32 kmem; { off_t symoff; struct rx_peer_rx_lock *rx_peerTable[256], se, *sentry = &se, *sep; long count, i, j; findsym("rx_peerHashTable", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(long)); + kread(kmem, symoff, (char *)&count, sizeof(long)); if (!count) { printf("No 'rx_peer' structures found.\n"); return; } - - kread(kmem, count, (char *) rx_peerTable, 256 * sizeof(long)); + + kread(kmem, count, (char *)rx_peerTable, 256 * sizeof(long)); printf("\n\nPrinting all 'rx_peer' structures...\n"); - for (i=0, j=0; i < 256; i++) { + for (i = 0, j = 0; i < 256; i++) { for (sep = rx_peerTable[i]; sep; sep = sentry->next, j++) { kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); - printf("\t%lx: next=0x%lx, host=0x%x, ", - sep, sentry->next, sentry->host); + printf("\t%lx: next=0x%lx, host=0x%x, ", sep, sentry->next, + sentry->host); printf("ifMTU=%d, natMTU=%d, maxMTU=%d\n", sentry->ifMTU, sentry->natMTU, sentry->maxMTU); printf("\t\trtt=%d:%d, timeout(%d:%d), nSent=%d, reSends=%d\n", - sentry->rtt, sentry->rtt_dev, - sentry->timeout.sec, sentry->timeout.usec, - sentry->nSent, sentry->reSends); - printf("\t\trefCount=%d, port=%d, idleWhen=0x%x\n", + sentry->rtt, sentry->rtt_dev, sentry->timeout.sec, + sentry->timeout.usec, sentry->nSent, sentry->reSends); + printf("\t\trefCount=%d, port=%d, idleWhen=0x%x\n", sentry->refCount, sentry->port, sentry->idleWhen); - printf("\t\tCongestionQueue (0x%x:0x%x), inPacketSkew=0x%x, outPacketSkew=0x%x\n", - sentry->congestionQueue.prev, sentry->congestionQueue.next, - sentry->inPacketSkew, sentry->outPacketSkew); + printf + ("\t\tCongestionQueue (0x%x:0x%x), inPacketSkew=0x%x, outPacketSkew=0x%x\n", + sentry->congestionQueue.prev, sentry->congestionQueue.next, + sentry->inPacketSkew, sentry->outPacketSkew); printf("\t\tpeer_lock=%d\n", sentry->peer_lock); } } @@ -3329,34 +3613,35 @@ void print_peertable_lock(kmem) } #endif /* KDUMP_RX_LOCK */ -void print_peertable(kmem) - afs_int32 kmem; +void +print_peertable(kmem) + afs_int32 kmem; { off_t symoff; struct rx_peer *rx_peerTable[256], se, *sentry = &se, *sep; long count, i, j; findsym("rx_peerHashTable", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(long)); + kread(kmem, symoff, (char *)&count, sizeof(long)); - kread(kmem, count, (char *) rx_peerTable, 256 * sizeof(long)); + kread(kmem, count, (char *)rx_peerTable, 256 * sizeof(long)); printf("\n\nPrinting all 'rx_peer' structures...\n"); - for (i=0, j=0; i < 256; i++) { + for (i = 0, j = 0; i < 256; i++) { for (sep = rx_peerTable[i]; sep; sep = sentry->next, j++) { kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); - printf("\t%lx: next=0x%lx, host=0x%x, ", - sep, sentry->next, sentry->host); + printf("\t%lx: next=0x%lx, host=0x%x, ", sep, sentry->next, + sentry->host); printf("ifMTU=%d, natMTU=%d, maxMTU=%d\n", sentry->ifMTU, sentry->natMTU, sentry->maxMTU); printf("\t\trtt=%d:%d, timeout(%d:%d), nSent=%d, reSends=%d\n", - sentry->rtt, sentry->rtt_dev, - sentry->timeout.sec, sentry->timeout.usec, - sentry->nSent, sentry->reSends); - printf("\t\trefCount=%d, port=%d, idleWhen=0x%x\n", + sentry->rtt, sentry->rtt_dev, sentry->timeout.sec, + sentry->timeout.usec, sentry->nSent, sentry->reSends); + printf("\t\trefCount=%d, port=%d, idleWhen=0x%x\n", sentry->refCount, sentry->port, sentry->idleWhen); - printf("\t\tCongestionQueue (0x%x:0x%x), inPacketSkew=0x%x, outPacketSkew=0x%x\n", - sentry->congestionQueue.prev, sentry->congestionQueue.next, - sentry->inPacketSkew, sentry->outPacketSkew); + printf + ("\t\tCongestionQueue (0x%x:0x%x), inPacketSkew=0x%x, outPacketSkew=0x%x\n", + sentry->congestionQueue.prev, sentry->congestionQueue.next, + sentry->inPacketSkew, sentry->outPacketSkew); #ifdef RX_ENABLE_LOCKS printf("\t\tpeer_lock=%d\n", sentry->peer_lock); #endif /* RX_ENABLE_LOCKS */ @@ -3367,8 +3652,9 @@ void print_peertable(kmem) #ifdef KDUMP_RX_LOCK -void print_conntable_lock(kmem) - afs_int32 kmem; +void +print_conntable_lock(kmem) + afs_int32 kmem; { off_t symoff; struct rx_connection_rx_lock *rx_connTable[256], se, *sentry = &se; @@ -3376,38 +3662,44 @@ void print_conntable_lock(kmem) long count, i, j; findsym("rx_connHashTable", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(long)); + kread(kmem, symoff, (char *)&count, sizeof(long)); if (!count) { printf("No 'rx_connection' structures found.\n"); return; } - kread(kmem, count, (char *) rx_connTable, 256 * sizeof(long)); + kread(kmem, count, (char *)rx_connTable, 256 * sizeof(long)); printf("\n\nPrinting all 'rx_connection' structures...\n"); - for (i=0, j=0; i < 256; i++) { - for (sep = rx_connTable[i]; sep; sep = sentry->next, j++) { - kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); - printf("\t%lx: next=0x%lx, peer=0x%lx, epoch=0x%x, cid=0x%x, ackRate=%d\n", + for (i = 0, j = 0; i < 256; i++) { + for (sep = rx_connTable[i]; sep; sep = sentry->next, j++) { + kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); + printf + ("\t%lx: next=0x%lx, peer=0x%lx, epoch=0x%x, cid=0x%x, ackRate=%d\n", sep, se.next, se.peer, se.epoch, se.cid, se.ackRate); - printf("\t\tcall[%x=%d, %x=%d, %x=%d, %x=%d]\n", - se.call[0], se.callNumber[0], - se.call[1], se.callNumber[1], - se.call[2], se.callNumber[2], - se.call[3], se.callNumber[3]); - printf("\t\ttimeout=%d, flags=0x%x, type=0x%x, serviceId=%d, service=0x%lx, refCount=%d\n", - se.timeout, se.flags, se.type, se.serviceId, se.service, se.refCount); - printf("\t\tserial=%d, lastSerial=%d, secsUntilDead=%d, secsUntilPing=%d, secIndex=%d\n", + printf("\t\tcall[%lx=%d, %lx=%d, %lx=%d, %lx=%d]\n", se.call[0], + se.callNumber[0], se.call[1], se.callNumber[1], se.call[2], + se.callNumber[2], se.call[3], se.callNumber[3]); + printf + ("\t\ttimeout=%d, flags=0x%x, type=0x%x, serviceId=%d, service=0x%lx, refCount=%d\n", + se.timeout, se.flags, se.type, se.serviceId, se.service, + se.refCount); + printf + ("\t\tserial=%d, lastSerial=%d, secsUntilDead=%d, secsUntilPing=%d, secIndex=%d\n", se.serial, se.lastSerial, se.secondsUntilDead, se.secondsUntilPing, se.securityIndex); - printf("\t\terror=%d, secObject=0x%lx, secData=0x%lx, secHeaderSize=%d, secmaxTrailerSize=%d\n", + printf + ("\t\terror=%d, secObject=0x%lx, secData=0x%lx, secHeaderSize=%d, secmaxTrailerSize=%d\n", se.error, se.securityObject, se.securityData, se.securityHeaderSize, se.securityMaxTrailerSize); - printf("\t\tchallEvent=0x%lx, lastSendTime=0x%x, maxSerial=%d, hardDeadTime=%d\n", - se.challengeEvent, se.lastSendTime, - se.maxSerial, se.hardDeadTime); - if (se.flags & RX_CONN_MAKECALL_WAITING) - printf("\t\t***** Conn in RX_CONN_MAKECALL_WAITING state *****\n"); - printf("\t\tcall_lock=%d, call_cv=%d, data_lock=%d, refCount=%d\n", + printf + ("\t\tchallEvent=0x%lx, lastSendTime=0x%x, maxSerial=%d, hardDeadTime=%d\n", + se.challengeEvent, se.lastSendTime, se.maxSerial, + se.hardDeadTime); + if (se.flags & RX_CONN_MAKECALL_WAITING) + printf + ("\t\t***** Conn in RX_CONN_MAKECALL_WAITING state *****\n"); + printf + ("\t\tcall_lock=%d, call_cv=%d, data_lock=%d, refCount=%d\n", se.conn_call_lock, se.conn_call_cv, se.conn_data_lock, se.refCount); } @@ -3416,43 +3708,50 @@ void print_conntable_lock(kmem) } #endif /* KDUMP_RX_LOCK */ -void print_conntable(kmem) - afs_int32 kmem; +void +print_conntable(kmem) + afs_int32 kmem; { off_t symoff; struct rx_connection *rx_connTable[256], se, *sentry = &se, *sep; long count, i, j; findsym("rx_connHashTable", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(long)); + kread(kmem, symoff, (char *)&count, sizeof(long)); - kread(kmem, count, (char *) rx_connTable, 256 * sizeof(long)); + kread(kmem, count, (char *)rx_connTable, 256 * sizeof(long)); printf("\n\nPrinting all 'rx_connection' structures...\n"); - for (i=0, j=0; i < 256; i++) { - for (sep = rx_connTable[i]; sep; sep = sentry->next, j++) { - kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); - printf("\t%lx: next=0x%lx, peer=0x%lx, epoch=0x%x, cid=0x%x, ackRate=%d\n", + for (i = 0, j = 0; i < 256; i++) { + for (sep = rx_connTable[i]; sep; sep = sentry->next, j++) { + kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); + printf + ("\t%lx: next=0x%lx, peer=0x%lx, epoch=0x%x, cid=0x%x, ackRate=%d\n", sep, se.next, se.peer, se.epoch, se.cid, se.ackRate); - printf("\t\tcall[%x=%d, %x=%d, %x=%d, %x=%d]\n", - se.call[0], se.callNumber[0], - se.call[1], se.callNumber[1], - se.call[2], se.callNumber[2], - se.call[3], se.callNumber[3]); - printf("\t\ttimeout=%d, flags=0x%x, type=0x%x, serviceId=%d, service=0x%lx, refCount=%d\n", - se.timeout, se.flags, se.type, se.serviceId, se.service, se.refCount); - printf("\t\tserial=%d, lastSerial=%d, secsUntilDead=%d, secsUntilPing=%d, secIndex=%d\n", + printf("\t\tcall[%x=%d, %x=%d, %x=%d, %x=%d]\n", se.call[0], + se.callNumber[0], se.call[1], se.callNumber[1], se.call[2], + se.callNumber[2], se.call[3], se.callNumber[3]); + printf + ("\t\ttimeout=%d, flags=0x%x, type=0x%x, serviceId=%d, service=0x%lx, refCount=%d\n", + se.timeout, se.flags, se.type, se.serviceId, se.service, + se.refCount); + printf + ("\t\tserial=%d, lastSerial=%d, secsUntilDead=%d, secsUntilPing=%d, secIndex=%d\n", se.serial, se.lastSerial, se.secondsUntilDead, se.secondsUntilPing, se.securityIndex); - printf("\t\terror=%d, secObject=0x%lx, secData=0x%lx, secHeaderSize=%d, secmaxTrailerSize=%d\n", + printf + ("\t\terror=%d, secObject=0x%lx, secData=0x%lx, secHeaderSize=%d, secmaxTrailerSize=%d\n", se.error, se.securityObject, se.securityData, se.securityHeaderSize, se.securityMaxTrailerSize); - printf("\t\tchallEvent=0x%lx, lastSendTime=0x%x, maxSerial=%d, hardDeadTime=%d\n", - se.challengeEvent, se.lastSendTime, - se.maxSerial, se.hardDeadTime); - if (se.flags & RX_CONN_MAKECALL_WAITING) - printf("\t\t***** Conn in RX_CONN_MAKECALL_WAITING state *****\n"); + printf + ("\t\tchallEvent=0x%lx, lastSendTime=0x%x, maxSerial=%d, hardDeadTime=%d\n", + se.challengeEvent, se.lastSendTime, se.maxSerial, + se.hardDeadTime); + if (se.flags & RX_CONN_MAKECALL_WAITING) + printf + ("\t\t***** Conn in RX_CONN_MAKECALL_WAITING state *****\n"); #ifdef RX_ENABLE_LOCKS - printf("\t\tcall_lock=%d, call_cv=%d, data_lock=%d, refCount=%d\n", + printf + ("\t\tcall_lock=%d, call_cv=%d, data_lock=%d, refCount=%d\n", se.conn_call_lock, se.conn_call_cv, se.conn_data_lock, se.refCount); #endif /* RX_ENABLE_LOCKS */ @@ -3463,8 +3762,9 @@ void print_conntable(kmem) #ifdef KDUMP_RX_LOCK -void print_calltable_lock(kmem) - afs_int32 kmem; +void +print_calltable_lock(kmem) + afs_int32 kmem; { off_t symoff; struct rx_connection_rx_lock *rx_connTable[256], se; @@ -3473,15 +3773,15 @@ void print_calltable_lock(kmem) long count, i, j, k; findsym("rx_connHashTable", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(long)); + kread(kmem, symoff, (char *)&count, sizeof(long)); if (!count) { printf("No 'rx_call' structures found.\n"); return; } - kread(kmem, count, (char *) rx_connTable, 256 * sizeof(long)); + kread(kmem, count, (char *)rx_connTable, 256 * sizeof(long)); printf("\n\nPrinting all active 'rx_call' structures...\n"); - for (i=0, j=0; i < 256; i++) { + for (i = 0, j = 0; i < 256; i++) { for (sep = rx_connTable[i]; sep; sep = se.next) { kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); for (k = 0; k < RX_MAXCALLS; k++) { @@ -3490,33 +3790,52 @@ void print_calltable_lock(kmem) if (call) { j++; kread(kmem, (off_t) call, (char *)centry, sizeof *centry); - printf("\t%lx: conn=0x%lx, qiheader(0x%lx:0x%lx), tq(0x%lx:0x%lx), rq(0x%lx:0x%lx)\n", - call, centry->conn, centry->queue_item_header.prev, centry->queue_item_header.next, - centry->tq.prev, centry->tq.next, centry->rq.prev, centry->rq.next); - printf("\t\t: curvec=%d, curpos=%d, nLeft=%d, nFree=%d, currPacket=0x%lx, callNumber=0x%x\n", - centry->curvec, centry->curpos, centry->nLeft, centry->nFree, centry->currentPacket, centry->callNumber); - printf("\t\t: channel=%d, state=0x%x, mode=0x%x, flags=0x%x, localStatus=0x%x, remStatus=0x%x\n", - centry->channel, centry->state, centry->mode, centry->flags, centry->localStatus, - centry->remoteStatus); - printf("\t\t: error=%d, timeout=0x%x, rnext=0x%x, rprev=0x%x, rwind=0x%x, tfirst=0x%x, tnext=0x%x\n", - centry->error, centry->timeout, centry->rnext, centry->rprev, centry->rwind, centry->tfirst, - centry->tnext); - printf("\t\t: twind=%d, resendEvent=0x%lx, timeoutEvent=0x%lx, keepAliveEvent=0x%lx, delayedAckEvent=0x%lx\n", - centry->twind, centry->resendEvent, centry->timeoutEvent, centry->keepAliveEvent, - centry->delayedAckEvent); - printf("\t\t: lastSendTime=0x%x, lastReceiveTime=0x%x, lastAcked=0x%x, startTime=0x%x, startWait=0x%x\n", - centry->lastSendTime, centry->lastReceiveTime, centry->lastAcked, centry->startTime, centry->startWait); + printf + ("\t%lx: conn=0x%lx, qiheader(0x%lx:0x%lx), tq(0x%lx:0x%lx), rq(0x%lx:0x%lx)\n", + call, centry->conn, centry->queue_item_header.prev, + centry->queue_item_header.next, centry->tq.prev, + centry->tq.next, centry->rq.prev, centry->rq.next); + printf + ("\t\t: curvec=%d, curpos=%d, nLeft=%d, nFree=%d, currPacket=0x%lx, callNumber=0x%x\n", + centry->curvec, centry->curpos, centry->nLeft, + centry->nFree, centry->currentPacket, + centry->callNumber); + printf + ("\t\t: channel=%d, state=0x%x, mode=0x%x, flags=0x%x, localStatus=0x%x, remStatus=0x%x\n", + centry->channel, centry->state, centry->mode, + centry->flags, centry->localStatus, + centry->remoteStatus); + printf + ("\t\t: error=%d, timeout=0x%x, rnext=0x%x, rprev=0x%x, rwind=0x%x, tfirst=0x%x, tnext=0x%x\n", + centry->error, centry->timeout, centry->rnext, + centry->rprev, centry->rwind, centry->tfirst, + centry->tnext); + printf + ("\t\t: twind=%d, resendEvent=0x%lx, timeoutEvent=0x%lx, keepAliveEvent=0x%lx, delayedAckEvent=0x%lx\n", + centry->twind, centry->resendEvent, + centry->timeoutEvent, centry->keepAliveEvent, + centry->delayedAckEvent); + printf + ("\t\t: lastSendTime=0x%x, lastReceiveTime=0x%x, lastAcked=0x%x, startTime=0x%x, startWait=0x%x\n", + centry->lastSendTime, centry->lastReceiveTime, + centry->lastAcked, centry->startTime, + centry->startWait); if (centry->flags & RX_CALL_WAIT_PROC) - printf("\t\t******** Call in RX_CALL_WAIT_PROC state **********\n"); + printf + ("\t\t******** Call in RX_CALL_WAIT_PROC state **********\n"); if (centry->flags & RX_CALL_WAIT_WINDOW_ALLOC) - printf("\t\t******** Call in RX_CALL_WAIT_WINDOW_ALLOC state **********\n"); + printf + ("\t\t******** Call in RX_CALL_WAIT_WINDOW_ALLOC state **********\n"); if (centry->flags & RX_CALL_READER_WAIT) - printf("\t\t******** Conn in RX_CALL_READER_WAIT state **********\n"); + printf + ("\t\t******** Conn in RX_CALL_READER_WAIT state **********\n"); if (centry->flags & RX_CALL_WAIT_PACKETS) - printf("\t\t******** Conn in RX_CALL_WAIT_PACKETS state **********\n"); - printf("\t\t: lock=0x%x, cv_twind=0x%x, cv_rq=0x%x, refCount=%d\n", - centry->lock, centry->cv_twind, centry->cv_rq, - centry->refCount); + printf + ("\t\t******** Conn in RX_CALL_WAIT_PACKETS state **********\n"); + printf + ("\t\t: lock=0x%x, cv_twind=0x%x, cv_rq=0x%x, refCount=%d\n", + centry->lock, centry->cv_twind, centry->cv_rq, + centry->refCount); printf("\t\t: MTU=%d\n", centry->MTU); } } @@ -3526,54 +3845,74 @@ void print_calltable_lock(kmem) } #endif /* KDUMP_RX_LOCK */ -void print_calltable(kmem) - afs_int32 kmem; +void +print_calltable(kmem) + afs_int32 kmem; { off_t symoff; struct rx_connection *rx_connTable[256], se, *sentry = &se, *sep; long count, i, j, k; findsym("rx_connHashTable", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(long)); + kread(kmem, symoff, (char *)&count, sizeof(long)); - kread(kmem, count, (char *) rx_connTable, 256 * sizeof(long)); + kread(kmem, count, (char *)rx_connTable, 256 * sizeof(long)); printf("\n\nPrinting all active 'rx_call' structures...\n"); - for (i=0, j=0; i < 256; i++) { + for (i = 0, j = 0; i < 256; i++) { for (sep = rx_connTable[i]; sep; sep = se.next) { - kread(kmem, (off_t)sep, (char *)sentry, sizeof *sentry); + kread(kmem, (off_t) sep, (char *)sentry, sizeof *sentry); for (k = 0; k < RX_MAXCALLS; k++) { struct rx_call ce, *centry = &ce, *call = se.call[k]; if (call) { j++; - kread(kmem, (off_t)call, (char *)centry, sizeof *centry); - printf("\t%lx: conn=0x%lx, qiheader(0x%lx:0x%lx), tq(0x%lx:0x%lx), rq(0x%lx:0x%lx)\n", - call, centry->conn, centry->queue_item_header.prev, centry->queue_item_header.next, - centry->tq.prev, centry->tq.next, centry->rq.prev, centry->rq.next); - printf("\t\t: curvec=%d, curpos=%d, nLeft=%d, nFree=%d, currPacket=0x%lx, callNumber=0x%x\n", - centry->curvec, centry->curpos, centry->nLeft, centry->nFree, centry->currentPacket, centry->callNumber); - printf("\t\t: channel=%d, state=0x%x, mode=0x%x, flags=0x%x, localStatus=0x%x, remStatus=0x%x\n", - centry->channel, centry->state, centry->mode, centry->flags, centry->localStatus, - centry->remoteStatus); - printf("\t\t: error=%d, timeout=0x%x, rnext=0x%x, rprev=0x%x, rwind=0x%x, tfirst=0x%x, tnext=0x%x\n", - centry->error, centry->timeout, centry->rnext, centry->rprev, centry->rwind, centry->tfirst, - centry->tnext); - printf("\t\t: twind=%d, resendEvent=0x%lx, timeoutEvent=0x%lx, keepAliveEvent=0x%lx, delayedAckEvent=0x%lx\n", - centry->twind, centry->resendEvent, centry->timeoutEvent, centry->keepAliveEvent, - centry->delayedAckEvent); - printf("\t\t: lastSendTime=0x%x, lastReceiveTime=0x%x, lastAcked=0x%x, startTime=0x%x, startWait=0x%x\n", - centry->lastSendTime, centry->lastReceiveTime, centry->lastAcked, centry->startTime, centry->startWait); + kread(kmem, (off_t) call, (char *)centry, sizeof *centry); + printf + ("\t%lx: conn=0x%lx, qiheader(0x%lx:0x%lx), tq(0x%lx:0x%lx), rq(0x%lx:0x%lx)\n", + call, centry->conn, centry->queue_item_header.prev, + centry->queue_item_header.next, centry->tq.prev, + centry->tq.next, centry->rq.prev, centry->rq.next); + printf + ("\t\t: curvec=%d, curpos=%d, nLeft=%d, nFree=%d, currPacket=0x%lx, callNumber=0x%x\n", + centry->curvec, centry->curpos, centry->nLeft, + centry->nFree, centry->currentPacket, + centry->callNumber); + printf + ("\t\t: channel=%d, state=0x%x, mode=0x%x, flags=0x%x, localStatus=0x%x, remStatus=0x%x\n", + centry->channel, centry->state, centry->mode, + centry->flags, centry->localStatus, + centry->remoteStatus); + printf + ("\t\t: error=%d, timeout=0x%x, rnext=0x%x, rprev=0x%x, rwind=0x%x, tfirst=0x%x, tnext=0x%x\n", + centry->error, centry->timeout, centry->rnext, + centry->rprev, centry->rwind, centry->tfirst, + centry->tnext); + printf + ("\t\t: twind=%d, resendEvent=0x%lx, timeoutEvent=0x%lx, keepAliveEvent=0x%lx, delayedAckEvent=0x%lx\n", + centry->twind, centry->resendEvent, + centry->timeoutEvent, centry->keepAliveEvent, + centry->delayedAckEvent); + printf + ("\t\t: lastSendTime=0x%x, lastReceiveTime=0x%x, lastAcked=0x%x, startTime=0x%x, startWait=0x%x\n", + centry->lastSendTime, centry->lastReceiveTime, + centry->lastAcked, centry->startTime, + centry->startWait); if (centry->flags & RX_CALL_WAIT_PROC) - printf("\t\t******** Call in RX_CALL_WAIT_PROC state **********\n"); + printf + ("\t\t******** Call in RX_CALL_WAIT_PROC state **********\n"); if (centry->flags & RX_CALL_WAIT_WINDOW_ALLOC) - printf("\t\t******** Call in RX_CALL_WAIT_WINDOW_ALLOC state **********\n"); + printf + ("\t\t******** Call in RX_CALL_WAIT_WINDOW_ALLOC state **********\n"); if (centry->flags & RX_CALL_READER_WAIT) - printf("\t\t******** Conn in RX_CALL_READER_WAIT state **********\n"); + printf + ("\t\t******** Conn in RX_CALL_READER_WAIT state **********\n"); if (centry->flags & RX_CALL_WAIT_PACKETS) - printf("\t\t******** Conn in RX_CALL_WAIT_PACKETS state **********\n"); + printf + ("\t\t******** Conn in RX_CALL_WAIT_PACKETS state **********\n"); #ifdef RX_ENABLE_LOCKS - printf("\t\t: lock=0x%x, cv_twind=0x%x, cv_rq=0x%x, refCount=%d\n", - centry->lock, centry->cv_twind, centry->cv_rq, - centry->refCount); + printf + ("\t\t: lock=0x%x, cv_twind=0x%x, cv_rq=0x%x, refCount=%d\n", + centry->lock, centry->cv_twind, centry->cv_rq, + centry->refCount); #endif /* RX_ENABLE_LOCKS */ printf("\t\t: MTU=%d\n", centry->MTU); } @@ -3583,22 +3922,23 @@ void print_calltable(kmem) printf("... found %d 'rx_call' entries in the table\n", j); } -void print_eventtable(kmem) - afs_int32 kmem; +void +print_eventtable(kmem) + afs_int32 kmem; { off_t symoff; struct rx_queue epq; struct rx_queue evq; char *epend, *evend; - afs_int32 count, i, j=0, k=0; + afs_int32 count, i, j = 0, k = 0; #if ! defined(AFS_HPUX_ENV) && ! defined(AFS_AIX_ENV) findsym("rxevent_nFree", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(afs_int32)); + kread(kmem, symoff, (char *)&count, sizeof(afs_int32)); printf("\n\n\trxevent_nFree = %d\n", count); findsym("rxevent_nPosted", &symoff); - kread(kmem, symoff, (char *) &count, sizeof(afs_int32)); + kread(kmem, symoff, (char *)&count, sizeof(afs_int32)); printf("\trxevent_nPosted = %d\n", count); #endif } @@ -3609,102 +3949,106 @@ void print_eventtable(kmem) * Print the up/downtime stats for the given class of server records * provided. */ -void print_upDownStats(a_upDownP) - struct afs_stats_SrvUpDownInfo *a_upDownP; /*Ptr to server up/down info*/ +void +print_upDownStats(a_upDownP) + struct afs_stats_SrvUpDownInfo *a_upDownP; /*Ptr to server up/down info */ -{ /*print_upDownStats*/ +{ /*print_upDownStats */ /* * First, print the simple values. */ - printf("\t\t%10d numTtlRecords\n", a_upDownP->numTtlRecords); - printf("\t\t%10d numUpRecords\n", a_upDownP->numUpRecords); - printf("\t\t%10d numDownRecords\n", a_upDownP->numDownRecords); - printf("\t\t%10d sumOfRecordAges\n", a_upDownP->sumOfRecordAges); - printf("\t\t%10d ageOfYoungestRecord\n", a_upDownP->ageOfYoungestRecord); - printf("\t\t%10d ageOfOldestRecord\n", a_upDownP->ageOfOldestRecord); - printf("\t\t%10d numDowntimeIncidents\n", a_upDownP->numDowntimeIncidents); - printf("\t\t%10d numRecordsNeverDown\n", a_upDownP->numRecordsNeverDown); - printf("\t\t%10d maxDowntimesInARecord\n", a_upDownP->maxDowntimesInARecord); - printf("\t\t%10d sumOfDowntimes\n", a_upDownP->sumOfDowntimes); - printf("\t\t%10d shortestDowntime\n", a_upDownP->shortestDowntime); - printf("\t\t%10d longestDowntime\n", a_upDownP->longestDowntime); + printf("\t\t%10d numTtlRecords\n", a_upDownP->numTtlRecords); + printf("\t\t%10d numUpRecords\n", a_upDownP->numUpRecords); + printf("\t\t%10d numDownRecords\n", a_upDownP->numDownRecords); + printf("\t\t%10d sumOfRecordAges\n", a_upDownP->sumOfRecordAges); + printf("\t\t%10d ageOfYoungestRecord\n", a_upDownP->ageOfYoungestRecord); + printf("\t\t%10d ageOfOldestRecord\n", a_upDownP->ageOfOldestRecord); + printf("\t\t%10d numDowntimeIncidents\n", + a_upDownP->numDowntimeIncidents); + printf("\t\t%10d numRecordsNeverDown\n", a_upDownP->numRecordsNeverDown); + printf("\t\t%10d maxDowntimesInARecord\n", + a_upDownP->maxDowntimesInARecord); + printf("\t\t%10d sumOfDowntimes\n", a_upDownP->sumOfDowntimes); + printf("\t\t%10d shortestDowntime\n", a_upDownP->shortestDowntime); + printf("\t\t%10d longestDowntime\n", a_upDownP->longestDowntime); /* * Now, print the array values. */ printf("\t\tDowntime duration distribution:\n"); - printf("\t\t\t%8d: 0 min .. 10 min\n", a_upDownP->downDurations[0]); + printf("\t\t\t%8d: 0 min .. 10 min\n", a_upDownP->downDurations[0]); printf("\t\t\t%8d: 10 min .. 30 min\n", a_upDownP->downDurations[1]); - printf("\t\t\t%8d: 30 min .. 1 hr\n", a_upDownP->downDurations[2]); - printf("\t\t\t%8d: 1 hr .. 2 hr\n", a_upDownP->downDurations[3]); - printf("\t\t\t%8d: 2 hr .. 4 hr\n", a_upDownP->downDurations[4]); - printf("\t\t\t%8d: 4 hr .. 8 hr\n", a_upDownP->downDurations[5]); - printf("\t\t\t%8d: > 8 hr\n", a_upDownP->downDurations[6]); + printf("\t\t\t%8d: 30 min .. 1 hr\n", a_upDownP->downDurations[2]); + printf("\t\t\t%8d: 1 hr .. 2 hr\n", a_upDownP->downDurations[3]); + printf("\t\t\t%8d: 2 hr .. 4 hr\n", a_upDownP->downDurations[4]); + printf("\t\t\t%8d: 4 hr .. 8 hr\n", a_upDownP->downDurations[5]); + printf("\t\t\t%8d: > 8 hr\n", a_upDownP->downDurations[6]); printf("\t\tDowntime incident distribution:\n"); - printf("\t\t\t%8d: 0 times\n", a_upDownP->downIncidents[0]); - printf("\t\t\t%8d: 1 time\n", a_upDownP->downDurations[1]); - printf("\t\t\t%8d: 2 .. 5 times\n", a_upDownP->downDurations[2]); - printf("\t\t\t%8d: 6 .. 10 times\n", a_upDownP->downDurations[3]); + printf("\t\t\t%8d: 0 times\n", a_upDownP->downIncidents[0]); + printf("\t\t\t%8d: 1 time\n", a_upDownP->downDurations[1]); + printf("\t\t\t%8d: 2 .. 5 times\n", a_upDownP->downDurations[2]); + printf("\t\t\t%8d: 6 .. 10 times\n", a_upDownP->downDurations[3]); printf("\t\t\t%8d: 10 .. 50 times\n", a_upDownP->downDurations[4]); - printf("\t\t\t%8d: > 50 times\n", a_upDownP->downDurations[5]); -} /*print_upDownStats*/ + printf("\t\t\t%8d: > 50 times\n", a_upDownP->downDurations[5]); +} /*print_upDownStats */ -void print_cmperfstats(perfP) - struct afs_stats_CMPerf *perfP; +void +print_cmperfstats(perfP) + struct afs_stats_CMPerf *perfP; { - struct afs_stats_SrvUpDownInfo *upDownP; /*Ptr to server up/down info*/ - - printf("\t%10d numPerfCalls\n", perfP->numPerfCalls); - printf("\t%10d epoch\n", perfP->epoch); - printf("\t%10d numCellsVisible\n", perfP->numCellsVisible); - printf("\t%10d numCellsContacted\n", perfP->numCellsContacted); - printf("\t%10d dlocalAccesses\n", perfP->dlocalAccesses); - printf("\t%10d vlocalAccesses\n", perfP->vlocalAccesses); - printf("\t%10d dremoteAccesses\n", perfP->dremoteAccesses); - printf("\t%10d vremoteAccesses\n", perfP->vremoteAccesses); - printf("\t%10d cacheNumEntries\n", perfP->cacheNumEntries); - printf("\t%10d cacheBlocksTotal\n", perfP->cacheBlocksTotal); - printf("\t%10d cacheBlocksInUse\n", perfP->cacheBlocksInUse); - printf("\t%10d cacheBlocksOrig\n", perfP->cacheBlocksOrig); - printf("\t%10d cacheMaxDirtyChunks\n", perfP->cacheMaxDirtyChunks); - printf("\t%10d cacheCurrDirtyChunks\n", perfP->cacheCurrDirtyChunks); - printf("\t%10d dcacheHits\n", perfP->dcacheHits); - printf("\t%10d vcacheHits\n", perfP->vcacheHits); - printf("\t%10d dcacheMisses\n", perfP->dcacheMisses); - printf("\t%10d vcacheMisses\n", perfP->vcacheMisses); - printf("\t%10d cacheFlushes\n", perfP->cacheFlushes); - printf("\t%10d cacheFilesReused\n", perfP->cacheFilesReused); - printf("\t%10d vcacheXAllocs\n", perfP->vcacheXAllocs); - printf("\t%10d dcacheXAllocs\n", perfP->dcacheXAllocs); - - printf("\t%10d bufAlloced\n", perfP->bufAlloced); - printf("\t%10d bufHits\n", perfP->bufHits); - printf("\t%10d bufMisses\n", perfP->bufMisses); - printf("\t%10d bufFlushDirty\n", perfP->bufFlushDirty); - - printf("\t%10d LargeBlocksActive\n", perfP->LargeBlocksActive); - printf("\t%10d LargeBlocksAlloced\n", perfP->LargeBlocksAlloced); - printf("\t%10d SmallBlocksActive\n", perfP->SmallBlocksActive); - printf("\t%10d SmallBlocksAlloced\n", perfP->SmallBlocksAlloced); - printf("\t%10d MediumBlocksActive\n", perfP->MediumBlocksActive); - printf("\t%10d MediumBlocksAlloced\n", perfP->MediumBlocksAlloced); - printf("\t%10d OutStandingMemUsage\n", perfP->OutStandingMemUsage); - printf("\t%10d OutStandingAllocs\n", perfP->OutStandingAllocs); - printf("\t%10d CallBackAlloced\n", perfP->CallBackAlloced); - printf("\t%10d CallBackFlushes\n", perfP->CallBackFlushes); - printf("\t%10d CallBackLoops\n", perfP->cbloops); - - printf("\t%10d srvRecords\n", perfP->srvRecords); - printf("\t%10d srvNumBuckets\n", perfP->srvNumBuckets); - printf("\t%10d srvMaxChainLength\n", perfP->srvMaxChainLength); - printf("\t%10d srvRecordsHWM\n", perfP->srvRecordsHWM); - printf("\t%10d srvMaxChainLengthHWM\n", perfP->srvMaxChainLengthHWM); - - printf("\t%10d sysName_ID\n", perfP->sysName_ID); - printf("\t%10d osi_Read_EFAULTS\n", perfP->osiread_efaults); + struct afs_stats_SrvUpDownInfo *upDownP; /*Ptr to server up/down info */ + + printf("\t%10d numPerfCalls\n", perfP->numPerfCalls); + printf("\t%10d epoch\n", perfP->epoch); + printf("\t%10d numCellsVisible\n", perfP->numCellsVisible); + printf("\t%10d numCellsContacted\n", perfP->numCellsContacted); + printf("\t%10d dlocalAccesses\n", perfP->dlocalAccesses); + printf("\t%10d vlocalAccesses\n", perfP->vlocalAccesses); + printf("\t%10d dremoteAccesses\n", perfP->dremoteAccesses); + printf("\t%10d vremoteAccesses\n", perfP->vremoteAccesses); + printf("\t%10d cacheNumEntries\n", perfP->cacheNumEntries); + printf("\t%10d cacheBlocksTotal\n", perfP->cacheBlocksTotal); + printf("\t%10d cacheBlocksInUse\n", perfP->cacheBlocksInUse); + printf("\t%10d cacheBlocksOrig\n", perfP->cacheBlocksOrig); + printf("\t%10d cacheMaxDirtyChunks\n", perfP->cacheMaxDirtyChunks); + printf("\t%10d cacheCurrDirtyChunks\n", perfP->cacheCurrDirtyChunks); + printf("\t%10d dcacheHits\n", perfP->dcacheHits); + printf("\t%10d vcacheHits\n", perfP->vcacheHits); + printf("\t%10d dcacheMisses\n", perfP->dcacheMisses); + printf("\t%10d vcacheMisses\n", perfP->vcacheMisses); + printf("\t%10d cacheFlushes\n", perfP->cacheFlushes); + printf("\t%10d cacheFilesReused\n", perfP->cacheFilesReused); + printf("\t%10d vcacheXAllocs\n", perfP->vcacheXAllocs); + printf("\t%10d dcacheXAllocs\n", perfP->dcacheXAllocs); + + printf("\t%10d bufAlloced\n", perfP->bufAlloced); + printf("\t%10d bufHits\n", perfP->bufHits); + printf("\t%10d bufMisses\n", perfP->bufMisses); + printf("\t%10d bufFlushDirty\n", perfP->bufFlushDirty); + + printf("\t%10d LargeBlocksActive\n", perfP->LargeBlocksActive); + printf("\t%10d LargeBlocksAlloced\n", perfP->LargeBlocksAlloced); + printf("\t%10d SmallBlocksActive\n", perfP->SmallBlocksActive); + printf("\t%10d SmallBlocksAlloced\n", perfP->SmallBlocksAlloced); + printf("\t%10d MediumBlocksActive\n", perfP->MediumBlocksActive); + printf("\t%10d MediumBlocksAlloced\n", perfP->MediumBlocksAlloced); + printf("\t%10d OutStandingMemUsage\n", perfP->OutStandingMemUsage); + printf("\t%10d OutStandingAllocs\n", perfP->OutStandingAllocs); + printf("\t%10d CallBackAlloced\n", perfP->CallBackAlloced); + printf("\t%10d CallBackFlushes\n", perfP->CallBackFlushes); + printf("\t%10d CallBackLoops\n", perfP->cbloops); + + printf("\t%10d srvRecords\n", perfP->srvRecords); + printf("\t%10d srvNumBuckets\n", perfP->srvNumBuckets); + printf("\t%10d srvMaxChainLength\n", perfP->srvMaxChainLength); + printf("\t%10d srvRecordsHWM\n", perfP->srvRecordsHWM); + printf("\t%10d srvMaxChainLengthHWM\n", perfP->srvMaxChainLengthHWM); + + printf("\t%10d sysName_ID\n", perfP->sysName_ID); + printf("\t%10d osi_Read_EFAULTS\n", perfP->osiread_efaults); printf("\tFile Server up/downtimes, same cell:\n"); print_upDownStats(&(perfP->fs_UpDown[0])); @@ -3720,416 +4064,450 @@ void print_cmperfstats(perfP) } -void print_cmstats(cmp) - struct afs_CMStats *cmp; +void +print_cmstats(cmp) + struct afs_CMStats *cmp; { - printf("\t%10d afs_init\n", cmp->callInfo.C_afs_init); - printf("\t%10d gop_rdwr\n", cmp->callInfo.C_gop_rdwr); - printf("\t%10d aix_gnode_rele\n", cmp->callInfo.C_aix_gnode_rele); - printf("\t%10d gettimeofday\n", cmp->callInfo.C_gettimeofday); - printf("\t%10d m_cpytoc\n", cmp->callInfo.C_m_cpytoc); - printf("\t%10d aix_vattr_null\n", cmp->callInfo.C_aix_vattr_null); - printf("\t%10d afs_gn_frunc\n", cmp->callInfo.C_afs_gn_ftrunc); - printf("\t%10d afs_gn_rdwr\n", cmp->callInfo.C_afs_gn_rdwr); - printf("\t%10d afs_gn_ioctl\n", cmp->callInfo.C_afs_gn_ioctl); - printf("\t%10d afs_gn_locktl\n", cmp->callInfo.C_afs_gn_lockctl); - printf("\t%10d afs_gn_readlink\n", cmp->callInfo.C_afs_gn_readlink); - printf("\t%10d afs_gn_readdir\n", cmp->callInfo.C_afs_gn_readdir); - printf("\t%10d afs_gn_select\n", cmp->callInfo.C_afs_gn_select); - printf("\t%10d afs_gn_strategy\n", cmp->callInfo.C_afs_gn_strategy); - printf("\t%10d afs_gn_symlink\n", cmp->callInfo.C_afs_gn_symlink); - printf("\t%10d afs_gn_revoke\n", cmp->callInfo.C_afs_gn_revoke); - printf("\t%10d afs_gn_link\n", cmp->callInfo.C_afs_gn_link); - printf("\t%10d afs_gn_mkdir\n", cmp->callInfo.C_afs_gn_mkdir); - printf("\t%10d afs_gn_mknod\n", cmp->callInfo.C_afs_gn_mknod); - printf("\t%10d afs_gn_remove\n", cmp->callInfo.C_afs_gn_remove); - printf("\t%10d afs_gn_rename\n", cmp->callInfo.C_afs_gn_rename); - printf("\t%10d afs_gn_rmdir\n", cmp->callInfo.C_afs_gn_rmdir); - printf("\t%10d afs_gn_fid\n", cmp->callInfo.C_afs_gn_fid); - printf("\t%10d afs_gn_lookup\n", cmp->callInfo.C_afs_gn_lookup); - printf("\t%10d afs_gn_open\n", cmp->callInfo.C_afs_gn_open); - printf("\t%10d afs_gn_create\n", cmp->callInfo.C_afs_gn_create); - printf("\t%10d afs_gn_hold\n", cmp->callInfo.C_afs_gn_hold); - printf("\t%10d afs_gn_rele\n", cmp->callInfo.C_afs_gn_rele); - printf("\t%10d afs_gn_unmap\n", cmp->callInfo.C_afs_gn_unmap); - printf("\t%10d afs_gn_access\n", cmp->callInfo.C_afs_gn_access); - printf("\t%10d afs_gn_getattr\n", cmp->callInfo.C_afs_gn_getattr); - printf("\t%10d afs_gn_setattr\n", cmp->callInfo.C_afs_gn_setattr); - printf("\t%10d afs_gn_fclear\n", cmp->callInfo.C_afs_gn_fclear); - printf("\t%10d afs_gn_fsync\n", cmp->callInfo.C_afs_gn_fsync); - printf("\t%10d phash\n", cmp->callInfo.C_pHash); - printf("\t%10d DInit\n", cmp->callInfo.C_DInit); - printf("\t%10d DRead\n", cmp->callInfo.C_DRead); - printf("\t%10d FixupBucket\n", cmp->callInfo.C_FixupBucket); - printf("\t%10d afs_newslot\n", cmp->callInfo.C_afs_newslot); - printf("\t%10d DRelease\n", cmp->callInfo.C_DRelease); - printf("\t%10d DFlush\n", cmp->callInfo.C_DFlush); - printf("\t%10d DFlushEntry\n", cmp->callInfo.C_DFlushEntry); - printf("\t%10d DVOffset\n", cmp->callInfo.C_DVOffset); - printf("\t%10d DZap\n", cmp->callInfo.C_DZap); - printf("\t%10d DNew\n", cmp->callInfo.C_DNew); - printf("\t%10d afs_RemoveVCB\n", cmp->callInfo.C_afs_RemoveVCB); - printf("\t%10d afs_NewVCache\n", cmp->callInfo.C_afs_NewVCache); - printf("\t%10d afs_FlushActiveVcaches\n", cmp->callInfo.C_afs_FlushActiveVcaches); - printf("\t%10d afs_VerifyVCache\n", cmp->callInfo.C_afs_VerifyVCache); - printf("\t%10d afs_WriteVCache\n", cmp->callInfo.C_afs_WriteVCache); - printf("\t%10d afs_GetVCache\n", cmp->callInfo.C_afs_GetVCache); - printf("\t%10d afs_StuffVcache\n", cmp->callInfo.C_afs_StuffVcache); - printf("\t%10d afs_FindVCache\n", cmp->callInfo.C_afs_FindVCache); - printf("\t%10d afs_PutDCache\n", cmp->callInfo.C_afs_PutDCache); - printf("\t%10d afs_PutVCache\n", cmp->callInfo.C_afs_PutVCache); - printf("\t%10d CacheStoreProc\n", cmp->callInfo.C_CacheStoreProc); - printf("\t%10d afs_FindDcache\n", cmp->callInfo.C_afs_FindDCache); - printf("\t%10d afs_TryToSmush\n", cmp->callInfo.C_afs_TryToSmush); - printf("\t%10d afs_AdjustSize\n", cmp->callInfo.C_afs_AdjustSize); - printf("\t%10d afs_CheckSize\n", cmp->callInfo.C_afs_CheckSize); - printf("\t%10d afs_StoreWarn\n", cmp->callInfo.C_afs_StoreWarn); - printf("\t%10d CacheFetchProc\n", cmp->callInfo.C_CacheFetchProc); - printf("\t%10d UFS_CacheStoreProc\n", cmp->callInfo.C_UFS_CacheStoreProc); - printf("\t%10d UFS_CacheFetchProc\n", cmp->callInfo.C_UFS_CacheFetchProc); - printf("\t%10d afs_GetDCache\n", cmp->callInfo.C_afs_GetDCache); - printf("\t%10d afs_SimpleVStat\n", cmp->callInfo.C_afs_SimpleVStat); - printf("\t%10d afs_ProcessFS\n", cmp->callInfo.C_afs_ProcessFS); - printf("\t%10d afs_InitCacheInfo\n", cmp->callInfo.C_afs_InitCacheInfo); - printf("\t%10d afs_InitVolumeInfo\n", cmp->callInfo.C_afs_InitVolumeInfo); - printf("\t%10d afs_InitCacheFile\n", cmp->callInfo.C_afs_InitCacheFile); - printf("\t%10d afs_CacheInit\n", cmp->callInfo.C_afs_CacheInit); - printf("\t%10d afs_GetDSlot\n", cmp->callInfo.C_afs_GetDSlot); - printf("\t%10d afs_WriteThroughDSlots\n", cmp->callInfo.C_afs_WriteThroughDSlots); - printf("\t%10d afs_MemGetDSlot\n", cmp->callInfo.C_afs_MemGetDSlot); - printf("\t%10d afs_UFSGetDSlot\n", cmp->callInfo.C_afs_UFSGetDSlot); - printf("\t%10d afs_StoreDCache\n", cmp->callInfo.C_afs_StoreDCache); - printf("\t%10d afs_StoreMini\n", cmp->callInfo.C_afs_StoreMini); - printf("\t%10d afs_StoreAllSegments\n", cmp->callInfo.C_afs_StoreAllSegments); - printf("\t%10d afs_InvalidateAllSegments\n", cmp->callInfo.C_afs_InvalidateAllSegments); - printf("\t%10d afs_TruncateAllSegments\n", cmp->callInfo.C_afs_TruncateAllSegments); - printf("\t%10d afs_CheckVolSync\n", cmp->callInfo.C_afs_CheckVolSync); - printf("\t%10d afs_wakeup\n", cmp->callInfo.C_afs_wakeup); - printf("\t%10d afs_CFileOpen\n", cmp->callInfo.C_afs_CFileOpen); - printf("\t%10d afs_CFileTruncate\n", cmp->callInfo.C_afs_CFileTruncate); - printf("\t%10d afs_GetDownD\n", cmp->callInfo.C_afs_GetDownD); - printf("\t%10d afs_WriteDCache\n", cmp->callInfo.C_afs_WriteDCache); - printf("\t%10d afs_FlushDCache\n", cmp->callInfo.C_afs_FlushDCache); - printf("\t%10d afs_GetDownDSlot\n", cmp->callInfo.C_afs_GetDownDSlot); - printf("\t%10d afs_FlushVCache\n", cmp->callInfo.C_afs_FlushVCache); - printf("\t%10d afs_GetDownV\n", cmp->callInfo.C_afs_GetDownV); - printf("\t%10d afs_QueueVCB\n", cmp->callInfo.C_afs_QueueVCB); - printf("\t%10d afs_call\n", cmp->callInfo.C_afs_call); - printf("\t%10d afs_syscall_call\n", cmp->callInfo.C_afs_syscall_call); - printf("\t%10d afs_syscall_icreate\n", cmp->callInfo.C_afs_syscall_icreate); - printf("\t%10d afs_syscall_iopen\n", cmp->callInfo.C_afs_syscall_iopen); - printf("\t%10d afs_syscall_iincdec\n", cmp->callInfo.C_afs_syscall_iincdec); - printf("\t%10d afs_syscall_ireadwrite\n", cmp->callInfo.C_afs_syscall_ireadwrite); - printf("\t%10d afs_syscall\n", cmp->callInfo.C_afs_syscall); - printf("\t%10d lpioctl\n", cmp->callInfo.C_lpioctl); - printf("\t%10d lsetpag\n", cmp->callInfo.C_lsetpag); - printf("\t%10d afs_CheckInit\n", cmp->callInfo.C_afs_CheckInit); - printf("\t%10d ClearCallback\n", cmp->callInfo.C_ClearCallBack); - printf("\t%10d SRXAFSCB_GetCE\n", cmp->callInfo.C_SRXAFSCB_GetCE); - printf("\t%10d SRXAFSCB_GetLock\n", cmp->callInfo.C_SRXAFSCB_GetLock); - printf("\t%10d SRXAFSCB_CallBack\n", cmp->callInfo.C_SRXAFSCB_CallBack); - printf("\t%10d SRXAFSCB_InitCallBackState\n", cmp->callInfo.C_SRXAFSCB_InitCallBackState); - printf("\t%10d SRXAFSCB_Probe\n", cmp->callInfo.C_SRXAFSCB_Probe); - printf("\t%10d afs_Chunk\n", cmp->callInfo.C_afs_Chunk); - printf("\t%10d afs_ChunkBase\n", cmp->callInfo.C_afs_ChunkBase); - printf("\t%10d afs_ChunkOffset\n", cmp->callInfo.C_afs_ChunkOffset); - printf("\t%10d afs_ChunkSize\n", cmp->callInfo.C_afs_ChunkSize); - printf("\t%10d afs_ChunkToBase\n", cmp->callInfo.C_afs_ChunkToBase); - printf("\t%10d afs_ChunkToSize\n", cmp->callInfo.C_afs_ChunkToSize); - printf("\t%10d afs_SetChunkSize\n", cmp->callInfo.C_afs_SetChunkSize); - printf("\t%10d afs_config\n", cmp->callInfo.C_afs_config); - printf("\t%10d mem_freebytes\n", cmp->callInfo.C_mem_freebytes); - printf("\t%10d mem_getbytes\n", cmp->callInfo.C_mem_getbytes); - printf("\t%10d afs_Daemon\n", cmp->callInfo.C_afs_Daemon); - printf("\t%10d afs_CheckRootVolume\n", cmp->callInfo.C_afs_CheckRootVolume); - printf("\t%10d BPath\n", cmp->callInfo.C_BPath); - printf("\t%10d BPrefetch\n", cmp->callInfo.C_BPrefetch); - printf("\t%10d BStore\n", cmp->callInfo.C_BStore); - printf("\t%10d afs_BBusy\n", cmp->callInfo.C_afs_BBusy); - printf("\t%10d afs_BQueue\n", cmp->callInfo.C_afs_BQueue); - printf("\t%10d afs_BRelease\n", cmp->callInfo.C_afs_BRelease); - printf("\t%10d afs_BackgroundDaemon\n", cmp->callInfo.C_afs_BackgroundDaemon); - printf("\t%10d exporter_add\n", cmp->callInfo.C_exporter_add); - printf("\t%10d exporter_find\n", cmp->callInfo.C_exporter_find); - printf("\t%10d afs_gfs_kalloc\n", cmp->callInfo.C_afs_gfs_kalloc); - printf("\t%10d afs_gfs_kfree\n", cmp->callInfo.C_afs_gfs_kfree); - printf("\t%10d gop_lookupname\n", cmp->callInfo.C_gop_lookupname); - printf("\t%10d afs_uniqtime\n", cmp->callInfo.C_afs_uniqtime); - printf("\t%10d gfs_vattr_null\n", cmp->callInfo.C_gfs_vattr_null); - printf("\t%10d afs_lock\n", cmp->callInfo.C_afs_lock); - printf("\t%10d afs_unlock\n", cmp->callInfo.C_afs_unlock); - printf("\t%10d afs_update\n", cmp->callInfo.C_afs_update); - printf("\t%10d afs_gclose\n", cmp->callInfo.C_afs_gclose); - printf("\t%10d afs_gopen\n", cmp->callInfo.C_afs_gopen); - printf("\t%10d afs_greadlink\n", cmp->callInfo.C_afs_greadlink); - printf("\t%10d afs_select\n", cmp->callInfo.C_afs_select); - printf("\t%10d afs_gbmap\n", cmp->callInfo.C_afs_gbmap); - printf("\t%10d afs_getfsdata\n", cmp->callInfo.C_afs_getfsdata); - printf("\t%10d afs_gsymlink\n", cmp->callInfo.C_afs_gsymlink); - printf("\t%10d afs_namei\n", cmp->callInfo.C_afs_namei); - printf("\t%10d afs_gmount\n", cmp->callInfo.C_afs_gmount); - printf("\t%10d afs_gget\n", cmp->callInfo.C_afs_gget); - printf("\t%10d afs_glink\n", cmp->callInfo.C_afs_glink); - printf("\t%10d afs_gmkdir\n", cmp->callInfo.C_afs_gmkdir); - printf("\t%10d afs_unlink\n", cmp->callInfo.C_afs_unlink); - printf("\t%10d afs_grmdir\n", cmp->callInfo.C_afs_grmdir); - printf("\t%10d afs_makenode\n", cmp->callInfo.C_afs_makenode); - printf("\t%10d afs_grename\n", cmp->callInfo.C_afs_grename); - printf("\t%10d afs_rele\n", cmp->callInfo.C_afs_rele); - printf("\t%10d afs_syncgp\n", cmp->callInfo.C_afs_syncgp); - printf("\t%10d afs_getval\n", cmp->callInfo.C_afs_getval); - printf("\t%10d afs_trunc\n", cmp->callInfo.C_afs_trunc); - printf("\t%10d afs_rwgp\n", cmp->callInfo.C_afs_rwgp); - printf("\t%10d afs_stat\n", cmp->callInfo.C_afs_stat); - printf("\t%10d afsc_link\n", cmp->callInfo.C_afsc_link); - printf("\t%10d afs_vfs_mount\n", cmp->callInfo.C_afs_vfs_mount); - printf("\t%10d afs_uniqtime\n", cmp->callInfo.C_afs_uniqtime); - printf("\t%10d iopen\n", cmp->callInfo.C_iopen); - printf("\t%10d idec\n", cmp->callInfo.C_idec); - printf("\t%10d iinc\n", cmp->callInfo.C_iinc); - printf("\t%10d ireadwrite\n", cmp->callInfo.C_ireadwrite); - printf("\t%10d iread\n", cmp->callInfo.C_iread); - printf("\t%10d iwrite\n", cmp->callInfo.C_iwrite); - printf("\t%10d iforget\n", cmp->callInfo.C_iforget); - printf("\t%10d icreate\n", cmp->callInfo.C_icreate); - printf("\t%10d igetinode\n", cmp->callInfo.C_igetinode); - printf("\t%10d osi_SleepR\n", cmp->callInfo.C_osi_SleepR); - printf("\t%10d osi_SleepS\n", cmp->callInfo.C_osi_SleepS); - printf("\t%10d osi_SleepW\n", cmp->callInfo.C_osi_SleepW); - printf("\t%10d osi_Sleep\n", cmp->callInfo.C_osi_Sleep); - printf("\t%10d afs_LookupMCE\n", cmp->callInfo.C_afs_LookupMCE); - printf("\t%10d afs_MemReadBlk\n", cmp->callInfo.C_afs_MemReadBlk); - printf("\t%10d afs_MemReadUIO\n", cmp->callInfo.C_afs_MemReadUIO); - printf("\t%10d afs_MemWriteBlk\n", cmp->callInfo.C_afs_MemWriteBlk); - printf("\t%10d afs_MemWriteUIO\n", cmp->callInfo.C_afs_MemWriteUIO); - printf("\t%10d afs_MemCacheStoreProc\n", cmp->callInfo.C_afs_MemCacheStoreProc); - printf("\t%10d afs_MemCacheFetchProc\n", cmp->callInfo.C_afs_MemCacheFetchProc); - printf("\t%10d afs_MemCacheTruncate\n", cmp->callInfo.C_afs_MemCacheTruncate); - printf("\t%10d afs_MemCacheStoreProc\n", cmp->callInfo.C_afs_MemCacheStoreProc); - printf("\t%10d afs_GetNfsClientPag\n", cmp->callInfo.C_afs_GetNfsClientPag); - printf("\t%10d afs_FindNfsClientPag\n", cmp->callInfo.C_afs_FindNfsClientPag); - printf("\t%10d afs_PutNfsClientPag\n", cmp->callInfo.C_afs_PutNfsClientPag); - printf("\t%10d afs_nfsclient_reqhandler\n", cmp->callInfo.C_afs_nfsclient_reqhandler); - printf("\t%10d afs_nfsclient_GC\n", cmp->callInfo.C_afs_nfsclient_GC); - printf("\t%10d afs_nfsclient_hold\n", cmp->callInfo.C_afs_nfsclient_hold); - printf("\t%10d afs_nfsclient_stats\n", cmp->callInfo.C_afs_nfsclient_stats); - printf("\t%10d afs_nfsclient_sysname\n", cmp->callInfo.C_afs_nfsclient_sysname); - printf("\t%10d afs_rfs_dispatch\n", cmp->callInfo.C_afs_rfs_dispatch); - printf("\t%10d afs_nfs2afscall\n", cmp->callInfo.C_Nfs2AfsCall); - printf("\t%10d afs_sun_xuntext\n", cmp->callInfo.C_afs_sun_xuntext); - printf("\t%10d osi_Active\n", cmp->callInfo.C_osi_Active); - printf("\t%10d osi_FlushPages\n", cmp->callInfo.C_osi_FlushPages); - printf("\t%10d osi_FlushText\n", cmp->callInfo.C_osi_FlushText); - printf("\t%10d osi_CallProc\n", cmp->callInfo.C_osi_CallProc); - printf("\t%10d osi_CancelProc\n", cmp->callInfo.C_osi_CancelProc); - printf("\t%10d osi_Invisible\n", cmp->callInfo.C_osi_Invisible); - printf("\t%10d osi_Time\n", cmp->callInfo.C_osi_Time); - printf("\t%10d osi_Alloc\n", cmp->callInfo.C_osi_Alloc); - printf("\t%10d osi_SetTime\n", cmp->callInfo.C_osi_SetTime); - printf("\t%10d osi_Dump\n", cmp->callInfo.C_osi_Dump); - printf("\t%10d osi_Free\n", cmp->callInfo.C_osi_Free); - printf("\t%10d osi_UFSOpen\n", cmp->callInfo.C_osi_UFSOpen); - printf("\t%10d osi_Close\n", cmp->callInfo.C_osi_Close); - printf("\t%10d osi_Stat\n", cmp->callInfo.C_osi_Stat); - printf("\t%10d osi_Truncate\n", cmp->callInfo.C_osi_Truncate); - printf("\t%10d osi_Read\n", cmp->callInfo.C_osi_Read); - printf("\t%10d osi_Write\n", cmp->callInfo.C_osi_Write); - printf("\t%10d osi_MapStrategy\n", cmp->callInfo.C_osi_MapStrategy); - printf("\t%10d osi_AllocLargeSpace\n", cmp->callInfo.C_osi_AllocLargeSpace); - printf("\t%10d osi_FreeLargeSpace\n", cmp->callInfo.C_osi_FreeLargeSpace); - printf("\t%10d osi_AllocSmallSpace\n", cmp->callInfo.C_osi_AllocSmallSpace); - printf("\t%10d osi_FreeSmallSpace\n", cmp->callInfo.C_osi_FreeSmallSpace); - printf("\t%10d osi_CloseToTheEdge\n", cmp->callInfo.C_osi_CloseToTheEdge); - printf("\t%10d osi_xgreedy\n", cmp->callInfo.C_osi_xgreedy); - printf("\t%10d osi_FreeSocket\n", cmp->callInfo.C_osi_FreeSocket); - printf("\t%10d osi_NewSocket\n", cmp->callInfo.C_osi_NewSocket); - printf("\t%10d osi_NetSend\n", cmp->callInfo.C_osi_NetSend); - printf("\t%10d WaitHack\n", cmp->callInfo.C_WaitHack); - printf("\t%10d osi_CancelWait\n", cmp->callInfo.C_osi_CancelWait); - printf("\t%10d osi_Wakeup\n", cmp->callInfo.C_osi_Wakeup); - printf("\t%10d osi_Wait\n", cmp->callInfo.C_osi_Wait); - printf("\t%10d dirp_Read\n", cmp->callInfo.C_dirp_Read); - printf("\t%10d dirp_Cpy\n", cmp->callInfo.C_dirp_Cpy); - printf("\t%10d dirp_Eq\n", cmp->callInfo.C_dirp_Eq); - printf("\t%10d dirp_Write\n", cmp->callInfo.C_dirp_Write); - printf("\t%10d dirp_Zap\n", cmp->callInfo.C_dirp_Zap); - printf("\t%10d afs_ioctl\n", cmp->callInfo.C_afs_ioctl); - printf("\t%10d handleIoctl\n", cmp->callInfo.C_HandleIoctl); - printf("\t%10d afs_xioctl\n", cmp->callInfo.C_afs_xioctl); - printf("\t%10d afs_pioctl\n", cmp->callInfo.C_afs_pioctl); - printf("\t%10d HandlePioctl\n", cmp->callInfo.C_HandlePioctl); - printf("\t%10d PGetVolumeStatus\n", cmp->callInfo.C_PGetVolumeStatus); - printf("\t%10d PSetVolumeStatus\n", cmp->callInfo.C_PSetVolumeStatus); - printf("\t%10d PFlush\n", cmp->callInfo.C_PFlush); - printf("\t%10d PFlushVolumeData\n", cmp->callInfo.C_PFlushVolumeData); - printf("\t%10d PNewStatMount\n", cmp->callInfo.C_PNewStatMount); - printf("\t%10d PGetTokens\n", cmp->callInfo.C_PGetTokens); - printf("\t%10d PSetTokens\n", cmp->callInfo.C_PSetTokens); - printf("\t%10d PUnlog\n", cmp->callInfo.C_PUnlog); - printf("\t%10d PCheckServers\n", cmp->callInfo.C_PCheckServers); - printf("\t%10d PCheckAuth\n", cmp->callInfo.C_PCheckAuth); - printf("\t%10d PCheckVolNames\n", cmp->callInfo.C_PCheckVolNames); - printf("\t%10d PFindVolume\n", cmp->callInfo.C_PFindVolume); - printf("\t%10d Prefetch\n", cmp->callInfo.C_Prefetch); - printf("\t%10d PGetCacheSize\n", cmp->callInfo.C_PGetCacheSize); - printf("\t%10d PSetCacheSize\n", cmp->callInfo.C_PSetCacheSize); - printf("\t%10d PSetSysName\n", cmp->callInfo.C_PSetSysName); - printf("\t%10d PExportAfs\n", cmp->callInfo.C_PExportAfs); - printf("\t%10d HandleClientContext\n", cmp->callInfo.C_HandleClientContext); - printf("\t%10d PViceAccess\n", cmp->callInfo.C_PViceAccess); - printf("\t%10d PRemoveCallBack\n", cmp->callInfo.C_PRemoveCallBack); - printf("\t%10d PRemoveMount\n", cmp->callInfo.C_PRemoveMount); - printf("\t%10d PSetVolumeStatus\n", cmp->callInfo.C_PSetVolumeStatus); - printf("\t%10d PListCells\n", cmp->callInfo.C_PListCells); - printf("\t%10d PNewCell\n", cmp->callInfo.C_PNewCell); - printf("\t%10d PGetUserCell\n", cmp->callInfo.C_PGetUserCell); - printf("\t%10d PGetCellStatus\n", cmp->callInfo.C_PGetCellStatus); - printf("\t%10d PSetCellStatus\n", cmp->callInfo.C_PSetCellStatus); - printf("\t%10d PVenusLogging\n", cmp->callInfo.C_PVenusLogging); - printf("\t%10d PGetAcl\n", cmp->callInfo.C_PGetAcl); - printf("\t%10d PGetFID\n", cmp->callInfo.C_PGetFID); - printf("\t%10d PSetAcl\n", cmp->callInfo.C_PSetAcl); - printf("\t%10d PGetFileCell\n", cmp->callInfo.C_PGetFileCell); - printf("\t%10d PGetWSCell\n", cmp->callInfo.C_PGetWSCell); - printf("\t%10d PGetSPrefs\n", cmp->callInfo.C_PGetSPrefs); - printf("\t%10d PSetSPrefs\n", cmp->callInfo.C_PSetSPrefs); - printf("\t%10d afs_ResetAccessCache\n", cmp->callInfo.C_afs_ResetAccessCache); - printf("\t%10d afs_FindUser\n", cmp->callInfo.C_afs_FindUser); - printf("\t%10d afs_GetUser\n", cmp->callInfo.C_afs_GetUser); - printf("\t%10d afs_GCUserData\n", cmp->callInfo.C_afs_GCUserData); - printf("\t%10d afs_PutUser\n", cmp->callInfo.C_afs_PutUser); - printf("\t%10d afs_SetPrimary\n", cmp->callInfo.C_afs_SetPrimary); - printf("\t%10d afs_ResetUserConns\n", cmp->callInfo.C_afs_ResetUserConns); - printf("\t%10d afs_RemoveUserConns\n", cmp->callInfo.C_RemoveUserConns); - printf("\t%10d afs_ResourceInit\n", cmp->callInfo.C_afs_ResourceInit); - printf("\t%10d afs_GetCell\n", cmp->callInfo.C_afs_GetCell); - printf("\t%10d afs_GetCellByIndex\n", cmp->callInfo.C_afs_GetCellByIndex); - printf("\t%10d afs_GetCellByName\n", cmp->callInfo.C_afs_GetCellByName); - printf("\t%10d afs_GetRealCellByIndex\n", cmp->callInfo.C_afs_GetRealCellByIndex); - printf("\t%10d afs_NewCell\n", cmp->callInfo.C_afs_NewCell); - printf("\t%10d CheckVLDB\n", cmp->callInfo.C_CheckVLDB); - printf("\t%10d afs_GetVolume\n", cmp->callInfo.C_afs_GetVolume); - printf("\t%10d afs_PutVolume\n", cmp->callInfo.C_afs_PutVolume); - printf("\t%10d afs_GetVolumeByName\n", cmp->callInfo.C_afs_GetVolumeByName); - printf("\t%10d afs_random\n", cmp->callInfo.C_afs_random); - printf("\t%10d InstallVolumeEntry\n", cmp->callInfo.C_InstallVolumeEntry); - printf("\t%10d InstallVolumeInfo\n", cmp->callInfo.C_InstallVolumeInfo); - printf("\t%10d afs_ResetVolumeInfo\n", cmp->callInfo.C_afs_ResetVolumeInfo); - printf("\t%10d afs_FindServer\n", cmp->callInfo.C_afs_FindServer); - printf("\t%10d afs_GetServer\n", cmp->callInfo.C_afs_GetServer); - printf("\t%10d afs_SortServers\n", cmp->callInfo.C_afs_SortServers); - printf("\t%10d afs_CheckServers\n", cmp->callInfo.C_afs_CheckServers); - printf("\t%10d ServerDown\n", cmp->callInfo.C_ServerDown); - printf("\t%10d afs_Conn\n", cmp->callInfo.C_afs_Conn); - printf("\t%10d afs_PutConn\n", cmp->callInfo.C_afs_PutConn); - printf("\t%10d afs_ConnByHost\n", cmp->callInfo.C_afs_ConnByHost); - printf("\t%10d afs_ConnByMHosts\n", cmp->callInfo.C_afs_ConnByMHosts); - printf("\t%10d afs_Analyze\n", cmp->callInfo.C_afs_Analyze); - printf("\t%10d afs_CheckLocks\n", cmp->callInfo.C_afs_CheckLocks); - printf("\t%10d CheckVLServer\n", cmp->callInfo.C_CheckVLServer); - printf("\t%10d afs_CheckCacheResets\n", cmp->callInfo.C_afs_CheckCacheResets); - printf("\t%10d afs_CheckVolumeNames\n", cmp->callInfo.C_afs_CheckVolumeNames); - printf("\t%10d afs_CheckCode\n", cmp->callInfo.C_afs_CheckCode); - printf("\t%10d afs_CopyError\n", cmp->callInfo.C_afs_CopyError); - printf("\t%10d afs_FinalizeReq\n", cmp->callInfo.C_afs_FinalizeReq); - printf("\t%10d afs_GetVolCache\n", cmp->callInfo.C_afs_GetVolCache); - printf("\t%10d afs_GetVolSlot\n", cmp->callInfo.C_afs_GetVolSlot); - printf("\t%10d afs_UFSGetVolSlot\n", cmp->callInfo.C_afs_UFSGetVolSlot); - printf("\t%10d afs_MemGetVolSlot\n", cmp->callInfo.C_afs_MemGetVolSlot); - printf("\t%10d afs_WriteVolCache\n", cmp->callInfo.C_afs_WriteVolCache); - printf("\t%10d haveCallbacksfrom\n", cmp->callInfo.C_HaveCallBacksFrom); - printf("\t%10d afs_getpage\n", cmp->callInfo.C_afs_getpage); - printf("\t%10d afs_putpage\n", cmp->callInfo.C_afs_putpage); - printf("\t%10d afs_nfsrdwr\n", cmp->callInfo.C_afs_nfsrdwr); - printf("\t%10d afs_map\n", cmp->callInfo.C_afs_map); - printf("\t%10d afs_cmp\n", cmp->callInfo.C_afs_cmp); - printf("\t%10d afs_PageLeft\n", cmp->callInfo.C_afs_PageLeft); - printf("\t%10d afs_mount\n", cmp->callInfo.C_afs_mount); - printf("\t%10d afs_unmount\n", cmp->callInfo.C_afs_unmount); - printf("\t%10d afs_root\n", cmp->callInfo.C_afs_root); - printf("\t%10d afs_statfs\n", cmp->callInfo.C_afs_statfs); - printf("\t%10d afs_sync\n", cmp->callInfo.C_afs_sync); - printf("\t%10d afs_vget\n", cmp->callInfo.C_afs_vget); - printf("\t%10d afs_index\n", cmp->callInfo.C_afs_index); - printf("\t%10d afs_setpag\n", cmp->callInfo.C_afs_setpag); - printf("\t%10d genpag\n", cmp->callInfo.C_genpag); - printf("\t%10d getpag\n", cmp->callInfo.C_getpag); - printf("\t%10d genpag\n", cmp->callInfo.C_genpag); - printf("\t%10d afs_GetMariner\n", cmp->callInfo.C_afs_GetMariner); - printf("\t%10d afs_AddMarinerName\n", cmp->callInfo.C_afs_AddMarinerName); - printf("\t%10d afs_open\n", cmp->callInfo.C_afs_open); - printf("\t%10d afs_close\n", cmp->callInfo.C_afs_close); - printf("\t%10d afs_closex\n", cmp->callInfo.C_afs_closex); - printf("\t%10d afs_write\n", cmp->callInfo.C_afs_write); - printf("\t%10d afs_UFSwrite\n", cmp->callInfo.C_afs_UFSWrite); - printf("\t%10d afs_Memwrite\n", cmp->callInfo.C_afs_MemWrite); - printf("\t%10d afs_rdwr\n", cmp->callInfo.C_afs_rdwr); - printf("\t%10d afs_read\n", cmp->callInfo.C_afs_read); - printf("\t%10d afs_UFSread\n", cmp->callInfo.C_afs_UFSRead); - printf("\t%10d afs_Memread\n", cmp->callInfo.C_afs_MemRead); - printf("\t%10d afs_CopyOutAttrs\n", cmp->callInfo.C_afs_CopyOutAttrs); - printf("\t%10d afs_access\n", cmp->callInfo.C_afs_access); - printf("\t%10d afs_getattr\n", cmp->callInfo.C_afs_getattr); - printf("\t%10d afs_setattr\n", cmp->callInfo.C_afs_setattr); - printf("\t%10d afs_VAttrToAS\n", cmp->callInfo.C_afs_VAttrToAS); - printf("\t%10d EvalMountPoint\n", cmp->callInfo.C_EvalMountPoint); - printf("\t%10d afs_lookup\n", cmp->callInfo.C_afs_lookup); - printf("\t%10d afs_create\n", cmp->callInfo.C_afs_create); - printf("\t%10d afs_LocalHero\n", cmp->callInfo.C_afs_LocalHero); - printf("\t%10d afs_remove\n", cmp->callInfo.C_afs_remove); - printf("\t%10d afs_link\n", cmp->callInfo.C_afs_link); - printf("\t%10d afs_rename\n", cmp->callInfo.C_afs_rename); - printf("\t%10d afs_InitReq\n", cmp->callInfo.C_afs_InitReq); - printf("\t%10d afs_mkdir\n", cmp->callInfo.C_afs_mkdir); - printf("\t%10d afs_rmdir\n", cmp->callInfo.C_afs_rmdir); - printf("\t%10d afs_readdir\n", cmp->callInfo.C_afs_readdir); - printf("\t%10d afs_read1dir\n", cmp->callInfo.C_afs_read1dir); - printf("\t%10d afs_readdir_move\n", cmp->callInfo.C_afs_readdir_move); - printf("\t%10d afs_readdir_iter\n", cmp->callInfo.C_afs_readdir_iter); - printf("\t%10d afs_symlink\n", cmp->callInfo.C_afs_symlink); - printf("\t%10d afs_HandleLink\n", cmp->callInfo.C_afs_HandleLink); - printf("\t%10d afs_MemHandleLink\n", cmp->callInfo.C_afs_MemHandleLink); - printf("\t%10d afs_UFSHandleLink\n", cmp->callInfo.C_afs_UFSHandleLink); - printf("\t%10d HandleFlock\n", cmp->callInfo.C_HandleFlock); - printf("\t%10d afs_readlink\n", cmp->callInfo.C_afs_readlink); - printf("\t%10d afs_fsync\n", cmp->callInfo.C_afs_fsync); - printf("\t%10d afs_inactive\n", cmp->callInfo.C_afs_inactive); - printf("\t%10d afs_ustrategy\n", cmp->callInfo.C_afs_ustrategy); - printf("\t%10d afs_strategy\n", cmp->callInfo.C_afs_strategy); - printf("\t%10d afs_bread\n", cmp->callInfo.C_afs_bread); - printf("\t%10d afs_brelse\n", cmp->callInfo.C_afs_brelse); - printf("\t%10d afs_bmap\n", cmp->callInfo.C_afs_bmap); - printf("\t%10d afs_fid\n", cmp->callInfo.C_afs_fid); - printf("\t%10d afs_FakeOpen\n", cmp->callInfo.C_afs_FakeOpen); - printf("\t%10d afs_FakeClose\n", cmp->callInfo.C_afs_FakeClose); - printf("\t%10d afs_StoreOnLastReference\n", cmp->callInfo.C_afs_StoreOnLastReference); - printf("\t%10d afs_AccessOK\n", cmp->callInfo.C_afs_AccessOK); - printf("\t%10d afs_GetAccessBits\n", cmp->callInfo.C_afs_GetAccessBits); - printf("\t%10d afsio_copy\n", cmp->callInfo.C_afsio_copy); - printf("\t%10d afsio_trim\n", cmp->callInfo.C_afsio_trim); - printf("\t%10d afsio_skip\n", cmp->callInfo.C_afsio_skip); - printf("\t%10d afs_page_read\n", cmp->callInfo.C_afs_page_read); - printf("\t%10d afs_page_write\n", cmp->callInfo.C_afs_page_write); - printf("\t%10d afs_page_read\n", cmp->callInfo.C_afs_page_read); - printf("\t%10d afs_get_groups_from_pag\n", cmp->callInfo.C_afs_get_groups_from_pag); - printf("\t%10d afs_get_pag_from_groups\n", cmp->callInfo.C_afs_get_pag_from_groups); - printf("\t%10d AddPag\n", cmp->callInfo.C_AddPag); - printf("\t%10d PagInCred\n", cmp->callInfo.C_PagInCred); - printf("\t%10d afs_getgroups\n", cmp->callInfo.C_afs_getgroups); - printf("\t%10d afs_page_in\n", cmp->callInfo.C_afs_page_in); - printf("\t%10d afs_page_out\n", cmp->callInfo.C_afs_page_out); - printf("\t%10d afs_AdvanceFD\n", cmp->callInfo.C_afs_AdvanceFD); - printf("\t%10d afs_lockf\n", cmp->callInfo.C_afs_lockf); - printf("\t%10d afs_xsetgroups\n", cmp->callInfo.C_afs_xsetgroups); - printf("\t%10d afs_nlinks\n", cmp->callInfo.C_afs_nlinks); - printf("\t%10d afs_lockctl\n", cmp->callInfo.C_afs_lockctl); - printf("\t%10d afs_xflock\n", cmp->callInfo.C_afs_xflock); - printf("\t%10d PGetCPrefs\n", cmp->callInfo.C_PGetCPrefs); - printf("\t%10d PSetCPrefs\n", cmp->callInfo.C_PSetCPrefs); + printf("\t%10d afs_init\n", cmp->callInfo.C_afs_init); + printf("\t%10d gop_rdwr\n", cmp->callInfo.C_gop_rdwr); + printf("\t%10d aix_gnode_rele\n", cmp->callInfo.C_aix_gnode_rele); + printf("\t%10d gettimeofday\n", cmp->callInfo.C_gettimeofday); + printf("\t%10d m_cpytoc\n", cmp->callInfo.C_m_cpytoc); + printf("\t%10d aix_vattr_null\n", cmp->callInfo.C_aix_vattr_null); + printf("\t%10d afs_gn_frunc\n", cmp->callInfo.C_afs_gn_ftrunc); + printf("\t%10d afs_gn_rdwr\n", cmp->callInfo.C_afs_gn_rdwr); + printf("\t%10d afs_gn_ioctl\n", cmp->callInfo.C_afs_gn_ioctl); + printf("\t%10d afs_gn_locktl\n", cmp->callInfo.C_afs_gn_lockctl); + printf("\t%10d afs_gn_readlink\n", cmp->callInfo.C_afs_gn_readlink); + printf("\t%10d afs_gn_readdir\n", cmp->callInfo.C_afs_gn_readdir); + printf("\t%10d afs_gn_select\n", cmp->callInfo.C_afs_gn_select); + printf("\t%10d afs_gn_strategy\n", cmp->callInfo.C_afs_gn_strategy); + printf("\t%10d afs_gn_symlink\n", cmp->callInfo.C_afs_gn_symlink); + printf("\t%10d afs_gn_revoke\n", cmp->callInfo.C_afs_gn_revoke); + printf("\t%10d afs_gn_link\n", cmp->callInfo.C_afs_gn_link); + printf("\t%10d afs_gn_mkdir\n", cmp->callInfo.C_afs_gn_mkdir); + printf("\t%10d afs_gn_mknod\n", cmp->callInfo.C_afs_gn_mknod); + printf("\t%10d afs_gn_remove\n", cmp->callInfo.C_afs_gn_remove); + printf("\t%10d afs_gn_rename\n", cmp->callInfo.C_afs_gn_rename); + printf("\t%10d afs_gn_rmdir\n", cmp->callInfo.C_afs_gn_rmdir); + printf("\t%10d afs_gn_fid\n", cmp->callInfo.C_afs_gn_fid); + printf("\t%10d afs_gn_lookup\n", cmp->callInfo.C_afs_gn_lookup); + printf("\t%10d afs_gn_open\n", cmp->callInfo.C_afs_gn_open); + printf("\t%10d afs_gn_create\n", cmp->callInfo.C_afs_gn_create); + printf("\t%10d afs_gn_hold\n", cmp->callInfo.C_afs_gn_hold); + printf("\t%10d afs_gn_rele\n", cmp->callInfo.C_afs_gn_rele); + printf("\t%10d afs_gn_unmap\n", cmp->callInfo.C_afs_gn_unmap); + printf("\t%10d afs_gn_access\n", cmp->callInfo.C_afs_gn_access); + printf("\t%10d afs_gn_getattr\n", cmp->callInfo.C_afs_gn_getattr); + printf("\t%10d afs_gn_setattr\n", cmp->callInfo.C_afs_gn_setattr); + printf("\t%10d afs_gn_fclear\n", cmp->callInfo.C_afs_gn_fclear); + printf("\t%10d afs_gn_fsync\n", cmp->callInfo.C_afs_gn_fsync); + printf("\t%10d phash\n", cmp->callInfo.C_pHash); + printf("\t%10d DInit\n", cmp->callInfo.C_DInit); + printf("\t%10d DRead\n", cmp->callInfo.C_DRead); + printf("\t%10d FixupBucket\n", cmp->callInfo.C_FixupBucket); + printf("\t%10d afs_newslot\n", cmp->callInfo.C_afs_newslot); + printf("\t%10d DRelease\n", cmp->callInfo.C_DRelease); + printf("\t%10d DFlush\n", cmp->callInfo.C_DFlush); + printf("\t%10d DFlushEntry\n", cmp->callInfo.C_DFlushEntry); + printf("\t%10d DVOffset\n", cmp->callInfo.C_DVOffset); + printf("\t%10d DZap\n", cmp->callInfo.C_DZap); + printf("\t%10d DNew\n", cmp->callInfo.C_DNew); + printf("\t%10d afs_RemoveVCB\n", cmp->callInfo.C_afs_RemoveVCB); + printf("\t%10d afs_NewVCache\n", cmp->callInfo.C_afs_NewVCache); + printf("\t%10d afs_FlushActiveVcaches\n", + cmp->callInfo.C_afs_FlushActiveVcaches); + printf("\t%10d afs_VerifyVCache\n", cmp->callInfo.C_afs_VerifyVCache); + printf("\t%10d afs_WriteVCache\n", cmp->callInfo.C_afs_WriteVCache); + printf("\t%10d afs_GetVCache\n", cmp->callInfo.C_afs_GetVCache); + printf("\t%10d afs_StuffVcache\n", cmp->callInfo.C_afs_StuffVcache); + printf("\t%10d afs_FindVCache\n", cmp->callInfo.C_afs_FindVCache); + printf("\t%10d afs_PutDCache\n", cmp->callInfo.C_afs_PutDCache); + printf("\t%10d afs_PutVCache\n", cmp->callInfo.C_afs_PutVCache); + printf("\t%10d CacheStoreProc\n", cmp->callInfo.C_CacheStoreProc); + printf("\t%10d afs_FindDcache\n", cmp->callInfo.C_afs_FindDCache); + printf("\t%10d afs_TryToSmush\n", cmp->callInfo.C_afs_TryToSmush); + printf("\t%10d afs_AdjustSize\n", cmp->callInfo.C_afs_AdjustSize); + printf("\t%10d afs_CheckSize\n", cmp->callInfo.C_afs_CheckSize); + printf("\t%10d afs_StoreWarn\n", cmp->callInfo.C_afs_StoreWarn); + printf("\t%10d CacheFetchProc\n", cmp->callInfo.C_CacheFetchProc); + printf("\t%10d UFS_CacheStoreProc\n", cmp->callInfo.C_UFS_CacheStoreProc); + printf("\t%10d UFS_CacheFetchProc\n", cmp->callInfo.C_UFS_CacheFetchProc); + printf("\t%10d afs_GetDCache\n", cmp->callInfo.C_afs_GetDCache); + printf("\t%10d afs_SimpleVStat\n", cmp->callInfo.C_afs_SimpleVStat); + printf("\t%10d afs_ProcessFS\n", cmp->callInfo.C_afs_ProcessFS); + printf("\t%10d afs_InitCacheInfo\n", cmp->callInfo.C_afs_InitCacheInfo); + printf("\t%10d afs_InitVolumeInfo\n", cmp->callInfo.C_afs_InitVolumeInfo); + printf("\t%10d afs_InitCacheFile\n", cmp->callInfo.C_afs_InitCacheFile); + printf("\t%10d afs_CacheInit\n", cmp->callInfo.C_afs_CacheInit); + printf("\t%10d afs_GetDSlot\n", cmp->callInfo.C_afs_GetDSlot); + printf("\t%10d afs_WriteThroughDSlots\n", + cmp->callInfo.C_afs_WriteThroughDSlots); + printf("\t%10d afs_MemGetDSlot\n", cmp->callInfo.C_afs_MemGetDSlot); + printf("\t%10d afs_UFSGetDSlot\n", cmp->callInfo.C_afs_UFSGetDSlot); + printf("\t%10d afs_StoreDCache\n", cmp->callInfo.C_afs_StoreDCache); + printf("\t%10d afs_StoreMini\n", cmp->callInfo.C_afs_StoreMini); + printf("\t%10d afs_StoreAllSegments\n", + cmp->callInfo.C_afs_StoreAllSegments); + printf("\t%10d afs_InvalidateAllSegments\n", + cmp->callInfo.C_afs_InvalidateAllSegments); + printf("\t%10d afs_TruncateAllSegments\n", + cmp->callInfo.C_afs_TruncateAllSegments); + printf("\t%10d afs_CheckVolSync\n", cmp->callInfo.C_afs_CheckVolSync); + printf("\t%10d afs_wakeup\n", cmp->callInfo.C_afs_wakeup); + printf("\t%10d afs_CFileOpen\n", cmp->callInfo.C_afs_CFileOpen); + printf("\t%10d afs_CFileTruncate\n", cmp->callInfo.C_afs_CFileTruncate); + printf("\t%10d afs_GetDownD\n", cmp->callInfo.C_afs_GetDownD); + printf("\t%10d afs_WriteDCache\n", cmp->callInfo.C_afs_WriteDCache); + printf("\t%10d afs_FlushDCache\n", cmp->callInfo.C_afs_FlushDCache); + printf("\t%10d afs_GetDownDSlot\n", cmp->callInfo.C_afs_GetDownDSlot); + printf("\t%10d afs_FlushVCache\n", cmp->callInfo.C_afs_FlushVCache); + printf("\t%10d afs_GetDownV\n", cmp->callInfo.C_afs_GetDownV); + printf("\t%10d afs_QueueVCB\n", cmp->callInfo.C_afs_QueueVCB); + printf("\t%10d afs_call\n", cmp->callInfo.C_afs_call); + printf("\t%10d afs_syscall_call\n", cmp->callInfo.C_afs_syscall_call); + printf("\t%10d afs_syscall_icreate\n", + cmp->callInfo.C_afs_syscall_icreate); + printf("\t%10d afs_syscall_iopen\n", cmp->callInfo.C_afs_syscall_iopen); + printf("\t%10d afs_syscall_iincdec\n", + cmp->callInfo.C_afs_syscall_iincdec); + printf("\t%10d afs_syscall_ireadwrite\n", + cmp->callInfo.C_afs_syscall_ireadwrite); + printf("\t%10d afs_syscall\n", cmp->callInfo.C_afs_syscall); + printf("\t%10d lpioctl\n", cmp->callInfo.C_lpioctl); + printf("\t%10d lsetpag\n", cmp->callInfo.C_lsetpag); + printf("\t%10d afs_CheckInit\n", cmp->callInfo.C_afs_CheckInit); + printf("\t%10d ClearCallback\n", cmp->callInfo.C_ClearCallBack); + printf("\t%10d SRXAFSCB_GetCE\n", cmp->callInfo.C_SRXAFSCB_GetCE); + printf("\t%10d SRXAFSCB_GetLock\n", cmp->callInfo.C_SRXAFSCB_GetLock); + printf("\t%10d SRXAFSCB_CallBack\n", cmp->callInfo.C_SRXAFSCB_CallBack); + printf("\t%10d SRXAFSCB_InitCallBackState\n", + cmp->callInfo.C_SRXAFSCB_InitCallBackState); + printf("\t%10d SRXAFSCB_Probe\n", cmp->callInfo.C_SRXAFSCB_Probe); + printf("\t%10d afs_Chunk\n", cmp->callInfo.C_afs_Chunk); + printf("\t%10d afs_ChunkBase\n", cmp->callInfo.C_afs_ChunkBase); + printf("\t%10d afs_ChunkOffset\n", cmp->callInfo.C_afs_ChunkOffset); + printf("\t%10d afs_ChunkSize\n", cmp->callInfo.C_afs_ChunkSize); + printf("\t%10d afs_ChunkToBase\n", cmp->callInfo.C_afs_ChunkToBase); + printf("\t%10d afs_ChunkToSize\n", cmp->callInfo.C_afs_ChunkToSize); + printf("\t%10d afs_SetChunkSize\n", cmp->callInfo.C_afs_SetChunkSize); + printf("\t%10d afs_config\n", cmp->callInfo.C_afs_config); + printf("\t%10d mem_freebytes\n", cmp->callInfo.C_mem_freebytes); + printf("\t%10d mem_getbytes\n", cmp->callInfo.C_mem_getbytes); + printf("\t%10d afs_Daemon\n", cmp->callInfo.C_afs_Daemon); + printf("\t%10d afs_CheckRootVolume\n", + cmp->callInfo.C_afs_CheckRootVolume); + printf("\t%10d BPath\n", cmp->callInfo.C_BPath); + printf("\t%10d BPrefetch\n", cmp->callInfo.C_BPrefetch); + printf("\t%10d BStore\n", cmp->callInfo.C_BStore); + printf("\t%10d afs_BBusy\n", cmp->callInfo.C_afs_BBusy); + printf("\t%10d afs_BQueue\n", cmp->callInfo.C_afs_BQueue); + printf("\t%10d afs_BRelease\n", cmp->callInfo.C_afs_BRelease); + printf("\t%10d afs_BackgroundDaemon\n", + cmp->callInfo.C_afs_BackgroundDaemon); + printf("\t%10d exporter_add\n", cmp->callInfo.C_exporter_add); + printf("\t%10d exporter_find\n", cmp->callInfo.C_exporter_find); + printf("\t%10d afs_gfs_kalloc\n", cmp->callInfo.C_afs_gfs_kalloc); + printf("\t%10d afs_gfs_kfree\n", cmp->callInfo.C_afs_gfs_kfree); + printf("\t%10d gop_lookupname\n", cmp->callInfo.C_gop_lookupname); + printf("\t%10d afs_uniqtime\n", cmp->callInfo.C_afs_uniqtime); + printf("\t%10d gfs_vattr_null\n", cmp->callInfo.C_gfs_vattr_null); + printf("\t%10d afs_lock\n", cmp->callInfo.C_afs_lock); + printf("\t%10d afs_unlock\n", cmp->callInfo.C_afs_unlock); + printf("\t%10d afs_update\n", cmp->callInfo.C_afs_update); + printf("\t%10d afs_gclose\n", cmp->callInfo.C_afs_gclose); + printf("\t%10d afs_gopen\n", cmp->callInfo.C_afs_gopen); + printf("\t%10d afs_greadlink\n", cmp->callInfo.C_afs_greadlink); + printf("\t%10d afs_select\n", cmp->callInfo.C_afs_select); + printf("\t%10d afs_gbmap\n", cmp->callInfo.C_afs_gbmap); + printf("\t%10d afs_getfsdata\n", cmp->callInfo.C_afs_getfsdata); + printf("\t%10d afs_gsymlink\n", cmp->callInfo.C_afs_gsymlink); + printf("\t%10d afs_namei\n", cmp->callInfo.C_afs_namei); + printf("\t%10d afs_gmount\n", cmp->callInfo.C_afs_gmount); + printf("\t%10d afs_gget\n", cmp->callInfo.C_afs_gget); + printf("\t%10d afs_glink\n", cmp->callInfo.C_afs_glink); + printf("\t%10d afs_gmkdir\n", cmp->callInfo.C_afs_gmkdir); + printf("\t%10d afs_unlink\n", cmp->callInfo.C_afs_unlink); + printf("\t%10d afs_grmdir\n", cmp->callInfo.C_afs_grmdir); + printf("\t%10d afs_makenode\n", cmp->callInfo.C_afs_makenode); + printf("\t%10d afs_grename\n", cmp->callInfo.C_afs_grename); + printf("\t%10d afs_rele\n", cmp->callInfo.C_afs_rele); + printf("\t%10d afs_syncgp\n", cmp->callInfo.C_afs_syncgp); + printf("\t%10d afs_getval\n", cmp->callInfo.C_afs_getval); + printf("\t%10d afs_trunc\n", cmp->callInfo.C_afs_trunc); + printf("\t%10d afs_rwgp\n", cmp->callInfo.C_afs_rwgp); + printf("\t%10d afs_stat\n", cmp->callInfo.C_afs_stat); + printf("\t%10d afsc_link\n", cmp->callInfo.C_afsc_link); + printf("\t%10d afs_vfs_mount\n", cmp->callInfo.C_afs_vfs_mount); + printf("\t%10d afs_uniqtime\n", cmp->callInfo.C_afs_uniqtime); + printf("\t%10d iopen\n", cmp->callInfo.C_iopen); + printf("\t%10d idec\n", cmp->callInfo.C_idec); + printf("\t%10d iinc\n", cmp->callInfo.C_iinc); + printf("\t%10d ireadwrite\n", cmp->callInfo.C_ireadwrite); + printf("\t%10d iread\n", cmp->callInfo.C_iread); + printf("\t%10d iwrite\n", cmp->callInfo.C_iwrite); + printf("\t%10d iforget\n", cmp->callInfo.C_iforget); + printf("\t%10d icreate\n", cmp->callInfo.C_icreate); + printf("\t%10d igetinode\n", cmp->callInfo.C_igetinode); + printf("\t%10d osi_SleepR\n", cmp->callInfo.C_osi_SleepR); + printf("\t%10d osi_SleepS\n", cmp->callInfo.C_osi_SleepS); + printf("\t%10d osi_SleepW\n", cmp->callInfo.C_osi_SleepW); + printf("\t%10d osi_Sleep\n", cmp->callInfo.C_osi_Sleep); + printf("\t%10d afs_LookupMCE\n", cmp->callInfo.C_afs_LookupMCE); + printf("\t%10d afs_MemReadBlk\n", cmp->callInfo.C_afs_MemReadBlk); + printf("\t%10d afs_MemReadUIO\n", cmp->callInfo.C_afs_MemReadUIO); + printf("\t%10d afs_MemWriteBlk\n", cmp->callInfo.C_afs_MemWriteBlk); + printf("\t%10d afs_MemWriteUIO\n", cmp->callInfo.C_afs_MemWriteUIO); + printf("\t%10d afs_MemCacheStoreProc\n", + cmp->callInfo.C_afs_MemCacheStoreProc); + printf("\t%10d afs_MemCacheFetchProc\n", + cmp->callInfo.C_afs_MemCacheFetchProc); + printf("\t%10d afs_MemCacheTruncate\n", + cmp->callInfo.C_afs_MemCacheTruncate); + printf("\t%10d afs_MemCacheStoreProc\n", + cmp->callInfo.C_afs_MemCacheStoreProc); + printf("\t%10d afs_GetNfsClientPag\n", + cmp->callInfo.C_afs_GetNfsClientPag); + printf("\t%10d afs_FindNfsClientPag\n", + cmp->callInfo.C_afs_FindNfsClientPag); + printf("\t%10d afs_PutNfsClientPag\n", + cmp->callInfo.C_afs_PutNfsClientPag); + printf("\t%10d afs_nfsclient_reqhandler\n", + cmp->callInfo.C_afs_nfsclient_reqhandler); + printf("\t%10d afs_nfsclient_GC\n", cmp->callInfo.C_afs_nfsclient_GC); + printf("\t%10d afs_nfsclient_hold\n", cmp->callInfo.C_afs_nfsclient_hold); + printf("\t%10d afs_nfsclient_stats\n", + cmp->callInfo.C_afs_nfsclient_stats); + printf("\t%10d afs_nfsclient_sysname\n", + cmp->callInfo.C_afs_nfsclient_sysname); + printf("\t%10d afs_rfs_dispatch\n", cmp->callInfo.C_afs_rfs_dispatch); + printf("\t%10d afs_nfs2afscall\n", cmp->callInfo.C_Nfs2AfsCall); + printf("\t%10d afs_sun_xuntext\n", cmp->callInfo.C_afs_sun_xuntext); + printf("\t%10d osi_Active\n", cmp->callInfo.C_osi_Active); + printf("\t%10d osi_FlushPages\n", cmp->callInfo.C_osi_FlushPages); + printf("\t%10d osi_FlushText\n", cmp->callInfo.C_osi_FlushText); + printf("\t%10d osi_CallProc\n", cmp->callInfo.C_osi_CallProc); + printf("\t%10d osi_CancelProc\n", cmp->callInfo.C_osi_CancelProc); + printf("\t%10d osi_Invisible\n", cmp->callInfo.C_osi_Invisible); + printf("\t%10d osi_Time\n", cmp->callInfo.C_osi_Time); + printf("\t%10d osi_Alloc\n", cmp->callInfo.C_osi_Alloc); + printf("\t%10d osi_SetTime\n", cmp->callInfo.C_osi_SetTime); + printf("\t%10d osi_Dump\n", cmp->callInfo.C_osi_Dump); + printf("\t%10d osi_Free\n", cmp->callInfo.C_osi_Free); + printf("\t%10d osi_UFSOpen\n", cmp->callInfo.C_osi_UFSOpen); + printf("\t%10d osi_Close\n", cmp->callInfo.C_osi_Close); + printf("\t%10d osi_Stat\n", cmp->callInfo.C_osi_Stat); + printf("\t%10d osi_Truncate\n", cmp->callInfo.C_osi_Truncate); + printf("\t%10d osi_Read\n", cmp->callInfo.C_osi_Read); + printf("\t%10d osi_Write\n", cmp->callInfo.C_osi_Write); + printf("\t%10d osi_MapStrategy\n", cmp->callInfo.C_osi_MapStrategy); + printf("\t%10d osi_AllocLargeSpace\n", + cmp->callInfo.C_osi_AllocLargeSpace); + printf("\t%10d osi_FreeLargeSpace\n", cmp->callInfo.C_osi_FreeLargeSpace); + printf("\t%10d osi_AllocSmallSpace\n", + cmp->callInfo.C_osi_AllocSmallSpace); + printf("\t%10d osi_FreeSmallSpace\n", cmp->callInfo.C_osi_FreeSmallSpace); + printf("\t%10d osi_CloseToTheEdge\n", cmp->callInfo.C_osi_CloseToTheEdge); + printf("\t%10d osi_xgreedy\n", cmp->callInfo.C_osi_xgreedy); + printf("\t%10d osi_FreeSocket\n", cmp->callInfo.C_osi_FreeSocket); + printf("\t%10d osi_NewSocket\n", cmp->callInfo.C_osi_NewSocket); + printf("\t%10d osi_NetSend\n", cmp->callInfo.C_osi_NetSend); + printf("\t%10d WaitHack\n", cmp->callInfo.C_WaitHack); + printf("\t%10d osi_CancelWait\n", cmp->callInfo.C_osi_CancelWait); + printf("\t%10d osi_Wakeup\n", cmp->callInfo.C_osi_Wakeup); + printf("\t%10d osi_Wait\n", cmp->callInfo.C_osi_Wait); + printf("\t%10d dirp_Read\n", cmp->callInfo.C_dirp_Read); + printf("\t%10d dirp_Cpy\n", cmp->callInfo.C_dirp_Cpy); + printf("\t%10d dirp_Eq\n", cmp->callInfo.C_dirp_Eq); + printf("\t%10d dirp_Write\n", cmp->callInfo.C_dirp_Write); + printf("\t%10d dirp_Zap\n", cmp->callInfo.C_dirp_Zap); + printf("\t%10d afs_ioctl\n", cmp->callInfo.C_afs_ioctl); + printf("\t%10d handleIoctl\n", cmp->callInfo.C_HandleIoctl); + printf("\t%10d afs_xioctl\n", cmp->callInfo.C_afs_xioctl); + printf("\t%10d afs_pioctl\n", cmp->callInfo.C_afs_pioctl); + printf("\t%10d HandlePioctl\n", cmp->callInfo.C_HandlePioctl); + printf("\t%10d PGetVolumeStatus\n", cmp->callInfo.C_PGetVolumeStatus); + printf("\t%10d PSetVolumeStatus\n", cmp->callInfo.C_PSetVolumeStatus); + printf("\t%10d PFlush\n", cmp->callInfo.C_PFlush); + printf("\t%10d PFlushVolumeData\n", cmp->callInfo.C_PFlushVolumeData); + printf("\t%10d PNewStatMount\n", cmp->callInfo.C_PNewStatMount); + printf("\t%10d PGetTokens\n", cmp->callInfo.C_PGetTokens); + printf("\t%10d PSetTokens\n", cmp->callInfo.C_PSetTokens); + printf("\t%10d PUnlog\n", cmp->callInfo.C_PUnlog); + printf("\t%10d PCheckServers\n", cmp->callInfo.C_PCheckServers); + printf("\t%10d PCheckAuth\n", cmp->callInfo.C_PCheckAuth); + printf("\t%10d PCheckVolNames\n", cmp->callInfo.C_PCheckVolNames); + printf("\t%10d PFindVolume\n", cmp->callInfo.C_PFindVolume); + printf("\t%10d Prefetch\n", cmp->callInfo.C_Prefetch); + printf("\t%10d PGetCacheSize\n", cmp->callInfo.C_PGetCacheSize); + printf("\t%10d PSetCacheSize\n", cmp->callInfo.C_PSetCacheSize); + printf("\t%10d PSetSysName\n", cmp->callInfo.C_PSetSysName); + printf("\t%10d PExportAfs\n", cmp->callInfo.C_PExportAfs); + printf("\t%10d HandleClientContext\n", + cmp->callInfo.C_HandleClientContext); + printf("\t%10d PViceAccess\n", cmp->callInfo.C_PViceAccess); + printf("\t%10d PRemoveCallBack\n", cmp->callInfo.C_PRemoveCallBack); + printf("\t%10d PRemoveMount\n", cmp->callInfo.C_PRemoveMount); + printf("\t%10d PSetVolumeStatus\n", cmp->callInfo.C_PSetVolumeStatus); + printf("\t%10d PListCells\n", cmp->callInfo.C_PListCells); + printf("\t%10d PNewCell\n", cmp->callInfo.C_PNewCell); + printf("\t%10d PGetUserCell\n", cmp->callInfo.C_PGetUserCell); + printf("\t%10d PGetCellStatus\n", cmp->callInfo.C_PGetCellStatus); + printf("\t%10d PSetCellStatus\n", cmp->callInfo.C_PSetCellStatus); + printf("\t%10d PVenusLogging\n", cmp->callInfo.C_PVenusLogging); + printf("\t%10d PGetAcl\n", cmp->callInfo.C_PGetAcl); + printf("\t%10d PGetFID\n", cmp->callInfo.C_PGetFID); + printf("\t%10d PSetAcl\n", cmp->callInfo.C_PSetAcl); + printf("\t%10d PGetFileCell\n", cmp->callInfo.C_PGetFileCell); + printf("\t%10d PGetWSCell\n", cmp->callInfo.C_PGetWSCell); + printf("\t%10d PGetSPrefs\n", cmp->callInfo.C_PGetSPrefs); + printf("\t%10d PSetSPrefs\n", cmp->callInfo.C_PSetSPrefs); + printf("\t%10d afs_ResetAccessCache\n", + cmp->callInfo.C_afs_ResetAccessCache); + printf("\t%10d afs_FindUser\n", cmp->callInfo.C_afs_FindUser); + printf("\t%10d afs_GetUser\n", cmp->callInfo.C_afs_GetUser); + printf("\t%10d afs_GCUserData\n", cmp->callInfo.C_afs_GCUserData); + printf("\t%10d afs_PutUser\n", cmp->callInfo.C_afs_PutUser); + printf("\t%10d afs_SetPrimary\n", cmp->callInfo.C_afs_SetPrimary); + printf("\t%10d afs_ResetUserConns\n", cmp->callInfo.C_afs_ResetUserConns); + printf("\t%10d afs_RemoveUserConns\n", cmp->callInfo.C_RemoveUserConns); + printf("\t%10d afs_ResourceInit\n", cmp->callInfo.C_afs_ResourceInit); + printf("\t%10d afs_GetCell\n", cmp->callInfo.C_afs_GetCell); + printf("\t%10d afs_GetCellByIndex\n", cmp->callInfo.C_afs_GetCellByIndex); + printf("\t%10d afs_GetCellByName\n", cmp->callInfo.C_afs_GetCellByName); + printf("\t%10d afs_GetRealCellByIndex\n", + cmp->callInfo.C_afs_GetRealCellByIndex); + printf("\t%10d afs_NewCell\n", cmp->callInfo.C_afs_NewCell); + printf("\t%10d CheckVLDB\n", cmp->callInfo.C_CheckVLDB); + printf("\t%10d afs_GetVolume\n", cmp->callInfo.C_afs_GetVolume); + printf("\t%10d afs_PutVolume\n", cmp->callInfo.C_afs_PutVolume); + printf("\t%10d afs_GetVolumeByName\n", + cmp->callInfo.C_afs_GetVolumeByName); + printf("\t%10d afs_random\n", cmp->callInfo.C_afs_random); + printf("\t%10d InstallVolumeEntry\n", cmp->callInfo.C_InstallVolumeEntry); + printf("\t%10d InstallVolumeInfo\n", cmp->callInfo.C_InstallVolumeInfo); + printf("\t%10d afs_ResetVolumeInfo\n", + cmp->callInfo.C_afs_ResetVolumeInfo); + printf("\t%10d afs_FindServer\n", cmp->callInfo.C_afs_FindServer); + printf("\t%10d afs_GetServer\n", cmp->callInfo.C_afs_GetServer); + printf("\t%10d afs_SortServers\n", cmp->callInfo.C_afs_SortServers); + printf("\t%10d afs_CheckServers\n", cmp->callInfo.C_afs_CheckServers); + printf("\t%10d ServerDown\n", cmp->callInfo.C_ServerDown); + printf("\t%10d afs_Conn\n", cmp->callInfo.C_afs_Conn); + printf("\t%10d afs_PutConn\n", cmp->callInfo.C_afs_PutConn); + printf("\t%10d afs_ConnByHost\n", cmp->callInfo.C_afs_ConnByHost); + printf("\t%10d afs_ConnByMHosts\n", cmp->callInfo.C_afs_ConnByMHosts); + printf("\t%10d afs_Analyze\n", cmp->callInfo.C_afs_Analyze); + printf("\t%10d afs_CheckLocks\n", cmp->callInfo.C_afs_CheckLocks); + printf("\t%10d CheckVLServer\n", cmp->callInfo.C_CheckVLServer); + printf("\t%10d afs_CheckCacheResets\n", + cmp->callInfo.C_afs_CheckCacheResets); + printf("\t%10d afs_CheckVolumeNames\n", + cmp->callInfo.C_afs_CheckVolumeNames); + printf("\t%10d afs_CheckCode\n", cmp->callInfo.C_afs_CheckCode); + printf("\t%10d afs_CopyError\n", cmp->callInfo.C_afs_CopyError); + printf("\t%10d afs_FinalizeReq\n", cmp->callInfo.C_afs_FinalizeReq); + printf("\t%10d afs_GetVolCache\n", cmp->callInfo.C_afs_GetVolCache); + printf("\t%10d afs_GetVolSlot\n", cmp->callInfo.C_afs_GetVolSlot); + printf("\t%10d afs_UFSGetVolSlot\n", cmp->callInfo.C_afs_UFSGetVolSlot); + printf("\t%10d afs_MemGetVolSlot\n", cmp->callInfo.C_afs_MemGetVolSlot); + printf("\t%10d afs_WriteVolCache\n", cmp->callInfo.C_afs_WriteVolCache); + printf("\t%10d haveCallbacksfrom\n", cmp->callInfo.C_HaveCallBacksFrom); + printf("\t%10d afs_getpage\n", cmp->callInfo.C_afs_getpage); + printf("\t%10d afs_putpage\n", cmp->callInfo.C_afs_putpage); + printf("\t%10d afs_nfsrdwr\n", cmp->callInfo.C_afs_nfsrdwr); + printf("\t%10d afs_map\n", cmp->callInfo.C_afs_map); + printf("\t%10d afs_cmp\n", cmp->callInfo.C_afs_cmp); + printf("\t%10d afs_PageLeft\n", cmp->callInfo.C_afs_PageLeft); + printf("\t%10d afs_mount\n", cmp->callInfo.C_afs_mount); + printf("\t%10d afs_unmount\n", cmp->callInfo.C_afs_unmount); + printf("\t%10d afs_root\n", cmp->callInfo.C_afs_root); + printf("\t%10d afs_statfs\n", cmp->callInfo.C_afs_statfs); + printf("\t%10d afs_sync\n", cmp->callInfo.C_afs_sync); + printf("\t%10d afs_vget\n", cmp->callInfo.C_afs_vget); + printf("\t%10d afs_index\n", cmp->callInfo.C_afs_index); + printf("\t%10d afs_setpag\n", cmp->callInfo.C_afs_setpag); + printf("\t%10d genpag\n", cmp->callInfo.C_genpag); + printf("\t%10d getpag\n", cmp->callInfo.C_getpag); + printf("\t%10d genpag\n", cmp->callInfo.C_genpag); + printf("\t%10d afs_GetMariner\n", cmp->callInfo.C_afs_GetMariner); + printf("\t%10d afs_AddMarinerName\n", cmp->callInfo.C_afs_AddMarinerName); + printf("\t%10d afs_open\n", cmp->callInfo.C_afs_open); + printf("\t%10d afs_close\n", cmp->callInfo.C_afs_close); + printf("\t%10d afs_closex\n", cmp->callInfo.C_afs_closex); + printf("\t%10d afs_write\n", cmp->callInfo.C_afs_write); + printf("\t%10d afs_UFSwrite\n", cmp->callInfo.C_afs_UFSWrite); + printf("\t%10d afs_Memwrite\n", cmp->callInfo.C_afs_MemWrite); + printf("\t%10d afs_rdwr\n", cmp->callInfo.C_afs_rdwr); + printf("\t%10d afs_read\n", cmp->callInfo.C_afs_read); + printf("\t%10d afs_UFSread\n", cmp->callInfo.C_afs_UFSRead); + printf("\t%10d afs_Memread\n", cmp->callInfo.C_afs_MemRead); + printf("\t%10d afs_CopyOutAttrs\n", cmp->callInfo.C_afs_CopyOutAttrs); + printf("\t%10d afs_access\n", cmp->callInfo.C_afs_access); + printf("\t%10d afs_getattr\n", cmp->callInfo.C_afs_getattr); + printf("\t%10d afs_setattr\n", cmp->callInfo.C_afs_setattr); + printf("\t%10d afs_VAttrToAS\n", cmp->callInfo.C_afs_VAttrToAS); + printf("\t%10d EvalMountPoint\n", cmp->callInfo.C_EvalMountPoint); + printf("\t%10d afs_lookup\n", cmp->callInfo.C_afs_lookup); + printf("\t%10d afs_create\n", cmp->callInfo.C_afs_create); + printf("\t%10d afs_LocalHero\n", cmp->callInfo.C_afs_LocalHero); + printf("\t%10d afs_remove\n", cmp->callInfo.C_afs_remove); + printf("\t%10d afs_link\n", cmp->callInfo.C_afs_link); + printf("\t%10d afs_rename\n", cmp->callInfo.C_afs_rename); + printf("\t%10d afs_InitReq\n", cmp->callInfo.C_afs_InitReq); + printf("\t%10d afs_mkdir\n", cmp->callInfo.C_afs_mkdir); + printf("\t%10d afs_rmdir\n", cmp->callInfo.C_afs_rmdir); + printf("\t%10d afs_readdir\n", cmp->callInfo.C_afs_readdir); + printf("\t%10d afs_read1dir\n", cmp->callInfo.C_afs_read1dir); + printf("\t%10d afs_readdir_move\n", cmp->callInfo.C_afs_readdir_move); + printf("\t%10d afs_readdir_iter\n", cmp->callInfo.C_afs_readdir_iter); + printf("\t%10d afs_symlink\n", cmp->callInfo.C_afs_symlink); + printf("\t%10d afs_HandleLink\n", cmp->callInfo.C_afs_HandleLink); + printf("\t%10d afs_MemHandleLink\n", cmp->callInfo.C_afs_MemHandleLink); + printf("\t%10d afs_UFSHandleLink\n", cmp->callInfo.C_afs_UFSHandleLink); + printf("\t%10d HandleFlock\n", cmp->callInfo.C_HandleFlock); + printf("\t%10d afs_readlink\n", cmp->callInfo.C_afs_readlink); + printf("\t%10d afs_fsync\n", cmp->callInfo.C_afs_fsync); + printf("\t%10d afs_inactive\n", cmp->callInfo.C_afs_inactive); + printf("\t%10d afs_ustrategy\n", cmp->callInfo.C_afs_ustrategy); + printf("\t%10d afs_strategy\n", cmp->callInfo.C_afs_strategy); + printf("\t%10d afs_bread\n", cmp->callInfo.C_afs_bread); + printf("\t%10d afs_brelse\n", cmp->callInfo.C_afs_brelse); + printf("\t%10d afs_bmap\n", cmp->callInfo.C_afs_bmap); + printf("\t%10d afs_fid\n", cmp->callInfo.C_afs_fid); + printf("\t%10d afs_FakeOpen\n", cmp->callInfo.C_afs_FakeOpen); + printf("\t%10d afs_FakeClose\n", cmp->callInfo.C_afs_FakeClose); + printf("\t%10d afs_StoreOnLastReference\n", + cmp->callInfo.C_afs_StoreOnLastReference); + printf("\t%10d afs_AccessOK\n", cmp->callInfo.C_afs_AccessOK); + printf("\t%10d afs_GetAccessBits\n", cmp->callInfo.C_afs_GetAccessBits); + printf("\t%10d afsio_copy\n", cmp->callInfo.C_afsio_copy); + printf("\t%10d afsio_trim\n", cmp->callInfo.C_afsio_trim); + printf("\t%10d afsio_skip\n", cmp->callInfo.C_afsio_skip); + printf("\t%10d afs_page_read\n", cmp->callInfo.C_afs_page_read); + printf("\t%10d afs_page_write\n", cmp->callInfo.C_afs_page_write); + printf("\t%10d afs_page_read\n", cmp->callInfo.C_afs_page_read); + printf("\t%10d afs_get_groups_from_pag\n", + cmp->callInfo.C_afs_get_groups_from_pag); + printf("\t%10d afs_get_pag_from_groups\n", + cmp->callInfo.C_afs_get_pag_from_groups); + printf("\t%10d AddPag\n", cmp->callInfo.C_AddPag); + printf("\t%10d PagInCred\n", cmp->callInfo.C_PagInCred); + printf("\t%10d afs_getgroups\n", cmp->callInfo.C_afs_getgroups); + printf("\t%10d afs_page_in\n", cmp->callInfo.C_afs_page_in); + printf("\t%10d afs_page_out\n", cmp->callInfo.C_afs_page_out); + printf("\t%10d afs_AdvanceFD\n", cmp->callInfo.C_afs_AdvanceFD); + printf("\t%10d afs_lockf\n", cmp->callInfo.C_afs_lockf); + printf("\t%10d afs_xsetgroups\n", cmp->callInfo.C_afs_xsetgroups); + printf("\t%10d afs_nlinks\n", cmp->callInfo.C_afs_nlinks); + printf("\t%10d afs_lockctl\n", cmp->callInfo.C_afs_lockctl); + printf("\t%10d afs_xflock\n", cmp->callInfo.C_afs_xflock); + printf("\t%10d PGetCPrefs\n", cmp->callInfo.C_PGetCPrefs); + printf("\t%10d PSetCPrefs\n", cmp->callInfo.C_PSetCPrefs); #ifdef AFS_HPUX_ENV - printf("\t%10d afs_pagein\n", cmp->callInfo.C_afs_pagein); - printf("\t%10d afs_pageout\n", cmp->callInfo.C_afs_pageout); - printf("\t%10d afs_hp_strategy\n", cmp->callInfo.C_afs_hp_strategy); + printf("\t%10d afs_pagein\n", cmp->callInfo.C_afs_pagein); + printf("\t%10d afs_pageout\n", cmp->callInfo.C_afs_pageout); + printf("\t%10d afs_hp_strategy\n", cmp->callInfo.C_afs_hp_strategy); #endif } @@ -4141,84 +4519,155 @@ void print_cmstats(cmp) print_struct_vcache_offsets() { - printf("struct vcache.v offset = %ld, size = %ld\n", values(struct vcache, v)); - printf("struct vcache.vlruq offset = %ld, size = %ld\n", values(struct vcache, vlruq)); - printf("struct vcache.nextfree offset = %ld, size = %ld\n", values(struct vcache, nextfree)); - printf("struct vcache.hnext offset = %ld, size = %ld\n", values(struct vcache, hnext)); - printf("struct vcache.fid offset = %ld, size = %ld\n", values(struct vcache, fid)); - printf("struct vcache.m offset = %ld, size = %ld\n", values(struct vcache, m)); - printf("struct vcache.lock offset = %ld, size = %ld\n", values(struct vcache, lock)); - printf("struct vcache.parentVnode offset = %ld, size = %ld\n", values(struct vcache, parentVnode)); - printf("struct vcache.parentUnique offset = %ld, size = %ld\n", values(struct vcache, parentUnique)); - printf("struct vcache.mvid offset = %ld, size = %ld\n", values(struct vcache, mvid)); - printf("struct vcache.linkData offset = %ld, size = %ld\n", values(struct vcache, linkData)); - printf("struct vcache.flushDV offset = %ld, size = %ld\n", values(struct vcache, flushDV)); - printf("struct vcache.mapDV offset = %ld, size = %ld\n", values(struct vcache, mapDV)); - printf("struct vcache.truncPos offset = %ld, size = %ld\n", values(struct vcache, truncPos)); - printf("struct vcache.callback offset = %ld, size = %ld\n", values(struct vcache, callback)); - printf("struct vcache.cbExpires offset = %ld, size = %ld\n", values(struct vcache, cbExpires)); - printf("struct vcache.callsort offset = %ld, size = %ld\n", values(struct vcache, callsort)); - printf("struct vcache.Access offset = %ld, size = %ld\n", values(struct vcache, Access)); - printf("struct vcache.anyAccess offset = %ld, size = %ld\n", values(struct vcache, anyAccess)); - printf("struct vcache.last_looker offset = %ld, size = %ld\n", values(struct vcache, last_looker)); - printf("struct vcache.activeV offset = %ld, size = %ld\n", values(struct vcache, activeV)); - printf("struct vcache.slocks offset = %ld, size = %ld\n", values(struct vcache, slocks)); - printf("struct vcache.opens offset = %ld, size = %ld\n", values(struct vcache, opens)); - printf("struct vcache.execsOrWriters offset = %ld, size = %ld\n", values(struct vcache, execsOrWriters)); - printf("struct vcache.flockCount offset = %ld, size = %ld\n", values(struct vcache, flockCount)); - printf("struct vcache.mvstat offset = %ld, size = %ld\n", values(struct vcache, mvstat)); - printf("struct vcache.states offset = %ld, size = %ld\n", values(struct vcache, states)); - printf("struct vcache.quick offset = %ld, size = %ld\n", values(struct vcache, quick)); - printf("struct vcache.symhintstamp offset = %ld, size = %ld\n", values(struct vcache, symhintstamp)); - printf("struct vcache.h1 offset = %ld, size = %ld\n", values(struct vcache, h1)); - printf("struct vcache.lastr offset = %ld, size = %ld\n", values(struct vcache, lastr)); - printf("struct vcache.vc_rwlockid offset = %ld, size = %ld\n", values(struct vcache, vc_rwlockid)); - printf("struct vcache.vc_locktrips offset = %ld, size = %ld\n", values(struct vcache, vc_locktrips)); - printf("struct vcache.vc_rwlock offset = %ld, size = %ld\n", values(struct vcache, vc_rwlock)); - printf("struct vcache.mapcnt offset = %ld, size = %ld\n", values(struct vcache, mapcnt)); - printf("struct vcache.cred offset = %ld, size = %ld\n", values(struct vcache, cred)); - printf("struct vcache.vc_bhv_desc offset = %ld, size = %ld\n", values(struct vcache, vc_bhv_desc)); - printf("struct vcache.vc_error offset = %ld, size = %ld\n", values(struct vcache, vc_error)); - printf("struct vcache.xlatordv offset = %ld, size = %ld\n", values(struct vcache, xlatordv)); - printf("struct vcache.uncred offset = %ld, size = %ld\n", values(struct vcache, uncred)); - printf("struct vcache.asynchrony offset = %ld, size = %ld\n", values(struct vcache, asynchrony)); + printf("struct vcache.v offset = %ld, size = %ld\n", + values(struct vcache, v)); + printf("struct vcache.vlruq offset = %ld, size = %ld\n", + values(struct vcache, vlruq)); + printf("struct vcache.nextfree offset = %ld, size = %ld\n", + values(struct vcache, nextfree)); + printf("struct vcache.hnext offset = %ld, size = %ld\n", + values(struct vcache, hnext)); + printf("struct vcache.fid offset = %ld, size = %ld\n", + values(struct vcache, fid)); + printf("struct vcache.m offset = %ld, size = %ld\n", + values(struct vcache, m)); + printf("struct vcache.lock offset = %ld, size = %ld\n", + values(struct vcache, lock)); + printf("struct vcache.parentVnode offset = %ld, size = %ld\n", + values(struct vcache, parentVnode)); + printf("struct vcache.parentUnique offset = %ld, size = %ld\n", + values(struct vcache, parentUnique)); + printf("struct vcache.mvid offset = %ld, size = %ld\n", + values(struct vcache, mvid)); + printf("struct vcache.linkData offset = %ld, size = %ld\n", + values(struct vcache, linkData)); + printf("struct vcache.flushDV offset = %ld, size = %ld\n", + values(struct vcache, flushDV)); + printf("struct vcache.mapDV offset = %ld, size = %ld\n", + values(struct vcache, mapDV)); + printf("struct vcache.truncPos offset = %ld, size = %ld\n", + values(struct vcache, truncPos)); + printf("struct vcache.callback offset = %ld, size = %ld\n", + values(struct vcache, callback)); + printf("struct vcache.cbExpires offset = %ld, size = %ld\n", + values(struct vcache, cbExpires)); + printf("struct vcache.callsort offset = %ld, size = %ld\n", + values(struct vcache, callsort)); + printf("struct vcache.Access offset = %ld, size = %ld\n", + values(struct vcache, Access)); + printf("struct vcache.anyAccess offset = %ld, size = %ld\n", + values(struct vcache, anyAccess)); + printf("struct vcache.last_looker offset = %ld, size = %ld\n", + values(struct vcache, last_looker)); + printf("struct vcache.activeV offset = %ld, size = %ld\n", + values(struct vcache, activeV)); + printf("struct vcache.slocks offset = %ld, size = %ld\n", + values(struct vcache, slocks)); + printf("struct vcache.opens offset = %ld, size = %ld\n", + values(struct vcache, opens)); + printf("struct vcache.execsOrWriters offset = %ld, size = %ld\n", + values(struct vcache, execsOrWriters)); + printf("struct vcache.flockCount offset = %ld, size = %ld\n", + values(struct vcache, flockCount)); + printf("struct vcache.mvstat offset = %ld, size = %ld\n", + values(struct vcache, mvstat)); + printf("struct vcache.states offset = %ld, size = %ld\n", + values(struct vcache, states)); + printf("struct vcache.quick offset = %ld, size = %ld\n", + values(struct vcache, quick)); + printf("struct vcache.symhintstamp offset = %ld, size = %ld\n", + values(struct vcache, symhintstamp)); + printf("struct vcache.h1 offset = %ld, size = %ld\n", + values(struct vcache, h1)); + printf("struct vcache.lastr offset = %ld, size = %ld\n", + values(struct vcache, lastr)); + printf("struct vcache.vc_rwlockid offset = %ld, size = %ld\n", + values(struct vcache, vc_rwlockid)); + printf("struct vcache.vc_locktrips offset = %ld, size = %ld\n", + values(struct vcache, vc_locktrips)); + printf("struct vcache.vc_rwlock offset = %ld, size = %ld\n", + values(struct vcache, vc_rwlock)); + printf("struct vcache.mapcnt offset = %ld, size = %ld\n", + values(struct vcache, mapcnt)); + printf("struct vcache.cred offset = %ld, size = %ld\n", + values(struct vcache, cred)); + printf("struct vcache.vc_bhv_desc offset = %ld, size = %ld\n", + values(struct vcache, vc_bhv_desc)); + printf("struct vcache.vc_error offset = %ld, size = %ld\n", + values(struct vcache, vc_error)); + printf("struct vcache.xlatordv offset = %ld, size = %ld\n", + values(struct vcache, xlatordv)); + printf("struct vcache.uncred offset = %ld, size = %ld\n", + values(struct vcache, uncred)); + printf("struct vcache.asynchrony offset = %ld, size = %ld\n", + values(struct vcache, asynchrony)); } print_struct_vnode_offsets() { - printf("struct vnode.v_list offset = %ld, size = %ld\n", values(struct vnode, v_list)); - printf("struct vnode.v_flag offset = %ld, size = %ld\n", values(struct vnode, v_flag)); - printf("struct vnode.v_count offset = %ld, size = %ld\n", values(struct vnode, v_count)); - printf("struct vnode.v_listid offset = %ld, size = %ld\n", values(struct vnode, v_listid)); - printf("struct vnode.v_intpcount offset = %ld, size = %ld\n", values(struct vnode, v_intpcount)); - printf("struct vnode.v_type offset = %ld, size = %ld\n", values(struct vnode, v_type)); - printf("struct vnode.v_rdev offset = %ld, size = %ld\n", values(struct vnode, v_rdev)); - printf("struct vnode.v_vfsmountedhere offset = %ld, size = %ld\n", values(struct vnode, v_vfsmountedhere)); - printf("struct vnode.v_vfsp offset = %ld, size = %ld\n", values(struct vnode, v_vfsp)); - printf("struct vnode.v_stream offset = %ld, size = %ld\n", values(struct vnode, v_stream)); - printf("struct vnode.v_filocks offset = %ld, size = %ld\n", values(struct vnode, v_filocks)); - printf("struct vnode.v_filocksem offset = %ld, size = %ld\n", values(struct vnode, v_filocksem)); - printf("struct vnode.v_number offset = %ld, size = %ld\n", values(struct vnode, v_number)); - printf("struct vnode.v_bh offset = %ld, size = %ld\n", values(struct vnode, v_bh)); - printf("struct vnode.v_namecap offset = %ld, size = %ld\n", values(struct vnode, v_namecap)); - printf("struct vnode.v_hashp offset = %ld, size = %ld\n", values(struct vnode, v_hashp)); - printf("struct vnode.v_hashn offset = %ld, size = %ld\n", values(struct vnode, v_hashn)); - printf("struct vnode.v_mreg offset = %ld, size = %ld\n", values(struct vnode, v_mreg)); - printf("struct vnode.v_mregb offset = %ld, size = %ld\n", values(struct vnode, v_mregb)); - printf("struct vnode.v_pgcnt offset = %ld, size = %ld\n", values(struct vnode, v_pgcnt)); - printf("struct vnode.v_dpages offset = %ld, size = %ld\n", values(struct vnode, v_dpages)); - printf("struct vnode.v_dpages_gen offset = %ld, size = %ld\n", values(struct vnode, v_dpages_gen)); - printf("struct vnode.v_dbuf offset = %ld, size = %ld\n", values(struct vnode, v_dbuf)); - printf("struct vnode.v_buf offset = %ld, size = %ld\n", values(struct vnode, v_buf)); - printf("struct vnode.v_bufgen offset = %ld, size = %ld\n", values(struct vnode, v_bufgen)); - printf("struct vnode.v_traceix offset = %ld, size = %ld\n", values(struct vnode, v_traceix)); - printf("struct vnode.v_buf_lock offset = %ld, size = %ld\n", values(struct vnode, v_buf_lock)); - printf("struct vnode.v_pc offset = %ld, size = %ld\n", values(struct vnode, v_pc)); + printf("struct vnode.v_list offset = %ld, size = %ld\n", + values(struct vnode, v_list)); + printf("struct vnode.v_flag offset = %ld, size = %ld\n", + values(struct vnode, v_flag)); + printf("struct vnode.v_count offset = %ld, size = %ld\n", + values(struct vnode, v_count)); + printf("struct vnode.v_listid offset = %ld, size = %ld\n", + values(struct vnode, v_listid)); + printf("struct vnode.v_intpcount offset = %ld, size = %ld\n", + values(struct vnode, v_intpcount)); + printf("struct vnode.v_type offset = %ld, size = %ld\n", + values(struct vnode, v_type)); + printf("struct vnode.v_rdev offset = %ld, size = %ld\n", + values(struct vnode, v_rdev)); + printf("struct vnode.v_vfsmountedhere offset = %ld, size = %ld\n", + values(struct vnode, v_vfsmountedhere)); + printf("struct vnode.v_vfsp offset = %ld, size = %ld\n", + values(struct vnode, v_vfsp)); + printf("struct vnode.v_stream offset = %ld, size = %ld\n", + values(struct vnode, v_stream)); + printf("struct vnode.v_filocks offset = %ld, size = %ld\n", + values(struct vnode, v_filocks)); + printf("struct vnode.v_filocksem offset = %ld, size = %ld\n", + values(struct vnode, v_filocksem)); + printf("struct vnode.v_number offset = %ld, size = %ld\n", + values(struct vnode, v_number)); + printf("struct vnode.v_bh offset = %ld, size = %ld\n", + values(struct vnode, v_bh)); + printf("struct vnode.v_namecap offset = %ld, size = %ld\n", + values(struct vnode, v_namecap)); + printf("struct vnode.v_hashp offset = %ld, size = %ld\n", + values(struct vnode, v_hashp)); + printf("struct vnode.v_hashn offset = %ld, size = %ld\n", + values(struct vnode, v_hashn)); + printf("struct vnode.v_mreg offset = %ld, size = %ld\n", + values(struct vnode, v_mreg)); + printf("struct vnode.v_mregb offset = %ld, size = %ld\n", + values(struct vnode, v_mregb)); + printf("struct vnode.v_pgcnt offset = %ld, size = %ld\n", + values(struct vnode, v_pgcnt)); + printf("struct vnode.v_dpages offset = %ld, size = %ld\n", + values(struct vnode, v_dpages)); + printf("struct vnode.v_dpages_gen offset = %ld, size = %ld\n", + values(struct vnode, v_dpages_gen)); + printf("struct vnode.v_dbuf offset = %ld, size = %ld\n", + values(struct vnode, v_dbuf)); + printf("struct vnode.v_buf offset = %ld, size = %ld\n", + values(struct vnode, v_buf)); + printf("struct vnode.v_bufgen offset = %ld, size = %ld\n", + values(struct vnode, v_bufgen)); + printf("struct vnode.v_traceix offset = %ld, size = %ld\n", + values(struct vnode, v_traceix)); + printf("struct vnode.v_buf_lock offset = %ld, size = %ld\n", + values(struct vnode, v_buf_lock)); + printf("struct vnode.v_pc offset = %ld, size = %ld\n", + values(struct vnode, v_pc)); #ifdef VNODE_TRACING - printf("struct vnode.v_trace offset = %ld, size = %ld\n", values(struct vnode, v_trace)); + printf("struct vnode.v_trace offset = %ld, size = %ld\n", + values(struct vnode, v_trace)); #endif #ifdef CKPT - printf("struct vnode.v_ckpt offset = %ld, size = %ld\n", values(struct vnode, v_ckpt)); + printf("struct vnode.v_ckpt offset = %ld, size = %ld\n", + values(struct vnode, v_ckpt)); #endif } #endif diff --git a/src/venus/livesys.c b/src/venus/livesys.c index f751716d8..4037fded8 100644 --- a/src/venus/livesys.c +++ b/src/venus/livesys.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/livesys.c,v 1.1 2001/10/14 18:07:08 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/livesys.c,v 1.4 2003/07/15 23:17:22 shadow Exp $"); #include #include @@ -21,20 +22,27 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/livesys.c,v 1.1 2001/10/14 18:07: #include #include #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include #include #include #ifdef AFS_AIX32_ENV #include #endif -#include #define MAXSIZE 2048 static char space[MAXSIZE]; -int main(argc, argv) - int argc; - char **argv; +int +main(argc, argv) + int argc; + char **argv; { afs_int32 code; struct ViceIoctl blob; diff --git a/src/venus/test/Makefile.in b/src/venus/test/Makefile.in index 57ec1a795..d1c2c044c 100644 --- a/src/venus/test/Makefile.in +++ b/src/venus/test/Makefile.in @@ -5,32 +5,11 @@ # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html -DEST=@DEST@ -TOP_INCDIR=@TOP_INCDIR@ -TOP_LIBDIR=@TOP_LIBDIR@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ -libexecdir=@libexecdir@ -libdir=@libdir@ -includedir=@includedir@ -mandir=@mandir@ -afssrvbindir=@afssrvbindir@ -afssrvsbindir=@afssrvsbindir@ -afssrvlibexecdir=@afssrvlibexecdir@ -COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et -RXGEN=${TOP_SRCDIR}/rxgen/rxgen -TOP_SRCDIR=@TOP_SRCDIR@ -SYS_NAME=@AFS_SYSNAME@ - -include ../../config/Makefile.${SYS_NAME} - - - -OPTIMIZE=-O - -INCDIRS= -I${TOP_SRCDIR}/config -I${TOP_INCDIR} -I.. +srcdir=@srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config + + +INCDIRS= -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} -I.. LDIRS= -L${TOP_LIBDIR} -L.. LIBS= -lsys -lubik -lvldb -lauth -lrxkad -ldes -lcom_err -lcmd -lrx -llwp -lafsutil diff --git a/src/venus/test/fulltest.c b/src/venus/test/fulltest.c index 211219012..75fbc6bcc 100644 --- a/src/venus/test/fulltest.c +++ b/src/venus/test/fulltest.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/test/fulltest.c,v 1.1.1.4 2001/07/14 22:24:38 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/test/fulltest.c,v 1.6 2003/07/15 23:17:24 shadow Exp $"); #include #include @@ -19,8 +20,9 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/test/fulltest.c,v 1.1.1.4 2001/07 #include main(argc, argv) -int argc; -char **argv; { + int argc; + char **argv; +{ char *dirName; char tempName[1024]; struct stat tstat; @@ -33,32 +35,46 @@ char **argv; { #endif /* venus system tester */ - if (argc != 2) return printf("usage: fulltest \n"); + if (argc != 2) + return printf("usage: fulltest \n"); dirName = argv[1]; mkdir(dirName, 0777); - if (chdir(dirName) < 0) return perror("chdir"); + if (chdir(dirName) < 0) + return perror("chdir"); if (getcwd(tempName, 1024) == 0) { return printf("Could not get working dir.\n"); } /* now create some files */ fd1 = open("hi", O_CREAT | O_TRUNC | O_RDWR, 0666); - if (fd1 < 0) return perror("open1"); - if (close(fd1) < 0) return perror("close1"); - if (access("hi", 2) < 0) return printf("New file can not be written (access)\n"); - if (chmod ("hi", 0741) < 0) return perror("chmod1"); - if (stat("hi", &tstat) < 0) return perror("stat1"); - if ((tstat.st_mode & 0777) != 0741) return printf("chmod failed to set mode properly\n"); - + if (fd1 < 0) + return perror("open1"); + if (close(fd1) < 0) + return perror("close1"); + if (access("hi", 2) < 0) + return printf("New file can not be written (access)\n"); + if (chmod("hi", 0741) < 0) + return perror("chmod1"); + if (stat("hi", &tstat) < 0) + return perror("stat1"); + if ((tstat.st_mode & 0777) != 0741) + return printf("chmod failed to set mode properly\n"); + fd1 = open("hi", O_RDWR); - if (fd1 < 0) return perror("open2"); - if (fchmod(fd1, 0654) < 0) return perror("fchmod"); - if (fstat(fd1, &tstat) < 0) return perror("fstat1"); - if ((tstat.st_mode & 0777) != 0654) return printf("fchmod failed to set mode properly\n"); + if (fd1 < 0) + return perror("open2"); + if (fchmod(fd1, 0654) < 0) + return perror("fchmod"); + if (fstat(fd1, &tstat) < 0) + return perror("fstat1"); + if ((tstat.st_mode & 0777) != 0654) + return printf("fchmod failed to set mode properly\n"); #if 0 - /* These appear to be defunct routines; - * I don't know what, if anything, replaced them */ - if (osi_ExclusiveLockNoBlock(fd1) < 0) return perror("flock1"); - if (osi_UnLock(fd1) < 0) return perror("flock/unlock"); + /* These appear to be defunct routines; + * I don't know what, if anything, replaced them */ + if (osi_ExclusiveLockNoBlock(fd1) < 0) + return perror("flock1"); + if (osi_UnLock(fd1) < 0) + return perror("flock/unlock"); #endif /* How about shared lock portability? */ @@ -70,90 +86,125 @@ char **argv; { fl.l_start = 0; fl.l_len = 0; - if (fcntl(fd1, F_SETLK, &fl) == -1) return perror("fcntl1: RDLCK"); + if (fcntl(fd1, F_SETLK, &fl) == -1) + return perror("fcntl1: RDLCK"); fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; - if (fcntl(fd1, F_SETLK, &fl) == -1) return perror("fcntl2: UNLCK"); + if (fcntl(fd1, F_SETLK, &fl) == -1) + return perror("fcntl2: UNLCK"); fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; - if (fcntl(fd1, F_SETLK, &fl) == -1) return perror("fcntl3: WRLCK"); + if (fcntl(fd1, F_SETLK, &fl) == -1) + return perror("fcntl3: WRLCK"); fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; - if (fcntl(fd1, F_SETLK, &fl) == -1) return perror("fcntl4: UNLCK"); + if (fcntl(fd1, F_SETLK, &fl) == -1) + return perror("fcntl4: UNLCK"); } - if (fsync(fd1) < 0) return perror("fsync"); - if (write(fd1, "hi\n", 3) != 3) return perror("write"); - if (ftruncate(fd1, 2) < 0) return perror("ftruncate"); - if (close(fd1) < 0) return perror("close2"); - + if (fsync(fd1) < 0) + return perror("fsync"); + if (write(fd1, "hi\n", 3) != 3) + return perror("write"); + if (ftruncate(fd1, 2) < 0) + return perror("ftruncate"); + if (close(fd1) < 0) + return perror("close2"); + fd1 = open("hi", O_RDONLY); - if (fd1 < 0) return perror("open3"); - if (read(fd1, tempName, 100) != 2) return perror("read2"); - if (close (fd1) < 0) return perror("close3"); - - if (link("hi", "bye") < 0) return perror("link"); - if (stat("bye", &tstat) < 0) return perror("link/stat"); - - if (unlink("bye")<0) return perror("unlink"); - - if (symlink("hi", "bye") < 0) return perror("symlink"); - if (readlink("bye", tempName, 100) != 2) return perror("readlink"); - if (strncmp(tempName, "hi", 2) != 0) return printf("readlink contents"); - if (mkdir("tdir", 0777) < 0) return perror("mkdir"); + if (fd1 < 0) + return perror("open3"); + if (read(fd1, tempName, 100) != 2) + return perror("read2"); + if (close(fd1) < 0) + return perror("close3"); + + if (link("hi", "bye") < 0) + return perror("link"); + if (stat("bye", &tstat) < 0) + return perror("link/stat"); + + if (unlink("bye") < 0) + return perror("unlink"); + + if (symlink("hi", "bye") < 0) + return perror("symlink"); + if (readlink("bye", tempName, 100) != 2) + return perror("readlink"); + if (strncmp(tempName, "hi", 2) != 0) + return printf("readlink contents"); + if (mkdir("tdir", 0777) < 0) + return perror("mkdir"); fd1 = open("tdir/fdsa", O_CREAT | O_TRUNC, 0777); close(fd1); - if (rmdir("tdir") == 0) return printf("removed non-empty dir\n"); - if (unlink("tdir/fdsa") < 0) return perror("unlink tdir contents"); - if (rmdir("tdir") < 0) return perror("rmdir"); - - fd1 = open (".", O_RDONLY); - if (fd1<0) return perror("open dot"); - if (read(fd1, tempName, 20) < 20) perror("read dir"); + if (rmdir("tdir") == 0) + return printf("removed non-empty dir\n"); + if (unlink("tdir/fdsa") < 0) + return perror("unlink tdir contents"); + if (rmdir("tdir") < 0) + return perror("rmdir"); + + fd1 = open(".", O_RDONLY); + if (fd1 < 0) + return perror("open dot"); + if (read(fd1, tempName, 20) < 20) + perror("read dir"); close(fd1); fd1 = open("rotest", O_RDWR | O_CREAT, 0444); - if (fd1<0) return perror("open ronly"); - fchown(fd1, 1, -1); /* don't check error code, may fail on Ultrix */ + if (fd1 < 0) + return perror("open ronly"); + fchown(fd1, 1, -1); /* don't check error code, may fail on Ultrix */ code = write(fd1, "test", 4); if (code != 4) { printf("rotest short read (%d)\n", code); exit(1); } code = close(fd1); - if (code) return perror("close ronly"); + if (code) + return perror("close ronly"); code = stat("rotest", &tstat); - if (code < 0) return perror("stat ronly"); + if (code < 0) + return perror("stat ronly"); if (tstat.st_size != 4) { printf("rotest short close\n"); exit(1); } - if (unlink("rotest")<0) return perror("rotest unlink"); - - if (rename("hi", "bye") < 0) return perror("rename1"); - if (stat("bye", &tstat) < 0) return perror("rename target invisible\n"); - if (stat("hi", &tstat) == 0) return printf("rename source still there\n"); - + if (unlink("rotest") < 0) + return perror("rotest unlink"); + + if (rename("hi", "bye") < 0) + return perror("rename1"); + if (stat("bye", &tstat) < 0) + return perror("rename target invisible\n"); + if (stat("hi", &tstat) == 0) + return printf("rename source still there\n"); + #ifndef AFS_AIX_ENV /* No truncate(2) on aix so the following are excluded */ - if (truncate("bye", 1) < 0) return perror("truncate"); - if (stat("bye", &tstat) < 0) return perror("truncate zapped"); - if (tstat.st_size != 1) return printf("truncate failed\n"); + if (truncate("bye", 1) < 0) + return perror("truncate"); + if (stat("bye", &tstat) < 0) + return perror("truncate zapped"); + if (tstat.st_size != 1) + return printf("truncate failed\n"); #endif - if (utimes("bye", tvp) < 0) return perror("utimes"); - if (unlink("bye") < 0) return perror("unlink bye"); + if (utimes("bye", tvp) < 0) + return perror("utimes"); + if (unlink("bye") < 0) + return perror("unlink bye"); /* now finish up */ chdir(".."); diff --git a/src/venus/test/getinitparams.c b/src/venus/test/getinitparams.c index a85b76506..8b1d0ef74 100644 --- a/src/venus/test/getinitparams.c +++ b/src/venus/test/getinitparams.c @@ -10,7 +10,8 @@ /* Get CM initialization parameters. */ #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/test/getinitparams.c,v 1.1.1.3 2001/07/11 03:12:01 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/test/getinitparams.c,v 1.5 2003/07/15 23:17:24 shadow Exp $"); #include #include @@ -32,7 +33,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/test/getinitparams.c,v 1.1.1.3 20 -int GetInitParamsCmd(struct cmd_syndesc *as) +int +GetInitParamsCmd(struct cmd_syndesc *as) { struct cm_initparams cm_initParams; struct ViceIoctl blob; @@ -42,13 +44,13 @@ int GetInitParamsCmd(struct cmd_syndesc *as) int fd; if (as->parms[0].items) { - file = as->parms[0].items->data; + file = as->parms[0].items->data; } if (file) { printf("ioctl test\n"); fd = open(file, O_RDONLY, 0); - if (fd<0) { + if (fd < 0) { perror("open"); exit(1); } @@ -56,14 +58,14 @@ int GetInitParamsCmd(struct cmd_syndesc *as) printf("lpioctl test\n"); } - blob.in = (char*)0; + blob.in = (char *)0; blob.in_size = 0; blob.out = (char *)&cm_initParams; blob.out_size = sizeof(struct cm_initparams); if (file) { code = ioctl(fd, VIOC_GETINITPARAMS, &blob); - if (code<0) { + if (code < 0) { perror("ioctl: Error getting CM initialization parameters"); exit(1); } @@ -92,12 +94,12 @@ int GetInitParamsCmd(struct cmd_syndesc *as) main(ac, av) -int ac; -char **av; + int ac; + char **av; { int code; struct cmd_syndesc *ts; - + #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a @@ -106,18 +108,17 @@ char **av; * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGSEGV, &nsa, NULL); #endif - ts = cmd_CreateSyntax((char *)0, GetInitParamsCmd, (char *)0, + ts = cmd_CreateSyntax(NULL, GetInitParamsCmd, NULL, "Get CM initialization parameters"); - + cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "filename in AFS"); code = cmd_Dispatch(ac, av); exit(code); } - diff --git a/src/venus/test/idtest.c b/src/venus/test/idtest.c index 4ae51daa2..5e2ce5351 100644 --- a/src/venus/test/idtest.c +++ b/src/venus/test/idtest.c @@ -10,9 +10,11 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/test/idtest.c,v 1.1.1.4 2001/07/14 22:24:38 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/test/idtest.c,v 1.5 2003/07/15 23:17:24 shadow Exp $"); -main(argc, argv) { +main(argc, argv) +{ int uid; uid = geteuid(); @@ -21,4 +23,3 @@ main(argc, argv) { printf("and my real UID is %d.\n", uid); exit(0); } - diff --git a/src/venus/test/owntest.c b/src/venus/test/owntest.c index 97e653a46..e44068d0d 100644 --- a/src/venus/test/owntest.c +++ b/src/venus/test/owntest.c @@ -9,8 +9,12 @@ #include #include +#ifdef HAVE_STDLIB_H +#include +#endif -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/test/owntest.c,v 1.1.1.6 2003/07/30 17:13:33 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/test/owntest.c,v 1.8 2003/07/15 23:17:24 shadow Exp $"); #include #include @@ -21,45 +25,47 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/test/owntest.c,v 1.1.1.6 2003/07/ extern int errno; main(argc, argv) -int argc; -char **argv; { + int argc; + char **argv; +{ struct timeval tv[2]; struct stat tstat; register long code; - register char *pn; /* path name we're dealing with */ + register char *pn; /* path name we're dealing with */ if (argc != 2) { - printf("usage: owntest \n"); + printf + ("usage: owntest \n"); exit(1); } pn = argv[1]; printf("Starting tests on %s.\n", pn); code = chmod(pn, 0444); - if (code<0) { - perror("chmod to RO"); - return 1; + if (code < 0) { + perror("chmod to RO"); + exit(errno); } code = chmod(pn, 0666); - if (code<0) { - perror("chmod back to RW"); - return 1; + if (code < 0) { + perror("chmod back to RW"); + exit(errno); } - gettimeofday(&tv[0], (void *) 0); - gettimeofday(&tv[1], (void *) 0); + gettimeofday(&tv[0], NULL); + gettimeofday(&tv[1], NULL); tv[0].tv_sec -= 10000; tv[0].tv_usec = 0; tv[1].tv_sec -= 20000; tv[1].tv_usec = 0; code = utimes(pn, tv); - if (code<0) { - perror("utimes"); - return 1; + if (code < 0) { + perror("utimes"); + exit(errno); } code = stat(pn, &tstat); - if (code<0) { - perror("stat"); - return 1; + if (code < 0) { + perror("stat"); + exit(errno); } if (tstat.st_mtime != tv[1].tv_sec) { printf("modtime didn't stick\n"); diff --git a/src/venus/twiddle.c b/src/venus/twiddle.c index 49d721a65..7fe169bb6 100644 --- a/src/venus/twiddle.c +++ b/src/venus/twiddle.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/twiddle.c,v 1.2 2003/01/02 03:55:53 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/twiddle.c,v 1.7 2003/07/15 23:17:22 shadow Exp $"); #include #include @@ -38,8 +39,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/twiddle.c,v 1.2 2003/01/02 03:55: #define MAXSIZE 2048 -#define MAXINSIZE 1300 /* pioctl complains if data is larger than this */ -#define VMSGSIZE 128 /* size of msg buf in volume hdr */ +#define MAXINSIZE 1300 /* pioctl complains if data is larger than this */ +#define VMSGSIZE 128 /* size of msg buf in volume hdr */ static char space[MAXSIZE]; static char tspace[1024]; @@ -50,67 +51,69 @@ extern struct cmd_syndesc *cmd_CreateSyntax(); static char pn[] = "fs"; static int rxInitDone = 0; -static Twiddle(as) -struct cmd_syndesc *as; { +static +Twiddle(as) + struct cmd_syndesc *as; +{ afs_int32 code; struct ViceIoctl blob; struct cmd_item *ti; struct rxparams rxp; int tmp; - - ti=as->parms[0].items; + + ti = as->parms[0].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rx_initReceiveWindow = tmp; - ti=as->parms[1].items; + ti = as->parms[1].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rx_maxReceiveWindow = tmp; - ti=as->parms[2].items; + ti = as->parms[2].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rx_initSendWindow = tmp; - ti=as->parms[3].items; + ti = as->parms[3].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rx_maxSendWindow = tmp; - ti=as->parms[4].items; + ti = as->parms[4].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rxi_nSendFrags = tmp; - ti=as->parms[5].items; + ti = as->parms[5].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rxi_nRecvFrags = tmp; - ti=as->parms[6].items; + ti = as->parms[6].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rxi_OrphanFragSize = tmp; - ti=as->parms[7].items; + ti = as->parms[7].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rx_maxReceiveSize = tmp; - ti=as->parms[8].items; + ti = as->parms[8].items; if (ti && ti->data) { - tmp = atoi (ti->data); - } - else tmp = 0; + tmp = atoi(ti->data); + } else + tmp = 0; rxp.rx_MyMaxSendSize = tmp; blob.in = (char *)&rxp; @@ -128,11 +131,12 @@ struct cmd_syndesc *as; { #include "AFS_component_version_number.c" main(argc, argv) -int argc; -char **argv; { + int argc; + char **argv; +{ register afs_int32 code; register struct cmd_syndesc *ts; - + #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a @@ -141,16 +145,16 @@ char **argv; { * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGSEGV, &nsa, NULL); #endif /* try to find volume location information */ - - ts = cmd_CreateSyntax((char *)0, Twiddle, 0, "adjust rx parms"); + + ts = cmd_CreateSyntax(NULL, Twiddle, 0, "adjust rx parms"); cmd_AddParm(ts, "-initReceiveWindow ", CMD_SINGLE, CMD_OPTIONAL, "16"); cmd_AddParm(ts, "-maxReceiveWindow ", CMD_SINGLE, CMD_OPTIONAL, "16"); cmd_AddParm(ts, "-initSendWindow ", CMD_SINGLE, CMD_OPTIONAL, "8"); @@ -162,41 +166,46 @@ char **argv; { cmd_AddParm(ts, "-MyMaxSendSize ", CMD_SINGLE, CMD_OPTIONAL, ""); code = cmd_Dispatch(argc, argv); - if (rxInitDone) rx_Finalize(); - + if (rxInitDone) + rx_Finalize(); + exit(code); } Die(code, filename) - int code; - char *filename; -{ /*Die*/ + int code; + char *filename; +{ /*Die */ if (errno == EINVAL) { if (filename) - fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename); - else fprintf(stderr,"%s: Invalid argument.\n", pn); - } - else if (errno == ENOENT) { - if (filename) fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename); - else fprintf(stderr,"%s: no such file returned\n", pn); - } - else if (errno == EROFS) fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn); + fprintf(stderr, + "%s: Invalid argument; it is possible that %s is not in AFS.\n", + pn, filename); + else + fprintf(stderr, "%s: Invalid argument.\n", pn); + } else if (errno == ENOENT) { + if (filename) + fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename); + else + fprintf(stderr, "%s: no such file returned\n", pn); + } else if (errno == EROFS) + fprintf(stderr, + "%s: You can not change a backup or readonly volume\n", pn); else if (errno == EACCES || errno == EPERM) { - if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename); - else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn); - } - else { - if (filename) fprintf(stderr,"%s:'%s'", pn, filename); - else fprintf(stderr,"%s", pn); - fprintf(stderr,": %s\n", error_message(errno)); + if (filename) + fprintf(stderr, + "%s: You don't have the required access rights on '%s'\n", + pn, filename); + else + fprintf(stderr, + "%s: You do not have the required rights to do this operation\n", + pn); + } else { + if (filename) + fprintf(stderr, "%s:'%s'", pn, filename); + else + fprintf(stderr, "%s", pn); + fprintf(stderr, ": %s\n", error_message(errno)); } -} /*Die*/ - - - - - - - - +} /*Die */ diff --git a/src/venus/up.c b/src/venus/up.c index 2fda14b7a..9a062dd04 100644 --- a/src/venus/up.c +++ b/src/venus/up.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/up.c,v 1.1.1.8 2003/07/30 17:13:32 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/up.c,v 1.13 2003/07/15 23:17:22 shadow Exp $"); /* missing type from C language */ #define Boolean short @@ -18,13 +19,6 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/up.c,v 1.1.1.8 2003/07/30 17:13:3 #define false 0 #include -#ifdef HAVE_STRING_H -#include -#else -#ifdef HAVE_STRINGS_H -#include -#endif -#endif #ifdef AFS_AIX32_ENV #include #undef _NONSTD_TYPES @@ -46,29 +40,38 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/venus/up.c,v 1.1.1.8 2003/07/30 17:13:3 #undef VIRTUE #undef VICE #include -#include +#include #ifdef HAVE_NETINET_IN_H #include #endif + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include /* ************************************************************* */ #define MAXACL 400 -#if !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) +#if !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) extern sys_nerr; extern char *sys_errlist[]; #endif -Boolean verbose = false; -Boolean renameTargets = false; -Boolean oneLevel = false; -Boolean preserveDate = true; -Boolean preserveMountPoints = false; -Boolean forceOverwrite = false; +Boolean verbose = false; +Boolean renameTargets = false; +Boolean oneLevel = false; +Boolean preserveDate = true; +Boolean preserveMountPoints = false; +Boolean forceOverwrite = false; -int pageSize; +int pageSize; Boolean setacl = true; Boolean oldAcl = false; char file1[MAXPATHLEN], file2[MAXPATHLEN]; @@ -92,8 +95,8 @@ struct OldAcl { #include "AFS_component_version_number.c" main(argc, argv) - int argc; - char *argv[]; + int argc; + char *argv[]; { #ifdef AFS_AIX32_ENV @@ -104,7 +107,7 @@ main(argc, argv) * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; @@ -114,53 +117,53 @@ main(argc, argv) pageSize = getpagesize(); #endif ScanArgs(argc, argv); - + /* now read each line of the CopyList */ if (Copy(file1, file2, !oneLevel, 0)) - exit(1); /* some type of failure */ + exit(1); /* some type of failure */ exit(0); } ScanArgs(argc, argv) - int argc; - char *argv[]; + int argc; + char *argv[]; { /* skip program name */ argc--, argv++; - + /* check for -flag options */ while (argc > 0 && *argv[0] == '-') { - char *cp = *argv; + char *cp = *argv; - switch (*++cp) { - case 'v': + switch (*++cp) { + case 'v': verbose = true; break; - - case '1': + + case '1': oneLevel = true; break; - - case 'r': + + case 'r': renameTargets = true; break; - - case 'f': + + case 'f': forceOverwrite = true; break; - - case 'x': + + case 'x': preserveDate = false; break; - - case 'm': + + case 'm': preserveMountPoints = true; break; - - default: + + default: fprintf(stderr, "Unknown option: '%c'\n", *cp); fprintf(stderr, "usage: up [-v1frxm] from to\n"); exit(1); @@ -169,14 +172,14 @@ ScanArgs(argc, argv) } if (argc != 2) { - fprintf(stderr, "usage: up [-v1frx] from to\n"); - exit(1); + fprintf(stderr, "usage: up [-v1frx] from to\n"); + exit(1); } strncpy(file1, argv[0], MAXPATHLEN); strncpy(file2, argv[1], MAXPATHLEN); -} /*ScanArgs*/ +} /*ScanArgs */ @@ -186,30 +189,29 @@ ScanArgs(argc, argv) * true if it exists, false otherwise. Note: the owner argument * is a hack. All directories made will have this owner. */ -Boolean MakeParent(file, owner) - char *file; - afs_int32 owner; +Boolean +MakeParent(file, owner) + char *file; + afs_int32 owner; { - char parent[MAXPATHLEN]; + char parent[MAXPATHLEN]; char *p; struct stat s; - + strcpy(parent, file); - + p = strrchr(parent, '/'); if (!p) { strcpy(parent, "."); - } - else if (p > parent) { - *p = '\0'; - } - else { + } else if (p > parent) { + *p = '\0'; + } else { p[1] = '\0'; } - + if (stat(parent, &s) < 0) { if (!MakeParent(parent, owner)) - return(false); + return (false); if (verbose) { printf("Creating directory %s\n", parent); @@ -219,8 +221,8 @@ Boolean MakeParent(file, owner) mkdir(parent, 0777); chown(parent, owner, -1); } - return(true); -} /*MakeParent*/ + return (true); +} /*MakeParent */ /* @@ -229,493 +231,512 @@ Boolean MakeParent(file, owner) * possibly copying subfiles if this is a directory */ Copy(file1, file2, recursive, level) - char *file1; /* input file name */ - char *file2; /* output file name */ - Boolean recursive; /* true if directory should be copied */ - int level; /* level of recursion: 0, 1, ... */ + char *file1; /* input file name */ + char *file2; /* output file name */ + Boolean recursive; /* true if directory should be copied */ + int level; /* level of recursion: 0, 1, ... */ { - struct stat s1, s2; /*Stat blocks*/ + struct stat s1, s2; /*Stat blocks */ struct ViceIoctl blob; char aclspace[MAXACL]; afs_int32 rcode = 0, code; - int goods2 = 1; + int goods2 = 1; code = lstat(file1, &s1); if (code < 0) { - fprintf(stderr,"Can't find %s\n",file1); - return 1; + fprintf(stderr, "Can't find %s\n", file1); + return 1; } code = lstat(file2, &s2); if (code < 0) { - if (!MakeParent(file2,s1.st_uid)) - return 0; - goods2 = 0; + if (!MakeParent(file2, s1.st_uid)) + return 0; + goods2 = 0; } if ((s1.st_mode & S_IFMT) == S_IFREG) { - /* - * -------------------- Copy regular file -------------------- - */ - int f1, f2, n; - char buf[4096]; /* Must be bigger than sizeof (*head) */ - struct timeval tv[2]; - char tmpfile[MAXPATHLEN], newName[MAXPATHLEN]; - - if (verbose) { - printf("Level %d: File %s to %s\n", level, file1, file2); - fflush(stdout); - } - - /* Wonder if there is a security hole */ - if ( ((s1.st_mode & 04002) == 04002) || - ((s1.st_mode & 04020) == 04020) || - ((s1.st_mode & 02002) == 02002) ) { - fprintf(stderr, "WARNING: Mode-bits security hole in files %s and %s\n", - file1, file2); - } - - if (!goods2 || (s1.st_mtime != s2.st_mtime) || (s1.st_size != s2.st_size)) { /*c*/ - /* Don't ovewrite a write protected file (unless force: -f) */ - if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { - fprintf(stderr, - "File %s is write protected against its owner; not changed\n", - file2); - return 1; - } - - if (verbose) { - printf(" Copy file %s to %s (%u Bytes)\n", file1, file2, s1.st_size); - fflush(stdout); - } - - strcpy(tmpfile, file2); /* Name of temporary file */ - strcat(tmpfile,".UPD"); - - /* open file1 for input */ - f1 = open(file1, O_RDONLY); - if (f1 < 0) { - fprintf(stderr, "Unable to open input file %s, ", file1); - if (errno >= sys_nerr) - fprintf(stderr, "error code = %d\n", errno); - else - fprintf(stderr, "%s\n", sys_errlist[errno]); - return 1; - } - - /* open temporary output file */ - f2 = open(tmpfile, (O_WRONLY | O_CREAT | O_TRUNC), s1.st_mode); - if (f2 < 0) { - fprintf(stderr, "Unable to open output file %s, ", tmpfile); - if (errno >= sys_nerr) - fprintf(stderr, "error code = %d\n", errno); - else - fprintf(stderr, "%s\n", sys_errlist[errno]); - fflush(stdout); - close(f1); - return 1; - } - - /* Copy file1 to temporary file */ - while ((n = read(f1, buf, sizeof(buf))) > 0) { - if (write(f2, buf, n) != n) { - fprintf(stderr,"Write failed, file %s must be copied again.\n", file2); - } - } - - /* preserve access and modification times: ("-x" disables)*/ - if (preserveDate) { - tv[0].tv_sec = s1.st_atime; - tv[0].tv_usec = 0; - tv[1].tv_sec = s1.st_mtime; - tv[1].tv_usec = 0; - utimes(tmpfile, tv); - } - - /* Close the files */ - code = close(f1); - code = close(f2); - if (code < 0) { - perror("close "); - rcode = 1; - } - - /* Rename file2 to file2.old. [-r] */ - if (renameTargets && goods2) { - strcpy(newName, file2); - strcat(newName, ".old"); - if (verbose) { - printf(" Renaming %s to %s\n", file2, newName); - fflush(stdout); - } - if (rename(file2, newName) < 0) { - fprintf(stderr, "Rename of %s to %s failed.\n", file2, newName); - } - } - - /* Rename temporary file to file2 */ - code = rename(tmpfile, file2); - if (code < 0) { - fprintf(stderr, "Rename of %s to %s failed.\n", tmpfile, file2); - return 1; - } - - /* Re-stat file2 and compare file sizes */ - code = lstat(file2, &s2); - if (code < 0) { - fprintf(stderr, "WARNING: Unable to stat new file %s\n", file2); - return 1; - } - if (s1.st_size != s2.st_size) { - fprintf(stderr, "WARNING: New file %s is %u bytes long; should be %u\n", - file2, s2.st_size, s1.st_size); - } - } /*c*/ - - /* Set the user-id */ - if (s2.st_uid != s1.st_uid) { - if (verbose) { - printf(" Set owner-id for %s to %d\n", file2, s1.st_uid); - fflush(stdout); - } - code = chown(file2, s1.st_uid, -1); - if (code) { - fprintf(stderr, "Unable to set owner-id for %s to %d\n", file2, s1.st_uid); - fflush(stdout); - rcode = 1; - s1.st_mode &= ~04000; /* Don't set suid bit */ - } - } - - /* Set the group-id */ - if (s2.st_gid != s1.st_gid) { - if (verbose) { - printf(" Set group-id for %s to %d\n", file2, s1.st_gid); - fflush(stdout); - } - code = chown(file2, -1, s1.st_gid); - if (code) { - fprintf(stderr, "Unable to set group-id for %s to %d\n", file2, s1.st_gid); - fflush(stdout); - rcode = 1; - s1.st_mode &= ~02000; /* Don't set sgid bit */ - } - } - - /* Set the mode bits */ - if (s1.st_mode != s2.st_mode) { - if (verbose) { - printf(" Set mode-bit for %s to %o\n", file2, (s1.st_mode & 07777)); - fflush(stdout); - } - code = chmod(file2, s1.st_mode); - if (code) { - fprintf(stderr, "Unable to set mode-bits for %s to %d\n", file2, s1.st_mode); - rcode = 1; - } - } - } /* regular file */ + /* + * -------------------- Copy regular file -------------------- + */ + int f1, f2, n; + char buf[4096]; /* Must be bigger than sizeof (*head) */ + struct timeval tv[2]; + char tmpfile[MAXPATHLEN], newName[MAXPATHLEN]; - else if ((s1.st_mode & S_IFMT) == S_IFLNK) { - /* - * --------------------- Copy symlink -------------------- - */ - char linkvalue[MAXPATHLEN+1]; - int n; - - if (verbose) { - printf("Level %d: Symbolic link %s to %s\n", level, file1, file2); - fflush(stdout); - } - - /* Don't ovewrite a write protected directory (unless force: -f) */ - if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { - fprintf(stderr, - "Link %s is write protected against its owner; not changed\n", - file2); - return 1; - } - - if (verbose) { - printf(" Copy symbolic link %s->%s to %s\n", file1, linkvalue, file2); - fflush(stdout); - } - - n = readlink(file1, linkvalue, sizeof(linkvalue)); - if (n == -1) { - fprintf(stderr, "Could not read symbolic link %s\n", file1); - perror("read link "); - return 1; - } - linkvalue[n] = 0; - - unlink(file2); /* Always make the new link (it was easier) */ - - code = symlink(linkvalue, file2); - if (code == -1) { - fprintf(stderr, "Could not create symbolic link %s\n", file2); - perror("create link "); - return 1; - } - } /*Dealing with symlink*/ - - else if ( preserveMountPoints && (code=isMountPoint( file1, &blob )) ) { - /* - * --------------------- Copy mount point -------------------- - */ - - if ( code > 1 ) { - perror("checking for mount point "); - return 1; - } - if (verbose) { - printf("Level %d: Mount point %s to %s\n", level, file1, file2); - fflush(stdout); - } - - /* Don't ovewrite a write protected directory (unless force: -f) */ - if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { - fprintf(stderr, - "Target %s is write protected against its owner; not changed\n", - file2); - return 1; - } - - if (verbose) { - printf(" Copy mount point %s for vol %s to %s\n", file1, blob.out, file2); - fflush(stdout); - } - - unlink(file2); /* Always make the new link (it was easier) */ - - strcat(blob.out, "."); /* stupid convention; these end with a period */ - code = symlink(blob.out, file2); - if (code == -1) { - fprintf(stderr, "Could not create mount point %s for vol %s\n", file2, blob.out); - perror("create mount point "); - return 1; - } - - } /*Dealing with mount point*/ - - else if (((s1.st_mode & S_IFMT) == S_IFDIR) && (recursive || (level == 0))) { - /* - * ----------------------- Copy directory ----------------------- - */ - DIR *dir; - int tfd, code, i; - struct OldAcl *oacl; - char tacl[MAXACL]; - char f1[MAXPATHLEN], f2[MAXPATHLEN]; - char *p1, *p2; - struct dirent *d; - - if (verbose) { - printf("Level %d: Directory %s to %s\n", level, file1, file2); - fflush(stdout); - } - - /* Don't ovewrite a write protected directory (unless force: -f) */ - if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { - fprintf(stderr, - "Directory %s is write protected against its owner; not changed\n", - file2); - return 1; - } - - strcpy(f1, file1); - strcpy(f2, file2); - p1 = f1 + strlen(f1); - p2 = f2 + strlen(f2); - if (p1 == f1 || p1[-1] != '/') - *p1++ = '/'; - if (p2 == f2 || p2[-1] != '/') - *p2++ = '/'; - - dir = opendir(file1); - if (dir == NULL) { - fprintf(stderr, "Couldn't open %s\n", file1); - return 1; - } - - while ((d = readdir(dir)) != NULL) { - if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) - continue; - strcpy(p1, d->d_name); - strcpy(p2, d->d_name); - code = Copy(f1, f2, recursive, level + 1); - if (code && !rcode) rcode = 1; /* remember errors */ - } - - closedir(dir); - - if (verbose) { - printf("Level %d: Copied directory %s to %s\n", level, file1, file2); - fflush(stdout); - } - - mkdir(file2, 0777); /* Handle case where MakeParent not invoked. */ - - if (verbose) { - printf(" Set owner-id for %s to %d\n", file2, s1.st_uid); - fflush(stdout); - } - code = chown(file2, s1.st_uid, -1); - if (code) { - fprintf(stderr, "Unable to set owner-id for %s to %d\n", file2, s1.st_uid); - fflush(stdout); - s1.st_mode &= ~04000; /* Don't set suid bit */ - } - - if (verbose) { - printf(" Set group-id for %s to %d\n", file2, s1.st_gid); - fflush(stdout); - } - code = chown(file2, -1, s1.st_gid); - if (code) { - fprintf(stderr, "Unable to set group-id for %s to %d\n", file2, s1.st_gid); - fflush(stdout); - s1.st_mode &= ~02000; /* Don't set sgid bit */ - } - - if (verbose) { - printf(" Set mode-bit for %s to %o\n", file2, (s1.st_mode & 07777)); - fflush(stdout); - } - code = chmod(file2, s1.st_mode); - if (code) { - fprintf(stderr, "Unable to set mode-bits for %s to %d\n", file2, s1.st_mode); - fflush(stdout); - rcode = 1; - } - - if (setacl == true) { - if (verbose) { - printf(" Set acls for %s\n", file2); - fflush(stdout); - } - - blob.in = aclspace; - blob.out = aclspace; - blob.in_size = 0; - blob.out_size = MAXACL; - - if (oldAcl) { - /* Get an old-style ACL and convert it */ - for (i=1; i= sys_nerr) + fprintf(stderr, "error code = %d\n", errno); + else + fprintf(stderr, "%s\n", sys_errlist[errno]); + return 1; + } + + /* open temporary output file */ + f2 = open(tmpfile, (O_WRONLY | O_CREAT | O_TRUNC), s1.st_mode); + if (f2 < 0) { + fprintf(stderr, "Unable to open output file %s, ", tmpfile); + if (errno >= sys_nerr) + fprintf(stderr, "error code = %d\n", errno); + else + fprintf(stderr, "%s\n", sys_errlist[errno]); + fflush(stdout); + close(f1); return 1; - } - code = ioctl(tfd, _VICEIOCTL(4), &blob); - close(tfd); - if (code < 0) { - if (errno == EINVAL) { - setacl = false; + } + + /* Copy file1 to temporary file */ + while ((n = read(f1, buf, sizeof(buf))) > 0) { + if (write(f2, buf, n) != n) { + fprintf(stderr, + "Write failed, file %s must be copied again.\n", + file2); } - else { - return 1; + } + + /* preserve access and modification times: ("-x" disables) */ + if (preserveDate) { + tv[0].tv_sec = s1.st_atime; + tv[0].tv_usec = 0; + tv[1].tv_sec = s1.st_mtime; + tv[1].tv_usec = 0; + utimes(tmpfile, tv); + } + + /* Close the files */ + code = close(f1); + code = close(f2); + if (code < 0) { + perror("close "); + rcode = 1; + } + + /* Rename file2 to file2.old. [-r] */ + if (renameTargets && goods2) { + strcpy(newName, file2); + strcat(newName, ".old"); + if (verbose) { + printf(" Renaming %s to %s\n", file2, newName); + fflush(stdout); } - } - /* Now convert the thing. */ - oacl = (struct OldAcl *) (aclspace+4); - sprintf(tacl, "%d\n%d\n", oacl->nplus, oacl->nminus); - strcat(tacl, oacl->data); - strcpy(aclspace, tacl); - } /*Grab and convert old-style ACL*/ - else { - /* Get a new-style ACL */ - code = pioctl(file1, _VICEIOCTL(2), &blob, 1); - if (code < 0) { - if (errno == EINVAL) { - setacl = false; + if (rename(file2, newName) < 0) { + fprintf(stderr, "Rename of %s to %s failed.\n", file2, + newName); + } + } + + /* Rename temporary file to file2 */ + code = rename(tmpfile, file2); + if (code < 0) { + fprintf(stderr, "Rename of %s to %s failed.\n", tmpfile, + file2); + return 1; + } + + /* Re-stat file2 and compare file sizes */ + code = lstat(file2, &s2); + if (code < 0) { + fprintf(stderr, "WARNING: Unable to stat new file %s\n", + file2); + return 1; + } + if (s1.st_size != s2.st_size) { + fprintf(stderr, + "WARNING: New file %s is %u bytes long; should be %u\n", + file2, s2.st_size, s1.st_size); + } + } + + /*c */ + /* Set the user-id */ + if (s2.st_uid != s1.st_uid) { + if (verbose) { + printf(" Set owner-id for %s to %d\n", file2, s1.st_uid); + fflush(stdout); + } + code = chown(file2, s1.st_uid, -1); + if (code) { + fprintf(stderr, "Unable to set owner-id for %s to %d\n", + file2, s1.st_uid); + fflush(stdout); + rcode = 1; + s1.st_mode &= ~04000; /* Don't set suid bit */ + } + } + + /* Set the group-id */ + if (s2.st_gid != s1.st_gid) { + if (verbose) { + printf(" Set group-id for %s to %d\n", file2, s1.st_gid); + fflush(stdout); + } + code = chown(file2, -1, s1.st_gid); + if (code) { + fprintf(stderr, "Unable to set group-id for %s to %d\n", + file2, s1.st_gid); + fflush(stdout); + rcode = 1; + s1.st_mode &= ~02000; /* Don't set sgid bit */ + } + } + + /* Set the mode bits */ + if (s1.st_mode != s2.st_mode) { + if (verbose) { + printf(" Set mode-bit for %s to %o\n", file2, + (s1.st_mode & 07777)); + fflush(stdout); + } + code = chmod(file2, s1.st_mode); + if (code) { + fprintf(stderr, "Unable to set mode-bits for %s to %d\n", + file2, s1.st_mode); + rcode = 1; + } + } + } + /* regular file */ + else if ((s1.st_mode & S_IFMT) == S_IFLNK) { + /* + * --------------------- Copy symlink -------------------- + */ + char linkvalue[MAXPATHLEN + 1]; + int n; + + if (verbose) { + printf("Level %d: Symbolic link %s to %s\n", level, file1, file2); + fflush(stdout); + } + + /* Don't ovewrite a write protected directory (unless force: -f) */ + if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { + fprintf(stderr, + "Link %s is write protected against its owner; not changed\n", + file2); + return 1; + } + + if (verbose) { + printf(" Copy symbolic link %s->%s to %s\n", file1, linkvalue, + file2); + fflush(stdout); + } + + n = readlink(file1, linkvalue, sizeof(linkvalue)); + if (n == -1) { + fprintf(stderr, "Could not read symbolic link %s\n", file1); + perror("read link "); + return 1; + } + linkvalue[n] = 0; + + unlink(file2); /* Always make the new link (it was easier) */ + + code = symlink(linkvalue, file2); + if (code == -1) { + fprintf(stderr, "Could not create symbolic link %s\n", file2); + perror("create link "); + return 1; + } + } + /*Dealing with symlink */ + else if (preserveMountPoints && (code = isMountPoint(file1, &blob))) { + /* + * --------------------- Copy mount point -------------------- + */ + + if (code > 1) { + perror("checking for mount point "); + return 1; + } + if (verbose) { + printf("Level %d: Mount point %s to %s\n", level, file1, file2); + fflush(stdout); + } + + /* Don't ovewrite a write protected directory (unless force: -f) */ + if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { + fprintf(stderr, + "Target %s is write protected against its owner; not changed\n", + file2); + return 1; + } + + if (verbose) { + printf(" Copy mount point %s for vol %s to %s\n", file1, + blob.out, file2); + fflush(stdout); + } + + unlink(file2); /* Always make the new link (it was easier) */ + + strcat(blob.out, "."); /* stupid convention; these end with a period */ + code = symlink(blob.out, file2); + if (code == -1) { + fprintf(stderr, "Could not create mount point %s for vol %s\n", + file2, blob.out); + perror("create mount point "); + return 1; + } + + } + /*Dealing with mount point */ + else if (((s1.st_mode & S_IFMT) == S_IFDIR) + && (recursive || (level == 0))) { + /* + * ----------------------- Copy directory ----------------------- + */ + DIR *dir; + int tfd, code, i; + struct OldAcl *oacl; + char tacl[MAXACL]; + char f1[MAXPATHLEN], f2[MAXPATHLEN]; + char *p1, *p2; + struct dirent *d; + + if (verbose) { + printf("Level %d: Directory %s to %s\n", level, file1, file2); + fflush(stdout); + } + + /* Don't ovewrite a write protected directory (unless force: -f) */ + if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { + fprintf(stderr, + "Directory %s is write protected against its owner; not changed\n", + file2); + return 1; + } + + strcpy(f1, file1); + strcpy(f2, file2); + p1 = f1 + strlen(f1); + p2 = f2 + strlen(f2); + if (p1 == f1 || p1[-1] != '/') + *p1++ = '/'; + if (p2 == f2 || p2[-1] != '/') + *p2++ = '/'; + + dir = opendir(file1); + if (dir == NULL) { + fprintf(stderr, "Couldn't open %s\n", file1); + return 1; + } + + while ((d = readdir(dir)) != NULL) { + if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) + continue; + strcpy(p1, d->d_name); + strcpy(p2, d->d_name); + code = Copy(f1, f2, recursive, level + 1); + if (code && !rcode) + rcode = 1; /* remember errors */ + } + + closedir(dir); + + if (verbose) { + printf("Level %d: Copied directory %s to %s\n", level, file1, + file2); + fflush(stdout); + } + + mkdir(file2, 0777); /* Handle case where MakeParent not invoked. */ + + if (verbose) { + printf(" Set owner-id for %s to %d\n", file2, s1.st_uid); + fflush(stdout); + } + code = chown(file2, s1.st_uid, -1); + if (code) { + fprintf(stderr, "Unable to set owner-id for %s to %d\n", file2, + s1.st_uid); + fflush(stdout); + s1.st_mode &= ~04000; /* Don't set suid bit */ + } + + if (verbose) { + printf(" Set group-id for %s to %d\n", file2, s1.st_gid); + fflush(stdout); + } + code = chown(file2, -1, s1.st_gid); + if (code) { + fprintf(stderr, "Unable to set group-id for %s to %d\n", file2, + s1.st_gid); + fflush(stdout); + s1.st_mode &= ~02000; /* Don't set sgid bit */ + } + + if (verbose) { + printf(" Set mode-bit for %s to %o\n", file2, + (s1.st_mode & 07777)); + fflush(stdout); + } + code = chmod(file2, s1.st_mode); + if (code) { + fprintf(stderr, "Unable to set mode-bits for %s to %d\n", file2, + s1.st_mode); + fflush(stdout); + rcode = 1; + } + + if (setacl == true) { + if (verbose) { + printf(" Set acls for %s\n", file2); + fflush(stdout); + } + + blob.in = aclspace; + blob.out = aclspace; + blob.in_size = 0; + blob.out_size = MAXACL; + + if (oldAcl) { + /* Get an old-style ACL and convert it */ + for (i = 1; i < strlen(file1); i++) + if (file1[i] == '/') + break; + strcpy(aclspace, &file1[i]); + + blob.in_size = 1 + strlen(aclspace); + tfd = open(file1, O_RDONLY, 0); + if (tfd < 0) { + perror("old-acl open "); + return 1; } - else { - perror("getacl "); - return 1; + code = ioctl(tfd, _VICEIOCTL(4), &blob); + close(tfd); + if (code < 0) { + if (errno == EINVAL) { + setacl = false; + } else { + return 1; + } } - } - } /*Grab new-style ACL*/ - - /* - * Now, set the new-style ACL. - */ - if (setacl == true) { - blob.out = aclspace; - blob.in = aclspace; - blob.out_size = 0; - blob.in_size = 1+strlen(aclspace); - code = pioctl(file2, _VICEIOCTL(1), &blob, 1); - if (code) { - if (errno == EINVAL) { - setacl = false; + /* Now convert the thing. */ + oacl = (struct OldAcl *)(aclspace + 4); + sprintf(tacl, "%d\n%d\n", oacl->nplus, oacl->nminus); + strcat(tacl, oacl->data); + strcpy(aclspace, tacl); + } /*Grab and convert old-style ACL */ + else { + /* Get a new-style ACL */ + code = pioctl(file1, _VICEIOCTL(2), &blob, 1); + if (code < 0) { + if (errno == EINVAL) { + setacl = false; + } else { + perror("getacl "); + return 1; + } } - else { - fprintf(stderr, "Couldn't set acls for %s\n", file2); - return 1; + } /*Grab new-style ACL */ + + /* + * Now, set the new-style ACL. + */ + if (setacl == true) { + blob.out = aclspace; + blob.in = aclspace; + blob.out_size = 0; + blob.in_size = 1 + strlen(aclspace); + code = pioctl(file2, _VICEIOCTL(1), &blob, 1); + if (code) { + if (errno == EINVAL) { + setacl = false; + } else { + fprintf(stderr, "Couldn't set acls for %s\n", file2); + return 1; + } } - } - } + } - if (setacl == false) { - printf("Not setting acls\n"); - } - } + if (setacl == false) { + printf("Not setting acls\n"); + } + } } return rcode; -} /*Copy*/ +} /*Copy */ -int isMountPoint( name, blob ) - char *name; - struct ViceIoctl *blob; +int +isMountPoint(name, blob) + char *name; + struct ViceIoctl *blob; { - afs_int32 code; - char true_name[1024]; /*dirname*/ - char parent_dir[1024]; /*Parent directory of true name*/ - char *last_component; /*Last component of true name*/ + afs_int32 code; + char true_name[1024]; /*dirname */ + char parent_dir[1024]; /*Parent directory of true name */ + char *last_component; /*Last component of true name */ - sprintf(true_name, "%s%s", - (name[0] == '/') ? "" : "./", - name); + sprintf(true_name, "%s%s", (name[0] == '/') ? "" : "./", name); /* * Find rightmost slash, if any. */ - last_component = (char *) strrchr(true_name, '/'); + last_component = (char *)strrchr(true_name, '/'); if (last_component) { - /* - * Found it. Designate everything before it as the parent directory, - * everything after it as the final component. - */ - strncpy(parent_dir, true_name, last_component - true_name); - parent_dir[last_component - true_name] = 0; - last_component++; /*Skip the slash*/ - } - else { - /* - * No slash appears in the given file name. Set parent_dir to the current - * directory, and the last component as the given name. - */ - strcpy(parent_dir, "."); - last_component = true_name; + /* + * Found it. Designate everything before it as the parent directory, + * everything after it as the final component. + */ + strncpy(parent_dir, true_name, last_component - true_name); + parent_dir[last_component - true_name] = 0; + last_component++; /*Skip the slash */ + } else { + /* + * No slash appears in the given file name. Set parent_dir to the current + * directory, and the last component as the given name. + */ + strcpy(parent_dir, "."); + last_component = true_name; } if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) { - fprintf(stderr, "up: you may not use '.' or '..' as the last component\n"); - fprintf(stderr, "up: of a name in the 'up' command.\n"); - return 3; + fprintf(stderr, + "up: you may not use '.' or '..' as the last component\n"); + fprintf(stderr, "up: of a name in the 'up' command.\n"); + return 3; } blob->in = last_component; - blob->in_size = strlen(last_component)+1; + blob->in_size = strlen(last_component) + 1; blob->out_size = MAXSIZE; blob->out = space; memset(space, 0, MAXSIZE); @@ -723,23 +744,22 @@ int isMountPoint( name, blob ) code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, blob, 0); if (code == 0) { - printf("'%s' is a mount point for volume '%s'\n", name, space); - fflush(stdout); - return 1; - } - else { - if (errno == EINVAL) { - /* printf( "'%s' is not a mount point.\n", name); + printf("'%s' is a mount point for volume '%s'\n", name, space); + fflush(stdout); + return 1; + } else { + if (errno == EINVAL) { + /* printf( "'%s' is not a mount point.\n", name); * fflush(stdout); */ - return 0; - } - else { - fprintf( stderr, "problem examining '%s' in '%s'.\n", last_component, parent_dir ); - return 2; - /* Die(errno, (ti->data ? ti->data : parent_dir)); - */ - } + return 0; + } else { + fprintf(stderr, "problem examining '%s' in '%s'.\n", + last_component, parent_dir); + return 2; + /* Die(errno, (ti->data ? ti->data : parent_dir)); + */ + } } return 4; } diff --git a/src/venus/whatfid.c b/src/venus/whatfid.c index f1322de19..c0a72a9fa 100644 --- a/src/venus/whatfid.c +++ b/src/venus/whatfid.c @@ -13,7 +13,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/venus/whatfid.c,v 1.1.1.4 2001/07/14 22:24:38 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/venus/whatfid.c,v 1.5 2003/07/15 23:17:22 shadow Exp $"); #include #include @@ -50,7 +51,7 @@ int WhatFidCmd_FileParm; int WhatFidCmd_FollowLinkParm; int WhatFidCmd(as) -register struct cmd_syndesc *as; + register struct cmd_syndesc *as; { register afs_int32 code; struct ViceIoctl blob; @@ -62,11 +63,11 @@ register struct cmd_syndesc *as; if (as->parms[1].items) follow = 0; - for(ti=as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ blob.out_size = sizeof(struct VenusFid); blob.in_size = 0; - blob.out = (char*)&vFid; + blob.out = (char *)&vFid; code = pioctl(ti->data, VIOCGETFID, &blob, follow); if (code) { PioctlError(code, ti->data); @@ -77,15 +78,16 @@ register struct cmd_syndesc *as; } return 0; } - + main(argc, argv) -int argc; -char **argv; { + int argc; + char **argv; +{ register afs_int32 code; register struct cmd_syndesc *ts; - + #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a @@ -94,7 +96,7 @@ char **argv; { * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; @@ -105,35 +107,48 @@ char **argv; { ts = cmd_CreateSyntax("initcmd", WhatFidCmd, 0, "list fid for file(s)"); WhatFidCmd_FileParm = cmd_AddParm(ts, "-path", CMD_LIST, 0, "pathnames"); - WhatFidCmd_FollowLinkParm = cmd_AddParm(ts, "-link", CMD_FLAG, CMD_OPTIONAL, - "do not follow symlinks"); - + WhatFidCmd_FollowLinkParm = + cmd_AddParm(ts, "-link", CMD_FLAG, CMD_OPTIONAL, + "do not follow symlinks"); + exit(cmd_Dispatch(argc, argv)); } void PioctlError(code, filename) - int code; - char *filename; -{ /*Die*/ + int code; + char *filename; +{ /*Die */ if (errno == EINVAL) { if (filename) - fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename); - else fprintf(stderr,"%s: Invalid argument.\n", pn); - } - else if (errno == ENOENT) { - if (filename) fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename); - else fprintf(stderr,"%s: no such file returned\n", pn); - } - else if (errno == EROFS) fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn); + fprintf(stderr, + "%s: Invalid argument; it is possible that %s is not in AFS.\n", + pn, filename); + else + fprintf(stderr, "%s: Invalid argument.\n", pn); + } else if (errno == ENOENT) { + if (filename) + fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename); + else + fprintf(stderr, "%s: no such file returned\n", pn); + } else if (errno == EROFS) + fprintf(stderr, + "%s: You can not change a backup or readonly volume\n", pn); else if (errno == EACCES || errno == EPERM) { - if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename); - else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn); - } - else { - if (filename) fprintf(stderr,"%s:'%s'", pn, filename); - else fprintf(stderr,"%s", pn); - fprintf(stderr,": %s\n", error_message(errno)); + if (filename) + fprintf(stderr, + "%s: You don't have the required access rights on '%s'\n", + pn, filename); + else + fprintf(stderr, + "%s: You do not have the required rights to do this operation\n", + pn); + } else { + if (filename) + fprintf(stderr, "%s:'%s'", pn, filename); + else + fprintf(stderr, "%s", pn); + fprintf(stderr, ": %s\n", error_message(errno)); } -} /*Die*/ +} /*Die */ diff --git a/src/vlserver/Makefile.in b/src/vlserver/Makefile.in index b04dc04c1..45bd2ff8e 100644 --- a/src/vlserver/Makefile.in +++ b/src/vlserver/Makefile.in @@ -5,32 +5,9 @@ # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html -DEST=@DEST@ -TOP_INCDIR=@TOP_INCDIR@ -TOP_LIBDIR=@TOP_LIBDIR@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ -libexecdir=@libexecdir@ -libdir=@libdir@ -includedir=@includedir@ -mandir=@mandir@ -afssrvbindir=@afssrvbindir@ -afssrvsbindir=@afssrvsbindir@ -afssrvlibexecdir=@afssrvlibexecdir@ -TOP_SRCDIR=@TOP_SRCDIR@ -SYS_NAME=@AFS_SYSNAME@ - -SHELL = /bin/sh - -include ../config/Makefile.${SYS_NAME} - -KERNELDIR=../libafs -UKERNELDIR=../libuafs -COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et - -CFLAGS=${DBUG} -I. -I.. -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS} +srcdir=@srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config + INCLS=${TOP_INCDIR}/ubik.h \ ${TOP_INCDIR}/lwp.h \ ${TOP_INCDIR}/lock.h \ @@ -49,54 +26,43 @@ LIBS=\ ${TOP_LIBDIR}/liblwp.a \ ${TOP_LIBDIR}/libdes.a \ ${TOP_LIBDIR}/libcom_err.a \ - ${TOP_LIBDIR}/util.a \ + ${TOP_LIBDIR}/libcmd.a \ ${TOP_LIBDIR}/libsys.a \ - ${TOP_LIBDIR}/util.a - -auditlib=${TOP_LIBDIR}/libaudit.a - -RXGEN=${TOP_SRCDIR}/rxgen/rxgen -KSRCS=Kvldbint.cs.c Kvldbint.xdr.c vl_opcodes.h vldbint.h -UKSRCS=$(KSRCS) + ${TOP_LIBDIR}/libafsutil.a OBJS=vldbint.xdr.o vldbint.cs.o vl_errors.o -CDIR=../../../src/vlserver -include ../config/Makefile.version -noversion: install - -all: kinstall ukinstall \ +all: \ vlserver vlclient cnvldb vlserver cnvldb vldb_check \ - ${TOP_LIBDIR}/libvldb.a \ + Kvldbint.cs.c Kvldbint.xdr.c vldbint.h \ + ${TOP_LIBDIR}/libvldb.a depinstall + +depinstall: \ + Kvldbint.cs.c Kvldbint.xdr.c vldbint.h \ ${TOP_INCDIR}/afs/vl_opcodes.h \ ${TOP_INCDIR}/afs/vlserver.h \ ${TOP_INCDIR}/afs/vldbint.h \ - ${TOP_INCDIR}/afs/cnvldb.h + ${TOP_INCDIR}/afs/cnvldb.h -clean: - $(RM) -f *.o vlserver vlclient cnvldb vldbint.cs.c vldbint.ss.c \ - vldbint.xdr.c vldbint.h Kvldbint.cs.c Kvldbint.xdr.c \ - core *.a *.otl vlserver.h vldb_check\ - vl_errors.c AFS_component_version_number.c +vldb_check: vldb_check.o ${LIBS} + $(CC) ${CFLAGS} -o vldb_check vldb_check.o ${LIBS} ${XLIBS} -vldb_check: vldb_check.c - $(CC) ${CFLAGS} -o vldb_check vldb_check.c ${XLIBS} \ - ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a +vldb_check.o: vldb_check.c AFS_component_version_number.o -cnvldb: cnvldb.o - $(CC) ${CFLAGS} -o cnvldb cnvldb.o ${XLIBS} ${TOP_LIBDIR}/libcmd.a\ - ${TOP_LIBDIR}/util.a +cnvldb: cnvldb.o ${LIBS} + $(CC) ${CFLAGS} -o cnvldb cnvldb.o ${LIBS} ${XLIBS} cnvldb.o: cnvldb.c cnvldb.h AFS_component_version_number.o -sascnvldb: sascnvldb.o - $(CC) ${CFLAGS} -o sascnvldb sascnvldb.o ${XLIBS} +sascnvldb: sascnvldb.o ${LIBS} + $(CC) ${CFLAGS} -o sascnvldb sascnvldb.o ${LIBS} ${XLIBS} sascnvldb.o: sascnvldb.c cnvldb.h AFS_component_version_number.o vlserver: vlserver.o vlutils.o vlprocs.o vldbint.ss.o vldbint.xdr.o $(LIBS) - $(CC) ${CFLAGS} -o vlserver vlserver.o vlutils.o vlprocs.o vldbint.ss.o vldbint.xdr.o $(LIBS) ${XLIBS} ${auditlib} + $(CC) ${CFLAGS} -o vlserver vlserver.o vlutils.o vlprocs.o vldbint.ss.o \ + vldbint.xdr.o $(LIBS) ${XLIBS} ${TOP_LIBDIR}/libaudit.a vlserver.o: vlserver.c ${INCLS} AFS_component_version_number.o vlutils.o: vlutils.c ${INCLS} @@ -104,13 +70,28 @@ vlprocs.o: vlprocs.c ${INCLS} vldbint.ss.o: vldbint.ss.c vldbint.xdr.c vldbint.cs.o: vldbint.cs.c vldbint.xdr.c vldbint.xdr.o: vldbint.xdr.c vldbint.h -vldbint.ss.c vldbint.cs.c vldbint.xdr.c vldbint.h: vldbint.xg - ${RXGEN} -x vldbint.xg + +vldbint.cs.c: vldbint.xg + ${RXGEN} -x -C -o $@ ${srcdir}/vldbint.xg + +vldbint.ss.c: vldbint.xg + ${RXGEN} -x -S -o $@ ${srcdir}/vldbint.xg + +vldbint.xdr.c: vldbint.xg + ${RXGEN} -x -c -o $@ ${srcdir}/vldbint.xg + +vldbint.h: vldbint.xg + ${RXGEN} -x -h -o $@ ${srcdir}/vldbint.xg + +vldbint.cs.c: vldbint.h +vldbint.ss.c: vldbint.h +vldbint.xdr.c: vldbint.h Kvldbint.cs.c: vldbint.xg - ${RXGEN} -x -k -C -o $@ vldbint.xg + ${RXGEN} -x -k -C -o $@ ${srcdir}/vldbint.xg + Kvldbint.xdr.c: vldbint.xg - ${RXGEN} -x -k -c -o $@ vldbint.xg + ${RXGEN} -x -k -c -o $@ ${srcdir}/vldbint.xg libvldb.a: $(OBJS) AFS_component_version_number.o $(RM) -f $@ @@ -124,25 +105,31 @@ vlclient.o: vlclient.c ${INCLS} AFS_component_version_number.o vl_errors.o: vl_errors.c vlserver.h vl_errors.c: vl_errors.et vlserver.p.h - $(RM) -f vlserver.h vl_errors.c; ${COMPILE_ET} vl_errors -h vlserver + $(RM) -f vlserver.h vl_errors.c; ${COMPILE_ET} -p ${srcdir} vl_errors -h vlserver system: install -kinstall: $(KSRCS) - ${INSTALL} $(KSRCS) ${KERNELDIR}/afsint - -ukinstall webinstall: ${UKERNELDIR}/afsint $(UKSRCS) - ${INSTALL} $(UKSRCS) ${UKERNELDIR}/afsint - -${UKERNELDIR}/afsint: - mkdir -p $@ - ${DEST}/root.server/usr/afs/bin/vlserver: vlserver ${INSTALL} $? $@ ${DEST}/etc/vldb_convert: cnvldb ${INSTALL} -f $? $@ +${TOP_LIBDIR}/libvldb.a: libvldb.a + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/vl_opcodes.h: vl_opcodes.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/vlserver.h: vlserver.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/vldbint.h: vldbint.h + ${INSTALL} $? $@ + +${TOP_INCDIR}/afs/cnvldb.h: cnvldb.h + ${INSTALL} $? $@ + install: \ ${DESTDIR}${afssrvlibexecdir}/vlserver \ ${DESTDIR}${afssrvsbindir}/vldb_convert \ @@ -153,86 +140,64 @@ install: \ ${DESTDIR}${includedir}/afs/cnvldb.h \ ${DESTDIR}${afssrvsbindir}/vldb_check -libinstall: \ - ${DESTDIR}${libdir}/afs/libvldb.a \ - ${DESTDIR}${includedir}/afs/vl_opcodes.h \ - ${DESTDIR}${includedir}/afs/vlserver.h \ - ${DESTDIR}${includedir}/afs/vldbint.h \ - ${DESTDIR}${includedir}/afs/cnvldb.h - ${DESTDIR}${afssrvlibexecdir}/vlserver: vlserver ${INSTALL} $? $@ ${DESTDIR}${afssrvsbindir}/vldb_convert: cnvldb ${INSTALL} -f $? $@ -${DEST}/lib/afs/libvldb.a: libvldb.a - ${INSTALL} $? $@ - ${DESTDIR}${libdir}/afs/libvldb.a: libvldb.a ${INSTALL} $? $@ - -${TOP_LIBDIR}/libvldb.a: libvldb.a - ${INSTALL} $? $@ - - -${DEST}/include/afs/vl_opcodes.h: vl_opcodes.h - ${INSTALL} $? $@ - ${DESTDIR}${includedir}/afs/vl_opcodes.h: vl_opcodes.h ${INSTALL} $? $@ - -${TOP_INCDIR}/afs/vl_opcodes.h: vl_opcodes.h - ${INSTALL} $? $@ - - -${DEST}/include/afs/vlserver.h: vlserver.h - ${INSTALL} $? $@ - ${DESTDIR}${includedir}/afs/vlserver.h: vlserver.h ${INSTALL} $? $@ - -${TOP_INCDIR}/afs/vlserver.h: vlserver.h +${DESTDIR}${includedir}/afs/vldbint.h: vldbint.h ${INSTALL} $? $@ - -${DEST}/include/afs/vldbint.h: vldbint.h +${DESTDIR}${includedir}/afs/cnvldb.h: cnvldb.h ${INSTALL} $? $@ -${DESTDIR}${includedir}/afs/vldbint.h: vldbint.h +${DESTDIR}${afssrvsbindir}/vldb_check: vldb_check ${INSTALL} $? $@ +dest: \ + ${DEST}/root.server/usr/afs/bin/vlserver \ + ${DEST}/etc/vldb_convert \ + ${DEST}/lib/afs/libvldb.a \ + ${DEST}/include/afs/vl_opcodes.h \ + ${DEST}/include/afs/vlserver.h \ + ${DEST}/include/afs/vldbint.h \ + ${DEST}/include/afs/cnvldb.h \ + ${DEST}/etc/vldb_check -${TOP_INCDIR}/afs/vldbint.h: vldbint.h +${DEST}/lib/afs/libvldb.a: libvldb.a ${INSTALL} $? $@ - -${DEST}/include/afs/cnvldb.h: cnvldb.h +${DEST}/include/afs/vl_opcodes.h: vl_opcodes.h ${INSTALL} $? $@ -${DESTDIR}${includedir}/afs/cnvldb.h: cnvldb.h +${DEST}/include/afs/vlserver.h: vlserver.h ${INSTALL} $? $@ - -${TOP_INCDIR}/afs/cnvldb.h: cnvldb.h +${DEST}/include/afs/vldbint.h: vldbint.h ${INSTALL} $? $@ +${DEST}/include/afs/cnvldb.h: cnvldb.h + ${INSTALL} $? $@ ${DEST}/etc/vldb_check: vldb_check ${INSTALL} $? $@ -${DESTDIR}${afssrvsbindir}/vldb_check: vldb_check - ${INSTALL} $? $@ +# +# Misc targets +# +include ../config/Makefile.version -dest: \ - ${DEST}/root.server/usr/afs/bin/vlserver \ - ${DEST}/etc/vldb_convert \ - ${DEST}/lib/afs/libvldb.a \ - ${DEST}/include/afs/vl_opcodes.h \ - ${DEST}/include/afs/vlserver.h \ - ${DEST}/include/afs/vldbint.h \ - ${DEST}/include/afs/cnvldb.h \ - ${DEST}/etc/vldb_check +clean: + $(RM) -f *.o *.a *.otl *.xdr.c *.cs.c *.ss.c core \ + vlserver vlclient cnvldb vldbint.h vlserver.h vldb_check \ + vl_errors.c AFS_component_version_number.c diff --git a/src/vlserver/NTMakefile b/src/vlserver/NTMakefile index e2331e4e1..b0dfcb109 100644 --- a/src/vlserver/NTMakefile +++ b/src/vlserver/NTMakefile @@ -7,14 +7,14 @@ # Override default definitions in NTMakefile.$(SYS_NAME) before including. +RELDIR=vlserver !INCLUDE ..\config\NTMakefile.$(SYS_NAME) !include ..\config\NTMakefile.version - ############################################################################ # Definitions for installing header files -INCFILEDIR = $(DESTDIR)\include +INCFILEDIR = $(DESTDIR)\include\afs INCFILES = \ $(INCFILEDIR)\afs\vl_opcodes.h \ @@ -27,11 +27,10 @@ INCFILES = \ LIBFILE = $(DESTDIR)\lib\afs\afsvldb.lib LIBOBJS =\ - vl_errors.obj \ - vldbint.cs.obj \ - vldbint.xdr.obj \ - AFS_component_version_number.obj - + $(OUT)\vl_errors.obj \ + $(OUT)\vldbint.cs.obj \ + $(OUT)\vldbint.xdr.obj \ + $(OUT)\AFS_component_version_number.obj $(LIBFILE): $(LIBOBJS) $(LIBARCH) @@ -42,19 +41,19 @@ $(LIBFILE): $(LIBOBJS) MT_LIBFILE = $(DESTDIR)\lib\afs\mtafsvldb.lib MT_LIBOBJS =\ - vl_errors_mt.obj \ - vldbint.cs_mt.obj \ - vldbint.xdr_mt.obj \ - AFS_component_version_number.obj + $(OUT)\vl_errors_mt.obj \ + $(OUT)\vldbint.cs_mt.obj \ + $(OUT)\vldbint.xdr_mt.obj \ + $(OUT)\AFS_component_version_number.obj -vl_errors_mt.obj:vl_errors.c - $(C2OBJ) vl_errors.c -DAFS_PTHREAD_ENV /Fovl_errors_mt.obj +$(OUT)\vl_errors_mt.obj:vl_errors.c + $(C2OBJ) $** -DAFS_PTHREAD_ENV -vldbint.cs_mt.obj:vldbint.cs.c - $(C2OBJ) vldbint.cs.c -DAFS_PTHREAD_ENV /Fovldbint.cs_mt.obj +$(OUT)\vldbint.cs_mt.obj:vldbint.cs.c + $(C2OBJ) $** -DAFS_PTHREAD_ENV -vldbint.xdr_mt.obj:vldbint.xdr.c - $(C2OBJ) vldbint.xdr.c -DAFS_PTHREAD_ENV /Fovldbint.xdr_mt.obj +$(OUT)\vldbint.xdr_mt.obj:vldbint.xdr.c + $(C2OBJ) $** -DAFS_PTHREAD_ENV $(MT_LIBFILE): $(MT_LIBOBJS) $(LIBARCH) @@ -65,12 +64,12 @@ $(MT_LIBFILE): $(MT_LIBOBJS) VLSERVER = $(DESTDIR)\root.server\usr\afs\bin\vlserver.exe VLSERVER_EXEOBJS =\ - vldbint.ss.obj \ - vldbint.xdr.obj \ - vlprocs.obj \ - vlserver.obj \ - vlutils.obj \ - vlserver.res + $(OUT)\vldbint.ss.obj \ + $(OUT)\vldbint.xdr.obj \ + $(OUT)\vlprocs.obj \ + $(OUT)\vlserver.obj \ + $(OUT)\vlutils.obj \ + $(OUT)\vlserver.res VLSERVER_EXECLIBS = \ $(DESTDIR)\lib\afsubik.lib \ @@ -95,13 +94,16 @@ $(VLSERVER): $(VLSERVER_EXEOBJS) $(LIBFILE) $(VLSERVER_EXECLIBS) ############################################################################ # generate versioninfo resources -vlserver.res: vlserver.rc AFS_component_version_number.h - $(RC) $*.rc +$(OUT)\vlserver.res: AFS_component_version_number.h +# $(RC) $*.rc ############################################################################ # rxgen on vldbint.xg -vldbint.ss.c vldbint.cs.c vldbint.xdr.c $(DESTDIR)\include\afs\vldbint.h: vldbint.xg +$(INCFILES):$$(@F) + $(COPY) $** $(INCFILEDIR)\. + +vldbint.ss.c vldbint.cs.c vldbint.xdr.c vldbint.h: vldbint.xg $(RXGEN) -x $** $(COPY) vldbint.h $(DESTDIR)\include\afs\vldbint.h @@ -109,7 +111,7 @@ vldbint.ss.c vldbint.cs.c vldbint.xdr.c $(DESTDIR)\include\afs\vldbint.h: vldbin # Definitions for generating files via COMPILE_ET # Need an explicit copy here, since we've fussed with the general rule. -$(INCFILEDIR)\afs\vlserver.h vl_errors.c: vl_errors.et vlserver.p.h +vlserver.h vl_errors.c: vl_errors.et vlserver.p.h $(DEL) vlserver.h vl_errors.c $(COMPILE_ET) vl_errors -h vlserver $(COPY) vlserver.h $(INCFILEDIR)\afs\vlserver.h @@ -123,7 +125,7 @@ VLDB_CHECK_LIBS =\ $(DESTDIR)\lib\afs\afseventlog.lib \ $(DESTDIR)\lib\afs\afscmd.lib -vldb_check.exe: vldb_check.obj $(VLDB_CHECK_LIBS) +$(OUT)\vldb_check.exe: $(OUT)\vldb_check.obj $(VLDB_CHECK_LIBS) $(EXECONLINK) ############################################################################ @@ -132,14 +134,14 @@ VLCLIENT_LIBS = \ $(DESTDIR)\lib\afs\afscmd.lib \ $(DESTDIR)\lib\afs\afspioctl.lib -vlclient.exe: vlclient.obj $(LIBFILE) $(VLSERVER_EXECLIBS) $(VLCLIENT_LIBS) +$(OUT)\vlclient.exe: $(OUT)\vlclient.obj $(LIBFILE) $(VLSERVER_EXECLIBS) $(VLCLIENT_LIBS) $(EXECONLINK) ############################################################################ # install vlserver components -install: $(INCFILES) $(LIBFILE) $(VLSERVER) vldb_check.exe vlclient.exe \ +install: $(INCFILES) $(LIBFILE) $(VLSERVER) $(OUT)\vldb_check.exe $(OUT)\vlclient.exe \ $(MT_LIBFILE) install9x: install @@ -150,5 +152,8 @@ install_libutils: $(INCFILES) $(LIBFILE) # clean up clean:: - $(DEL) vldbint.cs.c vldbint.ss.c vldbint.xdr.c vldbint.h - $(DEL) vlserver.h vl_errors.c + $(DEL) vldbint.cs.c vldbint.ss.c vldbint.xdr.c vldbint.h$$ + $(DEL) vlserver.h vl_errors.c $(INCFILES) + +mkdir: + diff --git a/src/vlserver/cnvldb.c b/src/vlserver/cnvldb.c index c8e0bf7b5..1dc89c492 100644 --- a/src/vlserver/cnvldb.c +++ b/src/vlserver/cnvldb.c @@ -10,13 +10,15 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/cnvldb.c,v 1.3 2003/07/30 17:23:46 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vlserver/cnvldb.c,v 1.9 2003/07/15 23:17:33 shadow Exp $"); #include #include #include #include #include + #ifdef HAVE_STRING_H #include #else @@ -24,7 +26,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/cnvldb.c,v 1.3 2003/07/30 17:2 #include #endif #endif -#include "cnvldb.h" /* CHANGEME! */ + +#include "cnvldb.h" /* CHANGEME! */ #include #include #include @@ -33,7 +36,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/cnvldb.c,v 1.3 2003/07/30 17:2 #include "vlserver.h" -#define MAXSIZE 2048 /* most I'll get back from PIOCTL */ +#define MAXSIZE 2048 /* most I'll get back from PIOCTL */ #define BADSERVERID 255 /* XXX */ @@ -41,24 +44,26 @@ extern struct cmd_syndesc *cmd_CreateSyntax(); static char pn[] = "cnvldb"; static char tempname[] = "XXnewvldb"; static char space[MAXSIZE]; -static int MaxServers[3] = {30,254,254};/* max server # permitted in this version*/ +static int MaxServers[3] = { 30, 254, 254 }; /* max server # permitted in this version */ static afs_int32 Conv4to3(); static int convert_vlentry(); static int rewrite_header(); -static char tspace[1024]; /* chdir can't handle anything bigger, anyway */ +static char tspace[1024]; /* chdir can't handle anything bigger, anyway */ /* return a static pointer to a buffer */ -static char *Parent(apath) -char *apath; { +static char * +Parent(apath) + char *apath; +{ register char *tp; strcpy(tspace, apath); tp = strrchr(tspace, '/'); if (tp) { *tp = 0; - } - else strcpy(tspace, "."); + } else + strcpy(tspace, "."); return tspace; } @@ -69,143 +74,146 @@ afs_int32 dbsize; char *pathname = NULL; const char *dbPath; -static handleit(as) - struct cmd_syndesc *as; +static +handleit(as) + struct cmd_syndesc *as; { register struct cmd_item *ti; register afs_int32 code; - int w, old, new, rc, dump=0, fromv=0; + int w, old, new, rc, dump = 0, fromv = 0; short uvers; - char ubik[80]; /* space for some ubik header */ + char ubik[80]; /* space for some ubik header */ union { struct vlheader_1 header1; struct vlheader_2 header2; struct vlheader_3 header3; - } oldheader, oldheader1, newheader; /* large enough for either */ - + } oldheader, oldheader1, newheader; /* large enough for either */ + union { struct vlentry_1 entry1; struct vlentry_2 entry2; struct vlentry_3 entry3; - char mhinfo_block[VL_ADDREXTBLK_SIZE]; + char mhinfo_block[VL_ADDREXTBLK_SIZE]; } xvlentry; - - pathname = (as->parms[2].items ? as->parms[2].items->data : dbPath); /* -name */ - showversion = (as->parms[3].items ? 1 : 0); /* -showversion */ - dump = (as->parms[4].items ? 1 : 0); /* -dumpvldb */ - fromvers = (as->parms[1].items ? atoi(as->parms[1].items->data) : 0); /* -fromversion */ - tovers = (as->parms[0].items ? atoi(as->parms[0].items->data) : 0); /* -toversion */ + + pathname = (as->parms[2].items ? as->parms[2].items->data : dbPath); /* -name */ + showversion = (as->parms[3].items ? 1 : 0); /* -showversion */ + dump = (as->parms[4].items ? 1 : 0); /* -dumpvldb */ + fromvers = (as->parms[1].items ? atoi(as->parms[1].items->data) : 0); /* -fromversion */ + tovers = (as->parms[0].items ? atoi(as->parms[0].items->data) : 0); /* -toversion */ /* should stat() the old vldb, get its size, and see if there's */ /* room for another. It might be in AFS, so check the quota, too */ - old = open(pathname,O_RDONLY); + old = open(pathname, O_RDONLY); if (old < 0) { - perror(pn); - exit (-1); + perror(pn); + exit(-1); } /* Read the version */ lseek(old, 64, L_SET); - read (old, &fromv, sizeof(int)); + read(old, &fromv, sizeof(int)); fromv = ntohl(fromv); if ((fromv < 1) || (fromv > 4)) { - fprintf(stderr, pn); - fprintf(stderr,": Unrecognized VLDB version %d.\n", fromv); - exit(-1); + fprintf(stderr, pn); + fprintf(stderr, ": Unrecognized VLDB version %d.\n", fromv); + exit(-1); } /* Sequentially read the database converting the entries as we go */ lseek(old, 0, L_SET); - read (old, ubik, 64); - readheader (old, fromv, &oldheader); + read(old, ubik, 64); + readheader(old, fromv, &oldheader); if (fromv == 1) { - dbsize = ntohl(oldheader.header1.vital_header.eofPtr); - fromv = ntohl(oldheader.header1.vital_header.vldbversion); - mhaddr = 0; + dbsize = ntohl(oldheader.header1.vital_header.eofPtr); + fromv = ntohl(oldheader.header1.vital_header.vldbversion); + mhaddr = 0; } else if (fromv == 2) { - dbsize = ntohl(oldheader.header2.vital_header.eofPtr); - fromv = ntohl(oldheader.header2.vital_header.vldbversion); - mhaddr = 0; + dbsize = ntohl(oldheader.header2.vital_header.eofPtr); + fromv = ntohl(oldheader.header2.vital_header.vldbversion); + mhaddr = 0; } else { - int pos; + int pos; - dbsize = ntohl(oldheader.header3.vital_header.eofPtr); - fromv = ntohl(oldheader.header3.vital_header.vldbversion); - mhaddr = ntohl(oldheader.header3.SIT); + dbsize = ntohl(oldheader.header3.vital_header.eofPtr); + fromv = ntohl(oldheader.header3.vital_header.vldbversion); + mhaddr = ntohl(oldheader.header3.SIT); - /* Read the multihomed extent blocks in */ - pos = oldpos; - read_mhentries(mhaddr, old); + /* Read the multihomed extent blocks in */ + pos = oldpos; + read_mhentries(mhaddr, old); - /* Position back to this after header */ - lseek(old, pos+64, L_SET); - oldpos = pos; + /* Position back to this after header */ + lseek(old, pos + 64, L_SET); + oldpos = pos; } if (showversion || dump) { - if (showversion) - fprintf(stdout, "%s has a version of %d\n", pathname, fromv); - if (dump) { - while (oldpos < dbsize) { - rc = readentry(old, fromv, &xvlentry); - if ((rc == 0) || (rc == EOF)) break; - printentry(fromv, &xvlentry); - } - } - exit(0); + if (showversion) + fprintf(stdout, "%s has a version of %d\n", pathname, fromv); + if (dump) { + while (oldpos < dbsize) { + rc = readentry(old, fromv, &xvlentry); + if ((rc == 0) || (rc == EOF)) + break; + printentry(fromv, &xvlentry); + } + } + exit(0); } - if (!fromvers) { /* not set */ - fromvers = fromv; + if (!fromvers) { /* not set */ + fromvers = fromv; } else if (fromvers != fromv) { - fprintf(stdout, "%s has a version of %d while the -fromversion specified was %d - aborting\n", - pathname, fromv, fromvers); + fprintf(stdout, + "%s has a version of %d while the -fromversion specified was %d - aborting\n", + pathname, fromv, fromvers); exit(0); } if ((fromvers < 1) || (fromvers > 4)) { - fprintf(stderr, pn); - fprintf(stderr,": VLDB version %d is not supported.\n",fromvers); - fprintf(stderr, pn); - fprintf(stderr, ": Only versions 1-4 are currently supported.\n"); - exit(-1); + fprintf(stderr, pn); + fprintf(stderr, ": VLDB version %d is not supported.\n", fromvers); + fprintf(stderr, pn); + fprintf(stderr, ": Only versions 1-4 are currently supported.\n"); + exit(-1); } if (!tovers) - tovers = fromvers + 1; - - if (tovers < 1 || tovers > 4 ) { - fprintf(stderr, pn); - fprintf(stderr,": VLDB version %d is not supported.\n",tovers); - fprintf(stderr, pn); - fprintf(stderr, ": Only versions 1 - 4 are currently supported.\n"); - exit(-1); + tovers = fromvers + 1; + + if (tovers < 1 || tovers > 4) { + fprintf(stderr, pn); + fprintf(stderr, ": VLDB version %d is not supported.\n", tovers); + fprintf(stderr, pn); + fprintf(stderr, ": Only versions 1 - 4 are currently supported.\n"); + exit(-1); } if (mhaddr && (tovers < 3)) { - fprintf(stderr, pn); - fprintf(stderr,": Cannot convert. VLDB contains multihome info.\n"); - exit(-1); + fprintf(stderr, pn); + fprintf(stderr, ": Cannot convert. VLDB contains multihome info.\n"); + exit(-1); } /* OK! let's get down to business... */ if (chdir(Parent(pathname))) { - perror (pn); + perror(pn); exit(-1); } - - new = open(tempname,O_WRONLY|O_CREAT|O_TRUNC,0600); + + new = open(tempname, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (new < 0) { - perror(pn); - exit(-1); + perror(pn); + exit(-1); } - + /* Write the UBIK data */ - w = write (new, ubik, 64); + w = write(new, ubik, 64); if (w != 64) { - printf("Write of ubik header failed %d; error %u\n", w, errno); - exit(1); + printf("Write of ubik header failed %d; error %u\n", w, errno); + exit(1); } /* Because we know that all the vldb entries are the same size and type we @@ -215,12 +223,14 @@ static handleit(as) * converting the vldb-- we'll probably have to chase down the various * linked lists in turn, doing lseeks and the like. */ - + convert_header(old, new, fromvers, tovers, &oldheader, &newheader); while (oldpos < dbsize) { - rc = readentry(old, fromvers, &xvlentry); - if ((rc == 0) || (rc == EOF)) break; - convert_vlentry(new, fromvers, tovers, &oldheader, &newheader, &xvlentry); + rc = readentry(old, fromvers, &xvlentry); + if ((rc == 0) || (rc == EOF)) + break; + convert_vlentry(new, fromvers, tovers, &oldheader, &newheader, + &xvlentry); } /* We have now finished sequentially reading and writing the database. @@ -236,66 +246,71 @@ static handleit(as) } close(new); - renamefile(tempname,pathname); + renamefile(tempname, pathname); sleep(5); exit(0); } -readheader(fd, version, addr) - int fd; - int version; - char *addr; +readheader(fd, version, addr) + int fd; + int version; + char *addr; { - int hdrsize, size=0; + int hdrsize, size = 0; oldpos = 0; if (version == 1) - hdrsize = sizeof(struct vlheader_1); - else - hdrsize = sizeof(struct vlheader_2); + hdrsize = sizeof(struct vlheader_1); + else + hdrsize = sizeof(struct vlheader_2); size = read(fd, addr, hdrsize); - if (size > 0) oldpos += size; + if (size > 0) + oldpos += size; return; } -readentry(fd, version, addr) - int fd; - int version; - char *addr; +readentry(fd, version, addr) + int fd; + int version; + char *addr; { int rc, rc1; struct vlentry_3 *vl3p = (struct vlentry_3 *)addr; int toread; - toread = ((version == 1) ? sizeof(struct vlentry_1) : sizeof(struct vlentry_2)); + toread = + ((version == + 1) ? sizeof(struct vlentry_1) : sizeof(struct vlentry_2)); rc = read(fd, addr, toread); if (rc != toread) - printf("Partial read of vlentry at pos %u: %d\n", oldpos, rc); - if (rc > 0) oldpos += rc; + printf("Partial read of vlentry at pos %u: %d\n", oldpos, rc); + if (rc > 0) + oldpos += rc; /* Read a mhblock entry if there is one */ if ((rc > 0) && (vl3p->flags == VLCONTBLOCK)) { - if (!mhaddr) /* Remember first mh block */ - mhaddr = oldpos - rc; - - rc1 = read(fd, &addr[rc], VL_ADDREXTBLK_SIZE-rc); - if (rc1 != VL_ADDREXTBLK_SIZE-rc) - printf("Partial read of mhblock at pos %u: %d\n", oldpos+rc, rc1); - if (rc1 > 0) { - oldpos += rc1; - rc += rc1; - } + if (!mhaddr) /* Remember first mh block */ + mhaddr = oldpos - rc; + + rc1 = read(fd, &addr[rc], VL_ADDREXTBLK_SIZE - rc); + if (rc1 != VL_ADDREXTBLK_SIZE - rc) + printf("Partial read of mhblock at pos %u: %d\n", oldpos + rc, + rc1); + if (rc1 > 0) { + oldpos += rc1; + rc += rc1; + } } return rc; } -printentry(version, addr) - int version; - char *addr; +printentry(version, addr) + int version; + char *addr; { struct vlentry_2 *vl2p = (struct vlentry_2 *)addr; struct vlentry_3 *vl3p = (struct vlentry_3 *)addr; @@ -303,42 +318,42 @@ printentry(version, addr) /* Don't print anything if the entry is a mh info block */ if (vl3p->flags == VLCONTBLOCK) { - return; + return; } if (version == 1 || version == 2) { - printf("%s\t%5d [%10d:%10d:%10d]%8X%8d\n", - vl2p->name, vl2p->spares3, + printf("%s\t%5d [%10d:%10d:%10d]%8X%8d\n", vl2p->name, vl2p->spares3, vl2p->volumeId[0], vl2p->volumeId[1], vl2p->volumeId[2], vl2p->flags, vl2p->LockAfsId); printf("\t%8d%8d%8d [%7d%7d%7d]%7d% [%4d%4d%4d%4d][%4d%4d%4d%4d]\n", - vl2p->LockTimestamp, vl2p->cloneId, vl2p->spares0, + vl2p->LockTimestamp, vl2p->cloneId, vl2p->spares0, vl2p->nextIdHash[0], vl2p->nextIdHash[1], vl2p->nextIdHash[2], - vl2p->nextNameHash, - vl2p->serverNumber[0], vl2p->serverNumber[1], - vl2p->serverNumber[2], vl2p->serverNumber[3], - vl2p->serverPartition[0], vl2p->serverPartition[1], - vl2p->serverPartition[2], vl2p->serverPartition[3]); - printf("\t[%4d%4d%4d%4d]\n", - vl2p->serverFlags[0], vl2p->serverFlags[1], - vl2p->serverFlags[2], vl2p->serverFlags[3]); - } else /* if (version >= 3) */ { - if (vl3p->flags == VLFREE) - return; + vl2p->nextNameHash, vl2p->serverNumber[0], + vl2p->serverNumber[1], vl2p->serverNumber[2], + vl2p->serverNumber[3], vl2p->serverPartition[0], + vl2p->serverPartition[1], vl2p->serverPartition[2], + vl2p->serverPartition[3]); + printf("\t[%4d%4d%4d%4d]\n", vl2p->serverFlags[0], + vl2p->serverFlags[1], vl2p->serverFlags[2], + vl2p->serverFlags[3]); + } else { /* if (version >= 3) */ + + if (vl3p->flags == VLFREE) + return; printf("%s\tPos=%d NextIdHash=[%d:%d:%d] NextNameHash=%d\n", - vl3p->name, - (oldpos - sizeof(struct vlentry_3)), + vl3p->name, (oldpos - sizeof(struct vlentry_3)), vl3p->nextIdHash[0], vl3p->nextIdHash[1], vl3p->nextIdHash[2], vl3p->nextNameHash); - printf("\tRW=%u RO=%u BK=%u CL=%u flags=0x%X lockBy=%d lockTime=%u\n", - vl3p->volumeId[0], vl3p->volumeId[1], vl3p->volumeId[2], vl3p->cloneId, - vl3p->flags, vl3p->LockAfsId, vl3p->LockTimestamp); - for (i=0; iserverNumber[i] & 0xff) != 0xff) { - printf("\tServer=%d Partition=%d flags=%X\n", - vl3p->serverNumber[i], vl3p->serverPartition[i], - vl3p->serverFlags[i]); - } + printf("\tRW=%u RO=%u BK=%u CL=%u flags=0x%X lockBy=%d lockTime=%u\n", + vl3p->volumeId[0], vl3p->volumeId[1], vl3p->volumeId[2], + vl3p->cloneId, vl3p->flags, vl3p->LockAfsId, + vl3p->LockTimestamp); + for (i = 0; i < OMAXNSERVERS; i++) { + if ((vl3p->serverNumber[i] & 0xff) != 0xff) { + printf("\tServer=%d Partition=%d flags=%X\n", + vl3p->serverNumber[i], vl3p->serverPartition[i], + vl3p->serverFlags[i]); + } } } return; @@ -352,101 +367,102 @@ struct extentaddr *base[VL_MAX_ADDREXTBLKS]; * If it's not good, then don't read the block in. */ read_mhentries(mh_addr, oldfd) - int oldfd; - afs_uint32 mh_addr; + int oldfd; + afs_uint32 mh_addr; { - afs_uint32 sit, a; - afs_int32 code; - int j; - - if (readmhentries) - return; - readmhentries = 1; - - /* Initialize base pointers */ - for (j=0; j < VL_MAX_ADDREXTBLKS; j++) - base[j] = 0; - - if (!mh_addr) - return; - - /* Check if the first extent block is beyond eof. If - * it is, it's not real. - */ - if (mh_addr > dbsize-VL_ADDREXTBLK_SIZE) - return; - - /* Now read the first mh extent block */ - code = lseek(oldfd, mh_addr+64, L_SET); - if (code < 0) { - perror("seek MH block"); - exit(1); - } - base[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); - if (!base[0]) { - perror("malloc1"); - exit(1); - } - code = read(oldfd, (char *)base[0], VL_ADDREXTBLK_SIZE); - if (code != VL_ADDREXTBLK_SIZE) { - perror("read MH block"); - free(base[0]); - base[0] = 0; - exit(1); - } - - /* Verify that this block is the right one */ - if (ntohl(base[0]->ex_flags) != VLCONTBLOCK) { /* check if flag is correct */ - free(base[0]); - base[0] = 0; - return; - } - - /* The first block contains pointers to the other extent blocks. - * Check to see if the pointers are good and read them in if they are. - */ - a = mh_addr; - for (j=1; j < VL_MAX_ADDREXTBLKS; j++) { - if (!base[0]->ex_contaddrs[j]) - continue; - - sit = ntohl(base[0]->ex_contaddrs[j]); - - /* Every time we allocate a new extent block, it is allocated after - * the previous ones. But it must be before the EOF. - */ - if ((sit < (a + VL_ADDREXTBLK_SIZE)) || (sit > dbsize - VL_ADDREXTBLK_SIZE)) { - continue; - } - - /* Read the extent block in */ - sit += 64; - code = lseek(oldfd, sit, L_SET); - if (code < 0) { - perror("seek MH block"); + afs_uint32 sit, a; + afs_int32 code; + int j; + + if (readmhentries) + return; + readmhentries = 1; + + /* Initialize base pointers */ + for (j = 0; j < VL_MAX_ADDREXTBLKS; j++) + base[j] = 0; + + if (!mh_addr) + return; + + /* Check if the first extent block is beyond eof. If + * it is, it's not real. + */ + if (mh_addr > dbsize - VL_ADDREXTBLK_SIZE) + return; + + /* Now read the first mh extent block */ + code = lseek(oldfd, mh_addr + 64, L_SET); + if (code < 0) { + perror("seek MH block"); exit(1); - } - base[j] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); - if (!base[j]) { - perror("malloc1"); + } + base[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); + if (!base[0]) { + perror("malloc1"); exit(1); - } - code = read(oldfd, (char *)base[j], VL_ADDREXTBLK_SIZE); - if (code != VL_ADDREXTBLK_SIZE) { - perror("read MH block"); + } + code = read(oldfd, (char *)base[0], VL_ADDREXTBLK_SIZE); + if (code != VL_ADDREXTBLK_SIZE) { + perror("read MH block"); + free(base[0]); + base[0] = 0; exit(1); - } - - /* Verify that this block knows its an extent block */ - if (ntohl(base[j]->ex_flags) != VLCONTBLOCK) { - free(base[j]); - base[j] = 0; - continue; - } - - /* The extent block passed our tests */ - a = ntohl(base[0]->ex_contaddrs[j]); - } + } + + /* Verify that this block is the right one */ + if (ntohl(base[0]->ex_flags) != VLCONTBLOCK) { /* check if flag is correct */ + free(base[0]); + base[0] = 0; + return; + } + + /* The first block contains pointers to the other extent blocks. + * Check to see if the pointers are good and read them in if they are. + */ + a = mh_addr; + for (j = 1; j < VL_MAX_ADDREXTBLKS; j++) { + if (!base[0]->ex_contaddrs[j]) + continue; + + sit = ntohl(base[0]->ex_contaddrs[j]); + + /* Every time we allocate a new extent block, it is allocated after + * the previous ones. But it must be before the EOF. + */ + if ((sit < (a + VL_ADDREXTBLK_SIZE)) + || (sit > dbsize - VL_ADDREXTBLK_SIZE)) { + continue; + } + + /* Read the extent block in */ + sit += 64; + code = lseek(oldfd, sit, L_SET); + if (code < 0) { + perror("seek MH block"); + exit(1); + } + base[j] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); + if (!base[j]) { + perror("malloc1"); + exit(1); + } + code = read(oldfd, (char *)base[j], VL_ADDREXTBLK_SIZE); + if (code != VL_ADDREXTBLK_SIZE) { + perror("read MH block"); + exit(1); + } + + /* Verify that this block knows its an extent block */ + if (ntohl(base[j]->ex_flags) != VLCONTBLOCK) { + free(base[j]); + base[j] = 0; + continue; + } + + /* The extent block passed our tests */ + a = ntohl(base[0]->ex_contaddrs[j]); + } } /* Follow the SIT pointer in the header (mhaddr) to the multihomed @@ -457,253 +473,272 @@ read_mhentries(mh_addr, oldfd) * Before this can be called, the routine read_mhentries must be called. */ convert_mhentries(oldfd, newfd, header, fromver, tover) - int oldfd, newfd; - struct vlheader_2 *header; - int fromver, tover; + int oldfd, newfd; + struct vlheader_2 *header; + int fromver, tover; { - afs_uint32 sit; - afs_int32 code; - int i, j, modified=0, w; - afs_uint32 raddr, addr; - struct extentaddr *exp; - int basei, index; - - /* Check if the header says the extent block exists. If - * it does, then read_mhentries should have read it in. - */ - if (mhaddr && !base[0]) { - printf("Fix Bad base extent block pointer\n"); - header->SIT = mhaddr = 0; - } else if (mhaddr && base[0]) { - - if ((ntohl(header->SIT) != mhaddr) && (tover == 4)) { - printf("Fix pointer to first base extent block. Was 0x%x, now 0x%x\n", - ntohl(header->SIT), mhaddr); - header->SIT = htonl(mhaddr); - } - - /* Check if the first block points to itself. If not, then fix it */ - if (ntohl(base[0]->ex_contaddrs[0]) != mhaddr) { - printf("Fix bad pointer in base extent block: Base 0\n"); - base[0]->ex_contaddrs[0] = htonl(mhaddr); - modified = 1; - } - - /* The first block contains pointers to the other extent blocks. - * Check to see if the pointers are good. - */ - for (j=1; j < VL_MAX_ADDREXTBLKS; j++) { - /* Check if the base extent block says the extent blocks exist. - * If it does, then read_mhentries should have read it in. + afs_uint32 sit; + afs_int32 code; + int i, j, modified = 0, w; + afs_uint32 raddr, addr; + struct extentaddr *exp; + int basei, index; + + /* Check if the header says the extent block exists. If + * it does, then read_mhentries should have read it in. + */ + if (mhaddr && !base[0]) { + printf("Fix Bad base extent block pointer\n"); + header->SIT = mhaddr = 0; + } else if (mhaddr && base[0]) { + + if ((ntohl(header->SIT) != mhaddr) && (tover == 4)) { + printf + ("Fix pointer to first base extent block. Was 0x%x, now 0x%x\n", + ntohl(header->SIT), mhaddr); + header->SIT = htonl(mhaddr); + } + + /* Check if the first block points to itself. If not, then fix it */ + if (ntohl(base[0]->ex_contaddrs[0]) != mhaddr) { + printf("Fix bad pointer in base extent block: Base 0\n"); + base[0]->ex_contaddrs[0] = htonl(mhaddr); + modified = 1; + } + + /* The first block contains pointers to the other extent blocks. + * Check to see if the pointers are good. */ - if (base[0]->ex_contaddrs[j] && !base[j]) { - printf("Fix bad pointer in base extent block: Base %d\n", j); - base[0]->ex_contaddrs[j] = 0; - modified = 1; + for (j = 1; j < VL_MAX_ADDREXTBLKS; j++) { + /* Check if the base extent block says the extent blocks exist. + * If it does, then read_mhentries should have read it in. + */ + if (base[0]->ex_contaddrs[j] && !base[j]) { + printf("Fix bad pointer in base extent block: Base %d\n", j); + base[0]->ex_contaddrs[j] = 0; + modified = 1; + } } - } - /* Now write out the base extent blocks if it changed */ - if (modified) { - code = lseek(newfd, mhaddr+64, L_SET); - if (code < 0) { - perror("seek MH Block"); - exit(1); + /* Now write out the base extent blocks if it changed */ + if (modified) { + code = lseek(newfd, mhaddr + 64, L_SET); + if (code < 0) { + perror("seek MH Block"); + exit(1); + } + w = write(newfd, (char *)base[0], VL_ADDREXTBLK_SIZE); + if (w != VL_ADDREXTBLK_SIZE) { + perror("write MH Block"); + exit(1); + } } - w = write(newfd, (char *)base[0], VL_ADDREXTBLK_SIZE); - if (w != VL_ADDREXTBLK_SIZE) { - perror("write MH Block"); - exit(1); + } + + /* If we are converting from version 4 to version 3, then + * translate any multihome ptrs in the IpMappedAddr array + * to true IP addresses. + */ + if ((fromver == 4) && (tover == 3)) { + /* Step through the fileserver addresses in the VLDB header + * and convert the pointers back to IP addresses. + */ + for (i = 0; i < 254; i++) { + addr = ntohl(header->IpMappedAddr[i]); + if (addr && ((addr & 0xff000000) == 0xff000000)) { + basei = (addr >> 16) & 0xff; + index = addr & 0xffff; + + if ((basei >= VL_ADDREXTBLK_SIZE) || !base[basei]) { + fprintf(stderr, + "Warning: mh entry %d has no IP address; ignored!!\n", + i); + header->IpMappedAddr[i] = 0; + continue; + } + exp = &base[basei][index]; + + /* For now return the first ip address back */ + for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) { + if (exp->ex_addrs[j]) { + raddr = ntohl(exp->ex_addrs[j]); + break; + } + } + if (j >= VL_MAXIPADDRS_PERMH) { + fprintf(stderr, + "Warning: mh entry %d has no ip address; ignored!!\n", + i); + raddr = 0; + } else { + printf + ("Multi-homed addr: converting to single ip address %d.%d.%d.%d\n", + (raddr >> 24 & 0xff), (raddr >> 16 & 0xff), + (raddr >> 8 & 0xff), (raddr & 0xff)); + } + header->IpMappedAddr[i] = htonl(raddr); + } } - } - } - - /* If we are converting from version 4 to version 3, then - * translate any multihome ptrs in the IpMappedAddr array - * to true IP addresses. - */ - if ((fromver == 4) && (tover == 3)) { - /* Step through the fileserver addresses in the VLDB header - * and convert the pointers back to IP addresses. - */ - for (i=0; i<254; i++) { - addr = ntohl(header->IpMappedAddr[i]); - if (addr && ((addr & 0xff000000) == 0xff000000)) { - basei = (addr >> 16) & 0xff; - index = addr & 0xffff; - - if ((basei >= VL_ADDREXTBLK_SIZE) || !base[basei]) { - fprintf(stderr, "Warning: mh entry %d has no IP address; ignored!!\n", i); - header->IpMappedAddr[i] = 0; - continue; - } - exp = &base[basei][index]; - - /* For now return the first ip address back */ - for (j=0; j < VL_MAXIPADDRS_PERMH; j++) { - if (exp->ex_addrs[j]) { - raddr = ntohl(exp->ex_addrs[j]); - break; - } - } - if (j >= VL_MAXIPADDRS_PERMH) { - fprintf(stderr, "Warning: mh entry %d has no ip address; ignored!!\n", i); - raddr = 0; - } else { - printf("Multi-homed addr: converting to single ip address %d.%d.%d.%d\n", - (raddr>>24 & 0xff), (raddr>>16 & 0xff), - (raddr>>8 & 0xff), (raddr & 0xff)); - } - header->IpMappedAddr[i] = htonl(raddr); + header->SIT = mhaddr = 0; /* mhinfo block has been removed */ + + /* Now step through the hash tables in header updating them. + * Because we removed the mh info blocks and some entries they + * point to may have changed position. + * The VolnameHash + */ + for (i = 0; i < 8191; i++) { + header->VolnameHash[i] = Conv4to3(header->VolnameHash[i]); } - } - header->SIT = mhaddr = 0; /* mhinfo block has been removed */ - - /* Now step through the hash tables in header updating them. - * Because we removed the mh info blocks and some entries they - * point to may have changed position. - * The VolnameHash - */ - for (i=0; i<8191; i++) { - header->VolnameHash[i] = Conv4to3(header->VolnameHash[i]); - } - /* The VolidHash */ - for (i=0; i<3; i++) { - for (j=0; j<8191; j++) { - header->VolidHash[i][j] = Conv4to3(header->VolidHash[i][j]); + /* The VolidHash */ + for (i = 0; i < 3; i++) { + for (j = 0; j < 8191; j++) { + header->VolidHash[i][j] = Conv4to3(header->VolidHash[i][j]); + } } - } - /* Update eofptr to take into account the removal of the mhinfo blocks */ - header->vital_header.eofPtr = htonl(Conv4to3(dbsize)); - } + /* Update eofptr to take into account the removal of the mhinfo blocks */ + header->vital_header.eofPtr = htonl(Conv4to3(dbsize)); + } } convert_header(ofd, fd, fromv, tov, fromaddr, toaddr) - int ofd, fd, fromv, tov; - char *fromaddr, *toaddr; + int ofd, fd, fromv, tov; + char *fromaddr, *toaddr; { - struct vlheader_1 *tvp1; - struct vlheader_2 *tvp2; - int i,j,diff, w; - - if (fromv == 1) { - if (tov == 1) { - memcpy(toaddr, fromaddr, sizeof(struct vlheader_1)); - tvp1 = (struct vlheader_1 *) toaddr; - - w = write (fd, tvp1, sizeof(struct vlheader_1)); - if (w != sizeof(struct vlheader_1)) { - printf("Write of header failed %d; error %u\n", w, errno); - exit(1); - } + struct vlheader_1 *tvp1; + struct vlheader_2 *tvp2; + int i, j, diff, w; - /* for garbage-collecting... */ - for (i=0;i<31; i++) - tvp1->IpMappedAddr[i] = 0; - - } else if (tov == 2 || tov == 3) { - tvp1 = (struct vlheader_1 *) fromaddr; - tvp2 = (struct vlheader_2 *) toaddr; - memset(tvp2, 0, sizeof(struct vlheader_2)); - tvp2->vital_header.vldbversion = htonl(tov); - tvp2->vital_header.headersize = htonl(sizeof(struct vlheader_2)); - diff = ntohl(tvp2->vital_header.headersize) - - ntohl(tvp1->vital_header.headersize); - if (ntohl(tvp1->vital_header.freePtr)) - tvp2->vital_header.freePtr = htonl(ntohl(tvp1->vital_header.freePtr) + diff); - if (ntohl(tvp1->vital_header.eofPtr)) - tvp2->vital_header.eofPtr = htonl(ntohl(tvp1->vital_header.eofPtr) + diff); - tvp2->vital_header.allocs = tvp1->vital_header.allocs; - tvp2->vital_header.frees = tvp1->vital_header.frees; - tvp2->vital_header.MaxVolumeId = tvp1->vital_header.MaxVolumeId; - for (i=0;i<3;i++) - tvp2->vital_header.totalEntries[i] = tvp1->vital_header.totalEntries[i]; - - for (i=0;i<31;i++) - tvp2->IpMappedAddr[i] = tvp1->IpMappedAddr[i]; - - for (i=0;i<8191;i++) { - if (ntohl(tvp1->VolnameHash[i])) - tvp2->VolnameHash[i] = htonl(ntohl(tvp1->VolnameHash[i]) + diff); - } + if (fromv == 1) { + if (tov == 1) { + memcpy(toaddr, fromaddr, sizeof(struct vlheader_1)); + tvp1 = (struct vlheader_1 *)toaddr; + + w = write(fd, tvp1, sizeof(struct vlheader_1)); + if (w != sizeof(struct vlheader_1)) { + printf("Write of header failed %d; error %u\n", w, errno); + exit(1); + } - for (i=0;i<3;i++) { - for (j=0;j<8191;j++) { - if (ntohl(tvp1->VolidHash[i][j])) - tvp2->VolidHash[i][j] = htonl(ntohl(tvp1->VolidHash[i][j]) + diff); - } - } - - w = write (fd, tvp2, sizeof(struct vlheader_2)); - if (w != sizeof(struct vlheader_2)) { - printf("Write of header failed %d; error %u\n", w, errno); - exit(1); - } - - /* for garbage-collecting... */ - for (i=0;i<31; i++) - tvp2->IpMappedAddr[i] = 0; - } else - return EINVAL; - } else if (fromv == 2 || fromv == 3 || fromv == 4) { - if (tov == 2 || tov == 3 || tov == 4) { - memcpy(toaddr, fromaddr, sizeof(struct vlheader_2)); - tvp2 = (struct vlheader_2 *) toaddr; - tvp2->vital_header.vldbversion = htonl(tov); - w = write (fd, tvp2, sizeof(struct vlheader_2)); - if (w != sizeof(struct vlheader_2)) { - printf("Write of header failed %d; error %u\n", w, errno); - exit(1); - } + /* for garbage-collecting... */ + for (i = 0; i < 31; i++) + tvp1->IpMappedAddr[i] = 0; + + } else if (tov == 2 || tov == 3) { + tvp1 = (struct vlheader_1 *)fromaddr; + tvp2 = (struct vlheader_2 *)toaddr; + memset(tvp2, 0, sizeof(struct vlheader_2)); + tvp2->vital_header.vldbversion = htonl(tov); + tvp2->vital_header.headersize = htonl(sizeof(struct vlheader_2)); + diff = + ntohl(tvp2->vital_header.headersize) - + ntohl(tvp1->vital_header.headersize); + if (ntohl(tvp1->vital_header.freePtr)) + tvp2->vital_header.freePtr = + htonl(ntohl(tvp1->vital_header.freePtr) + diff); + if (ntohl(tvp1->vital_header.eofPtr)) + tvp2->vital_header.eofPtr = + htonl(ntohl(tvp1->vital_header.eofPtr) + diff); + tvp2->vital_header.allocs = tvp1->vital_header.allocs; + tvp2->vital_header.frees = tvp1->vital_header.frees; + tvp2->vital_header.MaxVolumeId = tvp1->vital_header.MaxVolumeId; + for (i = 0; i < 3; i++) + tvp2->vital_header.totalEntries[i] = + tvp1->vital_header.totalEntries[i]; + + for (i = 0; i < 31; i++) + tvp2->IpMappedAddr[i] = tvp1->IpMappedAddr[i]; + + for (i = 0; i < 8191; i++) { + if (ntohl(tvp1->VolnameHash[i])) + tvp2->VolnameHash[i] = + htonl(ntohl(tvp1->VolnameHash[i]) + diff); + } - } else if (tov == 1) { - tvp2 = (struct vlheader_2 *) fromaddr; - tvp1 = (struct vlheader_1 *) toaddr; - memset(tvp1, 0, sizeof(struct vlheader_1)); - tvp1->vital_header.vldbversion = htonl(1); - tvp1->vital_header.headersize = htonl(sizeof(struct vlheader_1)); - diff = ntohl(tvp1->vital_header.headersize) - ntohl(tvp2->vital_header.headersize); - if (ntohl(tvp2->vital_header.freePtr)) - tvp1->vital_header.freePtr = htonl(ntohl(tvp2->vital_header.freePtr) + diff); - if (ntohl(tvp2->vital_header.eofPtr)) - tvp1->vital_header.eofPtr = htonl(ntohl(tvp2->vital_header.eofPtr) + diff); - tvp1->vital_header.allocs = tvp2->vital_header.allocs; - tvp1->vital_header.frees = tvp2->vital_header.frees; - tvp1->vital_header.MaxVolumeId = tvp2->vital_header.MaxVolumeId; - for (i=0;i<3;i++) - tvp1->vital_header.totalEntries[i] = tvp2->vital_header.totalEntries[i]; - - for (i=0;i<31;i++) - tvp1->IpMappedAddr[i] = tvp2->IpMappedAddr[i]; - - for (i=0;i<8191;i++) { - if (ntohl(tvp2->VolnameHash[i])) - tvp1->VolnameHash[i] = htonl(ntohl(tvp2->VolnameHash[i]) + diff); - } + for (i = 0; i < 3; i++) { + for (j = 0; j < 8191; j++) { + if (ntohl(tvp1->VolidHash[i][j])) + tvp2->VolidHash[i][j] = + htonl(ntohl(tvp1->VolidHash[i][j]) + diff); + } + } - for (i=0;i<3;i++) { - for (j=0;j<8191;j++) { - if (ntohl(tvp2->VolidHash[i][j])) - tvp1->VolidHash[i][j] = htonl(ntohl(tvp2->VolidHash[i][j]) + diff); - } - } + w = write(fd, tvp2, sizeof(struct vlheader_2)); + if (w != sizeof(struct vlheader_2)) { + printf("Write of header failed %d; error %u\n", w, errno); + exit(1); + } - w = write (fd, tvp1, sizeof(struct vlheader_1)); - if (w != sizeof(struct vlheader_2)) { - printf("Write of header failed %d; error %u\n", w, errno); - exit(1); - } - - /* for garbage-collecting... */ - for (i=0;i<31; i++) - tvp1->IpMappedAddr[i] = 0; - } else - return EINVAL; - } else - return EINVAL; - return 0; + /* for garbage-collecting... */ + for (i = 0; i < 31; i++) + tvp2->IpMappedAddr[i] = 0; + } else + return EINVAL; + } else if (fromv == 2 || fromv == 3 || fromv == 4) { + if (tov == 2 || tov == 3 || tov == 4) { + memcpy(toaddr, fromaddr, sizeof(struct vlheader_2)); + tvp2 = (struct vlheader_2 *)toaddr; + tvp2->vital_header.vldbversion = htonl(tov); + w = write(fd, tvp2, sizeof(struct vlheader_2)); + if (w != sizeof(struct vlheader_2)) { + printf("Write of header failed %d; error %u\n", w, errno); + exit(1); + } + + } else if (tov == 1) { + tvp2 = (struct vlheader_2 *)fromaddr; + tvp1 = (struct vlheader_1 *)toaddr; + memset(tvp1, 0, sizeof(struct vlheader_1)); + tvp1->vital_header.vldbversion = htonl(1); + tvp1->vital_header.headersize = htonl(sizeof(struct vlheader_1)); + diff = + ntohl(tvp1->vital_header.headersize) - + ntohl(tvp2->vital_header.headersize); + if (ntohl(tvp2->vital_header.freePtr)) + tvp1->vital_header.freePtr = + htonl(ntohl(tvp2->vital_header.freePtr) + diff); + if (ntohl(tvp2->vital_header.eofPtr)) + tvp1->vital_header.eofPtr = + htonl(ntohl(tvp2->vital_header.eofPtr) + diff); + tvp1->vital_header.allocs = tvp2->vital_header.allocs; + tvp1->vital_header.frees = tvp2->vital_header.frees; + tvp1->vital_header.MaxVolumeId = tvp2->vital_header.MaxVolumeId; + for (i = 0; i < 3; i++) + tvp1->vital_header.totalEntries[i] = + tvp2->vital_header.totalEntries[i]; + + for (i = 0; i < 31; i++) + tvp1->IpMappedAddr[i] = tvp2->IpMappedAddr[i]; + + for (i = 0; i < 8191; i++) { + if (ntohl(tvp2->VolnameHash[i])) + tvp1->VolnameHash[i] = + htonl(ntohl(tvp2->VolnameHash[i]) + diff); + } + + for (i = 0; i < 3; i++) { + for (j = 0; j < 8191; j++) { + if (ntohl(tvp2->VolidHash[i][j])) + tvp1->VolidHash[i][j] = + htonl(ntohl(tvp2->VolidHash[i][j]) + diff); + } + } + + w = write(fd, tvp1, sizeof(struct vlheader_1)); + if (w != sizeof(struct vlheader_2)) { + printf("Write of header failed %d; error %u\n", w, errno); + exit(1); + } + + /* for garbage-collecting... */ + for (i = 0; i < 31; i++) + tvp1->IpMappedAddr[i] = 0; + } else + return EINVAL; + } else + return EINVAL; + return 0; } @@ -716,22 +751,24 @@ convert_header(ofd, fd, fromv, tov, fromaddr, toaddr) * * Before this can be called, the routine read_mhentries must be called. */ -static afs_int32 Conv4to3(addr) - afs_int32 addr; +static afs_int32 +Conv4to3(addr) + afs_int32 addr; { - afs_int32 raddr; - int i; + afs_int32 raddr; + int i; - if (!base[0] || !addr) - return(addr); + if (!base[0] || !addr) + return (addr); - raddr = addr; - for (i=0; iex_contaddrs[i] && (addr > base[0]->ex_contaddrs[i])) - raddr -= VL_ADDREXTBLK_SIZE; - } + raddr = addr; + for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) { + if (base[i] && base[0]->ex_contaddrs[i] + && (addr > base[0]->ex_contaddrs[i])) + raddr -= VL_ADDREXTBLK_SIZE; + } - return(raddr); + return (raddr); } /* this only works because the vlheader struct is essentially the same @@ -741,9 +778,9 @@ static afs_int32 Conv4to3(addr) static int convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentryp) - int new, fromvers, tovers; - struct vlheader_1 *oldheader, *newheader; /* close enough */ - struct vlentry_1 *vlentryp; /* 1 and 2 are identical */ + int new, fromvers, tovers; + struct vlheader_1 *oldheader, *newheader; /* close enough */ + struct vlentry_1 *vlentryp; /* 1 and 2 are identical */ { int diff, i, s, w; struct vlentry_3 *vl3p = (struct vlentry_3 *)vlentryp; @@ -753,14 +790,15 @@ convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentryp) * Otherwise, don't keep it (version 3 and earlier don't have them). */ if (vl3p->flags == VLCONTBLOCK) { - if (tovers >= 4) { - w = write (new, vlentryp, VL_ADDREXTBLK_SIZE); - if (w != VL_ADDREXTBLK_SIZE) { - printf("Write of mh info block failed %d; error %u\n", w, errno); - exit(1); - } - } - return 0; + if (tovers >= 4) { + w = write(new, vlentryp, VL_ADDREXTBLK_SIZE); + if (w != VL_ADDREXTBLK_SIZE) { + printf("Write of mh info block failed %d; error %u\n", w, + errno); + exit(1); + } + } + return 0; } if (fromvers == 2 && tovers == 3) { @@ -772,7 +810,7 @@ convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentryp) vl.flags = vlentryp->flags; vl.LockAfsId = vlentryp->LockAfsId; vl.LockTimestamp = vlentryp->LockTimestamp; - vl.cloneId = vlentryp->cloneId; + vl.cloneId = vlentryp->cloneId; vl.nextIdHash[0] = vlentryp->nextIdHash[0]; vl.nextIdHash[1] = vlentryp->nextIdHash[1]; vl.nextIdHash[2] = vlentryp->nextIdHash[2]; @@ -783,28 +821,29 @@ convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentryp) vl.serverPartition[i] = vlentryp->serverPartition[i]; vl.serverFlags[i] = vlentryp->serverFlags[i]; } - for (;i < 13; i++) - vl.serverNumber[i] = vl.serverPartition[i] = vl.serverFlags[i] = BADSERVERID; - w = write (new, &vl, sizeof(struct vlentry_3)); + for (; i < 13; i++) + vl.serverNumber[i] = vl.serverPartition[i] = vl.serverFlags[i] = + BADSERVERID; + w = write(new, &vl, sizeof(struct vlentry_3)); if (w != sizeof(struct vlentry_3)) { - printf("Write of entry failed %d; error %u\n", w, errno); - exit(1); + printf("Write of entry failed %d; error %u\n", w, errno); + exit(1); } return 0; - } else if (fromvers == 3 && tovers == 2) { + } else if (fromvers == 3 && tovers == 2) { struct vlentry_2 vl; - struct vlentry_3 *xnvlentry = (struct vlentry_3 *) vlentryp; + struct vlentry_3 *xnvlentry = (struct vlentry_3 *)vlentryp; - memset((char *)&vl, 0, sizeof (struct vlentry_2)); + memset((char *)&vl, 0, sizeof(struct vlentry_2)); vl.volumeId[0] = xnvlentry->volumeId[0]; vl.volumeId[1] = xnvlentry->volumeId[1]; vl.volumeId[2] = xnvlentry->volumeId[2]; vl.flags = xnvlentry->flags; vl.LockAfsId = xnvlentry->LockAfsId; vl.LockTimestamp = xnvlentry->LockTimestamp; - vl.cloneId = xnvlentry->cloneId; - for (i=0;i<3;i++) { + vl.cloneId = xnvlentry->cloneId; + for (i = 0; i < 3; i++) { if (ntohl(xnvlentry->nextIdHash[i])) vl.nextIdHash[i] = xnvlentry->nextIdHash[i]; } @@ -816,32 +855,36 @@ convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentryp) vl.serverPartition[i] = xnvlentry->serverPartition[i]; vl.serverFlags[i] = xnvlentry->serverFlags[i]; } - w = write (new, &vl, sizeof(struct vlentry_2)); + w = write(new, &vl, sizeof(struct vlentry_2)); if (w != sizeof(struct vlentry_2)) { - printf("Write of entry failed %d; error %u\n", w, errno); - exit(1); + printf("Write of entry failed %d; error %u\n", w, errno); + exit(1); } return 0; - } else if (fromvers == 3 && tovers == 1) { + } else if (fromvers == 3 && tovers == 1) { struct vlentry_1 vl; - struct vlentry_3 *xnvlentry = (struct vlentry_3 *) vlentryp; - - diff = (tovers == 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)) - - (fromvers == 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)); - memset((char *)&vl, 0, sizeof (struct vlentry_1)); + struct vlentry_3 *xnvlentry = (struct vlentry_3 *)vlentryp; + + diff = + (tovers == + 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)) + - (fromvers == + 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)); + memset((char *)&vl, 0, sizeof(struct vlentry_1)); vl.volumeId[0] = xnvlentry->volumeId[0]; vl.volumeId[1] = xnvlentry->volumeId[1]; vl.volumeId[2] = xnvlentry->volumeId[2]; vl.flags = xnvlentry->flags; vl.LockAfsId = xnvlentry->LockAfsId; vl.LockTimestamp = xnvlentry->LockTimestamp; - vl.cloneId = xnvlentry->cloneId; - for (i=0;i<3;i++) { + vl.cloneId = xnvlentry->cloneId; + for (i = 0; i < 3; i++) { if (ntohl(xnvlentry->nextIdHash[i])) - vl.nextIdHash[i] = htonl(ntohl(xnvlentry->nextIdHash[i]) + diff); + vl.nextIdHash[i] = + htonl(ntohl(xnvlentry->nextIdHash[i]) + diff); } if (ntohl(xnvlentry->nextNameHash)) - vl.nextNameHash = htonl(ntohl(xnvlentry->nextNameHash) + diff); + vl.nextNameHash = htonl(ntohl(xnvlentry->nextNameHash) + diff); memcpy(vl.name, xnvlentry->name, 65); for (i = 0; i < 8; i++) { @@ -849,92 +892,96 @@ convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentryp) vl.serverPartition[i] = xnvlentry->serverPartition[i]; vl.serverFlags[i] = xnvlentry->serverFlags[i]; } - for (i=0;i<8;i++) { + for (i = 0; i < 8; i++) { s = xnvlentry->serverNumber[i]; if (s != 255) { - if (s > MaxServers[tovers-1]) { - fprintf(stderr, "%s: Too Many Servers (%d) for this version!\n",pn,s+1); + if (s > MaxServers[tovers - 1]) { + fprintf(stderr, + "%s: Too Many Servers (%d) for this version!\n", + pn, s + 1); exit(-1); } else newheader->IpMappedAddr[s] = oldheader->IpMappedAddr[s]; } } - w = write (new, &vl, sizeof(struct vlentry_1)); + w = write(new, &vl, sizeof(struct vlentry_1)); if (w != sizeof(struct vlentry_1)) { - printf("Write of entry failed %d; error %u\n", w, errno); - exit(1); + printf("Write of entry failed %d; error %u\n", w, errno); + exit(1); } return 0; - } else if (fromvers == 4 && tovers == 3) { + } else if (fromvers == 4 && tovers == 3) { struct vlentry_3 vl; /* We are converting from version 4 to 3. In this conversion, mh info * blocks go away and all vlentries after them move up in the vldb file. * When this happens, the linked list pointers need to be updated. */ memcpy(&vl, vlentryp, sizeof(vl)); - for (i=0; i<3; i++) { - vl.nextIdHash[i] = Conv4to3(vl.nextIdHash[i]); + for (i = 0; i < 3; i++) { + vl.nextIdHash[i] = Conv4to3(vl.nextIdHash[i]); } vl.nextNameHash = Conv4to3(vl.nextNameHash); - w = write (new, &vl, sizeof(vl)); + w = write(new, &vl, sizeof(vl)); if (w != sizeof(vl)) { - printf("Write of entry failed %d; error %u\n", w, errno); - exit(1); + printf("Write of entry failed %d; error %u\n", w, errno); + exit(1); } return 0; } if (tovers == 1) { - w = write (new, vlentryp, sizeof(struct vlentry_1)); - if (w != sizeof(struct vlentry_1)) { - printf("Write of entry failed %d; error %u\n", w, errno); - exit(1); - } + w = write(new, vlentryp, sizeof(struct vlentry_1)); + if (w != sizeof(struct vlentry_1)) { + printf("Write of entry failed %d; error %u\n", w, errno); + exit(1); + } } else if (tovers == 2) { - w = write (new, vlentryp, sizeof(struct vlentry_2)); - if (w != sizeof(struct vlentry_2)) { - printf("Write of entry failed %d; error %u\n", w, errno); - exit(1); - } + w = write(new, vlentryp, sizeof(struct vlentry_2)); + if (w != sizeof(struct vlentry_2)) { + printf("Write of entry failed %d; error %u\n", w, errno); + exit(1); + } } else if (tovers == 3 || tovers == 4) { - w = write (new, vlentryp, sizeof(struct vlentry_3)); - if (w != sizeof(struct vlentry_3)) { - printf("Write of entry failed %d; error %u\n", w, errno); - exit(1); - } + w = write(new, vlentryp, sizeof(struct vlentry_3)); + if (w != sizeof(struct vlentry_3)) { + printf("Write of entry failed %d; error %u\n", w, errno); + exit(1); + } } else { - perror(pn); - fprintf(stderr, "Skipping vlentry write - db corrupted - bad toversion %d\n", - tovers); + perror(pn); + fprintf(stderr, + "Skipping vlentry write - db corrupted - bad toversion %d\n", + tovers); } - - return; + + return; } static int rewrite_header(new, tovers, newheader) - int new, tovers; - char *newheader; + int new, tovers; + char *newheader; { int pos, w, towrite; - pos = lseek (new, 64, L_SET); /* leave room for ubik */ + pos = lseek(new, 64, L_SET); /* leave room for ubik */ if (pos == -1) { perror(pn); - fprintf(stderr, "%s: no garbage colection\n",pn); + fprintf(stderr, "%s: no garbage colection\n", pn); return; } else if (pos != 64) { - fprintf(stderr,"%s: Can't rewind: no garbage collection\n",pn); + fprintf(stderr, "%s: Can't rewind: no garbage collection\n", pn); return; } - towrite = ((tovers == 1) ? sizeof(struct vlheader_1) : - sizeof(struct vlheader_2)); - w = write (new, newheader, towrite); + towrite = + ((tovers == + 1) ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)); + w = write(new, newheader, towrite); if (w != towrite) { - printf("Write of entry failed %d; error %u\n", w, errno); - exit(1); + printf("Write of entry failed %d; error %u\n", w, errno); + exit(1); } return; @@ -944,21 +991,24 @@ rewrite_header(new, tovers, newheader) #include "AFS_component_version_number.c" main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; { register struct cmd_syndesc *ts; afs_int32 code; - + ts = cmd_CreateSyntax("initcmd", handleit, 0, "optional"); cmd_AddParm(ts, "-to", CMD_SINGLE, CMD_OPTIONAL, "goal version"); cmd_AddParm(ts, "-from", CMD_SINGLE, CMD_OPTIONAL, "current version"); cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "pathname"); - cmd_AddParm(ts, "-showversion", CMD_FLAG, CMD_OPTIONAL, "Just display version of current vldb"); - cmd_AddParm(ts, "-dumpvldb", CMD_FLAG, CMD_OPTIONAL, "display all vldb entries"); + cmd_AddParm(ts, "-showversion", CMD_FLAG, CMD_OPTIONAL, + "Just display version of current vldb"); + cmd_AddParm(ts, "-dumpvldb", CMD_FLAG, CMD_OPTIONAL, + "display all vldb entries"); #ifdef DEBUG - cmd_AddParm(ts, "-noGC", CMD_FLAG, CMD_OPTIONAL, "Don't do garbage collection"); + cmd_AddParm(ts, "-noGC", CMD_FLAG, CMD_OPTIONAL, + "Don't do garbage collection"); #endif /* DEBUG */ dbPath = AFSDIR_SERVER_VLDB_FILEPATH; diff --git a/src/vlserver/cnvldb.h b/src/vlserver/cnvldb.h index 5aef6cb07..21ff9091f 100644 --- a/src/vlserver/cnvldb.h +++ b/src/vlserver/cnvldb.h @@ -9,123 +9,104 @@ /* VLDB structures for VLDB version 1. */ struct vital_vlheader_1 { - afs_int32 vldbversion; - afs_int32 headersize; - afs_int32 freePtr; - afs_int32 eofPtr; - afs_int32 allocs; - afs_int32 frees; - afs_int32 MaxVolumeId; - afs_int32 totalEntries[3]; + afs_int32 vldbversion; + afs_int32 headersize; + afs_int32 freePtr; + afs_int32 eofPtr; + afs_int32 allocs; + afs_int32 frees; + afs_int32 MaxVolumeId; + afs_int32 totalEntries[3]; }; -typedef struct vital_vlheader_1 vital_vlheader1; +typedef struct vital_vlheader_1 vital_vlheader1; struct vlheader_1 { - vital_vlheader1 vital_header; - afs_int32 IpMappedAddr[31]; - afs_int32 VolnameHash[8191]; - afs_int32 VolidHash[3][8191]; + vital_vlheader1 vital_header; + afs_int32 IpMappedAddr[31]; + afs_int32 VolnameHash[8191]; + afs_int32 VolidHash[3][8191]; }; struct vlentry_1 { - afs_int32 volumeId[3]; - afs_int32 flags; - afs_int32 LockAfsId; - afs_int32 LockTimestamp; - afs_int32 cloneId; - afs_int32 spares0; - afs_int32 nextIdHash[3]; - afs_int32 nextNameHash; - afs_int32 spares1[2]; - char name[65]; - char spares3; - unsigned char serverNumber[8]; - unsigned char serverPartition[8]; - unsigned char serverFlags[8]; - char spares4; - char spares2[1]; + afs_int32 volumeId[3]; + afs_int32 flags; + afs_int32 LockAfsId; + afs_int32 LockTimestamp; + afs_int32 cloneId; + afs_int32 spares0; + afs_int32 nextIdHash[3]; + afs_int32 nextNameHash; + afs_int32 spares1[2]; + char name[65]; + char spares3; + unsigned char serverNumber[8]; + unsigned char serverPartition[8]; + unsigned char serverFlags[8]; + char spares4; + char spares2[1]; }; /* VLDB structures for VLDB version 2. */ -typedef struct vital_vlheader_1 vital_vlheader2; +typedef struct vital_vlheader_1 vital_vlheader2; struct vlheader_2 { - vital_vlheader2 vital_header; - afs_int32 IpMappedAddr[255]; /* == 0..254 */ - afs_int32 VolnameHash[8191]; - afs_int32 VolidHash[3][8191]; - afs_int32 SIT; + vital_vlheader2 vital_header; + afs_int32 IpMappedAddr[255]; /* == 0..254 */ + afs_int32 VolnameHash[8191]; + afs_int32 VolidHash[3][8191]; + afs_int32 SIT; }; struct vlentry_2 { - afs_int32 volumeId[3]; - afs_int32 flags; - afs_int32 LockAfsId; - afs_int32 LockTimestamp; - afs_int32 cloneId; - afs_int32 spares0; - afs_int32 nextIdHash[3]; - afs_int32 nextNameHash; - afs_int32 spares1[2]; - char name[65]; - char spares3; - unsigned char serverNumber[8]; - unsigned char serverPartition[8]; - unsigned char serverFlags[8]; - char spares4; - char spares2[1]; + afs_int32 volumeId[3]; + afs_int32 flags; + afs_int32 LockAfsId; + afs_int32 LockTimestamp; + afs_int32 cloneId; + afs_int32 spares0; + afs_int32 nextIdHash[3]; + afs_int32 nextNameHash; + afs_int32 spares1[2]; + char name[65]; + char spares3; + unsigned char serverNumber[8]; + unsigned char serverPartition[8]; + unsigned char serverFlags[8]; + char spares4; + char spares2[1]; }; -typedef struct vital_vlheader_1 vital_vlheader3; +typedef struct vital_vlheader_1 vital_vlheader3; struct vlheader_3 { - vital_vlheader3 vital_header; - afs_int32 IpMappedAddr[255]; /* == 0..254 */ - afs_int32 VolnameHash[8191]; - afs_int32 VolidHash[3][8191]; - afs_int32 SIT; + vital_vlheader3 vital_header; + afs_int32 IpMappedAddr[255]; /* == 0..254 */ + afs_int32 VolnameHash[8191]; + afs_int32 VolidHash[3][8191]; + afs_int32 SIT; }; struct vlentry_3 { - afs_int32 volumeId[3]; - afs_int32 flags; - afs_int32 LockAfsId; - afs_int32 LockTimestamp; - afs_int32 cloneId; - afs_int32 nextIdHash[3]; - afs_int32 nextNameHash; - char name[65]; + afs_int32 volumeId[3]; + afs_int32 flags; + afs_int32 LockAfsId; + afs_int32 LockTimestamp; + afs_int32 cloneId; + afs_int32 nextIdHash[3]; + afs_int32 nextNameHash; + char name[65]; #define MAXSERVERS 13 - unsigned char serverNumber[MAXSERVERS]; - unsigned char serverPartition[MAXSERVERS]; - unsigned char serverFlags[MAXSERVERS]; + unsigned char serverNumber[MAXSERVERS]; + unsigned char serverPartition[MAXSERVERS]; + unsigned char serverFlags[MAXSERVERS]; #ifdef obsolete_vldb_fields - afs_int32 spares0; /* AssociatedChain */ - afs_int32 spares1[0]; - afs_int32 spares1[1]; - char spares3; /* volumeType */ - char spares4; /* RefCount */ - char spares2[1]; + afs_int32 spares0; /* AssociatedChain */ + afs_int32 spares1[0]; + afs_int32 spares1[1]; + char spares3; /* volumeType */ + char spares4; /* RefCount */ + char spares2[1]; #endif }; - - - - - - - - - - - - - - - - - - - diff --git a/src/vlserver/sascnvldb.c b/src/vlserver/sascnvldb.c index 0c73c78f6..bd0d04bee 100644 --- a/src/vlserver/sascnvldb.c +++ b/src/vlserver/sascnvldb.c @@ -10,14 +10,15 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/sascnvldb.c,v 1.2 2003/01/02 03:55:53 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vlserver/sascnvldb.c,v 1.7 2003/07/15 23:17:34 shadow Exp $"); #include #include #include #include #include -#include "cnvldb.h" /* CHANGEME! */ +#include "cnvldb.h" /* CHANGEME! */ #include #include @@ -33,81 +34,85 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/sascnvldb.c,v 1.2 2003/01/02 0 #endif #include -#define MAXSIZE 2048 /* most I'll get back from PIOCTL */ +#define MAXSIZE 2048 /* most I'll get back from PIOCTL */ extern struct cmd_syndesc *cmd_CreateSyntax(); static char pn[] = "cnvldb"; static char tempname[] = "XXnewvldb"; static char space[MAXSIZE]; -static int MaxServers[2] = {30,254};/* max server # permitted in this version*/ +static int MaxServers[2] = { 30, 254 }; /* max server # permitted in this version */ -#ifdef notdef /* postpone this... */ -static int -saferead (fd,addr,osize) -int fd,osize; -char * addr; +#ifdef notdef /* postpone this... */ +static int +saferead(fd, addr, osize) + int fd, osize; + char *addr; { - int rc,size; - char *ptr; - - if (size == EOF) - return (EOF); - - ptr=addr; - rc=osize=size; - - while(rc != EOF) { - rc = read(fd, ptr, size)) { - if (rc == size) - return osize; - else { - if (errno != EINTR) { - perror(pn); - exit(-1); - } + int rc, size; + char *ptr; + + if (size == EOF) + return (EOF); + + ptr = addr; + rc = osize = size; + + while (rc != EOF) { + rc = read(fd, ptr, size)) { + if (rc == size) + return osize; + else { + if (errno != EINTR) { + perror(pn); + exit(-1); + } + } + } } - } -} -static int -saferead (fd,addr,osize) -int fd,osize; -char * addr; -{ - int rc; - - rc = read(fd,addr,osize); - if (rc != osize && rc != EOF) { - perror(pn); - exit(-1); - } - return(rc); -} + static int + saferead(fd, addr, osize) + int fd, osize; + char *addr; + { + int rc; + + rc = read(fd, addr, osize); + if (rc != osize && rc != EOF) { + perror(pn); + exit(-1); + } + return (rc); + } #else #define saferead(fd,addr,siz) read((fd),(addr),(siz)) #endif -static char tspace[1024]; /* chdir can't handle anything bigger, anyway */ +static char tspace[1024]; /* chdir can't handle anything bigger, anyway */ /* return a static pointer to a buffer */ -static char *Parent(apath) -char *apath; { +static char * +Parent(apath) + char *apath; +{ register char *tp; strcpy(tspace, apath); tp = strrchr(tspace, '/'); if (tp) { *tp = 0; - } - else strcpy(tspace, "."); + } else + strcpy(tspace, "."); return tspace; } #ifdef notdef - + /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */ -static int InAFS(apath) -register char *apath; { +static int +InAFS(apath) + register char *apath; +{ struct ViceIoctl blob; register afs_int32 code; @@ -117,36 +122,44 @@ register char *apath; { code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1); if (code) { - if ((errno == EINVAL) || (errno == ENOENT)) return 0; + if ((errno == EINVAL) || (errno == ENOENT)) + return 0; } return 1; } QuickPrintStatus(status, name) -struct VolumeStatus *status; -char *name; { - double QuotaUsed =0.0; - double PartUsed =0.0; + struct VolumeStatus *status; + char *name; +{ + double QuotaUsed = 0.0; + double PartUsed = 0.0; int WARN = 0; if (status->MaxQuota != 0) { - QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0); + QuotaUsed = + ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0); } else { - /* no limit */ + /* no limit */ } - PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0)); + PartUsed = + (100.0 - + ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) * + 100.0)); } -static ListQuotaCmd(as) -register struct cmd_syndesc *as; { +static +ListQuotaCmd(as) + register struct cmd_syndesc *as; +{ register afs_int32 code; struct ViceIoctl blob; register struct cmd_item *ti; struct VolumeStatus *status; char *name; - - for(ti=as->parms[0].items; ti; ti=ti->next) { + + for (ti = as->parms[0].items; ti; ti = ti->next) { /* once per file */ blob.out_size = MAXSIZE; blob.in_size = 0; @@ -164,72 +177,73 @@ register struct cmd_syndesc *as; { } #endif /* notdef */ -int gc = 1, - fromvers = 1, - tovers = 2; -char *pathname = NULL, - *defaultpath = "/usr/afs/db/vl.DB0"; +int gc = 1, fromvers = 1, tovers = 2; +char *pathname = NULL, *defaultpath = "/usr/afs/db/vl.DB0"; usage() { -fprintf(stderr, "usage: %s ",pn); -fprintf(stderr, "[-name ] [-help]\n"); + fprintf(stderr, "usage: %s ", pn); + fprintf(stderr, "[-name ] [-help]\n"); } getargs(argc, argv) -int argc; -char **argv; { -int pos,i; -pos=0; + int argc; + char **argv; +{ + int pos, i; + pos = 0; - for (i=1;ivital_header.vldbversion = htonl(2); - write (fd, tvp2, sizeof(struct vlheader_2)); + write(fd, tvp2, sizeof(struct vlheader_2)); /* for garbage-collecting... */ if (gc) - for (i=0;i<254; i++) - tvp2->IpMappedAddr[i] = 0; + for (i = 0; i < 254; i++) + tvp2->IpMappedAddr[i] = 0; -return 0; + return 0; } static int convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentry) -int new, fromvers, tovers; -struct vlheader_1 *oldheader, *newheader; /* close enough */ -struct vlentry_1 *vlentry; /* 1 and 2 are identical */ + int new, fromvers, tovers; + struct vlheader_1 *oldheader, *newheader; /* close enough */ + struct vlentry_1 *vlentry; /* 1 and 2 are identical */ { -int diff, i, s; + int diff, i, s; #ifndef DEBUG -if (fromvers != tovers ) { /* only supports 1 and 2 currently */ + if (fromvers != tovers) { /* only supports 1 and 2 currently */ #endif - diff = (tovers == 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)) - - (fromvers == 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)); + diff = + (tovers == + 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)) + - (fromvers == + 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2)); - for (i=0;i<3;i++) - vlentry->nextIdHash[i] = htonl(ntohl(vlentry->nextIdHash[i]) + diff); + for (i = 0; i < 3; i++) + vlentry->nextIdHash[i] = + htonl(ntohl(vlentry->nextIdHash[i]) + diff); - vlentry->nextNameHash = htonl(ntohl(vlentry->nextNameHash) + diff); + vlentry->nextNameHash = htonl(ntohl(vlentry->nextNameHash) + diff); #ifndef DEBUG - } -else { - ; /* no change, we're just in it for the GC */ - } + } else { + ; /* no change, we're just in it for the GC */ + } #endif -for (i=0;i<8;i++) { - s = vlentry->serverNumber[i]; - if (s != 255) { - if (s > 254) { - fprintf(stderr, "%s: Too Many Servers (%d) for this version!\n",pn,s+1); - exit(-1); - } - else { - newheader->IpMappedAddr[s] = oldheader->IpMappedAddr[s]; + for (i = 0; i < 8; i++) { + s = vlentry->serverNumber[i]; + if (s != 255) { + if (s > 254) { + fprintf(stderr, + "%s: Too Many Servers (%d) for this version!\n", pn, + s + 1); + exit(-1); + } else { + newheader->IpMappedAddr[s] = oldheader->IpMappedAddr[s]; + } + } } - } -} -write (new, vlentry, sizeof(struct vlentry_2)); + write(new, vlentry, sizeof(struct vlentry_2)); -return; + return; } static int rewrite_header(new, tovers, newheader) -int new, tovers; -char *newheader; + int new, tovers; + char *newheader; { -int pos; + int pos; -pos = lseek (new, 64, L_SET); /* leave room for ubik */ + pos = lseek(new, 64, L_SET); /* leave room for ubik */ -if (pos == -1) { - perror(pn); - fprintf(stderr, "%s: no garbage collection\n",pn); - return; -} -else if (pos != 64) { - fprintf(stderr,"%s: Can't rewind: no garbage collection\n",pn); - return; -} + if (pos == -1) { + perror(pn); + fprintf(stderr, "%s: no garbage collection\n", pn); + return; + } else if (pos != 64) { + fprintf(stderr, "%s: Can't rewind: no garbage collection\n", pn); + return; + } -if (tovers = 1) { - write (new, newheader, sizeof (struct vlheader_1)); -} -else { - write (new, newheader, sizeof (struct vlheader_2)); -} + if (tovers = 1) { + write(new, newheader, sizeof(struct vlheader_1)); + } else { + write(new, newheader, sizeof(struct vlheader_2)); + } -return; + return; } diff --git a/src/vlserver/vlclient.c b/src/vlserver/vlclient.c index 9ab1b52f4..9e1dae583 100644 --- a/src/vlserver/vlclient.c +++ b/src/vlserver/vlclient.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vlclient.c,v 1.1.1.7 2001/10/14 18:07:16 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vlserver/vlclient.c,v 1.12 2003/12/07 22:49:42 jaltman Exp $"); #include #include @@ -37,6 +38,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vlclient.c,v 1.1.1.7 2001/10/1 #include #endif #include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include @@ -62,7 +72,6 @@ void print_usage(); void fill_entry(); void fill_update_entry(); -extern int VL_GetAddrsU(), VL_RegisterAddrs(); #define VL_NUMBER_OPCODESX 34 static char *opcode_names[VL_NUMBER_OPCODESX] = { "CreateEntry", @@ -81,7 +90,7 @@ static char *opcode_names[VL_NUMBER_OPCODESX] = { "Probe", "GetAddrs", "ChangeAddr", - "CreateEntryN", + "CreateEntryN", "GetEntryByIDN", "GetEntryByNameN", "ReplaceEntryN", @@ -97,7 +106,7 @@ static char *opcode_names[VL_NUMBER_OPCODESX] = { "ListAttributesU", "LinkedListU", "RegisterAddr", - "GetAddrsU" + "GetAddrsU", "ListAttributesN2" }; @@ -109,31 +118,31 @@ struct Vlent { char name[64]; }; -extern int VL_UpdateEntryByName(); #define NVOLS 1000 #define ALLOCNT 50000 struct Vlent *VLa[NVOLS]; #define VHash(avol) ((avol)&(NVOLS-1)) struct Vlent *VL, *SVL; -int VLcnt=0; +int VLcnt = 0; struct ubik_client *cstruct; struct rx_connection *serverconns[MAXSERVERS]; char confdir[AFSDIR_PATH_MAX]; char *(args[50]); -extern struct cmd_syndesc *cmd_CreateSyntax(); -struct Vlent *GetVolume(vol, entry) - struct vldbentry *entry; +struct Vlent * +GetVolume(vol, entry) + struct vldbentry *entry; { register int i; register struct Vlent *vl; - if (!vol) return (struct Vlent *)0; + if (!vol) + return NULL; i = VHash(vol); - for (vl=VLa[i]; vl; vl = vl->next) { - if ((vl->rwid == vol && vol != entry->volumeId[0]) || - (vl->roid == vol && vol != entry->volumeId[1]) || - (vl->baid == vol && vol != entry->volumeId[2])) { + for (vl = VLa[i]; vl; vl = vl->next) { + if ((vl->rwid == vol && vol != entry->volumeId[0]) + || (vl->roid == vol && vol != entry->volumeId[1]) + || (vl->baid == vol && vol != entry->volumeId[2])) { return vl; } } @@ -143,19 +152,21 @@ struct Vlent *GetVolume(vol, entry) strcpy(entry->name, VL->name); VL->next = VLa[i]; VLa[i] = VL; - if (VLcnt++ > ALLOCNT) { /* XXXX FIX XXXXXXXXX */ + if (VLcnt++ > ALLOCNT) { /* XXXX FIX XXXXXXXXX */ printf("Too many entries (> %d)\n", ALLOCNT); exit(1); } VL++; - return (struct Vlent *)0; + return NULL; } /* Almost identical's to pr_Initialize in vlserver/pruser.c */ -afs_int32 vl_Initialize(auth, confDir, server, cellp) -int auth, server; -char *confDir, *cellp; -{ afs_int32 code; +afs_int32 +vl_Initialize(auth, confDir, server, cellp) + int auth, server; + char *confDir, *cellp; +{ + afs_int32 code; struct afsconf_dir *tdir; struct ktc_principal sname; struct ktc_token ttoken; @@ -166,7 +177,7 @@ char *confDir, *cellp; code = rx_Init(0); if (code) { - fprintf(stderr,"vl_Initialize: Could not initialize rx.\n"); + fprintf(stderr, "vl_Initialize: Could not initialize rx.\n"); return code; } @@ -174,73 +185,80 @@ char *confDir, *cellp; if (!server) { tdir = afsconf_Open(confDir); if (!tdir) { - fprintf(stderr,"Could not open configuration directory (%s).\n", confDir); + fprintf(stderr, "Could not open configuration directory (%s).\n", + confDir); return -1; } } - if (auth) { /* we don't need tickets for null */ + if (auth) { /* we don't need tickets for null */ if (!server) { code = afsconf_GetLocalCell(tdir, sname.cell, sizeof(sname.cell)); if (code) { - fprintf(stderr,"vl_Initialize: Could not get local cell name.\n"); + fprintf(stderr, + "vl_Initialize: Could not get local cell name.\n"); return code; } } else strncpy(sname.cell, cellp, sizeof(sname.cell)); sname.instance[0] = 0; strcpy(sname.name, "afs"); - code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0); + code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL); if (code) { - fprintf(stderr,"vl_Initialize: Could not get afs tokens, running unauthenticated.\n"); + fprintf(stderr, + "vl_Initialize: Could not get afs tokens, running unauthenticated.\n"); scIndex = 0; - } - else if (ttoken.kvno <= 255) + } else if (ttoken.kvno <= 255) scIndex = 2; - else { /* bcrypt */ - fprintf (stderr, - "vl_Initialize: funny kvno (%d) in ticket, proceeding\n", - ttoken.kvno); + else { /* bcrypt */ + fprintf(stderr, + "vl_Initialize: funny kvno (%d) in ticket, proceeding\n", + ttoken.kvno); scIndex = 2; } } switch (scIndex) { - case 0 : - sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject(); - break; - case 1 : - return -1; - case 2: - sc = (struct rx_securityClass *) rxkad_NewClientSecurityObject (rxkad_clear, - &ttoken.sessionKey, ttoken.kvno, ttoken.ticketLen, ttoken.ticket); - } + case 0: + sc = rxnull_NewClientSecurityObject(); + break; + case 1: + return -1; + case 2: + sc = rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey, + ttoken.kvno, ttoken.ticketLen, + ttoken.ticket); + } if (!server) { - code = afsconf_GetCellInfo(tdir,(char *)0, AFSCONF_VLDBSERVICE, &info); + code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info); if (info.numServers > MAXSERVERS) { fprintf(stderr, "vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n", info.numServers, MAXSERVERS); exit(1); } - for (i = 0;ih_addr, sizeof(addr)); return addr; } -static handleit(as) - struct cmd_syndesc *as; +static +handleit(as) + struct cmd_syndesc *as; { register struct cmd_item *ti; - register afs_int32 code, server = 0, sawserver=0; + register afs_int32 code, server = 0, sawserver = 0; afs_int32 id, voltype; - struct vldbentry entry; - char *cmd = 0, *cellp=0; + struct vldbentry entry; + char *cmd = 0, *cellp = 0; struct VldbUpdateEntry updateentry; struct VldbListByAttributes listbyattributes; - int noAuth = 1; /* Default is authenticated connections */ + int noAuth = 1; /* Default is authenticated connections */ - if (ti = as->parms[0].items) /* -cellpath */ + if (ti = as->parms[0].items) /* -cellpath */ strcpy(confdir, ti->data); - if (as->parms[1].items) /* -server */ - strcpy(confdir, AFSDIR_SERVER_ETC_DIRPATH); - if (as->parms[2].items) /* -noauth */ - noAuth = 0; + if (as->parms[1].items) /* -server */ + strcpy(confdir, AFSDIR_SERVER_ETC_DIRPATH); + if (as->parms[2].items) /* -noauth */ + noAuth = 0; if (ti = as->parms[3].items) { /* -host */ server = GetServer(ti->data); if (server == 0) { @@ -285,22 +305,24 @@ static handleit(as) sawserver = 1; } if (!sawserver && noAuth && (!(ti = as->parms[4].items))) { - printf("Must also specify the -cell' option along with -host for authenticated conns\n"); - exit(1); + printf + ("Must also specify the -cell' option along with -host for authenticated conns\n"); + exit(1); } if (ti = as->parms[4].items) { /* -cell */ cellp = ti->data; } if (code = vl_Initialize(noAuth, confdir, server, cellp)) { - printf("Couldn't initialize vldb library (code=%d).\n",code); + printf("Couldn't initialize vldb library (code=%d).\n", code); exit(1); } - if (as->parms[5].items) { /* -gstats */ + if (as->parms[5].items) { /* -gstats */ vldstats stats; vital_vlheader vital_header; code = ubik_Call(VL_GetStats, cstruct, 0, &stats, &vital_header); - if (!code) dump_stats(&stats, &vital_header); + if (!code) + dump_stats(&stats, &vital_header); exit(0); } @@ -323,14 +345,14 @@ static handleit(as) if (!strcmp(oper, "cr")) { fill_entry(&entry, argp, nargs); display_entry(&entry, 0); - code = ubik_Call(VL_CreateEntry, cstruct,0, &entry); + code = ubik_Call(VL_CreateEntry, cstruct, 0, &entry); printf("return code is %d\n", code); - } else if (!strcmp(oper,"rm")) { + } else if (!strcmp(oper, "rm")) { sscanf(&(*argp)[0], "%d", &id); ++argp, --nargs; sscanf(&(*argp)[0], "%d", &voltype); code = ubik_Call(VL_DeleteEntry, cstruct, 0, id, voltype); - printf("return code is %d\n",code); + printf("return code is %d\n", code); } else if (!strcmp(oper, "re")) { sscanf(&(*argp)[0], "%d", &id); ++argp, --nargs; @@ -340,7 +362,9 @@ static handleit(as) ++argp, --nargs; fill_entry(&entry, argp, nargs); display_entry(&entry, 0); - code = ubik_Call(VL_ReplaceEntry, cstruct, 0, id, voltype, &entry, releasetype); + code = + ubik_Call(VL_ReplaceEntry, cstruct, 0, id, voltype, + &entry, releasetype); printf("return code is %d\n", code); } else if (!strcmp(oper, "up")) { sscanf(&(*argp)[0], "%d", &id); @@ -351,240 +375,321 @@ static handleit(as) ++argp, --nargs; fill_update_entry(&updateentry, argp, nargs); display_update_entry(&updateentry, 0); - code = ubik_Call(VL_UpdateEntry, cstruct, 0, id, voltype, &updateentry, releasetype); + code = + ubik_Call(VL_UpdateEntry, cstruct, 0, id, voltype, + &updateentry, releasetype); printf("return code is %d\n", code); - } else if (!strcmp(oper,"ls")) { - afs_int32 index, count, next_index; - for (index = 0; 1; index = next_index) { - memset(&entry, 0, sizeof(entry)); - code = ubik_Call(VL_ListEntry,cstruct,0,index,&count,&next_index,&entry); - if (code) { - printf("VL_ListEntry returned code = %d\n", code); - break; - } - if (!next_index) break; - display_entry(&entry, 0); - } - } else if (!strcmp(oper,"ldups")) { - afs_int32 index, count, num=0, num1=0, next_index; - struct Vlent *vl1; - - VL = SVL = (struct Vlent *) malloc(ALLOCNT * sizeof(struct Vlent)); - if (VL == NULL) { - printf("Can't allocate memory...\n"); - exit(1); - } - printf("Enumerating all entries in vldb...\n"); - for (index = 0; 1; index = next_index) { - memset(&entry, 0, sizeof(entry)); - code = ubik_Call(VL_ListEntry,cstruct,0,index,&count,&next_index,&entry); - if (code) { - printf("VL_ListEntry returned code = %d\n", code); - break; - } - if (!next_index) break; - num++; - if (vl1 = GetVolume(entry.volumeId[0], &entry)) { - num1++; - printf("Duplicate entry is found for RW vol %u: [RW %u, RO %u, BA %u, name=%s]\n", - entry.volumeId[0], vl1->rwid, vl1->roid, vl1->baid, vl1->name); - } - if (vl1 = GetVolume(entry.volumeId[1], &entry)) { - num1++; - printf("Duplicate entry is found for RO vol %u: [RW %u, RO %u, BA %u, name=%s]\n", - entry.volumeId[1], vl1->rwid, vl1->roid, vl1->baid, vl1->name); - } - if (vl1 = GetVolume(entry.volumeId[2], &entry)) { - num1++; - printf("Duplicate entry is found for BA vol %u: [RW %u, RO %u, BA %u, name=%s]\n", - entry.volumeId[2], vl1->rwid, vl1->roid, vl1->baid, vl1->name); - } - /*display_entry(&entry, 0);*/ - } - printf("(%d vldb entries found - %d duplicates)\n", num, num1); - } else if (!strcmp(oper,"checkhash")) { - int index, count, num=0, num1=0, num2 = 0, num3=0, num31=0, num4=0, num41=0, next_index; - struct vldbentry tentry; - - VL = SVL = (struct Vlent *) malloc(ALLOCNT * sizeof(struct Vlent)); - if (VL == NULL) { - printf("Can't allocate memory...\n"); - exit(1); - } - printf("Volumes not found in main hash tables in vldb...\n"); - for (index = 0; 1; index = next_index) { - memset(&entry, 0, sizeof(entry)); - code = ubik_Call(VL_ListEntry,cstruct,0,index,&count,&next_index,&entry); - if (code) { - printf("VL_ListEntry returned code = %d\n", code); - break; - } - if (!next_index) break; - num++; - code = ubik_Call(VL_GetEntryByNameO,cstruct,0,entry.name, &tentry); - if (code == VL_NOENT) { - num1++; - printf("\tVolume %s %d (not in namehash)\n", entry.name, entry.volumeId[RWVOL]); - } - code = ubik_Call(VL_GetEntryByID,cstruct,0,entry.volumeId[RWVOL], RWVOL, &tentry); - if (code == VL_NOENT) { - num2++; - printf("\tVolume %s %d (not in rwid hash)\n", entry.name, entry.volumeId[RWVOL]); - } - if (entry.volumeId[BACKVOL]) { - code = ubik_Call(VL_GetEntryByID,cstruct,0,entry.volumeId[BACKVOL], BACKVOL, &tentry); - num31++; - if (code == VL_NOENT) { - num3++; - printf("\tVolume %s %d (not in backup id hash)\n", entry.name, entry.volumeId[BACKVOL]); - } - } - if (entry.volumeId[ROVOL]) { - code = ubik_Call(VL_GetEntryByID,cstruct,0,entry.volumeId[ROVOL], ROVOL, &tentry); - num41++; - if (code == VL_NOENT) { - num4++; - printf("\tVolume %s %d (not in RO id hash)\n", entry.name, entry.volumeId[ROVOL]); - } - } - } - printf("\nTotal vldb entries %d\nTotal volumes %d (%d rw, %d backup, %d ro)\n", - num, num+num31+num41, num, num31, num41); - printf("\n\t%d didn't hash properly by name\n\t%d didn't hash properly by rw volid\n", - num1, num2); - printf("\t%d didn't hash properly by backup volid (out of %d)\n\t%d didn't hash properly by ro volid (out of %d)\n", - num3, num31, num4, num41); - } else if (!strcmp(oper,"fixhash")) { - int index, count, num=0, num1=0, num2 = 0, next_index, x=0; - struct vldbentry tentry; - - VL = SVL = (struct Vlent *) malloc(ALLOCNT * sizeof(struct Vlent)); - if (VL == NULL) { - printf("Can't allocate memory...\n"); - exit(1); - } - printf("Volumes not found in main hash tables in vldb will be fixed...\n"); - memset(&updateentry, 0, sizeof(updateentry)); - for (index = 0; 1; index = next_index) { - int n1=0, n2=0, n3=0, n4=0; - memset(&entry, 0, sizeof(entry)); - code = ubik_Call(VL_ListEntry,cstruct,0,index,&count,&next_index,&entry); - if (code) { - printf("VL_ListEntry returned code = %d\n", code); - break; - } - if (!next_index) break; - num++; - code = ubik_Call(VL_GetEntryByNameO,cstruct,0,entry.name, &tentry); - if (code == VL_NOENT) { - num1++; - n1 = 1; - updateentry.Mask = VLUPDATE_VOLNAMEHASH; - printf("\tVolume %s %d (not in namehash)\n", entry.name, entry.volumeId[RWVOL]); - code = ubik_Call(VL_UpdateEntry, cstruct, 0, entry.volumeId[RWVOL], -1, &updateentry, 0); - if (code) { - x++; - printf("\tFailed to update volume %s (err=%d)\n", entry.name, code); - } - } - code = ubik_Call(VL_GetEntryByID,cstruct,0,entry.volumeId[RWVOL], RWVOL, &tentry); - if (code == VL_NOENT) { - num1++; - num2++; - updateentry.Mask = VLUPDATE_RWID; - updateentry.spares3 = entry.volumeId[RWVOL]; - printf("\tVolume %s %d (not in rw id hash)\n", entry.name, entry.volumeId[RWVOL]); - code = ubik_Call(VL_UpdateEntryByName, cstruct, 0, entry.name, &updateentry, 0); - if (code) { - printf("\tFailed to update volume %s (err=%d)\n", entry.name, code); - x++; - } - x++; - } - if (entry.volumeId[BACKVOL] && !n2) { - code = ubik_Call(VL_GetEntryByID,cstruct,0,entry.volumeId[BACKVOL], BACKVOL, &tentry); - if (code == VL_NOENT) { - n3 = 1; - num1++; - updateentry.Mask = VLUPDATE_BACKUPID; - updateentry.BackupId = entry.volumeId[BACKVOL]; - printf("\tVolume %s %d (not in backup id hash)\n", entry.name, entry.volumeId[BACKVOL]); - code = ubik_Call(VL_UpdateEntry, cstruct, 0, entry.volumeId[RWVOL], -1, &updateentry, 0); - if (code) { - printf("\tFailed to update volume %s (err=%d)\n", entry.name, code); - x++; - } - } - } - if (entry.volumeId[ROVOL && !n2]) { - code = ubik_Call(VL_GetEntryByID,cstruct,0,entry.volumeId[ROVOL], ROVOL, &tentry); - if (code == VL_NOENT) { - n4 = 1; - num1++; - updateentry.Mask = VLUPDATE_READONLYID; - updateentry.ReadOnlyId = entry.volumeId[ROVOL]; - printf("\tVolume %s %d (not in RO id hash)\n", entry.name, entry.volumeId[ROVOL]); - code = ubik_Call(VL_UpdateEntry, cstruct, 0, entry.volumeId[RWVOL], -1, &updateentry, 0); - if (code) { - printf("\tFailed to update volume %s (err=%d)\n", entry.name, code); - x++; - } - } - } - } - printf("\nTotal vldb entries found %d:\n\t%d entries didn't hash properly and are fixed except %d that need to be handled manually\n", - num, num1, x); + } else if (!strcmp(oper, "ls")) { + afs_int32 index, count, next_index; + for (index = 0; 1; index = next_index) { + memset(&entry, 0, sizeof(entry)); + code = + ubik_Call(VL_ListEntry, cstruct, 0, index, &count, + &next_index, &entry); + if (code) { + printf("VL_ListEntry returned code = %d\n", code); + break; + } + if (!next_index) + break; + display_entry(&entry, 0); + } + } else if (!strcmp(oper, "ldups")) { + afs_int32 index, count, num = 0, num1 = 0, next_index; + struct Vlent *vl1; + + VL = SVL = + (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent)); + if (VL == NULL) { + printf("Can't allocate memory...\n"); + exit(1); + } + printf("Enumerating all entries in vldb...\n"); + for (index = 0; 1; index = next_index) { + memset(&entry, 0, sizeof(entry)); + code = + ubik_Call(VL_ListEntry, cstruct, 0, index, &count, + &next_index, &entry); + if (code) { + printf("VL_ListEntry returned code = %d\n", code); + break; + } + if (!next_index) + break; + num++; + if (vl1 = GetVolume(entry.volumeId[0], &entry)) { + num1++; + printf + ("Duplicate entry is found for RW vol %u: [RW %u, RO %u, BA %u, name=%s]\n", + entry.volumeId[0], vl1->rwid, vl1->roid, + vl1->baid, vl1->name); + } + if (vl1 = GetVolume(entry.volumeId[1], &entry)) { + num1++; + printf + ("Duplicate entry is found for RO vol %u: [RW %u, RO %u, BA %u, name=%s]\n", + entry.volumeId[1], vl1->rwid, vl1->roid, + vl1->baid, vl1->name); + } + if (vl1 = GetVolume(entry.volumeId[2], &entry)) { + num1++; + printf + ("Duplicate entry is found for BA vol %u: [RW %u, RO %u, BA %u, name=%s]\n", + entry.volumeId[2], vl1->rwid, vl1->roid, + vl1->baid, vl1->name); + } + /*display_entry(&entry, 0); */ + } + printf("(%d vldb entries found - %d duplicates)\n", num, + num1); + } else if (!strcmp(oper, "checkhash")) { + int index, count, num = 0, num1 = 0, num2 = 0, num3 = + 0, num31 = 0, num4 = 0, num41 = 0, next_index; + struct vldbentry tentry; + + VL = SVL = + (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent)); + if (VL == NULL) { + printf("Can't allocate memory...\n"); + exit(1); + } + printf("Volumes not found in main hash tables in vldb...\n"); + for (index = 0; 1; index = next_index) { + memset(&entry, 0, sizeof(entry)); + code = + ubik_Call(VL_ListEntry, cstruct, 0, index, &count, + &next_index, &entry); + if (code) { + printf("VL_ListEntry returned code = %d\n", code); + break; + } + if (!next_index) + break; + num++; + code = + ubik_Call(VL_GetEntryByNameO, cstruct, 0, entry.name, + &tentry); + if (code == VL_NOENT) { + num1++; + printf("\tVolume %s %d (not in namehash)\n", + entry.name, entry.volumeId[RWVOL]); + } + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, + entry.volumeId[RWVOL], RWVOL, &tentry); + if (code == VL_NOENT) { + num2++; + printf("\tVolume %s %d (not in rwid hash)\n", + entry.name, entry.volumeId[RWVOL]); + } + if (entry.volumeId[BACKVOL]) { + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, + entry.volumeId[BACKVOL], BACKVOL, + &tentry); + num31++; + if (code == VL_NOENT) { + num3++; + printf("\tVolume %s %d (not in backup id hash)\n", + entry.name, entry.volumeId[BACKVOL]); + } + } + if (entry.volumeId[ROVOL]) { + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, + entry.volumeId[ROVOL], ROVOL, &tentry); + num41++; + if (code == VL_NOENT) { + num4++; + printf("\tVolume %s %d (not in RO id hash)\n", + entry.name, entry.volumeId[ROVOL]); + } + } + } + printf + ("\nTotal vldb entries %d\nTotal volumes %d (%d rw, %d backup, %d ro)\n", + num, num + num31 + num41, num, num31, num41); + printf + ("\n\t%d didn't hash properly by name\n\t%d didn't hash properly by rw volid\n", + num1, num2); + printf + ("\t%d didn't hash properly by backup volid (out of %d)\n\t%d didn't hash properly by ro volid (out of %d)\n", + num3, num31, num4, num41); + } else if (!strcmp(oper, "fixhash")) { + int index, count, num = 0, num1 = 0, num2 = 0, next_index, x = + 0; + struct vldbentry tentry; + + VL = SVL = + (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent)); + if (VL == NULL) { + printf("Can't allocate memory...\n"); + exit(1); + } + printf + ("Volumes not found in main hash tables in vldb will be fixed...\n"); + memset(&updateentry, 0, sizeof(updateentry)); + for (index = 0; 1; index = next_index) { + /* FIXME: n2 is never changed for some reason */ + int n1 = 0, n2 = 0, n3 = 0, n4 = 0; + memset(&entry, 0, sizeof(entry)); + code = + ubik_Call(VL_ListEntry, cstruct, 0, index, &count, + &next_index, &entry); + if (code) { + printf("VL_ListEntry returned code = %d\n", code); + break; + } + if (!next_index) + break; + num++; + code = + ubik_Call(VL_GetEntryByNameO, cstruct, 0, entry.name, + &tentry); + if (code == VL_NOENT) { + num1++; + n1 = 1; + updateentry.Mask = VLUPDATE_VOLNAMEHASH; + printf("\tVolume %s %d (not in namehash)\n", + entry.name, entry.volumeId[RWVOL]); + code = + ubik_Call(VL_UpdateEntry, cstruct, 0, + entry.volumeId[RWVOL], -1, &updateentry, + 0); + if (code) { + x++; + printf("\tFailed to update volume %s (err=%d)\n", + entry.name, code); + } + } + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, + entry.volumeId[RWVOL], RWVOL, &tentry); + if (code == VL_NOENT) { + num1++; + num2++; + updateentry.Mask = VLUPDATE_RWID; + updateentry.spares3 = entry.volumeId[RWVOL]; + printf("\tVolume %s %d (not in rw id hash)\n", + entry.name, entry.volumeId[RWVOL]); + code = + ubik_Call(VL_UpdateEntryByName, cstruct, 0, + entry.name, &updateentry, 0); + if (code) { + printf("\tFailed to update volume %s (err=%d)\n", + entry.name, code); + x++; + } + x++; + } + if (entry.volumeId[BACKVOL] && !n2) { + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, + entry.volumeId[BACKVOL], BACKVOL, + &tentry); + if (code == VL_NOENT) { + n3 = 1; + num1++; + updateentry.Mask = VLUPDATE_BACKUPID; + updateentry.BackupId = entry.volumeId[BACKVOL]; + printf("\tVolume %s %d (not in backup id hash)\n", + entry.name, entry.volumeId[BACKVOL]); + code = + ubik_Call(VL_UpdateEntry, cstruct, 0, + entry.volumeId[RWVOL], -1, + &updateentry, 0); + if (code) { + printf + ("\tFailed to update volume %s (err=%d)\n", + entry.name, code); + x++; + } + } + } + if (entry.volumeId[ROVOL && !n2]) { + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, + entry.volumeId[ROVOL], ROVOL, &tentry); + if (code == VL_NOENT) { + n4 = 1; + num1++; + updateentry.Mask = VLUPDATE_READONLYID; + updateentry.ReadOnlyId = entry.volumeId[ROVOL]; + printf("\tVolume %s %d (not in RO id hash)\n", + entry.name, entry.volumeId[ROVOL]); + code = + ubik_Call(VL_UpdateEntry, cstruct, 0, + entry.volumeId[RWVOL], -1, + &updateentry, 0); + if (code) { + printf + ("\tFailed to update volume %s (err=%d)\n", + entry.name, code); + x++; + } + } + } + } + printf + ("\nTotal vldb entries found %d:\n\t%d entries didn't hash properly and are fixed except %d that need to be handled manually\n", + num, num1, x); } else if (!strcmp(oper, "la")) { - int nentries=0, i; + int nentries = 0, i; bulkentries entries; struct vldbentry *entry; memset(&entries, 0, sizeof(entries)); fill_listattributes_entry(&listbyattributes, argp, nargs); display_listattributes_entry(&listbyattributes, 0); - code = ubik_Call(VL_ListAttributes, cstruct, 0, &listbyattributes, &nentries, &entries); + code = + ubik_Call(VL_ListAttributes, cstruct, 0, + &listbyattributes, &nentries, &entries); if (code) { printf("VL_ListAttributes returned code = %d\n", code); continue; } entry = (struct vldbentry *)entries.bulkentries_val; - for (i=0; i < nentries; i++, entry++) + for (i = 0; i < nentries; i++, entry++) display_entry(entry, 0); - if (entries.bulkentries_val) free((char *)entries.bulkentries_val); + if (entries.bulkentries_val) + free((char *)entries.bulkentries_val); } else if (!strcmp(oper, "lan2")) { - int nentries, i, si, nsi, t=0; + int nentries, i, si, nsi, t = 0; nbulkentries entries; struct nvldbentry *entry; char name[64]; /* The volume name to search for (supports wildcarding) */ if (nargs > 0) { - strcpy(name,argp[0]); - ++argp, --nargs; + strcpy(name, argp[0]); + ++argp, --nargs; } else { - strcpy(name,""); + strcpy(name, ""); } - + fill_listattributes_entry(&listbyattributes, argp, nargs); display_listattributes_entry(&listbyattributes, 0); printf("Wildcard VolName: '%s'\n", name); - for (si=0; si!=-1; si=nsi) { - nentries = 0; - memset(&entries, 0, sizeof(entries)); - code = ubik_Call(VL_ListAttributesN2, cstruct, 0, - &listbyattributes, name, si, - &nentries, &entries, &nsi); - if (code) { - printf("VL_ListAttributesN2 returned code = %d\n", code); - break; - } - - t += nentries; - entry = (struct nvldbentry *)entries.nbulkentries_val; - for (i=0; i < nentries; i++, entry++) - display_entryN(entry, 0); - if (entries.nbulkentries_val) free((char *)entries.nbulkentries_val); + for (si = 0; si != -1; si = nsi) { + nentries = 0; + memset(&entries, 0, sizeof(entries)); + code = + ubik_Call(VL_ListAttributesN2, cstruct, 0, + &listbyattributes, name, si, &nentries, + &entries, &nsi); + if (code) { + printf("VL_ListAttributesN2 returned code = %d\n", + code); + break; + } + + t += nentries; + entry = (struct nvldbentry *)entries.nbulkentries_val; + for (i = 0; i < nentries; i++, entry++) + display_entryN(entry, 0); + if (entries.nbulkentries_val) + free((char *)entries.nbulkentries_val); } printf("--- %d volumes ---\n", t); } else if (!strcmp(oper, "ln")) { @@ -595,16 +700,18 @@ static handleit(as) fill_listattributes_entry(&listbyattributes, argp, nargs); display_listattributes_entry(&listbyattributes, 0); memset(&linkedvldbs, 0, sizeof(vldb_list)); - code = ubik_Call(VL_LinkedList, cstruct, 0, &listbyattributes, - &netries, &linkedvldbs); + code = + ubik_Call(VL_LinkedList, cstruct, 0, &listbyattributes, + &netries, &linkedvldbs); if (code) { printf("VL_LinkedList returned code = %d\n", code); continue; } - printf("Found %d entr%s\n", netries, (netries==1?"y":"ies")); + printf("Found %d entr%s\n", netries, + (netries == 1 ? "y" : "ies")); for (vllist = linkedvldbs.node; vllist; vllist = vllist1) { vllist1 = vllist->next_vldb; - display_entry(&vllist->VldbEntry, 0); + display_entry(&vllist->VldbEntry, 0); free((char *)vllist); } } else if (!strcmp(oper, "lnn")) { @@ -615,95 +722,120 @@ static handleit(as) fill_listattributes_entry(&listbyattributes, argp, nargs); display_listattributes_entry(&listbyattributes, 0); memset(&linkedvldbs, 0, sizeof(vldb_list)); - code = ubik_Call(VL_LinkedListN, cstruct, 0, &listbyattributes, - &netries, &linkedvldbs); + code = + ubik_Call(VL_LinkedListN, cstruct, 0, &listbyattributes, + &netries, &linkedvldbs); if (code) { printf("VL_LinkedList returned code = %d\n", code); continue; } - printf("Found %d entr%s\n", netries, (netries==1?"y":"ies")); + printf("Found %d entr%s\n", netries, + (netries == 1 ? "y" : "ies")); for (vllist = linkedvldbs.node; vllist; vllist = vllist1) { vllist1 = vllist->next_vldb; - display_entry(&vllist->VldbEntry, 0); + display_entry(&vllist->VldbEntry, 0); free((char *)vllist); } - } else if (!strcmp(oper,"di")) { - sscanf(&(*argp)[0], "%d", &id); - ++argp, --nargs; - sscanf(&(*argp)[0], "%d", &voltype); - code = ubik_Call(VL_GetEntryByID, cstruct, 0, id, voltype, &entry); - display_entry(&entry, code); - printf("return code is %d.\n",code); - } else if (!strcmp(oper,"rmnh")) { - sscanf(&(*argp)[0], "%d", &id); - ++argp, --nargs; - sscanf(&(*argp)[0], "%d", &voltype); - code = ubik_Call(VL_GetEntryByID, cstruct, 0, id, voltype, &entry); - display_entry(&entry, code); - memset(&updateentry, 0, sizeof(updateentry)); - updateentry.Mask = VLUPDATE_VOLNAMEHASH; - printf("\tRehashing namehash table for %s (%d)\n", entry.name, entry.volumeId[RWVOL]); - code = ubik_Call(VL_UpdateEntry, cstruct, 0, entry.volumeId[RWVOL], -1, &updateentry, 0); - if (code) { - printf("\tFailed to update volume %s (err=%d)\n", entry.name, code); - } - printf("return code is %d.\n",code); - } else if (!strcmp(oper,"undelete")) { - afs_int32 index, count, next_index; - - memset(&updateentry, 0, sizeof(updateentry)); - sscanf(&(*argp)[0], "%d", &id); - ++argp, --nargs; - sscanf(&(*argp)[0], "%d", &voltype); - if (voltype < 0 && voltype > 2) { - printf("Illegal voltype; must be 0, 1 or 2\n"); - continue; - } - printf("Searching vldb for volume %d...\n", id); - for (index = 0; 1; index = next_index) { - memset(&entry, 0, sizeof(entry)); - code = ubik_Call(VL_ListEntry,cstruct,0,index,&count,&next_index,&entry); - if (code) { - printf("VL_ListEntry returned code = %d\n", code); - break; - } - if (!next_index) break; - if (entry.volumeId[voltype] == id) { - printf("\nThe current contents of the vldb for %d:\n", id); - display_entry(&entry, 0); - - if (entry.flags & VLDELETED) { - updateentry.Mask = VLUPDATE_FLAGS; - updateentry.flags = entry.flags; - updateentry.flags &= ~VLDELETED; - printf("\tUndeleting vldb entry for vol %d (%s)\n", id, entry.name); - code = ubik_Call(VL_UpdateEntry, cstruct, 0, id, -1, &updateentry, 0); - if (code) { - printf("\tFailed to update volume %s (err=%d)\n", entry.name, code); - } - } else { - printf("Entry not deleted; ignored\n"); - } - break; - } - } - } else if (!strcmp(oper,"dn")) { - vname = &argp[0][0]; - code = ubik_Call(VL_GetEntryByNameO,cstruct,0,vname, &entry); - display_entry(&entry, code); - printf("return code is %d.\n",code); - } else if (!strcmp(oper, "nv")) { - int newvolid; - sscanf(&(*argp)[0], "%d", &id); - code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &newvolid); - if (!code) printf("Current Max volid is (in hex):%X\n", newvolid); - printf("return code is %d\n", code); - } else if (!strcmp(oper, "gs")) { - vldstats stats; - vital_vlheader vital_header; - code = ubik_Call(VL_GetStats, cstruct, 0, &stats, &vital_header); - if (!code) dump_stats(&stats, &vital_header); - printf("return code is %d.\n", code); + } else if (!strcmp(oper, "di")) { + sscanf(&(*argp)[0], "%d", &id); + ++argp, --nargs; + sscanf(&(*argp)[0], "%d", &voltype); + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, id, voltype, + &entry); + display_entry(&entry, code); + printf("return code is %d.\n", code); + } else if (!strcmp(oper, "rmnh")) { + sscanf(&(*argp)[0], "%d", &id); + ++argp, --nargs; + sscanf(&(*argp)[0], "%d", &voltype); + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, id, voltype, + &entry); + display_entry(&entry, code); + memset(&updateentry, 0, sizeof(updateentry)); + updateentry.Mask = VLUPDATE_VOLNAMEHASH; + printf("\tRehashing namehash table for %s (%d)\n", entry.name, + entry.volumeId[RWVOL]); + code = + ubik_Call(VL_UpdateEntry, cstruct, 0, + entry.volumeId[RWVOL], -1, &updateentry, 0); + if (code) { + printf("\tFailed to update volume %s (err=%d)\n", + entry.name, code); + } + printf("return code is %d.\n", code); + } else if (!strcmp(oper, "undelete")) { + afs_int32 index, count, next_index; + + memset(&updateentry, 0, sizeof(updateentry)); + sscanf(&(*argp)[0], "%d", &id); + ++argp, --nargs; + sscanf(&(*argp)[0], "%d", &voltype); + if (voltype < 0 && voltype > 2) { + printf("Illegal voltype; must be 0, 1 or 2\n"); + continue; + } + printf("Searching vldb for volume %d...\n", id); + for (index = 0; 1; index = next_index) { + memset(&entry, 0, sizeof(entry)); + code = + ubik_Call(VL_ListEntry, cstruct, 0, index, &count, + &next_index, &entry); + if (code) { + printf("VL_ListEntry returned code = %d\n", code); + break; + } + if (!next_index) + break; + if (entry.volumeId[voltype] == id) { + printf("\nThe current contents of the vldb for %d:\n", + id); + display_entry(&entry, 0); + + if (entry.flags & VLDELETED) { + updateentry.Mask = VLUPDATE_FLAGS; + updateentry.flags = entry.flags; + updateentry.flags &= ~VLDELETED; + printf + ("\tUndeleting vldb entry for vol %d (%s)\n", + id, entry.name); + code = + ubik_Call(VL_UpdateEntry, cstruct, 0, id, -1, + &updateentry, 0); + if (code) { + printf + ("\tFailed to update volume %s (err=%d)\n", + entry.name, code); + } + } else { + printf("Entry not deleted; ignored\n"); + } + break; + } + } + } else if (!strcmp(oper, "dn")) { + vname = &argp[0][0]; + code = + ubik_Call(VL_GetEntryByNameO, cstruct, 0, vname, &entry); + display_entry(&entry, code); + printf("return code is %d.\n", code); + } else if (!strcmp(oper, "nv")) { + int newvolid; + sscanf(&(*argp)[0], "%d", &id); + code = + ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &newvolid); + if (!code) + printf("Current Max volid is (in hex):%X\n", newvolid); + printf("return code is %d\n", code); + } else if (!strcmp(oper, "gs")) { + vldstats stats; + vital_vlheader vital_header; + code = + ubik_Call(VL_GetStats, cstruct, 0, &stats, &vital_header); + if (!code) + dump_stats(&stats, &vital_header); + printf("return code is %d.\n", code); } else if (!strcmp(oper, "ga")) { int nentries, i; afs_uint32 *addrp; @@ -712,18 +844,21 @@ static handleit(as) addrs.bulkaddrs_val = 0; addrs.bulkaddrs_len = 0; - code = ubik_Call(VL_GetAddrs, cstruct, 0, 0 /*Handle*/, 0 /*spare2*/, &vlcb, + code = ubik_Call(VL_GetAddrs, cstruct, 0, 0 /*Handle */ , + 0 /*spare2 */ , &vlcb, &nentries, &addrs); if (code) { printf("VL_GetAddrs returned code = %d\n", code); continue; } addrp = addrs.bulkaddrs_val; - for (i=0; i < nentries; i++, addrp++) { + for (i = 0; i < nentries; i++, addrp++) { if ((*addrp & 0xff000000) == 0xff000000) - printf ("[0x%x %u] (special multi-homed entry)\n", *addrp, *addrp); + printf("[0x%x %u] (special multi-homed entry)\n", + *addrp, *addrp); else - printf ("[0x%x %u] %s\n", *addrp, *addrp, hostutil_GetNameByINet(ntohl(*addrp))); + printf("[0x%x %u] %s\n", *addrp, *addrp, + hostutil_GetNameByINet(ntohl(*addrp))); } free((char *)addrs.bulkaddrs_val); } else if (!strcmp(oper, "gau")) { @@ -734,142 +869,161 @@ static handleit(as) addrs.bulkaddrs_val = 0; addrs.bulkaddrs_len = 0; - code = ubik_Call(VL_GetAddrs, cstruct, 0, 0 /*Handle*/, 0 /*spare2*/, &vlcb, + code = ubik_Call(VL_GetAddrs, cstruct, 0, 0 /*Handle */ , + 0 /*spare2 */ , &vlcb, &nentries, &addrs); if (code) { printf("VL_GetAddrs returned code = %d\n", code); continue; } addrp = addrs.bulkaddrs_val; - for (i=0; i < nentries; i++, addrp++) { - if ((*addrp & 0xff000000) == 0xff000000) { - int mhnentries, unique; - struct in_addr hostAddr; - afs_uint32 *mhaddrp; - bulkaddrs mhaddrs; - ListAddrByAttributes attrs; - afsUUID uuid; - - printf ("[0x%x %u] (special multi-homed entry)\n", *addrp, *addrp); - attrs.Mask = VLADDR_INDEX; - mhaddrs.bulkaddrs_val = 0; - mhaddrs.bulkaddrs_len = 0; - attrs.index = *addrp & 0x00ffffff; - - code = ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid, &unique, &mhnentries, &mhaddrs); - if (code) { - printf("VL_GetAddrsU returned code = %d\n", code); - continue; - } - printf(" [%d]: uuid[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x]\n addrunique=%d, ip address(es):\n", attrs.index, uuid.time_low, - uuid.time_mid, uuid.time_hi_and_version, uuid.clock_seq_hi_and_reserved, uuid.clock_seq_low, - uuid.node[0], uuid.node[1], uuid.node[2], uuid.node[3], uuid.node[4], uuid.node[5], unique); - mhaddrp = mhaddrs.bulkaddrs_val; - for (j=0; j> 16) & 0xff; - index = *addrp1 & 0xffff; - - addrs2.bulkaddrs_val = 0; - addrs2.bulkaddrs_len = 0; - attrs.Mask = VLADDR_INDEX; - attrs.index = (base * VL_MHSRV_PERBLK) + index; - code = ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, - &uuid, &unique, &nentries2, &addrs2); - if (code) { - printf("VL_GetAddrsU returned code = %d\n", code); - break; - } - - addrp2 = addrs2.bulkaddrs_val; - for (j=0; j> 16) & 0xff; + index = *addrp1 & 0xffff; + + addrs2.bulkaddrs_val = 0; + addrs2.bulkaddrs_len = 0; + attrs.Mask = VLADDR_INDEX; + attrs.index = (base * VL_MHSRV_PERBLK) + index; + code = + ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid, + &unique, &nentries2, &addrs2); + if (code) { + printf("VL_GetAddrsU returned code = %d\n", code); + break; + } + + addrp2 = addrs2.bulkaddrs_val; + for (j = 0; j < nentries2; j++) { + serveraddrs[i][j] = ntohl(addrp2[j]); + } + free((char *)addrs2.bulkaddrs_val); } if (nargs) { - if (serveraddrtype[i] == 1) { - printf ("%u\n", serveraddrs[i][0]); - } else { - printf ("["); - for (j=0; jh_addr, sizeof(afs_uint32)); - - ++argp, --nargs; - printf(" to %s\n", *argp); - h2 = hostutil_GetHostByName(&(*argp)[0]); - if (!h2) { - printf("cmdebug: can't resolve address for host %s", *argp); - continue; - } - memcpy(&a2, (afs_int32 *)h2->h_addr, sizeof(afs_uint32)); - - printf("changing 0x%x to 0x%x\n", ntohl(a1), ntohl(a2)); - code = ubik_Call(VL_ChangeAddr, cstruct, 0, ntohl(a1), ntohl(a2)); - if (code) { - printf("VL_ChangeAddr returned code = %d\n", code); - continue; - } - } else if (!strcmp(oper,"caid")) { - afs_uint32 a1, a2; - - sscanf(&(*argp)[0], "%d", &a1); - printf("changing %d (0x%x)", a1, a1); - ++argp, --nargs; - sscanf(&(*argp)[0], "%d", &a2); - printf(" to %d (0x%x)\n", a2, a2); - code = ubik_Call(VL_ChangeAddr, cstruct, 0, a1, a2); - if (code) { - printf("VL_ChangeAddr returned code = %d\n", code); - continue; - } - } else if ((!strcmp(oper,"?")) || !strcmp(oper,"h")) - print_usage(); - else if ((!strcmp(oper,"q")) || !strcmp(oper, "quit")) - exit(0); - else { - printf("Unknown oper!\n"); - } + } else if (!strcmp(oper, "ca")) { + extern struct hostent *hostutil_GetHostByName(); + struct hostent *h1, *h2; + afs_uint32 a1, a2; + + printf("changing %s", *argp); + h1 = hostutil_GetHostByName(&(*argp)[0]); + if (!h1) { + printf("cmdebug: can't resolve address for host %s", + *argp); + continue; + } + memcpy(&a1, (afs_int32 *) h1->h_addr, sizeof(afs_uint32)); + + ++argp, --nargs; + printf(" to %s\n", *argp); + h2 = hostutil_GetHostByName(&(*argp)[0]); + if (!h2) { + printf("cmdebug: can't resolve address for host %s", + *argp); + continue; + } + memcpy(&a2, (afs_int32 *) h2->h_addr, sizeof(afs_uint32)); + + printf("changing 0x%x to 0x%x\n", ntohl(a1), ntohl(a2)); + code = + ubik_Call(VL_ChangeAddr, cstruct, 0, ntohl(a1), + ntohl(a2)); + if (code) { + printf("VL_ChangeAddr returned code = %d\n", code); + continue; + } + } else if (!strcmp(oper, "caid")) { + afs_uint32 a1, a2; + + sscanf(&(*argp)[0], "%d", &a1); + printf("changing %d (0x%x)", a1, a1); + ++argp, --nargs; + sscanf(&(*argp)[0], "%d", &a2); + printf(" to %d (0x%x)\n", a2, a2); + code = ubik_Call(VL_ChangeAddr, cstruct, 0, a1, a2); + if (code) { + printf("VL_ChangeAddr returned code = %d\n", code); + continue; + } + } else if ((!strcmp(oper, "?")) || !strcmp(oper, "h")) + print_usage(); + else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit")) + exit(0); + else { + printf("Unknown oper!\n"); + } } } } @@ -956,20 +1116,26 @@ static handleit(as) #include "AFS_component_version_number.c" main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; { register struct cmd_syndesc *ts; afs_int32 code; strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH); ts = cmd_CreateSyntax("initcmd", handleit, 0, "initialize the program"); - cmd_AddParm(ts, "-cellpath", CMD_LIST, CMD_OPTIONAL, "Cell configuration directory"); - cmd_AddParm(ts, "-server", CMD_LIST, CMD_OPTIONAL, "Use the cell config in /usr/afs/etc (default /usr/vice/etc)"); - cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "Run it without authentication"); - cmd_AddParm(ts, "-host", CMD_LIST, CMD_OPTIONAL, "vldb server to talk to"); - cmd_AddParm(ts, "-cell", CMD_LIST, CMD_OPTIONAL, "cellname '-host' belongs to (required for auth conns)"); - cmd_AddParm(ts, "-getstats", CMD_FLAG, CMD_OPTIONAL, "print vldb statistics (non interactive)"); + cmd_AddParm(ts, "-cellpath", CMD_LIST, CMD_OPTIONAL, + "Cell configuration directory"); + cmd_AddParm(ts, "-server", CMD_LIST, CMD_OPTIONAL, + "Use the cell config in /usr/afs/etc (default /usr/vice/etc)"); + cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, + "Run it without authentication"); + cmd_AddParm(ts, "-host", CMD_LIST, CMD_OPTIONAL, + "vldb server to talk to"); + cmd_AddParm(ts, "-cell", CMD_LIST, CMD_OPTIONAL, + "cellname '-host' belongs to (required for auth conns)"); + cmd_AddParm(ts, "-getstats", CMD_FLAG, CMD_OPTIONAL, + "print vldb statistics (non interactive)"); code = cmd_Dispatch(argc, argv); exit(code); } @@ -977,9 +1143,9 @@ main(argc, argv) void fill_entry(entry, argp, nargs) -struct vldbentry *entry; -char **argp; -int nargs; + struct vldbentry *entry; + char **argp; + int nargs; { char *name; int i; @@ -990,20 +1156,20 @@ int nargs; ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->nServers); strcpy(entry->name, name); - for (i=0; i < entry->nServers; i++) { - ++argp, --nargs; + for (i = 0; i < entry->nServers; i++) { + ++argp, --nargs; sscanf(&(*argp)[0], "%u", &entry->serverNumber[i]); } - for (i=0; i < entry->nServers; i++) { - ++argp, --nargs; + for (i = 0; i < entry->nServers; i++) { + ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->serverPartition[i]); } - for (i=0; i < entry->nServers; i++) { - ++argp, --nargs; + for (i = 0; i < entry->nServers; i++) { + ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->serverFlags[i]); } - for (i=0; i < MAXTYPES; i++) { - ++argp, --nargs; + for (i = 0; i < MAXTYPES; i++) { + ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->volumeId[i]); } ++argp, --nargs; @@ -1014,9 +1180,9 @@ int nargs; void fill_update_entry(entry, argp, nargs) -struct VldbUpdateEntry *entry; -char **argp; -int nargs; + struct VldbUpdateEntry *entry; + char **argp; + int nargs; { int i, Mask; char *name; @@ -1047,83 +1213,88 @@ int nargs; sscanf(&(*argp)[0], "%d", &entry->nModifiedRepsites); if (entry->nModifiedRepsites != -1) entry->Mask |= VLUPDATE_REPSITES; - for (i=0; i < entry->nModifiedRepsites; i++) { - ++argp, --nargs; + for (i = 0; i < entry->nModifiedRepsites; i++) { + ++argp, --nargs; sscanf(&(*argp)[0], "%x", &Mask); - ++argp, --nargs; + ++argp, --nargs; sscanf(&(*argp)[0], "%u", &entry->RepsitesTargetServer[i]); - ++argp, --nargs; + ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->RepsitesTargetPart[i]); if (Mask & VLUPDATE_REPS_DELETE) entry->RepsitesMask[i] |= VLUPDATE_REPS_DELETE; if (Mask & VLUPDATE_REPS_MODSERV) { - ++argp, --nargs; + ++argp, --nargs; sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]); entry->RepsitesMask[i] |= VLUPDATE_REPS_MODSERV; } else if (Mask & VLUPDATE_REPS_MODPART) { - ++argp, --nargs; + ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]); entry->RepsitesMask[i] |= VLUPDATE_REPS_MODPART; } else if (Mask & VLUPDATE_REPS_MODFLAG) { - ++argp, --nargs; + ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]); entry->RepsitesMask[i] |= VLUPDATE_REPS_MODFLAG; } else if (Mask & VLUPDATE_REPS_ADD) { - ++argp, --nargs; + ++argp, --nargs; sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]); - ++argp, --nargs; + ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]); - ++argp, --nargs; + ++argp, --nargs; sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]); entry->RepsitesMask[i] |= VLUPDATE_REPS_ADD; } } - } +} void fill_listattributes_entry(entry, argp, nargs) - struct VldbListByAttributes *entry; - char **argp; - int nargs; + struct VldbListByAttributes *entry; + char **argp; + int nargs; { entry->Mask = 0; - if (nargs <= 0) return; + if (nargs <= 0) + return; entry->server = ntohl(GetServer(argp[0])); sscanf(&(*argp)[0], "%d", &entry->server); if (entry->server != 0) entry->Mask |= VLLIST_SERVER; ++argp, --nargs; - if (nargs <= 0) return; + if (nargs <= 0) + return; sscanf(&(*argp)[0], "%d", &entry->partition); if (entry->partition != -1) entry->Mask |= VLLIST_PARTITION; ++argp, --nargs; - if (nargs <= 0) return; + if (nargs <= 0) + return; sscanf(&(*argp)[0], "%d", &entry->volumeid); if (entry->volumeid != -1) entry->Mask |= VLLIST_VOLUMEID; ++argp, --nargs; - if (nargs <= 0) return; + if (nargs <= 0) + return; sscanf(&(*argp)[0], "%d", &entry->flag); if (entry->flag != -1) entry->Mask |= VLLIST_FLAG; - } +} void display_listattributes_entry(entry, error) -struct VldbListByAttributes *entry; -int error; + struct VldbListByAttributes *entry; + int error; { - if (error) return; + if (error) + return; printf("\nList entry values (Mask=%x)\n", entry->Mask); if (entry->Mask & VLLIST_SERVER) - printf("\tServer: %d.%d.%d.%d\n", - (entry->server>>24) & 0xff, (entry->server>>16) & 0xff, - (entry->server>> 8) & 0xff, (entry->server) & 0xff); + printf("\tServer: %d.%d.%d.%d\n", (entry->server >> 24) & 0xff, + (entry->server >> 16) & 0xff, (entry->server >> 8) & 0xff, + (entry->server) & 0xff); if (entry->Mask & VLLIST_PARTITION) printf("\tPartition: %d\n", entry->partition); if (entry->Mask & VLLIST_VOLUMEID) @@ -1137,56 +1308,62 @@ int error; void display_entry(entry, error) -struct vldbentry *entry; -int error; + struct vldbentry *entry; + int error; { int i; - - if (error) return; - printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n", entry->name, entry->volumeId[RWVOL], entry->flags); - printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ", entry->volumeId[0], entry->volumeId[1], entry->volumeId[2], entry->cloneId); - printf("nServers=%d\n", entry->nServers); + + if (error) + return; + printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n", + entry->name, entry->volumeId[RWVOL], entry->flags); + printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ", + entry->volumeId[0], entry->volumeId[1], entry->volumeId[2], + entry->cloneId); + printf("nServers=%d\n", entry->nServers); printf("ServerNumber\tServerPart\tserverFlag\n"); - for (i=0; i < entry->nServers; i++) - printf("%12u\t%10d\t%10x\n", entry->serverNumber[i], entry->serverPartition[i], entry->serverFlags[i]); + for (i = 0; i < entry->nServers; i++) + printf("%12u\t%10d\t%10x\n", entry->serverNumber[i], + entry->serverPartition[i], entry->serverFlags[i]); } void display_entryN(entry, error) - struct nvldbentry *entry; - int error; + struct nvldbentry *entry; + int error; { int i, et, ei; - - if (error) return; + + if (error) + return; printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n", entry->name, entry->volumeId[RWVOL], entry->flags); printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ", - entry->volumeId[0], entry->volumeId[1], - entry->volumeId[2], entry->cloneId); - printf("nServers=%d\n", entry->nServers); + entry->volumeId[0], entry->volumeId[1], entry->volumeId[2], + entry->cloneId); + printf("nServers=%d\n", entry->nServers); printf("ServerNumber\tServerPart\tserverFlag\n"); ei = entry->matchindex & 0xffff; et = (entry->matchindex >> 16) & 0xffff; - for (i=0; i < entry->nServers; i++) { - printf("%12u\t%10d\t%10x", - entry->serverNumber[i], entry->serverPartition[i], - entry->serverFlags[i]); - if (i == ei) { - printf(" <--- %s", (et==4)?"RW":((et==8)?"BK":"RO")); - } - printf("\n"); - } + for (i = 0; i < entry->nServers; i++) { + printf("%12u\t%10d\t%10x", entry->serverNumber[i], + entry->serverPartition[i], entry->serverFlags[i]); + if (i == ei) { + printf(" <--- %s", (et == 4) ? "RW" : ((et == 8) ? "BK" : "RO")); + } + printf("\n"); + } } void display_update_entry(entry, error) -struct VldbUpdateEntry *entry; -int error; + struct VldbUpdateEntry *entry; + int error; { int i; - - if (error) return; + + if (error) + return; printf("\nUpdate entry values (Mask=%x)\n", entry->Mask); if (entry->Mask & VLUPDATE_VOLUMENAME) printf("\tNew name: %s\n", entry->name); @@ -1201,17 +1378,22 @@ int error; if (entry->Mask & VLUPDATE_REPSITES) { printf("\tRepsites info:\n"); printf("\tFlag\tTServer\tTPart\tNServer\tNPart\tNFlag\n"); - for (i=0; i < entry->nModifiedRepsites; i++) { - printf("\t%4x\t%7U\t%5d", entry->RepsitesMask[i], entry->RepsitesTargetServer[i], entry->RepsitesTargetPart[i]); - if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD) || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV)) + for (i = 0; i < entry->nModifiedRepsites; i++) { + printf("\t%4x\t%7U\t%5d", entry->RepsitesMask[i], + entry->RepsitesTargetServer[i], + entry->RepsitesTargetPart[i]); + if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD) + || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV)) printf("\t%7U", entry->RepsitesNewServer[i]); else printf("\t-------"); - if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD) || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODPART)) + if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD) + || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODPART)) printf("\t%5d", entry->RepsitesNewPart[i]); else printf("\t-----"); - if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD) || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG)) + if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD) + || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG)) printf("\t%5x\n", entry->RepsitesNewFlags[i]); else printf("\t-----\n"); @@ -1221,28 +1403,34 @@ int error; void dump_stats(stats, vital_header) -vldstats *stats; -vital_vlheader *vital_header; -{ int i; + vldstats *stats; + vital_vlheader *vital_header; +{ + int i; char strg[30]; - strncpy(strg, ctime((time_t *)&stats->start_time), sizeof(strg)); - strg[strlen(strg)-1] = 0; + strncpy(strg, ctime((time_t *) & stats->start_time), sizeof(strg)); + strg[strlen(strg) - 1] = 0; printf("Dynamic statistics stats (starting time: %s):\n", strg); printf("OpcodeName\t# Requests\t# Aborts\n"); - for (i=0; i < VL_NUMBER_OPCODESX; i++) - printf("%10s\t%10d\t%8d\n", opcode_names[i], stats->requests[i], stats->aborts[i]); - printf("\nVldb header stats (version=%d)\n", ntohl(vital_header->vldbversion)); - printf("headersize=%d, allocs=%d, frees=%d, MaxVolid=%X\n", ntohl(vital_header->headersize), ntohl(vital_header->allocs), ntohl(vital_header->frees), ntohl(vital_header->MaxVolumeId)); - for (i=0; i < MAXTYPES; i++) - printf("total %s entries=%d\n", volumetype_string(i), ntohl(vital_header->totalEntries[i])); + for (i = 0; i < VL_NUMBER_OPCODESX; i++) + printf("%10s\t%10d\t%8d\n", opcode_names[i], stats->requests[i], + stats->aborts[i]); + printf("\nVldb header stats (version=%d)\n", + ntohl(vital_header->vldbversion)); + printf("headersize=%d, allocs=%d, frees=%d, MaxVolid=%X\n", + ntohl(vital_header->headersize), ntohl(vital_header->allocs), + ntohl(vital_header->frees), ntohl(vital_header->MaxVolumeId)); + for (i = 0; i < MAXTYPES; i++) + printf("total %s entries=%d\n", volumetype_string(i), + ntohl(vital_header->totalEntries[i])); } void -GetArgs(line,args, nargs) - register char *line; - register char **args; - register int *nargs; +GetArgs(line, args, nargs) + register char *line; + register char **args; + register int *nargs; { *nargs = 0; while (*line) { @@ -1253,7 +1441,7 @@ GetArgs(line,args, nargs) *last = 0; if (!*line) break; - *args++ = line, (*nargs)++; + *args++ = line, (*nargs)++; while (*line && *line != ' ') line++; } @@ -1265,7 +1453,8 @@ print_usage() printf("Valid Commands:\n"); printf(" CreateEntry:\n"); - printf("\tcr <#S> . . . \n"); + printf + ("\tcr <#S> . . . \n"); printf(" DeleteEntry:\n"); printf("\trm \n"); @@ -1274,7 +1463,8 @@ print_usage() printf("\tre \n"); printf(" UpdateEntry:\n"); - printf("\tup <#AddSer> [. . .] \n"); + printf + ("\tup <#AddSer> [. . .] \n"); printf(" ListEntry:\n"); printf("\tls\n"); @@ -1285,7 +1475,8 @@ print_usage() printf(" For each vlentry, find it by name, RW id, BK id, and RO id\n"); printf("\tcheckhash\n"); - printf(" UpdateEntry (update the volname, RW id, BK id, RO id hashes):\n"); + printf + (" UpdateEntry (update the volname, RW id, BK id, RO id hashes):\n"); printf("\tfixhash\n"); printf(" ListAttributes:\n"); diff --git a/src/vlserver/vlclient.h b/src/vlserver/vlclient.h index 6b58997a7..99e7a09f2 100644 --- a/src/vlserver/vlclient.h +++ b/src/vlserver/vlclient.h @@ -24,4 +24,3 @@ extern int VL_LinkedListN(); extern int VL_GetStats(); extern int VL_GetAddrs(); extern int VL_ChangeAddr(); - diff --git a/src/vlserver/vldb_check.c b/src/vlserver/vldb_check.c index 3e11b2eee..8e2c33942 100644 --- a/src/vlserver/vldb_check.c +++ b/src/vlserver/vldb_check.c @@ -9,22 +9,23 @@ /* Read a VLDB file and verify it for correctness */ -#define VL 0x001 /* good volume entry */ -#define FR 0x002 /* free volume entry */ -#define MH 0x004 /* multi-homed entry */ +#define VL 0x001 /* good volume entry */ +#define FR 0x002 /* free volume entry */ +#define MH 0x004 /* multi-homed entry */ -#define RWH 0x010 /* on rw hash chain */ -#define ROH 0x020 /* on ro hash chain */ -#define BKH 0x040 /* on bk hash chain */ -#define NH 0x080 /* on name hash chain */ +#define RWH 0x010 /* on rw hash chain */ +#define ROH 0x020 /* on ro hash chain */ +#define BKH 0x040 /* on bk hash chain */ +#define NH 0x080 /* on name hash chain */ -#define MHC 0x100 /* on multihomed chain */ -#define FRC 0x200 /* on free chain */ +#define MHC 0x100 /* on multihomed chain */ +#define FRC 0x200 /* on free chain */ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vldb_check.c,v 1.1.1.7 2001/10/14 18:07:16 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vlserver/vldb_check.c,v 1.11 2003/11/29 21:38:04 jaltman Exp $"); #include #include @@ -39,6 +40,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vldb_check.c,v 1.1.1.7 2001/10 #include #include #endif + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include "vlserver.h" #include "vldbint.h" #include @@ -49,316 +59,357 @@ int fd; int listentries, listservers, listheader, listuheader, verbose; struct er { - long addr; - int type; + long addr; + int type; } *record; -int serveraddrs[MAXSERVERID+2]; - +int serveraddrs[MAXSERVERID + 2]; + #define HDRSIZE 64 -int readUbikHeader() +int +readUbikHeader() { - int offset, r; - struct ubik_hdr uheader; - - offset = lseek(fd, 0, 0); - if (offset != 0) { - printf("error: lseek to 0 failed: %d %d\n", offset, errno); - return(-1); - } - - /* now read the info */ - r = read(fd, &uheader, sizeof(uheader)); - if (r != sizeof(uheader)) { - printf("error: read of %d bytes failed: %d %d\n", sizeof(uheader), r, errno); - return(-1); - } - - uheader.magic = ntohl(uheader.magic); - uheader.size = ntohl(uheader.size); - uheader.version.epoch = ntohl(uheader.version.epoch); - uheader.version.counter = ntohl(uheader.version.counter); - - if (listuheader) { - printf("Ubik Header\n"); - printf(" Magic = 0x%x\n", uheader.magic); - printf(" Size = %u\n", uheader.size); - printf(" Version.epoch = %u\n", uheader.version.epoch); - printf(" Version.counter = %u\n", uheader.version.counter); - } - - if (uheader.size != HDRSIZE) - printf("Ubik header size is %u (should be %u)\n", uheader.size, HDRSIZE); - if (uheader.magic != UBIK_MAGIC) - printf("Ubik header magic is 0x%x (should be 0x%x)\n", uheader.magic, UBIK_MAGIC); - - return(0); + int offset, r; + struct ubik_hdr uheader; + + offset = lseek(fd, 0, 0); + if (offset != 0) { + printf("error: lseek to 0 failed: %d %d\n", offset, errno); + return (-1); + } + + /* now read the info */ + r = read(fd, &uheader, sizeof(uheader)); + if (r != sizeof(uheader)) { + printf("error: read of %d bytes failed: %d %d\n", sizeof(uheader), r, + errno); + return (-1); + } + + uheader.magic = ntohl(uheader.magic); + uheader.size = ntohl(uheader.size); + uheader.version.epoch = ntohl(uheader.version.epoch); + uheader.version.counter = ntohl(uheader.version.counter); + + if (listuheader) { + printf("Ubik Header\n"); + printf(" Magic = 0x%x\n", uheader.magic); + printf(" Size = %u\n", uheader.size); + printf(" Version.epoch = %u\n", uheader.version.epoch); + printf(" Version.counter = %u\n", uheader.version.counter); + } + + if (uheader.size != HDRSIZE) + printf("Ubik header size is %u (should be %u)\n", uheader.size, + HDRSIZE); + if (uheader.magic != UBIK_MAGIC) + printf("Ubik header magic is 0x%x (should be 0x%x)\n", uheader.magic, + UBIK_MAGIC); + + return (0); } -int vldbread(position,buffer,size) - int position; - char *buffer; - int size; +int +vldbread(position, buffer, size) + int position; + char *buffer; + int size; { - int offset, r, p; - - /* seek to the correct spot. skip ubik stuff */ - p = position + HDRSIZE; - offset = lseek(fd, p, 0); - if (offset != p) { - printf("error: lseek to %d failed: %d %d\n", p, offset, errno); - return(-1); - } - - /* now read the info */ - r = read(fd, buffer, size); - if (r != size) { - printf("error: read of %d bytes failed: %d %d\n", size, r, errno); - return(-1); - } - return(0); + int offset, r, p; + + /* seek to the correct spot. skip ubik stuff */ + p = position + HDRSIZE; + offset = lseek(fd, p, 0); + if (offset != p) { + printf("error: lseek to %d failed: %d %d\n", p, offset, errno); + return (-1); + } + + /* now read the info */ + r = read(fd, buffer, size); + if (r != size) { + printf("error: read of %d bytes failed: %d %d\n", size, r, errno); + return (-1); + } + return (0); } -char *vtype(type) - int type; +char * +vtype(type) + int type; { - static char Type[3]; - - if (type == 0) strcpy(Type,"rw"); - else if (type == 1) strcpy(Type,"ro"); - else if (type == 2) strcpy(Type,"bk"); - else strcpy(Type,"??"); - return(Type); + static char Type[3]; + + if (type == 0) + strcpy(Type, "rw"); + else if (type == 1) + strcpy(Type, "ro"); + else if (type == 2) + strcpy(Type, "bk"); + else + strcpy(Type, "??"); + return (Type); } -afs_int32 NameHash(volname) - char *volname; +afs_int32 +NameHash(volname) + char *volname; { - unsigned int hash; - char *vchar; + unsigned int hash; + char *vchar; - hash = 0; - for (vchar=volname+strlen(volname)-1; vchar >= volname; vchar--) - hash = (hash*63) + (*((unsigned char *)vchar) - 63); - return(hash % HASHSIZE); + hash = 0; + for (vchar = volname + strlen(volname) - 1; vchar >= volname; vchar--) + hash = (hash * 63) + (*((unsigned char *)vchar) - 63); + return (hash % HASHSIZE); } -afs_int32 IdHash(volid) - afs_int32 volid; +afs_int32 +IdHash(volid) + afs_int32 volid; { - return((abs(volid)) % HASHSIZE); + return ((abs(volid)) % HASHSIZE); } #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" -int InvalidVolname(volname) - char *volname; +int +InvalidVolname(volname) + char *volname; { - char *map; - size_t slen; - - map = LEGALCHARS; - slen = strlen(volname); - if (slen >= VL_MAXNAMELEN) return 1; - return (slen != strspn(volname, map)); + char *map; + size_t slen; + + map = LEGALCHARS; + slen = strlen(volname); + if (slen >= VL_MAXNAMELEN) + return 1; + return (slen != strspn(volname, map)); } readheader(headerp) - struct vlheader *headerp; + struct vlheader *headerp; { - int i,j; - - vldbread(0, headerp, sizeof(*headerp)); - - headerp->vital_header.vldbversion = ntohl(headerp->vital_header.vldbversion); - headerp->vital_header.headersize = ntohl(headerp->vital_header.headersize); - headerp->vital_header.freePtr = ntohl(headerp->vital_header.freePtr); - headerp->vital_header.eofPtr = ntohl(headerp->vital_header.eofPtr); - headerp->vital_header.allocs = ntohl(headerp->vital_header.allocs); - headerp->vital_header.frees = ntohl(headerp->vital_header.frees); - headerp->vital_header.MaxVolumeId = ntohl(headerp->vital_header.MaxVolumeId); - headerp->vital_header.totalEntries[0] = ntohl(headerp->vital_header.totalEntries[0]); - for (i=0; ivital_header.totalEntries[i] = ntohl(headerp->vital_header.totalEntries[1]); - - headerp->SIT = ntohl(headerp->SIT); - for (i=0; iIpMappedAddr[i] = ntohl(headerp->IpMappedAddr[i]); - for (i=0; iVolnameHash[i] = ntohl(headerp->VolnameHash[i]); - for (i=0; iVolidHash[i][j] = ntohl(headerp->VolidHash[i][j]); - - if (listheader) { - printf("vldb header\n"); - printf(" vldbversion = %u\n", headerp->vital_header.vldbversion); - printf(" headersize = %u [actual=%u]\n", - headerp->vital_header.headersize, sizeof(*headerp)); - printf(" freePtr = 0x%x\n", headerp->vital_header.freePtr); - printf(" eofPtr = %u\n", headerp->vital_header.eofPtr); - printf(" allocblock calls = %10u\n", headerp->vital_header.allocs); - printf(" freeblock calls = %10u\n", headerp->vital_header.frees); - printf(" MaxVolumeId = %u\n", headerp->vital_header.MaxVolumeId); - printf(" rw vol entries = %u\n", headerp->vital_header.totalEntries[0]); - printf(" ro vol entries = %u\n", headerp->vital_header.totalEntries[1]); - printf(" bk vol entries = %u\n", headerp->vital_header.totalEntries[2]); - printf(" multihome info = 0x%x (%u)\n", headerp->SIT, headerp->SIT); - printf(" server ip addr table: size = %d entries\n", MAXSERVERID+1); - printf(" volume name hash table: size = %d buckets\n", HASHSIZE); - printf(" volume id hash table: %d tables with %d buckets each\n", - MAXTYPES, HASHSIZE); - } - - /* Check the header size */ - if (headerp->vital_header.headersize != sizeof(*headerp)) - printf("Header reports its size as %d (should be %d)\n", - headerp->vital_header.headersize, sizeof(*headerp)); + int i, j; + + vldbread(0, headerp, sizeof(*headerp)); + + headerp->vital_header.vldbversion = + ntohl(headerp->vital_header.vldbversion); + headerp->vital_header.headersize = + ntohl(headerp->vital_header.headersize); + headerp->vital_header.freePtr = ntohl(headerp->vital_header.freePtr); + headerp->vital_header.eofPtr = ntohl(headerp->vital_header.eofPtr); + headerp->vital_header.allocs = ntohl(headerp->vital_header.allocs); + headerp->vital_header.frees = ntohl(headerp->vital_header.frees); + headerp->vital_header.MaxVolumeId = + ntohl(headerp->vital_header.MaxVolumeId); + headerp->vital_header.totalEntries[0] = + ntohl(headerp->vital_header.totalEntries[0]); + for (i = 0; i < MAXTYPES; i++) + headerp->vital_header.totalEntries[i] = + ntohl(headerp->vital_header.totalEntries[1]); + + headerp->SIT = ntohl(headerp->SIT); + for (i = 0; i < MAXSERVERID; i++) + headerp->IpMappedAddr[i] = ntohl(headerp->IpMappedAddr[i]); + for (i = 0; i < HASHSIZE; i++) + headerp->VolnameHash[i] = ntohl(headerp->VolnameHash[i]); + for (i = 0; i < MAXTYPES; i++) + for (j = 0; j < HASHSIZE; j++) + headerp->VolidHash[i][j] = ntohl(headerp->VolidHash[i][j]); + + if (listheader) { + printf("vldb header\n"); + printf(" vldbversion = %u\n", + headerp->vital_header.vldbversion); + printf(" headersize = %u [actual=%u]\n", + headerp->vital_header.headersize, sizeof(*headerp)); + printf(" freePtr = 0x%x\n", headerp->vital_header.freePtr); + printf(" eofPtr = %u\n", headerp->vital_header.eofPtr); + printf(" allocblock calls = %10u\n", headerp->vital_header.allocs); + printf(" freeblock calls = %10u\n", headerp->vital_header.frees); + printf(" MaxVolumeId = %u\n", + headerp->vital_header.MaxVolumeId); + printf(" rw vol entries = %u\n", + headerp->vital_header.totalEntries[0]); + printf(" ro vol entries = %u\n", + headerp->vital_header.totalEntries[1]); + printf(" bk vol entries = %u\n", + headerp->vital_header.totalEntries[2]); + printf(" multihome info = 0x%x (%u)\n", headerp->SIT, + headerp->SIT); + printf(" server ip addr table: size = %d entries\n", + MAXSERVERID + 1); + printf(" volume name hash table: size = %d buckets\n", HASHSIZE); + printf(" volume id hash table: %d tables with %d buckets each\n", + MAXTYPES, HASHSIZE); + } + + /* Check the header size */ + if (headerp->vital_header.headersize != sizeof(*headerp)) + printf("Header reports its size as %d (should be %d)\n", + headerp->vital_header.headersize, sizeof(*headerp)); } readMH(addr, mhblockP) - afs_int32 addr; - struct extentaddr *mhblockP; + afs_int32 addr; + struct extentaddr *mhblockP; { - int i, j; - struct extentaddr *e; + int i, j; + struct extentaddr *e; - vldbread(addr, mhblockP, VL_ADDREXTBLK_SIZE); + vldbread(addr, mhblockP, VL_ADDREXTBLK_SIZE); - mhblockP->ex_count = ntohl(mhblockP->ex_count); - mhblockP->ex_flags = ntohl(mhblockP->ex_flags); - for (i=0; iex_contaddrs[i] = ntohl(mhblockP->ex_contaddrs[i]); + mhblockP->ex_count = ntohl(mhblockP->ex_count); + mhblockP->ex_flags = ntohl(mhblockP->ex_flags); + for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) + mhblockP->ex_contaddrs[i] = ntohl(mhblockP->ex_contaddrs[i]); - for (i=1; iex_uniquifier = ntohl(e->ex_uniquifier); - for (j=0; jex_addrs[j] = ntohl(e->ex_addrs[j]); - } -} + /* won't convert hostuuid */ + e->ex_uniquifier = ntohl(e->ex_uniquifier); + for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) + e->ex_addrs[j] = ntohl(e->ex_addrs[j]); + } +} readentry(addr, vlentryp, type) - afs_int32 addr; - struct nvlentry *vlentryp; - afs_int32 *type; + afs_int32 addr; + struct nvlentry *vlentryp; + afs_int32 *type; { - int i; - - vldbread(addr, vlentryp, sizeof(*vlentryp)); - - for (i=0; ivolumeId[i] = ntohl(vlentryp->volumeId[i]); - vlentryp->flags = ntohl(vlentryp->flags); - vlentryp->LockAfsId = ntohl(vlentryp->LockAfsId); - vlentryp->LockTimestamp = ntohl(vlentryp->LockTimestamp); - vlentryp->cloneId = ntohl(vlentryp->cloneId); - for (i=0; inextIdHash[i] = ntohl(vlentryp->nextIdHash[i]); - vlentryp->nextNameHash = ntohl(vlentryp->nextNameHash); - for (i=0; iserverNumber[i] = ntohl(vlentryp->serverNumber[i]); - vlentryp->serverPartition[i] = ntohl(vlentryp->serverPartition[i]); - vlentryp->serverFlags[i] = ntohl(vlentryp->serverFlags[i]); - } - - if (vlentryp->flags == VLCONTBLOCK) { - *type = MH; - } else if (vlentryp->flags == VLFREE) { - *type = FR; - } else { - *type = VL; - } - - if (listentries) { - printf("address %u: ", addr); - if (vlentryp->flags == VLCONTBLOCK) { - printf("mh extension block\n"); - } else if (vlentryp->flags == VLFREE) { - printf("free vlentry\n"); - } else { - printf("vlentry %s\n", vlentryp->name); - printf(" rw id = %u ; ro id = %u ; bk id = %u\n", - vlentryp->volumeId[0], vlentryp->volumeId[1], vlentryp->volumeId[2]); - printf(" flags ="); - if (vlentryp->flags & VLF_RWEXISTS) printf(" rw"); - if (vlentryp->flags & VLF_ROEXISTS) printf(" ro"); - if (vlentryp->flags & VLF_BACKEXISTS) printf(" bk"); - if (vlentryp->flags & 0xffff8fff) - printf(" errorflag(0x%x)", vlentryp->flags); - printf("\n"); - printf(" LockAfsId = %d\n", vlentryp->LockAfsId); - printf(" LockTimestamp = %d\n", vlentryp->LockTimestamp); - printf(" cloneId = %u\n", vlentryp->cloneId); - printf(" next hash for rw = %u ; ro = %u ; bk = %u ; name = %u\n", - vlentryp->nextIdHash[0], vlentryp->nextIdHash[1], - vlentryp->nextIdHash[2], vlentryp->nextNameHash); - for (i=0; iserverNumber[i] != 255) { - printf(" server %d ; partition %d ; flags =", - vlentryp->serverNumber[i], vlentryp->serverPartition[i]); - if (vlentryp->serverFlags[i] & VLSF_RWVOL) printf(" rw"); - if (vlentryp->serverFlags[i] & VLSF_ROVOL) printf(" ro"); - if (vlentryp->serverFlags[i] & VLSF_BACKVOL) printf(" bk"); - if (vlentryp->serverFlags[i] & VLSF_NEWREPSITE) printf(" newro"); - printf("\n"); - } + int i; + + vldbread(addr, vlentryp, sizeof(*vlentryp)); + + for (i = 0; i < MAXTYPES; i++) + vlentryp->volumeId[i] = ntohl(vlentryp->volumeId[i]); + vlentryp->flags = ntohl(vlentryp->flags); + vlentryp->LockAfsId = ntohl(vlentryp->LockAfsId); + vlentryp->LockTimestamp = ntohl(vlentryp->LockTimestamp); + vlentryp->cloneId = ntohl(vlentryp->cloneId); + for (i = 0; i < MAXTYPES; i++) + vlentryp->nextIdHash[i] = ntohl(vlentryp->nextIdHash[i]); + vlentryp->nextNameHash = ntohl(vlentryp->nextNameHash); + for (i = 0; i < NMAXNSERVERS; i++) { + vlentryp->serverNumber[i] = ntohl(vlentryp->serverNumber[i]); + vlentryp->serverPartition[i] = ntohl(vlentryp->serverPartition[i]); + vlentryp->serverFlags[i] = ntohl(vlentryp->serverFlags[i]); + } + + if (vlentryp->flags == VLCONTBLOCK) { + *type = MH; + } else if (vlentryp->flags == VLFREE) { + *type = FR; + } else { + *type = VL; + } + + if (listentries) { + printf("address %u: ", addr); + if (vlentryp->flags == VLCONTBLOCK) { + printf("mh extension block\n"); + } else if (vlentryp->flags == VLFREE) { + printf("free vlentry\n"); + } else { + printf("vlentry %s\n", vlentryp->name); + printf(" rw id = %u ; ro id = %u ; bk id = %u\n", + vlentryp->volumeId[0], vlentryp->volumeId[1], + vlentryp->volumeId[2]); + printf(" flags ="); + if (vlentryp->flags & VLF_RWEXISTS) + printf(" rw"); + if (vlentryp->flags & VLF_ROEXISTS) + printf(" ro"); + if (vlentryp->flags & VLF_BACKEXISTS) + printf(" bk"); + if (vlentryp->flags & 0xffff8fff) + printf(" errorflag(0x%x)", vlentryp->flags); + printf("\n"); + printf(" LockAfsId = %d\n", vlentryp->LockAfsId); + printf(" LockTimestamp = %d\n", vlentryp->LockTimestamp); + printf(" cloneId = %u\n", vlentryp->cloneId); + printf + (" next hash for rw = %u ; ro = %u ; bk = %u ; name = %u\n", + vlentryp->nextIdHash[0], vlentryp->nextIdHash[1], + vlentryp->nextIdHash[2], vlentryp->nextNameHash); + for (i = 0; i < NMAXNSERVERS; i++) { + if (vlentryp->serverNumber[i] != 255) { + printf(" server %d ; partition %d ; flags =", + vlentryp->serverNumber[i], + vlentryp->serverPartition[i]); + if (vlentryp->serverFlags[i] & VLSF_RWVOL) + printf(" rw"); + if (vlentryp->serverFlags[i] & VLSF_ROVOL) + printf(" ro"); + if (vlentryp->serverFlags[i] & VLSF_BACKVOL) + printf(" bk"); + if (vlentryp->serverFlags[i] & VLSF_NEWREPSITE) + printf(" newro"); + printf("\n"); + } + } } - } - } + } } void readSIT(base, addr) - int base; - int addr; + int base; + int addr; { - int i,j,a; - char sitbuf[VL_ADDREXTBLK_SIZE]; - struct extentaddr *extent; - - if (!addr) - return; - vldbread(addr, sitbuf, VL_ADDREXTBLK_SIZE); - extent = (struct extentaddr *)sitbuf; - - printf("multihome info block: base %d\n", base); - if (base == 0) { - printf(" count = %u\n", ntohl(extent->ex_count)); - printf(" flags = %u\n", ntohl(extent->ex_flags)); - for (i=0; iex_contaddrs[i])); - } - } - for (i=1; i= VL_MAX_ADDREXTBLKS) continue; - - printf(" base %d index %d:\n", base, i); - - printf(" afsuuid = (%x %x %x /%d/%d/ /%x/%x/%x/%x/%x/%x/)\n", - ntohl(extent[i].ex_hostuuid.time_low), - ntohl(extent[i].ex_hostuuid.time_mid), - ntohl(extent[i].ex_hostuuid.time_hi_and_version), - ntohl(extent[i].ex_hostuuid.clock_seq_hi_and_reserved), - ntohl(extent[i].ex_hostuuid.clock_seq_low), - ntohl(extent[i].ex_hostuuid.node[0]), ntohl(extent[i].ex_hostuuid.node[1]), - ntohl(extent[i].ex_hostuuid.node[2]), ntohl(extent[i].ex_hostuuid.node[3]), - ntohl(extent[i].ex_hostuuid.node[4]), ntohl(extent[i].ex_hostuuid.node[5])); - printf(" uniquifier = %u\n", ntohl(extent[i].ex_uniquifier)); - for (j=0; j>24)&0xff, (a>>16)&0xff, - (a>>8) &0xff, (a )&0xff); + int i, j, a; + char sitbuf[VL_ADDREXTBLK_SIZE]; + struct extentaddr *extent; + + if (!addr) + return; + vldbread(addr, sitbuf, VL_ADDREXTBLK_SIZE); + extent = (struct extentaddr *)sitbuf; + + printf("multihome info block: base %d\n", base); + if (base == 0) { + printf(" count = %u\n", ntohl(extent->ex_count)); + printf(" flags = %u\n", ntohl(extent->ex_flags)); + for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) { + printf(" contaddrs[%d] = %u\n", i, + ntohl(extent->ex_contaddrs[i])); + } + } + for (i = 1; i < VL_MHSRV_PERBLK; i++) { + /* should we skip this entry */ + for (j = 0; j < VL_MAX_ADDREXTBLKS; j++) { + if (extent[i].ex_addrs[j]) + break; } - } - } + if (j >= VL_MAX_ADDREXTBLKS) + continue; + + printf(" base %d index %d:\n", base, i); + + printf(" afsuuid = (%x %x %x /%d/%d/ /%x/%x/%x/%x/%x/%x/)\n", + ntohl(extent[i].ex_hostuuid.time_low), + ntohl(extent[i].ex_hostuuid.time_mid), + ntohl(extent[i].ex_hostuuid.time_hi_and_version), + ntohl(extent[i].ex_hostuuid.clock_seq_hi_and_reserved), + ntohl(extent[i].ex_hostuuid.clock_seq_low), + ntohl(extent[i].ex_hostuuid.node[0]), + ntohl(extent[i].ex_hostuuid.node[1]), + ntohl(extent[i].ex_hostuuid.node[2]), + ntohl(extent[i].ex_hostuuid.node[3]), + ntohl(extent[i].ex_hostuuid.node[4]), + ntohl(extent[i].ex_hostuuid.node[5])); + printf(" uniquifier = %u\n", ntohl(extent[i].ex_uniquifier)); + for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) { + a = ntohl(extent[i].ex_addrs[j]); + if (a) { + printf(" %d.%d.%d.%d\n", (a >> 24) & 0xff, + (a >> 16) & 0xff, (a >> 8) & 0xff, (a) & 0xff); + } + } + } } /* @@ -368,83 +419,92 @@ readSIT(base, addr) */ void ReadAllEntries(header) - struct vlheader *header; + struct vlheader *header; { - afs_int32 type, rindex, i, j, e; - int freecount=0, mhcount=0, vlcount=0; - int rwcount=0, rocount=0, bkcount=0; - struct nvlentry vlentry; - afs_uint32 addr, entrysize, maxvolid=0; - - if (verbose) - printf("Read each entry in the database\n"); - for (addr = header->vital_header.headersize; - addr < header->vital_header.eofPtr; addr += entrysize) { - - /* Remember the highest volume id */ - readentry(addr, &vlentry, &type); - if (type == VL) { - if (!(vlentry.flags & VLF_RWEXISTS)) - printf("WARNING: VLDB entry '%s' has no RW volume\n", vlentry.name); - - for (i=0; ivital_header.headersize; + addr < header->vital_header.eofPtr; addr += entrysize) { + + /* Remember the highest volume id */ + readentry(addr, &vlentry, &type); + if (type == VL) { + if (!(vlentry.flags & VLF_RWEXISTS)) + printf("WARNING: VLDB entry '%s' has no RW volume\n", + vlentry.name); + + for (i = 0; i < MAXTYPES; i++) + if (maxvolid < vlentry.volumeId[i]) + maxvolid = vlentry.volumeId[i]; + + e = 1; + for (j = 0; j < NMAXNSERVERS; j++) { + if (vlentry.serverNumber[j] == 255) + continue; + if (vlentry.serverFlags[j] & (VLSF_ROVOL | VLSF_NEWREPSITE)) { + rocount++; + continue; + } + if (vlentry.serverFlags[j] & VLSF_RWVOL) { + rwcount++; + if (vlentry.flags & VLF_BACKEXISTS) + bkcount++; + continue; + } + if (e) { + printf + ("VLDB entry '%s' contains an unknown RW/RO index serverFlag\n", + vlentry.name); + e = 0; + } + printf + (" index %d : serverNumber %d : serverPartition %d : serverFlag %d\n", + j, vlentry.serverNumber[j], vlentry.serverPartition[j], + vlentry.serverFlags[j]); + } } - } - rindex = addr/sizeof(vlentry); - if (record[rindex].type) { - printf("INTERNAL ERROR: record holder %d already in use\n", rindex); - return; - } - record[rindex].addr = addr; - record[rindex].type = type; - - /* Determine entrysize and keep count */ - if (type == VL) { - entrysize = sizeof(vlentry); - vlcount++; - } else if (type == FR) { - entrysize = sizeof(vlentry); - freecount++; - } else if (type == MH) { - entrysize = VL_ADDREXTBLK_SIZE; - mhcount++; - } else { - printf("Unknown entry at %u\n", addr); - } - } - if (verbose) { - printf("Found %d entries, %d free entries, %d multihomed blocks\n", - vlcount, freecount, mhcount); - printf("Found %d RW volumes, %d BK volumes, %d RO volumes\n", - rwcount, bkcount, rocount); - } - - /* Check the maxmimum volume id in the header */ - if (maxvolid != header->vital_header.MaxVolumeId-1) - printf("Header's maximum volume id is %u and largest id found in VLDB is %u\n", - header->vital_header.MaxVolumeId, maxvolid); + rindex = addr / sizeof(vlentry); + if (record[rindex].type) { + printf("INTERNAL ERROR: record holder %d already in use\n", + rindex); + return; + } + record[rindex].addr = addr; + record[rindex].type = type; + + /* Determine entrysize and keep count */ + if (type == VL) { + entrysize = sizeof(vlentry); + vlcount++; + } else if (type == FR) { + entrysize = sizeof(vlentry); + freecount++; + } else if (type == MH) { + entrysize = VL_ADDREXTBLK_SIZE; + mhcount++; + } else { + printf("Unknown entry at %u\n", addr); + } + } + if (verbose) { + printf("Found %d entries, %d free entries, %d multihomed blocks\n", + vlcount, freecount, mhcount); + printf("Found %d RW volumes, %d BK volumes, %d RO volumes\n", rwcount, + bkcount, rocount); + } + + /* Check the maxmimum volume id in the header */ + if (maxvolid != header->vital_header.MaxVolumeId - 1) + printf + ("Header's maximum volume id is %u and largest id found in VLDB is %u\n", + header->vital_header.MaxVolumeId, maxvolid); } @@ -454,54 +514,61 @@ ReadAllEntries(header) * Check that the name is hashed correctly. */ FollowNameHash(header) - struct vlheader *header; + struct vlheader *header; { - int count=0, longest=0, shortest=-1, chainlength; - struct nvlentry vlentry; - afs_uint32 addr; - afs_int32 i, type, rindex; - - /* Now follow the Name Hash Table */ - if (verbose) - printf("Check Volume Name Hash\n"); - for (i=0; iVolnameHash[i]; addr; addr=vlentry.nextNameHash) { - readentry(addr, &vlentry, &type); - if (type != VL) { - printf("Name Hash %d: Bad entry at %u: Not a valid vlentry\n", i, addr); - continue; - } - - rindex = addr/sizeof(vlentry); - - if (record[rindex].addr != addr && record[rindex].addr) { - printf("INTERNAL ERROR: addresses %u and %u use same record slot %d\n", - record[rindex].addr, addr, rindex); - } - if (record[rindex].type & NH) { - printf("Name Hash %d: Bad entry '%s': Already in the name hash\n", - i, vlentry.name); - break; - } - record[rindex].type |= NH; - - chainlength++; - count++; - - /* Hash the name and check if in correct hash table */ - if (NameHash(vlentry.name) != i) { - printf("Name Hash %d: Bad entry '%s': Incorrect name hash chain (should be in %d)\n", - i, vlentry.name, NameHash(vlentry.name)); + int count = 0, longest = 0, shortest = -1, chainlength; + struct nvlentry vlentry; + afs_uint32 addr; + afs_int32 i, type, rindex; + + /* Now follow the Name Hash Table */ + if (verbose) + printf("Check Volume Name Hash\n"); + for (i = 0; i < HASHSIZE; i++) { + chainlength = 0; + for (addr = header->VolnameHash[i]; addr; addr = vlentry.nextNameHash) { + readentry(addr, &vlentry, &type); + if (type != VL) { + printf("Name Hash %d: Bad entry at %u: Not a valid vlentry\n", + i, addr); + continue; + } + + rindex = addr / sizeof(vlentry); + + if (record[rindex].addr != addr && record[rindex].addr) { + printf + ("INTERNAL ERROR: addresses %u and %u use same record slot %d\n", + record[rindex].addr, addr, rindex); + } + if (record[rindex].type & NH) { + printf + ("Name Hash %d: Bad entry '%s': Already in the name hash\n", + i, vlentry.name); + break; + } + record[rindex].type |= NH; + + chainlength++; + count++; + + /* Hash the name and check if in correct hash table */ + if (NameHash(vlentry.name) != i) { + printf + ("Name Hash %d: Bad entry '%s': Incorrect name hash chain (should be in %d)\n", + i, vlentry.name, NameHash(vlentry.name)); + } } - } - if (chainlength > longest) longest = chainlength; - if ((shortest == -1) || (chainlength < shortest)) shortest = chainlength; - } - if (verbose) { - printf("%d entries in name hash, longest is %d, shortest is %d, average length is %f\n", - count, longest, shortest, ((float)count/(float)HASHSIZE)); - } + if (chainlength > longest) + longest = chainlength; + if ((shortest == -1) || (chainlength < shortest)) + shortest = chainlength; + } + if (verbose) { + printf + ("%d entries in name hash, longest is %d, shortest is %d, average length is %f\n", + count, longest, shortest, ((float)count / (float)HASHSIZE)); + } } /* @@ -510,60 +577,71 @@ FollowNameHash(header) * Check that the ID is hashed correctly. */ FollowIdHash(header) - struct vlheader *header; + struct vlheader *header; { - int count=0, longest=0, shortest=-1, chainlength; - struct nvlentry vlentry; - afs_uint32 addr; - afs_int32 i, j, hash, type, rindex; - - /* Now follow the RW, RO, and BK Hash Tables */ - if (verbose) - printf("Check RW, RO, and BK id Hashes\n"); - for (i=0; iVolidHash[i][j]; addr; addr=vlentry.nextIdHash[i]) { - readentry(addr, &vlentry, &type); - if (type != VL) { - printf("%s Id Hash %d: Bad entry at %u: Not a valid vlentry\n", - vtype(i), j, addr); - continue; - } - - rindex = addr/sizeof(vlentry); - if (record[rindex].addr != addr && record[rindex].addr) { - printf("INTERNAL ERROR: addresses %u and %u use same record slot %d\n", - record[rindex].addr, addr, rindex); - } - if (record[rindex].type & hash) { - printf("%s Id Hash %d: Bad entry '%s': Already in the the hash table\n", - vtype(i), j, vlentry.name); - break; - } - record[rindex].type |= hash; - - chainlength++; - count++; - - /* Hash the id and check if in correct hash table */ - if (IdHash(vlentry.volumeId[i]) != j) { - printf("%s Id Hash %d: Bad entry '%s': Incorrect Id hash chain (should be in %d)\n", - vtype(i), j, vlentry.name, IdHash(vlentry.volumeId[i])); - } + int count = 0, longest = 0, shortest = -1, chainlength; + struct nvlentry vlentry; + afs_uint32 addr; + afs_int32 i, j, hash, type, rindex; + + /* Now follow the RW, RO, and BK Hash Tables */ + if (verbose) + printf("Check RW, RO, and BK id Hashes\n"); + for (i = 0; i < MAXTYPES; i++) { + hash = ((i == 0) ? RWH : ((i == 1) ? ROH : BKH)); + count = longest = 0; + shortest = -1; + + for (j = 0; j < HASHSIZE; j++) { + chainlength = 0; + for (addr = header->VolidHash[i][j]; addr; + addr = vlentry.nextIdHash[i]) { + readentry(addr, &vlentry, &type); + if (type != VL) { + printf + ("%s Id Hash %d: Bad entry at %u: Not a valid vlentry\n", + vtype(i), j, addr); + continue; + } + + rindex = addr / sizeof(vlentry); + if (record[rindex].addr != addr && record[rindex].addr) { + printf + ("INTERNAL ERROR: addresses %u and %u use same record slot %d\n", + record[rindex].addr, addr, rindex); + } + if (record[rindex].type & hash) { + printf + ("%s Id Hash %d: Bad entry '%s': Already in the the hash table\n", + vtype(i), j, vlentry.name); + break; + } + record[rindex].type |= hash; + + chainlength++; + count++; + + /* Hash the id and check if in correct hash table */ + if (IdHash(vlentry.volumeId[i]) != j) { + printf + ("%s Id Hash %d: Bad entry '%s': Incorrect Id hash chain (should be in %d)\n", + vtype(i), j, vlentry.name, + IdHash(vlentry.volumeId[i])); + } + } + + if (chainlength > longest) + longest = chainlength; + if ((shortest == -1) || (chainlength < shortest)) + shortest = chainlength; } - - if (chainlength > longest) longest = chainlength; - if ((shortest == -1) || (chainlength < shortest)) shortest = chainlength; - } - if (verbose) { - printf("%d entries in %s hash, longest is %d, shortest is %d, average length is %f\n", - count, vtype(i), longest, shortest, ((float)count/(float)HASHSIZE)); - } - } + if (verbose) { + printf + ("%d entries in %s hash, longest is %d, shortest is %d, average length is %f\n", + count, vtype(i), longest, shortest, + ((float)count / (float)HASHSIZE)); + } + } } /* @@ -571,39 +649,43 @@ FollowIdHash(header) * Record we found it in the free chain within the record array. */ FollowFreeChain(header) - struct vlheader *header; + struct vlheader *header; { - afs_int32 count=0; - struct nvlentry vlentry; - afs_uint32 addr; - afs_int32 type, rindex; - - /* Now follow the Free Chain */ - if (verbose) - printf("Check Volume Free Chain\n"); - for (addr=header->vital_header.freePtr; addr; addr=vlentry.nextIdHash[0]) { - readentry(addr, &vlentry, &type); - if (type != FR) { - printf("Free Chain %d: Bad entry at %u: Not a valid free vlentry (0x%x)\n", - count, addr, type); - continue; - } - - rindex = addr/sizeof(vlentry); - if (record[rindex].addr != addr && record[rindex].addr) { - printf("INTERNAL ERROR: addresses %u and %u use same record slot %d\n", - record[rindex].addr, addr, rindex); - } - if (record[rindex].type & FRC) { - printf("Free Chain: Bad entry at %u: Already in the free chain\n", addr); - break; - } - record[rindex].type |= FRC; - - count++; - } - if (verbose) - printf("%d entries on free chain\n", count); + afs_int32 count = 0; + struct nvlentry vlentry; + afs_uint32 addr; + afs_int32 type, rindex; + + /* Now follow the Free Chain */ + if (verbose) + printf("Check Volume Free Chain\n"); + for (addr = header->vital_header.freePtr; addr; + addr = vlentry.nextIdHash[0]) { + readentry(addr, &vlentry, &type); + if (type != FR) { + printf + ("Free Chain %d: Bad entry at %u: Not a valid free vlentry (0x%x)\n", + count, addr, type); + continue; + } + + rindex = addr / sizeof(vlentry); + if (record[rindex].addr != addr && record[rindex].addr) { + printf + ("INTERNAL ERROR: addresses %u and %u use same record slot %d\n", + record[rindex].addr, addr, rindex); + } + if (record[rindex].type & FRC) { + printf("Free Chain: Bad entry at %u: Already in the free chain\n", + addr); + break; + } + record[rindex].type |= FRC; + + count++; + } + if (verbose) + printf("%d entries on free chain\n", count); } /* @@ -623,314 +705,351 @@ FollowFreeChain(header) * list. The vlserver does this when a fileserver registeres itself. */ CheckIpAddrs(header) - struct vlheader *header; + struct vlheader *header; { - int mhblocks=0; - afs_int32 i, j, m, rindex; - afs_int32 mhentries, regentries; - afs_int32 caddrs[VL_MAX_ADDREXTBLKS]; - char mhblock[VL_ADDREXTBLK_SIZE]; - struct extentaddr *MHblock = (struct extentaddr *)mhblock; - struct extentaddr *e; - int ipindex, ipaddrs; - afsUUID nulluuid; - - memset(&nulluuid, 0, sizeof(nulluuid)); - - if (verbose) - printf("Check Multihomed blocks\n"); - - if (header->SIT) { - /* Read the first MH block and from it, gather the - * addresses of all the mh blocks. - */ - readMH(header->SIT, MHblock); - if (MHblock->ex_flags != VLCONTBLOCK) { - printf("Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n", - header->SIT); - } - - for (i=0; iex_contaddrs[i]; - } - - if (header->SIT != caddrs[0]) { - printf("MH block does not point to self %u in header, %u in block\n", - header->SIT, caddrs[0]); - } - - /* Now read each MH block and record it in the record array */ - for (i=0; iSIT) { + /* Read the first MH block and from it, gather the + * addresses of all the mh blocks. + */ + readMH(header->SIT, MHblock); if (MHblock->ex_flags != VLCONTBLOCK) { - printf("Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n", - header->SIT); + printf + ("Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n", + header->SIT); } - rindex = caddrs[i]/sizeof(vlentry); - if (record[rindex].addr != caddrs[i] && record[rindex].addr) { - printf("INTERNAL ERROR: addresses %u and %u use same record slot %d\n", - record[rindex].addr, caddrs[i], rindex); - } - if (record[rindex].type & FRC) { - printf("MH Blocks Chain %d: Bad entry at %u: Already a MH block\n", i, record[rindex].addr); - break; + for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) { + caddrs[i] = MHblock->ex_contaddrs[i]; } - record[rindex].type |= MHC; - - mhblocks++; - /* Read each entry in a multihomed block. - * Find the pointer to the entry in the IpMappedAddr array and - * verify that the entry is good (has IP addresses in it). - */ - mhentries = 0; - for (j=1; jIpMappedAddr[ipindex] & 0xff000000) == 0xff000000) && - (((header->IpMappedAddr[ipindex] & 0x00ff0000)>>16) == i) && - ((header->IpMappedAddr[ipindex] & 0x0000ffff) == j) ) { - break; - } - } - if (ipindex >= MAXSERVERID) ipindex = -1; - else serveraddrs[ipindex] = -1; - - if (memcmp(&e->ex_hostuuid, &nulluuid, sizeof(afsUUID)) == 0) { - if (ipindex != -1) { - printf("Server Addrs index %d references null MH block %d, index %d\n", i, j); - serveraddrs[ipindex] = 0; /* avoids printing 2nd error below */ - } - continue; - } - - /* Step through each ip address and count the good addresses */ - ipaddrs = 0; - for (m=0; mex_addrs[m]) ipaddrs++; - } - - /* If we found any good ip addresses, mark it in the serveraddrs record */ - if (ipaddrs) { - mhentries++; - if (ipindex == -1) { - printf("MH block %d, index %d: Not referenced by server addrs\n", i, j); - } else { - serveraddrs[ipindex] = ipaddrs; /* It is good */ - } - } - - if (listservers && ipaddrs) { - printf("MH block %d, index %d:", i, j); - for (m=0; mex_addrs[m]) continue; - printf(" %d.%d.%d.%d", - (e->ex_addrs[m]&0xff000000)>>24, - (e->ex_addrs[m]&0x00ff0000)>>16, - (e->ex_addrs[m]&0x0000ff00)>>8, - (e->ex_addrs[m]&0x000000ff)); - } - printf("\n"); - } + if (header->SIT != caddrs[0]) { + printf + ("MH block does not point to self %u in header, %u in block\n", + header->SIT, caddrs[0]); } + + /* Now read each MH block and record it in the record array */ + for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) { + if (!caddrs[i]) + continue; + + readMH(caddrs[i], MHblock); + if (MHblock->ex_flags != VLCONTBLOCK) { + printf + ("Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n", + header->SIT); + } + + rindex = caddrs[i] / sizeof(vlentry); + if (record[rindex].addr != caddrs[i] && record[rindex].addr) { + printf + ("INTERNAL ERROR: addresses %u and %u use same record slot %d\n", + record[rindex].addr, caddrs[i], rindex); + } + if (record[rindex].type & FRC) { + printf + ("MH Blocks Chain %d: Bad entry at %u: Already a MH block\n", + i, record[rindex].addr); + break; + } + record[rindex].type |= MHC; + + mhblocks++; + + /* Read each entry in a multihomed block. + * Find the pointer to the entry in the IpMappedAddr array and + * verify that the entry is good (has IP addresses in it). + */ + mhentries = 0; + for (j = 1; j < VL_MHSRV_PERBLK; j++) { + e = (struct extentaddr *)&(MHblock[j]); + + /* Search the IpMappedAddr array for the reference to this entry */ + for (ipindex = 0; ipindex < MAXSERVERID; ipindex++) { + if (((header->IpMappedAddr[ipindex] & 0xff000000) == + 0xff000000) + && + (((header-> + IpMappedAddr[ipindex] & 0x00ff0000) >> 16) == i) + && ((header->IpMappedAddr[ipindex] & 0x0000ffff) == + j)) { + break; + } + } + if (ipindex >= MAXSERVERID) + ipindex = -1; + else + serveraddrs[ipindex] = -1; + + if (memcmp(&e->ex_hostuuid, &nulluuid, sizeof(afsUUID)) == 0) { + if (ipindex != -1) { + printf + ("Server Addrs index %d references null MH block %d, index %d\n", + ipindex, i, j); + serveraddrs[ipindex] = 0; /* avoids printing 2nd error below */ + } + continue; + } + + /* Step through each ip address and count the good addresses */ + ipaddrs = 0; + for (m = 0; m < VL_MAXIPADDRS_PERMH; m++) { + if (e->ex_addrs[m]) + ipaddrs++; + } + + /* If we found any good ip addresses, mark it in the serveraddrs record */ + if (ipaddrs) { + mhentries++; + if (ipindex == -1) { + printf + ("MH block %d, index %d: Not referenced by server addrs\n", + i, j); + } else { + serveraddrs[ipindex] = ipaddrs; /* It is good */ + } + } + + if (listservers && ipaddrs) { + printf("MH block %d, index %d:", i, j); + for (m = 0; m < VL_MAXIPADDRS_PERMH; m++) { + if (!e->ex_addrs[m]) + continue; + printf(" %d.%d.%d.%d", + (e->ex_addrs[m] & 0xff000000) >> 24, + (e->ex_addrs[m] & 0x00ff0000) >> 16, + (e->ex_addrs[m] & 0x0000ff00) >> 8, + (e->ex_addrs[m] & 0x000000ff)); + } + printf("\n"); + } + } /* * if (mhentries != MHblock->ex_count) { * printf("MH blocks says it has %d entries (found %d)\n", * MHblock->ex_count, mhentries); * } */ - } - } - if (verbose) - printf("%d multihomed blocks\n", mhblocks); - - /* Check the server addresses */ - if (verbose) - printf("Check server addresses\n"); - mhentries = regentries = 0; - for (i=0; i<=MAXSERVERID; i++) { - if (header->IpMappedAddr[i]) { - if ((header->IpMappedAddr[i] & 0xff000000) == 0xff000000) { - mhentries++; - if (((header->IpMappedAddr[i] & 0x00ff0000)>>16) > VL_MAX_ADDREXTBLKS) - printf("IP Addr for entry %d: Multihome block is bad (%d)\n", - i, ((header->IpMappedAddr[i] & 0x00ff0000)>>16)); - if ( ((header->IpMappedAddr[i] & 0x0000ffff) > VL_MHSRV_PERBLK) || - ((header->IpMappedAddr[i] & 0x0000ffff) < 1) ) - printf("IP Addr for entry %d: Multihome index is bad (%d)\n", - i, (header->IpMappedAddr[i] & 0x0000ffff)); - if (serveraddrs[i] == -1) { - printf("warning: IP Addr for entry %d: Multihome entry has no ip addresses\n", i); - serveraddrs[i] = 0; - } - if (listservers) { - printf(" Server ip addr %d = MH block %d, index %d\n", i, - (header->IpMappedAddr[i] & 0x00ff0000)>>16, - (header->IpMappedAddr[i] & 0x0000ffff)); - } - } else { - regentries++; - serveraddrs[i] = 1; /* It is good */ - if (listservers) { - printf(" Server ip addr %d = %d.%d.%d.%d\n", i, - (header->IpMappedAddr[i]&0xff000000)>>24, - (header->IpMappedAddr[i]&0x00ff0000)>>16, - (header->IpMappedAddr[i]&0x0000ff00)>>8, - (header->IpMappedAddr[i]&0x000000ff)); - } } - } - } - if (verbose) { - printf("%d simple entries, %d multihomed entries, Total = %d\n", - regentries, mhentries, mhentries+regentries); - } + } + if (verbose) + printf("%d multihomed blocks\n", mhblocks); + + /* Check the server addresses */ + if (verbose) + printf("Check server addresses\n"); + mhentries = regentries = 0; + for (i = 0; i <= MAXSERVERID; i++) { + if (header->IpMappedAddr[i]) { + if ((header->IpMappedAddr[i] & 0xff000000) == 0xff000000) { + mhentries++; + if (((header->IpMappedAddr[i] & 0x00ff0000) >> 16) > + VL_MAX_ADDREXTBLKS) + printf + ("IP Addr for entry %d: Multihome block is bad (%d)\n", + i, ((header->IpMappedAddr[i] & 0x00ff0000) >> 16)); + if (((header->IpMappedAddr[i] & 0x0000ffff) > VL_MHSRV_PERBLK) + || ((header->IpMappedAddr[i] & 0x0000ffff) < 1)) + printf + ("IP Addr for entry %d: Multihome index is bad (%d)\n", + i, (header->IpMappedAddr[i] & 0x0000ffff)); + if (serveraddrs[i] == -1) { + printf + ("warning: IP Addr for entry %d: Multihome entry has no ip addresses\n", + i); + serveraddrs[i] = 0; + } + if (listservers) { + printf(" Server ip addr %d = MH block %d, index %d\n", + i, (header->IpMappedAddr[i] & 0x00ff0000) >> 16, + (header->IpMappedAddr[i] & 0x0000ffff)); + } + } else { + regentries++; + serveraddrs[i] = 1; /* It is good */ + if (listservers) { + printf(" Server ip addr %d = %d.%d.%d.%d\n", i, + (header->IpMappedAddr[i] & 0xff000000) >> 24, + (header->IpMappedAddr[i] & 0x00ff0000) >> 16, + (header->IpMappedAddr[i] & 0x0000ff00) >> 8, + (header->IpMappedAddr[i] & 0x000000ff)); + } + } + } + } + if (verbose) { + printf("%d simple entries, %d multihomed entries, Total = %d\n", + regentries, mhentries, mhentries + regentries); + } } int WorkerBee(as, arock) - struct cmd_syndesc *as; - char *arock; + struct cmd_syndesc *as; + char *arock; { - char *dbfile; - afs_int32 maxentries, type; - struct vlheader header; - struct nvlentry vlentry; - int i, j, help=0; - - dbfile = as->parms[0].items->data; /* -database */ - listuheader = (as->parms[1].items ? 1 : 0); /* -uheader */ - listheader = (as->parms[2].items ? 1 : 0); /* -vheader */ - listservers = (as->parms[3].items ? 1 : 0); /* -servers */ - listentries = (as->parms[4].items ? 1 : 0); /* -entries */ - verbose = (as->parms[5].items ? 1 : 0); /* -verbose */ - - /* open the vldb database file */ - fd = open(dbfile, O_RDONLY, 0); - if (fd < 0) { - printf("can't open file '%s'. error = %d\n", dbfile, errno); - return; - } - - /* read the ubik header and the vldb database header*/ - readUbikHeader(); - readheader(&header); - if (header.vital_header.vldbversion < 3) { - printf("does not support vldb with version less than 3\n"); - return; - } - - maxentries = (header.vital_header.eofPtr / sizeof(vlentry)) + 1; - record = (struct er *)malloc(maxentries * sizeof(struct er)); - memset((char *)record, 0, (maxentries * sizeof(struct er))); - memset((char *)serveraddrs, 0, sizeof(serveraddrs)); - - /* Will fill in the record array of entries it found */ - ReadAllEntries(&header); - listentries = 0; /* Listed all the entries */ - - /* Check the multihomed blocks for valid entries as well as - * the IpMappedAddrs array in the header for valid entries. - */ - CheckIpAddrs(&header); - - /* Follow the hash tables */ - FollowNameHash(&header); - FollowIdHash(&header); - - /* Follow the chain of free entries */ - FollowFreeChain(&header); - - /* Now check the record we have been keeping for inconsistancies - * For valid vlentries, also check that the server we point to is - * valid (the serveraddrs array). - */ - if (verbose) - printf("Verify each volume entry\n"); - for (i=0; iparms[0].items->data; /* -database */ + listuheader = (as->parms[1].items ? 1 : 0); /* -uheader */ + listheader = (as->parms[2].items ? 1 : 0); /* -vheader */ + listservers = (as->parms[3].items ? 1 : 0); /* -servers */ + listentries = (as->parms[4].items ? 1 : 0); /* -entries */ + verbose = (as->parms[5].items ? 1 : 0); /* -verbose */ + + /* open the vldb database file */ + fd = open(dbfile, O_RDONLY, 0); + if (fd < 0) { + printf("can't open file '%s'. error = %d\n", dbfile, errno); + return 0; + } + + /* read the ubik header and the vldb database header */ + readUbikHeader(); + readheader(&header); + if (header.vital_header.vldbversion < 3) { + printf("does not support vldb with version less than 3\n"); + return 0; + } + + maxentries = (header.vital_header.eofPtr / sizeof(vlentry)) + 1; + record = (struct er *)malloc(maxentries * sizeof(struct er)); + memset((char *)record, 0, (maxentries * sizeof(struct er))); + memset((char *)serveraddrs, 0, sizeof(serveraddrs)); + + /* Will fill in the record array of entries it found */ + ReadAllEntries(&header); + listentries = 0; /* Listed all the entries */ + + /* Check the multihomed blocks for valid entries as well as + * the IpMappedAddrs array in the header for valid entries. + */ + CheckIpAddrs(&header); + + /* Follow the hash tables */ + FollowNameHash(&header); + FollowIdHash(&header); + + /* Follow the chain of free entries */ + FollowFreeChain(&header); + + /* Now check the record we have been keeping for inconsistancies + * For valid vlentries, also check that the server we point to is + * valid (the serveraddrs array). + */ + if (verbose) + printf("Verify each volume entry\n"); + for (i = 0; i < maxentries; i++) { + if (record[i].type == 0) + continue; + + /* If a vlentry, verify that its name is valid, its name and ids are + * on the hash chains, and its server numbers are good. + */ + if (record[i].type & VL) { + readentry(record[i].addr, &vlentry, &type); + + if (InvalidVolname(vlentry.name)) + printf("Volume '%s' at addr %u has an invalid name\n", + vlentry.name, record[i].addr); + + if (!(record[i].type & NH)) + printf("Volume '%s' not found in name hash\n", vlentry.name); + + if (vlentry.volumeId[0] && !(record[i].type & RWH)) + printf("Volume '%s' id %u not found in RW hash chain\n", + vlentry.name, vlentry.volumeId[0]); + + if (vlentry.volumeId[1] && !(record[i].type & ROH)) + printf("Volume '%s' id %u not found in RO hash chain\n", + vlentry.name, vlentry.volumeId[1]); + + if (vlentry.volumeId[2] && !(record[i].type & BKH)) + printf("Volume '%s' id %u not found in BK hash chain\n", + vlentry.name, vlentry.volumeId[2]); + + for (j = 0; j < NMAXNSERVERS; j++) { + if ((vlentry.serverNumber[j] != 255) + && (serveraddrs[vlentry.serverNumber[j]] == 0)) { + printf + ("Volume '%s', index %d points to empty server entry %d\n", + vlentry.name, j, vlentry.serverNumber[j]); + } + } + + if (record[i].type & 0xffffff00) + printf + ("Volume '%s' id %u also found on other chains (0x%x)\n", + vlentry.name, vlentry.volumeId[0], record[i].type); + + /* A free entry */ + } else if (record[i].type & FR) { + if (!(record[i].type & FRC)) + printf("Free vlentry at %u not on free chain\n", + record[i].addr); + + if (record[i].type & 0xfffffdf0) + printf + ("Free vlentry at %u also found on other chains (0x%x)\n", + record[i].addr, record[i].type); + + /* A multihomed entry */ + } else if (record[i].type & MH) { + if (!(record[i].type & MHC)) + printf("Multihomed block at %u is orphaned\n", + record[i].addr); + + if (record[i].type & 0xfffffef0) + printf + ("Multihomed block at %u also found on other chains (0x%x)\n", + record[i].addr, record[i].type); - if (record[i].type & 0xffffff00) - printf("Volume '%s' id %u also found on other chains (0x%x)\n", - vlentry.name, vlentry.volumeId[0], record[i].type); - - /* A free entry */ - } else if (record[i].type & FR) { - if (!(record[i].type & FRC)) - printf("Free vlentry at %u not on free chain\n", record[i].addr); - - if (record[i].type & 0xfffffdf0) - printf("Free vlentry at %u also found on other chains (0x%x)\n", - record[i].addr, record[i].type); - - /* A multihomed entry */ - } else if (record[i].type & MH) { - if (!(record[i].type & MHC)) - printf("Multihomed block at %u is orphaned\n", record[i].addr); - - if (record[i].type & 0xfffffef0) - printf("Multihomed block at %u also found on other chains (0x%x)\n", - record[i].addr, record[i].type); - - } else { - printf("Unknown entry type at %u (0x%x)\n", record[i].addr, record[i].type); - } - } + } else { + printf("Unknown entry type at %u (0x%x)\n", record[i].addr, + record[i].type); + } + } + return 0; } main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; { - struct cmd_syndesc *ts; - - setlinebuf(stdout); - - ts=cmd_CreateSyntax((char *)0, WorkerBee, (char *) 0, "vldb check"); - cmd_AddParm(ts, "-database", CMD_SINGLE, CMD_REQUIRED, "vldb_file"); - cmd_AddParm(ts, "-uheader", CMD_FLAG, CMD_OPTIONAL, "Display UBIK header"); - cmd_AddParm(ts, "-vheader", CMD_FLAG, CMD_OPTIONAL, "Display VLDB header"); - cmd_AddParm(ts, "-servers", CMD_FLAG, CMD_OPTIONAL, "Display server list"); - cmd_AddParm(ts, "-entries", CMD_FLAG, CMD_OPTIONAL, "Display entries"); - cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose"); - - return cmd_Dispatch(argc, argv); + struct cmd_syndesc *ts; + + setlinebuf(stdout); + + ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "vldb check"); + cmd_AddParm(ts, "-database", CMD_SINGLE, CMD_REQUIRED, "vldb_file"); + cmd_AddParm(ts, "-uheader", CMD_FLAG, CMD_OPTIONAL, + "Display UBIK header"); + cmd_AddParm(ts, "-vheader", CMD_FLAG, CMD_OPTIONAL, + "Display VLDB header"); + cmd_AddParm(ts, "-servers", CMD_FLAG, CMD_OPTIONAL, + "Display server list"); + cmd_AddParm(ts, "-entries", CMD_FLAG, CMD_OPTIONAL, "Display entries"); + cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose"); + + return cmd_Dispatch(argc, argv); } diff --git a/src/vlserver/vlprocs.c b/src/vlserver/vlprocs.c index 1da0f7d14..e4f438308 100644 --- a/src/vlserver/vlprocs.c +++ b/src/vlserver/vlprocs.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vlprocs.c,v 1.1.1.8 2002/05/11 00:03:34 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vlserver/vlprocs.c,v 1.13 2003/11/29 21:38:04 jaltman Exp $"); #include #include @@ -24,21 +25,31 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vlprocs.c,v 1.1.1.8 2002/05/11 #else #include #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include #include "vlserver.h" #include "afs/audit.h" #ifndef AFS_NT40_ENV #include #endif +#ifdef HAVE_POSIX_REGEX /* use POSIX regexp library */ +#include +#endif extern int smallMem; extern extent_mod; extern struct afsconf_dir *vldb_confdir; extern struct ubik_dbase *VL_dbase; -struct vlheader cheader; /* kept in network byte order */ +struct vlheader cheader; /* kept in network byte order */ extern afs_uint32 HostAddress[]; /* host addresses kept in host byte order */ int maxnservers; -struct extentaddr *ex_addr[VL_MAX_ADDREXTBLKS] = { 0, 0, 0, 0}; +struct extentaddr *ex_addr[VL_MAX_ADDREXTBLKS] = { 0, 0, 0, 0 }; static char rxinfo_str[128]; /* Need rxinfo string to be non-local */ #define ABORT(c) { errorcode = (c); goto abort; } #undef END @@ -68,8 +79,9 @@ static int InvalidReleasetype(); static int IpAddrToRelAddr(); static int ChangeIPAddr(); -char *rxinfo(rxcall) - struct rx_call *rxcall; +char * +rxinfo(rxcall) + struct rx_call *rxcall; { int code; register struct rx_connection *tconn; @@ -78,100 +90,105 @@ char *rxinfo(rxcall) char tcell[64]; afs_uint32 exp; struct in_addr hostAddr; - + tconn = rx_ConnectionOf(rxcall); hostAddr.s_addr = rx_HostOf(rx_PeerOf(tconn)); - code = rxkad_GetServerInfo(rxcall->conn, (afs_int32 *) 0, &exp, tname, tinst, tcell, (afs_int32 *) 0); + code = + rxkad_GetServerInfo(rxcall->conn, NULL, &exp, tname, tinst, tcell, + NULL); if (!code) - sprintf(rxinfo_str,"%s %s", inet_ntoa(hostAddr), tname); + sprintf(rxinfo_str, "%s %s", inet_ntoa(hostAddr), tname); else - sprintf(rxinfo_str,"%s noauth",inet_ntoa(hostAddr)); - return(rxinfo_str); + sprintf(rxinfo_str, "%s noauth", inet_ntoa(hostAddr)); + return (rxinfo_str); } /* This is called to initialize the database, set the appropriate locks and make sure that the vldb header is valid */ -int Init_VLdbase (trans, locktype, this_op) - struct ubik_trans **trans; - int locktype; /* indicate read or write transaction */ - int this_op; -{ - int errorcode=0, pass, wl; - - for (pass=1; pass<=3; pass++) { - if (pass == 2) { /* take write lock to rebuild the db */ - errorcode = ubik_BeginTrans (VL_dbase, UBIK_WRITETRANS, trans); - wl = 1; - } - else if (locktype == LOCKREAD) { - errorcode = ubik_BeginTransReadAny (VL_dbase, UBIK_READTRANS, trans); - wl = 0; - } - else { - errorcode = ubik_BeginTrans (VL_dbase, UBIK_WRITETRANS, trans); - wl = 1; - } - if (errorcode) - return errorcode; - - errorcode = ubik_SetLock (*trans, 1, 1, locktype); - if (errorcode) { - COUNT_ABO; - ubik_AbortTrans (*trans); - return errorcode; - } - - /* check that dbase is initialized and setup cheader */ - /* 2nd pass we try to rebuild the header */ - errorcode = CheckInit(*trans, ((pass==2)?1:0)); - if (!errorcode && wl && extent_mod) - errorcode = readExtents(*trans); /* Fix the mh extent blocks */ - if (errorcode) { - COUNT_ABO; - ubik_AbortTrans(*trans); - /* Only rebuld if the database is empty */ - /* Exit if can't rebuild */ - if ((pass == 1) && (errorcode != VL_EMPTY)) return errorcode; - if (pass == 2) return errorcode; - } - else { /* No errorcode */ - if (pass == 2) { - ubik_EndTrans(*trans); /* Rebuilt db. End trans, then retake original lock */ - } - else { - break; /* didn't rebuild and successful - exit */ - } - } - } - return errorcode; +int +Init_VLdbase(trans, locktype, this_op) + struct ubik_trans **trans; + int locktype; /* indicate read or write transaction */ + int this_op; +{ + int errorcode = 0, pass, wl; + + for (pass = 1; pass <= 3; pass++) { + if (pass == 2) { /* take write lock to rebuild the db */ + errorcode = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, trans); + wl = 1; + } else if (locktype == LOCKREAD) { + errorcode = + ubik_BeginTransReadAny(VL_dbase, UBIK_READTRANS, trans); + wl = 0; + } else { + errorcode = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, trans); + wl = 1; + } + if (errorcode) + return errorcode; + + errorcode = ubik_SetLock(*trans, 1, 1, locktype); + if (errorcode) { + COUNT_ABO; + ubik_AbortTrans(*trans); + return errorcode; + } + + /* check that dbase is initialized and setup cheader */ + /* 2nd pass we try to rebuild the header */ + errorcode = CheckInit(*trans, ((pass == 2) ? 1 : 0)); + if (!errorcode && wl && extent_mod) + errorcode = readExtents(*trans); /* Fix the mh extent blocks */ + if (errorcode) { + COUNT_ABO; + ubik_AbortTrans(*trans); + /* Only rebuld if the database is empty */ + /* Exit if can't rebuild */ + if ((pass == 1) && (errorcode != VL_EMPTY)) + return errorcode; + if (pass == 2) + return errorcode; + } else { /* No errorcode */ + if (pass == 2) { + ubik_EndTrans(*trans); /* Rebuilt db. End trans, then retake original lock */ + } else { + break; /* didn't rebuild and successful - exit */ + } + } + } + return errorcode; } /* Create a new vldb entry; both new volume id and name must be unique (non-existant in vldb). */ +afs_int32 SVL_CreateEntry(rxcall, newentry) - struct rx_call *rxcall; - struct vldbentry *newentry; -{ struct ubik_trans *trans; - afs_int32 errorcode, blockindex; - struct nvlentry tentry; - - COUNT_REQ (VLCREATEENTRY); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) { + struct rx_call *rxcall; + struct vldbentry *newentry; +{ + struct ubik_trans *trans; + afs_int32 errorcode, blockindex; + struct nvlentry tentry; + + COUNT_REQ(VLCREATEENTRY); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) { errorcode = VL_PERM; goto end; - } + } /* Do some validity tests on new entry */ - if ( (errorcode = check_vldbentry(newentry)) + if ((errorcode = check_vldbentry(newentry)) || (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))) goto end; - VLog(1, ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL], rxinfo(rxcall))); + VLog(1, + ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL], + rxinfo(rxcall))); /* XXX shouldn't we check to see if the r/o volume is duplicated? */ - if (newentry->volumeId[RWVOL] - && FindByID(trans, newentry->volumeId[RWVOL], RWVOL, &tentry, - &errorcode)) { /* entry already exists, we fail */ - errorcode = VL_IDEXIST; + if (newentry->volumeId[RWVOL] + && FindByID(trans, newentry->volumeId[RWVOL], RWVOL, &tentry, &errorcode)) { /* entry already exists, we fail */ + errorcode = VL_IDEXIST; goto abort; } else if (errorcode) { goto abort; @@ -180,21 +197,21 @@ SVL_CreateEntry(rxcall, newentry) /* Is this following check (by volume name) necessary?? */ /* If entry already exists, we fail */ if (FindByName(trans, newentry->name, &tentry, &errorcode)) { - errorcode = VL_NAMEEXIST; - goto abort; + errorcode = VL_NAMEEXIST; + goto abort; } else if (errorcode) { - goto abort; - } + goto abort; + } blockindex = AllocBlock(trans, &tentry); if (blockindex == 0) { - errorcode = VL_CREATEFAIL; - goto abort; + errorcode = VL_CREATEFAIL; + goto abort; } memset(&tentry, 0, sizeof(struct nvlentry)); /* Convert to its internal representation; both in host byte order */ - if (errorcode = vldbentry_to_vlentry(trans, newentry, &tentry)) { + if (errorcode = vldbentry_to_vlentry(trans, newentry, &tentry)) { FreeBlock(trans, blockindex); goto abort; } @@ -204,10 +221,9 @@ SVL_CreateEntry(rxcall, newentry) if (errorcode) { FreeBlock(trans, blockindex); goto abort; - } - else { - errorcode = ubik_EndTrans(trans); - goto end; + } else { + errorcode = ubik_EndTrans(trans); + goto end; } abort: @@ -215,36 +231,39 @@ SVL_CreateEntry(rxcall, newentry) ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLCreateEntryEvent, errorcode, - AUD_STR, (newentry ? newentry->name : (char *)0), AUD_END); + osi_auditU(rxcall, VLCreateEntryEvent, errorcode, AUD_STR, + (newentry ? newentry->name : NULL), AUD_END); return errorcode; } +afs_int32 SVL_CreateEntryN(rxcall, newentry) - struct rx_call *rxcall; - struct nvldbentry *newentry; -{ struct ubik_trans *trans; - afs_int32 errorcode, blockindex; - struct nvlentry tentry; - - COUNT_REQ (VLCREATEENTRYN); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) { + struct rx_call *rxcall; + struct nvldbentry *newentry; +{ + struct ubik_trans *trans; + afs_int32 errorcode, blockindex; + struct nvlentry tentry; + + COUNT_REQ(VLCREATEENTRYN); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) { errorcode = VL_PERM; goto end; - } + } /* Do some validity tests on new entry */ - if ( (errorcode = check_nvldbentry(newentry)) + if ((errorcode = check_nvldbentry(newentry)) || (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))) goto end; - VLog(1, ("Create Volume %d %s\n", newentry->volumeId[RWVOL], rxinfo(rxcall))); + VLog(1, + ("Create Volume %d %s\n", newentry->volumeId[RWVOL], + rxinfo(rxcall))); /* XXX shouldn't we check to see if the r/o volume is duplicated? */ - if (newentry->volumeId[RWVOL] - && FindByID(trans, newentry->volumeId[RWVOL], RWVOL, &tentry, - &errorcode)) { /* entry already exists, we fail */ - errorcode = VL_IDEXIST; + if (newentry->volumeId[RWVOL] + && FindByID(trans, newentry->volumeId[RWVOL], RWVOL, &tentry, &errorcode)) { /* entry already exists, we fail */ + errorcode = VL_IDEXIST; goto abort; } else if (errorcode) { goto abort; @@ -253,21 +272,21 @@ SVL_CreateEntryN(rxcall, newentry) /* Is this following check (by volume name) necessary?? */ /* If entry already exists, we fail */ if (FindByName(trans, newentry->name, &tentry, &errorcode)) { - errorcode = VL_NAMEEXIST; - goto abort; + errorcode = VL_NAMEEXIST; + goto abort; } else if (errorcode) { - goto abort; - } + goto abort; + } blockindex = AllocBlock(trans, &tentry); if (blockindex == 0) { - errorcode = VL_CREATEFAIL; - goto abort; + errorcode = VL_CREATEFAIL; + goto abort; } memset(&tentry, 0, sizeof(struct nvlentry)); /* Convert to its internal representation; both in host byte order */ - if (errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry)) { + if (errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry)) { FreeBlock(trans, blockindex); goto abort; } @@ -277,10 +296,9 @@ SVL_CreateEntryN(rxcall, newentry) if (errorcode) { FreeBlock(trans, blockindex); goto abort; - } - else { - errorcode = ubik_EndTrans(trans); - goto end; + } else { + errorcode = ubik_EndTrans(trans); + goto end; } abort: @@ -288,33 +306,35 @@ SVL_CreateEntryN(rxcall, newentry) ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLCreateEntryEvent, errorcode, - AUD_STR, (newentry ? newentry->name : (char *)0), AUD_END); + osi_auditU(rxcall, VLCreateEntryEvent, errorcode, AUD_STR, + (newentry ? newentry->name : NULL), AUD_END); return errorcode; } +afs_int32 SVL_ChangeAddr(rxcall, ip1, ip2) - struct rx_call *rxcall; - afs_int32 ip1, ip2; -{ struct ubik_trans *trans; - afs_int32 errorcode; + struct rx_call *rxcall; + afs_int32 ip1, ip2; +{ + struct ubik_trans *trans; + afs_int32 errorcode; - COUNT_REQ (VLCHANGEADDR); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) { + COUNT_REQ(VLCHANGEADDR); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) { errorcode = VL_PERM; goto end; - } + } if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) goto end; VLog(1, ("Change Addr %d -> %d %s\n", ip1, ip2, rxinfo(rxcall))); if (errorcode = ChangeIPAddr(ip1, ip2, trans)) - goto abort; + goto abort; else { - errorcode = ubik_EndTrans(trans); - goto end; + errorcode = ubik_EndTrans(trans); + goto end; } abort: @@ -322,39 +342,42 @@ SVL_ChangeAddr(rxcall, ip1, ip2) ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLChangeAddrEvent, errorcode, AUD_LONG, ip1, - AUD_LONG, ip2, AUD_END); + osi_auditU(rxcall, VLChangeAddrEvent, errorcode, AUD_LONG, ip1, AUD_LONG, + ip2, AUD_END); return errorcode; } /* Delete a vldb entry given the volume id. */ +afs_int32 SVL_DeleteEntry(rxcall, volid, voltype) - struct rx_call *rxcall; - afs_int32 volid; - afs_int32 voltype; -{ struct ubik_trans *trans; - afs_int32 blockindex, errorcode; - struct nvlentry tentry; - - COUNT_REQ (VLDELETEENTRY); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) + struct rx_call *rxcall; + afs_int32 volid; + afs_int32 voltype; +{ + struct ubik_trans *trans; + afs_int32 blockindex, errorcode; + struct nvlentry tentry; + + COUNT_REQ(VLDELETEENTRY); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) END(VL_PERM); - if ((voltype != -1 ) && (InvalidVoltype(voltype))) - END( VL_BADVOLTYPE ); + if ((voltype != -1) && (InvalidVoltype(voltype))) + END(VL_BADVOLTYPE); - if (errorcode = Init_VLdbase (&trans, LOCKWRITE, this_op)) + if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) goto end; VLog(1, ("Delete Volume %d %s\n", volid, rxinfo(rxcall))); blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode); - if (blockindex == 0) { /* volid not found */ - if (!errorcode) errorcode = VL_NOENT; + if (blockindex == 0) { /* volid not found */ + if (!errorcode) + errorcode = VL_NOENT; goto abort; } if (tentry.flags & VLDELETED) { /* Already deleted; return */ - ABORT( VL_ENTDELETED ); + ABORT(VL_ENTDELETED); } if (errorcode = RemoveEntry(trans, blockindex, &tentry)) { goto abort; @@ -367,73 +390,79 @@ SVL_DeleteEntry(rxcall, volid, voltype) ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLDeleteEntryEvent, errorcode, AUD_LONG, volid, AUD_END); + osi_auditU(rxcall, VLDeleteEntryEvent, errorcode, AUD_LONG, volid, + AUD_END); return errorcode; } /* Get a vldb entry given its volume id; make sure it's not a deleted entry. */ -GetEntryByID (rxcall, volid, voltype, aentry, new, this_op) - struct rx_call *rxcall; - afs_int32 volid; - afs_int32 voltype, new, this_op; - char *aentry; /* entry data copied here */ -{ struct ubik_trans *trans; - afs_int32 blockindex, errorcode; - struct nvlentry tentry; - - if ((voltype != -1 ) && (InvalidVoltype(voltype))) +GetEntryByID(rxcall, volid, voltype, aentry, new, this_op) + struct rx_call *rxcall; + afs_int32 volid; + afs_int32 voltype, new, this_op; + char *aentry; /* entry data copied here */ +{ + struct ubik_trans *trans; + afs_int32 blockindex, errorcode; + struct nvlentry tentry; + + if ((voltype != -1) && (InvalidVoltype(voltype))) return VL_BADVOLTYPE; - if (errorcode = Init_VLdbase (&trans, LOCKREAD, this_op)) + if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; VLog(5, ("GetVolumeByID %d (%d) %s\n", volid, new, rxinfo(rxcall))); blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode); - if (blockindex == 0) { /* entry not found */ - if (!errorcode) errorcode = VL_NOENT; + if (blockindex == 0) { /* entry not found */ + if (!errorcode) + errorcode = VL_NOENT; COUNT_ABO; - ubik_AbortTrans (trans); + ubik_AbortTrans(trans); return errorcode; } if (tentry.flags & VLDELETED) { /* Entry is deleted! */ COUNT_ABO; - ubik_AbortTrans (trans); + ubik_AbortTrans(trans); return VL_ENTDELETED; } - /* Convert from the internal to external form */ + /* Convert from the internal to external form */ if (new == 1) vlentry_to_nvldbentry(&tentry, (struct nvldbentry *)aentry); else if (new == 2) vlentry_to_uvldbentry(&tentry, (struct uvldbentry *)aentry); else vlentry_to_vldbentry(&tentry, (struct vldbentry *)aentry); - return(ubik_EndTrans(trans)); + return (ubik_EndTrans(trans)); } -SVL_GetEntryByID (rxcall, volid, voltype, aentry) - struct rx_call *rxcall; - afs_int32 volid, voltype; - vldbentry *aentry; /* entry data copied here */ +afs_int32 +SVL_GetEntryByID(rxcall, volid, voltype, aentry) + struct rx_call *rxcall; + afs_int32 volid, voltype; + vldbentry *aentry; /* entry data copied here */ { - COUNT_REQ (VLGETENTRYBYID); + COUNT_REQ(VLGETENTRYBYID); return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0, this_op)); } -SVL_GetEntryByIDN (rxcall, volid, voltype, aentry) - struct rx_call *rxcall; - afs_int32 volid, voltype; - nvldbentry *aentry; /* entry data copied here */ +afs_int32 +SVL_GetEntryByIDN(rxcall, volid, voltype, aentry) + struct rx_call *rxcall; + afs_int32 volid, voltype; + nvldbentry *aentry; /* entry data copied here */ { - COUNT_REQ (VLGETENTRYBYIDN); + COUNT_REQ(VLGETENTRYBYIDN); return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1, this_op)); } -SVL_GetEntryByIDU (rxcall, volid, voltype, aentry) - struct rx_call *rxcall; - afs_int32 volid, voltype; - uvldbentry *aentry; /* entry data copied here */ +afs_int32 +SVL_GetEntryByIDU(rxcall, volid, voltype, aentry) + struct rx_call *rxcall; + afs_int32 volid, voltype; + uvldbentry *aentry; /* entry data copied here */ { - COUNT_REQ (VLGETENTRYBYIDU); + COUNT_REQ(VLGETENTRYBYIDU); return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2, this_op)); } @@ -441,36 +470,41 @@ SVL_GetEntryByIDU (rxcall, volid, voltype, aentry) /* returns true if the id is a decimal integer, in which case we interpret it as an id. make the cache manager much simpler */ -static int NameIsId(aname) -register char *aname; { +static int +NameIsId(aname) + register char *aname; +{ register int tc; while (tc = *aname++) { - if (tc > '9' || tc < '0') return 0; + if (tc > '9' || tc < '0') + return 0; } return 1; } /* Get a vldb entry given the volume's name; of course, very similar to VLGetEntryByID() above. */ -GetEntryByName (rxcall, volname, aentry, new, this_op) - struct rx_call *rxcall; - char *volname; - char *aentry; /* entry data copied here */ - int new, this_op; -{ struct ubik_trans *trans; - afs_int32 blockindex, errorcode; - struct nvlentry tentry; +GetEntryByName(rxcall, volname, aentry, new, this_op) + struct rx_call *rxcall; + char *volname; + char *aentry; /* entry data copied here */ + int new, this_op; +{ + struct ubik_trans *trans; + afs_int32 blockindex, errorcode; + struct nvlentry tentry; if (NameIsId(volname)) { return GetEntryByID(rxcall, atoi(volname), -1, aentry, new, this_op); } if (InvalidVolname(volname)) return VL_BADNAME; - if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) + if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxcall))); blockindex = FindByName(trans, volname, &tentry, &errorcode); - if (blockindex == 0) { /* entry not found */ - if (!errorcode) errorcode = VL_NOENT; + if (blockindex == 0) { /* entry not found */ + if (!errorcode) + errorcode = VL_NOENT; COUNT_ABO; ubik_AbortTrans(trans); return errorcode; @@ -482,68 +516,73 @@ GetEntryByName (rxcall, volname, aentry, new, this_op) } /* Convert to external entry representation */ if (new == 1) - vlentry_to_nvldbentry(&tentry, (struct nvldbentry *)aentry); + vlentry_to_nvldbentry(&tentry, (struct nvldbentry *)aentry); else if (new == 2) vlentry_to_uvldbentry(&tentry, (struct uvldbentry *)aentry); else - vlentry_to_vldbentry(&tentry, (struct vldbentry *)aentry); - return(ubik_EndTrans(trans)); + vlentry_to_vldbentry(&tentry, (struct vldbentry *)aentry); + return (ubik_EndTrans(trans)); } -SVL_GetEntryByNameO (rxcall, volname, aentry) - struct rx_call *rxcall; - char *volname; - struct vldbentry *aentry; /* entry data copied here */ +afs_int32 +SVL_GetEntryByNameO(rxcall, volname, aentry) + struct rx_call *rxcall; + char *volname; + struct vldbentry *aentry; /* entry data copied here */ { - COUNT_REQ (VLGETENTRYBYNAME); + COUNT_REQ(VLGETENTRYBYNAME); return (GetEntryByName(rxcall, volname, (char *)aentry, 0, this_op)); } -SVL_GetEntryByNameN (rxcall, volname, aentry) - struct rx_call *rxcall; - char *volname; - struct nvldbentry *aentry; /* entry data copied here */ +afs_int32 +SVL_GetEntryByNameN(rxcall, volname, aentry) + struct rx_call *rxcall; + char *volname; + struct nvldbentry *aentry; /* entry data copied here */ { - COUNT_REQ (VLGETENTRYBYNAMEN); + COUNT_REQ(VLGETENTRYBYNAMEN); return (GetEntryByName(rxcall, volname, (char *)aentry, 1, this_op)); } -SVL_GetEntryByNameU (rxcall, volname, aentry) - struct rx_call *rxcall; - char *volname; - struct uvldbentry *aentry; /* entry data copied here */ +afs_int32 +SVL_GetEntryByNameU(rxcall, volname, aentry) + struct rx_call *rxcall; + char *volname; + struct uvldbentry *aentry; /* entry data copied here */ { - COUNT_REQ (VLGETENTRYBYNAMEU); + COUNT_REQ(VLGETENTRYBYNAMEU); return (GetEntryByName(rxcall, volname, (char *)aentry, 2, this_op)); } /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */ -SVL_GetNewVolumeId (rxcall, Maxvolidbump, newvolumeid) -struct rx_call *rxcall; -afs_int32 Maxvolidbump; -afs_int32 *newvolumeid; -{ register afs_int32 errorcode, maxvolumeid; +afs_int32 +SVL_GetNewVolumeId(rxcall, Maxvolidbump, newvolumeid) + struct rx_call *rxcall; + afs_int32 Maxvolidbump; + afs_int32 *newvolumeid; +{ + register afs_int32 errorcode, maxvolumeid; struct ubik_trans *trans; - COUNT_REQ (VLGETNEWVOLUMEID); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) - END( VL_PERM ); + COUNT_REQ(VLGETNEWVOLUMEID); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) + END(VL_PERM); if (Maxvolidbump < 0 || Maxvolidbump > MAXBUMPCOUNT) - END ( VL_BADVOLIDBUMP ); + END(VL_BADVOLIDBUMP); - if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) - goto end; + if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) + goto end; *newvolumeid = maxvolumeid = ntohl(cheader.vital_header.MaxVolumeId); maxvolumeid += Maxvolidbump; VLog(1, ("GetNewVolid newmax=%d %s\n", maxvolumeid, rxinfo(rxcall))); cheader.vital_header.MaxVolumeId = htonl(maxvolumeid); if (write_vital_vlheader(trans)) { - ABORT( VL_IO ); + ABORT(VL_IO); } errorcode = (ubik_EndTrans(trans)); goto end; @@ -553,7 +592,7 @@ afs_int32 *newvolumeid; ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLGetNewVolumeIdEvent, errorcode, AUD_END); + osi_auditU(rxcall, VLGetNewVolumeIdEvent, errorcode, AUD_END); return errorcode; } @@ -562,47 +601,50 @@ afs_int32 *newvolumeid; * newentry. No individual checking/updating per field (alike * VLUpdateEntry) is done. */ -SVL_ReplaceEntry (rxcall, volid, voltype, newentry, releasetype) -struct rx_call *rxcall; -afs_int32 volid; -afs_int32 voltype; -struct vldbentry *newentry; -afs_int32 releasetype; -{ struct ubik_trans *trans; - afs_int32 blockindex, errorcode, typeindex; - int hashnewname; - int hashVol[MAXTYPES]; - struct nvlentry tentry; - - COUNT_REQ (VLREPLACEENTRY); - for(typeindex = 0; typeindex < MAXTYPES; typeindex++) +afs_int32 +SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype) + struct rx_call *rxcall; + afs_int32 volid; + afs_int32 voltype; + struct vldbentry *newentry; + afs_int32 releasetype; +{ + struct ubik_trans *trans; + afs_int32 blockindex, errorcode, typeindex; + int hashnewname; + int hashVol[MAXTYPES]; + struct nvlentry tentry; + + COUNT_REQ(VLREPLACEENTRY); + for (typeindex = 0; typeindex < MAXTYPES; typeindex++) hashVol[typeindex] = 0; hashnewname = 0; - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) - END ( VL_PERM ); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) + END(VL_PERM); if (errorcode = check_vldbentry(newentry)) goto end; if (voltype != -1 && InvalidVoltype(voltype)) - END ( VL_BADVOLTYPE ); + END(VL_BADVOLTYPE); if (releasetype && InvalidReleasetype(releasetype)) - END( VL_BADRELLOCKTYPE ); + END(VL_BADRELLOCKTYPE); if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) - goto end; + goto end; VLog(1, ("OReplace Volume %d %s\n", volid, rxinfo(rxcall))); /* find vlentry we're changing */ blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode); - if (blockindex == 0) { /* entry not found */ - if (!errorcode) errorcode = VL_NOENT; + if (blockindex == 0) { /* entry not found */ + if (!errorcode) + errorcode = VL_NOENT; goto abort; } /* check that we're not trying to change the RW vol ID */ if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) { - ABORT( VL_BADENTRY ); + ABORT(VL_BADENTRY); } /* unhash volid entries if they're disappearing or changing. @@ -611,15 +653,15 @@ afs_int32 releasetype; for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) { if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) { if (tentry.volumeId[typeindex]) - if (errorcode = UnhashVolid(trans, typeindex, blockindex, - &tentry)) { + if (errorcode = + UnhashVolid(trans, typeindex, blockindex, &tentry)) { goto abort; } /* we must rehash new id if the id is different and the ID is nonzero */ hashVol[typeindex] = 1; /* must rehash this guy if he exists */ } } - + /* Rehash volname if it changes */ if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */ if (errorcode = UnhashVolname(trans, blockindex, &tentry)) { @@ -629,12 +671,12 @@ afs_int32 releasetype; } /* after this, tentry is new entry, not old one. vldbentry_to_vlentry - doesn't touch hash chains */ + * doesn't touch hash chains */ if (errorcode = vldbentry_to_vlentry(trans, newentry, &tentry)) { goto abort; } - for(typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) { + for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) { if (hashVol[typeindex] && tentry.volumeId[typeindex]) { if (errorcode = HashVolid(trans, typeindex, blockindex, &tentry)) { goto abort; @@ -648,61 +690,65 @@ afs_int32 releasetype; if (releasetype) ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */ if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) { - ABORT( VL_IO ); + ABORT(VL_IO); } - END (ubik_EndTrans(trans)); + END(ubik_EndTrans(trans)); abort: COUNT_ABO; ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLReplaceVLEntryEvent, errorcode, AUD_LONG, volid, AUD_END); + osi_auditU(rxcall, VLReplaceVLEntryEvent, errorcode, AUD_LONG, volid, + AUD_END); return errorcode; } -SVL_ReplaceEntryN (rxcall, volid, voltype, newentry, releasetype) -struct rx_call *rxcall; -afs_int32 volid; -afs_int32 voltype; -struct nvldbentry *newentry; -afs_int32 releasetype; -{ struct ubik_trans *trans; - afs_int32 blockindex, errorcode, typeindex; - int hashnewname; - int hashVol[MAXTYPES]; - struct nvlentry tentry; - - COUNT_REQ (VLREPLACEENTRYN); - for(typeindex = 0; typeindex < MAXTYPES; typeindex++) +afs_int32 +SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype) + struct rx_call *rxcall; + afs_int32 volid; + afs_int32 voltype; + struct nvldbentry *newentry; + afs_int32 releasetype; +{ + struct ubik_trans *trans; + afs_int32 blockindex, errorcode, typeindex; + int hashnewname; + int hashVol[MAXTYPES]; + struct nvlentry tentry; + + COUNT_REQ(VLREPLACEENTRYN); + for (typeindex = 0; typeindex < MAXTYPES; typeindex++) hashVol[typeindex] = 0; hashnewname = 0; - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) - END ( VL_PERM ); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) + END(VL_PERM); if (errorcode = check_nvldbentry(newentry)) goto end; if (voltype != -1 && InvalidVoltype(voltype)) - END ( VL_BADVOLTYPE ); + END(VL_BADVOLTYPE); if (releasetype && InvalidReleasetype(releasetype)) - END( VL_BADRELLOCKTYPE ); + END(VL_BADRELLOCKTYPE); if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) - goto end; + goto end; VLog(1, ("Replace Volume %d %s\n", volid, rxinfo(rxcall))); /* find vlentry we're changing */ blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode); - if (blockindex == 0) { /* entry not found */ - if (!errorcode) errorcode = VL_NOENT; + if (blockindex == 0) { /* entry not found */ + if (!errorcode) + errorcode = VL_NOENT; goto abort; } /* check that we're not trying to change the RW vol ID */ if (newentry->volumeId[RWVOL] != tentry.volumeId[RWVOL]) { - ABORT( VL_BADENTRY ); + ABORT(VL_BADENTRY); } /* unhash volid entries if they're disappearing or changing. @@ -711,15 +757,15 @@ afs_int32 releasetype; for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) { if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) { if (tentry.volumeId[typeindex]) - if (errorcode = UnhashVolid(trans, typeindex, blockindex, - &tentry)) { + if (errorcode = + UnhashVolid(trans, typeindex, blockindex, &tentry)) { goto abort; } /* we must rehash new id if the id is different and the ID is nonzero */ hashVol[typeindex] = 1; /* must rehash this guy if he exists */ } } - + /* Rehash volname if it changes */ if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */ if (errorcode = UnhashVolname(trans, blockindex, &tentry)) { @@ -729,12 +775,12 @@ afs_int32 releasetype; } /* after this, tentry is new entry, not old one. vldbentry_to_vlentry - doesn't touch hash chains */ + * doesn't touch hash chains */ if (errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry)) { goto abort; } - for(typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) { + for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) { if (hashVol[typeindex] && tentry.volumeId[typeindex]) { if (errorcode = HashVolid(trans, typeindex, blockindex, &tentry)) { goto abort; @@ -748,58 +794,63 @@ afs_int32 releasetype; if (releasetype) ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */ if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) { - ABORT( VL_IO ); + ABORT(VL_IO); } - END (ubik_EndTrans(trans)); + END(ubik_EndTrans(trans)); abort: COUNT_ABO; ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLReplaceVLEntryEvent, errorcode, AUD_LONG, volid, AUD_END); + osi_auditU(rxcall, VLReplaceVLEntryEvent, errorcode, AUD_LONG, volid, + AUD_END); return errorcode; } /* Update a vldb entry (accessed thru its volume id). Almost all of the entry's fields can be modified in a single call by setting the appropriate bits in the Mask field in VldbUpdateentry. */ /* this routine may never have been tested; use replace entry instead unless you're brave */ -SVL_UpdateEntry (rxcall, volid, voltype, updateentry, releasetype) - struct rx_call *rxcall; - afs_int32 volid; - afs_int32 voltype; - afs_int32 releasetype; - struct VldbUpdateEntry *updateentry; /* Update entry copied here */ -{ struct ubik_trans *trans; - afs_int32 blockindex, errorcode; - struct nvlentry tentry; - - COUNT_REQ (VLUPDATEENTRY); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) - END( VL_PERM ); - if ((voltype != -1 ) && (InvalidVoltype(voltype))) - END( VL_BADVOLTYPE ); +afs_int32 +SVL_UpdateEntry(rxcall, volid, voltype, updateentry, releasetype) + struct rx_call *rxcall; + afs_int32 volid; + afs_int32 voltype; + afs_int32 releasetype; + struct VldbUpdateEntry *updateentry; /* Update entry copied here */ +{ + struct ubik_trans *trans; + afs_int32 blockindex, errorcode; + struct nvlentry tentry; + + COUNT_REQ(VLUPDATEENTRY); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) + END(VL_PERM); + if ((voltype != -1) && (InvalidVoltype(voltype))) + END(VL_BADVOLTYPE); if (releasetype && InvalidReleasetype(releasetype)) - END( VL_BADRELLOCKTYPE ); - if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) - goto end; + END(VL_BADRELLOCKTYPE); + if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) + goto end; VLog(1, ("Update Volume %d %s\n", volid, rxinfo(rxcall))); blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode); - if (blockindex == 0) { /* entry not found */ - if (!errorcode) errorcode = VL_NOENT; + if (blockindex == 0) { /* entry not found */ + if (!errorcode) + errorcode = VL_NOENT; goto abort; } /* Do the actual updating of the entry, tentry. */ - if (errorcode = get_vldbupdateentry(trans, blockindex, updateentry, &tentry)) { + if (errorcode = + get_vldbupdateentry(trans, blockindex, updateentry, &tentry)) { goto abort; } if (releasetype) - ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */ + ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */ if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) { - ABORT( VL_IO ); + ABORT(VL_IO); } END(ubik_EndTrans(trans)); @@ -808,42 +859,47 @@ SVL_UpdateEntry (rxcall, volid, voltype, updateentry, releasetype) ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLUpdateEntryEvent, errorcode, AUD_LONG, volid, AUD_END); + osi_auditU(rxcall, VLUpdateEntryEvent, errorcode, AUD_LONG, volid, + AUD_END); return errorcode; } -SVL_UpdateEntryByName (rxcall, volname, updateentry, releasetype) - struct rx_call *rxcall; - char *volname; - afs_int32 releasetype; - struct VldbUpdateEntry *updateentry; /* Update entry copied here */ -{ struct ubik_trans *trans; - afs_int32 blockindex, errorcode; - struct nvlentry tentry; +afs_int32 +SVL_UpdateEntryByName(rxcall, volname, updateentry, releasetype) + struct rx_call *rxcall; + char *volname; + afs_int32 releasetype; + struct VldbUpdateEntry *updateentry; /* Update entry copied here */ +{ + struct ubik_trans *trans; + afs_int32 blockindex, errorcode; + struct nvlentry tentry; - COUNT_REQ (VLUPDATEENTRYBYNAME); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) - END( VL_PERM ); + COUNT_REQ(VLUPDATEENTRYBYNAME); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) + END(VL_PERM); if (releasetype && InvalidReleasetype(releasetype)) - END( VL_BADRELLOCKTYPE ); - if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) - goto end; + END(VL_BADRELLOCKTYPE); + if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) + goto end; blockindex = FindByName(trans, volname, &tentry, &errorcode); - if (blockindex == 0) { /* entry not found */ - if (!errorcode) errorcode = VL_NOENT; + if (blockindex == 0) { /* entry not found */ + if (!errorcode) + errorcode = VL_NOENT; goto abort; } /* Do the actual updating of the entry, tentry. */ - if (errorcode = get_vldbupdateentry(trans, blockindex, updateentry, &tentry)) { + if (errorcode = + get_vldbupdateentry(trans, blockindex, updateentry, &tentry)) { goto abort; } if (releasetype) - ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */ + ReleaseEntry(&tentry, releasetype); /* Unlock entry if necessary */ if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) { - ABORT( VL_IO ); + ABORT(VL_IO); } END(ubik_EndTrans(trans)); @@ -852,61 +908,64 @@ SVL_UpdateEntryByName (rxcall, volname, updateentry, releasetype) ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLUpdateEntryEvent, errorcode, AUD_LONG, -1, AUD_END); + osi_auditU(rxcall, VLUpdateEntryEvent, errorcode, AUD_LONG, -1, AUD_END); return errorcode; } /* Set a lock to the vldb entry for volid (of type voltype if not -1). */ -SVL_SetLock (rxcall, volid, voltype, voloper) -struct rx_call *rxcall; -afs_int32 volid; -afs_int32 voltype; -afs_int32 voloper; -{ afs_int32 timestamp, blockindex, errorcode; - struct ubik_trans *trans; - struct nvlentry tentry; +afs_int32 +SVL_SetLock(rxcall, volid, voltype, voloper) + struct rx_call *rxcall; + afs_int32 volid; + afs_int32 voltype; + afs_int32 voloper; +{ + afs_int32 timestamp, blockindex, errorcode; + struct ubik_trans *trans; + struct nvlentry tentry; COUNT_REQ(VLSETLOCK); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) - END( VL_PERM ); - if ((voltype != -1 ) && (InvalidVoltype(voltype))) - END( VL_BADVOLTYPE ); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) + END(VL_PERM); + if ((voltype != -1) && (InvalidVoltype(voltype))) + END(VL_BADVOLTYPE); if (InvalidOperation(voloper)) - END( VL_BADVOLOPER ); + END(VL_BADVOLOPER); if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) - goto end; + goto end; VLog(1, ("SetLock Volume %d %s\n", volid, rxinfo(rxcall))); blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode); if (blockindex == NULLO) { - if (!errorcode) errorcode = VL_NOENT; + if (!errorcode) + errorcode = VL_NOENT; goto abort; } if (tentry.flags & VLDELETED) { - ABORT( VL_ENTDELETED ); + ABORT(VL_ENTDELETED); } timestamp = FT_ApproxTime(); /* Check if entry is already locked; note that we unlock any entry * locked more than MAXLOCKTIME seconds */ - if ((tentry.LockTimestamp) - && ((timestamp - tentry.LockTimestamp) < MAXLOCKTIME)) { - ABORT( VL_ENTRYLOCKED ); + if ((tentry.LockTimestamp) + && ((timestamp - tentry.LockTimestamp) < MAXLOCKTIME)) { + ABORT(VL_ENTRYLOCKED); } /* Consider it an unlocked entry: set current timestamp, caller * and active vol operation */ tentry.LockTimestamp = timestamp; - tentry.LockAfsId = 0; /* Not implemented yet */ + tentry.LockAfsId = 0; /* Not implemented yet */ if (tentry.flags & VLOP_RELEASE) { - ABORT( VL_RERELEASE ); + ABORT(VL_RERELEASE); } - tentry.flags &= ~VLOP_ALLOPERS; /* Clear any possible older operation bit */ + tentry.flags &= ~VLOP_ALLOPERS; /* Clear any possible older operation bit */ tentry.flags |= voloper; if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) { - ABORT( VL_IO ); + ABORT(VL_IO); } END(ubik_EndTrans(trans)); @@ -915,7 +974,7 @@ afs_int32 voloper; ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLSetLockEvent, errorcode, AUD_LONG, volid, AUD_END); + osi_auditU(rxcall, VLSetLockEvent, errorcode, AUD_LONG, volid, AUD_END); return errorcode; } @@ -924,38 +983,41 @@ afs_int32 voloper; * fields (afsid and/or volume operation) will be cleared along with * the lock time stamp. */ -SVL_ReleaseLock (rxcall, volid, voltype, releasetype) -struct rx_call *rxcall; -afs_int32 volid; -afs_int32 voltype; -afs_int32 releasetype; -{ afs_int32 blockindex, errorcode; - struct ubik_trans *trans; - struct nvlentry tentry; +afs_int32 +SVL_ReleaseLock(rxcall, volid, voltype, releasetype) + struct rx_call *rxcall; + afs_int32 volid; + afs_int32 voltype; + afs_int32 releasetype; +{ + afs_int32 blockindex, errorcode; + struct ubik_trans *trans; + struct nvlentry tentry; COUNT_REQ(VLRELEASELOCK); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) - END( VL_PERM ); - if ((voltype != -1 ) && (InvalidVoltype(voltype))) - END( VL_BADVOLTYPE ); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) + END(VL_PERM); + if ((voltype != -1) && (InvalidVoltype(voltype))) + END(VL_BADVOLTYPE); if (releasetype && InvalidReleasetype(releasetype)) - END( VL_BADRELLOCKTYPE ); + END(VL_BADRELLOCKTYPE); if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)) goto end; VLog(1, ("ReleaseLock Volume %d %s\n", volid, rxinfo(rxcall))); blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode); if (blockindex == NULLO) { - if (!errorcode) errorcode = VL_NOENT; + if (!errorcode) + errorcode = VL_NOENT; goto abort; } if (tentry.flags & VLDELETED) { - ABORT( VL_ENTDELETED ); + ABORT(VL_ENTDELETED); } if (releasetype) - ReleaseEntry(&tentry, releasetype); /* Unlock the appropriate fields */ + ReleaseEntry(&tentry, releasetype); /* Unlock the appropriate fields */ if (vlentrywrite(trans, blockindex, &tentry, sizeof(tentry))) { - ABORT( VL_IO ); + ABORT(VL_IO); } END(ubik_EndTrans(trans)); @@ -964,73 +1026,81 @@ afs_int32 releasetype; ubik_AbortTrans(trans); end: - osi_auditU (rxcall, VLReleaseLockEvent, errorcode, AUD_LONG, volid, AUD_END); + osi_auditU(rxcall, VLReleaseLockEvent, errorcode, AUD_LONG, volid, + AUD_END); return errorcode; } - + /* ListEntry returns a single vldb entry, aentry, with offset previous_index; the remaining parameters (i.e. next_index) are used so that sequential calls to this routine will get the next (all) vldb entries. */ -SVL_ListEntry (rxcall, previous_index, count, next_index, aentry) -struct rx_call *rxcall; -afs_int32 previous_index; -afs_int32 *count; -afs_int32 *next_index; -struct vldbentry *aentry; -{ int errorcode; - struct ubik_trans *trans; - struct nvlentry tentry; +afs_int32 +SVL_ListEntry(rxcall, previous_index, count, next_index, aentry) + struct rx_call *rxcall; + afs_int32 previous_index; + afs_int32 *count; + afs_int32 *next_index; + struct vldbentry *aentry; +{ + int errorcode; + struct ubik_trans *trans; + struct nvlentry tentry; COUNT_REQ(VLLISTENTRY); if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; VLog(25, ("OListEntry index=%d %s\n", previous_index, rxinfo(rxcall))); *next_index = NextEntry(trans, previous_index, &tentry, count); - if (*next_index) + if (*next_index) vlentry_to_vldbentry(&tentry, aentry); - return(ubik_EndTrans(trans)); + return (ubik_EndTrans(trans)); } /* ListEntry returns a single vldb entry, aentry, with offset previous_index; the remaining parameters (i.e. next_index) are used so that sequential calls to this routine will get the next (all) vldb entries. */ -SVL_ListEntryN (rxcall, previous_index, count, next_index, aentry) -struct rx_call *rxcall; -afs_int32 previous_index; -afs_int32 *count; -afs_int32 *next_index; -struct nvldbentry *aentry; -{ int errorcode; - struct ubik_trans *trans; - struct nvlentry tentry; +afs_int32 +SVL_ListEntryN(rxcall, previous_index, count, next_index, aentry) + struct rx_call *rxcall; + afs_int32 previous_index; + afs_int32 *count; + afs_int32 *next_index; + struct nvldbentry *aentry; +{ + int errorcode; + struct ubik_trans *trans; + struct nvlentry tentry; COUNT_REQ(VLLISTENTRYN); if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxcall))); *next_index = NextEntry(trans, previous_index, &tentry, count); - if (*next_index) + if (*next_index) vlentry_to_nvldbentry(&tentry, aentry); - return(ubik_EndTrans(trans)); + return (ubik_EndTrans(trans)); } /* Retrieves in vldbentries all vldb entries that match the specified attributes (by server number, partition, volume type, and flag); if volume id is specified then the associated list for that entry is returned. CAUTION: This could be a very expensive call since in most cases sequential search of all vldb entries is performed. */ +afs_int32 SVL_ListAttributes(rxcall, attributes, nentries, vldbentries) -struct rx_call *rxcall; -struct VldbListByAttributes *attributes; -afs_int32 *nentries; -bulkentries *vldbentries; -{ int errorcode, allocCount = 0; - struct ubik_trans *trans; - struct nvlentry tentry; - struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0; - int pollcount = 0; - - COUNT_REQ (VLLISTATTRIBUTES); + struct rx_call *rxcall; + struct VldbListByAttributes *attributes; + afs_int32 *nentries; + bulkentries *vldbentries; +{ + int errorcode, allocCount = 0; + struct ubik_trans *trans; + struct nvlentry tentry; + struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0; + int pollcount = 0; + + COUNT_REQ(VLLISTATTRIBUTES); vldbentries->bulkentries_val = 0; vldbentries->bulkentries_len = *nentries = 0; if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; allocCount = VLDBALLOCCOUNT; - Vldbentry = VldbentryFirst = vldbentries->bulkentries_val = (vldbentry *)malloc(allocCount * sizeof(vldbentry)); + Vldbentry = VldbentryFirst = vldbentries->bulkentries_val = + (vldbentry *) malloc(allocCount * sizeof(vldbentry)); if (Vldbentry == NULL) { COUNT_ABO; ubik_AbortTrans(trans); @@ -1039,105 +1109,135 @@ bulkentries *vldbentries; VldbentryLast = VldbentryFirst + allocCount; /* Handle the attribute by volume id totally separate of the rest (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */ if (attributes->Mask & VLLIST_VOLUMEID) { - afs_int32 blockindex; + afs_int32 blockindex; - blockindex = FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); + blockindex = + FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); if (blockindex == 0) { - if (!errorcode) errorcode = VL_NOENT; + if (!errorcode) + errorcode = VL_NOENT; COUNT_ABO; ubik_AbortTrans(trans); - if(vldbentries->bulkentries_val)free((char *)vldbentries->bulkentries_val); + if (vldbentries->bulkentries_val) + free((char *)vldbentries->bulkentries_val); vldbentries->bulkentries_val = 0; vldbentries->bulkentries_len = 0; return errorcode; } - if (errorcode = put_attributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, &tentry, nentries, &allocCount)) { + if (errorcode = + put_attributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, + vldbentries, &tentry, nentries, &allocCount)) { COUNT_ABO; ubik_AbortTrans(trans); - if(vldbentries->bulkentries_val)free((char *)vldbentries->bulkentries_val); + if (vldbentries->bulkentries_val) + free((char *)vldbentries->bulkentries_val); vldbentries->bulkentries_val = 0; vldbentries->bulkentries_len = 0; return VL_SIZEEXCEEDED; } } else { - afs_int32 nextblockindex=0, count=0, k, match=0; - while (nextblockindex = NextEntry(trans, nextblockindex, &tentry, &count)) { + afs_int32 nextblockindex = 0, count = 0, k, match = 0; + while (nextblockindex = + NextEntry(trans, nextblockindex, &tentry, &count)) { if (++pollcount > 50) { - IOMGR_Poll(); - pollcount = 0; + IOMGR_Poll(); + pollcount = 0; } match = 0; if (attributes->Mask & VLLIST_SERVER) { int serverindex; - if ((serverindex = IpAddrToRelAddr(attributes->server, (struct ubik_trans *) 0)) == -1) continue; - for (k=0; kserver, + (struct ubik_trans *)0)) == -1) + continue; + for (k = 0; k < OMAXNSERVERS; k++) { + if (tentry.serverNumber[k] == BADSERVERID) + break; if (tentry.serverNumber[k] == serverindex) { match = 1; break; } } - if (!match) continue; + if (!match) + continue; } if (attributes->Mask & VLLIST_PARTITION) { if (match) { - if (tentry.serverPartition[k] != attributes->partition) continue; + if (tentry.serverPartition[k] != attributes->partition) + continue; } else { - for (k=0; kpartition) { + for (k = 0; k < OMAXNSERVERS; k++) { + if (tentry.serverNumber[k] == BADSERVERID) + break; + if (tentry.serverPartition[k] == + attributes->partition) { match = 1; break; } } - if (!match) continue; + if (!match) + continue; } } if (attributes->Mask & VLLIST_FLAG) { - if (!(tentry.flags & attributes->flag)) continue; + if (!(tentry.flags & attributes->flag)) + continue; } - if (errorcode = put_attributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, &tentry, nentries, &allocCount)) { + if (errorcode = + put_attributeentry(&Vldbentry, &VldbentryFirst, + &VldbentryLast, vldbentries, &tentry, + nentries, &allocCount)) { COUNT_ABO; ubik_AbortTrans(trans); - if(vldbentries->bulkentries_val)free((char *)vldbentries->bulkentries_val); + if (vldbentries->bulkentries_val) + free((char *)vldbentries->bulkentries_val); vldbentries->bulkentries_val = 0; vldbentries->bulkentries_len = 0; return errorcode; } } } - if (vldbentries->bulkentries_len && (allocCount > vldbentries->bulkentries_len)) { + if (vldbentries->bulkentries_len + && (allocCount > vldbentries->bulkentries_len)) { - vldbentries->bulkentries_val = (vldbentry *) realloc(vldbentries->bulkentries_val, vldbentries->bulkentries_len * sizeof(vldbentry)); + vldbentries->bulkentries_val = + (vldbentry *) realloc(vldbentries->bulkentries_val, + vldbentries->bulkentries_len * + sizeof(vldbentry)); if (vldbentries->bulkentries_val == NULL) { COUNT_ABO; ubik_AbortTrans(trans); return VL_NOMEM; } } - VLog(5, ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len, rxinfo(rxcall))); - return(ubik_EndTrans(trans)); + VLog(5, + ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len, + rxinfo(rxcall))); + return (ubik_EndTrans(trans)); } +afs_int32 SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries) -struct rx_call *rxcall; -struct VldbListByAttributes *attributes; -afs_int32 *nentries; -nbulkentries *vldbentries; -{ int errorcode, allocCount = 0; - struct ubik_trans *trans; - struct nvlentry tentry; - struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0; - int pollcount = 0; - - COUNT_REQ (VLLISTATTRIBUTESN); + struct rx_call *rxcall; + struct VldbListByAttributes *attributes; + afs_int32 *nentries; + nbulkentries *vldbentries; +{ + int errorcode, allocCount = 0; + struct ubik_trans *trans; + struct nvlentry tentry; + struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0; + int pollcount = 0; + + COUNT_REQ(VLLISTATTRIBUTESN); vldbentries->nbulkentries_val = 0; vldbentries->nbulkentries_len = *nentries = 0; if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; allocCount = VLDBALLOCCOUNT; - Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val = (nvldbentry *)malloc(allocCount * sizeof(nvldbentry)); + Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val = + (nvldbentry *) malloc(allocCount * sizeof(nvldbentry)); if (Vldbentry == NULL) { COUNT_ABO; ubik_AbortTrans(trans); @@ -1146,298 +1246,379 @@ nbulkentries *vldbentries; VldbentryLast = VldbentryFirst + allocCount; /* Handle the attribute by volume id totally separate of the rest (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */ if (attributes->Mask & VLLIST_VOLUMEID) { - afs_int32 blockindex; + afs_int32 blockindex; - blockindex = FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); + blockindex = + FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); if (blockindex == 0) { - if (!errorcode) errorcode = VL_NOENT; + if (!errorcode) + errorcode = VL_NOENT; COUNT_ABO; ubik_AbortTrans(trans); - if(vldbentries->nbulkentries_val)free((char *)vldbentries->nbulkentries_val); + if (vldbentries->nbulkentries_val) + free((char *)vldbentries->nbulkentries_val); vldbentries->nbulkentries_val = 0; vldbentries->nbulkentries_len = 0; return errorcode; } - if (errorcode = put_nattributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, - &tentry, 0, 0, nentries, &allocCount)) { + if (errorcode = + put_nattributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, + vldbentries, &tentry, 0, 0, nentries, + &allocCount)) { COUNT_ABO; ubik_AbortTrans(trans); - if(vldbentries->nbulkentries_val)free((char *)vldbentries->nbulkentries_val); + if (vldbentries->nbulkentries_val) + free((char *)vldbentries->nbulkentries_val); vldbentries->nbulkentries_val = 0; vldbentries->nbulkentries_len = 0; return VL_SIZEEXCEEDED; } } else { - afs_int32 nextblockindex=0, count=0, k, match=0; - while (nextblockindex = NextEntry(trans, nextblockindex, &tentry, &count)) { + afs_int32 nextblockindex = 0, count = 0, k, match = 0; + while (nextblockindex = + NextEntry(trans, nextblockindex, &tentry, &count)) { if (++pollcount > 50) { - IOMGR_Poll(); - pollcount = 0; + IOMGR_Poll(); + pollcount = 0; } match = 0; if (attributes->Mask & VLLIST_SERVER) { int serverindex; - if ((serverindex = IpAddrToRelAddr(attributes->server, (struct ubik_trans *) 0)) == -1) continue; - for (k=0; kserver, + (struct ubik_trans *)0)) == -1) + continue; + for (k = 0; k < NMAXNSERVERS; k++) { + if (tentry.serverNumber[k] == BADSERVERID) + break; if (tentry.serverNumber[k] == serverindex) { match = 1; break; } } - if (!match) continue; + if (!match) + continue; } if (attributes->Mask & VLLIST_PARTITION) { if (match) { - if (tentry.serverPartition[k] != attributes->partition) continue; + if (tentry.serverPartition[k] != attributes->partition) + continue; } else { - for (k=0; kpartition) { + for (k = 0; k < NMAXNSERVERS; k++) { + if (tentry.serverNumber[k] == BADSERVERID) + break; + if (tentry.serverPartition[k] == + attributes->partition) { match = 1; break; } } - if (!match) continue; + if (!match) + continue; } } if (attributes->Mask & VLLIST_FLAG) { - if (!(tentry.flags & attributes->flag)) continue; + if (!(tentry.flags & attributes->flag)) + continue; } - if (errorcode = put_nattributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, - vldbentries, &tentry, 0, 0, nentries, &allocCount)) { + if (errorcode = + put_nattributeentry(&Vldbentry, &VldbentryFirst, + &VldbentryLast, vldbentries, &tentry, 0, + 0, nentries, &allocCount)) { COUNT_ABO; ubik_AbortTrans(trans); - if(vldbentries->nbulkentries_val)free((char *)vldbentries->nbulkentries_val); + if (vldbentries->nbulkentries_val) + free((char *)vldbentries->nbulkentries_val); vldbentries->nbulkentries_val = 0; vldbentries->nbulkentries_len = 0; return errorcode; } } } - if (vldbentries->nbulkentries_len && (allocCount > vldbentries->nbulkentries_len)) { + if (vldbentries->nbulkentries_len + && (allocCount > vldbentries->nbulkentries_len)) { - vldbentries->nbulkentries_val = (nvldbentry *) realloc(vldbentries->nbulkentries_val, - vldbentries->nbulkentries_len * sizeof(nvldbentry)); + vldbentries->nbulkentries_val = + (nvldbentry *) realloc(vldbentries->nbulkentries_val, + vldbentries->nbulkentries_len * + sizeof(nvldbentry)); if (vldbentries->nbulkentries_val == NULL) { COUNT_ABO; ubik_AbortTrans(trans); return VL_NOMEM; } } - VLog(5, ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len, rxinfo(rxcall))); - return(ubik_EndTrans(trans)); + VLog(5, + ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len, + rxinfo(rxcall))); + return (ubik_EndTrans(trans)); } -SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries, vldbentries, nextstartindex) - struct rx_call *rxcall; - struct VldbListByAttributes *attributes; - char * name; /* Wildcarded volume name */ - afs_int32 startindex; - afs_int32 *nentries; - nbulkentries *vldbentries; - afs_int32 *nextstartindex; +afs_int32 +SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries, + vldbentries, nextstartindex) + struct rx_call *rxcall; + struct VldbListByAttributes *attributes; + char *name; /* Wildcarded volume name */ + afs_int32 startindex; + afs_int32 *nentries; + nbulkentries *vldbentries; + afs_int32 *nextstartindex; { - int errorcode=0, maxCount=VLDBALLOCCOUNT; - struct ubik_trans *trans; - struct nvlentry tentry; - struct nvldbentry *Vldbentry=0, *VldbentryFirst=0, *VldbentryLast=0; - afs_int32 blockindex=0, count=0, k, match, matchindex; - int serverindex=-1; /* no server found */ - int findserver=0, findpartition=0, findflag=0, findname=0; - char *t; - int pollcount=0; - int namematchRWBK, namematchRO, thismatch, matchtype; - char volumename[VL_MAXNAMELEN]; - - COUNT_REQ (VLLISTATTRIBUTESN2); - vldbentries->nbulkentries_val = 0; - vldbentries->nbulkentries_len = 0; - *nentries = 0; - *nextstartindex = -1; - - errorcode = Init_VLdbase(&trans, LOCKREAD, this_op); - if (errorcode) return errorcode; - - Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val = (nvldbentry *)malloc(maxCount * sizeof(nvldbentry)); - if (Vldbentry == NULL) { - COUNT_ABO; - ubik_AbortTrans(trans); - return VL_NOMEM; - } - - VldbentryLast = VldbentryFirst + maxCount; - - /* Handle the attribute by volume id totally separate of the rest - * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) - */ - if (attributes->Mask & VLLIST_VOLUMEID) { - blockindex = FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); - if (blockindex == 0) { - if (!errorcode) errorcode = VL_NOENT; - } else { - errorcode = put_nattributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, - vldbentries, &tentry, 0, 0, nentries, &maxCount); - if (errorcode) goto done; - } - } - - /* Search each entry in the database and return all entries - * that match the request. It checks volumename (with - * wildcarding), entry flags, server, and partition. - */ - else { - /* Get the server index for matching server address */ - if (attributes->Mask & VLLIST_SERVER) { - serverindex = IpAddrToRelAddr(attributes->server, (struct ubik_trans *)0); - if (serverindex == -1) goto done; - findserver = 1; - } - findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0); - findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0); - if (name && (strcmp(name,".*") != 0) && (strcmp(name,"") != 0)) { - sprintf(volumename, "^%s$", name); - t = (char *)re_comp(volumename); - if (t) { - errorcode = VL_BADNAME; - goto done; - } - findname = 1; - } - - /* Read each entry and see if it is the one we want */ - blockindex = startindex; - while (blockindex = NextEntry(trans, blockindex, &tentry, &count)) { - if (++pollcount > 50) { - IOMGR_Poll(); - pollcount = 0; - } - - /* Step through each server index searching for a match. - * Match to an existing RW, BK, or RO volume name (preference - * is in this order). Remember which index we matched against. - */ - namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */ - match = 0; - for (k=0; (knbulkentries_val = 0; + vldbentries->nbulkentries_len = 0; + *nentries = 0; + *nextstartindex = -1; + + errorcode = Init_VLdbase(&trans, LOCKREAD, this_op); + if (errorcode) + return errorcode; + + Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val = + (nvldbentry *) malloc(maxCount * sizeof(nvldbentry)); + if (Vldbentry == NULL) { + COUNT_ABO; + ubik_AbortTrans(trans); + return VL_NOMEM; + } + + VldbentryLast = VldbentryFirst + maxCount; + + /* Handle the attribute by volume id totally separate of the rest + * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) + */ + if (attributes->Mask & VLLIST_VOLUMEID) { + blockindex = + FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); + if (blockindex == 0) { + if (!errorcode) + errorcode = VL_NOENT; + } else { + errorcode = + put_nattributeentry(&Vldbentry, &VldbentryFirst, + &VldbentryLast, vldbentries, &tentry, 0, + 0, nentries, &maxCount); + if (errorcode) + goto done; + } + } + + /* Search each entry in the database and return all entries + * that match the request. It checks volumename (with + * wildcarding), entry flags, server, and partition. + */ + else { + /* Get the server index for matching server address */ + if (attributes->Mask & VLLIST_SERVER) { + serverindex = + IpAddrToRelAddr(attributes->server, (struct ubik_trans *)0); + if (serverindex == -1) + goto done; + findserver = 1; + } + findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0); + findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0); + if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) { + sprintf(volumename, "^%s$", name); +#ifdef HAVE_POSIX_REGEX + if (regcomp(&re, volumename, REG_NOSUB) != 0) { + errorcode = VL_BADNAME; + goto done; + } + need_regfree = 1; +#else + t = (char *)re_comp(volumename); + if (t) { + errorcode = VL_BADNAME; + goto done; + } +#endif + findname = 1; + } + + /* Read each entry and see if it is the one we want */ + blockindex = startindex; + while (blockindex = NextEntry(trans, blockindex, &tentry, &count)) { + if (++pollcount > 50) { + IOMGR_Poll(); + pollcount = 0; + } + + /* Step through each server index searching for a match. + * Match to an existing RW, BK, or RO volume name (preference + * is in this order). Remember which index we matched against. + */ + namematchRWBK = namematchRO = 0; /* 0->notTried; 1->match; 2->noMatch */ + match = 0; + for (k = 0; + (k < NMAXNSERVERS + && (tentry.serverNumber[k] != BADSERVERID)); k++) { + thismatch = 0; /* does this index match */ + + /* Match against the RW or BK volume name. Remember + * results in namematchRWBK. Prefer RW over BK. + */ + if (tentry.serverFlags[k] & VLSF_RWVOL) { + /* Does the name match the RW name */ + if (tentry.flags & VLF_RWEXISTS) { + if (findname) { + sprintf(volumename, "%s", tentry.name); +#ifdef HAVE_POSIX_REGEX + if (regexec(&re, volumename, 0, NULL, 0) == 0) { + thismatch = VLSF_RWVOL; + } +#else + if (re_exec(volumename)) { + thismatch = VLSF_RWVOL; + } +#endif + } else { + thismatch = VLSF_RWVOL; + } } - } else { - thismatch = VLSF_RWVOL; - } - } - - /* Does the name match the BK name */ - if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) { - if (findname) { - sprintf(volumename, "%s.backup", tentry.name); - if (re_exec(volumename)) { - thismatch = VLSF_BACKVOL; + + /* Does the name match the BK name */ + if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) { + if (findname) { + sprintf(volumename, "%s.backup", tentry.name); +#ifdef HAVE_POSIX_REGEX + if (regexec(&re, volumename, 0, NULL, 0) == 0) { + thismatch = VLSF_BACKVOL; + } +#else + if (re_exec(volumename)) { + thismatch = VLSF_BACKVOL; + } +#endif + } else { + thismatch = VLSF_BACKVOL; + } } - } else { - thismatch = VLSF_BACKVOL; - } - } - - namematchRWBK = (thismatch?1:2); - } - - /* Match with the RO volume name. Compare once and - * remember results in namematchRO. Note that this will - * pick up entries marked NEWREPSITEs and DONTUSE. - */ - else { - if (tentry.flags & VLF_ROEXISTS) { - if (findname) { - if (namematchRO) { - thismatch = ((namematchRO == 1)?VLSF_ROVOL:0); - } else { - sprintf(volumename, "%s.readonly", tentry.name); - if (re_exec(volumename)) - thismatch = VLSF_ROVOL; + + namematchRWBK = (thismatch ? 1 : 2); + } + + /* Match with the RO volume name. Compare once and + * remember results in namematchRO. Note that this will + * pick up entries marked NEWREPSITEs and DONTUSE. + */ + else { + if (tentry.flags & VLF_ROEXISTS) { + if (findname) { + if (namematchRO) { + thismatch = + ((namematchRO == 1) ? VLSF_ROVOL : 0); + } else { + sprintf(volumename, "%s.readonly", + tentry.name); +#ifdef HAVE_POSIX_REGEX + if (regexec(&re, volumename, 0, NULL, 0) == 0) { + thismatch = VLSF_ROVOL; + } +#else + if (re_exec(volumename)) + thismatch = VLSF_ROVOL; +#endif + } + } else { + thismatch = VLSF_ROVOL; + } } - } else { - thismatch = VLSF_ROVOL; - } - } - namematchRO = (thismatch?1:2); - } - - /* Is there a server match */ - if (thismatch && findserver && - (tentry.serverNumber[k] != serverindex)) - thismatch = 0; - - /* Is there a partition match */ - if (thismatch && findpartition && - (tentry.serverPartition[k] != attributes->partition)) - thismatch = 0; - - /* Is there a flag match */ - if (thismatch && findflag && !(tentry.flags & attributes->flag)) - thismatch = 0; - - /* We found a match. Remember the index, and type */ - if (thismatch) { - match = 1; - matchindex = k; - matchtype = thismatch; - } - - /* Since we prefer RW and BK volume matches over RO matches, - * if we have already checked the RWBK name, then we already - * found the best match and so end the search. - * - * If we tried matching against the RW, BK, and RO volume names - * and both failed, then we end the search (none will match). - */ - if ( (match && namematchRWBK) || - ((namematchRWBK==2) && (namematchRO==2)) ) - break; - } - - /* Passed all the tests. Take it */ - if (match) { - errorcode = put_nattributeentry(&Vldbentry, - &VldbentryFirst, &VldbentryLast, - vldbentries, &tentry, matchtype, matchindex, - nentries, &maxCount); - if (errorcode) goto done; - - if (*nentries >= maxCount) break; /* collected the max */ - } - } - *nextstartindex = (blockindex ? blockindex : -1); - } - - done: - if (errorcode) { - COUNT_ABO; - ubik_AbortTrans(trans); - if (vldbentries->nbulkentries_val) - free((char *)vldbentries->nbulkentries_val); - vldbentries->nbulkentries_val = 0; - vldbentries->nbulkentries_len = 0; - *nextstartindex = -1; - return errorcode; - } else { - VLog(5, ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len, rxinfo(rxcall))); - return(ubik_EndTrans(trans)); - } + namematchRO = (thismatch ? 1 : 2); + } + + /* Is there a server match */ + if (thismatch && findserver + && (tentry.serverNumber[k] != serverindex)) + thismatch = 0; + + /* Is there a partition match */ + if (thismatch && findpartition + && (tentry.serverPartition[k] != attributes->partition)) + thismatch = 0; + + /* Is there a flag match */ + if (thismatch && findflag + && !(tentry.flags & attributes->flag)) + thismatch = 0; + + /* We found a match. Remember the index, and type */ + if (thismatch) { + match = 1; + matchindex = k; + matchtype = thismatch; + } + + /* Since we prefer RW and BK volume matches over RO matches, + * if we have already checked the RWBK name, then we already + * found the best match and so end the search. + * + * If we tried matching against the RW, BK, and RO volume names + * and both failed, then we end the search (none will match). + */ + if ((match && namematchRWBK) + || ((namematchRWBK == 2) && (namematchRO == 2))) + break; + } + + /* Passed all the tests. Take it */ + if (match) { + errorcode = + put_nattributeentry(&Vldbentry, &VldbentryFirst, + &VldbentryLast, vldbentries, &tentry, + matchtype, matchindex, nentries, + &maxCount); + if (errorcode) + goto done; + + if (*nentries >= maxCount) + break; /* collected the max */ + } + } + *nextstartindex = (blockindex ? blockindex : -1); + } + + done: +#ifdef HAVE_POSIX_REGEX + if (need_regfree) + regfree(&re); +#endif + + if (errorcode) { + COUNT_ABO; + ubik_AbortTrans(trans); + if (vldbentries->nbulkentries_val) + free((char *)vldbentries->nbulkentries_val); + vldbentries->nbulkentries_val = 0; + vldbentries->nbulkentries_len = 0; + *nextstartindex = -1; + return errorcode; + } else { + VLog(5, + ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len, + rxinfo(rxcall))); + return (ubik_EndTrans(trans)); + } } @@ -1447,21 +1628,22 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries, vldbentries * returned. CAUTION: This could be a very expensive call since in most * cases sequential search of all vldb entries is performed. */ +afs_int32 SVL_LinkedList(rxcall, attributes, nentries, vldbentries) - struct rx_call *rxcall; - struct VldbListByAttributes *attributes; - afs_int32 *nentries; - vldb_list *vldbentries; -{ - int errorcode; - struct ubik_trans *trans; - struct nvlentry tentry; - vldblist vllist, *vllistptr; - afs_int32 blockindex, count, k, match; - int serverindex; - int pollcount = 0; - - COUNT_REQ (VLLINKEDLIST); + struct rx_call *rxcall; + struct VldbListByAttributes *attributes; + afs_int32 *nentries; + vldb_list *vldbentries; +{ + int errorcode; + struct ubik_trans *trans; + struct nvlentry tentry; + vldblist vllist, *vllistptr; + afs_int32 blockindex, count, k, match; + int serverindex; + int pollcount = 0; + + COUNT_REQ(VLLINKEDLIST); if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; @@ -1471,7 +1653,8 @@ SVL_LinkedList(rxcall, attributes, nentries, vldbentries) /* List by volumeid */ if (attributes->Mask & VLLIST_VOLUMEID) { - blockindex = FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); + blockindex = + FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); if (!blockindex) { COUNT_ABO; ubik_AbortTrans(trans); @@ -1480,65 +1663,72 @@ SVL_LinkedList(rxcall, attributes, nentries, vldbentries) vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry)); if (vllist == NULL) { - COUNT_ABO; - ubik_AbortTrans(trans); - return VL_NOMEM; + COUNT_ABO; + ubik_AbortTrans(trans); + return VL_NOMEM; } vlentry_to_vldbentry(&tentry, &vllist->VldbEntry); vllist->next_vldb = NULL; - *vllistptr = vllist; /* Thread onto list */ + *vllistptr = vllist; /* Thread onto list */ vllistptr = &vllist->next_vldb; (*nentries)++; } /* Search by server, partition, and flags */ else { - for (blockindex = NextEntry(trans, 0, &tentry, &count); - blockindex; + for (blockindex = NextEntry(trans, 0, &tentry, &count); blockindex; blockindex = NextEntry(trans, blockindex, &tentry, &count)) { match = 0; - + if (++pollcount > 50) { - IOMGR_Poll(); - pollcount = 0; + IOMGR_Poll(); + pollcount = 0; } /* Does this volume exist on the desired server */ if (attributes->Mask & VLLIST_SERVER) { - serverindex = IpAddrToRelAddr(attributes->server, (struct ubik_trans *)0); - if (serverindex == -1) continue; - for (k=0; k < OMAXNSERVERS; k++) { - if (tentry.serverNumber[k] == BADSERVERID) break; + serverindex = + IpAddrToRelAddr(attributes->server, + (struct ubik_trans *)0); + if (serverindex == -1) + continue; + for (k = 0; k < OMAXNSERVERS; k++) { + if (tentry.serverNumber[k] == BADSERVERID) + break; if (tentry.serverNumber[k] == serverindex) { - match = 1; - break; + match = 1; + break; } } - if (!match) continue; + if (!match) + continue; } /* Does this volume exist on the desired partition */ if (attributes->Mask & VLLIST_PARTITION) { if (match) { if (tentry.serverPartition[k] != attributes->partition) - match = 0; + match = 0; } else { - for (k=0; k < OMAXNSERVERS; k++) { - if (tentry.serverNumber[k] == BADSERVERID) break; - if (tentry.serverPartition[k] == attributes->partition) { + for (k = 0; k < OMAXNSERVERS; k++) { + if (tentry.serverNumber[k] == BADSERVERID) + break; + if (tentry.serverPartition[k] == + attributes->partition) { match = 1; break; } } } - if (!match) continue; + if (!match) + continue; } /* Does this volume have the desired flags */ if (attributes->Mask & VLLIST_FLAG) { if (!(tentry.flags & attributes->flag)) - continue; + continue; } vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry)); @@ -1550,35 +1740,36 @@ SVL_LinkedList(rxcall, attributes, nentries, vldbentries) vlentry_to_vldbentry(&tentry, &vllist->VldbEntry); vllist->next_vldb = NULL; - *vllistptr = vllist; /* Thread onto list */ + *vllistptr = vllist; /* Thread onto list */ vllistptr = &vllist->next_vldb; (*nentries)++; if (smallMem && (*nentries >= VLDBALLOCCOUNT)) { - COUNT_ABO; - ubik_AbortTrans(trans); - return VL_SIZEEXCEEDED; + COUNT_ABO; + ubik_AbortTrans(trans); + return VL_SIZEEXCEEDED; } } } *vllistptr = NULL; - return(ubik_EndTrans(trans)); + return (ubik_EndTrans(trans)); } +afs_int32 SVL_LinkedListN(rxcall, attributes, nentries, vldbentries) - struct rx_call *rxcall; - struct VldbListByAttributes *attributes; - afs_int32 *nentries; - nvldb_list *vldbentries; + struct rx_call *rxcall; + struct VldbListByAttributes *attributes; + afs_int32 *nentries; + nvldb_list *vldbentries; { - int errorcode; - struct ubik_trans *trans; - struct nvlentry tentry; - nvldblist vllist, *vllistptr; - afs_int32 blockindex, count, k, match; - int serverindex; - int pollcount = 0; - - COUNT_REQ (VLLINKEDLISTN); + int errorcode; + struct ubik_trans *trans; + struct nvlentry tentry; + nvldblist vllist, *vllistptr; + afs_int32 blockindex, count, k, match; + int serverindex; + int pollcount = 0; + + COUNT_REQ(VLLINKEDLISTN); if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; @@ -1588,7 +1779,8 @@ SVL_LinkedListN(rxcall, attributes, nentries, vldbentries) /* List by volumeid */ if (attributes->Mask & VLLIST_VOLUMEID) { - blockindex = FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); + blockindex = + FindByID(trans, attributes->volumeid, -1, &tentry, &errorcode); if (!blockindex) { COUNT_ABO; ubik_AbortTrans(trans); @@ -1597,65 +1789,72 @@ SVL_LinkedListN(rxcall, attributes, nentries, vldbentries) vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry)); if (vllist == NULL) { - COUNT_ABO; - ubik_AbortTrans(trans); - return VL_NOMEM; + COUNT_ABO; + ubik_AbortTrans(trans); + return VL_NOMEM; } vlentry_to_nvldbentry(&tentry, &vllist->VldbEntry); vllist->next_vldb = NULL; - *vllistptr = vllist; /* Thread onto list */ + *vllistptr = vllist; /* Thread onto list */ vllistptr = &vllist->next_vldb; (*nentries)++; } /* Search by server, partition, and flags */ else { - for (blockindex = NextEntry(trans, 0, &tentry, &count); - blockindex; + for (blockindex = NextEntry(trans, 0, &tentry, &count); blockindex; blockindex = NextEntry(trans, blockindex, &tentry, &count)) { match = 0; - + if (++pollcount > 50) { - IOMGR_Poll(); - pollcount = 0; + IOMGR_Poll(); + pollcount = 0; } /* Does this volume exist on the desired server */ if (attributes->Mask & VLLIST_SERVER) { - serverindex = IpAddrToRelAddr(attributes->server, (struct ubik_trans *)0); - if (serverindex == -1) continue; - for (k=0; k < NMAXNSERVERS; k++) { - if (tentry.serverNumber[k] == BADSERVERID) break; + serverindex = + IpAddrToRelAddr(attributes->server, + (struct ubik_trans *)0); + if (serverindex == -1) + continue; + for (k = 0; k < NMAXNSERVERS; k++) { + if (tentry.serverNumber[k] == BADSERVERID) + break; if (tentry.serverNumber[k] == serverindex) { - match = 1; - break; + match = 1; + break; } } - if (!match) continue; + if (!match) + continue; } /* Does this volume exist on the desired partition */ if (attributes->Mask & VLLIST_PARTITION) { if (match) { if (tentry.serverPartition[k] != attributes->partition) - match = 0; + match = 0; } else { - for (k=0; k < NMAXNSERVERS; k++) { - if (tentry.serverNumber[k] == BADSERVERID) break; - if (tentry.serverPartition[k] == attributes->partition) { + for (k = 0; k < NMAXNSERVERS; k++) { + if (tentry.serverNumber[k] == BADSERVERID) + break; + if (tentry.serverPartition[k] == + attributes->partition) { match = 1; break; } } } - if (!match) continue; + if (!match) + continue; } /* Does this volume have the desired flags */ if (attributes->Mask & VLLIST_FLAG) { if (!(tentry.flags & attributes->flag)) - continue; + continue; } vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry)); @@ -1667,68 +1866,74 @@ SVL_LinkedListN(rxcall, attributes, nentries, vldbentries) vlentry_to_nvldbentry(&tentry, &vllist->VldbEntry); vllist->next_vldb = NULL; - *vllistptr = vllist; /* Thread onto list */ + *vllistptr = vllist; /* Thread onto list */ vllistptr = &vllist->next_vldb; (*nentries)++; if (smallMem && (*nentries >= VLDBALLOCCOUNT)) { - COUNT_ABO; - ubik_AbortTrans(trans); - return VL_SIZEEXCEEDED; + COUNT_ABO; + ubik_AbortTrans(trans); + return VL_SIZEEXCEEDED; } } } *vllistptr = NULL; - return(ubik_EndTrans(trans)); + return (ubik_EndTrans(trans)); } /* Get back vldb header statistics (allocs, frees, maxvolumeid, totalentries, etc) and dynamic statistics (number of requests and/or aborts per remote procedure call, etc) */ +afs_int32 SVL_GetStats(rxcall, stats, vital_header) -struct rx_call *rxcall; -vldstats *stats; -vital_vlheader *vital_header; -{ register afs_int32 errorcode; - struct ubik_trans *trans; + struct rx_call *rxcall; + vldstats *stats; + vital_vlheader *vital_header; +{ + register afs_int32 errorcode; + struct ubik_trans *trans; COUNT_REQ(VLGETSTATS); #ifdef notdef /* Allow users to get statistics freely */ - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) /* Must be in 'UserList' to use */ + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) /* Must be in 'UserList' to use */ return VL_PERM; #endif if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; - VLog(5, ("GetStats %\n", rxinfo(rxcall))); - memcpy((char *) vital_header, (char *)&cheader.vital_header, sizeof(vital_vlheader)); - memcpy((char *) stats, (char *)&dynamic_statistics, sizeof(vldstats)); - return(ubik_EndTrans(trans)); + VLog(5, ("GetStats %s\n", rxinfo(rxcall))); + memcpy((char *)vital_header, (char *)&cheader.vital_header, + sizeof(vital_vlheader)); + memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats)); + return (ubik_EndTrans(trans)); } /* Get the list of file server addresses from the VLDB. Currently it's pretty * easy to do. In the future, it might require a little bit of grunging * through the VLDB, but that's life. */ +afs_int32 SVL_GetAddrs(rxcall, Handle, spare2, spare3, nentries, addrsp) -struct rx_call *rxcall; -afs_int32 Handle, spare2; -struct VLCallBack *spare3; -afs_int32 *nentries; -bulkaddrs *addrsp; -{ register afs_int32 errorcode; - struct ubik_trans *trans; + struct rx_call *rxcall; + afs_int32 Handle, spare2; + struct VLCallBack *spare3; + afs_int32 *nentries; + bulkaddrs *addrsp; +{ + register afs_int32 errorcode; + struct ubik_trans *trans; int nservers, i; afs_uint32 *taddrp; COUNT_REQ(VLGETADDRS); addrsp->bulkaddrs_len = *nentries = 0; addrsp->bulkaddrs_val = 0; - memset(spare3, 0, sizeof (struct VLCallBack)); + memset(spare3, 0, sizeof(struct VLCallBack)); if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)) return errorcode; VLog(5, ("GetAddrs\n")); - addrsp->bulkaddrs_val = taddrp = (afs_uint32 *)malloc(sizeof(afs_int32)*(MAXSERVERID+1)); - nservers= *nentries = addrsp->bulkaddrs_len = 0; + addrsp->bulkaddrs_val = taddrp = + (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1)); + nservers = *nentries = addrsp->bulkaddrs_len = 0; if (!taddrp) { COUNT_ABO; @@ -1736,373 +1941,408 @@ bulkaddrs *addrsp; return VL_NOMEM; } - for (i=0; i <= MAXSERVERID; i++) { - if (*taddrp = ntohl(cheader.IpMappedAddr[i])) { - taddrp++; - nservers++; - } - } + for (i = 0; i <= MAXSERVERID; i++) { + if (*taddrp = ntohl(cheader.IpMappedAddr[i])) { + taddrp++; + nservers++; + } + } addrsp->bulkaddrs_len = *nentries = nservers; - return(ubik_EndTrans(trans)); + return (ubik_EndTrans(trans)); } #define PADDR(addr) printf("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff); +afs_int32 SVL_RegisterAddrs(rxcall, uuidp, spare1, addrsp) - struct rx_call *rxcall; - afsUUID *uuidp; - afs_int32 spare1; - bulkaddrs *addrsp; + struct rx_call *rxcall; + afsUUID *uuidp; + afs_int32 spare1; + bulkaddrs *addrsp; { - afs_int32 code; - struct ubik_trans *trans; - int cnt, h, i, j, k, m, base, index; - struct extentaddr *exp = 0, *tex; - afsUUID tuuid; - afs_uint32 addrs[VL_MAXIPADDRS_PERMH]; - afs_int32 fbase; - int count, willChangeEntry, foundUuidEntry, willReplaceCnt; - int WillReplaceEntry, WillChange[MAXSERVERID+1], FoundUuid, ReplaceEntry; - int srvidx, mhidx; - - COUNT_REQ(VLREGADDR); - if (!afsconf_SuperUser(vldb_confdir, rxcall, (char *)0)) - return (VL_PERM); - if (code = Init_VLdbase(&trans, LOCKWRITE, this_op)) - return code; - - /* Eliminate duplicates from IP address list */ - for (k=0, cnt=0; kbulkaddrs_len; k++) { - if (addrsp->bulkaddrs_val[k] == 0) - continue; - for (m=0; m < cnt; m++) { - if (addrs[m] == addrsp->bulkaddrs_val[k]) - break; - } - if (m == cnt) { - if (m == VL_MAXIPADDRS_PERMH) { - VLog(0, ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n", - VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k])); - } else { - addrs[m] = addrsp->bulkaddrs_val[k]; - cnt++; - } - } - } - if (cnt <= 0) { - ubik_AbortTrans(trans); - return VL_INDEXERANGE; - } - - count = 0; - willReplaceCnt = 0; - foundUuidEntry = 0; - /* For each server registered within the VLDB */ - for (srvidx=0; srvidx <= MAXSERVERID;srvidx++) { - willChangeEntry = 0; - WillReplaceEntry = 1; - if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) { - /* The server is registered as a multihomed */ - base = (HostAddress[srvidx] >> 16) & 0xff; - index = HostAddress[srvidx] & 0x0000ffff; - if (base >= VL_MAX_ADDREXTBLKS) { - VLog(0, ("Internal error: Multihome extent base is too large. Base %d index %d\n", - base, index)); - continue; - } - if (index >= VL_MHSRV_PERBLK) { - VLog(0, ("Internal error: Multihome extent index is too large. Base %d index %d\n", - base, index)); - continue; + afs_int32 code; + struct ubik_trans *trans; + int cnt, h, i, j, k, m, base, index; + struct extentaddr *exp = 0, *tex; + afsUUID tuuid; + afs_uint32 addrs[VL_MAXIPADDRS_PERMH]; + afs_int32 fbase; + int count, willChangeEntry, foundUuidEntry, willReplaceCnt; + int WillReplaceEntry, WillChange[MAXSERVERID + 1], FoundUuid, + ReplaceEntry; + int srvidx, mhidx; + + COUNT_REQ(VLREGADDR); + if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) + return (VL_PERM); + if (code = Init_VLdbase(&trans, LOCKWRITE, this_op)) + return code; + + /* Eliminate duplicates from IP address list */ + for (k = 0, cnt = 0; k < addrsp->bulkaddrs_len; k++) { + if (addrsp->bulkaddrs_val[k] == 0) + continue; + for (m = 0; m < cnt; m++) { + if (addrs[m] == addrsp->bulkaddrs_val[k]) + break; } - if (!ex_addr[base]) { - VLog(0, ("Internal error: Multihome extent does not exist. Base %d\n", base)); - continue; + if (m == cnt) { + if (m == VL_MAXIPADDRS_PERMH) { + VLog(0, + ("Number of addresses exceeds %d. Cannot register IP addr 0x%x in VLDB\n", + VL_MAXIPADDRS_PERMH, addrsp->bulkaddrs_val[k])); + } else { + addrs[m] = addrsp->bulkaddrs_val[k]; + cnt++; + } } + } + if (cnt <= 0) { + ubik_AbortTrans(trans); + return VL_INDEXERANGE; + } + + count = 0; + willReplaceCnt = 0; + foundUuidEntry = 0; + /* For each server registered within the VLDB */ + for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) { + willChangeEntry = 0; + WillReplaceEntry = 1; + if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) { + /* The server is registered as a multihomed */ + base = (HostAddress[srvidx] >> 16) & 0xff; + index = HostAddress[srvidx] & 0x0000ffff; + if (base >= VL_MAX_ADDREXTBLKS) { + VLog(0, + ("Internal error: Multihome extent base is too large. Base %d index %d\n", + base, index)); + continue; + } + if (index >= VL_MHSRV_PERBLK) { + VLog(0, + ("Internal error: Multihome extent index is too large. Base %d index %d\n", + base, index)); + continue; + } + if (!ex_addr[base]) { + VLog(0, + ("Internal error: Multihome extent does not exist. Base %d\n", + base)); + continue; + } - /* See if the addresses to register will change this server entry */ - exp = &ex_addr[base][index]; - tuuid = exp->ex_hostuuid; - afs_ntohuuid(&tuuid); - if (afs_uuid_equal(uuidp, &tuuid)) { - foundUuidEntry = 1; - FoundUuid = srvidx; + /* See if the addresses to register will change this server entry */ + exp = &ex_addr[base][index]; + tuuid = exp->ex_hostuuid; + afs_ntohuuid(&tuuid); + if (afs_uuid_equal(uuidp, &tuuid)) { + foundUuidEntry = 1; + FoundUuid = srvidx; + } else { + for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { + if (!exp->ex_addrs[mhidx]) + continue; + for (k = 0; k < cnt; k++) { + if (ntohl(exp->ex_addrs[mhidx]) == addrs[k]) { + willChangeEntry = 1; + WillChange[count] = srvidx; + break; + } + } + if (k >= cnt) + WillReplaceEntry = 0; + } + } } else { - for (mhidx=0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { - if (!exp->ex_addrs[mhidx]) continue; - for (k=0; kex_addrs[mhidx]) == addrs[k]) { + /* The server is not registered as a multihomed. + * See if the addresses to register will replace this server entry. + */ + for (k = 0; k < cnt; k++) { + if (HostAddress[srvidx] == addrs[k]) { willChangeEntry = 1; WillChange[count] = srvidx; + WillReplaceEntry = 1; break; - } - } - if (k >= cnt) WillReplaceEntry = 0; - } - } - } else { - /* The server is not registered as a multihomed. - * See if the addresses to register will replace this server entry. - */ - for (k=0; k 0)) || - (!foundUuidEntry && (count > 1)) ) { - VLog(0, ("The following fileserver is being registered in the VLDB:\n")); - printf(" ["); - for (k=0; k0) printf(" "); - PADDR(addrs[k]); - } - printf("]\n"); + } + } + } + if (willChangeEntry) { + if (WillReplaceEntry) { + willReplaceCnt++; + ReplaceEntry = srvidx; + } + count++; + } + } - if (foundUuidEntry) { - printf(" It would have replaced the existing VLDB server entry:\n"); - printf(" entry %d: [", FoundUuid); - base = (HostAddress[FoundUuid] >> 16) & 0xff; - index = HostAddress[FoundUuid] & 0x0000ffff; - exp = &ex_addr[base][index]; - for (mhidx=0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { - if (!exp->ex_addrs[mhidx]) continue; - if (mhidx > 0) printf(" "); - PADDR(ntohl(exp->ex_addrs[mhidx])); + /* If we found the uuid in the VLDB and if we are replacing another + * entire entry, then complain and fail. Also, if we did not find + * the uuid in the VLDB and the IP addresses being registered was + * found in more than one other entry, then we don't know which one + * to replace and will complain and fail. + */ + if ((foundUuidEntry && (willReplaceCnt > 0)) + || (!foundUuidEntry && (count > 1))) { + VLog(0, + ("The following fileserver is being registered in the VLDB:\n")); + printf(" ["); + for (k = 0; k < cnt; k++) { + if (k > 0) + printf(" "); + PADDR(addrs[k]); } printf("]\n"); - } - - if (count == 1) printf(" Yet another VLDB server entry exists:\n"); - else printf(" Yet other VLDB server entries exist:\n"); - for (j=0; j> 16) & 0xff; - index = HostAddress[srvidx] & 0x0000ffff; - exp = &ex_addr[base][index]; - for (mhidx=0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { - if (!exp->ex_addrs[mhidx]) continue; - if (mhidx > 0) printf(" "); - PADDR(ntohl(exp->ex_addrs[mhidx])); - } - printf("]"); - } else { - PADDR(HostAddress[srvidx]); - } - printf("\n"); - } - - if (count == 1) - printf(" You must 'vos changeaddr' this other server entry\n"); - else - printf(" You must 'vos changeaddr' these other server entries\n"); - if (foundUuidEntry) - printf(" and/or remove the sysid file from the registering fileserver\n"); - printf(" before the fileserver can be registered in the VLDB.\n"); - - ubik_AbortTrans(trans); - return VL_MULTIPADDR; - } - - /* Passed the checks. Now find and update the existing mh entry, or create - * a new mh entry. - */ - if (foundUuidEntry) { - /* Found the entry with same uuid. See if we need to change it */ - int change = 0; - - fbase = (HostAddress[FoundUuid] >> 16) & 0xff; - index = HostAddress[FoundUuid] & 0x0000ffff; - exp = &ex_addr[fbase][index]; - - /* Determine if the entry has changed */ - for (k=0; ((k < cnt) && !change); k++) { - if (ntohl(exp->ex_addrs[k]) != addrs[k]) - change = 1; - } - for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) { - if (exp->ex_addrs[k] != 0) - change = 1; - } - if (!change) { - return(ubik_EndTrans(trans)); - } - } - - VLog(0, ("The following fileserver is being registered in the VLDB:\n")); - printf(" ["); - for (k=0; k0) printf(" "); - PADDR(addrs[k]); - } - printf("]\n"); - - if (foundUuidEntry) { - printf(" It will replace the following existing entry in the VLDB (same uuid):\n"); - printf(" entry %d: [", FoundUuid); - for (k=0; k < VL_MAXIPADDRS_PERMH; k++) { - if (exp->ex_addrs[k] == 0) continue; - if (k>0) printf(" "); - PADDR(ntohl(exp->ex_addrs[k])); - } - printf("]\n"); - } - else if (willReplaceCnt || (count == 1)) { - /* If we are not replacing an entry and there is only one entry to change, - * then we will replace that entry. - */ - if (!willReplaceCnt) { - ReplaceEntry = WillChange[0]; - willReplaceCnt++; - } - - /* Have an entry that needs to be replaced */ - if ((HostAddress[ReplaceEntry] & 0xff000000) == 0xff000000) { - fbase = (HostAddress[ReplaceEntry] >> 16) & 0xff; - index = HostAddress[ReplaceEntry] & 0x0000ffff; + + if (foundUuidEntry) { + printf + (" It would have replaced the existing VLDB server entry:\n"); + printf(" entry %d: [", FoundUuid); + base = (HostAddress[FoundUuid] >> 16) & 0xff; + index = HostAddress[FoundUuid] & 0x0000ffff; + exp = &ex_addr[base][index]; + for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { + if (!exp->ex_addrs[mhidx]) + continue; + if (mhidx > 0) + printf(" "); + PADDR(ntohl(exp->ex_addrs[mhidx])); + } + printf("]\n"); + } + + if (count == 1) + printf(" Yet another VLDB server entry exists:\n"); + else + printf(" Yet other VLDB server entries exist:\n"); + for (j = 0; j < count; j++) { + srvidx = WillChange[j]; + printf(" entry %d: ", srvidx); + if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) { + printf("["); + base = (HostAddress[srvidx] >> 16) & 0xff; + index = HostAddress[srvidx] & 0x0000ffff; + exp = &ex_addr[base][index]; + for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { + if (!exp->ex_addrs[mhidx]) + continue; + if (mhidx > 0) + printf(" "); + PADDR(ntohl(exp->ex_addrs[mhidx])); + } + printf("]"); + } else { + PADDR(HostAddress[srvidx]); + } + printf("\n"); + } + + if (count == 1) + printf(" You must 'vos changeaddr' this other server entry\n"); + else + printf + (" You must 'vos changeaddr' these other server entries\n"); + if (foundUuidEntry) + printf + (" and/or remove the sysid file from the registering fileserver\n"); + printf(" before the fileserver can be registered in the VLDB.\n"); + + ubik_AbortTrans(trans); + return VL_MULTIPADDR; + } + + /* Passed the checks. Now find and update the existing mh entry, or create + * a new mh entry. + */ + if (foundUuidEntry) { + /* Found the entry with same uuid. See if we need to change it */ + int change = 0; + + fbase = (HostAddress[FoundUuid] >> 16) & 0xff; + index = HostAddress[FoundUuid] & 0x0000ffff; exp = &ex_addr[fbase][index]; - printf(" It will replace the following existing entry in the VLDB (new uuid):\n"); - printf(" entry %d: [", ReplaceEntry); - for (k=0; k < VL_MAXIPADDRS_PERMH; k++) { - if (exp->ex_addrs[k] == 0) continue; - if (k>0) printf(" "); - PADDR(ntohl(exp->ex_addrs[k])); + /* Determine if the entry has changed */ + for (k = 0; ((k < cnt) && !change); k++) { + if (ntohl(exp->ex_addrs[k]) != addrs[k]) + change = 1; + } + for (; ((k < VL_MAXIPADDRS_PERMH) && !change); k++) { + if (exp->ex_addrs[k] != 0) + change = 1; + } + if (!change) { + return (ubik_EndTrans(trans)); + } + } + + VLog(0, ("The following fileserver is being registered in the VLDB:\n")); + printf(" ["); + for (k = 0; k < cnt; k++) { + if (k > 0) + printf(" "); + PADDR(addrs[k]); + } + printf("]\n"); + + if (foundUuidEntry) { + printf + (" It will replace the following existing entry in the VLDB (same uuid):\n"); + printf(" entry %d: [", FoundUuid); + for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) { + if (exp->ex_addrs[k] == 0) + continue; + if (k > 0) + printf(" "); + PADDR(ntohl(exp->ex_addrs[k])); } printf("]\n"); - } else { - /* Not a mh entry. So we have to create a new mh entry and - * put it on the ReplaceEntry slot of the HostAddress array. + } else if (willReplaceCnt || (count == 1)) { + /* If we are not replacing an entry and there is only one entry to change, + * then we will replace that entry. */ - printf(" It will replace existing entry %d, ", ReplaceEntry); - PADDR(HostAddress[ReplaceEntry]); - printf(", in the VLDB (new uuid):\n"); + if (!willReplaceCnt) { + ReplaceEntry = WillChange[0]; + willReplaceCnt++; + } - code = FindExtentBlock(trans, uuidp, 1, ReplaceEntry, &exp, &fbase); + /* Have an entry that needs to be replaced */ + if ((HostAddress[ReplaceEntry] & 0xff000000) == 0xff000000) { + fbase = (HostAddress[ReplaceEntry] >> 16) & 0xff; + index = HostAddress[ReplaceEntry] & 0x0000ffff; + exp = &ex_addr[fbase][index]; + + printf + (" It will replace the following existing entry in the VLDB (new uuid):\n"); + printf(" entry %d: [", ReplaceEntry); + for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) { + if (exp->ex_addrs[k] == 0) + continue; + if (k > 0) + printf(" "); + PADDR(ntohl(exp->ex_addrs[k])); + } + printf("]\n"); + } else { + /* Not a mh entry. So we have to create a new mh entry and + * put it on the ReplaceEntry slot of the HostAddress array. + */ + printf(" It will replace existing entry %d, ", ReplaceEntry); + PADDR(HostAddress[ReplaceEntry]); + printf(", in the VLDB (new uuid):\n"); + + code = + FindExtentBlock(trans, uuidp, 1, ReplaceEntry, &exp, &fbase); + if (code || !exp) { + ubik_AbortTrans(trans); + return (code ? code : VL_IO); + } + } + } else { + /* There is no entry for this server, must create a new mh entry as + * well as use a new slot of the HostAddress array. + */ + printf(" It will create a new entry in the VLDB.\n"); + code = FindExtentBlock(trans, uuidp, 1, -1, &exp, &fbase); if (code || !exp) { - ubik_AbortTrans(trans); - return (code ? code : VL_IO); - } - } - } else { - /* There is no entry for this server, must create a new mh entry as - * well as use a new slot of the HostAddress array. - */ - printf(" It will create a new entry in the VLDB.\n"); - code = FindExtentBlock(trans, uuidp, 1, -1, &exp, &fbase); - if (code || !exp) { - ubik_AbortTrans(trans); - return (code ? code : VL_IO); - } - } - - /* Now we have a mh entry to fill in. Update the uuid, bump the - * uniquifier, and fill in its IP addresses. - */ - tuuid = *uuidp; - afs_htonuuid(&tuuid); - exp->ex_hostuuid = tuuid; - exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier)+1); - for (k=0; k < cnt; k++) { - exp->ex_addrs[k] = htonl(addrs[k]); - } - for (; k < VL_MAXIPADDRS_PERMH; k++) { - exp->ex_addrs[k] = 0; - } - - /* Write the new mh entry out */ - if (vlwrite(trans, DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[fbase]), - (char *)ex_addr[fbase], (char *)exp), - (char *)exp, sizeof(*exp))) { - ubik_AbortTrans(trans); - return VL_IO; - } - - /* Remove any common addresses from other mh entres. We know these entries - * are being changed and not replaced so they are mh entries. - */ - m = 0; - for (i=0; i> 16) & 0xff; - index = HostAddress[WillChange[i]] & 0x0000ffff; - tex = &ex_addr[fbase][index]; - - if (++m == 1) - printf(" The following existing entries in the VLDB will be updated:\n"); - - printf(" entry %d: [", WillChange[i]); - for (h=j=0; j < VL_MAXIPADDRS_PERMH; j++) { - if (tex->ex_addrs[j]) { - if (j>0) printf(" "); - PADDR(ntohl(tex->ex_addrs[j])); - } - - for (k=0; kex_addrs[j]) == addrs[k]) break; - } - if (k >= cnt) { - /* Not found, so we keep it */ - tex->ex_addrs[h] = tex->ex_addrs[j]; - h++; - } - } - for (j=h; j < VL_MAXIPADDRS_PERMH; j++) { - tex->ex_addrs[j] = 0; /* zero rest of mh entry */ - } - printf("]\n"); - - /* Write out the modified mh entry */ - tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier)+1); - doff=DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), - (char *)ex_addr[base], (char *)tex); - if (vlwrite(trans, doff, (char*)tex, sizeof(*tex))) { - ubik_AbortTrans(trans); + ubik_AbortTrans(trans); + return (code ? code : VL_IO); + } + } + + /* Now we have a mh entry to fill in. Update the uuid, bump the + * uniquifier, and fill in its IP addresses. + */ + tuuid = *uuidp; + afs_htonuuid(&tuuid); + exp->ex_hostuuid = tuuid; + exp->ex_uniquifier = htonl(ntohl(exp->ex_uniquifier) + 1); + for (k = 0; k < cnt; k++) { + exp->ex_addrs[k] = htonl(addrs[k]); + } + for (; k < VL_MAXIPADDRS_PERMH; k++) { + exp->ex_addrs[k] = 0; + } + + /* Write the new mh entry out */ + if (vlwrite + (trans, + DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[fbase]), + (char *)ex_addr[fbase], (char *)exp), (char *)exp, + sizeof(*exp))) { + ubik_AbortTrans(trans); return VL_IO; - } - } + } + + /* Remove any common addresses from other mh entres. We know these entries + * are being changed and not replaced so they are mh entries. + */ + m = 0; + for (i = 0; i < count; i++) { + afs_int32 doff; + + /* Skip the entry we replaced */ + if (willReplaceCnt && (WillChange[i] == ReplaceEntry)) + continue; + + base = (HostAddress[WillChange[i]] >> 16) & 0xff; + index = HostAddress[WillChange[i]] & 0x0000ffff; + tex = &ex_addr[fbase][index]; + + if (++m == 1) + printf + (" The following existing entries in the VLDB will be updated:\n"); + + printf(" entry %d: [", WillChange[i]); + for (h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) { + if (tex->ex_addrs[j]) { + if (j > 0) + printf(" "); + PADDR(ntohl(tex->ex_addrs[j])); + } + + for (k = 0; k < cnt; k++) { + if (ntohl(tex->ex_addrs[j]) == addrs[k]) + break; + } + if (k >= cnt) { + /* Not found, so we keep it */ + tex->ex_addrs[h] = tex->ex_addrs[j]; + h++; + } + } + for (j = h; j < VL_MAXIPADDRS_PERMH; j++) { + tex->ex_addrs[j] = 0; /* zero rest of mh entry */ + } + printf("]\n"); + + /* Write out the modified mh entry */ + tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1); + doff = + DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), + (char *)ex_addr[base], (char *)tex); + if (vlwrite(trans, doff, (char *)tex, sizeof(*tex))) { + ubik_AbortTrans(trans); + return VL_IO; + } + } - return(ubik_EndTrans(trans)); + return (ubik_EndTrans(trans)); } +afs_int32 SVL_GetAddrsU(rxcall, attributes, uuidpo, uniquifier, nentries, addrsp) -struct rx_call *rxcall; -struct ListAddrByAttributes *attributes; -afsUUID *uuidpo; -afs_int32 *uniquifier, *nentries; -bulkaddrs *addrsp; -{ register afs_int32 errorcode, index=-1, offset; - struct ubik_trans *trans; - int nservers, i, j, base=0; - struct extentaddr *exp=0; + struct rx_call *rxcall; + struct ListAddrByAttributes *attributes; + afsUUID *uuidpo; + afs_int32 *uniquifier, *nentries; + bulkaddrs *addrsp; +{ + register afs_int32 errorcode, index = -1, offset; + struct ubik_trans *trans; + int nservers, i, j, base = 0; + struct extentaddr *exp = 0; afsUUID tuuid; afs_uint32 *taddrp, taddr; @@ -2114,7 +2354,7 @@ bulkaddrs *addrsp; return errorcode; if (attributes->Mask & VLADDR_IPADDR) { - if (attributes->Mask & (VLADDR_INDEX|VLADDR_UUID)) { + if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) { ubik_AbortTrans(trans); return VL_BADMASK; } @@ -2125,27 +2365,31 @@ bulkaddrs *addrsp; exp = &ex_addr[base][i]; tuuid = exp->ex_hostuuid; afs_ntohuuid(&tuuid); - if (afs_uuid_is_nil(&tuuid)) continue; + if (afs_uuid_is_nil(&tuuid)) + continue; for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) { - if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) { + if (exp->ex_addrs[j] + && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) { break; } } - if (j < VL_MAXIPADDRS_PERMH) break; + if (j < VL_MAXIPADDRS_PERMH) + break; } - if (i < VL_MHSRV_PERBLK) break; + if (i < VL_MHSRV_PERBLK) + break; } if (base >= VL_MAX_ADDREXTBLKS) { ubik_AbortTrans(trans); return VL_NOENT; } } else if (attributes->Mask & VLADDR_INDEX) { - if (attributes->Mask & (VLADDR_IPADDR|VLADDR_UUID)) { + if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) { ubik_AbortTrans(trans); return VL_BADMASK; } index = attributes->index; - if (index < 1 || index >= (VL_MAX_ADDREXTBLKS*VL_MHSRV_PERBLK)) { + if (index < 1 || index >= (VL_MAX_ADDREXTBLKS * VL_MHSRV_PERBLK)) { ubik_AbortTrans(trans); return VL_INDEXERANGE; } @@ -2161,7 +2405,7 @@ bulkaddrs *addrsp; } exp = &ex_addr[base][offset]; } else if (attributes->Mask & VLADDR_UUID) { - if (attributes->Mask & (VLADDR_IPADDR|VLADDR_INDEX)) { + if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) { ubik_AbortTrans(trans); return VL_BADMASK; } @@ -2169,21 +2413,23 @@ bulkaddrs *addrsp; ubik_AbortTrans(trans); return VL_NOENT; } - if (errorcode = FindExtentBlock(trans, &attributes->uuid, 0, -1, &exp, &base)) { + if (errorcode = + FindExtentBlock(trans, &attributes->uuid, 0, -1, &exp, &base)) { ubik_AbortTrans(trans); return errorcode; } } else { - ubik_AbortTrans(trans); + ubik_AbortTrans(trans); return VL_BADMASK; } - if (exp == (struct extentaddr *)0) { + if (exp == NULL) { ubik_AbortTrans(trans); return VL_NOENT; } - addrsp->bulkaddrs_val = taddrp = (afs_uint32 *)malloc(sizeof(afs_int32)*(MAXSERVERID+1)); - nservers= *nentries = addrsp->bulkaddrs_len = 0; + addrsp->bulkaddrs_val = taddrp = + (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1)); + nservers = *nentries = addrsp->bulkaddrs_len = 0; if (!taddrp) { COUNT_ABO; ubik_AbortTrans(trans); @@ -2195,24 +2441,26 @@ bulkaddrs *addrsp; ubik_AbortTrans(trans); return VL_NOENT; } - if (uuidpo) *uuidpo = tuuid; - if (uniquifier) *uniquifier = ntohl(exp->ex_uniquifier); + if (uuidpo) + *uuidpo = tuuid; + if (uniquifier) + *uniquifier = ntohl(exp->ex_uniquifier); for (i = 0; i < VL_MAXIPADDRS_PERMH; i++) { - if (exp->ex_addrs[i]) { - taddr = ntohl(exp->ex_addrs[i]); - /* Weed out duplicates */ - for (j = 0; j < nservers; j++) { - if (taddrp[j] == taddr) - break; - } - if ((j == nservers) && (j <= MAXSERVERID)) { - taddrp[nservers] = taddr; - nservers++; - } - } + if (exp->ex_addrs[i]) { + taddr = ntohl(exp->ex_addrs[i]); + /* Weed out duplicates */ + for (j = 0; j < nservers; j++) { + if (taddrp[j] == taddr) + break; + } + if ((j == nservers) && (j <= MAXSERVERID)) { + taddrp[nservers] = taddr; + nservers++; + } + } } addrsp->bulkaddrs_len = *nentries = nservers; - return(ubik_EndTrans(trans)); + return (ubik_EndTrans(trans)); } /* ============> End of Exported vldb RPC functions <============= */ @@ -2220,25 +2468,30 @@ bulkaddrs *addrsp; /* Routine that copies the given vldb entry to the output buffer, vldbentries. */ static int -put_attributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries, entry, nentries, alloccnt) -struct vldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast; -bulkentries *vldbentries; -struct nvlentry *entry; -afs_int32 *nentries, *alloccnt; +put_attributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries, + entry, nentries, alloccnt) + struct vldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast; + bulkentries *vldbentries; + struct nvlentry *entry; + afs_int32 *nentries, *alloccnt; { vldbentry *reall; afs_int32 allo; if (*Vldbentry == *VldbentryLast) { - if (smallMem) return VL_SIZEEXCEEDED; /* no growing if smallMem defined */ + if (smallMem) + return VL_SIZEEXCEEDED; /* no growing if smallMem defined */ /* Allocate another set of memory; each time allocate twice as * many blocks as the last time. When we reach VLDBALLOCLIMIT, * then grow in increments of VLDBALLOCINCR. */ - allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt; - reall = (vldbentry *) realloc(*VldbentryFirst, (*alloccnt+allo)*sizeof(vldbentry)); - if (reall == NULL) return VL_NOMEM; + allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt; + reall = + (vldbentry *) realloc(*VldbentryFirst, + (*alloccnt + allo) * sizeof(vldbentry)); + if (reall == NULL) + return VL_NOMEM; *VldbentryFirst = vldbentries->bulkentries_val = reall; *Vldbentry = *VldbentryFirst + *alloccnt; @@ -2253,26 +2506,30 @@ afs_int32 *nentries, *alloccnt; } static int -put_nattributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries, entry, - matchtype, matchindex, nentries, alloccnt) -struct nvldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast; -nbulkentries *vldbentries; -struct nvlentry *entry; -afs_int32 matchtype, matchindex, *nentries, *alloccnt; +put_nattributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries, + entry, matchtype, matchindex, nentries, alloccnt) + struct nvldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast; + nbulkentries *vldbentries; + struct nvlentry *entry; + afs_int32 matchtype, matchindex, *nentries, *alloccnt; { nvldbentry *reall; afs_int32 allo; if (*Vldbentry == *VldbentryLast) { - if (smallMem) return VL_SIZEEXCEEDED; /* no growing if smallMem defined */ + if (smallMem) + return VL_SIZEEXCEEDED; /* no growing if smallMem defined */ /* Allocate another set of memory; each time allocate twice as * many blocks as the last time. When we reach VLDBALLOCLIMIT, * then grow in increments of VLDBALLOCINCR. */ - allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt; - reall = (nvldbentry *)realloc(*VldbentryFirst, (*alloccnt+allo)*sizeof(nvldbentry)); - if (reall == NULL) return VL_NOMEM; + allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt; + reall = + (nvldbentry *) realloc(*VldbentryFirst, + (*alloccnt + allo) * sizeof(nvldbentry)); + if (reall == NULL) + return VL_NOMEM; *VldbentryFirst = vldbentries->nbulkentries_val = reall; *Vldbentry = *VldbentryFirst + *alloccnt; @@ -2280,7 +2537,7 @@ afs_int32 matchtype, matchindex, *nentries, *alloccnt; *alloccnt += allo; } vlentry_to_nvldbentry(entry, *Vldbentry); - (*Vldbentry)->matchindex = (matchtype << 16) + matchindex; + (*Vldbentry)->matchindex = (matchtype << 16) + matchindex; (*Vldbentry)++; (*nentries)++; vldbentries->nbulkentries_len++; @@ -2291,11 +2548,11 @@ afs_int32 matchtype, matchindex, *nentries, *alloccnt; /* Common code to actually remove a vldb entry from the database. */ static int RemoveEntry(trans, entryptr, tentry) -struct ubik_trans *trans; -afs_int32 entryptr; -struct nvlentry *tentry; + struct ubik_trans *trans; + afs_int32 entryptr; + struct nvlentry *tentry; { - register int errorcode; + register int errorcode; if (errorcode = UnthreadVLentry(trans, entryptr, tentry)) return errorcode; @@ -2306,8 +2563,8 @@ struct nvlentry *tentry; static ReleaseEntry(tentry, releasetype) -struct nvlentry *tentry; -afs_int32 releasetype; + struct nvlentry *tentry; + afs_int32 releasetype; { if (releasetype & LOCKREL_TIMESTAMP) tentry->LockTimestamp = 0; @@ -2319,43 +2576,47 @@ afs_int32 releasetype; /* Verify that the incoming vldb entry is valid; multi type of error codes are returned. */ -static int +static int check_vldbentry(aentry) -struct vldbentry *aentry; + struct vldbentry *aentry; { - afs_int32 i; + afs_int32 i; if (InvalidVolname(aentry->name)) return VL_BADNAME; if (aentry->nServers <= 0 || aentry->nServers > OMAXNSERVERS) return VL_BADSERVER; - for (i=0; i < aentry->nServers; i++) { + for (i = 0; i < aentry->nServers; i++) { /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID) return VL_BADSERVER; */ - if (aentry->serverPartition[i] < 0 || aentry->serverPartition[i] > MAXPARTITIONID) + if (aentry->serverPartition[i] < 0 + || aentry->serverPartition[i] > MAXPARTITIONID) return VL_BADPARTITION; - if (aentry->serverFlags[i] < 0 || aentry->serverFlags[i] > MAXSERVERFLAG) + if (aentry->serverFlags[i] < 0 + || aentry->serverFlags[i] > MAXSERVERFLAG) return VL_BADSERVERFLAG; } return 0; } -static int +static int check_nvldbentry(aentry) -struct nvldbentry *aentry; + struct nvldbentry *aentry; { - afs_int32 i; + afs_int32 i; if (InvalidVolname(aentry->name)) return VL_BADNAME; if (aentry->nServers <= 0 || aentry->nServers > NMAXNSERVERS) return VL_BADSERVER; - for (i=0; i < aentry->nServers; i++) { + for (i = 0; i < aentry->nServers; i++) { /* if (aentry->serverNumber[i] < 0 || aentry->serverNumber[i] > MAXSERVERID) return VL_BADSERVER; */ - if (aentry->serverPartition[i] < 0 || aentry->serverPartition[i] > MAXPARTITIONID) + if (aentry->serverPartition[i] < 0 + || aentry->serverPartition[i] > MAXPARTITIONID) return VL_BADPARTITION; - if (aentry->serverFlags[i] < 0 || aentry->serverFlags[i] > MAXSERVERFLAG) + if (aentry->serverFlags[i] < 0 + || aentry->serverFlags[i] > MAXSERVERFLAG) return VL_BADSERVERFLAG; } return 0; @@ -2366,24 +2627,26 @@ struct nvldbentry *aentry; (more compact) form. This call should not change the hash chains! */ static int vldbentry_to_vlentry(atrans, VldbEntry, VlEntry) -struct ubik_trans *atrans; -struct vldbentry *VldbEntry; -struct nvlentry *VlEntry; + struct ubik_trans *atrans; + struct vldbentry *VldbEntry; + struct nvlentry *VlEntry; { int i, serverindex; - if (strcmp(VlEntry->name, VldbEntry->name)) + if (strcmp(VlEntry->name, VldbEntry->name)) strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name)); - for (i=0; inServers; i++) { + for (i = 0; i < VldbEntry->nServers; i++) { serverindex = IpAddrToRelAddr(VldbEntry->serverNumber[i], atrans); - if (serverindex == -1) return VL_BADSERVER; + if (serverindex == -1) + return VL_BADSERVER; VlEntry->serverNumber[i] = serverindex; VlEntry->serverPartition[i] = VldbEntry->serverPartition[i]; VlEntry->serverFlags[i] = VldbEntry->serverFlags[i]; } - for (;i < OMAXNSERVERS; i++) - VlEntry->serverNumber[i] = VlEntry->serverPartition[i] = VlEntry->serverFlags[i] = BADSERVERID; - for (i=0; i < MAXTYPES; i++) + for (; i < OMAXNSERVERS; i++) + VlEntry->serverNumber[i] = VlEntry->serverPartition[i] = + VlEntry->serverFlags[i] = BADSERVERID; + for (i = 0; i < MAXTYPES; i++) VlEntry->volumeId[i] = VldbEntry->volumeId[i]; VlEntry->cloneId = VldbEntry->cloneId; VlEntry->flags = VldbEntry->flags; @@ -2392,24 +2655,26 @@ struct nvlentry *VlEntry; static int nvldbentry_to_vlentry(atrans, VldbEntry, VlEntry) -struct ubik_trans *atrans; -struct nvldbentry *VldbEntry; -struct nvlentry *VlEntry; + struct ubik_trans *atrans; + struct nvldbentry *VldbEntry; + struct nvlentry *VlEntry; { int i, serverindex; - if (strcmp(VlEntry->name, VldbEntry->name)) + if (strcmp(VlEntry->name, VldbEntry->name)) strncpy(VlEntry->name, VldbEntry->name, sizeof(VlEntry->name)); - for (i=0; inServers; i++) { + for (i = 0; i < VldbEntry->nServers; i++) { serverindex = IpAddrToRelAddr(VldbEntry->serverNumber[i], atrans); - if (serverindex == -1) return VL_BADSERVER; + if (serverindex == -1) + return VL_BADSERVER; VlEntry->serverNumber[i] = serverindex; VlEntry->serverPartition[i] = VldbEntry->serverPartition[i]; VlEntry->serverFlags[i] = VldbEntry->serverFlags[i]; } - for (;i < NMAXNSERVERS; i++) - VlEntry->serverNumber[i] = VlEntry->serverPartition[i] = VlEntry->serverFlags[i] = BADSERVERID; - for (i=0; i < MAXTYPES; i++) + for (; i < NMAXNSERVERS; i++) + VlEntry->serverNumber[i] = VlEntry->serverPartition[i] = + VlEntry->serverFlags[i] = BADSERVERID; + for (i = 0; i < MAXTYPES; i++) VlEntry->volumeId[i] = VldbEntry->volumeId[i]; VlEntry->cloneId = VldbEntry->cloneId; VlEntry->flags = VldbEntry->flags; @@ -2420,10 +2685,10 @@ struct nvlentry *VlEntry; /* Update the vldb entry with the new fields as indicated by the value of the Mask entry in the updateentry structure. All necessary validation checks are performed. */ static get_vldbupdateentry(trans, blockindex, updateentry, VlEntry) -struct ubik_trans *trans; -afs_int32 blockindex; -struct VldbUpdateEntry *updateentry; -struct nvlentry *VlEntry; + struct ubik_trans *trans; + afs_int32 blockindex; + struct VldbUpdateEntry *updateentry; + struct nvlentry *VlEntry; { int i, j, errorcode, serverindex; @@ -2478,73 +2743,121 @@ struct nvlentry *VlEntry; return errorcode; } if (updateentry->Mask & VLUPDATE_REPSITES) { - if (updateentry->nModifiedRepsites <= 0 || updateentry->nModifiedRepsites > OMAXNSERVERS) - return VL_BADSERVER; - for (i=0; i < updateentry->nModifiedRepsites; i++) { + if (updateentry->nModifiedRepsites <= 0 + || updateentry->nModifiedRepsites > OMAXNSERVERS) + return VL_BADSERVER; + for (i = 0; i < updateentry->nModifiedRepsites; i++) { /* if (updateentry->RepsitesTargetServer[i] < 0 || updateentry->RepsitesTargetServer[i] > MAXSERVERID) return VL_BADSERVER; */ - if (updateentry->RepsitesTargetPart[i] < 0 || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID) + if (updateentry->RepsitesTargetPart[i] < 0 + || updateentry->RepsitesTargetPart[i] > MAXPARTITIONID) return VL_BADPARTITION; if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_DELETE) { - if ((j = repsite_exists(VlEntry, IpAddrToRelAddr(updateentry->RepsitesTargetServer[i], trans), updateentry->RepsitesTargetPart[i])) != -1) + if ((j = + repsite_exists(VlEntry, + IpAddrToRelAddr(updateentry-> + RepsitesTargetServer[i], + trans), + updateentry->RepsitesTargetPart[i])) != + -1) repsite_compress(VlEntry, j); - else return VL_NOREPSERVER; + else + return VL_NOREPSERVER; } if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_ADD) { /* if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID) return VL_BADSERVER; */ - if (updateentry->RepsitesNewPart[i] < 0 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID) + if (updateentry->RepsitesNewPart[i] < 0 + || updateentry->RepsitesNewPart[i] > MAXPARTITIONID) return VL_BADPARTITION; - if (repsite_exists(VlEntry, IpAddrToRelAddr(updateentry->RepsitesNewServer[i], trans), updateentry->RepsitesNewPart[i]) != -1) + if (repsite_exists + (VlEntry, + IpAddrToRelAddr(updateentry->RepsitesNewServer[i], + trans), + updateentry->RepsitesNewPart[i]) != -1) return VL_DUPREPSERVER; - for (j=0; VlEntry->serverNumber[j] != BADSERVERID && j < OMAXNSERVERS; j++); - if (j >= OMAXNSERVERS) return VL_REPSFULL; - if ((serverindex = IpAddrToRelAddr(updateentry->RepsitesNewServer[i], trans)) == -1) + for (j = 0; + VlEntry->serverNumber[j] != BADSERVERID + && j < OMAXNSERVERS; j++); + if (j >= OMAXNSERVERS) + return VL_REPSFULL; + if ((serverindex = + IpAddrToRelAddr(updateentry->RepsitesNewServer[i], + trans)) == -1) return VL_BADSERVER; VlEntry->serverNumber[j] = serverindex; VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i]; - if (updateentry->RepsitesNewFlags[i] < 0 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG) + if (updateentry->RepsitesNewFlags[i] < 0 + || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG) return VL_BADSERVERFLAG; - VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i]; + VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i]; } if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV) { /*n if (updateentry->RepsitesNewServer[i] < 0 || updateentry->RepsitesNewServer[i] > MAXSERVERID) return VL_BADSERVER; */ - if ((j = repsite_exists(VlEntry, IpAddrToRelAddr(updateentry->RepsitesTargetServer[i], trans), updateentry->RepsitesTargetPart[i])) != -1) { - VlEntry->serverNumber[j] = IpAddrToRelAddr(updateentry->RepsitesNewServer[i], trans); - } - else return VL_NOREPSERVER; + if ((j = + repsite_exists(VlEntry, + IpAddrToRelAddr(updateentry-> + RepsitesTargetServer[i], + trans), + updateentry->RepsitesTargetPart[i])) != + -1) { + VlEntry->serverNumber[j] = + IpAddrToRelAddr(updateentry->RepsitesNewServer[i], + trans); + } else + return VL_NOREPSERVER; } if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODPART) { - if (updateentry->RepsitesNewPart[i] < 0 || updateentry->RepsitesNewPart[i] > MAXPARTITIONID) + if (updateentry->RepsitesNewPart[i] < 0 + || updateentry->RepsitesNewPart[i] > MAXPARTITIONID) return VL_BADPARTITION; - if ((j = repsite_exists(VlEntry, IpAddrToRelAddr(updateentry->RepsitesTargetServer[i], trans), updateentry->RepsitesTargetPart[i])) != -1) - VlEntry->serverPartition[j] = updateentry->RepsitesNewPart[i]; - else return VL_NOREPSERVER; + if ((j = + repsite_exists(VlEntry, + IpAddrToRelAddr(updateentry-> + RepsitesTargetServer[i], + trans), + updateentry->RepsitesTargetPart[i])) != + -1) + VlEntry->serverPartition[j] = + updateentry->RepsitesNewPart[i]; + else + return VL_NOREPSERVER; } if (updateentry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG) { - if ((j = repsite_exists(VlEntry, IpAddrToRelAddr(updateentry->RepsitesTargetServer[i], trans), updateentry->RepsitesTargetPart[i])) != -1) { - if (updateentry->RepsitesNewFlags[i] < 0 || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG) + if ((j = + repsite_exists(VlEntry, + IpAddrToRelAddr(updateentry-> + RepsitesTargetServer[i], + trans), + updateentry->RepsitesTargetPart[i])) != + -1) { + if (updateentry->RepsitesNewFlags[i] < 0 + || updateentry->RepsitesNewFlags[i] > MAXSERVERFLAG) return VL_BADSERVERFLAG; - VlEntry->serverFlags[j] = updateentry->RepsitesNewFlags[i]; - } else return VL_NOREPSERVER; + VlEntry->serverFlags[j] = + updateentry->RepsitesNewFlags[i]; + } else + return VL_NOREPSERVER; } } } return 0; } - + /* Check if the specified [server,partition] entry is found in the vldb entry's repsite table; it's offset in the table is returned, if it's present there. */ static int repsite_exists(VlEntry, server, partition) -struct nvlentry *VlEntry; -int server, partition; + struct nvlentry *VlEntry; + int server, partition; { int i; - for (i=0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS; i++) { - if ((VlEntry->serverNumber[i] == server) && (VlEntry->serverPartition[i] == partition)) + for (i = 0; VlEntry->serverNumber[i] != BADSERVERID && i < OMAXNSERVERS; + i++) { + if ((VlEntry->serverNumber[i] == server) + && (VlEntry->serverPartition[i] == partition)) return i; } return -1; @@ -2555,14 +2868,19 @@ int server, partition; /* Repsite table compression: used when deleting a repsite entry so that all active repsite entries are on the top of the table. */ static repsite_compress(VlEntry, offset) -struct nvlentry *VlEntry; -int offset; + struct nvlentry *VlEntry; + int offset; { int repsite_offset = offset; - for (; VlEntry->serverNumber[repsite_offset] != BADSERVERID && repsite_offset < OMAXNSERVERS-1; repsite_offset++) { - VlEntry->serverNumber[repsite_offset] = VlEntry->serverNumber[repsite_offset+1]; - VlEntry->serverPartition[repsite_offset] = VlEntry->serverPartition[repsite_offset+1]; - VlEntry->serverFlags[repsite_offset] = VlEntry->serverFlags[repsite_offset+1]; + for (; + VlEntry->serverNumber[repsite_offset] != BADSERVERID + && repsite_offset < OMAXNSERVERS - 1; repsite_offset++) { + VlEntry->serverNumber[repsite_offset] = + VlEntry->serverNumber[repsite_offset + 1]; + VlEntry->serverPartition[repsite_offset] = + VlEntry->serverPartition[repsite_offset + 1]; + VlEntry->serverFlags[repsite_offset] = + VlEntry->serverFlags[repsite_offset + 1]; } VlEntry->serverNumber[repsite_offset] = BADSERVERID; } @@ -2571,16 +2889,18 @@ int offset; /* Convert from the internal (compacted) vldb entry to the external representation used by the interface. */ static vlentry_to_vldbentry(VlEntry, VldbEntry) -struct nvlentry *VlEntry; -struct vldbentry *VldbEntry; + struct nvlentry *VlEntry; + struct vldbentry *VldbEntry; { int i, j; - + memset(VldbEntry, 0, sizeof(struct vldbentry)); strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name)); - for (i=0; i < OMAXNSERVERS; i++) { - if (VlEntry->serverNumber[i] == BADSERVERID) break; - if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == 0xff000000) { + for (i = 0; i < OMAXNSERVERS; i++) { + if (VlEntry->serverNumber[i] == BADSERVERID) + break; + if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == + 0xff000000) { struct extentaddr *exp; int base, index; @@ -2595,12 +2915,13 @@ struct vldbentry *VldbEntry; } } } else - VldbEntry->serverNumber[i] = HostAddress[VlEntry->serverNumber[i]]; + VldbEntry->serverNumber[i] = + HostAddress[VlEntry->serverNumber[i]]; VldbEntry->serverPartition[i] = VlEntry->serverPartition[i]; VldbEntry->serverFlags[i] = VlEntry->serverFlags[i]; } VldbEntry->nServers = i; - for (i=0; ivolumeId[i] = VlEntry->volumeId[i]; VldbEntry->cloneId = VlEntry->cloneId; VldbEntry->flags = VlEntry->flags; @@ -2608,17 +2929,20 @@ struct vldbentry *VldbEntry; /* Convert from the internal (compacted) vldb entry to the external representation used by the interface. */ -static vlentry_to_nvldbentry(VlEntry, VldbEntry) -struct nvlentry *VlEntry; -struct nvldbentry *VldbEntry; +static +vlentry_to_nvldbentry(VlEntry, VldbEntry) + struct nvlentry *VlEntry; + struct nvldbentry *VldbEntry; { int i, j; - + memset(VldbEntry, 0, sizeof(struct vldbentry)); strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name)); - for (i=0; i < NMAXNSERVERS; i++) { - if (VlEntry->serverNumber[i] == BADSERVERID) break; - if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == 0xff000000) { + for (i = 0; i < NMAXNSERVERS; i++) { + if (VlEntry->serverNumber[i] == BADSERVERID) + break; + if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == + 0xff000000) { struct extentaddr *exp; int base, index; @@ -2633,30 +2957,34 @@ struct nvldbentry *VldbEntry; } } } else - VldbEntry->serverNumber[i] = HostAddress[VlEntry->serverNumber[i]]; + VldbEntry->serverNumber[i] = + HostAddress[VlEntry->serverNumber[i]]; VldbEntry->serverPartition[i] = VlEntry->serverPartition[i]; VldbEntry->serverFlags[i] = VlEntry->serverFlags[i]; } VldbEntry->nServers = i; - for (i=0; ivolumeId[i] = VlEntry->volumeId[i]; VldbEntry->cloneId = VlEntry->cloneId; VldbEntry->flags = VlEntry->flags; } -static vlentry_to_uvldbentry(VlEntry, VldbEntry) -struct nvlentry *VlEntry; -struct uvldbentry *VldbEntry; +static +vlentry_to_uvldbentry(VlEntry, VldbEntry) + struct nvlentry *VlEntry; + struct uvldbentry *VldbEntry; { int i, j; - + memset(VldbEntry, 0, sizeof(struct vldbentry)); strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name)); - for (i=0; i < NMAXNSERVERS; i++) { - if (VlEntry->serverNumber[i] == BADSERVERID) break; + for (i = 0; i < NMAXNSERVERS; i++) { + if (VlEntry->serverNumber[i] == BADSERVERID) + break; VldbEntry->serverFlags[i] = VlEntry->serverFlags[i]; VldbEntry->serverUnique[i] = 0; - if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == 0xff000000) { + if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == + 0xff000000) { struct extentaddr *exp; int base, index; afsUUID tuuid; @@ -2670,13 +2998,14 @@ struct uvldbentry *VldbEntry; VldbEntry->serverNumber[i] = tuuid; VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier); } else { - VldbEntry->serverNumber[i].time_low = HostAddress[VlEntry->serverNumber[i]]; + VldbEntry->serverNumber[i].time_low = + HostAddress[VlEntry->serverNumber[i]]; } VldbEntry->serverPartition[i] = VlEntry->serverPartition[i]; } VldbEntry->nServers = i; - for (i=0; ivolumeId[i] = VlEntry->volumeId[i]; VldbEntry->cloneId = VlEntry->cloneId; VldbEntry->flags = VlEntry->flags; @@ -2688,22 +3017,23 @@ struct uvldbentry *VldbEntry; /* Verify that the volname is a valid volume name. */ static int InvalidVolname(volname) -char *volname; + char *volname; { char *map; int slen; map = LEGALCHARS; slen = strlen(volname); - if (slen >= VL_MAXNAMELEN) return 1; - return(slen != strspn(volname, map)); + if (slen >= VL_MAXNAMELEN) + return 1; + return (slen != strspn(volname, map)); } /* Verify that the given volume type is valid. */ static int InvalidVoltype(voltype) -afs_int32 voltype; + afs_int32 voltype; { if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL) return 1; @@ -2713,47 +3043,56 @@ afs_int32 voltype; static int InvalidOperation(voloper) -afs_int32 voloper; + afs_int32 voloper; { - if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE && voloper != VLOP_BACKUP && voloper != VLOP_DELETE && voloper != VLOP_DUMP) + if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE + && voloper != VLOP_BACKUP && voloper != VLOP_DELETE + && voloper != VLOP_DUMP) return 1; return 0; } static int InvalidReleasetype(releasetype) -afs_int32 releasetype; + afs_int32 releasetype; { - if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE) || (releasetype & LOCKREL_AFSID)) + if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE) + || (releasetype & LOCKREL_AFSID)) return 0; return 1; } static int IpAddrToRelAddr(ipaddr, atrans) -struct ubik_trans *atrans; -register afs_uint32 ipaddr; + struct ubik_trans *atrans; + register afs_uint32 ipaddr; { register int i, j; register afs_int32 code, base, index; struct extentaddr *exp; for (i = 0; i <= MAXSERVERID; i++) { - if (HostAddress[i] == ipaddr) + if (HostAddress[i] == ipaddr) return i; if ((HostAddress[i] & 0xff000000) == 0xff000000) { base = (HostAddress[i] >> 16) & 0xff; index = HostAddress[i] & 0x0000ffff; if (base >= VL_MAX_ADDREXTBLKS) { - VLog(0, ("Internal error: Multihome extent base is too large. Base %d index %d\n", base, index)); + VLog(0, + ("Internal error: Multihome extent base is too large. Base %d index %d\n", + base, index)); return -1; /* EINVAL */ } if (index >= VL_MHSRV_PERBLK) { - VLog(0, ("Internal error: Multihome extent index is too large. Base %d index %d\n", base, index)); + VLog(0, + ("Internal error: Multihome extent index is too large. Base %d index %d\n", + base, index)); return -1; /* EINVAL */ } if (!ex_addr[base]) { - VLog(0, ("Internal error: Multihome extent does not exist. Base %d\n", base)); + VLog(0, + ("Internal error: Multihome extent does not exist. Base %d\n", + base)); return -1; /* EINVAL */ } exp = &ex_addr[base][index]; @@ -2767,12 +3106,17 @@ register afs_uint32 ipaddr; /* allocate the new server a server id pronto */ if (atrans) { - for(i=0;i <= MAXSERVERID;i++) { + for (i = 0; i <= MAXSERVERID; i++) { if (cheader.IpMappedAddr[i] == 0) { cheader.IpMappedAddr[i] = htonl(ipaddr); - code = vlwrite(atrans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]), (char *) &cheader.IpMappedAddr[i], sizeof(afs_int32)); + code = + vlwrite(atrans, + DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]), + (char *)&cheader.IpMappedAddr[i], + sizeof(afs_int32)); HostAddress[i] = ipaddr; - if (code) return -1; + if (code) + return -1; return i; } } @@ -2782,8 +3126,8 @@ register afs_uint32 ipaddr; static int ChangeIPAddr(ipaddr1, ipaddr2, atrans) -struct ubik_trans *atrans; -register afs_uint32 ipaddr1, ipaddr2; + struct ubik_trans *atrans; + register afs_uint32 ipaddr1, ipaddr2; { int i, j; afs_int32 code; @@ -2791,55 +3135,56 @@ register afs_uint32 ipaddr1, ipaddr2; int base, index, mhidx; afsUUID tuuid; afs_int32 blockindex, count; - int pollcount = 0; + int pollcount = 0; struct nvlentry tentry; if (!atrans) - return VL_CREATEFAIL; + return VL_CREATEFAIL; /* Don't let addr change to 256.*.*.* : Causes internal error below */ if ((ipaddr2 & 0xff000000) == 0xff000000) - return(VL_BADSERVER); - - /* If we are removing an address, ip1 will be -1 and ip2 will be - * the original address. This prevents an older revision vlserver - * from removing the IP address (won't find server 0xfffffff in - * the VLDB). An older revision vlserver does not have the check - * to see if any volumes exist on the server being removed. - */ - if (ipaddr1 == 0xffffffff) { - ipaddr1 = ipaddr2; - ipaddr2 = 0; - } + return (VL_BADSERVER); + + /* If we are removing an address, ip1 will be -1 and ip2 will be + * the original address. This prevents an older revision vlserver + * from removing the IP address (won't find server 0xfffffff in + * the VLDB). An older revision vlserver does not have the check + * to see if any volumes exist on the server being removed. + */ + if (ipaddr1 == 0xffffffff) { + ipaddr1 = ipaddr2; + ipaddr2 = 0; + } for (i = 0; i <= MAXSERVERID; i++) { - if ((HostAddress[i] & 0xff000000) == 0xff000000) { - base = (HostAddress[i] >> 16) & 0xff; - index = HostAddress[i] & 0x0000ffff; - if ((base >= VL_MAX_ADDREXTBLKS) || (index >= VL_MHSRV_PERBLK)) { - VLog(0, ("Internal error: Multihome extent addr is too large. Base %d index %d\n", + if ((HostAddress[i] & 0xff000000) == 0xff000000) { + base = (HostAddress[i] >> 16) & 0xff; + index = HostAddress[i] & 0x0000ffff; + if ((base >= VL_MAX_ADDREXTBLKS) || (index >= VL_MHSRV_PERBLK)) { + VLog(0, + ("Internal error: Multihome extent addr is too large. Base %d index %d\n", base, index)); - return -1; /* EINVAL */ - } - - exp = &ex_addr[base][index]; - for (mhidx=0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { - if (!exp->ex_addrs[mhidx]) continue; - if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1) - break; - } - if (mhidx < VL_MAXIPADDRS_PERMH) { - break; - } - } - else if (HostAddress[i] == ipaddr1) { - exp = (struct extentaddr *)0; - break; - } + return -1; /* EINVAL */ + } + + exp = &ex_addr[base][index]; + for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { + if (!exp->ex_addrs[mhidx]) + continue; + if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1) + break; + } + if (mhidx < VL_MAXIPADDRS_PERMH) { + break; + } + } else if (HostAddress[i] == ipaddr1) { + exp = NULL; + break; + } } if (i >= MAXSERVERID) { - return VL_NOENT; /* not found */ + return VL_NOENT; /* not found */ } /* If we are removing a server entry, a volume cannot @@ -2847,68 +3192,77 @@ register afs_uint32 ipaddr1, ipaddr2; * server entry: return error "volume entry exists". */ if (ipaddr2 == 0) { - for (blockindex = NextEntry(atrans, 0, &tentry, &count); - blockindex; - blockindex = NextEntry(atrans, blockindex, &tentry, &count)) { - if (++pollcount > 50) { - IOMGR_Poll(); - pollcount = 0; - } - for (j=0; j 50) { + IOMGR_Poll(); + pollcount = 0; + } + for (j = 0; j < NMAXNSERVERS; j++) { + if (tentry.serverNumber[j] == BADSERVERID) + break; + if (tentry.serverNumber[j] == i) { + return VL_IDEXIST; + } + } + } } /* Log a message saying we are changing/removing an IP address */ - VLog(0, ("The following IP address is being %s:\n", - (ipaddr2?"changed":"removed"))); + VLog(0, + ("The following IP address is being %s:\n", + (ipaddr2 ? "changed" : "removed"))); printf(" entry %d: ", i); if (exp) { - printf("["); - for (mhidx=0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { - if (!exp->ex_addrs[mhidx]) continue; - if (mhidx>0) printf(" "); - PADDR(ntohl(exp->ex_addrs[mhidx])); - } - printf("]"); + printf("["); + for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { + if (!exp->ex_addrs[mhidx]) + continue; + if (mhidx > 0) + printf(" "); + PADDR(ntohl(exp->ex_addrs[mhidx])); + } + printf("]"); } else { - PADDR(ipaddr1); + PADDR(ipaddr1); } if (ipaddr2) { - printf(" -> "); - PADDR(ipaddr2); + printf(" -> "); + PADDR(ipaddr2); } printf("\n"); /* Change the registered uuuid addresses */ if (exp) { - memset(&tuuid, 0, sizeof(afsUUID)); - afs_htonuuid(&tuuid); - exp->ex_hostuuid = tuuid; - code = vlwrite(atrans, DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), - (char *)ex_addr[base], (char *)exp), - (char *)&tuuid, sizeof(tuuid)); - if (code) - return VL_IO; + memset(&tuuid, 0, sizeof(afsUUID)); + afs_htonuuid(&tuuid); + exp->ex_hostuuid = tuuid; + code = + vlwrite(atrans, + DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), + (char *)ex_addr[base], (char *)exp), + (char *)&tuuid, sizeof(tuuid)); + if (code) + return VL_IO; } /* Now change the host address entry */ cheader.IpMappedAddr[i] = htonl(ipaddr2); - code = vlwrite(atrans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]), (char *) - &cheader.IpMappedAddr[i], sizeof(afs_int32)); + code = + vlwrite(atrans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]), + (char *) + &cheader.IpMappedAddr[i], sizeof(afs_int32)); HostAddress[i] = ipaddr2; if (code) - return VL_IO; + return VL_IO; return 0; } /* see if the vlserver is back yet */ +afs_int32 SVL_ProbeServer(rxcall) -struct rx_call *rxcall; { + struct rx_call *rxcall; +{ return 0; } diff --git a/src/vlserver/vlserver.c b/src/vlserver/vlserver.c index 9caa6c701..eefbf76f8 100644 --- a/src/vlserver/vlserver.c +++ b/src/vlserver/vlserver.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vlserver.c,v 1.1.1.10 2002/05/11 00:03:35 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vlserver/vlserver.c,v 1.18 2003/12/07 22:49:42 jaltman Exp $"); #include #include @@ -33,6 +34,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vlserver.c,v 1.1.1.10 2002/05/ #include #endif #include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include @@ -52,26 +62,29 @@ int lwps = 9; struct vldstats dynamic_statistics; struct ubik_dbase *VL_dbase; -afs_uint32 HostAddress[MAXSERVERID+1]; +afs_uint32 HostAddress[MAXSERVERID + 1]; extern int afsconf_CheckAuth(); extern int afsconf_ServerAuth(); -extern afs_int32 ubik_lastYesTime; -extern afs_int32 ubik_nBuffers; - -static CheckSignal(); +static CheckSignal(); int LogLevel = 0; int smallMem = 0; -int rxJumbograms = 1; /* default is to send and receive jumbo grams */ +int rxJumbograms = 1; /* default is to send and receive jumbo grams */ -static void CheckSignal_Signal() {IOMGR_SoftSig(CheckSignal, 0);} +static void +CheckSignal_Signal() +{ + IOMGR_SoftSig(CheckSignal, 0); +} -static CheckSignal() +static +CheckSignal() { register int i, errorcode; - struct ubik_trans *trans; + struct ubik_trans *trans; - if (errorcode = Init_VLdbase(&trans, LOCKREAD, VLGETSTATS-VL_LOWEST_OPCODE)) + if (errorcode = + Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)) return errorcode; VLog(0, ("Dump name hash table out\n")); for (i = 0; i < HASHSIZE; i++) { @@ -81,43 +94,45 @@ static CheckSignal() for (i = 0; i < HASHSIZE; i++) { HashIdDump(trans, i); } - return(ubik_EndTrans(trans)); -} /*CheckSignal*/ + return (ubik_EndTrans(trans)); +} /*CheckSignal */ /* Initialize the stats for the opcodes */ -void initialize_dstats () -{ int i; +void +initialize_dstats() +{ + int i; dynamic_statistics.start_time = (afs_uint32) time(0); - for (i=0; i< MAX_NUMBER_OPCODES; i++) { + for (i = 0; i < MAX_NUMBER_OPCODES; i++) { dynamic_statistics.requests[i] = 0; dynamic_statistics.aborts[i] = 0; } } /* check whether caller is authorized to manage RX statistics */ -int vldb_rxstat_userok(call) - struct rx_call *call; +int +vldb_rxstat_userok(call) + struct rx_call *call; { - return afsconf_SuperUser(vldb_confdir, call, (char *)0); + return afsconf_SuperUser(vldb_confdir, call, NULL); } /* Main server module */ #include "AFS_component_version_number.c" -main (argc, argv) -int argc; -char **argv; +main(argc, argv) + int argc; + char **argv; { - register afs_int32 code; - afs_int32 myHost; - struct rx_service *tservice; + register afs_int32 code; + afs_int32 myHost; + struct rx_service *tservice; struct rx_securityClass *sc[3]; - extern struct rx_securityClass *rxnull_NewServerSecurityObject(); - extern int VL_ExecuteRequest(); - extern int RXSTATS_ExecuteRequest(); + extern int VL_ExecuteRequest(); + extern int RXSTATS_ExecuteRequest(); struct afsconf_dir *tdir; struct ktc_encryptionKey tkey; struct afsconf_cell info; @@ -127,7 +142,7 @@ char **argv; extern int rx_extraPackets; char commandLine[150]; char clones[MAXHOSTSPERCELL]; - + #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a @@ -136,8 +151,8 @@ char **argv; * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - - rx_extraPackets = 100; /* should be a switch, I guess... */ + + rx_extraPackets = 100; /* should be a switch, I guess... */ sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; @@ -145,14 +160,15 @@ char **argv; sigaction(SIGSEGV, &nsa, NULL); #endif /* Parse command line */ - for (index=1; index < argc; index++) { + for (index = 1; index < argc; index++) { if (strcmp(argv[index], "-noauth") == 0) { noAuth = 1; } else if (strcmp(argv[index], "-p") == 0) { lwps = atoi(argv[++index]); if (lwps > MAXLWP) { - printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP); + printf("Warning: '-p %d' is too big; using %d instead\n", + lwps, MAXLWP); lwps = MAXLWP; } @@ -164,19 +180,19 @@ char **argv; } else if (strcmp(argv[index], "-trace") == 0) { extern char rxi_tracename[80]; - strcpy (rxi_tracename, argv[++index]); + strcpy(rxi_tracename, argv[++index]); } else if (strcmp(argv[index], "-enable_peer_stats") == 0) { rx_enablePeerRPCStats(); } else if (strcmp(argv[index], "-enable_process_stats") == 0) { rx_enableProcessRPCStats(); #ifndef AFS_NT40_ENV - } else if (strcmp(argv[index], "-syslog")==0) { + } else if (strcmp(argv[index], "-syslog") == 0) { /* set syslog logging flag */ serverLogSyslog = 1; - } else if (strncmp(argv[index], "-syslog=", 8)==0) { + } else if (strncmp(argv[index], "-syslog=", 8) == 0) { serverLogSyslog = 1; - serverLogSyslogFacility = atoi(argv[index]+8); + serverLogSyslogFacility = atoi(argv[index] + 8); #endif } else { /* support help flag */ @@ -198,35 +214,41 @@ char **argv; /* Initialize dirpaths */ if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) { #ifdef AFS_NT40_ENV - ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0],0); + ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0); #endif - fprintf(stderr,"%s: Unable to obtain AFS server directory.\n", argv[0]); + fprintf(stderr, "%s: Unable to obtain AFS server directory.\n", + argv[0]); exit(2); - } + } vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH; - OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */ - SetupLogSignals(); +#ifndef AFS_NT40_ENV + serverLogSyslogTag = "vlserver"; +#endif + OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */ + SetupLogSignals(); tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH); if (!tdir) { - printf("vlserver: can't open configuration files in dir %s, giving up.\n", AFSDIR_SERVER_ETC_DIRPATH); + printf + ("vlserver: can't open configuration files in dir %s, giving up.\n", + AFSDIR_SERVER_ETC_DIRPATH); exit(1); } -#ifdef AFS_NT40_ENV +#ifdef AFS_NT40_ENV /* initialize winsock */ - if (afs_winsockInit()<0) { - ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, - argv[0],0); - fprintf(stderr, "vlserver: couldn't initialize winsock. \n"); - exit(1); + if (afs_winsockInit() < 0) { + ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0); + fprintf(stderr, "vlserver: couldn't initialize winsock. \n"); + exit(1); } #endif /* get this host */ - gethostname(hostname,sizeof(hostname)); + gethostname(hostname, sizeof(hostname)); th = gethostbyname(hostname); if (!th) { - printf("vlserver: couldn't get address of this host (%s).\n", hostname); + printf("vlserver: couldn't get address of this host (%s).\n", + hostname); exit(1); } memcpy(&myHost, th->h_addr, sizeof(afs_int32)); @@ -235,30 +257,33 @@ char **argv; signal(SIGXCPU, CheckSignal_Signal); #endif /* get list of servers */ - code = afsconf_GetExtendedCellInfo(tdir,(char *)0, AFSCONF_VLDBSERVICE, - &info, &clones); + code = + afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info, + &clones); if (code) { printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n"); exit(2); } - vldb_confdir = tdir; /* Preserve our configuration dir */ + vldb_confdir = tdir; /* Preserve our configuration dir */ /* rxvab no longer supported */ memset(&tkey, 0, sizeof(tkey)); - if (noAuth) afsconf_SetNoAuthFlag(tdir, 1); + if (noAuth) + afsconf_SetNoAuthFlag(tdir, 1); ubik_nBuffers = 512; ubik_CRXSecurityProc = afsconf_ClientAuth; - ubik_CRXSecurityRock = (char *) tdir; + ubik_CRXSecurityRock = (char *)tdir; ubik_SRXSecurityProc = afsconf_ServerAuth; - ubik_SRXSecurityRock = (char *) tdir; + ubik_SRXSecurityRock = (char *)tdir; ubik_CheckRXSecurityProc = afsconf_CheckAuth; - ubik_CheckRXSecurityRock = (char *) tdir; - code = ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, - &clones, vl_dbaseName, &VL_dbase); + ubik_CheckRXSecurityRock = (char *)tdir; + code = + ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, &clones, + vl_dbaseName, &VL_dbase); if (code) { - printf("vlserver: Ubik init failed with code %d\n",code); + printf("vlserver: Ubik init failed with code %d\n", code); exit(2); } if (!rxJumbograms) { @@ -270,9 +295,11 @@ char **argv; initialize_dstats(); sc[0] = rxnull_NewServerSecurityObject(); - sc[1] = (struct rx_securityClass *) 0; - sc[2] = (struct rx_securityClass *) rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, (char *) 0); - tservice = rx_NewService(0, USER_SERVICE_ID, "Vldb server", sc, 3, VL_ExecuteRequest); + sc[1] = (struct rx_securityClass *)0; + sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL); + tservice = + rx_NewService(0, USER_SERVICE_ID, "Vldb server", sc, 3, + VL_ExecuteRequest); if (tservice == (struct rx_service *)0) { printf("vlserver: Could not create VLDB_SERVICE rx service\n"); exit(3); @@ -282,7 +309,9 @@ char **argv; lwps = 4; rx_SetMaxProcs(tservice, lwps); - tservice = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3, RXSTATS_ExecuteRequest); + tservice = + rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3, + RXSTATS_ExecuteRequest); if (tservice == (struct rx_service *)0) { printf("vlserver: Could not create rpc stats rx service\n"); exit(3); @@ -290,16 +319,17 @@ char **argv; rx_SetMinProcs(tservice, 2); rx_SetMaxProcs(tservice, 4); - for (commandLine[0]='\0', i=0; i 0) strcat(commandLine, " "); + for (commandLine[0] = '\0', i = 0; i < argc; i++) { + if (i > 0) + strcat(commandLine, " "); strcat(commandLine, argv[i]); } - ViceLog(0,("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine)); - printf("%s\n", cml_version_number); /* Goes to the log */ + ViceLog(0, + ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine)); + printf("%s\n", cml_version_number); /* Goes to the log */ /* allow super users to manage RX statistics */ rx_SetRxStatUserOk(vldb_rxstat_userok); - rx_StartServer(1); /* Why waste this idle process?? */ + rx_StartServer(1); /* Why waste this idle process?? */ } - diff --git a/src/vlserver/vlserver.p.h b/src/vlserver/vlserver.p.h index 0a8beb59e..141e626d5 100644 --- a/src/vlserver/vlserver.p.h +++ b/src/vlserver/vlserver.p.h @@ -23,11 +23,11 @@ extern struct vldstats dynamic_statistics; /* Current upper limits limits on certain entries; increase with care! */ #define BADSERVERID 255 -#define MAXSERVERID 254 /* permits 255 servers; was == 30 in version 1 */ +#define MAXSERVERID 254 /* permits 255 servers; was == 30 in version 1 */ #define MAXSERVERFLAG 0x80 #define MAXPARTITIONID 255 -#define MAXBUMPCOUNT 0x7fffffff /* Infinite upper bound on bumping for now */ -#define MAXLOCKTIME 0x7fffffff /* Infinite locking for now */ +#define MAXBUMPCOUNT 0x7fffffff /* Infinite upper bound on bumping for now */ +#define MAXLOCKTIME 0x7fffffff /* Infinite locking for now */ /* Order of entries in the volumeid[] array */ #define RWVOL 0 @@ -36,18 +36,18 @@ extern struct vldstats dynamic_statistics; /* Header struct holding stats, internal pointers and the hash tables */ struct vlheader { - struct vital_vlheader vital_header; /* all small critical stuff are in here */ - afs_uint32 IpMappedAddr[MAXSERVERID+1]; /* Mapping of ip addresses to relative ones */ - afs_int32 VolnameHash[HASHSIZE]; /* hash table for vol names */ - afs_int32 VolidHash[MAXTYPES][HASHSIZE]; /* hash table for vol ids */ - afs_int32 SIT; /* spare for poss future use */ + struct vital_vlheader vital_header; /* all small critical stuff are in here */ + afs_uint32 IpMappedAddr[MAXSERVERID + 1]; /* Mapping of ip addresses to relative ones */ + afs_int32 VolnameHash[HASHSIZE]; /* hash table for vol names */ + afs_int32 VolidHash[MAXTYPES][HASHSIZE]; /* hash table for vol ids */ + afs_int32 SIT; /* spare for poss future use */ }; /* Vlentry's flags state */ -#define VLFREE 1 /* If in free list */ -#define VLDELETED 2 /* Entry is soft deleted */ -#define VLLOCKED 4 /* Advisory lock on entry */ -#define VLCONTBLOCK 8 /* Special continuation block entry */ +#define VLFREE 1 /* If in free list */ +#define VLDELETED 2 /* Entry is soft deleted */ +#define VLLOCKED 4 /* Advisory lock on entry */ +#define VLCONTBLOCK 8 /* Special continuation block entry */ /* Valid RelaseLock types */ #define LOCKREL_TIMESTAMP 1 @@ -55,40 +55,40 @@ struct vlheader { #define LOCKREL_AFSID 4 /* Per repsite flags (serverFlags) */ -#define VLREPSITE_NEW 1 /* Replication site is got new release */ +#define VLREPSITE_NEW 1 /* Replication site is got new release */ /* Internal representation of vldbentry; trying to save any bytes */ struct vlentry { - afs_uint32 volumeId[MAXTYPES]; /* Corresponding volume of each type */ - afs_int32 flags; /* General flags */ - afs_int32 LockAfsId; /* Person who locked entry */ - afs_int32 LockTimestamp; /* lock time stamp */ - afs_int32 cloneId; /* used during cloning */ - afs_int32 spares0; /* XXXX was AssociatedChain XXXX */ - afs_int32 nextIdHash[MAXTYPES]; /* Next id hash table pointer (or freelist ->[0]) */ - afs_int32 nextNameHash; /* Next name hash table pointer */ - afs_int32 spares1[2]; /* long spares */ - char name[VL_MAXNAMELEN]; /* Volume name */ - char spares3; /* XXX was volumeType XXXX */ - u_char serverNumber[OMAXNSERVERS]; /* Server # for each server that holds volume */ - u_char serverPartition[OMAXNSERVERS];/* Server Partition number */ - u_char serverFlags[OMAXNSERVERS]; /* Server flags */ - char spares4; /* XXX was RefCount XXX */ - char spares2[1]; /* for 32-bit alignment */ + afs_uint32 volumeId[MAXTYPES]; /* Corresponding volume of each type */ + afs_int32 flags; /* General flags */ + afs_int32 LockAfsId; /* Person who locked entry */ + afs_int32 LockTimestamp; /* lock time stamp */ + afs_int32 cloneId; /* used during cloning */ + afs_int32 spares0; /* XXXX was AssociatedChain XXXX */ + afs_int32 nextIdHash[MAXTYPES]; /* Next id hash table pointer (or freelist ->[0]) */ + afs_int32 nextNameHash; /* Next name hash table pointer */ + afs_int32 spares1[2]; /* long spares */ + char name[VL_MAXNAMELEN]; /* Volume name */ + char spares3; /* XXX was volumeType XXXX */ + u_char serverNumber[OMAXNSERVERS]; /* Server # for each server that holds volume */ + u_char serverPartition[OMAXNSERVERS]; /* Server Partition number */ + u_char serverFlags[OMAXNSERVERS]; /* Server flags */ + char spares4; /* XXX was RefCount XXX */ + char spares2[1]; /* for 32-bit alignment */ }; struct nvlentry { - afs_uint32 volumeId[MAXTYPES]; /* Corresponding volume of each type */ - afs_int32 flags; /* General flags */ - afs_int32 LockAfsId; /* Person who locked entry */ - afs_int32 LockTimestamp; /* lock time stamp */ - afs_int32 cloneId; /* used during cloning */ - afs_int32 nextIdHash[MAXTYPES]; /* Next id hash table pointer (or freelist ->[0]) */ - afs_int32 nextNameHash; /* Next name hash table pointer */ - char name[VL_MAXNAMELEN]; /* Volume name */ - u_char serverNumber[NMAXNSERVERS]; /* Server # for each server that holds volume */ - u_char serverPartition[NMAXNSERVERS];/* Server Partition number */ - u_char serverFlags[NMAXNSERVERS]; /* Server flags */ + afs_uint32 volumeId[MAXTYPES]; /* Corresponding volume of each type */ + afs_int32 flags; /* General flags */ + afs_int32 LockAfsId; /* Person who locked entry */ + afs_int32 LockTimestamp; /* lock time stamp */ + afs_int32 cloneId; /* used during cloning */ + afs_int32 nextIdHash[MAXTYPES]; /* Next id hash table pointer (or freelist ->[0]) */ + afs_int32 nextNameHash; /* Next name hash table pointer */ + char name[VL_MAXNAMELEN]; /* Volume name */ + u_char serverNumber[NMAXNSERVERS]; /* Server # for each server that holds volume */ + u_char serverPartition[NMAXNSERVERS]; /* Server Partition number */ + u_char serverFlags[NMAXNSERVERS]; /* Server flags */ }; typedef struct vlheader vlheader; @@ -106,11 +106,11 @@ typedef struct nvlentry nvlentry; struct extentaddr { union ex_un { struct { - afs_int32 count; /* # of valid addresses */ - afs_int32 spares1[2]; - afs_int32 flags; /* must match vlentry's flags field XXX */ + afs_int32 count; /* # of valid addresses */ + afs_int32 spares1[2]; + afs_int32 flags; /* must match vlentry's flags field XXX */ afs_uint32 contaddrs[VL_MAX_ADDREXTBLKS]; - afs_int32 spares2[24]; + afs_int32 spares2[24]; } _ex_header; struct { afsUUID hostuuid; @@ -126,6 +126,8 @@ struct extentaddr { #define ex_addrs _ex_un._ex_addrentry.addrs #define ex_uniquifier _ex_un._ex_addrentry.uniquifier -#define VLog(level, str) ViceLog(5, str) +#define VLog(level, str) ViceLog(5, str) + +extern int FreeBlock(struct ubik_trans *trans, afs_int32 blockindex); #endif /* _VLSERVER_ */ diff --git a/src/vlserver/vlutils.c b/src/vlserver/vlutils.c index 88becd573..7f0693558 100644 --- a/src/vlserver/vlutils.c +++ b/src/vlserver/vlutils.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vlutils.c,v 1.1.1.7 2001/10/14 18:07:18 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vlserver/vlutils.c,v 1.9 2003/12/07 22:49:42 jaltman Exp $"); #include #ifdef AFS_NT40_ENV @@ -18,92 +19,112 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vlserver/vlutils.c,v 1.1.1.7 2001/10/14 #else #include #endif + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include #include "vlserver.h" -extern struct vlheader cheader; +extern struct vlheader cheader; struct vlheader xheader; -extern struct ubik_dbase *VL_dbase; extern afs_uint32 HostAddress[]; extern int maxnservers; struct extentaddr extentaddr; extern struct extentaddr *ex_addr[]; -int vldbversion=0; +int vldbversion = 0; static int index_OK(); #define ERROR_EXIT(code) {error=(code); goto error_exit;} /* Hashing algorithm based on the volume id; HASHSIZE must be prime */ -afs_int32 IDHash(volumeid) -afs_int32 volumeid; +afs_int32 +IDHash(volumeid) + afs_int32 volumeid; { - return((abs(volumeid)) % HASHSIZE); + return ((abs(volumeid)) % HASHSIZE); } /* Hashing algorithm based on the volume name; name's size is implicit (64 chars) and if changed it should be reflected here. */ -afs_int32 NameHash (volumename) -register char *volumename; -{ register unsigned int hash; - register int i; +afs_int32 +NameHash(volumename) + register char *volumename; +{ + register unsigned int hash; + register int i; hash = 0; - for (i=strlen(volumename), volumename += i-1; i--; volumename--) - hash = (hash*63) + (*((unsigned char *)volumename) - 63); - return(hash % HASHSIZE); + for (i = strlen(volumename), volumename += i - 1; i--; volumename--) + hash = (hash * 63) + (*((unsigned char *)volumename) - 63); + return (hash % HASHSIZE); } /* package up seek and write into one procedure for ease of use */ -afs_int32 vlwrite (trans, offset, buffer, length) -struct ubik_trans *trans; -afs_int32 offset; -char *buffer; -afs_int32 length; -{ afs_int32 errorcode; - - if (errorcode = ubik_Seek(trans, 0, offset)) return errorcode; - return(ubik_Write(trans, buffer, length)); +afs_int32 +vlwrite(trans, offset, buffer, length) + struct ubik_trans *trans; + afs_int32 offset; + char *buffer; + afs_int32 length; +{ + afs_int32 errorcode; + + if (errorcode = ubik_Seek(trans, 0, offset)) + return errorcode; + return (ubik_Write(trans, buffer, length)); } /* Package up seek and read into one procedure for ease of use */ -afs_int32 vlread (trans, offset, buffer, length) -struct ubik_trans *trans; -afs_int32 offset; -char *buffer; -afs_int32 length; -{ afs_int32 errorcode; - - if (errorcode = ubik_Seek(trans, 0, offset)) return errorcode; - return(ubik_Read(trans, buffer, length)); +afs_int32 +vlread(trans, offset, buffer, length) + struct ubik_trans *trans; + afs_int32 offset; + char *buffer; + afs_int32 length; +{ + afs_int32 errorcode; + + if (errorcode = ubik_Seek(trans, 0, offset)) + return errorcode; + return (ubik_Read(trans, buffer, length)); } /* take entry and convert to network order and write to disk */ -afs_int32 vlentrywrite(trans, offset, buffer, length) -struct ubik_trans *trans; -afs_int32 offset; -char *buffer; -afs_int32 length; { +afs_int32 +vlentrywrite(trans, offset, buffer, length) + struct ubik_trans *trans; + afs_int32 offset; + char *buffer; + afs_int32 length; +{ struct vlentry oentry; struct nvlentry nentry, *nep; char *bufp; register afs_int32 i; - if (length != sizeof(oentry)) return -1; + if (length != sizeof(oentry)) + return -1; if (maxnservers == 13) { nep = (struct nvlentry *)buffer; - for (i=0;ivolumeId[i]); nentry.flags = htonl(nep->flags); nentry.LockAfsId = htonl(nep->LockAfsId); nentry.LockTimestamp = htonl(nep->LockTimestamp); nentry.cloneId = htonl(nep->cloneId); - for (i=0;inextIdHash[i]); nentry.nextNameHash = htonl(nep->nextNameHash); memcpy(nentry.name, nep->name, VL_MAXNAMELEN); @@ -114,48 +135,52 @@ afs_int32 length; { } else { memset(&oentry, 0, sizeof(struct vlentry)); nep = (struct nvlentry *)buffer; - for (i=0;ivolumeId[i]); oentry.flags = htonl(nep->flags); oentry.LockAfsId = htonl(nep->LockAfsId); oentry.LockTimestamp = htonl(nep->LockTimestamp); oentry.cloneId = htonl(nep->cloneId); - for (i=0;inextIdHash[i]); oentry.nextNameHash = htonl(nep->nextNameHash); memcpy(oentry.name, nep->name, VL_MAXNAMELEN); memcpy(oentry.serverNumber, nep->serverNumber, OMAXNSERVERS); memcpy(oentry.serverPartition, nep->serverPartition, OMAXNSERVERS); memcpy(oentry.serverFlags, nep->serverFlags, OMAXNSERVERS); - bufp = (char *)&oentry; + bufp = (char *)&oentry; } return vlwrite(trans, offset, bufp, length); } /* read entry and convert to host order and write to disk */ -afs_int32 vlentryread(trans, offset, buffer, length) -struct ubik_trans *trans; -afs_int32 offset; -char *buffer; -afs_int32 length; { +afs_int32 +vlentryread(trans, offset, buffer, length) + struct ubik_trans *trans; + afs_int32 offset; + char *buffer; + afs_int32 length; +{ struct vlentry *oep, tentry; struct nvlentry *nep, *nbufp; char *bufp = (char *)&tentry; register afs_int32 i; - if (length != sizeof(vlentry)) return -1; + if (length != sizeof(vlentry)) + return -1; i = vlread(trans, offset, bufp, length); - if (i) return i; + if (i) + return i; if (maxnservers == 13) { nep = (struct nvlentry *)bufp; nbufp = (struct nvlentry *)buffer; - for(i=0;ivolumeId[i] = ntohl(nep->volumeId[i]); nbufp->flags = ntohl(nep->flags); nbufp->LockAfsId = ntohl(nep->LockAfsId); nbufp->LockTimestamp = ntohl(nep->LockTimestamp); nbufp->cloneId = ntohl(nep->cloneId); - for(i=0;inextIdHash[i] = ntohl(nep->nextIdHash[i]); nbufp->nextNameHash = ntohl(nep->nextNameHash); memcpy(nbufp->name, nep->name, VL_MAXNAMELEN); @@ -165,14 +190,14 @@ afs_int32 length; { } else { oep = (struct vlentry *)bufp; nbufp = (struct nvlentry *)buffer; - memset(nbufp, 0, sizeof (struct nvlentry)); - for(i=0;ivolumeId[i] = ntohl(oep->volumeId[i]); nbufp->flags = ntohl(oep->flags); nbufp->LockAfsId = ntohl(oep->LockAfsId); nbufp->LockTimestamp = ntohl(oep->LockTimestamp); nbufp->cloneId = ntohl(oep->cloneId); - for(i=0;inextIdHash[i] = ntohl(oep->nextIdHash[i]); nbufp->nextNameHash = ntohl(oep->nextNameHash); memcpy(nbufp->name, oep->name, VL_MAXNAMELEN); @@ -184,10 +209,13 @@ afs_int32 length; { } /* Convenient write of small critical vldb header info to the database. */ -int write_vital_vlheader(trans) -register struct ubik_trans *trans; +int +write_vital_vlheader(trans) + register struct ubik_trans *trans; { - if (vlwrite(trans, 0, (char *) &cheader.vital_header, sizeof(vital_vlheader))) return VL_IO; + if (vlwrite + (trans, 0, (char *)&cheader.vital_header, sizeof(vital_vlheader))) + return VL_IO; return 0; } @@ -202,93 +230,96 @@ int extent_mod = 0; * will wait until the next write transaction to write them out * (extent_mod tells us the on-disk copy is bad). */ -afs_int32 readExtents(trans) - struct ubik_trans *trans; +afs_int32 +readExtents(trans) + struct ubik_trans *trans; { - afs_uint32 extentAddr; - afs_int32 error=0, code; - int i; - - extent_mod = 0; - extentAddr = ntohl(cheader.SIT); - if (!extentAddr) - return 0; - - /* Read the first extension block */ - if (!ex_addr[0]) { - ex_addr[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); - if (!ex_addr[0]) - ERROR_EXIT(VL_NOMEM); - } - code = vlread(trans, extentAddr, (char *)ex_addr[0], VL_ADDREXTBLK_SIZE); - if (code) { - free(ex_addr[0]); /* Not the place to create it */ - ex_addr[0] = 0; - ERROR_EXIT(VL_IO); - } - - /* In case more that 64 mh servers are in use they're kept in these - * continuation blocks - */ - for (i=1; i < VL_MAX_ADDREXTBLKS; i++) { - if (!ex_addr[0]->ex_contaddrs[i]) - continue; - - /* Before reading it in, check to see if the address is good */ - if ( (ntohl(ex_addr[0]->ex_contaddrs[i]) < - ntohl(ex_addr[0]->ex_contaddrs[i-1])+VL_ADDREXTBLK_SIZE) || - (ntohl(ex_addr[0]->ex_contaddrs[i]) > - ntohl(cheader.vital_header.eofPtr)-VL_ADDREXTBLK_SIZE) ) { - extent_mod = 1; - ex_addr[0]->ex_contaddrs[i] = 0; - continue; - } - - - /* Read the continuation block */ - if (!ex_addr[i]) { - ex_addr[i] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); - if (!ex_addr[i]) - ERROR_EXIT(VL_NOMEM); - } - code = vlread(trans, ntohl(ex_addr[0]->ex_contaddrs[i]), + afs_uint32 extentAddr; + afs_int32 error = 0, code; + int i; + + extent_mod = 0; + extentAddr = ntohl(cheader.SIT); + if (!extentAddr) + return 0; + + /* Read the first extension block */ + if (!ex_addr[0]) { + ex_addr[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); + if (!ex_addr[0]) + ERROR_EXIT(VL_NOMEM); + } + code = vlread(trans, extentAddr, (char *)ex_addr[0], VL_ADDREXTBLK_SIZE); + if (code) { + free(ex_addr[0]); /* Not the place to create it */ + ex_addr[0] = 0; + ERROR_EXIT(VL_IO); + } + + /* In case more that 64 mh servers are in use they're kept in these + * continuation blocks + */ + for (i = 1; i < VL_MAX_ADDREXTBLKS; i++) { + if (!ex_addr[0]->ex_contaddrs[i]) + continue; + + /* Before reading it in, check to see if the address is good */ + if ((ntohl(ex_addr[0]->ex_contaddrs[i]) < + ntohl(ex_addr[0]->ex_contaddrs[i - 1]) + VL_ADDREXTBLK_SIZE) + || (ntohl(ex_addr[0]->ex_contaddrs[i]) > + ntohl(cheader.vital_header.eofPtr) - VL_ADDREXTBLK_SIZE)) { + extent_mod = 1; + ex_addr[0]->ex_contaddrs[i] = 0; + continue; + } + + + /* Read the continuation block */ + if (!ex_addr[i]) { + ex_addr[i] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); + if (!ex_addr[i]) + ERROR_EXIT(VL_NOMEM); + } + code = + vlread(trans, ntohl(ex_addr[0]->ex_contaddrs[i]), (char *)ex_addr[i], VL_ADDREXTBLK_SIZE); - if (code) { - free(ex_addr[i]); /* Not the place to create it */ - ex_addr[i] = 0; - ERROR_EXIT(VL_IO); - } - - /* After reading it in, check to see if its a real continuation block */ - if (ntohl(ex_addr[i]->ex_flags) != VLCONTBLOCK) { - extent_mod = 1; - ex_addr[0]->ex_contaddrs[i] = 0; - free(ex_addr[i]); /* Not the place to create it */ - ex_addr[i] = 0; - continue; - } - } - - if (extent_mod) { - code = vlwrite(trans, extentAddr, ex_addr[0], VL_ADDREXTBLK_SIZE); - if (!code) { - VLog(0, ("Multihome server support modification\n")); - } - /* Keep extent_mod true in-case the transaction aborts */ - /* Don't return error so we don't abort transaction */ - } - - error_exit: - return error; + if (code) { + free(ex_addr[i]); /* Not the place to create it */ + ex_addr[i] = 0; + ERROR_EXIT(VL_IO); + } + + /* After reading it in, check to see if its a real continuation block */ + if (ntohl(ex_addr[i]->ex_flags) != VLCONTBLOCK) { + extent_mod = 1; + ex_addr[0]->ex_contaddrs[i] = 0; + free(ex_addr[i]); /* Not the place to create it */ + ex_addr[i] = 0; + continue; + } + } + + if (extent_mod) { + code = vlwrite(trans, extentAddr, ex_addr[0], VL_ADDREXTBLK_SIZE); + if (!code) { + VLog(0, ("Multihome server support modification\n")); + } + /* Keep extent_mod true in-case the transaction aborts */ + /* Don't return error so we don't abort transaction */ + } + + error_exit: + return error; } /* Check that the database has been initialized. Be careful to fail in a safe manner, to avoid bogusly reinitializing the db. */ -afs_int32 CheckInit (trans, builddb) - struct ubik_trans *trans; - int builddb; +afs_int32 +CheckInit(trans, builddb) + struct ubik_trans *trans; + int builddb; { - afs_int32 error=0, i, code, ubcode=0; + afs_int32 error = 0, i, code, ubcode = 0; /* ubik_CacheUpdate must be called on every transaction. It returns 0 if the * previous transaction would have left the cache fine, and non-zero otherwise. @@ -299,18 +330,19 @@ afs_int32 CheckInit (trans, builddb) */ if (ubik_CacheUpdate(trans) != 0) { /* if version changed (or first call), read the header */ - ubcode = vlread (trans, 0, (char *) &cheader, sizeof(cheader)); + ubcode = vlread(trans, 0, (char *)&cheader, sizeof(cheader)); vldbversion = ntohl(cheader.vital_header.vldbversion); if (!ubcode && (vldbversion != 0)) { - memcpy(HostAddress, cheader.IpMappedAddr, sizeof(cheader.IpMappedAddr)); - for (i=0; iex_contaddrs[base]) { /* Create a new extension block */ - if (!ex_addr[base]) { - ex_addr[base] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); + if (!ex_addr[base]) { + ex_addr[base] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); if (!ex_addr[base]) - ERROR_EXIT(VL_NOMEM); + ERROR_EXIT(VL_NOMEM); } memset((char *)ex_addr[base], 0, VL_ADDREXTBLK_SIZE); /* Write the full extension block at end of vldb */ ex_addr[base]->ex_flags = htonl(VLCONTBLOCK); blockindex = ntohl(cheader.vital_header.eofPtr); - code = vlwrite(trans, blockindex, (char *)ex_addr[base], VL_ADDREXTBLK_SIZE); - if (code) ERROR_EXIT(VL_IO); + code = + vlwrite(trans, blockindex, (char *)ex_addr[base], + VL_ADDREXTBLK_SIZE); + if (code) + ERROR_EXIT(VL_IO); /* Update the cheader.vitalheader structure on disk */ cheader.vital_header.eofPtr = blockindex + VL_ADDREXTBLK_SIZE; cheader.vital_header.eofPtr = htonl(cheader.vital_header.eofPtr); code = write_vital_vlheader(trans); - if (code) ERROR_EXIT(VL_IO); - + if (code) + ERROR_EXIT(VL_IO); + /* Write the address of the base extension block in the vldb header */ if (base == 0) { cheader.SIT = htonl(blockindex); - code = vlwrite(trans, DOFFSET(0,&cheader,&cheader.SIT), - (char *)&cheader.SIT, sizeof(cheader.SIT)); - if (code) ERROR_EXIT(VL_IO); + code = + vlwrite(trans, DOFFSET(0, &cheader, &cheader.SIT), + (char *)&cheader.SIT, sizeof(cheader.SIT)); + if (code) + ERROR_EXIT(VL_IO); } /* Write the address of this extension block into the base extension block */ ex_addr[0]->ex_contaddrs[base] = htonl(blockindex); - code = vlwrite(trans, ntohl(cheader.SIT), ex_addr[0], sizeof(struct extentaddr)); - if (code) ERROR_EXIT(VL_IO); + code = + vlwrite(trans, ntohl(cheader.SIT), ex_addr[0], + sizeof(struct extentaddr)); + if (code) + ERROR_EXIT(VL_IO); } error_exit: @@ -406,32 +447,34 @@ afs_int32 GetExtentBlock(trans, base) } -afs_int32 FindExtentBlock(trans, uuidp, createit, hostslot, expp, basep) - register struct ubik_trans *trans; - afsUUID *uuidp; - afs_int32 createit, hostslot, *basep; - struct extentaddr **expp; +afs_int32 +FindExtentBlock(trans, uuidp, createit, hostslot, expp, basep) + register struct ubik_trans *trans; + afsUUID *uuidp; + afs_int32 createit, hostslot, *basep; + struct extentaddr **expp; { afsUUID tuuid; - struct extentaddr *exp; - register afs_int32 i, j, code, base, index, error=0; + struct extentaddr *exp; + register afs_int32 i, j, code, base, index, error = 0; - *expp = (struct extentaddr *)0; + *expp = NULL; *basep = 0; /* Create the first extension block if it does not exist */ if (!cheader.SIT) { - code = GetExtentBlock(trans, 0); - if (code) ERROR_EXIT(code); + code = GetExtentBlock(trans, 0); + if (code) + ERROR_EXIT(code); } - for (i = 0; i < MAXSERVERID+1; i++) { + for (i = 0; i < MAXSERVERID + 1; i++) { if ((HostAddress[i] & 0xff000000) == 0xff000000) { if ((base = (HostAddress[i] >> 16) & 0xff) > VL_MAX_ADDREXTBLKS) { - ERROR_EXIT(VL_INDEXERANGE); + ERROR_EXIT(VL_INDEXERANGE); } if ((index = HostAddress[i] & 0x0000ffff) > VL_MHSRV_PERBLK) { - ERROR_EXIT(VL_INDEXERANGE); + ERROR_EXIT(VL_INDEXERANGE); } exp = &ex_addr[base][index]; tuuid = exp->ex_hostuuid; @@ -446,20 +489,23 @@ afs_int32 FindExtentBlock(trans, uuidp, createit, hostslot, expp, basep) if (createit) { if (hostslot == -1) { - for (i=0; i MAXSERVERID) ERROR_EXIT(VL_REPSFULL); + if (i > MAXSERVERID) + ERROR_EXIT(VL_REPSFULL); } else { i = hostslot; } - for (base=0; baseex_contaddrs[base]) { - code = GetExtentBlock(trans, base); - if (code) ERROR_EXIT(code); + code = GetExtentBlock(trans, base); + if (code) + ERROR_EXIT(code); } - for (j=1; jex_hostuuid; afs_ntohuuid(&tuuid); @@ -467,22 +513,33 @@ afs_int32 FindExtentBlock(trans, uuidp, createit, hostslot, expp, basep) tuuid = *uuidp; afs_htonuuid(&tuuid); exp->ex_hostuuid = tuuid; - code = vlwrite(trans, DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), - (char *)ex_addr[base], (char *)exp), - (char *) &tuuid, sizeof(tuuid)); - if (code) ERROR_EXIT(VL_IO); - HostAddress[i] = 0xff000000 | ((base << 16) & 0xff0000) | (j & 0xffff); + code = + vlwrite(trans, + DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), + (char *)ex_addr[base], (char *)exp), + (char *)&tuuid, sizeof(tuuid)); + if (code) + ERROR_EXIT(VL_IO); + HostAddress[i] = + 0xff000000 | ((base << 16) & 0xff0000) | (j & 0xffff); *expp = exp; *basep = base; if (vldbversion != VLDBVERSION_4) { - cheader.vital_header.vldbversion = htonl(VLDBVERSION_4); + cheader.vital_header.vldbversion = + htonl(VLDBVERSION_4); code = write_vital_vlheader(trans); - if (code) ERROR_EXIT(VL_IO); + if (code) + ERROR_EXIT(VL_IO); } cheader.IpMappedAddr[i] = htonl(HostAddress[i]); - code = vlwrite(trans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]), - (char *) &cheader.IpMappedAddr[i], sizeof(afs_int32)); - if (code) ERROR_EXIT(VL_IO); + code = + vlwrite(trans, + DOFFSET(0, &cheader, + &cheader.IpMappedAddr[i]), + (char *)&cheader.IpMappedAddr[i], + sizeof(afs_int32)); + if (code) + ERROR_EXIT(VL_IO); ERROR_EXIT(0); } } @@ -496,65 +553,77 @@ afs_int32 FindExtentBlock(trans, uuidp, createit, hostslot, expp, basep) /* Allocate a free block of storage for entry, returning address of a new zeroed entry (or zero if something is wrong). */ -afs_int32 AllocBlock (trans, tentry) -register struct ubik_trans *trans; -struct nvlentry *tentry; -{ register afs_int32 blockindex; +afs_int32 +AllocBlock(trans, tentry) + register struct ubik_trans *trans; + struct nvlentry *tentry; +{ + register afs_int32 blockindex; if (cheader.vital_header.freePtr) { /* allocate this dude */ blockindex = ntohl(cheader.vital_header.freePtr); - if (vlentryread(trans, blockindex, (char *) tentry, sizeof(vlentry))) return 0; + if (vlentryread(trans, blockindex, (char *)tentry, sizeof(vlentry))) + return 0; cheader.vital_header.freePtr = htonl(tentry->nextIdHash[0]); - } - else { + } else { /* hosed, nothing on free list, grow file */ blockindex = ntohl(cheader.vital_header.eofPtr); /* remember this guy */ cheader.vital_header.eofPtr = htonl(blockindex + sizeof(vlentry)); } cheader.vital_header.allocs++; - if (write_vital_vlheader(trans)) return 0; + if (write_vital_vlheader(trans)) + return 0; memset(tentry, 0, sizeof(nvlentry)); /* zero new entry */ return blockindex; } /* Free a block given its index. It must already have been unthreaded. Returns zero for success or an error code on failure. */ -int FreeBlock (trans, blockindex) -struct ubik_trans *trans; -afs_int32 blockindex; -{ struct nvlentry tentry; +int +FreeBlock(trans, blockindex) + struct ubik_trans *trans; + afs_int32 blockindex; +{ + struct nvlentry tentry; /* check validity of blockindex just to be on the safe side */ - if (!index_OK (trans, blockindex)) return VL_BADINDEX; + if (!index_OK(trans, blockindex)) + return VL_BADINDEX; memset(&tentry, 0, sizeof(nvlentry)); - tentry.nextIdHash[0] = cheader.vital_header.freePtr; /* already in network order */ + tentry.nextIdHash[0] = cheader.vital_header.freePtr; /* already in network order */ tentry.flags = htonl(VLFREE); cheader.vital_header.freePtr = htonl(blockindex); - if (vlwrite (trans, blockindex, (char *)&tentry, sizeof(nvlentry))) + if (vlwrite(trans, blockindex, (char *)&tentry, sizeof(nvlentry))) return VL_IO; cheader.vital_header.frees++; - if (write_vital_vlheader(trans)) return VL_IO; + if (write_vital_vlheader(trans)) + return VL_IO; return 0; } /* Look for a block by volid and voltype (if not known use -1 which searches all 3 volid hash lists. Note that the linked lists are read in first from the database header. If found read the block's contents into the area pointed to by tentry and return the block's index. If not found return 0. */ -afs_int32 FindByID (trans, volid, voltype, tentry, error) -struct ubik_trans *trans; -afs_int32 volid; -afs_int32 voltype; -struct nvlentry *tentry; -afs_int32 *error; -{ register afs_int32 typeindex, hashindex, blockindex; +afs_int32 +FindByID(trans, volid, voltype, tentry, error) + struct ubik_trans *trans; + afs_int32 volid; + afs_int32 voltype; + struct nvlentry *tentry; + afs_int32 *error; +{ + register afs_int32 typeindex, hashindex, blockindex; *error = 0; hashindex = IDHash(volid); if (voltype == -1) { /* Should we have one big hash table for volids as opposed to the three ones? */ for (typeindex = 0; typeindex < MAXTYPES; typeindex++) { - for (blockindex = ntohl(cheader.VolidHash[typeindex][hashindex]); blockindex != NULLO; blockindex = tentry->nextIdHash[typeindex]) { - if (vlentryread(trans, blockindex, (char *) tentry, sizeof(nvlentry))) { + for (blockindex = ntohl(cheader.VolidHash[typeindex][hashindex]); + blockindex != NULLO; + blockindex = tentry->nextIdHash[typeindex]) { + if (vlentryread + (trans, blockindex, (char *)tentry, sizeof(nvlentry))) { *error = VL_IO; return 0; } @@ -563,8 +632,10 @@ afs_int32 *error; } } } else { - for (blockindex = ntohl(cheader.VolidHash[voltype][hashindex]); blockindex != NULLO; blockindex = tentry->nextIdHash[voltype]) { - if (vlentryread(trans, blockindex, (char *) tentry, sizeof(nvlentry))) { + for (blockindex = ntohl(cheader.VolidHash[voltype][hashindex]); + blockindex != NULLO; blockindex = tentry->nextIdHash[voltype]) { + if (vlentryread + (trans, blockindex, (char *)tentry, sizeof(nvlentry))) { *error = VL_IO; return 0; } @@ -572,91 +643,107 @@ afs_int32 *error; return blockindex; } } - return 0; /* no such entry */ + return 0; /* no such entry */ } /* Look for a block by volume name. If found read the block's contents into the area pointed to by tentry and return the block's index. If not found return 0. */ -afs_int32 FindByName (trans, volname, tentry, error) -struct ubik_trans *trans; -char *volname; -struct nvlentry *tentry; -afs_int32 *error; -{ register afs_int32 hashindex; - register afs_int32 blockindex; +afs_int32 +FindByName(trans, volname, tentry, error) + struct ubik_trans *trans; + char *volname; + struct nvlentry *tentry; + afs_int32 *error; +{ + register afs_int32 hashindex; + register afs_int32 blockindex; char tname[VL_MAXNAMELEN]; /* remove .backup or .readonly extensions for stupid backwards compatibility */ - hashindex = strlen(volname); /* really string length */ - if (hashindex >= 8 && strcmp(volname+hashindex-7, ".backup")==0) { + hashindex = strlen(volname); /* really string length */ + if (hashindex >= 8 && strcmp(volname + hashindex - 7, ".backup") == 0) { /* this is a backup volume */ strcpy(tname, volname); - tname[hashindex-7] = 0; /* zap extension */ - } - else if (hashindex >= 10 && strcmp(volname+hashindex-9, ".readonly")==0) { + tname[hashindex - 7] = 0; /* zap extension */ + } else if (hashindex >= 10 + && strcmp(volname + hashindex - 9, ".readonly") == 0) { /* this is a readonly volume */ strcpy(tname, volname); - tname[hashindex-9] = 0; /* zap extension */ - } - else strcpy(tname, volname); + tname[hashindex - 9] = 0; /* zap extension */ + } else + strcpy(tname, volname); *error = 0; hashindex = NameHash(tname); - for (blockindex = ntohl(cheader.VolnameHash[hashindex]); blockindex != NULLO; blockindex = tentry->nextNameHash) { - if (vlentryread(trans, blockindex, (char *) tentry, sizeof(nvlentry))) { + for (blockindex = ntohl(cheader.VolnameHash[hashindex]); + blockindex != NULLO; blockindex = tentry->nextNameHash) { + if (vlentryread(trans, blockindex, (char *)tentry, sizeof(nvlentry))) { *error = VL_IO; return 0; } if (!strcmp(tname, tentry->name)) return blockindex; } - return 0; /* no such entry */ + return 0; /* no such entry */ } -int HashNDump (trans, hashindex) -struct ubik_trans *trans; -int hashindex; +int +HashNDump(trans, hashindex) + struct ubik_trans *trans; + int hashindex; -{ register int i=0; - register int blockindex; - struct nvlentry tentry; +{ + register int i = 0; + register int blockindex; + struct nvlentry tentry; - for (blockindex = ntohl(cheader.VolnameHash[hashindex]); blockindex != NULLO; blockindex = tentry.nextNameHash) { - if (vlentryread(trans, blockindex, (char *) &tentry, sizeof(nvlentry))) return 0; + for (blockindex = ntohl(cheader.VolnameHash[hashindex]); + blockindex != NULLO; blockindex = tentry.nextNameHash) { + if (vlentryread(trans, blockindex, (char *)&tentry, sizeof(nvlentry))) + return 0; i++; - VLog(0, ("[%d]#%d: %10d %d %d (%s)\n", hashindex, i, tentry.volumeId[0], + VLog(0, + ("[%d]#%d: %10d %d %d (%s)\n", hashindex, i, tentry.volumeId[0], tentry.nextIdHash[0], tentry.nextNameHash, tentry.name)); } return 0; } -int HashIdDump (trans, hashindex) -struct ubik_trans *trans; -int hashindex; +int +HashIdDump(trans, hashindex) + struct ubik_trans *trans; + int hashindex; -{ register int i=0; - register int blockindex; - struct nvlentry tentry; +{ + register int i = 0; + register int blockindex; + struct nvlentry tentry; - for (blockindex = ntohl(cheader.VolidHash[0][hashindex]); blockindex != NULLO; blockindex = tentry.nextIdHash[0]) { - if (vlentryread(trans, blockindex, (char *) &tentry, sizeof(nvlentry))) return 0; + for (blockindex = ntohl(cheader.VolidHash[0][hashindex]); + blockindex != NULLO; blockindex = tentry.nextIdHash[0]) { + if (vlentryread(trans, blockindex, (char *)&tentry, sizeof(nvlentry))) + return 0; i++; - VLog(0, ("[%d]#%d: %10d %d %d (%s)\n", hashindex, i, tentry.volumeId[0], - tentry.nextIdHash[0], tentry.nextNameHash, tentry.name)); + VLog(0, + ("[%d]#%d: %10d %d %d (%s)\n", hashindex, i, tentry.volumeId[0], + tentry.nextIdHash[0], tentry.nextNameHash, tentry.name)); } return 0; } /* Add a block to the hash table given a pointer to the block and its index. The block is threaded onto both hash tables and written to disk. The routine returns zero if there were no errors. */ -int ThreadVLentry (trans, blockindex, tentry) -struct ubik_trans *trans; -afs_int32 blockindex; -struct nvlentry *tentry; -{ int errorcode; +int +ThreadVLentry(trans, blockindex, tentry) + struct ubik_trans *trans; + afs_int32 blockindex; + struct nvlentry *tentry; +{ + int errorcode; - if (!index_OK(trans, blockindex)) return VL_BADINDEX; + if (!index_OK(trans, blockindex)) + return VL_BADINDEX; /* Insert into volid's hash linked list */ if (errorcode = HashVolid(trans, RWVOL, blockindex, tentry)) return errorcode; @@ -665,32 +752,37 @@ struct nvlentry *tentry; if (tentry->volumeId[ROVOL]) { if (errorcode = HashVolid(trans, ROVOL, blockindex, tentry)) return errorcode; - } + } if (tentry->volumeId[BACKVOL]) { if (errorcode = HashVolid(trans, BACKVOL, blockindex, tentry)) return errorcode; - } - + } + /* Insert into volname's hash linked list */ HashVolname(trans, blockindex, tentry); /* Update cheader entry */ - if (write_vital_vlheader(trans)) return VL_IO; + if (write_vital_vlheader(trans)) + return VL_IO; /* Update hash list pointers in the entry itself */ - if (vlentrywrite(trans, blockindex, (char *)tentry, sizeof(nvlentry))) return VL_IO; + if (vlentrywrite(trans, blockindex, (char *)tentry, sizeof(nvlentry))) + return VL_IO; return 0; } /* Remove a block from both the hash tables. If success return 0, else return an error code. */ -int UnthreadVLentry (trans, blockindex, aentry) -struct ubik_trans *trans; -afs_int32 blockindex; -struct nvlentry *aentry; -{ register afs_int32 errorcode, typeindex; +int +UnthreadVLentry(trans, blockindex, aentry) + struct ubik_trans *trans; + afs_int32 blockindex; + struct nvlentry *aentry; +{ + register afs_int32 errorcode, typeindex; - if (!index_OK(trans, blockindex)) return VL_BADINDEX; + if (!index_OK(trans, blockindex)) + return VL_BADINDEX; if (errorcode = UnhashVolid(trans, RWVOL, blockindex, aentry)) return errorcode; @@ -711,32 +803,42 @@ struct nvlentry *aentry; } /* cheader must have be read before this routine is called. */ -int HashVolid(trans, voltype, blockindex, tentry) -struct ubik_trans *trans; -afs_int32 voltype; -afs_int32 blockindex; -struct nvlentry *tentry; -{ afs_int32 hashindex, errorcode; +int +HashVolid(trans, voltype, blockindex, tentry) + struct ubik_trans *trans; + afs_int32 voltype; + afs_int32 blockindex; + struct nvlentry *tentry; +{ + afs_int32 hashindex, errorcode; struct vlentry ventry; - if (FindByID(trans, tentry->volumeId[voltype], voltype, &ventry, &errorcode)) + if (FindByID + (trans, tentry->volumeId[voltype], voltype, &ventry, &errorcode)) return VL_IDALREADYHASHED; - else if (errorcode) return errorcode; + else if (errorcode) + return errorcode; hashindex = IDHash(tentry->volumeId[voltype]); - tentry->nextIdHash[voltype] = ntohl(cheader.VolidHash[voltype][hashindex]); + tentry->nextIdHash[voltype] = + ntohl(cheader.VolidHash[voltype][hashindex]); cheader.VolidHash[voltype][hashindex] = htonl(blockindex); - if (vlwrite(trans, DOFFSET(0, &cheader, &cheader.VolidHash[voltype][hashindex]), (char *) &cheader.VolidHash[voltype][hashindex], sizeof(afs_int32))) return VL_IO; + if (vlwrite + (trans, DOFFSET(0, &cheader, &cheader.VolidHash[voltype][hashindex]), + (char *)&cheader.VolidHash[voltype][hashindex], sizeof(afs_int32))) + return VL_IO; return 0; } /* cheader must have be read before this routine is called. */ -int UnhashVolid(trans, voltype, blockindex, aentry) -struct ubik_trans *trans; -afs_int32 voltype; -afs_int32 blockindex; -struct nvlentry *aentry; -{ int hashindex, nextblockindex, prevblockindex; +int +UnhashVolid(trans, voltype, blockindex, aentry) + struct ubik_trans *trans; + afs_int32 voltype; + afs_int32 blockindex; + struct nvlentry *aentry; +{ + int hashindex, nextblockindex, prevblockindex; struct nvlentry tentry; afs_int32 code; afs_int32 temp; @@ -748,20 +850,31 @@ struct nvlentry *aentry; nextblockindex = ntohl(cheader.VolidHash[voltype][hashindex]); if (nextblockindex == blockindex) { /* First on the hash list; just adjust pointers */ - cheader.VolidHash[voltype][hashindex] = htonl(aentry->nextIdHash[voltype]); - code = vlwrite(trans, DOFFSET(0, &cheader, &cheader.VolidHash[voltype][hashindex]), (char *) &cheader.VolidHash[voltype][hashindex], sizeof(afs_int32)); - if (code) return VL_IO; + cheader.VolidHash[voltype][hashindex] = + htonl(aentry->nextIdHash[voltype]); + code = + vlwrite(trans, + DOFFSET(0, &cheader, + &cheader.VolidHash[voltype][hashindex]), + (char *)&cheader.VolidHash[voltype][hashindex], + sizeof(afs_int32)); + if (code) + return VL_IO; } else { while (nextblockindex != blockindex) { prevblockindex = nextblockindex; /* always done once */ - if (vlentryread(trans, nextblockindex, (char *)&tentry, sizeof(nvlentry))) + if (vlentryread + (trans, nextblockindex, (char *)&tentry, sizeof(nvlentry))) return VL_IO; if ((nextblockindex = tentry.nextIdHash[voltype]) == NULLO) return VL_NOENT; } temp = tentry.nextIdHash[voltype] = aentry->nextIdHash[voltype]; temp = htonl(temp); /* convert to network byte order before writing */ - if (vlwrite(trans, DOFFSET(prevblockindex, &tentry, &tentry.nextIdHash[voltype]), (char *)&temp, sizeof(afs_int32))) + if (vlwrite + (trans, + DOFFSET(prevblockindex, &tentry, &tentry.nextIdHash[voltype]), + (char *)&temp, sizeof(afs_int32))) return VL_IO; } aentry->nextIdHash[voltype] = 0; @@ -769,29 +882,36 @@ struct nvlentry *aentry; } -int HashVolname(trans, blockindex, aentry) -struct ubik_trans *trans; -afs_int32 blockindex; -struct nvlentry *aentry; -{ register afs_int32 hashindex; +int +HashVolname(trans, blockindex, aentry) + struct ubik_trans *trans; + afs_int32 blockindex; + struct nvlentry *aentry; +{ + register afs_int32 hashindex; register afs_int32 code; /* Insert into volname's hash linked list */ hashindex = NameHash(aentry->name); aentry->nextNameHash = ntohl(cheader.VolnameHash[hashindex]); cheader.VolnameHash[hashindex] = htonl(blockindex); - code = vlwrite(trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]), (char *) &cheader.VolnameHash[hashindex], sizeof(afs_int32)); - if (code) return VL_IO; + code = + vlwrite(trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]), + (char *)&cheader.VolnameHash[hashindex], sizeof(afs_int32)); + if (code) + return VL_IO; return 0; } -int UnhashVolname(trans, blockindex, aentry) -struct ubik_trans *trans; -afs_int32 blockindex; -struct nvlentry *aentry; -{ register afs_int32 hashindex, nextblockindex, prevblockindex; - struct nvlentry tentry; +int +UnhashVolname(trans, blockindex, aentry) + struct ubik_trans *trans; + afs_int32 blockindex; + struct nvlentry *aentry; +{ + register afs_int32 hashindex, nextblockindex, prevblockindex; + struct nvlentry tentry; afs_int32 temp; /* Take it out of the Volname hash list */ @@ -800,18 +920,24 @@ struct nvlentry *aentry; if (nextblockindex == blockindex) { /* First on the hash list; just adjust pointers */ cheader.VolnameHash[hashindex] = htonl(aentry->nextNameHash); - if (vlwrite(trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]), (char *) &cheader.VolnameHash[hashindex], sizeof(afs_int32))) return VL_IO; + if (vlwrite + (trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]), + (char *)&cheader.VolnameHash[hashindex], sizeof(afs_int32))) + return VL_IO; } else { while (nextblockindex != blockindex) { prevblockindex = nextblockindex; /* always done at least once */ - if (vlentryread(trans, nextblockindex, (char *)&tentry, sizeof(nvlentry))) + if (vlentryread + (trans, nextblockindex, (char *)&tentry, sizeof(nvlentry))) return VL_IO; if ((nextblockindex = tentry.nextNameHash) == NULLO) return VL_NOENT; } tentry.nextNameHash = aentry->nextNameHash; temp = htonl(tentry.nextNameHash); - if (vlwrite(trans, DOFFSET(prevblockindex, &tentry, &tentry.nextNameHash), (char *)&temp, sizeof(afs_int32))) + if (vlwrite + (trans, DOFFSET(prevblockindex, &tentry, &tentry.nextNameHash), + (char *)&temp, sizeof(afs_int32))) return VL_IO; } aentry->nextNameHash = 0; @@ -821,24 +947,27 @@ struct nvlentry *aentry; /* Returns the vldb entry tentry at offset index; remaining is the number of entries left; the routine also returns the index of the next sequential entry in the vldb */ -afs_int32 NextEntry (trans, blockindex, tentry, remaining) -struct ubik_trans *trans; -afs_int32 blockindex; -struct nvlentry *tentry; -afs_int32 *remaining; -{ register afs_int32 lastblockindex; +afs_int32 +NextEntry(trans, blockindex, tentry, remaining) + struct ubik_trans *trans; + afs_int32 blockindex; + struct nvlentry *tentry; + afs_int32 *remaining; +{ + register afs_int32 lastblockindex; - if (blockindex == 0) /* get first one */ + if (blockindex == 0) /* get first one */ blockindex = sizeof(cheader); else { - if (!index_OK (trans, blockindex)) { - *remaining = -1; /* error */ + if (!index_OK(trans, blockindex)) { + *remaining = -1; /* error */ return 0; } blockindex += sizeof(nvlentry); } /* now search for the first entry that isn't free */ - for (lastblockindex = ntohl(cheader.vital_header.eofPtr); blockindex < lastblockindex;) { + for (lastblockindex = ntohl(cheader.vital_header.eofPtr); + blockindex < lastblockindex;) { if (vlentryread(trans, blockindex, (char *)tentry, sizeof(nvlentry))) { *remaining = -1; return 0; @@ -851,25 +980,26 @@ afs_int32 *remaining; } else { if (tentry->flags != VLFREE) { /* estimate remaining number of entries, not including this one */ - *remaining = (lastblockindex - blockindex) / sizeof(nvlentry) - 1; + *remaining = + (lastblockindex - blockindex) / sizeof(nvlentry) - 1; return blockindex; } blockindex += sizeof(nvlentry); } } - *remaining = 0; /* no more entries */ + *remaining = 0; /* no more entries */ return 0; } /* Routine to verify that index is a legal offset to a vldb entry in the table */ -static int index_OK (trans, blockindex) -struct ubik_trans *trans; -afs_int32 blockindex; +static int +index_OK(trans, blockindex) + struct ubik_trans *trans; + afs_int32 blockindex; { - if ((blockindex < sizeof(cheader)) || (blockindex >= ntohl(cheader.vital_header.eofPtr))) + if ((blockindex < sizeof(cheader)) + || (blockindex >= ntohl(cheader.vital_header.eofPtr))) return 0; return 1; } - - diff --git a/src/vol/Makefile.in b/src/vol/Makefile.in index e02c96f23..278d0013e 100644 --- a/src/vol/Makefile.in +++ b/src/vol/Makefile.in @@ -7,46 +7,25 @@ # # Portions Copyright (c) 2003 Apple Computer, Inc. -DEST=@DEST@ -TOP_INCDIR=@TOP_INCDIR@ -TOP_LIBDIR=@TOP_LIBDIR@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ -libexecdir=@libexecdir@ -libdir=@libdir@ -includedir=@includedir@ -mandir=@mandir@ -afssrvbindir=@afssrvbindir@ -afssrvsbindir=@afssrvsbindir@ -afssrvlibexecdir=@afssrvlibexecdir@ -COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et -RXGEN=${TOP_SRCDIR}/rxgen/rxgen -TOP_SRCDIR=@TOP_SRCDIR@ -SYS_NAME=@AFS_SYSNAME@ - -SHELL=/bin/sh - -include ../config/Makefile.${SYS_NAME} - -INCDIRS=-I${TOP_SRCDIR}/config -I. -I${TOP_INCDIR} ${FSINCLUDES} -LDFLAGS = ${OPTMZ} ${PROF} ${LDIRS} ${XLDFLAGS} +srcdir=@srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config +HELPER_SPLINT=@HELPER_SPLINT@ + LIBS=${TOP_LIBDIR}/libcmd.a vlib.a ${TOP_LIBDIR}/util.a \ ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libdir.a \ ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libacl.a -CFLAGS = -D${SYS_NAME} ${OPTMZ} ${INCDIRS} ${XCFLAGS} ${DBG} +CFLAGS = ${COMMON_CFLAGS} -D${SYS_NAME} ${FSINCLUDES} ${XCFLAGS} PUBLICHEADERS=nfs.h vnode.h viceinode.h volume.h voldefs.h partition.h\ fssync.h ihandle.h namei_ops.h VLIBOBJS=vnode.o volume.o vutil.o partition.o fssync.o purge.o \ clone.o nuke.o devname.o listinodes.o common.o ihandle.o \ - namei_ops.o ${EXTRA_VLIBOBJS} + namei_ops.o fstab.o -OBJECTS=${VLIBOBJS} physio.o vol-salvage.o vol-info.o +OBJECTS=${VLIBOBJS} physio.o vol-salvage.o vol-info.o vol-dump.o all: gi \ ${TOP_LIBDIR}/vlib.a \ @@ -166,31 +145,24 @@ vol-info: vol-info.o physio.o ihandle.o listinodes.o: listinodes.c AFS_component_version_number.c case ${SYS_NAME} in \ hp?00_ux101 | hp_ux10? ) \ - ${CC} ${CFLAGS} -D_FILE64 -c listinodes.c \ + ${CC} ${CFLAGS} -D_FILE64 -c ${srcdir}/listinodes.c \ ;; \ - * ) ${CC} ${CFLAGS} -c listinodes.c \ + * ) ${CC} ${CFLAGS} -c ${srcdir}/listinodes.c \ ;; \ esac -gi: ${TOP_LIBDIR}/libsys.a +gi: ${TOP_LIBDIR}/libsys.a case ${SYS_NAME} in \ *linux* | sgi_* | *fbsd* ) \ echo "Don't build gi on ${SYS_NAME}";; \ *) \ - ${CC} ${CFLAGS} -c gi.c ; \ + ${CC} ${CFLAGS} -c ${srcdir}/gi.c ; \ ${CC} ${LDFLAGS} -o gi gi.o ${TOP_LIBDIR}/libsys.a;; \ esac -volinfo: vol-info.o physio.o ihandle.o - case ${SYS_NAME} in \ - *linux* | *fbsd*) \ - ${CC} ${CFLAGS} ${DBG} -o volinfo vol-info.o physio.o \ - ihandle.o ${LIBS} ${XLIBS} ;; \ - *) \ - ${CC} ${CFLAGS} ${DBG} -o volinfo vol-info.o physio.o \ - ihandle.o ${LIBS} ${XLIBS} ;; \ - esac - +volinfo: vol-info.o physio.o ihandle.o fstab.o ${LIBS} + ${CC} ${CFLAGS} -o volinfo vol-info.o physio.o \ + ihandle.o fstab.o ${LIBS} ${XLIBS} fs_conv_dux40D: fs_conv_411.o ${CC} ${CFLAGS} ${TOP_LIBDIR}/libcmd.a -o fs_conv_dux40D fs_conv_411.o ${LIBS} ${XLIBS} @@ -199,10 +171,10 @@ fs_conv_sol26: fs_conv_411.o vlib.a ${CC} ${CFLAGS} ${TOP_LIBDIR}/libcmd.a -o fs_conv_sol26 fs_conv_411.o ${LIBS} ${XLIBS} fs_conv_411.o: fs_conv_411.c AFS_component_version_number.c - ${CC} ${CFLAGS} -c fs_conv_411.c + ${CC} ${CFLAGS} -c ${srcdir}/fs_conv_411.c xfs_size_check: xfs_size_check.c - ${CC} ${CFLAGS} -o xfs_size_check xfs_size_check.c + ${CC} ${CFLAGS} -o xfs_size_check ${srcdir}/xfs_size_check.c # # Misc. targets @@ -305,3 +277,9 @@ dest: \ ${DEST}/include/afs/ihandle.h \ ${DEST}/include/afs/namei_ops.h +check-splint:: + sh $(HELPER_SPLINT) $(CFLAGS) \ + vnode.c volume.c vutil.c partition.c fssync.c purge.c \ + clone.c nuke.c devname.c listinodes.c common.c ihandle.c \ + namei_ops.c \ + physio.c vol-salvage.c vol-info.c diff --git a/src/vol/NTMakefile b/src/vol/NTMakefile index 3d577ae49..0b966f23f 100644 --- a/src/vol/NTMakefile +++ b/src/vol/NTMakefile @@ -5,6 +5,7 @@ # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html +RELDIR=vol !INCLUDE ..\config\NTMakefile.$(SYS_NAME) !INCLUDE ..\config\NTMakefile.version @@ -32,18 +33,18 @@ INCFILES =\ LIBFILE = $(DESTDIR)\lib\afs\afsvol.lib LIBOBJS =\ - common.obj \ - clone.obj \ - fssync.obj \ - ntops.obj \ - nuke.obj \ - partition.obj \ - purge.obj \ - vnode.obj \ - volume.obj \ - vutil.obj \ - ihandle.obj \ - AFS_component_version_number.obj + $(OUT)\common.obj \ + $(OUT)\clone.obj \ + $(OUT)\fssync.obj \ + $(OUT)\ntops.obj \ + $(OUT)\nuke.obj \ + $(OUT)\partition.obj \ + $(OUT)\purge.obj \ + $(OUT)\vnode.obj \ + $(OUT)\volume.obj \ + $(OUT)\vutil.obj \ + $(OUT)\ihandle.obj \ + $(OUT)\AFS_component_version_number.obj $(LIBFILE): $(LIBOBJS) $(LIBARCH) @@ -70,10 +71,10 @@ EXEC_LIBS = \ SALVAGER = $(DESTDIR)\root.server\usr\afs\bin\salvager.exe SALVAGER_EXEOBJS =\ - vol-salvage.obj \ - physio.obj \ - AFS_component_version_number.obj \ - salvager.res + $(OUT)\vol-salvage.obj \ + $(OUT)\physio.obj \ + $(OUT)\AFS_component_version_number.obj \ + $(OUT)\salvager.res $(SALVAGER): $(SALVAGER_EXEOBJS) $(EXEC_LIBS) $(EXECONLINK) @@ -84,16 +85,19 @@ $(SALVAGER): $(SALVAGER_EXEOBJS) $(EXEC_LIBS) # build volinfo VOLINFO = $(DESTDIR)\root.server\usr\afs\bin\volinfo.exe -$(VOLINFO): vol-info.obj physio.obj volinfo.res $(EXEC_LIBS) +$(VOLINFO): $(OUT)\vol-info.obj $(OUT)\physio.obj $(OUT)\volinfo.res $(EXEC_LIBS) $(EXECONLINK) $(EXEPREP) ############################################################################ # generate versioninfo resources -salvager.res: salvager.rc AFS_component_version_number.h +$(OUT)\salvager.res: salvager.rc AFS_component_version_number.h -volinfo.res: volinfo.rc AFS_component_version_number.h +$(OUT)\volinfo.res: AFS_component_version_number.h ############################################################################ # Install targets install: $(INCFILES) $(LIBFILE) $(SALVAGER) $(VOLINFO) + +mkdir: + diff --git a/src/vol/clone.c b/src/vol/clone.c index 17bc7551b..6851e6799 100644 --- a/src/vol/clone.c +++ b/src/vol/clone.c @@ -18,7 +18,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/clone.c,v 1.1.1.8 2003/04/13 19:08:16 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/clone.c,v 1.17 2003/08/08 20:40:45 shadow Exp $"); #include #include @@ -37,6 +38,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/clone.c,v 1.1.1.8 2003/04/13 19:08: #include #include #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include #include @@ -52,7 +60,9 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/clone.c,v 1.1.1.8 2003/04/13 19:08: #include "partition.h" #include "viceinode.h" -int (*vol_PollProc)() = 0; /* someone must init this */ +/*@printflike@*/ extern void Log(const char *format, ...); + +int (*vol_PollProc) () = 0; /* someone must init this */ #define ERROR_EXIT(code) {error = code; goto error_exit;} @@ -61,7 +71,7 @@ int (*vol_PollProc)() = 0; /* someone must init this */ */ struct clone_rock { IHandle_t *h; - afs_int32 vol; + VolId vol; }; #define CLONE_MAXITEMS 100 @@ -79,26 +89,29 @@ struct clone_head { void CloneVolume(); void CloneVolume_r(); -static ci_AddItem(ah, aino) -Inode aino; -struct clone_head *ah; { +static int +ci_AddItem(struct clone_head *ah, Inode aino) +{ register struct clone_items *ti; /* if no last elt (first call) or last item full, get a new one */ if ((!ah->last) || ah->last->nitems >= CLONE_MAXITEMS) { - ti = (struct clone_items *) malloc(sizeof(struct clone_items)); + ti = (struct clone_items *)malloc(sizeof(struct clone_items)); + if (!ti) { + Log("ci_AddItem: malloc failed\n"); + assert(0); + } ti->nitems = 0; - ti->next = (struct clone_items *) 0; + ti->next = (struct clone_items *)0; if (ah->last) { ah->last->next = ti; ah->last = ti; - } - else { + } else { /* first dude in the list */ ah->first = ah->last = ti; } - } - else ti = ah->last; + } else + ti = ah->last; /* now ti points to the end of the list, to a clone_item with room * for at least one more element. Add it. @@ -108,288 +121,310 @@ struct clone_head *ah; { } /* initialize a clone header */ -int ci_InitHead(struct clone_head *ah) +int +ci_InitHead(struct clone_head *ah) { memset(ah, 0, sizeof(*ah)); return 0; } /* apply a function to all dudes in the set */ -int ci_Apply(struct clone_head *ah, int (*aproc)(), char *arock) +int +ci_Apply(struct clone_head *ah, int (*aproc) (), char *arock) { register struct clone_items *ti; register int i; - for(ti=ah->first; ti; ti=ti->next) { - for(i=0; initems; i++) { - (*aproc)(ti->data[i], arock); + for (ti = ah->first; ti; ti = ti->next) { + for (i = 0; i < ti->nitems; i++) { + (*aproc) (ti->data[i], arock); } } return 0; } /* free all dudes in the list */ -int ci_Destroy(struct clone_head *ah) +int +ci_Destroy(struct clone_head *ah) { register struct clone_items *ti, *ni; - for(ti=ah->first; ti; ti=ni) { - ni = ti->next; /* guard against freeing */ + for (ti = ah->first; ti; ti = ni) { + ni = ti->next; /* guard against freeing */ free(ti); } return 0; } -static IDecProc(adata, aparm) -Inode adata; -struct clone_rock *aparm; { +static int +IDecProc(Inode adata, struct clone_rock *aparm) +{ IH_DEC(aparm->h, adata, aparm->vol); DOPOLL; return 0; } -afs_int32 DoCloneIndex(rwvp, clvp, class, reclone) - Volume *rwvp; /* The RW volume */ - Volume *clvp; /* The cloned volume */ - VnodeClass class; - int reclone; /* Whether to reclone or not */ +afs_int32 +DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) { - afs_int32 code, error=0; - FdHandle_t *rwFd=0, *clFdIn=0, *clFdOut=0; - StreamHandle_t *rwfile=0, *clfilein=0, *clfileout=0; - IHandle_t *rwH=0, *clHin=0, *clHout=0; - char buf[SIZEOF_LARGEDISKVNODE], dbuf[SIZEOF_LARGEDISKVNODE]; - struct VnodeDiskObject *rwvnode = (struct VnodeDiskObject *) buf; - struct VnodeDiskObject *clvnode = (struct VnodeDiskObject *) dbuf; - Inode rwinode, clinode; - struct clone_head decHead; - struct clone_rock decRock; - afs_int32 offset, dircloned, inodeinced; - - struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; - int ReadWriteOriginal = VolumeWriteable(rwvp); - struct DiskPartition *partition = rwvp->partition; - Device device = rwvp->device; - - /* Open the RW volume's index file and seek to beginning */ - IH_COPY(rwH, rwvp->vnodeIndex[class].handle); - rwFd = IH_OPEN(rwH); - if (!rwFd) ERROR_EXIT(EIO); - rwfile = FDH_FDOPEN(rwFd, ReadWriteOriginal? "r+":"r"); - if (!rwfile) ERROR_EXIT(EIO); - STREAM_SEEK(rwfile, vcp->diskSize, 0); /* Will fail if no vnodes */ - - /* Open the clone volume's index file and seek to beginning */ - IH_COPY(clHout, clvp->vnodeIndex[class].handle); - clFdOut = IH_OPEN(clHout); - if (!clFdOut) ERROR_EXIT(EIO); - clfileout = FDH_FDOPEN(clFdOut, "a"); - if (!clfileout) ERROR_EXIT(EIO); - code = STREAM_SEEK(clfileout, vcp->diskSize, 0); - if (code) ERROR_EXIT(EIO); - - /* If recloning, open the new volume's index; this time for - * reading. We never read anything that we're simultaneously - * writing, so this all works. - */ - if (reclone) { - IH_COPY(clHin, clvp->vnodeIndex[class].handle); - clFdIn = IH_OPEN(clHin); - if (!clFdIn) ERROR_EXIT(EIO); - clfilein = FDH_FDOPEN(clFdIn, "r"); - if (!clfilein) ERROR_EXIT(EIO); - STREAM_SEEK(clfilein, vcp->diskSize, 0); /* Will fail if no vnodes */ - } - - /* Initialize list of inodes to nuke */ - ci_InitHead(&decHead); - decRock.h = V_linkHandle(rwvp); - decRock.vol = V_parentId(rwvp); - - /* Read each vnode in the old volume's index file */ - for (offset=vcp->diskSize; - STREAM_READ(rwvnode,vcp->diskSize,1,rwfile) == 1; - offset+=vcp->diskSize) { - dircloned = inodeinced = 0; - - /* If we are recloning the volume, read the corresponding vnode - * from the clone and determine its inode number. - */ - if ( reclone && !STREAM_EOF(clfilein) && - (STREAM_READ(clvnode, vcp->diskSize, 1, clfilein) == 1) ) { - clinode = VNDISK_GET_INO(clvnode); - } else { - clinode = 0; - } - - if (rwvnode->type != vNull) { - if (rwvnode->vnodeMagic != vcp->magic) ERROR_EXIT(-1); - rwinode = VNDISK_GET_INO(rwvnode); - - /* Increment the inode if not already */ - if (clinode && (clinode == rwinode)) { - clinode = 0; /* already cloned - don't delete later */ - } else if (rwinode) { - if (IH_INC(V_linkHandle(rwvp), rwinode, V_parentId(rwvp)) == -1) { - Log("IH_INC failed: %x, %s, %d errno %d\n", - V_linkHandle(rwvp), PrintInode(NULL, rwinode), - V_parentId(rwvp), errno); - assert(0); - } - inodeinced = 1; - } - - /* If a directory, mark vnode in old volume as cloned */ - if ((rwvnode->type == vDirectory) && ReadWriteOriginal) { + afs_int32 code, error = 0; + FdHandle_t *rwFd = 0, *clFdIn = 0, *clFdOut = 0; + StreamHandle_t *rwfile = 0, *clfilein = 0, *clfileout = 0; + IHandle_t *rwH = 0, *clHin = 0, *clHout = 0; + char buf[SIZEOF_LARGEDISKVNODE], dbuf[SIZEOF_LARGEDISKVNODE]; + struct VnodeDiskObject *rwvnode = (struct VnodeDiskObject *)buf; + struct VnodeDiskObject *clvnode = (struct VnodeDiskObject *)dbuf; + Inode rwinode, clinode; + struct clone_head decHead; + struct clone_rock decRock; + afs_int32 offset, dircloned, inodeinced; + + struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; + int ReadWriteOriginal = VolumeWriteable(rwvp); + struct DiskPartition *partition = rwvp->partition; + Device device = rwvp->device; + + /* Open the RW volume's index file and seek to beginning */ + IH_COPY(rwH, rwvp->vnodeIndex[class].handle); + rwFd = IH_OPEN(rwH); + if (!rwFd) + ERROR_EXIT(EIO); + rwfile = FDH_FDOPEN(rwFd, ReadWriteOriginal ? "r+" : "r"); + if (!rwfile) + ERROR_EXIT(EIO); + STREAM_SEEK(rwfile, vcp->diskSize, 0); /* Will fail if no vnodes */ + + /* Open the clone volume's index file and seek to beginning */ + IH_COPY(clHout, clvp->vnodeIndex[class].handle); + clFdOut = IH_OPEN(clHout); + if (!clFdOut) + ERROR_EXIT(EIO); + clfileout = FDH_FDOPEN(clFdOut, "a"); + if (!clfileout) + ERROR_EXIT(EIO); + code = STREAM_SEEK(clfileout, vcp->diskSize, 0); + if (code) + ERROR_EXIT(EIO); + + /* If recloning, open the new volume's index; this time for + * reading. We never read anything that we're simultaneously + * writing, so this all works. + */ + if (reclone) { + IH_COPY(clHin, clvp->vnodeIndex[class].handle); + clFdIn = IH_OPEN(clHin); + if (!clFdIn) + ERROR_EXIT(EIO); + clfilein = FDH_FDOPEN(clFdIn, "r"); + if (!clfilein) + ERROR_EXIT(EIO); + STREAM_SEEK(clfilein, vcp->diskSize, 0); /* Will fail if no vnodes */ + } + + /* Initialize list of inodes to nuke */ + ci_InitHead(&decHead); + decRock.h = V_linkHandle(rwvp); + decRock.vol = V_parentId(rwvp); + + /* Read each vnode in the old volume's index file */ + for (offset = vcp->diskSize; + STREAM_READ(rwvnode, vcp->diskSize, 1, rwfile) == 1; + offset += vcp->diskSize) { + dircloned = inodeinced = 0; + + /* If we are recloning the volume, read the corresponding vnode + * from the clone and determine its inode number. + */ + if (reclone && !STREAM_EOF(clfilein) + && (STREAM_READ(clvnode, vcp->diskSize, 1, clfilein) == 1)) { + clinode = VNDISK_GET_INO(clvnode); + } else { + clinode = 0; + } + + if (rwvnode->type != vNull) { + if (rwvnode->vnodeMagic != vcp->magic) + ERROR_EXIT(-1); + rwinode = VNDISK_GET_INO(rwvnode); + + /* Increment the inode if not already */ + if (clinode && (clinode == rwinode)) { + clinode = 0; /* already cloned - don't delete later */ + } else if (rwinode) { + if (IH_INC(V_linkHandle(rwvp), rwinode, V_parentId(rwvp)) == + -1) { + Log("IH_INC failed: %x, %s, %u errno %d\n", + V_linkHandle(rwvp), PrintInode(NULL, rwinode), + V_parentId(rwvp), errno); + assert(0); + } + inodeinced = 1; + } + + /* If a directory, mark vnode in old volume as cloned */ + if ((rwvnode->type == vDirectory) && ReadWriteOriginal) { #ifdef DVINC - /* - * It is my firmly held belief that immediately after - * copy-on-write, the two directories can be identical. - * If the new copy is changed (presumably, that is the very - * next thing that will happen) then the dataVersion will - * get bumped. - */ - /* NOTE: the dataVersion++ is incredibly important!!!. - This will cause the inode created by the file server - on copy-on-write to be stamped with a dataVersion bigger - than the current one. The salvager will then do the - right thing */ - rwvnode->dataVersion++; + /* + * It is my firmly held belief that immediately after + * copy-on-write, the two directories can be identical. + * If the new copy is changed (presumably, that is the very + * next thing that will happen) then the dataVersion will + * get bumped. + */ + /* NOTE: the dataVersion++ is incredibly important!!!. + * This will cause the inode created by the file server + * on copy-on-write to be stamped with a dataVersion bigger + * than the current one. The salvager will then do the + * right thing */ + rwvnode->dataVersion++; #endif /* DVINC */ - rwvnode->cloned = 1; - code = STREAM_SEEK(rwfile, offset, 0); - if (code == -1) goto clonefailed; - code = STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile); - if (code != 1) goto clonefailed; - dircloned = 1; - code = STREAM_SEEK(rwfile, offset + vcp->diskSize, 0); - if (code == -1) goto clonefailed; + rwvnode->cloned = 1; + code = STREAM_SEEK(rwfile, offset, 0); + if (code == -1) + goto clonefailed; + code = STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile); + if (code != 1) + goto clonefailed; + dircloned = 1; + code = STREAM_SEEK(rwfile, offset + vcp->diskSize, 0); + if (code == -1) + goto clonefailed; #ifdef DVINC - rwvnode->dataVersion--; /* Really needs to be set to the value in the inode, - for the read-only volume */ + rwvnode->dataVersion--; /* Really needs to be set to the value in the inode, + * for the read-only volume */ #endif /* DVINC */ - } - } - - /* Overwrite the vnode etnry in the clone volume */ - rwvnode->cloned = 0; - code = STREAM_WRITE(rwvnode, vcp->diskSize, 1, clfileout); - if (code != 1) { - clonefailed: - /* Couldn't clone, go back and decrement the inode's link count */ - if (inodeinced) { - if (IH_DEC(V_linkHandle(rwvp), rwinode, V_parentId(rwvp)) == -1) { - Log("IH_DEC failed: %x, %s, %d errno %d\n", - V_linkHandle(rwvp), PrintInode(NULL, rwinode), - V_parentId(rwvp), errno); - assert(0); - } - } - /* And if the directory was marked clone, unmark it */ - if (dircloned) { - rwvnode->cloned = 0; - if (STREAM_SEEK(rwfile, offset, 0) != -1) - STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile); - } - ERROR_EXIT(EIO); - } - - /* Removal of the old cloned inode */ - if (clinode) { - ci_AddItem(&decHead, clinode); /* just queue it */ - } - - DOPOLL; - } - if (STREAM_ERROR(clfileout)) ERROR_EXIT(EIO); - - /* Clean out any junk at end of clone file */ - if (reclone) { - STREAM_SEEK(clfilein, offset, 0); - while (STREAM_READ(clvnode, vcp->diskSize, 1, clfilein) == 1) { - if (clvnode->type != vNull && VNDISK_GET_INO(clvnode) != 0) { - ci_AddItem(&decHead, VNDISK_GET_INO(clvnode)); - } - DOPOLL; - } - } - - /* come here to finish up. If code is non-zero, we've already run into problems, - * and shouldn't do the idecs. - */ - error_exit: - if (rwfile) STREAM_CLOSE(rwfile); - if (clfilein) STREAM_CLOSE(clfilein); - if (clfileout) STREAM_CLOSE(clfileout); - - if (rwFd) FDH_CLOSE(rwFd); - if (clFdIn) FDH_CLOSE(clFdIn); - if (clFdOut) FDH_CLOSE(clFdOut); - - if (rwH) IH_RELEASE(rwH); - if (clHout) IH_RELEASE(clHout); - if (clHin) IH_RELEASE(clHin); - - /* Next, we sync the disk. We have to reopen in case we're truncating, - * since we were using stdio above, and don't know when the buffers - * would otherwise be flushed. There's no stdio fftruncate call. - */ - rwFd = IH_OPEN(clvp->vnodeIndex[class].handle); - if (rwFd == NULL) { - if (!error) error = EIO; - } else { - if (reclone) { - /* If doing a reclone, we're keeping the clone. We need to - * truncate the file to offset bytes. - */ - if (reclone && !error) { - error = FDH_TRUNC(rwFd, offset); - } - } - FDH_SYNC(rwFd); - FDH_CLOSE(rwFd); - } - - /* Now finally do the idec's. At this point, all potential - * references have been cleaned up and sent to the disk - * (see above fclose and fsync). No matter what happens, we - * no longer need to keep these references around. - */ - code = ci_Apply(&decHead, IDecProc, (char *) &decRock); - if (!error) error = code; - ci_Destroy(&decHead); - - return error; + } + } + + /* Overwrite the vnode entry in the clone volume */ + rwvnode->cloned = 0; + code = STREAM_WRITE(rwvnode, vcp->diskSize, 1, clfileout); + if (code != 1) { + clonefailed: + /* Couldn't clone, go back and decrement the inode's link count */ + if (inodeinced) { + if (IH_DEC(V_linkHandle(rwvp), rwinode, V_parentId(rwvp)) == + -1) { + Log("IH_DEC failed: %x, %s, %u errno %d\n", + V_linkHandle(rwvp), PrintInode(NULL, rwinode), + V_parentId(rwvp), errno); + assert(0); + } + } + /* And if the directory was marked clone, unmark it */ + if (dircloned) { + rwvnode->cloned = 0; + if (STREAM_SEEK(rwfile, offset, 0) != -1) + (void)STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile); + } + ERROR_EXIT(EIO); + } + + /* Removal of the old cloned inode */ + if (clinode) { + ci_AddItem(&decHead, clinode); /* just queue it */ + } + + DOPOLL; + } + if (STREAM_ERROR(clfileout)) + ERROR_EXIT(EIO); + + /* Clean out any junk at end of clone file */ + if (reclone) { + STREAM_SEEK(clfilein, offset, 0); + while (STREAM_READ(clvnode, vcp->diskSize, 1, clfilein) == 1) { + if (clvnode->type != vNull && VNDISK_GET_INO(clvnode) != 0) { + ci_AddItem(&decHead, VNDISK_GET_INO(clvnode)); + } + DOPOLL; + } + } + + /* come here to finish up. If code is non-zero, we've already run into problems, + * and shouldn't do the idecs. + */ + error_exit: + if (rwfile) + STREAM_CLOSE(rwfile); + if (clfilein) + STREAM_CLOSE(clfilein); + if (clfileout) + STREAM_CLOSE(clfileout); + + if (rwFd) + FDH_CLOSE(rwFd); + if (clFdIn) + FDH_CLOSE(clFdIn); + if (clFdOut) + FDH_CLOSE(clFdOut); + + if (rwH) + IH_RELEASE(rwH); + if (clHout) + IH_RELEASE(clHout); + if (clHin) + IH_RELEASE(clHin); + + /* Next, we sync the disk. We have to reopen in case we're truncating, + * since we were using stdio above, and don't know when the buffers + * would otherwise be flushed. There's no stdio fftruncate call. + */ + rwFd = IH_OPEN(clvp->vnodeIndex[class].handle); + if (rwFd == NULL) { + if (!error) + error = EIO; + } else { + if (reclone) { + /* If doing a reclone, we're keeping the clone. We need to + * truncate the file to offset bytes. + */ + if (reclone && !error) { + error = FDH_TRUNC(rwFd, offset); + } + } + FDH_SYNC(rwFd); + FDH_CLOSE(rwFd); + } + + /* Now finally do the idec's. At this point, all potential + * references have been cleaned up and sent to the disk + * (see above fclose and fsync). No matter what happens, we + * no longer need to keep these references around. + */ + code = ci_Apply(&decHead, IDecProc, (char *)&decRock); + if (!error) + error = code; + ci_Destroy(&decHead); + + return error; } void -CloneVolume(error, original, new, old) - Error *error; - Volume *original, *new, *old; +CloneVolume(Error * error, Volume * original, Volume * new, Volume * old) { - VOL_LOCK - CloneVolume_r(error, original, new, old); - VOL_UNLOCK -} + VOL_LOCK CloneVolume_r(error, original, new, old); +VOL_UNLOCK} void -CloneVolume_r(rerror, original, new, old) - Error *rerror; - Volume *original, *new, *old; +CloneVolume_r(Error * rerror, Volume * original, Volume * new, Volume * old) { - afs_int32 code, error=0; + afs_int32 code, error = 0; afs_int32 reclone; *rerror = 0; reclone = ((new == old) ? 1 : 0); code = DoCloneIndex(original, new, vLarge, reclone); - if (code) ERROR_EXIT(code); + if (code) + ERROR_EXIT(code); code = DoCloneIndex(original, new, vSmall, reclone); - if (code) ERROR_EXIT(code); + if (code) + ERROR_EXIT(code); code = CopyVolumeHeader_r(&V_disk(original), &V_disk(new)); - if (code) ERROR_EXIT(code); + if (code) + ERROR_EXIT(code); error_exit: *rerror = error; diff --git a/src/vol/common.c b/src/vol/common.c index ca3a2e69c..0e5aedbb8 100644 --- a/src/vol/common.c +++ b/src/vol/common.c @@ -19,36 +19,48 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/common.c,v 1.1.1.4 2001/07/14 22:24:55 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/common.c,v 1.6 2003/07/15 23:17:37 shadow Exp $"); #include int Statistics = 0; -/* VARARGS */ -Log (a,b,c,d,e,f,g,h,i,j,k) - char *a, *b, *c, *d, *e, *f, *g, *h, *i, *j, *k; +/*@printflike@*/ void +Log(const char *format, ...) { int level; + va_list args; if (Statistics) level = -1; else level = 0; - ViceLog(level,(a,b,c,d,e,f,g,h,i,j,k)); + + va_start(args, format); + vViceLog(level, (format, args)); + va_end(args); } -Abort(s,a,b,c,d,e,f,g,h,i,j) - char *s, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; +/*@printflike@*/ void +Abort(const char *format, ...) { + va_list args; + ViceLog(0, ("Program aborted: ")); - ViceLog(0, (s,a,b,c,d,e,f,g,h,i,j)); + va_start(args, format); + vViceLog(0, (format, args)); + va_end(args); abort(); } -Quit(s,a,b,c,d,e,f,g,h,i,j) - char *s, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; +/*@printflike@*/ void +Quit(const char *format, ...) { - ViceLog(0, (s,a,b,c,d,e,f,g,h,i,j)); + va_list args; + + va_start(args, format); + vViceLog(0, (format, args)); + va_end(args); exit(1); } diff --git a/src/vol/devname.c b/src/vol/devname.c index bed3cc799..71ad7ea60 100644 --- a/src/vol/devname.c +++ b/src/vol/devname.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/devname.c,v 1.3 2004/01/10 21:12:32 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/devname.c,v 1.13 2003/12/08 07:31:57 shadow Exp $"); #include #include @@ -19,7 +20,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/devname.c,v 1.3 2004/01/10 21:12:32 #if !defined(AFS_SGI_ENV) #ifdef AFS_OSF_ENV #include -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #ifdef AFS_VFSINCL_ENV #define VFS #ifdef AFS_SUN5_ENV @@ -37,7 +38,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/devname.c,v 1.3 2004/01/10 21:12:32 #include #endif #endif /* AFS_VFSINCL_ENV */ -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ #endif /* AFS_SGI_ENV */ #include #include @@ -65,7 +66,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/devname.c,v 1.3 2004/01/10 21:12:32 #include #ifdef AFS_SGI_EFS_IOPS_ENV #define ROOTINO EFS_ROOTINO -#include "../sgiefs/efs.h" +#include "sgiefs/efs.h" #endif #else #ifdef AFS_LINUX22_ENV @@ -86,12 +87,22 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/devname.c,v 1.3 2004/01/10 21:12:32 #endif /* ITIMER_REAL */ #include "partition.h" + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + + /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device. * returns pointer to static storage; copy it out quickly! */ -char *vol_DevName(adev, wpath) -char *wpath; -dev_t adev; { +char * +vol_DevName(dev_t adev, char *wpath) +{ static char pbuffer[128]; char pbuf[128], *ptr; int code, i; @@ -112,15 +123,17 @@ dev_t adev; { #endif #ifdef AFS_AIX_ENV - if ((nmounts = getmount(&vmountp)) <= 0) { - return (char *)0; + if ((nmounts = getmount(&vmountp)) <= 0) { + return NULL; } - for (; nmounts; nmounts--, vmountp = (struct vmount *)((int)vmountp + vmountp->vmt_length)) { + for (; nmounts; + nmounts--, vmountp = + (struct vmount *)((int)vmountp + vmountp->vmt_length)) { char *part = vmt2dataptr(vmountp, VMT_STUB); #else #ifdef AFS_SUN5_ENV if (!(mntfile = fopen(MNTTAB, "r"))) { - return (char *)0; + return NULL; } while (!getmntent(mntfile, &mnt)) { char *part = mnt.mnt_mountp; @@ -129,41 +142,44 @@ dev_t adev; { #ifdef AFS_LINUX22_ENV if ((mfd = setmntent("/proc/mounts", "r")) == NULL) { if ((mfd = setmntent("/etc/mtab", "r")) == NULL) { - return (char *)0; + return NULL; } } #else - if ((mfd = setmntent(MOUNTED/*MNTTAB*/, "r")) == NULL) { - return (char *)0; + if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) { + return NULL; } #endif - while (mntent = getmntent(mfd)) { + while ((mntent = getmntent(mfd))) { char *part = mntent->mnt_dir; #else setfsent(); - while (fsent = getfsent()) { + while ((fsent = getfsent())) { char *part = fsent->fs_file; #endif #endif /* AFS_SGI_ENV */ #endif struct stat status; #ifdef AFS_AIX_ENV - if (vmountp->vmt_flags & (MNT_READONLY|MNT_REMOVABLE|MNT_REMOTE)) continue; /* Ignore any "special" partitions */ + if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE)) + continue; /* Ignore any "special" partitions */ #else #ifdef AFS_SUN5_ENV /* Ignore non ufs or non read/write partitions */ - if ((strcmp(mnt.mnt_fstype, "ufs") !=0) || - (strncmp(mnt.mnt_mntopts, "ro,ignore",9) ==0)) - continue; + if ((strcmp(mnt.mnt_fstype, "ufs") != 0) + || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0)) + continue; #else #if defined(AFS_LINUX22_ENV) if (strcmp(mntent->mnt_type, "ext2")) continue; #else #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) - if (!hasmntopt(mntent, MNTOPT_RW)) continue; + if (!hasmntopt(mntent, MNTOPT_RW)) + continue; #else - if (strcmp(fsent->fs_type, "rw") != 0) continue; /* Ignore non read/write partitions */ + if (strcmp(fsent->fs_type, "rw") != 0) + continue; /* Ignore non read/write partitions */ #endif /* AFS_LINUX22_ENV */ #endif /* AFS_SGI_ENV */ #endif @@ -171,12 +187,13 @@ dev_t adev; { /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */ if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { continue; /* Non /vicepx; ignore */ - } + } if (stat(part, &status) == -1) { continue; } #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV) - if ((status.st_ino != ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK)*/) { + if ((status.st_ino != + ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) { continue; } #endif @@ -192,7 +209,7 @@ dev_t adev; { #else strcpy(pbuffer, fsent->fs_spec); #endif -#endif /* AFS_SGI_ENV */ +#endif /* AFS_SGI_ENV */ #endif if (wpath) { strcpy(pbuf, pbuffer); @@ -201,59 +218,57 @@ dev_t adev; { *ptr = '\0'; strcpy(wpath, pbuf); } else - return (char *)0; + return NULL; } - ptr = (char *)strrchr(pbuffer, '/'); + ptr = (char *)strrchr(pbuffer, '/'); if (ptr) { - strcpy(pbuffer, ptr+1); + strcpy(pbuffer, ptr + 1); return pbuffer; } else - return (char *)0; + return NULL; } } -#ifndef AFS_AIX_ENV #ifdef AFS_SUN5_ENV - (void) fclose(mntfile); + (void)fclose(mntfile); #else #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV) endmntent(mfd); #else +#ifndef AFS_AIX_ENV endfsent(); #endif -#endif /* AFS_SGI_ENV */ #endif - return (char *)0; +#endif /* AFS_SGI_ENV */ + return NULL; } - /* Search for the raw device name. Will put an "r" in front of each * directory and file entry of the pathname until we find a character * device. */ -char *afs_rawname(devfile) - char *devfile; +char * +afs_rawname(char *devfile) { - static char rawname[100]; - struct stat statbuf; - char *p; - int code, i; + static char rawname[100]; + struct stat statbuf; + char *p; + int code, i; - i = strlen(devfile); - while (i >= 0) { - strcpy(rawname, devfile); - if (devfile[i] == '/') { - rawname[i+1] = 'r'; - rawname[i+2] = 0; - strcat(rawname, &devfile[i+1]); - } + i = strlen(devfile); + while (i >= 0) { + strcpy(rawname, devfile); + if (devfile[i] == '/') { + rawname[i + 1] = 'r'; + rawname[i + 2] = 0; + strcat(rawname, &devfile[i + 1]); + } - code = stat(rawname, &statbuf); - if (!code && S_ISCHR(statbuf.st_mode)) - return rawname; - - while((--i>=0) && (devfile[i] != '/')); - } + code = stat(rawname, &statbuf); + if (!code && S_ISCHR(statbuf.st_mode)) + return rawname; - return (char *)0; -} + while ((--i >= 0) && (devfile[i] != '/')); + } + return NULL; +} diff --git a/src/vol/fs_conv_411.c b/src/vol/fs_conv_411.c index 8aa0f824b..fcc89119e 100644 --- a/src/vol/fs_conv_411.c +++ b/src/vol/fs_conv_411.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/fs_conv_411.c,v 1.2 2003/01/02 03:55:53 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/fs_conv_411.c,v 1.9 2003/08/08 21:54:54 shadow Exp $"); #if defined(AFS_DUX40_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_SUN54_ENV) #if defined AFS_DUX40_ENV @@ -81,80 +82,87 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/fs_conv_411.c,v 1.2 2003/01/02 03:5 #include #include -int icount=0, iarraysize=0, *iarray; +int icount = 0, iarraysize = 0, *iarray; -char *rawname(), *unrawname(), *vol_DevName(), *blockcheck(); -#define ROOTINODE 2 -int force = 0, verbose = 0, unconv = 0; +char *rawname(), *unrawname(), *vol_DevName(), *blockcheck(); +#define ROOTINODE 2 +int force = 0, verbose = 0, unconv = 0; #ifdef AFS_DUX40_ENV -int sortinodes(a,b) - int *a, *b; +int +sortinodes(a, b) + int *a, *b; { - if (*a < *b) return -1; - if (*a > *b) return +1; - return 0; + if (*a < *b) + return -1; + if (*a > *b) + return +1; + return 0; } -int BuildInodes(path) - char *path; +int +BuildInodes(path) + char *path; { - DIR *d; - struct dirent *de; - char p[256]; - struct stat stats; - int code=0; - - d = opendir(path); - if (!d) { - printf("Cannot open %s: error %d\n", path, errno); - return -1; - } - - while (de = readdir(d)) { - if (iarraysize == 0) { - iarraysize = 1000; - iarray = (int *) malloc(iarraysize * sizeof(int)); - } - if (icount >= iarraysize) { - iarraysize += 1000; - iarray = (int *) realloc(iarray, iarraysize * sizeof(int)); - } - iarray[icount] = de->d_ino; - icount++; - - if ( (strcmp(de->d_name,".") == 0) || (strcmp(de->d_name,"..") == 0) ) - continue; - - strcpy(p, path); - strcat(p, "/"); - strcat(p, de->d_name); - - code = stat(p, &stats); - if (code) { - printf("Cannot stat %s: error %d\n", path, errno); + DIR *d; + struct dirent *de; + char p[256]; + struct stat stats; + int code = 0; + + d = opendir(path); + if (!d) { + printf("Cannot open %s: error %d\n", path, errno); return -1; - } - if (S_ISDIR(stats.st_mode)) { - code = BuildInodes(p); - if (code) break; - } - } - - closedir(d); - return code; + } + + while (de = readdir(d)) { + if (iarraysize == 0) { + iarraysize = 1000; + iarray = (int *)malloc(iarraysize * sizeof(int)); + } + if (icount >= iarraysize) { + iarraysize += 1000; + iarray = (int *)realloc(iarray, iarraysize * sizeof(int)); + } + iarray[icount] = de->d_ino; + icount++; + + if ((strcmp(de->d_name, ".") == 0) || (strcmp(de->d_name, "..") == 0)) + continue; + + strcpy(p, path); + strcat(p, "/"); + strcat(p, de->d_name); + + code = stat(p, &stats); + if (code) { + printf("Cannot stat %s: error %d\n", path, errno); + return -1; + } + if (S_ISDIR(stats.st_mode)) { + code = BuildInodes(p); + if (code) + break; + } + } + + closedir(d); + return code; } #endif -static ConvCmd(as) - struct cmd_syndesc *as; +static +ConvCmd(as) + struct cmd_syndesc *as; { unconv = 0; handleit(as); } -static UnConvCmd(as) - struct cmd_syndesc *as; +static +UnConvCmd(as) + struct cmd_syndesc *as; { unconv = 1; handleit(as); @@ -162,8 +170,9 @@ static UnConvCmd(as) #if defined(AFS_SUN54_ENV) -static handleit(as) - struct cmd_syndesc *as; +static +handleit(as) + struct cmd_syndesc *as; { register struct cmd_item *ti; char *dname; @@ -180,41 +189,43 @@ static handleit(as) force = 0; if (unconv) { - printf("Unconverts from a %s AFS partition to a pre-%s compatible format.\n\n", - OSVERS, OSVERS); - } - else { - printf("Converts a pre-%s AFS partition to a %s compatible format.\n\n", - OSVERS, OSVERS); + printf + ("Unconverts from a %s AFS partition to a pre-%s compatible format.\n\n", + OSVERS, OSVERS); + } else { + printf + ("Converts a pre-%s AFS partition to a %s compatible format.\n\n", + OSVERS, OSVERS); } if (!force) { - printf("*** Must use the '-force' option for command to have effect! ***\n"); + printf + ("*** Must use the '-force' option for command to have effect! ***\n"); if (!verbose) { - printf("*** Use the '-verbose' option to report what will be converted ***\n"); - exit(1); + printf + ("*** Use the '-verbose' option to report what will be converted ***\n"); + exit(1); } } - for (ti = as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { FILE *fsent; char *namep = ti->data; int found = 0; haspart = 1; - if ( ( fsent = fopen(VFSTAB, "r")) == NULL ) - { - printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno); - exit(2); + if ((fsent = fopen(VFSTAB, "r")) == NULL) { + printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno); + exit(2); } while (!getvfsent(fsent, &mnt)) { char *part = mnt.vfs_mountp; - if ( !part) + if (!part) continue; if (!strncmp(namep, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { if (!strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { - if (!strncmp(part, namep, strlen(part)+1)) { + if (!strncmp(part, namep, strlen(part) + 1)) { if (dname = mnt.vfs_fsckdev) { printf("ProcessFileSys %s %s\n", dname, namep); ProcessFileSys(dname, namep); @@ -230,19 +241,17 @@ static handleit(as) fclose(fsent); } - /* if raw devices are specified */ - for (ti = as->parms[3].items; ti; ti=ti->next) { + /* if raw devices are specified */ + for (ti = as->parms[3].items; ti; ti = ti->next) { char *namep = ti->data; hasDevice = 1; - if ( namep ) - { - if ( !CheckMountedDevice(namep) ) - { - printf("Device %s may be mounted, aborting...\n", namep); - continue; - } - ProcessFileSys(namep, namep); + if (namep) { + if (!CheckMountedDevice(namep)) { + printf("Device %s may be mounted, aborting...\n", namep); + continue; + } + ProcessFileSys(namep, namep); } } @@ -250,33 +259,34 @@ static handleit(as) int didSome = 0; FILE *fsent; - if ( ( fsent = fopen(VFSTAB, "r")) ==NULL ) - { - printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno); - exit(2); - } - while (!getvfsent(fsent, &mnt)) { - char *part = mnt.vfs_mountp; + if ((fsent = fopen(VFSTAB, "r")) == NULL) { + printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno); + exit(2); + } + while (!getvfsent(fsent, &mnt)) { + char *part = mnt.vfs_mountp; - if ( !part) + if (!part) continue; if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE) == 0) { - if (dname = mnt.vfs_fsckdev ) + if (dname = mnt.vfs_fsckdev) ProcessFileSys(dname, part); - didSome++; - } + didSome++; + } } fclose(fsent); if (!didSome) - printf("No file system partitions named %s* found; not processed\n",VICE_PARTITION_PREFIX); + printf + ("No file system partitions named %s* found; not processed\n", + VICE_PARTITION_PREFIX); } } #else /* AFS_SUN54_ENV */ handleit(as) - struct cmd_syndesc *as; + struct cmd_syndesc *as; { register struct cmd_item *ti; char *dname; @@ -292,22 +302,25 @@ handleit(as) force = 0; if (unconv) { - printf("Unconverts from a %s AFS partition to a pre-%s compatible format.\n\n", - OSVERS, OSVERS); - } - else { - printf("Converts a pre-%s AFS partition to a %s compatible format.\n\n", - OSVERS, OSVERS); + printf + ("Unconverts from a %s AFS partition to a pre-%s compatible format.\n\n", + OSVERS, OSVERS); + } else { + printf + ("Converts a pre-%s AFS partition to a %s compatible format.\n\n", + OSVERS, OSVERS); } if (!force) { - printf("*** Must use the '-force' option for command to have effect! ***\n"); + printf + ("*** Must use the '-force' option for command to have effect! ***\n"); if (!verbose) { - printf("*** Use the '-verbose' option to report what will be converted ***\n"); - exit(1); + printf + ("*** Use the '-verbose' option to report what will be converted ***\n"); + exit(1); } } - for (ti = as->parms[0].items; ti; ti=ti->next) { + for (ti = as->parms[0].items; ti; ti = ti->next) { struct fstab *fsent; char *namep = ti->data; int found = 0; @@ -319,7 +332,7 @@ handleit(as) if (!strncmp(namep, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { if (!strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { - if (!strncmp(part, namep, strlen(part)+1)) { + if (!strncmp(part, namep, strlen(part) + 1)) { if (dname = unrawname(fsent->fs_spec)) { ProcessFileSys(dname, namep); found = 1; @@ -330,13 +343,13 @@ handleit(as) } else { if (!rawname(namep) || !unrawname(namep)) break; - if (!strcmp(fsent->fs_spec, rawname(namep)) || - !strcmp(fsent->fs_spec, unrawname(namep))) { + if (!strcmp(fsent->fs_spec, rawname(namep)) + || !strcmp(fsent->fs_spec, unrawname(namep))) { if (dname = unrawname(fsent->fs_spec)) { ProcessFileSys(dname, fsent->fs_file); found = 1; break; - } + } } } } @@ -362,7 +375,9 @@ handleit(as) } endfsent(); if (!didSome) - printf("No file system partitions named %s* found; not processed\n",VICE_PARTITION_PREFIX); + printf + ("No file system partitions named %s* found; not processed\n", + VICE_PARTITION_PREFIX); } } #endif /* AFS_SUN54_ENV */ @@ -370,41 +385,49 @@ handleit(as) #include "AFS_component_version_number.c" -main(argc,argv) -char **argv; +main(argc, argv) + char **argv; { register struct cmd_syndesc *ts; afs_int32 code; - + if (geteuid() != 0) { printf("must be run as root; sorry\n"); exit(1); } #ifdef AFS_DUX40_ENV - ts = cmd_CreateSyntax("convert", ConvCmd, 0, "Convert to DUX 4.0D format"); + ts = cmd_CreateSyntax("convert", ConvCmd, 0, + "Convert to DUX 4.0D format"); #else #if defined(AFS_SUN54_ENV) - ts = cmd_CreateSyntax("convert", ConvCmd, 0, "Convert to AFS SunOS 5.6 format"); + ts = cmd_CreateSyntax("convert", ConvCmd, 0, + "Convert to AFS SunOS 5.6 format"); #else - ts = cmd_CreateSyntax("convert", ConvCmd, 0, "Convert to AFS 4.1.1 format"); + ts = cmd_CreateSyntax("convert", ConvCmd, 0, + "Convert to AFS 4.1.1 format"); #endif #endif cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL, "AFS partition name"); cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose mode"); - cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Safeguard enforce switch"); + cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, + "Safeguard enforce switch"); cmd_AddParm(ts, "-device", CMD_LIST, CMD_OPTIONAL, "AFS raw device name"); #ifdef AFS_DUX40_ENV - ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, "Convert back from OSF 4.0D to earlier formats"); + ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, + "Convert back from OSF 4.0D to earlier formats"); #else #if defined(AFS_SUN54_ENV) - ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, "Convert back from AFS SunOS 5.6 to earlier formats"); + ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, + "Convert back from AFS SunOS 5.6 to earlier formats"); #else - ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, "Convert back from AFS 4.1.1 to earlier formats"); + ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, + "Convert back from AFS 4.1.1 to earlier formats"); #endif #endif cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL, "AFS partition name"); cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose mode"); - cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Safeguard enforce switch"); + cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, + "Safeguard enforce switch"); cmd_AddParm(ts, "-device", CMD_LIST, CMD_OPTIONAL, "AFS raw device name"); code = cmd_Dispatch(argc, argv); @@ -413,7 +436,7 @@ char **argv; ProcessFileSys(dname, path) - char *dname, *path; + char *dname, *path; { struct stat status, stat1; #if !defined(AFS_SUN54_ENV) @@ -422,13 +445,15 @@ ProcessFileSys(dname, path) char devbuffer[120], *devname; int i, j, mounted = 0, code; - if (stat(path,&status) == -1) { + if (stat(path, &status) == -1) { printf("Couldn't find file system \"%s\"\n", path); return; } if (status.st_ino == ROOTINODE) { if (force) { - printf("Partition %s is mounted; only unmounted partitions are processed\n", path); + printf + ("Partition %s is mounted; only unmounted partitions are processed\n", + path); return; } mounted = 1; @@ -440,36 +465,37 @@ ProcessFileSys(dname, path) #endif if (!mounted) { #ifdef AFS_DUX40_ENV - ufsargs.fspec = devname; - code = mount(MOUNT_UFS, path, 0, &ufsargs); + ufsargs.fspec = devname; + code = mount(MOUNT_UFS, path, 0, &ufsargs); #else #if defined(AFS_SUN54_ENV) code = 0; #else - ufsargs.fspec = devname; - code = mount("4.2", path, M_NEWTYPE, &ufsargs); + ufsargs.fspec = devname; + code = mount("4.2", path, M_NEWTYPE, &ufsargs); #endif #endif - if (code < 0) { - printf("Couldn't mount %s on %s (err=%d)\n", devname, path, errno); - return; - } + if (code < 0) { + printf("Couldn't mount %s on %s (err=%d)\n", devname, path, + errno); + return; + } } - - if (stat(path,&status) == -1) { + + if (stat(path, &status) == -1) { printf("Couldn't find file system \"%s\"\n", path); return; } - #ifdef AFS_DUX40_ENV icount = 0; code = BuildInodes(path); if (code) { - printf("Couldn't generate list of all inodes in directory %s\n", path); - return; + printf("Couldn't generate list of all inodes in directory %s\n", + path); + return; } if (icount) - qsort(iarray, icount, sizeof(int), sortinodes); + qsort(iarray, icount, sizeof(int), sortinodes); #endif #if !defined(AFS_SUN54_ENV) @@ -483,413 +509,457 @@ ProcessFileSys(dname, path) printf("Unable to get inodes for \"%s\"; not processed\n", path); if (!mounted) { #ifdef AFS_DUX40_ENV - umount(path); + umount(path); #endif } } -int ProcessAfsInodes(devname, partition) - char *devname, *partition; +int +ProcessAfsInodes(devname, partition) + char *devname, *partition; { - union { - struct fs fs; - char block[SBSIZE]; - } super; - int pfd, i, c, e, bufsize, cnt =0, mod = 0, wcnt = 0, ccnt = 0, ncnt; - FILE *inodeFile = NULL; - char rdev[25]; - struct dinode *inodes = NULL, *einodes, *p; - int code, istep=0; - - sync(); - sleep(5); /* XXXX */ + union { + struct fs fs; + char block[SBSIZE]; + } super; + int pfd, i, c, e, bufsize, cnt = 0, mod = 0, wcnt = 0, ccnt = 0, ncnt; + FILE *inodeFile = NULL; + char rdev[25]; + struct dinode *inodes = NULL, *einodes, *p; + int code, istep = 0; + + sync(); + sleep(5); /* XXXX */ #if defined(AFS_SUN54_ENV) - sprintf(rdev, "%s", devname); + sprintf(rdev, "%s", devname); #else - sprintf(rdev, "/dev/r%s", devname); + sprintf(rdev, "/dev/r%s", devname); #endif - pfd = open(rdev, O_RDWR); - if (pfd < 0) { - printf("Could not read device %s to get inode list\n", rdev); - printf("errno %d: %s\n", errno, strerror(errno)); - return -1; - } - if (bread(pfd, super.block, SBLOCK, SBSIZE) == -1) { - printf("Unable to read superblock, partition %s\n", partition); - goto out; - } - - /* - * run a few consistency checks of the superblock - * (Cribbed from vfsck) - */ - if ((super.fs.fs_magic != FS_MAGIC) || (super.fs.fs_ncg < 1) || (super.fs.fs_cpg < 1) || - (super.fs.fs_ncg * super.fs.fs_cpg < super.fs.fs_ncyl || - (super.fs.fs_ncg - 1) * super.fs.fs_cpg >= super.fs.fs_ncyl) || - (super.fs.fs_sbsize > SBSIZE)) { - printf("There's something wrong with the superblock for partition %s; run vfsck\n", partition); - goto out; - } - bufsize = super.fs.fs_ipg * sizeof(struct dinode); - if (!(inodes = (struct dinode *) malloc(bufsize))) { - printf("Unable to allocate enough memory to scan inodes; help!\n"); - goto out; - } - einodes = (struct dinode *) (((char *)inodes) + bufsize); - printf("Processing all AFS inodes on partition %s (device %s)...\n", partition, rdev); - for (c = 0; c < super.fs.fs_ncg; c++) { - daddr_t dblk1; + pfd = open(rdev, O_RDWR); + if (pfd < 0) { + printf("Could not read device %s to get inode list\n", rdev); + printf("errno %d: %s\n", errno, strerror(errno)); + return -1; + } + if (bread(pfd, super.block, SBLOCK, SBSIZE) == -1) { + printf("Unable to read superblock, partition %s\n", partition); + goto out; + } + + /* + * run a few consistency checks of the superblock + * (Cribbed from vfsck) + */ + if ((super.fs.fs_magic != FS_MAGIC) || (super.fs.fs_ncg < 1) + || (super.fs.fs_cpg < 1) + || (super.fs.fs_ncg * super.fs.fs_cpg < super.fs.fs_ncyl + || (super.fs.fs_ncg - 1) * super.fs.fs_cpg >= super.fs.fs_ncyl) + || (super.fs.fs_sbsize > SBSIZE)) { + printf + ("There's something wrong with the superblock for partition %s; run vfsck\n", + partition); + goto out; + } + bufsize = super.fs.fs_ipg * sizeof(struct dinode); + if (!(inodes = (struct dinode *)malloc(bufsize))) { + printf("Unable to allocate enough memory to scan inodes; help!\n"); + goto out; + } + einodes = (struct dinode *)(((char *)inodes) + bufsize); + printf("Processing all AFS inodes on partition %s (device %s)...\n", + partition, rdev); + for (c = 0; c < super.fs.fs_ncg; c++) { + daddr_t dblk1; #if defined(AFS_SUN54_ENV) daddr_t f1; offset_t off; #endif - i = c*super.fs.fs_ipg; - e = i+super.fs.fs_ipg; + i = c * super.fs.fs_ipg; + e = i + super.fs.fs_ipg; #ifdef AFS_DUX40_ENV - dblk1 = fsbtodb(&super.fs, itod(&super.fs, i)); - code = lseek(pfd, (off_t) ((off_t)dblk1 * DEV_BSIZE), L_SET); + dblk1 = fsbtodb(&super.fs, itod(&super.fs, i)); + code = lseek(pfd, (off_t) ((off_t) dblk1 * DEV_BSIZE), L_SET); #else #if defined(AFS_SUN54_ENV) - f1 = fsbtodb(&super.fs,itod(&super.fs,i)); - off = (offset_t)f1 << DEV_BSHIFT; - code = llseek(pfd, off, L_SET) ; + f1 = fsbtodb(&super.fs, itod(&super.fs, i)); + off = (offset_t) f1 << DEV_BSHIFT; + code = llseek(pfd, off, L_SET); #else - code = lseek(pfd, dbtob(fsbtodb(&super.fs,itod(&super.fs,i))), L_SET); + code = + lseek(pfd, dbtob(fsbtodb(&super.fs, itod(&super.fs, i))), L_SET); #endif #endif - if (code == -1) { - printf("Error reading inodes for partition %s; run vfsck\n", partition); - printf("%d: %s\n", errno, strerror(errno)); + if (code == -1) { + printf("Error reading inodes for partition %s; run vfsck\n", + partition); + printf("%d: %s\n", errno, strerror(errno)); #if defined(AFS_SUN54_ENV) - printf("file number = %d; offset = %ld\n", pfd, off); + printf("file number = %d; offset = %ld\n", pfd, off); #else - printf("file number = %d\n", pfd); + printf("file number = %d\n", pfd); #endif - goto out; - } - while (i < e) { - wcnt = ncnt = mod = 0; - code = read(pfd, inodes, bufsize); - if (code != bufsize) { - printf("Error reading inodes for partition %s; run vfsck\n", partition); - if (code<0) { - printf("errno %d: %s\n", errno, strerror(errno)); - } goto out; - } + } + while (i < e) { + wcnt = ncnt = mod = 0; + code = read(pfd, inodes, bufsize); + if (code != bufsize) { + printf("Error reading inodes for partition %s; run vfsck\n", + partition); + if (code < 0) { + printf("errno %d: %s\n", errno, strerror(errno)); + } + goto out; + } - /* Step through each inode */ - for (p = inodes; p < einodes && i < e; i++, p++) + /* Step through each inode */ + for (p = inodes; p < einodes && i < e; i++, p++) #ifdef AFS_DUX40_ENV - { - afs_uint32 v1, v2, v3, v4; - afs_uint32 volid, vnode, uniq, vers; - afs_uint32 type, rwvol; - afs_uint32 t; - int special; - - if ((p->di_mode&IFMT) != IFREG) { - /* This inode is not an AFS inode so - * zero out all the spare fields. - */ - zeroSpares: - if (!(p->di_flags & IC_PROPLIST)) { - p->di_proplb=0; - } - if (!(p->di_flags & IC_XUID)) { - p->di_uid=0; - } - if (!(p->di_flags & IC_XGID)) { - p->di_gid=0; - } - mod = 1; - ncnt++; - continue; - } + { + afs_uint32 v1, v2, v3, v4; + afs_uint32 volid, vnode, uniq, vers; + afs_uint32 type, rwvol; + afs_uint32 t; + int special; + + if ((p->di_mode & IFMT) != IFREG) { + /* This inode is not an AFS inode so + * zero out all the spare fields. + */ + zeroSpares: + if (!(p->di_flags & IC_PROPLIST)) { + p->di_proplb = 0; + } + if (!(p->di_flags & IC_XUID)) { + p->di_uid = 0; + } + if (!(p->di_flags & IC_XGID)) { + p->di_gid = 0; + } + mod = 1; + ncnt++; + continue; + } /* printf("Inode %d: proplb=%u, uid=%u, bcuid=0x%x, bcgid=0x%x, gid=0x%x\n", * i , p->di_proplb, p->di_uid, p->di_bcuid, p->di_bcgid, * p->di_gid); - */ - - if (unconv) { /*unconvert*/ - /* Check if the inode is not a DUX40D AFS inode */ - if (p->di_proplb != VICEMAGIC || (p->di_flags & IC_PROPLIST)) { - ccnt++; - if (verbose) - printf(" AFS Inode %d: already unconverted\n", i); - continue; - } - - v1 = p->di_uid; - v2 = p->di_gid; - v3 = ((u_int)(p->di_bcuid)) << 16 | ((u_int)(p->di_bcgid)); - - /* We have a sorted list of ufs inodes. Is it one of these */ - while ((istep < icount) && (i > iarray[istep])) { - istep++; - } - if ((istep < icount) && (i == iarray[istep])) { - /* Yes, its a ufs inode */ - if (verbose) - printf(" Inode %d: Not an AFS Inode\n", i); - goto zeroSpares; - } - - /* Is it not an AFS inode. !IS_VICEMAGIC check */ - if (!(v2 || v3)) { - if (verbose) - printf("Warning: Inode %d: Unreferenced inode\n", i); - continue; /* skip, making no change */ - } - - volid = v1; - if (((v2 >> 3) == 0x1fffffff) && (v2 & 0x3)) { - special = 1; /* INODESPECIAL */ - type = v2 & 0x3; - rwvol = v3; - if (verbose) { - printf(" %s AFS Inode %d: Vol=%u, RWVol=%u, Type=%d\n", - (force?"Unconverting":"Would have unconverted"), i, - volid, rwvol, type); - } - } else { - special = 0; - vnode = ((v2 >> 27) << 16) + (v3 & 0xffff); - uniq = (v2 & 0x3fffff); - vers = (((v2 >> 22) & 0x1f) << 16) + ((v3 >> 16) & 0xffff); - if (verbose) { - printf(" %s AFS Inode %d: RWVol=%u, VNode=%u, Uniq=%u, Vers=%u\n", - (force?"Unconverting":"Would have unconverted"), i, - volid, vnode, uniq, vers); - } - } - - /* Now unconvert the DUX40D AFS inode to the OSF30 version */ - p->di_proplb = v1; - p->di_uid = v2; - p->di_gid = v3; - p->di_flags &= ~(IC_PROPLIST|IC_XUID|IC_XGID); - p->di_bcuid = 0; - p->di_bcgid = -2; - mod = 1; cnt++; wcnt++; - - } else { /*convert*/ - if ((p->di_proplb == VICEMAGIC && !(p->di_flags & IC_PROPLIST)) - || (p->di_uid == 0 && p->di_gid == 0) - || (p->di_flags & (IC_XUID|IC_XGID))) { - /* This inode is either already converted or not an AFS inode */ - /* We have a sorted list of ufs inodes. Is it one of these */ - while ((istep < icount) && (i > iarray[istep])) { - istep++; - } - if ((istep < icount) && (i == iarray[istep])) { - /* Yes, its a ufs inode */ - if (verbose) { - printf(" Inode %d: Not an AFS Inode %s\n", - i, ((p->di_spare[1] || p->di_spare[2])?"(fixed)":"")); - } - goto zeroSpares; - } - - /* Is it a AFS inode. IS_VICEMAGIC check */ - if ((p->di_uid || p->di_gid) - && !(p->di_flags & (IC_XUID|IC_XGID))) { - ccnt++; - if (verbose) - printf(" AFS Inode %d: already converted\n", i); - continue; - } - - /* Not an AFS nor UFS inode */ - printf("Warning: Inode %d: Unreferenced inode\n", i); - continue; /* skip, making no changes */ - } - - v1 = p->di_proplb; - v2 = p->di_uid; - v3 = p->di_gid; - - volid = v1; - if (((v2 >> 3) == 0x1fffffff) && (v2 & 0x3)) { - special = 1; /* INODESPECIAL */ - type = v2 & 0x3; - rwvol = v3; - if (verbose) { - printf(" %s AFS Inode %d: Vol=%u, RWVol=%u, Type=%d\n", - (force?"Converting":"Would have converted"),i, - volid, rwvol, type); - } - } else { - special = 0; - vnode = ((v2 >> 27) << 16) + (v3 & 0xffff); - uniq = (v2 & 0x3fffff); - vers = (((v2 >> 22) & 0x1f) << 16) + ((v3 >> 16) & 0xffff); - if (verbose) { - printf(" %s AFS Inode %d: RWVol=%u, VNode=%u, Uniq=%u, Vers=%u\n", - (force?"Converting":"Would have converted"),i, - volid, (vnode & 0x1fffff), (uniq & 0x3fffff), - (vers & 0x1fffff)); - } - } - - /* Now convert the OSF30 AFS inode to the DUX40D version */ - p->di_proplb = VICEMAGIC; - p->di_uid = v1; - p->di_gid = v2; - p->di_bcuid = (u_short)(v3 >> 16); - p->di_bcgid = (u_short)v3; - p->di_flags &= ~(IC_PROPLIST); - p->di_flags |= (IC_XUID|IC_XGID); - mod = 1; cnt++; wcnt++; - } /*convert*/ - } + */ + + if (unconv) { /*unconvert */ + /* Check if the inode is not a DUX40D AFS inode */ + if (p->di_proplb != VICEMAGIC + || (p->di_flags & IC_PROPLIST)) { + ccnt++; + if (verbose) + printf(" AFS Inode %d: already unconverted\n", + i); + continue; + } + + v1 = p->di_uid; + v2 = p->di_gid; + v3 = ((u_int) (p->di_bcuid)) << 16 | + ((u_int) (p->di_bcgid)); + + /* We have a sorted list of ufs inodes. Is it one of these */ + while ((istep < icount) && (i > iarray[istep])) { + istep++; + } + if ((istep < icount) && (i == iarray[istep])) { + /* Yes, its a ufs inode */ + if (verbose) + printf(" Inode %d: Not an AFS Inode\n", i); + goto zeroSpares; + } + + /* Is it not an AFS inode. !IS_VICEMAGIC check */ + if (!(v2 || v3)) { + if (verbose) + printf("Warning: Inode %d: Unreferenced inode\n", + i); + continue; /* skip, making no change */ + } + + volid = v1; + if (((v2 >> 3) == 0x1fffffff) && (v2 & 0x3)) { + special = 1; /* INODESPECIAL */ + type = v2 & 0x3; + rwvol = v3; + if (verbose) { + printf + (" %s AFS Inode %d: Vol=%u, RWVol=%u, Type=%d\n", + (force ? "Unconverting" : + "Would have unconverted"), i, volid, rwvol, + type); + } + } else { + special = 0; + vnode = ((v2 >> 27) << 16) + (v3 & 0xffff); + uniq = (v2 & 0x3fffff); + vers = + (((v2 >> 22) & 0x1f) << 16) + + ((v3 >> 16) & 0xffff); + if (verbose) { + printf + (" %s AFS Inode %d: RWVol=%u, VNode=%u, Uniq=%u, Vers=%u\n", + (force ? "Unconverting" : + "Would have unconverted"), i, volid, vnode, + uniq, vers); + } + } + + /* Now unconvert the DUX40D AFS inode to the OSF30 version */ + p->di_proplb = v1; + p->di_uid = v2; + p->di_gid = v3; + p->di_flags &= ~(IC_PROPLIST | IC_XUID | IC_XGID); + p->di_bcuid = 0; + p->di_bcgid = -2; + mod = 1; + cnt++; + wcnt++; + + } else { /*convert */ + if ((p->di_proplb == VICEMAGIC + && !(p->di_flags & IC_PROPLIST)) + || (p->di_uid == 0 && p->di_gid == 0) + || (p->di_flags & (IC_XUID | IC_XGID))) { + /* This inode is either already converted or not an AFS inode */ + /* We have a sorted list of ufs inodes. Is it one of these */ + while ((istep < icount) && (i > iarray[istep])) { + istep++; + } + if ((istep < icount) && (i == iarray[istep])) { + /* Yes, its a ufs inode */ + if (verbose) { + printf(" Inode %d: Not an AFS Inode %s\n", + i, ((p->di_spare[1] + || p-> + di_spare[2]) ? "(fixed)" : "")); + } + goto zeroSpares; + } + + /* Is it a AFS inode. IS_VICEMAGIC check */ + if ((p->di_uid || p->di_gid) + && !(p->di_flags & (IC_XUID | IC_XGID))) { + ccnt++; + if (verbose) + printf(" AFS Inode %d: already converted\n", + i); + continue; + } + + /* Not an AFS nor UFS inode */ + printf("Warning: Inode %d: Unreferenced inode\n", i); + continue; /* skip, making no changes */ + } + + v1 = p->di_proplb; + v2 = p->di_uid; + v3 = p->di_gid; + + volid = v1; + if (((v2 >> 3) == 0x1fffffff) && (v2 & 0x3)) { + special = 1; /* INODESPECIAL */ + type = v2 & 0x3; + rwvol = v3; + if (verbose) { + printf + (" %s AFS Inode %d: Vol=%u, RWVol=%u, Type=%d\n", + (force ? "Converting" : + "Would have converted"), i, volid, rwvol, + type); + } + } else { + special = 0; + vnode = ((v2 >> 27) << 16) + (v3 & 0xffff); + uniq = (v2 & 0x3fffff); + vers = + (((v2 >> 22) & 0x1f) << 16) + + ((v3 >> 16) & 0xffff); + if (verbose) { + printf + (" %s AFS Inode %d: RWVol=%u, VNode=%u, Uniq=%u, Vers=%u\n", + (force ? "Converting" : + "Would have converted"), i, volid, + (vnode & 0x1fffff), (uniq & 0x3fffff), + (vers & 0x1fffff)); + } + } + + /* Now convert the OSF30 AFS inode to the DUX40D version */ + p->di_proplb = VICEMAGIC; + p->di_uid = v1; + p->di_gid = v2; + p->di_bcuid = (u_short) (v3 >> 16); + p->di_bcgid = (u_short) v3; + p->di_flags &= ~(IC_PROPLIST); + p->di_flags |= (IC_XUID | IC_XGID); + mod = 1; + cnt++; + wcnt++; + } /*convert */ + } #else - { - afs_uint32 p1, p2, p3, p4; - int p5; - quad* q; + { + afs_uint32 p1, p2, p3, p4; + int p5; + quad *q; #if defined(AFS_SUN56_ENV) - q = (quad *)&(p->di_ic.ic_lsize); + q = (quad *) & (p->di_ic.ic_lsize); #else - q = &(p->di_ic.ic_size); + q = &(p->di_ic.ic_size); #endif - - p1 = p->di_gen; - p2 = p->di_ic.ic_flags; - p3 = q->val[0]; - p4 = p->di_ic.ic_uid; - p5 = p->di_ic.ic_gid; - - /* the game is afoot, Dr Watson! */ - if ( !verbose && ! ((ccnt+cnt+ncnt) % 5000 ) ) - { - printf("."); - fflush(stdout); - } - if (unconv) { - /* - * Convert from a 5.6 format to a pre 5.6 format - */ - if ( (p2 || p3) && !p4 && (p5 == -2) ) - { - if ( verbose) - printf("AFS Inode %d: Already in pre-%s AFS format (%x,%x,%x,%x,%x) ignoring..\n", - i, OSVERS, p1, p2, p3,p4, p5); - ccnt++; - continue; + p1 = p->di_gen; + p2 = p->di_ic.ic_flags; + p3 = q->val[0]; + p4 = p->di_ic.ic_uid; + p5 = p->di_ic.ic_gid; + + /* the game is afoot, Dr Watson! */ + if (!verbose && !((ccnt + cnt + ncnt) % 5000)) { + printf("."); + fflush(stdout); } - if ( p5 == VICEMAGIC) - { + if (unconv) { + /* + * Convert from a 5.6 format to a pre 5.6 format + */ + if ((p2 || p3) && !p4 && (p5 == -2)) { + if (verbose) + printf + ("AFS Inode %d: Already in pre-%s AFS format (%x,%x,%x,%x,%x) ignoring..\n", + i, OSVERS, p1, p2, p3, p4, p5); + ccnt++; + continue; + } + + if (p5 == VICEMAGIC) { /* This is a sol 2.6 AFS inode */ - mod = 1; - cnt++; wcnt++; - if (verbose) - printf("AFS Inode %d: %s from Sol5.6 (%x,%x,%x,%x,%x) \n", - i, (force ? "Unconverting" : - "Would have unconverted"), p1,p2,p3,p4,p5); - if ( force ) - { - q->val[0] = p->di_uid; - p->di_uid = 0; - p->di_gid = -2; - p->di_suid = UID_LONG; - p->di_sgid = GID_LONG; + mod = 1; + cnt++; + wcnt++; + if (verbose) + printf + ("AFS Inode %d: %s from Sol5.6 (%x,%x,%x,%x,%x) \n", + i, + (force ? "Unconverting" : + "Would have unconverted"), p1, p2, p3, p4, + p5); + if (force) { + q->val[0] = p->di_uid; + p->di_uid = 0; + p->di_gid = -2; + p->di_suid = UID_LONG; + p->di_sgid = GID_LONG; } continue; - } - } else { - if (p5 == VICEMAGIC) - { /* Assume an already converted 5.6 afs inode */ - if ( verbose ) - printf("AFS Inode %d: Already in %s AFS format (p1=%x,p2=%x,p3=%x,p4=%x,p5=%x); ignoring..\n", - i, OSVERS, p1,p2,p3,p4, p5); - ccnt++; - continue; - } - - /* for inodes created in solaris 2.4, there is a possibility - ** that the gid gets chopped off to an unsigned short(2 bytes) - */ - if ( (p2 || p3) && !p4 && ((p5 == -2) || - ((unsigned short)p5 == (unsigned short)-2) )) - { - /* This is a pre Sol2.6 inode */ - mod = 1; - cnt++; wcnt++; - if (verbose) - printf("AFS Inode %d: %s to 5.6 format (p1=%x,p2=%x,p3=%x,p4=%x, p5=%x)\n", - i, (force ? "Converting" : "Would have converted"), - p1, p2, p3, p4, p5); - if ( force ) - { - p->di_gid = VICEMAGIC; - p->di_uid = q->val[0]; - p->di_suid = UID_LONG; - p->di_sgid = GID_LONG; - q->val[0]=0; - } - continue; + } + } else { + if (p5 == VICEMAGIC) { /* Assume an already converted 5.6 afs inode */ + if (verbose) + printf + ("AFS Inode %d: Already in %s AFS format (p1=%x,p2=%x,p3=%x,p4=%x,p5=%x); ignoring..\n", + i, OSVERS, p1, p2, p3, p4, p5); + ccnt++; + continue; + } + + /* for inodes created in solaris 2.4, there is a possibility + ** that the gid gets chopped off to an unsigned short(2 bytes) + */ + if ((p2 || p3) && !p4 && ((p5 == -2) + || ((unsigned short)p5 == + (unsigned short)-2))) { + /* This is a pre Sol2.6 inode */ + mod = 1; + cnt++; + wcnt++; + if (verbose) + printf + ("AFS Inode %d: %s to 5.6 format (p1=%x,p2=%x,p3=%x,p4=%x, p5=%x)\n", + i, + (force ? "Converting" : + "Would have converted"), p1, p2, p3, p4, + p5); + if (force) { + p->di_gid = VICEMAGIC; + p->di_uid = q->val[0]; + p->di_suid = UID_LONG; + p->di_sgid = GID_LONG; + q->val[0] = 0; + } + continue; + } } + /* If not an AFS inode, ignore */ + ncnt++; + if (verbose) + printf + ("Non AFS Inode %d: (p1=%x,p2=%x,p3=%x, p4=%x,p5=%x) ignoring..\n", + i, p1, p2, p3, p4, p5); } - /* If not an AFS inode, ignore */ - ncnt++; - if ( verbose ) - printf("Non AFS Inode %d: (p1=%x,p2=%x,p3=%x, p4=%x,p5=%x) ignoring..\n", - i, p1, p2, p3, p4,p5); - } -#endif - - if (mod && force) { - if (lseek(pfd, -bufsize, SEEK_CUR) == -1) { /* Point to loc bef read */ - printf("Error Seeking backwards %d bytes\n", bufsize); - printf("errno %d: %s\n", errno, strerror(errno)); - goto out; - } - code = write(pfd, inodes, bufsize); - if (code != bufsize) { /* Update inodes */ - printf("Error writing modified inodes for partition %s\n", partition); - if (code<0) - printf("errno %d: %s\n", errno, strerror(errno)); - goto out; - } - if (verbose) { - printf(" Write %d AFS inodes and %d non-AFS inodes to disk\n", - wcnt, ncnt); +#endif + + if (mod && force) { + if (lseek(pfd, -bufsize, SEEK_CUR) == -1) { /* Point to loc bef read */ + printf("Error Seeking backwards %d bytes\n", bufsize); + printf("errno %d: %s\n", errno, strerror(errno)); + goto out; + } + code = write(pfd, inodes, bufsize); + if (code != bufsize) { /* Update inodes */ + printf("Error writing modified inodes for partition %s\n", + partition); + if (code < 0) + printf("errno %d: %s\n", errno, strerror(errno)); + goto out; + } + if (verbose) { + printf + (" Write %d AFS inodes and %d non-AFS inodes to disk\n", + wcnt, ncnt); + } } - } - } - } - - printf("\n%s: %d AFS inodes %s ", partition, cnt, (force?"were":"would have been")); - if (unconv) - printf("unconverted to a pre-%s format; %d already unconverted.\n", OSVERS, ccnt); - else - printf("converted to a %s format; %d already converted.\n", OSVERS, ccnt); - - close(pfd); - return 0; - -out: - close(pfd); - return -1; + } + } + + printf("\n%s: %d AFS inodes %s ", partition, cnt, + (force ? "were" : "would have been")); + if (unconv) + printf("unconverted to a pre-%s format; %d already unconverted.\n", + OSVERS, ccnt); + else + printf("converted to a %s format; %d already converted.\n", OSVERS, + ccnt); + + close(pfd); + return 0; + + out: + close(pfd); + return -1; } -int bread(fd, buf, blk, size) - int fd; - char *buf; - daddr_t blk; - afs_int32 size; +int +bread(fd, buf, blk, size) + int fd; + char *buf; + daddr_t blk; + afs_int32 size; { - if (lseek(fd, (off_t)dbtob(blk), L_SET) < 0 || read(fd, buf, size) != size) { + if (lseek(fd, (off_t) dbtob(blk), L_SET) < 0 + || read(fd, buf, size) != size) { printf("bread: lseek failed (errno = %d)\n", errno); return -1; } @@ -901,8 +971,9 @@ int bread(fd, buf, blk, size) * Ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device. * returns pointer to static storage; copy it out quickly! */ -char *vol_DevName(adev) - dev_t adev; +char * +vol_DevName(adev) + dev_t adev; { struct dirent *dp; static char pbuffer[128]; @@ -917,86 +988,87 @@ char *vol_DevName(adev) strcpy(pbuffer, dirName); strcat(pbuffer, "/"); strcat(pbuffer, dp->d_name); - if (stat(pbuffer, &tstat) != -1 && - (tstat.st_mode & S_IFMT) == S_IFBLK && - (tstat.st_rdev == adev)) { - strcpy(pbuffer, dp->d_name); - closedir(dirp); - return pbuffer; - } + if (stat(pbuffer, &tstat) != -1 && (tstat.st_mode & S_IFMT) == S_IFBLK + && (tstat.st_rdev == adev)) { + strcpy(pbuffer, dp->d_name); + closedir(dirp); + return pbuffer; + } } closedir(dirp); - return (char *) 0; /* failed */ + return NULL; /* failed */ } - -char *unrawname(name) - char *name; + +char * +unrawname(name) + char *name; { - char *dp; - struct stat stb; - - if ((dp = strrchr(name, '/')) == 0) - return (name); - if (stat(name, &stb) < 0) - return (name); - if ((stb.st_mode & S_IFMT) != S_IFCHR) - return (name); - if (*(dp + 1) != 'r') - return (name); - (void)strcpy(dp + 1, dp + 2); + char *dp; + struct stat stb; + + if ((dp = strrchr(name, '/')) == 0) + return (name); + if (stat(name, &stb) < 0) + return (name); + if ((stb.st_mode & S_IFMT) != S_IFCHR) return (name); + if (*(dp + 1) != 'r') + return (name); + (void)strcpy(dp + 1, dp + 2); + return (name); } char * rawname(name) - char *name; + char *name; { - static char rawbuf[32]; - char *dp; - - if ((dp = strrchr(name, '/')) == 0) - return (0); - *dp = 0; - (void)strcpy(rawbuf, name); - *dp = '/'; - (void)strcat(rawbuf, "/r"); - (void)strcat(rawbuf, dp + 1); - return (rawbuf); + static char rawbuf[32]; + char *dp; + + if ((dp = strrchr(name, '/')) == 0) + return (0); + *dp = 0; + (void)strcpy(rawbuf, name); + *dp = '/'; + (void)strcat(rawbuf, "/r"); + (void)strcat(rawbuf, dp + 1); + return (rawbuf); } -char *blockcheck(name) - char *name; +char * +blockcheck(name) + char *name; { - struct stat stslash, stblock, stchar; - char *raw; - int retried = 0; - -retry: - if (stat(name, &stblock) < 0) { - perror(name); - printf("Can't stat %s\n", name); - return (0); + struct stat stslash, stblock, stchar; + char *raw; + int retried = 0; + + retry: + if (stat(name, &stblock) < 0) { + perror(name); + printf("Can't stat %s\n", name); + return (0); + } + if ((stblock.st_mode & S_IFMT) == S_IFBLK) { + raw = rawname(name); + if (stat(raw, &stchar) < 0) { + perror(raw); + printf("Can't stat %s\n", raw); + return (name); } - if ((stblock.st_mode & S_IFMT) == S_IFBLK) { - raw = rawname(name); - if (stat(raw, &stchar) < 0) { - perror(raw); - printf("Can't stat %s\n", raw); - return (name); - } - if ((stchar.st_mode & S_IFMT) == S_IFCHR) { - return (raw); - } else { - printf("%s is not a character device\n", raw); - return (name); - } - } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) { - name = unrawname(name); - retried++; - goto retry; + if ((stchar.st_mode & S_IFMT) == S_IFCHR) { + return (raw); + } else { + printf("%s is not a character device\n", raw); + return (name); } - printf("Can't make sense out of name %s\n", name); - return (0); + } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) { + name = unrawname(name); + retried++; + goto retry; + } + printf("Can't make sense out of name %s\n", name); + return (0); } @@ -1004,7 +1076,8 @@ retry: * Overwrites abuffer with the corrected name. */ EnsureDevice(abuffer) -char *abuffer; { + char *abuffer; +{ struct dirent *dp; char pbuffer[128]; struct stat tstat; @@ -1014,9 +1087,11 @@ char *abuffer; { short dev; code = stat(abuffer, &tstat); - if (code) return code; - if (((tstat.st_mode & S_IFMT) == S_IFBLK) || ((tstat.st_mode & S_IFMT) == S_IFCHR)) { - return 0; /* already a block or char device */ + if (code) + return code; + if (((tstat.st_mode & S_IFMT) == S_IFBLK) + || ((tstat.st_mode & S_IFMT) == S_IFCHR)) { + return 0; /* already a block or char device */ } /* otherwise, assume we've got a normal file, and we look up its device */ dev = tstat.st_dev; /* remember device for this file */ @@ -1024,33 +1099,33 @@ char *abuffer; { /* now, look in /dev for the appropriate file */ dirp = opendir(dirName = "/dev"); - while (dp=readdir(dirp)) { + while (dp = readdir(dirp)) { strcpy(pbuffer, dirName); strcat(pbuffer, "/"); strcat(pbuffer, dp->d_name); - if (stat(pbuffer, &tstat) != -1 && - (tstat.st_mode & S_IFMT) == S_IFBLK && - (tstat.st_rdev == dev)) { - strcpy(abuffer, pbuffer); - closedir(dirp); - return 0; - } + if (stat(pbuffer, &tstat) != -1 && (tstat.st_mode & S_IFMT) == S_IFBLK + && (tstat.st_rdev == dev)) { + strcpy(abuffer, pbuffer); + closedir(dirp); + return 0; + } } closedir(dirp); - return 1; /* failed */ + return 1; /* failed */ } #else #include "AFS_component_version_number.c" main(argc, argv) - int argc; - char *argv[]; + int argc; + char *argv[]; { - printf("%s: **ONLY** supported for SunOS 3.5-4.x and dux4.0D systems ...\n", - argv[0]); + printf + ("%s: **ONLY** supported for SunOS 3.5-4.x and dux4.0D systems ...\n", + argv[0]); } -#endif /* defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV) */ +#endif /* defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV) */ #if defined(AFS_SUN54_ENV) @@ -1062,76 +1137,68 @@ main(argc, argv) ** Returns 1 if the conversion process should continue, otherwise returns 0 */ CheckMountedDevice(devName) -char* devName; /* raw device name */ + char *devName; /* raw device name */ { - FILE *vfsent, *mntent; - struct mnttab mnt; - struct vfstab vnt; - char* unRawDev=0; - char YesNo='y'; - int found = 0; - - if ( ( vfsent = fopen(VFSTAB, "r")) == NULL ) - { - printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno); - exit(2); - } - while (!getvfsent(vfsent, &vnt)) - { - char *rawDev = vnt.vfs_fsckdev; - if ( rawDev && !strcmp(rawDev, devName) ) - { - /* this is the device we are looking for */ - unRawDev = vnt.vfs_special; - break; - } - } - fclose(vfsent); - - if ( !unRawDev ) goto done; /* could not find it in /etc/vfstab */ - - /* we found the entry in /etc/vfstab. Now we open /etc/mnnttab and - ** verify that it is not mounted - */ - if ( ( mntent = fopen(MNTTAB, "r")) == NULL ) - { - printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno); - exit(2); - } - - while (!getmntent(mntent, &mnt)) - { - char* resource = mnt.mnt_special; - if ( resource && !strcmp(resource, unRawDev) ) - { - found = 1; - break; - } + FILE *vfsent, *mntent; + struct mnttab mnt; + struct vfstab vnt; + char *unRawDev = 0; + char YesNo = 'y'; + int found = 0; + + if ((vfsent = fopen(VFSTAB, "r")) == NULL) { + printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno); + exit(2); + } + while (!getvfsent(vfsent, &vnt)) { + char *rawDev = vnt.vfs_fsckdev; + if (rawDev && !strcmp(rawDev, devName)) { + /* this is the device we are looking for */ + unRawDev = vnt.vfs_special; + break; } - fclose(mntent); + } + fclose(vfsent); + if (!unRawDev) + goto done; /* could not find it in /etc/vfstab */ - /* if we found an entry in the /etc/mnttab file, then this - ** device must be mounted - */ - if ( found ) - { -done: - do - { - printf("Device %s may be mounted. Can corrupt data. Continue anyway(y/n)?", devName); - fflush(stdout); - fflush(stdin); - YesNo = getc(stdin); - } - while ( YesNo != 'y' && YesNo != 'Y' && - YesNo != 'n' && YesNo != 'N' ); + /* we found the entry in /etc/vfstab. Now we open /etc/mnnttab and + ** verify that it is not mounted + */ + if ((mntent = fopen(MNTTAB, "r")) == NULL) { + printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno); + exit(2); + } + + while (!getmntent(mntent, &mnt)) { + char *resource = mnt.mnt_special; + if (resource && !strcmp(resource, unRawDev)) { + found = 1; + break; } - if ( (YesNo == 'y') || ( YesNo == 'Y' ) ) - return 1; - return 0; + } + fclose(mntent); + + + /* if we found an entry in the /etc/mnttab file, then this + ** device must be mounted + */ + if (found) { + done: + do { + printf + ("Device %s may be mounted. Can corrupt data. Continue anyway(y/n)?", + devName); + fflush(stdout); + fflush(stdin); + YesNo = getc(stdin); + } + while (YesNo != 'y' && YesNo != 'Y' && YesNo != 'n' && YesNo != 'N'); + } + if ((YesNo == 'y') || (YesNo == 'Y')) + return 1; + return 0; } #endif /* AFS_SUN54_ENV */ - - diff --git a/src/vol/fssync.c b/src/vol/fssync.c index 76d8b1e4b..9e0906407 100644 --- a/src/vol/fssync.c +++ b/src/vol/fssync.c @@ -16,7 +16,7 @@ #ifdef notdef /* All this is going away in early 1989 */ -int newVLDB; /* Compatibility flag */ +int newVLDB; /* Compatibility flag */ #endif static int newVLDB = 1; @@ -38,7 +38,8 @@ static int newVLDB = 1; #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/fssync.c,v 1.1.1.9 2003/04/13 19:08:17 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/fssync.c,v 1.23 2003/12/08 06:09:12 shadow Exp $"); #include #include @@ -60,6 +61,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/fssync.c,v 1.1.1.9 2003/04/13 19:08 #endif /* AFS_PTHREAD_ENV */ #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + + #include #include #include "nfs.h" @@ -73,16 +83,22 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/fssync.c,v 1.1.1.9 2003/04/13 19:08 #include "volume.h" #include "partition.h" -extern int LogLevel; /* Vice loglevel */ -int (*V_BreakVolumeCallbacks)(); +/*@printflike@*/ extern void Log(const char *format, ...); + +#ifdef osi_Assert +#undef osi_Assert +#endif +#define osi_Assert(e) (void)(e) + +int (*V_BreakVolumeCallbacks) (); #define MAXHANDLERS 4 /* Up to 4 clients; must be at least 2, so that - move = dump+restore can run on single server */ + * move = dump+restore can run on single server */ #define MAXOFFLINEVOLUMES 30 /* This needs to be as big as the maximum - number that would be offline for 1 operation. - Current winner is salvage, which needs all - cloned read-only copies offline when salvaging - a single read-write volume */ + * number that would be offline for 1 operation. + * Current winner is salvage, which needs all + * cloned read-only copies offline when salvaging + * a single read-write volume */ #define MAX_BIND_TRIES 5 /* Number of times to retry socket bind */ @@ -94,8 +110,8 @@ struct offlineInfo { static struct offlineInfo OfflineVolumes[MAXHANDLERS][MAXOFFLINEVOLUMES]; -static FS_sd = -1; /* Client socket for talking to file server */ -static AcceptSd = -1; /* Socket used by server for accepting connections */ +static FS_sd = -1; /* Client socket for talking to file server */ +static AcceptSd = -1; /* Socket used by server for accepting connections */ static int getport(); @@ -103,12 +119,10 @@ struct command { bit32 command; bit32 reason; VolumeId volume; - char partName[16]; /* partition name, e.g. /vicepa */ + char partName[16]; /* partition name, e.g. /vicepa */ }; - /* Forward declarations */ -static int getport(); static void FSYNC_sync(); static void FSYNC_newconnection(); static void FSYNC_com(); @@ -116,12 +130,14 @@ static void FSYNC_Drop(); static void AcceptOn(); static void AcceptOff(); static void InitHandler(); -static void CallHandler(fd_set *fdsetp); +static void CallHandler(fd_set * fdsetp); static int AddHandler(); static int FindHandler(); static int FindHandler_r(); static int RemoveHandler(); -static void GetHandler(fd_set *fdsetp, int *maxfdp); +static void GetHandler(fd_set * fdsetp, int *maxfdp); + +extern int LogLevel; /* * This lock controls access to the handler array. The overhead @@ -129,16 +145,18 @@ static void GetHandler(fd_set *fdsetp, int *maxfdp); */ struct Lock FSYNC_handler_lock; -int FSYNC_clientInit(void) +int +FSYNC_clientInit(void) { struct sockaddr_in addr; /* I can't believe the following is needed for localhost connections!! */ - static backoff[] = {3,3,3,5,5,5,7,15,16,24,32,40,48,0}; - int *timeout = &backoff[0]; + static time_t backoff[] = + { 3, 3, 3, 5, 5, 5, 7, 15, 16, 24, 32, 40, 48, 0 }; + time_t *timeout = &backoff[0]; for (;;) { - FS_sd = getport(&addr); - if (connect(FS_sd, (struct sockaddr *) &addr, sizeof(addr)) >= 0) + FS_sd = getport(&addr); + if (connect(FS_sd, (struct sockaddr *)&addr, sizeof(addr)) >= 0) return 1; #if defined(AFS_SGI_ENV) /* down with worthless error messages! */ @@ -150,7 +168,7 @@ int FSYNC_clientInit(void) if (!*timeout) break; if (!(*timeout & 1)) - perror("FSYNC_clientInit temporary failure (will retry)"); + perror("FSYNC_clientInit temporary failure (will retry)"); #endif FSYNC_clientFinis(); sleep(*timeout++); @@ -159,7 +177,8 @@ int FSYNC_clientInit(void) return 0; } -void FSYNC_clientFinis(void) +void +FSYNC_clientFinis(void) { #ifdef AFS_NT40_ENV closesocket(FS_sd); @@ -170,7 +189,8 @@ void FSYNC_clientFinis(void) Lock_Destroy(&FSYNC_handler_lock); } -int FSYNC_askfs(VolumeId volume, char *partName, int com, int reason) +int +FSYNC_askfs(VolumeId volume, char *partName, int com, int reason) { byte response; struct command command; @@ -183,37 +203,47 @@ int FSYNC_askfs(VolumeId volume, char *partName, int com, int reason) else command.partName[0] = 0; assert(FS_sd != -1); + VFSYNC_LOCK #ifdef AFS_NT40_ENV - if (send(FS_sd, (char*)&command, sizeof(command), 0) != sizeof(command)) { + if (send(FS_sd, (char *)&command, sizeof(command), 0) != sizeof(command)) { printf("FSYNC_askfs: write to file server failed\n"); - return FSYNC_DENIED; + response = FSYNC_DENIED; + goto done; } while ((n = recv(FS_sd, &response, 1, 0)) != 1) { if (n == 0 || WSAEINTR != WSAGetLastError()) { printf("FSYNC_askfs: No response from file server\n"); - return FSYNC_DENIED; + response = FSYNC_DENIED; + goto done; } } #else if (write(FS_sd, &command, sizeof(command)) != sizeof(command)) { printf("FSYNC_askfs: write to file server failed\n"); - return FSYNC_DENIED; + response = FSYNC_DENIED; + goto done; } while ((n = read(FS_sd, &response, 1)) != 1) { if (n == 0 || errno != EINTR) { printf("FSYNC_askfs: No response from file server\n"); - return FSYNC_DENIED; + response = FSYNC_DENIED; + goto done; } } #endif if (response == 0) { - printf("FSYNC_askfs: negative response from file server; volume %u, command %d\n", command.volume, command.command); + printf + ("FSYNC_askfs: negative response from file server; volume %u, command %d\n", + command.volume, (int)command.command); } + done: + VFSYNC_UNLOCK return response; } -void FSYNC_fsInit(void) +void +FSYNC_fsInit(void) { #ifdef AFS_PTHREAD_ENV pthread_t tid; @@ -223,14 +253,14 @@ void FSYNC_fsInit(void) assert(pthread_create(&tid, &tattr, FSYNC_sync, NULL) == 0); #else /* AFS_PTHREAD_ENV */ PROCESS pid; - assert (LWP_CreateProcess(FSYNC_sync, USUAL_STACK_SIZE, - USUAL_PRIORITY, 0, - "FSYNC_sync", &pid) == LWP_SUCCESS); + assert(LWP_CreateProcess + (FSYNC_sync, USUAL_STACK_SIZE, USUAL_PRIORITY, (void *)0, + "FSYNC_sync", &pid) == LWP_SUCCESS); #endif /* AFS_PTHREAD_ENV */ } -static int getport(addr) - struct sockaddr_in *addr; +static int +getport(struct sockaddr_in *addr) { int sd; @@ -240,13 +270,15 @@ static int getport(addr) addr->sin_len = sizeof(struct sockaddr_in); #endif addr->sin_addr.s_addr = htonl(0x7f000001); - addr->sin_family = AF_INET; /* was localhost->h_addrtype */ - addr->sin_port = htons(2040); /* XXXX htons not _really_ neccessary */ + addr->sin_family = AF_INET; /* was localhost->h_addrtype */ + addr->sin_port = htons(2040); /* XXXX htons not _really_ neccessary */ return sd; } -static void FSYNC_sync() { +static void +FSYNC_sync() +{ struct sockaddr_in addr; int on = 1; extern VInit; @@ -257,42 +289,48 @@ static void FSYNC_sync() { #endif #ifndef AFS_NT40_ENV - signal(SIGPIPE, SIG_IGN); + (void)signal(SIGPIPE, SIG_IGN); #endif #ifdef AFS_PTHREAD_ENV - /* set our 'thread-id' so that the host hold table works */ - MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */ - tid=++rxi_pthread_hinum; + /* set our 'thread-id' so that the host hold table works */ + MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */ + tid = ++rxi_pthread_hinum; MUTEX_EXIT(&rx_stats_mutex); pthread_setspecific(rx_thread_id_key, (void *)tid); Log("Set thread id %d for FSYNC_sync\n", tid); #endif /* AFS_PTHREAD_ENV */ while (!VInit) { - /* Let somebody else run until level > 0. That doesn't mean that - * all volumes have been attached. */ + /* Let somebody else run until level > 0. That doesn't mean that + * all volumes have been attached. */ #ifdef AFS_PTHREAD_ENV pthread_yield(); #else /* AFS_PTHREAD_ENV */ - LWP_DispatchProcess(); + LWP_DispatchProcess(); #endif /* AFS_PTHREAD_ENV */ - } + } AcceptSd = getport(&addr); /* Reuseaddr needed because system inexplicably leaves crud lying around */ - code = setsockopt(AcceptSd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)); - if (code) Log("FSYNC_sync: setsockopt failed with (%d)\n",errno); - - for (numTries=0; numTries < MAX_BIND_TRIES; numTries++) { - if ((code = bind(AcceptSd, (struct sockaddr *) &addr, sizeof(addr))) == 0) break; - Log("FSYNC_sync: bind failed with (%d), will sleep and retry\n",errno); - sleep(5); + code = + setsockopt(AcceptSd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, + sizeof(on)); + if (code) + Log("FSYNC_sync: setsockopt failed with (%d)\n", errno); + + for (numTries = 0; numTries < MAX_BIND_TRIES; numTries++) { + if ((code = + bind(AcceptSd, (struct sockaddr *)&addr, sizeof(addr))) == 0) + break; + Log("FSYNC_sync: bind failed with (%d), will sleep and retry\n", + errno); + sleep(5); } assert(!code); - listen(AcceptSd,100); + listen(AcceptSd, 100); InitHandler(); AcceptOn(); - for(;;) { + for (;;) { fd_set readfds; int maxfd; GetHandler(&readfds, &maxfd); @@ -300,26 +338,25 @@ static void FSYNC_sync() { * doesn't have exactly same semantics as select. */ #ifdef AFS_PTHREAD_ENV - if (select(maxfd+1, &readfds, NULL, NULL, NULL) >= 1) + if (select(maxfd + 1, &readfds, NULL, NULL, NULL) >= 1) #else /* AFS_PTHREAD_ENV */ - if (IOMGR_Select(maxfd+1, &readfds, NULL, NULL, NULL) >= 1) + if (IOMGR_Select(maxfd + 1, &readfds, NULL, NULL, NULL) >= 1) #endif /* AFS_PTHREAD_ENV */ - CallHandler(&readfds); + CallHandler(&readfds); } } -static void FSYNC_newconnection(afd) - int afd; +static void +FSYNC_newconnection(int afd) { struct sockaddr_in other; int junk, fd; junk = sizeof(other); - fd = accept(afd, (struct sockaddr *) &other, &junk); + fd = accept(afd, (struct sockaddr *)&other, &junk); if (fd == -1) { - Log("FSYNC_newconnection: accept failed, errno==%d\n", errno); - assert(1==2); - } - else if (!AddHandler(fd, FSYNC_com)) { + Log("FSYNC_newconnection: accept failed, errno==%d\n", errno); + assert(1 == 2); + } else if (!AddHandler(fd, FSYNC_com)) { AcceptOff(); assert(AddHandler(fd, FSYNC_com)); } @@ -330,11 +367,11 @@ static void FSYNC_newconnection(afd) */ afs_int32 FS_cnt = 0; -static void FSYNC_com(fd) - int fd; +static void +FSYNC_com(int fd) { byte rc = FSYNC_OK; - int n, i, ack = 1; + int n, i; Error error; struct command command; int leaveonline; @@ -344,37 +381,36 @@ static void FSYNC_com(fd) FS_cnt++; #ifdef AFS_NT40_ENV - n = recv(fd, &command, sizeof (command), 0); -#else - n = read(fd, &command, sizeof (command)); + n = recv(fd, &command, sizeof(command), 0); +#else + n = read(fd, &command, sizeof(command)); #endif if (n <= 0) { FSYNC_Drop(fd); - return; + return; } if (n < sizeof(command)) { Log("FSYNC_com: partial read (%d instead of %d); dropping connection (cnt=%d)\n", n, sizeof(command), FS_cnt); FSYNC_Drop(fd); return; } - VATTACH_LOCK - VOL_LOCK - volumes = OfflineVolumes[FindHandler(fd)]; - for (v = 0, i = 0; ivolumeID = 0; - break; - case FSYNC_ON: + case FSYNC_DONE: + /* don't try to put online, this call is made only after deleting + * a volume, in which case we want to remove the vol # from the + * OfflineVolumes array only */ + if (v) + v->volumeID = 0; + break; + case FSYNC_ON: /* This is where a detatched volume gets reattached. However in the @@ -383,7 +419,7 @@ attatched and it is only necessary to clear the busy flag. See defect #2080 for details. */ - /* is the volume already attatched? */ + /* is the volume already attatched? */ #ifdef notdef /* * XXX With the following enabled we had bizarre problems where the backup id would @@ -393,53 +429,54 @@ defect #2080 for details. * VOffline, etc. when we don't want to; someday the whole #2080 issue should be revisited to * be done right XXX */ - vp=VGetVolume_r(&error,command.volume); - if(vp) { - /* yep, is the BUSY flag set? */ - if(vp->specialStatus==VBUSY) { + vp = VGetVolume_r(&error, command.volume); + if (vp) { + /* yep, is the BUSY flag set? */ + if (vp->specialStatus == VBUSY) { /* test harness for defect #2081 */ #ifdef TEST2081 - /* - test #2081 by releasing TEST.2081, - so leave it alone here, zap it after - */ + /* + * test #2081 by releasing TEST.2081, + * so leave it alone here, zap it after + */ - if(strcmp(vp->header->diskstuff.name,"TEST.2081")==0) - break; + if (strcmp(vp->header->diskstuff.name, "TEST.2081") == 0) + break; #endif - /* yep, clear BUSY flag */ - - vp->specialStatus=0; - /* make sure vol is online */ - if(v) { - v->volumeID=0; - V_inUse(vp)=1; /* online */ - } - VPutVolume_r(vp); - break; - } - VPutVolume_r(vp); + /* yep, clear BUSY flag */ + + vp->specialStatus = 0; + /* make sure vol is online */ + if (v) { + v->volumeID = 0; + V_inUse(vp) = 1; /* online */ } + VPutVolume_r(vp); + break; + } + VPutVolume_r(vp); + } #endif - /* so, we need to attach the volume */ + /* so, we need to attach the volume */ - if (v) - v->volumeID = 0; - tvolName[0] = '/'; - sprintf(&tvolName[1], VFORMAT, command.volume); + if (v) + v->volumeID = 0; + tvolName[0] = '/'; + sprintf(&tvolName[1], VFORMAT, command.volume); - vp = VAttachVolumeByName_r(&error, command.partName, tvolName, V_UPDATE); - if (vp) - VPutVolume_r(vp); - break; - case FSYNC_OFF: - case FSYNC_NEEDVOLUME: { + vp = VAttachVolumeByName_r(&error, command.partName, tvolName, + V_VOLUPD); + if (vp) + VPutVolume_r(vp); + break; + case FSYNC_OFF: + case FSYNC_NEEDVOLUME:{ leaveonline = 0; /* not already offline, we need to find a slot for newly offline volume */ if (!v) { - for (i = 0; ispecialStatus = VBUSY; - } + if (command.command == FSYNC_NEEDVOLUME + && (command.reason == V_CLONE + || command.reason == V_DUMP)) { + vp->specialStatus = VBUSY; + } /* remember what volume we got, so we can keep track of how * many volumes the volserver or whatever is using. Note that * vp is valid since leaveonline is only set when vp is valid. @@ -486,20 +524,14 @@ defect #2080 for details. * weird callers. */ VPutVolume_r(vp); - } - else { + } else { VOffline_r(vp, "A volume utility is running."); } vp = 0; - } - else { - VUpdateVolume_r(&error, vp); /* At least get volume stats right */ + } else { + VUpdateVolume_r(&error, vp); /* At least get volume stats right */ if (LogLevel) { - Log("FSYNC: Volume %u (%s) was left on line for an external %s request\n", - V_id(vp), V_name(vp), - command.reason == V_CLONE? "clone": - command.reason == V_READONLY? "readonly": - command.reason == V_DUMP? "dump" : "UNKNOWN"); + Log("FSYNC: Volume %u (%s) was left on line for an external %s request\n", V_id(vp), V_name(vp), command.reason == V_CLONE ? "clone" : command.reason == V_READONLY ? "readonly" : command.reason == V_DUMP ? "dump" : "UNKNOWN"); } } if (vp) @@ -508,91 +540,70 @@ defect #2080 for details. rc = FSYNC_OK; break; } - case FSYNC_MOVEVOLUME: - /* Yuch: the "reason" for the move is the site it got moved to... */ - /* still set specialStatus so we stop sending back VBUSY. - also should still break callbacks. Note that I don't know - how to tell if we should break all or not, so we just do it - since it doesn't matter much if we do an extra break - volume callbacks on a volume move within the same server */ - vp = VGetVolume_r(&error, command.volume); - if (vp) { - vp->specialStatus = VMOVED; - VPutVolume_r(vp); - } -#ifdef AFS_NT40_ENV - send(fd, &rc, 1, 0); -#else - write(fd, &rc, 1); -#endif - ack = 0; - if (V_BreakVolumeCallbacks) { - Log("fssync: volume %u moved to %x; breaking all call backs\n", - command.volume, command.reason); - VOL_UNLOCK - VATTACH_UNLOCK - (*V_BreakVolumeCallbacks)(command.volume); - VATTACH_LOCK - VOL_LOCK - } - break; - case FSYNC_RESTOREVOLUME: - /* if the volume is being restored, break all callbacks on it*/ -#ifdef AFS_NT40_ENV - send(fd, &rc, 1, 0); -#else - write(fd, &rc, 1); -#endif - ack = 0; - if (V_BreakVolumeCallbacks) { - VOL_UNLOCK - VATTACH_UNLOCK - (*V_BreakVolumeCallbacks)(command.volume); - VATTACH_LOCK - VOL_LOCK - } - break; - default: - rc = FSYNC_DENIED; - break; + case FSYNC_MOVEVOLUME: + /* Yuch: the "reason" for the move is the site it got moved to... */ + /* still set specialStatus so we stop sending back VBUSY. + * also should still break callbacks. Note that I don't know + * how to tell if we should break all or not, so we just do it + * since it doesn't matter much if we do an extra break + * volume callbacks on a volume move within the same server */ + vp = VGetVolume_r(&error, command.volume); + if (vp) { + vp->specialStatus = VMOVED; + VPutVolume_r(vp); + } + + if (V_BreakVolumeCallbacks) { + Log("fssync: volume %u moved to %x; breaking all call backs\n", + command.volume, command.reason); + VOL_UNLOCK VATTACH_UNLOCK(*V_BreakVolumeCallbacks) (command. + volume); + VATTACH_LOCK VOL_LOCK} + break; + case FSYNC_RESTOREVOLUME: + /* if the volume is being restored, break all callbacks on it */ + if (V_BreakVolumeCallbacks) { + Log("fssync: volume %u restored; breaking all call backs\n", + command.volume); + VOL_UNLOCK VATTACH_UNLOCK(*V_BreakVolumeCallbacks) (command. + volume); + VATTACH_LOCK VOL_LOCK} + break; + default: + rc = FSYNC_DENIED; + break; } - VOL_UNLOCK - VATTACH_UNLOCK - if (ack) { + VOL_UNLOCK VATTACH_UNLOCK #ifdef AFS_NT40_ENV - send(fd, &rc, 1, 0); + (void) send(fd, &rc, 1, 0); #else - write(fd, &rc, 1); + (void) write(fd, &rc, 1); #endif - } } -static void FSYNC_Drop(fd) - int fd; +static void +FSYNC_Drop(int fd) { struct offlineInfo *p; register i; Error error; char tvolName[VMAXPATHLEN]; - VATTACH_LOCK - VOL_LOCK - p = OfflineVolumes[FindHandler(fd)]; - for (i = 0; i= 0 && FD_ISSET(HandlerFD[i], fdsetp)) { ReleaseReadLock(&FSYNC_handler_lock); - (*HandlerProc[i])(HandlerFD[i]); + (*HandlerProc[i]) (HandlerFD[i]); ObtainReadLock(&FSYNC_handler_lock); } } ReleaseReadLock(&FSYNC_handler_lock); } -static int AddHandler (afd, aproc) - int afd; - int (*aproc)(); +static int +AddHandler(int afd, int (*aproc) ()) { register int i; ObtainWriteLock(&FSYNC_handler_lock); - for(i=0;i=MAXHANDLERS) { + for (i = 0; i < MAXHANDLERS; i++) + if (HandlerFD[i] == -1) + break; + if (i >= MAXHANDLERS) { ReleaseWriteLock(&FSYNC_handler_lock); return 0; } @@ -665,35 +682,35 @@ static int AddHandler (afd, aproc) return 1; } -static int FindHandler (afd) - register int afd; +static int +FindHandler(register int afd) { register int i; ObtainReadLock(&FSYNC_handler_lock); - for(i=0;i + #if defined(AFS_DARWIN_ENV) /*----------------------------------------------------------------------- * This version of fstab.c is intended to be used on Darwin systems to diff --git a/src/vol/gi.c b/src/vol/gi.c index e3a66bb03..5fd02da3d 100644 --- a/src/vol/gi.c +++ b/src/vol/gi.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/gi.c,v 1.1.1.5 2001/09/11 14:35:42 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/gi.c,v 1.8 2003/07/15 23:17:38 shadow Exp $"); #include #include @@ -20,65 +21,71 @@ int statflag; #include "AFS_component_version_number.c" -main(argc,argv) -char **argv; +void +Perror(char *err, int a1, int a2, int a3) { - int error=0; - struct stat status; - int dev, fd, inode; + char msg[200]; + sprintf(msg, err, a1, a2, a3); + perror(msg); +} + +int +main(int argc, char **argv) +{ + int error = 0; + struct stat status; + int dev, fd, inode; #if defined(AFS_NT40_ENV) || defined(AFS_NAMEI_ENV) - fprintf(stderr, "gi not supported on NT or NAMEI systems.\n"); - exit(1); + fprintf(stderr, "gi not supported on NT or NAMEI systems.\n"); + exit(1); #else - argc--; argv++; - while (argc && **argv == '-') { - if (strcmp(*argv, "-stat") == 0) - statflag = 1; - else { - error=1; - break; - } - argc--; argv++; - } - if (error || argc!=2) { - fprintf(stderr, "Usage: gi [-stat] partition inodenumber\n"); - exit(1); - } - if (stat(*argv, &status) != 0) { - fprintf(stderr, "gi: cannot stat %s [should be mounted partition name]\n", *argv); - exit(1); - } - dev = status.st_dev; - inode = atoi(*++argv); - fd = iopen(dev, inode, 0); - if (fd < 0) { - Perror("Unable to open inode %d", inode); - exit(1); - } - if (statflag) { - if (fstat(fd, &status) != 0) { - Perror("Unable to fstat the inode!"); - exit(1); - } - printf("Inode status: dev=%d, ino=%d, mode=%o, nlink=%d, uid=%d, gid=%d, size=%d, mtime=%d, blocks=%d\n", status.st_dev, status.st_ino, status.st_mode, status.st_nlink, status.st_uid, status.st_gid, status.st_size, status.st_mtime); - } + argc--; + argv++; + while (argc && **argv == '-') { + if (strcmp(*argv, "-stat") == 0) + statflag = 1; else { - /* Send the inode to standard out */ - char buf[4096]; int n; - while ((n = read(fd, buf, sizeof(buf))) >0) - write(1, buf, n); + error = 1; + break; } - exit(0); + argc--; + argv++; + } + if (error || argc != 2) { + fprintf(stderr, "Usage: gi [-stat] partition inodenumber\n"); + exit(1); + } + if (stat(*argv, &status) != 0) { + fprintf(stderr, + "gi: cannot stat %s [should be mounted partition name]\n", + *argv); + exit(1); + } + dev = status.st_dev; + inode = atoi(*++argv); + fd = iopen(dev, inode, 0); + if (fd < 0) { + Perror("Unable to open inode %d", inode, 0, 0); + exit(1); + } + if (statflag) { + if (fstat(fd, &status) != 0) { + Perror("Unable to fstat the inode!", 0, 0, 0); + exit(1); + } + printf + ("Inode status: dev=%d, ino=%d, mode=%o, nlink=%d, uid=%d, gid=%d, size=%d, mtime=%d, blocks=%d\n", + status.st_dev, status.st_ino, status.st_mode, status.st_nlink, + status.st_uid, status.st_gid, status.st_size, status.st_mtime); + } else { + /* Send the inode to standard out */ + char buf[4096]; + int n; + while ((n = read(fd, buf, sizeof(buf))) > 0) + write(1, buf, n); + } + exit(0); #endif /* AFS_NT40_ENV || AFS_NAMEI_ENV */ } - -Perror(err, a1, a2, a3) - char *err; -{ - char msg[200]; - sprintf(msg, err, a1, a2, a3); - perror(msg); -} - diff --git a/src/vol/ihandle.c b/src/vol/ihandle.c index 9a38dea5f..e5b21ea41 100644 --- a/src/vol/ihandle.c +++ b/src/vol/ihandle.c @@ -14,7 +14,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/ihandle.c,v 1.1.1.8 2002/12/11 02:46:15 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/ihandle.c,v 1.18 2003/12/09 19:58:28 shadow Exp $"); #include #include @@ -30,12 +31,19 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/ihandle.c,v 1.1.1.8 2002/12/11 02:4 #include #endif #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include #include #include #include -#include "ihandle.h" #include "nfs.h" +#include "ihandle.h" #include "viceinode.h" #ifdef AFS_PTHREAD_ENV #include @@ -44,7 +52,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/ihandle.c,v 1.1.1.8 2002/12/11 02:4 #endif /* AFS_PTHREAD_ENV */ #include -extern afs_int32 DErrno; +#ifndef AFS_NT40_ENV +#ifdef O_LARGEFILE +#define afs_stat stat64 +#define afs_fstat fstat64 +#else /* !O_LARGEFILE */ +#define afs_stat stat +#define afs_fstat fstat +#endif /* !O_LARGEFILE */ +#endif /* AFS_NT40_ENV */ #ifdef AFS_PTHREAD_ENV pthread_once_t ih_glock_once = PTHREAD_ONCE_INIT; @@ -85,21 +101,24 @@ IHashBucket_t ihashTable[I_HANDLE_HASH_SIZE]; #ifdef AFS_PTHREAD_ENV /* Initialize the global ihandle mutex */ -void ih_glock_init() +void +ih_glock_init() { assert(pthread_mutex_init(&ih_glock_mutex, NULL) == 0); } #endif /* AFS_PTHREAD_ENV */ /* Initialize the file descriptor cache */ -void ih_Initialize() { +void +ih_Initialize(void) +{ int i; assert(!ih_Inited); ih_Inited = 1; DLL_INIT_LIST(ihAvailHead, ihAvailTail); DLL_INIT_LIST(fdAvailHead, fdAvailTail); DLL_INIT_LIST(fdLruHead, fdLruTail); - for (i = 0 ; i < I_HANDLE_HASH_SIZE ; i++) { + for (i = 0; i < I_HANDLE_HASH_SIZE; i++) { DLL_INIT_LIST(ihashTable[i].ihash_head, ihashTable[i].ihash_tail); } #if defined(AFS_NT40_ENV) @@ -110,7 +129,7 @@ void ih_Initialize() { assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0); rlim.rlim_cur = rlim.rlim_max; assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0); - fdMaxCacheSize = rlim.rlim_cur-FD_HANDLE_SETASIDE; + fdMaxCacheSize = rlim.rlim_cur - FD_HANDLE_SETASIDE; #ifdef AFS_NBSD_ENV /* XXX this is to avoid using up all system fd netbsd is * somewhat broken and have set maximum fd for a root process @@ -129,57 +148,61 @@ void ih_Initialize() { /* Avoid problems with "UFSOpen: igetinode failed" panics on HPUX 11.0 */ fdMaxCacheSize = 0; #else - fdMaxCacheSize = MAX(sysconf(_SC_OPEN_MAX)-FD_HANDLE_SETASIDE, 0); - fdMaxCacheSize = MIN(fdMaxCacheSize, FD_MAX_CACHESIZE); + { + long fdMax = MAX(sysconf(_SC_OPEN_MAX) - FD_HANDLE_SETASIDE, 0); + fdMaxCacheSize = (int)MIN(fdMax, FD_MAX_CACHESIZE); + } #endif fdCacheSize = MIN(fdMaxCacheSize, FD_DEFAULT_CACHESIZE); } /* Make the file descriptor cache as big as possible. Don't this call * if the program uses fopen or fdopen. */ -void ih_UseLargeCache() { - IH_LOCK - +void +ih_UseLargeCache(void) +{ + IH_LOCK; if (!ih_Inited) { ih_Initialize(); } fdCacheSize = fdMaxCacheSize; - IH_UNLOCK + IH_UNLOCK; } /* Allocate a chunk of inode handles */ -void iHandleAllocateChunk() +void +iHandleAllocateChunk(void) { int i; IHandle_t *ihP; assert(ihAvailHead == NULL); - ihP = (IHandle_t *)malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t)); + ihP = (IHandle_t *) malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t)); assert(ihP != NULL); - for (i = 0 ; i < I_HANDLE_MALLOCSIZE ; i++) { + for (i = 0; i < I_HANDLE_MALLOCSIZE; i++) { ihP[i].ih_refcnt = 0; DLL_INSERT_TAIL(&ihP[i], ihAvailHead, ihAvailTail, ih_next, ih_prev); } } /* Initialize an inode handle */ -IHandle_t *ih_init(int dev, int vid, Inode ino) +IHandle_t * +ih_init(int dev, int vid, Inode ino) { int ihash = IH_HASH(dev, vid, ino); IHandle_t *ihP; - IH_LOCK - + IH_LOCK; if (!ih_Inited) { ih_Initialize(); } /* Do we already have a handle for this Inode? */ - for (ihP = ihashTable[ihash].ihash_head ; ihP ; ihP = ihP->ih_next) { + for (ihP = ihashTable[ihash].ihash_head; ihP; ihP = ihP->ih_next) { if (ihP->ih_ino == ino && ihP->ih_vid == vid && ihP->ih_dev == dev) { ihP->ih_refcnt++; - IH_UNLOCK + IH_UNLOCK; return ihP; } } @@ -199,31 +222,33 @@ IHandle_t *ih_init(int dev, int vid, Inode ino) DLL_INIT_LIST(ihP->ih_fdhead, ihP->ih_fdtail); DLL_INSERT_TAIL(ihP, ihashTable[ihash].ihash_head, ihashTable[ihash].ihash_tail, ih_next, ih_prev); - IH_UNLOCK + IH_UNLOCK; return ihP; } /* Copy an inode handle */ -IHandle_t *ih_copy(IHandle_t *ihP) +IHandle_t * +ih_copy(IHandle_t * ihP) { - IH_LOCK + IH_LOCK; assert(ih_Inited); assert(ihP->ih_refcnt > 0); ihP->ih_refcnt++; - IH_UNLOCK + IH_UNLOCK; return ihP; } /* Allocate a chunk of file descriptor handles */ -void fdHandleAllocateChunk() +void +fdHandleAllocateChunk(void) { int i; FdHandle_t *fdP; assert(fdAvailHead == NULL); - fdP = (FdHandle_t *)malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t)); + fdP = (FdHandle_t *) malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t)); assert(fdP != NULL); - for (i = 0 ; i < FD_HANDLE_MALLOCSIZE ; i++) { + for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) { fdP[i].fd_status = FD_HANDLE_AVAIL; fdP[i].fd_ih = NULL; fdP[i].fd_fd = INVALID_FD; @@ -232,16 +257,17 @@ void fdHandleAllocateChunk() } /* Allocate a chunk of stream handles */ -void streamHandleAllocateChunk() +void +streamHandleAllocateChunk(void) { int i; StreamHandle_t *streamP; assert(streamAvailHead == NULL); streamP = (StreamHandle_t *) - malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t)); + malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t)); assert(streamP != NULL); - for (i = 0 ; i < STREAM_HANDLE_MALLOCSIZE ; i++) { + for (i = 0; i < STREAM_HANDLE_MALLOCSIZE; i++) { streamP[i].str_fd = INVALID_FD; DLL_INSERT_TAIL(&streamP[i], streamAvailHead, streamAvailTail, str_next, str_prev); @@ -251,26 +277,27 @@ void streamHandleAllocateChunk() /* * Get a file descriptor handle given an Inode handle */ -FdHandle_t *ih_open(IHandle_t *ihP) +FdHandle_t * +ih_open(IHandle_t * ihP) { FdHandle_t *fdP; FD_t fd; FD_t closeFd; - if (!ihP) /* XXX should log here in the fileserver */ + if (!ihP) /* XXX should log here in the fileserver */ return NULL; - IH_LOCK + IH_LOCK; /* Do we already have an open file handle for this Inode? */ - for (fdP = ihP->ih_fdtail ; fdP != NULL ; fdP = fdP->fd_ihprev) { + for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) { if (fdP->fd_status != FD_HANDLE_INUSE) { assert(fdP->fd_status == FD_HANDLE_OPEN); fdP->fd_status = FD_HANDLE_INUSE; DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); ihP->ih_refcnt++; - IH_UNLOCK - FDH_SEEK(fdP, 0, SEEK_SET); + IH_UNLOCK; + (void) FDH_SEEK(fdP, 0, SEEK_SET); return fdP; } } @@ -279,12 +306,12 @@ FdHandle_t *ih_open(IHandle_t *ihP) * Try to open the Inode, return NULL on error. */ fdInUseCount += 1; - IH_UNLOCK + IH_UNLOCK; fd = OS_IOPEN(ihP); - IH_LOCK + IH_LOCK; if (fd == INVALID_FD) { fdInUseCount -= 1; - IH_UNLOCK + IH_UNLOCK; return NULL; } @@ -297,7 +324,7 @@ FdHandle_t *ih_open(IHandle_t *ihP) assert(fdP->fd_status == FD_HANDLE_OPEN); DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail, - fd_ihnext, fd_ihprev); + fd_ihnext, fd_ihprev); closeFd = fdP->fd_fd; } else { if (fdAvailHead == NULL) { @@ -316,32 +343,32 @@ FdHandle_t *ih_open(IHandle_t *ihP) ihP->ih_refcnt++; /* Add this handle to the Inode's list of open descriptors */ - DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev); + DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, + fd_ihprev); if (closeFd != INVALID_FD) { - IH_UNLOCK + IH_UNLOCK; OS_CLOSE(closeFd); - IH_LOCK + IH_LOCK; fdInUseCount -= 1; } - IH_UNLOCK + IH_UNLOCK; return fdP; } /* * Return a file descriptor handle to the cache */ -int fd_close(FdHandle_t *fdP) +int +fd_close(FdHandle_t * fdP) { - FD_t closeFd; IHandle_t *ihP; if (!fdP) return 0; - IH_LOCK - + IH_LOCK; assert(ih_Inited); assert(fdInUseCount > 0); assert(fdP->fd_status == FD_HANDLE_INUSE); @@ -354,7 +381,7 @@ int fd_close(FdHandle_t *fdP) * IH_REALLY_CLOSED) or we have too many open files. */ if (ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize) { - IH_UNLOCK + IH_UNLOCK; return fd_reallyclose(fdP); } @@ -367,9 +394,9 @@ int fd_close(FdHandle_t *fdP) */ if (ihP->ih_refcnt > 1) { ihP->ih_refcnt--; - IH_UNLOCK + IH_UNLOCK; } else { - IH_UNLOCK + IH_UNLOCK; ih_release(ihP); } @@ -380,7 +407,8 @@ int fd_close(FdHandle_t *fdP) * Actually close the file descriptor handle and return it to * the free list. */ -int fd_reallyclose(FdHandle_t *fdP) +int +fd_reallyclose(FdHandle_t * fdP) { FD_t closeFd; IHandle_t *ihP; @@ -388,8 +416,7 @@ int fd_reallyclose(FdHandle_t *fdP) if (!fdP) return 0; - IH_LOCK - + IH_LOCK; assert(ih_Inited); assert(fdInUseCount > 0); assert(fdP->fd_status == FD_HANDLE_INUSE); @@ -409,22 +436,21 @@ int fd_reallyclose(FdHandle_t *fdP) * has completed its job. */ if (!ihP->ih_fdhead) { - ihP->ih_flags &= ~IH_REALLY_CLOSED; + ihP->ih_flags &= ~IH_REALLY_CLOSED; } - IH_UNLOCK + IH_UNLOCK; OS_CLOSE(closeFd); - IH_LOCK - + IH_LOCK; fdInUseCount -= 1; /* If this is not the only reference to the Inode then we can decrement * the reference count, otherwise we need to call ih_release. */ if (ihP->ih_refcnt > 1) { ihP->ih_refcnt--; - IH_UNLOCK + IH_UNLOCK; } else { - IH_UNLOCK + IH_UNLOCK; ih_release(ihP); } @@ -432,18 +458,18 @@ int fd_reallyclose(FdHandle_t *fdP) } /* Enable buffered I/O on a file descriptor */ -StreamHandle_t *stream_fdopen(FD_t fd) +StreamHandle_t * +stream_fdopen(FD_t fd) { StreamHandle_t *streamP; - IH_LOCK + IH_LOCK; if (streamAvailHead == NULL) { streamHandleAllocateChunk(); } streamP = streamAvailHead; DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev); - IH_UNLOCK - + IH_UNLOCK; streamP->str_fd = fd; streamP->str_buflen = 0; streamP->str_bufoff = 0; @@ -454,7 +480,8 @@ StreamHandle_t *stream_fdopen(FD_t fd) } /* Open a file for buffered I/O */ -StreamHandle_t *stream_open(const char *filename, const char *mode) +StreamHandle_t * +stream_open(const char *filename, const char *mode) { FD_t fd; @@ -463,15 +490,15 @@ StreamHandle_t *stream_open(const char *filename, const char *mode) } else if (strcmp(mode, "r+") == 0) { fd = OS_OPEN(filename, O_RDWR, 0); } else if (strcmp(mode, "w") == 0) { - fd = OS_OPEN(filename, O_WRONLY|O_TRUNC|O_CREAT, 0); + fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0); } else if (strcmp(mode, "w+") == 0) { - fd = OS_OPEN(filename, O_RDWR|O_TRUNC|O_CREAT, 0); + fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0); } else if (strcmp(mode, "a") == 0) { - fd = OS_OPEN(filename, O_WRONLY|O_APPEND|O_CREAT, 0); + fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0); } else if (strcmp(mode, "a+") == 0) { - fd = OS_OPEN(filename, O_RDWR|O_APPEND|O_CREAT, 0); + fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0); } else { - assert(FALSE); /* not implemented */ + assert(FALSE); /* not implemented */ } if (fd == INVALID_FD) { @@ -481,9 +508,11 @@ StreamHandle_t *stream_open(const char *filename, const char *mode) } /* fread for buffered I/O handles */ -int stream_read(void *ptr, int size, int nitems, StreamHandle_t *streamP) +afs_sfsize_t +stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems, + StreamHandle_t * streamP) { - int nbytes, bytesRead, bytesToRead; + afs_fsize_t nbytes, bytesRead, bytesToRead; char *p; /* Need to seek before changing direction */ @@ -501,8 +530,9 @@ int stream_read(void *ptr, int size, int nitems, StreamHandle_t *streamP) while (nbytes > 0 && !streamP->str_eof) { if (streamP->str_buflen == 0) { streamP->str_bufoff = 0; - streamP->str_buflen = OS_READ(streamP->str_fd, streamP->str_buffer, - STREAM_HANDLE_BUFSIZE); + streamP->str_buflen = + OS_READ(streamP->str_fd, streamP->str_buffer, + STREAM_HANDLE_BUFSIZE); if (streamP->str_buflen < 0) { streamP->str_error = errno; streamP->str_buflen = 0; @@ -518,7 +548,7 @@ int stream_read(void *ptr, int size, int nitems, StreamHandle_t *streamP) if (bytesToRead > streamP->str_buflen) { bytesToRead = streamP->str_buflen; } - memcpy(p, streamP->str_buffer+streamP->str_bufoff, bytesToRead); + memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead); p += bytesToRead; streamP->str_bufoff += bytesToRead; streamP->str_buflen -= bytesToRead; @@ -526,14 +556,17 @@ int stream_read(void *ptr, int size, int nitems, StreamHandle_t *streamP) nbytes -= bytesToRead; } - return (bytesRead/size); + return (bytesRead / size); } /* fwrite for buffered I/O handles */ -int stream_write(void *ptr, int size, int nitems, StreamHandle_t *streamP) +afs_sfsize_t +stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems, + StreamHandle_t * streamP) { char *p; - int rc, nbytes, bytesWritten, bytesToWrite; + afs_sfsize_t rc; + afs_fsize_t nbytes, bytesWritten, bytesToWrite; /* Need to seek before changing direction */ if (streamP->str_direction == STREAM_DIRECTION_NONE) { @@ -564,7 +597,7 @@ int stream_write(void *ptr, int size, int nitems, StreamHandle_t *streamP) if (bytesToWrite > streamP->str_buflen) { bytesToWrite = streamP->str_buflen; } - memcpy(streamP->str_buffer+streamP->str_bufoff, p, bytesToWrite); + memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite); p += bytesToWrite; streamP->str_bufoff += bytesToWrite; streamP->str_buflen -= bytesToWrite; @@ -572,17 +605,18 @@ int stream_write(void *ptr, int size, int nitems, StreamHandle_t *streamP) nbytes -= bytesToWrite; } - return (bytesWritten/size); + return (bytesWritten / size); } /* fseek for buffered I/O handles */ -int stream_seek(StreamHandle_t *streamP, int offset, int whence) +int +stream_seek(StreamHandle_t * streamP, afs_foff_t offset, int whence) { int rc; int retval = 0; - if (streamP->str_direction == STREAM_DIRECTION_WRITE && - streamP->str_bufoff > 0) { + if (streamP->str_direction == STREAM_DIRECTION_WRITE + && streamP->str_bufoff > 0) { rc = OS_WRITE(streamP->str_fd, streamP->str_buffer, streamP->str_bufoff); if (rc < 0) { @@ -602,13 +636,14 @@ int stream_seek(StreamHandle_t *streamP, int offset, int whence) } /* fflush for buffered I/O handles */ -int stream_flush(StreamHandle_t *streamP) +int +stream_flush(StreamHandle_t * streamP) { int rc; int retval = 0; - if (streamP->str_direction == STREAM_DIRECTION_WRITE && - streamP->str_bufoff > 0) { + if (streamP->str_direction == STREAM_DIRECTION_WRITE + && streamP->str_bufoff > 0) { rc = OS_WRITE(streamP->str_fd, streamP->str_buffer, streamP->str_bufoff); if (rc < 0) { @@ -623,14 +658,15 @@ int stream_flush(StreamHandle_t *streamP) } /* Free a buffered I/O handle */ -int stream_close(StreamHandle_t *streamP, int reallyClose) +int +stream_close(StreamHandle_t * streamP, int reallyClose) { int rc; int retval = 0; assert(streamP != NULL); - if (streamP->str_direction == STREAM_DIRECTION_WRITE && - streamP->str_bufoff > 0) { + if (streamP->str_direction == STREAM_DIRECTION_WRITE + && streamP->str_bufoff > 0) { rc = OS_WRITE(streamP->str_fd, streamP->str_buffer, streamP->str_bufoff); if (rc < 0) { @@ -645,11 +681,10 @@ int stream_close(StreamHandle_t *streamP, int reallyClose) } streamP->str_fd = INVALID_FD; - IH_LOCK + IH_LOCK; DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail, str_next, str_prev); - IH_UNLOCK - + IH_UNLOCK; return retval; } @@ -658,7 +693,8 @@ int stream_close(StreamHandle_t *streamP, int reallyClose) * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle * if it fails to close all file handles. */ -static int ih_fdclose(IHandle_t *ihP) +static int +ih_fdclose(IHandle_t * ihP) { int closeCount, closedAll; FdHandle_t *fdP, *head, *tail, *next; @@ -675,50 +711,48 @@ static int ih_fdclose(IHandle_t *ihP) * can drop the lock before we close the files. */ for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) { - next = fdP->fd_ihnext; - assert(fdP->fd_ih == ihP); - assert(fdP->fd_status == FD_HANDLE_OPEN || - fdP->fd_status == FD_HANDLE_INUSE); - if (fdP->fd_status == FD_HANDLE_OPEN) { - DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, - fd_ihnext, fd_ihprev); - DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); - DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev); - } else { - closedAll = 0; - ihP->ih_flags |= IH_REALLY_CLOSED; - } + next = fdP->fd_ihnext; + assert(fdP->fd_ih == ihP); + assert(fdP->fd_status == FD_HANDLE_OPEN + || fdP->fd_status == FD_HANDLE_INUSE); + if (fdP->fd_status == FD_HANDLE_OPEN) { + DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, + fd_ihprev); + DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); + DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev); + } else { + closedAll = 0; + ihP->ih_flags |= IH_REALLY_CLOSED; + } } /* If the ihandle reference count is 1, we should have * closed all file descriptors. */ if (ihP->ih_refcnt == 1 || closedAll) { - assert(closedAll); - assert(!ihP->ih_fdhead); - assert(!ihP->ih_fdtail); + assert(closedAll); + assert(!ihP->ih_fdhead); + assert(!ihP->ih_fdtail); } if (head == NULL) { - return 0; /* No file descriptors closed */ + return 0; /* No file descriptors closed */ } - IH_UNLOCK - + IH_UNLOCK; /* * Close the file descriptors */ closeCount = 0; for (fdP = head; fdP != NULL; fdP = fdP->fd_next) { - OS_CLOSE(fdP->fd_fd); - fdP->fd_status = FD_HANDLE_AVAIL; - fdP->fd_fd = INVALID_FD; - fdP->fd_ih = NULL; - closeCount++; + OS_CLOSE(fdP->fd_fd); + fdP->fd_status = FD_HANDLE_AVAIL; + fdP->fd_fd = INVALID_FD; + fdP->fd_ih = NULL; + closeCount++; } - IH_LOCK - + IH_LOCK; assert(fdInUseCount >= closeCount); fdInUseCount -= closeCount; @@ -726,56 +760,55 @@ static int ih_fdclose(IHandle_t *ihP) * Append the temporary queue to the list of available descriptors */ if (fdAvailHead == NULL) { - fdAvailHead = head; - fdAvailTail = tail; + fdAvailHead = head; + fdAvailTail = tail; } else { - fdAvailTail->fd_next = head; - head->fd_prev = fdAvailTail; - fdAvailTail = tail; + fdAvailTail->fd_next = head; + head->fd_prev = fdAvailTail; + fdAvailTail = tail; } return 0; } /* Close all cached file descriptors for this inode. */ -int ih_reallyclose(IHandle_t *ihP) +int +ih_reallyclose(IHandle_t * ihP) { if (!ihP) - return 0; - - IH_LOCK + return 0; + IH_LOCK; assert(ihP->ih_refcnt > 0); ih_fdclose(ihP); - IH_UNLOCK - + IH_UNLOCK; return 0; } /* Release an Inode handle. All cached file descriptors for this * inode are closed when the last reference to this handle is released */ -int ih_release(IHandle_t *ihP) +int +ih_release(IHandle_t * ihP) { int ihash; if (!ihP) - return 0; - - IH_LOCK + return 0; + IH_LOCK; assert(ihP->ih_refcnt > 0); if (ihP->ih_refcnt > 1) { - ihP->ih_refcnt--; - IH_UNLOCK - return 0; + ihP->ih_refcnt--; + IH_UNLOCK; + return 0; } ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino); DLL_DELETE(ihP, ihashTable[ihash].ihash_head, - ihashTable[ihash].ihash_tail, ih_next, ih_prev); + ihashTable[ihash].ihash_tail, ih_next, ih_prev); ih_fdclose(ihP); @@ -783,13 +816,13 @@ int ih_release(IHandle_t *ihP) DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev); - IH_UNLOCK - + IH_UNLOCK; return 0; } /* Sync an inode to disk if its handle isn't NULL */ -int ih_condsync(IHandle_t *ihP) +int +ih_condsync(IHandle_t * ihP) { int code; FdHandle_t *fdP; @@ -813,8 +846,9 @@ int ih_condsync(IHandle_t *ihP) * OS specific support routines. *************************************************************************/ #ifndef AFS_NAMEI_ENV -Inode ih_icreate(IHandle_t *ih, int dev, char *part, Inode nI, int p1, int p2, - int p3, int p4) +Inode +ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2, + int p3, int p4) { Inode ino; #ifdef AFS_3DISPARES @@ -832,10 +866,11 @@ Inode ih_icreate(IHandle_t *ih, int dev, char *part, Inode nI, int p1, int p2, #ifndef AFS_NT40_ENV -int ih_size(int fd) +afs_sfsize_t +ih_size(int fd) { - struct stat status; - if (fstat(fd, &status)<0) + struct afs_stat status; + if (afs_fstat(fd, &status) < 0) return -1; return status.st_size; } diff --git a/src/vol/ihandle.h b/src/vol/ihandle.h index a14f2f7f1..bc6a07531 100644 --- a/src/vol/ihandle.h +++ b/src/vol/ihandle.h @@ -155,12 +155,12 @@ typedef int FD_t; /* file descriptor handle */ typedef struct FdHandle_s { - int fd_status; /* status flags */ - FD_t fd_fd; /* file descriptor */ - struct IHandle_s *fd_ih; /* Pointer to Inode handle */ + int fd_status; /* status flags */ + FD_t fd_fd; /* file descriptor */ + struct IHandle_s *fd_ih; /* Pointer to Inode handle */ struct FdHandle_s *fd_next; /* LRU/Avail list pointers */ struct FdHandle_s *fd_prev; - struct FdHandle_s *fd_ihnext; /* Inode handle's list of file descriptors */ + struct FdHandle_s *fd_ihnext; /* Inode handle's list of file descriptors */ struct FdHandle_s *fd_ihprev; } FdHandle_t; @@ -170,17 +170,17 @@ typedef struct FdHandle_s { #define FD_HANDLE_INUSE 3 /* handle is open and in use */ /* buffered file descriptor handle */ -#define STREAM_HANDLE_BUFSIZE 2048 /* buffer size for STR_READ/STR_WRITE */ +#define STREAM_HANDLE_BUFSIZE 2048 /* buffer size for STR_READ/STR_WRITE */ typedef struct StreamHandle_s { - FD_t str_fd; /* file descriptor */ - int str_direction; /* current read/write direction */ - int str_buflen; /* bytes remaining in buffer */ - int str_bufoff; /* current offset into buffer */ - int str_error; /* error code */ - int str_eof; /* end of file flag */ - struct StreamHandle_s *str_next; /* Avail list pointers */ + FD_t str_fd; /* file descriptor */ + int str_direction; /* current read/write direction */ + afs_sfsize_t str_buflen; /* bytes remaining in buffer */ + afs_foff_t str_bufoff; /* current offset into buffer */ + int str_error; /* error code */ + int str_eof; /* end of file flag */ + struct StreamHandle_s *str_next; /* Avail list pointers */ struct StreamHandle_s *str_prev; - char str_buffer[STREAM_HANDLE_BUFSIZE]; /* data buffer */ + char str_buffer[STREAM_HANDLE_BUFSIZE]; /* data buffer */ } StreamHandle_t; #define STREAM_DIRECTION_NONE 1 /* stream is in initial mode */ @@ -208,14 +208,14 @@ typedef struct StreamHandle_s { /* Inode handle */ typedef struct IHandle_s { - int ih_vid; /* Parent volume id. */ - int ih_dev; /* device id. */ - int ih_flags; /* Flags */ - Inode ih_ino; /* Inode number */ - int ih_refcnt; /* reference count */ - struct FdHandle_s *ih_fdhead; /* List of open file desciptors */ + int ih_vid; /* Parent volume id. */ + int ih_dev; /* device id. */ + int ih_flags; /* Flags */ + Inode ih_ino; /* Inode number */ + int ih_refcnt; /* reference count */ + struct FdHandle_s *ih_fdhead; /* List of open file desciptors */ struct FdHandle_s *ih_fdtail; - struct IHandle_s *ih_next; /* Links for avail list/hash chains */ + struct IHandle_s *ih_next; /* Links for avail list/hash chains */ struct IHandle_s *ih_prev; } IHandle_t; @@ -231,8 +231,8 @@ typedef struct IHandle_s { * Hash buckets for inode handles */ typedef struct IHashBucket_s { - IHandle_t *ihash_head; - IHandle_t *ihash_tail; + IHandle_t *ihash_head; + IHandle_t *ihash_tail; } IHashBucket_t; /* Prototypes for handle support routines. */ @@ -242,33 +242,37 @@ typedef struct IHashBucket_s { #else #include "namei_ops.h" #endif -extern void ih_clear(IHandle_t *h); -extern Inode ih_create(IHandle_t *h, int dev, char *part, Inode nI, int p1, - int p2, int p3, int p4); -extern FILE *ih_fdopen(FdHandle_t *h, char *fdperms); +extern void ih_clear(IHandle_t * h); +extern Inode ih_create(IHandle_t * h, int dev, char *part, Inode nI, int p1, + int p2, int p3, int p4); +extern FILE *ih_fdopen(FdHandle_t * h, char *fdperms); #endif /* AFS_NAMEI_ENV */ /* - * Prototypes for file descriptor cache routined + * Prototypes for file descriptor cache routines */ +extern void ih_Initialize(void); extern void ih_UseLargeCache(void); -extern IHandle_t *ih_init(int dev, int vid, Inode ino); -extern IHandle_t *ih_copy(IHandle_t *ihP); -extern FdHandle_t *ih_open(IHandle_t *ihP); -extern int fd_close(FdHandle_t *fdP); -extern int fd_reallyclose(FdHandle_t *fdP); +extern IHandle_t *ih_init(int /*@alt Device@ */ dev, int /*@alt VolId@ */ vid, + Inode ino); +extern IHandle_t *ih_copy(IHandle_t * ihP); +extern FdHandle_t *ih_open(IHandle_t * ihP); +extern int fd_close(FdHandle_t * fdP); +extern int fd_reallyclose(FdHandle_t * fdP); extern StreamHandle_t *stream_fdopen(FD_t fd); extern StreamHandle_t *stream_open(const char *file, const char *mode); -extern int stream_read(void *ptr, int size, int nitems, - StreamHandle_t *streamP); -extern int stream_write(void *ptr, int size, int nitems, - StreamHandle_t *streamP); -extern int stream_seek(StreamHandle_t *streamP, int offset, int whence); -extern int stream_flush(StreamHandle_t *streamP); -extern int stream_close(StreamHandle_t *streamP, int reallyClose); -extern int ih_reallyclose(IHandle_t *ihP); -extern int ih_release(IHandle_t *ihP); -extern int ih_condsync(IHandle_t *ihP); +extern afs_sfsize_t stream_read(void *ptr, afs_fsize_t size, + afs_fsize_t nitems, StreamHandle_t * streamP); +extern afs_sfsize_t stream_write(void *ptr, afs_fsize_t size, + afs_fsize_t nitems, + StreamHandle_t * streamP); +extern int stream_seek(StreamHandle_t * streamP, afs_foff_t offset, + int whence); +extern int stream_flush(StreamHandle_t * streamP); +extern int stream_close(StreamHandle_t * streamP, int reallyClose); +extern int ih_reallyclose(IHandle_t * ihP); +extern int ih_release(IHandle_t * ihP); +extern int ih_condsync(IHandle_t * ihP); /* Macros common to user space and inode API's. */ #define IH_INIT(H, D, V, I) ((H) = ih_init((D), (V), (I))) @@ -335,29 +339,73 @@ extern int ih_condsync(IHandle_t *ihP); #define IH_IWRITE(H, O, B, S) nt_iwrite(H, O, B, S) #else /* AFS_NT40_ENV */ + +/*@+fcnmacros +macrofcndecl@*/ +#ifdef S_SPLINT_S +extern Inode IH_CREATE(IHandle_t * H, int /*@alt Device @ */ D, + char *P, Inode N, int /*@alt VolumeId @ */ P1, + int /*@alt VnodeId @ */ P2, + int /*@alt Unique @ */ P3, + int /*@alt unsigned @ */ P4); +extern FD_t OS_IOPEN(IHandle_t * H); +extern int OS_OPEN(const char *F, int M, mode_t P); +extern int OS_CLOSE(int FD); +extern ssize_t OS_READ(int FD, void *B, size_t S); +extern ssize_t OS_WRITE(int FD, void *B, size_t S); +extern int OS_SYNC(int FD); +extern afs_sfsize_t OS_SIZE(int FD); +extern int IH_INC(IHandle_t * H, Inode I, int /*@alt VolId, VolumeId @ */ P); +extern int IH_DEC(IHandle_t * H, Inode I, int /*@alt VolId, VolumeId @ */ P); +extern afs_sfsize_t IH_IREAD(IHandle_t * H, afs_foff_t O, void *B, + afs_fsize_t S); +extern afs_sfsize_t IH_IWRITE(IHandle_t * H, afs_foff_t O, void *B, + afs_fsize_t S); +#ifdef O_LARGEFILE +extern off64_t OS_SEEK(int FD, off64_t O, int F); +extern int OS_TRUNC(int FD, off64_t L); +#else /* !O_LARGEFILE */ +extern off_t OS_SEEK(int FD, off_t O, int F); +extern int OS_TRUNC(int FD, off_t L); +#endif /* !O_LARGEFILE */ +#endif /*S_SPLINT_S */ + #define IH_CREATE(H, D, P, N, P1, P2, P3, P4) \ namei_icreate(H, P, P1, P2, P3, P4) #define OS_IOPEN(H) namei_iopen(H) +#ifdef O_LARGEFILE +#define OS_OPEN(F, M, P) open64(F, M, P) +#else /* !O_LARGEFILE */ #define OS_OPEN(F, M, P) open(F, M, P) +#endif /* !O_LARGEFILE */ #define OS_CLOSE(FD) close(FD) #define OS_READ(FD, B, S) read(FD, B, S) #define OS_WRITE(FD, B, S) write(FD, B, S) -#define OS_SEEK(FD, O, F) lseek(FD, O, F) +#ifdef O_LARGEFILE +#define OS_SEEK(FD, O, F) lseek64(FD, (off64_t) (O), F) +#else /* !O_LARGEFILE */ +#define OS_SEEK(FD, O, F) lseek(FD, (off_t) (O), F) +#endif /* !O_LARGEFILE */ #define OS_SYNC(FD) fsync(FD) -#define OS_TRUNC(FD, L) ftruncate(FD, L) +#ifdef O_LARGEFILE +#define OS_TRUNC(FD, L) ftruncate64(FD, (off64_t) (L)) +#else /* !O_LARGEFILE */ +#define OS_TRUNC(FD, L) ftruncate(FD, (off_t) (L)) +#endif /* !O_LARGEFILE */ #define OS_SIZE(FD) ih_size(FD) +extern afs_sfsize_t ih_size(int fd); #define IH_INC(H, I, P) namei_inc(H, I, P) #define IH_DEC(H, I, P) namei_dec(H, I, P) #define IH_IREAD(H, O, B, S) namei_iread(H, O, B, S) #define IH_IWRITE(H, O, B, S) namei_iwrite(H, O, B, S) +/*@=fcnmacros =macrofcndecl@*/ #endif /* AFS_NT40_ENV */ #else /* AFS_NAMEI_ENV */ -extern Inode ih_icreate(IHandle_t *ih, int dev, char *part, Inode nI, int p1,\ +extern Inode ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2, int p3, int p4); #define IH_CREATE(H, D, P, N, P1, P2, P3, P4) \ @@ -366,18 +414,31 @@ extern Inode ih_icreate(IHandle_t *ih, int dev, char *part, Inode nI, int p1,\ #ifdef AFS_LINUX22_ENV #define OS_IOPEN(H) -1 #else +#ifdef O_LARGEFILE +#define OS_IOPEN(H) (IOPEN((H)->ih_dev, (H)->ih_ino, O_RDWR|O_LARGEFILE)) +#else #define OS_IOPEN(H) (IOPEN((H)->ih_dev, (H)->ih_ino, O_RDWR)) #endif +#endif #define OS_OPEN(F, M, P) open(F, M, P) #define OS_CLOSE(FD) close(FD) #define OS_READ(FD, B, S) read(FD, B, S) #define OS_WRITE(FD, B, S) write(FD, B, S) -#define OS_SEEK(FD, O, F) lseek(FD, O, F) +#ifdef O_LARGEFILE +#define OS_SEEK(FD, O, F) lseek64(FD, (off64_t) (O), F) +#else /* !O_LARGEFILE */ +#define OS_SEEK(FD, O, F) lseek(FD, (off_t) (O), F) +#endif /* !O_LARGEFILE */ #define OS_SYNC(FD) fsync(FD) -#define OS_TRUNC(FD, L) ftruncate(FD, L) +#ifdef O_LARGEFILE +#define OS_TRUNC(FD, L) ftruncate64(FD, (off64_t) (L)) +#else /* !O_LARGEFILE */ +#define OS_TRUNC(FD, L) ftruncate(FD, (off_t) (L)) +#endif /* !O_LARGEFILE */ #define OS_SIZE(FD) ih_size(FD) +extern afs_sfsize_t ih_size(int fd); #ifdef AFS_LINUX22_ENV #define IH_INC(H, I, P) -1 diff --git a/src/vol/listinodes.c b/src/vol/listinodes.c index 6049afb74..d3d4ca456 100644 --- a/src/vol/listinodes.c +++ b/src/vol/listinodes.c @@ -15,12 +15,13 @@ */ -#define ITC /* Required by inode.h */ +#define ITC /* Required by inode.h */ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/listinodes.c,v 1.1.1.10 2002/09/26 19:09:23 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/listinodes.c,v 1.13 2003/07/15 23:17:39 shadow Exp $"); #ifndef AFS_NAMEI_ENV #if defined(AFS_LINUX20_ENV) || defined(AFS_SUN4_ENV) @@ -31,10 +32,10 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/listinodes.c,v 1.1.1.10 2002/09/26 * -1 - Unable to read the inodes. * -2 - Unable to completely write temp file. Produces warning message in log. */ -ListViceInodes(devname, mountedOn, resultFile, judgeInode, judgeParam, forcep, forceR, wpath) -char *devname, *mountedOn, *resultFile, *wpath; -int (*judgeInode)(); -int *forcep, forceR; +int +ListViceInodes(char *devname, char *mountedOn, char *resultFile, + int (*judgeInode) (), int judgeParam, int *forcep, int forceR, + char *wpath) { Log("ListViceInodes not implemented for this platform!\n"); return -1; @@ -46,7 +47,7 @@ int *forcep, forceR; #else #ifdef AFS_OSF_ENV #include -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #ifdef AFS_VFSINCL_ENV #define VFS #ifdef AFS_SUN5_ENV @@ -67,7 +68,7 @@ int *forcep, forceR; #include #endif #endif /* AFS_VFSINCL_ENV */ -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ #include #ifdef AFS_VFSINCL_ENV #include @@ -84,7 +85,7 @@ int *forcep, forceR; #endif /* AFS_DEC_ENV */ #ifdef AFS_OSF_ENV #include -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #include #endif #endif /* AFS_VFSINCL_ENV */ @@ -122,12 +123,12 @@ int pfd; #include #ifndef FSBSIZE -#define FSBSIZE (4096) /* filesystem block size */ -#define FSBSHIFT (12) /* log2(FSBSIZE) */ -#define FSBMASK (FSBSIZE - 1) /* FSBSIZE mask */ +#define FSBSIZE (4096) /* filesystem block size */ +#define FSBSHIFT (12) /* log2(FSBSIZE) */ +#define FSBMASK (FSBSIZE - 1) /* FSBSIZE mask */ #define MIN_FSIZE DISKMAP_B /* minimum fs size (FSblocks) */ -#define LAST_RSVD_I 15 /* last reserved inode */ +#define LAST_RSVD_I 15 /* last reserved inode */ #endif #ifndef INOPB @@ -155,204 +156,204 @@ int agblocks; #undef itoo #define itoo(x) (int) ((unsigned)(x) % INOPB) -int Bsize = FSBSIZE; /* block size for this system */ -daddr_t fmax; /* total number of blocks n file system */ -ino_t imax, inum; /* total number of I-nodes in file system */ +int Bsize = FSBSIZE; /* block size for this system */ +daddr_t fmax; /* total number of blocks n file system */ +ino_t imax, inum; /* total number of I-nodes in file system */ static struct superblock fs; struct dinode *ginode(); +int +ListViceInodes(char *devname, char *mountedOn, char *resultFile, + int (*judgeInode) (), int judgeParam, int *forcep, int forceR, + char *wpath) +{ + FILE *inodeFile = NULL; + char dev[50], rdev[51]; + struct stat status; + struct dinode *p; + struct ViceInodeInfo info; + struct stat root_inode; + int ninodes = 0, err = 0; -ListViceInodes(devname, mountedOn, resultFile, judgeInode, judgeParam, forcep, forceR, wpath) -char *devname, *mountedOn, *resultFile, *wpath; -int (*judgeInode)(); -int *forcep, forceR; { - FILE *inodeFile = NULL; - char dev[50], rdev[51]; - struct stat status; - struct dinode *p; - struct ViceInodeInfo info; - struct stat root_inode; - int ninodes = 0, err = 0; - - pfd = -1; /* initialize so we don't close on error output below. */ - *forcep = 0; - sync(); sleep(1); /* simulate operator */ - sync(); sleep(1); - sync(); sleep(1); - - partition = mountedOn; - sprintf(dev, "/dev/%s", devname); - sprintf(rdev, "/dev/r%s", devname); - - if (stat(mountedOn, &root_inode) < 0) { - Log("cannot stat: %s\n", mountedOn); - return -1; - } - - if (root_inode.st_ino != ROOTDIR_I) { - Log("%s is not root of a filesystem\n", mountedOn); - return -1; - } + pfd = -1; /* initialize so we don't close on error output below. */ + *forcep = 0; + sync(); + sleep(1); /* simulate operator */ + sync(); + sleep(1); + sync(); + sleep(1); + + partition = mountedOn; + sprintf(dev, "/dev/%s", devname); + sprintf(rdev, "/dev/r%s", devname); + + if (stat(mountedOn, &root_inode) < 0) { + Log("cannot stat: %s\n", mountedOn); + return -1; + } + if (root_inode.st_ino != ROOTDIR_I) { + Log("%s is not root of a filesystem\n", mountedOn); + return -1; + } - /* - * done with the superblock, now try to read the raw device. - */ - if(ReadSuper(&fs, dev)<0) - return -1; - switch (fs.s_fmod) { - default: - case FM_CLEAN: /* clean and unmounted */ - Log("Most peculiar - Super blk in FM_CLEAN state!\n"); - goto out; - case FM_MOUNT: /* mounted cleanly */ - break; + /* + * done with the superblock, now try to read the raw device. + */ + if (ReadSuper(&fs, dev) < 0) + return -1; - case FM_MDIRTY: /* dirty when mounted or commit fail */ - case FM_LOGREDO: /* log redo attempted but failed */ - Log("File system %s is in a bad state.\n", rdev); - Log("Call your IBM representative.\n"); - return -1; - } + switch (fs.s_fmod) { + default: + case FM_CLEAN: /* clean and unmounted */ + Log("Most peculiar - Super blk in FM_CLEAN state!\n"); + goto out; + case FM_MOUNT: /* mounted cleanly */ + break; + + case FM_MDIRTY: /* dirty when mounted or commit fail */ + case FM_LOGREDO: /* log redo attempted but failed */ + Log("File system %s is in a bad state.\n", rdev); + Log("Call your IBM representative.\n"); + return -1; + } #ifdef AFS_AIX42_ENV - if (IsBigFilesFileSystem(&fs, (char*)0)) { - Log("%s is a big files filesystem, can't salvage.\n", mountedOn); - return -1; - } + if (IsBigFilesFileSystem(&fs, (char *)0)) { + Log("%s is a big files filesystem, can't salvage.\n", mountedOn); + return -1; + } #else - if (strncmp(fs.s_magic, fsv3magic, strlen(fsv3magic)) != 0) { + if (strncmp(fs.s_magic, fsv3magic, strlen(fsv3magic)) != 0) { #ifdef AFS_AIX41_ENV - if ((strncmp(fs.s_magic, fsv3pmagic, strlen(fsv3pmagic)) != 0) || - (fs.s_version != fsv3pvers)) { - Log("Super block doesn't have the problem magic (%s vs v3magic %s v3pmagic %s)\n", - fs.s_magic, fsv3magic, fsv3pmagic); - return -1; - } + if ((strncmp(fs.s_magic, fsv3pmagic, strlen(fsv3pmagic)) != 0) + || (fs.s_version != fsv3pvers)) { + Log("Super block doesn't have the problem magic (%s vs v3magic %s v3pmagic %s)\n", fs.s_magic, fsv3magic, fsv3pmagic); + return -1; + } #else - Log("Super block doesn't have the problem magic (%s vs v3magic %s)\n", - fs.s_magic, fsv3magic); - return -1; + Log("Super block doesn't have the problem magic (%s vs v3magic %s)\n", + fs.s_magic, fsv3magic); + return -1; #endif - } + } #endif #ifdef AFS_AIX41_ENV - fragsize = (fs.s_fragsize)? fs.s_fragsize : FSBSIZE; - iagsize = (fs.s_iagsize)? fs.s_iagsize : fs.s_agsize; - ag512 = fragsize * fs.s_agsize / 512; - agblocks = fragsize * fs.s_agsize >> BSHIFT; + fragsize = (fs.s_fragsize) ? fs.s_fragsize : FSBSIZE; + iagsize = (fs.s_iagsize) ? fs.s_iagsize : fs.s_agsize; + ag512 = fragsize * fs.s_agsize / 512; + agblocks = fragsize * fs.s_agsize >> BSHIFT; #endif /* AFS_AIX41_ENV */ - fmax = fs.s_fsize / (FSBSIZE/512); /* first invalid blk num */ + fmax = fs.s_fsize / (FSBSIZE / 512); /* first invalid blk num */ - pfd = open(rdev, O_RDONLY); - if (pfd < 0) { - Log("Unable to open `%s' inode for reading\n", rdev); - return -1; - } + pfd = open(rdev, O_RDONLY); + if (pfd < 0) { + Log("Unable to open `%s' inode for reading\n", rdev); + return -1; + } - inodeFile = fopen(resultFile, "w"); - if (inodeFile == NULL) { - Log("Unable to create inode description file %s\n" - , resultFile); - goto out; - } - - /* - * calculate the maximum number of inodes possible - */ + inodeFile = fopen(resultFile, "w"); + if (inodeFile == NULL) { + Log("Unable to create inode description file %s\n", resultFile); + goto out; + } + + /* + * calculate the maximum number of inodes possible + */ #ifdef AFS_AIX41_ENV - imax = iagsize * (fs.s_fsize/ag512) - 1; + imax = iagsize * (fs.s_fsize / ag512) - 1; #else /* AFS_AIX41_ENV */ - imax = ((fmax / fs.s_agsize + - ((fmax % fs.s_agsize) >= fs.s_agsize/INOPB ? 1 : 0)) - * fs.s_agsize) - 1; + imax = + ((fmax / fs.s_agsize + + ((fmax % fs.s_agsize) >= fs.s_agsize / INOPB ? 1 : 0)) + * fs.s_agsize) - 1; #endif /* AFS_AIX41_ENV */ - /* - * check for "FORCESALVAGE" equivalent: - * LAST_RSVD_I is a vice inode, with dead beef, and - * di_nlink == 2 to indicate the FORCE. - */ - assert(p = ginode(LAST_RSVD_I)); + /* + * check for "FORCESALVAGE" equivalent: + * LAST_RSVD_I is a vice inode, with dead beef, and + * di_nlink == 2 to indicate the FORCE. + */ + assert(p = ginode(LAST_RSVD_I)); - if (p->di_vicemagic == VICEMAGIC - && p->di_vicep1 == 0xdeadbeef - && p->di_nlink == 2) { - *forcep = 1; - idec(root_inode.st_dev, LAST_RSVD_I, 0xdeadbeef); - } + if (p->di_vicemagic == VICEMAGIC && p->di_vicep1 == 0xdeadbeef + && p->di_nlink == 2) { + *forcep = 1; + idec(root_inode.st_dev, LAST_RSVD_I, 0xdeadbeef); + } - for (inum = LAST_RSVD_I + 1; inum <= imax; ++inum) { - if ((p = ginode(inum)) == NULL - || p->di_vicemagic != VICEMAGIC - || (p->di_mode & IFMT) != IFREG) - continue; + for (inum = LAST_RSVD_I + 1; inum <= imax; ++inum) { + if ((p = ginode(inum)) == NULL || p->di_vicemagic != VICEMAGIC + || (p->di_mode & IFMT) != IFREG) + continue; - info.inodeNumber = inum; - info.byteCount = p->di_size; - info.linkCount = p->di_nlink; - info.u.param[0] = p->di_vicep1; - info.u.param[1] = p->di_vicep2; - info.u.param[2] = p->di_vicep3; - info.u.param[3] = p->di_vicep4; + info.inodeNumber = inum; + info.byteCount = p->di_size; + info.linkCount = p->di_nlink; + info.u.param[0] = p->di_vicep1; + info.u.param[1] = p->di_vicep2; + info.u.param[2] = p->di_vicep3; + info.u.param[3] = p->di_vicep4; - if (judgeInode && (*judgeInode)(&info, judgeParam) == 0) - continue; + if (judgeInode && (*judgeInode) (&info, judgeParam) == 0) + continue; - if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { - Log("Error writing inode file for partition %s\n" - , partition); - goto out; - } - ++ninodes; + if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { + Log("Error writing inode file for partition %s\n", partition); + goto out; } + ++ninodes; + } - if (fflush(inodeFile) == EOF) { - Log("Unable to successfully flush inode file for %s\n", partition); - err = -2; - goto out1; - } - if (fsync(fileno(inodeFile)) == -1) { - Log("Unable to successfully fsync inode file for %s\n", partition); - err = -2; - goto out1; - } - if (fclose(inodeFile) == EOF) { - Log("Unable to successfully close inode file for %s\n", partition); - err = -2; - goto out1; - } + if (fflush(inodeFile) == EOF) { + Log("Unable to successfully flush inode file for %s\n", partition); + err = -2; + goto out1; + } + if (fsync(fileno(inodeFile)) == -1) { + Log("Unable to successfully fsync inode file for %s\n", partition); + err = -2; + goto out1; + } + if (fclose(inodeFile) == EOF) { + Log("Unable to successfully close inode file for %s\n", partition); + err = -2; + goto out1; + } - /* - * Paranoia: check that the file is really the right size - */ - if (stat(resultFile, &status) == -1) { - Log("Unable to successfully stat inode file for %s\n", partition); - err = -2; - goto out1; - } - if (status.st_size != ninodes * sizeof (struct ViceInodeInfo)) { - Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof (struct ViceInodeInfo), partition); - err = -2; - goto out1; - } - close(pfd); - return 0; + /* + * Paranoia: check that the file is really the right size + */ + if (stat(resultFile, &status) == -1) { + Log("Unable to successfully stat inode file for %s\n", partition); + err = -2; + goto out1; + } + if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + Log("Wrong size (%d instead of %d) in inode file for %s\n", + status.st_size, ninodes * sizeof(struct ViceInodeInfo), + partition); + err = -2; + goto out1; + } + close(pfd); + return 0; - out: - err = -1; - out1: - if (pfd >= 0) - close(pfd); - if (inodeFile) - fclose(inodeFile); + out: + err = -1; + out1: + if (pfd >= 0) + close(pfd); + if (inodeFile) + fclose(inodeFile); - return err; + return err; } /* Read in the superblock for devName */ @@ -363,11 +364,10 @@ ReadSuper(struct superblock *fs, char *devName) pfd = open(devName, O_RDONLY); if (pfd < 0) { - Log("Unable to open inode on %s for reading superblock.\n", - devName); + Log("Unable to open inode on %s for reading superblock.\n", devName); return -1; } - + if (bread(pfd, fs, SUPER_B, sizeof(struct superblock)) < 0) { Log("Unable to read superblock on %s.\n", devName); return -1; @@ -381,9 +381,9 @@ ReadSuper(struct superblock *fs, char *devName) int IsBigFilesFileSystem(struct superblock *sb) { - if((strncmp(sb->s_magic,fsv3pmagic,4) == 0) - && (sb->s_version == fsbigfile) - && (sb->s_bigexp)) + if ((strncmp(sb->s_magic, fsv3pmagic, 4) == 0) + && (sb->s_version == fsbigfile) + && (sb->s_bigexp)) return 1; else return 0; @@ -391,37 +391,45 @@ IsBigFilesFileSystem(struct superblock *sb) #endif struct dinode * -ginode(inum) { - int ag; - daddr_t pblk; - struct dinode *dp; - static char buf[FSBSIZE]; - static daddr_t last_blk = -1; +ginode(inum) +{ + int ag; + daddr_t pblk; + struct dinode *dp; + static char buf[FSBSIZE]; + static daddr_t last_blk = -1; #ifdef AFS_AIX41_ENV - ag = inum / iagsize; - pblk = (ag == 0) ? INODES_B + inum/INOPB - : ag*agblocks + (inum - ag*iagsize)/INOPB; + ag = inum / iagsize; + pblk = + (ag == + 0) ? INODES_B + inum / INOPB : ag * agblocks + (inum - + ag * iagsize) / + INOPB; #else /* AFS_AIX41_ENV */ - ag = inum/fs.s_agsize; - pblk = (ag == 0) ? INODES_B + inum/INOPB - : ag*fs.s_agsize + (inum - ag*fs.s_agsize)/INOPB; -#endif /* AFS_AIX41_ENV */ - - if (last_blk != pblk) { - if (bread(pfd, buf, pblk, sizeof(buf)) < 0) { - last_blk = -1; - return 0; - } - last_blk = pblk; + ag = inum / fs.s_agsize; + pblk = + (ag == + 0) ? INODES_B + inum / INOPB : ag * fs.s_agsize + (inum - + ag * + fs.s_agsize) / + INOPB; +#endif /* AFS_AIX41_ENV */ + + if (last_blk != pblk) { + if (bread(pfd, buf, pblk, sizeof(buf)) < 0) { + last_blk = -1; + return 0; } + last_blk = pblk; + } - dp = (struct dinode *)buf; - dp += itoo(inum); - return (dp); + dp = (struct dinode *)buf; + dp += itoo(inum); + return (dp); } -#else /* !AFS_AIX31_ENV */ +#else /* !AFS_AIX31_ENV */ #if defined(AFS_SGI_ENV) @@ -429,7 +437,7 @@ ginode(inum) { #define __ASSERT_H__ #ifdef AFS_SGI_EFS_IOPS_ENV -#include "../sgiefs/libefs.h" +#include "sgiefs/libefs.h" extern int Log(); /* afs_efs_figet() replaces the SGI library routine because we are malloc'ing @@ -438,185 +446,188 @@ extern int Log(); * memory. */ struct efs_dinode * -afs_efs_figet(EFS_MOUNT *mp, struct efs_dinode *dinodeBuf, int *last_cgno, +afs_efs_figet(EFS_MOUNT * mp, struct efs_dinode *dinodeBuf, int *last_cgno, ino_t inum) { int cgno = EFS_ITOCG(mp->m_fs, inum); - + if (cgno != *last_cgno) { - if (efs_readb(mp->m_fd, (char *)dinodeBuf, EFS_CGIMIN(mp->m_fs, cgno), - mp->m_fs->fs_cgisize) != mp->m_fs->fs_cgisize) { + if (efs_readb + (mp->m_fd, (char *)dinodeBuf, EFS_CGIMIN(mp->m_fs, cgno), + mp->m_fs->fs_cgisize) != mp->m_fs->fs_cgisize) { Log("Unable to read inodes for cylinder group %d.\n", cgno); return NULL; } *last_cgno = cgno; } - return dinodeBuf + (inum % (mp->m_fs->fs_cgisize*EFS_INOPBB)); + return dinodeBuf + (inum % (mp->m_fs->fs_cgisize * EFS_INOPBB)); } int -efs_ListViceInodes(devname, mountedOn, resultFile, judgeInode, judgeParam, - forcep, forceR, wpath) -char *devname, *mountedOn, *resultFile, *wpath; -int (*judgeInode)(); -int *forcep, forceR; +efs_ListViceInodes(char *devname, char *mountedOn, char *resultFile, + int (*judgeInode) (), int judgeParam, int *forcep, + int forceR, char *wpath) { - FILE *inodeFile = NULL; - char dev[50], rdev[51]; - struct stat status; - struct efs_dinode *p; - struct ViceInodeInfo info; - int ninodes = 0, err = 0; - struct efs_dinode *dinodeBuf = NULL; - int last_cgno; - EFS_MOUNT *mp; - ino_t imax, inum; /* total number of I-nodes in file system */ - - *forcep = 0; - - partition = mountedOn; - sprintf(dev, "/dev/dsk/%s", devname); - sprintf(rdev, "/dev/rdsk/%s", devname); - - - /* - * open raw device - */ - efs_init(Log); - if ((stat(rdev, &status) == -1) || ((mp = efs_mount(rdev, O_RDONLY)) == NULL)) { - sprintf(rdev, "/dev/r%s", devname); - mp = efs_mount(rdev, O_RDONLY); - } - if (mp == NULL) { - Log("Unable to open `%s' inode for reading\n", rdev); - return -1; - } - - inodeFile = fopen(resultFile, "w"); - if (inodeFile == NULL) { - Log("Unable to create inode description file %s\n" - , resultFile); - goto out; - } - - /* Allocate space for one cylinder group's worth of inodes. */ - dinodeBuf = (struct efs_dinode*)malloc(mp->m_fs->fs_cgisize * BBSIZE); - if (!dinodeBuf) { - Log("Unable to malloc %lu bytes for inode buffer.\n", - mp->m_fs->fs_cgisize * BBSIZE); - goto out; - } + FILE *inodeFile = NULL; + char dev[50], rdev[51]; + struct stat status; + struct efs_dinode *p; + struct ViceInodeInfo info; + int ninodes = 0, err = 0; + struct efs_dinode *dinodeBuf = NULL; + int last_cgno; + EFS_MOUNT *mp; + ino_t imax, inum; /* total number of I-nodes in file system */ - /* - * calculate the maximum number of inodes possible - */ - imax = mp->m_fs->fs_ncg * mp->m_fs->fs_ipcg; + *forcep = 0; - last_cgno = -1; - for (inum = 2; inum < imax; ++inum) { - p = afs_efs_figet(mp, dinodeBuf, &last_cgno, inum); - if (!p) { - Log("Unable to read all inodes from partition.\n"); - goto out; - } - if (!IS_DVICEMAGIC(p) || !((p->di_mode&IFMT) == IFREG)) { - continue; - } + partition = mountedOn; + sprintf(dev, "/dev/dsk/%s", devname); + sprintf(rdev, "/dev/rdsk/%s", devname); -#if defined(AFS_SGI_EXMAG) - /* volume ID */ - info.u.param[0] = dmag(p, 0) << 24 | dmag(p, 1) << 16 | - dmag(p, 2) << 8 | dmag(p, 3) << 0; - if ((p)->di_version == EFS_IVER_AFSSPEC) { - info.u.param[1] = INODESPECIAL; - /* type */ - info.u.param[2] = dmag(p, 8); - /* parentId */ - info.u.param[3] = dmag(p, 4) << 24 | dmag(p, 5) << 16 | - dmag(p, 6) << 8 | dmag(p, 7) << 0; - } else { - /* vnode number */ - info.u.param[1] = dmag(p, 4) << 16 | - dmag(p, 5) << 8 | dmag(p, 6) << 0; - /* disk uniqifier */ - info.u.param[2] = dmag(p, 7) << 16 | - dmag(p, 8) << 8 | dmag(p, 9) << 0; - /* data version */ - info.u.param[3] = dmag(p, 10) << 16 | - dmag(p, 11) << 8 | (p)->di_spare; - } -#else -BOMB!! -#endif - info.inodeNumber = inum; - info.byteCount = p->di_size; - info.linkCount = p->di_nlink; -#ifdef notdef -Log("Ino=%d, bytes=%d, linkCnt=%d, [%x,%x,%x,%x]\n", inum, p->di_size, p->di_nlink, - info.u.param[0],info.u.param[1],info.u.param[2],info.u.param[3]); -#endif - if (judgeInode && (*judgeInode)(&info, judgeParam) == 0) - continue; + /* + * open raw device + */ + efs_init(Log); + if ((stat(rdev, &status) == -1) + || ((mp = efs_mount(rdev, O_RDONLY)) == NULL)) { + sprintf(rdev, "/dev/r%s", devname); + mp = efs_mount(rdev, O_RDONLY); + } + if (mp == NULL) { + Log("Unable to open `%s' inode for reading\n", rdev); + return -1; + } - if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { - Log("Error writing inode file for partition %s\n" - , partition); - goto out; - } - ++ninodes; - } + inodeFile = fopen(resultFile, "w"); + if (inodeFile == NULL) { + Log("Unable to create inode description file %s\n", resultFile); + goto out; + } - if (fflush(inodeFile) == EOF) { - Log("Unable to successfully flush inode file for %s\n", partition); - err = -2; - goto out1; - } - if (fsync(fileno(inodeFile)) == -1) { - Log("Unable to successfully fsync inode file for %s\n", partition); - err = -2; - goto out1; - } - if (fclose(inodeFile) == EOF) { - Log("Unable to successfully close inode file for %s\n", partition); - err = -2; - goto out1; - } + /* Allocate space for one cylinder group's worth of inodes. */ + dinodeBuf = (struct efs_dinode *)malloc(mp->m_fs->fs_cgisize * BBSIZE); + if (!dinodeBuf) { + Log("Unable to malloc %lu bytes for inode buffer.\n", + mp->m_fs->fs_cgisize * BBSIZE); + goto out; + } - /* - * Paranoia: check that the file is really the right size - */ - if (stat(resultFile, &status) == -1) { - Log("Unable to successfully stat inode file for %s\n", partition); - err = -2; - goto out1; + /* + * calculate the maximum number of inodes possible + */ + imax = mp->m_fs->fs_ncg * mp->m_fs->fs_ipcg; + + last_cgno = -1; + for (inum = 2; inum < imax; ++inum) { + p = afs_efs_figet(mp, dinodeBuf, &last_cgno, inum); + if (!p) { + Log("Unable to read all inodes from partition.\n"); + goto out; } - if (status.st_size != ninodes * sizeof (struct ViceInodeInfo)) { - Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof (struct ViceInodeInfo), partition); - err = -2; - goto out1; + if (!IS_DVICEMAGIC(p) || !((p->di_mode & IFMT) == IFREG)) { + continue; } - efs_umount(mp); - if (dinodeBuf) { - free(dinodeBuf); +#if defined(AFS_SGI_EXMAG) + /* volume ID */ + info.u.param[0] = + dmag(p, 0) << 24 | dmag(p, 1) << 16 | dmag(p, 2) << 8 | dmag(p, + 3) << + 0; + if ((p)->di_version == EFS_IVER_AFSSPEC) { + info.u.param[1] = INODESPECIAL; + /* type */ + info.u.param[2] = dmag(p, 8); + /* parentId */ + info.u.param[3] = + dmag(p, 4) << 24 | dmag(p, 5) << 16 | dmag(p, + 6) << 8 | dmag(p, + 7) + << 0; + } else { + /* vnode number */ + info.u.param[1] = + dmag(p, 4) << 16 | dmag(p, 5) << 8 | dmag(p, 6) << 0; + /* disk uniqifier */ + info.u.param[2] = + dmag(p, 7) << 16 | dmag(p, 8) << 8 | dmag(p, 9) << 0; + /* data version */ + info.u.param[3] = + dmag(p, 10) << 16 | dmag(p, 11) << 8 | (p)->di_spare; } - return 0; +#else + BOMB ! ! +#endif + info.inodeNumber = inum; + info.byteCount = p->di_size; + info.linkCount = p->di_nlink; +#ifdef notdef + Log("Ino=%d, bytes=%d, linkCnt=%d, [%x,%x,%x,%x]\n", inum, p->di_size, + p->di_nlink, info.u.param[0], info.u.param[1], info.u.param[2], + info.u.param[3]); +#endif + if (judgeInode && (*judgeInode) (&info, judgeParam) == 0) + continue; - out: - err = -1; - out1: - if (dinodeBuf) { - free(dinodeBuf); + if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { + Log("Error writing inode file for partition %s\n", partition); + goto out; } - efs_umount(mp); - if (inodeFile) - fclose(inodeFile); + ++ninodes; + } + + if (fflush(inodeFile) == EOF) { + Log("Unable to successfully flush inode file for %s\n", partition); + err = -2; + goto out1; + } + if (fsync(fileno(inodeFile)) == -1) { + Log("Unable to successfully fsync inode file for %s\n", partition); + err = -2; + goto out1; + } + if (fclose(inodeFile) == EOF) { + Log("Unable to successfully close inode file for %s\n", partition); + err = -2; + goto out1; + } + + /* + * Paranoia: check that the file is really the right size + */ + if (stat(resultFile, &status) == -1) { + Log("Unable to successfully stat inode file for %s\n", partition); + err = -2; + goto out1; + } + if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + Log("Wrong size (%d instead of %d) in inode file for %s\n", + status.st_size, ninodes * sizeof(struct ViceInodeInfo), + partition); + err = -2; + goto out1; + } + efs_umount(mp); + if (dinodeBuf) { + free(dinodeBuf); + } + return 0; + + out: + err = -1; + out1: + if (dinodeBuf) { + free(dinodeBuf); + } + efs_umount(mp); + if (inodeFile) + fclose(inodeFile); - return err; + return err; } #endif /* AFS_SGI_EFS_IOPS_ENV */ @@ -647,8 +658,9 @@ Log("Ino=%d, bytes=%d, linkCnt=%d, [%x,%x,%x,%x]\n", inum, p->di_size, p->di_nli * We can't change the names until the readdir is complete, so we set the * rename flag if the file needs renaming. */ -int xfs_VerifyInode(char *dir, uint64_t pino, char *name, i_list_inode_t *info, - int *rename) +int +xfs_VerifyInode(char *dir, uint64_t pino, char *name, i_list_inode_t * info, + int *rename) { char path[1024]; int vno; @@ -661,13 +673,13 @@ int xfs_VerifyInode(char *dir, uint64_t pino, char *name, i_list_inode_t *info, int tag; *rename = 0; - (void) sprintf(path, "%s/%s", dir, name); + (void)sprintf(path, "%s/%s", dir, name); /* Verify uid and gid fields */ if (info->ili_magic != XFS_VICEMAGIC) { Log("%s magic for %s/%s (inode %s) from %d to %d\n", - Testing ? "Would have changed" : "Changing", - dir, name, PrintInode(NULL, info->ili_info.inodeNumber), - info->ili_magic, XFS_VICEMAGIC); + Testing ? "Would have changed" : "Changing", dir, name, + PrintInode(NULL, info->ili_info.inodeNumber), info->ili_magic, + XFS_VICEMAGIC); if (!Testing) update_chown = 1; } @@ -675,17 +687,17 @@ int xfs_VerifyInode(char *dir, uint64_t pino, char *name, i_list_inode_t *info, vno = info->ili_info.param[0]; if (info->ili_vno != AFS_XFS_VNO_CLIP(vno)) { Log("%s volume id for %s/%s (inode %s) from %d to %d\n", - Testing ? "Would have changed" : "Changing", - dir, name, PrintInode(NULL, info->ili_info.inodeNumber), - info->ili_vno , AFS_XFS_VNO_CLIP(vno)); + Testing ? "Would have changed" : "Changing", dir, name, + PrintInode(NULL, info->ili_info.inodeNumber), info->ili_vno, + AFS_XFS_VNO_CLIP(vno)); if (!Testing) update_chown = 1; } if (update_chown) { - if (chown(path, AFS_XFS_VNO_CLIP(vno), XFS_VICEMAGIC)<0) { - Log("Can't chown %s to uid=%d, gid=0x%x\n", - path, AFS_XFS_VNO_CLIP(vno), XFS_VICEMAGIC); + if (chown(path, AFS_XFS_VNO_CLIP(vno), XFS_VICEMAGIC) < 0) { + Log("Can't chown %s to uid=%d, gid=0x%x\n", path, + AFS_XFS_VNO_CLIP(vno), XFS_VICEMAGIC); retCode = -1; } } @@ -693,23 +705,23 @@ int xfs_VerifyInode(char *dir, uint64_t pino, char *name, i_list_inode_t *info, /* Check Parent inode number. */ if (info->ili_pino != pino) { afs_ino_str_t sino, sipino, spino; - (void) PrintInode(sino, info->ili_info.inodeNumber); - (void) PrintInode(sipino, info->ili_pino); - (void) PrintInode(spino, pino); - Log("%s parent ino for %s (inode %s) from %s to %s.\n", - Testing ? "Would have changed" : "Changing", - path, sino, sipino, spino); + (void)PrintInode(sino, info->ili_info.inodeNumber); + (void)PrintInode(sipino, info->ili_pino); + (void)PrintInode(spino, pino); + Log("%s parent ino for %s (inode %s) from %s to %s.\n", + Testing ? "Would have changed" : "Changing", path, sino, sipino, + spino); if (!Testing) update_pino = 1; } /* Verify the file name. */ - (void) strcpy(tmpName, "."); - (void) strcat(tmpName, int_to_base64(stmp, info->ili_info.param[2])); + (void)strcpy(tmpName, "."); + (void)strcat(tmpName, int_to_base64(stmp, info->ili_info.param[2])); if (strncmp(name, tmpName, strlen(tmpName))) { Log("%s name %s (inode %s) in directory %s, unique=%d, tag=%d\n", - Testing ? "Would have returned bad" : "Bad", - name, PrintInode(NULL, info->ili_info.inodeNumber), dir, + Testing ? "Would have returned bad" : "Bad", name, + PrintInode(NULL, info->ili_info.inodeNumber), dir, info->ili_info.param[2], info->ili_tag); if (!Testing) *rename = 1; @@ -717,25 +729,24 @@ int xfs_VerifyInode(char *dir, uint64_t pino, char *name, i_list_inode_t *info, if (!*rename) { /* update the tag? */ - (void) strcat(tmpName, "."); - (void) strcat(tmpName, int_to_base64(stmp, info->ili_tag)); + (void)strcat(tmpName, "."); + (void)strcat(tmpName, int_to_base64(stmp, info->ili_tag)); if (strcmp(name, tmpName)) { char *p; - (void) strcpy(tmpName, name); - p = strchr(tmpName+1, '.'); + (void)strcpy(tmpName, name); + p = strchr(tmpName + 1, '.'); if (!p) { Log("No tag found on name %s (inode %s)in directory, %s.\n", name, PrintInode(NULL, info->ili_info.inodeNumber), dir, Testing ? "would have renamed" : "will rename"); if (!Testing) *rename = 1; - } - else { - tag = base64_to_int(p+1); + } else { + tag = base64_to_int(p + 1); Log("%s the tag for %s (inode %s) from %d to %d.\n", - Testing ? "Would have changed" : "Will change", - path, PrintInode(NULL, info->ili_info.inodeNumber), dir, - tag, info->ili_tag); + Testing ? "Would have changed" : "Will change", path, + PrintInode(NULL, info->ili_info.inodeNumber), dir, tag, + info->ili_tag); if (!Testing) update_tag = 1; } @@ -747,7 +758,8 @@ int xfs_VerifyInode(char *dir, uint64_t pino, char *name, i_list_inode_t *info, int length; length = SIZEOF_XFS_ATTR_T; - if (attr_get(path, AFS_XFS_ATTR, (char*)&attrs, &length, ATTR_ROOT)<0) { + if (attr_get(path, AFS_XFS_ATTR, (char *)&attrs, &length, ATTR_ROOT) < + 0) { Log("Can't get AFS attribute for %s\n", path); return -1; } @@ -755,8 +767,9 @@ int xfs_VerifyInode(char *dir, uint64_t pino, char *name, i_list_inode_t *info, attrs.at_pino = pino; if (update_tag) attrs.at_tag = tag; - if(attr_set(path, AFS_XFS_ATTR, (char*)&attrs, length, - ATTR_ROOT|ATTR_REPLACE)<0) { + if (attr_set + (path, AFS_XFS_ATTR, (char *)&attrs, length, + ATTR_ROOT | ATTR_REPLACE) < 0) { Log("Can't set AFS attribute into %s\n", path); retCode = -1; } @@ -770,7 +783,8 @@ typedef struct { char name[28]; } xfs_Rename_t; -int xfs_RenameFiles(char *dir, xfs_Rename_t *renames, int n_renames) +int +xfs_RenameFiles(char *dir, xfs_Rename_t * renames, int n_renames) { int i, j; char opath[128], nbase[128], npath[128]; @@ -780,13 +794,14 @@ int xfs_RenameFiles(char *dir, xfs_Rename_t *renames, int n_renames) int tag; int fd; - for (i=0; i0) { + for (i = 0; i < n_renames; i++) { + (void)sprintf(opath, "%s/%s", dir, renames[i].name); + (void)sprintf(nbase, "%s/.%s", dir, + int_to_base64(stmp, renames[i].uniq)); + for (tag = 2, j = 0; j < 64; tag++, j++) { + (void)sprintf(npath, "%s.%s", nbase, int_to_base64(stmp, tag)); + fd = open(npath, O_CREAT | O_EXCL | O_RDWR, 0); + if (fd > 0) { close(fd); break; } @@ -795,7 +810,7 @@ int xfs_RenameFiles(char *dir, xfs_Rename_t *renames, int n_renames) Log("Can't find a new name for %s\n", opath); return -1; } - if (rename(opath, npath)<0) { + if (rename(opath, npath) < 0) { Log("Can't rename %s to %s\n", opath, npath); return -1; } @@ -805,11 +820,10 @@ int xfs_RenameFiles(char *dir, xfs_Rename_t *renames, int n_renames) } -xfs_ListViceInodes(devname, mountedOn, resultFile, judgeInode, judgeParam, - forcep, forceR, wpath) -char *devname, *mountedOn, *resultFile, *wpath; -int (*judgeInode)(); -int *forcep, forceR; +int +xfs_ListViceInodes(char *devname, char *mountedOn, char *resultFile, + int (*judgeInode) (), int judgeParam, int *forcep, + int forceR, char *wpath) { FILE *inodeFile = NULL; i_list_inode_t info; @@ -827,7 +841,7 @@ int *forcep, forceR; char vol_dirname[1024]; int ninodes = 0; int code = 0; - xfs_Rename_t *renames = (xfs_Rename_t*)0; + xfs_Rename_t *renames = (xfs_Rename_t *) 0; int rename; #define N_RENAME_STEP 64 int n_renames = 0; @@ -838,7 +852,7 @@ int *forcep, forceR; *forcep = 0; - if (stat64(mountedOn, &sdirbuf)<0) { + if (stat64(mountedOn, &sdirbuf) < 0) { perror("xfs_ListViceInodes: stat64"); return -1; } @@ -849,12 +863,12 @@ int *forcep, forceR; return -1; } - if ((top_dirp=opendir(mountedOn)) == NULL) { + if ((top_dirp = opendir(mountedOn)) == NULL) { Log("Can't open directory %s to read inodes.\n", mountedOn); return -1; } - while (top_direntp=readdir64(top_dirp)) { + while (top_direntp = readdir64(top_dirp)) { /* Only descend directories with the AFSDIR attribute set. * Could also verify the contents of the atribute, but currently * they are not used. @@ -862,13 +876,13 @@ int *forcep, forceR; * only going through the directory containing the volume's inodes. * But I'm being complete as a first pass. */ - (void) sprintf(vol_dirname, "%s/%s", mountedOn, top_direntp->d_name); + (void)sprintf(vol_dirname, "%s/%s", mountedOn, top_direntp->d_name); length = SIZEOF_XFS_DATTR_T; - if (attr_get(vol_dirname, AFS_XFS_DATTR, (char*)&dattrs, &length, - ATTR_ROOT)) + if (attr_get + (vol_dirname, AFS_XFS_DATTR, (char *)&dattrs, &length, ATTR_ROOT)) continue; - if ((vol_dirp=opendir(vol_dirname)) == NULL) { + if ((vol_dirp = opendir(vol_dirname)) == NULL) { if (errno == ENOTDIR) continue; Log("Can't open directory %s to read inodes.\n", vol_dirname); @@ -877,15 +891,16 @@ int *forcep, forceR; pino = top_direntp->d_ino; n_renames = 0; - while (vol_direntp=readdir64(vol_dirp)) { + while (vol_direntp = readdir64(vol_dirp)) { if (vol_direntp->d_name[1] == '\0' || vol_direntp->d_name[1] == '.') continue; info.ili_version = AFS_XFS_ILI_VERSION; info_size = sizeof(i_list_inode_t); - code = ilistinode64(sdirbuf.st_dev, vol_direntp->d_ino, - &info, &info_size); + code = + ilistinode64(sdirbuf.st_dev, vol_direntp->d_ino, &info, + &info_size); if (code) { /* Where possible, give more explicit messages. */ switch (errno) { @@ -897,33 +912,33 @@ int *forcep, forceR; break; case EINVAL: case E2BIG: - if (info_size != sizeof(i_list_inode_t) || - info.ili_version != AFS_XFS_ILI_VERSION) { + if (info_size != sizeof(i_list_inode_t) + || info.ili_version != AFS_XFS_ILI_VERSION) { Log("Version skew between kernel and salvager.\n"); goto err1_exit; } break; } - /* Continue, so we collect all the errors in the first pass.*/ - Log("Error listing inode named %s/%s: %s\n", - vol_dirname, vol_direntp->d_name, strerror(errno)); - errors ++; + /* Continue, so we collect all the errors in the first pass. */ + Log("Error listing inode named %s/%s: %s\n", vol_dirname, + vol_direntp->d_name, strerror(errno)); + errors++; continue; } if (info.ili_attr_version != AFS_XFS_ATTR_VERS) { - Log("Unrecognized XFS attribute version %d in %s/%s. Upgrade salvager\n", - info.ili_attr_version, vol_dirname, vol_direntp->d_name); + Log("Unrecognized XFS attribute version %d in %s/%s. Upgrade salvager\n", info.ili_attr_version, vol_dirname, vol_direntp->d_name); goto err1_exit; } - if (judgeInode && (*judgeInode)(&info.ili_info, judgeParam) == 0) + if (judgeInode && (*judgeInode) (&info.ili_info, judgeParam) == 0) continue; - + rename = 0; - if (xfs_VerifyInode(vol_dirname, pino, vol_direntp->d_name, - &info, &rename)<0) { - errors ++; + if (xfs_VerifyInode + (vol_dirname, pino, vol_direntp->d_name, &info, + &rename) < 0) { + errors++; } if (rename) { @@ -931,11 +946,11 @@ int *forcep, forceR; if (n_renames >= n_avail) { n_avail += N_RENAME_STEP; if (n_avail == N_RENAME_STEP) - renames = (xfs_Rename_t*) - malloc(n_avail*sizeof(xfs_Rename_t)); + renames = (xfs_Rename_t *) + malloc(n_avail * sizeof(xfs_Rename_t)); else - renames = (xfs_Rename_t*) - realloc((char*)renames, + renames = (xfs_Rename_t *) + realloc((char *)renames, n_avail * sizeof(xfs_Rename_t)); if (!renames) { Log("Can't %salloc %lu bytes for rename list.\n", @@ -944,25 +959,26 @@ int *forcep, forceR; goto err1_exit; } } - (void) strcpy(renames[n_renames].name, vol_direntp->d_name); + (void)strcpy(renames[n_renames].name, vol_direntp->d_name); renames[n_renames].uniq = info.ili_info.param[2]; - n_renames ++; + n_renames++; } - if (fwrite(&info.ili_info, sizeof(vice_inode_info_t), 1, inodeFile) + if (fwrite + (&info.ili_info, sizeof(vice_inode_info_t), 1, inodeFile) != 1) { Log("Error writing inode file for partition %s\n", mountedOn); goto err1_exit; } - ninodes ++; + ninodes++; - } /* end while vol_direntp */ + } /* end while vol_direntp */ closedir(vol_dirp); - vol_dirp = (DIR*)0; + vol_dirp = (DIR *) 0; if (n_renames) { Log("Renaming files.\n"); - if (xfs_RenameFiles(vol_dirname, renames, n_renames)<0) { + if (xfs_RenameFiles(vol_dirname, renames, n_renames) < 0) { goto err1_exit; } } @@ -970,7 +986,7 @@ int *forcep, forceR; closedir(top_dirp); if (renames) - free((char*)renames); + free((char *)renames); if (fflush(inodeFile) == EOF) { ("Unable to successfully flush inode file for %s\n", mountedOn); fclose(inodeFile); @@ -979,24 +995,24 @@ int *forcep, forceR; if (fsync(fileno(inodeFile)) == -1) { Log("Unable to successfully fsync inode file for %s\n", mountedOn); fclose(inodeFile); - return errors ? -1 : -2; + return errors ? -1 : -2; } if (fclose(inodeFile) == EOF) { Log("Unable to successfully close inode file for %s\n", mountedOn); - return errors ? -1 : -2; + return errors ? -1 : -2; } /* * Paranoia: check that the file is really the right size */ if (stat(resultFile, &status) == -1) { Log("Unable to successfully stat inode file for %s\n", partition); - return errors ? -1 : -2; + return errors ? -1 : -2; } - if (status.st_size != ninodes * sizeof (struct ViceInodeInfo)) { - Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof (struct ViceInodeInfo), + if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + Log("Wrong size (%d instead of %d) in inode file for %s\n", + status.st_size, ninodes * sizeof(struct ViceInodeInfo), partition); - return errors ? -1 : -2; + return errors ? -1 : -2; } if (errors) { @@ -1006,13 +1022,13 @@ int *forcep, forceR; return 0; - err1_exit: + err1_exit: if (vol_dirp) closedir(vol_dirp); if (top_dirp) closedir(top_dirp); if (renames) - free((char*)renames); + free((char *)renames); if (inodeFile) fclose(inodeFile); return -1; @@ -1020,57 +1036,53 @@ int *forcep, forceR; #endif -ListViceInodes(devname, mountedOn, resultFile, judgeInode, judgeParam, forcep, - forceR, wpath) -char *devname, *mountedOn, *resultFile, *wpath; -int (*judgeInode)(); -int *forcep, forceR; +int +ListViceInodes(char *devname, char *mountedOn, char *resultFile, + int (*judgeInode) (), int judgeParam, int *forcep, int forceR, + char *wpath) { - FILE *inodeFile = NULL; - char dev[50], rdev[51]; - struct stat status; - struct efs_dinode *p; - struct ViceInodeInfo info; - struct stat root_inode; - int ninodes = 0, err = 0; - struct efs_dinode *dinodeBuf = NULL; - int last_cgno; + FILE *inodeFile = NULL; + char dev[50], rdev[51]; + struct stat status; + struct efs_dinode *p; + struct ViceInodeInfo info; + struct stat root_inode; + int ninodes = 0, err = 0; + struct efs_dinode *dinodeBuf = NULL; + int last_cgno; #ifdef AFS_SGI_EFS_IOPS_ENV - EFS_MOUNT *mp; + EFS_MOUNT *mp; #endif - ino_t imax, inum; /* total number of I-nodes in file system */ - - *forcep = 0; - sync(); sleep(1); /* simulate operator */ - sync(); sleep(1); - sync(); sleep(1); - - if (stat(mountedOn, &root_inode) < 0) { - Log("cannot stat: %s\n", mountedOn); - return -1; - } - + ino_t imax, inum; /* total number of I-nodes in file system */ + *forcep = 0; + sync(); + sleep(1); /* simulate operator */ + sync(); + sleep(1); + sync(); + sleep(1); + + if (stat(mountedOn, &root_inode) < 0) { + Log("cannot stat: %s\n", mountedOn); + return -1; + } #ifdef AFS_SGI_XFS_IOPS_ENV - if (!strcmp("xfs", root_inode.st_fstype)) { - return xfs_ListViceInodes(devname, mountedOn, resultFile, - judgeInode, judgeParam, - forcep, forceR, wpath); - } - else + if (!strcmp("xfs", root_inode.st_fstype)) { + return xfs_ListViceInodes(devname, mountedOn, resultFile, judgeInode, + judgeParam, forcep, forceR, wpath); + } else #endif #ifdef AFS_SGI_EFS_IOPS_ENV - if (root_inode.st_ino == EFS_ROOTINO) { - return efs_ListViceInodes(devname, mountedOn, resultFile, - judgeInode, judgeParam, - forcep, forceR, wpath); - } - else + if (root_inode.st_ino == EFS_ROOTINO) { + return efs_ListViceInodes(devname, mountedOn, resultFile, judgeInode, + judgeParam, forcep, forceR, wpath); + } else #endif - { - Log("%s is not root of a filesystem\n", mountedOn); - return -1; - } + { + Log("%s is not root of a filesystem\n", mountedOn); + return -1; + } } #else /* AFS_SGI_ENV */ @@ -1080,17 +1092,17 @@ int *forcep, forceR; #define MAXNINDIR (MAXBSIZE / sizeof(daddr_t)) struct bufarea { - struct bufarea *b_next; /* must be first */ - daddr_t b_bno; - int b_size; - union { - char b_buf[MAXBSIZE]; /* buffer space */ - short b_lnks[SPERB]; /* link counts */ - daddr_t b_indir[MAXNINDIR]; /* indirect block */ - struct fs b_fs; /* super block */ - struct cg b_cg; /* cylinder group */ - } b_un; - char b_dirty; + struct bufarea *b_next; /* must be first */ + daddr_t b_bno; + int b_size; + union { + char b_buf[MAXBSIZE]; /* buffer space */ + short b_lnks[SPERB]; /* link counts */ + daddr_t b_indir[MAXNINDIR]; /* indirect block */ + struct fs b_fs; /* super block */ + struct cg b_cg; /* cylinder group */ + } b_un; + char b_dirty; }; typedef struct bufarea BUFAREA; @@ -1099,290 +1111,297 @@ BUFAREA sblk; #endif /* AFS_HPUX_ENV */ extern char *afs_rawname(); -int ListViceInodes(devname, mountedOn, resultFile, judgeInode, judgeParam, forcep, forceR, wpath) - char *devname, *mountedOn, *resultFile, *wpath; - int (*judgeInode)(), *forcep, forceR; +int +ListViceInodes(char *devname, char *mountedOn, char *resultFile, + int (*judgeInode) (), int judgeParam, int *forcep, int forceR, + char *wpath) { - union { + union { #ifdef AFS_AIX_ENV - struct filsys fs; - char block[BSIZE]; -#else /* !AFS_AIX_ENV */ - struct fs fs; - char block[SBSIZE]; + struct filsys fs; + char block[BSIZE]; +#else /* !AFS_AIX_ENV */ + struct fs fs; + char block[SBSIZE]; #endif - } super; - int i, c, e, bufsize, code, err =0; - FILE *inodeFile = NULL; - char dev[50], rdev[100], err1[512], *ptr1; - struct dinode *inodes = NULL, *einodes, *dptr; - struct stat status; - int ninodes = 0; - struct dinode *p; - struct ViceInodeInfo info; - - *forcep = 0; - partition = mountedOn; - sprintf(rdev, "%s/%s", wpath, devname); - ptr1 = afs_rawname(rdev); - strcpy(rdev, ptr1); - - sync(); - /* Bletch: this is terrible; is there a better way to do this? Does this work? vfsck doesn't even sleep!! */ + } super; + int i, c, e, bufsize, code, err = 0; + FILE *inodeFile = NULL; + char dev[50], rdev[100], err1[512], *ptr1; + struct dinode *inodes = NULL, *einodes, *dptr; + struct stat status; + int ninodes = 0; + struct dinode *p; + struct ViceInodeInfo info; + + *forcep = 0; + partition = mountedOn; + sprintf(rdev, "%s/%s", wpath, devname); + ptr1 = afs_rawname(rdev); + strcpy(rdev, ptr1); + + sync(); + /* Bletch: this is terrible; is there a better way to do this? Does this work? vfsck doesn't even sleep!! */ #ifdef AFS_AIX_ENV - sleep(5); /* Trying a smaller one for aix */ + sleep(5); /* Trying a smaller one for aix */ #else - sleep(10); + sleep(10); #endif - pfd = open(rdev, O_RDONLY); - if (pfd <= 0) { - sprintf(err1, "Could not open device %s to get inode list\n", rdev); - perror(err1); - return -1; - } - - + pfd = open(rdev, O_RDONLY); + if (pfd <= 0) { + sprintf(err1, "Could not open device %s to get inode list\n", rdev); + perror(err1); + return -1; + } #ifdef AFS_AIX_ENV - if (bread(pfd, (char *)&super.fs, SUPERB, sizeof super.fs) == -1) { + if (bread(pfd, (char *)&super.fs, SUPERB, sizeof super.fs) == -1) { #else #ifdef AFS_HPUX_ENV - if (bread(pfd, (char *)&sblock, SBLOCK, SBSIZE) == -1) { + if (bread(pfd, (char *)&sblock, SBLOCK, SBSIZE) == -1) { #else - if (bread(pfd, super.block, SBLOCK, SBSIZE) == -1) { + if (bread(pfd, super.block, SBLOCK, SBSIZE) == -1) { #endif /* AFS_HPUX_ENV */ #endif - Log("Unable to read superblock, partition %s\n", partition); - goto out; - } - - inodeFile = fopen(resultFile, "w"); - if (inodeFile == NULL) { - Log("Unable to create inode description file %s\n", resultFile); - goto out; - } - + Log("Unable to read superblock, partition %s\n", partition); + goto out; + } + + inodeFile = fopen(resultFile, "w"); + if (inodeFile == NULL) { + Log("Unable to create inode description file %s\n", resultFile); + goto out; + } #ifdef AFS_AIX_ENV - /* - char *FSlabel(), *fslabel=0; - fslabel = FSlabel(&super.fs); + /* + * char *FSlabel(), *fslabel=0; + * fslabel = FSlabel(&super.fs); */ - if (super.fs.s_bsize == 0) - super.fs.s_bsize = 512; - if (super.fs.s_bsize != BSIZE ) { - Log("SuperBlk: Cluster size not %d; run vfsck\n", BSIZE); - goto out; - } - fmax = super.fs.s_fsize; /* first invalid blk num */ - imax = ((ino_t)super.fs.s_isize - (SUPERB+1)) * INOPB; - if (imax == 0) { - Log("Size check: imax==0!\n"); - goto out; - } - if (GetAuxInodeFile(partition, &status) == 0) { - Log("Can't access Aux inode file for partition %s, aborting\n", partition); - goto out; - } - for (inum=1; inum <= imax; inum++) { - struct dauxinode *auxp; - if ((auxp = IsAfsInode(inum)) == NULL){ - /* Not an afs inode, keep going */ - continue; - } - if ((p = ginode(inum)) == NULL) - continue; - /* deleted/non-existent inode when di_mode == 0 */ - if (!p->di_mode) - continue; - info.inodeNumber = (int)inum; - info.byteCount = p->di_size; - info.linkCount = p->di_nlink; - info.u.param[0] = auxp->aux_param1; - info.u.param[1] = auxp->aux_param2; - info.u.param[2] = auxp->aux_param3; - info.u.param[3] = auxp->aux_param4; - if (judgeInode && (*judgeInode)(&info, judgeParam) == 0) - continue; - if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { - Log("Error writing inode file for partition %s\n", partition); - goto out; - } - ninodes++; - } + if (super.fs.s_bsize == 0) + super.fs.s_bsize = 512; + if (super.fs.s_bsize != BSIZE) { + Log("SuperBlk: Cluster size not %d; run vfsck\n", BSIZE); + goto out; + } + fmax = super.fs.s_fsize; /* first invalid blk num */ + imax = ((ino_t) super.fs.s_isize - (SUPERB + 1)) * INOPB; + if (imax == 0) { + Log("Size check: imax==0!\n"); + goto out; + } + if (GetAuxInodeFile(partition, &status) == 0) { + Log("Can't access Aux inode file for partition %s, aborting\n", + partition); + goto out; + } + for (inum = 1; inum <= imax; inum++) { + struct dauxinode *auxp; + if ((auxp = IsAfsInode(inum)) == NULL) { + /* Not an afs inode, keep going */ + continue; + } + if ((p = ginode(inum)) == NULL) + continue; + /* deleted/non-existent inode when di_mode == 0 */ + if (!p->di_mode) + continue; + info.inodeNumber = (int)inum; + info.byteCount = p->di_size; + info.linkCount = p->di_nlink; + info.u.param[0] = auxp->aux_param1; + info.u.param[1] = auxp->aux_param2; + info.u.param[2] = auxp->aux_param3; + info.u.param[3] = auxp->aux_param4; + if (judgeInode && (*judgeInode) (&info, judgeParam) == 0) + continue; + if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { + Log("Error writing inode file for partition %s\n", partition); + goto out; + } + ninodes++; + } #else - /* - * run a few consistency checks of the superblock - * (Cribbed from vfsck) - */ + /* + * run a few consistency checks of the superblock + * (Cribbed from vfsck) + */ #ifdef AFS_HPUX_ENV #if defined(FD_FSMAGIC) - if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN) && (sblock.fs_magic != FD_FSMAGIC) + if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN) + && (sblock.fs_magic != FD_FSMAGIC) #if defined(AFS_HPUX101_ENV) - && ( sblock.fs_magic != FD_FSMAGIC_2) + && (sblock.fs_magic != FD_FSMAGIC_2) #endif - ) - { + ) { #else - if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)) { + if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)) { #endif - Log("There's something wrong with the superblock for partition %s; bad magic (%d) run vfsck\n", - partition, sblock.fs_magic); - goto out; - } - if (sblock.fs_ncg < 1 ) { - Log("There's something wrong with the superblock for partition %s; NCG OUT OF RANGE (%d) run vfsck\n", - partition, sblock.fs_ncg); - goto out; - } - if (sblock.fs_cpg < 1 || sblock.fs_cpg > MAXCPG ) { - Log("There's something wrong with the superblock for partition %s; CPG OUT OF RANGE (%d) run vfsck\n", - partition, sblock.fs_cpg); - goto out; - } - if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl || - (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) { - Log("There's something wrong with the superblock for partition %s; NCYL LESS THAN NCG*CPG run vfsck\n", partition); - goto out; - } - if (sblock.fs_sbsize > SBSIZE ) { - Log("There's something wrong with the superblock for partition %s; bsize too large (%d vs. %d) run vfsck\n", - partition, sblock.fs_sbsize, sblock.fs_bsize); - goto out; - } - + Log("There's something wrong with the superblock for partition %s; bad magic (%d) run vfsck\n", partition, sblock.fs_magic); + goto out; + } + if (sblock.fs_ncg < 1) { + Log("There's something wrong with the superblock for partition %s; NCG OUT OF RANGE (%d) run vfsck\n", partition, sblock.fs_ncg); + goto out; + } + if (sblock.fs_cpg < 1 || sblock.fs_cpg > MAXCPG) { + Log("There's something wrong with the superblock for partition %s; CPG OUT OF RANGE (%d) run vfsck\n", partition, sblock.fs_cpg); + goto out; + } + if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl + || (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) { + Log("There's something wrong with the superblock for partition %s; NCYL LESS THAN NCG*CPG run vfsck\n", partition); + goto out; + } + if (sblock.fs_sbsize > SBSIZE) { + Log("There's something wrong with the superblock for partition %s; bsize too large (%d vs. %d) run vfsck\n", partition, sblock.fs_sbsize, sblock.fs_bsize); + goto out; + } #else - if ( - (super.fs.fs_magic != FS_MAGIC) - || (super.fs.fs_ncg < 1) + if ((super.fs.fs_magic != FS_MAGIC) + || (super.fs.fs_ncg < 1) #if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) - || (super.fs.fs_cpg < 1) + || (super.fs.fs_cpg < 1) #else - || (super.fs.fs_cpg < 1 || super.fs.fs_cpg > MAXCPG) + || (super.fs.fs_cpg < 1 || super.fs.fs_cpg > MAXCPG) #endif - || (super.fs.fs_ncg * super.fs.fs_cpg < super.fs.fs_ncyl || - (super.fs.fs_ncg - 1) * super.fs.fs_cpg >= super.fs.fs_ncyl) - || (super.fs.fs_sbsize > SBSIZE)) { - Log("There's something wrong with the superblock for partition %s; run vfsck\n", partition); - goto out; - } + || (super.fs.fs_ncg * super.fs.fs_cpg < super.fs.fs_ncyl + || (super.fs.fs_ncg - 1) * super.fs.fs_cpg >= super.fs.fs_ncyl) + || (super.fs.fs_sbsize > SBSIZE)) { + Log("There's something wrong with the superblock for partition %s; run vfsck\n", partition); + goto out; + } #endif /* AFS_HPUX_ENV */ #ifdef AFS_HPUX_ENV - bufsize = sblock.fs_ipg * sizeof(struct dinode); + bufsize = sblock.fs_ipg * sizeof(struct dinode); #else - bufsize = super.fs.fs_ipg * sizeof(struct dinode); + bufsize = super.fs.fs_ipg * sizeof(struct dinode); #endif /* AFS_HPUX_ENV */ - inodes = (struct dinode *) malloc(bufsize); - einodes = (struct dinode *) (((char *)inodes) + bufsize); - if (inodes == NULL) { - Log("Unable to allocate enough memory to scan inodes; help!\n"); - goto out; - } - Log("Scanning inodes on device %s...\n", rdev); + inodes = (struct dinode *)malloc(bufsize); + einodes = (struct dinode *)(((char *)inodes) + bufsize); + if (inodes == NULL) { + Log("Unable to allocate enough memory to scan inodes; help!\n"); + goto out; + } + Log("Scanning inodes on device %s...\n", rdev); #ifdef AFS_HPUX_ENV - for (c = 0; c < sblock.fs_ncg; c++) { - i = c*sblock.fs_ipg; e = i+sblock.fs_ipg; + for (c = 0; c < sblock.fs_ncg; c++) { + i = c * sblock.fs_ipg; + e = i + sblock.fs_ipg; #if defined(AFS_HPUX102_ENV) - if (lseek(pfd, dbtoo(fsbtodb(&sblock,itod(&sblock,i))), L_SET) == -1) { + if (lseek(pfd, dbtoo(fsbtodb(&sblock, itod(&sblock, i))), L_SET) == + -1) { #else - if (lseek(pfd, dbtob(fsbtodb(&sblock,itod(&sblock,i))), L_SET) == -1) { + if (lseek(pfd, dbtob(fsbtodb(&sblock, itod(&sblock, i))), L_SET) == + -1) { #endif #else - for (c = 0; c < super.fs.fs_ncg; c++) { - daddr_t dblk1; + for (c = 0; c < super.fs.fs_ncg; c++) { + daddr_t dblk1; #if defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) - daddr_t f1; + daddr_t f1; #if defined(AFS_DARWIN_ENV) #define offset_t off_t #define llseek lseek #endif - offset_t off; + offset_t off; #endif /* AFS_SUN5_ENV */ - i = c*super.fs.fs_ipg; e = i+super.fs.fs_ipg; + i = c * super.fs.fs_ipg; + e = i + super.fs.fs_ipg; #ifdef AFS_OSF_ENV dblk1 = fsbtodb(&super.fs, itod(&super.fs, i)); - if (lseek(pfd, (off_t) ((off_t)dblk1 * DEV_BSIZE), L_SET) == -1) { + if (lseek(pfd, (off_t) ((off_t) dblk1 * DEV_BSIZE), L_SET) == -1) { #else #if defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) - f1 = fsbtodb(&super.fs,itod(&super.fs,i)); - off = (offset_t)f1 << DEV_BSHIFT; + f1 = fsbtodb(&super.fs, itod(&super.fs, i)); + off = (offset_t) f1 << DEV_BSHIFT; if (llseek(pfd, off, L_SET) == -1) { #else - if (lseek(pfd, dbtob(fsbtodb(&super.fs,itod(&super.fs,i))), L_SET) == -1) { + if (lseek(pfd, dbtob(fsbtodb(&super.fs, itod(&super.fs, i))), L_SET) + == -1) { #endif /* AFS_SUN5_ENV */ #endif /* AFS_OSF_ENV */ #endif /* AFS_HPUX_ENV */ - Log("Error reading inodes for partition %s; run vfsck\n", partition); + Log("Error reading inodes for partition %s; run vfsck\n", + partition); goto out; } - while (idi_mode = 0; dptr++; - dptr->di_mode = 0; dptr++; - dptr->di_mode = 0; dptr++; - dptr->di_mode = 0; dptr++; + dptr->di_mode = 0; + dptr++; + dptr->di_mode = 0; + dptr++; + dptr->di_mode = 0; + dptr++; + dptr->di_mode = 0; + dptr++; } else dptr += 4; } } - for (p=inodes; pdi_vicep1, p->di_vicep2, p->di_vicep3, p->di_mode, p->di_size, p->di_nlink); -printf("Ino=%d, v1=%x, v2=%x, v3=%x, mode=%x size=%d, lcnt=%d\n", i, p->di_vicep1, p->di_vicep2, p->di_vicep3, p->di_mode, p->di_size, p->di_nlink); + Log("Ino=%d, v1=%x, v2=%x, v3=%x, mode=%x size=%d, lcnt=%d\n", + i, p->di_vicep1, p->di_vicep2, p->di_vicep3, p->di_mode, + p->di_size, p->di_nlink); + printf + ("Ino=%d, v1=%x, v2=%x, v3=%x, mode=%x size=%d, lcnt=%d\n", + i, p->di_vicep1, p->di_vicep2, p->di_vicep3, p->di_mode, + p->di_size, p->di_nlink); #endif #ifdef AFS_OSF_ENV #ifdef AFS_3DISPARES /* Check to see if this inode is a pre-"OSF1 4.0D" inode */ if ((p->di_uid || p->di_gid) - && !(p->di_flags & (IC_XUID|IC_XGID))) { - Log("Found unconverted inode %d: Use 'fs_conv_dux40D convert' on partition %s\n", - i, partition); - goto out; + && !(p->di_flags & (IC_XUID | IC_XGID))) { + Log("Found unconverted inode %d: Use 'fs_conv_dux40D convert' on partition %s\n", i, partition); + goto out; } #else - assert(0); /* define AFS_3DISPARES in param.h */ + assert(0); /* define AFS_3DISPARES in param.h */ #endif #endif #if defined(AFS_SUN56_ENV) /* if this is a pre-sol2.6 unconverted inode, bail out */ - { - afs_uint32 p1, p2, p3, p4; - int p5; - quad* q; - - q = (quad *)&(p->di_ic.ic_lsize); - p1 = p->di_gen; - p2 = p->di_ic.ic_flags; - p3 = q->val[0]; - p4 = p->di_ic.ic_uid; - p5 = p->di_ic.ic_gid; - - if ( (p2 || p3) && !p4 && (p5 == -2) ) { - Log("Found unconverted inode %d\n", i); - Log("You should run the AFS file conversion utility\n"); - goto out; + afs_uint32 p1, p2, p3, p4; + int p5; + quad *q; + + q = (quad *) & (p->di_ic.ic_lsize); + p1 = p->di_gen; + p2 = p->di_ic.ic_flags; + p3 = q->val[0]; + p4 = p->di_ic.ic_uid; + p5 = p->di_ic.ic_gid; + + if ((p2 || p3) && !p4 && (p5 == -2)) { + Log("Found unconverted inode %d\n", i); + Log("You should run the AFS file conversion utility\n"); + goto out; + } } - } #endif - if (IS_DVICEMAGIC(p) && (p->di_mode&IFMT) == IFREG) { - afs_uint32 p2 = p->di_vicep2, p3 = DI_VICEP3(p); + if (IS_DVICEMAGIC(p) && (p->di_mode & IFMT) == IFREG) { + afs_uint32 p2 = p->di_vicep2, p3 = DI_VICEP3(p); - info.u.param[0] = p->di_vicep1; + info.u.param[0] = p->di_vicep1; #ifdef AFS_3DISPARES if (((p2 >> 3) == INODESPECIAL) && (p2 & 0x3)) { info.u.param[1] = INODESPECIAL; @@ -1391,103 +1410,102 @@ printf("Ino=%d, v1=%x, v2=%x, v3=%x, mode=%x size=%d, lcnt=%d\n", i, p->di_vicep } else { info.u.param[1] = ((p2 >> 27) << 16) + (p3 & 0xffff); info.u.param[2] = (p2 & 0x3fffff); - info.u.param[3] = (((p2 >> 22) & 0x1f) << 16) + (p3 >> 16); + info.u.param[3] = + (((p2 >> 22) & 0x1f) << 16) + (p3 >> 16); } #else - info.u.param[1] = p->di_vicep2; - info.u.param[2] = DI_VICEP3(p); - info.u.param[3] = p->di_vicep4; + info.u.param[1] = p->di_vicep2; + info.u.param[2] = DI_VICEP3(p); + info.u.param[3] = p->di_vicep4; #endif - info.inodeNumber = i; - info.byteCount = p->di_size; - info.linkCount = p->di_nlink; - if (judgeInode && (*judgeInode)(&info, judgeParam) == 0) - continue; - if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { - Log("Error writing inode file for partition %s\n", partition); - goto out; + info.inodeNumber = i; + info.byteCount = p->di_size; + info.linkCount = p->di_nlink; + if (judgeInode && (*judgeInode) (&info, judgeParam) == 0) + continue; + if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { + Log("Error writing inode file for partition %s\n", + partition); + goto out; } ninodes++; - } + } } } - } - if (inodes) free(inodes); + } + if (inodes) + free(inodes); #endif - if (fflush(inodeFile) == EOF) { - Log("Unable to successfully flush inode file for %s\n", partition); - err = -2; - goto out1; - } - if (fsync(fileno(inodeFile)) == -1) { - Log("Unable to successfully fsync inode file for %s\n", partition); - err = -2; - goto out1; - } - if (fclose(inodeFile) == EOF) { - Log("Unable to successfully close inode file for %s\n", partition); - err = -2; - goto out1; - } + if (fflush(inodeFile) == EOF) { + Log("Unable to successfully flush inode file for %s\n", partition); + err = -2; + goto out1; + } + if (fsync(fileno(inodeFile)) == -1) { + Log("Unable to successfully fsync inode file for %s\n", partition); + err = -2; + goto out1; + } + if (fclose(inodeFile) == EOF) { + Log("Unable to successfully close inode file for %s\n", partition); + err = -2; + goto out1; + } - /* - * Paranoia: check that the file is really the right size - */ - if (stat(resultFile, &status) == -1) { - Log("Unable to successfully stat inode file for %s\n", partition); - err = -2; - goto out1; - } - if (status.st_size != ninodes * sizeof (struct ViceInodeInfo)) { - Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof (struct ViceInodeInfo), partition); - err = -2; - goto out1; - } - close(pfd); - return 0; - -out: - err = -1; -out1: - close(pfd); - if (inodeFile) - fclose(inodeFile); - if (inodes) - free(inodes); - return err; + /* + * Paranoia: check that the file is really the right size + */ + if (stat(resultFile, &status) == -1) { + Log("Unable to successfully stat inode file for %s\n", partition); + err = -2; + goto out1; + } + if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + Log("Wrong size (%d instead of %d) in inode file for %s\n", + status.st_size, ninodes * sizeof(struct ViceInodeInfo), + partition); + err = -2; + goto out1; + } + close(pfd); + return 0; + + out: + err = -1; + out1: + close(pfd); + if (inodeFile) + fclose(inodeFile); + if (inodes) + free(inodes); + return err; } -#endif /* !AFS_SGI_ENV */ -#endif /* !AFS_AIX31_ENV */ +#endif /* !AFS_SGI_ENV */ +#endif /* !AFS_AIX31_ENV */ #ifdef AFS_DARWIN_ENV #undef dbtob #define dbtob(db) ((unsigned)(db) << DEV_BSHIFT) #endif -int bread(fd, buf, blk, size) - int fd; - char *buf; - daddr_t blk; - afs_int32 size; +int +bread(int fd, char *buf, daddr_t blk, afs_int32 size) { #ifdef AFS_AIX_ENV #ifdef AFS_AIX41_ENV - offset_t off = (offset_t)blk << FSBSHIFT; + offset_t off = (offset_t) blk << FSBSHIFT; if (llseek(fd, off, 0) < 0) { Log("Unable to seek to offset %llu for block %u\n", off, blk); return -1; } #else /* AFS_AIX41_ENV */ if (lseek(fd, blk * Bsize, 0) < 0) { - Log("Unable to seek to offset %u for block %u\n", - blk * Bsize, blk); + Log("Unable to seek to offset %u for block %u\n", blk * Bsize, blk); } #endif /* AFS_AIX41_ENV */ #else - if (lseek(fd, (off_t)dbtob(blk), L_SET) < 0) { - Log("Unable to seek to offset %u for block %u\n", - dbtob(blk), blk); + if (lseek(fd, (off_t) dbtob(blk), L_SET) < 0) { + Log("Unable to seek to offset %u for block %u\n", dbtob(blk), blk); } #endif if (read(fd, buf, size) != size) { diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index 6c8dfd96f..399492e45 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -12,7 +12,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/namei_ops.c,v 1.1.1.8 2002/09/26 19:09:23 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/namei_ops.c,v 1.21 2003/11/24 03:51:24 shadow Exp $"); #ifdef AFS_NAMEI_ENV #include @@ -42,19 +43,45 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/namei_ops.c,v 1.1.1.8 2002/09/26 19 #include "viceinode.h" #include "voldefs.h" #include "partition.h" +#include + +/*@+fcnmacros +macrofcndecl@*/ +#ifdef O_LARGEFILE +#ifdef S_SPLINT_S +extern off64_t afs_lseek(int FD, off64_t O, int F); +#endif /*S_SPLINT_S */ +#define afs_lseek(FD, O, F) lseek64(FD, (off64_t)(O), F) +#define afs_stat stat64 +#define afs_fstat fstat64 +#define afs_open open64 +#define afs_fopen fopen64 +#else /* !O_LARGEFILE */ +#ifdef S_SPLINT_S +extern off_t afs_lseek(int FD, off_t O, int F); +#endif /*S_SPLINT_S */ +#define afs_lseek(FD, O, F) lseek(FD, (off_t)(O), F) +#define afs_stat stat +#define afs_fstat fstat +#define afs_open open +#define afs_fopen fopen +#endif /* !O_LARGEFILE */ +/*@=fcnmacros =macrofcndecl@*/ + +/*@printflike@*/ extern void Log(const char *format, ...); extern char *volutil_PartitionName_r(int volid, char *buf, int buflen); -int namei_iread(IHandle_t *h, int offset, char *buf, int size) +afs_sfsize_t +namei_iread(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size) { - int nBytes; + afs_sfsize_t nBytes; FdHandle_t *fdP; fdP = IH_OPEN(h); if (fdP == NULL) return -1; - if (FDH_SEEK(fdP, offset, SEEK_SET)<0) { + if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { FDH_REALLYCLOSE(fdP); return -1; } @@ -64,16 +91,17 @@ int namei_iread(IHandle_t *h, int offset, char *buf, int size) return nBytes; } -int namei_iwrite(IHandle_t *h, int offset, char *buf, int size) +afs_sfsize_t +namei_iwrite(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size) { - int nBytes; + afs_sfsize_t nBytes; FdHandle_t *fdP; fdP = IH_OPEN(h); if (fdP == NULL) return -1; - if (FDH_SEEK(fdP, offset, SEEK_SET)<0) { + if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { FDH_REALLYCLOSE(fdP); return -1; } @@ -107,22 +135,22 @@ int namei_iwrite(IHandle_t *h, int offset, char *buf, int size) #define NAMEI_SPECDIR "special" #define NAMEI_SPECDIRLEN (sizeof(NAMEI_SPECDIR)-1) -#define NAMEI_MAXVOLS 5 /* Maximum supported number of volumes per volume - * group, not counting temporary (move) volumes. - * This is the number of separate files, all having - * the same vnode number, which can occur in a volume - * group at once. - */ +#define NAMEI_MAXVOLS 5 /* Maximum supported number of volumes per volume + * group, not counting temporary (move) volumes. + * This is the number of separate files, all having + * the same vnode number, which can occur in a volume + * group at once. + */ + - typedef struct { int ogm_owner; int ogm_group; int ogm_mode; } namei_ogm_t; -int namei_SetLinkCount(FdHandle_t *h, Inode ino, int count, int locked); -static int GetFreeTag(IHandle_t *ih, int vno); +int namei_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked); +static int GetFreeTag(IHandle_t * ih, int vno); /* namei_HandleToInodeDir * @@ -131,18 +159,20 @@ static int GetFreeTag(IHandle_t *ih, int vno); * */ #define PNAME_BLEN 64 -static void namei_HandleToInodeDir(namei_t *name, IHandle_t *ih) +static void +namei_HandleToInodeDir(namei_t * name, IHandle_t * ih) { char *tmp = name->n_base; memset(name, '\0', sizeof(*name)); - (void) volutil_PartitionName_r(ih->ih_dev, tmp, NAMEI_LCOMP_LEN); + (void)volutil_PartitionName_r(ih->ih_dev, tmp, NAMEI_LCOMP_LEN); tmp += VICE_PREFIX_SIZE; tmp += ih->ih_dev > 25 ? 2 : 1; - *tmp = '/'; tmp ++; - (void) strcpy(tmp, INODEDIR); - (void) strcpy(name->n_path, name->n_base); + *tmp = '/'; + tmp++; + (void)strcpy(tmp, INODEDIR); + (void)strcpy(name->n_path, name->n_base); } #define addtoname(N, C) \ @@ -151,16 +181,17 @@ do { \ } while(0) -static void namei_HandleToVolDir(namei_t *name, IHandle_t *ih) +static void +namei_HandleToVolDir(namei_t * name, IHandle_t * ih) { lb64_string_t tmp; namei_HandleToInodeDir(name, ih); - (void) int32_to_flipbase64(tmp, (int64_t)(ih->ih_vid & 0xff)); - (void) strcpy(name->n_voldir1, tmp); + (void)int32_to_flipbase64(tmp, (int64_t) (ih->ih_vid & 0xff)); + (void)strcpy(name->n_voldir1, tmp); addtoname(name, name->n_voldir1); - (void) int32_to_flipbase64(tmp, (int64_t)ih->ih_vid); - (void) strcpy(name->n_voldir2, tmp); + (void)int32_to_flipbase64(tmp, (int64_t) ih->ih_vid); + (void)strcpy(name->n_voldir2, tmp); addtoname(name, name->n_voldir2); } @@ -169,28 +200,28 @@ static void namei_HandleToVolDir(namei_t *name, IHandle_t *ih) * Constructs a file name for the fully qualified handle. * Note that special files end up in /vicepX/InodeDir/Vxx/V*.data/special */ -void namei_HandleToName(namei_t *name, IHandle_t *ih) +void +namei_HandleToName(namei_t * name, IHandle_t * ih) { lb64_string_t str; int vno = (int)(ih->ih_ino & NAMEI_VNODEMASK); - + namei_HandleToVolDir(name, ih); if (vno == NAMEI_VNODESPECIAL) { - (void) strcpy(name->n_dir1, NAMEI_SPECDIR); + (void)strcpy(name->n_dir1, NAMEI_SPECDIR); addtoname(name, name->n_dir1); name->n_dir2[0] = '\0'; - } - else { - (void) int32_to_flipbase64(str, VNO_DIR1(vno)); - (void) strcpy(name->n_dir1, str); + } else { + (void)int32_to_flipbase64(str, VNO_DIR1(vno)); + (void)strcpy(name->n_dir1, str); addtoname(name, name->n_dir1); - (void) int32_to_flipbase64(str, VNO_DIR2(vno)); - (void) strcpy(name->n_dir2, str); + (void)int32_to_flipbase64(str, VNO_DIR2(vno)); + (void)strcpy(name->n_dir2, str); addtoname(name, name->n_dir2); } - (void) int64_to_flipbase64(str, (int64_t)ih->ih_ino); - (void) strcpy(name->n_inode, str); + (void)int64_to_flipbase64(str, (int64_t) ih->ih_ino); + (void)strcpy(name->n_inode, str); addtoname(name, name->n_inode); } @@ -199,22 +230,25 @@ void namei_HandleToName(namei_t *name, IHandle_t *ih) */ #define VICE_README "These files and directories are a part of the AFS \ namespace. Modifying them\nin any way will result in loss of AFS data.\n" -int namei_ViceREADME(char *partition) +int +namei_ViceREADME(char *partition) { - char filename[32]; - int fd; - - /* Create the inode directory if we're starting for the first time */ - sprintf(filename, "%s/%s", partition, INODEDIR); - mkdir(filename, 0700); - - sprintf(filename, "%s/%s/README", partition, INODEDIR); - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0444); - if (fd >= 0) { - write(fd, VICE_README, strlen(VICE_README)); - close(fd); - } - return(errno); + char filename[32]; + int fd; + + /* Create the inode directory if we're starting for the first time */ + (void)afs_snprintf(filename, sizeof filename, "%s/%s", partition, + INODEDIR); + mkdir(filename, 0700); + + (void)afs_snprintf(filename, sizeof filename, "%s/%s/README", partition, + INODEDIR); + fd = afs_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0444); + if (fd >= 0) { + (void)write(fd, VICE_README, strlen(VICE_README)); + close(fd); + } + return (errno); } @@ -227,7 +261,7 @@ do { \ else { \ *created = 1; \ } \ -} while (0) +} while (0) #define create_nextdir(A) \ do { \ @@ -239,13 +273,14 @@ do { \ * If creating the file failed because of ENOENT or ENOTDIR, try * creating all the directories first. */ -static int namei_CreateDataDirectories(namei_t *name, int *created) +static int +namei_CreateDataDirectories(namei_t * name, int *created) { char tmp[256]; *created = 0; - (void) strcpy(tmp, name->n_base); + (void)strcpy(tmp, name->n_base); create_dir(); create_nextdir(name->n_voldir1); @@ -255,7 +290,7 @@ static int namei_CreateDataDirectories(namei_t *name, int *created) create_nextdir(name->n_dir2); } return 0; -} +} /* delTree(): Deletes an entire tree of directories (no files) * Input: @@ -279,64 +314,64 @@ static int namei_CreateDataDirectories(namei_t *name, int *created) static int delTree(char *root, char *tree, int *errp) { - char *cp; - DIR *ds; - struct dirent *dirp; - struct stat st; - - if (*tree) { - /* delete the children first */ - cp = strchr(tree, '/'); - if (cp) { - delTree(root, cp+1, errp); - *cp = '\0'; - } - else - cp = tree + strlen(tree); /* move cp to the end of string tree */ - - /* now delete all entries in this dir */ - if ( (ds = opendir(root)) != (DIR *)NULL) { - errno = 0; - while ((dirp = readdir(ds))) { - /* ignore . and .. */ - if (!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, "..")) - continue; - /* since root is big enough, we reuse the space to - * concatenate the dirname to the current tree - */ - strcat(root, "/"); - strcat(root, dirp->d_name); - if ( stat(root, &st) == 0 && S_ISDIR(st.st_mode)) { - /* delete this subtree */ - delTree(root, cp+1, errp); + char *cp; + DIR *ds; + struct dirent *dirp; + struct afs_stat st; + + if (*tree) { + /* delete the children first */ + cp = strchr(tree, '/'); + if (cp) { + delTree(root, cp + 1, errp); + *cp = '\0'; } else - *errp = *errp ? *errp : errno; - - /* recover path to our cur tree by truncating it to - * its original len - */ - *cp = 0; - } - /* if (!errno) -- closedir not implicit if we got an error */ - closedir(ds); - } - - /* finally axe the current dir */ - if (rmdir(root)) - *errp = *errp ? *errp : errno; - -#ifndef AFS_PTHREAD_ENV /* let rx get some work done */ - IOMGR_Poll(); + cp = tree + strlen(tree); /* move cp to the end of string tree */ + + /* now delete all entries in this dir */ + if ((ds = opendir(root)) != (DIR *) NULL) { + errno = 0; + while ((dirp = readdir(ds))) { + /* ignore . and .. */ + if (!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, "..")) + continue; + /* since root is big enough, we reuse the space to + * concatenate the dirname to the current tree + */ + strcat(root, "/"); + strcat(root, dirp->d_name); + if (afs_stat(root, &st) == 0 && S_ISDIR(st.st_mode)) { + /* delete this subtree */ + delTree(root, cp + 1, errp); + } else + *errp = *errp ? *errp : errno; + + /* recover path to our cur tree by truncating it to + * its original len + */ + *cp = 0; + } + /* if (!errno) -- closedir not implicit if we got an error */ + closedir(ds); + } + + /* finally axe the current dir */ + if (rmdir(root)) + *errp = *errp ? *errp : errno; + +#ifndef AFS_PTHREAD_ENV /* let rx get some work done */ + IOMGR_Poll(); #endif /* !AFS_PTHREAD_ENV */ - } /* if valid tree */ - - /* if we encountered errors during cleanup, we return a -1 */ - if (*errp) - return -1; + } + + /* if valid tree */ + /* if we encountered errors during cleanup, we return a -1 */ + if (*errp) + return -1; + + return 0; - return 0; - } /* namei_RemoveDataDirectories @@ -348,20 +383,21 @@ delTree(char *root, char *tree, int *errp) * and only do rmdir's. */ -static int namei_RemoveDataDirectories(namei_t *name) +static int +namei_RemoveDataDirectories(namei_t * name) { - char pbuf[MAXPATHLEN], *path = pbuf; - int prefixlen = strlen(name->n_base), err = 0; - - strcpy(path, name->n_path); + char pbuf[MAXPATHLEN], *path = pbuf; + int prefixlen = strlen(name->n_base), err = 0; + + strcpy(path, name->n_path); - /* move past the prefix */ - path = path+prefixlen+1; /* skip over the trailing / */ + /* move past the prefix */ + path = path + prefixlen + 1; /* skip over the trailing / */ - /* now delete all dirs upto path */ - return delTree(pbuf, path, &err); - -} + /* now delete all dirs upto path */ + return delTree(pbuf, path, &err); + +} /* Create the file in the name space. * @@ -389,13 +425,14 @@ static int namei_RemoveDataDirectories(namei_t *name) * details of the inode numbers. This only allows for 7 volume special * types, but if we get that far, this could should be dead by then. */ -Inode namei_MakeSpecIno(int volid, int type) +Inode +namei_MakeSpecIno(int volid, int type) { Inode ino; ino = NAMEI_INODESPECIAL; type &= NAMEI_TAGMASK; - ino |= ((Inode)type) << NAMEI_TAGSHIFT; - ino |= ((Inode)volid) << NAMEI_UNIQSHIFT; + ino |= ((Inode) type) << NAMEI_TAGSHIFT; + ino |= ((Inode) volid) << NAMEI_UNIQSHIFT; return ino; } @@ -405,18 +442,19 @@ Inode namei_MakeSpecIno(int volid, int type) * group - next 15 bits of parm. * mode - 2 bits of parm, then lowest = 3 bits of tag. */ -static int SetOGM(int fd, int parm, int tag) +static int +SetOGM(int fd, int parm, int tag) { int owner, group, mode; owner = parm & 0x7fff; group = (parm >> 15) & 0x7fff; - if (fchown(fd, owner, group)<0) + if (fchown(fd, owner, group) < 0) return -1; mode = (parm >> 27) & 0x18; mode |= tag & 0x7; - if (fchmod(fd, mode)<0) + if (fchmod(fd, mode) < 0) return -1; return 0; @@ -424,29 +462,32 @@ static int SetOGM(int fd, int parm, int tag) } /* GetOGM - get parm and tag from owner, group and mode bits. */ -static void GetOGMFromStat(struct stat *status, int *parm, int *tag) +static void +GetOGMFromStat(struct afs_stat *status, int *parm, int *tag) { *parm = status->st_uid | (status->st_gid << 15); *parm |= (status->st_mode & 0x18) << 27; *tag = status->st_mode & 0x7; } -static int GetOGM(int fd, int *parm, int *tag) +static int +GetOGM(int fd, int *parm, int *tag) { - struct stat status; - if (fstat(fd, &status)<0) + struct afs_stat status; + if (afs_fstat(fd, &status) < 0) return -1; GetOGMFromStat(&status, parm, tag); return 0; } -int big_vno = 0; /* Just in case we ever do 64 bit vnodes. */ +int big_vno = 0; /* Just in case we ever do 64 bit vnodes. */ /* Derive the name and create it O_EXCL. If that fails we have an error. * Get the tag from a free column in the link table. */ -Inode namei_icreate(IHandle_t *lh, char *part, int p1, int p2, int p3, int p4) +Inode +namei_icreate(IHandle_t * lh, char *part, int p1, int p2, int p3, int p4) { namei_t name; int fd = -1; @@ -457,9 +498,9 @@ Inode namei_icreate(IHandle_t *lh, char *part, int p1, int p2, int p3, int p4) FdHandle_t tfd; int tag; int ogm_parm; - - memset((void*)&tmp, 0, sizeof(IHandle_t)); + + memset((void *)&tmp, 0, sizeof(IHandle_t)); tmp.ih_dev = volutil_GetPartitionID(part); @@ -468,7 +509,7 @@ Inode namei_icreate(IHandle_t *lh, char *part, int p1, int p2, int p3, int p4) return -1; } - if (p2 == -1 ) { + if (p2 == -1) { /* Parameters for special file: * p1 - volume id - goes into owner/group/mode * p2 - vnode == -1 @@ -478,11 +519,10 @@ Inode namei_icreate(IHandle_t *lh, char *part, int p1, int p2, int p3, int p4) ogm_parm = p1; tag = p3; - tmp.ih_vid = p4; /* Use parent volume id, where this file will be.*/ + tmp.ih_vid = p4; /* Use parent volume id, where this file will be. */ tmp.ih_ino = namei_MakeSpecIno(p1, p3); - } - else { - int vno = p2 & NAMEI_VNODEMASK; + } else { + int vno = p2 & NAMEI_VNODEMASK; /* Parameters for regular file: * p1 - volume id * p2 - vnode @@ -491,7 +531,7 @@ Inode namei_icreate(IHandle_t *lh, char *part, int p1, int p2, int p3, int p4) */ if (vno != p2) { - big_vno ++; + big_vno++; errno = EINVAL; return -1; } @@ -502,28 +542,28 @@ Inode namei_icreate(IHandle_t *lh, char *part, int p1, int p2, int p3, int p4) /* name is */ tmp.ih_vid = p1; - tmp.ih_ino = (Inode)p2; - tmp.ih_ino |= ((Inode)tag)<= 0) close(fd); @@ -549,19 +589,20 @@ bad: } } } - return (code || (fd<0)) ? (Inode)-1 : tmp.ih_ino; + return (code || (fd < 0)) ? (Inode) - 1 : tmp.ih_ino; } /* namei_iopen */ -int namei_iopen(IHandle_t *h) +int +namei_iopen(IHandle_t * h) { int fd; namei_t name; /* Convert handle to file name. */ namei_HandleToName(&name, h); - fd = open(name.n_path, O_RDWR, 0666); + fd = afs_open(name.n_path, O_RDWR, 0666); return fd; } @@ -569,7 +610,8 @@ int namei_iopen(IHandle_t *h) * handle passed in _is_ for the inode. We only check p1 for the special * files. */ -int namei_dec(IHandle_t *ih, Inode ino, int p1) +int +namei_dec(IHandle_t * ih, Inode ino, int p1) { int count = 0; namei_t name; @@ -579,7 +621,7 @@ int namei_dec(IHandle_t *ih, Inode ino, int p1) if ((ino & NAMEI_INODESPECIAL) == NAMEI_INODESPECIAL) { IHandle_t *tmp; int inode_p1, tag; - int type = (int)((ino>>NAMEI_TAGSHIFT) & NAMEI_TAGMASK); + int type = (int)((ino >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK); /* Verify this is the right file. */ IH_INIT(tmp, ih->ih_dev, ih->ih_vid, ino); @@ -591,70 +633,77 @@ int namei_dec(IHandle_t *ih, Inode ino, int p1) return -1; } - if ((GetOGM(fdP->fd_fd, &inode_p1, &tag)<0) || (inode_p1 != p1)) { + if ((GetOGM(fdP->fd_fd, &inode_p1, &tag) < 0) || (inode_p1 != p1)) { FDH_REALLYCLOSE(fdP); IH_RELEASE(tmp); errno = EINVAL; return -1; } - + /* If it's the link table itself, decrement the link count. */ if (type == VI_LINKTABLE) { - if ((count = namei_GetLinkCount(fdP, (Inode)0, 1))<0) { + if ((count = namei_GetLinkCount(fdP, (Inode) 0, 1)) < 0) { FDH_REALLYCLOSE(fdP); IH_RELEASE(tmp); return -1; } - count --; - if (namei_SetLinkCount(fdP, (Inode)0, count<0 ? 0 : count, 1)<0) { + count--; + if (namei_SetLinkCount(fdP, (Inode) 0, count < 0 ? 0 : count, 1) < + 0) { FDH_REALLYCLOSE(fdP); IH_RELEASE(tmp); return -1; } - if (count>0) { + if (count > 0) { FDH_REALLYCLOSE(fdP); IH_RELEASE(tmp); return 0; } } - + namei_HandleToName(&name, tmp); if ((code = unlink(name.n_path)) == 0) { if (type == VI_LINKTABLE) { /* Try to remove directory. If it fails, that's ok. * Salvage will clean up. */ - (void) namei_RemoveDataDirectories(&name); + (void)namei_RemoveDataDirectories(&name); } } FDH_REALLYCLOSE(fdP); IH_RELEASE(tmp); - } - else { + } else { /* Get a file descriptor handle for this Inode */ fdP = IH_OPEN(ih); if (fdP == NULL) { return -1; } - if ((count = namei_GetLinkCount(fdP, ino, 1))<0) { + if ((count = namei_GetLinkCount(fdP, ino, 1)) < 0) { FDH_REALLYCLOSE(fdP); return -1; } - count --; + count--; if (count >= 0) { - if (namei_SetLinkCount(fdP, ino, count, 1)<0) { + if (namei_SetLinkCount(fdP, ino, count, 1) < 0) { FDH_REALLYCLOSE(fdP); return -1; } } - if (count == 0 ) { - IHandle_t th = *ih; - th.ih_ino = ino; - namei_HandleToName(&name, &th); + if (count == 0) { + IHandle_t *th; + IH_INIT(th, ih->ih_dev, ih->ih_vid, ino); +#if 0 + /* This triggers in the fileserver on the volume index vnodes */ + if (th->ih_refcnt > 1) + Log("Warning: Leaked ref on ihandle dev %d vid %d ino %lld\n", + th->ih_dev, th->ih_vid, (int64_t) th->ih_ino); +#endif + namei_HandleToName(&name, th); + IH_RELEASE(th); code = unlink(name.n_path); } FDH_CLOSE(fdP); @@ -663,17 +712,18 @@ int namei_dec(IHandle_t *ih, Inode ino, int p1) return code; } -int namei_inc(IHandle_t *h, Inode ino, int p1) +int +namei_inc(IHandle_t * h, Inode ino, int p1) { int count; int code = 0; FdHandle_t *fdP; if ((ino & NAMEI_INODESPECIAL) == NAMEI_INODESPECIAL) { - int type = (int)((ino>>NAMEI_TAGSHIFT) & NAMEI_TAGMASK); + int type = (int)((ino >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK); if (type != VI_LINKTABLE) return 0; - ino = (Inode)0; + ino = (Inode) 0; } /* Get a file descriptor handle for this Inode */ @@ -682,16 +732,16 @@ int namei_inc(IHandle_t *h, Inode ino, int p1) return -1; } - if ((count = namei_GetLinkCount(fdP, ino, 1))<0) + if ((count = namei_GetLinkCount(fdP, ino, 1)) < 0) code = -1; else { - count ++; + count++; if (count > 7) { errno = EINVAL; code = -1; count = 7; } - if (namei_SetLinkCount(fdP, ino, count, 1)<0) + if (namei_SetLinkCount(fdP, ino, count, 1) < 0) code = -1; } if (code) { @@ -782,14 +832,15 @@ int namei_inc(IHandle_t *h, Inode ino, int p1) * short. */ #define LINKTABLE_WIDTH 2 -#define LINKTABLE_SHIFT 1 /* log 2 = 1 */ +#define LINKTABLE_SHIFT 1 /* log 2 = 1 */ -static void namei_GetLCOffsetAndIndexFromIno(Inode ino, int *offset, int *index) +static void +namei_GetLCOffsetAndIndexFromIno(Inode ino, afs_foff_t * offset, int *index) { - int toff = (int) (ino & NAMEI_VNODEMASK); - int tindex = (int)((ino>>NAMEI_TAGSHIFT) & NAMEI_TAGMASK); + int toff = (int)(ino & NAMEI_VNODEMASK); + int tindex = (int)((ino >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK); - *offset = (toff << LINKTABLE_SHIFT) + 8; /* * 2 + sizeof stamp */ + *offset = (afs_foff_t) ((toff << LINKTABLE_SHIFT) + 8); /* * 2 + sizeof stamp */ *index = (tindex << 1) + tindex; } @@ -798,32 +849,34 @@ static void namei_GetLCOffsetAndIndexFromIno(Inode ino, int *offset, int *index) * If lockit is set, lock the file and leave it locked upon a successful * return. */ -int namei_GetLinkCount(FdHandle_t *h, Inode ino, int lockit) +int +namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit) { unsigned short row = 0; - int offset, index; + afs_foff_t offset; + int index; namei_GetLCOffsetAndIndexFromIno(ino, &offset, &index); if (lockit) { #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) - if (lockf(h->fd_fd, F_LOCK, 0) < 0) + if (lockf(h->fd_fd, F_LOCK, 0) < 0) #else - if (flock(h->fd_fd, LOCK_EX)<0) + if (flock(h->fd_fd, LOCK_EX) < 0) #endif return -1; } - if (lseek(h->fd_fd, offset, SEEK_SET) == -1) + if (afs_lseek(h->fd_fd, offset, SEEK_SET) == -1) goto bad_getLinkByte; - - if (read(h->fd_fd, (char*)&row, sizeof(row))!=sizeof(row)) { + + if (read(h->fd_fd, (char *)&row, sizeof(row)) != sizeof(row)) { goto bad_getLinkByte; } - - return (int) ((row >> index) & NAMEI_TAGMASK); - bad_getLinkByte: + return (int)((row >> index) & NAMEI_TAGMASK); + + bad_getLinkByte: if (lockit) #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) lockf(h->fd_fd, F_ULOCK, 0); @@ -834,10 +887,11 @@ int namei_GetLinkCount(FdHandle_t *h, Inode ino, int lockit) } /* Return a free column index for this vnode. */ -static int GetFreeTag(IHandle_t *ih, int vno) +static int +GetFreeTag(IHandle_t * ih, int vno) { FdHandle_t *fdP; - int offset; + afs_foff_t offset; int col; int coldata; short row; @@ -852,29 +906,29 @@ static int GetFreeTag(IHandle_t *ih, int vno) #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) if (lockf(fdP->fd_fd, F_LOCK, 0) < 0) { #else - if (flock(fdP->fd_fd, LOCK_EX)<0) { + if (flock(fdP->fd_fd, LOCK_EX) < 0) { #endif FDH_REALLYCLOSE(fdP); return -1; } - - offset = (vno << LINKTABLE_SHIFT) + 8; /* * 2 + sizeof stamp */ - if (lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { + + offset = (vno << LINKTABLE_SHIFT) + 8; /* * 2 + sizeof stamp */ + if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { goto badGetFreeTag; } - - code = read(fdP->fd_fd, (char*)&row, sizeof(row)); + + code = read(fdP->fd_fd, (char *)&row, sizeof(row)); if (code != sizeof(row)) { if (code != 0) goto badGetFreeTag; row = 0; } - + /* Now find a free column in this row and claim it. */ - for (col = 0; col= NAMEI_MAXVOLS) goto badGetFreeTag; @@ -882,10 +936,10 @@ static int GetFreeTag(IHandle_t *ih, int vno) coldata = 1 << (col * 3); row |= coldata; - if (lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { + if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { goto badGetFreeTag; } - if (write(fdP->fd_fd, (char*)&row, sizeof(row))!=sizeof(row)) { + if (write(fdP->fd_fd, (char *)&row, sizeof(row)) != sizeof(row)) { goto badGetFreeTag; } FDH_SYNC(fdP); @@ -897,7 +951,7 @@ static int GetFreeTag(IHandle_t *ih, int vno) FDH_REALLYCLOSE(fdP); return col;; - badGetFreeTag: + badGetFreeTag: #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) lockf(fdP->fd_fd, F_ULOCK, 0); #else @@ -913,9 +967,11 @@ static int GetFreeTag(IHandle_t *ih, int vno) * If locked is set, assume file is locked. Otherwise, lock file before * proceeding to modify it. */ -int namei_SetLinkCount(FdHandle_t *fdP, Inode ino, int count, int locked) +int +namei_SetLinkCount(FdHandle_t * fdP, Inode ino, int count, int locked) { - int offset, index; + afs_foff_t offset; + int index; unsigned short row; int junk; int code = -1; @@ -924,20 +980,20 @@ int namei_SetLinkCount(FdHandle_t *fdP, Inode ino, int count, int locked) if (!locked) { #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) - if (lockf(fdP->fd_fd, F_LOCK, 0) < 0) { + if (lockf(fdP->fd_fd, F_LOCK, 0) < 0) { #else - if (flock(fdP->fd_fd, LOCK_EX)<0) { + if (flock(fdP->fd_fd, LOCK_EX) < 0) { #endif return -1; } } - if (lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { + if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { errno = EBADF; goto bad_SetLinkCount; } - - code = read(fdP->fd_fd, (char*)&row, sizeof(row)); + + code = read(fdP->fd_fd, (char *)&row, sizeof(row)); if (code != sizeof(row)) { if (code != 0) { errno = EBADF; @@ -945,18 +1001,18 @@ int namei_SetLinkCount(FdHandle_t *fdP, Inode ino, int count, int locked) } row = 0; } - + junk = 7 << index; count <<= index; row &= (unsigned short)~junk; row |= (unsigned short)count; - if (lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { - errno = EBADF; + if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { + errno = EBADF; goto bad_SetLinkCount; } - if (write(fdP->fd_fd, (char*)&row, sizeof(short)) != sizeof(short)) { + if (write(fdP->fd_fd, (char *)&row, sizeof(short)) != sizeof(short)) { errno = EBADF; goto bad_SetLinkCount; } @@ -964,8 +1020,8 @@ int namei_SetLinkCount(FdHandle_t *fdP, Inode ino, int count, int locked) code = 0; - -bad_SetLinkCount: + + bad_SetLinkCount: #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) lockf(fdP->fd_fd, F_ULOCK, 0); #else @@ -980,12 +1036,13 @@ bad_SetLinkCount: static int DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, int volid); static int DecodeVolumeName(char *name, int *vid); -static int namei_ListAFSSubDirs(IHandle_t *dirIH, - int (*write_fun)(FILE *, struct ViceInodeInfo *, - char *, char *), - FILE *fp, - int (*judgeFun)(struct ViceInodeInfo *, int vid), - int singleVolumeNumber); +static int namei_ListAFSSubDirs(IHandle_t * dirIH, + int (*write_fun) (FILE *, + struct ViceInodeInfo *, + char *, char *), FILE * fp, + int (*judgeFun) (struct ViceInodeInfo *, + int vid), + int singleVolumeNumber); /* WriteInodeInfo @@ -997,8 +1054,8 @@ static int namei_ListAFSSubDirs(IHandle_t *dirIH, * This is written as a callback simply so that other listing routines * can use the same inode reading code. */ -static int WriteInodeInfo(FILE *fp, struct ViceInodeInfo *info, char *dir, - char *name) +static int +WriteInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name) { int n; n = fwrite(info, sizeof(*info), 1, fp); @@ -1006,18 +1063,18 @@ static int WriteInodeInfo(FILE *fp, struct ViceInodeInfo *info, char *dir, } -int mode_errors; /* Number of errors found in mode bits on directories. */ -void VerifyDirPerms(char *path) +int mode_errors; /* Number of errors found in mode bits on directories. */ +void +VerifyDirPerms(char *path) { - struct stat status; + struct afs_stat status; - if (stat(path, &status)<0) { + if (afs_stat(path, &status) < 0) { Log("Unable to stat %s. Please manually verify mode bits for this" " directory\n", path); - } - else { + } else { if (((status.st_mode & 0777) != 0700) || (status.st_uid != 0)) - mode_errors ++; + mode_errors++; } } @@ -1034,17 +1091,17 @@ void VerifyDirPerms(char *path) * * If the resultFile is NULL, then don't call the write routine. */ -int ListViceInodes(char *devname, char *mountedOn, char *resultFile, - int (*judgeInode)(struct ViceInodeInfo *info, int vid), - int singleVolumeNumber, int *forcep, - int forceR, char *wpath) +int +ListViceInodes(char *devname, char *mountedOn, char *resultFile, + int (*judgeInode) (struct ViceInodeInfo * info, int vid), + int singleVolumeNumber, int *forcep, int forceR, char *wpath) { - FILE *fp = (FILE*)-1; + FILE *fp = (FILE *) - 1; int ninodes; - struct stat status; + struct afs_stat status; if (resultFile) { - fp = fopen(resultFile, "w"); + fp = afs_fopen(resultFile, "w"); if (!fp) { Log("Unable to create inode description file %s\n", resultFile); return -1; @@ -1055,8 +1112,9 @@ int ListViceInodes(char *devname, char *mountedOn, char *resultFile, mode_errors = 0; VerifyDirPerms(mountedOn); - ninodes = namei_ListAFSFiles(mountedOn, WriteInodeInfo, fp, - judgeInode, singleVolumeNumber); + ninodes = + namei_ListAFSFiles(mountedOn, WriteInodeInfo, fp, judgeInode, + singleVolumeNumber); if (!resultFile) return ninodes; @@ -1084,13 +1142,13 @@ int ListViceInodes(char *devname, char *mountedOn, char *resultFile, /* * Paranoia: check that the file is really the right size */ - if (stat(resultFile, &status) == -1) { + if (afs_stat(resultFile, &status) == -1) { Log("Unable to successfully stat inode file for %s\n", mountedOn); return -2; } - if (status.st_size != ninodes * sizeof (struct ViceInodeInfo)) { - Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof (struct ViceInodeInfo), + if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + Log("Wrong size (%d instead of %d) in inode file for %s\n", + status.st_size, ninodes * sizeof(struct ViceInodeInfo), mountedOn); return -2; } @@ -1105,12 +1163,12 @@ int ListViceInodes(char *devname, char *mountedOn, char *resultFile, * * Returns <0 on error, else number of files found to match. */ -int namei_ListAFSFiles(char *dev, - int (*writeFun)(FILE *, struct ViceInodeInfo *, char *, - char *), - FILE *fp, - int (*judgeFun)(struct ViceInodeInfo *, int), - int singleVolumeNumber) +int +namei_ListAFSFiles(char *dev, + int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, + char *), FILE * fp, + int (*judgeFun) (struct ViceInodeInfo *, int), + int singleVolumeNumber) { IHandle_t ih; namei_t name; @@ -1122,18 +1180,18 @@ int namei_ListAFSFiles(char *dev, static void FreeZLCList(void); #endif - memset((void*)&ih, 0, sizeof(IHandle_t)); + memset((void *)&ih, 0, sizeof(IHandle_t)); ih.ih_dev = volutil_GetPartitionID(dev); if (singleVolumeNumber) { ih.ih_vid = singleVolumeNumber; namei_HandleToVolDir(&name, &ih); - ninodes = namei_ListAFSSubDirs(&ih, writeFun, fp, - judgeFun, singleVolumeNumber); + ninodes = + namei_ListAFSSubDirs(&ih, writeFun, fp, judgeFun, + singleVolumeNumber); if (ninodes < 0) return ninodes; - } - else { + } else { /* Find all volume data directories and descend through them. */ namei_HandleToInodeDir(&name, &ih); ninodes = 0; @@ -1141,17 +1199,20 @@ int namei_ListAFSFiles(char *dev, if (!dirp1) return 0; while ((dp1 = readdir(dirp1))) { - if (*dp1->d_name == '.') continue; - (void) strcpy(path2, name.n_path); - (void) strcat(path2, "/"); - (void) strcat(path2, dp1->d_name); + if (*dp1->d_name == '.') + continue; + (void)strcpy(path2, name.n_path); + (void)strcat(path2, "/"); + (void)strcat(path2, dp1->d_name); dirp2 = opendir(path2); if (dirp2) { while ((dp2 = readdir(dirp2))) { - if (*dp2->d_name == '.') continue; + if (*dp2->d_name == '.') + continue; if (!DecodeVolumeName(dp2->d_name, &ih.ih_vid)) { - ninodes += namei_ListAFSSubDirs(&ih, writeFun, fp, - judgeFun, 0); + ninodes += + namei_ListAFSSubDirs(&ih, writeFun, fp, judgeFun, + 0); } } closedir(dirp2); @@ -1174,12 +1235,12 @@ int namei_ListAFSFiles(char *dev, * < 0 - an error * > = 0 - number of AFS files found. */ -static int namei_ListAFSSubDirs(IHandle_t *dirIH, - int (*writeFun)(FILE *, struct ViceInodeInfo *, - char *, char *), - FILE *fp, - int (*judgeFun)(struct ViceInodeInfo *, int), - int singleVolumeNumber) +static int +namei_ListAFSSubDirs(IHandle_t * dirIH, + int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, + char *), FILE * fp, + int (*judgeFun) (struct ViceInodeInfo *, int), + int singleVolumeNumber) { IHandle_t myIH = *dirIH; namei_t name; @@ -1196,100 +1257,106 @@ static int namei_ListAFSSubDirs(IHandle_t *dirIH, #endif namei_HandleToVolDir(&name, &myIH); - (void) strcpy(path1, name.n_path); + (void)strcpy(path1, name.n_path); /* Do the directory containing the special files first to pick up link * counts. */ - (void) strcat(path1, "/"); - (void) strcat(path1, NAMEI_SPECDIR); + (void)strcat(path1, "/"); + (void)strcat(path1, NAMEI_SPECDIR); linkHandle.fd_fd = -1; dirp1 = opendir(path1); if (dirp1) { while ((dp1 = readdir(dirp1))) { - if (*dp1->d_name == '.') continue; - if (DecodeInode(path1, dp1->d_name, &info, myIH.ih_vid)<0) + if (*dp1->d_name == '.') + continue; + if (DecodeInode(path1, dp1->d_name, &info, myIH.ih_vid) < 0) continue; if (info.u.param[2] != VI_LINKTABLE) { info.linkCount = 1; - } - else { + } else { /* Open this handle */ - (void) sprintf(path2, "%s/%s", path1, dp1->d_name); - linkHandle.fd_fd = open(path2, O_RDONLY, 0666); - info.linkCount = namei_GetLinkCount(&linkHandle, (Inode)0, 0); + (void)afs_snprintf(path2, sizeof path2, "%s/%s", path1, + dp1->d_name); + linkHandle.fd_fd = afs_open(path2, O_RDONLY, 0666); + info.linkCount = + namei_GetLinkCount(&linkHandle, (Inode) 0, 0); } - if (judgeFun && !(*judgeFun)(&info, singleVolumeNumber)) + if (judgeFun && !(*judgeFun) (&info, singleVolumeNumber)) continue; - if ((*writeFun)(fp, &info, path1, dp1->d_name)<0) { + if ((*writeFun) (fp, &info, path1, dp1->d_name) < 0) { if (linkHandle.fd_fd >= 0) close(linkHandle.fd_fd); closedir(dirp1); return -1; } - ninodes ++; + ninodes++; } closedir(dirp1); } /* Now run through all the other subdirs */ namei_HandleToVolDir(&name, &myIH); - (void) strcpy(path1, name.n_path); - + (void)strcpy(path1, name.n_path); + dirp1 = opendir(path1); if (dirp1) { while ((dp1 = readdir(dirp1))) { - if (*dp1->d_name == '.') continue; + if (*dp1->d_name == '.') + continue; if (!strcmp(dp1->d_name, NAMEI_SPECDIR)) continue; - + /* Now we've got a next level subdir. */ - (void) strcpy(path2, path1); - (void) strcat(path2, "/"); - (void) strcat(path2, dp1->d_name); + (void)strcpy(path2, path1); + (void)strcat(path2, "/"); + (void)strcat(path2, dp1->d_name); dirp2 = opendir(path2); if (dirp2) { while ((dp2 = readdir(dirp2))) { - if (*dp2->d_name == '.') continue; - + if (*dp2->d_name == '.') + continue; + /* Now we've got to the actual data */ - (void) strcpy(path3, path2); - (void) strcat(path3, "/"); - (void) strcat(path3, dp2->d_name); + (void)strcpy(path3, path2); + (void)strcat(path3, "/"); + (void)strcat(path3, dp2->d_name); dirp3 = opendir(path3); if (dirp3) { while ((dp3 = readdir(dirp3))) { - if (*dp3->d_name == '.') continue; - if (DecodeInode(path3, dp3->d_name, &info, - myIH.ih_vid)<0) + if (*dp3->d_name == '.') + continue; + if (DecodeInode + (path3, dp3->d_name, &info, myIH.ih_vid) < 0) continue; - info.linkCount = namei_GetLinkCount(&linkHandle, - info.inodeNumber, 0); + info.linkCount = + namei_GetLinkCount(&linkHandle, + info.inodeNumber, 0); if (info.linkCount == 0) { #ifdef DELETE_ZLC - Log("Found 0 link count file %s/%s, deleting it.\n", - path3, dp3->d_name); + Log("Found 0 link count file %s/%s, deleting it.\n", path3, dp3->d_name); AddToZLCDeleteList((char)i, dp3->d_name); #else - Log("Found 0 link count file %s/%s.\n", - path3, dp3->d_name); + Log("Found 0 link count file %s/%s.\n", path3, + dp3->d_name); #endif continue; } if (judgeFun - && !(*judgeFun)(&info, singleVolumeNumber)) + && !(*judgeFun) (&info, singleVolumeNumber)) continue; - if ((*writeFun)(fp, &info, path3, dp3->d_name)<0) { + if ((*writeFun) (fp, &info, path3, dp3->d_name) < + 0) { close(linkHandle.fd_fd); closedir(dirp3); closedir(dirp2); closedir(dirp1); return -1; } - ninodes ++; + ninodes++; } closedir(dirp3); } @@ -1311,11 +1378,12 @@ static int namei_ListAFSSubDirs(IHandle_t *dirIH, return ninodes; } -static int DecodeVolumeName(char *name, int *vid) +static int +DecodeVolumeName(char *name, int *vid) { if (strlen(name) <= 2) return -1; - *vid = (int) flipbase64_to_int64(name); + *vid = (int)flipbase64_to_int64(name); return 0; } @@ -1325,24 +1393,24 @@ static int DecodeVolumeName(char *name, int *vid) * Get the inode number from the name. * Get */ -static int DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, - int volid) +static int +DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, int volid) { char fpath[512]; - struct stat status; + struct afs_stat status; int parm, tag; - (void) strcpy(fpath, dpath); - (void) strcat(fpath, "/"); - (void) strcat(fpath, name); + (void)strcpy(fpath, dpath); + (void)strcat(fpath, "/"); + (void)strcat(fpath, name); - if (stat(fpath, &status)<0) { + if (afs_stat(fpath, &status) < 0) { return -1; } info->byteCount = status.st_size; - info->inodeNumber = flipbase64_to_int64(name); - + info->inodeNumber = (Inode) flipbase64_to_int64(name); + GetOGMFromStat(&status, &parm, &tag); if ((info->inodeNumber & NAMEI_INODESPECIAL) == NAMEI_INODESPECIAL) { /* p1 - vid, p2 - -1, p3 - type, p4 - rwvid */ @@ -1350,32 +1418,233 @@ static int DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, info->u.param[1] = -1; info->u.param[2] = tag; info->u.param[3] = volid; - } - else { + } else { /* p1 - vid, p2 - vno, p3 - uniq, p4 - dv */ info->u.param[0] = volid; info->u.param[1] = (int)(info->inodeNumber & NAMEI_VNODEMASK); info->u.param[2] = (int)((info->inodeNumber >> NAMEI_UNIQSHIFT) - & (Inode)NAMEI_UNIQMASK); + & (Inode) NAMEI_UNIQMASK); info->u.param[3] = parm; } return 0; } +/* + * Convert the VolumeInfo file from RO to RW + * this routine is called by namei_convertROtoRWvolume() + */ + +static afs_int32 +convertVolumeInfo(fdr, fdw, vid) + int fdr; + int fdw; + afs_uint32 vid; +{ + struct VolumeDiskData vd; + char *p; + + if (read(fdr, &vd, sizeof(struct VolumeDiskData)) != + sizeof(struct VolumeDiskData)) { + Log("1 convertVolumeInfo: read failed for %lu with code %d\n", vid, + errno); + return -1; + } + vd.restoredFromId = vd.id; /* remember the RO volume here */ + vd.cloneId = vd.id; + vd.id = vd.parentId; + vd.type = RWVOL; + vd.dontSalvage = 0; + vd.uniquifier += 5000; /* just in case there are still file copies from + * the old RW volume around */ + p = strrchr(vd.name, '.'); + if (p && !strcmp(p, ".readonly")) { + bzero(p, 8); + } + if (write(fdw, &vd, sizeof(struct VolumeDiskData)) != + sizeof(struct VolumeDiskData)) { + Log("1 convertVolumeInfo: write failed for %lu with code %d\n", vid, + errno); + return -1; + } + return 0; +} + +/* + * Convert a RO-volume into a RW-volume + * + * This function allows to recover very fast from the loss of a partition + * from RO-copies if all RO-Copies exist on another partition. + * Then these RO-volumes can be made to the new RW-volumes. + * Backup of RW-volumes then consists in "vos release". + * + * We must make sure in this partition exists only the RO-volume which + * is typical for remote replicas. + * + * Then the linktable is already ok, + * the vnode files need to be renamed + * the volinfo file needs to be replaced by another one with + * slightly different contents and new name. + * The volume header file of the RO-volume in the /vicep directory + * is destroyed by this call. A new header file for the RW-volume must + * be created after return from this routine. + */ + +int +namei_ConvertROtoRWvolume(IHandle_t * h, afs_uint32 vid) +{ + namei_t n; + char dir_name[512], oldpath[512], newpath[512]; + char smallName[64]; + char largeName[64]; + char infoName[64]; + IHandle_t t_ih; + char infoSeen = 0; + char smallSeen = 0; + char largeSeen = 0; + char linkSeen = 0; + int code, fd, fd2; + char *p; + DIR *dirp; + struct dirent *dp; + struct ViceInodeInfo info; + + namei_HandleToName(&n, h); + strcpy(dir_name, n.n_path); + p = strrchr(dir_name, '/'); + *p = 0; + dirp = opendir(dir_name); + if (!dirp) { + Log("1 namei_ConvertROtoRWvolume: Could not opendir(%s)\n", dir_name); + return EIO; + } + + while ((dp = readdir(dirp))) { + /* struct ViceInodeInfo info; */ + + if (*dp->d_name == '.') + continue; + if (DecodeInode(dir_name, dp->d_name, &info, h->ih_vid) < 0) { + Log("1 namei_ConvertROtoRWvolume: DecodeInode failed for %s/%s\n", + dir_name, dp->d_name); + closedir(dirp); + return -1; + } + if (info.u.param[1] != -1) { + Log("1 namei_ConvertROtoRWvolume: found other than volume special file %s/%s\n", dir_name, dp->d_name); + closedir(dirp); + return -1; + } + if (info.u.param[0] != vid) { + if (info.u.param[0] == h->ih_vid) { + if (info.u.param[2] == VI_LINKTABLE) { /* link table */ + linkSeen = 1; + continue; + } + } + Log("1 namei_ConvertROtoRWvolume: found special file %s/%s for volume %lu\n", dir_name, dp->d_name, info.u.param[0]); + closedir(dirp); + return VVOLEXISTS; + } + if (info.u.param[2] == VI_VOLINFO) { /* volume info file */ + strcpy(infoName, dp->d_name); + infoSeen = 1; + } else if (info.u.param[2] == VI_SMALLINDEX) { /* small vnodes file */ + strcpy(smallName, dp->d_name); + smallSeen = 1; + } else if (info.u.param[2] == VI_LARGEINDEX) { /* large vnodes file */ + strcpy(largeName, dp->d_name); + largeSeen = 1; + } else { + closedir(dirp); + Log("1 namei_ConvertROtoRWvolume: unknown type %d of special file found : %s/%s\n", info.u.param[2], dir_name, dp->d_name); + return -1; + } + } + closedir(dirp); + + if (!infoSeen || !smallSeen || !largeSeen || !linkSeen) { + Log("1 namei_ConvertROtoRWvolume: not all special files found in %s\n", dir_name); + return -1; + } + + /* + * If we come here then there was only a RO-volume and we can safely + * proceed. + */ + + bzero(&t_ih, sizeof(t_ih)); + t_ih.ih_dev = h->ih_dev; + t_ih.ih_vid = h->ih_vid; + + (void)afs_snprintf(oldpath, sizeof oldpath, "%s/%s", dir_name, infoName); + fd = afs_open(oldpath, O_RDWR, 0); + if (fd < 0) { + Log("1 namei_ConvertROtoRWvolume: could not open RO info file: %s\n", + oldpath); + return -1; + } + t_ih.ih_ino = namei_MakeSpecIno(h->ih_vid, VI_VOLINFO); + namei_HandleToName(&n, &t_ih); + fd2 = afs_open(n.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0); + if (fd2 < 0) { + Log("1 namei_ConvertROtoRWvolume: could not create RW info file: %s\n", n.n_path); + close(fd); + return -1; + } + code = convertVolumeInfo(fd, fd2, h->ih_vid); + close(fd); + if (code) { + close(fd2); + unlink(n.n_path); + return -1; + } + SetOGM(fd2, h->ih_vid, 1); + close(fd2); + + t_ih.ih_ino = namei_MakeSpecIno(h->ih_vid, VI_SMALLINDEX); + namei_HandleToName(&n, &t_ih); + (void)afs_snprintf(newpath, sizeof newpath, "%s/%s", dir_name, smallName); + fd = afs_open(newpath, O_RDWR, 0); + if (fd < 0) { + Log("1 namei_ConvertROtoRWvolume: could not open SmallIndex file: %s\n", newpath); + return -1; + } + SetOGM(fd, h->ih_vid, 2); + close(fd); + link(newpath, n.n_path); + unlink(newpath); + + t_ih.ih_ino = namei_MakeSpecIno(h->ih_vid, VI_LARGEINDEX); + namei_HandleToName(&n, &t_ih); + (void)afs_snprintf(newpath, sizeof newpath, "%s/%s", dir_name, largeName); + fd = afs_open(newpath, O_RDWR, 0); + if (fd < 0) { + Log("1 namei_ConvertROtoRWvolume: could not open LargeIndex file: %s\n", newpath); + return -1; + } + SetOGM(fd, h->ih_vid, 3); + close(fd); + link(newpath, n.n_path); + unlink(newpath); + + unlink(oldpath); + return 0; +} /* PrintInode * * returns a static string used to print either 32 or 64 bit inode numbers. */ -char * PrintInode(char *s, Inode ino) +char * +PrintInode(char *s, Inode ino) { - static afs_ino_str_t result; + static afs_ino_str_t result; if (!s) s = result; - (void) sprintf((char*)s, "%Lu", ino); + (void)afs_snprintf(s, sizeof(afs_ino_str_t), "%llu", (afs_uintmax_t) ino); - return (char*)s; + return s; } @@ -1392,7 +1661,8 @@ typedef struct zlcList_s { static zlcList_t *zlcAnchor = NULL; static zlcList_t *zlcCur = NULL; -static void AddToZLCDeleteList(char dir, char *name) +static void +AddToZLCDeleteList(char dir, char *name) { assert(strlen(name) <= MAX_ZLC_NAMELEN - 3); @@ -1400,13 +1670,12 @@ static void AddToZLCDeleteList(char dir, char *name) if (zlcCur && zlcCur->zlc_next) zlcCur = zlcCur->zlc_next; else { - zlcList_t *tmp = (zlcList_t*)malloc(sizeof(zlcList_t)); + zlcList_t *tmp = (zlcList_t *) malloc(sizeof(zlcList_t)); if (!tmp) return; if (!zlcAnchor) { zlcAnchor = tmp; - } - else { + } else { zlcCur->zlc_next = tmp; } zlcCur = tmp; @@ -1415,30 +1684,32 @@ static void AddToZLCDeleteList(char dir, char *name) } } - (void) sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%c\\%s", dir, name); - zlcCur->zlc_n ++; + (void)sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%c\\%s", dir, name); + zlcCur->zlc_n++; } -static void DeleteZLCFiles(char *path) +static void +DeleteZLCFiles(char *path) { zlcList_t *z; int i; char fname[1024]; for (z = zlcAnchor; z; z = z->zlc_next) { - for (i=0; i < z->zlc_n; i++) { - (void) sprintf(fname, "%s\\%s", path, z->zlc_names[i]); - if (namei_unlink(fname)<0) { + for (i = 0; i < z->zlc_n; i++) { + (void)sprintf(fname, "%s\\%s", path, z->zlc_names[i]); + if (namei_unlink(fname) < 0) { Log("ZLC: Can't unlink %s, dos error = %d\n", fname, - GetLastError()); + GetLastError()); } } - z->zlc_n = 0; /* Can reuse space. */ + z->zlc_n = 0; /* Can reuse space. */ } zlcCur = zlcAnchor; } -static void FreeZLCList(void) +static void +FreeZLCList(void) { zlcList_t *tnext; zlcList_t *i; @@ -1454,4 +1725,3 @@ static void FreeZLCList(void) #endif #endif /* AFS_NAMEI_ENV */ - diff --git a/src/vol/namei_ops.h b/src/vol/namei_ops.h index df55e01e7..64a476655 100644 --- a/src/vol/namei_ops.h +++ b/src/vol/namei_ops.h @@ -26,32 +26,35 @@ char *PrintInode(char *s, Inode ino); #endif /* Basic file operations */ -extern FILE *namei_fdopen(IHandle_t *h, char *fdperms); +extern FILE *namei_fdopen(IHandle_t * h, char *fdperms); extern int namei_unlink(char *name); /* Inode operations */ extern Inode namei_MakeSpecIno(int volid, int type); -extern Inode namei_icreate(IHandle_t *h, char *p, int p1, int p2, int p3, int p4); -extern FD_t namei_iopen(IHandle_t *h); -extern int namei_irelease(IHandle_t *h); -int namei_iread(IHandle_t *h, int offset, char *buf, int size); -int namei_iwrite(IHandle_t *h, int offset, char *buf, int size); -extern int namei_dec(IHandle_t *h, Inode ino, int p1); -extern int namei_inc(IHandle_t *h, Inode ino, int p1); -extern int namei_GetLinkCount(FdHandle_t *h, Inode ino, int lockit); +extern Inode namei_icreate(IHandle_t * h, char *p, int p1, int p2, int p3, + int p4); +extern FD_t namei_iopen(IHandle_t * h); +extern int namei_irelease(IHandle_t * h); +afs_sfsize_t namei_iread(IHandle_t * h, afs_foff_t offset, char *buf, + afs_fsize_t size); +afs_sfsize_t namei_iwrite(IHandle_t * h, afs_foff_t offset, char *buf, + afs_fsize_t size); +extern int namei_dec(IHandle_t * h, Inode ino, int p1); +extern int namei_inc(IHandle_t * h, Inode ino, int p1); +extern int namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit); extern int namei_ViceREADME(char *partition); #include "nfs.h" #include "viceinode.h" int namei_ListAFSFiles(char *dev, - int (*write_fun)(FILE *fp, struct ViceInodeInfo *info, - char *dir, char *file), - FILE *fp, - int (*judge_fun)(struct ViceInodeInfo *info, int vid), - int singleVolumeNumber); + int (*write_fun) (FILE * fp, + struct ViceInodeInfo * info, + char *dir, char *file), FILE * fp, + int (*judge_fun) (struct ViceInodeInfo * info, + int vid), int singleVolumeNumber); int ListViceInodes(char *devname, char *mountedOn, char *resultFile, - int (*judgeInode)(struct ViceInodeInfo *info, int vid), - int singleVolumeNumber, int *forcep, - int forceR, char *wpath); + int (*judgeInode) (struct ViceInodeInfo * info, int vid), + int singleVolumeNumber, int *forcep, int forceR, + char *wpath); #define NAMEI_LCOMP_LEN 32 @@ -66,8 +69,8 @@ typedef struct { char n_inode[NAMEI_LCOMP_LEN]; char n_path[NAMEI_PATH_LEN]; } namei_t; -void namei_HandleToName(namei_t *name, IHandle_t *h); +void namei_HandleToName(namei_t * name, IHandle_t * h); #endif /* AFS_NAMEI_ENV */ - + #endif /* _AFS_NAMEI_OPS_H_H_ */ diff --git a/src/vol/nfs.h b/src/vol/nfs.h index a24c6e9b7..0472c89e8 100644 --- a/src/vol/nfs.h +++ b/src/vol/nfs.h @@ -32,7 +32,7 @@ typedef afs_uint32 bit32; /* Unsigned, 32 bits */ typedef unsigned short bit16; /* Unsigned, 16 bits */ typedef unsigned char byte; /* Unsigned, 8 bits */ -typedef bit32 Device; /* Unix device number */ +typedef bit32 Device; /* Unix device number */ #ifndef Error #define Error bit32 #endif diff --git a/src/vol/ntops.c b/src/vol/ntops.c index 543a0d505..77f3bb9f8 100644 --- a/src/vol/ntops.c +++ b/src/vol/ntops.c @@ -12,7 +12,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/ntops.c,v 1.1.1.4 2001/07/14 22:24:57 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/ntops.c,v 1.7 2003/12/07 22:49:43 jaltman Exp $"); #ifdef AFS_NT40_ENV #include @@ -40,6 +41,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/ntops.c,v 1.1.1.4 2001/07/14 22:24: #define BASEFILEATTRIBUTE FILE_ATTRIBUTE_NORMAL +static void AddToZLCDeleteList(char dir, char *name); + /* nt_unlink - unlink a case sensitive name. * * nt_unlink supports the nt_dec call. @@ -50,19 +53,19 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/ntops.c,v 1.1.1.4 2001/07/14 22:24: * call tries to create a new file with the same name. Fortunately, neither * case should occur as part of nt_dec. */ -int nt_unlink(char *name) +int +nt_unlink(char *name) { HANDLE fh; - - fh = CreateFile(name, GENERIC_READ|GENERIC_WRITE, + + fh = CreateFile(name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, - BASEFILEATTRIBUTE | FILE_FLAG_DELETE_ON_CLOSE - | FILE_FLAG_POSIX_SEMANTICS, - NULL); + BASEFILEATTRIBUTE | FILE_FLAG_DELETE_ON_CLOSE | + FILE_FLAG_POSIX_SEMANTICS, NULL); if (fh != INVALID_HANDLE_VALUE) CloseHandle(fh); - else { + else { errno = nterr_nt2unix(GetLastError(), ENOENT); return -1; } @@ -74,14 +77,15 @@ int nt_unlink(char *name) * Return Value: * the handle or -1 on error. */ -FD_t nt_open(char *name, int flags, int mode) +FD_t +nt_open(char *name, int flags, int mode) { HANDLE fh; DWORD nt_access = 0; DWORD nt_share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; DWORD nt_create = 0; /* Really use the sequential one for data files, random for meta data. */ - DWORD FandA = BASEFILEATTRIBUTE | FILE_FLAG_SEQUENTIAL_SCAN ; + DWORD FandA = BASEFILEATTRIBUTE | FILE_FLAG_SEQUENTIAL_SCAN; /* set access */ if ((flags & O_RDWR) || (flags & O_WRONLY)) @@ -92,25 +96,30 @@ FD_t nt_open(char *name, int flags, int mode) /* set creation */ switch (flags & (O_CREAT | O_EXCL | O_TRUNC)) { case 0: - nt_create = OPEN_EXISTING; break; + nt_create = OPEN_EXISTING; + break; case O_CREAT: - nt_create = OPEN_ALWAYS; break; + nt_create = OPEN_ALWAYS; + break; case O_CREAT | O_TRUNC: - nt_create = CREATE_ALWAYS; break; + nt_create = CREATE_ALWAYS; + break; case O_CREAT | O_EXCL: case O_CREAT | O_EXCL | O_TRUNC: - nt_create = CREATE_NEW; break; + nt_create = CREATE_NEW; + break; case O_TRUNC: - nt_create = TRUNCATE_EXISTING; break; + nt_create = TRUNCATE_EXISTING; + break; case O_TRUNC | O_EXCL: case O_EXCL: default: - errno = EINVAL; return INVALID_FD; + errno = EINVAL; + return INVALID_FD; break; } - fh = CreateFile(name, nt_access, nt_share, NULL, nt_create, - FandA, NULL); + fh = CreateFile(name, nt_access, nt_share, NULL, nt_create, FandA, NULL); if (fh == INVALID_HANDLE_VALUE) { fh = INVALID_FD; @@ -119,7 +128,8 @@ FD_t nt_open(char *name, int flags, int mode) return fh; } -int nt_close(FD_t fd) +int +nt_close(FD_t fd) { BOOL code; @@ -131,12 +141,13 @@ int nt_close(FD_t fd) return 0; } -int nt_write(FD_t fd, char *buf, size_t size) +int +nt_write(FD_t fd, char *buf, size_t size) { BOOL code; DWORD nbytes; - code = WriteFile((HANDLE)fd, (void*)buf, (DWORD)size, &nbytes, NULL); + code = WriteFile((HANDLE) fd, (void *)buf, (DWORD) size, &nbytes, NULL); if (!code) { errno = nterr_nt2unix(GetLastError(), EBADF); @@ -145,12 +156,13 @@ int nt_write(FD_t fd, char *buf, size_t size) return (int)nbytes; } -int nt_read(FD_t fd, char *buf, size_t size) +int +nt_read(FD_t fd, char *buf, size_t size) { BOOL code; DWORD nbytes; - code = ReadFile((HANDLE)fd, (void*)buf, (DWORD)size, &nbytes, NULL); + code = ReadFile((HANDLE) fd, (void *)buf, (DWORD) size, &nbytes, NULL); if (!code) { errno = nterr_nt2unix(GetLastError(), EBADF); @@ -159,7 +171,8 @@ int nt_read(FD_t fd, char *buf, size_t size) return (int)nbytes; } -int nt_iread(IHandle_t *h, int offset, char *buf, int size) +int +nt_iread(IHandle_t * h, int offset, char *buf, int size) { int nBytes; FdHandle_t *fdP; @@ -168,7 +181,7 @@ int nt_iread(IHandle_t *h, int offset, char *buf, int size) if (fdP == NULL) return -1; - if (FDH_SEEK(fdP, offset, SEEK_SET)<0) { + if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { FDH_REALLYCLOSE(fdP); return -1; } @@ -178,7 +191,8 @@ int nt_iread(IHandle_t *h, int offset, char *buf, int size) return nBytes; } -int nt_iwrite(IHandle_t *h, int offset, char *buf, int size) +int +nt_iwrite(IHandle_t * h, int offset, char *buf, int size) { int nBytes; FdHandle_t *fdP; @@ -187,7 +201,7 @@ int nt_iwrite(IHandle_t *h, int offset, char *buf, int size) if (fdP == NULL) return -1; - if (FDH_SEEK(fdP, offset, SEEK_SET)<0) { + if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { FDH_REALLYCLOSE(fdP); return -1; } @@ -197,7 +211,8 @@ int nt_iwrite(IHandle_t *h, int offset, char *buf, int size) } -int nt_size(FD_t fd) +int +nt_size(FD_t fd) { BY_HANDLE_FILE_INFORMATION finfo; @@ -208,7 +223,8 @@ int nt_size(FD_t fd) } -int nt_getFileCreationTime(FD_t fd, FILETIME *ftime) +int +nt_getFileCreationTime(FD_t fd, FILETIME * ftime) { BY_HANDLE_FILE_INFORMATION finfo; @@ -220,31 +236,33 @@ int nt_getFileCreationTime(FD_t fd, FILETIME *ftime) return 0; } -int nt_setFileCreationTime(FD_t fd, FILETIME *ftime) +int +nt_setFileCreationTime(FD_t fd, FILETIME * ftime) { return !SetFileTime(fd, ftime, NULL, NULL); } -int nt_sync(int cdrive) +int +nt_sync(int cdrive) { FD_t drive_fd; char sdrive[32]; int n; n = cdrive; - if (n<=26) { - cdrive = 'A' + (n-1); + if (n <= 26) { + cdrive = 'A' + (n - 1); } cdrive = _toupper(cdrive); - (void) sprintf(sdrive, "\\\\.\\%c:", cdrive); - drive_fd = nt_open(sdrive , O_RDWR, 0666); + (void)sprintf(sdrive, "\\\\.\\%c:", cdrive); + drive_fd = nt_open(sdrive, O_RDWR, 0666); if (drive_fd == INVALID_FD) { return -1; } - if (!FlushFileBuffers((HANDLE)drive_fd)) { + if (!FlushFileBuffers((HANDLE) drive_fd)) { errno = nterr_nt2unix(GetLastError(), EBADF); nt_close(drive_fd); return -1; @@ -255,9 +273,10 @@ int nt_sync(int cdrive) /* Currently nt_ftruncate only tested to shrink a file. */ -int nt_ftruncate(FD_t fd, int len) +int +nt_ftruncate(FD_t fd, int len) { - if (SetFilePointer(fd, (LONG)len, NULL, FILE_BEGIN) + if (SetFilePointer(fd, (LONG) len, NULL, FILE_BEGIN) == 0xffffffff) { errno = nterr_nt2unix(GetLastError(), EBADF); return -1; @@ -270,14 +289,16 @@ int nt_ftruncate(FD_t fd, int len) } -int nt_fsync(FD_t fd) +int +nt_fsync(FD_t fd) { int code = FlushFileBuffers(fd); return code == 0 ? -1 : 0; } -int nt_seek(FD_t fd, int off, int where) +int +nt_seek(FD_t fd, int off, int where) { int code = SetFilePointer(fd, off, NULL, where); return code; @@ -298,15 +319,15 @@ int nt_seek(FD_t fd, int off, int where) #define NT_TAGSHIFT 32 #define NT_INODESPECIAL 0x2000000000 -#define NT_MAXVOLS 5 /* Maximum supported number of volumes per volume - * group, not counting temporary (move) volumes. - * This is the number of separate files, all having - * the same vnode number, which can occur in a volume - * group at once. - */ +#define NT_MAXVOLS 5 /* Maximum supported number of volumes per volume + * group, not counting temporary (move) volumes. + * This is the number of separate files, all having + * the same vnode number, which can occur in a volume + * group at once. + */ - -int nt_SetLinkCount(FdHandle_t *h, Inode ino, int count, int locked); + +int nt_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked); /* nt_DevToDrive @@ -320,30 +341,33 @@ int nt_SetLinkCount(FdHandle_t *h, Inode ino, int count, int locked); * Returns pointer to end of drive if successful, else NULL. * */ -char * nt_DevToDrive(char *drive, int dev) +char * +nt_DevToDrive(char *drive, int dev) { if (dev < 2 || dev > 25) { errno = EINVAL; - return NULL; /* Invalid drive */ + return NULL; /* Invalid drive */ } drive[0] = (char)('A' + dev); drive[1] = ':'; drive[2] = '\0'; - - return drive+2; + + return drive + 2; } /* Returns pointer to end of name if successful, else NULL. */ -char * nt_HandleToVolDir(char *name, IHandle_t *h) +char * +nt_HandleToVolDir(char *name, IHandle_t * h) { b32_string_t str1; - if (!(name = nt_DevToDrive(name, h->ih_dev))) return NULL; + if (!(name = nt_DevToDrive(name, h->ih_dev))) + return NULL; - (void) memcpy(name, "\\Vol_", 5); + (void)memcpy(name, "\\Vol_", 5); name += 5; - (void) strcpy(name, int_to_base32(str1, h->ih_vid)); + (void)strcpy(name, int_to_base32(str1, h->ih_vid)); name += strlen(name); memcpy(name, ".data", 5); name += 5; @@ -356,13 +380,15 @@ char * nt_HandleToVolDir(char *name, IHandle_t *h) * * Constructs a file name for the fully qualified handle. */ -int nt_HandleToName(char *name, IHandle_t *h) +int +nt_HandleToName(char *name, IHandle_t * h) { b32_string_t str1; - int tag = (int)((h->ih_ino>>NT_TAGSHIFT) & NT_TAGMASK); + int tag = (int)((h->ih_ino >> NT_TAGSHIFT) & NT_TAGMASK); int vno = (int)(h->ih_ino & NT_VNODEMASK); - - if (!(name = nt_HandleToVolDir(name, h))) return -1; + + if (!(name = nt_HandleToVolDir(name, h))) + return -1; str1[0] = '\\'; if (h->ih_ino & NT_INODESPECIAL) @@ -371,17 +397,17 @@ int nt_HandleToName(char *name, IHandle_t *h) if (vno & 0x1) str1[1] = 'Q'; else - str1[1] = ((vno & 0x1f)>>1) + 'A'; + str1[1] = ((vno & 0x1f) >> 1) + 'A'; } memcpy(name, str1, 2); name += 2; - (void) memcpy(name, "\\V_", 3); + (void)memcpy(name, "\\V_", 3); name += 3; - (void) strcpy(name, int_to_base32(str1, vno)); + (void)strcpy(name, int_to_base32(str1, vno)); name += strlen(name); *(name++) = '.'; - (void) strcpy(name, int_to_base32(str1, tag)); + (void)strcpy(name, int_to_base32(str1, tag)); name += strlen(name); *name = '\0'; @@ -401,7 +427,8 @@ int nt_HandleToName(char *name, IHandle_t *h) * Q ----- data directory * R ----- special files directory */ -static int nt_CreateDataDirectories(IHandle_t *h, int *created) +static int +nt_CreateDataDirectories(IHandle_t * h, int *created) { char name[128]; char *s; @@ -409,23 +436,22 @@ static int nt_CreateDataDirectories(IHandle_t *h, int *created) if (!(s = nt_HandleToVolDir(name, h))) return -1; - - if (mkdir(name)<0) { + + if (mkdir(name) < 0) { if (errno != EEXIST) return -1; - } - else + } else *created = 1; *s++ = '\\'; - *(s+1) = '\0'; - for (i = 'A'; i <= 'R' ; i++) { + *(s + 1) = '\0'; + for (i = 'A'; i <= 'R'; i++) { *s = (char)i; - if (mkdir(name)<0 && errno != EEXIST) + if (mkdir(name) < 0 && errno != EEXIST) return -1; } return 0; -} +} /* nt_RemoveDataDirectories * @@ -433,7 +459,8 @@ static int nt_CreateDataDirectories(IHandle_t *h, int *created) * can continue running if the removes fail. The salvage process will * finish tidying up for us. */ -static int nt_RemoveDataDirectories(IHandle_t *h) +static int +nt_RemoveDataDirectories(IHandle_t * h) { char name[128]; char *s; @@ -443,22 +470,22 @@ static int nt_RemoveDataDirectories(IHandle_t *h) return -1; *s++ = '\\'; - *(s+1) = '\0'; - for (i = 'A'; i <= 'R' ; i++) { + *(s + 1) = '\0'; + for (i = 'A'; i <= 'R'; i++) { *s = (char)i; - if (rmdir(name)<0 && errno != ENOENT) + if (rmdir(name) < 0 && errno != ENOENT) return -1; } /* Delete the Vol_NNNNNN.data directory. */ s--; *s = '\0'; - if (rmdir(name)<0 && errno != ENOENT) { + if (rmdir(name) < 0 && errno != ENOENT) { return -1; } - + return 0; -} +} /* Create the file in the name space. @@ -486,12 +513,14 @@ static int nt_RemoveDataDirectories(IHandle_t *h) * This function is called by VCreateVolume to hide the implementation * details of the inode numbers. */ -Inode nt_MakeSpecIno(int type) +Inode +nt_MakeSpecIno(int type) { - return ((Inode)type | (Inode)NT_INODESPECIAL); + return ((Inode) type | (Inode) NT_INODESPECIAL); } -Inode nt_icreate(IHandle_t *h, char *part, int p1, int p2, int p3, int p4) +Inode +nt_icreate(IHandle_t * h, char *part, int p1, int p2, int p3, int p4) { char filename[128]; b32_string_t str1; @@ -506,26 +535,25 @@ Inode nt_icreate(IHandle_t *h, char *part, int p1, int p2, int p3, int p4) FdHandle_t tfd; int save_errno; - memset((void*)&tmp, 0, sizeof(IHandle_t)); + memset((void *)&tmp, 0, sizeof(IHandle_t)); tmp.ih_dev = tolower(*part) - 'a'; - if (p2 == -1 ) { - tmp.ih_vid = p4; /* Use parent volume id, where this file will be.*/ + if (p2 == -1) { + tmp.ih_vid = p4; /* Use parent volume id, where this file will be. */ - if (nt_CreateDataDirectories(&tmp, &created_dir)<0) + if (nt_CreateDataDirectories(&tmp, &created_dir) < 0) goto bad; tmp.ih_ino = nt_MakeSpecIno(p3); ftime.dwHighDateTime = p1; ftime.dwLowDateTime = p2; - } - else { + } else { /* Regular file or directory. * Encoding: p1 -> dir, p2 -> name, p3,p4 -> Create time */ - tmp.ih_ino = (Inode)p2; + tmp.ih_ino = (Inode) p2; tmp.ih_vid = p1; ftime.dwHighDateTime = p3; @@ -533,14 +561,14 @@ Inode nt_icreate(IHandle_t *h, char *part, int p1, int p2, int p3, int p4) } /* Now create file. */ - if ((code = nt_HandleToName(filename, &tmp))<0) + if ((code = nt_HandleToName(filename, &tmp)) < 0) goto bad; p = filename + strlen(filename); - p --; - for (i=0; iih_dev, h->ih_vid, ino); - if (nt_HandleToName(name, tmp)<0) { + if (nt_HandleToName(name, tmp) < 0) { IH_RELEASE(tmp); errno = EINVAL; return -1; } - dirH = FindFirstFileEx(name, FindExInfoStandard, &info, - FindExSearchNameMatch, NULL, - FIND_FIRST_EX_CASE_SENSITIVE); + dirH = + FindFirstFileEx(name, FindExInfoStandard, &info, + FindExSearchNameMatch, NULL, + FIND_FIRST_EX_CASE_SENSITIVE); if (!dirH) { IH_RELEASE(tmp); errno = ENOENT; - return -1; /* Can't get info, leave alone */ + return -1; /* Can't get info, leave alone */ } FindClose(dirH); if (info.ftCreationTime.dwHighDateTime != (unsigned int)p1) { IH_RELEASE(tmp); return -1; - } - + } + /* If it's the link table itself, decrement the link count. */ if ((ino & NT_VNODEMASK) == VI_LINKTABLE) { fdP = IH_OPEN(tmp); - if(fdP == NULL) { + if (fdP == NULL) { IH_RELEASE(tmp); return -1; } - if ((count = nt_GetLinkCount(fdP, (Inode)0, 1))<0) { + if ((count = nt_GetLinkCount(fdP, (Inode) 0, 1)) < 0) { FDH_REALLYCLOSE(fdP); IH_RELEASE(tmp); return -1; } - count --; - if (nt_SetLinkCount(fdP, (Inode)0, count<0 ? 0 : count, 1)<0) { + count--; + if (nt_SetLinkCount(fdP, (Inode) 0, count < 0 ? 0 : count, 1) < 0) { FDH_REALLYCLOSE(fdP); IH_RELEASE(tmp); return -1; } FDH_REALLYCLOSE(fdP); - if (count>0) { + if (count > 0) { IH_RELEASE(tmp); return 0; } } - + if ((code = nt_unlink(name)) == 0) { if ((ino & NT_VNODEMASK) == VI_LINKTABLE) { /* Try to remove directory. If it fails, that's ok. * Salvage will clean up. */ - (void) nt_RemoveDataDirectories(tmp); + (void)nt_RemoveDataDirectories(tmp); } } IH_RELEASE(tmp); - } - else { + } else { /* Get a file descriptor handle for this Inode */ fdP = IH_OPEN(h); if (fdP == NULL) { return -1; } - if ((count = nt_GetLinkCount(fdP, ino, 1))<0) { + if ((count = nt_GetLinkCount(fdP, ino, 1)) < 0) { FDH_REALLYCLOSE(fdP); return -1; } - count --; + count--; if (count >= 0) { - if (nt_SetLinkCount(fdP, ino, count, 1)<0) { + if (nt_SetLinkCount(fdP, ino, count, 1) < 0) { FDH_REALLYCLOSE(fdP); return -1; } } - if (count == 0 ) { + if (count == 0) { IHandle_t th = *h; th.ih_ino = ino; nt_HandleToName(name, &th); @@ -725,7 +754,8 @@ int nt_dec(IHandle_t *h, Inode ino, int p1) return code; } -int nt_inc(IHandle_t *h, Inode ino, int p1) +int +nt_inc(IHandle_t * h, Inode ino, int p1) { int count; int code = 0; @@ -734,7 +764,7 @@ int nt_inc(IHandle_t *h, Inode ino, int p1) if (ino & NT_INODESPECIAL) { if ((ino & NT_VNODEMASK) != VI_LINKTABLE) return 0; - ino = (Inode)0; + ino = (Inode) 0; } /* Get a file descriptor handle for this Inode */ @@ -743,16 +773,16 @@ int nt_inc(IHandle_t *h, Inode ino, int p1) return -1; } - if ((count = nt_GetLinkCount(fdP, ino, 1))<0) + if ((count = nt_GetLinkCount(fdP, ino, 1)) < 0) code = -1; else { - count ++; + count++; if (count > 7) { errno = EINVAL; code = -1; count = 7; } - if (nt_SetLinkCount(fdP, ino, count, 1)<0) + if (nt_SetLinkCount(fdP, ino, count, 1) < 0) code = -1; } if (code) { @@ -790,14 +820,15 @@ int nt_inc(IHandle_t *h, Inode ino, int p1) * in the link table. */ #define LINKTABLE_WIDTH 2 -#define LINKTABLE_SHIFT 1 /* log 2 = 1 */ +#define LINKTABLE_SHIFT 1 /* log 2 = 1 */ -static void nt_GetLCOffsetAndIndexFromIno(Inode ino, int *offset, int *index) +static void +nt_GetLCOffsetAndIndexFromIno(Inode ino, int *offset, int *index) { - int toff = (int) (ino & NT_VNODEMASK); - int tindex = (int)((ino>>NT_TAGSHIFT) & NT_TAGMASK); + int toff = (int)(ino & NT_VNODEMASK); + int tindex = (int)((ino >> NT_TAGSHIFT) & NT_TAGMASK); - *offset = (toff << LINKTABLE_SHIFT) + 8; /* *2 + sizeof stamp */ + *offset = (toff << LINKTABLE_SHIFT) + 8; /* *2 + sizeof stamp */ *index = (tindex << 1) + tindex; } @@ -806,7 +837,8 @@ static void nt_GetLCOffsetAndIndexFromIno(Inode ino, int *offset, int *index) * If lockit is set, lock the file and leave it locked upon a successful * return. */ -int nt_GetLinkCount(FdHandle_t *h, Inode ino, int lockit) +int +nt_GetLinkCount(FdHandle_t * h, Inode ino, int lockit) { unsigned short row = 0; int junk; @@ -819,16 +851,16 @@ int nt_GetLinkCount(FdHandle_t *h, Inode ino, int lockit) return -1; } - if (!SetFilePointer(h->fd_fd, (LONG)offset, NULL, FILE_BEGIN)) + if (!SetFilePointer(h->fd_fd, (LONG) offset, NULL, FILE_BEGIN)) goto bad_getLinkByte; - - if (!ReadFile(h->fd_fd, (void*)&row, 2, &junk, NULL)) { + + if (!ReadFile(h->fd_fd, (void *)&row, 2, &junk, NULL)) { goto bad_getLinkByte; } - - return (int) ((row >> index) & NT_TAGMASK); - bad_getLinkByte: + return (int)((row >> index) & NT_TAGMASK); + + bad_getLinkByte: if (lockit) UnlockFile(h->fd_fd, offset, 0, 2, 0); return -1; @@ -841,7 +873,8 @@ int nt_GetLinkCount(FdHandle_t *h, Inode ino, int lockit) * If locked is set, assume file is locked. Otherwise, lock file before * proceeding to modify it. */ -int nt_SetLinkCount(FdHandle_t *h, Inode ino, int count, int locked) +int +nt_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked) { int offset, index; unsigned short row; @@ -857,38 +890,38 @@ int nt_SetLinkCount(FdHandle_t *h, Inode ino, int count, int locked) return -1; } } - if (!SetFilePointer(h->fd_fd, (LONG)offset, NULL, FILE_BEGIN)) { + if (!SetFilePointer(h->fd_fd, (LONG) offset, NULL, FILE_BEGIN)) { errno = nterr_nt2unix(GetLastError(), EBADF); goto bad_SetLinkCount; } - - if (!ReadFile(h->fd_fd, (void*)&row, 2, &junk, NULL)) { + + if (!ReadFile(h->fd_fd, (void *)&row, 2, &junk, NULL)) { errno = nterr_nt2unix(GetLastError(), EBADF); goto bad_SetLinkCount; } if (junk == 0) row = 0; - + junk = 7 << index; count <<= index; row &= (unsigned short)~junk; row |= (unsigned short)count; - if (!SetFilePointer(h->fd_fd, (LONG)offset, NULL, FILE_BEGIN)) { + if (!SetFilePointer(h->fd_fd, (LONG) offset, NULL, FILE_BEGIN)) { errno = nterr_nt2unix(GetLastError(), EBADF); goto bad_SetLinkCount; } - if (!WriteFile(h->fd_fd, (void*)&row, 2, &junk, NULL)) { + if (!WriteFile(h->fd_fd, (void *)&row, 2, &junk, NULL)) { errno = nterr_nt2unix(GetLastError(), EBADF); goto bad_SetLinkCount; } code = 0; - -bad_SetLinkCount: + + bad_SetLinkCount: UnlockFile(h->fd_fd, offset, 0, 2, 0); return code; @@ -898,11 +931,11 @@ bad_SetLinkCount: /* ListViceInodes - write inode data to a results file. */ static int DecodeInodeName(char *name, int *p1, int *p2); static int DecodeVolumeName(char *name, int *vid); -static int nt_ListAFSSubDirs(IHandle_t *dirIH, - int (*write_fun)(FILE *, struct ViceInodeInfo *, - char *, char *), - FILE *fp, - int (*judgeFun)(struct ViceInodeInfo *, int vid), +static int nt_ListAFSSubDirs(IHandle_t * dirIH, + int (*write_fun) (FILE *, struct ViceInodeInfo *, + char *, char *), FILE * fp, + int (*judgeFun) (struct ViceInodeInfo *, + int vid), int singleVolumeNumber); @@ -915,8 +948,8 @@ static int nt_ListAFSSubDirs(IHandle_t *dirIH, * This is written as a callback simply so that other listing routines * can use the same inode reading code. */ -static int WriteInodeInfo(FILE *fp, struct ViceInodeInfo *info, char *dir, - char *name) +static int +WriteInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name) { int n; n = fwrite(info, sizeof(*info), 1, fp); @@ -937,12 +970,12 @@ static int WriteInodeInfo(FILE *fp, struct ViceInodeInfo *info, char *dir, * * If the resultFile is NULL, then don't call the write routine. */ -int ListViceInodes(char *devname, char *mountedOn, char *resultFile, - int (*judgeInode)(struct ViceInodeInfo *info, int vid), - int singleVolumeNumber, int *forcep, - int forceR, char *wpath) +int +ListViceInodes(char *devname, char *mountedOn, char *resultFile, + int (*judgeInode) (struct ViceInodeInfo * info, int vid), + int singleVolumeNumber, int *forcep, int forceR, char *wpath) { - FILE *fp = (FILE*)-1; + FILE *fp = (FILE *) - 1; int ninodes; struct stat status; @@ -953,8 +986,9 @@ int ListViceInodes(char *devname, char *mountedOn, char *resultFile, return -1; } } - ninodes = nt_ListAFSFiles(wpath, WriteInodeInfo, fp, - judgeInode, singleVolumeNumber); + ninodes = + nt_ListAFSFiles(wpath, WriteInodeInfo, fp, judgeInode, + singleVolumeNumber); if (!resultFile) return ninodes; @@ -986,9 +1020,9 @@ int ListViceInodes(char *devname, char *mountedOn, char *resultFile, Log("Unable to successfully stat inode file for %s\n", mountedOn); return -2; } - if (status.st_size != ninodes * sizeof (struct ViceInodeInfo)) { - Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof (struct ViceInodeInfo), + if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + Log("Wrong size (%d instead of %d) in inode file for %s\n", + status.st_size, ninodes * sizeof(struct ViceInodeInfo), mountedOn); return -2; } @@ -1003,12 +1037,12 @@ int ListViceInodes(char *devname, char *mountedOn, char *resultFile, * * Returns <0 on error, else number of files found to match. */ -int nt_ListAFSFiles(char *dev, - int (*writeFun)(FILE *, struct ViceInodeInfo *, char *, - char *), - FILE *fp, - int (*judgeFun)(struct ViceInodeInfo *, int), - int singleVolumeNumber) +int +nt_ListAFSFiles(char *dev, + int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, + char *), FILE * fp, + int (*judgeFun) (struct ViceInodeInfo *, int), + int singleVolumeNumber) { IHandle_t h; char name[MAX_PATH]; @@ -1017,19 +1051,18 @@ int nt_ListAFSFiles(char *dev, struct dirent *dp; static void FreeZLCList(void); - memset((void*)&h, 0, sizeof(IHandle_t)); + memset((void *)&h, 0, sizeof(IHandle_t)); h.ih_dev = toupper(*dev) - 'A'; if (singleVolumeNumber) { h.ih_vid = singleVolumeNumber; - if (nt_HandleToVolDir(name, &h)<0) + if (!nt_HandleToVolDir(name, &h)) return -1; - ninodes = nt_ListAFSSubDirs(&h, writeFun, fp, - judgeFun, singleVolumeNumber); + ninodes = + nt_ListAFSSubDirs(&h, writeFun, fp, judgeFun, singleVolumeNumber); if (ninodes < 0) return ninodes; - } - else { + } else { /* Find all Vol_*.data directories and descend through them. */ if (!nt_DevToDrive(name, h.ih_dev)) return -1; @@ -1039,8 +1072,7 @@ int nt_ListAFSFiles(char *dev, return -1; while (dp = readdir(dirp)) { if (!DecodeVolumeName(dp->d_name, &h.ih_vid)) { - ninodes += nt_ListAFSSubDirs(&h, writeFun, fp, - judgeFun, 0); + ninodes += nt_ListAFSSubDirs(&h, writeFun, fp, judgeFun, 0); } } } @@ -1058,12 +1090,12 @@ int nt_ListAFSFiles(char *dev, * < 0 - an error * > = 0 - number of AFS files found. */ -static int nt_ListAFSSubDirs(IHandle_t *dirIH, - int (*writeFun)(FILE *, struct ViceInodeInfo *, - char *, char *), - FILE *fp, - int (*judgeFun)(struct ViceInodeInfo *, int), - int singleVolumeNumber) +static int +nt_ListAFSSubDirs(IHandle_t * dirIH, + int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, + char *), FILE * fp, + int (*judgeFun) (struct ViceInodeInfo *, int), + int singleVolumeNumber) { int i; IHandle_t myIH = *dirIH; @@ -1077,72 +1109,68 @@ static int nt_ListAFSSubDirs(IHandle_t *dirIH, int tag, vno; FdHandle_t linkHandle; int ninodes = 0; - static void AddToZLCDeleteList(char dir, char *name); static void DeleteZLCFiles(char *path); s = nt_HandleToVolDir(path, &myIH); strcpy(basePath, path); - if (!s) return -1; + if (!s) + return -1; *s = '\\'; s++; - *(s+1) = '\0'; + *(s + 1) = '\0'; /* Do the directory containing the special files first to pick up link * counts. */ - for (i='R'; i>='A'; i--) { + for (i = 'R'; i >= 'A'; i--) { *s = (char)i; - (void) strcpy(findPath, path); - (void) strcat(findPath, "\\*"); - dirH = FindFirstFileEx(findPath, FindExInfoStandard, &data, - FindExSearchNameMatch, NULL, - FIND_FIRST_EX_CASE_SENSITIVE); + (void)strcpy(findPath, path); + (void)strcat(findPath, "\\*"); + dirH = + FindFirstFileEx(findPath, FindExInfoStandard, &data, + FindExSearchNameMatch, NULL, + FIND_FIRST_EX_CASE_SENSITIVE); if (dirH == INVALID_HANDLE_VALUE) continue; while (1) { /* Store the vice info. */ - memset((void*)&info, 0, sizeof(info)); + memset((void *)&info, 0, sizeof(info)); if (*data.cFileName == '.') goto next_file; - if (DecodeInodeName(data.cFileName, &vno, &tag)<0) { - Log("Error parsing %s\\%s\n", - path, data.cFileName); - } - else { - info.inodeNumber = (Inode)tag << NT_TAGSHIFT; - info.inodeNumber |= (Inode)vno; + if (DecodeInodeName(data.cFileName, &vno, &tag) < 0) { + Log("Error parsing %s\\%s\n", path, data.cFileName); + } else { + info.inodeNumber = (Inode) tag << NT_TAGSHIFT; + info.inodeNumber |= (Inode) vno; info.byteCount = data.nFileSizeLow; - if (i == 'R') { /* Special inode. */ + if (i == 'R') { /* Special inode. */ info.inodeNumber |= NT_INODESPECIAL; info.u.param[0] = data.ftCreationTime.dwHighDateTime; - info.u.param[1] = data.ftCreationTime.dwLowDateTime; + info.u.param[1] = data.ftCreationTime.dwLowDateTime; info.u.param[2] = vno; info.u.param[3] = dirIH->ih_vid; if (info.u.param[2] != VI_LINKTABLE) { info.linkCount = 1; - } - else { + } else { /* Open this handle */ char lpath[1024]; - (void) sprintf(lpath, "%s\\%s", - path, data.cFileName); + (void)sprintf(lpath, "%s\\%s", path, data.cFileName); linkHandle.fd_fd = nt_open(lpath, O_RDONLY, 0666); - info.linkCount = nt_GetLinkCount(&linkHandle, - (Inode)0, 0); + info.linkCount = + nt_GetLinkCount(&linkHandle, (Inode) 0, 0); } - } - else { /* regular file. */ - info.linkCount = nt_GetLinkCount(&linkHandle, - info.inodeNumber, 0); + } else { /* regular file. */ + info.linkCount = + nt_GetLinkCount(&linkHandle, info.inodeNumber, 0); if (info.linkCount == 0) { #ifdef notdef Log("Found 0 link count file %s\\%s, deleting it.\n", path, data.cFileName); AddToZLCDeleteList((char)i, data.cFileName); #else - Log("Found 0 link count file %s\\%s.\n", - path, data.cFileName); + Log("Found 0 link count file %s\\%s.\n", path, + data.cFileName); #endif goto next_file; } @@ -1151,16 +1179,16 @@ static int nt_ListAFSSubDirs(IHandle_t *dirIH, info.u.param[2] = data.ftCreationTime.dwHighDateTime; info.u.param[3] = data.ftCreationTime.dwLowDateTime; } - if (judgeFun && !(*judgeFun)(&info, singleVolumeNumber)) + if (judgeFun && !(*judgeFun) (&info, singleVolumeNumber)) goto next_file; - if ((*writeFun)(fp, &info, path, data.cFileName)<0) { + if ((*writeFun) (fp, &info, path, data.cFileName) < 0) { nt_close(linkHandle.fd_fd); FindClose(dirH); return -1; } - ninodes ++; + ninodes++; } - next_file: + next_file: if (!FindNextFile(dirH, &data)) { break; } @@ -1178,7 +1206,8 @@ static int nt_ListAFSSubDirs(IHandle_t *dirIH, } /* The name begins with "Vol_" and ends with .data. See nt_HandleToVolDir() */ -static int DecodeVolumeName(char *name, int *vid) +static int +DecodeVolumeName(char *name, int *vid) { char stmp[32]; int len; @@ -1188,30 +1217,33 @@ static int DecodeVolumeName(char *name, int *vid) return -1; if (strncmp(name, "Vol_", 4)) return -1; - if (strcmp(name+len-5, ".data")) + if (strcmp(name + len - 5, ".data")) return -1; strcpy(stmp, name); - stmp[len-5] = '\0'; - *vid = base32_to_int(stmp+4); + stmp[len - 5] = '\0'; + *vid = base32_to_int(stmp + 4); return 0; } /* Recall that the name beings with a "V_" */ -static int DecodeInodeName(char *name, int *p1, int *p2) +static int +DecodeInodeName(char *name, int *p1, int *p2) { char *s, *t; char stmp[16]; - (void) strcpy(stmp, name); + (void)strcpy(stmp, name); s = strrchr(stmp, '_'); - if (!s) return -1; + if (!s) + return -1; s++; t = strrchr(s, '.'); - if (!t) return -1; + if (!t) + return -1; *t = '\0'; *p1 = base32_to_int(s); - *p2 = base32_to_int(t+1); + *p2 = base32_to_int(t + 1); return 0; } @@ -1220,15 +1252,16 @@ static int DecodeInodeName(char *name, int *p1, int *p2) * * returns a static string used to print either 32 or 64 bit inode numbers. */ -char * PrintInode(char *s, Inode ino) +char * +PrintInode(char *s, Inode ino) { - static afs_ino_str_t result; + static afs_ino_str_t result; if (!s) s = result; - (void) sprintf((char*)s, "%I64u", ino); + (void)sprintf((char *)s, "%I64u", ino); - return (char*)s; + return (char *)s; } @@ -1244,7 +1277,8 @@ typedef struct zlcList_s { static zlcList_t *zlcAnchor = NULL; static zlcList_t *zlcCur = NULL; -static void AddToZLCDeleteList(char dir, char *name) +static void +AddToZLCDeleteList(char dir, char *name) { assert(strlen(name) <= MAX_ZLC_NAMELEN - 3); @@ -1252,13 +1286,12 @@ static void AddToZLCDeleteList(char dir, char *name) if (zlcCur && zlcCur->zlc_next) zlcCur = zlcCur->zlc_next; else { - zlcList_t *tmp = (zlcList_t*)malloc(sizeof(zlcList_t)); + zlcList_t *tmp = (zlcList_t *) malloc(sizeof(zlcList_t)); if (!tmp) return; if (!zlcAnchor) { zlcAnchor = tmp; - } - else { + } else { zlcCur->zlc_next = tmp; } zlcCur = tmp; @@ -1267,30 +1300,32 @@ static void AddToZLCDeleteList(char dir, char *name) } } - (void) sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%c\\%s", dir, name); - zlcCur->zlc_n ++; + (void)sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%c\\%s", dir, name); + zlcCur->zlc_n++; } -static void DeleteZLCFiles(char *path) +static void +DeleteZLCFiles(char *path) { zlcList_t *z; int i; char fname[1024]; for (z = zlcAnchor; z; z = z->zlc_next) { - for (i=0; i < z->zlc_n; i++) { - (void) sprintf(fname, "%s\\%s", path, z->zlc_names[i]); - if (nt_unlink(fname)<0) { + for (i = 0; i < z->zlc_n; i++) { + (void)sprintf(fname, "%s\\%s", path, z->zlc_names[i]); + if (nt_unlink(fname) < 0) { Log("ZLC: Can't unlink %s, dos error = %d\n", fname, - GetLastError()); + GetLastError()); } } - z->zlc_n = 0; /* Can reuse space. */ + z->zlc_n = 0; /* Can reuse space. */ } zlcCur = zlcAnchor; } -static void FreeZLCList(void) +static void +FreeZLCList(void) { zlcList_t *tnext; zlcList_t *i; @@ -1305,4 +1340,3 @@ static void FreeZLCList(void) } #endif /* AFS_NT40_ENV */ - diff --git a/src/vol/ntops.h b/src/vol/ntops.h index 7119707cb..e5098e1f0 100644 --- a/src/vol/ntops.h +++ b/src/vol/ntops.h @@ -26,39 +26,38 @@ extern int nt_close(FD_t fd); extern int nt_write(FD_t fd, char *buf, size_t size); extern int nt_read(FD_t fd, char *buf, size_t size); extern int nt_size(FD_t fd); -extern int nt_getFileCreationTime(FD_t fd, FILETIME *ftime); -extern int nt_setFileCreationTime(FD_t fd, FILETIME *ftime); +extern int nt_getFileCreationTime(FD_t fd, FILETIME * ftime); +extern int nt_setFileCreationTime(FD_t fd, FILETIME * ftime); extern int nt_sync(int cdrive); extern int nt_ftruncate(FD_t fd, int len); extern int nt_fsync(FD_t fd); extern int nt_seek(FD_t fd, int off, int where); -extern FILE *nt_fdopen(IHandle_t *h, char *fdperms); +extern FILE *nt_fdopen(IHandle_t * h, char *fdperms); extern int nt_unlink(char *name); /* Inode operations */ extern Inode nt_MakeSpecIno(int type); -extern Inode nt_icreate(IHandle_t *h, char *p, int p1, int p2, int p3, int p4); -extern FD_t nt_iopen(IHandle_t *h); -extern int nt_irelease(IHandle_t *h); -int nt_iread(IHandle_t *h, int offset, char *buf, int size); -int nt_iwrite(IHandle_t *h, int offset, char *buf, int size); -extern int nt_dec(IHandle_t *h, Inode ino, int p1); -extern int nt_inc(IHandle_t *h, Inode ino, int p1); -extern int nt_GetLinkCount(FdHandle_t *h, Inode ino, int lockit); +extern Inode nt_icreate(IHandle_t * h, char *p, int p1, int p2, int p3, + int p4); +extern FD_t nt_iopen(IHandle_t * h); +extern int nt_irelease(IHandle_t * h); +int nt_iread(IHandle_t * h, int offset, char *buf, int size); +int nt_iwrite(IHandle_t * h, int offset, char *buf, int size); +extern int nt_dec(IHandle_t * h, Inode ino, int p1); +extern int nt_inc(IHandle_t * h, Inode ino, int p1); +extern int nt_GetLinkCount(FdHandle_t * h, Inode ino, int lockit); int nt_ListAFSFiles(char *dev, - int (*write_fun)(FILE *fp, struct ViceInodeInfo*, - char *dir, char *file), - FILE *fp, - int (*judge_fun)(struct ViceInodeInfo*, int vid), + int (*write_fun) (FILE * fp, struct ViceInodeInfo *, + char *dir, char *file), FILE * fp, + int (*judge_fun) (struct ViceInodeInfo *, int vid), int singleVolumeNumber); int ListViceInodes(char *devname, char *mountedOn, char *resultFile, - int (*judgeInode)(struct ViceInodeInfo *info, int vid), - int singleVolumeNumber, int *forcep, - int forceR, char *wpath); + int (*judgeInode) (struct ViceInodeInfo * info, int vid), + int singleVolumeNumber, int *forcep, int forceR, + char *wpath); -int nt_HandleToName(char *name, IHandle_t *h); -char * nt_HandleToVolDir(char *name, IHandle_t *h); - -#endif /* _NTOPS_H_ */ +int nt_HandleToName(char *name, IHandle_t * h); +char *nt_HandleToVolDir(char *name, IHandle_t * h); +#endif /* _NTOPS_H_ */ diff --git a/src/vol/nuke.c b/src/vol/nuke.c index 3a417d3a7..a0a846beb 100644 --- a/src/vol/nuke.c +++ b/src/vol/nuke.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/nuke.c,v 1.1.1.6 2003/04/13 19:08:18 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/nuke.c,v 1.13 2003/11/23 04:53:43 jaltman Exp $"); #include #include @@ -42,6 +43,14 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/nuke.c,v 1.1.1.6 2003/04/13 19:08:1 #include "salvage.h" #include "fssync.h" +#ifdef O_LARGEFILE +#define afs_stat stat64 +#else /* !O_LARGEFILE */ +#define afs_stat stat +#endif /* !O_LARGEFILE */ + +/*@printflike@*/ extern void Log(const char *format, ...); + struct Lock localLock; char *vol_DevName(); @@ -53,39 +62,40 @@ char *vol_DevName(); */ struct ilist { struct ilist *next; - afs_int32 freePtr; /* first free index in this table */ - Inode inode[MAXATONCE]; /* inode # */ - afs_int32 count[MAXATONCE]; /* link count */ + afs_int32 freePtr; /* first free index in this table */ + Inode inode[MAXATONCE]; /* inode # */ + afs_int32 count[MAXATONCE]; /* link count */ } *allInodes = 0; /* called with a structure specifying info about the inode, and our rock (which * is the volume ID. Returns true if we should keep this inode, otherwise false. * Note that ainfo->u.param[0] is always the volume ID, for any vice inode. */ -static NukeProc(ainfo, avolid) -struct ViceInodeInfo *ainfo; -afs_int32 avolid; { +static int +NukeProc(struct ViceInodeInfo *ainfo, afs_int32 avolid) +{ struct ilist *ti; register afs_int32 i; #ifndef AFS_PTHREAD_ENV - IOMGR_Poll(); /* poll so we don't kill the RPC connection */ + IOMGR_Poll(); /* poll so we don't kill the RPC connection */ #endif /* !AFS_PTHREAD_ENV */ /* check if this is the volume we're looking for */ - if (ainfo->u.param[0] != avolid) return 0; /* don't want this one */ + if (ainfo->u.param[0] != avolid) + return 0; /* don't want this one */ /* record the info */ if (!allInodes || allInodes->freePtr >= MAXATONCE) { - ti = (struct ilist *) malloc(sizeof(struct ilist)); + ti = (struct ilist *)malloc(sizeof(struct ilist)); memset(ti, 0, sizeof(*ti)); ti->next = allInodes; allInodes = ti; - } - else ti = allInodes; /* use the one with space */ - i = ti->freePtr++; /* find our slot in this mess */ + } else + ti = allInodes; /* use the one with space */ + i = ti->freePtr++; /* find our slot in this mess */ ti->inode[i] = ainfo->inodeNumber; ti->count[i] = ainfo->linkCount; - return 0; /* don't care if anything's written out, actually */ + return 0; /* don't care if anything's written out, actually */ } /* function called with partition name and volid ID, and which removes all @@ -98,15 +108,14 @@ afs_int32 avolid; { * cloned from that RW volume ID, too, since everything except for their * indices will be gone. */ -nuke(aname, avolid) -char *aname; -afs_int32 avolid; { +int +nuke(char *aname, afs_int32 avolid) +{ /* first process the partition containing this junk */ - struct stat tstat; + struct afs_stat tstat; struct ilist *ti, *ni; register afs_int32 code; - char *tfile; - int i, j, forceSal; + int i, forceSal; char devName[64], wpath[100]; char *lastDevComp; #ifdef AFS_NAMEI_ENV @@ -119,8 +128,9 @@ afs_int32 avolid; { #endif /* AFS_NAMEI_ENV */ IHandle_t *fileH; - if (avolid == 0) return EINVAL; - code = stat(aname, &tstat); + if (avolid == 0) + return EINVAL; + code = afs_stat(aname, &tstat); if (code) { printf("volnuke: partition %s does not exist.\n", aname); return code; @@ -130,21 +140,24 @@ afs_int32 avolid; { lastDevComp = aname; #else #ifdef AFS_NT40_ENV - lastDevComp = &aname[strlen(aname)-1]; + lastDevComp = &aname[strlen(aname) - 1]; *lastDevComp = toupper(*lastDevComp); #else - tfile = vol_DevName(tstat.st_dev, wpath); + { + char *tfile = vol_DevName(tstat.st_dev, wpath); if (!tfile) { printf("volnuke: can't find %s's device.\n", aname); return 1; } strcpy(devName, tfile); /* save this from the static buffer */ + } /* aim lastDevComp at the 'foo' of '/dev/foo' */ lastDevComp = strrchr(devName, '/'); /* either points at slash, or there is no slash; adjust appropriately */ if (lastDevComp) lastDevComp++; - else lastDevComp = devName; + else + lastDevComp = devName; #endif /* AFS_NT40_ENV */ #endif /* AFS_NAMEI_ENV && !AFS_NT40_ENV */ @@ -154,49 +167,54 @@ afs_int32 avolid; { * volume we're nuking. */ #ifdef AFS_NAMEI_ENV - code = ListViceInodes(lastDevComp, aname, NULL, NukeProc, avolid, - &forceSal, 0, wpath); + code = + ListViceInodes(lastDevComp, aname, NULL, NukeProc, avolid, &forceSal, + 0, wpath); #else - code = ListViceInodes(lastDevComp, aname, "/tmp/vNukeXX", NukeProc, avolid, &forceSal, 0, wpath); + code = + ListViceInodes(lastDevComp, aname, "/tmp/vNukeXX", NukeProc, avolid, + &forceSal, 0, wpath); unlink("/tmp/vNukeXX"); /* clean it up now */ #endif if (code == 0) { /* actually do the idecs now */ - for(ti=allInodes; ti; ti=ti->next) { - for(i=0;ifreePtr;i++) { + for (ti = allInodes; ti; ti = ti->next) { + for (i = 0; i < ti->freePtr; i++) { #ifndef AFS_PTHREAD_ENV IOMGR_Poll(); /* keep RPC running */ #endif /* !AFS_PTHREAD_ENV */ /* idec this inode into oblivion */ #ifdef AFS_NAMEI_ENV #ifdef AFS_NT40_ENV - IH_INIT(fileH, (int) (*lastDevComp - 'A'), avolid, + IH_INIT(fileH, (int)(*lastDevComp - 'A'), avolid, ti->inode[i]); nt_HandleToName(path, fileH); #else - IH_INIT(fileH, (int) volutil_GetPartitionID(aname), avolid, + IH_INIT(fileH, (int)volutil_GetPartitionID(aname), avolid, ti->inode[i]); namei_HandleToName(&ufs_name, fileH); path = ufs_name.n_path; #endif /* AFS_NT40_ENV */ IH_RELEASE(fileH); - if (unlink(path)<0) { + if (unlink(path) < 0) { Log("Nuke: Failed to remove %s\n", path); } #else /* AFS_NAMEI_ENV */ - IH_INIT(fileH, (int) tstat.st_dev, avolid, - ti->inode[i]); - for(j=0;jcount[i];j++) { - code = IH_DEC(fileH, ti->inode[i], avolid); - } + IH_INIT(fileH, (int)tstat.st_dev, avolid, ti->inode[i]); + { + int j; + for (j = 0; j < ti->count[i]; j++) { + code = IH_DEC(fileH, ti->inode[i], avolid); + } + } IH_RELEASE(fileH); #endif /* AFS_NAMEI_ENV */ } ni = ti->next; free(ti); } - code = 0; /* we really don't care about it except for debugging */ - allInodes = (struct ilist *) 0; + code = 0; /* we really don't care about it except for debugging */ + allInodes = NULL; /* at this point, we should try to remove the volume header file itself. * the volume header file is the file named VNNNNN.vol in the UFS file @@ -205,22 +223,23 @@ afs_int32 avolid; { */ /* reuse devName buffer now */ #ifdef AFS_NT40_ENV - sprintf(devName, "%c:\\%s", *lastDevComp , VolumeExternalName(avolid)); + afs_snprintf(devName, sizeof devName, "%c:\\%s", *lastDevComp, + VolumeExternalName(avolid)); #else - sprintf(devName, "%s/%s", aname, VolumeExternalName(avolid)); + afs_snprintf(devName, sizeof devName, "%s/%s", aname, + VolumeExternalName(avolid)); #endif /* AFS_NT40_ENV */ code = unlink(devName); - if (code) code = errno; - } - else { + if (code) + code = errno; + } else { /* just free things */ - for(ti=allInodes; ti; ti = ni) { + for (ti = allInodes; ti; ti = ni) { ni = ti->next; free(ti); } - allInodes = (struct ilist *) 0; + allInodes = NULL; } ReleaseWriteLock(&localLock); return code; } - diff --git a/src/vol/partition.c b/src/vol/partition.c index 42669ae6f..fce55e972 100644 --- a/src/vol/partition.c +++ b/src/vol/partition.c @@ -20,7 +20,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/partition.c,v 1.14 2004/01/10 21:12:32 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/partition.c,v 1.29 2003/10/24 06:26:19 shadow Exp $"); #include #ifdef AFS_NT40_ENV @@ -30,8 +31,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/partition.c,v 1.14 2004/01/10 21:12 #else #include #include - -#if AFS_HAVE_STATVFS + +#if AFS_HAVE_STATVFS || AFS_HAVE_STATVFS64 #include #endif /* AFS_HAVE_STATVFS */ #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) @@ -42,7 +43,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/partition.c,v 1.14 2004/01/10 21:12 #ifdef AFS_OSF_ENV #include #include -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #ifdef AFS_VFSINCL_ENV #define VFS #ifdef AFS_SUN5_ENV @@ -60,7 +61,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/partition.c,v 1.14 2004/01/10 21:12 #include #endif #endif /* AFS_VFSINCL_ENV */ -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ #include #include #include @@ -95,7 +96,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/partition.c,v 1.14 2004/01/10 21:12 #endif #endif #endif -#endif /* AFS_SGI_ENV */ +#endif /* AFS_SGI_ENV */ #endif /* AFS_NT40_ENV */ #if defined(AFS_SGI_ENV) #include @@ -105,6 +106,14 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/partition.c,v 1.14 2004/01/10 21:12 #include #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include "nfs.h" @@ -118,11 +127,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/partition.c,v 1.14 2004/01/10 21:12 #include "ntops.h" #else #include "namei_ops.h" -#if defined(AFS_SGI_ENV) -#include -#else #include -#endif /* AFS_SGI_ENV */ #endif /* AFS_NT40_ENV */ #endif /* AFS_NAMEI_ENV */ #include "vnode.h" @@ -143,7 +148,45 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/partition.c,v 1.14 2004/01/10 21:12 #include #endif -int aixlow_water = 8; /* default 8% */ +#ifdef O_LARGEFILE + +#define afs_stat stat64 +#define afs_open open64 +#define afs_fopen fopen64 +#ifndef AFS_NT40_ENV +#if AFS_HAVE_STATVFS64 +# define afs_statvfs statvfs64 +#else +# if AFS_HAVE_STATFS64 +# define afs_statfs statfs64 +#else +# if AFS_HAVE_STATVFS +# define afs_statvfs statvfs +# else +# define afs_statfs statfs +# endif /* !AFS_HAVE_STATVFS */ +# endif /* !AFS_HAVE_STATFS64 */ +#endif /* !AFS_HAVE_STATVFS64 */ +#endif /* !AFS_NT40_ENV */ + +#else /* !O_LARGEFILE */ + +#define afs_stat stat +#define afs_open open +#define afs_fopen fopen +#ifndef AFS_NT40_ENV +#if AFS_HAVE_STATVFS +#define afs_statvfs statvfs +#else /* !AFS_HAVE_STATVFS */ +#define afs_statfs statfs +#endif /* !AFS_HAVE_STATVFS */ +#endif /* !AFS_NT40_ENV */ + +#endif /* !O_LARGEFILE */ + +/*@printflike@*/ extern void Log(const char *format, ...); + +int aixlow_water = 8; /* default 8% */ struct DiskPartition *DiskPartitionList; #ifdef AFS_SGI_XFS_IOPS_ENV @@ -153,7 +196,8 @@ struct DiskPartition *DiskPartitionList; * the XFS inode. */ #include -static int VerifyXFSInodeSize(char *part, char *fstype) +static int +VerifyXFSInodeSize(char *part, char *fstype) { afs_xfs_attr_t junk; int length = SIZEOF_XFS_ATTR_T; @@ -165,30 +209,30 @@ static int VerifyXFSInodeSize(char *part, char *fstype) return 0; if (attr_set(part, AFS_XFS_ATTR, &junk, length, ATTR_ROOT) == 0) { - if (((fd=open(part, O_RDONLY, 0)) != -1) + if (((fd = open(part, O_RDONLY, 0)) != -1) && (fcntl(fd, F_FSGETXATTRA, &fsx) == 0)) { - + if (fsx.fsx_nextents) { Log("Partition %s: XFS inodes too small, exiting.\n", part); Log("Run xfs_size_check utility and remake partitions.\n"); - } - else + } else code = 0; } if (fd > 0) close(fd); - (void) attr_remove(part, AFS_XFS_ATTR, ATTR_ROOT); + (void)attr_remove(part, AFS_XFS_ATTR, ATTR_ROOT); } return code; } #endif -static void VInitPartition_r(char *path, char *devname, Device dev) +static void +VInitPartition_r(char *path, char *devname, Device dev) { struct DiskPartition *dp, *op; - dp = (struct DiskPartition *) malloc(sizeof (struct DiskPartition)); + dp = (struct DiskPartition *)malloc(sizeof(struct DiskPartition)); /* Add it to the end, to preserve order when we print statistics */ for (op = DiskPartitionList; op; op = op->next) { if (!op->next) @@ -209,7 +253,7 @@ static void VInitPartition_r(char *path, char *devname, Device dev) strcat(dp->devName, "Lock"); mkdir(dp->devName, 0700); strcat(dp->devName, path); - close(open(dp->devName, O_RDWR | O_CREAT, 0600)); + close(afs_open(dp->devName, O_RDWR | O_CREAT, 0600)); dp->device = volutil_GetPartitionID(path); #else dp->devName = (char *)malloc(strlen(devname) + 1); @@ -218,20 +262,19 @@ static void VInitPartition_r(char *path, char *devname, Device dev) #endif dp->lock_fd = -1; dp->flags = 0; - dp->f_files = 1; /* just a default value */ + dp->f_files = 1; /* just a default value */ #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV) if (programType == fileServer) - (void) namei_ViceREADME(VPartitionPath(dp)); + (void)namei_ViceREADME(VPartitionPath(dp)); #endif VSetPartitionDiskUsage_r(dp); } -static void VInitPartition(char *path, char *devname, Device dev) +static void +VInitPartition(char *path, char *devname, Device dev) { - VOL_LOCK - VInitPartition_r(path, devname, dev); - VOL_UNLOCK -} + VOL_LOCK VInitPartition_r(path, devname, dev); +VOL_UNLOCK} #ifndef AFS_NT40_ENV /* VAttachPartitions() finds the vice partitions on this server. Calls @@ -248,11 +291,10 @@ static void VInitPartition(char *path, char *devname, Device dev) * * Use partition name as devname. */ -int VCheckPartition(part, devname) - char *part; - char *devname; +int +VCheckPartition(char *part, char *devname) { - struct stat status; + struct afs_stat status; #if !defined(AFS_LINUX20_ENV) && !defined(AFS_NT40_ENV) char AFSIDatPath[MAXPATHLEN]; #endif @@ -262,17 +304,16 @@ int VCheckPartition(part, devname) if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { return 0; } - if (stat(part, &status) < 0) { + if (afs_stat(part, &status) < 0) { Log("VInitVnodes: Couldn't find file system %s; ignored\n", part); return 0; } - #ifndef AFS_AIX32_ENV if (programType == fileServer) { char salvpath[MAXPATHLEN]; strcpy(salvpath, part); strcat(salvpath, "/FORCESALVAGE"); - if (stat(salvpath, &status) == 0) { + if (afs_stat(salvpath, &status) == 0) { Log("VInitVnodes: Found %s; aborting\n", salvpath); return -1; } @@ -283,7 +324,7 @@ int VCheckPartition(part, devname) strcpy(AFSIDatPath, part); strcat(AFSIDatPath, "/AFSIDat"); #ifdef AFS_NAMEI_ENV - if (stat(AFSIDatPath, &status) < 0) { + if (afs_stat(AFSIDatPath, &status) < 0) { DIR *dirp; struct dirent *dp; @@ -293,13 +334,13 @@ int VCheckPartition(part, devname) if (dp->d_name[0] == 'V') { Log("This program is compiled with AFS_NAMEI_ENV, but partition %s seems to contain volumes which don't use the namei-interface; aborting\n", part); closedir(dirp); - return -1; + return -1; } } closedir(dirp); } #else /* AFS_NAMEI_ENV */ - if (stat(AFSIDatPath, &status) == 0) { + if (afs_stat(AFSIDatPath, &status) == 0) { Log("This program is compiled without AFS_NAMEI_ENV, but partition %s seems to contain volumes which use the namei-interface; aborting\n", part); return -1; } @@ -312,7 +353,7 @@ int VCheckPartition(part, devname) #endif #if defined(AFS_DUX40_ENV) && !defined(AFS_NAMEI_ENV) - if (status.st_ino != ROOTINO) { + if (afs_status.st_ino != ROOTINO) { Log("%s is not a mounted file system; ignored.\n", part); return 0; } @@ -328,11 +369,11 @@ int VCheckPartition(part, devname) * mounted partition (return value 0). For non-NAMEI environments, it * always returns 0. */ -static int VIsAlwaysAttach(part) - char *part; +static int +VIsAlwaysAttach(char *part) { #ifdef AFS_NAMEI_ENV - struct stat st; + struct afs_stat st; char checkfile[256]; int ret; @@ -343,9 +384,9 @@ static int VIsAlwaysAttach(part) strcat(checkfile, "/"); strcat(checkfile, VICE_ALWAYSATTACH_FILE); - ret = stat(checkfile, &st); + ret = afs_stat(checkfile, &st); return (ret < 0) ? 0 : 1; -#else /* AFS_NAMEI_ENV */ +#else /* AFS_NAMEI_ENV */ return 0; #endif /* AFS_NAMEI_ENV */ } @@ -355,20 +396,22 @@ static int VIsAlwaysAttach(part) * used to attach /vicepX directories which aren't on dedicated * partitions, in the NAMEI fileserver. */ -void VAttachPartitions2() { +void +VAttachPartitions2() +{ #ifdef AFS_NAMEI_ENV DIR *dirp; struct dirent *de; char pname[32]; dirp = opendir("/"); - while (de = readdir(dirp)) { + while ((de = readdir(dirp))) { strcpy(pname, "/"); strncat(pname, de->d_name, 20); - pname[sizeof(pname)-1] = '\0'; + pname[sizeof(pname) - 1] = '\0'; /* Only keep track of "/vicepx" partitions since automounter - may hose us */ + * may hose us */ if (VIsAlwaysAttach(pname)) VCheckPartition(pname, ""); } @@ -378,60 +421,63 @@ void VAttachPartitions2() { #endif /* AFS_NT40_ENV */ #ifdef AFS_SUN5_ENV -int VAttachPartitions(void) +int +VAttachPartitions(void) { int errors = 0; struct mnttab mnt; FILE *mntfile; - if (!(mntfile = fopen(MNTTAB, "r"))) { + if (!(mntfile = afs_fopen(MNTTAB, "r"))) { Log("Can't open %s\n", MNTTAB); perror(MNTTAB); exit(-1); } while (!getmntent(mntfile, &mnt)) { /* Ignore non ufs or non read/write partitions */ - if ((strcmp(mnt.mnt_fstype, "ufs") !=0) || - (strncmp(mnt.mnt_mntopts, "ro,ignore",9) ==0)) - continue; + if ((strcmp(mnt.mnt_fstype, "ufs") != 0) + || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0)) + continue; /* If we're going to always attach this partition, do it later. */ if (VIsAlwaysAttach(mnt.mnt_mountp)) continue; - if (VCheckPartition(mnt.mnt_mountp, mnt.mnt_special) < 0 ) - errors ++; + if (VCheckPartition(mnt.mnt_mountp, mnt.mnt_special) < 0) + errors++; } - (void) fclose(mntfile); + (void)fclose(mntfile); /* Process the always-attach partitions, if any. */ VAttachPartitions2(); - return errors ; + return errors; } #endif /* AFS_SUN5_ENV */ #if defined(AFS_SGI_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_HPUX_ENV) -int VAttachPartitions(void) +int +VAttachPartitions(void) { int errors = 0; FILE *mfd; struct mntent *mntent; - + if ((mfd = setmntent(MOUNTED, "r")) == NULL) { Log("Problems in getting mount entries(setmntent)\n"); exit(-1); } while (mntent = getmntent(mfd)) { - if (!hasmntopt(mntent, MNTOPT_RW)) continue; - + if (!hasmntopt(mntent, MNTOPT_RW)) + continue; + /* If we're going to always attach this partition, do it later. */ if (VIsAlwaysAttach(mntent->mnt_dir)) continue; - if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname) < 0 ) - errors ++; + if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname) < 0) + errors++; } endmntent(mfd); @@ -439,7 +485,7 @@ int VAttachPartitions(void) /* Process the always-attach partitions, if any. */ VAttachPartitions2(); - return errors ; + return errors; } #endif #ifdef AFS_AIX_ENV @@ -447,65 +493,66 @@ int VAttachPartitions(void) * (This function was grabbed from df.c) */ int -getmount(vmountpp) -register struct vmount **vmountpp; /* place to tell where buffer is */ +getmount(register struct vmount **vmountpp) { - int size; - register struct vmount *vm; - int nmounts; - - /* set initial size of mntctl buffer to a MAGIC NUMBER */ - size = BUFSIZ; - - /* try the operation until ok or a fatal error */ - while (1) { - if ((vm = (struct vmount *)malloc(size)) == NULL) { - /* failed getting memory for mount status buf */ - perror("FATAL ERROR: get_stat malloc failed\n"); - exit(-1); - } - - /* - * perform the QUERY mntctl - if it returns > 0, that is the - * number of vmount structures in the buffer. If it returns - * -1, an error occured. If it returned 0, then look in - * first word of buffer for needed size. - */ - if ((nmounts = mntctl(MCTL_QUERY, size, (caddr_t)vm)) > 0) { - /* OK, got it, now return */ - *vmountpp = vm; - return(nmounts); - - } else if (nmounts == 0) { - /* the buffer wasn't big enough .... */ - /* .... get required buffer size */ - size = *(int *)vm; - free(vm); - - } else { - /* some other kind of error occurred */ - free(vm); - return(-1); - } + int size; + register struct vmount *vm; + int nmounts; + + /* set initial size of mntctl buffer to a MAGIC NUMBER */ + size = BUFSIZ; + + /* try the operation until ok or a fatal error */ + while (1) { + if ((vm = (struct vmount *)malloc(size)) == NULL) { + /* failed getting memory for mount status buf */ + perror("FATAL ERROR: get_stat malloc failed\n"); + exit(-1); + } + + /* + * perform the QUERY mntctl - if it returns > 0, that is the + * number of vmount structures in the buffer. If it returns + * -1, an error occured. If it returned 0, then look in + * first word of buffer for needed size. + */ + if ((nmounts = mntctl(MCTL_QUERY, size, (caddr_t) vm)) > 0) { + /* OK, got it, now return */ + *vmountpp = vm; + return (nmounts); + + } else if (nmounts == 0) { + /* the buffer wasn't big enough .... */ + /* .... get required buffer size */ + size = *(int *)vm; + free(vm); + + } else { + /* some other kind of error occurred */ + free(vm); + return (-1); } + } } -int VAttachPartitions(void) +int +VAttachPartitions(void) { int errors = 0; int nmounts; struct vmount *vmountp; - if ((nmounts = getmount(&vmountp)) <= 0) { + if ((nmounts = getmount(&vmountp)) <= 0) { Log("Problems in getting # of mount entries(getmount)\n"); exit(-1); } - for (; nmounts; nmounts--, - vmountp = (struct vmount *)((int)vmountp + vmountp->vmt_length)) { + for (; nmounts; + nmounts--, vmountp = + (struct vmount *)((int)vmountp + vmountp->vmt_length)) { char *part = vmt2dataptr(vmountp, VMT_STUB); - if (vmountp->vmt_flags & (MNT_READONLY|MNT_REMOVABLE|MNT_REMOTE)) - continue; /* Ignore any "special" partitions */ + if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE)) + continue; /* Ignore any "special" partitions */ #ifdef AFS_AIX42_ENV #ifndef AFS_NAMEI_ENV @@ -514,7 +561,7 @@ int VAttachPartitions(void) /* The Log statements are non-sequiters in the SalvageLog and don't * even appear in the VolserLog, so restrict them to the FileLog. */ - if (ReadSuper(&fs, vmt2dataptr(vmountp, VMT_OBJECT))<0) { + if (ReadSuper(&fs, vmt2dataptr(vmountp, VMT_OBJECT)) < 0) { if (programType == fileServer) Log("Can't read superblock for %s, ignoring it.\n", part); continue; @@ -532,18 +579,19 @@ int VAttachPartitions(void) if (VIsAlwaysAttach(part)) continue; - if (VCheckPartition(part, vmt2dataptr(vmountp, VMT_OBJECT)) < 0 ) - errors ++; + if (VCheckPartition(part, vmt2dataptr(vmountp, VMT_OBJECT)) < 0) + errors++; } /* Process the always-attach partitions, if any. */ VAttachPartitions2(); - return errors ; + return errors; } #endif #if defined(AFS_DUX40_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) -int VAttachPartitions(void) +int +VAttachPartitions(void) { int errors = 0; struct fstab *fsent; @@ -554,21 +602,22 @@ int VAttachPartitions(void) } while (fsent = getfsent()) { - if (strcmp(fsent->fs_type, "rw") != 0) continue; + if (strcmp(fsent->fs_type, "rw") != 0) + continue; /* If we're going to always attach this partition, do it later. */ if (VIsAlwaysAttach(fsent->fs_file)) continue; - if (VCheckPartition(fsent->fs_file, fsent->fs_spec) < 0 ) - errors ++; + if (VCheckPartition(fsent->fs_file, fsent->fs_spec) < 0) + errors++; } endfsent(); - + /* Process the always-attach partitions, if any. */ VAttachPartitions2(); - return errors ; + return errors; } #endif @@ -584,17 +633,18 @@ int VAttachPartitions(void) * 0 invalid entry */ -int VValidVPTEntry(struct vptab *vpe) +int +VValidVPTEntry(struct vptab *vpe) { int len = strlen(vpe->vp_name); int i; - if (len < VICE_PREFIX_SIZE+1 || len > VICE_PREFIX_SIZE + 2) + if (len < VICE_PREFIX_SIZE + 1 || len > VICE_PREFIX_SIZE + 2) return 0; if (strncmp(vpe->vp_name, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) return 0; - - for (i=VICE_PREFIX_SIZE; ivp_name[i] < 'a' || vpe->vp_name[i] > 'z') { Log("Invalid partition name %s in registry, ignoring it.\n", vpe->vp_name); @@ -602,9 +652,9 @@ int VValidVPTEntry(struct vptab *vpe) } } if (len == VICE_PREFIX_SIZE + 2) { - i = (int)(vpe->vp_name[VICE_PREFIX_SIZE]-'a') * 26 + - (int)(vpe->vp_name[VICE_PREFIX_SIZE+1]-'a') ; - if (i>255) { + i = (int)(vpe->vp_name[VICE_PREFIX_SIZE] - 'a') * 26 + + (int)(vpe->vp_name[VICE_PREFIX_SIZE + 1] - 'a'); + if (i > 255) { Log("Invalid partition name %s in registry, ignoring it.\n", vpe->vp_name); return 0; @@ -612,8 +662,8 @@ int VValidVPTEntry(struct vptab *vpe) } len = strlen(vpe->vp_dev); - if (len != 2 || vpe->vp_dev[1] != ':' || vpe->vp_dev[0] < 'A' || - vpe->vp_dev[0] > 'Z') { + if (len != 2 || vpe->vp_dev[1] != ':' || vpe->vp_dev[0] < 'A' + || vpe->vp_dev[0] > 'Z') { Log("Invalid device name %s in registry, ignoring it.\n", vpe->vp_dev); return 0; @@ -622,7 +672,8 @@ int VValidVPTEntry(struct vptab *vpe) return 1; } -int VCheckPartition(char *partName) +int +VCheckPartition(char *partName) { char volRoot[4]; char volFsType[64]; @@ -630,19 +681,18 @@ int VCheckPartition(char *partName) int err; /* partName is presumed to be of the form "X:" */ - (void) sprintf(volRoot, "%c:\\", *partName); - - if (!GetVolumeInformation(volRoot, /* volume root directory */ - NULL, /* volume name buffer */ - 0, /* volume name size */ - NULL, /* volume serial number */ - &dwDummy, /* max component length */ - &dwDummy, /* file system flags */ - volFsType, /* file system name */ + (void)sprintf(volRoot, "%c:\\", *partName); + + if (!GetVolumeInformation(volRoot, /* volume root directory */ + NULL, /* volume name buffer */ + 0, /* volume name size */ + NULL, /* volume serial number */ + &dwDummy, /* max component length */ + &dwDummy, /* file system flags */ + volFsType, /* file system name */ sizeof(volFsType))) { err = GetLastError(); - Log("VCheckPartition: Failed to get partition information for %s, ignoring it.\n", - partName); + Log("VCheckPartition: Failed to get partition information for %s, ignoring it.\n", partName); return -1; } @@ -655,18 +705,19 @@ int VCheckPartition(char *partName) } -int VAttachPartitions(void) +int +VAttachPartitions(void) { struct DiskPartition *partP, *prevP, *nextP; struct vpt_iter iter; struct vptab entry; - if (vpt_Start(&iter)<0) { + if (vpt_Start(&iter) < 0) { Log("No partitions to attach.\n"); return 0; } - while (0==vpt_NextEntry(&iter, &entry)) { + while (0 == vpt_NextEntry(&iter, &entry)) { if (!VValidVPTEntry(&entry)) { continue; } @@ -679,23 +730,24 @@ int VAttachPartitions(void) if (*partP->devName == *entry.vp_dev) { Log("Same drive (%s) used for both partition %s and partition %s, ignoring both.\n", entry.vp_dev, partP->name, entry.vp_name); partP->flags = PART_DUPLICATE; - break; /* Only one entry will ever be in this list. */ + break; /* Only one entry will ever be in this list. */ } } - if (partP) continue; /* found a duplicate */ + if (partP) + continue; /* found a duplicate */ - if (VCheckPartition(entry.vp_dev)<0) + if (VCheckPartition(entry.vp_dev) < 0) continue; /* This test allows for manually inserting the FORCESALVAGE flag * and thereby invoking the salvager. scandisk obviously won't be * doing this for us. */ if (programType == fileServer) { - struct stat status; + struct afs_stat status; char salvpath[MAXPATHLEN]; strcpy(salvpath, entry.vp_dev); strcat(salvpath, "\\FORCESALVAGE"); - if (stat(salvpath, &status) == 0) { + if (afs_stat(salvpath, &status) == 0) { Log("VAttachPartitions: Found %s; aborting\n", salvpath); exit(1); } @@ -714,8 +766,7 @@ int VAttachPartitions(void) else DiskPartitionList = partP->next; free(partP); - } - else + } else prevP = partP; } @@ -724,49 +775,52 @@ int VAttachPartitions(void) #endif #ifdef AFS_LINUX22_ENV -int VAttachPartitions(void) +int +VAttachPartitions(void) { int errors = 0; FILE *mfd; struct mntent *mntent; - + if ((mfd = setmntent("/proc/mounts", "r")) == NULL) { if ((mfd = setmntent("/etc/mtab", "r")) == NULL) { Log("Problems in getting mount entries(setmntent)\n"); exit(-1); } } - while (mntent = getmntent(mfd)) { + while ((mntent = getmntent(mfd))) { /* If we're going to always attach this partition, do it later. */ if (VIsAlwaysAttach(mntent->mnt_dir)) continue; - if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname) < 0 ) - errors ++; + if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname) < 0) + errors++; } endmntent(mfd); /* Process the always-attach partitions, if any. */ VAttachPartitions2(); - return errors ; + return errors; } #endif /* AFS_LINUX22_ENV */ /* This routine is to be called whenever the actual name of the partition * is required. The canonical name is still in part->name. */ -char * VPartitionPath(struct DiskPartition *part) +char * +VPartitionPath(struct DiskPartition *part) { #ifdef AFS_NT40_ENV return part->devName; #else return part->name; -#endif +#endif } /* get partition structure, abortp tells us if we should abort on failure */ -struct DiskPartition *VGetPartition_r(char *name, int abortp) +struct DiskPartition * +VGetPartition_r(char *name, int abortp) { register struct DiskPartition *dp; for (dp = DiskPartitionList; dp; dp = dp->next) { @@ -778,111 +832,112 @@ struct DiskPartition *VGetPartition_r(char *name, int abortp) return dp; } -struct DiskPartition *VGetPartition(char *name, int abortp) +struct DiskPartition * +VGetPartition(char *name, int abortp) { struct DiskPartition *retVal; - VOL_LOCK - retVal = VGetPartition_r(name, abortp); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VGetPartition_r(name, abortp); + VOL_UNLOCK return retVal; } #ifdef AFS_NT40_ENV -void VSetPartitionDiskUsage_r(register struct DiskPartition *dp) +void +VSetPartitionDiskUsage_r(register struct DiskPartition *dp) { ULARGE_INTEGER free_user, total, free_total; int ufree, tot, tfree; - - if (!GetDiskFreeSpaceEx(VPartitionPath(dp), &free_user, &total, - &free_total)) { - printf("Failed to get disk space info for %s, error = %d\n", - dp->name, GetLastError()); + + if (!GetDiskFreeSpaceEx + (VPartitionPath(dp), &free_user, &total, &free_total)) { + printf("Failed to get disk space info for %s, error = %d\n", dp->name, + GetLastError()); return; } /* Convert to 1K units. */ - ufree = (int) Int64ShraMod32(free_user.QuadPart, 10); - tot = (int) Int64ShraMod32(total.QuadPart, 10); - tfree = (int) Int64ShraMod32(free_total.QuadPart, 10); + ufree = (int)Int64ShraMod32(free_user.QuadPart, 10); + tot = (int)Int64ShraMod32(total.QuadPart, 10); + tfree = (int)Int64ShraMod32(free_total.QuadPart, 10); - dp->minFree = tfree - ufree; /* only used in VPrintDiskStats_r */ + dp->minFree = tfree - ufree; /* only used in VPrintDiskStats_r */ dp->totalUsable = tot; dp->free = tfree; } #else -void VSetPartitionDiskUsage_r(register struct DiskPartition *dp) +void +VSetPartitionDiskUsage_r(register struct DiskPartition *dp) { int fd, totalblks, free, used, availblks, bsize, code; int reserved; -#if AFS_HAVE_STATVFS - struct statvfs statbuf; +#ifdef afs_statvfs + struct afs_statvfs statbuf; #else - struct statfs statbuf; + struct afs_statfs statbuf; #endif if (dp->flags & PART_DONTUPDATE) return; /* Note: we don't bother syncing because it's only an estimate, update - is syncing every 30 seconds anyway, we only have to keep the disk - approximately 10% from full--you just can't get the stuff in from - the net fast enough to worry */ -#if AFS_HAVE_STATVFS - code = statvfs(dp->name, &statbuf); + * is syncing every 30 seconds anyway, we only have to keep the disk + * approximately 10% from full--you just can't get the stuff in from + * the net fast enough to worry */ +#ifdef afs_statvfs + code = afs_statvfs(dp->name, &statbuf); #else - code = statfs(dp->name, &statbuf); + code = afs_statfs(dp->name, &statbuf); #endif if (code < 0) { - Log("statfs of %s failed in VSetPartitionDiskUsage (errno = %d)\n", dp->name, errno); + Log("statfs of %s failed in VSetPartitionDiskUsage (errno = %d)\n", + dp->name, errno); return; } - if (statbuf.f_blocks == -1) { /* Undefined; skip stats.. */ + if (statbuf.f_blocks == -1) { /* Undefined; skip stats.. */ Log("statfs of %s failed in VSetPartitionDiskUsage\n", dp->name); return; } totalblks = statbuf.f_blocks; free = statbuf.f_bfree; reserved = free - statbuf.f_bavail; -#if AFS_HAVE_STATVFS +#ifdef afs_statvfs bsize = statbuf.f_frsize; #else bsize = statbuf.f_bsize; #endif availblks = totalblks - reserved; - dp->f_files = statbuf.f_files; /* max # of files in partition */ + dp->f_files = statbuf.f_files; /* max # of files in partition */ /* Now free and totalblks are in fragment units, but we want them in * 1K units. */ if (bsize >= 1024) { - free *= (bsize/1024); + free *= (bsize / 1024); totalblks *= (bsize / 1024); - availblks *= (bsize / 1024 ); - reserved *= (bsize / 1024 ); - } - else { - free /= (1024/bsize); - totalblks /= (1024/bsize); - availblks /= (1024/bsize); - reserved /= (1024/bsize); + availblks *= (bsize / 1024); + reserved *= (bsize / 1024); + } else { + free /= (1024 / bsize); + totalblks /= (1024 / bsize); + availblks /= (1024 / bsize); + reserved /= (1024 / bsize); } /* now compute remaining figures */ used = totalblks - free; - dp->minFree = reserved; /* only used in VPrintDiskStats_r */ + dp->minFree = reserved; /* only used in VPrintDiskStats_r */ dp->totalUsable = availblks; - dp->free = availblks - used; /* this is exactly f_bavail */ + dp->free = availblks - used; /* this is exactly f_bavail */ } #endif /* AFS_NT40_ENV */ -void VSetPartitionDiskUsage(register struct DiskPartition *dp) +void +VSetPartitionDiskUsage(register struct DiskPartition *dp) { - VOL_LOCK - VSetPartitionDiskUsage_r(dp); - VOL_UNLOCK -} + VOL_LOCK VSetPartitionDiskUsage_r(dp); +VOL_UNLOCK} -void VResetDiskUsage_r(void) +void +VResetDiskUsage_r(void) { struct DiskPartition *dp; for (dp = DiskPartitionList; dp; dp = dp->next) { @@ -893,76 +948,84 @@ void VResetDiskUsage_r(void) } } -void VResetDiskUsage(void) +void +VResetDiskUsage(void) { - VOL_LOCK - VResetDiskUsage_r(); - VOL_UNLOCK -} + VOL_LOCK VResetDiskUsage_r(); +VOL_UNLOCK} -void VAdjustDiskUsage_r(Error *ec, Volume *vp, afs_int32 blocks, afs_int32 checkBlocks) +void +VAdjustDiskUsage_r(Error * ec, Volume * vp, afs_sfsize_t blocks, + afs_sfsize_t checkBlocks) { *ec = 0; /* why blocks instead of checkBlocks in the check below? Otherwise, any check - for less than BlocksSpare would skip the error-checking path, and we - could grow existing files forever, not just for another BlocksSpare - blocks. */ + * for less than BlocksSpare would skip the error-checking path, and we + * could grow existing files forever, not just for another BlocksSpare + * blocks. */ if (blocks > 0) { #ifdef AFS_AIX32_ENV - afs_int32 rem, minavail; + afs_int32 rem, minavail; - if ((rem = vp->partition->free - checkBlocks) < - (minavail = (vp->partition->totalUsable * aixlow_water) / 100)) + if ((rem = vp->partition->free - checkBlocks) < (minavail = + (vp->partition-> + totalUsable * + aixlow_water) / + 100)) #else if (vp->partition->free - checkBlocks < 0) #endif *ec = VDISKFULL; - else if (V_maxquota(vp) && V_diskused(vp) + checkBlocks > V_maxquota(vp)) + else if (V_maxquota(vp) + && V_diskused(vp) + checkBlocks > V_maxquota(vp)) *ec = VOVERQUOTA; - } + } vp->partition->free -= blocks; V_diskused(vp) += blocks; } -void VAdjustDiskUsage(Error *ec, Volume *vp, afs_int32 blocks, afs_int32 checkBlocks) +void +VAdjustDiskUsage(Error * ec, Volume * vp, afs_sfsize_t blocks, + afs_sfsize_t checkBlocks) { - VOL_LOCK - VAdjustDiskUsage_r(ec, vp, blocks, checkBlocks); - VOL_UNLOCK -} + VOL_LOCK VAdjustDiskUsage_r(ec, vp, blocks, checkBlocks); +VOL_UNLOCK} -int VDiskUsage_r(Volume *vp, afs_int32 blocks) +int +VDiskUsage_r(Volume * vp, afs_sfsize_t blocks) { if (blocks > 0) { #ifdef AFS_AIX32_ENV - afs_int32 rem, minavail; + afs_int32 rem, minavail; - if ((rem = vp->partition->free - blocks) < - (minavail = (vp->partition->totalUsable * aixlow_water) / 100)) + if ((rem = vp->partition->free - blocks) < (minavail = + (vp->partition-> + totalUsable * + aixlow_water) / 100)) #else if (vp->partition->free - blocks < 0) #endif - return(VDISKFULL); - } + return (VDISKFULL); + } vp->partition->free -= blocks; return 0; } -int VDiskUsage(Volume *vp, afs_int32 blocks) +int +VDiskUsage(Volume * vp, afs_sfsize_t blocks) { int retVal; - VOL_LOCK - retVal = VDiskUsage_r(vp, blocks); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VDiskUsage_r(vp, blocks); + VOL_UNLOCK return retVal; } -void VPrintDiskStats_r(void) +void +VPrintDiskStats_r(void) { struct DiskPartition *dp; for (dp = DiskPartitionList; dp; dp = dp->next) { - Log("Partition %s: %d available 1K blocks (minfree=%d), ", - dp->name, dp->totalUsable, dp->minFree); + Log("Partition %s: %d available 1K blocks (minfree=%d), ", dp->name, + dp->totalUsable, dp->minFree); if (dp->free < 0) Log("overallocated by %d blocks\n", -dp->free); else @@ -970,48 +1033,52 @@ void VPrintDiskStats_r(void) } } -void VPrintDiskStats(void) +void +VPrintDiskStats(void) { - VOL_LOCK - VPrintDiskStats_r(); - VOL_UNLOCK -} + VOL_LOCK VPrintDiskStats_r(); +VOL_UNLOCK} #ifdef AFS_NT40_ENV /* Need a separate lock file on NT, since NT only has mandatory file locks. */ #define LOCKFILE "LOCKFILE" -void VLockPartition_r(char *name) +void +VLockPartition_r(char *name) { struct DiskPartition *dp = VGetPartition_r(name, 0); OVERLAPPED lap; - - if (!dp) return; + + if (!dp) + return; if (dp->lock_fd == -1) { char path[64]; int rc; - (void) sprintf(path, "%s\\%s", VPartitionPath(dp), LOCKFILE); - dp->lock_fd = (int)CreateFile(path, GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, - CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); - assert (dp->lock_fd != (int)INVALID_HANDLE_VALUE); - - memset((char*)&lap, 0, sizeof(lap)); - rc = LockFileEx((HANDLE)dp->lock_fd, LOCKFILE_EXCLUSIVE_LOCK, - 0, 1, 0, &lap); + (void)sprintf(path, "%s\\%s", VPartitionPath(dp), LOCKFILE); + dp->lock_fd = + (int)CreateFile(path, GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); + assert(dp->lock_fd != (int)INVALID_HANDLE_VALUE); + + memset((char *)&lap, 0, sizeof(lap)); + rc = LockFileEx((HANDLE) dp->lock_fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, + 0, &lap); assert(rc); } } -void VUnlockPartition_r(char *name) +void +VUnlockPartition_r(char *name) { register struct DiskPartition *dp = VGetPartition_r(name, 0); OVERLAPPED lap; - if (!dp) return; /* no partition, will fail later */ - memset((char*)&lap, 0, sizeof(lap)); + if (!dp) + return; /* no partition, will fail later */ + memset((char *)&lap, 0, sizeof(lap)); - UnlockFileEx((HANDLE)dp->lock_fd, 0, 1, 0, &lap); - CloseHandle((HANDLE)dp->lock_fd); + UnlockFileEx((HANDLE) dp->lock_fd, 0, 1, 0, &lap); + CloseHandle((HANDLE) dp->lock_fd); dp->lock_fd = -1; } #else /* AFS_NT40_ENV */ @@ -1023,27 +1090,40 @@ void VUnlockPartition_r(char *name) #define LOCKRDONLY_OFFSET ((PRIV_LOCKRDONLY - 1) / BITS(int)) #endif /* defined(AFS_HPUX_ENV) */ -void VLockPartition_r(char *name) +void +VLockPartition_r(char *name) { register struct DiskPartition *dp = VGetPartition_r(name, 0); char *partitionName; int retries, code; struct timeval pausing; #if defined(AFS_HPUX_ENV) - int lockfRtn; - struct privgrp_map privGrpList[PRIV_MAXGRPS]; - unsigned int *globalMask; - int globalMaskIndex; + int lockfRtn; + struct privgrp_map privGrpList[PRIV_MAXGRPS]; + unsigned int *globalMask; + int globalMaskIndex; #endif /* defined(AFS_HPUX_ENV) */ #if defined(AFS_DARWIN_ENV) char lockfile[MAXPATHLEN]; #endif /* defined(AFS_DARWIN_ENV) */ - - if (!dp) return; /* no partition, will fail later */ - if (dp->lock_fd != -1) return; +#ifdef AFS_NAMEI_ENV +#ifdef AFS_AIX42_ENV + char LockFileName[MAXPATHLEN + 1]; + + sprintf((char *)&LockFileName, "%s/AFSINODE_FSLock", name); + partitionName = (char *)&LockFileName; +#endif +#endif + + if (!dp) + return; /* no partition, will fail later */ + if (dp->lock_fd != -1) + return; #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) +#if !defined(AFS_AIX42_ENV) || !defined(AFS_NAMEI_ENV) partitionName = dp->devName; +#endif code = O_RDWR; #elif defined(AFS_DARWIN_ENV) strlcpy((partitionName = lockfile), dp->name, sizeof(lockfile)); @@ -1054,87 +1134,85 @@ void VLockPartition_r(char *name) code = O_RDONLY; #endif - for (retries=25; retries; retries--) { -#if defined(AFS_DARWIN_ENV) - dp->lock_fd = open(partitionName, code, 0600); -#else /* ! defined(AFS_DARWIN_ENV) */ - dp->lock_fd = open(partitionName, code); -#endif /* defined(AFS_DARWIN_ENV) */ - if (dp->lock_fd != -1) break; - pausing.tv_sec = 0; - pausing.tv_usec = 500000; - select(0, NULL, NULL, NULL, &pausing); + for (retries = 25; retries; retries--) { + dp->lock_fd = afs_open(partitionName, code); + if (dp->lock_fd != -1) + break; + if (errno == ENOENT) + code |= O_CREAT; + pausing.tv_sec = 0; + pausing.tv_usec = 500000; + select(0, NULL, NULL, NULL, &pausing); } assert(retries != 0); #if defined (AFS_HPUX_ENV) - assert(getprivgrp(privGrpList) == 0); + assert(getprivgrp(privGrpList) == 0); - /* - * In general, it will difficult and time-consuming ,if not impossible, - * to try to find the privgroup to which this process belongs that has the - * smallest membership, to minimise the security hole. So, we use the privgrp - * to which everybody belongs. - */ - /* first, we have to find the global mask */ - for (globalMaskIndex = 0; globalMaskIndex < PRIV_MAXGRPS; - globalMaskIndex++) { - if (privGrpList[globalMaskIndex].priv_groupno == PRIV_GLOBAL) { - globalMask = &(privGrpList[globalMaskIndex]. - priv_mask[LOCKRDONLY_OFFSET]); + /* + * In general, it will difficult and time-consuming ,if not impossible, + * to try to find the privgroup to which this process belongs that has the + * smallest membership, to minimise the security hole. So, we use the privgrp + * to which everybody belongs. + */ + /* first, we have to find the global mask */ + for (globalMaskIndex = 0; globalMaskIndex < PRIV_MAXGRPS; + globalMaskIndex++) { + if (privGrpList[globalMaskIndex].priv_groupno == PRIV_GLOBAL) { + globalMask = + &(privGrpList[globalMaskIndex].priv_mask[LOCKRDONLY_OFFSET]); break; - } } + } - if (((*globalMask) & privmask(PRIV_LOCKRDONLY)) == 0) { - /* allow everybody to set a lock on a read-only file descriptor */ - (*globalMask) |= privmask(PRIV_LOCKRDONLY); - assert(setprivgrp(PRIV_GLOBAL, - privGrpList[globalMaskIndex].priv_mask) == 0); - - lockfRtn = lockf(dp->lock_fd, F_LOCK, 0); + if (((*globalMask) & privmask(PRIV_LOCKRDONLY)) == 0) { + /* allow everybody to set a lock on a read-only file descriptor */ + (*globalMask) |= privmask(PRIV_LOCKRDONLY); + assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask) + == 0); + + lockfRtn = lockf(dp->lock_fd, F_LOCK, 0); + + /* remove the privilege granted to everybody to lock a read-only fd */ + (*globalMask) &= ~(privmask(PRIV_LOCKRDONLY)); + assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask) + == 0); + } else { + /* in this case, we should be able to do this with impunity, anyway */ + lockfRtn = lockf(dp->lock_fd, F_LOCK, 0); + } - /* remove the privilege granted to everybody to lock a read-only fd */ - (*globalMask) &= ~(privmask(PRIV_LOCKRDONLY)); - assert(setprivgrp(PRIV_GLOBAL, - privGrpList[globalMaskIndex].priv_mask) == 0); - } - else { - /* in this case, we should be able to do this with impunity, anyway */ - lockfRtn = lockf(dp->lock_fd, F_LOCK, 0); - } - - assert (lockfRtn != -1); + assert(lockfRtn != -1); #else #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) - assert (lockf(dp->lock_fd, F_LOCK, 0) != -1); + assert(lockf(dp->lock_fd, F_LOCK, 0) != -1); #else - assert (flock(dp->lock_fd, LOCK_EX) == 0); -#endif /* defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) */ + assert(flock(dp->lock_fd, LOCK_EX) == 0); +#endif /* defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) */ #endif } -void VUnlockPartition_r(char *name) +void +VUnlockPartition_r(char *name) { register struct DiskPartition *dp = VGetPartition_r(name, 0); - if (!dp) return; /* no partition, will fail later */ + if (!dp) + return; /* no partition, will fail later */ close(dp->lock_fd); dp->lock_fd = -1; } #endif /* AFS_NT40_ENV */ -void VLockPartition(char *name) +void +VLockPartition(char *name) { - VOL_LOCK - VLockPartition_r(name); - VOL_UNLOCK -} + VOL_LOCK VLockPartition_r(name); +VOL_UNLOCK} -void VUnlockPartition(char *name) +void +VUnlockPartition(char *name) { - VOL_LOCK - VUnlockPartition_r(name); - VOL_UNLOCK -} + VOL_LOCK VUnlockPartition_r(name); +VOL_UNLOCK} diff --git a/src/vol/partition.h b/src/vol/partition.h index e471dea54..547ec94c1 100644 --- a/src/vol/partition.h +++ b/src/vol/partition.h @@ -50,39 +50,39 @@ */ struct DiskPartition { struct DiskPartition *next; - char *name; /* Mounted partition name */ - char *devName; /* Device mounted on */ - Device device; /* device number */ - int lock_fd; /* File descriptor of this partition if locked; otherwise -1; - Not used by the file server */ - int free; /* Total number of blocks (1K) presumed - available on this partition (accounting - for the minfree parameter for the - partition). This is adjusted - approximately by the sizes of files - and directories read/written, and - periodically the superblock is read and - this is recomputed. This number can - be negative, if the partition starts - out too full */ - int totalUsable; /* Total number of blocks available on this - partition, taking into account the minfree - parameter for the partition (see the - 4.2bsd command tunefs, but note that the - bug mentioned there--that the superblock - is not reread--does not apply here. The - superblock is re-read periodically by - VSetPartitionDiskUsage().) */ - int minFree; /* Number blocks to be kept free, as last read - from the superblock */ - int flags; - int f_files; /* total number of files in this partition */ + char *name; /* Mounted partition name */ + char *devName; /* Device mounted on */ + Device device; /* device number */ + int lock_fd; /* File descriptor of this partition if locked; otherwise -1; + * Not used by the file server */ + int free; /* Total number of blocks (1K) presumed + * available on this partition (accounting + * for the minfree parameter for the + * partition). This is adjusted + * approximately by the sizes of files + * and directories read/written, and + * periodically the superblock is read and + * this is recomputed. This number can + * be negative, if the partition starts + * out too full */ + int totalUsable; /* Total number of blocks available on this + * partition, taking into account the minfree + * parameter for the partition (see the + * 4.2bsd command tunefs, but note that the + * bug mentioned there--that the superblock + * is not reread--does not apply here. The + * superblock is re-read periodically by + * VSetPartitionDiskUsage().) */ + int minFree; /* Number blocks to be kept free, as last read + * from the superblock */ + int flags; + int f_files; /* total number of files in this partition */ }; #define PART_DONTUPDATE 1 -#define PART_DUPLICATE 2 /* NT - used if we find more than one partition - * using the same drive. Will be dumped before - * all partitions attached. - */ +#define PART_DUPLICATE 2 /* NT - used if we find more than one partition + * using the same drive. Will be dumped before + * all partitions attached. + */ #ifdef AFS_NT40_ENV #include @@ -90,6 +90,8 @@ extern int VValidVPTEntry(struct vptab *vptp); #endif +struct Volume; /* Potentially forward definition */ + extern struct DiskPartition *DiskPartitionList; extern struct DiskPartition *VGetPartition(); extern int VAttachPartitions(void); @@ -102,7 +104,7 @@ extern void VResetDiskUsage_r(void); extern void VSetPartitionDiskUsage(register struct DiskPartition *dp); extern void VSetPartitionDiskUsage_r(register struct DiskPartition *dp); extern char *VPartitionPath(struct DiskPartition *p); -/*extern void VAdjustDiskUsage(Error *ec, Volume *vp, afs_int32 blocks, - afs_int32 checkBlocks); */ +extern void VAdjustDiskUsage(Error * ec, struct Volume *vp, + afs_sfsize_t blocks, afs_sfsize_t checkBlocks); +extern int VDiskUsage(struct Volume *vp, afs_sfsize_t blocks); extern void VPrintDiskStats(void); - diff --git a/src/vol/physio.c b/src/vol/physio.c index 18868e8d2..9db617b03 100644 --- a/src/vol/physio.c +++ b/src/vol/physio.c @@ -17,7 +17,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/physio.c,v 1.1.1.5 2001/09/11 14:35:45 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/physio.c,v 1.12 2003/08/08 20:40:45 shadow Exp $"); #include #include @@ -27,6 +28,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/physio.c,v 1.1.1.5 2001/09/11 14:35 #else #include #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #ifdef AFS_SUN5_ENV #include #endif @@ -35,17 +43,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/physio.c,v 1.1.1.5 2001/09/11 14:35 #include #include #include -#include "ihandle.h" #include "nfs.h" +#include "ihandle.h" #include "salvage.h" #include "afs/assert.h" #include "afs/dir.h" /* returns 0 on success, errno on failure */ -int ReallyRead (file, block, data) -DirHandle * file; -int block; -char * data; +int +ReallyRead(DirHandle * file, int block, char *data) { FdHandle_t *fdP; int code; @@ -55,16 +61,16 @@ char * data; code = errno; return code; } - if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) { + if (FDH_SEEK(fdP, block * AFS_PAGESIZE, SEEK_SET) < 0) { code = errno; FDH_REALLYCLOSE(fdP); return code; } - code = FDH_READ(fdP, data, AFS_PAGESIZE); + code = FDH_READ(fdP, data, (afs_fsize_t) AFS_PAGESIZE); if (code != AFS_PAGESIZE) { if (code < 0) code = errno; - else + else code = EIO; FDH_REALLYCLOSE(fdP); return code; @@ -74,10 +80,8 @@ char * data; } /* returns 0 on success, errno on failure */ -int ReallyWrite (file, block, data) -DirHandle * file; -int block; -char * data; +int +ReallyWrite(DirHandle * file, int block, char *data) { FdHandle_t *fdP; extern int VolumeChanged; @@ -90,16 +94,16 @@ char * data; code = errno; return code; } - if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) { + if (FDH_SEEK(fdP, block * AFS_PAGESIZE, SEEK_SET) < 0) { code = errno; FDH_REALLYCLOSE(fdP); return code; } - code = FDH_WRITE(fdP, data, AFS_PAGESIZE); + code = FDH_WRITE(fdP, data, (afs_fsize_t) AFS_PAGESIZE); if (code != AFS_PAGESIZE) { if (code < 0) code = errno; - else + else code = EIO; FDH_REALLYCLOSE(fdP); return code; @@ -113,11 +117,9 @@ char * data; * Create a handle to a directory entry and reference it (IH_INIT). * The handle needs to be dereferenced with the FidZap() routine. */ -SetSalvageDirHandle(dir, volume, device, inode) -DirHandle *dir; -afs_int32 volume; -Inode inode; -Device device; +void +SetSalvageDirHandle(DirHandle * dir, afs_int32 volume, Device device, + Inode inode) { static SalvageCacheCheck = 1; memset(dir, 0, sizeof(DirHandle)); @@ -125,61 +127,56 @@ Device device; dir->dirh_device = device; dir->dirh_volume = volume; dir->dirh_inode = inode; - IH_INIT(dir->dirh_handle, device, volume, inode); + IH_INIT(dir->dirh_handle, device, volume, inode); /* Always re-read for a new dirhandle */ dir->dirh_cacheCheck = SalvageCacheCheck++; } -FidZap (file) -DirHandle * file; - +void +FidZap(DirHandle * file) { IH_RELEASE(file->dirh_handle); memset(file, 0, sizeof(DirHandle)); } -FidZero (file) -DirHandle * file; - +void +FidZero(DirHandle * file) { memset(file, 0, sizeof(DirHandle)); } -FidEq (afile, bfile) -DirHandle * afile; -DirHandle * bfile; - +int +FidEq(DirHandle * afile, DirHandle * bfile) { - if (afile->dirh_volume != bfile->dirh_volume) return 0; - if (afile->dirh_device != bfile->dirh_device) return 0; - if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck) return 0; - if (afile->dirh_inode != bfile->dirh_inode) return 0; + if (afile->dirh_volume != bfile->dirh_volume) + return 0; + if (afile->dirh_device != bfile->dirh_device) + return 0; + if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck) + return 0; + if (afile->dirh_inode != bfile->dirh_inode) + return 0; return 1; } -FidVolEq (afile, vid) -DirHandle * afile; -afs_int32 vid; - +int +FidVolEq(DirHandle * afile, afs_int32 vid) { - if (afile->dirh_volume != vid) return 0; + if (afile->dirh_volume != vid) + return 0; return 1; } -FidCpy (tofile, fromfile) -DirHandle * tofile; -DirHandle * fromfile; - +void +FidCpy(DirHandle * tofile, DirHandle * fromfile) { *tofile = *fromfile; IH_COPY(tofile->dirh_handle, fromfile->dirh_handle); } -Die (msg) -char * msg; - +void +Die(char *msg) { - printf("%s\n",msg); - assert(1==2); + printf("%s\n", msg); + assert(1 == 2); } - diff --git a/src/vol/purge.c b/src/vol/purge.c index 25fe927f8..49e514804 100644 --- a/src/vol/purge.c +++ b/src/vol/purge.c @@ -16,7 +16,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/purge.c,v 1.1.1.5 2001/09/11 14:35:46 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/purge.c,v 1.9 2003/07/15 23:17:40 shadow Exp $"); #include #ifdef AFS_NT40_ENV @@ -27,6 +28,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/purge.c,v 1.1.1.5 2001/09/11 14:35: #include #include #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include #include @@ -47,20 +55,22 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/purge.c,v 1.1.1.5 2001/09/11 14:35: #include "fssync.h" /* forward declarations */ -void PurgeIndex_r(Volume *vp, VnodeClass class); -void PurgeHeader_r(Volume *vp); +void PurgeIndex_r(Volume * vp, VnodeClass class); +void PurgeHeader_r(Volume * vp); -void VPurgeVolume_r(Error *ec, Volume *vp) +void +VPurgeVolume_r(Error * ec, Volume * vp) { - struct DiskPartition *tpartp = vp->partition; + struct DiskPartition *tpartp = vp->partition; char purgePath[MAXPATHLEN]; /* N.B. it's important here to use the partition pointed to by the * volume header. This routine can, under some circumstances, be called * when two volumes with the same id exist on different partitions. */ - sprintf(purgePath, "%s/%s", VPartitionPath(vp->partition), - VolumeExternalName(V_id(vp))); + (void)afs_snprintf(purgePath, sizeof purgePath, "%s/%s", + VPartitionPath(vp->partition), + VolumeExternalName(V_id(vp))); PurgeIndex_r(vp, vLarge); PurgeIndex_r(vp, vSmall); PurgeHeader_r(vp); @@ -68,26 +78,24 @@ void VPurgeVolume_r(Error *ec, Volume *vp) /* * Call the fileserver to break all call backs for that volume */ - FSYNC_askfs(V_id(vp), tpartp->name, FSYNC_RESTOREVOLUME, 0); + FSYNC_askfs(V_id(vp), tpartp->name, FSYNC_RESTOREVOLUME, 0); } -void VPurgeVolume(Error *ec, Volume *vp) +void +VPurgeVolume(Error * ec, Volume * vp) { - VOL_LOCK - VPurgeVolume_r(ec, vp); - VOL_UNLOCK -} + VOL_LOCK VPurgeVolume_r(ec, vp); +VOL_UNLOCK} #define MAXOBLITATONCE 200 /* delete a portion of an index, adjusting offset appropriately. Returns 0 if things work and we should be called again, 1 if success full and done, and -1 if an error occurred. It adjusts offset appropriately on 0 or 1 return codes, and otherwise doesn't touch it */ -static ObliterateRegion(avp, aclass, afile, aoffset) -afs_int32 *aoffset; -StreamHandle_t *afile; -VnodeClass aclass; -Volume *avp; { +static int +ObliterateRegion(Volume * avp, VnodeClass aclass, StreamHandle_t * afile, + afs_int32 * aoffset) +{ register struct VnodeClassInfo *vcp; Inode inodes[MAXOBLITATONCE]; register afs_int32 iindex, nscanned; @@ -96,17 +104,17 @@ Volume *avp; { int hitEOF; register int i; register afs_int32 code; - register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; + register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; hitEOF = 0; vcp = &VnodeClassInfo[aclass]; - offset = *aoffset; /* original offset */ + offset = *aoffset; /* original offset */ iindex = 0; nscanned = 0; /* advance over up to MAXOBLITATONCE inodes. nscanned tells us how many we examined. - We remember the inodes in an array, and idec them after zeroing them in the index. - The reason for these contortions is to make volume deletion idempotent, even - if we crash in the middle of a delete operation. */ + * We remember the inodes in an array, and idec them after zeroing them in the index. + * The reason for these contortions is to make volume deletion idempotent, even + * if we crash in the middle of a delete operation. */ STREAM_SEEK(afile, offset, 0); while (1) { if (iindex >= MAXOBLITATONCE) { @@ -121,7 +129,7 @@ Volume *avp; { } if (vnode->type != vNull) { if (vnode->vnodeMagic != vcp->magic) - goto fail; /* something really wrong; let salvager take care of it */ + goto fail; /* something really wrong; let salvager take care of it */ if (VNDISK_GET_INO(vnode)) inodes[iindex++] = VNDISK_GET_INO(vnode); } @@ -130,42 +138,42 @@ Volume *avp; { /* next, obliterate the index and fflush (and fsync) it */ STREAM_SEEK(afile, *aoffset, 0); /* seek back to start of vnode index region */ memset(buf, 0, sizeof(buf)); /* zero out our proto-vnode */ - for(i=0;idiskSize, 1, afile) != 1) goto fail; } - STREAM_FLUSH(afile); /* ensure 0s are on the disk */ + STREAM_FLUSH(afile); /* ensure 0s are on the disk */ OS_SYNC(afile->str_fd); /* finally, do the idec's */ - for(i=0;ivnodeIndex[class].handle); if (fdP == NULL) @@ -178,22 +186,23 @@ void PurgeIndex_r(Volume *vp, VnodeClass class) } offset = vcp->diskSize; - while(1) { + while (1) { code = ObliterateRegion(vp, class, ifile, &offset); - if (code) break; /* if error or hit EOF */ + if (code) + break; /* if error or hit EOF */ } STREAM_CLOSE(ifile); FDH_CLOSE(fdP); } -void PurgeHeader(Volume *vp) +void +PurgeHeader(Volume * vp) { - VOL_LOCK - PurgeHeader_r(vp); - VOL_UNLOCK -} + VOL_LOCK PurgeHeader_r(vp); +VOL_UNLOCK} -void PurgeHeader_r(Volume *vp) +void +PurgeHeader_r(Volume * vp) { IH_REALLYCLOSE(V_diskDataHandle(vp)); IH_DEC(V_linkHandle(vp), vp->vnodeIndex[vLarge].handle->ih_ino, V_id(vp)); @@ -205,5 +214,3 @@ void PurgeHeader_r(Volume *vp) IH_DEC(V_linkHandle(vp), vp->linkHandle->ih_ino, V_parentId(vp)); #endif } - - diff --git a/src/vol/salvage.h b/src/vol/salvage.h index cdbf28901..a18a24574 100644 --- a/src/vol/salvage.h +++ b/src/vol/salvage.h @@ -21,7 +21,6 @@ typedef struct DirHandle { int dirh_volume; int dirh_device; Inode dirh_inode; - IHandle_t *dirh_handle; - afs_int32 dirh_cacheCheck; + IHandle_t *dirh_handle; + afs_int32 dirh_cacheCheck; } DirHandle; - diff --git a/src/vol/test/Makefile.in b/src/vol/test/Makefile.in index 9dadbda66..9a0156bbe 100644 --- a/src/vol/test/Makefile.in +++ b/src/vol/test/Makefile.in @@ -5,28 +5,9 @@ # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html -DEST=@DEST@ -TOP_INCDIR=@TOP_INCDIR@ -TOP_LIBDIR=@TOP_LIBDIR@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ -libexecdir=@libexecdir@ -libdir=@libdir@ -includedir=@includedir@ -mandir=@mandir@ -afssrvbindir=@afssrvbindir@ -afssrvsbindir=@afssrvsbindir@ -afssrvlibexecdir=@afssrvlibexecdir@ -COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et -RXGEN=${TOP_SRCDIR}/rxgen/rxgen -TOP_SRCDIR=@TOP_SRCDIR@ -SYS_NAME=@AFS_SYSNAME@ - -SHELL=/bin/sh - -include ../../config/Makefile.${SYS_NAME} +srcdir=@srcdir@ +include @TOP_OBJDIR@/src/config/Makefile.config + INCDIRS=-I. -I.. -I${TOP_INCDIR} ${FSINCLUDES} INSTALL = ${SRCDIR}/bin/install @@ -50,9 +31,6 @@ OBJECTS=listVicepx.o utilities.o updateDirInode.o all: listVicepx updateDirInode testpart -kinstall: - @echo No kernel source here. - install: ${OBJECTS}: ${PUBLICHEADERS} ${TOP_INCDIR}/lwp.h ${TOP_INCDIR}/lock.h ${TOP_INCDIR}/afs/afsint.h ../filesignal.h ../vutils.h ../vldb.h ../salvage.h ../volinodes.h ../qiin.h diff --git a/src/vol/test/NTMakefile b/src/vol/test/NTMakefile index 3432e8f67..8d8da685b 100644 --- a/src/vol/test/NTMakefile +++ b/src/vol/test/NTMakefile @@ -5,10 +5,10 @@ # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html +RELDIR=vol\test !INCLUDE ..\..\config\NTMakefile.$(SYS_NAME) !INCLUDE ..\..\config\NTMakefile.version - ############################################################################ # External libraries @@ -24,15 +24,18 @@ EXEC_LIBS = \ ############################################################################ # build inode lister -ILIST = ilist.exe +ILIST = $(OUT)\ilist.exe -$(ILIST): ilist_nt.obj $(EXEC_LIBS) +$(ILIST): $(OUT)\ilist_nt.obj $(EXEC_LIBS) $(EXECONLINK) ############################################################################ # build link table lister -LTLIST = ltlist.exe +LTLIST = $(OUT)\ltlist.exe -$(LTLIST): ltlist.obj $(EXEC_LIBS) +$(LTLIST): $(OUT)\ltlist.obj $(EXEC_LIBS) $(EXECONLINK) + +mkdir: + diff --git a/src/vol/test/ilist_nt.c b/src/vol/test/ilist_nt.c index 7ce4ef148..70773657a 100644 --- a/src/vol/test/ilist_nt.c +++ b/src/vol/test/ilist_nt.c @@ -14,7 +14,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/ilist_nt.c,v 1.1.1.4 2001/07/14 22:25:04 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/ilist_nt.c,v 1.5 2003/07/15 23:17:43 shadow Exp $"); #include #include @@ -28,36 +29,41 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/ilist_nt.c,v 1.1.1.4 2001/07/1 #include "viceinode.h" -void Usage(void) +void +Usage(void) { printf("Usage: ilist ilist partition [volume]\n"); - printf("List all \"inodes\" for the volume group containing the volume\n"); + printf + ("List all \"inodes\" for the volume group containing the volume\n"); printf("or for the entire partition.\n"); exit(1); } /* This judge function can be a dummy since I know how nt_ListAFSFiles works */ -int Judge(struct ViceInodeInfo *info, int vid) +int +Judge(struct ViceInodeInfo *info, int vid) { return 1; } -int PrintInodeInfo(FILE *fp, struct ViceInodeInfo *info, char *dir, char *name) +int +PrintInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name) { static int lastVID = -1; int rwVID; char dname[1024]; - - rwVID = info->u.param[1] == -1 ? info->u.special.parentId : - info->u.vnode.volumeId; + + rwVID = + info->u.param[1] == + -1 ? info->u.special.parentId : info->u.vnode.volumeId; if (rwVID != lastVID) { if (lastVID != -1) printf("\n"); lastVID = rwVID; /* This munging of the name remove a "\R". */ - (void) strcpy(dname, dir); - dname[strlen(dname)-2] = '\0'; + (void)strcpy(dname, dir); + dname[strlen(dname) - 2] = '\0'; printf("Parent Volume %d, Directory %s\n", rwVID, dname); printf("%14s %8s %5s %10s %10s %10s %10s %s\n", "Inode", "Size", "Nlink", "P1", "P2", "P3", "P4", "Name"); @@ -74,12 +80,14 @@ main(int ac, char **av) char *part; int ninodes; - if (ac < 2 || ac > 3) Usage(); + if (ac < 2 || ac > 3) + Usage(); part = av[1]; if (ac == 3) singleVolumeNumber = atoi(av[2]); - ninodes = nt_ListAFSFiles(part, PrintInodeInfo, stdout, - Judge, singleVolumeNumber); + ninodes = + nt_ListAFSFiles(part, PrintInodeInfo, stdout, Judge, + singleVolumeNumber); } diff --git a/src/vol/test/listVicepx.c b/src/vol/test/listVicepx.c index c6b1cc5bb..355a784bf 100644 --- a/src/vol/test/listVicepx.c +++ b/src/vol/test/listVicepx.c @@ -17,7 +17,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/listVicepx.c,v 1.1.1.5 2001/09/11 14:35:52 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/listVicepx.c,v 1.6 2003/07/15 23:17:43 shadow Exp $"); #include #include @@ -26,7 +27,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/listVicepx.c,v 1.1.1.5 2001/09 #if !defined(AFS_SGI_ENV) #ifdef AFS_OSF_ENV #include -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #ifdef AFS_VFSINCL_ENV #define VFS #ifdef AFS_SUN5_ENV @@ -38,8 +39,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/listVicepx.c,v 1.1.1.5 2001/09 #ifndef AFS_AIX_ENV #include #endif -#endif AFS_VFSINCL_ENV -#endif /* AFS_OSF_ENV */ +#endif /* AFS_VFSINCL_ENV */ +#endif /* AFS_OSF_ENV */ #endif /* AFS_SGI_ENV */ #include #include @@ -73,7 +74,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/listVicepx.c,v 1.1.1.5 2001/09 /* #include */ -#include "efs.h" /* until 5.1 release */ +#include "efs.h" /* until 5.1 release */ #define ROOTINO EFS_ROOTINO #else @@ -111,216 +112,207 @@ extern void *calloc(), *realloc(); #endif #include "salvage.h" int volumeId; -int VolumeChanged; /* to satisfy library libdir use */ +int VolumeChanged; /* to satisfy library libdir use */ #include "listVicepx.h" -char* orphan_NoVnode = "ORPHANED_NoVnode"; -char* orphan_NoUnique = "ORPHANED_NoUnique"; +char *orphan_NoVnode = "ORPHANED_NoVnode"; +char *orphan_NoUnique = "ORPHANED_NoUnique"; #define allNull 0x00 -#define allFiles 0x01 /* equivalent to /bin/ls */ -#define lFlag 0x02 /* equivalent to /bin/ls -l */ -#define allDirs 0x04 /* equivalent to /bin/ls -ld */ -#define contentsDInode 0x08 /* list contents of dir inode */ -#define volInfo 0x10 /* list info from vol header */ +#define allFiles 0x01 /* equivalent to /bin/ls */ +#define lFlag 0x02 /* equivalent to /bin/ls -l */ +#define allDirs 0x04 /* equivalent to /bin/ls -ld */ +#define contentsDInode 0x08 /* list contents of dir inode */ +#define volInfo 0x10 /* list info from vol header */ extern DirEnt *lookup(); -extern char *getFileName(), *getDirName(), *printStack(); -extern DirEnt* hash[]; +extern char *getFileName(), *getDirName(), *printStack(); +extern DirEnt *hash[]; -int -Usage( name) -char* name; +int +Usage(name) + char *name; { - assert(name); - printf("Usage is %s -p -v [-ls | -lsl | -ld] [-volInfo] [-dir ] \n", name); - printf("-ls : lists all files\n"); - printf("-lsl : lists all files along with its properties\n"); - printf("-ld : lists all directories\n"); - printf("-volInfo : lists volume header \n"); - printf("-dir : prints contents of directory inode\n"); - exit(1); + assert(name); + printf + ("Usage is %s -p -v [-ls | -lsl | -ld] [-volInfo] [-dir ] \n", + name); + printf("-ls : lists all files\n"); + printf("-lsl : lists all files along with its properties\n"); + printf("-ld : lists all directories\n"); + printf("-volInfo : lists volume header \n"); + printf("-dir : prints contents of directory inode\n"); + exit(1); } - + main(argc, argv) -int argc; -char* argv[]; + int argc; + char *argv[]; { - char fullName[32+VNAMESIZE+sizeof(VHDREXT)+4]; - char partition[32], volume[VNAMESIZE]; - struct stat statBuf; - struct VolumeHeader volumeHeader; - int fd,i, sawPart=0, sawVolume=0, sawDirContents=0; - char option = allNull; /* no default options */ - Inode dirInode; /* list contents of this dir Inode */ - - for (i = 1; i < argc; i++) - { - if (!strcmp(argv[i], "-p")) - { - if ( (i+1) >= argc ) - Usage(argv[0]); - assert(strlen(argv[i+1]) < 32 ); - strcpy( partition, argv[++i]); - sawPart = 1; - } - else if ( !strcmp(argv[i], "-v")) - { - if ( (i+1) >= argc ) - Usage(argv[0]); - assert(strlen(argv[i+1]) < VNAMESIZE ); - strcpy( volume, argv[++i]); - sawVolume = 1; - } - else if ( !strcmp(argv[i], "-dir")) - { - if ( (i+1) >= argc ) - Usage(argv[0]); - dirInode = atoi(argv[++i]); - option |= contentsDInode; - sawDirContents = 1; - } - else if ( !strcmp(argv[i], "-ls")) - option |= allFiles; - else if ( !strcmp(argv[i], "-lsl")) - option |= ( allFiles | lFlag ); - else if ( !strcmp(argv[i], "-ld")) - option |= allDirs; - else if ( !strcmp(argv[i], "-volInfo")) - option |= volInfo; - else + char fullName[32 + VNAMESIZE + sizeof(VHDREXT) + 4]; + char partition[32], volume[VNAMESIZE]; + struct stat statBuf; + struct VolumeHeader volumeHeader; + int fd, i, sawPart = 0, sawVolume = 0, sawDirContents = 0; + char option = allNull; /* no default options */ + Inode dirInode; /* list contents of this dir Inode */ + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-p")) { + if ((i + 1) >= argc) Usage(argv[0]); - } - /* check input parameters */ - if ( !sawPart || !sawVolume) + assert(strlen(argv[i + 1]) < 32); + strcpy(partition, argv[++i]); + sawPart = 1; + } else if (!strcmp(argv[i], "-v")) { + if ((i + 1) >= argc) Usage(argv[0]); + assert(strlen(argv[i + 1]) < VNAMESIZE); + strcpy(volume, argv[++i]); + sawVolume = 1; + } else if (!strcmp(argv[i], "-dir")) { + if ((i + 1) >= argc) + Usage(argv[0]); + dirInode = atoi(argv[++i]); + option |= contentsDInode; + sawDirContents = 1; + } else if (!strcmp(argv[i], "-ls")) + option |= allFiles; + else if (!strcmp(argv[i], "-lsl")) + option |= (allFiles | lFlag); + else if (!strcmp(argv[i], "-ld")) + option |= allDirs; + else if (!strcmp(argv[i], "-volInfo")) + option |= volInfo; + else + Usage(argv[0]); + } + /* check input parameters */ + if (!sawPart || !sawVolume) + Usage(argv[0]); + + /* extract volume id */ + volumeId = atoi(volume); + + /* construct unix file name */ + strcpy(fullName, partition); + strcat(fullName, "/V"); + strcat(fullName, volume); + strcat(fullName, VHDREXT); + + /* check to see that volume exists */ + if (stat(fullName, &statBuf) < 0) { + printf("Error in stat(%s) : %d\n", fullName, errno); + exit(2); + } - /* extract volume id */ - volumeId = atoi(volume); - - /* construct unix file name */ - strcpy(fullName, partition); - strcat(fullName,"/V"); - strcat(fullName,volume); - strcat(fullName, VHDREXT); - - /* check to see that volume exists */ - if ( stat(fullName, &statBuf) < 0 ) - { - printf("Error in stat(%s) : %d\n", fullName, errno); - exit(2); - } - - /* read volume header */ - if ( (fd=open(fullName, O_RDONLY)) < 0 ) - { - printf("Error in open(%s) : %d\n", fullName, errno); - exit(3); - } - if ( read(fd, &volumeHeader, sizeof(struct VolumeHeader)) < sizeof(struct VolumeHeader)) - { - printf("Error in reading Volume Header : %d\n", errno); - exit(4); - } + /* read volume header */ + if ((fd = open(fullName, O_RDONLY)) < 0) { + printf("Error in open(%s) : %d\n", fullName, errno); + exit(3); + } + if (read(fd, &volumeHeader, sizeof(struct VolumeHeader)) < + sizeof(struct VolumeHeader)) { + printf("Error in reading Volume Header : %d\n", errno); + exit(4); + } - switch ( option ) - { - case volInfo: /* volume header info */ - printf("VolId:%d VolInfo:%d mag:%x vers:%d smallVnodeIndex:%d largeVnodeIndex:%d VoAcl:%d volMntTab:%d\n", - volumeHeader.id, volumeHeader.volumeInfo, - volumeHeader.stamp.magic, volumeHeader.stamp.version, - volumeHeader.smallVnodeIndex, volumeHeader.largeVnodeIndex, - volumeHeader.volumeAcl, volumeHeader.volumeMountTable); - break; + switch (option) { + case volInfo: /* volume header info */ + printf + ("VolId:%d VolInfo:%d mag:%x vers:%d smallVnodeIndex:%d largeVnodeIndex:%d VoAcl:%d volMntTab:%d\n", + volumeHeader.id, volumeHeader.volumeInfo, + volumeHeader.stamp.magic, volumeHeader.stamp.version, + volumeHeader.smallVnodeIndex, volumeHeader.largeVnodeIndex, + volumeHeader.volumeAcl, volumeHeader.volumeMountTable); + break; + + case contentsDInode: /* list directory entries */ + printContentsOfDirInode(statBuf.st_dev, dirInode, fullName, option); + break; + } - case contentsDInode: /* list directory entries */ - printContentsOfDirInode(statBuf.st_dev, dirInode, - fullName, option); - break; - } + scanLargeVnode(statBuf.st_dev, volumeHeader.largeVnodeIndex, fullName, + option); + if (option & allDirs) + printDirs(fullName); - scanLargeVnode(statBuf.st_dev, volumeHeader.largeVnodeIndex, fullName, option); - if ( option & allDirs ) - printDirs(fullName); - - if ( option & allFiles ) - scanSmallVnode(statBuf.st_dev, volumeHeader.smallVnodeIndex, fullName, option); - close(fd); + if (option & allFiles) + scanSmallVnode(statBuf.st_dev, volumeHeader.smallVnodeIndex, fullName, + option); + close(fd); } -int +int scanLargeVnode(dev, node, partitionName, option) -dev_t dev; -Inode node; -char* partitionName; -char option; /* user options */ + dev_t dev; + Inode node; + char *partitionName; + char option; /* user options */ { - afs_int32 diskSize = SIZEOF_LARGEDISKVNODE; - int nVnodes, fdi, vnodeIndex, offset=0; - char buf[SIZEOF_LARGEDISKVNODE]; - struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; - FILE* file; - struct stat statBuf; - - /* open this largeVodeIndex */ - if ( (fdi = iopen(dev, node, O_RDONLY)) < 0 ) - { - printf("Error in reading node : %d\n", errno); - exit(5); - } + afs_int32 diskSize = SIZEOF_LARGEDISKVNODE; + int nVnodes, fdi, vnodeIndex, offset = 0; + char buf[SIZEOF_LARGEDISKVNODE]; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; + FILE *file; + struct stat statBuf; + + /* open this largeVodeIndex */ + if ((fdi = iopen(dev, node, O_RDONLY)) < 0) { + printf("Error in reading node : %d\n", errno); + exit(5); + } - /* get a FILE pointer */ - if ( (file = fdopen(fdi, "r")) == 0 ) - { - printf("fdopen failed : %d\n", errno); - exit(6); - } + /* get a FILE pointer */ + if ((file = fdopen(fdi, "r")) == 0) { + printf("fdopen failed : %d\n", errno); + exit(6); + } - /*find out how many directories are there in this volume */ - if ( fstat(fdi, &statBuf) < 0 ) - { - printf("Error in stat(fd=%d): %d\n", fdi, errno); - exit(6); - } - nVnodes = (statBuf.st_size / diskSize) - 1; - if (nVnodes > 0) - fseek(file, diskSize, 0); - else nVnodes = 0; - - /* scan all entries in this volume */ - DInit(10); /* initialise directory buffer */ - - for (vnodeIndex = 0; nVnodes && fread(vnode, diskSize, 1, file) == 1; - nVnodes--, vnodeIndex++, offset += diskSize) - { - /* scan this directory */ - int createDirEnt(); - if ( (vnode->type == vDirectory ) && (vnode->inodeNumber ) ) - { - DirHandle dir; - DirEnt * dirEntry; - - dir.volume = volumeId; - dir.device = dev; - dir.cacheCheck = 0; - dir.inode = vnode->inodeNumber; + /*find out how many directories are there in this volume */ + if (fstat(fdi, &statBuf) < 0) { + printf("Error in stat(fd=%d): %d\n", fdi, errno); + exit(6); + } + nVnodes = (statBuf.st_size / diskSize) - 1; + if (nVnodes > 0) + fseek(file, diskSize, 0); + else + nVnodes = 0; + + /* scan all entries in this volume */ + DInit(10); /* initialise directory buffer */ + + for (vnodeIndex = 0; nVnodes && fread(vnode, diskSize, 1, file) == 1; + nVnodes--, vnodeIndex++, offset += diskSize) { + /* scan this directory */ + int createDirEnt(); + if ((vnode->type == vDirectory) && (vnode->inodeNumber)) { + DirHandle dir; + DirEnt *dirEntry; + + dir.volume = volumeId; + dir.device = dev; + dir.cacheCheck = 0; + dir.inode = vnode->inodeNumber; #ifdef DEBUG - printf("Directory inode %d (parent vnode = %d) contains the entries :\n", - vnode->inodeNumber, vnode->parent ); + printf + ("Directory inode %d (parent vnode = %d) contains the entries :\n", + vnode->inodeNumber, vnode->parent); #endif - assert(dirEntry = (DirEnt*) malloc(sizeof(DirEnt))); - dirEntry->inode = vnode->inodeNumber; - dirEntry->numEntries = 0; - dirEntry->vnodeName = NULL; - EnumerateDir(&dir, &createDirEnt, dirEntry ); - insertHash(dirEntry); /* insert in hash table */ - } + assert(dirEntry = (DirEnt *) malloc(sizeof(DirEnt))); + dirEntry->inode = vnode->inodeNumber; + dirEntry->numEntries = 0; + dirEntry->vnodeName = NULL; + EnumerateDir(&dir, &createDirEnt, dirEntry); + insertHash(dirEntry); /* insert in hash table */ } - fclose(file); + } + fclose(file); #ifdef DEBUG - printHash(); + printHash(); #endif } @@ -328,320 +320,300 @@ char option; /* user options */ int createDirEnt(dirEntry, fileName, vnode, unique) -DirEnt* dirEntry; -char* fileName; -afs_int32 vnode; -afs_int32 unique; + DirEnt *dirEntry; + char *fileName; + afs_int32 vnode; + afs_int32 unique; { - int fdi; - FILE* file; - struct stat statBuf; - - /* fil up special fields for itself and parent */ - if ( strcmp(fileName,".") == 0 ) - { - dirEntry->vnode = vnode; - return; - } - if ( strcmp(fileName,"..") == 0 ) - { - dirEntry->vnodeParent = vnode; - return; - } + int fdi; + FILE *file; + struct stat statBuf; + + /* fil up special fields for itself and parent */ + if (strcmp(fileName, ".") == 0) { + dirEntry->vnode = vnode; + return; + } + if (strcmp(fileName, "..") == 0) { + dirEntry->vnodeParent = vnode; + return; + } - (dirEntry->numEntries)++; - assert( dirEntry->vnodeName = (VnodeName *)realloc(dirEntry->vnodeName, - dirEntry->numEntries*sizeof(VnodeName))); - dirEntry->vnodeName[dirEntry->numEntries-1].vnode = vnode; - dirEntry->vnodeName[dirEntry->numEntries-1].vunique = unique; - dirEntry->vnodeName[dirEntry->numEntries-1].name = (char *)malloc(strlen(fileName)+1); - assert(dirEntry->vnodeName[dirEntry->numEntries-1].name); - strcpy(dirEntry->vnodeName[dirEntry->numEntries-1].name, fileName); + (dirEntry->numEntries)++; + assert(dirEntry->vnodeName = + (VnodeName *) realloc(dirEntry->vnodeName, + dirEntry->numEntries * sizeof(VnodeName))); + dirEntry->vnodeName[dirEntry->numEntries - 1].vnode = vnode; + dirEntry->vnodeName[dirEntry->numEntries - 1].vunique = unique; + dirEntry->vnodeName[dirEntry->numEntries - 1].name = + (char *)malloc(strlen(fileName) + 1); + assert(dirEntry->vnodeName[dirEntry->numEntries - 1].name); + strcpy(dirEntry->vnodeName[dirEntry->numEntries - 1].name, fileName); } -int -scanSmallVnode(dev, node, partitionName, option ) -dev_t dev; -Inode node; -char* partitionName; -char option; /* user options */ +int +scanSmallVnode(dev, node, partitionName, option) + dev_t dev; + Inode node; + char *partitionName; + char option; /* user options */ { - afs_int32 diskSize = SIZEOF_SMALLDISKVNODE; - int nVnodes, fdi, vnodeIndex, offset=0; - char buf[SIZEOF_LARGEDISKVNODE]; - struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; - FILE* file; - struct stat statBuf; - - /* open this smallVodeIndex */ - if ( (fdi = iopen(dev, node, O_RDONLY)) < 0 ) - { - printf("Error in reading node : %d\n", errno); - exit(5); - } + afs_int32 diskSize = SIZEOF_SMALLDISKVNODE; + int nVnodes, fdi, vnodeIndex, offset = 0; + char buf[SIZEOF_LARGEDISKVNODE]; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; + FILE *file; + struct stat statBuf; + + /* open this smallVodeIndex */ + if ((fdi = iopen(dev, node, O_RDONLY)) < 0) { + printf("Error in reading node : %d\n", errno); + exit(5); + } - /* get a FILE pointer */ - if ( (file = fdopen(fdi, "r")) == 0 ) - { - printf("fdopen failed : %d\n", errno); - exit(6); - } + /* get a FILE pointer */ + if ((file = fdopen(fdi, "r")) == 0) { + printf("fdopen failed : %d\n", errno); + exit(6); + } - /*find out how many files are there in this volume */ - if ( fstat(fdi, &statBuf) < 0 ) - { - printf("Error in stat(fd=%d): %d\n", fdi, errno); - exit(6); - } - nVnodes = (statBuf.st_size / diskSize) - 1; - if (nVnodes > 0) - fseek(file, diskSize, 0); - else nVnodes = 0; - - /* scan all entries in this volume */ - for (vnodeIndex = 0; nVnodes && fread(vnode, diskSize, 1, file) == 1; - nVnodes--, vnodeIndex++, offset += 1) - if ( (vnode->type == vFile) || ( vnode->type == vSymlink) ) - { - char* name, *fullPathName; - int pNode, nNode, orphan = 0; - DirEnt* dir; + /*find out how many files are there in this volume */ + if (fstat(fdi, &statBuf) < 0) { + printf("Error in stat(fd=%d): %d\n", fdi, errno); + exit(6); + } + nVnodes = (statBuf.st_size / diskSize) - 1; + if (nVnodes > 0) + fseek(file, diskSize, 0); + else + nVnodes = 0; + + /* scan all entries in this volume */ + for (vnodeIndex = 0; nVnodes && fread(vnode, diskSize, 1, file) == 1; + nVnodes--, vnodeIndex++, offset += 1) + if ((vnode->type == vFile) || (vnode->type == vSymlink)) { + char *name, *fullPathName; + int pNode, nNode, orphan = 0; + DirEnt *dir; #ifdef FILE_DEBUG - printf(" File Inode = %d parent vnode=%d ", vnode->inodeNumber, - vnode->parent); + printf(" File Inode = %d parent vnode=%d ", vnode->inodeNumber, + vnode->parent); #endif - - if ( (dir = lookup(vnode->parent)) == 0 )/* orphaned*/ - orphan = 1, pushStack ( orphan_NoVnode ); - if ( !orphan ) - { - name=getFileName(dir,vnode->uniquifier); - if ( name == 0 ) - orphan = 1, pushStack(orphan_NoUnique ); - } - if ( !orphan ) - { - /* push the file name on stack */ - pushStack ( name ); - pNode = vnode->parent; - nNode = dir->vnodeParent; - } - while ( !orphan && (pNode != nNode) ) - { - if( (dir= lookup(nNode)) == 0 ) - { - orphan = 1, pushStack(orphan_NoVnode); - break; - } - if( (name = getDirName(dir, pNode)) == 0 ) - { - orphan = 1, pushStack(orphan_NoVnode); - break; - } - pushStack ( name ); - pNode = nNode; - nNode = dir->vnodeParent; - } - fullPathName = printStack(); /* full name of file or symLink */ - if ( vnode->type == vSymlink ) /* check if mount point */ - { - /* read contents of link */ - struct stat statLink; - int fdLink; - char* symLink; - if ( (fdLink=iopen( dev, vnode->inodeNumber, O_RDONLY)) < 0 ) - { - printf("Error in opening symbolic link : %d\n", errno); - exit(10); - } - if ( fstat(fdLink, &statLink) < 0 ) - { - printf("Error in symLink stat(fd=%d): %d\n", fdLink, errno); - exit(12); - } - assert( symLink = (char*)malloc(statLink.st_size+1) ); - if (read(fdLink, symLink, statLink.st_size) < 0 ) - { - printf("Error in reading symbolic link : %d\n", errno); - exit(11); - } - symLink[statLink.st_size] = 0; /* null termination */ - if ( symLink[0] == '#' ) /* this is a mount point */ - printf("Volume %s mounted on %s%s\n", - symLink, partitionName, fullPathName); - free(symLink); - close(fdLink); - } - if ( option & allFiles) - { - if ( option & lFlag ) - { - switch ( vnode->type ) - { - case vFile: printf("F "); - break; - case vDirectory:printf("D "); - break; - case vSymlink: printf("S "); - break; - default: printf("U "); - break; - } - printf("Ind:%d ", vnode->inodeNumber); - printf("Mod:%x ", vnode->modeBits); - printf("Lnk:%d ", vnode->linkCount); - printf("Own:%d ", vnode->owner); - printf("Grp:%d ", vnode->group); - printf("Siz:%d ", vnode->length); - } - printf("~%s\n", fullPathName); - } + + if ((dir = lookup(vnode->parent)) == 0) /* orphaned */ + orphan = 1, pushStack(orphan_NoVnode); + if (!orphan) { + name = getFileName(dir, vnode->uniquifier); + if (name == 0) + orphan = 1, pushStack(orphan_NoUnique); + } + if (!orphan) { + /* push the file name on stack */ + pushStack(name); + pNode = vnode->parent; + nNode = dir->vnodeParent; + } + while (!orphan && (pNode != nNode)) { + if ((dir = lookup(nNode)) == 0) { + orphan = 1, pushStack(orphan_NoVnode); + break; } - - fclose(file); + if ((name = getDirName(dir, pNode)) == 0) { + orphan = 1, pushStack(orphan_NoVnode); + break; + } + pushStack(name); + pNode = nNode; + nNode = dir->vnodeParent; + } + fullPathName = printStack(); /* full name of file or symLink */ + if (vnode->type == vSymlink) { /* check if mount point */ + /* read contents of link */ + struct stat statLink; + int fdLink; + char *symLink; + if ((fdLink = iopen(dev, vnode->inodeNumber, O_RDONLY)) < 0) { + printf("Error in opening symbolic link : %d\n", errno); + exit(10); + } + if (fstat(fdLink, &statLink) < 0) { + printf("Error in symLink stat(fd=%d): %d\n", fdLink, + errno); + exit(12); + } + assert(symLink = (char *)malloc(statLink.st_size + 1)); + if (read(fdLink, symLink, statLink.st_size) < 0) { + printf("Error in reading symbolic link : %d\n", errno); + exit(11); + } + symLink[statLink.st_size] = 0; /* null termination */ + if (symLink[0] == '#') /* this is a mount point */ + printf("Volume %s mounted on %s%s\n", symLink, + partitionName, fullPathName); + free(symLink); + close(fdLink); + } + if (option & allFiles) { + if (option & lFlag) { + switch (vnode->type) { + case vFile: + printf("F "); + break; + case vDirectory: + printf("D "); + break; + case vSymlink: + printf("S "); + break; + default: + printf("U "); + break; + } + printf("Ind:%d ", vnode->inodeNumber); + printf("Mod:%x ", vnode->modeBits); + printf("Lnk:%d ", vnode->linkCount); + printf("Own:%d ", vnode->owner); + printf("Grp:%d ", vnode->group); + printf("Siz:%d ", vnode->length); + } + printf("~%s\n", fullPathName); + } + } + + fclose(file); } /* Lists all directories in the volume */ printDirs(partitionName) -char* partitionName; + char *partitionName; { int i, j, vnode, inode; - DirEnt *ptr, *dir, *tmpDir; + DirEnt *ptr, *dir, *tmpDir; - /* The root level vnode for this volume */ - tmpDir = lookup(1); /* root vnode is 1 */ - if ( tmpDir == 0 ) + /* The root level vnode for this volume */ + tmpDir = lookup(1); /* root vnode is 1 */ + if (tmpDir == 0) printf("Root vnode(1) does not exists :%s\n", partitionName); else printf("D Ind:%d Vnd:1 ~\n", tmpDir->inode); - for ( i=0; i < MAX_HASH_SIZE; i++) - for ( ptr = (DirEnt*)hash[i]; ptr; ptr = ptr->next) - for ( j=0; j < ptr->numEntries; j++) - { - int nVnode, pVnode; - char *fullPathName, *name; + for (i = 0; i < MAX_HASH_SIZE; i++) + for (ptr = (DirEnt *) hash[i]; ptr; ptr = ptr->next) + for (j = 0; j < ptr->numEntries; j++) { + int nVnode, pVnode; + char *fullPathName, *name; - pVnode = ptr->vnodeParent; /* parent vnode */ - nVnode = ptr->vnode; /* this dir vnode */ - vnode = ptr->vnodeName[j].vnode; /* my Vnode */ + pVnode = ptr->vnodeParent; /* parent vnode */ + nVnode = ptr->vnode; /* this dir vnode */ + vnode = ptr->vnodeName[j].vnode; /* my Vnode */ /* directory vnode numbers are odd */ - if ( (vnode % 2) == 0 ) - continue; + if ((vnode % 2) == 0) + continue; tmpDir = lookup(vnode); - if ( !tmpDir ) /* orphaned directory */ - { + if (!tmpDir) { /* orphaned directory */ printf("%s : vnode:%d \n", orphan_NoVnode, vnode); continue; } - inode = tmpDir->inode; /* the inode for this vnode */ - - pushStack(ptr->vnodeName[j].name); - - while ( pVnode != 1 ) - { - dir = lookup( pVnode ); - if ( dir == 0 ) /* orphan */ - { - pushStack(orphan_NoVnode); - break; - } - name = getDirName( dir, nVnode ); - if ( name == 0 ) - { - pushStack(orphan_NoVnode); - break; - } - pushStack(name); - nVnode = pVnode; - pVnode = dir->vnodeParent; - } - fullPathName = printStack();/* full path name of directory*/ - printf("D Ind:%d Vnd:%d ~%s\n", - inode, vnode, fullPathName); - } + inode = tmpDir->inode; /* the inode for this vnode */ + + pushStack(ptr->vnodeName[j].name); + + while (pVnode != 1) { + dir = lookup(pVnode); + if (dir == 0) { /* orphan */ + pushStack(orphan_NoVnode); + break; + } + name = getDirName(dir, nVnode); + if (name == 0) { + pushStack(orphan_NoVnode); + break; + } + pushStack(name); + nVnode = pVnode; + pVnode = dir->vnodeParent; + } + fullPathName = printStack(); /* full path name of directory */ + printf("D Ind:%d Vnd:%d ~%s\n", inode, vnode, fullPathName); + } } /* figure out how many pages in use in a directory, given ptr to its (locked) he ader */ -static ComputeUsedPages(dhp) -register struct DirHeader *dhp; { +static +ComputeUsedPages(dhp) + register struct DirHeader *dhp; +{ register afs_int32 usedPages, i; if (dhp->header.pgcount != 0) { - /* new style */ - usedPages = ntohs(dhp->header.pgcount); - } - else { - /* old style */ - usedPages = 0; - for(i=0; ialloMap[i] == EPP) { - usedPages = i; - break; - } - } - if (usedPages == 0) usedPages = MAXPAGES; + /* new style */ + usedPages = ntohs(dhp->header.pgcount); + } else { + /* old style */ + usedPages = 0; + for (i = 0; i < MAXPAGES; i++) { + if (dhp->alloMap[i] == EPP) { + usedPages = i; + break; + } + } + if (usedPages == 0) + usedPages = MAXPAGES; } return usedPages; } printContentsOfDirInode(device, dirInode, fullName, options) -dev_t device; -Inode dirInode; -char* fullName; -char options; + dev_t device; + Inode dirInode; + char *fullName; + char options; { - int fd, i, j, usedPages, pages; - FILE* file; - struct stat statBuf; - char dirPage[2048]; - struct DirHeader *dhp= (struct DirHeader*)&dirPage[0]; - struct DirEntry *de; + int fd, i, j, usedPages, pages; + FILE *file; + struct stat statBuf; + char dirPage[2048]; + struct DirHeader *dhp = (struct DirHeader *)&dirPage[0]; + struct DirEntry *de; struct PageHeader *pg; - fd = iopen(device, dirInode, O_RDONLY); - if ( fd <= 0 ) - { + fd = iopen(device, dirInode, O_RDONLY); + if (fd <= 0) { printf("Cannot open direcory inode %d\n", dirInode); - return -1; + return -1; } - if ( (file = fdopen(fd, "r")) == 0 ) /* for buffered read */ - { + if ((file = fdopen(fd, "r")) == 0) { /* for buffered read */ printf("fdopen failed : %d\n", errno); close(fd); return -1; } - if ( fstat(fd, &statBuf) < 0 ) - { + if (fstat(fd, &statBuf) < 0) { printf("Error in stat(fd=%d): %d\n", fd, errno); return -1; } /* read first page */ - if ( fread(&dirPage, sizeof(dirPage), 1, file ) != 1) - { - printf("Cannot read dir header from inode %d(errno %d)\n", - dirInode, errno); + if (fread(&dirPage, sizeof(dirPage), 1, file) != 1) { + printf("Cannot read dir header from inode %d(errno %d)\n", dirInode, + errno); fclose(file); return -1; } usedPages = ComputeUsedPages(dhp); - + printf("Alloc map: "); - for ( i=0; i < MAXPAGES; i++) - { - if ( (i % 16) == 0 ) - printf("\n"); + for (i = 0; i < MAXPAGES; i++) { + if ((i % 16) == 0) + printf("\n"); printf("%.2x ", (unsigned char)dhp->alloMap[i]); } printf("\nHash table:"); - for ( i=0; i < NHASHENT; i++) - { - if ( (i % 16) == 0 ) - printf("\n"); + for (i = 0; i < NHASHENT; i++) { + if ((i % 16) == 0) + printf("\n"); printf("%.2d ", dhp->hashTable[i]); } printf("\n"); @@ -652,28 +624,26 @@ char options; printf("tag :%d\n", dhp->header.tag); printf("freecnt :%d(not used)\n", dhp->header.freecount); printf("freebitmap :"); - for ( i=0; i < EPP/8; i++) + for (i = 0; i < EPP / 8; i++) printf("%.2x ", (unsigned char)(dhp->header.freebitmap[i])); printf("\n"); /* print slots in the first page of this directory */ de = ((struct DirPage0 *)dirPage)->entry; - for(i=DHE+1; iflag, de->length, de->next, - de->fid.vnode, de->fid.vunique, de->name); + for (i = DHE + 1; i < EPP; i++, de = (struct DirEntry *)((char *)de + 32)) + printf("ent %d: f=%d l=%d n=%d vn=%d vu=%d name:%s\n", i, de->flag, + de->length, de->next, de->fid.vnode, de->fid.vunique, + de->name); /* read all succeeding pages of this directory */ - for ( pages=1; pages < usedPages; pages++) - { - if ( fread(&dirPage, sizeof(dirPage), 1, file ) != 1) - { - printf("Cannot read %s page from inode %d(errno %d)\n", - pages, dirInode, errno); + for (pages = 1; pages < usedPages; pages++) { + if (fread(&dirPage, sizeof(dirPage), 1, file) != 1) { + printf("Cannot read %s page from inode %d(errno %d)\n", pages, + dirInode, errno); fclose(file); return -1; } - pg = &((struct DirPage1 *)dirPage)->header; /* page header */ + pg = &((struct DirPage1 *)dirPage)->header; /* page header */ de = ((struct DirPage1 *)dirPage)->entry; /* print page header info */ @@ -682,20 +652,17 @@ char options; printf("tag :%d\n", pg->tag); printf("freecnt :%d(not used)\n", pg->freecount); printf("freebitmap :"); - for ( i=0; i < EPP/8; i++) + for (i = 0; i < EPP / 8; i++) printf("%.2x ", (unsigned char)(pg->freebitmap[i])); printf("\n"); - + /* print slots in this page */ - for(i=1; iflag, de->length, de->next, - de->fid.vnode, de->fid.vunique, de->name); + for (i = 1; i < EPP; i++, de = (struct DirEntry *)((char *)de + 32)) + printf("ent %d: f=%d l=%d n=%d vn=%d vu=%d name:%s\n", i, + de->flag, de->length, de->next, de->fid.vnode, + de->fid.vunique, de->name); } fclose(file); return 0; -} - - - +} diff --git a/src/vol/test/listVicepx.h b/src/vol/test/listVicepx.h index 7fc527655..32a03d2b5 100644 --- a/src/vol/test/listVicepx.h +++ b/src/vol/test/listVicepx.h @@ -10,20 +10,17 @@ #define MAX_HASH_SIZE 100 #define MAX_STACK_SIZE 1000 -typedef struct vnodeName -{ - int vnode; - int vunique; /* uniquefier */ - char* name; /* name for this vnode */ +typedef struct vnodeName { + int vnode; + int vunique; /* uniquefier */ + char *name; /* name for this vnode */ } VnodeName; -typedef struct dirEnt -{ - int vnode; /* this directory's vnode */ - int inode; /* this directory's inode */ - int vnodeParent; /* parent directory's vnode */ - int numEntries; /* number of enrtries in this directory */ - VnodeName* vnodeName; /* the entries themselves */ - struct dirEntry* next; /* used by hash table */ +typedef struct dirEnt { + int vnode; /* this directory's vnode */ + int inode; /* this directory's inode */ + int vnodeParent; /* parent directory's vnode */ + int numEntries; /* number of enrtries in this directory */ + VnodeName *vnodeName; /* the entries themselves */ + struct dirEntry *next; /* used by hash table */ } DirEnt; - diff --git a/src/vol/test/ltlist.c b/src/vol/test/ltlist.c index 7faf9d01c..080fd1ccb 100644 --- a/src/vol/test/ltlist.c +++ b/src/vol/test/ltlist.c @@ -12,7 +12,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/ltlist.c,v 1.1.1.4 2001/07/14 22:25:05 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/ltlist.c,v 1.5 2003/07/15 23:17:44 shadow Exp $"); #include #ifdef AFS_NT40_ENV @@ -40,21 +41,20 @@ main(int ac, char **av) } /* Print the magic and version numbers in hex. */ - count = fread((void*)stamp, 1, 8, fp); + count = fread((void *)stamp, 1, 8, fp); if (count != 8) { if (feof(fp)) { - printf("Only read %d bytes of %s, wanted 8 for stamp.\n", - count, av[1]); - } - else { + printf("Only read %d bytes of %s, wanted 8 for stamp.\n", count, + av[1]); + } else { #ifdef AFS_NT40_ENV - printf("NT Error %d reading 8 bytes from %s\n", - GetLastError(), av[1]); + printf("NT Error %d reading 8 bytes from %s\n", GetLastError(), + av[1]); #else perror("fread"); #endif } - exit(1); + exit(1); } printf("magic=0x%x, version=0x%x\n", stamp[0], stamp[1]); @@ -62,11 +62,10 @@ main(int ac, char **av) printf("%10s %2s %2s %2s %2s %2s\n", "Vnode", "F1", "F2", "F3", "F4", "F5"); i = 0; - while (fread((void*)&row, 1, 2, fp)) { - printf("%10d %2d %2d %2d %2d %2d\n", i, - (int)(row&0x7), (int)((row>>3)&0x7), (int)((row>>6)&0x7), - (int)((row>>9)&0x7), (int)((row>>12)&0x7)); - i ++; + while (fread((void *)&row, 1, 2, fp)) { + printf("%10d %2d %2d %2d %2d %2d\n", i, (int)(row & 0x7), + (int)((row >> 3) & 0x7), (int)((row >> 6) & 0x7), + (int)((row >> 9) & 0x7), (int)((row >> 12) & 0x7)); + i++; } } - diff --git a/src/vol/test/nicreate.c b/src/vol/test/nicreate.c index 3666e65e0..3a25cf4ba 100644 --- a/src/vol/test/nicreate.c +++ b/src/vol/test/nicreate.c @@ -14,7 +14,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nicreate.c,v 1.1.1.4 2001/07/14 22:25:05 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/nicreate.c,v 1.5 2003/07/15 23:17:46 shadow Exp $"); #ifdef AFS_NAMEI_ENV #include @@ -38,9 +39,10 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nicreate.c,v 1.1.1.4 2001/07/1 char *prog = "nicreate"; -IHandle_t * GetLinkHandle(char *part, int volid); +IHandle_t *GetLinkHandle(char *part, int volid); -void Usage(void) +void +Usage(void) { printf("Usage: %s partition RWvolid p1 p2 p3 p4\n", prog); exit(1); @@ -54,7 +56,8 @@ main(int ac, char **av) IHandle_t lh, *lhp; Inode ino; - if (ac != 7) Usage(); + if (ac != 7) + Usage(); part = av[1]; volid = atoi(av[2]); @@ -76,11 +79,9 @@ main(int ac, char **av) ino = namei_icreate(lhp, part, p1, p2, p3, p4); if (!VALID_INO(ino)) { perror("namei_icreate"); - } - else { + } else { printf("Returned inode %s\n", PrintInode(NULL, ino)); } } #endif /* AFS_NAMEI_ENV */ - diff --git a/src/vol/test/nilist.c b/src/vol/test/nilist.c index d918ceb1d..90d2f2aa0 100644 --- a/src/vol/test/nilist.c +++ b/src/vol/test/nilist.c @@ -14,7 +14,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nilist.c,v 1.1.1.4 2001/07/14 22:25:05 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/nilist.c,v 1.5 2003/07/15 23:17:46 shadow Exp $"); #include #ifdef AFS_NT40_ENV @@ -32,42 +33,47 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nilist.c,v 1.1.1.4 2001/07/14 #ifndef AFS_NAMEI_ENV main() { - printf("nilist is only useful for namei AFS file server" - " implementations.\n"); - exit(1); + printf("nilist is only useful for namei AFS file server" + " implementations.\n"); + exit(1); } #else -void Usage(void) +void +Usage(void) { printf("Usage: nilist partition [volume]\n"); - printf("List all \"inodes\" for the volume group containing the volume\n"); + printf + ("List all \"inodes\" for the volume group containing the volume\n"); printf("or for the entire partition.\n"); exit(1); } /* This judge function can be a dummy since I know how nt_ListAFSFiles works */ -int Judge(struct ViceInodeInfo *info, int vid) +int +Judge(struct ViceInodeInfo *info, int vid) { return 1; } -int PrintInodeInfo(FILE *fp, struct ViceInodeInfo *info, char *dir, char *name) +int +PrintInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name) { static int lastVID = -1; int rwVID; char dname[1024]; - - rwVID = info->u.param[1] == -1 ? info->u.special.parentId : - info->u.vnode.volumeId; + + rwVID = + info->u.param[1] == + -1 ? info->u.special.parentId : info->u.vnode.volumeId; if (rwVID != lastVID) { if (lastVID != -1) printf("\n"); lastVID = rwVID; /* This munging of the name remove a "\R". */ - (void) strcpy(dname, dir); - dname[strlen(dname)-2] = '\0'; + (void)strcpy(dname, dir); + dname[strlen(dname) - 2] = '\0'; printf("Parent Volume %d, Directory %s\n", rwVID, dname); printf("%19s %8s %5s %10s %10s %10s %10s %s\n", "Inode", "Size", "Nlink", "P1", "P2", "P3", "P4", "Name"); @@ -91,18 +97,21 @@ main(int ac, char **av) char *part; int ninodes; - if (ac < 2 || ac > 3) Usage(); + if (ac < 2 || ac > 3) + Usage(); part = av[1]; if (ac == 3) singleVolumeNumber = atoi(av[2]); #ifdef AFS_NT40_ENV - ninodes = nt_ListAFSFiles(part, PrintInodeInfo, stdout, - Judge, singleVolumeNumber); + ninodes = + nt_ListAFSFiles(part, PrintInodeInfo, stdout, Judge, + singleVolumeNumber); #else - ninodes = namei_ListAFSFiles(part, PrintInodeInfo, stdout, - Judge, singleVolumeNumber); + ninodes = + namei_ListAFSFiles(part, PrintInodeInfo, stdout, Judge, + singleVolumeNumber); #endif } diff --git a/src/vol/test/nincdec.c b/src/vol/test/nincdec.c index bb0527694..bbb39d6ef 100644 --- a/src/vol/test/nincdec.c +++ b/src/vol/test/nincdec.c @@ -14,7 +14,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nincdec.c,v 1.1.1.4 2001/07/14 22:25:06 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/nincdec.c,v 1.5 2003/07/15 23:17:46 shadow Exp $"); #ifdef AFS_NAMEI_ENV #include @@ -38,10 +39,11 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nincdec.c,v 1.1.1.4 2001/07/14 char *prog = "nincdec"; -IHandle_t * GetLinkHandle(char *part, int volid); +IHandle_t *GetLinkHandle(char *part, int volid); -void Usage(void) +void +Usage(void) { printf("Usage: %s <-i ino | -v vno uniq tag> \n", prog); @@ -63,11 +65,12 @@ main(int ac, char **av) int i; - if (ac < 5) Usage(); + if (ac < 5) + Usage(); part = av[1]; volid = atoi(av[2]); - + i = 4; if (!strcmp(av[3], "-i")) { code = sscanf(av[i++], "%Lu", &ino); @@ -75,31 +78,31 @@ main(int ac, char **av) printf("Failed to get inode from %s\n", av[4]); exit(1); } - } - else if (!strcmp(av[3], "-v")) { - vno = (int64_t)atoi(av[i++]); + } else if (!strcmp(av[3], "-v")) { + vno = (int64_t) atoi(av[i++]); vno &= 0x3ffffff; - tag = (int64_t)atoi(av[i++]); - uniq = (int64_t)atoi(av[i++]); + tag = (int64_t) atoi(av[i++]); + uniq = (int64_t) atoi(av[i++]); ino = uniq; ino |= tag << 32; ino |= vno << 35; printf("ino=%Lu\n", ino); - } - else { + } else { printf("Expected \"-i\" or \"-v\" for inode value\n"); Usage(); } incdecarg = av[i++]; - if (!strcmp(incdecarg, "dec")) do_inc = 0; - else if (!strcmp(incdecarg, "inc")) do_inc = 1; + if (!strcmp(incdecarg, "dec")) + do_inc = 0; + else if (!strcmp(incdecarg, "inc")) + do_inc = 1; else { printf("%s: Expected \"inc\" or \"dec\"\n", incdecarg); Usage(); } - + lh = GetLinkHandle(part, volid); if (!lh) { printf("Failed to get link handle, exiting\n"); @@ -110,7 +113,7 @@ main(int ac, char **av) code = namei_inc(lh, ino, volid); else code = namei_dec(lh, ino, volid); - + printf("namei_%s returned %d\n", do_inc ? "inc" : "dec", code); exit(0); diff --git a/src/vol/test/nino.c b/src/vol/test/nino.c index 7954c4263..b34d103c6 100644 --- a/src/vol/test/nino.c +++ b/src/vol/test/nino.c @@ -13,13 +13,15 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nino.c,v 1.1.1.4 2001/07/14 22:25:06 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/nino.c,v 1.6 2003/07/15 23:17:46 shadow Exp $"); #include #include -#include "../../util/afsutil.h" +#include "util/afsutil.h" -void Usage(void) +void +Usage(void) { printf("Usage: nino <-i ino> | <-c uniq tag vno> | <-a ino_base64>\n"); exit(1); @@ -32,7 +34,8 @@ void do_inobase64(int ac, char **av); main(int ac, char **av) { - if (ac < 3) Usage(); + if (ac < 3) + Usage(); if (!strcmp("-c", av[1])) do_contents(ac, av); @@ -40,11 +43,12 @@ main(int ac, char **av) do_ino(ac, av); else if (!strcmp("-a", av[1])) do_inobase64(ac, av); - else + else Usage(); } -void do_contents(int ac, char **av) +void +do_contents(int ac, char **av) { int64_t ino; int64_t vno, tag, uniq; @@ -56,22 +60,23 @@ void do_contents(int ac, char **av) exit(1); } - vno = (int64_t)atoi(av[4]); + vno = (int64_t) atoi(av[4]); vno &= 0x3ffffff; - tag = (int64_t)atoi(av[3]); + tag = (int64_t) atoi(av[3]); tag &= 0x7; - uniq = (int64_t)atoi(av[2]); + uniq = (int64_t) atoi(av[2]); ino = vno; ino |= tag << 26; ino |= uniq << 32; int64_to_flipbase64(str, ino); - + printf("ino=%Lu, base64=%s\n", ino, str); - + } -void do_ino(int ac, char **av) +void +do_ino(int ac, char **av) { int64_t ino1 = 0; int64_t ino = 0; @@ -84,20 +89,21 @@ void do_ino(int ac, char **av) exit(1); } - ino = (int64_t)-1; + ino = (int64_t) - 1; sscanf(av[2], "%qu", &ino); printf("%Lu %Lu %Lu\n", ino, ino1, ino2); vno = (int)ino; - if (vno == 0x3ffffff) vno = -1; + if (vno == 0x3ffffff) + vno = -1; int64_to_flipbase64(str, ino); - printf("ino=%Lu, vno=%d, tag=%u, uniq=%u, base64=%s\n", - ino, vno, (int)((ino>>26)&0x7), (int)((ino>>32)&0xffffffff), - str); + printf("ino=%Lu, vno=%d, tag=%u, uniq=%u, base64=%s\n", ino, vno, + (int)((ino >> 26) & 0x7), (int)((ino >> 32) & 0xffffffff), str); } -void do_inobase64(int ac, char **av) +void +do_inobase64(int ac, char **av) { int64_t ino1 = 0; int64_t ino = 0; @@ -113,9 +119,9 @@ void do_inobase64(int ac, char **av) ino = flipbase64_to_int64(av[2]); vno = (int)ino; - if (vno == 0x3ffffff) vno = -1; - printf("ino=%Lu, vno=%d, tag=%u, uniq=%u\n", - ino, vno, (int)((ino>>26)&0x7), (int)((ino>>32)&0xffffffff)); + if (vno == 0x3ffffff) + vno = -1; + printf("ino=%Lu, vno=%d, tag=%u, uniq=%u\n", ino, vno, + (int)((ino >> 26) & 0x7), (int)((ino >> 32) & 0xffffffff)); } - diff --git a/src/vol/test/nsubr.c b/src/vol/test/nsubr.c index eb77e4040..7f99667d4 100644 --- a/src/vol/test/nsubr.c +++ b/src/vol/test/nsubr.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nsubr.c,v 1.1.1.4 2001/07/14 22:25:06 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/nsubr.c,v 1.5 2003/07/15 23:17:46 shadow Exp $"); #ifdef AFS_NAMEI_ENV #include @@ -34,7 +35,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/nsubr.c,v 1.1.1.4 2001/07/14 2 -IHandle_t * GetLinkHandle(char *part, int volid) +IHandle_t * +GetLinkHandle(char *part, int volid) { int dev; Inode ino; @@ -47,6 +49,9 @@ IHandle_t * GetLinkHandle(char *part, int volid) return lh; } -void DFlushVolume(void) {} ; +void +DFlushVolume(void) +{ +}; #endif /* AFS_NAMEI_ENV */ diff --git a/src/vol/test/testpart.c b/src/vol/test/testpart.c index f72ace97f..2a66f087a 100644 --- a/src/vol/test/testpart.c +++ b/src/vol/test/testpart.c @@ -10,34 +10,37 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/testpart.c,v 1.1.1.4 2001/07/14 22:25:06 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/testpart.c,v 1.5 2003/07/15 23:17:46 shadow Exp $"); #include Log(a, b, c, d, e, f, g, h, i, j, k) { -printf(a,b,c,d,e,f,g,h,i,j,k); + printf(a, b, c, d, e, f, g, h, i, j, k); } -iopen() {} +iopen() +{ +} AssertionFailed() { -printf("assertion failed\n"); -exit(-1); + printf("assertion failed\n"); + exit(-1); } Abort() { -printf("Aborting\n"); -exit(-1); + printf("Aborting\n"); + exit(-1); } main(argc, argv) -int argc; -char **argv; { + int argc; + char **argv; +{ VInitVolumePackage(1, 0, 0, 0, 0); VPrintDiskStats(); } - diff --git a/src/vol/test/updateDirInode.c b/src/vol/test/updateDirInode.c index 02d52f815..156a3382f 100644 --- a/src/vol/test/updateDirInode.c +++ b/src/vol/test/updateDirInode.c @@ -17,7 +17,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/updateDirInode.c,v 1.1.1.4 2001/07/14 22:25:06 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/updateDirInode.c,v 1.5 2003/07/15 23:17:46 shadow Exp $"); #include #include @@ -26,7 +27,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/updateDirInode.c,v 1.1.1.4 200 #if !defined(AFS_SGI_ENV) #ifdef AFS_OSF_ENV #include -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #ifdef AFS_VFSINCL_ENV #define VFS #ifdef AFS_SUN5_ENV @@ -38,8 +39,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/updateDirInode.c,v 1.1.1.4 200 #ifndef AFS_AIX_ENV #include #endif -#endif AFS_VFSINCL_ENV -#endif /* AFS_OSF_ENV */ +#endif /* AFS_VFSINCL_ENV */ +#endif /* AFS_OSF_ENV */ #endif /* AFS_SGI_ENV */ #include #include @@ -73,7 +74,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/updateDirInode.c,v 1.1.1.4 200 /* #include */ -#include "efs.h" /* until 5.1 release */ +#include "efs.h" /* until 5.1 release */ #define ROOTINO EFS_ROOTINO #else @@ -111,11 +112,11 @@ extern void *calloc(), *realloc(); #endif #include "salvage.h" int volumeId; -int VolumeChanged; /* to satisfy library libdir use */ +int VolumeChanged; /* to satisfy library libdir use */ #include "listVicepx.h" -char* orphan_NoVnode = "ORPHANED_NoVnode"; -char* orphan_NoUnique = "ORPHANED_NoUnique"; +char *orphan_NoVnode = "ORPHANED_NoVnode"; +char *orphan_NoUnique = "ORPHANED_NoUnique"; #define READBUFSIZE 5*1024 @@ -123,166 +124,149 @@ char* orphan_NoUnique = "ORPHANED_NoUnique"; #define verbose 0x01 #define update 0x02 /* update specified dir inode */ -int -Usage( name) -char* name; +int +Usage(name) + char *name; { - assert(name); - printf("Usage is %s -p -v -dirInode -f -verbose\n", name); - exit(1); + assert(name); + printf + ("Usage is %s -p -v -dirInode -f -verbose\n", + name); + exit(1); } - + main(argc, argv) -int argc; -char* argv[]; + int argc; + char *argv[]; { - char fullName[32+VNAMESIZE+sizeof(VHDREXT)+4]; - char partition[32], volume[VNAMESIZE]; - struct stat statBuf; - struct VolumeHeader volumeHeader; - int fd,i, sawPart=0, sawVolume=0, sawDirContents=0, sawDirFile=0; - char option = allNull; /* no default options */ - Inode dirInode; /* destination dir Inode */ - char* fileName; /* source directory file */ - - for (i = 1; i < argc; i++) - { - if (!strcmp(argv[i], "-p")) - { - if ( (i+1) >= argc ) - Usage(argv[0]); - assert(strlen(argv[i+1]) < 32 ); - strcpy( partition, argv[++i]); - sawPart = 1; - } - else if ( !strcmp(argv[i], "-v")) - { - if ( (i+1) >= argc ) - Usage(argv[0]); - assert(strlen(argv[i+1]) < VNAMESIZE ); - strcpy( volume, argv[++i]); - sawVolume = 1; - } - else if ( !strcmp(argv[i], "-dirInode")) - { - if ( (i+1) >= argc ) - Usage(argv[0]); - dirInode = atoi(argv[++i]); - sawDirContents = 1; - option |= update; - } - else if ( !strcmp(argv[i], "-f")) - { - if ( (i+1) >= argc ) - Usage(argv[0]); - fileName = argv[++i]; - sawDirFile = 1; - } - else if ( !strcmp(argv[i], "-verbose")) - option |= verbose; - else + char fullName[32 + VNAMESIZE + sizeof(VHDREXT) + 4]; + char partition[32], volume[VNAMESIZE]; + struct stat statBuf; + struct VolumeHeader volumeHeader; + int fd, i, sawPart = 0, sawVolume = 0, sawDirContents = 0, sawDirFile = 0; + char option = allNull; /* no default options */ + Inode dirInode; /* destination dir Inode */ + char *fileName; /* source directory file */ + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-p")) { + if ((i + 1) >= argc) Usage(argv[0]); - } + assert(strlen(argv[i + 1]) < 32); + strcpy(partition, argv[++i]); + sawPart = 1; + } else if (!strcmp(argv[i], "-v")) { + if ((i + 1) >= argc) + Usage(argv[0]); + assert(strlen(argv[i + 1]) < VNAMESIZE); + strcpy(volume, argv[++i]); + sawVolume = 1; + } else if (!strcmp(argv[i], "-dirInode")) { + if ((i + 1) >= argc) + Usage(argv[0]); + dirInode = atoi(argv[++i]); + sawDirContents = 1; + option |= update; + } else if (!strcmp(argv[i], "-f")) { + if ((i + 1) >= argc) + Usage(argv[0]); + fileName = argv[++i]; + sawDirFile = 1; + } else if (!strcmp(argv[i], "-verbose")) + option |= verbose; + else + Usage(argv[0]); + } - /* option to verify whether input file is syntactically good */ - if ( sawDirFile && !sawPart && !sawVolume && !sawDirContents) - { - scanDirFile(0, 0, fileName, option); - exit(2); - } + /* option to verify whether input file is syntactically good */ + if (sawDirFile && !sawPart && !sawVolume && !sawDirContents) { + scanDirFile(0, 0, fileName, option); + exit(2); + } - /* check input parameters */ - if ( !sawPart || !sawVolume || !sawDirFile || !sawDirContents) - Usage(argv[0]); + /* check input parameters */ + if (!sawPart || !sawVolume || !sawDirFile || !sawDirContents) + Usage(argv[0]); - /* extract volume id */ - volumeId = atoi(volume); + /* extract volume id */ + volumeId = atoi(volume); - /* construct unix file name */ - strcpy(fullName, partition); - strcat(fullName,"/V"); - strcat(fullName,volume); - strcat(fullName, VHDREXT); + /* construct unix file name */ + strcpy(fullName, partition); + strcat(fullName, "/V"); + strcat(fullName, volume); + strcat(fullName, VHDREXT); - /* check to see that volume exists */ - if ( stat(fullName, &statBuf) < 0 ) - { - printf("Error in stat(%s) : %d\n", fullName, errno); - exit(2); - } + /* check to see that volume exists */ + if (stat(fullName, &statBuf) < 0) { + printf("Error in stat(%s) : %d\n", fullName, errno); + exit(2); + } - /* read volume header */ - if ( (fd=open(fullName, O_RDONLY)) < 0 ) - { - printf("Error in open(%s) : %d\n", fullName, errno); - exit(3); - } - if ( read(fd, &volumeHeader, sizeof(struct VolumeHeader)) < sizeof(struct VolumeHeader)) - { - printf("Error in reading Volume Header : %d\n", errno); - exit(4); - } + /* read volume header */ + if ((fd = open(fullName, O_RDONLY)) < 0) { + printf("Error in open(%s) : %d\n", fullName, errno); + exit(3); + } + if (read(fd, &volumeHeader, sizeof(struct VolumeHeader)) < + sizeof(struct VolumeHeader)) { + printf("Error in reading Volume Header : %d\n", errno); + exit(4); + } - scanDirFile(statBuf.st_dev, dirInode, fileName, option); - close(fd); + scanDirFile(statBuf.st_dev, dirInode, fileName, option); + close(fd); } -int +int scanDirFile(dev, node, fileName, option) -dev_t dev; -Inode node; /* destination directory inode number */ -char* fileName; /* source file to update from */ -char option; /* user options */ + dev_t dev; + Inode node; /* destination directory inode number */ + char *fileName; /* source file to update from */ + char option; /* user options */ { - int fd, i, j, temp; - FILE* fp; - char dirPage[2048]; - char buf[READBUFSIZE]; /* read buffer */ - struct DirHeader *dhp= (struct DirHeader*)&dirPage[0]; - struct stat statBuf; - int pgCount = 0; /* current page */ - + int fd, i, j, temp; + FILE *fp; + char dirPage[2048]; + char buf[READBUFSIZE]; /* read buffer */ + struct DirHeader *dhp = (struct DirHeader *)&dirPage[0]; + struct stat statBuf; + int pgCount = 0; /* current page */ + /* open this directory source file */ - if ( (fp = fopen(fileName, "r")) == 0 ) - { - printf("fopen of %s failed : %d\n", fileName, errno); - exit(6); + if ((fp = fopen(fileName, "r")) == 0) { + printf("fopen of %s failed : %d\n", fileName, errno); + exit(6); } - fgets(buf, READBUFSIZE, fp); /* ignore "Alloc map:" */ - for ( i=0; i < MAXPAGES; i++) /* read alloMap */ - { + fgets(buf, READBUFSIZE, fp); /* ignore "Alloc map:" */ + for (i = 0; i < MAXPAGES; i++) { /* read alloMap */ fscanf(fp, "%x", &temp); - dhp->alloMap[i] = ( unsigned char )temp; + dhp->alloMap[i] = (unsigned char)temp; } - fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ + fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ - fgets(buf, READBUFSIZE, fp); /* ignore "Hash map:" */ - for ( i=0; i < NHASHENT; i++) - { + fgets(buf, READBUFSIZE, fp); /* ignore "Hash map:" */ + for (i = 0; i < NHASHENT; i++) { fscanf(fp, "%d", &temp); dhp->hashTable[i] = (unsigned short)temp; } - fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ - - while ( ReadPage(fp, dhp, pgCount)) /* read from source file */ - { - if ( option & verbose ) - PrintDir(dhp, pgCount); - if ( option & update ) /* update destnation dir inode */ - { - if ( pgCount == 0 ) /* first page */ - if ( (fd = iopen(dev, node, O_WRONLY)) < 0 ) - { + fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ + + while (ReadPage(fp, dhp, pgCount)) { /* read from source file */ + if (option & verbose) + PrintDir(dhp, pgCount); + if (option & update) { /* update destnation dir inode */ + if (pgCount == 0) /* first page */ + if ((fd = iopen(dev, node, O_WRONLY)) < 0) { printf("Error in opening destination inode %d(err %d)\n", - node, errno); + node, errno); exit(1); } - if ( write(fd, dirPage, sizeof(dirPage)) != sizeof(dirPage)) - { + if (write(fd, dirPage, sizeof(dirPage)) != sizeof(dirPage)) { printf("Error in writing %d th page into inode %d(err %d)\n", - pgCount, node, errno); + pgCount, node, errno); exit(1); } } @@ -294,68 +278,64 @@ char option; /* user options */ /* prints out a directory data */ PrintDir(dhp, pgCount) -struct DirHeader *dhp; -int pgCount; /* current page Number */ + struct DirHeader *dhp; + int pgCount; /* current page Number */ { int i; - struct DirEntry *de; + struct DirEntry *de; struct PageHeader *pg; - if ( pgCount == 0 ) /* first page */ - { - printf("Alloc map: "); - for ( i=0; i < MAXPAGES; i++) /* read alloMap */ - { - if ( (i % 16) == 0 ) - printf("\n"); + if (pgCount == 0) { /* first page */ + printf("Alloc map: "); + for (i = 0; i < MAXPAGES; i++) { /* read alloMap */ + if ((i % 16) == 0) + printf("\n"); printf("%.2x ", dhp->alloMap[i]); - } - printf("\nHash table:"); - for ( i=0; i < NHASHENT; i++) - { - if ( (i % 16) == 0 ) - printf("\n"); - printf("%.2d ", dhp->hashTable[i]); - } - printf("\n"); - - /* print page header info */ - printf("--------------- Page 0 ---------------\n"); + } + printf("\nHash table:"); + for (i = 0; i < NHASHENT; i++) { + if ((i % 16) == 0) + printf("\n"); + printf("%.2d ", dhp->hashTable[i]); + } + printf("\n"); + + /* print page header info */ + printf("--------------- Page 0 ---------------\n"); printf("pgcnt :%d\n", dhp->header.pgcount); printf("tag :%d\n", dhp->header.tag); printf("freecnt :%d(not used)\n", dhp->header.freecount); printf("freebitmap :"); - for ( i=0; i < EPP/8; i++) - printf("%.2x ", (unsigned char)(dhp->header.freebitmap[i])); + for (i = 0; i < EPP / 8; i++) + printf("%.2x ", (unsigned char)(dhp->header.freebitmap[i])); printf("\n"); - /* print slots in the first page of this directory */ - de = ((struct DirPage0 *)dhp)->entry; - for(i=DHE+1; iflag, de->length, de->next, - de->fid.vnode, de->fid.vunique, de->name); - } - else - { - pg = &((struct DirPage1 *)dhp)->header; /* page header */ + /* print slots in the first page of this directory */ + de = ((struct DirPage0 *)dhp)->entry; + for (i = DHE + 1; i < EPP; + i++, de = (struct DirEntry *)((char *)de + 32)) + printf("ent %d: f=%d l=%d n=%d vn=%d vu=%d name:%s\n", i, + de->flag, de->length, de->next, de->fid.vnode, + de->fid.vunique, de->name); + } else { + pg = &((struct DirPage1 *)dhp)->header; /* page header */ de = ((struct DirPage1 *)dhp)->entry; /* print page header info */ printf("--------------- Page %d ---------------\n", pgCount); - printf("pgcnt :%d\n", pg->pgcount); - printf("tag :%d\n", pg->tag); - printf("freecnt :%d(not used)\n", pg->freecount); - printf("freebitmap :"); - for ( i=0; i < EPP/8; i++) - printf("%.2x ", (unsigned char)(pg->freebitmap[i])); - printf("\n"); - - /* print slots in this page */ - for(i=1; iflag, de->length, de->next, - de->fid.vnode, de->fid.vunique, de->name); + printf("pgcnt :%d\n", pg->pgcount); + printf("tag :%d\n", pg->tag); + printf("freecnt :%d(not used)\n", pg->freecount); + printf("freebitmap :"); + for (i = 0; i < EPP / 8; i++) + printf("%.2x ", (unsigned char)(pg->freebitmap[i])); + printf("\n"); + + /* print slots in this page */ + for (i = 1; i < EPP; i++, de = (struct DirEntry *)((char *)de + 32)) + printf("ent %d: f=%d l=%d n=%d vn=%d vu=%d name:%s\n", i, + de->flag, de->length, de->next, de->fid.vnode, + de->fid.vunique, de->name); } } @@ -363,98 +343,87 @@ int pgCount; /* current page Number */ ** Returns 0 if there are no more pages ** Returns 1 if there are more pages to be read */ -ReadPage(fp, dhp, pageNo) /* Read one page(pageNo) from file fp into dhp*/ -FILE* fp; -struct DirHeader *dhp; -int pageNo; +ReadPage(fp, dhp, pageNo) /* Read one page(pageNo) from file fp into dhp */ + FILE *fp; + struct DirHeader *dhp; + int pageNo; { - int pgcnt, page, freecnt, freebit[EPP/8]; - int tag; - char buf[READBUFSIZE]; /* read buffer */ - int start; - int i, ent, f, l, n, vnode, unique; - char dirName[18]; - struct DirEntry *dirEntry; - struct PageHeader *pageHeader; - - if(fscanf(fp,"--------------- Page %d ---------------\n",&page)!=1) - { + int pgcnt, page, freecnt, freebit[EPP / 8]; + int tag; + char buf[READBUFSIZE]; /* read buffer */ + int start; + int i, ent, f, l, n, vnode, unique; + char dirName[18]; + struct DirEntry *dirEntry; + struct PageHeader *pageHeader; + + if (fscanf(fp, "--------------- Page %d ---------------\n", &page) != 1) { return 0; /* no more pages */ } /* defensive check */ - if ( page != pageNo ) - { + if (page != pageNo) { printf("Wrong page: pageNo %d does not match data in file %d\n", - pageNo, page); + pageNo, page); exit(1); } - if ( fscanf(fp, "pgcnt :%d", &pgcnt) != 1 ) - { + if (fscanf(fp, "pgcnt :%d", &pgcnt) != 1) { printf("Error in looking for pgcnt: in page %d\n", pageNo); exit(1); } - fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ + fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ - if ( fscanf(fp, "tag :%d", &tag) != 1 ) - { + if (fscanf(fp, "tag :%d", &tag) != 1) { printf("Error in looking for tag: in page %d\n", pageNo); exit(1); } - fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ + fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ - if ( fscanf(fp, "freecnt :%d", &freecnt) != 1 ) - { + if (fscanf(fp, "freecnt :%d", &freecnt) != 1) { printf("Error in looking for freecnt: in page %d\n", pageNo); exit(1); } - fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ + fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ - if ( fscanf(fp, "freebitmap :%x %x %x %x %x %x %x %x", - &freebit[0], &freebit[1], &freebit[2], &freebit[3], - &freebit[4], &freebit[5], &freebit[6], &freebit[7]) != 8 ) - { + if (fscanf + (fp, "freebitmap :%x %x %x %x %x %x %x %x", &freebit[0], &freebit[1], + &freebit[2], &freebit[3], &freebit[4], &freebit[5], &freebit[6], + &freebit[7]) != 8) { printf("Error in looking for freecnt: in page %d\n", pageNo); exit(1); } - fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ + fgets(buf, READBUFSIZE, fp); /* ignore trailing spaces */ - if ( pageNo == 0 ) /* first page */ - { - start = DHE+1; /* this is 13 */ + if (pageNo == 0) { /* first page */ + start = DHE + 1; /* this is 13 */ dirEntry = ((struct DirPage0 *)dhp)->entry; - pageHeader = &(dhp->header); - } - else - { + pageHeader = &(dhp->header); + } else { start = 1; dirEntry = ((struct DirPage1 *)dhp)->entry; - pageHeader = &( ((struct DirPage1 *)dhp)->header); + pageHeader = &(((struct DirPage1 *)dhp)->header); } - /* update page header */ + /* update page header */ pageHeader->pgcount = pgcnt; - pageHeader->tag = tag; - pageHeader->freecount = freecnt; /* this is currently unused */ - for ( i=0; i < EPP/8; i++) + pageHeader->tag = tag; + pageHeader->freecount = freecnt; /* this is currently unused */ + for (i = 0; i < EPP / 8; i++) pageHeader->freebitmap[i] = freebit[i]; - /* update directory entries */ - for ( ; start < EPP; start++ ) - { - if ( fscanf(fp, "ent %d: f=%d l=%d n=%d vn=%d vu=%d name:%s\n", - &ent, &f, &l, &n, &vnode, &unique, dirName) != 7 ) - { - printf("Error in reading the %d th entry in page %d\n", - start, pageNo); + /* update directory entries */ + for (; start < EPP; start++) { + if (fscanf + (fp, "ent %d: f=%d l=%d n=%d vn=%d vu=%d name:%s\n", &ent, &f, &l, + &n, &vnode, &unique, dirName) != 7) { + printf("Error in reading the %d th entry in page %d\n", start, + pageNo); exit(1); - } - if ( ent != start ) - { - printf("Wrong dir entry: found %d, has to be %\n", - ent, start); + } + if (ent != start) { + printf("Wrong dir entry: found %d, has to be %\n", ent, start); exit(1); - } + } dirEntry->flag = f; dirEntry->length = l; dirEntry->next = n; @@ -463,7 +432,7 @@ int pageNo; memcpy(dirEntry->name, dirName, 18); strncpy(dirEntry->name, dirName); - dirEntry = ( struct DirEntry *) ( (char *)dirEntry + 32 ); + dirEntry = (struct DirEntry *)((char *)dirEntry + 32); } - return 1; /* there are more pages */ + return 1; /* there are more pages */ } diff --git a/src/vol/test/utilities.c b/src/vol/test/utilities.c index 0219306c8..46cb934b9 100644 --- a/src/vol/test/utilities.c +++ b/src/vol/test/utilities.c @@ -10,124 +10,125 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/test/utilities.c,v 1.1.1.4 2001/07/14 22:25:05 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/test/utilities.c,v 1.5 2003/07/15 23:17:46 shadow Exp $"); #include #include #include "listVicepx.h" -DirEnt* hash[MAX_HASH_SIZE]; -static char* stack[MAX_STACK_SIZE]; -static int stackSize; -static char fileName[2048]; +DirEnt *hash[MAX_HASH_SIZE]; +static char *stack[MAX_STACK_SIZE]; +static int stackSize; +static char fileName[2048]; /* hashes a number in the range 1.. MAX_HASH_SIZE */ mountHash(num) -int num; + int num; { - return ( num % MAX_HASH_SIZE); + return (num % MAX_HASH_SIZE); } - + /* insert entry in hash table */ -insertHash( dir) -DirEnt* dir; +insertHash(dir) + DirEnt *dir; { - int h; - h = mountHash(dir->vnode); - - /* insert in hash table */ - dir->next = hash[h]; - hash[h] = dir; + int h; + h = mountHash(dir->vnode); + + /* insert in hash table */ + dir->next = hash[h]; + hash[h] = dir; } DirEnt * lookup(vnode) -int vnode; + int vnode; { - DirEnt* ptr; - ptr = hash[ mountHash(vnode) ]; - while ( ptr ) - if ( ptr->vnode == vnode ) - return ptr; - else ptr = ptr->next; - return 0; + DirEnt *ptr; + ptr = hash[mountHash(vnode)]; + while (ptr) + if (ptr->vnode == vnode) + return ptr; + else + ptr = ptr->next; + return 0; } -char* +char * getDirName(dir, node) -DirEnt* dir; -int node; + DirEnt *dir; + int node; { - int i; - for ( i=0; i < dir->numEntries; i++) - if ( dir->vnodeName[i].vnode == node ) - return dir->vnodeName[i].name; - return 0; + int i; + for (i = 0; i < dir->numEntries; i++) + if (dir->vnodeName[i].vnode == node) + return dir->vnodeName[i].name; + return 0; } - + /* this shud be called on a vnode for a file only */ -char* +char * getFileName(dir, unique) -DirEnt* dir; -int unique; + DirEnt *dir; + int unique; { - /* go down the linked list */ - int i; - for ( i= 0; i < dir->numEntries; i++) - if ( dir->vnodeName[i].vunique == unique ) - return dir->vnodeName[i].name; - return 0; + /* go down the linked list */ + int i; + for (i = 0; i < dir->numEntries; i++) + if (dir->vnodeName[i].vunique == unique) + return dir->vnodeName[i].name; + return 0; } - + /* for debugging */ printHash() { - int i, j; - for ( i=0; i < MAX_HASH_SIZE; i++) - { - DirEnt * ptr = hash[i]; - while ( ptr ) - { + int i, j; + for (i = 0; i < MAX_HASH_SIZE; i++) { + DirEnt *ptr = hash[i]; + while (ptr) { #ifdef DEBUG - printf ("Vnode: %d Parent Vnode : %d \n", ptr->vnode, ptr->vnodeParent); + printf("Vnode: %d Parent Vnode : %d \n", ptr->vnode, + ptr->vnodeParent); #endif - for ( j=0; j < ptr->numEntries; j++) - printf("\t %s %d %d\n", ptr->vnodeName[j].name, - ptr->vnodeName[j].vnode, ptr->vnodeName[j].vunique); - ptr = ptr->next; - } + for (j = 0; j < ptr->numEntries; j++) + printf("\t %s %d %d\n", ptr->vnodeName[j].name, + ptr->vnodeName[j].vnode, ptr->vnodeName[j].vunique); + ptr = ptr->next; } -} + } +} -pushStack ( name ) -char* name; +pushStack(name) + char *name; { - assert( stackSize < MAX_STACK_SIZE ); - assert( stack[stackSize] = (char *)malloc ( strlen(name) + 1 )); - strcpy( stack[stackSize], name ); - stackSize++; + assert(stackSize < MAX_STACK_SIZE); + assert(stack[stackSize] = (char *)malloc(strlen(name) + 1)); + strcpy(stack[stackSize], name); + stackSize++; } -char* +char * popStack() { - if ( stackSize == 0 ) return 0; /* stack empty */ - return stack[--stackSize]; + if (stackSize == 0) + return 0; /* stack empty */ + return stack[--stackSize]; } -char* +char * printStack() { - char* name; - fileName[0] = 0; - while ( name = popStack() ) - { - strcat(fileName, "/"); - strcat(fileName, name ); - free(name); - } - return fileName; + char *name; + fileName[0] = 0; + while (name = popStack()) { + strcat(fileName, "/"); + strcat(fileName, name); + free(name); + } + return fileName; } diff --git a/src/vol/viceinode.h b/src/vol/viceinode.h index 015d673fb..cbf1a0117 100644 --- a/src/vol/viceinode.h +++ b/src/vol/viceinode.h @@ -20,23 +20,23 @@ /* The four inode parameters for most inodes (files, directories, symbolic links) */ struct InodeParams { - VolId volumeId; - VnodeId vnodeNumber; - Unique vnodeUniquifier; - FileVersion inodeDataVersion; + VolId volumeId; + VnodeId vnodeNumber; + Unique vnodeUniquifier; + FileVersion inodeDataVersion; }; /* The four inode parameters for special inodes, i.e. the descriptive inodes for a volume */ struct SpecialInodeParams { - VolId volumeId; - VnodeId vnodeNumber; /* this must be INODESPECIAL */ + VolId volumeId; + VnodeId vnodeNumber; /* this must be INODESPECIAL */ #ifdef AFS_3DISPARES - VolId parentId; - int type; + VolId parentId; + int type; #else - int type; - VolId parentId; + int type; + VolId parentId; #endif }; @@ -45,20 +45,20 @@ struct SpecialInodeParams { these correspond to the params.fsck array of this record. */ struct ViceInodeInfo { - Inode inodeNumber; - int byteCount; - int linkCount; + Inode inodeNumber; + afs_fsize_t byteCount; + int linkCount; union { - bit32 param[4]; - struct InodeParams vnode; + bit32 param[4]; + struct InodeParams vnode; struct SpecialInodeParams special; } u; -}; +}; #ifdef AFS_3DISPARES -#define INODESPECIAL 0x1fffffff +#define INODESPECIAL 0x1fffffff #else -#define INODESPECIAL 0xffffffff +#define INODESPECIAL 0xffffffff #endif /* Special inode types. Be careful of the ordering. Must start at 1. See vutil.h */ diff --git a/src/vol/vnode.c b/src/vol/vnode.c index 79af3f990..1bfde891d 100644 --- a/src/vol/vnode.c +++ b/src/vol/vnode.c @@ -16,10 +16,18 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vnode.c,v 1.1.1.8 2003/04/13 19:08:18 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/vnode.c,v 1.18 2003/11/29 21:38:05 jaltman Exp $"); #include #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #ifdef AFS_PTHREAD_ENV #include #else /* AFS_PTHREAD_ENV */ @@ -35,8 +43,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vnode.c,v 1.1.1.8 2003/04/13 19:08: #include #include "ihandle.h" #include "vnode.h" -#include "partition.h" #include "volume.h" +#include "partition.h" #if defined(AFS_SGI_ENV) #include "sys/types.h" #include "fcntl.h" @@ -55,13 +63,17 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vnode.c,v 1.1.1.8 2003/04/13 19:08: #include #endif /* AFS_NT40_ENV */ #include -#include + +/*@printflike@*/ extern void Log(const char *format, ...); + +/*@printflike@*/ extern void Abort(const char *format, ...); + struct VnodeClassInfo VnodeClassInfo[nVNODECLASSES]; -private int moveHash(); -void StickOnLruChain_r(); -void VPutVnode_r(); +private int moveHash(register Vnode * vnp, bit32 newHash); +void StickOnLruChain_r(register Vnode * vnp, + register struct VnodeClassInfo *vcp); #define BAD_IGET -1000 @@ -90,10 +102,11 @@ void VPutVnode_r(); /* logging stuff for finding bugs */ #define THELOGSIZE 5120 static afs_int32 theLog[THELOGSIZE]; -static afs_int32 vnLogPtr=0; +static afs_int32 vnLogPtr = 0; VNLog(aop, anparms, av1, av2, av3, av4) -afs_int32 aop, anparms; -afs_int32 av1, av2, av3,av4; { + afs_int32 aop, anparms; + afs_int32 av1, av2, av3, av4; +{ register afs_int32 temp; afs_int32 data[4]; @@ -102,14 +115,17 @@ afs_int32 av1, av2, av3,av4; { data[1] = av2; data[2] = av3; data[3] = av4; - if (anparms>4) anparms = 4; /* do bounds checking */ + if (anparms > 4) + anparms = 4; /* do bounds checking */ - temp = (aop<<16) | anparms; + temp = (aop << 16) | anparms; theLog[vnLogPtr++] = temp; - if (vnLogPtr >= THELOGSIZE) vnLogPtr = 0; - for(temp=0;temp= THELOGSIZE) + vnLogPtr = 0; + for (temp = 0; temp < anparms; temp++) { theLog[vnLogPtr++] = data[temp]; - if (vnLogPtr >= THELOGSIZE) vnLogPtr = 0; + if (vnLogPtr >= THELOGSIZE) + vnLogPtr = 0; } } @@ -122,15 +138,18 @@ afs_int32 av1, av2, av3,av4; { * when there are not many volumes represented), and spread * equally amongst vnodes within a single volume. */ -int VolumeHashOffset_r() { +int +VolumeHashOffset_r(void) +{ static int nextVolumeHashOffset = 0; /* hashindex Must be power of two in size */ # define hashShift 3 # define hashMask ((1<>hashShift); + offset = hashindex[nextVolumeHashOffset & hashMask] + + (nextVolumeHashOffset >> hashShift); nextVolumeHashOffset++; return offset; } @@ -144,40 +163,41 @@ private Vnode *VnodeHashTable[VNODE_HASH_TABLE_SIZE]; /* Code to invalidate a vnode entry. Called when we've damaged a vnode, and want to prevent future VGetVnode's from applying to it. Leaves it in the same hash bucket but that shouldn't be important. */ -VInvalidateVnode_r(avnode) -register struct Vnode *avnode; { - avnode->changed_newTime = 0; /* don't let it get flushed out again */ +void +VInvalidateVnode_r(register struct Vnode *avnode) +{ + avnode->changed_newTime = 0; /* don't let it get flushed out again */ avnode->changed_oldTime = 0; - avnode->delete = 0; /* it isn't deleted, erally */ - avnode->cacheCheck = 0; /* invalid: prevents future vnode searches from working */ + avnode->delete = 0; /* it isn't deleted, erally */ + avnode->cacheCheck = 0; /* invalid: prevents future vnode searches from working */ } /* Not normally called by general client; called by volume.c */ -VInitVnodes(class,nVnodes) - VnodeClass class; - int nVnodes; +int +VInitVnodes(VnodeClass class, int nVnodes) { byte *va; register struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; vcp->allocs = vcp->gets = vcp->reads = vcp->writes = 0; vcp->cacheSize = nVnodes; - switch(class) { - case vSmall: - assert(CHECKSIZE_SMALLVNODE); + switch (class) { + case vSmall: + assert(CHECKSIZE_SMALLVNODE); vcp->lruHead = NULL; - vcp->residentSize = SIZEOF_SMALLVNODE; + vcp->residentSize = SIZEOF_SMALLVNODE; vcp->diskSize = SIZEOF_SMALLDISKVNODE; vcp->magic = SMALLVNODEMAGIC; break; - case vLarge: + case vLarge: vcp->lruHead = NULL; vcp->residentSize = SIZEOF_LARGEVNODE; vcp->diskSize = SIZEOF_LARGEDISKVNODE; vcp->magic = LARGEVNODEMAGIC; - break; + break; } - { int s = vcp->diskSize-1; + { + int s = vcp->diskSize - 1; int n = 0; while (s) s >>= 1, n++; @@ -185,13 +205,13 @@ VInitVnodes(class,nVnodes) } if (nVnodes == 0) - return 0; + return 0; - va = (byte *) calloc(nVnodes,vcp->residentSize); - assert (va != NULL); + va = (byte *) calloc(nVnodes, vcp->residentSize); + assert(va != NULL); while (nVnodes--) { Vnode *vnp = (Vnode *) va; - vnp->nUsers = 0; /* no context switches */ + vnp->nUsers = 0; /* no context switches */ Lock_Init(&vnp->lock); vnp->changed_oldTime = 0; vnp->changed_newTime = 0; @@ -203,7 +223,7 @@ VInitVnodes(class,nVnodes) #else /* AFS_PTHREAD_ENV */ vnp->writer = (PROCESS) 0; #endif /* AFS_PTHREAD_ENV */ - vnp->hashIndex = 0; + vnp->hashIndex = 0; vnp->handle = NULL; if (vcp->lruHead == NULL) vcp->lruHead = vnp->lruNext = vnp->lruPrev = vnp; @@ -223,8 +243,9 @@ VInitVnodes(class,nVnodes) /* allocate an *unused* vnode from the LRU chain, going backwards of course. It shouldn't be necessary to specify that nUsers == 0 since if it is in the list, nUsers should be 0. Things shouldn't be in lruq unless no one is using them. */ -Vnode *VGetFreeVnode_r(vcp) -struct VnodeClassInfo *vcp; { +Vnode * +VGetFreeVnode_r(struct VnodeClassInfo * vcp) +{ register Vnode *vnp; vnp = vcp->lruHead->lruPrev; @@ -235,27 +256,21 @@ struct VnodeClassInfo *vcp; { return vnp; } -static mlkReason=0; +static mlkReason = 0; static mlkLastAlloc = 0; static mlkLastOver = 0; static mlkLastDelete = 0; -Vnode *VAllocVnode(ec,vp,type) - Error *ec; - Volume *vp; - VnodeType type; +Vnode * +VAllocVnode(Error * ec, Volume * vp, VnodeType type) { Vnode *retVal; - VOL_LOCK - retVal = VAllocVnode_r(ec, vp, type); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VAllocVnode_r(ec, vp, type); + VOL_UNLOCK return retVal; } -Vnode *VAllocVnode_r(ec,vp,type) - Error *ec; - Volume *vp; - VnodeType type; +Vnode * +VAllocVnode_r(Error * ec, Volume * vp, VnodeType type) { register Vnode *vnp; VnodeId vnodeNumber; @@ -277,16 +292,16 @@ Vnode *VAllocVnode_r(ec,vp,type) vcp = &VnodeClassInfo[class]; if (!VolumeWriteable(vp)) { - *ec = VREADONLY; + *ec = (bit32) VREADONLY; return NULL; } unique = vp->nextVnodeUnique++; if (!unique) - unique = vp->nextVnodeUnique++; + unique = vp->nextVnodeUnique++; if (vp->nextVnodeUnique > V_uniquifier(vp)) { - VUpdateVolume_r(ec,vp); + VUpdateVolume_r(ec, vp); if (*ec) return NULL; } @@ -298,26 +313,25 @@ Vnode *VAllocVnode_r(ec,vp,type) } /* Find a slot in the bit map */ - bitNumber = VAllocBitmapEntry_r(ec,vp,&vp->vnodeIndex[class]); + bitNumber = VAllocBitmapEntry_r(ec, vp, &vp->vnodeIndex[class]); if (*ec) - return NULL; - vnodeNumber = bitNumberToVnodeNumber(bitNumber,class); + return NULL; + vnodeNumber = bitNumberToVnodeNumber(bitNumber, class); VNLog(2, 1, vnodeNumber); /* Prepare to move it to the new hash chain */ newHash = VNODE_HASH(vp, vnodeNumber); for (vnp = VnodeHashTable[newHash]; - vnp && (vnp->vnodeNumber!=vnodeNumber || vnp->volumePtr!=vp - || vnp->volumePtr->cacheCheck!=vnp->cacheCheck); - vnp = vnp->hashNext - ); + vnp && (vnp->vnodeNumber != vnodeNumber || vnp->volumePtr != vp + || vnp->volumePtr->cacheCheck != vnp->cacheCheck); + vnp = vnp->hashNext); if (vnp) { /* slot already exists. May even not be in lruq (consider store file locking a file being deleted) - so we may have to wait for it below */ + * so we may have to wait for it below */ VNLog(3, 2, vnodeNumber, (afs_int32) vnp); /* If first user, remove it from the LRU chain. We can assume that - there is at least one item in the queue */ + * there is at least one item in the queue */ if (++vnp->nUsers == 1) { if (vnp == vcp->lruHead) vcp->lruHead = vcp->lruHead->lruNext; @@ -329,17 +343,14 @@ Vnode *VAllocVnode_r(ec,vp,type) ObtainWriteLock(&vnp->lock); } else { /* follow locking hierarchy */ - VOL_UNLOCK - ObtainWriteLock(&vnp->lock); - VOL_LOCK - } + VOL_UNLOCK ObtainWriteLock(&vnp->lock); + VOL_LOCK} #ifdef AFS_PTHREAD_ENV vnp->writer = pthread_self(); #else /* AFS_PTHREAD_ENV */ LWP_CurrentProcess(&vnp->writer); #endif /* AFS_PTHREAD_ENV */ - } - else { + } else { vnp = VGetFreeVnode_r(vcp); /* Remove vnode from LRU chain and grab a write lock */ if (vnp == vcp->lruHead) @@ -349,7 +360,7 @@ Vnode *VAllocVnode_r(ec,vp,type) if (vnp == vcp->lruHead || vcp->lruHead == NULL) Abort("VGetVnode: lru chain addled!\n"); /* Initialize the header fields so noone allocates another - vnode with the same number */ + * vnode with the same number */ vnp->vnodeNumber = vnodeNumber; vnp->volumePtr = vp; vnp->cacheCheck = vp->cacheCheck; @@ -363,35 +374,35 @@ Vnode *VAllocVnode_r(ec,vp,type) LWP_CurrentProcess(&vnp->writer); #endif /* AFS_PTHREAD_ENV */ /* Sanity check: is this vnode really not in use? */ - { - int size; - IHandle_t *ihP = vp->vnodeIndex[class].handle; - FdHandle_t *fdP; - off_t off = vnodeIndexOffset(vcp, vnodeNumber); - - VOL_UNLOCK - fdP = IH_OPEN(ihP); - if (fdP == NULL) - Abort("VAllocVnode: can't open index file!\n"); - if ((size = FDH_SIZE(fdP)) < 0) - Abort("VAllocVnode: can't stat index file!\n"); - if (FDH_SEEK(fdP, off, SEEK_SET) < 0) - Abort("VAllocVnode: can't seek on index file!\n"); - if (off < size) { - if (FDH_READ(fdP, &vnp->disk, vcp->diskSize) == vcp->diskSize) { - if (vnp->disk.type != vNull) - Abort("VAllocVnode: addled bitmap or index!\n"); - } - } else { - /* growing file - grow in a reasonable increment */ - char *buf = (char *)malloc(16*1024); - memset(buf, 0, 16*1024); - FDH_WRITE(fdP, buf, 16*1024); - free(buf); - } - FDH_CLOSE(fdP); - VOL_LOCK - } + { + int size; + IHandle_t *ihP = vp->vnodeIndex[class].handle; + FdHandle_t *fdP; + off_t off = vnodeIndexOffset(vcp, vnodeNumber); + + VOL_UNLOCK fdP = IH_OPEN(ihP); + if (fdP == NULL) + Abort("VAllocVnode: can't open index file!\n"); + if ((size = FDH_SIZE(fdP)) < 0) + Abort("VAllocVnode: can't stat index file!\n"); + if (FDH_SEEK(fdP, off, SEEK_SET) < 0) + Abort("VAllocVnode: can't seek on index file!\n"); + if (off < size) { + if (FDH_READ(fdP, &vnp->disk, vcp->diskSize) == vcp->diskSize) { + if (vnp->disk.type != vNull) + Abort("VAllocVnode: addled bitmap or index!\n"); + } + } else { + /* growing file - grow in a reasonable increment */ + char *buf = (char *)malloc(16 * 1024); + if (!buf) + Abort("VAllocVnode: malloc failed\n"); + memset(buf, 0, 16 * 1024); + (void)FDH_WRITE(fdP, buf, 16 * 1024); + free(buf); + } + FDH_CLOSE(fdP); + VOL_LOCK} VNLog(4, 2, vnodeNumber, (afs_int32) vnp); } @@ -402,8 +413,8 @@ Vnode *VAllocVnode_r(ec,vp,type) LWP_CurrentProcess(&vnp->writer); #endif /* AFS_PTHREAD_ENV */ memset(&vnp->disk, 0, sizeof(vnp->disk)); - vnp->changed_newTime = 0; /* set this bit when vnode is updated */ - vnp->changed_oldTime = 0; /* set this on CopyOnWrite. */ + vnp->changed_newTime = 0; /* set this bit when vnode is updated */ + vnp->changed_oldTime = 0; /* set this on CopyOnWrite. */ vnp->delete = 0; vnp->disk.vnodeMagic = vcp->magic; vnp->disk.type = type; @@ -412,33 +423,25 @@ Vnode *VAllocVnode_r(ec,vp,type) vcp->allocs++; return vnp; } - -Vnode *VGetVnode(ec,vp,vnodeNumber,locktype) - Error *ec; - Volume *vp; - VnodeId vnodeNumber; - int locktype; /* READ_LOCK or WRITE_LOCK, as defined in lock.h */ -{ + +Vnode * +VGetVnode(Error * ec, Volume * vp, VnodeId vnodeNumber, int locktype) +{ /* READ_LOCK or WRITE_LOCK, as defined in lock.h */ Vnode *retVal; - VOL_LOCK - retVal = VGetVnode_r(ec, vp, vnodeNumber, locktype); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VGetVnode_r(ec, vp, vnodeNumber, locktype); + VOL_UNLOCK return retVal; } -Vnode *VGetVnode_r(ec,vp,vnodeNumber,locktype) - Error *ec; - Volume *vp; - VnodeId vnodeNumber; - int locktype; /* READ_LOCK or WRITE_LOCK, as defined in lock.h */ -{ +Vnode * +VGetVnode_r(Error * ec, Volume * vp, VnodeId vnodeNumber, int locktype) +{ /* READ_LOCK or WRITE_LOCK, as defined in lock.h */ register Vnode *vnp; int newHash; VnodeClass class; struct VnodeClassInfo *vcp; *ec = 0; - mlkReason = 0; /* last call didn't fail */ + mlkReason = 0; /* last call didn't fail */ if (vnodeNumber == 0) { *ec = VNOVNODE; @@ -448,21 +451,21 @@ Vnode *VGetVnode_r(ec,vp,vnodeNumber,locktype) VNLog(100, 1, vnodeNumber); if (programType == fileServer && !V_inUse(vp)) { - *ec = (vp->specialStatus ? vp->specialStatus : VOFFLINE); + *ec = (vp->specialStatus ? vp->specialStatus : VOFFLINE); /* If the volume is VBUSY (being cloned or dumped) and this is * a READ operation, then don't fail. */ if ((*ec != VBUSY) || (locktype != READ_LOCK)) { - mlkReason = 2; - return NULL; + mlkReason = 2; + return NULL; } *ec = 0; } class = vnodeIdToClass(vnodeNumber); vcp = &VnodeClassInfo[class]; if (locktype == WRITE_LOCK && !VolumeWriteable(vp)) { - *ec = VREADONLY; + *ec = (bit32) VREADONLY; mlkReason = 3; return NULL; } @@ -478,20 +481,19 @@ Vnode *VGetVnode_r(ec,vp,vnodeNumber,locktype) /* See whether the vnode is in the cache. */ newHash = VNODE_HASH(vp, vnodeNumber); for (vnp = VnodeHashTable[newHash]; - vnp && (vnp->vnodeNumber!=vnodeNumber || vnp->volumePtr!=vp - || vnp->volumePtr->cacheCheck!=vnp->cacheCheck); - vnp = vnp->hashNext - ); + vnp && (vnp->vnodeNumber != vnodeNumber || vnp->volumePtr != vp + || vnp->volumePtr->cacheCheck != vnp->cacheCheck); + vnp = vnp->hashNext); vcp->gets++; if (vnp == NULL) { - int n; + int n; IHandle_t *ihP = vp->vnodeIndex[class].handle; FdHandle_t *fdP; - /* Not in cache; tentatively grab most distantly used one from the LRU - chain */ + /* Not in cache; tentatively grab most distantly used one from the LRU + * chain */ vcp->reads++; vnp = VGetFreeVnode_r(vcp); - /* Remove it from the old hash chain */ + /* Remove it from the old hash chain */ moveHash(vnp, newHash); /* Remove it from the LRU chain */ if (vnp == vcp->lruHead) @@ -513,43 +515,37 @@ Vnode *VGetVnode_r(ec,vp,vnodeNumber,locktype) #ifdef AFS_PTHREAD_ENV vnp->writer = pthread_self(); #else /* AFS_PTHREAD_ENV */ - LWP_CurrentProcess(&vnp->writer); + LWP_CurrentProcess(&vnp->writer); #endif /* AFS_PTHREAD_ENV */ - /* Read vnode from volume index */ - VOL_UNLOCK - fdP = IH_OPEN(ihP); + /* Read vnode from volume index */ + VOL_UNLOCK fdP = IH_OPEN(ihP); if (fdP == NULL) { - Log("VGetVnode: can't open index dev=%d, i=%s\n", - vp->device, PrintInode(NULL, - vp->vnodeIndex[class].handle->ih_ino)); + Log("VGetVnode: can't open index dev=%u, i=%s\n", vp->device, + PrintInode(NULL, vp->vnodeIndex[class].handle->ih_ino)); *ec = VIO; - mlkReason=9; - } - else if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), - SEEK_SET) < 0) { - Log ("VGetVnode: can't seek on index file vn=%d\n",vnodeNumber); + mlkReason = 9; + } else if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) + < 0) { + Log("VGetVnode: can't seek on index file vn=%u\n", vnodeNumber); *ec = VIO; - mlkReason=10; + mlkReason = 10; FDH_REALLYCLOSE(fdP); - } - else if ((n = FDH_READ(fdP, (char*)&vnp->disk, vcp->diskSize)) - != vcp->diskSize) { + } else if ((n = FDH_READ(fdP, (char *)&vnp->disk, vcp->diskSize)) + != vcp->diskSize) { /* Don't take volume off line if the inumber is out of range - or the inode table is full. */ + * or the inode table is full. */ FDH_REALLYCLOSE(fdP); - VOL_LOCK - if(n == BAD_IGET) { + VOL_LOCK if (n == BAD_IGET) { Log("VGetVnode: bad inumber %s\n", PrintInode(NULL, vp->vnodeIndex[class].handle->ih_ino)); *ec = VIO; mlkReason = 4; } /* Check for disk errors. Anything else just means that the vnode - is not allocated */ + * is not allocated */ if (n == -1 && errno == EIO) { - Log("VGetVnode: Couldn't read vnode %d, volume %u (%s); volume needs salvage\n", - vnodeNumber, V_id(vp), V_name(vp)); + Log("VGetVnode: Couldn't read vnode %u, volume %u (%s); volume needs salvage\n", vnodeNumber, V_id(vp), V_name(vp)); VForceOffline_r(vp); *ec = VSALVAGE; mlkReason = 4; @@ -559,47 +555,44 @@ Vnode *VGetVnode_r(ec,vp,vnodeNumber,locktype) } VInvalidateVnode_r(vnp); if (vnp->nUsers-- == 1) - StickOnLruChain_r(vnp,vcp); + StickOnLruChain_r(vnp, vcp); ReleaseWriteLock(&vnp->lock); return NULL; } FDH_CLOSE(fdP); VOL_LOCK - /* Quick check to see that the data is reasonable */ - if (vnp->disk.vnodeMagic != vcp->magic || vnp->disk.type == vNull) { + /* Quick check to see that the data is reasonable */ + if (vnp->disk.vnodeMagic != vcp->magic || vnp->disk.type == vNull) { if (vnp->disk.type == vNull) { *ec = VNOVNODE; mlkReason = 6; VInvalidateVnode_r(vnp); if (vnp->nUsers-- == 1) - StickOnLruChain_r(vnp,vcp); + StickOnLruChain_r(vnp, vcp); ReleaseWriteLock(&vnp->lock); return NULL; /* The vnode is not allocated */ - } - else { + } else { struct vnodeIndex *index = &vp->vnodeIndex[class]; - int bitNumber = vnodeIdToBitNumber(vnodeNumber); - int offset = bitNumber >> 3; + unsigned int bitNumber = vnodeIdToBitNumber(vnodeNumber); + unsigned int offset = bitNumber >> 3; /* Test to see if vnode number is valid. */ - if ((offset >= index->bitmapSize) || - ((*(index->bitmap+offset) & (1<<(bitNumber&0x7))) == 0)) { - Log("VGetVnode: Request for unallocated vnode %u, volume %u (%s) denied.\n", - vnodeNumber, V_id(vp), V_name(vp)); + if ((offset >= index->bitmapSize) + || ((*(index->bitmap + offset) & (1 << (bitNumber & 0x7))) + == 0)) { + Log("VGetVnode: Request for unallocated vnode %u, volume %u (%s) denied.\n", vnodeNumber, V_id(vp), V_name(vp)); mlkReason = 11; *ec = VNOVNODE; - } - else { - Log("VGetVnode: Bad magic number, vnode %d, volume %u (%s); volume needs salvage\n", - vnodeNumber, V_id(vp), V_name(vp)); + } else { + Log("VGetVnode: Bad magic number, vnode %u, volume %u (%s); volume needs salvage\n", vnodeNumber, V_id(vp), V_name(vp)); vp->goingOffline = 1; /* used to call VOffline, but that would mess - up the volume ref count if called here */ + * up the volume ref count if called here */ *ec = VSALVAGE; mlkReason = 7; } VInvalidateVnode_r(vnp); if (vnp->nUsers-- == 1) - StickOnLruChain_r(vnp,vcp); + StickOnLruChain_r(vnp, vcp); ReleaseWriteLock(&vnp->lock); return NULL; } @@ -609,8 +602,8 @@ Vnode *VGetVnode_r(ec,vp,vnodeNumber,locktype) } else { VNLog(101, 2, vnodeNumber, (afs_int32) vnp); if (++vnp->nUsers == 1) { - /* First user. Remove it from the LRU chain. We can assume that - there is at least one item in the queue */ + /* First user. Remove it from the LRU chain. We can assume that + * there is at least one item in the queue */ if (vnp == vcp->lruHead) vcp->lruHead = vcp->lruHead->lruNext; if (vnp == vcp->lruHead || vcp->lruHead == NULL) @@ -619,24 +612,23 @@ Vnode *VGetVnode_r(ec,vp,vnodeNumber,locktype) vnp->lruNext->lruPrev = vnp->lruPrev; } } - VOL_UNLOCK - if (locktype == READ_LOCK) + VOL_UNLOCK if (locktype == READ_LOCK) ObtainReadLock(&vnp->lock); else { ObtainWriteLock(&vnp->lock); #ifdef AFS_PTHREAD_ENV vnp->writer = pthread_self(); #else /* AFS_PTHREAD_ENV */ - LWP_CurrentProcess(&vnp->writer); + LWP_CurrentProcess(&vnp->writer); #endif /* AFS_PTHREAD_ENV */ } VOL_LOCK - /* Check that the vnode hasn't been removed while we were obtaining - the lock */ - VNLog(102, 2, vnodeNumber, (afs_int32) vnp); - if ((vnp->disk.type == vNull) || (vnp->cacheCheck == 0)){ + /* Check that the vnode hasn't been removed while we were obtaining + * the lock */ + VNLog(102, 2, vnodeNumber, (afs_int32) vnp); + if ((vnp->disk.type == vNull) || (vnp->cacheCheck == 0)) { if (vnp->nUsers-- == 1) - StickOnLruChain_r(vnp,vcp); + StickOnLruChain_r(vnp, vcp); if (locktype == READ_LOCK) ReleaseReadLock(&vnp->lock); else @@ -647,29 +639,23 @@ Vnode *VGetVnode_r(ec,vp,vnodeNumber,locktype) return NULL; } if (programType == fileServer) - VBumpVolumeUsage_r(vnp->volumePtr);/* Hack; don't know where it should be - called from. Maybe VGetVolume */ + VBumpVolumeUsage_r(vnp->volumePtr); /* Hack; don't know where it should be + * called from. Maybe VGetVolume */ return vnp; } -int TrustVnodeCacheEntry = 1; +int TrustVnodeCacheEntry = 1; /* This variable is bogus--when it's set to 0, the hash chains fill up with multiple versions of the same vnode. Should fix this!! */ void -VPutVnode(ec,vnp) - Error *ec; - register Vnode *vnp; +VPutVnode(Error * ec, register Vnode * vnp) { - VOL_LOCK - VPutVnode_r(ec,vnp); - VOL_UNLOCK -} + VOL_LOCK VPutVnode_r(ec, vnp); +VOL_UNLOCK} void -VPutVnode_r(ec,vnp) - Error *ec; - register Vnode *vnp; +VPutVnode_r(Error * ec, register Vnode * vnp) { int writeLocked, offset; VnodeClass class; @@ -677,7 +663,7 @@ VPutVnode_r(ec,vnp) int code; *ec = 0; - assert (vnp->nUsers != 0); + assert(vnp->nUsers != 0); class = vnodeIdToClass(vnp->vnodeNumber); vcp = &VnodeClassInfo[class]; assert(vnp->disk.vnodeMagic == vcp->magic); @@ -692,40 +678,43 @@ VPutVnode_r(ec,vnp) LWP_CurrentProcess(&thisProcess); #endif /* AFS_PTHREAD_ENV */ VNLog(201, 2, (afs_int32) vnp, - ((vnp->changed_newTime) << 1) | ((vnp->changed_oldTime) << 1) | vnp->delete); + ((vnp->changed_newTime) << 1) | ((vnp-> + changed_oldTime) << 1) | vnp-> + delete); if (thisProcess != vnp->writer) - Abort("VPutVnode: Vnode at 0x%x locked by another process!\n",vnp); + Abort("VPutVnode: Vnode at 0x%x locked by another process!\n", + vnp); if (vnp->changed_oldTime || vnp->changed_newTime || vnp->delete) { Volume *vp = vnp->volumePtr; - afs_int32 now = FT_ApproxTime(); + afs_uint32 now = FT_ApproxTime(); assert(vnp->cacheCheck == vp->cacheCheck); if (vnp->delete) { - /* No longer any directory entries for this vnode. Free the Vnode */ - memset(&vnp->disk, 0, sizeof (vnp->disk)); + /* No longer any directory entries for this vnode. Free the Vnode */ + memset(&vnp->disk, 0, sizeof(vnp->disk)); mlkLastDelete = vnp->vnodeNumber; /* delete flag turned off further down */ VNLog(202, 2, vnp->vnodeNumber, (afs_int32) vnp); } else if (vnp->changed_newTime) { - vnp->disk.serverModifyTime = now; + vnp->disk.serverModifyTime = now; } if (vnp->changed_newTime) V_updateDate(vp) = vp->updateTime = now; /* The vnode has been changed. Write it out to disk */ - if (!V_inUse(vp)) { + if (!V_inUse(vp)) { assert(V_needsSalvaged(vp)); *ec = VSALVAGE; } else { IHandle_t *ihP = vp->vnodeIndex[class].handle; FdHandle_t *fdP; - VOL_UNLOCK - fdP = IH_OPEN(ihP); + VOL_UNLOCK fdP = IH_OPEN(ihP); if (fdP == NULL) Abort("VPutVnode: can't open index file!\n"); offset = vnodeIndexOffset(vcp, vnp->vnodeNumber); if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { - Abort("VPutVnode: can't seek on index file! fdp=0x%x offset=%d, errno=%d\n", + Abort + ("VPutVnode: can't seek on index file! fdp=0x%x offset=%d, errno=%d\n", fdP, offset, errno); } code = FDH_WRITE(fdP, &vnp->disk, vcp->diskSize); @@ -733,31 +722,27 @@ VPutVnode_r(ec,vnp) /* Don't force volume offline if the inumber is out of * range or the inode table is full. */ - VOL_LOCK - if (code == BAD_IGET) { + VOL_LOCK if (code == BAD_IGET) { Log("VPutVnode: bad inumber %s\n", - PrintInode(NULL, vp->vnodeIndex[class].handle->ih_ino)); + PrintInode(NULL, + vp->vnodeIndex[class].handle->ih_ino)); *ec = VIO; } else { - Log("VPutVnode: Couldn't write vnode %d, volume %u (%s)\n", - vnp->vnodeNumber, V_id(vnp->volumePtr), - V_name(vnp->volumePtr)); + Log("VPutVnode: Couldn't write vnode %u, volume %u (%s) (error %d)\n", vnp->vnodeNumber, V_id(vnp->volumePtr), V_name(vnp->volumePtr), code); VForceOffline_r(vp); *ec = VSALVAGE; } - VOL_UNLOCK - FDH_REALLYCLOSE(fdP); + VOL_UNLOCK FDH_REALLYCLOSE(fdP); } else { FDH_CLOSE(fdP); } - VOL_LOCK - - /* If the vnode is to be deleted, and we wrote the vnode out, - * free its bitmap entry. Do after the vnode is written so we - * don't allocate from bitmap before the vnode is written - * (doing so could cause a "addled bitmap" message). - */ - if (vnp->delete && !*ec) { + VOL_LOCK + /* If the vnode is to be deleted, and we wrote the vnode out, + * free its bitmap entry. Do after the vnode is written so we + * don't allocate from bitmap before the vnode is written + * (doing so could cause a "addled bitmap" message). + */ + if (vnp->delete && !*ec) { VFreeBitMapEntry_r(ec, &vp->vnodeIndex[class], vnodeIdToBitNumber(vnp->vnodeNumber)); } @@ -765,21 +750,23 @@ VPutVnode_r(ec,vnp) vcp->writes++; vnp->changed_newTime = vnp->changed_oldTime = 0; } - } else { /* Not write locked */ + } else { /* Not write locked */ if (vnp->changed_newTime || vnp->changed_oldTime || vnp->delete) - Abort("VPutVnode: Change or delete flag for vnode 0x%x is set but vnode is not write locked!\n", vnp); + Abort + ("VPutVnode: Change or delete flag for vnode 0x%x is set but vnode is not write locked!\n", + vnp); } /* Do not look at disk portion of vnode after this point; it may - have been deleted above */ + * have been deleted above */ if (vnp->nUsers-- == 1) - StickOnLruChain_r(vnp,vcp); + StickOnLruChain_r(vnp, vcp); vnp->delete = 0; if (writeLocked) - ReleaseWriteLock(&vnp->lock); + ReleaseWriteLock(&vnp->lock); else - ReleaseReadLock(&vnp->lock); + ReleaseReadLock(&vnp->lock); } /* @@ -787,20 +774,16 @@ VPutVnode_r(ec,vnp) * Do nothing if the vnode isn't write locked or the vnode has * been deleted. */ -int VVnodeWriteToRead(ec,vnp) - Error *ec; - register Vnode *vnp; +int +VVnodeWriteToRead(Error * ec, register Vnode * vnp) { int retVal; - VOL_LOCK - retVal = VVnodeWriteToRead_r(ec, vnp); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VVnodeWriteToRead_r(ec, vnp); + VOL_UNLOCK return retVal; } -int VVnodeWriteToRead_r(ec,vnp) - Error *ec; - register Vnode *vnp; +int +VVnodeWriteToRead_r(Error * ec, register Vnode * vnp) { int writeLocked; VnodeClass class; @@ -813,7 +796,7 @@ int VVnodeWriteToRead_r(ec,vnp) #endif /* AFS_PTHREAD_ENV */ *ec = 0; - assert (vnp->nUsers != 0); + assert(vnp->nUsers != 0); class = vnodeIdToClass(vnp->vnodeNumber); vcp = &VnodeClassInfo[class]; assert(vnp->disk.vnodeMagic == vcp->magic); @@ -823,7 +806,6 @@ int VVnodeWriteToRead_r(ec,vnp) if (!writeLocked) { return 0; } - #ifdef AFS_PTHREAD_ENV thisProcess = pthread_self(); #else /* AFS_PTHREAD_ENV */ @@ -831,16 +813,17 @@ int VVnodeWriteToRead_r(ec,vnp) #endif /* AFS_PTHREAD_ENV */ VNLog(301, 2, (afs_int32) vnp, - ((vnp->changed_newTime) << 1) | ((vnp->changed_oldTime) << 1) | - vnp->delete); + ((vnp->changed_newTime) << 1) | ((vnp-> + changed_oldTime) << 1) | vnp-> + delete); if (thisProcess != vnp->writer) - Abort("VPutVnode: Vnode at 0x%x locked by another process!\n",vnp); + Abort("VPutVnode: Vnode at 0x%x locked by another process!\n", (int)vnp); if (vnp->delete) { return 0; } if (vnp->changed_oldTime || vnp->changed_newTime) { Volume *vp = vnp->volumePtr; - afs_int32 now = FT_ApproxTime(); + afs_uint32 now = FT_ApproxTime(); assert(vnp->cacheCheck == vp->cacheCheck); if (vnp->changed_newTime) vnp->disk.serverModifyTime = now; @@ -855,8 +838,7 @@ int VVnodeWriteToRead_r(ec,vnp) IHandle_t *ihP = vp->vnodeIndex[class].handle; FdHandle_t *fdP; off_t off = vnodeIndexOffset(vcp, vnp->vnodeNumber); - VOL_UNLOCK - fdP = IH_OPEN(ihP); + VOL_UNLOCK fdP = IH_OPEN(ihP); if (fdP == NULL) Abort("VPutVnode: can't open index file!\n"); code = FDH_SEEK(fdP, off, SEEK_SET); @@ -868,24 +850,18 @@ int VVnodeWriteToRead_r(ec,vnp) * Don't force volume offline if the inumber is out of * range or the inode table is full. */ - VOL_LOCK - if(code == BAD_IGET) - { - Log("VPutVnode: bad inumber %d\n", - vp->vnodeIndex[class].handle->ih_ino); - *ec = VIO; + VOL_LOCK if (code == BAD_IGET) { + Log("VPutVnode: bad inumber %s\n", + PrintInode(NULL, vp->vnodeIndex[class].handle->ih_ino)); + *ec = VIO; } else { - Log("VPutVnode: Couldn't write vnode %d, volume %u (%s)\n", - vnp->vnodeNumber, V_id(vnp->volumePtr), - V_name(vnp->volumePtr)); - VForceOffline_r(vp); + Log("VPutVnode: Couldn't write vnode %u, volume %u (%s)\n", vnp->vnodeNumber, V_id(vnp->volumePtr), V_name(vnp->volumePtr)); + VForceOffline_r(vp); *ec = VSALVAGE; } - VOL_UNLOCK - } + VOL_UNLOCK} FDH_CLOSE(fdP); - VOL_LOCK - } + VOL_LOCK} vcp->writes++; vnp->changed_newTime = vnp->changed_oldTime = 0; } @@ -896,12 +872,11 @@ int VVnodeWriteToRead_r(ec,vnp) /* Move the vnode, vnp, to the new hash table given by the hash table index, newHash */ -static int moveHash(vnp, newHash) - register Vnode *vnp; - bit32 newHash; +static int +moveHash(register Vnode * vnp, bit32 newHash) { Vnode *tvnp; - /* Remove it from the old hash chain */ + /* Remove it from the old hash chain */ tvnp = VnodeHashTable[vnp->hashIndex]; if (tvnp == vnp) VnodeHashTable[vnp->hashIndex] = vnp->hashNext; @@ -911,7 +886,7 @@ static int moveHash(vnp, newHash) if (tvnp) tvnp->hashNext = vnp->hashNext; } - /* Add it to the new hash chain */ + /* Add it to the new hash chain */ vnp->hashNext = VnodeHashTable[newHash]; VnodeHashTable[newHash] = vnp; vnp->hashIndex = newHash; @@ -919,11 +894,9 @@ static int moveHash(vnp, newHash) } void -StickOnLruChain_r(vnp,vcp) - register Vnode *vnp; - register struct VnodeClassInfo *vcp; +StickOnLruChain_r(register Vnode * vnp, register struct VnodeClassInfo *vcp) { - /* Add it to the circular LRU list */ + /* Add it to the circular LRU list */ if (vcp->lruHead == NULL) Abort("VPutVnode: vcp->lruHead==NULL"); else { @@ -933,12 +906,12 @@ StickOnLruChain_r(vnp,vcp) vnp->lruPrev->lruNext = vnp; vcp->lruHead = vnp; } - /* If the vnode was just deleted, put it at the end of the chain so it - will be reused immediately */ + /* If the vnode was just deleted, put it at the end of the chain so it + * will be reused immediately */ if (vnp->delete) vcp->lruHead = vnp->lruNext; - /* If caching is turned off, set volumeptr to NULL to invalidate the - entry */ + /* If caching is turned off, set volumeptr to NULL to invalidate the + * entry */ if (!TrustVnodeCacheEntry) vnp->volumePtr = NULL; } @@ -947,12 +920,13 @@ StickOnLruChain_r(vnp,vcp) * files for vnodes in that volume are closed. This might be excessive, * since we may only be taking one volume of a volume group offline. */ -void VCloseVnodeFiles_r(Volume *vp) +void +VCloseVnodeFiles_r(Volume * vp) { int i; Vnode *vnp; - for (i=0; ihashNext) { if (vnp->volumePtr == vp) { IH_REALLYCLOSE(vnp->handle); @@ -965,12 +939,13 @@ void VCloseVnodeFiles_r(Volume *vp) * files for vnodes in that volume are closed and all inode handles * for vnodes in that volume are released. */ -void VReleaseVnodeFiles_r(Volume *vp) +void +VReleaseVnodeFiles_r(Volume * vp) { int i; Vnode *vnp; - for (i=0; ihashNext) { if (vnp->volumePtr == vp) { IH_RELEASE(vnp->handle); diff --git a/src/vol/vnode.h b/src/vol/vnode.h index 2901eb0d9..efde399cb 100644 --- a/src/vol/vnode.h +++ b/src/vol/vnode.h @@ -16,10 +16,11 @@ #define Date afs_uint32 -typedef struct ViceLock -{ - int lockCount; - int lockTime; +struct Volume; /* Potentially forward definition. */ + +typedef struct ViceLock { + int lockCount; + int lockTime; } ViceLock; #define ViceLockCheckLocked(vptr) ((vptr)->lockTime == 0) @@ -28,7 +29,7 @@ typedef struct ViceLock #define ROOTVNODE 1 /*typedef enum {vNull=0, vFile=1, vDirectory=2, vSymlink=3} VnodeType;*/ -typedef int VnodeType; +typedef unsigned int VnodeType; #define vNull 0 #define vFile 1 #define vDirectory 2 @@ -49,13 +50,13 @@ struct VnodeClassInfo { int residentSize; /* resident size of vnode */ int cacheSize; /* Vnode cache size */ bit32 magic; /* Magic number for this type of vnode, - for as long as we're using vnode magic - numbers */ - int allocs; /* Total number of successful allocation - requests; this is the same as the number - of sanity checks on the vnode index */ - int gets,reads; /* Number of VGetVnodes and corresponding - reads */ + * for as long as we're using vnode magic + * numbers */ + int allocs; /* Total number of successful allocation + * requests; this is the same as the number + * of sanity checks on the vnode index */ + int gets, reads; /* Number of VGetVnodes and corresponding + * reads */ int writes; /* Number of vnode writes */ }; @@ -68,46 +69,46 @@ extern struct VnodeClassInfo VnodeClassInfo[nVNODECLASSES]; of the index. The header record is the same size as a vnode */ #define vnodeIndexOffset(vcp,vnodeNumber) \ ((vnodeIdToBitNumber(vnodeNumber)+1)<<(vcp)->logSize) -#define bitNumberToVnodeNumber(b,class) (((b)<disk.reserved6, (V)->disk.length) +#define VNDISK_GET_LEN(N, V) FillInt64(N, (V)->reserved6, (V)->length) +#define VN_SET_LEN(V, N) SplitInt64(N, (V)->disk.reserved6, (V)->disk.length) +#define VNDISK_SET_LEN(V, N) SplitInt64(N, (V)->reserved6, (V)->length) +#else /* !AFS_LARGEFILE_ENV */ +#define VN_GET_LEN(N, V) (N) = (V)->disk.length; +#define VNDISK_GET_LEN(N, V) (N) = (V)->length; +#define VN_SET_LEN(V, N) (V)->disk.length = (N); +#define VNDISK_SET_LEN(V, N) (V)->length = (N); +#endif /* !AFS_LARGEFILE_ENV */ + #ifdef AFS_64BIT_IOPS_ENV #define VN_GET_INO(V) ((Inode)((V)->disk.vn_ino_lo | \ ((V)->disk.vn_ino_hi ? \ @@ -187,17 +200,19 @@ typedef struct Vnode { vnodes */ #define VAclSize(vnp) (SIZEOF_LARGEDISKVNODE - SIZEOF_SMALLDISKVNODE) #define VAclDiskSize(v) (SIZEOF_LARGEDISKVNODE - SIZEOF_SMALLDISKVNODE) -extern int VolumeHashOffset(); -extern int VolumeHashOffset_r(); -extern VInitVnodes(); -extern VInitVnodes_r(); -extern Vnode *VGetVnode(); -extern Vnode *VGetVnode_r(); -extern VputVnode(); -extern VputVnode_r(); -extern VVnodeWriteToRead(); -extern VVnodeWriteToRead_r(); -extern Vnode *VAllocVnode(); -extern Vnode *VAllocVnode_r(); -extern VFreeVnode(); -extern VFreeVnode_r(); +/*extern int VolumeHashOffset(); */ +extern int VolumeHashOffset_r(void); +extern VInitVnodes(VnodeClass class, int nVnodes); +/*extern VInitVnodes_r();*/ +extern Vnode *VGetVnode(Error * ec, struct Volume *vp, VnodeId vnodeNumber, + int locktype); +extern Vnode *VGetVnode_r(Error * ec, struct Volume *vp, VnodeId vnodeNumber, + int locktype); +extern void VPutVnode(Error * ec, register Vnode * vnp); +extern void VPutVnode_r(Error * ec, register Vnode * vnp); +extern VVnodeWriteToRead(Error * ec, register Vnode * vnp); +extern VVnodeWriteToRead_r(Error * ec, register Vnode * vnp); +extern Vnode *VAllocVnode(Error * ec, struct Volume *vp, VnodeType type); +extern Vnode *VAllocVnode_r(Error * ec, struct Volume *vp, VnodeType type); +/*extern VFreeVnode();*/ +extern Vnode *VGetFreeVnode_r(struct VnodeClassInfo *vcp); diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index 61af81b3b..81839e62f 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -17,7 +17,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vol-info.c,v 1.1.1.6 2001/09/11 14:35:47 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/vol-info.c,v 1.16 2003/11/29 21:38:05 jaltman Exp $"); #include #include @@ -56,7 +57,17 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vol-info.c,v 1.1.1.6 2001/09/11 14: #include -int DumpVnodes = 0; /* Dump everything, i.e. summary of all vnodes */ +#ifdef O_LARGEFILE +#define afs_stat stat64 +#define afs_fstat fstat64 +#define afs_open open64 +#else /* !O_LARGEFILE */ +#define afs_stat stat +#define afs_fstat fstat +#define afs_open open +#endif /* !O_LARGEFILE */ + +int DumpVnodes = 0; /* Dump everything, i.e. summary of all vnodes */ int DumpInodeNumber = 0; /* Dump inode numbers with vnodes */ int DumpDate = 0; /* Dump vnode date (server modify date) with vnode */ int InodeTimes = 0; /* Dump some of the dates associated with inodes */ @@ -64,15 +75,16 @@ int InodeTimes = 0; /* Dump some of the dates associated with inodes */ int PrintFileNames = 0; #endif int online = 0; -int dheader=0; -int dsizeOnly = 0, totvolsize=0, Vauxsize = 0, Vdiskused = 0, Vvnodesize = 0; -int Totvolsize=0, TVauxsize = 0, TVdiskused = 0, TVvnodesize = 0; -int Stotvolsize=0, SVauxsize = 0, SVdiskused = 0, SVvnodesize = 0; -int fixheader = 0, saveinodes = 0, orphaned=0; +int dheader = 0; +int dsizeOnly = 0, totvolsize = 0, Vauxsize = 0, Vdiskused = 0, Vvnodesize = + 0; +int Totvolsize = 0, TVauxsize = 0, TVdiskused = 0, TVvnodesize = 0; +int Stotvolsize = 0, SVauxsize = 0, SVdiskused = 0, SVvnodesize = 0; +int fixheader = 0, saveinodes = 0, orphaned = 0; int VolumeChanged; /* Forward Declarations */ -void PrintHeader(register Volume *vp); +void PrintHeader(register Volume * vp); void HandleAllPart(void); void HandlePart(struct DiskPartition *partP); void HandleVolume(struct DiskPartition *partP, char *name); @@ -80,23 +92,26 @@ struct DiskPartition *FindCurrentPartition(void); Volume *AttachVolume(struct DiskPartition *dp, char *volname, register struct VolumeHeader *header); #if defined(AFS_NAMEI_ENV) -void PrintVnode(int offset, VnodeDiskObject *vnode, int vnodeNumber, - Inode ino, Volume* vp); +void PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber, + Inode ino, Volume * vp); #else -void PrintVnode(int offset, VnodeDiskObject *vnode, int vnodeNumber, +void PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber, Inode ino); #endif -void PrintVnodes(Volume *vp, VnodeClass class); +void PrintVnodes(Volume * vp, VnodeClass class); -char *date(time_t date) +char * +date(time_t date) { - static char results[8][100]; +#define MAX_DATE_RESULT 100 + static char results[8][MAX_DATE_RESULT]; static next; struct tm *tm = localtime(&date); char buf[32]; - strftime (buf, 32, "%Y/%m/%d.%H:%M:%S", tm); /* NT does not have %T */ - sprintf(results[next = (next+1)&7], "%lu (%s)", (unsigned long) date, buf); + (void)strftime(buf, 32, "%Y/%m/%d.%H:%M:%S", tm); /* NT does not have %T */ + (void)afs_snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT, + "%lu (%s)", (unsigned long)date, buf); return results[next]; } @@ -108,14 +123,15 @@ char name[VMAXPATHLEN]; char BU[1000]; -int ReadHdr1(IHandle_t *ih, char *to, int size, u_int magic, u_int version) +int +ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version) { struct versionStamp *vsn; - int bad=0; + int bad = 0; int code; - vsn = (struct versionStamp *) to; - + vsn = (struct versionStamp *)to; + code = IH_IREAD(ih, 0, to, size); if (code != size) return -1; @@ -151,8 +167,9 @@ int ReadHdr1(IHandle_t *ih, char *to, int size, u_int magic, u_int version) } -Volume *AttachVolume(struct DiskPartition *dp, char *volname, - register struct VolumeHeader *header) +Volume * +AttachVolume(struct DiskPartition * dp, char *volname, + register struct VolumeHeader * header) { register Volume *vp; afs_int32 ec = 0; @@ -167,52 +184,49 @@ Volume *AttachVolume(struct DiskPartition *dp, char *volname, header->smallVnodeIndex); IH_INIT(vp->diskDataHandle, dp->device, header->parent, header->volumeInfo); - IH_INIT(V_linkHandle(vp), dp->device, header->parent, - header->linkTable); + IH_INIT(V_linkHandle(vp), dp->device, header->parent, header->linkTable); vp->cacheCheck = 0; /* XXXX */ vp->shuttingDown = 0; vp->goingOffline = 0; vp->nUsers = 1; - vp->header = (struct volHeader *) calloc(1, sizeof(*vp->header)); - ec = ReadHdr1(V_diskDataHandle(vp), - (char *)&V_disk(vp), sizeof(V_disk(vp)), - VOLUMEINFOMAGIC, VOLUMEINFOVERSION); + vp->header = (struct volHeader *)calloc(1, sizeof(*vp->header)); + ec = ReadHdr1(V_diskDataHandle(vp), (char *)&V_disk(vp), + sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION); if (!ec) { struct IndexFileHeader iHead; - ec = ReadHdr1(vp->vnodeIndex[vSmall].handle, - (char *)&iHead, sizeof(iHead), - SMALLINDEXMAGIC, SMALLINDEXVERSION); + ec = ReadHdr1(vp->vnodeIndex[vSmall].handle, (char *)&iHead, + sizeof(iHead), SMALLINDEXMAGIC, SMALLINDEXVERSION); } if (!ec) { struct IndexFileHeader iHead; - ec = ReadHdr1(vp->vnodeIndex[vLarge].handle, - (char *)&iHead, sizeof(iHead), - LARGEINDEXMAGIC, LARGEINDEXVERSION); + ec = ReadHdr1(vp->vnodeIndex[vLarge].handle, (char *)&iHead, + sizeof(iHead), LARGEINDEXMAGIC, LARGEINDEXVERSION); } #ifdef AFS_NAMEI_ENV if (!ec) { struct versionStamp stamp; - ec = ReadHdr1(V_linkHandle(vp), - (char *)&stamp, sizeof(stamp), - LINKTABLEMAGIC, LINKTABLEVERSION); + ec = ReadHdr1(V_linkHandle(vp), (char *)&stamp, sizeof(stamp), + LINKTABLEMAGIC, LINKTABLEVERSION); } #endif - if (ec) return (Volume *)0; + if (ec) + return (Volume *) 0; return vp; } -static int handleit(struct cmd_syndesc *as) +static int +handleit(struct cmd_syndesc *as) { register struct cmd_item *ti; int err = 0; - int volumeId=0; + int volumeId = 0; char *partName = 0; - struct DiskPartition *partP= NULL; + struct DiskPartition *partP = NULL; + - #ifndef AFS_NT40_ENV - if (geteuid() != 0) { + if (geteuid() != 0) { printf("vol-info must be run as root; sorry\n"); exit(1); } @@ -220,59 +234,59 @@ static int handleit(struct cmd_syndesc *as) if (as->parms[0].items) online = 1; - else + else online = 0; if (as->parms[1].items) DumpVnodes = 1; - else + else DumpVnodes = 0; if (as->parms[2].items) DumpDate = 1; - else + else DumpDate = 0; if (as->parms[3].items) DumpInodeNumber = 1; - else + else DumpInodeNumber = 0; if (as->parms[4].items) InodeTimes = 1; - else + else InodeTimes = 0; - if (ti = as->parms[5].items) + if ((ti = as->parms[5].items)) partName = ti->data; - if (ti = as->parms[6].items) + if ((ti = as->parms[6].items)) volumeId = atoi(ti->data); if (as->parms[7].items) dheader = 1; - else + else dheader = 0; if (as->parms[8].items) { dsizeOnly = 1; dheader = 1; DumpVnodes = 1; - } else + } else dsizeOnly = 0; if (as->parms[9].items) { fixheader = 1; - } else + } else fixheader = 0; if (as->parms[10].items) { saveinodes = 1; dheader = 1; DumpVnodes = 1; - } else + } else saveinodes = 0; if (as->parms[11].items) { orphaned = 1; DumpVnodes = 1; - } else + } else #if defined(AFS_NAMEI_ENV) if (as->parms[12].items) { PrintFileNames = 1; DumpVnodes = 1; - } else + } else #endif - orphaned = 0; + orphaned = 0; DInit(10); @@ -298,7 +312,7 @@ static int handleit(struct cmd_syndesc *as) } } else { char name1[128]; - + if (!partP) { partP = FindCurrentPartition(); if (!partP) { @@ -306,9 +320,11 @@ static int handleit(struct cmd_syndesc *as) exit(1); } } - sprintf(name1,VFORMAT,volumeId); + (void)afs_snprintf(name1, sizeof name1, VFORMAT, + (unsigned long)volumeId); if (dsizeOnly && !saveinodes) - printf("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n"); + printf + ("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n"); HandleVolume(partP, name1); } return 0; @@ -316,13 +332,14 @@ static int handleit(struct cmd_syndesc *as) #ifdef AFS_NT40_ENV #include -struct DiskPartition *FindCurrentPartition() +struct DiskPartition * +FindCurrentPartition() { int dr = _getdrive(); struct DiskPartition *dp; - - dr --; - for(dp = DiskPartitionList; dp; dp = dp->next) { + + dr--; + for (dp = DiskPartitionList; dp; dp = dp->next) { if (*dp->devName - 'A' == dr) break; } @@ -332,7 +349,8 @@ struct DiskPartition *FindCurrentPartition() return dp; } #else -struct DiskPartition *FindCurrentPartition() +struct DiskPartition * +FindCurrentPartition() { char partName[1024]; char tmp = '\0'; @@ -349,7 +367,8 @@ struct DiskPartition *FindCurrentPartition() *p = '\0'; } if (!(dp = VGetPartition(partName, 0))) { - if (tmp) *p = tmp; + if (tmp) + *p = tmp; printf("%s is not a valid vice partition.\n", partName); exit(1); } @@ -357,7 +376,8 @@ struct DiskPartition *FindCurrentPartition() } #endif -void HandleAllPart(void) +void +HandleAllPart(void) { struct DiskPartition *partP; @@ -372,26 +392,26 @@ void HandleAllPart(void) } if (dsizeOnly) { - printf("\nServer Totals%12d%9d%10d%10d%9d\n", - SVdiskused, SVauxsize, SVvnodesize, Stotvolsize, - Stotvolsize-SVdiskused); + printf("\nServer Totals%12d%9d%10d%10d%9d\n", SVdiskused, SVauxsize, + SVvnodesize, Stotvolsize, Stotvolsize - SVdiskused); } } -void HandlePart(struct DiskPartition *partP) +void +HandlePart(struct DiskPartition *partP) { - int nvols=0; + int nvols = 0; DIR *dirp; - struct dirent *dp; + struct dirent *dp; #ifdef AFS_NT40_ENV char pname[64]; char *p = pname; - (void) sprintf(pname, "%s\\", VPartitionPath(partP)); + (void)sprintf(pname, "%s\\", VPartitionPath(partP)); #else char *p = VPartitionPath(partP); #endif - + if (chdir(p) == -1) { printf("Can't chdir to partition %s; giving up\n", p); exit(1); @@ -401,32 +421,34 @@ void HandlePart(struct DiskPartition *partP) exit(1); } if (dsizeOnly && !saveinodes) - printf("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n"); - while (dp = readdir(dirp)) { + printf + ("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n"); + while ((dp = readdir(dirp))) { p = (char *)strrchr(dp->d_name, '.'); if (p != NULL && strcmp(p, VHDREXT) == 0) { - HandleVolume(partP, dp->d_name); + HandleVolume(partP, dp->d_name); Totvolsize += totvolsize; TVauxsize += Vauxsize; TVvnodesize += Vvnodesize; TVdiskused += Vdiskused; nvols++; - } + } } closedir(dirp); if (dsizeOnly) { printf("\nPart Totals %12d%9d%10d%10d%9d (%d volumes)\n\n", TVdiskused, TVauxsize, TVvnodesize, Totvolsize, - Totvolsize-TVdiskused, nvols); + Totvolsize - TVdiskused, nvols); } } -void HandleVolume(struct DiskPartition *dp, char *name) +void +HandleVolume(struct DiskPartition *dp, char *name) { struct VolumeHeader header; struct VolumeDiskHeader diskHeader; - struct stat status, stat; + struct afs_stat status, stat; register int fd; Volume *vp; IHandle_t *ih; @@ -438,22 +460,25 @@ void HandleVolume(struct DiskPartition *dp, char *name) } else { afs_int32 n; - (void) sprintf(headerName, "%s/%s", VPartitionPath(dp), name); - if ((fd = open(headerName, O_RDONLY)) == -1 - || fstat(fd,&status) == -1) { + (void)afs_snprintf(headerName, sizeof headerName, "%s/%s", + VPartitionPath(dp), name); + if ((fd = afs_open(headerName, O_RDONLY)) == -1 + || afs_fstat(fd, &status) == -1) { printf("Volinfo: Cannot read volume header %s\n", name); close(fd); exit(1); } - n = read(fd, &diskHeader, sizeof (diskHeader)); + n = read(fd, &diskHeader, sizeof(diskHeader)); - if (n != sizeof (diskHeader) + if (n != sizeof(diskHeader) || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) { printf("Volinfo: Error reading volume header %s\n", name); exit(1); } if (diskHeader.stamp.version != VOLUMEHEADERVERSION) { - printf("Volinfo: Volume %s, version number is incorrect; volume needs salvage\n",name); + printf + ("Volinfo: Volume %s, version number is incorrect; volume needs salvage\n", + name); exit(1); } DiskToVolumeHeader(&header, &diskHeader); @@ -463,17 +488,17 @@ void HandleVolume(struct DiskPartition *dp, char *name) int size = 0; int code; - if (fstat(fd, &stat) == -1) { + if (afs_fstat(fd, &stat) == -1) { perror("stat"); exit(1); - } + } if (!dsizeOnly && !saveinodes) { printf("Volume header (size = %d):\n", size = stat.st_size); printf("\tstamp\t= 0x%x\n", header.stamp.version); - printf("\tVolId\t= %d\n", header.id); + printf("\tVolId\t= %u\n", header.id); } - IH_INIT(ih, dp->device , header.id, header.volumeInfo); + IH_INIT(ih, dp->device, header.id, header.volumeInfo); fdP = IH_OPEN(ih); if (fdP == NULL) { perror("opening volume info"); @@ -483,17 +508,17 @@ void HandleVolume(struct DiskPartition *dp, char *name) if (code == -1) { perror("fstat"); exit(1); - } + } FDH_REALLYCLOSE(fdP); IH_RELEASE(ih); size += code; if (!dsizeOnly && !saveinodes) { - printf("\tparent\t= %d\n", header.parent); + printf("\tparent\t= %u\n", header.parent); printf("\tInfo inode\t= %s (size = %d)\n", PrintInode(NULL, header.volumeInfo), code); } - IH_INIT(ih, dp->device , header.id, header.smallVnodeIndex); + IH_INIT(ih, dp->device, header.id, header.smallVnodeIndex); fdP = IH_OPEN(ih); if (fdP == NULL) { perror("opening small vnode index"); @@ -503,7 +528,7 @@ void HandleVolume(struct DiskPartition *dp, char *name) if (code == -1) { perror("fstat"); exit(1); - } + } FDH_REALLYCLOSE(fdP); IH_RELEASE(ih); size += code; @@ -522,7 +547,7 @@ void HandleVolume(struct DiskPartition *dp, char *name) if (code == -1) { perror("fstat"); exit(1); - } + } FDH_REALLYCLOSE(fdP); IH_RELEASE(ih); size += code; @@ -544,7 +569,7 @@ void HandleVolume(struct DiskPartition *dp, char *name) if (code == -1) { perror("fstat"); exit(1); - } + } FDH_REALLYCLOSE(fdP); IH_RELEASE(ih); size += code; @@ -572,45 +597,54 @@ void HandleVolume(struct DiskPartition *dp, char *name) printf("\nSmall vnodes(files, symbolic links)\n"); fflush(stdout); } - if (saveinodes) + if (saveinodes) printf("Saving all volume files to current directory ...\n"); PrintVnodes(vp, vSmall); } if (dsizeOnly) { - Vauxsize = Vauxsize/1024; - Vvnodesize = Vvnodesize/1024; + Vauxsize = Vauxsize / 1024; + Vvnodesize = Vvnodesize / 1024; totvolsize = Vauxsize + Vvnodesize; if (saveinodes) - printf("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n"); + printf + ("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n"); - printf("%d\t%9d%9d%10d%10d%9d\t%24s\n", - V_id(vp), Vdiskused, Vauxsize, Vvnodesize, totvolsize, - totvolsize-Vdiskused, V_name(vp)); + printf("%u\t%9d%9d%10d%10d%9d\t%24s\n", V_id(vp), Vdiskused, Vauxsize, + Vvnodesize, totvolsize, totvolsize - Vdiskused, V_name(vp)); } } -main(argc,argv) -char **argv; +main(int argc, char **argv) { register struct cmd_syndesc *ts; afs_int32 code; - ts = cmd_CreateSyntax((char *)0, handleit, 0, "Dump volume's internal state"); - cmd_AddParm(ts, "-online", CMD_FLAG, CMD_OPTIONAL, "Get info from running fileserver"); + ts = cmd_CreateSyntax(NULL, handleit, 0, "Dump volume's internal state"); + cmd_AddParm(ts, "-online", CMD_FLAG, CMD_OPTIONAL, + "Get info from running fileserver"); cmd_AddParm(ts, "-vnode", CMD_FLAG, CMD_OPTIONAL, "Dump vnode info"); - cmd_AddParm(ts, "-date", CMD_FLAG, CMD_OPTIONAL, "Also dump vnode's mod date"); - cmd_AddParm(ts, "-inode", CMD_FLAG, CMD_OPTIONAL, "Dump vnode's inode number"); - cmd_AddParm(ts, "-itime", CMD_FLAG, CMD_OPTIONAL, "Dump special inode's mod times"); - cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL, "AFS partition name (default current partition)"); + cmd_AddParm(ts, "-date", CMD_FLAG, CMD_OPTIONAL, + "Also dump vnode's mod date"); + cmd_AddParm(ts, "-inode", CMD_FLAG, CMD_OPTIONAL, + "Dump vnode's inode number"); + cmd_AddParm(ts, "-itime", CMD_FLAG, CMD_OPTIONAL, + "Dump special inode's mod times"); + cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL, + "AFS partition name (default current partition)"); cmd_AddParm(ts, "-volumeid", CMD_LIST, CMD_OPTIONAL, "Volume id"); - cmd_AddParm(ts, "-header", CMD_FLAG, CMD_OPTIONAL, "Dump volume's header info"); - cmd_AddParm(ts, "-sizeOnly", CMD_FLAG, CMD_OPTIONAL, "Dump volume's size"); - cmd_AddParm(ts, "-fixheader", CMD_FLAG, CMD_OPTIONAL, "Try to fix header"); - cmd_AddParm(ts, "-saveinodes", CMD_FLAG, CMD_OPTIONAL, "Try to save all inodes"); - cmd_AddParm(ts, "-orphaned", CMD_FLAG, CMD_OPTIONAL, "List all dir/files without a parent"); + cmd_AddParm(ts, "-header", CMD_FLAG, CMD_OPTIONAL, + "Dump volume's header info"); + cmd_AddParm(ts, "-sizeOnly", CMD_FLAG, CMD_OPTIONAL, + "Dump volume's size"); + cmd_AddParm(ts, "-fixheader", CMD_FLAG, CMD_OPTIONAL, + "Try to fix header"); + cmd_AddParm(ts, "-saveinodes", CMD_FLAG, CMD_OPTIONAL, + "Try to save all inodes"); + cmd_AddParm(ts, "-orphaned", CMD_FLAG, CMD_OPTIONAL, + "List all dir/files without a parent"); #if defined(AFS_NAMEI_ENV) - cmd_AddParm(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL, "Print filenames"); + cmd_AddParm(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL, "Print filenames"); #endif code = cmd_Dispatch(argc, argv); return code; @@ -618,57 +652,71 @@ char **argv; #define typestring(type) (type == RWVOL? "read/write": type == ROVOL? "readonly": type == BACKVOL? "backup": "unknown") -void PrintHeader(register Volume *vp) +void +PrintHeader(register Volume * vp) { Vdiskused = V_diskused(vp); - if (dsizeOnly || saveinodes) return; + if (dsizeOnly || saveinodes) + return; printf("Volume header for volume %u (%s)\n", V_id(vp), V_name(vp)); printf("stamp.magic = %x, stamp.version = %u\n", V_stamp(vp).magic, - V_stamp(vp).version); - printf("inUse = %d, inService = %d, blessed = %d, needsSalvaged = %d, dontSalvage = %d\n", - V_inUse(vp), V_inService(vp), V_blessed(vp), V_needsSalvaged(vp), V_dontSalvage(vp)); - printf("type = %d (%s), uniquifier = %u, needsCallback = %d, destroyMe = %x\n", - V_type(vp), typestring(V_type(vp)), V_uniquifier(vp), V_needsCallback(vp), - V_destroyMe(vp)); - printf("id = %u, parentId = %u, cloneId = %u, backupId = %u, restoredFromId = %u\n", - V_id(vp), V_parentId(vp), V_cloneId(vp), V_backupId(vp), V_restoredFromId(vp)); - printf("maxquota = %d, minquota = %d, maxfiles = %d, filecount = %d, diskused = %d\n", - V_maxquota(vp), V_minquota(vp), V_maxfiles(vp), V_filecount(vp), V_diskused(vp)); - printf("creationDate = %s, copyDate = %s\n", date(V_creationDate(vp)), date(V_copyDate(vp))); - printf("backupDate = %s, expirationDate = %s\n", date(V_backupDate(vp)), date(V_expirationDate(vp))); - printf("accessDate = %s, updateDate = %s\n", date(V_accessDate(vp)), date(V_updateDate(vp))); - printf("owner = %u, accountNumber = %u\n", V_owner(vp), V_accountNumber(vp)); - printf("dayUse = %u; week = (%u, %u, %u, %u, %u, %u, %u), dayUseDate = %s\n", - V_dayUse(vp), V_weekUse(vp)[0], V_weekUse(vp)[1], V_weekUse(vp)[2], - V_weekUse(vp)[3],V_weekUse(vp)[4],V_weekUse(vp)[5],V_weekUse(vp)[6], - date(V_dayUseDate(vp))); + V_stamp(vp).version); + printf + ("inUse = %d, inService = %d, blessed = %d, needsSalvaged = %d, dontSalvage = %d\n", + V_inUse(vp), V_inService(vp), V_blessed(vp), V_needsSalvaged(vp), + V_dontSalvage(vp)); + printf + ("type = %d (%s), uniquifier = %u, needsCallback = %d, destroyMe = %x\n", + V_type(vp), typestring(V_type(vp)), V_uniquifier(vp), + V_needsCallback(vp), V_destroyMe(vp)); + printf + ("id = %u, parentId = %u, cloneId = %u, backupId = %u, restoredFromId = %u\n", + V_id(vp), V_parentId(vp), V_cloneId(vp), V_backupId(vp), + V_restoredFromId(vp)); + printf + ("maxquota = %d, minquota = %d, maxfiles = %d, filecount = %d, diskused = %d\n", + V_maxquota(vp), V_minquota(vp), V_maxfiles(vp), V_filecount(vp), + V_diskused(vp)); + printf("creationDate = %s, copyDate = %s\n", date(V_creationDate(vp)), + date(V_copyDate(vp))); + printf("backupDate = %s, expirationDate = %s\n", date(V_backupDate(vp)), + date(V_expirationDate(vp))); + printf("accessDate = %s, updateDate = %s\n", date(V_accessDate(vp)), + date(V_updateDate(vp))); + printf("owner = %u, accountNumber = %u\n", V_owner(vp), + V_accountNumber(vp)); + printf + ("dayUse = %u; week = (%u, %u, %u, %u, %u, %u, %u), dayUseDate = %s\n", + V_dayUse(vp), V_weekUse(vp)[0], V_weekUse(vp)[1], V_weekUse(vp)[2], + V_weekUse(vp)[3], V_weekUse(vp)[4], V_weekUse(vp)[5], + V_weekUse(vp)[6], date(V_dayUseDate(vp))); } /* GetFileInfo * OS independent file info. Die on failure. */ #ifdef AFS_NT40_ENV -char *NT_date(FILETIME *ft) +char * +NT_date(FILETIME * ft) { static char result[8][64]; static int next = 0; SYSTEMTIME st; FILETIME lft; - - if (!FileTimeToLocalFileTime(ft, &lft) || - !FileTimeToSystemTime(&lft, &st)) { + + if (!FileTimeToLocalFileTime(ft, &lft) + || !FileTimeToSystemTime(&lft, &st)) { printf("Time conversion failed.\n"); exit(1); } - sprintf(result[next = ((next+1)&7)], "%4d/%02d/%02d.%2d:%2d:%2d", - st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, - st.wSecond); + sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d", + st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); return result[next]; } #endif -static void GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, - char **atime) +static void +GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, char **atime) { #ifdef AFS_NT40_ENV BY_HANDLE_FILE_INFORMATION fi; @@ -681,8 +729,8 @@ static void GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, *mtime = NT_date(&fi.ftLastWriteTime); *atime = NT_date(&fi.ftLastAccessTime); #else - struct stat status; - if (fstat(fd, &status) == -1) { + struct afs_stat status; + if (afs_fstat(fd, &status) == -1) { printf("fstat failed %d\n", errno); exit(1); } @@ -693,21 +741,22 @@ static void GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, #endif } -void PrintVnodes(Volume *vp, VnodeClass class) +void +PrintVnodes(Volume * vp, VnodeClass class) { - afs_int32 diskSize = (class == vSmall ? - SIZEOF_SMALLDISKVNODE : SIZEOF_LARGEDISKVNODE); + afs_int32 diskSize = + (class == vSmall ? SIZEOF_SMALLDISKVNODE : SIZEOF_LARGEDISKVNODE); char buf[SIZEOF_LARGEDISKVNODE]; - struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; StreamHandle_t *file; - register int vnodeIndex, nVnodes, offset=0; + register int vnodeIndex, nVnodes, offset = 0; Inode ino; IHandle_t *ih = vp->vnodeIndex[class].handle; FdHandle_t *fdP; int size; char *ctime, *atime, *mtime; char nfile[50], buffer[256]; - int total, ofd, len, code, bad=0; + int total, ofd, len, code, bad = 0; fdP = IH_OPEN(ih); if (fdP == NULL) { @@ -723,17 +772,18 @@ void PrintVnodes(Volume *vp, VnodeClass class) GetFileInfo(fdP->fd_fd, &size, &ctime, &atime, &mtime); if (InodeTimes && !dsizeOnly) { - printf("ichanged : %s\nimodified: %s\niaccessed: %s\n\n", - ctime, mtime, atime); + printf("ichanged : %s\nimodified: %s\niaccessed: %s\n\n", ctime, + mtime, atime); } nVnodes = (size / diskSize) - 1; if (nVnodes > 0) { STREAM_SEEK(file, diskSize, 0); - } - else nVnodes = 0; + } else + nVnodes = 0; - for (vnodeIndex = 0; nVnodes && STREAM_READ(vnode, diskSize, 1, file) == 1; + for (vnodeIndex = 0; + nVnodes && STREAM_READ(vnode, diskSize, 1, file) == 1; nVnodes--, vnodeIndex++, offset += diskSize) { ino = VNDISK_GET_INO(vnode); @@ -742,18 +792,20 @@ void PrintVnodes(Volume *vp, VnodeClass class) IHandle_t *ih1; FdHandle_t *fdP1; IH_INIT(ih1, V_device(vp), V_parentId(vp), ino); - fdP1 = IH_OPEN(ih1); + fdP1 = IH_OPEN(ih1); if (fdP1 == NULL) { printf("Can't open inode %s error %d (ignored)\n", PrintInode(NULL, ino), errno); continue; } - sprintf(nfile, "TmpInode.%s", PrintInode(NULL, ino)); - ofd = open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600); + (void)afs_snprintf(nfile, sizeof nfile, "TmpInode.%s", + PrintInode(NULL, ino)); + ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600); if (ofd < 0) { - printf("Can't create file %s; error %d (ignored)\n", nfile, errno); + printf("Can't create file %s; error %d (ignored)\n", + nfile, errno); continue; - } + } total = bad = 0; while (1) { len = FDH_READ(fdP1, buffer, sizeof(buffer)); @@ -762,30 +814,35 @@ void PrintVnodes(Volume *vp, VnodeClass class) IH_RELEASE(ih1); close(ofd); unlink(nfile); - printf("Error while reading from inode %s (%d - ignored)\n", - PrintInode(NULL, ino), errno); + printf + ("Error while reading from inode %s (%d - ignored)\n", + PrintInode(NULL, ino), errno); bad = 1; break; } - if (len == 0) break; /* No more input */ + if (len == 0) + break; /* No more input */ code = write(ofd, buffer, len); if (code != len) { FDH_REALLYCLOSE(fdP1); IH_RELEASE(ih1); close(ofd); unlink(nfile); - printf("Error while writing to \"%s\" (%d - ignored)\n", nfile, errno); + printf + ("Error while writing to \"%s\" (%d - ignored)\n", + nfile, errno); bad = 1; break; } total += len; } - if (bad) continue; + if (bad) + continue; FDH_REALLYCLOSE(fdP1); IH_RELEASE(ih1); close(ofd); - printf("... Copied inode %d to file %s (%d bytes)\n", - ino, nfile, total); + printf("... Copied inode %s to file %s (%d bytes)\n", + PrintInode(NULL, ino), nfile, total); } } else { #if defined(AFS_NAMEI_ENV) @@ -802,9 +859,13 @@ void PrintVnodes(Volume *vp, VnodeClass class) } #if defined(AFS_NAMEI_ENV) -void PrintVnode(int offset, VnodeDiskObject *vnode, int vnodeNumber, Inode ino, Volume *vp) +void +PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber, + Inode ino, Volume * vp) #else -void PrintVnode(int offset, VnodeDiskObject *vnode, int vnodeNumber, Inode ino) +void +PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber, + Inode ino) #endif { #if defined(AFS_NAMEI_ENV) @@ -815,24 +876,32 @@ void PrintVnode(int offset, VnodeDiskObject *vnode, int vnodeNumber, Inode ino) char filename[MAX_PATH]; #endif #endif - Vvnodesize += vnode->length; - if (dsizeOnly) return; - if (orphaned && (vnode->length ==0 || vnode->parent || !offset)) return; - printf("%10d Vnode %u.%u.%u cloned: %d, length: %d linkCount: %d parent: %d", - offset, vnodeNumber, vnode->uniquifier, vnode->dataVersion, vnode->cloned, vnode->length, vnode->linkCount, vnode->parent); + afs_fsize_t fileLength; + + VNDISK_GET_LEN(fileLength, vnode); + Vvnodesize += fileLength; + if (dsizeOnly) + return; + if (orphaned && (fileLength == 0 || vnode->parent || !offset)) + return; + printf + ("%10d Vnode %u.%u.%u cloned: %u, length: %llu linkCount: %d parent: %u", + offset, vnodeNumber, vnode->uniquifier, vnode->dataVersion, + vnode->cloned, (afs_uintmax_t) fileLength, vnode->linkCount, + vnode->parent); if (DumpInodeNumber) printf(" inode: %s", PrintInode(NULL, ino)); if (DumpDate) printf(" ServerModTime: %s", date(vnode->serverModifyTime)); #if defined(AFS_NAMEI_ENV) - if(PrintFileNames) { - IH_INIT(ihtmpp, V_device(vp), V_parentId(vp), ino); + if (PrintFileNames) { + IH_INIT(ihtmpp, V_device(vp), V_parentId(vp), ino); #if !defined(AFS_NT40_ENV) - namei_HandleToName(&filename, ihtmpp); - printf(" UFS-Filename: %s",filename.n_path); + namei_HandleToName(&filename, ihtmpp); + printf(" UFS-Filename: %s", filename.n_path); #else - nt_HandleToName(filename, ihtmpp); - printf(" NTFS-Filename: %s",filename); + nt_HandleToName(filename, ihtmpp); + printf(" NTFS-Filename: %s", filename); #endif } #endif diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 8b0f0d17f..fc3ddc890 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -91,7 +91,8 @@ Vnodes with 0 inode pointers in RW volumes are now deleted. #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vol-salvage.c,v 1.1.1.13 2003/07/30 17:13:41 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/vol-salvage.c,v 1.40 2003/12/07 22:49:43 jaltman Exp $"); #include #include @@ -132,7 +133,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vol-salvage.c,v 1.1.1.13 2003/07/30 #else /* AFS_VFSINCL_ENV */ #ifdef AFS_OSF_ENV #include -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV) #include #endif @@ -172,7 +173,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vol-salvage.c,v 1.1.1.13 2003/07/30 #include #include #include -#include /* signal(), kill(), wait(), etc. */ +#include /* signal(), kill(), wait(), etc. */ #ifndef AFS_NT40_ENV #include #endif @@ -188,15 +189,36 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vol-salvage.c,v 1.1.1.13 2003/07/30 #include "fssync.h" #include "viceinode.h" #include "salvage.h" -#include "volinodes.h" /* header magic number, etc. stuff */ +#include "volinodes.h" /* header magic number, etc. stuff */ #ifdef AFS_NT40_ENV #include #endif +/*@+fcnmacros +macrofcndecl@*/ +#ifdef O_LARGEFILE +#ifdef S_SPLINT_S +extern off64_t afs_lseek(int FD, off64_t O, int F); +#endif /*S_SPLINT_S */ +#define afs_lseek(FD, O, F) lseek64(FD, (off64_t) (O), F) +#define afs_stat stat64 +#define afs_fstat fstat64 +#define afs_open open64 +#define afs_fopen fopen64 +#else /* !O_LARGEFILE */ +#ifdef S_SPLINT_S +extern off_t afs_lseek(int FD, off_t O, int F); +#endif /*S_SPLINT_S */ +#define afs_lseek(FD, O, F) lseek(FD, (off_t) (O), F) +#define afs_stat stat +#define afs_fstat fstat +#define afs_open open +#define afs_fopen fopen +#endif /* !O_LARGEFILE */ +/*@=fcnmacros =macrofcndecl@*/ + #ifdef AFS_OSF_ENV extern void *calloc(); #endif -extern char *vol_DevName(); static char *TimeStamp(time_t clock, int precision); #define ORPH_IGNORE 0 @@ -204,84 +226,84 @@ static char *TimeStamp(time_t clock, int precision); #define ORPH_ATTACH 2 -int debug; /* -d flag */ -int Testing=0; /* -n flag */ -int ListInodeOption; /* -i flag */ -int ShowRootFiles; /* -r flag */ -int RebuildDirs; /* -sal flag */ -int Parallel = 4; /* -para X flag */ -int PartsPerDisk = 8; /* Salvage up to 8 partitions on same disk sequentially */ -int forceR = 0; /* -b flag */ -int ShowLog = 0; /* -showlog flag */ -int ShowSuid = 0; /* -showsuid flag */ -int ShowMounts = 0; /* -showmounts flag */ -int orphans = ORPH_IGNORE; /* -orphans option */ -int Showmode = 0; +int debug; /* -d flag */ +int Testing = 0; /* -n flag */ +int ListInodeOption; /* -i flag */ +int ShowRootFiles; /* -r flag */ +int RebuildDirs; /* -sal flag */ +int Parallel = 4; /* -para X flag */ +int PartsPerDisk = 8; /* Salvage up to 8 partitions on same disk sequentially */ +int forceR = 0; /* -b flag */ +int ShowLog = 0; /* -showlog flag */ +int ShowSuid = 0; /* -showsuid flag */ +int ShowMounts = 0; /* -showmounts flag */ +int orphans = ORPH_IGNORE; /* -orphans option */ +int Showmode = 0; #ifndef AFS_NT40_ENV -int useSyslog = 0; /* -syslog flag */ -int useSyslogFacility = LOG_DAEMON; /* -syslogfacility option */ +int useSyslog = 0; /* -syslog flag */ +int useSyslogFacility = LOG_DAEMON; /* -syslogfacility option */ #endif #define MAXPARALLEL 32 -int OKToZap; /* -o flag */ -int ForceSalvage; /* If salvage should occur despite the DONT_SALVAGE flag - in the volume header */ +int OKToZap; /* -o flag */ +int ForceSalvage; /* If salvage should occur despite the DONT_SALVAGE flag + * in the volume header */ static FILE *logFile = 0; /* one of {/usr/afs/logs,/vice/file}/SalvageLog */ #define ROOTINODE 2 /* Root inode of a 4.2 Unix file system - partition */ -Device fileSysDevice; /* The device number of the current - partition being salvaged */ + * partition */ +Device fileSysDevice; /* The device number of the current + * partition being salvaged */ #ifdef AFS_NT40_ENV char fileSysPath[8]; #else -char *fileSysPath; /* The path of the mounted partition currently - being salvaged, i.e. the directory - containing the volume headers */ +char *fileSysPath; /* The path of the mounted partition currently + * being salvaged, i.e. the directory + * containing the volume headers */ #endif -char *fileSysPathName; /* NT needs this to make name pretty in log. */ +char *fileSysPathName; /* NT needs this to make name pretty in log. */ IHandle_t *VGLinkH; /* Link handle for current volume group. */ int VGLinkH_cnt; /* # of references to lnk handle. */ -struct DiskPartition *fileSysPartition; /* Partition being salvaged */ +struct DiskPartition *fileSysPartition; /* Partition being salvaged */ #ifndef AFS_NT40_ENV -char *fileSysDeviceName; /* The block device where the file system - being salvaged was mounted */ -char *filesysfulldev; +char *fileSysDeviceName; /* The block device where the file system + * being salvaged was mounted */ +char *filesysfulldev; #endif -int VolumeChanged; /* Set by any routine which would change the volume in - a way which would require callback is to be broken if the - volume was put back on line by an active file server */ - -VolumeDiskData VolInfo; /* A copy of the last good or salvaged volume header dealt with */ +int VolumeChanged; /* Set by any routine which would change the volume in + * a way which would require callback is to be broken if the + * volume was put back on line by an active file server */ + +VolumeDiskData VolInfo; /* A copy of the last good or salvaged volume header dealt with */ struct InodeSummary { /* Inode summary file--an entry for each - volume in the inode file for a partition */ - VolId volumeId; /* Volume id */ - VolId RWvolumeId; /* RW volume associated */ - int index; /* index into inode file (0, 1, 2 ...) */ - int nInodes; /* Number of inodes for this volume */ - int nSpecialInodes; /* Number of special inodes, i.e. volume - header, index, etc. These are all - marked (viceinode.h) and will all be sorted - to the beginning of the information for - this volume. Read-only volumes should - ONLY have special inodes (all the other - inodes look as if they belong to the - original RW volume). */ - Unique maxUniquifier; /* The maximum uniquifier found in all the inodes. - This is only useful for RW volumes and is used - to compute a new volume uniquifier in the event - that the header needs to be recreated. The inode - uniquifier may be a truncated version of vnode - uniquifier (AFS_3DISPARES). The real maxUniquifer - is from the vnodes and later calcuated from it */ + * volume in the inode file for a partition */ + VolId volumeId; /* Volume id */ + VolId RWvolumeId; /* RW volume associated */ + int index; /* index into inode file (0, 1, 2 ...) */ + int nInodes; /* Number of inodes for this volume */ + int nSpecialInodes; /* Number of special inodes, i.e. volume + * header, index, etc. These are all + * marked (viceinode.h) and will all be sorted + * to the beginning of the information for + * this volume. Read-only volumes should + * ONLY have special inodes (all the other + * inodes look as if they belong to the + * original RW volume). */ + Unique maxUniquifier; /* The maximum uniquifier found in all the inodes. + * This is only useful for RW volumes and is used + * to compute a new volume uniquifier in the event + * that the header needs to be recreated. The inode + * uniquifier may be a truncated version of vnode + * uniquifier (AFS_3DISPARES). The real maxUniquifer + * is from the vnodes and later calcuated from it */ struct VolumeSummary *volSummary; - /* Either a pointer to the original volume - header summary, or constructed summary - information */ + /* Either a pointer to the original volume + * header summary, or constructed summary + * information */ } *inodeSummary; #define readOnly(isp) ((isp)->volumeId != (isp)->RWvolumeId) int nVolumesInInodeFile; /* Number of read-write volumes summarized */ @@ -289,61 +311,61 @@ int inodeFd; /* File descriptor for inode file */ struct VolumeSummary { /* Volume summary an entry for each - volume in a volume directory. - Assumption: one volume directory per - partition */ - char *fileName; /* File name on the partition for the volume - header */ - struct VolumeHeader header; - /* volume number, rw volume number, inode - numbers of each major component of - the volume */ - IHandle_t *volumeInfoHandle; - byte wouldNeedCallback; /* set if the file server should issue - call backs for all the files in this volume when - the volume goes back on line */ + * volume in a volume directory. + * Assumption: one volume directory per + * partition */ + char *fileName; /* File name on the partition for the volume + * header */ + struct VolumeHeader header; + /* volume number, rw volume number, inode + * numbers of each major component of + * the volume */ + IHandle_t *volumeInfoHandle; + byte wouldNeedCallback; /* set if the file server should issue + * call backs for all the files in this volume when + * the volume goes back on line */ }; struct VnodeInfo { - IHandle_t *handle; /* Inode containing this index */ - int nVnodes; /* Total number of vnodes in index */ - int nAllocatedVnodes; /* Total number actually used */ - int volumeBlockCount; /* Total number of blocks used by volume */ - Inode *inodes; /* Directory only */ + IHandle_t *handle; /* Inode containing this index */ + int nVnodes; /* Total number of vnodes in index */ + int nAllocatedVnodes; /* Total number actually used */ + int volumeBlockCount; /* Total number of blocks used by volume */ + Inode *inodes; /* Directory only */ struct VnodeEssence { - short count; /* Number of references to vnode; MUST BE SIGNED */ - unsigned claimed:1; /* Set when a parent directory containing an entry - referencing this vnode is found. The claim - is that the parent in "parent" can point to - this vnode, and no other */ - unsigned changed:1; /* Set if any parameters (other than the count) - in the vnode change. It is determined if the - link count has changed by noting whether it is - 0 after scanning all directories */ - unsigned salvaged:1;/* Set if this directory vnode has already been salvaged. */ - unsigned todelete:1;/* Set if this vnode is to be deleted (should not be claimed) */ - afs_uint32 blockCount; - /* Number of blocks (1K) used by this vnode, - approximately */ - VnodeId parent; /* parent in vnode */ - Unique unique; /* Must match entry! */ - char *name; /* Name of directory entry */ - int modeBits; /* File mode bits */ - Inode InodeNumber; /* file's inode */ - int type; /* File type */ - int author; /* File author */ - int owner; /* File owner */ - int group; /* File group */ + short count; /* Number of references to vnode; MUST BE SIGNED */ + unsigned claimed:1; /* Set when a parent directory containing an entry + * referencing this vnode is found. The claim + * is that the parent in "parent" can point to + * this vnode, and no other */ + unsigned changed:1; /* Set if any parameters (other than the count) + * in the vnode change. It is determined if the + * link count has changed by noting whether it is + * 0 after scanning all directories */ + unsigned salvaged:1; /* Set if this directory vnode has already been salvaged. */ + unsigned todelete:1; /* Set if this vnode is to be deleted (should not be claimed) */ + afs_fsize_t blockCount; + /* Number of blocks (1K) used by this vnode, + * approximately */ + VnodeId parent; /* parent in vnode */ + Unique unique; /* Must match entry! */ + char *name; /* Name of directory entry */ + int modeBits; /* File mode bits */ + Inode InodeNumber; /* file's inode */ + int type; /* File type */ + int author; /* File author */ + int owner; /* File owner */ + int group; /* File group */ } *vnodes; } vnodeInfo[nVNODECLASSES]; - + struct DirSummary { struct DirHandle dirHandle; VnodeId vnodeNumber; Unique unique; unsigned haveDot, haveDotDot; VolumeId rwVid; - int copied; /* If the copy-on-write stuff has been applied */ + int copied; /* If the copy-on-write stuff has been applied */ VnodeId parent; char *name; char *vname; @@ -351,9 +373,9 @@ struct DirSummary { }; -struct VolumeSummary *volumeSummaryp; /* Holds all the volumes in a part */ +struct VolumeSummary *volumeSummaryp; /* Holds all the volumes in a part */ int nVolumes; /* Number of volumes (read-write and read-only) - in volume summary */ + * in volume summary */ #ifdef AFS_NT40_ENV /* For NT, we can fork the per partition salvagers to gain the required @@ -365,7 +387,7 @@ int nVolumes; /* Number of volumes (read-write and read-only) * data transfer. */ #define SALVAGER_MAGIC 0x00BBaaDD -#define NOT_CHILD -1 /* job numbers start at 0 */ +#define NOT_CHILD -1 /* job numbers start at 0 */ /* If new options need to be passed to child, add them here. */ typedef struct { int cj_magic; @@ -374,7 +396,7 @@ typedef struct { } childJob_t; /* Child job this process is running. */ -childJob_t myjob = { SALVAGER_MAGIC, NOT_CHILD}; +childJob_t myjob = { SALVAGER_MAGIC, NOT_CHILD, "" }; int nt_SalvagePartition(char *partName, int jobn); int nt_SetupPartitionSalvage(void *datap, int len); @@ -391,10 +413,12 @@ typedef struct { /* Forward declarations */ -void Log(), Abort(), Exit(); +/*@printflike@*/ void Log(const char *format, ...); +/*@printflike@*/ void Abort(const char *format, ...); +void Exit(int code); int Fork(void); int Wait(char *prog); -char * ToString(char *s); +char *ToString(char *s); void AskOffline(VolumeId volumeId); void AskOnline(VolumeId volumeId, char *partition); void CheckLogFile(void); @@ -406,17 +430,16 @@ void CopyAndSalvage(register struct DirSummary *dir); int CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume); void CopyOnWrite(register struct DirSummary *dir); void CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes, - register struct InodeSummary * summary); + register struct InodeSummary *summary); void DeleteExtraVolumeHeaderFile(register struct VolumeSummary *vsp); void DistilVnodeEssence(VolumeId vid, VnodeClass class, Inode ino, - Unique *maxu); + Unique * maxu); int GetInodeSummary(char *path, VolumeId singleVolumeNumber); void GetVolumeSummary(VolumeId singleVolumeNumber); void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, Unique unique); void MaybeZapVolume(register struct InodeSummary *isp, char *message, - int deleteMe, - int check); + int deleteMe, int check); void ObtainSalvageLock(void); void PrintInodeList(void); void PrintInodeSummary(void); @@ -424,20 +447,21 @@ void PrintVolumeSummary(void); int QuickCheck(register struct InodeSummary *isp, int nVols); void RemoveTheForce(char *path); void SalvageDir(char *name, VolumeId rwVid, struct VnodeInfo *dirVnodeInfo, - IHandle_t *alinkH, int i, struct DirSummary *rootdir, + IHandle_t * alinkH, int i, struct DirSummary *rootdir, int *rootdirfound); void SalvageFileSysParallel(struct DiskPartition *partP); void SalvageFileSys(struct DiskPartition *partP, VolumeId singleVolumeNumber); -void SalvageFileSys1(struct DiskPartition *partP, VolumeId singleVolumeNumber); +void SalvageFileSys1(struct DiskPartition *partP, + VolumeId singleVolumeNumber); int SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, - int check, int *deleteMe); + int check, int *deleteMe); int SalvageIndex(Inode ino, VnodeClass class, int RW, - register struct ViceInodeInfo *ip, - int nInodes, struct VolumeSummary *volSummary, int check); + register struct ViceInodeInfo *ip, int nInodes, + struct VolumeSummary *volSummary, int check); int SalvageVnodes(register struct InodeSummary *rwIsp, - register struct InodeSummary * thisIsp, - register struct ViceInodeInfo * inodes, int check); -int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t *alinkH); + register struct InodeSummary *thisIsp, + register struct ViceInodeInfo *inodes, int check); +int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t * alinkH); void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols); #ifdef AFS_NT40_ENV void SalvageVolumeGroup(register struct InodeSummary *isp, int nVols); @@ -445,59 +469,84 @@ void SalvageVolumeGroup(register struct InodeSummary *isp, int nVols); #define SalvageVolumeGroup DoSalvageVolumeGroup #endif int SalvageVolumeHeaderFile(register struct InodeSummary *isp, - register struct ViceInodeInfo *inodes, - int RW, int check, int *deleteMe); + register struct ViceInodeInfo *inodes, int RW, + int check, int *deleteMe); void showlog(void); int UseTheForceLuke(char *path); static int IsVnodeOrphaned(VnodeId vnode); /* Uniquifier stored in the Inode */ -static Unique IUnique(u) - Unique u; +static Unique +IUnique(Unique u) { #ifdef AFS_3DISPARES - return(u & 0x3fffff); + return (u & 0x3fffff); #else #if defined(AFS_SGI_EXMAG) - return(u & SGI_UNIQMASK); + return (u & SGI_UNIQMASK); #else - return(u); + return (u); #endif /* AFS_SGI_EXMAG */ #endif } -static int BadError(aerror) -register int aerror; { +static int +BadError(register int aerror) +{ if (aerror == EPERM || aerror == ENXIO || aerror == ENOENT) return 1; - return 0; /* otherwise may be transient, e.g. EMFILE */ + return 0; /* otherwise may be transient, e.g. EMFILE */ } char *tmpdir = 0; -static handleit(as) - struct cmd_syndesc *as; +static int +handleit(struct cmd_syndesc *as) { register struct cmd_item *ti; char pname[100], *temp; - afs_int32 seenpart = 0, seenvol = 0, vid = 0; + afs_int32 seenpart = 0, seenvol = 0, vid = 0, seenany = 0; struct DiskPartition *partP; #ifdef AFS_SGI_VNODE_GLUE - if (afs_init_kernel_config(-1) <0) { - printf("Can't determine NUMA configuration, not starting salvager.\n"); + if (afs_init_kernel_config(-1) < 0) { + printf + ("Can't determine NUMA configuration, not starting salvager.\n"); exit(1); } #endif - if (ti = as->parms[0].items) { /* -partition */ +#ifdef FAST_RESTART + { + afs_int32 i; + for (i = 0; i < CMD_MAXPARMS; i++) { + if (as->parms[i].items) { + seenany = 1; + break; + } + } + } + if (!seenany) { + char *msg = + "Exiting immediately without salvage. Look into the FileLog to find volumes which really need to be salvaged!"; + + if (useSyslog) + Log(msg); + else + printf("%s\n", msg); + + Exit(0); + } +#endif /* FAST_RESTART */ + if ((ti = as->parms[0].items)) { /* -partition */ seenpart = 1; strncpy(pname, ti->data, 100); } - if (ti = as->parms[1].items) { /* -volumeid */ + if ((ti = as->parms[1].items)) { /* -volumeid */ if (!seenpart) { - printf("You must also specify '-partition' option with the '-volumeid' option\n"); + printf + ("You must also specify '-partition' option with the '-volumeid' option\n"); exit(-1); } seenvol = 1; @@ -519,81 +568,92 @@ static handleit(as) RebuildDirs = 1; if (as->parms[9].items) /* -ForceReads */ forceR = 1; - if (ti = as->parms[10].items) {/* -Parallel # */ - temp = ti->data; - if (strncmp(temp,"all",3) == 0) { - PartsPerDisk = 1; - temp += 3; + if ((ti = as->parms[10].items)) { /* -Parallel # */ + temp = ti->data; + if (strncmp(temp, "all", 3) == 0) { + PartsPerDisk = 1; + temp += 3; } if (strlen(temp) != 0) { - Parallel = atoi(temp); - if (Parallel < 1) Parallel = 1; - if (Parallel > MAXPARALLEL) { - printf("Setting parallel salvages to maximum of %d \n", MAXPARALLEL); - Parallel = MAXPARALLEL; - } + Parallel = atoi(temp); + if (Parallel < 1) + Parallel = 1; + if (Parallel > MAXPARALLEL) { + printf("Setting parallel salvages to maximum of %d \n", + MAXPARALLEL); + Parallel = MAXPARALLEL; + } } } - if (ti = as->parms[11].items) {/* -tmpdir */ + if ((ti = as->parms[11].items)) { /* -tmpdir */ DIR *dirp; tmpdir = ti->data; dirp = opendir(tmpdir); if (!dirp) { - printf("Can't open temporary placeholder dir %s; using current partition \n", tmpdir); - tmpdir = (char *)0; + printf + ("Can't open temporary placeholder dir %s; using current partition \n", + tmpdir); + tmpdir = NULL; } else closedir(dirp); } - if (ti = as->parms[12].items) /* -showlog */ + if ((ti = as->parms[12].items)) /* -showlog */ ShowLog = 1; - if (ti = as->parms[13].items) { /* -log */ + if ((ti = as->parms[13].items)) { /* -log */ Testing = 1; ShowSuid = 1; Showmode = 1; } - if (ti = as->parms[14].items) { /* -showmounts */ + if ((ti = as->parms[14].items)) { /* -showmounts */ Testing = 1; Showmode = 1; ShowMounts = 1; } - if (ti = as->parms[15].items) { /* -orphans */ - if (Testing) - orphans = ORPH_IGNORE; - else if (strcmp(ti->data, "remove")==0 || strcmp(ti->data, "r")==0) - orphans = ORPH_REMOVE; - else if (strcmp(ti->data, "attach")==0 || strcmp(ti->data, "a")==0) - orphans = ORPH_ATTACH; + if ((ti = as->parms[15].items)) { /* -orphans */ + if (Testing) + orphans = ORPH_IGNORE; + else if (strcmp(ti->data, "remove") == 0 + || strcmp(ti->data, "r") == 0) + orphans = ORPH_REMOVE; + else if (strcmp(ti->data, "attach") == 0 + || strcmp(ti->data, "a") == 0) + orphans = ORPH_ATTACH; + } +#ifndef AFS_NT40_ENV /* ignore options on NT */ + if ((ti = as->parms[16].items)) { /* -syslog */ + useSyslog = 1; + ShowLog = 0; + } + if ((ti = as->parms[17].items)) { /* -syslogfacility */ + useSyslogFacility = atoi(ti->data); } -#ifndef AFS_NT40_ENV /* ignore options on NT */ - if ( ti = as->parms[16].items) { /* -syslog */ - useSyslog = 1; - ShowLog = 0; - } - if ( ti = as->parms[17].items) { /* -syslogfacility */ - useSyslogFacility = atoi(ti->data); - } - if (ti = as->parms[18].items) { /* -datelogs */ - TimeStampLogFile(); - } + if ((ti = as->parms[18].items)) { /* -datelogs */ + TimeStampLogFile(); + } #endif #ifdef FAST_RESTART - if (ti = as->parms[19].items) { /* -DontSalvage */ - printf("Exiting immediately without salvage. Look into the FileLog"); - printf(" to find volumes which really need to be salvaged!\n"); - Exit(0); + if (ti = as->parms[19].items) { /* -DontSalvage */ + char *msg = + "Exiting immediately without salvage. Look into the FileLog to find volumes which really need to be salvaged!"; + + if (useSyslog) + Log(msg); + else + printf("%s\n", msg); + Exit(0); } -#endif /* FAST_RESTART */ - +#endif /* FAST_RESTART */ + /* Note: if seemvol we initialize this as a standard volume utility: this has the - implication that the file server may be running; negotations have to be made with - the file server in this case to take the read write volume and associated read-only - volumes off line before salvaging */ + * implication that the file server may be running; negotations have to be made with + * the file server in this case to take the read write volume and associated read-only + * volumes off line before salvaging */ #ifdef AFS_NT40_ENV if (seenvol) { - if (afs_winsockInit()<0) { + if (afs_winsockInit() < 0) { ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, AFSDIR_SALVAGER_FILE, 0); Log("Failed to initailize winsock, exiting.\n"); @@ -601,38 +661,37 @@ static handleit(as) } } #endif - VInitVolumePackage(seenvol ? volumeUtility: salvager, 5, 5, DONT_CONNECT_FS, 0); + VInitVolumePackage(seenvol ? volumeUtility : salvager, 5, 5, + DONT_CONNECT_FS, 0); DInit(10); #ifdef AFS_NT40_ENV if (myjob.cj_number != NOT_CHILD) { if (!seenpart) { seenpart = 1; - (void) strcpy(pname, myjob.cj_part); + (void)strcpy(pname, myjob.cj_part); } } #endif if (seenpart == 0) { - for (partP = DiskPartitionList; partP; partP = partP->next) { - SalvageFileSysParallel(partP); - } - SalvageFileSysParallel(0); - } - else { + for (partP = DiskPartitionList; partP; partP = partP->next) { + SalvageFileSysParallel(partP); + } + SalvageFileSysParallel(0); + } else { partP = VGetPartition(pname, 0); if (!partP) { - Log("salvage: Unknown or unmounted partition %s; salvage aborted\n", - pname); + Log("salvage: Unknown or unmounted partition %s; salvage aborted\n", pname); Exit(1); } if (!seenvol) SalvageFileSys(partP, 0); - else { + else { /* Salvage individual volume */ if (vid <= 0) { Log("salvage: invalid volume id specified; salvage aborted\n"); Exit(1); } - SalvageFileSys (partP, vid); + SalvageFileSys(partP, vid); } } return (0); @@ -649,13 +708,13 @@ int n_save_args = 0; pthread_t main_thread; #endif -main(argc,argv) -char **argv; +int +main(int argc, char **argv) { struct cmd_syndesc *ts; int err = 0; char commandLine[150]; - + int i; extern char cml_version_number[]; @@ -667,7 +726,7 @@ char **argv; * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; @@ -680,7 +739,8 @@ char **argv; #ifdef AFS_NT40_ENV ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0); #endif - fprintf(stderr,"%s: Unable to obtain AFS server directory.\n", argv[0]); + fprintf(stderr, "%s: Unable to obtain AFS server directory.\n", + argv[0]); exit(2); } #ifdef AFS_NT40_ENV @@ -689,30 +749,30 @@ char **argv; /* This is a child per partition salvager. Don't setup log or * try to lock the salvager lock. */ - if (nt_SetupPartitionSalvage(spawnDatap, spawnDataLen)<0) + if (nt_SetupPartitionSalvage(spawnDatap, spawnDataLen) < 0) exit(3); - } - else { + } else { #endif - for (commandLine[0] = '\0', i=0; i 0) strcat(commandLine, " "); + for (commandLine[0] = '\0', i = 0; i < argc; i++) { + if (i > 0) + strcat(commandLine, " "); strcat(commandLine, argv[i]); } /* All entries to the log will be appended. Useful if there are * multiple salvagers appending to the log. */ - + CheckLogFile(); #ifndef AFS_NT40_ENV #ifdef AFS_LINUX20_ENV - fcntl(fileno(logFile), F_SETFL, O_APPEND); /* Isn't this redundant? */ + fcntl(fileno(logFile), F_SETFL, O_APPEND); /* Isn't this redundant? */ #else - fcntl(fileno(logFile), F_SETFL, FAPPEND); /* Isn't this redundant? */ + fcntl(fileno(logFile), F_SETFL, FAPPEND); /* Isn't this redundant? */ #endif #endif setlinebuf(logFile); - + #ifndef AFS_NT40_ENV if (geteuid() != 0) { printf("Salvager must be run as root.\n"); @@ -720,9 +780,9 @@ char **argv; Exit(0); } #endif - + /* bad for normal help flag processing, but can do nada */ - + fprintf(logFile, "%s\n", cml_version_number); Log("STARTING AFS SALVAGER %s (%s)\n", SalvageVersion, commandLine); @@ -737,52 +797,73 @@ char **argv; #endif ts = cmd_CreateSyntax("initcmd", handleit, 0, "initialize the program"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "Name of partition to salvage"); - cmd_AddParm(ts, "-volumeid", CMD_SINGLE,CMD_OPTIONAL, "Volume Id to salvage"); - cmd_AddParm(ts, "-debug", CMD_FLAG,CMD_OPTIONAL, "Run in Debugging mode"); - cmd_AddParm(ts, "-nowrite", CMD_FLAG,CMD_OPTIONAL, "Run readonly/test mode"); - cmd_AddParm(ts, "-inodes", CMD_FLAG,CMD_OPTIONAL, "Just list affected afs inodes - debugging flag"); - cmd_AddParm(ts, "-force", CMD_FLAG,CMD_OPTIONAL, "Force full salvaging"); - cmd_AddParm(ts, "-oktozap", CMD_FLAG,CMD_OPTIONAL, "Give permission to destroy bogus inodes/volumes - debugging flag"); - cmd_AddParm(ts, "-rootinodes", CMD_FLAG,CMD_OPTIONAL, "Show inodes owned by root - debugging flag"); - cmd_AddParm(ts, "-salvagedirs", CMD_FLAG,CMD_OPTIONAL, "Force rebuild/salvage of all directories"); - cmd_AddParm(ts, "-blockreads", CMD_FLAG,CMD_OPTIONAL, "Read smaller blocks to handle IO/bad blocks"); - cmd_AddParm(ts, "-parallel", CMD_SINGLE,CMD_OPTIONAL, "# of max parallel partition salvaging"); - cmd_AddParm(ts, "-tmpdir", CMD_SINGLE,CMD_OPTIONAL, "Name of dir to place tmp files "); - cmd_AddParm(ts, "-showlog", CMD_FLAG,CMD_OPTIONAL, "Show log file upon completion"); - cmd_AddParm(ts, "-showsuid", CMD_FLAG,CMD_OPTIONAL, "Report on suid/sgid files"); - cmd_AddParm(ts, "-showmounts", CMD_FLAG,CMD_OPTIONAL, "Report on mountpoints"); - cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL, "ignore | remove | attach"); - - /* note - syslog isn't avail on NT, but if we make it conditional, have - to deal with screwy offsets for cmd params */ - cmd_AddParm(ts, "-syslog", CMD_FLAG, CMD_OPTIONAL, "Write salvage log to syslogs"); - cmd_AddParm(ts, "-syslogfacility", CMD_SINGLE, CMD_OPTIONAL, "Syslog facility number to use"); - cmd_AddParm(ts, "-datelogs", CMD_FLAG, CMD_OPTIONAL, "Include timestamp in logfile filename"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, + "Name of partition to salvage"); + cmd_AddParm(ts, "-volumeid", CMD_SINGLE, CMD_OPTIONAL, + "Volume Id to salvage"); + cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, + "Run in Debugging mode"); + cmd_AddParm(ts, "-nowrite", CMD_FLAG, CMD_OPTIONAL, + "Run readonly/test mode"); + cmd_AddParm(ts, "-inodes", CMD_FLAG, CMD_OPTIONAL, + "Just list affected afs inodes - debugging flag"); + cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force full salvaging"); + cmd_AddParm(ts, "-oktozap", CMD_FLAG, CMD_OPTIONAL, + "Give permission to destroy bogus inodes/volumes - debugging flag"); + cmd_AddParm(ts, "-rootinodes", CMD_FLAG, CMD_OPTIONAL, + "Show inodes owned by root - debugging flag"); + cmd_AddParm(ts, "-salvagedirs", CMD_FLAG, CMD_OPTIONAL, + "Force rebuild/salvage of all directories"); + cmd_AddParm(ts, "-blockreads", CMD_FLAG, CMD_OPTIONAL, + "Read smaller blocks to handle IO/bad blocks"); + cmd_AddParm(ts, "-parallel", CMD_SINGLE, CMD_OPTIONAL, + "# of max parallel partition salvaging"); + cmd_AddParm(ts, "-tmpdir", CMD_SINGLE, CMD_OPTIONAL, + "Name of dir to place tmp files "); + cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL, + "Show log file upon completion"); + cmd_AddParm(ts, "-showsuid", CMD_FLAG, CMD_OPTIONAL, + "Report on suid/sgid files"); + cmd_AddParm(ts, "-showmounts", CMD_FLAG, CMD_OPTIONAL, + "Report on mountpoints"); + cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL, + "ignore | remove | attach"); + + /* note - syslog isn't avail on NT, but if we make it conditional, have + * to deal with screwy offsets for cmd params */ + cmd_AddParm(ts, "-syslog", CMD_FLAG, CMD_OPTIONAL, + "Write salvage log to syslogs"); + cmd_AddParm(ts, "-syslogfacility", CMD_SINGLE, CMD_OPTIONAL, + "Syslog facility number to use"); + cmd_AddParm(ts, "-datelogs", CMD_FLAG, CMD_OPTIONAL, + "Include timestamp in logfile filename"); #ifdef FAST_RESTART - cmd_AddParm(ts, "-DontSalvage", CMD_FLAG, CMD_OPTIONAL, "Don't salvage. This my be set in BosConfig to let the fileserver restart immediately after a crash. Bad volumes will be taken offline"); + cmd_AddParm(ts, "-DontSalvage", CMD_FLAG, CMD_OPTIONAL, + "Don't salvage. This my be set in BosConfig to let the fileserver restart immediately after a crash. Bad volumes will be taken offline"); #endif /* FAST_RESTART */ err = cmd_Dispatch(argc, argv); Exit(err); } /* Get the salvage lock if not already held. Hold until process exits. */ -void ObtainSalvageLock(void) +void +ObtainSalvageLock(void) { int salvageLock; - + #ifdef AFS_NT40_ENV - salvageLock = (int) CreateFile(AFSDIR_SERVER_SLVGLOCK_FILEPATH, 0, 0, NULL, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, - NULL); + salvageLock = + (int)CreateFile(AFSDIR_SERVER_SLVGLOCK_FILEPATH, 0, 0, NULL, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (salvageLock == (int)INVALID_HANDLE_VALUE) { fprintf(stderr, "salvager: There appears to be another salvager running! Aborted.\n"); Exit(1); } #else - salvageLock = open(AFSDIR_SERVER_SLVGLOCK_FILEPATH, O_CREAT|O_RDWR, 0666); + salvageLock = + afs_open(AFSDIR_SERVER_SLVGLOCK_FILEPATH, O_CREAT | O_RDWR, 0666); assert(salvageLock >= 0); #ifdef AFS_DARWIN_ENV if (flock(salvageLock, LOCK_EX) == -1) { @@ -801,29 +882,31 @@ void ObtainSalvageLock(void) /* Check if the given partition is mounted. For XFS, the root inode is not a * constant. So we check the hard way. */ -int IsPartitionMounted(char *part) +int +IsPartitionMounted(char *part) { FILE *mntfp; struct mntent *mntent; - + assert(mntfp = setmntent(MOUNTED, "r")); while (mntent = getmntent(mntfp)) { if (!strcmp(part, mntent->mnt_dir)) break; } endmntent(mntfp); - + return mntent ? 1 : 1; } #endif /* Check if the given inode is the root of the filesystem. */ #ifndef AFS_SGI_XFS_IOPS_ENV -int IsRootInode(status) -struct stat *status; +int +IsRootInode(struct afs_stat *status) { - /* The root inode is not a fixed value in XFS partitions. So we need to see if - * the partition is in the list of mounted partitions. This only affects the - * SalvageFileSys path, so we check there. + /* + * The root inode is not a fixed value in XFS partitions. So we need to + * see if the partition is in the list of mounted partitions. This only + * affects the SalvageFileSys path, so we check there. */ return (status->st_ino == ROOTINODE); } @@ -834,26 +917,26 @@ struct stat *status; /* We don't want to salvage big files filesystems, since we can't put volumes on * them. */ -int CheckIfBigFilesFS(mountPoint, devName) - char *mountPoint; - char *devName; +int +CheckIfBigFilesFS(char *mountPoint, char *devName) { struct superblock fs; char name[128]; if (strncmp(devName, "/dev/", 5)) { - (void) sprintf(name, "/dev/%s", devName); - } - else { - (void) strcpy(name, devName); + (void)sprintf(name, "/dev/%s", devName); + } else { + (void)strcpy(name, devName); } - if (ReadSuper(&fs, name)<0) { - Log("Unable to read superblock. Not salvaging partition %s.\n", mountPoint); + if (ReadSuper(&fs, name) < 0) { + Log("Unable to read superblock. Not salvaging partition %s.\n", + mountPoint); return 1; } if (IsBigFilesFileSystem(&fs)) { - Log("Partition %s is a big files filesystem, not salvaging.\n", mountPoint); + Log("Partition %s is a big files filesystem, not salvaging.\n", + mountPoint); return 1; } return 0; @@ -863,15 +946,16 @@ int CheckIfBigFilesFS(mountPoint, devName) #ifdef AFS_NT40_ENV #define HDSTR "\\Device\\Harddisk" -#define HDLEN (sizeof(HDSTR)-1) /* Length of "\Device\Harddisk" */ -int SameDisk(struct DiskPartition *p1, struct DiskPartition *p2) +#define HDLEN (sizeof(HDSTR)-1) /* Length of "\Device\Harddisk" */ +int +SameDisk(struct DiskPartition *p1, struct DiskPartition *p2) { #define RES_LEN 256 char res[RES_LEN]; int d1, d2; - static int dowarn=1; - - if (!QueryDosDevice(p1->devName, res, RES_LEN-1)) + static int dowarn = 1; + + if (!QueryDosDevice(p1->devName, res, RES_LEN - 1)) return 1; if (strncmp(res, HDSTR, HDLEN)) { if (dowarn) { @@ -883,7 +967,7 @@ int SameDisk(struct DiskPartition *p1, struct DiskPartition *p2) } d1 = atoi(&res[HDLEN]); - if (!QueryDosDevice(p2->devName, res, RES_LEN-1)) + if (!QueryDosDevice(p2->devName, res, RES_LEN - 1)) return 1; if (strncmp(res, HDSTR, HDLEN)) { if (dowarn) { @@ -894,7 +978,7 @@ int SameDisk(struct DiskPartition *p1, struct DiskPartition *p2) return 1; } d2 = atoi(&res[HDLEN]); - + return d1 == d2; } #else @@ -904,15 +988,16 @@ int SameDisk(struct DiskPartition *p1, struct DiskPartition *p2) /* This assumes that two partitions with the same device number divided by * PartsPerDisk are on the same disk. */ -void SalvageFileSysParallel(struct DiskPartition *partP) +void +SalvageFileSysParallel(struct DiskPartition *partP) { struct job { - struct DiskPartition *partP; - int pid; /* Pid for this job */ - int jobnumb; /* Log file job number */ - struct job *nextjob; /* Next partition on disk to salvage */ + struct DiskPartition *partP; + int pid; /* Pid for this job */ + int jobnumb; /* Log file job number */ + struct job *nextjob; /* Next partition on disk to salvage */ }; - static struct job *jobs[MAXPARALLEL] = {0}; /* Need to zero this */ + static struct job *jobs[MAXPARALLEL] = { 0 }; /* Need to zero this */ struct job *thisjob = 0; static int numjobs = 0; static int jobcount = 0; @@ -925,167 +1010,177 @@ void SalvageFileSysParallel(struct DiskPartition *partP) int i, j, pid; if (partP) { - /* We have a partition to salvage. Copy it into thisjob */ - thisjob = (struct job *) malloc(sizeof(struct job)); - if (!thisjob) { - Log("Can't salvage '%s'. Not enough memory\n", partP->name); - return; - } - memset(thisjob, 0, sizeof(struct job)); - thisjob->partP = partP; - thisjob->jobnumb = jobcount; - jobcount++; - } - else if (jobcount == 0) { - /* We are asking to wait for all jobs (partp == 0), yet we never - * started any. - */ - Log("No file system partitions named %s* found; not salvaged\n", - VICE_PARTITION_PREFIX); - return; + /* We have a partition to salvage. Copy it into thisjob */ + thisjob = (struct job *)malloc(sizeof(struct job)); + if (!thisjob) { + Log("Can't salvage '%s'. Not enough memory\n", partP->name); + return; + } + memset(thisjob, 0, sizeof(struct job)); + thisjob->partP = partP; + thisjob->jobnumb = jobcount; + jobcount++; + } else if (jobcount == 0) { + /* We are asking to wait for all jobs (partp == 0), yet we never + * started any. + */ + Log("No file system partitions named %s* found; not salvaged\n", + VICE_PARTITION_PREFIX); + return; } if (debug || Parallel == 1) { if (thisjob) { - SalvageFileSys(thisjob->partP, 0); - free(thisjob); + SalvageFileSys(thisjob->partP, 0); + free(thisjob); } return; } if (thisjob) { - /* Check to see if thisjob is for a disk that we are already - * salvaging. If it is, link it in as the next job to do. The - * jobs array has 1 entry per disk being salvages. numjobs is - * the total number of disks currently being salvaged. In - * order to keep thejobs array compact, when a disk is - * completed, the hightest element in the jobs array is moved - * down to now open slot. - */ - for (j=0; jpartP, thisjob->partP)) { - /* On same disk, add it to this list and return */ - thisjob->nextjob = jobs[j]->nextjob; - jobs[j]->nextjob = thisjob; - thisjob = 0; - break; - } - } + /* Check to see if thisjob is for a disk that we are already + * salvaging. If it is, link it in as the next job to do. The + * jobs array has 1 entry per disk being salvages. numjobs is + * the total number of disks currently being salvaged. In + * order to keep thejobs array compact, when a disk is + * completed, the hightest element in the jobs array is moved + * down to now open slot. + */ + for (j = 0; j < numjobs; j++) { + if (SameDisk(jobs[j]->partP, thisjob->partP)) { + /* On same disk, add it to this list and return */ + thisjob->nextjob = jobs[j]->nextjob; + jobs[j]->nextjob = thisjob; + thisjob = 0; + break; + } + } } /* Loop until we start thisjob or until all existing jobs are finished */ - while ( thisjob || (!partP && (numjobs > 0)) ) { - startjob = -1; /* No new job to start */ - - if ( (numjobs >= Parallel) || (!partP && (numjobs > 0)) ) { - /* Either the max jobs are running or we have to wait for all - * the jobs to finish. In either case, we wait for at least one - * job to finish. When it's done, clean up after it. - */ - pid = wait(&wstatus); - assert(pid != -1); - for (j=0; jpid) break; - } - assert(j < numjobs); - if (WCOREDUMP(wstatus)) { /* Say if the job core dumped */ - Log("Salvage of %s core dumped!\n", jobs[j]->partP->name); - } - - numjobs--; /* job no longer running */ - oldjob = jobs[j]; /* remember */ - jobs[j] = jobs[j]->nextjob; /* Step to next part on same disk */ - free(oldjob); /* free the old job */ - - /* If there is another partition on the disk to salvage, then - * say we will start it (startjob). If not, then put thisjob there - * and say we will start it. - */ - if (jobs[j]) { /* Another partitions to salvage */ - startjob = j; /* Will start it */ - } else { /* There is not another partition to salvage */ - if (thisjob) { - jobs[j] = thisjob; /* Add thisjob */ + while (thisjob || (!partP && (numjobs > 0))) { + startjob = -1; /* No new job to start */ + + if ((numjobs >= Parallel) || (!partP && (numjobs > 0))) { + /* Either the max jobs are running or we have to wait for all + * the jobs to finish. In either case, we wait for at least one + * job to finish. When it's done, clean up after it. + */ + pid = wait(&wstatus); + assert(pid != -1); + for (j = 0; j < numjobs; j++) { /* Find which job it is */ + if (pid == jobs[j]->pid) + break; + } + assert(j < numjobs); + if (WCOREDUMP(wstatus)) { /* Say if the job core dumped */ + Log("Salvage of %s core dumped!\n", jobs[j]->partP->name); + } + + numjobs--; /* job no longer running */ + oldjob = jobs[j]; /* remember */ + jobs[j] = jobs[j]->nextjob; /* Step to next part on same disk */ + free(oldjob); /* free the old job */ + + /* If there is another partition on the disk to salvage, then + * say we will start it (startjob). If not, then put thisjob there + * and say we will start it. + */ + if (jobs[j]) { /* Another partitions to salvage */ + startjob = j; /* Will start it */ + } else { /* There is not another partition to salvage */ + if (thisjob) { + jobs[j] = thisjob; /* Add thisjob */ + thisjob = 0; + startjob = j; /* Will start it */ + } else { + jobs[j] = jobs[numjobs]; /* Move last job up to this slot */ + startjob = -1; /* Don't start it - already running */ + } + } + } else { + /* We don't have to wait for a job to complete */ + if (thisjob) { + jobs[numjobs] = thisjob; /* Add this job */ thisjob = 0; - startjob = j; /* Will start it */ - } else { - jobs[j] = jobs[numjobs]; /* Move last job up to this slot */ - startjob = -1; /* Don't start it - already running */ - } - } - } else { - /* We don't have to wait for a job to complete */ - if (thisjob) { - jobs[numjobs] = thisjob; /* Add this job */ - thisjob = 0; - startjob = numjobs; /* Will start it */ - } - } - - /* Start up a new salvage job on a partition in job slot "startjob" */ - if (startjob != -1) { - if (!Showmode) - Log("Starting salvage of file system partition %s\n", - jobs[startjob]->partP->name); + startjob = numjobs; /* Will start it */ + } + } + + /* Start up a new salvage job on a partition in job slot "startjob" */ + if (startjob != -1) { + if (!Showmode) + Log("Starting salvage of file system partition %s\n", + jobs[startjob]->partP->name); #ifdef AFS_NT40_ENV - /* For NT, we not only fork, but re-exec the salvager. Pass in the - * commands and pass the child job number via the data path. - */ - pid = nt_SalvagePartition(jobs[startjob]->partP->name, + /* For NT, we not only fork, but re-exec the salvager. Pass in the + * commands and pass the child job number via the data path. + */ + pid = + nt_SalvagePartition(jobs[startjob]->partP->name, jobs[startjob]->jobnumb); - jobs[startjob]->pid = pid; - numjobs++; + jobs[startjob]->pid = pid; + numjobs++; #else - pid = Fork(); - if (pid) { - jobs[startjob]->pid = pid; - numjobs++; - } else { - int fd; - - ShowLog = 0; - for (fd =0; fd < 16; fd++) close(fd); - open("/", 0); dup2(0, 1); dup2(0, 2); + pid = Fork(); + if (pid) { + jobs[startjob]->pid = pid; + numjobs++; + } else { + int fd; + + ShowLog = 0; + for (fd = 0; fd < 16; fd++) + close(fd); + open("/", 0); + dup2(0, 1); + dup2(0, 2); #ifndef AFS_NT40_ENV - if ( useSyslog ) { - openlog(NULL, LOG_PID, useSyslogFacility); - } else -#endif - { - sprintf(logFileName, "%s.%d", AFSDIR_SERVER_SLVGLOG_FILEPATH, jobs[startjob]->jobnumb); - logFile = fopen(logFileName, "w"); - } - if (!logFile) logFile = stdout; + if (useSyslog) { + openlog("salvager", LOG_PID, useSyslogFacility); + } else +#endif + { + (void)afs_snprintf(logFileName, sizeof logFileName, + "%s.%d", + AFSDIR_SERVER_SLVGLOG_FILEPATH, + jobs[startjob]->jobnumb); + logFile = afs_fopen(logFileName, "w"); + } + if (!logFile) + logFile = stdout; - SalvageFileSys1(jobs[startjob]->partP, 0); - Exit(0); - } + SalvageFileSys1(jobs[startjob]->partP, 0); + Exit(0); + } #endif - } - } /* while ( thisjob || (!partP && numjobs > 0) ) */ + } + } /* while ( thisjob || (!partP && numjobs > 0) ) */ /* If waited for all jobs to complete, now collect log files and return */ #ifndef AFS_NT40_ENV - if ( ! useSyslog ) /* if syslogging - no need to collect */ -#endif - if (!partP) { - for (i=0; idevice; @@ -1132,7 +1227,7 @@ void SalvageFileSys1(struct DiskPartition *partP, VolumeId singleVolumeNumber) #ifdef AFS_NT40_ENV /* Opendir can fail on "C:" but not on "C:\" if C is empty! */ - (void) sprintf(fileSysPath, "%s\\", fileSysPathName); + (void)sprintf(fileSysPath, "%s\\", fileSysPathName); name = partP->devName; #else fileSysPath = fileSysPathName; @@ -1153,9 +1248,10 @@ void SalvageFileSys1(struct DiskPartition *partP, VolumeId singleVolumeNumber) Abort("Couldn't connect to file server\n"); } AskOffline(singleVolumeNumber); - } - else { - if (!Showmode) Log("SALVAGING FILE SYSTEM PARTITION %s (device=%s%s)\n", partP->name, name, (Testing? "(READONLY mode)":"")); + } else { + if (!Showmode) + Log("SALVAGING FILE SYSTEM PARTITION %s (device=%s%s)\n", + partP->name, name, (Testing ? "(READONLY mode)" : "")); if (ForceSalvage) Log("***Forced salvage of all volumes on this partition***\n"); } @@ -1170,9 +1266,9 @@ void SalvageFileSys1(struct DiskPartition *partP, VolumeId singleVolumeNumber) struct dirent *dp; assert((dirp = opendir(fileSysPath)) != NULL); - while (dp = readdir(dirp)) { - if (!strncmp(dp->d_name, "salvage.inodes.", 15) || - !strncmp(dp->d_name, "salvage.temp.", 13)) { + while ((dp = readdir(dirp))) { + if (!strncmp(dp->d_name, "salvage.inodes.", 15) + || !strncmp(dp->d_name, "salvage.temp.", 13)) { char npath[1024]; Log("Removing old salvager temp files %s\n", dp->d_name); strcpy(npath, fileSysPath); @@ -1185,10 +1281,11 @@ void SalvageFileSys1(struct DiskPartition *partP, VolumeId singleVolumeNumber) } tdir = (tmpdir ? tmpdir : fileSysPath); #ifdef AFS_NT40_ENV - (void) _putenv("TMP="); /* If "TMP" is set, then that overrides tdir. */ - (void) strncpy(inodeListPath, _tempnam(tdir, "salvage.inodes."), 255); + (void)_putenv("TMP="); /* If "TMP" is set, then that overrides tdir. */ + (void)strncpy(inodeListPath, _tempnam(tdir, "salvage.inodes."), 255); #else - snprintf(inodeListPath, 255, "%s/salvage.inodes.%s.%d", tdir, name, getpid()); + snprintf(inodeListPath, 255, "%s/salvage.inodes.%s.%d", tdir, name, + getpid()); #endif if (GetInodeSummary(inodeListPath, singleVolumeNumber) < 0) { unlink(inodeListPath); @@ -1200,107 +1297,110 @@ void SalvageFileSys1(struct DiskPartition *partP, VolumeId singleVolumeNumber) * mean to unlink the file at that point. Those places have been * modified to actually do that so that the NT crt can be used there. */ - inodeFd = _open_osfhandle((long)nt_open(inodeListPath, O_RDWR, 0), O_RDWR); - nt_unlink(inodeListPath); /* NT's crt unlink won't if file is open. */ + inodeFd = + _open_osfhandle((long)nt_open(inodeListPath, O_RDWR, 0), O_RDWR); + nt_unlink(inodeListPath); /* NT's crt unlink won't if file is open. */ #else - inodeFd = open(inodeListPath, O_RDONLY); + inodeFd = afs_open(inodeListPath, O_RDONLY); unlink(inodeListPath); #endif if (inodeFd == -1) - Abort("Temporary file %s is missing...\n", - inodeListPath); + Abort("Temporary file %s is missing...\n", inodeListPath); if (ListInodeOption) { PrintInodeList(); return; } /* enumerate volumes in the partition. - figure out sets of read-only + rw volumes. - salvage each set, read-only volumes first, then read-write. - Fix up inodes on last volume in set (whether it is read-write - or read-only). - */ + * figure out sets of read-only + rw volumes. + * salvage each set, read-only volumes first, then read-write. + * Fix up inodes on last volume in set (whether it is read-write + * or read-only). + */ GetVolumeSummary(singleVolumeNumber); - for (i = j = 0,vsp = volumeSummaryp,esp = vsp+nVolumes; i < nVolumesInInodeFile; i = j) { + for (i = j = 0, vsp = volumeSummaryp, esp = vsp + nVolumes; + i < nVolumesInInodeFile; i = j) { VolumeId rwvid = inodeSummary[i].RWvolumeId; - for (j=i; j < nVolumesInInodeFile - && inodeSummary[j].RWvolumeId == rwvid; j++) { + for (j = i; + j < nVolumesInInodeFile && inodeSummary[j].RWvolumeId == rwvid; + j++) { VolumeId vid = inodeSummary[j].volumeId; struct VolumeSummary *tsp; /* Scan volume list (from partition root directory) looking for the - current rw volume number in the volume list from the inode scan. - If there is one here that is not in the inode volume list, - delete it now. */ - for ( ; vspheader.parent < rwvid); vsp++) { + * current rw volume number in the volume list from the inode scan. + * If there is one here that is not in the inode volume list, + * delete it now. */ + for (; vsp < esp && (vsp->header.parent < rwvid); vsp++) { if (vsp->fileName) DeleteExtraVolumeHeaderFile(vsp); } /* Now match up the volume summary info from the root directory with the - entry in the volume list obtained from scanning inodes */ + * entry in the volume list obtained from scanning inodes */ inodeSummary[j].volSummary = NULL; - for (tsp = vsp; tspheader.parent == rwvid); tsp++) { + for (tsp = vsp; tsp < esp && (tsp->header.parent == rwvid); tsp++) { if (tsp->header.id == vid) { inodeSummary[j].volSummary = tsp; tsp->fileName = 0; break; } } - } + } /* Salvage the group of volumes (several read-only + 1 read/write) * starting with the current read-only volume we're looking at. */ - SalvageVolumeGroup(&inodeSummary[i], j-i); + SalvageVolumeGroup(&inodeSummary[i], j - i); } /* Delete any additional volumes that were listed in the partition but which didn't have any corresponding inodes */ - for ( ; vspfileName) + for (; vsp < esp; vsp++) { + if (vsp->fileName) DeleteExtraVolumeHeaderFile(vsp); } - if (!singleVolumeNumber) /* Remove the FORCESALVAGE file */ - RemoveTheForce(fileSysPath); + if (!singleVolumeNumber) /* Remove the FORCESALVAGE file */ + RemoveTheForce(fileSysPath); if (!Testing && singleVolumeNumber) { - AskOnline(singleVolumeNumber, fileSysPartition->name); + AskOnline(singleVolumeNumber, fileSysPartition->name); - /* Step through the volumeSummary list and set all volumes on-line. - * The volumes were taken off-line in GetVolumeSummary. - */ - for (j=0; jname); - } - } - else { - if (!Showmode) - Log("SALVAGING OF PARTITION %s%s COMPLETED\n", - fileSysPartition->name, (Testing ? " (READONLY mode)":"")); + /* Step through the volumeSummary list and set all volumes on-line. + * The volumes were taken off-line in GetVolumeSummary. + */ + for (j = 0; j < nVolumes; j++) { + AskOnline(volumeSummaryp[j].header.id, fileSysPartition->name); + } + } else { + if (!Showmode) + Log("SALVAGING OF PARTITION %s%s COMPLETED\n", + fileSysPartition->name, (Testing ? " (READONLY mode)" : "")); } - close(inodeFd); /* SalvageVolumeGroup was the last which needed it. */ + close(inodeFd); /* SalvageVolumeGroup was the last which needed it. */ } -void DeleteExtraVolumeHeaderFile(register struct VolumeSummary *vsp) +void +DeleteExtraVolumeHeaderFile(register struct VolumeSummary *vsp) { - if (!Showmode) Log("The volume header file %s is not associated with any actual data (%sdeleted)\n", - vsp->fileName, (Testing? "would have been ":"")); + if (!Showmode) + Log("The volume header file %s is not associated with any actual data (%sdeleted)\n", vsp->fileName, (Testing ? "would have been " : "")); if (!Testing) unlink(vsp->fileName); vsp->fileName = 0; } -CompareInodes(_p1,_p2) - const void *_p1,*_p2; +CompareInodes(const void *_p1, const void *_p2) { register const struct ViceInodeInfo *p1 = _p1; register const struct ViceInodeInfo *p2 = _p2; - if (p1->u.vnode.vnodeNumber == INODESPECIAL || - p2->u.vnode.vnodeNumber == INODESPECIAL) { + if (p1->u.vnode.vnodeNumber == INODESPECIAL + || p2->u.vnode.vnodeNumber == INODESPECIAL) { VolumeId p1rwid, p2rwid; - p1rwid = (p1->u.vnode.vnodeNumber==INODESPECIAL - ? p1->u.special.parentId : p1->u.vnode.volumeId); - p2rwid = (p2->u.vnode.vnodeNumber==INODESPECIAL - ? p2->u.special.parentId : p2->u.vnode.volumeId); + p1rwid = + (p1->u.vnode.vnodeNumber == + INODESPECIAL ? p1->u.special.parentId : p1->u.vnode.volumeId); + p2rwid = + (p2->u.vnode.vnodeNumber == + INODESPECIAL ? p2->u.special.parentId : p2->u.vnode.volumeId); if (p1rwid < p2rwid) return -1; if (p1rwid > p2rwid) @@ -1308,75 +1408,75 @@ CompareInodes(_p1,_p2) if (p1->u.vnode.vnodeNumber == INODESPECIAL && p2->u.vnode.vnodeNumber == INODESPECIAL) { if (p1->u.vnode.volumeId == p2->u.vnode.volumeId) - return (p1->u.special.type < p2->u.special.type? -1: 1); + return (p1->u.special.type < p2->u.special.type ? -1 : 1); if (p1->u.vnode.volumeId == p1rwid) return -1; if (p2->u.vnode.volumeId == p2rwid) return 1; - return (p1->u.vnode.volumeId < p2->u.vnode.volumeId? -1: 1); + return (p1->u.vnode.volumeId < p2->u.vnode.volumeId ? -1 : 1); } if (p1->u.vnode.vnodeNumber != INODESPECIAL) - return (p2->u.vnode.volumeId == p2rwid? 1: -1); - return (p1->u.vnode.volumeId == p1rwid? -1: 1); + return (p2->u.vnode.volumeId == p2rwid ? 1 : -1); + return (p1->u.vnode.volumeId == p1rwid ? -1 : 1); } - if (p1->u.vnode.volumeIdu.vnode.volumeId) + if (p1->u.vnode.volumeId < p2->u.vnode.volumeId) return -1; - if (p1->u.vnode.volumeId>p2->u.vnode.volumeId) + if (p1->u.vnode.volumeId > p2->u.vnode.volumeId) return 1; if (p1->u.vnode.vnodeNumber < p2->u.vnode.vnodeNumber) return -1; if (p1->u.vnode.vnodeNumber > p2->u.vnode.vnodeNumber) return 1; /* The following tests are reversed, so that the most desirable - of several similar inodes comes first */ + * of several similar inodes comes first */ if (p1->u.vnode.vnodeUniquifier > p2->u.vnode.vnodeUniquifier) { #ifdef AFS_3DISPARES - if (p1->u.vnode.vnodeUniquifier > 3775414 /* 90% of 4.2M */ && - p2->u.vnode.vnodeUniquifier < 419490 /* 10% of 4.2M */) + if (p1->u.vnode.vnodeUniquifier > 3775414 /* 90% of 4.2M */ && + p2->u.vnode.vnodeUniquifier < 419490 /* 10% of 4.2M */ ) return 1; #endif #ifdef AFS_SGI_EXMAG - if (p1->u.vnode.vnodeUniquifier > 15099494 /* 90% of 16M */ && - p2->u.vnode.vnodeUniquifier < 1677721 /* 10% of 16M */) + if (p1->u.vnode.vnodeUniquifier > 15099494 /* 90% of 16M */ && + p2->u.vnode.vnodeUniquifier < 1677721 /* 10% of 16M */ ) return 1; #endif return -1; } if (p1->u.vnode.vnodeUniquifier < p2->u.vnode.vnodeUniquifier) { #ifdef AFS_3DISPARES - if (p2->u.vnode.vnodeUniquifier > 3775414 /* 90% of 4.2M */ && - p1->u.vnode.vnodeUniquifier < 419490 /* 10% of 4.2M */) + if (p2->u.vnode.vnodeUniquifier > 3775414 /* 90% of 4.2M */ && + p1->u.vnode.vnodeUniquifier < 419490 /* 10% of 4.2M */ ) return -1; #endif #ifdef AFS_SGI_EXMAG - if (p2->u.vnode.vnodeUniquifier > 15099494 /* 90% of 16M */ && - p1->u.vnode.vnodeUniquifier < 1677721 /* 10% of 16M */) + if (p2->u.vnode.vnodeUniquifier > 15099494 /* 90% of 16M */ && + p1->u.vnode.vnodeUniquifier < 1677721 /* 10% of 16M */ ) return 1; #endif return 1; } if (p1->u.vnode.inodeDataVersion > p2->u.vnode.inodeDataVersion) { #ifdef AFS_3DISPARES - if (p1->u.vnode.inodeDataVersion > 1887437 /* 90% of 2.1M */ && - p2->u.vnode.inodeDataVersion < 209716 /* 10% of 2.1M */) + if (p1->u.vnode.inodeDataVersion > 1887437 /* 90% of 2.1M */ && + p2->u.vnode.inodeDataVersion < 209716 /* 10% of 2.1M */ ) return 1; #endif #ifdef AFS_SGI_EXMAG - if (p1->u.vnode.inodeDataVersion > 15099494 /* 90% of 16M */ && - p2->u.vnode.inodeDataVersion < 1677721 /* 10% of 16M */) + if (p1->u.vnode.inodeDataVersion > 15099494 /* 90% of 16M */ && + p2->u.vnode.inodeDataVersion < 1677721 /* 10% of 16M */ ) return 1; #endif return -1; } if (p1->u.vnode.inodeDataVersion < p2->u.vnode.inodeDataVersion) { #ifdef AFS_3DISPARES - if (p2->u.vnode.inodeDataVersion > 1887437 /* 90% of 2.1M */ && - p1->u.vnode.inodeDataVersion < 209716 /* 10% of 2.1M */) + if (p2->u.vnode.inodeDataVersion > 1887437 /* 90% of 2.1M */ && + p1->u.vnode.inodeDataVersion < 209716 /* 10% of 2.1M */ ) return -1; #endif #ifdef AFS_SGI_EXMAG - if (p2->u.vnode.inodeDataVersion > 15099494 /* 90% of 16M */ && - p1->u.vnode.inodeDataVersion < 1677721 /* 10% of 16M */) + if (p2->u.vnode.inodeDataVersion > 15099494 /* 90% of 16M */ && + p1->u.vnode.inodeDataVersion < 1677721 /* 10% of 16M */ ) return 1; #endif return 1; @@ -1384,8 +1484,9 @@ CompareInodes(_p1,_p2) return 0; } -void CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes, - register struct InodeSummary * summary) +void +CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes, + register struct InodeSummary *summary) { int volume = ip->u.vnode.volumeId; int rwvolume = volume; @@ -1399,9 +1500,8 @@ void CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes, nSpecial++; rwvolume = ip->u.special.parentId; /* This isn't quite right, as there could (in error) be different - parent inodes in different special vnodes */ - } - else { + * parent inodes in different special vnodes */ + } else { if (maxunique < ip->u.vnode.vnodeUniquifier) maxunique = ip->u.vnode.vnodeUniquifier; } @@ -1409,14 +1509,13 @@ void CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes, } summary->volumeId = volume; summary->RWvolumeId = rwvolume; - summary->nInodes =n; + summary->nInodes = n; summary->nSpecialInodes = nSpecial; summary->maxUniquifier = maxunique; } -int OnlyOneVolume(inodeinfo, singleVolumeNumber) - struct ViceInodeInfo *inodeinfo; - VolumeId singleVolumeNumber; +int +OnlyOneVolume(struct ViceInodeInfo *inodeinfo, VolumeId singleVolumeNumber) { if (inodeinfo->u.vnode.vnodeNumber == INODESPECIAL) return (inodeinfo->u.special.parentId == singleVolumeNumber); @@ -1429,9 +1528,10 @@ int OnlyOneVolume(inodeinfo, singleVolumeNumber) * unlink the file and abort. For lessor errors, return -1. The file will * be unlinked by the caller. */ -int GetInodeSummary(char *path, VolumeId singleVolumeNumber) +int +GetInodeSummary(char *path, VolumeId singleVolumeNumber) { - struct stat status; + struct afs_stat status; int forceSal, err; struct ViceInodeInfo *ip; struct InodeSummary summary; @@ -1448,10 +1548,12 @@ int GetInodeSummary(char *path, VolumeId singleVolumeNumber) char *tdir; /* This file used to come from vfsck; cobble it up ourselves now... */ - if ((err = ListViceInodes(dev, fileSysPath, path, singleVolumeNumber?OnlyOneVolume:0, singleVolumeNumber, &forceSal, forceR, wpath)) < 0) { - if (err == -2) { - Log("*** I/O error %d when writing a tmp inode file %s; Not salvaged %s ***\nIncrease space on partition or use '-tmpdir'\n", - errno, path, dev); + if ((err = + ListViceInodes(dev, fileSysPath, path, + singleVolumeNumber ? OnlyOneVolume : 0, + singleVolumeNumber, &forceSal, forceR, wpath)) < 0) { + if (err == -2) { + Log("*** I/O error %d when writing a tmp inode file %s; Not salvaged %s ***\nIncrease space on partition or use '-tmpdir'\n", errno, path, dev); return -1; } unlink(path); @@ -1461,53 +1563,71 @@ int GetInodeSummary(char *path, VolumeId singleVolumeNumber) Log("***Forced salvage of all volumes on this partition***\n"); ForceSalvage = 1; } - inodeFd = open(path, O_RDWR); - if (inodeFd == -1 || fstat(inodeFd, &status) == -1) { + inodeFd = afs_open(path, O_RDWR); + if (inodeFd == -1 || afs_fstat(inodeFd, &status) == -1) { unlink(path); Abort("No inode description file for \"%s\"; not salvaged\n", dev); } tdir = (tmpdir ? tmpdir : part); #ifdef AFS_NT40_ENV - (void) _putenv("TMP="); /* If "TMP" is set, then that overrides tdir. */ - (void) strcpy(summaryFileName, _tempnam(tdir, "salvage.temp")); + (void)_putenv("TMP="); /* If "TMP" is set, then that overrides tdir. */ + (void)strcpy(summaryFileName, _tempnam(tdir, "salvage.temp")); #else - sprintf(summaryFileName, "%s/salvage.temp.%d", tdir, getpid()); + (void)afs_snprintf(summaryFileName, sizeof summaryFileName, + "%s/salvage.temp.%d", tdir, getpid()); #endif - summaryFile = fopen(summaryFileName, "a+"); + summaryFile = afs_fopen(summaryFileName, "a+"); if (summaryFile == NULL) { close(inodeFd); unlink(path); Abort("Unable to create inode summary file\n"); } if (!canfork || debug || Fork() == 0) { - int nInodes; + int nInodes; nInodes = status.st_size / sizeof(struct ViceInodeInfo); if (nInodes == 0) { - fclose(summaryFile); close(inodeFd); + fclose(summaryFile); + close(inodeFd); unlink(summaryFileName); - if (!singleVolumeNumber) /* Remove the FORCESALVAGE file */ - RemoveTheForce(fileSysPath); + if (!singleVolumeNumber) /* Remove the FORCESALVAGE file */ + RemoveTheForce(fileSysPath); + else { + struct VolumeSummary *vsp; + int i, j; + + GetVolumeSummary(singleVolumeNumber); + + for (i = 0,vsp = volumeSummaryp; i < nVolumes; i++) { + if (vsp->fileName) + DeleteExtraVolumeHeaderFile(vsp); + } + } Log("%s vice inodes on %s; not salvaged\n", - singleVolumeNumber? "No applicable": "No", dev); + singleVolumeNumber ? "No applicable" : "No", dev); return -1; } - ip = (struct ViceInodeInfo *) malloc(status.st_size); + ip = (struct ViceInodeInfo *)malloc(status.st_size); if (ip == NULL) { - fclose(summaryFile); close(inodeFd); + fclose(summaryFile); + close(inodeFd); unlink(path); unlink(summaryFileName); - Abort("Unable to allocate enough space to read inode table; %s not salvaged\n", dev); + Abort + ("Unable to allocate enough space to read inode table; %s not salvaged\n", + dev); } if (read(inodeFd, ip, status.st_size) != status.st_size) { - fclose(summaryFile); close(inodeFd); + fclose(summaryFile); + close(inodeFd); unlink(path); unlink(summaryFileName); Abort("Unable to read inode table; %s not salvaged\n", dev); } qsort(ip, nInodes, sizeof(struct ViceInodeInfo), CompareInodes); - if (lseek(inodeFd, 0, SEEK_SET) == -1 || - write(inodeFd, ip, status.st_size) != status.st_size) { - fclose(summaryFile); close(inodeFd); + if (afs_lseek(inodeFd, 0, SEEK_SET) == -1 + || write(inodeFd, ip, status.st_size) != status.st_size) { + fclose(summaryFile); + close(inodeFd); unlink(path); unlink(summaryFileName); Abort("Unable to rewrite inode table; %s not salvaged\n", dev); @@ -1515,9 +1635,10 @@ int GetInodeSummary(char *path, VolumeId singleVolumeNumber) summary.index = 0; while (nInodes) { CountVolumeInodes(ip, nInodes, &summary); - if (fwrite(&summary, sizeof (summary), 1, summaryFile) != 1) { + if (fwrite(&summary, sizeof(summary), 1, summaryFile) != 1) { Log("Difficulty writing summary file (errno = %d); %s not salvaged\n", errno, dev); - fclose(summaryFile); close(inodeFd); + fclose(summaryFile); + close(inodeFd); return -1; } summary.index += (summary.nInodes); @@ -1527,33 +1648,34 @@ int GetInodeSummary(char *path, VolumeId singleVolumeNumber) /* Following fflush is not fclose, because if it was debug mode would not work */ if (fflush(summaryFile) == EOF || fsync(fileno(summaryFile)) == -1) { Log("Unable to write summary file (errno = %d); %s not salvaged\n", errno, dev); - fclose(summaryFile); close(inodeFd); + fclose(summaryFile); + close(inodeFd); return -1; } if (canfork && !debug) { ShowLog = 0; Exit(0); } - } - else { + } else { if (Wait("Inode summary") == -1) { - fclose(summaryFile); close(inodeFd); + fclose(summaryFile); + close(inodeFd); unlink(path); unlink(summaryFileName); - Exit(1); /* salvage of this partition aborted */ + Exit(1); /* salvage of this partition aborted */ } } - assert(fstat(fileno(summaryFile), &status) != -1); - if ( status.st_size != 0 ) { + assert(afs_fstat(fileno(summaryFile), &status) != -1); + if (status.st_size != 0) { int ret; - inodeSummary = (struct InodeSummary *) malloc(status.st_size); + inodeSummary = (struct InodeSummary *)malloc(status.st_size); assert(inodeSummary != NULL); /* For GNU we need to do lseek to get the file pointer moved. */ - assert(lseek(fileno(summaryFile), 0, SEEK_SET) == 0); + assert(afs_lseek(fileno(summaryFile), 0, SEEK_SET) == 0); ret = read(fileno(summaryFile), inodeSummary, status.st_size); assert(ret == status.st_size); } - nVolumesInInodeFile = status.st_size / sizeof (struct InodeSummary); + nVolumesInInodeFile = status.st_size / sizeof(struct InodeSummary); fclose(summaryFile); close(inodeFd); unlink(summaryFileName); @@ -1563,98 +1685,108 @@ int GetInodeSummary(char *path, VolumeId singleVolumeNumber) /* Comparison routine for volume sort. This is setup so that a read-write volume comes immediately before any read-only clones of that volume */ -CompareVolumes(_p1,_p2) - const void *_p1,*_p2; +int +CompareVolumes(const void *_p1, const void *_p2) { register const struct VolumeSummary *p1 = _p1; register const struct VolumeSummary *p2 = _p2; if (p1->header.parent != p2->header.parent) - return p1->header.parent < p2->header.parent? -1: 1; - if (p1->header.id == p1->header.parent) /* p1 is rw volume */ + return p1->header.parent < p2->header.parent ? -1 : 1; + if (p1->header.id == p1->header.parent) /* p1 is rw volume */ return -1; - if (p2->header.id == p2->header.parent) /* p2 is rw volume */ + if (p2->header.id == p2->header.parent) /* p2 is rw volume */ return 1; - return p1->header.id < p2->header.id ? -1: 1; /* Both read-only */ + return p1->header.id < p2->header.id ? -1 : 1; /* Both read-only */ } -void GetVolumeSummary(VolumeId singleVolumeNumber) +void +GetVolumeSummary(VolumeId singleVolumeNumber) { DIR *dirp; afs_int32 nvols = 0; struct VolumeSummary *vsp, vs; struct VolumeDiskHeader diskHeader; - struct dirent *dp; + struct dirent *dp; /* Get headers from volume directory */ if (chdir(fileSysPath) == -1 || (dirp = opendir(".")) == NULL) Abort("Can't read directory %s; not salvaged\n", fileSysPath); if (!singleVolumeNumber) { - while (dp = readdir(dirp)) { + while ((dp = readdir(dirp))) { char *p = dp->d_name; p = strrchr(dp->d_name, '.'); if (p != NULL && strcmp(p, VHDREXT) == 0) { int fd; - if ((fd = open(dp->d_name, O_RDONLY)) != -1 && - read(fd, (char*)&diskHeader, sizeof (diskHeader)) - == sizeof (diskHeader) && - diskHeader.stamp.magic == VOLUMEHEADERMAGIC) { + if ((fd = afs_open(dp->d_name, O_RDONLY)) != -1 + && read(fd, (char *)&diskHeader, sizeof(diskHeader)) + == sizeof(diskHeader) + && diskHeader.stamp.magic == VOLUMEHEADERMAGIC) { DiskToVolumeHeader(&vs.header, &diskHeader); nvols++; } close(fd); - } + } } #ifdef AFS_NT40_ENV - closedir(dirp); dirp = opendir("."); /* No rewinddir for NT */ + closedir(dirp); + dirp = opendir("."); /* No rewinddir for NT */ #else rewinddir(dirp); #endif - if (!nvols) nvols = 1; - volumeSummaryp = (struct VolumeSummary *)malloc(nvols * sizeof(struct VolumeSummary)); + if (!nvols) + nvols = 1; + volumeSummaryp = + (struct VolumeSummary *)malloc(nvols * + sizeof(struct VolumeSummary)); } else - volumeSummaryp = (struct VolumeSummary *)malloc(20 * sizeof(struct VolumeSummary)); + volumeSummaryp = + (struct VolumeSummary *)malloc(20 * sizeof(struct VolumeSummary)); assert(volumeSummaryp != NULL); nVolumes = 0; vsp = volumeSummaryp; - while (dp = readdir(dirp)) { + while ((dp = readdir(dirp))) { char *p = dp->d_name; p = strrchr(dp->d_name, '.'); if (p != NULL && strcmp(p, VHDREXT) == 0) { int error = 0; int fd; - if ((fd = open(dp->d_name, O_RDONLY)) == -1 - || read(fd, &diskHeader, sizeof (diskHeader)) - != sizeof (diskHeader) - || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) { + if ((fd = afs_open(dp->d_name, O_RDONLY)) == -1 + || read(fd, &diskHeader, sizeof(diskHeader)) + != sizeof(diskHeader) + || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) { error = 1; } close(fd); if (error) { if (!singleVolumeNumber) { - if (!Showmode) Log("%s/%s is not a legitimate volume header file; %sdeleted\n", fileSysPathName, - dp->d_name, (Testing? "it would have been ":"")); + if (!Showmode) + Log("%s/%s is not a legitimate volume header file; %sdeleted\n", fileSysPathName, dp->d_name, (Testing ? "it would have been " : "")); if (!Testing) unlink(dp->d_name); } - } - else { + } else { char nameShouldBe[64]; DiskToVolumeHeader(&vsp->header, &diskHeader); - if (singleVolumeNumber && vsp->header.id==singleVolumeNumber && vsp->header.parent!=singleVolumeNumber) { - Log("%u is a read-only volume; not salvaged\n", singleVolumeNumber); + if (singleVolumeNumber && vsp->header.id == singleVolumeNumber + && vsp->header.parent != singleVolumeNumber) { + Log("%u is a read-only volume; not salvaged\n", + singleVolumeNumber); Exit(1); } - if (!singleVolumeNumber || (vsp->header.id==singleVolumeNumber || vsp->header.parent==singleVolumeNumber)) { - sprintf(nameShouldBe, VFORMAT, vsp->header.id); + if (!singleVolumeNumber + || (vsp->header.id == singleVolumeNumber + || vsp->header.parent == singleVolumeNumber)) { + (void)afs_snprintf(nameShouldBe, sizeof nameShouldBe, + VFORMAT, vsp->header.id); if (singleVolumeNumber) AskOffline(vsp->header.id); if (strcmp(nameShouldBe, dp->d_name)) { - if (!Showmode) Log("Volume header file %s is incorrectly named; %sdeleted (it will be recreated later, if necessary)\n", dp->d_name, (Testing ? "it would have been ":"")); + if (!Showmode) + Log("Volume header file %s is incorrectly named; %sdeleted (it will be recreated later, if necessary)\n", dp->d_name, (Testing ? "it would have been " : "")); if (!Testing) unlink(dp->d_name); - } - else { + } else { vsp->fileName = ToString(dp->d_name); nVolumes++; vsp++; @@ -1665,54 +1797,58 @@ void GetVolumeSummary(VolumeId singleVolumeNumber) } } closedir(dirp); - qsort(volumeSummaryp,nVolumes,sizeof (struct VolumeSummary),CompareVolumes); + qsort(volumeSummaryp, nVolumes, sizeof(struct VolumeSummary), + CompareVolumes); } /* Find the link table. This should be associated with the RW volume or, if * a RO only site, then the RO volume. For now, be cautious and hunt carefully. */ -Inode FindLinkHandle(register struct InodeSummary *isp, int nVols, - struct ViceInodeInfo *allInodes) +Inode +FindLinkHandle(register struct InodeSummary *isp, int nVols, + struct ViceInodeInfo *allInodes) { int i, j; struct ViceInodeInfo *ip; - for (i=0; ivolumeId, INODESPECIAL, - VI_LINKTABLE, isp->RWvolumeId); + ino = + IH_CREATE(NULL, fileSysDevice, fileSysPath, 0, isp->volumeId, + INODESPECIAL, VI_LINKTABLE, isp->RWvolumeId); if (!VALID_INO(ino)) - Abort("Unable to allocate link table inode for volume %u (error = %d)\n", - isp->RWvolumeId, errno); + Abort + ("Unable to allocate link table inode for volume %u (error = %d)\n", + isp->RWvolumeId, errno); IH_INIT(VGLinkH, fileSysDevice, isp->RWvolumeId, ino); fdP = IH_OPEN(VGLinkH); if (fdP == NULL) Abort("Can't open link table for volume %u (error = %d)\n", isp->RWvolumeId, errno); - if (FDH_TRUNC(fdP, 0)<0) + if (FDH_TRUNC(fdP, 0) < 0) Abort("Can't truncate link table for volume %u (error = %d)\n", isp->RWvolumeId, errno); version.magic = LINKTABLEMAGIC; version.version = LINKTABLEVERSION; - if (FDH_WRITE(fdP, (char*)&version, sizeof(version)) + if (FDH_WRITE(fdP, (char *)&version, sizeof(version)) != sizeof(version)) Abort("Can't truncate link table for volume %u (error = %d)\n", isp->RWvolumeId, errno); @@ -1729,14 +1865,16 @@ int CreateLinkTable(register struct InodeSummary *isp, Inode ino) } #ifdef AFS_NT40_ENV -void *nt_SVG(void *arg) +void * +nt_SVG(void *arg) { - SVGParms_t *parms = (SVGParms_t*)arg; + SVGParms_t *parms = (SVGParms_t *) arg; DoSalvageVolumeGroup(parms->svgp_inodeSummaryp, parms->svgp_count); return NULL; } -void SalvageVolumeGroup(register struct InodeSummary *isp, int nVols) +void +SalvageVolumeGroup(register struct InodeSummary *isp, int nVols) { pthread_t tid; pthread_attr_t tattr; @@ -1759,8 +1897,7 @@ void SalvageVolumeGroup(register struct InodeSummary *isp, int nVols) } code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); if (code) { - Log("Failed to salvage volume group %u: pthread_attr_setdetachstate()\n", - isp->RWvolumeId); + Log("Failed to salvage volume group %u: pthread_attr_setdetachstate()\n", isp->RWvolumeId); return; } code = pthread_create(&tid, &tattr, nt_SVG, &parms); @@ -1769,13 +1906,14 @@ void SalvageVolumeGroup(register struct InodeSummary *isp, int nVols) isp->RWvolumeId); return; } - (void) pthread_join(tid, NULL); + (void)pthread_join(tid, NULL); } #endif /* AFS_NT40_ENV */ -void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) +void +DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) { - struct ViceInodeInfo *inodes,*allInodes,*ip; + struct ViceInodeInfo *inodes, *allInodes, *ip; int i, totalInodes, size, salvageTo; int haveRWvolume; int check; @@ -1785,7 +1923,8 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) FdHandle_t *fdP = NULL; VGLinkH_cnt = 0; - haveRWvolume = (isp->volumeId==isp->RWvolumeId && isp->nSpecialInodes>0); + haveRWvolume = (isp->volumeId == isp->RWvolumeId + && isp->nSpecialInodes > 0); if ((!ShowMounts) || (ShowMounts && !haveRWvolume)) { if (!ForceSalvage && QuickCheck(isp, nVols)) return; @@ -1793,22 +1932,24 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) if (ShowMounts && !haveRWvolume) return; if (canfork && !debug && Fork() != 0) { - (void) Wait("Salvage volume group"); + (void)Wait("Salvage volume group"); return; } - for (i = 0, totalInodes = 0; iindex; /* this would the base of all the inodes - for the partition, if all the inodes - had been read into memory */ - assert(lseek(inodeFd,isp->index*sizeof(struct ViceInodeInfo),SEEK_SET) != -1); - assert(read(inodeFd,inodes,size) == size); + size = totalInodes * sizeof(struct ViceInodeInfo); + inodes = (struct ViceInodeInfo *)malloc(size); + allInodes = inodes - isp->index; /* this would the base of all the inodes + * for the partition, if all the inodes + * had been read into memory */ + assert(afs_lseek + (inodeFd, isp->index * sizeof(struct ViceInodeInfo), + SEEK_SET) != -1); + assert(read(inodeFd, inodes, size) == size); /* Don't try to salvage a read write volume if there isn't one on this - partition */ - salvageTo = haveRWvolume? 0:1; + * partition */ + salvageTo = haveRWvolume ? 0 : 1; #ifdef AFS_NAMEI_ENV ino = FindLinkHandle(isp, nVols, allInodes); @@ -1818,11 +1959,10 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) } if (!VALID_INO(ino) || fdP == NULL) { Log("%s link table for volume %u.\n", - Testing ? "Would have recreated" :"Recreating", isp->RWvolumeId); + Testing ? "Would have recreated" : "Recreating", isp->RWvolumeId); if (Testing) { IH_INIT(VGLinkH, fileSysDevice, -1, -1); - } - else { + } else { CreateLinkTable(isp, ino); } } @@ -1833,10 +1973,10 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) #endif /* Salvage in reverse order--read/write volume last; this way any - Inodes not referenced by the time we salvage the read/write volume - can be picked up by the read/write volume */ + * Inodes not referenced by the time we salvage the read/write volume + * can be picked up by the read/write volume */ /* ACTUALLY, that's not done right now--the inodes just vanish */ - for (i = nVols-1; i>=salvageTo; i--) { + for (i = nVols - 1; i >= salvageTo; i--) { int rw = (i == 0); struct InodeSummary *lisp = &isp[i]; #ifdef AFS_NAMEI_ENV @@ -1852,17 +1992,19 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) } } #endif - if (!Showmode) Log("%s VOLUME %u%s.\n", rw? "SALVAGING": "CHECKING CLONED", - lisp->volumeId, (Testing?"(READONLY mode)":"")); + if (!Showmode) + Log("%s VOLUME %u%s.\n", rw ? "SALVAGING" : "CHECKING CLONED", + lisp->volumeId, (Testing ? "(READONLY mode)" : "")); /* Check inodes twice. The second time do things seriously. This - way the whole RO volume can be deleted, below, if anything goes wrong */ - for (check = 1; check>=0; check--) { + * way the whole RO volume can be deleted, below, if anything goes wrong */ + for (check = 1; check >= 0; check--) { int deleteMe; - if (SalvageVolumeHeaderFile(lisp,allInodes,rw,check, &deleteMe) == -1) { - MaybeZapVolume(lisp,"Volume header",deleteMe, check); + if (SalvageVolumeHeaderFile(lisp, allInodes, rw, check, &deleteMe) + == -1) { + MaybeZapVolume(lisp, "Volume header", deleteMe, check); if (rw && deleteMe) { - haveRWvolume = 0; /* This will cause its inodes to be deleted--since salvage - volume won't be called */ + haveRWvolume = 0; /* This will cause its inodes to be deleted--since salvage + * volume won't be called */ break; } if (!rw) @@ -1870,8 +2012,8 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) } if (rw && check == 1) continue; - if (SalvageVnodes(isp,lisp,allInodes,check) == -1) { - MaybeZapVolume(lisp,"Vnode index", 0, check); + if (SalvageVnodes(isp, lisp, allInodes, check) == -1) { + MaybeZapVolume(lisp, "Vnode index", 0, check); break; } } @@ -1879,28 +2021,25 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) /* Fix actual inode counts */ if (!Showmode) { - for (ip = inodes; totalInodes; ip++,totalInodes--) { + for (ip = inodes; totalInodes; ip++, totalInodes--) { static int TraceBadLinkCounts = 0; #ifdef AFS_NAMEI_ENV if (VGLinkH->ih_ino == ip->inodeNumber) { dec_VGLinkH = ip->linkCount - VGLinkH_cnt; VGLinkH_p1 = ip->u.param[0]; - continue; /* Deal with this last. */ + continue; /* Deal with this last. */ } #endif if (ip->linkCount != 0 && TraceBadLinkCounts) { - TraceBadLinkCounts--; /* Limit reports, per volume */ - Log("#### DEBUG #### Link count incorrect by %d; inode %s, size %u, p=(%u,%u,%u,%u)\n", - ip->linkCount, PrintInode(NULL, ip->inodeNumber), - ip->byteCount, ip->u.param[0], ip->u.param[1], - ip->u.param[2], ip->u.param[3]); + TraceBadLinkCounts--; /* Limit reports, per volume */ + Log("#### DEBUG #### Link count incorrect by %d; inode %s, size %llu, p=(%u,%u,%u,%u)\n", ip->linkCount, PrintInode(NULL, ip->inodeNumber), (afs_uintmax_t) ip->byteCount, ip->u.param[0], ip->u.param[1], ip->u.param[2], ip->u.param[3]); } while (ip->linkCount > 0) { /* below used to assert, not break */ if (!Testing) { if (IH_DEC(VGLinkH, ip->inodeNumber, ip->u.param[0])) { - Log ("idec failed. inode %s errno %d\n", - PrintInode(NULL, ip->inodeNumber), errno); + Log("idec failed. inode %s errno %d\n", + PrintInode(NULL, ip->inodeNumber), errno); break; } } @@ -1909,9 +2048,9 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) while (ip->linkCount < 0) { /* these used to be asserts */ if (!Testing) { - if (IH_INC(VGLinkH ,ip->inodeNumber, ip->u.param[0])) { - Log ("iinc failed. inode %s errno %d\n", - PrintInode(NULL, ip->inodeNumber) ,errno); + if (IH_INC(VGLinkH, ip->inodeNumber, ip->u.param[0])) { + Log("iinc failed. inode %s errno %d\n", + PrintInode(NULL, ip->inodeNumber), errno); break; } } @@ -1920,16 +2059,16 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) } #ifdef AFS_NAMEI_ENV while (dec_VGLinkH > 0) { - if (IH_DEC(VGLinkH, VGLinkH->ih_ino, VGLinkH_p1)<0) { + if (IH_DEC(VGLinkH, VGLinkH->ih_ino, VGLinkH_p1) < 0) { Log("idec failed on link table, errno = %d\n", errno); } - dec_VGLinkH --; + dec_VGLinkH--; } while (dec_VGLinkH < 0) { - if (IH_INC(VGLinkH, VGLinkH->ih_ino, VGLinkH_p1)<0) { + if (IH_INC(VGLinkH, VGLinkH->ih_ino, VGLinkH_p1) < 0) { Log("iinc failed on link table, errno = %d\n", errno); } - dec_VGLinkH ++; + dec_VGLinkH++; } #endif } @@ -1945,34 +2084,34 @@ void DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) } } -int QuickCheck(register struct InodeSummary *isp, int nVols) +int +QuickCheck(register struct InodeSummary *isp, int nVols) { /* Check headers BEFORE forking */ register int i; IHandle_t *h; - for (i = 0; inSpecialInodes == 0 && nVols >1) + if (i == 0 && isp->nSpecialInodes == 0 && nVols > 1) continue; return 0; } IH_INIT(h, fileSysDevice, vs->header.parent, vs->header.volumeInfo); - if (IH_IREAD(h, 0, (char*)&volHeader, sizeof(volHeader)) + if (IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader)) == sizeof(volHeader) && volHeader.stamp.magic == VOLUMEINFOMAGIC && volHeader.dontSalvage == DONT_SALVAGE - && volHeader.needsSalvaged == 0 - && volHeader.destroyMe == 0) { + && volHeader.needsSalvaged == 0 && volHeader.destroyMe == 0) { if (volHeader.inUse == 1) { volHeader.inUse = 0; volHeader.inService = 1; if (!Testing) { - if (IH_IWRITE(h, 0, (char*)&volHeader, sizeof(volHeader)) + if (IH_IWRITE(h, 0, (char *)&volHeader, sizeof(volHeader)) != sizeof(volHeader)) { IH_RELEASE(h); return 0; @@ -1980,8 +2119,7 @@ int QuickCheck(register struct InodeSummary *isp, int nVols) } } IH_RELEASE(h); - } - else { + } else { IH_RELEASE(h); return 0; } @@ -1998,9 +2136,10 @@ int QuickCheck(register struct InodeSummary *isp, int nVols) * Calls SalvageHeader for each possible type of volume special file. */ -int SalvageVolumeHeaderFile(register struct InodeSummary *isp, - register struct ViceInodeInfo *inodes, - int RW, int check, int *deleteMe) +int +SalvageVolumeHeaderFile(register struct InodeSummary *isp, + register struct ViceInodeInfo *inodes, int RW, + int check, int *deleteMe) { int headerFd = 0; int i; @@ -2009,31 +2148,31 @@ int SalvageVolumeHeaderFile(register struct InodeSummary *isp, struct VolumeDiskHeader diskHeader; if (deleteMe) - *deleteMe = 0; + *deleteMe = 0; memset(&tempHeader, 0, sizeof(tempHeader)); tempHeader.stamp.magic = VOLUMEHEADERMAGIC; tempHeader.stamp.version = VOLUMEHEADERVERSION; tempHeader.id = isp->volumeId; tempHeader.parent = isp->RWvolumeId; /* Check for duplicates (inodes are sorted by type field) */ - for (i = 0; inSpecialInodes-1; i++) { - ip = &inodes[isp->index+i]; - if (ip->u.special.type == (ip+1)->u.special.type) { - if (!Showmode) Log("Duplicate special inodes in volume header; salvage of volume %u aborted\n", isp->volumeId); + for (i = 0; i < isp->nSpecialInodes - 1; i++) { + ip = &inodes[isp->index + i]; + if (ip->u.special.type == (ip + 1)->u.special.type) { + if (!Showmode) + Log("Duplicate special inodes in volume header; salvage of volume %u aborted\n", isp->volumeId); return -1; } } - for (i = 0; inSpecialInodes; i++) { - ip = &inodes[isp->index+i]; + for (i = 0; i < isp->nSpecialInodes; i++) { + ip = &inodes[isp->index + i]; if (ip->u.special.type <= 0 || ip->u.special.type > MAXINODETYPE) { if (check) { Log("Rubbish header inode\n"); return -1; } Log("Rubbish header inode; deleted\n"); - } - else if (!stuff[ip->u.special.type-1].obsolete) { - *(stuff[ip->u.special.type-1].inode) = ip->inodeNumber; + } else if (!stuff[ip->u.special.type - 1].obsolete) { + *(stuff[ip->u.special.type - 1].inode) = ip->inodeNumber; if (!check && ip->u.special.type != VI_LINKTABLE) ip->linkCount--; /* Keep the inode around */ allinodesobsolete = 0; @@ -2047,14 +2186,14 @@ int SalvageVolumeHeaderFile(register struct InodeSummary *isp, } if (!check) - VGLinkH_cnt ++; /* one for every header. */ + VGLinkH_cnt++; /* one for every header. */ if (!RW && !check && isp->volSummary) { ClearROInUseBit(isp->volSummary); return 0; } - for (i = 0; i< MAXINODETYPE; i++) { + for (i = 0; i < MAXINODETYPE; i++) { if (stuff[i].inodeType == VI_LINKTABLE) { /* Gross hack: SalvageHeader does a bcmp on the volume header. * And we may have recreated the link table earlier, so set the @@ -2065,54 +2204,59 @@ int SalvageVolumeHeaderFile(register struct InodeSummary *isp, } continue; } - if (SalvageHeader(&stuff[i],isp,check,deleteMe) == -1 && check) + if (SalvageHeader(&stuff[i], isp, check, deleteMe) == -1 && check) return -1; } if (isp->volSummary == NULL) { char name[64]; - sprintf(name, VFORMAT, isp->volumeId); + (void)afs_snprintf(name, sizeof name, VFORMAT, isp->volumeId); if (check) { Log("No header file for volume %u\n", isp->volumeId); return -1; } - if (!Showmode) Log("No header file for volume %u; %screating %s/%s\n", - isp->volumeId, (Testing?"it would have been ":""), - fileSysPathName, name); - headerFd = open(name, O_RDWR|O_CREAT|O_TRUNC, 0644); + if (!Showmode) + Log("No header file for volume %u; %screating %s/%s\n", + isp->volumeId, (Testing ? "it would have been " : ""), + fileSysPathName, name); + headerFd = afs_open(name, O_RDWR | O_CREAT | O_TRUNC, 0644); assert(headerFd != -1); isp->volSummary = (struct VolumeSummary *) malloc(sizeof(struct VolumeSummary)); isp->volSummary->fileName = ToString(name); - } - else { + } else { char name[64]; /* hack: these two fields are obsolete... */ - isp->volSummary->header.volumeAcl = 0; + isp->volSummary->header.volumeAcl = 0; isp->volSummary->header.volumeMountTable = 0; - if (memcmp(&isp->volSummary->header, &tempHeader, sizeof(struct VolumeHeader))) { + if (memcmp + (&isp->volSummary->header, &tempHeader, + sizeof(struct VolumeHeader))) { /* We often remove the name before calling us, so we make a fake one up */ if (isp->volSummary->fileName) { strcpy(name, isp->volSummary->fileName); } else { - sprintf(name, VFORMAT, isp->volumeId); + (void)afs_snprintf(name, sizeof name, VFORMAT, isp->volumeId); isp->volSummary->fileName = ToString(name); } - Log("Header file %s is damaged or no longer valid%s\n", - name, (check ? "" : "; repairing")); + Log("Header file %s is damaged or no longer valid%s\n", name, + (check ? "" : "; repairing")); if (check) return -1; - headerFd = open(name, O_RDWR|O_TRUNC, 0644); + headerFd = afs_open(name, O_RDWR | O_TRUNC, 0644); assert(headerFd != -1); - } + } } if (headerFd) { - memcpy(&isp->volSummary->header, &tempHeader, sizeof(struct VolumeHeader)); + memcpy(&isp->volSummary->header, &tempHeader, + sizeof(struct VolumeHeader)); if (Testing) { - if (!Showmode) Log("It would have written a new header file for volume %u\n", isp->volumeId); + if (!Showmode) + Log("It would have written a new header file for volume %u\n", + isp->volumeId); } else { VolumeHeaderToDisk(&diskHeader, &tempHeader); if (write(headerFd, &diskHeader, sizeof(struct VolumeDiskHeader)) @@ -2124,27 +2268,28 @@ int SalvageVolumeHeaderFile(register struct InodeSummary *isp, } close(headerFd); } - IH_INIT(isp->volSummary->volumeInfoHandle, fileSysDevice, - isp->RWvolumeId, isp->volSummary->header.volumeInfo); + IH_INIT(isp->volSummary->volumeInfoHandle, fileSysDevice, isp->RWvolumeId, + isp->volSummary->header.volumeInfo); return 0; } -int SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, - int check, int *deleteMe) +int +SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, int check, + int *deleteMe) { union { - VolumeDiskData volumeInfo; - struct versionStamp fileHeader; + VolumeDiskData volumeInfo; + struct versionStamp fileHeader; } header; IHandle_t *specH; int recreate = 0; afs_int32 code; FdHandle_t *fdP; - + if (sp->obsolete) return 0; #ifndef AFS_NAMEI_ENV - if ( sp->inodeType == VI_LINKTABLE) + if (sp->inodeType == VI_LINKTABLE) return 0; #endif if (*(sp->inode) == 0) { @@ -2152,15 +2297,17 @@ int SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, Log("Missing inode in volume header (%s)\n", sp->description); return -1; } - if (!Showmode) Log("Missing inode in volume header (%s); %s\n", - sp->description, (Testing ? "it would have recreated it": "recreating")); + if (!Showmode) + Log("Missing inode in volume header (%s); %s\n", sp->description, + (Testing ? "it would have recreated it" : "recreating")); if (!Testing) { - *(sp->inode) = IH_CREATE(NULL, fileSysDevice, fileSysPath, 0, - isp->volumeId, INODESPECIAL, - sp->inodeType, isp->RWvolumeId); - if (!VALID_INO(*(sp->inode))) - Abort("Unable to allocate inode (%s) for volume header (error = %d)\n", - sp->description, errno); + *(sp->inode) = + IH_CREATE(NULL, fileSysDevice, fileSysPath, 0, isp->volumeId, + INODESPECIAL, sp->inodeType, isp->RWvolumeId); + if (!VALID_INO(*(sp->inode))) + Abort + ("Unable to allocate inode (%s) for volume header (error = %d)\n", + sp->description, errno); } recreate = 1; } @@ -2169,19 +2316,20 @@ int SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, fdP = IH_OPEN(specH); if (OKToZap && (fdP == NULL) && BadError(errno)) { /* bail out early and destroy the volume */ - if (!Showmode) Log("Still can't open volume header inode (%s), destroying volume\n", - sp->description); - if (deleteMe) *deleteMe = 1; + if (!Showmode) + Log("Still can't open volume header inode (%s), destroying volume\n", sp->description); + if (deleteMe) + *deleteMe = 1; IH_RELEASE(specH); return -1; } if (fdP == NULL) - Abort("Unable to open inode (%s) of volume header (error = %d)\n", - sp->description, errno); - - if (!recreate && - (FDH_READ(fdP, (char*)&header, sp->size) != sp->size - || header.fileHeader.magic != sp->stamp.magic)) { + Abort("Unable to open inode (%s) of volume header (error = %d)\n", + sp->description, errno); + + if (!recreate + && (FDH_READ(fdP, (char *)&header, sp->size) != sp->size + || header.fileHeader.magic != sp->stamp.magic)) { if (check) { Log("Part of the header (%s) is corrupted\n", sp->description); FDH_REALLYCLOSE(fdP); @@ -2189,10 +2337,11 @@ int SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, return -1; } Log("Part of the header (%s) is corrupted; recreating\n", - sp->description); + sp->description); recreate = 1; } - if (sp->inodeType == VI_VOLINFO && header.volumeInfo.destroyMe == DESTROY_ME) { + if (sp->inodeType == VI_VOLINFO + && header.volumeInfo.destroyMe == DESTROY_ME) { if (deleteMe) *deleteMe = 1; FDH_REALLYCLOSE(fdP); @@ -2200,56 +2349,64 @@ int SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, return -1; } if (recreate && !Testing) { - if (check) - Abort("Internal error: recreating volume header (%s) in check mode\n", + if (check) + Abort + ("Internal error: recreating volume header (%s) in check mode\n", sp->description); code = FDH_TRUNC(fdP, 0); if (code == -1) - Abort("Unable to truncate volume header file (%s) (error = %d)\n", - sp->description, errno); + Abort("Unable to truncate volume header file (%s) (error = %d)\n", + sp->description, errno); /* The following code should be moved into vutil.c */ if (sp->inodeType == VI_VOLINFO) { struct timeval tp; - memset(&header.volumeInfo, 0, sizeof (header.volumeInfo)); + memset(&header.volumeInfo, 0, sizeof(header.volumeInfo)); header.volumeInfo.stamp = sp->stamp; header.volumeInfo.id = isp->volumeId; header.volumeInfo.parentId = isp->RWvolumeId; - sprintf(header.volumeInfo.name, "bogus.%u",isp->volumeId); - Log("Warning: the name of volume %u is now \"bogus.%u\"\n", isp->volumeId, isp->volumeId); + sprintf(header.volumeInfo.name, "bogus.%u", isp->volumeId); + Log("Warning: the name of volume %u is now \"bogus.%u\"\n", + isp->volumeId, isp->volumeId); header.volumeInfo.inService = 0; header.volumeInfo.blessed = 0; /* The + 1000 is a hack in case there are any files out in venus caches */ - header.volumeInfo.uniquifier = (isp->maxUniquifier+1)+1000; - header.volumeInfo.type = - (isp->volumeId == isp->RWvolumeId? readwriteVolume:readonlyVolume); /* XXXX */ + header.volumeInfo.uniquifier = (isp->maxUniquifier + 1) + 1000; + header.volumeInfo.type = (isp->volumeId == isp->RWvolumeId ? readwriteVolume : readonlyVolume); /* XXXX */ header.volumeInfo.needsCallback = 0; - gettimeofday(&tp,0); + gettimeofday(&tp, 0); header.volumeInfo.creationDate = tp.tv_sec; - if(FDH_SEEK(fdP,0,SEEK_SET)<0) { - Abort("Unable to seek to beginning of volume header file (%s) (errno = %d)\n",sp->description,errno); + if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { + Abort + ("Unable to seek to beginning of volume header file (%s) (errno = %d)\n", + sp->description, errno); } - code = FDH_WRITE(fdP, (char*)&header.volumeInfo, - sizeof(header.volumeInfo)); + code = + FDH_WRITE(fdP, (char *)&header.volumeInfo, + sizeof(header.volumeInfo)); if (code != sizeof(header.volumeInfo)) { - if (code < 0) - Abort("Unable to write volume header file (%s) (errno = %d)\n", - sp->description, errno); - Abort("Unable to write entire volume header file (%s)\n", - sp->description); + if (code < 0) + Abort + ("Unable to write volume header file (%s) (errno = %d)\n", + sp->description, errno); + Abort("Unable to write entire volume header file (%s)\n", + sp->description); } - } - else { - if(FDH_SEEK(fdP,0,SEEK_SET)<0) { - Abort("Unable to seek to beginning of volume header file (%s) (errno = %d)\n",sp->description,errno); - } - code = FDH_WRITE(fdP, (char*)&sp->stamp, sizeof(sp->stamp)); - if (code != sizeof(sp->stamp)) { - if (code < 0) - Abort("Unable to write version stamp in volume header file (%s) (errno = %d)\n", - sp->description, errno); - Abort("Unable to write entire version stamp in volume header file (%s)\n", - sp->description); + } else { + if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { + Abort + ("Unable to seek to beginning of volume header file (%s) (errno = %d)\n", + sp->description, errno); + } + code = FDH_WRITE(fdP, (char *)&sp->stamp, sizeof(sp->stamp)); + if (code != sizeof(sp->stamp)) { + if (code < 0) + Abort + ("Unable to write version stamp in volume header file (%s) (errno = %d)\n", + sp->description, errno); + Abort + ("Unable to write entire version stamp in volume header file (%s)\n", + sp->description); } } } @@ -2261,48 +2418,57 @@ int SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, char update[25]; if (VolInfo.updateDate) { strcpy(update, TimeStamp(VolInfo.updateDate, 0)); - if (!Showmode) Log("%s (%u) %supdated %s\n", VolInfo.name, VolInfo.id, - (Testing?"it would have been ":""), update); + if (!Showmode) + Log("%s (%u) %supdated %s\n", VolInfo.name, VolInfo.id, + (Testing ? "it would have been " : ""), update); } else { strcpy(update, TimeStamp(VolInfo.creationDate, 0)); - if (!Showmode) Log("%s (%u) not updated (created %s)\n", VolInfo.name, VolInfo.id, update); + if (!Showmode) + Log("%s (%u) not updated (created %s)\n", VolInfo.name, + VolInfo.id, update); } } - } + } return 0; } -int SalvageVnodes(register struct InodeSummary *rwIsp, - register struct InodeSummary * thisIsp, - register struct ViceInodeInfo * inodes, int check) +int +SalvageVnodes(register struct InodeSummary *rwIsp, + register struct InodeSummary *thisIsp, + register struct ViceInodeInfo *inodes, int check) { int ilarge, ismall, ioffset, RW, nInodes; - ioffset = rwIsp->index+rwIsp->nSpecialInodes; /* first inode */ - if (Showmode) return 0; + ioffset = rwIsp->index + rwIsp->nSpecialInodes; /* first inode */ + if (Showmode) + return 0; RW = (rwIsp == thisIsp); nInodes = (rwIsp->nInodes - rwIsp->nSpecialInodes); - ismall = SalvageIndex(thisIsp->volSummary->header.smallVnodeIndex, - vSmall, RW, &inodes[ioffset], nInodes, thisIsp->volSummary, check); + ismall = + SalvageIndex(thisIsp->volSummary->header.smallVnodeIndex, vSmall, RW, + &inodes[ioffset], nInodes, thisIsp->volSummary, check); if (check && ismall == -1) return -1; - ilarge = SalvageIndex(thisIsp->volSummary->header.largeVnodeIndex, - vLarge, RW, &inodes[ioffset], nInodes, thisIsp->volSummary, check); - return (ilarge==0 && ismall==0 ? 0: -1); + ilarge = + SalvageIndex(thisIsp->volSummary->header.largeVnodeIndex, vLarge, RW, + &inodes[ioffset], nInodes, thisIsp->volSummary, check); + return (ilarge == 0 && ismall == 0 ? 0 : -1); } -int SalvageIndex(Inode ino, VnodeClass class, int RW, - register struct ViceInodeInfo *ip, - int nInodes, struct VolumeSummary *volSummary, int check) +int +SalvageIndex(Inode ino, VnodeClass class, int RW, + register struct ViceInodeInfo *ip, int nInodes, + struct VolumeSummary *volSummary, int check) { VolumeId volumeNumber; char buf[SIZEOF_LARGEDISKVNODE]; - struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; int err = 0; StreamHandle_t *file; struct VnodeClassInfo *vcp; - int size; + afs_sfsize_t size; + afs_fsize_t vnodeLength; int vnodeIndex, nVnodes; afs_ino_str_t stmp1, stmp2; IHandle_t *handle; @@ -2319,25 +2485,22 @@ int SalvageIndex(Inode ino, VnodeClass class, int RW, assert(size != -1); nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { - assert((nVnodes+1) * vcp->diskSize == size); + assert((nVnodes + 1) * vcp->diskSize == size); assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0); - } - else { + } else { nVnodes = 0; } for (vnodeIndex = 0; - nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1; - nVnodes--, vnodeIndex++) { + nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1; + nVnodes--, vnodeIndex++) { if (vnode->type != vNull) { int vnodeChanged = 0; int vnodeNumber = bitNumberToVnodeNumber(vnodeIndex, class); /* Log programs that belong to root (potentially suid root); - don't bother for read-only or backup volumes */ -#ifdef notdef /* This is done elsewhere */ - if (ShowRootFiles && RW && vnode->owner==0 && vnodeNumber != 1) - Log("OWNER IS ROOT %s %u dir %u vnode %u author %u owner %u mode %o\n", - VolInfo.name, volumeNumber, vnode->parent, vnodeNumber, vnode->author, - vnode->owner, vnode->modeBits); + * don't bother for read-only or backup volumes */ +#ifdef notdef /* This is done elsewhere */ + if (ShowRootFiles && RW && vnode->owner == 0 && vnodeNumber != 1) + Log("OWNER IS ROOT %s %u dir %u vnode %u author %u owner %u mode %o\n", VolInfo.name, volumeNumber, vnode->parent, vnodeNumber, vnode->author, vnode->owner, vnode->modeBits); #endif if (VNDISK_GET_INO(vnode) == 0) { if (RW) { @@ -2345,17 +2508,17 @@ int SalvageIndex(Inode ino, VnodeClass class, int RW, memset(vnode, 0, vcp->diskSize); vnodeChanged = 1; } - } - else { + } else { if (vcp->magic != vnode->vnodeMagic) { /* bad magic #, probably partially created vnode */ - Log("Partially allocated vnode %d deleted.\n", vnodeNumber); + Log("Partially allocated vnode %d deleted.\n", + vnodeNumber); memset(vnode, 0, vcp->diskSize); vnodeChanged = 1; goto vnodeDone; } /* ****** Should do a bit more salvage here: e.g. make sure - vnode type matches what it should be given the index */ + * vnode type matches what it should be given the index */ while (nInodes && ip->u.vnode.vnodeNumber < vnodeNumber) { /* if (vnodeIdToClass(ip->u.vnode.vnodeNumber) == class && RW) { * Log("Inode %d: says it belongs to non-existing vnode %d\n", @@ -2368,23 +2531,23 @@ int SalvageIndex(Inode ino, VnodeClass class, int RW, if (!RW) { while (nInodes && ip->u.vnode.vnodeNumber == vnodeNumber) { /* The following doesn't work, because the version number - is not maintained correctly by the file server */ + * is not maintained correctly by the file server */ /*if (vnode->uniquifier == ip->u.vnode.vnodeUniquifier && - vnode->dataVersion == ip->u.vnode.inodeDataVersion) - break;*/ + * vnode->dataVersion == ip->u.vnode.inodeDataVersion) + * break; */ if (VNDISK_GET_INO(vnode) == ip->inodeNumber) break; ip++; nInodes--; } - } - else { + } else { /* For RW volume, look for vnode with matching inode number; - if no such match, take the first determined by our sort - order */ + * if no such match, take the first determined by our sort + * order */ register struct ViceInodeInfo *lip = ip; register lnInodes = nInodes; - while (lnInodes && lip->u.vnode.vnodeNumber == vnodeNumber) { + while (lnInodes + && lip->u.vnode.vnodeNumber == vnodeNumber) { if (VNDISK_GET_INO(vnode) == lip->inodeNumber) { ip = lip; nInodes = lnInodes; @@ -2397,8 +2560,8 @@ int SalvageIndex(Inode ino, VnodeClass class, int RW, if (nInodes && ip->u.vnode.vnodeNumber == vnodeNumber) { /* "Matching" inode */ if (RW) { - Unique vu,iu; - FileVersion vd,id; + Unique vu, iu; + FileVersion vd, id; vu = vnode->uniquifier; iu = ip->u.vnode.vnodeUniquifier; vd = vnode->dataVersion; @@ -2411,45 +2574,52 @@ int SalvageIndex(Inode ino, VnodeClass class, int RW, */ if (IUnique(vu) != IUnique(iu)) { if (!Showmode) { - Log("Vnode %u: vnode.unique, %u, does not match inode unique, %u; fixed, but status will be wrong\n", - vnodeNumber, IUnique(vu), IUnique(iu)); + Log("Vnode %u: vnode.unique, %u, does not match inode unique, %u; fixed, but status will be wrong\n", vnodeNumber, IUnique(vu), IUnique(iu)); } - + vnode->uniquifier = iu; #ifdef AFS_3DISPARES - vnode->dataVersion = (id >= vd ? - /* 90% of 2.1M */ ((id-vd) > 1887437 ? vd:id): - /* 90% of 2.1M */ ((vd-id) > 1887437 ? id:vd)); + vnode->dataVersion = (id >= vd ? + /* 90% of 2.1M */ + ((id - vd) > + 1887437 ? vd : id) : + /* 90% of 2.1M */ + ((vd - id) > + 1887437 ? id : vd)); #else #if defined(AFS_SGI_EXMAG) - vnode->dataVersion = (id >= vd ? - /* 90% of 16M */ ((id-vd) > 15099494 ? vd:id): - /* 90% of 16M */ ((vd-id) > 15099494 ? id:vd)); + vnode->dataVersion = (id >= vd ? + /* 90% of 16M */ + ((id - vd) > + 15099494 ? vd : id) : + /* 90% of 16M */ + ((vd - id) > + 15099494 ? id : vd)); #else - vnode->dataVersion = (id>vd ? id:vd); + vnode->dataVersion = (id > vd ? id : vd); #endif /* AFS_SGI_EXMAG */ -#endif /* AFS_3DISPARES */ +#endif /* AFS_3DISPARES */ vnodeChanged = 1; - } - else { + } else { /* don't bother checking for vd > id any more, since - partial file transfers always result in this state, - and you can't do much else anyway (you've already - found the best data you can) */ + * partial file transfers always result in this state, + * and you can't do much else anyway (you've already + * found the best data you can) */ #ifdef AFS_3DISPARES - if (!vnodeIsDirectory(vnodeNumber) && - ((vd < id && (id-vd) < 1887437) || - ((vd > id && (vd-id) > 1887437)))) { + if (!vnodeIsDirectory(vnodeNumber) + && ((vd < id && (id - vd) < 1887437) + || ((vd > id && (vd - id) > 1887437)))) { #else #if defined(AFS_SGI_EXMAG) - if (!vnodeIsDirectory(vnodeNumber) && - ((vd < id && (id-vd) < 15099494) || - ((vd > id && (vd-id) > 15099494)))) { + if (!vnodeIsDirectory(vnodeNumber) + && ((vd < id && (id - vd) < 15099494) + || ((vd > id && (vd - id) > 15099494)))) { #else if (!vnodeIsDirectory(vnodeNumber) && vd < id) { #endif /* AFS_SGI_EXMAG */ #endif - if (!Showmode) Log("Vnode %d: version < inode version; fixed (old status)\n", vnodeNumber); + if (!Showmode) + Log("Vnode %d: version < inode version; fixed (old status)\n", vnodeNumber); vnode->dataVersion = id; vnodeChanged = 1; } @@ -2458,102 +2628,93 @@ int SalvageIndex(Inode ino, VnodeClass class, int RW, if (ip->inodeNumber != VNDISK_GET_INO(vnode)) { if (check) { if (!Showmode) { - Log("Vnode %d: inode number incorrect (is %s should be %s). FileSize=%d\n", - vnodeNumber, - PrintInode(stmp1, VNDISK_GET_INO(vnode)), - PrintInode(stmp2, ip->inodeNumber), - ip->byteCount); + Log("Vnode %d: inode number incorrect (is %s should be %s). FileSize=%llu\n", vnodeNumber, PrintInode(stmp1, VNDISK_GET_INO(vnode)), PrintInode(stmp2, ip->inodeNumber), (afs_uintmax_t) ip->byteCount); } VNDISK_SET_INO(vnode, ip->inodeNumber); err = -1; goto zooks; } if (!Showmode) { - Log("Vnode %d: inode number incorrect; changed from %s to %s. FileSize=%d\n", - vnodeNumber, - PrintInode(stmp1, VNDISK_GET_INO(vnode)), - PrintInode(stmp2, ip->inodeNumber), - ip->byteCount); + Log("Vnode %d: inode number incorrect; changed from %s to %s. FileSize=%llu\n", vnodeNumber, PrintInode(stmp1, VNDISK_GET_INO(vnode)), PrintInode(stmp2, ip->inodeNumber), (afs_uintmax_t) ip->byteCount); } VNDISK_SET_INO(vnode, ip->inodeNumber); vnodeChanged = 1; } - if (ip->byteCount != vnode->length) { + VNDISK_GET_LEN(vnodeLength, vnode); + if (ip->byteCount != vnodeLength) { if (check) { - if (!Showmode) Log("Vnode %d: length incorrect; (is %d should be %d)\n", - vnodeNumber, vnode->length, ip->byteCount); + if (!Showmode) + Log("Vnode %d: length incorrect; (is %llu should be %llu)\n", vnodeNumber, (afs_uintmax_t) vnodeLength, (afs_uintmax_t) ip->byteCount); err = -1; goto zooks; } - if (!Showmode) Log("Vnode %d: length incorrect; changed from %d to %d\n", - vnodeNumber, vnode->length, ip->byteCount); - vnode->length = ip->byteCount; + if (!Showmode) + Log("Vnode %d: length incorrect; changed from %llu to %llu\n", vnodeNumber, (afs_uintmax_t) vnodeLength, (afs_uintmax_t) ip->byteCount); + VNDISK_SET_LEN(vnode, ip->byteCount); vnodeChanged = 1; } if (!check) - ip->linkCount--; /* Keep the inode around */ + ip->linkCount--; /* Keep the inode around */ ip++; nInodes--; - } - else { /* no matching inode */ - if (VNDISK_GET_INO(vnode) != 0 || vnode->type == vDirectory) { + } else { /* no matching inode */ + if (VNDISK_GET_INO(vnode) != 0 + || vnode->type == vDirectory) { /* No matching inode--get rid of the vnode */ if (check) { if (VNDISK_GET_INO(vnode)) { if (!Showmode) { - Log("Vnode %d (unique %d): corresponding inode %s is missing\n", - vnodeNumber, vnode->uniquifier, - PrintInode(NULL, VNDISK_GET_INO(vnode))); + Log("Vnode %d (unique %u): corresponding inode %s is missing\n", vnodeNumber, vnode->uniquifier, PrintInode(NULL, VNDISK_GET_INO(vnode))); } } else { - if (!Showmode) Log("Vnode %d (unique %d): bad directory vnode (no inode number listed)\n", vnodeNumber, vnode->uniquifier); + if (!Showmode) + Log("Vnode %d (unique %u): bad directory vnode (no inode number listed)\n", vnodeNumber, vnode->uniquifier); } err = -1; goto zooks; } if (VNDISK_GET_INO(vnode)) { if (!Showmode) { - Log("Vnode %d (unique %d): corresponding inode %s is missing; vnode deleted, vnode mod time=%s", - vnodeNumber, vnode->uniquifier, - PrintInode(NULL, VNDISK_GET_INO(vnode)), - ctime((time_t *)&(vnode->serverModifyTime))); + Log("Vnode %d (unique %u): corresponding inode %s is missing; vnode deleted, vnode mod time=%s", vnodeNumber, vnode->uniquifier, PrintInode(NULL, VNDISK_GET_INO(vnode)), ctime((time_t *) & (vnode->serverModifyTime))); } } else { - if (!Showmode) Log("Vnode %d (unique %d): bad directory vnode (no inode number listed); vnode deleted, vnode mod time=%s", vnodeNumber, vnode->uniquifier, ctime((time_t *)&(vnode->serverModifyTime))); + if (!Showmode) + Log("Vnode %d (unique %u): bad directory vnode (no inode number listed); vnode deleted, vnode mod time=%s", vnodeNumber, vnode->uniquifier, ctime((time_t *) & (vnode->serverModifyTime))); } memset(vnode, 0, vcp->diskSize); vnodeChanged = 1; } else { - /* Should not reach here becuase we checked for - * (inodeNumber == 0) above. And where we zero the vnode, - * we also goto vnodeDone. - */ + /* Should not reach here becuase we checked for + * (inodeNumber == 0) above. And where we zero the vnode, + * we also goto vnodeDone. + */ } } while (nInodes && ip->u.vnode.vnodeNumber == vnodeNumber) { ip++; nInodes--; } - } /* VNDISK_GET_INO(vnode) != 0 */ + } /* VNDISK_GET_INO(vnode) != 0 */ vnodeDone: assert(!(vnodeChanged && check)); if (vnodeChanged && !Testing) { - assert(IH_IWRITE(handle, vnodeIndexOffset(vcp,vnodeNumber), - (char*)vnode, vcp->diskSize) - == vcp->diskSize); + assert(IH_IWRITE + (handle, vnodeIndexOffset(vcp, vnodeNumber), + (char *)vnode, vcp->diskSize) + == vcp->diskSize); VolumeChanged = 1; /* For break call back */ } } } -zooks: + zooks: STREAM_CLOSE(file); FDH_CLOSE(fdP); IH_RELEASE(handle); return err; } -struct VnodeEssence *CheckVnodeNumber(vnodeNumber) - VnodeId vnodeNumber; +struct VnodeEssence * +CheckVnodeNumber(VnodeId vnodeNumber) { VnodeClass class; struct VnodeInfo *vip; @@ -2562,11 +2723,11 @@ struct VnodeEssence *CheckVnodeNumber(vnodeNumber) class = vnodeIdToClass(vnodeNumber); vip = &vnodeInfo[class]; offset = vnodeIdToBitNumber(vnodeNumber); - return (offset >= vip->nVnodes? NULL: &vip->vnodes[offset]); + return (offset >= vip->nVnodes ? NULL : &vip->vnodes[offset]); } - -void CopyOnWrite(register struct DirSummary *dir) +void +CopyOnWrite(register struct DirSummary *dir) { /* Copy the directory unconditionally if we are going to change it: * not just if was cloned. @@ -2577,29 +2738,32 @@ void CopyOnWrite(register struct DirSummary *dir) int code; if (dir->copied || Testing) - return; - DFlush(); /* Well justified paranoia... */ + return; + DFlush(); /* Well justified paranoia... */ - code = IH_IREAD(vnodeInfo[vLarge].handle, - vnodeIndexOffset(vcp, dir->vnodeNumber), - (char*)&vnode, sizeof (vnode)); + code = + IH_IREAD(vnodeInfo[vLarge].handle, + vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode, + sizeof(vnode)); assert(code == sizeof(vnode)); oldinode = VNDISK_GET_INO(&vnode); /* Increment the version number by a whole lot to avoid problems with * clients that were promised new version numbers--but the file server * crashed before the versions were written to disk. */ - newinode = IH_CREATE(dir->ds_linkH, fileSysDevice, fileSysPath, 0, - dir->rwVid, dir->vnodeNumber, - vnode.uniquifier, vnode.dataVersion += 200); + newinode = + IH_CREATE(dir->ds_linkH, fileSysDevice, fileSysPath, 0, dir->rwVid, + dir->vnodeNumber, vnode.uniquifier, vnode.dataVersion += + 200); assert(VALID_INO(newinode)); assert(CopyInode(fileSysDevice, oldinode, newinode, dir->rwVid) == 0); vnode.cloned = 0; VNDISK_SET_INO(&vnode, newinode); - code = IH_IWRITE(vnodeInfo[vLarge].handle, - vnodeIndexOffset(vcp, dir->vnodeNumber), - (char*)&vnode, sizeof (vnode)); - assert(code == sizeof (vnode)); + code = + IH_IWRITE(vnodeInfo[vLarge].handle, + vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode, + sizeof(vnode)); + assert(code == sizeof(vnode)); SetSalvageDirHandle(&dir->dirHandle, dir->dirHandle.dirh_handle->ih_vid, fileSysDevice, newinode); @@ -2608,37 +2772,41 @@ void CopyOnWrite(register struct DirSummary *dir) */ dir->copied = 1; } - -/* This function should either successfully create a new dir, or give up and leave - * things the way they were. In particular, if it fails to write the new dir properly, - * it should return w/o changing the reference to the old dir. + +/* + * This function should either successfully create a new dir, or give up + * and leave things the way they were. In particular, if it fails to write + * the new dir properly, it should return w/o changing the reference to the + * old dir. */ -void CopyAndSalvage(register struct DirSummary *dir) +void +CopyAndSalvage(register struct DirSummary *dir) { struct VnodeDiskObject vnode; struct VnodeClassInfo *vcp = &VnodeClassInfo[vLarge]; Inode oldinode, newinode; DirHandle newdir; register afs_int32 code; - afs_int32 parentUnique= 1; + afs_int32 parentUnique = 1; struct VnodeEssence *vnodeEssence; if (Testing) return; Log("Salvaging directory %u...\n", dir->vnodeNumber); - code = IH_IREAD(vnodeInfo[vLarge].handle, - vnodeIndexOffset(vcp, dir->vnodeNumber), - (char*)&vnode, sizeof (vnode)); - assert(code == sizeof (vnode)); + code = + IH_IREAD(vnodeInfo[vLarge].handle, + vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode, + sizeof(vnode)); + assert(code == sizeof(vnode)); oldinode = VNDISK_GET_INO(&vnode); /* Increment the version number by a whole lot to avoid problems with * clients that were promised new version numbers--but the file server * crashed before the versions were written to disk. */ - newinode = IH_CREATE(dir->ds_linkH, fileSysDevice, fileSysPath, 0, - dir->rwVid, dir->vnodeNumber, - vnode.uniquifier, - vnode.dataVersion += 200); + newinode = + IH_CREATE(dir->ds_linkH, fileSysDevice, fileSysPath, 0, dir->rwVid, + dir->vnodeNumber, vnode.uniquifier, vnode.dataVersion += + 200); assert(VALID_INO(newinode)); SetSalvageDirHandle(&newdir, dir->rwVid, fileSysDevice, newinode); @@ -2647,14 +2815,16 @@ void CopyAndSalvage(register struct DirSummary *dir) * The uniquifier for .. might be set to a bogus value of 1 and * the salvager will later clean it up. */ - if ( vnode.parent && (vnodeEssence = CheckVnodeNumber(vnode.parent)) ) { - parentUnique = (vnodeEssence->unique ? vnodeEssence->unique : 1); - } - code = DirSalvage(&dir->dirHandle, &newdir, - dir->vnodeNumber, vnode.uniquifier, - (vnode.parent?vnode.parent:dir->vnodeNumber), - parentUnique); - if (code == 0) code = DFlush(); + if (vnode.parent && (vnodeEssence = CheckVnodeNumber(vnode.parent))) { + parentUnique = (vnodeEssence->unique ? vnodeEssence->unique : 1); + } + code = + DirSalvage(&dir->dirHandle, &newdir, dir->vnodeNumber, + vnode.uniquifier, + (vnode.parent ? vnode.parent : dir->vnodeNumber), + parentUnique); + if (code == 0) + code = DFlush(); if (code) { /* didn't really build the new directory properly, let's just give up. */ code = IH_DEC(dir->ds_linkH, newinode, dir->rwVid); @@ -2671,25 +2841,27 @@ void CopyAndSalvage(register struct DirSummary *dir) } vnode.cloned = 0; VNDISK_SET_INO(&vnode, newinode); - vnode.length = Length(&newdir); - code = IH_IWRITE(vnodeInfo[vLarge].handle, - vnodeIndexOffset(vcp, dir->vnodeNumber), - (char*)&vnode, sizeof (vnode)); - assert(code == sizeof (vnode)); + VNDISK_SET_LEN(&vnode, Length(&newdir)); + code = + IH_IWRITE(vnodeInfo[vLarge].handle, + vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode, + sizeof(vnode)); + assert(code == sizeof(vnode)); #ifdef AFS_NT40_ENV nt_sync(fileSysDevice); #else - sync(); /* this is slow, but hopefully rarely called. We don't have - * an open FD on the file itself to fsync. - */ + sync(); /* this is slow, but hopefully rarely called. We don't have + * an open FD on the file itself to fsync. + */ #endif code = IH_DEC(dir->ds_linkH, oldinode, dir->rwVid); assert(code == 0); dir->dirHandle = newdir; } -void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, - Unique unique) +void +JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, + Unique unique) { struct VnodeEssence *vnodeEssence; afs_int32 dirOrphaned, todelete; @@ -2699,17 +2871,14 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, vnodeEssence = CheckVnodeNumber(vnodeNumber); if (vnodeEssence == NULL) { if (!Showmode) { - Log("dir vnode %d: invalid entry deleted: %s/%s (vnode %d, unique %d)\n", - dir->vnodeNumber, dir->name?dir->name:"??", - name, vnodeNumber, unique); + Log("dir vnode %u: invalid entry deleted: %s/%s (vnode %u, unique %u)\n", dir->vnodeNumber, dir->name ? dir->name : "??", name, vnodeNumber, unique); } if (!Testing) { CopyOnWrite(dir); assert(Delete(&dir->dirHandle, name) == 0); - } + } return; } - #ifdef AFS_AIX_ENV #ifndef AFS_NAMEI_ENV /* On AIX machines, don't allow entries to point to inode 0. That is a special @@ -2717,56 +2886,51 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, * the machine. */ if (vnodeEssence->InodeNumber == 0) { - Log("dir vnode %d: invalid entry: %s/%s has no inode (vnode %d, unique %d)%s\n", - dir->vnodeNumber, (dir->name?dir->name:"??"), - name, vnodeNumber, unique, - (Testing?"-- would have deleted":" -- deleted")); - if (!Testing) { - CopyOnWrite(dir); - assert(Delete(&dir->dirHandle, name) == 0); - } - return; - } -#endif -#endif - - if (!(vnodeNumber & 1) && !Showmode && - !(vnodeEssence->count || vnodeEssence->unique || vnodeEssence->modeBits)) { - Log("dir vnode %d: invalid entry: %s/%s (vnode %d, unique %d)%s\n", - dir->vnodeNumber, (dir->name?dir->name:"??"), - name, vnodeNumber, unique, - ((!unique)?(Testing?"-- would have deleted":" -- deleted"):"")); - if (!unique) { - if (!Testing) { - CopyOnWrite(dir); - assert(Delete(&dir->dirHandle, name) == 0); - } - return; - } + Log("dir vnode %d: invalid entry: %s/%s has no inode (vnode %d, unique %d)%s\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, (Testing ? "-- would have deleted" : " -- deleted")); + if (!Testing) { + CopyOnWrite(dir); + assert(Delete(&dir->dirHandle, name) == 0); + } + return; + } +#endif +#endif + + if (!(vnodeNumber & 1) && !Showmode + && !(vnodeEssence->count || vnodeEssence->unique + || vnodeEssence->modeBits)) { + Log("dir vnode %u: invalid entry: %s/%s (vnode %u, unique %u)%s\n", + dir->vnodeNumber, (dir->name ? dir->name : "??"), name, + vnodeNumber, unique, + ((!unique) ? (Testing ? "-- would have deleted" : " -- deleted") : + "")); + if (!unique) { + if (!Testing) { + CopyOnWrite(dir); + assert(Delete(&dir->dirHandle, name) == 0); + } + return; + } } /* Check if the Uniquifiers match. If not, change the directory entry * so its unique matches the vnode unique. Delete if the unique is zero * or if the directory is orphaned. */ - if (!IUnique(vnodeEssence->unique) || - (IUnique(vnodeEssence->unique) != IUnique(unique)) ) { - if ( !IUnique(vnodeEssence->unique) && - ((strcmp(name,"..")==0) || (strcmp(name,".")==0)) ) { - /* This is an orphaned directory. Don't delete the . or .. - * entry. Otherwise, it will get created in the next - * salvage and deleted again here. So Just skip it. - */ - return; - } - + if (!vnodeEssence->unique || (vnodeEssence->unique) != unique) { + if (!vnodeEssence->unique + && ((strcmp(name, "..") == 0) || (strcmp(name, ".") == 0))) { + /* This is an orphaned directory. Don't delete the . or .. + * entry. Otherwise, it will get created in the next + * salvage and deleted again here. So Just skip it. + */ + return; + } + todelete = ((!vnodeEssence->unique || dirOrphaned) ? 1 : 0); if (!Showmode) { - Log("dir vnode %d: %s/%s (vnode %d): unique changed from %d to %d %s\n", - dir->vnodeNumber, (dir->name ? dir->name : "??"), - name, vnodeNumber, unique, vnodeEssence->unique, - (!todelete?"":(Testing?"-- would have deleted":"-- deleted"))); + Log("dir vnode %u: %s/%s (vnode %u): unique changed from %u to %u %s\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, vnodeEssence->unique, (!todelete ? "" : (Testing ? "-- would have deleted" : "-- deleted"))); } if (!Testing) { ViceFid fid; @@ -2775,16 +2939,17 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, CopyOnWrite(dir); assert(Delete(&dir->dirHandle, name) == 0); if (!todelete) - assert(Create(&dir->dirHandle, name, &fid) == 0); + assert(Create(&dir->dirHandle, name, &fid) == 0); } - if (todelete) return; /* no need to continue */ + if (todelete) + return; /* no need to continue */ } - if (strcmp(name,".") == 0) { - if (dir->vnodeNumber != vnodeNumber || (IUnique(dir->unique) != IUnique(unique))) { + if (strcmp(name, ".") == 0) { + if (dir->vnodeNumber != vnodeNumber || (dir->unique != unique)) { ViceFid fid; - if (!Showmode) Log("directory vnode %d.%d: bad '.' entry (was %d.%d); fixed\n", - dir->vnodeNumber, dir->unique, vnodeNumber, unique); + if (!Showmode) + Log("directory vnode %u.%u: bad '.' entry (was %u.%u); fixed\n", dir->vnodeNumber, dir->unique, vnodeNumber, unique); if (!Testing) { CopyOnWrite(dir); assert(Delete(&dir->dirHandle, ".") == 0); @@ -2793,58 +2958,54 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, assert(Create(&dir->dirHandle, ".", &fid) == 0); } - vnodeNumber = fid.Vnode; /* Get the new Essence */ + vnodeNumber = fid.Vnode; /* Get the new Essence */ unique = fid.Unique; vnodeEssence = CheckVnodeNumber(vnodeNumber); } dir->haveDot = 1; - } - else if (strcmp(name,"..") == 0) { + } else if (strcmp(name, "..") == 0) { ViceFid pa; if (dir->parent) { struct VnodeEssence *dotdot; pa.Vnode = dir->parent; dotdot = CheckVnodeNumber(pa.Vnode); - assert (dotdot != NULL); /* XXX Should not be assert */ + assert(dotdot != NULL); /* XXX Should not be assert */ pa.Unique = dotdot->unique; - } - else { + } else { pa.Vnode = dir->vnodeNumber; pa.Unique = dir->unique; } - if ((pa.Vnode != vnodeNumber) || (IUnique(pa.Unique) != IUnique(unique))) { - if (!Showmode) Log("directory vnode %d.%d: bad '..' entry (was %d.%d); fixed\n", - dir->vnodeNumber, IUnique(dir->unique), vnodeNumber, IUnique(unique)); + if ((pa.Vnode != vnodeNumber) || (pa.Unique != unique)) { + if (!Showmode) + Log("directory vnode %u.%u: bad '..' entry (was %u.%u); fixed\n", dir->vnodeNumber, dir->unique, vnodeNumber, unique); if (!Testing) { CopyOnWrite(dir); assert(Delete(&dir->dirHandle, "..") == 0); assert(Create(&dir->dirHandle, "..", &pa) == 0); } - vnodeNumber = pa.Vnode; /* Get the new Essence */ + vnodeNumber = pa.Vnode; /* Get the new Essence */ unique = pa.Unique; vnodeEssence = CheckVnodeNumber(vnodeNumber); } dir->haveDotDot = 1; - } else if (strncmp(name,".__afs",6) == 0) { - if (!Showmode) { - Log("dir vnode %d: special old unlink-while-referenced file %s %s deleted (vnode %d)\n", - dir->vnodeNumber, name, (Testing?"would have been":"is"), vnodeNumber); + } else if (strncmp(name, ".__afs", 6) == 0) { + if (!Showmode) { + Log("dir vnode %u: special old unlink-while-referenced file %s %s deleted (vnode %u)\n", dir->vnodeNumber, name, (Testing ? "would have been" : "is"), vnodeNumber); } - if (!Testing) { + if (!Testing) { CopyOnWrite(dir); assert(Delete(&dir->dirHandle, name) == 0); } - vnodeEssence->claimed = 0; /* Not claimed: Orphaned */ - vnodeEssence->todelete = 1; /* Will later delete vnode and decr inode */ + vnodeEssence->claimed = 0; /* Not claimed: Orphaned */ + vnodeEssence->todelete = 1; /* Will later delete vnode and decr inode */ return; - } - else { + } else { if (ShowSuid && (vnodeEssence->modeBits & 06000)) - Log("FOUND suid/sgid file: %s/%s (%u.%u %05o) author %u (vnode %u dir %u)\n", dir->name?dir->name:"??", name, - vnodeEssence->owner, vnodeEssence->group, vnodeEssence->modeBits, vnodeEssence->author,vnodeNumber, dir->vnodeNumber); - if (ShowMounts && (vnodeEssence->type == vSymlink) && !(vnodeEssence->modeBits & 0111)) { - int code, size; + Log("FOUND suid/sgid file: %s/%s (%u.%u %05o) author %u (vnode %u dir %u)\n", dir->name ? dir->name : "??", name, vnodeEssence->owner, vnodeEssence->group, vnodeEssence->modeBits, vnodeEssence->author, vnodeNumber, dir->vnodeNumber); + if (ShowMounts && (vnodeEssence->type == vSymlink) + && !(vnodeEssence->modeBits & 0111)) { + int code, size; char buf[1024]; IHandle_t *ihP; FdHandle_t *fdP; @@ -2856,21 +3017,22 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, size = FDH_SIZE(fdP); assert(size != -1); memset(buf, 0, 1024); - if (size > 1024) size = 1024; + if (size > 1024) + size = 1024; code = FDH_READ(fdP, buf, size); assert(code == size); Log("In volume %u (%s) found mountpoint %s/%s to '%s'\n", dir->dirHandle.dirh_handle->ih_vid, dir->vname, - dir->name?dir->name:"??", name, buf); + dir->name ? dir->name : "??", name, buf); FDH_REALLYCLOSE(fdP); IH_RELEASE(ihP); } - if (ShowRootFiles && vnodeEssence->owner==0 && vnodeNumber != 1) - Log("FOUND root file: %s/%s (%u.%u %05o) author %u (vnode %u dir %u)\n", dir->name?dir->name:"??", name, - vnodeEssence->owner, vnodeEssence->group, vnodeEssence->modeBits, vnodeEssence->author, vnodeNumber, dir->vnodeNumber); - if (vnodeIdToClass(vnodeNumber) == vLarge && vnodeEssence->name == (char *)0) { + if (ShowRootFiles && vnodeEssence->owner == 0 && vnodeNumber != 1) + Log("FOUND root file: %s/%s (%u.%u %05o) author %u (vnode %u dir %u)\n", dir->name ? dir->name : "??", name, vnodeEssence->owner, vnodeEssence->group, vnodeEssence->modeBits, vnodeEssence->author, vnodeNumber, dir->vnodeNumber); + if (vnodeIdToClass(vnodeNumber) == vLarge + && vnodeEssence->name == NULL) { char *n; - if (n = (char*)malloc(strlen(name)+1)) + if ((n = (char *)malloc(strlen(name) + 1))) strcpy(n, name); vnodeEssence->name = n; } @@ -2883,40 +3045,33 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, * from different directories. */ if (vnodeEssence->parent != dir->vnodeNumber) { - if (!vnodeEssence->claimed && !dirOrphaned) { - /* Vnode does not point back to this directory. - * Orphaned dirs cannot claim a file (it may belong to - * another non-orphaned dir). - */ - if (!Showmode) { - Log("dir vnode %d: %s/%s (vnode %d, unique %d) -- parent vnode %schanged from %d to %d\n", - dir->vnodeNumber, (dir->name ? dir->name : "??"), name, - vnodeNumber, unique, (Testing?"would have been ":""), - vnodeEssence->parent, dir->vnodeNumber); - } - vnodeEssence->parent = dir->vnodeNumber; - vnodeEssence->changed = 1; - } else { - /* Vnode was claimed by another directory */ - if (!Showmode) { - if (dirOrphaned) { - Log("dir vnode %d: %s/%s parent vnode is %d (vnode %d, unique %d) -- %sdeleted\n", - dir->vnodeNumber, (dir->name ? dir->name : "??"), name, - vnodeEssence->parent, vnodeNumber, unique, - (Testing?"would have been ":"")); - } else { - Log("dir vnode %d: %s/%s already claimed by directory vnode %d (vnode %d, unique %d) -- %sdeleted\n", - dir->vnodeNumber, (dir->name ? dir->name : "??"), name, - vnodeEssence->parent, vnodeNumber, unique, - (Testing?"would have been ":"")); - } - } - if (!Testing) { - CopyOnWrite(dir); - assert(Delete(&dir->dirHandle, name) == 0); - } - return; - } + if (!vnodeEssence->claimed && !dirOrphaned && vnodeNumber != 1) { + /* Vnode does not point back to this directory. + * Orphaned dirs cannot claim a file (it may belong to + * another non-orphaned dir). + */ + if (!Showmode) { + Log("dir vnode %u: %s/%s (vnode %u, unique %u) -- parent vnode %schanged from %u to %u\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, (Testing ? "would have been " : ""), vnodeEssence->parent, dir->vnodeNumber); + } + vnodeEssence->parent = dir->vnodeNumber; + vnodeEssence->changed = 1; + } else { + /* Vnode was claimed by another directory */ + if (!Showmode) { + if (dirOrphaned) { + Log("dir vnode %u: %s/%s parent vnode is %u (vnode %u, unique %u) -- %sdeleted\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeEssence->parent, vnodeNumber, unique, (Testing ? "would have been " : "")); + } else if (vnodeNumber == 1) { + Log("dir vnode %d: %s/%s is invalid (vnode %d, unique %d) -- %sdeleted\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, (Testing?"would have been ":"")); + } else { + Log("dir vnode %u: %s/%s already claimed by directory vnode %u (vnode %u, unique %u) -- %sdeleted\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeEssence->parent, vnodeNumber, unique, (Testing ? "would have been " : "")); + } + } + if (!Testing) { + CopyOnWrite(dir); + assert(Delete(&dir->dirHandle, name) == 0); + } + return; + } } /* This directory claims the vnode */ vnodeEssence->claimed = 1; @@ -2924,13 +3079,13 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, vnodeEssence->count--; } -void DistilVnodeEssence(VolumeId rwVId, VnodeClass class, Inode ino, - Unique *maxu) +void +DistilVnodeEssence(VolumeId rwVId, VnodeClass class, Inode ino, Unique * maxu) { register struct VnodeInfo *vip = &vnodeInfo[class]; struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; char buf[SIZEOF_LARGEDISKVNODE]; - struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; int size; StreamHandle_t *file; int vnodeIndex; @@ -2946,37 +3101,37 @@ void DistilVnodeEssence(VolumeId rwVId, VnodeClass class, Inode ino, assert(size != -1); vip->nVnodes = (size / vcp->diskSize) - 1; if (vip->nVnodes > 0) { - assert((vip->nVnodes+1)*vcp->diskSize == size); + assert((vip->nVnodes + 1) * vcp->diskSize == size); assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0); assert((vip->vnodes = (struct VnodeEssence *) - calloc(vip->nVnodes, sizeof(struct VnodeEssence))) != NULL); + calloc(vip->nVnodes, sizeof(struct VnodeEssence))) != NULL); if (class == vLarge) { assert((vip->inodes = (Inode *) - calloc(vip->nVnodes, sizeof (Inode))) != NULL); - } - else { + calloc(vip->nVnodes, sizeof(Inode))) != NULL); + } else { vip->inodes = NULL; } - } - else { + } else { vip->nVnodes = 0; vip->vnodes = NULL; vip->inodes = NULL; } vip->volumeBlockCount = vip->nAllocatedVnodes = 0; for (vnodeIndex = 0, nVnodes = vip->nVnodes; - nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1; - nVnodes--, vnodeIndex++) { + nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1; + nVnodes--, vnodeIndex++) { if (vnode->type != vNull) { register struct VnodeEssence *vep = &vip->vnodes[vnodeIndex]; + afs_fsize_t vnodeLength; vip->nAllocatedVnodes++; vep->count = vnode->linkCount; - vep->blockCount = nBlocks(vnode->length); + VNDISK_GET_LEN(vnodeLength, vnode); + vep->blockCount = nBlocks(vnodeLength); vip->volumeBlockCount += vep->blockCount; vep->parent = vnode->parent; vep->unique = vnode->uniquifier; if (*maxu < vnode->uniquifier) - *maxu = vnode->uniquifier; + *maxu = vnode->uniquifier; vep->modeBits = vnode->modeBits; vep->InodeNumber = VNDISK_GET_INO(vnode); vep->type = vnode->type; @@ -2985,26 +3140,25 @@ void DistilVnodeEssence(VolumeId rwVId, VnodeClass class, Inode ino, vep->group = vnode->group; if (vnode->type == vDirectory) { assert(class == vLarge); - vip->inodes[vnodeIndex] = VNDISK_GET_INO(vnode); + vip->inodes[vnodeIndex] = VNDISK_GET_INO(vnode); } } - } + } STREAM_CLOSE(file); FDH_CLOSE(fdP); } -static char *GetDirName(vnode, vp, path) - VnodeId vnode; - struct VnodeEssence *vp; - char *path; +static char * +GetDirName(VnodeId vnode, struct VnodeEssence *vp, char *path) { struct VnodeEssence *parentvp; - + if (vnode == 1) { strcpy(path, "."); return path; } - if (vp->parent && vp->name && (parentvp = CheckVnodeNumber(vp->parent)) && GetDirName(vp->parent, parentvp, path)) { + if (vp->parent && vp->name && (parentvp = CheckVnodeNumber(vp->parent)) + && GetDirName(vp->parent, parentvp, path)) { strcat(path, "/"); strcat(path, vp->name); return path; @@ -3015,22 +3169,26 @@ static char *GetDirName(vnode, vp, path) /* To determine if a vnode is orhpaned or not, the vnode and all its parent * vnodes must be "claimed". The vep->claimed flag is set in JudgeEntry(). */ -static int IsVnodeOrphaned(vnode) - VnodeId vnode; +static int +IsVnodeOrphaned(VnodeId vnode) { struct VnodeEssence *vep; - - if (vnode == 0) return(1); /* Vnode zero does not exist */ - if (vnode == 1) return(0); /* The root dir vnode is always claimed */ - vep = CheckVnodeNumber(vnode); /* Get the vnode essence */ - if (!vep || !vep->claimed) return(1); /* Vnode is not claimed - it is orphaned */ - - return( IsVnodeOrphaned(vep->parent) ); + + if (vnode == 0) + return (1); /* Vnode zero does not exist */ + if (vnode == 1) + return (0); /* The root dir vnode is always claimed */ + vep = CheckVnodeNumber(vnode); /* Get the vnode essence */ + if (!vep || !vep->claimed) + return (1); /* Vnode is not claimed - it is orphaned */ + + return (IsVnodeOrphaned(vep->parent)); } -void SalvageDir(char *name, VolumeId rwVid, struct VnodeInfo *dirVnodeInfo, - IHandle_t *alinkH, int i, struct DirSummary *rootdir, - int *rootdirfound) +void +SalvageDir(char *name, VolumeId rwVid, struct VnodeInfo *dirVnodeInfo, + IHandle_t * alinkH, int i, struct DirSummary *rootdir, + int *rootdirfound) { static struct DirSummary dir; static struct DirHandle dirHandle; @@ -3039,19 +3197,29 @@ void SalvageDir(char *name, VolumeId rwVid, struct VnodeInfo *dirVnodeInfo, int dirok, code; if (dirVnodeInfo->vnodes[i].salvaged) - return; /* already salvaged */ + return; /* already salvaged */ dir.rwVid = rwVid; dirVnodeInfo->vnodes[i].salvaged = 1; - + if (dirVnodeInfo->inodes[i] == 0) - return; /* Not allocated to a directory */ + return; /* Not allocated to a directory */ + + if (bitNumberToVnodeNumber(i, vLarge) == 1) { + if (dirVnodeInfo->vnodes[i].parent) { + Log("Bad parent, vnode 1; %s...\n", + (Testing ? "skipping" : "salvaging")); + dirVnodeInfo->vnodes[i].parent = 0; + dirVnodeInfo->vnodes[i].changed = 1; + } + } else { + parent = CheckVnodeNumber(dirVnodeInfo->vnodes[i].parent); + if (parent && parent->salvaged == 0) + SalvageDir(name, rwVid, dirVnodeInfo, alinkH, + vnodeIdToBitNumber(dirVnodeInfo->vnodes[i].parent), + rootdir, rootdirfound); + } - parent = CheckVnodeNumber(dirVnodeInfo->vnodes[i].parent); - if (parent && parent->salvaged == 0) - SalvageDir(name, rwVid, dirVnodeInfo, alinkH, - vnodeIdToBitNumber(dirVnodeInfo->vnodes[i].parent), - rootdir, rootdirfound); dir.vnodeNumber = bitNumberToVnodeNumber(i, vLarge); dir.unique = dirVnodeInfo->vnodes[i].unique; dir.copied = 0; @@ -3059,30 +3227,33 @@ void SalvageDir(char *name, VolumeId rwVid, struct VnodeInfo *dirVnodeInfo, dir.parent = dirVnodeInfo->vnodes[i].parent; dir.haveDot = dir.haveDotDot = 0; dir.ds_linkH = alinkH; - SetSalvageDirHandle(&dir.dirHandle, dir.rwVid, fileSysDevice, dirVnodeInfo->inodes[i]); + SetSalvageDirHandle(&dir.dirHandle, dir.rwVid, fileSysDevice, + dirVnodeInfo->inodes[i]); dirok = ((RebuildDirs && !Testing) ? 0 : DirOK(&dir.dirHandle)); if (!dirok) { if (!RebuildDirs) { - Log("Directory bad, vnode %d; %s...\n", - dir.vnodeNumber, (Testing ? "skipping" : "salvaging")); + Log("Directory bad, vnode %u; %s...\n", dir.vnodeNumber, + (Testing ? "skipping" : "salvaging")); } if (!Testing) { - CopyAndSalvage(&dir); - dirok = 1; + CopyAndSalvage(&dir); + dirok = 1; } } dirHandle = dir.dirHandle; - dir.name = GetDirName(bitNumberToVnodeNumber(i,vLarge), &dirVnodeInfo->vnodes[i], path); - + dir.name = + GetDirName(bitNumberToVnodeNumber(i, vLarge), + &dirVnodeInfo->vnodes[i], path); + if (dirok) { - /* If enumeration failed for random reasons, we will probably delete - * too much stuff, so we guard against this instead. - */ - assert(EnumerateDir(&dirHandle, JudgeEntry, &dir) == 0); + /* If enumeration failed for random reasons, we will probably delete + * too much stuff, so we guard against this instead. + */ + assert(EnumerateDir(&dirHandle, JudgeEntry, &dir) == 0); } - + /* Delete the old directory if it was copied in order to salvage. * CopyOnWrite has written the new inode # to the disk, but we still * have the old one in our local structure here. Thus, we idec the @@ -3104,7 +3275,8 @@ void SalvageDir(char *name, VolumeId rwVid, struct VnodeInfo *dirVnodeInfo, return; } -int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t *alinkH) +int +SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t * alinkH) { /* This routine, for now, will only be called for read-write volumes */ int i, j, code; @@ -3116,36 +3288,34 @@ int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t *alinkH) VolumeDiskData volHeader; VolumeId vid; int orphaned, rootdirfound = 0; - Unique maxunique = 0; /* the maxUniquifier from the vnodes */ - afs_int32 ofiles=0, oblocks=0; /* Number of orphaned files/blocks */ + Unique maxunique = 0; /* the maxUniquifier from the vnodes */ + afs_int32 ofiles = 0, oblocks = 0; /* Number of orphaned files/blocks */ struct VnodeEssence *vep; afs_int32 v, pv; IHandle_t *h; int nBytes; - ViceFid pa; + ViceFid pa; VnodeId LFVnode, ThisVnode; - Unique LFUnique, ThisUnique; + Unique LFUnique, ThisUnique; char npath[128]; vid = rwIsp->volSummary->header.id; IH_INIT(h, fileSysDevice, vid, rwIsp->volSummary->header.volumeInfo); - nBytes = IH_IREAD(h, 0, (char*)&volHeader, sizeof(volHeader)); + nBytes = IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader)); assert(nBytes == sizeof(volHeader)); assert(volHeader.stamp.magic == VOLUMEINFOMAGIC); - assert (volHeader.destroyMe != DESTROY_ME); + assert(volHeader.destroyMe != DESTROY_ME); /* (should not have gotten this far with DESTROY_ME flag still set!) */ - DistilVnodeEssence(vid, vLarge, - rwIsp->volSummary->header.largeVnodeIndex, + DistilVnodeEssence(vid, vLarge, rwIsp->volSummary->header.largeVnodeIndex, &maxunique); - DistilVnodeEssence(vid, vSmall, - rwIsp->volSummary->header.smallVnodeIndex, + DistilVnodeEssence(vid, vSmall, rwIsp->volSummary->header.smallVnodeIndex, &maxunique); dirVnodeInfo = &vnodeInfo[vLarge]; for (i = 0; i < dirVnodeInfo->nVnodes; i++) { - SalvageDir(volHeader.name, vid, dirVnodeInfo, alinkH, i, - &rootdir, &rootdirfound); + SalvageDir(volHeader.name, vid, dirVnodeInfo, alinkH, i, &rootdir, + &rootdirfound); } if (Showmode) { IH_RELEASE(h); @@ -3156,137 +3326,144 @@ int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t *alinkH) * connect them to the tree as orphaned (if requested). */ oldrootdir = rootdir; - for (class=0; class < nVNODECLASSES; class++) { - for (v=0; v < vnodeInfo[class].nVnodes; v++) { - vep = &(vnodeInfo[class].vnodes[v]); - ThisVnode = bitNumberToVnodeNumber(v, class); - ThisUnique = vep->unique; - - if ((vep->type == 0) || vep->claimed || ThisVnode == 1) - continue; /* Ignore unused, claimed, and root vnodes */ - - /* This vnode is orphaned. If it is a directory vnode, then the '..' - * entry in this vnode had incremented the parent link count (In - * JudgeEntry()). We need to go to the parent and decrement that - * link count. But if the parent's unique is zero, then the parent - * link count was not incremented in JudgeEntry(). - */ - if (class == vLarge) { /* directory vnode */ - pv = vnodeIdToBitNumber(vep->parent); - if (IUnique(vnodeInfo[vLarge].vnodes[pv].unique) != 0) - vnodeInfo[vLarge].vnodes[pv].count++; - } - - if (!rootdirfound) - continue; /* If no rootdir, can't attach orphaned files */ - - /* Here we attach orphaned files and directories into the - * root directory, LVVnode, making sure link counts stay correct. - */ - if ((orphans == ORPH_ATTACH) && !vep->todelete && !Testing) { - LFVnode = rootdir.vnodeNumber; /* Lost+Found vnode number */ - LFUnique = rootdir.unique; /* Lost+Found uniquifier */ - - /* Update this orphaned vnode's info. Its parent info and - * link count (do for orphaned directories and files). - */ - vep->parent = LFVnode; /* Parent is the root dir */ - vep->unique = LFUnique; - vep->changed = 1; - vep->claimed = 1; - vep->count--; /* Inc link count (root dir will pt to it) */ - - /* If this orphaned vnode is a directory, change '..'. - * The name of the orphaned dir/file is unknown, so we - * build a unique name. No need to CopyOnWrite the directory - * since it is not connected to tree in BK or RO volume and - * won't be visible there. - */ - if (class == vLarge) { - ViceFid pa; - DirHandle dh; - - /* Remove and recreate the ".." entry in this orphaned directory */ - SetSalvageDirHandle(&dh,vid,fileSysDevice,vnodeInfo[class].inodes[v]); - pa.Vnode = LFVnode; - pa.Unique = LFUnique; - assert(Delete(&dh, "..") == 0); - assert(Create(&dh, "..", &pa) == 0); - - /* The original parent's link count was decremented above. - * Here we increment the new parent's link count. + for (class = 0; class < nVNODECLASSES; class++) { + for (v = 0; v < vnodeInfo[class].nVnodes; v++) { + vep = &(vnodeInfo[class].vnodes[v]); + ThisVnode = bitNumberToVnodeNumber(v, class); + ThisUnique = vep->unique; + + if ((vep->type == 0) || vep->claimed || ThisVnode == 1) + continue; /* Ignore unused, claimed, and root vnodes */ + + /* This vnode is orphaned. If it is a directory vnode, then the '..' + * entry in this vnode had incremented the parent link count (In + * JudgeEntry()). We need to go to the parent and decrement that + * link count. But if the parent's unique is zero, then the parent + * link count was not incremented in JudgeEntry(). + */ + if (class == vLarge) { /* directory vnode */ + pv = vnodeIdToBitNumber(vep->parent); + if (vnodeInfo[vLarge].vnodes[pv].unique != 0) + vnodeInfo[vLarge].vnodes[pv].count++; + } + + if (!rootdirfound) + continue; /* If no rootdir, can't attach orphaned files */ + + /* Here we attach orphaned files and directories into the + * root directory, LVVnode, making sure link counts stay correct. + */ + if ((orphans == ORPH_ATTACH) && !vep->todelete && !Testing) { + LFVnode = rootdir.vnodeNumber; /* Lost+Found vnode number */ + LFUnique = rootdir.unique; /* Lost+Found uniquifier */ + + /* Update this orphaned vnode's info. Its parent info and + * link count (do for orphaned directories and files). + */ + vep->parent = LFVnode; /* Parent is the root dir */ + vep->unique = LFUnique; + vep->changed = 1; + vep->claimed = 1; + vep->count--; /* Inc link count (root dir will pt to it) */ + + /* If this orphaned vnode is a directory, change '..'. + * The name of the orphaned dir/file is unknown, so we + * build a unique name. No need to CopyOnWrite the directory + * since it is not connected to tree in BK or RO volume and + * won't be visible there. */ - pv = vnodeIdToBitNumber(LFVnode); - vnodeInfo[vLarge].vnodes[pv].count--; - - } - - /* Go to the root dir and add this entry. The link count of the - * root dir was incremented when ".." was created. Try 10 times. - */ - for (j=0; j<10; j++) { - pa.Vnode = ThisVnode; - pa.Unique = ThisUnique; - - sprintf(npath, "%s.%d.%d", - ((class == vLarge)?"__ORPHANDIR__":"__ORPHANFILE__"), - ThisVnode, ThisUnique); - - CopyOnWrite(&rootdir); - code = Create(&rootdir.dirHandle, npath, &pa); - if (!code) break; - - ThisUnique += 50; /* Try creating a different file */ - } - assert(code == 0); - Log("Attaching orphaned %s to volume's root dir as %s\n", - ((class == vLarge)?"directory":"file"), npath); - } - } /* for each vnode in the class */ - } /* for each class of vnode */ + if (class == vLarge) { + ViceFid pa; + DirHandle dh; + + /* Remove and recreate the ".." entry in this orphaned directory */ + SetSalvageDirHandle(&dh, vid, fileSysDevice, + vnodeInfo[class].inodes[v]); + pa.Vnode = LFVnode; + pa.Unique = LFUnique; + assert(Delete(&dh, "..") == 0); + assert(Create(&dh, "..", &pa) == 0); + + /* The original parent's link count was decremented above. + * Here we increment the new parent's link count. + */ + pv = vnodeIdToBitNumber(LFVnode); + vnodeInfo[vLarge].vnodes[pv].count--; + + } + + /* Go to the root dir and add this entry. The link count of the + * root dir was incremented when ".." was created. Try 10 times. + */ + for (j = 0; j < 10; j++) { + pa.Vnode = ThisVnode; + pa.Unique = ThisUnique; + + (void)afs_snprintf(npath, sizeof npath, "%s.%u.%u", + ((class == + vLarge) ? "__ORPHANDIR__" : + "__ORPHANFILE__"), ThisVnode, + ThisUnique); + + CopyOnWrite(&rootdir); + code = Create(&rootdir.dirHandle, npath, &pa); + if (!code) + break; + + ThisUnique += 50; /* Try creating a different file */ + } + assert(code == 0); + Log("Attaching orphaned %s to volume's root dir as %s\n", + ((class == vLarge) ? "directory" : "file"), npath); + } + } /* for each vnode in the class */ + } /* for each class of vnode */ /* Delete the old rootinode directory if the rootdir was CopyOnWrite */ DFlush(); if (!oldrootdir.copied && rootdir.copied) { - code = IH_DEC(oldrootdir.ds_linkH, oldrootdir.dirHandle.dirh_inode, oldrootdir.rwVid); - assert(code == 0); - /* dirVnodeInfo->inodes[?] is not updated with new inode number */ + code = + IH_DEC(oldrootdir.ds_linkH, oldrootdir.dirHandle.dirh_inode, + oldrootdir.rwVid); + assert(code == 0); + /* dirVnodeInfo->inodes[?] is not updated with new inode number */ } - DFlush(); /* Flush the changes */ + DFlush(); /* Flush the changes */ if (!rootdirfound && (orphans == ORPH_ATTACH)) { - Log("Cannot attach orphaned files and directories: Root directory not found\n"); - orphans = ORPH_IGNORE; + Log("Cannot attach orphaned files and directories: Root directory not found\n"); + orphans = ORPH_IGNORE; } /* Write out all changed vnodes. Orphaned files and directories * will get removed here also (if requested). */ - for (class = 0; class < nVNODECLASSES; class++){ + for (class = 0; class < nVNODECLASSES; class++) { int nVnodes = vnodeInfo[class].nVnodes; struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; struct VnodeEssence *vnodes = vnodeInfo[class].vnodes; FilesInVolume += vnodeInfo[class].nAllocatedVnodes; BlocksInVolume += vnodeInfo[class].volumeBlockCount; - for (i = 0; itype != 0) && (orphaned=IsVnodeOrphaned(vnodeNumber))) { - vnp->claimed = 0; /* Makes IsVnodeOrphaned calls faster */ - vnp->changed = 1; + if ((vnp->type != 0) && (orphaned = IsVnodeOrphaned(vnodeNumber))) { + vnp->claimed = 0; /* Makes IsVnodeOrphaned calls faster */ + vnp->changed = 1; } if (vnp->changed || vnp->count) { int oldCount; int code; - nBytes = IH_IREAD(vnodeInfo[class].handle, - vnodeIndexOffset(vcp, vnodeNumber), - (char*)&vnode, sizeof (vnode)); + nBytes = + IH_IREAD(vnodeInfo[class].handle, + vnodeIndexOffset(vcp, vnodeNumber), + (char *)&vnode, sizeof(vnode)); assert(nBytes == sizeof(vnode)); vnode.parent = vnp->parent; @@ -3294,54 +3471,59 @@ int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t *alinkH) vnode.linkCount = vnode.linkCount - vnp->count; if (orphaned == -1) - orphaned = IsVnodeOrphaned(vnodeNumber); + orphaned = IsVnodeOrphaned(vnodeNumber); if (orphaned) { if (!vnp->todelete) { - /* Orphans should have already been attached (if requested) */ - assert(orphans != ORPH_ATTACH); - oblocks += vnp->blockCount; - ofiles++; + /* Orphans should have already been attached (if requested) */ + assert(orphans != ORPH_ATTACH); + oblocks += vnp->blockCount; + ofiles++; } - if (((orphans == ORPH_REMOVE) || vnp->todelete) && !Testing) { - BlocksInVolume -= vnp->blockCount; - FilesInVolume--; - if (VNDISK_GET_INO(&vnode)) { - code = IH_DEC(alinkH, VNDISK_GET_INO(&vnode), vid); - assert(code == 0); - } - memset(&vnode, 0, sizeof(vnode)); + if (((orphans == ORPH_REMOVE) || vnp->todelete) + && !Testing) { + BlocksInVolume -= vnp->blockCount; + FilesInVolume--; + if (VNDISK_GET_INO(&vnode)) { + code = + IH_DEC(alinkH, VNDISK_GET_INO(&vnode), vid); + assert(code == 0); + } + memset(&vnode, 0, sizeof(vnode)); } } else if (vnp->count) { if (!Showmode) { - Log("Vnode %d: link count incorrect (was %d, %s %d)\n", - vnodeNumber, oldCount, - (Testing?"would have changed to":"now"), vnode.linkCount); + Log("Vnode %u: link count incorrect (was %d, %s %d)\n", vnodeNumber, oldCount, (Testing ? "would have changed to" : "now"), vnode.linkCount); } } vnode.dataVersion++; if (!Testing) { - nBytes = IH_IWRITE(vnodeInfo[class].handle, - vnodeIndexOffset(vcp, vnodeNumber), - (char*)&vnode, sizeof (vnode)); + nBytes = + IH_IWRITE(vnodeInfo[class].handle, + vnodeIndexOffset(vcp, vnodeNumber), + (char *)&vnode, sizeof(vnode)); assert(nBytes == sizeof(vnode)); - } + } VolumeChanged = 1; } } } if (!Showmode && ofiles) { - Log("%s %d orphaned files and directories (approx. %u KB)\n", - (!Testing && (orphans == ORPH_REMOVE))?"Removed":"Found", - ofiles, oblocks); + Log("%s %d orphaned files and directories (approx. %u KB)\n", + (!Testing + && (orphans == ORPH_REMOVE)) ? "Removed" : "Found", ofiles, + oblocks); } for (class = 0; class < nVNODECLASSES; class++) { - register struct VnodeInfo *vip = &vnodeInfo[class]; - for (i=0; inVnodes; i++) - if (vip->vnodes[i].name) free(vip->vnodes[i].name); - if (vip->vnodes) free(vip->vnodes); - if (vip->inodes) free(vip->inodes); + register struct VnodeInfo *vip = &vnodeInfo[class]; + for (i = 0; i < vip->nVnodes; i++) + if (vip->vnodes[i].name) + free(vip->vnodes[i].name); + if (vip->vnodes) + free(vip->vnodes); + if (vip->inodes) + free(vip->inodes); } /* Set correct resource utilization statistics */ @@ -3350,7 +3532,8 @@ int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t *alinkH) /* Make sure the uniquifer is big enough: maxunique is the real maxUniquifier */ if (volHeader.uniquifier < (maxunique + 1)) { - if (!Showmode) Log("Volume uniquifier is too low; fixed\n"); + if (!Showmode) + Log("Volume uniquifier is too low; fixed\n"); /* Plus 2,000 in case there are workstations out there with * cached vnodes that have since been deleted */ @@ -3358,35 +3541,36 @@ int SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t *alinkH) } /* Turn off the inUse bit; the volume's been salvaged! */ - volHeader.inUse = 0; /* clear flag indicating inUse@last crash */ + volHeader.inUse = 0; /* clear flag indicating inUse@last crash */ volHeader.needsSalvaged = 0; /* clear 'damaged' flag */ - volHeader.inService = 1; /* allow service again */ - volHeader.needsCallback = (VolumeChanged != 0); + volHeader.inService = 1; /* allow service again */ + volHeader.needsCallback = (VolumeChanged != 0); volHeader.dontSalvage = DONT_SALVAGE; VolumeChanged = 0; if (!Testing) { - nBytes = IH_IWRITE(h, 0, (char*)&volHeader, sizeof(volHeader)); + nBytes = IH_IWRITE(h, 0, (char *)&volHeader, sizeof(volHeader)); assert(nBytes == sizeof(volHeader)); } if (!Showmode) { - Log("%sSalvaged %s (%u): %d files, %d blocks\n", - (Testing?"It would have ":""), volHeader.name, - volHeader.id, FilesInVolume, BlocksInVolume); - } + Log("%sSalvaged %s (%u): %d files, %d blocks\n", + (Testing ? "It would have " : ""), volHeader.name, volHeader.id, + FilesInVolume, BlocksInVolume); + } IH_RELEASE(vnodeInfo[vSmall].handle); IH_RELEASE(vnodeInfo[vLarge].handle); IH_RELEASE(h); return 0; } -void ClearROInUseBit(struct VolumeSummary *summary) +void +ClearROInUseBit(struct VolumeSummary *summary) { IHandle_t *h = summary->volumeInfoHandle; int nBytes; VolumeDiskData volHeader; - - nBytes = IH_IREAD(h, 0, (char*)&volHeader, sizeof(volHeader)); + + nBytes = IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader)); assert(nBytes == sizeof(volHeader)); assert(volHeader.stamp.magic == VOLUMEINFOMAGIC); volHeader.inUse = 0; @@ -3394,7 +3578,7 @@ void ClearROInUseBit(struct VolumeSummary *summary) volHeader.inService = 1; volHeader.dontSalvage = DONT_SALVAGE; if (!Testing) { - nBytes = IH_IREAD(h, 0, (char*)&volHeader, sizeof(volHeader)); + nBytes = IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader)); assert(nBytes == sizeof(volHeader)); } } @@ -3404,49 +3588,53 @@ void ClearROInUseBit(struct VolumeSummary *summary) * * deleteMe - Always do so, only a partial volume. */ -void MaybeZapVolume(register struct InodeSummary *isp, char *message, - int deleteMe, - int check) +void +MaybeZapVolume(register struct InodeSummary *isp, char *message, int deleteMe, + int check) { if (readOnly(isp) || deleteMe) { if (isp->volSummary && isp->volSummary->fileName) { if (deleteMe) { - if (!Showmode) Log("Volume %u (is only a partial volume--probably an attempt was made to move/restore it when a machine crash occured.\n", isp->volumeId); - if (!Showmode) Log("It will be deleted on this server (you may find it elsewhere)\n"); + if (!Showmode) + Log("Volume %u (is only a partial volume--probably an attempt was made to move/restore it when a machine crash occured.\n", isp->volumeId); + if (!Showmode) + Log("It will be deleted on this server (you may find it elsewhere)\n"); } else { - if (!Showmode) Log("Volume %u needs to be salvaged. Since it is read-only, however,\n",isp->volumeId); - if (!Showmode) Log("it will be deleted instead. It should be recloned.\n"); + if (!Showmode) + Log("Volume %u needs to be salvaged. Since it is read-only, however,\n", isp->volumeId); + if (!Showmode) + Log("it will be deleted instead. It should be recloned.\n"); } if (!Testing) unlink(isp->volSummary->fileName); } - } - else if (!check) { - Log("%s salvage was unsuccessful: read-write volume %u\n", - message, isp->volumeId); - Abort("Salvage of volume %u aborted\n", + } else if (!check) { + Log("%s salvage was unsuccessful: read-write volume %u\n", message, isp->volumeId); + Abort("Salvage of volume %u aborted\n", isp->volumeId); } } -void AskOffline(VolumeId volumeId) +void +AskOffline(VolumeId volumeId) { - if (FSYNC_askfs(volumeId, (char *)0, FSYNC_OFF, FSYNC_SALVAGE) == FSYNC_DENIED) { + if (FSYNC_askfs(volumeId, NULL, FSYNC_OFF, FSYNC_SALVAGE) == FSYNC_DENIED) { Log("AskOffline: file server denied offline request; a general salvage is required.\n"); - Abort("Salvage aborted\n"); + Abort("Salvage aborted\n"); } } -void AskOnline(VolumeId volumeId, char *partition) +void +AskOnline(VolumeId volumeId, char *partition) { if (FSYNC_askfs(volumeId, partition, FSYNC_ON, 0) == FSYNC_DENIED) { - Log("AskOnline: file server denied online request to volume %u partition %s\n", - volumeId, partition); + Log("AskOnline: file server denied online request to volume %u partition %s\n", volumeId, partition); } } -int CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume) +int +CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume) { /* Volume parameter is passed in case iopen is upgraded in future to * require a volume Id to be passed @@ -3464,62 +3652,66 @@ int CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume) assert(n != -1); while ((n = FDH_READ(srcFdP, buf, sizeof(buf))) > 0) assert(FDH_WRITE(destFdP, buf, n) == n); - assert (n == 0); + assert(n == 0); FDH_REALLYCLOSE(srcFdP); FDH_REALLYCLOSE(destFdP); - IH_RELEASE(srcH); + IH_RELEASE(srcH); IH_RELEASE(destH); return 0; } -void PrintInodeList(void) +void +PrintInodeList(void) { register struct ViceInodeInfo *ip; struct ViceInodeInfo *buf; - struct stat status; + struct afs_stat status; register nInodes; - assert(fstat(inodeFd, &status) == 0); - buf = (struct ViceInodeInfo *) malloc(status.st_size); + assert(afs_fstat(inodeFd, &status) == 0); + buf = (struct ViceInodeInfo *)malloc(status.st_size); assert(buf != NULL); nInodes = status.st_size / sizeof(struct ViceInodeInfo); assert(read(inodeFd, buf, status.st_size) == status.st_size); - for(ip = buf; nInodes--; ip++) { - Log("Inode:%s, linkCount=%d, size=%u, p=(%u,%u,%u,%u)\n", - PrintInode(NULL, ip->inodeNumber), ip->linkCount, ip->byteCount, - ip->u.param[0], ip->u.param[1], ip->u.param[2], ip->u.param[3]); + for (ip = buf; nInodes--; ip++) { + Log("Inode:%s, linkCount=%d, size=%#llx, p=(%u,%u,%u,%u)\n", + PrintInode(NULL, ip->inodeNumber), ip->linkCount, + (afs_uintmax_t) ip->byteCount, ip->u.param[0], ip->u.param[1], + ip->u.param[2], ip->u.param[3]); } free(buf); } -void PrintInodeSummary(void) +void +PrintInodeSummary(void) { - int i; - struct InodeSummary *isp; - - for (i=0; ivolumeId, isp->RWvolumeId, isp->index, isp->nInodes, - isp->nSpecialInodes, isp->maxUniquifier); - } + int i; + struct InodeSummary *isp; + + for (i = 0; i < nVolumesInInodeFile; i++) { + isp = &inodeSummary[i]; + Log("VID:%u, RW:%u, index:%d, nInodes:%d, nSpecialInodes:%d, maxUniquifier:%u, volSummary\n", isp->volumeId, isp->RWvolumeId, isp->index, isp->nInodes, isp->nSpecialInodes, isp->maxUniquifier); + } } -void PrintVolumeSummary(void) +void +PrintVolumeSummary(void) { - int i; - struct VolumeSummary *vsp; + int i; + struct VolumeSummary *vsp; - for (i=0, vsp=volumeSummaryp; ifileName); - } + for (i = 0, vsp = volumeSummaryp; i < nVolumes; vsp++, i++) { + Log("fileName:%s, header, wouldNeedCallback\n", vsp->fileName); + } } -int Fork(void) { +int +Fork(void) +{ int f; #ifdef AFS_NT40_ENV f = 0; - assert(0); /* Fork is never executed in the NT code path */ + assert(0); /* Fork is never executed in the NT code path */ #else f = fork(); assert(f >= 0); @@ -3527,13 +3719,15 @@ int Fork(void) { return f; } -void Exit(code) - int code; +void +Exit(code) + int code; { - if (ShowLog) showlog(); + if (ShowLog) + showlog(); #ifdef AFS_NT40_ENV if (main_thread != pthread_self()) - pthread_exit((void*)code); + pthread_exit((void *)code); else exit(code); #else @@ -3541,7 +3735,8 @@ void Exit(code) #endif } -int Wait(char *prog) +int +Wait(char *prog) { int status; int pid; @@ -3554,40 +3749,41 @@ int Wait(char *prog) return pid; } -static char *TimeStamp(time_t clock, int precision) +static char * +TimeStamp(time_t clock, int precision) { struct tm *lt; static char timestamp[20]; lt = localtime(&clock); if (precision) - strftime (timestamp, 20, "%m/%d/%Y %T", lt); + (void)strftime(timestamp, 20, "%m/%d/%Y %T", lt); else - strftime (timestamp, 20, "%m/%d/%Y %H:%M", lt); + (void)strftime(timestamp, 20, "%m/%d/%Y %H:%M", lt); return timestamp; } -void CheckLogFile(void) +void +CheckLogFile(void) { - char oldSlvgLog[AFSDIR_PATH_MAX]; + char oldSlvgLog[AFSDIR_PATH_MAX]; #ifndef AFS_NT40_ENV - if ( useSyslog ) { - ShowLog = 0; - return; - } + if (useSyslog) { + ShowLog = 0; + return; + } #endif - strcpy(oldSlvgLog, AFSDIR_SERVER_SLVGLOG_FILEPATH); - strcat(oldSlvgLog, ".old"); + strcpy(oldSlvgLog, AFSDIR_SERVER_SLVGLOG_FILEPATH); + strcat(oldSlvgLog, ".old"); if (!logFile) { renamefile(AFSDIR_SERVER_SLVGLOG_FILEPATH, oldSlvgLog); - logFile = fopen(AFSDIR_SERVER_SLVGLOG_FILEPATH, "a"); + logFile = afs_fopen(AFSDIR_SERVER_SLVGLOG_FILEPATH, "a"); - if (!logFile) { /* still nothing, use stdout */ + if (!logFile) { /* still nothing, use stdout */ logFile = stdout; ShowLog = 0; } - #ifndef AFS_NAMEI_ENV AFS_DEBUG_IOPS_LOG(logFile); #endif @@ -3595,120 +3791,136 @@ void CheckLogFile(void) } #ifndef AFS_NT40_ENV -void TimeStampLogFile(void) +void +TimeStampLogFile(void) { - char stampSlvgLog[AFSDIR_PATH_MAX]; - struct tm *lt; - time_t now; - - now = time(0); - lt = localtime(&now); - sprintf(stampSlvgLog, "%s.%04d-%02d-%02d.%02d:%02d:%02d", - AFSDIR_SERVER_SLVGLOG_FILEPATH, - lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, - lt->tm_hour, lt->tm_min, lt->tm_sec); - - /* try to link the logfile to a timestamped filename */ - /* if it fails, oh well, nothing we can do */ - link(AFSDIR_SERVER_SLVGLOG_FILEPATH, stampSlvgLog); + char stampSlvgLog[AFSDIR_PATH_MAX]; + struct tm *lt; + time_t now; + + now = time(0); + lt = localtime(&now); + (void)afs_snprintf(stampSlvgLog, sizeof stampSlvgLog, + "%s.%04d-%02d-%02d.%02d:%02d:%02d", + AFSDIR_SERVER_SLVGLOG_FILEPATH, lt->tm_year + 1900, + lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, + lt->tm_sec); + + /* try to link the logfile to a timestamped filename */ + /* if it fails, oh well, nothing we can do */ + link(AFSDIR_SERVER_SLVGLOG_FILEPATH, stampSlvgLog); } #endif -void showlog(void) +void +showlog(void) { char line[256]; #ifndef AFS_NT40_ENV - if ( useSyslog ) { - printf("Can't show log since using syslog.\n"); - fflush(stdout); - return; - } + if (useSyslog) { + printf("Can't show log since using syslog.\n"); + fflush(stdout); + return; + } #endif rewind(logFile); fclose(logFile); - logFile = fopen(AFSDIR_SERVER_SLVGLOG_FILEPATH, "r"); + logFile = afs_fopen(AFSDIR_SERVER_SLVGLOG_FILEPATH, "r"); if (!logFile) printf("Can't read %s, exiting\n", AFSDIR_SERVER_SLVGLOG_FILEPATH); else { rewind(logFile); while (fgets(line, sizeof(line), logFile)) - printf("%s",line); + printf("%s", line); fflush(stdout); } } -void Log(a,b,c,d,e,f,g,h,i,j,k) -char *a, *b, *c, *d, *e, *f, *g, *h, *i, *j, *k; +void +Log(const char *format, ...) { struct timeval now; + char tmp[1024]; + va_list args; + va_start(args, format); + (void)afs_vsnprintf(tmp, sizeof tmp, format, args); + va_end(args); #ifndef AFS_NT40_ENV - if ( useSyslog ) - { - syslog(LOG_INFO, a,b,c,d,e,f,g,h,i,j,k); - } else -#endif - { - gettimeofday(&now, 0); - fprintf(logFile, "%s ", TimeStamp(now.tv_sec, 1)); - fprintf(logFile, a,b,c,d,e,f,g,h,i,j,k); - fflush(logFile); - } + if (useSyslog) { + syslog(LOG_INFO, "%s", tmp); + } else +#endif + { + gettimeofday(&now, 0); + fprintf(logFile, "%s %s", TimeStamp(now.tv_sec, 1), tmp); + fflush(logFile); + } } -void Abort(a,b,c,d,e,f,g,h,i,j,k) -char *a, *b, *c, *d, *e, *f, *g, *h, *i, *j, *k; +void +Abort(const char *format, ...) { + va_list args; + char tmp[1024]; + + va_start(args, format); + (void)afs_vsnprintf(tmp, sizeof tmp, format, args); + va_end(args); #ifndef AFS_NT40_ENV - if ( useSyslog ) - { - syslog(LOG_INFO, a,b,c,d,e,f,g,h,i,j,k); - } else + if (useSyslog) { + syslog(LOG_INFO, "%s", tmp); + } else #endif - { - fprintf(logFile, a,b,c,d,e,f,g,h,i,j,k); - fflush(logFile); - if (ShowLog) showlog(); - } + { + fprintf(logFile, "%s", tmp); + fflush(logFile); + if (ShowLog) + showlog(); + } + if (debug) abort(); Exit(1); } -char * ToString(char *s) +char * +ToString(char *s) { register char *p; - p = (char *) malloc(strlen(s)+1); + p = (char *)malloc(strlen(s) + 1); assert(p != NULL); - strcpy(p,s); + strcpy(p, s); return p; } /* Remove the FORCESALVAGE file */ -void RemoveTheForce(char *path) +void +RemoveTheForce(char *path) { - if (!Testing && ForceSalvage) { - if (chdir(path) == 0) - unlink("FORCESALVAGE"); - } + if (!Testing && ForceSalvage) { + if (chdir(path) == 0) + unlink("FORCESALVAGE"); + } } #ifndef AFS_AIX32_ENV /* * UseTheForceLuke - see if we can use the force */ -int UseTheForceLuke(char *path) +int +UseTheForceLuke(char *path) { - struct stat force; + struct afs_stat force; assert(chdir(path) != -1); - return (stat("FORCESALVAGE", &force) == 0); + return (afs_stat("FORCESALVAGE", &force) == 0); } #else /* @@ -3722,10 +3934,11 @@ int UseTheForceLuke(char *path) * ListViceInodes() has a side effect of setting ForceSalvage if * it detects a need, based on root inode examination. */ -int UseTheForceLuke(char *path) +int +UseTheForceLuke(char *path) { - return 0; /* sorry OB1 */ + return 0; /* sorry OB1 */ } #endif @@ -3733,27 +3946,28 @@ int UseTheForceLuke(char *path) /* NT support routines */ static char execpathname[MAX_PATH]; -int nt_SalvagePartition(char *partName, int jobn) +int +nt_SalvagePartition(char *partName, int jobn) { int pid; int n; childJob_t job; if (!*execpathname) { - n = GetModuleFileName(NULL, execpathname, MAX_PATH-1); + n = GetModuleFileName(NULL, execpathname, MAX_PATH - 1); if (!n || n == 1023) return -1; } job.cj_magic = SALVAGER_MAGIC; job.cj_number = jobn; - (void) strcpy(job.cj_part, partName); - pid = (int)spawnprocveb(execpathname, save_args, NULL, - &job, sizeof(job)); + (void)strcpy(job.cj_part, partName); + pid = (int)spawnprocveb(execpathname, save_args, NULL, &job, sizeof(job)); return pid; } -int nt_SetupPartitionSalvage(void *datap, int len) +int +nt_SetupPartitionSalvage(void *datap, int len) { - childJob_t *jobp = (childJob_t*)datap; + childJob_t *jobp = (childJob_t *) datap; char logname[AFSDIR_PATH_MAX]; if (len != sizeof(childJob_t)) @@ -3763,10 +3977,11 @@ int nt_SetupPartitionSalvage(void *datap, int len) myjob = *jobp; /* Open logFile */ - (void) sprintf(logname, "%s.%d", AFSDIR_SERVER_SLVGLOG_FILEPATH, - myjob.cj_number); - logFile = fopen(logname, "w"); - if (!logFile) logFile = stdout; + (void)sprintf(logname, "%s.%d", AFSDIR_SERVER_SLVGLOG_FILEPATH, + myjob.cj_number); + logFile = afs_fopen(logname, "w"); + if (!logFile) + logFile = stdout; return 0; } diff --git a/src/vol/voldefs.h b/src/vol/voldefs.h index 7c77d372c..2094a0ca0 100644 --- a/src/vol/voldefs.h +++ b/src/vol/voldefs.h @@ -35,7 +35,7 @@ #define VHDREXT ".vol" #endif #define VMAXPATHLEN 64 /* Maximum length (including null) of a volume - external path name */ + * external path name */ #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV) /* INODEDIR holds all the inodes. Since it's name does not begin with "V" diff --git a/src/vol/volinodes.h b/src/vol/volinodes.h index 93f0ba719..cb72b9c0b 100644 --- a/src/vol/volinodes.h +++ b/src/vol/volinodes.h @@ -25,29 +25,32 @@ private struct VolumeHeader tempHeader; #endif private struct stuff { struct versionStamp stamp; - bit32 inodeType; - int size; /* size of any fixed size portion of the header */ - Inode *inode; - char *description; + bit32 inodeType; + int size; /* size of any fixed size portion of the header */ + Inode *inode; + char *description; /* if this is 1, then this inode is obsolete-- * salvager may delete it, and shouldn't complain * if it isn't there; create can not bother to create it */ - int obsolete; + int obsolete; } stuff[] = { - {{VOLUMEINFOMAGIC,VOLUMEINFOVERSION}, VI_VOLINFO, sizeof(VolumeDiskData), - &tempHeader.volumeInfo, "Volume information", 0}, - {{SMALLINDEXMAGIC,SMALLINDEXVERSION},VI_SMALLINDEX,sizeof(struct versionStamp), - &tempHeader.smallVnodeIndex, "small inode index", 0}, - {{LARGEINDEXMAGIC,LARGEINDEXVERSION},VI_LARGEINDEX,sizeof(struct versionStamp), - &tempHeader.largeVnodeIndex, "large inode index", 0}, - {{ACLMAGIC,ACLVERSION},VI_ACL,sizeof(struct versionStamp), - &tempHeader.volumeAcl, "access control list", 1}, - {{MOUNTMAGIC,MOUNTVERSION},VI_MOUNTTABLE,sizeof(struct versionStamp), - &tempHeader.volumeMountTable, "mount table", 1}, - {{LINKTABLEMAGIC,LINKTABLEVERSION},VI_LINKTABLE, - sizeof(struct versionStamp), - &tempHeader.linkTable, "link table", NO_LINK_TABLE}, -}; + { { + VOLUMEINFOMAGIC, VOLUMEINFOVERSION}, VI_VOLINFO, sizeof(VolumeDiskData), + &tempHeader.volumeInfo, "Volume information", 0} + , { { + SMALLINDEXMAGIC, SMALLINDEXVERSION} + , VI_SMALLINDEX, sizeof(struct versionStamp), &tempHeader.smallVnodeIndex, + "small inode index", 0}, { { + LARGEINDEXMAGIC, LARGEINDEXVERSION}, VI_LARGEINDEX, + sizeof(struct versionStamp), &tempHeader.largeVnodeIndex, + "large inode index", 0}, { { + ACLMAGIC, ACLVERSION}, VI_ACL, sizeof(struct versionStamp), + &tempHeader.volumeAcl, "access control list", 1}, { { + MOUNTMAGIC, MOUNTVERSION}, VI_MOUNTTABLE, sizeof(struct versionStamp), + &tempHeader.volumeMountTable, "mount table", 1}, { { +LINKTABLEMAGIC, LINKTABLEVERSION}, VI_LINKTABLE, + sizeof(struct versionStamp), &tempHeader.linkTable, "link table", + NO_LINK_TABLE},}; /* inodeType is redundant in the above table; it used to be useful, but now we require the table to be ordered */ #define MAXINODETYPE VI_LINKTABLE diff --git a/src/vol/volume.c b/src/vol/volume.c index d4520dd69..adc52cd3f 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -19,7 +19,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/volume.c,v 1.1.1.14 2003/04/13 19:08:20 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/volume.c,v 1.35 2004/04/18 06:13:54 kolya Exp $"); #include #include @@ -29,7 +30,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/volume.c,v 1.1.1.14 2003/04/13 19:0 #if !defined(AFS_SGI_ENV) #ifdef AFS_OSF_ENV #include -#else /* AFS_OSF_ENV */ +#else /* AFS_OSF_ENV */ #ifdef AFS_VFSINCL_ENV #define VFS #ifdef AFS_SUN5_ENV @@ -47,7 +48,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/volume.c,v 1.1.1.14 2003/04/13 19:0 #include #endif #endif /* AFS_VFSINCL_ENV */ -#endif /* AFS_OSF_ENV */ +#endif /* AFS_OSF_ENV */ #endif /* AFS_SGI_ENV */ #endif /* AFS_NT40_ENV */ #include @@ -82,13 +83,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/volume.c,v 1.1.1.14 2003/04/13 19:0 #ifdef AFS_SGI_EFS_IOPS_ENV #define ROOTINO EFS_ROOTINO #include -#include "../sgiefs/efs.h" /* until 5.1 release */ +#include "sgiefs/efs.h" /* until 5.1 release */ #endif #else #ifndef AFS_LINUX20_ENV -#include /* Need to find in libc 5, present in libc 6 */ +#include /* Need to find in libc 5, present in libc 6 */ #endif #endif #endif /* AFS_SGI_ENV */ @@ -116,8 +117,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/volume.c,v 1.1.1.14 2003/04/13 19:0 #include "lwp.h" #include #include "ihandle.h" -#ifdef AFS_NT40_ENV #include +#ifdef AFS_NT40_ENV #include #endif #include "vnode.h" @@ -134,9 +135,21 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/volume.c,v 1.1.1.14 2003/04/13 19:0 #include #endif +#ifdef O_LARGEFILE +#define afs_stat stat64 +#define afs_fstat fstat64 +#define afs_open open64 +#else /* !O_LARGEFILE */ +#define afs_stat stat +#define afs_fstat fstat +#define afs_open open +#endif /* !O_LARGEFILE */ + #ifdef AFS_PTHREAD_ENV pthread_mutex_t vol_glock_mutex; pthread_mutex_t vol_attach_mutex; +pthread_mutex_t vol_fsync_mutex; +pthread_mutex_t vol_trans_mutex; pthread_cond_t vol_put_volume_cond; pthread_cond_t vol_sleep_cond; #endif /* AFS_PTHREAD_ENV */ @@ -145,89 +158,97 @@ pthread_cond_t vol_sleep_cond; extern void *calloc(), *realloc(); #endif +/*@printflike@*/ extern void Log(const char *format, ...); + /* Forward declarations */ -static Volume *attach2(); -static void FreeVolume(); -static void VScanUpdateList(); -static void InitLRU(); -static int GetVolumeHeader(); -static void ReleaseVolumeHeader(); -static void FreeVolumeHeader(); -static void AddVolumeToHashTable(); -static void DeleteVolumeFromHashTable(); -static int VHold(Volume *vp); -static int VHold_r(Volume *vp); -static void GetBitmap(Error *ec, Volume *vp, VnodeClass class); -static void GetVolumePath(Error *ec, VolId volumeId, char **partitionp, - char **namep); -static void VReleaseVolumeHandles_r(Volume *vp); -static void VCloseVolumeHandles_r(Volume *vp); - -int LogLevel; /* Vice loglevel--not defined as extern so that it will be - defined when not linked with vice, XXXX */ +static Volume *attach2(Error * ec, char *path, + register struct VolumeHeader *header, + struct DiskPartition *partp, int isbusy); +static void FreeVolume(Volume * vp); +static void VScanUpdateList(void); +static void InitLRU(int howMany); +static int GetVolumeHeader(register Volume * vp); +static void ReleaseVolumeHeader(register struct volHeader *hd); +static void FreeVolumeHeader(register Volume * vp); +static void AddVolumeToHashTable(register Volume * vp, int hashid); +static void DeleteVolumeFromHashTable(register Volume * vp); +static int VHold(Volume * vp); +static int VHold_r(Volume * vp); +static void GetBitmap(Error * ec, Volume * vp, VnodeClass class); +static void GetVolumePath(Error * ec, VolId volumeId, char **partitionp, + char **namep); +static void VReleaseVolumeHandles_r(Volume * vp); +static void VCloseVolumeHandles_r(Volume * vp); + +int LogLevel; /* Vice loglevel--not defined as extern so that it will be + * defined when not linked with vice, XXXX */ ProgramType programType; /* The type of program using the package */ #define VOLUME_BITMAP_GROWSIZE 16 /* bytes, => 128vnodes */ - /* Must be a multiple of 4 (1 word) !!*/ + /* Must be a multiple of 4 (1 word) !! */ #define VOLUME_HASH_TABLE_SIZE 128 /* Must be a power of 2!! */ #define VOLUME_HASH(volumeId) (volumeId&(VOLUME_HASH_TABLE_SIZE-1)) private Volume *VolumeHashTable[VOLUME_HASH_TABLE_SIZE]; #ifndef AFS_HAVE_FFS /* This macro is used where an ffs() call does not exist. Was in util/ffs.c */ -ffs(x) { \ - afs_int32 ffs_i; \ - afs_int32 ffs_tmp = x; \ - if (ffs_tmp == 0) return(-1); \ - else \ - for (ffs_i = 1;; ffs_i++) { \ - if (ffs_tmp & 1) return(ffs_i); \ - else ffs_tmp >>= 1; \ - } \ - } +ffs(x) +{ + afs_int32 ffs_i; + afs_int32 ffs_tmp = x; + if (ffs_tmp == 0) + return (-1); + else + for (ffs_i = 1;; ffs_i++) { + if (ffs_tmp & 1) + return (ffs_i); + else + ffs_tmp >>= 1; + } +} #endif /* !AFS_HAVE_FFS */ -struct Lock vol_listLock; /* Lock obtained when listing volumes: prevents a volume from being missed if the volume is attached during a list volumes */ +struct Lock vol_listLock; /* Lock obtained when listing volumes: prevents a volume from being missed if the volume is attached during a list volumes */ extern struct Lock FSYNC_handler_lock; -Volume *VAttachVolumeByName(); -Volume *VAttachVolumeByName_r(); - -static int TimeZoneCorrection; /* Number of seconds west of GMT */ +static int TimeZoneCorrection; /* Number of seconds west of GMT */ /* Common message used when the volume goes off line */ char *VSalvageMessage = -"Files in this volume are currently unavailable; call operations"; + "Files in this volume are currently unavailable; call operations"; -int VInit; /* 0 - uninitialized, - 1 - initialized but not all volumes have been attached, - 2 - initialized and all volumes have been attached, - 3 - initialized, all volumes have been attached, and - VConnectFS() has completed. */ +int VInit; /* 0 - uninitialized, + * 1 - initialized but not all volumes have been attached, + * 2 - initialized and all volumes have been attached, + * 3 - initialized, all volumes have been attached, and + * VConnectFS() has completed. */ -int VolumeCacheCheck; /* Incremented everytime a volume goes on line-- - * used to stamp volume headers and in-core - * vnodes. When the volume goes on-line the - * vnode will be invalidated */ +bit32 VolumeCacheCheck; /* Incremented everytime a volume goes on line-- + * used to stamp volume headers and in-core + * vnodes. When the volume goes on-line the + * vnode will be invalidated */ -int VolumeCacheSize = 200, VolumeGets=0, VolumeReplacements=0, Vlooks = 0; +int VolumeCacheSize = 200, VolumeGets = 0, VolumeReplacements = 0, Vlooks = 0; -int VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes, +int +VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes, int connect, int volcache) { - int errors = 0; /* Number of errors while finding vice partitions. */ + int errors = 0; /* Number of errors while finding vice partitions. */ struct timeval tv; struct timezone tz; programType = pt; - + #ifdef AFS_PTHREAD_ENV assert(pthread_mutex_init(&vol_glock_mutex, NULL) == 0); assert(pthread_mutex_init(&vol_attach_mutex, NULL) == 0); + assert(pthread_mutex_init(&vol_fsync_mutex, NULL) == 0); + assert(pthread_mutex_init(&vol_trans_mutex, NULL) == 0); assert(pthread_cond_init(&vol_put_volume_cond, NULL) == 0); assert(pthread_cond_init(&vol_sleep_cond, NULL) == 0); #else /* AFS_PTHREAD_ENV */ @@ -235,10 +256,10 @@ int VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes, #endif /* AFS_PTHREAD_ENV */ Lock_Init(&vol_listLock); Lock_Init(&FSYNC_handler_lock); - srandom(time(0)); /* For VGetVolumeInfo */ + srandom(time(0)); /* For VGetVolumeInfo */ gettimeofday(&tv, &tz); - TimeZoneCorrection = tz.tz_minuteswest*60; - + TimeZoneCorrection = tz.tz_minuteswest * 60; + /* Ok, we have done enough initialization that fileserver can * start accepting calls, even though the volumes may not be * available just yet. @@ -259,7 +280,7 @@ int VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes, errors = VAttachPartitions(); - if (errors) + if (errors) return -1; if (programType == fileServer) { @@ -271,32 +292,36 @@ int VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes, /* Attach all the volumes in this partition */ for (diskP = DiskPartitionList; diskP; diskP = diskP->next) { int nAttached = 0, nUnattached = 0; + Log("Partition %s: attaching volumes\n", diskP->name); dirp = opendir(VPartitionPath(diskP)); assert(dirp); - while (dp = readdir(dirp)) { + while ((dp = readdir(dirp))) { char *p; p = strrchr(dp->d_name, '.'); if (p != NULL && strcmp(p, VHDREXT) == 0) { Error error; Volume *vp; vp = VAttachVolumeByName(&error, diskP->name, dp->d_name, - V_UPDATE); - (*(vp?&nAttached:&nUnattached))++; + V_VOLUPD); + (*(vp ? &nAttached : &nUnattached))++; if (error == VOFFLINE) - Log("Volume %u stays offline (/vice/offline/%s exists)\n", - VolumeNumber(dp->d_name), dp->d_name); + Log("Volume %d stays offline (/vice/offline/%s exists)\n", VolumeNumber(dp->d_name), dp->d_name); + else if (LogLevel >= 5) { + Log("Partition %s: attached volume %d (%s)\n", + diskP->name, VolumeNumber(dp->d_name), + dp->d_name); + } if (vp) { VPutVolume(vp); } } } - Log("Partition %s: attached %d volumes; %d volumes not attached\n", - diskP->name, nAttached, nUnattached); + Log("Partition %s: attached %d volumes; %d volumes not attached\n", diskP->name, nAttached, nUnattached); closedir(dirp); } } - VInit = 2; /* Initialized, and all volumes have been attached */ + VInit = 2; /* Initialized, and all volumes have been attached */ if (programType == volumeUtility && connect) { if (!VConnectFS()) { Log("Unable to connect to file server; aborted\n"); @@ -310,79 +335,87 @@ int VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes, file server is also running. This is separated from VInitVolumePackage so that a utility can fork--and each of the children can independently initialize communication with the file server */ -int VConnectFS(void) +int +VConnectFS(void) { int retVal; - VOL_LOCK - retVal = VConnectFS_r(); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VConnectFS_r(); + VOL_UNLOCK return retVal; } -int VConnectFS_r(void) +int +VConnectFS_r(void) { int rc; assert(VInit == 2 && programType == volumeUtility); rc = FSYNC_clientInit(); if (rc) - VInit = 3; + VInit = 3; return rc; } -void VDisconnectFS_r(void) { +void +VDisconnectFS_r(void) +{ assert(programType == volumeUtility); FSYNC_clientFinis(); VInit = 2; } -void VDisconnectFS(void) { - VOL_LOCK - VDisconnectFS_r(); - VOL_UNLOCK -} +void +VDisconnectFS(void) +{ + VOL_LOCK VDisconnectFS_r(); +VOL_UNLOCK} -void VShutdown_r(void) +void +VShutdown_r(void) { int i; register Volume *vp, *np; register afs_int32 code; Log("VShutdown: shutting down on-line volumes...\n"); - for (i=0; ihashNext) { + for (vp = VolumeHashTable[i]; vp; vp = vp->hashNext) { code = VHold_r(vp); - if (code == 0) break; /* got it */ + if (code == 0) + break; /* got it */ /* otherwise we go around again, trying another volume */ } - while(vp) { + while (vp) { + if (LogLevel >= 5) + Log("VShutdown: Attempting to take volume %u offline.\n", + vp->hashid); /* first compute np before releasing vp, in case vp disappears * after releasing. Hold it, so it doesn't disapear. If we * can't hold it, try the next one in the chain. Invariant * at the top of this loop is that vp is held (has extra ref count). */ - for(np=vp->hashNext; np; np=np->hashNext) { + for (np = vp->hashNext; np; np = np->hashNext) { code = VHold_r(np); - if (code == 0) break; /* got it */ + if (code == 0) + break; /* got it */ } /* next, take the volume offline (drops reference count) */ VOffline_r(vp, "File server was shut down"); - vp = np; /* next guy to try */ + vp = np; /* next guy to try */ } } Log("VShutdown: complete.\n"); } -void VShutdown(void) +void +VShutdown(void) { - VOL_LOCK - VShutdown_r(); - VOL_UNLOCK -} + VOL_LOCK VShutdown_r(); +VOL_UNLOCK} -static void ReadHeader(Error *ec, IHandle_t *h, char *to, int size, - int magic, int version) +static void +ReadHeader(Error * ec, IHandle_t * h, char *to, int size, bit32 magic, + bit32 version) { struct versionStamp *vsn; FdHandle_t *fdP; @@ -404,7 +437,7 @@ static void ReadHeader(Error *ec, IHandle_t *h, char *to, int size, FDH_REALLYCLOSE(fdP); return; } - vsn = (struct versionStamp *) to; + vsn = (struct versionStamp *)to; if (FDH_READ(fdP, to, size) != size || vsn->magic != magic) { *ec = VSALVAGE; FDH_REALLYCLOSE(fdP); @@ -422,10 +455,11 @@ static void ReadHeader(Error *ec, IHandle_t *h, char *to, int size, * Allows for storing 64 bit inode numbers in on-disk volume header * file. */ -void VolumeHeaderToDisk(VolumeDiskHeader_t *dh, VolumeHeader_t *h) +void +VolumeHeaderToDisk(VolumeDiskHeader_t * dh, VolumeHeader_t * h) { - memset((char*)dh, 0, sizeof(VolumeDiskHeader_t)); + memset((char *)dh, 0, sizeof(VolumeDiskHeader_t)); dh->stamp = h->stamp; dh->id = h->id; dh->parent = h->parent; @@ -434,9 +468,11 @@ void VolumeHeaderToDisk(VolumeDiskHeader_t *dh, VolumeHeader_t *h) dh->volumeInfo_lo = (afs_int32) h->volumeInfo & 0xffffffff; dh->volumeInfo_hi = (afs_int32) (h->volumeInfo >> 32) & 0xffffffff; dh->smallVnodeIndex_lo = (afs_int32) h->smallVnodeIndex & 0xffffffff; - dh->smallVnodeIndex_hi = (afs_int32) (h->smallVnodeIndex >> 32) & 0xffffffff; + dh->smallVnodeIndex_hi = + (afs_int32) (h->smallVnodeIndex >> 32) & 0xffffffff; dh->largeVnodeIndex_lo = (afs_int32) h->largeVnodeIndex & 0xffffffff; - dh->largeVnodeIndex_hi = (afs_int32) (h->largeVnodeIndex >> 32) & 0xffffffff; + dh->largeVnodeIndex_hi = + (afs_int32) (h->largeVnodeIndex >> 32) & 0xffffffff; dh->linkTable_lo = (afs_int32) h->linkTable & 0xffffffff; dh->linkTable_hi = (afs_int32) (h->linkTable >> 32) & 0xffffffff; #else @@ -453,23 +489,27 @@ void VolumeHeaderToDisk(VolumeDiskHeader_t *dh, VolumeHeader_t *h) * zero'd the volume header file so that high parts of inode * numbers are 0 in older (SGI EFS) volume header files. */ -void DiskToVolumeHeader(VolumeHeader_t *h, VolumeDiskHeader_t *dh) +void +DiskToVolumeHeader(VolumeHeader_t * h, VolumeDiskHeader_t * dh) { - memset((char*)h, 0, sizeof(VolumeHeader_t)); + memset((char *)h, 0, sizeof(VolumeHeader_t)); h->stamp = dh->stamp; h->id = dh->id; h->parent = dh->parent; #ifdef AFS_64BIT_IOPS_ENV - h->volumeInfo = dh->volumeInfo_lo | ((Inode)dh->volumeInfo_hi << 32); - - h->smallVnodeIndex = dh->smallVnodeIndex_lo | - ((Inode)dh->smallVnodeIndex_hi << 32); - - h->largeVnodeIndex = dh->largeVnodeIndex_lo | - ((Inode)dh->largeVnodeIndex_hi << 32); - h->linkTable = dh->linkTable_lo | - ((Inode)dh->linkTable_hi << 32); + h->volumeInfo = + (Inode) dh->volumeInfo_lo | ((Inode) dh->volumeInfo_hi << 32); + + h->smallVnodeIndex = + (Inode) dh->smallVnodeIndex_lo | ((Inode) dh-> + smallVnodeIndex_hi << 32); + + h->largeVnodeIndex = + (Inode) dh->largeVnodeIndex_lo | ((Inode) dh-> + largeVnodeIndex_hi << 32); + h->linkTable = + (Inode) dh->linkTable_lo | ((Inode) dh->linkTable_hi << 32); #else h->volumeInfo = dh->volumeInfo_lo; h->smallVnodeIndex = dh->smallVnodeIndex_lo; @@ -479,9 +519,10 @@ void DiskToVolumeHeader(VolumeHeader_t *h, VolumeDiskHeader_t *dh) } -void WriteVolumeHeader_r(ec, vp) - Error *ec; - Volume *vp; +void +WriteVolumeHeader_r(ec, vp) + Error *ec; + Volume *vp; { IHandle_t *h = V_diskDataHandle(vp); FdHandle_t *fdP; @@ -498,7 +539,7 @@ void WriteVolumeHeader_r(ec, vp) FDH_REALLYCLOSE(fdP); return; } - if (FDH_WRITE(fdP, (char*)&V_disk(vp), sizeof(V_disk(vp))) + if (FDH_WRITE(fdP, (char *)&V_disk(vp), sizeof(V_disk(vp))) != sizeof(V_disk(vp))) { *ec = VSALVAGE; FDH_REALLYCLOSE(fdP); @@ -512,31 +553,20 @@ void WriteVolumeHeader_r(ec, vp) normally goes online at this time. An offline volume must be reattached to make it go online */ Volume * -VAttachVolumeByName(ec, partition, name, mode) - Error *ec; - char *partition; - char *name; - int mode; +VAttachVolumeByName(Error * ec, char *partition, char *name, int mode) { Volume *retVal; - VATTACH_LOCK - VOL_LOCK - retVal = VAttachVolumeByName_r(ec, partition, name, mode); - VOL_UNLOCK - VATTACH_UNLOCK - return retVal; + VATTACH_LOCK VOL_LOCK retVal = + VAttachVolumeByName_r(ec, partition, name, mode); + VOL_UNLOCK VATTACH_UNLOCK return retVal; } Volume * -VAttachVolumeByName_r(ec, partition, name, mode) - Error *ec; - char *partition; - char *name; - int mode; +VAttachVolumeByName_r(Error * ec, char *partition, char *name, int mode) { register Volume *vp; - int fd,n; - struct stat status; + int fd, n; + struct afs_stat status; struct VolumeDiskHeader diskHeader; struct VolumeHeader iheader; struct DiskPartition *partp; @@ -553,9 +583,9 @@ VAttachVolumeByName_r(ec, partition, name, mode) if (V_inUse(vp)) return vp; if (vp->specialStatus == VBUSY) - isbusy = 1; + isbusy = 1; VDetachVolume_r(ec, vp); - if ( *ec ) { + if (*ec) { Log("VAttachVolume: Error detaching volume (%s)\n", name); } } @@ -571,34 +601,34 @@ VAttachVolumeByName_r(ec, partition, name, mode) strcpy(path, VPartitionPath(partp)); strcat(path, "/"); strcat(path, name); - VOL_UNLOCK - if ((fd = open(path, O_RDONLY)) == -1 || fstat(fd,&status) == -1) { - close(fd); - VOL_LOCK - *ec = VNOVOL; + VOL_UNLOCK if ((fd = afs_open(path, O_RDONLY)) == -1 + || afs_fstat(fd, &status) == -1) { + Log("VAttachVolume: Failed to open %s (errno %d)\n", path, errno); + if (fd > -1) + close(fd); + VOL_LOCK *ec = VNOVOL; goto done; } - n = read(fd, &diskHeader, sizeof (diskHeader)); + n = read(fd, &diskHeader, sizeof(diskHeader)); close(fd); - VOL_LOCK - if (n != sizeof (diskHeader) || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) { + VOL_LOCK if (n != sizeof(diskHeader) + || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) { Log("VAttachVolume: Error reading volume header %s\n", path); *ec = VSALVAGE; goto done; } if (diskHeader.stamp.version != VOLUMEHEADERVERSION) { - Log("VAttachVolume: Volume %s, version number is incorrect; volume needs salvaged\n",path); + Log("VAttachVolume: Volume %s, version number is incorrect; volume needs salvaged\n", path); *ec = VSALVAGE; goto done; } - + DiskToVolumeHeader(&iheader, &diskHeader); if (programType == volumeUtility && mode != V_SECRETLY) { if (FSYNC_askfs(iheader.id, partition, FSYNC_NEEDVOLUME, mode) == FSYNC_DENIED) { - Log("VAttachVolume: attach of volume %u apparently denied by file server\n", - iheader.id); - *ec = VNOVOL; /* XXXX */ + Log("VAttachVolume: attach of volume %u apparently denied by file server\n", iheader.id); + *ec = VNOVOL; /* XXXX */ goto done; } } @@ -606,10 +636,11 @@ VAttachVolumeByName_r(ec, partition, name, mode) vp = attach2(ec, path, &iheader, partp, isbusy); if (programType == volumeUtility && vp) { /* duplicate computation in fssync.c about whether the server - * takes the volume offline or not. If the volume isn't - * offline, we must not return it when we detach the volume, - * or the server will abort */ - if (mode == V_READONLY || (!VolumeWriteable(vp) && (mode==V_CLONE || mode==V_DUMP))) + * takes the volume offline or not. If the volume isn't + * offline, we must not return it when we detach the volume, + * or the server will abort */ + if (mode == V_READONLY + || (!VolumeWriteable(vp) && (mode == V_CLONE || mode == V_DUMP))) vp->needsPutBack = 0; else vp->needsPutBack = 1; @@ -627,16 +658,15 @@ VAttachVolumeByName_r(ec, partition, name, mode) * that it doesn't think are really checked out. */ if (programType == volumeUtility && vp == NULL && mode != V_SECRETLY) { FSYNC_askfs(iheader.id, partition, FSYNC_ON, 0); - } - else if (programType == fileServer && vp) { - V_needsCallback(vp) = 0; + } else if (programType == fileServer && vp) { + V_needsCallback(vp) = 0; #ifdef notdef - if (VInit >= 2 && V_BreakVolumeCallbacks) { - Log("VAttachVolume: Volume %u was changed externally; breaking callbacks\n", V_id(vp)); - (*V_BreakVolumeCallbacks)(V_id(vp)); - } + if (VInit >= 2 && V_BreakVolumeCallbacks) { + Log("VAttachVolume: Volume %u was changed externally; breaking callbacks\n", V_id(vp)); + (*V_BreakVolumeCallbacks) (V_id(vp)); + } #endif - VUpdateVolume_r(ec,vp); + VUpdateVolume_r(ec, vp); if (*ec) { Log("VAttachVolume: Error updating volume\n"); if (vp) @@ -645,15 +675,15 @@ VAttachVolumeByName_r(ec, partition, name, mode) } if (VolumeWriteable(vp) && V_dontSalvage(vp) == 0) { /* This is a hack: by temporarily settint the incore - * dontSalvage flag ON, the volume will be put back on the - * Update list (with dontSalvage OFF again). It will then - * come back in N minutes with DONT_SALVAGE eventually - * set. This is the way that volumes that have never had - * it set get it set; or that volumes that have been - * offline without DONT SALVAGE having been set also - * eventually get it set */ + * dontSalvage flag ON, the volume will be put back on the + * Update list (with dontSalvage OFF again). It will then + * come back in N minutes with DONT_SALVAGE eventually + * set. This is the way that volumes that have never had + * it set get it set; or that volumes that have been + * offline without DONT SALVAGE having been set also + * eventually get it set */ V_dontSalvage(vp) = DONT_SALVAGE; - VAddToVolumeUpdateList_r(ec,vp); + VAddToVolumeUpdateList_r(ec, vp); if (*ec) { Log("VAttachVolume: Error adding volume to update list\n"); if (vp) @@ -662,10 +692,10 @@ VAttachVolumeByName_r(ec, partition, name, mode) } } if (LogLevel) - Log("VOnline: volume %u (%s) attached and online\n", - V_id(vp), V_name(vp)); + Log("VOnline: volume %u (%s) attached and online\n", V_id(vp), + V_name(vp)); } -done: + done: if (programType == volumeUtility) { VUnlockPartition_r(partition); } @@ -675,107 +705,90 @@ done: return vp; } -private Volume *attach2(ec, path, header, partp, isbusy) - Error *ec; - char *path; - register struct VolumeHeader *header; - struct DiskPartition *partp; - int isbusy; +private Volume * +attach2(Error * ec, char *path, register struct VolumeHeader * header, + struct DiskPartition * partp, int isbusy) { register Volume *vp; - VOL_UNLOCK - vp = (Volume *) calloc(1, sizeof(Volume)); + VOL_UNLOCK vp = (Volume *) calloc(1, sizeof(Volume)); assert(vp != NULL); - vp->specialStatus = (isbusy ? VBUSY : 0); + vp->specialStatus = (byte) (isbusy ? VBUSY : 0); vp->device = partp->device; vp->partition = partp; IH_INIT(vp->vnodeIndex[vLarge].handle, partp->device, header->parent, - header->largeVnodeIndex); + header->largeVnodeIndex); IH_INIT(vp->vnodeIndex[vSmall].handle, partp->device, header->parent, - header->smallVnodeIndex); + header->smallVnodeIndex); IH_INIT(vp->diskDataHandle, partp->device, header->parent, - header->volumeInfo); - IH_INIT(vp->linkHandle, partp->device, header->parent, - header->linkTable); + header->volumeInfo); + IH_INIT(vp->linkHandle, partp->device, header->parent, header->linkTable); vp->cacheCheck = ++VolumeCacheCheck; /* just in case this ever rolls over */ - if (!vp->cacheCheck) + if (!vp->cacheCheck) vp->cacheCheck = ++VolumeCacheCheck; vp->shuttingDown = 0; vp->goingOffline = 0; vp->nUsers = 1; - VOL_LOCK - GetVolumeHeader(vp); - VOL_UNLOCK - (void) ReadHeader(ec, V_diskDataHandle(vp), - (char *)&V_disk(vp), sizeof(V_disk(vp)), - VOLUMEINFOMAGIC, VOLUMEINFOVERSION); - VOL_LOCK - if (*ec) { - Log("VAttachVolume: Error reading diskDataHandle vol header %s; error=%d\n", - path, *ec); + VOL_LOCK GetVolumeHeader(vp); + VOL_UNLOCK(void) ReadHeader(ec, V_diskDataHandle(vp), (char *)&V_disk(vp), + sizeof(V_disk(vp)), VOLUMEINFOMAGIC, + VOLUMEINFOVERSION); + VOL_LOCK if (*ec) { + Log("VAttachVolume: Error reading diskDataHandle vol header %s; error=%u\n", path, *ec); } if (!*ec) { struct IndexFileHeader iHead; -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS /* * We just read in the diskstuff part of the header. If the detailed * volume stats area has not yet been initialized, we should bzero the * area and mark it as initialized. */ - if (! (V_stat_initialized(vp))) { + if (!(V_stat_initialized(vp))) { memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES); V_stat_initialized(vp) = 1; } -#endif /* TRANSARC_VOL_STATS */ - VOL_UNLOCK - (void) ReadHeader(ec, vp->vnodeIndex[vSmall].handle, - (char *)&iHead, sizeof(iHead), - SMALLINDEXMAGIC, SMALLINDEXVERSION); - VOL_LOCK - if (*ec) { - Log("VAttachVolume: Error reading smallVnode vol header %s; error=%d\n", - path, *ec); +#endif /* OPENAFS_VOL_STATS */ + VOL_UNLOCK(void) ReadHeader(ec, vp->vnodeIndex[vSmall].handle, + (char *)&iHead, sizeof(iHead), + SMALLINDEXMAGIC, SMALLINDEXVERSION); + VOL_LOCK if (*ec) { + Log("VAttachVolume: Error reading smallVnode vol header %s; error=%u\n", path, *ec); } } if (!*ec) { struct IndexFileHeader iHead; - VOL_UNLOCK - (void) ReadHeader(ec, vp->vnodeIndex[vLarge].handle, - (char *)&iHead, sizeof(iHead), - LARGEINDEXMAGIC, LARGEINDEXVERSION); - VOL_LOCK - if (*ec) { - Log("VAttachVolume: Error reading largeVnode vol header %s; error=%d\n", - path, *ec); + VOL_UNLOCK(void) ReadHeader(ec, vp->vnodeIndex[vLarge].handle, + (char *)&iHead, sizeof(iHead), + LARGEINDEXMAGIC, LARGEINDEXVERSION); + VOL_LOCK if (*ec) { + Log("VAttachVolume: Error reading largeVnode vol header %s; error=%u\n", path, *ec); } } #ifdef AFS_NAMEI_ENV if (!*ec) { struct versionStamp stamp; - VOL_UNLOCK - (void) ReadHeader(ec, V_linkHandle(vp), - (char *)&stamp, sizeof(stamp), - LINKTABLEMAGIC, LINKTABLEVERSION); - VOL_LOCK - if (*ec) { - Log("VAttachVolume: Error reading namei vol header %s; error=%d\n", - path, *ec); + VOL_UNLOCK(void) ReadHeader(ec, V_linkHandle(vp), (char *)&stamp, + sizeof(stamp), LINKTABLEMAGIC, + LINKTABLEVERSION); + VOL_LOCK if (*ec) { + Log("VAttachVolume: Error reading namei vol header %s; error=%u\n", path, *ec); } } #endif if (*ec) { - Log("VAttachVolume: Error attaching volume %s; volume needs salvage; error=%d\n", - path, *ec); + Log("VAttachVolume: Error attaching volume %s; volume needs salvage; error=%u\n", path, *ec); FreeVolume(vp); return NULL; } if (V_needsSalvaged(vp)) { - if (vp->specialStatus) vp->specialStatus = 0; + if (vp->specialStatus) + vp->specialStatus = 0; Log("VAttachVolume: volume salvage flag is ON for %s; volume needs salvage\n", path); *ec = VSALVAGE; + FreeVolume(vp); return NULL; } if (programType == fileServer) { @@ -783,7 +796,7 @@ private Volume *attach2(ec, path, header, partp, isbusy) if (V_inUse(vp) && VolumeWriteable(vp)) { if (!V_needsSalvaged(vp)) { V_needsSalvaged(vp) = 1; - VUpdateVolume_r(ec,vp); + VUpdateVolume_r(ec, vp); } FreeVolume(vp); Log("VAttachVolume: volume %s needs to be salvaged; not attached.\n", path); @@ -805,13 +818,12 @@ private Volume *attach2(ec, path, header, partp, isbusy) #ifndef BITMAP_LATER if (programType == fileServer && VolumeWriteable(vp)) { int i; - for (i = 0; ispecialStatus) vp->specialStatus = 0; - if (V_blessed(vp) && V_inService(vp) && !V_needsSalvaged(vp)) { + if (vp->specialStatus) + vp->specialStatus = 0; + if (V_blessed(vp) && V_inService(vp) && !V_needsSalvaged(vp)) { V_inUse(vp) = 1; V_offlineMessage(vp)[0] = '\0'; } @@ -835,37 +848,27 @@ private Volume *attach2(ec, path, header, partp, isbusy) */ Volume * -VAttachVolume(ec,volumeId, mode) - Error *ec; - VolumeId volumeId; - int mode; +VAttachVolume(Error * ec, VolumeId volumeId, int mode) { Volume *retVal; - VATTACH_LOCK - VOL_LOCK - retVal = VAttachVolume_r(ec, volumeId, mode); - VOL_UNLOCK - VATTACH_UNLOCK - return retVal; + VATTACH_LOCK VOL_LOCK retVal = VAttachVolume_r(ec, volumeId, mode); + VOL_UNLOCK VATTACH_UNLOCK return retVal; } Volume * -VAttachVolume_r(ec,volumeId, mode) - Error *ec; - VolumeId volumeId; - int mode; +VAttachVolume_r(Error * ec, VolumeId volumeId, int mode) { char *part, *name; - GetVolumePath(ec,volumeId, &part, &name); + GetVolumePath(ec, volumeId, &part, &name); if (*ec) { - register Volume *vp; + register Volume *vp; Error error; vp = VGetVolume_r(&error, volumeId); if (vp) { assert(V_inUse(vp) == 0); VDetachVolume_r(ec, vp); } - return NULL; + return NULL; } return VAttachVolumeByName_r(ec, part, name, mode); } @@ -878,31 +881,32 @@ VAttachVolume_r(ec,volumeId, mode) * we still guarantee we won't context swap, but the ref count won't be * incremented (otherwise we'd violate the invariant). */ -static int VHold_r(register Volume *vp) +static int +VHold_r(register Volume * vp) { Error error; if (vp->nUsers == 0 && !GetVolumeHeader(vp)) { VolumeReplacements++; - ReadHeader(&error, V_diskDataHandle(vp), - (char *)&V_disk(vp), sizeof(V_disk(vp)), - VOLUMEINFOMAGIC, VOLUMEINFOVERSION); - if (error) return error; + ReadHeader(&error, V_diskDataHandle(vp), (char *)&V_disk(vp), + sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION); + if (error) + return error; } vp->nUsers++; return 0; } -static int VHold(register Volume *vp) +static int +VHold(register Volume * vp) { int retVal; - VOL_LOCK - retVal = VHold_r(vp); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VHold_r(vp); + VOL_UNLOCK return retVal; } -void VTakeOffline_r(register Volume *vp) +void +VTakeOffline_r(register Volume * vp) { assert(vp->nUsers > 0); assert(programType == fileServer); @@ -910,19 +914,19 @@ void VTakeOffline_r(register Volume *vp) V_needsSalvaged(vp) = 1; } -void VTakeOffline(register Volume *vp) +void +VTakeOffline(register Volume * vp) { - VOL_LOCK - VTakeOffline_r(vp); - VOL_UNLOCK -} + VOL_LOCK VTakeOffline_r(vp); +VOL_UNLOCK} -void VPutVolume_r(register Volume *vp) +void +VPutVolume_r(register Volume * vp) { assert(--vp->nUsers >= 0); if (vp->nUsers == 0) { ReleaseVolumeHeader(vp->header); - if (vp->goingOffline) { + if (vp->goingOffline) { Error error; assert(programType == fileServer); vp->goingOffline = 0; @@ -930,8 +934,8 @@ void VPutVolume_r(register Volume *vp) VUpdateVolume_r(&error, vp); VCloseVolumeHandles_r(vp); if (LogLevel) { - Log("VOffline: Volume %u (%s) is now offline", - V_id(vp), V_name(vp)); + Log("VOffline: Volume %u (%s) is now offline", V_id(vp), + V_name(vp)); if (V_offlineMessage(vp)[0]) Log(" (%s)", V_offlineMessage(vp)); Log("\n"); @@ -949,42 +953,38 @@ void VPutVolume_r(register Volume *vp) #ifdef AFS_PTHREAD_ENV assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0); #else /* AFS_PTHREAD_ENV */ - LWP_NoYieldSignal(VPutVolume); + LWP_NoYieldSignal(VPutVolume); #endif /* AFS_PTHREAD_ENV */ } } } -void VPutVolume(register Volume *vp) +void +VPutVolume(register Volume * vp) { - VOL_LOCK - VPutVolume_r(vp); - VOL_UNLOCK -} + VOL_LOCK VPutVolume_r(vp); +VOL_UNLOCK} /* Get a pointer to an attached volume. The pointer is returned regardless of whether or not the volume is in service or on/off line. An error code, however, is returned with an indication of the volume's status */ -Volume *VGetVolume(ec,volumeId) - Error *ec; - VolId volumeId; +Volume * +VGetVolume(Error * ec, VolId volumeId) { Volume *retVal; - VOL_LOCK - retVal = VGetVolume_r(ec,volumeId); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VGetVolume_r(ec, volumeId); + VOL_UNLOCK return retVal; } -Volume *VGetVolume_r(ec,volumeId) - Error *ec; - VolId volumeId; +Volume * +VGetVolume_r(Error * ec, VolId volumeId) { Volume *vp; - unsigned short V0=0, V1=0, V2=0, V3=0, V4=0, V5=0, V6=0, V7=0, V8=0, V9=0; - unsigned short V10=0, V11=0, V12=0, V13=0, V14=0, V15=0; + unsigned short V0 = 0, V1 = 0, V2 = 0, V3 = 0, V4 = 0, V5 = 0, V6 = + 0, V7 = 0, V8 = 0, V9 = 0; + unsigned short V10 = 0, V11 = 0, V12 = 0, V13 = 0, V14 = 0, V15 = 0; - for(;;) { + for (;;) { *ec = 0; V0++; for (vp = VolumeHashTable[VOLUME_HASH(volumeId)]; @@ -992,37 +992,38 @@ Volume *VGetVolume_r(ec,volumeId) Vlooks++; if (!vp) { - V1++; - if (VInit < 2) { - V2++; - /* Until we have reached an initialization level of 2 - we don't know whether this volume exists or not. - We can't sleep and retry later because before a volume - is attached, the caller tries to get it first. Just - return VOFFLINE and the caller can choose whether to - retry the command or not.*/ - *ec = VOFFLINE; - break; - } + V1++; + if (VInit < 2) { + V2++; + /* Until we have reached an initialization level of 2 + * we don't know whether this volume exists or not. + * We can't sleep and retry later because before a volume + * is attached, the caller tries to get it first. Just + * return VOFFLINE and the caller can choose whether to + * retry the command or not. */ + *ec = VOFFLINE; + break; + } - *ec = VNOVOL; - break; + *ec = VNOVOL; + break; } V3++; VolumeGets++; if (vp->nUsers == 0 && !GetVolumeHeader(vp)) { - V5++; + V5++; VolumeReplacements++; - ReadHeader(ec, V_diskDataHandle(vp), - (char *)&V_disk(vp), sizeof(V_disk(vp)), VOLUMEINFOMAGIC, - VOLUMEINFOVERSION); + ReadHeader(ec, V_diskDataHandle(vp), (char *)&V_disk(vp), + sizeof(V_disk(vp)), VOLUMEINFOMAGIC, + VOLUMEINFOVERSION); if (*ec) { - V6++; + V6++; /* Only log the error if it was a totally unexpected error. Simply - a missing inode is likely to be caused by the volume being deleted */ + * a missing inode is likely to be caused by the volume being deleted */ if (errno != ENXIO || LogLevel) - Log("Volume %u: couldn't reread volume header\n", vp->hashid); + Log("Volume %u: couldn't reread volume header\n", + vp->hashid); FreeVolume(vp); vp = 0; break; @@ -1030,45 +1031,43 @@ Volume *VGetVolume_r(ec,volumeId) } V7++; if (vp->shuttingDown) { - V8++; + V8++; *ec = VNOVOL; vp = 0; break; } if (programType == fileServer) { - V9++; + V9++; if (vp->goingOffline) { - V10++; + V10++; #ifdef AFS_PTHREAD_ENV pthread_cond_wait(&vol_put_volume_cond, &vol_glock_mutex); #else /* AFS_PTHREAD_ENV */ - LWP_WaitProcess(VPutVolume); + LWP_WaitProcess(VPutVolume); #endif /* AFS_PTHREAD_ENV */ continue; } if (vp->specialStatus) { - V11++; + V11++; *ec = vp->specialStatus; - } - else if (V_inService(vp)==0 || V_blessed(vp)==0) { - V12++; + } else if (V_inService(vp) == 0 || V_blessed(vp) == 0) { + V12++; *ec = VNOVOL; - } - else if (V_inUse(vp)==0) { - V13++; + } else if (V_inUse(vp) == 0) { + V13++; *ec = VOFFLINE; - } - else { - V14++; - } + } else { + V14++; + } } break; } V15++; /* if no error, bump nUsers */ - if (vp) vp->nUsers++; + if (vp) + vp->nUsers++; - assert (vp || *ec); + assert(vp || *ec); return vp; } @@ -1077,18 +1076,19 @@ Volume *VGetVolume_r(ec,volumeId) * For VOffline, if we re-attach the volume, the files may possible be * different than before. */ -static void VReleaseVolumeHandles_r(Volume *vp) +static void +VReleaseVolumeHandles_r(Volume * vp) { DFlushVolume(V_id(vp)); VReleaseVnodeFiles_r(vp); /* Too time consuming and unnecessary for the volserver */ if (programType != volumeUtility) { - IH_CONDSYNC(vp->vnodeIndex[vLarge].handle); - IH_CONDSYNC(vp->vnodeIndex[vSmall].handle); - IH_CONDSYNC(vp->diskDataHandle); + IH_CONDSYNC(vp->vnodeIndex[vLarge].handle); + IH_CONDSYNC(vp->vnodeIndex[vSmall].handle); + IH_CONDSYNC(vp->diskDataHandle); #ifdef AFS_NT40_ENV - IH_CONDSYNC(vp->linkHandle); + IH_CONDSYNC(vp->linkHandle); #endif /* AFS_NT40_ENV */ } @@ -1100,15 +1100,17 @@ static void VReleaseVolumeHandles_r(Volume *vp) /* Force the volume offline, set the salvage flag. No further references to * the volume through the volume package will be honored. */ -void VForceOffline_r(Volume *vp) +void +VForceOffline_r(Volume * vp) { Error error; if (!V_inUse(vp)) - return; - strcpy(V_offlineMessage(vp), "Forced offline due to internal error: volume needs to be salvaged"); + return; + strcpy(V_offlineMessage(vp), + "Forced offline due to internal error: volume needs to be salvaged"); Log("Volume %u forced offline: it needs salvaging!\n", V_id(vp)); V_inUse(vp) = 0; - vp->goingOffline = 0; + vp->goingOffline = 0; V_needsSalvaged(vp) = 1; VUpdateVolume_r(&error, vp); #ifdef AFS_PTHREAD_ENV @@ -1121,59 +1123,58 @@ void VForceOffline_r(Volume *vp) } -void VForceOffline(Volume *vp) +void +VForceOffline(Volume * vp) { - VOL_LOCK - VForceOffline_r(vp); - VOL_UNLOCK -} + VOL_LOCK VForceOffline_r(vp); +VOL_UNLOCK} /* The opposite of VAttachVolume. The volume header is written to disk, with the inUse bit turned off. A copy of the header is maintained in memory, however (which is why this is VOffline, not VDetach). - */ -void VOffline_r(Volume *vp, char *message) + */ +void +VOffline_r(Volume * vp, char *message) { Error error; VolumeId vid = V_id(vp); assert(programType != volumeUtility); if (!V_inUse(vp)) { VPutVolume_r(vp); - return; + return; } if (V_offlineMessage(vp)[0] == '\0') - strncpy(V_offlineMessage(vp),message, - sizeof(V_offlineMessage(vp))); - V_offlineMessage(vp)[sizeof(V_offlineMessage(vp))-1] = '\0'; - vp->goingOffline = 1; + strncpy(V_offlineMessage(vp), message, sizeof(V_offlineMessage(vp))); + V_offlineMessage(vp)[sizeof(V_offlineMessage(vp)) - 1] = '\0'; + vp->goingOffline = 1; VPutVolume_r(vp); vp = VGetVolume_r(&error, vid); /* Wait for it to go offline */ - if (vp) /* In case it was reattached... */ - VPutVolume_r(vp); + if (vp) /* In case it was reattached... */ + VPutVolume_r(vp); } -void VOffline(Volume *vp, char *message) +void +VOffline(Volume * vp, char *message) { - VOL_LOCK - VOffline_r(vp, message); - VOL_UNLOCK -} + VOL_LOCK VOffline_r(vp, message); +VOL_UNLOCK} /* For VDetachVolume, we close all cached file descriptors, but keep * the Inode handles in case we need to read from a busy volume. */ -static void VCloseVolumeHandles_r(Volume *vp) +static void +VCloseVolumeHandles_r(Volume * vp) { DFlushVolume(V_id(vp)); VCloseVnodeFiles_r(vp); /* Too time consuming and unnecessary for the volserver */ if (programType != volumeUtility) { - IH_CONDSYNC(vp->vnodeIndex[vLarge].handle); - IH_CONDSYNC(vp->vnodeIndex[vSmall].handle); - IH_CONDSYNC(vp->diskDataHandle); + IH_CONDSYNC(vp->vnodeIndex[vLarge].handle); + IH_CONDSYNC(vp->vnodeIndex[vSmall].handle); + IH_CONDSYNC(vp->diskDataHandle); #ifdef AFS_NT40_ENV - IH_CONDSYNC(vp->linkHandle); + IH_CONDSYNC(vp->linkHandle); #endif /* AFS_NT40_ENV */ } @@ -1189,15 +1190,16 @@ static void VCloseVolumeHandles_r(Volume *vp) * (or other information) will still be available to clients. For NAMEI, also * close the file handles. */ -void VDetachVolume_r(Error *ec, Volume *vp) +void +VDetachVolume_r(Error * ec, Volume * vp) { VolumeId volume; struct DiskPartition *tpartp; int notifyServer, useDone; - *ec = 0; /* always "succeeds" */ + *ec = 0; /* always "succeeds" */ if (programType == volumeUtility) { - notifyServer = vp->needsPutBack; + notifyServer = vp->needsPutBack; useDone = (V_destroyMe(vp) == DESTROY_ME); } tpartp = vp->partition; @@ -1208,99 +1210,98 @@ void VDetachVolume_r(Error *ec, Volume *vp) /* Will be detached sometime in the future--this is OK since volume is offline */ if (programType == volumeUtility && notifyServer) { - /* Note: The server is not notified in the case of a bogus volume explicitly to - make it possible to create a volume, do a partial restore, then abort the - operation without ever putting the volume online. This is essential in the - case of a volume move operation between two partitions on the same server. In - that case, there would be two instances of the same volume, one of them bogus, - which the file server would attempt to put on line */ + /* + * Note: The server is not notified in the case of a bogus volume + * explicitly to make it possible to create a volume, do a partial + * restore, then abort the operation without ever putting the volume + * online. This is essential in the case of a volume move operation + * between two partitions on the same server. In that case, there + * would be two instances of the same volume, one of them bogus, + * which the file server would attempt to put on line + */ if (useDone) - FSYNC_askfs(volume, tpartp->name, FSYNC_DONE, 0); /* don't put online */ + /* don't put online */ + FSYNC_askfs(volume, tpartp->name, FSYNC_DONE, 0); else { - FSYNC_askfs(volume, tpartp->name, FSYNC_ON, 0); /* fs can use it again */ - /* Dettaching it so break all callbacks on it*/ + /* fs can use it again */ + FSYNC_askfs(volume, tpartp->name, FSYNC_ON, 0); + /* Dettaching it so break all callbacks on it */ if (V_BreakVolumeCallbacks) { Log("volume %u detached; breaking all call backs\n", volume); - (*V_BreakVolumeCallbacks)(volume); + (*V_BreakVolumeCallbacks) (volume); } } } } -void VDetachVolume(Error *ec, Volume *vp) +void +VDetachVolume(Error * ec, Volume * vp) { - VOL_LOCK - VDetachVolume_r(ec, vp); - VOL_UNLOCK -} + VOL_LOCK VDetachVolume_r(ec, vp); +VOL_UNLOCK} -int VAllocBitmapEntry_r(ec,vp,index) - Error *ec; - Volume *vp; - register struct vnodeIndex *index; +VnodeId +VAllocBitmapEntry_r(Error * ec, Volume * vp, register struct vnodeIndex + *index) { - register byte *bp,*ep; + register byte *bp, *ep; *ec = 0; /* This test is probably redundant */ if (!VolumeWriteable(vp)) { - *ec = VREADONLY; + *ec = (bit32) VREADONLY; return 0; } #ifdef BITMAP_LATER if ((programType == fileServer) && !index->bitmap) { - int i; - int wasVBUSY = 0; - if (vp->specialStatus == VBUSY) { - if (vp->goingOffline) { /* vos dump waiting for the volume to - go offline. We probably come here - from AddNewReadableResidency */ - wasVBUSY = 1; - } else { - VOL_UNLOCK - while (vp->specialStatus == VBUSY) + int i; + int wasVBUSY = 0; + if (vp->specialStatus == VBUSY) { + if (vp->goingOffline) { /* vos dump waiting for the volume to + * go offline. We probably come here + * from AddNewReadableResidency */ + wasVBUSY = 1; + } else { + VOL_UNLOCK while (vp->specialStatus == VBUSY) #ifdef AFS_PTHREAD_ENV sleep(2); #else /* AFS_PTHREAD_ENV */ IOMGR_Sleep(2); #endif /* AFS_PTHREAD_ENV */ - VOL_LOCK + VOL_LOCK} + } + if (!index->bitmap) { + vp->specialStatus = VBUSY; /* Stop anyone else from using it. */ + for (i = 0; i < nVNODECLASSES; i++) { + VOL_UNLOCK GetBitmap(ec, vp, i); + VOL_LOCK if (*ec) { + vp->specialStatus = 0; + vp->shuttingDown = 1; /* Let who has it free it. */ + return NULL; + } } - } - if (!index->bitmap) { - vp->specialStatus = VBUSY; /* Stop anyone else from using it.*/ - for (i = 0; ispecialStatus = 0; - vp->shuttingDown = 1; /* Let who has it free it. */ - return NULL; - } - } - if (!wasVBUSY) - vp->specialStatus = 0; /* Allow others to have access. */ - } + if (!wasVBUSY) + vp->specialStatus = 0; /* Allow others to have access. */ + } } #endif /* BITMAP_LATER */ bp = index->bitmap + index->bitmapOffset; ep = index->bitmap + index->bitmapSize; while (bp < ep) { - if ((*(bit32 *)bp) != 0xffffffff) { + if ((*(bit32 *) bp) != (bit32) 0xffffffff) { int o; - index->bitmapOffset = bp - index->bitmap; + index->bitmapOffset = (afs_uint32) (bp - index->bitmap); while (*bp == 0xff) - bp++; - o = ffs(~*bp)-1; /* ffs is documented in BSTRING(3) */ + bp++; + o = ffs(~*bp) - 1; /* ffs is documented in BSTRING(3) */ *bp |= (1 << o); - return (bp - index->bitmap)*8 + o; + return (VnodeId) ((bp - index->bitmap) * 8 + o); } - bp += sizeof(bit32) /* i.e. 4 */; + bp += sizeof(bit32) /* i.e. 4 */ ; } /* No bit map entry--must grow bitmap */ bp = (byte *) - realloc(index->bitmap, index->bitmapSize+VOLUME_BITMAP_GROWSIZE); + realloc(index->bitmap, index->bitmapSize + VOLUME_BITMAP_GROWSIZE); assert(bp != NULL); index->bitmap = bp; bp += index->bitmapSize; @@ -1308,70 +1309,69 @@ int VAllocBitmapEntry_r(ec,vp,index) index->bitmapOffset = index->bitmapSize; index->bitmapSize += VOLUME_BITMAP_GROWSIZE; *bp = 1; - return index->bitmapOffset*8; + return index->bitmapOffset * 8; } -int VAllocBitmapEntry(ec,vp,index) - Error *ec; - Volume *vp; - register struct vnodeIndex *index; +VnodeId +VAllocBitmapEntry(Error * ec, Volume * vp, register struct vnodeIndex * index) { - int retVal; - VOL_LOCK - retVal = VAllocBitmapEntry_r(ec,vp,index); - VOL_UNLOCK - return retVal; + VnodeId retVal; + VOL_LOCK retVal = VAllocBitmapEntry_r(ec, vp, index); + VOL_UNLOCK return retVal; } -void VFreeBitMapEntry_r(Error *ec, register struct vnodeIndex *index, - int bitNumber) +void +VFreeBitMapEntry_r(Error * ec, register struct vnodeIndex *index, + unsigned bitNumber) { unsigned int offset; - *ec = 0; + *ec = 0; #ifdef BITMAP_LATER - if (!index->bitmap) return; + if (!index->bitmap) + return; #endif /* BITMAP_LATER */ - offset = bitNumber>>3; - if (offset >= index->bitmapSize) { + offset = bitNumber >> 3; + if (offset >= index->bitmapSize) { *ec = VNOVNODE; return; - } - if (offset < index->bitmapOffset) - index->bitmapOffset = offset&~3; /* Truncate to nearest bit32 */ - *(index->bitmap + offset) &= ~(1 << (bitNumber & 0x7)); + } + if (offset < index->bitmapOffset) + index->bitmapOffset = offset & ~3; /* Truncate to nearest bit32 */ + *(index->bitmap + offset) &= ~(1 << (bitNumber & 0x7)); } -void VFreeBitMapEntry(Error *ec, register struct vnodeIndex *index, - int bitNumber) +void +VFreeBitMapEntry(Error * ec, register struct vnodeIndex *index, + unsigned bitNumber) { - VOL_LOCK - VFreeBitMapEntry_r(ec, index, bitNumber); - VOL_UNLOCK -} + VOL_LOCK VFreeBitMapEntry_r(ec, index, bitNumber); +VOL_UNLOCK} -void VUpdateVolume_r(Error *ec,Volume *vp) +void +VUpdateVolume_r(Error * ec, Volume * vp) { *ec = 0; - if (programType == fileServer) - V_uniquifier(vp) = (V_inUse(vp)? V_nextVnodeUnique(vp) + 200: V_nextVnodeUnique(vp)); - /*printf("Writing volume header for '%s'\n", V_name(vp));*/ + if (programType == fileServer) + V_uniquifier(vp) = + (V_inUse(vp) ? V_nextVnodeUnique(vp) + + 200 : V_nextVnodeUnique(vp)); + /*printf("Writing volume header for '%s'\n", V_name(vp)); */ WriteVolumeHeader_r(ec, vp); if (*ec) { - Log( - "VUpdateVolume: error updating volume header, volume %u (%s)\n", + Log("VUpdateVolume: error updating volume header, volume %u (%s)\n", V_id(vp), V_name(vp)); - VForceOffline_r(vp); + VForceOffline_r(vp); } } -void VUpdateVolume(Error *ec, Volume *vp) +void +VUpdateVolume(Error * ec, Volume * vp) { - VOL_LOCK - VUpdateVolume_r(ec, vp); - VOL_UNLOCK -} + VOL_LOCK VUpdateVolume_r(ec, vp); +VOL_UNLOCK} -void VSyncVolume_r(Error *ec, Volume *vp) +void +VSyncVolume_r(Error * ec, Volume * vp) { FdHandle_t *fdP; VUpdateVolume_r(ec, vp); @@ -1385,20 +1385,19 @@ void VSyncVolume_r(Error *ec, Volume *vp) } } -void VSyncVolume(Error *ec, Volume *vp) +void +VSyncVolume(Error * ec, Volume * vp) { - VOL_LOCK - VSyncVolume_r(ec, vp); - VOL_UNLOCK -} + VOL_LOCK VSyncVolume_r(ec, vp); +VOL_UNLOCK} -static void FreeVolume(vp) - Volume *vp; +static void +FreeVolume(Volume * vp) { int i; if (!vp) - return; - for (i = 0; ivnodeIndex[i].bitmap) free(vp->vnodeIndex[i].bitmap); FreeVolumeHeader(vp); @@ -1406,12 +1405,12 @@ static void FreeVolume(vp) free(vp); } -static void GetBitmap(Error *ec, Volume *vp, VnodeClass class) +static void +GetBitmap(Error * ec, Volume * vp, VnodeClass class) { StreamHandle_t *file; int nVnodes; int size; - int counter = 0; struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; struct vnodeIndex *vip = &vp->vnodeIndex[class]; struct VnodeDiskObject *vnode; @@ -1424,20 +1423,20 @@ static void GetBitmap(Error *ec, Volume *vp, VnodeClass class) *ec = 0; fdP = IH_OPEN(vip->handle); - assert (fdP != NULL); + assert(fdP != NULL); file = FDH_FDOPEN(fdP, "r"); - assert (file != NULL); + assert(file != NULL); vnode = (VnodeDiskObject *) malloc(vcp->diskSize); assert(vnode != NULL); size = OS_SIZE(fdP->fd_fd); assert(size != -1); - nVnodes = (size <= vcp->diskSize? 0: size-vcp->diskSize) - >> vcp->logSize; - vip->bitmapSize = ((nVnodes/8)+10)/4*4; /* The 10 is a little extra so - a few files can be created in this volume, - the whole thing is rounded up to nearest 4 - bytes, because the bit map allocator likes - it that way */ + nVnodes = (size <= vcp->diskSize ? 0 : size - vcp->diskSize) + >> vcp->logSize; + vip->bitmapSize = ((nVnodes / 8) + 10) / 4 * 4; /* The 10 is a little extra so + * a few files can be created in this volume, + * the whole thing is rounded up to nearest 4 + * bytes, because the bit map allocator likes + * it that way */ #ifdef BITMAP_LATER BitMap = (byte *) calloc(1, vip->bitmapSize); assert(BitMap != NULL); @@ -1446,32 +1445,31 @@ static void GetBitmap(Error *ec, Volume *vp, VnodeClass class) assert(vip->bitmap != NULL); vip->bitmapOffset = 0; #endif /* BITMAP_LATER */ - if (STREAM_SEEK(file,vcp->diskSize,0) != -1) { - int bitNumber = 0; - for (bitNumber = 0; bitNumber < nVnodes+100; bitNumber++) { - if (STREAM_READ(vnode, vcp->diskSize, 1, file) != 1) - break; - if (vnode->type != vNull) { - if (vnode->vnodeMagic != vcp->magic) { - Log("GetBitmap: addled vnode index in volume %s; volume needs salvage\n", - V_name(vp)); - *ec = VSALVAGE; - break; - } + if (STREAM_SEEK(file, vcp->diskSize, 0) != -1) { + int bitNumber = 0; + for (bitNumber = 0; bitNumber < nVnodes + 100; bitNumber++) { + if (STREAM_READ(vnode, vcp->diskSize, 1, file) != 1) + break; + if (vnode->type != vNull) { + if (vnode->vnodeMagic != vcp->magic) { + Log("GetBitmap: addled vnode index in volume %s; volume needs salvage\n", V_name(vp)); + *ec = VSALVAGE; + break; + } #ifdef BITMAP_LATER - *(BitMap + (bitNumber>>3)) |= (1 << (bitNumber & 0x7)); + *(BitMap + (bitNumber >> 3)) |= (1 << (bitNumber & 0x7)); #else /* BITMAP_LATER */ - *(vip->bitmap + (bitNumber>>3)) |= (1 << (bitNumber & 0x7)); + *(vip->bitmap + (bitNumber >> 3)) |= (1 << (bitNumber & 0x7)); #endif /* BITMAP_LATER */ - if (unique <= vnode->uniquifier) - unique = vnode->uniquifier + 1; - } + if (unique <= vnode->uniquifier) + unique = vnode->uniquifier + 1; + } #ifndef AFS_PTHREAD_ENV - if ((bitNumber & 0x00ff) == 0x0ff) { /* every 256 iterations */ - IOMGR_Poll(); - } + if ((bitNumber & 0x00ff) == 0x0ff) { /* every 256 iterations */ + IOMGR_Poll(); + } #endif /* !AFS_PTHREAD_ENV */ - } + } } if (vp->nextVnodeUnique < unique) { Log("GetBitmap: bad volume uniquifier for volume %s; volume needs salvage\n", V_name(vp)); @@ -1490,15 +1488,15 @@ static void GetBitmap(Error *ec, Volume *vp, VnodeClass class) * the pointer to bitmap should already be filled and we can free ours. */ if (vip->bitmap == NULL) { - vip->bitmap = BitMap; - vip->bitmapOffset = 0; - } else - free((byte *)BitMap); + vip->bitmap = BitMap; + vip->bitmapOffset = 0; + } else + free((byte *) BitMap); #endif /* BITMAP_LATER */ } -static void GetVolumePath(Error *ec, VolId volumeId, char **partitionp, - char **namep) +static void +GetVolumePath(Error * ec, VolId volumeId, char **partitionp, char **namep) { static char partition[VMAXPATHLEN], name[VMAXPATHLEN]; char path[VMAXPATHLEN]; @@ -1507,48 +1505,47 @@ static void GetVolumePath(Error *ec, VolId volumeId, char **partitionp, *ec = 0; name[0] = '/'; - sprintf(&name[1],VFORMAT,volumeId); + (void)afs_snprintf(&name[1], (sizeof name) - 1, VFORMAT, volumeId); for (dp = DiskPartitionList; dp; dp = dp->next) { - struct stat status; - strcpy(path, VPartitionPath(dp)); + struct afs_stat status; + strcpy(path, VPartitionPath(dp)); strcat(path, name); - if (stat(path,&status) == 0) { + if (afs_stat(path, &status) == 0) { strcpy(partition, dp->name); found = 1; break; } } if (!found) { - *ec = VNOVOL; + *ec = VNOVOL; *partitionp = *namep = NULL; - } - else { + } else { *partitionp = partition; - *namep = name; + *namep = name; } -} +} -VolumeNumber(name) - char *name; +int +VolumeNumber(char *name) { if (*name == '/') - name++; - return atoi(name+1); + name++; + return atoi(name + 1); } -char *VolumeExternalName(volumeId) - VolumeId volumeId; +char * +VolumeExternalName(VolumeId volumeId) { - static char name[15]; - sprintf(name,VFORMAT,volumeId); + static char name[VMAXPATHLEN]; + (void)afs_snprintf(name, sizeof name, VFORMAT, volumeId); return name; } -#if TRANSARC_VOL_STATS -#define OneDay (86400) /* 24 hours' worth of seconds */ +#if OPENAFS_VOL_STATS +#define OneDay (86400) /* 24 hours' worth of seconds */ #else -#define OneDay (24*60*60) /* 24 hours */ -#endif /* TRANSARC_VOL_STATS */ +#define OneDay (24*60*60) /* 24 hours */ +#endif /* OPENAFS_VOL_STATS */ #define Midnight(date) ((date-TimeZoneCorrection)/OneDay*OneDay+TimeZoneCorrection) @@ -1574,55 +1571,50 @@ char *VolumeExternalName(volumeId) * As described. *------------------------------------------------------------------------*/ -VAdjustVolumeStatistics_r(vp) - register Volume *vp; - -{ /*VAdjustVolumeStatistics*/ - +int +VAdjustVolumeStatistics_r(register Volume * vp) +{ unsigned int now = FT_ApproxTime(); if (now - V_dayUseDate(vp) > OneDay) { - register ndays, i; + register ndays, i; ndays = (now - V_dayUseDate(vp)) / OneDay; - for (i = 6; i>ndays-1; i--) - V_weekUse(vp)[i] = V_weekUse(vp)[i-ndays]; - for (i = 0; i ndays - 1; i--) + V_weekUse(vp)[i] = V_weekUse(vp)[i - ndays]; + for (i = 0; i < ndays - 1 && i < 7; i++) V_weekUse(vp)[i] = 0; if (ndays <= 7) - V_weekUse(vp)[ndays-1] = V_dayUse(vp); + V_weekUse(vp)[ndays - 1] = V_dayUse(vp); V_dayUse(vp) = 0; V_dayUseDate(vp) = Midnight(now); -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS /* * All we need to do is bzero the entire VOL_STATS_BYTES of * the detailed volume statistics area. */ memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES); -#endif /* TRANSARC_VOL_STATS */ - } /*It's been more than a day of collection*/ +#endif /* OPENAFS_VOL_STATS */ + } -#if TRANSARC_VOL_STATS + /*It's been more than a day of collection */ /* * Always return happily. */ - return(0); -#endif /* TRANSARC_VOL_STATS */ + return (0); +} /*VAdjustVolumeStatistics */ -} /*VAdjustVolumeStatistics*/ - -VAdjustVolumeStatistics(vp) - register Volume *vp; +int +VAdjustVolumeStatistics(register Volume * vp) { int retVal; - VOL_LOCK - VAdjustVolumeStatistics_r(vp); - VOL_UNLOCK - return retVal; + VOL_LOCK retVal = VAdjustVolumeStatistics_r(vp); + VOL_UNLOCK return retVal; } -void VBumpVolumeUsage_r(register Volume *vp) +void +VBumpVolumeUsage_r(register Volume * vp) { unsigned int now = FT_ApproxTime(); if (now - V_dayUseDate(vp) > OneDay) @@ -1636,41 +1628,40 @@ void VBumpVolumeUsage_r(register Volume *vp) } } -void VBumpVolumeUsage(register Volume *vp) +void +VBumpVolumeUsage(register Volume * vp) { - VOL_LOCK - VBumpVolumeUsage_r(vp); - VOL_UNLOCK -} + VOL_LOCK VBumpVolumeUsage_r(vp); +VOL_UNLOCK} -void VSetDiskUsage_r(void) +void +VSetDiskUsage_r(void) { static int FifteenMinuteCounter = 0; - + while (VInit < 2) { - /* NOTE: Don't attempt to access the partitions list until the - initialization level indicates that all volumes are attached, - which implies that all partitions are initialized. */ + /* NOTE: Don't attempt to access the partitions list until the + * initialization level indicates that all volumes are attached, + * which implies that all partitions are initialized. */ #ifdef AFS_PTHREAD_ENV - sleep(10); + sleep(10); #else /* AFS_PTHREAD_ENV */ - IOMGR_Sleep(10); + IOMGR_Sleep(10); #endif /* AFS_PTHREAD_ENV */ } VResetDiskUsage_r(); if (++FifteenMinuteCounter == 3) { FifteenMinuteCounter = 0; - VScanUpdateList(); + VScanUpdateList(); } } -void VSetDiskUsage(void) +void +VSetDiskUsage(void) { - VOL_LOCK - VSetDiskUsage_r(); - VOL_UNLOCK -} + VOL_LOCK VSetDiskUsage_r(); +VOL_UNLOCK} /* The number of minutes that a volume hasn't been updated before the * "Dont salvage" flag in the volume header will be turned on */ @@ -1681,7 +1672,8 @@ static int nUpdatedVolumes; /* Updated with entry in UpdateList, salvage after c static int updateSize; /* number of entries possible */ #define UPDATE_LIST_SIZE 100 /* size increment */ -void VAddToVolumeUpdateList_r(Error *ec, Volume *vp) +void +VAddToVolumeUpdateList_r(Error * ec, Volume * vp) { *ec = 0; vp->updateTime = FT_ApproxTime(); @@ -1693,29 +1685,34 @@ void VAddToVolumeUpdateList_r(Error *ec, Volume *vp) return; if (!UpdateList) { updateSize = UPDATE_LIST_SIZE; - UpdateList = (VolumeId *) malloc(sizeof (VolumeId) * updateSize); + UpdateList = (VolumeId *) malloc(sizeof(VolumeId) * updateSize); } else { if (nUpdatedVolumes == updateSize) { updateSize += UPDATE_LIST_SIZE; - UpdateList = (VolumeId *) realloc(UpdateList, sizeof (VolumeId) * updateSize); + UpdateList = + (VolumeId *) realloc(UpdateList, + sizeof(VolumeId) * updateSize); } } + assert(UpdateList != NULL); UpdateList[nUpdatedVolumes++] = V_id(vp); } -static void VScanUpdateList() { +static void +VScanUpdateList(void) +{ register int i, gap; register Volume *vp; Error error; - afs_int32 now = FT_ApproxTime(); + afs_uint32 now = FT_ApproxTime(); /* Be careful with this code, since it works with interleaved calls to AddToVolumeUpdateList */ - for (i = gap = 0; inUsers == 1 && now - vp->updateTime > SALVAGE_INTERVAL) { V_dontSalvage(vp) = DONT_SALVAGE; - VUpdateVolume_r(&error, vp); /* No need to fsync--not critical */ + VUpdateVolume_r(&error, vp); /* No need to fsync--not critical */ gap++; } if (vp) @@ -1734,8 +1731,8 @@ static void VScanUpdateList() { static struct volHeader *volumeLRU; /* Allocate a bunch of headers; string them together */ -static void InitLRU(howMany) -int howMany; +static void +InitLRU(int howMany) { register struct volHeader *hp; if (programType != fileServer) @@ -1747,8 +1744,8 @@ int howMany; /* Get a volume header from the LRU list; update the old one if necessary */ /* Returns 1 if there was already a header, which is removed from the LRU list */ -static int GetVolumeHeader(vp) -register Volume *vp; +static int +GetVolumeHeader(register Volume * vp) { Error error; register struct volHeader *hd; @@ -1758,28 +1755,28 @@ register Volume *vp; old = (vp->header != 0); /* old == volume already has a header */ if (programType != fileServer) { if (!vp->header) { - hd = (struct volHeader *) calloc(1, sizeof(*vp->header)); + hd = (struct volHeader *)calloc(1, sizeof(*vp->header)); assert(hd != 0); vp->header = hd; hd->back = vp; } - } - else { + } else { if (old) { hd = vp->header; if (volumeLRU == hd) volumeLRU = hd->next; assert(hd->back == vp); - } - else { + } else { if (volumeLRU) - hd = volumeLRU->prev; /* not currently in use and least recently used */ + /* not currently in use and least recently used */ + hd = volumeLRU->prev; else { - hd = (struct volHeader *) calloc(1, sizeof(*vp->header)); - hd->prev = hd->next = hd; /* make it look like single elt LRU */ + hd = (struct volHeader *)calloc(1, sizeof(*vp->header)); + /* make it look like single elt LRU */ + hd->prev = hd->next = hd; if (!everLogged) { Log("****Allocated more volume headers, probably leak****\n"); - everLogged=1; + everLogged = 1; } } if (hd->back) { @@ -1790,49 +1787,48 @@ register Volume *vp; hd->back->header = 0; } hd->back = vp; - vp->header = hd; + vp->header = hd; } - if (hd->next) { /* hd->next != 0 --> in LRU chain (we zero it later) */ + if (hd->next) { /* hd->next != 0 --> in LRU chain (we zero it later) */ hd->prev->next = hd->next; /* pull hd out of LRU list */ hd->next->prev = hd->prev; /* if hd only element, this is noop */ } - hd->next = hd->prev = 0; + hd->next = hd->prev = 0; /* if not in LRU chain, next test won't be true */ if (hd == volumeLRU) /* last header item, turn into empty list */ - volumeLRU = (struct volHeader *) 0; + volumeLRU = NULL; } return old; } /* Put it at the top of the LRU chain */ -static void ReleaseVolumeHeader(hd) - register struct volHeader *hd; +static void +ReleaseVolumeHeader(register struct volHeader *hd) { if (programType != fileServer) return; - if (!hd || hd->next) /* no header, or header already released */ + if (!hd || hd->next) /* no header, or header already released */ return; if (!volumeLRU) { hd->next = hd->prev = hd; } else { hd->prev = volumeLRU->prev; hd->next = volumeLRU; - hd->prev->next = hd->next->prev = hd; + hd->prev->next = hd->next->prev = hd; } volumeLRU = hd; } -static void FreeVolumeHeader(vp) -register Volume *vp; +static void +FreeVolumeHeader(register Volume * vp) { register struct volHeader *hd = vp->header; if (!hd) return; if (programType == fileServer) { ReleaseVolumeHeader(hd); - hd->back = 0; - } - else { + hd->back = 0; + } else { free(hd); } vp->header = 0; @@ -1843,18 +1839,18 @@ register Volume *vp; /* Routines to add volume to hash chain, delete it */ /***************************************************/ -static void AddVolumeToHashTable(vp, hashid) -register Volume *vp; +static void +AddVolumeToHashTable(register Volume * vp, int hashid) { int hash = VOLUME_HASH(hashid); vp->hashid = hashid; vp->hashNext = VolumeHashTable[hash]; VolumeHashTable[hash] = vp; vp->vnodeHashOffset = VolumeHashOffset_r(); -} +} -static void DeleteVolumeFromHashTable(vp) -register Volume *vp; +static void +DeleteVolumeFromHashTable(register Volume * vp) { int hash = VOLUME_HASH(vp->hashid); if (VolumeHashTable[hash] == vp) @@ -1872,23 +1868,20 @@ register Volume *vp; vp->hashid = 0; } -void VPrintCacheStats_r(void) +void +VPrintCacheStats_r(void) { register struct VnodeClassInfo *vcp; vcp = &VnodeClassInfo[vLarge]; - Log("Large vnode cache, %d entries, %d allocs, %d gets (%d reads), %d writes\n", - vcp->cacheSize, vcp->allocs, vcp->gets, vcp->reads, vcp->writes); + Log("Large vnode cache, %d entries, %d allocs, %d gets (%d reads), %d writes\n", vcp->cacheSize, vcp->allocs, vcp->gets, vcp->reads, vcp->writes); vcp = &VnodeClassInfo[vSmall]; - Log("Small vnode cache,%d entries, %d allocs, %d gets (%d reads), %d writes\n", - vcp->cacheSize, vcp->allocs, vcp->gets, vcp->reads, vcp->writes); + Log("Small vnode cache,%d entries, %d allocs, %d gets (%d reads), %d writes\n", vcp->cacheSize, vcp->allocs, vcp->gets, vcp->reads, vcp->writes); Log("Volume header cache, %d entries, %d gets, %d replacements\n", VolumeCacheSize, VolumeGets, VolumeReplacements); } -void VPrintCacheStats(void) +void +VPrintCacheStats(void) { - VOL_LOCK - VPrintCacheStats_r(); - VOL_UNLOCK -} - + VOL_LOCK VPrintCacheStats_r(); +VOL_UNLOCK} diff --git a/src/vol/volume.h b/src/vol/volume.h index cd155457b..c0756092d 100644 --- a/src/vol/volume.h +++ b/src/vol/volume.h @@ -22,7 +22,7 @@ #include "ihandle.h" #define VolumeWriteable(vp) (V_type(vp)==readwriteVolume) #define VolumeWriteable2(vol) (vol.type == readwriteVolume) -typedef bit32 FileOffset; /* Offset in this file */ +typedef bit32 FileOffset; /* Offset in this file */ #define Date afs_uint32 #ifdef AFS_PTHREAD_ENV @@ -30,6 +30,8 @@ typedef bit32 FileOffset; /* Offset in this file */ #include extern pthread_mutex_t vol_glock_mutex; extern pthread_mutex_t vol_attach_mutex; +extern pthread_mutex_t vol_fsync_mutex; +extern pthread_mutex_t vol_trans_mutex; extern pthread_cond_t vol_put_volume_cond; extern pthread_cond_t vol_sleep_cond; #define VATTACH_LOCK \ @@ -40,31 +42,43 @@ extern pthread_cond_t vol_sleep_cond; assert(pthread_mutex_lock(&vol_glock_mutex) == 0); #define VOL_UNLOCK \ assert(pthread_mutex_unlock(&vol_glock_mutex) == 0); +#define VFSYNC_LOCK \ + assert(pthread_mutex_lock(&vol_fsync_mutex) == 0); +#define VFSYNC_UNLOCK \ + assert(pthread_mutex_unlock(&vol_fsync_mutex) == 0); +#define VTRANS_LOCK \ + assert(pthread_mutex_lock(&vol_trans_mutex) == 0); +#define VTRANS_UNLOCK \ + assert(pthread_mutex_unlock(&vol_trans_mutex) == 0); #else /* AFS_PTHREAD_ENV */ #define VATTACH_LOCK #define VATTACH_UNLOCK #define VOL_LOCK #define VOL_UNLOCK +#define VFSYNC_LOCK +#define VFSYNC_UNLOCK +#define VTRANS_LOCK +#define VTRANS_UNLOCK #endif /* AFS_PTHREAD_ENV */ -typedef enum {fileServer, volumeUtility, salvager} ProgramType; +typedef enum { fileServer, volumeUtility, salvager } ProgramType; extern ProgramType programType; /* The type of program using the package */ /* Some initialization parameters for the volume package */ /* Add new initialization parameters here */ -extern int (*V_BreakVolumeCallbacks)(); -extern int (*vol_PollProc)(); +extern int (*V_BreakVolumeCallbacks) (); +extern int (*vol_PollProc) (); #define DOPOLL ((vol_PollProc)? (*vol_PollProc)() : 0) struct versionStamp { /* Version stamp for critical volume files */ - bit32 magic; /* Magic number */ - bit32 version; /* Version number of this file, or software - that created this file */ + bit32 magic; /* Magic number */ + bit32 version; /* Version number of this file, or software + * that created this file */ }; /* Magic numbers and version stamps for each type of file */ -#define VOLUMEHEADERMAGIC 0x88a1bb3c -#define VOLUMEINFOMAGIC 0x78a1b2c5 +#define VOLUMEHEADERMAGIC ((bit32)0x88a1bb3c) +#define VOLUMEINFOMAGIC ((bit32)0x78a1b2c5) #define SMALLINDEXMAGIC 0x99776655 #define LARGEINDEXMAGIC 0x88664433 #define MOUNTMAGIC 0x9a8b7c6d @@ -82,75 +96,75 @@ struct versionStamp { /* Version stamp for critical volume files */ /* * Define whether we are keeping detailed statistics on volume dealings. */ -#define TRANSARC_VOL_STATS 1 +#define OPENAFS_VOL_STATS 1 -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS /* * Define various indices and counts used in keeping volume-level statistics. */ #define VOL_STATS_NUM_RWINFO_FIELDS 4 -#define VOL_STATS_SAME_NET 0 /*Within same site (total)*/ +#define VOL_STATS_SAME_NET 0 /*Within same site (total) */ #define VOL_STATS_SAME_NET_AUTH 1 /*Within same site (authenticated); - (must be 1 more than above)*/ -#define VOL_STATS_DIFF_NET 2 /*From external site (total)*/ + * (must be 1 more than above) */ +#define VOL_STATS_DIFF_NET 2 /*From external site (total) */ #define VOL_STATS_DIFF_NET_AUTH 3 /*From external site (authenticated) - (must be 1 more than above)*/ + * (must be 1 more than above) */ #define VOL_STATS_NUM_TIME_RANGES 6 -#define VOL_STATS_TIME_CAP_0 60 /*60 seconds*/ -#define VOL_STATS_TIME_CAP_1 600 /*10 minutes, in seconds*/ -#define VOL_STATS_TIME_CAP_2 3600 /*1 hour, in seconds*/ -#define VOL_STATS_TIME_CAP_3 86400 /*1 day, in seconds*/ -#define VOL_STATS_TIME_CAP_4 604800 /*1 week, in seconds*/ +#define VOL_STATS_TIME_CAP_0 60 /*60 seconds */ +#define VOL_STATS_TIME_CAP_1 600 /*10 minutes, in seconds */ +#define VOL_STATS_TIME_CAP_2 3600 /*1 hour, in seconds */ +#define VOL_STATS_TIME_CAP_3 86400 /*1 day, in seconds */ +#define VOL_STATS_TIME_CAP_4 604800 /*1 week, in seconds */ #define VOL_STATS_NUM_TIME_FIELDS 6 -#define VOL_STATS_TIME_IDX_0 0 /*0 secs to 60 secs*/ -#define VOL_STATS_TIME_IDX_1 1 /*1 min to 10 mins*/ -#define VOL_STATS_TIME_IDX_2 2 /*10 mins to 60 mins*/ -#define VOL_STATS_TIME_IDX_3 3 /*1 hr to 24 hrs*/ -#define VOL_STATS_TIME_IDX_4 4 /*1 day to 7 days*/ -#define VOL_STATS_TIME_IDX_5 5 /*Greater than 1 week*/ -#endif /* TRANSARC_VOL_STATS */ +#define VOL_STATS_TIME_IDX_0 0 /*0 secs to 60 secs */ +#define VOL_STATS_TIME_IDX_1 1 /*1 min to 10 mins */ +#define VOL_STATS_TIME_IDX_2 2 /*10 mins to 60 mins */ +#define VOL_STATS_TIME_IDX_3 3 /*1 hr to 24 hrs */ +#define VOL_STATS_TIME_IDX_4 4 /*1 day to 7 days */ +#define VOL_STATS_TIME_IDX_5 5 /*Greater than 1 week */ +#endif /* OPENAFS_VOL_STATS */ /* Volume header. This is the contents of the named file representing * the volume. Read-only by the file server! */ typedef struct VolumeHeader { - struct versionStamp stamp;/* Must be first field */ - VolumeId id; /* Volume number */ - VolumeId parent; /* Read-write volume number (or this volume - number if this is a read-write volume) */ - Inode volumeInfo; - Inode smallVnodeIndex; - Inode largeVnodeIndex; - Inode volumeAcl; - Inode volumeMountTable; - Inode linkTable; + struct versionStamp stamp; /* Must be first field */ + VolumeId id; /* Volume number */ + VolumeId parent; /* Read-write volume number (or this volume + * number if this is a read-write volume) */ + Inode volumeInfo; + Inode smallVnodeIndex; + Inode largeVnodeIndex; + Inode volumeAcl; + Inode volumeMountTable; + Inode linkTable; } VolumeHeader_t; typedef struct VolumeDiskHeader { - struct versionStamp stamp;/* Must be first field */ - VolumeId id; /* Volume number */ - VolumeId parent; /* Read-write volume number (or this volume - number if this is a read-write volume) */ - afs_int32 volumeInfo_lo; - afs_int32 smallVnodeIndex_lo; - afs_int32 largeVnodeIndex_lo; - afs_int32 volumeAcl_lo; - afs_int32 volumeMountTable_lo; - afs_int32 volumeInfo_hi; - afs_int32 smallVnodeIndex_hi; - afs_int32 largeVnodeIndex_hi; - afs_int32 volumeAcl_hi; - afs_int32 volumeMountTable_hi; - afs_int32 linkTable_lo; - afs_int32 linkTable_hi; + struct versionStamp stamp; /* Must be first field */ + VolumeId id; /* Volume number */ + VolumeId parent; /* Read-write volume number (or this volume + * number if this is a read-write volume) */ + afs_int32 volumeInfo_lo; + afs_int32 smallVnodeIndex_lo; + afs_int32 largeVnodeIndex_lo; + afs_int32 volumeAcl_lo; + afs_int32 volumeMountTable_lo; + afs_int32 volumeInfo_hi; + afs_int32 smallVnodeIndex_hi; + afs_int32 largeVnodeIndex_hi; + afs_int32 volumeAcl_hi; + afs_int32 volumeMountTable_hi; + afs_int32 linkTable_lo; + afs_int32 linkTable_hi; /* If you add fields, add them before here and reduce the size of array */ - bit32 reserved[3]; + bit32 reserved[3]; } VolumeDiskHeader_t; /* A vnode index file header */ @@ -164,117 +178,117 @@ struct IndexFileHeader { /******************************************************************************/ typedef struct VolumeDiskData { struct versionStamp stamp; /* Must be first field */ - VolumeId id; /* Volume id--unique over all systems */ + VolumeId id; /* Volume id--unique over all systems */ #define VNAMESIZE 32 /* including 0 byte */ - char name[VNAMESIZE];/* Unofficial name for the volume */ - byte inUse; /* Volume is being used (perhaps it is online), - or the system crashed while it was used */ - byte inService; /* Volume in service, not necessarily on line - This bit is set by an operator/system - programmer. Manually taking a volume offline - always clears the inService bit. Taking - it out of service also takes it offline */ - byte blessed; /* Volume is administratively blessed with - the ability to go on line. Set by a system - administrator. Clearing this bit will - take the volume offline */ - byte needsSalvaged; /* Volume needs salvaged--an unrecoverable - error occured to the volume. Note: a volume - may still require salvage even if this - flag isn't set--e.g. if a system crash - occurred while the volume was on line. */ - bit32 uniquifier; /* Next vnode uniquifier for this volume */ - int type; /* */ - VolId parentId; /* Id of parent, if type==readonly */ - VolId cloneId; /* Latest read-only clone, if type==readwrite, - 0 if the volume has never been cloned. Note: the - indicated volume does not necessarily exist (it - may have been deleted since cloning). */ - VolId backupId; /* Latest backup copy of this read write volume */ - VolId restoredFromId; /* The id in the dump this volume was restored from--used simply - to make sure that an incremental dump is not restored on top - of something inappropriate: Note: this field itself is NEVER - dumped!!! */ - byte needsCallback; /* Set by the salvager if anything was changed - about the volume. Note: this is not set by - clone/makebackups when setting the copy-on-write - flag in directories; this flag is not seen by - the clients. */ + char name[VNAMESIZE]; /* Unofficial name for the volume */ + byte inUse; /* Volume is being used (perhaps it is online), + * or the system crashed while it was used */ + byte inService; /* Volume in service, not necessarily on line + * This bit is set by an operator/system + * programmer. Manually taking a volume offline + * always clears the inService bit. Taking + * it out of service also takes it offline */ + byte blessed; /* Volume is administratively blessed with + * the ability to go on line. Set by a system + * administrator. Clearing this bit will + * take the volume offline */ + byte needsSalvaged; /* Volume needs salvaged--an unrecoverable + * error occured to the volume. Note: a volume + * may still require salvage even if this + * flag isn't set--e.g. if a system crash + * occurred while the volume was on line. */ + bit32 uniquifier; /* Next vnode uniquifier for this volume */ + int type; /* */ + VolId parentId; /* Id of parent, if type==readonly */ + VolId cloneId; /* Latest read-only clone, if type==readwrite, + * 0 if the volume has never been cloned. Note: the + * indicated volume does not necessarily exist (it + * may have been deleted since cloning). */ + VolId backupId; /* Latest backup copy of this read write volume */ + VolId restoredFromId; /* The id in the dump this volume was restored from--used simply + * to make sure that an incremental dump is not restored on top + * of something inappropriate: Note: this field itself is NEVER + * dumped!!! */ + byte needsCallback; /* Set by the salvager if anything was changed + * about the volume. Note: this is not set by + * clone/makebackups when setting the copy-on-write + * flag in directories; this flag is not seen by + * the clients. */ #define DESTROY_ME 0xD3 - byte destroyMe; /* If this is set to DESTROY_ME, then the salvager should destroy - this volume; it is bogus (left over from an aborted volume move, - for example). Note: if this flag is on, then inService should - be OFF--only the salvager checks this flag */ + byte destroyMe; /* If this is set to DESTROY_ME, then the salvager should destroy + * this volume; it is bogus (left over from an aborted volume move, + * for example). Note: if this flag is on, then inService should + * be OFF--only the salvager checks this flag */ #ifdef ALPHA_DUX40_ENV #define DONT_SALVAGE 0xE6 -#else /* ALPHA_DUX40_ENV */ +#else /* ALPHA_DUX40_ENV */ #define DONT_SALVAGE 0xE5 -#endif /* ALPHA_DUX40_ENV */ - byte dontSalvage; /* If this is on, then don't bother salvaging this volume*/ - byte reserveb3; +#endif /* ALPHA_DUX40_ENV */ + byte dontSalvage; /* If this is on, then don't bother salvaging this volume */ + byte reserveb3; - bit32 reserved1[6]; + bit32 reserved1[6]; /* Administrative stuff */ - int maxquota; /* Quota maximum, 1K blocks */ - int minquota; /* Quota minimum, 1K blocks */ - int maxfiles; /* Maximum number of files (i.e. inodes) */ - bit32 accountNumber; /* Uninterpreted account number */ - bit32 owner; /* The person administratively responsible - for this volume */ - int reserved2[8]; /* Other administrative constraints */ + int maxquota; /* Quota maximum, 1K blocks */ + int minquota; /* Quota minimum, 1K blocks */ + int maxfiles; /* Maximum number of files (i.e. inodes) */ + bit32 accountNumber; /* Uninterpreted account number */ + bit32 owner; /* The person administratively responsible + * for this volume */ + int reserved2[8]; /* Other administrative constraints */ /* Resource usage & statistics */ - int filecount; /* Actual number of files */ - int diskused; /* Actual disk space used, 1K blocks */ - int dayUse; /* Metric for today's usage of this volume so far */ - int weekUse[7]; /* Usage of the volume for the last week. - weekUse[0] is for most recent complete 24 hour period - of measurement; week[6] is 7 days ago */ - Date dayUseDate; /* Date the dayUse statistics refer to; the week use stats - are the preceding 7 days */ - int reserved3[11]; /* Other stats here */ - + int filecount; /* Actual number of files */ + int diskused; /* Actual disk space used, 1K blocks */ + int dayUse; /* Metric for today's usage of this volume so far */ + int weekUse[7]; /* Usage of the volume for the last week. + * weekUse[0] is for most recent complete 24 hour period + * of measurement; week[6] is 7 days ago */ + Date dayUseDate; /* Date the dayUse statistics refer to; the week use stats + * are the preceding 7 days */ + int reserved3[11]; /* Other stats here */ + /* Server supplied dates */ - Date creationDate; /* Creation date for a read/write - volume; cloning date for original copy of - a readonly volume (replicated volumes have - the same creation date) */ - Date accessDate; /* Last access time by a user, large granularity */ - Date updateDate; /* Last modification by user */ - Date expirationDate; /* 0 if it never expires */ - Date backupDate; /* last time a backup clone was taken */ + Date creationDate; /* Creation date for a read/write + * volume; cloning date for original copy of + * a readonly volume (replicated volumes have + * the same creation date) */ + Date accessDate; /* Last access time by a user, large granularity */ + Date updateDate; /* Last modification by user */ + Date expirationDate; /* 0 if it never expires */ + Date backupDate; /* last time a backup clone was taken */ /* Time that this copy of this volume was made. NEVER backed up. This field is only - set when the copy is created */ - Date copyDate; + * set when the copy is created */ + Date copyDate; -#if TRANSARC_VOL_STATS - bit32 stat_initialized; /*Are the stat fields below set up?*/ - bit32 reserved4[7]; +#if OPENAFS_VOL_STATS + bit32 stat_initialized; /*Are the stat fields below set up? */ + bit32 reserved4[7]; #else - bit32 reserved4[8]; -#endif /* TRANSARC_VOL_STATS */ + bit32 reserved4[8]; +#endif /* OPENAFS_VOL_STATS */ /* messages */ #define VMSGSIZE 128 - char offlineMessage[VMSGSIZE]; /* Why the volume is offline */ -#if TRANSARC_VOL_STATS + char offlineMessage[VMSGSIZE]; /* Why the volume is offline */ +#if OPENAFS_VOL_STATS #define VOL_STATS_BYTES 128 - /* - * Keep per-volume aggregate statistics on type and distance of access, - * along with authorship info. - */ - bit32 stat_reads[VOL_STATS_NUM_RWINFO_FIELDS]; - bit32 stat_writes[VOL_STATS_NUM_RWINFO_FIELDS]; - bit32 stat_fileSameAuthor[VOL_STATS_NUM_TIME_FIELDS]; - bit32 stat_fileDiffAuthor[VOL_STATS_NUM_TIME_FIELDS]; - bit32 stat_dirSameAuthor[VOL_STATS_NUM_TIME_FIELDS]; - bit32 stat_dirDiffAuthor[VOL_STATS_NUM_TIME_FIELDS]; + /* + * Keep per-volume aggregate statistics on type and distance of access, + * along with authorship info. + */ + bit32 stat_reads[VOL_STATS_NUM_RWINFO_FIELDS]; + bit32 stat_writes[VOL_STATS_NUM_RWINFO_FIELDS]; + bit32 stat_fileSameAuthor[VOL_STATS_NUM_TIME_FIELDS]; + bit32 stat_fileDiffAuthor[VOL_STATS_NUM_TIME_FIELDS]; + bit32 stat_dirSameAuthor[VOL_STATS_NUM_TIME_FIELDS]; + bit32 stat_dirDiffAuthor[VOL_STATS_NUM_TIME_FIELDS]; #else - char motd[VMSGSIZE]; /* Volume "message of the day" */ -#endif /* TRANSARC_VOL_STATS */ + char motd[VMSGSIZE]; /* Volume "message of the day" */ +#endif /* OPENAFS_VOL_STATS */ } VolumeDiskData; @@ -283,51 +297,51 @@ typedef struct VolumeDiskData { /* Memory resident volume information */ /**************************************/ typedef struct Volume { - struct Volume *hashNext; /* Next in hash resolution table */ - VolumeId hashid; /* Volume number -- for hash table lookup */ - struct volHeader *header; /* Cached disk data */ - Device device; /* Unix device for the volume */ + struct Volume *hashNext; /* Next in hash resolution table */ + VolumeId hashid; /* Volume number -- for hash table lookup */ + struct volHeader *header; /* Cached disk data */ + Device device; /* Unix device for the volume */ struct DiskPartition - *partition; /* Information about the Unix partition */ + *partition; /* Information about the Unix partition */ struct vnodeIndex { - IHandle_t *handle; /* Unix inode holding this index */ - byte *bitmap; /* Index bitmap */ - afs_uint32 bitmapSize; /* length of bitmap, in bytes */ - afs_uint32 bitmapOffset; /* Which byte address of the first long to - start search from in bitmap */ + IHandle_t *handle; /* Unix inode holding this index */ + byte *bitmap; /* Index bitmap */ + afs_uint32 bitmapSize; /* length of bitmap, in bytes */ + afs_uint32 bitmapOffset; /* Which byte address of the first long to + * start search from in bitmap */ } vnodeIndex[nVNODECLASSES]; - IHandle_t *linkHandle; - Unique nextVnodeUnique;/* Derived originally from volume uniquifier. - This is the actual next version number to - assign; the uniquifier is bumped by 200 and - and written to disk every 200 file creates - If the volume is shutdown gracefully, the - uniquifier should be rewritten with the - value nextVnodeVersion*/ - IHandle_t *diskDataHandle;/* Unix inode holding general volume info */ - bit16 vnodeHashOffset;/* Computed by HashOffset function in vnode.h. - Assigned to the volume when initialized. - Added to vnode number for hash table index */ - byte shuttingDown; /* This volume is going to be detached */ - byte goingOffline; /* This volume is going offline */ - bit16 cacheCheck; /* Online sequence number to be used to invalidate vnode cache entries - that stayed around while a volume was offline */ - short nUsers; /* Number of users of this volume header */ - byte needsPutBack; /* For a volume utility, this flag is set if we need - to give the volume back when we detach it. The server has - certain modes where it doesn't detach the volume, and - if we give it back spuriously, the server aborts. This field - is meaningless on the file server */ - byte specialStatus; /* An error code to return on VGetVolume: the - volume is unavailable for the reason quoted, - currently VBUSY or VMOVED */ - afs_int32 updateTime; /* Time that this volume was put on the updated - volume list--the list of volumes that will be - salvaged should the file server crash */ + IHandle_t *linkHandle; + Unique nextVnodeUnique; /* Derived originally from volume uniquifier. + * This is the actual next version number to + * assign; the uniquifier is bumped by 200 and + * and written to disk every 200 file creates + * If the volume is shutdown gracefully, the + * uniquifier should be rewritten with the + * value nextVnodeVersion */ + IHandle_t *diskDataHandle; /* Unix inode holding general volume info */ + bit16 vnodeHashOffset; /* Computed by HashOffset function in vnode.h. + * Assigned to the volume when initialized. + * Added to vnode number for hash table index */ + byte shuttingDown; /* This volume is going to be detached */ + byte goingOffline; /* This volume is going offline */ + bit32 cacheCheck; /* Online sequence number to be used to invalidate vnode cache entries + * that stayed around while a volume was offline */ + short nUsers; /* Number of users of this volume header */ + byte needsPutBack; /* For a volume utility, this flag is set if we need + * to give the volume back when we detach it. The server has + * certain modes where it doesn't detach the volume, and + * if we give it back spuriously, the server aborts. This field + * is meaningless on the file server */ + byte specialStatus; /* An error code to return on VGetVolume: the + * volume is unavailable for the reason quoted, + * currently VBUSY or VMOVED */ + afs_uint32 updateTime; /* Time that this volume was put on the updated + * volume list--the list of volumes that will be + * salvaged should the file server crash */ } Volume; struct volHeader { - struct volHeader *prev, *next;/* LRU pointers */ + struct volHeader *prev, *next; /* LRU pointers */ VolumeDiskData diskstuff; /* General volume info read from disk */ Volume *back; /* back pointer to current volume structure */ }; @@ -378,7 +392,7 @@ struct volHeader { #define V_offlineMessage(vp) ((vp)->header->diskstuff.offlineMessage) #define V_disk(vp) ((vp)->header->diskstuff) #define V_motd(vp) ((vp)->header->diskstuff.motd) -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS #define V_stat_initialized(vp) ((vp)->header->diskstuff.stat_initialized) #define V_stat_area(vp) (((vp)->header->diskstuff.stat_reads)) #define V_stat_reads(vp, idx) (((vp)->header->diskstuff.stat_reads)[idx]) @@ -387,7 +401,7 @@ struct volHeader { #define V_stat_fileDiffAuthor(vp, idx) (((vp)->header->diskstuff.stat_fileDiffAuthor)[idx]) #define V_stat_dirSameAuthor(vp, idx) (((vp)->header->diskstuff.stat_dirSameAuthor)[idx]) #define V_stat_dirDiffAuthor(vp, idx) (((vp)->header->diskstuff.stat_dirDiffAuthor)[idx]) -#endif /* TRANSARC_VOL_STATS */ +#endif /* OPENAFS_VOL_STATS */ /* File offset computations. The offset values in the volume header are computed with these macros -- when the file is written only!! */ @@ -397,85 +411,92 @@ struct volHeader { extern char *VSalvageMessage; /* Canonical message when a volume is forced - offline */ -extern Volume * VGetVolume(); -extern Volume * VGetVolume_r(); + * offline */ +extern Volume *VGetVolume(Error * ec, VolId volumeId); +extern Volume *VGetVolume_r(Error * ec, VolId volumeId); extern void VPutVolume(Volume *); extern void VPutVolume_r(Volume *); -extern void VOffline(Volume *vp, char *message); -extern void VOffline_r(Volume *vp, char *message); +extern void VOffline(Volume * vp, char *message); +extern void VOffline_r(Volume * vp, char *message); extern int VConnectFS(void); extern int VConnectFS_r(void); -extern Volume * VAttachVolume(); -extern Volume * VAttachVolume_r(); -extern Volume * VCreateVolume(); -extern Volume * VCreateVolume_r(); -extern VnodeId VallocBitMapEntry(); -extern VnodeId VallocBitMapEntry_r(); -extern void VFreeBitMapEntry(Error *ec, register struct vnodeIndex *index, - int bitNumber); -extern void VFreeBitMapEntry_r(Error *ec, register struct vnodeIndex *index, - int bitNumber); -extern int VolumeNumber(); -extern int VolumeNumber_r(); -extern char * VolumeExternalName(); -extern char * VolumeExternalName_r(); -extern Volume * VAttachVolumeByName(); -extern Volume * VAttachVolumeByName_r(); +extern Volume *VAttachVolume(Error * ec, VolumeId volumeId, int mode); +extern Volume *VAttachVolume_r(Error * ec, VolumeId volumeId, int mode); +extern Volume *VCreateVolume(Error * ec, char *partname, VolId volumeId, + VolId parentId); +extern Volume *VCreateVolume_r(Error * ec, char *partname, VolId volumeId, + VolId parentId); +extern VnodeId VAllocBitmapEntry(Error * ec, Volume * vp, + struct vnodeIndex *index); +extern VnodeId VAllocBitmapEntry_r(Error * ec, Volume * vp, + struct vnodeIndex *index); +extern void VFreeBitMapEntry(Error * ec, register struct vnodeIndex *index, + unsigned bitNumber); +extern void VFreeBitMapEntry_r(Error * ec, register struct vnodeIndex *index, + unsigned bitNumber); +extern int VolumeNumber(char *name); +extern char *VolumeExternalName(VolumeId volumeId); +extern Volume *VAttachVolumeByName(Error * ec, char *partition, char *name, + int mode); +extern Volume *VAttachVolumeByName_r(Error * ec, char *partition, char *name, + int mode); extern void VShutdown(void); -extern void VUpdateVolume(Error *ec,Volume *vp); -extern void VUpdateVolume_r(Error *ec,Volume *vp); -extern void VAddToVolumeUpdateList(Error *ec, Volume *vp); -extern void VAddToVolumeUpdateList_r(Error *ec, Volume *vp); -extern void VDetachVolume(Error *ec, Volume *vp); -extern void VDetachVolume_r(Error *ec, Volume *vp); -extern void VForceOffline(Volume *vp); -extern void VBumpVolumeUsage(register Volume *vp); +extern void VUpdateVolume(Error * ec, Volume * vp); +extern void VUpdateVolume_r(Error * ec, Volume * vp); +extern void VAddToVolumeUpdateList(Error * ec, Volume * vp); +extern void VAddToVolumeUpdateList_r(Error * ec, Volume * vp); +extern void VDetachVolume(Error * ec, Volume * vp); +extern void VDetachVolume_r(Error * ec, Volume * vp); +extern void VForceOffline(Volume * vp); +extern void VForceOffline_r(Volume * vp); +extern void VBumpVolumeUsage(register Volume * vp); +extern void VBumpVolumeUsage_r(register Volume * vp); extern void VSetDiskUsage(void); extern void VPrintCacheStats(void); -extern void VReleaseVnodeFiles_r(Volume *vp); -extern void VCloseVnodeFiles_r(Volume *vp); +extern void VReleaseVnodeFiles_r(Volume * vp); +extern void VCloseVnodeFiles_r(Volume * vp); extern struct DiskPartition *VGetPartition(char *name, int abortp); extern struct DiskPartition *VGetPartition_r(char *name, int abortp); extern int VInitVolumePackage(ProgramType pt, int nLargeVnodes, - int nSmallVnodes, - int connect, int volcache); -extern void DiskToVolumeHeader(VolumeHeader_t *h, VolumeDiskHeader_t *dh); -extern void VolumeHeaderToDisk(VolumeDiskHeader_t *dh, VolumeHeader_t *h); + int nSmallVnodes, int connect, int volcache); +extern void DiskToVolumeHeader(VolumeHeader_t * h, VolumeDiskHeader_t * dh); +extern void VolumeHeaderToDisk(VolumeDiskHeader_t * dh, VolumeHeader_t * h); +extern void VTakeOffline_r(register Volume * vp); +extern void VTakeOffline(register Volume * vp); /* Naive formula relating number of file size to number of 1K blocks in file */ /* Note: we charge 1 block for 0 length files so the user can't store an inifite number of them; for most files, we give him the inode, vnode, and indirect block overhead, for FREE! */ -#define nBlocks(bytes) ((bytes) == 0? 1: ((bytes)+1023)/1024) +#define nBlocks(bytes) ((afs_sfsize_t)((bytes) == 0? 1: (((afs_sfsize_t)(bytes))+1023)/1024)) /* Client process id -- file server sends a Check volumes signal back to the client at this pid */ #define CLIENTPID "/vice/vol/clientpid" /* Modes of attachment, for VAttachVolume[ByName] to convey to the file server */ -#define V_READONLY 1 /* Absolutely no updates will be done to the volume */ -#define V_CLONE 2 /* Cloning the volume: if it is read/write, then directory - version numbers will change. Header will be updated. If - the volume is read-only, the file server may continue to - server it; it may also continue to server it in read/write - mode if the writes are deferred */ -#define V_UPDATE 3 /* General update or volume purge is possible. Volume must - go offline */ -#define V_DUMP 4 /* A dump of the volume is requested; the volume can be served - read-only during this time */ -#define V_SECRETLY 5 /* Secret attach of the volume. This is used to attach a volume - which the file server doesn't know about--and which it shouldn't - know about yet, since the volume has just been created and - is somewhat bogus. Required to make sure that a file server - never knows about more than one copy of the same volume--when - a volume is moved from one partition to another on a single - server */ +#define V_READONLY 1 /* Absolutely no updates will be done to the volume */ +#define V_CLONE 2 /* Cloning the volume: if it is read/write, then directory + * version numbers will change. Header will be updated. If + * the volume is read-only, the file server may continue to + * server it; it may also continue to server it in read/write + * mode if the writes are deferred */ +#define V_VOLUPD 3 /* General update or volume purge is possible. Volume must + * go offline */ +#define V_DUMP 4 /* A dump of the volume is requested; the volume can be served + * read-only during this time */ +#define V_SECRETLY 5 /* Secret attach of the volume. This is used to attach a volume + * which the file server doesn't know about--and which it shouldn't + * know about yet, since the volume has just been created and + * is somewhat bogus. Required to make sure that a file server + * never knows about more than one copy of the same volume--when + * a volume is moved from one partition to another on a single + * server */ #if defined(NEARINODE_HINT) -#define V_pref(vp,nearInode) nearInodeHash(V_id(vp),(nearInode)); (nearInode) %= V_partition(vp)->f_files -#else -#define V_pref(vp,nearInode) nearInode = 0 -#endif /* NEARINODE_HINT */ +#define V_pref(vp,nearInode) nearInodeHash(V_id(vp),(nearInode)); (nearInode) %= V_partition(vp)->f_files +#else +#define V_pref(vp,nearInode) nearInode = 0 +#endif /* NEARINODE_HINT */ #endif /* __volume_h */ diff --git a/src/vol/vutil.c b/src/vol/vutil.c index d3e758f90..c03152944 100644 --- a/src/vol/vutil.c +++ b/src/vol/vutil.c @@ -17,7 +17,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vutil.c,v 1.1.1.8 2001/10/14 18:07:26 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/vol/vutil.c,v 1.15 2003/11/29 21:38:05 jaltman Exp $"); #include #include @@ -45,6 +46,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vutil.c,v 1.1.1.8 2001/10/14 18:07: #include "lwp.h" #include #include "ihandle.h" +#include #ifdef AFS_NT40_ENV #include "ntops.h" #include @@ -64,10 +66,18 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/vutil.c,v 1.1.1.8 2001/10/14 18:07: #include #endif -void AssignVolumeName(); -void AssignVolumeName_r(); -void ClearVolumeStats(); -void ClearVolumeStats_r(); +#ifdef O_LARGEFILE +#define afs_open open64 +#else /* !O_LARGEFILE */ +#define afs_open open +#endif /* !O_LARGEFILE */ + +/*@printflike@*/ extern void Log(const char *format, ...); + +void AssignVolumeName(register VolumeDiskData * vol, char *name, char *ext); +void AssignVolumeName_r(register VolumeDiskData * vol, char *name, char *ext); +void ClearVolumeStats(register VolumeDiskData * vol); +void ClearVolumeStats_r(register VolumeDiskData * vol); #define nFILES (sizeof (stuff)/sizeof(struct stuff)) @@ -76,7 +86,8 @@ void ClearVolumeStats_r(); volume header ON: this means that the volumes will not be attached by the file server and WILL BE DESTROYED the next time a system salvage is performed */ -static void RemoveInodes(Device dev, int vid) +static void +RemoveInodes(Device dev, VolumeId vid) { register int i; IHandle_t *handle; @@ -85,7 +96,7 @@ static void RemoveInodes(Device dev, int vid) * needs the dev and vid to decrement volume special files. */ IH_INIT(handle, dev, vid, -1); - for (i = 0; if_files; #endif - VLockPartition(partname); - memset(&tempHeader, 0, sizeof (tempHeader)); + VLockPartition_r(partname); + memset(&tempHeader, 0, sizeof(tempHeader)); tempHeader.stamp.magic = VOLUMEHEADERMAGIC; tempHeader.stamp.version = VOLUMEHEADERVERSION; tempHeader.id = vol.id; @@ -154,15 +157,16 @@ Volume *VCreateVolume_r(ec, partname, volumeId, parentId) vol.stamp.magic = VOLUMEINFOMAGIC; vol.stamp.version = VOLUMEINFOVERSION; vol.destroyMe = DESTROY_ME; - sprintf(headerName, VFORMAT, vol.id); - sprintf(volumePath, "%s/%s", VPartitionPath(partition), headerName); - fd = open(volumePath, O_CREAT|O_EXCL|O_WRONLY, 0600); + (void)afs_snprintf(headerName, sizeof headerName, VFORMAT, vol.id); + (void)afs_snprintf(volumePath, sizeof volumePath, "%s/%s", + VPartitionPath(partition), headerName); + fd = afs_open(volumePath, O_CREAT | O_EXCL | O_WRONLY, 0600); if (fd == -1) { - if (errno == EEXIST) { - Log("VCreateVolume: Header file %s already exists!\n", volumePath); + if (errno == EEXIST) { + Log("VCreateVolume: Header file %s already exists!\n", + volumePath); *ec = VVOLEXISTS; - } - else { + } else { Log("VCreateVolume: Couldn't create header file %s for volume %u\n", volumePath, vol.id); *ec = VNOVOL; } @@ -170,17 +174,15 @@ Volume *VCreateVolume_r(ec, partname, volumeId, parentId) } device = partition->device; - for (i = 0; iobsolete) continue; #ifdef AFS_NAMEI_ENV - *(p->inode) = IH_CREATE(NULL, device, VPartitionPath(partition), - nearInode, - (p->inodeType == VI_LINKTABLE) ? vol.parentId : - vol.id, - INODESPECIAL, p->inodeType, - vol.parentId); + *(p->inode) = + IH_CREATE(NULL, device, VPartitionPath(partition), nearInode, + (p->inodeType == VI_LINKTABLE) ? vol.parentId : vol.id, + INODESPECIAL, p->inodeType, vol.parentId); if (!(VALID_INO(*(p->inode)))) { if (errno == EEXIST) { /* Increment the reference count instead. */ @@ -201,21 +203,21 @@ Volume *VCreateVolume_r(ec, partname, volumeId, parentId) code = IH_INC(lh, *(p->inode), parentId); FDH_REALLYCLOSE(fdP); IH_RELEASE(lh); - if (code<0) + if (code < 0) goto bad; continue; } } #else - *(p->inode) = IH_CREATE(NULL, device, VPartitionPath(partition), - nearInode, vol.id, INODESPECIAL, p->inodeType, - vol.parentId); + *(p->inode) = + IH_CREATE(NULL, device, VPartitionPath(partition), nearInode, + vol.id, INODESPECIAL, p->inodeType, vol.parentId); #endif - - if (!VALID_INO(*(p->inode))) { + + if (!VALID_INO(*(p->inode))) { Log("VCreateVolume: Problem creating %s file associated with volume header %s\n", p->description, volumePath); bad: - if(handle) + if (handle) IH_RELEASE(handle); RemoveInodes(device, vol.id); *ec = VNOVOL; @@ -227,94 +229,92 @@ Volume *VCreateVolume_r(ec, partname, volumeId, parentId) if (fdP == NULL) { Log("VCreateVolume: Problem iopen inode %s (err=%d)\n", PrintInode(NULL, *(p->inode)), errno); - goto bad; - } - if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { - Log("VCreateVolume: Problem lseek inode %s (err=%d)\n", - PrintInode(NULL, *(p->inode)), errno); - FDH_REALLYCLOSE(fdP); - goto bad; - } - if (FDH_WRITE(fdP, (char*)&p->stamp, sizeof(p->stamp)) != sizeof(p->stamp)) { - Log("VCreateVolume: Problem writing to inode %s (err=%d)\n", - PrintInode(NULL, *(p->inode)), errno); - FDH_REALLYCLOSE(fdP); - goto bad; - } + goto bad; + } + if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { + Log("VCreateVolume: Problem lseek inode %s (err=%d)\n", + PrintInode(NULL, *(p->inode)), errno); + FDH_REALLYCLOSE(fdP); + goto bad; + } + if (FDH_WRITE(fdP, (char *)&p->stamp, sizeof(p->stamp)) != + sizeof(p->stamp)) { + Log("VCreateVolume: Problem writing to inode %s (err=%d)\n", + PrintInode(NULL, *(p->inode)), errno); + FDH_REALLYCLOSE(fdP); + goto bad; + } FDH_REALLYCLOSE(fdP); IH_RELEASE(handle); - nearInode = *(p->inode); + nearInode = *(p->inode); } IH_INIT(handle, device, vol.parentId, tempHeader.volumeInfo); fdP = IH_OPEN(handle); if (fdP == NULL) { - Log("VCreateVolume: Problem iopen inode %d (err=%d)\n", tempHeader.volumeInfo, errno); + Log("VCreateVolume: Problem iopen inode %s (err=%d)\n", + PrintInode(NULL, tempHeader.volumeInfo), errno); unlink(volumePath); goto bad; - } + } if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { - Log("VCreateVolume: Problem lseek inode %d (err=%d)\n", tempHeader.volumeInfo, errno); + Log("VCreateVolume: Problem lseek inode %s (err=%d)\n", + PrintInode(NULL, tempHeader.volumeInfo), errno); FDH_REALLYCLOSE(fdP); unlink(volumePath); goto bad; - } - if (FDH_WRITE(fdP, (char*)&vol, sizeof(vol)) != sizeof(vol)) { - Log("VCreateVolume: Problem writing to inode %d (err=%d)\n", tempHeader.volumeInfo, errno); + } + if (FDH_WRITE(fdP, (char *)&vol, sizeof(vol)) != sizeof(vol)) { + Log("VCreateVolume: Problem writing to inode %s (err=%d)\n", + PrintInode(NULL, tempHeader.volumeInfo), errno); FDH_REALLYCLOSE(fdP); unlink(volumePath); goto bad; - } + } FDH_CLOSE(fdP); IH_RELEASE(handle); VolumeHeaderToDisk(&diskHeader, &tempHeader); - if (write(fd, &diskHeader, sizeof (diskHeader)) != sizeof (diskHeader)) { + if (write(fd, &diskHeader, sizeof(diskHeader)) != sizeof(diskHeader)) { Log("VCreateVolume: Unable to write volume header %s; volume %u not created\n", volumePath, vol.id); unlink(volumePath); goto bad; } fsync(fd); close(fd); - return (VAttachVolumeByName(ec, partname, headerName, V_SECRETLY)); + return (VAttachVolumeByName_r(ec, partname, headerName, V_SECRETLY)); } void -AssignVolumeName(vol, name, ext) - register VolumeDiskData *vol; - char *name,*ext; +AssignVolumeName(register VolumeDiskData * vol, char *name, char *ext) { - VOL_LOCK - AssignVolumeName_r(vol, name, ext); - VOL_UNLOCK -} + VOL_LOCK AssignVolumeName_r(vol, name, ext); +VOL_UNLOCK} void -AssignVolumeName_r(vol, name, ext) - register VolumeDiskData *vol; - char *name,*ext; +AssignVolumeName_r(register VolumeDiskData * vol, char *name, char *ext) { register char *dot; - strncpy(vol->name, name, VNAMESIZE-1); - vol->name[VNAMESIZE-1] = '\0'; + strncpy(vol->name, name, VNAMESIZE - 1); + vol->name[VNAMESIZE - 1] = '\0'; dot = strrchr(vol->name, '.'); - if (dot && (strcmp(dot,".backup") == 0 || strcmp(dot, ".readonly") == 0)) - *dot = 0; + if (dot && (strcmp(dot, ".backup") == 0 || strcmp(dot, ".readonly") == 0)) + *dot = 0; if (ext) - strncat(vol->name, ext, VNAMESIZE-1-strlen(vol->name)); + strncat(vol->name, ext, VNAMESIZE - 1 - strlen(vol->name)); } -afs_int32 CopyVolumeHeader_r(from, to) - VolumeDiskData *from, *to; +afs_int32 +CopyVolumeHeader_r(VolumeDiskData * from, VolumeDiskData * to) { /* The id and parentId fields are not copied; these are inviolate--the to volume - is assumed to have already been created. The id's cannot be changed once - creation has taken place, since they are embedded in the various inodes associated - with the volume. The copydate is also inviolate--it always reflects the time - this volume was created (compare with the creation date--the creation date of - a backup volume is the creation date of the original parent, because the backup - is used to backup the parent volume). */ + * is assumed to have already been created. The id's cannot be changed once + * creation has taken place, since they are embedded in the various inodes associated + * with the volume. The copydate is also inviolate--it always reflects the time + * this volume was created (compare with the creation date--the creation date of + * a backup volume is the creation date of the original parent, because the backup + * is used to backup the parent volume). */ Date copydate; VolumeId id, parent; id = to->id; @@ -330,29 +330,23 @@ afs_int32 CopyVolumeHeader_r(from, to) return 0; } -afs_int32 CopyVolumeHeader(from, to) - VolumeDiskData *from, *to; +afs_int32 +CopyVolumeHeader(VolumeDiskData * from, VolumeDiskData * to) { afs_int32 code; - VOL_LOCK - code = CopyVolumeHeader_r(from, to); - VOL_UNLOCK - return(code); + VOL_LOCK code = CopyVolumeHeader_r(from, to); + VOL_UNLOCK return (code); } void -ClearVolumeStats(vol) - register VolumeDiskData *vol; +ClearVolumeStats(register VolumeDiskData * vol) { - VOL_LOCK - ClearVolumeStats_r(vol); - VOL_UNLOCK -} + VOL_LOCK ClearVolumeStats_r(vol); +VOL_UNLOCK} void -ClearVolumeStats_r(vol) - register VolumeDiskData *vol; +ClearVolumeStats_r(register VolumeDiskData * vol) { memset(vol->weekUse, 0, sizeof(vol->weekUse)); vol->dayUse = 0; diff --git a/src/vol/xfs_size_check.c b/src/vol/xfs_size_check.c index 77a4fd6ea..2c0098fec 100644 --- a/src/vol/xfs_size_check.c +++ b/src/vol/xfs_size_check.c @@ -11,7 +11,7 @@ * attribute for AFS inode parameters. Check all the mounted /vicep partitions. #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/xfs_size_check.c,v 1.1.1.4 2001/07/11 03:12:27 hartmans Exp $"); +RCSID("$Header: /cvs/openafs/src/vol/xfs_size_check.c,v 1.6 2003/07/15 23:17:42 shadow Exp $"); */ #include @@ -24,7 +24,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/vol/xfs_size_check.c,v 1.1.1.4 2001/07/ #include #include "partition.h" #ifdef AFS_SGI_EFS_IOPS_ENV -#include "../sgiefs/efs.h" +#include "sgiefs/efs.h" #endif #include @@ -38,7 +38,8 @@ char *prog = "xfs_size_check"; #define VERIFY_ERROR -1 #define VERIFY_OK 0 #define VERIFY_FIX 1 -static int VerifyXFSInodeSize(char *part) +static int +VerifyXFSInodeSize(char *part) { afs_xfs_attr_t junk; int length = SIZEOF_XFS_ATTR_T; @@ -46,7 +47,7 @@ static int VerifyXFSInodeSize(char *part) int code = VERIFY_ERROR; struct fsxattr fsx; - if (attr_set(part, AFS_XFS_ATTR, &junk, length, ATTR_ROOT)<0) { + if (attr_set(part, AFS_XFS_ATTR, &junk, length, ATTR_ROOT) < 0) { if (errno == EPERM) { printf("Must be root to run %s\n", prog); exit(1); @@ -54,21 +55,21 @@ static int VerifyXFSInodeSize(char *part) return VERIFY_ERROR; } - if ((fd=open(part, O_RDONLY, 0))<0) + if ((fd = open(part, O_RDONLY, 0)) < 0) goto done; - if (fcntl(fd, F_FSGETXATTRA, &fsx)<0) + if (fcntl(fd, F_FSGETXATTRA, &fsx) < 0) goto done; - + if (fsx.fsx_nextents == 0) code = VERIFY_OK; else code = VERIFY_FIX; - done: - if (fd>=0) + done: + if (fd >= 0) close(fd); - (void) attr_remove(part, AFS_XFS_ATTR, ATTR_ROOT); + (void)attr_remove(part, AFS_XFS_ATTR, ATTR_ROOT); return code; } @@ -83,8 +84,9 @@ partInfo *partList = NULL; int nParts = 0; int nAvail = 0; -int CheckPartitions() - { +int +CheckPartitions() +{ int i; struct mntent *mntent; FILE *mfd; @@ -101,11 +103,12 @@ int CheckPartitions() while (mntent = getmntent(mfd)) { char *part = mntent->mnt_dir; - if (!hasmntopt(mntent, MNTOPT_RW)) continue; + if (!hasmntopt(mntent, MNTOPT_RW)) + continue; - if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { + if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { continue; /* Non /vicepx; ignore */ - } + } if (stat(part, &status) == -1) { printf("Couldn't find file system %s; ignored\n", part); continue; @@ -116,26 +119,30 @@ int CheckPartitions() case VERIFY_OK: break; case VERIFY_ERROR: - printf("%s: Can't check XFS inode size: %s\n", strerror(errno)); + printf("%s: Can't check XFS inode size: %s\n", + strerror(errno)); break; case VERIFY_FIX: if (nAvail <= nParts) { - nAvail += ALLOC_STEP; + nAvail += ALLOC_STEP; if (nAvail == ALLOC_STEP) - partList = (partInfo*)malloc(nAvail*sizeof(partInfo)); + partList = + (partInfo *) malloc(nAvail * sizeof(partInfo)); else - partList = (partInfo*)realloc((char*)partList, - nAvail*sizeof(partInfo)); + partList = + (partInfo *) realloc((char *)partList, + nAvail * sizeof(partInfo)); if (!partList) { - printf("Failed to %salloc %d bytes for partition list.\n", - (nAvail == ALLOC_STEP) ? "m" : "re", - nAvail*sizeof(partInfo)); + printf + ("Failed to %salloc %d bytes for partition list.\n", + (nAvail == ALLOC_STEP) ? "m" : "re", + nAvail * sizeof(partInfo)); exit(1); } } - (void) strcpy(partList[nParts].partName, part); - (void) strcpy(partList[nParts].devName, mntent->mnt_fsname); - nParts ++; + (void)strcpy(partList[nParts].partName, part); + (void)strcpy(partList[nParts].devName, mntent->mnt_fsname); + nParts++; break; default: printf("Unknown return code %d from VerifyXFSInodeSize.\n", @@ -161,15 +168,19 @@ main(int ac, char **av) code = CheckPartitions(); if (code) { printf("Need to remake the following partitions:\n"); - for (i=0; i #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/common.c,v 1.1.1.6 2001/10/14 18:07:28 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/common.c,v 1.10 2003/11/15 04:59:16 shadow Exp $"); #include #include #include -Log(a,b,c,d,e,f) -char *a, *b, *c, *d, *e, *f; +#ifndef AFS_PTHREAD_ENV +/*@printflike@*/ void +Log(const char *format, ...) { - ViceLog(0, (a, b,c, d, e, f)); + va_list args; + + va_start(args, format); + vViceLog(0, (format, args)); + va_end(args); } +#endif -LogError(errcode) -afs_int32 errcode; +void +LogError(afs_int32 errcode) { - ViceLog(0, ("%s: %s\n", error_table_name(errcode),error_message(errcode))); + ViceLog(0, + ("%s: %s\n", error_table_name(errcode), error_message(errcode))); } -Abort(s,a,b,c,d,e,f,g,h,i,j) -char *s; +#ifndef AFS_PTHREAD_ENV +/*@printflike@*/ void +Abort(const char *format, ...) { + va_list args; + ViceLog(0, ("Program aborted: ")); - ViceLog(0, (s,a,b,c,d,e,f,g,h,i,j)); + va_start(args, format); + vViceLog(0, (format, args)); + va_end(args); abort(); } +#endif void -InitErrTabs() +InitErrTabs(void) { +#ifndef AFS_PTHREAD_ENV initialize_KA_error_table(); initialize_RXK_error_table(); initialize_KTC_error_table(); @@ -46,5 +61,6 @@ InitErrTabs() initialize_CMD_error_table(); initialize_VL_error_table(); initialize_VOLS_error_table(); +#endif return; } diff --git a/src/volser/dump.h b/src/volser/dump.h index 48e0002bc..349eb7247 100644 --- a/src/volser/dump.h +++ b/src/volser/dump.h @@ -38,7 +38,7 @@ struct DumpHeader { char volumeName[VNAMESIZE]; int nDumpTimes; /* Number of pairs */ struct { - afs_int32 from, to; + afs_int32 from, to; } dumpTimes[MAXDUMPTIMES]; }; diff --git a/src/volser/dumpstuff.c b/src/volser/dumpstuff.c index e691852c3..83562b200 100644 --- a/src/volser/dumpstuff.c +++ b/src/volser/dumpstuff.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/dumpstuff.c,v 1.1.1.9 2003/04/13 19:08:21 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/dumpstuff.c,v 1.25 2003/11/23 04:53:44 jaltman Exp $"); #include #include @@ -25,8 +26,19 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/dumpstuff.c,v 1.1.1.9 2003/04/13 #include #include #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include +#ifdef AFS_PTHREAD_ENV +#include +#else /* AFS_PTHREAD_ENV */ #include +#endif /* AFS_PTHREAD_ENV */ #include #include #include @@ -44,6 +56,18 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/dumpstuff.c,v 1.1.1.9 2003/04/13 #include "volser.h" #include "volint.h" +#ifndef AFS_NT40_ENV +#ifdef O_LARGEFILE +#define afs_stat stat64 +#define afs_fstat fstat64 +#else /* !O_LARGEFILE */ +#define afs_stat stat +#define afs_fstat fstat +#endif /* !O_LARGEFILE */ +#endif /* !AFS_NT40_ENV */ + +/*@printflike@*/ extern void Log(const char *format, ...); + extern int DoLogging; /* This iod stuff is a silly little package to emulate the old qi_in stuff, which @@ -58,49 +82,66 @@ struct iod { struct rx_call *call; /* call to which to write, might be an array */ int device; /* dump device ID for volume */ int parentId; /* dump parent ID for volume */ - struct DiskPartition *dumpPartition; /* Dump partition. */ - struct rx_call **calls; /* array of pointers to calls */ - int ncalls; /* how many calls/codes in array */ - int *codes; /* one return code for each call */ + struct DiskPartition *dumpPartition; /* Dump partition. */ + struct rx_call **calls; /* array of pointers to calls */ + int ncalls; /* how many calls/codes in array */ + int *codes; /* one return code for each call */ char haveOldChar; /* state for pushing back a character */ char oldChar; }; /* Forward Declarations */ -static int DumpDumpHeader(register struct iod *iodp, register Volume *vp, +static int DumpDumpHeader(register struct iod *iodp, register Volume * vp, afs_int32 fromtime); -static int DumpPartial(register struct iod *iodp, register Volume *vp, +static int DumpPartial(register struct iod *iodp, register Volume * vp, afs_int32 fromtime, int dumpAllDirs); -static int DumpVnodeIndex(register struct iod *iodp, Volume *vp, - VnodeClass class, afs_int32 fromtime, int forcedump); +static int DumpVnodeIndex(register struct iod *iodp, Volume * vp, + VnodeClass class, afs_int32 fromtime, + int forcedump); static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid, int vnodeNumber, int dumpEverything); static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp); -static int ReadVnodes(register struct iod *iodp, Volume *vp, - int incremental, afs_int32 *Lbuf, afs_int32 s1, - afs_int32 *Sbuf, afs_int32 s2, afs_int32 delo); -static bit32 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t *handleP, - Error *status); - - -static void iod_Init(register struct iod *iodp, register struct rx_call *call) +static int ReadVnodes(register struct iod *iodp, Volume * vp, int incremental, + afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, + afs_int32 s2, afs_int32 delo); +static afs_fsize_t volser_WriteFile(int vn, struct iod *iodp, + FdHandle_t * handleP, int tag, + Error * status); + +static int SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp, + afs_int32 fromtime, + register struct volintSize *size); +static int SizeDumpPartial(register struct iod *iodp, register Volume * vp, + afs_int32 fromtime, int dumpAllDirs, + register struct volintSize *size); +static int SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp, + VnodeClass class, afs_int32 fromtime, + int forcedump, + register struct volintSize *size); +static int SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, + int volid, int vnodeNumber, int dumpEverything, + register struct volintSize *size); + +static void +iod_Init(register struct iod *iodp, register struct rx_call *call) { iodp->call = call; iodp->haveOldChar = 0; iodp->ncalls = 1; - iodp->calls = (struct rx_call **) 0; + iodp->calls = (struct rx_call **)0; } -static void iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls, - int *codes) +static void +iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls, + int *codes) { - iodp->calls = calls; - iodp->haveOldChar = 0; - iodp->ncalls = ncalls; - iodp->codes = codes; - iodp->call = (struct rx_call *) 0; + iodp->calls = calls; + iodp->haveOldChar = 0; + iodp->ncalls = ncalls; + iodp->codes = codes; + iodp->call = (struct rx_call *)0; } /* N.B. iod_Read doesn't check for oldchar (see previous comment) */ @@ -112,76 +153,83 @@ static void iod_InitMulti(struct iod *iodp, struct rx_call **calls, int ncalls, * I don't think we want half the replicas to go bad just because one * connection timed out, but if they all time out, then we should give up. */ -static int iod_Write(struct iod *iodp, char *buf, int nbytes) +static int +iod_Write(struct iod *iodp, char *buf, int nbytes) { - int code, i; - int one_success = 0; - - assert ((iodp->call && iodp->ncalls == 1 && !iodp->calls) || - (!iodp->call && iodp->ncalls >= 1 && iodp->calls)); - - if (iodp->call) { - code = rx_Write(iodp->call, buf, nbytes); - return code; - } - - for (i=0; i < iodp->ncalls; i++) { - if (iodp->calls[i] && !iodp->codes[i]) { - code = rx_Write(iodp->calls[i], buf, nbytes); - if (code != nbytes) { /* everything gets merged into a single error */ - iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */ - } /* standard dump does, anyways */ - else { - one_success = TRUE; - } + int code, i; + int one_success = 0; + + assert((iodp->call && iodp->ncalls == 1 && !iodp->calls) + || (!iodp->call && iodp->ncalls >= 1 && iodp->calls)); + + if (iodp->call) { + code = rx_Write(iodp->call, buf, nbytes); + return code; } - } /* for all calls */ -if (one_success) - return nbytes; -else return 0; + for (i = 0; i < iodp->ncalls; i++) { + if (iodp->calls[i] && !iodp->codes[i]) { + code = rx_Write(iodp->calls[i], buf, nbytes); + if (code != nbytes) { /* everything gets merged into a single error */ + iodp->codes[i] = VOLSERDUMPERROR; /* but that's exactly what the */ + } /* standard dump does, anyways */ + else { + one_success = TRUE; + } + } + } /* for all calls */ + + if (one_success) + return nbytes; + else + return 0; } -static void iod_ungetc(struct iod *iodp, int achar) +static void +iod_ungetc(struct iod *iodp, int achar) { iodp->oldChar = achar; iodp->haveOldChar = 1; } -static int iod_getc(register struct iod *iodp) +static int +iod_getc(register struct iod *iodp) { unsigned char t; - + if (iodp->haveOldChar) { iodp->haveOldChar = 0; return iodp->oldChar; } - if (iod_Read(iodp, &t, 1) == 1) return t; + if (iod_Read(iodp, &t, 1) == 1) + return t; return EOF; } -static int ReadShort(register struct iod *iodp, register unsigned short *sp) +static int +ReadShort(register struct iod *iodp, register unsigned short *sp) { - register b1,b0; + register b1, b0; b1 = iod_getc(iodp); b0 = iod_getc(iodp); - *sp = (b1<<8) | b0; + *sp = (b1 << 8) | b0; return b0 != EOF; } -static int ReadInt32(register struct iod *iodp, afs_uint32 *lp) +static int +ReadInt32(register struct iod *iodp, afs_uint32 * lp) { - afs_uint32 register b3,b2,b1,b0; + afs_uint32 register b3, b2, b1, b0; b3 = iod_getc(iodp); b2 = iod_getc(iodp); b1 = iod_getc(iodp); b0 = iod_getc(iodp); - *lp = (((((b3<<8)|b2)<<8)|b1)<<8)|b0; + *lp = (((((b3 << 8) | b2) << 8) | b1) << 8) | b0; return b0 != EOF; } -static void ReadString(register struct iod *iodp, register char *to, - register int maxa) +static void +ReadString(register struct iod *iodp, register char *to, register int maxa) { register int c; while (maxa--) { @@ -194,233 +242,273 @@ static void ReadString(register struct iod *iodp, register char *to, } } -static void ReadByteString(register struct iod *iodp, register byte *to, - register int size) +static void +ReadByteString(register struct iod *iodp, register byte * to, + register int size) { while (size--) *to++ = iod_getc(iodp); } -static int ReadVolumeHeader(register struct iod *iodp, VolumeDiskData *vol) +static int +ReadVolumeHeader(register struct iod *iodp, VolumeDiskData * vol) { register tag; afs_uint32 trash; memset(vol, 0, sizeof(*vol)); while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) { switch (tag) { - case 'i': - if(!ReadInt32(iodp, &vol->id)) return VOLSERREAD_DUMPERROR; - break; - case 'v': - if(!ReadInt32(iodp, &trash)) return VOLSERREAD_DUMPERROR; - break; - case 'n': - ReadString(iodp, vol->name, sizeof(vol->name)); - /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */ - break; - case 's': - vol->inService = iod_getc(iodp ); - break; - case 'b': - vol->blessed = iod_getc(iodp ); - break; - case 'u': - if(!ReadInt32(iodp, &vol->uniquifier)) return VOLSERREAD_DUMPERROR; - break; - case 't': - vol->type = iod_getc(iodp ); - break; - case 'p': - if(!ReadInt32(iodp, &vol->parentId)) return VOLSERREAD_DUMPERROR; - break; - case 'c': - if(!ReadInt32(iodp, &vol->cloneId)) return VOLSERREAD_DUMPERROR; - break; - case 'q': - if(!ReadInt32(iodp, (afs_uint32 *)&vol->maxquota)) return VOLSERREAD_DUMPERROR; - break; - case 'm': - if(!ReadInt32(iodp, (afs_uint32 *)&vol->minquota)) return VOLSERREAD_DUMPERROR; - break; - case 'd': - if(!ReadInt32(iodp, (afs_uint32 *)&vol->diskused)) return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */ - break; - case 'f': - if(!ReadInt32(iodp, (afs_uint32 *)&vol->filecount)) return VOLSERREAD_DUMPERROR; - break; - case 'a': - if(!ReadInt32(iodp, &vol->accountNumber)) return VOLSERREAD_DUMPERROR; - break; - case 'o': - if(!ReadInt32(iodp, &vol->owner)) return VOLSERREAD_DUMPERROR; - break; - case 'C': - if(!ReadInt32(iodp, &vol->creationDate)) return VOLSERREAD_DUMPERROR; - break; - case 'A': - if(!ReadInt32(iodp, &vol->accessDate)) return VOLSERREAD_DUMPERROR; - break; - case 'U': - if(!ReadInt32(iodp, &vol->updateDate)) return VOLSERREAD_DUMPERROR; - break; - case 'E': - if(!ReadInt32(iodp, &vol->expirationDate)) return VOLSERREAD_DUMPERROR; - break; - case 'B': - if(!ReadInt32(iodp, &vol->backupDate)) return VOLSERREAD_DUMPERROR; - break; - case 'O': - ReadString(iodp, vol->offlineMessage, sizeof(vol->offlineMessage)); - break; - case 'M': - /* - * Detailed volume statistics are never stored in dumps, - * so we just restore either the null string if this volume - * had already been set to store statistics, or the old motd - * contents otherwise. It doesn't matter, since this field - * will soon get initialized anyway. - */ - ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE); - break; - case 'W': { + case 'i': + if (!ReadInt32(iodp, &vol->id)) + return VOLSERREAD_DUMPERROR; + break; + case 'v': + if (!ReadInt32(iodp, &trash)) + return VOLSERREAD_DUMPERROR; + break; + case 'n': + ReadString(iodp, vol->name, sizeof(vol->name)); + /*this means the name of the retsored volume could be possibly different. In conjunction with SAFSVolSignalRestore */ + break; + case 's': + vol->inService = iod_getc(iodp); + break; + case 'b': + vol->blessed = iod_getc(iodp); + break; + case 'u': + if (!ReadInt32(iodp, &vol->uniquifier)) + return VOLSERREAD_DUMPERROR; + break; + case 't': + vol->type = iod_getc(iodp); + break; + case 'p': + if (!ReadInt32(iodp, &vol->parentId)) + return VOLSERREAD_DUMPERROR; + break; + case 'c': + if (!ReadInt32(iodp, &vol->cloneId)) + return VOLSERREAD_DUMPERROR; + break; + case 'q': + if (!ReadInt32(iodp, (afs_uint32 *) & vol->maxquota)) + return VOLSERREAD_DUMPERROR; + break; + case 'm': + if (!ReadInt32(iodp, (afs_uint32 *) & vol->minquota)) + return VOLSERREAD_DUMPERROR; + break; + case 'd': + if (!ReadInt32(iodp, (afs_uint32 *) & vol->diskused)) + return VOLSERREAD_DUMPERROR; /* Bogus: should calculate this */ + break; + case 'f': + if (!ReadInt32(iodp, (afs_uint32 *) & vol->filecount)) + return VOLSERREAD_DUMPERROR; + break; + case 'a': + if (!ReadInt32(iodp, &vol->accountNumber)) + return VOLSERREAD_DUMPERROR; + break; + case 'o': + if (!ReadInt32(iodp, &vol->owner)) + return VOLSERREAD_DUMPERROR; + break; + case 'C': + if (!ReadInt32(iodp, &vol->creationDate)) + return VOLSERREAD_DUMPERROR; + break; + case 'A': + if (!ReadInt32(iodp, &vol->accessDate)) + return VOLSERREAD_DUMPERROR; + break; + case 'U': + if (!ReadInt32(iodp, &vol->updateDate)) + return VOLSERREAD_DUMPERROR; + break; + case 'E': + if (!ReadInt32(iodp, &vol->expirationDate)) + return VOLSERREAD_DUMPERROR; + break; + case 'B': + if (!ReadInt32(iodp, &vol->backupDate)) + return VOLSERREAD_DUMPERROR; + break; + case 'O': + ReadString(iodp, vol->offlineMessage, + sizeof(vol->offlineMessage)); + break; + case 'M': + /* + * Detailed volume statistics are never stored in dumps, + * so we just restore either the null string if this volume + * had already been set to store statistics, or the old motd + * contents otherwise. It doesn't matter, since this field + * will soon get initialized anyway. + */ + ReadString(iodp, (char *)(vol->stat_reads), VMSGSIZE); + break; + case 'W':{ unsigned short length; int i; - afs_uint32 data; - if(!ReadShort(iodp, &length)) return VOLSERREAD_DUMPERROR; - for (i = 0; iweekUse)/sizeof(vol->weekUse[0])) + afs_uint32 data; + if (!ReadShort(iodp, &length)) + return VOLSERREAD_DUMPERROR; + for (i = 0; i < length; i++) { + if (!ReadInt32(iodp, &data)) + return VOLSERREAD_DUMPERROR; + if (i < sizeof(vol->weekUse) / sizeof(vol->weekUse[0])) vol->weekUse[i] = data; } break; } - case 'D': - if(!ReadInt32(iodp, &vol->dayUseDate)) return VOLSERREAD_DUMPERROR; - break; - case 'Z': - if(!ReadInt32(iodp, (afs_uint32 *)&vol->dayUse)) return VOLSERREAD_DUMPERROR; - break; + case 'D': + if (!ReadInt32(iodp, &vol->dayUseDate)) + return VOLSERREAD_DUMPERROR; + break; + case 'Z': + if (!ReadInt32(iodp, (afs_uint32 *) & vol->dayUse)) + return VOLSERREAD_DUMPERROR; + break; } } iod_ungetc(iodp, tag); return 0; } -static int DumpTag(register struct iod *iodp, register int tag) +static int +DumpTag(register struct iod *iodp, register int tag) { char p; - + p = tag; - return((iod_Write(iodp, &p, 1) == 1)? 0 : VOLSERDUMPERROR); - + return ((iod_Write(iodp, &p, 1) == 1) ? 0 : VOLSERDUMPERROR); + } -static int DumpByte(register struct iod *iodp, char tag, byte value) +static int +DumpByte(register struct iod *iodp, char tag, byte value) { char tbuffer[2]; - register byte *p = (unsigned char *) tbuffer; + register byte *p = (unsigned char *)tbuffer; *p++ = tag; *p = value; - return((iod_Write(iodp, tbuffer, 2) == 2)? 0: VOLSERDUMPERROR); + return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR); } #define putint32(p, v) *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v #define putshort(p, v) *p++ = v>>8, *p++ = v -static int DumpDouble(register struct iod *iodp, char tag, - register afs_uint32 value1, register afs_uint32 value2) +static int +DumpDouble(register struct iod *iodp, char tag, register afs_uint32 value1, + register afs_uint32 value2) { char tbuffer[9]; - register byte *p = (unsigned char *) tbuffer; + register byte *p = (unsigned char *)tbuffer; *p++ = tag; putint32(p, value1); putint32(p, value2); - return((iod_Write(iodp, tbuffer, 9) == 9)? 0: VOLSERDUMPERROR); + return ((iod_Write(iodp, tbuffer, 9) == 9) ? 0 : VOLSERDUMPERROR); } -static int DumpInt32(register struct iod *iodp, char tag, - register afs_uint32 value) +static int +DumpInt32(register struct iod *iodp, char tag, register afs_uint32 value) { char tbuffer[5]; - register byte *p = (unsigned char *) tbuffer; + register byte *p = (unsigned char *)tbuffer; *p++ = tag; putint32(p, value); - return((iod_Write(iodp, tbuffer, 5) == 5)? 0: VOLSERDUMPERROR); + return ((iod_Write(iodp, tbuffer, 5) == 5) ? 0 : VOLSERDUMPERROR); } -static int DumpArrayInt32(register struct iod *iodp, char tag, - register afs_uint32 *array, register int nelem) +static int +DumpArrayInt32(register struct iod *iodp, char tag, + register afs_uint32 * array, register int nelem) { char tbuffer[4]; - register afs_uint32 v ; + register afs_uint32 v; int code = 0; - register byte *p = (unsigned char *) tbuffer; + register byte *p = (unsigned char *)tbuffer; *p++ = tag; putshort(p, nelem); code = iod_Write(iodp, tbuffer, 3); - if (code != 3) return VOLSERDUMPERROR; + if (code != 3) + return VOLSERDUMPERROR; while (nelem--) { - p = (unsigned char *) tbuffer; - v = *array++;/*this was register */ - + p = (unsigned char *)tbuffer; + v = *array++; /*this was register */ + putint32(p, v); code = iod_Write(iodp, tbuffer, 4); - if(code != 4) return VOLSERDUMPERROR; + if (code != 4) + return VOLSERDUMPERROR; } return 0; } -static int DumpShort(register struct iod *iodp, char tag, unsigned int value) +static int +DumpShort(register struct iod *iodp, char tag, unsigned int value) { char tbuffer[3]; - register byte *p = (unsigned char *) tbuffer; + register byte *p = (unsigned char *)tbuffer; *p++ = tag; - *p++ = value>>8; + *p++ = value >> 8; *p = value; - return((iod_Write(iodp, tbuffer, 3) == 3)? 0: VOLSERDUMPERROR); + return ((iod_Write(iodp, tbuffer, 3) == 3) ? 0 : VOLSERDUMPERROR); } -static int DumpBool(register struct iod *iodp, char tag, unsigned int value) +static int +DumpBool(register struct iod *iodp, char tag, unsigned int value) { char tbuffer[2]; - register byte *p = (unsigned char *) tbuffer; + register byte *p = (unsigned char *)tbuffer; *p++ = tag; *p = value; - return((iod_Write(iodp, tbuffer, 2) == 2)? 0: VOLSERDUMPERROR); + return ((iod_Write(iodp, tbuffer, 2) == 2) ? 0 : VOLSERDUMPERROR); } -static int DumpString(register struct iod *iodp, char tag, register char *s) +static int +DumpString(register struct iod *iodp, char tag, register char *s) { register n; int code = 0; code = iod_Write(iodp, &tag, 1); - if(code != 1) return VOLSERDUMPERROR; - n = strlen(s)+1; + if (code != 1) + return VOLSERDUMPERROR; + n = strlen(s) + 1; code = iod_Write(iodp, s, n); - if(code != n) return VOLSERDUMPERROR; + if (code != n) + return VOLSERDUMPERROR; return 0; } -static int DumpByteString(register struct iod *iodp, char tag, - register byte *bs, register int nbytes) +static int +DumpByteString(register struct iod *iodp, char tag, register byte * bs, + register int nbytes) { int code = 0; code = iod_Write(iodp, &tag, 1); - if(code != 1) return VOLSERDUMPERROR; + if (code != 1) + return VOLSERDUMPERROR; code = iod_Write(iodp, (char *)bs, nbytes); - if(code != nbytes) return VOLSERDUMPERROR; + if (code != nbytes) + return VOLSERDUMPERROR; return 0; } - -static int DumpFile(struct iod *iodp, char tag, int vnode, FdHandle_t *handleP) + +static int +DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP) { - int code = 0, lcode = 0, error = 0; + int code = 0, lcode = 0, error = 0; afs_int32 pad = 0, offset; - int n, nbytes, howMany, howBig; - byte *p; - struct stat status; - int size; + afs_sfsize_t n, nbytes, howMany, howBig; + byte *p; +#ifndef AFS_NT40_ENV + struct afs_stat status; +#endif + afs_sfsize_t size; #ifdef AFS_AIX_ENV #include struct statfs tstatfs; @@ -431,7 +519,7 @@ static int DumpFile(struct iod *iodp, char tag, int vnode, FdHandle_t *handleP) howMany = 4096; #else - fstat(handleP->fd_fd, &status); + afs_fstat(handleP->fd_fd, &status); howBig = status.st_size; #ifdef AFS_AIX_ENV @@ -447,31 +535,42 @@ static int DumpFile(struct iod *iodp, char tag, int vnode, FdHandle_t *handleP) size = FDH_SIZE(handleP); - code = DumpInt32(iodp, tag, size); +#ifdef AFS_LARGEFILE_ENV + { + afs_uint32 hi, lo; + SplitInt64(size, hi, lo); + if (hi == 0L) { + code = DumpInt32(iodp, 'f', lo); + } else { + code = DumpDouble(iodp, 'h', hi, lo); + } + } +#else /* !AFS_LARGEFILE_ENV */ + code = DumpInt32(iodp, 'f', size); +#endif /* !AFS_LARGEFILE_ENV */ if (code) { - return VOLSERDUMPERROR; + return VOLSERDUMPERROR; } - p = (unsigned char *) malloc(howMany); + p = (unsigned char *)malloc(howMany); if (!p) { - Log("1 Volser: DumpFile: no memory"); - return VOLSERDUMPERROR; + Log("1 Volser: DumpFile: no memory"); + return VOLSERDUMPERROR; } for (nbytes = size; (nbytes && !error); nbytes -= howMany) { - if (nbytes < howMany) - howMany = nbytes; + if (nbytes < howMany) + howMany = nbytes; /* Read the data - unless we know we can't */ - n = (lcode ? 0 : FDH_READ(handleP, p, howMany)); + n = (lcode ? 0 : FDH_READ(handleP, p, howMany)); /* If read any good data and we null padded previously, log the * amount that we had null padded. */ if ((n > 0) && pad) { - Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", - pad, offset); - pad = 0; + Log("1 Volser: DumpFile: Null padding file %d bytes at offset %u\n", pad, offset); + pad = 0; } /* If didn't read enough data, null padd the rest of the buffer. This @@ -479,162 +578,203 @@ static int DumpFile(struct iod *iodp, char tag, int vnode, FdHandle_t *handleP) * want to quit the dump, so we start null padding. */ if (n < howMany) { - /* Record the read error */ - if (n < 0) { - n = 0; - Log("1 Volser: DumpFile: Error %d reading inode %s for vnode %d\n", - errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); - } - else if (!pad) { - Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", - PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); - } - - /* Pad the rest of the buffer with zeros. Remember offset we started - * padding. Keep total tally of padding. - */ - memset(p+n, 0, howMany-n); - if (!pad) - offset = (howBig - nbytes) + n; - pad += (howMany-n); - - /* Now seek over the data we could not get. An error here means we - * can't do the next read. - */ - lcode = FDH_SEEK(handleP, ((size - nbytes) + howMany), SEEK_SET); - if (lcode != ((size - nbytes) + howMany)) { - if (lcode < 0) { - Log("1 Volser: DumpFile: Error %d seeking in inode %s for vnode %d\n", - errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); - } - else { - Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", - PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); - lcode = -1; - } - } - else { - lcode = 0; - } + /* Record the read error */ + if (n < 0) { + n = 0; + Log("1 Volser: DumpFile: Error %d reading inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); + } else if (!pad) { + Log("1 Volser: DumpFile: Error reading inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); + } + + /* Pad the rest of the buffer with zeros. Remember offset we started + * padding. Keep total tally of padding. + */ + memset(p + n, 0, howMany - n); + if (!pad) + offset = (howBig - nbytes) + n; + pad += (howMany - n); + + /* Now seek over the data we could not get. An error here means we + * can't do the next read. + */ + lcode = FDH_SEEK(handleP, ((size - nbytes) + howMany), SEEK_SET); + if (lcode != ((size - nbytes) + howMany)) { + if (lcode < 0) { + Log("1 Volser: DumpFile: Error %d seeking in inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); + } else { + Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); + lcode = -1; + } + } else { + lcode = 0; + } } /* Now write the data out */ - if (iod_Write(iodp, (char *)p, howMany) != howMany) - error = VOLSERDUMPERROR; + if (iod_Write(iodp, (char *)p, howMany) != howMany) + error = VOLSERDUMPERROR; +#ifndef AFS_PTHREAD_ENV IOMGR_Poll(); +#endif } - if (pad) { /* Any padding we hadn't reported yet */ - Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n", - pad, offset); + if (pad) { /* Any padding we hadn't reported yet */ + Log("1 Volser: DumpFile: Null padding file: %d bytes at offset %u\n", + pad, offset); } free(p); return error; } -static int DumpVolumeHeader(register struct iod *iodp, register Volume *vp) +static int +DumpVolumeHeader(register struct iod *iodp, register Volume * vp) { int code = 0; - static char nullString[1] = ""; /*The ``contents'' of motd*/ - - if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); - if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} - if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); - if (!code) code = DumpString(iodp, 'n',V_name(vp)); - if (!code) code = DumpBool(iodp, 's',V_inService(vp)); - if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); - if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); - if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); - if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} - if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); - if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); - if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); - if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); - if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); - if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); - if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); - if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /* Rw volume creation date */ - if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); - if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); - if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); - if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /* Rw volume backup clone date */ - if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); + static char nullString[1] = ""; /*The ``contents'' of motd */ + + if (!code) + code = DumpTag(iodp, D_VOLUMEHEADER); + if (!code) { + code = DumpInt32(iodp, 'i', V_id(vp)); + } + if (!code) + code = DumpInt32(iodp, 'v', V_stamp(vp).version); + if (!code) + code = DumpString(iodp, 'n', V_name(vp)); + if (!code) + code = DumpBool(iodp, 's', V_inService(vp)); + if (!code) + code = DumpBool(iodp, 'b', V_blessed(vp)); + if (!code) + code = DumpInt32(iodp, 'u', V_uniquifier(vp)); + if (!code) + code = DumpByte(iodp, 't', (byte) V_type(vp)); + if (!code) { + code = DumpInt32(iodp, 'p', V_parentId(vp)); + } + if (!code) + code = DumpInt32(iodp, 'c', V_cloneId(vp)); + if (!code) + code = DumpInt32(iodp, 'q', V_maxquota(vp)); + if (!code) + code = DumpInt32(iodp, 'm', V_minquota(vp)); + if (!code) + code = DumpInt32(iodp, 'd', V_diskused(vp)); + if (!code) + code = DumpInt32(iodp, 'f', V_filecount(vp)); + if (!code) + code = DumpInt32(iodp, 'a', V_accountNumber(vp)); + if (!code) + code = DumpInt32(iodp, 'o', V_owner(vp)); + if (!code) + code = DumpInt32(iodp, 'C', V_creationDate(vp)); /* Rw volume creation date */ + if (!code) + code = DumpInt32(iodp, 'A', V_accessDate(vp)); + if (!code) + code = DumpInt32(iodp, 'U', V_updateDate(vp)); + if (!code) + code = DumpInt32(iodp, 'E', V_expirationDate(vp)); + if (!code) + code = DumpInt32(iodp, 'B', V_backupDate(vp)); /* Rw volume backup clone date */ + if (!code) + code = DumpString(iodp, 'O', V_offlineMessage(vp)); /* * We do NOT dump the detailed volume statistics residing in the old * motd field, since we cannot tell from the info in a dump whether * statistics data has been put there. Instead, we dump a null string, * just as if that was what the motd contained. */ - if (!code) code = DumpString(iodp, 'M', nullString); - if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); - if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); - if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); + if (!code) + code = DumpString(iodp, 'M', nullString); + if (!code) + code = + DumpArrayInt32(iodp, 'W', (afs_uint32 *) V_weekUse(vp), + sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0])); + if (!code) + code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); + if (!code) + code = DumpInt32(iodp, 'Z', V_dayUse(vp)); return code; } -static int DumpEnd(register struct iod *iodp) +static int +DumpEnd(register struct iod *iodp) { - return(DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC)); + return (DumpInt32(iodp, D_DUMPEND, DUMPENDMAGIC)); } /* Guts of the dump code */ /* Dump a whole volume */ -int DumpVolume(register struct rx_call *call, register Volume *vp, - afs_int32 fromtime, int dumpAllDirs) +int +DumpVolume(register struct rx_call *call, register Volume * vp, + afs_int32 fromtime, int dumpAllDirs) { struct iod iod; int code = 0; register struct iod *iodp = &iod; iod_Init(iodp, call); - - if (!code) code = DumpDumpHeader(iodp, vp, fromtime); - - if (!code) code = DumpPartial(iodp, vp, fromtime, dumpAllDirs); - + + if (!code) + code = DumpDumpHeader(iodp, vp, fromtime); + + if (!code) + code = DumpPartial(iodp, vp, fromtime, dumpAllDirs); + /* hack follows. Errors should be handled quite differently in this version of dump than they used to be.*/ if (rx_Error(iodp->call)) { - Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n", rx_Error(iodp->call)); + Log("1 Volser: DumpVolume: Rx call failed during dump, error %d\n", + rx_Error(iodp->call)); return VOLSERDUMPERROR; } - if (!code) code = DumpEnd(iodp); - + if (!code) + code = DumpEnd(iodp); + return code; } /* Dump a volume to multiple places*/ -int DumpVolMulti(struct rx_call **calls, int ncalls, Volume *vp, - afs_int32 fromtime, int dumpAllDirs, int *codes) +int +DumpVolMulti(struct rx_call **calls, int ncalls, Volume * vp, + afs_int32 fromtime, int dumpAllDirs, int *codes) { struct iod iod; int code = 0; iod_InitMulti(&iod, calls, ncalls, codes); - - if (!code) code = DumpDumpHeader(&iod, vp, fromtime); - if (!code) code = DumpPartial(&iod, vp, fromtime, dumpAllDirs); - if (!code) code = DumpEnd(&iod); + + if (!code) + code = DumpDumpHeader(&iod, vp, fromtime); + if (!code) + code = DumpPartial(&iod, vp, fromtime, dumpAllDirs); + if (!code) + code = DumpEnd(&iod); return code; } /* A partial dump (no dump header) */ -static int DumpPartial(register struct iod *iodp, register Volume *vp, - afs_int32 fromtime, int dumpAllDirs) +static int +DumpPartial(register struct iod *iodp, register Volume * vp, + afs_int32 fromtime, int dumpAllDirs) { int code = 0; - if (!code) code = DumpVolumeHeader(iodp, vp); - if (!code) code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs); - if (!code) code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0); + if (!code) + code = DumpVolumeHeader(iodp, vp); + if (!code) + code = DumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs); + if (!code) + code = DumpVnodeIndex(iodp, vp, vSmall, fromtime, 0); return code; } -static int DumpVnodeIndex(register struct iod *iodp, Volume *vp, - VnodeClass class, afs_int32 fromtime, int forcedump) +static int +DumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class, + afs_int32 fromtime, int forcedump) { register int code = 0; register struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; char buf[SIZEOF_LARGEDISKVNODE]; - struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; StreamHandle_t *file; FdHandle_t *fdP; int size; @@ -649,26 +789,34 @@ static int DumpVnodeIndex(register struct iod *iodp, Volume *vp, assert(size != -1); nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { - assert((nVnodes+1)*vcp->diskSize == size); + assert((nVnodes + 1) * vcp->diskSize == size); assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0); - } - else nVnodes = 0; - for (vnodeIndex = 0; nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code; - nVnodes--, vnodeIndex++) { + } else + nVnodes = 0; + for (vnodeIndex = 0; + nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code; + nVnodes--, vnodeIndex++) { flag = forcedump || (vnode->serverModifyTime >= fromtime); /* Note: the >= test is very important since some old volumes may not have - a serverModifyTime. For an epoch dump, this results in 0>=0 test, which - does dump the file! */ - if (!code) code = DumpVnode(iodp, vnode, V_id(vp), bitNumberToVnodeNumber(vnodeIndex, class), flag); - if (!flag) IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */ + * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which + * does dump the file! */ + if (!code) + code = + DumpVnode(iodp, vnode, V_id(vp), + bitNumberToVnodeNumber(vnodeIndex, class), flag); +#ifndef AFS_PTHREAD_ENV + if (!flag) + IOMGR_Poll(); /* if we dont' xfr data, but scan instead, could lose conn */ +#endif } STREAM_CLOSE(file); FDH_CLOSE(fdP); return code; } -static int DumpDumpHeader(register struct iod *iodp, register Volume *vp, - afs_int32 fromtime) +static int +DumpDumpHeader(register struct iod *iodp, register Volume * vp, + afs_int32 fromtime) { int code = 0; int UseLatestReadOnlyClone = 1; @@ -676,17 +824,24 @@ static int DumpDumpHeader(register struct iod *iodp, register Volume *vp, iodp->device = vp->device; iodp->parentId = V_parentId(vp); iodp->dumpPartition = vp->partition; - if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); - if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); - if (!code) code = DumpString(iodp, 'n',V_name(vp)); + if (!code) + code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); + if (!code) + code = + DumpInt32(iodp, 'v', + UseLatestReadOnlyClone ? V_id(vp) : V_parentId(vp)); + if (!code) + code = DumpString(iodp, 'n', V_name(vp)); dumpTimes[0] = fromtime; dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */ - if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); + if (!code) + code = DumpArrayInt32(iodp, 't', (afs_uint32 *) dumpTimes, 2); return code; } -static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, - int volid, int vnodeNumber, int dumpEverything) +static int +DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid, + int vnodeNumber, int dumpEverything) { int code = 0; IHandle_t *ihP; @@ -694,33 +849,46 @@ static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, if (!v || v->type == vNull) return code; - if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); + if (!code) + code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); if (!dumpEverything) - return code; - if (!code) code = DumpByte(iodp, 't',(byte)v->type); - if (!code) code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */ - if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); - if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); - if (!code) code = DumpInt32(iodp, 'a', v->author); - if (!code) code = DumpInt32(iodp, 'o', v->owner); - if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */ - if (!code) code = DumpShort(iodp, 'b', v->modeBits); - if (!code) code = DumpInt32(iodp, 'p', v->parent); - if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); + return code; + if (!code) + code = DumpByte(iodp, 't', (byte) v->type); + if (!code) + code = DumpShort(iodp, 'l', v->linkCount); /* May not need this */ + if (!code) + code = DumpInt32(iodp, 'v', v->dataVersion); + if (!code) + code = DumpInt32(iodp, 'm', v->unixModifyTime); + if (!code) + code = DumpInt32(iodp, 'a', v->author); + if (!code) + code = DumpInt32(iodp, 'o', v->owner); + if (!code && v->group) + code = DumpInt32(iodp, 'g', v->group); /* default group is 0 */ + if (!code) + code = DumpShort(iodp, 'b', v->modeBits); + if (!code) + code = DumpInt32(iodp, 'p', v->parent); + if (!code) + code = DumpInt32(iodp, 's', v->serverModifyTime); if (v->type == vDirectory) { acl_HtonACL(VVnodeDiskACL(v)); - if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); + if (!code) + code = + DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), + VAclDiskSize(v)); } if (VNDISK_GET_INO(v)) { IH_INIT(ihP, iodp->device, iodp->parentId, VNDISK_GET_INO(v)); fdP = IH_OPEN(ihP); if (fdP == NULL) { - Log("1 Volser: DumpVnode: dump: Unable to open inode %d for vnode %d (volume %d); not dumped, error %d\n", - VNDISK_GET_INO(v), vnodeNumber, volid, errno); + Log("1 Volser: DumpVnode: dump: Unable to open inode %llu for vnode %u (volume %i); not dumped, error %d\n", (afs_uintmax_t) VNDISK_GET_INO(v), vnodeNumber, volid, errno); IH_RELEASE(ihP); return VOLSERREAD_DUMPERROR; } - code = DumpFile(iodp, 'f', vnodeNumber, fdP); + code = DumpFile(iodp, vnodeNumber, fdP); FDH_CLOSE(fdP); IH_RELEASE(ihP); } @@ -728,64 +896,67 @@ static int DumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, } -int ProcessIndex(Volume *vp, VnodeClass class, afs_int32 **Bufp, int *sizep, - int del) +int +ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep, + int del) { - int i, nVnodes, offset, code, index=0; + int i, nVnodes, offset, code, index = 0; afs_int32 *Buf; - int cnt=0; + int cnt = 0; int size; StreamHandle_t *afile; FdHandle_t *fdP; struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; char buf[SIZEOF_LARGEDISKVNODE], zero[SIZEOF_LARGEDISKVNODE]; - register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; - + register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; + memset(zero, 0, sizeof(zero)); /* zero out our proto-vnode */ fdP = IH_OPEN(vp->vnodeIndex[class].handle); if (fdP == NULL) return -1; afile = FDH_FDOPEN(fdP, "r+"); if (del) { - int cnt1=0; + int cnt1 = 0; Buf = *Bufp; - for (i = 0; i<*sizep; i++) { + for (i = 0; i < *sizep; i++) { if (Buf[i]) { cnt++; - STREAM_SEEK(afile, Buf[i], 0); + STREAM_SEEK(afile, Buf[i], 0); code = STREAM_READ(vnode, vcp->diskSize, 1, afile); if (code == 1) { if (vnode->type != vNull && VNDISK_GET_INO(vnode)) { cnt1++; if (DoLogging) { - Log("RestoreVolume %d Cleanup: Removing old vnode=%d inode=%d size=%d\n", - V_id(vp), bitNumberToVnodeNumber(i,class), - VNDISK_GET_INO(vnode), vnode->length); + Log("RestoreVolume %u Cleanup: Removing old vnode=%u inode=%llu size=unknown\n", + V_id(vp), bitNumberToVnodeNumber(i, class), + (afs_uintmax_t) VNDISK_GET_INO(vnode)); } IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(vnode), - V_parentId(vp)); + V_parentId(vp)); DOPOLL; } STREAM_SEEK(afile, Buf[i], 0); - (void ) STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */ + (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */ } Buf[i] = 0; } } if (DoLogging) { - Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n", - cnt1, V_id(vp)); + Log("RestoreVolume Cleanup: Removed %d inodes for volume %d\n", + cnt1, V_id(vp)); } - STREAM_FLUSH(afile); /* ensure 0s are on the disk */ + STREAM_FLUSH(afile); /* ensure 0s are on the disk */ OS_SYNC(afile->str_fd); } else { size = OS_SIZE(fdP->fd_fd); assert(size != -1); - nVnodes = (size <= vcp->diskSize ? 0 : - size-vcp->diskSize) >> vcp->logSize; + nVnodes = + (size <= + vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize; if (nVnodes > 0) { Buf = (afs_int32 *) malloc(nVnodes * sizeof(afs_int32)); - if (Buf == NULL) return 1; + if (Buf == NULL) + return 1; memset((char *)Buf, 0, nVnodes * sizeof(afs_int32)); STREAM_SEEK(afile, offset = vcp->diskSize, 0); while (1) { @@ -794,7 +965,7 @@ int ProcessIndex(Volume *vp, VnodeClass class, afs_int32 **Bufp, int *sizep, break; } if (vnode->type != vNull && VNDISK_GET_INO(vnode)) { - Buf[(offset >> vcp->logSize)-1] = offset; + Buf[(offset >> vcp->logSize) - 1] = offset; cnt++; } offset += vcp->diskSize; @@ -809,8 +980,9 @@ int ProcessIndex(Volume *vp, VnodeClass class, afs_int32 **Bufp, int *sizep, } -int RestoreVolume(register struct rx_call *call, Volume *avp, - int incremental, struct restoreCookie *cookie) +int +RestoreVolume(register struct rx_call *call, Volume * avp, int incremental, + struct restoreCookie *cookie) { VolumeDiskData vol; struct DumpHeader header; @@ -819,56 +991,61 @@ int RestoreVolume(register struct rx_call *call, Volume *avp, register Volume *vp; struct iod iod; register struct iod *iodp = &iod; - afs_int32 *b1=0, *b2=0; - int s1=0, s2=0, delo=0, tdelo; + afs_int32 *b1 = 0, *b2 = 0; + int s1 = 0, s2 = 0, delo = 0, tdelo; int tag; iod_Init(iodp, call); - + vp = avp; - if (!ReadDumpHeader(iodp, &header)){ + if (!ReadDumpHeader(iodp, &header)) { Log("1 Volser: RestoreVolume: Error reading header file for dump; aborted\n"); return VOLSERREAD_DUMPERROR; } - if (iod_getc(iodp) != D_VOLUMEHEADER){ + if (iod_getc(iodp) != D_VOLUMEHEADER) { Log("1 Volser: RestoreVolume: Volume header missing from dump; not restored\n"); return VOLSERREAD_DUMPERROR; } - if(ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) return VOLSERREAD_DUMPERROR; + if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) + return VOLSERREAD_DUMPERROR; delo = ProcessIndex(vp, vLarge, &b1, &s1, 0); - if (!delo) delo = ProcessIndex(vp, vSmall, &b2, &s2, 0); + if (!delo) + delo = ProcessIndex(vp, vSmall, &b2, &s2, 0); if (delo) { - if (b1) free((char *)b1); - if (b2) free((char *)b2); - b1 = b2 = 0; + if (b1) + free((char *)b1); + if (b2) + free((char *)b2); + b1 = b2 = 0; } - strncpy(vol.name,cookie->name,VOLSER_OLDMAXVOLNAME); + strncpy(vol.name, cookie->name, VOLSER_OLDMAXVOLNAME); vol.type = cookie->type; vol.cloneId = cookie->clone; vol.parentId = cookie->parent; - + tdelo = delo; while (1) { - if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) { - error = VOLSERREAD_DUMPERROR; - goto clean; - } - tag = iod_getc(iodp); - if (tag != D_VOLUMEHEADER) - break; - if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) { - error = VOLSERREAD_DUMPERROR; - goto out; - } - tdelo = -1; + if (ReadVnodes(iodp, vp, 0, b1, s1, b2, s2, tdelo)) { + error = VOLSERREAD_DUMPERROR; + goto clean; + } + tag = iod_getc(iodp); + if (tag != D_VOLUMEHEADER) + break; + if (ReadVolumeHeader(iodp, &vol) == VOLSERREAD_DUMPERROR) { + error = VOLSERREAD_DUMPERROR; + goto out; + } + tdelo = -1; } - if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic) || endMagic != DUMPENDMAGIC){ - Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n"); - error = VOLSERREAD_DUMPERROR; - goto clean; + if (tag != D_DUMPEND || !ReadInt32(iodp, &endMagic) + || endMagic != DUMPENDMAGIC) { + Log("1 Volser: RestoreVolume: End of dump not found; restore aborted\n"); + error = VOLSERREAD_DUMPERROR; + goto clean; } @@ -883,7 +1060,7 @@ int RestoreVolume(register struct rx_call *call, Volume *avp, ProcessIndex(vp, vSmall, &b2, &s2, 1); } - clean: + clean: ClearVolumeStats(&vol); CopyVolumeHeader(&vol, &V_disk(vp)); V_destroyMe(vp) = 0; @@ -893,93 +1070,99 @@ int RestoreVolume(register struct rx_call *call, Volume *avp, error = VOLSERREAD_DUMPERROR; goto out; } - out: + out: /* Free the malloced space above */ - if (b1) free((char *)b1); - if (b2) free((char *)b2); + if (b1) + free((char *)b1); + if (b2) + free((char *)b2); return error; } -static int ReadVnodes(register struct iod *iodp, Volume *vp, - int incremental, afs_int32 *Lbuf, afs_int32 s1, - afs_int32 *Sbuf, afs_int32 s2, afs_int32 delo) +static int +ReadVnodes(register struct iod *iodp, Volume * vp, int incremental, + afs_int32 * Lbuf, afs_int32 s1, afs_int32 * Sbuf, afs_int32 s2, + afs_int32 delo) { afs_int32 vnodeNumber; char buf[SIZEOF_LARGEDISKVNODE]; register tag; - struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; struct VnodeDiskObject oldvnode; int idx; VnodeClass class; struct VnodeClassInfo *vcp; IHandle_t *tmpH; FdHandle_t *fdP; - Inode nearInode; + Inode nearInode; tag = iod_getc(iodp); V_pref(vp, nearInode); while (tag == D_VNODE) { - int haveStuff = 0; - memset(buf, 0, sizeof (buf)); - if (!ReadInt32(iodp, (afs_uint32 *)&vnodeNumber)) + int haveStuff = 0; + memset(buf, 0, sizeof(buf)); + if (!ReadInt32(iodp, (afs_uint32 *) & vnodeNumber)) break; ReadInt32(iodp, &vnode->uniquifier); while ((tag = iod_getc(iodp)) > D_MAX && tag != EOF) { haveStuff = 1; switch (tag) { - case 't': - vnode->type = (VnodeType) iod_getc(iodp); - break; - case 'l': - { - unsigned short tlc; - ReadShort(iodp, &tlc); - vnode->linkCount = (signed int)tlc; - } - break; - case 'v': - ReadInt32(iodp, &vnode->dataVersion); - break; - case 'm': - ReadInt32(iodp, &vnode->unixModifyTime); - break; - case 's': - ReadInt32(iodp, &vnode->serverModifyTime); - break; - case 'a': - ReadInt32(iodp, &vnode->author); - break; - case 'o': - ReadInt32(iodp, &vnode->owner); - break; - case 'g': - ReadInt32(iodp, (afs_uint32 *)&vnode->group); - break; - case 'b': { + case 't': + vnode->type = (VnodeType) iod_getc(iodp); + break; + case 'l': + { + unsigned short tlc; + ReadShort(iodp, &tlc); + vnode->linkCount = (signed int)tlc; + } + break; + case 'v': + ReadInt32(iodp, &vnode->dataVersion); + break; + case 'm': + ReadInt32(iodp, &vnode->unixModifyTime); + break; + case 's': + ReadInt32(iodp, &vnode->serverModifyTime); + break; + case 'a': + ReadInt32(iodp, &vnode->author); + break; + case 'o': + ReadInt32(iodp, &vnode->owner); + break; + case 'g': + ReadInt32(iodp, (afs_uint32 *) & vnode->group); + break; + case 'b':{ unsigned short modeBits; ReadShort(iodp, &modeBits); vnode->modeBits = (unsigned int)modeBits; break; } - case 'p': - ReadInt32(iodp, &vnode->parent); - break; - case 'A': - ReadByteString(iodp, (byte *)VVnodeDiskACL(vnode), - VAclDiskSize(vnode)); - acl_NtohACL(VVnodeDiskACL(vnode)); - break; - case 'f': { + case 'p': + ReadInt32(iodp, &vnode->parent); + break; + case 'A': + ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode), + VAclDiskSize(vnode)); + acl_NtohACL(VVnodeDiskACL(vnode)); + break; +#ifdef AFS_LARGEFILE_ENV + case 'h': +#endif + case 'f':{ Inode ino; Error error; + afs_fsize_t vnodeLength; - ino = IH_CREATE(V_linkHandle(vp), - V_device(vp), - VPartitionPath(V_partition(vp)), - nearInode, V_parentId(vp), vnodeNumber, - vnode->uniquifier, - vnode->dataVersion); + ino = + IH_CREATE(V_linkHandle(vp), V_device(vp), + VPartitionPath(V_partition(vp)), nearInode, + V_parentId(vp), vnodeNumber, + vnode->uniquifier, vnode->dataVersion); if (!VALID_INO(ino)) { perror("unable to allocate inode"); Log("1 Volser: ReadVnodes: Restore aborted\n"); @@ -993,12 +1176,14 @@ static int ReadVnodes(register struct iod *iodp, Volume *vp, IH_RELEASE(tmpH); return VOLSERREAD_DUMPERROR; } - vnode->length = volser_WriteFile(vnodeNumber, iodp, fdP, - &error); + vnodeLength = + volser_WriteFile(vnodeNumber, iodp, fdP, tag, &error); + VNDISK_SET_LEN(vnode, vnodeLength); FDH_REALLYCLOSE(fdP); IH_RELEASE(tmpH); if (error) { - Log("1 Volser: ReadVnodes: IDEC inode %d\n", ino); + Log("1 Volser: ReadVnodes: IDEC inode %llu\n", + (afs_uintmax_t) ino); IH_DEC(V_linkHandle(vp), ino, V_parentId(vp)); return VOLSERREAD_DUMPERROR; } @@ -1008,16 +1193,18 @@ static int ReadVnodes(register struct iod *iodp, Volume *vp, } class = vnodeIdToClass(vnodeNumber); - vcp = &VnodeClassInfo[class]; + vcp = &VnodeClassInfo[class]; /* Mark this vnode as in this dump - so we don't delete it later */ if (!delo) { - idx = (vnodeIndexOffset(vcp,vnodeNumber) >> vcp->logSize) - 1; - if (class == vLarge) { - if (Lbuf && (idx < s1)) Lbuf[idx] = 0; - } else { - if (Sbuf && (idx < s2)) Sbuf[idx] = 0; - } + idx = (vnodeIndexOffset(vcp, vnodeNumber) >> vcp->logSize) - 1; + if (class == vLarge) { + if (Lbuf && (idx < s1)) + Lbuf[idx] = 0; + } else { + if (Sbuf && (idx < s2)) + Sbuf[idx] = 0; + } } if (haveStuff) { @@ -1026,19 +1213,22 @@ static int ReadVnodes(register struct iod *iodp, Volume *vp, Log("1 Volser: ReadVnodes: Error opening vnode index; restore aborted\n"); return VOLSERREAD_DUMPERROR; } - if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) < 0) { + if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) < + 0) { Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n"); FDH_REALLYCLOSE(fdP); return VOLSERREAD_DUMPERROR; } - if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) == sizeof(oldvnode)) { + if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) == + sizeof(oldvnode)) { if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) { IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode), - V_parentId(vp)); + V_parentId(vp)); } } vnode->vnodeMagic = vcp->magic; - if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) < 0) { + if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) < + 0) { Log("1 Volser: ReadVnodes: Error seeking into vnode index; restore aborted\n"); FDH_REALLYCLOSE(fdP); return VOLSERREAD_DUMPERROR; @@ -1062,38 +1252,59 @@ static int ReadVnodes(register struct iod *iodp, Volume *vp, * needing to read an ungetc'd character, since the ReadInt32 will have read * it instead. */ -static bit32 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t *handleP, - Error *status) +static afs_fsize_t +volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag, + Error * status) { afs_int32 code; - afs_uint32 filesize; - bit32 written=0; + afs_fsize_t filesize; + afs_fsize_t written = 0; register afs_uint32 size = 8192; - register afs_uint32 nbytes; + register afs_fsize_t nbytes; unsigned char *p; *status = 0; +#ifdef AFS_64BIT_ENV + { + afs_uint32 filesize_high = 0L, filesize_low = 0L; +#ifdef AFS_LARGEFILE_ENV + if (tag == 'h') { + if (!ReadInt32(iodp, &filesize_high)) { + *status = 1; + return 0; + } + } +#endif /* !AFS_LARGEFILE_ENV */ + if (!ReadInt32(iodp, &filesize_low)) { + *status = 1; + return 0; + } + FillInt64(filesize, filesize_high, filesize_low); + } +#else /* !AFS_64BIT_ENV */ if (!ReadInt32(iodp, &filesize)) { - *status = 1; - return(0); + *status = 1; + return (0); } - p = (unsigned char *) malloc(size); +#endif /* !AFS_64BIT_ENV */ + p = (unsigned char *)malloc(size); if (p == NULL) { - *status = 2; - return(0); + *status = 2; + return (0); } for (nbytes = filesize; nbytes; nbytes -= size) { if (nbytes < size) size = nbytes; - + if ((code = iod_Read(iodp, p, size)) != size) { - Log("1 Volser: WriteFile: Error reading dump file %d size=%d nbytes=%d (%d of %d); restore aborted\n", vn, filesize, nbytes, code, size); + Log("1 Volser: WriteFile: Error reading dump file %d size=%llu nbytes=%u (%d of %u); restore aborted\n", vn, (afs_uintmax_t) filesize, nbytes, code, size); *status = 3; break; } code = FDH_WRITE(handleP, p, size); - if (code > 0) written += code; + if (code > 0) + written += code; if (code != size) { Log("1 Volser: WriteFile: Error creating file in volume; restore aborted\n"); *status = 4; @@ -1101,39 +1312,40 @@ static bit32 volser_WriteFile(int vn, struct iod *iodp, FdHandle_t *handleP, } } free(p); - return(written); + return (written); } -static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp) +static int +ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp) { register tag; afs_uint32 beginMagic; if (iod_getc(iodp) != D_DUMPHEADER || !ReadInt32(iodp, &beginMagic) - || !ReadInt32(iodp, (afs_uint32 *)&hp->version) - || beginMagic != DUMPBEGINMAGIC - ) return 0; + || !ReadInt32(iodp, (afs_uint32 *) & hp->version) + || beginMagic != DUMPBEGINMAGIC) + return 0; hp->volumeId = 0; hp->nDumpTimes = 0; while ((tag = iod_getc(iodp)) > D_MAX) { - unsigned short arrayLength; - register int i; - switch(tag) { - case 'v': - if (!ReadInt32(iodp, &hp->volumeId)) - return 0; - break; - case 'n': - ReadString(iodp, hp->volumeName, sizeof(hp->volumeName)); - break; - case 't': - if (!ReadShort(iodp, &arrayLength)) + unsigned short arrayLength; + register int i; + switch (tag) { + case 'v': + if (!ReadInt32(iodp, &hp->volumeId)) + return 0; + break; + case 'n': + ReadString(iodp, hp->volumeName, sizeof(hp->volumeName)); + break; + case 't': + if (!ReadShort(iodp, &arrayLength)) + return 0; + hp->nDumpTimes = (arrayLength >> 1); + for (i = 0; i < hp->nDumpTimes; i++) + if (!ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].from) + || !ReadInt32(iodp, (afs_uint32 *) & hp->dumpTimes[i].to)) return 0; - hp->nDumpTimes = (arrayLength >> 1); - for (i = 0; inDumpTimes; i++) - if (!ReadInt32(iodp, (afs_uint32 *)&hp->dumpTimes[i].from) - || !ReadInt32(iodp, (afs_uint32 *)&hp->dumpTimes[i].to)) - return 0; - break; + break; } } if (!hp->volumeId || !hp->nDumpTimes) { @@ -1142,3 +1354,284 @@ static int ReadDumpHeader(register struct iod *iodp, struct DumpHeader *hp) iod_ungetc(iodp, tag); return 1; } + + +/* ----- Below are the calls that calculate dump size ----- */ + +static int +SizeDumpVolumeHeader(register struct iod *iodp, register Volume * vp, + register struct volintSize *v_size) +{ + int code = 0; + static char nullString[1] = ""; /*The ``contents'' of motd */ + afs_uint64 addvar; + +/* if (!code) code = DumpTag(iodp, D_VOLUMEHEADER); */ + FillInt64(addvar,0, 1); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) {code = DumpInt32(iodp, 'i',V_id(vp));} */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'v',V_stamp(vp).version); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */ + FillInt64(addvar,0, (2 + strlen(V_name(vp)))); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpBool(iodp, 's',V_inService(vp)); */ + FillInt64(addvar,0, 2); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpBool(iodp, 'b',V_blessed(vp)); */ + FillInt64(addvar,0, 2); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'u',V_uniquifier(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpByte(iodp, 't',(byte)V_type(vp)); */ + FillInt64(addvar,0, 2); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code){ code = DumpInt32(iodp, 'p',V_parentId(vp));} */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'c',V_cloneId(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'q',V_maxquota(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'm',V_minquota(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'd',V_diskused(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'f',V_filecount(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'a', V_accountNumber(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'o', V_owner(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'C',V_creationDate(vp)); /\* Rw volume creation date *\/ */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'A',V_accessDate(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'U',V_updateDate(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'E',V_expirationDate(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'B',V_backupDate(vp)); /\* Rw volume backup clone date *\/ */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpString(iodp, 'O',V_offlineMessage(vp)); */ + FillInt64(addvar,0, (2 + strlen(V_offlineMessage(vp)))); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* /\* */ +/* * We do NOT dump the detailed volume statistics residing in the old */ +/* * motd field, since we cannot tell from the info in a dump whether */ +/* * statistics data has been put there. Instead, we dump a null string, */ +/* * just as if that was what the motd contained. */ +/* *\/ */ +/* if (!code) code = DumpString(iodp, 'M', nullString); */ + FillInt64(addvar,0, (2 + strlen(nullString))); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpArrayInt32(iodp, 'W', (afs_uint32 *)V_weekUse(vp), sizeof(V_weekUse(vp))/sizeof(V_weekUse(vp)[0])); */ + FillInt64(addvar,0, (3 + 4 * (sizeof(V_weekUse(vp)) / sizeof(V_weekUse(vp)[0])))); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'D', V_dayUseDate(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'Z', V_dayUse(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); + return code; +} + +static int +SizeDumpEnd(register struct iod *iodp, register struct volintSize *v_size) +{ + int code = 0; + afs_uint64 addvar; + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); + return code; +} + +int +SizeDumpVolume(register struct rx_call *call, register Volume * vp, + afs_int32 fromtime, int dumpAllDirs, + register struct volintSize *v_size) +{ + int code = 0; + register struct iod *iodp = (struct iod *)0; +/* iod_Init(iodp, call); */ + + if (!code) + code = SizeDumpDumpHeader(iodp, vp, fromtime, v_size); + if (!code) + code = SizeDumpPartial(iodp, vp, fromtime, dumpAllDirs, v_size); + if (!code) + code = SizeDumpEnd(iodp, v_size); + + return code; +} + +static int +SizeDumpDumpHeader(register struct iod *iodp, register Volume * vp, + afs_int32 fromtime, register struct volintSize *v_size) +{ + int code = 0; + int UseLatestReadOnlyClone = 1; +/* afs_int32 dumpTimes[2]; */ + afs_uint64 addvar; +/* iodp->device = vp->device; */ +/* iodp->parentId = V_parentId(vp); */ +/* iodp->dumpPartition = vp->partition; */ + + ZeroInt64(v_size->dump_size); /* initialize the size */ +/* if (!code) code = DumpDouble(iodp, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); */ + FillInt64(addvar,0, 9); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'v', UseLatestReadOnlyClone? V_id(vp): V_parentId(vp)); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpString(iodp, 'n',V_name(vp)); */ + FillInt64(addvar,0, (2 + strlen(V_name(vp)))); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* dumpTimes[0] = fromtime; */ +/* dumpTimes[1] = V_backupDate(vp); /\* Until the time the clone was made *\/ */ +/* if (!code) code = DumpArrayInt32(iodp, 't', (afs_uint32 *)dumpTimes, 2); */ + FillInt64(addvar,0, (3 + 4 * 2)); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); + return code; +} + +static int +SizeDumpVnode(register struct iod *iodp, struct VnodeDiskObject *v, int volid, + int vnodeNumber, int dumpEverything, + register struct volintSize *v_size) +{ + int code = 0; + afs_uint64 addvar; + + if (!v || v->type == vNull) + return code; +/* if (!code) code = DumpDouble(iodp, D_VNODE, vnodeNumber, v->uniquifier); */ + FillInt64(addvar,0, 9); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); + if (!dumpEverything) + return code; +/* if (!code) code = DumpByte(iodp, 't',(byte)v->type); */ + FillInt64(addvar,0, 2); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpShort(iodp, 'l', v->linkCount); /\* May not need this *\/ */ + FillInt64(addvar,0, 3); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'v', v->dataVersion); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'm', v->unixModifyTime); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'a', v->author); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'o', v->owner); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code && v->group) code = DumpInt32(iodp, 'g', v->group); /\* default group is 0 *\/ */ + if (v->group) { + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); + } +/* if (!code) code = DumpShort(iodp, 'b', v->modeBits); */ + FillInt64(addvar,0, 3); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 'p', v->parent); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); +/* if (!code) code = DumpInt32(iodp, 's', v->serverModifyTime); */ + FillInt64(addvar,0, 5); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); + if (v->type == vDirectory) { +/* acl_HtonACL(VVnodeDiskACL(v)); */ +/* if (!code) code = DumpByteString(iodp, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); */ + FillInt64(addvar,0, (1 + VAclDiskSize(v))); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); + } + + if (VNDISK_GET_INO(v)) { + FillInt64(addvar,0, (v->length + 5)); + AddUInt64(v_size->dump_size, addvar, &v_size->dump_size); + } + return code; +} + +/* A partial dump (no dump header) */ +static int +SizeDumpPartial(register struct iod *iodp, register Volume * vp, + afs_int32 fromtime, int dumpAllDirs, + register struct volintSize *v_size) +{ + int code = 0; + if (!code) + code = SizeDumpVolumeHeader(iodp, vp, v_size); + if (!code) + code = + SizeDumpVnodeIndex(iodp, vp, vLarge, fromtime, dumpAllDirs, + v_size); + if (!code) + code = SizeDumpVnodeIndex(iodp, vp, vSmall, fromtime, 0, v_size); + return code; +} + +static int +SizeDumpVnodeIndex(register struct iod *iodp, Volume * vp, VnodeClass class, + afs_int32 fromtime, int forcedump, + register struct volintSize *v_size) +{ + register int code = 0; + register struct VnodeClassInfo *vcp = &VnodeClassInfo[class]; + char buf[SIZEOF_LARGEDISKVNODE]; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; + StreamHandle_t *file; + FdHandle_t *fdP; + int size; + int flag; + register int vnodeIndex, nVnodes; + + fdP = IH_OPEN(vp->vnodeIndex[class].handle); + assert(fdP != NULL); + file = FDH_FDOPEN(fdP, "r+"); + assert(file != NULL); + size = OS_SIZE(fdP->fd_fd); + assert(size != -1); + nVnodes = (size / vcp->diskSize) - 1; + if (nVnodes > 0) { + assert((nVnodes + 1) * vcp->diskSize == size); + assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0); + } else + nVnodes = 0; + for (vnodeIndex = 0; + nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1 && !code; + nVnodes--, vnodeIndex++) { + flag = forcedump || (vnode->serverModifyTime >= fromtime); + /* Note: the >= test is very important since some old volumes may not have + * a serverModifyTime. For an epoch dump, this results in 0>=0 test, which + * does dump the file! */ + if (!code) + code = + SizeDumpVnode(iodp, vnode, V_id(vp), + bitNumberToVnodeNumber(vnodeIndex, class), flag, + v_size); + } + STREAM_CLOSE(file); + FDH_CLOSE(fdP); + return code; +} diff --git a/src/volser/lockdata.h b/src/volser/lockdata.h index 074d7b517..7c8df8b8c 100644 --- a/src/volser/lockdata.h +++ b/src/volser/lockdata.h @@ -10,12 +10,12 @@ #ifndef _LOCKDATA_ #define _LOCKDATA_ 1 -#define ZERO 2147617029 /*to be replaced by 0L */ +#define ZERO 2147617029 /*to be replaced by 0L */ #define N_SECURITY_OBJECTS 1 struct aqueue { - char name[VOLSER_MAXVOLNAME];/* related to max volname allowed in the vldb */ + char name[VOLSER_MAXVOLNAME]; /* related to max volname allowed in the vldb */ afs_int32 ids[3]; afs_int32 copyDate[3]; int isValid[3]; diff --git a/src/volser/lockprocs.c b/src/volser/lockprocs.c index f2397c86a..9d175bd25 100644 --- a/src/volser/lockprocs.c +++ b/src/volser/lockprocs.c @@ -17,7 +17,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/lockprocs.c,v 1.1.1.6 2001/10/14 18:07:29 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/lockprocs.c,v 1.8 2003/07/15 23:17:48 shadow Exp $"); #include #ifdef AFS_NT40_ENV @@ -25,6 +26,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/lockprocs.c,v 1.1.1.6 2001/10/14 #else #include #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include #include #include @@ -40,124 +48,126 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/lockprocs.c,v 1.1.1.6 2001/10/14 * If server is zero, will match first index of ANY server and partition * Zero is a valid partition field. */ -int FindIndex(entry, server, part, type) - struct nvldbentry *entry; - afs_int32 server, part, type; +int +FindIndex(entry, server, part, type) + struct nvldbentry *entry; + afs_int32 server, part, type; { int e; afs_int32 error = 0; - for (e=0; (e < entry->nServers) && !error; e++) { + for (e = 0; (e < entry->nServers) && !error; e++) { if (!type || (entry->serverFlags[e] & type)) { - if ( (!server || (entry->serverPartition[e] == part)) && - (!server || VLDB_IsSameAddrs(entry->serverNumber[e],server,&error)) ) - break; - if (type == ITSRWVOL) - return -1; /* quit when we are looking for RW entry (there's only 1) */ + if ((!server || (entry->serverPartition[e] == part)) + && (!server + || VLDB_IsSameAddrs(entry->serverNumber[e], server, + &error))) + break; + if (type == ITSRWVOL) + return -1; /* quit when we are looking for RW entry (there's only 1) */ } } if (error) { - fprintf(STDERR, - "Failed to get info about server's %d address(es) from vlserver (err=%d)\n", - entry->serverNumber[e], error); - return -1; + fprintf(STDERR, + "Failed to get info about server's %d address(es) from vlserver (err=%d)\n", + entry->serverNumber[e], error); + return -1; } if (e >= entry->nServers) - return -1; /* Didn't find it */ + return -1; /* Didn't find it */ - return e; /* return the index */ + return e; /* return the index */ } /* Changes the rw site only */ void -SetAValue (entry, oserver, opart, nserver, npart, type) +SetAValue(entry, oserver, opart, nserver, npart, type) struct nvldbentry *entry; - afs_int32 oserver, opart, nserver, npart, type; + afs_int32 oserver, opart, nserver, npart, type; { int e; afs_int32 error = 0; e = FindIndex(entry, oserver, opart, type); if (e == -1) - return; /* If didn't find it, just return */ + return; /* If didn't find it, just return */ - entry->serverNumber[e] = nserver; + entry->serverNumber[e] = nserver; entry->serverPartition[e] = npart; /* Now move rest of entries up */ if ((nserver == 0L) && (npart == 0L)) { - for (e++; enServers; e++) { - entry->serverNumber[e-1] = entry->serverNumber[e]; - entry->serverPartition[e-1] = entry->serverPartition[e]; - entry->serverFlags[e-1] = entry->serverFlags[e]; - } + for (e++; e < entry->nServers; e++) { + entry->serverNumber[e - 1] = entry->serverNumber[e]; + entry->serverPartition[e - 1] = entry->serverPartition[e]; + entry->serverFlags[e - 1] = entry->serverFlags[e]; + } } } /* Changes the RW site only */ -Lp_SetRWValue (entry, oserver, opart, nserver, npart) +Lp_SetRWValue(entry, oserver, opart, nserver, npart) struct nvldbentry *entry; - afs_int32 oserver, opart, nserver, npart; + afs_int32 oserver, opart, nserver, npart; { - SetAValue (entry, oserver, opart, nserver, npart, ITSRWVOL); + SetAValue(entry, oserver, opart, nserver, npart, ITSRWVOL); } /* Changes the RO site only */ Lp_SetROValue(entry, oserver, opart, nserver, npart) struct nvldbentry *entry; - afs_int32 oserver, opart, nserver, npart; + afs_int32 oserver, opart, nserver, npart; { - SetAValue (entry, oserver, opart, nserver, npart, ITSROVOL); + SetAValue(entry, oserver, opart, nserver, npart, ITSROVOL); } /* Returns success if this server and partition matches the RW entry */ Lp_Match(server, part, entry) - afs_int32 server, part; - struct nvldbentry *entry; + afs_int32 server, part; + struct nvldbentry *entry; { if (FindIndex(entry, server, part, ITSRWVOL) == -1) - return 0; + return 0; return 1; } /* Return the index of the RO entry (plus 1) if it exists, else return 0 */ Lp_ROMatch(server, part, entry) - afs_int32 server, part; + afs_int32 server, part; struct nvldbentry *entry; { - return (FindIndex(entry,server,part,ITSROVOL) + 1); + return (FindIndex(entry, server, part, ITSROVOL) + 1); } /* Return the index of the RW entry if it exists, else return -1 */ Lp_GetRwIndex(entry) struct nvldbentry *entry; { - return (FindIndex(entry,0,0,ITSRWVOL)); + return (FindIndex(entry, 0, 0, ITSRWVOL)); } /*initialize queue pointed by */ Lp_QInit(ahead) struct qHead *ahead; { - ahead->count = 0; - ahead->next = (struct aqueue *)0; + ahead->count = 0; + ahead->next = NULL; } /*add in front of queue */ -Lp_QAdd(ahead,elem) +Lp_QAdd(ahead, elem) struct qHead *ahead; struct aqueue *elem; { struct aqueue *temp; - if(ahead->count == 0) { + if (ahead->count == 0) { ahead->count += 1; ahead->next = elem; - elem->next = (struct aqueue *)0; - } - else { + elem->next = NULL; + } else { temp = ahead->next; ahead->count += 1; ahead->next = elem; @@ -165,16 +175,17 @@ Lp_QAdd(ahead,elem) } } -Lp_QScan(ahead,id,success, elem) +Lp_QScan(ahead, id, success, elem) struct qHead *ahead; struct aqueue **elem; afs_int32 id; int *success; -{ struct aqueue *cptr; +{ + struct aqueue *cptr; cptr = ahead->next; - while(cptr != (struct aqueue *)0) { - if(cptr->ids[RWVOL] == id) { + while (cptr != NULL) { + if (cptr->ids[RWVOL] == id) { *success = 1; *elem = cptr; return 0; @@ -187,7 +198,7 @@ Lp_QScan(ahead,id,success, elem) /*return the element in the beginning of the queue , free *the space used by that element . indicates if enumeration was ok*/ -Lp_QEnumerate(ahead,success, elem) +Lp_QEnumerate(ahead, success, elem) struct qHead *ahead; struct aqueue *elem; int *success; @@ -195,21 +206,20 @@ Lp_QEnumerate(ahead,success, elem) int i; struct aqueue *temp; - if(ahead->count > 0) {/*more elements left */ + if (ahead->count > 0) { /*more elements left */ ahead->count -= 1; temp = ahead->next; ahead->next = ahead->next->next; - strncpy(elem->name,temp->name,VOLSER_OLDMAXVOLNAME); - for(i= 0; i < 3; i++){ + strncpy(elem->name, temp->name, VOLSER_OLDMAXVOLNAME); + for (i = 0; i < 3; i++) { elem->ids[i] = temp->ids[i]; elem->copyDate[i] = temp->copyDate[i]; elem->isValid[i] = temp->isValid[i]; } - elem->next = (struct aqueue *)0; + elem->next = NULL; *success = 1; free(temp); - } - else /*queue is empty*/ + } else /*queue is empty */ *success = 0; } @@ -222,25 +232,30 @@ Lp_QTraverse(ahead) old = ahead->next; new = old->next; count = ahead->count; - printf("traversing the internal queue, which groups all the related volumes on a per partition basis\n"); - while(count > 0) { + printf + ("traversing the internal queue, which groups all the related volumes on a per partition basis\n"); + while (count > 0) { printf("---------------------------\n"); - printf("%s RW-Id %u",old->name,old->ids[RWVOL]); - if(old->isValid[RWVOL]) + printf("%s RW-Id %lu", old->name, (unsigned long)old->ids[RWVOL]); + if (old->isValid[RWVOL]) printf(" valid "); - else printf(" invalid "); - printf("RO-Id %u",old->ids[ROVOL]); - if(old->isValid[ROVOL]) + else + printf(" invalid "); + printf("RO-Id %lu", (unsigned long)old->ids[ROVOL]); + if (old->isValid[ROVOL]) printf(" valid "); - else printf(" invalid "); - printf("BACKUP-Id %u",old->ids[BACKVOL]); - if(old->isValid[BACKVOL]) + else + printf(" invalid "); + printf("BACKUP-Id %lu", (unsigned long)old->ids[BACKVOL]); + if (old->isValid[BACKVOL]) printf(" valid "); - else printf(" invalid "); + else + printf(" invalid "); printf("\n"); printf("---------------------------\n"); old = new; - if(count != 1) new = new->next; + if (count != 1) + new = new->next; count--; } } diff --git a/src/volser/physio.c b/src/volser/physio.c index d4c70bcfd..f8f5a91f7 100644 --- a/src/volser/physio.c +++ b/src/volser/physio.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/physio.c,v 1.1.1.5 2001/09/11 14:35:54 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/physio.c,v 1.11 2003/12/09 23:07:57 shadow Exp $"); #include #ifdef AFS_NT40_ENV @@ -20,6 +21,13 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/physio.c,v 1.1.1.5 2001/09/11 14 #include #include #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #ifdef AFS_SUN5_ENV #include #endif @@ -35,10 +43,8 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/physio.c,v 1.1.1.5 2001/09/11 14 #include "vol.h" /* returns 0 on success, errno on failure */ -int ReallyRead (file, block, data) -DirHandle * file; -int block; -char * data; +int +ReallyRead(DirHandle * file, int block, char *data) { FdHandle_t *fdP; int code; @@ -48,7 +54,7 @@ char * data; code = errno; return code; } - if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) { + if (FDH_SEEK(fdP, block * AFS_PAGESIZE, SEEK_SET) < 0) { code = errno; FDH_REALLYCLOSE(fdP); return code; @@ -57,7 +63,7 @@ char * data; if (code != AFS_PAGESIZE) { if (code < 0) code = errno; - else + else code = EIO; FDH_REALLYCLOSE(fdP); return code; @@ -67,10 +73,8 @@ char * data; } /* returns 0 on success, errno on failure */ -int ReallyWrite (file, block, data) -DirHandle * file; -int block; -char * data; +int +ReallyWrite(DirHandle * file, int block, char *data) { FdHandle_t *fdP; extern int VolumeChanged; @@ -83,7 +87,7 @@ char * data; code = errno; return code; } - if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) { + if (FDH_SEEK(fdP, block * AFS_PAGESIZE, SEEK_SET) < 0) { code = errno; FDH_REALLYCLOSE(fdP); return code; @@ -92,7 +96,7 @@ char * data; if (code != AFS_PAGESIZE) { if (code < 0) code = errno; - else + else code = EIO; FDH_REALLYCLOSE(fdP); return code; @@ -106,11 +110,9 @@ char * data; * Create a handle to a directory entry and reference it (IH_INIT). * The handle needs to be dereferenced with the FidZap() routine. */ -SetSalvageDirHandle(dir, volume, device, inode) -DirHandle *dir; -afs_int32 volume; -Inode inode; -afs_int32 device; +void +SetSalvageDirHandle(DirHandle * dir, afs_int32 volume, afs_int32 device, + Inode inode) { private SalvageCacheCheck = 1; memset(dir, 0, sizeof(DirHandle)); @@ -121,58 +123,54 @@ afs_int32 device; IH_INIT(dir->dirh_handle, device, volume, inode); /* Always re-read for a new dirhandle */ - dir->dirh_cacheCheck = SalvageCacheCheck++; + dir->dirh_cacheCheck = SalvageCacheCheck++; } -FidZap (file) -DirHandle * file; - +void +FidZap(DirHandle * file) { IH_RELEASE(file->dirh_handle); memset(file, 0, sizeof(DirHandle)); } -FidZero (file) -DirHandle * file; - +void +FidZero(DirHandle * file) { memset(file, 0, sizeof(DirHandle)); } -FidEq (afile, bfile) -DirHandle * afile; -DirHandle * bfile; - +int +FidEq(DirHandle * afile, DirHandle * bfile) { - if (afile->dirh_volume != bfile->dirh_volume) return 0; - if (afile->dirh_device != bfile->dirh_device) return 0; - if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck) return 0; - if (afile->dirh_inode != bfile->dirh_inode) return 0; + if (afile->dirh_volume != bfile->dirh_volume) + return 0; + if (afile->dirh_device != bfile->dirh_device) + return 0; + if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck) + return 0; + if (afile->dirh_inode != bfile->dirh_inode) + return 0; return 1; } -FidVolEq (afile, vid) -DirHandle * afile; -afs_int32 vid; - +int +FidVolEq(DirHandle * afile, afs_int32 vid) { - if (afile->dirh_volume != vid) return 0; + if (afile->dirh_volume != vid) + return 0; return 1; } -FidCpy (tofile, fromfile) -DirHandle * tofile; -DirHandle * fromfile; - +void +FidCpy(DirHandle * tofile, DirHandle * fromfile) { *tofile = *fromfile; IH_COPY(tofile->dirh_handle, fromfile->dirh_handle); } -Die (msg) -char * msg; - +void +Die(char *msg) { - printf("%s\n",msg); - assert(1==2); + printf("%s\n", msg); + assert(1 == 2); } diff --git a/src/volser/restorevol.c b/src/volser/restorevol.c index f6f1d9eb6..8e4782245 100644 --- a/src/volser/restorevol.c +++ b/src/volser/restorevol.c @@ -42,7 +42,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/restorevol.c,v 1.1.1.5 2001/09/11 14:35:54 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/restorevol.c,v 1.13 2003/12/05 08:36:06 shadow Exp $"); #include #include @@ -64,6 +65,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/restorevol.c,v 1.1.1.5 2001/09/1 #include #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + + char rootdir[MAXPATHLEN]; char mntroot[MAXPATHLEN]; #define ADIR "AFSDir-" @@ -71,856 +81,913 @@ char mntroot[MAXPATHLEN]; #define ODIR "__ORPHANEDIR__." #define OFILE "__ORPHANFILE__." -int inc_dump = 0; +int inc_dump = 0; FILE *dumpfile; -afs_int32 readvalue(size) +afs_int32 +readvalue(size) { - afs_int32 value, s; - int code; - char *ptr; - - value = 0; - ptr = (char *) &value; - - s = sizeof(value) - size; - if (size < 0) { - fprintf (stderr, "Too much data in afs_int32\n"); - return 0; - } - - code = fread (&ptr[s], 1, size, dumpfile); - if (code != size) fprintf (stderr, "Code = %d; Errno = %d\n", code, errno); - - return (value); + afs_int32 value, s; + int code; + char *ptr; + + value = 0; + ptr = (char *)&value; + + s = sizeof(value) - size; + if (size < 0) { + fprintf(stderr, "Too much data in afs_int32\n"); + return 0; + } + + code = fread(&ptr[s], 1, size, dumpfile); + if (code != size) + fprintf(stderr, "Code = %d; Errno = %d\n", code, errno); + + return (value); } -char readchar() +char +readchar() { - char value; - int code; - char *ptr; + char value; + int code; + char *ptr; - value = '\0'; - code = fread (&value, 1, 1, dumpfile); - if (code != 1) fprintf (stderr, "Code = %d; Errno = %d\n", code, errno); + value = '\0'; + code = fread(&value, 1, 1, dumpfile); + if (code != 1) + fprintf(stderr, "Code = %d; Errno = %d\n", code, errno); - return (value); + return (value); } #define BUFSIZE 16384 char buf[BUFSIZE]; -char readdata(buffer, size) - char *buffer; - afs_int32 size; +char +readdata(buffer, size) + char *buffer; + afs_sfsize_t size; { - int code; - afs_int32 s; - - if (!buffer) { - while (size > 0) { - s = ((size > BUFSIZE) ? BUFSIZE : size); - code = fread(buf, 1, s, dumpfile); - if (code != s) fprintf (stderr, "Code = %d; Errno = %d\n", code, errno); - size -= s; - } - } - else { - code = fread (buffer, 1, size, dumpfile); - if (code != size) { - if (code < 0) - fprintf (stderr, "Code = %d; Errno = %d\n", code, errno); - else - fprintf (stderr, "Read %d bytes out of %d\n", code, size); - } - if ((code >= 0) && (code < BUFSIZE)) - buffer[size] = 0; /* Add null char at end */ - } + int code; + afs_int32 s; + + if (!buffer) { + while (size > 0) { + s = (afs_int32) ((size > BUFSIZE) ? BUFSIZE : size); + code = fread(buf, 1, s, dumpfile); + if (code != s) + fprintf(stderr, "Code = %d; Errno = %d\n", code, errno); + size -= s; + } + } else { + code = fread(buffer, 1, size, dumpfile); + if (code != size) { + if (code < 0) + fprintf(stderr, "Code = %d; Errno = %d\n", code, errno); + else + fprintf(stderr, "Read %d bytes out of %lld\n", code, (afs_uintmax_t)size); + } + if ((code >= 0) && (code < BUFSIZE)) + buffer[size] = 0; /* Add null char at end */ + } } -afs_int32 ReadDumpHeader(dh) - struct DumpHeader *dh; /* Defined in dump.h */ +afs_int32 +ReadDumpHeader(dh) + struct DumpHeader *dh; /* Defined in dump.h */ { - int code, i, done; - char tag, c; - afs_int32 magic; + int code, i, done; + char tag, c; + afs_int32 magic; /* memset(&dh, 0, sizeof(dh)); */ - magic = ntohl(readvalue(4)); - dh->version = ntohl(readvalue(4)); - - done = 0; - while (!done) { - tag = readchar(); - switch (tag) { - case 'v': - dh->volumeId = ntohl(readvalue(4)); - break; - - case 'n': - for (i=0, c='a'; c!='\0'; i++) { - dh->volumeName[i] = c = readchar(); - } - dh->volumeName[i] = c; - break; - - case 't': - dh->nDumpTimes = ntohl(readvalue(2)) >> 1; - for (i=0; inDumpTimes; i++) { - dh->dumpTimes[i].from = ntohl(readvalue(4)); - dh->dumpTimes[i].to = ntohl(readvalue(4)); - } - break; - - default: - done = 1; - break; - } - } - - return((afs_int32)tag); + magic = ntohl(readvalue(4)); + dh->version = ntohl(readvalue(4)); + + done = 0; + while (!done) { + tag = readchar(); + switch (tag) { + case 'v': + dh->volumeId = ntohl(readvalue(4)); + break; + + case 'n': + for (i = 0, c = 'a'; c != '\0'; i++) { + dh->volumeName[i] = c = readchar(); + } + dh->volumeName[i] = c; + break; + + case 't': + dh->nDumpTimes = ntohl(readvalue(2)) >> 1; + for (i = 0; i < dh->nDumpTimes; i++) { + dh->dumpTimes[i].from = ntohl(readvalue(4)); + dh->dumpTimes[i].to = ntohl(readvalue(4)); + } + break; + + default: + done = 1; + break; + } + } + + return ((afs_int32) tag); } -struct volumeHeader -{ - afs_int32 volumeId; - char volumeName[100]; - afs_int32 volType; - afs_int32 uniquifier; - afs_int32 parentVol; - afs_int32 cloneId; - afs_int32 maxQuota; - afs_int32 minQuota; - afs_int32 diskUsed; - afs_int32 fileCount; - afs_int32 accountNumber; - afs_int32 owner; - afs_int32 creationDate; - afs_int32 accessDate; - afs_int32 updateDate; - afs_int32 expirationDate; - afs_int32 backupDate; - afs_int32 dayUseDate; - afs_int32 dayUse; - afs_int32 weekCount; - afs_int32 weekUse[100]; /* weekCount of these */ - char motd[1024]; - int inService; - int blessed; - char message[1024]; +struct volumeHeader { + afs_int32 volumeId; + char volumeName[100]; + afs_int32 volType; + afs_int32 uniquifier; + afs_int32 parentVol; + afs_int32 cloneId; + afs_int32 maxQuota; + afs_int32 minQuota; + afs_int32 diskUsed; + afs_int32 fileCount; + afs_int32 accountNumber; + afs_int32 owner; + afs_int32 creationDate; + afs_int32 accessDate; + afs_int32 updateDate; + afs_int32 expirationDate; + afs_int32 backupDate; + afs_int32 dayUseDate; + afs_int32 dayUse; + afs_int32 weekCount; + afs_int32 weekUse[100]; /* weekCount of these */ + char motd[1024]; + int inService; + int blessed; + char message[1024]; }; -afs_int32 ReadVolumeHeader(count) - afs_int32 count; +afs_int32 +ReadVolumeHeader(count) + afs_int32 count; { - struct volumeHeader vh; - int code, i, done, entries; - char tag, c; + struct volumeHeader vh; + int code, i, done, entries; + char tag, c; /* memset(&vh, 0, sizeof(vh)); */ - done = 0; - while (!done) { - tag = readchar(); - switch (tag) { - case 'i': - vh.volumeId = ntohl(readvalue(4)); - break; - - case 'v': - ntohl(readvalue(4)); /* version stamp - ignore */ - break; - - case 'n': - for (i=0, c='a'; c!='\0'; i++) { - vh.volumeName[i] = c = readchar(); - } - vh.volumeName[i] = c; - break; - - case 's': - vh.inService = ntohl(readvalue(1)); - break; - - case 'b': - vh.blessed = ntohl(readvalue(1)); - break; - - case 'u': - vh.uniquifier = ntohl(readvalue(4)); - break; - - case 't': - vh.volType = ntohl(readvalue(1)); - break; - - case 'p': - vh.parentVol = ntohl(readvalue(4)); - break; - - case 'c': - vh.cloneId = ntohl(readvalue(4)); - break; - - case 'q': - vh.maxQuota = ntohl(readvalue(4)); - break; - - case 'm': - vh.minQuota = ntohl(readvalue(4)); - break; - - case 'd': - vh.diskUsed = ntohl(readvalue(4)); - break; - - case 'f': - vh.fileCount = ntohl(readvalue(4)); - break; - - case 'a': - vh.accountNumber = ntohl(readvalue(4)); - break; - - case 'o': - vh.owner = ntohl(readvalue(4)); - break; - - case 'C': - vh.creationDate = ntohl(readvalue(4)); - break; - - case 'A': - vh.accessDate = ntohl(readvalue(4)); - break; - - case 'U': - vh.updateDate = ntohl(readvalue(4)); - break; - - case 'E': - vh.expirationDate = ntohl(readvalue(4)); - break; - - case 'B': - vh.backupDate = ntohl(readvalue(4)); - break; - - case 'O': - for (i=0, c='a'; c!='\0'; i++) { - vh.message[i] = c = readchar(); - } - vh.volumeName[i] = c; - break; - - case 'W': - vh.weekCount = ntohl(readvalue(2)); - for (i=0; i". It's a symbolic link to its real dir. - * The parent dir and symbolic link to it must exist. - */ - vnode = ((vn.type == 2) ? vn.vnode : vn.parent); - if (vnode == 1) - sprintf(parentdir, "%s", rootdir); - else { - sprintf(parentdir, "%s/%s%d", rootdir, ADIR, vnode); - - len = readlink(parentdir, linkname, MAXNAMELEN); - if (len < 0) { + vn.dataSize = 0; + vn.vnode = 0; + vn.parent = 0; + vn.type = 0; + + vn.vnode = ntohl(readvalue(4)); + vn.uniquifier = ntohl(readvalue(4)); + + done = 0; + while (!done) { + tag = readchar(); + switch (tag) { + case 't': + vn.type = ntohl(readvalue(1)); + break; + + case 'l': + vn.linkCount = ntohl(readvalue(2)); + break; + + case 'v': + vn.dataVersion = ntohl(readvalue(4)); + break; + + case 'm': + vn.unixModTime = ntohl(readvalue(4)); + break; + + case 's': + vn.servModTime = ntohl(readvalue(4)); + break; + + case 'a': + vn.author = ntohl(readvalue(4)); + break; + + case 'o': + vn.owner = ntohl(readvalue(4)); + break; + + case 'g': + vn.group = ntohl(readvalue(4)); + break; + + case 'b': + vn.modebits = ntohl(readvalue(2)); + break; + + case 'p': + vn.parent = ntohl(readvalue(4)); + break; + + case 'A': + readdata(vn.acl, 192); /* Skip ACL data */ + break; + +#ifdef AFS_LARGEFILE_ENV + case 'h': + { + afs_uint32 hi, lo; + hi = ntohl(readvalue(4)); + lo = ntohl(readvalue(4)); + FillInt64(vn.dataSize, hi, lo); + } + goto common_vnode; +#endif /* !AFS_LARGEFILE_ENV */ + + case 'f': + vn.dataSize = ntohl(readvalue(4)); + + common_vnode: + /* parentdir is the name of this dir's vnode-file-link + * or this file's parent vnode-file-link. + * "./AFSDir-<#>". It's a symbolic link to its real dir. + * The parent dir and symbolic link to it must exist. + */ + vnode = ((vn.type == 2) ? vn.vnode : vn.parent); + if (vnode == 1) + strncpy(parentdir, rootdir, sizeof parentdir); + else { + afs_snprintf(parentdir, sizeof parentdir, "%s/%s%d", rootdir, + ADIR, vnode); + + len = readlink(parentdir, linkname, MAXNAMELEN); + if (len < 0) { /* parentdir does not exist. So create an orphan dir. * and then link the parentdir to the orphaned dir. */ - sprintf(linkname, "%s/%s%d", rootdir, ODIR, vnode); + afs_snprintf(linkname, sizeof linkname, "%s/%s%d", + rootdir, ODIR, vnode); code = mkdir(linkname, 0777); if ((code < 0) && (errno != EEXIST)) { - fprintf(stderr, "Error creating directory %s code=%d;%d\n", - linkname, code, errno); + fprintf(stderr, + "Error creating directory %s code=%d;%d\n", + linkname, code, errno); } - + /* Link the parentdir to it - now parentdir exists */ - sprintf(linkname, "%s%d/", ODIR, vnode); + afs_snprintf(linkname, sizeof linkname, "%s%d/", ODIR, + vnode); code = symlink(linkname, parentdir); if (code) { - fprintf(stderr, "Error creating symlink %s -> %s code=%d;%d\n", - parentdir, linkname, code, errno); + fprintf(stderr, + "Error creating symlink %s -> %s code=%d;%d\n", + parentdir, linkname, code, errno); } - } - } - - if (vn.type == 2) { - /*ITSADIR*/ - /* We read the directory entries. If the entry is a - * directory, the subdir is created and the root dir - * will contain a link to it. If its a file, we only - * create a symlink in the dir to the file name. - */ - char *buffer; - unsigned short j; - afs_int32 this_vn; - char *this_name; - - struct DirEntry - { - char flag; - char length; - unsigned short next; - struct MKFid - { - afs_int32 vnode; - afs_int32 vunique; - } fid; - char name[20]; - }; - - struct Pageheader - { - unsigned short pgcount; - unsigned short tag; - char freecount; - char freebitmap[8]; - char padding[19]; - }; - - struct DirHeader - { - struct Pageheader header; - char alloMap[128]; - unsigned short hashTable[128]; - }; - - struct Page0 - { - struct DirHeader header; - struct DirEntry entry[1]; - } *page0; - - - buffer = (char *)0; - buffer = (char *)malloc(vn.dataSize); - - readdata(buffer, vn.dataSize); - page0 = (struct Page0 *)buffer; - - /* Step through each bucket in the hash table, i, - * and follow each element in the hash chain, j. - * This gives us each entry of the dir. - */ - for (i=0; i<128; i++) { - for (j=ntohs(page0->header.hashTable[i]); j; - j=ntohs(page0->entry[j].next)) { - j -= 13; - this_vn = ntohl(page0->entry[j].fid.vnode); + } + } + + if (vn.type == 2) { + /*ITSADIR*/ + /* We read the directory entries. If the entry is a + * directory, the subdir is created and the root dir + * will contain a link to it. If its a file, we only + * create a symlink in the dir to the file name. + */ + char *buffer; + unsigned short j; + afs_int32 this_vn; + char *this_name; + + struct DirEntry { + char flag; + char length; + unsigned short next; + struct MKFid { + afs_int32 vnode; + afs_int32 vunique; + } fid; + char name[20]; + }; + + struct Pageheader { + unsigned short pgcount; + unsigned short tag; + char freecount; + char freebitmap[8]; + char padding[19]; + }; + + struct DirHeader { + struct Pageheader header; + char alloMap[128]; + unsigned short hashTable[128]; + }; + + struct Page0 { + struct DirHeader header; + struct DirEntry entry[1]; + } *page0; + + + buffer = NULL; + buffer = (char *)malloc(vn.dataSize); + + readdata(buffer, vn.dataSize); + page0 = (struct Page0 *)buffer; + + /* Step through each bucket in the hash table, i, + * and follow each element in the hash chain, j. + * This gives us each entry of the dir. + */ + for (i = 0; i < 128; i++) { + for (j = ntohs(page0->header.hashTable[i]); j; + j = ntohs(page0->entry[j].next)) { + j -= 13; + this_vn = ntohl(page0->entry[j].fid.vnode); this_name = page0->entry[j].name; - if ((strcmp(this_name,"." ) == 0) || - (strcmp(this_name,"..") == 0)) - continue; /* Skip these */ + if ((strcmp(this_name, ".") == 0) + || (strcmp(this_name, "..") == 0)) + continue; /* Skip these */ /* For a directory entry, create it. Then create the * link (from the rootdir) to this directory. */ - if (this_vn & 1) { /*ADIRENTRY*/ - /* dirname is the directory to create. - * vflink is what will link to it. - */ - sprintf(dirname, "%s/%s", parentdir, this_name); - sprintf(vflink, "%s/%s%d", rootdir, ADIR, this_vn); - - /* The link and directory may already exist */ - len = readlink(vflink, linkname, MAXNAMELEN); - if (len < 0) { - /* Doesn't already exist - so create the directory. - * umask will pare the mode bits down. - */ - code = mkdir(dirname, 0777); - if ((code < 0) && (errno != EEXIST)) { - fprintf(stderr, "Error creating directory %s code=%d;%d\n", - dirname, code, errno); - } - } else { - /* Does already exist - so move the directory. - * It was created originally as orphaned. - */ - linkname[len-1] = '\0'; /* remove '/' at end */ - sprintf(lname, "%s/%s", rootdir, linkname); - code = rename(lname, dirname); - if (code) { - fprintf(stderr, "Error renaming %s to %s code=%d;%d\n", - lname, dirname, code, errno); - } - } - - /* Now create/update the link to the new/moved directory */ - if (vn.vnode == 1) - sprintf(dirname, "%s/", this_name); - else - sprintf(dirname, "%s%d/%s/", ADIR, vn.vnode, this_name); - unlink(vflink); - code = symlink(dirname, vflink); - if (code) { - fprintf(stderr, "Error creating symlink %s -> %s code=%d;%d\n", - vflink, dirname, code, errno); - } - } /*ADIRENTRY*/ - - /* For a file entry, we remember the name of the file - * by creating a link within the directory. Restoring - * the file will later remove the link. - */ - else { - /*AFILEENTRY*/ - sprintf(vflink, "%s/%s%d", parentdir, AFILE, this_vn); - - code = symlink(this_name, vflink); - if ((code < 0) && (errno != EEXIST)) { - fprintf(stderr, "Error creating symlink %s -> %s code=%d;%d\n", - vflink, page0->entry[j].name, code, errno); - } - } /*AFILEENTRY*/ - } - } - free(buffer); - } /*ITSADIR*/ - - else if (vn.type == 1) { - /*ITSAFILE*/ - /* A file vnode. So create it into the desired directory. A - * link should exist in the directory naming the file. - */ - int fid; - int lfile; - afs_int32 size, s; - - /* Check if its vnode-file-link exists. If not, - * then the file will be an orphaned file. - */ - lfile = 1; - sprintf(filename, "%s/%s%d", parentdir, AFILE, vn.vnode); - len = readlink(filename, fname, MAXNAMELEN); - if (len < 0) { - sprintf(filename, "%s/%s%d", rootdir, OFILE, vn.vnode); - lfile = 0; /* no longer a linked file; a direct path */ - } - - /* Create a mode for the file. Use the owner bits and - * duplicate them across group and other. The umask - * will remove what we don't want. - */ - mode = (vn.modebits >> 6) & 0x7; - mode |= (mode << 6) | (mode << 3); - - /* Write the file out */ - fid = open(filename, (O_CREAT | O_WRONLY | O_TRUNC), mode); - size = vn.dataSize; - while (size > 0) { - s = ((size > BUFSIZE) ? BUFSIZE : size); - code = fread(buf, 1, s, dumpfile); - if (code > 0) { - write(fid, buf, code); + if (this_vn & 1) { + /*ADIRENTRY*/ + /* dirname is the directory to create. + * vflink is what will link to it. + */ + afs_snprintf(dirname, sizeof dirname, "%s/%s", + parentdir, this_name); + afs_snprintf(vflink, sizeof vflink, "%s/%s%d", + rootdir, ADIR, this_vn); + + /* The link and directory may already exist */ + len = readlink(vflink, linkname, MAXNAMELEN); + if (len < 0) { + /* Doesn't already exist - so create the directory. + * umask will pare the mode bits down. + */ + code = mkdir(dirname, 0777); + if ((code < 0) && (errno != EEXIST)) { + fprintf(stderr, + "Error creating directory %s code=%d;%d\n", + dirname, code, errno); + } + } else { + /* Does already exist - so move the directory. + * It was created originally as orphaned. + */ + linkname[len - 1] = '\0'; /* remove '/' at end */ + afs_snprintf(lname, sizeof lname, "%s/%s", + rootdir, linkname); + code = rename(lname, dirname); + if (code) { + fprintf(stderr, + "Error renaming %s to %s code=%d;%d\n", + lname, dirname, code, errno); + } + } + + /* Now create/update the link to the new/moved directory */ + if (vn.vnode == 1) + afs_snprintf(dirname, sizeof dirname, "%s/", + this_name); + else + afs_snprintf(dirname, sizeof dirname, + "%s%d/%s/", ADIR, vn.vnode, + this_name); + unlink(vflink); + code = symlink(dirname, vflink); + if (code) { + fprintf(stderr, + "Error creating symlink %s -> %s code=%d;%d\n", + vflink, dirname, code, errno); + } + } + /*ADIRENTRY*/ + /* For a file entry, we remember the name of the file + * by creating a link within the directory. Restoring + * the file will later remove the link. + */ + else { + /*AFILEENTRY*/ afs_snprintf(vflink, + sizeof vflink, + "%s/%s%d", parentdir, + AFILE, this_vn); + + code = symlink(this_name, vflink); + if ((code < 0) && (errno != EEXIST)) { + fprintf(stderr, + "Error creating symlink %s -> %s code=%d;%d\n", + vflink, page0->entry[j].name, code, + errno); + } + } + /*AFILEENTRY*/} + } + free(buffer); + } + /*ITSADIR*/ + else if (vn.type == 1) { + /*ITSAFILE*/ + /* A file vnode. So create it into the desired directory. A + * link should exist in the directory naming the file. + */ + int fid; + int lfile; + afs_sfsize_t size, s; + + /* Check if its vnode-file-link exists. If not, + * then the file will be an orphaned file. + */ + lfile = 1; + afs_snprintf(filename, sizeof filename, "%s/%s%d", parentdir, + AFILE, vn.vnode); + len = readlink(filename, fname, MAXNAMELEN); + if (len < 0) { + afs_snprintf(filename, sizeof filename, "%s/%s%d", + rootdir, OFILE, vn.vnode); + lfile = 0; /* no longer a linked file; a direct path */ + } + + /* Create a mode for the file. Use the owner bits and + * duplicate them across group and other. The umask + * will remove what we don't want. + */ + mode = (vn.modebits >> 6) & 0x7; + mode |= (mode << 6) | (mode << 3); + + /* Write the file out */ + fid = open(filename, (O_CREAT | O_WRONLY | O_TRUNC), mode); + size = vn.dataSize; + while (size > 0) { + s = (afs_int32) ((size > BUFSIZE) ? BUFSIZE : size); + code = fread(buf, 1, s, dumpfile); + if (code > 0) { + (void)write(fid, buf, code); size -= code; - } - if (code != s) { - if (code < 0) - fprintf (stderr, "Code = %d; Errno = %d\n", code, errno); - else - fprintf (stderr, "Read %d bytes out of %d\n", - (vn.dataSize - size), vn.dataSize); + } + if (code != s) { + if (code < 0) + fprintf(stderr, "Code = %d; Errno = %d\n", code, + errno); + else { + char tmp[100]; + (void)afs_snprintf(tmp, sizeof tmp, + "Read %llu bytes out of %llu", + (afs_uintmax_t) (vn.dataSize - + size), + (afs_uintmax_t) vn.dataSize); + fprintf(stderr, "%s\n", tmp); + } break; - } - } - close(fid); - if (size != 0) { - fprintf(stderr, " File %s (%s) is incomplete\n", filename, fname); - } - - /* Remove the link to the file */ - if (lfile) { - unlink(filename); - } - } /*ITSAFILE*/ - - else if (vn.type == 3) { - /*ITSASYMLINK*/ - /* A symlink vnode. So read it into the desired directory. This could - * also be a mount point. If the volume is being restored to AFS, this - * will become a mountpoint. If not, it becomes a symlink to no-where. - */ - int fid; - afs_int32 size, s; - - /* Check if its vnode-file-link exists and create pathname - * of the symbolic link. If it doesn't exist, - * then the link will be an orphaned link. - */ - sprintf(linkname, "%s/%s%d", parentdir, AFILE, vn.vnode); - len = readlink(linkname, fname, MAXNAMELEN); - if (len < 0) { - sprintf(filename, "%s/%s%d", rootdir, OFILE, vn.vnode); - } else { - fname[len] = '\0'; - sprintf(filename, "%s/%s", parentdir, fname); - } - - /* Read the link in, delete it, and then create it */ - readdata(buf, vn.dataSize); - - /* If a mountpoint, change its link path to mountroot */ - s = strlen(buf); - if ( ((buf[0] == '%') || (buf[0] == '#')) && (buf[s-1] == '.') ) { - /* This is a symbolic link */ - buf[s-1] = 0; /* Remove prefix '.' */ - strcpy(lname, &buf[1]); /* Remove postfix '#' or '%' */ - strcpy(buf, mntroot); - strcat(buf, lname); - } - - unlink(filename); - code = symlink(buf, filename); - if (code) { - fprintf(stderr, "Error creating symlink %s -> %s code=%d;%d\n", - filename, buf, code, errno); - } - - /* Remove the symbolic link */ - unlink(linkname); - } /*ITSASYMLINK*/ - else { - fprintf (stderr, "Unknown Vnode block\n"); - } - break; - - default: - done = 1; - break; - } - } - if (vn.type == 0) - inc_dump = 1; - - return((afs_int32)tag); + } + } + close(fid); + if (size != 0) { + fprintf(stderr, " File %s (%s) is incomplete\n", + filename, fname); + } + + /* Remove the link to the file */ + if (lfile) { + unlink(filename); + } + } + /*ITSAFILE*/ + else if (vn.type == 3) { + /*ITSASYMLINK*/ + /* A symlink vnode. So read it into the desired directory. This could + * also be a mount point. If the volume is being restored to AFS, this + * will become a mountpoint. If not, it becomes a symlink to no-where. + */ + int fid; + afs_int32 size, s; + + /* Check if its vnode-file-link exists and create pathname + * of the symbolic link. If it doesn't exist, + * then the link will be an orphaned link. + */ + afs_snprintf(linkname, sizeof linkname, "%s/%s%d", parentdir, + AFILE, vn.vnode); + len = readlink(linkname, fname, MAXNAMELEN); + if (len < 0) { + afs_snprintf(filename, sizeof filename, "%s/%s%d", + rootdir, OFILE, vn.vnode); + } else { + fname[len] = '\0'; + afs_snprintf(filename, sizeof filename, "%s/%s", + parentdir, fname); + } + + /* Read the link in, delete it, and then create it */ + readdata(buf, vn.dataSize); + + /* If a mountpoint, change its link path to mountroot */ + s = strlen(buf); + if (((buf[0] == '%') || (buf[0] == '#')) + && (buf[s - 1] == '.')) { + /* This is a symbolic link */ + buf[s - 1] = 0; /* Remove prefix '.' */ + strcpy(lname, &buf[1]); /* Remove postfix '#' or '%' */ + strcpy(buf, mntroot); + strcat(buf, lname); + } + + unlink(filename); + code = symlink(buf, filename); + if (code) { + fprintf(stderr, + "Error creating symlink %s -> %s code=%d;%d\n", + filename, buf, code, errno); + } + + /* Remove the symbolic link */ + unlink(linkname); + } + /*ITSASYMLINK*/ + else { + fprintf(stderr, "Unknown Vnode block\n"); + } + break; + + default: + done = 1; + break; + } + } + if (vn.type == 0) + inc_dump = 1; + + return ((afs_int32) tag); } WorkerBee(as, arock) - struct cmd_syndesc *as; - char *arock; + struct cmd_syndesc *as; + char *arock; { - int code=0, c, len; - afs_int32 type, count, vcount; - DIR *dirP, *dirQ; - struct dirent *dirE, *dirF; - char fname[MAXNAMELEN], name[MAXNAMELEN], lname[MAXNAMELEN], mname[MAXNAMELEN]; - char thisdir[MAXPATHLEN], *t; - struct DumpHeader dh; /* Defined in dump.h */ -#if 0/*ndef HAVE_GETCWD*/ /* XXX enable when autoconf happens */ - extern char *getwd(); + int code = 0, c, len; + afs_int32 type, count, vcount; + DIR *dirP, *dirQ; + struct dirent *dirE, *dirF; + char fname[MAXNAMELEN], name[MAXNAMELEN], lname[MAXNAMELEN], + mname[MAXNAMELEN]; + char thisdir[MAXPATHLEN], *t; + struct DumpHeader dh; /* Defined in dump.h */ +#if 0/*ndef HAVE_GETCWD*/ /* XXX enable when autoconf happens */ + extern char *getwd(); #define getcwd(x,y) getwd(x) #endif - - if (as->parms[0].items) { /* -file */ - dumpfile = fopen(as->parms[0].items->data, "r"); - if (!dumpfile) { - fprintf(stderr, "Cannot open '%s'. Code = %d\n", - as->parms[0].items->data, errno); - goto cleanup; - } - } else { - dumpfile = (FILE *)stdin; /* use stdin */ - } - - /* Read the dump header. From it we get the volume name */ - type = ntohl(readvalue(1)); - if (type != 1) { - fprintf(stderr, "Expected DumpHeader\n"); - code = -1; - goto cleanup; - } - type = ReadDumpHeader(&dh); - - /* Get the root directory we restore to */ - if (as->parms[1].items) { /* -dir */ - strcpy(rootdir, as->parms[1].items->data); - } else { - strcpy(rootdir,"."); - } - strcat(rootdir,"/"); - - /* Append the RW volume name to the root directory */ - strcat(rootdir, dh.volumeName); - len = strlen(rootdir); - if (strcmp(".backup",rootdir+len-7) == 0) { - rootdir[len-7] = 0; - } else if (strcmp(".readonly",rootdir+len-9) == 0) { - rootdir[len-9] = 0; - } - - /* Append the extension we asked for */ - if (as->parms[2].items) { - strcat(rootdir, as->parms[2].items->data); /* -extension */ - } - - /* The mountpoint root is either specifid in -mountpoint - * or -dir or the current working dir. - */ - if ((as->parms[3].items) || (as->parms[1].items)) { /* -mountpoint or -dir*/ - t = (char *)getcwd(thisdir, MAXPATHLEN); /* remember current dir */ - if (!t) { - fprintf(stderr, "Cannot get pathname of current working directory: %s\n", - thisdir); - code = -1; - goto cleanup; - } - /* Change to the mount point dir */ - code = chdir((as->parms[3].items ? as->parms[3].items->data : - as->parms[1].items->data)); - if (code) { - fprintf(stderr, "Mount point directory not found: Error = %d\n", stderr); - goto cleanup; - } - t = (char *)getcwd(mntroot, MAXPATHLEN); /* get its full pathname */ - if (!t) { - fprintf(stderr, "Cannot determine pathname of mount point root directory: %s\n", - mntroot); + + if (as->parms[0].items) { /* -file */ + dumpfile = fopen(as->parms[0].items->data, "r"); + if (!dumpfile) { + fprintf(stderr, "Cannot open '%s'. Code = %d\n", + as->parms[0].items->data, errno); + goto cleanup; + } + } else { + dumpfile = (FILE *) stdin; /* use stdin */ + } + + /* Read the dump header. From it we get the volume name */ + type = ntohl(readvalue(1)); + if (type != 1) { + fprintf(stderr, "Expected DumpHeader\n"); code = -1; goto cleanup; - } - strcat(mntroot, "/"); /* append '/' to end of it */ - chdir(thisdir); /* return to original working dir */ - if (code) { - fprintf(stderr, "Cannot find working directory: Error = %d\n", stderr); - goto cleanup; - } - } else { /* use current directory */ - t = (char *)getcwd(mntroot, MAXPATHLEN); /* get full pathname of current dir */ - if (!t) { - fprintf(stderr, "Cannot determine pathname of current working directory: %s\n", - mntroot); + } + type = ReadDumpHeader(&dh); + + /* Get the root directory we restore to */ + if (as->parms[1].items) { /* -dir */ + strcpy(rootdir, as->parms[1].items->data); + } else { + strcpy(rootdir, "."); + } + strcat(rootdir, "/"); + + /* Append the RW volume name to the root directory */ + strcat(rootdir, dh.volumeName); + len = strlen(rootdir); + if (strcmp(".backup", rootdir + len - 7) == 0) { + rootdir[len - 7] = 0; + } else if (strcmp(".readonly", rootdir + len - 9) == 0) { + rootdir[len - 9] = 0; + } + + /* Append the extension we asked for */ + if (as->parms[2].items) { + strcat(rootdir, as->parms[2].items->data); /* -extension */ + } + + /* The mountpoint root is either specifid in -mountpoint + * or -dir or the current working dir. + */ + if ((as->parms[3].items) || (as->parms[1].items)) { /* -mountpoint or -dir */ + t = (char *)getcwd(thisdir, MAXPATHLEN); /* remember current dir */ + if (!t) { + fprintf(stderr, + "Cannot get pathname of current working directory: %s\n", + thisdir); + code = -1; + goto cleanup; + } + /* Change to the mount point dir */ + code = + chdir((as->parms[3].items ? as->parms[3].items->data : as-> + parms[1].items->data)); + if (code) { + fprintf(stderr, "Mount point directory not found: Error = %d\n", + errno); + goto cleanup; + } + t = (char *)getcwd(mntroot, MAXPATHLEN); /* get its full pathname */ + if (!t) { + fprintf(stderr, + "Cannot determine pathname of mount point root directory: %s\n", + mntroot); + code = -1; + goto cleanup; + } + strcat(mntroot, "/"); /* append '/' to end of it */ + code = chdir(thisdir); /* return to original working dir */ + if (code) { + fprintf(stderr, "Cannot find working directory: Error = %d\n", + errno); + goto cleanup; + } + } else { /* use current directory */ + t = (char *)getcwd(mntroot, MAXPATHLEN); /* get full pathname of current dir */ + if (!t) { + fprintf(stderr, + "Cannot determine pathname of current working directory: %s\n", + mntroot); + code = -1; + goto cleanup; + } + } + strcat(mntroot, "/"); /* append '/' to end of it */ + + /* Set the umask for the restore */ + if (as->parms[4].items) { /* -umask */ + afs_int32 mask; + mask = strtol(as->parms[4].items->data, 0, 8); + fprintf(stderr, "Umask set to 0%03o\n", mask); + umask(mask); + } + + fprintf(stderr, "Restoring volume dump of '%s' to directory '%s'.\n", + dh.volumeName, rootdir); + code = mkdir(rootdir, 0777); + if ((code < 0) && (errno != EEXIST)) { + fprintf(stderr, "Error creating directory %s code=%d;%d\n", rootdir, + code, errno); + } + + for (count = 1; type == 2; count++) { + type = ReadVolumeHeader(count); + for (vcount = 1; type == 3; vcount++) + type = ReadVNode(vcount); + } + + if (type != 4) { + fprintf(stderr, "Expected End-of-Dump\n"); code = -1; goto cleanup; - } - } - strcat(mntroot, "/"); /* append '/' to end of it */ - - /* Set the umask for the restore */ - if (as->parms[4].items) { /* -umask */ - afs_int32 mask; - mask = strtol(as->parms[4].items->data, 0, 8); - fprintf(stderr, "Umask set to 0%03o\n", mask); - umask(mask); - } - - fprintf(stderr, "Restoring volume dump of '%s' to directory '%s'.\n", - dh.volumeName, rootdir); - code = mkdir(rootdir, 0777); - if ((code < 0) && (errno != EEXIST)) { - fprintf(stderr, "Error creating directory %s code=%d;%d\n", - rootdir, code, errno); - } - - for (count=1; type==2; count++) { - type = ReadVolumeHeader(count); - for (vcount=1; type==3; vcount++) - type = ReadVNode(vcount); - } - - if (type != 4) { - fprintf(stderr, "Expected End-of-Dump\n"); - code = -1; - goto cleanup; - } - - cleanup: - /* For incremental restores, Follow each directory link and - * remove an "AFSFile" links. - */ - if (inc_dump) { - fprintf(stderr, "An incremental dump.\n"); - dirP = opendir(rootdir); - while (dirP && (dirE = readdir(dirP))) { - if (strncmp(dirE->d_name, ADIR, strlen(ADIR)) == 0) { - sprintf(name, "%s/%s", rootdir, dirE->d_name); - dirQ = opendir(name); - while (dirQ && (dirF = readdir(dirQ))) { - if (strncmp(dirF->d_name, AFILE, strlen(AFILE)) == 0) { - sprintf(name, "%s/%s/%s", rootdir, dirE->d_name, dirF->d_name); - unlink(name); - } - } - closedir(dirQ); - } else if (strncmp(dirE->d_name, AFILE, strlen(AFILE)) == 0) { - sprintf(name, "%s/%s", rootdir, dirE->d_name); - unlink(name); + } + + cleanup: + /* For incremental restores, Follow each directory link and + * remove an "AFSFile" links. + */ + if (inc_dump) { + fprintf(stderr, "An incremental dump.\n"); + dirP = opendir(rootdir); + while (dirP && (dirE = readdir(dirP))) { + if (strncmp(dirE->d_name, ADIR, strlen(ADIR)) == 0) { + afs_snprintf(name, sizeof name, "%s/%s", rootdir, + dirE->d_name); + dirQ = opendir(name); + while (dirQ && (dirF = readdir(dirQ))) { + if (strncmp(dirF->d_name, AFILE, strlen(AFILE)) == 0) { + afs_snprintf(name, sizeof name, "%s/%s/%s", rootdir, + dirE->d_name, dirF->d_name); + unlink(name); + } + } + closedir(dirQ); + } else if (strncmp(dirE->d_name, AFILE, strlen(AFILE)) == 0) { + afs_snprintf(name, sizeof name, "%s/%s", rootdir, + dirE->d_name); + unlink(name); + } } - } - closedir(dirP); - } - - /* Now go through and remove all the directory links */ - dirP = opendir(rootdir); - while (dirP && (dirE = readdir(dirP))) { - if (strncmp(dirE->d_name, ADIR, strlen(ADIR)) == 0) { - sprintf(name, "%s/%s", rootdir, dirE->d_name); - unlink(name); - } - } - closedir(dirP); - - return(code); + closedir(dirP); + } + + /* Now go through and remove all the directory links */ + dirP = opendir(rootdir); + while (dirP && (dirE = readdir(dirP))) { + if (strncmp(dirE->d_name, ADIR, strlen(ADIR)) == 0) { + afs_snprintf(name, sizeof name, "%s/%s", rootdir, dirE->d_name); + unlink(name); + } + } + closedir(dirP); + + return (code); } main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; { - struct cmd_syndesc *ts; - struct cmd_item *ti; + struct cmd_syndesc *ts; + struct cmd_item *ti; - setlinebuf(stdout); + setlinebuf(stdout); - ts=cmd_CreateSyntax((char *)0, WorkerBee, (char *) 0, "vldb check"); - cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file"); - cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "restore dir"); - cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL, "name extension"); - cmd_AddParm(ts, "-mountpoint", CMD_SINGLE, CMD_OPTIONAL, "mount point root"); - cmd_AddParm(ts, "-umask", CMD_SINGLE, CMD_OPTIONAL, "mode mask"); + ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "vldb check"); + cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file"); + cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "restore dir"); + cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL, "name extension"); + cmd_AddParm(ts, "-mountpoint", CMD_SINGLE, CMD_OPTIONAL, + "mount point root"); + cmd_AddParm(ts, "-umask", CMD_SINGLE, CMD_OPTIONAL, "mode mask"); - return cmd_Dispatch(argc, argv); + return cmd_Dispatch(argc, argv); } diff --git a/src/volser/vol.h b/src/volser/vol.h index 382d0ecf3..522fb97ee 100644 --- a/src/volser/vol.h +++ b/src/volser/vol.h @@ -18,9 +18,9 @@ #include typedef struct DirHandle { - int dirh_volume; - int dirh_device; - Inode dirh_inode; - afs_int32 dirh_cacheCheck; - IHandle_t *dirh_handle; + int dirh_volume; + int dirh_device; + Inode dirh_inode; + afs_int32 dirh_cacheCheck; + IHandle_t *dirh_handle; } DirHandle; diff --git a/src/volser/volint.xg b/src/volser/volint.xg index 5c36aea18..cfa515596 100644 --- a/src/volser/volint.xg +++ b/src/volser/volint.xg @@ -47,6 +47,8 @@ statindex 16 #define VOLSETINFO 126 #define VOLXLISTPARTITIONS 127 #define VOLFORWARDMULTIPLE 128 +#define VOLCONVERTRO 65536 +#define VOLGETSIZE 65537 const SIZE = 1024; @@ -215,6 +217,11 @@ struct replica { struct destServer server; }; +/* Various size parameters of the volume */ +struct volintSize { + afs_uint64 dump_size; +}; + typedef replica manyDests<>; typedef afs_int32 manyResults<>; typedef transDebugInfo transDebugEntries<>; @@ -390,3 +397,14 @@ proc ForwardMultiple( IN struct restoreCookie *cookie, OUT manyResults *results ) = VOLFORWARDMULTIPLE; + +proc ConvertROtoRWvolume( + IN afs_int32 partid, + IN afs_int32 volid +) = VOLCONVERTRO; + +proc GetSize( + IN afs_int32 fromTrans, + IN afs_int32 fromDate, + OUT struct volintSize *size +) = VOLGETSIZE; diff --git a/src/volser/volmain.c b/src/volser/volmain.c index 60f965285..237d32ea6 100644 --- a/src/volser/volmain.c +++ b/src/volser/volmain.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/volmain.c,v 1.8 2002/05/12 05:50:44 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/volmain.c,v 1.18 2003/12/07 22:49:44 jaltman Exp $"); #include #ifdef AFS_NT40_ENV @@ -23,11 +24,22 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/volmain.c,v 1.8 2002/05/12 05:50 #include #include #endif +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #include #include #include #include +#ifdef AFS_PTHREAD_ENV +#include +#else /* AFS_PTHREAD_ENV */ #include +#endif /* AFS_PTHREAD_ENV */ #include #include #include @@ -53,36 +65,34 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/volmain.c,v 1.8 2002/05/12 05:50 #include #include +/*@printflike@*/ extern void Log(const char *format, ...); +/*@printflike@*/ extern void Abort(const char *format, ...); + #define VolserVersion "2.0" #define N_SECURITY_OBJECTS 3 -extern int (*vol_PollProc)(); extern struct volser_trans *TransList(); +#ifndef AFS_PTHREAD_ENV +extern int (*vol_PollProc) (); extern int IOMGR_Poll(); -char *GlobalNameHack = (char *)0; +#endif +char *GlobalNameHack = NULL; int hackIsIn = 0; afs_int32 GlobalVolCloneId, GlobalVolParentId; int GlobalVolType; -int VolumeChanged; /* XXXX */ +int VolumeChanged; /* XXXX */ static char busyFlags[MAXHELPERS]; struct volser_trans *QI_GlobalWriteTrans = 0; -extern int QI_write(); -extern int QI_flush(); -extern int (*VolWriteProc)(); -extern int (*VolFlushProc)(); extern void AFSVolExecuteRequest(); extern void RXSTATS_ExecuteRequest(); -extern struct rx_securityClass *rxnull_NewServerSecurityObject(); -extern struct rx_service *rx_NewService(); -extern Log(); struct afsconf_dir *tdir; -static afs_int32 runningCalls=0; +static afs_int32 runningCalls = 0; int DoLogging = 0; #define MAXLWP 16 int lwps = 9; -int udpBufSize = 0; /* UDP buffer size for receive*/ +int udpBufSize = 0; /* UDP buffer size for receive */ -int Testing = 0; /* for ListViceInodes */ +int Testing = 0; /* for ListViceInodes */ #define VS_EXIT(code) { \ osi_audit(VS_ExitEvent, code, AUD_END); \ @@ -90,105 +100,135 @@ int Testing = 0; /* for ListViceInodes */ } -static MyBeforeProc () { +static +MyBeforeProc(struct rx_call *acall) +{ + VTRANS_LOCK; runningCalls++; + VTRANS_UNLOCK; return 0; } -static MyAfterProc () { +static +MyAfterProc(struct rx_call *acall, afs_int32 code) +{ + VTRANS_LOCK; runningCalls--; + VTRANS_UNLOCK; return 0; } /* Called every GCWAKEUP seconds to try to unlock all our partitions, * if we're idle and there are no active transactions */ -static TryUnlock() { +static +TryUnlock() +{ /* if there are no running calls, and there are no active transactions, then - it should be safe to release any partition locks we've accumulated */ - if (runningCalls == 0 && TransList() == (struct volser_trans *) 0) { + * it should be safe to release any partition locks we've accumulated */ + VTRANS_LOCK; + if (runningCalls == 0 && TransList() == (struct volser_trans *)0) { + VTRANS_UNLOCK; VPFullUnlock(); /* in volprocs.c */ - } + } else + VTRANS_UNLOCK; } /* background daemon for timing out transactions */ -static BKGLoop() { +static +BKGLoop() +{ struct timeval tv; - int loop=0; + int loop = 0; while (1) { tv.tv_sec = GCWAKEUP; tv.tv_usec = 0; - (void) IOMGR_Select(0, 0, 0, 0, &tv); +#ifdef AFS_PTHREAD_ENV + select(0, 0, 0, 0, &tv); +#else + (void)IOMGR_Select(0, 0, 0, 0, &tv); +#endif GCTrans(); TryUnlock(); loop++; - if ( loop == 10 ) - { /* reopen log every 5 minutes */ - loop = 0; - ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH); + if (loop == 10) { /* reopen log every 5 minutes */ + loop = 0; + ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH); } } } /* Background daemon for sleeping so the volserver does not become I/O bound */ afs_int32 TTsleep, TTrun; -static BKGSleep() +static +BKGSleep() { - struct volser_trans *tt; - - if (TTsleep) { - while (1) { - IOMGR_Sleep(TTrun); - for (tt=TransList(); tt; tt=tt->next) { - if ( (strcmp(tt->lastProcName,"DeleteVolume") == 0) || - (strcmp(tt->lastProcName,"Clone") == 0) || - (strcmp(tt->lastProcName,"ReClone") == 0) || - (strcmp(tt->lastProcName,"Forward") == 0) || - (strcmp(tt->lastProcName,"Restore") == 0) || - (strcmp(tt->lastProcName,"ForwardMulti") == 0) ) - break; - } - if (tt) { - sleep(TTsleep); + struct volser_trans *tt; + + if (TTsleep) { + while (1) { +#ifdef AFS_PTHREAD_ENV + sleep(TTrun); +#else /* AFS_PTHREAD_ENV */ + IOMGR_Sleep(TTrun); +#endif + VTRANS_LOCK; + for (tt = TransList(); tt; tt = tt->next) { + if ((strcmp(tt->lastProcName, "DeleteVolume") == 0) + || (strcmp(tt->lastProcName, "Clone") == 0) + || (strcmp(tt->lastProcName, "ReClone") == 0) + || (strcmp(tt->lastProcName, "Forward") == 0) + || (strcmp(tt->lastProcName, "Restore") == 0) + || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) + break; + } + if (tt) { + VTRANS_UNLOCK; + sleep(TTsleep); + } else + VTRANS_UNLOCK; } - } - } + } } #ifndef AFS_NT40_ENV -int volser_syscall(a3, a4, a5) -afs_uint32 a3, a4; -void * a5; +int +volser_syscall(a3, a4, a5) + afs_uint32 a3, a4; + void *a5; { - afs_uint32 rcode; - void (*old)(); - + afs_uint32 rcode; + void (*old) (); + #ifndef AFS_LINUX20_ENV - old = signal(SIGSYS, SIG_IGN); + old = signal(SIGSYS, SIG_IGN); #endif - rcode = syscall (AFS_SYSCALL /* AFS_SYSCALL */, 28 /* AFSCALL_CALL */, a3, a4, a5); + rcode = + syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3, + a4, a5); #ifndef AFS_LINUX20_ENV - signal(SIGSYS, old); + signal(SIGSYS, old); #endif - return rcode; + return rcode; } #endif /* check whether caller is authorized to manage RX statistics */ -int vol_rxstat_userok(call) - struct rx_call *call; +int +vol_rxstat_userok(call) + struct rx_call *call; { - return afsconf_SuperUser(tdir, call, (char *)0); + return afsconf_SuperUser(tdir, call, NULL); } #include "AFS_component_version_number.c" main(argc, argv) -int argc; -char **argv; { - char *pid; + int argc; + char **argv; +{ register afs_int32 code; struct rx_securityClass *(securityObjects[3]); struct rx_service *service; @@ -196,8 +236,8 @@ char **argv; { int rxpackets = 100; char commandLine[150]; int i; - int rxJumbograms = 1; /* default is to send and receive jumbograms. */ - int bufSize = 0; /* temp variable to read in udp socket buf size*/ + int rxJumbograms = 1; /* default is to send and receive jumbograms. */ + int bufSize = 0; /* temp variable to read in udp socket buf size */ #ifdef AFS_AIX32_ENV /* @@ -207,7 +247,7 @@ char **argv; { * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; @@ -219,78 +259,73 @@ char **argv; { /* Initialize dirpaths */ if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) { #ifdef AFS_NT40_ENV - ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0],0); + ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0); #endif - fprintf(stderr,"%s: Unable to obtain AFS server directory.\n", argv[0]); + fprintf(stderr, "%s: Unable to obtain AFS server directory.\n", + argv[0]); exit(2); } - - for (commandLine[0] = '\0', i=0; i 0) strcat(commandLine, " "); + + for (commandLine[0] = '\0', i = 0; i < argc; i++) { + if (i > 0) + strcat(commandLine, " "); strcat(commandLine, argv[i]); } TTsleep = TTrun = 0; /* parse cmd line */ - for(code=1;code MAXLWP) { printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP); lwps = MAXLWP; } - } - else if (strcmp(argv[code], "-nojumbo")==0) { + } else if (strcmp(argv[code], "-nojumbo") == 0) { rxJumbograms = 0; - } - else if (strcmp(argv[code], "-sleep")==0) { + } else if (strcmp(argv[code], "-sleep") == 0) { sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun); if ((TTsleep < 0) || (TTrun <= 0)) { printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n", TTsleep, TTrun); TTsleep = TTrun = 0; } - } - else if ( strcmp(argv[code], "-udpsize")==0) { - if ( (code+1) >= argc ) { + } else if (strcmp(argv[code], "-udpsize") == 0) { + if ((code + 1) >= argc) { printf("You have to specify -udpsize \n"); exit(1); } sscanf(argv[++code], "%d", &bufSize); - if ( bufSize < rx_GetMinUdpBufSize() ) - printf("Warning:udpsize %d is less than minimum %d; ignoring\n", - bufSize, rx_GetMinUdpBufSize() ); + if (bufSize < rx_GetMinUdpBufSize()) + printf + ("Warning:udpsize %d is less than minimum %d; ignoring\n", + bufSize, rx_GetMinUdpBufSize()); else udpBufSize = bufSize; - } - else if (strcmp(argv[code], "-enable_peer_stats")==0) { + } else if (strcmp(argv[code], "-enable_peer_stats") == 0) { rx_enablePeerRPCStats(); - } - else if (strcmp(argv[code], "-enable_process_stats")==0) { + } else if (strcmp(argv[code], "-enable_process_stats") == 0) { rx_enableProcessRPCStats(); } #ifndef AFS_NT40_ENV - else if (strcmp(argv[code], "-syslog")==0) { + else if (strcmp(argv[code], "-syslog") == 0) { /* set syslog logging flag */ serverLogSyslog = 1; - } - else if (strncmp(argv[code], "-syslog=", 8)==0) { + } else if (strncmp(argv[code], "-syslog=", 8) == 0) { serverLogSyslog = 1; - serverLogSyslogFacility = atoi(argv[code]+8); + serverLogSyslogFacility = atoi(argv[code] + 8); } #endif else { printf("volserver: unrecognized flag '%s'\n", argv[code]); -usage: + usage: #ifndef AFS_NT40_ENV printf("Usage: volserver [-log] [-p ] " "[-udpsize ] " @@ -307,15 +342,16 @@ usage: } } #ifdef AFS_SGI_VNODE_GLUE - if (afs_init_kernel_config(-1) <0) { - printf("Can't determine NUMA configuration, not starting volserver.\n"); + if (afs_init_kernel_config(-1) < 0) { + printf + ("Can't determine NUMA configuration, not starting volserver.\n"); exit(1); } #endif InitErrTabs(); #ifdef AFS_NT40_ENV - if (afs_winsockInit()<0) { + if (afs_winsockInit() < 0) { ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0); printf("Volume server unable to start winsock, exiting.\n"); exit(1); @@ -323,21 +359,24 @@ usage: #endif VInitVolumePackage(volumeUtility, 0, 0, CONNECT_FS, 0); DInit(40); +#ifndef AFS_PTHREAD_ENV vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */ +#endif #ifndef AFS_NT40_ENV rxi_syscallp = volser_syscall; #endif - rx_nPackets = rxpackets; /* set the max number of packets */ - if ( udpBufSize) - rx_SetUdpBufSize(udpBufSize);/* set the UDP buffer size for receive */ + rx_nPackets = rxpackets; /* set the max number of packets */ + if (udpBufSize) + rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */ code = rx_Init((int)htons(AFSCONF_VOLUMEPORT)); if (code) { - fprintf(stderr,"rx init failed on socket AFSCONF_VOLUMEPORT %u\n",AFSCONF_VOLUMEPORT); + fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n", + AFSCONF_VOLUMEPORT); VS_EXIT(1); } if (!rxJumbograms) { /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */ - rx_SetNoJumbo(); + rx_SetNoJumbo(); } rx_GetIFInfo(); rx_SetRxDeadTime(420); @@ -347,50 +386,73 @@ usage: OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH); SetupLogSignals(); - /* create the lwp to garbage-collect old transactions and sleep periodically */ - LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid); - LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid); + { +#ifdef AFS_PTHREAD_ENV + pthread_t tid; + pthread_attr_t tattr; + assert(pthread_attr_init(&tattr) == 0); + assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); + + assert(pthread_create(&tid, &tattr, (void *)BKGLoop, NULL) == 0); +#else + PROCESS pid; + LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid); + LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid); +#endif + } /* Create a single security object, in this case the null security object, for unauthenticated connections, which will be used to control security on connections made to this server */ tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH); if (!tdir) { - Abort("volser: could not open conf files in %s\n", AFSDIR_SERVER_ETC_DIRPATH); + Abort("volser: could not open conf files in %s\n", + AFSDIR_SERVER_ETC_DIRPATH); VS_EXIT(1); } afsconf_GetKey(tdir, 999, &tkey); - securityObjects[0] = (struct rx_securityClass *) rxnull_NewServerSecurityObject(); - securityObjects[1] = (struct rx_securityClass *) 0; /* don't bother with rxvab */ - securityObjects[2] = (struct rx_securityClass *) rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, (char *) 0); - if (securityObjects[0] == (struct rx_securityClass *) 0) Abort("rxnull_NewServerSecurityObject"); - service = rx_NewService(0, VOLSERVICE_ID, "VOLSER", securityObjects, 3, AFSVolExecuteRequest); - if (service == (struct rx_service *) 0) Abort("rx_NewService"); - rx_SetBeforeProc(service, (char (*)()) MyBeforeProc); - rx_SetAfterProc(service, (char (*)()) MyAfterProc); + securityObjects[0] = rxnull_NewServerSecurityObject(); + securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */ + securityObjects[2] = + rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL); + if (securityObjects[0] == (struct rx_securityClass *)0) + Abort("rxnull_NewServerSecurityObject"); + service = + rx_NewService(0, VOLSERVICE_ID, "VOLSER", securityObjects, 3, + AFSVolExecuteRequest); + if (service == (struct rx_service *)0) + Abort("rx_NewService"); + rx_SetBeforeProc(service, MyBeforeProc); + rx_SetAfterProc(service, MyAfterProc); rx_SetIdleDeadTime(service, 0); /* never timeout */ if (lwps < 4) lwps = 4; rx_SetMaxProcs(service, lwps); +#ifdef AFS_SGI_ENV + rx_SetStackSize(service, 49152); +#else rx_SetStackSize(service, 32768); +#endif - service = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityObjects, 3, RXSTATS_ExecuteRequest); - if (service == (struct rx_service *) 0) Abort("rx_NewService"); + service = + rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityObjects, 3, + RXSTATS_ExecuteRequest); + if (service == (struct rx_service *)0) + Abort("rx_NewService"); rx_SetMinProcs(service, 2); rx_SetMaxProcs(service, 4); Log("Starting AFS Volserver %s (%s)\n", VolserVersion, commandLine); if (TTsleep) { - Log("Will sleep %d second%s every %d second%s\n", - TTsleep, (TTsleep>1)?"s":"", - TTrun+TTsleep, (TTrun+TTsleep>1)?"s":""); + Log("Will sleep %d second%s every %d second%s\n", TTsleep, + (TTsleep > 1) ? "s" : "", TTrun + TTsleep, + (TTrun + TTsleep > 1) ? "s" : ""); } /* allow super users to manage RX statistics */ rx_SetRxStatUserOk(vol_rxstat_userok); - rx_StartServer(1); /* Donate this process to the server process pool */ + rx_StartServer(1); /* Donate this process to the server process pool */ osi_audit(VS_FinishEvent, (-1), AUD_END); Abort("StartServer returned?"); } - diff --git a/src/volser/volprocs.c b/src/volser/volprocs.c index 913e90030..433a7a618 100644 --- a/src/volser/volprocs.c +++ b/src/volser/volprocs.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/volprocs.c,v 1.1.1.10 2004/01/10 20:58:11 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/volprocs.c,v 1.33 2004/01/01 06:22:31 shadow Exp $"); #include #include @@ -23,6 +24,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/volprocs.c,v 1.1.1.10 2004/01/10 #include #include #endif + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include @@ -30,7 +40,11 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/volprocs.c,v 1.1.1.10 2004/01/10 #include #include #include +#ifdef AFS_PTHREAD_ENV +#include +#else /* AFS_PTHREAD_ENV */ #include +#endif /* AFS_PTHREAD_ENV */ #include #include #include @@ -50,17 +64,22 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/volprocs.c,v 1.1.1.10 2004/01/10 #include #include #include "afs/audit.h" +#include #include "volser.h" #include "volint.h" + +#include "volser_prototypes.h" + extern int DoLogging; -extern struct volser_trans *FindTrans(), *NewTrans(),*TransList(); -extern struct rx_securityClass *rxnull_NewServerSecurityObject(); -extern struct rx_service *rx_NewService(); -extern struct rx_securityClass *rxnull_NewClientSecurityObject(); +extern struct volser_trans *FindTrans(), *NewTrans(), *TransList(); extern struct afsconf_dir *tdir; + +/* Needed by Irix. Leave, or include a header */ extern char *volutil_PartitionName(); +extern void LogError(afs_int32 errcode); + /* Forward declarations */ static int GetPartName(afs_int32 partid, char *pname); @@ -70,18 +89,24 @@ static int GetPartName(afs_int32 partid, char *pname); #define ENOTCONN 134 #endif -afs_int32 localTid=1; -afs_int32 VolPartitionInfo(), VolNukeVolume(), VolCreateVolume(), VolDeleteVolume(), VolClone(); -afs_int32 VolReClone(), VolTransCreate(), VolGetNthVolume(), VolGetFlags(), VolForward(), VolDump(); -afs_int32 VolForwardMultiple(); -afs_int32 VolRestore(), VolEndTrans(), VolSetForwarding(), VolGetStatus(), VolSetInfo(), VolGetName(); -afs_int32 VolSignalRestore(), VolListPartitions(), VolListOneVolume(), VolXListOneVolume(), VolXListVolumes(); -afs_int32 VolListVolumes(), XVolListPartitions(), VolMonitor(), VolSetIdsTypes(), VolSetDate(), VolSetFlags(); +afs_int32 localTid = 1; +afs_int32 VolPartitionInfo(), VolNukeVolume(), VolCreateVolume(), +VolDeleteVolume(), VolClone(); +afs_int32 VolReClone(), VolTransCreate(), VolGetNthVolume(), VolGetFlags(), +VolForward(), VolDump(); +afs_int32 VolRestore(), VolEndTrans(), VolSetForwarding(), VolGetStatus(), +VolSetInfo(), VolGetName(); +afs_int32 VolListPartitions(), VolListOneVolume(), +VolXListOneVolume(), VolXListVolumes(); +afs_int32 VolListVolumes(), XVolListPartitions(), VolMonitor(), +VolSetIdsTypes(), VolSetDate(), VolSetFlags(); /* this call unlocks all of the partition locks we've set */ -VPFullUnlock() { +int +VPFullUnlock() +{ register struct DiskPartition *tp; - for(tp = DiskPartitionList; tp; tp = tp->next) { + for (tp = DiskPartitionList; tp; tp = tp->next) { if (tp->lock_fd != -1) { close(tp->lock_fd); /* releases flock held on this partition */ tp->lock_fd = -1; @@ -91,60 +116,65 @@ VPFullUnlock() { } /* get partition id from a name */ -afs_int32 PartitionID(aname) -char *aname; { +afs_int32 +PartitionID(char *aname) +{ register char tc; register int code = 0; char ascii[3]; tc = *aname; - if (tc == 0) return -1; /* unknown */ + if (tc == 0) + return -1; /* unknown */ /* otherwise check for vicepa or /vicepa, or just plain "a" */ ascii[2] = 0; if (!strncmp(aname, "/vicep", 6)) { - strncpy(ascii, aname+6, 2); - } - else return -1; /* bad partition name */ + strncpy(ascii, aname + 6, 2); + } else + return -1; /* bad partition name */ /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz, and are numbered - from 0. Do the appropriate conversion */ + * from 0. Do the appropriate conversion */ if (ascii[1] == 0) { /* one char name, 0..25 */ - if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */ + if (ascii[0] < 'a' || ascii[0] > 'z') + return -1; /* wrongo */ return ascii[0] - 'a'; - } - else { + } else { /* two char name, 26 .. */ - if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */ - if (ascii[1] < 'a' || ascii[1] > 'z') return -1; /* just as bad */ + if (ascii[0] < 'a' || ascii[0] > 'z') + return -1; /* wrongo */ + if (ascii[1] < 'a' || ascii[1] > 'z') + return -1; /* just as bad */ code = (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26; - if (code > VOLMAXPARTS) return -1; + if (code > VOLMAXPARTS) + return -1; return code; } } -static int ConvertVolume(avol, aname, asize) -afs_int32 avol; -char *aname; -afs_int32 asize; { - if (asize < 18) return -1; +static int +ConvertVolume(afs_int32 avol, char *aname, afs_int32 asize) +{ + if (asize < 18) + return -1; /* It's better using the Generic VFORMAT since otherwise we have to make changes to too many places... The 14 char limitation in names hits us again in AIX; print in field of 9 digits (still 10 for the rest), right justified with 0 padding */ - sprintf(aname, VFORMAT, avol); + (void)afs_snprintf(aname, asize, VFORMAT, (unsigned long)avol); return 0; } -static int ConvertPartition(apartno, aname, asize) -int apartno; -char *aname; -int asize; { - if (asize < 10) return E2BIG; - if (apartno < 0) return EINVAL; +static int +ConvertPartition(int apartno, char *aname, int asize) +{ + if (asize < 10) + return E2BIG; + if (apartno < 0) + return EINVAL; strcpy(aname, "/vicep"); if (apartno < 26) { - aname[6] = 'a'+apartno; + aname[6] = 'a' + apartno; aname[7] = 0; - } - else { + } else { apartno -= 26; aname[6] = 'a' + (apartno / 26); aname[7] = 'a' + (apartno % 26); @@ -154,82 +184,83 @@ int asize; { } /* the only attach function that takes a partition is "...ByName", so we use it */ -struct Volume *XAttachVolume(error, avolid, apartid, amode) -afs_int32 *error; -afs_int32 avolid; -afs_int32 apartid; -int amode; { +struct Volume * +XAttachVolume(afs_int32 *error, afs_int32 avolid, afs_int32 apartid, int amode) +{ char pbuf[30], vbuf[20]; register struct Volume *tv; if (ConvertPartition(apartid, pbuf, sizeof(pbuf))) { *error = EINVAL; - return (struct Volume *) 0; + return NULL; } if (ConvertVolume(avolid, vbuf, sizeof(vbuf))) { *error = EINVAL; - return (struct Volume *) 0; + return NULL; } tv = VAttachVolumeByName(error, pbuf, vbuf, amode); return tv; } /* Adapted from the file server; create a root directory for this volume */ -static ViceCreateRoot(vp) -Volume * vp; +static int +ViceCreateRoot(Volume *vp) { DirHandle dir; - struct acl_accessList * ACL; - ViceFid did; + struct acl_accessList *ACL; + ViceFid did; Inode inodeNumber, nearInode; char buf[SIZEOF_LARGEDISKVNODE]; - struct VnodeDiskObject *vnode = (struct VnodeDiskObject *) buf; + struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; struct VnodeClassInfo *vcp = &VnodeClassInfo[vLarge]; IHandle_t *h; FdHandle_t *fdP; int code; - int length; + afs_fsize_t length; - memset(vnode, 0, SIZEOF_LARGEDISKVNODE); + memset(vnode, 0, SIZEOF_LARGEDISKVNODE); V_pref(vp, nearInode); - inodeNumber = IH_CREATE(V_linkHandle(vp), V_device(vp), - VPartitionPath(V_partition(vp)), nearInode, - V_parentId(vp), 1, 1, 0); + inodeNumber = + IH_CREATE(V_linkHandle(vp), V_device(vp), + VPartitionPath(V_partition(vp)), nearInode, V_parentId(vp), + 1, 1, 0); assert(VALID_INO(inodeNumber)); SetSalvageDirHandle(&dir, V_parentId(vp), vp->device, inodeNumber); did.Volume = V_id(vp); - did.Vnode = (VnodeId)1; + did.Vnode = (VnodeId) 1; did.Unique = 1; assert(!(MakeDir(&dir, &did, &did))); - DFlush(); /* flush all modified dir buffers out */ - DZap(&dir); /* Remove all buffers for this dir */ - length = Length(&dir); /* Remember size of this directory */ + DFlush(); /* flush all modified dir buffers out */ + DZap(&dir); /* Remove all buffers for this dir */ + length = Length(&dir); /* Remember size of this directory */ - FidZap(&dir); /* Done with the dir handle obtained via SetSalvageDirHandle() */ + FidZap(&dir); /* Done with the dir handle obtained via SetSalvageDirHandle() */ - /* build a single entry ACL that gives all rights to system:administrators */ - /* this section of code assumes that access list format is not going to - * change - */ + /* build a single entry ACL that gives all rights to system:administrators */ + /* this section of code assumes that access list format is not going to + * change + */ ACL = VVnodeDiskACL(vnode); ACL->size = sizeof(struct acl_accessList); ACL->version = ACL_ACLVERSION; ACL->total = 1; ACL->positive = 1; ACL->negative = 0; - ACL->entries[0].id = -204; /* this assumes System:administrators is group -204 */ - ACL->entries[0].rights = PRSFS_READ | PRSFS_WRITE | PRSFS_INSERT | PRSFS_LOOKUP | PRSFS_DELETE | PRSFS_LOCK | PRSFS_ADMINISTER; + ACL->entries[0].id = -204; /* this assumes System:administrators is group -204 */ + ACL->entries[0].rights = + PRSFS_READ | PRSFS_WRITE | PRSFS_INSERT | PRSFS_LOOKUP | PRSFS_DELETE + | PRSFS_LOCK | PRSFS_ADMINISTER; vnode->type = vDirectory; vnode->cloned = 0; vnode->modeBits = 0777; vnode->linkCount = 2; - vnode->length = length; + VNDISK_SET_LEN(vnode, length); vnode->uniquifier = 1; - V_uniquifier(vp) = vnode->uniquifier+1; + V_uniquifier(vp) = vnode->uniquifier + 1; vnode->dataVersion = 1; VNDISK_SET_INO(vnode, inodeNumber); vnode->unixModifyTime = vnode->serverModifyTime = V_creationDate(vp); @@ -248,62 +279,58 @@ Volume * vp; assert(code == SIZEOF_LARGEDISKVNODE); FDH_REALLYCLOSE(fdP); IH_RELEASE(h); - V_diskused(vp) = nBlocks(vnode->length); + VNDISK_GET_LEN(length, vnode); + V_diskused(vp) = nBlocks(length); return 1; } -afs_int32 SAFSVolPartitionInfo (acid,pname,partition) -struct rx_call *acid; -char *pname; -struct diskPartition *partition; +afs_int32 +SAFSVolPartitionInfo(struct rx_call *acid, char *pname, struct diskPartition + *partition) { - afs_int32 code; - - code = VolPartitionInfo (acid,pname,partition); - osi_auditU(acid, VS_ParInfEvent, code, AUD_STR, pname, AUD_END); - return code; + afs_int32 code; + + code = VolPartitionInfo(acid, pname, partition); + osi_auditU(acid, VS_ParInfEvent, code, AUD_STR, pname, AUD_END); + return code; } -afs_int32 VolPartitionInfo (acid,pname,partition) -struct rx_call *acid; -char *pname; -struct diskPartition *partition; +afs_int32 +VolPartitionInfo(struct rx_call *acid, char *pname, struct diskPartition + *partition) { register struct DiskPartition *dp; /* if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS; */ - VResetDiskUsage(); + VResetDiskUsage(); dp = VGetPartition(pname, 0); - if(dp) { - strncpy(partition->name,dp->name,32); - strncpy(partition->devName,dp->devName,32); - partition->lock_fd = dp->lock_fd ; + if (dp) { + strncpy(partition->name, dp->name, 32); + strncpy(partition->devName, dp->devName, 32); + partition->lock_fd = dp->lock_fd; partition->free = dp->free; partition->minFree = dp->totalUsable; return 0; - } - else + } else return VOLSERILLEGAL_PARTITION; } /* obliterate a volume completely, and slowly. */ -afs_int32 SAFSVolNukeVolume (acid, apartID, avolID) -struct rx_call *acid; -afs_int32 apartID, avolID; +afs_int32 +SAFSVolNukeVolume(struct rx_call *acid, afs_int32 apartID, afs_int32 avolID) { - afs_int32 code; - - code = VolNukeVolume (acid, apartID, avolID); - osi_auditU(acid, VS_NukVolEvent, code, AUD_LONG, avolID, AUD_END); - return code; + afs_int32 code; + + code = VolNukeVolume(acid, apartID, avolID); + osi_auditU(acid, VS_NukVolEvent, code, AUD_LONG, avolID, AUD_END); + return code; } -afs_int32 VolNukeVolume (acid, apartID, avolID) -struct rx_call *acid; -afs_int32 apartID, avolID; +afs_int32 +VolNukeVolume(struct rx_call *acid, afs_int32 apartID, afs_int32 avolID) { register char *tp; char partName[50]; @@ -313,19 +340,23 @@ afs_int32 apartID, avolID; char caller[MAXKTCNAMELEN]; /* check for access */ - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS; - if (DoLogging) Log("%s is executing VolNukeVolume %u\n", caller, avolID); + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; + if (DoLogging) + Log("%s is executing VolNukeVolume %u\n", caller, avolID); tp = volutil_PartitionName(apartID); - if (!tp) return VOLSERNOVOL; + if (!tp) + return VOLSERNOVOL; strcpy(partName, tp); /* remember it for later */ /* we first try to attach the volume in update mode, so that the file * server doesn't try to use it (and abort) while (or after) we delete it. * If we don't get the volume, that's fine, too. We just won't put it back. */ - tvp = XAttachVolume(&error, avolID, apartID, V_UPDATE); + tvp = XAttachVolume(&error, avolID, apartID, V_VOLUPD); code = nuke(partName, avolID); - if (tvp) VDetachVolume(&error, tvp); + if (tvp) + VDetachVolume(&error, tvp); return code; } @@ -335,68 +366,64 @@ afs_int32 apartID, avolID; * for the volume id (useful for things like volume restore). * Return the new volume id in *avolid. */ -afs_int32 SAFSVolCreateVolume (acid, apart, aname, atype, aparent, avolid, atrans) -struct rx_call *acid; -afs_int32 apart; -afs_int32 atype; -char *aname; -afs_int32 aparent; -afs_int32 *atrans; -afs_int32 *avolid; -{ - afs_int32 code; - - code = VolCreateVolume (acid, apart, aname, atype, aparent, avolid, atrans); - osi_auditU(acid, VS_CrVolEvent, code, AUD_LONG, *atrans, - AUD_LONG, *avolid, - AUD_STR, aname, - AUD_LONG, atype, - AUD_LONG, aparent, - AUD_END); - return code; -} - -afs_int32 VolCreateVolume (acid, apart, aname, atype, aparent, avolid, atrans) -struct rx_call *acid; -afs_int32 apart; -afs_int32 atype; -char *aname; -afs_int32 aparent; -afs_int32 *atrans; -afs_int32 *avolid; +afs_int32 +SAFSVolCreateVolume(struct rx_call *acid, afs_int32 apart, char *aname, + afs_int32 atype, afs_int32 aparent, afs_int32 *avolid, + afs_int32 *atrans) +{ + afs_int32 code; + + code = + VolCreateVolume(acid, apart, aname, atype, aparent, avolid, atrans); + osi_auditU(acid, VS_CrVolEvent, code, AUD_LONG, *atrans, AUD_LONG, + *avolid, AUD_STR, aname, AUD_LONG, atype, AUD_LONG, aparent, + AUD_END); + return code; +} + +afs_int32 +VolCreateVolume(struct rx_call *acid, afs_int32 apart, char *aname, + afs_int32 atype, afs_int32 aparent, afs_int32 *avolid, + afs_int32 *atrans) { afs_int32 error; register Volume *vp; - afs_int32 junk; /* discardable error code */ - register afs_int32 volumeID, doCreateRoot=1; + afs_int32 junk; /* discardable error code */ + register afs_int32 volumeID, doCreateRoot = 1; register struct volser_trans *tt; char ppath[30]; char caller[MAXKTCNAMELEN]; - if (strlen(aname) > 31) return VOLSERBADNAME; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS; - if (DoLogging) Log("%s is executing CreateVolume '%s'\n", caller, aname); - if (error = ConvertPartition(apart, ppath, sizeof(ppath))) return error;/*a standard unix error*/ - if (atype != readwriteVolume && atype != readonlyVolume && atype != backupVolume) + if (strlen(aname) > 31) + return VOLSERBADNAME; + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; + if (DoLogging) + Log("%s is executing CreateVolume '%s'\n", caller, aname); + if ((error = ConvertPartition(apart, ppath, sizeof(ppath)))) + return error; /*a standard unix error */ + if (atype != readwriteVolume && atype != readonlyVolume + && atype != backupVolume) return EINVAL; if ((volumeID = *avolid) == 0) { - - Log("1 Volser: CreateVolume: missing volume number; %s volume not created\n",aname); - return E2BIG; - + + Log("1 Volser: CreateVolume: missing volume number; %s volume not created\n", aname); + return E2BIG; + } if ((aparent == volumeID) && (atype == readwriteVolume)) { doCreateRoot = 0; } - if (aparent == 0) aparent = volumeID; + if (aparent == 0) + aparent = volumeID; tt = NewTrans(volumeID, apart); if (!tt) { Log("1 createvolume: failed to create trans\n"); - return VOLSERVOLBUSY; /* volume already busy! */ + return VOLSERVOLBUSY; /* volume already busy! */ } vp = VCreateVolume(&error, ppath, volumeID, aparent); if (error) { - Log("1 Volser: CreateVolume: Unable to create the volume; aborted, error code %u\n",error); + Log("1 Volser: CreateVolume: Unable to create the volume; aborted, error code %u\n", error); LogError(error); DeleteTrans(tt); return EIO; @@ -410,7 +437,7 @@ afs_int32 *avolid; ViceCreateRoot(vp); V_destroyMe(vp) = DESTROY_ME; V_inService(vp) = 0; - V_maxquota(vp) = 5000; /* set a quota of 5000 at init time */ + V_maxquota(vp) = 5000; /* set a quota of 5000 at init time */ VUpdateVolume(&error, vp); if (error) { Log("1 Volser: create UpdateVolume failed, code %d\n", error); @@ -421,52 +448,55 @@ afs_int32 *avolid; } tt->volume = vp; *atrans = tt->tid; - strcpy(tt->lastProcName,"CreateVolume"); + strcpy(tt->lastProcName, "CreateVolume"); tt->rxCallPtr = acid; Log("1 Volser: CreateVolume: volume %u (%s) created\n", volumeID, aname); tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)) return VOLSERTRELE_ERROR; + if (TRELE(tt)) + return VOLSERTRELE_ERROR; return 0; } /* delete the volume associated with this transaction */ -afs_int32 SAFSVolDeleteVolume (acid, atrans) -afs_int32 atrans; -struct rx_call *acid; +afs_int32 +SAFSVolDeleteVolume(struct rx_call *acid, afs_int32 atrans) { - afs_int32 code; + afs_int32 code; - code = VolDeleteVolume (acid, atrans); - osi_auditU(acid, VS_DelVolEvent, code, AUD_LONG, atrans, AUD_END); - return code; + code = VolDeleteVolume(acid, atrans); + osi_auditU(acid, VS_DelVolEvent, code, AUD_LONG, atrans, AUD_END); + return code; } -afs_int32 VolDeleteVolume (acid, atrans) -afs_int32 atrans; -struct rx_call *acid; +afs_int32 +VolDeleteVolume(struct rx_call *acid, afs_int32 atrans) { register struct volser_trans *tt; afs_int32 error; char caller[MAXKTCNAMELEN]; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS; + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; tt = FindTrans(atrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: Delete: volume %u already deleted \n",tt->volid); + Log("1 Volser: Delete: volume %u already deleted \n", tt->volid); TRELE(tt); return ENOENT; } - if (DoLogging) Log("%s is executing Delete Volume %u\n", caller, tt->volid); - strcpy(tt->lastProcName,"DeleteVolume"); + if (DoLogging) + Log("%s is executing Delete Volume %u\n", caller, tt->volid); + strcpy(tt->lastProcName, "DeleteVolume"); tt->rxCallPtr = acid; VPurgeVolume(&error, tt->volume); /* don't check error code, it is not set! */ - tt->vflags |= VTDeleted; /* so we know not to do anything else to it */ + tt->vflags |= VTDeleted; /* so we know not to do anything else to it */ tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)) return VOLSERTRELE_ERROR; - - Log("1 Volser: Delete: volume %u deleted \n",tt->volid); - return 0; /* vpurgevolume doesn't set an error code */ + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + + Log("1 Volser: Delete: volume %u deleted \n", tt->volid); + return 0; /* vpurgevolume doesn't set an error code */ } /* make a clone of the volume associated with atrans, possibly giving it a new @@ -478,51 +508,44 @@ struct rx_call *acid; * the same, while doing them separately would result in far more iincs and idecs being * peformed (and they are slow operations). */ -afs_int32 SAFSVolClone (acid, atrans, purgeId, newType, newName, newNumber) -struct rx_call *acid; -afs_int32 atrans; -afs_int32 newType; -afs_int32 *newNumber; -afs_int32 purgeId; /* for efficiency reasons, sometimes faster to piggyback a purge here */ -char *newName; -{ - afs_int32 code; - - code = VolClone (acid, atrans, purgeId, newType, newName, newNumber); - osi_auditU(acid, VS_CloneEvent, code, AUD_LONG, atrans, - AUD_LONG, purgeId, - AUD_STR, newName, - AUD_LONG, newType, - AUD_LONG, *newNumber, AUD_END); - return code; -} - -afs_int32 VolClone (acid, atrans, purgeId, newType, newName, newNumber) -struct rx_call *acid; -afs_int32 atrans; -afs_int32 newType; -afs_int32 *newNumber; -afs_int32 purgeId; /* for efficiency reasons, sometimes faster to piggyback a purge here */ -char *newName; +/* for efficiency reasons, sometimes faster to piggyback a purge here */ +afs_int32 +SAFSVolClone(struct rx_call *acid, afs_int32 atrans, afs_int32 purgeId, + afs_int32 newType, char *newName, afs_int32 *newNumber) +{ + afs_int32 code; + + code = VolClone(acid, atrans, purgeId, newType, newName, newNumber); + osi_auditU(acid, VS_CloneEvent, code, AUD_LONG, atrans, AUD_LONG, purgeId, + AUD_STR, newName, AUD_LONG, newType, AUD_LONG, *newNumber, + AUD_END); + return code; +} + +afs_int32 +VolClone(struct rx_call *acid, afs_int32 atrans, afs_int32 purgeId, + afs_int32 newType, char *newName, afs_int32 *newNumber) { VolumeId newId; register struct Volume *originalvp, *purgevp, *newvp; Error error, code; - register struct volser_trans *tt,*ttc; + register struct volser_trans *tt, *ttc; char caller[MAXKTCNAMELEN]; - - if (strlen(newName)>31) return VOLSERBADNAME; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ - if (DoLogging) Log("%s is executing Clone Volume new name=%s\n", caller, newName); + + if (strlen(newName) > 31) + return VOLSERBADNAME; + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ + if (DoLogging) + Log("%s is executing Clone Volume new name=%s\n", caller, newName); error = 0; originalvp = (Volume *) 0; purgevp = (Volume *) 0; newvp = (Volume *) 0; - tt = ttc = (struct volser_trans *) 0; + tt = ttc = (struct volser_trans *)0; - if (!newNumber || !*newNumber) - { - Log("1 Volser: Clone: missing volume number for the clone; aborted\n"); + if (!newNumber || !*newNumber) { + Log("1 Volser: Clone: missing volume number for the clone; aborted\n"); goto fail; } newId = *newNumber; @@ -530,63 +553,64 @@ char *newName; if (newType != readonlyVolume && newType != backupVolume) return EINVAL; tt = FindTrans(atrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: Clone: volume %u has been deleted \n",tt->volid); + Log("1 Volser: Clone: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } - ttc = NewTrans(newId,tt->partition); - if (!ttc) - { /* someone is messing with the clone already */ + ttc = NewTrans(newId, tt->partition); + if (!ttc) { /* someone is messing with the clone already */ TRELE(tt); return VBUSY; } - strcpy(tt->lastProcName,"Clone"); + strcpy(tt->lastProcName, "Clone"); tt->rxCallPtr = acid; - - + + if (purgeId) { - purgevp = VAttachVolume(&error, purgeId, V_UPDATE); + purgevp = VAttachVolume(&error, purgeId, V_VOLUPD); if (error) { Log("1 Volser: Clone: Could not attach 'purge' volume %u; clone aborted\n", purgeId); goto fail; } - } - else { - purgevp = (struct Volume *) 0; + } else { + purgevp = NULL; } originalvp = tt->volume; - if ((V_type(originalvp) == backupVolume) || (V_type(originalvp) == readonlyVolume)){ - Log("1 Volser: Clone: The volume to be cloned must be a read/write; aborted\n"); + if ((V_type(originalvp) == backupVolume) + || (V_type(originalvp) == readonlyVolume)) { + Log("1 Volser: Clone: The volume to be cloned must be a read/write; aborted\n"); error = EROFS; goto fail; } if ((V_destroyMe(originalvp) == DESTROY_ME) || !V_inService(originalvp)) { - Log("1 Volser: Clone: Volume %d is offline and cannot be cloned\n", - V_id(originalvp)); - error = VOFFLINE; - goto fail; + Log("1 Volser: Clone: Volume %d is offline and cannot be cloned\n", + V_id(originalvp)); + error = VOFFLINE; + goto fail; } if (purgevp) { if (originalvp->device != purgevp->device) { - Log("1 Volser: Clone: Volumes %u and %u are on different devices\n", tt->volid, purgeId); + Log("1 Volser: Clone: Volumes %u and %u are on different devices\n", tt->volid, purgeId); error = EXDEV; goto fail; } if (V_type(purgevp) != readonlyVolume) { - Log("1 Volser: Clone: The \"purge\" volume must be a read only volume; aborted\n"); + Log("1 Volser: Clone: The \"purge\" volume must be a read only volume; aborted\n"); error = EINVAL; goto fail; } - if (V_type(originalvp) == readonlyVolume && V_parentId(originalvp) != V_parentId(purgevp)) { + if (V_type(originalvp) == readonlyVolume + && V_parentId(originalvp) != V_parentId(purgevp)) { Log("1 Volser: Clone: Volume %u and volume %u were not cloned from the same parent volume; aborted\n", tt->volid, purgeId); error = EXDEV; goto fail; } - if (V_type(originalvp) == readwriteVolume && tt->volid != V_parentId(purgevp)) { - Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", - purgeId, tt->volid); + if (V_type(originalvp) == readwriteVolume + && tt->volid != V_parentId(purgevp)) { + Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", purgeId, tt->volid); error = EXDEV; goto fail; } @@ -594,7 +618,9 @@ char *newName; error = 0; - newvp = VCreateVolume(&error, originalvp->partition->name, newId, V_parentId(originalvp)); + newvp = + VCreateVolume(&error, originalvp->partition->name, newId, + V_parentId(originalvp)); if (error) { Log("1 Volser: Clone: Couldn't create new volume; clone aborted\n"); newvp = (Volume *) 0; @@ -602,26 +628,26 @@ char *newName; } if (newType == readonlyVolume) V_cloneId(originalvp) = newId; - Log("1 Volser: Clone: Cloning volume %u to new volume %u\n", tt->volid, newId); + Log("1 Volser: Clone: Cloning volume %u to new volume %u\n", tt->volid, + newId); if (purgevp) - Log("1 Volser: Clone: Purging old read only volume %u\n", purgeId); + Log("1 Volser: Clone: Purging old read only volume %u\n", purgeId); CloneVolume(&error, originalvp, newvp, purgevp); - purgevp = (struct Volume *) 0; /* clone releases it, maybe even if error */ + purgevp = NULL; /* clone releases it, maybe even if error */ if (error) { - Log("1 Volser: Clone: clone operation failed with code %d\n", error); - LogError(error); + Log("1 Volser: Clone: clone operation failed with code %u\n", error); + LogError(error); goto fail; } if (newType == readonlyVolume) { AssignVolumeName(&V_disk(newvp), V_name(originalvp), ".readonly"); V_type(newvp) = readonlyVolume; - } - else if (newType == backupVolume) { + } else if (newType == backupVolume) { AssignVolumeName(&V_disk(newvp), V_name(originalvp), ".backup"); V_type(newvp) = backupVolume; V_backupId(originalvp) = newId; } - strcpy(newvp->header->diskstuff.name,newName); + strcpy(newvp->header->diskstuff.name, newName); V_creationDate(newvp) = V_copyDate(newvp); ClearVolumeStats(&V_disk(newvp)); V_destroyMe(newvp) = DESTROY_ME; @@ -633,108 +659,112 @@ char *newName; V_inUse(newvp) = 0; VUpdateVolume(&error, newvp); if (error) { - Log("1 Volser: Clone: VUpdate failed code %d\n", error); - LogError(error); + Log("1 Volser: Clone: VUpdate failed code %u\n", error); + LogError(error); goto fail; } - VDetachVolume(&error, newvp); /* allow file server to get it's hands on it */ - newvp = (struct Volume *) 0; + VDetachVolume(&error, newvp); /* allow file server to get it's hands on it */ + newvp = NULL; VUpdateVolume(&error, originalvp); if (error) { - Log("1 Volser: Clone: original update %d\n", error); - LogError(error); + Log("1 Volser: Clone: original update %u\n", error); + LogError(error); goto fail; } tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)){ - tt = (struct volser_trans *) 0; + if (TRELE(tt)) { + tt = (struct volser_trans *)0; error = VOLSERTRELE_ERROR; goto fail; } DeleteTrans(ttc); return 0; -fail: - if (purgevp) VDetachVolume(&code, purgevp); - if (newvp) VDetachVolume(&code, newvp); + fail: + if (purgevp) + VDetachVolume(&code, purgevp); + if (newvp) + VDetachVolume(&code, newvp); if (tt) { tt->rxCallPtr = (struct rx_call *)0; TRELE(tt); } - if(ttc) DeleteTrans(ttc); + if (ttc) + DeleteTrans(ttc); return error; } /* reclone this volume into the specified id */ -afs_int32 SAFSVolReClone (acid, atrans, cloneId) -struct rx_call *acid; -afs_int32 atrans; -afs_int32 cloneId; +afs_int32 +SAFSVolReClone(struct rx_call *acid, afs_int32 atrans, afs_int32 cloneId) { - afs_int32 code; + afs_int32 code; - code = VolReClone (acid, atrans, cloneId); - osi_auditU(acid, VS_ReCloneEvent, code, AUD_LONG, atrans, AUD_LONG, cloneId, AUD_END); - return code; + code = VolReClone(acid, atrans, cloneId); + osi_auditU(acid, VS_ReCloneEvent, code, AUD_LONG, atrans, AUD_LONG, + cloneId, AUD_END); + return code; } -afs_int32 VolReClone (acid, atrans, cloneId) -struct rx_call *acid; -afs_int32 atrans; -afs_int32 cloneId; +afs_int32 +VolReClone(struct rx_call *acid, afs_int32 atrans, afs_int32 cloneId) { register struct Volume *originalvp, *clonevp; Error error, code; afs_int32 newType; - register struct volser_trans *tt,*ttc; + register struct volser_trans *tt, *ttc; char caller[MAXKTCNAMELEN]; - - /*not a super user*/ - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS; - if (DoLogging) Log("%s is executing Reclone Volume %u\n", caller, cloneId); + + /*not a super user */ + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; + if (DoLogging) + Log("%s is executing Reclone Volume %u\n", caller, cloneId); error = 0; clonevp = originalvp = (Volume *) 0; - tt = (struct volser_trans *) 0; + tt = (struct volser_trans *)0; tt = FindTrans(atrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolReClone: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolReClone: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } ttc = NewTrans(cloneId, tt->partition); - if (!ttc){ /* someone is messing with the clone already */ + if (!ttc) { /* someone is messing with the clone already */ TRELE(tt); return VBUSY; } - strcpy(tt->lastProcName,"ReClone"); + strcpy(tt->lastProcName, "ReClone"); tt->rxCallPtr = acid; - + originalvp = tt->volume; - if ((V_type(originalvp) == backupVolume) || - (V_type(originalvp) == readonlyVolume)){ - Log("1 Volser: Clone: The volume to be cloned must be a read/write; aborted\n"); + if ((V_type(originalvp) == backupVolume) + || (V_type(originalvp) == readonlyVolume)) { + Log("1 Volser: Clone: The volume to be cloned must be a read/write; aborted\n"); error = EROFS; goto fail; } if ((V_destroyMe(originalvp) == DESTROY_ME) || !V_inService(originalvp)) { - Log("1 Volser: Clone: Volume %d is offline and cannot be cloned\n", - V_id(originalvp)); - error = VOFFLINE; - goto fail; + Log("1 Volser: Clone: Volume %d is offline and cannot be cloned\n", + V_id(originalvp)); + error = VOFFLINE; + goto fail; } - clonevp = VAttachVolume(&error, cloneId, V_UPDATE); + clonevp = VAttachVolume(&error, cloneId, V_VOLUPD); if (error) { Log("1 Volser: can't attach clone %d\n", cloneId); goto fail; } - newType = V_type(clonevp); /* type of the new volume */ + newType = V_type(clonevp); /* type of the new volume */ if (originalvp->device != clonevp->device) { - Log("1 Volser: Clone: Volumes %u and %u are on different devices\n", tt->volid, cloneId); + Log("1 Volser: Clone: Volumes %u and %u are on different devices\n", + tt->volid, cloneId); error = EXDEV; goto fail; } @@ -743,24 +773,26 @@ afs_int32 cloneId; error = EINVAL; goto fail; } - if (V_type(originalvp) == readonlyVolume && V_parentId(originalvp) != V_parentId(clonevp)) { + if (V_type(originalvp) == readonlyVolume + && V_parentId(originalvp) != V_parentId(clonevp)) { Log("1 Volser: Clone: Volume %u and volume %u were not cloned from the same parent volume; aborted\n", tt->volid, cloneId); error = EXDEV; goto fail; } - if (V_type(originalvp) == readwriteVolume && tt->volid != V_parentId(clonevp)) { - Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", - cloneId, tt->volid); + if (V_type(originalvp) == readwriteVolume + && tt->volid != V_parentId(clonevp)) { + Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", cloneId, tt->volid); error = EXDEV; goto fail; } error = 0; - Log("1 Volser: Clone: Recloning volume %u to volume %u\n", - tt->volid, cloneId); + Log("1 Volser: Clone: Recloning volume %u to volume %u\n", tt->volid, + cloneId); CloneVolume(&error, originalvp, clonevp, clonevp); if (error) { - Log("1 Volser: Clone: reclone operation failed with code %d\n", error); + Log("1 Volser: Clone: reclone operation failed with code %d\n", + error); LogError(error); goto fail; } @@ -769,8 +801,7 @@ afs_int32 cloneId; if (newType == readonlyVolume) { AssignVolumeName(&V_disk(clonevp), V_name(originalvp), ".readonly"); V_type(clonevp) = readonlyVolume; - } - else if (newType == backupVolume) { + } else if (newType == backupVolume) { AssignVolumeName(&V_disk(clonevp), V_name(originalvp), ".backup"); V_type(clonevp) = backupVolume; V_backupId(originalvp) = cloneId; @@ -790,40 +821,42 @@ afs_int32 cloneId; V_inUse(clonevp) = 0; VUpdateVolume(&error, clonevp); if (error) { - Log("1 Volser: Clone: VUpdate failed code %d\n", error); + Log("1 Volser: Clone: VUpdate failed code %u\n", error); LogError(error); goto fail; } - VDetachVolume(&error, clonevp); /* allow file server to get it's hands on it */ - clonevp = (struct Volume *) 0; + VDetachVolume(&error, clonevp); /* allow file server to get it's hands on it */ + clonevp = NULL; VUpdateVolume(&error, originalvp); if (error) { - Log("1 Volser: Clone: original update %d\n", error); - LogError(error); + Log("1 Volser: Clone: original update %u\n", error); + LogError(error); goto fail; } tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)){ - tt = (struct volser_trans *) 0; + if (TRELE(tt)) { + tt = (struct volser_trans *)0; error = VOLSERTRELE_ERROR; goto fail; } - + DeleteTrans(ttc); { - struct DiskPartition *tpartp = originalvp->partition; - FSYNC_askfs(cloneId, tpartp->name, FSYNC_RESTOREVOLUME, 0); + struct DiskPartition *tpartp = originalvp->partition; + FSYNC_askfs(cloneId, tpartp->name, FSYNC_RESTOREVOLUME, 0); } return 0; -fail: - if (clonevp) VDetachVolume(&code, clonevp); + fail: + if (clonevp) + VDetachVolume(&code, clonevp); if (tt) { tt->rxCallPtr = (struct rx_call *)0; TRELE(tt); } - if(ttc) DeleteTrans(ttc); + if (ttc) + DeleteTrans(ttc); return error; } @@ -831,26 +864,21 @@ fail: * volume transaction is spec'd by iflags. New trans id is returned in ttid. * See volser.h for definition of iflags (the constants are named IT*). */ -afs_int32 SAFSVolTransCreate (acid, volume, partition, iflags, ttid) -struct rx_call *acid; -afs_int32 volume; -afs_int32 partition; -afs_int32 iflags; -afs_int32 *ttid; +afs_int32 +SAFSVolTransCreate(struct rx_call *acid, afs_int32 volume, afs_int32 partition, + afs_int32 iflags, afs_int32 *ttid) { - afs_int32 code; + afs_int32 code; - code = VolTransCreate (acid, volume, partition, iflags, ttid); - osi_auditU(acid, VS_TransCrEvent, code, AUD_LONG, *ttid, AUD_LONG, volume, AUD_END); - return code; + code = VolTransCreate(acid, volume, partition, iflags, ttid); + osi_auditU(acid, VS_TransCrEvent, code, AUD_LONG, *ttid, AUD_LONG, volume, + AUD_END); + return code; } -afs_int32 VolTransCreate (acid, volume, partition, iflags, ttid) -struct rx_call *acid; -afs_int32 volume; -afs_int32 partition; -afs_int32 iflags; -afs_int32 *ttid; +afs_int32 +VolTransCreate(struct rx_call *acid, afs_int32 volume, afs_int32 partition, + afs_int32 iflags, afs_int32 *ttid) { register struct volser_trans *tt; register Volume *tv; @@ -858,13 +886,19 @@ afs_int32 *ttid; afs_int32 mode; char caller[MAXKTCNAMELEN]; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ - if (iflags & ITCreate) mode = V_SECRETLY; - else if (iflags & ITBusy) mode = V_CLONE; - else if (iflags & ITReadOnly) mode = V_READONLY; - else if (iflags & ITOffline) mode = V_UPDATE; - else { - Log("1 Volser: TransCreate: Could not create trans, error %u\n",EINVAL); + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ + if (iflags & ITCreate) + mode = V_SECRETLY; + else if (iflags & ITBusy) + mode = V_CLONE; + else if (iflags & ITReadOnly) + mode = V_READONLY; + else if (iflags & ITOffline) + mode = V_VOLUPD; + else { + Log("1 Volser: TransCreate: Could not create trans, error %u\n", + EINVAL); LogError(EINVAL); return EINVAL; } @@ -877,7 +911,8 @@ afs_int32 *ttid; tv = XAttachVolume(&error, volume, partition, mode); if (error) { /* give up */ - if (tv) VDetachVolume(&code, tv); + if (tv) + VDetachVolume(&code, tv); DeleteTrans(tt); return error; } @@ -885,73 +920,69 @@ afs_int32 *ttid; *ttid = tt->tid; tt->iflags = iflags; tt->vflags = 0; - strcpy(tt->lastProcName,"TransCreate"); - if(TRELE(tt)) return VOLSERTRELE_ERROR; - + strcpy(tt->lastProcName, "TransCreate"); + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + return 0; } /* using aindex as a 0-based index, return the aindex'th volume on this server * Both the volume number and partition number (one-based) are returned. */ -afs_int32 SAFSVolGetNthVolume (acid, aindex, avolume, apart) -struct rx_call *acid; -afs_int32 aindex; -afs_int32 *avolume; -afs_int32 *apart; +afs_int32 +SAFSVolGetNthVolume(struct rx_call *acid, afs_int32 aindex, afs_int32 *avolume, + afs_int32 *apart) { - afs_int32 code; + afs_int32 code; - code = VolGetNthVolume (acid, aindex, avolume, apart); - osi_auditU(acid, VS_GetNVolEvent, code, AUD_LONG, *avolume, AUD_END); - return code; + code = VolGetNthVolume(acid, aindex, avolume, apart); + osi_auditU(acid, VS_GetNVolEvent, code, AUD_LONG, *avolume, AUD_END); + return code; } -afs_int32 VolGetNthVolume (acid, aindex, avolume, apart) -struct rx_call *acid; -afs_int32 aindex; -afs_int32 *avolume; -afs_int32 *apart; +afs_int32 +VolGetNthVolume(struct rx_call *acid, afs_int32 aindex, afs_int32 *avolume, + afs_int32 *apart) { - Log("1 Volser: GetNthVolume: Not yet implemented\n"); + Log("1 Volser: GetNthVolume: Not yet implemented\n"); return VOLSERNO_OP; } /* return the volume flags (VT* constants in volser.h) associated with this * transaction. */ -afs_int32 SAFSVolGetFlags (acid, atid, aflags) -struct rx_call *acid; -afs_int32 atid; -afs_int32 *aflags; +afs_int32 +SAFSVolGetFlags(struct rx_call *acid, afs_int32 atid, afs_int32 *aflags) { - afs_int32 code; + afs_int32 code; - code = VolGetFlags (acid, atid, aflags); - osi_auditU(acid, VS_GetFlgsEvent, code, AUD_LONG, atid, AUD_END); - return code; + code = VolGetFlags(acid, atid, aflags); + osi_auditU(acid, VS_GetFlgsEvent, code, AUD_LONG, atid, AUD_END); + return code; } -afs_int32 VolGetFlags (acid, atid, aflags) -struct rx_call *acid; -afs_int32 atid; -afs_int32 *aflags; +afs_int32 +VolGetFlags(struct rx_call *acid, afs_int32 atid, afs_int32 *aflags) { register struct volser_trans *tt; - + tt = FindTrans(atid); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolGetFlags: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolGetFlags: volume %u has been deleted \n", + tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"GetFlags"); + strcpy(tt->lastProcName, "GetFlags"); tt->rxCallPtr = acid; *aflags = tt->vflags; tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)) return VOLSERTRELE_ERROR; - + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + return 0; } @@ -959,40 +990,40 @@ afs_int32 *aflags; * transaction. Effects take place immediately on volume, although volume * remains attached as usual by the transaction. */ -afs_int32 SAFSVolSetFlags (acid, atid, aflags) -struct rx_call *acid; -afs_int32 atid; -afs_int32 aflags; +afs_int32 +SAFSVolSetFlags(struct rx_call *acid, afs_int32 atid, afs_int32 aflags) { - afs_int32 code; + afs_int32 code; - code = VolSetFlags (acid, atid, aflags); - osi_auditU(acid, VS_SetFlgsEvent, code, AUD_LONG, atid, AUD_LONG, aflags, AUD_END); - return code; + code = VolSetFlags(acid, atid, aflags); + osi_auditU(acid, VS_SetFlgsEvent, code, AUD_LONG, atid, AUD_LONG, aflags, + AUD_END); + return code; } -afs_int32 VolSetFlags (acid, atid, aflags) -struct rx_call *acid; -afs_int32 atid; -afs_int32 aflags; +afs_int32 +VolSetFlags(struct rx_call *acid, afs_int32 atid, afs_int32 aflags) { register struct volser_trans *tt; register struct Volume *vp; afs_int32 error; char caller[MAXKTCNAMELEN]; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ /* find the trans */ tt = FindTrans(atid); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolSetFlags: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolSetFlags: volume %u has been deleted \n", + tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"SetFlags"); + strcpy(tt->lastProcName, "SetFlags"); tt->rxCallPtr = acid; - vp = tt->volume; /* pull volume out of transaction */ + vp = tt->volume; /* pull volume out of transaction */ /* check if we're allowed to make any updates */ if (tt->iflags & ITReadOnly) { @@ -1003,22 +1034,21 @@ afs_int32 aflags; /* handle delete-on-salvage flag */ if (aflags & VTDeleteOnSalvage) { V_destroyMe(tt->volume) = DESTROY_ME; - } - else { + } else { V_destroyMe(tt->volume) = 0; } - + if (aflags & VTOutOfService) { V_inService(vp) = 0; - } - else { + } else { V_inService(vp) = 1; } VUpdateVolume(&error, vp); tt->vflags = aflags; tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt) && !error) return VOLSERTRELE_ERROR; - + if (TRELE(tt) && !error) + return VOLSERTRELE_ERROR; + return error; } @@ -1026,30 +1056,24 @@ afs_int32 aflags; * date. Send the dump to a different transaction (destTrans) on the server * specified by the destServer structure. */ -afs_int32 SAFSVolForward (acid, fromTrans, fromDate, destination, destTrans,cookie) -struct rx_call *acid; -afs_int32 fromTrans; -afs_int32 fromDate; -struct destServer *destination; -struct restoreCookie *cookie; -afs_int32 destTrans; -{ - afs_int32 code; - - code = VolForward (acid, fromTrans, fromDate, destination, destTrans,cookie); - osi_auditU(acid, VS_ForwardEvent, code, AUD_LONG, fromTrans, - AUD_HOST, destination->destHost, - AUD_LONG, destTrans, AUD_END); - return code; -} - -afs_int32 VolForward (acid, fromTrans, fromDate, destination, destTrans,cookie) -struct rx_call *acid; -afs_int32 fromTrans; -afs_int32 fromDate; -struct destServer *destination; -struct restoreCookie *cookie; -afs_int32 destTrans; +afs_int32 +SAFSVolForward(struct rx_call *acid, afs_int32 fromTrans, afs_int32 fromDate, + struct destServer *destination, afs_int32 destTrans, + struct restoreCookie *cookie) +{ + afs_int32 code; + + code = + VolForward(acid, fromTrans, fromDate, destination, destTrans, cookie); + osi_auditU(acid, VS_ForwardEvent, code, AUD_LONG, fromTrans, AUD_HOST, + destination->destHost, AUD_LONG, destTrans, AUD_END); + return code; +} + +afs_int32 +VolForward(struct rx_call *acid, afs_int32 fromTrans, afs_int32 fromDate, + struct destServer *destination, afs_int32 destTrans, + struct restoreCookie *cookie) { register struct volser_trans *tt; register afs_int32 code; @@ -1060,22 +1084,24 @@ afs_int32 destTrans; afs_int32 securityIndex; char caller[MAXKTCNAMELEN]; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ /* initialize things */ - tcon = (struct rx_connection *) 0; - tt = (struct volser_trans *) 0; + tcon = (struct rx_connection *)0; + tt = (struct volser_trans *)0; /* find the local transaction */ tt = FindTrans(fromTrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolForward: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolForward: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } vp = tt->volume; - strcpy(tt->lastProcName,"Forward"); - + strcpy(tt->lastProcName, "Forward"); + /* get auth info for the this connection (uses afs from ticket file) */ code = afsconf_ClientAuth(tdir, &securityObject, &securityIndex); if (code) { @@ -1084,39 +1110,45 @@ afs_int32 destTrans; } /* make an rpc connection to the other server */ - tcon = rx_NewConnection(htonl(destination->destHost), htons(destination->destPort),VOLSERVICE_ID, securityObject, securityIndex); + tcon = + rx_NewConnection(htonl(destination->destHost), + htons(destination->destPort), VOLSERVICE_ID, + securityObject, securityIndex); if (!tcon) { - tt->rxCallPtr = (struct rx_call *)0; + tt->rxCallPtr = (struct rx_call *)0; TRELE(tt); return ENOTCONN; } tcall = rx_NewCall(tcon); tt->rxCallPtr = tcall; /* start restore going. fromdate == 0 --> doing an incremental dump/restore */ - code = StartAFSVolRestore(tcall, destTrans, (fromDate? 1 : 0),cookie); + code = StartAFSVolRestore(tcall, destTrans, (fromDate ? 1 : 0), cookie); if (code) { goto fail; } /* these next calls implictly call rx_Write when writing out data */ - code = DumpVolume(tcall, vp, fromDate, 0);/* last field = don't dump all dirs */ - if (code) goto fail; - EndAFSVolRestore(tcall); /* probably doesn't do much */ + code = DumpVolume(tcall, vp, fromDate, 0); /* last field = don't dump all dirs */ + if (code) + goto fail; + EndAFSVolRestore(tcall); /* probably doesn't do much */ tt->rxCallPtr = (struct rx_call *)0; code = rx_EndCall(tcall, 0); - rx_DestroyConnection(tcon); /* done with the connection */ + rx_DestroyConnection(tcon); /* done with the connection */ tcon = NULL; - if (code) goto fail; - if(TRELE(tt)) return VOLSERTRELE_ERROR; - + if (code) + goto fail; + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + return 0; - -fail: + + fail: if (tcon) { - rx_EndCall(tcall,0); + (void)rx_EndCall(tcall, 0); rx_DestroyConnection(tcon); } - if (tt){ + if (tt) { tt->rxCallPtr = (struct rx_call *)0; TRELE(tt); } @@ -1133,300 +1165,301 @@ fail: * need just an incremental (and from the same time), if that's * what we're doing. */ -afs_int32 SAFSVolForwardMultiple (acid, fromTrans, fromDate, destinations, - spare, cookie, results) - struct rx_call *acid; - afs_int32 fromTrans; - afs_int32 fromDate; - afs_int32 spare; - manyDests *destinations; - struct restoreCookie *cookie; - manyResults *results; -{ - afs_int32 securityIndex; - struct rx_securityClass *securityObject; - char caller[MAXKTCNAMELEN]; - struct volser_trans *tt; - afs_int32 ec, code, *codes; - struct rx_connection **tcons; - struct rx_call **tcalls; - struct Volume *vp; - int i, nconns, is_incremental; - - if (results) - memset(results, 0, sizeof(manyResults)); - - if (!afsconf_SuperUser(tdir, acid, caller)) - return VOLSERBAD_ACCESS;/*not a super user*/ - tt = FindTrans(fromTrans); - if (!tt) - return ENOENT; - if (tt->vflags & VTDeleted) { - Log("1 Volser: VolForward: volume %u has been deleted \n",tt->volid); - TRELE(tt); - return ENOENT; - } - vp = tt->volume; - strcpy(tt->lastProcName, "ForwardMulti"); - - /* (fromDate == 0) ==> incremental dump */ - is_incremental = (fromDate ? 1 : 0); - - i= results->manyResults_len = destinations->manyDests_len; - results->manyResults_val = codes = (afs_int32 *)malloc(i * sizeof(afs_int32)); - tcons = (struct rx_connection **) malloc (i*sizeof (struct rx_connection *)); - tcalls = (struct rx_call **) malloc (i*sizeof (struct rx_call *)); - - /* get auth info for this connection (uses afs from ticket file) */ - code = afsconf_ClientAuth(tdir, &securityObject, &securityIndex); - if (code) { - goto fail; /* in order to audit each failure */ - } - - /* make connections to all the other servers */ - for (i=0; i < destinations->manyDests_len; i++) { - struct replica *dest = &(destinations->manyDests_val[i]); - tcons[i] = rx_NewConnection(htonl(dest->server.destHost), - htons(dest->server.destPort), - VOLSERVICE_ID, securityObject, securityIndex); - if (!tcons[i]) { - codes[i] = ENOTCONN; +afs_int32 +SAFSVolForwardMultiple(struct rx_call *acid, afs_int32 fromTrans, afs_int32 + fromDate, manyDests *destinations, afs_int32 spare, + struct restoreCookie *cookie, manyResults *results) +{ + afs_int32 securityIndex; + struct rx_securityClass *securityObject; + char caller[MAXKTCNAMELEN]; + struct volser_trans *tt; + afs_int32 ec, code, *codes; + struct rx_connection **tcons; + struct rx_call **tcalls; + struct Volume *vp; + int i, is_incremental; + + if (results) + memset(results, 0, sizeof(manyResults)); + + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ + tt = FindTrans(fromTrans); + if (!tt) + return ENOENT; + if (tt->vflags & VTDeleted) { + Log("1 Volser: VolForward: volume %u has been deleted \n", tt->volid); + TRELE(tt); + return ENOENT; } - else { - if (!(tcalls[i] = rx_NewCall(tcons[i]))) - codes[i]=ENOTCONN; - else { - codes[i] = StartAFSVolRestore(tcalls[i], dest->trans, - is_incremental,cookie); - if (codes[i]) { - rx_EndCall (tcalls[i],0); tcalls[i] = 0; - rx_DestroyConnection(tcons[i]); tcons[i] = 0; + vp = tt->volume; + strcpy(tt->lastProcName, "ForwardMulti"); + + /* (fromDate == 0) ==> incremental dump */ + is_incremental = (fromDate ? 1 : 0); + + i = results->manyResults_len = destinations->manyDests_len; + results->manyResults_val = codes = + (afs_int32 *) malloc(i * sizeof(afs_int32)); + tcons = + (struct rx_connection **)malloc(i * sizeof(struct rx_connection *)); + tcalls = (struct rx_call **)malloc(i * sizeof(struct rx_call *)); + + /* get auth info for this connection (uses afs from ticket file) */ + code = afsconf_ClientAuth(tdir, &securityObject, &securityIndex); + if (code) { + goto fail; /* in order to audit each failure */ + } + + /* make connections to all the other servers */ + for (i = 0; i < destinations->manyDests_len; i++) { + struct replica *dest = &(destinations->manyDests_val[i]); + tcons[i] = + rx_NewConnection(htonl(dest->server.destHost), + htons(dest->server.destPort), VOLSERVICE_ID, + securityObject, securityIndex); + if (!tcons[i]) { + codes[i] = ENOTCONN; + } else { + if (!(tcalls[i] = rx_NewCall(tcons[i]))) + codes[i] = ENOTCONN; + else { + codes[i] = + StartAFSVolRestore(tcalls[i], dest->trans, is_incremental, + cookie); + if (codes[i]) { + (void)rx_EndCall(tcalls[i], 0); + tcalls[i] = 0; + rx_DestroyConnection(tcons[i]); + tcons[i] = 0; + } + } } - } - } - } - - /* these next calls implictly call rx_Write when writing out data */ - code = DumpVolMulti(tcalls, i, vp, fromDate, 0, codes); - - -fail: - for (i--; i >=0 ; i--) { - struct replica *dest = &(destinations->manyDests_val[i]); - - if (!code && tcalls[i] && !codes[i]) { - EndAFSVolRestore(tcalls[i]); - } - if (tcalls[i]) { - ec = rx_EndCall(tcalls[i], 0); - if (!codes[i]) codes[i] = ec; - } - if (tcons[i]) { - rx_DestroyConnection(tcons[i]); /* done with the connection */ - } - - osi_auditU(acid, VS_ForwardEvent, (code ? code : codes[i]), - AUD_LONG, fromTrans, AUD_HOST, dest->server.destHost, - AUD_LONG, dest->trans, AUD_END); - } - free (tcons); - free (tcalls); - - if (tt) { - tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt) && !code) /* return the first code if it's set */ - return VOLSERTRELE_ERROR; - } - - return code; + } + + /* these next calls implictly call rx_Write when writing out data */ + code = DumpVolMulti(tcalls, i, vp, fromDate, 0, codes); + + + fail: + for (i--; i >= 0; i--) { + struct replica *dest = &(destinations->manyDests_val[i]); + + if (!code && tcalls[i] && !codes[i]) { + EndAFSVolRestore(tcalls[i]); + } + if (tcalls[i]) { + ec = rx_EndCall(tcalls[i], 0); + if (!codes[i]) + codes[i] = ec; + } + if (tcons[i]) { + rx_DestroyConnection(tcons[i]); /* done with the connection */ + } + + osi_auditU(acid, VS_ForwardEvent, (code ? code : codes[i]), AUD_LONG, + fromTrans, AUD_HOST, dest->server.destHost, AUD_LONG, + dest->trans, AUD_END); + } + free(tcons); + free(tcalls); + + if (tt) { + tt->rxCallPtr = (struct rx_call *)0; + if (TRELE(tt) && !code) /* return the first code if it's set */ + return VOLSERTRELE_ERROR; + } + + return code; } -afs_int32 SAFSVolDump (acid, fromTrans, fromDate) -struct rx_call *acid; -afs_int32 fromTrans; -afs_int32 fromDate; +afs_int32 +SAFSVolDump(struct rx_call *acid, afs_int32 fromTrans, afs_int32 fromDate) { - afs_int32 code; + afs_int32 code; - code = VolDump (acid, fromTrans, fromDate); - osi_auditU(acid, VS_DumpEvent, code, AUD_LONG, fromTrans, AUD_END); - return code; + code = VolDump(acid, fromTrans, fromDate); + osi_auditU(acid, VS_DumpEvent, code, AUD_LONG, fromTrans, AUD_END); + return code; } -afs_int32 VolDump (acid, fromTrans, fromDate) -struct rx_call *acid; -afs_int32 fromTrans; -afs_int32 fromDate; +afs_int32 +VolDump(struct rx_call *acid, afs_int32 fromTrans, afs_int32 fromDate) { int code = 0; register struct volser_trans *tt; char caller[MAXKTCNAMELEN]; - - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ tt = FindTrans(fromTrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolDump: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolDump: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"Dump"); + strcpy(tt->lastProcName, "Dump"); tt->rxCallPtr = acid; code = DumpVolume(acid, tt->volume, fromDate, 1); /* squirt out the volume's data, too */ - if(code){tt->rxCallPtr = (struct rx_call *)0; TRELE(tt); return code;} - tt->rxCallPtr = (struct rx_call *)0; - - if(TRELE(tt)) return VOLSERTRELE_ERROR; - + if (code) { + tt->rxCallPtr = (struct rx_call *)0; + TRELE(tt); + return code; + } + tt->rxCallPtr = (struct rx_call *)0; + + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + return 0; } /* * Ha! No more helper process! */ -afs_int32 SAFSVolRestore (acid, atrans, aflags,cookie) -struct rx_call *acid; -int aflags; -afs_int32 atrans; -struct restoreCookie *cookie; +afs_int32 +SAFSVolRestore(struct rx_call *acid, afs_int32 atrans, afs_int32 aflags, + struct restoreCookie *cookie) { - afs_int32 code; + afs_int32 code; - code = VolRestore (acid, atrans, aflags,cookie); - osi_auditU(acid, VS_RestoreEvent, code, AUD_LONG, atrans, AUD_END); - return code; + code = VolRestore(acid, atrans, aflags, cookie); + osi_auditU(acid, VS_RestoreEvent, code, AUD_LONG, atrans, AUD_END); + return code; } -afs_int32 VolRestore (acid, atrans, aflags,cookie) -struct rx_call *acid; -int aflags; -afs_int32 atrans; -struct restoreCookie *cookie; +afs_int32 +VolRestore(struct rx_call *acid, afs_int32 atrans, afs_int32 aflags, + struct restoreCookie *cookie) { register struct volser_trans *tt; - register afs_int32 code,tcode; + register afs_int32 code, tcode; char caller[MAXKTCNAMELEN]; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ tt = FindTrans(atrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolRestore: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolRestore: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"Restore"); + strcpy(tt->lastProcName, "Restore"); tt->rxCallPtr = acid; DFlushVolume(V_parentId(tt->volume)); /* Ensure dir buffers get dropped */ - code = RestoreVolume(acid, tt->volume, (aflags & 1),cookie); /* last is incrementalp */ - FSYNC_askfs(tt->volid, (char *) 0, FSYNC_RESTOREVOLUME, 0l);/*break call backs on the - restored volume */ - tt->rxCallPtr = (struct rx_call *)0; + code = RestoreVolume(acid, tt->volume, (aflags & 1), cookie); /* last is incrementalp */ + FSYNC_askfs(tt->volid, NULL, FSYNC_RESTOREVOLUME, 0l); /*break call backs on the + * restored volume */ + tt->rxCallPtr = (struct rx_call *)0; tcode = TRELE(tt); - - return (code? code : tcode); + + return (code ? code : tcode); } /* end a transaction, returning the transaction's final error code in rcode */ -afs_int32 SAFSVolEndTrans (acid, destTrans, rcode) -struct rx_call *acid; -afs_int32 destTrans; -afs_int32 *rcode; +afs_int32 +SAFSVolEndTrans(struct rx_call *acid, afs_int32 destTrans, afs_int32 *rcode) { - afs_int32 code; + afs_int32 code; - code = VolEndTrans (acid, destTrans, rcode); - osi_auditU(acid, VS_EndTrnEvent, code, AUD_LONG, destTrans, AUD_END); - return code; + code = VolEndTrans(acid, destTrans, rcode); + osi_auditU(acid, VS_EndTrnEvent, code, AUD_LONG, destTrans, AUD_END); + return code; } -afs_int32 VolEndTrans (acid, destTrans, rcode) -struct rx_call *acid; -afs_int32 destTrans; -afs_int32 *rcode; +afs_int32 +VolEndTrans(struct rx_call *acid, afs_int32 destTrans, afs_int32 *rcode) { register struct volser_trans *tt; char caller[MAXKTCNAMELEN]; - - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ tt = FindTrans(destTrans); - if (!tt) {return ENOENT;} + if (!tt) { + return ENOENT; + } *rcode = tt->returnCode; - DeleteTrans(tt); /* this does an implicit TRELE */ - + DeleteTrans(tt); /* this does an implicit TRELE */ + return 0; } -afs_int32 SAFSVolSetForwarding (acid, atid, anewsite) -struct rx_call *acid; -afs_int32 atid; -afs_int32 anewsite; +afs_int32 +SAFSVolSetForwarding(struct rx_call *acid, afs_int32 atid, afs_int32 anewsite) { - afs_int32 code; + afs_int32 code; - code = VolSetForwarding (acid, atid, anewsite); - osi_auditU(acid, VS_SetForwEvent, code, AUD_LONG, atid, AUD_HOST, anewsite, AUD_END); - return code; + code = VolSetForwarding(acid, atid, anewsite); + osi_auditU(acid, VS_SetForwEvent, code, AUD_LONG, atid, AUD_HOST, + anewsite, AUD_END); + return code; } -afs_int32 VolSetForwarding (acid, atid, anewsite) -struct rx_call *acid; -afs_int32 atid; -afs_int32 anewsite; +afs_int32 +VolSetForwarding(struct rx_call *acid, afs_int32 atid, afs_int32 anewsite) { - register struct volser_trans *tt; char caller[MAXKTCNAMELEN]; - - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ tt = FindTrans(atid); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolSetForwarding: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolSetForwarding: volume %u has been deleted \n", + tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"SetForwarding"); + strcpy(tt->lastProcName, "SetForwarding"); tt->rxCallPtr = acid; - FSYNC_askfs(tt->volid, (char *) 0, FSYNC_MOVEVOLUME, anewsite); + FSYNC_askfs(tt->volid, NULL, FSYNC_MOVEVOLUME, anewsite); tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)) return VOLSERTRELE_ERROR; - + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + return 0; } -afs_int32 SAFSVolGetStatus (acid, atrans, astatus) -struct rx_call *acid; -afs_int32 atrans; -register struct volser_status *astatus; +afs_int32 +SAFSVolGetStatus(struct rx_call *acid, afs_int32 atrans, + register struct volser_status *astatus) { - afs_int32 code; + afs_int32 code; - code = VolGetStatus (acid, atrans, astatus); - osi_auditU(acid, VS_GetStatEvent, code, AUD_LONG, atrans, AUD_END); - return code; + code = VolGetStatus(acid, atrans, astatus); + osi_auditU(acid, VS_GetStatEvent, code, AUD_LONG, atrans, AUD_END); + return code; } -afs_int32 VolGetStatus (acid, atrans, astatus) -struct rx_call *acid; -afs_int32 atrans; -register struct volser_status *astatus; +afs_int32 +VolGetStatus(struct rx_call *acid, afs_int32 atrans, + register struct volser_status *astatus) { register struct Volume *tv; register struct VolumeDiskData *td; struct volser_trans *tt; - - + + tt = FindTrans(atrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolGetStatus: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolGetStatus: volume %u has been deleted \n", + tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"GetStatus"); + strcpy(tt->lastProcName, "GetStatus"); tt->rxCallPtr = acid; tv = tt->volume; if (!tv) { @@ -1434,7 +1467,7 @@ register struct volser_status *astatus; TRELE(tt); return ENOENT; } - + td = &tv->header->diskstuff; astatus->volID = td->id; astatus->nextUnique = td->uniquifier; @@ -1453,27 +1486,26 @@ register struct volser_status *astatus; astatus->backupDate = td->backupDate; astatus->copyDate = td->copyDate; tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)) return VOLSERTRELE_ERROR; - + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + return 0; } -afs_int32 SAFSVolSetInfo (acid, atrans, astatus) -struct rx_call *acid; -afs_int32 atrans; -register struct volintInfo *astatus; +afs_int32 +SAFSVolSetInfo(struct rx_call *acid, afs_int32 atrans, + register struct volintInfo *astatus) { - afs_int32 code; + afs_int32 code; - code = VolSetInfo (acid, atrans, astatus); - osi_auditU(acid, VS_SetInfoEvent, code, AUD_LONG, atrans, AUD_END); - return code; + code = VolSetInfo(acid, atrans, astatus); + osi_auditU(acid, VS_SetInfoEvent, code, AUD_LONG, atrans, AUD_END); + return code; } -afs_int32 VolSetInfo (acid, atrans, astatus) -struct rx_call *acid; -afs_int32 atrans; -register struct volintInfo *astatus; +afs_int32 +VolSetInfo(struct rx_call *acid, afs_int32 atrans, + register struct volintInfo *astatus) { register struct Volume *tv; register struct VolumeDiskData *td; @@ -1481,15 +1513,17 @@ register struct volintInfo *astatus; char caller[MAXKTCNAMELEN]; afs_int32 error; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ tt = FindTrans(atrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolSetInfo: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolSetInfo: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"SetStatus"); + strcpy(tt->lastProcName, "SetStatus"); tt->rxCallPtr = acid; tv = tt->volume; if (!tv) { @@ -1497,7 +1531,7 @@ register struct volintInfo *astatus; TRELE(tt); return ENOENT; } - + td = &tv->header->diskstuff; /* * Add more fields as necessary @@ -1508,42 +1542,40 @@ register struct volintInfo *astatus; td->dayUse = astatus->dayUse; VUpdateVolume(&error, tv); tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)) return VOLSERTRELE_ERROR; + if (TRELE(tt)) + return VOLSERTRELE_ERROR; return 0; } -afs_int32 SAFSVolGetName (acid, atrans, aname) -struct rx_call *acid; -afs_int32 atrans; -char **aname; +afs_int32 +SAFSVolGetName(struct rx_call *acid, afs_int32 atrans, char **aname) { - afs_int32 code; + afs_int32 code; - code = VolGetName (acid, atrans, aname); - osi_auditU(acid, VS_GetNameEvent, code, AUD_LONG, atrans, AUD_END); - return code; + code = VolGetName(acid, atrans, aname); + osi_auditU(acid, VS_GetNameEvent, code, AUD_LONG, atrans, AUD_END); + return code; } -afs_int32 VolGetName (acid, atrans, aname) -struct rx_call *acid; -afs_int32 atrans; -char **aname; +afs_int32 +VolGetName(struct rx_call *acid, afs_int32 atrans, char **aname) { register struct Volume *tv; register struct VolumeDiskData *td; struct volser_trans *tt; register int len; - - *aname = (char *)0; + + *aname = NULL; tt = FindTrans(atrans); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolGetName: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolGetName: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"GetName"); + strcpy(tt->lastProcName, "GetName"); tt->rxCallPtr = acid; tv = tt->volume; if (!tv) { @@ -1551,9 +1583,9 @@ char **aname; TRELE(tt); return ENOENT; } - + td = &tv->header->diskstuff; - len = strlen(td->name)+1; /* don't forget the null */ + len = strlen(td->name) + 1; /* don't forget the null */ if (len >= SIZE) { tt->rxCallPtr = (struct rx_call *)0; TRELE(tt); @@ -1562,48 +1594,45 @@ char **aname; *aname = (char *)malloc(len); strcpy(*aname, td->name); tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt)) return VOLSERTRELE_ERROR; - + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + return 0; } + /*this is a handshake to indicate that the next call will be SAFSVolRestore * - a noop now !*/ -afs_int32 SAFSVolSignalRestore (acid, volname, volType, parentId, cloneId) -struct rx_call *acid; -char volname[]; -afs_int32 parentId, cloneId; -int volType; +afs_int32 +SAFSVolSignalRestore(struct rx_call *acid, char volname[], int volType, + afs_int32 parentId, afs_int32 cloneId) { - return 0; + return 0; } /*return a list of all partitions on the server. The non mounted *partitions are returned as -1 in the corresponding slot in partIds*/ -afs_int32 SAFSVolListPartitions (acid, partIds) -struct rx_call *acid; -struct pIDs *partIds; +afs_int32 +SAFSVolListPartitions(struct rx_call *acid, struct pIDs *partIds) { - afs_int32 code; + afs_int32 code; - code = VolListPartitions (acid, partIds); - osi_auditU(acid, VS_ListParEvent, code, AUD_END); - return code; + code = VolListPartitions(acid, partIds); + osi_auditU(acid, VS_ListParEvent, code, AUD_END); + return code; } -afs_int32 VolListPartitions (acid, partIds) -struct rx_call *acid; -struct pIDs *partIds; -{ +afs_int32 +VolListPartitions(struct rx_call *acid, struct pIDs *partIds) +{ char namehead[9]; - int code; char i; - strcpy(namehead, "/vicep"); /*7 including null terminator*/ + strcpy(namehead, "/vicep"); /*7 including null terminator */ /* Just return attached partitions. */ namehead[7] = '\0'; - for (i=0; i<26; i++) { + for (i = 0; i < 26; i++) { namehead[6] = i + 'a'; if (VGetPartition(namehead, 0)) partIds->partIds[i] = VGetPartition(namehead, 0) ? i : -1; @@ -1614,38 +1643,36 @@ struct pIDs *partIds; /*return a list of all partitions on the server. The non mounted *partitions are returned as -1 in the corresponding slot in partIds*/ -afs_int32 SAFSVolXListPartitions (acid, pEntries) -struct rx_call *acid; -struct partEntries *pEntries; +afs_int32 +SAFSVolXListPartitions(struct rx_call *acid, struct partEntries *pEntries) { - afs_int32 code; + afs_int32 code; - code = XVolListPartitions (acid, pEntries); - osi_auditU(acid, VS_ListParEvent, code, AUD_END); - return code; + code = XVolListPartitions(acid, pEntries); + osi_auditU(acid, VS_ListParEvent, code, AUD_END); + return code; } -afs_int32 XVolListPartitions (acid, pEntries) -struct rx_call *acid; -struct partEntries *pEntries; -{ +afs_int32 +XVolListPartitions(struct rx_call *acid, struct partEntries *pEntries) +{ struct stat rbuf, pbuf; char namehead[9]; struct partList partList; struct DiskPartition *dp; - int i, j=0, k; + int i, j = 0, k; - strcpy(namehead, "/vicep"); /*7 including null terminator*/ + strcpy(namehead, "/vicep"); /*7 including null terminator */ /* Only report attached partitions */ - for(i = 0 ; i < VOLMAXPARTS; i++){ + for (i = 0; i < VOLMAXPARTS; i++) { if (i < 26) { namehead[6] = i + 'a'; namehead[7] = '\0'; } else { k = i - 26; - namehead[6] = 'a' + (k/26); - namehead[7] = 'a' + (k%26); + namehead[6] = 'a' + (k / 26); + namehead[7] = 'a' + (k % 26); namehead[8] = '\0'; } dp = VGetPartition(namehead, 0); @@ -1653,69 +1680,70 @@ struct partEntries *pEntries; partList.partId[j++] = i; } pEntries->partEntries_val = (afs_int32 *) malloc(j * sizeof(int)); - memcpy((char *)pEntries->partEntries_val, (char *)&partList, j * sizeof(int)); + memcpy((char *)pEntries->partEntries_val, (char *)&partList, + j * sizeof(int)); pEntries->partEntries_len = j; return 0; } /*extract the volume id from string vname. Its of the form " V0*.vol "*/ -afs_int32 ExtractVolId(vname) -char vname[]; +afs_int32 +ExtractVolId(char vname[]) { int i; - char name[VOLSER_MAXVOLNAME +1]; + char name[VOLSER_MAXVOLNAME + 1]; - strcpy(name,vname); + strcpy(name, vname); i = 0; - while(name[i] == 'V' || name[i] == '0') + while (name[i] == 'V' || name[i] == '0') i++; - - name[11] = '\0'; /* smash the "." */ - return(atol(&name[i])); + + name[11] = '\0'; /* smash the "." */ + return (atol(&name[i])); } /*return the name of the next volume header in the directory associated with dirp and dp. *the volume id is returned in volid, and volume header name is returned in volname*/ -GetNextVol(DIR *dirp, char *volname, afs_int32 *volid) -{ +int +GetNextVol(DIR * dirp, char *volname, afs_int32 * volid) +{ struct dirent *dp; - dp = readdir(dirp);/*read next entry in the directory */ - if(dp){ - - if((dp->d_name[0] == 'V') && !strcmp(&(dp->d_name[11]), VHDREXT)){ + dp = readdir(dirp); /*read next entry in the directory */ + if (dp) { + if ((dp->d_name[0] == 'V') && !strcmp(&(dp->d_name[11]), VHDREXT)) { *volid = ExtractVolId(dp->d_name); - strcpy(volname,dp->d_name); - return 0;/*return the name of the file representing a volume */ - } - else { - strcpy(volname,""); - return 0;/*volname doesnot represent a volume*/ + strcpy(volname, dp->d_name); + return 0; /*return the name of the file representing a volume */ + } else { + strcpy(volname, ""); + return 0; /*volname doesnot represent a volume */ } + } else { + strcpy(volname, "EOD"); + return 0; /*end of directory */ } - else {strcpy(volname,"EOD"); return 0;/*end of directory */} - + } /*return the header information about the */ -afs_int32 SAFSVolListOneVolume (acid, partid, volumeId, volumeInfo) -struct rx_call *acid; -afs_int32 volumeId, partid; -volEntries *volumeInfo; +afs_int32 +SAFSVolListOneVolume(struct rx_call *acid, afs_int32 partid, afs_int32 + volumeId, volEntries *volumeInfo) { - afs_int32 code; + afs_int32 code; - code = VolListOneVolume (acid, partid, volumeId, volumeInfo); - osi_auditU(acid, VS_Lst1VolEvent, code, AUD_LONG, volumeId, AUD_END); - return code; + code = VolListOneVolume(acid, partid, volumeId, volumeInfo); + osi_auditU(acid, VS_Lst1VolEvent, code, AUD_LONG, volumeId, AUD_END); + return code; } -afs_int32 VolListOneVolume (acid, partid, volumeId, volumeInfo) -struct rx_call *acid; -afs_int32 volumeId, partid; -volEntries *volumeInfo; -{ volintInfo *pntr; +afs_int32 +VolListOneVolume(struct rx_call *acid, afs_int32 partid, afs_int32 + volumeId, volEntries *volumeInfo) +{ + volintInfo *pntr; register struct Volume *tv; struct DiskPartition *partP; struct volser_trans *ttc; @@ -1726,65 +1754,70 @@ volEntries *volumeInfo; int found = 0; unsigned int now; - volumeInfo->volEntries_val = (volintInfo *) malloc( sizeof(volintInfo)); + volumeInfo->volEntries_val = (volintInfo *) malloc(sizeof(volintInfo)); pntr = volumeInfo->volEntries_val; volumeInfo->volEntries_len = 1; - if(GetPartName(partid, pname)) return VOLSERILLEGAL_PARTITION; - if (!(partP = VGetPartition(pname, 0))) return VOLSERILLEGAL_PARTITION; + if (GetPartName(partid, pname)) + return VOLSERILLEGAL_PARTITION; + if (!(partP = VGetPartition(pname, 0))) + return VOLSERILLEGAL_PARTITION; dirp = opendir(VPartitionPath(partP)); - if(dirp == NULL) return VOLSERILLEGAL_PARTITION; - strcpy(volname,""); - ttc = (struct volser_trans *) 0; - tv = (Volume *) 0; /* volume not attached */ + if (dirp == NULL) + return VOLSERILLEGAL_PARTITION; + strcpy(volname, ""); + ttc = (struct volser_trans *)0; + tv = (Volume *) 0; /* volume not attached */ - while(strcmp(volname,"EOD") && !found){/*while there are more volumes in the partition */ + while (strcmp(volname, "EOD") && !found) { /*while there are more volumes in the partition */ - if(!strcmp(volname,"")) {/* its not a volume, fetch next file */ + if (!strcmp(volname, "")) { /* its not a volume, fetch next file */ GetNextVol(dirp, volname, &volid); - continue; /*back to while loop */ + continue; /*back to while loop */ } - - if(volid == volumeId) { /*copy other things too */ + + if (volid == volumeId) { /*copy other things too */ found = 1; - IOMGR_Poll(); /*make sure that the client doesnot time out*/ - ttc = NewTrans(volid,partid); - if(!ttc){ +#ifndef AFS_PTHREAD_ENV + IOMGR_Poll(); /*make sure that the client doesnot time out */ +#endif + ttc = NewTrans(volid, partid); + if (!ttc) { pntr->status = VBUSY; pntr->volid = volid; goto drop; } - tv = VAttachVolumeByName(&error, pname, volname,V_READONLY); - if(error) { - pntr->status = 0; /*things are messed up */ - strcpy(pntr->name,volname); + tv = VAttachVolumeByName(&error, pname, volname, V_READONLY); + if (error) { + pntr->status = 0; /*things are messed up */ + strcpy(pntr->name, volname); pntr->volid = volid; - Log("1 Volser: ListVolumes: Could not attach volume %u (%s:%s), error=%d\n",volid,pname,volname,error); + Log("1 Volser: ListVolumes: Could not attach volume %u (%s:%s), error=%d\n", volid, pname, volname, error); goto drop; } - if(tv->header->diskstuff.destroyMe == DESTROY_ME) { + if (tv->header->diskstuff.destroyMe == DESTROY_ME) { /*this volume will be salvaged */ pntr->status = 0; - strcpy(pntr->name,volname); + strcpy(pntr->name, volname); pntr->volid = volid; - Log("1 Volser: ListVolumes: Volume %u (%s) will be destroyed on next salvage\n",volid,volname); + Log("1 Volser: ListVolumes: Volume %u (%s) will be destroyed on next salvage\n", volid, volname); goto drop; } - if(tv->header->diskstuff.needsSalvaged){ + if (tv->header->diskstuff.needsSalvaged) { /*this volume will be salvaged */ pntr->status = 0; - strcpy(pntr->name,volname); + strcpy(pntr->name, volname); pntr->volid = volid; - Log("1 Volser: ListVolumes: Volume %u (%s) needs to be salvaged\n",volid,volname); + Log("1 Volser: ListVolumes: Volume %u (%s) needs to be salvaged\n", volid, volname); goto drop; } /*read in the relevant info */ - pntr->status = VOK ; /*its ok */ + pntr->status = VOK; /*its ok */ pntr->volid = tv->header->diskstuff.id; - strcpy(pntr->name,tv->header->diskstuff.name); - pntr->type = tv->header->diskstuff.type; /*if ro volume*/ - pntr->cloneID = tv->header->diskstuff.cloneId; /*if rw volume*/ + strcpy(pntr->name, tv->header->diskstuff.name); + pntr->type = tv->header->diskstuff.type; /*if ro volume */ + pntr->cloneID = tv->header->diskstuff.cloneId; /*if rw volume */ pntr->backupID = tv->header->diskstuff.backupId; pntr->parentID = tv->header->diskstuff.parentId; pntr->copyDate = tv->header->diskstuff.copyDate; @@ -1796,43 +1829,50 @@ volEntries *volumeInfo; pntr->filecount = tv->header->diskstuff.filecount; now = FT_ApproxTime(); if (now - tv->header->diskstuff.dayUseDate > OneDay) - pntr->dayUse = 0; + pntr->dayUse = 0; else - pntr->dayUse = tv->header->diskstuff.dayUse; + pntr->dayUse = tv->header->diskstuff.dayUse; pntr->creationDate = tv->header->diskstuff.creationDate; pntr->accessDate = tv->header->diskstuff.accessDate; pntr->updateDate = tv->header->diskstuff.updateDate; pntr->backupDate = tv->header->diskstuff.backupDate; - pntr->spare0 = tv->header->diskstuff.minquota; - pntr->spare1 = (long) tv->header->diskstuff.weekUse[0] + (long) tv->header->diskstuff.weekUse[1] + - (long) tv->header->diskstuff.weekUse[2] + (long) tv->header->diskstuff.weekUse[3] + - (long) tv->header->diskstuff.weekUse[4] + (long) tv->header->diskstuff.weekUse[5] + - (long) tv->header->diskstuff.weekUse[6]; - pntr->flags = pntr->spare2 = pntr->spare3 = (long) 0; - VDetachVolume(&error,tv);/*free the volume */ + pntr->spare0 = tv->header->diskstuff.minquota; + pntr->spare1 = + (long)tv->header->diskstuff.weekUse[0] + + (long)tv->header->diskstuff.weekUse[1] + + (long)tv->header->diskstuff.weekUse[2] + + (long)tv->header->diskstuff.weekUse[3] + + (long)tv->header->diskstuff.weekUse[4] + + (long)tv->header->diskstuff.weekUse[5] + + (long)tv->header->diskstuff.weekUse[6]; + pntr->flags = pntr->spare2 = pntr->spare3 = (long)0; + VDetachVolume(&error, tv); /*free the volume */ tv = (Volume *) 0; - if(error) { - pntr->status = 0; /*things are messed up */ - strcpy(pntr->name,volname); - Log("1 Volser: ListVolumes: Could not detach volume %s\n",volname); + if (error) { + pntr->status = 0; /*things are messed up */ + strcpy(pntr->name, volname); + Log("1 Volser: ListVolumes: Could not detach volume %s\n", + volname); goto drop; } } GetNextVol(dirp, volname, &volid); } - drop: - if (tv) { - VDetachVolume(&error, tv); - tv = (Volume *) 0; - } - if(ttc) { - DeleteTrans(ttc); - ttc = (struct volser_trans *) 0; - } - + drop: + if (tv) { + VDetachVolume(&error, tv); + tv = (Volume *) 0; + } + if (ttc) { + DeleteTrans(ttc); + ttc = (struct volser_trans *)0; + } + closedir(dirp); - if(found)return 0 ; - else return ENODEV; + if (found) + return 0; + else + return ENODEV; } /*------------------------------------------------------------------------ @@ -1858,46 +1898,42 @@ volEntries *volumeInfo; * As advertised. *------------------------------------------------------------------------*/ -afs_int32 SAFSVolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) - struct rx_call *a_rxCidP; - afs_int32 a_partID; - afs_int32 a_volID; - volXEntries *a_volumeXInfoP; -{ - afs_int32 code; - - code = VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP); - osi_auditU(a_rxCidP, VS_XLst1VlEvent, code, AUD_LONG, a_volID, AUD_END); - return code; -} - -afs_int32 VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) - struct rx_call *a_rxCidP; - afs_int32 a_partID; - afs_int32 a_volID; - volXEntries *a_volumeXInfoP; - -{ /*SAFSVolXListOneVolume*/ - - volintXInfo *xInfoP; /*Ptr to the extended vol info*/ - register struct Volume *tv; /*Volume ptr*/ - struct volser_trans *ttc; /*Volume transaction ptr*/ - struct DiskPartition *partP; /*Ptr to partition */ - char pname[9], volname[20]; /*Partition, volume names*/ - afs_int32 error; /*Error code*/ - afs_int32 code; /*Return code*/ - DIR *dirp; /*Partition directory ptr*/ - afs_int32 currVolID; /*Current volume ID*/ - int found = 0; /*Did we find the volume we need?*/ - struct VolumeDiskData *volDiskDataP; /*Ptr to on-disk volume data*/ - int numStatBytes; /*Num stat bytes to copy per volume*/ +afs_int32 +SAFSVolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID, + afs_int32 a_volID, volXEntries *a_volumeXInfoP) +{ + afs_int32 code; + + code = VolXListOneVolume(a_rxCidP, a_partID, a_volID, a_volumeXInfoP); + osi_auditU(a_rxCidP, VS_XLst1VlEvent, code, AUD_LONG, a_volID, AUD_END); + return code; +} + +afs_int32 +VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID, + afs_int32 a_volID, volXEntries *a_volumeXInfoP) +{ /*SAFSVolXListOneVolume */ + + volintXInfo *xInfoP; /*Ptr to the extended vol info */ + register struct Volume *tv; /*Volume ptr */ + struct volser_trans *ttc; /*Volume transaction ptr */ + struct DiskPartition *partP; /*Ptr to partition */ + char pname[9], volname[20]; /*Partition, volume names */ + afs_int32 error; /*Error code */ + afs_int32 code; /*Return code */ + DIR *dirp; /*Partition directory ptr */ + afs_int32 currVolID; /*Current volume ID */ + int found = 0; /*Did we find the volume we need? */ + struct VolumeDiskData *volDiskDataP; /*Ptr to on-disk volume data */ + int numStatBytes; /*Num stat bytes to copy per volume */ unsigned int now; /* * Set up our pointers for action, marking our structure to hold exactly * one entry. Also, assume we'll fail in our quest. */ - a_volumeXInfoP->volXEntries_val = (volintXInfo *) malloc(sizeof(volintXInfo)); + a_volumeXInfoP->volXEntries_val = + (volintXInfo *) malloc(sizeof(volintXInfo)); xInfoP = a_volumeXInfoP->volXEntries_val; a_volumeXInfoP->volXEntries_len = 1; code = ENODEV; @@ -1906,38 +1942,40 @@ afs_int32 VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) * If the partition name we've been given is bad, bogue out. */ if (GetPartName(a_partID, pname)) - return(VOLSERILLEGAL_PARTITION); + return (VOLSERILLEGAL_PARTITION); /* * Open the directory representing the given AFS parttion. If we can't * do that, we lose. */ - if (!(partP = VGetPartition(pname, 0))) return VOLSERILLEGAL_PARTITION; + if (!(partP = VGetPartition(pname, 0))) + return VOLSERILLEGAL_PARTITION; dirp = opendir(VPartitionPath(partP)); if (dirp == NULL) - return(VOLSERILLEGAL_PARTITION); + return (VOLSERILLEGAL_PARTITION); /* * Sweep through the partition directory, looking for the desired entry. * First, of course, figure out how many stat bytes to copy out of each * volume. */ - numStatBytes = 4*((2*VOLINT_STATS_NUM_RWINFO_FIELDS) + - (4*VOLINT_STATS_NUM_TIME_FIELDS)); + numStatBytes = + 4 * ((2 * VOLINT_STATS_NUM_RWINFO_FIELDS) + + (4 * VOLINT_STATS_NUM_TIME_FIELDS)); strcpy(volname, ""); - ttc = (struct volser_trans *)0; /*No transaction yet*/ - tv = (Volume *)0; /*Volume not yet attached*/ + ttc = (struct volser_trans *)0; /*No transaction yet */ + tv = (Volume *) 0; /*Volume not yet attached */ - while (strcmp(volname,"EOD") && !found) { + while (strcmp(volname, "EOD") && !found) { /* * If this is not a volume, move on to the next entry in the * partition's directory. */ - if (!strcmp(volname,"")) { + if (!strcmp(volname, "")) { GetNextVol(dirp, volname, &currVolID); continue; } - + if (currVolID == a_volID) { /* * We found the volume entry we're interested. Pull out the @@ -1945,7 +1983,9 @@ afs_int32 VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) * doesn't time out) and to set up a transaction on the volume. */ found = 1; +#ifndef AFS_PTHREAD_ENV IOMGR_Poll(); +#endif ttc = NewTrans(currVolID, a_partID); if (!ttc) { /* @@ -1962,7 +2002,7 @@ afs_int32 VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) */ tv = VAttachVolumeByName(&error, pname, volname, V_READONLY); if (error) { - xInfoP->status = 0; /*things are messed up */ + xInfoP->status = 0; /*things are messed up */ strcpy(xInfoP->name, volname); xInfoP->volid = currVolID; Log("1 Volser: XListOneVolume: Could not attach volume %u\n", @@ -1987,8 +2027,7 @@ afs_int32 VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) xInfoP->status = 0; strcpy(xInfoP->name, volname); xInfoP->volid = currVolID; - Log("1 Volser: XListOneVolume: Volume %u needs to be salvaged\n", - currVolID); + Log("1 Volser: XListOneVolume: Volume %u needs to be salvaged\n", currVolID); goto drop; } @@ -1996,32 +2035,33 @@ afs_int32 VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) * Pull out the desired info and stuff it into the area we'll be * returning to our caller. */ - strcpy(xInfoP->name,volDiskDataP->name); - xInfoP->volid = volDiskDataP->id; - xInfoP->type = volDiskDataP->type; - xInfoP->backupID = volDiskDataP->backupId; - xInfoP->parentID = volDiskDataP->parentId; - xInfoP->cloneID = volDiskDataP->cloneId; - xInfoP->status = VOK; - xInfoP->copyDate = volDiskDataP->copyDate; - xInfoP->inUse = volDiskDataP->inUse; + strcpy(xInfoP->name, volDiskDataP->name); + xInfoP->volid = volDiskDataP->id; + xInfoP->type = volDiskDataP->type; + xInfoP->backupID = volDiskDataP->backupId; + xInfoP->parentID = volDiskDataP->parentId; + xInfoP->cloneID = volDiskDataP->cloneId; + xInfoP->status = VOK; + xInfoP->copyDate = volDiskDataP->copyDate; + xInfoP->inUse = volDiskDataP->inUse; xInfoP->creationDate = volDiskDataP->creationDate; - xInfoP->accessDate = volDiskDataP->accessDate; - xInfoP->updateDate = volDiskDataP->updateDate; - xInfoP->backupDate = volDiskDataP->backupDate; + xInfoP->accessDate = volDiskDataP->accessDate; + xInfoP->updateDate = volDiskDataP->updateDate; + xInfoP->backupDate = volDiskDataP->backupDate; now = FT_ApproxTime(); if (now - volDiskDataP->dayUseDate > OneDay) - xInfoP->dayUse = 0; + xInfoP->dayUse = 0; else - xInfoP->dayUse = volDiskDataP->dayUse; - xInfoP->filecount = volDiskDataP->filecount; - xInfoP->maxquota = volDiskDataP->maxquota; - xInfoP->size = volDiskDataP->diskused; + xInfoP->dayUse = volDiskDataP->dayUse; + xInfoP->filecount = volDiskDataP->filecount; + xInfoP->maxquota = volDiskDataP->maxquota; + xInfoP->size = volDiskDataP->diskused; /* * Copy out the stat fields in a single operation. */ - memcpy((char *)&(xInfoP->stat_reads[0]), (char *)&(volDiskDataP->stat_reads[0]), numStatBytes); + memcpy((char *)&(xInfoP->stat_reads[0]), + (char *)&(volDiskDataP->stat_reads[0]), numStatBytes); /* * We're done copying. Detach the volume and iterate (at this @@ -2029,7 +2069,7 @@ afs_int32 VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) * loop). */ VDetachVolume(&error, tv); - tv = (Volume *)0; + tv = (Volume *) 0; if (error) { xInfoP->status = 0; strcpy(xInfoP->name, volname); @@ -2042,113 +2082,118 @@ afs_int32 VolXListOneVolume (a_rxCidP, a_partID, a_volID, a_volumeXInfoP) * At this point, we're golden. */ code = 0; - } /*Found desired volume*/ + } /*Found desired volume */ GetNextVol(dirp, volname, &currVolID); } /* * Drop the transaction we have for this volume. */ - drop: - if (tv) { - VDetachVolume(&error, tv); - tv = (Volume *)0; - } - if (ttc) { - DeleteTrans(ttc); - ttc = (struct volser_trans *)0; - } + drop: + if (tv) { + VDetachVolume(&error, tv); + tv = (Volume *) 0; + } + if (ttc) { + DeleteTrans(ttc); + ttc = (struct volser_trans *)0; + } /* * Clean up before going to dinner: close the partition directory, * return the proper value. */ closedir(dirp); - return(code); + return (code); -} /*SAFSVolXListOneVolume*/ +} /*SAFSVolXListOneVolume */ /*returns all the volumes on partition partid. If flags = 1 then all the * relevant info about the volumes is also returned */ -afs_int32 SAFSVolListVolumes (acid, partid, flags, volumeInfo) -struct rx_call *acid; -afs_int32 flags, partid; -volEntries *volumeInfo; +afs_int32 +SAFSVolListVolumes(struct rx_call *acid, afs_int32 partid, afs_int32 flags, + volEntries *volumeInfo) { - afs_int32 code; + afs_int32 code; - code = VolListVolumes (acid, partid, flags, volumeInfo); - osi_auditU(acid, VS_ListVolEvent, code, AUD_END); - return code; + code = VolListVolumes(acid, partid, flags, volumeInfo); + osi_auditU(acid, VS_ListVolEvent, code, AUD_END); + return code; } -afs_int32 VolListVolumes (acid, partid, flags, volumeInfo) -struct rx_call *acid; -afs_int32 flags, partid; -volEntries *volumeInfo; -{ volintInfo *pntr; +afs_int32 +VolListVolumes(struct rx_call *acid, afs_int32 partid, afs_int32 flags, + volEntries *volumeInfo) +{ + volintInfo *pntr; register struct Volume *tv; struct DiskPartition *partP; struct volser_trans *ttc; - afs_int32 allocSize = 1000;/*to be changed to a larger figure */ + afs_int32 allocSize = 1000; /*to be changed to a larger figure */ char pname[9], volname[20]; afs_int32 error = 0; DIR *dirp; afs_int32 volid; unsigned int now; - volumeInfo->volEntries_val = (volintInfo *) malloc(allocSize * sizeof(volintInfo)); + volumeInfo->volEntries_val = + (volintInfo *) malloc(allocSize * sizeof(volintInfo)); pntr = volumeInfo->volEntries_val; volumeInfo->volEntries_len = 0; - if(GetPartName(partid, pname)) return VOLSERILLEGAL_PARTITION; - if (!(partP = VGetPartition(pname, 0))) return VOLSERILLEGAL_PARTITION; + if (GetPartName(partid, pname)) + return VOLSERILLEGAL_PARTITION; + if (!(partP = VGetPartition(pname, 0))) + return VOLSERILLEGAL_PARTITION; dirp = opendir(VPartitionPath(partP)); - if(dirp == NULL) return VOLSERILLEGAL_PARTITION; - strcpy(volname,""); - while(strcmp(volname,"EOD")){/*while there are more partitions in the partition */ - ttc = (struct volser_trans *) 0; /* new one for each pass */ - tv = (Volume *) 0; /* volume not attached */ + if (dirp == NULL) + return VOLSERILLEGAL_PARTITION; + strcpy(volname, ""); + while (strcmp(volname, "EOD")) { /*while there are more partitions in the partition */ + ttc = (struct volser_trans *)0; /* new one for each pass */ + tv = (Volume *) 0; /* volume not attached */ - if(!strcmp(volname,"")) {/* its not a volume, fetch next file */ + if (!strcmp(volname, "")) { /* its not a volume, fetch next file */ GetNextVol(dirp, volname, &volid); - continue; /*back to while loop */ + continue; /*back to while loop */ } - - if(flags) { /*copy other things too */ - IOMGR_Poll(); /*make sure that the client doesnot time out*/ - ttc = NewTrans(volid,partid); - if(!ttc){ + + if (flags) { /*copy other things too */ +#ifndef AFS_PTHREAD_ENV + IOMGR_Poll(); /*make sure that the client doesnot time out */ +#endif + ttc = NewTrans(volid, partid); + if (!ttc) { pntr->status = VBUSY; pntr->volid = volid; goto drop; } - tv = VAttachVolumeByName(&error, pname, volname,V_READONLY); - if(error) { - pntr->status = 0; /*things are messed up */ - strcpy(pntr->name,volname); + tv = VAttachVolumeByName(&error, pname, volname, V_READONLY); + if (error) { + pntr->status = 0; /*things are messed up */ + strcpy(pntr->name, volname); pntr->volid = volid; - Log("1 Volser: ListVolumes: Could not attach volume %u (%s) error=%d\n",volid,volname,error); + Log("1 Volser: ListVolumes: Could not attach volume %u (%s) error=%d\n", volid, volname, error); goto drop; } - if(tv->header->diskstuff.needsSalvaged){ + if (tv->header->diskstuff.needsSalvaged) { /*this volume will be salvaged */ pntr->status = 0; - strcpy(pntr->name,volname); + strcpy(pntr->name, volname); pntr->volid = volid; - Log("1 Volser: ListVolumes: Volume %u (%s) needs to be salvaged\n",volid, volname); + Log("1 Volser: ListVolumes: Volume %u (%s) needs to be salvaged\n", volid, volname); goto drop; } - if(tv->header->diskstuff.destroyMe == DESTROY_ME) { + if (tv->header->diskstuff.destroyMe == DESTROY_ME) { /*this volume will be salvaged */ goto drop2; } /*read in the relevant info */ - pntr->status = VOK ; /*its ok */ + pntr->status = VOK; /*its ok */ pntr->volid = tv->header->diskstuff.id; - strcpy(pntr->name,tv->header->diskstuff.name); - pntr->type = tv->header->diskstuff.type; /*if ro volume*/ - pntr->cloneID = tv->header->diskstuff.cloneId; /*if rw volume*/ + strcpy(pntr->name, tv->header->diskstuff.name); + pntr->type = tv->header->diskstuff.type; /*if ro volume */ + pntr->cloneID = tv->header->diskstuff.cloneId; /*if rw volume */ pntr->backupID = tv->header->diskstuff.backupId; pntr->parentID = tv->header->diskstuff.parentId; pntr->copyDate = tv->header->diskstuff.copyDate; @@ -2159,79 +2204,85 @@ volEntries *volumeInfo; pntr->filecount = tv->header->diskstuff.filecount; now = FT_ApproxTime(); if (now - tv->header->diskstuff.dayUseDate > OneDay) - pntr->dayUse = 0; + pntr->dayUse = 0; else - pntr->dayUse = tv->header->diskstuff.dayUse; + pntr->dayUse = tv->header->diskstuff.dayUse; pntr->creationDate = tv->header->diskstuff.creationDate; pntr->accessDate = tv->header->diskstuff.accessDate; pntr->updateDate = tv->header->diskstuff.updateDate; pntr->backupDate = tv->header->diskstuff.backupDate; - pntr->spare0 = tv->header->diskstuff.minquota; - pntr->spare1 = (long) tv->header->diskstuff.weekUse[0] + (long) tv->header->diskstuff.weekUse[1] + - (long) tv->header->diskstuff.weekUse[2] + (long) tv->header->diskstuff.weekUse[3] + - (long) tv->header->diskstuff.weekUse[4] + (long) tv->header->diskstuff.weekUse[5] + - (long) tv->header->diskstuff.weekUse[6]; - pntr->flags = pntr->spare2 = pntr->spare3 = (long) 0; - VDetachVolume(&error,tv);/*free the volume */ + pntr->spare0 = tv->header->diskstuff.minquota; + pntr->spare1 = + (long)tv->header->diskstuff.weekUse[0] + + (long)tv->header->diskstuff.weekUse[1] + + (long)tv->header->diskstuff.weekUse[2] + + (long)tv->header->diskstuff.weekUse[3] + + (long)tv->header->diskstuff.weekUse[4] + + (long)tv->header->diskstuff.weekUse[5] + + (long)tv->header->diskstuff.weekUse[6]; + pntr->flags = pntr->spare2 = pntr->spare3 = (long)0; + VDetachVolume(&error, tv); /*free the volume */ tv = (Volume *) 0; - if(error) { - pntr->status = 0; /*things are messed up */ - strcpy(pntr->name,volname); - Log("1 Volser: ListVolumes: Could not detach volume %s\n",volname); + if (error) { + pntr->status = 0; /*things are messed up */ + strcpy(pntr->name, volname); + Log("1 Volser: ListVolumes: Could not detach volume %s\n", + volname); goto drop; } - }else{ + } else { pntr->volid = volid; - /*just volids are needed*/ + /*just volids are needed */ } drop: - if(ttc) { + if (ttc) { DeleteTrans(ttc); - ttc = (struct volser_trans *) 0; + ttc = (struct volser_trans *)0; } - pntr++; + pntr++; volumeInfo->volEntries_len += 1; - if((allocSize - volumeInfo->volEntries_len) < 5) { + if ((allocSize - volumeInfo->volEntries_len) < 5) { /*running out of space, allocate more space */ - allocSize = (allocSize *3)/2; - pntr = (volintInfo *) realloc((char *) volumeInfo->volEntries_val, - allocSize * sizeof(volintInfo)); - if(pntr == NULL) { + allocSize = (allocSize * 3) / 2; + pntr = + (volintInfo *) realloc((char *)volumeInfo->volEntries_val, + allocSize * sizeof(volintInfo)); + if (pntr == NULL) { if (tv) { VDetachVolume(&error, tv); tv = (Volume *) 0; } - if(ttc) { + if (ttc) { DeleteTrans(ttc); - ttc = (struct volser_trans *) 0; + ttc = (struct volser_trans *)0; } closedir(dirp); return VOLSERNO_MEMORY; } - volumeInfo->volEntries_val = pntr; /* point to new block */ + volumeInfo->volEntries_val = pntr; /* point to new block */ /* set pntr to the right position */ pntr = volumeInfo->volEntries_val + volumeInfo->volEntries_len; - + } - + drop2: if (tv) { VDetachVolume(&error, tv); tv = (Volume *) 0; } - if(ttc) { + if (ttc) { DeleteTrans(ttc); - ttc = (struct volser_trans *) 0; + ttc = (struct volser_trans *)0; } - GetNextVol(dirp, volname, &volid); - + GetNextVol(dirp, volname, &volid); + } closedir(dirp); if (ttc) DeleteTrans(ttc); - - return 0 ; + + return 0; } /*------------------------------------------------------------------------ @@ -2261,38 +2312,33 @@ volEntries *volumeInfo; * As advertised. *------------------------------------------------------------------------*/ -afs_int32 SAFSVolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) - struct rx_call *a_rxCidP; - afs_int32 a_partID; - afs_int32 a_flags; - volXEntries *a_volumeXInfoP; -{ - afs_int32 code; - - code = VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP); - osi_auditU(a_rxCidP, VS_XLstVolEvent, code, AUD_END); - return code; -} - -afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) - struct rx_call *a_rxCidP; - afs_int32 a_partID; - afs_int32 a_flags; - volXEntries *a_volumeXInfoP; - -{ /*SAFSVolXListVolumes*/ - - volintXInfo *xInfoP; /*Ptr to the extended vol info*/ - register struct Volume *tv; /*Volume ptr*/ - struct DiskPartition *partP; /*Ptr to partition*/ - struct volser_trans *ttc; /*Volume transaction ptr*/ - afs_int32 allocSize = 1000; /*To be changed to a larger figure */ - char pname[9], volname[20]; /*Partition, volume names*/ - afs_int32 error = 0; /*Return code*/ - DIR *dirp; /*Partition directory ptr*/ - afs_int32 volid; /*Current volume ID*/ - struct VolumeDiskData *volDiskDataP; /*Ptr to on-disk volume data*/ - int numStatBytes; /*Num stat bytes to copy per volume*/ +afs_int32 +SAFSVolXListVolumes(struct rx_call *a_rxCidP, afs_int32 a_partID, + afs_int32 a_flags, volXEntries *a_volumeXInfoP) +{ + afs_int32 code; + + code = VolXListVolumes(a_rxCidP, a_partID, a_flags, a_volumeXInfoP); + osi_auditU(a_rxCidP, VS_XLstVolEvent, code, AUD_END); + return code; +} + +afs_int32 +VolXListVolumes(struct rx_call *a_rxCidP, afs_int32 a_partID, + afs_int32 a_flags, volXEntries *a_volumeXInfoP) +{ /*SAFSVolXListVolumes */ + + volintXInfo *xInfoP; /*Ptr to the extended vol info */ + register struct Volume *tv; /*Volume ptr */ + struct DiskPartition *partP; /*Ptr to partition */ + struct volser_trans *ttc; /*Volume transaction ptr */ + afs_int32 allocSize = 1000; /*To be changed to a larger figure */ + char pname[9], volname[20]; /*Partition, volume names */ + afs_int32 error = 0; /*Return code */ + DIR *dirp; /*Partition directory ptr */ + afs_int32 volid; /*Current volume ID */ + struct VolumeDiskData *volDiskDataP; /*Ptr to on-disk volume data */ + int numStatBytes; /*Num stat bytes to copy per volume */ unsigned int now; /* @@ -2308,13 +2354,14 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) * If the partition name we've been given is bad, bogue out. */ if (GetPartName(a_partID, pname)) - return(VOLSERILLEGAL_PARTITION); + return (VOLSERILLEGAL_PARTITION); /* * Open the directory representing the given AFS parttion. If we can't * do that, we lose. */ - if (!(partP = VGetPartition(pname, 0))) return VOLSERILLEGAL_PARTITION; + if (!(partP = VGetPartition(pname, 0))) + return VOLSERILLEGAL_PARTITION; dirp = opendir(VPartitionPath(partP)); if (dirp == NULL) return (VOLSERILLEGAL_PARTITION); @@ -2323,18 +2370,19 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) * Sweep through the partition directory, acting on each entry. First, * of course, figure out how many stat bytes to copy out of each volume. */ - numStatBytes = 4*((2*VOLINT_STATS_NUM_RWINFO_FIELDS) + - (4*VOLINT_STATS_NUM_TIME_FIELDS)); - strcpy(volname,""); + numStatBytes = + 4 * ((2 * VOLINT_STATS_NUM_RWINFO_FIELDS) + + (4 * VOLINT_STATS_NUM_TIME_FIELDS)); + strcpy(volname, ""); while (strcmp(volname, "EOD")) { - ttc = (struct volser_trans *)0; /*New one for each pass*/ - tv = (Volume *)0; /*Volume not yet attached*/ + ttc = (struct volser_trans *)0; /*New one for each pass */ + tv = (Volume *) 0; /*Volume not yet attached */ /* * If this is not a volume, move on to the next entry in the * partition's directory. */ - if(!strcmp(volname,"")) { + if (!strcmp(volname, "")) { GetNextVol(dirp, volname, &volid); continue; } @@ -2344,8 +2392,10 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) * Full info about the volume desired. Poll to make sure the * client doesn't time out, then start up a new transaction. */ +#ifndef AFS_PTHREAD_ENV IOMGR_Poll(); - ttc = NewTrans(volid,a_partID); +#endif + ttc = NewTrans(volid, a_partID); if (!ttc) { /* * Couldn't get a transaction on this volume; let our caller @@ -2361,7 +2411,7 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) */ tv = VAttachVolumeByName(&error, pname, volname, V_READONLY); if (error) { - xInfoP->status = 0; /*things are messed up */ + xInfoP->status = 0; /*things are messed up */ strcpy(xInfoP->name, volname); xInfoP->volid = volid; Log("1 Volser: XListVolumes: Could not attach volume %u\n", @@ -2378,8 +2428,7 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) xInfoP->status = 0; strcpy(xInfoP->name, volname); xInfoP->volid = volid; - Log("1 Volser: XListVolumes: Volume %u needs to be salvaged\n", - volid); + Log("1 Volser: XListVolumes: Volume %u needs to be salvaged\n", volid); goto drop; } @@ -2390,32 +2439,33 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) * Pull out the desired info and stuff it into the area we'll be * returning to our caller. */ - strcpy(xInfoP->name,volDiskDataP->name); - xInfoP->volid = volDiskDataP->id; - xInfoP->type = volDiskDataP->type; - xInfoP->backupID = volDiskDataP->backupId; - xInfoP->parentID = volDiskDataP->parentId; - xInfoP->cloneID = volDiskDataP->cloneId; - xInfoP->status = VOK; - xInfoP->copyDate = volDiskDataP->copyDate; - xInfoP->inUse = volDiskDataP->inUse; + strcpy(xInfoP->name, volDiskDataP->name); + xInfoP->volid = volDiskDataP->id; + xInfoP->type = volDiskDataP->type; + xInfoP->backupID = volDiskDataP->backupId; + xInfoP->parentID = volDiskDataP->parentId; + xInfoP->cloneID = volDiskDataP->cloneId; + xInfoP->status = VOK; + xInfoP->copyDate = volDiskDataP->copyDate; + xInfoP->inUse = volDiskDataP->inUse; xInfoP->creationDate = volDiskDataP->creationDate; - xInfoP->accessDate = volDiskDataP->accessDate; - xInfoP->updateDate = volDiskDataP->updateDate; - xInfoP->backupDate = volDiskDataP->backupDate; + xInfoP->accessDate = volDiskDataP->accessDate; + xInfoP->updateDate = volDiskDataP->updateDate; + xInfoP->backupDate = volDiskDataP->backupDate; now = FT_ApproxTime(); if (now - volDiskDataP->dayUseDate > OneDay) - xInfoP->dayUse = 0; + xInfoP->dayUse = 0; else - xInfoP->dayUse = volDiskDataP->dayUse; - xInfoP->filecount = volDiskDataP->filecount; - xInfoP->maxquota = volDiskDataP->maxquota; - xInfoP->size = volDiskDataP->diskused; + xInfoP->dayUse = volDiskDataP->dayUse; + xInfoP->filecount = volDiskDataP->filecount; + xInfoP->maxquota = volDiskDataP->maxquota; + xInfoP->size = volDiskDataP->diskused; /* * Copy out the stat fields in a single operation. */ - memcpy((char *)&(xInfoP->stat_reads[0]), (char *)&(volDiskDataP->stat_reads[0]), numStatBytes); + memcpy((char *)&(xInfoP->stat_reads[0]), + (char *)&(volDiskDataP->stat_reads[0]), numStatBytes); /* * We're done copying. Detach the volume and iterate. @@ -2429,7 +2479,7 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) volname); goto drop; } - } /*Full contents desired*/ + } /*Full contents desired */ else /* * Just volume IDs are needed. @@ -2440,24 +2490,24 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) /* * Drop the transaction we have for this volume. */ - if(ttc) { + if (ttc) { DeleteTrans(ttc); - ttc = (struct volser_trans *) 0; + ttc = (struct volser_trans *)0; } /* * Bump the pointer in the data area we're building, along with * the count of the number of entries it contains. */ - xInfoP++; + xInfoP++; (a_volumeXInfoP->volXEntries_len)++; if ((allocSize - a_volumeXInfoP->volXEntries_len) < 5) { /* * We're running out of space in the area we've built. Grow it. */ - allocSize = (allocSize * 3)/2; + allocSize = (allocSize * 3) / 2; xInfoP = (volintXInfo *) - realloc((char *) a_volumeXInfoP->volXEntries_val, + realloc((char *)a_volumeXInfoP->volXEntries_val, (allocSize * sizeof(volintXInfo))); if (xInfoP == NULL) { /* @@ -2469,10 +2519,10 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) } if (ttc) { DeleteTrans(ttc); - ttc = (struct volser_trans *) 0; + ttc = (struct volser_trans *)0; } closedir(dirp); - return(VOLSERNO_MEMORY); + return (VOLSERNO_MEMORY); } /* @@ -2481,10 +2531,11 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) * the new block. */ a_volumeXInfoP->volXEntries_val = xInfoP; - xInfoP = a_volumeXInfoP->volXEntries_val + - a_volumeXInfoP->volXEntries_len; - } /*Need more space*/ - + xInfoP = + a_volumeXInfoP->volXEntries_val + + a_volumeXInfoP->volXEntries_len; + } + /*Need more space */ drop2: /* * Detach our current volume and the transaction on it, then move on @@ -2494,12 +2545,12 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) VDetachVolume(&error, tv); tv = (Volume *) 0; } - if (ttc) { + if (ttc) { DeleteTrans(ttc); - ttc = (struct volser_trans *) 0; + ttc = (struct volser_trans *)0; } - GetNextVol(dirp, volname, &volid); - } /*Sweep through the partition directory*/ + GetNextVol(dirp, volname, &volid); + } /*Sweep through the partition directory */ /* * We've examined all entries in the partition directory. Close it, @@ -2508,37 +2559,37 @@ afs_int32 VolXListVolumes (a_rxCidP, a_partID, a_flags, a_volumeXInfoP) closedir(dirp); if (ttc) DeleteTrans(ttc); - return(0); + return (0); -} /*SAFSVolXListVolumes*/ +} /*SAFSVolXListVolumes */ /*this call is used to monitor the status of volser for debugging purposes. *information about all the active transactions is returned in transInfo*/ -afs_int32 SAFSVolMonitor (acid,transInfo) - struct rx_call *acid; - transDebugEntries *transInfo; +afs_int32 +SAFSVolMonitor(struct rx_call *acid, transDebugEntries *transInfo) { - afs_int32 code; + afs_int32 code; - code = VolMonitor (acid,transInfo); - osi_auditU(acid, VS_MonitorEvent, code, AUD_END); - return code; + code = VolMonitor(acid, transInfo); + osi_auditU(acid, VS_MonitorEvent, code, AUD_END); + return code; } -afs_int32 VolMonitor (acid,transInfo) - struct rx_call *acid; - transDebugEntries *transInfo; +afs_int32 +VolMonitor(struct rx_call *acid, transDebugEntries *transInfo) { transDebugInfo *pntr; afs_int32 allocSize = 50; struct volser_trans *tt, *allTrans; - transInfo->transDebugEntries_val = (transDebugInfo *) malloc(allocSize * sizeof(transDebugInfo)); + transInfo->transDebugEntries_val = + (transDebugInfo *) malloc(allocSize * sizeof(transDebugInfo)); pntr = transInfo->transDebugEntries_val; transInfo->transDebugEntries_len = 0; allTrans = TransList(); - if(allTrans == (struct volser_trans *)0) return 0;/*no active transactions */ - for(tt=allTrans;tt;tt=tt->next){/*copy relevant info into pntr */ + if (allTrans == (struct volser_trans *)0) + return 0; /*no active transactions */ + for (tt = allTrans; tt; tt = tt->next) { /*copy relevant info into pntr */ pntr->tid = tt->tid; pntr->time = tt->time; pntr->creationTime = tt->creationTime; @@ -2548,9 +2599,9 @@ afs_int32 VolMonitor (acid,transInfo) pntr->iflags = tt->iflags; pntr->vflags = tt->vflags; pntr->tflags = tt->tflags; - strcpy(pntr->lastProcName,tt->lastProcName); + strcpy(pntr->lastProcName, tt->lastProcName); pntr->callValid = 0; - if(tt->rxCallPtr) { /*record call related info */ + if (tt->rxCallPtr) { /*record call related info */ pntr->callValid = 1; pntr->readNext = tt->rxCallPtr->rnext; pntr->transmitNext = tt->rxCallPtr->tnext; @@ -2559,151 +2610,299 @@ afs_int32 VolMonitor (acid,transInfo) } pntr++; transInfo->transDebugEntries_len += 1; - if((allocSize - transInfo->transDebugEntries_len) < 5) {/*alloc some more space */ - allocSize = (allocSize *3)/2; - pntr = (transDebugInfo *) realloc((char *) transInfo->transDebugEntries_val,allocSize * sizeof(transDebugInfo)); + if ((allocSize - transInfo->transDebugEntries_len) < 5) { /*alloc some more space */ + allocSize = (allocSize * 3) / 2; + pntr = + (transDebugInfo *) realloc((char *)transInfo-> + transDebugEntries_val, + allocSize * + sizeof(transDebugInfo)); transInfo->transDebugEntries_val = pntr; - pntr = transInfo->transDebugEntries_val + transInfo->transDebugEntries_len; - /*set pntr to right position*/ + pntr = + transInfo->transDebugEntries_val + + transInfo->transDebugEntries_len; + /*set pntr to right position */ } - + } - + return 0; } -afs_int32 SAFSVolSetIdsTypes (acid,atid,name, type, pId, cloneId, backupId) - struct rx_call *acid; - afs_int32 type, pId, cloneId, backupId, atid; - char name[]; +afs_int32 +SAFSVolSetIdsTypes(struct rx_call *acid, afs_int32 atid, char name[], afs_int32 type, afs_int32 pId, afs_int32 cloneId, afs_int32 backupId) { - afs_int32 code; + afs_int32 code; - code = VolSetIdsTypes (acid,atid,name, type, pId, cloneId, backupId); - osi_auditU(acid, VS_SetIdTyEvent, code, AUD_LONG, atid, - AUD_STR, name, - AUD_STR, type, - AUD_LONG, pId, - AUD_LONG, cloneId, - AUD_LONG, backupId, AUD_END); - return code; + code = VolSetIdsTypes(acid, atid, name, type, pId, cloneId, backupId); + osi_auditU(acid, VS_SetIdTyEvent, code, AUD_LONG, atid, AUD_STR, name, + AUD_STR, type, AUD_LONG, pId, AUD_LONG, cloneId, AUD_LONG, + backupId, AUD_END); + return code; } -afs_int32 VolSetIdsTypes (acid,atid,name, type, pId, cloneId, backupId) - struct rx_call *acid; - afs_int32 type, pId, cloneId, backupId, atid; - char name[]; +afs_int32 +VolSetIdsTypes(struct rx_call *acid, afs_int32 atid, char name[], afs_int32 type, afs_int32 pId, afs_int32 cloneId, afs_int32 backupId) { struct Volume *tv; afs_int32 error = 0; - register struct volser_trans *tt; + register struct volser_trans *tt; char caller[MAXKTCNAMELEN]; - if (strlen(name)>31) return VOLSERBADNAME; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + if (strlen(name) > 31) + return VOLSERBADNAME; + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ /* find the trans */ tt = FindTrans(atid); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolSetIds: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolSetIds: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"SetIdsTypes"); + strcpy(tt->lastProcName, "SetIdsTypes"); tt->rxCallPtr = acid; tv = tt->volume; - + V_type(tv) = type; V_backupId(tv) = backupId; V_cloneId(tv) = cloneId; V_parentId(tv) = pId; - strcpy((&V_disk(tv))->name,name); + strcpy((&V_disk(tv))->name, name); VUpdateVolume(&error, tv); if (error) { - Log("1 Volser: SetIdsTypes: VUpdate failed code %d\n", error); - LogError(error); + Log("1 Volser: SetIdsTypes: VUpdate failed code %d\n", error); + LogError(error); goto fail; } tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt) && !error) return VOLSERTRELE_ERROR; - + if (TRELE(tt) && !error) + return VOLSERTRELE_ERROR; + return error; -fail: + fail: tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt) && !error) return VOLSERTRELE_ERROR; + if (TRELE(tt) && !error) + return VOLSERTRELE_ERROR; return error; } -afs_int32 SAFSVolSetDate (acid,atid,cdate) - struct rx_call *acid; - afs_int32 atid, cdate; +afs_int32 +SAFSVolSetDate(struct rx_call *acid, afs_int32 atid, afs_int32 cdate) { - afs_int32 code; + afs_int32 code; - code = VolSetDate (acid,atid,cdate); - osi_auditU(acid, VS_SetDateEvent, code, AUD_LONG, atid, AUD_LONG, cdate, AUD_END); - return code; + code = VolSetDate(acid, atid, cdate); + osi_auditU(acid, VS_SetDateEvent, code, AUD_LONG, atid, AUD_LONG, cdate, + AUD_END); + return code; } -afs_int32 VolSetDate (acid,atid,cdate) - struct rx_call *acid; - afs_int32 atid, cdate; +afs_int32 +VolSetDate(struct rx_call *acid, afs_int32 atid, afs_int32 cdate) { struct Volume *tv; afs_int32 error = 0; - register struct volser_trans *tt; + register struct volser_trans *tt; char caller[MAXKTCNAMELEN]; - if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;/*not a super user*/ + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ /* find the trans */ tt = FindTrans(atid); - if (!tt) return ENOENT; + if (!tt) + return ENOENT; if (tt->vflags & VTDeleted) { - Log("1 Volser: VolSetDate: volume %u has been deleted \n",tt->volid); + Log("1 Volser: VolSetDate: volume %u has been deleted \n", tt->volid); TRELE(tt); return ENOENT; } - strcpy(tt->lastProcName,"SetDate"); + strcpy(tt->lastProcName, "SetDate"); tt->rxCallPtr = acid; tv = tt->volume; - - V_creationDate(tv) = cdate; + + V_creationDate(tv) = cdate; VUpdateVolume(&error, tv); if (error) { - Log("1 Volser: SetDate: VUpdate failed code %d\n", error); - LogError(error); + Log("1 Volser: SetDate: VUpdate failed code %d\n", error); + LogError(error); goto fail; } tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt) && !error) return VOLSERTRELE_ERROR; - + if (TRELE(tt) && !error) + return VOLSERTRELE_ERROR; + return error; -fail: + fail: tt->rxCallPtr = (struct rx_call *)0; - if(TRELE(tt) && !error) return VOLSERTRELE_ERROR; + if (TRELE(tt) && !error) + return VOLSERTRELE_ERROR; return error; } +#ifdef AFS_NAMEI_ENV +/* + * Inode number format (from namei_ops.c): + * low 26 bits - vnode number - all 1's if volume special file. + * next 3 bits - tag + * next 3 bits spare (0's) + * high 32 bits - uniquifier (regular) or type if spare + */ +#define NAMEI_VNODEMASK 0x003ffffff +#define NAMEI_TAGMASK 0x7 +#define NAMEI_TAGSHIFT 26 +#define NAMEI_UNIQMASK 0xffffffff +#define NAMEI_UNIQSHIFT 32 +#define NAMEI_INODESPECIAL ((Inode)NAMEI_VNODEMASK) +#define NAMEI_VNODESPECIAL NAMEI_VNODEMASK +#endif /* AFS_NAMEI_ENV */ + +afs_int32 +SAFSVolConvertROtoRWvolume(struct rx_call *acid, afs_int32 partId, + afs_int32 volumeId) +{ +#if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV) + DIR *dirp; + char pname[16]; + char volname[20]; + afs_int32 error = 0; + afs_int32 volid; + int found = 0; + char caller[MAXKTCNAMELEN]; + char headername[16]; + char opath[256]; + char npath[256]; + struct VolumeDiskHeader h; + int fd; + IHandle_t *ih; + Inode ino; + struct DiskPartition *dp; + + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ + if (GetPartName(partId, pname)) + return VOLSERILLEGAL_PARTITION; + dirp = opendir(pname); + if (dirp == NULL) + return VOLSERILLEGAL_PARTITION; + strcpy(volname, ""); + + while (strcmp(volname, "EOD") && !found) { /*while there are more volumes in the partition */ + GetNextVol(dirp, volname, &volid); + if (strcmp(volname, "")) { /* its a volume */ + if (volid == volumeId) + found = 1; + } + } + if (!found) + return ENOENT; + (void)afs_snprintf(headername, sizeof headername, VFORMAT, volumeId); + (void)afs_snprintf(opath, sizeof opath, "%s/%s", pname, headername); + fd = open(opath, O_RDONLY); + if (fd < 0) { + Log("1 SAFS_VolConvertROtoRWvolume: Couldn't open header for RO-volume %lu.\n", volumeId); + return ENOENT; + } + if (read(fd, &h, sizeof(h)) != sizeof(h)) { + Log("1 SAFS_VolConvertROtoRWvolume: Couldn't read header for RO-volume %lu.\n", volumeId); + close(fd); + return EIO; + } + close(fd); + FSYNC_askfs(volumeId, pname, FSYNC_RESTOREVOLUME, 0); + + for (dp = DiskPartitionList; dp && strcmp(dp->name, pname); + dp = dp->next); + if (!dp) { + Log("1 SAFS_VolConvertROtoRWvolume: Couldn't find DiskPartition for %s\n", pname); + return EIO; + } + ino = namei_MakeSpecIno(h.parent, VI_LINKTABLE); + IH_INIT(ih, dp->device, h.parent, ino); + + error = namei_ConvertROtoRWvolume(ih, volumeId); + if (error) + return error; + h.id = h.parent; + h.volumeInfo_hi = h.id; + h.smallVnodeIndex_hi = h.id; + h.largeVnodeIndex_hi = h.id; + h.linkTable_hi = h.id; + (void)afs_snprintf(headername, sizeof headername, VFORMAT, h.id); + (void)afs_snprintf(npath, sizeof npath, "%s/%s", pname, headername); + fd = open(npath, O_CREAT | O_EXCL | O_RDWR, 0644); + if (fd < 0) { + Log("1 SAFS_VolConvertROtoRWvolume: Couldn't create header for RW-volume %lu.\n", h.id); + return EIO; + } + if (write(fd, &h, sizeof(h)) != sizeof(h)) { + Log("1 SAFS_VolConvertROtoRWvolume: Couldn't write header for RW-volume %lu.\n", h.id); + close(fd); + return EIO; + } + close(fd); + if (unlink(opath) < 0) { + Log("1 SAFS_VolConvertROtoRWvolume: Couldn't unlink RO header, error = %d\n", error); + } + FSYNC_askfs(volumeId, pname, FSYNC_DONE, 0); + FSYNC_askfs(h.id, pname, FSYNC_ON, 0); + return 0; +#else /* AFS_NAMEI_ENV */ + return EINVAL; +#endif /* AFS_NAMEI_ENV */ +} + +afs_int32 +SAFSVolGetSize(struct rx_call *acid, afs_int32 fromTrans, afs_int32 fromDate, + register struct volintSize *size) +{ + int code = 0; + register struct volser_trans *tt; + char caller[MAXKTCNAMELEN]; + + if (!afsconf_SuperUser(tdir, acid, caller)) + return VOLSERBAD_ACCESS; /*not a super user */ + tt = FindTrans(fromTrans); + if (!tt) + return ENOENT; + if (tt->vflags & VTDeleted) { + TRELE(tt); + return ENOENT; + } + strcpy(tt->lastProcName, "GetSize"); + tt->rxCallPtr = acid; + code = SizeDumpVolume(acid, tt->volume, fromDate, 1, size); /* measure volume's data */ + tt->rxCallPtr = (struct rx_call *)0; + if (TRELE(tt)) + return VOLSERTRELE_ERROR; + +/* osi_auditU(acid, VS_DumpEvent, code, AUD_LONG, fromTrans, AUD_END); */ + return code; +} + /* GetPartName - map partid (a decimal number) into pname (a string) * Since for NT we actually want to return the drive name, we map through the * partition struct. */ -static int GetPartName(afs_int32 partid, char *pname) -{ +static int +GetPartName(afs_int32 partid, char *pname) +{ if (partid < 0) return -1; - if(partid < 26) { - strcpy(pname,"/vicep"); + if (partid < 26) { + strcpy(pname, "/vicep"); pname[6] = 'a' + partid; pname[7] = '\0'; return 0; } else if (partid < VOLMAXPARTS) { - strcpy(pname,"/vicep"); + strcpy(pname, "/vicep"); partid -= 26; pname[6] = 'a' + (partid / 26); pname[7] = 'a' + (partid % 26); pname[8] = '\0'; return 0; - } - else return -1; + } else + return -1; } diff --git a/src/volser/volser.p.h b/src/volser/volser.p.h index 74f580dec..091b523b8 100644 --- a/src/volser/volser.p.h +++ b/src/volser/volser.p.h @@ -9,6 +9,12 @@ #ifndef _VOLSER_ #define _VOLSER_ 1 + +#ifdef AFS_PTHREAD_ENV +#include +#include +#endif + /* vflags, representing state of the volume */ #define VTDeleteOnSalvage 1 /* delete on next salvage */ #define VTOutOfService 2 /* never put this volume online */ @@ -17,7 +23,7 @@ /* iflags, representing "attach mode" for this volume at the start of this transaction */ #define ITOffline 1 /* volume offline on server (returns VOFFLINE) */ #define ITBusy 2 /* volume busy on server (returns VBUSY) */ -#define ITReadOnly 8 /* volume readonly on client, readwrite on server -DO NOT USE*/ +#define ITReadOnly 8 /* volume readonly on client, readwrite on server -DO NOT USE */ #define ITCreate 0x10 /* volume does not exist correctly yet */ #define ITCreateVolID 0x1000 /* create volid */ @@ -32,25 +38,25 @@ #define THOLD(tt) ((tt)->refCount++) struct volser_trans { - struct volser_trans *next; /* next ptr in active trans list */ - afs_int32 tid; /* transaction id */ - afs_int32 time; /* time transaction was last active (for timeouts) */ - afs_int32 creationTime; /* time the transaction started */ - afs_int32 returnCode; /* transaction error code */ - struct Volume *volume; /* pointer to open volume */ - afs_int32 volid; /* open volume's id */ - afs_int32 partition; /* open volume's partition */ - afs_int32 dumpTransId; /* other side's trans id during a dump */ - afs_int32 dumpSeq; /* next sequence number to use during a dump */ - short refCount; /* reference count on this structure */ - short iflags; /* initial attach mode flags (IT*) */ - char vflags; /* current volume status flags (VT*) */ - char tflags; /* transaction flags (TT*) */ - char incremental; /* do an incremental restore */ + struct volser_trans *next; /* next ptr in active trans list */ + afs_int32 tid; /* transaction id */ + afs_int32 time; /* time transaction was last active (for timeouts) */ + afs_int32 creationTime; /* time the transaction started */ + afs_int32 returnCode; /* transaction error code */ + struct Volume *volume; /* pointer to open volume */ + afs_int32 volid; /* open volume's id */ + afs_int32 partition; /* open volume's partition */ + afs_int32 dumpTransId; /* other side's trans id during a dump */ + afs_int32 dumpSeq; /* next sequence number to use during a dump */ + short refCount; /* reference count on this structure */ + short iflags; /* initial attach mode flags (IT*) */ + char vflags; /* current volume status flags (VT*) */ + char tflags; /* transaction flags (TT*) */ + char incremental; /* do an incremental restore */ /* the fields below are useful for debugging */ - char lastProcName[30]; /* name of the last procedure which used transaction */ - struct rx_call *rxCallPtr; /* pointer to latest associated rx_call */ - + char lastProcName[30]; /* name of the last procedure which used transaction */ + struct rx_call *rxCallPtr; /* pointer to latest associated rx_call */ + }; /* This is how often the garbage collection thread wakes up and @@ -70,8 +76,8 @@ struct volser_dest { * trans is queued. Finally, VHRequest goes off (but VHIdle stays off) when * helper is done. VHIdle goes on again when an lwp waits for work. */ -#define VHIdle 1 /* vol helper is waiting for a request here */ -#define VHRequest 2 /* a request has been queued here */ +#define VHIdle 1 /* vol helper is waiting for a request here */ +#define VHRequest 2 /* a request has been queued here */ extern struct volser_trans *QI_GlobalWriteTrans; /* the stuff below is from errors.h in vol directory */ @@ -80,22 +86,22 @@ extern struct volser_trans *QI_GlobalWriteTrans; #define VSALVAGE 101 /* Volume needs salvage */ #define VNOVNODE 102 /* Bad vnode number quoted */ #define VNOVOL 103 /* Volume not attached, doesn't exist, - not created or not online */ + * not created or not online */ #define VVOLEXISTS 104 /* Volume already exists */ #define VNOSERVICE 105 /* Volume is not in service (i.e. it's - is out of funds, is obsolete, or somesuch) */ + * is out of funds, is obsolete, or somesuch) */ #define VOFFLINE 106 /* Volume is off line, for the reason - given in the offline message */ + * given in the offline message */ #define VONLINE 107 /* Volume is already on line */ #define VDISKFULL 108 /* Partition is "full", i.e. rougly within - n% of full */ + * n% of full */ #define VOVERQUOTA 109 /* Volume max quota exceeded */ #define VBUSY 110 /* Volume temporarily unavailable; try again. - The volume should be available again shortly; if - it isn't something is wrong. Not normally to be - propagated to the application level */ + * The volume should be available again shortly; if + * it isn't something is wrong. Not normally to be + * propagated to the application level */ #define VMOVED 111 /* Volume has moved to another server; do a VGetVolumeInfo - to THIS server to find out where */ + * to THIS server to find out where */ #define MyPort 5003 #define NameLen 80 @@ -107,15 +113,15 @@ extern struct volser_trans *QI_GlobalWriteTrans; #define VOLMAXPARTS 255 /*flags used for interfacing with the backup system */ -struct volDescription { /*used for interfacing with the backup system */ - char volName[VOLSER_MAXVOLNAME];/* should be VNAMESIZE as defined in volume.h*/ +struct volDescription { /*used for interfacing with the backup system */ + char volName[VOLSER_MAXVOLNAME]; /* should be VNAMESIZE as defined in volume.h */ afs_int32 volId; int volSize; afs_int32 volFlags; afs_int32 volCloneId; }; -struct partList { /*used by the backup system */ +struct partList { /*used by the backup system */ afs_int32 partId[VOLMAXPARTS]; afs_int32 partFlags[VOLMAXPARTS]; }; @@ -137,8 +143,8 @@ struct partList { /*used by the backup system */ #define ITSBACKVOL 0x08 #define RO_DONTUSE 0x20 -#define VLOP_RESTORE 0x100/*this is bogus, clashes with VLOP_DUMP */ -#define VLOP_ADDSITE 0x80 /*this is bogus, clashes with VLOP_DELETE*/ +#define VLOP_RESTORE 0x100 /*this is bogus, clashes with VLOP_DUMP */ +#define VLOP_ADDSITE 0x80 /*this is bogus, clashes with VLOP_DELETE */ #define PARTVALID 0x01 #define CLONEVALID 0x02 #define CLONEZAPPED 0x04 @@ -147,18 +153,20 @@ struct partList { /*used by the backup system */ #define SIZEVALID 0x20 #define ENTRYVALID 0x40 #define REUSECLONEID 0x80 -#define VOK 0x02 +#define VOK 0x02 /* Values for the UV_RestoreVolume flags parameter */ +/* Also used for UV_CopyVolume and UV_CloneVolume */ #define RV_FULLRST 0x1 #define RV_OFFLINE 0x2 #define RV_RDONLY 0x10000 +#define RV_CPINCR 0x20000 +#define RV_NOVLDB 0x40000 +#define RV_NOCLONE 0x80000 -#endif /* _VOLSER_ */ - - - - - - +extern afs_uint32 vsu_GetVolumeID(char *astring, struct ubik_client *acstruct, afs_int32 *errp); +extern int vsu_ExtractName(char rname[], char name[]); +extern afs_int32 vsu_ClientInit(int noAuthFlag, char *confDir, char *cellName, afs_int32 sauth, struct ubik_client **uclientp, int (*secproc)()); +extern void vsu_SetCrypt(int cryptflag); +#endif /* _VOLSER_ */ diff --git a/src/volser/voltrans.c b/src/volser/voltrans.c index fbfd72f03..4c28fbec0 100644 --- a/src/volser/voltrans.c +++ b/src/volser/voltrans.c @@ -17,67 +17,127 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/voltrans.c,v 1.1.1.5 2001/09/11 14:35:56 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/voltrans.c,v 1.10 2003/11/22 02:57:04 shadow Exp $"); #ifdef AFS_NT40_ENV #include #else #include #endif + +#include +#include +#include +#ifdef AFS_NT40_ENV +#include +#include +#else +#include +#include +#include +#endif +#include +#include +#include +#include +#ifdef AFS_PTHREAD_ENV +#include +#else /* AFS_PTHREAD_ENV */ +#include +#endif /* AFS_PTHREAD_ENV */ +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#ifdef AFS_NT40_ENV +#include +#endif +#include +#include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include "volser.h" -static struct volser_trans *allTrans=0; +/*@printflike@*/ extern void Log(const char *format, ...); + +static struct volser_trans *allTrans = 0; static afs_int32 transCounter = 1; /* create a new transaction, returning ptr to same with high ref count */ -struct volser_trans *NewTrans(avol, apart) -afs_int32 avol; -afs_int32 apart; { +struct volser_trans * +NewTrans(avol, apart) + afs_int32 avol; + afs_int32 apart; +{ /* set volid, next, partition */ register struct volser_trans *tt; struct timeval tp; struct timezone tzp; + VTRANS_LOCK; /* don't allow the same volume to be attached twice */ - for(tt=allTrans;tt;tt=tt->next) { - if ((tt->volid == avol) && (tt->partition == apart)){ - return (struct volser_trans *) 0; /* volume busy */ + for (tt = allTrans; tt; tt = tt->next) { + if ((tt->volid == avol) && (tt->partition == apart)) { + VTRANS_UNLOCK; + return (struct volser_trans *)0; /* volume busy */ } } - tt = (struct volser_trans *) malloc(sizeof(struct volser_trans)); + VTRANS_UNLOCK; + tt = (struct volser_trans *)malloc(sizeof(struct volser_trans)); memset(tt, 0, sizeof(struct volser_trans)); tt->volid = avol; tt->partition = apart; - tt->next = allTrans; - tt->tid = transCounter++; tt->refCount = 1; tt->rxCallPtr = (struct rx_call *)0; - strcpy(tt->lastProcName,""); - gettimeofday(&tp,&tzp); + strcpy(tt->lastProcName, ""); + gettimeofday(&tp, &tzp); tt->creationTime = tp.tv_sec; - allTrans = tt; tt->time = FT_ApproxTime(); + VTRANS_LOCK; + tt->tid = transCounter++; + tt->next = allTrans; + allTrans = tt; + VTRANS_UNLOCK; return tt; } /* find a trans, again returning with high ref count */ -struct volser_trans *FindTrans(atrans) -register afs_int32 atrans; { +struct volser_trans * +FindTrans(atrans) + register afs_int32 atrans; +{ register struct volser_trans *tt; - for(tt=allTrans;tt;tt=tt->next) { + VTRANS_LOCK; + for (tt = allTrans; tt; tt = tt->next) { if (tt->tid == atrans) { tt->time = FT_ApproxTime(); tt->refCount++; + VTRANS_UNLOCK; return tt; } } - return (struct volser_trans *) 0; + VTRANS_UNLOCK; + return (struct volser_trans *)0; } /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */ DeleteTrans(atrans) -register struct volser_trans *atrans; { + register struct volser_trans *atrans; +{ register struct volser_trans *tt, **lt; afs_int32 error; @@ -87,31 +147,36 @@ register struct volser_trans *atrans; { atrans->tflags |= TTDeleted; return 0; } + /* otherwise we zap it ourselves */ + VTRANS_LOCK; lt = &allTrans; - for(tt = *lt; tt; lt = &tt->next, tt = *lt) { + for (tt = *lt; tt; lt = &tt->next, tt = *lt) { if (tt == atrans) { if (tt->volume) VDetachVolume(&error, tt->volume); - tt->volume = (struct Volume *) 0; + tt->volume = NULL; *lt = tt->next; free(tt); + VTRANS_UNLOCK; return 0; } } - return -1; /* failed to find the transaction in the generic list */ + VTRANS_UNLOCK; + return -1; /* failed to find the transaction in the generic list */ } /* THOLD is a macro defined in volser.h */ /* put a transaction back */ -TRELE (at) -register struct volser_trans *at; { - if (at->refCount == 0){ +TRELE(at) + register struct volser_trans *at; +{ + if (at->refCount == 0) { Log("TRELE: bad refcount\n"); return VOLSERTRELE_ERROR; } - + at->time = FT_ApproxTime(); /* we're still using it */ if (at->refCount == 1 && (at->tflags & TTDeleted)) { DeleteTrans(at); @@ -123,25 +188,27 @@ register struct volser_trans *at; { } /* look for old transactions and delete them */ -#define OLDTRANSTIME 600 /* seconds */ -#define OLDTRANSWARN 300 /* seconds */ +#define OLDTRANSTIME 600 /* seconds */ +#define OLDTRANSWARN 300 /* seconds */ static int GCDeletes = 0; -GCTrans() +GCTrans() { register struct volser_trans *tt, *nt; afs_int32 now; - + now = FT_ApproxTime(); - for(tt = allTrans; tt; tt=nt) { + VTRANS_LOCK; + for (tt = allTrans; tt; tt = nt) { nt = tt->next; /* remember in case we zap it */ if (tt->time + OLDTRANSWARN < now) { - Log("trans %u on volume %u %s than %d seconds\n", - tt->tid, tt->volid, - ((tt->refCount>0)?"is older":"has been idle for more"), - (((now-tt->time)/GCWAKEUP)*GCWAKEUP)); + Log("trans %u on volume %u %s than %d seconds\n", tt->tid, + tt->volid, + ((tt->refCount > 0) ? "is older" : "has been idle for more"), + (((now - tt->time) / GCWAKEUP) * GCWAKEUP)); } - if (tt->refCount > 0) continue; + if (tt->refCount > 0) + continue; if (tt->time + OLDTRANSTIME < now) { Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid); tt->refCount++; /* we're using it now */ @@ -149,10 +216,13 @@ GCTrans() GCDeletes++; } } + VTRANS_UNLOCK; return 0; } + /*return the head of the transaction list */ -struct volser_trans *TransList() +struct volser_trans * +TransList() { - return(allTrans); + return (allTrans); } diff --git a/src/volser/vos.c b/src/volser/vos.c index e25567c64..23689f03c 100644 --- a/src/volser/vos.c +++ b/src/volser/vos.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vos.c,v 1.2 2002/10/20 19:01:31 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/vos.c,v 1.38 2004/04/08 22:20:39 jaltman Exp $"); #include #ifdef AFS_NT40_ENV @@ -22,12 +23,22 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vos.c,v 1.2 2002/10/20 19:01:31 #include #include #include +#include #endif #include #ifdef AFS_AIX_ENV #include #endif #include + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include @@ -50,6 +61,11 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vos.c,v 1.2 2002/10/20 19:01:31 #ifdef AFS_AIX32_ENV #include #endif +#include "volser_prototypes.h" + +#ifdef HAVE_POSIX_REGEX +#include +#endif struct tqElem { afs_int32 volid; @@ -61,9 +77,6 @@ struct tqHead { struct tqElem *next; }; - -struct hostent *hostutil_GetHostByName(register char *ahost); - #define COMMONPARMS cmd_Seek(ts, 12);\ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\ @@ -79,41 +92,19 @@ struct rx_connection *tconn; afs_int32 tserver; extern struct ubik_client *cstruct; const char *confdir; -extern struct rx_connection *UV_Bind(); -extern struct rx_securityClass *rxnull_NewClientSecurityObject(); -extern int UV_SetSecurity(); -extern int UV_SetVolumeInfo(); -extern int vsu_SetCrypt(); -extern VL_SetLock(); -extern VL_ReleaseLock(); -extern VL_DeleteEntry(); -extern VL_ListEntry(); -extern VL_GetAddrs(); -extern VL_GetAddrsU(); -extern VL_ChangeAddr(); - -extern int vsu_ExtractName(); -extern PrintError(); -extern int MapPartIdIntoName(); -extern int MapHostToNetwork(); -extern int MapNetworkToHost(); -extern void EnumerateEntry(); -extern void SubEnumerateEntry(); - static struct tqHead busyHead, notokHead; -static void qInit(ahead) -struct tqHead *ahead; +static void +qInit(struct tqHead *ahead) { memset((char *)ahead, 0, sizeof(struct tqHead)); return; } -static void qPut(ahead,volid) -struct tqHead *ahead; -afs_int32 volid; +static void +qPut(struct tqHead *ahead, afs_int32 volid) { struct tqElem *elem; @@ -125,13 +116,13 @@ afs_int32 volid; return; } -static void qGet(ahead,volid) -struct tqHead *ahead; -afs_int32 *volid; +static void +qGet(struct tqHead *ahead, afs_int32 *volid) { struct tqElem *tmp; - if(ahead->count <= 0) return; + if (ahead->count <= 0) + return; *volid = ahead->next->volid; tmp = ahead->next; ahead->next = tmp->next; @@ -141,8 +132,8 @@ afs_int32 *volid; } /* returns 1 if exists else 0 */ -static FileExists(filename) -char *filename; +static int +FileExists(char *filename) { usd_handle_t ufd; int code; @@ -161,53 +152,50 @@ char *filename; } /* returns 1 if doesnot end in .readonly or .backup, else 0 */ -static VolNameOK(name) -char *name; -{ +static int +VolNameOK(char *name) +{ int total; - + total = strlen(name); - if(!strcmp(&name[total - 9],".readonly")) { + if (!strcmp(&name[total - 9], ".readonly")) { return 0; - } - else if(!strcmp(&name[total - 7 ],".backup")) { + } else if (!strcmp(&name[total - 7], ".backup")) { return 0; - } - else { + } else { return 1; } } /* return 1 if name is a number else 0 */ -static IsNumeric(name) -char *name; +static int +IsNumeric(char *name) { - int result, len,i; + int result, len, i; char *ptr; result = 1; ptr = name; len = strlen(name); - for(i = 0; i < len ; i++){ - if(*ptr < '0' || *ptr > '9'){ + for (i = 0; i < len; i++) { + if (*ptr < '0' || *ptr > '9') { result = 0; break; } ptr++; - + } return result; - - } /* * Parse a server name/address and return the address in HOST BYTE order */ -afs_int32 GetServer(aname) -char *aname; { +afs_int32 +GetServer(char *aname) +{ register struct hostent *th; afs_int32 addr; int b1, b2, b3, b4; @@ -216,55 +204,57 @@ char *aname; { code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4); if (code == 4) { - addr = (b1<<24) | (b2<<16) | (b3<<8) | b4; - addr = ntohl(addr); /* convert to host order */ + addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; + addr = ntohl(addr); /* convert to host order */ } else { - th = gethostbyname(aname); - if (!th) return 0; + th = gethostbyname(aname); + if (!th) + return 0; memcpy(&addr, th->h_addr, sizeof(addr)); } - if (addr == htonl(0x7f000001)) { /* local host */ - code = gethostname(hostname, MAXHOSTCHARS); - if (code) return 0; - th = gethostbyname(hostname); /* returns host byte order */ - if (!th) return 0; - memcpy(&addr, th->h_addr, sizeof(addr)); + if (addr == htonl(0x7f000001)) { /* local host */ + code = gethostname(hostname, MAXHOSTCHARS); + if (code) + return 0; + th = gethostbyname(hostname); /* returns host byte order */ + if (!th) + return 0; + memcpy(&addr, th->h_addr, sizeof(addr)); } - return (addr); + return (addr); } -afs_int32 GetVolumeType(aname) -char *aname; +afs_int32 +GetVolumeType(char *aname) { - if(!strcmp(aname,"ro")) - return(ROVOL); - else if(!strcmp(aname, "rw")) - return(RWVOL); - else if(!strcmp(aname,"bk")) - return(BACKVOL); - else return(-1); + if (!strcmp(aname, "ro")) + return (ROVOL); + else if (!strcmp(aname, "rw")) + return (RWVOL); + else if (!strcmp(aname, "bk")) + return (BACKVOL); + else + return (-1); } -int IsPartValid(partId, server, code) -afs_int32 server, partId,*code; - -{ +int +IsPartValid(afs_int32 partId, afs_int32 server, afs_int32 *code) +{ struct partList dummyPartList; - int i,success, cnt; - + int i, success, cnt; - success = 0; *code = 0; - *code = UV_ListPartitions(server,&dummyPartList, &cnt); - if(*code) return success; - for(i = 0 ; i < cnt ; i++) { - if(dummyPartList.partFlags[i] & PARTVALID) - if(dummyPartList.partId[i] == partId) + *code = UV_ListPartitions(server, &dummyPartList, &cnt); + if (*code) + return success; + for (i = 0; i < cnt; i++) { + if (dummyPartList.partFlags[i] & PARTVALID) + if (dummyPartList.partId[i] == partId) success = 1; } return success; @@ -273,92 +263,91 @@ afs_int32 server, partId,*code; /*sends the contents of file associated with and to Rx Stream -* associated with */ -SendFile(ufd, call, blksize) -usd_handle_t ufd; -register struct rx_call *call; -long blksize; + * associated with */ +int +SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize) { - char *buffer = (char*) 0; + char *buffer = (char *)0; afs_int32 error = 0; int done = 0; afs_uint32 nbytes; buffer = (char *)malloc(blksize); if (!buffer) { - fprintf(STDERR,"malloc failed\n"); + fprintf(STDERR, "malloc failed\n"); return -1; } while (!error && !done) { -#ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */ +#ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */ fd_set in; - FD_ZERO(&in); - FD_SET((int)(ufd->handle), &in); + FD_ZERO(&in); + FD_SET((int)(ufd->handle), &in); /* don't timeout if read blocks */ - IOMGR_Select(((int)(ufd->handle))+1, &in, 0, 0, 0); + IOMGR_Select(((int)(ufd->handle)) + 1, &in, 0, 0, 0); #endif - error = USD_READ(ufd, buffer, blksize, &nbytes); + error = USD_READ(ufd, buffer, blksize, &nbytes); if (error) { fprintf(STDERR, "File system read failed\n"); break; } - if(nbytes == 0){ + if (nbytes == 0) { done = 1; break; } - if (rx_Write(call, buffer, nbytes) != nbytes){ + if (rx_Write(call, buffer, nbytes) != nbytes) { error = -1; break; } } - if (buffer) free(buffer); + if (buffer) + free(buffer); return error; } /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and * writes it out to the volume. */ -afs_int32 WriteData(call,rock) -struct rx_call *call; -char *rock; +afs_int32 +WriteData(struct rx_call *call, char *rock) { char *filename; usd_handle_t ufd; long blksize; - afs_int32 error,code; + afs_int32 error, code; int ufdIsOpen = 0; error = 0; filename = rock; - if(!filename || !*filename) { + if (!filename || !*filename) { usd_StandardInput(&ufd); blksize = 4096; ufdIsOpen = 1; } else { - code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd); - if (code == 0) { + code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd); + if (code == 0) { ufdIsOpen = 1; code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize); - } - if (code){ - fprintf(STDERR,"Could not access file '%s'\n", filename); + } + if (code) { + fprintf(STDERR, "Could not access file '%s'\n", filename); error = VOLSERBADOP; goto wfail; - } + } } - code = SendFile(ufd,call,blksize); - if(code) { + code = SendFile(ufd, call, blksize); + if (code) { error = code; goto wfail; } wfail: - if(ufdIsOpen) { + if (ufdIsOpen) { code = USD_CLOSE(ufd); - if(code){ - fprintf(STDERR,"Could not close dump file %s\n", - (filename && *filename)?filename:"STDOUT"); - if(!error) error = code; + if (code) { + fprintf(STDERR, "Could not close dump file %s\n", + (filename && *filename) ? filename : "STDOUT"); + if (!error) + error = code; } } return error; @@ -367,50 +356,49 @@ char *rock; /* Receive data from stream into file associated * with */ -int ReceiveFile(ufd, call, blksize) - usd_handle_t ufd; - struct rx_call *call; - long blksize; +int +ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize) { - char *buffer = (char *) 0; - afs_int32 bytesread; - afs_uint32 bytesleft, w; + char *buffer = NULL; + afs_int32 bytesread; + afs_uint32 bytesleft, w; afs_int32 error = 0; buffer = (char *)malloc(blksize); if (!buffer) { - fprintf(STDERR,"memory allocation failed\n"); - ERROR_EXIT(-1); - } - - while ((bytesread=rx_Read(call,buffer,blksize)) > 0) { - for (bytesleft=bytesread; bytesleft; bytesleft-=w) { -#ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */ - fd_set out; - FD_ZERO(&out); - FD_SET((int)(ufd->handle), &out); - /* don't timeout if write blocks */ - IOMGR_Select(((int)(ufd->handle))+1, 0, &out, 0, 0); + fprintf(STDERR, "memory allocation failed\n"); + ERROR_EXIT(-1); + } + + while ((bytesread = rx_Read(call, buffer, blksize)) > 0) { + for (bytesleft = bytesread; bytesleft; bytesleft -= w) { +#ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */ + fd_set out; + FD_ZERO(&out); + FD_SET((int)(ufd->handle), &out); + /* don't timeout if write blocks */ + IOMGR_Select(((int)(ufd->handle)) + 1, 0, &out, 0, 0); #endif - error = USD_WRITE(ufd, &buffer[bytesread-bytesleft], bytesleft, &w); - if (error) { - fprintf(STDERR,"File system write failed\n"); - ERROR_EXIT(-1); - } - } + error = + USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w); + if (error) { + fprintf(STDERR, "File system write failed\n"); + ERROR_EXIT(-1); + } + } } error_exit: - if (buffer) free(buffer); - return(error); + if (buffer) + free(buffer); + return (error); } -afs_int32 DumpFunction(call, filename) - struct rx_call *call; - char *filename; +afs_int32 +DumpFunction(struct rx_call *call, char *filename) { - usd_handle_t ufd; /* default is to stdout */ - afs_int32 error=0, code; + usd_handle_t ufd; /* default is to stdout */ + afs_int32 error = 0, code; afs_hyper_t size; long blksize; int ufdIsOpen = 0; @@ -421,120 +409,152 @@ afs_int32 DumpFunction(call, filename) blksize = 4096; ufdIsOpen = 1; } else { - code = usd_Open(filename, USD_OPEN_CREATE|USD_OPEN_RDWR, 0666, &ufd); + code = + usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd); if (code == 0) { ufdIsOpen = 1; hzero(size); code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size); - } - if (code == 0) { + } + if (code == 0) { code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize); - } - if (code){ + } + if (code) { fprintf(STDERR, "Could not create file '%s'\n", filename); ERROR_EXIT(VOLSERBADOP); - } + } } code = ReceiveFile(ufd, call, blksize); - if (code) ERROR_EXIT(code); + if (code) + ERROR_EXIT(code); error_exit: /* Close the output file */ if (ufdIsOpen) { - code = USD_CLOSE(ufd); - if (code) { - fprintf(STDERR,"Could not close dump file %s\n", - (filename && *filename)?filename:"STDIN"); - if (!error) error = code; - } - } - - return(error); -} - -static void DisplayFormat(pntr,server,part,totalOK,totalNotOK,totalBusy,fast,longlist,disp) -volintInfo *pntr; -afs_int32 server,part; -int *totalOK,*totalNotOK,*totalBusy; -int fast,longlist, disp; + code = USD_CLOSE(ufd); + if (code) { + fprintf(STDERR, "Could not close dump file %s\n", + (filename && *filename) ? filename : "STDIN"); + if (!error) + error = code; + } + } + + return (error); +} + +static void +DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast, + longlist, disp) + volintInfo *pntr; + afs_int32 server, part; + int *totalOK, *totalNotOK, *totalBusy; + int fast, longlist, disp; { char pname[10]; - if(fast){ - fprintf(STDOUT,"%-10u\n",pntr->volid); - } - else if(longlist){ - if(pntr->status == VOK){ - fprintf(STDOUT,"%-32s ",pntr->name); - fprintf(STDOUT,"%10u ",pntr->volid); - if(pntr->type == 0) fprintf(STDOUT,"RW "); - if(pntr->type == 1) fprintf(STDOUT,"RO "); - if(pntr->type == 2) fprintf(STDOUT,"BK "); - fprintf(STDOUT,"%10d K ",pntr->size); - if(pntr->inUse == 1) { - fprintf(STDOUT,"On-line"); + if (fast) { + fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid); + } else if (longlist) { + if (pntr->status == VOK) { + fprintf(STDOUT, "%-32s ", pntr->name); + fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid); + if (pntr->type == 0) + fprintf(STDOUT, "RW "); + if (pntr->type == 1) + fprintf(STDOUT, "RO "); + if (pntr->type == 2) + fprintf(STDOUT, "BK "); + fprintf(STDOUT, "%10d K ", pntr->size); + if (pntr->inUse == 1) { + fprintf(STDOUT, "On-line"); *totalOK += 1; } else { - fprintf(STDOUT,"Off-line"); + fprintf(STDOUT, "Off-line"); *totalNotOK++; } - if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**"); - fprintf(STDOUT,"\n"); - MapPartIdIntoName(part,pname); - fprintf(STDOUT," %s %s \n",hostutil_GetNameByINet(server),pname); - fprintf(STDOUT," RWrite %10u ROnly %10u Backup %10u \n", pntr->parentID,pntr->cloneID, pntr->backupID); - fprintf(STDOUT," MaxQuota %10d K \n",pntr->maxquota); - fprintf(STDOUT," Creation %s", - ctime((time_t *)&pntr->creationDate)); - if(pntr->updateDate < pntr->creationDate) - fprintf(STDOUT," Last Update %s", - ctime((time_t *)&pntr->creationDate)); + if (pntr->needsSalvaged == 1) + fprintf(STDOUT, "**needs salvage**"); + fprintf(STDOUT, "\n"); + MapPartIdIntoName(part, pname); + fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server), + pname); + fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n", + (unsigned long)pntr->parentID, + (unsigned long)pntr->cloneID, + (unsigned long)pntr->backupID); + fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota); + fprintf(STDOUT, " Creation %s", + ctime((time_t *) & pntr->creationDate)); +#ifdef FULL_LISTVOL_SWITCH + fprintf(STDOUT, " Copy %s", + ctime((time_t *) & pntr->copyDate)); + if (!pntr->backupDate) + fprintf(STDOUT, " Backup Never\n"); + else + fprintf(STDOUT, " Backup %s", + ctime((time_t *) & pntr->backupDate)); + if (pntr->accessDate) + fprintf(STDOUT, " Last Access %s", + ctime((time_t *) & pntr->accessDate)); +#endif + if (pntr->updateDate < pntr->creationDate) + fprintf(STDOUT, " Last Update %s", + ctime((time_t *) & pntr->creationDate)); else - fprintf(STDOUT," Last Update %s", - ctime((time_t *)&pntr->updateDate)); - fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n", + fprintf(STDOUT, " Last Update %s", + ctime((time_t *) & pntr->updateDate)); + fprintf(STDOUT, + " %d accesses in the past day (i.e., vnode references)\n", pntr->dayUse); - } - else if (pntr->status == VBUSY) { + } else if (pntr->status == VBUSY) { *totalBusy += 1; - qPut(&busyHead,pntr->volid); - if (disp) fprintf(STDOUT,"**** Volume %u is busy ****\n",pntr->volid); - } - else { + qPut(&busyHead, pntr->volid); + if (disp) + fprintf(STDOUT, "**** Volume %lu is busy ****\n", + (unsigned long)pntr->volid); + } else { *totalNotOK += 1; - qPut(¬okHead,pntr->volid); - if (disp) fprintf(STDOUT,"**** Could not attach volume %u ****\n",pntr->volid); - } - fprintf(STDOUT,"\n"); - } - else {/* default listing */ - if(pntr->status == VOK){ - fprintf(STDOUT,"%-32s ",pntr->name); - fprintf(STDOUT,"%10u ",pntr->volid); - if(pntr->type == 0) fprintf(STDOUT,"RW "); - if(pntr->type == 1) fprintf(STDOUT,"RO "); - if(pntr->type == 2) fprintf(STDOUT,"BK "); - fprintf(STDOUT,"%10d K ",pntr->size); - if(pntr->inUse == 1) { - fprintf(STDOUT,"On-line"); + qPut(¬okHead, pntr->volid); + if (disp) + fprintf(STDOUT, "**** Could not attach volume %lu ****\n", + (unsigned long)pntr->volid); + } + fprintf(STDOUT, "\n"); + } else { /* default listing */ + if (pntr->status == VOK) { + fprintf(STDOUT, "%-32s ", pntr->name); + fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid); + if (pntr->type == 0) + fprintf(STDOUT, "RW "); + if (pntr->type == 1) + fprintf(STDOUT, "RO "); + if (pntr->type == 2) + fprintf(STDOUT, "BK "); + fprintf(STDOUT, "%10d K ", pntr->size); + if (pntr->inUse == 1) { + fprintf(STDOUT, "On-line"); *totalOK += 1; } else { - fprintf(STDOUT,"Off-line"); + fprintf(STDOUT, "Off-line"); *totalNotOK += 1; } - if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**"); - fprintf(STDOUT,"\n"); - } - else if (pntr->status == VBUSY) { + if (pntr->needsSalvaged == 1) + fprintf(STDOUT, "**needs salvage**"); + fprintf(STDOUT, "\n"); + } else if (pntr->status == VBUSY) { *totalBusy += 1; - qPut(&busyHead,pntr->volid); - if (disp) fprintf(STDOUT,"**** Volume %u is busy ****\n",pntr->volid); - } - else { + qPut(&busyHead, pntr->volid); + if (disp) + fprintf(STDOUT, "**** Volume %lu is busy ****\n", + (unsigned long)pntr->volid); + } else { *totalNotOK += 1; - qPut(¬okHead,pntr->volid); - if (disp) fprintf(STDOUT,"**** Could not attach volume %u ****\n",pntr->volid); + qPut(¬okHead, pntr->volid); + if (disp) + fprintf(STDOUT, "**** Could not attach volume %lu ****\n", + (unsigned long)pntr->volid); } } } @@ -566,20 +586,20 @@ int fast,longlist, disp; * As advertised. *------------------------------------------------------------------------*/ -static void XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, - a_totalNotOKP, a_totalBusyP, a_fast, a_int32, - a_showProblems) - volintXInfo *a_xInfoP; - afs_int32 a_servID; - afs_int32 a_partID; - int *a_totalOKP; - int *a_totalNotOKP; - int *a_totalBusyP; - int a_fast; - int a_int32; - int a_showProblems; - -{ /*XDisplayFormat*/ +static void +XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP, + a_totalBusyP, a_fast, a_int32, a_showProblems) + volintXInfo *a_xInfoP; + afs_int32 a_servID; + afs_int32 a_partID; + int *a_totalOKP; + int *a_totalNotOKP; + int *a_totalBusyP; + int a_fast; + int a_int32; + int a_showProblems; + +{ /*XDisplayFormat */ char pname[10]; @@ -587,286 +607,299 @@ static void XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, /* * Short & sweet. */ - fprintf(STDOUT, "%-10u\n", a_xInfoP->volid); - } - else - if (a_int32) { + fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid); + } else if (a_int32) { + /* + * Fully-detailed listing. + */ + if (a_xInfoP->status == VOK) { /* - * Fully-detailed listing. + * Volume's status is OK - all the fields are valid. */ - if (a_xInfoP->status == VOK) { - /* - * Volume's status is OK - all the fields are valid. - */ - fprintf(STDOUT, "%-32s ", a_xInfoP->name); - fprintf(STDOUT, "%10u ", a_xInfoP->volid); - if (a_xInfoP->type == 0) fprintf(STDOUT,"RW "); - if (a_xInfoP->type == 1) fprintf(STDOUT,"RO "); - if (a_xInfoP->type == 2) fprintf(STDOUT,"BK "); - fprintf(STDOUT, "%10d K used ", a_xInfoP->size); - fprintf(STDOUT, "%d files ", a_xInfoP->filecount); - if(a_xInfoP->inUse == 1) { - fprintf(STDOUT, "On-line"); - (*a_totalOKP)++; - } - else { - fprintf(STDOUT, "Off-line"); - (*a_totalNotOKP)++; - } - fprintf(STDOUT, "\n"); - MapPartIdIntoName(a_partID, pname); - fprintf(STDOUT, " %s %s \n", - hostutil_GetNameByINet(a_servID), - pname); - fprintf(STDOUT, " RWrite %10u ROnly %10u Backup %10u \n", - a_xInfoP->parentID, a_xInfoP->cloneID, a_xInfoP->backupID); - fprintf(STDOUT, " MaxQuota %10d K \n", - a_xInfoP->maxquota); - fprintf(STDOUT, " Creation %s", - ctime((time_t *)&a_xInfoP->creationDate)); - if (a_xInfoP->updateDate < a_xInfoP->creationDate) - fprintf(STDOUT, " Last Update %s", - ctime((time_t *)&a_xInfoP->creationDate)); - else - fprintf(STDOUT, " Last Update %s", - ctime((time_t *)&a_xInfoP->updateDate)); - fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n", - a_xInfoP->dayUse); - - /* - * Print all the read/write and authorship stats. - */ - fprintf(STDOUT, - "\n Raw Read/Write Stats\n"); - fprintf(STDOUT, - " |-------------------------------------------|\n"); - fprintf(STDOUT, - " | Same Network | Diff Network |\n"); - fprintf(STDOUT, - " |----------|----------|----------|----------|\n"); - fprintf(STDOUT, - " | Total | Auth | Total | Auth |\n"); - fprintf(STDOUT, - " |----------|----------|----------|----------|\n"); - fprintf(STDOUT, - "Reads | %8d | %8d | %8d | %8d |\n", - a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET], - a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH], - a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET], - a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]); - fprintf(STDOUT, - "Writes | %8d | %8d | %8d | %8d |\n", - a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET], - a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH], - a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET], - a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]); - fprintf(STDOUT, - " |-------------------------------------------|\n\n"); - - fprintf(STDOUT, - " Writes Affecting Authorship\n"); - fprintf(STDOUT, - " |-------------------------------------------|\n"); - fprintf(STDOUT, - " | File Authorship | Directory Authorship|\n"); - fprintf(STDOUT, - " |----------|----------|----------|----------|\n"); - fprintf(STDOUT, - " | Same | Diff | Same | Diff |\n"); - fprintf(STDOUT, - " |----------|----------|----------|----------|\n"); - fprintf(STDOUT, - "0-60 sec | %8d | %8d | %8d | %8d |\n", - a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0], - a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0], - a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0], - a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]); - fprintf(STDOUT, - "1-10 min | %8d | %8d | %8d | %8d |\n", - a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1], - a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1], - a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1], - a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]); - fprintf(STDOUT, - "10min-1hr | %8d | %8d | %8d | %8d |\n", - a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2], - a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2], - a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2], - a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]); - fprintf(STDOUT, - "1hr-1day | %8d | %8d | %8d | %8d |\n", - a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3], - a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3], - a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3], - a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]); - fprintf(STDOUT, - "1day-1wk | %8d | %8d | %8d | %8d |\n", - a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4], - a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4], - a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4], - a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]); - fprintf(STDOUT, - "> 1wk | %8d | %8d | %8d | %8d |\n", - a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5], - a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5], - a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5], - a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]); - fprintf(STDOUT, - " |-------------------------------------------|\n"); - } /*Volume status OK*/ + fprintf(STDOUT, "%-32s ", a_xInfoP->name); + fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid); + if (a_xInfoP->type == 0) + fprintf(STDOUT, "RW "); + if (a_xInfoP->type == 1) + fprintf(STDOUT, "RO "); + if (a_xInfoP->type == 2) + fprintf(STDOUT, "BK "); + fprintf(STDOUT, "%10d K used ", a_xInfoP->size); + fprintf(STDOUT, "%d files ", a_xInfoP->filecount); + if (a_xInfoP->inUse == 1) { + fprintf(STDOUT, "On-line"); + (*a_totalOKP)++; + } else { + fprintf(STDOUT, "Off-line"); + (*a_totalNotOKP)++; + } + fprintf(STDOUT, "\n"); + MapPartIdIntoName(a_partID, pname); + fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID), + pname); + fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n", + (unsigned long)a_xInfoP->parentID, + (unsigned long)a_xInfoP->cloneID, + (unsigned long)a_xInfoP->backupID); + fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota); + fprintf(STDOUT, " Creation %s", + ctime((time_t *) & a_xInfoP->creationDate)); +#ifdef FULL_LISTVOL_SWITCH + fprintf(STDOUT, " Copy %s", + ctime((time_t *) & a_xInfoP->copyDate)); + if (!a_xInfoP->backupDate) + fprintf(STDOUT, " Backup Never\n"); else - if (a_xInfoP->status == VBUSY) { - (*a_totalBusyP)++; - qPut(&busyHead, a_xInfoP->volid); - if (a_showProblems) - fprintf(STDOUT, "**** Volume %u is busy ****\n", - a_xInfoP->volid); - } /*Busy volume*/ - else { - (*a_totalNotOKP)++; - qPut(¬okHead, a_xInfoP->volid); - if (a_showProblems) - fprintf(STDOUT, "**** Could not attach volume %u ****\n", - a_xInfoP->volid); - } /*Screwed volume*/ - fprintf(STDOUT,"\n"); - } /*Long listing*/ - else { + fprintf(STDOUT, " Backup %s", + ctime((time_t *) & a_xInfoP->backupDate)); + if (a_xInfoP->accessDate) + fprintf(STDOUT, " Last Access %s", + ctime((time_t *) & a_xInfoP->accessDate)); +#endif + if (a_xInfoP->updateDate < a_xInfoP->creationDate) + fprintf(STDOUT, " Last Update %s", + ctime((time_t *) & a_xInfoP->creationDate)); + else + fprintf(STDOUT, " Last Update %s", + ctime((time_t *) & a_xInfoP->updateDate)); + fprintf(STDOUT, + " %d accesses in the past day (i.e., vnode references)\n", + a_xInfoP->dayUse); + /* - * Default listing. + * Print all the read/write and authorship stats. */ - if (a_xInfoP->status == VOK) { - fprintf(STDOUT, "%-32s ", a_xInfoP->name); - fprintf(STDOUT, "%10u ", a_xInfoP->volid); - if (a_xInfoP->type == 0) fprintf(STDOUT, "RW "); - if (a_xInfoP->type == 1) fprintf(STDOUT, "RO "); - if (a_xInfoP->type == 2) fprintf(STDOUT, "BK "); - fprintf(STDOUT, "%10d K ", a_xInfoP->size); - if(a_xInfoP->inUse == 1) { - fprintf(STDOUT, "On-line"); - (*a_totalOKP)++; - } else { - fprintf(STDOUT, "Off-line"); - (*a_totalNotOKP)++; - } - fprintf(STDOUT, "\n"); - } /*Volume OK*/ - else - if (a_xInfoP->status == VBUSY) { - (*a_totalBusyP)++; - qPut(&busyHead, a_xInfoP->volid); - if (a_showProblems) - fprintf(STDOUT,"**** Volume %u is busy ****\n", - a_xInfoP->volid); - } /*Busy volume*/ - else { - (*a_totalNotOKP)++; - qPut(¬okHead, a_xInfoP->volid); - if (a_showProblems) - fprintf(STDOUT,"**** Could not attach volume %u ****\n", - a_xInfoP->volid); - } /*Screwed volume*/ - } /*Default listing*/ -} /*XDisplayFormat*/ + fprintf(STDOUT, "\n Raw Read/Write Stats\n"); + fprintf(STDOUT, + " |-------------------------------------------|\n"); + fprintf(STDOUT, + " | Same Network | Diff Network |\n"); + fprintf(STDOUT, + " |----------|----------|----------|----------|\n"); + fprintf(STDOUT, + " | Total | Auth | Total | Auth |\n"); + fprintf(STDOUT, + " |----------|----------|----------|----------|\n"); + fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n", + a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET], + a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH], + a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET], + a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]); + fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n", + a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET], + a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH], + a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET], + a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]); + fprintf(STDOUT, + " |-------------------------------------------|\n\n"); + + fprintf(STDOUT, + " Writes Affecting Authorship\n"); + fprintf(STDOUT, + " |-------------------------------------------|\n"); + fprintf(STDOUT, + " | File Authorship | Directory Authorship|\n"); + fprintf(STDOUT, + " |----------|----------|----------|----------|\n"); + fprintf(STDOUT, + " | Same | Diff | Same | Diff |\n"); + fprintf(STDOUT, + " |----------|----------|----------|----------|\n"); + fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n", + a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0], + a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0], + a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0], + a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]); + fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n", + a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1], + a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1], + a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1], + a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]); + fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n", + a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2], + a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2], + a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2], + a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]); + fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n", + a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3], + a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3], + a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3], + a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]); + fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n", + a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4], + a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4], + a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4], + a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]); + fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n", + a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5], + a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5], + a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5], + a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]); + fprintf(STDOUT, + " |-------------------------------------------|\n"); + } /*Volume status OK */ + else if (a_xInfoP->status == VBUSY) { + (*a_totalBusyP)++; + qPut(&busyHead, a_xInfoP->volid); + if (a_showProblems) + fprintf(STDOUT, "**** Volume %lu is busy ****\n", + (unsigned long)a_xInfoP->volid); + } /*Busy volume */ + else { + (*a_totalNotOKP)++; + qPut(¬okHead, a_xInfoP->volid); + if (a_showProblems) + fprintf(STDOUT, "**** Could not attach volume %lu ****\n", + (unsigned long)a_xInfoP->volid); + } /*Screwed volume */ + fprintf(STDOUT, "\n"); + } /*Long listing */ + else { + /* + * Default listing. + */ + if (a_xInfoP->status == VOK) { + fprintf(STDOUT, "%-32s ", a_xInfoP->name); + fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid); + if (a_xInfoP->type == 0) + fprintf(STDOUT, "RW "); + if (a_xInfoP->type == 1) + fprintf(STDOUT, "RO "); + if (a_xInfoP->type == 2) + fprintf(STDOUT, "BK "); + fprintf(STDOUT, "%10d K ", a_xInfoP->size); + if (a_xInfoP->inUse == 1) { + fprintf(STDOUT, "On-line"); + (*a_totalOKP)++; + } else { + fprintf(STDOUT, "Off-line"); + (*a_totalNotOKP)++; + } + fprintf(STDOUT, "\n"); + } /*Volume OK */ + else if (a_xInfoP->status == VBUSY) { + (*a_totalBusyP)++; + qPut(&busyHead, a_xInfoP->volid); + if (a_showProblems) + fprintf(STDOUT, "**** Volume %lu is busy ****\n", + (unsigned long)a_xInfoP->volid); + } /*Busy volume */ + else { + (*a_totalNotOKP)++; + qPut(¬okHead, a_xInfoP->volid); + if (a_showProblems) + fprintf(STDOUT, "**** Could not attach volume %lu ****\n", + (unsigned long)a_xInfoP->volid); + } /*Screwed volume */ + } /*Default listing */ +} /*XDisplayFormat */ #ifdef FULL_LISTVOL_SWITCH -static void DisplayFormat2(server, partition, pntr) - long server, partition; - volintInfo *pntr; +static void +DisplayFormat2(server, partition, pntr) + long server, partition; + volintInfo *pntr; { - static long server_cache = -1, partition_cache = -1; - static char hostname[256], - address[32], - pname[16]; - - if (server != server_cache) { - struct in_addr s; - - s.s_addr = server; - strcpy(hostname, hostutil_GetNameByINet(server)); - strcpy(address, inet_ntoa(s)); - server_cache = server; - } - if (partition != partition_cache) { - MapPartIdIntoName(partition, pname); - partition_cache = partition; - } - fprintf(STDOUT, "name\t\t%s\n", pntr->name); - fprintf(STDOUT, "id\t\t%lu\n", pntr->volid); - fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname); - fprintf(STDOUT, "part\t\t%s\n", pname); - switch (pntr->status) { - case VOK: - fprintf(STDOUT, "status\t\tOK\n"); - break; - case VBUSY: - fprintf(STDOUT, "status\t\tBUSY\n"); - return; - default: - fprintf(STDOUT, "status\t\tUNATTACHABLE\n"); + static long server_cache = -1, partition_cache = -1; + static char hostname[256], address[32], pname[16]; + + if (server != server_cache) { + struct in_addr s; + + s.s_addr = server; + strcpy(hostname, hostutil_GetNameByINet(server)); + strcpy(address, inet_ntoa(s)); + server_cache = server; + } + if (partition != partition_cache) { + MapPartIdIntoName(partition, pname); + partition_cache = partition; + } else { + pname[0] = '\0'; + } + fprintf(STDOUT, "name\t\t%s\n", pntr->name); + fprintf(STDOUT, "id\t\t%lu\n", pntr->volid); + fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname); + fprintf(STDOUT, "part\t\t%s\n", pname); + switch (pntr->status) { + case VOK: + fprintf(STDOUT, "status\t\tOK\n"); + break; + case VBUSY: + fprintf(STDOUT, "status\t\tBUSY\n"); + return; + default: + fprintf(STDOUT, "status\t\tUNATTACHABLE\n"); + return; + } + fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID); + fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID); + fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID); + fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N"); + fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N"); + /* 0xD3 is from afs/volume.h since I had trouble including the file */ + fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N"); + switch (pntr->type) { + case 0: + fprintf(STDOUT, "type\t\tRW\n"); + break; + case 1: + fprintf(STDOUT, "type\t\tRO\n"); + break; + case 2: + fprintf(STDOUT, "type\t\tBK\n"); + break; + default: + fprintf(STDOUT, "type\t\t?\n"); + break; + } + fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate, + ctime(&pntr->creationDate)); + fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate, + ctime(&pntr->accessDate)); + fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate, + ctime(&pntr->updateDate)); + fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate, + ctime(&pntr->backupDate)); + fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate, + ctime(&pntr->copyDate)); + fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags); + fprintf(STDOUT, "diskused\t%u\n", pntr->size); + fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota); + fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0); + fprintf(STDOUT, "filecount\t%u\n", pntr->filecount); + fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse); + fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1); + fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2); + fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3); return; - } - fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID); - fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID); - fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID); - fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N"); - fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N"); - /* 0xD3 is from afs/volume.h since I had trouble including the file */ - fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N"); - switch (pntr->type) { - case 0: - fprintf(STDOUT, "type\t\tRW\n"); - break; - case 1: - fprintf(STDOUT, "type\t\tRO\n"); - break; - case 2: - fprintf(STDOUT, "type\t\tBK\n"); - break; - default: - fprintf(STDOUT, "type\t\t?\n"); - break; - } - fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate, ctime(&pntr->creationDate)); - fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate, ctime(&pntr->accessDate)); - fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate, ctime(&pntr->updateDate)); - fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate, ctime(&pntr->backupDate)); - fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate, ctime(&pntr->copyDate)); - fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags); - fprintf(STDOUT, "diskused\t%u\n", pntr->size); - fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota); - fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0); - fprintf(STDOUT, "filecount\t%u\n", pntr->filecount); - fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse); - fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1); - fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2); - fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3); - return; } -static void DisplayVolumes2(server, partition, pntr, count) - volintInfo *pntr; - long server, partition, count; +static void +DisplayVolumes2(server, partition, pntr, count) + volintInfo *pntr; + long server, partition, count; { - long i; - - for (i = 0; i < count; i++) { - fprintf(STDOUT, "BEGIN_OF_ENTRY\n"); - DisplayFormat2(server, partition, pntr); - fprintf(STDOUT, "END_OF_ENTRY\n\n"); - pntr++; - } - return; + long i; + + for (i = 0; i < count; i++) { + fprintf(STDOUT, "BEGIN_OF_ENTRY\n"); + DisplayFormat2(server, partition, pntr); + fprintf(STDOUT, "END_OF_ENTRY\n\n"); + pntr++; + } + return; } #endif /* FULL_LISTVOL_SWITCH */ -static void DisplayVolumes(server,part,pntr,count,longlist,fast,quiet) -afs_int32 server,part; -volintInfo *pntr; -afs_int32 count,longlist,fast; -int quiet; +static void +DisplayVolumes(server, part, pntr, count, longlist, fast, quiet) + afs_int32 server, part; + volintInfo *pntr; + afs_int32 count, longlist, fast; + int quiet; { - int totalOK,totalNotOK,totalBusy, i; + int totalOK, totalNotOK, totalBusy, i; afs_int32 volid; totalOK = 0; @@ -874,26 +907,31 @@ int quiet; totalBusy = 0; qInit(&busyHead); qInit(¬okHead); - for(i = 0; i < count; i++){ - DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,fast,longlist,0); + for (i = 0; i < count; i++) { + DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, + fast, longlist, 0); pntr++; } - if(totalBusy){ - while(busyHead.count){ - qGet(&busyHead,&volid); - fprintf(STDOUT,"**** Volume %u is busy ****\n",volid); + if (totalBusy) { + while (busyHead.count) { + qGet(&busyHead, &volid); + fprintf(STDOUT, "**** Volume %lu is busy ****\n", + (unsigned long)volid); } } - if(totalNotOK){ - while(notokHead.count){ - qGet(¬okHead,&volid); - fprintf(STDOUT,"**** Could not attach volume %u ****\n",volid); + if (totalNotOK) { + while (notokHead.count) { + qGet(¬okHead, &volid); + fprintf(STDOUT, "**** Could not attach volume %lu ****\n", + (unsigned long)volid); } } - if(!quiet){ - fprintf(STDOUT,"\n"); - if(!fast){ - fprintf(STDOUT,"Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",totalOK,totalNotOK,totalBusy); + if (!quiet) { + fprintf(STDOUT, "\n"); + if (!fast) { + fprintf(STDOUT, + "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n", + totalOK, totalNotOK, totalBusy); } } } @@ -923,23 +961,24 @@ int quiet; * As advertised. *------------------------------------------------------------------------*/ -static void XDisplayVolumes(a_servID, a_partID, a_xInfoP, - a_count, a_int32, a_fast, a_quiet) - afs_int32 a_servID; - afs_int32 a_partID; - volintXInfo *a_xInfoP; - afs_int32 a_count; - afs_int32 a_int32; - afs_int32 a_fast; - int a_quiet; - -{ /*XDisplayVolumes*/ - - int totalOK; /*Total OK volumes*/ - int totalNotOK; /*Total screwed volumes*/ - int totalBusy; /*Total busy volumes*/ - int i; /*Loop variable*/ - afs_int32 volid; /*Current volume ID*/ +static void +XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast, + a_quiet) + afs_int32 a_servID; + afs_int32 a_partID; + volintXInfo *a_xInfoP; + afs_int32 a_count; + afs_int32 a_int32; + afs_int32 a_fast; + int a_quiet; + +{ /*XDisplayVolumes */ + + int totalOK; /*Total OK volumes */ + int totalNotOK; /*Total screwed volumes */ + int totalBusy; /*Total busy volumes */ + int i; /*Loop variable */ + afs_int32 volid; /*Current volume ID */ /* * Initialize counters and (global!!) queues. @@ -953,16 +992,9 @@ static void XDisplayVolumes(a_servID, a_partID, a_xInfoP, /* * Display each volume in the list. */ - for(i = 0; i < a_count; i++) { - XDisplayFormat(a_xInfoP, - a_servID, - a_partID, - &totalOK, - &totalNotOK, - &totalBusy, - a_fast, - a_int32, - 0); + for (i = 0; i < a_count; i++) { + XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK, + &totalBusy, a_fast, a_int32, 0); a_xInfoP++; } @@ -972,13 +1004,15 @@ static void XDisplayVolumes(a_servID, a_partID, a_xInfoP, if (totalBusy) { while (busyHead.count) { qGet(&busyHead, &volid); - fprintf(STDOUT, "**** Volume %u is busy ****\n", volid); + fprintf(STDOUT, "**** Volume %lu is busy ****\n", + (unsigned long)volid); } } if (totalNotOK) { while (notokHead.count) { qGet(¬okHead, &volid); - fprintf(STDOUT, "**** Could not attach volume %u ****\n", volid); + fprintf(STDOUT, "**** Could not attach volume %lu ****\n", + (unsigned long)volid); } } @@ -991,38 +1025,39 @@ static void XDisplayVolumes(a_servID, a_partID, a_xInfoP, } } -} /*XDisplayVolumes*/ +} /*XDisplayVolumes */ /* set and to the correct values depending on * and */ -static void GetServerAndPart (entry, voltype, server, part, previdx) - struct nvldbentry *entry; - afs_int32 *server,*part; - int voltype; - int *previdx; +static void +GetServerAndPart(entry, voltype, server, part, previdx) + struct nvldbentry *entry; + afs_int32 *server, *part; + int voltype; + int *previdx; { int i, istart, vtype; *server = -1; - *part = -1; + *part = -1; /* Doesn't check for non-existance of backup volume */ if ((voltype == RWVOL) || (voltype == BACKVOL)) { - vtype = ITSRWVOL; - istart = 0; /* seach the entire entry */ + vtype = ITSRWVOL; + istart = 0; /* seach the entire entry */ } else { - vtype = ITSROVOL; - /* Seach from beginning of entry or pick up where we left off */ - istart = ((*previdx < 0) ? 0 : *previdx+1); + vtype = ITSROVOL; + /* Seach from beginning of entry or pick up where we left off */ + istart = ((*previdx < 0) ? 0 : *previdx + 1); } for (i = istart; i < entry->nServers; i++) { - if (entry->serverFlags[i] & vtype) { - *server = entry->serverNumber[i]; - *part = entry->serverPartition[i]; - *previdx = i; - return; - } + if (entry->serverFlags[i] & vtype) { + *server = entry->serverNumber[i]; + *part = entry->serverPartition[i]; + *previdx = i; + return; + } } /* Didn't find any, return -1 */ @@ -1030,13 +1065,14 @@ static void GetServerAndPart (entry, voltype, server, part, previdx) return; } -static void PostVolumeStats(entry) -struct nvldbentry *entry; +static void +PostVolumeStats(entry) + struct nvldbentry *entry; { SubEnumerateEntry(entry); /* Check for VLOP_ALLOPERS */ if (entry->flags & VLOP_ALLOPERS) - fprintf(STDOUT," Volume is currently LOCKED \n"); + fprintf(STDOUT, " Volume is currently LOCKED \n"); return; } @@ -1063,46 +1099,50 @@ struct nvldbentry *entry; * As advertised. *------------------------------------------------------------------------*/ -static void XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType) - volintXInfo *a_xInfoP; - struct nvldbentry *a_entryP; - afs_int32 a_srvID; - afs_int32 a_partID; - int a_volType; - -{ /*XVolumeStats*/ - - int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here*/ - - XDisplayFormat(a_xInfoP, /*Ptr to extended volume info*/ - a_srvID, /*Server ID to print*/ - a_partID, /*Partition ID to print*/ - &totalOK, /*Ptr to total-OK counter*/ - &totalNotOK, /*Ptr to total-screwed counter*/ - &totalBusy, /*Ptr to total-busy counter*/ - 0, /*Don't do a fast listing*/ - 1, /*Do a long listing*/ - 1); /*Show volume problems*/ +static void +XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType) + volintXInfo *a_xInfoP; + struct nvldbentry *a_entryP; + afs_int32 a_srvID; + afs_int32 a_partID; + int a_volType; + +{ /*XVolumeStats */ + + int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */ + + XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */ + a_srvID, /*Server ID to print */ + a_partID, /*Partition ID to print */ + &totalOK, /*Ptr to total-OK counter */ + &totalNotOK, /*Ptr to total-screwed counter */ + &totalBusy, /*Ptr to total-busy counter */ + 0, /*Don't do a fast listing */ + 1, /*Do a long listing */ + 1); /*Show volume problems */ return; -} /*XVolumeStats*/ +} /*XVolumeStats */ -static void VolumeStats(pntr,entry,server,part,voltype) -volintInfo *pntr; -struct nvldbentry *entry; -int voltype; -afs_int32 server,part; +static void +VolumeStats(pntr, entry, server, part, voltype) + volintInfo *pntr; + struct nvldbentry *entry; + int voltype; + afs_int32 server, part; { - int totalOK,totalNotOK,totalBusy; - afs_int32 vcode,vcode2; - - DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,0,1,1); + int totalOK, totalNotOK, totalBusy; + + DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1, + 1); return; } /* command to forcibly remove a volume */ -static NukeVolume(as) -register struct cmd_syndesc *as; { +static +NukeVolume(as) + register struct cmd_syndesc *as; +{ register afs_int32 code; afs_int32 volID, err; afs_int32 partID; @@ -1111,7 +1151,7 @@ register struct cmd_syndesc *as; { server = GetServer(tp = as->parms[0].items->data); if (!server) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", tp); + fprintf(STDERR, "vos: server '%s' not found in host table\n", tp); return 1; } @@ -1123,12 +1163,17 @@ register struct cmd_syndesc *as; { volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err); if (volID == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: could not parse '%s' as a numeric volume ID", tp); + if (err) + PrintError("", err); + else + fprintf(STDERR, + "vos: could not parse '%s' as a numeric volume ID", tp); return 1; } - fprintf(STDOUT, "vos: forcibly removing all traces of volume %d, please wait...", volID); + fprintf(STDOUT, + "vos: forcibly removing all traces of volume %d, please wait...", + volID); fflush(STDOUT); code = UV_NukeVolume(server, partID, volID); if (code == 0) @@ -1160,119 +1205,133 @@ register struct cmd_syndesc *as; { * As advertised. *------------------------------------------------------------------------ */ -static ExamineVolume(as) -register struct cmd_syndesc *as; +static +ExamineVolume(as) + register struct cmd_syndesc *as; { struct nvldbentry entry; afs_int32 vcode = 0; - volintInfo *pntr = (volintInfo *)0; - volintXInfo *xInfoP = (volintXInfo *)0; + volintInfo *pntr = (volintInfo *) 0; + volintXInfo *xInfoP = (volintXInfo *) 0; afs_int32 volid; afs_int32 code, err, error = 0; int voltype, foundserv = 0, foundentry = 0; afs_int32 aserver, apart; int previdx = -1; - int wantExtendedInfo; /*Do we want extended vol info?*/ + int wantExtendedInfo; /*Do we want extended vol info? */ - wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */ + wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */ - volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */ + volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */ if (volid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data); + if (err) + PrintError("", err); + else + fprintf(STDERR, "Unknown volume ID or name '%s'\n", + as->parms[0].items->data); return -1; } if (verbose) { - fprintf(STDOUT, "Fetching VLDB entry for %u .. ", volid); - fflush(STDOUT); + fprintf(STDOUT, "Fetching VLDB entry for %lu .. ", + (unsigned long)volid); + fflush(STDOUT); } - vcode = VLDB_GetEntryByID (volid, -1, &entry); + vcode = VLDB_GetEntryByID(volid, -1, &entry); if (vcode) { - fprintf(STDERR, "Could not fetch the entry for volume number %u from VLDB \n",volid); + fprintf(STDERR, + "Could not fetch the entry for volume number %lu from VLDB \n", + (unsigned long)volid); return (vcode); } if (verbose) - fprintf(STDOUT, "done\n"); + fprintf(STDOUT, "done\n"); MapHostToNetwork(&entry); if (entry.volumeId[RWVOL] == volid) - voltype = RWVOL; + voltype = RWVOL; else if (entry.volumeId[BACKVOL] == volid) - voltype = BACKVOL; - else /* (entry.volumeId[ROVOL] == volid) */ - voltype = ROVOL; - - do { /* do {...} while (voltype == ROVOL) */ - /* Get the entry for the volume. If its a RW vol, get the RW entry. - * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist). - * If its a RO vol, get the next RO entry. - */ - GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL), &aserver, &apart, &previdx); - if (previdx == -1) { /* searched all entries */ - if (!foundentry) { - fprintf(STDERR,"Volume %s does not exist in VLDB\n\n", as->parms[0].items->data); - error = ENOENT; - } - break; - } - foundentry = 1; - - /* Get information about the volume from the server */ - if (verbose) { - fprintf(STDOUT,"Getting volume listing from the server %s .. ", - hostutil_GetNameByINet(aserver)); - fflush(STDOUT); - } - if (wantExtendedInfo) - code = UV_XListOneVolume(aserver, apart, volid, &xInfoP); - else - code = UV_ListOneVolume(aserver, apart, volid, &pntr); - if (verbose) - fprintf(STDOUT,"done\n"); - - if (code) { - error = code; - if (code == ENODEV) { - if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) { - /* The VLDB says there is no backup volume and its not on disk */ - fprintf(STDERR, "Volume %s does not exist\n", as->parms[0].items->data); + voltype = BACKVOL; + else /* (entry.volumeId[ROVOL] == volid) */ + voltype = ROVOL; + + do { /* do {...} while (voltype == ROVOL) */ + /* Get the entry for the volume. If its a RW vol, get the RW entry. + * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist). + * If its a RO vol, get the next RO entry. + */ + GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL), + &aserver, &apart, &previdx); + if (previdx == -1) { /* searched all entries */ + if (!foundentry) { + fprintf(STDERR, "Volume %s does not exist in VLDB\n\n", + as->parms[0].items->data); error = ENOENT; - } else { - fprintf(STDERR, "Volume does not exist on server %s as indicated by the VLDB\n", - hostutil_GetNameByINet(aserver)); - } - } else { - PrintDiagnostics("examine", code); - } - fprintf(STDOUT, "\n"); - } else { - foundserv = 1; - if (wantExtendedInfo) - XVolumeStats(xInfoP, &entry, aserver, apart, voltype); - else + } + break; + } + foundentry = 1; + + /* Get information about the volume from the server */ + if (verbose) { + fprintf(STDOUT, "Getting volume listing from the server %s .. ", + hostutil_GetNameByINet(aserver)); + fflush(STDOUT); + } + if (wantExtendedInfo) + code = UV_XListOneVolume(aserver, apart, volid, &xInfoP); + else + code = UV_ListOneVolume(aserver, apart, volid, &pntr); + if (verbose) + fprintf(STDOUT, "done\n"); + + if (code) { + error = code; + if (code == ENODEV) { + if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) { + /* The VLDB says there is no backup volume and its not on disk */ + fprintf(STDERR, "Volume %s does not exist\n", + as->parms[0].items->data); + error = ENOENT; + } else { + fprintf(STDERR, + "Volume does not exist on server %s as indicated by the VLDB\n", + hostutil_GetNameByINet(aserver)); + } + } else { + PrintDiagnostics("examine", code); + } + fprintf(STDOUT, "\n"); + } else { + foundserv = 1; + if (wantExtendedInfo) + XVolumeStats(xInfoP, &entry, aserver, apart, voltype); + else #ifdef FULL_LISTVOL_SWITCH - if (as->parms[2].items) { - DisplayFormat2(aserver, apart, pntr); - EnumerateEntry(&entry); - } else + if (as->parms[2].items) { + DisplayFormat2(aserver, apart, pntr); + EnumerateEntry(&entry); + } else #endif /* FULL_LISTVOL_SWITCH */ - VolumeStats(pntr, &entry, aserver, apart, voltype); + VolumeStats(pntr, &entry, aserver, apart, voltype); - if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) { - /* The VLDB says there is no backup volume yet we found one on disk */ - fprintf(STDERR, "Volume %s does not exist in VLDB\n", as->parms[0].items->data); - error = ENOENT; - } - } + if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) { + /* The VLDB says there is no backup volume yet we found one on disk */ + fprintf(STDERR, "Volume %s does not exist in VLDB\n", + as->parms[0].items->data); + error = ENOENT; + } + } - if (pntr) free(pntr); - if (xInfoP) free(xInfoP); + if (pntr) + free(pntr); + if (xInfoP) + free(xInfoP); } while (voltype == ROVOL); if (!foundserv) { - fprintf(STDERR,"Dump only information from VLDB\n\n"); - fprintf(STDOUT,"%s \n", entry.name); /* PostVolumeStats doesn't print name */ + fprintf(STDERR, "Dump only information from VLDB\n\n"); + fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */ } PostVolumeStats(&entry); @@ -1299,8 +1358,9 @@ register struct cmd_syndesc *as; * As advertised. *------------------------------------------------------------------------ */ -static SetFields(as) -register struct cmd_syndesc *as; +static +SetFields(as) + register struct cmd_syndesc *as; { struct nvldbentry entry; afs_int32 vcode = 0; @@ -1310,42 +1370,48 @@ register struct cmd_syndesc *as; afs_int32 aserver, apart; int previdx = -1; - volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */ + volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */ if (volid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data); + if (err) + PrintError("", err); + else + fprintf(STDERR, "Unknown volume ID or name '%s'\n", + as->parms[0].items->data); return -1; } - code = VLDB_GetEntryByID (volid, RWVOL, &entry); + code = VLDB_GetEntryByID(volid, RWVOL, &entry); if (code) { - fprintf(STDERR, "Could not fetch the entry for volume number %u from VLDB \n",volid); + fprintf(STDERR, + "Could not fetch the entry for volume number %lu from VLDB \n", + (unsigned long)volid); return (code); } MapHostToNetwork(&entry); GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx); if (previdx == -1) { - fprintf(STDERR,"Volume %s does not exist in VLDB\n\n", as->parms[0].items->data); + fprintf(STDERR, "Volume %s does not exist in VLDB\n\n", + as->parms[0].items->data); return (ENOENT); } memset(&info, 0, sizeof(info)); - info.volid = volid; - info.type = RWVOL; - info.dayUse = -1; + info.volid = volid; + info.type = RWVOL; + info.dayUse = -1; info.maxquota = -1; - info.flags = -1; - info.spare0 = -1; - info.spare1 = -1; - info.spare2 = -1; - info.spare3 = -1; + info.flags = -1; + info.spare0 = -1; + info.spare1 = -1; + info.spare2 = -1; + info.spare3 = -1; if (as->parms[1].items) { /* -max */ code = util_GetInt32(as->parms[1].items->data, &info.maxquota); if (code) { - fprintf(STDERR,"invalid quota value\n"); + fprintf(STDERR, "invalid quota value\n"); return code; } } @@ -1355,7 +1421,9 @@ register struct cmd_syndesc *as; } code = UV_SetVolumeInfo(aserver, apart, volid, &info); if (code) - fprintf(STDERR,"Could not update volume info fields for volume number %u\n",volid); + fprintf(STDERR, + "Could not update volume info fields for volume number %lu\n", + (unsigned long)volid); return (code); } @@ -1378,35 +1446,42 @@ register struct cmd_syndesc *as; * As advertised. *------------------------------------------------------------------------ */ -static volOnline(as) - register struct cmd_syndesc *as; +static +volOnline(as) + register struct cmd_syndesc *as; { afs_int32 server, partition, volid; - afs_int32 code, err=0; + afs_int32 code, err = 0; server = GetServer(as->parms[0].items->data); if (server == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data); + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); return -1; } partition = volutil_GetPartitionID(as->parms[1].items->data); if (partition < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data); + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); return ENOENT; } - volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */ + volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */ if (!volid) { - if (err) PrintError("", err); - else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data); - return -1; + if (err) + PrintError("", err); + else + fprintf(STDERR, "Unknown volume ID or name '%s'\n", + as->parms[0].items->data); + return -1; } - code = UV_SetVolume(server, partition, volid, ITOffline, 0/*online*/, 0/*sleep*/); + code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ , + 0 /*sleep */ ); if (code) { - fprintf(STDERR, "Failed to set volume. Code = %d\n", code); - return -1; + fprintf(STDERR, "Failed to set volume. Code = %d\n", code); + return -1; } return 0; @@ -1431,55 +1506,62 @@ static volOnline(as) * As advertised. *------------------------------------------------------------------------ */ -static volOffline(as) - register struct cmd_syndesc *as; +static int +volOffline(register struct cmd_syndesc *as) { afs_int32 server, partition, volid; - afs_int32 code, err=0; + afs_int32 code, err = 0; afs_int32 transflag, sleeptime, transdone; server = GetServer(as->parms[0].items->data); if (server == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data); + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); return -1; } partition = volutil_GetPartitionID(as->parms[1].items->data); if (partition < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data); + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); return ENOENT; } - volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */ + volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */ if (!volid) { - if (err) PrintError("", err); - else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data); - return -1; + if (err) + PrintError("", err); + else + fprintf(STDERR, "Unknown volume ID or name '%s'\n", + as->parms[0].items->data); + return -1; } transflag = (as->parms[4].items ? ITBusy : ITOffline); sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0); - transdone = (sleeptime ? 0/*online*/ : VTOutOfService); + transdone = (sleeptime ? 0 /*online */ : VTOutOfService); if (as->parms[4].items && !as->parms[3].items) { - fprintf(STDERR,"-sleep option must be used with -busy flag\n"); + fprintf(STDERR, "-sleep option must be used with -busy flag\n"); return -1; } - code = UV_SetVolume(server, partition, volid, transflag, transdone, sleeptime); + code = + UV_SetVolume(server, partition, volid, transflag, transdone, + sleeptime); if (code) { - fprintf(STDERR, "Failed to set volume. Code = %d\n", code); - return -1; + fprintf(STDERR, "Failed to set volume. Code = %d\n", code); + return -1; } return 0; } -static CreateVolume(as) -register struct cmd_syndesc *as; +static int +CreateVolume(register struct cmd_syndesc *as) { - afs_int32 pname; + afs_int32 pnum; char part[10]; - afs_int32 volid,code; + afs_int32 volid, code; struct nvldbentry entry; afs_int32 vcode; afs_int32 quota; @@ -1487,89 +1569,105 @@ register struct cmd_syndesc *as; quota = 5000; tserver = GetServer(as->parms[0].items->data); if (!tserver) { - fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data ); + fprintf(STDERR, "vos: host '%s' not found in host table\n", + as->parms[0].items->data); return ENOENT; } - pname = volutil_GetPartitionID(as->parms[1].items->data); - if (pname < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data ); + pnum = volutil_GetPartitionID(as->parms[1].items->data); + if (pnum < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); return ENOENT; } - if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); + if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); return ENOENT; } - if(!ISNAMEVALID(as->parms[2].items->data)) { - fprintf(STDERR,"vos: the name of the root volume %s exceeds the size limit of %d\n",as->parms[2].items->data,VOLSER_OLDMAXVOLNAME - 10); + if (!ISNAMEVALID(as->parms[2].items->data)) { + fprintf(STDERR, + "vos: the name of the root volume %s exceeds the size limit of %d\n", + as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10); return E2BIG; } - if(!VolNameOK(as->parms[2].items->data)){ - fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[2].items->data); + if (!VolNameOK(as->parms[2].items->data)) { + fprintf(STDERR, + "Illegal volume name %s, should not end in .readonly or .backup\n", + as->parms[2].items->data); return EINVAL; } - if(IsNumeric(as->parms[2].items->data)){ - fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[2].items->data); + if (IsNumeric(as->parms[2].items->data)) { + fprintf(STDERR, "Illegal volume name %s, should not be a number\n", + as->parms[2].items->data); return EINVAL; } vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry); - if(!vcode) { - fprintf(STDERR,"Volume %s already exists\n",as->parms[2].items->data); + if (!vcode) { + fprintf(STDERR, "Volume %s already exists\n", + as->parms[2].items->data); PrintDiagnostics("create", code); return EEXIST; } if (as->parms[3].items) { - if (!IsNumeric(as->parms[3].items->data)){ - fprintf(STDERR,"Initial quota %s should be numeric.\n", as->parms[3].items->data); - return EINVAL; - } - - code = util_GetInt32(as->parms[3].items->data, "a); - if (code) { - fprintf(STDERR,"vos: bad integer specified for quota.\n"); - return code; - } + if (!IsNumeric(as->parms[3].items->data)) { + fprintf(STDERR, "Initial quota %s should be numeric.\n", + as->parms[3].items->data); + return EINVAL; + } + + code = util_GetInt32(as->parms[3].items->data, "a); + if (code) { + fprintf(STDERR, "vos: bad integer specified for quota.\n"); + return code; + } } - code = UV_CreateVolume2(tserver, pname,as->parms[2].items->data, - quota, 0, 0, 0, 0, &volid); + code = + UV_CreateVolume2(tserver, pnum, as->parms[2].items->data, quota, 0, + 0, 0, 0, &volid); if (code) { PrintDiagnostics("create", code); return code; } - MapPartIdIntoName(pname, part); - fprintf(STDOUT,"Volume %u created on partition %s of %s\n", volid, part,as->parms[0].items->data ); + MapPartIdIntoName(pnum, part); + fprintf(STDOUT, "Volume %lu created on partition %s of %s\n", + (unsigned long)volid, part, as->parms[0].items->data); return 0; } -static afs_int32 DeleteAll(entry) -struct nvldbentry *entry; +static afs_int32 +DeleteAll(entry) + struct nvldbentry *entry; { int i; afs_int32 error, code, curserver, curpart, volid; MapHostToNetwork(entry); error = 0; - for(i=0; i < entry->nServers; i++){ + for (i = 0; i < entry->nServers; i++) { curserver = entry->serverNumber[i]; curpart = entry->serverPartition[i]; - if(entry->serverFlags[i] & ITSROVOL){ + if (entry->serverFlags[i] & ITSROVOL) { volid = entry->volumeId[ROVOL]; - } - else{ + } else { volid = entry->volumeId[RWVOL]; } - code = UV_DeleteVolume(curserver,curpart,volid); - if(code && !error) + code = UV_DeleteVolume(curserver, curpart, volid); + if (code && !error) error = code; } return error; } -static DeleteVolume(as) - struct cmd_syndesc *as; +static +DeleteVolume(as) + struct cmd_syndesc *as; { afs_int32 err, code = 0; afs_int32 server = 0, partition = -1, volid; @@ -1577,39 +1675,41 @@ static DeleteVolume(as) afs_int32 idx, j; if (as->parms[0].items) { - server = GetServer(as->parms[0].items->data); - if (!server) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", - as->parms[0].items->data); - return ENOENT; - } + server = GetServer(as->parms[0].items->data); + if (!server) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); + return ENOENT; + } } if (as->parms[1].items) { - partition = volutil_GetPartitionID(as->parms[1].items->data); - if (partition < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", - as->parms[1].items->data ); - return EINVAL; - } - - /* Check for validity of the partition */ - if (!IsPartValid(partition, server, &code)) { - if (code) { - PrintError("", code); - } else { - fprintf(STDERR,"vos : partition %s does not exist on the server\n", - as->parms[1].items->data); - } - return ENOENT; - } + partition = volutil_GetPartitionID(as->parms[1].items->data); + if (partition < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); + return EINVAL; + } + + /* Check for validity of the partition */ + if (!IsPartValid(partition, server, &code)) { + if (code) { + PrintError("", code); + } else { + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); + } + return ENOENT; + } } volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); if (volid == 0) { - fprintf(STDERR, "Can't find volume name '%s' in VLDB\n", + fprintf(STDERR, "Can't find volume name '%s' in VLDB\n", as->parms[2].items->data); - if (err) PrintError("", err); + if (err) + PrintError("", err); return ENOENT; } @@ -1617,265 +1717,759 @@ static DeleteVolume(as) * them in from the VLDB entry. */ if ((partition == -1) || !server) { - struct nvldbentry entry; - - code = VLDB_GetEntryByID(volid, -1, &entry); - if (code) { - fprintf(STDERR,"Could not fetch the entry for volume %u from VLDB\n", - volid); - PrintError("",code); - return (code); - } - - if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS)) || - ((volid == entry.volumeId[BACKVOL]) && (entry.flags & BACK_EXISTS)) ) { - idx = Lp_GetRwIndex(&entry); - if ( (idx == -1) || - (server && (server != entry.serverNumber[idx])) || - ((partition != -1) && (partition != entry.serverPartition[idx])) ) { - fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data); - return ENOENT; - } - } - else if ((volid == entry.volumeId[ROVOL]) && (entry.flags & RO_EXISTS)) { - for (idx=-1,j=0; jparms[2].items->data); - return ENOENT; + struct nvldbentry entry; + + code = VLDB_GetEntryByID(volid, -1, &entry); + if (code) { + fprintf(STDERR, + "Could not fetch the entry for volume %lu from VLDB\n", + (unsigned long)volid); + PrintError("", code); + return (code); + } + + if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS)) + || ((volid == entry.volumeId[BACKVOL]) + && (entry.flags & BACK_EXISTS))) { + idx = Lp_GetRwIndex(&entry); + if ((idx == -1) || (server && (server != entry.serverNumber[idx])) + || ((partition != -1) + && (partition != entry.serverPartition[idx]))) { + fprintf(STDERR, "VLDB: Volume '%s' no match\n", + as->parms[2].items->data); + return ENOENT; + } + } else if ((volid == entry.volumeId[ROVOL]) + && (entry.flags & RO_EXISTS)) { + for (idx = -1, j = 0; j < entry.nServers; j++) { + if (entry.serverFlags[j] != ITSROVOL) + continue; + + if (((server == 0) || (server == entry.serverNumber[j])) + && ((partition == -1) + || (partition == entry.serverPartition[j]))) { + if (idx != -1) { + fprintf(STDERR, + "VLDB: Volume '%s' matches more than one RO\n", + as->parms[2].items->data); + return ENOENT; + } + idx = j; } - idx = j; - } - } - if (idx == -1) { - fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data); - return ENOENT; - } - } - else { - fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data); - return ENOENT; - } + } + if (idx == -1) { + fprintf(STDERR, "VLDB: Volume '%s' no match\n", + as->parms[2].items->data); + return ENOENT; + } + } else { + fprintf(STDERR, "VLDB: Volume '%s' no match\n", + as->parms[2].items->data); + return ENOENT; + } - server = htonl(entry.serverNumber[idx]); - partition = entry.serverPartition[idx]; + server = htonl(entry.serverNumber[idx]); + partition = entry.serverPartition[idx]; } code = UV_DeleteVolume(server, partition, volid); if (code) { - PrintDiagnostics("remove", code); - return code; + PrintDiagnostics("remove", code); + return code; } MapPartIdIntoName(partition, pname); - fprintf(STDOUT,"Volume %u on partition %s server %s deleted\n", - volid, pname, hostutil_GetNameByINet(server)); + fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n", + (unsigned long)volid, pname, hostutil_GetNameByINet(server)); return 0; } -#define TESTM 0 /* set for move space tests, clear for production */ -static MoveVolume(as) -register struct cmd_syndesc *as; +#define TESTM 0 /* set for move space tests, clear for production */ +static +MoveVolume(as) + register struct cmd_syndesc *as; { - - afs_int32 volid, fromserver, toserver, frompart, topart,code, err; + + afs_int32 volid, fromserver, toserver, frompart, topart; + afs_int32 flags, code, err; char fromPartName[10], toPartName[10]; - struct diskPartition partition; /* for space check */ - volintInfo *p; + struct diskPartition partition; /* for space check */ + volintInfo *p; - volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); - if (volid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", + volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); + if (volid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", as->parms[0].items->data); - return ENOENT; - } - fromserver = GetServer(as->parms[1].items->data); - if (fromserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[1].items->data); - return ENOENT; - } - toserver = GetServer(as->parms[3].items->data); - if (toserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[3].items->data); - return ENOENT; + return ENOENT; + } + fromserver = GetServer(as->parms[1].items->data); + if (fromserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[1].items->data); + return ENOENT; + } + toserver = GetServer(as->parms[3].items->data); + if (toserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[3].items->data); + return ENOENT; + } + frompart = volutil_GetPartitionID(as->parms[2].items->data); + if (frompart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[2].items->data); + return EINVAL; + } + if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[2].items->data); + return ENOENT; + } + topart = volutil_GetPartitionID(as->parms[4].items->data); + if (topart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[4].items->data); + return EINVAL; + } + if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[4].items->data); + return ENOENT; + } + + flags = 0; + if (as->parms[5].items) flags |= RV_NOCLONE; + + /* + * check source partition for space to clone volume + */ + + MapPartIdIntoName(topart, toPartName); + MapPartIdIntoName(frompart, fromPartName); + + /* + * check target partition for space to move volume + */ + + code = UV_PartitionInfo(toserver, toPartName, &partition); + if (code) { + fprintf(STDERR, "vos: cannot access partition %s\n", toPartName); + exit(1); + } + if (TESTM) + fprintf(STDOUT, "target partition %s free space %d\n", toPartName, + partition.free); + + p = (volintInfo *) 0; + code = UV_ListOneVolume(fromserver, frompart, volid, &p); + if (code) { + fprintf(STDERR, "vos:cannot access volume %lu\n", + (unsigned long)volid); + free(p); + exit(1); + } + if (TESTM) + fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid, + p->size); + if (partition.free <= p->size) { + fprintf(STDERR, + "vos: no space on target partition %s to move volume %lu\n", + toPartName, (unsigned long)volid); + free(p); + exit(1); + } + free(p); + + if (TESTM) { + fprintf(STDOUT, "size test - don't do move\n"); + exit(0); + } + + /* successful move still not guaranteed but shoot for it */ + + code = + UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags); + if (code) { + PrintDiagnostics("move", code); + return code; + } + MapPartIdIntoName(topart, toPartName); + MapPartIdIntoName(frompart, fromPartName); + fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n", + (unsigned long)volid, as->parms[1].items->data, fromPartName, + as->parms[3].items->data, toPartName); + + return 0; +} + +static +CopyVolume(as) + register struct cmd_syndesc *as; +{ + afs_int32 volid, fromserver, toserver, frompart, topart, code, err, flags; + char fromPartName[10], toPartName[10], *tovolume; + struct nvldbentry entry; + struct diskPartition partition; /* for space check */ + volintInfo *p; + + volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); + if (volid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", + as->parms[0].items->data); + return ENOENT; + } + fromserver = GetServer(as->parms[1].items->data); + if (fromserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[1].items->data); + return ENOENT; + } + + toserver = GetServer(as->parms[4].items->data); + if (toserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[4].items->data); + return ENOENT; + } + + tovolume = as->parms[3].items->data; + if (!ISNAMEVALID(tovolume)) { + fprintf(STDERR, + "vos: the name of the root volume %s exceeds the size limit of %d\n", + tovolume, VOLSER_OLDMAXVOLNAME - 10); + return E2BIG; + } + if (!VolNameOK(tovolume)) { + fprintf(STDERR, + "Illegal volume name %s, should not end in .readonly or .backup\n", + tovolume); + return EINVAL; + } + if (IsNumeric(tovolume)) { + fprintf(STDERR, "Illegal volume name %s, should not be a number\n", + tovolume); + return EINVAL; + } + code = VLDB_GetEntryByName(tovolume, &entry); + if (!code) { + fprintf(STDERR, "Volume %s already exists\n", tovolume); + PrintDiagnostics("copy", code); + return EEXIST; + } + + frompart = volutil_GetPartitionID(as->parms[2].items->data); + if (frompart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[2].items->data); + return EINVAL; + } + if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[2].items->data); + return ENOENT; + } + + topart = volutil_GetPartitionID(as->parms[5].items->data); + if (topart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[5].items->data); + return EINVAL; + } + if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[5].items->data); + return ENOENT; + } + + flags = 0; + if (as->parms[6].items) flags |= RV_OFFLINE; + if (as->parms[7].items) flags |= RV_RDONLY; + if (as->parms[8].items) flags |= RV_NOCLONE; + + MapPartIdIntoName(topart, toPartName); + MapPartIdIntoName(frompart, fromPartName); + + /* + * check target partition for space to move volume + */ + + code = UV_PartitionInfo(toserver, toPartName, &partition); + if (code) { + fprintf(STDERR, "vos: cannot access partition %s\n", toPartName); + exit(1); + } + if (TESTM) + fprintf(STDOUT, "target partition %s free space %d\n", toPartName, + partition.free); + + p = (volintInfo *) 0; + code = UV_ListOneVolume(fromserver, frompart, volid, &p); + if (code) { + fprintf(STDERR, "vos:cannot access volume %lu\n", + (unsigned long)volid); + free(p); + exit(1); + } + + if (partition.free <= p->size) { + fprintf(STDERR, + "vos: no space on target partition %s to copy volume %lu\n", + toPartName, (unsigned long)volid); + free(p); + exit(1); + } + free(p); + + /* successful copy still not guaranteed but shoot for it */ + + code = + UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver, + topart, 0, flags); + if (code) { + PrintDiagnostics("copy", code); + return code; + } + MapPartIdIntoName(topart, toPartName); + MapPartIdIntoName(frompart, fromPartName); + fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n", + (unsigned long)volid, as->parms[1].items->data, fromPartName, + tovolume, as->parms[4].items->data, toPartName); + + return 0; +} + + +static +ShadowVolume(as) + register struct cmd_syndesc *as; +{ + afs_int32 volid, fromserver, toserver, frompart, topart, tovolid; + afs_int32 code, err, flags; + char fromPartName[10], toPartName[10], toVolName[32], *tovolume; + struct nvldbentry entry; + struct diskPartition partition; /* for space check */ + volintInfo *p, *q; + + p = (volintInfo *) 0; + q = (volintInfo *) 0; + + volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); + if (volid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", + as->parms[0].items->data); + return ENOENT; + } + fromserver = GetServer(as->parms[1].items->data); + if (fromserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[1].items->data); + return ENOENT; + } + + toserver = GetServer(as->parms[3].items->data); + if (toserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[3].items->data); + return ENOENT; + } + + frompart = volutil_GetPartitionID(as->parms[2].items->data); + if (frompart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[2].items->data); + return EINVAL; + } + if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[2].items->data); + return ENOENT; + } + + topart = volutil_GetPartitionID(as->parms[4].items->data); + if (topart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[4].items->data); + return EINVAL; + } + if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[4].items->data); + return ENOENT; + } + + if (as->parms[5].items) { + tovolume = as->parms[5].items->data; + if (!ISNAMEVALID(tovolume)) { + fprintf(STDERR, + "vos: the name of the root volume %s exceeds the size limit of %d\n", + tovolume, VOLSER_OLDMAXVOLNAME - 10); + return E2BIG; } - frompart = volutil_GetPartitionID(as->parms[2].items->data); - if (frompart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data); + if (!VolNameOK(tovolume)) { + fprintf(STDERR, + "Illegal volume name %s, should not end in .readonly or .backup\n", + tovolume); return EINVAL; } - if (!IsPartValid(frompart,fromserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[2].items->data); - return ENOENT; - } - topart = volutil_GetPartitionID(as->parms[4].items->data); - if (topart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[4].items->data); + if (IsNumeric(tovolume)) { + fprintf(STDERR, + "Illegal volume name %s, should not be a number\n", + tovolume); return EINVAL; } - if (!IsPartValid(topart,toserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[4].items->data); - return ENOENT; - } - - /* - check source partition for space to clone volume - */ - - MapPartIdIntoName(topart,toPartName); - MapPartIdIntoName(frompart, fromPartName); - - /* - check target partition for space to move volume - */ - - code=UV_PartitionInfo(toserver,toPartName,&partition); - if(code) - { - fprintf(STDERR,"vos: cannot access partition %s\n",toPartName); - exit(1); + } else { + /* use actual name of source volume */ + code = UV_ListOneVolume(fromserver, frompart, volid, &p); + if (code) { + fprintf(STDERR, "vos:cannot access volume %lu\n", + (unsigned long)volid); + exit(1); } - if(TESTM) - fprintf(STDOUT,"target partition %s free space %d\n", - toPartName,partition.free); + strcpy(toVolName, p->name); + tovolume = toVolName; + /* save p for size checks later */ + } - p=(volintInfo *)0; - code=UV_ListOneVolume(fromserver,frompart,volid,&p); - if(code) - { - fprintf(STDERR,"vos:cannot access volume %u\n",volid); + if (as->parms[6].items) { + tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err); + if (tovolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", + as->parms[6].items->data); + if (p) free(p); - exit(1); + return ENOENT; } - if(TESTM) - fprintf(STDOUT,"volume %u size %d\n",volid,p->size); - if(partition.free<=p->size) - { - fprintf(STDERR,"vos: no space on target partition %s to move volume %u\n", - toPartName,volid); + } else { + tovolid = vsu_GetVolumeID(tovolume, cstruct, &err); + if (tovolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", + tovolume); + if (p) free(p); - exit(1); + return ENOENT; } - free(p); + } - if(TESTM) - { - fprintf(STDOUT,"size test - don't do move\n"); - exit(0); - } + flags = RV_NOVLDB; + if (as->parms[7].items) flags |= RV_OFFLINE; + if (as->parms[8].items) flags |= RV_RDONLY; + if (as->parms[9].items) flags |= RV_NOCLONE; + if (as->parms[10].items) flags |= RV_CPINCR; + + MapPartIdIntoName(topart, toPartName); + MapPartIdIntoName(frompart, fromPartName); + + /* + * check target partition for space to move volume + */ - /* successful move still not guaranteed but shoot for it */ + code = UV_PartitionInfo(toserver, toPartName, &partition); + if (code) { + fprintf(STDERR, "vos: cannot access partition %s\n", toPartName); + exit(1); + } + if (TESTM) + fprintf(STDOUT, "target partition %s free space %d\n", toPartName, + partition.free); - code = UV_MoveVolume(volid, fromserver, frompart, toserver, topart); + /* Don't do this again if we did it above */ + if (!p) { + code = UV_ListOneVolume(fromserver, frompart, volid, &p); if (code) { - PrintDiagnostics("move", code); - return code; + fprintf(STDERR, "vos:cannot access volume %lu\n", + (unsigned long)volid); + exit(1); } - MapPartIdIntoName(topart,toPartName); - MapPartIdIntoName(frompart, fromPartName); - fprintf(STDOUT,"Volume %u moved from %s %s to %s %s \n",volid,as->parms[1].items->data,fromPartName,as->parms[3].items->data,toPartName); + } + + /* OK if this fails */ + code = UV_ListOneVolume(toserver, topart, tovolid, &q); + + /* Treat existing volume size as "free" */ + if (q) + p->size = (q->size < p->size) ? p->size - q->size : 0; + + if (partition.free <= p->size) { + fprintf(STDERR, + "vos: no space on target partition %s to copy volume %lu\n", + toPartName, (unsigned long)volid); + free(p); + if (q) free(q); + exit(1); + } + free(p); + if (q) free(q); + + /* successful copy still not guaranteed but shoot for it */ + + code = + UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver, + topart, tovolid, flags); + if (code) { + PrintDiagnostics("shadow", code); + return code; + } + MapPartIdIntoName(topart, toPartName); + MapPartIdIntoName(frompart, fromPartName); + fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n", + (unsigned long)volid, as->parms[1].items->data, fromPartName, + as->parms[4].items->data, toPartName); return 0; } -static BackupVolume(as) -register struct cmd_syndesc *as; + + +static +CloneVolume(as) + register struct cmd_syndesc *as; { - afs_int32 avolid, aserver, apart,vtype,code, err; - struct nvldbentry entry; - - afs_int32 buvolid,buserver,bupart,butype; - struct nvldbentry buentry; - struct rx_connection *conn; - volEntries volInfo; - struct nvldbentry store; - - avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); - if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", + afs_int32 server, part, volid, cloneid, voltype; + char partName[10], *volname; + afs_int32 code, err, flags; + struct nvldbentry entry; + + volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); + if (volid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", as->parms[0].items->data); + return ENOENT; + } + + if (as->parms[1].items || as->parms[2].items) { + if (!as->parms[1].items || !as->parms[2].items) { + fprintf(STDERR, + "Must specify both -server and -partition options\n"); + return -1; + } + server = GetServer(as->parms[1].items->data); + if (server == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[1].items->data); return ENOENT; } - code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry); - if(code) exit(1); + part = volutil_GetPartitionID(as->parms[2].items->data); + if (part < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[2].items->data); + return EINVAL; + } + if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[2].items->data); + return ENOENT; + } + } else { + code = GetVolumeInfo(volid, &server, &part, &voltype, &entry); + if (code) + return code; + } - /* verify this is a readwrite volume */ + volname = 0; + if (as->parms[3].items) { + volname = as->parms[3].items->data; + if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) { + fprintf(STDERR, + "vos: the name of the root volume %s exceeds the size limit of %d\n", + volname, VOLSER_OLDMAXVOLNAME - 1); + return E2BIG; + } + if (!VolNameOK(volname)) { + fprintf(STDERR, + "Illegal volume name %s, should not end in .readonly or .backup\n", + volname); + return EINVAL; + } + if (IsNumeric(volname)) { + fprintf(STDERR, + "Illegal volume name %s, should not be a number\n", + volname); + return EINVAL; + } + } - if(vtype != RWVOL) - { - fprintf(STDERR,"%s not RW volume\n",as->parms[0].items->data); - exit(1); + cloneid = 0; + if (as->parms[4].items) { + cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err); + if (cloneid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", + as->parms[4].items->data); + return ENOENT; } + } - /* is there a backup volume already? */ + flags = 0; + if (as->parms[5].items) flags |= RV_OFFLINE; + if (as->parms[6].items) flags |= RV_RDONLY; - if(entry.flags & BACK_EXISTS) - { - /* yep, where is it? */ - buvolid=entry.volumeId[BACKVOL]; - code=GetVolumeInfo(buvolid,&buserver,&bupart,&butype,&buentry); - if(code) exit(1); + code = + UV_CloneVolume(server, part, volid, cloneid, volname, flags); - /* is it local? */ - code = VLDB_IsSameAddrs(buserver, aserver, &err); - if (err) { - fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver; aborting call!\n", buserver); - exit(1); - } - if (!code) - { - fprintf(STDERR,"FATAL ERROR: backup volume %u exists on server %u\n", - buvolid,buserver); - exit(1); - } - } + if (code) { + PrintDiagnostics("clone", code); + return code; + } + MapPartIdIntoName(part, partName); + fprintf(STDOUT, "Created clone for volume %lu\n", + as->parms[0].items->data); - /* nope, carry on */ + return 0; +} - code = UV_BackupVolume(aserver, apart, avolid); - if (code) { - PrintDiagnostics("backup", code); - return code; +static +BackupVolume(as) + register struct cmd_syndesc *as; +{ + afs_int32 avolid, aserver, apart, vtype, code, err; + struct nvldbentry entry; + + afs_int32 buvolid, buserver, bupart, butype; + struct nvldbentry buentry; + + avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume ID or name '%s'\n", + as->parms[0].items->data); + return ENOENT; + } + code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry); + if (code) + exit(1); + + /* verify this is a readwrite volume */ + + if (vtype != RWVOL) { + fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data); + exit(1); + } + + /* is there a backup volume already? */ + + if (entry.flags & BACK_EXISTS) { + /* yep, where is it? */ + + buvolid = entry.volumeId[BACKVOL]; + code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry); + if (code) + exit(1); + + /* is it local? */ + code = VLDB_IsSameAddrs(buserver, aserver, &err); + if (err) { + fprintf(STDERR, + "Failed to get info about server's %d address(es) from vlserver; aborting call!\n", + buserver); + exit(1); } - fprintf(STDOUT,"Created backup volume for %s \n",as->parms[0].items->data); - return 0; + if (!code) { + fprintf(STDERR, + "FATAL ERROR: backup volume %lu exists on server %lu\n", + (unsigned long)buvolid, (unsigned long)buserver); + exit(1); + } + } + + /* nope, carry on */ + + code = UV_BackupVolume(aserver, apart, avolid); + + if (code) { + PrintDiagnostics("backup", code); + return code; + } + fprintf(STDOUT, "Created backup volume for %s \n", + as->parms[0].items->data); + return 0; } -static ReleaseVolume(as) -register struct cmd_syndesc *as; + +static +ReleaseVolume(as) + register struct cmd_syndesc *as; { struct nvldbentry entry; - afs_int32 avolid, aserver, apart,vtype,code, err; + afs_int32 avolid, aserver, apart, vtype, code, err; int force = 0; - if(as->parms[1].items) force = 1; + if (as->parms[1].items) + force = 1; avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data); + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[0].items->data); return ENOENT; } - code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry); - if(code) return code; + code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry); + if (code) + return code; if (vtype != RWVOL) { - fprintf(STDERR,"%s not a RW volume\n", as->parms[0].items->data); - return(ENOENT); + fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data); + return (ENOENT); } - if(!ISNAMEVALID(entry.name)){ - fprintf(STDERR,"Volume name %s is too long, rename before releasing\n",entry.name); + if (!ISNAMEVALID(entry.name)) { + fprintf(STDERR, + "Volume name %s is too long, rename before releasing\n", + entry.name); return E2BIG; } @@ -1884,76 +2478,96 @@ register struct cmd_syndesc *as; PrintDiagnostics("release", code); return code; } - fprintf(STDOUT,"Released volume %s successfully\n",as->parms[0].items->data ); + fprintf(STDOUT, "Released volume %s successfully\n", + as->parms[0].items->data); return 0; } -static DumpVolume(as) -register struct cmd_syndesc *as; -{ - afs_int32 avolid, aserver, apart,voltype,fromdate=0,code, err, i; - char filename[NameLen]; - struct nvldbentry entry; +static +DumpVolume(as) + register struct cmd_syndesc *as; - rx_SetRxDeadTime(60 * 10); - for (i = 0; iservice) rxConn->service->connDeadTime = rx_connDeadTime; - } +{ + afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i; + char filename[NameLen]; + struct nvldbentry entry; - avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); - if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data); - return ENOENT; - } + rx_SetRxDeadTime(60 * 10); + for (i = 0; i < MAXSERVERS; i++) { + struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i); + if (rxConn == 0) + break; + rx_SetConnDeadTime(rxConn, rx_connDeadTime); + if (rxConn->service) + rxConn->service->connDeadTime = rx_connDeadTime; + } - if (as->parms[3].items || as->parms[4].items) { - if (!as->parms[3].items || !as->parms[4].items) { - fprintf(STDERR, "Must specify both -server and -partition options\n"); - return -1; - } - aserver = GetServer(as->parms[3].items->data); - if (aserver == 0) { - fprintf(STDERR, "Invalid server name\n"); - return -1; - } - apart = volutil_GetPartitionID(as->parms[4].items->data); - if (apart < 0) { - fprintf(STDERR, "Invalid partition name\n"); - return -1; - } - } else { - code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry); - if (code) return code; - } + avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[0].items->data); + return ENOENT; + } - if (as->parms[1].items && strcmp(as->parms[1].items->data,"0")) { - code = ktime_DateToInt32(as->parms[1].items->data, &fromdate); - if (code) { - fprintf(STDERR,"vos: failed to parse date '%s' (error=%d))\n", - as->parms[1].items->data, code); - return code; - } + if (as->parms[3].items || as->parms[4].items) { + if (!as->parms[3].items || !as->parms[4].items) { + fprintf(STDERR, + "Must specify both -server and -partition options\n"); + return -1; } - if(as->parms[2].items){ - strcpy(filename,as->parms[2].items->data); + aserver = GetServer(as->parms[3].items->data); + if (aserver == 0) { + fprintf(STDERR, "Invalid server name\n"); + return -1; } - else{ - strcpy(filename,""); + apart = volutil_GetPartitionID(as->parms[4].items->data); + if (apart < 0) { + fprintf(STDERR, "Invalid partition name\n"); + return -1; } - code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, filename); + } else { + code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry); + if (code) + return code; + } + + if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) { + code = ktime_DateToInt32(as->parms[1].items->data, &fromdate); if (code) { - PrintDiagnostics("dump", code); + fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n", + as->parms[1].items->data, code); return code; } - if(strcmp(filename,"")) - fprintf(STDERR,"Dumped volume %s in file %s\n",as->parms[0].items->data, filename); - else - fprintf(STDERR,"Dumped volume %s in stdout \n",as->parms[0].items->data); - return 0; + } + if (as->parms[2].items) { + strcpy(filename, as->parms[2].items->data); + } else { + strcpy(filename, ""); + } + + if (as->parms[5].items) { + code = + UV_DumpClonedVolume(avolid, aserver, apart, fromdate, + DumpFunction, filename); + } else { + code = + UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, + filename); + } + if (code) { + PrintDiagnostics("dump", code); + return code; + } + if (strcmp(filename, "")) + fprintf(STDERR, "Dumped volume %s in file %s\n", + as->parms[0].items->data, filename); + else + fprintf(STDERR, "Dumped volume %s in stdout \n", + as->parms[0].items->data); + return 0; } #define ASK 0 @@ -1961,286 +2575,334 @@ register struct cmd_syndesc *as; #define FULL 2 #define INC 3 -static RestoreVolume(as) -register struct cmd_syndesc *as; +static +RestoreVolume(as) + register struct cmd_syndesc *as; -{ - afs_int32 avolid, aserver, apart, code,vcode, err; - afs_int32 aoverwrite = ASK; - int restoreflags, readonly = 0, offline = 0, voltype = RWVOL; - char prompt; - char afilename[NameLen], avolname[VOLSER_MAXVOLNAME +1],apartName[10]; - char volname[VOLSER_MAXVOLNAME +1]; - struct nvldbentry entry; - - prompt = 'n'; - - if(as->parms[4].items){ - avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err); - if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[4].items->data); - exit(1); - } - } - else - avolid = 0; +{ + afs_int32 avolid, aserver, apart, code, vcode, err; + afs_int32 aoverwrite = ASK; + int restoreflags, readonly = 0, offline = 0, voltype = RWVOL; + char prompt; + char afilename[NameLen], avolname[VOLSER_MAXVOLNAME + 1], apartName[10]; + char volname[VOLSER_MAXVOLNAME + 1]; + struct nvldbentry entry; - if (as->parms[5].items) { - if ( (strcmp(as->parms[5].items->data, "a") == 0) || - (strcmp(as->parms[5].items->data, "abort") == 0) ) { - aoverwrite = ABORT; - } - else if ( (strcmp(as->parms[5].items->data, "f") == 0) || - (strcmp(as->parms[5].items->data, "full") == 0) ) { - aoverwrite = FULL; - } - else if ( (strcmp(as->parms[5].items->data, "i") == 0) || - (strcmp(as->parms[5].items->data, "inc") == 0) || - (strcmp(as->parms[5].items->data, "increment") == 0) || - (strcmp(as->parms[5].items->data, "incremental") == 0) ) { - aoverwrite = INC; - } - else { - fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n", - as->parms[5].items->data); - exit(1); - } - } - if (as->parms[6].items) offline = 1; - if (as->parms[7].items) { - readonly = 1; - voltype = ROVOL; - } + prompt = 'n'; - aserver = GetServer(as->parms[0].items->data); - if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data); - exit(1); - } - apart = volutil_GetPartitionID(as->parms[1].items->data); - if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data ); - exit(1); - } - if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); + if (as->parms[4].items) { + avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[4].items->data); exit(1); } - strcpy(avolname,as->parms[2].items->data ); - if(!ISNAMEVALID(avolname)) { - fprintf(STDERR,"vos: the name of the volume %s exceeds the size limit\n",avolname); + } else + avolid = 0; + + if (as->parms[5].items) { + if ((strcmp(as->parms[5].items->data, "a") == 0) + || (strcmp(as->parms[5].items->data, "abort") == 0)) { + aoverwrite = ABORT; + } else if ((strcmp(as->parms[5].items->data, "f") == 0) + || (strcmp(as->parms[5].items->data, "full") == 0)) { + aoverwrite = FULL; + } else if ((strcmp(as->parms[5].items->data, "i") == 0) + || (strcmp(as->parms[5].items->data, "inc") == 0) + || (strcmp(as->parms[5].items->data, "increment") == 0) + || (strcmp(as->parms[5].items->data, "incremental") == 0)) { + aoverwrite = INC; + } else { + fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n", + as->parms[5].items->data); exit(1); } - if(!VolNameOK(avolname)){ - fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",avolname); + } + if (as->parms[6].items) + offline = 1; + if (as->parms[7].items) { + readonly = 1; + voltype = ROVOL; + } + + aserver = GetServer(as->parms[0].items->data); + if (aserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); + exit(1); + } + apart = volutil_GetPartitionID(as->parms[1].items->data); + if (apart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); + exit(1); + } + if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); + exit(1); + } + strcpy(avolname, as->parms[2].items->data); + if (!ISNAMEVALID(avolname)) { + fprintf(STDERR, + "vos: the name of the volume %s exceeds the size limit\n", + avolname); + exit(1); + } + if (!VolNameOK(avolname)) { + fprintf(STDERR, + "Illegal volume name %s, should not end in .readonly or .backup\n", + avolname); + exit(1); + } + if (as->parms[3].items) { + strcpy(afilename, as->parms[3].items->data); + if (!FileExists(afilename)) { + fprintf(STDERR, "Can't access file %s\n", afilename); exit(1); } - if(as->parms[3].items){ - strcpy(afilename,as->parms[3].items->data ); - if(!FileExists(afilename)){ - fprintf(STDERR,"Can't access file %s\n",afilename); - exit(1); - } - } - else { - strcpy(afilename,""); - } + } else { + strcpy(afilename, ""); + } - /* Check if volume exists or not */ + /* Check if volume exists or not */ - vsu_ExtractName(volname,avolname); - vcode = VLDB_GetEntryByName(volname, &entry); - if (vcode) { /* no volume - do a full restore */ - restoreflags = RV_FULLRST; - if ( (aoverwrite == INC) || (aoverwrite == ABORT) ) - fprintf(STDERR,"Volume does not exist; Will perform a full restore\n"); + vsu_ExtractName(volname, avolname); + vcode = VLDB_GetEntryByName(volname, &entry); + if (vcode) { /* no volume - do a full restore */ + restoreflags = RV_FULLRST; + if ((aoverwrite == INC) || (aoverwrite == ABORT)) + fprintf(STDERR, + "Volume does not exist; Will perform a full restore\n"); + } + + else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */ + ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */ + restoreflags = RV_FULLRST; + if ((aoverwrite == INC) || (aoverwrite == ABORT)) + fprintf(STDERR, + "%s Volume does not exist; Will perform a full restore\n", + readonly ? "RO" : "RW"); + + if (avolid == 0) { + avolid = entry.volumeId[voltype]; + } else if (entry.volumeId[voltype] != 0 + && entry.volumeId[voltype] != avolid) { + avolid = entry.volumeId[voltype]; } + } - else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */ - || (readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */ - restoreflags = RV_FULLRST; - if ( (aoverwrite == INC) || (aoverwrite == ABORT) ) - fprintf(STDERR,"%s Volume does not exist; Will perform a full restore\n", - readonly ? "RO" : "RW"); + else { /* volume exists - do we do a full incremental or abort */ + int Oserver, Opart, Otype, vol_elsewhere = 0; + struct nvldbentry Oentry; + int c, dc; - if (avolid == 0) { - avolid = entry.volumeId[voltype]; - } - else if (entry.volumeId[voltype] != 0 && entry.volumeId[voltype] != avolid) { - avolid = entry.volumeId[voltype]; - } + if (avolid == 0) { + avolid = entry.volumeId[voltype]; + } else if (entry.volumeId[voltype] != 0 + && entry.volumeId[voltype] != avolid) { + avolid = entry.volumeId[voltype]; } - else { /* volume exists - do we do a full incremental or abort */ - int Oserver, Opart, Otype, vol_elsewhere = 0; - struct nvldbentry Oentry; - int c, dc; + /* A file name was specified - check if volume is on another partition */ + vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry); + if (vcode) + exit(1); - if(avolid == 0) { - avolid = entry.volumeId[voltype]; - } - else if(entry.volumeId[voltype] != 0 && entry.volumeId[voltype] != avolid) { - avolid = entry.volumeId[voltype]; - } - - /* A file name was specified - check if volume is on another partition */ - vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry); - if (vcode) exit(1); - - vcode = VLDB_IsSameAddrs(Oserver, aserver, &err); - if (err) { - fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", - Oserver, err); + vcode = VLDB_IsSameAddrs(Oserver, aserver, &err); + if (err) { + fprintf(STDERR, + "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", + Oserver, err); + exit(1); + } + if (!vcode || (Opart != apart)) + vol_elsewhere = 1; + + if (aoverwrite == ASK) { + if (strcmp(afilename, "") == 0) { /* The file is from standard in */ + fprintf(STDERR, + "Volume exists and no -overwrite option specified; Aborting restore command\n"); exit(1); } - if (!vcode || (Opart != apart)) vol_elsewhere = 1; - if (aoverwrite == ASK) { - if (strcmp(afilename,"") == 0) { /* The file is from standard in */ - fprintf(STDERR,"Volume exists and no -overwrite option specified; Aborting restore command\n"); - exit(1); - } - - /* Ask what to do */ - if (vol_elsewhere) { - fprintf(STDERR,"The volume %s %u already exists on a different server/part\n", - volname, entry.volumeId[voltype]); - fprintf(STDERR, - "Do you want to do a full restore or abort? [fa](a): "); - } - else - { - fprintf(STDERR,"The volume %s %u already exists in the VLDB\n", - volname, entry.volumeId[voltype]); - fprintf(STDERR, - "Do you want to do a full/incremental restore or abort? [fia](a): "); - } - dc = c = getchar(); - while (!(dc==EOF || dc=='\n')) dc=getchar(); /* goto end of line */ - if ((c == 'f') || (c == 'F')) aoverwrite = FULL; - else if ((c == 'i') || (c == 'I')) aoverwrite = INC; - else aoverwrite = ABORT; + /* Ask what to do */ + if (vol_elsewhere) { + fprintf(STDERR, + "The volume %s %u already exists on a different server/part\n", + volname, entry.volumeId[voltype]); + fprintf(STDERR, + "Do you want to do a full restore or abort? [fa](a): "); + } else { + fprintf(STDERR, + "The volume %s %u already exists in the VLDB\n", + volname, entry.volumeId[voltype]); + fprintf(STDERR, + "Do you want to do a full/incremental restore or abort? [fia](a): "); } + dc = c = getchar(); + while (!(dc == EOF || dc == '\n')) + dc = getchar(); /* goto end of line */ + if ((c == 'f') || (c == 'F')) + aoverwrite = FULL; + else if ((c == 'i') || (c == 'I')) + aoverwrite = INC; + else + aoverwrite = ABORT; + } - if (aoverwrite == ABORT) { - fprintf(STDERR,"Volume exists; Aborting restore command\n"); + if (aoverwrite == ABORT) { + fprintf(STDERR, "Volume exists; Aborting restore command\n"); + exit(1); + } else if (aoverwrite == FULL) { + restoreflags = RV_FULLRST; + fprintf(STDERR, + "Volume exists; Will delete and perform full restore\n"); + } else if (aoverwrite == INC) { + restoreflags = 0; + if (vol_elsewhere) { + fprintf(STDERR, + "%s volume %lu already exists on a different server/part; not allowed\n", + readonly ? "RO" : "RW", (unsigned long)avolid); exit(1); } - else if (aoverwrite == FULL) { - restoreflags = RV_FULLRST; - fprintf(STDERR,"Volume exists; Will delete and perform full restore\n"); - } - else if (aoverwrite == INC) { - restoreflags = 0; - if (vol_elsewhere) { - fprintf(STDERR, - "%s volume %u already exists on a different server/part; not allowed\n", - readonly ? "RO" : "RW", avolid); - exit(1); - } - } - } - if (offline) restoreflags |= RV_OFFLINE; - if (readonly) restoreflags |= RV_RDONLY; - code = UV_RestoreVolume(aserver, apart, avolid, avolname, - restoreflags, WriteData, afilename); - if (code) { - PrintDiagnostics("restore", code); - exit(1); } - MapPartIdIntoName(apart,apartName); + } + if (offline) + restoreflags |= RV_OFFLINE; + if (readonly) + restoreflags |= RV_RDONLY; + code = + UV_RestoreVolume(aserver, apart, avolid, avolname, restoreflags, + WriteData, afilename); + if (code) { + PrintDiagnostics("restore", code); + exit(1); + } + MapPartIdIntoName(apart, apartName); - /* - patch typo here - originally "parms[1]", should be "parms[0]" - */ + /* + * patch typo here - originally "parms[1]", should be "parms[0]" + */ - fprintf(STDOUT,"Restored volume %s on %s %s\n", - avolname, as->parms[0].items->data, apartName); - return 0; + fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname, + as->parms[0].items->data, apartName); + return 0; } -static LockReleaseCmd(as) -register struct cmd_syndesc *as; + +static +LockReleaseCmd(as) + register struct cmd_syndesc *as; { - afs_int32 avolid,code, err; + afs_int32 avolid, code, err; - avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); - if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data); - exit(1); - } - - code = UV_LockRelease(avolid); - if (code) { - PrintDiagnostics("unlock", code); - exit(1); - } - fprintf(STDOUT,"Released lock on vldb entry for volume %s\n",as->parms[0].items->data); + avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[0].items->data); + exit(1); + } + + code = UV_LockRelease(avolid); + if (code) { + PrintDiagnostics("unlock", code); + exit(1); + } + fprintf(STDOUT, "Released lock on vldb entry for volume %s\n", + as->parms[0].items->data); return 0; } -static AddSite(as) -register struct cmd_syndesc *as; + +static +AddSite(as) + register struct cmd_syndesc *as; { - afs_int32 avolid, aserver, apart,code, err; - char apartName[10]; + afs_int32 avolid, aserver, apart, code, err; + char apartName[10], avolname[VOLSER_MAXVOLNAME + 1]; - avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); - if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data); - exit(1); - } - aserver = GetServer(as->parms[0].items->data); - if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data); - exit(1); - } - apart = volutil_GetPartitionID(as->parms[1].items->data); - if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data ); - exit(1); - } - if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); - exit(1); - } - code = UV_AddSite(aserver, apart, avolid); - if (code) { - PrintDiagnostics("addsite", code); - exit(1); - } - MapPartIdIntoName(apart,apartName); - fprintf(STDOUT,"Added replication site %s %s for volume %s\n",as->parms[0].items->data, apartName,as->parms[2].items->data); - return 0; + vsu_ExtractName(avolname, as->parms[2].items->data);; + avolid = vsu_GetVolumeID(avolname, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[2].items->data); + exit(1); + } + aserver = GetServer(as->parms[0].items->data); + if (aserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); + exit(1); + } + apart = volutil_GetPartitionID(as->parms[1].items->data); + if (apart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); + exit(1); + } + if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); + exit(1); + } + code = UV_AddSite(aserver, apart, avolid); + if (code) { + PrintDiagnostics("addsite", code); + exit(1); + } + MapPartIdIntoName(apart, apartName); + fprintf(STDOUT, "Added replication site %s %s for volume %s\n", + as->parms[0].items->data, apartName, as->parms[2].items->data); + return 0; } -static RemoveSite(as) -register struct cmd_syndesc *as; -{ +static +RemoveSite(as) + register struct cmd_syndesc *as; +{ afs_int32 avolid, aserver, apart, code, err; - char apartName[10]; + char apartName[10], avolname[VOLSER_MAXVOLNAME + 1]; - avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); - if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data); - exit(1); - } - aserver = GetServer(as->parms[0].items->data); - if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data); - exit(1); - } - apart = volutil_GetPartitionID(as->parms[1].items->data); - if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data ); - exit(1); - } + vsu_ExtractName(avolname, as->parms[2].items->data); + avolid = vsu_GetVolumeID(avolname, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[2].items->data); + exit(1); + } + aserver = GetServer(as->parms[0].items->data); + if (aserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); + exit(1); + } + apart = volutil_GetPartitionID(as->parms[1].items->data); + if (apart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); + exit(1); + } /* *skip the partition validity check, since it is possible that the partition *has since been decomissioned. @@ -2252,56 +2914,70 @@ register struct cmd_syndesc *as; exit(1); } */ - code = UV_RemoveSite(aserver, apart, avolid); - if (code) { - PrintDiagnostics("remsite", code); - exit(1); - } - MapPartIdIntoName(apart,apartName); - fprintf(STDOUT,"Removed replication site %s %s for volume %s\n",as->parms[0].items->data,apartName,as->parms[2].items->data); + code = UV_RemoveSite(aserver, apart, avolid); + if (code) { + PrintDiagnostics("remsite", code); + exit(1); + } + MapPartIdIntoName(apart, apartName); + fprintf(STDOUT, "Removed replication site %s %s for volume %s\n", + as->parms[0].items->data, apartName, as->parms[2].items->data); return 0; } -static ChangeLocation(as) -register struct cmd_syndesc *as; + +static +ChangeLocation(as) + register struct cmd_syndesc *as; { - afs_int32 avolid, aserver, apart,code, err; - char apartName[10]; + afs_int32 avolid, aserver, apart, code, err; + char apartName[10]; - avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); - if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data); - exit(1); - } - aserver = GetServer(as->parms[0].items->data); - if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data); - exit(1); - } - apart = volutil_GetPartitionID(as->parms[1].items->data); - if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data ); - exit(1); - } - if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); - exit(1); - } - code = UV_ChangeLocation(aserver, apart, avolid); - if (code) { - PrintDiagnostics("addsite", code); - exit(1); - } - MapPartIdIntoName(apart,apartName); - fprintf(STDOUT,"Changed location to %s %s for volume %s\n",as->parms[0].items->data, apartName,as->parms[2].items->data); - return 0; + avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[2].items->data); + exit(1); + } + aserver = GetServer(as->parms[0].items->data); + if (aserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); + exit(1); + } + apart = volutil_GetPartitionID(as->parms[1].items->data); + if (apart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); + exit(1); + } + if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); + exit(1); + } + code = UV_ChangeLocation(aserver, apart, avolid); + if (code) { + PrintDiagnostics("addsite", code); + exit(1); + } + MapPartIdIntoName(apart, apartName); + fprintf(STDOUT, "Changed location to %s %s for volume %s\n", + as->parms[0].items->data, apartName, as->parms[2].items->data); + return 0; } -static ListPartitions(as) -register struct cmd_syndesc *as; +static +ListPartitions(as) + register struct cmd_syndesc *as; { - afs_int32 aserver,code; + afs_int32 aserver, code; struct partList dummyPartList; int i; char pname[10]; @@ -2309,42 +2985,45 @@ register struct cmd_syndesc *as; aserver = GetServer(as->parms[0].items->data); if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data); + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); exit(1); } - code = UV_ListPartitions(aserver,&dummyPartList, &cnt); + code = UV_ListPartitions(aserver, &dummyPartList, &cnt); if (code) { PrintDiagnostics("listpart", code); exit(1); } total = 0; - fprintf(STDOUT,"The partitions on the server are:\n"); - for(i = 0 ; i < cnt ; i++){ - if(dummyPartList.partFlags[i] & PARTVALID){ + fprintf(STDOUT, "The partitions on the server are:\n"); + for (i = 0; i < cnt; i++) { + if (dummyPartList.partFlags[i] & PARTVALID) { memset(pname, 0, sizeof(pname)); - MapPartIdIntoName(dummyPartList.partId[i],pname); - fprintf(STDOUT," %10s ",pname); + MapPartIdIntoName(dummyPartList.partId[i], pname); + fprintf(STDOUT, " %10s ", pname); total++; - if( (i % 5) == 0 && (i != 0)) fprintf(STDOUT,"\n"); + if ((i % 5) == 0 && (i != 0)) + fprintf(STDOUT, "\n"); } } - fprintf(STDOUT,"\n"); - fprintf(STDOUT,"Total: %d\n",total); + fprintf(STDOUT, "\n"); + fprintf(STDOUT, "Total: %d\n", total); return 0; - + } -static int CompareVolName(p1,p2) -char *p1,*p2; +static int +CompareVolName(p1, p2) + char *p1, *p2; { - volintInfo *arg1,*arg2; + volintInfo *arg1, *arg2; + + arg1 = (volintInfo *) p1; + arg2 = (volintInfo *) p2; + return (strcmp(arg1->name, arg2->name)); - arg1 = (volintInfo *)p1; - arg2 = (volintInfo *)p2; - return(strcmp(arg1->name,arg2->name)); - } /*------------------------------------------------------------------------ @@ -2369,27 +3048,33 @@ char *p1,*p2; * As advertised. *------------------------------------------------------------------------*/ -static int XCompareVolName(a_obj1P, a_obj2P) - char *a_obj1P, *a_obj2P; +static int +XCompareVolName(a_obj1P, a_obj2P) + char *a_obj1P, *a_obj2P; -{ /*XCompareVolName*/ +{ /*XCompareVolName */ - return(strcmp(((struct volintXInfo *)(a_obj1P))->name, - ((struct volintXInfo *)(a_obj2P))->name)); + return (strcmp + (((struct volintXInfo *)(a_obj1P))->name, + ((struct volintXInfo *)(a_obj2P))->name)); -} /*XCompareVolName*/ +} /*XCompareVolName */ -static int CompareVolID(p1,p2) -char *p1,*p2; +static int +CompareVolID(p1, p2) + char *p1, *p2; { - volintInfo *arg1,*arg2; - - arg1 = (volintInfo *)p1; - arg2 = (volintInfo *)p2; - if(arg1->volid == arg2->volid) return 0; - if(arg1->volid > arg2->volid) return 1; - else return -1; - + volintInfo *arg1, *arg2; + + arg1 = (volintInfo *) p1; + arg2 = (volintInfo *) p2; + if (arg1->volid == arg2->volid) + return 0; + if (arg1->volid > arg2->volid) + return 1; + else + return -1; + } /*------------------------------------------------------------------------ @@ -2414,24 +3099,24 @@ char *p1,*p2; * As advertised. *------------------------------------------------------------------------*/ -static int XCompareVolID(a_obj1P, a_obj2P) - char *a_obj1P, *a_obj2P; +static int +XCompareVolID(a_obj1P, a_obj2P) + char *a_obj1P, *a_obj2P; -{ /*XCompareVolID*/ +{ /*XCompareVolID */ - afs_int32 id1, id2; /*Volume IDs we're comparing*/ + afs_int32 id1, id2; /*Volume IDs we're comparing */ id1 = ((struct volintXInfo *)(a_obj1P))->volid; id2 = ((struct volintXInfo *)(a_obj2P))->volid; if (id1 == id2) - return(0); + return (0); + else if (id1 > id2) + return (1); else - if (id1 > id2) - return(1); - else - return(-1); + return (-1); -} /*XCompareVolID*/ +} /*XCompareVolID */ /*------------------------------------------------------------------------ * PRIVATE ListVolumes @@ -2453,17 +3138,18 @@ static int XCompareVolID(a_obj1P, a_obj2P) * As advertised. *------------------------------------------------------------------------*/ -static ListVolumes(as) -register struct cmd_syndesc *as; -{ - afs_int32 apart,int32list,fast; - afs_int32 aserver,code; - volintInfo *pntr,*oldpntr; +static +ListVolumes(as) + register struct cmd_syndesc *as; +{ + afs_int32 apart, int32list, fast; + afs_int32 aserver, code; + volintInfo *pntr, *oldpntr; afs_int32 count; int i; char *base; - volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info*/ - int wantExtendedInfo; /*Do we want extended vol info?*/ + volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */ + int wantExtendedInfo; /*Do we want extended vol info? */ char pname[10]; struct partList dummyPartList; @@ -2474,12 +3160,18 @@ register struct cmd_syndesc *as; fast = 0; int32list = 0; - if(as->parms[3].items) int32list = 1; - if(as->parms[4].items) quiet = 1; - else quiet = 0; - if(as->parms[2].items) fast = 1; - if(fast) all = 0; - else all = 1; + if (as->parms[3].items) + int32list = 1; + if (as->parms[4].items) + quiet = 1; + else + quiet = 0; + if (as->parms[2].items) + fast = 1; + if (fast) + all = 0; + else + all = 1; if (as->parms[5].items) { /* * We can't coexist with the fast flag. @@ -2495,13 +3187,13 @@ register struct cmd_syndesc *as; */ wantExtendedInfo = 1; int32list = 1; - } - else + } else wantExtendedInfo = 0; - if(as->parms[1].items){ + if (as->parms[1].items) { apart = volutil_GetPartitionID(as->parms[1].items->data); if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data); + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); exit(1); } dummyPartList.partId[0] = apart; @@ -2510,41 +3202,42 @@ register struct cmd_syndesc *as; } aserver = GetServer(as->parms[0].items->data); if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data ); + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); exit(1); } - if(apart != -1) { - if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); + if (apart != -1) { + if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); exit(1); } - } - else { - code = UV_ListPartitions(aserver,&dummyPartList, &cnt); + } else { + code = UV_ListPartitions(aserver, &dummyPartList, &cnt); if (code) { PrintDiagnostics("listvol", code); exit(1); } } - for(i = 0 ; i < cnt ; i++){ - if(dummyPartList.partFlags[i] & PARTVALID){ + for (i = 0; i < cnt; i++) { + if (dummyPartList.partFlags[i] & PARTVALID) { if (wantExtendedInfo) - code = UV_XListVolumes(aserver, - dummyPartList.partId[i], - all, - &xInfoP, - &count); + code = + UV_XListVolumes(aserver, dummyPartList.partId[i], all, + &xInfoP, &count); else - code = UV_ListVolumes(aserver, - dummyPartList.partId[i], - all, - &pntr, - &count); + code = + UV_ListVolumes(aserver, dummyPartList.partId[i], all, + &pntr, &count); if (code) { PrintDiagnostics("listvol", code); - if(pntr) free(pntr); + if (pntr) + free(pntr); exit(1); } if (wantExtendedInfo) { @@ -2555,169 +3248,183 @@ register struct cmd_syndesc *as; base = (char *)pntr; } - if(!fast) { - if (wantExtendedInfo) + if (!fast) { + if (wantExtendedInfo) qsort(base, count, sizeof(volintXInfo), XCompareVolName); else qsort(base, count, sizeof(volintInfo), CompareVolName); } else { - if (wantExtendedInfo) + if (wantExtendedInfo) qsort(base, count, sizeof(volintXInfo), XCompareVolID); else qsort(base, count, sizeof(volintInfo), CompareVolID); } - MapPartIdIntoName(dummyPartList.partId[i],pname); - if(!quiet) - fprintf(STDOUT,"Total number of volumes on server %s partition %s: %u \n",as->parms[0].items->data,pname,count); + MapPartIdIntoName(dummyPartList.partId[i], pname); + if (!quiet) + fprintf(STDOUT, + "Total number of volumes on server %s partition %s: %lu \n", + as->parms[0].items->data, pname, + (unsigned long)count); if (wantExtendedInfo) { - XDisplayVolumes(aserver, - dummyPartList.partId[i], - origxInfoP, - count, - int32list, - fast, - quiet); - if(xInfoP) + XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP, + count, int32list, fast, quiet); + if (xInfoP) free(xInfoP); - xInfoP = (volintXInfo *)0; - } - else { + xInfoP = (volintXInfo *) 0; + } else { #ifdef FULL_LISTVOL_SWITCH - if (as->parms[6].items) - DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr, - count); - else + if (as->parms[6].items) + DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr, + count); + else #endif /* FULL_LISTVOL_SWITCH */ - DisplayVolumes(aserver, - dummyPartList.partId[i], - oldpntr, - count, - int32list, - fast, - quiet); + DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr, + count, int32list, fast, quiet); if (pntr) free(pntr); - pntr = (volintInfo *)0; + pntr = (volintInfo *) 0; } } } return 0; } -static SyncVldb(as) - register struct cmd_syndesc *as; +static +SyncVldb(as) + register struct cmd_syndesc *as; { - afs_int32 pname, code; /* part name */ - char part[10]; - int flags = 0; - char *volname = 0; - - tserver = 0; - if (as->parms[0].items) { - tserver = GetServer(as->parms[0].items->data); - if (!tserver) { - fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data ); - exit(1); - } - } + afs_int32 pnum, code; /* part name */ + char part[10]; + int flags = 0; + char *volname = 0; - if (as->parms[1].items) { - pname = volutil_GetPartitionID(as->parms[1].items->data); - if (pname < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data ); - exit(1); - } - if (!IsPartValid(pname,tserver,&code)) { /*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos: partition %s does not exist on the server\n", - as->parms[1].items->data); - exit(1); - } - flags = 1; - - if (!tserver) { - fprintf(STDERR,"The -partition option requires a -server option\n"); - exit(1); - } - } - - if (as->parms[2].items) { - /* Synchronize an individual volume */ - volname = as->parms[2].items->data; - code = UV_SyncVolume(tserver, pname, volname, flags); - } else { - if (!tserver) { - fprintf(STDERR,"Without a -volume option, the -server option is required\n"); + tserver = 0; + if (as->parms[0].items) { + tserver = GetServer(as->parms[0].items->data); + if (!tserver) { + fprintf(STDERR, "vos: host '%s' not found in host table\n", + as->parms[0].items->data); + exit(1); + } + } + + if (as->parms[1].items) { + pnum = volutil_GetPartitionID(as->parms[1].items->data); + if (pnum < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); + exit(1); + } + if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos: partition %s does not exist on the server\n", + as->parms[1].items->data); + exit(1); + } + flags = 1; + + if (!tserver) { + fprintf(STDERR, + "The -partition option requires a -server option\n"); + exit(1); + } + } + + if (as->parms[2].items) { + /* Synchronize an individual volume */ + volname = as->parms[2].items->data; + code = UV_SyncVolume(tserver, pnum, volname, flags); + } else { + if (!tserver) { + fprintf(STDERR, + "Without a -volume option, the -server option is required\n"); + exit(1); + } + code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ ); + } + + if (code) { + PrintDiagnostics("syncvldb", code); exit(1); - } - code = UV_SyncVldb(tserver, pname, flags, 0/*unused*/); - } - - if (code) { - PrintDiagnostics("syncvldb", code); - exit(1); - } - - /* Print a summary of what we did */ - if (volname) fprintf(STDOUT,"VLDB volume %s synchronized", volname); - else fprintf(STDOUT,"VLDB synchronized"); - if (tserver) { - fprintf(STDOUT," with state of server %s", as->parms[0].items->data); - } - if (flags) { - MapPartIdIntoName(pname,part); - fprintf(STDOUT," partition %s\n", part); - } - fprintf(STDOUT, "\n"); - - return 0; + } + + /* Print a summary of what we did */ + if (volname) + fprintf(STDOUT, "VLDB volume %s synchronized", volname); + else + fprintf(STDOUT, "VLDB synchronized"); + if (tserver) { + fprintf(STDOUT, " with state of server %s", as->parms[0].items->data); + } + if (flags) { + MapPartIdIntoName(pnum, part); + fprintf(STDOUT, " partition %s\n", part); + } + fprintf(STDOUT, "\n"); + + return 0; } - -static SyncServer(as) -register struct cmd_syndesc *as; + +static +SyncServer(as) + register struct cmd_syndesc *as; { - afs_int32 pname,code; /* part name */ + afs_int32 pnum, code; /* part name */ char part[10]; - - int flags = 0; - tserver = GetServer(as->parms[0].items->data); - if (!tserver) { - fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data ); + int flags = 0; + + tserver = GetServer(as->parms[0].items->data); + if (!tserver) { + fprintf(STDERR, "vos: host '%s' not found in host table\n", + as->parms[0].items->data); + exit(1); + } + if (as->parms[1].items) { + pnum = volutil_GetPartitionID(as->parms[1].items->data); + if (pnum < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); exit(1); } - if(as->parms[1].items){ - pname = volutil_GetPartitionID(as->parms[1].items->data); - if (pname < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data); - exit(1); - } - if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); - exit(1); - } - flags = 1; - } - - code = UV_SyncServer(tserver, pname, flags, 0/*unused*/); - if (code) { - PrintDiagnostics("syncserv", code); + if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); exit(1); } - if(flags){ - MapPartIdIntoName(pname,part); - fprintf(STDOUT,"Server %s partition %s synchronized with VLDB\n",as->parms[0].items->data,part); - } - else fprintf(STDOUT,"Server %s synchronized with VLDB\n",as->parms[0].items->data); + flags = 1; + } else { + pnum = -1; + } + + code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ ); + if (code) { + PrintDiagnostics("syncserv", code); + exit(1); + } + if (flags) { + MapPartIdIntoName(pnum, part); + fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n", + as->parms[0].items->data, part); + } else + fprintf(STDOUT, "Server %s synchronized with VLDB\n", + as->parms[0].items->data); return 0; - + } -static VolumeInfoCmd(name) -char *name; -{ +static +VolumeInfoCmd(name) + char *name; +{ struct nvldbentry entry; afs_int32 vcode; @@ -2726,7 +3433,7 @@ char *name; */ vcode = VLDB_GetEntryByName(name, &entry); if (vcode) { - PrintError("", vcode); + PrintError("", vcode); exit(1); } MapHostToNetwork(&entry); @@ -2737,18 +3444,19 @@ char *name; * Leave this routine as is, but put in correct check. */ if (entry.flags & VLOP_ALLOPERS) - fprintf(STDOUT," Volume is currently LOCKED \n"); + fprintf(STDOUT, " Volume is currently LOCKED \n"); return 0; } -static VolumeZap(as) -register struct cmd_syndesc *as; +static +VolumeZap(as) + register struct cmd_syndesc *as; { struct nvldbentry entry; - afs_int32 volid,code,server,part, zapbackupid=0, backupid=0, err; - + afs_int32 volid, code, server, part, zapbackupid = 0, backupid = 0, err; + if (as->parms[3].items) { /* force flag is on, use the other version */ return NukeVolume(as); @@ -2759,209 +3467,256 @@ register struct cmd_syndesc *as; } volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); - if(volid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data); + if (volid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[2].items->data); exit(1); } part = volutil_GetPartitionID(as->parms[1].items->data); if (part < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data ); + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); exit(1); } server = GetServer(as->parms[0].items->data); if (!server) { - fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data ); - exit(1); + fprintf(STDERR, "vos: host '%s' not found in host table\n", + as->parms[0].items->data); + exit(1); } - if (!IsPartValid(part,server,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); - exit(1); - } - code = VLDB_GetEntryByID(volid,-1, &entry); + if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); + exit(1); + } + code = VLDB_GetEntryByID(volid, -1, &entry); if (!code) { - if (volid == entry.volumeId[RWVOL]) + if (volid == entry.volumeId[RWVOL]) backupid = entry.volumeId[BACKVOL]; - fprintf(STDERR,"Warning: Entry for volume number %u exists in VLDB (but we're zapping it anyway!)\n", - volid); + fprintf(STDERR, + "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n", + (unsigned long)volid); } if (zapbackupid) { - volintInfo *pntr = (volintInfo *)0; + volintInfo *pntr = (volintInfo *) 0; if (!backupid) { code = UV_ListOneVolume(server, part, volid, &pntr); if (!code) { if (volid == pntr->parentID) backupid = pntr->backupID; - if (pntr) free(pntr); + if (pntr) + free(pntr); } } if (backupid) { - code = UV_VolumeZap(server,part, backupid); + code = UV_VolumeZap(server, part, backupid); if (code) { PrintDiagnostics("zap", code); exit(1); } - fprintf(STDOUT,"Backup Volume %u deleted\n", backupid); + fprintf(STDOUT, "Backup Volume %lu deleted\n", + (unsigned long)backupid); } } - code = UV_VolumeZap(server,part,volid); + code = UV_VolumeZap(server, part, volid); if (code) { PrintDiagnostics("zap", code); exit(1); } - fprintf(STDOUT,"Volume %u deleted\n",volid); + fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid); return 0; } - -static VolserStatus(as) -register struct cmd_syndesc *as; -{ +static +VolserStatus(as) + register struct cmd_syndesc *as; + +{ afs_int32 server, code; - transDebugInfo *pntr,*oldpntr; + transDebugInfo *pntr, *oldpntr; afs_int32 count; int i; char pname[10]; server = GetServer(as->parms[0].items->data); if (!server) { - fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data ); - exit(1); + fprintf(STDERR, "vos: host '%s' not found in host table\n", + as->parms[0].items->data); + exit(1); } - code = UV_VolserStatus(server,&pntr,&count); - if(code) { - PrintDiagnostics("status",code); + code = UV_VolserStatus(server, &pntr, &count); + if (code) { + PrintDiagnostics("status", code); exit(1); } oldpntr = pntr; - if(count == 0) - fprintf(STDOUT,"No active transactions on %s\n",as->parms[0].items->data); + if (count == 0) + fprintf(STDOUT, "No active transactions on %s\n", + as->parms[0].items->data); else { - fprintf(STDOUT,"Total transactions: %d\n",count); + fprintf(STDOUT, "Total transactions: %d\n", count); } - for(i = 0; i < count ; i++){ + for (i = 0; i < count; i++) { /*print out the relevant info */ - fprintf(STDOUT,"--------------------------------------\n"); - fprintf(STDOUT,"transaction: %u created: %s",pntr->tid, - ctime((time_t *)&pntr->time)); - if(pntr->returnCode){ - fprintf(STDOUT,"returnCode: %u\n",pntr->returnCode); - } - if(pntr->iflags){ - fprintf(STDOUT,"attachFlags: "); - switch(pntr->iflags){ - case ITOffline: fprintf(STDOUT,"offline "); + fprintf(STDOUT, "--------------------------------------\n"); + fprintf(STDOUT, "transaction: %lu created: %s", + (unsigned long)pntr->tid, ctime((time_t *) & pntr->time)); + if (pntr->returnCode) { + fprintf(STDOUT, "returnCode: %lu\n", + (unsigned long)pntr->returnCode); + } + if (pntr->iflags) { + fprintf(STDOUT, "attachFlags: "); + switch (pntr->iflags) { + case ITOffline: + fprintf(STDOUT, "offline "); break; - case ITBusy: fprintf(STDOUT,"busy "); + case ITBusy: + fprintf(STDOUT, "busy "); break; - case ITReadOnly: fprintf(STDOUT,"readonly "); + case ITReadOnly: + fprintf(STDOUT, "readonly "); break; - case ITCreate: fprintf(STDOUT,"create "); + case ITCreate: + fprintf(STDOUT, "create "); break; - case ITCreateVolID: fprintf(STDOUT,"create volid "); + case ITCreateVolID: + fprintf(STDOUT, "create volid "); break; } - fprintf(STDOUT,"\n"); - } - if(pntr->vflags){ - fprintf(STDOUT,"volumeStatus: "); - switch(pntr->vflags){ - case VTDeleteOnSalvage: fprintf(STDOUT,"deleteOnSalvage "); - case VTOutOfService: fprintf(STDOUT,"outOfService "); - case VTDeleted: fprintf(STDOUT,"deleted "); + fprintf(STDOUT, "\n"); + } + if (pntr->vflags) { + fprintf(STDOUT, "volumeStatus: "); + switch (pntr->vflags) { + case VTDeleteOnSalvage: + fprintf(STDOUT, "deleteOnSalvage "); + case VTOutOfService: + fprintf(STDOUT, "outOfService "); + case VTDeleted: + fprintf(STDOUT, "deleted "); } - fprintf(STDOUT,"\n"); + fprintf(STDOUT, "\n"); } - if(pntr->tflags){ - fprintf(STDOUT,"transactionFlags: "); - fprintf(STDOUT,"delete\n"); + if (pntr->tflags) { + fprintf(STDOUT, "transactionFlags: "); + fprintf(STDOUT, "delete\n"); } - MapPartIdIntoName(pntr->partition ,pname); - fprintf(STDOUT,"volume: %u partition: %s procedure: %s\n",pntr->volid,pname, pntr->lastProcName); - if(pntr->callValid){ - fprintf(STDOUT,"packetRead: %u lastReceiveTime: %d packetSend: %u lastSendTime: %d\n",pntr->readNext,pntr->lastReceiveTime,pntr->transmitNext, pntr->lastSendTime); + MapPartIdIntoName(pntr->partition, pname); + fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n", + (unsigned long)pntr->volid, pname, pntr->lastProcName); + if (pntr->callValid) { + fprintf(STDOUT, + "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n", + (unsigned long)pntr->readNext, pntr->lastReceiveTime, + (unsigned long)pntr->transmitNext, pntr->lastSendTime); } pntr++; - fprintf(STDOUT,"--------------------------------------\n"); - fprintf(STDOUT,"\n"); + fprintf(STDOUT, "--------------------------------------\n"); + fprintf(STDOUT, "\n"); } - if(oldpntr) free(oldpntr); + if (oldpntr) + free(oldpntr); return 0; } - -static RenameVolume(as) -register struct cmd_syndesc *as; + +static +RenameVolume(as) + register struct cmd_syndesc *as; { - afs_int32 code1,code2,code; - struct nvldbentry entry; + afs_int32 code1, code2, code; + struct nvldbentry entry; - code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry); - if(code1){ - fprintf(STDERR,"vos: Could not find entry for volume %s\n",as->parms[0].items->data); - exit(1); - } - code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry); - if((!code1) && (!code2)) { /*the newname already exists */ - fprintf(STDERR,"vos: volume %s already exists\n",as->parms[1].items->data); - exit(1); - } + code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry); + if (code1) { + fprintf(STDERR, "vos: Could not find entry for volume %s\n", + as->parms[0].items->data); + exit(1); + } + code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry); + if ((!code1) && (!code2)) { /*the newname already exists */ + fprintf(STDERR, "vos: volume %s already exists\n", + as->parms[1].items->data); + exit(1); + } - if(code1 && code2){ - fprintf(STDERR,"vos: Could not find entry for volume %s or %s\n",as->parms[0].items->data,as->parms[1].items->data); - exit(1); - } - if(!VolNameOK(as->parms[0].items->data)){ - fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[0].items->data); + if (code1 && code2) { + fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n", + as->parms[0].items->data, as->parms[1].items->data); exit(1); } - if(!ISNAMEVALID(as->parms[1].items->data)) { - fprintf(STDERR,"vos: the new volume name %s exceeds the size limit of %d\n",as->parms[1].items->data,VOLSER_OLDMAXVOLNAME - 10); + if (!VolNameOK(as->parms[0].items->data)) { + fprintf(STDERR, + "Illegal volume name %s, should not end in .readonly or .backup\n", + as->parms[0].items->data); exit(1); } - if(!VolNameOK(as->parms[1].items->data)){ - fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[1].items->data); + if (!ISNAMEVALID(as->parms[1].items->data)) { + fprintf(STDERR, + "vos: the new volume name %s exceeds the size limit of %d\n", + as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10); exit(1); } - if(IsNumeric(as->parms[1].items->data)){ - fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[1].items->data); + if (!VolNameOK(as->parms[1].items->data)) { + fprintf(STDERR, + "Illegal volume name %s, should not end in .readonly or .backup\n", + as->parms[1].items->data); exit(1); } - MapHostToNetwork(&entry); - code = UV_RenameVolume(&entry,as->parms[0].items->data,as->parms[1].items->data); - if (code) { - PrintDiagnostics("rename", code); - exit(1); - } - fprintf(STDOUT,"Renamed volume %s to %s\n",as->parms[0].items->data,as->parms[1].items->data); - return 0; + if (IsNumeric(as->parms[1].items->data)) { + fprintf(STDERR, "Illegal volume name %s, should not be a number\n", + as->parms[1].items->data); + exit(1); + } + MapHostToNetwork(&entry); + code = + UV_RenameVolume(&entry, as->parms[0].items->data, + as->parms[1].items->data); + if (code) { + PrintDiagnostics("rename", code); + exit(1); + } + fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data, + as->parms[1].items->data); + return 0; } -GetVolumeInfo(volid, server, part, voltype,rentry) -afs_int32 *server, volid, *part, *voltype; -register struct nvldbentry *rentry; +GetVolumeInfo(volid, server, part, voltype, rentry) + afs_int32 *server, volid, *part, *voltype; + register struct nvldbentry *rentry; { afs_int32 vcode; - int i,index = -1; + int i, index = -1; vcode = VLDB_GetEntryByID(volid, -1, rentry); - if(vcode) { - fprintf(STDERR,"Could not fetch the entry for volume %u from VLDB \n",volid); - PrintError("",vcode); - return (vcode); + if (vcode) { + fprintf(STDERR, + "Could not fetch the entry for volume %lu from VLDB \n", + (unsigned long)volid); + PrintError("", vcode); + return (vcode); } MapHostToNetwork(rentry); - if(volid == rentry->volumeId[ROVOL]){ + if (volid == rentry->volumeId[ROVOL]) { *voltype = ROVOL; for (i = 0; i < rentry->nServers; i++) { - if ( (index == -1) && (rentry->serverFlags[i] & ITSROVOL) && - !(rentry->serverFlags[i] & RO_DONTUSE) ) + if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL) + && !(rentry->serverFlags[i] & RO_DONTUSE)) index = i; } - if(index == -1) { - fprintf(STDERR,"RO volume is not found in VLDB entry for volume %u\n", volid); + if (index == -1) { + fprintf(STDERR, + "RO volume is not found in VLDB entry for volume %lu\n", + (unsigned long)volid); return -1; } @@ -2969,28 +3724,35 @@ register struct nvldbentry *rentry; *part = rentry->serverPartition[index]; return 0; } - + index = Lp_GetRwIndex(rentry); - if(index == -1) { - fprintf(STDERR,"RW Volume is not found in VLDB entry for volume %u\n", volid); - return -1; + if (index == -1) { + fprintf(STDERR, + "RW Volume is not found in VLDB entry for volume %lu\n", + (unsigned long)volid); + return -1; } - if(volid == rentry->volumeId[RWVOL]){ + if (volid == rentry->volumeId[RWVOL]) { *voltype = RWVOL; *server = rentry->serverNumber[index]; *part = rentry->serverPartition[index]; return 0; } - if(volid == rentry->volumeId[BACKVOL]){ + if (volid == rentry->volumeId[BACKVOL]) { *voltype = BACKVOL; *server = rentry->serverNumber[index]; *part = rentry->serverPartition[index]; return 0; } + fprintf(STDERR, + "unexpected volume type for volume %lu\n", + (unsigned long)volid); + return -1; } -static DeleteEntry(as) -register struct cmd_syndesc *as; +static +DeleteEntry(as) + register struct cmd_syndesc *as; { afs_int32 apart; @@ -3002,162 +3764,179 @@ register struct cmd_syndesc *as; struct cmd_item *itp; afs_int32 nentries; int j; - char prefix[VOLSER_MAXVOLNAME+1]; - int seenprefix=0; - afs_int32 totalBack=0, totalFail=0, err; - - if (as->parms[0].items) { /* -id */ - if (as->parms[1].items || as->parms[2].items || as->parms[3].items) { - fprintf(STDERR,"You cannot use -server, -partition, or -prefix with the -id argument\n"); - exit(-2); - } - for (itp=as->parms[0].items; itp; itp=itp->next) { - avolid = vsu_GetVolumeID(itp->data, cstruct, &err); - if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", itp->data); - continue; - } - if (as->parms[4].items) { /* -noexecute */ - fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", itp->data); - fflush(STDOUT); - continue; - } - vcode = ubik_Call(VL_DeleteEntry,cstruct, 0, avolid, RWVOL); - if (vcode) { - fprintf(STDERR,"Could not delete entry for volume %s\n", itp->data); - fprintf(STDERR,"You must specify a RW volume name or ID " - "(the entire VLDB entry will be deleted)\n", itp->data); - PrintError("",vcode); - totalFail++; - continue; - } - totalBack++; - } - fprintf(STDOUT,"Deleted %d VLDB entries\n", totalBack); - return(totalFail); + char prefix[VOLSER_MAXVOLNAME + 1]; + int seenprefix = 0; + afs_int32 totalBack = 0, totalFail = 0, err; + + if (as->parms[0].items) { /* -id */ + if (as->parms[1].items || as->parms[2].items || as->parms[3].items) { + fprintf(STDERR, + "You cannot use -server, -partition, or -prefix with the -id argument\n"); + exit(-2); + } + for (itp = as->parms[0].items; itp; itp = itp->next) { + avolid = vsu_GetVolumeID(itp->data, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + itp->data); + continue; + } + if (as->parms[4].items) { /* -noexecute */ + fprintf(STDOUT, "Would have deleted VLDB entry for %s \n", + itp->data); + fflush(STDOUT); + continue; + } + vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL); + if (vcode) { + fprintf(STDERR, "Could not delete entry for volume %s\n", + itp->data); + fprintf(STDERR, + "You must specify a RW volume name or ID " + "(the entire VLDB entry will be deleted)\n"); + PrintError("", vcode); + totalFail++; + continue; + } + totalBack++; + } + fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack); + return (totalFail); } if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) { - fprintf(STDERR,"You must specify an option\n"); - exit(-2); + fprintf(STDERR, "You must specify an option\n"); + exit(-2); } /* Zero out search attributes */ memset(&attributes, 0, sizeof(struct VldbListByAttributes)); - if (as->parms[1].items) { /* -prefix */ - strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME); - seenprefix = 1; - if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */ - fprintf(STDERR,"You must provide -server with the -prefix argument\n"); - exit(-2); - } - } - - if (as->parms[2].items) { /* -server */ - afs_int32 aserver; - aserver = GetServer(as->parms[2].items->data); - if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[2].items->data ); - exit(-1); - } - attributes.server = ntohl(aserver); - attributes.Mask |= VLLIST_SERVER; - } - - if (as->parms[3].items) { /* -partition */ - if (!as->parms[2].items) { - fprintf(STDERR,"You must provide -server with the -partition argument\n"); - exit(-2); - } - apart = volutil_GetPartitionID(as->parms[3].items->data); - if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", - as->parms[3].items->data); - exit(-1); - } - attributes.partition = apart; - attributes.Mask |= VLLIST_PARTITION; + if (as->parms[1].items) { /* -prefix */ + strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME); + seenprefix = 1; + if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */ + fprintf(STDERR, + "You must provide -server with the -prefix argument\n"); + exit(-2); + } + } + + if (as->parms[2].items) { /* -server */ + afs_int32 aserver; + aserver = GetServer(as->parms[2].items->data); + if (aserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[2].items->data); + exit(-1); + } + attributes.server = ntohl(aserver); + attributes.Mask |= VLLIST_SERVER; + } + + if (as->parms[3].items) { /* -partition */ + if (!as->parms[2].items) { + fprintf(STDERR, + "You must provide -server with the -partition argument\n"); + exit(-2); + } + apart = volutil_GetPartitionID(as->parms[3].items->data); + if (apart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[3].items->data); + exit(-1); + } + attributes.partition = apart; + attributes.Mask |= VLLIST_PARTITION; } /* Print status line of what we are doing */ - fprintf(STDOUT,"Deleting VLDB entries for "); + fprintf(STDOUT, "Deleting VLDB entries for "); if (as->parms[2].items) { - fprintf(STDOUT,"server %s ", as->parms[2].items->data); + fprintf(STDOUT, "server %s ", as->parms[2].items->data); } if (as->parms[3].items) { - char pname[10]; - MapPartIdIntoName(apart, pname); - fprintf(STDOUT,"partition %s ", pname); + char pname[10]; + MapPartIdIntoName(apart, pname); + fprintf(STDOUT, "partition %s ", pname); } if (seenprefix) { - fprintf(STDOUT,"which are prefixed with %s ", prefix); + fprintf(STDOUT, "which are prefixed with %s ", prefix); } - fprintf(STDOUT,"\n"); + fprintf(STDOUT, "\n"); fflush(STDOUT); /* Get all the VLDB entries on a server and/or partition */ memset(&arrayEntries, 0, sizeof(arrayEntries)); vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); if (vcode) { - fprintf(STDERR,"Could not access the VLDB for attributes\n"); - PrintError("",vcode); - exit(-1); + fprintf(STDERR, "Could not access the VLDB for attributes\n"); + PrintError("", vcode); + exit(-1); } /* Process each entry */ - for (j=0; jname, prefix, strlen(prefix))){ - if (verbose) { - fprintf(STDOUT,"Omitting to delete %s due to prefix %s mismatch\n", - vllist->name, prefix); - } - fflush(STDOUT); - continue; - } - } - - if (as->parms[4].items) { /* -noexecute */ - fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", vllist->name); - fflush(STDOUT); - continue; - } - - /* Only matches the RW volume name */ - avolid = vllist->volumeId[RWVOL]; - vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL); - if (vcode){ - fprintf(STDOUT,"Could not delete VDLB entry for %s\n",vllist->name); - totalFail++; - PrintError("",vcode); - continue; - } else { - totalBack++; - if (verbose) - fprintf(STDOUT,"Deleted VLDB entry for %s \n",vllist->name); - } - fflush(STDOUT); - } /*for*/ - - fprintf(STDOUT,"----------------------\n"); - fprintf(STDOUT,"Total VLDB entries deleted: %u; failed to delete: %u\n",totalBack,totalFail); - if (arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val); + for (j = 0; j < nentries; j++) { + vllist = &arrayEntries.nbulkentries_val[j]; + if (seenprefix) { + /* It only deletes the RW volumes */ + if (strncmp(vllist->name, prefix, strlen(prefix))) { + if (verbose) { + fprintf(STDOUT, + "Omitting to delete %s due to prefix %s mismatch\n", + vllist->name, prefix); + } + fflush(STDOUT); + continue; + } + } + + if (as->parms[4].items) { /* -noexecute */ + fprintf(STDOUT, "Would have deleted VLDB entry for %s \n", + vllist->name); + fflush(STDOUT); + continue; + } + + /* Only matches the RW volume name */ + avolid = vllist->volumeId[RWVOL]; + vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL); + if (vcode) { + fprintf(STDOUT, "Could not delete VDLB entry for %s\n", + vllist->name); + totalFail++; + PrintError("", vcode); + continue; + } else { + totalBack++; + if (verbose) + fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name); + } + fflush(STDOUT); + } /*for */ + + fprintf(STDOUT, "----------------------\n"); + fprintf(STDOUT, + "Total VLDB entries deleted: %lu; failed to delete: %lu\n", + (unsigned long)totalBack, (unsigned long)totalFail); + if (arrayEntries.nbulkentries_val) + free(arrayEntries.nbulkentries_val); return 0; } -static int CompareVldbEntryByName(p1,p2) -char *p1,*p2; +static int +CompareVldbEntryByName(p1, p2) + char *p1, *p2; { - struct nvldbentry *arg1,*arg2; + struct nvldbentry *arg1, *arg2; arg1 = (struct nvldbentry *)p1; arg2 = (struct nvldbentry *)p2; - return(strcmp(arg1->name,arg2->name)); + return (strcmp(arg1->name, arg2->name)); } /* @@ -3195,16 +3974,17 @@ char *p1,*p2; } -*/ -static ListVLDB(as) - struct cmd_syndesc *as; -{ +*/ +static +ListVLDB(as) + struct cmd_syndesc *as; +{ afs_int32 apart; - afs_int32 aserver,code; + afs_int32 aserver, code; afs_int32 vcode; struct VldbListByAttributes attributes; nbulkentries arrayEntries; - struct nvldbentry *vllist, *tarray=0, *ttarray; + struct nvldbentry *vllist, *tarray = 0, *ttarray; afs_int32 centries, nentries = 0, tarraysize, parraysize; int j; char pname[10]; @@ -3215,150 +3995,163 @@ static ListVLDB(as) apart = 0; attributes.Mask = 0; - lock = (as->parms[3].items ? 1 : 0); /* -lock flag */ - quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */ - sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */ + lock = (as->parms[3].items ? 1 : 0); /* -lock flag */ + quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */ + sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */ /* If the volume name is given, Use VolumeInfoCmd to look it up * and not ListAttributes. */ if (as->parms[0].items) { - if (lock) { - fprintf(STDERR,"vos: illegal use of '-locked' switch, need to specify server and/or partition\n"); - exit(1); - } - code = VolumeInfoCmd(as->parms[0].items->data); - if (code) { - PrintError("",code); - exit(1); - } - return 0; + if (lock) { + fprintf(STDERR, + "vos: illegal use of '-locked' switch, need to specify server and/or partition\n"); + exit(1); + } + code = VolumeInfoCmd(as->parms[0].items->data); + if (code) { + PrintError("", code); + exit(1); + } + return 0; } /* Server specified */ if (as->parms[1].items) { - aserver = GetServer(as->parms[1].items->data); - if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data ); - exit(1); - } - attributes.server = ntohl(aserver); - attributes.Mask |= VLLIST_SERVER; - } - + aserver = GetServer(as->parms[1].items->data); + if (aserver == 0) { + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[1].items->data); + exit(1); + } + attributes.server = ntohl(aserver); + attributes.Mask |= VLLIST_SERVER; + } + /* Partition specified */ if (as->parms[2].items) { - apart = volutil_GetPartitionID(as->parms[2].items->data); - if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data); - exit(1); - } - attributes.partition = apart; - attributes.Mask |= VLLIST_PARTITION; + apart = volutil_GetPartitionID(as->parms[2].items->data); + if (apart < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[2].items->data); + exit(1); + } + attributes.partition = apart; + attributes.Mask |= VLLIST_PARTITION; } if (lock) { - attributes.Mask |= VLLIST_FLAG; - attributes.flag = VLOP_ALLOPERS; + attributes.Mask |= VLLIST_FLAG; + attributes.flag = VLOP_ALLOPERS; } /* Print header information */ if (!quiet) { - MapPartIdIntoName(apart, pname); - fprintf(STDOUT,"VLDB entries for %s %s%s%s %s\n", - (as->parms[1].items ? "server" : "all" ), - (as->parms[1].items ? as->parms[1].items->data : "servers"), - (as->parms[2].items ? " partition " : ""), - (as->parms[2].items ? pname : ""), - (lock ? "which are locked:" : "")); + MapPartIdIntoName(apart, pname); + fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n", + (as->parms[1].items ? "server" : "all"), + (as->parms[1].items ? as->parms[1].items->data : "servers"), + (as->parms[2].items ? " partition " : ""), + (as->parms[2].items ? pname : ""), + (lock ? "which are locked:" : "")); } for (thisindex = 0; (thisindex != -1); thisindex = nextindex) { - memset(&arrayEntries, 0, sizeof(arrayEntries)); - centries = 0; - nextindex = -1; - - vcode = VLDB_ListAttributesN2(&attributes, 0, thisindex, - ¢ries, &arrayEntries, &nextindex); - if (vcode == RXGEN_OPCODE) { - /* Vlserver not running with ListAttributesN2. Fall back */ - vcode = VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries); - nextindex = -1; - } - if (vcode) { - fprintf(STDERR,"Could not access the VLDB for attributes\n"); - PrintError("",vcode); - exit(1); - } - nentries += centries; - - /* We don't sort, so just print the entries now */ - if (!sort) { - for (j = 0; j < centries; j++) { /* process each entry */ - vllist = &arrayEntries.nbulkentries_val[j]; - MapHostToNetwork(vllist); - EnumerateEntry(vllist); - - if(vllist->flags & VLOP_ALLOPERS) - fprintf(STDOUT," Volume is currently LOCKED \n"); - } - } - - /* So we sort. First we must collect all the entries and keep - * them in memory. - */ - else if (centries > 0) { - if (!tarray) { - /* steal away the first bulk entries array */ - tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val; - tarraysize = centries * sizeof(struct nvldbentry); - arrayEntries.nbulkentries_val = 0; - } else { - /* Grow the tarray to keep the extra entries */ - parraysize = (centries * sizeof(struct nvldbentry)); - ttarray = (struct nvldbentry *) realloc(tarray, tarraysize + parraysize); - if (!ttarray) { - fprintf(STDERR,"Could not allocate enough space for the VLDB entries\n"); - goto bypass; - } - tarray = ttarray; - - /* Copy them in */ - memcpy(((char *)tarray)+tarraysize, (char *)arrayEntries.nbulkentries_val, parraysize); - tarraysize += parraysize; - } - } - - /* Free the bulk array */ - if (arrayEntries.nbulkentries_val) { - free(arrayEntries.nbulkentries_val); - arrayEntries.nbulkentries_val = 0; - } + memset(&arrayEntries, 0, sizeof(arrayEntries)); + centries = 0; + nextindex = -1; + + vcode = + VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries, + &arrayEntries, &nextindex); + if (vcode == RXGEN_OPCODE) { + /* Vlserver not running with ListAttributesN2. Fall back */ + vcode = + VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries); + nextindex = -1; + } + if (vcode) { + fprintf(STDERR, "Could not access the VLDB for attributes\n"); + PrintError("", vcode); + exit(1); + } + nentries += centries; + + /* We don't sort, so just print the entries now */ + if (!sort) { + for (j = 0; j < centries; j++) { /* process each entry */ + vllist = &arrayEntries.nbulkentries_val[j]; + MapHostToNetwork(vllist); + EnumerateEntry(vllist); + + if (vllist->flags & VLOP_ALLOPERS) + fprintf(STDOUT, " Volume is currently LOCKED \n"); + } + } + + /* So we sort. First we must collect all the entries and keep + * them in memory. + */ + else if (centries > 0) { + if (!tarray) { + /* steal away the first bulk entries array */ + tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val; + tarraysize = centries * sizeof(struct nvldbentry); + arrayEntries.nbulkentries_val = 0; + } else { + /* Grow the tarray to keep the extra entries */ + parraysize = (centries * sizeof(struct nvldbentry)); + ttarray = + (struct nvldbentry *)realloc(tarray, + tarraysize + parraysize); + if (!ttarray) { + fprintf(STDERR, + "Could not allocate enough space for the VLDB entries\n"); + goto bypass; + } + tarray = ttarray; + + /* Copy them in */ + memcpy(((char *)tarray) + tarraysize, + (char *)arrayEntries.nbulkentries_val, parraysize); + tarraysize += parraysize; + } + } + + /* Free the bulk array */ + if (arrayEntries.nbulkentries_val) { + free(arrayEntries.nbulkentries_val); + arrayEntries.nbulkentries_val = 0; + } } /* Here is where we now sort all the entries and print them */ if (sort && (nentries > 0)) { - qsort((char *)tarray, nentries, sizeof(struct nvldbentry), CompareVldbEntryByName); - for (vllist=tarray, j=0; jflags & VLOP_ALLOPERS) - fprintf(STDOUT," Volume is currently LOCKED \n"); - } + if (vllist->flags & VLOP_ALLOPERS) + fprintf(STDOUT, " Volume is currently LOCKED \n"); + } } -bypass: - if (!quiet) fprintf(STDOUT,"\nTotal entries: %u\n", nentries); - if (tarray) free(tarray); + bypass: + if (!quiet) + fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries); + if (tarray) + free(tarray); return 0; } -static BackSys(as) - register struct cmd_syndesc *as; -{ - afs_int32 apart=0, avolid; - afs_int32 aserver=0, code, aserver1, apart1; +static +BackSys(as) + register struct cmd_syndesc *as; +{ + afs_int32 apart = 0, avolid; + afs_int32 aserver = 0, code, aserver1, apart1; afs_int32 vcode; struct VldbListByAttributes attributes; nbulkentries arrayEntries; @@ -3367,11 +4160,10 @@ static BackSys(as) int j; char pname[10]; int seenprefix, seenxprefix, exclude, ex, exp, noaction; - afs_int32 totalBack=0; - afs_int32 totalFail=0; - int previdx=-1, error, same; - int comp=0; - char compstr[50]; + afs_int32 totalBack = 0; + afs_int32 totalFail = 0; + int previdx = -1, error, same; + int comp = 0; struct cmd_item *ti; char *ccode; int match; @@ -3379,227 +4171,317 @@ static BackSys(as) memset(&attributes, 0, sizeof(struct VldbListByAttributes)); attributes.Mask = 0; - seenprefix = (as->parms[0].items ? 1 : 0); - exclude = (as->parms[3].items ? 1 : 0); + seenprefix = (as->parms[0].items ? 1 : 0); + exclude = (as->parms[3].items ? 1 : 0); seenxprefix = (as->parms[4].items ? 1 : 0); - noaction = (as->parms[5].items ? 1 : 0); + noaction = (as->parms[5].items ? 1 : 0); - if (as->parms[1].items) { /* -server */ + if (as->parms[1].items) { /* -server */ aserver = GetServer(as->parms[1].items->data); if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data ); + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[1].items->data); exit(1); } - attributes.server = ntohl(aserver); - attributes.Mask |= VLLIST_SERVER; + attributes.server = ntohl(aserver); + attributes.Mask |= VLLIST_SERVER; } - if (as->parms[2].items) { /* -partition */ + if (as->parms[2].items) { /* -partition */ apart = volutil_GetPartitionID(as->parms[2].items->data); if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data); + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[2].items->data); exit(1); } - attributes.partition = apart; - attributes.Mask |= VLLIST_PARTITION; + attributes.partition = apart; + attributes.Mask |= VLLIST_PARTITION; } /* Check to make sure the prefix and xprefix expressions compile ok */ if (seenprefix) { - for (ti=as->parms[0].items; ti; ti=ti->next) { - if (strncmp(ti->data,"^",1) == 0) { - ccode = (char *)re_comp(ti->data); - if (ccode) { - fprintf(STDERR,"Unrecognizable -prefix regular expression: '%s': %s\n", - ti->data, ccode); - exit(1); - } - } - } + for (ti = as->parms[0].items; ti; ti = ti->next) { + if (strncmp(ti->data, "^", 1) == 0) { +#ifdef HAVE_POSIX_REGEX + regex_t re; + char errbuf[256]; + + code = regcomp(&re, ti->data, REG_NOSUB); + if (code != 0) { + regerror(code, &re, errbuf, sizeof errbuf); + fprintf(STDERR, + "Unrecognizable -prefix regular expression: '%s': %s\n", + ti->data, errbuf); + exit(1); + } + regfree(&re); +#else + ccode = (char *)re_comp(ti->data); + if (ccode) { + fprintf(STDERR, + "Unrecognizable -prefix regular expression: '%s': %s\n", + ti->data, ccode); + exit(1); + } +#endif + } + } } if (seenxprefix) { - for (ti=as->parms[4].items; ti; ti=ti->next) { - if (strncmp(ti->data,"^",1) == 0) { - ccode = (char *)re_comp(ti->data); - if (ccode) { - fprintf(STDERR,"Unrecognizable -xprefix regular expression: '%s': %s\n", - ti->data, ccode); - exit(1); - } - } - } - } - - memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */ + for (ti = as->parms[4].items; ti; ti = ti->next) { + if (strncmp(ti->data, "^", 1) == 0) { +#ifdef HAVE_POSIX_REGEX + regex_t re; + char errbuf[256]; + + code = regcomp(&re, ti->data, REG_NOSUB); + if (code != 0) { + regerror(code, &re, errbuf, sizeof errbuf); + fprintf(STDERR, + "Unrecognizable -xprefix regular expression: '%s': %s\n", + ti->data, errbuf); + exit(1); + } + regfree(&re); +#else + ccode = (char *)re_comp(ti->data); + if (ccode) { + fprintf(STDERR, + "Unrecognizable -xprefix regular expression: '%s': %s\n", + ti->data, ccode); + exit(1); + } +#endif + } + } + } + + memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */ vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); if (vcode) { - fprintf(STDERR,"Could not access the VLDB for attributes\n"); - PrintError("",vcode); + fprintf(STDERR, "Could not access the VLDB for attributes\n"); + PrintError("", vcode); exit(1); } if (as->parms[1].items || as->parms[2].items || verbose) { - fprintf(STDOUT,"%s up volumes", (noaction?"Would have backed":"Backing")); + fprintf(STDOUT, "%s up volumes", + (noaction ? "Would have backed" : "Backing")); - if (as->parms[1].items) { - fprintf(STDOUT," on server %s", as->parms[1].items->data); + if (as->parms[1].items) { + fprintf(STDOUT, " on server %s", as->parms[1].items->data); } else if (as->parms[2].items) { - fprintf(STDOUT," for all servers"); + fprintf(STDOUT, " for all servers"); } if (as->parms[2].items) { MapPartIdIntoName(apart, pname); - fprintf(STDOUT," partition %s", pname); + fprintf(STDOUT, " partition %s", pname); } if (seenprefix || (!seenprefix && seenxprefix)) { - ti = (seenprefix ? as->parms[0].items : as->parms[4].items); - ex = (seenprefix ? exclude : !exclude); - exp = (strncmp(ti->data,"^",1) == 0); - fprintf(STDOUT," which %smatch %s '%s'", (ex ? "do not " : ""), - (exp?"expression":"prefix"), ti->data); - for (ti=ti->next; ti; ti=ti->next) { - exp = (strncmp(ti->data,"^",1) == 0); - printf(" %sor %s '%s'", (ex ? "n" : ""), - (exp?"expression":"prefix"), ti->data); + ti = (seenprefix ? as->parms[0].items : as->parms[4].items); + ex = (seenprefix ? exclude : !exclude); + exp = (strncmp(ti->data, "^", 1) == 0); + fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""), + (exp ? "expression" : "prefix"), ti->data); + for (ti = ti->next; ti; ti = ti->next) { + exp = (strncmp(ti->data, "^", 1) == 0); + printf(" %sor %s '%s'", (ex ? "n" : ""), + (exp ? "expression" : "prefix"), ti->data); } } if (seenprefix && seenxprefix) { - ti = as->parms[4].items; - exp = (strncmp(ti->data,"^",1) == 0); - fprintf(STDOUT," %swhich match %s '%s'", - (exclude?"adding those ":"removing those "), - (exp?"expression":"prefix"), ti->data); - for (ti=ti->next; ti; ti=ti->next) { - exp = (strncmp(ti->data,"^",1) == 0); - printf(" or %s '%s'", (exp?"expression":"prefix"), ti->data); + ti = as->parms[4].items; + exp = (strncmp(ti->data, "^", 1) == 0); + fprintf(STDOUT, " %swhich match %s '%s'", + (exclude ? "adding those " : "removing those "), + (exp ? "expression" : "prefix"), ti->data); + for (ti = ti->next; ti; ti = ti->next) { + exp = (strncmp(ti->data, "^", 1) == 0); + printf(" or %s '%s'", (exp ? "expression" : "prefix"), + ti->data); } } - fprintf(STDOUT," .. "); - if (verbose) fprintf(STDOUT,"\n"); + fprintf(STDOUT, " .. "); + if (verbose) + fprintf(STDOUT, "\n"); fflush(STDOUT); } - for (j=0; jparms[0].items; ti; ti=ti->next) { - if (strncmp(ti->data,"^",1) == 0) { - ccode = (char *)re_comp(ti->data); - if (ccode) { - fprintf(STDERR,"Error in -prefix regular expression: '%s': %s\n", - ti->data, ccode); - exit(1); - } - match = (re_exec(vllist->name) == 1); - } else { - match = (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0); - } - if (match) break; - } + for (ti = as->parms[0].items; ti; ti = ti->next) { + if (strncmp(ti->data, "^", 1) == 0) { +#ifdef HAVE_POSIX_REGEX + regex_t re; + char errbuf[256]; + + /* XXX -- should just do the compile once! */ + code = regcomp(&re, ti->data, REG_NOSUB); + if (code != 0) { + regerror(code, &re, errbuf, sizeof errbuf); + fprintf(STDERR, + "Error in -prefix regular expression: '%s': %s\n", + ti->data, errbuf); + exit(1); + } + match = (regexec(&re, vllist->name, 0, NULL, 0) == 0); + regfree(&re); +#else + ccode = (char *)re_comp(ti->data); + if (ccode) { + fprintf(STDERR, + "Error in -prefix regular expression: '%s': %s\n", + ti->data, ccode); + exit(1); + } + match = (re_exec(vllist->name) == 1); +#endif + } else { + match = + (strncmp(vllist->name, ti->data, strlen(ti->data)) == + 0); + } + if (match) + break; + } } else { - match = 1; + match = 1; } - + /* Without the -exclude flag: If it matches the prefix, then * check if we want to exclude any from xprefix. * With the -exclude flag: If it matches the prefix, then * check if we want to add any from xprefix. */ if (match && seenxprefix) { - for (ti=as->parms[4].items; ti; ti=ti->next) { - if (strncmp(ti->data,"^",1) == 0) { - ccode = (char *)re_comp(ti->data); - if (ccode) { - fprintf(STDERR,"Error in -xprefix regular expression: '%s': %s\n", - ti->data, ccode); - exit(1); - } - if (re_exec(vllist->name) == 1) { - match = 0; - break; - } - } else { - if (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0) { - match = 0; - break; - } - } - } + for (ti = as->parms[4].items; ti; ti = ti->next) { + if (strncmp(ti->data, "^", 1) == 0) { +#ifdef HAVE_POSIX_REGEX + regex_t re; + char errbuf[256]; + + /* XXX -- should just do the compile once! */ + code = regcomp(&re, ti->data, REG_NOSUB); + if (code != 0) { + regerror(code, &re, errbuf, sizeof errbuf); + fprintf(STDERR, + "Error in -xprefix regular expression: '%s': %s\n", + ti->data, errbuf); + exit(1); + } + if (regexec(&re, vllist->name, 0, NULL, 0) == 0) + match = 0; + regfree(&re); +#else + ccode = (char *)re_comp(ti->data); + if (ccode) { + fprintf(STDERR, + "Error in -xprefix regular expression: '%s': %s\n", + ti->data, ccode); + exit(1); + } + if (re_exec(vllist->name) == 1) { + match = 0; + break; + } +#endif + } else { + if (strncmp(vllist->name, ti->data, strlen(ti->data)) == + 0) { + match = 0; + break; + } + } + } } - if (exclude) match = !match; /* -exclude will reverse the match */ - if (!match) continue; /* Skip if no match */ + if (exclude) + match = !match; /* -exclude will reverse the match */ + if (!match) + continue; /* Skip if no match */ /* Print list of volumes to backup */ if (noaction) { - fprintf(STDOUT," %s\n", vllist->name); + fprintf(STDOUT, " %s\n", vllist->name); continue; } - if(!(vllist->flags & RW_EXISTS)){ - if(verbose) { - fprintf(STDOUT,"Omitting to backup %s since RW volume does not exist \n", vllist->name); - fprintf(STDOUT,"\n"); + if (!(vllist->flags & RW_EXISTS)) { + if (verbose) { + fprintf(STDOUT, + "Omitting to backup %s since RW volume does not exist \n", + vllist->name); + fprintf(STDOUT, "\n"); } fflush(STDOUT); continue; } - + avolid = vllist->volumeId[RWVOL]; MapHostToNetwork(vllist); - GetServerAndPart(vllist,RWVOL,&aserver1,&apart1,&previdx); - if(aserver1 == -1 || apart1 == -1){ - fprintf(STDOUT,"could not backup %s, invalid VLDB entry\n",vllist->name); + GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx); + if (aserver1 == -1 || apart1 == -1) { + fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n", + vllist->name); totalFail++; continue; } - if (aserver) { + if (aserver) { same = VLDB_IsSameAddrs(aserver, aserver1, &error); if (error) { - fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", + fprintf(STDERR, + "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", aserver, error); totalFail++; continue; } } - if ((aserver && !same) || (apart && (apart != apart1))) { - if(verbose) { - fprintf(STDOUT, "Omitting to backup %s since the RW is in a different location\n", vllist->name); + if ((aserver && !same) || (apart && (apart != apart1))) { + if (verbose) { + fprintf(STDOUT, + "Omitting to backup %s since the RW is in a different location\n", + vllist->name); } continue; } - if(verbose){ + if (verbose) { time_t now = time(0); - fprintf(STDOUT,"Creating backup volume for %s on %s",vllist->name, ctime(&now)); + fprintf(STDOUT, "Creating backup volume for %s on %s", + vllist->name, ctime(&now)); fflush(STDOUT); } code = UV_BackupVolume(aserver1, apart1, avolid); if (code) { - fprintf(STDOUT,"Could not backup %s\n",vllist->name); - totalFail++; - } - else { + fprintf(STDOUT, "Could not backup %s\n", vllist->name); + totalFail++; + } else { totalBack++; } - if (verbose) fprintf(STDOUT,"\n"); + if (verbose) + fprintf(STDOUT, "\n"); fflush(STDOUT); - } /* process each vldb entry */ - fprintf(STDOUT,"done\n"); - fprintf(STDOUT,"Total volumes backed up: %u; failed to backup: %u\n",totalBack,totalFail); + } /* process each vldb entry */ + fprintf(STDOUT, "done\n"); + fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n", + (unsigned long)totalBack, (unsigned long)totalFail); fflush(STDOUT); - if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val); + if (arrayEntries.nbulkentries_val) + free(arrayEntries.nbulkentries_val); return 0; } -static UnlockVLDB(as) -register struct cmd_syndesc *as; -{ +static +UnlockVLDB(as) + register struct cmd_syndesc *as; +{ afs_int32 apart; - afs_int32 aserver,code; + afs_int32 aserver, code; afs_int32 vcode; struct VldbListByAttributes attributes; nbulkentries arrayEntries; @@ -3614,76 +4496,93 @@ register struct cmd_syndesc *as; totalE = 0; attributes.Mask = 0; - if(as->parms[0].items) {/* server specified */ + if (as->parms[0].items) { /* server specified */ aserver = GetServer(as->parms[0].items->data); if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data ); + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); exit(1); } attributes.server = ntohl(aserver); attributes.Mask |= VLLIST_SERVER; } - if(as->parms[1].items) {/* partition specified */ + if (as->parms[1].items) { /* partition specified */ apart = volutil_GetPartitionID(as->parms[1].items->data); if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data); + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); exit(1); } - if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); + if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); exit(1); } attributes.partition = apart; attributes.Mask |= VLLIST_PARTITION; } attributes.flag = VLOP_ALLOPERS; - attributes.Mask |= VLLIST_FLAG; - memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */ + attributes.Mask |= VLLIST_FLAG; + memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */ vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); - if(vcode) { - fprintf(STDERR,"Could not access the VLDB for attributes\n"); - PrintError("",vcode); + if (vcode) { + fprintf(STDERR, "Could not access the VLDB for attributes\n"); + PrintError("", vcode); exit(1); } - for(j=0;jvolumeId[RWVOL]; - vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid,-1, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if(vcode){ - fprintf(STDERR,"Could not unlock entry for volume %s\n",vllist->name); - PrintError("",vcode); + vcode = + ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, "Could not unlock entry for volume %s\n", + vllist->name); + PrintError("", vcode); totalE++; } - + } - MapPartIdIntoName(apart,pname); - if(totalE) fprintf(STDOUT,"Could not lock %u VLDB entries of %u locked entries\n",totalE,nentries); + MapPartIdIntoName(apart, pname); + if (totalE) + fprintf(STDOUT, + "Could not lock %lu VLDB entries of %lu locked entries\n", + (unsigned long)totalE, (unsigned long)nentries); else { - if(as->parms[0].items) { - fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on server %s ",as->parms[0].items->data); - if(as->parms[1].items){ - MapPartIdIntoName(apart,pname); - fprintf(STDOUT,"partition %s\n",pname); - } - else fprintf(STDOUT,"\n"); + if (as->parms[0].items) { + fprintf(STDOUT, + "Unlocked all the VLDB entries for volumes on server %s ", + as->parms[0].items->data); + if (as->parms[1].items) { + MapPartIdIntoName(apart, pname); + fprintf(STDOUT, "partition %s\n", pname); + } else + fprintf(STDOUT, "\n"); - } - else if(as->parms[1].items){ - MapPartIdIntoName(apart,pname); - fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on partition %s on all servers\n",pname); + } else if (as->parms[1].items) { + MapPartIdIntoName(apart, pname); + fprintf(STDOUT, + "Unlocked all the VLDB entries for volumes on partition %s on all servers\n", + pname); } } - - if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val); + + if (arrayEntries.nbulkentries_val) + free(arrayEntries.nbulkentries_val); return 0; } -static PartitionInfo(as) -register struct cmd_syndesc *as; -{ +static +PartitionInfo(as) + register struct cmd_syndesc *as; +{ afs_int32 apart; - afs_int32 aserver,code; + afs_int32 aserver, code; char pname[10]; struct diskPartition partition; struct partList dummyPartList; @@ -3692,321 +4591,599 @@ register struct cmd_syndesc *as; apart = -1; aserver = GetServer(as->parms[0].items->data); if (aserver == 0) { - fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data ); + fprintf(STDERR, "vos: server '%s' not found in host table\n", + as->parms[0].items->data); exit(1); } - if(as->parms[1].items){ + if (as->parms[1].items) { apart = volutil_GetPartitionID(as->parms[1].items->data); if (apart < 0) { - fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data); + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); exit(1); } dummyPartList.partId[0] = apart; dummyPartList.partFlags[0] = PARTVALID; cnt = 1; } - if(apart != -1) { - if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */ - if(code) PrintError("",code); - else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); + if (apart != -1) { + if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); exit(1); } - } - else { - code = UV_ListPartitions(aserver,&dummyPartList, &cnt); + } else { + code = UV_ListPartitions(aserver, &dummyPartList, &cnt); if (code) { PrintDiagnostics("listpart", code); exit(1); } } - for(i = 0 ; i < cnt ; i++){ - if(dummyPartList.partFlags[i] & PARTVALID){ - MapPartIdIntoName(dummyPartList.partId[i],pname); - code = UV_PartitionInfo(aserver,pname,&partition); - if(code){ - fprintf(STDERR,"Could not get information on partition %s\n",pname); - PrintError("",code); + for (i = 0; i < cnt; i++) { + if (dummyPartList.partFlags[i] & PARTVALID) { + MapPartIdIntoName(dummyPartList.partId[i], pname); + code = UV_PartitionInfo(aserver, pname, &partition); + if (code) { + fprintf(STDERR, "Could not get information on partition %s\n", + pname); + PrintError("", code); exit(1); } - fprintf(STDOUT,"Free space on partition %s: %d K blocks out of total %d\n",pname,partition.free,partition.minFree); + fprintf(STDOUT, + "Free space on partition %s: %d K blocks out of total %d\n", + pname, partition.free, partition.minFree); } } return 0; } -static ChangeAddr(as) -register struct cmd_syndesc *as; +static +ChangeAddr(as) + register struct cmd_syndesc *as; { afs_int32 ip1, ip2, vcode; - int remove=0; + int remove = 0; ip1 = GetServer(as->parms[0].items->data); if (!ip1) { - fprintf(STDERR, "vos: invalid host address\n"); - return( EINVAL ); + fprintf(STDERR, "vos: invalid host address\n"); + return (EINVAL); } - if ( ( as->parms[1].items && as->parms[2].items) || - (!as->parms[1].items && !as->parms[2].items) ) { - fprintf(STDERR, "vos: Must specify either '-newaddr ' or '-remove' flag\n"); - return(EINVAL); + if ((as->parms[1].items && as->parms[2].items) + || (!as->parms[1].items && !as->parms[2].items)) { + fprintf(STDERR, + "vos: Must specify either '-newaddr ' or '-remove' flag\n"); + return (EINVAL); } if (as->parms[1].items) { - ip2 = GetServer(as->parms[1].items->data); - if (!ip2) { - fprintf(STDERR, "vos: invalid host address\n"); - return( EINVAL ); - } + ip2 = GetServer(as->parms[1].items->data); + if (!ip2) { + fprintf(STDERR, "vos: invalid host address\n"); + return (EINVAL); + } } else { - /* Play a trick here. If we are removing an address, ip1 will be -1 - * and ip2 will be the original address. This switch prevents an - * older revision vlserver from removing the IP address. - */ - remove = 1; - ip2 = ip1; - ip1 = 0xffffffff; + /* Play a trick here. If we are removing an address, ip1 will be -1 + * and ip2 will be the original address. This switch prevents an + * older revision vlserver from removing the IP address. + */ + remove = 1; + ip2 = ip1; + ip1 = 0xffffffff; } - vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2) ); + vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2)); if (vcode) { - if (remove) { - fprintf(STDERR,"Could not remove server %s from the VLDB\n", - as->parms[0].items->data); - if (vcode == VL_NOENT) { - fprintf(STDERR, "vlserver does not support the remove flag or "); - } + if (remove) { + fprintf(STDERR, "Could not remove server %s from the VLDB\n", + as->parms[0].items->data); + if (vcode == VL_NOENT) { + fprintf(STDERR, + "vlserver does not support the remove flag or "); + } } else { - fprintf(STDERR,"Could not change server %s to server %s\n", - as->parms[0].items->data, as->parms[1].items->data); + fprintf(STDERR, "Could not change server %s to server %s\n", + as->parms[0].items->data, as->parms[1].items->data); } - PrintError("",vcode); - return( vcode ); + PrintError("", vcode); + return (vcode); } if (remove) { - fprintf(STDOUT,"Removed server %s from the VLDB\n", - as->parms[0].items->data); + fprintf(STDOUT, "Removed server %s from the VLDB\n", + as->parms[0].items->data); } else { - fprintf(STDOUT,"Changed server %s to server %s\n", - as->parms[0].items->data, as->parms[1].items->data); + fprintf(STDOUT, "Changed server %s to server %s\n", + as->parms[0].items->data, as->parms[1].items->data); } return 0; } static void -print_addrs(const bulkaddrs *addrs, const afsUUID *m_uuid, int nentries, int print, int noresolve) +print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries, + int print, int noresolve) { - afs_int32 vcode; - afs_int32 i, j; - struct VLCallBack unused; - afs_int32 *addrp; - bulkaddrs m_addrs; - ListAddrByAttributes m_attrs; - afs_int32 m_unique, m_nentries, *m_addrp; - afs_int32 base, index; - char buf[1024]; - - if (print) { - afsUUID_to_string(m_uuid, buf, sizeof(buf)); - printf("UUID: %s\n", buf); - } - - /* print out the list of all the server */ - addrp = (afs_int32 *)addrs->bulkaddrs_val; - for (i=0; i>16) & 0xff; - index = (*addrp) & 0xffff; - - if ( (base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && - (index >= 1) && (index <= VL_MHSRV_PERBLK) ) { - m_attrs.Mask = VLADDR_INDEX; - m_attrs.index = (base * VL_MHSRV_PERBLK) + index; - m_nentries = 0; - m_addrs.bulkaddrs_val = 0; - m_addrs.bulkaddrs_len = 0; - vcode = ubik_Call(VL_GetAddrsU, cstruct, 0, - &m_attrs, &m_uuid, &m_unique, &m_nentries, &m_addrs); - if (vcode) { - fprintf(STDERR,"vos: could not list the multi-homed server addresses\n"); - PrintError("",vcode); - } - - /* Print the list */ - m_addrp = (afs_int32 *)m_addrs.bulkaddrs_val; - for (j=0; j\n"); - } else { - printf("\n"); - } - - continue; - } - } - - /* Otherwise, it is a non-multihomed entry and contains - * the IP address of the server - print it. - */ - *addrp = htonl(*addrp); - if (noresolve) { - char hoststr[16]; - printf("%s\n", afs_inet_ntoa_r(*addrp,hoststr)); - } else { - printf("%s\n", hostutil_GetNameByINet(*addrp)); - } - } - - if (print) { - printf("\n"); - } - return; + afs_int32 vcode; + afs_int32 i, j; + struct VLCallBack vlcb; + afs_int32 *addrp; + bulkaddrs m_addrs; + ListAddrByAttributes m_attrs; + afs_int32 m_nentries, *m_addrp; + afs_int32 base, index; + char buf[1024]; + + if (print) { + afsUUID_to_string(m_uuid, buf, sizeof(buf)); + printf("UUID: %s\n", buf); + } + + /* print out the list of all the server */ + addrp = (afs_int32 *) addrs->bulkaddrs_val; + for (i = 0; i < nentries; i++, addrp++) { + /* If it is a multihomed address, then we will need to + * get the addresses for this multihomed server from + * the vlserver and print them. + */ + if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) { + /* Get the list of multihomed fileservers */ + base = (*addrp >> 16) & 0xff; + index = (*addrp) & 0xffff; + + if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1) + && (index <= VL_MHSRV_PERBLK)) { + m_attrs.Mask = VLADDR_INDEX; + m_attrs.index = (base * VL_MHSRV_PERBLK) + index; + m_nentries = 0; + m_addrs.bulkaddrs_val = 0; + m_addrs.bulkaddrs_len = 0; + vcode = + ubik_Call(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid, + &vlcb, &m_nentries, &m_addrs); + if (vcode) { + fprintf(STDERR, + "vos: could not list the multi-homed server addresses\n"); + PrintError("", vcode); + } + + /* Print the list */ + m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val; + for (j = 0; j < m_nentries; j++, m_addrp++) { + *m_addrp = htonl(*m_addrp); + if (noresolve) { + char hoststr[16]; + printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr)); + } else { + printf("%s ", hostutil_GetNameByINet(*m_addrp)); + } + } + if (j == 0) { + printf("\n"); + } else { + printf("\n"); + } + + continue; + } + } + + /* Otherwise, it is a non-multihomed entry and contains + * the IP address of the server - print it. + */ + *addrp = htonl(*addrp); + if (noresolve) { + char hoststr[16]; + printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr)); + } else { + printf("%s\n", hostutil_GetNameByINet(*addrp)); + } + } + + if (print) { + printf("\n"); + } + return; } -static ListAddrs(as) -register struct cmd_syndesc *as; +static +ListAddrs(as) + register struct cmd_syndesc *as; { - afs_int32 vcode; - afs_int32 i, j, noresolve=0, printuuid=0; - struct VLCallBack unused; - afs_int32 nentries, *addrp; - bulkaddrs addrs, m_addrs; - ListAddrByAttributes m_attrs; - afsUUID m_uuid, askuuid; - afs_int32 m_unique, m_nentries, *m_addrp; - afs_int32 base, index; - - memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes)); - m_attrs.Mask = VLADDR_INDEX; - - memset(&m_addrs, 0, sizeof(bulkaddrs)); - memset(&askuuid, 0, sizeof(afsUUID)); - if (as->parms[0].items) { - /* -uuid */ - afsUUID_from_string(as->parms[0].items->data, &askuuid); - m_attrs.Mask = VLADDR_UUID; - m_attrs.uuid = askuuid; - } - if (as->parms[1].items) { - /* -host */ - struct hostent *he; - afs_int32 saddr; - he = hostutil_GetHostByName((char*)as->parms[1].items->data); - if (he == (struct hostent *)0) { - fprintf(stderr, - "Can't get host info for '%s'\n", - as->parms[1].items->data); - exit(-1); - } - memcpy(&saddr, he->h_addr, 4); - m_attrs.Mask = VLADDR_IPADDR; - m_attrs.ipaddr = ntohl(saddr); - } - if (as->parms[2].items) { - noresolve=1; - } - if (as->parms[3].items) { - printuuid=1; - } - - m_addrs.bulkaddrs_val = 0; - m_addrs.bulkaddrs_len = 0; - - vcode = ubik_Call_New(VL_GetAddrs, cstruct, 0, - 0, 0, &m_unique, &nentries, &m_addrs); - if (vcode) { - fprintf(STDERR,"vos: could not list the server addresses\n"); - PrintError("",vcode); - return( vcode ); - } - - m_nentries = 0; - m_addrs.bulkaddrs_val = 0; - m_addrs.bulkaddrs_len = 0; - i=1; - while (1) { - m_attrs.index = i; - - vcode = ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid, - &m_unique, &m_nentries, &m_addrs); - if(vcode == VL_NOENT) { - i++; - nentries++; - continue; - } - - if (vcode) { - fprintf(STDERR,"vos: could not list the server addresses\n"); - PrintError("",vcode); - return( vcode ); - } - - print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve); - i++; - - if ((as->parms[1].items)||(as->parms[0].items)||(i>nentries)) - break; - } - - return 0; + afs_int32 vcode; + afs_int32 i, noresolve = 0, printuuid = 0; + struct VLCallBack vlcb; + afs_int32 nentries; + bulkaddrs m_addrs; + ListAddrByAttributes m_attrs; + afsUUID m_uuid, askuuid; + afs_int32 m_nentries; + + memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes)); + m_attrs.Mask = VLADDR_INDEX; + + memset(&m_addrs, 0, sizeof(bulkaddrs)); + memset(&askuuid, 0, sizeof(afsUUID)); + if (as->parms[0].items) { + /* -uuid */ + afsUUID_from_string(as->parms[0].items->data, &askuuid); + m_attrs.Mask = VLADDR_UUID; + m_attrs.uuid = askuuid; + } + if (as->parms[1].items) { + /* -host */ + struct hostent *he; + afs_int32 saddr; + he = hostutil_GetHostByName((char *)as->parms[1].items->data); + if (he == NULL) { + fprintf(stderr, "Can't get host info for '%s'\n", + as->parms[1].items->data); + exit(-1); + } + memcpy(&saddr, he->h_addr, 4); + m_attrs.Mask = VLADDR_IPADDR; + m_attrs.ipaddr = ntohl(saddr); + } + if (as->parms[2].items) { + noresolve = 1; + } + if (as->parms[3].items) { + printuuid = 1; + } + + m_addrs.bulkaddrs_val = 0; + m_addrs.bulkaddrs_len = 0; + + vcode = + ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &vlcb, &nentries, + &m_addrs); + if (vcode) { + fprintf(STDERR, "vos: could not list the server addresses\n"); + PrintError("", vcode); + return (vcode); + } + + m_nentries = 0; + m_addrs.bulkaddrs_val = 0; + m_addrs.bulkaddrs_len = 0; + i = 1; + while (1) { + m_attrs.index = i; + + vcode = + ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid, + &vlcb, &m_nentries, &m_addrs); + if (vcode == VL_NOENT) { + i++; + nentries++; + continue; + } + + if (vcode == VL_INDEXERANGE) { + break; + } + + if (vcode) { + fprintf(STDERR, "vos: could not list the server addresses\n"); + PrintError("", vcode); + return (vcode); + } + + print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve); + i++; + + if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries)) + break; + } + + return 0; } -static LockEntry(as) -register struct cmd_syndesc *as; +static +LockEntry(as) + register struct cmd_syndesc *as; { - afs_int32 avolid,vcode, err; + afs_int32 avolid, vcode, err; avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); if (avolid == 0) { - if (err) PrintError("", err); - else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data); + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[0].items->data); exit(1); } - vcode = ubik_Call(VL_SetLock,cstruct, 0, avolid, -1, VLOP_DELETE); - if(vcode){ - fprintf(STDERR,"Could not lock VLDB entry for volume %s\n",as->parms[0].items->data); - PrintError("",vcode); + vcode = ubik_Call(VL_SetLock, cstruct, 0, avolid, -1, VLOP_DELETE); + if (vcode) { + fprintf(STDERR, "Could not lock VLDB entry for volume %s\n", + as->parms[0].items->data); + PrintError("", vcode); exit(1); } - fprintf(STDOUT,"Locked VLDB entry for volume %s\n",as->parms[0].items->data); + fprintf(STDOUT, "Locked VLDB entry for volume %s\n", + as->parms[0].items->data); + return 0; +} + +static +ConvertRO(as) + register struct cmd_syndesc *as; + +{ + afs_int32 partition = -1; + afs_int32 server, volid, code, i, same; + struct nvldbentry entry, storeEntry; + afs_int32 vcode; + afs_int32 rwindex; + afs_int32 rwserver = 0; + afs_int32 rwpartition; + afs_int32 roindex; + afs_int32 roserver = 0; + afs_int32 ropartition; + int force = 0; + struct rx_connection *aconn; + char c, dc; + + server = GetServer(as->parms[0].items->data); + if (!server) { + fprintf(STDERR, "vos: host '%s' not found in host table\n", + as->parms[0].items->data); + return ENOENT; + } + partition = volutil_GetPartitionID(as->parms[1].items->data); + if (partition < 0) { + fprintf(STDERR, "vos: could not interpret partition name '%s'\n", + as->parms[1].items->data); + return ENOENT; + } + if (!IsPartValid(partition, server, &code)) { + if (code) + PrintError("", code); + else + fprintf(STDERR, + "vos : partition %s does not exist on the server\n", + as->parms[1].items->data); + return ENOENT; + } + volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code); + if (volid == 0) { + if (code) + PrintError("", code); + else + fprintf(STDERR, "Unknown volume ID or name '%s'\n", + as->parms[0].items->data); + return -1; + } + if (as->parms[3].items) + force = 1; + + vcode = VLDB_GetEntryByID(volid, -1, &entry); + if (vcode) { + fprintf(STDERR, + "Could not fetch the entry for volume %lu from VLDB\n", + (unsigned long)volid); + PrintError("convertROtoRW", code); + return vcode; + } + + /* use RO volid even if user specified RW or BK volid */ + + if (volid != entry.volumeId[ROVOL]) + volid = entry.volumeId[ROVOL]; + + MapHostToNetwork(&entry); + for (i = 0; i < entry.nServers; i++) { + if (entry.serverFlags[i] & ITSRWVOL) { + rwindex = i; + rwserver = entry.serverNumber[i]; + rwpartition = entry.serverPartition[i]; + } + if (entry.serverFlags[i] & ITSROVOL) { + same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code); + if (code) { + fprintf(STDERR, + "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", + server, code); + return ENOENT; + } + if (same) { + roindex = i; + roserver = entry.serverNumber[i]; + ropartition = entry.serverPartition[i]; + break; + } + } + } + if (!roserver) { + fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n"); + } + if (ropartition != partition) { + fprintf(STDERR, + "Warning: RO volume should be in partition %d instead of %d (vldb)\n", + ropartition, partition); + } + + if (rwserver) { + fprintf(STDERR, + "VLDB indicates that a RW volume exists already on %s in partition %s.\n", + hostutil_GetNameByINet(rwserver), + volutil_PartitionName(rwpartition)); + if (!force) { + fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n"); + dc = c = getchar(); + while (!(dc == EOF || dc == '\n')) + dc = getchar(); /* goto end of line */ + if ((c != 'y') && (c != 'Y')) { + fprintf(STDERR, "aborted.\n"); + return -1; + } + } + } + + vcode = + ubik_Call(VL_SetLock, cstruct, 0, entry.volumeId[RWVOL], RWVOL, + VLOP_MOVE); + aconn = UV_Bind(server, AFSCONF_VOLUMEPORT); + code = AFSVolConvertROtoRWvolume(aconn, partition, volid); + if (code) { + fprintf(STDERR, + "Converting RO volume %lu to RW volume failed with code %d\n", + (unsigned long)volid, code); + PrintError("convertROtoRW ", code); + return -1; + } + entry.serverFlags[roindex] = ITSRWVOL; + entry.flags |= RW_EXISTS; + entry.flags &= ~BACK_EXISTS; + if (rwserver) { + (entry.nServers)--; + if (rwindex != entry.nServers) { + entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers]; + entry.serverPartition[rwindex] = + entry.serverPartition[entry.nServers]; + entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers]; + entry.serverNumber[entry.nServers] = 0; + entry.serverPartition[entry.nServers] = 0; + entry.serverFlags[entry.nServers] = 0; + } + } + entry.flags &= ~RO_EXISTS; + for (i = 0; i < entry.nServers; i++) { + if (entry.serverFlags[i] & ITSROVOL) { + if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE))) + entry.flags |= RO_EXISTS; + } + } + MapNetworkToHost(&entry, &storeEntry); + code = + VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry, + (LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP)); + if (code) { + fprintf(STDERR, + "Warning: volume converted, but vldb update failed with code %d!\n", + code); + } + vcode = UV_LockRelease(entry.volumeId[RWVOL]); + if (vcode) { + PrintDiagnostics("unlock", vcode); + } + return code; +} + +static +Sizes(as) + register struct cmd_syndesc *as; +{ + afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i; + struct nvldbentry entry; + volintSize vol_size; + + rx_SetRxDeadTime(60 * 10); + for (i = 0; i < MAXSERVERS; i++) { + struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i); + if (rxConn == 0) + break; + rx_SetConnDeadTime(rxConn, rx_connDeadTime); + if (rxConn->service) + rxConn->service->connDeadTime = rx_connDeadTime; + } + + avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); + if (avolid == 0) { + if (err) + PrintError("", err); + else + fprintf(STDERR, "vos: can't find volume '%s'\n", + as->parms[0].items->data); + return ENOENT; + } + + if (as->parms[1].items || as->parms[2].items) { + if (!as->parms[1].items || !as->parms[2].items) { + fprintf(STDERR, + "Must specify both -server and -partition options\n"); + return -1; + } + aserver = GetServer(as->parms[2].items->data); + if (aserver == 0) { + fprintf(STDERR, "Invalid server name\n"); + return -1; + } + apart = volutil_GetPartitionID(as->parms[1].items->data); + if (apart < 0) { + fprintf(STDERR, "Invalid partition name\n"); + return -1; + } + } else { + code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry); + if (code) + return code; + } + + fromdate = 0; + + if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) { + code = ktime_DateToInt32(as->parms[4].items->data, &fromdate); + if (code) { + fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n", + as->parms[1].items->data, code); + return code; + } + } + + fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data); + + if (as->parms[3].items) { /* do the dump estimate */ +#ifdef AFS_64BIT_ENV + vol_size.dump_size = 0; +#else + FillInt64(vol_size.dump_size,0, 1); +#endif + code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size); + if (code) { + PrintDiagnostics("size", code); + return code; + } + /* presumably the size info is now gathered in pntr */ + /* now we display it */ + + fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size); + } + + /* Display info */ + return 0; } PrintDiagnostics(astring, acode) - char *astring; - afs_int32 acode; + char *astring; + afs_int32 acode; { if (acode == EACCES) { - fprintf(STDERR,"You are not authorized to perform the 'vos %s' command (%d)\n", + fprintf(STDERR, + "You are not authorized to perform the 'vos %s' command (%d)\n", astring, acode); - } - else { - fprintf(STDERR,"Error in vos %s command.\n", astring); + } else { + fprintf(STDERR, "Error in vos %s command.\n", astring); PrintError("", acode); } return 0; } -static MyBeforeProc(as, arock) -struct cmd_syndesc *as; -char *arock; { +static +MyBeforeProc(as, arock) + struct cmd_syndesc *as; + char *arock; +{ register char *tcell; register afs_int32 code; register afs_int32 sauth; @@ -4016,40 +5193,44 @@ char *arock; { cstruct = (struct ubik_client *)0; sauth = 0; - tcell = (char *) 0; + tcell = NULL; if (as->parms[12].items) /* if -cell specified */ tcell = as->parms[12].items->data; - if(as->parms[14].items) /* -serverauth specified */ + if (as->parms[14].items) /* -serverauth specified */ sauth = 1; - if(as->parms[16].items) /* -crypt specified */ + if (as->parms[16].items) /* -crypt specified */ vsu_SetCrypt(1); - if (code = vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth, - &cstruct, UV_SetSecurity)) { - fprintf(STDERR,"could not initialize VLDB library (code=%u) \n",code); + if ((code = + vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth, + &cstruct, UV_SetSecurity))) { + fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n", + (unsigned long)code); exit(1); } rxInitDone = 1; - if(as->parms[15].items) /* -verbose flag set */ + if (as->parms[15].items) /* -verbose flag set */ verbose = 1; else verbose = 0; return 0; } -int osi_audit() +int +osi_audit() { /* this sucks but it works for now. */ -return 0; + return 0; } #include "AFS_component_version_number.c" main(argc, argv) -int argc; -char **argv; { - register afs_int32 code; - + int argc; + char **argv; +{ + register afs_int32 code; + register struct cmd_syndesc *ts; #ifdef AFS_AIX32_ENV @@ -4060,7 +5241,7 @@ char **argv; { * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; @@ -4069,13 +5250,14 @@ char **argv; { confdir = AFSDIR_CLIENT_ETC_DIRPATH; - cmd_SetBeforeProc(MyBeforeProc, (char *) 0); + cmd_SetBeforeProc(MyBeforeProc, NULL); ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name"); cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name"); - cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "initial quota (KB)"); + cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, + "initial quota (KB)"); #ifdef notdef cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, ""); #endif @@ -4091,18 +5273,82 @@ char **argv; { ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source"); - cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, "partition name on source"); - cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, "machine name on destination"); - cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, "partition name on destination"); + cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, + "partition name on source"); + cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, + "machine name on destination"); + cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, + "partition name on destination"); + cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL, + "copy live volume without cloning"); + COMMONPARMS; + + ts = cmd_CreateSyntax("copy", CopyVolume, 0, "copy a volume"); + cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source"); + cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source"); + cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, + "partition name on source"); + cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination"); + cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, + "machine name on destination"); + cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, + "partition name on destination"); + cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL, + "leave new volume offline"); + cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL, + "make new volume read-only"); + cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL, + "copy live volume without cloning"); + COMMONPARMS; + + ts = cmd_CreateSyntax("shadow", ShadowVolume, 0, + "make or update a shadow volume"); + cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source"); + cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source"); + cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, + "partition name on source"); + cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, + "machine name on destination"); + cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, + "partition name on destination"); + cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL, + "volume name on destination"); + cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL, + "volume ID on destination"); + cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL, + "leave shadow volume offline"); + cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL, + "make shadow volume read-only"); + cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL, + "copy live volume without cloning"); + cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL, + "do incremental update if target exists"); + COMMONPARMS; + + ts = cmd_CreateSyntax("backup", BackupVolume, 0, + "make backup of a volume"); + cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); COMMONPARMS; - ts = cmd_CreateSyntax("backup", BackupVolume, 0, "make backup of a volume"); + ts = cmd_CreateSyntax("clone", CloneVolume, 0, + "make clone of a volume"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); + cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition"); + cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL, + "volume name on destination"); + cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL, + "volume ID on destination"); + cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL, + "leave clone volume offline"); + cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL, + "make clone volume read-only, not readwrite"); COMMONPARMS; ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); - cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force a complete release"); + cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, + "force a complete release"); COMMONPARMS; ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume"); @@ -4111,38 +5357,47 @@ char **argv; { cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file"); cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server"); cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition"); + cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, + "dump a clone of the volume"); COMMONPARMS; ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name"); cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored"); - cmd_AddParm(ts, "-file", CMD_SINGLE,CMD_OPTIONAL, "dump file"); - cmd_AddParm(ts, "-id", CMD_SINGLE,CMD_OPTIONAL, "volume ID"); - cmd_AddParm(ts, "-overwrite", CMD_SINGLE,CMD_OPTIONAL, "abort | full | incremental"); + cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file"); + cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID"); + cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL, + "abort | full | incremental"); cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL, "leave restored volume offline"); cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL, "make restored volume read-only"); COMMONPARMS; - ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0, "release lock on VLDB entry for a volume"); + ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0, + "release lock on VLDB entry for a volume"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); COMMONPARMS; - ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0, "change an RW volume's location in the VLDB"); - cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new location"); - cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name for new location"); + ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0, + "change an RW volume's location in the VLDB"); + cmd_AddParm(ts, "-server", CMD_SINGLE, 0, + "machine name for new location"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, + "partition name for new location"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); COMMONPARMS; ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site"); - cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name for new site"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, + "partition name for new site"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); COMMONPARMS; - ts = cmd_CreateSyntax("remsite", RemoveSite, 0, "remove a replication site"); + ts = cmd_CreateSyntax("remsite", RemoveSite, 0, + "remove a replication site"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); @@ -4152,72 +5407,82 @@ char **argv; { cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); COMMONPARMS; - ts = cmd_CreateSyntax("listvol", ListVolumes, 0, "list volumes on server (bypass VLDB)"); + ts = cmd_CreateSyntax("listvol", ListVolumes, 0, + "list volumes on server (bypass VLDB)"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing"); cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "list all normal volume fields"); - cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information"); + cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, + "generate minimal information"); cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL, "list extended volume fields"); #ifdef FULL_LISTVOL_SWITCH - cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL, - "machine readable format"); + cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL, + "machine readable format"); #endif /* FULL_LISTVOL_SWITCH */ COMMONPARMS; - ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0, "synchronize VLDB with server"); + ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0, + "synchronize VLDB with server"); cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name"); - cmd_AddParm(ts, "-volume", CMD_SINGLE,CMD_OPTIONAL , "volume name or ID"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); + cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID"); COMMONPARMS; - ts = cmd_CreateSyntax("syncserv", SyncServer, 0, "synchronize server with VLDB"); + ts = cmd_CreateSyntax("syncserv", SyncServer, 0, + "synchronize server with VLDB"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); COMMONPARMS; - ts = cmd_CreateSyntax("examine", ExamineVolume, 0, "everything about the volume"); + ts = cmd_CreateSyntax("examine", ExamineVolume, 0, + "everything about the volume"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL, "list extended volume fields"); #ifdef FULL_LISTVOL_SWITCH - cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL, - "machine readable format"); + cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL, + "machine readable format"); #endif /* FULL_LISTVOL_SWITCH */ COMMONPARMS; - cmd_CreateAlias (ts, "volinfo"); + cmd_CreateAlias(ts, "volinfo"); - ts = cmd_CreateSyntax("setfields", SetFields, 0, "change volume info fields"); - cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); + ts = cmd_CreateSyntax("setfields", SetFields, 0, + "change volume info fields"); + cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)"); - cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse"); + cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse"); COMMONPARMS; - ts = cmd_CreateSyntax("offline", volOffline, 0, (char *) CMD_HIDDEN); - cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name"); + ts = cmd_CreateSyntax("offline", volOffline, 0, (char *)CMD_HIDDEN); + cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name"); - cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); + cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep"); - cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume"); + cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume"); COMMONPARMS; - ts = cmd_CreateSyntax("online", volOnline, 0, (char *) CMD_HIDDEN); - cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name"); + ts = cmd_CreateSyntax("online", volOnline, 0, (char *)CMD_HIDDEN); + cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name"); - cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); + cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); COMMONPARMS; - ts = cmd_CreateSyntax("zap", VolumeZap, 0, "delete the volume, don't bother with VLDB"); + ts = cmd_CreateSyntax("zap", VolumeZap, 0, + "delete the volume, don't bother with VLDB"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID"); - cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force deletion of bad volumes"); - cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL, "also delete backup volume if one is found"); + cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, + "force deletion of bad volumes"); + cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL, + "also delete backup volume if one is found"); COMMONPARMS; - ts = cmd_CreateSyntax("status", VolserStatus, 0, "report on volser status"); + ts = cmd_CreateSyntax("status", VolserStatus, 0, + "report on volser status"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); COMMONPARMS; @@ -4226,68 +5491,103 @@ char **argv; { cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name "); COMMONPARMS; - ts = cmd_CreateSyntax("listvldb", ListVLDB, 0, "list volumes in the VLDB"); - cmd_AddParm(ts, "-name", CMD_SINGLE,CMD_OPTIONAL, "volume name or ID"); - cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name"); + ts = cmd_CreateSyntax("listvldb", ListVLDB, 0, + "list volumes in the VLDB"); + cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID"); + cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only"); - cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information"); - cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL, "do not alphabetically sort the volume names"); + cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, + "generate minimal information"); + cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL, + "do not alphabetically sort the volume names"); COMMONPARMS; ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups"); - cmd_AddParm(ts, "-prefix", CMD_LIST,CMD_OPTIONAL, "common prefix on volume(s)"); - cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name"); - cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL, "exclude common prefix volumes"); - cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL, "negative prefix on volume(s)"); + cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL, + "common prefix on volume(s)"); + cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); + cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL, + "exclude common prefix volumes"); + cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL, + "negative prefix on volume(s)"); cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action"); COMMONPARMS; - ts = cmd_CreateSyntax("delentry", DeleteEntry, 0, "delete VLDB entry for a volume"); + ts = cmd_CreateSyntax("delentry", DeleteEntry, 0, + "delete VLDB entry for a volume"); cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID"); - cmd_AddParm(ts, "-prefix", CMD_SINGLE,CMD_OPTIONAL, "prefix of the volume whose VLDB entry is to be deleted"); - cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name"); - cmd_AddParm(ts, "-noexecute", CMD_FLAG,CMD_OPTIONAL|CMD_HIDE, "no execute"); + cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL, + "prefix of the volume whose VLDB entry is to be deleted"); + cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); + cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE, + "no execute"); COMMONPARMS; - ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0, "list partition information"); + ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0, + "list partition information"); cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); COMMONPARMS; - ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0, "unlock all the locked entries in the VLDB"); - cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name"); - cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name"); + ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0, + "unlock all the locked entries in the VLDB"); + cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); COMMONPARMS; - ts = cmd_CreateSyntax("lock", LockEntry, 0, "lock VLDB entry for a volume"); + ts = cmd_CreateSyntax("lock", LockEntry, 0, + "lock VLDB entry for a volume"); cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); COMMONPARMS; - ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0, "change the IP address of a file server"); + ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0, + "change the IP address of a file server"); cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address"); cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address"); - cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL, "remove the IP address from the VLDB"); + cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL, + "remove the IP address from the VLDB"); COMMONPARMS; - ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0, "list the IP address of all file servers registered in the VLDB"); + ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0, + "list the IP address of all file servers registered in the VLDB"); cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server"); cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host"); - cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); - cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL, "print uuid of hosts"); + cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, + "don't resolve addresses"); + cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL, + "print uuid of hosts"); + COMMONPARMS; + + ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, 0, + "convert a RO volume into a RW volume (after loss of old RW volume)"); + cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name"); + cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); + cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask"); + COMMONPARMS; + + ts = cmd_CreateSyntax("size", Sizes, 0, + "obtain various sizes of the volume."); + cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID"); + cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name"); + cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name"); + cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, + "Obtain the size of the dump"); + cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time"); COMMONPARMS; code = cmd_Dispatch(argc, argv); if (rxInitDone) { /* Shut down the ubik_client and rx connections */ if (cstruct) { - ubik_ClientDestroy (cstruct); + (void)ubik_ClientDestroy(cstruct); cstruct = 0; } rx_Finalize(); } - exit((code?-1:0)); + exit((code ? -1 : 0)); } diff --git a/src/volser/vsprocs.c b/src/volser/vsprocs.c index df38a4dd1..7faec4158 100644 --- a/src/volser/vsprocs.c +++ b/src/volser/vsprocs.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vsprocs.c,v 1.2 2002/10/20 19:01:31 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/vsprocs.c,v 1.30 2004/01/08 21:54:10 shadow Exp $"); #include #include @@ -25,6 +26,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vsprocs.c,v 1.2 2002/10/20 19:01 #include #include #endif + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include @@ -36,7 +46,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vsprocs.c,v 1.2 2002/10/20 19:01 #include #include #include -#include "volser.h" +#include "volser.h" #include "volint.h" #include "lockdata.h" #include @@ -44,341 +54,513 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vsprocs.c,v 1.2 2002/10/20 19:01 #include #include #include -#define ERRCODE_RANGE 8 /* from error_table.h */ -#define CLOCKSKEW 2 /* not really skew, but resolution */ +#define ERRCODE_RANGE 8 /* from error_table.h */ +#define CLOCKSKEW 2 /* not really skew, but resolution */ /* for UV_MoveVolume() recovery */ -#include /* signal(), kill(), wait(), etc. */ +#include /* signal(), kill(), wait(), etc. */ #include -afs_int32 VolumeExists(), CheckVldbRWBK(), CheckVldb(); +#include struct ubik_client *cstruct; int verbose = 0; -extern struct rx_securityClass *rxnull_NewClientSecurityObject(); -extern struct rx_connection *rx_NewConnection(); -extern void AFSVolExecuteRequest(); -extern struct rx_securityClass *rxnull_NewServerSecurityObject(); -extern int VL_GetNewVolumeId(); -extern int VL_SetLock(); -extern int VL_ReleaseLock(); -extern int VL_DeleteEntry(); - -void MapNetworkToHost(); -void MapHostToNetwork(); struct release { - afs_int32 time; - afs_int32 vldbEntryIndex; + afs_int32 time; + afs_int32 vldbEntryIndex; }; +/* Utility macros used by rest of this source file */ +#define EPRINT(ec, es) \ +do { \ + fprintf(STDERR, "\n"); \ + fprintf(STDERR, (es)); \ + PrintError(" ",ec); \ +} while (0) + +#define EPRINT1(ec, es, ep1) \ +do { \ + fprintf(STDERR, "\n"); \ + fprintf(STDERR, (es), (ep1)); \ + PrintError(" ",ec); \ +} while (0) + +#define EPRINT2(ec, es, ep1, ep2) \ +do { \ + fprintf(STDERR, "\n"); \ + fprintf(STDERR, (es), (ep1), (ep2)); \ + PrintError(" ",ec); \ +} while (0) + +#define EPRINT3(ec, es, ep1, ep2, ep3) \ +do { \ + fprintf(STDERR, "\n"); \ + fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \ + PrintError(" ",ec); \ +} while (0) + +#define EGOTO(where, ec, es) \ +do { \ + if (ec) { \ + EPRINT((ec),(es)); \ + error = (ec); \ + goto where; \ + } \ +} while (0) + +#define EGOTO1(where, ec, es, ep1) \ +do { \ + if (ec) { \ + EPRINT1((ec),(es),(ep1)); \ + error = (ec); \ + goto where; \ + } \ +} while (0) + +#define EGOTO2(where, ec, es, ep1, ep2) \ +do { \ + if (ec) { \ + EPRINT2((ec),(es),(ep1),(ep2)); \ + error = (ec); \ + goto where; \ + } \ +} while (0) + +#define EGOTO3(where, ec, es, ep1, ep2, ep3) \ +do { \ + if (ec) { \ + EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \ + error = (ec); \ + goto where; \ + } \ +} while (0) + +#define VPRINT(es) \ + { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } } +#define VPRINT1(es, p) \ + { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } } +#define VPRINT2(es, p1, p2) \ + { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } } +#define VPRINT3(es, p1, p2, p3) \ + { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } } +#define VDONE \ + { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } } + + + +/* getting rid of this */ +#define ERROR_EXIT(code) {error=(code); goto error_exit;} + + +/* Protos for static routines */ +static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn, + afs_int32 apart, afs_int32 okvol, + afs_int32 delvol); +static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part, + afs_int32 flags); +static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index, + struct rx_connection **connPtr, afs_int32 * transPtr, + afs_int32 * timePtr); +static int SimulateForwardMultiple(struct rx_connection *fromconn, + afs_int32 fromtid, afs_int32 fromdate, + manyDests * tr, afs_int32 flags, + void *cookie, manyResults * results); +static int rel_compar(struct release *r1, struct release *r2); +static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, + afs_int32 apart, afs_int32 * modentry, + afs_uint32 * maxvolid); + + /*map the partition into partition name */ void -MapPartIdIntoName(partId, partName) -afs_int32 partId; -char *partName; +MapPartIdIntoName(afs_int32 partId, char *partName) { - if(partId < 26) {/* what if partId > = 26 ? */ - strcpy(partName,"/vicep"); + if (partId < 26) { /* what if partId > = 26 ? */ + strcpy(partName, "/vicep"); partName[6] = partId + 'a'; partName[7] = '\0'; return; } else if (partId < VOLMAXPARTS) { - strcpy(partName,"/vicep"); + strcpy(partName, "/vicep"); partId -= 26; - partName[6] = 'a' + (partId/26); - partName[7] = 'a' + (partId%26); + partName[6] = 'a' + (partId / 26); + partName[7] = 'a' + (partId % 26); partName[8] = '\0'; return; } } -yesprompt(str) -char *str; +int +yesprompt(char *str) { int response, c; int code; fprintf(STDERR, "Do you want to %s? [yn](n): ", str); response = c = getchar(); - while (!(c==EOF || c=='\n')) c=getchar(); /*skip to end of line*/ - code = (response=='y'||response=='Y'); + while (!(c == EOF || c == '\n')) + c = getchar(); /*skip to end of line */ + code = (response == 'y' || response == 'Y'); return code; } -PrintError(msg, errcode) - char *msg; - afs_int32 errcode; +int +PrintError(char *msg, afs_int32 errcode) { - fprintf(STDERR,msg); - /*replace by a big switch statement*/ - switch(errcode) { - case 0 : - break; - case -1 : fprintf(STDERR,"Possible communication failure\n"); - break; - case VSALVAGE: fprintf(STDERR,"Volume needs to be salvaged\n"); - break; - case VNOVNODE: fprintf(STDERR,"Bad vnode number quoted\n"); - break; - case VNOVOL: fprintf(STDERR,"Volume not attached, does not exist, or not on line\n"); - break; - case VVOLEXISTS:fprintf(STDERR,"Volume already exists\n"); - break; - case VNOSERVICE:fprintf(STDERR,"Volume is not in service\n"); - break; - case VOFFLINE: fprintf(STDERR,"Volume is off line\n"); - break; - case VONLINE: fprintf(STDERR,"Volume is already on line\n"); - break; - case VDISKFULL: fprintf(STDERR,"Partition is full\n"); - break; - case VOVERQUOTA:fprintf(STDERR,"Volume max quota exceeded\n"); - break; - case VBUSY: fprintf(STDERR,"Volume temporarily unavailable\n"); - break; - case VMOVED:fprintf(STDERR,"Volume has moved to another server\n"); - break; - case VL_IDEXIST : fprintf(STDERR,"VLDB: volume Id exists in the vldb\n"); - break; - case VL_IO: fprintf(STDERR,"VLDB: a read terminated too early\n"); - break; - case VL_NAMEEXIST: fprintf(STDERR,"VLDB: volume entry exists in the vldb\n"); - break; - case VL_CREATEFAIL: fprintf(STDERR,"VLDB: internal creation failure\n"); - break; - case VL_NOENT: fprintf(STDERR,"VLDB: no such entry\n"); - break; - case VL_EMPTY: fprintf(STDERR,"VLDB: vldb database is empty\n"); - break; - case VL_ENTDELETED: fprintf(STDERR,"VLDB: entry is deleted (soft delete)\n"); - break; - case VL_BADNAME: fprintf(STDERR,"VLDB: volume name is illegal\n"); - break; - case VL_BADINDEX: fprintf(STDERR,"VLDB: index was out of range\n"); - break; - case VL_BADVOLTYPE: fprintf(STDERR,"VLDB: bad volume type\n"); - break; - case VL_BADSERVER: fprintf(STDERR,"VLDB: illegal server number (not within limits)\n"); - break; - case VL_BADPARTITION: fprintf(STDERR,"VLDB: bad partition number\n"); - break; - case VL_REPSFULL: fprintf(STDERR,"VLDB: run out of space for replication sites\n"); - break; - case VL_NOREPSERVER: fprintf(STDERR,"VLDB: no such repsite server exists\n"); - break; - case VL_DUPREPSERVER: fprintf(STDERR,"VLDB: replication site server already exists\n"); - break; - case VL_RWNOTFOUND: fprintf(STDERR,"VLDB: parent r/w entry not found\n"); - break; - case VL_BADREFCOUNT: fprintf(STDERR,"VLDB: illegal reference count number\n"); - break; - case VL_SIZEEXCEEDED: fprintf(STDERR,"VLDB: vldb size for attributes exceeded\n"); - break; - case VL_BADENTRY: fprintf(STDERR,"VLDB: bad incoming vldb entry\n"); - break; - case VL_BADVOLIDBUMP: fprintf(STDERR,"VLDB: illegal max volid increment\n"); - break; - case VL_IDALREADYHASHED: fprintf(STDERR,"VLDB: (RO/BACK) Id already hashed\n"); - break; - case VL_ENTRYLOCKED: fprintf(STDERR,"VLDB: vldb entry is already locked\n"); - break; - case VL_BADVOLOPER: fprintf(STDERR,"VLDB: bad volume operation code\n"); - break; - case VL_BADRELLOCKTYPE: fprintf(STDERR,"VLDB: bad release lock type\n"); - break; - case VL_RERELEASE: fprintf(STDERR,"VLDB: status report: last release was aborted\n"); - break; - case VL_BADSERVERFLAG: fprintf(STDERR,"VLDB: invalid replication site server flag\n"); - break; - case VL_PERM: fprintf(STDERR,"VLDB: no permission access for call\n"); - break; - case VOLSERREAD_DUMPERROR:fprintf(STDERR,"VOLSER: Problems encountered in reading the dump file !\n"); - break; - case VOLSERDUMPERROR:fprintf(STDERR,"VOLSER: Problems encountered in doing the dump !\n"); - break; - case VOLSERATTACH_ERROR: fprintf(STDERR,"VOLSER: Could not attach the volume\n"); - break; - case VOLSERDETACH_ERROR: fprintf(STDERR,"VOLSER: Could not detach the volume\n"); - break; - case VOLSERILLEGAL_PARTITION: fprintf(STDERR,"VOLSER: encountered illegal partition number\n"); - break; - case VOLSERBAD_ACCESS: fprintf(STDERR,"VOLSER: permission denied, not a super user\n"); - break; - case VOLSERVLDB_ERROR: fprintf(STDERR,"VOLSER: error detected in the VLDB\n"); - break; - case VOLSERBADNAME: fprintf(STDERR,"VOLSER: error in volume name\n"); - break; - case VOLSERVOLMOVED: fprintf(STDERR,"VOLSER: volume has moved\n"); - break; - case VOLSERBADOP: fprintf(STDERR,"VOLSER: illegal operation\n"); - break; - case VOLSERBADRELEASE: fprintf(STDERR,"VOLSER: release could not be completed\n"); - break; - case VOLSERVOLBUSY: fprintf(STDERR,"VOLSER: volume is busy\n"); - break; - case VOLSERNO_MEMORY: fprintf(STDERR,"VOLSER: volume server is out of memory\n"); - break; - case VOLSERNOVOL:fprintf(STDERR,"VOLSER: no such volume - location specified incorrectly or volume does not exist\n"); - break; - case VOLSERMULTIRWVOL: fprintf(STDERR,"VOLSER: multiple RW volumes with same ID, one of which should be deleted\n"); - break; - case VOLSERFAILEDOP: fprintf(STDERR,"VOLSER: not all entries were successfully processed\n"); - break; - default: - { - - afs_int32 offset; - - initialize_KA_error_table(); - initialize_RXK_error_table(); - initialize_KTC_error_table(); - initialize_ACFG_error_table(); - initialize_CMD_error_table(); - initialize_VL_error_table(); - - offset = errcode & ((1< */ /* takes server address in network order, port in host order. dumb */ -struct rx_connection *UV_Bind(aserver, port) -afs_int32 aserver, port; +struct rx_connection * +UV_Bind(afs_int32 aserver, afs_int32 port) { register struct rx_connection *tc; - - tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass, uvindex); + + tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass, + uvindex); return tc; } /* if is allright(indicated by beibg able to * start a transaction, delete the */ -static afs_int32 CheckAndDeleteVolume(aconn,apart,okvol,delvol) -struct rx_connection *aconn; -afs_int32 apart,okvol,delvol; +static afs_int32 +CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart, + afs_int32 okvol, afs_int32 delvol) { - afs_int32 error,code,tid,rcode; + afs_int32 error, code, tid, rcode; error = 0; code = 0; - if(okvol == 0) { - code = AFSVolTransCreate(aconn, delvol, apart, ITOffline,&tid); - if(!error && code) error = code; - code = AFSVolDeleteVolume(aconn,tid); - if(!error && code) error = code; - code = AFSVolEndTrans(aconn,tid, &rcode); - if(!code) code = rcode; - if(!error && code) error = code; + if (okvol == 0) { + code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid); + if (!error && code) + error = code; + code = AFSVolDeleteVolume(aconn, tid); + if (!error && code) + error = code; + code = AFSVolEndTrans(aconn, tid, &rcode); + if (!code) + code = rcode; + if (!error && code) + error = code; return error; - } - else { - code = AFSVolTransCreate(aconn, okvol, apart, ITOffline,&tid); - if(!code) { - code = AFSVolEndTrans(aconn,tid, &rcode); - if(!code) code = rcode; - if(!error && code) error = code; - code = AFSVolTransCreate(aconn, delvol, apart, ITOffline,&tid); - if(!error && code) error = code; - code = AFSVolDeleteVolume(aconn,tid); - if(!error && code) error = code; - code = AFSVolEndTrans(aconn,tid, &rcode); - if(!code) code = rcode; - if(!error && code) error = code; - } - else + } else { + code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid); + if (!code) { + code = AFSVolEndTrans(aconn, tid, &rcode); + if (!code) + code = rcode; + if (!error && code) + error = code; + code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid); + if (!error && code) + error = code; + code = AFSVolDeleteVolume(aconn, tid); + if (!error && code) + error = code; + code = AFSVolEndTrans(aconn, tid, &rcode); + if (!code) + code = rcode; + if (!error && code) + error = code; + } else error = code; return error; } } /* called by EmuerateEntry, show vldb entry in a reasonable format */ -void SubEnumerateEntry(entry) -struct nvldbentry *entry; +void +SubEnumerateEntry(struct nvldbentry *entry) { int i; char pname[10]; int isMixed = 0; #ifdef notdef - fprintf(STDOUT," readWriteID %-10u ",entry->volumeId[RWVOL]); - if(entry->flags & RW_EXISTS) fprintf(STDOUT," valid \n");else fprintf(STDOUT," invalid \n"); - fprintf(STDOUT," readOnlyID %-10u ",entry->volumeId[ROVOL]); - if(entry->flags & RO_EXISTS) fprintf(STDOUT," valid \n") ;else fprintf(STDOUT," invalid \n"); - fprintf(STDOUT," backUpID %-10u ",entry->volumeId[BACKVOL]); - if(entry->flags & BACK_EXISTS) fprintf(STDOUT," valid \n"); else fprintf(STDOUT," invalid \n"); - if((entry->cloneId != 0) && (entry->flags & RO_EXISTS)) - fprintf(STDOUT," releaseClone %-10u \n",entry->cloneId); + fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]); + if (entry->flags & RW_EXISTS) + fprintf(STDOUT, " valid \n"); + else + fprintf(STDOUT, " invalid \n"); + fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]); + if (entry->flags & RO_EXISTS) + fprintf(STDOUT, " valid \n"); + else + fprintf(STDOUT, " invalid \n"); + fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]); + if (entry->flags & BACK_EXISTS) + fprintf(STDOUT, " valid \n"); + else + fprintf(STDOUT, " invalid \n"); + if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS)) + fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId); #else if (entry->flags & RW_EXISTS) - fprintf(STDOUT," RWrite: %-10u",entry->volumeId[RWVOL]); + fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]); if (entry->flags & RO_EXISTS) - fprintf(STDOUT," ROnly: %-10u",entry->volumeId[ROVOL]); + fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]); if (entry->flags & BACK_EXISTS) - fprintf(STDOUT," Backup: %-10u",entry->volumeId[BACKVOL]); + fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]); if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS)) - fprintf(STDOUT," RClone: %-10u",entry->cloneId); - fprintf(STDOUT,"\n"); + fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId); + fprintf(STDOUT, "\n"); #endif - fprintf(STDOUT," number of sites -> %u\n",entry->nServers); - for(i = 0; i < entry->nServers; i++) { - if(entry->serverFlags[i] & NEW_REPSITE) + fprintf(STDOUT, " number of sites -> %lu\n", + (unsigned long)entry->nServers); + for (i = 0; i < entry->nServers; i++) { + if (entry->serverFlags[i] & NEW_REPSITE) isMixed = 1; } - for(i = 0; i < entry->nServers; i++) { - MapPartIdIntoName(entry->serverPartition[i],pname); - fprintf(STDOUT," server %s partition %s ", + for (i = 0; i < entry->nServers; i++) { + MapPartIdIntoName(entry->serverPartition[i], pname); + fprintf(STDOUT, " server %s partition %s ", hostutil_GetNameByINet(entry->serverNumber[i]), pname); - if(entry->serverFlags[i] & ITSRWVOL) fprintf(STDOUT,"RW Site ") ; else fprintf(STDOUT,"RO Site "); + if (entry->serverFlags[i] & ITSRWVOL) + fprintf(STDOUT, "RW Site "); + else + fprintf(STDOUT, "RO Site "); if (isMixed) { - if (entry->serverFlags[i] & NEW_REPSITE) - fprintf(STDOUT," -- New release"); - else - fprintf(STDOUT," -- Old release"); + if (entry->serverFlags[i] & NEW_REPSITE) + fprintf(STDOUT, " -- New release"); + else + fprintf(STDOUT, " -- Old release"); } else { - if (entry->serverFlags[i] & RO_DONTUSE) - fprintf(STDOUT," -- Not released"); + if (entry->serverFlags[i] & RO_DONTUSE) + fprintf(STDOUT, " -- Not released"); } - fprintf(STDOUT,"\n"); + fprintf(STDOUT, "\n"); } - + return; - + } /*enumerate the vldb entry corresponding to */ -void EnumerateEntry(entry) -struct nvldbentry *entry; +void +EnumerateEntry(struct nvldbentry *entry) { - fprintf(STDOUT,"\n"); - fprintf(STDOUT,"%s \n",entry->name); + fprintf(STDOUT, "\n"); + fprintf(STDOUT, "%s \n", entry->name); SubEnumerateEntry(entry); return; } /* forcibly remove a volume. Very dangerous call */ -UV_NukeVolume(server, partid, volid) -afs_int32 server; -afs_int32 partid, volid; { +int +UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid) +{ register struct rx_connection *tconn; register afs_int32 code; @@ -386,16 +568,15 @@ afs_int32 partid, volid; { if (tconn) { code = AFSVolNukeVolume(tconn, partid, volid); rx_DestroyConnection(tconn); - } - else code = 0; + } else + code = 0; return code; } /* like df. Return usage of on in */ -UV_PartitionInfo(server,pname,partition) -afs_int32 server; -char *pname; -struct diskPartition *partition; +int +UV_PartitionInfo(afs_int32 server, char *pname, + struct diskPartition *partition) { register struct rx_connection *aconn; afs_int32 code; @@ -403,42 +584,40 @@ struct diskPartition *partition; code = 0; aconn = (struct rx_connection *)0; aconn = UV_Bind(server, AFSCONF_VOLUMEPORT); - code = AFSVolPartitionInfo(aconn,pname,partition); - if(code){ - fprintf(STDERR,"Could not get information on partition %s\n",pname); - PrintError("",code); + code = AFSVolPartitionInfo(aconn, pname, partition); + if (code) { + fprintf(STDERR, "Could not get information on partition %s\n", pname); + PrintError("", code); } - if(aconn) rx_DestroyConnection(aconn); + if (aconn) + rx_DestroyConnection(aconn); return code; } /* old interface to create volume */ -UV_CreateVolume(aserver, apart, aname, anewid) -afs_int32 apart, aserver; -char *aname; -afs_int32 *anewid; +int +UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname, + afs_int32 * anewid) { -afs_int32 code; -code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid); -return code; + afs_int32 code; + code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid); + return code; } /* create a volume, given a server, partition number, volume name --> sends * back new vol id in */ -UV_CreateVolume2(aserver, apart, aname, aquota, aspare1, aspare2, aspare3, aspare4, anewid) -afs_int32 apart, aserver; -afs_int32 aspare1, aspare2, aspare3, aspare4; -afs_int32 aquota; -char *aname; -afs_int32 *anewid; +int +UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname, + afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2, + afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid) { register struct rx_connection *aconn; afs_int32 tid; register afs_int32 code; afs_int32 error; - afs_int32 rcode,vcode; - struct nvldbentry entry,storeEntry;/*the new vldb entry */ + afs_int32 rcode, vcode; + struct nvldbentry entry, storeEntry; /*the new vldb entry */ struct volintInfo tstatus; tid = 0; @@ -450,111 +629,106 @@ afs_int32 *anewid; aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); /* next the next 3 available ids from the VLDB */ - vcode = ubik_Call(VL_GetNewVolumeId,cstruct, 0, 3, anewid); - if(vcode) { - fprintf(STDERR,"Could not get an Id for volume %s\n",aname); - error = vcode; - goto cfail; - } - code = AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid); - if (code) { - fprintf(STDERR,"Failed to create the volume %s %u \n",aname,*anewid); - error = code; - goto cfail; - } - + vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 3, anewid); + EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname); + + code = + AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid); + EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname, + *anewid); + code = AFSVolSetInfo(aconn, tid, &tstatus); - if (code) { - fprintf(STDERR,"Could not change quota (error %d), continuing...\n", code); - } + if (code) + EPRINT(code, "Could not change quota (error %d), continuing...\n"); + + code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */ + EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname, + *anewid); + + VPRINT2("Volume %s %u created and brought online\n", aname, *anewid); - code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */ - if (code) { - fprintf(STDERR,"Could not bring the volume %s %u online \n",aname,*anewid); - error = code; - goto cfail; - } - if(verbose) fprintf(STDOUT,"Volume %s %u created and brought online\n",aname,*anewid); /* set up the vldb entry for this volume */ - strncpy(entry.name, aname,VOLSER_OLDMAXVOLNAME); + strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME); entry.nServers = 1; entry.serverNumber[0] = aserver; /* this should have another - level of indirection later */ + * level of indirection later */ entry.serverPartition[0] = apart; /* this should also have - another indirection level */ - entry.flags = RW_EXISTS;/* this records that rw volume exists */ + * another indirection level */ + entry.flags = RW_EXISTS; /* this records that rw volume exists */ entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */ entry.volumeId[RWVOL] = *anewid; - entry.volumeId[ROVOL] = *anewid + 1;/* rw,ro, bk id are related in the default case */ + entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */ entry.volumeId[BACKVOL] = *anewid + 2; entry.cloneId = 0; /*map into right byte order, before passing to xdr, the stuff has to be in host - byte order. Xdr converts it into network order */ - MapNetworkToHost(&entry,&storeEntry); + * byte order. Xdr converts it into network order */ + MapNetworkToHost(&entry, &storeEntry); /* create the vldb entry */ vcode = VLDB_CreateEntry(&storeEntry); - if(vcode) { - fprintf(STDERR,"Could not create a VLDB entry for the volume %s %u\n", aname,*anewid); - /*destroy the created volume*/ - if(verbose) { - fprintf(STDOUT,"Deleting the newly created volume %u\n",*anewid); - } - AFSVolDeleteVolume(aconn,tid); + if (vcode) { + fprintf(STDERR, + "Could not create a VLDB entry for the volume %s %lu\n", + aname, (unsigned long)*anewid); + /*destroy the created volume */ + VPRINT1("Deleting the newly created volume %u\n", *anewid); + AFSVolDeleteVolume(aconn, tid); error = vcode; goto cfail; } - if(verbose) fprintf(STDOUT,"Created the VLDB entry for the volume %s %u\n",aname,*anewid); - /* volume created, now terminate the transaction and release the connection*/ - code = AFSVolEndTrans(aconn, tid, &rcode);/*if it crashes before this - the volume will come online anyway when transaction timesout , so if - vldb entry exists then the volume is guaranteed to exist too wrt create*/ + VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid); + /* volume created, now terminate the transaction and release the connection */ + code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this + * the volume will come online anyway when transaction timesout , so if + * vldb entry exists then the volume is guaranteed to exist too wrt create */ tid = 0; - if(code){ - fprintf(STDERR,"Failed to end the transaction on the volume %s %u\n",aname,*anewid); + if (code) { + fprintf(STDERR, + "Failed to end the transaction on the volume %s %lu\n", aname, + (unsigned long)*anewid); error = code; goto cfail; } - cfail: - if(tid) - { - code= AFSVolEndTrans(aconn, tid, &rcode); - if(code) - fprintf(STDERR,"WARNING: could not end transaction\n"); - } - if(aconn) rx_DestroyConnection(aconn); - PrintError("",error); + cfail: + if (tid) { + code = AFSVolEndTrans(aconn, tid, &rcode); + if (code) + fprintf(STDERR, "WARNING: could not end transaction\n"); + } + if (aconn) + rx_DestroyConnection(aconn); + PrintError("", error); return error; - + } + /* create a volume, given a server, partition number, volume name --> sends * back new vol id in */ -UV_AddVLDBEntry(aserver, apart, aname, aid) - afs_int32 apart, aserver; - char *aname; - afs_int32 aid; +int +UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname, + afs_int32 aid) { register struct rx_connection *aconn; afs_int32 error; afs_int32 vcode; - struct nvldbentry entry,storeEntry;/*the new vldb entry */ + struct nvldbentry entry, storeEntry; /*the new vldb entry */ aconn = (struct rx_connection *)0; error = 0; /* set up the vldb entry for this volume */ - strncpy(entry.name, aname,VOLSER_OLDMAXVOLNAME); + strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME); entry.nServers = 1; entry.serverNumber[0] = aserver; /* this should have another - level of indirection later */ + * level of indirection later */ entry.serverPartition[0] = apart; /* this should also have - another indirection level */ - entry.flags = RW_EXISTS;/* this records that rw volume exists */ + * another indirection level */ + entry.flags = RW_EXISTS; /* this records that rw volume exists */ entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */ entry.volumeId[RWVOL] = aid; #ifdef notdef - entry.volumeId[ROVOL] = anewid + 1;/* rw,ro, bk id are related in the default case */ + entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */ entry.volumeId[BACKVOL] = *anewid + 2; #else entry.volumeId[ROVOL] = 0; @@ -562,37 +736,38 @@ UV_AddVLDBEntry(aserver, apart, aname, aid) #endif entry.cloneId = 0; /*map into right byte order, before passing to xdr, the stuff has to be in host - byte order. Xdr converts it into network order */ - MapNetworkToHost(&entry,&storeEntry); + * byte order. Xdr converts it into network order */ + MapNetworkToHost(&entry, &storeEntry); /* create the vldb entry */ vcode = VLDB_CreateEntry(&storeEntry); - if(vcode) { - fprintf(STDERR,"Could not create a VLDB entry for the volume %s %u\n", aname,aid); + if (vcode) { + fprintf(STDERR, + "Could not create a VLDB entry for the volume %s %lu\n", + aname, (unsigned long)aid); error = vcode; goto cfail; } - if(verbose) fprintf(STDOUT,"Created the VLDB entry for the volume %s %u\n",aname,aid); + VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid); cfail: - if(aconn) rx_DestroyConnection(aconn); - PrintError("",error); + if (aconn) + rx_DestroyConnection(aconn); + PrintError("", error); return error; } -#define ERROR_EXIT(code) {error=(code); goto error_exit;} - /* Delete the volume on * the physical entry gets removed from the vldb only if the ref count * becomes zero */ -UV_DeleteVolume(aserver, apart, avolid) - afs_int32 aserver, apart, avolid; +int +UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid) { struct rx_connection *aconn = (struct rx_connection *)0; afs_int32 ttid = 0; afs_int32 code, rcode; afs_int32 error = 0; - struct nvldbentry entry,storeEntry; + struct nvldbentry entry, storeEntry; int islocked = 0; afs_int32 avoltype = -1, vtype; int notondisk = 0, notinvldb = 0; @@ -601,54 +776,44 @@ UV_DeleteVolume(aserver, apart, avolid) code = ubik_Call(VL_SetLock, cstruct, 0, avolid, avoltype, VLOP_DELETE); if (code) { if (code != VL_NOENT) { - fprintf(STDERR,"Could not lock VLDB entry for the volume %u\n", avolid); - ERROR_EXIT(code); + EGOTO1(error_exit, code, + "Could not lock VLDB entry for the volume %u\n", avolid); } notinvldb = 1; } else { - islocked = 1; + islocked = 1; - code = VLDB_GetEntryByID(avolid, avoltype, &entry); - if (code) { - fprintf(STDERR,"Could not fetch VLDB entry for volume %u\n",avolid); - ERROR_EXIT(code); - } - MapHostToNetwork(&entry); + code = VLDB_GetEntryByID(avolid, avoltype, &entry); + EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n", + avolid); + MapHostToNetwork(&entry); - if (verbose) - EnumerateEntry(&entry); + if (verbose) + EnumerateEntry(&entry); } /* Whether volume is in the VLDB or not. Delete the volume on disk */ aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid); if (code) { - if (code == VNOVOL) { - notondisk = 1; - } else { - fprintf(STDERR,"Transaction on volume %u failed\n", avolid); - ERROR_EXIT(code); - } - } - else { - if (verbose) { - fprintf(STDOUT,"Trying to delete the volume %u ...", avolid); - fflush(STDOUT); - } - code = AFSVolDeleteVolume(aconn, ttid); - if (code) { - fprintf(STDERR,"Could not delete the volume %u \n", avolid); - ERROR_EXIT(code); - } - code = AFSVolEndTrans(aconn, ttid, &rcode); - code = (code ? code : rcode); - ttid = 0; - if (code) { - fprintf(STDERR,"Could not end the transaction for the volume %u \n",avolid); - ERROR_EXIT(code); - } - if (verbose) - fprintf(STDOUT," done\n"); + if (code == VNOVOL) { + notondisk = 1; + } else { + EGOTO1(error_exit, code, "Transaction on volume %u failed\n", + avolid); + } + } else { + VPRINT1("Trying to delete the volume %u ...", avolid); + + code = AFSVolDeleteVolume(aconn, ttid); + EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid); + + code = AFSVolEndTrans(aconn, ttid, &rcode); + code = (code ? code : rcode); + ttid = 0; + EGOTO1(error_exit, code, + "Could not end the transaction for the volume %u \n", avolid); + VDONE; } /* Now update the VLDB entry. @@ -656,19 +821,18 @@ UV_DeleteVolume(aserver, apart, avolid) * Whether volume is on disk or not. Delete the volume in VLDB. */ if (notinvldb) - ERROR_EXIT(0); + ERROR_EXIT(0); if (avolid == entry.volumeId[BACKVOL]) { /* Its a backup volume, modify the VLDB entry. Check that the * backup volume is on the server/partition we asked to delete. */ - if ( !(entry.flags & BACK_EXISTS) || !Lp_Match(aserver,apart,&entry)) { - notinvldb = 2; /* Not on this server and partition */ - ERROR_EXIT(0); + if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) { + notinvldb = 2; /* Not on this server and partition */ + ERROR_EXIT(0); } - if (verbose) - fprintf(STDOUT,"Marking the backup volume %u deleted in the VLDB\n", avolid); + VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid); entry.flags &= ~BACK_EXISTS; vtype = BACKVOL; @@ -680,58 +844,64 @@ UV_DeleteVolume(aserver, apart, avolid) * If flags does not have RO_EIXSTS set, then this may mean the RO * hasn't been released (and could exist in VLDB). */ - if (!Lp_ROMatch(aserver,apart,&entry)) { - notinvldb = 2; /* Not found on this server and partition */ - ERROR_EXIT(0); + if (!Lp_ROMatch(aserver, apart, &entry)) { + notinvldb = 2; /* Not found on this server and partition */ + ERROR_EXIT(0); } - + if (verbose) - fprintf(STDOUT,"Marking the readonly volume %u deleted in the VLDB\n", avolid); + fprintf(STDOUT, + "Marking the readonly volume %lu deleted in the VLDB\n", + (unsigned long)avolid); - Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */ + Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */ entry.nServers--; - if (!Lp_ROMatch(0,0,&entry)) - entry.flags &= ~RO_EXISTS; /* This was the last ro volume */ + if (!Lp_ROMatch(0, 0, &entry)) + entry.flags &= ~RO_EXISTS; /* This was the last ro volume */ vtype = ROVOL; } else if (avolid == entry.volumeId[RWVOL]) { - /* It's a rw volume, delete the backup volume, modify the VLDB entry. + /* It's a rw volume, delete the backup volume, modify the VLDB entry. * Check that the readwrite volumes is on the server/partition we * asked to delete. */ - if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver,apart,&entry)) { - notinvldb = 2; /* Not found on this server and partition */ - ERROR_EXIT(0); + if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) { + notinvldb = 2; /* Not found on this server and partition */ + ERROR_EXIT(0); } - + /* Delete backup if it exists */ - code = AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart, ITOffline, &ttid); + code = + AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart, + ITOffline, &ttid); if (!code) { - if (verbose) { - fprintf(STDOUT,"Trying to delete the backup volume %u ...", entry.volumeId[BACKVOL]); - fflush(STDOUT); - } - code = AFSVolDeleteVolume(aconn, ttid); - if (code) { - fprintf(STDERR,"Could not delete the volume %u \n", entry.volumeId[BACKVOL]); - ERROR_EXIT(code); - } - code = AFSVolEndTrans(aconn, ttid, &rcode); - ttid = 0; - code = (code ? code : rcode); - if (code) { - fprintf(STDERR,"Could not end the transaction for the volume %u \n", - entry.volumeId[BACKVOL]); - ERROR_EXIT(code); - } - if (verbose) - fprintf(STDOUT," done\n"); + if (verbose) { + fprintf(STDOUT, "Trying to delete the backup volume %u ...", + entry.volumeId[BACKVOL]); + fflush(STDOUT); + } + code = AFSVolDeleteVolume(aconn, ttid); + EGOTO1(error_exit, code, "Could not delete the volume %u \n", + entry.volumeId[BACKVOL]); + + code = AFSVolEndTrans(aconn, ttid, &rcode); + ttid = 0; + code = (code ? code : rcode); + EGOTO1(error_exit, code, + "Could not end the transaction for the volume %u \n", + entry.volumeId[BACKVOL]); + if (verbose) + fprintf(STDOUT, " done\n"); } if (verbose) - fprintf(STDOUT,"Marking the readwrite volume %u%s deleted in the VLDB\n", - avolid, ((entry.flags & BACK_EXISTS)?", and its backup volume,":"")); + fprintf(STDOUT, + "Marking the readwrite volume %lu%s deleted in the VLDB\n", + (unsigned long)avolid, + ((entry. + flags & BACK_EXISTS) ? ", and its backup volume," : + "")); Lp_SetRWValue(&entry, aserver, apart, 0L, 0L); entry.nServers--; @@ -739,131 +909,139 @@ UV_DeleteVolume(aserver, apart, avolid) vtype = RWVOL; if (entry.flags & RO_EXISTS) - fprintf(STDERR,"WARNING: ReadOnly copy(s) may still exist\n"); + fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n"); } else { - notinvldb = 2; /* Not found on this server and partition */ - ERROR_EXIT(0); + notinvldb = 2; /* Not found on this server and partition */ + ERROR_EXIT(0); } /* Either delete or replace the VLDB entry */ if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) { - if (verbose) - fprintf(STDOUT,"Last reference to the VLDB entry for %u - deleting entry\n", avolid); - code = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, vtype); - if (code) { - fprintf(STDERR,"Could not delete the VLDB entry for the volume %u \n",avolid); - ERROR_EXIT(code); - } + if (verbose) + fprintf(STDOUT, + "Last reference to the VLDB entry for %lu - deleting entry\n", + (unsigned long)avolid); + code = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, vtype); + EGOTO1(error_exit, code, + "Could not delete the VLDB entry for the volume %u \n", + avolid); } else { - MapNetworkToHost(&entry, &storeEntry); - code = VLDB_ReplaceEntry(avolid, vtype, &storeEntry, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); - if (code) { - fprintf(STDERR,"Could not update the VLDB entry for the volume %u \n", avolid); - ERROR_EXIT(code); - } + MapNetworkToHost(&entry, &storeEntry); + code = + VLDB_ReplaceEntry(avolid, vtype, &storeEntry, + (LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP)); + EGOTO1(error_exit, code, + "Could not update the VLDB entry for the volume %u \n", + avolid); } islocked = 0; error_exit: - if (error) PrintError("", error); + if (error) + EPRINT(error, "\n"); if (notondisk && notinvldb) { - fprintf(STDERR,"Volume %u does not exist %s\n", - avolid, ((notinvldb == 2)?"on server and partition":"")); - PrintError("", VOLSERNOVOL); - if (!error) error = VOLSERNOVOL; - } - else if (notondisk) { - fprintf(STDERR,"WARNING: Volume %u did not exist on the partition\n", avolid); - } - else if (notinvldb) { - fprintf(STDERR,"WARNING: Volume %u does not exist in VLDB %s\n", - avolid, ((notinvldb == 2)?"on server and partition":"")); + EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid, + ((notinvldb == 2) ? "on server and partition" : "")); + if (!error) + error = VOLSERNOVOL; + } else if (notondisk) { + fprintf(STDERR, + "WARNING: Volume %lu did not exist on the partition\n", + (unsigned long)avolid); + } else if (notinvldb) { + fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n", + (unsigned long)avolid, + ((notinvldb == 2) ? "on server and partition" : "")); } if (ttid) { code = AFSVolEndTrans(aconn, ttid, &rcode); code = (code ? code : rcode); if (code) { - fprintf(STDERR,"Could not end transaction on the volume %u\n", avolid); + fprintf(STDERR, "Could not end transaction on the volume %lu\n", + (unsigned long)avolid); PrintError("", code); - if (!error) error = code; + if (!error) + error = code; } } if (islocked) { - code = ubik_Call(VL_ReleaseLock,cstruct, 0, avolid, -1, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); + code = + ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, -1, + (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); if (code) { - fprintf(STDERR,"Could not release the lock on the VLDB entry for the volume %u \n", + EPRINT1(code, + "Could not release the lock on the VLDB entry for the volume %u \n", avolid); - PrintError("", code); - if (!error) error = code; + if (!error) + error = code; } } - if (aconn) rx_DestroyConnection(aconn); + if (aconn) + rx_DestroyConnection(aconn); return error; } /* add recovery to UV_MoveVolume */ -#define TESTC 0 /* set to test recovery code, clear for production */ +#define TESTC 0 /* set to test recovery code, clear for production */ jmp_buf env; -int interrupt=0; +int interrupt = 0; -void sigint_handler(x) +void +sigint_handler(int x) { - if(interrupt) - longjmp(env,0); + if (interrupt) + longjmp(env, 0); - fprintf(STDOUT, - "\nSIGINT handler: vos move operation in progress\n"); - fprintf(STDOUT, - "WARNING: may leave AFS storage and metadata in indeterminate state\n"); - fprintf(STDOUT, - "enter second control-c to exit\n"); - fflush(STDOUT); + fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n"); + fprintf(STDOUT, + "WARNING: may leave AFS storage and metadata in indeterminate state\n"); + fprintf(STDOUT, "enter second control-c to exit\n"); + fflush(STDOUT); - interrupt=1; - signal(SIGINT,sigint_handler); + interrupt = 1; + (void)signal(SIGINT, sigint_handler); - return; + return; } -#define ONERR(ec, es, ep) if (ec) { fprintf(STDERR, (es), (ep)); PrintError(" ",ec); error = (ec); goto mfail; } - /* Move volume on to - * . The operation is almost idempotent + * . The operation is almost idempotent. The following + * flags are recognized: + * + * RV_NOCLONE - don't use a copy clone */ -UV_MoveVolume(afromvol, afromserver, afrompart, atoserver, atopart) - afs_int32 afromvol; - afs_int32 afromserver, atoserver; - afs_int32 afrompart, atopart; +int +UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart, + afs_int32 atoserver, afs_int32 atopart, int flags) { - struct rx_connection *toconn, *fromconn ; - afs_int32 fromtid, totid, clonetid; - char vname[64]; - char *volName = 0; - char tmpName[VOLSER_MAXVOLNAME +1]; - afs_int32 rcode; - afs_int32 fromDate; + struct rx_connection *toconn, *fromconn; + afs_int32 fromtid, totid, clonetid; + char vname[64]; + char *volName = 0; + char tmpName[VOLSER_MAXVOLNAME + 1]; + afs_int32 rcode; + afs_int32 fromDate; struct restoreCookie cookie; - register afs_int32 vcode, code; - afs_int32 newVol, volid, backupId; + register afs_int32 vcode, code; + afs_int32 newVol, volid, backupId; struct volser_status tstatus; - struct destServer destination; + struct destServer destination; - struct nvldbentry entry, storeEntry; - int i, islocked, pntg; - afs_int32 error; - char in,lf; /* for test code */ - int same; + struct nvldbentry entry, storeEntry; + int i, islocked, pntg; + afs_int32 error; + char in, lf; /* for test code */ + int same; #ifdef ENABLE_BUGFIX_1165 volEntries volumeInfo; @@ -872,35 +1050,33 @@ UV_MoveVolume(afromvol, afromserver, afrompart, atoserver, atopart) islocked = 0; fromconn = (struct rx_connection *)0; - toconn = (struct rx_connection *)0; - fromtid = 0; - totid = 0; + toconn = (struct rx_connection *)0; + fromtid = 0; + totid = 0; clonetid = 0; - error = 0; - volid = 0; - pntg = 0; + error = 0; + volid = 0; + pntg = 0; backupId = 0; - newVol = 0; + newVol = 0; /* support control-c processing */ - if (setjmp(env)) goto mfail; - (void) signal(SIGINT,sigint_handler); - - if (TESTC) - { - fprintf(STDOUT, + if (setjmp(env)) + goto mfail; + (void)signal(SIGINT, sigint_handler); + + if (TESTC) { + fprintf(STDOUT, "\nThere are three tests points - verifies all code paths through recovery.\n"); - fprintf(STDOUT,"First test point - operation not started.\n"); - fprintf(STDOUT,"...test here (y, n)? "); + fprintf(STDOUT, "First test point - operation not started.\n"); + fprintf(STDOUT, "...test here (y, n)? "); fflush(STDOUT); - fscanf(stdin,"%c",&in); - fscanf(stdin,"%c",&lf); /* toss away */ - if (in=='y') - { - fprintf(STDOUT,"type control-c\n"); - while(1) - { - fprintf(stdout,"."); + fscanf(stdin, "%c", &in); + fscanf(stdin, "%c", &lf); /* toss away */ + if (in == 'y') { + fprintf(STDOUT, "type control-c\n"); + while (1) { + fprintf(stdout, "."); fflush(stdout); sleep(1); } @@ -909,45 +1085,49 @@ UV_MoveVolume(afromvol, afromserver, afrompart, atoserver, atopart) } vcode = VLDB_GetEntryByID(afromvol, -1, &entry); - ONERR (vcode, "Could not fetch the entry for the volume %u from the VLDB \n", afromvol); + EGOTO1(mfail, vcode, + "Could not fetch the entry for the volume %u from the VLDB \n", + afromvol); - if (entry.volumeId[RWVOL] != afromvol) - { - fprintf(STDERR,"Only RW volume can be moved\n"); + if (entry.volumeId[RWVOL] != afromvol) { + fprintf(STDERR, "Only RW volume can be moved\n"); exit(1); } - vcode = ubik_Call(VL_SetLock, cstruct, 0,afromvol, RWVOL, VLOP_MOVE); - ONERR (vcode, "Could not lock entry for volume %u \n", afromvol); + vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_MOVE); + EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol); islocked = 1; - vcode = VLDB_GetEntryByID (afromvol, RWVOL, &entry); - ONERR (vcode, "Could not fetch the entry for the volume %u from the VLDB \n", afromvol); + vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry); + EGOTO1(mfail, vcode, + "Could not fetch the entry for the volume %u from the VLDB \n", + afromvol); backupId = entry.volumeId[BACKVOL]; MapHostToNetwork(&entry); - if ( !Lp_Match(afromserver, afrompart, &entry) ) - { + if (!Lp_Match(afromserver, afrompart, &entry)) { /* the from server and partition do not exist in the vldb entry corresponding to volid */ - if ( !Lp_Match(atoserver, atopart, &entry) ) - { + if (!Lp_Match(atoserver, atopart, &entry)) { /* the to server and partition do not exist in the vldb entry corresponding to volid */ - fprintf(STDERR,"The volume %u is not on the specified site. \n", afromvol); - fprintf(STDERR,"The current site is :"); - for (i=0; imaxquota = -1; /* Else it will replace the default quota */ + infop->maxquota = -1; /* Else it will replace the default quota */ #endif /* create a volume on the target machine */ volid = afromvol; - code = AFSVolTransCreate (toconn, volid, atopart, ITOffline, &totid); - if (!code) - { - /* Delete the existing volume. - * While we are deleting the volume in these steps, the transaction - * we started against the cloned volume (clonetid above) will be - * sitting idle. It will get cleaned up after 600 seconds - */ - if (verbose) fprintf(STDOUT,"Deleting pre-existing volume %u on destination ...",volid); - fflush(STDOUT); - + code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid); + if (!code) { + /* Delete the existing volume. + * While we are deleting the volume in these steps, the transaction + * we started against the cloned volume (clonetid above) will be + * sitting idle. It will get cleaned up after 600 seconds + */ + VPRINT1("Deleting pre-existing volume %u on destination ...", volid); code = AFSVolDeleteVolume(toconn, totid); - ONERR (code, "Could not delete the pre-existing volume %u on destination\n", volid); - + EGOTO1(mfail, code, + "Could not delete the pre-existing volume %u on destination\n", + volid); + VDONE; + + VPRINT1 + ("Ending transaction on pre-existing volume %u on destination ...", + volid); code = AFSVolEndTrans(toconn, totid, &rcode); totid = 0; - if (!code) code = rcode; - ONERR (code, "Could not end the transaction on pre-existing volume %u on destination\n", + if (!code) + code = rcode; + EGOTO1(mfail, code, + "Could not end the transaction on pre-existing volume %u on destination\n", volid); - - if (verbose) fprintf(STDOUT," done\n"); + VDONE; } - if (verbose) fprintf(STDOUT,"Creating the destination volume %u ...",volid); - fflush(STDOUT); - code = AFSVolCreateVolume (toconn, atopart, volName, volser_RW, volid, &volid, &totid); - ONERR (code, "Failed to create the destination volume %u\n", volid); - if (verbose) fprintf(STDOUT," done\n"); + VPRINT1("Creating the destination volume %u ...", volid); + code = + AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid, + &totid); + EGOTO1(mfail, code, "Failed to create the destination volume %u\n", + volid); + VDONE; strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME); free(volName); - volName = (char *) 0; + volName = NULL; - code = AFSVolSetFlags (toconn, totid, (VTDeleteOnSalvage | VTOutOfService)); - ONERR(code, "Failed to set the flags on the destination volume %u\n", volid); + VPRINT1("Setting volume flags on destination volume %u ...", volid); + code = + AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService)); + EGOTO1(mfail, code, + "Failed to set the flags on the destination volume %u\n", volid); + VDONE; /*** * Now dump the clone to the new volume @@ -1138,75 +1395,104 @@ UV_MoveVolume(afromvol, afromserver, afrompart, atoserver, atopart) destination.destPort = AFSCONF_VOLUMEPORT; destination.destSSID = 1; - /* Copy the clone to the new volume */ - if (verbose) fprintf(STDOUT, "Dumping from clone %u on source to volume %u on destination ...", - newVol, afromvol); - fflush(STDOUT); - strncpy(cookie.name,tmpName,VOLSER_OLDMAXVOLNAME); - cookie.type = RWVOL; + strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME); + cookie.type = RWVOL; cookie.parent = entry.volumeId[RWVOL]; - cookie.clone = 0; - code = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie); - ONERR (code, "Failed to move data for the volume %u\n", volid); - if (verbose) fprintf(STDOUT," done\n"); + cookie.clone = 0; - code = AFSVolEndTrans(fromconn, clonetid, &rcode); - if (!code) code = rcode; - clonetid = 0; - ONERR (code, "Failed to end the transaction on the cloned volume %u\n", newVol); + if (!(flags & RV_NOCLONE)) { + /* Copy the clone to the new volume */ + VPRINT2("Dumping from clone %u on source to volume %u on destination ...", + newVol, afromvol); + code = + AFSVolForward(fromconn, clonetid, 0, &destination, totid, + &cookie); + EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid); + VDONE; + + VPRINT1("Ending transaction on cloned volume %u ...", newVol); + code = AFSVolEndTrans(fromconn, clonetid, &rcode); + if (!code) + code = rcode; + clonetid = 0; + EGOTO1(mfail, code, + "Failed to end the transaction on the cloned volume %u\n", + newVol); + VDONE; + } /* *** * reattach to the main-line volume, and incrementally dump it. * ***/ - if (verbose) - fprintf(STDOUT,"Doing the incremental dump from source to destination for volume %u ... ", - afromvol); - fflush(STDOUT); - + VPRINT1("Starting transaction on source volume %u ...", afromvol); code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid); - ONERR (code, "Failed to create a transaction on the source volume %u\n", afromvol); + EGOTO1(mfail, code, + "Failed to create a transaction on the source volume %u\n", + afromvol); + VDONE; /* now do the incremental */ - code = AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,&cookie); - ONERR (code, "Failed to do the incremental dump from rw volume on old site to rw volume on newsite\n", 0); - if (verbose)fprintf(STDOUT," done\n"); + VPRINT2 + ("Doing the%s dump from source to destination for volume %u ... ", + (flags & RV_NOCLONE) ? "" : " incremental", + afromvol); + code = + AFSVolForward(fromconn, fromtid, fromDate, &destination, totid, + &cookie); + EGOTO1(mfail, code, + "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n", + (flags & RV_NOCLONE) ? "" : " incremental"); + VDONE; /* now adjust the flags so that the new volume becomes official */ + VPRINT1("Setting volume flags on old source volume %u ...", afromvol); code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService); - ONERR (code, "Failed to set the flags to make old source volume offline\n", 0); + EGOTO(mfail, code, + "Failed to set the flags to make old source volume offline\n"); + VDONE; + VPRINT1("Setting volume flags on new source volume %u ...", afromvol); code = AFSVolSetFlags(toconn, totid, 0); - ONERR (code, "Failed to set the flags to make new source volume online\n", 0); + EGOTO(mfail, code, + "Failed to set the flags to make new source volume online\n"); + VDONE; #ifdef ENABLE_BUGFIX_1165 + VPRINT1("Setting volume status on destination volume %u ...", volid); code = AFSVolSetInfo(toconn, totid, infop); - ONERR (code, "Failed to set volume status on the destination volume %u\n", volid); + EGOTO1(mfail, code, + "Failed to set volume status on the destination volume %u\n", + volid); + VDONE; #endif /* put new volume online */ + VPRINT1("Ending transaction on destination volume %u ...", afromvol); code = AFSVolEndTrans(toconn, totid, &rcode); totid = 0; - if (!code) code = rcode; - ONERR (code, "Failed to end the transaction on the volume %u on the new site\n", afromvol); + if (!code) + code = rcode; + EGOTO1(mfail, code, + "Failed to end the transaction on the volume %u on the new site\n", + afromvol); + VDONE; Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart); - MapNetworkToHost(&entry,&storeEntry); + MapNetworkToHost(&entry, &storeEntry); storeEntry.flags &= ~BACK_EXISTS; - if (TESTC) - { - fprintf(STDOUT, "Second test point - operation in progress but not complete.\n"); - fprintf(STDOUT,"...test here (y, n)? "); + if (TESTC) { + fprintf(STDOUT, + "Second test point - operation in progress but not complete.\n"); + fprintf(STDOUT, "...test here (y, n)? "); fflush(STDOUT); - fscanf(stdin,"%c",&in); - fscanf(stdin,"%c",&lf); /* toss away */ - if (in=='y') - { - fprintf(STDOUT,"type control-c\n"); - while(1) - { - fprintf(stdout,"."); + fscanf(stdin, "%c", &in); + fscanf(stdin, "%c", &lf); /* toss away */ + if (in == 'y') { + fprintf(STDOUT, "type control-c\n"); + while (1) { + fprintf(stdout, "."); fflush(stdout); sleep(1); } @@ -1214,37 +1500,38 @@ UV_MoveVolume(afromvol, afromserver, afrompart, atoserver, atopart) /* or drop through */ } - vcode = VLDB_ReplaceEntry (afromvol, -1, &storeEntry, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); - if (vcode) - { - fprintf(STDERR," Could not release the lock on the VLDB entry for the volume %s %u \n", - storeEntry.name,afromvol); + VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol); + vcode = + VLDB_ReplaceEntry(afromvol, -1, &storeEntry, + (LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP)); + if (vcode) { + fprintf(STDERR, + " Could not release the lock on the VLDB entry for the volume %s %lu \n", + storeEntry.name, (unsigned long)afromvol); error = vcode; goto mfail; } - islocked=0; + islocked = 0; + VDONE; - if (TESTC) - { - fprintf(STDOUT, "Third test point - operation complete but no cleanup.\n"); - fprintf(STDOUT,"...test here (y, n)? "); + if (TESTC) { + fprintf(STDOUT, + "Third test point - operation complete but no cleanup.\n"); + fprintf(STDOUT, "...test here (y, n)? "); fflush(STDOUT); - fscanf(stdin,"%c",&in); - fscanf(stdin,"%c",&lf); /* toss away */ - if (in=='y') - { - fprintf(STDOUT,"type control-c\n"); - while(1) - { - fprintf(stdout,"."); + fscanf(stdin, "%c", &in); + fscanf(stdin, "%c", &lf); /* toss away */ + if (in == 'y') { + fprintf(STDOUT, "type control-c\n"); + while (1) { + fprintf(stdout, "."); fflush(stdout); sleep(1); } } /* or drop through */ } - #ifdef notdef /* This is tricky. File server is very stupid, and if you mark the volume * as VTOutOfService, it may mark the *good* instance (if you're moving @@ -1252,94 +1539,119 @@ UV_MoveVolume(afromvol, afromserver, afrompart, atoserver, atopart) * we're cleaning this code up in DEcorum, we're just going to kludge around * it for now by removing this call. */ /* already out of service, just zap it now */ - code = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService); - if (code) - { - fprintf(STDERR,"Failed to set the flags to make the old source volume offline\n"); + code = + AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService); + if (code) { + fprintf(STDERR, + "Failed to set the flags to make the old source volume offline\n"); goto mfail; } #endif - if (atoserver != afromserver) - { - /* set forwarding pointer for moved volumes */ - code = AFSVolSetForwarding(fromconn, fromtid, atoserver); - ONERR (code, "Failed to set the forwarding pointer for the volume %u\n", afromvol); - } - - if (verbose) fprintf(STDOUT,"Deleting old volume %u on source ...", afromvol); - fflush(STDOUT); - - code = AFSVolDeleteVolume(fromconn,fromtid); /* zap original volume */ - ONERR (code, "Failed to delete the old volume %u on source\n", afromvol); - + if (atoserver != afromserver) { + /* set forwarding pointer for moved volumes */ + VPRINT1("Setting forwarding pointer for volume %u ...", afromvol); + code = AFSVolSetForwarding(fromconn, fromtid, atoserver); + EGOTO1(mfail, code, + "Failed to set the forwarding pointer for the volume %u\n", + afromvol); + VDONE; + } + + VPRINT1("Deleting old volume %u on source ...", afromvol); + code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */ + EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n", + afromvol); + VDONE; + + VPRINT1("Ending transaction on old volume %u on the source ...", + afromvol); code = AFSVolEndTrans(fromconn, fromtid, &rcode); fromtid = 0; - if (!code) code = rcode; - ONERR (code, "Failed to end the transaction on the old volume %u on the source\n", afromvol); - - if (verbose) fprintf(STDOUT," done\n"); + if (!code) + code = rcode; + EGOTO1(mfail, code, + "Failed to end the transaction on the old volume %u on the source\n", + afromvol); + VDONE; /* Delete the backup volume on the original site */ - code = AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid); - if (!code) - { - fprintf(STDOUT, "WARNING : Deleting the backup volume %u on the source ...",backupId); - fflush(STDOUT); - - code = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService); - ONERR (code, "Failed to set the flags on the backup volume on source\n", 0); - - code = AFSVolDeleteVolume(fromconn,fromtid); - ONERR (code, "Failed to delete the backup volume on source\n", 0); - - code = AFSVolEndTrans(fromconn,fromtid, &rcode); + VPRINT1("Creating transaction for backup volume %u on source ...", + backupId); + code = + AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid); + VDONE; + if (!code) { + VPRINT1("Setting flags on backup volume %u on source ...", backupId); + code = + AFSVolSetFlags(fromconn, fromtid, + VTDeleteOnSalvage | VTOutOfService); + EGOTO1(mfail, code, + "Failed to set the flags on the backup volume %u on the source\n", + backupId); + VDONE; + + VPRINT1("Deleting the backup volume %u on the source ...", backupId); + code = AFSVolDeleteVolume(fromconn, fromtid); + EGOTO1(mfail, code, + "Failed to delete the backup volume %u on the source\n", + backupId); + VDONE; + + VPRINT1("Ending transaction on backup volume %u on source ...", + backupId); + code = AFSVolEndTrans(fromconn, fromtid, &rcode); fromtid = 0; - if (!code) code = rcode; - ONERR (code, "Failed to end the transaction on the backup volume %u on source\n", 0); - - fprintf(STDOUT," done\n"); - } - else code = 0; /* no backup volume? that's okay */ + if (!code) + code = rcode; + EGOTO1(mfail, code, + "Failed to end the transaction on the backup volume %u on the source\n", + backupId); + VDONE; + } else + code = 0; /* no backup volume? that's okay */ fromtid = 0; - if (verbose) fprintf(STDOUT,"Starting transaction on the cloned volume %u ...",newVol); - fflush(STDOUT); - - code = AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid); - ONERR (code, "Failed to start a transaction on the cloned volume%u\n", newVol); - - if (verbose) fprintf(STDOUT," done\n"); - - /* now delete the clone */ - if (verbose) fprintf(STDOUT,"Deleting the clone %u ...", newVol); - fflush(STDOUT); - - code = AFSVolDeleteVolume(fromconn, clonetid); - ONERR (code, "Failed to delete the cloned volume %u\n", newVol); - - if (verbose) fprintf(STDOUT," done\n"); - - code = AFSVolEndTrans(fromconn, clonetid, &rcode); - if (!code) code = rcode; - clonetid = 0; - ONERR (code, "Failed to end the transaction on the cloned volume %u\n", newVol); + if (!(flags & RV_NOCLONE)) { + VPRINT1("Starting transaction on the cloned volume %u ...", newVol); + code = + AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, + &clonetid); + EGOTO1(mfail, code, + "Failed to start a transaction on the cloned volume%u\n", + newVol); + VDONE; + + /* now delete the clone */ + VPRINT1("Deleting the cloned volume %u ...", newVol); + code = AFSVolDeleteVolume(fromconn, clonetid); + EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n", + newVol); + VDONE; + + VPRINT1("Ending transaction on cloned volume %u ...", newVol); + code = AFSVolEndTrans(fromconn, clonetid, &rcode); + if (!code) + code = rcode; + clonetid = 0; + EGOTO1(mfail, code, + "Failed to end the transaction on the cloned volume %u\n", + newVol); + VDONE; + } /* fall through */ /* END OF MOVE */ - if (TESTC) - { - fprintf(STDOUT,"Fourth test point - operation complete.\n"); - fprintf(STDOUT,"...test here (y, n)? "); + if (TESTC) { + fprintf(STDOUT, "Fourth test point - operation complete.\n"); + fprintf(STDOUT, "...test here (y, n)? "); fflush(STDOUT); - fscanf(stdin,"%c",&in); - fscanf(stdin,"%c",&lf); /* toss away */ - if (in=='y') - { - fprintf(STDOUT,"type control-c\n"); - while(1) - { - fprintf(stdout,"."); + fscanf(stdin, "%c", &in); + fscanf(stdin, "%c", &lf); /* toss away */ + if (in == 'y') { + fprintf(STDOUT, "type control-c\n"); + while (1) { + fprintf(stdout, "."); fflush(stdout); sleep(1); } @@ -1349,90 +1661,123 @@ UV_MoveVolume(afromvol, afromserver, afrompart, atoserver, atopart) /* normal cleanup code */ - if (entry.flags & RO_EXISTS) fprintf(STDERR,"WARNING : readOnly copies still exist \n"); + if (entry.flags & RO_EXISTS) + fprintf(STDERR, "WARNING : readOnly copies still exist \n"); - if (islocked) - { - vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, afromvol, -1, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); - if (vcode) - { - fprintf(STDERR," Could not release the lock on the VLDB entry for the volume %u \n", - afromvol); - if (!error) error = vcode; + if (islocked) { + VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol); + vcode = + ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1, + (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); + if (vcode) { + VPRINT("\n"); + fprintf(STDERR, + " Could not release the lock on the VLDB entry for the volume %lu \n", + (unsigned long)afromvol); + if (!error) + error = vcode; } + VDONE; } - - if (fromtid) - { + + if (fromtid) { + VPRINT1("Cleanup: Ending transaction on source volume %u ...", + afromvol); code = AFSVolEndTrans(fromconn, fromtid, &rcode); - if (code || rcode) - { - fprintf(STDERR,"Could not end transaction on the source's clone volume %u\n", newVol); - if (!error) error = (code ? code : rcode); + if (code || rcode) { + VPRINT("\n"); + fprintf(STDERR, + "Could not end transaction on the source volume %lu\n", + (unsigned long)afromvol); + if (!error) + error = (code ? code : rcode); } + VDONE; } - if (clonetid) - { + if (clonetid) { + VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol); code = AFSVolEndTrans(fromconn, clonetid, &rcode); - if (code || rcode) - { - fprintf(STDERR,"Could not end transaction on the source's clone volume %u\n",newVol); - if (!error) error = (code ? code : rcode); + if (code || rcode) { + VPRINT("\n"); + fprintf(STDERR, + "Could not end transaction on the source's clone volume %lu\n", + (unsigned long)newVol); + if (!error) + error = (code ? code : rcode); } + VDONE; } - if (totid) - { + if (totid) { + VPRINT1("Cleanup: Ending transaction on destination volume %u ...", + afromvol); code = AFSVolEndTrans(toconn, totid, &rcode); - if (code) - { - fprintf(STDERR,"Could not end transaction on destination volume %u\n",afromvol); - if (!error) error = (code ? code : rcode); + if (code) { + VPRINT("\n"); + fprintf(STDERR, + "Could not end transaction on destination volume %lu\n", + (unsigned long)afromvol); + if (!error) + error = (code ? code : rcode); } + VDONE; } - if (volName) free(volName); + if (volName) + free(volName); #ifdef ENABLE_BUGFIX_1165 - if (infop) free(infop); + if (infop) + free(infop); #endif - if (fromconn) rx_DestroyConnection(fromconn); - if (toconn) rx_DestroyConnection(toconn); - PrintError("",error); + if (fromconn) + rx_DestroyConnection(fromconn); + if (toconn) + rx_DestroyConnection(toconn); + PrintError("", error); return error; /* come here only when the sky falls */ -mfail: + mfail: - if (pntg) - { - fprintf(STDOUT,"vos move: operation interrupted, cleanup in progress...\n"); - fprintf(STDOUT,"clear transaction contexts\n"); + if (pntg) { + fprintf(STDOUT, + "vos move: operation interrupted, cleanup in progress...\n"); + fprintf(STDOUT, "clear transaction contexts\n"); fflush(STDOUT); } /* unlock VLDB entry */ - if (islocked) - ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1, + if (islocked) { + VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol); + ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1, (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); + VDONE; + } - if (clonetid) AFSVolEndTrans(fromconn, clonetid, &rcode); - if (totid) AFSVolEndTrans(toconn, totid, &rcode); - if (fromtid) - { /* put it on-line */ - AFSVolSetFlags(fromconn,fromtid,0); - AFSVolEndTrans(fromconn, fromtid, &rcode); + if (clonetid) { + VPRINT("Recovery: Ending transaction on clone volume ..."); + AFSVolEndTrans(fromconn, clonetid, &rcode); + VDONE; } + if (totid) { + VPRINT("Recovery: Ending transaction on destination volume ..."); + AFSVolEndTrans(toconn, totid, &rcode); + VDONE; + } + if (fromtid) { /* put it on-line */ + VPRINT("Recovery: Setting volume flags on source volume ..."); + AFSVolSetFlags(fromconn, fromtid, 0); + VDONE; - if (verbose) - { /* get current VLDB entry */ - fprintf(STDOUT,"access VLDB\n"); - fflush(STDOUT); + VPRINT("Recovery: Ending transaction on source volume ..."); + AFSVolEndTrans(fromconn, fromtid, &rcode); + VDONE; } - vcode= VLDB_GetEntryByID (afromvol, -1, &entry); - if (vcode) - { - fprintf(STDOUT,"FATAL: VLDB access error: abort cleanup\n"); + + VPRINT("Recovery: Accessing VLDB.\n"); + vcode = VLDB_GetEntryByID(afromvol, -1, &entry); + if (vcode) { + fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n"); fflush(STDOUT); goto done; } @@ -1443,33 +1788,75 @@ mfail: * volume move didn't finish so we remove the volume from the target * location. Otherwise, we remove the volume from the source location. */ - if (Lp_Match(afromserver,afrompart,&entry)) { /* didn't move - delete target volume */ - if (pntg) { + if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */ + if (pntg) { fprintf(STDOUT, "move incomplete - attempt cleanup of target partition - no guarantee\n"); fflush(STDOUT); } if (volid && toconn) { - code=AFSVolTransCreate(toconn,volid,atopart, ITOffline,&totid); + VPRINT1 + ("Recovery: Creating transaction for destination volume %u ...", + volid); + code = + AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid); + if (!code) { - AFSVolSetFlags(toconn,totid, VTDeleteOnSalvage | VTOutOfService); - AFSVolDeleteVolume(toconn,totid); - AFSVolEndTrans(toconn,totid,&rcode); + VDONE; + + VPRINT1 + ("Recovery: Setting flags on destination volume %u ...", + volid); + AFSVolSetFlags(toconn, totid, + VTDeleteOnSalvage | VTOutOfService); + VDONE; + + VPRINT1("Recovery: Deleting destination volume %u ...", + volid); + AFSVolDeleteVolume(toconn, totid); + VDONE; + + VPRINT1 + ("Recovery: Ending transaction on destination volume %u ...", + volid); + AFSVolEndTrans(toconn, totid, &rcode); + VDONE; + } else { + VPRINT1 + ("\nRecovery: Unable to start transaction on destination volume %u.\n", + afromvol); } } /* put source volume on-line */ if (fromconn) { - code=AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid); + VPRINT1("Recovery: Creating transaction on source volume %u ...", + afromvol); + code = + AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, + &fromtid); if (!code) { - AFSVolSetFlags(fromconn,fromtid,0); - AFSVolEndTrans(fromconn,fromtid,&rcode); + VDONE; + + VPRINT1("Recovery: Setting flags on source volume %u ...", + afromvol); + AFSVolSetFlags(fromconn, fromtid, 0); + VDONE; + + VPRINT1 + ("Recovery: Ending transaction on source volume %u ...", + afromvol); + AFSVolEndTrans(fromconn, fromtid, &rcode); + VDONE; + } else { + VPRINT1 + ("\nRecovery: Unable to start transaction on source volume %u.\n", + afromvol); } } - } - else { /* yep, move complete */ - if (pntg) { + } else { /* yep, move complete */ + if (pntg) { fprintf(STDOUT, "move complete - attempt cleanup of source partition - no guarantee\n"); fflush(STDOUT); @@ -1477,65 +1864,661 @@ mfail: /* delete backup volume */ if (fromconn) { - code=AFSVolTransCreate (fromconn,backupId,afrompart, ITOffline,&fromtid); + VPRINT1("Recovery: Creating transaction on backup volume %u ...", + backupId); + code = + AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, + &fromtid); if (!code) { - AFSVolSetFlags(fromconn,fromtid, VTDeleteOnSalvage | VTOutOfService); - AFSVolDeleteVolume(fromconn,fromtid); - AFSVolEndTrans(fromconn,fromtid,&rcode); + VDONE; + + VPRINT1("Recovery: Setting flags on backup volume %u ...", + backupId); + AFSVolSetFlags(fromconn, fromtid, + VTDeleteOnSalvage | VTOutOfService); + VDONE; + + VPRINT1("Recovery: Deleting backup volume %u ...", backupId); + AFSVolDeleteVolume(fromconn, fromtid); + VDONE; + + VPRINT1 + ("Recovery: Ending transaction on backup volume %u ...", + backupId); + AFSVolEndTrans(fromconn, fromtid, &rcode); + VDONE; + } else { + VPRINT1 + ("\nRecovery: Unable to start transaction on backup volume %u.\n", + backupId); } /* delete source volume */ - code=AFSVolTransCreate (fromconn, afromvol, afrompart, ITBusy, &fromtid); + VPRINT1("Recovery: Creating transaction on source volume %u ...", + afromvol); + code = + AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, + &fromtid); if (!code) { - AFSVolSetFlags(fromconn,fromtid, VTDeleteOnSalvage | VTOutOfService); - if (atoserver != afromserver) - AFSVolSetForwarding(fromconn,fromtid,atoserver); - AFSVolDeleteVolume(fromconn,fromtid); - AFSVolEndTrans(fromconn,fromtid,&rcode); + VDONE; + + VPRINT1("Recovery: Setting flags on backup volume %u ...", + afromvol); + AFSVolSetFlags(fromconn, fromtid, + VTDeleteOnSalvage | VTOutOfService); + VDONE; + + if (atoserver != afromserver) { + VPRINT("Recovery: Setting volume forwarding pointer ..."); + AFSVolSetForwarding(fromconn, fromtid, atoserver); + VDONE; + } + + VPRINT1("Recovery: Deleting source volume %u ...", afromvol); + AFSVolDeleteVolume(fromconn, fromtid); + VDONE; + + VPRINT1 + ("Recovery: Ending transaction on source volume %u ...", + afromvol); + AFSVolEndTrans(fromconn, fromtid, &rcode); + VDONE; + } else { + VPRINT1 + ("\nRecovery: Unable to start transaction on source volume %u.\n", + afromvol); } } } /* common cleanup - delete local clone */ if (newVol) { - code = AFSVolTransCreate (fromconn, newVol, afrompart, ITOffline, &clonetid); + VPRINT1("Recovery: Creating transaction on clone volume %u ...", + newVol); + code = + AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, + &clonetid); if (!code) { - AFSVolDeleteVolume(fromconn,clonetid); - AFSVolEndTrans(fromconn,clonetid,&rcode); + VDONE; + + VPRINT1("Recovery: Deleting clone volume %u ...", newVol); + AFSVolDeleteVolume(fromconn, clonetid); + VDONE; + + VPRINT1("Recovery: Ending transaction on clone volume %u ...", + newVol); + AFSVolEndTrans(fromconn, clonetid, &rcode); + VDONE; + } else { + VPRINT1 + ("\nRecovery: Unable to start transaction on source volume %u.\n", + afromvol); } } /* unlock VLDB entry */ - ubik_Call (VL_ReleaseLock, cstruct, 0, afromvol, -1, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); - -done: /* routine cleanup */ - if (volName) free(volName); + VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...", + afromvol); + ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1, + (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); + VDONE; + + done: /* routine cleanup */ + if (volName) + free(volName); #ifdef ENABLE_BUGFIX_1165 - if (infop) free(infop); + if (infop) + free(infop); #endif - if (fromconn) rx_DestroyConnection(fromconn); - if (toconn) rx_DestroyConnection(toconn); + if (fromconn) + rx_DestroyConnection(fromconn); + if (toconn) + rx_DestroyConnection(toconn); + + if (pntg) { + fprintf(STDOUT, "cleanup complete - user verify desired result\n"); + fflush(STDOUT); + } + exit(1); +} + + +int +UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart, + afs_int32 atoserver, afs_int32 atopart) +{ + return UV_MoveVolume2(afromvol, afromserver, afrompart, + atoserver, atopart, 0); +} + + +/* Copy volume from to + * . The new volume is named by . The new volume + * has ID if that is nonzero; otherwise a new ID is allocated + * from the VLDB. the following flags are supported: + * + * RV_RDONLY - target volume is RO + * RV_OFFLINE - leave target volume offline + * RV_CPINCR - do incremental dump if target exists + * RV_NOVLDB - don't create/update VLDB entry + * RV_NOCLONE - don't use a copy clone + */ +int +UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart, + char *atovolname, afs_int32 atoserver, afs_int32 atopart, + afs_int32 atovolid, int flags) +{ + struct rx_connection *toconn, *fromconn; + afs_int32 fromtid, totid, clonetid; + char vname[64]; + afs_int32 rcode; + afs_int32 fromDate, cloneFromDate; + struct restoreCookie cookie; + register afs_int32 vcode, code; + afs_int32 cloneVol, newVol, volflag; + struct volser_status tstatus; + struct destServer destination; + + struct nvldbentry entry, newentry, storeEntry; + int islocked, pntg; + afs_int32 error; + int justclone = 0; + + islocked = 0; + fromconn = (struct rx_connection *)0; + toconn = (struct rx_connection *)0; + fromtid = 0; + totid = 0; + clonetid = 0; + error = 0; + pntg = 0; + newVol = 0; + + /* support control-c processing */ + if (setjmp(env)) + goto mfail; + (void)signal(SIGINT, sigint_handler); + + vcode = VLDB_GetEntryByID(afromvol, -1, &entry); + EGOTO1(mfail, vcode, + "Could not fetch the entry for the volume %u from the VLDB \n", + afromvol); + MapHostToNetwork(&entry); + + pntg = 1; + toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */ + fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT); + fromtid = totid = 0; /* initialize to uncreated */ + + + /* check if we can shortcut and use a local clone instead of a full copy */ + if (afromserver == atoserver && afrompart == atopart) { + justclone = 1; + } + + /* *** + * clone the read/write volume locally. + * ***/ + + cloneVol = 0; + if (!(flags & RV_NOCLONE)) { + VPRINT1("Starting transaction on source volume %u ...", afromvol); + code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, + &fromtid); + EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n", + afromvol); + VDONE; + + /* Get a clone id */ + VPRINT1("Allocating new volume id for clone of volume %u ...", + afromvol); + cloneVol = 0; + vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &cloneVol); + EGOTO1(mfail, vcode, + "Could not get an ID for the clone of volume %u from the VLDB\n", + afromvol); + VDONE; + } + + if (atovolid) { + newVol = atovolid; + } else { + /* Get a new volume id */ + VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol); + newVol = 0; + vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &newVol); + EGOTO1(mfail, vcode, + "Could not get an ID for the copy of volume %u from the VLDB\n", + afromvol); + VDONE; + } + + if (!(flags & RV_NOCLONE)) { + /* Do the clone. Default flags on clone are set to delete on salvage and out of service */ + VPRINT1("Cloning source volume %u ...", afromvol); + strcpy(vname, "copy-clone-temp"); + code = + AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, + &cloneVol); + EGOTO1(mfail, code, "Failed to clone the source volume %u\n", + afromvol); + VDONE; + + VPRINT1("Ending the transaction on the source volume %u ...", afromvol); + rcode = 0; + code = AFSVolEndTrans(fromconn, fromtid, &rcode); + fromtid = 0; + if (!code) + code = rcode; + EGOTO1(mfail, code, + "Failed to end the transaction on the source volume %u\n", + afromvol); + VDONE; + } + + /* *** + * Create the destination volume + * ***/ + + if (!(flags & RV_NOCLONE)) { + VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol); + code = + AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline, + &clonetid); + EGOTO1(mfail, code, + "Failed to start a transaction on the cloned volume%u\n", + cloneVol); + VDONE; + + VPRINT1("Setting flags on cloned volume %u ...", cloneVol); + code = + AFSVolSetFlags(fromconn, clonetid, + VTDeleteOnSalvage | VTOutOfService); /*redundant */ + EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n", + cloneVol); + VDONE; + + /* remember time from which we've dumped the volume */ + VPRINT1("Getting status of cloned volume %u ...", cloneVol); + code = AFSVolGetStatus(fromconn, clonetid, &tstatus); + EGOTO1(mfail, code, + "Failed to get the status of the cloned volume %u\n", + cloneVol); + VDONE; + + fromDate = tstatus.creationDate - CLOCKSKEW; + } else { + fromDate = 0; + } + + /* create a volume on the target machine */ + cloneFromDate = 0; + code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid); + if (!code) { + if ((flags & RV_CPINCR)) { + VPRINT1("Getting status of pre-existing volume %u ...", newVol); + code = AFSVolGetStatus(toconn, totid, &tstatus); + EGOTO1(mfail, code, + "Failed to get the status of the pre-existing volume %u\n", + newVol); + VDONE; + + /* Using the update date should be OK here, but add some fudge */ + cloneFromDate = tstatus.updateDate - CLOCKSKEW; + if ((flags & RV_NOCLONE)) + fromDate = cloneFromDate; + + /* XXX We should check that the source volume's creationDate is + * XXX not newer than the existing target volume, and if not, + * XXX throw away the existing target and do a full dump. */ + + goto cpincr; + } + + /* Delete the existing volume. + * While we are deleting the volume in these steps, the transaction + * we started against the cloned volume (clonetid above) will be + * sitting idle. It will get cleaned up after 600 seconds + */ + VPRINT1("Deleting pre-existing volume %u on destination ...", newVol); + code = AFSVolDeleteVolume(toconn, totid); + EGOTO1(mfail, code, + "Could not delete the pre-existing volume %u on destination\n", + newVol); + VDONE; + + VPRINT1 + ("Ending transaction on pre-existing volume %u on destination ...", + newVol); + code = AFSVolEndTrans(toconn, totid, &rcode); + totid = 0; + if (!code) + code = rcode; + EGOTO1(mfail, code, + "Could not end the transaction on pre-existing volume %u on destination\n", + newVol); + VDONE; + } + + VPRINT1("Creating the destination volume %u ...", newVol); + code = + AFSVolCreateVolume(toconn, atopart, atovolname, + (flags & RV_RDONLY) ? volser_RO : volser_RW, + newVol, &newVol, &totid); + EGOTO1(mfail, code, "Failed to create the destination volume %u\n", + newVol); + VDONE; + + VPRINT1("Setting volume flags on destination volume %u ...", newVol); + code = + AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService)); + EGOTO1(mfail, code, + "Failed to set the flags on the destination volume %u\n", newVol); + VDONE; + +cpincr: + + destination.destHost = ntohl(atoserver); + destination.destPort = AFSCONF_VOLUMEPORT; + destination.destSSID = 1; + + strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME); + cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL; + cookie.parent = 0; + cookie.clone = 0; + + /*** + * Now dump the clone to the new volume + ***/ + + if (!(flags & RV_NOCLONE)) { + /* XXX probably should have some code here that checks to see if + * XXX we are copying to same server and partition - if so, just + * XXX use a clone to save disk space */ + + /* Copy the clone to the new volume */ + VPRINT2("Dumping from clone %u on source to volume %u on destination ...", + cloneVol, newVol); + code = + AFSVolForward(fromconn, clonetid, cloneFromDate, &destination, + totid, &cookie); + EGOTO1(mfail, code, "Failed to move data for the volume %u\n", + newVol); + VDONE; + + VPRINT1("Ending transaction on cloned volume %u ...", cloneVol); + code = AFSVolEndTrans(fromconn, clonetid, &rcode); + if (!code) + code = rcode; + clonetid = 0; + EGOTO1(mfail, code, + "Failed to end the transaction on the cloned volume %u\n", + cloneVol); + VDONE; + } + + /* *** + * reattach to the main-line volume, and incrementally dump it. + * ***/ + + VPRINT1("Starting transaction on source volume %u ...", afromvol); + code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid); + EGOTO1(mfail, code, + "Failed to create a transaction on the source volume %u\n", + afromvol); + VDONE; + + /* now do the incremental */ + VPRINT2 + ("Doing the%s dump from source to destination for volume %u ... ", + (flags & RV_NOCLONE) ? "" : " incremental", + afromvol); + code = + AFSVolForward(fromconn, fromtid, fromDate, &destination, totid, + &cookie); + EGOTO1(mfail, code, + "Failed to do the%s dump from old site to new site\n", + afromvol); + VDONE; + + VPRINT1("Setting volume flags on destination volume %u ...", newVol); + volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */ + code = AFSVolSetFlags(toconn, totid, volflag); + EGOTO(mfail, code, + "Failed to set the flags to make destination volume online\n"); + VDONE; + + /* put new volume online */ + VPRINT1("Ending transaction on destination volume %u ...", newVol); + code = AFSVolEndTrans(toconn, totid, &rcode); + totid = 0; + if (!code) + code = rcode; + EGOTO1(mfail, code, + "Failed to end the transaction on the destination volume %u\n", + newVol); + VDONE; + + VPRINT1("Ending transaction on source volume %u ...", afromvol); + code = AFSVolEndTrans(fromconn, fromtid, &rcode); + fromtid = 0; + if (!code) + code = rcode; + EGOTO1(mfail, code, + "Failed to end the transaction on the source volume %u\n", + afromvol); + VDONE; + + fromtid = 0; + + if (!(flags & RV_NOCLONE)) { + VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol); + code = + AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline, + &clonetid); + EGOTO1(mfail, code, + "Failed to start a transaction on the cloned volume%u\n", + cloneVol); + VDONE; + + /* now delete the clone */ + VPRINT1("Deleting the cloned volume %u ...", cloneVol); + code = AFSVolDeleteVolume(fromconn, clonetid); + EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n", + cloneVol); + VDONE; + + VPRINT1("Ending transaction on cloned volume %u ...", cloneVol); + code = AFSVolEndTrans(fromconn, clonetid, &rcode); + if (!code) + code = rcode; + clonetid = 0; + EGOTO1(mfail, code, + "Failed to end the transaction on the cloned volume %u\n", + cloneVol); + VDONE; + } + + if (!(flags & RV_NOVLDB)) { + /* create the vldb entry for the copied volume */ + strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME); + newentry.nServers = 1; + newentry.serverNumber[0] = atoserver; + newentry.serverPartition[0] = atopart; + newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS; + newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL; + newentry.volumeId[RWVOL] = newVol; + newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0; + newentry.volumeId[BACKVOL] = 0; + newentry.cloneId = 0; + /*map into right byte order, before passing to xdr, the stuff has to be in host + * byte order. Xdr converts it into network order */ + MapNetworkToHost(&newentry, &storeEntry); + /* create the vldb entry */ + vcode = VLDB_CreateEntry(&storeEntry); + if (vcode) { + fprintf(STDERR, + "Could not create a VLDB entry for the volume %s %lu\n", + atovolname, (unsigned long)newVol); + /*destroy the created volume */ + VPRINT1("Deleting the newly created volume %u\n", newVol); + AFSVolDeleteVolume(toconn, totid); + error = vcode; + goto mfail; + } + VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname, + newVol); + } + + /* normal cleanup code */ + + if (fromtid) { + VPRINT1("Cleanup: Ending transaction on source volume %u ...", + afromvol); + code = AFSVolEndTrans(fromconn, fromtid, &rcode); + if (code || rcode) { + VPRINT("\n"); + fprintf(STDERR, + "Could not end transaction on the source volume %lu\n", + (unsigned long)afromvol); + if (!error) + error = (code ? code : rcode); + } + VDONE; + } + + if (clonetid) { + VPRINT1("Cleanup: Ending transaction on clone volume %u ...", + cloneVol); + code = AFSVolEndTrans(fromconn, clonetid, &rcode); + if (code || rcode) { + VPRINT("\n"); + fprintf(STDERR, + "Could not end transaction on the source's clone volume %lu\n", + (unsigned long)cloneVol); + if (!error) + error = (code ? code : rcode); + } + VDONE; + } + + if (totid) { + VPRINT1("Cleanup: Ending transaction on destination volume %u ...", + newVol); + code = AFSVolEndTrans(toconn, totid, &rcode); + if (code) { + VPRINT("\n"); + fprintf(STDERR, + "Could not end transaction on destination volume %lu\n", + (unsigned long)newVol); + if (!error) + error = (code ? code : rcode); + } + VDONE; + } + if (fromconn) + rx_DestroyConnection(fromconn); + if (toconn) + rx_DestroyConnection(toconn); + PrintError("", error); + return error; + + /* come here only when the sky falls */ + mfail: + + if (pntg) { + fprintf(STDOUT, + "vos copy: operation interrupted, cleanup in progress...\n"); + fprintf(STDOUT, "clear transaction contexts\n"); + fflush(STDOUT); + } + + if (clonetid) { + VPRINT("Recovery: Ending transaction on clone volume ..."); + AFSVolEndTrans(fromconn, clonetid, &rcode); + VDONE; + } + if (totid) { + VPRINT("Recovery: Ending transaction on destination volume ..."); + AFSVolEndTrans(toconn, totid, &rcode); + VDONE; + } + if (fromtid) { /* put it on-line */ + VPRINT("Recovery: Ending transaction on source volume ..."); + AFSVolEndTrans(fromconn, fromtid, &rcode); + VDONE; + } + + VPRINT("Recovery: Accessing VLDB.\n"); + vcode = VLDB_GetEntryByID(afromvol, -1, &entry); + if (vcode) { + fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n"); + fflush(STDOUT); + goto done; + } + MapHostToNetwork(&entry); + + /* common cleanup - delete local clone */ + if (cloneVol) { + VPRINT1("Recovery: Creating transaction on clone volume %u ...", + cloneVol); + code = + AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, + &clonetid); + if (!code) { + VDONE; + + VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol); + AFSVolDeleteVolume(fromconn, clonetid); + VDONE; + + VPRINT1("Recovery: Ending transaction on clone volume %u ...", + cloneVol); + AFSVolEndTrans(fromconn, clonetid, &rcode); + VDONE; + } else { + VPRINT1 + ("\nRecovery: Unable to start transaction on clone volume %u.\n", + cloneVol); + } + } + + done: /* routine cleanup */ + if (fromconn) + rx_DestroyConnection(fromconn); + if (toconn) + rx_DestroyConnection(toconn); if (pntg) { - fprintf(STDOUT,"cleanup complete - user verify desired result\n"); + fprintf(STDOUT, "cleanup complete - user verify desired result\n"); fflush(STDOUT); } exit(1); } + +int +UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart, + char *atovolname, afs_int32 atoserver, afs_int32 atopart) +{ + return UV_CopyVolume2(afromvol, afromserver, afrompart, + atovolname, atoserver, atopart, 0, 0); +} + + + /* Make a new backup of volume on and * if one already exists, update it */ -UV_BackupVolume(aserver, apart, avolid) - afs_int32 aserver, apart, avolid; +int +UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid) { struct rx_connection *aconn = (struct rx_connection *)0; afs_int32 ttid = 0, btid = 0; afs_int32 backupID; afs_int32 code = 0, rcode = 0; - char vname[VOLSER_MAXVOLNAME +1]; + char vname[VOLSER_MAXVOLNAME + 1]; struct nvldbentry entry, storeEntry; afs_int32 error = 0; int vldblocked = 0, vldbmod = 0, backexists = 1; @@ -1544,59 +2527,67 @@ UV_BackupVolume(aserver, apart, avolid) /* the calls to VLDB will succeed only if avolid is a RW volume, * since we are following the RW hash chain for searching */ - code = VLDB_GetEntryByID(avolid, RWVOL, &entry); + code = VLDB_GetEntryByID(avolid, RWVOL, &entry); if (code) { - fprintf(STDERR, "Could not fetch the entry for the volume %u from the VLDB \n", avolid); - error = code; goto bfail; + fprintf(STDERR, + "Could not fetch the entry for the volume %lu from the VLDB \n", + (unsigned long)avolid); + error = code; + goto bfail; } - MapHostToNetwork(&entry); + MapHostToNetwork(&entry); /* These operations require the VLDB be locked since it means the VLDB * will change or the vldb is already locked. */ - if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */ - (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */ - (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */ - - code = ubik_Call(VL_SetLock,cstruct, 0, avolid, RWVOL, VLOP_BACKUP); - if (code) { - fprintf(STDERR,"Could not lock the VLDB entry for the volume %u\n",avolid); - error = code; - goto bfail; - } - vldblocked = 1; - - /* Reread the vldb entry */ - code = VLDB_GetEntryByID(avolid, RWVOL, &entry); - if (code) { - fprintf(STDERR,"Could not fetch the entry for the volume %u from the VLDB \n",avolid); - error = code; - goto bfail; - } - MapHostToNetwork(&entry); + if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */ + (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */ + (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */ + + code = ubik_Call(VL_SetLock, cstruct, 0, avolid, RWVOL, VLOP_BACKUP); + if (code) { + fprintf(STDERR, + "Could not lock the VLDB entry for the volume %lu\n", + (unsigned long)avolid); + error = code; + goto bfail; + } + vldblocked = 1; + + /* Reread the vldb entry */ + code = VLDB_GetEntryByID(avolid, RWVOL, &entry); + if (code) { + fprintf(STDERR, + "Could not fetch the entry for the volume %lu from the VLDB \n", + (unsigned long)avolid); + error = code; + goto bfail; + } + MapHostToNetwork(&entry); } if (!ISNAMEVALID(entry.name)) { - fprintf(STDERR, "Name of the volume %s exceeds the size limit\n", entry.name); - error = VOLSERBADNAME; - goto bfail; + fprintf(STDERR, "Name of the volume %s exceeds the size limit\n", + entry.name); + error = VOLSERBADNAME; + goto bfail; } backupID = entry.volumeId[BACKVOL]; if (backupID == INVALID_BID) { - /* Get a backup volume id from the VLDB and update the vldb - * entry with it. - */ - code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &backupID); - if (code) { - fprintf(STDERR, - "Could not allocate ID for the backup volume of %u from the VLDB\n", - avolid); - error = code; - goto bfail; - } - entry.volumeId[BACKVOL] = backupID; - vldbmod = 1; + /* Get a backup volume id from the VLDB and update the vldb + * entry with it. + */ + code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &backupID); + if (code) { + fprintf(STDERR, + "Could not allocate ID for the backup volume of %lu from the VLDB\n", + (unsigned long)avolid); + error = code; + goto bfail; + } + entry.volumeId[BACKVOL] = backupID; + vldbmod = 1; } /* Test to see if the backup volume exists by trying to create @@ -1604,23 +2595,24 @@ UV_BackupVolume(aserver, apart, avolid) */ code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid); if (code) { - if (code != VNOVOL) { - fprintf(STDERR,"Could not reach the backup volume %u\n", backupID); - error = code; - goto bfail; - } - backexists = 0; /* backup volume does not exist */ + if (code != VNOVOL) { + fprintf(STDERR, "Could not reach the backup volume %lu\n", + (unsigned long)backupID); + error = code; + goto bfail; + } + backexists = 0; /* backup volume does not exist */ } if (btid) { - code = AFSVolEndTrans(aconn, btid, &rcode); - btid = 0; - if (code || rcode) { - fprintf(STDERR, - "Could not end transaction on the previous backup volume %u\n", - backupID); - error = (code ? code : rcode); - goto bfail; - } + code = AFSVolEndTrans(aconn, btid, &rcode); + btid = 0; + if (code || rcode) { + fprintf(STDERR, + "Could not end transaction on the previous backup volume %lu\n", + (unsigned long)backupID); + error = (code ? code : rcode); + goto bfail; + } } /* Now go ahead and try to clone the RW volume. @@ -1628,68 +2620,71 @@ UV_BackupVolume(aserver, apart, avolid) */ code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid); if (code) { - fprintf(STDERR,"Could not start a transaction on the volume %u\n",avolid); - error = code; - goto bfail; + fprintf(STDERR, "Could not start a transaction on the volume %lu\n", + (unsigned long)avolid); + error = code; + goto bfail; } /* Clone or reclone the volume, depending on whether the backup * volume exists or not */ if (backexists) { - if(verbose) - fprintf(STDOUT,"Re-cloning backup volume %u ...", backupID); - fflush(STDOUT); + VPRINT1("Re-cloning backup volume %u ...", backupID); - code = AFSVolReClone(aconn, ttid, backupID); - if (code) { - fprintf(STDERR,"Could not re-clone backup volume %u\n", backupID); - error = code; - goto bfail; - } - } - else { - if (verbose) - fprintf(STDOUT,"Creating a new backup clone %u ...", backupID); - fflush(STDOUT); + code = AFSVolReClone(aconn, ttid, backupID); + if (code) { + fprintf(STDERR, "Could not re-clone backup volume %lu\n", + (unsigned long)backupID); + error = code; + goto bfail; + } + } else { + VPRINT1("Creating a new backup clone %u ...", backupID); - strcpy(vname, entry.name); - strcat(vname,".backup"); + strcpy(vname, entry.name); + strcat(vname, ".backup"); - code = AFSVolClone(aconn, ttid, 0,backupVolume, vname, &backupID); - if (code) { - fprintf(STDERR,"Failed to clone the volume %u\n",avolid); - error = code; - goto bfail; - } + code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID); + if (code) { + fprintf(STDERR, "Failed to clone the volume %lu\n", + (unsigned long)avolid); + error = code; + goto bfail; + } } /* End the transaction on the RW volume */ code = AFSVolEndTrans(aconn, ttid, &rcode); ttid = 0; if (code || rcode) { - fprintf(STDERR, "Failed to end the transaction on the rw volume %u\n", avolid); + fprintf(STDERR, + "Failed to end the transaction on the rw volume %lu\n", + (unsigned long)avolid); error = (code ? code : rcode); goto bfail; } /* Mork vldb as backup exists */ if (!(entry.flags & BACK_EXISTS)) { - entry.flags |= BACK_EXISTS; - vldbmod = 1; + entry.flags |= BACK_EXISTS; + vldbmod = 1; } /* Now go back to the backup volume and bring it on line */ code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid); if (code) { - fprintf(STDERR,"Failed to start a transaction on the backup volume %u\n",backupID); + fprintf(STDERR, + "Failed to start a transaction on the backup volume %lu\n", + (unsigned long)backupID); error = code; goto bfail; } code = AFSVolSetFlags(aconn, btid, 0); if (code) { - fprintf(STDERR,"Could not mark the backup volume %u on line \n",backupID); + fprintf(STDERR, "Could not mark the backup volume %lu on line \n", + (unsigned long)backupID); error = code; goto bfail; } @@ -1697,89 +2692,292 @@ UV_BackupVolume(aserver, apart, avolid) code = AFSVolEndTrans(aconn, btid, &rcode); btid = 0; if (code || rcode) { - fprintf(STDERR, "Failed to end the transaction on the backup volume %u\n", backupID); + fprintf(STDERR, + "Failed to end the transaction on the backup volume %lu\n", + (unsigned long)backupID); error = (code ? code : rcode); goto bfail; } - if (verbose) - fprintf(STDOUT,"done\n"); + VDONE; /* Will update the vldb below */ bfail: if (ttid) { - code = AFSVolEndTrans(aconn, ttid, &rcode); - if (code || rcode) { - fprintf(STDERR, "Could not end transaction on the volume %u\n", avolid); - if (!error) - error = (code ? code : rcode); - } + code = AFSVolEndTrans(aconn, ttid, &rcode); + if (code || rcode) { + fprintf(STDERR, "Could not end transaction on the volume %lu\n", + (unsigned long)avolid); + if (!error) + error = (code ? code : rcode); + } } if (btid) { - code = AFSVolEndTrans(aconn, btid, &rcode); - if (code || rcode) { - fprintf(STDERR,"Could not end transaction the backup volume %u\n",backupID); - if (!error) - error = (code ? code : rcode); - } + code = AFSVolEndTrans(aconn, btid, &rcode); + if (code || rcode) { + fprintf(STDERR, + "Could not end transaction the backup volume %lu\n", + (unsigned long)backupID); + if (!error) + error = (code ? code : rcode); + } } /* Now update the vldb - if modified */ if (vldblocked) { - if (vldbmod) { - MapNetworkToHost(&entry,&storeEntry); - code = VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); - if (code) { - fprintf(STDERR,"Could not update the VLDB entry for the volume %u \n",avolid); - if (!error) - error = code; - } - } - else { - code = ubik_Call(VL_ReleaseLock,cstruct, 0, avolid, RWVOL, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); - if (code) { - fprintf(STDERR,"Could not unlock the VLDB entry for the volume %u \n",avolid); - if (!error) - error = code; - } - } - } - - if (aconn) - rx_DestroyConnection(aconn); - - PrintError("",error); - return error; + if (vldbmod) { + MapNetworkToHost(&entry, &storeEntry); + code = + VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry, + (LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP)); + if (code) { + fprintf(STDERR, + "Could not update the VLDB entry for the volume %lu \n", + (unsigned long)avolid); + if (!error) + error = code; + } + } else { + code = + ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, RWVOL, + (LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP)); + if (code) { + fprintf(STDERR, + "Could not unlock the VLDB entry for the volume %lu \n", + (unsigned long)avolid); + if (!error) + error = code; + } + } + } + + if (aconn) + rx_DestroyConnection(aconn); + + PrintError("", error); + return error; } -static int DelVol (conn, vid, part, flags) -struct rx_connection *conn; -afs_int32 vid, part, flags; +/* Make a new clone of volume on and + * using volume ID , or a new ID allocated from the VLDB. + * The new volume is named by , or by appending ".clone" to + * the existing name if is NULL. The following flags are + * supported: + * + * RV_RDONLY - target volume is RO + * RV_OFFLINE - leave target volume offline + */ + +int +UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid, + afs_int32 acloneid, char *aname, int flags) { - afs_int32 acode, ccode, rcode, tid; - ccode = rcode = tid = 0; - - acode = AFSVolTransCreate(conn, vid, part, flags, &tid); - if (!acode) { /* It really was there */ - acode = AFSVolDeleteVolume(conn, tid); - if (acode) { - fprintf(STDERR, "Failed to delete volume %u.\n", vid); - PrintError ("", acode); - } - ccode = AFSVolEndTrans(conn, tid, &rcode); - if (!ccode) - ccode = rcode; - if (ccode) { - fprintf(STDERR, "Failed to end transaction on volume %u.\n", vid); - PrintError ("", ccode); - } - } - -return acode; + struct rx_connection *aconn = (struct rx_connection *)0; + afs_int32 ttid = 0, btid = 0; + afs_int32 code = 0, rcode = 0; + char vname[VOLSER_MAXVOLNAME + 1]; + afs_int32 error = 0; + int backexists = 1; + volEntries volumeInfo; + + aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); + + if (!aname) { + volumeInfo.volEntries_val = (volintInfo *) 0; + volumeInfo.volEntries_len = 0; + code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo); + if (code) { + fprintf(stderr, "Could not get info for volume %lu\n", + (unsigned long)avolid); + error = code; + goto bfail; + } + strncpy(vname, volumeInfo.volEntries_val[0].name, + VOLSER_OLDMAXVOLNAME - 7); + vname[VOLSER_OLDMAXVOLNAME - 7] = 0; + strcat(vname, ".clone"); + aname = vname; + if (volumeInfo.volEntries_val) + free(volumeInfo.volEntries_val); + } + + if (!acloneid) { + /* Get a clone id */ + VPRINT1("Allocating new volume id for clone of volume %u ...", + avolid); + code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &acloneid); + EGOTO1(bfail, code, + "Could not get an ID for the clone of volume %u from the VLDB\n", + avolid); + VDONE; + } + + /* Test to see if the clone volume exists by trying to create + * a transaction on the clone volume. We've assumed the clone exists. + */ + /* XXX I wonder what happens if the clone has some other parent... */ + code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid); + if (code) { + if (code != VNOVOL) { + fprintf(STDERR, "Could not reach the clone volume %lu\n", + (unsigned long)acloneid); + error = code; + goto bfail; + } + backexists = 0; /* backup volume does not exist */ + } + if (btid) { + code = AFSVolEndTrans(aconn, btid, &rcode); + btid = 0; + if (code || rcode) { + fprintf(STDERR, + "Could not end transaction on the previous clone volume %lu\n", + (unsigned long)acloneid); + error = (code ? code : rcode); + goto bfail; + } + } + + /* Now go ahead and try to clone the RW volume. + * First start a transaction on the RW volume + */ + code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid); + if (code) { + fprintf(STDERR, "Could not start a transaction on the volume %lu\n", + (unsigned long)avolid); + error = code; + goto bfail; + } + + /* Clone or reclone the volume, depending on whether the backup + * volume exists or not + */ + if (backexists) { + VPRINT1("Re-cloning clone volume %u ...", acloneid); + + code = AFSVolReClone(aconn, ttid, acloneid); + if (code) { + fprintf(STDERR, "Could not re-clone backup volume %lu\n", + (unsigned long)acloneid); + error = code; + goto bfail; + } + } else { + VPRINT1("Creating a new clone %u ...", acloneid); + + code = AFSVolClone(aconn, ttid, 0, + (flags & RV_RDONLY) ? readonlyVolume : backupVolume, + aname, &acloneid); + if (code) { + fprintf(STDERR, "Failed to clone the volume %lu\n", + (unsigned long)avolid); + error = code; + goto bfail; + } + } + + /* End the transaction on the RW volume */ + code = AFSVolEndTrans(aconn, ttid, &rcode); + ttid = 0; + if (code || rcode) { + fprintf(STDERR, + "Failed to end the transaction on the rw volume %lu\n", + (unsigned long)avolid); + error = (code ? code : rcode); + goto bfail; + } + + /* Now go back to the backup volume and bring it on line */ + if (!(flags & RV_OFFLINE)) { + code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid); + if (code) { + fprintf(STDERR, + "Failed to start a transaction on the clone volume %lu\n", + (unsigned long)acloneid); + error = code; + goto bfail; + } + + code = AFSVolSetFlags(aconn, btid, 0); + if (code) { + fprintf(STDERR, "Could not mark the clone volume %lu on line \n", + (unsigned long)acloneid); + error = code; + goto bfail; + } + + code = AFSVolEndTrans(aconn, btid, &rcode); + btid = 0; + if (code || rcode) { + fprintf(STDERR, + "Failed to end the transaction on the clone volume %lu\n", + (unsigned long)acloneid); + error = (code ? code : rcode); + goto bfail; + } + } + + VDONE; + + bfail: + if (ttid) { + code = AFSVolEndTrans(aconn, ttid, &rcode); + if (code || rcode) { + fprintf(STDERR, "Could not end transaction on the volume %lu\n", + (unsigned long)avolid); + if (!error) + error = (code ? code : rcode); + } + } + + if (btid) { + code = AFSVolEndTrans(aconn, btid, &rcode); + if (code || rcode) { + fprintf(STDERR, + "Could not end transaction on the clone volume %lu\n", + (unsigned long)acloneid); + if (!error) + error = (code ? code : rcode); + } + } + + if (aconn) + rx_DestroyConnection(aconn); + + PrintError("", error); + return error; +} + +static int +DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part, + afs_int32 flags) +{ + afs_int32 acode, ccode, rcode, tid; + ccode = rcode = tid = 0; + + acode = AFSVolTransCreate(conn, vid, part, flags, &tid); + if (!acode) { /* It really was there */ + acode = AFSVolDeleteVolume(conn, tid); + if (acode) { + fprintf(STDERR, "Failed to delete volume %lu.\n", + (unsigned long)vid); + PrintError("", acode); + } + ccode = AFSVolEndTrans(conn, tid, &rcode); + if (!ccode) + ccode = rcode; + if (ccode) { + fprintf(STDERR, "Failed to end transaction on volume %lu.\n", + (unsigned long)vid); + PrintError("", ccode); + } + } + + return acode; } #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; } @@ -1789,121 +2987,128 @@ return acode; * if necessary. Return the time from which a dump should * be made (0 if it's a new volume) */ -static int GetTrans (vldbEntryPtr, index, connPtr, transPtr, timePtr) - struct nvldbentry *vldbEntryPtr; - afs_int32 index; - struct rx_connection **connPtr; - afs_int32 *transPtr, *timePtr; +static int +GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index, + struct rx_connection **connPtr, afs_int32 * transPtr, + afs_int32 * timePtr) { - afs_int32 volid; - struct volser_status tstatus; - int code, rcode, tcode; - - *connPtr = (struct rx_connection *)0; - *timePtr = 0; - *transPtr = 0; - - /* get connection to the replication site */ - *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT); - if (!*connPtr) goto fail; /* server is down */ - - volid = vldbEntryPtr->volumeId[ROVOL]; - if (volid) - code = AFSVolTransCreate(*connPtr, volid, vldbEntryPtr->serverPartition[index], - ITOffline, transPtr); - - /* If the volume does not exist, create it */ - if (!volid || code) { - char volname[64]; - - if (volid && (code != VNOVOL)){ - PrintError("Failed to start a transaction on the RO volume.\n", - code); - goto fail; - } - - strcpy(volname, vldbEntryPtr->name); - strcat(volname, ".readonly"); - - if (verbose) { - fprintf(STDOUT,"Creating new volume %u on replication site %s: ", - volid, hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index])); - fflush(STDOUT); - } - - code = AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index], - volname, volser_RO, - vldbEntryPtr->volumeId[RWVOL], &volid, transPtr); - if (code) { - PrintError("Failed to create the ro volume: ",code); - goto fail; - } - vldbEntryPtr->volumeId[ROVOL] = volid; - - if (verbose) fprintf(STDOUT,"done.\n"); - - /* The following is a bit redundant, since create sets these flags by default */ - code = AFSVolSetFlags(*connPtr, *transPtr, VTDeleteOnSalvage | VTOutOfService); - if (code) { - PrintError("Failed to set flags on the ro volume: ", code); - goto fail; - } - } - - /* Otherwise, the transaction did succeed, so get the creation date of the - * latest RO volume on the replication site - */ - else { - if (verbose) { - fprintf(STDOUT,"Updating existing ro volume %u on %s ...\n", - volid, hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index])); - fflush(STDOUT); - } - - code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus); - if (code) { - PrintError("Failed to get status of volume on destination: ",code); - goto fail; - } - *timePtr = tstatus.creationDate-CLOCKSKEW; - } - - return 0; - - fail: - if (*transPtr) { - tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode); - *transPtr = 0; - if (!tcode) tcode = rcode; - if (tcode) PrintError("Could not end transaction on a ro volume: ", tcode); - } - - return code; + afs_int32 volid; + struct volser_status tstatus; + int code, rcode, tcode; + + *connPtr = (struct rx_connection *)0; + *timePtr = 0; + *transPtr = 0; + + /* get connection to the replication site */ + *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT); + if (!*connPtr) + goto fail; /* server is down */ + + volid = vldbEntryPtr->volumeId[ROVOL]; + if (volid) + code = + AFSVolTransCreate(*connPtr, volid, + vldbEntryPtr->serverPartition[index], ITOffline, + transPtr); + + /* If the volume does not exist, create it */ + if (!volid || code) { + char volname[64]; + + if (volid && (code != VNOVOL)) { + PrintError("Failed to start a transaction on the RO volume.\n", + code); + goto fail; + } + + strcpy(volname, vldbEntryPtr->name); + strcat(volname, ".readonly"); + + if (verbose) { + fprintf(STDOUT, + "Creating new volume %lu on replication site %s: ", + (unsigned long)volid, + hostutil_GetNameByINet(vldbEntryPtr-> + serverNumber[index])); + fflush(STDOUT); + } + + code = + AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index], + volname, volser_RO, + vldbEntryPtr->volumeId[RWVOL], &volid, + transPtr); + if (code) { + PrintError("Failed to create the ro volume: ", code); + goto fail; + } + vldbEntryPtr->volumeId[ROVOL] = volid; + + VDONE; + + /* The following is a bit redundant, since create sets these flags by default */ + code = + AFSVolSetFlags(*connPtr, *transPtr, + VTDeleteOnSalvage | VTOutOfService); + if (code) { + PrintError("Failed to set flags on the ro volume: ", code); + goto fail; + } + } + + /* Otherwise, the transaction did succeed, so get the creation date of the + * latest RO volume on the replication site + */ + else { + VPRINT2("Updating existing ro volume %u on %s ...\n", volid, + hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index])); + + code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus); + if (code) { + PrintError("Failed to get status of volume on destination: ", + code); + goto fail; + } + *timePtr = tstatus.creationDate - CLOCKSKEW; + } + + return 0; + + fail: + if (*transPtr) { + tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode); + *transPtr = 0; + if (!tcode) + tcode = rcode; + if (tcode) + PrintError("Could not end transaction on a ro volume: ", tcode); + } + + return code; } -static int SimulateForwardMultiple(fromconn, fromtid, fromdate, tr, - flags, cookie, results) -struct rx_connection *fromconn; -afs_int32 fromtid, fromdate, flags; -manyDests *tr; -void *cookie; -manyResults *results; +static int +SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid, + afs_int32 fromdate, manyDests * tr, afs_int32 flags, + void *cookie, manyResults * results) { - int i; - - for (i=0; imanyDests_len; i++) { - results->manyResults_val[i] = AFSVolForward(fromconn, fromtid, - fromdate, &(tr->manyDests_val[i].server), - tr->manyDests_val[i].trans, cookie); - } - return 0; + int i; + + for (i = 0; i < tr->manyDests_len; i++) { + results->manyResults_val[i] = + AFSVolForward(fromconn, fromtid, fromdate, + &(tr->manyDests_val[i].server), + tr->manyDests_val[i].trans, cookie); + } + return 0; } -static int rel_compar (r1, r2) - struct release *r1, *r2; +static int +rel_compar(struct release *r1, struct release *r2) { - return (r1->time - r2->time); + return (r1->time - r2->time); } /* UV_ReleaseVolume() @@ -1920,541 +3125,684 @@ static int rel_compar (r1, r2) * the time: Influences when we write back the VLDB entry. */ -UV_ReleaseVolume(afromvol, afromserver, afrompart, forceflag) - afs_int32 afromserver; - afs_int32 afrompart; - afs_int32 afromvol; - int forceflag; +int +UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver, + afs_int32 afrompart, int forceflag) { - char vname[64]; - afs_int32 code, vcode, rcode, tcode; - afs_int32 cloneVolId, roVolId; - struct replica *replicas=0; - struct nvldbentry entry,storeEntry; - int i, volcount, m, fullrelease, vldbindex; - int failure; - struct restoreCookie cookie; - struct rx_connection **toconns=0; - struct release *times=0; - int nservers = 0; - struct rx_connection *fromconn = (struct rx_connection *)0; - afs_int32 error = 0; - int islocked = 0; - afs_int32 clonetid=0, onlinetid; - afs_int32 fromtid=0; - afs_uint32 fromdate, thisdate; - int s; - manyDests tr; - manyResults results; - int rwindex, roindex, roclone, roexists; - afs_int32 rwcrdate; - struct rtime { - int validtime; - afs_uint32 time; - } remembertime[NMAXNSERVERS]; - int releasecount = 0; - struct volser_status volstatus; - - memset((char *)remembertime, 0, sizeof(remembertime)); - memset((char *)&results, 0, sizeof(results)); - - vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_RELEASE); - if (vcode != VL_RERELEASE) - ONERROR(vcode, afromvol, "Could not lock the VLDB entry for the volume %u.\n"); - islocked = 1; - - /* Get the vldb entry in readable format */ - vcode = VLDB_GetEntryByID (afromvol, RWVOL, &entry); - ONERROR(vcode, afromvol, "Could not fetch the entry for the volume %u from the VLDB.\n"); - MapHostToNetwork(&entry); - - if (verbose) - EnumerateEntry(&entry); - - if (!ISNAMEVALID(entry.name)) - ONERROR(VOLSERBADOP, entry.name, - "Volume name %s is too long, rename before releasing.\n"); - if (entry.volumeId[RWVOL] != afromvol) - ONERROR(VOLSERBADOP, afromvol, - "The volume %u being released is not a read-write volume.\n"); - if (entry.nServers <= 1) - ONERROR(VOLSERBADOP, afromvol, - "Volume %u has no replicas - release operation is meaningless!\n"); - if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10)) - ONERROR(VOLSERBADOP, entry.name, - "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n"); - - /* roclone is true if one of the RO volumes is on the same - * partition as the RW volume. In this case, we make the RO volume - * on the same partition a clone instead of a complete copy. - */ - - roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1; - roclone = ((roindex == -1) ? 0 : 1); - rwindex = Lp_GetRwIndex(&entry); - if (rwindex < 0) - ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n"); - - /* Make sure we have a RO volume id to work with */ - if (entry.volumeId[ROVOL] == INVALID_BID) { - /* need to get a new RO volume id */ - vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &roVolId); - ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n"); - - entry.volumeId[ROVOL] = roVolId; - MapNetworkToHost(&entry, &storeEntry); - vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0); - ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n"); - } - - /* Will we be completing a previously unfinished release. -force overrides */ - for (fullrelease=1, i=0; (fullrelease && (i (VOLSER_OLDMAXVOLNAME - 10)) + ONERROR(VOLSERBADOP, entry.name, + "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n"); + + /* roclone is true if one of the RO volumes is on the same + * partition as the RW volume. In this case, we make the RO volume + * on the same partition a clone instead of a complete copy. + */ + + roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1; + roclone = ((roindex == -1) ? 0 : 1); + rwindex = Lp_GetRwIndex(&entry); + if (rwindex < 0) + ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n"); + + /* Make sure we have a RO volume id to work with */ + if (entry.volumeId[ROVOL] == INVALID_BID) { + /* need to get a new RO volume id */ + vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &roVolId); + ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n"); + + entry.volumeId[ROVOL] = roVolId; + MapNetworkToHost(&entry, &storeEntry); + vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0); + ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n"); + } + + /* Will we be completing a previously unfinished release. -force overrides */ + for (fullrelease = 1, i = 0; (fullrelease && (i < entry.nServers)); i++) { + if (entry.serverFlags[i] & NEW_REPSITE) + fullrelease = 0; + } + if (forceflag && !fullrelease) + fullrelease = 1; + + /* Determine which volume id to use and see if it exists */ + cloneVolId = + ((fullrelease + || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId); + code = VolumeExists(afromserver, afrompart, cloneVolId); + roexists = ((code == ENODEV) ? 0 : 1); + + fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT); + if (!fromconn) + ONERROR(-1, afromserver, + "Cannot establish connection with server 0x%x\n"); + + if (!fullrelease) { + if (!roexists) + fullrelease = 1; /* Do a full release if RO clone does not exist */ + else { + /* Begin transaction on RW and mark it busy while we query it */ + code = AFSVolTransCreate( + fromconn, afromvol, afrompart, ITBusy, &fromtid + ); + ONERROR(code, afromvol, + "Failed to start transaction on RW volume %u\n"); + + /* Query the creation date for the RW */ + code = AFSVolGetStatus(fromconn, fromtid, &volstatus); + ONERROR(code, afromvol, + "Failed to get the status of RW volume %u\n"); + rwcrdate = volstatus.creationDate; + + /* End transaction on RW */ + code = AFSVolEndTrans(fromconn, fromtid, &rcode); + fromtid = 0; + ONERROR((code ? code : rcode), afromvol, + "Failed to end transaction on RW volume %u\n"); + + /* Begin transaction on clone and mark it busy while we query it */ + code = AFSVolTransCreate( + fromconn, cloneVolId, afrompart, ITBusy, &clonetid + ); + ONERROR(code, cloneVolId, + "Failed to start transaction on RW clone %u\n"); + + /* Query the creation date for the clone */ + code = AFSVolGetStatus(fromconn, clonetid, &volstatus); + ONERROR(code, cloneVolId, + "Failed to get the status of RW clone %u\n"); + clcrdate = volstatus.creationDate; + + /* End transaction on RW */ + code = AFSVolEndTrans(fromconn, clonetid, &rcode); + clonetid = 0; + ONERROR((code ? code : rcode), cloneVolId, + "Failed to end transaction on RW volume %u\n"); + + if (rwcrdate > clcrdate) + fullrelease = 2;/* Do a full release if RO clone older than RW */ + } + } + + if (verbose) { + switch (fullrelease) { + case 2: + fprintf(STDOUT, "RW %lu changed, doing a complete release\n", + (unsigned long)afromvol); + break; + case 1: + fprintf(STDOUT, "This is a complete release of volume %lu\n", + (unsigned long)afromvol); + break; + case 0: + fprintf(STDOUT, "This is a completion of a previous release\n"); + break; + } + } + + if (fullrelease) { + /* If the RO clone exists, then if the clone is a temporary + * clone, delete it. Or if the RO clone is marked RO_DONTUSE + * (it was recently added), then also delete it. We do not + * want to "reclone" a temporary RO clone. + */ + if (roexists + && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) { + code = DelVol(fromconn, cloneVolId, afrompart, ITOffline); + if (code && (code != VNOVOL)) + ERROREXIT(code); + roexists = 0; + } + + /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't + * write this entry out to the vlserver until after the first + * RO volume is released (temp RO clones don't count). + */ + for (i = 0; i < entry.nServers; i++) { + entry.serverFlags[i] &= ~NEW_REPSITE; + entry.serverFlags[i] |= RO_DONTUSE; + } + entry.serverFlags[rwindex] |= NEW_REPSITE; + entry.serverFlags[rwindex] &= ~RO_DONTUSE; + + /* Begin transaction on RW and mark it busy while we clone it */ + code = + AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, + &clonetid); + ONERROR(code, afromvol, "Failed to start transaction on volume %u\n"); + + /* Clone or reclone the volume */ + if (roexists) { + VPRINT1("Recloning RW volume %u...", cloneVolId); + code = AFSVolReClone(fromconn, clonetid, cloneVolId); + ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n"); + VDONE; } else { - strcpy(vname, "readonly-clone-temp"); - if (verbose) - fprintf(STDERR, "Cloning RW volume to temporary RO ...\n"); + if (roclone) { + strcpy(vname, entry.name); + strcat(vname, ".readonly"); + VPRINT("Cloning RW volume %u to permanent RO..."); + } else { + strcpy(vname, "readonly-clone-temp"); + VPRINT("Cloning RW volume %u to temporary RO..."); + } + code = + AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname, + &cloneVolId); + ONERROR(code, afromvol, "Failed to clone the RW volume %u\n"); + VDONE; } - code = AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname, &cloneVolId); - ONERROR(code, afromvol, "Failed to clone the RW volume %u\n"); - } - /* Get the time the RW was created for future information */ - code = AFSVolGetStatus(fromconn, clonetid, &volstatus); - ONERROR(code, cloneVolId, "Failed to get the status of the RW volume %u\n"); - rwcrdate = volstatus.creationDate; + /* Get the time the RW was created for future information */ + VPRINT1("Getting status of RW volume %u...", cloneVolId); + code = AFSVolGetStatus(fromconn, clonetid, &volstatus); + ONERROR(code, cloneVolId, + "Failed to get the status of the RW volume %u\n"); + VDONE; + rwcrdate = volstatus.creationDate; - /* End the transaction on the RW volume */ - code = AFSVolEndTrans(fromconn, clonetid, &rcode); - clonetid = 0; - ONERROR((code?code:rcode), cloneVolId, "Failed to end cloning transaction on RW %u\n"); + /* End the transaction on the RW volume */ + VPRINT1("Ending cloning transaction on RW volume %u...", cloneVolId); + code = AFSVolEndTrans(fromconn, clonetid, &rcode); + clonetid = 0; + ONERROR((code ? code : rcode), cloneVolId, + "Failed to end cloning transaction on RW %u\n"); + VDONE; - /* Remember clone volume ID in case we fail or are interrupted */ - entry.cloneId = cloneVolId; + /* Remember clone volume ID in case we fail or are interrupted */ + entry.cloneId = cloneVolId; - if (roclone) { - /* Bring the RO clone online - though not if it's a temporary clone */ - code = AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline, &onlinetid); - ONERROR(code, cloneVolId, "Failed to start transaction on volume %u\n"); + if (roclone) { + /* Bring the RO clone online - though not if it's a temporary clone */ + VPRINT1("Starting transaction on RO clone volume %u...", + cloneVolId); + code = + AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline, + &onlinetid); + ONERROR(code, cloneVolId, + "Failed to start transaction on volume %u\n"); + VDONE; + + VPRINT1("Setting volume flags for volume %u...", cloneVolId); + tcode = AFSVolSetFlags(fromconn, onlinetid, 0); + VDONE; + + VPRINT1("Ending transaction on volume %u...", cloneVolId); + code = AFSVolEndTrans(fromconn, onlinetid, &rcode); + ONERROR((code ? code : rcode), cloneVolId, + "Failed to end transaction on RO clone %u\n"); + VDONE; + + ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n"); + + /* Sleep so that a client searching for an online volume won't + * find the clone offline and then the next RO offline while the + * release brings the clone online and the next RO offline (race). + * There is a fix in the 3.4 client that does not need this sleep + * anymore, but we don't know what clients we have. + */ + if (entry.nServers > 2) + sleep(5); - tcode = AFSVolSetFlags(fromconn, onlinetid, 0); + /* Mark the RO clone in the VLDB as a good site (already released) */ + entry.serverFlags[roindex] |= NEW_REPSITE; + entry.serverFlags[roindex] &= ~RO_DONTUSE; + entry.flags |= RO_EXISTS; - code = AFSVolEndTrans(fromconn, onlinetid, &rcode); - ONERROR((code?code:rcode), cloneVolId, "Failed to end transaction on RO clone %u\n"); + releasecount++; - ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n"); + /* Write out the VLDB entry only if the clone is not a temporary + * clone. If we did this to a temporary clone then we would end + * up marking all the ROs as "old release" making the ROs + * temporarily unavailable. + */ + MapNetworkToHost(&entry, &storeEntry); + VPRINT1("Replacing VLDB entry for %s...", entry.name); + vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0); + ONERROR(vcode, entry.name, + "Could not update vldb entry for %s.\n"); + VDONE; + } + } - /* Sleep so that a client searching for an online volume won't - * find the clone offline and then the next RO offline while the - * release brings the clone online and the next RO offline (race). - * There is a fix in the 3.4 client that does not need this sleep - * anymore, but we don't know what clients we have. - */ - if (entry.nServers > 2) - sleep(5); + /* Now we will release from the clone to the remaining RO replicas. + * The first 2 ROs (counting the non-temporary RO clone) are released + * individually: releasecount. This is to reduce the race condition + * of clients trying to find an on-line RO volume. The remaining ROs + * are released in parallel but no more than half the number of ROs + * (rounded up) at a time: nservers. + */ - /* Mark the RO clone in the VLDB as a good site (already released)*/ - entry.serverFlags[roindex] |= NEW_REPSITE; - entry.serverFlags[roindex] &= ~RO_DONTUSE; - entry.flags |= RO_EXISTS; + strcpy(vname, entry.name); + strcat(vname, ".readonly"); + memset(&cookie, 0, sizeof(cookie)); + strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME); + cookie.type = ROVOL; + cookie.parent = entry.volumeId[RWVOL]; + cookie.clone = 0; - releasecount++; + nservers = entry.nServers / 2; /* how many to do at once, excluding clone */ + replicas = + (struct replica *)malloc(sizeof(struct replica) * nservers + 1); + times = (struct release *)malloc(sizeof(struct release) * nservers + 1); + toconns = + (struct rx_connection **)malloc(sizeof(struct rx_connection *) * + nservers + 1); + results.manyResults_val = + (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1); + if (!replicas || !times || !!!results.manyResults_val || !toconns) + ONERROR(ENOMEM, 0, + "Failed to create transaction on the release clone\n"); + + memset(replicas, 0, (sizeof(struct replica) * nservers + 1)); + memset(times, 0, (sizeof(struct release) * nservers + 1)); + memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1)); + memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1)); + + /* Create a transaction on the cloned volume */ + VPRINT1("Starting transaction on cloned volume %u...", cloneVolId); + code = + AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid); + if (!fullrelease && code) + ONERROR(VOLSERNOVOL, afromvol, + "Old clone is inaccessible. Try vos release -f %u.\n"); + ONERROR(code, 0, "Failed to create transaction on the release clone\n"); + VDONE; + + /* For each index in the VLDB */ + for (vldbindex = 0; vldbindex < entry.nServers;) { + + /* Get a transaction on the replicas. Pick replacas which have an old release. */ + for (volcount = 0; + ((volcount < nservers) && (vldbindex < entry.nServers)); + vldbindex++) { + /* The first two RO volumes will be released individually. + * The rest are then released in parallel. This is a hack + * for clients not recognizing right away when a RO volume + * comes back on-line. + */ + if ((volcount == 1) && (releasecount < 2)) + break; + + if (vldbindex == roindex) + continue; /* the clone */ + if ((entry.serverFlags[vldbindex] & NEW_REPSITE) + && !(entry.serverFlags[vldbindex] & RO_DONTUSE)) + continue; + if (!(entry.serverFlags[vldbindex] & ITSROVOL)) + continue; /* not a RO vol */ + + + /* Get a Transaction on this replica. Get a new connection if + * necessary. Create the volume if necessary. Return the + * time from which the dump should be made (0 if it's a new + * volume). Each volume might have a different time. + */ + replicas[volcount].server.destHost = + ntohl(entry.serverNumber[vldbindex]); + replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT; + replicas[volcount].server.destSSID = 1; + times[volcount].vldbEntryIndex = vldbindex; + + code = + GetTrans(&entry, vldbindex, &(toconns[volcount]), + &(replicas[volcount].trans), + &(times[volcount].time)); + if (code) + continue; + + /* Thisdate is the date from which we want to pick up all changes */ + if (forceflag || !fullrelease + || (rwcrdate > times[volcount].time)) { + /* If the forceflag is set, then we want to do a full dump. + * If it's not a full release, we can't be sure that the creation + * date is good (so we also do a full dump). + * If the RW volume was replaced (its creation date is newer than + * the last release), then we can't be sure what has changed (so + * we do a full dump). + */ + thisdate = 0; + } else if (remembertime[vldbindex].validtime) { + /* Trans was prev ended. Use the time from the prev trans + * because, prev trans may have created the volume. In which + * case time[volcount].time would be now instead of 0. + */ + thisdate = + (remembertime[vldbindex].time < + times[volcount].time) ? remembertime[vldbindex]. + time : times[volcount].time; + } else { + thisdate = times[volcount].time; + } + remembertime[vldbindex].validtime = 1; + remembertime[vldbindex].time = thisdate; + + if (volcount == 0) { + fromdate = thisdate; + } else { + /* Include this volume if it is within 15 minutes of the earliest */ + if (((fromdate > + thisdate) ? (fromdate - thisdate) : (thisdate - + fromdate)) > 900) { + AFSVolEndTrans(toconns[volcount], + replicas[volcount].trans, &rcode); + replicas[volcount].trans = 0; + break; + } + if (thisdate < fromdate) + fromdate = thisdate; + } + volcount++; + } + if (!volcount) + continue; + + if (verbose) { + fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s", + (unsigned long)cloneVolId, entry.volumeId[ROVOL], + hostutil_GetNameByINet(entry. + serverNumber[times[0]. + vldbEntryIndex])); + + for (s = 1; s < volcount; s++) { + fprintf(STDOUT, " and %s", + hostutil_GetNameByINet(entry. + serverNumber[times[s]. + vldbEntryIndex])); + } + + if (fromdate == 0) + fprintf(STDOUT, " (full release)"); + fprintf(STDOUT, ".\n"); + fflush(STDOUT); + } + + /* Release the ones we have collected */ + tr.manyDests_val = &(replicas[0]); + tr.manyDests_len = results.manyResults_len = volcount; + code = + AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr, + 0 /*spare */ , &cookie, &results); + if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */ + code = + SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr, + 0 /*spare */ , &cookie, &results); + nservers = 1; + } + + if (code) { + PrintError("Release failed: ", code); + } else { + for (m = 0; m < volcount; m++) { + if (results.manyResults_val[m]) { + if ((m == 0) || (results.manyResults_val[m] != ENOENT)) { + /* we retry timed out transaction. When it is + * not the first volume and the transaction wasn't found + * (assume it timed out and was garbage collected by volser). + */ + PrintError + ("Failed to dump volume from clone to a ro site: ", + results.manyResults_val[m]); + } + continue; + } + + code = + AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname, + ROVOL, entry.volumeId[RWVOL], 0, 0); + if (code) { + if ((m == 0) || (code != ENOENT)) { + PrintError("Failed to set correct names and ids: ", + code); + } + continue; + } + + /* have to clear dest. flags to ensure new vol goes online: + * because the restore (forwarded) operation copied + * the V_inService(=0) flag over to the destination. + */ + code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0); + if (code) { + if ((m == 0) || (code != ENOENT)) { + PrintError("Failed to set flags on ro volume: ", + code); + } + continue; + } + + entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE; + entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE; + entry.flags |= RO_EXISTS; + releasecount++; + } + } + + /* End the transactions and destroy the connections */ + for (s = 0; s < volcount; s++) { + if (replicas[s].trans) + code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode); + replicas[s].trans = 0; + if (!code) + code = rcode; + if (code) { + if ((s == 0) || (code != ENOENT)) { + PrintError("Could not end transaction on a ro volume: ", + code); + } else { + PrintError + ("Transaction timed out on a ro volume. Will retry.\n", + 0); + if (times[s].vldbEntryIndex < vldbindex) + vldbindex = times[s].vldbEntryIndex; + } + } + + if (toconns[s]) + rx_DestroyConnection(toconns[s]); + toconns[s] = 0; + } - /* Write out the VLDB entry only if the clone is not a temporary - * clone. If we did this to a temporary clone then we would end - * up marking all the ROs as "old release" making the ROs - * temporarily unavailable. - */ MapNetworkToHost(&entry, &storeEntry); vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0); - ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n"); - } - } - - /* Now we will release from the clone to the remaining RO replicas. - * The first 2 ROs (counting the non-temporary RO clone) are released - * individually: releasecount. This is to reduce the race condition - * of clients trying to find an on-line RO volume. The remaining ROs - * are released in parallel but no more than half the number of ROs - * (rounded up) at a time: nservers. - */ - - strcpy(vname, entry.name); - strcat(vname, ".readonly"); - memset(&cookie, 0, sizeof(cookie)); - strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME); - cookie.type = ROVOL; - cookie.parent = entry.volumeId[RWVOL]; - cookie.clone = 0; - - nservers = entry.nServers/2; /* how many to do at once, excluding clone */ - replicas = (struct replica *) malloc (sizeof(struct replica)*nservers+1); - times = (struct release *) malloc (sizeof(struct release)*nservers+1); - toconns = (struct rx_connection **) malloc (sizeof(struct rx_connection *)*nservers+1); - results.manyResults_val = (afs_int32 *) malloc (sizeof(afs_int32)*nservers+1); - if ( !replicas || !times || !! !results.manyResults_val || !toconns ) - ONERROR(ENOMEM, 0, "Failed to create transaction on the release clone\n"); - - memset(replicas, 0, (sizeof(struct replica)*nservers+1)); - memset(times, 0, (sizeof(struct release)*nservers+1)); - memset(toconns, 0, (sizeof(struct rx_connection *)*nservers+1)); - memset(results.manyResults_val, 0, (sizeof(afs_int32)*nservers+1)); - - /* Create a transaction on the cloned volume */ - code = AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid); - if (!fullrelease && code) - ONERROR(VOLSERNOVOL, afromvol,"Old clone is inaccessible. Try vos release -f %u.\n"); - ONERROR(code, 0, "Failed to create transaction on the release clone\n"); - - /* For each index in the VLDB */ - for (vldbindex=0; vldbindex times[volcount].time)) { - /* If the forceflag is set, then we want to do a full dump. - * If it's not a full release, we can't be sure that the creation - * date is good (so we also do a full dump). - * If the RW volume was replaced (its creation date is newer than - * the last release), then we can't be sure what has changed (so - * we do a full dump). - */ - thisdate = 0; - } else if (remembertime[vldbindex].validtime) { - /* Trans was prev ended. Use the time from the prev trans - * because, prev trans may have created the volume. In which - * case time[volcount].time would be now instead of 0. - */ - thisdate = (remembertime[vldbindex].time < times[volcount].time) ? - remembertime[vldbindex].time : times[volcount].time; - } else { - thisdate = times[volcount].time; - } - remembertime[vldbindex].validtime = 1; - remembertime[vldbindex].time = thisdate; + MapNetworkToHost(&entry, &storeEntry); + vcode = + VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, + LOCKREL_TIMESTAMP); + ONERROR(vcode, afromvol, + " Could not update VLDB entry for volume %u\n"); - if (volcount == 0) { - fromdate = thisdate; - } else { - /* Include this volume if it is within 15 minutes of the earliest */ - if (((fromdate>thisdate)?(fromdate-thisdate):(thisdate-fromdate)) > 900) { - AFSVolEndTrans(toconns[volcount], replicas[volcount].trans, &rcode); - replicas[volcount].trans = 0; - break; - } - if (thisdate < fromdate) - fromdate = thisdate; - } - volcount++; - } - if (!volcount) continue; - - if (verbose) { - fprintf(STDOUT,"Starting ForwardMulti from %u to %u on %s", - cloneVolId, entry.volumeId[ROVOL], - hostutil_GetNameByINet(entry.serverNumber[times[0].vldbEntryIndex])); - - for (s=1; s on and @@ -2462,101 +3810,238 @@ void dump_sig_handler(x) * DumpFunction does the real work behind the scenes after * extracting parameters from the rock */ -UV_DumpVolume(afromvol, afromserver, afrompart, fromdate, DumpFunction, rock) - afs_int32 afromserver; - afs_int32 afrompart; - afs_int32 afromvol; - afs_int32 fromdate; - afs_int32 (*DumpFunction)(); - char *rock; +int +UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart, + afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock) { - struct rx_connection *fromconn = (struct rx_connection *)0; - struct rx_call *fromcall = (struct rx_call *)0; - afs_int32 fromtid=0, rxError=0, rcode=0; - afs_int32 code, error = 0; + struct rx_connection *fromconn = (struct rx_connection *)0; + struct rx_call *fromcall = (struct rx_call *)0; + afs_int32 fromtid = 0, rxError = 0, rcode = 0; + afs_int32 code, error = 0; - if (setjmp(env)) ERROR_EXIT(EPIPE); + if (setjmp(env)) + ERROR_EXIT(EPIPE); #ifndef AFS_NT40_ENV - (void) signal(SIGPIPE, dump_sig_handler); + (void)signal(SIGPIPE, dump_sig_handler); #endif - (void) signal(SIGINT, dump_sig_handler); - - /* get connections to the servers */ - fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT); - code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid); - if (code) { - fprintf(STDERR,"Could not start transaction on the volume %u to be dumped\n", afromvol); - ERROR_EXIT(code); - } - - if (verbose) { - if (!fromdate) - fprintf(STDERR,"Full Dump ..."); - else - fprintf(STDERR,"Incremental Dump (as of %.24s) ...", - ctime((time_t *)&fromdate)); - fflush(STDERR); - } - - fromcall = rx_NewCall(fromconn); - code = StartAFSVolDump(fromcall, fromtid, fromdate); - if (code) { - fprintf(STDERR,"Could not start the dump process \n"); - ERROR_EXIT(code); - } - if (code = DumpFunction(fromcall, rock)) { - fprintf(STDERR,"Error while dumping volume \n"); - ERROR_EXIT(code); - } - - if (verbose) - fprintf(STDERR,"completed\n"); - - error_exit: - if (fromcall) { - code = rx_EndCall(fromcall, rxError); - if (code) { - fprintf(STDERR,"Error in rx_EndCall\n"); - if (!error) error = code; - } - } - if (fromtid) { - code = AFSVolEndTrans(fromconn, fromtid, &rcode); - if (code || rcode) { - fprintf(STDERR,"Could not end transaction on the volume %u\n", afromvol); - if (!error) error = (code?code:rcode); - } - } - if (fromconn) - rx_DestroyConnection(fromconn); - - PrintError("", error); - return(error); + (void)signal(SIGINT, dump_sig_handler); + + if (!fromdate) { + VPRINT("Full Dump ...\n"); + } else { + VPRINT1("Incremental Dump (as of %.24s)...\n", + ctime((time_t *) & fromdate)); + } + + /* get connections to the servers */ + fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT); + + VPRINT1("Starting transaction on volume %u...", afromvol); + code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid); + EGOTO1(error_exit, code, + "Could not start transaction on the volume %u to be dumped\n", + afromvol); + VDONE; + + fromcall = rx_NewCall(fromconn); + + VPRINT1("Starting volume dump on volume %u...", afromvol); + code = StartAFSVolDump(fromcall, fromtid, fromdate); + EGOTO(error_exit, code, "Could not start the dump process \n"); + VDONE; + + VPRINT1("Dumping volume %u...", afromvol); + code = DumpFunction(fromcall, rock); + EGOTO(error_exit, code, "Error while dumping volume \n"); + VDONE; + + error_exit: + if (fromcall) { + code = rx_EndCall(fromcall, rxError); + if (code) { + fprintf(STDERR, "Error in rx_EndCall\n"); + if (!error) + error = code; + } + } + if (fromtid) { + VPRINT1("Ending transaction on volume %u...", afromvol); + code = AFSVolEndTrans(fromconn, fromtid, &rcode); + if (code || rcode) { + fprintf(STDERR, "Could not end transaction on the volume %lu\n", + (unsigned long)afromvol); + if (!error) + error = (code ? code : rcode); + } + VDONE; + } + if (fromconn) + rx_DestroyConnection(fromconn); + + PrintError("", error); + return (error); } +/* Clone the volume on and + * , and then dump the clone volume to + * starting from . + * DumpFunction does the real work behind the scenes after + * extracting parameters from the rock + */ +int +UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver, + afs_int32 afrompart, afs_int32 fromdate, + afs_int32(*DumpFunction) (), char *rock) +{ + struct rx_connection *fromconn = (struct rx_connection *)0; + struct rx_call *fromcall = (struct rx_call *)0; + afs_int32 fromtid = 0, rxError = 0, rcode = 0; + afs_int32 clonetid = 0; + afs_int32 code = 0, vcode = 0, error = 0; + afs_int32 clonevol = 0; + char vname[64]; + + if (setjmp(env)) + ERROR_EXIT(EPIPE); +#ifndef AFS_NT40_ENV + (void)signal(SIGPIPE, dump_sig_handler); +#endif + (void)signal(SIGINT, dump_sig_handler); + + if (!fromdate) { + VPRINT("Full Dump ...\n"); + } else { + VPRINT1("Incremental Dump (as of %.24s)...\n", + ctime((time_t *) & fromdate)); + } + + /* get connections to the servers */ + fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT); + + VPRINT1("Starting transaction on volume %u...", afromvol); + code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid); + EGOTO1(error_exit, code, + "Could not start transaction on the volume %u to be dumped\n", + afromvol); + VDONE; + + /* Get a clone id */ + VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol); + code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &clonevol); + EGOTO1(error_exit, code, + "Could not get an ID for the clone of volume %u from the VLDB\n", + afromvol); + VDONE; + + /* Do the clone. Default flags on clone are set to delete on salvage and out of service */ + VPRINT2("Cloning source volume %u to clone volume %u...", afromvol, + clonevol); + strcpy(vname, "dump-clone-temp"); + code = + AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol); + EGOTO1(error_exit, code, "Failed to clone the source volume %u\n", + afromvol); + VDONE; + + VPRINT1("Ending the transaction on the volume %u ...", afromvol); + rcode = 0; + code = AFSVolEndTrans(fromconn, fromtid, &rcode); + fromtid = 0; + if (!code) + code = rcode; + EGOTO1(error_exit, code, + "Failed to end the transaction on the volume %u\n", afromvol); + VDONE; + + + VPRINT1("Starting transaction on the cloned volume %u ...", clonevol); + code = + AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline, + &clonetid); + EGOTO1(error_exit, code, + "Failed to start a transaction on the cloned volume%u\n", + clonevol); + VDONE; + + VPRINT1("Setting flags on cloned volume %u ...", clonevol); + code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */ + EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n", + clonevol); + VDONE; + + + fromcall = rx_NewCall(fromconn); + + VPRINT1("Starting volume dump from cloned volume %u...", clonevol); + code = StartAFSVolDump(fromcall, clonetid, fromdate); + EGOTO(error_exit, code, "Could not start the dump process \n"); + VDONE; + + VPRINT1("Dumping volume %u...", afromvol); + code = DumpFunction(fromcall, rock); + EGOTO(error_exit, code, "Error while dumping volume \n"); + VDONE; + + error_exit: + /* now delete the clone */ + VPRINT1("Deleting the cloned volume %u ...", clonevol); + code = AFSVolDeleteVolume(fromconn, clonetid); + if (code) { + fprintf(STDERR, "Failed to delete the cloned volume %lu\n", + (unsigned long)clonevol); + } else { + VDONE; + } + + if (fromcall) { + code = rx_EndCall(fromcall, rxError); + if (code) { + fprintf(STDERR, "Error in rx_EndCall\n"); + if (!error) + error = code; + } + } + if (clonetid) { + VPRINT1("Ending transaction on cloned volume %u...", clonevol); + code = AFSVolEndTrans(fromconn, clonetid, &rcode); + if (code || rcode) { + fprintf(STDERR, + "Could not end transaction on the cloned volume %lu\n", + (unsigned long)clonevol); + if (!error) + error = (code ? code : rcode); + } + VDONE; + } + if (fromconn) + rx_DestroyConnection(fromconn); + + PrintError("", error); + return (error); +} + + /* * Restore a volume on from * the dump file . WriteData does all the real work * after extracting params from the rock */ -UV_RestoreVolume(toserver, topart, tovolid, tovolname, flags, WriteData, rock) - afs_int32 toserver, topart, tovolid; - char tovolname[]; - int flags; - afs_int32 (*WriteData)(); - char *rock; +int +UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid, + char tovolname[], int flags, afs_int32(*WriteData) (), + char *rock) { - struct rx_connection *toconn,*tempconn; + struct rx_connection *toconn, *tempconn; struct rx_call *tocall; - afs_int32 totid, code, rcode, vcode,terror = 0; + afs_int32 totid, code, rcode, vcode, terror = 0; afs_int32 rxError = 0; struct volser_status tstatus; char partName[10]; afs_int32 pvolid; afs_int32 temptid; int success; - struct nvldbentry entry,storeEntry; + struct nvldbentry entry, storeEntry; afs_int32 error; int islocked; struct restoreCookie cookie; @@ -2567,7 +4052,7 @@ UV_RestoreVolume(toserver, topart, tovolid, tovolname, flags, WriteData, rock) memset(&cookie, 0, sizeof(cookie)); - islocked = 0; + islocked = 0; success = 0; error = 0; reuseID = 1; @@ -2578,222 +4063,239 @@ UV_RestoreVolume(toserver, topart, tovolid, tovolname, flags, WriteData, rock) temptid = 0; if (flags & RV_RDONLY) { - voltype = ROVOL; + voltype = ROVOL; volsertype = volser_RO; } else { - voltype = RWVOL; + voltype = RWVOL; volsertype = volser_RW; } pvolid = tovolid; toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT); - if(pvolid == 0) {/*alot a new id if needed */ + if (pvolid == 0) { /*alot a new id if needed */ vcode = VLDB_GetEntryByName(tovolname, &entry); - if(vcode == VL_NOENT) { - vcode = ubik_Call(VL_GetNewVolumeId,cstruct, 0, 1, &pvolid); - if(vcode) { - fprintf(STDERR,"Could not get an Id for the volume %s\n",tovolname); + if (vcode == VL_NOENT) { + vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &pvolid); + if (vcode) { + fprintf(STDERR, "Could not get an Id for the volume %s\n", + tovolname); error = vcode; goto refail; } reuseID = 0; - } else if (flags & RV_RDONLY) { + } else if (flags & RV_RDONLY) { if (entry.flags & RW_EXISTS) { - fprintf(STDERR,"Entry for ReadWrite volume %s already exists!\n",entry.name); + fprintf(STDERR, + "Entry for ReadWrite volume %s already exists!\n", + entry.name); error = VOLSERBADOP; goto refail; } if (!entry.volumeId[ROVOL]) { - fprintf(STDERR,"Existing entry for volume %s has no ReadOnly ID\n",tovolname); + fprintf(STDERR, + "Existing entry for volume %s has no ReadOnly ID\n", + tovolname); error = VOLSERBADOP; goto refail; } pvolid = entry.volumeId[ROVOL]; } else { pvolid = entry.volumeId[RWVOL]; - } - }/* at this point we have a volume id to use/reuse for the volume to be restored */ - - if(strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) { - fprintf(STDERR,"The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",tovolname); - error = VOLSERBADOP; - goto refail; + } + } + /* at this point we have a volume id to use/reuse for the volume to be restored */ + if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) { + EGOTO1(refail, VOLSERBADOP, + "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", + tovolname); } MapPartIdIntoName(topart, partName); - fprintf(STDOUT,"Restoring volume %s Id %u on server %s partition %s ..", tovolname, - pvolid, hostutil_GetNameByINet(toserver), partName); + fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..", + tovolname, (unsigned long)pvolid, + hostutil_GetNameByINet(toserver), partName); fflush(STDOUT); - code = AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0,&pvolid, &totid); - if (code){ - if (flags & RV_FULLRST) { /* full restore: delete then create anew */ - if(verbose) { - fprintf(STDOUT,"Deleting the previous volume %u ...",pvolid); - fflush(STDOUT); - } - code = AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid); - if (code) { - fprintf(STDERR,"Failed to start transaction on %u\n",pvolid); - error = code; - goto refail; - } - code = AFSVolSetFlags(toconn, totid, VTDeleteOnSalvage | VTOutOfService); - if (code){ - fprintf(STDERR,"Could not set flags on volume %u \n",pvolid); - error = code; - goto refail; - } - code = AFSVolDeleteVolume(toconn,totid); - if (code){ - fprintf(STDERR,"Could not delete volume %u\n",pvolid); - error = code; - goto refail; - } + code = + AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0, &pvolid, + &totid); + if (code) { + if (flags & RV_FULLRST) { /* full restore: delete then create anew */ + VPRINT1("Deleting the previous volume %u ...", pvolid); + + code = + AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid); + EGOTO1(refail, code, "Failed to start transaction on %u\n", + pvolid); + + code = + AFSVolSetFlags(toconn, totid, + VTDeleteOnSalvage | VTOutOfService); + EGOTO1(refail, code, "Could not set flags on volume %u \n", + pvolid); + + code = AFSVolDeleteVolume(toconn, totid); + EGOTO1(refail, code, "Could not delete volume %u\n", pvolid); + code = AFSVolEndTrans(toconn, totid, &rcode); totid = 0; - if (!code) code = rcode; - if (code) { - fprintf(STDERR,"Could not end transaction on %u\n",pvolid); - error = code; - goto refail; - } - if (verbose) fprintf(STDOUT," done\n"); - code = AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0,&pvolid, &totid); - if (code){ - fprintf(STDERR,"Could not create new volume %u\n",pvolid); - error = code; - goto refail;} - } - else{ - - code = AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid); - if (code) { - fprintf(STDERR,"Failed to start transaction on %u\n",pvolid); - error = code; - goto refail; - } + if (!code) + code = rcode; + EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid); + + VDONE; + + code = + AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0, + &pvolid, &totid); + EGOTO1(refail, code, "Could not create new volume %u\n", pvolid); + + newDate = 0; + } else { + code = + AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid); + EGOTO1(refail, code, "Failed to start transaction on %u\n", + pvolid); + + code = AFSVolGetStatus(toconn, totid, &tstatus); + EGOTO1(refail, code, "Could not get timestamp from volume %u\n", + pvolid); + newDate = tstatus.creationDate; } } cookie.parent = pvolid; cookie.type = voltype; cookie.clone = 0; - strncpy(cookie.name,tovolname,VOLSER_OLDMAXVOLNAME); + strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME); tocall = rx_NewCall(toconn); - terror = StartAFSVolRestore(tocall,totid, 1,&cookie); - if(terror) { - fprintf(STDERR,"Volume restore Failed \n"); + terror = StartAFSVolRestore(tocall, totid, 1, &cookie); + if (terror) { + fprintf(STDERR, "Volume restore Failed \n"); error = terror; goto refail; } code = WriteData(tocall, rock); - if(code) { - fprintf(STDERR,"Could not transmit data\n"); + if (code) { + fprintf(STDERR, "Could not transmit data\n"); error = code; goto refail; } - terror = rx_EndCall(tocall,rxError); - tocall = (struct rx_call *) 0; + terror = rx_EndCall(tocall, rxError); + tocall = (struct rx_call *)0; if (terror) { - fprintf(STDERR,"rx_EndCall Failed \n"); - error = terror; + fprintf(STDERR, "rx_EndCall Failed \n"); + error = terror; goto refail; } - code = AFSVolGetStatus(toconn,totid, &tstatus); - if(code) { - fprintf(STDERR,"Could not get status information about the volume %u\n",pvolid); + code = AFSVolGetStatus(toconn, totid, &tstatus); + if (code) { + fprintf(STDERR, + "Could not get status information about the volume %lu\n", + (unsigned long)pvolid); error = code; goto refail; } - code = AFSVolSetIdsTypes(toconn,totid, tovolname, voltype, pvolid,0,0); - if(code) { - fprintf(STDERR,"Could not set the right type and ID on %u\n",pvolid); + code = AFSVolSetIdsTypes(toconn, totid, tovolname, voltype, pvolid, 0, 0); + if (code) { + fprintf(STDERR, "Could not set the right type and ID on %lu\n", + (unsigned long)pvolid); error = code; goto refail; } - newDate = time(0); - code = AFSVolSetDate(toconn,totid, newDate); - if(code) { - fprintf(STDERR,"Could not set the date on %u\n",pvolid); + if (!newDate) + newDate = time(0); + code = AFSVolSetDate(toconn, totid, newDate); + if (code) { + fprintf(STDERR, "Could not set the date on %lu\n", + (unsigned long)pvolid); error = code; goto refail; } - volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */ + volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */ code = AFSVolSetFlags(toconn, totid, volflag); - if (code){ - fprintf(STDERR,"Could not mark %u online\n",pvolid ); + if (code) { + fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid); error = code; goto refail; } - + /* It isn't handled right in refail */ code = AFSVolEndTrans(toconn, totid, &rcode); totid = 0; - if(!code) code = rcode; - if(code) { - fprintf(STDERR,"Could not end transaction on %u\n",pvolid); + if (!code) + code = rcode; + if (code) { + fprintf(STDERR, "Could not end transaction on %lu\n", + (unsigned long)pvolid); error = code; goto refail; } success = 1; - fprintf(STDOUT," done\n"); + fprintf(STDOUT, " done\n"); fflush(STDOUT); if (success && (!reuseID || (flags & RV_FULLRST))) { - /* Volume was restored on the file server, update the + /* Volume was restored on the file server, update the * VLDB to reflect the change. */ - vcode = VLDB_GetEntryByID(pvolid,voltype, &entry); - if(vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) { - fprintf(STDERR,"Could not fetch the entry for volume number %u from VLDB \n",pvolid); + vcode = VLDB_GetEntryByID(pvolid, voltype, &entry); + if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) { + fprintf(STDERR, + "Could not fetch the entry for volume number %lu from VLDB \n", + (unsigned long)pvolid); error = vcode; goto refail; } - if (!vcode) MapHostToNetwork(&entry); - if(vcode == VL_NOENT) { /* it doesnot exist already */ - /*make the vldb return this indication specifically*/ - if (verbose) fprintf(STDOUT,"------- Creating a new VLDB entry ------- \n"); + if (!vcode) + MapHostToNetwork(&entry); + if (vcode == VL_NOENT) { /* it doesnot exist already */ + /*make the vldb return this indication specifically */ + VPRINT("------- Creating a new VLDB entry ------- \n"); strcpy(entry.name, tovolname); entry.nServers = 1; - entry.serverNumber[0] = toserver;/*should be indirect */ + entry.serverNumber[0] = toserver; /*should be indirect */ entry.serverPartition[0] = topart; entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL; entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS; if (flags & RV_RDONLY) entry.volumeId[ROVOL] = pvolid; - else if(tstatus.cloneID != 0){ - entry.volumeId[ROVOL] = tstatus.cloneID;/*this should come from status info on the volume if non zero */ - } - else + else if (tstatus.cloneID != 0) { + entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */ + } else entry.volumeId[ROVOL] = INVALID_BID; entry.volumeId[RWVOL] = pvolid; entry.cloneId = 0; - if(tstatus.backupID != 0){ + if (tstatus.backupID != 0) { entry.volumeId[BACKVOL] = tstatus.backupID; /*this should come from status info on the volume if non zero */ - } - else + } else entry.volumeId[BACKVOL] = INVALID_BID; - MapNetworkToHost(&entry,&storeEntry); + MapNetworkToHost(&entry, &storeEntry); vcode = VLDB_CreateEntry(&storeEntry); - if(vcode) { - fprintf(STDERR,"Could not create the VLDB entry for volume number %u \n",pvolid); + if (vcode) { + fprintf(STDERR, + "Could not create the VLDB entry for volume number %lu \n", + (unsigned long)pvolid); error = vcode; goto refail; } islocked = 0; - if (verbose) EnumerateEntry(&entry); - } - else { /*update the existing entry */ - if(verbose) { - fprintf(STDOUT,"Updating the existing VLDB entry\n"); - fprintf(STDOUT,"------- Old entry -------\n"); + if (verbose) + EnumerateEntry(&entry); + } else { /*update the existing entry */ + if (verbose) { + fprintf(STDOUT, "Updating the existing VLDB entry\n"); + fprintf(STDOUT, "------- Old entry -------\n"); EnumerateEntry(&entry); - fprintf(STDOUT,"------- New entry -------\n"); + fprintf(STDOUT, "------- New entry -------\n"); } - vcode = ubik_Call(VL_SetLock,cstruct, 0, pvolid, voltype, VLOP_RESTORE); - if(vcode) { - fprintf(STDERR,"Could not lock the entry for volume number %u \n",pvolid); + vcode = + ubik_Call(VL_SetLock, cstruct, 0, pvolid, voltype, + VLOP_RESTORE); + if (vcode) { + fprintf(STDERR, + "Could not lock the entry for volume number %lu \n", + (unsigned long)pvolid); error = vcode; goto refail; } @@ -2806,214 +4308,274 @@ UV_RestoreVolume(toserver, topart, tovolid, tovolname, flags, WriteData, rock) else index = Lp_GetRwIndex(&entry); if (index == -1) { - /* Add the new site for the volume being restored */ - entry.serverNumber[entry.nServers] = toserver; - entry.serverPartition[entry.nServers] = topart; - entry.serverFlags[entry.nServers] = - (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL; - entry.nServers++; + /* Add the new site for the volume being restored */ + entry.serverNumber[entry.nServers] = toserver; + entry.serverPartition[entry.nServers] = topart; + entry.serverFlags[entry.nServers] = + (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL; + entry.nServers++; } else { - /* This volume should be deleted on the old site - * if its different from new site. - */ - same = VLDB_IsSameAddrs(toserver, entry.serverNumber[index], &errcode); - if (errcode) { - fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d)\n", - toserver, errcode); - } - if ( (!errcode && !same) || (entry.serverPartition[index] != topart) ) { - tempconn = UV_Bind(entry.serverNumber[index], AFSCONF_VOLUMEPORT); - if (verbose) { - MapPartIdIntoName(entry.serverPartition[index], apartName); - fprintf(STDOUT,"Deleting the previous volume %u on server %s, partition %s ...", - pvolid, - hostutil_GetNameByINet(entry.serverNumber[index]), apartName); - fflush(STDOUT); - } - code = AFSVolTransCreate(tempconn, pvolid, entry.serverPartition[index], ITOffline, &temptid); - if (!code){ - code = AFSVolSetFlags(tempconn, temptid, VTDeleteOnSalvage | VTOutOfService); - if(code) { - fprintf(STDERR,"Could not set flags on volume %u on the older site\n",pvolid); - error = code; - goto refail; - } - code = AFSVolDeleteVolume(tempconn,temptid); - if(code){ - fprintf(STDERR,"Could not delete volume %u on the older site\n",pvolid); - error = code; - goto refail; - } - code = AFSVolEndTrans(tempconn, temptid, &rcode); - temptid = 0; - if(!code) code = rcode; - if(code){ - fprintf(STDERR,"Could not end transaction on volume %u on the older site\n",pvolid); - error = code; - goto refail; - } - if(verbose) fprintf(STDOUT," done\n"); - MapPartIdIntoName(entry.serverPartition[index],partName); - } - } - entry.serverNumber[index] = toserver; - entry.serverPartition[index] = topart; + /* This volume should be deleted on the old site + * if its different from new site. + */ + same = + VLDB_IsSameAddrs(toserver, entry.serverNumber[index], + &errcode); + EPRINT2(errcode, + "Failed to get info about server's %d address(es) from vlserver (err=%d)\n", + toserver, errcode); + if ((!errcode && !same) + || (entry.serverPartition[index] != topart)) { + tempconn = + UV_Bind(entry.serverNumber[index], + AFSCONF_VOLUMEPORT); + + MapPartIdIntoName(entry.serverPartition[index], + apartName); + VPRINT3 + ("Deleting the previous volume %u on server %s, partition %s ...", + pvolid, + hostutil_GetNameByINet(entry.serverNumber[index]), + apartName); + code = + AFSVolTransCreate(tempconn, pvolid, + entry.serverPartition[index], + ITOffline, &temptid); + if (!code) { + code = + AFSVolSetFlags(tempconn, temptid, + VTDeleteOnSalvage | + VTOutOfService); + if (code) { + fprintf(STDERR, + "Could not set flags on volume %lu on the older site\n", + (unsigned long)pvolid); + error = code; + goto refail; + } + code = AFSVolDeleteVolume(tempconn, temptid); + if (code) { + fprintf(STDERR, + "Could not delete volume %lu on the older site\n", + (unsigned long)pvolid); + error = code; + goto refail; + } + code = AFSVolEndTrans(tempconn, temptid, &rcode); + temptid = 0; + if (!code) + code = rcode; + if (code) { + fprintf(STDERR, + "Could not end transaction on volume %lu on the older site\n", + (unsigned long)pvolid); + error = code; + goto refail; + } + VDONE; + MapPartIdIntoName(entry.serverPartition[index], + partName); + } + } + entry.serverNumber[index] = toserver; + entry.serverPartition[index] = topart; } entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS; - MapNetworkToHost(&entry,&storeEntry); - vcode = VLDB_ReplaceEntry(pvolid,voltype, &storeEntry,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP ); - if(vcode) { - fprintf(STDERR,"Could not update the entry for volume number %u \n",pvolid); + MapNetworkToHost(&entry, &storeEntry); + vcode = + VLDB_ReplaceEntry(pvolid, voltype, &storeEntry, + LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, + "Could not update the entry for volume number %lu \n", + (unsigned long)pvolid); error = vcode; goto refail; } islocked = 0; - if(verbose) EnumerateEntry(&entry); - } - - - } - refail: - if (tocall) { - code = rx_EndCall(tocall, rxError); - if (!error) error = code; - } - if(islocked) { - vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, pvolid, voltype, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if(vcode) { - fprintf(STDERR,"Could not release lock on the VLDB entry for the volume %u\n",pvolid); - if(!error) error = vcode; - } - } - if(totid) { - code = AFSVolEndTrans(toconn, totid, &rcode); - if(!code) code = rcode; - if(code) { - fprintf(STDERR,"Could not end transaction on the volume %u \n",pvolid); - if(!error) error = code; - } - } - if(temptid) { - code = AFSVolEndTrans(toconn, temptid, &rcode); - if(!code) code = rcode; - if(code) { - fprintf(STDERR,"Could not end transaction on the volume %u \n",pvolid); - if(!error) error = code; - } - } - if(tempconn) rx_DestroyConnection(tempconn); - if(toconn) rx_DestroyConnection(toconn); - PrintError("",error); - return error; + if (verbose) + EnumerateEntry(&entry); + } + + + } + refail: + if (tocall) { + code = rx_EndCall(tocall, rxError); + if (!error) + error = code; + } + if (islocked) { + vcode = + ubik_Call(VL_ReleaseLock, cstruct, 0, pvolid, voltype, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, + "Could not release lock on the VLDB entry for the volume %lu\n", + (unsigned long)pvolid); + if (!error) + error = vcode; + } + } + if (totid) { + code = AFSVolEndTrans(toconn, totid, &rcode); + if (!code) + code = rcode; + if (code) { + fprintf(STDERR, "Could not end transaction on the volume %lu \n", + (unsigned long)pvolid); + if (!error) + error = code; + } + } + if (temptid) { + code = AFSVolEndTrans(toconn, temptid, &rcode); + if (!code) + code = rcode; + if (code) { + fprintf(STDERR, "Could not end transaction on the volume %lu \n", + (unsigned long)pvolid); + if (!error) + error = code; + } + } + if (tempconn) + rx_DestroyConnection(tempconn); + if (toconn) + rx_DestroyConnection(toconn); + PrintError("", error); + return error; } /*unlocks the vldb entry associated with */ -UV_LockRelease(volid) -afs_int32 volid; +int +UV_LockRelease(afs_int32 volid) { - - + + afs_int32 vcode; - if (verbose) fprintf(STDERR,"Binding to the VLDB server\n"); - vcode = ubik_Call(VL_ReleaseLock,cstruct, 0,volid,-1,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP ); - if(vcode) { - fprintf(STDERR,"Could not unlock the entry for volume number %u in VLDB \n",volid); - PrintError("",vcode); + VPRINT("Binding to the VLDB server\n"); + vcode = + ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, + "Could not unlock the entry for volume number %lu in VLDB \n", + (unsigned long)volid); + PrintError("", vcode); return (vcode); } - if (verbose) fprintf(STDERR,"VLDB updated\n"); + VPRINT("VLDB updated\n"); return 0; } /*adds and as a readonly replication site for *in vldb */ -UV_AddSite(server, part, volid) -afs_int32 server, part, volid; +int +UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid) { - int j, nro=0, islocked=0; - struct nvldbentry entry,storeEntry; - afs_int32 vcode, error=0; + int j, nro = 0, islocked = 0; + struct nvldbentry entry, storeEntry; + afs_int32 vcode, error = 0; char apartName[10]; - error = ubik_Call(VL_SetLock,cstruct, 0,volid,RWVOL, VLOP_ADDSITE); + error = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE); if (error) { - fprintf(STDERR," Could not lock the VLDB entry for the volume %u \n", volid); + fprintf(STDERR, + " Could not lock the VLDB entry for the volume %lu \n", + (unsigned long)volid); goto asfail; } islocked = 1; - error = VLDB_GetEntryByID(volid,RWVOL, &entry); + error = VLDB_GetEntryByID(volid, RWVOL, &entry); if (error) { - fprintf(STDERR,"Could not fetch the VLDB entry for volume number %u \n",volid); + fprintf(STDERR, + "Could not fetch the VLDB entry for volume number %lu \n", + (unsigned long)volid); goto asfail; } - if (!ISNAMEVALID(entry.name)){ - fprintf(STDERR,"Volume name %s is too long, rename before adding site\n", entry.name); + if (!ISNAMEVALID(entry.name)) { + fprintf(STDERR, + "Volume name %s is too long, rename before adding site\n", + entry.name); error = VOLSERBADOP; goto asfail; } MapHostToNetwork(&entry); /* See if it's too many entries */ - if (entry.nServers >= NMAXNSERVERS){ - fprintf(STDERR,"Total number of entries will exceed %u\n", NMAXNSERVERS); - error = VOLSERBADOP; - goto asfail; + if (entry.nServers >= NMAXNSERVERS) { + fprintf(STDERR, "Total number of entries will exceed %u\n", + NMAXNSERVERS); + error = VOLSERBADOP; + goto asfail; } /* See if it's on the same server */ - for (j=0; j < entry.nServers; j++) { - if (entry.serverFlags[j] & ITSROVOL) { - nro++; - if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) { - if (error) { - fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", - server, error); - } else { - MapPartIdIntoName(entry.serverPartition[j], apartName); - fprintf(STDERR,"RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n", apartName); - error = VOLSERBADOP; - } - goto asfail; - } - } + for (j = 0; j < entry.nServers; j++) { + if (entry.serverFlags[j] & ITSROVOL) { + nro++; + if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) { + if (error) { + fprintf(STDERR, + "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", + server, error); + } else { + MapPartIdIntoName(entry.serverPartition[j], apartName); + fprintf(STDERR, + "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n", + apartName); + error = VOLSERBADOP; + } + goto asfail; + } + } } /* See if it's too many RO sites - leave one for the RW */ - if (nro >= NMAXNSERVERS-1){ - fprintf(STDERR,"Total number of sites will exceed %u\n", NMAXNSERVERS-1); - error = VOLSERBADOP; - goto asfail; + if (nro >= NMAXNSERVERS - 1) { + fprintf(STDERR, "Total number of sites will exceed %u\n", + NMAXNSERVERS - 1); + error = VOLSERBADOP; + goto asfail; } - if (verbose) fprintf(STDOUT,"Adding a new site ..."); - fflush(STDOUT); + VPRINT("Adding a new site ..."); entry.serverNumber[entry.nServers] = server; entry.serverPartition[entry.nServers] = part; entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE); entry.nServers++; - - MapNetworkToHost(&entry,&storeEntry); - error = VLDB_ReplaceEntry(volid,RWVOL,&storeEntry,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + + MapNetworkToHost(&entry, &storeEntry); + error = + VLDB_ReplaceEntry(volid, RWVOL, &storeEntry, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); if (error) { - fprintf(STDERR,"Could not update entry for volume %u \n",volid); - goto asfail; + fprintf(STDERR, "Could not update entry for volume %lu \n", + (unsigned long)volid); + goto asfail; } islocked = 0; - if (verbose) fprintf(STDOUT," done\n"); + VDONE; asfail: if (islocked) { - vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if (vcode) { - fprintf(STDERR,"Could not release lock on volume entry for %u \n",volid); - PrintError("", vcode); - } + vcode = + ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, + "Could not release lock on volume entry for %lu \n", + (unsigned long)volid); + PrintError("", vcode); + } } PrintError("", error); @@ -3021,144 +4583,169 @@ afs_int32 server, part, volid; } /*removes as read only site for from the vldb */ -UV_RemoveSite(server, part, volid) -afs_int32 server, part, volid; +int +UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid) { afs_int32 vcode; - struct nvldbentry entry,storeEntry; + struct nvldbentry entry, storeEntry; int islocked; - vcode = ubik_Call(VL_SetLock,cstruct, 0,volid,RWVOL, VLOP_ADDSITE); - if(vcode) { - fprintf(STDERR," Could not lock the VLDB entry for volume %u \n", volid); - PrintError("",vcode); - return(vcode); + vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE); + if (vcode) { + fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n", + (unsigned long)volid); + PrintError("", vcode); + return (vcode); } islocked = 1; - vcode = VLDB_GetEntryByID(volid,RWVOL, &entry); - if(vcode) { - fprintf(STDERR,"Could not fetch the entry for volume number %u from VLDB \n",volid); - PrintError("",vcode); + vcode = VLDB_GetEntryByID(volid, RWVOL, &entry); + if (vcode) { + fprintf(STDERR, + "Could not fetch the entry for volume number %lu from VLDB \n", + (unsigned long)volid); + PrintError("", vcode); return (vcode); } MapHostToNetwork(&entry); - if(!Lp_ROMatch(server, part, &entry)){ + if (!Lp_ROMatch(server, part, &entry)) { /*this site doesnot exist */ - fprintf(STDERR,"This site is not a replication site \n"); - vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if(vcode) { - fprintf(STDERR,"Could not update entry for volume %u \n",volid); - PrintError("",vcode); - ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - return(vcode); + fprintf(STDERR, "This site is not a replication site \n"); + vcode = + ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, "Could not update entry for volume %lu \n", + (unsigned long)volid); + PrintError("", vcode); + ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + return (vcode); } return VOLSERBADOP; - } - else { /*remove the rep site */ + } else { /*remove the rep site */ Lp_SetROValue(&entry, server, part, 0, 0); entry.nServers--; - if((entry.nServers == 1) && (entry.flags & RW_EXISTS)) + if ((entry.nServers == 1) && (entry.flags & RW_EXISTS)) entry.flags &= ~RO_EXISTS; - if(entry.nServers < 1) { /*this is the last ref */ - if(verbose) fprintf(STDOUT,"Deleting the VLDB entry for %u ...",volid); + if (entry.nServers < 1) { /*this is the last ref */ + VPRINT1("Deleting the VLDB entry for %u ...", volid); fflush(STDOUT); - vcode = ubik_Call(VL_DeleteEntry,cstruct, 0,volid, ROVOL); - if(vcode) { - fprintf(STDERR,"Could not delete VLDB entry for volume %u \n",volid); - PrintError("",vcode); - return(vcode); + vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, volid, ROVOL); + if (vcode) { + fprintf(STDERR, + "Could not delete VLDB entry for volume %lu \n", + (unsigned long)volid); + PrintError("", vcode); + return (vcode); } - if (verbose) fprintf(STDOUT," done\n"); + VDONE; } - MapNetworkToHost(&entry,&storeEntry); - fprintf(STDOUT,"Deleting the replication site for volume %u ...",volid); + MapNetworkToHost(&entry, &storeEntry); + fprintf(STDOUT, "Deleting the replication site for volume %lu ...", + (unsigned long)volid); fflush(STDOUT); - vcode = VLDB_ReplaceEntry(volid,RWVOL,&storeEntry,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if(vcode){ - fprintf(STDERR,"Could not release lock on volume entry for %u \n",volid); - PrintError("",vcode); - ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - return(vcode); + vcode = + VLDB_ReplaceEntry(volid, RWVOL, &storeEntry, + LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, + "Could not release lock on volume entry for %lu \n", + (unsigned long)volid); + PrintError("", vcode); + ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + return (vcode); } - if(verbose) fprintf(STDOUT," done\n"); + VDONE; } return 0; } /*sets as read/write site for in the vldb */ -UV_ChangeLocation(server, part, volid) -afs_int32 server, part, volid; +int +UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid) { afs_int32 vcode; - struct nvldbentry entry,storeEntry; + struct nvldbentry entry, storeEntry; int index; - vcode = ubik_Call(VL_SetLock,cstruct, 0,volid,RWVOL, VLOP_ADDSITE); - if(vcode) { - fprintf(STDERR," Could not lock the VLDB entry for volume %u \n", volid); - PrintError("",vcode); - return(vcode); + vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE); + if (vcode) { + fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n", + (unsigned long)volid); + PrintError("", vcode); + return (vcode); } - vcode = VLDB_GetEntryByID(volid,RWVOL, &entry); - if(vcode) { - fprintf(STDERR,"Could not fetch the entry for volume number %u from VLDB \n",volid); - PrintError("",vcode); + vcode = VLDB_GetEntryByID(volid, RWVOL, &entry); + if (vcode) { + fprintf(STDERR, + "Could not fetch the entry for volume number %lu from VLDB \n", + (unsigned long)volid); + PrintError("", vcode); return (vcode); } MapHostToNetwork(&entry); index = Lp_GetRwIndex(&entry); if (index < 0) { /* no RW site exists */ - fprintf(STDERR,"No existing RW site for volume %u", volid); - vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if(vcode) { - fprintf(STDERR,"Could not release lock on entry for volume %u \n",volid); - PrintError("",vcode); - return(vcode); + fprintf(STDERR, "No existing RW site for volume %lu", + (unsigned long)volid); + vcode = + ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, + "Could not release lock on entry for volume %lu \n", + (unsigned long)volid); + PrintError("", vcode); + return (vcode); } return VOLSERBADOP; - } - else { /* change the RW site */ + } else { /* change the RW site */ entry.serverNumber[index] = server; entry.serverPartition[index] = part; - MapNetworkToHost(&entry,&storeEntry); - vcode = VLDB_ReplaceEntry(volid,RWVOL,&storeEntry,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if(vcode){ - fprintf(STDERR,"Could not update entry for volume %u \n",volid); - PrintError("",vcode); - ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - return(vcode); + MapNetworkToHost(&entry, &storeEntry); + vcode = + VLDB_ReplaceEntry(volid, RWVOL, &storeEntry, + LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, "Could not update entry for volume %lu \n", + (unsigned long)volid); + PrintError("", vcode); + ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + return (vcode); } - if(verbose) fprintf(STDOUT," done\n"); + VDONE; } return 0; } /*list all the partitions on */ -UV_ListPartitions(aserver, ptrPartList, cntp) - afs_int32 aserver; - struct partList *ptrPartList; - afs_int32 *cntp; +int +UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList, + afs_int32 * cntp) { struct rx_connection *aconn; struct pIDs partIds; struct partEntries partEnts; - register int i, j=0, code; + register int i, j = 0, code; *cntp = 0; - aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT); + aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); partEnts.partEntries_len = 0; - partEnts.partEntries_val = (afs_int32 *)0; - code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */ - if (code == RXGEN_OPCODE) - { - for(i = 0; i < 26; i++) /* try old interface */ - partIds.partIds[i] = -1; + partEnts.partEntries_val = NULL; + code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */ + if (code == RXGEN_OPCODE) { + for (i = 0; i < 26; i++) /* try old interface */ + partIds.partIds[i] = -1; code = AFSVolListPartitions(aconn, &partIds); if (!code) { - for (i = 0;i < 26; i++) { - if((partIds.partIds[i]) != -1) { + for (i = 0; i < 26; i++) { + if ((partIds.partIds[i]) != -1) { ptrPartList->partId[j] = partIds.partIds[i]; ptrPartList->partFlags[j] = PARTVALID; j++; @@ -3167,36 +4754,37 @@ UV_ListPartitions(aserver, ptrPartList, cntp) } *cntp = j; } - } - else if (!code) - { + } else if (!code) { *cntp = partEnts.partEntries_len; if (*cntp > VOLMAXPARTS) { - fprintf(STDERR,"Warning: number of partitions on the server too high %d (process only %d)\n", + fprintf(STDERR, + "Warning: number of partitions on the server too high %d (process only %d)\n", *cntp, VOLMAXPARTS); *cntp = VOLMAXPARTS; } - for (i = 0;i < *cntp; i++) { + for (i = 0; i < *cntp; i++) { ptrPartList->partId[i] = partEnts.partEntries_val[i]; ptrPartList->partFlags[i] = PARTVALID; } free(partEnts.partEntries_val); } -out: + + /* out: */ if (code) - fprintf(STDERR,"Could not fetch the list of partitions from the server\n"); - PrintError("",code); - if(aconn) rx_DestroyConnection(aconn); + fprintf(STDERR, + "Could not fetch the list of partitions from the server\n"); + PrintError("", code); + if (aconn) + rx_DestroyConnection(aconn); return code; } /*zap the list of volumes specified by volPtrArray (the volCloneId field). This is used by the backup system */ -UV_ZapVolumeClones(aserver,apart,volPtr,arraySize) -afs_int32 aserver, apart; -afs_int32 arraySize; -struct volDescription *volPtr; +int +UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart, + struct volDescription *volPtr, afs_int32 arraySize) { struct rx_connection *aconn; struct volDescription *curPtr; @@ -3207,37 +4795,47 @@ struct volDescription *volPtr; afs_int32 tid; aconn = (struct rx_connection *)0; - aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT); + aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); curPos = 0; - for(curPtr = volPtr; curPos < arraySize; curPtr++) { - if(curPtr->volFlags & CLONEVALID) { + for (curPtr = volPtr; curPos < arraySize; curPtr++) { + if (curPtr->volFlags & CLONEVALID) { curPtr->volFlags &= ~CLONEZAPPED; success = 1; - code = AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline, &tid); - if(code) success = 0; + code = + AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline, + &tid); + if (code) + success = 0; else { code = AFSVolDeleteVolume(aconn, tid); - if(code) success = 0; + if (code) + success = 0; code = AFSVolEndTrans(aconn, tid, &rcode); - if(code || rcode) success = 0; + if (code || rcode) + success = 0; } - if(success) curPtr->volFlags |= CLONEZAPPED; - if(!success) fprintf(STDERR,"Could not zap volume %u\n",curPtr->volCloneId); - if(success && verbose) fprintf(STDOUT,"Clone of %s %u deleted\n", curPtr->volName,curPtr->volCloneId); + if (success) + curPtr->volFlags |= CLONEZAPPED; + if (!success) + fprintf(STDERR, "Could not zap volume %lu\n", + (unsigned long)curPtr->volCloneId); + if (success) + VPRINT2("Clone of %s %u deleted\n", curPtr->volName, + curPtr->volCloneId); curPos++; tid = 0; } } - if(aconn)rx_DestroyConnection(aconn); + if (aconn) + rx_DestroyConnection(aconn); return 0; } /*return a list of clones of the volumes specified by volPtrArray. Used by the backup system */ -UV_GenerateVolumeClones(aserver,apart,volPtr,arraySize) -afs_int32 aserver, apart; -afs_int32 arraySize; -struct volDescription *volPtr; +int +UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart, + struct volDescription *volPtr, afs_int32 arraySize) { struct rx_connection *aconn; struct volDescription *curPtr; @@ -3247,58 +4845,67 @@ struct volDescription *volPtr; afs_int32 tid; int reuseCloneId = 0; afs_int32 curCloneId = 0; - char cloneName[256];/*max vol name */ + char cloneName[256]; /*max vol name */ aconn = (struct rx_connection *)0; - aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT); + aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); curPos = 0; - if((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID)) + if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID)) reuseCloneId = 1; - else { /*get a bunch of id's from vldb */ - code = ubik_Call(VL_GetNewVolumeId,cstruct, 0, arraySize, &curCloneId); - if(code) { - fprintf(STDERR,"Could not get ID's for the clone from VLDB\n"); - PrintError("",code); + else { /*get a bunch of id's from vldb */ + code = + ubik_Call(VL_GetNewVolumeId, cstruct, 0, arraySize, &curCloneId); + if (code) { + fprintf(STDERR, "Could not get ID's for the clone from VLDB\n"); + PrintError("", code); return code; } } - for(curPtr = volPtr; curPos < arraySize; curPtr++) { - if(curPtr->volFlags & ENTRYVALID) { + for (curPtr = volPtr; curPos < arraySize; curPtr++) { + if (curPtr->volFlags & ENTRYVALID) { - curPtr->volFlags |= CLONEVALID; + curPtr->volFlags |= CLONEVALID; /*make a clone of curParentId and record as curPtr->volCloneId */ - code = AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline, &tid); - if(verbose && code) fprintf(STDERR,"Clone for volume %s %u failed \n",curPtr->volName,curPtr->volId); - if(code) { - curPtr->volFlags &= ~CLONEVALID; /*cant clone */ + code = + AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline, + &tid); + if (code) + VPRINT2("Clone for volume %s %u failed \n", curPtr->volName, + curPtr->volId); + if (code) { + curPtr->volFlags &= ~CLONEVALID; /*cant clone */ curPos++; continue; } - if(strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9) ){ + if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) { strcpy(cloneName, curPtr->volName); - strcat(cloneName,"-tmpClone-"); - } - else strcpy(cloneName,"-tmpClone"); - if(reuseCloneId) { + strcat(cloneName, "-tmpClone-"); + } else + strcpy(cloneName, "-tmpClone"); + if (reuseCloneId) { curPtr->volCloneId = curCloneId; curCloneId++; } - code = AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,&(curPtr->volCloneId)); - if(code){ + code = + AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName, + &(curPtr->volCloneId)); + if (code) { curPtr->volFlags &= ~CLONEVALID; curPos++; - fprintf(STDERR,"Could not clone %s due to error %u\n", curPtr->volName,code); - code=AFSVolEndTrans(aconn, tid, &rcode); - if(code) - fprintf(STDERR,"WARNING: could not end transaction\n"); + fprintf(STDERR, "Could not clone %s due to error %lu\n", + curPtr->volName, (unsigned long)code); + code = AFSVolEndTrans(aconn, tid, &rcode); + if (code) + fprintf(STDERR, "WARNING: could not end transaction\n"); continue; } - if(verbose) fprintf(STDOUT,"********** Cloned %s temporary %u\n",cloneName,curPtr->volCloneId); + VPRINT2("********** Cloned %s temporary %u\n", cloneName, + curPtr->volCloneId); code = AFSVolEndTrans(aconn, tid, &rcode); - if(code || rcode) { - curPtr->volFlags &= ~CLONEVALID; + if (code || rcode) { + curPtr->volFlags &= ~CLONEVALID; curPos++; continue; } @@ -3306,42 +4913,42 @@ struct volDescription *volPtr; curPos++; } } - if (aconn) rx_DestroyConnection(aconn); + if (aconn) + rx_DestroyConnection(aconn); return 0; } - + /*list all the volumes on and . If all = 1, then all the * relevant fields of the volume are also returned. This is a heavy weight operation.*/ -UV_ListVolumes(aserver,apart,all,resultPtr,size) -afs_int32 aserver, apart; -int all ; -struct volintInfo **resultPtr; -afs_int32 *size; +int +UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all, + struct volintInfo **resultPtr, afs_int32 * size) { struct rx_connection *aconn; afs_int32 code = 0; volEntries volumeInfo; - + code = 0; *size = 0; - *resultPtr = (volintInfo *)0; - volumeInfo.volEntries_val = (volintInfo *)0;/*this hints the stub to allocate space*/ + *resultPtr = (volintInfo *) 0; + volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */ volumeInfo.volEntries_len = 0; - aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT); + aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); code = AFSVolListVolumes(aconn, apart, all, &volumeInfo); - if(code) { - fprintf(STDERR,"Could not fetch the list of volumes from the server\n"); - } - else{ + if (code) { + fprintf(STDERR, + "Could not fetch the list of volumes from the server\n"); + } else { *resultPtr = volumeInfo.volEntries_val; *size = volumeInfo.volEntries_len; } - if(aconn) rx_DestroyConnection(aconn); - PrintError("",code); - return code; + if (aconn) + rx_DestroyConnection(aconn); + PrintError("", code); + return code; } /*------------------------------------------------------------------------ @@ -3378,18 +4985,14 @@ afs_int32 *size; * As advertised. *------------------------------------------------------------------------*/ -UV_XListVolumes(a_serverID, a_partID, a_all, a_resultPP, a_numEntsInResultP) - afs_int32 a_serverID; - afs_int32 a_partID; - int a_all; - struct volintXInfo **a_resultPP; - afs_int32 *a_numEntsInResultP; - -{ /*UV_XListVolumes*/ - - struct rx_connection *rxConnP; /*Ptr to the Rx connection involved*/ - afs_int32 code; /*Error code to return*/ - volXEntries volumeXInfo; /*Area for returned extended vol info*/ +int +UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all, + struct volintXInfo **a_resultPP, + afs_int32 * a_numEntsInResultP) +{ + struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */ + afs_int32 code; /*Error code to return */ + volXEntries volumeXInfo; /*Area for returned extended vol info */ /* * Set up our error code and the area for returned extended volume info. @@ -3398,8 +5001,8 @@ UV_XListVolumes(a_serverID, a_partID, a_all, a_resultPP, a_numEntsInResultP) */ code = 0; *a_numEntsInResultP = 0; - *a_resultPP = (volintXInfo *)0; - volumeXInfo.volXEntries_val = (volintXInfo *)0; + *a_resultPP = (volintXInfo *) 0; + volumeXInfo.volXEntries_val = (volintXInfo *) 0; volumeXInfo.volXEntries_len = 0; /* @@ -3409,8 +5012,7 @@ UV_XListVolumes(a_serverID, a_partID, a_all, a_resultPP, a_numEntsInResultP) rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT); code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo); if (code) - fprintf(STDERR, - "[UV_XListVolumes] Couldn't fetch volume list\n"); + fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n"); else { /* * We got the info; pull out the pointer to where the results lie @@ -3427,38 +5029,39 @@ UV_XListVolumes(a_serverID, a_partID, a_all, a_resultPP, a_numEntsInResultP) rx_DestroyConnection(rxConnP); PrintError("", code); - return(code); -} /*UV_XListVolumes*/ + return (code); +} /*UV_XListVolumes */ /* get all the information about volume on and */ -UV_ListOneVolume(aserver,apart,volid,resultPtr) -afs_int32 aserver, apart; -afs_int32 volid; -struct volintInfo **resultPtr; +int +UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid, + struct volintInfo **resultPtr) { struct rx_connection *aconn; afs_int32 code = 0; volEntries volumeInfo; - + code = 0; - *resultPtr = (volintInfo *)0; - volumeInfo.volEntries_val = (volintInfo *)0;/*this hints the stub to allocate space*/ + *resultPtr = (volintInfo *) 0; + volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */ volumeInfo.volEntries_len = 0; - aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT); + aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo); - if(code) { - fprintf(STDERR,"Could not fetch the information about volume %u from the server\n",volid); - } - else{ + if (code) { + fprintf(STDERR, + "Could not fetch the information about volume %lu from the server\n", + (unsigned long)volid); + } else { *resultPtr = volumeInfo.volEntries_val; - + } - if(aconn) rx_DestroyConnection(aconn); - PrintError("",code); - return code; + if (aconn) + rx_DestroyConnection(aconn); + PrintError("", code); + return code; } /*------------------------------------------------------------------------ @@ -3489,16 +5092,13 @@ struct volintInfo **resultPtr; * As advertised. *------------------------------------------------------------------------*/ -UV_XListOneVolume(a_serverID, a_partID, a_volID, a_resultPP) - afs_int32 a_serverID; - afs_int32 a_partID; - afs_int32 a_volID; - struct volintXInfo **a_resultPP; - -{ /*UV_XListOneVolume*/ - struct rx_connection *rxConnP; /*Rx connection to Volume Server*/ - afs_int32 code; /*Error code*/ - volXEntries volumeXInfo; /*Area for returned info*/ +int +UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID, + struct volintXInfo **a_resultPP) +{ + struct rx_connection *rxConnP; /*Rx connection to Volume Server */ + afs_int32 code; /*Error code */ + volXEntries volumeXInfo; /*Area for returned info */ /* * Set up our error code, and the area we're in which we are returning @@ -3506,8 +5106,8 @@ UV_XListOneVolume(a_serverID, a_partID, a_volID, a_resultPP) * to allocate space for us. */ code = 0; - *a_resultPP = (volintXInfo *)0; - volumeXInfo.volXEntries_val = (volintXInfo *)0; + *a_resultPP = (volintXInfo *) 0; + volumeXInfo.volXEntries_val = (volintXInfo *) 0; volumeXInfo.volXEntries_len = 0; /* @@ -3516,7 +5116,7 @@ UV_XListOneVolume(a_serverID, a_partID, a_volID, a_resultPP) */ rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT); code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo); - if(code) + if (code) fprintf(STDERR, "[UV_XListOneVolume] Couldn't fetch the volume information\n"); else @@ -3531,9 +5131,9 @@ UV_XListOneVolume(a_serverID, a_partID, a_volID, a_resultPP) if (rxConnP) rx_DestroyConnection(rxConnP); - PrintError("",code); - return code; -} /*UV_XListOneVolume*/ + PrintError("", code); + return code; +} /* CheckVolume() * Given a volume we read from a partition, check if it is @@ -3554,389 +5154,452 @@ UV_XListOneVolume(a_serverID, a_partID, a_volID, a_resultPP) * VLDB entries are locked only when a change needs to be done. * Output changed to look a lot like the "vos syncserv" otuput. */ -static afs_int32 CheckVolume(volumeinfo, aserver, apart, modentry, maxvolid) - volintInfo *volumeinfo; - afs_int32 aserver, apart; - afs_int32 *modentry; - afs_uint32 *maxvolid; -{ - int idx, j; - afs_int32 code, error = 0; - struct nvldbentry entry, storeEntry; - char pname[10]; - int pass=0, islocked=0, createentry, addvolume, modified, mod; - afs_int32 rwvolid; - - if (modentry) *modentry = 0; - rwvolid = ((volumeinfo->type == RWVOL) ? volumeinfo->volid : volumeinfo->parentID); - - retry: - /* Check to see if the VLDB is ok without locking it (pass 1). - * If it will change, then lock the VLDB entry, read it again, - * then make the changes to it (pass 2). - */ - if (++pass == 2) { - code = ubik_Call(VL_SetLock, cstruct, 0, rwvolid, RWVOL, VLOP_DELETE); - if (code) { - fprintf(STDERR, "Could not lock VLDB entry for %u\n", rwvolid); - ERROR_EXIT(code); - } - islocked = 1; - } - - createentry = 0; /* Do we need to create a VLDB entry */ - addvolume = 0; /* Add this volume to the VLDB entry */ - modified = 0; /* The VLDB entry was modified */ - - /* Read the entry from VLDB by its RW volume id */ - code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry); - if (code) { - if (code != VL_NOENT) { - fprintf(STDOUT,"Could not retreive the VLDB entry for volume %u \n", rwvolid); - ERROR_EXIT(code); - } - - memset(&entry, 0, sizeof(entry)); - vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */ - - createentry = 1; - } else { - MapHostToNetwork(&entry); - } - - if (verbose && (pass == 1)) { - fprintf(STDOUT,"_______________________________\n"); - fprintf(STDOUT,"\n-- status before -- \n"); - if (createentry) { - fprintf(STDOUT,"\n**does not exist**\n"); - } else { - if ((entry.flags & RW_EXISTS) || - (entry.flags & RO_EXISTS) || - (entry.flags & BACK_EXISTS)) - EnumerateEntry(&entry); - } - fprintf(STDOUT,"\n"); - } - - if (volumeinfo->type == RWVOL) { /* RW volume exists */ - if (createentry) { - idx = 0; - entry.nServers = 1; - addvolume++; - } else { - /* Check existence of RW and BK volumes */ - code = CheckVldbRWBK(&entry, &mod); - if (code) ERROR_EXIT(code); - if (mod) modified++; - - idx = Lp_GetRwIndex(&entry); - if (idx == -1) { /* RW index not found in the VLDB entry */ - idx = entry.nServers; /* put it into next index */ - entry.nServers++; +static afs_int32 +CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart, + afs_int32 * modentry, afs_uint32 * maxvolid) +{ + int idx, j; + afs_int32 code, error = 0; + struct nvldbentry entry, storeEntry; + char pname[10]; + int pass = 0, islocked = 0, createentry, addvolume, modified, mod; + afs_int32 rwvolid; + + if (modentry) + *modentry = 0; + rwvolid = + ((volumeinfo->type == + RWVOL) ? volumeinfo->volid : volumeinfo->parentID); + + retry: + /* Check to see if the VLDB is ok without locking it (pass 1). + * If it will change, then lock the VLDB entry, read it again, + * then make the changes to it (pass 2). + */ + if (++pass == 2) { + code = ubik_Call(VL_SetLock, cstruct, 0, rwvolid, RWVOL, VLOP_DELETE); + if (code) { + fprintf(STDERR, "Could not lock VLDB entry for %lu\n", + (unsigned long)rwvolid); + ERROR_EXIT(code); + } + islocked = 1; + } + + createentry = 0; /* Do we need to create a VLDB entry */ + addvolume = 0; /* Add this volume to the VLDB entry */ + modified = 0; /* The VLDB entry was modified */ + + /* Read the entry from VLDB by its RW volume id */ + code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry); + if (code) { + if (code != VL_NOENT) { + fprintf(STDOUT, + "Could not retreive the VLDB entry for volume %lu \n", + (unsigned long)rwvolid); + ERROR_EXIT(code); + } + + memset(&entry, 0, sizeof(entry)); + vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */ + + createentry = 1; + } else { + MapHostToNetwork(&entry); + } + + if (verbose && (pass == 1)) { + fprintf(STDOUT, "_______________________________\n"); + fprintf(STDOUT, "\n-- status before -- \n"); + if (createentry) { + fprintf(STDOUT, "\n**does not exist**\n"); + } else { + if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS) + || (entry.flags & BACK_EXISTS)) + EnumerateEntry(&entry); + } + fprintf(STDOUT, "\n"); + } + + if (volumeinfo->type == RWVOL) { /* RW volume exists */ + if (createentry) { + idx = 0; + entry.nServers = 1; addvolume++; - } else { /* RW index found in the VLDB entry. */ - /* Verify if this volume's location matches where the VLDB says it is */ - if (!Lp_Match(aserver, apart, &entry)) { - if (entry.flags & RW_EXISTS) { - /* The RW volume exists elsewhere - report this one a duplicate */ - if (pass == 1) { - MapPartIdIntoName(apart, pname); - fprintf(STDERR,"*** Warning: Orphaned RW volume %u exists on %s %s\n", - rwvolid, hostutil_GetNameByINet(aserver), pname); - MapPartIdIntoName(entry.serverPartition[idx], pname); - fprintf(STDERR," VLDB reports RW volume %u exists on %s %s\n", - rwvolid, - hostutil_GetNameByINet(entry.serverNumber[idx]), pname); - } - } else { - /* The RW volume does not exist - have VLDB point to this one */ - addvolume++; - - /* Check for orphaned BK volume on old partition */ - if (entry.flags & BACK_EXISTS) { - if (pass == 1) { - MapPartIdIntoName(entry.serverPartition[idx], pname); - fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n", - entry.volumeId[BACKVOL], - hostutil_GetNameByINet(entry.serverNumber[idx]), pname); - MapPartIdIntoName(apart, pname); - fprintf(STDERR," VLDB reports its RW volume %u exists on %s %s\n", - rwvolid, hostutil_GetNameByINet(aserver), pname); - } - } - } - } else { - /* Volume location matches the VLDB location */ - if ( (volumeinfo->backupID && !entry.volumeId[BACKVOL]) || - (volumeinfo->cloneID && !entry.volumeId[ROVOL]) || - (strncmp(entry.name,volumeinfo->name,VOLSER_OLDMAXVOLNAME) != 0) ) { - addvolume++; - } + } else { + /* Check existence of RW and BK volumes */ + code = CheckVldbRWBK(&entry, &mod); + if (code) + ERROR_EXIT(code); + if (mod) + modified++; + + idx = Lp_GetRwIndex(&entry); + if (idx == -1) { /* RW index not found in the VLDB entry */ + idx = entry.nServers; /* put it into next index */ + entry.nServers++; + addvolume++; + } else { /* RW index found in the VLDB entry. */ + /* Verify if this volume's location matches where the VLDB says it is */ + if (!Lp_Match(aserver, apart, &entry)) { + if (entry.flags & RW_EXISTS) { + /* The RW volume exists elsewhere - report this one a duplicate */ + if (pass == 1) { + MapPartIdIntoName(apart, pname); + fprintf(STDERR, + "*** Warning: Orphaned RW volume %lu exists on %s %s\n", + (unsigned long)rwvolid, + hostutil_GetNameByINet(aserver), pname); + MapPartIdIntoName(entry.serverPartition[idx], + pname); + fprintf(STDERR, + " VLDB reports RW volume %lu exists on %s %s\n", + (unsigned long)rwvolid, + hostutil_GetNameByINet(entry. + serverNumber[idx]), + pname); + } + } else { + /* The RW volume does not exist - have VLDB point to this one */ + addvolume++; + + /* Check for orphaned BK volume on old partition */ + if (entry.flags & BACK_EXISTS) { + if (pass == 1) { + MapPartIdIntoName(entry.serverPartition[idx], + pname); + fprintf(STDERR, + "*** Warning: Orphaned BK volume %u exists on %s %s\n", + entry.volumeId[BACKVOL], + hostutil_GetNameByINet(entry. + serverNumber + [idx]), pname); + MapPartIdIntoName(apart, pname); + fprintf(STDERR, + " VLDB reports its RW volume %lu exists on %s %s\n", + (unsigned long)rwvolid, + hostutil_GetNameByINet(aserver), + pname); + } + } + } + } else { + /* Volume location matches the VLDB location */ + if ((volumeinfo->backupID && !entry.volumeId[BACKVOL]) + || (volumeinfo->cloneID && !entry.volumeId[ROVOL]) + || + (strncmp + (entry.name, volumeinfo->name, + VOLSER_OLDMAXVOLNAME) != 0)) { + addvolume++; + } + } } - } - } - - if (addvolume) { - entry.flags |= RW_EXISTS; - entry.volumeId[RWVOL] = rwvolid; - if (!entry.volumeId[BACKVOL]) - entry.volumeId[BACKVOL] = volumeinfo->backupID; - if (!entry.volumeId[ROVOL]) - entry.volumeId[ROVOL] = volumeinfo->cloneID; - - entry.serverFlags[idx] = ITSRWVOL; - entry.serverNumber[idx] = aserver; - entry.serverPartition[idx] = apart; - strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME); - - modified++; - - /* One last check - to update BK if need to */ - code = CheckVldbRWBK(&entry, &mod); - if (code) ERROR_EXIT(code); - if (mod) modified++; - } - } - - else if (volumeinfo->type == BACKVOL) { /* A BK volume */ - if (createentry) { - idx = 0; - entry.nServers = 1; - addvolume++; - } else { - /* Check existence of RW and BK volumes */ - code = CheckVldbRWBK(&entry, &mod); - if (code) ERROR_EXIT(code); - if (mod) modified++; - - idx = Lp_GetRwIndex(&entry); - if (idx == -1) { /* RW index not found in the VLDB entry */ - idx = entry.nServers; /* Put it into next index */ - entry.nServers++; + } + + if (addvolume) { + entry.flags |= RW_EXISTS; + entry.volumeId[RWVOL] = rwvolid; + if (!entry.volumeId[BACKVOL]) + entry.volumeId[BACKVOL] = volumeinfo->backupID; + if (!entry.volumeId[ROVOL]) + entry.volumeId[ROVOL] = volumeinfo->cloneID; + + entry.serverFlags[idx] = ITSRWVOL; + entry.serverNumber[idx] = aserver; + entry.serverPartition[idx] = apart; + strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME); + + modified++; + + /* One last check - to update BK if need to */ + code = CheckVldbRWBK(&entry, &mod); + if (code) + ERROR_EXIT(code); + if (mod) + modified++; + } + } + + else if (volumeinfo->type == BACKVOL) { /* A BK volume */ + if (createentry) { + idx = 0; + entry.nServers = 1; addvolume++; - } else { /* RW index found in the VLDB entry */ - /* Verify if this volume's location matches where the VLDB says it is */ - if (!Lp_Match(aserver, apart, &entry)) { - /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */ - if (pass == 1) { - MapPartIdIntoName(apart, pname); - fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n", - volumeinfo->volid, hostutil_GetNameByINet(aserver), pname); - MapPartIdIntoName(entry.serverPartition[idx], pname); - fprintf(STDERR," VLDB reports its RW/BK volume %u exists on %s %s\n", - rwvolid, - hostutil_GetNameByINet(entry.serverNumber[idx]), pname); - } - } else { - if (volumeinfo->volid != entry.volumeId[BACKVOL]) { - if (!(entry.flags & BACK_EXISTS)) { - addvolume++; - } - else if (volumeinfo->volid > entry.volumeId[BACKVOL]) { - addvolume++; - - if (pass == 1) { - MapPartIdIntoName(entry.serverPartition[idx], pname); - fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n", - entry.volumeId[BACKVOL], hostutil_GetNameByINet(aserver), pname); - fprintf(STDERR," VLDB reports its BK volume ID is %u\n", - volumeinfo->volid); - } - } else { - if (pass == 1) { + } else { + /* Check existence of RW and BK volumes */ + code = CheckVldbRWBK(&entry, &mod); + if (code) + ERROR_EXIT(code); + if (mod) + modified++; + + idx = Lp_GetRwIndex(&entry); + if (idx == -1) { /* RW index not found in the VLDB entry */ + idx = entry.nServers; /* Put it into next index */ + entry.nServers++; + addvolume++; + } else { /* RW index found in the VLDB entry */ + /* Verify if this volume's location matches where the VLDB says it is */ + if (!Lp_Match(aserver, apart, &entry)) { + /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */ + if (pass == 1) { + MapPartIdIntoName(apart, pname); + fprintf(STDERR, + "*** Warning: Orphaned BK volume %lu exists on %s %s\n", + (unsigned long)volumeinfo->volid, + hostutil_GetNameByINet(aserver), pname); MapPartIdIntoName(entry.serverPartition[idx], pname); - fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n", - volumeinfo->volid, hostutil_GetNameByINet(aserver), pname); - fprintf(STDERR," VLDB reports its BK volume ID is %u\n", - entry.volumeId[BACKVOL]); - } - } - } - else if (!entry.volumeId[BACKVOL]) { - addvolume++; - } - } - } - } - if (addvolume) { - entry.flags |= BACK_EXISTS; - entry.volumeId[RWVOL] = rwvolid; - entry.volumeId[BACKVOL] = volumeinfo->volid; - - entry.serverNumber[idx] = aserver; - entry.serverPartition[idx] = apart; - entry.serverFlags[idx] = ITSRWVOL; - - modified++; - } - } - - else if (volumeinfo->type == ROVOL) { /* A RO volume */ - if (volumeinfo->volid == entry.volumeId[ROVOL]) { - /* This is a quick check to see if the RO entry exists in the - * VLDB so we avoid the CheckVldbRO() call (which checks if each - * RO volume listed in the VLDB exists). - */ - idx = Lp_ROMatch(aserver, apart, &entry) - 1; - if (idx == -1) { - idx = entry.nServers; - entry.nServers++; - addvolume++; - } else { - if (!(entry.flags & RO_EXISTS)) { - addvolume++; + fprintf(STDERR, + " VLDB reports its RW/BK volume %lu exists on %s %s\n", + (unsigned long)rwvolid, + hostutil_GetNameByINet(entry. + serverNumber[idx]), + pname); + } + } else { + if (volumeinfo->volid != entry.volumeId[BACKVOL]) { + if (!(entry.flags & BACK_EXISTS)) { + addvolume++; + } else if (volumeinfo->volid > + entry.volumeId[BACKVOL]) { + addvolume++; + + if (pass == 1) { + MapPartIdIntoName(entry.serverPartition[idx], + pname); + fprintf(STDERR, + "*** Warning: Orphaned BK volume %u exists on %s %s\n", + entry.volumeId[BACKVOL], + hostutil_GetNameByINet(aserver), + pname); + fprintf(STDERR, + " VLDB reports its BK volume ID is %lu\n", + (unsigned long)volumeinfo->volid); + } + } else { + if (pass == 1) { + MapPartIdIntoName(entry.serverPartition[idx], + pname); + fprintf(STDERR, + "*** Warning: Orphaned BK volume %lu exists on %s %s\n", + (unsigned long)volumeinfo->volid, + hostutil_GetNameByINet(aserver), + pname); + fprintf(STDERR, + " VLDB reports its BK volume ID is %u\n", + entry.volumeId[BACKVOL]); + } + } + } else if (!entry.volumeId[BACKVOL]) { + addvolume++; + } + } } - } - } else { - /* Before we correct the VLDB entry, make sure all the - * ROs listed in the VLDB exist. - */ - code = CheckVldbRO(&entry, &mod); - if (code) ERROR_EXIT(code); - if (mod) modified++; - - if (!(entry.flags & RO_EXISTS)) { - /* No RO exists in the VLDB entry - add this one */ - idx = entry.nServers; - entry.nServers++; - addvolume++; - } - else if (volumeinfo->volid > entry.volumeId[ROVOL]) { - /* The volume headers's RO ID does not match that in the VLDB entry, - * and the vol hdr's ID is greater (implies more recent). So delete - * all the RO volumes listed in VLDB entry and add this volume. + } + if (addvolume) { + entry.flags |= BACK_EXISTS; + entry.volumeId[RWVOL] = rwvolid; + entry.volumeId[BACKVOL] = volumeinfo->volid; + + entry.serverNumber[idx] = aserver; + entry.serverPartition[idx] = apart; + entry.serverFlags[idx] = ITSRWVOL; + + modified++; + } + } + + else if (volumeinfo->type == ROVOL) { /* A RO volume */ + if (volumeinfo->volid == entry.volumeId[ROVOL]) { + /* This is a quick check to see if the RO entry exists in the + * VLDB so we avoid the CheckVldbRO() call (which checks if each + * RO volume listed in the VLDB exists). */ - for (j=0; jvolid); - } - - Lp_SetRWValue(entry, entry.serverNumber[idx], - entry.serverPartition[idx], 0L, 0L); - entry.nServers--; - modified++; - j--; - } + idx = Lp_ROMatch(aserver, apart, &entry) - 1; + if (idx == -1) { + idx = entry.nServers; + entry.nServers++; + addvolume++; + } else { + if (!(entry.flags & RO_EXISTS)) { + addvolume++; + } } - - idx = entry.nServers; - entry.nServers++; - addvolume++; - } - else if (volumeinfo->volid < entry.volumeId[ROVOL]) { - /* The volume headers's RO ID does not match that in the VLDB entry, - * and the vol hdr's ID is lower (implies its older). So orphan it. + } else { + /* Before we correct the VLDB entry, make sure all the + * ROs listed in the VLDB exist. */ - if (pass == 1) { - MapPartIdIntoName(apart, pname); - fprintf(STDERR,"*** Warning: Orphaned RO volume %u exists on %s %s\n", - volumeinfo->volid, hostutil_GetNameByINet(aserver), pname); - fprintf(STDERR," VLDB reports its RO volume ID is %u\n", - entry.volumeId[ROVOL]); - } - } - else { - /* The RO volume ID in the volume header match that in the VLDB entry, - * and there exist RO volumes in the VLDB entry. See if any of them - * are this one. If not, then we add it. - */ - idx = Lp_ROMatch(aserver, apart, &entry) - 1; - if (idx == -1) { - idx = entry.nServers; - entry.nServers++; - addvolume++; + code = CheckVldbRO(&entry, &mod); + if (code) + ERROR_EXIT(code); + if (mod) + modified++; + + if (!(entry.flags & RO_EXISTS)) { + /* No RO exists in the VLDB entry - add this one */ + idx = entry.nServers; + entry.nServers++; + addvolume++; + } else if (volumeinfo->volid > entry.volumeId[ROVOL]) { + /* The volume headers's RO ID does not match that in the VLDB entry, + * and the vol hdr's ID is greater (implies more recent). So delete + * all the RO volumes listed in VLDB entry and add this volume. + */ + for (j = 0; j < entry.nServers; j++) { + if (entry.serverFlags[j] & ITSROVOL) { + /* Verify this volume exists and print message we are orphaning it */ + if (pass == 1) { + MapPartIdIntoName(apart, pname); + fprintf(STDERR, + "*** Warning: Orphaned RO volume %u exists on %s %s\n", + entry.volumeId[ROVOL], + hostutil_GetNameByINet(entry. + serverNumber[j]), + pname); + fprintf(STDERR, + " VLDB reports its RO volume ID is %lu\n", + (unsigned long)volumeinfo->volid); + } + + Lp_SetRWValue(entry, entry.serverNumber[idx], + entry.serverPartition[idx], 0L, 0L); + entry.nServers--; + modified++; + j--; + } + } + + idx = entry.nServers; + entry.nServers++; + addvolume++; + } else if (volumeinfo->volid < entry.volumeId[ROVOL]) { + /* The volume headers's RO ID does not match that in the VLDB entry, + * and the vol hdr's ID is lower (implies its older). So orphan it. + */ + if (pass == 1) { + MapPartIdIntoName(apart, pname); + fprintf(STDERR, + "*** Warning: Orphaned RO volume %lu exists on %s %s\n", + (unsigned long)volumeinfo->volid, + hostutil_GetNameByINet(aserver), pname); + fprintf(STDERR, + " VLDB reports its RO volume ID is %u\n", + entry.volumeId[ROVOL]); + } + } else { + /* The RO volume ID in the volume header match that in the VLDB entry, + * and there exist RO volumes in the VLDB entry. See if any of them + * are this one. If not, then we add it. + */ + idx = Lp_ROMatch(aserver, apart, &entry) - 1; + if (idx == -1) { + idx = entry.nServers; + entry.nServers++; + addvolume++; + } } - } - } - - if (addvolume) { - entry.flags |= RO_EXISTS; - entry.volumeId[RWVOL] = rwvolid; - entry.volumeId[ROVOL] = volumeinfo->volid; - - entry.serverNumber[idx] = aserver; - entry.serverPartition[idx] = apart; - entry.serverFlags[idx] = ITSROVOL; - - modified++; - } - } - - /* Remember largest volume id */ - if (entry.volumeId[ROVOL] > *maxvolid) *maxvolid = entry.volumeId[ROVOL]; - if (entry.volumeId[BACKVOL] > *maxvolid) *maxvolid = entry.volumeId[BACKVOL]; - if (entry.volumeId[RWVOL] > *maxvolid) *maxvolid = entry.volumeId[RWVOL]; - - if (modified) { - MapNetworkToHost(&entry, &storeEntry); - - if (createentry) { - code = VLDB_CreateEntry(&storeEntry); - if (code) { - fprintf(STDOUT,"Could not create a VLDB entry for the volume %u\n", rwvolid); - ERROR_EXIT(code); - } - } - else { - if (pass == 1) goto retry; - code = VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry, - LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if (code) { - fprintf(STDERR,"Could not update entry for %u\n", rwvolid); - ERROR_EXIT(code); - } - } - if (modentry) *modentry = modified; - } else if (pass == 2) { - code = ubik_Call(VL_ReleaseLock,cstruct, 0, rwvolid, RWVOL, - LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if (code) { - PrintError("Could not unlock VLDB entry ", code); - } - } - - if (verbose) { - fprintf(STDOUT,"-- status after --\n"); - if (modified) - EnumerateEntry(&entry); - else - fprintf(STDOUT,"\n**no change**\n"); - } - - error_exit: - if (verbose) { - fprintf(STDOUT,"\n_______________________________\n"); - } - return(error); -} + } -int sortVolumes(v1, v2) - volintInfo *v1, *v2; -{ - afs_int32 rwvolid1, rwvolid2; + if (addvolume) { + entry.flags |= RO_EXISTS; + entry.volumeId[RWVOL] = rwvolid; + entry.volumeId[ROVOL] = volumeinfo->volid; + + entry.serverNumber[idx] = aserver; + entry.serverPartition[idx] = apart; + entry.serverFlags[idx] = ITSROVOL; + + modified++; + } + } - rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID); - rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID); + /* Remember largest volume id */ + if (entry.volumeId[ROVOL] > *maxvolid) + *maxvolid = entry.volumeId[ROVOL]; + if (entry.volumeId[BACKVOL] > *maxvolid) + *maxvolid = entry.volumeId[BACKVOL]; + if (entry.volumeId[RWVOL] > *maxvolid) + *maxvolid = entry.volumeId[RWVOL]; - if (rwvolid1 > rwvolid2) return -1; /* lower RW id goes first */ - if (rwvolid1 < rwvolid2) return 1; + if (modified) { + MapNetworkToHost(&entry, &storeEntry); + + if (createentry) { + code = VLDB_CreateEntry(&storeEntry); + if (code) { + fprintf(STDOUT, + "Could not create a VLDB entry for the volume %lu\n", + (unsigned long)rwvolid); + ERROR_EXIT(code); + } + } else { + if (pass == 1) + goto retry; + code = + VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry, + LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP); + if (code) { + fprintf(STDERR, "Could not update entry for %lu\n", + (unsigned long)rwvolid); + ERROR_EXIT(code); + } + } + if (modentry) + *modentry = modified; + } else if (pass == 2) { + code = + ubik_Call(VL_ReleaseLock, cstruct, 0, rwvolid, RWVOL, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + if (code) { + PrintError("Could not unlock VLDB entry ", code); + } + } - if (v1->type == RWVOL) return -1; /* RW vols go first */ - if (v2->type == RWVOL) return 1; + if (verbose) { + fprintf(STDOUT, "-- status after --\n"); + if (modified) + EnumerateEntry(&entry); + else + fprintf(STDOUT, "\n**no change**\n"); + } - if ((v1->type == BACKVOL) && (v2->type == ROVOL )) return -1; /* BK vols next */ - if ((v1->type == ROVOL ) && (v2->type == BACKVOL)) return 1; + error_exit: + VPRINT("\n_______________________________\n"); + return (error); +} - if (v1->volid < v2->volid) return 1; /* larger volids first */ - if (v1->volid > v2->volid) return -1; - return 0; +int +sortVolumes(const void *a, const void *b) +{ + volintInfo *v1 = (volintInfo *) a; + volintInfo *v2 = (volintInfo *) b; + afs_int32 rwvolid1, rwvolid2; + + rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID); + rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID); + + if (rwvolid1 > rwvolid2) + return -1; /* lower RW id goes first */ + if (rwvolid1 < rwvolid2) + return 1; + + if (v1->type == RWVOL) + return -1; /* RW vols go first */ + if (v2->type == RWVOL) + return 1; + + if ((v1->type == BACKVOL) && (v2->type == ROVOL)) + return -1; /* BK vols next */ + if ((v1->type == ROVOL) && (v2->type == BACKVOL)) + return 1; + + if (v1->volid < v2->volid) + return 1; /* larger volids first */ + if (v1->volid > v2->volid) + return -1; + return 0; } /* UV_SyncVolume() @@ -3945,10 +5608,8 @@ int sortVolumes(v1, v2) * Checks the VLDB entry (similar to syncserv) as well as checks * if the volume exists on specified servers (similar to syncvldb). */ -UV_SyncVolume(aserver, apart, avolname, flags) - afs_int32 aserver, apart; - char *avolname; - int flags; +int +UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags) { struct rx_connection *aconn = 0; afs_int32 j, k, code, vcode, error = 0; @@ -3960,40 +5621,40 @@ UV_SyncVolume(aserver, apart, avolname, flags) afs_int32 pcnt, rv; afs_int32 maxvolid = 0; - volumeInfo.volEntries_val = (volintInfo *)0; + volumeInfo.volEntries_val = (volintInfo *) 0; volumeInfo.volEntries_len = 0; if (!aserver && flags) { - /* fprintf(STDERR,"Partition option requires a server option\n"); */ - ERROR_EXIT(EINVAL); + /* fprintf(STDERR,"Partition option requires a server option\n"); */ + ERROR_EXIT(EINVAL); } /* Turn verbose logging off and do our own verbose logging */ tverbose = verbose; - verbose = 0; + verbose = 0; /* Read the VLDB entry */ vcode = VLDB_GetEntryByName(avolname, &vldbentry); if (vcode && (vcode != VL_NOENT)) { - fprintf(STDERR,"Could not access the VLDB for volume %s\n", avolname); - ERROR_EXIT(vcode); + fprintf(STDERR, "Could not access the VLDB for volume %s\n", + avolname); + ERROR_EXIT(vcode); } else if (!vcode) { - MapHostToNetwork(&vldbentry); + MapHostToNetwork(&vldbentry); } if (tverbose) { - fprintf(STDOUT,"Processing VLDB entry %s ...\n", avolname); - fprintf(STDOUT,"_______________________________\n"); - fprintf(STDOUT,"\n-- status before -- \n"); - if (vcode) { - fprintf(STDOUT,"\n**does not exist**\n"); - } else { - if ((vldbentry.flags & RW_EXISTS) || - (vldbentry.flags & RO_EXISTS) || - (vldbentry.flags & BACK_EXISTS)) - EnumerateEntry(&vldbentry); - } - fprintf(STDOUT,"\n"); + fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname); + fprintf(STDOUT, "_______________________________\n"); + fprintf(STDOUT, "\n-- status before -- \n"); + if (vcode) { + fprintf(STDOUT, "\n**does not exist**\n"); + } else { + if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS) + || (vldbentry.flags & BACK_EXISTS)) + EnumerateEntry(&vldbentry); + } + fprintf(STDOUT, "\n"); } /* Verify that all of the VLDB entries exist on the repective servers @@ -4001,143 +5662,169 @@ UV_SyncVolume(aserver, apart, avolname, flags) * Equivalent to a syncserv. */ if (!vcode) { - code = CheckVldb(&vldbentry, &mod); - if (code) { - fprintf(STDERR,"Could not process VLDB entry for volume %s\n", vldbentry.name); - ERROR_EXIT(code); - } - if (mod) modified++; + code = CheckVldb(&vldbentry, &mod); + if (code) { + fprintf(STDERR, "Could not process VLDB entry for volume %s\n", + vldbentry.name); + ERROR_EXIT(code); + } + if (mod) + modified++; } /* If aserver is given, we will search for the desired volume on it */ if (aserver) { - /* Generate array of partitions on the server that we will check */ - if (!flags) { - code = UV_ListPartitions(aserver, &PartList, &pcnt); - if (code) { - fprintf(STDERR,"Could not fetch the list of partitions from the server\n"); - ERROR_EXIT(code); - } - } else { - PartList.partId[0] = apart; - pcnt = 1; - } - - aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT); - - /* If a volume ID were given, search for it on each partition */ - if (volumeid = atol(avolname)) { - for (j=0; j maxvldbid) { - afs_uint32 id, nid; - id = maxvolid - maxvldbid + 1; - code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid); - if (code) { - fprintf(STDERR,"Error in increasing highest allocated volume id in VLDB\n"); - if (!error) error = code; - } - } + afs_int32 maxvldbid = 0; + code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid); + if (code) { + fprintf(STDERR, + "Could not get the highest allocated volume id from the VLDB\n"); + if (!error) + error = code; + } else if (maxvolid > maxvldbid) { + afs_uint32 id, nid; + id = maxvolid - maxvldbid + 1; + code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid); + if (code) { + fprintf(STDERR, + "Error in increasing highest allocated volume id in VLDB\n"); + if (!error) + error = code; + } + } } verbose = tverbose; if (verbose) { - if (error) fprintf(STDOUT,"...error encountered"); - else fprintf(STDOUT,"...done entry\n"); + if (error) + fprintf(STDOUT, "...error encountered"); + else + fprintf(STDOUT, "...done entry\n"); } - if (aconn) rx_DestroyConnection(aconn); - if (volumeInfo.volEntries_val) free(volumeInfo.volEntries_val); + if (aconn) + rx_DestroyConnection(aconn); + if (volumeInfo.volEntries_val) + free(volumeInfo.volEntries_val); - PrintError("",error); + PrintError("", error); return error; } @@ -4145,12 +5832,11 @@ UV_SyncVolume(aserver, apart, avolname, flags) * Synchronise vldb with the file server and, * optionally, . */ -UV_SyncVldb(aserver, apart, flags, force) - afs_int32 aserver, apart; - int flags, force; +int +UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force) { struct rx_connection *aconn; - afs_int32 code, error=0; + afs_int32 code, error = 0; int i, j, pfail; volEntries volumeInfo; struct partList PartList; @@ -4161,118 +5847,122 @@ UV_SyncVldb(aserver, apart, flags, force) afs_int32 modified; afs_uint32 maxvolid = 0; - volumeInfo.volEntries_val = (volintInfo *)0; + volumeInfo.volEntries_val = (volintInfo *) 0; volumeInfo.volEntries_len = 0; aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); /* Generate array of partitions to check */ if (!flags) { - code = UV_ListPartitions(aserver, &PartList, &pcnt); - if (code) { - fprintf(STDERR,"Could not fetch the list of partitions from the server\n"); - ERROR_EXIT(code); - } + code = UV_ListPartitions(aserver, &PartList, &pcnt); + if (code) { + fprintf(STDERR, + "Could not fetch the list of partitions from the server\n"); + ERROR_EXIT(code); + } } else { - PartList.partId[0] = apart; - pcnt = 1; + PartList.partId[0] = apart; + pcnt = 1; } - if (verbose) { - fprintf(STDOUT,"Processing volume entries ...\n"); - fflush(STDOUT); - } + VPRINT("Processing volume entries ...\n"); /* Step through the array of partitions */ for (i = 0; i < pcnt; i++) { - apart = PartList.partId[i]; - MapPartIdIntoName(apart, pname); - - volumeInfo.volEntries_val = (volintInfo *)0; - volumeInfo.volEntries_len = 0; - code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo); - if (code) { - fprintf(STDERR,"Could not fetch the list of volumes from the server\n"); - ERROR_EXIT(code); - } - - /* May want to sort the entries: RW, BK (high to low), RO (high to low) */ - qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len, - sizeof(volintInfo), sortVolumes); - - pfail = 0; - for (vi=volumeInfo.volEntries_val, j=0; j < volumeInfo.volEntries_len; j++, vi++) { - if (!vi->status) - continue; - - tentries++; - - if (verbose) { - fprintf(STDOUT,"Processing volume entry %d: %s (%u) on server %s %s...\n", - j+1, vi->name, vi->volid, - hostutil_GetNameByINet(aserver), pname); - fflush(STDOUT); - } - - code = CheckVolume(vi, aserver, apart, &modified, &maxvolid); - if (code) { - PrintError("",code); - failures++; - pfail++; - } - else if (modified) { - modifications++; - } - - if (verbose) { - if (code) { - fprintf(STDOUT,"...error encountered\n\n"); - } else { - fprintf(STDOUT,"...done entry %d\n\n", j+1); - } - } - } - - if (pfail) { - fprintf(STDERR,"Could not process entries on server %s partition %s\n", - hostutil_GetNameByINet(aserver), pname); - } - if (volumeInfo.volEntries_val) { - free(volumeInfo.volEntries_val); - volumeInfo.volEntries_val = 0; - } - - }/* thru all partitions */ + apart = PartList.partId[i]; + MapPartIdIntoName(apart, pname); - if (verbose) { - fprintf(STDOUT, "Total entries: %u, Failed to process %d, Changed %d\n", - tentries, failures, modifications); - } + volumeInfo.volEntries_val = (volintInfo *) 0; + volumeInfo.volEntries_len = 0; + code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo); + if (code) { + fprintf(STDERR, + "Could not fetch the list of volumes from the server\n"); + ERROR_EXIT(code); + } + + /* May want to sort the entries: RW, BK (high to low), RO (high to low) */ + qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len, + sizeof(volintInfo), sortVolumes); + + pfail = 0; + for (vi = volumeInfo.volEntries_val, j = 0; + j < volumeInfo.volEntries_len; j++, vi++) { + if (!vi->status) + continue; + + tentries++; + + if (verbose) { + fprintf(STDOUT, + "Processing volume entry %d: %s (%lu) on server %s %s...\n", + j + 1, vi->name, (unsigned long)vi->volid, + hostutil_GetNameByINet(aserver), pname); + fflush(STDOUT); + } + + code = CheckVolume(vi, aserver, apart, &modified, &maxvolid); + if (code) { + PrintError("", code); + failures++; + pfail++; + } else if (modified) { + modifications++; + } + + if (verbose) { + if (code) { + fprintf(STDOUT, "...error encountered\n\n"); + } else { + fprintf(STDOUT, "...done entry %d\n\n", j + 1); + } + } + } + + if (pfail) { + fprintf(STDERR, + "Could not process entries on server %s partition %s\n", + hostutil_GetNameByINet(aserver), pname); + } + if (volumeInfo.volEntries_val) { + free(volumeInfo.volEntries_val); + volumeInfo.volEntries_val = 0; + } + + } /* thru all partitions */ + + VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries, + failures, modifications); error_exit: /* Now check if the maxvolid is larger than that stored in the VLDB */ if (maxvolid) { - afs_uint32 maxvldbid = 0; - code = ubik_Call(VL_GetNewVolumeId,cstruct, 0, 0, &maxvldbid); - if (code) { - fprintf(STDERR, "Could not get the highest allocated volume id from the VLDB\n"); - if (!error) error = code; - } else if (maxvolid > maxvldbid) { - afs_uint32 id, nid; - id = maxvolid - maxvldbid + 1; - code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid); - if (code) { - fprintf(STDERR,"Error in increasing highest allocated volume id in VLDB\n"); - if (!error) error = code; - } - } - } - - if (aconn) rx_DestroyConnection(aconn); + afs_uint32 maxvldbid = 0; + code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid); + if (code) { + fprintf(STDERR, + "Could not get the highest allocated volume id from the VLDB\n"); + if (!error) + error = code; + } else if (maxvolid > maxvldbid) { + afs_uint32 id, nid; + id = maxvolid - maxvldbid + 1; + code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid); + if (code) { + fprintf(STDERR, + "Error in increasing highest allocated volume id in VLDB\n"); + if (!error) + error = code; + } + } + } + + if (aconn) + rx_DestroyConnection(aconn); if (volumeInfo.volEntries_val) - free(volumeInfo.volEntries_val); - PrintError("",error); - return(error); + free(volumeInfo.volEntries_val); + PrintError("", error); + return (error); } /* VolumeExists() @@ -4282,409 +5972,418 @@ UV_SyncVldb(aserver, apart, flags, force) * Some error codes mean the volume is unavailable but * still exists - so we catch these error codes. */ -afs_int32 VolumeExists(server, partition, volumeid) - afs_int32 server, partition, volumeid; +afs_int32 +VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid) { - struct rx_connection *conn=(struct rx_connection *)0; - afs_int32 code = -1; - volEntries volumeInfo; - - conn = UV_Bind(server, AFSCONF_VOLUMEPORT); - if (conn) { - volumeInfo.volEntries_val = (volintInfo *)0; - volumeInfo.volEntries_len = 0; - code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo); - if (volumeInfo.volEntries_val) - free(volumeInfo.volEntries_val); - if (code == VOLSERILLEGAL_PARTITION) - code = ENODEV; - rx_DestroyConnection(conn); - } - return code; + struct rx_connection *conn = (struct rx_connection *)0; + afs_int32 code = -1; + volEntries volumeInfo; + + conn = UV_Bind(server, AFSCONF_VOLUMEPORT); + if (conn) { + volumeInfo.volEntries_val = (volintInfo *) 0; + volumeInfo.volEntries_len = 0; + code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo); + if (volumeInfo.volEntries_val) + free(volumeInfo.volEntries_val); + if (code == VOLSERILLEGAL_PARTITION) + code = ENODEV; + rx_DestroyConnection(conn); + } + return code; } /* CheckVldbRWBK() * */ -afs_int32 CheckVldbRWBK(entry, modified) - struct nvldbentry *entry; - afs_int32 *modified; +afs_int32 +CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified) { - int modentry = 0; - int idx; - afs_int32 code, error = 0; - char pname[10]; - - if (modified) *modified = 0; - idx = Lp_GetRwIndex(entry); - - /* Check to see if the RW volume exists and set the RW_EXISTS - * flag accordingly. - */ - if (idx == -1) { /* Did not find a RW entry */ - if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */ - entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */ - modentry++; - } - } else { - code = VolumeExists(entry->serverNumber[idx], - entry->serverPartition[idx], - entry->volumeId[RWVOL]); - if (code == 0) { /* RW volume exists */ - if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */ - entry->flags |= RW_EXISTS; /* ... so say RW does exist */ + int modentry = 0; + int idx; + afs_int32 code, error = 0; + char pname[10]; + + if (modified) + *modified = 0; + idx = Lp_GetRwIndex(entry); + + /* Check to see if the RW volume exists and set the RW_EXISTS + * flag accordingly. + */ + if (idx == -1) { /* Did not find a RW entry */ + if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */ + entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */ + modentry++; + } + } else { + code = + VolumeExists(entry->serverNumber[idx], + entry->serverPartition[idx], entry->volumeId[RWVOL]); + if (code == 0) { /* RW volume exists */ + if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */ + entry->flags |= RW_EXISTS; /* ... so say RW does exist */ + modentry++; + } + } else if (code == ENODEV) { /* RW volume does not exist */ + if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */ + entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */ + modentry++; + } + } else { + /* If VLDB says it didn't exist, then ignore error */ + if (entry->flags & RW_EXISTS) { + MapPartIdIntoName(entry->serverPartition[idx], pname); + fprintf(STDERR, + "Transaction call failed for RW volume %u on server %s %s\n", + entry->volumeId[RWVOL], + hostutil_GetNameByINet(entry->serverNumber[idx]), + pname); + ERROR_EXIT(code); + } + } + } + + /* Check to see if the BK volume exists and set the BACK_EXISTS + * flag accordingly. idx already ponts to the RW entry. + */ + if (idx == -1) { /* Did not find a RW entry */ + if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */ + entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */ modentry++; - } - } - else if (code == ENODEV) { /* RW volume does not exist */ - if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */ - entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */ + } + } else { /* Found a RW entry */ + code = + VolumeExists(entry->serverNumber[idx], + entry->serverPartition[idx], + entry->volumeId[BACKVOL]); + if (code == 0) { /* BK volume exists */ + if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */ + entry->flags |= BACK_EXISTS; /* ... so say BK does exist */ + modentry++; + } + } else if (code == ENODEV) { /* BK volume does not exist */ + if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */ + entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */ + modentry++; + } + } else { + /* If VLDB says it didn't exist, then ignore error */ + if (entry->flags & BACK_EXISTS) { + MapPartIdIntoName(entry->serverPartition[idx], pname); + fprintf(STDERR, + "Transaction call failed for BK volume %u on server %s %s\n", + entry->volumeId[BACKVOL], + hostutil_GetNameByINet(entry->serverNumber[idx]), + pname); + ERROR_EXIT(code); + } + } + } + + /* If there is an idx but the BK and RW volumes no + * longer exist, then remove the RW entry. + */ + if ((idx != -1) && !(entry->flags & RW_EXISTS) + && !(entry->flags & BACK_EXISTS)) { + Lp_SetRWValue(entry, entry->serverNumber[idx], + entry->serverPartition[idx], 0L, 0L); + entry->nServers--; + modentry++; + } + + error_exit: + if (modified) + *modified = modentry; + return (error); +} + +int +CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified) +{ + int idx; + int foundro = 0, modentry = 0; + afs_int32 code, error = 0; + char pname[10]; + + if (modified) + *modified = 0; + + /* Check to see if the RO volumes exist and set the RO_EXISTS + * flag accordingly. + */ + for (idx = 0; idx < entry->nServers; idx++) { + if (!(entry->serverFlags[idx] & ITSROVOL)) { + continue; /* not a RO */ + } + + code = + VolumeExists(entry->serverNumber[idx], + entry->serverPartition[idx], entry->volumeId[ROVOL]); + if (code == 0) { /* RO volume exists */ + foundro++; + } else if (code == ENODEV) { /* RW volume does not exist */ + Lp_SetROValue(entry, entry->serverNumber[idx], + entry->serverPartition[idx], 0L, 0L); + entry->nServers--; + idx--; modentry++; - } - } - else { - /* If VLDB says it didn't exist, then ignore error */ - if (entry->flags & RW_EXISTS) { + } else { MapPartIdIntoName(entry->serverPartition[idx], pname); - fprintf(STDERR,"Transaction call failed for RW volume %u on server %s %s\n", - entry->volumeId[RWVOL], + fprintf(STDERR, + "Transaction call failed for RO %u on server %s %s\n", + entry->volumeId[ROVOL], hostutil_GetNameByINet(entry->serverNumber[idx]), pname); ERROR_EXIT(code); - } - } - } - - /* Check to see if the BK volume exists and set the BACK_EXISTS - * flag accordingly. idx already ponts to the RW entry. - */ - if (idx == -1) { /* Did not find a RW entry */ - if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */ - entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */ - modentry++; - } - } - else { /* Found a RW entry */ - code = VolumeExists(entry->serverNumber[idx], - entry->serverPartition[idx], - entry->volumeId[BACKVOL]); - if (code == 0) { /* BK volume exists */ - if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */ - entry->flags |= BACK_EXISTS; /* ... so say BK does exist */ + } + } + + if (foundro) { /* A RO volume exists */ + if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */ + entry->flags |= RO_EXISTS; /* ... so say RW does exist */ modentry++; - } - } - else if (code == ENODEV) { /* BK volume does not exist */ - if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */ - entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */ + } + } else { /* A RO volume does not exist */ + if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */ + entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */ modentry++; - } - } - else { - /* If VLDB says it didn't exist, then ignore error */ - if (entry->flags & BACK_EXISTS) { - MapPartIdIntoName(entry->serverPartition[idx], pname); - fprintf(STDERR,"Transaction call failed for BK volume %u on server %s %s\n", - entry->volumeId[BACKVOL], - hostutil_GetNameByINet(entry->serverNumber[idx]), pname); - ERROR_EXIT(code); - } - } - } - - /* If there is an idx but the BK and RW volumes no - * longer exist, then remove the RW entry. - */ - if ((idx != -1) && !(entry->flags & RW_EXISTS) && - !(entry->flags & BACK_EXISTS)) { - Lp_SetRWValue(entry, entry->serverNumber[idx], - entry->serverPartition[idx], 0L, 0L); - entry->nServers--; - modentry++; - } - - error_exit: - if (modified) *modified = modentry; - return(error); -} + } + } -CheckVldbRO(entry, modified) - struct nvldbentry *entry; - afs_int32 *modified; -{ - int idx; - int foundro = 0, modentry = 0; - afs_int32 code, error = 0; - char pname[10]; - - if (modified) *modified = 0; - - /* Check to see if the RO volumes exist and set the RO_EXISTS - * flag accordingly. - */ - for (idx=0; idx < entry->nServers; idx++) { - if (!(entry->serverFlags[idx] & ITSROVOL)) { - continue; /* not a RO */ - } - - code = VolumeExists(entry->serverNumber[idx], - entry->serverPartition[idx], - entry->volumeId[ROVOL]); - if (code == 0) { /* RO volume exists */ - foundro++; - } - else if (code == ENODEV) { /* RW volume does not exist */ - Lp_SetROValue(entry, entry->serverNumber[idx], - entry->serverPartition[idx], 0L, 0L); - entry->nServers--; - idx--; - modentry++; - } - else { - MapPartIdIntoName(entry->serverPartition[idx], pname); - fprintf(STDERR,"Transaction call failed for RO %u on server %s %s\n", - entry->volumeId[ROVOL], - hostutil_GetNameByINet(entry->serverNumber[idx]), pname); - ERROR_EXIT(code); - } - } - - if (foundro) { /* A RO volume exists */ - if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */ - entry->flags |= RO_EXISTS; /* ... so say RW does exist */ - modentry++; - } - } else { /* A RO volume does not exist */ - if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */ - entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */ - modentry++; - } - } - - error_exit: - if (modified) *modified = modentry; - return(error); + error_exit: + if (modified) + *modified = modentry; + return (error); } /* CheckVldb() * Ensure that matches with the info on file servers */ -afs_int32 CheckVldb(entry, modified) - struct nvldbentry *entry; - afs_int32 *modified; +afs_int32 +CheckVldb(struct nvldbentry * entry, afs_int32 * modified) { - afs_int32 code, error=0; - struct nvldbentry storeEntry; - int islocked=0, mod, modentry, delentry=0; - int pass=0; - - if (modified) *modified = 0; - if (verbose) { - fprintf(STDOUT,"_______________________________\n"); - fprintf(STDOUT,"\n-- status before -- \n"); - if ((entry->flags & RW_EXISTS) || - (entry->flags & RO_EXISTS) || - (entry->flags & BACK_EXISTS)) - EnumerateEntry(entry); - fprintf(STDOUT,"\n"); - } - - if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) { - fprintf(STDERR,"Volume name %s exceeds limit of %d characters\n", - entry->name, VOLSER_OLDMAXVOLNAME-10); - } - - retry: - /* Check to see if the VLDB is ok without locking it (pass 1). - * If it will change, then lock the VLDB entry, read it again, - * then make the changes to it (pass 2). - */ - if (++pass == 2) { - code = ubik_Call(VL_SetLock,cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_DELETE); - if (code) { - fprintf(STDERR, "Could not lock VLDB entry for %u \n",entry->volumeId[RWVOL] ); - ERROR_EXIT(code); - } - islocked = 1; - - code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry); - if (code) { - fprintf(STDERR,"Could not read VLDB entry for volume %s\n", entry->name); - ERROR_EXIT(code); - } - else { - MapHostToNetwork(entry); - } - } - - modentry = 0; - - /* Check if the RW and BK entries are ok */ - code = CheckVldbRWBK(entry, &mod); - if (code) ERROR_EXIT(code); - if (mod && (pass == 1)) goto retry; - if (mod) modentry++; - - /* Check if the RO volumes entries are ok */ - code = CheckVldbRO(entry, &mod); - if (code) ERROR_EXIT(code); - if (mod && (pass == 1)) goto retry; - if (mod) modentry++; - - /* The VLDB entry has been updated. If it as been modified, then - * write the entry back out the the VLDB. - */ - if (modentry) { - if (pass == 1) goto retry; - - if (!(entry->flags & RW_EXISTS) && - !(entry->flags & BACK_EXISTS) && - !(entry->flags & RO_EXISTS)) { - /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */ - code = ubik_Call(VL_DeleteEntry, cstruct, 0, entry->volumeId[RWVOL], RWVOL); - if (code) { - fprintf(STDERR,"Could not delete VLDB entry for volume %u \n", + afs_int32 code, error = 0; + struct nvldbentry storeEntry; + int islocked = 0, mod, modentry, delentry = 0; + int pass = 0; + + if (modified) + *modified = 0; + if (verbose) { + fprintf(STDOUT, "_______________________________\n"); + fprintf(STDOUT, "\n-- status before -- \n"); + if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS) + || (entry->flags & BACK_EXISTS)) + EnumerateEntry(entry); + fprintf(STDOUT, "\n"); + } + + if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) { + fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n", + entry->name, VOLSER_OLDMAXVOLNAME - 10); + } + + retry: + /* Check to see if the VLDB is ok without locking it (pass 1). + * If it will change, then lock the VLDB entry, read it again, + * then make the changes to it (pass 2). + */ + if (++pass == 2) { + code = + ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL, + VLOP_DELETE); + if (code) { + fprintf(STDERR, "Could not lock VLDB entry for %u \n", entry->volumeId[RWVOL]); ERROR_EXIT(code); - } - delentry = 1; - } - else { - /* Replace old entry with our new one */ - MapNetworkToHost(entry,&storeEntry); - code = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); - if (code) { - fprintf(STDERR,"Could not update VLDB entry for volume %u\n", - entry->volumeId[RWVOL] ); + } + islocked = 1; + + code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry); + if (code) { + fprintf(STDERR, "Could not read VLDB entry for volume %s\n", + entry->name); ERROR_EXIT(code); - } - } - if (modified) *modified = 1; - islocked = 0; - } - - if (verbose) { - fprintf(STDOUT,"-- status after --\n"); - if (delentry) - fprintf(STDOUT,"\n**entry deleted**\n"); - else if (modentry) - EnumerateEntry(entry); - else - fprintf(STDOUT,"\n**no change**\n"); - } - - error_exit: - if (verbose) { - fprintf(STDOUT,"\n_______________________________\n"); - } - - if (islocked) { - code = ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL, - (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); - if (code) { - fprintf(STDERR,"Could not release lock on VLDB entry for volume %u\n", - entry->volumeId[RWVOL]); - if (!error) error = code; - } - } - return error; + } else { + MapHostToNetwork(entry); + } + } + + modentry = 0; + + /* Check if the RW and BK entries are ok */ + code = CheckVldbRWBK(entry, &mod); + if (code) + ERROR_EXIT(code); + if (mod && (pass == 1)) + goto retry; + if (mod) + modentry++; + + /* Check if the RO volumes entries are ok */ + code = CheckVldbRO(entry, &mod); + if (code) + ERROR_EXIT(code); + if (mod && (pass == 1)) + goto retry; + if (mod) + modentry++; + + /* The VLDB entry has been updated. If it as been modified, then + * write the entry back out the the VLDB. + */ + if (modentry) { + if (pass == 1) + goto retry; + + if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS) + && !(entry->flags & RO_EXISTS)) { + /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */ + code = + ubik_Call(VL_DeleteEntry, cstruct, 0, entry->volumeId[RWVOL], + RWVOL); + if (code) { + fprintf(STDERR, + "Could not delete VLDB entry for volume %u \n", + entry->volumeId[RWVOL]); + ERROR_EXIT(code); + } + delentry = 1; + } else { + /* Replace old entry with our new one */ + MapNetworkToHost(entry, &storeEntry); + code = + VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, + (LOCKREL_OPCODE | LOCKREL_AFSID | + LOCKREL_TIMESTAMP)); + if (code) { + fprintf(STDERR, "Could not update VLDB entry for volume %u\n", + entry->volumeId[RWVOL]); + ERROR_EXIT(code); + } + } + if (modified) + *modified = 1; + islocked = 0; + } + + if (verbose) { + fprintf(STDOUT, "-- status after --\n"); + if (delentry) + fprintf(STDOUT, "\n**entry deleted**\n"); + else if (modentry) + EnumerateEntry(entry); + else + fprintf(STDOUT, "\n**no change**\n"); + } + + error_exit: + VPRINT("\n_______________________________\n"); + + if (islocked) { + code = + ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL], + RWVOL, + (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP)); + if (code) { + fprintf(STDERR, + "Could not release lock on VLDB entry for volume %u\n", + entry->volumeId[RWVOL]); + if (!error) + error = code; + } + } + return error; } /* UV_SyncServer() * Synchronise (if flags = 1) with the VLDB. */ -UV_SyncServer(aserver, apart, flags, force) - afs_int32 aserver, apart; - int flags, force; +int +UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force) { struct rx_connection *aconn; afs_int32 code, error = 0; - afs_int32 nentries, tentries=0; + afs_int32 nentries, tentries = 0; struct VldbListByAttributes attributes; nbulkentries arrayEntries; - afs_int32 failures=0, modified, modifications=0; + afs_int32 failures = 0, modified, modifications = 0; struct nvldbentry *vlentry; afs_int32 si, nsi, j; - aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT); + aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT); /* Set up attributes to search VLDB */ - attributes.server = ntohl(aserver); - attributes.Mask = VLLIST_SERVER; + attributes.server = ntohl(aserver); + attributes.Mask = VLLIST_SERVER; if (flags) { - attributes.partition = apart; - attributes.Mask |= VLLIST_PARTITION; + attributes.partition = apart; + attributes.Mask |= VLLIST_PARTITION; } - if (verbose) { - fprintf(STDOUT,"Processing VLDB entries ...\n"); - fflush(STDOUT); - } + VPRINT("Processing VLDB entries ...\n"); /* While we need to collect more VLDB entries */ - for (si=0; si != -1; si=nsi) { - memset(&arrayEntries, 0, sizeof(arrayEntries)); - - /* Collect set of VLDB entries */ - code = VLDB_ListAttributesN2(&attributes, 0, si, - &nentries, &arrayEntries, &nsi); - if (code == RXGEN_OPCODE) { - code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); - nsi = -1; - } - if (code) { - fprintf(STDERR,"Could not access the VLDB for attributes\n"); - ERROR_EXIT(code); - } - tentries += nentries; - - for (j=0; jname); - failures++; - } else if (modified) { - modifications++; - } - - if (verbose) { - if (code) { - fprintf(STDOUT,"...error encountered\n\n"); - } else { - fprintf(STDOUT,"...done entry %d\n\n", j+1); - } - } - } - - if (arrayEntries.nbulkentries_val) { - free(arrayEntries.nbulkentries_val); - arrayEntries.nbulkentries_val = 0; - } - } + for (si = 0; si != -1; si = nsi) { + memset(&arrayEntries, 0, sizeof(arrayEntries)); + + /* Collect set of VLDB entries */ + code = + VLDB_ListAttributesN2(&attributes, 0, si, &nentries, + &arrayEntries, &nsi); + if (code == RXGEN_OPCODE) { + code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); + nsi = -1; + } + if (code) { + fprintf(STDERR, "Could not access the VLDB for attributes\n"); + ERROR_EXIT(code); + } + tentries += nentries; - if (verbose) { - fprintf(STDOUT,"Total entries: %u, Failed to process %d, Changed %d\n", - tentries, failures, modifications); + for (j = 0; j < nentries; j++) { + vlentry = &arrayEntries.nbulkentries_val[j]; + MapHostToNetwork(vlentry); + + VPRINT1("Processing VLDB entry %d ...\n", j + 1); + + code = CheckVldb(vlentry, &modified); + if (code) { + PrintError("", code); + fprintf(STDERR, + "Could not process VLDB entry for volume %s\n", + vlentry->name); + failures++; + } else if (modified) { + modifications++; + } + + if (verbose) { + if (code) { + fprintf(STDOUT, "...error encountered\n\n"); + } else { + fprintf(STDOUT, "...done entry %d\n\n", j + 1); + } + } + } + + if (arrayEntries.nbulkentries_val) { + free(arrayEntries.nbulkentries_val); + arrayEntries.nbulkentries_val = 0; + } } - error_exit: + VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries, + failures, modifications); + + error_exit: if (aconn) - rx_DestroyConnection(aconn); + rx_DestroyConnection(aconn); if (arrayEntries.nbulkentries_val) - free(arrayEntries.nbulkentries_val); + free(arrayEntries.nbulkentries_val); if (failures) - error = VOLSERFAILEDOP; + error = VOLSERFAILEDOP; return error; } @@ -4692,13 +6391,12 @@ UV_SyncServer(aserver, apart, flags, force) *readonly and backup volumes. This operation is also idempotent. *salvager is capable of recovering from rename operation stopping halfway. *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */ -UV_RenameVolume(entry,oldname,newname) -struct nvldbentry *entry; -char oldname[],newname[]; +int +UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[]) { struct nvldbentry storeEntry; - afs_int32 vcode,code,rcode,error; - int i,index; + afs_int32 vcode, code, rcode, error; + int i, index; char nameBuffer[256]; afs_int32 tid; struct rx_connection *aconn; @@ -4709,206 +6407,257 @@ char oldname[],newname[]; tid = 0; islocked = 0; - vcode = ubik_Call(VL_SetLock,cstruct, 0,entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE);/*last param is dummy*/ - if(vcode){ - fprintf(STDERR," Could not lock the VLDB entry for the volume %u \n",entry->volumeId[RWVOL] ); + vcode = ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */ + if (vcode) { + fprintf(STDERR, + " Could not lock the VLDB entry for the volume %u \n", + entry->volumeId[RWVOL]); error = vcode; goto rvfail; } islocked = 1; - strncpy(entry->name,newname,VOLSER_OLDMAXVOLNAME); - MapNetworkToHost(entry,&storeEntry); - vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL],RWVOL, &storeEntry,0 ); + strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME); + MapNetworkToHost(entry, &storeEntry); + vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0); if (vcode) { - fprintf(STDERR,"Could not update VLDB entry for %u\n",entry->volumeId[RWVOL]); + fprintf(STDERR, "Could not update VLDB entry for %u\n", + entry->volumeId[RWVOL]); error = vcode; goto rvfail; } - if(verbose) fprintf(STDOUT,"Recorded the new name %s in VLDB\n",newname); + VPRINT1("Recorded the new name %s in VLDB\n", newname); /*at this stage the intent to rename is recorded in the vldb, as far as the vldb - is concerned, oldname is lost */ - if(entry->flags & RW_EXISTS) { + * is concerned, oldname is lost */ + if (entry->flags & RW_EXISTS) { index = Lp_GetRwIndex(entry); - if(index == -1){ /* there is a serious discrepancy */ - fprintf(STDERR,"There is a serious discrepancy in VLDB entry for volume %u\n",entry->volumeId[RWVOL]); - fprintf(STDERR,"try building VLDB from scratch\n"); + if (index == -1) { /* there is a serious discrepancy */ + fprintf(STDERR, + "There is a serious discrepancy in VLDB entry for volume %u\n", + entry->volumeId[RWVOL]); + fprintf(STDERR, "try building VLDB from scratch\n"); error = VOLSERVLDB_ERROR; goto rvfail; } - aconn = UV_Bind(entry->serverNumber[index],AFSCONF_VOLUMEPORT); - code = AFSVolTransCreate(aconn,entry->volumeId[RWVOL],entry->serverPartition[index], ITOffline, &tid); - if(code) { /*volume doesnot exist */ - fprintf(STDERR,"Could not start transaction on the rw volume %u\n",entry->volumeId[RWVOL]); + aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT); + code = + AFSVolTransCreate(aconn, entry->volumeId[RWVOL], + entry->serverPartition[index], ITOffline, &tid); + if (code) { /*volume doesnot exist */ + fprintf(STDERR, + "Could not start transaction on the rw volume %u\n", + entry->volumeId[RWVOL]); error = code; goto rvfail; - } - else {/*volume exists, process it */ + } else { /*volume exists, process it */ - code = AFSVolSetIdsTypes(aconn, tid, newname,RWVOL, entry->volumeId[RWVOL],entry->volumeId[ROVOL],entry->volumeId[BACKVOL]); - if(!code) { - if(verbose) printf("Renamed rw volume %s to %s\n",oldname,newname); + code = + AFSVolSetIdsTypes(aconn, tid, newname, RWVOL, + entry->volumeId[RWVOL], + entry->volumeId[ROVOL], + entry->volumeId[BACKVOL]); + if (!code) { + VPRINT2("Renamed rw volume %s to %s\n", oldname, newname); code = AFSVolEndTrans(aconn, tid, &rcode); tid = 0; - if(code) { - fprintf(STDERR,"Could not end transaction on volume %s %u\n",entry->name,entry->volumeId[RWVOL]); + if (code) { + fprintf(STDERR, + "Could not end transaction on volume %s %u\n", + entry->name, entry->volumeId[RWVOL]); error = code; goto rvfail; } - } - else { - fprintf(STDERR,"Could not set parameters on volume %s %u\n",entry->name,entry->volumeId[RWVOL]); + } else { + fprintf(STDERR, "Could not set parameters on volume %s %u\n", + entry->name, entry->volumeId[RWVOL]); error = code; goto rvfail; } } - if(aconn) rx_DestroyConnection(aconn); + if (aconn) + rx_DestroyConnection(aconn); aconn = (struct rx_connection *)0; - } /*end rw volume processing */ - - if(entry->flags & BACK_EXISTS) {/*process the backup volume */ + } + /*end rw volume processing */ + if (entry->flags & BACK_EXISTS) { /*process the backup volume */ index = Lp_GetRwIndex(entry); - if(index == -1){ /* there is a serious discrepancy */ - fprintf(STDERR,"There is a serious discrepancy in the VLDB entry for the backup volume %u\n",entry->volumeId[BACKVOL]); - fprintf(STDERR,"try building VLDB from scratch\n"); + if (index == -1) { /* there is a serious discrepancy */ + fprintf(STDERR, + "There is a serious discrepancy in the VLDB entry for the backup volume %u\n", + entry->volumeId[BACKVOL]); + fprintf(STDERR, "try building VLDB from scratch\n"); error = VOLSERVLDB_ERROR; goto rvfail; } - aconn = UV_Bind(entry->serverNumber[index],AFSCONF_VOLUMEPORT); - code = AFSVolTransCreate(aconn,entry->volumeId[BACKVOL],entry->serverPartition[index], ITOffline, &tid); - if(code) { /*volume doesnot exist */ - fprintf(STDERR,"Could not start transaction on the backup volume %u\n",entry->volumeId[BACKVOL]); + aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT); + code = + AFSVolTransCreate(aconn, entry->volumeId[BACKVOL], + entry->serverPartition[index], ITOffline, &tid); + if (code) { /*volume doesnot exist */ + fprintf(STDERR, + "Could not start transaction on the backup volume %u\n", + entry->volumeId[BACKVOL]); error = code; goto rvfail; - } - else {/*volume exists, process it */ - if(strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)){ - fprintf(STDERR,"Volume name %s.backup exceeds the limit of %u characters\n",newname,VOLSER_OLDMAXVOLNAME); + } else { /*volume exists, process it */ + if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) { + fprintf(STDERR, + "Volume name %s.backup exceeds the limit of %u characters\n", + newname, VOLSER_OLDMAXVOLNAME); error = code; goto rvfail; } - strcpy(nameBuffer,newname); - strcat(nameBuffer,".backup"); + strcpy(nameBuffer, newname); + strcat(nameBuffer, ".backup"); - code = AFSVolSetIdsTypes(aconn, tid,nameBuffer ,BACKVOL, entry->volumeId[RWVOL],0,0); - if(!code) { - if(verbose) fprintf(STDOUT,"Renamed backup volume to %s \n",nameBuffer); + code = + AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL, + entry->volumeId[RWVOL], 0, 0); + if (!code) { + VPRINT1("Renamed backup volume to %s \n", nameBuffer); code = AFSVolEndTrans(aconn, tid, &rcode); tid = 0; - if(code) { - fprintf(STDERR,"Could not end transaction on the backup volume %u\n",entry->volumeId[BACKVOL]); + if (code) { + fprintf(STDERR, + "Could not end transaction on the backup volume %u\n", + entry->volumeId[BACKVOL]); error = code; goto rvfail; } - } - else { - fprintf(STDERR,"Could not set parameters on the backup volume %u\n",entry->volumeId[BACKVOL]); + } else { + fprintf(STDERR, + "Could not set parameters on the backup volume %u\n", + entry->volumeId[BACKVOL]); error = code; goto rvfail; } } - } /* end backup processing */ - if(aconn) rx_DestroyConnection(aconn); + } /* end backup processing */ + if (aconn) + rx_DestroyConnection(aconn); aconn = (struct rx_connection *)0; - if(entry->flags & RO_EXISTS){ /*process the ro volumes */ - for(i = 0; i < entry->nServers; i++){ - if(entry->serverFlags[i] & ITSROVOL) { - aconn = UV_Bind(entry->serverNumber[i],AFSCONF_VOLUMEPORT); - code = AFSVolTransCreate(aconn,entry->volumeId[ROVOL],entry->serverPartition[i], ITOffline, &tid); - if(code) { /*volume doesnot exist */ - fprintf(STDERR,"Could not start transaction on the ro volume %u\n",entry->volumeId[ROVOL]); + if (entry->flags & RO_EXISTS) { /*process the ro volumes */ + for (i = 0; i < entry->nServers; i++) { + if (entry->serverFlags[i] & ITSROVOL) { + aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT); + code = + AFSVolTransCreate(aconn, entry->volumeId[ROVOL], + entry->serverPartition[i], ITOffline, + &tid); + if (code) { /*volume doesnot exist */ + fprintf(STDERR, + "Could not start transaction on the ro volume %u\n", + entry->volumeId[ROVOL]); error = code; goto rvfail; - } - else {/*volume exists, process it */ - strcpy(nameBuffer,newname); - strcat(nameBuffer,".readonly"); - if(strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)){ - fprintf(STDERR,"Volume name %s exceeds the limit of %u characters\n",nameBuffer,VOLSER_OLDMAXVOLNAME); + } else { /*volume exists, process it */ + strcpy(nameBuffer, newname); + strcat(nameBuffer, ".readonly"); + if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) { + fprintf(STDERR, + "Volume name %s exceeds the limit of %u characters\n", + nameBuffer, VOLSER_OLDMAXVOLNAME); error = code; goto rvfail; } - code = AFSVolSetIdsTypes(aconn, tid, nameBuffer,ROVOL, entry->volumeId[RWVOL],0,0); - if(!code) { - if(verbose) fprintf(STDOUT,"Renamed RO volume %s on host %s\n", - nameBuffer, - hostutil_GetNameByINet(entry->serverNumber[i])); + code = + AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL, + entry->volumeId[RWVOL], 0, 0); + if (!code) { + VPRINT2("Renamed RO volume %s on host %s\n", + nameBuffer, + hostutil_GetNameByINet(entry-> + serverNumber[i])); code = AFSVolEndTrans(aconn, tid, &rcode); tid = 0; if (code) { - fprintf(STDERR,"Could not end transaction on volume %u\n",entry->volumeId[ROVOL]); + fprintf(STDERR, + "Could not end transaction on volume %u\n", + entry->volumeId[ROVOL]); error = code; goto rvfail; } - } - else { - fprintf(STDERR,"Could not set parameters on the ro volume %u\n",entry->volumeId[ROVOL]); + } else { + fprintf(STDERR, + "Could not set parameters on the ro volume %u\n", + entry->volumeId[ROVOL]); error = code; goto rvfail; } } - if(aconn) rx_DestroyConnection(aconn); + if (aconn) + rx_DestroyConnection(aconn); aconn = (struct rx_connection *)0; } } } -rvfail: - if(islocked) { - vcode = ubik_Call(VL_ReleaseLock,cstruct, 0,entry->volumeId[RWVOL] , RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); - if(vcode){ - fprintf(STDERR,"Could not unlock the VLDB entry for the volume %s %u\n",entry->name,entry->volumeId[RWVOL]); - if(!error) error = vcode; + rvfail: + if (islocked) { + vcode = + ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL], + RWVOL, + LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP); + if (vcode) { + fprintf(STDERR, + "Could not unlock the VLDB entry for the volume %s %u\n", + entry->name, entry->volumeId[RWVOL]); + if (!error) + error = vcode; } } - if(tid) { - code = AFSVolEndTrans(aconn, tid, &rcode); - if(!code) code = rcode; - if(code) { - fprintf(STDERR,"Failed to end transaction on a volume \n"); - if(!error) error = code; + if (tid) { + code = AFSVolEndTrans(aconn, tid, &rcode); + if (!code) + code = rcode; + if (code) { + fprintf(STDERR, "Failed to end transaction on a volume \n"); + if (!error) + error = code; } } - if(aconn) rx_DestroyConnection(aconn); - PrintError("",error); + if (aconn) + rx_DestroyConnection(aconn); + PrintError("", error); return error; - + } /*report on all the active transactions on volser */ -UV_VolserStatus(server,rpntr,rcount) -afs_int32 server; -transDebugInfo **rpntr; -afs_int32 *rcount; +int +UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount) { struct rx_connection *aconn; transDebugEntries transInfo; afs_int32 code = 0; - + aconn = UV_Bind(server, AFSCONF_VOLUMEPORT); transInfo.transDebugEntries_val = (transDebugInfo *) 0; transInfo.transDebugEntries_len = 0; - code = AFSVolMonitor(aconn,&transInfo); - if(code) { - fprintf(STDERR,"Could not access status information about the server\n"); - PrintError("",code); - if (transInfo.transDebugEntries_val) free(transInfo.transDebugEntries_val); - if(aconn) rx_DestroyConnection(aconn); + code = AFSVolMonitor(aconn, &transInfo); + if (code) { + fprintf(STDERR, + "Could not access status information about the server\n"); + PrintError("", code); + if (transInfo.transDebugEntries_val) + free(transInfo.transDebugEntries_val); + if (aconn) + rx_DestroyConnection(aconn); return code; - } - else { + } else { *rcount = transInfo.transDebugEntries_len; *rpntr = transInfo.transDebugEntries_val; - if(aconn) rx_DestroyConnection(aconn); + if (aconn) + rx_DestroyConnection(aconn); return 0; } - -} -/*delete the volume without interacting with the vldb */ -UV_VolumeZap(server,part,volid) -afs_int32 volid,server,part; +} + +/*delete the volume without interacting with the vldb */ +int +UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid) { - afs_int32 rcode,ttid,error,code; + afs_int32 rcode, ttid, error, code; struct rx_connection *aconn; code = 0; @@ -4917,143 +6666,199 @@ afs_int32 volid,server,part; aconn = UV_Bind(server, AFSCONF_VOLUMEPORT); code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid); - if(code){ - fprintf(STDERR,"Could not start transaction on volume %u\n",volid); + if (code) { + fprintf(STDERR, "Could not start transaction on volume %lu\n", + (unsigned long)volid); error = code; goto zfail; } code = AFSVolDeleteVolume(aconn, ttid); - if(code){ - fprintf(STDERR,"Could not delete volume %u\n",volid); + if (code) { + fprintf(STDERR, "Could not delete volume %lu\n", + (unsigned long)volid); error = code; goto zfail; } code = AFSVolEndTrans(aconn, ttid, &rcode); ttid = 0; - if(!code) code = rcode; - if(code){ - fprintf(STDERR,"Could not end transaction on volume %u\n",volid); + if (!code) + code = rcode; + if (code) { + fprintf(STDERR, "Could not end transaction on volume %lu\n", + (unsigned long)volid); error = code; goto zfail; } -zfail: -if(ttid){ - code = AFSVolEndTrans(aconn,ttid,&rcode); - if(!code) code = rcode; - if(!error) error = code; -} -PrintError("",error); -if(aconn) rx_DestroyConnection(aconn); -return error; + zfail: + if (ttid) { + code = AFSVolEndTrans(aconn, ttid, &rcode); + if (!code) + code = rcode; + if (!error) + error = code; + } + PrintError("", error); + if (aconn) + rx_DestroyConnection(aconn); + return error; } -UV_SetVolume(server, partition, volid, transflag, setflag, sleeptime) - afs_int32 server, partition, volid, transflag, setflag; +int +UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid, + afs_int32 transflag, afs_int32 setflag, int sleeptime) { - struct rx_connection *conn = 0; - afs_int32 tid=0; - afs_int32 code, error=0, rcode; - - conn = UV_Bind(server, AFSCONF_VOLUMEPORT); - if (!conn) { - fprintf(STDERR, "SetVolumeStatus: Bind Failed"); - ERROR_EXIT(-1); - } - - code = AFSVolTransCreate(conn, volid, partition, transflag, &tid); - if (code) { - fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n"); - ERROR_EXIT(code); - } - - code = AFSVolSetFlags(conn, tid, setflag); - if (code) { - fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n"); - ERROR_EXIT(code); - } - - if (sleeptime) { + struct rx_connection *conn = 0; + afs_int32 tid = 0; + afs_int32 code, error = 0, rcode; + + conn = UV_Bind(server, AFSCONF_VOLUMEPORT); + if (!conn) { + fprintf(STDERR, "SetVolumeStatus: Bind Failed"); + ERROR_EXIT(-1); + } + + code = AFSVolTransCreate(conn, volid, partition, transflag, &tid); + if (code) { + fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n"); + ERROR_EXIT(code); + } + + code = AFSVolSetFlags(conn, tid, setflag); + if (code) { + fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n"); + ERROR_EXIT(code); + } + + if (sleeptime) { #ifdef AFS_PTHREAD_ENV - sleep(sleeptime); + sleep(sleeptime); #else - IOMGR_Sleep(sleeptime); + IOMGR_Sleep(sleeptime); #endif - } - - error_exit: - if (tid) { - rcode = 0; - code = AFSVolEndTrans(conn, tid, &rcode); - if (code || rcode) { - fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n"); - if (!error) error = (code ? code : rcode); - } - } - - if (conn) rx_DestroyConnection(conn); - return(error); + } + + error_exit: + if (tid) { + rcode = 0; + code = AFSVolEndTrans(conn, tid, &rcode); + if (code || rcode) { + fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n"); + if (!error) + error = (code ? code : rcode); + } + } + + if (conn) + rx_DestroyConnection(conn); + return (error); } -UV_SetVolumeInfo(server, partition, volid, infop) - afs_int32 server, partition, volid; - volintInfo *infop; +int +UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid, + volintInfo * infop) { - struct rx_connection *conn = 0; - afs_int32 tid=0; - afs_int32 code, error=0, rcode; - - conn = UV_Bind(server, AFSCONF_VOLUMEPORT); - if (!conn) { - fprintf(STDERR, "SetVolumeInfo: Bind Failed"); - ERROR_EXIT(-1); - } - - code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid); - if (code) { - fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n"); - ERROR_EXIT(code); - } - - code = AFSVolSetInfo(conn, tid, infop); - if (code) { - fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n"); - ERROR_EXIT(code); - } - - error_exit: - if (tid) { - rcode = 0; - code = AFSVolEndTrans(conn, tid, &rcode); - if (code || rcode) { - fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n"); - if (!error) error = (code ? code : rcode); - } - } - - if (conn) rx_DestroyConnection(conn); - return(error); + struct rx_connection *conn = 0; + afs_int32 tid = 0; + afs_int32 code, error = 0, rcode; + + conn = UV_Bind(server, AFSCONF_VOLUMEPORT); + if (!conn) { + fprintf(STDERR, "SetVolumeInfo: Bind Failed"); + ERROR_EXIT(-1); + } + + code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid); + if (code) { + fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n"); + ERROR_EXIT(code); + } + + code = AFSVolSetInfo(conn, tid, infop); + if (code) { + fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n"); + ERROR_EXIT(code); + } + + error_exit: + if (tid) { + rcode = 0; + code = AFSVolEndTrans(conn, tid, &rcode); + if (code || rcode) { + fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n"); + if (!error) + error = (code ? code : rcode); + } + } + + if (conn) + rx_DestroyConnection(conn); + return (error); +} + +int +UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart, + afs_int32 fromdate, struct volintSize *vol_size) +{ + struct rx_connection *aconn = (struct rx_connection *)0; + afs_int32 tid = 0, rcode = 0; + afs_int32 code, error = 0; + + + /* get connections to the servers */ + aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT); + + VPRINT1("Starting transaction on volume %u...", afromvol); + code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid); + EGOTO1(error_exit, code, + "Could not start transaction on the volume %u to be measured\n", + afromvol); + VDONE; + + VPRINT1("Getting size of volume on volume %u...", afromvol); + code = AFSVolGetSize(aconn, tid, fromdate, vol_size); + EGOTO(error_exit, code, "Could not start the measurement process \n"); + VDONE; + + error_exit: + if (tid) { + VPRINT1("Ending transaction on volume %u...", afromvol); + code = AFSVolEndTrans(aconn, tid, &rcode); + if (code || rcode) { + fprintf(STDERR, "Could not end transaction on the volume %u\n", + afromvol); + fprintf(STDERR, "error codes: %d and %d\n", code, rcode); + if (!error) + error = (code ? code : rcode); + } + VDONE; + } + if (aconn) + rx_DestroyConnection(aconn); + + PrintError("", error); + return (error); } /*maps the host addresses in (present in network byte order) to that in< new> (present in host byte order )*/ void -MapNetworkToHost(old, new) -struct nvldbentry *old, *new; +MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new) { - int i,count; + int i, count; /*copy all the fields */ - strcpy(new->name,old->name); + strcpy(new->name, old->name); /* new->volumeType = old->volumeType;*/ new->nServers = old->nServers; count = old->nServers; - if(count < NMAXNSERVERS) count++; - for(i = 0; i < count; i++) { + if (count < NMAXNSERVERS) + count++; + for (i = 0; i < count; i++) { new->serverNumber[i] = ntohl(old->serverNumber[i]); new->serverPartition[i] = old->serverPartition[i]; new->serverFlags[i] = old->serverFlags[i]; } - new->volumeId[RWVOL]= old->volumeId[RWVOL]; + new->volumeId[RWVOL] = old->volumeId[RWVOL]; new->volumeId[ROVOL] = old->volumeId[ROVOL]; new->volumeId[BACKVOL] = old->volumeId[BACKVOL]; new->cloneId = old->cloneId; @@ -5062,15 +6867,14 @@ struct nvldbentry *old, *new; /*maps the host entries in which are present in host byte order to network byte order */ void -MapHostToNetwork(entry) -struct nvldbentry *entry; +MapHostToNetwork(struct nvldbentry *entry) { - int i,count; - + int i, count; + count = entry->nServers; - if(count < NMAXNSERVERS) count++; - for(i = 0; i < count; i++) { + if (count < NMAXNSERVERS) + count++; + for (i = 0; i < count; i++) { entry->serverNumber[i] = htonl(entry->serverNumber[i]); } } - diff --git a/src/volser/vsutils.c b/src/volser/vsutils.c index 8e53fb21c..0f825be9e 100644 --- a/src/volser/vsutils.c +++ b/src/volser/vsutils.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vsutils.c,v 1.1.1.9 2001/10/14 18:07:32 hartmans Exp $"); +RCSID + ("$Header: /cvs/openafs/src/volser/vsutils.c,v 1.16 2003/12/07 22:49:46 jaltman Exp $"); #include #ifdef AFS_NT40_ENV @@ -26,6 +27,15 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vsutils.c,v 1.1.1.9 2001/10/14 1 #ifdef AFS_AIX_ENV #include #endif + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include #include #include @@ -46,35 +56,32 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/volser/vsutils.c,v 1.1.1.9 2001/10/14 1 struct ubik_client *cstruct; static rxkad_level vsu_rxkad_level = rxkad_clear; -extern int VL_CreateEntry(), VL_CreateEntryN(); -extern int VL_GetEntryByID(), VL_GetEntryByIDN(); -extern int VL_GetEntryByNameO(), VL_GetEntryByNameN(); -extern int VL_ReplaceEntry(), VL_ReplaceEntryN(); -extern int VL_ListAttributes(), VL_ListAttributesN(), VL_ListAttributesN2(); - -static void ovlentry_to_nvlentry(oentryp, nentryp) - struct vldbentry *oentryp; - struct nvldbentry *nentryp; + +static void +ovlentry_to_nvlentry(oentryp, nentryp) + struct vldbentry *oentryp; + struct nvldbentry *nentryp; { register int i; memset(nentryp, 0, sizeof(struct nvldbentry)); strncpy(nentryp->name, oentryp->name, sizeof(nentryp->name)); - for (i=0; i < oentryp->nServers; i++) { + for (i = 0; i < oentryp->nServers; i++) { nentryp->serverNumber[i] = oentryp->serverNumber[i]; nentryp->serverPartition[i] = oentryp->serverPartition[i]; nentryp->serverFlags[i] = oentryp->serverFlags[i]; } nentryp->nServers = oentryp->nServers; - for (i=0; ivolumeId[i] = oentryp->volumeId[i]; nentryp->cloneId = oentryp->cloneId; nentryp->flags = oentryp->flags; } -static nvlentry_to_ovlentry(nentryp, oentryp) - struct nvldbentry *nentryp; - struct vldbentry *oentryp; +static +nvlentry_to_ovlentry(nentryp, oentryp) + struct nvldbentry *nentryp; + struct vldbentry *oentryp; { register int i; @@ -87,29 +94,29 @@ static nvlentry_to_ovlentry(nentryp, oentryp) */ return VL_BADSERVER; } - for (i=0; i < nentryp->nServers; i++) { + for (i = 0; i < nentryp->nServers; i++) { oentryp->serverNumber[i] = nentryp->serverNumber[i]; oentryp->serverPartition[i] = nentryp->serverPartition[i]; oentryp->serverFlags[i] = nentryp->serverFlags[i]; } oentryp->nServers = i; - for (i=0; ivolumeId[i] = nentryp->volumeId[i]; oentryp->cloneId = nentryp->cloneId; oentryp->flags = nentryp->flags; return 0; } -static int newvlserver=0; +static int newvlserver = 0; VLDB_CreateEntry(entryp) - struct nvldbentry *entryp; + struct nvldbentry *entryp; { struct vldbentry oentry; register int code; if (newvlserver == 1) { -tryold: + tryold: code = nvlentry_to_ovlentry(entryp, &oentry); if (code) return code; @@ -129,15 +136,16 @@ tryold: } VLDB_GetEntryByID(volid, voltype, entryp) - afs_int32 volid, voltype; - struct nvldbentry *entryp; + afs_int32 volid, voltype; + struct nvldbentry *entryp; { struct vldbentry oentry; register int code; if (newvlserver == 1) { -tryold: - code = ubik_Call(VL_GetEntryByID, cstruct, 0, volid, voltype, &oentry); + tryold: + code = + ubik_Call(VL_GetEntryByID, cstruct, 0, volid, voltype, &oentry); if (!code) ovlentry_to_nvlentry(&oentry, entryp); return code; @@ -155,14 +163,14 @@ tryold: } VLDB_GetEntryByName(namep, entryp) - char *namep; - struct nvldbentry *entryp; + char *namep; + struct nvldbentry *entryp; { struct vldbentry oentry; register int code; if (newvlserver == 1) { -tryold: + tryold: code = ubik_Call(VL_GetEntryByNameO, cstruct, 0, namep, &oentry); if (!code) ovlentry_to_nvlentry(&oentry, entryp); @@ -181,21 +189,25 @@ tryold: } VLDB_ReplaceEntry(volid, voltype, entryp, releasetype) - afs_int32 volid, voltype, releasetype; - struct nvldbentry *entryp; + afs_int32 volid, voltype, releasetype; + struct nvldbentry *entryp; { struct vldbentry oentry; register int code; if (newvlserver == 1) { -tryold: + tryold: code = nvlentry_to_ovlentry(entryp, &oentry); if (code) return code; - code = ubik_Call(VL_ReplaceEntry, cstruct, 0, volid, voltype, &oentry, releasetype); + code = + ubik_Call(VL_ReplaceEntry, cstruct, 0, volid, voltype, &oentry, + releasetype); return code; } - code = ubik_Call(VL_ReplaceEntryN, cstruct, 0, volid, voltype, entryp, releasetype); + code = + ubik_Call(VL_ReplaceEntryN, cstruct, 0, volid, voltype, entryp, + releasetype); if (!newvlserver) { if (code == RXGEN_OPCODE) { newvlserver = 1; /* Doesn't support new interface */ @@ -210,27 +222,34 @@ tryold: VLDB_ListAttributes(attrp, entriesp, blkentriesp) - VldbListByAttributes *attrp; - afs_int32 *entriesp; - nbulkentries *blkentriesp; + VldbListByAttributes *attrp; + afs_int32 *entriesp; + nbulkentries *blkentriesp; { bulkentries arrayEntries; register int code, i; if (newvlserver == 1) { -tryold: - memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */ - code = ubik_Call(VL_ListAttributes, cstruct, 0, attrp, entriesp, &arrayEntries); + tryold: + memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */ + code = + ubik_Call(VL_ListAttributes, cstruct, 0, attrp, entriesp, + &arrayEntries); if (!code) { - blkentriesp->nbulkentries_val = (nvldbentry *)malloc(*entriesp * sizeof(struct nvldbentry)); + blkentriesp->nbulkentries_val = + (nvldbentry *) malloc(*entriesp * sizeof(struct nvldbentry)); for (i = 0; i < *entriesp; i++) { /* process each entry */ - ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i], &blkentriesp->nbulkentries_val[i]); + ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i], + &blkentriesp->nbulkentries_val[i]); } } - if (arrayEntries.bulkentries_val) free(arrayEntries.bulkentries_val); + if (arrayEntries.bulkentries_val) + free(arrayEntries.bulkentries_val); return code; } - code = ubik_Call(VL_ListAttributesN, cstruct, 0, attrp, entriesp, blkentriesp); + code = + ubik_Call(VL_ListAttributesN, cstruct, 0, attrp, entriesp, + blkentriesp); if (!newvlserver) { if (code == RXGEN_OPCODE) { newvlserver = 1; /* Doesn't support new interface */ @@ -242,76 +261,89 @@ tryold: return code; } -VLDB_ListAttributesN2(attrp, name, thisindex, nentriesp, blkentriesp, nextindexp) - VldbListByAttributes *attrp; - char *name; - afs_int32 thisindex; - afs_int32 *nentriesp; - nbulkentries *blkentriesp; - afs_int32 *nextindexp; +VLDB_ListAttributesN2(attrp, name, thisindex, nentriesp, blkentriesp, + nextindexp) + VldbListByAttributes *attrp; + char *name; + afs_int32 thisindex; + afs_int32 *nentriesp; + nbulkentries *blkentriesp; + afs_int32 *nextindexp; { - afs_int32 code; + afs_int32 code; - code = ubik_Call(VL_ListAttributesN2, cstruct, 0, - attrp, (name?name:""), thisindex, - nentriesp, blkentriesp, nextindexp); - return code; + code = + ubik_Call(VL_ListAttributesN2, cstruct, 0, attrp, (name ? name : ""), + thisindex, nentriesp, blkentriesp, nextindexp); + return code; } -static int vlserverv4=-1; +static int vlserverv4 = -1; struct cacheips { afs_int32 server; afs_int32 count; afs_uint32 addrs[16]; }; -struct cacheips cacheips[16]; -int cacheip_index=0; -extern int VL_GetAddrsU(); +/* + * Increase cache size. This avoids high CPU usage by the vlserver + * in environments where there are more than 16 fileservers in the + * cell. + */ +#define GETADDRUCACHESIZE 64 +struct cacheips cacheips[GETADDRUCACHESIZE]; +int cacheip_index = 0; + VLDB_IsSameAddrs(serv1, serv2, errorp) - afs_int32 serv1, serv2, *errorp; + afs_int32 serv1, serv2, *errorp; { register int code; ListAddrByAttributes attrs; bulkaddrs addrs; - afs_uint32 *addrp, nentries, unique, i, j, f1, f2; + afs_uint32 *addrp, nentries, unique, i, j, f1, f2; afsUUID uuid; static int initcache = 0; *errorp = 0; - if (serv1 == serv2) + if (serv1 == serv2) return 1; if (vlserverv4 == 1) { return 0; } if (!initcache) { - for (i=0; i<16; i++) { - cacheips[i].server = cacheips[i].count = 0; + for (i = 0; i < GETADDRUCACHESIZE; i++) { + cacheips[i].server = cacheips[i].count = 0; } initcache = 1; } /* See if it's cached */ - for (i=0; i<16; i++) { - f1 = f2 = 0; - for (j=0; j < cacheips[i].count; j++) { - if (serv1 == cacheips[i].addrs[j]) f1 = 1; - else if (serv2 == cacheips[i].addrs[j]) f2 = 1; - - if (f1 && f2) - return 1; - } - if (f1 || f2) - return 0; - } + for (i = 0; i < GETADDRUCACHESIZE; i++) { + f1 = f2 = 0; + for (j = 0; j < cacheips[i].count; j++) { + if (serv1 == cacheips[i].addrs[j]) + f1 = 1; + else if (serv2 == cacheips[i].addrs[j]) + f2 = 1; + + if (f1 && f2) + return 1; + } + if (f1 || f2) + return 0; + if (cacheips[i].server == serv1) + return 0; + } memset(&attrs, 0, sizeof(attrs)); attrs.Mask = VLADDR_IPADDR; attrs.ipaddr = serv1; memset(&addrs, 0, sizeof(addrs)); memset(&uuid, 0, sizeof(uuid)); - code = ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid, &unique, &nentries, &addrs); + code = + ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid, &unique, &nentries, + &addrs); if (vlserverv4 == -1) { if (code == RXGEN_OPCODE) { vlserverv4 = 1; /* Doesn't support new interface */ @@ -328,11 +360,14 @@ VLDB_IsSameAddrs(serv1, serv2, errorp) } code = 0; - if (++cacheip_index >= 16) cacheip_index = 0; + if (nentries > GETADDRUCACHESIZE) + nentries = GETADDRUCACHESIZE; /* safety check; should not happen */ + if (++cacheip_index >= GETADDRUCACHESIZE) + cacheip_index = 0; cacheips[cacheip_index].server = serv1; cacheips[cacheip_index].count = nentries; addrp = addrs.bulkaddrs_val; - for (i=0; icellName, AFSCONF_VLDBSERVICE, - &info); - if (code) { - fprintf(STDERR, "vsu_ClientInit: can't find cell %s's hosts in %s/%s\n", - cellName, AFSDIR_SERVER_ETC_DIRPATH,AFSDIR_CELLSERVDB_FILE); - exit(1); - } - } - else { /* not -localauth */ - tdir = afsconf_Open(confDir); - if (!tdir) { - fprintf(STDERR, "vsu_ClientInit: Could not process files in configuration directory (%s).\n", - confDir); - return -1; - } - - if (!cellName) { - code = afsconf_GetLocalCell(tdir, cellstr, sizeof(cellstr)); - if (code) { - fprintf(STDERR, "vsu_ClientInit: can't get local cellname, check %s/%s\n", - confDir, AFSDIR_THISCELL_FILE); - exit(1); - } - cellName = cellstr; - } - - code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, &info); - if (code) { - fprintf(STDERR, "vsu_ClientInit: can't find cell %s's hosts in %s/%s\n", - cellName, confDir,AFSDIR_CELLSERVDB_FILE); - exit(1); - } - if (noAuthFlag) /* -noauth */ - scIndex = 0; - else { /* not -noauth */ - strcpy(sname.cell, info.name); - sname.instance[0] = 0; - strcpy(sname.name, "afs"); - code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0); - if (code) { /* did not get ticket */ - fprintf(STDERR, "vsu_ClientInit: Could not get afs tokens, running unauthenticated.\n"); - scIndex = 0; - } - else { /* got a ticket */ - scIndex = 2; - if ((ttoken.kvno < 0) || (ttoken.kvno > 255)) { - fprintf(STDERR, "vsu_ClientInit: funny kvno (%d) in ticket, proceeding\n", - ttoken.kvno); - } - } - } - - switch (scIndex) { - case 0 : - sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject(); - break; - case 2: - sc = (struct rx_securityClass *)rxkad_NewClientSecurityObject( - vsu_rxkad_level, &ttoken.sessionKey, ttoken.kvno, - ttoken.ticketLen, ttoken.ticket); - break; - default: - fprintf(STDERR, "vsu_ClientInit: unsupported security index %d\n", - scIndex); - exit(1); - break; - } + if (sauth) { /* -localauth */ + tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH); + if (!tdir) { + fprintf(STDERR, + "vsu_ClientInit: Could not process files in configuration directory (%s).\n", + AFSDIR_SERVER_ETC_DIRPATH); + return -1; + } + code = afsconf_ClientAuth(tdir, &sc, &scIndex); /* sets sc,scIndex */ + if (code) { + fprintf(STDERR, + "vsu_ClientInit: Could not get security object for -localAuth\n"); + return -1; + } + code = + afsconf_GetCellInfo(tdir, tdir->cellName, AFSCONF_VLDBSERVICE, + &info); + if (code) { + fprintf(STDERR, + "vsu_ClientInit: can't find cell %s's hosts in %s/%s\n", + cellName, AFSDIR_SERVER_ETC_DIRPATH, + AFSDIR_CELLSERVDB_FILE); + exit(1); + } + } else { /* not -localauth */ + tdir = afsconf_Open(confDir); + if (!tdir) { + fprintf(STDERR, + "vsu_ClientInit: Could not process files in configuration directory (%s).\n", + confDir); + return -1; + } + + if (!cellName) { + code = afsconf_GetLocalCell(tdir, cellstr, sizeof(cellstr)); + if (code) { + fprintf(STDERR, + "vsu_ClientInit: can't get local cellname, check %s/%s\n", + confDir, AFSDIR_THISCELL_FILE); + exit(1); + } + cellName = cellstr; + } + + code = + afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, &info); + if (code) { + fprintf(STDERR, + "vsu_ClientInit: can't find cell %s's hosts in %s/%s\n", + cellName, confDir, AFSDIR_CELLSERVDB_FILE); + exit(1); + } + if (noAuthFlag) /* -noauth */ + scIndex = 0; + else { /* not -noauth */ + strcpy(sname.cell, info.name); + sname.instance[0] = 0; + strcpy(sname.name, "afs"); + code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL); + if (code) { /* did not get ticket */ + fprintf(STDERR, + "vsu_ClientInit: Could not get afs tokens, running unauthenticated.\n"); + scIndex = 0; + } else { /* got a ticket */ + scIndex = 2; + if ((ttoken.kvno < 0) || (ttoken.kvno > 255)) { + fprintf(STDERR, + "vsu_ClientInit: funny kvno (%d) in ticket, proceeding\n", + ttoken.kvno); + } + } + } + + switch (scIndex) { + case 0: + sc = rxnull_NewClientSecurityObject(); + break; + case 2: + sc = rxkad_NewClientSecurityObject(vsu_rxkad_level, + &ttoken.sessionKey, + ttoken.kvno, ttoken.ticketLen, + ttoken.ticket); + break; + default: + fprintf(STDERR, "vsu_ClientInit: unsupported security index %d\n", + scIndex); + exit(1); + break; + } } - if (secproc) /* tell UV module about default authentication */ - (*secproc) (sc, scIndex); + afsconf_Close(tdir); + + if (secproc) /* tell UV module about default authentication */ + (*secproc) (sc, scIndex); if (info.numServers > VLDB_MAXSERVERS) { - fprintf(STDERR, "vsu_ClientInit: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", - info.numServers, VLDB_MAXSERVERS); - exit(1); + fprintf(STDERR, + "vsu_ClientInit: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", + info.numServers, VLDB_MAXSERVERS); + exit(1); } - for (i=0; i without readonly or backup suffixes * and return the result as . */ -vsu_ExtractName(rname,name) -char rname[],name[]; -{ char sname[32]; +int +vsu_ExtractName(rname, name) + char rname[], name[]; +{ + char sname[VOLSER_OLDMAXVOLNAME + 1]; int total; - strcpy(sname,name); + strncpy(sname, name, sizeof(sname)); + sname[sizeof(sname) - 1] = '\0'; total = strlen(sname); - if(!strcmp(&sname[total - 9],".readonly")) { + if (!strcmp(&sname[total - 9], ".readonly")) { /*discard the last 8 chars */ sname[total - 9] = '\0'; - strcpy(rname,sname); + strcpy(rname, sname); return 0; - } - else if(!strcmp(&sname[total - 7 ],".backup")) { + } else if (!strcmp(&sname[total - 7], ".backup")) { /*discard last 6 chars */ sname[total - 7] = '\0'; - strcpy(rname,sname); + strcpy(rname, sname); return 0; - } - else { - strncpy(rname,name,VOLSER_OLDMAXVOLNAME); + } else { + strncpy(rname, name, VOLSER_OLDMAXVOLNAME); + rname[VOLSER_OLDMAXVOLNAME] = '\0'; return -1; } } /* returns 0 if failed */ -afs_uint32 vsu_GetVolumeID(astring, acstruct, errp) -struct ubik_client *acstruct; -afs_int32 *errp; -char *astring; { +afs_uint32 +vsu_GetVolumeID(astring, acstruct, errp) + struct ubik_client *acstruct; + afs_int32 *errp; + char *astring; +{ afs_uint32 tc, value; - char *str,*ptr, volname[VOLSER_OLDMAXVOLNAME+1]; + char *str, *ptr, volname[VOLSER_OLDMAXVOLNAME + 1]; int tryname, curval; struct nvldbentry entry; afs_int32 vcode = 0; @@ -561,38 +621,49 @@ char *astring; { str = astring; ptr = astring; tryname = 0; - while (curval = *str++){ - if(curval < '0' || curval > '9') + while ((curval = *str++)) { + if (curval < '0' || curval > '9') tryname = 1; } - if(tryname) { - vsu_ExtractName(volname,astring); + if (tryname) { + vsu_ExtractName(volname, astring); vcode = VLDB_GetEntryByName(volname, &entry); - if(!vcode) { - if(!strcmp(&astring[total - 9],".readonly")) + if (!vcode) { + if (!strcmp(&astring[total - 9], ".readonly")) return entry.volumeId[ROVOL]; - else if ((!strcmp(&astring[total - 7 ],".backup"))) + else if ((!strcmp(&astring[total - 7], ".backup"))) return entry.volumeId[BACKVOL]; else - return (entry.volumeId[RWVOL]); + return (entry.volumeId[RWVOL]); } else { *errp = vcode; - return 0; /* can't find volume */ + return 0; /* can't find volume */ } } value = 0; - while (tc = *astring++) { + while ((tc = *astring++)) { if (tc & 0x80) { - if(!tryname) fprintf(STDERR,"goofed in volid \n"); - else {fprintf(STDERR,"Could not get entry from vldb for %s\n",ptr);PrintError("",vcode);} + if (!tryname) + fprintf(STDERR, "goofed in volid \n"); + else { + fprintf(STDERR, "Could not get entry from vldb for %s\n", + ptr); + PrintError("", vcode); + } *errp = EINVAL; return 0; } - if (tc < '0' || tc > '9'){ - if(!tryname) fprintf(STDERR,"internal error: out of range char in vol ID\n"); - else {fprintf(STDERR,"Could not get entry from vldb for %s\n",ptr);PrintError("",vcode);} + if (tc < '0' || tc > '9') { + if (!tryname) + fprintf(STDERR, + "internal error: out of range char in vol ID\n"); + else { + fprintf(STDERR, "Could not get entry from vldb for %s\n", + ptr); + PrintError("", vcode); + } *errp = ERANGE; return 0; }