Use ramdisk_size from kernel cmdline
If we can't get file's size then use ramdisk_size if given.
This commit is contained in:
parent
7f50a883ac
commit
ee71c69502
@ -18,12 +18,6 @@
|
|||||||
#define _GNU_SOURCE 1
|
#define _GNU_SOURCE 1
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
/* If we have more than that amount of memory (in bytes), we assume we can load the second stage as a ramdisk */
|
|
||||||
#define MEM_LIMIT_RAMDISK (256 * 1024 * 1024)
|
|
||||||
|
|
||||||
/* If we have more than that amount of memory (in bytes), we assume we can load the rescue as a ramdisk */
|
|
||||||
#define MEM_LIMIT_RESCUE (128 * 1024 * 1024)
|
|
||||||
|
|
||||||
#define VERSION_FILE "/.VERSION"
|
#define VERSION_FILE "/.VERSION"
|
||||||
#define RAMDISK_LOCATION "/"
|
#define RAMDISK_LOCATION "/"
|
||||||
#define IMAGE_LOCATION "/image"
|
#define IMAGE_LOCATION "/image"
|
||||||
|
6
disk.c
6
disk.c
@ -310,11 +310,11 @@ static enum return_type try_with_partition(char *choice)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(ramdisk_path, &statbuf)) {
|
ramdisk_size = get_ramdisk_size(ramdisk_path);
|
||||||
stg1_error_message("Could not get ramdisk size: %s", strerror(errno));
|
if (ramdisk_size == 0) {
|
||||||
|
stg1_error_message("Could not get %s size: %s", ramdisk_path, strerror(errno));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
ramdisk_size = (unsigned long)statbuf.st_size;
|
|
||||||
|
|
||||||
log_message("found the %s Installation, good news!", version);
|
log_message("found the %s Installation, good news!", version);
|
||||||
|
|
||||||
|
12
network.c
12
network.c
@ -763,11 +763,13 @@ enum return_type ftp_prepare(void)
|
|||||||
char * questions_auto[] = { "server", "directory", "user", "pass", NULL };
|
char * questions_auto[] = { "server", "directory", "user", "pass", NULL };
|
||||||
static char ** answers = NULL;
|
static char ** answers = NULL;
|
||||||
enum return_type results;
|
enum return_type results;
|
||||||
|
unsigned long ramdisk_size;
|
||||||
|
|
||||||
update_splash("prepare");
|
update_splash("prepare");
|
||||||
if (!ramdisk_possible(MEM_LIMIT_RAMDISK)) {
|
ramdisk_size = get_ramdisk_size(NULL);
|
||||||
|
if (!ramdisk_possible(ramdisk_size)) {
|
||||||
stg1_error_message("FTP install needs more than %d Mbytes of memory (detected %u Mbytes).",
|
stg1_error_message("FTP install needs more than %d Mbytes of memory (detected %u Mbytes).",
|
||||||
BYTES2MB(MEM_LIMIT_RAMDISK), BYTES2MB(total_memory()));
|
BYTES2MB(ramdisk_size), BYTES2MB(total_memory()));
|
||||||
return RETURN_ERROR;
|
return RETURN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -854,12 +856,14 @@ enum return_type http_prepare(void)
|
|||||||
char * questions_auto[] = { "server", "directory", NULL };
|
char * questions_auto[] = { "server", "directory", NULL };
|
||||||
static char ** answers = NULL;
|
static char ** answers = NULL;
|
||||||
enum return_type results;
|
enum return_type results;
|
||||||
|
unsigned long ramdisk_size;
|
||||||
|
|
||||||
update_splash("prepare");
|
update_splash("prepare");
|
||||||
|
|
||||||
if (!ramdisk_possible(MEM_LIMIT_RAMDISK)) {
|
ramdisk_size = get_ramdisk_size(NULL);
|
||||||
|
if (!ramdisk_possible(ramdisk_size)) {
|
||||||
stg1_error_message("HTTP install needs more than %d Mbytes of memory (detected %u Mbytes).",
|
stg1_error_message("HTTP install needs more than %d Mbytes of memory (detected %u Mbytes).",
|
||||||
BYTES2MB(MEM_LIMIT_RAMDISK), BYTES2MB(total_memory()));
|
BYTES2MB(ramdisk_size), BYTES2MB(total_memory()));
|
||||||
return RETURN_ERROR;
|
return RETURN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
stage1.c
2
stage1.c
@ -342,7 +342,7 @@ void stage1()
|
|||||||
init_frontend(buf);
|
init_frontend(buf);
|
||||||
update_splash("init_frontend");
|
update_splash("init_frontend");
|
||||||
|
|
||||||
if (IS_RESCUE && !ramdisk_possible(MEM_LIMIT_RESCUE)) {
|
if (IS_RESCUE && !ramdisk_possible(get_ramdisk_size(NULL))) {
|
||||||
stg1_error_message("You are starting the rescue with a low memory configuration. "
|
stg1_error_message("You are starting the rescue with a low memory configuration. "
|
||||||
"From that point, experience showed us that the program may stop "
|
"From that point, experience showed us that the program may stop "
|
||||||
"or crash at any point without immediate proper reason. Continue at "
|
"or crash at any point without immediate proper reason. Continue at "
|
||||||
|
41
tools.c
41
tools.c
@ -48,8 +48,15 @@
|
|||||||
#include "init.h"
|
#include "init.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* If we have more than that amount of memory (in bytes), we assume we can load the second stage as a ramdisk */
|
||||||
|
#define MEM_LIMIT_RAMDISK (256 * 1024 * 1024)
|
||||||
|
|
||||||
|
/* If we have more than that amount of memory (in bytes), we assume we can load the rescue as a ramdisk */
|
||||||
|
#define MEM_LIMIT_RESCUE (128 * 1024 * 1024)
|
||||||
|
|
||||||
static struct param_elem params[50];
|
static struct param_elem params[50];
|
||||||
static int param_number = 0;
|
static int param_number = 0;
|
||||||
|
static unsigned long cmdline_ramdisk_size = 0;
|
||||||
|
|
||||||
void process_cmdline(void)
|
void process_cmdline(void)
|
||||||
{
|
{
|
||||||
@ -105,6 +112,17 @@ void process_cmdline(void)
|
|||||||
set_param(MODE_AUTOMATIC);
|
set_param(MODE_AUTOMATIC);
|
||||||
grab_automatic_params(value);
|
grab_automatic_params(value);
|
||||||
}
|
}
|
||||||
|
if (!strcmp(name, "ramdisk_size")) {
|
||||||
|
long tmp;
|
||||||
|
char *endptr = NULL;
|
||||||
|
errno = 0;
|
||||||
|
tmp = strtol(value, &endptr, 0);
|
||||||
|
if (errno == 0 && endptr && *endptr == '\0' && tmp > 0) {
|
||||||
|
/* ramdisk_size in cmdline given in Kbs, convert
|
||||||
|
* its value to bytes */
|
||||||
|
cmdline_ramdisk_size = (unsigned long)tmp * 1024;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (buf[i] == '\0')
|
if (buf[i] == '\0')
|
||||||
break;
|
break;
|
||||||
i++;
|
i++;
|
||||||
@ -213,6 +231,23 @@ unsigned long total_memory(void)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long get_ramdisk_size(const char *ramdisk_path)
|
||||||
|
{
|
||||||
|
/* If path is given then use it and return 0 if stat failed */
|
||||||
|
if (ramdisk_path) {
|
||||||
|
struct stat statbuf;
|
||||||
|
|
||||||
|
return stat(ramdisk_path, &statbuf) ? 0 : (unsigned long)statbuf.st_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use ramdisk_size from cmdline if given */
|
||||||
|
if (cmdline_ramdisk_size)
|
||||||
|
return cmdline_ramdisk_size;
|
||||||
|
|
||||||
|
/* Fallback to hardcoded values as last resort */
|
||||||
|
return IS_RESCUE ? MEM_LIMIT_RESCUE : MEM_LIMIT_RAMDISK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int ramdisk_possible(unsigned long ramdisk_size)
|
int ramdisk_possible(unsigned long ramdisk_size)
|
||||||
{
|
{
|
||||||
@ -229,7 +264,6 @@ int ramdisk_possible(unsigned long ramdisk_size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void save_stuff_for_rescue(void)
|
static void save_stuff_for_rescue(void)
|
||||||
{
|
{
|
||||||
char * file = "/etc/resolv.conf";
|
char * file = "/etc/resolv.conf";
|
||||||
@ -453,10 +487,9 @@ enum return_type load_ramdisk(char *ramdisk_path, unsigned long size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
struct stat statr;
|
size = get_ramdisk_size(img_name);
|
||||||
if (stat(img_name, &statr))
|
if (size == 0)
|
||||||
return RETURN_ERROR;
|
return RETURN_ERROR;
|
||||||
size = (unsigned long)statr.st_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return load_ramdisk_fd(st2_fd, size);
|
return load_ramdisk_fd(st2_fd, size);
|
||||||
|
1
tools.h
1
tools.h
@ -31,6 +31,7 @@ void unset_param(int i);
|
|||||||
int charstar_to_int(char * s);
|
int charstar_to_int(char * s);
|
||||||
/* Returns total memory in Kb */
|
/* Returns total memory in Kb */
|
||||||
unsigned long total_memory(void);
|
unsigned long total_memory(void);
|
||||||
|
unsigned long get_ramdisk_size(const char *ramdisk_path);
|
||||||
int ramdisk_possible(unsigned long ramdisk_size);
|
int ramdisk_possible(unsigned long ramdisk_size);
|
||||||
char * get_ramdisk_realname(void);
|
char * get_ramdisk_realname(void);
|
||||||
enum return_type load_ramdisk(char *, unsigned long size);
|
enum return_type load_ramdisk(char *, unsigned long size);
|
||||||
|
Loading…
Reference in New Issue
Block a user