Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sysinst Fix /tmp tmpfs handling and on machines wit...
details: https://anonhg.NetBSD.org/src/rev/2a69a8d629d0
branches: trunk
changeset: 968431:2a69a8d629d0
user: martin <martin%NetBSD.org@localhost>
date: Thu Jan 16 16:47:19 2020 +0000
description:
Fix /tmp tmpfs handling and on machines with enough RAM default to
creating a /tmp tmpfs with 25% of ram size limit. Suggested by ad@.
diffstat:
usr.sbin/sysinst/bsddisklabel.c | 96 ++++++++++++++++++++++++++++++++--------
usr.sbin/sysinst/defs.h | 8 ++-
usr.sbin/sysinst/disks.c | 46 ++++++++++++-------
usr.sbin/sysinst/main.c | 3 +-
4 files changed, 112 insertions(+), 41 deletions(-)
diffs (295 lines):
diff -r 48d7497e38e4 -r 2a69a8d629d0 usr.sbin/sysinst/bsddisklabel.c
--- a/usr.sbin/sysinst/bsddisklabel.c Thu Jan 16 15:29:24 2020 +0000
+++ b/usr.sbin/sysinst/bsddisklabel.c Thu Jan 16 16:47:19 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bsddisklabel.c,v 1.34 2020/01/09 13:22:30 martin Exp $ */
+/* $NetBSD: bsddisklabel.c,v 1.35 2020/01/16 16:47:19 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -236,8 +236,16 @@
size / sizemult);
}
size = pset->infos[opt].size;
- snprintf(psize, sizeof psize, "%" PRIu64 "%s",
- size / sizemult, inc_free);
+ if (pset->infos[opt].fs_type == FS_TMPFS) {
+ if (pset->infos[opt].size < 0)
+ snprintf(psize, sizeof psize, "%" PRIu64 "%%", -size);
+ else
+ snprintf(psize, sizeof psize, "%" PRIu64 " %s", size,
+ msg_string(MSG_megname));
+ } else {
+ snprintf(psize, sizeof psize, "%" PRIu64 "%s",
+ size / sizemult, inc_free);
+ }
if (pset->infos[opt].type == PT_swap) {
snprintf(swap, sizeof swap, "<%s>",
@@ -521,6 +529,20 @@
return NO_PART;
}
+static daddr_t
+parse_ram_size(const char *str, bool *is_percent)
+{
+ daddr_t val;
+ char *cp;
+
+ val = strtoull(str, &cp, 10);
+ while (*cp && isspace((unsigned char)*cp))
+ cp++;
+
+ *is_percent = *cp == '%';
+ return val;
+}
+
int
set_ptn_size(menudesc *m, void *arg)
{
@@ -531,7 +553,7 @@
size_t i, root = ~0U;
daddr_t size, old_size, new_size_val, mult;
int rv;
- bool non_zero, extend;
+ bool non_zero, extend, is_ram_size, is_percent = false;
if (pset->cur_free_space == 0 && p->size == 0 &&
!(p->flags & PUIFLG_JUST_MOUNTPOINT))
@@ -561,22 +583,47 @@
}
}
+ is_ram_size = (p->flags & PUIFLG_JUST_MOUNTPOINT)
+ && p->fs_type == FS_TMPFS;
+
size = p->size;
+ if (is_ram_size && size < 0) {
+ is_percent = true;
+ size = -size;
+ }
old_size = size;
if (size == 0)
size = p->def_size;
- size /= sizemult;
- snprintf(dflt, sizeof dflt, "%" PRIu64 "%s",
- size, p->flags & PUIFLAG_EXTEND ? "+" : "");
+ if (!is_ram_size)
+ size /= sizemult;
+
+ if (is_ram_size) {
+ snprintf(dflt, sizeof dflt, "%" PRIu64 "%s",
+ size, is_percent ? "%" : "");
+ } else {
+ snprintf(dflt, sizeof dflt, "%" PRIu64 "%s",
+ size, p->flags & PUIFLAG_EXTEND ? "+" : "");
+ }
for (;;) {
msg_fmt_prompt_win(MSG_askfssize, -1, 18, 0, 0,
- dflt, answer, sizeof answer, "%s%s", p->mount, multname);
+ dflt, answer, sizeof answer, "%s%s", p->mount,
+ is_ram_size ? msg_string(MSG_megname) : multname);
- /* cp will be checked below */
+ if (is_ram_size) {
+ new_size_val = parse_ram_size(answer, &is_percent);
+ if (is_percent &&
+ (new_size_val < 0 || new_size_val > 100))
+ continue;
+ if (!is_percent && new_size_val < 0)
+ continue;
+ size = new_size_val;
+ extend = false;
+ break;
+ }
mult = sizemult;
- new_size_val = parse_disk_pos(answer, &mult, pm->dlcylsize,
- &extend);
+ new_size_val = parse_disk_pos(answer, &mult,
+ pm->dlcylsize, &extend);
if (strcmp(answer, dflt) == 0)
non_zero = p->def_size > 0;
@@ -613,7 +660,9 @@
}
daddr_t align = pset->parts->pscheme->get_part_alignment(pset->parts);
- size = NUMSEC(size, mult, align);
+ if (!is_ram_size) {
+ size = NUMSEC(size, mult, align);
+ }
if (p->flags & PUIFLAG_EXTEND)
p->flags &= ~PUIFLAG_EXTEND;
if (extend && (p->limit == 0 || p->limit > p->size)) {
@@ -626,7 +675,7 @@
adjust_free:
if ((p->flags & (PUIFLG_IS_OUTER|PUIFLG_JUST_MOUNTPOINT)) == 0)
pset->cur_free_space += p->size - size;
- p->size = size;
+ p->size = is_percent ? -size : size;
set_pset_exit_str(pset);
return 0;
@@ -879,6 +928,20 @@
memcpy(wanted->infos, default_parts_init, sizeof(default_parts_init));
+#ifdef HAVE_TMPFS
+ if (get_ramsize() > 96) {
+ for (i = 0; i < wanted->num; i++) {
+ if (wanted->infos[i].type != PT_root ||
+ wanted->infos[i].fs_type != FS_TMPFS)
+ continue;
+ /* default tmpfs to 1/4 RAM */
+ wanted->infos[i].size = -25;
+ wanted->infos[i].def_size = -25;
+ break;
+ }
+ }
+#endif
+
#ifdef MD_PART_DEFAULTS
MD_PART_DEFAULTS(pm, wanted->infos, wanted->num);
#endif
@@ -918,11 +981,6 @@
#endif
}
}
- if ((wanted->infos[i].flags & PUIFLG_JUST_MOUNTPOINT) &&
- wanted->infos[i].size == 0)
- /* default tmpfs to 1/4 RAM */
- wanted->infos[i].def_size =
- get_ramsize() * (MEG/512/4);
}
/*
@@ -1131,7 +1189,7 @@
infos[pno].fs_version = info.fs_sub_type;
}
/* Add the non-partition entires after that */
- j = pset->num;
+ j = pset->parts->num_part;
for (i = 0; i < pset->num; i++) {
if (j >= no)
break;
diff -r 48d7497e38e4 -r 2a69a8d629d0 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h Thu Jan 16 15:29:24 2020 +0000
+++ b/usr.sbin/sysinst/defs.h Thu Jan 16 16:47:19 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.50 2020/01/09 13:22:30 martin Exp $ */
+/* $NetBSD: defs.h,v 1.51 2020/01/16 16:47:19 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -241,7 +241,10 @@
* layout according to the partitioning scheme backend.
*/
struct part_usage_info {
- daddr_t size; /* thumb guestimate of size [sec] */
+ daddr_t size; /* thumb guestimate of size,
+ * [sec if positive, %-of-ram
+ * if TMPFS and negative]
+ */
daddr_t def_size; /* default size */
daddr_t limit; /* max size */
char mount[MOUNTLEN]; /* where will we mount this? */
@@ -363,7 +366,6 @@
FILE *logfp;
FILE *script;
-daddr_t tmp_ramdisk_size;
#define MAX_DISKS 15
daddr_t root_limit; /* BIOS (etc) read limit */
diff -r 48d7497e38e4 -r 2a69a8d629d0 usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c Thu Jan 16 15:29:24 2020 +0000
+++ b/usr.sbin/sysinst/disks.c Thu Jan 16 16:47:19 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: disks.c,v 1.59 2020/01/09 13:22:30 martin Exp $ */
+/* $NetBSD: disks.c,v 1.60 2020/01/16 16:47:19 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -1299,7 +1299,11 @@
if (ptn->size == 0)
continue;
- if (ptn->type != PT_swap &&
+ bool is_tmpfs = ptn->type == PT_root &&
+ ptn->fs_type == FS_TMPFS &&
+ (ptn->flags & PUIFLG_JUST_MOUNTPOINT);
+
+ if (!is_tmpfs && ptn->type != PT_swap &&
(ptn->instflags & PUIINST_MOUNT) == 0)
continue;
@@ -1350,6 +1354,29 @@
scripting_fprintf(f, "%s\t\tnone\tswap\tsw%s\t\t 0 0\n",
dev, dump_dev);
continue;
+#ifdef HAVE_TMPFS
+ case FS_TMPFS:
+ if (ptn->size < 0)
+ scripting_fprintf(f,
+ "tmpfs\t\t/tmp\ttmpfs\trw,-m=1777,"
+ "-s=ram%%%" PRIu64 "\n", -ptn->size);
+ else
+ scripting_fprintf(f,
+ "tmpfs\t\t/tmp\ttmpfs\trw,-m=1777,"
+ "-s=%" PRIu64 "M\n", ptn->size);
+ continue;
+#else
+ case FS_MFS:
+ if (swap_dev[0] != 0)
+ scripting_fprintf(f,
+ "%s\t\t/tmp\tmfs\trw,-s=%"
+ PRIu64 "\n", swap_dev, ptn->size);
+ else
+ scripting_fprintf(f,
+ "swap\t\t/tmp\tmfs\trw,-s=%"
+ PRIu64 "\n", ptn->size);
+ continue;
+#endif
case FS_SYSVBFS:
fstype = "sysvbfs";
make_target_dir("/stand");
@@ -1379,21 +1406,6 @@
}
done_with_disks:
- if (tmp_ramdisk_size > 0) {
-#ifdef HAVE_TMPFS
- scripting_fprintf(f, "tmpfs\t\t/tmp\ttmpfs\trw,-m=1777,-s=%"
- PRIu64 "\n",
- tmp_ramdisk_size * 512);
-#else
- if (swap_dev[0] != 0)
- scripting_fprintf(f, "%s\t\t/tmp\tmfs\trw,-s=%"
- PRIu64 "\n", swap_dev, tmp_ramdisk_size);
- else
- scripting_fprintf(f, "swap\t\t/tmp\tmfs\trw,-s=%"
- PRIu64 "\n", tmp_ramdisk_size);
-#endif
- }
-
if (cdrom_dev[0] == 0)
get_default_cdrom(cdrom_dev, sizeof(cdrom_dev));
diff -r 48d7497e38e4 -r 2a69a8d629d0 usr.sbin/sysinst/main.c
--- a/usr.sbin/sysinst/main.c Thu Jan 16 15:29:24 2020 +0000
+++ b/usr.sbin/sysinst/main.c Thu Jan 16 16:47:19 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.19 2019/12/11 15:08:45 martin Exp $ */
+/* $NetBSD: main.c,v 1.20 2020/01/16 16:47:19 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -134,7 +134,6 @@
const struct f_arg *arg;
sizemult = 1;
- tmp_ramdisk_size = 0;
clean_xfer_dir = 0;
mnt2_mounted = 0;
fd_type = "msdos";
Home |
Main Index |
Thread Index |
Old Index