< prev index next >
src/hotspot/os_cpu/linux_x86/gc/z/zBackingPath_linux_x86.cpp
Print this page
*** 31,47 ****
#include <unistd.h>
// Mount information, see proc(5) for more details.
#define PROC_SELF_MOUNTINFO "/proc/self/mountinfo"
! ZBackingPath::ZBackingPath(const char* filesystem, const char* preferred_path) {
if (ZPath != NULL) {
// Use specified path
_path = strdup(ZPath);
} else {
// Find suitable path
! _path = find_mountpoint(filesystem, preferred_path);
}
}
ZBackingPath::~ZBackingPath() {
free(_path);
--- 31,47 ----
#include <unistd.h>
// Mount information, see proc(5) for more details.
#define PROC_SELF_MOUNTINFO "/proc/self/mountinfo"
! ZBackingPath::ZBackingPath(const char* filesystem, const char** preferred_mountpoints) {
if (ZPath != NULL) {
// Use specified path
_path = strdup(ZPath);
} else {
// Find suitable path
! _path = find_mountpoint(filesystem, preferred_mountpoints);
}
}
ZBackingPath::~ZBackingPath() {
free(_path);
*** 66,76 ****
free(line_filesystem);
return line_mountpoint;
}
! void ZBackingPath::get_mountpoints(ZArray<char*>* mountpoints, const char* filesystem) const {
FILE* fd = fopen(PROC_SELF_MOUNTINFO, "r");
if (fd == NULL) {
ZErrno err;
log_error(gc, init)("Failed to open %s: %s", PROC_SELF_MOUNTINFO, err.to_string());
return;
--- 66,76 ----
free(line_filesystem);
return line_mountpoint;
}
! void ZBackingPath::get_mountpoints(const char* filesystem, ZArray<char*>* mountpoints) const {
FILE* fd = fopen(PROC_SELF_MOUNTINFO, "r");
if (fd == NULL) {
ZErrno err;
log_error(gc, init)("Failed to open %s: %s", PROC_SELF_MOUNTINFO, err.to_string());
return;
*** 96,136 ****
free(mountpoint);
}
mountpoints->clear();
}
! char* ZBackingPath::find_mountpoint(const char* filesystem, const char* preferred_mountpoint) const {
char* path = NULL;
ZArray<char*> mountpoints;
! get_mountpoints(&mountpoints, filesystem);
if (mountpoints.size() == 0) {
! // No filesystem found
log_error(gc, init)("Failed to find an accessible %s filesystem", filesystem);
} else if (mountpoints.size() == 1) {
! // One filesystem found
path = strdup(mountpoints.at(0));
! } else if (mountpoints.size() > 1) {
! // More than one filesystem found
! ZArrayIterator<char*> iter(&mountpoints);
! for (char* mountpoint; iter.next(&mountpoint);) {
! if (!strcmp(mountpoint, preferred_mountpoint)) {
! // Preferred mount point found
! path = strdup(mountpoint);
! break;
! }
! }
!
! if (path == NULL) {
! // Preferred mount point not found
! log_error(gc, init)("More than one %s filesystem found:", filesystem);
! ZArrayIterator<char*> iter2(&mountpoints);
! for (char* mountpoint; iter2.next(&mountpoint);) {
! log_error(gc, init)(" %s", mountpoint);
! }
! }
}
free_mountpoints(&mountpoints);
return path;
--- 96,144 ----
free(mountpoint);
}
mountpoints->clear();
}
! char* ZBackingPath::find_preferred_mountpoint(const char* filesystem,
! ZArray<char*>* mountpoints,
! const char** preferred_mountpoints) const {
! // Among the found mountpoints, return the first that is on the list of preferred mountpoints
! ZArrayIterator<char*> iter1(mountpoints);
! for (char* mountpoint; iter1.next(&mountpoint);) {
! for (const char** preferred = preferred_mountpoints; *preferred != NULL; preferred++) {
! if (!strcmp(mountpoint, *preferred)) {
! // Preferred mountpoint found
! return strdup(mountpoint);
! }
! }
! }
!
! // Preferred mountpoint not found
! log_error(gc, init)("More than one %s filesystem found:", filesystem);
! ZArrayIterator<char*> iter2(mountpoints);
! for (char* mountpoint; iter2.next(&mountpoint);) {
! log_error(gc, init)(" %s", mountpoint);
! }
!
! return NULL;
! }
!
! char* ZBackingPath::find_mountpoint(const char* filesystem, const char** preferred_mountpoints) const {
char* path = NULL;
ZArray<char*> mountpoints;
! get_mountpoints(filesystem, &mountpoints);
if (mountpoints.size() == 0) {
! // No mountpoint found
log_error(gc, init)("Failed to find an accessible %s filesystem", filesystem);
} else if (mountpoints.size() == 1) {
! // One mountpoint found
path = strdup(mountpoints.at(0));
! } else {
! // More than one mountpoint found
! path = find_preferred_mountpoint(filesystem, &mountpoints, preferred_mountpoints);
}
free_mountpoints(&mountpoints);
return path;
< prev index next >