Module Name: src
Committed By: hannken
Date: Thu Feb 24 09:38:58 UTC 2011
Modified Files:
src/sbin/dump: snapshot.c
src/share/man/man4: fss.4
src/sys/dev: fss.c fssvar.h
src/sys/ufs/ffs: ffs_snapshot.c
src/usr.sbin/fssconfig: fssconfig.c
Log Message:
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).
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sbin/dump/snapshot.c
cvs rdiff -u -r1.14 -r1.15 src/share/man/man4/fss.4
cvs rdiff -u -r1.72 -r1.73 src/sys/dev/fss.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/fssvar.h
cvs rdiff -u -r1.109 -r1.110 src/sys/ufs/ffs/ffs_snapshot.c
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/fssconfig/fssconfig.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/dump/snapshot.c
diff -u src/sbin/dump/snapshot.c:1.5 src/sbin/dump/snapshot.c:1.6
--- src/sbin/dump/snapshot.c:1.5 Sun Apr 11 08:23:51 2010
+++ src/sbin/dump/snapshot.c Thu Feb 24 09:38:57 2011
@@ -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;
}
Index: src/share/man/man4/fss.4
diff -u src/share/man/man4/fss.4:1.14 src/share/man/man4/fss.4:1.15
--- src/share/man/man4/fss.4:1.14 Fri Nov 5 10:02:53 2010
+++ src/share/man/man4/fss.4 Thu Feb 24 09:38:57 2011
@@ -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
Index: src/sys/dev/fss.c
diff -u src/sys/dev/fss.c:1.72 src/sys/dev/fss.c:1.73
--- src/sys/dev/fss.c:1.72 Mon Dec 27 18:41:07 2010
+++ src/sys/dev/fss.c Thu Feb 24 09:38:57 2011
@@ -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;
Index: src/sys/dev/fssvar.h
diff -u src/sys/dev/fssvar.h:1.24 src/sys/dev/fssvar.h:1.25
--- src/sys/dev/fssvar.h:1.24 Mon Apr 5 09:30:46 2010
+++ src/sys/dev/fssvar.h Thu Feb 24 09:38:57 2011
@@ -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
Index: src/sys/ufs/ffs/ffs_snapshot.c
diff -u src/sys/ufs/ffs/ffs_snapshot.c:1.109 src/sys/ufs/ffs/ffs_snapshot.c:1.110
--- src/sys/ufs/ffs/ffs_snapshot.c:1.109 Wed Feb 23 17:05:33 2011
+++ src/sys/ufs/ffs/ffs_snapshot.c Thu Feb 24 09:38:57 2011
@@ -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 @@
struct snap_info *si = VFSTOUFS(mp)->um_snapinfo;
TAILQ_FOREACH(xp, &si->si_snapshots, i_nextsnap) {
- if (xp == ip)
- break;
- error = expunge(vp, xp, fs, snapacct, BLK_SNAP);
- if (error)
- break;
+ if (xp != ip) {
+ error = expunge(vp, xp, fs, snapacct, BLK_SNAP);
+ if (error)
+ break;
+ }
if (xp->i_nlink != 0)
continue;
error = UFS_WAPBL_BEGIN(mp);
Index: src/usr.sbin/fssconfig/fssconfig.c
diff -u src/usr.sbin/fssconfig/fssconfig.c:1.6 src/usr.sbin/fssconfig/fssconfig.c:1.7
--- src/usr.sbin/fssconfig/fssconfig.c:1.6 Mon Apr 28 20:24:16 2008
+++ src/usr.sbin/fssconfig/fssconfig.c Thu Feb 24 09:38:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: fssconfig.c,v 1.6 2008/04/28 20:24:16 martin Exp $ */
+/* $NetBSD: fssconfig.c,v 1.7 2011/02/24 09:38:58 hannken Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -168,15 +168,16 @@
err(1, "open: %s", argv[0]);
}
+ if ((xflag || istmp) && isreg)
+ fss.fss_flags |= FSS_UNLINK_ON_CREATE;
+ else
+ fss.fss_flags = 0;
if (ioctl(fd, FSSIOCSET, &fss) < 0) {
if (istmp)
unlink(fss.fss_bstore);
err(1, "%s: FSSIOCSET", full);
}
- if ((xflag || istmp) && isreg && unlink(fss.fss_bstore) < 0)
- err(1, "unlink: %s", fss.fss_bstore);
-
if (vflag)
list(1, argv);
}