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/nfs4client/nfs4_vn_subs.c

Version: -  FREEBSD  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  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 /* $FreeBSD$ */
    2 /* $Id: nfs4_vn_subs.c,v 1.9 2003/11/05 14:59:00 rees Exp $ */
    3 
    4 /*-
    5  * copyright (c) 2003
    6  * the regents of the university of michigan
    7  * all rights reserved
    8  * 
    9  * permission is granted to use, copy, create derivative works and redistribute
   10  * this software and such derivative works for any purpose, so long as the name
   11  * of the university of michigan is not used in any advertising or publicity
   12  * pertaining to the use or distribution of this software without specific,
   13  * written prior authorization.  if the above copyright notice or any other
   14  * identification of the university of michigan is included in any copy of any
   15  * portion of this software, then the disclaimer below must also be included.
   16  * 
   17  * this software is provided as is, without representation from the university
   18  * of michigan as to its fitness for any purpose, and without warranty by the
   19  * university of michigan of any kind, either express or implied, including
   20  * without limitation the implied warranties of merchantability and fitness for
   21  * a particular purpose. the regents of the university of michigan shall not be
   22  * liable for any damages, including special, indirect, incidental, or
   23  * consequential damages, with respect to any claim arising out of or in
   24  * connection with the use of the software, even if it has been or is hereafter
   25  * advised of the possibility of such damages.
   26  */
   27 
   28 #include <sys/param.h>
   29 #include <sys/systm.h>
   30 #include <sys/kernel.h>
   31 #include <sys/limits.h>
   32 #include <sys/lock.h>
   33 #include <sys/malloc.h>
   34 #include <sys/mbuf.h>
   35 #include <sys/module.h>
   36 #include <sys/mount.h>
   37 #include <sys/proc.h>
   38 #include <sys/socket.h>
   39 #include <sys/socketvar.h>
   40 #include <sys/sockio.h>
   41 #include <sys/vnode.h>
   42 #include <sys/types.h>
   43 
   44 #include <vm/vm.h>
   45 #include <vm/vm_extern.h>
   46 #include <vm/uma.h>
   47 
   48 #include <net/if.h>
   49 #include <net/route.h>
   50 #include <netinet/in.h>
   51 
   52 #include <rpc/rpcclnt.h>
   53 
   54 #include <nfs/rpcv2.h>
   55 #include <nfs/nfsproto.h>
   56 #include <nfsclient/nfs.h>
   57 #include <nfsclient/nfsmount.h>
   58 #include <nfs/xdr_subs.h>
   59 #include <nfsclient/nfsm_subs.h>
   60 #include <nfsclient/nfsdiskless.h>
   61 
   62 /* NFSv4 */
   63 #include <nfs4client/nfs4.h>
   64 #include <nfs4client/nfs4m_subs.h>
   65 #include <nfs4client/nfs4_vn.h>
   66 
   67 #include <nfsclient/nfsnode.h>
   68 
   69 void
   70 nfs4_vnop_loadattrcache(struct vnode *vp, struct nfsv4_fattr *fap,
   71     struct vattr *vaper)
   72 {
   73         struct vattr *vap;
   74         struct nfsnode *np;
   75         int32_t rdev;
   76         enum vtype vtyp;
   77         u_short vmode;
   78         struct timespec mtime;
   79         struct timeval tv;
   80 
   81         microtime(&tv);
   82 
   83         vtyp = nv3tov_type[fap->fa4_type & 0x7];
   84         vmode = (fap->fa4_valid & FA4V_MODE) ? fap->fa4_mode : 0777;
   85         rdev = (fap->fa4_valid & FA4V_RDEV) ?
   86             makedev(fap->fa4_rdev_major, fap->fa4_rdev_minor) : 0;
   87         if (fap->fa4_valid & FA4V_MTIME)
   88                 mtime = fap->fa4_mtime;
   89         else
   90                 bzero(&mtime, sizeof mtime);
   91 
   92         /*
   93          * If v_type == VNON it is a new node, so fill in the v_type,
   94          * n_mtime fields. Check to see if it represents a special
   95          * device, and if so, check for a possible alias. Once the
   96          * correct vnode has been obtained, fill in the rest of the
   97          * information.
   98          */
   99         np = VTONFS(vp);
  100         vap = &np->n_vattr;
  101         if (vp->v_type != vtyp || np->n_mtime.tv_sec == 0) {
  102                 bzero(vap, sizeof *vap);
  103                 vp->v_type = vtyp;
  104                 np->n_mtime.tv_sec = mtime.tv_sec;
  105         }
  106         vap->va_type = vtyp;
  107         vap->va_mode = (vmode & 07777);
  108         vap->va_rdev = rdev;
  109         vap->va_mtime = mtime;
  110         vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
  111         if (fap->fa4_valid & FA4V_NLINK)
  112                 vap->va_nlink = fap->fa4_nlink;
  113         if (fap->fa4_valid & FA4V_UID)
  114                 vap->va_uid = fap->fa4_uid;
  115         if (fap->fa4_valid & FA4V_GID)
  116                 vap->va_gid = fap->fa4_gid;
  117         vap->va_size = fap->fa4_size;
  118         vap->va_blocksize = NFS_FABLKSIZE;
  119         vap->va_bytes = fap->fa4_size;
  120         if (fap->fa4_valid & FA4V_FILEID)
  121                 vap->va_fileid = nfs_v4fileid4_to_fileid(fap->fa4_fileid);
  122         if (fap->fa4_valid & FA4V_ATIME)
  123                 vap->va_atime = fap->fa4_atime;
  124         if (fap->fa4_valid & FA4V_BTIME)
  125                 vap->va_birthtime = fap->fa4_btime;
  126         if (fap->fa4_valid & FA4V_CTIME)
  127                 vap->va_ctime = fap->fa4_ctime;
  128         vap->va_flags = 0;
  129         vap->va_filerev = 0;
  130         /* XXX dontshrink flag? */
  131         if (vap->va_size != np->n_size) {
  132                 if (vap->va_type == VREG) {
  133                         if (np->n_flag & NMODIFIED) {
  134                                 if (vap->va_size < np->n_size)
  135                                         vap->va_size = np->n_size;
  136                                 else
  137                                         np->n_size = vap->va_size;
  138                         } else
  139                                 np->n_size = vap->va_size;
  140                         vnode_pager_setsize(vp, np->n_size);
  141                 } else
  142                         np->n_size = vap->va_size;
  143         }
  144         np->n_attrstamp = tv.tv_sec;
  145         if (vaper != NULL) {
  146                 bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(*vap));
  147                 if (np->n_flag & NCHG) {
  148                         if (np->n_flag & NACC)
  149                                 vaper->va_atime = np->n_atim;
  150                         if (np->n_flag & NUPD)
  151                                 vaper->va_mtime = np->n_mtim;
  152                 }
  153         }
  154 }
  155 
  156 static uint64_t nfs_nullcookie = 0;
  157 /*
  158  * This function finds the directory cookie that corresponds to the
  159  * logical byte offset given.
  160  */
  161 uint64_t *
  162 nfs4_getcookie(struct nfsnode *np, off_t off, int add)
  163 {
  164         struct nfsdmap *dp, *dp2;
  165         int pos;
  166 
  167         pos = (uoff_t)off / NFS_DIRBLKSIZ;
  168         if (pos == 0 || off < 0) {
  169 #ifdef DIAGNOSTIC
  170                 if (add)
  171                         panic("nfs getcookie add at <= 0");
  172 #endif
  173                 return (&nfs_nullcookie);
  174         }
  175         pos--;
  176         dp = LIST_FIRST(&np->n_cookies);
  177         if (!dp) {
  178                 if (add) {
  179                         MALLOC(dp, struct nfsdmap *, sizeof (struct nfsdmap),
  180                                 M_NFSDIROFF, M_WAITOK);
  181                         dp->ndm_eocookie = 0;
  182                         LIST_INSERT_HEAD(&np->n_cookies, dp, ndm_list);
  183                 } else
  184                         return (NULL);
  185         }
  186         while (pos >= NFSNUMCOOKIES) {
  187                 pos -= NFSNUMCOOKIES;
  188                 if (LIST_NEXT(dp, ndm_list)) {
  189                         if (!add && dp->ndm_eocookie < NFSNUMCOOKIES &&
  190                                 pos >= dp->ndm_eocookie)
  191                                 return (NULL);
  192                         dp = LIST_NEXT(dp, ndm_list);
  193                 } else if (add) {
  194                         MALLOC(dp2, struct nfsdmap *, sizeof (struct nfsdmap),
  195                                 M_NFSDIROFF, M_WAITOK);
  196                         dp2->ndm_eocookie = 0;
  197                         LIST_INSERT_AFTER(dp, dp2, ndm_list);
  198                         dp = dp2;
  199                 } else
  200                         return (NULL);
  201         }
  202         if (pos >= dp->ndm_eocookie) {
  203                 if (add)
  204                         dp->ndm_eocookie = pos + 1;
  205                 else
  206                         return (NULL);
  207         }
  208         return (&dp->ndm4_cookies[pos]);
  209 }
  210 
  211 /*
  212  * Invalidate cached directory information, except for the actual directory
  213  * blocks (which are invalidated separately).
  214  * Done mainly to avoid the use of stale offset cookies.
  215  */
  216 void
  217 nfs4_invaldir(struct vnode *vp)
  218 {
  219         struct nfsnode *np = VTONFS(vp);
  220 
  221         np->n_direofoffset = 0;
  222         bzero(np->n4_cookieverf, NFSX_V4VERF);
  223         if (LIST_FIRST(&np->n_cookies))
  224                 LIST_FIRST(&np->n_cookies)->ndm_eocookie = 0;
  225 }

Cache object: 21a93f8506e465e42c78508e575c1500


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