Source-Changes-HG archive

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

[src/trunk]: src fss(4): Allow FSSIOCSET to set the initial flags. Add a new...



details:   https://anonhg.NetBSD.org/src/rev/f4608dfd6974
branches:  trunk
changeset: 762610:f4608dfd6974
user:      hannken <hannken%NetBSD.org@localhost>
date:      Thu Feb 24 09:38:57 2011 +0000

description:
fss(4): Allow FSSIOCSET to set the initial flags.  Add a new flag
        "FSS_UNLINK_ON_CREATE" to unlink the backing store before
        the snapshot gets created.

With this change dump(8) no longer dumps the zero-sized, but named
snapshot it is working on.  Same applies to fsck_ffs(8).

diffstat:

 sbin/dump/snapshot.c           |  16 +++++++---------
 share/man/man4/fss.4           |  12 ++++++++++--
 sys/dev/fss.c                  |  38 +++++++++++++++++++++++++-------------
 sys/dev/fssvar.h               |   7 +++++--
 sys/ufs/ffs/ffs_snapshot.c     |  19 ++++++++++---------
 usr.sbin/fssconfig/fssconfig.c |   9 +++++----
 6 files changed, 62 insertions(+), 39 deletions(-)

diffs (truncated from 345 to 300 lines):

diff -r bae0d12185f0 -r f4608dfd6974 sbin/dump/snapshot.c
--- a/sbin/dump/snapshot.c      Thu Feb 24 08:59:22 2011 +0000
+++ b/sbin/dump/snapshot.c      Thu Feb 24 09:38:57 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: snapshot.c,v 1.5 2010/04/11 08:23:51 hannken Exp $     */
+/*     $NetBSD: snapshot.c,v 1.6 2011/02/24 09:38:57 hannken Exp $     */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
 int
 snap_open(char *file, char *backup, time_t *snap_date, char **snap_dev)
 {
-       int i, n, fd, israw, fsinternal, dounlink, flags;
+       int i, n, fd, israw, fsinternal, dounlink;
        char path[MAXPATHLEN], fss_dev[14], *cp;
        dev_t mountdev;
        struct fss_set fss;
@@ -144,6 +144,9 @@
        if (close(fd) < 0)
                goto fail;
 
+       fss.fss_flags = FSS_UNCONFIG_ON_CLOSE;
+       if (dounlink)
+               fss.fss_flags |= FSS_UNLINK_ON_CREATE;
        /*
         * Create the snapshot on the first free snapshot device.
         */
@@ -152,9 +155,6 @@
                if ((fd = open(fss_dev, O_RDWR, 0)) < 0)
                        goto fail;
 
-               if (ioctl(fd, FSSIOFGET, &flags) < 0)
-                       goto fail;
-
                if (ioctl(fd, FSSIOCSET, &fss) < 0) {
                        if (errno != EBUSY)
                                goto fail;
@@ -162,6 +162,7 @@
                        fd = -1;
                        continue;
                }
+               dounlink = 0;
 
                if (snap_dev != NULL) {
                        *snap_dev = strdup(fss_dev);
@@ -171,10 +172,7 @@
                        }
                }
 
-               flags |= FSS_UNCONFIG_ON_CLOSE;
-               if (ioctl(fd, FSSIOCGET, &fsg) < 0 ||
-                   ioctl(fd, FSSIOFSET, &flags) < 0 ||
-                   (!israw && unlink(fss.fss_bstore) < 0)) {
+               if (ioctl(fd, FSSIOCGET, &fsg) < 0) {
                        ioctl(fd, FSSIOCCLR);
                        goto fail;
                }
diff -r bae0d12185f0 -r f4608dfd6974 share/man/man4/fss.4
--- a/share/man/man4/fss.4      Thu Feb 24 08:59:22 2011 +0000
+++ b/share/man/man4/fss.4      Thu Feb 24 09:38:57 2011 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fss.4,v 1.14 2010/11/05 10:02:53 hannken Exp $ */
+.\"    $NetBSD: fss.4,v 1.15 2011/02/24 09:38:57 hannken Exp $ */
 .\"
 .\"
 .\" Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd November 5, 2010
+.Dd February 24, 2011
 .Dt FSS 4
 .Os
 .Sh NAME
@@ -65,6 +65,7 @@
        char *fss_mount;
        char *fss_bstore;
        blksize_t fss_csize;
+       int fss_flags;
 };
 .Ed
 .Pp
@@ -78,6 +79,9 @@
 The struct element
 .Va fss_csize
 is the preferred size of this data.
+The struct element
+.Va fss_flags
+is the initial set of flags.
 .It Dv FSSIOCGET(struct fss_get)
 Gets the status of a
 .Nm
@@ -120,6 +124,10 @@
 Unconfigure the
 .Nm
 device on the last close.
+.It Dv FSS_UNLINK_ON_CREATE
+Unlink the backing file before the
+.Nm
+device is created.
 .El
 .It Dv FSSIOFGET(int)
 Gets the flags of a
diff -r bae0d12185f0 -r f4608dfd6974 sys/dev/fss.c
--- a/sys/dev/fss.c     Thu Feb 24 08:59:22 2011 +0000
+++ b/sys/dev/fss.c     Thu Feb 24 09:38:57 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fss.c,v 1.72 2010/12/27 18:41:07 hannken Exp $ */
+/*     $NetBSD: fss.c,v 1.73 2011/02/24 09:38:57 hannken Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.72 2010/12/27 18:41:07 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.73 2011/02/24 09:38:57 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -58,6 +58,7 @@
 #include <sys/kthread.h>
 #include <sys/fstrans.h>
 #include <sys/simplelock.h>
+#include <sys/vfs_syscalls.h>          /* For do_sys_unlink(). */
 
 #include <miscfs/specfs/specdev.h>
 
@@ -303,6 +304,9 @@
        struct fss_get *fsg = (struct fss_get *)data;
 
        switch (cmd) {
+       case FSSIOCSET50:
+               fss->fss_flags = 0;
+               /* Fall through */
        case FSSIOCSET:
                mutex_enter(&sc->sc_lock);
                if ((flag & FWRITE) == 0)
@@ -311,6 +315,8 @@
                        error = EBUSY;
                else
                        error = fss_create_snapshot(sc, fss, l);
+               if (error == 0)
+                       sc->sc_uflags = fss->fss_flags;
                mutex_exit(&sc->sc_lock);
                break;
 
@@ -613,11 +619,6 @@
                                NSM_FOLLOW_NOEMULROOT, &vp);
        if (error != 0)
                return error;
-       error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-       if (error != 0) {
-               vrele(vp);
-               return error;
-       }
 
        if (vp->v_type == VREG && vp->v_mount == sc->sc_mount) {
                sc->sc_flags |= FSS_PERSISTENT;
@@ -629,14 +630,20 @@
                    sc->sc_bs_bshift++)
                        if (FSS_FSBSIZE(sc) == fsbsize)
                                break;
-               if (sc->sc_bs_bshift >= bits) {
-                       VOP_UNLOCK(sc->sc_bs_vp);
+               if (sc->sc_bs_bshift >= bits)
                        return EINVAL;
-               }
 
                sc->sc_bs_bmask = FSS_FSBSIZE(sc)-1;
                sc->sc_clshift = 0;
 
+               if ((fss->fss_flags & FSS_UNLINK_ON_CREATE) != 0) {
+                       error = do_sys_unlink(fss->fss_bstore, UIO_USERSPACE);
+                       if (error)
+                               return error;
+               }
+               error = vn_lock(vp, LK_EXCLUSIVE);
+               if (error != 0)
+                       return error;
                error = VFS_SNAPSHOT(sc->sc_mount, sc->sc_bs_vp, &ts);
                TIMESPEC_TO_TIMEVAL(&sc->sc_time, &ts);
 
@@ -644,7 +651,7 @@
 
                return error;
        }
-       vput(vp);
+       vrele(vp);
 
        /*
         * Get the block device it is mounted on.
@@ -696,6 +703,11 @@
        }
        pathbuf_destroy(pb2);
 
+       if ((fss->fss_flags & FSS_UNLINK_ON_CREATE) != 0) {
+               error = do_sys_unlink(fss->fss_bstore, UIO_USERSPACE);
+               if (error)
+                       return error;
+       }
        if (sc->sc_bs_vp->v_type == VREG) {
                fsbsize = sc->sc_bs_vp->v_mount->mnt_stat.f_iosize;
                if (fsbsize & (fsbsize-1))      /* No power of two */
@@ -817,7 +829,7 @@
        fss_softc_free(sc);
        if (sc->sc_bs_vp != NULL) {
                if (sc->sc_flags & FSS_PERSISTENT)
-                       vn_close(sc->sc_bs_vp, FREAD, l->l_cred);
+                       vrele(sc->sc_bs_vp);
                else
                        vn_close(sc->sc_bs_vp, FREAD|FWRITE, l->l_cred);
        }
@@ -844,7 +856,7 @@
 
        fss_softc_free(sc);
        if (sc->sc_flags & FSS_PERSISTENT)
-               vn_close(sc->sc_bs_vp, FREAD, l->l_cred);
+               vrele(sc->sc_bs_vp);
        else
                vn_close(sc->sc_bs_vp, FREAD|FWRITE, l->l_cred);
        sc->sc_bs_vp = NULL;
diff -r bae0d12185f0 -r f4608dfd6974 sys/dev/fssvar.h
--- a/sys/dev/fssvar.h  Thu Feb 24 08:59:22 2011 +0000
+++ b/sys/dev/fssvar.h  Thu Feb 24 09:38:57 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fssvar.h,v 1.24 2010/04/05 09:30:46 hannken Exp $      */
+/*     $NetBSD: fssvar.h,v 1.25 2011/02/24 09:38:57 hannken Exp $      */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -35,11 +35,13 @@
 #include <sys/simplelock.h>
 
 #define FSS_UNCONFIG_ON_CLOSE  0x01    /* Unconfigure on last close */
+#define FSS_UNLINK_ON_CREATE   0x02    /* Unlink backing store on create */
 
 struct fss_set {
        char            *fss_mount;     /* Mount point of file system */
        char            *fss_bstore;    /* Path of backing store */
        blksize_t       fss_csize;      /* Preferred cluster size */
+       int             fss_flags;      /* Initial flags */
 };
 
 struct fss_get {
@@ -50,11 +52,12 @@
        blkcnt_t        fsg_bs_size;    /* # clusters on backing store */
 };
 
-#define FSSIOCSET      _IOW('F', 0, struct fss_set)    /* Configure */
+#define FSSIOCSET      _IOW('F', 5, struct fss_set)    /* Configure */
 #define FSSIOCGET      _IOR('F', 1, struct fss_get)    /* Status */
 #define FSSIOCCLR      _IO('F', 2)                     /* Unconfigure */
 #define FSSIOFSET      _IOW('F', 3, int)               /* Set flags */
 #define FSSIOFGET      _IOR('F', 4, int)               /* Get flags */
+#define FSSIOCSET50    _IOW('F', 0, struct fss_set)    /* Old configure */
 
 #ifdef _KERNEL
 
diff -r bae0d12185f0 -r f4608dfd6974 sys/ufs/ffs/ffs_snapshot.c
--- a/sys/ufs/ffs/ffs_snapshot.c        Thu Feb 24 08:59:22 2011 +0000
+++ b/sys/ufs/ffs/ffs_snapshot.c        Thu Feb 24 09:38:57 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_snapshot.c,v 1.109 2011/02/23 17:05:33 dyoung Exp $        */
+/*     $NetBSD: ffs_snapshot.c,v 1.110 2011/02/24 09:38:57 hannken Exp $       */
 
 /*
  * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.109 2011/02/23 17:05:33 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.110 2011/02/24 09:38:57 hannken Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -275,7 +275,8 @@
         * Record snapshot inode. Since this is the newest snapshot,
         * it must be placed at the end of the list.
         */
-       fs->fs_snapinum[snaploc] = ip->i_number;
+       if (ip->i_nlink > 0)
+               fs->fs_snapinum[snaploc] = ip->i_number;
 
        mutex_enter(&si->si_lock);
        if (is_active_snapshot(si, ip))
@@ -389,7 +390,7 @@
                        (void) ffs_truncate(vp, (off_t)0, 0, NOCRED);
                        UFS_WAPBL_END(mp);
                }
-       } else
+       } else if (ip->i_nlink > 0)
                vref(vp);
        return (error);
 }
@@ -721,11 +722,11 @@



Home | Main Index | Thread Index | Old Index