Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sysinst Try to get rid of all wedges we created (af...
details: https://anonhg.NetBSD.org/src/rev/8cd520bf1311
branches: trunk
changeset: 359883:8cd520bf1311
user: martin <martin%NetBSD.org@localhost>
date: Sat Jan 29 15:32:49 2022 +0000
description:
Try to get rid of all wedges we created (after unmounting).
diffstat:
usr.sbin/sysinst/defs.h | 3 +-
usr.sbin/sysinst/gpt.c | 5 +++-
usr.sbin/sysinst/target.c | 49 ++++++++++++++++++++++++++++++++++++++++++++--
usr.sbin/sysinst/util.c | 20 +++++++++++++++++-
4 files changed, 70 insertions(+), 7 deletions(-)
diffs (184 lines):
diff -r 48b386943b8d -r 8cd520bf1311 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h Sat Jan 29 12:27:30 2022 +0000
+++ b/usr.sbin/sysinst/defs.h Sat Jan 29 15:32:49 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.76 2021/12/05 02:52:17 msaitoh Exp $ */
+/* $NetBSD: defs.h,v 1.77 2022/01/29 15:32:49 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -927,6 +927,7 @@
int target_file_exists_p(const char *);
int target_symlink_exists_p(const char *);
void unwind_mounts(void);
+void register_post_umount_delwedge(const char *disk, const char *wedge);
int target_mounted(void);
void umount_root(void);
diff -r 48b386943b8d -r 8cd520bf1311 usr.sbin/sysinst/gpt.c
--- a/usr.sbin/sysinst/gpt.c Sat Jan 29 12:27:30 2022 +0000
+++ b/usr.sbin/sysinst/gpt.c Sat Jan 29 15:32:49 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gpt.c,v 1.26 2021/07/17 19:27:22 martin Exp $ */
+/* $NetBSD: gpt.c,v 1.27 2022/01/29 15:32:49 martin Exp $ */
/*
* Copyright 2018 The NetBSD Foundation, Inc.
@@ -1680,6 +1680,9 @@
assert(parts != NULL);
for (p = parts->partitions; p != NULL; p = n) {
+ if (p->gp_flags & GPEF_WEDGE)
+ register_post_umount_delwedge(parts->dp.disk,
+ p->gp_dev_name);
free(__UNCONST(p->last_mounted));
n = p->gp_next;
free(p);
diff -r 48b386943b8d -r 8cd520bf1311 usr.sbin/sysinst/target.c
--- a/usr.sbin/sysinst/target.c Sat Jan 29 12:27:30 2022 +0000
+++ b/usr.sbin/sysinst/target.c Sat Jan 29 15:32:49 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: target.c,v 1.15 2021/01/31 22:45:47 rillig Exp $ */
+/* $NetBSD: target.c,v 1.16 2022/01/29 15:32:49 martin Exp $ */
/*
* Copyright 1997 Jonathan Stone
@@ -71,7 +71,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: target.c,v 1.15 2021/01/31 22:45:47 rillig Exp $");
+__RCSID("$NetBSD: target.c,v 1.16 2022/01/29 15:32:49 martin Exp $");
#endif
/*
@@ -83,6 +83,7 @@
#include <sys/param.h> /* XXX vm_param.h always defines TRUE*/
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <sys/sysctl.h>
#include <sys/stat.h> /* stat() */
#include <sys/mount.h> /* statfs() */
@@ -93,7 +94,7 @@
#include <unistd.h>
#include <curses.h> /* defines TRUE, but checks */
#include <errno.h>
-
+#include <util.h>
#include "defs.h"
#include "md.h"
@@ -119,6 +120,13 @@
char um_mountpoint[4]; /* Allocated longer... */
};
+/* Record a wedge for later deletion after all file systems have been unmounted */
+struct umount_delwedge {
+ struct umount_delwedge *next;
+ char disk[MAXPATHLEN], wedge[MAXPATHLEN];
+};
+struct umount_delwedge *post_umount_dwlist = NULL;
+
/* Unwind-mount stack */
struct unwind_mount *unwind_mountlist = NULL;
@@ -519,6 +527,35 @@
return target_mount_do(opts, from, on);
}
+static bool
+delete_wedge(const char *disk, const char *wedge)
+{
+ struct dkwedge_info dkw;
+ char diskpath[MAXPATHLEN];
+ int fd, error;
+
+ fd = opendisk(disk, O_RDWR, diskpath, sizeof(diskpath), 0);
+ if (fd < 0)
+ return false;
+ memset(&dkw, 0, sizeof(dkw));
+ strlcpy(dkw.dkw_devname, wedge, sizeof(dkw.dkw_devname));
+ error = ioctl(fd, DIOCDWEDGE, &dkw);
+ close(fd);
+ return error == 0;
+}
+
+void
+register_post_umount_delwedge(const char *disk, const char *wedge)
+{
+ struct umount_delwedge *dw;
+
+ dw = calloc(1, sizeof(*dw));
+ dw->next = post_umount_dwlist;
+ strlcpy(dw->disk, disk, sizeof(dw->disk));
+ strlcpy(dw->wedge, wedge, sizeof(dw->wedge));
+ post_umount_dwlist = dw;
+}
+
/*
* unwind the mount stack, unmounting mounted filesystems.
* For now, ignore any errors in unmount.
@@ -529,6 +566,7 @@
unwind_mounts(void)
{
struct unwind_mount *m;
+ struct umount_delwedge *dw;
static volatile int unwind_in_progress = 0;
/* signal safety */
@@ -547,6 +585,11 @@
target_prefix(), m->um_mountpoint);
free(m);
}
+ while ((dw = post_umount_dwlist) != NULL) {
+ post_umount_dwlist = dw->next;
+ delete_wedge(dw->disk, dw->wedge);
+ free(dw);
+ }
unwind_in_progress = 0;
}
diff -r 48b386943b8d -r 8cd520bf1311 usr.sbin/sysinst/util.c
--- a/usr.sbin/sysinst/util.c Sat Jan 29 12:27:30 2022 +0000
+++ b/usr.sbin/sysinst/util.c Sat Jan 29 15:32:49 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.63 2022/01/03 11:44:02 martin Exp $ */
+/* $NetBSD: util.c,v 1.64 2022/01/29 15:32:49 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -2541,9 +2541,9 @@
void
free_install_desc(struct install_partition_desc *install)
{
-#ifndef NO_CLONES
size_t i, j;
+#ifndef NO_CLONES
for (i = 0; i < install->num; i++) {
struct selected_partitions *src = install->infos[i].clone_src;
if (!(install->infos[i].flags & PUIFLG_CLONE_PARTS) ||
@@ -2555,6 +2555,22 @@
install->infos[j].clone_src = NULL;
}
#endif
+
+ for (i = 0; i < install->num; i++) {
+ struct disk_partitions * parts = install->infos[i].parts;
+
+ if (parts == NULL)
+ continue;
+
+ if (parts->pscheme->free)
+ parts->pscheme->free(parts);
+
+ /* NULL all other references to this parts */
+ for (j = i+1; j < install->num; j++)
+ if (install->infos[j].parts == parts)
+ install->infos[j].parts = NULL;
+ }
+
free(install->write_back);
free(install->infos);
}
Home |
Main Index |
Thread Index |
Old Index