2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * osi_vfsops.c for IRIX
13 #include <afsconfig.h>
14 #include "afs/param.h"
19 #include "afs/sysincludes.h" /* Standard vendor system headers */
20 #include "afsincludes.h" /* Afs-based standard headers */
21 #include "afs/afs_stats.h" /* statistics stuff */
22 #include "sys/syssgi.h"
25 struct vfs *afs_globalVFS = 0;
26 struct vcache *afs_globalVp = 0;
28 #ifdef AFS_SGI_VNODE_GLUE
29 #include <sys/invent.h>
31 mutex_t afs_init_kern_lock;
35 #define SYS_setgroups SGI_SETGROUPS
37 int (*nfs_rfsdisptab_v2) () = NULL;
42 #include "sys/mload.h"
43 char *Afs_mversion = M_VERSION;
45 extern int (*setgroupsp) (int, gid_t *);
46 extern struct afs_lock afs_xvcache;
47 extern int idbg_afsuser();
48 extern void afs_mpservice(void *);
51 * AFS fs initialization - we also plug system calls here
53 #define NewSystemCall(n,f,a) \
54 syscallsw[ABI_IRIX5].sc_sysent[(n)-1000].sy_narg = a; \
55 syscallsw[ABI_IRIX5].sc_sysent[(n)-1000].sy_call = f; \
56 syscallsw[ABI_IRIX5].sc_sysent[(n)-1000].sy_flags = 0;
57 extern struct vfsops Afs_vfsops, *afs_vfsopsp;
58 extern struct vnodeops Afs_vnodeops, *afs_vnodeopsp;
59 extern void (*afsidestroyp) (struct inode *);
60 extern void (*afsdptoipp) (struct efs_dinode *, struct inode *);
61 extern void (*afsiptodpp) (struct inode *, struct efs_dinode *);
62 extern void afsidestroy(struct inode *);
63 extern void afsdptoip(struct efs_dinode *, struct inode *);
64 extern void afsiptodp(struct inode *, struct efs_dinode *);
65 extern int (*idbg_prafsnodep) (vnode_t *);
66 extern int (*idbg_afsvfslistp) (void);
67 extern int idbg_prafsnode(vnode_t *);
68 extern int idbg_afsvfslist(void);
72 Afs_init(struct vfssw *vswp, int fstype)
74 extern int Afs_syscall(), Afs_xsetgroups(), afs_pioctl(), afs_setpag();
75 extern int icreate(), iopen(), iinc(), idec();
76 #ifdef AFS_SGI_XFS_IOPS_ENV
79 extern int iread(), iwrite();
86 #ifdef AFS_SGI_VNODE_GLUE
87 /* Synchronize doing NUMA test. */
88 mutex_init(&afs_init_kern_lock, MUTEX_DEFAULT, "init_kern_lock");
91 * set up pointers from main kernel into us
93 afs_vnodeopsp = &Afs_vnodeops;
94 afs_vfsopsp = &Afs_vfsops;
95 afsidestroyp = afsidestroy;
96 afsiptodpp = afsiptodp;
97 afsdptoipp = afsdptoip;
98 idbg_prafsnodep = idbg_prafsnode;
99 idbg_afsvfslistp = idbg_afsvfslist;
100 NewSystemCall(AFS_SYSCALL, Afs_syscall, 6);
101 NewSystemCall(AFS_PIOCTL, afs_pioctl, 4);
102 NewSystemCall(AFS_SETPAG, afs_setpag, 0);
103 NewSystemCall(AFS_IOPEN, iopen, 3);
104 NewSystemCall(AFS_ICREATE, icreate, 6);
105 NewSystemCall(AFS_IINC, iinc, 3);
106 NewSystemCall(AFS_IDEC, idec, 3);
107 #ifdef AFS_SGI_XFS_IOPS_ENV
108 NewSystemCall(AFS_IOPEN64, iopen64, 4);
110 NewSystemCall(AFS_IREAD, iread, 6);
111 NewSystemCall(AFS_IWRITE, iwrite, 6);
114 /* last replace these */
115 setgroupsp = Afs_xsetgroups;
117 idbg_addfunc("afsuser", idbg_afsuser);
122 extern int afs_mount(), afs_unmount(), afs_root(), afs_statfs();
124 extern int afs_sync(OSI_VFS_DECL(afsp), int flags, struct cred *cr);
126 extern int afs_sync(OSI_VFS_DECL(afsp), short flags, struct cred *cr);
128 extern int afs_vget(OSI_VFS_DECL(afsp), vnode_t ** vpp, struct fid *afidp);
130 struct vfsops afs_lockedvfsops =
132 struct vfsops Afs_vfsops =
137 BHV_IDENTITY_INIT_POSITION(VFS_POSITION_BASE),
144 fs_nosys, /* rootinit */
145 fs_nosys, /* mntupdate */
153 fs_nosys, /* mountroot */
155 fs_nosys, /* realvfsops */
156 fs_import, /* import */
157 fs_nosys, /* quotactl */
159 fs_nosys, /* swapvp */
162 extern struct afs_q VLRU; /*vcache LRU */
165 static bhv_desc_t afs_vfs_bhv;
167 afs_mount(struct vfs *afsp, vnode_t * mvp, struct mounta *uap,
173 AFS_STATCNT(afs_mount);
178 if (mvp->v_type != VDIR)
181 if (afs_globalVFS) { /* Don't allow remounts. */
185 afs_globalVFS = afsp;
186 afsp->vfs_bsize = 8192;
187 afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */
188 afsp->vfs_fsid.val[1] = afs_fstype;
190 vfs_insertbhv(afsp, &afs_vfs_bhv, &Afs_vfsops, &afs_vfs_bhv);
192 afsp->vfs_data = NULL;
194 afsp->vfs_fstype = afs_fstype;
195 afsp->vfs_dev = 0xbabebabe; /* XXX this should be unique */
197 #ifndef AFS_NONFSTRANS
198 if (nfs_rfsdisptab_v2)
199 afs_xlatorinit_v2(nfs_rfsdisptab_v2);
205 afs_unmount(OSI_VFS_ARG(afsp), flags, cr)
210 extern int afs_afs_cold_shutdown;
212 vnode_t *vp, *rootvp = NULL;
213 register struct afs_q *tq;
216 OSI_VFS_CONVERT(afsp)
218 AFS_STATCNT(afs_unmount);
224 * flush all pages from inactive vnodes - return
225 * EBUSY if any still in use
227 ObtainWriteLock(&afs_xvcache, 172);
228 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
231 vp = (vnode_t *) tvc;
232 if (error = afs_FlushVCache(tvc, &fv_slept))
233 if (vp->v_flag & VROOT) {
237 ReleaseWriteLock(&afs_xvcache);
243 * rootvp gets lots of ref counts
246 tvc = VTOAFS(rootvp);
247 if (tvc->opens || CheckLock(&tvc->lock) || LockWaiters(&tvc->lock)) {
248 ReleaseWriteLock(&afs_xvcache);
251 ReleaseWriteLock(&afs_xvcache);
254 ObtainWriteLock(&afs_xvcache, 173);
255 afs_FlushVCache(tvc, &fv_slept);
257 ReleaseWriteLock(&afs_xvcache);
261 VFS_REMOVEBHV(afsp, &afs_vfs_bhv);
268 afs_root(OSI_VFS_ARG(afsp), avpp)
272 register afs_int32 code = 0;
273 struct vrequest treq;
274 register struct vcache *tvp = 0;
275 OSI_VFS_CONVERT(afsp)
277 AFS_STATCNT(afs_root);
278 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
282 afs_PutVCache(afs_globalVp);
286 if (!(code = afs_InitReq(&treq, OSI_GET_CURRENT_CRED()))
287 && !(code = afs_CheckInit())) {
288 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
289 /* we really want this to stay around */
298 VN_HOLD(AFSTOV(tvp));
299 s = VN_LOCK(AFSTOV(tvp));
300 AFSTOV(tvp)->v_flag |= VROOT;
301 VN_UNLOCK(AFSTOV(tvp), s);
303 afs_globalVFS = afsp;
307 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
308 ICL_TYPE_INT32, code);
312 afs_statfs(OSI_VFS_ARG(afsp), abp, avp)
315 struct vnode *avp; /* unused */
317 OSI_VFS_CONVERT(afsp)
319 AFS_STATCNT(afs_statfs);
320 abp->f_bsize = afsp->vfs_bsize;
321 abp->f_frsize = afsp->vfs_bsize;
322 /* Fake a high number below to satisfy programs that use the statfs
323 * call to make sure that there's enough space in the device partition
324 * before storing something there.
326 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
327 abp->f_ffree = abp->f_favail = 900000;
329 abp->f_fsid = AFS_VFSMAGIC; /* magic */
330 strcpy(abp->f_basetype, AFS_MOUNT_AFS);
332 abp->f_namemax = 256;
339 * sync's responsibilities include pushing back DELWRI pages
340 * Things to watch out for:
341 * 1) don't want to hold off new vnodes in the file system
342 * while pushing back pages
343 * 2) since we can deal with un-referenced vndoes need to watch
344 * races with folks who recycle vnodes
346 * SYNC_BDFLUSH - do NOT sleep waiting for an inode - also, when
347 * when pushing DELWRI - only push old ones.
348 * SYNC_PDFLUSH - push v_dpages.
349 * SYNC_ATTR - sync attributes - note that ordering considerations
350 * dictate that we also flush dirty pages
351 * SYNC_WAIT - do synchronouse writes - inode & delwri
352 * SYNC_NOWAIT - start delayed writes.
353 * SYNC_DELWRI - look at inodes w/ delwri pages. Other flags
354 * decide how to deal with them.
355 * SYNC_CLOSE - flush delwri and invalidate others.
356 * SYNC_FSDATA - push fs data (e.g. superblocks)
359 extern afs_int32 vcachegen;
360 #define PREEMPT_MASK 0x7f
366 afs_sync(OSI_VFS_DECL(afsp),
374 /* Why enable the vfs sync operation?? */
375 int error, lasterr, preempt;
378 afs_uint32 lvcachegen;
379 register struct afs_q *tq;
382 OSI_VFS_CONVERT(afsp)
386 * if not interested in vnodes, skip all this
389 if ((flags & (SYNC_CLOSE | SYNC_DELWRI | SYNC_PDFLUSH)) == 0)
391 #else /* AFS_SGI61_ENV */
392 if ((flags & (SYNC_CLOSE | SYNC_DELWRI | SYNC_ATTR)) == 0)
394 #endif /* AFS_SGI61_ENV */
396 ObtainReadLock(&afs_xvcache);
397 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
400 vp = (vnode_t *) tvc;
402 * Since we push all dirty pages on last close/VOP_INACTIVE
403 * we are only concerned with vnodes with
404 * active reference counts.
407 if (vp->v_count == 0) {
411 if ((flags & SYNC_CLOSE) == 0 && !AFS_VN_DIRTY(vp)) {
417 * ignore vnodes which need no flushing
419 if (flags & SYNC_DELWRI) {
420 if (!AFS_VN_DIRTY(vp)) {
426 else if (flags & SYNC_PDFLUSH) {
427 if (!VN_GET_DPAGES(vp)) {
432 #endif /* AFS_SGI61_ENV */
436 lvcachegen = vcachegen;
437 ReleaseReadLock(&afs_xvcache);
440 * Try to lock rwlock without sleeping. If we can't, we must
443 if (afs_rwlock_nowait(vp, 1) == 0) {
445 if (flags & (SYNC_BDFLUSH | SYNC_PDFLUSH))
446 #else /* AFS_SGI61_ENV */
447 if (flags & SYNC_BDFLUSH)
448 #endif /* AFS_SGI61_ENV */
451 ObtainReadLock(&afs_xvcache);
452 if (vcachegen != lvcachegen) {
453 ReleaseReadLock(&afs_xvcache);
458 AFS_RWLOCK(vp, VRWLOCK_WRITE);
462 if (flags & SYNC_CLOSE) {
463 PFLUSHINVALVP(vp, (off_t) 0, (off_t) tvc->m.Length);
466 else if (flags & SYNC_PDFLUSH) {
467 if (VN_GET_DPAGES(vp)) {
468 pdflush(vp, B_ASYNC);
471 #endif /* AFS_SGI61_ENV */
474 if ((flags & SYNC_DELWRI) && AFS_VN_DIRTY(vp)) {
476 PFLUSHVP(vp, (off_t) tvc->m.Length,
477 (flags & SYNC_WAIT) ? 0 : B_ASYNC, error);
478 #else /* AFS_SGI61_ENV */
479 if (flags & SYNC_WAIT)
480 /* push all and wait */
481 PFLUSHVP(vp, (off_t) tvc->m.Length, (off_t) 0, error);
482 else if (flags & SYNC_BDFLUSH) {
484 error = pdflush(vp, B_ASYNC);
486 /* push all but don't wait */
487 PFLUSHVP(vp, (off_t) tvc->m.Length, (off_t) B_ASYNC, error);
489 #endif /* AFS_SGI61_ENV */
493 * Release vp, check error and whether to preempt, and if
494 * we let go of xvcache lock and someone has changed the
495 * VLRU, restart the loop
498 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
502 if ((++preempt & PREEMPT_MASK) == 0) {
507 ObtainReadLock(&afs_xvcache);
508 if (vcachegen != lvcachegen) {
509 ReleaseReadLock(&afs_xvcache);
513 ReleaseReadLock(&afs_xvcache);
519 afs_vget(OSI_VFS_DECL(afsp), vnode_t ** avcp, struct fid * fidp)
521 struct VenusFid vfid;
522 struct vrequest treq;
523 register struct cell *tcell;
524 register afs_int32 code = 0;
527 #if defined(AFS_SGI64_ENV) && defined(CKPT) && !defined(_R5000_CVT_WAR)
531 OSI_VFS_CONVERT(afsp)
533 AFS_STATCNT(afs_vget);
537 #if defined(AFS_SGI64_ENV) && defined(CKPT) && !defined(_R5000_CVT_WAR)
538 afid2 = (afs_fid2_t *) fidp;
539 if (afid2->af_len == sizeof(afs_fid2_t) - sizeof(afid2->af_len)) {
540 /* It's a checkpoint restart fid. */
541 tcell = afs_GetCellByIndex(afid2->af_cell, READ_LOCK);
546 vfid.Cell = tcell->cellNum;
547 afs_PutCell(tcell, READ_LOCK);
548 vfid.Fid.Volume = afid2->af_volid;
549 vfid.Fid.Vnode = afid2->af_vno;
550 vfid.Fid.Unique = afid2->af_uniq;
552 if (code = afs_InitReq(&treq, OSI_GET_CURRENT_CRED()))
555 (vnode_t *) afs_GetVCache(&vfid, &treq, NULL, (struct vcache *)0);
563 if (code = afs_InitReq(&treq, OSI_GET_CURRENT_CRED()))
565 code = afs_osi_vget((struct vcache **)avcp, fidp, &treq);
568 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
569 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, &vfid);
570 code = afs_CheckCode(code, &treq, 42);
575 #ifdef MP /* locked versions of vfs operations. */
577 /* wrappers for vfs calls */
579 #define AFS_MP_VFS_ARG(A) bhv_desc_t A
581 #define AFS_MP_VFS_ARG(A) struct vfs A
585 mp_afs_mount(struct vfs *a, struct vnode *b, struct mounta *c,
593 rv = afs_lockedvfsops.vfs_mount(a, b, c, d
603 mp_afs_unmount(AFS_MP_VFS_ARG(*a), int b, struct cred *c)
607 rv = afs_lockedvfsops.vfs_unmount(a, b, c);
613 mp_afs_root(AFS_MP_VFS_ARG(*a), struct vnode **b)
617 rv = afs_lockedvfsops.vfs_root(a, b);
623 mp_afs_statvfs(AFS_MP_VFS_ARG(*a), struct statvfs *b, struct vnode *c)
627 rv = afs_lockedvfsops.vfs_statvfs(a, b, c);
633 mp_afs_sync(AFS_MP_VFS_ARG(*a),
643 rv = afs_lockedvfsops.vfs_sync(a, b, c);
649 mp_afs_vget(AFS_MP_VFS_ARG(*a), struct vnode **b, struct fid *c)
653 rv = afs_lockedvfsops.vfs_vget(a, b, c);
658 struct vfsops Afs_vfsops = {
661 BHV_IDENTITY_INIT_POSITION(VFS_POSITION_BASE),
668 fs_nosys, /* rootinit */
669 fs_nosys, /* mntupdate */
677 fs_nosys, /* mountroot */
679 fs_nosys, /* realvfsops */
680 fs_import, /* import */
681 fs_nosys, /* quotactl */
683 fs_nosys, /* swapvp */