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/geom/geom_vfs.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) 2004 Poul-Henning Kamp
    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 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/6.3/sys/geom/geom_vfs.c 170553 2007-06-11 10:53:48Z kib $");
   29 
   30 #include <sys/param.h>
   31 #include <sys/systm.h>
   32 #include <sys/bio.h>
   33 #include <sys/kernel.h>
   34 #include <sys/malloc.h>
   35 #include <sys/vnode.h>
   36 #include <sys/mount.h>  /* XXX Temporary for VFS_LOCK_GIANT */
   37 
   38 #include <geom/geom.h>
   39 #include <geom/geom_vfs.h>
   40 
   41 /*
   42  * subroutines for use by filesystems.
   43  *
   44  * XXX: should maybe live somewhere else ?
   45  */
   46 #include <sys/buf.h>
   47 
   48 static struct buf_ops __g_vfs_bufops = {
   49         .bop_name =     "GEOM_VFS",
   50         .bop_write =    bufwrite,
   51         .bop_strategy = g_vfs_strategy, 
   52         .bop_sync =     bufsync,        
   53         .bop_bdflush =  bufbdflush
   54 };
   55 
   56 struct buf_ops *g_vfs_bufops = &__g_vfs_bufops;
   57 
   58 static g_orphan_t g_vfs_orphan;
   59 
   60 static struct g_class g_vfs_class = {
   61         .name =         "VFS",
   62         .version =      G_VERSION,
   63         .orphan =       g_vfs_orphan,
   64 };
   65 
   66 DECLARE_GEOM_CLASS(g_vfs_class, g_vfs);
   67 
   68 static void
   69 g_vfs_done(struct bio *bip)
   70 {
   71         struct buf *bp;
   72         int vfslocked;
   73 
   74         if (bip->bio_error) {
   75                 printf("g_vfs_done():");
   76                 g_print_bio(bip);
   77                 printf("error = %d\n", bip->bio_error);
   78         }
   79         bp = bip->bio_caller2;
   80         bp->b_error = bip->bio_error;
   81         bp->b_ioflags = bip->bio_flags;
   82         if (bip->bio_error)
   83                 bp->b_ioflags |= BIO_ERROR;
   84         bp->b_resid = bp->b_bcount - bip->bio_completed;
   85         g_destroy_bio(bip);
   86         vfslocked = VFS_LOCK_GIANT(((struct mount *)NULL));
   87         bufdone(bp);
   88         VFS_UNLOCK_GIANT(vfslocked);
   89 }
   90 
   91 void
   92 g_vfs_strategy(struct bufobj *bo, struct buf *bp)
   93 {
   94         struct g_consumer *cp;
   95         struct bio *bip;
   96 
   97         cp = bo->bo_private;
   98         G_VALID_CONSUMER(cp);
   99 
  100         bip = g_alloc_bio();
  101         bip->bio_cmd = bp->b_iocmd;
  102         bip->bio_offset = bp->b_iooffset;
  103         bip->bio_data = bp->b_data;
  104         bip->bio_done = g_vfs_done;
  105         bip->bio_caller2 = bp;
  106         bip->bio_length = bp->b_bcount;
  107         g_io_request(bip, cp);
  108 }
  109 
  110 static void
  111 g_vfs_orphan(struct g_consumer *cp)
  112 {
  113 
  114         /*
  115          * Don't do anything here yet.
  116          *
  117          * Ideally we should detach the consumer already now, but that
  118          * leads to a locking requirement in the I/O path to see if we have
  119          * a consumer or not.  Considering how ugly things are going to get
  120          * anyway as none of our filesystems are graceful about i/o errors,
  121          * this is not important right now.
  122          *
  123          * Down the road, this is the place where we could give the user
  124          * a "Abort, Retry or Ignore" option to replace the media again.
  125          */
  126 }
  127 
  128 int
  129 g_vfs_open(struct vnode *vp, struct g_consumer **cpp, const char *fsname, int wr)
  130 {
  131         struct g_geom *gp;
  132         struct g_provider *pp;
  133         struct g_consumer *cp;
  134         struct bufobj *bo;
  135         int vfslocked;
  136         int error;
  137 
  138         g_topology_assert();
  139 
  140         *cpp = NULL;
  141         pp = g_dev_getprovider(vp->v_rdev);
  142         if (pp == NULL)
  143                 return (ENOENT);
  144         gp = g_new_geomf(&g_vfs_class, "%s.%s", fsname, pp->name);
  145         cp = g_new_consumer(gp);
  146         g_attach(cp, pp);
  147         error = g_access(cp, 1, wr, 1);
  148         if (error) {
  149                 g_wither_geom(gp, ENXIO);
  150                 return (error);
  151         }
  152         vfslocked = VFS_LOCK_GIANT(vp->v_mount);
  153         vnode_create_vobject_off(vp, pp->mediasize, curthread);
  154         VFS_UNLOCK_GIANT(vfslocked);
  155         *cpp = cp;
  156         bo = &vp->v_bufobj;
  157         bo->bo_ops = g_vfs_bufops;
  158         bo->bo_private = cp;
  159         bo->bo_bsize = pp->sectorsize;
  160         gp->softc = bo;
  161 
  162         return (error);
  163 }
  164 
  165 void
  166 g_vfs_close(struct g_consumer *cp, struct thread *td)
  167 {
  168         struct g_geom *gp;
  169         struct bufobj *bo;
  170 
  171         g_topology_assert();
  172 
  173         gp = cp->geom;
  174         bo = gp->softc;
  175         bufobj_invalbuf(bo, V_SAVE, td, 0, 0);
  176         g_wither_geom_close(gp, ENXIO);
  177 }

Cache object: 01a7501744feeae553f5231b999b8cd6


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