Kernel VM: Add compatibility logic
* If old-format swap config file found, parse it properly
This commit is contained in:
parent
81d8910bd5
commit
33b1bc7bf7
@ -1441,6 +1441,8 @@ swap_init_post_modules()
|
|||||||
bool swapEnabled = true;
|
bool swapEnabled = true;
|
||||||
bool swapAutomatic = true;
|
bool swapAutomatic = true;
|
||||||
off_t swapSize = 0;
|
off_t swapSize = 0;
|
||||||
|
|
||||||
|
dev_t swapDeviceID = -1;
|
||||||
VolumeInfo selectedVolume = {};
|
VolumeInfo selectedVolume = {};
|
||||||
|
|
||||||
void* settings = load_driver_settings("virtual_memory");
|
void* settings = load_driver_settings("virtual_memory");
|
||||||
@ -1479,6 +1481,11 @@ swap_init_post_modules()
|
|||||||
strncpy(selectedVolume.filesystem, filesystem,
|
strncpy(selectedVolume.filesystem, filesystem,
|
||||||
sizeof(selectedVolume.filesystem));
|
sizeof(selectedVolume.filesystem));
|
||||||
selectedVolume.capacity = atoll(capacity);
|
selectedVolume.capacity = atoll(capacity);
|
||||||
|
} else if (size != NULL) {
|
||||||
|
// Older file format, no location information (assume /var/swap)
|
||||||
|
swapAutomatic = false;
|
||||||
|
swapSize = atoll(size);
|
||||||
|
swapDeviceID = gBootDevice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unload_driver_settings(settings);
|
unload_driver_settings(settings);
|
||||||
@ -1492,9 +1499,8 @@ swap_init_post_modules()
|
|||||||
if (!swapEnabled || swapSize < B_PAGE_SIZE)
|
if (!swapEnabled || swapSize < B_PAGE_SIZE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dev_t dev = -1;
|
if (!swapAutomatic && swapDeviceID < 0) {
|
||||||
|
// If user-specified swap, and no swap device has been chosen yet...
|
||||||
if (!swapAutomatic) {
|
|
||||||
KDiskDeviceManager::CreateDefault();
|
KDiskDeviceManager::CreateDefault();
|
||||||
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
|
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
|
||||||
PartitionScorer visitor(selectedVolume);
|
PartitionScorer visitor(selectedVolume);
|
||||||
@ -1514,16 +1520,16 @@ swap_init_post_modules()
|
|||||||
__func__, selectedVolume.name);
|
__func__, selectedVolume.name);
|
||||||
} else {
|
} else {
|
||||||
if (visitor.fBestPartition->IsMounted())
|
if (visitor.fBestPartition->IsMounted())
|
||||||
dev = visitor.fBestPartition->VolumeID();
|
swapDeviceID = visitor.fBestPartition->VolumeID();
|
||||||
else {
|
else {
|
||||||
KPath devPath, mountPoint;
|
KPath devPath, mountPoint;
|
||||||
visitor.fBestPartition->GetPath(&devPath);
|
visitor.fBestPartition->GetPath(&devPath);
|
||||||
get_mount_point(visitor.fBestPartition, &mountPoint);
|
get_mount_point(visitor.fBestPartition, &mountPoint);
|
||||||
const char* mountPath = mountPoint.Path();
|
const char* mountPath = mountPoint.Path();
|
||||||
mkdir(mountPath, S_IRWXU | S_IRWXG | S_IRWXO);
|
mkdir(mountPath, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
dev = _kern_mount(mountPath, devPath.Path(),
|
swapDeviceID = _kern_mount(mountPath, devPath.Path(),
|
||||||
NULL, 0, NULL, 0);
|
NULL, 0, NULL, 0);
|
||||||
if (dev < 0) {
|
if (swapDeviceID < 0) {
|
||||||
dprintf("%s: Can't mount configured swap partition '%s'\n",
|
dprintf("%s: Can't mount configured swap partition '%s'\n",
|
||||||
__func__, selectedVolume.name);
|
__func__, selectedVolume.name);
|
||||||
}
|
}
|
||||||
@ -1531,13 +1537,15 @@ swap_init_post_modules()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev < 0)
|
if (swapDeviceID < 0)
|
||||||
dev = gBootDevice;
|
swapDeviceID = gBootDevice;
|
||||||
|
|
||||||
|
// We now have a swapDeviceID which is used for the swap file
|
||||||
|
|
||||||
KPath path;
|
KPath path;
|
||||||
struct fs_info info;
|
struct fs_info info;
|
||||||
_kern_read_fs_info(dev, &info);
|
_kern_read_fs_info(swapDeviceID, &info);
|
||||||
if (dev == gBootDevice)
|
if (swapDeviceID == gBootDevice)
|
||||||
path = kDefaultSwapPath;
|
path = kDefaultSwapPath;
|
||||||
else {
|
else {
|
||||||
vfs_entry_ref_to_path(info.dev, info.root,
|
vfs_entry_ref_to_path(info.dev, info.root,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user