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

Cache object: 93af24375be8545a425589008620d970


[ 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.