The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/nwfs/nwfs_io.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1999, Boris Popov
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *    This product includes software developed by Boris Popov.
   16  * 4. Neither the name of the author nor the names of any co-contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  *
   32  * $FreeBSD: releng/6.0/sys/fs/nwfs/nwfs_io.c 143513 2005-03-13 12:18:25Z jeff $
   33  *
   34  */
   35 #include <sys/param.h>
   36 #include <sys/systm.h>
   37 #include <sys/resourcevar.h>    /* defines plimit structure in proc struct */
   38 #include <sys/kernel.h>
   39 #include <sys/bio.h>
   40 #include <sys/buf.h>
   41 #include <sys/proc.h>
   42 #include <sys/mount.h>
   43 #include <sys/namei.h>
   44 #include <sys/vnode.h>
   45 #include <sys/dirent.h>
   46 #include <sys/signalvar.h>
   47 #include <sys/sysctl.h>
   48 
   49 #include <vm/vm.h>
   50 #include <vm/vm_page.h>
   51 #include <vm/vm_extern.h>
   52 #include <vm/vm_object.h>
   53 #include <vm/vm_pager.h>
   54 #include <vm/vnode_pager.h>
   55 
   56 #include <netncp/ncp.h>
   57 #include <netncp/ncp_conn.h>
   58 #include <netncp/ncp_subr.h>
   59 #include <netncp/ncp_ncp.h>
   60 
   61 #include <fs/nwfs/nwfs.h>
   62 #include <fs/nwfs/nwfs_node.h>
   63 #include <fs/nwfs/nwfs_subr.h>
   64 
   65 static int nwfs_fastlookup = 1;
   66 
   67 SYSCTL_DECL(_vfs_nwfs);
   68 SYSCTL_INT(_vfs_nwfs, OID_AUTO, fastlookup, CTLFLAG_RW, &nwfs_fastlookup, 0, "");
   69 
   70 
   71 extern int nwfs_pbuf_freecnt;
   72 
   73 #define DE_SIZE (sizeof(struct dirent))
   74 #define NWFS_RWCACHE
   75 
   76 static int
   77 nwfs_readvdir(struct vnode *vp, struct uio *uio, struct ucred *cred) {
   78         struct nwmount *nmp = VTONWFS(vp);
   79         int error, count, i;
   80         struct dirent dp;
   81         struct nwnode *np = VTONW(vp);
   82         struct nw_entry_info fattr;
   83         struct vnode *newvp;
   84         struct componentname cn;
   85         ncpfid fid;
   86 
   87         np = VTONW(vp);
   88         NCPVNDEBUG("dirname='%s'\n",np->n_name);
   89         if (uio->uio_resid < DE_SIZE || (uio->uio_offset < 0))
   90                 return (EINVAL);
   91         error = 0;
   92         count = 0;
   93         i = uio->uio_offset / DE_SIZE; /* offset in directory */
   94         if (i == 0) {
   95                 error = ncp_initsearch(vp, uio->uio_td, cred);
   96                 if (error) {
   97                         NCPVNDEBUG("cannot initialize search, error=%d",error);
   98                         return( error );
   99                 }
  100         }
  101 
  102         for (; uio->uio_resid >= DE_SIZE; i++) {
  103                 bzero((char *) &dp, DE_SIZE);
  104                 dp.d_reclen = DE_SIZE;
  105                 switch (i) {
  106                     case 0:             /* `.' */
  107                     case 1:             /* `..' */
  108                         dp.d_fileno = (i == 0) ? np->n_fid.f_id : np->n_parent.f_id;
  109                         if (!dp.d_fileno) dp.d_fileno = NWFS_ROOT_INO;
  110                         dp.d_namlen = i + 1;
  111                         dp.d_name[0] = '.';
  112                         dp.d_name[1] = '.';
  113                         dp.d_name[i + 1] = '\0';
  114                         dp.d_type = DT_DIR;
  115                         break;
  116                     default:
  117                         error = ncp_search_for_file_or_subdir(nmp, &np->n_seq, &fattr, uio->uio_td, cred);
  118                         if (error && error < 0x80) break;
  119                         dp.d_fileno = fattr.dirEntNum;
  120                         dp.d_type = (fattr.attributes & aDIR) ? DT_DIR : DT_REG;
  121                         dp.d_namlen = fattr.nameLen;
  122                         bcopy(fattr.entryName, dp.d_name, dp.d_namlen);
  123                         dp.d_name[dp.d_namlen] = '\0';
  124 #if 0
  125                         if (error && eofflag) {
  126                         /*      *eofflag = 1;*/
  127                                 break;
  128                         }
  129 #endif
  130                         break;
  131                 }
  132                 if (nwfs_fastlookup && !error && i > 1) {
  133                         fid.f_id = fattr.dirEntNum;
  134                         fid.f_parent = np->n_fid.f_id;
  135                         error = nwfs_nget(vp->v_mount, fid, &fattr, vp, &newvp);
  136                         if (!error) {
  137                                 VTONW(newvp)->n_ctime = VTONW(newvp)->n_vattr.va_ctime.tv_sec;
  138                                 cn.cn_nameptr = dp.d_name;
  139                                 cn.cn_namelen = dp.d_namlen;
  140                                 cache_enter(vp, newvp, &cn);
  141                                 vput(newvp);
  142                         } else
  143                                 error = 0;
  144                 }
  145                 if (error >= 0x80) {
  146                     error = 0;
  147                     break;
  148                 }
  149                 if ((error = uiomove(&dp, DE_SIZE, uio)))
  150                         break;
  151         }
  152 
  153         uio->uio_offset = i * DE_SIZE;
  154         return (error);
  155 }
  156 
  157 int
  158 nwfs_readvnode(struct vnode *vp, struct uio *uiop, struct ucred *cred) {
  159         struct nwmount *nmp = VFSTONWFS(vp->v_mount);
  160         struct nwnode *np = VTONW(vp);
  161         struct thread *td;
  162         struct vattr vattr;
  163         int error, biosize;
  164 
  165         if (vp->v_type != VREG && vp->v_type != VDIR) {
  166                 printf("%s: vn types other than VREG or VDIR are unsupported !\n",__func__);
  167                 return EIO;
  168         }
  169         if (uiop->uio_resid == 0) return 0;
  170         if (uiop->uio_offset < 0) return EINVAL;
  171 /*      if (uiop->uio_offset + uiop->uio_resid > nmp->nm_maxfilesize)
  172                 return (EFBIG);*/
  173         td = uiop->uio_td;
  174         if (vp->v_type == VDIR) {
  175                 error = nwfs_readvdir(vp, uiop, cred);
  176                 return error;
  177         }
  178         biosize = NWFSTOCONN(nmp)->buffer_size;
  179         if (np->n_flag & NMODIFIED) {
  180                 nwfs_attr_cacheremove(vp);
  181                 error = VOP_GETATTR(vp, &vattr, cred, td);
  182                 if (error) return (error);
  183                 np->n_mtime = vattr.va_mtime.tv_sec;
  184         } else {
  185                 error = VOP_GETATTR(vp, &vattr, cred, td);
  186                 if (error) return (error);
  187                 if (np->n_mtime != vattr.va_mtime.tv_sec) {
  188                         error = nwfs_vinvalbuf(vp, td);
  189                         if (error) return (error);
  190                         np->n_mtime = vattr.va_mtime.tv_sec;
  191                 }
  192         }
  193         error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, uiop, cred);
  194         return (error);
  195 }
  196 
  197 int
  198 nwfs_writevnode(vp, uiop, cred, ioflag)
  199         struct vnode *vp;
  200         struct uio *uiop;
  201         struct ucred *cred;
  202         int ioflag;
  203 {
  204         struct nwmount *nmp = VTONWFS(vp);
  205         struct nwnode *np = VTONW(vp);
  206         struct thread *td;
  207 /*      struct vattr vattr;*/
  208         int error = 0;
  209 
  210         if (vp->v_type != VREG) {
  211                 printf("%s: vn types other than VREG unsupported !\n",__func__);
  212                 return EIO;
  213         }
  214         NCPVNDEBUG("ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
  215         if (uiop->uio_offset < 0) return EINVAL;
  216 /*      if (uiop->uio_offset + uiop->uio_resid > nmp->nm_maxfilesize)
  217                 return (EFBIG);*/
  218         td = uiop->uio_td;
  219         if (ioflag & (IO_APPEND | IO_SYNC)) {
  220                 if (np->n_flag & NMODIFIED) {
  221                         nwfs_attr_cacheremove(vp);
  222                         error = nwfs_vinvalbuf(vp, td);
  223                         if (error) return (error);
  224                 }
  225                 if (ioflag & IO_APPEND) {
  226                 /* We can relay only on local information about file size,
  227                  * because until file is closed NetWare will not return
  228                  * the correct size. */
  229 #if notyet
  230                         nwfs_attr_cacheremove(vp);
  231                         error = VOP_GETATTR(vp, &vattr, cred, td);
  232                         if (error) return (error);
  233 #endif
  234                         uiop->uio_offset = np->n_size;
  235                 }
  236         }
  237         if (uiop->uio_resid == 0) return 0;
  238         if (td != NULL) {
  239                 PROC_LOCK(td->td_proc);
  240                 if  (uiop->uio_offset + uiop->uio_resid >
  241                     lim_cur(td->td_proc, RLIMIT_FSIZE)) {
  242                         psignal(td->td_proc, SIGXFSZ);
  243                         PROC_UNLOCK(td->td_proc);
  244                         return (EFBIG);
  245                 }
  246                 PROC_UNLOCK(td->td_proc);
  247         }
  248         error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cred);
  249         NCPVNDEBUG("after: ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
  250         if (!error) {
  251                 if (uiop->uio_offset > np->n_size) {
  252                         np->n_vattr.va_size = np->n_size = uiop->uio_offset;
  253                         vnode_pager_setsize(vp, np->n_size);
  254                 }
  255         }
  256         return (error);
  257 }
  258 
  259 /*
  260  * Do an I/O operation to/from a cache block.
  261  */
  262 int
  263 nwfs_doio(vp, bp, cr, td)
  264         struct vnode *vp;
  265         struct buf *bp;
  266         struct ucred *cr;
  267         struct thread *td;
  268 {
  269         struct uio *uiop;
  270         struct nwnode *np;
  271         struct nwmount *nmp;
  272         int error = 0;
  273         struct uio uio;
  274         struct iovec io;
  275 
  276         np = VTONW(vp);
  277         nmp = VFSTONWFS(vp->v_mount);
  278         uiop = &uio;
  279         uiop->uio_iov = &io;
  280         uiop->uio_iovcnt = 1;
  281         uiop->uio_segflg = UIO_SYSSPACE;
  282         uiop->uio_td = td;
  283         if (bp->b_iocmd == BIO_READ) {
  284             io.iov_len = uiop->uio_resid = bp->b_bcount;
  285             io.iov_base = bp->b_data;
  286             uiop->uio_rw = UIO_READ;
  287             switch (vp->v_type) {
  288               case VREG:
  289                 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE;
  290                 error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, uiop, cr);
  291                 if (error)
  292                         break;
  293                 if (uiop->uio_resid) {
  294                         int left = uiop->uio_resid;
  295                         int nread = bp->b_bcount - left;
  296                         if (left > 0)
  297                             bzero((char *)bp->b_data + nread, left);
  298                 }
  299                 break;
  300 /*          case VDIR:
  301                 nfsstats.readdir_bios++;
  302                 uiop->uio_offset = ((u_quad_t)bp->b_lblkno) * NFS_DIRBLKSIZ;
  303                 if (nmp->nm_flag & NFSMNT_RDIRPLUS) {
  304                         error = nfs_readdirplusrpc(vp, uiop, cr);
  305                         if (error == NFSERR_NOTSUPP)
  306                                 nmp->nm_flag &= ~NFSMNT_RDIRPLUS;
  307                 }
  308                 if ((nmp->nm_flag & NFSMNT_RDIRPLUS) == 0)
  309                         error = nfs_readdirrpc(vp, uiop, cr);
  310                 if (error == 0 && uiop->uio_resid == bp->b_bcount)
  311                         bp->b_flags |= B_INVAL;
  312                 break;
  313 */
  314             default:
  315                 printf("nwfs_doio:  type %x unexpected\n",vp->v_type);
  316                 break;
  317             };
  318             if (error) {
  319                 bp->b_ioflags |= BIO_ERROR;
  320                 bp->b_error = error;
  321             }
  322         } else { /* write */
  323             if (((bp->b_blkno * DEV_BSIZE) + bp->b_dirtyend) > np->n_size)
  324                 bp->b_dirtyend = np->n_size - (bp->b_blkno * DEV_BSIZE);
  325 
  326             if (bp->b_dirtyend > bp->b_dirtyoff) {
  327                 io.iov_len = uiop->uio_resid = bp->b_dirtyend - bp->b_dirtyoff;
  328                 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE + bp->b_dirtyoff;
  329                 io.iov_base = (char *)bp->b_data + bp->b_dirtyoff;
  330                 uiop->uio_rw = UIO_WRITE;
  331                 error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cr);
  332 
  333                 /*
  334                  * For an interrupted write, the buffer is still valid
  335                  * and the write hasn't been pushed to the server yet,
  336                  * so we can't set BIO_ERROR and report the interruption
  337                  * by setting B_EINTR. For the B_ASYNC case, B_EINTR
  338                  * is not relevant, so the rpc attempt is essentially
  339                  * a noop.  For the case of a V3 write rpc not being
  340                  * committed to stable storage, the block is still
  341                  * dirty and requires either a commit rpc or another
  342                  * write rpc with iomode == NFSV3WRITE_FILESYNC before
  343                  * the block is reused. This is indicated by setting
  344                  * the B_DELWRI and B_NEEDCOMMIT flags.
  345                  */
  346                 if (error == EINTR
  347                     || (!error && (bp->b_flags & B_NEEDCOMMIT))) {
  348                         int s;
  349 
  350                         s = splbio();
  351                         bp->b_flags &= ~(B_INVAL|B_NOCACHE);
  352                         if ((bp->b_flags & B_ASYNC) == 0)
  353                             bp->b_flags |= B_EINTR;
  354                         if ((bp->b_flags & B_PAGING) == 0) {
  355                             bdirty(bp);
  356                             bp->b_flags &= ~B_DONE;
  357                         }
  358                         if ((bp->b_flags & B_ASYNC) == 0)
  359                             bp->b_flags |= B_EINTR;
  360                         splx(s);
  361                 } else {
  362                         if (error) {
  363                                 bp->b_ioflags |= BIO_ERROR;
  364                                 bp->b_error /*= np->n_error */= error;
  365 /*                              np->n_flag |= NWRITEERR;*/
  366                         }
  367                         bp->b_dirtyoff = bp->b_dirtyend = 0;
  368                 }
  369             } else {
  370                 bp->b_resid = 0;
  371                 bufdone(bp);
  372                 return (0);
  373             }
  374         }
  375         bp->b_resid = uiop->uio_resid;
  376         bufdone(bp);
  377         return (error);
  378 }
  379 
  380 /*
  381  * Vnode op for VM getpages.
  382  * Wish wish .... get rid from multiple IO routines
  383  */
  384 int
  385 nwfs_getpages(ap)
  386         struct vop_getpages_args /* {
  387                 struct vnode *a_vp;
  388                 vm_page_t *a_m;
  389                 int a_count;
  390                 int a_reqpage;
  391                 vm_ooffset_t a_offset;
  392         } */ *ap;
  393 {
  394 #ifndef NWFS_RWCACHE
  395         return vop_stdgetpages(ap);(ap->a_vp, ap->a_m, ap->a_count,
  396 #else
  397         int i, error, nextoff, size, toff, npages, count;
  398         struct uio uio;
  399         struct iovec iov;
  400         vm_offset_t kva;
  401         struct buf *bp;
  402         struct vnode *vp;
  403         struct thread *td;
  404         struct ucred *cred;
  405         struct nwmount *nmp;
  406         struct nwnode *np;
  407         vm_object_t object;
  408         vm_page_t *pages;
  409 
  410         vp = ap->a_vp;
  411         td = curthread;                 /* XXX */
  412         cred = td->td_ucred;            /* XXX */
  413         np = VTONW(vp);
  414         nmp = VFSTONWFS(vp->v_mount);
  415         pages = ap->a_m;
  416         count = ap->a_count;
  417 
  418         if ((object = vp->v_object) == NULL) {
  419                 printf("nwfs_getpages: called with non-merged cache vnode??\n");
  420                 return VM_PAGER_ERROR;
  421         }
  422 
  423         bp = getpbuf(&nwfs_pbuf_freecnt);
  424         npages = btoc(count);
  425         kva = (vm_offset_t) bp->b_data;
  426         pmap_qenter(kva, pages, npages);
  427 
  428         iov.iov_base = (caddr_t) kva;
  429         iov.iov_len = count;
  430         uio.uio_iov = &iov;
  431         uio.uio_iovcnt = 1;
  432         uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
  433         uio.uio_resid = count;
  434         uio.uio_segflg = UIO_SYSSPACE;
  435         uio.uio_rw = UIO_READ;
  436         uio.uio_td = td;
  437 
  438         error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, &uio,cred);
  439         pmap_qremove(kva, npages);
  440 
  441         relpbuf(bp, &nwfs_pbuf_freecnt);
  442 
  443         VM_OBJECT_LOCK(object);
  444         if (error && (uio.uio_resid == count)) {
  445                 printf("nwfs_getpages: error %d\n",error);
  446                 vm_page_lock_queues();
  447                 for (i = 0; i < npages; i++) {
  448                         if (ap->a_reqpage != i)
  449                                 vm_page_free(pages[i]);
  450                 }
  451                 vm_page_unlock_queues();
  452                 VM_OBJECT_UNLOCK(object);
  453                 return VM_PAGER_ERROR;
  454         }
  455 
  456         size = count - uio.uio_resid;
  457 
  458         vm_page_lock_queues();
  459         for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
  460                 vm_page_t m;
  461                 nextoff = toff + PAGE_SIZE;
  462                 m = pages[i];
  463 
  464                 if (nextoff <= size) {
  465                         m->valid = VM_PAGE_BITS_ALL;
  466                         m->dirty = 0;
  467                 } else {
  468                         int nvalid = ((size + DEV_BSIZE - 1) - toff) & ~(DEV_BSIZE - 1);
  469                         vm_page_set_validclean(m, 0, nvalid);
  470                 }
  471 
  472                 if (i != ap->a_reqpage) {
  473                         /*
  474                          * Whether or not to leave the page activated is up in
  475                          * the air, but we should put the page on a page queue
  476                          * somewhere (it already is in the object).  Result:
  477                          * It appears that emperical results show that
  478                          * deactivating pages is best.
  479                          */
  480 
  481                         /*
  482                          * Just in case someone was asking for this page we
  483                          * now tell them that it is ok to use.
  484                          */
  485                         if (!error) {
  486                                 if (m->flags & PG_WANTED)
  487                                         vm_page_activate(m);
  488                                 else
  489                                         vm_page_deactivate(m);
  490                                 vm_page_wakeup(m);
  491                         } else {
  492                                 vm_page_free(m);
  493                         }
  494                 }
  495         }
  496         vm_page_unlock_queues();
  497         VM_OBJECT_UNLOCK(object);
  498         return 0;
  499 #endif /* NWFS_RWCACHE */
  500 }
  501 
  502 /*
  503  * Vnode op for VM putpages.
  504  * possible bug: all IO done in sync mode
  505  * Note that vop_close always invalidate pages before close, so it's
  506  * not necessary to open vnode.
  507  */
  508 int
  509 nwfs_putpages(ap)
  510         struct vop_putpages_args /* {
  511                 struct vnode *a_vp;
  512                 vm_page_t *a_m;
  513                 int a_count;
  514                 int a_sync;
  515                 int *a_rtvals;
  516                 vm_ooffset_t a_offset;
  517         } */ *ap;
  518 {
  519         int error;
  520         struct vnode *vp = ap->a_vp;
  521         struct thread *td;
  522         struct ucred *cred;
  523 
  524 #ifndef NWFS_RWCACHE
  525         td = curthread;                 /* XXX */
  526         cred = td->td_ucred;            /* XXX */
  527         VOP_OPEN(vp, FWRITE, cred, td, -1);
  528         error = vop_stdputpages(ap);
  529         VOP_CLOSE(vp, FWRITE, cred, td);
  530         return error;
  531 #else
  532         struct uio uio;
  533         struct iovec iov;
  534         vm_offset_t kva;
  535         struct buf *bp;
  536         int i, npages, count;
  537         int *rtvals;
  538         struct nwmount *nmp;
  539         struct nwnode *np;
  540         vm_page_t *pages;
  541 
  542         td = curthread;                 /* XXX */
  543         cred = td->td_ucred;            /* XXX */
  544 /*      VOP_OPEN(vp, FWRITE, cred, td, -1);*/
  545         np = VTONW(vp);
  546         nmp = VFSTONWFS(vp->v_mount);
  547         pages = ap->a_m;
  548         count = ap->a_count;
  549         rtvals = ap->a_rtvals;
  550         npages = btoc(count);
  551 
  552         for (i = 0; i < npages; i++) {
  553                 rtvals[i] = VM_PAGER_AGAIN;
  554         }
  555 
  556         bp = getpbuf(&nwfs_pbuf_freecnt);
  557         kva = (vm_offset_t) bp->b_data;
  558         pmap_qenter(kva, pages, npages);
  559 
  560         iov.iov_base = (caddr_t) kva;
  561         iov.iov_len = count;
  562         uio.uio_iov = &iov;
  563         uio.uio_iovcnt = 1;
  564         uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
  565         uio.uio_resid = count;
  566         uio.uio_segflg = UIO_SYSSPACE;
  567         uio.uio_rw = UIO_WRITE;
  568         uio.uio_td = td;
  569         NCPVNDEBUG("ofs=%d,resid=%d\n",(int)uio.uio_offset, uio.uio_resid);
  570 
  571         error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, &uio, cred);
  572 /*      VOP_CLOSE(vp, FWRITE, cred, td);*/
  573         NCPVNDEBUG("paged write done: %d\n", error);
  574 
  575         pmap_qremove(kva, npages);
  576         relpbuf(bp, &nwfs_pbuf_freecnt);
  577 
  578         if (!error) {
  579                 int nwritten = round_page(count - uio.uio_resid) / PAGE_SIZE;
  580                 vm_page_lock_queues();
  581                 for (i = 0; i < nwritten; i++) {
  582                         rtvals[i] = VM_PAGER_OK;
  583                         vm_page_undirty(pages[i]);
  584                 }
  585                 vm_page_unlock_queues();
  586         }
  587         return rtvals[0];
  588 #endif /* NWFS_RWCACHE */
  589 }
  590 /*
  591  * Flush and invalidate all dirty buffers. If another process is already
  592  * doing the flush, just wait for completion.
  593  */
  594 int
  595 nwfs_vinvalbuf(vp, td)
  596         struct vnode *vp;
  597         struct thread *td;
  598 {
  599         struct nwnode *np = VTONW(vp);
  600 /*      struct nwmount *nmp = VTONWFS(vp);*/
  601         int error = 0;
  602 
  603         if (vp->v_iflag & VI_DOOMED)
  604                 return (0);
  605 
  606         while (np->n_flag & NFLUSHINPROG) {
  607                 np->n_flag |= NFLUSHWANT;
  608                 error = tsleep(&np->n_flag, PRIBIO + 2, "nwfsvinv", 2 * hz);
  609                 error = ncp_chkintr(NWFSTOCONN(VTONWFS(vp)), td);
  610                 if (error == EINTR)
  611                         return EINTR;
  612         }
  613         np->n_flag |= NFLUSHINPROG;
  614         error = vinvalbuf(vp, V_SAVE, td, PCATCH, 0);
  615         while (error) {
  616                 if (error == ERESTART || error == EINTR) {
  617                         np->n_flag &= ~NFLUSHINPROG;
  618                         if (np->n_flag & NFLUSHWANT) {
  619                                 np->n_flag &= ~NFLUSHWANT;
  620                                 wakeup(&np->n_flag);
  621                         }
  622                         return EINTR;
  623                 }
  624                 error = vinvalbuf(vp, V_SAVE, td, PCATCH, 0);
  625         }
  626         np->n_flag &= ~(NMODIFIED | NFLUSHINPROG);
  627         if (np->n_flag & NFLUSHWANT) {
  628                 np->n_flag &= ~NFLUSHWANT;
  629                 wakeup(&np->n_flag);
  630         }
  631         return (error);
  632 }

Cache object: 8c0f73c9824a7c6e104f57e1f57668a8


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.