From fcd5ec4841318b214c3a3d7f6f904648b1f3d216 Mon Sep 17 00:00:00 2001 From: hannken Date: Thu, 26 Oct 2006 20:02:30 +0000 Subject: [PATCH] When using a snapshot take the snapshot raw device on further open. Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots) Approved by: Manuel Bouyer --- sbin/dump/dump.h | 3 ++- sbin/dump/main.c | 10 +++++++--- sbin/dump/snapshot.c | 16 +++++++++++++--- sbin/dump/snapshot.h | 7 ++++--- sbin/dump/tape.c | 6 +++--- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/sbin/dump/dump.h b/sbin/dump/dump.h index 26af4840eb67..7bb99a3980ad 100644 --- a/sbin/dump/dump.h +++ b/sbin/dump/dump.h @@ -1,4 +1,4 @@ -/* $NetBSD: dump.h,v 1.43 2006/06/24 05:28:54 perseant Exp $ */ +/* $NetBSD: dump.h,v 1.44 2006/10/26 20:02:30 hannken Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -98,6 +98,7 @@ char *dumpinomap; /* map of files to be dumped */ * All calculations done in 0.1" units! */ char *disk; /* name of the disk file */ +char *disk_dev; /* name of the raw device we are dumping */ const char *tape; /* name of the tape file */ const char *dumpdates; /* name of the file containing dump date information*/ const char *temp; /* name of the file for doing rewrite of dumpdates */ diff --git a/sbin/dump/main.c b/sbin/dump/main.c index 11dcd12fa9fe..a76750e6a6db 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.62 2006/06/24 05:28:54 perseant Exp $ */ +/* $NetBSD: main.c,v 1.63 2006/10/26 20:02:30 hannken Exp $ */ /*- * Copyright (c) 1980, 1991, 1993, 1994 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\n\ #if 0 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/1/95"; #else -__RCSID("$NetBSD: main.c,v 1.62 2006/06/24 05:28:54 perseant Exp $"); +__RCSID("$NetBSD: main.c,v 1.63 2006/10/26 20:02:30 hannken Exp $"); #endif #endif /* not lint */ @@ -272,6 +272,7 @@ main(int argc, char *argv[]) */ getfstab(); /* /etc/fstab snarfed */ disk = NULL; + disk_dev = NULL; mountpoint = NULL; dirc = 0; for (i = 0; i < argc; i++) { @@ -441,9 +442,11 @@ main(int argc, char *argv[]) msg("Cannot open %s\n", disk); exit(X_STARTUP); } + disk_dev = disk; #else /* ! DUMP_LFS */ if (snap_backup != NULL || snap_internal) { - diskfd = snap_open(mntinfo->f_mntonname, snap_backup, &tnow); + diskfd = snap_open(mntinfo->f_mntonname, snap_backup, + &tnow, &disk_dev); if (diskfd < 0) { msg("Cannot open snapshot of %s\n", mntinfo->f_mntonname); @@ -455,6 +458,7 @@ main(int argc, char *argv[]) msg("Cannot open %s\n", disk); exit(X_STARTUP); } + disk_dev = disk; } sync(); #endif /* ! DUMP_LFS */ diff --git a/sbin/dump/snapshot.c b/sbin/dump/snapshot.c index e48b7501a128..4a85cfe6220d 100644 --- a/sbin/dump/snapshot.c +++ b/sbin/dump/snapshot.c @@ -1,4 +1,4 @@ -/* $NetBSD: snapshot.c,v 1.2 2005/04/19 08:10:43 hannken Exp $ */ +/* $NetBSD: snapshot.c,v 1.3 2006/10/26 20:02:30 hannken Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -47,6 +47,7 @@ #include #include #include +#include #include #include "snapshot.h" @@ -56,10 +57,11 @@ * using the second argument as backing store and return an open file * descriptor for the snapshot. If the second argument is NULL, use the first * as backing store. If the third argument is not NULL, it gets the time the - * snapshot was created. + * snapshot was created. If the fourth argument is not NULL, it gets the + * snapshot device path. */ int -snap_open(char *mountpoint, char *backup, time_t *snap_date) +snap_open(char *mountpoint, char *backup, time_t *snap_date, char **snap_dev) { int i, fd, israw, fsinternal, dounlink, flags; char path[MAXPATHLEN], fss_dev[14]; @@ -142,6 +144,14 @@ snap_open(char *mountpoint, char *backup, time_t *snap_date) continue; } + if (snap_dev != NULL) { + *snap_dev = strdup(fss_dev); + if (*snap_dev == NULL) { + ioctl(fd, FSSIOCCLR); + goto fail; + } + } + flags |= FSS_UNCONFIG_ON_CLOSE; if (ioctl(fd, FSSIOCGET, &fsg) < 0 || ioctl(fd, FSSIOFSET, &flags) < 0 || diff --git a/sbin/dump/snapshot.h b/sbin/dump/snapshot.h index 450319bafca8..98835a52c8b3 100644 --- a/sbin/dump/snapshot.h +++ b/sbin/dump/snapshot.h @@ -1,4 +1,4 @@ -/* $NetBSD: snapshot.h,v 1.2 2005/04/19 08:10:43 hannken Exp $ */ +/* $NetBSD: snapshot.h,v 1.3 2006/10/26 20:02:30 hannken Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -41,6 +41,7 @@ * using the second argument as backing store and return an open file * descriptor for the snapshot. If the second argument is NULL, use the first * as backing store. If the third argument is not NULL, it gets the time the - * snapshot was created. + * snapshot was created. If the fourth argument is not NULL, it gets the + * snapshot device path. */ -int snap_open(char *, char *, time_t *); +int snap_open(char *, char *, time_t *, char **); diff --git a/sbin/dump/tape.c b/sbin/dump/tape.c index cbba7e3d492a..1a628e002f52 100644 --- a/sbin/dump/tape.c +++ b/sbin/dump/tape.c @@ -1,4 +1,4 @@ -/* $NetBSD: tape.c,v 1.46 2006/06/24 05:28:54 perseant Exp $ */ +/* $NetBSD: tape.c,v 1.47 2006/10/26 20:02:30 hannken Exp $ */ /*- * Copyright (c) 1980, 1991, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)tape.c 8.4 (Berkeley) 5/1/95"; #else -__RCSID("$NetBSD: tape.c,v 1.46 2006/06/24 05:28:54 perseant Exp $"); +__RCSID("$NetBSD: tape.c,v 1.47 2006/10/26 20:02:30 hannken Exp $"); #endif #endif /* not lint */ @@ -823,7 +823,7 @@ doslave(int cmd, int slave_number) * Need our own seek pointer. */ (void) close(diskfd); - if ((diskfd = open(disk, O_RDONLY)) < 0) + if ((diskfd = open(disk_dev, O_RDONLY)) < 0) quit("slave couldn't reopen disk: %s\n", strerror(errno)); /*