Complete removal of DUX client code
[openafs.git] / src / afs / VNOPS / afs_vnop_strategy.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * Implements:
12  * afs_ustrategy
13  */
14
15 #include <afsconfig.h>
16 #include "afs/param.h"
17
18
19 #if !defined(AFS_HPUX_ENV) && !defined(AFS_SGI_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN80_ENV)
20
21 #include "afs/sysincludes.h"    /* Standard vendor system headers */
22 #include "afsincludes.h"        /* Afs-based standard headers */
23 #include "afs/afs_stats.h"      /* statistics */
24 #include "afs/afs_cbqueue.h"
25 #include "afs/nfsclient.h"
26 #include "afs/afs_osidnlc.h"
27
28
29
30 #if defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
31 int afs_ustrategy(register struct buf *abp, afs_ucred_t *credp)
32 #else
33 int afs_ustrategy(register struct buf *abp)
34 #endif
35 {
36     register afs_int32 code;
37     struct uio tuio;
38     struct iovec tiovec[1];
39     register struct vcache *tvc = VTOAFS(abp->b_vp);
40     register afs_int32 len = abp->b_bcount;
41 #ifdef  AFS_AIX41_ENV
42     struct ucred *credp;
43 #elif !defined(AFS_SUN5_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
44     afs_ucred_t *credp = u.u_cred;
45 #endif
46
47     AFS_STATCNT(afs_ustrategy);
48 #ifdef  AFS_AIX41_ENV
49     /*
50      * So that it won't change while reading it
51      */
52     ObtainReadLock(&tvc->lock);
53     if (tvc->credp) {
54         credp = tvc->credp;
55         crhold(credp);
56     } else {
57         credp = crref();
58     }
59     ReleaseReadLock(&tvc->lock);
60     osi_Assert(credp);
61 #endif
62 #ifdef AFS_FBSD50_ENV
63     if (abp->b_iocmd == BIO_READ) {
64 #else
65     if ((abp->b_flags & B_READ) == B_READ) {
66 #endif
67         /* read b_bcount bytes into kernel address b_un.b_addr starting
68          * at byte DEV_BSIZE * b_blkno.  Bzero anything we can't read,
69          * and finally call iodone(abp).  File is in abp->b_vp.  Credentials
70          * are from u area??
71          */
72         tuio.afsio_iov = tiovec;
73         tuio.afsio_iovcnt = 1;
74 #if defined(AFS_SUN5_ENV) || defined(AFS_XBSD_ENV)
75 # ifdef AFS_64BIT_CLIENT
76 #  ifdef AFS_SUN5_ENV
77         tuio.afsio_offset = (afs_offs_t) ldbtob(abp->b_lblkno);
78 #  else
79         tuio.afsio_offset = (afs_offs_t) dbtob(abp->b_blkno);
80 #  endif
81 # else /* AFS_64BIT_CLIENT */
82         tuio.afsio_offset = (u_int) dbtob(abp->b_blkno);
83 # endif /* AFS_64BIT_CLIENT */
84 #else
85         tuio.afsio_offset = DEV_BSIZE * abp->b_blkno;
86 #endif
87         tuio.afsio_seg = AFS_UIOSYS;
88 #ifdef AFS_UIOFMODE
89         tuio.afsio_fmode = 0;
90 #endif
91         tuio.afsio_resid = abp->b_bcount;
92 #if defined(AFS_XBSD_ENV)
93         tiovec[0].iov_base = abp->b_saveaddr;
94 #else
95         tiovec[0].iov_base = abp->b_un.b_addr;
96 #endif /* AFS_XBSD_ENV */
97         tiovec[0].iov_len = abp->b_bcount;
98         /* are user's credentials valid here?  probably, but this
99          * sure seems like the wrong things to do. */
100 #if     defined(AFS_SUN5_ENV)
101         code = afs_nlrdwr(VTOAFS(abp->b_vp), &tuio, UIO_READ, 0, credp);
102 #else
103         code = afs_rdwr(VTOAFS(abp->b_vp), &tuio, UIO_READ, 0, credp);
104 #endif
105         if (code == 0) {
106             if (tuio.afsio_resid > 0)
107 #if defined(AFS_XBSD_ENV)
108                 memset(abp->b_saveaddr + abp->b_bcount - tuio.afsio_resid, 0,
109                        tuio.afsio_resid);
110 #else
111                 memset(abp->b_un.b_addr + abp->b_bcount - tuio.afsio_resid, 0,
112                        tuio.afsio_resid);
113 #endif /* AFS_XBSD_ENV */
114 #ifdef  AFS_AIX32_ENV
115             /*
116              * If we read a block that is past EOF and the user was not storing
117              * to it, go ahead and write protect the page. This way we will detect
118              * storing beyond EOF in the future
119              */
120             if (dbtob(abp->b_blkno) + abp->b_bcount > tvc->f.m.Length) {
121                 if ((abp->b_flags & B_PFSTORE) == 0) {
122                     AFS_GUNLOCK();
123                     vm_protectp(tvc->segid, dbtob(abp->b_blkno) / PAGESIZE,
124                                 abp->b_bcount / PAGESIZE, RDONLY);
125                     AFS_GLOCK();
126                 }
127             }
128 #endif
129         }
130     } else {
131         tuio.afsio_iov = tiovec;
132         tuio.afsio_iovcnt = 1;
133 #if defined(AFS_SUN5_ENV)
134 #ifdef AFS_64BIT_CLIENT
135 #ifdef AFS_SUN5_ENV
136         tuio.afsio_offset = (afs_offs_t) ldbtob(abp->b_lblkno);
137 #else
138         tuio.afsio_offset = (afs_offs_t) dbtob(abp->b_blkno);
139 #endif
140 #else /* AFS_64BIT_CLIENT */
141         tuio.afsio_offset = (u_int) dbtob(abp->b_blkno);
142 #endif /* AFS_64BIT_CLIENT */
143 #ifdef  AFS_SUN5_ENV
144 #ifdef  AFS_SUN59_ENV
145         tuio.uio_limit = curproc->p_fsz_ctl.rlim_cur;
146 #else
147         tuio.uio_limit = u.u_rlimit[RLIMIT_FSIZE].rlim_cur;
148 #endif
149 #endif
150 #else
151         tuio.afsio_offset = DEV_BSIZE * abp->b_blkno;
152 #endif
153         tuio.afsio_seg = AFS_UIOSYS;
154 #ifdef AFS_UIOFMODE
155         tuio.afsio_fmode = 0;
156 #endif
157 #ifdef  AFS_AIX32_ENV
158         /*
159          * XXX It this really right? Ideally we should always write block size multiple
160          * and not any arbitrary size, right? XXX
161          */
162         len = MIN(len, tvc->f.m.Length - dbtob(abp->b_blkno));
163 #endif
164         tuio.afsio_resid = len;
165 #if defined(AFS_XBSD_ENV)
166         tiovec[0].iov_base = abp->b_saveaddr;
167 #else
168         tiovec[0].iov_base = abp->b_un.b_addr;
169 #endif /* AFS_XBSD_ENV */
170         tiovec[0].iov_len = len;
171         /* are user's credentials valid here?  probably, but this
172          * sure seems like the wrong things to do. */
173 #if     defined(AFS_SUN5_ENV)
174         code = afs_nlrdwr(VTOAFS(abp->b_vp), &tuio, UIO_WRITE, 0, credp);
175 #else
176         code = afs_rdwr(VTOAFS(abp->b_vp), &tuio, UIO_WRITE, 0, credp);
177 #endif
178     }
179
180 #if defined (AFS_XBSD_ENV)
181     if (code) {
182         abp->b_error = code;
183 #if !defined(AFS_FBSD50_ENV)
184         abp->b_flags |= B_ERROR;
185 #endif
186     }
187 #endif
188
189 #if defined(AFS_AIX32_ENV)
190     crfree(credp);
191 #elif defined(AFS_FBSD60_ENV)
192     (*abp->b_iodone)(abp);
193 #elif defined(AFS_FBSD50_ENV)
194     biodone(&abp->b_io);
195 #elif defined(AFS_XBSD_ENV)
196     biodone(abp);
197 #elif !defined(AFS_SUN5_ENV)
198     iodone(abp);
199 #endif
200
201     afs_Trace3(afs_iclSetp, CM_TRACE_STRATEGYDONE, ICL_TYPE_POINTER, tvc,
202                ICL_TYPE_INT32, code, ICL_TYPE_LONG, tuio.afsio_resid);
203     return code;
204 }
205
206 #endif /* !AFS_HPUX_ENV  && !AFS_SGI_ENV && !AFS_LINUX20_ENV */