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/coda/coda_vfsops.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  * 
    3  *             Coda: an Experimental Distributed File System
    4  *                              Release 3.1
    5  * 
    6  *           Copyright (c) 1987-1998 Carnegie Mellon University
    7  *                          All Rights Reserved
    8  * 
    9  * Permission  to  use, copy, modify and distribute this software and its
   10  * documentation is hereby granted,  provided  that  both  the  copyright
   11  * notice  and  this  permission  notice  appear  in  all  copies  of the
   12  * software, derivative works or  modified  versions,  and  any  portions
   13  * thereof, and that both notices appear in supporting documentation, and
   14  * that credit is given to Carnegie Mellon University  in  all  documents
   15  * and publicity pertaining to direct or indirect use of this code or its
   16  * derivatives.
   17  * 
   18  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
   19  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
   20  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
   21  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
   22  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
   23  * ANY DERIVATIVE WORK.
   24  * 
   25  * Carnegie  Mellon  encourages  users  of  this  software  to return any
   26  * improvements or extensions that  they  make,  and  to  grant  Carnegie
   27  * Mellon the rights to redistribute these changes without encumbrance.
   28  * 
   29  *      @(#) src/sys/cfs/coda_vfsops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
   30  * $FreeBSD: releng/5.0/sys/coda/coda_vfsops.c 101308 2002-08-04 10:29:36Z jeff $
   31  * 
   32  */
   33 
   34 /* 
   35  * Mach Operating System
   36  * Copyright (c) 1989 Carnegie-Mellon University
   37  * All rights reserved.  The CMU software License Agreement specifies
   38  * the terms and conditions for use and redistribution.
   39  */
   40 
   41 /*
   42  * This code was written for the Coda filesystem at Carnegie Mellon
   43  * University.  Contributers include David Steere, James Kistler, and
   44  * M. Satyanarayanan.  
   45  */
   46 
   47 #include <vcoda.h>
   48 
   49 #include <sys/param.h>
   50 #include <sys/systm.h>
   51 #include <sys/conf.h>
   52 #include <sys/kernel.h>
   53 #include <sys/lock.h>
   54 #include <sys/malloc.h>
   55 #include <sys/mount.h>
   56 #include <sys/namei.h>
   57 #include <sys/proc.h>
   58 
   59 #include <coda/coda.h>
   60 #include <coda/cnode.h>
   61 #include <coda/coda_vfsops.h>
   62 #include <coda/coda_venus.h>
   63 #include <coda/coda_subr.h>
   64 #include <coda/coda_opstats.h>
   65 
   66 MALLOC_DEFINE(M_CODA, "CODA storage", "Various Coda Structures");
   67 
   68 int codadebug = 0;
   69 int coda_vfsop_print_entry = 0;
   70 #define ENTRY    if(coda_vfsop_print_entry) myprintf(("Entered %s\n",__func__))
   71 
   72 struct vnode *coda_ctlvp;
   73 struct coda_mntinfo coda_mnttbl[NVCODA]; /* indexed by minor device number */
   74 
   75 /* structure to keep statistics of internally generated/satisfied calls */
   76 
   77 struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE];
   78 
   79 #define MARK_ENTRY(op) (coda_vfsopstats[op].entries++)
   80 #define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++)
   81 #define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++)
   82 #define MRAK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++)
   83 
   84 extern int coda_nc_initialized;     /* Set if cache has been initialized */
   85 extern int vc_nb_open(dev_t, int, int, struct thread *);
   86 
   87 int
   88 coda_vfsopstats_init(void)
   89 {
   90         register int i;
   91         
   92         for (i=0;i<CODA_VFSOPS_SIZE;i++) {
   93                 coda_vfsopstats[i].opcode = i;
   94                 coda_vfsopstats[i].entries = 0;
   95                 coda_vfsopstats[i].sat_intrn = 0;
   96                 coda_vfsopstats[i].unsat_intrn = 0;
   97                 coda_vfsopstats[i].gen_intrn = 0;
   98         }
   99         
  100         return 0;
  101 }
  102 
  103 /*
  104  * cfs mount vfsop
  105  * Set up mount info record and attach it to vfs struct.
  106  */
  107 /*ARGSUSED*/
  108 int
  109 coda_mount(vfsp, path, data, ndp, td)
  110     struct mount *vfsp;         /* Allocated and initialized by mount(2) */
  111     char *path;                 /* path covered: ignored by the fs-layer */
  112     caddr_t data;               /* Need to define a data type for this in netbsd? */
  113     struct nameidata *ndp;      /* Clobber this to lookup the device name */
  114     struct thread *td;
  115 {
  116     struct vnode *dvp;
  117     struct cnode *cp;
  118     dev_t dev;
  119     struct coda_mntinfo *mi;
  120     struct vnode *rootvp;
  121     ViceFid rootfid;
  122     ViceFid ctlfid;
  123     int error;
  124 
  125     ENTRY;
  126 
  127     coda_vfsopstats_init();
  128     coda_vnodeopstats_init();
  129     
  130     MARK_ENTRY(CODA_MOUNT_STATS);
  131     if (CODA_MOUNTED(vfsp)) {
  132         MARK_INT_FAIL(CODA_MOUNT_STATS);
  133         return(EBUSY);
  134     }
  135     
  136     /* Validate mount device.  Similar to getmdev(). */
  137     NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, data, td);
  138     error = namei(ndp);
  139     dvp = ndp->ni_vp;
  140 
  141     if (error) {
  142         MARK_INT_FAIL(CODA_MOUNT_STATS);
  143         return (error);
  144     }
  145     if (dvp->v_type != VCHR) {
  146         MARK_INT_FAIL(CODA_MOUNT_STATS);
  147         vrele(dvp);
  148         NDFREE(ndp, NDF_ONLY_PNBUF);
  149         return(ENXIO);
  150     }
  151     dev = dvp->v_rdev;
  152     vrele(dvp);
  153     NDFREE(ndp, NDF_ONLY_PNBUF);
  154 
  155     /*
  156      * See if the device table matches our expectations.
  157      */
  158     if (devsw(dev)->d_open != vc_nb_open)
  159     {
  160         MARK_INT_FAIL(CODA_MOUNT_STATS);
  161         return(ENXIO);
  162     }
  163     
  164     if (minor(dev) >= NVCODA || minor(dev) < 0) {
  165         MARK_INT_FAIL(CODA_MOUNT_STATS);
  166         return(ENXIO);
  167     }
  168     
  169     /*
  170      * Initialize the mount record and link it to the vfs struct
  171      */
  172     mi = &coda_mnttbl[minor(dev)];
  173     
  174     if (!VC_OPEN(&mi->mi_vcomm)) {
  175         MARK_INT_FAIL(CODA_MOUNT_STATS);
  176         return(ENODEV);
  177     }
  178     
  179     /* No initialization (here) of mi_vcomm! */
  180     vfsp->mnt_data = (qaddr_t)mi;
  181     vfs_getnewfsid (vfsp);
  182 
  183     mi->mi_vfsp = vfsp;
  184     
  185     /*
  186      * Make a root vnode to placate the Vnode interface, but don't
  187      * actually make the CODA_ROOT call to venus until the first call
  188      * to coda_root in case a server is down while venus is starting.
  189      */
  190     rootfid.Volume = 0;
  191     rootfid.Vnode = 0;
  192     rootfid.Unique = 0;
  193     cp = make_coda_node(&rootfid, vfsp, VDIR);
  194     rootvp = CTOV(cp);
  195     rootvp->v_vflag |= VV_ROOT;
  196         
  197     ctlfid.Volume = CTL_VOL;
  198     ctlfid.Vnode = CTL_VNO;
  199     ctlfid.Unique = CTL_UNI;
  200 /*  cp = make_coda_node(&ctlfid, vfsp, VCHR);
  201     The above code seems to cause a loop in the cnode links.
  202     I don't totally understand when it happens, it is caught
  203     when closing down the system.
  204  */
  205     cp = make_coda_node(&ctlfid, 0, VCHR);
  206 
  207     coda_ctlvp = CTOV(cp);
  208 
  209     /* Add vfs and rootvp to chain of vfs hanging off mntinfo */
  210     mi->mi_vfsp = vfsp;
  211     mi->mi_rootvp = rootvp;
  212     
  213     /* set filesystem block size */
  214     vfsp->mnt_stat.f_bsize = 8192;          /* XXX -JJK */
  215 
  216     /* Set f_iosize.  XXX -- inamura@isl.ntt.co.jp. 
  217        For vnode_pager_haspage() references. The value should be obtained 
  218        from underlying UFS. */
  219     /* Checked UFS. iosize is set as 8192 */
  220     vfsp->mnt_stat.f_iosize = 8192;
  221 
  222     /* error is currently guaranteed to be zero, but in case some
  223        code changes... */
  224     CODADEBUG(1,
  225              myprintf(("coda_mount returned %d\n",error)););
  226     if (error)
  227         MARK_INT_FAIL(CODA_MOUNT_STATS);
  228     else
  229         MARK_INT_SAT(CODA_MOUNT_STATS);
  230     
  231     return(error);
  232 }
  233 
  234 int
  235 coda_unmount(vfsp, mntflags, td)
  236     struct mount *vfsp;
  237     int mntflags;
  238     struct thread *td;
  239 {
  240     struct coda_mntinfo *mi = vftomi(vfsp);
  241     int active, error = 0;
  242     
  243     ENTRY;
  244     MARK_ENTRY(CODA_UMOUNT_STATS);
  245     if (!CODA_MOUNTED(vfsp)) {
  246         MARK_INT_FAIL(CODA_UMOUNT_STATS);
  247         return(EINVAL);
  248     }
  249     
  250     if (mi->mi_vfsp == vfsp) {  /* We found the victim */
  251         if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp)))
  252             return (EBUSY);     /* Venus is still running */
  253 
  254 #ifdef  DEBUG
  255         printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, VTOC(mi->mi_rootvp));
  256 #endif
  257         vrele(mi->mi_rootvp);
  258 
  259         active = coda_kill(vfsp, NOT_DOWNCALL);
  260         ASSERT_VOP_LOCKED(mi->mi_rootvp, "coda_unmount");
  261         mi->mi_rootvp->v_vflag &= ~VV_ROOT;
  262         error = vflush(mi->mi_vfsp, 0, FORCECLOSE);
  263         printf("coda_unmount: active = %d, vflush active %d\n", active, error);
  264         error = 0;
  265         /* I'm going to take this out to allow lookups to go through. I'm
  266          * not sure it's important anyway. -- DCS 2/2/94
  267          */
  268         /* vfsp->VFS_DATA = NULL; */
  269 
  270         /* No more vfsp's to hold onto */
  271         mi->mi_vfsp = NULL;
  272         mi->mi_rootvp = NULL;
  273 
  274         if (error)
  275             MARK_INT_FAIL(CODA_UMOUNT_STATS);
  276         else
  277             MARK_INT_SAT(CODA_UMOUNT_STATS);
  278 
  279         return(error);
  280     }
  281     return (EINVAL);
  282 }
  283 
  284 /*
  285  * find root of cfs
  286  */
  287 int
  288 coda_root(vfsp, vpp)
  289         struct mount *vfsp;
  290         struct vnode **vpp;
  291 {
  292     struct coda_mntinfo *mi = vftomi(vfsp);
  293     struct vnode **result;
  294     int error;
  295     struct thread *td = curthread;    /* XXX - bnoble */
  296     struct proc *p = td->td_proc;
  297     ViceFid VFid;
  298  
  299     ENTRY;
  300     MARK_ENTRY(CODA_ROOT_STATS);
  301     result = NULL;
  302     
  303     if (vfsp == mi->mi_vfsp) {
  304         if ((VTOC(mi->mi_rootvp)->c_fid.Volume != 0) ||
  305             (VTOC(mi->mi_rootvp)->c_fid.Vnode != 0) ||
  306             (VTOC(mi->mi_rootvp)->c_fid.Unique != 0))
  307             { /* Found valid root. */
  308                 *vpp = mi->mi_rootvp;
  309                 /* On Mach, this is vref.  On NetBSD, VOP_LOCK */
  310 #if     1
  311                 vref(*vpp);
  312                 vn_lock(*vpp, LK_EXCLUSIVE, td);
  313 #else
  314                 vget(*vpp, LK_EXCLUSIVE, td);
  315 #endif
  316                 MARK_INT_SAT(CODA_ROOT_STATS);
  317                 return(0);
  318             }
  319     }
  320 
  321     error = venus_root(vftomi(vfsp), td->td_ucred, p, &VFid);
  322 
  323     if (!error) {
  324         /*
  325          * Save the new rootfid in the cnode, and rehash the cnode into the
  326          * cnode hash with the new fid key.
  327          */
  328         coda_unsave(VTOC(mi->mi_rootvp));
  329         VTOC(mi->mi_rootvp)->c_fid = VFid;
  330         coda_save(VTOC(mi->mi_rootvp));
  331 
  332         *vpp = mi->mi_rootvp;
  333 #if     1
  334         vref(*vpp);
  335         vn_lock(*vpp, LK_EXCLUSIVE, td);
  336 #else
  337         vget(*vpp, LK_EXCLUSIVE, td);
  338 #endif
  339 
  340         MARK_INT_SAT(CODA_ROOT_STATS);
  341         goto exit;
  342     } else if (error == ENODEV || error == EINTR) {
  343         /* Gross hack here! */
  344         /*
  345          * If Venus fails to respond to the CODA_ROOT call, coda_call returns
  346          * ENODEV. Return the uninitialized root vnode to allow vfs
  347          * operations such as unmount to continue. Without this hack,
  348          * there is no way to do an unmount if Venus dies before a 
  349          * successful CODA_ROOT call is done. All vnode operations 
  350          * will fail.
  351          */
  352         *vpp = mi->mi_rootvp;
  353 #if     1
  354         vref(*vpp);
  355         vn_lock(*vpp, LK_EXCLUSIVE, td);
  356 #else
  357         vget(*vpp, LK_EXCLUSIVE, td);
  358 #endif
  359 
  360         MARK_INT_FAIL(CODA_ROOT_STATS);
  361         error = 0;
  362         goto exit;
  363     } else {
  364         CODADEBUG( CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", error)); );
  365         MARK_INT_FAIL(CODA_ROOT_STATS);
  366                 
  367         goto exit;
  368     }
  369 
  370  exit:
  371     return(error);
  372 }
  373 
  374 /*
  375  * Get filesystem statistics.
  376  */
  377 int
  378 coda_nb_statfs(vfsp, sbp, td)
  379     register struct mount *vfsp;
  380     struct statfs *sbp;
  381     struct thread *td;
  382 {
  383     ENTRY;
  384 /*  MARK_ENTRY(CODA_STATFS_STATS); */
  385     if (!CODA_MOUNTED(vfsp)) {
  386 /*      MARK_INT_FAIL(CODA_STATFS_STATS);*/
  387         return(EINVAL);
  388     }
  389     
  390     bzero(sbp, sizeof(struct statfs));
  391     /* XXX - what to do about f_flags, others? --bnoble */
  392     /* Below This is what AFS does
  393         #define NB_SFS_SIZ 0x895440
  394      */
  395     /* Note: Normal fs's have a bsize of 0x400 == 1024 */
  396     sbp->f_type = vfsp->mnt_vfc->vfc_typenum;
  397     sbp->f_bsize = 8192; /* XXX */
  398     sbp->f_iosize = 8192; /* XXX */
  399 #define NB_SFS_SIZ 0x8AB75D
  400     sbp->f_blocks = NB_SFS_SIZ;
  401     sbp->f_bfree = NB_SFS_SIZ;
  402     sbp->f_bavail = NB_SFS_SIZ;
  403     sbp->f_files = NB_SFS_SIZ;
  404     sbp->f_ffree = NB_SFS_SIZ;
  405     bcopy((caddr_t)&(vfsp->mnt_stat.f_fsid), (caddr_t)&(sbp->f_fsid), sizeof (fsid_t));
  406     snprintf(sbp->f_mntonname, sizeof(sbp->f_mntonname), "/coda");
  407     snprintf(sbp->f_mntfromname, sizeof(sbp->f_mntfromname), "CODA");
  408 /*  MARK_INT_SAT(CODA_STATFS_STATS); */
  409     return(0);
  410 }
  411 
  412 /*
  413  * Flush any pending I/O.
  414  */
  415 int
  416 coda_sync(vfsp, waitfor, cred, td)
  417     struct mount *vfsp;
  418     int    waitfor;
  419     struct ucred *cred;
  420     struct thread *td;
  421 {
  422     ENTRY;
  423     MARK_ENTRY(CODA_SYNC_STATS);
  424     MARK_INT_SAT(CODA_SYNC_STATS);
  425     return(0);
  426 }
  427 
  428 /* 
  429  * fhtovp is now what vget used to be in 4.3-derived systems.  For
  430  * some silly reason, vget is now keyed by a 32 bit ino_t, rather than
  431  * a type-specific fid.  
  432  */
  433 int
  434 coda_fhtovp(vfsp, fhp, nam, vpp, exflagsp, creadanonp)
  435     register struct mount *vfsp;    
  436     struct fid *fhp;
  437     struct mbuf *nam;
  438     struct vnode **vpp;
  439     int *exflagsp;
  440     struct ucred **creadanonp;
  441 {
  442     struct cfid *cfid = (struct cfid *)fhp;
  443     struct cnode *cp = 0;
  444     int error;
  445     struct thread *td = curthread; /* XXX -mach */
  446     struct proc *p = td->td_proc;
  447     ViceFid VFid;
  448     int vtype;
  449 
  450     ENTRY;
  451     
  452     MARK_ENTRY(CODA_VGET_STATS);
  453     /* Check for vget of control object. */
  454     if (IS_CTL_FID(&cfid->cfid_fid)) {
  455         *vpp = coda_ctlvp;
  456         vref(coda_ctlvp);
  457         MARK_INT_SAT(CODA_VGET_STATS);
  458         return(0);
  459     }
  460     
  461     error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, td->td_ucred, p, &VFid, &vtype);
  462     
  463     if (error) {
  464         CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));)
  465             *vpp = (struct vnode *)0;
  466     } else {
  467         CODADEBUG(CODA_VGET, 
  468                  myprintf(("vget: vol %lx vno %lx uni %lx type %d result %d\n",
  469                         VFid.Volume, VFid.Vnode, VFid.Unique, vtype, error)); )
  470             
  471         cp = make_coda_node(&VFid, vfsp, vtype);
  472         *vpp = CTOV(cp);
  473     }
  474     return(error);
  475 }
  476 
  477 /*
  478  * To allow for greater ease of use, some vnodes may be orphaned when
  479  * Venus dies.  Certain operations should still be allowed to go
  480  * through, but without propagating ophan-ness.  So this function will
  481  * get a new vnode for the file from the current run of Venus.  */
  482  
  483 int
  484 getNewVnode(vpp)
  485      struct vnode **vpp;
  486 {
  487     struct cfid cfid;
  488     struct coda_mntinfo *mi = vftomi((*vpp)->v_mount);
  489     
  490     ENTRY;
  491 
  492     cfid.cfid_len = (short)sizeof(ViceFid);
  493     cfid.cfid_fid = VTOC(*vpp)->c_fid;  /* Structure assignment. */
  494     /* XXX ? */
  495 
  496     /* We're guessing that if set, the 1st element on the list is a
  497      * valid vnode to use. If not, return ENODEV as venus is dead.
  498      */
  499     if (mi->mi_vfsp == NULL)
  500         return ENODEV;
  501     
  502     return coda_fhtovp(mi->mi_vfsp, (struct fid*)&cfid, NULL, vpp,
  503                       NULL, NULL);
  504 }
  505 
  506 #include <ufs/ufs/extattr.h>
  507 #include <ufs/ufs/quota.h>
  508 #include <ufs/ufs/ufsmount.h>
  509 /* get the mount structure corresponding to a given device.  Assume 
  510  * device corresponds to a UFS. Return NULL if no device is found.
  511  */ 
  512 struct mount *devtomp(dev)
  513     dev_t dev;
  514 {
  515     struct mount *mp;
  516    
  517     TAILQ_FOREACH(mp, &mountlist, mnt_list) {
  518         if (((VFSTOUFS(mp))->um_dev == dev)) {
  519             /* mount corresponds to UFS and the device matches one we want */
  520             return(mp); 
  521         }
  522     }
  523     /* mount structure wasn't found */ 
  524     return(NULL); 
  525 }
  526 
  527 struct vfsops coda_vfsops = {
  528     coda_mount,
  529     vfs_stdstart,
  530     coda_unmount,
  531     coda_root,
  532     vfs_stdquotactl,
  533     coda_nb_statfs,
  534     coda_sync,
  535     vfs_stdvget,
  536     vfs_stdfhtovp,
  537     vfs_stdcheckexp,
  538     vfs_stdvptofh,
  539     vfs_stdinit,
  540     vfs_stduninit,
  541     vfs_stdextattrctl,
  542 };
  543 
  544 VFS_SET(coda_vfsops, coda, VFCF_NETWORK);

Cache object: def87752f5973c5fecb786c5ada108fd


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