Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Update the file system snapshot driver:



details:   https://anonhg.NetBSD.org/src/rev/00ca39ed2469
branches:  trunk
changeset: 557549:00ca39ed2469
user:      hannken <hannken%NetBSD.org@localhost>
date:      Sun Jan 11 19:05:26 2004 +0000

description:
Update the file system snapshot driver:
- Document the kernel thread.
- Rename some functions and variables.
- Return EROFS where appropriate.
- Use shifts instead of 64-bit divide.
- Use a simple_lock to make it MP-safe.
- Add M_CANFAIL to malloc to avoid panic on large cluster size.
- Allow sparse file for backing store and use VOP_BALLOC() to allocate
  space. Default size of backing store is the size of the file system.

diffstat:

 distrib/sets/lists/man/mi      |    4 +-
 share/man/man4/Makefile        |    3 +-
 share/man/man4/fss.4           |   12 +-
 sys/dev/fss.c                  |  489 ++++++++++++++++++++++++++--------------
 sys/dev/fssvar.h               |   90 +++++--
 usr.sbin/fssconfig/fssconfig.8 |    4 +-
 usr.sbin/fssconfig/fssconfig.c |   14 +-
 7 files changed, 408 insertions(+), 208 deletions(-)

diffs (truncated from 1319 to 300 lines):

diff -r e17d3ff47236 -r 00ca39ed2469 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sun Jan 11 18:55:33 2004 +0000
+++ b/distrib/sets/lists/man/mi Sun Jan 11 19:05:26 2004 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.651 2004/01/11 15:09:51 lukem Exp $
+# $NetBSD: mi,v 1.652 2004/01/11 19:05:26 hannken Exp $
 ./usr/share/info/am-utils.info                 man-amd-info
 ./usr/share/info/as.info                       man-computil-info       bfd
 ./usr/share/info/awk.info                      man-util-info
@@ -746,6 +746,7 @@
 ./usr/share/man/cat4/fmv.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/fpa.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/fss.0                     man-sys-catman          .cat
+./usr/share/man/cat4/fssbs.0                   man-sys-catman          .cat
 ./usr/share/man/cat4/fta.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/fwiso.0                   man-sys-catman          .cat
 ./usr/share/man/cat4/fxp.0                     man-sys-catman          .cat
@@ -2795,6 +2796,7 @@
 ./usr/share/man/man4/fmv.4                     man-sys-man             .man
 ./usr/share/man/man4/fpa.4                     man-sys-man             .man
 ./usr/share/man/man4/fss.4                     man-sys-man             .man
+./usr/share/man/man4/fssbs.4                   man-sys-man             .man
 ./usr/share/man/man4/fta.4                     man-sys-man             .man
 ./usr/share/man/man4/fwiso.4                   man-sys-man             .man
 ./usr/share/man/man4/fxp.4                     man-sys-man             .man
diff -r e17d3ff47236 -r 00ca39ed2469 share/man/man4/Makefile
--- a/share/man/man4/Makefile   Sun Jan 11 18:55:33 2004 +0000
+++ b/share/man/man4/Makefile   Sun Jan 11 19:05:26 2004 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.308 2004/01/07 15:52:54 augustss Exp $
+#      $NetBSD: Makefile,v 1.309 2004/01/11 19:05:26 hannken Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/18/93
 
 MAN=   aac.4 acardide.4 aceride.4 acphy.4 adc.4 adv.4 adw.4 agp.4 \
@@ -93,6 +93,7 @@
 MLINKS+=cardbus.4 cbb.4
 MLINKS+=fd.4 stderr.4 fd.4 stdin.4 fd.4 stdout.4
 MLINKS+=fpa.4 fea.4 fpa.4 fta.4
+MLINKS+=fss.4 fssbs.4
 MLINKS+=le.4 bicc.4 le.4 nele.4 le.4 depca.4
 MLINKS+=netintro.4 networking.4
 MLINKS+=pms.4 pmsi.4
diff -r e17d3ff47236 -r 00ca39ed2469 share/man/man4/fss.4
--- a/share/man/man4/fss.4      Sun Jan 11 18:55:33 2004 +0000
+++ b/share/man/man4/fss.4      Sun Jan 11 19:05:26 2004 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fss.4,v 1.3 2003/12/20 21:38:54 wiz Exp $      */
+.\"    $NetBSD: fss.4,v 1.4 2004/01/11 19:05:27 hannken Exp $  */
 .\"
 .\"
 .\" Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 10, 2003
+.Dd January 10, 2004
 .Dt FSS 4
 .Os
 .Sh NAME
@@ -118,6 +118,14 @@
 .Nm
 device.
 .El
+.Sh KERNEL THREADS
+For each active snapshot device there is a kernel thread
+that handles the backing store.
+This thread is named
+.Va fssbsN
+where
+.Va N
+is the device minor number.
 .Sh FILES
 .Bl -tag -width /dev/rfss? -compact
 .It Pa /dev/rfss?
diff -r e17d3ff47236 -r 00ca39ed2469 sys/dev/fss.c
--- a/sys/dev/fss.c     Sun Jan 11 18:55:33 2004 +0000
+++ b/sys/dev/fss.c     Sun Jan 11 19:05:26 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fss.c,v 1.3 2004/01/10 17:16:38 hannken Exp $  */
+/*     $NetBSD: fss.c,v 1.4 2004/01/11 19:05:27 hannken Exp $  */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -43,7 +43,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.3 2004/01/10 17:16:38 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.4 2004/01/11 19:05:27 hannken Exp $");
+
+#include "fss.h"
+#include "opt_ddb.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -66,13 +69,11 @@
 
 #include <miscfs/specfs/specdev.h>
 
+#include <dev/fssvar.h>
+
 #include <machine/stdarg.h>
 
-#include "fss.h"
-#include <dev/fssvar.h>
-
-#ifdef DEBUG
-#include "opt_ddb.h"
+#if defined(DEBUG) && defined(DDB)
 #include <ddb/ddbvar.h>
 #include <machine/db_machdep.h>
 #include <ddb/db_command.h>
@@ -136,7 +137,6 @@
 dev_type_size(fss_size);
 
 static inline void fss_error(struct fss_softc *, const char *, ...);
-static inline int fss_valid(struct fss_softc *);
 static int fss_create_snapshot(struct fss_softc *, struct fss_set *,
     struct proc *);
 static int fss_delete_snapshot(struct fss_softc *, struct proc *);
@@ -146,8 +146,8 @@
 static void fss_read_cluster(struct fss_softc *, u_int32_t);
 static int fss_write_cluster(struct fss_cache *, u_int32_t);
 static void fss_bs_thread(void *);
-static inline void block_to_cluster(struct fss_softc *, daddr_t, long,
-    u_int32_t *, long *);
+static int fss_bmap(struct fss_softc *, off_t, int,
+    struct vnode **, daddr_t *, int *);
 static int fss_bs_io(struct fss_softc *, fss_io_type,
     u_int32_t, long, int, caddr_t);
 static u_int32_t *fss_bs_indir(struct fss_softc *, u_int32_t);
@@ -172,7 +172,7 @@
                sc = &fss_softc[i];
                sc->sc_unit = i;
                sc->sc_bdev = NODEV;
-               lockinit(&sc->sc_lock, PRIBIO, "fsslock", 0, 0);
+               simple_lock_init(&sc->sc_slock);
                bufq_alloc(&sc->sc_bufq, BUFQ_FCFS|BUFQ_SORT_RAWBLOCK);
        }
 }
@@ -182,8 +182,8 @@
 {
        struct fss_softc *sc;
 
-       if (fss_dev_to_softc(dev, &sc) != 0)
-               return ENXIO;
+       if ((sc = FSS_DEV_TO_SOFTC(dev)) == NULL)
+               return ENODEV;
 
        return 0;
 }
@@ -193,8 +193,8 @@
 {
        struct fss_softc *sc;
 
-       if (fss_dev_to_softc(dev, &sc) != 0)
-               return ENXIO;
+       if ((sc = FSS_DEV_TO_SOFTC(dev)) == NULL)
+               return ENODEV;
 
        return 0;
 }
@@ -202,12 +202,19 @@
 void
 fss_strategy(struct buf *bp)
 {
+       int s;
        struct fss_softc *sc;
 
+       sc = FSS_DEV_TO_SOFTC(bp->b_dev);
+
+       FSS_LOCK(sc, s);
+
        if ((bp->b_flags & B_READ) != B_READ ||
-           fss_dev_to_softc(bp->b_dev, &sc) != 0 ||
-           !fss_valid(sc)) {
-               bp->b_error = ENXIO;
+           sc == NULL || !FSS_ISVALID(sc)) {
+
+               FSS_UNLOCK(sc, s);
+
+               bp->b_error = (sc == NULL ? ENODEV : EROFS);
                bp->b_flags |= B_ERROR;
                bp->b_resid = bp->b_bcount;
                biodone(bp);
@@ -217,6 +224,8 @@
        bp->b_rawblkno = bp->b_blkno;
        BUFQ_PUT(&sc->sc_bufq, bp);
        wakeup(&sc->sc_bs_proc);
+
+       FSS_UNLOCK(sc, s);
 }
 
 int
@@ -234,15 +243,24 @@
 int
 fss_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
 {
-       int error;
+       int s, error;
        struct fss_softc *sc;
        struct fss_set *fss = (struct fss_set *)data;
        struct fss_get *fsg = (struct fss_get *)data;
 
-       if ((error = fss_dev_to_softc(dev, &sc)) != 0)
-               return error;
+       if ((sc = FSS_DEV_TO_SOFTC(dev)) == NULL)
+               return ENODEV;
 
-       lockmgr(&sc->sc_lock, LK_EXCLUSIVE, NULL);
+       FSS_LOCK(sc, s);
+       while ((sc->sc_flags & FSS_EXCL) == FSS_EXCL) {
+               error = ltsleep(sc, PRIBIO|PCATCH, "fsslock", 0, &sc->sc_slock);
+               if (error) {
+                       FSS_UNLOCK(sc, s);
+                       return error;
+               }
+       }
+       sc->sc_flags |= FSS_EXCL;
+       FSS_UNLOCK(sc, s);
 
        error = EINVAL;
 
@@ -268,7 +286,7 @@
        case FSSIOCGET:
                if ((sc->sc_flags & FSS_ACTIVE) == FSS_ACTIVE) {
                        memcpy(fsg->fsg_mount, sc->sc_mntname, MNAMELEN);
-                       fsg->fsg_csize = sc->sc_clsize;
+                       fsg->fsg_csize = FSS_CLSIZE(sc);
                        fsg->fsg_time = sc->sc_time;
                        fsg->fsg_mount_size = sc->sc_clcount;
                        fsg->fsg_bs_size = sc->sc_clnext;
@@ -278,7 +296,10 @@
                break;
        }
 
-       lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
+       FSS_LOCK(sc, s);
+       sc->sc_flags &= ~FSS_EXCL;
+       FSS_UNLOCK(sc, s);
+       wakeup(sc);
 
        return error;
 }
@@ -292,20 +313,19 @@
 int
 fss_dump(dev_t dev, daddr_t blkno, caddr_t va, size_t size)
 {
-       return ENXIO;
+       return EROFS;
 }
 
 /*
  * An error occured reading or writing the snapshot or backing store.
  * If it is the first error log to console.
+ * The caller holds the simplelock.
  */
 static inline void
 fss_error(struct fss_softc *sc, const char *fmt, ...)
 {
-       int s;
        va_list ap;
 
-       s = splbio();
        if ((sc->sc_flags & (FSS_ACTIVE|FSS_ERROR)) == FSS_ACTIVE) {
                va_start(ap, fmt);
                printf("fss%d: snapshot invalid: ", sc->sc_unit);
@@ -315,29 +335,13 @@
        }
        if ((sc->sc_flags & FSS_ACTIVE) == FSS_ACTIVE)
                sc->sc_flags |= FSS_ERROR;
-       splx(s);
-}
-
-/*
- * Check if this snapshot is still valid.
- */
-static inline int
-fss_valid(struct fss_softc *sc)
-{
-       int s, valid;
-
-       s = splbio();
-       valid = ((sc->sc_flags & (FSS_ACTIVE|FSS_ERROR)) == FSS_ACTIVE);
-       splx(s);
-
-       return valid;
 }
 
 /*
  * Allocate the variable sized parts of the softc and
  * fork the kernel thread.
  *
- * The fields sc_clcount, sc_clsize, sc_cache_size and sc_indir_size
+ * The fields sc_clcount, sc_clshift, sc_cache_size and sc_indir_size
  * must be initialized.
  */
 static int
@@ -346,24 +350,35 @@



Home | Main Index | Thread Index | Old Index